From 4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 13 Feb 2012 21:47:03 +0000 Subject: Rewritten most of the code for multithreading; still not 100%, but getting there. If this commit proves to be too problematic, we can always undo it. git-svn-id: http://mc-server.googlecode.com/svn/trunk@251 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPiston.cpp | 76 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 27 deletions(-) (limited to 'source/cPiston.cpp') diff --git a/source/cPiston.cpp b/source/cPiston.cpp index 7fb503a3a..cc6d48ca9 100644 --- a/source/cPiston.cpp +++ b/source/cPiston.cpp @@ -20,8 +20,6 @@ extern bool g_BlockPistonBreakable[]; 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) ) - @@ -49,6 +47,10 @@ unsigned short cPiston::FirstPassthroughBlock( int pistonX, int pistonY, int pis return 9001; } + + + + void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) { char pistonBlock = m_World->GetBlock( pistx, pisty, pistz ); char pistonMeta = m_World->GetBlockMeta( pistx, pisty, pistz ); @@ -87,7 +89,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) { Action.m_Byte2 = pistonMeta; - cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) ); + cChunkPtr Chunk = m_World->GetChunkOfBlock(pistx, pisty, pistz); Chunk->Broadcast( Action ); m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 8 ); @@ -109,33 +111,53 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) { } -void cPiston::RetractPiston( int pistx, int pisty, int pistz ) { + + + + +void cPiston::RetractPiston( int pistx, int pisty, int pistz ) +{ char pistonBlock = m_World->GetBlock( pistx, pisty, pistz ); char pistonMeta = m_World->GetBlockMeta( pistx, pisty, pistz ); - if (pistonMeta > 6) {// only retract if piston is not already retracted - //send blockaction packet - cPacket_BlockAction Action; - Action.m_PosX = (int)pistx; - Action.m_PosY = (short)pisty; - Action.m_PosZ = (int)pistz; - Action.m_Byte1 = 1; - Action.m_Byte2 = pistonMeta & ~(8); - 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 ) - if( m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) { - if( pistonBlock == E_BLOCK_STICKY_PISTON ) { - int tempx = pistx, tempy = pisty, tempz = pistz; - AddDir( tempx, tempy, tempz, pistonMeta&7, 1 ) - char tempblock = m_World->GetBlock( tempx, tempy, tempz ); - if(tempblock == E_BLOCK_OBSIDIAN || tempblock == E_BLOCK_BEDROCK || tempblock == E_BLOCK_PISTON_EXTENSION) {return;} - m_World->SetBlock( pistx, pisty, pistz, tempblock, m_World->GetBlockMeta( tempx, tempy, tempz ) ); - m_World->SetBlock( tempx, tempy, tempz, E_BLOCK_AIR, 0 ); - }else{ - m_World->SetBlock( pistx, pisty, pistz, E_BLOCK_AIR, 0 ); + if (pistonMeta <= 6) // only retract if piston is not already retracted + { + return; + } + + //send blockaction packet + cPacket_BlockAction Action; + Action.m_PosX = (int)pistx; + Action.m_PosY = (short)pisty; + Action.m_PosZ = (int)pistz; + Action.m_Byte1 = 1; + Action.m_Byte2 = pistonMeta & ~(8); + cChunkPtr Chunk = m_World->GetChunkOfBlock(pistx, pisty, pistz); + Chunk->Broadcast( Action ); + m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8) ); + + AddDir( pistx, pisty, pistz, pistonMeta & 7, 1 ) + if ( m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) + { + if ( pistonBlock == E_BLOCK_STICKY_PISTON ) + { + int tempx = pistx, tempy = pisty, tempz = pistz; + AddDir( tempx, tempy, tempz, pistonMeta & 7, 1 ) + char tempblock = m_World->GetBlock( tempx, tempy, tempz ); + if ( + (tempblock == E_BLOCK_OBSIDIAN) || + (tempblock == E_BLOCK_BEDROCK) || + (tempblock == E_BLOCK_PISTON_EXTENSION) + ) + { + // These cannot be moved by the sticky piston, bail out + return; } + m_World->SetBlock( pistx, pisty, pistz, tempblock, m_World->GetBlockMeta( tempx, tempy, tempz ) ); + m_World->SetBlock( tempx, tempy, tempz, E_BLOCK_AIR, 0 ); + } + else + { + m_World->SetBlock( pistx, pisty, pistz, E_BLOCK_AIR, 0 ); } } } \ No newline at end of file -- cgit v1.2.3