/* core/entity.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2. */ #ifndef __INCLUDED_CORE_ENTITY_H__ #define __INCLUDED_CORE_ENTITY_H__ namespace core { class EntityControlable; } #include "core/player.h" #include "math/mathlib.h" #include namespace core { namespace entity { /// Entity flags enum Flags {Static=1, Solid=2}; /// Entity type constants enum Type {Default = 0, Dynamic = 1, Controlable = 2}; /// Entity shape constants enum Shape {Diamond=0, Sphere=1, Cube=2}; } /// The base world entity. All gameworld entities must derive from this class. class Entity { public: /// create a new entity and add it to the registry Entity(unsigned int entity_flags = 0); virtual ~Entity(); /// core type id virtual inline unsigned int core_type() { return entity::Default; } /// unique instance identifier, automaticly set unsigned int id; /// core shape id entity::Shape core_shape; /// core color math::Color core_color; /// core radius, in game units float core_radius; /// the entities label std::string label; /// custom game type id of this entity unsigned int type; /// flags /// @see core::entity::Flags unsigned int flags; /* updateable by game */ /// location of the entity math::Vector3f location; /// direction the entity is facing, in degrees /// A direction of 0 degrees means the entity is looking /// along the positive X-axis. float direction; }; /// an entity that can move around in the game world class EntityDynamic : public Entity { public: EntityDynamic(unsigned int entity_flags = 0); virtual ~EntityDynamic(); /// core type id virtual inline unsigned int core_type() { return entity::Dynamic; } /* updateable by game */ /// current speed of the entity in game units per second float speed; }; /// an entity that can be controlled by a player class EntityControlable : public EntityDynamic { public: EntityControlable(unsigned int entity_flags = 0); virtual ~EntityControlable(); /// core type id virtual inline unsigned int core_type() { return entity::Controlable; } /// runs one game frame for the entity, to be implemented by game virtual void frame(float seconds) = 0; /* updateable by game */ /// owner of this controllable entity Player *owner; /* updatable by client */ /// the direction the client wants to travel the entity to /// @see direction float target_direction; /// engine thrust as set by the client, 0.0f - 1.0f float target_thrust; }; namespace entity { /// the entity registry extern std::vector registry; /// add an entity to the registry void add(Entity *ent); /// remove one entity from the registry void remove(unsigned int entity_id); /// clear the entity registry void clear(); /// list the entity registry void list(); /// run a game frame on each entity in the registry void frame(float seconds); } } #endif // __INCLUDED_CORE_ENTITY_H__