diff options
author | Stijn Buys <ingar@osirion.org> | 2010-10-26 21:08:12 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-10-26 21:08:12 +0000 |
commit | 75c6db097b990e58b4b2585580a89561c838d923 (patch) | |
tree | 8c913bdc531ea9a76dcaa9e10a65763f95fa55e4 /src/core/entity.h | |
parent | 23c7d2c11170ee8736673e82a88e87a3d2e538f7 (diff) |
updated network protocol version to 20, implemented invemtory depletion, unified depletion with keepalive
Diffstat (limited to 'src/core/entity.h')
-rw-r--r-- | src/core/entity.h | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/src/core/entity.h b/src/core/entity.h index 8dd5644..954b261 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -216,6 +216,11 @@ public: return entity_destroyed; } + /// time when the entity was last alive + inline unsigned long keepalive() const { + return entity_keepalive; + } + /// list inventory, if available, to console void list_inventory() const; @@ -255,6 +260,15 @@ public: virtual void frame(float seconds); /** + * @brief runs one upkeep frame for the entity + * The upkeep frame will be executed by the engine if the entity has the KeepAlive flag set + * and the keepalive timeout has been elapsed. + * The default implementation does nothing + * @param timestamp game timestamp for the current upkeep frame + */ + virtual void upkeep(const unsigned long timestamp); + + /** * @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 @@ -282,19 +296,43 @@ public: entity_radius = radius; } - /* ---- actors ---------------------------------------------------- */ + + /// set location + inline void set_location(const math::Vector3f &location) { + entity_location.assign(location); + } + + /// set location + inline void set_axis(const math::Axis &axis) { + entity_axis.assign(axis); + } - /// set flags + /// set flag inline void set_flag(Flags flag) { entity_flags |= flag; } - /// unset flags + /// unset flag inline void unset_flag(Flags flag) { entity_flags &= ~flag; } /** + * @brief add an inventory to this entity + * Entity takes ownership over the inventory pointer + */ + void set_inventory(Inventory *inventory); + + void set_info(Info *info); + + /// set the timestamp when the entity was last alive + void set_keepalive(unsigned long timestamp) { + entity_keepalive = timestamp; + } + + /* ---- actors ---------------------------------------------------- */ + + /** * @brief reset the physics state */ virtual void reset(); @@ -307,16 +345,6 @@ public: /// clear all update flags virtual void clear_updates(); - - /// set location - inline void set_location(const math::Vector3f &location) { - entity_location.assign(location); - } - - /// set location - inline void set_axis(const math::Axis &axis) { - entity_axis.assign(axis); - } /** * @brief mutable reference to the location @@ -345,15 +373,7 @@ public: inline math::Color& get_color_second() { return entity_color_second; } - - /** - * @brief add an inventory to this entity - * Entity takes ownership over the inventory pointer - */ - void set_inventory(Inventory *inventory); - - void set_info(Info *info); - + /* ---- deserializers -------------------------------------- */ /// receive a client-to-server update from a stream @@ -376,7 +396,6 @@ public: /// 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 @@ -459,6 +478,8 @@ private: Extension* entity_extension[4]; + unsigned long entity_keepalive; + static Registry entity_registry; static size_t entity_nextid; @@ -494,16 +515,6 @@ public: return entity_timer; } - /// time when the entity was last alive - inline const float keepalive_time() const { - return entity_keepalive_time; - } - - /// keepalive timeout - inline const float keepalive_timeout() const { - return entity_keepalive_timeout; - } - /*----- mutators -------------------------------------------------- */ /// mass of the entity @@ -540,12 +551,6 @@ public: /// set event state virtual void set_state(int state); - - /// set the time when the entity was last alive, in game time seconds - void set_keepalive_time(float time); - - /// set the timeout after which the entitie is deleted, in seconds - void set_keepalive_timeout(float timeout); /// runs one game frame for the entity /** @@ -560,8 +565,6 @@ public: virtual void reset(); protected: - float entity_keepalive_time; - float entity_keepalive_timeout; float entity_timer; int entity_state; }; |