Skip to content

Commit

Permalink
Merge branch 'release/1.3.1' of https://github.com/avivbeeri/dome int…
Browse files Browse the repository at this point in the history
…o release/1.3.1
  • Loading branch information
avivbeeri committed Oct 23, 2020
2 parents 488ec19 + 18ceaf2 commit afb5a0d
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,26 +324,31 @@ int main(int argc, char* args[])
WrenInterpretResult interpreterResult;

// Load user game file
WrenHandle* initMethod = NULL;
WrenHandle* updateMethod = NULL;
WrenHandle* drawMethod = NULL;
WrenHandle* gameClass = NULL;
SDL_Thread* recordThread = NULL;

interpreterResult = wrenInterpret(vm, "main", gameFile);
free(gameFile);
if (interpreterResult != WREN_RESULT_SUCCESS) {
result = EXIT_FAILURE;
goto cleanup;
goto vm_cleanup;
}
// Load the class into slot 0.


wrenEnsureSlots(vm, 3);
WrenHandle* initMethod = wrenMakeCallHandle(vm, "init()");
WrenHandle* updateMethod = wrenMakeCallHandle(vm, "update()");
WrenHandle* drawMethod = wrenMakeCallHandle(vm, "draw(_)");
initMethod = wrenMakeCallHandle(vm, "init()");
updateMethod = wrenMakeCallHandle(vm, "update()");
drawMethod = wrenMakeCallHandle(vm, "draw(_)");
wrenGetVariable(vm, "main", "Game", 0);
WrenHandle* gameClass = wrenGetSlotHandle(vm, 0);
gameClass = wrenGetSlotHandle(vm, 0);

// Initiate game loop
uint8_t FPS = 60;
double MS_PER_FRAME = ceil(1000.0 / FPS);
SDL_Thread* recordThread = NULL;

wrenSetSlotHandle(vm, 0, gameClass);
interpreterResult = wrenCall(vm, initMethod);
Expand Down Expand Up @@ -563,10 +568,21 @@ int main(int argc, char* args[])
}
}

wrenReleaseHandle(vm, initMethod);
wrenReleaseHandle(vm, drawMethod);
wrenReleaseHandle(vm, updateMethod);
wrenReleaseHandle(vm, gameClass);
if (initMethod != NULL) {
wrenReleaseHandle(vm, initMethod);
}

if (drawMethod != NULL) {
wrenReleaseHandle(vm, drawMethod);
}

if (updateMethod != NULL) {
wrenReleaseHandle(vm, updateMethod);
}

if (gameClass != NULL) {
wrenReleaseHandle(vm, gameClass);
}

if (bufferClass != NULL) {
wrenReleaseHandle(vm, bufferClass);
Expand Down

0 comments on commit afb5a0d

Please sign in to comment.