@ -4,16 +4,30 @@
# include "renderer.h"
# include <cstdio>
# include <cstring>
# include <cstdlib>
int main ( int argc , char * * argv ) {
// Parse command line arguments
const char * config_file = " configs/solar_system.txt " ;
if ( argc > 1 ) {
config_file = argv [ 1 ] ;
bool headless = false ;
int sim_duration_days = 365 ; // Default: 1 year for headless mode
for ( int i = 1 ; i < argc ; i + + ) {
if ( strcmp ( argv [ i ] , " --headless " ) = = 0 | | strcmp ( argv [ i ] , " -h " ) = = 0 ) {
headless = true ;
} else if ( strcmp ( argv [ i ] , " --days " ) = = 0 & & i + 1 < argc ) {
sim_duration_days = atoi ( argv [ + + i ] ) ;
} else if ( argv [ i ] [ 0 ] ! = ' - ' ) {
config_file = argv [ i ] ;
}
}
printf ( " === Orbital Mechanics Simulation === \n " ) ;
printf ( " Loading configuration: %s \n " , config_file ) ;
if ( headless ) {
printf ( " Mode: Headless (terminal output only) \n " ) ;
printf ( " Duration: %d days \n " , sim_duration_days ) ;
}
// Create simulation with time step of 60 seconds
const int MAX_BODIES = 100 ;
@ -27,6 +41,53 @@ int main(int argc, char** argv) {
return 1 ;
}
// If headless mode, run simulation without rendering
if ( headless ) {
const double SECONDS_PER_DAY = 86400.0 ;
const double total_time = sim_duration_days * SECONDS_PER_DAY ;
const double output_interval = SECONDS_PER_DAY ; // Print status once per day
double next_output_time = 0.0 ;
printf ( " \n === Initial State === \n " ) ;
for ( int i = 0 ; i < sim - > body_count ; i + + ) {
CelestialBody * body = & sim - > bodies [ i ] ;
printf ( " %s: \n " , body - > name ) ;
printf ( " Position: (%.3e, %.3e, %.3e) m \n " ,
body - > position . x , body - > position . y , body - > position . z ) ;
printf ( " Velocity: (%.3e, %.3e, %.3e) m/s \n " ,
body - > velocity . x , body - > velocity . y , body - > velocity . z ) ;
}
printf ( " \n === Running Simulation === \n " ) ;
while ( sim - > time < total_time ) {
update_simulation ( sim ) ;
// Print periodic updates
if ( sim - > time > = next_output_time ) {
printf ( " Day %.1f: " , sim - > time / SECONDS_PER_DAY ) ;
for ( int i = 0 ; i < sim - > body_count & & i < 3 ; i + + ) {
double dist = vec3_magnitude ( sim - > bodies [ i ] . position ) ;
printf ( " %s=%.3e m " , sim - > bodies [ i ] . name , dist ) ;
}
printf ( " \n " ) ;
next_output_time + = output_interval ;
}
}
printf ( " \n === Final State (Day %.1f) === \n " , sim - > time / SECONDS_PER_DAY ) ;
for ( int i = 0 ; i < sim - > body_count ; i + + ) {
CelestialBody * body = & sim - > bodies [ i ] ;
printf ( " %s: \n " , body - > name ) ;
printf ( " Position: (%.3e, %.3e, %.3e) m \n " ,
body - > position . x , body - > position . y , body - > position . z ) ;
printf ( " Velocity: (%.3e, %.3e, %.3e) m/s \n " ,
body - > velocity . x , body - > velocity . y , body - > velocity . z ) ;
}
destroy_simulation ( sim ) ;
return 0 ;
} else {
// Graphical mode
// Initialize renderer
init_renderer ( 1280 , 720 , " Orbital Mechanics Simulation " ) ;
@ -88,3 +149,4 @@ int main(int argc, char** argv) {
printf ( " \n Simulation ended. Final time: %.2f days \n " , sim - > time / 86400.0 ) ;
return 0 ;
}
}