Changeset 4597 in orxonox.OLD for orxonox/trunk/src/util/loading
- Timestamp:
- Jun 11, 2005, 12:55:48 AM (19 years ago)
- Location:
- orxonox/trunk/src/util/loading
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/loading/factory.cc
r4492 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 21 21 22 22 /* -------------------------------------------------- 23 * 23 * Factory 24 24 * -------------------------------------------------- 25 25 */ … … 27 27 /** 28 28 \brief constructor 29 29 30 30 set everything to zero and define factoryName 31 31 */ 32 32 Factory::Factory (const char* factoryName) 33 33 { 34 this->setClassID(CL_FACTORY, "Factory"); 35 this->setName(factoryName); 36 34 37 this->factoryName = NULL; 35 38 this->setFactoryName(factoryName); 36 39 next = NULL; 37 40 38 41 initialize(); 39 42 } … … 41 44 /** 42 45 \brief destructor 43 46 44 47 clear the Q 45 48 */ -
orxonox/trunk/src/util/loading/factory.h
r4492 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 14 14 */ 15 15 16 /*! 16 /*! 17 17 \file factory.h 18 18 \brief A loadable object handler … … 27 27 #include "tinyxml.h" 28 28 #include "load_param.h" 29 #include "base_object.h" 29 30 #include "debug.h" 30 31 31 /** 32 /** 32 33 Creates a factory to a Loadable Class. 33 34 this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 35 \todo make factoryName a BaseObject-parameter. (else it would be redundant) 34 36 */ 35 #define CREATE_FACTORY(CLASS_NAME) tFactory<CLASS_NAME>* global_##CLASS_NAME##Factory = new tFactory<CLASS_NAME>(#CLASS_NAME) 37 #define CREATE_FACTORY(CLASS_NAME) tFactory<CLASS_NAME>* global_##CLASS_NAME##Factory = new tFactory<CLASS_NAME>(#CLASS_NAME) 36 38 37 39 //! The Factory is a loadable object handler 38 class Factory {40 class Factory : public BaseObject { 39 41 40 42 public: 41 43 Factory (const char* factoryName = NULL); 42 44 ~Factory (); 43 45 44 46 45 47 virtual BaseObject* fabricate(const TiXmlElement* root); … … 53 55 /** \returns the next factory */ 54 56 Factory* getNext(void) const { return this->next; }; 55 57 56 58 protected: 57 59 char* factoryName; //!< the name of the factory … … 69 71 tFactory(const char* factoryName); 70 72 virtual ~tFactory(); 71 73 72 74 private: 73 75 BaseObject* fabricate(const TiXmlElement* root); … … 83 85 PRINTF(5)("fileName: %s loadable\n", this->factoryName); 84 86 } 85 87 86 88 87 89 template<class T> … … 90 92 91 93 template<class T> 92 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root) 93 { 94 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root) 95 { 94 96 if(!strcmp(root->Value(), getFactoryName())) 95 97 return new T ( root); 96 else if( getNext() != NULL) 98 else if( getNext() != NULL) 97 99 return getNext()->fabricate( root); 98 else 100 else 99 101 return NULL; 100 102 } -
orxonox/trunk/src/util/loading/game_loader.cc
r4511 r4597 1 1 2 2 3 /* 3 /* 4 4 orxonox - the future of 3D-vertical-scrollers 5 5 … … 39 39 \brief simple constructor 40 40 */ 41 GameLoader::GameLoader () 42 { 41 GameLoader::GameLoader () 42 { 43 this->setClassID(CL_GAME_LOADER, "GameLoader"); 44 this->setName("GameLoader"); 43 45 first = NULL; 44 46 } … … 110 112 switch(campaignID) 111 113 { 112 /* 113 114 115 116 114 /* 115 Debug Level 0: Debug level used to test the base frame work. 116 As you can see, all storyentity data is allocated before game 117 start. the storyentity will load themselfs shortly before start 118 through the StoryEntity::init() funtion. 117 119 */ 118 120 case DEBUG_CAMPAIGN_0: 119 121 { 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 122 Campaign* debugCampaign = new Campaign(); 123 124 World* world0 = new World(DEBUG_WORLD_0); 125 world0->setNextStoryID(WORLD_ID_1); 126 debugCampaign->addEntity(world0, WORLD_ID_0); 127 128 World* world1 = new World(DEBUG_WORLD_1); 129 world1->setNextStoryID(WORLD_ID_2); 130 debugCampaign->addEntity(world1, WORLD_ID_1); 131 132 World* world2 = new World(DEBUG_WORLD_2); 133 world2->setNextStoryID(WORLD_ID_GAMEEND); 134 debugCampaign->addEntity(world2, WORLD_ID_2); 135 136 this->currentCampaign = debugCampaign; 137 break; 136 138 } 137 139 } … … 139 141 140 142 141 /** 143 /** 142 144 \brief starts the current entity 143 \returns error code if this action has caused a error 145 \returns error code if this action has caused a error 144 146 */ 145 147 ErrorMessage GameLoader::start() … … 150 152 151 153 152 /** 154 /** 153 155 \brief stops the current entity 154 156 \returns error code if this action has caused a error … … 168 170 169 171 170 /** 172 /** 171 173 \brief pause the current entity 172 174 \returns error code if this action has caused a error … … 182 184 183 185 184 /** 186 /** 185 187 \brief resumes a pause 186 188 \returns error code if this action has caused a error … … 218 220 can load everything it needs into memory then. 219 221 */ 220 222 221 223 if( fileName == NULL) 222 224 { … … 224 226 return NULL; 225 227 } 226 228 227 229 TiXmlDocument* XMLDoc = new TiXmlDocument( fileName); 228 230 // load the campaign document … … 234 236 return NULL; 235 237 } 236 238 237 239 // check basic validity 238 240 TiXmlElement* root = XMLDoc->RootElement(); 239 241 assert( root != NULL); 240 242 241 243 if( strcmp( root->Value(), "Campaign")) 242 244 { … … 246 248 return NULL; 247 249 } 248 250 249 251 // construct campaign 250 252 Campaign* c = new Campaign( root); 251 253 252 254 // free the XML data 253 255 delete XMLDoc; … … 258 260 259 261 /** 260 \brief handle keyboard commands 262 \brief handle keyboard commands 261 263 \param event the event to handle 262 264 */ … … 265 267 if( event.type == KeyMapper::PEV_NEXT_WORLD) 266 268 { 267 if( likely(event.bPressed)) 268 269 270 269 if( likely(event.bPressed)) 270 { 271 this->nextLevel(); 272 } 271 273 } 272 274 else if( event.type == KeyMapper::PEV_PREVIOUS_WORLD) 273 275 { 274 276 if( likely(event.bPressed)) 275 276 277 277 { 278 this->previousLevel(); 279 } 278 280 } 279 281 else if( event.type == KeyMapper::PEV_PAUSE) 280 282 { 281 283 if( likely(event.bPressed)) 282 283 284 285 286 287 284 { 285 if(this->isPaused) 286 this->resume(); 287 else 288 this->pause(); 289 } 288 290 } 289 291 else if( event.type == KeyMapper::PEV_QUIT) … … 322 324 void GameLoader::registerFactory( Factory* factory) 323 325 { 324 325 326 327 328 329 326 assert( factory != NULL); 327 328 PRINTF(4)("Registered factory for '%s'\n", factory->getFactoryName()); 329 330 if( first == NULL) first = factory; 331 else first->registerFactory( factory); 330 332 } 331 333 … … 338 340 { 339 341 assert( element != NULL); 340 342 341 343 if( first == NULL) 342 344 { … … 344 346 return NULL; 345 347 } 346 348 347 349 if( element->Value() != NULL) 348 350 { 349 351 PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value()); 350 352 BaseObject* b = first->fabricate( element); 351 if( b == NULL) 352 353 else 354 353 if( b == NULL) 354 PRINTF(2)("Failed to fabricate a '%s'\n", element->Value()); 355 else 356 PRINTF(4)("Successfully fabricated a '%s'\n", element->Value()); 355 357 return b; 356 358 } 357 359 358 360 PRINTF(2)("Fabricate failed, TiXmlElement did not contain a value\n"); 359 361 360 362 return NULL; 361 363 } -
orxonox/trunk/src/util/loading/load_param.cc
r4501 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 30 30 */ 31 31 BaseLoadParam::BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, 32 int paramCount, bool multi, ...) 33 { 32 int paramCount, bool multi, ...) 33 { 34 this->setClassID(CL_LOAD_PARAM, "LoadParam"); 34 35 this->loadString = NULL; 35 36 … … 39 40 { 40 41 if (likely(!multi)) 41 42 this->loadString = grabParameter(root, paramName); 42 43 else 43 44 45 46 47 48 49 50 44 { 45 if (!strcmp(root->Value(), paramName)) 46 { 47 const TiXmlNode* val = root->FirstChild(); 48 if( val->ToText()) 49 this->loadString = val->Value(); 50 } 51 } 51 52 } 52 53 … … 64 65 va_start (types, multi); 65 66 for(int i = 0; i < paramCount; i++) 66 67 68 69 70 67 { 68 const char* tmpTypeName = va_arg (types, const char*); 69 this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; 70 strcpy(this->paramDesc->types[i], tmpTypeName); 71 } 71 72 va_end(types); 72 73 … … 131 132 { 132 133 if (i > 0) 133 134 PRINT(3)(","); 134 135 PRINT(3)("%s", this->types[i]); 135 136 } … … 194 195 { 195 196 if (!strcmp(enumClassDesc->className, className)) 196 197 198 199 197 { 198 delete iterator; 199 return enumClassDesc; 200 } 200 201 enumClassDesc = iterator->nextElement(); 201 202 } … … 216 217 { 217 218 if (!strcmp(enumParamDesc->paramName, paramName)) 218 219 220 221 219 { 220 delete iterator; 221 return enumParamDesc; 222 } 222 223 enumParamDesc = iterator->nextElement(); 223 224 } … … 243 244 LoadParamDescription* enumParamDesc = paramIT->nextElement(); 244 245 while (enumParamDesc) 245 246 247 248 246 { 247 enumParamDesc->print(); 248 enumParamDesc = paramIT->nextElement(); 249 } 249 250 delete paramIT; 250 251 … … 267 268 const TiXmlElement* element; 268 269 const TiXmlNode* node; 269 270 270 271 if (root == NULL) 271 272 return NULL; 272 273 assert( parameterName != NULL); 273 274 274 275 element = root->FirstChildElement( parameterName); 275 276 if( element == NULL) return NULL; 276 277 277 278 node = element->FirstChild(); 278 279 while( node != NULL) -
orxonox/trunk/src/util/loading/load_param.h
r4592 r4597 22 22 #define _LOAD_PARAM_H 23 23 24 #include "base_object.h" 24 25 #include "factory.h" 25 26 #include "debug.h" … … 228 229 229 230 //! abstract Base class for a Loadable parameter 230 class BaseLoadParam 231 class BaseLoadParam : public BaseObject 231 232 { 232 233 public:
Note: See TracChangeset
for help on using the changeset viewer.