Pause for half a second
#1
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
Reply
Thanks given by:
#2
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.
Reply
Thanks given by:
#3
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.
Reply
Thanks given by:
#4
Make it a pull request, so that we can comment on it.
Reply
Thanks given by:
#5
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).
Reply
Thanks given by:
#6
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 (&).
Reply
Thanks given by:




Users browsing this thread: 3 Guest(s)