Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4598 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Jun 11, 2005, 3:08:36 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: campaign now gets loaded via LoadParam

Location:
orxonox/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/story_entities/campaign.cc

    r4597 r4598  
    4141Campaign::Campaign ( TiXmlElement* root)
    4242{
    43   //! \todo loading with load_param....
    4443  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
     59Campaign::~Campaign () {}
     60
     61
     62ErrorMessage 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 */
     71void Campaign::loadParams(const TiXmlElement* root)
     72{
    4573  TiXmlElement* element;
    4674  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 */
     85void Campaign::loadWorldListParams(const TiXmlElement* root)
     86{
     87  const TiXmlElement* element = root->FirstChildElement();
    7588  // load Worlds/Subcampaigns/Whatever
    7689  StoryEntity* lastCreated = NULL;
    7790  while( element != NULL)
    78     {
    79       printf("Campaign: Constructor: adding a world\n");
    80       StoryEntity* created = (StoryEntity*) loader->fabricate( element);
     91  {
     92    printf("Campaign: Constructor: adding a world\n");
     93    StoryEntity* created = (StoryEntity*) GameLoader::getInstance()->fabricate(element);
    8194      /*
    82       if( lastCreated != NULL)
    83         created->setNextStoryID( lastCreated->getStoryID());
    84       else
    85         created->setNextStoryID( WORLD_ID_GAMEEND);
     95    if( lastCreated != NULL)
     96    created->setNextStoryID( lastCreated->getStoryID());
     97    else
     98    created->setNextStoryID( WORLD_ID_GAMEEND);
    8699      */
    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}
    106108
    107109ErrorMessage Campaign::start()
  • orxonox/trunk/src/story_entities/campaign.h

    r4597 r4598  
    1717  Campaign ( TiXmlElement* root);
    1818  virtual ~Campaign ();
     19
     20  void loadParams(const TiXmlElement* root);
     21  void loadWorldListParams(const TiXmlElement* root);
    1922
    2023  StoryEntity* currentEntity;
  • orxonox/trunk/src/util/loading/game_loader.cc

    r4597 r4598  
    337337   \param element a XMLElement containing all the needed info
    338338*/
    339 BaseObject* GameLoader::fabricate( TiXmlElement* element)
     339BaseObject* GameLoader::fabricate(const TiXmlElement* element)
    340340{
    341341  assert( element != NULL);
  • orxonox/trunk/src/util/loading/game_loader.h

    r4511 r4598  
    1 /*! 
     1/*!
    22    \file game_loader.h
    33    \brief loads campaigns, worlds and all other story_entities
    4 */ 
     4*/
    55
    66#ifndef _GAME_LOADER_H
     
    6060  bool worldCommand(Command* cmd);
    6161  ErrorMessage loadDebugCampaign(Uint32 campaignID);
    62  
     62
    6363  void registerFactory( Factory* factory );
    64   BaseObject* fabricate( TiXmlElement* data);
     64  BaseObject* fabricate(const TiXmlElement* data);
    6565
    6666  void process(const Event &event);
     
    7878
    7979  Campaign*              currentCampaign;      //!< reference to the current campaign playing
    80  
     80
    8181  EventHandler*          eventHandler;         //!< reference to the eventHandler
    8282
  • orxonox/trunk/src/util/loading/load_param.cc

    r4597 r4598  
    3030*/
    3131BaseLoadParam::BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName,
    32                              int paramCount, bool multi, ...)
     32                             int paramCount, bool multi, const void* pointerToParam, ...)
    3333{
    3434  this->setClassID(CL_LOAD_PARAM, "LoadParam");
    3535  this->loadString = NULL;
    36 
    37   if (paramCount == 0)
     36  this->pointerToParam = pointerToParam;
     37
     38  if (paramCount == 0 || this->pointerToParam)
    3839    this->loadString = "none";
    3940  else
     
    6364
    6465      va_list types;
    65       va_start (types, multi);
     66      va_start (types, pointerToParam);
    6667      for(int i = 0; i < paramCount; i++)
    6768        {
  • orxonox/trunk/src/util/loading/load_param.h

    r4597 r4598  
    2626#include "debug.h"
    2727#include "substring.h"
     28#include "tinyxml.h"
    2829
    2930// Forward Declaration //
     
    4142/**
    4243   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
    6975
    7076// 1. TYPE
     
    7581#define LoadParam1(type1) \
    7682 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) \
    7884    { \
    7985      if (loadString != NULL && root != NULL) \
     
    9298#define LoadParam2(type1, type2) \
    9399 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) \
    95101    { \
    96102      if (loadString != NULL && root != NULL) \
     
    117123#define LoadParam3(type1, type2, type3) \
    118124 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) \
    120126    { \
    121127      if (loadString != NULL && root != NULL) \
     
    143149#define LoadParam4(type1, type2, type3, type4) \
    144150 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) \
    146152    { \
    147153      if (loadString != NULL && root != NULL) \
     
    170176#define LoadParam5(type1, type2, type3, type4, type5) \
    171177 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) \
    173179    { \
    174180      if (loadString != NULL && root != NULL) \
     
    185191    }
    186192
     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}
    187207
    188208//! A class that handles the description of loadable parameters
     
    235255
    236256 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, ...);
    238258
    239259 protected:
     
    241261  LoadParamDescription*    paramDesc;            //!< The LoadParameterDescription of this LoadParameter
    242262  const char*              loadString;           //!< The string loaded by this LoadParam
     263  const void*              pointerToParam;       //!< A Pointer to a Parameter.
    243264};
    244265
     
    249270 public:
    250271  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, "")
    252273    {
    253274      if (loadString != NULL && root != NULL)
     
    284305  //! makes functions with four floats loadable
    285306  LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);
     307
     308  LoadParamPT(l_XML_ELEM);
    286309};
    287310
Note: See TracChangeset for help on using the changeset viewer.