From 9ec248eaa09a6e575a6bd5f79028dda3ef982bdf Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 16:34:26 +0100 Subject: Fixes #57 --- source/Piston.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'source/Piston.cpp') diff --git a/source/Piston.cpp b/source/Piston.cpp index d179d70b6..f5aaabf00 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); } } -- cgit v1.2.3 From 2b0541ab39e47dafcd7fdc66fa49a955ef7f8719 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 16:42:02 +0100 Subject: Attempt at fixing sleep issue --- source/Piston.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/Piston.cpp') diff --git a/source/Piston.cpp b/source/Piston.cpp index f5aaabf00..43c3441fb 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); -- cgit v1.2.3 From a322bb275f35a97e917acc8d29f9a3eb4695ae8f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 16:47:44 +0100 Subject: Attempt two --- source/Piston.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/Piston.cpp') diff --git a/source/Piston.cpp b/source/Piston.cpp index 43c3441fb..569ef02e3 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); -- cgit v1.2.3 From dd6450c2a9a521a30873a933f847f93a0704ac3d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 17:41:50 +0100 Subject: Attempt three This is extremely embarrassing... --- source/Piston.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'source/Piston.cpp') diff --git a/source/Piston.cpp b/source/Piston.cpp index 569ef02e3..0d436924c 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); -- cgit v1.2.3 From 27b400adf8457d2bed2b492ef01f9e6f68463a9d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 17:44:01 +0100 Subject: Credits --- source/Piston.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source/Piston.cpp') diff --git a/source/Piston.cpp b/source/Piston.cpp index 0d436924c..0ebebfc9b 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); -- cgit v1.2.3 From 020ff36af2c9f19527483af041a81e822b479e91 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 13 Aug 2013 17:45:40 +0100 Subject: YET ANOTHER ERROR >:( --- source/Piston.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/Piston.cpp') diff --git a/source/Piston.cpp b/source/Piston.cpp index 0ebebfc9b..161f2b38c 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); -- cgit v1.2.3