OpenGTA/spritemanager.h

265 lines
9.8 KiB
C
Raw Permalink Normal View History

2015-12-03 00:37:02 +00:00
/************************************************************************
2015-12-03 00:37:37 +00:00
* Copyright (c) 2005-2007 tok@openlinux.org.uk *
2015-12-03 00:37:02 +00:00
* *
* 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>
2015-12-03 00:37:37 +00:00
#include "abstract_container.h"
//#include "pedestrian.h"
#include "game_objects.h"
2015-12-03 00:37:02 +00:00
#include "Singleton.h"
2015-12-03 00:37:37 +00:00
#include "train_system.h"
#include "map_helper.h"
2015-12-03 00:37:02 +00:00
namespace OpenGTA {
2015-12-03 00:37:37 +00:00
2018-09-23 11:14:17 +00:00
constexpr Uint32 CONST_ANIM_STANDING_STILL = 1;
constexpr Uint32 CONST_ANIM_WALKING = 2;
constexpr Uint32 CONST_ANIM_RUNNING = 3;
constexpr Uint32 CONST_ANIM_SITTING_IN_CAR = 30;
constexpr Uint32 CONST_ANIM_CAR_EXIT = 31;
constexpr Uint32 CONST_ANIM_CAR_ENTER = 32;
/*
registerAnimation(0, SpriteObject::Animation(0, 0)); // dummy
registerAnimation(1, SpriteObject::Animation(98, 0)); // standing still
registerAnimation(2, SpriteObject::Animation(0, 7, 0.001f)); // walking
registerAnimation(3, SpriteObject::Animation(8, 7, 0.0015f)); // running
// registerAnimation(3, SpriteObject::Animation(16, 0)); // sitting in car
// registerAnimation(4, SpriteObject::Animation(17, 7)); // car-exit
// registerAnimation(5, SpriteObject::Animation(25, 7)); // car-enter
//registerAnimation(3, SpriteObject::Animation(107, 7, 0.002f));
//registerAnimation(4, SpriteObject::Animation(99, 7, 0.001f));
//registerAnimation(5, SpriteObject::Animation(28, 7));
// registerAnimation(6, SpriteObject::Animation(38, 2)); // falling
//registerAnimation(7, SpriteObject::Animation(41, 0)); // sliding under
//registerAnimation(9, SpriteObject::Animation(44, 0)); // death-back pose
//registerAnimation(11, SpriteObject::Animation(47, 1)); // swimming
//registerAnimation(12, SpriteObject::Animation(98, 0)); // standing still
registerAnimation(4, SpriteObject::Animation(89, 0)); // standing, gun
registerAnimation(5, SpriteObject::Animation(99, 7, 0.001f)); // walking, gun
registerAnimation(6, SpriteObject::Animation(107, 7, 0.002f)); // running, gun
registerAnimation(7, SpriteObject::Animation(134, 0)); //standing, flamethrower
registerAnimation(8, SpriteObject::Animation(118, 7, 0.001f)); // walking, flamethrower
registerAnimation(9, SpriteObject::Animation(126, 7, 0.002f)); // running, flamethrower
registerAnimation(10, SpriteObject::Animation(152, 0)); //standing, uzi
registerAnimation(11, SpriteObject::Animation(136, 7, 0.001f)); // walking, uzi
registerAnimation(12, SpriteObject::Animation(144, 7, 0.002f)); // running, uzi
registerAnimation(13, SpriteObject::Animation(170, 0)); //standing, rocket-launcher
registerAnimation(14, SpriteObject::Animation(154, 7, 0.001f)); // walking, rocket-launcher
registerAnimation(15, SpriteObject::Animation(162, 7, 0.002f)); // running, rocket-launcher
registerAnimation(42, SpriteObject::Animation(42, 1)); // death pose; maybe just 1?
registerAnimation(45, SpriteObject::Animation(45, 1)); // shot-in-front
registerAnimation(46, SpriteObject::Animation(354, 12));*/
2015-12-03 00:37:37 +00:00
#if 0
2015-12-03 00:37:02 +00:00
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);
2015-12-03 00:37:37 +00:00
void drawExplosion(GameObject & obj);
void drawTrain(TrainSegment & train);
TrainSegment & getTrainById(const Uint32 & id);
2015-12-03 00:37:02 +00:00
void createProjectile(uint8_t typeId, float, Vector3D p, Vector3D d, Uint32 & ticks);
2015-12-03 00:37:37 +00:00
void createExplosion(Vector3D center);
2015-12-03 00:37:02 +00:00
void drawProjectile(Projectile & p);
void collideProjectile(Projectile & p);
2015-12-03 00:37:37 +00:00
typedef std::list<TrainSegment> TrainListType;
2015-12-03 00:37:02 +00:00
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;
2015-12-03 00:37:37 +00:00
TrainListType activeTrains;
public:
TrainSystem trainSystem;
protected:
2015-12-03 00:37:02 +00:00
typedef std::map<Uint32, SpriteObject::Animation> AnimLookupType;
AnimLookupType animations;
private:
Uint32 drawMode;
};
2015-12-03 00:37:37 +00:00
#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);
}
2018-09-23 11:14:17 +00:00
template <typename T> T & addPed(const T & t) {
return this->add(t);
}
2015-12-03 00:37:37 +00:00
template <typename T> size_t getNum() {
return AbstractContainer<T>::objs.size();
}
inline Pedestrian & getPed(uint32_t id) {
return AbstractContainer<Pedestrian>::doGet(id);
}
2018-09-23 11:14:17 +00:00
inline Pedestrian & getPedById(uint32_t id) {
return this->getPed(id);
}
2015-12-03 00:37:37 +00:00
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);
}
2018-09-23 11:14:17 +00:00
inline void removePedById(uint32_t id) {
this->removePed(id);
}
2015-12-03 00:37:37 +00:00
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;
2015-12-03 00:38:22 +00:00
Uint32 lastCreateTick;
2015-12-03 00:37:37 +00:00
//SpriteManager(const SpriteManager & o) : trainSystem(AbstractContainer<TrainSegment>::objs) {assert(0);}
SpriteManager(const SpriteManager & o) {assert(0);}
};
2015-12-03 00:37:02 +00:00
2018-09-23 05:57:34 +00:00
typedef Loki::SingletonHolder<SpriteManager> SpriteManagerHolder;
2015-12-03 00:37:02 +00:00
}
#endif