Refactoring structs Part 1

This commit is contained in:
2021-05-20 22:20:52 -07:00
parent c19f7c1083
commit 5ae1f1c0d4
56 changed files with 484 additions and 422 deletions

View File

@ -9,74 +9,63 @@
game_t GAME_STATE;
bool gameInit() {
bool gameInit(game_t *game) {
// Init the game
GAME_STATE.name = GAME_NAME;
logInit();
logText("Starting Game");
game->name = GAME_NAME;
engineInit(&game->engine, game);
// Init
gameTimeInit();
renderInit();
inputInit();
// gameTimeInit();
// renderInit();
// inputInit();
// Load the world shader.
GAME_STATE.shaderWorld = assetShaderLoad(
"shaders/textured.vert", "shaders/textured.frag"
);
// // Load the world shader.
// GAME_STATE.shaderWorld = assetShaderLoad(
// "shaders/textured.vert", "shaders/textured.frag"
// );
// Font
GAME_STATE.fontTexture = assetTextureLoad("font.png");
GAME_STATE.fontTileset = tilesetCreate(20, 20,
GAME_STATE.fontTexture->width,
GAME_STATE.fontTexture->height,
1, 1, 1, 1
);
GAME_STATE.fontBatch = spriteBatchCreate(1024);
// // Font
// GAME_STATE.fontTexture = assetTextureLoad("font.png");
// GAME_STATE.fontTileset = tilesetCreate(20, 20,
// GAME_STATE.fontTexture->width,
// GAME_STATE.fontTexture->height,
// 1, 1, 1, 1
// );
// GAME_STATE.fontBatch = spriteBatchCreate(1024);
// Prepare the renderer.
holdemRenderFrameInit();
holdemRenderWorldInit();
holdemRenderPlayerInit();
holdemRenderCardInit();
holdemRenderChipInit();
// Prepare the action manager
pokerActionInit();
// Start the first action
pokerActionAdd(actionStart());
// // Prepare the renderer.
// pokerInit(&GAME_STATE.poker);
// holdemRenderFrameInit();
// holdemRenderWorldInit();
// holdemRenderPlayerInit();
// holdemRenderCardInit();
// holdemRenderChipInit();
// Init the input manger.
return true;
}
bool gameUpdate(float platformDelta) {
gameTimeUpdate(platformDelta);
renderFrameStart();
inputUpdate();
shaderUse(GAME_STATE.shaderWorld);// TODO: remove
// Update the frame buffers and action queue
holdemRenderFrameUpdate();
pokerActionUpdate();
bool gameUpdate(game_t *game, float platformDelta) {
engineUpdateStart(&game->engine, game, platformDelta);
engineUpdateEnd(&game->engine, game);
// Render things on each frame, then render those frames.
holdemRenderFrameUseLeft();
holdemRenderWorld();
holdemRenderFrameUseRight();
holdemRenderWorld();
holdemRenderFrameBack();
// shaderUse(GAME_STATE.shaderWorld);// TODO: remove
// // Update the frame buffers and action queue
// holdemRenderFrameUpdate();
// pokerActionUpdate();
if(inputIsPressed(INPUT_NULL)) return false;
return true;
// // Render things on each frame, then render those frames.
// holdemRenderFrameUseLeft();
// holdemRenderWorld();
// holdemRenderFrameUseRight();
// holdemRenderWorld();
// holdemRenderFrameBack();
}
void gameDispose() {
pokerActionDispose();
shaderDispose(GAME_STATE.shaderWorld);
inputDispose();
renderDispose();
void gameDispose(game_t *game) {
engineDispose(&game->engine, game);
// pokerActionDispose();
// shaderDispose(GAME_STATE.shaderWorld);
}

View File

@ -5,29 +5,14 @@
#pragma once
#include <dawn/dawn.h>
#include "gametime.h"
#include "../display/render.h"
#include "../display/camera.h"
#include "../display/shader.h"
#include "../display/gui/font.h"
#include "../file/asset.h"
#include "../input/input.h"
#include "../debug/log.h"
#include "../poker/action/action.h"
#include "../poker/action/start.h"
#include "../poker/render/player.h"
#include "../poker/render/card.h"
#include "../poker/render/chip.h"
#include "../poker/render/frame.h"
#include "../poker/render/look.h"
#include "../poker/render/world.h"
#include "../engine/engine.h"
/**
* Initialize the game context.
*
* @return True if successful, otherwise false.
*/
bool gameInit();
bool gameInit(game_t *game);
/**
* Tick the main game loop.
@ -35,9 +20,9 @@ bool gameInit();
* @param platformDelta The platform tick delta between the last render.
* @return True if successful, false if safe exit requested..
*/
bool gameUpdate(float platformDelta);
bool gameUpdate(game_t *game, float platformDelta);
/**
* Cleanup the game instance.
*/
void gameDispose();
void gameDispose(game_t *game);

View File

@ -1,28 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "gametime.h"
gametime_t TIME_STATE;
void gameTimeInit() {
TIME_STATE.delta = GAMETIME_FIXED_STEP;
TIME_STATE.last = GAMETIME_FIXED_STEP;
TIME_STATE.current = GAMETIME_FIXED_STEP + GAMETIME_FIXED_STEP;
}
void gameTimeUpdate(float platformDelta) {
platformDelta = mathMax(
mathMin(platformDelta, GAMETIME_FIXED_STEP),
0
);
TIME_STATE.last = TIME_STATE.current;
TIME_STATE.current = TIME_STATE.current + platformDelta;
TIME_STATE.delta = TIME_STATE.current - TIME_STATE.last;
TIME_STATE.fixedDelta = GAMETIME_FIXED_STEP;
}

View File

@ -1,21 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
/**
* Initializes the gametime global time tracking.
*/
void gameTimeInit();
/**
* Ticks the current game time.
*
* @param platformDelta The delta step between frames from the platform engine.
*/
void gameTimeUpdate(float platformDelta);