@ -21,6 +21,25 @@
# define MANEUVER_LIST_HEIGHT 450
# define MANEUVER_LIST_Y_OFFSET 320
static inline bool needs_body_list_rebuild ( UIState * ui_state , SimulationState * sim ) {
return ( ui_state - > cached_body_count ! = sim - > body_count | |
ui_state - > cached_craft_count ! = sim - > craft_count | |
ui_state - > body_list_buffer = = NULL ) ;
}
static inline bool needs_maneuver_list_rebuild ( UIState * ui_state , SimulationState * sim , int current_executed_count ) {
return ( ui_state - > cached_maneuver_count ! = sim - > maneuver_count | |
ui_state - > cached_executed_count ! = current_executed_count | |
ui_state - > maneuver_list_buffer = = NULL ) ;
}
static inline bool needs_hohmann_rebuild ( UIState * ui_state , SimulationState * sim ) {
return ( ui_state - > cached_body_count ! = sim - > body_count | |
ui_state - > cached_craft_count ! = sim - > craft_count | |
ui_state - > craft_list_buffer = = NULL | |
ui_state - > body_dropdown_buffer = = NULL ) ;
}
void gui_init ( ) {
GuiLoadStyleAmber ( ) ;
}
@ -96,9 +115,7 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state, UIStat
int total_items = sim - > body_count + sim - > craft_count ;
// Check if buffer needs rebuilding
bool needs_rebuild = ( ui_state - > cached_body_count ! = sim - > body_count | |
ui_state - > cached_craft_count ! = sim - > craft_count | |
ui_state - > body_list_buffer = = NULL ) ;
bool needs_rebuild = needs_body_list_rebuild ( ui_state , sim ) ;
if ( needs_rebuild ) {
int buffer_size = total_items * ( 64 + 3 + 1 ) + 1 ;
@ -362,9 +379,13 @@ void render_maneuver_list_ui(SimulationState* sim, RenderState* render_state, UI
GuiWindowBox ( panel_bounds , title ) ;
int craft_maneuver_count = 0 ;
int current_executed_count = 0 ;
for ( int i = 0 ; i < sim - > maneuver_count ; i + + ) {
if ( sim - > maneuvers [ i ] . craft_index = = ui_state - > selected_craft_index ) {
craft_maneuver_count + + ;
if ( sim - > maneuvers [ i ] . executed ) {
current_executed_count + + ;
}
}
}
@ -407,8 +428,7 @@ void render_maneuver_list_ui(SimulationState* sim, RenderState* render_state, UI
}
// Check if buffer needs rebuilding
bool needs_rebuild = ( ui_state - > cached_maneuver_count ! = sim - > maneuver_count | |
ui_state - > maneuver_list_buffer = = NULL ) ;
bool needs_rebuild = needs_maneuver_list_rebuild ( ui_state , sim , current_executed_count ) ;
if ( needs_rebuild ) {
int buffer_size = craft_maneuver_count * ( 64 + 10 + 1 ) + 1 ;
@ -437,6 +457,7 @@ void render_maneuver_list_ui(SimulationState* sim, RenderState* render_state, UI
}
ui_state - > cached_maneuver_count = sim - > maneuver_count ;
ui_state - > cached_executed_count = current_executed_count ;
}
Rectangle list_bounds = {
@ -748,10 +769,7 @@ void render_maneuver_hohmann_tab(SimulationState* sim, UIState* ui_state, int x,
}
}
bool needs_rebuild = ( ui_state - > cached_body_count ! = sim - > body_count | |
ui_state - > cached_craft_count ! = sim - > craft_count | |
ui_state - > craft_list_buffer = = NULL | |
ui_state - > body_dropdown_buffer = = NULL ) ;
bool needs_rebuild = needs_hohmann_rebuild ( ui_state , sim ) ;
if ( needs_rebuild ) {
int craft_buffer_size = sim - > craft_count * 64 + 1 ;
@ -1440,17 +1458,7 @@ void delete_maneuver_from_dialog(SimulationState* sim, UIState* ui_state) {
}
void ui_state_init_buffers ( UIState * ui_state ) {
ui_state - > cached_body_count = 0 ;
ui_state - > cached_craft_count = 0 ;
ui_state - > cached_maneuver_count = 0 ;
ui_state - > body_list_buffer_size = 0 ;
ui_state - > body_list_buffer = NULL ;
ui_state - > craft_list_buffer_size = 0 ;
ui_state - > craft_list_buffer = NULL ;
ui_state - > body_dropdown_buffer_size = 0 ;
ui_state - > body_dropdown_buffer = NULL ;
ui_state - > maneuver_list_buffer_size = 0 ;
ui_state - > maneuver_list_buffer = NULL ;
* ui_state = ( UIState ) { 0 } ;
}
void ui_state_free_buffers ( UIState * ui_state ) {