Cleaned some code, drastically reduced memory footprint.

This commit is contained in:
2021-09-05 15:02:02 -07:00
parent cb447a6033
commit 2285568480
19 changed files with 263 additions and 108 deletions

View File

@ -18,8 +18,9 @@ set(SETTING_PLATFORM_SDL 2)
# Game Settings
set(SETTING_GAME_POKER 1)
set(SETTING_GAME_DAWN 2)
set(SETTING_GAME_SANDBOX 3)
set(SETTING_GAME SETTING_GAME_POKER)
set(SETTING_GAME SETTING_GAME_SANDBOX)
set(SETTING_GAME_NAME "DawnGame")
################################## Targets #####################################

View File

@ -25,6 +25,7 @@
// Game Settings
#cmakedefine SETTING_GAME_POKER @SETTING_GAME_POKER@
#cmakedefine SETTING_GAME_DAWN @SETTING_GAME_DAWN@
#cmakedefine SETTING_GAME_SANDBOX @SETTING_GAME_SANDBOX@
#cmakedefine SETTING_GAME @SETTING_GAME@
#cmakedefine SETTING_GAME_NAME "@SETTING_GAME_NAME@"

View File

@ -18,6 +18,7 @@
#include "display/matrix.h"
#include "display/primitive.h"
#include "display/render.h"
#include "display/renderlist.h"
#include "display/scene.h"
#include "display/shader.h"
#include "display/spritebatch.h"

View File

@ -0,0 +1,31 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "../util/dynarray.h"
#include "../game/game.h"
#include "framebuffer.h"
#include "shader.h"
typedef struct _renderpass_t renderpass_t;
typedef struct _renderlist_t renderlist_t;
typedef void renderitem_t(
renderlist_t *list, renderpass_t *pass, game_t *game, int32_t i
);
typedef struct _renderpass_t {
framebuffer_t framebuffer;
shader_t *shader;
} renderpass_t;
typedef struct _renderlist_t {
int32_t width;
int32_t height;
dynarray_t passes;
} renderlist_t;

View File

@ -11,6 +11,8 @@
#include "poker/pokergame.h"
#elif SETTING_GAME == SETTING_GAME_DAWN
#include "dawn/dawngame.h"
#elif SETTING_GAME == SETTING_GAME_SANDBOX
#include "sandbox/sandboxscene.h"
#endif
/** Describes the current game */
@ -22,5 +24,7 @@ typedef struct {
pokergame_t pokerGame;
#elif SETTING_GAME == SETTING_GAME_DAWN
dawngame_t dawnGame;
#elif SETTING_GAME == SETTING_GAME_SANDBOX
sandboxscene_t sandboxScene;
#endif
} game_t;

View File

@ -0,0 +1,17 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
#include "../../display/camera.h"
#include "../../display/shader.h"
#include "../../display/font.h"
#include "../../display/primitive.h"
typedef struct {
camera_t camera;
} sandboxscene_t;

View File

@ -9,29 +9,20 @@
/** Debug Inputs */
#define INPUT_NULL (inputbind_t)0x00
#define INPUT_DEBUG_UP (inputbind_t)0x01
#define INPUT_DEBUG_DOWN (inputbind_t)0x02
#define INPUT_DEBUG_LEFT (inputbind_t)0x03
#define INPUT_DEBUG_RIGHT (inputbind_t)0x04
#define INPUT_DEBUG_RAISE (inputbind_t)0x05
#define INPUT_DEBUG_LOWER (inputbind_t)0x06
#define INPUT_DEBUG_FINE (inputbind_t)0x07
#define INPUT_DEBUG_PLUS (inputbind_t)0x08
#define INPUT_DEBUG_MINUS (inputbind_t)0x09
/** Real Inputs (Starts at 64/0x40) */
#define INPUT_UP (inputbind_t)0x40
#define INPUT_DOWN (inputbind_t)0x41
#define INPUT_LEFT (inputbind_t)0x42
#define INPUT_RIGHT (inputbind_t)0x43
#define INPUT_ACCEPT (inputbind_t)0x44
/** Real Inputs (Starts at 32/0x20) */
#define INPUT_UP (inputbind_t)0x20
#define INPUT_DOWN (inputbind_t)0x21
#define INPUT_LEFT (inputbind_t)0x22
#define INPUT_RIGHT (inputbind_t)0x23
#define INPUT_ACCEPT (inputbind_t)0x24
/** Additional sources */
#define INPUT_MOUSE_X (inputsource_t)0x20
#define INPUT_MOUSE_Y (inputsource_t)0x21
#define INPUT_MOUSE_X (inputsource_t)0x10
#define INPUT_MOUSE_Y (inputsource_t)0x11
#define INPUT_BIND_COUNT 0xFF
#define INPUT_SOURCE_COUNT 0xFFFF
#define INPUT_BIND_COUNT 0x40
#define INPUT_SOURCE_COUNT 0xFF
/**
* Input Bind, a specific action bind reference for the game engine to use.
@ -44,7 +35,7 @@ typedef uint8_t inputbind_t;
* hell this number refers to. For most platforms it will be an input, such as a
* keyboard scancode or a (pad number * button count) + button.
*/
typedef uint16_t inputsource_t;
typedef uint8_t inputsource_t;
/**
* Value that represents the state of an input. Defined as 0-1 where 0 is set

View File

@ -6,7 +6,6 @@
#include "glwfwplatform.h"
game_t *GAME_STATE;
GLFWwindow *window = NULL;
int32_t main() {
@ -51,34 +50,22 @@ int32_t main() {
// Init the game
if(gameInit(game)) {
// Bind initial keys
inputBind(input, INPUT_NULL, (inputsource_t)GLFW_KEY_ESCAPE);
inputBind(input, INPUT_DEBUG_UP, (inputsource_t)GLFW_KEY_W);
inputBind(input, INPUT_DEBUG_DOWN, (inputsource_t)GLFW_KEY_S);
inputBind(input, INPUT_DEBUG_LEFT, (inputsource_t)GLFW_KEY_A);
inputBind(input, INPUT_DEBUG_RIGHT, (inputsource_t)GLFW_KEY_D);
inputBind(input, INPUT_DEBUG_RAISE, (inputsource_t)GLFW_KEY_Q);
inputBind(input, INPUT_DEBUG_LOWER, (inputsource_t)GLFW_KEY_E);
inputBind(input, INPUT_DEBUG_FINE, (inputsource_t)GLFW_KEY_LEFT_CONTROL);
inputBind(input, INPUT_DEBUG_PLUS, (inputsource_t)GLFW_KEY_EQUAL);
inputBind(input, INPUT_DEBUG_MINUS, (inputsource_t)GLFW_KEY_MINUS);
inputBind(input, INPUT_UP, (inputsource_t)GLFW_KEY_UP);
inputBind(input, INPUT_DOWN, (inputsource_t)GLFW_KEY_DOWN);
inputBind(input, INPUT_LEFT, (inputsource_t)GLFW_KEY_LEFT);
inputBind(input, INPUT_RIGHT, (inputsource_t)GLFW_KEY_RIGHT);
inputBind(input, INPUT_UP, (inputsource_t)GLFW_KEY_W);
inputBind(input, INPUT_DOWN, (inputsource_t)GLFW_KEY_S);
inputBind(input, INPUT_LEFT, (inputsource_t)GLFW_KEY_A);
inputBind(input, INPUT_RIGHT, (inputsource_t)GLFW_KEY_D);
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_E);
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_ENTER);
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_SPACE);
inputBind(input, INPUT_MOUSE_X, GLFW_PLATFORM_INPUT_MOUSE_X);
inputBind(input, INPUT_MOUSE_Y, GLFW_PLATFORM_INPUT_MOUSE_Y);
inputBind(input, INPUT_NULL, glfwGetInputSourceForKey(GLFW_KEY_ESCAPE));
inputBind(input, INPUT_UP, glfwGetInputSourceForKey(GLFW_KEY_UP));
inputBind(input, INPUT_DOWN, glfwGetInputSourceForKey(GLFW_KEY_DOWN));
inputBind(input, INPUT_LEFT, glfwGetInputSourceForKey(GLFW_KEY_LEFT));
inputBind(input, INPUT_RIGHT, glfwGetInputSourceForKey(GLFW_KEY_RIGHT));
inputBind(input, INPUT_UP, glfwGetInputSourceForKey(GLFW_KEY_W));
inputBind(input, INPUT_DOWN, glfwGetInputSourceForKey(GLFW_KEY_S));
inputBind(input, INPUT_LEFT, glfwGetInputSourceForKey(GLFW_KEY_A));
inputBind(input, INPUT_RIGHT, glfwGetInputSourceForKey(GLFW_KEY_D));
inputBind(input, INPUT_ACCEPT, glfwGetInputSourceForKey(GLFW_KEY_E));
inputBind(input, INPUT_ACCEPT, glfwGetInputSourceForKey(GLFW_KEY_ENTER));
inputBind(input, INPUT_ACCEPT, glfwGetInputSourceForKey(GLFW_KEY_SPACE));
// Bind the fake inputs
inputBind(input, INPUT_MOUSE_X, (inputsource_t)INPUT_MOUSE_X);
inputBind(input, INPUT_MOUSE_Y, (inputsource_t)INPUT_MOUSE_Y);
inputBind(input, INPUT_MOUSE_X, GLFW_PLATFORM_INPUT_MOUSE_X);
inputBind(input, INPUT_MOUSE_Y, GLFW_PLATFORM_INPUT_MOUSE_Y);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
// Update the window title.
@ -122,9 +109,9 @@ void glfwOnKey(GLFWwindow *window,
) {
input_t *input = &GAME_STATE->engine.input;
if(action == GLFW_PRESS) {
input->buffer[(inputsource_t)key] = 1;
input->buffer[glfwGetInputSourceForKey(key)] = 1;
} else if(action == GLFW_RELEASE) {
input->buffer[(inputsource_t)key] = 0;
input->buffer[glfwGetInputSourceForKey(key)] = 0;
}
}
@ -136,4 +123,14 @@ void glfwOnCursor(GLFWwindow *window, double x, double y) {
input_t *input = &GAME_STATE->engine.input;
input->buffer[GLFW_PLATFORM_INPUT_MOUSE_X] = (float)x;
input->buffer[GLFW_PLATFORM_INPUT_MOUSE_Y] = (float)y;
}
inputsource_t glfwGetInputSourceForKey(int32_t key) {
// return (inputsource_t)((
// key <= GLFW_KEY_GRAVE_ACCENT ? key - GLFW_KEY_SPACE :
// key <= GLFW_KEY_MENU ? key - GLFW_KEY_ESCAPE + GLFW_KEY_GRAVE_ACCENT :
// key
// ) % INPUT_SOURCE_COUNT);
return 0;
}

View File

@ -13,8 +13,8 @@
#define WINDOW_WIDTH_DEFAULT 1280
#define WINDOW_HEIGHT_DEFAULT WINDOW_WIDTH_DEFAULT/16*9
#define GLFW_PLATFORM_INPUT_MOUSE_X (inputsource_t)512
#define GLFW_PLATFORM_INPUT_MOUSE_Y (inputsource_t)513
#define GLFW_PLATFORM_INPUT_MOUSE_X (inputsource_t)0xFF
#define GLFW_PLATFORM_INPUT_MOUSE_Y (inputsource_t)0xFE
/** The current running game state. */
extern game_t *GAME_STATE;
@ -48,4 +48,13 @@ void glfwOnKey(GLFWwindow *window,
void glfwOnError(int error, const char* description);
void glfwOnCursor(GLFWwindow *window, double x, double y);
void glfwOnCursor(GLFWwindow *window, double x, double y);
/**
* Get the game engine specific input source for a given GLFW Key code.
*
* @param key Key to get the input source for.
* @return The input source.
*/
inputsource_t glfwGetInputSourceForKey(int32_t key);

View File

@ -26,7 +26,7 @@ void primitiveInit(primitive_t *primitive,
primitive->indexBuffer = buffer[1];
free(buffer);
//Buffer an empty set of data then buffer each component
// Buffer an empty set of data then buffer each component
glBindBuffer(GL_ARRAY_BUFFER, primitive->vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, primitive->indexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizePositions+sizeCoordinates, 0, GL_DYNAMIC_DRAW);

43
src/display/renderlist.c Normal file
View File

@ -0,0 +1,43 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "renderlist.h"
void renderListInit(renderlist_t *list, int32_t passes, int32_t width, int32_t height) {
int32_t i;
renderpass_t *pass;
list->width = width;
list->height = height;
dynArrayInit(&list->passes, sizeof(renderpass_t), passes);
for(i = 0; i < passes; i++) {
pass = (renderpass_t *)dynArrayGet(&list->passes, i);
frameBufferInit(&pass->framebuffer, width, height);
}
}
void renderListRenderPass(renderlist_t *list, game_t *game, int32_t pass, dynarray_t *items, int32_t itemCount) {
int32_t i;
renderpass_t *renderPass;
renderitem_t *item;
renderPass = (renderpass_t *)dynArrayGet(&list->passes, pass);
// Bind the shader.
frameBufferUse(&renderPass->framebuffer, true);
shaderUse(renderPass->shader);
// "Uniforms"
// Render list
for(i = 0; i < itemCount; i++) {
item = (renderitem_t *)dynArrayGet(items, i);
item(list, renderPass, game, i);
}
}

16
src/display/renderlist.h Normal file
View File

@ -0,0 +1,16 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "framebuffer.h"
#include "primitive.h"
#include "shader.h"
#include "primitives/quad.h"
#include "../util/dynarray.h"
void renderListInit(renderlist_t *renderList, int32_t passes);

View File

@ -7,17 +7,17 @@
#include "game.h"
#include "../physics/vector.h"
bool gameInit(game_t *game) {
// Init the engine and the rendering pipeline
engineInit(&game->engine, game);
// Send off to the game instance
#if SETTING_GAME == SETTING_GAME_POKER
return pokerGameInit(game);
return pokerGameInit(&game->pokerGame);
#elif SETTING_GAME == SETTING_GAME_DAWN
return dawnGameInit(game);
#elif SETTING_GAME == SETTING_GAME_SANDBOX
return sandboxSceneInit(&game->sandboxScene);
#endif
}
@ -27,9 +27,11 @@ bool gameUpdate(game_t *game, float platformDelta) {
// Hand off to the game's logic
#if SETTING_GAME == SETTING_GAME_POKER
pokerGameUpdate(game);
pokerGameUpdate(&game->pokerGame, &game->engine);
#elif SETTING_GAME == SETTING_GAME_DAWN
dawnGameUpdate(game);
#elif SETTING_GAME == SETTING_GAME_SANDBOX
sandboxSceneUpdate(&game->sandboxScene, &game->engine);
#endif
// Hand back to the engine.
@ -42,6 +44,8 @@ void gameDispose(game_t *game) {
pokerGameDispose(game);
#elif SETTING_GAME == SETTING_GAME_DAWN
dawnGameDispose(game);
#elif SETTING_GAME == SETTING_GAME_SANDBOX
return sandboxSceneDispose(&game->sandboxScene);
#endif
engineDispose(&game->engine, game);

View File

@ -6,13 +6,14 @@
#pragma once
#include <dawn/dawn.h>
#include "../engine/engine.h"
#include "../locale/language.h"
#if SETTING_GAME == SETTING_GAME_POKER
#include "poker/pokergame.h"
#elif SETTING_GAME == SETTING_GAME_DAWN
#include "dawn/dawngame.h"
#elif SETTING_GAME == SETTING_GAME_SANDBOX
#include "sandbox/sandboxscene.h"
#endif
/**

View File

@ -7,80 +7,60 @@
#include "pokergame.h"
bool pokerGameInit(game_t *game) {
pokergame_t *pokerGame = &game->pokerGame;
bool pokerGameInit(pokergame_t *game) {
// Load the Assets.
pokerGameAssetsInit(&pokerGame->assets);
pokerGameAssetsInit(&game->assets);
// Initialize the Visual Novel Engine.
vnSceneInit(&pokerGame->scene,
&pokerGame->assets.font,
&pokerGame->assets.testTexture
vnSceneInit(&game->scene,
&game->assets.font,
&game->assets.testTexture
);
// Initialize the world
pokerWorldInit(pokerGame);
pokerWorldInit(game);
// Initialize the UI.
pokerUiInit(pokerGame);
pokerUiInit(game);
// Add the first action, the game action, and then start the action queue.
pokerGameActionStartAdd(pokerGame);
queueNext(&pokerGame->scene.conversation.actionQueue);
// Testing
dynArrayInit(&dynarr, sizeof(int32_t), 100);
int32_t i, count;
count = 32;
for(i = 0; i < count; i++) {
dynArrayPush(&dynarr, &i);
printf("Count i is %i\n", *((int32_t *)dynArrayGet(&dynarr, i)) );
}
dynArraySploice(&dynarr, 0, 16);
printf("Count 0 is %i\n", *((int32_t *)dynArrayGet(&dynarr, 0)) );
printf("Count 8 is %i\n", *((int32_t *)dynArrayGet(&dynarr, 8)) );
pokerGameActionStartAdd(game);
queueNext(&game->scene.conversation.actionQueue);
return true;
}
void pokerGameUpdate(game_t *game) {
pokergame_t *pokerGame;
pokerGame = &game->pokerGame;
void pokerGameUpdate(pokergame_t *game, engine_t *engine) {
// Update the VN Engine.
vnSceneUpdate(&pokerGame->scene, &game->engine);
vnSceneUpdate(&game->scene, engine);
// Bind the shader.
shaderUse(&pokerGame->assets.shader);
shaderUse(&game->assets.shader);
// Render the visual novel scene.
vnSceneRenderWorld(&pokerGame->scene,&game->engine,&pokerGame->assets.shader);
vnSceneRenderWorld(&game->scene, engine, &game->assets.shader);
pokerWorldRender(&pokerGame->world, &game->engine, &pokerGame->assets);
vnSceneRenderCharacters(&pokerGame->scene, &pokerGame->assets.shader);
pokerWorldRender(&game->world, engine, &game->assets);
vnSceneRenderCharacters(&game->scene, &game->assets.shader);
// Render the UI
vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
pokerUiRender(pokerGame, &game->engine);
vnSceneRenderGui(&game->scene, engine, &game->assets.shader);
pokerUiRender(game, engine);
}
void pokerGameDispose(game_t *game) {
pokergame_t *pokerGame;
pokerGame = &game->pokerGame;
void pokerGameDispose(pokergame_t *game) {
//Cleanup the UI
pokerUiDispose(pokerGame);
pokerUiDispose(game);
// Cleanup the world
pokerWorldDispose(pokerGame);
pokerWorldDispose(game);
// Destroy the Visual Novel engine.
vnSceneDispose(&pokerGame->scene);
vnSceneDispose(&game->scene);
// Unload all assets
pokerGameAssetsDispose(&pokerGame->assets);
pokerGameAssetsDispose(&game->assets);
}
void pokerGameQueueRestack(pokergame_t *pokerGame) {

View File

@ -23,19 +23,20 @@
* @param game Game to initialize.
* @returns True if successful, otherwise false.
*/
bool pokerGameInit(game_t *game);
bool pokerGameInit(pokergame_t *game);
/**
* Updates the poker game instance.
* @param game Game to update for.
* @param game Poker game to update for.
* @param engine Engine to use during update.
*/
void pokerGameUpdate(game_t *game);
void pokerGameUpdate(pokergame_t *game, engine_t *engine);
/**
* Disposes a previously initialized poker game instance.
* @param game Game to initialize for.
* @param game Game to dispose.
*/
void pokerGameDispose(game_t *game);
void pokerGameDispose(pokergame_t *game);
/**
* Restacks the poker game's stack.

View File

@ -0,0 +1,21 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "sandboxscene.h"
bool sandboxSceneInit(sandboxscene_t *game) {
printf("Sandbox init\n");
return true;
}
void sandboxSceneUpdate(sandboxscene_t *game, engine_t *engine) {
}
void sandboxSceneDispose(sandboxscene_t *game) {
}

View File

@ -0,0 +1,37 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../display/camera.h"
#include "../../display/shader.h"
#include "../../display/font.h"
#include "../../display/primitive.h"
#include "../../display/primitives/quad.h"
/**
* Initialize the sandbox scene test game.
*
* @param game Game to initialize.
* @return True if successful, otherwise false.
*/
bool sandboxSceneInit(sandboxscene_t *game);
/**
* Update a sandbox scene.
*
* @param game Game to update.
* @param engine Engine to use when updating.
*/
void sandboxSceneUpdate(sandboxscene_t *game, engine_t *engine);
/**
* Dispose a previously created scene game.
*
* @param game Game to dispose.
*/
void sandboxSceneDispose(sandboxscene_t *game);

View File

@ -81,8 +81,8 @@ void listRemoveEntry(list_t *list, listentry_t *entry, bool freeData) {
listentry_t * listGetByIndex(list_t *list, uint32_t index) {
if(index >= list->size) return NULL;
//TODO: We can probably make this more efficient by deciding which way we
//should loop from based on the list size.
// TODO: We can probably make this more efficient by deciding which way we
// should loop from based on the list size.
uint32_t i = 0;
listentry_t *previous = list->start;