Compare commits

...

2 Commits

3 changed files with 26 additions and 5 deletions

View File

@ -139,11 +139,15 @@ inline void destroy_entity(entity_t *entity)
inline void entity_manager_init(entity_manager_t *entity_manager)
{
linked_list_init(&entity_manager->entities, sizeof(entity_t), (deleter_t)destroy_entity);
debug_printf("Initialized entity manager.");
}
inline void entity_manager_add_entity(entity_manager_t *entity_manager, entity_t *entity)
{
linked_list_push_back(&entity_manager->entities, entity);
debug_printf("Added entity %d to entity manager.", entity->id);
}
// Only for this file
@ -186,4 +190,6 @@ inline void entity_manager_remove_entity(entity_manager_t *entity_manager, unsig
inline void entity_manager_exit(entity_manager_t *entity_manager)
{
linked_list_clear(&entity_manager->entities);
debug_printf("Exited entity manager.");
}

View File

@ -9,17 +9,21 @@
#endif
#if DEBUG > 0
#define debug_printf(fmt, ...) \
#define debug_printf(...) \
do { \
fprintf(stderr, "\033[33mINFO\033[m: %s:%d:%s(): " fmt "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fprintf(stderr, "\033[33mINFO\033[m: %s:%d:%s(): ", __FILE__, __LINE__, __func__); \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
} while (0)
#else
#define debug_printf(fmt, ...) do {} while (0)
#define debug_printf(...) do {} while (0)
#endif
#define error_printf(fmt, ...) \
#define error_printf(...) \
do { \
fprintf(stderr, "\033[31mERROR\033[m: %s:%d:%s(): " fmt "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fprintf(stderr, "\033[31mERROR\033[m: %s:%d:%s(): ", __FILE__, __LINE__, __func__); \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
} while (0)
#endif // ERRORS_H

View File

@ -1,7 +1,17 @@
#include "game.h"
#include <SDL2/SDL.h>
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);
last_clock_state = start_clock;
}
int main(void)
{
int exit_status = EXIT_SUCCESS;
@ -10,6 +20,7 @@ int main(void)
while(game.is_running)
{
update_time();
game_handle_event();
game_update();
if(game_render()) exit_status = EXIT_FAILURE;