Timer/TimeTask/Thread.sleep(time) for specifying exact framerate

Hi all,



I was wondering whether anyone had any knowledge or experience in setting the jme scene to update at an exact time.

I am working on a project that will require an "animation" to be rendered from a data file. The data file consists of (id,x,y,z,time) data. The id refers to a simple sphere in the scene graph.



Is there any way i can read from the data file at the correct time to represent the data exactly.

I'm assuming i will create a new controller to handle the updates to the spatial objs and do so at the right time.



The max speed of updating will be 250 frames / sec with ~30 spheres and interconnecting tubes being given updated

location information in each frame. In effect we will be playing back previously recorded movement.



The data file can be modified to contain the time in relative time if needed.

Will Thread.sleep(time) throw up any issues (I'm thinking it will be always slightly out due to random thread related overheads)



If anyone can share their thoughts on this it'd be much appreciated.

Thanks.

Firstly - the reading of the file should be in a seprate worker thread - if it is not a large file can you load it all into memory at once. If it is look at RandomFileAcess. Also consider that this may not be file based later - might be stream based.



Use the GameTaskQueue or whatever you have to update the scene items.



You can use the tpf in the JME thread to notify the worker thread of the time elapsed.

Expanding on what theprism said…





Without the need to control any threads with sleep(), you could write a controller which maintains a queue of animation updates which are read from the file. In this controllers update method you will be given a Time Per Frame value, which you can sum into a variable (currentTime) in the controller. When the current time reaches the amount of time between your animation updates, you can then take the next update from your queue and apply it. There are already animation controllers written for several purposes in jME. I would suggest looking at how they operate.

Is time per frame not a weighted average or some such? That would screw it up…

no. the value 'time per frame' you get every update cycle is the exact time that expired since he last update cycle.

Use NanoTimer if you want exact time and not weighted