Added some defineable types
This commit is contained in:
@ -9,31 +9,29 @@
|
||||
|
||||
game_t * gameInit(platform_t *platform) {
|
||||
// Create the game
|
||||
dawngame_t *dawn = malloc(sizeof(dawngame_t));
|
||||
if(dawn == NULL) return NULL;
|
||||
game_t *game = malloc(sizeof(game_t));
|
||||
if(game == NULL) return NULL;
|
||||
|
||||
// Load the game engine
|
||||
dawn->engine = engineInit(platform, GAME_NAME, GAME_INPUT_COUNT);
|
||||
if(dawn->engine == NULL) {
|
||||
free(dawn);
|
||||
game->engine = engineInit(platform, GAME_NAME, GAME_INPUT_COUNT);
|
||||
if(game->engine == NULL) {
|
||||
free(game);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Pass to the main game to handle.
|
||||
return (game_t *)dawn;
|
||||
// Pass to the main game to handle.r
|
||||
return game;
|
||||
}
|
||||
|
||||
void gameUpdate(game_t *game) {
|
||||
dawngame_t *dawn = (dawngame_t *)game;
|
||||
engineUpdate(dawn->engine);
|
||||
engineUpdate(game->engine);
|
||||
}
|
||||
|
||||
void gameDispose(game_t *game) {
|
||||
dawngame_t *dawn = (dawngame_t *)game;
|
||||
engineDispose(dawn->engine);
|
||||
free(dawn);
|
||||
engineDispose(game->engine);
|
||||
free(game);
|
||||
}
|
||||
|
||||
engine_t * gameGetEngine(game_t *game) {
|
||||
return ((dawngame_t *)game)->engine;
|
||||
return game->engine;
|
||||
}
|
@ -5,11 +5,21 @@
|
||||
|
||||
#pragma once
|
||||
#include <malloc.h>
|
||||
#include "../engine/game/game.h"
|
||||
#include "../engine/engine.h"
|
||||
|
||||
/////////////////////////////////// CONSTANTS //////////////////////////////////
|
||||
/////////////////////////////// TYPE DEFINITIONS ///////////////////////////////
|
||||
/** Context about Dawn Game */
|
||||
typedef struct {
|
||||
/** The engine context for the game */
|
||||
engine_t *engine;
|
||||
} dawngame_t;
|
||||
#define GAMETYPE_T dawngame_t
|
||||
|
||||
|
||||
////////////////////////////// TYPE BOUND INCLUDES /////////////////////////////
|
||||
#include "../engine/game/game.h"
|
||||
|
||||
/////////////////////////////////// CONSTANTS //////////////////////////////////
|
||||
/** Name of the Game */
|
||||
#define GAME_NAME "Dawn Game"
|
||||
|
||||
@ -19,11 +29,4 @@
|
||||
#define GAME_INPUT_LEFT (inputbind_t)0x03
|
||||
#define GAME_INPUT_RIGHT (inputbind_t)0x04
|
||||
|
||||
#define GAME_INPUT_COUNT 5
|
||||
|
||||
/////////////////////////////// Type Definitions ///////////////////////////////
|
||||
/** Context about Dawn Game */
|
||||
typedef struct {
|
||||
/** The engine context for the game */
|
||||
engine_t *engine;
|
||||
} dawngame_t;
|
||||
#define GAME_INPUT_COUNT 5
|
@ -11,7 +11,10 @@
|
||||
#include "../platform.h"
|
||||
|
||||
/** Information about the current game context. */
|
||||
typedef void game_t;
|
||||
#ifndef GAMETYPE_T
|
||||
#define GAMETYPE_T void
|
||||
#endif
|
||||
typedef GAMETYPE_T game_t;
|
||||
|
||||
/**
|
||||
* Initialize the game context.
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include "../util/list/list.h"
|
||||
#include "../platform.h"
|
||||
|
||||
/////////////////////////////////// CONSTANTS //////////////////////////////////
|
||||
#define INPUT_NULL (inputbind_t)0x00
|
||||
@ -19,7 +20,7 @@
|
||||
* e.g. "Jump" or "Walk Forward".
|
||||
*/
|
||||
typedef uint8_t inputbind_t;
|
||||
typedef void inputsource_t;
|
||||
typedef platforminput_t inputsource_t;
|
||||
|
||||
/**
|
||||
* Structure for the entire input mapping.
|
||||
|
@ -7,6 +7,12 @@
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef PLATFORMINPUT_T
|
||||
#define PLATFORMINPUT_T void
|
||||
#endif
|
||||
/** Definition for the platform's input source */
|
||||
typedef PLATFORMINPUT_T platforminput_t;
|
||||
|
||||
/**
|
||||
* Contains information about the running platform. Essentially this is just
|
||||
* some context as to what is running the game engine itself. It's mostly for
|
||||
@ -19,4 +25,8 @@ typedef struct {
|
||||
|
||||
/** Dimensions of the screen (in pixels) */
|
||||
uint32_t screenWidth, screenHeight;
|
||||
|
||||
int32_t inputSourceCount;
|
||||
float *inputValues;
|
||||
platforminput_t *inputSource;
|
||||
} platform_t;
|
@ -13,7 +13,11 @@ int32_t main() {
|
||||
platform_t platform = {
|
||||
.name = "glfw",
|
||||
.screenWidth = WINDOW_WIDTH_DEFAULT,
|
||||
.screenHeight = WINDOW_HEIGHT_DEFAULT
|
||||
.screenHeight = WINDOW_HEIGHT_DEFAULT,
|
||||
|
||||
.inputSourceCount = 0,
|
||||
.inputValues = NULL,
|
||||
.inputSource = NULL
|
||||
};
|
||||
|
||||
// Attempt to init GLFW
|
||||
@ -38,6 +42,10 @@ int32_t main() {
|
||||
runningGame = gameInit(&platform);
|
||||
if(runningGame == NULL) return 1;
|
||||
|
||||
// Update the window title.
|
||||
engine_t *engine = gameGetEngine(runningGame);
|
||||
glfwSetWindowTitle(window, engine->name);
|
||||
|
||||
// Main Render Loop
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
gameUpdate(runningGame);
|
||||
@ -65,11 +73,8 @@ void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height) {
|
||||
void glfwOnKey(GLFWwindow *window,
|
||||
int32_t key, int32_t scancode, int32_t action, int32_t mods
|
||||
) {
|
||||
char *title = glfwGetKeyName(key, scancode);
|
||||
if(title == NULL) {
|
||||
printf("Unknown Key %d", scancode);
|
||||
} else {
|
||||
printf(title);
|
||||
}
|
||||
printf("\n");
|
||||
float force = action == GLFW_PRESS ? 1 : 0;
|
||||
engine_t *engine = gameGetEngine(runningGame);
|
||||
|
||||
engine->input->current[scancode] = force;
|
||||
}
|
@ -5,6 +5,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PLATFORMINPUT_T uint32_t
|
||||
|
||||
// I load GLAD and GLFW Here because they need to be included in specific orders
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
Reference in New Issue
Block a user