Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 1257 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 »

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

Offline BettyJoNabisco

Junior Newbie





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

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
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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (59 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!