Show EntityManager.h syntax highlighted
/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG *
*Copyright (C) 2006, Tony Sparks *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
#pragma once
#include "ientity.h"
#include "IWeapon.h"
#include "Player.h"
#include <string>
#include <map>
class Scene;
/**
==========================
Manage all the entities of the world
Singleton
==========================
*/
template<class T>
class QuadTree;
class EntityManager
{
public:
/** Only allow one instance of the Entity Manager */
static EntityManager* GetInstance() { return instance; }
/** Update each entity */
void Update(long dt);
/** Create an empty Entity */
IEntity* CreateEntity(const std::string &entName);
/** Clone an entity */
IEntity* CloneEntity(const IEntity* ent);
/** Create the Player */
Player* CreatePlayer(const std::string &pName);
/** Create a weapon */
IWeapon* CreateWeapon(const std::string &wName );
/** Remove the entity without deleting it */
void RemoveWithoutDeleting(IEntity* ent);
/** Add the entity to the map */
void AddEntity( IEntity* ent) {
entities.push_back( ent );
};
/** Get the Player */
Player* GetPlayer();
/** Register the entity */
void RegisterEntity( IEntity* ent );
/** Find Entity by Name */
IEntity* Find( const std::string &name );
/** Find Entity by id */
IEntity* Find( int id );
/** Find the first entity in a given region */
IEntity* FindInRegion( Rect ®ion, IEntity* ignoreMe = NULL ); // VERY SLOW
/** How many entities are active */
size_t Count() { return entities.size(); };
/** HACK--How to register the Map with entities?
Reference: Currently I register the scene
when we load a new Scene, look at InGameStateView::LoadScene()
with the EntityManager, this is horrible and NEEDS fixing.
*/
void SetScene(Scene* scene);
private:
EntityManager(void);
/** Prune the entity List */
void CleanDeadEntities();
/** Move each entity that needs to be moved */
bool Move(IEntity* ent, long deltaTime);
/** Move X coord of an ent */
void MoveX(IEntity *ent, float xmove, float ymove, Scene* scene );
/** Move Y coord of an ent */
void MoveY(IEntity *ent, float xmove, float ymove, Scene* scene );
/** Check collision between entities */
bool CheckCollision(IEntity* ent, float x, float y);
// entity list
typedef std::list<IEntity* > type_ents;
type_ents entities;
// our instance
static EntityManager *instance;
// ids
static unsigned int m_idcounter;
// if the player has been created
bool m_playerCreated;
// Get the player
Player* m_player;
// it hurts me to write this
// the current scene
Scene* m_scene;
QuadTree<IEntity*> *quadTree;
public:
virtual ~EntityManager(void);
};
See more files for this project here