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