Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6142 in orxonox.OLD for trunk/src/util


Ignore:
Timestamp:
Dec 16, 2005, 7:13:57 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merge the ObjectManager to the trunk
merged with command:
svn merge -r6082:HEAD objectmanager/ ../trunk/

conflicts resolution was easy this time :)
but specially merged the world to network_world

Location:
trunk/src/util
Files:
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/Makefile.am

    r5750 r6142  
    77                        object_manager.cc \
    88                        loading/factory.cc \
    9                         garbage_collector.cc \
    109                        state.cc \
    1110                        user_control.cc \
     
    1918                        track/pilot_node.cc \
    2019                        track/track_manager.cc \
    21                         track/track_node.cc 
     20                        track/track_node.cc
    2221
    2322noinst_HEADERS =        fast_factory.h \
    2423                        object_manager.h \
    25                         garbage_collector.h \
    2624                        state.h \
    2725                        user_control.h \
  • trunk/src/util/object_manager.cc

    r5828 r6142  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
     
    1919#include "class_list.h"
    2020
    21 #include "p_node.h"
    2221#include "world_entity.h"
    23 #include "list.h"
     22
     23#include "shell_command.h"
     24
     25#include <assert.h>
    2426
    2527using namespace std;
    26 
    27 
    28 /**
    29  * standard constructor
     28SHELL_COMMAND(debug, ObjectManager, debug)
     29    ->defaultValues(2, NULL, 0);
     30
     31/**
     32 * @brief standard constructor
    3033 */
    3134ObjectManager::ObjectManager ()
     
    3740}
    3841
    39 /**
    40  *  the singleton reference to this class
    41  */
    42 ObjectManager* ObjectManager::singletonRef = NULL;
    43 
    44 /**
    45    @brief standard deconstructor
     42
     43/**
     44 * @brief standard deconstructor
     45 *
     46 * this also removes ALL entitites in existence.
    4647 */
    4748ObjectManager::~ObjectManager ()
    4849{
    49   ObjectManager::singletonRef = NULL;
    50 }
     50  this->flush();
     51}
     52
     53/**
     54 * @brief flushes all entities
     55 *
     56 * this function deletes all entities that exist within the ObjectManager.
     57 * It does this by poping each list from the front, and delete the given object.
     58 *
     59 * automatically called by a destructor.
     60 */
     61void ObjectManager::flush()
     62{
     63  for (unsigned int i = 0; i < OM_SIZE; ++i)
     64    while(!this->objectLists[i].empty())
     65      delete this->objectLists[i].front();
     66}
     67
     68
     69/**
     70 * @brief moves an Entity from an old list to a new One
     71 * @param entity the entity to move.
     72 * @param omList the new List to move the entity to.
     73 *
     74 * this will erase the entity from the old list
     75 */
     76void ObjectManager::toList (WorldEntity* entity, OM_LIST omList)
     77{
     78  assert (omList != OM_SIZE);
     79
     80  if (likely(entity->getOMListNumber() != OM_INIT))
     81    this->objectLists[entity->getOMListNumber()].erase(entity->getEntityIterator());
     82
     83  if (likely(omList != OM_INIT))
     84  {
     85    this->objectLists[omList].push_back(entity);
     86    entity->getEntityIterator() = --this->objectLists[omList].end();
     87    entity->getOMListNumber() = omList;
     88  }
     89}
     90
     91
     92/**
     93 * @see ObjectManager::toList(WorldEntity* OM_LIST)
     94 * @param entity the entity to move.
     95 * @param omList the new List to move the entity to.
     96 *
     97 * this function also does a transformation from omList as char* to OM_LIST.
     98 */
     99void ObjectManager::toList (WorldEntity* entity, const char* omList)
     100{
     101  this->toList(entity, ObjectManager::StringToOMList(omList));
     102}
     103
     104
    51105
    52106/**
     
    68122  return NULL;
    69123}
     124
     125
     126/**
     127 * @brief print out nice debug information about Elements in the list OM_LIST
     128 * @param omList the List to debug.
     129 * @param level: level 0: only show list info; level 1: also show entities and their names.
     130 */
     131void ObjectManager::debug(OM_LIST omList, unsigned int level) const
     132{
     133  if (omList != OM_INIT || omList == OM_SIZE)
     134  {
     135    PRINT(0)(" +ObjectManager-LIST: '%s'==size='%d'==---\n", ObjectManager::OMListToString((OM_LIST)omList), this->objectLists[omList].size());
     136  //  if (level >= 1)
     137    {
     138      std::list<WorldEntity*>::const_iterator entity;
     139      for (entity = this->objectLists[omList].begin(); entity != this->objectLists[omList].end(); entity++)
     140      {
     141        PRINT(0)(" | %s::%s\n",(*entity)->getClassName(), (*entity)->getName());
     142      }
     143    }
     144  }
     145  else
     146    PRINTF(2)("Invalid query. for OM_INIT-LIST or OM_SIZE\n");
     147}
     148
     149
     150/**
     151 * @brief prints out very nice debug information
     152 * @param listName the Name of the list to get Debug information from
     153 * @param level: level 0: only show list info; level 1: also show entities and their names.
     154 */
     155void ObjectManager::debug(const char* listName, unsigned int level)
     156{
     157  PRINT(0)("=================================\n");
     158  PRINT(0)("=ObjectManager-DEBUG=============\n");
     159  PRINT(0)("=================================\n");
     160  if (listName == NULL || listName[0] == '\0')
     161    for (unsigned int i = 0; i < OM_SIZE; ++i)
     162      debug((OM_LIST) i, level);
     163  else
     164    debug(ObjectManager::StringToOMList(listName));
     165  PRINT(0)("=========================== OM ==\n");
     166}
     167
     168
     169
     170/**
     171 * @brief transforms an omList into a String (usefull for debugging).
     172 * @param omList the OM_LIST to be transformed into a String.
     173 * @returns the String transformed from omList.
     174 */
     175const char* ObjectManager::OMListToString(OM_LIST omList)
     176{
     177  if (omList == OM_INIT || omList == OM_SIZE)
     178    return "===invalid===";
     179
     180  printf("%d\n", omList);
     181  return ObjectManager::objectManagerListNames[omList];
     182}
     183
     184
     185
     186/**
     187 * @brief transforms a String into an OM_LIST (usefull for debugging/Loading).
     188 * @param listName the OM_LIST-name to be transformed into an OM_LIST.
     189 * @returns the OM_LIST transformed from listName. or the default, if not found or NULL.
     190 */
     191OM_LIST ObjectManager::StringToOMList(const char* listName)
     192{
     193  if (unlikely(listName == NULL)) return OM_DEFAULT_LIST;
     194
     195  for(unsigned int i = 0; i < OM_SIZE; ++i) {
     196    if(!strcmp(listName, ObjectManager::objectManagerListNames[i])) {
     197      return (OM_LIST)i;
     198    }
     199  }
     200  return OM_DEFAULT_LIST;
     201}
     202
     203
     204
     205const char* ObjectManager::objectManagerListNames[] = {
     206    "null",
     207    "dead",
     208    "dead-tick",
     209    "environ-notick",
     210    "environ",
     211    "common",
     212
     213    "group00",
     214    "group00-proj",
     215    "group01",
     216    "group01-proj",
     217    "group02",
     218    "group02-proj",
     219    "group03",
     220    "group03-proj",
     221    "group04",
     222    "group04-proj",
     223    "group05",
     224    "group05-proj",
     225    "group06",
     226    "group06-proj",
     227    "group07",
     228    "group07-proj",
     229    "group08",
     230    "group08-proj",
     231    "group09",
     232    "group09-proj",
     233    "group10",
     234    "group10-proj",
     235    "group11",
     236    "group11-proj",
     237    "group12",
     238    "group12-proj",
     239    "group13",
     240    "group13-proj",
     241    "group14",
     242    "group14-proj",
     243    "group15",
     244    "group15-proj"
     245};
  • trunk/src/util/object_manager.h

    r5795 r6142  
    11/*!
    22 * @file object_manager.h
    3  * @brief Definition of the ... singleton Class
    4 */
     3 * @brief Definition of the ObjectManager.
     4 */
    55
    66#ifndef _OBJECT_MANAGER_H
     
    99#include "base_object.h"
    1010#include <list>
     11#include <vector>
     12
     13/// Enumerator for Managed Object Lists
     14typedef enum {
     15  OM_NULL             =  0,
     16  OM_DEAD,
     17  OM_DEAD_TICK,
     18  OM_ENVIRON_NOTICK,
     19  OM_ENVIRON,
     20  OM_COMMON,
     21
     22  OM_GROUP_00,
     23  OM_GROUP_00_PROJ,
     24  OM_GROUP_01,
     25  OM_GROUP_01_PROJ,
     26  OM_GROUP_02,
     27  OM_GROUP_02_PROJ,
     28  OM_GROUP_03,
     29  OM_GROUP_03_PROJ,
     30  OM_GROUP_04,
     31  OM_GROUP_04_PROJ,
     32  OM_GROUP_05,
     33  OM_GROUP_05_PROJ,
     34  OM_GROUP_06,
     35  OM_GROUP_06_PROJ,
     36  OM_GROUP_07,
     37  OM_GROUP_07_PROJ,
     38  OM_GROUP_08,
     39  OM_GROUP_08_PROJ,
     40  OM_GROUP_09,
     41  OM_GROUP_09_PROJ,
     42  OM_GROUP_10,
     43  OM_GROUP_10_PROJ,
     44  OM_GROUP_11,
     45  OM_GROUP_11_PROJ,
     46  OM_GROUP_12,
     47  OM_GROUP_12_PROJ,
     48  OM_GROUP_13,
     49  OM_GROUP_13_PROJ,
     50  OM_GROUP_14,
     51  OM_GROUP_14_PROJ,
     52  OM_GROUP_15,
     53  OM_GROUP_15_PROJ,
     54
     55  OM_SIZE,
     56
     57
     58  OM_INIT             = -1, //!< DO NOT USE THIS. (WorldEntity Internal).
     59} OM_LIST;
     60
     61#define OM_DEFAULT_LIST  OM_NULL
     62
    1163
    1264// FORWARD DECLARATION
     
    1466class WorldEntity;
    1567
    16 class ObjectGroupList
    17 {
    18 
    19 
    20 
    21 };
    22 
    23 
    24 //! A default singleton class.
     68//! A powerfull handler for the Object (WorldEntities) in the World.
    2569class ObjectManager : public BaseObject {
    2670
    2771 public:
    28   virtual ~ObjectManager(void);
    29   /** @returns a Pointer to the only object of this Class */
    30   inline static ObjectManager* getInstance(void) { if (!ObjectManager::singletonRef) ObjectManager::singletonRef = new ObjectManager();  return ObjectManager::singletonRef; };
     72   ObjectManager();
     73   virtual ~ObjectManager();
    3174
     75  void flush();
     76
     77  void toList (WorldEntity* entity, OM_LIST omList = OM_DEFAULT_LIST);
     78  void toList (WorldEntity* entity, const char* omList);
     79
     80
     81  std::list<WorldEntity*>& getObjectList(OM_LIST listNumber) { return this->objectLists[listNumber]; }
     82  const std::list<WorldEntity*>& getObjectList(OM_LIST listNumber) const { return this->objectLists[listNumber]; }
    3283
    3384  static std::list<WorldEntity*>* distanceFromObject(const PNode& center, float radius, ClassID classID);
    3485
    35   ObjectGroupList* getGroupList( );
     86  void debug(OM_LIST omList, unsigned int level = 0) const;
     87  void debug(const char* listName = NULL, unsigned int level = 0);
     88
     89  static OM_LIST StringToOMList(const char* listName);
     90  static const char* OMListToString(OM_LIST omList);
    3691
    3792 private:
    38   ObjectManager(void);
    39   static ObjectManager* singletonRef;
    40 
    41   std::list<ObjectGroupList>           groupList;
    42 
    43   const std::list<BaseObject>*         pNodeList;
     93  const std::list<BaseObject>*            pNodeList;
    4494
    4595
     96  std::list<WorldEntity*>                 objectLists[OM_SIZE];
     97
     98  static const char*                      objectManagerListNames[]; //!< Names of all the lists
    4699};
    47100
  • trunk/src/util/state.cc

    r4836 r6142  
    2929const PNode* State::cameraTarget = NULL;
    3030
    31 tList<WorldEntity>* State::worldEntityList = NULL;
     31ObjectManager* State::objectManager = NULL;
    3232
    3333/**
  • trunk/src/util/state.h

    r5405 r6142  
    1010class PNode;
    1111class WorldEntity;
    12 template<class T> class tList;
    13 //template<class T> class tStack;
     12class ObjectManager;
    1413
    1514//! handles states about orxonox's most importatn objects
     
    2221
    2322 public:
    24   // CAMERA //
     23   //////////////
     24   /// CAMERA ///
     25   //////////////
    2526  /** @param camera the PNode to the Camera, @param cameraTarget the PNode to the Camera's target */
    2627  static void setCamera(const PNode* camera, const PNode* cameraTarget);
     
    3031  static inline const PNode* getCameraTarget() { return State::cameraTarget; };
    3132
    32   // WORLD_ENTITY_LIST //
    33   /** @param worldEntityList The World's List of WorldEntities */
    34   static inline void setWorldEntityList(tList<WorldEntity>* worldEntityList) { State::worldEntityList = worldEntityList; };
    35   /** @returns the List of WorldEntities */
    36   static inline tList<WorldEntity>* getWorldEntityList() { return State::worldEntityList; };
     33  //////////////////////
     34  /// OBJECT-MANAGER ///
     35  //////////////////////
     36  /** @param objectManager the new Current ObjectManager */
     37  static inline void setObjectManager(ObjectManager* objectManager) { State::objectManager = objectManager; };
     38  /** @returns the current ObjectManager. */
     39  static inline ObjectManager* getObjectManager() { return State::objectManager; };
     40
     41  /////////////////////////
     42  /// WORLD_ENTITY_LIST ///
     43  /////////////////////////
    3744
    3845 private:
     
    4249  static const PNode*           cameraTarget;       //!< A reference to the cameraTarget
    4350  static PNode*                 nullParent;         //!< A reference to the Null-PNode.
     51  static ObjectManager*         objectManager;      //!< A referenct to the current ObjectManager
    4452
    45   static tList<WorldEntity>*    worldEntityList;    //!< The List of the worldEntities
    46 
    47   //tStack<
    4853};
    4954
Note: See TracChangeset for help on using the changeset viewer.