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 | #include "class_list.h" |
---|
20 | |
---|
21 | #include "world_entity.h" |
---|
22 | |
---|
23 | #include "shell_command.h" |
---|
24 | using namespace std; |
---|
25 | SHELL_COMMAND(debug, ObjectManager, debug) |
---|
26 | ->defaultValues(2, NULL, 0); |
---|
27 | |
---|
28 | /** |
---|
29 | * standard constructor |
---|
30 | */ |
---|
31 | ObjectManager::ObjectManager () |
---|
32 | { |
---|
33 | this->setClassID(CL_OBJECT_MANAGER, "ObjectManager"); |
---|
34 | this->setName("ObjectManager"); |
---|
35 | |
---|
36 | pNodeList = NULL; |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * the singleton reference to this class |
---|
41 | */ |
---|
42 | ObjectManager* ObjectManager::singletonRef = NULL; |
---|
43 | |
---|
44 | /** |
---|
45 | @brief standard deconstructor |
---|
46 | */ |
---|
47 | ObjectManager::~ObjectManager () |
---|
48 | { |
---|
49 | ObjectManager::singletonRef = NULL; |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | /** |
---|
54 | * @brief moves an Entity from an old list to a new One |
---|
55 | * @param entity the entity to move. |
---|
56 | * @param omList the new List to move the entity to. |
---|
57 | * |
---|
58 | * this will erase the entity from the old list |
---|
59 | */ |
---|
60 | void ObjectManager::toList (WorldEntity* entity, OM_LIST omList) |
---|
61 | { |
---|
62 | if (likely(entity->getOMListNumber() != OM_INIT)) |
---|
63 | this->objectLists[entity->getOMListNumber()].erase(entity->getEntityIterator()); |
---|
64 | |
---|
65 | if (likely(omList != OM_INIT)) |
---|
66 | { |
---|
67 | this->objectLists[omList].push_back(entity); |
---|
68 | entity->getEntityIterator() = --this->objectLists[omList].end(); |
---|
69 | entity->getOMListNumber() = omList; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | /** |
---|
75 | * @see ObjectManager::toList(WorldEntity* OM_LIST) |
---|
76 | * @param entity the entity to move. |
---|
77 | * @param omList the new List to move the entity to. |
---|
78 | * |
---|
79 | * this function also does a transformation from omList as char* to OM_LIST. |
---|
80 | */ |
---|
81 | void ObjectManager::toList (WorldEntity* entity, const char* omList) |
---|
82 | { |
---|
83 | this->toList(entity, ObjectManager::StringToOMList(omList)); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | /** |
---|
89 | * returns a new List with a list of WorldEntities of distance Radius from center |
---|
90 | */ |
---|
91 | std::list<WorldEntity*>* ObjectManager::distanceFromObject(const PNode& center, float radius, ClassID classID) |
---|
92 | { |
---|
93 | const std::list<BaseObject*>* objectList = ClassList::getList(classID); |
---|
94 | if (objectList != NULL) |
---|
95 | { |
---|
96 | std::list<WorldEntity*>* newList = new std::list<WorldEntity*>; |
---|
97 | |
---|
98 | list<BaseObject*>::const_iterator node; |
---|
99 | for (node = objectList->begin(); node != objectList->end(); node++) |
---|
100 | if ((dynamic_cast<PNode*>(*node)->getAbsCoor() - center.getAbsCoor()).len() < radius) |
---|
101 | newList->push_back(dynamic_cast<WorldEntity*>(*node)); |
---|
102 | return newList; |
---|
103 | } |
---|
104 | return NULL; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | /** |
---|
109 | * @brief print out nice debug information about Elements in the list OM_LIST |
---|
110 | * @param omList the List to debug. |
---|
111 | */ |
---|
112 | void ObjectManager::debug(OM_LIST omList) const |
---|
113 | { |
---|
114 | if (omList != OM_INIT) |
---|
115 | { |
---|
116 | PRINT(0)(" +ObjectManager-LIST: '%s'------\n", ObjectManager::OMListToString((OM_LIST) omList)); |
---|
117 | std::list<WorldEntity*>::const_iterator entity; |
---|
118 | for (entity = this->objectLists[omList].begin(); entity != this->objectLists[omList].end(); entity++) |
---|
119 | { |
---|
120 | PRINT(0)(" | %s::%s\n",(*entity)->getClassName(), (*entity)->getName()); |
---|
121 | } |
---|
122 | } |
---|
123 | else |
---|
124 | PRINTF(2)("Invalid query. for OM_INIT-LIST\n"); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | /** |
---|
129 | * @brief prints out very nice debug information |
---|
130 | * @param listName the Name of the list to get Debug information from |
---|
131 | */ |
---|
132 | void ObjectManager::debug(const char* listName) |
---|
133 | { |
---|
134 | PRINT(0)("=ObjectManager-DEBUG=============\n"); |
---|
135 | if (listName == NULL || listName[0] == '\0') |
---|
136 | for (unsigned int i = 0; i < OM_SIZE; ++i) |
---|
137 | debug((OM_LIST) i); |
---|
138 | else |
---|
139 | debug(ObjectManager::StringToOMList(listName)); |
---|
140 | PRINT(0)("=========================== OM ==\n"); |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | /** |
---|
146 | * @brief transforms an omList into a String (usefull for debugging). |
---|
147 | * @param omList the OM_LIST to be transformed into a String. |
---|
148 | * @returns the String transformed from omList. |
---|
149 | */ |
---|
150 | const char* ObjectManager::OMListToString(OM_LIST omList) |
---|
151 | { |
---|
152 | switch (omList) |
---|
153 | { |
---|
154 | case OM_DEAD: |
---|
155 | return "dead"; |
---|
156 | case OM_ENVIRON_NOTICK: |
---|
157 | return "environ-notick"; |
---|
158 | case OM_ENVIRON: |
---|
159 | return "environ"; |
---|
160 | case OM_COMMON: |
---|
161 | return "common"; |
---|
162 | case OM_GROUP_00: |
---|
163 | return "group00"; |
---|
164 | case OM_GROUP_00_PROJ: |
---|
165 | return "group00-proj"; |
---|
166 | case OM_GROUP_01: |
---|
167 | return "group01"; |
---|
168 | case OM_GROUP_01_PROJ: |
---|
169 | return "group01-proj"; |
---|
170 | case OM_GROUP_02: |
---|
171 | return "group02"; |
---|
172 | case OM_GROUP_02_PROJ: |
---|
173 | return "group02-proj"; |
---|
174 | case OM_GROUP_03: |
---|
175 | return "group03"; |
---|
176 | case OM_GROUP_03_PROJ: |
---|
177 | return "group03-proj"; |
---|
178 | case OM_GROUP_04: |
---|
179 | return "group04"; |
---|
180 | case OM_GROUP_04_PROJ: |
---|
181 | return "group04-proj"; |
---|
182 | case OM_GROUP_05: |
---|
183 | return "group05"; |
---|
184 | case OM_GROUP_05_PROJ: |
---|
185 | return "group05-proj"; |
---|
186 | case OM_GROUP_06: |
---|
187 | return "group06"; |
---|
188 | case OM_GROUP_06_PROJ: |
---|
189 | return "group06-proj"; |
---|
190 | case OM_GROUP_07: |
---|
191 | return "group07"; |
---|
192 | case OM_GROUP_07_PROJ: |
---|
193 | return "group07-proj"; |
---|
194 | case OM_GROUP_08: |
---|
195 | return "group08"; |
---|
196 | case OM_GROUP_08_PROJ: |
---|
197 | return "group08-proj"; |
---|
198 | case OM_GROUP_09: |
---|
199 | return "group09"; |
---|
200 | case OM_GROUP_09_PROJ: |
---|
201 | return "group09-proj"; |
---|
202 | case OM_GROUP_10: |
---|
203 | return "group10"; |
---|
204 | case OM_GROUP_10_PROJ: |
---|
205 | return "group10-proj"; |
---|
206 | case OM_GROUP_11: |
---|
207 | return "group11"; |
---|
208 | case OM_GROUP_11_PROJ: |
---|
209 | return "group11-proj"; |
---|
210 | case OM_GROUP_12: |
---|
211 | return "group11"; |
---|
212 | case OM_GROUP_12_PROJ: |
---|
213 | return "group12-proj"; |
---|
214 | case OM_GROUP_13: |
---|
215 | return "group03"; |
---|
216 | case OM_GROUP_13_PROJ: |
---|
217 | return "group13-proj"; |
---|
218 | case OM_GROUP_14: |
---|
219 | return "group14"; |
---|
220 | case OM_GROUP_14_PROJ: |
---|
221 | return "group14-proj"; |
---|
222 | case OM_GROUP_15: |
---|
223 | return "group15"; |
---|
224 | case OM_GROUP_15_PROJ: |
---|
225 | return "group15-proj"; |
---|
226 | default: |
---|
227 | return "null"; |
---|
228 | } |
---|
229 | |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | OM_LIST ObjectManager::StringToOMList(const char* listName) |
---|
235 | { |
---|
236 | if (unlikely(listName == NULL)) return OM_DEFAULT_LIST; |
---|
237 | |
---|
238 | if (!strcmp(listName, "dead")) return OM_DEAD; |
---|
239 | if (!strcmp(listName, "environ-notick")) return OM_ENVIRON_NOTICK; |
---|
240 | if (!strcmp(listName, "environ")) return OM_ENVIRON; |
---|
241 | if (!strcmp(listName, "common")) return OM_COMMON; |
---|
242 | |
---|
243 | if (!strcmp(listName, "group00")) return OM_GROUP_00; |
---|
244 | if (!strcmp(listName, "group00-proj")) return OM_GROUP_00_PROJ; |
---|
245 | if (!strcmp(listName, "group01")) return OM_GROUP_01; |
---|
246 | if (!strcmp(listName, "group01-proj")) return OM_GROUP_01_PROJ; |
---|
247 | if (!strcmp(listName, "group02")) return OM_GROUP_02; |
---|
248 | if (!strcmp(listName, "group02-proj")) return OM_GROUP_02_PROJ; |
---|
249 | if (!strcmp(listName, "group03")) return OM_GROUP_03; |
---|
250 | if (!strcmp(listName, "group03-proj")) return OM_GROUP_03_PROJ; |
---|
251 | if (!strcmp(listName, "group04")) return OM_GROUP_04; |
---|
252 | if (!strcmp(listName, "group04-proj")) return OM_GROUP_04_PROJ; |
---|
253 | if (!strcmp(listName, "group05")) return OM_GROUP_05; |
---|
254 | if (!strcmp(listName, "group05-proj")) return OM_GROUP_05_PROJ; |
---|
255 | if (!strcmp(listName, "group06")) return OM_GROUP_06; |
---|
256 | if (!strcmp(listName, "group06-proj")) return OM_GROUP_06_PROJ; |
---|
257 | if (!strcmp(listName, "group07")) return OM_GROUP_07; |
---|
258 | if (!strcmp(listName, "group07-proj")) return OM_GROUP_07_PROJ; |
---|
259 | if (!strcmp(listName, "group08")) return OM_GROUP_08; |
---|
260 | if (!strcmp(listName, "group08-proj")) return OM_GROUP_08_PROJ; |
---|
261 | if (!strcmp(listName, "group09")) return OM_GROUP_09; |
---|
262 | if (!strcmp(listName, "group09-proj")) return OM_GROUP_09_PROJ; |
---|
263 | if (!strcmp(listName, "group10")) return OM_GROUP_10; |
---|
264 | if (!strcmp(listName, "group10-proj")) return OM_GROUP_10_PROJ; |
---|
265 | if (!strcmp(listName, "group11")) return OM_GROUP_11; |
---|
266 | if (!strcmp(listName, "group11-proj")) return OM_GROUP_11_PROJ; |
---|
267 | if (!strcmp(listName, "group12")) return OM_GROUP_12; |
---|
268 | if (!strcmp(listName, "group12-proj")) return OM_GROUP_12_PROJ; |
---|
269 | if (!strcmp(listName, "group13")) return OM_GROUP_13; |
---|
270 | if (!strcmp(listName, "group13-proj")) return OM_GROUP_13_PROJ; |
---|
271 | if (!strcmp(listName, "group14")) return OM_GROUP_14; |
---|
272 | if (!strcmp(listName, "group14-proj")) return OM_GROUP_14_PROJ; |
---|
273 | if (!strcmp(listName, "group15")) return OM_GROUP_15; |
---|
274 | if (!strcmp(listName, "group15-proj")) return OM_GROUP_15_PROJ; |
---|
275 | |
---|
276 | return OM_DEFAULT_LIST; |
---|
277 | } |
---|
278 | |
---|