-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathspritemanager.h
193 lines (164 loc) · 7 KB
/
spritemanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/************************************************************************
* Copyright (c) 2005-2007 [email protected] *
* *
* This software is provided as-is, without any express or implied *
* warranty. In no event will the authors be held liable for any *
* damages arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute *
* it freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must *
* not claim that you wrote the original software. If you use this *
* software in a product, an acknowledgment in the product documentation *
* would be appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must *
* not be misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source *
* distribution. *
************************************************************************/
#ifndef OGTA_SpriteManager_H
#define OGTA_SpriteManager_H
#include <list>
#include <map>
#include "abstract_container.h"
//#include "pedestrian.h"
#include "game_objects.h"
#include "Singleton.h"
#include "train_system.h"
#include "map_helper.h"
namespace OpenGTA {
#if 0
class SpriteManager {
public:
SpriteManager();
~SpriteManager();
void drawInRect(SDL_Rect & r);
void clear();
void addPed(Pedestrian & ped);
Pedestrian & getPedById(const Uint32 & id);
void removePedById(const Uint32 & id);
void addCar(Car & car);
Car & getCarById(const Uint32 & id);
void removeCarById(const Uint32 & id);
void addObject(GameObject & go);
GameObject & getObjectById(const Uint32 & id);
void removeObjectById(const Uint32 & id);
void update(Uint32 ticks);
SpriteObject::Animation & getAnimationById(const Uint32 & id);
void registerAnimation(const Uint32 & id, const SpriteObject::Animation & anim);
inline bool getDrawTexture() { return (drawMode & 1); }
inline bool getDrawTexBorder() { return (drawMode & 2); }
inline bool getDrawBBox() { return (drawMode & 4); }
void setDrawTexture(bool v);
void setDrawTexBorder(bool v);
void setDrawBBox(bool v);
void drawPed(Pedestrian & ped);
void drawCar(Car & car);
void drawObject(GameObject & obj);
void drawExplosion(GameObject & obj);
void drawTrain(TrainSegment & train);
TrainSegment & getTrainById(const Uint32 & id);
void createProjectile(uint8_t typeId, float, Vector3D p, Vector3D d, Uint32 & ticks);
void createExplosion(Vector3D center);
void drawProjectile(Projectile & p);
void collideProjectile(Projectile & p);
typedef std::list<TrainSegment> TrainListType;
protected:
typedef std::list<Pedestrian> PedListType;
PedListType activePeds;
typedef std::list<Car> CarListType;
CarListType activeCars;
typedef std::list<GameObject> ObjectListType;
ObjectListType activeObjects;
typedef std::list<Projectile> ProjectileListType;
ProjectileListType activeProjectiles;
TrainListType activeTrains;
public:
TrainSystem trainSystem;
protected:
typedef std::map<Uint32, SpriteObject::Animation> AnimLookupType;
AnimLookupType animations;
private:
Uint32 drawMode;
};
#endif
class SpriteManager :
public AbstractContainer<Pedestrian>,
public AbstractContainer<Car>,
public AbstractContainer<SpriteObject> { //,
//public AbstractContainer<TrainSegment> {
public:
~SpriteManager();
void drawInRect(SDL_Rect & r);
void clear();
void removeDeadStuff();
template <typename T> T & add(const T & t) {
return AbstractContainer<T>::doAdd(t);
}
template <typename T> size_t getNum() {
return AbstractContainer<T>::objs.size();
}
inline Pedestrian & getPed(uint32_t id) {
return AbstractContainer<Pedestrian>::doGet(id);
}
inline Car & getCar(uint32_t id) {
return AbstractContainer<Car>::doGet(id);
}
inline SpriteObject & getObject(uint32_t id) {
return AbstractContainer<SpriteObject>::doGet(id);
}
/*
inline TrainSegment & getTrain(uint32_t id) {
return AbstractContainer<TrainSegment>::doGet(id);
}*/
template <typename T> inline std::list<T> & getList() {
return AbstractContainer<T>::objs;
}
inline void removePed(uint32_t id) {
AbstractContainer<Pedestrian>::doRemove(id);
}
inline void removeCar(uint32_t id) {
AbstractContainer<Car>::doRemove(id);
}
void realRemove();
inline bool getDrawTexture() { return (drawMode & 1); }
inline bool getDrawTexBorder() { return (drawMode & 2); }
inline bool getDrawBBox() { return (drawMode & 4); }
void setDrawTexture(bool v);
void setDrawTexBorder(bool v);
void setDrawBBox(bool v);
void drawBBoxOutline(const OBox &);
void drawTextureOutline(const float &, const float &);
void draw(Car &);
void draw(Pedestrian &);
void draw(SpriteObject &);
void draw(Projectile &);
void drawExplosion(SpriteObject &);
void update(Uint32 ticks);
SpriteObject::Animation & getAnimationById(const Uint32 & id);
void registerAnimation(const Uint32 & id, const SpriteObject::Animation & anim);
void createExplosion(Vector3D center);
void createProjectile(uint8_t typeId, float, Vector3D p, Vector3D d, Uint32 & ticks, Uint32 & owner);
public:
//TrainSystem trainSystem;
SpriteManager();
Util::SpriteCreationArea creationArea;
protected:
typedef std::map<Uint32, SpriteObject::Animation> AnimLookupType;
AnimLookupType animations;
typedef std::list<Projectile> ProjectileListType;
ProjectileListType activeProjectiles;
private:
Uint32 drawMode;
Uint32 lastCreateTick;
//SpriteManager(const SpriteManager & o) : trainSystem(AbstractContainer<TrainSegment>::objs) {assert(0);}
SpriteManager(const SpriteManager & o) {assert(0);}
};
typedef Loki::SingletonHolder<SpriteManager, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> SpriteManagerHolder;
}
#endif