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 | return ObjectManager::objectManagerListNames[omList]; |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | /** |
---|
158 | * @brief transforms a String into an OM_LIST (usefull for debugging/Loading). |
---|
159 | * @param listName the OM_LIST-name to be transformed into an OM_LIST. |
---|
160 | * @returns the OM_LIST transformed from listName. or the default, if not found or NULL. |
---|
161 | */ |
---|
162 | OM_LIST ObjectManager::StringToOMList(const char* listName) |
---|
163 | { |
---|
164 | if (unlikely(listName == NULL)) return OM_DEFAULT_LIST; |
---|
165 | |
---|
166 | for(unsigned int i = 0; i < OM_SIZE; ++i) { |
---|
167 | if(!strcmp(listName, ObjectManager::objectManagerListNames[i])) { |
---|
168 | return (OM_LIST)i; |
---|
169 | } |
---|
170 | } |
---|
171 | return OM_DEFAULT_LIST; |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | const char* ObjectManager::objectManagerListNames[] = { |
---|
177 | "null", |
---|
178 | "dead", |
---|
179 | "environ-notick", |
---|
180 | "environ", |
---|
181 | "common", |
---|
182 | |
---|
183 | "group00", |
---|
184 | "group00-proj", |
---|
185 | "group01", |
---|
186 | "group01-proj", |
---|
187 | "group02", |
---|
188 | "group02-proj", |
---|
189 | "group03", |
---|
190 | "group03-proj", |
---|
191 | "group04", |
---|
192 | "group04-proj", |
---|
193 | "group05", |
---|
194 | "group05-proj", |
---|
195 | "group06", |
---|
196 | "group06-proj", |
---|
197 | "group07", |
---|
198 | "group07-proj", |
---|
199 | "group08", |
---|
200 | "group08-proj", |
---|
201 | "group09", |
---|
202 | "group09-proj", |
---|
203 | "group10", |
---|
204 | "group10-proj", |
---|
205 | "group11", |
---|
206 | "group11-proj", |
---|
207 | "group12", |
---|
208 | "group12-proj", |
---|
209 | "group13", |
---|
210 | "group13-proj", |
---|
211 | "group14", |
---|
212 | "group14-proj", |
---|
213 | "group15", |
---|
214 | "group15-proj" |
---|
215 | }; |
---|