diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-21 19:06:15 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-21 19:06:15 +0000 |
commit | 8aa04fc836116a58f8ffd1e0c3539b9ea8a94ddf (patch) | |
tree | bb933edb3919ed67d05b098a6b97a73f01746762 /src/core/entity.h | |
parent | 41ad1e4c9e2a70d0a8811f4b035f0d3018045e61 (diff) |
dedicated server, entity transfer
Diffstat (limited to 'src/core/entity.h')
-rw-r--r-- | src/core/entity.h | 88 |
1 files changed, 82 insertions, 6 deletions
diff --git a/src/core/entity.h b/src/core/entity.h index df16075..9c90ef9 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -15,6 +15,7 @@ class EntityControlable; #include "core/player.h" #include "math/mathlib.h" +#include <iostream> #include <string> #include <map> @@ -29,7 +30,7 @@ public: enum Flags {Static=1, Solid=2}; /// Entity type constants - enum Type {Default = 0, Dynamic = 1, Controlable = 2}; + enum Type {Default=0, Dynamic=1, Controlable=2}; /// Entity shape constants enum Shape {Diamond=0, Sphere=1, Cube=2}; @@ -37,6 +38,9 @@ public: /// create a new entity and add it to the registry Entity(unsigned int flags = 0); + /// create an entity froms stream data + Entity(std::istream & is); + /// destroy an entity virtual ~Entity(); @@ -49,14 +53,17 @@ public: inline unsigned int moduletype() const { return entity_moduletypeid; } /// core type id - virtual inline unsigned int type() { return Default; } + virtual inline unsigned int type() const { return Default; } /// entity flags inline unsigned int flags() const { return entity_flags; } - /// entity name + /// entity name (can not contain double qoutes ") inline std::string const & name() { return entity_name; } + /// dirty flag + inline bool dirty() const { return entity_dirty; } + /// entity location inline math::Vector3f const & location() const { return entity_location; } @@ -72,8 +79,27 @@ public: /// base radius of the entity inline float radius() const { return entity_radius; } + /// serialize the entity to a stream + virtual void serialize(std::ostream & os) const; + + /// serialize a client-to-server update on a stream + virtual void serialize_client_update(std::ostream & os) const; + + /// serialize a server-to-client update on a stream + virtual void serialize_server_update(std::ostream & os) const; + + /*----- mutators -------------------------------------------------- */ + /// receive a client-to-server update from a stream + virtual void recieve_client_update(std::istream &is); + + /// receive a server-to-client update from a stream + virtual void recieve_server_update(std::istream &is); + + /// mark the entity as destroyed + inline void die() { entity_destroyed = true; } + /// runs one game frame for the entity /** * The default implementation does nothing @@ -108,30 +134,59 @@ public: unsigned int entity_moduletypeid; unsigned int entity_flags; + bool entity_dirty; + bool entity_created; + bool entity_destroyed; + private: /// add an entity to the registry static void add(Entity *ent); + /// add an entity with id to the registry + void add(Entity *ent, unsigned int id); + /// 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: + /// create a dynamic entity EntityDynamic(unsigned int flags = 0); + + /// create a dynamic entity from stream data + EntityDynamic(std::istream & is); + virtual ~EntityDynamic(); + /*----- inspectors ------------------------------------------------ */ /// core type id - virtual inline unsigned int type() { return Entity::Dynamic; } + virtual inline unsigned int type() const { return Entity::Dynamic; } /// current speed of the entity in game units per second inline float speed() const { return entity_speed; } + /// serialize the entity to a stream + virtual void serialize(std::ostream & os) const; + + /// serialize a client-to-server update on a stream + virtual void serialize_client_update(std::ostream & os) const ; + + /// serialize a server-to-client update on a stream + virtual void serialize_server_update(std::ostream & os) const; + /*----- mutators -------------------------------------------------- */ + /// receive a client-to-server update from a stream + virtual void recieve_client_update(std::istream &is); + + /// receive a server-to-client update from a stream + virtual void recieve_server_update(std::istream &is); + /// runs one game frame for the entity /** * The default implementation will update the position() of the entity, @@ -147,14 +202,19 @@ public: class EntityControlable : public EntityDynamic { public: - /// create + /// create a controlable entity EntityControlable(Player *player, unsigned int flags = 0); + + /// create a controlable entity from stream data + EntityControlable(std::istream & is); + virtual ~EntityControlable(); + /*----- inspectors ------------------------------------------------ */ /// core type id - virtual inline unsigned int type() { return Entity::Controlable; } + virtual inline unsigned int type() const { return Entity::Controlable; } /// owner of this entity inline Player *owner() const { return entity_owner; } @@ -162,8 +222,24 @@ public: /// thrust inline float thrust() const { return entity_thrust; } + /// serialize the entity to a stream + virtual void serialize(std::ostream & os) const; + + /// serialize a client-to-server update on a stream + virtual void serialize_client_update(std::ostream & os) const; + + /// serialize a server-to-client update on a stream + virtual void serialize_server_update(std::ostream & os) const; + + /*----- mutators -------------------------------------------------- */ + /// receive a client-to-server update from a stream + virtual void recieve_client_update(std::istream &is); + + /// receive a server-to-client update from a stream + virtual void recieve_server_update(std::istream &is); + /// set the target thrust void set_thrust(float t); |