diff options
Diffstat (limited to 'src/core/entity.h')
-rw-r--r-- | src/core/entity.h | 139 |
1 files changed, 73 insertions, 66 deletions
diff --git a/src/core/entity.h b/src/core/entity.h index 41c56b4..3002219 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -54,7 +54,7 @@ public: typedef std::list<MenuDescription *> Menus; /// create a new entity and add it to the registry - Entity(unsigned int flags = 0); + Entity(const unsigned int flags = 0); /// create an entity from stream data Entity(std::istream & is); @@ -65,25 +65,25 @@ public: /*----- inspectors ------------------------------------------------ */ /// entity id - inline unsigned int id() const { return entity_id; } + inline const unsigned int id() const { return entity_id; } /// module type id - inline unsigned int moduletype() const { return entity_moduletypeid; } + inline const unsigned int moduletype() const { return entity_moduletypeid; } /// core type id virtual inline const unsigned int type() const { return Default; } /// entity flags - inline unsigned int flags() const { return entity_flags; } + inline const unsigned int flags() const { return entity_flags; } /// returns true of a flag is set - inline bool flag_is_set(const Flags flag) const { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); } + inline const bool flag_is_set(const Flags flag) const { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); } /// entity label (can not contain double quotes ") - inline std::string const & label() { return entity_label; } + inline const std::string& label() const { return entity_label; } /// entity name (can not contain double qoutes ") - inline std::string const & name() { return entity_name; } + inline const std::string & name() const { return entity_name; } /// pointer to the model, is used client-side inline model::Model * model() { return entity_model; } @@ -134,7 +134,10 @@ public: inline Extension *extension(size_t type) const { return entity_extension[type]; } /// find a menu - MenuDescription *find_menu(std::string const &label); + MenuDescription *find_menu(const std::string &label); + + + /* ---- mutators -------------------------------------------------- */ /// assign entity color inline void set_color(const math::Color &color) { entity_color.assign(color); } @@ -142,27 +145,8 @@ public: /// assign entity secondary color inline void set_color_second(const math::Color &color) { entity_color_second.assign(color); } -/*----- serializers ----------------------------------------------- */ - - /// serialize the entity to a stream - virtual void serialize_server_create(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 receive_client_update(std::istream &is); - - /// receive a server-to-client create from a stream - virtual void receive_server_create(std::istream &is); - - /// receive a server-to-client update from a stream - virtual void receive_server_update(std::istream &is); + /// set dirty flag + inline void set_dirty(const bool dirty = true) { entity_dirty = dirty; } /// mark the entity as destroyed virtual void die(); @@ -173,33 +157,31 @@ public: */ virtual void frame(float seconds); - /// called when the entity received a docking request - virtual void dock(core::Entity *entity); - - /// set dirty flag - inline void set_dirty() { entity_dirty = true; } - - /// set the zone the entity is currently in /** + * @brief set the zone the entity is currently in + * * this fuction removes the entity from its previous zone * and removes it to the new one, if it is not 0 */ virtual void set_zone(Zone *zone); /// set the label - void set_label(char const *label); + void set_label(const char *label); /// set the label void set_label(const std::string &label); /// set the name - void set_name(char const *name); + void set_name(const char *name); /// set the name void set_name(const std::string &name); /// set visibility - void set_visible(bool visible = true); + inline void set_visible(const bool visible = true) { entity_visible = visible; } + + /// set as server-side entity + inline void set_serverside(const bool serverside = true) { entity_serverside = serverside; } /// set the model name and load the model void set_modelname(const std:: string &model); @@ -207,17 +189,19 @@ public: /// set the model void set_model(model::Model *model); - /// show the entity, make it visible - virtual void show(); + /// set entity radius + inline void set_radius(const float radius) { entity_radius = radius; } - /// hide the entity, make it invisible - virtual void hide(); + /* ---- actors ---------------------------------------------------- */ - /// set a flag - void set_flag(Flags flag); + /// called when the entity received a docking request + virtual void dock(core::Entity *entity); + + /// set flags + inline void set_flag(Flags flag) { entity_flags |= flag; } - /// unset a flag - void unset_flag(Flags flag); + /// unset flags + inline void unset_flag(Flags flag) { entity_flags &= ~flag; } /// add an entity menu void add_menu(MenuDescription *menu); @@ -228,8 +212,6 @@ public: /// clear all update flags virtual void clear_updates(); -/*----- actors ---------------------------------------------------- */ - /** * @brief mutable reference to the location */ @@ -251,7 +233,30 @@ public: inline math::Color& get_color_second() { return entity_color_second; } -/*----- static ---------------------------------------------------- */ + /* ---- deserializers -------------------------------------- */ + + /// receive a client-to-server update from a stream + virtual void receive_client_update(std::istream &is); + + /// receive a server-to-client create from a stream + virtual void receive_server_create(std::istream &is); + + /// receive a server-to-client update from a stream + virtual void receive_server_update(std::istream &is); + + /* ---- serializers ---------------------------------------- */ + + /// serialize the entity to a stream + virtual void serialize_server_create(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; + + + /* ---- static --------------------------------------------- */ /// type definition for the entity registry typedef std::map<unsigned int, Entity*> Registry; @@ -275,41 +280,43 @@ public: /// speed of the entity float entity_speed; - float entity_radius; Shape entity_shape; unsigned int entity_moduletypeid; - bool entity_dirty; bool entity_created; bool entity_destroyed; /// timestamp when entity data was received from the server float entity_servertimestamp; -protected: - // the zone the entity belongs to - Zone *entity_zone; - // the previous zone the entity belonged too - Zone *entity_oldzone; +private: + + unsigned int entity_id; + unsigned int entity_flags; + bool entity_dirty; bool entity_visible; bool entity_serverside; math::Vector3f entity_location; math::Axis entity_axis; + + float entity_radius; + math::Color entity_color; math::Color entity_color_second; -private: - unsigned int entity_id; - unsigned int entity_flags; - std::string entity_name; std::string entity_label; - - model::Model *entity_model; std::string entity_modelname; + model::Model* entity_model; + + // the zone the entity belongs to + Zone* entity_zone; + // the previous zone the entity belonged too + Zone* entity_oldzone; + Menus entity_menus; Extension* entity_extension[4]; @@ -326,7 +333,7 @@ class EntityDynamic : public Entity { public: /// create a dynamic entity - EntityDynamic(unsigned int flags = 0); + EntityDynamic(const unsigned int flags = 0); /// create a dynamic entity from stream data EntityDynamic(std::istream & is); @@ -387,7 +394,7 @@ class EntityControlable : public EntityDynamic friend class Player; public: /// create a controlable entity - EntityControlable(Player *owner, unsigned int flags = 0); + EntityControlable(Player *owner, const unsigned int flags = 0); /// create a controlable entity from stream data EntityControlable(std::istream & is); @@ -490,7 +497,7 @@ private: class EntityGlobe : public Entity { public: - EntityGlobe(unsigned int flags = 0); + EntityGlobe(const unsigned int flags = 0); EntityGlobe(std::istream & is); virtual ~EntityGlobe(); |