- Timestamp:
- Dec 7, 2005, 5:13:00 PM (19 years ago)
- Location:
- branches/network/src/util/loading
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/util/loading/game_loader.cc
r5972 r5974 37 37 38 38 SHELL_COMMAND(quit, GameLoader, stop) 39 40 39 ->describe("quits the game") 40 ->setAlias("orxoquit"); 41 41 42 42 … … 67 67 68 68 69 /** 70 * load a StoryEntity 71 * @param element a XMLElement containing all the needed info 72 */ 73 BaseObject* GameLoader::fabricate(const TiXmlElement* element) 74 { 75 assert( element != NULL); 76 77 if( Factory::getFirst() == NULL) 78 { 79 PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n"); 80 return NULL; 81 } 82 83 if( element->Value() != NULL) 84 { 85 PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value()); 86 BaseObject* b = Factory::getFirst()->fabricate( element); 87 if( b == NULL) 88 PRINTF(2)("Failed to fabricate a '%s'\n", element->Value()); 89 else 90 PRINTF(4)("Successfully fabricated a '%s'\n", element->Value()); 91 return b; 92 } 93 94 PRINTF(2)("Fabricate failed, TiElement did not contain a value\n"); 95 96 return NULL; 97 } 98 99 69 100 70 101 /** … … 73 104 ErrorMessage GameLoader::init() 74 105 { 75 if( this->currentCampaign != NULL)106 if( this->currentCampaign != NULL) 76 107 this->currentCampaign->init(); 77 108 78 this->eventHandler = EventHandler::getInstance(); 79 this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_PAUSE); 80 this->eventHandler->subscribe(this, ES_ALL, EV_MAIN_QUIT); //< External Quit Event 81 this->eventHandler->subscribe(this, ES_ALL, KeyMapper::PEV_QUIT); 82 this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_NEXT_WORLD); 83 this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_PREVIOUS_WORLD); 109 EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_PAUSE); 110 EventHandler::getInstance()->subscribe(this, ES_ALL, EV_MAIN_QUIT); //< External Quit Event 111 EventHandler::getInstance()->subscribe(this, ES_ALL, KeyMapper::PEV_QUIT); 112 EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_NEXT_WORLD); 113 EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_PREVIOUS_WORLD); 84 114 } 85 115 … … 97 127 ErrorMessage errorCode; 98 128 char* campaignName = ResourceManager::getFullName(fileName); 99 if (campaignName) 100 { 101 this->currentCampaign = this->fileToCampaign(campaignName); 102 delete[] campaignName; 103 } 104 // World* world0 = new World(DEBUG_WORLD_0); 105 // world0->setNextStoryID(WORLD_ID_GAMEEND); 106 // this->currentCampaign->addEntity(world0, WORLD_ID_2); 129 if( campaignName) 130 { 131 this->currentCampaign = this->fileToCampaign(campaignName); 132 delete[] campaignName; 133 } 107 134 } 108 135 … … 116 143 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 117 144 */ 118 ErrorMessage loadNetworkCampaign(const char* name)145 ErrorMessage GameLoader::loadNetworkCampaign(const char* name) 119 146 {} 120 147 … … 128 155 ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID) 129 156 { 130 switch( campaignID)131 157 switch( campaignID) 158 { 132 159 /* 133 160 Debug Level 0: Debug level used to test the base frame work. … … 155 182 break; 156 183 } 157 184 } 158 185 } 159 186 … … 165 192 ErrorMessage GameLoader::start() 166 193 { 167 if( this->currentCampaign != NULL)194 if( this->currentCampaign != NULL) 168 195 this->currentCampaign->start(); 169 196 } … … 182 209 void GameLoader::stop() 183 210 { 184 if( this->currentCampaign != NULL)211 if( this->currentCampaign != NULL) 185 212 this->currentCampaign->stop(); 186 213 } … … 196 223 { 197 224 this->isPaused = true; 198 if( this->currentCampaign != NULL)225 if( this->currentCampaign != NULL) 199 226 this->currentCampaign->pause(); 200 227 } … … 210 237 { 211 238 this->isPaused = false; 212 if( this->currentCampaign != NULL)239 if( this->currentCampaign != NULL) 213 240 this->currentCampaign->resume(); 214 241 } … … 220 247 ErrorMessage GameLoader::destroy() 221 248 { 222 223 249 } 224 250 … … 239 265 240 266 if( fileName == NULL) 241 242 243 244 267 { 268 PRINTF(2)("No filename specified for loading"); 269 return NULL; 270 } 245 271 246 272 TiXmlDocument* XMLDoc = new TiXmlDocument( fileName); 247 273 // load the campaign document 248 274 if( !XMLDoc->LoadFile()) 249 250 251 252 253 254 275 { 276 // report an error 277 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 278 delete XMLDoc; 279 return NULL; 280 } 255 281 256 282 // check basic validity … … 259 285 260 286 if( strcmp( root->Value(), "Campaign")) 261 262 263 264 265 266 287 { 288 // report an error 289 PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n"); 290 delete XMLDoc; 291 return NULL; 292 } 267 293 268 294 // construct campaign … … 332 358 void GameLoader::previousLevel() 333 359 { 334 if( this->currentCampaign != NULL)360 if( this->currentCampaign != NULL) 335 361 this->currentCampaign->previousLevel(); 336 362 } 337 363 338 /** 339 * load a StoryEntity 340 * @param element a XMLElement containing all the needed info 341 */ 342 BaseObject* GameLoader::fabricate(const TiXmlElement* element) 343 { 344 assert( element != NULL); 345 346 if( Factory::getFirst() == NULL) 347 { 348 PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n"); 349 return NULL; 350 } 351 352 if( element->Value() != NULL) 353 { 354 PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value()); 355 BaseObject* b = Factory::getFirst()->fabricate( element); 356 if( b == NULL) 357 PRINTF(2)("Failed to fabricate a '%s'\n", element->Value()); 358 else 359 PRINTF(4)("Successfully fabricated a '%s'\n", element->Value()); 360 return b; 361 } 362 363 PRINTF(2)("Fabricate failed, TiElement did not contain a value\n"); 364 365 return NULL; 366 } 364 -
branches/network/src/util/loading/game_loader.h
r5972 r5974 40 40 { 41 41 42 42 43 43 public: 44 44 ~GameLoader (); … … 46 46 /** this class is a singleton class @returns an instance of itself */ 47 47 static GameLoader* getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader(); return singletonRef; } 48 49 void registerFactory( Factory* factory ); 50 BaseObject* fabricate(const TiXmlElement* data); 48 51 49 52 ErrorMessage init(); … … 54 57 ErrorMessage destroy(); 55 58 59 ErrorMessage loadDebugCampaign(Uint32 campaignID); 60 ErrorMessage loadCampaign(const char* name); 61 ErrorMessage loadNetworkCampaign(const char* name); 62 63 void process(const Event &event); 64 56 65 void nextLevel(); 57 66 void previousLevel(); 58 67 59 ErrorMessage loadDebugCampaign(Uint32 campaignID);60 ErrorMessage loadCampaign(const char* name);61 ErrorMessage loadNetworkCampaign(const char* name);62 63 68 64 void registerFactory( Factory* factory );65 BaseObject* fabricate(const TiXmlElement* data);66 67 void process(const Event &event);68 69 70 69 private: 71 70 GameLoader (); … … 73 72 Campaign* fileToCampaign(const char* name); 74 73 75 74 76 75 private: 77 76 static GameLoader* singletonRef; //!< The singleton-reference to this object 78 79 Uint32 startTime; //!< start time of the campaign80 bool isPaused; //!< if the game is paused81 82 77 Campaign* currentCampaign; //!< reference to the current campaign playing 83 78 84 EventHandler* eventHandler; //!< reference to the eventHandler79 bool isPaused; //!< if the game is paused 85 80 }; 86 81
Note: See TracChangeset
for help on using the changeset viewer.