From 4d65ffffc0b6f35ac84e310fd4bc9739ea7e0c0a Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 5 Mar 2012 16:41:57 +0000 Subject: ChunkSender: Chunks are now compressed and sent to clients from a separate threads, proper passive waiting between threads. Not much tested, just appears to work :) git-svn-id: http://mc-server.googlecode.com/svn/trunk@365 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cBlockEntity.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'source/cBlockEntity.h') diff --git a/source/cBlockEntity.h b/source/cBlockEntity.h index ad1cf14ba..ab0a6c6ca 100644 --- a/source/cBlockEntity.h +++ b/source/cBlockEntity.h @@ -1,6 +1,13 @@ #pragma once +#include "cClientHandle.h" +#include "cWorld.h" + + + + + #ifndef _WIN32 #include "BlockID.h" #else @@ -16,9 +23,9 @@ namespace Json class Value; }; -class cClientHandle; class cPlayer; class cWorld; +class cPacket; @@ -49,7 +56,26 @@ public: virtual void SaveToJson (Json::Value & a_Value ) = 0; virtual void UsedBy( cPlayer * a_Player ) = 0; - virtual void SendTo( cClientHandle* a_Client ) { (void)a_Client; } + + void SendTo( cClientHandle* a_Client ) + { + std::auto_ptr Packet(GetPacket()); + if (Packet.get() == NULL) + { + return; + } + if ( a_Client != NULL ) + { + a_Client->Send(Packet.get()); + } + else // broadcast to all chunk clients + { + m_World->BroadcastToChunkOfBlock(m_PosX, m_PosY, m_PosZ, Packet.get()); + } + } + + /// Returns the packet to send to clients to represent this entity; NULL if no packet needed; caller is supposed to delete the packet + virtual cPacket * GetPacket(void) {return NULL; } protected: int m_PosX; // Position in block coordinates -- cgit v1.2.3