Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4597 in orxonox.OLD for orxonox/trunk/src/util/loading


Ignore:
Timestamp:
Jun 11, 2005, 12:55:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: setClassID implemented in all files

Location:
orxonox/trunk/src/util/loading
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/loading/factory.cc

    r4492 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    2121
    2222/*  --------------------------------------------------
    23  *              Factory
     23 *              Factory
    2424 *   --------------------------------------------------
    2525 */
     
    2727/**
    2828   \brief constructor
    29    
     29
    3030   set everything to zero and define factoryName
    3131*/
    3232Factory::Factory (const char* factoryName)
    3333{
     34  this->setClassID(CL_FACTORY, "Factory");
     35  this->setName(factoryName);
     36
    3437  this->factoryName = NULL;
    3538  this->setFactoryName(factoryName);
    3639  next = NULL;
    37  
     40
    3841  initialize();
    3942}
     
    4144/**
    4245   \brief destructor
    43    
     46
    4447   clear the Q
    4548*/
  • orxonox/trunk/src/util/loading/factory.h

    r4492 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    1414*/
    1515
    16 /*! 
     16/*!
    1717  \file factory.h
    1818  \brief A loadable object handler
     
    2727#include "tinyxml.h"
    2828#include "load_param.h"
     29#include "base_object.h"
    2930#include "debug.h"
    3031
    31 /** 
     32/**
    3233    Creates a factory to a Loadable Class.
    3334    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)
    3436*/
    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)
    3638
    3739//! The Factory is a loadable object handler
    38 class Factory {
     40class Factory : public BaseObject {
    3941
    4042 public:
    4143  Factory (const char* factoryName = NULL);
    4244  ~Factory ();
    43  
     45
    4446
    4547  virtual BaseObject* fabricate(const TiXmlElement* root);
     
    5355  /** \returns the next factory */
    5456  Factory* getNext(void) const { return this->next; };
    55        
     57
    5658 protected:
    5759  char*         factoryName;          //!< the name of the factory
     
    6971  tFactory(const char* factoryName);
    7072  virtual ~tFactory();
    71  
     73
    7274  private:
    7375  BaseObject* fabricate(const TiXmlElement* root);
     
    8385  PRINTF(5)("fileName: %s loadable\n", this->factoryName);
    8486}
    85  
     87
    8688
    8789template<class T>
     
    9092
    9193template<class T>
    92 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root) 
    93 { 
     94BaseObject* tFactory<T>::fabricate(const TiXmlElement* root)
     95{
    9496  if(!strcmp(root->Value(), getFactoryName()))
    9597    return new T ( root);
    96   else if( getNext() != NULL) 
     98  else if( getNext() != NULL)
    9799    return getNext()->fabricate( root);
    98   else 
     100  else
    99101    return NULL;
    100102}
  • orxonox/trunk/src/util/loading/game_loader.cc

    r4511 r4597  
    11
    22
    3 /* 
     3/*
    44   orxonox - the future of 3D-vertical-scrollers
    55
     
    3939   \brief simple constructor
    4040*/
    41 GameLoader::GameLoader ()
    42 {
     41GameLoader::GameLoader ()
     42{
     43  this->setClassID(CL_GAME_LOADER, "GameLoader");
     44  this->setName("GameLoader");
    4345  first = NULL;
    4446}
     
    110112  switch(campaignID)
    111113    {
    112       /* 
    113         Debug Level 0: Debug level used to test the base frame work.
    114         As you can see, all storyentity data is allocated before game
    115         start. the storyentity will load themselfs shortly before start
    116         through the StoryEntity::init() funtion.
     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.
    117119      */
    118120    case DEBUG_CAMPAIGN_0:
    119121      {
    120         Campaign* debugCampaign = new Campaign();
    121 
    122         World* world0 = new World(DEBUG_WORLD_0);
    123         world0->setNextStoryID(WORLD_ID_1);
    124         debugCampaign->addEntity(world0, WORLD_ID_0);
    125 
    126         World* world1 = new World(DEBUG_WORLD_1);
    127         world1->setNextStoryID(WORLD_ID_2);
    128         debugCampaign->addEntity(world1, WORLD_ID_1);
    129 
    130         World* world2 = new World(DEBUG_WORLD_2);
    131         world2->setNextStoryID(WORLD_ID_GAMEEND);
    132         debugCampaign->addEntity(world2, WORLD_ID_2);
    133 
    134         this->currentCampaign = debugCampaign;
    135         break;
     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;
    136138      }
    137139    }
     
    139141
    140142
    141 /** 
     143/**
    142144    \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
    144146*/
    145147ErrorMessage GameLoader::start()
     
    150152
    151153
    152 /** 
     154/**
    153155    \brief stops the current entity
    154156    \returns error code if this action has caused a error
     
    168170
    169171
    170 /** 
     172/**
    171173    \brief pause the current entity
    172174    \returns error code if this action has caused a error
     
    182184
    183185
    184 /** 
     186/**
    185187    \brief resumes a pause
    186188    \returns error code if this action has caused a error
     
    218220     can load everything it needs into memory then.
    219221  */
    220  
     222
    221223  if( fileName == NULL)
    222224    {
     
    224226      return NULL;
    225227    }
    226  
     228
    227229  TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);
    228230  // load the campaign document
     
    234236      return NULL;
    235237    }
    236        
     238
    237239  // check basic validity
    238240  TiXmlElement* root = XMLDoc->RootElement();
    239241  assert( root != NULL);
    240        
     242
    241243  if( strcmp( root->Value(), "Campaign"))
    242244    {
     
    246248      return NULL;
    247249    }
    248        
     250
    249251  // construct campaign
    250252  Campaign* c = new Campaign( root);
    251        
     253
    252254  // free the XML data
    253255  delete XMLDoc;
     
    258260
    259261/**
    260    \brief handle keyboard commands 
     262   \brief handle keyboard commands
    261263   \param event the event to handle
    262264*/
     
    265267  if( event.type == KeyMapper::PEV_NEXT_WORLD)
    266268    {
    267       if( likely(event.bPressed)) 
    268         {
    269           this->nextLevel();
    270         }
     269      if( likely(event.bPressed))
     270        {
     271          this->nextLevel();
     272        }
    271273    }
    272274  else if( event.type == KeyMapper::PEV_PREVIOUS_WORLD)
    273275    {
    274276      if( likely(event.bPressed))
    275         {
    276           this->previousLevel();
    277         }
     277        {
     278          this->previousLevel();
     279        }
    278280    }
    279281  else if( event.type == KeyMapper::PEV_PAUSE)
    280282    {
    281283      if( likely(event.bPressed))
    282         {
    283           if(this->isPaused)
    284             this->resume();
    285           else
    286             this->pause();
    287         }
     284        {
     285          if(this->isPaused)
     286            this->resume();
     287          else
     288            this->pause();
     289        }
    288290    }
    289291  else if( event.type == KeyMapper::PEV_QUIT)
     
    322324void GameLoader::registerFactory( Factory* factory)
    323325{
    324         assert( factory != NULL);
    325        
    326         PRINTF(4)("Registered factory for '%s'\n", factory->getFactoryName());
    327        
    328         if( first == NULL) first = factory;
    329         else first->registerFactory( factory);
     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);
    330332}
    331333
     
    338340{
    339341  assert( element != NULL);
    340        
     342
    341343  if( first == NULL)
    342344    {
     
    344346      return NULL;
    345347    }
    346        
     348
    347349  if( element->Value() != NULL)
    348350    {
    349351      PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value());
    350352      BaseObject* b = first->fabricate( element);
    351       if( b == NULL) 
    352         PRINTF(2)("Failed to fabricate a '%s'\n", element->Value());
    353       else 
    354         PRINTF(4)("Successfully fabricated a '%s'\n", element->Value());
     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());
    355357      return b;
    356358    }
    357        
     359
    358360  PRINTF(2)("Fabricate failed, TiXmlElement did not contain a value\n");
    359        
     361
    360362  return NULL;
    361363}
  • orxonox/trunk/src/util/loading/load_param.cc

    r4501 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    3030*/
    3131BaseLoadParam::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");
    3435  this->loadString = NULL;
    3536
     
    3940    {
    4041      if (likely(!multi))
    41         this->loadString = grabParameter(root, paramName);
     42        this->loadString = grabParameter(root, paramName);
    4243      else
    43         {
    44           if (!strcmp(root->Value(), paramName))
    45             {
    46               const TiXmlNode* val = root->FirstChild();
    47               if( val->ToText())
    48                 this->loadString = val->Value();
    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        }
    5152    }
    5253
     
    6465      va_start (types, multi);
    6566      for(int i = 0; i < paramCount; i++)
    66         {
    67           const char* tmpTypeName = va_arg (types, const char*);
    68           this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1];
    69           strcpy(this->paramDesc->types[i], tmpTypeName);
    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        }
    7172      va_end(types);
    7273
     
    131132    {
    132133      if (i > 0)
    133         PRINT(3)(",");
     134        PRINT(3)(",");
    134135      PRINT(3)("%s", this->types[i]);
    135136    }
     
    194195    {
    195196      if (!strcmp(enumClassDesc->className, className))
    196         {
    197           delete iterator;
    198           return enumClassDesc;
    199         }
     197        {
     198          delete iterator;
     199          return enumClassDesc;
     200        }
    200201      enumClassDesc = iterator->nextElement();
    201202    }
     
    216217    {
    217218      if (!strcmp(enumParamDesc->paramName, paramName))
    218         {
    219           delete iterator;
    220           return enumParamDesc;
    221         }
     219        {
     220          delete iterator;
     221          return enumParamDesc;
     222        }
    222223      enumParamDesc = iterator->nextElement();
    223224    }
     
    243244      LoadParamDescription* enumParamDesc = paramIT->nextElement();
    244245      while (enumParamDesc)
    245         {
    246           enumParamDesc->print();
    247           enumParamDesc = paramIT->nextElement();
    248         }
     246        {
     247          enumParamDesc->print();
     248          enumParamDesc = paramIT->nextElement();
     249        }
    249250      delete paramIT;
    250251
     
    267268  const TiXmlElement* element;
    268269  const TiXmlNode* node;
    269        
     270
    270271  if (root == NULL)
    271272    return NULL;
    272273  assert( parameterName != NULL);
    273        
     274
    274275  element = root->FirstChildElement( parameterName);
    275276  if( element == NULL) return NULL;
    276        
     277
    277278  node = element->FirstChild();
    278279  while( node != NULL)
  • orxonox/trunk/src/util/loading/load_param.h

    r4592 r4597  
    2222#define _LOAD_PARAM_H
    2323
     24#include "base_object.h"
    2425#include "factory.h"
    2526#include "debug.h"
     
    228229
    229230//! abstract Base class for a Loadable parameter
    230 class BaseLoadParam
     231class BaseLoadParam : public BaseObject
    231232{
    232233 public:
Note: See TracChangeset for help on using the changeset viewer.