Time stuff

This commit is contained in:
2025-08-17 16:11:22 -05:00
parent 6d6a0e4886
commit 3d4317260f
20 changed files with 176 additions and 17 deletions

View File

@@ -32,6 +32,7 @@ target_sources(${DUSK_TARGET_NAME}
PRIVATE
dusksdl2input.c
main.c
time.c
)
# Subdirs

View File

@@ -8,8 +8,6 @@ target_sources(${DUSK_TARGET_NAME}
PRIVATE
render.c
renderbackbuffer.c
rendertext.c
renderconsole.c
)
# Subdirs
@@ -19,4 +17,5 @@ add_subdirectory(mesh)
add_subdirectory(overworld)
add_subdirectory(texture)
add_subdirectory(spritebatch)
add_subdirectory(scene)
add_subdirectory(scene)
add_subdirectory(ui)

View File

@@ -41,7 +41,6 @@ void renderOverworldDraw(void) {
for(uint8_t i = 0; i < CHUNK_MAP_COUNT; i++) {
renderchunk_t *chunk = &RENDER_OVERWORLD.chunks[i];
// meshDraw(&chunk->meshBase, 0, CHUNK_TILE_COUNT * QUAD_VERTEX_COUNT);
meshDraw(&chunk->meshBase, -1, -1);
}
@@ -53,8 +52,8 @@ void renderOverworldDraw(void) {
// Draw the entity
spriteBatchPush(
NULL,
entity->x, entity->y,
entity->x + TILE_WIDTH_HEIGHT, entity->y + TILE_WIDTH_HEIGHT,
floorf(entity->x), floorf(entity->y),
floorf(entity->x + TILE_WIDTH_HEIGHT), floorf(entity->y + TILE_WIDTH_HEIGHT),
0xFF, 0x00, 0xFF, 0XFF,
0.0f, 0.0f, 1.0f, 1.0f
);

View File

@@ -5,11 +5,13 @@
* https://opensource.org/licenses/MIT
*/
#include "dusksdl2input.h"
#include "render.h"
#include "assert/assert.h"
#include "renderbackbuffer.h"
#include "rendertext.h"
#include "renderconsole.h"
#include "display/ui/rendertext.h"
#include "display/ui/renderconsole.h"
#include "display/ui/renderfps.h"
#include "console/console.h"
#include "display/scene/renderscene.h"
#include "display/spritebatch/spritebatch.h"
@@ -23,6 +25,7 @@ errorret_t renderInit(void) {
// Init SDL
uint32_t flags = SDL_INIT_VIDEO;
#if INPUT_SUPPORT_GAMEPAD
printf("Gamepad support enabled.\n");
flags |= SDL_INIT_GAMECONTROLLER;
#endif
@@ -100,6 +103,7 @@ errorret_t renderDraw(void) {
// Draw UI
cameraUIPush();
renderConsoleDraw();
renderFPSDraw();
spriteBatchFlush();
cameraUIPop();

View File

@@ -0,0 +1,12 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
renderconsole.c
renderfps.c
rendertext.c
)

View File

@@ -7,7 +7,7 @@
#include "renderconsole.h"
#include "console/console.h"
#include "rendertext.h"
#include "display/ui/rendertext.h"
void renderConsoleDraw(void) {
if(!CONSOLE.visible) return;

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "renderfps.h"
#include "display/ui/rendertext.h"
#include "time.h"
void renderFPSDraw(void) {
float_t fps = 1.0f / TIME.delta;
char_t buffer[32];
snprintf(buffer, sizeof(buffer), "FPS: %.1f", fps);
if(fps >= 50.0f) {
// Green
renderTextDraw(0, 0, buffer, 0x00, 0xFF, 0x00);
} else if(fps >= 30.0f) {
// Yellow
renderTextDraw(0, 0, buffer, 0xFF, 0xFF, 0x00);
} else {
// Red
renderTextDraw(0, 0, buffer, 0xFF, 0x00, 0x00);
}
}

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
/**
* Draws the FPS overlay.
*/
void renderFPSDraw(void);

View File

@@ -6,7 +6,7 @@
*/
#include "rendertext.h"
#include "render.h"
#include "display/render.h"
#include "assert/assert.h"
#include "display/spritebatch/spritebatch.h"
#include "util/memory.h"

View File

@@ -30,7 +30,7 @@
{ SDL_CONTROLLER_BUTTON_DPAD_RIGHT, INPUT_BIND_RIGHT },
{ SDL_CONTROLLER_BUTTON_A, INPUT_BIND_ACTION },
{ SDL_CONTROLLER_BUTTON_B, INPUT_BIND_CANCEL },
{ SDL_CONTROLLER_BUTTON_MISC1, INPUT_BIND_CONSOLE },
{ SDL_CONTROLLER_BUTTON_BACK, INPUT_BIND_CONSOLE },
{ 0, 0 }
};
#endif

View File

@@ -7,7 +7,6 @@
#include "display/render.h"
#include "game.h"
#include "console/console.h"
#include "input.h"
#define mainError(ret) \
@@ -26,7 +25,6 @@ int main(int argc, char *argv[]) {
gameUpdate();
mainError(renderDraw());
if(inputPressed(INPUT_BIND_QUIT)) consoleExec("quit");
if(!GAME.running) break;
}

21
src/dusksdl2/time.c Normal file
View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "time.h"
#include "dusksdl2.h"
#if DUSK_DYNAMIC_TIME
uint32_t TIME_LAST = 0;
float_t timeDeltaGet(void) {
// Get the current time in milliseconds
uint32_t currentTime = SDL_GetTicks();
float_t delta = (currentTime - TIME_LAST) / 1000.0f;
TIME_LAST = currentTime;
return delta;
}
#endif