Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9703 in orxonox.OLD for branches/new_class_id


Ignore:
Timestamp:
Aug 25, 2006, 12:11:45 PM (18 years ago)
Author:
bensch
Message:

orxonox/new_object_list: fast factory, ObjectManager, and Hud adapted

Location:
branches/new_class_id/src/util
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/util/fast_factory.cc

    r9406 r9703  
    2222
    2323
    24 
    25 /**
    26  * Initializes a FastFactory
     24NewObjectListDefinition(FastFactory);
     25
     26/**
     27 * @brief Initializes a FastFactory
    2728 * @param classID the ClassID this Class belongs to (the top-most)
    2829 * @param fastFactoryName the Name of the ObjectClass-handled here
    2930 * @return a new FastFactory
    3031 */
    31 FastFactory::FastFactory (ClassID classID, const std::string& fastFactoryName)
    32 {
    33   this->setClassID(CL_FAST_FACTORY, "FastFactory");
     32FastFactory::FastFactory (const NewClassID& classID, const std::string& fastFactoryName)
     33{
     34  this->registerObject(this, FastFactory::_objectList);
    3435  this->setName(fastFactoryName);
    3536
     
    9798 * @returns true if found, false otherwise.
    9899 */
    99 FastFactory* FastFactory::searchFastFactory(ClassID classID)
     100FastFactory* FastFactory::searchFastFactory(const NewClassID& classID)
    100101{
    101102  if (FastFactory::first == NULL)
     
    228229 * @return the Object to resurrect, NULL if classID is not found.
    229230 */
    230 BaseObject* FastFactory::resurrect(ClassID classID)
     231BaseObject* FastFactory::resurrect(const NewClassID& classID)
    231232{
    232233  FastFactory* tmpFac = FastFactory::getFirst();
  • branches/new_class_id/src/util/fast_factory.h

    r7221 r9703  
    4343//! A struct, that holds Lists of Objects of a certain type.
    4444typedef struct FastObjectMember
    45   {
    46     BaseObject*          objectPointer;      //!< Pointer to the Object Stored in this Class (if it is the DeadList, else it is bork)
     45{
     46  BaseObject*          objectPointer;      //!< Pointer to the Object Stored in this Class (if it is the DeadList, else it is bork)
    4747
    48     FastObjectMember*    next;               //!< the next stored FastObjectMember. (or NULL if this is the last one stored in either the deadList or the unusedContainers)
    49   };
     48  FastObjectMember*    next;               //!< the next stored FastObjectMember. (or NULL if this is the last one stored in either the deadList or the unusedContainers)
     49};
    5050
    5151//! The FastFactory is a fast loadable object creator, and Dynamic List of dead object handler.
     
    5959 */
    6060class FastFactory : public BaseObject
    61   {
     61{
     62  NewObjectListDeclaration(FastFactory);
    6263
    63   public:
    64     virtual ~FastFactory ();
    65     static void deleteAll();
     64public:
     65  virtual ~FastFactory ();
     66  static void deleteAll();
    6667
    67     // functions to push and pop elements of this class
    68     BaseObject* resurrect();
    69     static BaseObject* resurrect(ClassID classID);
    70     void kill(BaseObject* object);
    71     static void kill(BaseObject* object, bool searchForFastFactory);
     68  // functions to push and pop elements of this class
     69  BaseObject* resurrect();
     70  static BaseObject* resurrect(const NewClassID& classID);
     71  void kill(BaseObject* object);
     72  static void kill(BaseObject* object, bool searchForFastFactory);
    7273
    73     void prepare(unsigned int count);
     74  void prepare(unsigned int count);
    7475
    75     static void flushAll(bool hardFLUSH = false);
    76     void flush(bool hardFLUSH = false);
     76  static void flushAll(bool hardFLUSH = false);
     77  void flush(bool hardFLUSH = false);
    7778
    78     /** @returns the first FastFactory */
    79     inline static FastFactory* getFirst() { return FastFactory::first; };
     79  /** @returns the first FastFactory */
     80  inline static FastFactory* getFirst() { return FastFactory::first; };
    8081
    81     static FastFactory* searchFastFactory(ClassID classID);
    82     static FastFactory* searchFastFactory(const std::string& fastFactoryName);
     82  static FastFactory* searchFastFactory(const NewClassID& classID);
     83  static FastFactory* searchFastFactory(const std::string& fastFactoryName);
    8384
    84     ClassID getStoredID() const { return this->storedClassID; };
     85  const NewClassID& getStoredID() const { return this->storedClassID; };
    8586
    86   protected:
    87     FastFactory (ClassID classID, const std::string& fastFactoryName = "");
     87protected:
     88  FastFactory (const NewClassID& classID, const std::string& fastFactoryName = "");
    8889
    89     /** sets the Next factory in the list @param nextFactory the next factory */
    90     inline void setNext( FastFactory* nextFastFactory) { this->next = nextFastFactory; };
    91     /** @returns the next FastFactory */
    92     FastFactory* getNext() const { return this->next; };
     90  /** sets the Next factory in the list @param nextFactory the next factory */
     91  inline void setNext( FastFactory* nextFastFactory) { this->next = nextFastFactory; };
     92  /** @returns the next FastFactory */
     93  FastFactory* getNext() const { return this->next; };
    9394
    94     /** generates a new Object of the Class T */
    95     virtual void fabricate() = 0;
     95  /** generates a new Object of the Class T */
     96  virtual void fabricate() = 0;
    9697
    97   private:
    98     static void registerFastFactory(FastFactory* fastFactory);
     98private:
     99  static void registerFastFactory(FastFactory* fastFactory);
    99100
    100   protected:
    101     ClassID               storedClassID;        //!< The classID of the specified class.
    102     unsigned int          storedDeadObjects;    //!< How many dead objects are stored in this class
     101protected:
     102  NewClassID            storedClassID;        //!< The classID of the specified class.
     103  unsigned int          storedDeadObjects;    //!< How many dead objects are stored in this class
    103104
    104     FastObjectMember*     deadList;             //!< A List of all stored dead Objects of this class.
    105     FastObjectMember*     unusedContainers;     //!< This is a List of unused containers, that will be reused by kill.
     105  FastObjectMember*     deadList;             //!< A List of all stored dead Objects of this class.
     106  FastObjectMember*     unusedContainers;     //!< This is a List of unused containers, that will be reused by kill.
    106107
    107   private:
    108     static FastFactory*   first;                //!< A pointer to the first FastFactory.
     108private:
     109  static FastFactory*   first;                //!< A pointer to the first FastFactory.
    109110
    110     FastFactory*          next;                 //!< pointer to the next FastFactory.
    111   };
     111  FastFactory*          next;                 //!< pointer to the next FastFactory.
     112};
    112113
    113114
     
    119120template<class T>
    120121class tFastFactory : public FastFactory
    121   {
    122   public:
    123     static tFastFactory<T>* getFastFactory(ClassID classID, const std::string& fastFactoryName = NULL);
     122{
     123public:
     124  static tFastFactory<T>* getFastFactory(const NewClassID& classID, const std::string& fastFactoryName = NULL);
    124125
    125   private:
    126     tFastFactory(ClassID classID, const std::string& fastFactoryName);
     126private:
     127  tFastFactory(const NewClassID& classID, const std::string& fastFactoryName);
    127128
    128     virtual void fabricate();
    129   };
     129  virtual void fabricate();
     130};
    130131
    131132/**
     
    136137 */
    137138template<class T>
    138 tFastFactory<T>::tFastFactory(ClassID classID, const std::string& fastFactoryName)
     139tFastFactory<T>::tFastFactory(const NewClassID& classID, const std::string& fastFactoryName)
    139140    : FastFactory(classID, fastFactoryName)
    140141{}
     
    147148 */
    148149template<class T>
    149     tFastFactory<T>* tFastFactory<T>::getFastFactory(ClassID classID, const std::string& fastFactoryName)
     150tFastFactory<T>* tFastFactory<T>::getFastFactory(const NewClassID& classID, const std::string& fastFactoryName)
    150151{
    151152  tFastFactory<T>* tmpFac = NULL;
  • branches/new_class_id/src/util/hud.cc

    r9406 r9703  
    3434#include "playable.h"
    3535
     36NewObjectListDefinition(Hud);
    3637/**
    3738 * standard constructor
     
    4041Hud::Hud ()
    4142{
    42   this->setClassID(CL_HUD, "Hud");
     43  this->registerObject(this, Hud::_objectList);
    4344
    4445  //this->setSize2D(
     
    186187    printf("UPDATING RADAR\n");
    187188    this->_radar->setCenterNode(State::getPlayer()->getPlayable());
    188     this->_radar->addEntityList(&State::getObjectManager()->getObjectList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0));
    189     this->_radar->addEntityList(&State::getObjectManager()->getObjectList(OM_GROUP_02), Color(1.0, .2, .2));
     189    this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0));
     190    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_02), Color(1.0, .2, .2));
    190191    this->_radar->setAbsCoor2D(0.8 * this->resX, 0.01 * this->resY);
    191192    this->_radar->setWidgetSize(0.2 * this->resX, 0.2 * this->resY);
  • branches/new_class_id/src/util/hud.h

    r8995 r9703  
    2323class Hud : public Element2D, public EventListener
    2424{
     25  NewObjectListDeclaration(Hud);
    2526
    2627public:
  • branches/new_class_id/src/util/object_manager.cc

    r9656 r9703  
    1717
    1818#include "object_manager.h"
    19 #include "class_list.h"
    2019
    2120#include "world_entity.h"
     
    3029    ->defaultValues("", 0);
    3130
     31NewObjectListDefinition(ObjectManager);
    3232/**
    3333 * @brief standard constructor
     
    3535ObjectManager::ObjectManager ()
    3636{
    37    this->setClassID(CL_OBJECT_MANAGER, "ObjectManager");
     37  this->registerObject(this, ObjectManager::_objectList);
    3838   this->setName("ObjectManager");
    3939
     
    6363{
    6464  for (unsigned int i = 0; i < OM_SIZE; ++i)
    65     while(!this->objectLists[i].empty())
    66       delete this->objectLists[i].front();
     65    while(!this->entityLists[i].empty())
     66      delete this->entityLists[i].front();
    6767
    6868  // delete reflection list
     
    8383
    8484  if (likely(entity->getOMListNumber() != OM_INIT))
    85     this->objectLists[entity->getOMListNumber()].erase(entity->getEntityIterator());
     85    this->entityLists[entity->getOMListNumber()].erase(entity->getEntityIterator());
    8686
    8787  if (likely(omList != OM_INIT))
    8888  {
    89     this->objectLists[omList].push_back(entity);
    90     entity->getEntityIterator() = --this->objectLists[omList].end();
     89    this->entityLists[omList].push_back(entity);
     90    entity->getEntityIterator() = --this->entityLists[omList].end();
    9191    entity->getOMListNumber() = omList;
    9292  }
     
    111111 * @returns a new List with a list of WorldEntities of distance Radius from center
    112112 */
    113 void ObjectManager::distanceFromObject(EntityList& entities, const PNode& center, float radius, ClassID classID)
    114 {
    115   const std::list<BaseObject*>* objectList = ClassList::getList(classID);
    116   if (objectList != NULL)
     113  /*
     114void ObjectManager::distanceFromObject(EntityList& entities, const PNode& center, float radius, const NewClassID& classID)
     115{
     116  TODO FIXME
     117
     118  const std::list<BaseObject*>* entityList = ClassList::getList(classID);
     119  if (entityList != NULL)
    117120  {
    118121
    119122    std::list<BaseObject*>::const_iterator node;
    120     for (node = objectList->begin(); node != objectList->end(); node++)
     123    for (node = entityList->begin(); node != entityList->end(); node++)
    121124      if ((dynamic_cast<PNode*>(*node)->getAbsCoor() - center.getAbsCoor()).len() < radius)
    122125        entities.push_back(dynamic_cast<WorldEntity*>(*node));
    123126  }
    124127}
     128  */
    125129
    126130
     
    134138  if (omList != OM_INIT || omList == OM_SIZE)
    135139  {
    136     PRINT(0)(" +ObjectManager-LIST: '%s'==size='%d'==---\n", ObjectManager::OMListToString((OM_LIST)omList).c_str(), this->objectLists[omList].size());
     140    PRINT(0)(" +ObjectManager-LIST: '%s'==size='%d'==---\n", ObjectManager::OMListToString((OM_LIST)omList).c_str(), this->entityLists[omList].size());
    137141  //  if (level >= 1)
    138142    {
    139143      ObjectManager::EntityList::const_iterator entity;
    140       for (entity = this->objectLists[omList].begin(); entity != this->objectLists[omList].end(); entity++)
     144      for (entity = this->entityLists[omList].begin(); entity != this->entityLists[omList].end(); entity++)
    141145      {
    142146        PRINT(0)(" | %s::%s\n",(*entity)->getClassCName(), (*entity)->getCName());
  • branches/new_class_id/src/util/object_manager.h

    r9685 r9703  
    7373class ObjectManager : public BaseObject
    7474{
     75  NewObjectListDeclaration(ObjectManager);
    7576public:
    7677  typedef std::list<WorldEntity*> EntityList;      //!< A type definition to make it easy to use EntityLists.
     
    8687
    8788  /** @returns the List (listnumber) of objects. @param listNumber the List to get. */
    88   EntityList& getObjectList(OM_LIST listNumber) { return this->objectLists[listNumber]; }
     89  EntityList& getEntityList(OM_LIST listNumber) { return this->entityLists[listNumber]; }
    8990  /** @returns a constant LIST of Objects. @param listNumber the objectList to returns */
    90   const EntityList& getObjectList(OM_LIST listNumber) const { return this->objectLists[listNumber]; }
     91  const EntityList& getEntityList(OM_LIST listNumber) const { return this->entityLists[listNumber]; }
    9192
    9293  template <class T> static void distanceFromObject(EntityList& entities, const PNode& center, float radius, NewObjectList<T>& list);
     
    111112  const std::list<BaseObject>*            pNodeList;                //!< The List of PNodes.
    112113
    113   EntityList                              objectLists[OM_SIZE];     //!< The ObjectLists.
     114  EntityList                              entityLists[OM_SIZE];     //!< The ObjectLists.
    114115
    115116  static const std::string                objectManagerListNames[]; //!< Names of all the lists
Note: See TracChangeset for help on using the changeset viewer.