context_get_arena

This commit is contained in:
Allen Webster 2019-03-29 14:21:50 -07:00
parent e4d07a3778
commit 580548f44f
7 changed files with 171 additions and 151 deletions

View File

@ -179,8 +179,8 @@ get_next_view_after_active(Application_Links *app, u32 access){
static void static void
view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 count){ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 count){
if (count > 0){ if (count > 0){
// TODO(allen): replace with context supplied arena Arena *arena = context_get_arena(app);
Arena arena = make_arena(app); Temp_Memory_Arena temp = begin_temp_memory(arena);
struct View_Node{ struct View_Node{
View_Node *next; View_Node *next;
@ -200,7 +200,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32
View_Node *primary_view_last = 0; View_Node *primary_view_last = 0;
i32 available_view_count = 0; i32 available_view_count = 0;
primary_view_first = primary_view_last = push_array(&arena, View_Node, 1); primary_view_first = primary_view_last = push_array(arena, View_Node, 1);
primary_view_last->next = 0; primary_view_last->next = 0;
primary_view_last->view_id = view_id; primary_view_last->view_id = view_id;
available_view_count += 1; available_view_count += 1;
@ -209,7 +209,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32
if (view_id == first_view_id){ if (view_id == first_view_id){
break; break;
} }
View_Node *node = push_array(&arena, View_Node, 1); View_Node *node = push_array(arena, View_Node, 1);
primary_view_last->next = node; primary_view_last->next = node;
node->next = 0; node->next = 0;
node->view_id = view_id; node->view_id = view_id;
@ -225,7 +225,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32
} }
} }
arena_release_all(&arena); end_temp_memory(temp);
} }
} }

View File

@ -1,6 +1,7 @@
struct Application_Links; struct Application_Links;
#define GLOBAL_SET_SETTING_SIG(n) b32 n(Application_Links *app, Global_Setting_ID setting, i32 value) #define GLOBAL_SET_SETTING_SIG(n) b32 n(Application_Links *app, Global_Setting_ID setting, i32 value)
#define GLOBAL_SET_MAPPING_SIG(n) b32 n(Application_Links *app, void *data, i32 size) #define GLOBAL_SET_MAPPING_SIG(n) b32 n(Application_Links *app, void *data, i32 size)
#define CONTEXT_GET_ARENA_SIG(n) Arena* n(Application_Links *app)
#define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out) #define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out)
#define CHILD_PROCESS_SET_TARGET_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags) #define CHILD_PROCESS_SET_TARGET_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags)
#define BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out) #define BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out)
@ -158,6 +159,7 @@ struct Application_Links;
#define GET_VIEW_VISIBLE_RANGE_SIG(n) Range n(Application_Links *app, View_ID view_id) #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); typedef GLOBAL_SET_SETTING_SIG(Global_Set_Setting_Function);
typedef GLOBAL_SET_MAPPING_SIG(Global_Set_Mapping_Function); typedef GLOBAL_SET_MAPPING_SIG(Global_Set_Mapping_Function);
typedef CONTEXT_GET_ARENA_SIG(Context_Get_Arena_Function);
typedef CREATE_CHILD_PROCESS_SIG(Create_Child_Process_Function); typedef CREATE_CHILD_PROCESS_SIG(Create_Child_Process_Function);
typedef CHILD_PROCESS_SET_TARGET_BUFFER_SIG(Child_Process_Set_Target_Buffer_Function); typedef CHILD_PROCESS_SET_TARGET_BUFFER_SIG(Child_Process_Set_Target_Buffer_Function);
typedef BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(Buffer_Get_Attached_Child_Process_Function); typedef BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(Buffer_Get_Attached_Child_Process_Function);
@ -317,6 +319,7 @@ struct Application_Links{
#if defined(ALLOW_DEP_4CODER) #if defined(ALLOW_DEP_4CODER)
Global_Set_Setting_Function *global_set_setting; Global_Set_Setting_Function *global_set_setting;
Global_Set_Mapping_Function *global_set_mapping; Global_Set_Mapping_Function *global_set_mapping;
Context_Get_Arena_Function *context_get_arena;
Create_Child_Process_Function *create_child_process; Create_Child_Process_Function *create_child_process;
Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer; Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer;
Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process; Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process;
@ -475,6 +478,7 @@ Get_View_Visible_Range_Function *get_view_visible_range;
#else #else
Global_Set_Setting_Function *global_set_setting_; Global_Set_Setting_Function *global_set_setting_;
Global_Set_Mapping_Function *global_set_mapping_; Global_Set_Mapping_Function *global_set_mapping_;
Context_Get_Arena_Function *context_get_arena_;
Create_Child_Process_Function *create_child_process_; Create_Child_Process_Function *create_child_process_;
Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer_; Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer_;
Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process_; Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process_;
@ -641,6 +645,7 @@ int32_t type_coroutine;
#define FillAppLinksAPI(app_links) do{\ #define FillAppLinksAPI(app_links) do{\
app_links->global_set_setting_ = Global_Set_Setting;\ app_links->global_set_setting_ = Global_Set_Setting;\
app_links->global_set_mapping_ = Global_Set_Mapping;\ app_links->global_set_mapping_ = Global_Set_Mapping;\
app_links->context_get_arena_ = Context_Get_Arena;\
app_links->create_child_process_ = Create_Child_Process;\ app_links->create_child_process_ = Create_Child_Process;\
app_links->child_process_set_target_buffer_ = Child_Process_Set_Target_Buffer;\ app_links->child_process_set_target_buffer_ = Child_Process_Set_Target_Buffer;\
app_links->buffer_get_attached_child_process_ = Buffer_Get_Attached_Child_Process;\ app_links->buffer_get_attached_child_process_ = Buffer_Get_Attached_Child_Process;\
@ -799,6 +804,7 @@ app_links->get_view_visible_range_ = Get_View_Visible_Range;} while(false)
#if defined(ALLOW_DEP_4CODER) #if defined(ALLOW_DEP_4CODER)
static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting(app, setting, value));} static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting(app, setting, value));}
static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping(app, data, size));} static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping(app, data, size));}
static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena(app));}
static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process(app, path, command, child_process_id_out));} static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process(app, path, command, child_process_id_out));}
static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer(app, child_process_id, buffer_id, flags));} static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer(app, child_process_id, buffer_id, flags));}
static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process(app, buffer_id, child_process_id_out));} static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process(app, buffer_id, child_process_id_out));}
@ -957,6 +963,7 @@ static Range get_view_visible_range(Application_Links *app, View_ID view_id){ret
#else #else
static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting_(app, setting, value));} static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting_(app, setting, value));}
static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping_(app, data, size));} static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping_(app, data, size));}
static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena_(app));}
static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));} static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));}
static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer_(app, child_process_id, buffer_id, flags));} static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer_(app, child_process_id, buffer_id, flags));}
static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process_(app, buffer_id, child_process_id_out));} static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process_(app, buffer_id, child_process_id_out));}

View File

@ -262,116 +262,115 @@ mirror_add_range__inner_check_optimization(Application_Links *app, Managed_Objec
if (get_buffer_summary(app, source, AccessAll, &source_buffer)){ if (get_buffer_summary(app, source, AccessAll, &source_buffer)){
Managed_Scope scope = managed_object_get_containing_scope(app, mirror); Managed_Scope scope = managed_object_get_containing_scope(app, mirror);
Managed_Object mirror_check = mirror__check_scope_for_mirror(app, scope); Managed_Object mirror_check = mirror__check_scope_for_mirror(app, scope);
if (mirror_check == mirror){ Mirror mirror_data = {};
Mirror mirror_data = {}; if (mirror_check == mirror && managed_object_load_data(app, mirror, 0, 1, &mirror_data)){
if (managed_object_load_data(app, mirror, 0, 1, &mirror_data)){ Buffer_Summary mirror_buffer = {};
Buffer_Summary mirror_buffer = {}; Buffer_ID mirror_id = mirror_data.mirror_buffer_id;
Buffer_ID mirror_id = mirror_data.mirror_buffer_id; if (get_buffer_summary(app, mirror_id, AccessAll, &mirror_buffer)){
if (get_buffer_summary(app, mirror_id, AccessAll, &mirror_buffer)){ Arena *arena = context_get_arena(app);
Arena arena = make_arena(app, (8 << 10)); Temp_Memory_Arena temp = begin_temp_memory(arena);
// read mirror data into hot structure // read mirror data into hot structure
Mirror_Hot mirror_hot = {}; Mirror_Hot mirror_hot = {};
mirror_hot.count = mirror_data.count; mirror_hot.count = mirror_data.count;
mirror_hot.source_buffer_ids = push_array(&arena, Buffer_ID, mirror_hot.count); mirror_hot.source_buffer_ids = push_array(arena, Buffer_ID, mirror_hot.count);
mirror_hot.mirror_ranges = push_array(&arena, Marker, (mirror_hot.count)*2); mirror_hot.mirror_ranges = push_array(arena, Marker, (mirror_hot.count)*2);
mirror_hot.source_ranges = push_array(&arena, Managed_Object, mirror_hot.count); mirror_hot.source_ranges = push_array(arena, Managed_Object, mirror_hot.count);
b32 load_success = false; b32 load_success = false;
if (mirror_hot.count == 0){ if (mirror_hot.count == 0){
load_success = true; load_success = true;
}
else{
load_success = (managed_object_load_data(app, mirror_data.source_buffer_ids, 0, mirror_hot.count , mirror_hot.source_buffer_ids) &&
managed_object_load_data(app, mirror_data.mirror_ranges , 0, mirror_hot.count*2, mirror_hot.mirror_ranges ) &&
managed_object_load_data(app, mirror_data.source_ranges , 0, mirror_hot.count , mirror_hot.source_ranges ));
}
if (load_success){
Mirror__Check_Range_Result check = mirror__check_range_to_add(app, &arena, mirror_first, source_first, length,
&source_buffer, &mirror_buffer, &mirror_hot,
collidable_indices_first, auto_trust_text);
if (check.passed_checks){
// insert the new range at the insert index
b32 r = true;
i32 insert_index = check.insert_index;
*insert_index_out = insert_index;
Marker mirror_range[2] = {};
mirror_range[0].pos = mirror_first;
mirror_range[0].lean_right = false;
mirror_range[1].pos = mirror_first + length;
mirror_range[1].lean_right = true;
Marker source_range[2] = {};
source_range[0].pos = source_first;
source_range[0].lean_right = false;
source_range[1].pos = source_first + length;
source_range[1].lean_right = true;
Managed_Scope scopes[3] = {};
scopes[0] = scope;
scopes[1] = mirror_data.mirror_scope;
buffer_get_managed_scope(app, source, &scopes[2]);
Managed_Scope source_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 3);
Managed_Object new_source_range = alloc_buffer_markers_on_buffer(app, source, 2, &source_sub_scope);
r = r && managed_object_store_data(app, new_source_range, 0, 2, &source_range);
if (mirror_data.count + 1 > mirror_data.max){
if (mirror_data.count != 0){
r = r && managed_object_free(app, mirror_data.source_buffer_ids);
r = r && managed_object_free(app, mirror_data.mirror_ranges);
r = r && managed_object_free(app, mirror_data.source_ranges);
}
Managed_Scope mirror_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 2);
i32 new_max = 256;
if (new_max <= mirror_data.max){
new_max = mirror_data.max*2;
}
mirror_data.source_buffer_ids = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Buffer_ID), new_max);
mirror_data.mirror_ranges = alloc_buffer_markers_on_buffer(app, mirror_id, new_max*2, &mirror_sub_scope);
mirror_data.source_ranges = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Managed_Object), new_max);
mirror_data.max = new_max;
// head ranges
i32 head_count = insert_index;
if (head_count > 0){
r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, 0, head_count , mirror_hot.source_buffer_ids);
r = r && managed_object_store_data(app, mirror_data.mirror_ranges , 0, head_count*2, mirror_hot.mirror_ranges );
r = r && managed_object_store_data(app, mirror_data.source_ranges , 0, head_count , mirror_hot.source_ranges );
}
}
// tail ranges
i32 tail_count = mirror_hot.count - insert_index;
if (tail_count > 0){
i32 to = insert_index + 1;
i32 from = insert_index;
r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, to , tail_count , mirror_hot.source_buffer_ids + from);
r = r && managed_object_store_data(app, mirror_data.mirror_ranges , to*2, tail_count*2, mirror_hot.mirror_ranges + from*2 );
r = r && managed_object_store_data(app, mirror_data.source_ranges , to , tail_count , mirror_hot.source_ranges + from );
}
// new range
r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, insert_index , 1, &source );
r = r && managed_object_store_data(app, mirror_data.mirror_ranges , insert_index*2, 2, mirror_range );
r = r && managed_object_store_data(app, mirror_data.source_ranges , insert_index , 1, &new_source_range);
mirror_data.count += 1;
managed_object_store_data(app, mirror, 0, 1, &mirror_data);
result = r;
}
}
arena_release_all(&arena);
} }
else{
load_success = (managed_object_load_data(app, mirror_data.source_buffer_ids, 0, mirror_hot.count , mirror_hot.source_buffer_ids) &&
managed_object_load_data(app, mirror_data.mirror_ranges , 0, mirror_hot.count*2, mirror_hot.mirror_ranges ) &&
managed_object_load_data(app, mirror_data.source_ranges , 0, mirror_hot.count , mirror_hot.source_ranges ));
}
if (load_success){
Mirror__Check_Range_Result check = mirror__check_range_to_add(app, arena, mirror_first, source_first, length,
&source_buffer, &mirror_buffer, &mirror_hot,
collidable_indices_first, auto_trust_text);
if (check.passed_checks){
// insert the new range at the insert index
b32 r = true;
i32 insert_index = check.insert_index;
*insert_index_out = insert_index;
Marker mirror_range[2] = {};
mirror_range[0].pos = mirror_first;
mirror_range[0].lean_right = false;
mirror_range[1].pos = mirror_first + length;
mirror_range[1].lean_right = true;
Marker source_range[2] = {};
source_range[0].pos = source_first;
source_range[0].lean_right = false;
source_range[1].pos = source_first + length;
source_range[1].lean_right = true;
Managed_Scope scopes[3] = {};
scopes[0] = scope;
scopes[1] = mirror_data.mirror_scope;
buffer_get_managed_scope(app, source, &scopes[2]);
Managed_Scope source_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 3);
Managed_Object new_source_range = alloc_buffer_markers_on_buffer(app, source, 2, &source_sub_scope);
r = r && managed_object_store_data(app, new_source_range, 0, 2, &source_range);
if (mirror_data.count + 1 > mirror_data.max){
if (mirror_data.count != 0){
r = r && managed_object_free(app, mirror_data.source_buffer_ids);
r = r && managed_object_free(app, mirror_data.mirror_ranges);
r = r && managed_object_free(app, mirror_data.source_ranges);
}
Managed_Scope mirror_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 2);
i32 new_max = 256;
if (new_max <= mirror_data.max){
new_max = mirror_data.max*2;
}
mirror_data.source_buffer_ids = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Buffer_ID), new_max);
mirror_data.mirror_ranges = alloc_buffer_markers_on_buffer(app, mirror_id, new_max*2, &mirror_sub_scope);
mirror_data.source_ranges = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Managed_Object), new_max);
mirror_data.max = new_max;
// head ranges
i32 head_count = insert_index;
if (head_count > 0){
r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, 0, head_count , mirror_hot.source_buffer_ids);
r = r && managed_object_store_data(app, mirror_data.mirror_ranges , 0, head_count*2, mirror_hot.mirror_ranges );
r = r && managed_object_store_data(app, mirror_data.source_ranges , 0, head_count , mirror_hot.source_ranges );
}
}
// tail ranges
i32 tail_count = mirror_hot.count - insert_index;
if (tail_count > 0){
i32 to = insert_index + 1;
i32 from = insert_index;
r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, to , tail_count , mirror_hot.source_buffer_ids + from);
r = r && managed_object_store_data(app, mirror_data.mirror_ranges , to*2, tail_count*2, mirror_hot.mirror_ranges + from*2 );
r = r && managed_object_store_data(app, mirror_data.source_ranges , to , tail_count , mirror_hot.source_ranges + from );
}
// new range
r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, insert_index , 1, &source );
r = r && managed_object_store_data(app, mirror_data.mirror_ranges , insert_index*2, 2, mirror_range );
r = r && managed_object_store_data(app, mirror_data.source_ranges , insert_index , 1, &new_source_range);
mirror_data.count += 1;
managed_object_store_data(app, mirror, 0, 1, &mirror_data);
result = r;
}
}
end_temp_memory(temp);
} }
} }
} }
@ -553,9 +552,10 @@ static i32
mirror__range_loose_get_length(Application_Links *app, Buffer_ID mirror, Buffer_ID source, mirror__range_loose_get_length(Application_Links *app, Buffer_ID mirror, Buffer_ID source,
i32 mirror_first, i32 source_first, i32 max_length){ i32 mirror_first, i32 source_first, i32 max_length){
i32 result = 0; i32 result = 0;
Arena arena = make_arena(app, (8 << 10)); Arena *arena = context_get_arena(app);
char *buffer_1 = push_array(&arena, char, max_length); Temp_Memory_Arena temp = begin_temp_memory(arena);
char *buffer_2 = push_array(&arena, char, max_length); char *buffer_1 = push_array(arena, char, max_length);
char *buffer_2 = push_array(arena, char, max_length);
if (buffer_read_range(app, source, source_first, source_first + max_length, buffer_1)){ if (buffer_read_range(app, source, source_first, source_first + max_length, buffer_1)){
if (buffer_read_range(app, mirror, mirror_first, mirror_first + max_length, buffer_2)){ if (buffer_read_range(app, mirror, mirror_first, mirror_first + max_length, buffer_2)){
for (; result < max_length; for (; result < max_length;
@ -566,7 +566,7 @@ mirror__range_loose_get_length(Application_Links *app, Buffer_ID mirror, Buffer_
} }
} }
} }
arena_release_all(&arena); end_temp_memory(temp);
return(result); return(result);
} }
@ -597,18 +597,16 @@ mirror_buffer_insert_range(Application_Links *app, Buffer_ID mirror, Buffer_ID s
if (mode == MirrorMode_Constructing){ if (mode == MirrorMode_Constructing){
b32 did_insert = false; b32 did_insert = false;
{ {
// TODO(casey): Allen, this is going to be suuuuuper slow - it has to do a whole memory block Arena *arena = context_get_arena(app);
// reserve just to get the temporary space. This is the kind of thing that would be super simple and Temp_Memory_Arena temp = begin_temp_memory(arena);
// very efficient with a stack off the app pointer. char *buffer = push_array(arena, char, length);
Arena arena = make_arena(app, (8 << 10));
char *buffer = push_array(&arena, char, length);
if (buffer_read_range(app, source, source_first, source_first + length, buffer)){ if (buffer_read_range(app, source, source_first, source_first + length, buffer)){
String string = make_string(buffer, length); String string = make_string(buffer, length);
if (buffer_replace_range(app, mirror, mirror_insert_pos, mirror_insert_pos, string)){ if (buffer_replace_range(app, mirror, mirror_insert_pos, mirror_insert_pos, string)){
did_insert = true; did_insert = true;
} }
} }
arena_release_all(&arena); end_temp_memory(temp);
} }
if (did_insert){ if (did_insert){
result = mirror_add_range__inner(app, mirror_object, source, mirror_insert_pos, source_first, length); result = mirror_add_range__inner(app, mirror_object, source, mirror_insert_pos, source_first, length);
@ -798,20 +796,21 @@ mirror_buffer_insert_range_array(Application_Links *app, Buffer_ID mirror, Mirro
Mirror_Range *range = ranges; Mirror_Range *range = ranges;
i32 safe_to_ignore_index = 0; i32 safe_to_ignore_index = 0;
i32 total_shift = 0; i32 total_shift = 0;
Arena arena = make_arena(app, (8 << 10)); Arena *arena = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(arena);
for (i32 i = 0; i < count; i += 1, range += 1){ for (i32 i = 0; i < count; i += 1, range += 1){
i32 mirror_first = range->mirror_first + total_shift; i32 mirror_first = range->mirror_first + total_shift;
b32 did_insert = false; b32 did_insert = false;
{ {
Temp_Memory_Arena temp = begin_temp_memory(&arena); Temp_Memory_Arena buffer_temp = begin_temp_memory(arena);
char *buffer = push_array(&arena, char, range->length); char *buffer = push_array(arena, char, range->length);
if (buffer_read_range(app, range->source_buffer_id, range->source_first, range->source_first + range->length, buffer)){ if (buffer_read_range(app, range->source_buffer_id, range->source_first, range->source_first + range->length, buffer)){
String string = make_string(buffer, range->length); String string = make_string(buffer, range->length);
if (buffer_replace_range(app, mirror, mirror_first, mirror_first, string)){ if (buffer_replace_range(app, mirror, mirror_first, mirror_first, string)){
did_insert = true; did_insert = true;
} }
} }
end_temp_memory(temp); end_temp_memory(buffer_temp);
} }
i32 new_range_index = 0; i32 new_range_index = 0;
if (range->length > 0){ if (range->length > 0){
@ -826,7 +825,7 @@ mirror_buffer_insert_range_array(Application_Links *app, Buffer_ID mirror, Mirro
} }
total_shift += range->length; total_shift += range->length;
} }
arena_release_all(&arena); end_temp_memory(temp);
result = r; result = r;
} }
} }
@ -849,9 +848,10 @@ mirror_edit_handler(Application_Links *app, Buffer_ID buffer_id, i32 first, i32
if (mirror_get_mode__inner(app, mirror, &mode)){ if (mirror_get_mode__inner(app, mirror, &mode)){
Mirror mirror_data = {}; Mirror mirror_data = {};
if (managed_object_load_data(app, mirror, 0, 1, &mirror_data)){ if (managed_object_load_data(app, mirror, 0, 1, &mirror_data)){
Arena arena = make_arena(app, (8 << 10)); Arena *arena = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(arena);
Mirror_Hot mirror_hot = mirror__hot_from_data(app, &arena, mirror_data); Mirror_Hot mirror_hot = mirror__hot_from_data(app, arena, mirror_data);
switch (mode){ switch (mode){
case MirrorMode_Constructing: case MirrorMode_Constructing:
{ {
@ -944,7 +944,7 @@ mirror_edit_handler(Application_Links *app, Buffer_ID buffer_id, i32 first, i32
}break; }break;
} }
arena_release_all(&arena); end_temp_memory(temp);
} }
} }
} }

View File

@ -946,6 +946,9 @@ App_Init_Sig(app_init){
// NOTE(allen): init GUI keys // NOTE(allen): init GUI keys
models->user_up_key = key_up; models->user_up_key = key_up;
models->user_down_key = key_down; models->user_down_key = key_down;
// NOTE(allen):
models->custom_layer_arena = make_arena(&models->app_links);
} }
App_Step_Sig(app_step){ App_Step_Sig(app_step){

View File

@ -190,6 +190,12 @@ DOC(Dumps away the previous mappings and instantiates the mappings described in
return(result); return(result);
} }
API_EXPORT Arena*
Context_Get_Arena(Application_Links *app){
Models *models = (Models*)app->cmd_context;
return(&models->custom_layer_arena);
}
API_EXPORT b32 API_EXPORT b32
Create_Child_Process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){ Create_Child_Process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){
Models *models = (Models*)app->cmd_context; Models *models = (Models*)app->cmd_context;

View File

@ -29,6 +29,7 @@ struct App_Settings{
struct Models{ struct Models{
Mem_Options mem; Mem_Options mem;
App_Settings settings; App_Settings settings;
Face_ID global_font_id; Face_ID global_font_id;
@ -81,6 +82,7 @@ struct Models{
b32 keep_playing; b32 keep_playing;
// TODO(allen): do(eliminate user_*_key* nonsense from the core)
Key_Code user_up_key; Key_Code user_up_key;
Key_Code user_down_key; Key_Code user_down_key;
Key_Modifier user_up_key_modifier; Key_Modifier user_up_key_modifier;
@ -98,6 +100,8 @@ struct Models{
b32 animate_next_frame; b32 animate_next_frame;
Arena custom_layer_arena;
// Last frame state // Last frame state
Vec2_i32 prev_p; Vec2_i32 prev_p;
Panel *prev_mouse_panel; Panel *prev_mouse_panel;

View File

@ -144,33 +144,32 @@ history_is_activated(History *history){
internal void internal void
history_free(Heap *heap, History *history){ history_free(Heap *heap, History *history){
if (!history->activated){ if (history->activated){
return; arena_release_all(&history->arena);
memory_bank_free_all(heap, &history->bank);
block_zero_struct(history);
} }
arena_release_all(&history->arena);
memory_bank_free_all(heap, &history->bank);
block_zero_struct(history);
} }
internal i32 internal i32
history_get_record_count(History *history){ history_get_record_count(History *history){
if (!history->activated){ i32 result = 0;
return(0); if (history->activated){
result = history->record_count;
} }
return(history->record_count); return(result);
} }
internal Record* internal Record*
history_get_record(History *history, i32 index){ history_get_record(History *history, i32 index){
if (!history->activated){ Record *result = 0;
return(0); if (history->activated){
Node *node = history__to_node(history, index);
if (node != 0){
result = CastFromMember(Record, node, node);
}
} }
Record *record = 0; return(result);
Node *node = history__to_node(history, index);
if (node != 0){
record = CastFromMember(Record, node, node);
}
return(record);
} }
internal Record* internal Record*
@ -189,10 +188,11 @@ history_get_sub_record(Record *record, i32 sub_index){
internal Record* internal Record*
history_get_dummy_record(History *history){ history_get_dummy_record(History *history){
if (!history->activated){ Record *result = 0;
return(0); if (history->activated){
result = CastFromMember(Record, node, &history->records);
} }
return(CastFromMember(Record, node, &history->records)); return(result);
} }
internal void internal void