From 9812c38ae2c4b1e0bb9f333d3459418fb5d78e7b Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Mon, 7 Nov 2011 19:15:27 +0000 Subject: More updates to cPiston.cpp. Piston action will now only be broadcasted to players who have the chunk with the moving piston loaded. git-svn-id: http://mc-server.googlecode.com/svn/trunk@73 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPiston.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/cPiston.cpp b/source/cPiston.cpp index 16df55089..8d05be87f 100644 --- a/source/cPiston.cpp +++ b/source/cPiston.cpp @@ -4,6 +4,7 @@ #include "cBlockToPickup.h" #include "cItem.h" #include "cRoot.h" +#include "cClientHandle.h" #include "cWorld.h" #include "BlockID.h" #include "packets/cPacket_BlockAction.h" @@ -14,6 +15,7 @@ extern bool g_BlockPistonBreakable[]; #define AddDir( x, y, z, dir, amount ) switch(dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\ case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\ case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; } +#define FAST_FLOOR( x ) ( (x) < 0 ? ((int)x)-1 : ((int)x) ) cPiston::cPiston( cWorld* a_World ) :m_World ( a_World ) @@ -71,7 +73,8 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) { Action.m_PosZ = (int)pistz; Action.m_Byte1 = 0; Action.m_Byte2 = pistonMeta; - cRoot::Get()->GetServer()->Broadcast( Action ); + cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) ); + Chunk->Broadcast( Action ); m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 8 ); int extx = pistx; @@ -94,7 +97,8 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) { Action.m_PosZ = (int)pistz; Action.m_Byte1 = 1; Action.m_Byte1 = pistonMeta & ~(8); - cRoot::Get()->GetServer()->Broadcast( Action ); + cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) ); + Chunk->Broadcast( Action ); m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8) ); AddDir( pistx, pisty, pistz, pistonMeta & 7, 1 ) -- cgit v1.2.3