lovrPlatform: init/destroy;

This commit is contained in:
bjorn 2018-11-16 03:59:06 -08:00
parent b7deda3758
commit c9793eae49
3 changed files with 18 additions and 10 deletions

View File

@ -1,5 +1,4 @@
#include "resources/boot.lua.h"
#include "lib/glfw.h"
#include "version.h"
#include "api.h"
#include "luax.h"
@ -53,7 +52,7 @@ int main(int argc, char** argv) {
#endif
} while (restart);
glfwTerminate();
lovrPlatformDestroy();
return status;
}
@ -96,26 +95,20 @@ static void emscriptenLoop(void* arg) {
if (restart) {
main(context->argc, context->argv);
} else {
glfwTerminate();
lovrPlatformDestroy();
exit(status);
}
}
}
#endif
static void onGlfwError(int code, const char* description) {
lovrThrow(description);
}
typedef enum { // What flag is being searched for?
ARGFLAG_NONE, // Not processing a flag
ARGFLAG_ROOT
} ArgFlag;
lua_State* lovrInit(lua_State* L, int argc, char** argv) {
glfwSetErrorCallback(onGlfwError);
lovrAssert(glfwInit(), "Error initializing GLFW");
lovrPlatformSetTime(0.);
lovrAssert(lovrPlatformInit(), "Failed to initialize platform");
// arg table
// Args follow the lua standard https://en.wikibooks.org/wiki/Lua_Programming/command_line_parameter

View File

@ -68,6 +68,8 @@ typedef void (*gpuProc)(void);
typedef gpuProc (*getProcAddressProc)(const char*);
extern getProcAddressProc lovrGetProcAddress;
bool lovrPlatformInit();
void lovrPlatformDestroy();
void lovrPlatformPollEvents();
double lovrPlatformGetTime();
void lovrPlatformSetTime(double t);

View File

@ -57,6 +57,19 @@ static int convertKeyCode(KeyCode key) {
}
}
static void onGlfwError(int code, const char* description) {
lovrThrow(description);
}
bool lovrPlatformInit() {
glfwSetErrorCallback(onGlfwError);
return glfwInit();
}
void lovrPlatformDestroy() {
glfwTerminate();
}
void lovrPlatformPollEvents() {
glfwPollEvents();
}