Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/volumetric_fog/src/util/object_manager.cc @ 10561

Last change on this file since 10561 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 6.3 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
17
18#include "object_manager.h"
19
20#include "world_entity.h"
21
22#include "shell_command.h"
23
24#include <cassert>
25#include "debug.h"
26
27
28SHELL_COMMAND(debug, ObjectManager, debug)
29    ->defaultValues("", 0);
30
31ObjectListDefinition(ObjectManager);
32/**
33 * @brief standard constructor
34 */
35ObjectManager::ObjectManager ()
36{
37  this->registerObject(this, ObjectManager::_objectList);
38   this->setName("ObjectManager");
39
40   pNodeList = NULL;
41}
42
43
44/**
45 * @brief standard deconstructor
46 *
47 * this also removes ALL entitites in existence.
48 */
49ObjectManager::~ObjectManager ()
50{
51  this->flush();
52}
53
54/**
55 * @brief flushes all entities
56 *
57 * this function deletes all entities that exist within the ObjectManager.
58 * It does this by poping each list from the front, and delete the given object.
59 *
60 * automatically called by a destructor.
61 */
62void ObjectManager::flush()
63{
64  for (unsigned int i = 0; i < OM_SIZE; ++i)
65    while(!this->entityLists[i].empty())
66      delete this->entityLists[i].front();
67
68  // delete reflection list
69  this->reflectionList.clear();
70}
71
72
73/**
74 * @brief moves an Entity from an old list to a new One
75 * @param entity the entity to move.
76 * @param omList the new List to move the entity to.
77 *
78 * this will erase the entity from the old list
79 */
80void ObjectManager::toList (WorldEntity* entity, OM_LIST omList)
81{
82  assert (omList != OM_SIZE);
83
84  if (likely(entity->getOMListNumber() != OM_INIT))
85    this->entityLists[entity->getOMListNumber()].erase(entity->getEntityIterator());
86
87  if (likely(omList != OM_INIT))
88  {
89    this->entityLists[omList].push_back(entity);
90    entity->getEntityIterator() = --this->entityLists[omList].end();
91    entity->getOMListNumber() = omList;
92  }
93}
94
95
96/**
97 * @see ObjectManager::toList(WorldEntity* OM_LIST)
98 * @param entity the entity to move.
99 * @param omList the new List to move the entity to.
100 *
101 * this function also does a transformation from omList as char* to OM_LIST.
102 */
103void ObjectManager::toList (WorldEntity* entity, const std::string& omList)
104{
105  this->toList(entity, ObjectManager::StringToOMList(omList));
106}
107
108
109
110/**
111 * @returns a new List with a list of WorldEntities of distance Radius from center
112 */
113  /*
114void ObjectManager::distanceFromObject(EntityList& entities, const PNode& center, float radius, const ClassID& classID)
115{
116  TODO FIXME
117
118  const std::list<BaseObject*>* entityList = ClassList::getList(classID);
119  if (entityList != NULL)
120  {
121
122    std::list<BaseObject*>::const_iterator node;
123    for (node = entityList->begin(); node != entityList->end(); node++)
124      if ((dynamic_cast<PNode*>(*node)->getAbsCoor() - center.getAbsCoor()).len() < radius)
125        entities.push_back(dynamic_cast<WorldEntity*>(*node));
126  }
127}
128  */
129
130
131/**
132 * @brief print out nice debug information about Elements in the list OM_LIST
133 * @param omList the List to debug.
134 * @param level: level 0: only show list info; level 1: also show entities and their names.
135 */
136void ObjectManager::debug(OM_LIST omList, unsigned int level) const
137{
138  if (omList != OM_INIT || omList == OM_SIZE)
139  {
140    PRINT(0)(" +ObjectManager-LIST: '%s'==size='%d'==---\n", ObjectManager::OMListToString((OM_LIST)omList).c_str(), this->entityLists[omList].size());
141  //  if (level >= 1)
142    {
143      ObjectManager::EntityList::const_iterator entity;
144      for (entity = this->entityLists[omList].begin(); entity != this->entityLists[omList].end(); entity++)
145      {
146        PRINT(0)(" | %s::%s\n",(*entity)->getClassCName(), (*entity)->getCName());
147      }
148    }
149  }
150  else
151    PRINTF(2)("Invalid query. for OM_INIT-LIST or OM_SIZE\n");
152}
153
154
155/**
156 * @brief prints out very nice debug information
157 * @param listName the Name of the list to get Debug information from
158 * @param level: level 0: only show list info; level 1: also show entities and their names.
159 */
160void ObjectManager::debug(const std::string& listName, unsigned int level)
161{
162  PRINT(0)("=================================\n");
163  PRINT(0)("=ObjectManager-DEBUG=============\n");
164  PRINT(0)("=================================\n");
165  if (listName.empty())
166    for (unsigned int i = 0; i < OM_SIZE; ++i)
167      debug((OM_LIST) i, level);
168  else
169    debug(ObjectManager::StringToOMList(listName));
170  PRINT(0)("=========================== OM ==\n");
171}
172
173
174
175/**
176 * @brief transforms an omList into a String (usefull for debugging).
177 * @param omList the OM_LIST to be transformed into a String.
178 * @returns the String transformed from omList.
179 */
180const std::string& ObjectManager::OMListToString(OM_LIST omList)
181{
182  if (omList == OM_INIT || omList == OM_SIZE)
183    return ObjectManager::objectManagerListNames[OM_NULL];
184
185  printf("%d\n", omList);
186  return ObjectManager::objectManagerListNames[omList];
187}
188
189
190
191/**
192 * @brief transforms a String into an OM_LIST (usefull for debugging/Loading).
193 * @param listName the OM_LIST-name to be transformed into an OM_LIST.
194 * @returns the OM_LIST transformed from listName. or the default, if not found or NULL.
195 */
196OM_LIST ObjectManager::StringToOMList(const std::string& listName)
197{
198  if (unlikely(listName.empty())) return OM_DEFAULT_LIST;
199
200  for(unsigned int i = 0; i < OM_SIZE; ++i) {
201    if(listName == ObjectManager::objectManagerListNames[i]) {
202      return (OM_LIST)i;
203    }
204  }
205  return OM_NULL;
206}
207
208
209
210const std::string ObjectManager::objectManagerListNames[] = {
211    "null",
212    "dead",
213    "dead-tick",
214    "environ-notick",
215    "environ",
216    "background",
217    "common",
218
219    "players",
220    "players-proj",
221
222    "group00",
223    "group00-proj",
224    "group01",
225    "group01-proj",
226    "group02",
227    "group02-proj",
228    "group03",
229    "group03-proj",
230    "group04",
231    "group04-proj",
232    "group05",
233    "group05-proj",
234    "group06",
235    "group06-proj",
236    "group07",
237    "group07-proj",
238    "group08",
239    "group08-proj",
240    "group09",
241    "group09-proj",
242    "group10",
243    "group10-proj",
244    "group11",
245    "group11-proj",
246    "group12",
247    "group12-proj",
248    "group13",
249    "group13-proj",
250    "group14",
251    "group14-proj",
252    "group15",
253    "group15-proj"
254};
Note: See TracBrowser for help on using the repository browser.