You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.6 KiB
124 lines
3.6 KiB
#include "physics.h" |
|
#include "simulation.h" |
|
#include "config_loader.h" |
|
#include "renderer.h" |
|
#include <cstdio> |
|
#include <cstring> |
|
#include <cstdlib> |
|
#include <cmath> |
|
|
|
// Configuration defaults - edit to change default run mode |
|
//#define DEFAULT_CONFIG_FILE "configs/test_simple.toml" |
|
#define DEFAULT_CONFIG_FILE "tests/configs/solar_system.toml" |
|
|
|
struct ProgramArgs { |
|
const char* config_file; |
|
}; |
|
|
|
void parse_command_line_args(int argc, char** argv, ProgramArgs* args) { |
|
args->config_file = DEFAULT_CONFIG_FILE; |
|
|
|
for (int i = 1; i < argc; i++) { |
|
if (argv[i][0] != '-') { |
|
args->config_file = argv[i]; |
|
} |
|
} |
|
} |
|
|
|
void print_startup_info(const ProgramArgs* args) { |
|
printf("=== Orbital Mechanics Simulation ===\n"); |
|
printf("Loading configuration: %s\n", args->config_file); |
|
} |
|
|
|
void run_gui_simulation(SimulationState* sim) { |
|
init_renderer(1280, 720, "Orbital Mechanics Simulation"); |
|
|
|
RenderState render_state; |
|
setup_camera(&render_state); |
|
|
|
// Initialize UI state |
|
render_state.selected_body_index = -1; // No selection initially |
|
render_state.show_body_list = false; |
|
render_state.show_body_info = false; |
|
render_state.body_list_scroll = 0; // Initial scroll position |
|
render_state.body_list_active = -1; // No active item initially |
|
|
|
bool paused = false; |
|
double speed_multiplier = 1.0; |
|
int physics_steps_per_frame = 100; |
|
|
|
printf("\nSimulation started!\n"); |
|
printf("Controls:\n"); |
|
printf(" Arrow keys: Rotate and zoom camera\n"); |
|
printf(" Space: Pause/Resume\n"); |
|
printf(" +/-: Speed up/slow down simulation\n"); |
|
printf(" I: Toggle info display\n"); |
|
printf(" B: Toggle body list\n"); |
|
printf(" ESC: Quit\n\n"); |
|
|
|
while (!WindowShouldClose()) { |
|
if (IsKeyPressed(KEY_SPACE)) { |
|
paused = !paused; |
|
printf("Simulation %s\n", paused ? "paused" : "resumed"); |
|
} |
|
|
|
if (IsKeyPressed(KEY_EQUAL) || IsKeyPressed(KEY_KP_ADD)) { |
|
speed_multiplier *= 2.0; |
|
printf("Speed multiplier: %.1fx\n", speed_multiplier); |
|
} |
|
|
|
if (IsKeyPressed(KEY_MINUS) || IsKeyPressed(KEY_KP_SUBTRACT)) { |
|
speed_multiplier /= 2.0; |
|
if (speed_multiplier < 0.125) speed_multiplier = 0.125; |
|
printf("Speed multiplier: %.1fx\n", speed_multiplier); |
|
} |
|
|
|
if (!paused) { |
|
int steps = (int)(physics_steps_per_frame * speed_multiplier); |
|
for (int i = 0; i < steps; i++) { |
|
update_simulation(sim); |
|
} |
|
} |
|
|
|
#if 0 |
|
/**** |
|
* Hacks ahead... |
|
*/ |
|
int focus_index = 4; // earth: 2, jupiter, 4 |
|
if (sim->body_count >= focus_index) { |
|
Vector3 offset = {0, 2, 10}; |
|
focus_camera(&render_state, &sim->bodies[focus_index], offset); |
|
} |
|
#else |
|
update_camera(&render_state); |
|
#endif |
|
|
|
render_simulation(sim, &render_state); |
|
} |
|
|
|
close_renderer(); |
|
printf("\nSimulation ended. Final time: %.2f days\n", sim->time / 86400.0); |
|
} |
|
|
|
int main(int argc, char** argv) { |
|
ProgramArgs args; |
|
parse_command_line_args(argc, argv, &args); |
|
print_startup_info(&args); |
|
|
|
// Create simulation with time step of 60 seconds |
|
const int MAX_BODIES = 100; |
|
const double TIME_STEP = 60.0; // 60 seconds per step |
|
SimulationState* sim = create_simulation(MAX_BODIES, TIME_STEP); |
|
|
|
// Load system configuration |
|
if (!load_system_config(sim, args.config_file)) { |
|
printf("Failed to load configuration file\n"); |
|
destroy_simulation(sim); |
|
return 1; |
|
} |
|
|
|
run_gui_simulation(sim); |
|
|
|
destroy_simulation(sim); |
|
return 0; |
|
}
|
|
|