From: Elias N. <eli...@us...> - 2002-11-16 19:46:21
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/linux In directory usw-pr-cvs1:/tmp/cvs-serv29246 Modified Files: Game.java org_lwjgl_Sys.c Log Message: Added Sys timer support Index: Game.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/Game.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/Game.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Game.java 15 Nov 2002 11:10:32 -0000 1.2 +++ Game.java 16 Nov 2002 19:46:18 -0000 1.3 @@ -118,10 +118,12 @@ if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) finished = true;*/ Keyboard.read(); - if (Keyboard.getNumKeyboardEvents() > 0) { + for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) { Keyboard.next(); if (Keyboard.key == Keyboard.KEY_ESCAPE && Keyboard.state) finished = true; + if (Keyboard.key == Keyboard.KEY_T && Keyboard.state) + System.out.println("Current time: " + Sys.getTime()); } } @@ -149,6 +151,8 @@ Keyboard.create(); Keyboard.enableBuffer(); Mouse.create(); + Sys.setTime(0); + System.out.println("Timer resolution: " + Sys.getTimerResolution()); // Go into orthographic projection mode. gl.matrixMode(GL.PROJECTION); gl.loadIdentity(); Index: org_lwjgl_Sys.c CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/org_lwjgl_Sys.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/org_lwjgl_Sys.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- org_lwjgl_Sys.c 15 Nov 2002 11:10:32 -0000 1.2 +++ org_lwjgl_Sys.c 16 Nov 2002 19:46:18 -0000 1.3 @@ -39,6 +39,7 @@ * @version $Revision$ */ +#include <sys/time.h> #include "org_lwjgl_Sys.h" long int hires_timer_freq; // Hires timer frequency @@ -78,6 +79,20 @@ return hires_timer_freq; } +long queryTime(void) { + struct timeval tv; + if (gettimeofday(&tv, NULL) == -1) { +#ifdef _DEBUG + printf("Could not read current time\n"); +#endif + } + long result = tv.tv_sec * 1000000l + tv.tv_usec; +#ifdef _DEBUG + printf("Current time (native): %ld\n", result); +#endif + return result; +} + /* * Class: org_lwjgl_Sys * Method: getTime @@ -86,7 +101,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime (JNIEnv * env, jclass clazz) { -// QueryPerformanceCounter((LARGE_INTEGER*) &hires_timer); + hires_timer = queryTime(); hires_timer -= hires_timer_start; return hires_timer; } @@ -99,8 +114,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime (JNIEnv * env, jclass clazz, jlong startTime) { -/* QueryPerformanceFrequency((LARGE_INTEGER*) &hires_timer_freq); - QueryPerformanceCounter((LARGE_INTEGER*) &hires_timer_start);*/ + hires_timer_start = queryTime(); + // We don't have a real resolution so assume highest possible + hires_timer_freq = 1000000; hires_timer_start -= startTime; } |