Browse Source

Store and display config file name in simulation state

main
cinnaboot 6 months ago
parent
commit
c4262ab096
  1. 3
      src/config_loader.cpp
  2. 13
      src/renderer.cpp
  3. 2
      src/renderer.h
  4. 1
      src/simulation.cpp
  5. 1
      src/simulation.h

3
src/config_loader.cpp

@ -140,6 +140,9 @@ bool load_system_config(SimulationState* sim, const char* filepath) {
initialize_bodies(sim); initialize_bodies(sim);
strncpy(sim->config_name, filepath, sizeof(sim->config_name) - 1);
sim->config_name[sizeof(sim->config_name) - 1] = '\0';
printf("Loaded %d bodies from %s\n", body_count, filepath); printf("Loaded %d bodies from %s\n", body_count, filepath);
return true; return true;
} }

13
src/renderer.cpp

@ -390,7 +390,7 @@ void render_simulation(SimulationState* sim, RenderState* render_state) {
EndMode3D(); EndMode3D();
// Render UI panels (always shown) // Render UI panels (always shown)
render_info(sim, "solar_system.txt"); render_info(sim);
render_body_list_ui(sim, render_state); render_body_list_ui(sim, render_state);
render_body_info_ui(sim, render_state); render_body_info_ui(sim, render_state);
@ -398,10 +398,10 @@ void render_simulation(SimulationState* sim, RenderState* render_state) {
} }
// Render simulation information overlay // Render simulation information overlay
void render_info(SimulationState* sim, const char* config_name) { void render_info(SimulationState* sim) {
// Panel dimensions // Panel dimensions
int panel_width = 200; int panel_width = 200;
int panel_height = 280; int panel_height = 300;
int panel_x = 10; int panel_x = 10;
int panel_y = GetScreenHeight() - panel_height - 10; int panel_y = GetScreenHeight() - panel_height - 10;
@ -415,10 +415,15 @@ void render_info(SimulationState* sim, const char* config_name) {
// Prepare info text // Prepare info text
char info_text[1024]; char info_text[1024];
char temp_buffer[256]; char temp_buffer[256];
int offset = 0;
snprintf(info_text, sizeof(info_text), "Orbital Mechanics Simulation\n\n"); snprintf(info_text, sizeof(info_text), "Orbital Mechanics Simulation\n\n");
// Config name
if (sim->config_name[0] != '\0') {
snprintf(temp_buffer, sizeof(temp_buffer), "Config: %s\n\n", sim->config_name);
strcat(info_text, temp_buffer);
}
// Simulation time (in days) // Simulation time (in days)
double days = sim->time / 86400.0; // seconds to days double days = sim->time / 86400.0; // seconds to days
snprintf(temp_buffer, sizeof(temp_buffer), "Time: %.2f days\n", days); snprintf(temp_buffer, sizeof(temp_buffer), "Time: %.2f days\n", days);

2
src/renderer.h

@ -29,7 +29,7 @@ void update_camera(RenderState* render_state, SimulationState* sim);
// Rendering functions // Rendering functions
void render_body(CelestialBody* body, RenderState* render_state); void render_body(CelestialBody* body, RenderState* render_state);
void render_simulation(SimulationState* sim, RenderState* render_state); void render_simulation(SimulationState* sim, RenderState* render_state);
void render_info(SimulationState* sim, const char* config_name); void render_info(SimulationState* sim);
// UI rendering functions // UI rendering functions
void render_body_list_ui(SimulationState* sim, RenderState* render_state); void render_body_list_ui(SimulationState* sim, RenderState* render_state);

1
src/simulation.cpp

@ -13,6 +13,7 @@ SimulationState* create_simulation(int max_bodies, double time_step) {
sim->max_bodies = max_bodies; sim->max_bodies = max_bodies;
sim->time = 0.0; sim->time = 0.0;
sim->dt = time_step; sim->dt = time_step;
sim->config_name[0] = '\0';
return sim; return sim;
} }

1
src/simulation.h

@ -26,6 +26,7 @@ struct SimulationState {
int max_bodies; int max_bodies;
double time; // simulation time (seconds) double time; // simulation time (seconds)
double dt; // time step (seconds) double dt; // time step (seconds)
char config_name[256]; // name of the config file loaded
}; };
// Simulation management functions // Simulation management functions

Loading…
Cancel
Save