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