From 75c6db097b990e58b4b2585580a89561c838d923 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 26 Oct 2010 21:08:12 +0000 Subject: updated network protocol version to 20, implemented invemtory depletion, unified depletion with keepalive --- src/core/entity.h | 85 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 41 deletions(-) (limited to 'src/core/entity.h') 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; @@ -254,6 +259,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 @@ -282,18 +296,42 @@ 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 */ @@ -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; }; -- cgit v1.2.3