Added Sys timer support
This commit is contained in:
parent
fa979f0f20
commit
0b4f524ff9
|
@ -118,10 +118,12 @@ public final class Game {
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
|
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
|
||||||
finished = true;*/
|
finished = true;*/
|
||||||
Keyboard.read();
|
Keyboard.read();
|
||||||
if (Keyboard.getNumKeyboardEvents() > 0) {
|
for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
|
||||||
Keyboard.next();
|
Keyboard.next();
|
||||||
if (Keyboard.key == Keyboard.KEY_ESCAPE && Keyboard.state)
|
if (Keyboard.key == Keyboard.KEY_ESCAPE && Keyboard.state)
|
||||||
finished = true;
|
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.create();
|
||||||
Keyboard.enableBuffer();
|
Keyboard.enableBuffer();
|
||||||
Mouse.create();
|
Mouse.create();
|
||||||
|
Sys.setTime(0);
|
||||||
|
System.out.println("Timer resolution: " + Sys.getTimerResolution());
|
||||||
// Go into orthographic projection mode.
|
// Go into orthographic projection mode.
|
||||||
gl.matrixMode(GL.PROJECTION);
|
gl.matrixMode(GL.PROJECTION);
|
||||||
gl.loadIdentity();
|
gl.loadIdentity();
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
#include "org_lwjgl_Sys.h"
|
#include "org_lwjgl_Sys.h"
|
||||||
|
|
||||||
long int hires_timer_freq; // Hires timer frequency
|
long int hires_timer_freq; // Hires timer frequency
|
||||||
|
@ -78,6 +79,20 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
|
||||||
return hires_timer_freq;
|
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
|
* Class: org_lwjgl_Sys
|
||||||
* Method: getTime
|
* Method: getTime
|
||||||
|
@ -86,7 +101,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
|
||||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime
|
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
// QueryPerformanceCounter((LARGE_INTEGER*) &hires_timer);
|
hires_timer = queryTime();
|
||||||
hires_timer -= hires_timer_start;
|
hires_timer -= hires_timer_start;
|
||||||
return hires_timer;
|
return hires_timer;
|
||||||
}
|
}
|
||||||
|
@ -99,8 +114,9 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime
|
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime
|
||||||
(JNIEnv * env, jclass clazz, jlong startTime)
|
(JNIEnv * env, jclass clazz, jlong startTime)
|
||||||
{
|
{
|
||||||
/* QueryPerformanceFrequency((LARGE_INTEGER*) &hires_timer_freq);
|
hires_timer_start = queryTime();
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*) &hires_timer_start);*/
|
// We don't have a real resolution so assume highest possible
|
||||||
|
hires_timer_freq = 1000000;
|
||||||
hires_timer_start -= startTime;
|
hires_timer_start -= startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue