Ensure linux terminal is still working

This commit is contained in:
2024-10-06 16:43:54 -05:00
parent 45b3cf9478
commit 5444b0b8c7
15 changed files with 58 additions and 21 deletions

View File

@ -0,0 +1,13 @@
# Copyright (c) 2024 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Subdirs
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
time.c
game.c
)

66
src/dawn/game/game.c Normal file
View File

@ -0,0 +1,66 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "game/game.h"
#include "game/time.h"
#include "input.h"
#include "display/display.h"
#include "rpg/world/maps/testmap.h"
#include "ui/textbox.h"
map_t MAP;
game_t GAME;
void gameInit() {
memset(&GAME, 0, sizeof(game_t));
timeInit();
inputInit();
displayInit();
textboxInit();
testMapInit(&MAP);
gameSetMap(&MAP);
}
uint8_t gameUpdate(const float_t delta) {
timeUpdate(delta);
inputUpdate();
switch(GAME.state) {
case GAME_STATE_INITIAL:
GAME.state = GAME_STATE_OVERWORLD;
break;
case GAME_STATE_OVERWORLD:
textboxUpdate();
if(GAME.currentMap) mapUpdate(GAME.currentMap);
if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_PAUSED;
break;
case GAME_STATE_PAUSED:
if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_OVERWORLD;
break;
default:
assertUnreachable("Invalid game state.");
}
// Perform render.
displayUpdate();
if(GAME.shouldExit) return GAME_UPDATE_RESULT_EXIT;
return GAME_UPDATE_RESULT_CONTINUE;
}
void gameSetMap(map_t *map) {
GAME.currentMap = map;
}
void gameDispose() {
displayDispose();
}

49
src/dawn/game/game.h Normal file
View File

@ -0,0 +1,49 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/world/map.h"
#define GAME_UPDATE_RESULT_CONTINUE 0
#define GAME_UPDATE_RESULT_EXIT 1
#define GAME_STATE_INITIAL 0
#define GAME_STATE_OVERWORLD 1
#define GAME_STATE_PAUSED 2
typedef struct {
map_t *currentMap;
uint8_t state;
bool_t shouldExit;
} game_t;
extern game_t GAME;
/**
* Initializes the game state.
*/
void gameInit();
/**
* Updates the game state.
*
* @param delta Time since last update.
* @return Game update result, 0 for continue, 1 for exit, else for failure.
*/
uint8_t gameUpdate(const float_t delta);
/**
* Sets the current map, does not take ownership.
*
* @param map Map to set.
*/
void gameSetMap(map_t *map);
/**
* Cleans up the game state.
*/
void gameDispose();

23
src/dawn/game/time.c Normal file
View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "game/time.h"
#include "assert/assert.h"
dawntime_t TIME;
void timeInit() {
TIME.delta = 0.0f;
TIME.time = 0.0f;
}
void timeUpdate(const float_t delta) {
assertTrue(delta > 0, "time delta must be greater than 0.");
TIME.delta = delta;
TIME.time += delta;
}

28
src/dawn/game/time.h Normal file
View File

@ -0,0 +1,28 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dawn.h"
typedef struct {
float_t delta;
float_t time;
} dawntime_t;
extern dawntime_t TIME;
/**
* Initializes the time system.
*/
void timeInit();
/**
* Updates the time system.
*
* @param delta Time since last update.
*/
void timeUpdate(const float_t delta);