X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fclient.h;h=ee73cc42ce83a1e6d3e61076ae84e1e5cd881700;hb=ea3c653a8b6352b1df234e6a9663499e9a42bf90;hp=3915282865e0365609550a42a7530f42445d74f3;hpb=fa08294d09a46b603e9ff5e034010c0a7986c61a;p=dragonfireclient.git diff --git a/src/client.h b/src/client.h index 391528286..ee73cc42c 100644 --- a/src/client.h +++ b/src/client.h @@ -174,57 +174,30 @@ class MeshUpdateThread : public SimpleThread MutexedQueue m_queue_out; }; -#if 0 -struct IncomingPacket +enum ClientEventType { - IncomingPacket() - { - m_data = NULL; - m_datalen = 0; - m_refcount = NULL; - } - IncomingPacket(const IncomingPacket &a) - { - m_data = a.m_data; - m_datalen = a.m_datalen; - m_refcount = a.m_refcount; - if(m_refcount != NULL) - (*m_refcount)++; - } - IncomingPacket(u8 *data, u32 datalen) - { - m_data = new u8[datalen]; - memcpy(m_data, data, datalen); - m_datalen = datalen; - m_refcount = new s32(1); - } - ~IncomingPacket() - { - if(m_refcount != NULL){ - assert(*m_refcount > 0); - (*m_refcount)--; - if(*m_refcount == 0){ - if(m_data != NULL) - delete[] m_data; - delete m_refcount; - } - } - } - /*IncomingPacket & operator=(IncomingPacket a) - { - m_data = a.m_data; - m_datalen = a.m_datalen; - m_refcount = a.m_refcount; - (*m_refcount)++; - return *this; - }*/ - u8 *m_data; - u32 m_datalen; - s32 *m_refcount; + CE_NONE, + CE_PLAYER_DAMAGE, + CE_PLAYER_FORCE_MOVE }; -#endif -class Client : public con::PeerHandler +struct ClientEvent +{ + ClientEventType type; + union{ + struct{ + } none; + struct{ + u8 amount; + } player_damage; + struct{ + f32 pitch; + f32 yaw; + } player_force_move; + }; +}; + +class Client : public con::PeerHandler, public InventoryManager { public: /* @@ -275,10 +248,13 @@ class Client : public con::PeerHandler void groundAction(u8 action, v3s16 nodepos_undersurface, v3s16 nodepos_oversurface, u16 item); void clickObject(u8 button, v3s16 blockpos, s16 id, u16 item); + void clickActiveObject(u8 button, u16 id, u16 item); void sendSignText(v3s16 blockpos, s16 id, std::string text); + void sendSignNodeText(v3s16 p, std::string text); void sendInventoryAction(InventoryAction *a); void sendChatMessage(const std::wstring &message); + void sendDamage(u8 damage); // locks envlock void removeNode(v3s16 p); @@ -302,6 +278,11 @@ class Client : public con::PeerHandler // Copies the inventory of the local player to parameter void getLocalInventory(Inventory &dst); + InventoryContext *getInventoryContext(); + + Inventory* getInventory(InventoryContext *c, std::string id); + void inventoryAction(InventoryAction *a); + // Gets closest object pointed by the shootline // Returns NULL if not found MapBlockObject * getSelectedObject( @@ -310,11 +291,21 @@ class Client : public con::PeerHandler core::line3d shootline_on_map ); + // Gets closest object pointed by the shootline + // Returns NULL if not found + ClientActiveObject * getSelectedActiveObject( + f32 max_d, + v3f from_pos_f_on_map, + core::line3d shootline_on_map + ); + // Prints a line or two of info void printDebugInfo(std::ostream &os); u32 getDayNightRatio(); + u16 getHP(); + //void updateSomeExpiredMeshes(); void setTempMod(v3s16 p, NodeMod mod) @@ -379,13 +370,13 @@ class Client : public con::PeerHandler u64 getMapSeed(){ return m_map_seed; } - /* - These are not thread-safe - */ void addUpdateMeshTask(v3s16 blockpos, bool ack_to_server=false); // Including blocks at appropriate edges void addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server=false); + // Get event from queue. CE_NONE is returned if queue is empty. + ClientEvent getClientEvent(); + private: // Virtual methods from con::PeerHandler @@ -404,6 +395,7 @@ class Client : public con::PeerHandler float m_connection_reinit_timer; float m_avg_rtt_timer; float m_playerpos_send_timer; + float m_ignore_damage_timer; // Used after server moves player MeshUpdateThread m_mesh_update_thread; @@ -437,6 +429,10 @@ class Client : public con::PeerHandler // The seed returned by the server in TOCLIENT_INIT is stored here u64 m_map_seed; + + InventoryContext m_inventory_context; + + Queue m_client_event_queue; }; #endif // !SERVER