Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4938 in orxonox.OLD for orxonox/trunk/src/util/object_manager.h


Ignore:
Timestamp:
Jul 22, 2005, 11:57:38 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: doxygen tags.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/object_manager.h

    r4937 r4938  
    11/*!
    2     \file object_manager.h
    3   *  this manager will ceep track of the objects  in the world
    4 
    5     This is specially designed to:
    6     - Give an interface to the world data
    7     - separate the world data from the world build,update,draw process
    8     - recycle deleted objects: specific for Projectils since there is a lot of world entity creation/deletion (and this needs a lot of time)
    9     - control the garbage collector
    10 
    11     TO ADD SUPPORT FOR A CLASS do the following steps:
    12     1. include the hader file : #include "class_id.h"
    13     2. add the class to the type enum classID {}; in class_id.h
    14     3. define a function void mCache( ClassName ) in class ObjectManager
    15 
     2 * @file object_manager.h
     3 * The ObjectManager (FastFactory) is designed, to automatically generate and remove
     4 * (without to much overhead) many instances of different classes.
     5 *
     6 * It is especially usefull for objects, that come only for a short time into existence,
     7 * and get killed after a small amount of time (like shots).
     8 *
     9 * The Creation of an Object is usually done in the Weapon Class, where one subscribes
     10 * a Projectile with:
     11 * this->bulletFactory = tFastFactory<TestBullet>::getFastFactory(CL_TEST_BULLET, "TestBullet");
     12 * (this might change over time).
     13 * Then you can at loading time initialize an amount of the class with something like:
     14 * this->bulletFactory->prepare(100); // creates 100 entities of TestBullet (dead ones)
     15 * afterwards one can just retrieve an Object form the Class with
     16 * this->bulletFactory->resurrect();  // this returns a BaseObject an Object of the class.
    1617*/
    1718
     
    2122
    2223#include "base_object.h"
    23 #include "class_id.h"
    2424
     25
     26// FORWARD DECLARATION //
     27class GarbageCollector;
    2528template<class T> class tList;
    26 class GarbageCollector;
    27 
    2829
    2930/**
     
    3637struct FastObjectMember
    3738{
    38   BaseObject*               objectPointer;
     39  BaseObject*          objectPointer;      //!< Pointer to the Object Stored in this Class (if it is the DeadList, else it is bork)
    3940
    40   FastObjectMember*         next;
     41  FastObjectMember*    next;               //!< the next stored FastObjectMember. (or NULL if this is the last one stored in either the deadList or the unusedContainers)
    4142};
    4243
    4344//! The FastFactory is a fast loadable object creator, and Dynamic List of dead object handler.
    4445/**
     46 * The ObjectManager (FastFactory) is designed, to automatically generate and remove
     47 * (without to much overhead) many instances of different classes.
     48 *
    4549 * FastFactory is needed to glue all the tFastFactory<T>'s together.
    46  * Furthermore one can retrieve the corresponding tFastFactory over
    47  * tFastFactory<T>* = FastFacroty::getFastFactory(ID);
     50 * It is also the general class that implements the necessary functions
     51 * to generate, resurrect kill and stuff...
    4852 */
    4953class FastFactory : public BaseObject {
     
    5357
    5458    // functions to push and pop elements of this class
    55     BaseObject* resurect(ClassID classID);
    56     void kill(ClassID classID, BaseObject* object);
     59    BaseObject* resurrect();
     60    static BaseObject* resurrect(ClassID classID);
     61    void kill(BaseObject* object);
     62    static void kill(BaseObject* object, ClassID classID);
    5763
    58     virtual void fabricate() = NULL;
    5964    void prepare(unsigned int count);
    6065    // retrival functions for fast Ineraction
     
    7681
    7782//    virtual BaseObject* fabricate(ClassID classID) = NULL;
    78 
     83    virtual void fabricate() = NULL;
    7984    static FastFactory* searchFastFactory(ClassID classID, const char* fastFactoryName = NULL);
    8085
     
    104109    static tFastFactory<T>* getFastFactory(ClassID classID, const char* fastFactoryName = NULL);
    105110
    106     T* resurect();
    107111  private:
    108112    tFastFactory(ClassID classID, const char* fastFactoryName);
    109113
    110114    virtual void fabricate();
    111 
    112   private:
    113115};
    114116
     
    149151}
    150152
    151 template<class T>
    152     T* tFastFactory<T>::resurect()
    153 {
    154   PRINTF(4)("Resurecting Object of type %s\n", this->getName());
    155   if (unlikely(this->deadList == NULL))
    156   {
    157     PRINTF(2)("The deadList of Class %s is empty, this may be either because it has not been filled yet, or the cache is to small.\n" \
    158         "Fabricating a new %s", this->getName(), this->getName());
    159     this->fabricate();
    160     return resurect();
    161   }
    162   else
    163   {
    164     FastObjectMember* tmpC = deadList;
    165     this->deadList = this->deadList->next;
    166153
    167     tmpC->next = this->unusedContainers;
    168     this->unusedContainers = tmpC;
    169154
    170     return dynamic_cast<T*>(tmpC->objectPointer);
    171   }
    172 }
     155
     156
     157
     158
     159
    173160
    174161////////////////////
     
    186173  void registerClass(ClassID classID);
    187174
    188   BaseObject* resurect();
     175  BaseObject* resurrect();
    189176  void kill(BaseObject* object);
    190177
Note: See TracChangeset for help on using the changeset viewer.