From f5b9f5f41c70966d13200ac7e1474064a3f2bc45 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 15:44:10 +0100 Subject: [PATCH 1/8] Removed comments --- source/Blocks/BlockTorch.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/source/Blocks/BlockTorch.h b/source/Blocks/BlockTorch.h index f774e15a..99c1a7b7 100644 --- a/source/Blocks/BlockTorch.h +++ b/source/Blocks/BlockTorch.h @@ -109,17 +109,10 @@ public: static bool CanBePlacedOn(BLOCKTYPE a_BlockType, char a_Direction) { - //case E_BLOCK_GLASS: - //case E_BLOCK_FENCE: - //case E_BLOCK_NETHER_BRICK_FENCE: - //case E_BLOCK_PISTON: - //case E_BLOCK_IRON_BARS if ( g_BlockIsSolid[a_BlockType] ) { return (a_Direction == 0x1); // allow only direction "standing on floor" } else { - //default: - //{ return g_BlockIsSolid[a_BlockType]; } } From 9ec248eaa09a6e575a6bd5f79028dda3ef982bdf Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 16:34:26 +0100 Subject: [PATCH 2/8] Fixes #57 --- source/Piston.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/source/Piston.cpp b/source/Piston.cpp index d179d70b..f5aaabf0 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -122,6 +122,14 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) AddDir(extx, exty, extz, pistonMeta & 7, 1) + #ifdef _WIN32 // Pause for 0.1 seconds to allow client animation to run + #include + Sleep(100); + #else + #include + usleep(100 * 1000); // takes microseconds + #endif + m_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta & 7); } @@ -142,7 +150,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) m_World->BroadcastBlockAction(pistx, pisty, pistz, 1, pistonMeta & ~(8), E_BLOCK_PISTON); m_World->BroadcastSoundEffect("tile.piston.in", pistx * 8, pisty * 8, pistz * 8, 0.5f, 0.7f); 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) { @@ -166,11 +174,27 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) // These cannot be moved by the sticky piston, bail out return; } + #ifdef _WIN32 + #include + Sleep(100); + #else + #include + usleep(100 * 1000); // takes microseconds + #endif + m_World->SetBlock(pistx, pisty, pistz, tempblock, tempmeta); m_World->SetBlock(tempx, tempy, tempz, E_BLOCK_AIR, 0); } else { + #ifdef _WIN32 + #include + Sleep(100); + #else + #include + usleep(100 * 1000); // takes microseconds + #endif + m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); } } From 23a5fb14503cadfe7f51987c6b3be76390311764 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 16:36:19 +0100 Subject: [PATCH 3/8] Removed more comments --- source/Blocks/BlockTorch.h | 1 - 1 file changed, 1 deletion(-) diff --git a/source/Blocks/BlockTorch.h b/source/Blocks/BlockTorch.h index 99c1a7b7..3a50cab7 100644 --- a/source/Blocks/BlockTorch.h +++ b/source/Blocks/BlockTorch.h @@ -103,7 +103,6 @@ public: virtual bool DoesAllowBlockOnTop(void) override { return true; - //was false } From 2b0541ab39e47dafcd7fdc66fa49a955ef7f8719 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 16:42:02 +0100 Subject: [PATCH 4/8] Attempt at fixing sleep issue --- source/Piston.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Piston.cpp b/source/Piston.cpp index f5aaabf0..43c3441f 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -127,7 +127,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) Sleep(100); #else #include - usleep(100 * 1000); // takes microseconds + usleep(0.1); #endif m_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta & 7); @@ -179,7 +179,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) Sleep(100); #else #include - usleep(100 * 1000); // takes microseconds + usleep(0.1); #endif m_World->SetBlock(pistx, pisty, pistz, tempblock, tempmeta); @@ -192,7 +192,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) Sleep(100); #else #include - usleep(100 * 1000); // takes microseconds + usleep(0.1); #endif m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); From a322bb275f35a97e917acc8d29f9a3eb4695ae8f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 16:47:44 +0100 Subject: [PATCH 5/8] Attempt two --- source/Piston.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Piston.cpp b/source/Piston.cpp index 43c3441f..569ef02e 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -127,7 +127,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) Sleep(100); #else #include - usleep(0.1); + sleep(0.1); #endif m_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta & 7); @@ -179,7 +179,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) Sleep(100); #else #include - usleep(0.1); + sleep(0.1); #endif m_World->SetBlock(pistx, pisty, pistz, tempblock, tempmeta); @@ -192,7 +192,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) Sleep(100); #else #include - usleep(0.1); + sleep(0.1); #endif m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); From dd6450c2a9a521a30873a933f847f93a0704ac3d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 17:41:50 +0100 Subject: [PATCH 6/8] Attempt three This is extremely embarrassing... --- source/Piston.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/source/Piston.cpp b/source/Piston.cpp index 569ef02e..0d436924 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -12,7 +12,11 @@ #include "Server.h" #include "Blocks/BlockHandler.h" - +#ifdef _WIN32 +#include +#else +#include +#endif @@ -122,12 +126,10 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) AddDir(extx, exty, extz, pistonMeta & 7, 1) - #ifdef _WIN32 // Pause for 0.1 seconds to allow client animation to run - #include - Sleep(100); + #ifdef __WIN32__ + Sleep(100); #else - #include - sleep(0.1); + usleep(static_cast(100)*1000); //or use nanosleep on platforms where it's needed #endif m_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta & 7); @@ -174,12 +176,10 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) // These cannot be moved by the sticky piston, bail out return; } - #ifdef _WIN32 - #include - Sleep(100); + #ifdef __WIN32__ + Sleep(100); #else - #include - sleep(0.1); + usleep(static_cast(100)*1000); //or use nanosleep on platforms where it's needed #endif m_World->SetBlock(pistx, pisty, pistz, tempblock, tempmeta); @@ -187,12 +187,10 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) } else { - #ifdef _WIN32 - #include - Sleep(100); + #ifdef __WIN32__ + Sleep(100); #else - #include - sleep(0.1); + usleep(static_cast(100)*1000); //or use nanosleep on platforms where it's needed #endif m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); From 27b400adf8457d2bed2b492ef01f9e6f68463a9d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 17:44:01 +0100 Subject: [PATCH 7/8] Credits --- source/Piston.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/Piston.cpp b/source/Piston.cpp index 0d436924..0ebebfc9 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -19,6 +19,8 @@ #endif +//Athar from http://www.cplusplus.com/forum/unices/60161/ helped with the sleep code. + extern bool g_BlockPistonBreakable[]; @@ -129,7 +131,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) #ifdef __WIN32__ Sleep(100); #else - usleep(static_cast(100)*1000); //or use nanosleep on platforms where it's needed + usleep(static_cast(100)*1000); #endif m_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta & 7); @@ -179,7 +181,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) #ifdef __WIN32__ Sleep(100); #else - usleep(static_cast(100)*1000); //or use nanosleep on platforms where it's needed + usleep(static_cast(100)*1000); #endif m_World->SetBlock(pistx, pisty, pistz, tempblock, tempmeta); @@ -190,7 +192,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) #ifdef __WIN32__ Sleep(100); #else - usleep(static_cast(100)*1000); //or use nanosleep on platforms where it's needed + usleep(static_cast(100)*1000); #endif m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); From 020ff36af2c9f19527483af041a81e822b479e91 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 17:45:40 +0100 Subject: [PATCH 8/8] YET ANOTHER ERROR >:( --- source/Piston.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Piston.cpp b/source/Piston.cpp index 0ebebfc9..161f2b38 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -128,7 +128,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) AddDir(extx, exty, extz, pistonMeta & 7, 1) - #ifdef __WIN32__ + #ifdef _WIN32 Sleep(100); #else usleep(static_cast(100)*1000); @@ -178,7 +178,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) // These cannot be moved by the sticky piston, bail out return; } - #ifdef __WIN32__ + #ifdef _WIN32 Sleep(100); #else usleep(static_cast(100)*1000); @@ -189,7 +189,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) } else { - #ifdef __WIN32__ + #ifdef _WIN32 Sleep(100); #else usleep(static_cast(100)*1000);