context_get_arena
This commit is contained in:
parent
e4d07a3778
commit
580548f44f
|
@ -179,8 +179,8 @@ get_next_view_after_active(Application_Links *app, u32 access){
|
|||
static void
|
||||
view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 count){
|
||||
if (count > 0){
|
||||
// TODO(allen): replace with context supplied arena
|
||||
Arena arena = make_arena(app);
|
||||
Arena *arena = context_get_arena(app);
|
||||
Temp_Memory_Arena temp = begin_temp_memory(arena);
|
||||
|
||||
struct View_Node{
|
||||
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;
|
||||
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->view_id = view_id;
|
||||
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){
|
||||
break;
|
||||
}
|
||||
View_Node *node = push_array(&arena, View_Node, 1);
|
||||
View_Node *node = push_array(arena, View_Node, 1);
|
||||
primary_view_last->next = node;
|
||||
node->next = 0;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
struct Application_Links;
|
||||
#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 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 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)
|
||||
|
@ -158,6 +159,7 @@ struct Application_Links;
|
|||
#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_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 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);
|
||||
|
@ -317,6 +319,7 @@ struct Application_Links{
|
|||
#if defined(ALLOW_DEP_4CODER)
|
||||
Global_Set_Setting_Function *global_set_setting;
|
||||
Global_Set_Mapping_Function *global_set_mapping;
|
||||
Context_Get_Arena_Function *context_get_arena;
|
||||
Create_Child_Process_Function *create_child_process;
|
||||
Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer;
|
||||
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
|
||||
Global_Set_Setting_Function *global_set_setting_;
|
||||
Global_Set_Mapping_Function *global_set_mapping_;
|
||||
Context_Get_Arena_Function *context_get_arena_;
|
||||
Create_Child_Process_Function *create_child_process_;
|
||||
Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer_;
|
||||
Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process_;
|
||||
|
@ -641,6 +645,7 @@ int32_t type_coroutine;
|
|||
#define FillAppLinksAPI(app_links) do{\
|
||||
app_links->global_set_setting_ = Global_Set_Setting;\
|
||||
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->child_process_set_target_buffer_ = Child_Process_Set_Target_Buffer;\
|
||||
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)
|
||||
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 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 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));}
|
||||
|
@ -957,6 +963,7 @@ static Range get_view_visible_range(Application_Links *app, View_ID view_id){ret
|
|||
#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_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 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));}
|
||||
|
|
|
@ -262,20 +262,20 @@ mirror_add_range__inner_check_optimization(Application_Links *app, Managed_Objec
|
|||
if (get_buffer_summary(app, source, AccessAll, &source_buffer)){
|
||||
Managed_Scope scope = managed_object_get_containing_scope(app, mirror);
|
||||
Managed_Object mirror_check = mirror__check_scope_for_mirror(app, scope);
|
||||
if (mirror_check == mirror){
|
||||
Mirror mirror_data = {};
|
||||
if (managed_object_load_data(app, mirror, 0, 1, &mirror_data)){
|
||||
if (mirror_check == mirror && managed_object_load_data(app, mirror, 0, 1, &mirror_data)){
|
||||
Buffer_Summary mirror_buffer = {};
|
||||
Buffer_ID mirror_id = mirror_data.mirror_buffer_id;
|
||||
if (get_buffer_summary(app, mirror_id, AccessAll, &mirror_buffer)){
|
||||
Arena arena = make_arena(app, (8 << 10));
|
||||
Arena *arena = context_get_arena(app);
|
||||
Temp_Memory_Arena temp = begin_temp_memory(arena);
|
||||
|
||||
// read mirror data into hot structure
|
||||
Mirror_Hot mirror_hot = {};
|
||||
mirror_hot.count = mirror_data.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.source_ranges = push_array(&arena, Managed_Object, 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.source_ranges = push_array(arena, Managed_Object, mirror_hot.count);
|
||||
|
||||
b32 load_success = false;
|
||||
if (mirror_hot.count == 0){
|
||||
|
@ -288,7 +288,7 @@ mirror_add_range__inner_check_optimization(Application_Links *app, Managed_Objec
|
|||
}
|
||||
|
||||
if (load_success){
|
||||
Mirror__Check_Range_Result check = mirror__check_range_to_add(app, &arena, mirror_first, source_first, length,
|
||||
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);
|
||||
|
||||
|
@ -370,8 +370,7 @@ mirror_add_range__inner_check_optimization(Application_Links *app, Managed_Objec
|
|||
}
|
||||
}
|
||||
|
||||
arena_release_all(&arena);
|
||||
}
|
||||
end_temp_memory(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -553,9 +552,10 @@ static i32
|
|||
mirror__range_loose_get_length(Application_Links *app, Buffer_ID mirror, Buffer_ID source,
|
||||
i32 mirror_first, i32 source_first, i32 max_length){
|
||||
i32 result = 0;
|
||||
Arena arena = make_arena(app, (8 << 10));
|
||||
char *buffer_1 = push_array(&arena, char, max_length);
|
||||
char *buffer_2 = push_array(&arena, char, max_length);
|
||||
Arena *arena = context_get_arena(app);
|
||||
Temp_Memory_Arena temp = begin_temp_memory(arena);
|
||||
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, mirror, mirror_first, mirror_first + max_length, buffer_2)){
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -597,18 +597,16 @@ mirror_buffer_insert_range(Application_Links *app, Buffer_ID mirror, Buffer_ID s
|
|||
if (mode == MirrorMode_Constructing){
|
||||
b32 did_insert = false;
|
||||
{
|
||||
// TODO(casey): Allen, this is going to be suuuuuper slow - it has to do a whole memory block
|
||||
// reserve just to get the temporary space. This is the kind of thing that would be super simple and
|
||||
// very efficient with a stack off the app pointer.
|
||||
Arena arena = make_arena(app, (8 << 10));
|
||||
char *buffer = push_array(&arena, char, length);
|
||||
Arena *arena = context_get_arena(app);
|
||||
Temp_Memory_Arena temp = begin_temp_memory(arena);
|
||||
char *buffer = push_array(arena, char, length);
|
||||
if (buffer_read_range(app, source, source_first, source_first + length, buffer)){
|
||||
String string = make_string(buffer, length);
|
||||
if (buffer_replace_range(app, mirror, mirror_insert_pos, mirror_insert_pos, string)){
|
||||
did_insert = true;
|
||||
}
|
||||
}
|
||||
arena_release_all(&arena);
|
||||
end_temp_memory(temp);
|
||||
}
|
||||
if (did_insert){
|
||||
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;
|
||||
i32 safe_to_ignore_index = 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){
|
||||
i32 mirror_first = range->mirror_first + total_shift;
|
||||
b32 did_insert = false;
|
||||
{
|
||||
Temp_Memory_Arena temp = begin_temp_memory(&arena);
|
||||
char *buffer = push_array(&arena, char, range->length);
|
||||
Temp_Memory_Arena buffer_temp = begin_temp_memory(arena);
|
||||
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)){
|
||||
String string = make_string(buffer, range->length);
|
||||
if (buffer_replace_range(app, mirror, mirror_first, mirror_first, string)){
|
||||
did_insert = true;
|
||||
}
|
||||
}
|
||||
end_temp_memory(temp);
|
||||
end_temp_memory(buffer_temp);
|
||||
}
|
||||
i32 new_range_index = 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;
|
||||
}
|
||||
arena_release_all(&arena);
|
||||
end_temp_memory(temp);
|
||||
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)){
|
||||
Mirror 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){
|
||||
case MirrorMode_Constructing:
|
||||
{
|
||||
|
@ -944,7 +944,7 @@ mirror_edit_handler(Application_Links *app, Buffer_ID buffer_id, i32 first, i32
|
|||
}break;
|
||||
}
|
||||
|
||||
arena_release_all(&arena);
|
||||
end_temp_memory(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
3
4ed.cpp
3
4ed.cpp
|
@ -946,6 +946,9 @@ App_Init_Sig(app_init){
|
|||
// NOTE(allen): init GUI keys
|
||||
models->user_up_key = key_up;
|
||||
models->user_down_key = key_down;
|
||||
|
||||
// NOTE(allen):
|
||||
models->custom_layer_arena = make_arena(&models->app_links);
|
||||
}
|
||||
|
||||
App_Step_Sig(app_step){
|
||||
|
|
|
@ -190,6 +190,12 @@ DOC(Dumps away the previous mappings and instantiates the mappings described in
|
|||
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
|
||||
Create_Child_Process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){
|
||||
Models *models = (Models*)app->cmd_context;
|
||||
|
|
|
@ -29,6 +29,7 @@ struct App_Settings{
|
|||
|
||||
struct Models{
|
||||
Mem_Options mem;
|
||||
|
||||
App_Settings settings;
|
||||
|
||||
Face_ID global_font_id;
|
||||
|
@ -81,6 +82,7 @@ struct Models{
|
|||
|
||||
b32 keep_playing;
|
||||
|
||||
// TODO(allen): do(eliminate user_*_key* nonsense from the core)
|
||||
Key_Code user_up_key;
|
||||
Key_Code user_down_key;
|
||||
Key_Modifier user_up_key_modifier;
|
||||
|
@ -98,6 +100,8 @@ struct Models{
|
|||
|
||||
b32 animate_next_frame;
|
||||
|
||||
Arena custom_layer_arena;
|
||||
|
||||
// Last frame state
|
||||
Vec2_i32 prev_p;
|
||||
Panel *prev_mouse_panel;
|
||||
|
|
|
@ -144,33 +144,32 @@ history_is_activated(History *history){
|
|||
|
||||
internal void
|
||||
history_free(Heap *heap, History *history){
|
||||
if (!history->activated){
|
||||
return;
|
||||
}
|
||||
if (history->activated){
|
||||
arena_release_all(&history->arena);
|
||||
memory_bank_free_all(heap, &history->bank);
|
||||
block_zero_struct(history);
|
||||
}
|
||||
}
|
||||
|
||||
internal i32
|
||||
history_get_record_count(History *history){
|
||||
if (!history->activated){
|
||||
return(0);
|
||||
i32 result = 0;
|
||||
if (history->activated){
|
||||
result = history->record_count;
|
||||
}
|
||||
return(history->record_count);
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal Record*
|
||||
history_get_record(History *history, i32 index){
|
||||
if (!history->activated){
|
||||
return(0);
|
||||
}
|
||||
Record *record = 0;
|
||||
Record *result = 0;
|
||||
if (history->activated){
|
||||
Node *node = history__to_node(history, index);
|
||||
if (node != 0){
|
||||
record = CastFromMember(Record, node, node);
|
||||
result = CastFromMember(Record, node, node);
|
||||
}
|
||||
return(record);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal Record*
|
||||
|
@ -189,10 +188,11 @@ history_get_sub_record(Record *record, i32 sub_index){
|
|||
|
||||
internal Record*
|
||||
history_get_dummy_record(History *history){
|
||||
if (!history->activated){
|
||||
return(0);
|
||||
Record *result = 0;
|
||||
if (history->activated){
|
||||
result = CastFromMember(Record, node, &history->records);
|
||||
}
|
||||
return(CastFromMember(Record, node, &history->records));
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
|
|
Loading…
Reference in New Issue