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