#include "physics.h" #include "simulation.h" #include "config_loader.h" #include "renderer.h" #include "ui_renderer.h" #include #include #include #include // Configuration defaults - edit to change default run mode //#define DEFAULT_CONFIG_FILE "tests/test_moon_orbits.toml" #define DEFAULT_CONFIG_FILE "tests/test_maneuver_planning.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(1600, 900, "Orbital Mechanics Simulation"); RenderState render_state; setup_camera(&render_state); UIState ui_state; ui_state.body_list_scroll = 0; ui_state.body_list_active = -1; ui_state.selected_craft_index = -1; // Find root body (body with parent_index == -1) int root_body_index = -1; for (int i = 0; i < sim->body_count; i++) { if (sim->bodies[i].parent_index == -1) { root_body_index = i; break; } } // Initialize render state render_state.selected_body_index = root_body_index >= 0 ? root_body_index : -1; render_state.camera_target_enabled = root_body_index >= 0; render_state.last_target_index = root_body_index >= 0 ? root_body_index : -1; render_state.camera_offset = (Vector3){ 0, 50, 100 }; // Initialize UI state ui_state.body_list_scroll = 0; // Initial scroll position ui_state.body_list_active = root_body_index >= 0 ? root_body_index : -1; // Sync with selected body gui_init(); 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(" Select body from list to follow it\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); } } update_camera(&render_state, sim); begin_frame(); render_simulation(sim, &render_state); // Render UI panels render_info(sim); render_body_list_ui(sim, &render_state, &ui_state); render_body_info_ui(sim, &render_state, &ui_state); render_maneuver_list_ui(sim, &render_state, &ui_state); end_frame(); } close_renderer(&render_state); 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 int MAX_SPACECRAFT = 50; const int MAX_MANEUVERS = 100; const double TIME_STEP = 60.0; // 60 seconds per step SimulationState* sim = create_simulation(MAX_BODIES, MAX_SPACECRAFT, MAX_MANEUVERS, 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; }