mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-14 00:54:05 +02:00
#15 add platform specific func osGetTime / osSave
This commit is contained in:
@@ -12,15 +12,17 @@
|
||||
|
||||
time_t startTime;
|
||||
|
||||
int getTime() {
|
||||
int osGetTime() {
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return int((t.tv_sec - startTime) * 1000 + t.tv_usec / 1000);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
bool osSave(const char *name, const void *data, int size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int lastTime;
|
||||
extern "C" {
|
||||
|
||||
char Stream::cacheDir[255];
|
||||
char Stream::contentDir[255];
|
||||
@@ -49,8 +51,6 @@ JNI_METHOD(void, nativeInit)(JNIEnv* env, jobject obj, jstring contentDir, jstri
|
||||
env->ReleaseStringUTFChars(cacheDir, str);
|
||||
|
||||
Game::init();
|
||||
|
||||
lastTime = getTime();
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeFree)(JNIEnv* env) {
|
||||
@@ -62,11 +62,7 @@ JNI_METHOD(void, nativeReset)(JNIEnv* env) {
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeUpdate)(JNIEnv* env) {
|
||||
int time = getTime();
|
||||
if (time == lastTime)
|
||||
return;
|
||||
Game::update((time - lastTime) * 0.001f);
|
||||
lastTime = time;
|
||||
Game::update();
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeRender)(JNIEnv* env) {
|
||||
|
@@ -19,9 +19,7 @@
|
||||
char Stream::cacheDir[255];
|
||||
char Stream::contentDir[255];
|
||||
|
||||
int lastTime;
|
||||
|
||||
int getTime() {
|
||||
int osGetTime() {
|
||||
const int64_t kOneMillion = 1000 * 1000;
|
||||
static mach_timebase_info_data_t info;
|
||||
|
||||
@@ -31,6 +29,10 @@ int getTime() {
|
||||
return (int)((mach_absolute_time() * info.numer) / (kOneMillion * info.denom));
|
||||
}
|
||||
|
||||
bool osSave(const char *name, const void *data, int size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#define SND_BUF_SIZE 8192
|
||||
|
||||
static AudioQueueRef audioQueue;
|
||||
@@ -115,8 +117,6 @@ void soundInit() {
|
||||
|
||||
soundInit();
|
||||
Input::reset();
|
||||
|
||||
lastTime = getTime() - 1;
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
@@ -139,12 +139,7 @@ void soundInit() {
|
||||
Core::width = self.view.bounds.size.width * scale;
|
||||
Core::height = self.view.bounds.size.height * scale;
|
||||
|
||||
int time = getTime();
|
||||
if (time == lastTime)
|
||||
return;
|
||||
Game::update((time - lastTime) * 0.001f);
|
||||
lastTime = time;
|
||||
|
||||
Game::update();
|
||||
Game::render();
|
||||
}
|
||||
|
||||
|
@@ -14,12 +14,20 @@
|
||||
// Time
|
||||
unsigned int startTime;
|
||||
|
||||
int getTime() {
|
||||
int osGetTime() {
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return int((t.tv_sec - startTime) * 1000 + t.tv_usec / 1000);
|
||||
}
|
||||
|
||||
bool osSave(const char *name, const void *data, int size) {
|
||||
FILE *f = fopen(name, "wb");
|
||||
if (!f) return false;
|
||||
fwrite(data, size, 1, f);
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sound
|
||||
#define SND_FRAME_SIZE 4
|
||||
#define SND_DATA_SIZE (1024 * SND_FRAME_SIZE)
|
||||
@@ -206,8 +214,6 @@ int main(int argc, char **argv) {
|
||||
sndInit();
|
||||
Game::init(argc > 1 ? argv[1] : NULL);
|
||||
|
||||
int lastTime = getTime();
|
||||
|
||||
while (1) {
|
||||
if (XPending(dpy)) {
|
||||
XEvent event;
|
||||
@@ -216,17 +222,13 @@ int main(int argc, char **argv) {
|
||||
break;
|
||||
WndProc(event,dpy,wnd);
|
||||
} else {
|
||||
int time = getTime();
|
||||
if (time <= lastTime)
|
||||
continue;
|
||||
|
||||
pthread_mutex_lock(&sndMutex);
|
||||
Game::update((time - lastTime) * 0.001f);
|
||||
bool updated = Game::update();
|
||||
pthread_mutex_unlock(&sndMutex);
|
||||
lastTime = time;
|
||||
|
||||
Game::render();
|
||||
glXSwapBuffers(dpy, wnd);
|
||||
if (updated) {
|
||||
Game::render();
|
||||
glXSwapBuffers(dpy, wnd);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -138,12 +138,16 @@ OSStatus eventHandler(EventHandlerCallRef handler, EventRef event, void* userDat
|
||||
return CallNextEventHandler(handler, event);
|
||||
}
|
||||
|
||||
int getTime() {
|
||||
int osGetTime() {
|
||||
UInt64 t;
|
||||
Microseconds((UnsignedWide*)&t);
|
||||
return int(t / 1000);
|
||||
}
|
||||
|
||||
bool osSave(const char *name, const void *data, int size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char Stream::contentDir[255];
|
||||
char Stream::cacheDir[255];
|
||||
|
||||
@@ -197,17 +201,9 @@ int main() {
|
||||
SelectWindow(window);
|
||||
ShowWindow(window);
|
||||
|
||||
int lastTime = getTime(), fpsTime = lastTime + 1000, fps = 0;
|
||||
|
||||
EventRecord event;
|
||||
while (!isQuit)
|
||||
if (!GetNextEvent(0xffff, &event)) {
|
||||
int time = getTime();
|
||||
if (time <= lastTime)
|
||||
continue;
|
||||
Game::update((time - lastTime) * 0.001f);
|
||||
lastTime = time;
|
||||
|
||||
if (!GetNextEvent(0xffff, &event) && Game::update()) {
|
||||
Game::render();
|
||||
aglSwapBuffers(context);
|
||||
}
|
||||
|
@@ -18,12 +18,20 @@
|
||||
// Time
|
||||
unsigned int startTime;
|
||||
|
||||
int getTime() {
|
||||
int osGetTime() {
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return int((t.tv_sec - startTime) * 1000 + t.tv_usec / 1000);
|
||||
}
|
||||
|
||||
bool osSave(const char *name, const void *data, int size) {
|
||||
FILE *f = fopen(name, "wb");
|
||||
if (!f) return false;
|
||||
fwrite(data, size, 1, f);
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sound
|
||||
snd_pcm_uframes_t SND_FRAMES = 512;
|
||||
snd_pcm_t *sndOut;
|
||||
@@ -466,22 +474,16 @@ int main(int argc, char **argv) {
|
||||
|
||||
inputInit(); // initialize and grab input devices
|
||||
|
||||
int lastTime = getTime();
|
||||
|
||||
while (!Input::down[ikEscape]) {
|
||||
inputUpdate();
|
||||
|
||||
int time = getTime();
|
||||
if (time <= lastTime)
|
||||
continue;
|
||||
|
||||
pthread_mutex_lock(&sndMutex);
|
||||
Game::update((time - lastTime) * 0.001f);
|
||||
bool updated = Game::update();
|
||||
pthread_mutex_unlock(&sndMutex);
|
||||
lastTime = time;
|
||||
|
||||
Game::render();
|
||||
eglSwapBuffers(display, surface);
|
||||
if (updated) {
|
||||
Game::render();
|
||||
eglSwapBuffers(display, surface);
|
||||
}
|
||||
};
|
||||
|
||||
sndFree();
|
||||
|
Reference in New Issue
Block a user