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

@ -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;