-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClusterSlaveSimulation.cpp
More file actions
177 lines (141 loc) · 5 KB
/
Copy pathClusterSlaveSimulation.cpp
File metadata and controls
177 lines (141 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/***********************************************************************
ClusterSlaveSimulation - Proxy for local simulations run on the master
node of a cluster.
Copyright (c) 2019-2022 Oliver Kreylos
The Nanotech Construction Kit is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Nanotech Construction Kit is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with the Nanotech Construction Kit; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***********************************************************************/
#include "ClusterSlaveSimulation.h"
#include <vector>
#include <Misc/SizedTypes.h>
#include <Misc/Marshaller.h>
#include <Cluster/MulticastPipe.h>
#include "IO.h"
/***************************************
Methods of class ClusterSlaveSimulation:
***************************************/
void* ClusterSlaveSimulation::communicationThreadMethod(void)
{
/* Receive and process messages from the master until told to stop: */
bool keepRunning=true;
while(keepRunning)
{
/* Read the message type and handle the message: */
switch(clusterPipe->read<Misc::UInt8>())
{
case SetParameters:
/* Read the new simulation parameters: */
parameters.read(*clusterPipe);
/* Call the parameters changed callback if one was set: */
if(parametersChangedCallback!=0)
parametersChangedCallback(parameters,parametersChangedCallbackData);
break;
case UpdateSession:
/* Read the new session ID, which invalidates the session and blocks access to the unit type array: */
sessionId=clusterPipe->read<SessionID>();
/* Read the new domain size: */
Misc::read(*clusterPipe,domain);
/* Read the new list of unit types: */
Misc::read(*clusterPipe,unitTypes);
/* Call the session changed callback if one is set: */
if(sessionChangedCallback!=0)
sessionChangedCallback(sessionId,sessionChangedCallbackData);
break;
case UpdateSimulation:
{
/* Read a new reduced unit state array from the master and post it to the main thread: */
ReducedUnitStateArray& states=unitStates.startNewValue();
readStateArray(*clusterPipe,states,true);
unitStates.postNewValue();
break;
}
case Shutdown:
keepRunning=false;
break;
}
}
return 0;
}
ClusterSlaveSimulation::ClusterSlaveSimulation(Cluster::MulticastPipe* sClusterPipe)
:clusterPipe(sClusterPipe)
{
/* Start the communication thread: */
communicationThread.start(this,&ClusterSlaveSimulation::communicationThreadMethod);
}
ClusterSlaveSimulation::~ClusterSlaveSimulation(void)
{
/* Wait for the communication thread to shut down: */
communicationThread.join();
}
const SimulationInterface::Parameters& ClusterSlaveSimulation::getParameters(void) const
{
return parameters;
}
void ClusterSlaveSimulation::setParameters(const SimulationInterface::Parameters& newParameters)
{
/* Ignore */
}
bool ClusterSlaveSimulation::lockNewState(void)
{
return unitStates.lockNewValue();
}
bool ClusterSlaveSimulation::isLockedStateValid(void) const
{
return unitStates.getLockedValue().sessionId==sessionId;
}
PickID ClusterSlaveSimulation::pick(const Point& pickPosition,Scalar pickRadius,const Rotation& pickOrientation,bool pickConnected)
{
/* Ignore */
return 0;
}
PickID ClusterSlaveSimulation::pick(const Point& pickPosition,const Vector& pickDirection,const Rotation& pickOrientation,bool pickConnected)
{
/* Ignore */
return 0;
}
PickID ClusterSlaveSimulation::paste(const Point& newPosition,const Rotation& newOrientation,const Vector& newLinearVelocity,const Vector& newAngularVelocity)
{
/* Ignore */
return 0;
}
void ClusterSlaveSimulation::create(PickID pickId,UnitTypeID newTypeId,const Point& newPosition,const Rotation& newOrientation,const Vector& newLinearVelocity,const Vector& newAngularVelocity)
{
/* Ignore */
}
void ClusterSlaveSimulation::setState(PickID pickId,const Point& newPosition,const Rotation& newOrientation,const Vector& newLinearVelocity,const Vector& newAngularVelocity)
{
/* Ignore */
}
void ClusterSlaveSimulation::copy(PickID pickId)
{
/* Ignore */
}
void ClusterSlaveSimulation::destroy(PickID pickId)
{
/* Ignore */
}
void ClusterSlaveSimulation::release(PickID pickId)
{
/* Ignore */
}
void ClusterSlaveSimulation::loadState(IO::File& stateFile)
{
/* Ignore */
}
void ClusterSlaveSimulation::saveState(IO::File& stateFile,SimulationInterface::SaveStateCompleteCallback* completeCallback)
{
/* Ignore */
}
const ReducedUnitStateArray& ClusterSlaveSimulation::getLockedState(void) const
{
return unitStates.getLockedValue();
}