• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Timer and Fixed Frame Rate

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All! I'm trying to implement a game which requires blocks falling from the top of the grid, and No it's not Tetris. I imagined it would be very simple using the built in Java TimerTask, but after beginning to develop the game I'm having second thoughts. This is because at each *step* it goes through each player and moves their respective stub (blocks) down the grid until it hits the bottom, that is, the bottom of the grid or sits on top other previously fallen stubs (blocks). I would like to note that the graphics would be rigid in the sense that I am planning to have the grid represented as a 2D Matrix of JPanel/JComponent that are just color coded. So the movement of the stubs would be essentially setting the color of the previous set of blocks to white and then the next set of blocks to respective colors of the stub.

What I'm worried about is that when the stub hits the bottom of the grid, there will be some relatively heavy computation (NP complete) that could potentially decrease the throughput of the game. I am thinking about having a dispatch thread to perform the computation for the appropriate players who need the task performed.

I should also note, that the player will have the option of holding the down arrow to increase the speed of the stub to reaching the bottom.

Anyway, I think this game would be insanely fun. I'm definitely going to add a server/client model to it. Here are my questions, and I am open to suggestions

1. Is the Java TimerTask reliable for implementing a Fixed Frame Rate?

2. Should I use Fixed Frame Rate at all? or should I use Variable Frame Rate?

3. Would it ultimately be better to go the extra mile, and go from rigid motion to smoother motion?

Any help is greatly appreciated thank you.
 
Gary Drocella
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone?
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you haven't decided how your game will work yet, and you keep moving the goal post farther and farther making things harder on yourself with more work.

TimerTask's running speed depends on your CPU and the randomness of thread scheduling.

TimerTask is no more or less accurate to schedule than anything else in Java. Java isn't a real-time system so you should expect a few milliseconds of delay in either direction.
 
Walter Gabrielsen Iii
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, Swing has only 1 thread to do both GUI updates and Event handling.

You must use the Swing thread to do GUI updates, but take the heavy computations out of your Event Listeners or it can freeze the GUI.
reply
    Bookmark Topic Watch Topic
  • New Topic