xoreos  0.0.5
objectcontainer.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/types.h"
26 #include "src/common/util.h"
27 
31 #include "src/engines/sonic/area.h"
33 
34 namespace Engines {
35 
36 namespace Sonic {
37 
39  target.getPosition(xt, yt, zt);
40 }
41 
43  return getDistance(*a) < getDistance(*b);
44 }
45 
47  float x, y, z;
48  a.getPosition(x, y, z);
49 
50  return ABS(x - xt) + ABS(y - yt) + ABS(z - zt);
51 }
52 
53 
54 class SearchType : public ::Aurora::NWScript::SearchRange< std::list<Sonic::Object *> > {
55 public:
56  SearchType(const iterator &a, const iterator &b) : ::Aurora::NWScript::SearchRange<type>(std::make_pair(a, b)) { }
57  SearchType(const type &l) : ::Aurora::NWScript::SearchRange<type>(std::make_pair(l.begin(), l.end())) { }
59 
60  ::Aurora::NWScript::Object *getObject(const iterator &t) { return *t; }
61 };
62 
63 
65 }
66 
68 }
69 
71  lock();
72 
73  _objects.clear();
74 
76 
77  unlock();
78 }
79 
81  lock();
82 
84 
85  _objects[object.getType()].push_back(&object);
86 
87  unlock();
88 }
89 
91  lock();
92 
93  _objects[object.getType()].remove(&object);
94 
96 
97  unlock();
98 }
99 
101  ObjectMap::const_iterator l = _objects.find(type);
102  if (l == _objects.end())
103  return 0;
104 
105  SearchType ctx(l->second);
106 
107  return ctx.get();
108 }
109 
111  static const ObjectList kEmptyObjectList;
112 
113  ObjectMap::const_iterator l = _objects.find(type);
114  if (l == _objects.end())
115  return new SearchType(kEmptyObjectList.begin(), kEmptyObjectList.end());
116 
117  return new SearchType(l->second);
118 }
119 
121  return dynamic_cast<Sonic::Object *>(object);
122 }
123 
125  return dynamic_cast<Module *>(object);
126 }
127 
129  return dynamic_cast<Area *>(object);
130 }
131 
133  return dynamic_cast<Placeable *>(object);
134 }
135 
136 } // End of namespace Sonic
137 
138 } // End of namespace Engines
static Area * toArea(Aurora::NWScript::Object *object)
SearchType(const iterator &a, const iterator &b)
T ABS(T x)
Definition: util.h:69
void addObject(Sonic::Object &object)
Add an object to this container.
The context holding a Sonic Chronicles: The Dark Brotherhood area.
std::list< Sonic::Object * > ::const_iterator iterator
STL namespace.
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:60
An object within a Sonic area.
Definition: object.h:40
static Sonic::Object * toObject(::Aurora::NWScript::Object *object)
float getDistance(Sonic::Object &a)
ObjectDistanceSort(const Sonic::Object &target)
Utility templates and functions.
::Aurora::NWScript::Object * getFirstObjectByType(ObjectType type) const
Return the first object of this type.
static Placeable * toPlaceable(Aurora::NWScript::Object *object)
Low-level type definitions to handle fixed width types portably.
void removeObject(Object &object)
Remove an object from this container.
Object * get()
Return the current object in the search context.
::Aurora::NWScript::Object * getObject(const iterator &t)
The context needed to run a Sonic Chronicles: The Dark Brotherhood module.
A Sonic module.
Definition: module.h:45
A container of Sonic Chronicles: The Dark Brotherhood objects.
static Module * toModule(Aurora::NWScript::Object *object)
An object in a Sonic Chronicles: The Dark Brotherhood area.
::Aurora::NWScript::ObjectSearch * findObjectsByType(ObjectType type) const
Return a search context to iterate over all objects of this type.
A placeable object in a Sonic Chronicles: The Dark Brotherhood area.
void removeObject(Sonic::Object &object)
Remove an object from this container.
bool operator()(Sonic::Object *a, Sonic::Object *b)
void addObject(Object &object)
Add an object to this container.