Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (290)
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  
  Timing question  (Read 1272 times)
0 Members and 1 Guest are viewing this topic.
Offline Levendis

Junior Newbie




Java games rock!


« Posted 2003-01-11 04:06:09 »

I have a game that I've made using a java.util.Timer to deal with animations, performing the work of each frame in an actionPerformed method and just updating it about 30 times a second.  The result is pretty clean, but obviously all movements are based per frame as opposed to per timeslice.  I was wondering if there's anything especially wrong with this approach or if anyone had comments on tradeoffs between this and other approaches?
Also has sun fixed the high resolution timer yet?

Thanks.
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2003-01-11 08:23:52 »

Quote
I have a game that I've made using a java.util.Timer to deal with animations, performing the work of each frame in an actionPerformed method and just updating it about 30 times a second.  The result is pretty clean, but obviously all movements are based per frame as opposed to per timeslice.  I was wondering if there's anything especially wrong with this approach or if anyone had comments on tradeoffs between this and other approaches?


All depends on your needs. If the result looks ok, the approach is ok. It won't use more CPU than effectivly needed, is multithreading-friendly, lets the GC live - in this sense it even can be called 'advanced' compared to 'render-as-fast-as-you-can' things.

If time itself is an important term in you program (as it would be for a true simulation), you could measure the current time when called back by the Timer. There, again depending on your needs, the lowres clock System.currentTimeMillis() or the hires one com.sun.j3d.utils.timer.J3DTimer may be used.

At the bottom line I feel that's basically the Java way to design a gameloop.

Quote

Also has sun fixed the high resolution timer yet?


Fixed? It never has been broken (except for a short period in one beta).

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline princec
« League of Dukes »

JGO Kernel


Medals: 195
Projects: 3


Eh? Who? What? ... Me?


« Reply #2 - Posted 2003-01-11 10:49:48 »

I'm keeping me mouth shut this time :x

Cas Smiley

Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #3 - Posted 2003-01-11 16:25:20 »

... although I think Levendis could be interested in what you have to say.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline princec
« League of Dukes »

JGO Kernel


Medals: 195
Projects: 3


Eh? Who? What? ... Me?


« Reply #4 - Posted 2003-01-11 19:27:27 »

... ok then.  Grin

The other side of the coin is you do everything in a single thread - your main thread, in fact - read input, calculate, render, page flip, repeat.

This gives you the advantage of deterministic behaviour on all platforms, and actually makes your code a lot simpler to understand. It then depends on the style of game you are writing as to whether you tune for a specific framerate and use tick counting, or tune for a specific animation frequency and use hires timers. My personal recommendation is ticking for 2D and time for 3D.

If the page flip is a well behaved piece of code - like it is on my Nvidia cards for example - then other threads have their chance to run whilst the page flip occurs.

(And if you're really cunning and using OpenGL you'll also find that a lot of the drawing can happen asynchronously on the card at this point too - effectively giving you another processor to do all the pixel pushing work)

Cas Smiley

Offline Levendis

Junior Newbie




Java games rock!


« Reply #5 - Posted 2003-01-11 22:27:06 »

I appreciate the responses, thank you.  What I'm doing is 2d, and the only threads not synched with the main timer thread is the input and going to be the networking; main thread just notifies all objects to move to their next step each iteration.  Specifically one thing i've noticed with the timer method is that as characters move faster the responses are twitchy because they move a certain number of pixels per frame, conversely I've noticed on consoles in 2d games that characters sometimes appear to be skating as opposed to walking because of the timeslice based animations.
Based on what you both have said i'm going to finish this using the timer and once i'm done i'll do a 3d project with time slicing.

When I started this I did it this way because it was a method of animation that made sense to me and the entire project was for my education's sake.  In the meantime I haven't seen any other examples that used this technique so I thought that maybe there lurked some hidden evil I hadn't thought of.

Thanks again very much for your insights.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (60 views)
2013-05-17 21:29:12

alaslipknot (69 views)
2013-05-16 21:24:48

gouessej (100 views)
2013-05-16 00:53:38

gouessej (98 views)
2013-05-16 00:17:58

theagentd (107 views)
2013-05-15 15:01:13

theagentd (98 views)
2013-05-15 15:00:54

StreetDoggy (144 views)
2013-05-14 15:56:26

kutucuk (167 views)
2013-05-12 17:10:36

kutucuk (166 views)
2013-05-12 15:36:09

UnluckyDevil (175 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.078 seconds with 20 queries.