Added Sys timer support

This commit is contained in:
Elias Naur 2002-11-16 19:46:18 +00:00
parent fa979f0f20
commit 0b4f524ff9
2 changed files with 24 additions and 4 deletions

View File

@ -118,10 +118,12 @@ public final class Game {
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 @@ public final class Game {
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();

View File

@ -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 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
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_getTimerResolution
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 jlong JNICALL Java_org_lwjgl_Sys_getTime
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;
}