Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
committerStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
commit982562fa19bb87a3dab352e562f386f61c171b7b (patch)
treeaeade8d5b7d3c68f5c222af1d8ecc6a734e1b43f /src/core/entity.h
parentd198b7b8d9ff713d891f35ab173d1f428f610e7d (diff)
major rewrite of Cvar, Func and Entity
Diffstat (limited to 'src/core/entity.h')
-rw-r--r--src/core/entity.h204
1 files changed, 125 insertions, 79 deletions
diff --git a/src/core/entity.h b/src/core/entity.h
index b3dd7ef..7b3f200 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -15,136 +15,182 @@ class EntityControlable;
#include "core/player.h"
#include "math/mathlib.h"
-#include <vector>
+#include <string>
+#include <map>
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:
+ /// 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};
+
/// create a new entity and add it to the registry
- Entity(unsigned int entity_flags = 0);
+ Entity(unsigned int flags = 0);
+
+ /// destroy an entity
virtual ~Entity();
+
+/*----- inspectors ------------------------------------------------ */
+ /// entity id
+ inline unsigned int id() const { return entity_id; }
+
+ /// module type id
+ inline unsigned int moduletype() const { return entity_moduletypeid; }
+
/// core type id
- virtual inline unsigned int core_type() { return entity::Default; }
+ virtual inline unsigned int type() { return Default; }
- /// unique instance identifier, automaticly set
- unsigned int id;
+ /// entity flags
+ inline unsigned int flags() const { return entity_flags; }
- /// core shape id
- entity::Shape core_shape;
+ /// entity name
+ inline std::string const & name() { return entity_name; }
- /// core color
- math::Color core_color;
+ /// entity location
+ inline math::Vector3f const & location() const { return entity_location; }
- /// core radius, in game units
- float core_radius;
-
- /// the entities label
- std::string label;
+ /// direction the entity is facing, in degrees.
+ inline float direction() const { return entity_direction; }
+
+ /// base color of the entity
+ inline math::Color const & color() const { return entity_color; }
- /// custom game type id of this entity
- unsigned int type;
+ /// base shape of the entity
+ inline Shape shape() const { return entity_shape; }
- /// flags
- /// @see core::entity::Flags
- unsigned int flags;
+ /// base radius of the entity
+ inline float radius() const { return entity_radius; }
- /* updateable by game */
+/*----- mutators -------------------------------------------------- */
- /// location of the entity
- math::Vector3f location;
+ /// runs one game frame for the entity
+ /**
+ * The default implementation does nothing
+ */
+ virtual void frame(float seconds);
- /// direction the entity is facing, in degrees
- /// A direction of 0 degrees means the entity is looking
- /// along the positive X-axis.
- float direction;
+/*----- static ---------------------------------------------------- */
+
+ /// the entity registry
+ static std::map<unsigned int, Entity*> registry;
+
+ /// find an entity in the registry
+ static Entity *find(unsigned int id);
+
+ /// remove one entity from the registry and deletes it
+ static void remove(unsigned int entity_id);
+
+ /// list the entity registry
+ static void list();
+
+ /* entity_ variables can be set by the module */
+ float entity_radius;
+ std::string entity_name;
+ Shape entity_shape;
+ math::Vector3f entity_location;
+ math::Color entity_color;
+ /*
+ * A direction of 0 degrees means the entity is looking
+ * along the positive X-axis. Positive angle is along the negative Z-axis.
+ */
+ float entity_direction;
+ unsigned int entity_moduletypeid;
+ unsigned int entity_flags;
+
+private:
+ /// add an entity to the registry
+ static void add(Entity *ent);
+
+ /// the id is set by add()
+ unsigned int entity_id;
};
/// an entity that can move around in the game world
class EntityDynamic : public Entity
{
public:
- EntityDynamic(unsigned int entity_flags = 0);
+ EntityDynamic(unsigned int flags = 0);
virtual ~EntityDynamic();
+/*----- inspectors ------------------------------------------------ */
/// core type id
- virtual inline unsigned int core_type() { return entity::Dynamic; }
-
- /* updateable by game */
+ virtual inline unsigned int type() { return Entity::Dynamic; }
/// current speed of the entity in game units per second
- float speed;
+ inline float speed() const { return entity_speed; }
+
+/*----- mutators -------------------------------------------------- */
+
+ /// runs one game frame for the entity
+ /**
+ * The default implementation will update the position() of the entity,
+ * determined by its speed() and direction()
+ */
+ virtual void frame(float seconds);
+
+ /// speed of the entity
+ float entity_speed;
};
/// an entity that can be controlled by a player
class EntityControlable : public EntityDynamic
{
public:
- EntityControlable(unsigned int entity_flags = 0);
+ /// create
+ EntityControlable(Player *player, unsigned int 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 */
+/*----- inspectors ------------------------------------------------ */
- /// owner of this controllable entity
- Player *owner;
-
- /* updatable by client */
+ /// core type id
+ virtual inline unsigned int type() { return Entity::Controlable; }
- /// the direction the client wants to travel the entity to
- /// @see direction
- float target_direction;
+ /// owner of this entity
+ inline Player *owner() const { return entity_owner; }
- /// engine thrust as set by the client, 0.0f - 1.0f
- float target_thrust;
-};
+ /// thrust
+ inline float thrust() const { return entity_thrust; }
+/*----- mutators -------------------------------------------------- */
-namespace entity
-{
+ /// set the target thrust
+ void set_thrust(float t);
-/// the entity registry
-extern std::vector<Entity*> registry;
+ /// set the target direction
+ void set_direction(float t);
-/// add an entity to the registry
-void add(Entity *ent);
+ /// runs one game frame for the entity
+ /**
+ * The default implementation will set direction() and thrust() to the desired targets
+ * and calls its parent frame() funcion.
+ */
+ virtual void frame(float seconds);
-/// remove one entity from the registry
-void remove(unsigned int entity_id);
+ /* entity_ variables can be set by the module */
-/// clear the entity registry
-void clear();
+ /// owner of the entity
+ Player *entity_owner;
+ /// current thrust
+ float entity_thrust;
-/// list the entity registry
-void list();
+ /* target_ variables can be set by the client */
-/// run a game frame on each entity in the registry
-void frame(float seconds);
-
-}
+ /// target thrust as set by the client
+ float target_thrust;
+ /// target direction as set by the client
+ float target_direction;
+};
}