From: Gregory P. <gre...@us...> - 2003-01-02 18:19:33
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/macosx In directory sc8-pr-cvs1:/tmp/cvs-serv11992/src/native/macosx Modified Files: org_lwjgl_Sys.cpp Log Message: Added in timer support Index: org_lwjgl_Sys.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Sys.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Sys.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- org_lwjgl_Sys.cpp 30 Dec 2002 07:09:35 -0000 1.2 +++ org_lwjgl_Sys.cpp 2 Jan 2003 18:19:30 -0000 1.3 @@ -39,8 +39,14 @@ * @version $Revision$ */ +#include <sys/time.h> #include "org_lwjgl_Sys.h" + +long int hires_timer_freq; // Hires timer frequency +long int hires_timer_start; // Hires timer start +long int hires_timer; // Hires timer current time + /* * Class: org_lwjgl_Sys * Method: getDirectBufferAddress @@ -71,7 +77,22 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution (JNIEnv * env, jclass clazz) { - return 0L; + 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; + + return result; } /* @@ -82,7 +103,9 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime (JNIEnv * env, jclass clazz) { - return 0L; + hires_timer = queryTime(); + hires_timer -= hires_timer_start; + return hires_timer; } /* @@ -93,6 +116,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime (JNIEnv * env, jclass clazz, jlong startTime) { + hires_timer_start = queryTime(); + // We don't have a real resolution so assume highest possible + hires_timer_freq = 1000000; + hires_timer_start -= startTime; } /* @@ -103,4 +130,20 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority (JNIEnv * env, jclass clazz, jint priority) { +} + +/* + * Class: org_lwjgl_Sys + * Method: alert + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert(JNIEnv * env, jclass clazz, jstring title, jstring message) +{ + jboolean copy = JNI_FALSE; + const char * eMessageText = env->GetStringUTFChars(message, ©); + const char * cTitleBarText = env->GetStringUTFChars(title, ©); + printf("*** Alert ***\n%s\n%s\n", cTitleBarText, eMessageText); + + env->ReleaseStringUTFChars(message, eMessageText); + env->ReleaseStringUTFChars(title, cTitleBarText); } |