Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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 1462 times)
0 Members and 1 Guest are viewing this topic.
Offline Levendis

Junior Newbie




Java games rock!


« Posted 2003-01-11 03: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 07: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
Online princec

JGO Kernel


Medals: 362
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


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

I'm keeping me mouth shut this time :x

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Member




Friendly fire isn't friendly!


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

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

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Online princec

JGO Kernel


Medals: 362
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2003-01-11 18: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 21: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.

 

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

The first screenshot will be displayed as a thumbnail.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!