Added input manager and license.
This commit is contained in:
47
src/engine/engine.c
Normal file
47
src/engine/engine.c
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Msters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
engine_t * engineInit(char *gameName) {
|
||||
// Create the engine instance.
|
||||
engine_t *engine = malloc(sizeof(engine_t));
|
||||
if(engine == NULL) return NULL;
|
||||
|
||||
// Setup the renderer.
|
||||
engine->render = renderInit(gameName);
|
||||
if(engine->render == NULL) {
|
||||
free(engine);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Setup the input manager.
|
||||
engine->input = inputInit(0);
|
||||
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->input);
|
||||
renderFrame(engine->render);
|
||||
glfwSwapBuffers(engine->render->window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
bool engineDispose(engine_t *engine) {
|
||||
if(!renderDispose(engine->render)) return false;
|
||||
free(engine);
|
||||
|
||||
return true;
|
||||
}
|
46
src/engine/engine.h
Normal file
46
src/engine/engine.h
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2021 Dominic Msters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include "../display/render.h"
|
||||
#include "../file/asset.h"
|
||||
#include "../input/input.h"
|
||||
|
||||
/** Information about the current engine context. */
|
||||
typedef struct {
|
||||
/** Name of the game running. */
|
||||
char *gameName;
|
||||
|
||||
/** Renderer for the engine. */
|
||||
render_t *render;
|
||||
|
||||
/** Input Manager for the engine. */
|
||||
input_t *input;
|
||||
} engine_t;
|
||||
|
||||
/**
|
||||
* Initialize the engine context.
|
||||
*
|
||||
* @param gameName Name of the game being initialized.
|
||||
* @return The engine context.
|
||||
*/
|
||||
engine_t * engineInit(char *gameName);
|
||||
|
||||
/**
|
||||
* Start the main engine loop.
|
||||
*
|
||||
* @param engine The game to start the loop for.
|
||||
*/
|
||||
void engineStart(engine_t *engine);
|
||||
|
||||
/**
|
||||
* Cleanup a previously constructed game engine instance.
|
||||
*
|
||||
* @param engine The engine to cleanup.
|
||||
* @return True if successful or not.
|
||||
*/
|
||||
bool engineDispose(engine_t *engine);
|
||||
|
Reference in New Issue
Block a user