Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5622 in orxonox.OLD for branches


Ignore:
Timestamp:
Nov 17, 2005, 1:20:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/world_entities: Factory is now also able to fabricate by ClassID
for this the construction-MACRO changed from
CREATE_FACTORY(CLASS_NAME)
to
CREATE_FACTORY(CLASS_NAME, CLASS_ID)

Location:
branches/world_entities/src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/world_entities/src/lib/graphics/light.cc

    r5357 r5622  
    2929using namespace std;
    3030
    31 CREATE_FACTORY(Light);
     31CREATE_FACTORY(Light, CL_LIGHT);
    3232
    3333//! Definition of the Lights and their Names
  • branches/world_entities/src/lib/gui/gl_gui/glmenu/glmenu_imagescreen.cc

    r5373 r5622  
    2525#include "load_param.h"
    2626
    27 CREATE_FACTORY(GLMenuImageScreen);
     27CREATE_FACTORY(GLMenuImageScreen, CL_GLMENU_IMAGE_SCREEN);
    2828
    2929using namespace std;
  • branches/world_entities/src/lib/particles/particle_emitter.cc

    r5445 r5622  
    2828
    2929
    30 CREATE_FACTORY(ParticleEmitter);
     30CREATE_FACTORY(ParticleEmitter, CL_PARTICLE_EMITTER);
    3131
    3232/**
  • branches/world_entities/src/lib/particles/particle_system.cc

    r5511 r5622  
    3232#include "tinyxml.h"
    3333
    34 CREATE_FACTORY(ParticleSystem);
     34CREATE_FACTORY(ParticleSystem, CL_PARTICLE_SYSTEM);
    3535SHELL_COMMAND(texture, ParticleSystem, setMaterialTexture)
    3636    ->defaultValues(1, "maps/evil-flower.png");
  • branches/world_entities/src/lib/physics/fields/gravity.cc

    r5357 r5622  
    2323using namespace std;
    2424
    25 CREATE_FACTORY(Gravity);
     25CREATE_FACTORY(Gravity, CL_FIELD_GRAVITY);
    2626
    2727Gravity::Gravity(const TiXmlElement* root)
  • branches/world_entities/src/lib/physics/physics_connection.cc

    r5357 r5622  
    2929using namespace std;
    3030
    31 CREATE_FACTORY(PhysicsConnection);
     31CREATE_FACTORY(PhysicsConnection, CL_PHYSICS_CONNECTION);
    3232
    3333/**
  • branches/world_entities/src/story_entities/world.cc

    r5558 r5622  
    8181
    8282//! This creates a Factory to fabricate a World
    83 CREATE_FACTORY(World);
     83CREATE_FACTORY(World, CL_WORLD);
    8484
    8585World::World(const TiXmlElement* root)
  • branches/world_entities/src/subprojects/collision_detection/collision_test_entity.cc

    r5487 r5622  
    2626
    2727using namespace std;
    28 CREATE_FACTORY(CollisionTestEntity);
     28CREATE_FACTORY(CollisionTestEntity, CL_ENVIRONMENT);
    2929
    3030/**
  • branches/world_entities/src/util/loading/factory.cc

    r5298 r5622  
    3434   set everything to zero and define factoryName
    3535*/
    36 Factory::Factory (const char* factoryName)
     36Factory::Factory (const char* factoryName, ClassID classID)
    3737{
    3838  this->setClassID(CL_FACTORY, "Factory");
     
    4040
    4141  this->next = NULL;
     42  this->classID = classID;
    4243
    4344  Factory::registerFactory(this);
  • branches/world_entities/src/util/loading/factory.h

    r5357 r5622  
    3333 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    3434*/
    35 #define CREATE_FACTORY(CLASS_NAME) \
    36     tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME)
     35#define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \
     36    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
    3737
    3838//! The Factory is a loadable object handler
     
    4040
    4141 public:
    42   Factory (const char* factoryName = NULL);
     42  Factory (const char* factoryName = NULL, ClassID classID = CL_NULL);
    4343  virtual ~Factory ();
    4444
    4545  void fabricate(const char* className, const char* entityName);
     46  virtual BaseObject* fabricate(ClassID classID) = NULL;
    4647  virtual BaseObject* fabricate(const TiXmlElement* root) = NULL;
    4748  virtual BaseObject* fabricateDirect() = NULL;
     
    5758    Factory* getNext() const { return this->next; };
    5859
     60
     61  protected:
     62    ClassID           classID;              //!< The CLass-Identifyer of the Factory.
     63
    5964  private:
    6065    Factory*          next;                 //!< pointer to the next factory.
     
    6469/**
    6570 *  a factory that is able to load any kind of Object
    66    (this is a Functor)
    67 */
     71 * (this is a Functor)
     72 */
    6873template<class T> class tFactory : public Factory
    6974{
    70  public:
    71   tFactory(const char* factoryName);
    72   virtual ~tFactory();
     75  public:
     76    tFactory(const char* factoryName, ClassID classID);
     77    virtual ~tFactory();
    7378
    7479  private:
    75   virtual BaseObject* fabricate(const TiXmlElement* root);
    76   virtual BaseObject* fabricateDirect();
     80    virtual BaseObject* fabricate(ClassID classID);
     81    virtual BaseObject* fabricate(const TiXmlElement* root);
     82    virtual BaseObject* fabricateDirect();
    7783};
    7884
     
    8288*/
    8389template<class T>
    84 tFactory<T>::tFactory(const char* factoryName) : Factory(factoryName)
     90    tFactory<T>::tFactory(const char* factoryName, ClassID classID) : Factory(factoryName, classID)
    8591{
    8692  PRINTF(4)("Class: %s loadable\n", this->getName());
    8793}
    8894
    89 
     95/**
     96 * destructs the type-Factory
     97 */
    9098template<class T>
    91 tFactory<T>::~tFactory()
     99    tFactory<T>::~tFactory()
    92100{}
    93101
     102/**
     103 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
     104 * @param root the TiXmlElement T should load parameters from.
     105 * @return the newly fabricated T, NULL otherwise.
     106 */
    94107template<class T>
    95 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root)
     108    BaseObject* tFactory<T>::fabricate(const TiXmlElement* root)
    96109{
    97110  if (root == NULL)
     
    106119}
    107120
     121
     122/**
     123 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
     124 * @param classID the ClassID of T that should be created.
     125 * @return the newly fabricated T if fabricated NULL otherwise.
     126 */
     127template<class T>
     128    BaseObject* tFactory<T>::fabricate(ClassID classID)
     129{
     130  if(classID == this->classID)
     131    return this->fabricateDirect();
     132  else if( getNext() != NULL)
     133    return getNext()->fabricate( classID);
     134  else
     135    return NULL;
     136}
     137
     138/**
     139 * directly fabricate an Entity of this factory.
     140 */
    108141template<class T>
    109142    BaseObject* tFactory<T>::fabricateDirect()
  • branches/world_entities/src/world_entities/environment.cc

    r5500 r5622  
    2828
    2929using namespace std;
    30 CREATE_FACTORY(Environment);
     30CREATE_FACTORY(Environment, CL_ENVIRONMENT);
    3131
    3232/**
  • branches/world_entities/src/world_entities/player.cc

    r5621 r5622  
    3737using namespace std;
    3838
    39 CREATE_FACTORY(Player);
     39CREATE_FACTORY(Player, CL_PLAYER);
    4040
    4141/**
     
    8383  Weapon* wpLeft = new TestGun(this->weaponMan, 1);
    8484  wpLeft->setName("testGun Left");
    85   Weapon* cannon = new Cannon(this->weaponMan);
     85  Weapon* cannon = dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(CL_CANNON));
     86  cannon->setWeaponManager(this->weaponMan);
    8687  cannon->setName("BFG");
    8788
  • branches/world_entities/src/world_entities/power_ups/laser_power_up.cc

    r5500 r5622  
    2525using namespace std;
    2626
    27 CREATE_FACTORY(LaserPowerUp);
     27CREATE_FACTORY(LaserPowerUp, CL_LASER_POWER_UP);
    2828
    2929LaserPowerUp::LaserPowerUp ()
  • branches/world_entities/src/world_entities/power_ups/turret_power_up.cc

    r5500 r5622  
    2525using namespace std;
    2626
    27 CREATE_FACTORY(TurretPowerUp);
     27CREATE_FACTORY(TurretPowerUp, CL_TURRET_POWER_UP);
    2828
    2929TurretPowerUp::TurretPowerUp ()
  • branches/world_entities/src/world_entities/skybox.cc

    r5511 r5622  
    2525using namespace std;
    2626
    27 CREATE_FACTORY(SkyBox);
     27CREATE_FACTORY(SkyBox, CL_SKYBOX);
    2828
    2929/**
  • branches/world_entities/src/world_entities/terrain.cc

    r5511 r5622  
    2929using namespace std;
    3030
    31 CREATE_FACTORY(Terrain);
     31CREATE_FACTORY(Terrain, CL_TERRAIN);
    3232
    3333/**
  • branches/world_entities/src/world_entities/weapons/aiming_turret.cc

    r5576 r5622  
    3030#include "factory.h"
    3131
    32 CREATE_FACTORY(AimingTurret);
     32CREATE_FACTORY(AimingTurret, CL_AIMING_TURRET);
    3333
    3434using namespace std;
  • branches/world_entities/src/world_entities/weapons/cannon.cc

    r5621 r5622  
    4141using namespace std;
    4242
    43 CREATE_FACTORY(Cannon);
     43CREATE_FACTORY(Cannon, CL_CANNON);
    4444
    4545/**
  • branches/world_entities/src/world_entities/weapons/test_gun.cc

    r5500 r5622  
    4141using namespace std;
    4242
    43 CREATE_FACTORY(TestGun);
     43CREATE_FACTORY(TestGun, CL_TEST_GUN);
    4444
    4545/**
  • branches/world_entities/src/world_entities/weapons/turret.cc

    r5512 r5622  
    3030#include "factory.h"
    3131
    32 CREATE_FACTORY(Turret);
     32CREATE_FACTORY(Turret, CL_TURRET);
    3333
    3434using namespace std;
Note: See TracChangeset for help on using the changeset viewer.