51 lines
1.1 KiB
C
51 lines
1.1 KiB
C
/**
|
|
* Copyright (c) 2021 Dominic Msters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "engine.h"
|
|
|
|
engine_t * engineInit(
|
|
platform_t *platform, char *gameName, uint32_t inputCount
|
|
) {
|
|
// Create the engine instance.
|
|
engine_t *engine = malloc(sizeof(engine_t));
|
|
if(engine == NULL) return NULL;
|
|
|
|
engine->platform = platform;
|
|
|
|
// Setup the renderer.
|
|
engine->render = renderInit(gameName);
|
|
if(engine->render == NULL) {
|
|
free(engine);
|
|
return NULL;
|
|
}
|
|
|
|
// Setup the input manager.
|
|
engine->input = inputInit(platform, inputCount);
|
|
if(engine->input == NULL) {
|
|
free(engine->render);
|
|
free(engine);
|
|
return NULL;
|
|
}
|
|
|
|
return engine;
|
|
}
|
|
|
|
void engineStart(engine_t *engine) {
|
|
while(!glfwWindowShouldClose(engine->render->window)) {
|
|
inputUpdate(engine->platform, engine->input);
|
|
renderFrame(engine->render);
|
|
glfwSwapBuffers(engine->render->window);
|
|
glfwPollEvents();
|
|
}
|
|
}
|
|
|
|
bool engineDispose(engine_t *engine) {
|
|
if(!renderDispose(engine->render)) return false;
|
|
free(engine);
|
|
|
|
return true;
|
|
} |