Results 1 to 1 of 1
- 08-18-2011, 03:36 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
Framerate calcuration using SWT timerExec
In the following code, I called
display.timerExec(MILLISEC_WAIT , this);
at regular interval.
---
The result is like this.
MILLISEC_WAIT = 10 -> fps ~ 63
MILLISEC_WAIT = 20 -> fps ~ 32
MILLISEC_WAIT = 50 -> fps ~ 16
MILLISEC_WAIT = 100 -> fps ~ 9
---
I expected that fps is approximately equal to [1000/MILLSEC_WAIT].
But the result is much worse than that. (especially MILLSEC_WAIT = 10, 20, 50)
It seems timerExec was not called at exact interval that I specified.
Could somebody tell me why this happens?
Regards,
Java Code:public class SWTExample { static final int MILLISEC_WAIT = 100; static int fps; static long lastFPS; static Shell shell; public static void main(String[] args){ final Display display = new Display(); shell = new Shell(display); shell.open(); lastFPS = System.currentTimeMillis(); display.asyncExec(new Runnable(){ @Override public void run() { if(!shell.isDisposed()){ // I would like to use OpenGL rendering here... updateFps(); display.timerExec(MILLISEC_WAIT, this); } } }); while(!shell.isDisposed()){ if(!display.readAndDispatch()){ display.sleep(); } } display.dispose(); } private static void updateFps(){ if(System.currentTimeMillis() - lastFPS > 1000){ shell.setText("FPS: "+fps); fps = 0; lastFPS += 1000; } fps++; } }
Similar Threads
-
JMF : Unable to handle format: MJPG, 320x240, FrameRate=15.0, Length=33792 0
By Hayzam in forum Advanced JavaReplies: 0Last Post: 05-12-2008, 11:41 PM
Bookmarks