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

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