From 674fe1e955f729e8328772313c45fe76857ec835 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 19 Aug 2012 21:14:45 +0000 Subject: Window, Chest, Furnace and Pawn are not using cPackets at all git-svn-id: http://mc-server.googlecode.com/svn/trunk@762 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cChestEntity.h | 1 - source/cChunk.cpp | 32 +++++++++++++++++ source/cChunk.h | 5 ++- source/cChunkMap.cpp | 33 ++++++++++++++++++ source/cChunkMap.h | 5 +++ source/cClientHandle.cpp | 39 +++++++++++++++++++++ source/cClientHandle.h | 4 +++ source/cEntity.cpp | 13 ++----- source/cEntity.h | 50 +++++++++++++++++---------- source/cFurnaceEntity.cpp | 31 +++++------------ source/cPawn.cpp | 46 ++++++++++++------------ source/cPawn.h | 2 +- source/cWindow.cpp | 4 +-- source/cWindow.h | 3 +- source/cWorld.cpp | 18 ++++++++++ source/cWorld.h | 2 ++ source/packets/cPacket_InventoryProgressBar.h | 11 +++--- 17 files changed, 211 insertions(+), 88 deletions(-) (limited to 'source') diff --git a/source/cChestEntity.h b/source/cChestEntity.h index 0f37bdc81..c97eef5ad 100644 --- a/source/cChestEntity.h +++ b/source/cChestEntity.h @@ -3,7 +3,6 @@ #include "cBlockEntity.h" #include "cWindowOwner.h" -#include "packets/cPacket_BlockAction.h" diff --git a/source/cChunk.cpp b/source/cChunk.cpp index 4d3c928a6..001c795eb 100644 --- a/source/cChunk.cpp +++ b/source/cChunk.cpp @@ -1883,6 +1883,38 @@ void cChunk::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandl +void cChunk::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude) +{ + for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) + { + if (*itr == a_Exclude) + { + continue; + } + (*itr)->SendEntityStatus(a_Entity, a_Status); + } // for itr - LoadedByClient[] +} + + + + + +void cChunk::BroadcastMetadata(const cPawn & a_Pawn, const cClientHandle * a_Exclude) +{ + for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) + { + if (*itr == a_Exclude) + { + continue; + } + (*itr)->SendMetadata(a_Pawn); + } // for itr - LoadedByClient[] +} + + + + + void cChunk::PositionToWorldPosition(int a_ChunkX, int a_ChunkY, int a_ChunkZ, int & a_X, int & a_Y, int & a_Z) { a_Y = a_ChunkY; diff --git a/source/cChunk.h b/source/cChunk.h index 71811c7d5..1678bbf91 100644 --- a/source/cChunk.h +++ b/source/cChunk.h @@ -41,6 +41,7 @@ class cChunkMap; class cChestEntity; class cFurnaceEntity; class cBlockArea; +class cPawn; typedef std::list cClientHandleList; typedef cItemCallback cEntityCallback; @@ -182,7 +183,9 @@ public: void BroadcastEntLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastEntHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, const cClientHandle * a_Exclude = NULL); - void BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); + void BroadcastMetadata (const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL); void PositionToWorldPosition(int a_ChunkX, int a_ChunkY, int a_ChunkZ, int & a_X, int & a_Y, int & a_Z); Vector3i PositionToWorldPosition( const Vector3i & a_InChunkPos ) { return PositionToWorldPosition( a_InChunkPos.x, a_InChunkPos.y, a_InChunkPos.z ); } diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp index cbfbe1cf9..c6220bf76 100644 --- a/source/cChunkMap.cpp +++ b/source/cChunkMap.cpp @@ -402,6 +402,39 @@ void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHa +void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkY(), a_Entity.GetChunkZ()); + if (Chunk == NULL) + { + return; + } + // It's perfectly legal to broadcast packets even to invalid chunks! + Chunk->BroadcastEntityStatus(a_Entity, a_Status, a_Exclude); +} + + + + + + +void cChunkMap::BroadcastMetadata(const cPawn & a_Pawn, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(a_Pawn.GetChunkX(), a_Pawn.GetChunkY(), a_Pawn.GetChunkZ()); + if (Chunk == NULL) + { + return; + } + // It's perfectly legal to broadcast packets even to invalid chunks! + Chunk->BroadcastMetadata(a_Pawn, a_Exclude); +} + + + + + void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { // a_Player rclked block entity at the coords specified, handle it diff --git a/source/cChunkMap.h b/source/cChunkMap.h index fc595c906..69867cd2f 100644 --- a/source/cChunkMap.h +++ b/source/cChunkMap.h @@ -20,6 +20,7 @@ class cPacket; class cPlayer; class cChestEntity; class cFurnaceEntity; +class cPawn; typedef std::list cClientHandleList; typedef cChunk * cChunkPtr; @@ -70,6 +71,10 @@ public: void BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); + + void BroadcastMetadata(const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL); + /// a_Player rclked block entity at the coords specified, handle it void UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z); diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index a73e1f447..ed4d13a61 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -41,6 +41,7 @@ #include "packets/cPacket_13.h" #include "packets/cPacket_ArmAnim.h" +#include "packets/cPacket_BlockAction.h" #include "packets/cPacket_BlockChange.h" #include "packets/cPacket_BlockDig.h" #include "packets/cPacket_BlockPlace.h" @@ -50,8 +51,10 @@ #include "packets/cPacket_Disconnect.h" #include "packets/cPacket_EntityEquipment.h" #include "packets/cPacket_EntityLook.h" +#include "packets/cPacket_EntityStatus.h" #include "packets/cPacket_Flying.h" #include "packets/cPacket_Handshake.h" +#include "packets/cPacket_InventoryProgressBar.h" #include "packets/cPacket_InventorySlot.h" #include "packets/cPacket_ItemSwitch.h" #include "packets/cPacket_KeepAlive.h" @@ -1779,6 +1782,42 @@ void cClientHandle::SendPlayerMoveLook(void) +void cClientHandle::SendEntityStatus(const cEntity & a_Entity, char a_Status) +{ + cPacket_EntityStatus es; + es.m_Status = a_Status; + es.m_UniqueID = a_Entity.GetUniqueID(); + Send(es); +} + + + + + +void cClientHandle::SendMetadata(const cPawn & a_Pawn) +{ + cPacket_Metadata md(a_Pawn.GetMetaData(), a_Pawn.GetUniqueID()); + Send(md); +} + + + + + +void cClientHandle::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value) +{ + cPacket_InventoryProgressBar Progress; + Progress.m_WindowID = a_WindowID; + Progress.m_ProgressBar = a_ProgressBar; + Progress.m_Value = a_Value; + Progress.m_WindowID = a_WindowID; + Send(Progress); +} + + + + + void cClientHandle::CheckIfWorldDownloaded(void) { if (m_State != csDownloadingWorld) diff --git a/source/cClientHandle.h b/source/cClientHandle.h index ff0599675..bc644227f 100644 --- a/source/cClientHandle.h +++ b/source/cClientHandle.h @@ -32,6 +32,7 @@ class cPlayer; class cRedstone; class cInventory; class cWindow; +class cPawn; @@ -103,6 +104,9 @@ public: void SendGameMode(char a_GameMode); void SendDestroyEntity(const cEntity & a_Entity); void SendPlayerMoveLook(void); + void SendEntityStatus(const cEntity & a_Entity, char a_Status); + void SendMetadata(const cPawn & a_Entity); + void SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value); const AString & GetUsername(void) const; //tolua_export diff --git a/source/cEntity.cpp b/source/cEntity.cpp index 3e0ed7190..a906737cf 100644 --- a/source/cEntity.cpp +++ b/source/cEntity.cpp @@ -11,8 +11,6 @@ #include "cReferenceManager.h" #include "cClientHandle.h" -#include "packets/cPacket_DestroyEntity.h" - @@ -115,11 +113,7 @@ void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk) { return; } - if (m_Destroy == NULL) - { - m_Destroy = new cPacket_DestroyEntity(m_Entity); - } - a_Client->Send(*m_Destroy); + a_Client->SendDestroyEntity(*m_Entity); } virtual void Added(cClientHandle * a_Client) override @@ -134,14 +128,12 @@ void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk) } } - cPacket * m_Destroy; cPacket * m_Spawn; bool m_IgnoreOldChunk; cEntity * m_Entity; public: cMover(cEntity * a_Entity, bool a_IgnoreOldChunk) : - m_Destroy(NULL), m_Spawn(NULL), m_IgnoreOldChunk(a_IgnoreOldChunk), m_Entity(a_Entity) @@ -150,7 +142,6 @@ void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk) ~cMover() { delete m_Spawn; - delete m_Destroy; } } Mover(this, a_bIgnoreOldChunk); @@ -177,7 +168,7 @@ void cEntity::Destroy() RemoveFromChunk(); } - m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, cPacket_DestroyEntity(this)); + m_World->BroadcastDestroyEntity(*this); m_bDestroyed = true; diff --git a/source/cEntity.h b/source/cEntity.h index d5614eb84..ed32cdf4b 100644 --- a/source/cEntity.h +++ b/source/cEntity.h @@ -48,25 +48,37 @@ class cPacket; - -class cEntity //tolua_export -{ //tolua_export -public: //tolua_export - cEntity(const double & a_X, const double & a_Y, const double & a_Z); //tolua_export - virtual ~cEntity(); //tolua_export - - virtual void Initialize( cWorld* a_World ); //tolua_export - - enum eEntityType //tolua_export - { //tolua_export - eEntityType_Entity, //tolua_export - eEntityType_Player, //tolua_export - eEntityType_Pickup //tolua_export - }; //tolua_export - - virtual unsigned int GetEntityType() { return m_EntityType; } //tolua_export - virtual bool IsA( const char* a_EntityType ); //tolua_export - virtual const char* GetClass(); //tolua_export +// tolua_begin +class cEntity +{ +public: + enum + { + ENTITY_STATUS_HURT = 2, + ENTITY_STATUS_DEAD = 3, + ENTITY_STATUS_WOLF_TAMING = 6, + ENTITY_STATUS_WOLF_TAMED = 7, + ENTITY_STATUS_WOLF_SHAKING = 8, + ENTITY_STATUS_EATING_ACCEPTED = 9, + ENTITY_STATUS_SHEEP_EATING = 10, + } ; + + cEntity(const double & a_X, const double & a_Y, const double & a_Z); + virtual ~cEntity(); + + virtual void Initialize( cWorld* a_World ); + + enum eEntityType + { + eEntityType_Entity, + eEntityType_Player, + eEntityType_Pickup + }; + + virtual unsigned int GetEntityType() { return m_EntityType; } + virtual bool IsA( const char* a_EntityType ); + virtual const char* GetClass(); + // tolua_end cWorld * GetWorld(void) const { return m_World; } //tolua_export diff --git a/source/cFurnaceEntity.cpp b/source/cFurnaceEntity.cpp index 2373b3555..4b3c1d04e 100644 --- a/source/cFurnaceEntity.cpp +++ b/source/cFurnaceEntity.cpp @@ -12,9 +12,6 @@ #include "cServer.h" #include "cPickup.h" #include "cRoot.h" - -#include "packets/cPacket_InventoryProgressBar.h" - #include @@ -146,13 +143,10 @@ bool cFurnaceEntity::Tick( float a_Dt ) cWindow * Window = GetWindow(); if (Window != NULL) { - cPacket_InventoryProgressBar Progress; - Progress.m_ProgressBar = 0; - Progress.m_WindowID = (char)Window->GetWindowID(); - Progress.m_Value = (short)( m_TimeCooked * (180.f / m_CookTime) ); - if (Progress.m_Value > 180) Progress.m_Value = 180; - if (Progress.m_Value < 0) Progress.m_Value = 0; - Window->Broadcast(Progress); + short Value = (short)( m_TimeCooked * (180.f / m_CookTime)); + if (Value > 180) Value = 180; + if (Value < 0) Value = 0; + Window->BroadcastInventoryProgress(0, Value); } } } @@ -171,21 +165,14 @@ bool cFurnaceEntity::Tick( float a_Dt ) } if (Window != NULL) { - cPacket_InventoryProgressBar Progress; - Progress.m_WindowID = (char)Window->GetWindowID(); - Progress.m_ProgressBar = 1; - + short Value = 0; if (m_BurnTime > 0.f) { - Progress.m_Value = 250 - (short)( m_TimeBurned * (250.f / m_BurnTime) ); - if (Progress.m_Value > 250) Progress.m_Value = 250; - if (Progress.m_Value < 0) Progress.m_Value = 0; - } - else - { - Progress.m_Value = 0; + Value = 250 - (short)( m_TimeBurned * (250.f / m_BurnTime)); + if (Value > 250) Value = 250; + if (Value < 0) Value = 0; } - Window->Broadcast(Progress); + Window->BroadcastInventoryProgress(1, Value); } return ((m_CookingItem != NULL) || (m_TimeBurned < m_BurnTime)) && (m_BurnTime > 0.0); // Keep on ticking, if there's more to cook, or if it's cooking } diff --git a/source/cPawn.cpp b/source/cPawn.cpp index 5b2b475c0..d8a9d03be 100644 --- a/source/cPawn.cpp +++ b/source/cPawn.cpp @@ -9,13 +9,8 @@ #include "cPluginManager.h" #include "Vector3d.h" #include "BlockID.h" - #include "Defines.h" -#include "packets/cPacket_TeleportEntity.h" -#include "packets/cPacket_EntityStatus.h" -#include "packets/cPacket_Metadata.h" - @@ -62,27 +57,34 @@ void cPawn::Heal( int a_Health ) -void cPawn::TakeDamage( int a_Damage, cEntity* a_Instigator ) +void cPawn::TakeDamage(int a_Damage, cEntity * a_Instigator) { TakeDamageInfo TDI; TDI.Damage = a_Damage; TDI.Instigator = a_Instigator; - cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_TAKE_DAMAGE, 2, this, &TDI ); + cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_TAKE_DAMAGE, 2, this, &TDI); - if( TDI.Damage == 0 ) return; - if( m_Health <= 0 ) return; // Can't take damage if already dead + if (TDI.Damage == 0) + { + return; + } + if (m_Health <= 0) + { + // Can't take damage if already dead + return; + } m_Health -= (short)TDI.Damage; - if( m_Health < 0 ) m_Health = 0; + if (m_Health < 0) + { + m_Health = 0; + } - cPacket_EntityStatus Status; - Status.m_UniqueID = GetUniqueID(); - Status.m_Status = cPacket_EntityStatus::STATUS_TAKEDAMAGE; - m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, Status); + m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); if (m_Health <= 0) { - KilledBy( TDI.Instigator ); + KilledBy(TDI.Instigator); } } @@ -90,7 +92,7 @@ void cPawn::TakeDamage( int a_Damage, cEntity* a_Instigator ) -void cPawn::KilledBy( cEntity* a_Killer ) +void cPawn::KilledBy(cEntity * a_Killer) { m_Health = 0; @@ -99,19 +101,16 @@ void cPawn::KilledBy( cEntity* a_Killer ) return; // Give plugins a chance to 'unkill' the pawn. } - cPacket_EntityStatus Status; - Status.m_UniqueID = GetUniqueID(); - Status.m_Status = cPacket_EntityStatus::STATUS_DIE; - m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, Status); + m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_DEAD); } -void cPawn::TeleportToEntity( cEntity* a_Entity ) +void cPawn::TeleportToEntity(cEntity * a_Entity) { - TeleportTo( a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ() ); + TeleportTo(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ()); } @@ -148,8 +147,7 @@ void cPawn::SetMetaData(MetaData a_MetaData) { //Broadcast new status to clients in the chunk m_MetaData = a_MetaData; - cPacket_Metadata md(a_MetaData, GetUniqueID()); - m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, md); + m_World->BroadcastMetadata(*this); } diff --git a/source/cPawn.h b/source/cPawn.h index 0fcff0996..3b1a566f5 100644 --- a/source/cPawn.h +++ b/source/cPawn.h @@ -38,7 +38,7 @@ public: enum MetaData {NORMAL, BURNING, CROUCHED, RIDING, SPRINTING, EATING, BLOCKING}; virtual void SetMetaData(MetaData a_MetaData); - virtual MetaData GetMetaData() { return m_MetaData; } + virtual MetaData GetMetaData(void) const { return m_MetaData; } virtual void InStateBurning(float a_Dt); diff --git a/source/cWindow.cpp b/source/cWindow.cpp index 2c4534742..5278122d5 100644 --- a/source/cWindow.cpp +++ b/source/cWindow.cpp @@ -360,12 +360,12 @@ void cWindow::BroadcastWholeWindow(void) -void cWindow::Broadcast(const cPacket & a_Packet) +void cWindow::BroadcastInventoryProgress(short a_Progressbar, short a_Value) { cCSLock Lock(m_CS); for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr) { - (*itr)->GetClientHandle()->Send(a_Packet); + (*itr)->GetClientHandle()->SendInventoryProgress(m_WindowID, a_Progressbar, a_Value); } // for itr - m_OpenedBy[] } diff --git a/source/cWindow.h b/source/cWindow.h index 37ac5239d..36fc60f62 100644 --- a/source/cWindow.h +++ b/source/cWindow.h @@ -14,7 +14,6 @@ class cPlayer; class cItem; class cWindowOwner; class cClientHandle; -class cPacket; // TODO: remove this typedef std::list cPlayerList; @@ -76,7 +75,7 @@ public: void SendWholeWindow(cClientHandle * a_Client); void BroadcastWholeWindow(void); - void Broadcast(const cPacket & a_Packet); + void BroadcastInventoryProgress(short a_Progressbar, short a_Value); const AString & GetWindowTitle() const { return m_WindowTitle; } void SetWindowTitle( const std::string & a_WindowTitle ) { m_WindowTitle = a_WindowTitle; } diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 27db76491..a981a24c0 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -1372,6 +1372,24 @@ void cWorld::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandl +void cWorld::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastEntityStatus(a_Entity, a_Status, a_Exclude); +} + + + + + +void cWorld::BroadcastMetadata(const cPawn & a_Pawn, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastMetadata(a_Pawn, a_Exclude); +} + + + + + void cWorld::MarkChunkDirty (int a_ChunkX, int a_ChunkY, int a_ChunkZ) { m_ChunkMap->MarkChunkDirty (a_ChunkX, a_ChunkY, a_ChunkZ); diff --git a/source/cWorld.h b/source/cWorld.h index 103dd1b65..5c2132050 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -88,6 +88,8 @@ public: void BroadcastEntHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, const cClientHandle * a_Exclude = NULL); void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); + void BroadcastMetadata (const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL); void MarkChunkDirty (int a_ChunkX, int a_ChunkY, int a_ChunkZ); void MarkChunkSaving(int a_ChunkX, int a_ChunkY, int a_ChunkZ); diff --git a/source/packets/cPacket_InventoryProgressBar.h b/source/packets/cPacket_InventoryProgressBar.h index 0aa2fd3a8..b78205efa 100644 --- a/source/packets/cPacket_InventoryProgressBar.h +++ b/source/packets/cPacket_InventoryProgressBar.h @@ -14,16 +14,17 @@ public: : m_WindowID( 0 ) , m_ProgressBar( 0 ) , m_Value( 0 ) - { m_PacketID = E_INVENTORY_PROGRESS; } - virtual cPacket* Clone() const { return new cPacket_InventoryProgressBar(*this); } + { + m_PacketID = E_INVENTORY_PROGRESS; + } + + virtual cPacket * Clone() const { return new cPacket_InventoryProgressBar(*this); } virtual void Serialize(AString & a_Data) const override; - char m_WindowID; + char m_WindowID; short m_ProgressBar; short m_Value; - - static const unsigned int c_Size = 1 + 1 + 2 + 2; }; -- cgit v1.2.3