diff --git a/app.c b/app.c index 10af39b..58a06f8 100644 --- a/app.c +++ b/app.c @@ -17,7 +17,7 @@ App *app_NewApp() { render_LoadBundle("bundles.txt"); - App *app = malloc(sizeof(App)); + App *app = zero_malloc(sizeof(App)); app->input = input_NewSystem(app); app->physics = physics_NewSystem(app); @@ -26,7 +26,8 @@ App *app_NewApp() { app->camera = camera_NewSystem(app); app->particle = particle_NewSystem(app); - app->wantQuit = false; + app->switch_level = NULL; + app->wantQuit = false; Entity *player = entity_Create(app->entity, "player"); @@ -104,6 +105,13 @@ void app_DeleteApp(App *app) { void app_Advance(App *app, Duration deltaTime) { + // Limit deltaTime to 20ms (1/50 second) + if (deltaTime.microseconds > 20000) + deltaTime.microseconds = 20000; + + if (app->switch_level != NULL) + _app_SwitchLevel(app); + particle_Advance(app->particle, deltaTime); input_Advance(app->input); player_Advance(app->player, deltaTime); diff --git a/app.h b/app.h index f1de50b..c26eac6 100644 --- a/app.h +++ b/app.h @@ -22,7 +22,8 @@ typedef struct _App { System_Camera *camera; System_Particle *particle; - bool wantQuit; + char *switch_level; + bool wantQuit; } App; App *app_NewApp(); @@ -33,6 +34,10 @@ void app_Render(App *app); void app_DebugText(App *app, vector_Vector *vec_string); +// Trigger the app to reload all entities before next frame update. +void app_QueueLoadLevel(App *app, const char *level_name); +void _app_SwitchLevel(App *app); + #ifdef __cplusplus } diff --git a/app_file.c b/app_file.c new file mode 100644 index 0000000..c18e57a --- /dev/null +++ b/app_file.c @@ -0,0 +1,16 @@ + +#include +#include "app.h" +#include "types.h" + + +void app_QueueLoadLevel(App *app, const char *level_name) { + if (app->switch_level != NULL) { + WARN("previous switch_level \"%s\" not processed; purged", app->switch_level); + free(app->switch_level); + } + app->switch_level = copy_malloc(level_name); +} + +void _app_SwitchLevel(App *app) { +}