Compare commits

...

2 Commits

3 changed files with 36 additions and 5 deletions

View File

@ -3,6 +3,7 @@
#include <SDL3/SDL.h>
#include <stdlib.h>
#include "asset_manager.h"
#include "game.h"
#include "errors.h"
SDL_Window *window = NULL;
@ -16,7 +17,7 @@ inline int display_init(void)
return EXIT_FAILURE;
}
if(!SDL_SetAppMetadata("2D_Engine", "1.0", "2D_Engine"))
if(!SDL_SetAppMetadata("2D_Engine", "1.0", "2D_Engine_SDL2_Core"))
{
error_printf("Failed to set app metadata : %s", SDL_GetError());
return EXIT_FAILURE;
@ -94,6 +95,36 @@ inline int display_clear(void)
inline void display_update(void)
{
SDL_RenderPresent(renderer);
#if DEBUG >= 1
float fps = 1000.0f / game.delta_time_ms;
static float max_fps_10s = 0.0f;
static float low_fps_10s = 10000000.0f;
if(fps > max_fps_10s) max_fps_10s = fps;
if(fps < low_fps_10s) low_fps_10s = fps;
static float fps_update_delta_time = 0.0f;
fps_update_delta_time += game.delta_time_ms;
if(fps_update_delta_time >= 100.0f)
{
fps_update_delta_time = 0.0f;
char title[100];
sprintf(title, "2D_Engine | cur: %.2ffps | max: %.2ffps | low: %.2ffps", fps, max_fps_10s, low_fps_10s);
SDL_SetWindowTitle(window, title);
}
static float fps_max_low_update_delta_time = 0.0f;
fps_max_low_update_delta_time += game.delta_time_ms;
if(fps_max_low_update_delta_time > 10000.0f)
{
fps_max_low_update_delta_time = 0.0f;
max_fps_10s = 0.0f;
low_fps_10s = 10000000.0f;
}
#endif // DEBUG >= 1
}
int display_draw_texture(texture_t *texture, rect_t *src_rect, rect_t *dst_rect, bool flip)

View File

@ -91,7 +91,7 @@ component_t *entity_new_component(entity_t *entity, component_type_t component_t
if(component->component_init(component)) return NULL;
if(linked_list_push_front(&entity->components, component_elem)) return NULL;
if(linked_list_push_back(&entity->components, component_elem)) return NULL;
return component;
}

View File

@ -7,9 +7,9 @@ game_t game;
static inline void update_time(void)
{
static uint32_t last_clock_state = 0;
uint32_t start_clock = SDL_GetTicks();
game.delta_time_ms = (float)(start_clock - last_clock_state);
static uint64_t last_clock_state = 0;
uint64_t start_clock = SDL_GetTicksNS();
game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock_state));
last_clock_state = start_clock;
}