00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef _TASKEDSIMULATION_H_
00060 #define _TASKEDSIMULATION_H_
00061
00062 #include "simulation.h"
00063 #include "simulationtaskhandle.h"
00064 #include <string>
00065 #include <selforg/quickmp.h>
00066
00067 namespace lpzrobots {
00068
00069 class TaskedSimulation : public Simulation {
00070 public:
00071 TaskedSimulation() :
00072 Simulation(), taskId(0), simTaskHandle(0) {
00073 useOdeThread = false;
00074 useOsgThread = false;
00075 useQMPThreads = false;
00076 inTaskedMode = true;
00077 }
00078
00079 virtual ~TaskedSimulation() {
00080 }
00081
00082
00083 virtual void start(const OdeHandle&, const OsgHandle&, GlobalData& globalData,
00084 SimulationTaskHandle& simTaskHandle, int taskId) {
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 virtual bool restart(const OdeHandle&, const OsgHandle&, GlobalData& globalData, SimulationTaskHandle&,
00096 int taskId) {
00097 return false;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106 virtual void addCallback(GlobalData& globalData, bool draw, bool pause, bool control, SimulationTaskHandle&,
00107 int taskId) {
00108 }
00109
00110
00111
00112
00113
00114 virtual bool command(const OdeHandle&, const OsgHandle&, GlobalData& globalData, int key, bool down,
00115 SimulationTaskHandle&, int taskId) {
00116 return false;
00117 }
00118
00119
00120
00121
00122
00123
00124 void setTaskId(int taskId) {
00125 this->taskId = taskId;
00126 if (taskId == 0)
00127 noGraphics = false;
00128 else
00129 noGraphics = true;
00130
00131
00132 }
00133
00134 void setTaskNameSuffix(std::string nameSuffix) {
00135 windowName.append(nameSuffix);
00136 }
00137
00138
00139
00140
00141
00142
00143 void setSimTaskHandle(SimulationTaskHandle& simTaskHandle) {
00144 this->simTaskHandle = &simTaskHandle;
00145 }
00146
00147 private:
00148
00149
00150
00151
00152 void processCmdLine(int argc, char** argv) {
00153 Simulation::processCmdLine(argc, argv);
00154 useOdeThread = false;
00155 useOsgThread = false;
00156 useQMPThreads = false;
00157 inTaskedMode = true;
00158 if (taskId!=0) {
00159 noGraphics = true;
00160
00161 osgHandle.cfg->noGraphics=noGraphics;
00162 }
00163 }
00164
00165
00166
00167
00168
00169 virtual bool storeCfg(const char* filenamestem, const std::list<std::string>& comments = std::list<std::string>()) {
00170 return true;
00171 }
00172
00173
00174
00175
00176
00177 bool restoreCfg(const char* filenamestem) {
00178 bool result = Simulation::restoreCfg(filenamestem);
00179 useOdeThread = false;
00180 useOsgThread = false;
00181 useQMPThreads = false;
00182 inTaskedMode = true;
00183 if (taskId!=0) {
00184 noGraphics = true;
00185
00186 osgHandle.cfg->noGraphics=noGraphics;
00187 }
00188 return result;
00189 }
00190
00191 int taskId;
00192 SimulationTaskHandle* simTaskHandle;
00193 std::string nameSuffix;
00194
00195 void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& globalData) {
00196 QMP_CRITICAL(61);
00197 start(odeHandle, osgHandle, globalData, *simTaskHandle, taskId);
00198 QMP_END_CRITICAL(61);
00199 }
00200
00201 bool restart(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& globalData) {
00202 bool doRestart;
00203 QMP_CRITICAL(62);
00204 doRestart = restart(odeHandle, osgHandle, globalData, *simTaskHandle, taskId);
00205 QMP_END_CRITICAL(62);
00206 return doRestart;
00207 }
00208
00209 virtual void addCallback(GlobalData& globalData, bool draw, bool pause, bool control) {
00210 QMP_CRITICAL(63);
00211 addCallback(globalData, draw, pause, control, *simTaskHandle, taskId);
00212 QMP_END_CRITICAL(63);
00213 }
00214 ;
00215
00216 bool command(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& globalData, int key, bool down) {
00217 return command(odeHandle, osgHandle, globalData, key, down, *simTaskHandle, taskId);
00218 }
00219
00220 };
00221
00222 }
00223
00224 #endif