Moved some code around and cleaned things a bit.

This commit is contained in:
2021-02-22 08:08:12 +11:00
parent 424577f835
commit adc7f5e208
14 changed files with 405 additions and 77 deletions

View File

@ -7,11 +7,15 @@
#include "engine.h"
engine_t * engineInit(char *gameName) {
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) {
@ -20,7 +24,7 @@ engine_t * engineInit(char *gameName) {
}
// Setup the input manager.
engine->input = inputInit(0);
engine->input = inputInit(platform, inputCount);
if(engine->input == NULL) {
free(engine->render);
free(engine);
@ -32,7 +36,7 @@ engine_t * engineInit(char *gameName) {
void engineStart(engine_t *engine) {
while(!glfwWindowShouldClose(engine->render->window)) {
inputUpdate(engine->input);
inputUpdate(engine->platform, engine->input);
renderFrame(engine->render);
glfwSwapBuffers(engine->render->window);
glfwPollEvents();

View File

@ -5,6 +5,7 @@
#pragma once
#include <stdbool.h>
#include "../platform/platform.h"
#include "../display/render.h"
#include "../file/asset.h"
#include "../input/input.h"
@ -14,6 +15,9 @@ typedef struct {
/** Name of the game running. */
char *gameName;
/** Platform for the game */
platform_t *platform;
/** Renderer for the engine. */
render_t *render;
@ -24,10 +28,14 @@ typedef struct {
/**
* Initialize the engine context.
*
* @param platform The platform that the game is running on.
* @param gameName Name of the game being initialized.
* @param inputCount Count of input binds that exist in-engine.
* @return The engine context.
*/
engine_t * engineInit(char *gameName);
engine_t * engineInit(
platform_t *platform, char *gameName, uint32_t inputCount
);
/**
* Start the main engine loop.