Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Timers in SGS  (Read 1834 times)
0 Members and 1 Guest are viewing this topic.
Offline BettyJoNabisco

Junior Newbie

« Posted 2007-03-05 19:19:37 »

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
Offline endolf

JGO Coder

Medals: 7
Exp: 15 years

Current project release date: sometime in 3003

« Reply #1 - Posted 2007-03-06 07:41:03 »


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



Offline BettyJoNabisco

Junior Newbie

« Reply #2 - Posted 2007-03-06 14:02:45 »


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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder

Got any cats?

« Reply #3 - Posted 2007-03-11 20:09:44 »

Be aware that PDTimer goes away in the 0.9 release.

Its functions are subsumed by the built in TaskManager functionality.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Pages: [1]
  ignore  |  Print  

EgonOlsen (58 views)
2018-06-10 19:43:48

EgonOlsen (40 views)
2018-06-10 19:43:44

EgonOlsen (60 views)
2018-06-10 19:43:20

DesertCoockie (239 views)
2018-05-13 18:23:11

nelsongames (141 views)
2018-04-24 18:15:36

nelsongames (140 views)
2018-04-24 18:14:32

ivj94 (882 views)
2018-03-24 14:47:39

ivj94 (143 views)
2018-03-24 14:46:31

ivj94 (794 views)
2018-03-24 14:43:53

Solater (158 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!