Cuberite Forum
Pause for half a second - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Pause for half a second (/thread-1218.html)



Pause for half a second - tigerw - 08-13-2013

In my attempts to fix the piston-not-smoothly-extending-retracting bug, I have found that the animation is only played if the server sends the Block Action packet, waits until the animation has finished client side, and then sends the extension arm block update. It goes: Piston Base update -> Anim Packet -> pause -> Piston arm update

So... I need a way to pause the extension / retraction function in C++ for around half a second without user input or locking everything up or derpy stuff like that.

How would I do it? Tried with system("pause") in Windows and it works, but requires user interaction so it's obviously not the solution.

Edit: this works, is it good practice?
Code:
#ifdef _WIN32
#include <windows.h>
Sleep(500);
#else
#include <unistd.h>
usleep(500* 1000);
#endif



RE: Pause for half a second - xoft - 08-13-2013

You cannot just pause the code. You need to implement some form of scheduling and add a task that will execute "update piston arm N ticks from now".

This is not worth doing until I finish the PerWorldThread branch, because it rewrites quite a lot of threading stuff.


RE: Pause for half a second - tigerw - 08-14-2013

Aww Sad I spent the morning figuring it out.

Okay, I will wait for you to finish. Do you think I should commit another "lazy fix" type thing in the meantime. The animations do look pretty.


RE: Pause for half a second - xoft - 08-14-2013

Make it a pull request, so that we can comment on it.


RE: Pause for half a second - tigerw - 08-14-2013

Okay. Also, how would I detect if a piston is an extended piston or retracted one?

I found this snippet:
Code:
(currMeta & 0x8 != 0x0)

...but it doesn't work - putting it as another 'or' in the pistonpushable for statement stops pistons from pushing any piston (extended or retracted).


RE: Pause for half a second - xoft - 08-14-2013

Make a function, static bool cPiston::IsMetaExtended(NIBBLETYPE a_BlockMeta), that returns true if the piston is extended when it has the specified meta. This will simplify the condition and will be re-usable.

I believe you got bitten by C++ operator precedence, the inequality operator (!=) is evaluated before the bitwise and (&).