A more precise alternative to Thread.sleep()
1001190Apr 4 2013 — edited Apr 9 2013So I'm designing a multi player game (server/client). I am using Thread.sleep() in a class that is used specifically for tracking the move speed of a specific character. The problem with this is sleep() only pauses for milliseconds and is very processor dependent. I've tried making a mini spinlock (for sleeping in microseconds) and was successful with this and it was very accurate. However, it doesn't clock the same on the server as the clients. (Resulting in movement on the client being slower than movement on my server--and then chops when the server updates the sync). I believe I have thought up a way (in using the spin lock way of handling it) to have the client adjust for the difference of the sleeps when it loads a character, and I think that might work well enough. But I was curious if anyone knew a better way of doing sleep() accurately and in microseconds, or some non processor depending way of sleeping?