Timers in SGS

SGS folks, thanks for the help on the last question. I’ve gotten pretty far in doing the server side of my project. Here’s a new one.

My requirement is for the server to assist in the implementation of a “MoveTo” command from a client. The MoveTo Command has the arguments: presentLocation, desiredLocation, estimatedTimeToMove. A colleague is doing the client side and pretty much wants it to be this way. The idea is that the client is responding to a request by a player to move to a different location. The client sends a MoveTo command, and then starts an animation wherein the player’s avatar is shown walking to the desired Location from its present Location. The server’s responsibility is to make sure that other clients in the game are notified of the MoveTo, so they can also show animations of the player’s movement. In addition, it is the server’s responsibility to update the player’s persistent location at the end of the move. The intermediate states of the player do not need to be persisted.

So, my first thought for this is to use a timer, started when the MoveTo command is received and expiring after the “estimatedTimeToMove” has expired. The action at expiry would be simply to update the Player GLO’s location to its new value. There are miscellaneous boundary cases to be considered, such as interruption of the move, , but I want to get the general idea down first.

So, my questions are:

  1. Is PDTimer the way to implement this? I’m wondering if a persistent timer is too heavyweight for what I want to do? A persistent timer does have the advantage that a server shutdown shouldn’t cause me to have to restart all timers in the event of a server reboot. Also, since the timer expiration is going to result in a modifcation of a GLO, I really do want to be in a SimTask context when the timer expires.

  2. If PDTimer is not the right way to do this, what other kinds of timers would you folks suggest? Using a non-persistent timer, would I have to manually insert some kind of event into the SGS system? That sounds ugly.

  3. Assuming PDTimer is the right way to do this, I’m wondering about the reliability of the PDTimer mechanism. The documentation is sparse, the sample server code I’ve seen by and large has references to PDTimer commented out. Is the PDTimer facility mature enough to be used in ea2?

  4. Are PDTimers one-shot or repeating expiration? I want it to be one-shot expiration.

  5. Any way to stop a PDTimer?

  6. Any sample code beyond what I see in the sample code in the ea2 distro?

I appreciate any illumination you folks can provide.

Thanks in advace…BJN

Hi

PDTimer is the way to go, it’s only got 1 second granularity (even though the methods use millis), and has issues with when it actually fires (it will fire at some point after that number of ms has finished).

If you check the Javadocs for PDTimer, the 4th parameter is whether you want it to repeat or not.

I guess (not tried it) calling removeTimerEvent on your timer would effectivly stop it. Just keep a reference to the timer event when you create it.

I use it on line 78ish here

HTH

Endolf

Endolf,

Thanks again for the advice. I had gone on to experiment with PDTimer and discovered some of the answers myself. I came to the same conclusion, that removing the TimerEvent would effectively stop the timer, and I’m keeping a reference to the TimerEvent.

The one second granularity of timers is slightly worrisome, but can be lived with for now. I guess I’ll put in my vote for better granularity of timers. Maybe milliSec accuracy is overkill, but something better than 1 sec; say 0.1 sec to 0.01 sec.

Thanks again…BJN

Be aware that PDTimer goes away in the 0.9 release.

Its functions are subsumed by the built in TaskManager functionality.