diff --git a/4coder_base_types.h b/4coder_base_types.h index 7e4fd58e..47fcb4f3 100644 --- a/4coder_base_types.h +++ b/4coder_base_types.h @@ -103,6 +103,10 @@ typedef double f64; #define GB(x) (((umem)x) << 30) #define TB(x) (((umem)x) << 40) +#define Thousand(x) (x*1000) +#define Million(x) (x*1000000) +#define Billion(x) (x*1000000000) + #define max_i8 ((i8)0x7F) #define max_i16 ((i16)0x7FFF) #define max_i32 ((i32)0x7FFFFFFF) diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index bc56cb54..5ab18a3f 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -324,14 +324,14 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa f32 line_height = view.line_height; - Arena arena = make_arena(app); + Arena *arena = context_get_arena(app); + Temp_Memory_Arena temp = begin_temp_memory(arena); + static Managed_Scope render_scope = 0; if (render_scope == 0){ render_scope = create_user_managed_scope(app); } - Partition *scratch = &global_part; - { Rect_f32 r_cursor = f32R(view.render_region); @@ -349,34 +349,34 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa Fancy_Color base_color = fancy_id(Stag_Base); Fancy_Color pop2_color = fancy_id(Stag_Pop2); - Temp_Memory_Arena temp = begin_temp_memory(&arena); + Temp_Memory_Arena temp = begin_temp_memory(arena); Fancy_String_List list = {}; #if 0 // NOTE(allen): this is just an example of using base names instead of buffer names. i32 buffer_name_size = 0; buffer_get_base_buffer_name(app, buffer.buffer_id, 0, &buffer_name_size); - char *space = push_array(&arena, char, buffer_name_size); + char *space = push_array(arena, char, buffer_name_size); String string = make_string_cap(space, 0, buffer_name_size); buffer_get_base_buffer_name(app, buffer.buffer_id, &string, 0); - push_fancy_string (&arena, &list, base_color, string); + push_fancy_string (arena, &list, base_color, string); #else - push_fancy_string (&arena, &list, base_color, make_string(buffer.buffer_name, buffer.buffer_name_len)); + push_fancy_string (arena, &list, base_color, make_string(buffer.buffer_name, buffer.buffer_name_len)); #endif - push_fancy_stringf(&arena, &list, base_color, " - L#%d C#%d -", view.cursor.line, view.cursor.character); + push_fancy_stringf(arena, &list, base_color, " - L#%d C#%d -", view.cursor.line, view.cursor.character); b32 is_dos_mode = false; if (buffer_get_setting(app, buffer.buffer_id, BufferSetting_Eol, &is_dos_mode)){ if (is_dos_mode){ - push_fancy_string(&arena, &list, base_color, make_lit_string(" dos")); + push_fancy_string(arena, &list, base_color, make_lit_string(" dos")); } else{ - push_fancy_string(&arena, &list, base_color, make_lit_string(" nix")); + push_fancy_string(arena, &list, base_color, make_lit_string(" nix")); } } else{ - push_fancy_string(&arena, &list, base_color, make_lit_string(" ???")); + push_fancy_string(arena, &list, base_color, make_lit_string(" ???")); } { @@ -392,7 +392,7 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa if (HasFlag(dirty, DirtyState_UnloadedChanges)){ append(&str, "!"); } - push_fancy_string(&arena, &list, pop2_color, str); + push_fancy_string(arena, &list, pop2_color, str); } Face_ID font_id = 0; @@ -418,14 +418,14 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa bar.y1 = bar.y0 + line_height + 2.f; r_cursor.y0 = bar.y1; - Temp_Memory_Arena temp = begin_temp_memory(&arena); + Temp_Memory_Arena temp = begin_temp_memory(arena); Fancy_String_List list = {}; Fancy_Color default_color = fancy_id(Stag_Default); Fancy_Color pop1_color = fancy_id(Stag_Pop1); - push_fancy_string(&arena, &list, pop1_color , query_bar->prompt); - push_fancy_string(&arena, &list, default_color, query_bar->string); + push_fancy_string(arena, &list, pop1_color , query_bar->prompt); + push_fancy_string(arena, &list, default_color, query_bar->string); Face_ID font_id = 0; get_face_id(app, view.buffer_id, &font_id); @@ -461,8 +461,8 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa Vec2 p = panel_space_from_view_space(cursor.wrapped_p, view.scroll_vars.scroll_p); p += V2(render_params.buffer_region.p0); p.x = left_margin.x0; - Temp_Memory_Arena temp = begin_temp_memory(&arena); - Fancy_String *line_string = push_fancy_stringf(&arena, line_color, "%*d", line_count_digit_count, cursor.line); + Temp_Memory_Arena temp = begin_temp_memory(arena); + Fancy_String *line_string = push_fancy_stringf(arena, line_color, "%*d", line_count_digit_count, cursor.line); draw_fancy_string(app, font_id, line_string, p, Stag_Margin_Active, 0); end_temp_memory(temp); i32 next_line = cursor.line + 1; @@ -476,6 +476,8 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa } } + // TODO(allen): eliminate scratch partition usage + Partition *scratch = &global_part; // NOTE(allen): Scan for TODOs and NOTEs { Temp_Memory temp = begin_temp_memory(scratch); @@ -560,8 +562,9 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa Marker_Visual visual = create_marker_visual(app, cursor_and_mark); Marker_Visual_Type type = is_active_view?VisualType_CharacterBlocks:VisualType_CharacterWireFrames; + int_color cursor_color = Stag_Cursor; int_color text_color = is_active_view?Stag_At_Cursor:Stag_Default; - marker_visual_set_effect(app, visual, type, Stag_Cursor, text_color, 0); + marker_visual_set_effect(app, visual, type, cursor_color, text_color, 0); marker_visual_set_take_rule(app, visual, take_rule); marker_visual_set_priority(app, visual, VisualPriority_Highest); @@ -705,30 +708,29 @@ default_buffer_render_caller(Application_Links *app, Render_Parameters render_pa Fancy_Color pink = fancy_rgba(1.f, 0.f, 1.f, 1.f); Fancy_Color green = fancy_rgba(0.f, 1.f, 0.f, 1.f); Fancy_String_List list = {}; - push_fancy_stringf(&arena, &list, pink , "FPS: "); - push_fancy_stringf(&arena, &list, green, "["); - push_fancy_stringf(&arena, &list, white, "%5d", frame_index); - push_fancy_stringf(&arena, &list, green, "]: "); + push_fancy_stringf(arena, &list, pink , "FPS: "); + push_fancy_stringf(arena, &list, green, "["); + push_fancy_stringf(arena, &list, white, "%5d", frame_index); + push_fancy_stringf(arena, &list, green, "]: "); for (i32 k = 0; k < 2; k += 1){ f32 dt = dts[k]; str.size = 0; if (dt == 0.f){ - push_fancy_stringf(&arena, &list, white, "-----"); + push_fancy_stringf(arena, &list, white, "-----"); } else{ - push_fancy_stringf(&arena, &list, white, "%5d", round32(1.f/dt)); + push_fancy_stringf(arena, &list, white, "%5d", round32(1.f/dt)); } - push_fancy_stringf(&arena, &list, green, " | "); + push_fancy_stringf(arena, &list, green, " | "); } draw_fancy_string(app, font_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f)); - } } } - arena_release_all(&arena); + end_temp_memory(temp); managed_scope_clear_self_all_dependent_scopes(app, render_scope); } diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index e43bfbca..6fa4f2bf 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -155,7 +155,7 @@ struct Application_Links; #define DRAW_CLIP_POP_SIG(n) f32_Rect n(Application_Links *app) #define GET_DEFAULT_FONT_FOR_VIEW_SIG(n) Face_ID n(Application_Links *app, View_ID view_id) #define OPEN_COLOR_PICKER_SIG(n) void n(Application_Links *app, color_picker *picker) -#define ANIMATE_SIG(n) void n(Application_Links *app) +#define ANIMATE_IN_N_MILLISECONDS_SIG(n) void n(Application_Links *app, u32 n) #define FIND_ALL_IN_RANGE_INSENSITIVE_SIG(n) Found_String_List n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory) #define GET_VIEW_VISIBLE_RANGE_SIG(n) Range n(Application_Links *app, View_ID view_id) typedef GLOBAL_SET_SETTING_SIG(Global_Set_Setting_Function); @@ -314,7 +314,7 @@ typedef DRAW_CLIP_PUSH_SIG(Draw_Clip_Push_Function); typedef DRAW_CLIP_POP_SIG(Draw_Clip_Pop_Function); typedef GET_DEFAULT_FONT_FOR_VIEW_SIG(Get_Default_Font_For_View_Function); typedef OPEN_COLOR_PICKER_SIG(Open_Color_Picker_Function); -typedef ANIMATE_SIG(Animate_Function); +typedef ANIMATE_IN_N_MILLISECONDS_SIG(Animate_In_N_Milliseconds_Function); typedef FIND_ALL_IN_RANGE_INSENSITIVE_SIG(Find_All_In_Range_Insensitive_Function); typedef GET_VIEW_VISIBLE_RANGE_SIG(Get_View_Visible_Range_Function); struct Application_Links{ @@ -475,7 +475,7 @@ Draw_Clip_Push_Function *draw_clip_push; Draw_Clip_Pop_Function *draw_clip_pop; Get_Default_Font_For_View_Function *get_default_font_for_view; Open_Color_Picker_Function *open_color_picker; -Animate_Function *animate; +Animate_In_N_Milliseconds_Function *animate_in_n_milliseconds; Find_All_In_Range_Insensitive_Function *find_all_in_range_insensitive; Get_View_Visible_Range_Function *get_view_visible_range; #else @@ -635,7 +635,7 @@ Draw_Clip_Push_Function *draw_clip_push_; Draw_Clip_Pop_Function *draw_clip_pop_; Get_Default_Font_For_View_Function *get_default_font_for_view_; Open_Color_Picker_Function *open_color_picker_; -Animate_Function *animate_; +Animate_In_N_Milliseconds_Function *animate_in_n_milliseconds_; Find_All_In_Range_Insensitive_Function *find_all_in_range_insensitive_; Get_View_Visible_Range_Function *get_view_visible_range_; #endif @@ -803,7 +803,7 @@ app_links->draw_clip_push_ = Draw_Clip_Push;\ app_links->draw_clip_pop_ = Draw_Clip_Pop;\ app_links->get_default_font_for_view_ = Get_Default_Font_For_View;\ app_links->open_color_picker_ = Open_Color_Picker;\ -app_links->animate_ = Animate;\ +app_links->animate_in_n_milliseconds_ = Animate_In_N_Milliseconds;\ app_links->find_all_in_range_insensitive_ = Find_All_In_Range_Insensitive;\ app_links->get_view_visible_range_ = Get_View_Visible_Range;} while(false) #if defined(ALLOW_DEP_4CODER) @@ -963,7 +963,7 @@ static void draw_clip_push(Application_Links *app, f32_Rect clip_box){(app->draw static f32_Rect draw_clip_pop(Application_Links *app){return(app->draw_clip_pop(app));} static Face_ID get_default_font_for_view(Application_Links *app, View_ID view_id){return(app->get_default_font_for_view(app, view_id));} static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker(app, picker));} -static void animate(Application_Links *app){(app->animate(app));} +static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds(app, n));} static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory){return(app->find_all_in_range_insensitive(app, buffer_id, start, end, key, memory));} static Range get_view_visible_range(Application_Links *app, View_ID view_id){return(app->get_view_visible_range(app, view_id));} #else @@ -1123,7 +1123,7 @@ static void draw_clip_push(Application_Links *app, f32_Rect clip_box){(app->draw static f32_Rect draw_clip_pop(Application_Links *app){return(app->draw_clip_pop_(app));} static Face_ID get_default_font_for_view(Application_Links *app, View_ID view_id){return(app->get_default_font_for_view_(app, view_id));} static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker_(app, picker));} -static void animate(Application_Links *app){(app->animate_(app));} +static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds_(app, n));} static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory){return(app->find_all_in_range_insensitive_(app, buffer_id, start, end, key, memory));} static Range get_view_visible_range(Application_Links *app, View_ID view_id){return(app->get_view_visible_range_(app, view_id));} #endif diff --git a/4ed.cpp b/4ed.cpp index b7eede6c..69221377 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -768,7 +768,7 @@ force_abort_coroutine(System_Functions *system, Models *models, View *view){ } internal void -launch_command_via_event(System_Functions *system, Application_Step_Result *app_result, Models *models, View *view, Key_Event_Data event){ +launch_command_via_event(System_Functions *system, Models *models, View *view, Key_Event_Data event){ models->key = event; i32 map = view_get_map(view); @@ -787,16 +787,16 @@ launch_command_via_event(System_Functions *system, Application_Step_Result *app_ models->prev_command = cmd_bind; if (event.keycode != key_animate){ - app_result->animating = true; + models->animate_next_frame = true; } } } internal void -launch_command_via_keycode(System_Functions *system, Application_Step_Result *app_result, Models *models, View *view, Key_Code keycode){ +launch_command_via_keycode(System_Functions *system, Models *models, View *view, Key_Code keycode){ Key_Event_Data event = {}; event.keycode = keycode; - launch_command_via_event(system, app_result, models, view, event); + launch_command_via_event(system, models, view, event); } App_Read_Command_Line_Sig(app_read_command_line){ @@ -937,17 +937,12 @@ App_Init_Sig(app_init){ view_set_file(system, models, new_view, models->scratch_buffer); } - // NOTE(allen): hot directory + // NOTE(allen): miscellaneous init hot_directory_init(&models->hot_directory, current_directory); - - // NOTE(allen): child process container child_process_container_init(&models->child_processes, models); - - // NOTE(allen): init GUI keys models->user_up_key = key_up; models->user_down_key = key_down; - - // NOTE(allen): + models->period_wakeup_timer = system->wake_up_timer_create(); models->custom_layer_arena = make_arena(&models->app_links); } @@ -955,9 +950,7 @@ App_Step_Sig(app_step){ App_Vars *vars = (App_Vars*)memory->vars_memory; Models *models = &vars->models; - Application_Step_Result app_result = {}; - app_result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT; - app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr; + models->next_animate_delay = max_u32; models->animate_next_frame = false; // NOTE(allen): per-frame update of models state @@ -1236,7 +1229,7 @@ App_Step_Sig(app_step){ } // NOTE(allen): run deactivate command - launch_command_via_keycode(system, &app_result, models, view, key_click_deactivate_view); + launch_command_via_keycode(system, models, view, key_click_deactivate_view); // NOTE(allen): kill coroutine if we have one (again because we just launched a command) if (models->command_coroutine != 0){ @@ -1244,12 +1237,12 @@ App_Step_Sig(app_step){ } layout->active_panel = mouse_panel; - app_result.animating = true; + models->animate_next_frame = true; active_panel = mouse_panel; view = active_panel->view; // NOTE(allen): run activate command - launch_command_via_keycode(system, &app_result, models, view, key_click_activate_view); + launch_command_via_keycode(system, models, view, key_click_activate_view); }break; case EventConsume_Command: @@ -1275,7 +1268,7 @@ App_Step_Sig(app_step){ models->command_coroutine = app_resume_coroutine(system, &models->app_links, Co_Command, command_coroutine, &user_in, models->command_coroutine_flags); if (user_in.key.keycode != key_animate){ - app_result.animating = true; + models->animate_next_frame = true; } if (models->command_coroutine == 0){ @@ -1286,11 +1279,10 @@ App_Step_Sig(app_step){ // NOTE(allen): launch command else{ - launch_command_via_event(system, &app_result, models, view, *key_ptr); + launch_command_via_event(system, models, view, *key_ptr); } }break; } - }break; case APP_STATE_RESIZING: @@ -1440,7 +1432,7 @@ App_Step_Sig(app_step){ Hook_Function *exit_func = models->hooks[hook_exit]; if (exit_func != 0){ if (exit_func(&models->app_links) == 0){ - app_result.animating = true; + models->animate_next_frame = true; models->keep_playing = true; } } @@ -1522,6 +1514,11 @@ App_Step_Sig(app_step){ end_render_section(target, system); } + // NOTE(allen): set the app_result + Application_Step_Result app_result = {}; + app_result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT; + app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr; + // NOTE(allen): get new window title if (models->has_new_title){ models->has_new_title = false; @@ -1546,11 +1543,17 @@ App_Step_Sig(app_step){ } models->prev_mouse_panel = mouse_panel; - app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr; app_result.perform_kill = !models->keep_playing; - // TODO(allen): whenever something wants to animate it should set animate_next_frame now. - app_result.animating = app_result.animating || models->animate_next_frame; + app_result.animating = models->animate_next_frame; + if (models->animate_next_frame){ + // NOTE(allen): Silence the timer, because we're going to do another frame right away anyways. + system->wake_up_timer_set(models->period_wakeup_timer, max_u32); + } + else{ + // NOTE(allen): Set the timer's wakeup period, possibly to max_u32 thus effectively silencing it. + system->wake_up_timer_set(models->period_wakeup_timer, models->next_animate_delay); + } // NOTE(allen): Update Frame to Frame States models->prev_p = input->mouse.p; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index b0b4dd6a..8a3cecc7 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -4484,10 +4484,15 @@ DOC(Opens a color picker using the parameters in the supplied structure.) } API_EXPORT void -Animate(Application_Links *app) +Animate_In_N_Milliseconds(Application_Links *app, u32 n) { Models *models = (Models*)app->cmd_context; - models->animate_next_frame = true; + if (n == 0){ + models->animate_next_frame = true; + } + else{ + models->next_animate_delay = Min(models->next_animate_delay, n); + } } // NOTE(casey): Find_All_In_Range_Insensitive is the only routine supplied, because anyone who would prefer case-sensitive can diff --git a/4ed_app_models.h b/4ed_app_models.h index 6b503ecf..e126ad07 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -92,12 +92,13 @@ struct Models{ char *title_space; i32 title_capacity; - u32 edit_finished_hook_repeat_speed; - - i32 frame_counter; - Panel *resizing_intermediate_panel; + u32 edit_finished_hook_repeat_speed; + + Plat_Handle period_wakeup_timer; + i32 frame_counter; + u32 next_animate_delay; b32 animate_next_frame; Arena custom_layer_arena; diff --git a/4ed_system.h b/4ed_system.h index e2f054d4..1d79c4c0 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -75,9 +75,6 @@ typedef Sys_Wake_Up_Timer_Set_Sig(System_Wake_Up_Timer_Set); #define Sys_Wake_Up_Timer_Check_Sig(name) u64 name(Plat_Handle handle) typedef Sys_Wake_Up_Timer_Check_Sig(System_Wake_Up_Timer_Check); -#define Sys_Animate_Sig(name) void name() -typedef Sys_Animate_Sig(System_Animate); - // clipboard #define Sys_Post_Clipboard_Sig(name) void name(String str) typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard); @@ -253,7 +250,6 @@ struct System_Functions{ System_Wake_Up_Timer_Create *wake_up_timer_create; System_Wake_Up_Timer_Release *wake_up_timer_release; System_Wake_Up_Timer_Set *wake_up_timer_set; - System_Animate *animate; // clipboard: 1 System_Post_Clipboard *post_clipboard; diff --git a/platform_all/4ed_link_system_functions.cpp b/platform_all/4ed_link_system_functions.cpp index 9f448146..83ab30f8 100644 --- a/platform_all/4ed_link_system_functions.cpp +++ b/platform_all/4ed_link_system_functions.cpp @@ -33,7 +33,6 @@ link_system_code(){ SYSLINK(wake_up_timer_set); SYSLINK(post_clipboard); - SYSLINK(animate); SYSLINK(create_coroutine); SYSLINK(launch_coroutine); diff --git a/platform_win32/win32_4ed_functions.cpp b/platform_win32/win32_4ed_functions.cpp index 5eb340dc..7d96c138 100644 --- a/platform_win32/win32_4ed_functions.cpp +++ b/platform_win32/win32_4ed_functions.cpp @@ -588,10 +588,5 @@ Sys_Open_Color_Picker_Sig(system_open_color_picker){ CloseHandle(ThreadHandle); } -internal -Sys_Animate_Sig(system_animate){ - system_schedule_step(); -}; - // BOTTOM diff --git a/windows_scripts/setup_cl_generic.bat b/windows_scripts/setup_cl_generic.bat index 4c02ed2c..b6547aa9 100644 --- a/windows_scripts/setup_cl_generic.bat +++ b/windows_scripts/setup_cl_generic.bat @@ -2,7 +2,7 @@ REM (allen): quit early if we already have cl where /q cl -IF %ERRORLEVEL% EQU 0 (EXIT /b) +IF %ERRORLEVEL% == 0 (EXIT /b) SET "LIB="