diff options
Diffstat (limited to 'src/serverobject.h')
-rw-r--r-- | src/serverobject.h | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/src/serverobject.h b/src/serverobject.h index 5e3afb57b..d3dabdd4d 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -40,6 +40,38 @@ Some planning */ +#if 0 +class IntervalLimiter +{ +public: + IntervalLimiter(): + m_accumulator(0) + { + } + /* + dtime: time from last call to this method + wanted_interval: interval wanted + return value: + true: action should be skipped + false: action should be done and dtime has been set + */ + bool step(float &dtime, float wanted_interval) + { + accumulator += dtime; + if(accumulator < wanted_interval) + { + dtime = 0; + return true; + } + accumulator -= wanted-interval; + dtime = wanted_interval; + return false; + } +protected: + float m_accumulator; +}; +#endif + class ServerEnvironment; class InventoryItem; @@ -67,8 +99,15 @@ public: /* Step object in time. Messages added to messages are sent to client over network. + + send_recommended: + True at around 5 times a second, same for all objects. + This is used to let objects send most of the data at the + same time so that the data can be combined in a single + packet. */ - virtual void step(float dtime, Queue<ActiveObjectMessage> &messages){} + virtual void step(float dtime, Queue<ActiveObjectMessage> &messages, + bool send_recommended){} /* The return value of this is passed to the client-side object @@ -83,6 +122,12 @@ public: */ virtual std::string getStaticData(){return "";} + /* + Item that the player gets when this object is picked up. + If NULL, object cannot be picked up. + */ + virtual InventoryItem* createPickedUpItem(){return NULL;} + // Number of players which know about this object u16 m_known_by_count; /* @@ -129,7 +174,8 @@ public: {return ACTIVEOBJECT_TYPE_TEST;} static ServerActiveObject* create(ServerEnvironment *env, u16 id, v3f pos, const std::string &data); - void step(float dtime, Queue<ActiveObjectMessage> &messages); + void step(float dtime, Queue<ActiveObjectMessage> &messages, + bool send_recommended); private: float m_timer1; float m_age; @@ -144,13 +190,40 @@ public: {return ACTIVEOBJECT_TYPE_ITEM;} static ServerActiveObject* create(ServerEnvironment *env, u16 id, v3f pos, const std::string &data); - void step(float dtime, Queue<ActiveObjectMessage> &messages); + void step(float dtime, Queue<ActiveObjectMessage> &messages, + bool send_recommended); std::string getClientInitializationData(); std::string getStaticData(); InventoryItem* createInventoryItem(); + InventoryItem* createPickedUpItem(){return createInventoryItem();} private: std::string m_inventorystring; v3f m_speed_f; + v3f m_last_sent_position; +}; + +class RatSAO : public ServerActiveObject +{ +public: + RatSAO(ServerEnvironment *env, u16 id, v3f pos); + u8 getType() const + {return ACTIVEOBJECT_TYPE_RAT;} + static ServerActiveObject* create(ServerEnvironment *env, u16 id, v3f pos, + const std::string &data); + void step(float dtime, Queue<ActiveObjectMessage> &messages, + bool send_recommended); + std::string getClientInitializationData(); + std::string getStaticData(); + InventoryItem* createPickedUpItem(); +private: + v3f m_speed_f; + v3f m_oldpos; + v3f m_last_sent_position; + float m_yaw; + float m_counter1; + float m_counter2; + float m_age; + bool m_touching_ground; }; #endif |