Changeset 4598 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Jun 11, 2005, 3:08:36 AM (19 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/story_entities/campaign.cc
r4597 r4598 41 41 Campaign::Campaign ( TiXmlElement* root) 42 42 { 43 //! \todo loading with load_param....44 43 this->setClassID(CL_CAMPAIGN, "Campaign"); 44 45 PRINTF(3)("Loading Campaign...\n"); 46 47 assert( root != NULL); 48 49 this->entities = new tList<StoryEntity>(); 50 this->isInit = false; 51 52 this->loadParams(root); 53 54 55 //if( lastCreated != NULL) 56 //lastCreated->setStoryID( WORLD_ID_GAMEEND); 57 } 58 59 Campaign::~Campaign () {} 60 61 62 ErrorMessage Campaign::init() 63 { 64 this->isInit = true; 65 } 66 67 /** 68 \brief loads the Parameters of a Campaign 69 \param root: The XML-element to load from 70 */ 71 void Campaign::loadParams(const TiXmlElement* root) 72 { 45 73 TiXmlElement* element; 46 74 const char* string; 47 int id; 48 49 PRINTF(3)("Loading Campaign...\n"); 50 51 assert( root != NULL); 52 GameLoader* loader = GameLoader::getInstance(); 53 54 this->entities = new tList<StoryEntity>(); 55 this->isInit = false; 56 57 // grab all the necessary parameters 58 string = grabParameter( root, "identifier"); 59 if( string == NULL || sscanf(string, "%d", &id) != 1) 60 { 61 PRINTF(2)("Campaign is missing a proper 'identifier'\n"); 62 this->setStoryID( -1); 63 } 64 else this->setStoryID( id); 65 66 // find WorldList 67 element = root->FirstChildElement( "WorldList"); 68 if( element == NULL) 69 { 70 PRINTF(2)("Campaign is missing a proper 'WorldList'\n"); 71 } 72 else 73 element = element->FirstChildElement(); 74 75 76 LoadParam<Campaign>(root, "identifier", this, &Campaign::setStoryID); 77 78 LoadParam<Campaign>(root, "WorldList", this, &Campaign::loadWorldListParams, root->FirstChildElement("WorldList")); 79 } 80 81 /** 82 \brief loads a WorldList 83 \param root: the XML-element to load from 84 */ 85 void Campaign::loadWorldListParams(const TiXmlElement* root) 86 { 87 const TiXmlElement* element = root->FirstChildElement(); 75 88 // load Worlds/Subcampaigns/Whatever 76 89 StoryEntity* lastCreated = NULL; 77 90 while( element != NULL) 78 79 80 StoryEntity* created = (StoryEntity*) loader->fabricate(element);91 { 92 printf("Campaign: Constructor: adding a world\n"); 93 StoryEntity* created = (StoryEntity*) GameLoader::getInstance()->fabricate(element); 81 94 /* 82 83 84 85 95 if( lastCreated != NULL) 96 created->setNextStoryID( lastCreated->getStoryID()); 97 else 98 created->setNextStoryID( WORLD_ID_GAMEEND); 86 99 */ 87 if( created != NULL) 88 { 89 this->addEntity( created); 90 lastCreated = created; 91 } 92 element = element->NextSiblingElement(); 93 } 94 //if( lastCreated != NULL) 95 //lastCreated->setStoryID( WORLD_ID_GAMEEND); 96 } 97 98 Campaign::~Campaign () {} 99 100 101 ErrorMessage Campaign::init() 102 { 103 this->isInit = true; 104 } 105 100 if( created != NULL) 101 { 102 this->addEntity( created); 103 lastCreated = created; 104 } 105 element = element->NextSiblingElement(); 106 } 107 } 106 108 107 109 ErrorMessage Campaign::start() -
orxonox/trunk/src/story_entities/campaign.h
r4597 r4598 17 17 Campaign ( TiXmlElement* root); 18 18 virtual ~Campaign (); 19 20 void loadParams(const TiXmlElement* root); 21 void loadWorldListParams(const TiXmlElement* root); 19 22 20 23 StoryEntity* currentEntity; -
orxonox/trunk/src/util/loading/game_loader.cc
r4597 r4598 337 337 \param element a XMLElement containing all the needed info 338 338 */ 339 BaseObject* GameLoader::fabricate( TiXmlElement* element)339 BaseObject* GameLoader::fabricate(const TiXmlElement* element) 340 340 { 341 341 assert( element != NULL); -
orxonox/trunk/src/util/loading/game_loader.h
r4511 r4598 1 /*! 1 /*! 2 2 \file game_loader.h 3 3 \brief loads campaigns, worlds and all other story_entities 4 */ 4 */ 5 5 6 6 #ifndef _GAME_LOADER_H … … 60 60 bool worldCommand(Command* cmd); 61 61 ErrorMessage loadDebugCampaign(Uint32 campaignID); 62 62 63 63 void registerFactory( Factory* factory ); 64 BaseObject* fabricate( TiXmlElement* data);64 BaseObject* fabricate(const TiXmlElement* data); 65 65 66 66 void process(const Event &event); … … 78 78 79 79 Campaign* currentCampaign; //!< reference to the current campaign playing 80 80 81 81 EventHandler* eventHandler; //!< reference to the eventHandler 82 82 -
orxonox/trunk/src/util/loading/load_param.cc
r4597 r4598 30 30 */ 31 31 BaseLoadParam::BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, 32 int paramCount, bool multi, ...)32 int paramCount, bool multi, const void* pointerToParam, ...) 33 33 { 34 34 this->setClassID(CL_LOAD_PARAM, "LoadParam"); 35 35 this->loadString = NULL; 36 37 if (paramCount == 0) 36 this->pointerToParam = pointerToParam; 37 38 if (paramCount == 0 || this->pointerToParam) 38 39 this->loadString = "none"; 39 40 else … … 63 64 64 65 va_list types; 65 va_start (types, multi);66 va_start (types, pointerToParam); 66 67 for(int i = 0; i < paramCount; i++) 67 68 { -
orxonox/trunk/src/util/loading/load_param.h
r4597 r4598 26 26 #include "debug.h" 27 27 #include "substring.h" 28 #include "tinyxml.h" 28 29 29 30 // Forward Declaration // … … 41 42 /** 42 43 useable FunctionParameters are: 43 l_INT: int 44 l_LONG: long 45 l_SHORT: short 46 l_FLOAT: float 47 l_STRING: const char* 48 */ 49 50 #define l_INT_TYPE int //!< The type of an INT 51 #define l_INT_FUNC atoi //!< the function to call to parse INT 52 #define l_INT_NAME "int" //!< the name of an INT 53 54 #define l_LONG_TYPE long //!< The type of a LONG 55 #define l_LONG_FUNC atol //!< The function to parse a LONG 56 #define l_LONG_NAME "long" //!< The name of a LONG 57 58 #define l_SHORT_TYPE short //!< The type of a SHORT 59 #define l_SHORT_FUNC atoi //!< The function to parse a SHORT 60 #define l_SHORT_NAME "short" //!< The name of a SHORT 61 62 #define l_FLOAT_TYPE float //!< The type of a FLOAT 63 #define l_FLOAT_FUNC atof //!< The function to parse a FLOAT 64 #define l_FLOAT_NAME "float" //!< The name of a FLOAT 65 66 #define l_STRING_TYPE const char* //!< The type fo a STRING 67 #define l_STRING_FUNC //!< The function to parse a STRING 68 #define l_STRING_NAME "string" //!< The name of a STRING 44 l_INT: int 45 l_LONG: long 46 l_SHORT: short 47 l_FLOAT: float 48 l_STRING: const char* 49 l_XML_ELEM: TiXmlElement* 50 */ 51 52 #define l_INT_TYPE int //!< The type of an INT 53 #define l_INT_FUNC atoi //!< the function to call to parse INT 54 #define l_INT_NAME "int" //!< the name of an INT 55 56 #define l_LONG_TYPE long //!< The type of a LONG 57 #define l_LONG_FUNC atol //!< The function to parse a LONG 58 #define l_LONG_NAME "long" //!< The name of a LONG 59 60 #define l_SHORT_TYPE short //!< The type of a SHORT 61 #define l_SHORT_FUNC atoi //!< The function to parse a SHORT 62 #define l_SHORT_NAME "short" //!< The name of a SHORT 63 64 #define l_FLOAT_TYPE float //!< The type of a FLOAT 65 #define l_FLOAT_FUNC atof //!< The function to parse a FLOAT 66 #define l_FLOAT_NAME "float" //!< The name of a FLOAT 67 68 #define l_STRING_TYPE const char* //!< The type of a STRING 69 #define l_STRING_FUNC //!< The function to parse a STRING 70 #define l_STRING_NAME "string" //!< The name of a STRING 71 72 #define l_XML_ELEM_TYPE const TiXmlElement* //!< The type of an XML_ELEM 73 #define l_XML_ELEM_FUNC //!< The function to parse an XML_ELEM 74 #define l_XML_ELEM_NAME "XML" //!< The name of an XML_ELEM 69 75 70 76 // 1. TYPE … … 75 81 #define LoadParam1(type1) \ 76 82 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), bool multi = false) \ 77 : BaseLoadParam(root, pt2Object, paramName, 1, multi, type1##_NAME)\83 : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_NAME) \ 78 84 { \ 79 85 if (loadString != NULL && root != NULL) \ … … 92 98 #define LoadParam2(type1, type2) \ 93 99 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE), bool multi = false) \ 94 : BaseLoadParam(root, pt2Object, paramName, 2, multi, type1##_NAME, type2##_NAME) \100 : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_NAME, type2##_NAME) \ 95 101 { \ 96 102 if (loadString != NULL && root != NULL) \ … … 117 123 #define LoadParam3(type1, type2, type3) \ 118 124 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE), bool multi = false)\ 119 : BaseLoadParam(root, pt2Object, paramName, 3, multi, type1##_NAME, type2##_NAME, type3##_NAME) \125 : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME) \ 120 126 { \ 121 127 if (loadString != NULL && root != NULL) \ … … 143 149 #define LoadParam4(type1, type2, type3, type4) \ 144 150 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE), bool multi = false) \ 145 : BaseLoadParam(root, pt2Object, paramName, 4, multi, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \151 : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \ 146 152 { \ 147 153 if (loadString != NULL && root != NULL) \ … … 170 176 #define LoadParam5(type1, type2, type3, type4, type5) \ 171 177 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE), bool multi = false) \ 172 : BaseLoadParam(root, pt2Object, paramName, 5, multi, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \178 : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \ 173 179 { \ 174 180 if (loadString != NULL && root != NULL) \ … … 185 191 } 186 192 193 // Pointer TYPE 194 /** 195 \brief a Macro to easily implement many different Constructors for the LoadParam-Class with 1 argument 196 \param type1 The type of the Pointer 197 */ 198 #define LoadParamPT(type1) \ 199 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), type1##_TYPE pointerToParam, bool multi = false) \ 200 : BaseLoadParam(root, pt2Object, paramName, 1, multi, pointerToParam, type1##_NAME) \ 201 { \ 202 if (pointerToParam != NULL && root != NULL) \ 203 (*pt2Object.*function)((type1##_TYPE) pointerToParam); \ 204 else \ 205 PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \ 206 } 187 207 188 208 //! A class that handles the description of loadable parameters … … 235 255 236 256 protected: 237 BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, int paramCount, bool multi, ...);257 BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, int paramCount, bool multi, const void* pointerToParam, ...); 238 258 239 259 protected: … … 241 261 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 242 262 const char* loadString; //!< The string loaded by this LoadParam 263 const void* pointerToParam; //!< A Pointer to a Parameter. 243 264 }; 244 265 … … 249 270 public: 250 271 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(), bool multi = false) 251 : BaseLoadParam(root, pt2Object, paramName, 0, multi, "")272 : BaseLoadParam(root, pt2Object, paramName, 0, multi, NULL, "") 252 273 { 253 274 if (loadString != NULL && root != NULL) … … 284 305 //! makes functions with four floats loadable 285 306 LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT); 307 308 LoadParamPT(l_XML_ELEM); 286 309 }; 287 310
Note: See TracChangeset
for help on using the changeset viewer.