Code Search for Developers
 
 
  

EntityManager.h from palisma2d at Krugle


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 &region, 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

palisma2d

The University of Wisconsin-Parkside Developers Union first product. More info to come. Code name Palisma.

Project homepage: http://code.google.com/p/palisma2d/
Programming language(s): C,C++
License: gpl2

  DialogModel.cpp
  DialogModel.h
  DialogState.cpp
  DialogState.h
  Enemy.cpp
  Enemy.h
  EntityController.cpp
  EntityController.h
  EntityEvents.cpp
  EntityEvents.h
  EntityFactory.cpp
  EntityFactory.h
  EntityManager.cpp
  EntityManager.h
  EntityStates.cpp
  EntityStates.h
  Event.h
  HUD.cpp
  HUD.h
  IEntity.cpp
  IEntity.h
  IWeapon.cpp
  IWeapon.h
  InGameState.cpp
  InGameState.h
  Inventory.cpp
  Inventory.h
  MissionHolder.cpp
  MissionHolder.h
  Player.cpp
  Player.h
  PlayerConfig.cpp
  PlayerConfig.h
  PlayerController.cpp
  PlayerController.h
  QuestImporter.cpp
  QuestImporter.h
  ReadMe.txt
  Scene.cpp
  Scene.h
  Shotgun.cpp
  Shotgun.h
  State.h
  StateFactory.cpp
  StateFactory.h
  StateMachine.cpp
  StateMachine.h
  Tile.cpp
  Tile.h
  Weather.cpp
  Weather.h
  stdafx.cpp
  stdafx.h