Fully transitioned to the new system api linkage

This commit is contained in:
Allen Webster 2019-10-03 10:57:44 -07:00
parent 19f3d7a641
commit d654adacc5
32 changed files with 399 additions and 870 deletions

80
4ed.cpp
View File

@ -9,14 +9,13 @@
// TOP
Mutex_Lock::Mutex_Lock(System_Functions *s, System_Mutex m){
s->mutex_acquire(m);
this->system = s;
Mutex_Lock::Mutex_Lock(System_Mutex m){
system_mutex_acquire(m);
this->mutex = m;
}
Mutex_Lock::~Mutex_Lock(){
this->system->mutex_release(this->mutex);
system_mutex_release(this->mutex);
}
Mutex_Lock::operator System_Mutex(){
@ -42,7 +41,6 @@ restore_state(Application_Links *app, App_Coroutine_State state){
internal Coroutine*
app_coroutine_handle_request(Models *models, Coroutine *co, u32 *vals){
Coroutine *result = 0;
System_Functions *system = models->system;
switch (vals[2]){
case AppCoroutineRequest_NewFontFace:
{
@ -86,7 +84,7 @@ output_file_append(Models *models, Editing_File *file, String_Const_u8 value){
}
internal void
file_cursor_to_end(System_Functions *system, Models *models, Editing_File *file){
file_cursor_to_end(Models *models, Editing_File *file){
Assert(file != 0);
i64 pos = buffer_size(&file->state.buffer);
Layout *layout = &models->layout;
@ -473,10 +471,9 @@ command_caller(Coroutine *coroutine){
}
internal void
app_links_init(System_Functions *system, Application_Links *app_links){
app_links_init(Application_Links *app_links){
FillAppLinksAPI(app_links);
app_links->current_coroutine = 0;
app_links->system_links = system;
}
// App Functions
@ -753,7 +750,7 @@ get_event_flags(Key_Code keycode){
}
internal void
force_abort_coroutine(System_Functions *system, Models *models, View *view){
force_abort_coroutine(Models *models, View *view){
User_Input user_in = {};
user_in.abort = true;
for (u32 j = 0; j < 10 && models->command_coroutine != 0; ++j){
@ -767,7 +764,7 @@ force_abort_coroutine(System_Functions *system, Models *models, View *view){
}
internal void
launch_command_via_event(System_Functions *system, Models *models, View *view, Key_Event_Data event){
launch_command_via_event(Models *models, View *view, Key_Event_Data event){
models->key = event;
i32 map = view_get_map(view);
@ -792,21 +789,29 @@ launch_command_via_event(System_Functions *system, Models *models, View *view, K
}
internal void
launch_command_via_keycode(System_Functions *system, Models *models, View *view, Key_Code keycode){
launch_command_via_keycode(Models *models, View *view, Key_Code keycode){
Key_Event_Data event = {};
event.keycode = keycode;
launch_command_via_event(system, models, view, event);
launch_command_via_event(models, view, event);
}
internal void
app_load_vtables(API_VTable_system *vtable_system,
API_VTable_font *vtable_font,
API_VTable_graphics *vtable_graphics){
system_api_read_vtable(vtable_system);
font_api_read_vtable(vtable_font);
graphics_api_read_vtable(vtable_graphics);
}
internal Log_Function*
app_get_logger(System_Functions *system){
log_init(system);
app_get_logger(void){
log_init();
return(log_string);
}
App_Read_Command_Line_Sig(app_read_command_line){
Models *models = models_init(tctx);
models->system = system;
App_Settings *settings = &models->settings;
block_zero_struct(settings);
if (argc > 1){
@ -821,7 +826,7 @@ App_Init_Sig(app_init){
Models *models = (Models*)base_ptr;
models->keep_playing = true;
app_links_init(system, &models->app_links);
app_links_init(&models->app_links);
models->config_api = api;
models->app_links.cmd_context = models;
@ -829,10 +834,10 @@ App_Init_Sig(app_init){
Arena *arena = models->arena;
// NOTE(allen): coroutines
coroutine_system_init(system, &models->coroutines);
coroutine_system_init(&models->coroutines);
// NOTE(allen): font set
font_set_init(system, &models->font_set);
font_set_init(&models->font_set);
// NOTE(allen): live set
{
@ -871,7 +876,7 @@ App_Init_Sig(app_init){
// NOTE(allen): file setup
working_set_init(models, &models->working_set);
Mutex_Lock file_order_lock(system, models->working_set.mutex);
Mutex_Lock file_order_lock(models->working_set.mutex);
// NOTE(allen):
global_history_init(&models->global_history);
@ -937,21 +942,21 @@ App_Init_Sig(app_init){
{
Panel *panel = layout_initialize(arena, &models->layout);
View *new_view = live_set_alloc_view(&models->lifetime_allocator, &models->live_set, panel);
view_set_file(system, models, new_view, models->scratch_buffer);
view_set_file(models, new_view, models->scratch_buffer);
}
// NOTE(allen): miscellaneous init
hot_directory_init(system, arena, &models->hot_directory, current_directory);
hot_directory_init(arena, &models->hot_directory, current_directory);
child_process_container_init(models->tctx->allocator, &models->child_processes);
models->user_up_key = key_up;
models->user_down_key = key_down;
models->period_wakeup_timer = system->wake_up_timer_create();
models->period_wakeup_timer = system_wake_up_timer_create();
}
App_Step_Sig(app_step){
Models *models = (Models*)base_ptr;
Mutex_Lock file_order_lock(system, models->working_set.mutex);
Mutex_Lock file_order_lock(models->working_set.mutex);
models->next_animate_delay = max_u32;
models->animate_next_frame = false;
@ -1000,8 +1005,8 @@ App_Step_Sig(app_step){
b32 edited_file = false;
u32 amount = 0;
system->cli_begin_update(cli);
if (system->cli_update_step(cli, dest, max, &amount)){
system_cli_begin_update(cli);
if (system_cli_update_step(cli, dest, max, &amount)){
if (file != 0 && amount > 0){
amount = eol_in_place_convert_in(dest, amount);
output_file_append(models, file, SCu8(dest, amount));
@ -1009,7 +1014,7 @@ App_Step_Sig(app_step){
}
}
if (system->cli_end_update(cli)){
if (system_cli_end_update(cli)){
if (file != 0){
String_Const_u8 str = push_u8_stringf(scratch, "exited with code %d", cli->exit);
output_file_append(models, file, str);
@ -1020,7 +1025,7 @@ App_Step_Sig(app_step){
}
if (child_process->cursor_at_end && file != 0){
file_cursor_to_end(system, models, file);
file_cursor_to_end(models, file);
}
}
@ -1150,15 +1155,15 @@ App_Step_Sig(app_step){
{
// NOTE(allen): kill coroutine if we have one
if (models->command_coroutine != 0){
force_abort_coroutine(system, models, view);
force_abort_coroutine(models, view);
}
// NOTE(allen): run deactivate command
launch_command_via_keycode(system, models, view, key_click_deactivate_view);
launch_command_via_keycode(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){
force_abort_coroutine(system, models, view);
force_abort_coroutine(models, view);
}
layout->active_panel = mouse_panel;
@ -1167,7 +1172,7 @@ App_Step_Sig(app_step){
view = active_panel->view;
// NOTE(allen): run activate command
launch_command_via_keycode(system, models, view, key_click_activate_view);
launch_command_via_keycode(models, view, key_click_activate_view);
}break;
case EventConsume_Command:
@ -1203,7 +1208,7 @@ App_Step_Sig(app_step){
// NOTE(allen): launch command
else{
launch_command_via_event(system, models, view, *key_ptr);
launch_command_via_event(models, view, *key_ptr);
}
}break;
}
@ -1240,7 +1245,7 @@ App_Step_Sig(app_step){
// NOTE(allen): dt
f32 literal_dt = 0.f;
u64 now_usecond_stamp = system->now_time();
u64 now_usecond_stamp = system_now_time();
if (!input->first_step){
u64 elapsed_useconds = now_usecond_stamp - models->last_render_usecond_stamp;
literal_dt = (f32)((f64)(elapsed_useconds)/1000000.f);
@ -1363,7 +1368,7 @@ App_Step_Sig(app_step){
models->color_table = color_table;
}
begin_render_section(target, system, models->frame_counter, literal_dt, animation_dt);
begin_render_section(target, models->frame_counter, literal_dt, animation_dt);
models->in_render_mode = true;
if (models->render_caller != 0){
@ -1371,7 +1376,7 @@ App_Step_Sig(app_step){
}
models->in_render_mode = false;
end_render_section(target, system);
end_render_section(target);
}
// NOTE(allen): flush the log
@ -1411,11 +1416,11 @@ App_Step_Sig(app_step){
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);
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);
system_wake_up_timer_set(models->period_wakeup_timer, models->next_animate_delay);
}
// NOTE(allen): Update Frame to Frame States
@ -1430,6 +1435,7 @@ App_Step_Sig(app_step){
extern "C" App_Get_Functions_Sig(app_get_functions){
App_Functions result = {};
result.load_vtables = app_load_vtables;
result.get_logger = app_get_logger;
result.read_command_line = app_read_command_line;
result.init = app_init;

13
4ed.h
View File

@ -57,7 +57,6 @@ struct Plat_Settings{
#define App_Read_Command_Line_Sig(name) \
void *name(Thread_Context *tctx, \
System_Functions *system, \
String_Const_u8 current_directory,\
Plat_Settings *plat_settings,\
char ***files, \
@ -73,8 +72,7 @@ struct Custom_API{
};
#define App_Init_Sig(name) \
void name(System_Functions *system, \
Render_Target *target, \
void name(Render_Target *target, \
void *base_ptr, \
String_Const_u8 clipboard,\
String_Const_u8 current_directory,\
@ -104,17 +102,20 @@ struct Application_Step_Input{
};
#define App_Step_Sig(name) Application_Step_Result \
name(System_Functions *system, \
Render_Target *target, \
name(Render_Target *target, \
void *base_ptr, \
Application_Step_Input *input)
typedef App_Step_Sig(App_Step);
typedef b32 Log_Function(String_Const_u8 str);
typedef Log_Function *App_Get_Logger(System_Functions *system);
typedef Log_Function *App_Get_Logger(void);
typedef void App_Load_VTables(API_VTable_system *vtable_system,
API_VTable_font *vtable_font,
API_VTable_graphics *vtable_graphics);
struct App_Functions{
App_Load_VTables *load_vtables;
App_Get_Logger *get_logger;
App_Read_Command_Line *read_command_line;
App_Init *init;

View File

@ -89,8 +89,7 @@ Get_Thread_Context(Application_Links *app){
api(custom) function b32
Create_Child_Process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
return(child_process_call(models, system, path, command, child_process_id_out));
return(child_process_call(models, path, command, child_process_id_out));
}
api(custom) function b32
@ -139,7 +138,7 @@ Clipboard_Post(Application_Links *app, i32 clipboard_id, String_Const_u8 string)
Models *models = (Models*)app->cmd_context;
String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, (i32)string.size);
block_copy(dest->str, string.str, string.size);
models->system->post_clipboard(*dest);
system_post_clipboard(*dest);
return(true);
}
@ -204,11 +203,10 @@ api(custom) function Buffer_ID
Get_Buffer_By_File_Name(Application_Links *app, String_Const_u8 file_name, Access_Flag access)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Editing_File_Name canon = {};
Buffer_ID result = false;
Scratch_Block scratch(app);
if (get_canon_name(system, scratch, file_name, &canon)){
if (get_canon_name(scratch, file_name, &canon)){
Working_Set *working_set = &models->working_set;
Editing_File *file = working_set_contains_canon(working_set, string_from_file_name(&canon));
if (api_check_buffer(file, access)){
@ -672,7 +670,6 @@ api(custom) function b32
Buffer_Set_Setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i32 value)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Editing_File *file = imp_get_file(models, buffer_id);
b32 result = false;
if (api_check_buffer(file)){
@ -814,7 +811,6 @@ api(custom) function b32
Buffer_Save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, Buffer_Save_Flag flags)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Editing_File *file = imp_get_file(models, buffer_id);
b32 result = false;
@ -829,7 +825,7 @@ Buffer_Save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_na
if (!skip_save){
Scratch_Block scratch(models->tctx, Scratch_Share);
String_Const_u8 name = push_string_copy(scratch, file_name);
save_file_to_name(system, models, file, name.str);
save_file_to_name(models, file, name.str);
result = true;
}
}
@ -841,7 +837,6 @@ api(custom) function Buffer_Kill_Result
Buffer_Kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Working_Set *working_set = &models->working_set;
Editing_File *file = imp_get_file(models, buffer_id);
Buffer_Kill_Result result = BufferKillResult_DoesNotExist;
@ -855,7 +850,7 @@ Buffer_Kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags)
buffer_unbind_name_low_level(working_set, file);
if (file->canon.name_size != 0){
buffer_unbind_file(system, working_set, file);
buffer_unbind_file(working_set, file);
}
file_free(models, file);
working_set_free_file(&models->heap, working_set, file);
@ -872,7 +867,7 @@ Buffer_Kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags)
Assert(file_node != order);
view->file = 0;
Editing_File *new_file = CastFromMember(Editing_File, touch_node, file_node);
view_set_file(system, models, view, new_file);
view_set_file(models, view, new_file);
file_node = file_node->next;
if (file_node == order){
file_node = file_node->next;
@ -898,21 +893,20 @@ api(custom) function Buffer_Reopen_Result
Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Scratch_Block scratch(models->tctx, Scratch_Share);
Editing_File *file = imp_get_file(models, buffer_id);
Buffer_Reopen_Result result = BufferReopenResult_Failed;
if (api_check_buffer(file)){
if (file->canon.name_size > 0){
Plat_Handle handle = {};
if (system->load_handle(scratch, (char*)file->canon.name_space, &handle)){
File_Attributes attributes = system->load_attributes(handle);
if (system_load_handle(scratch, (char*)file->canon.name_space, &handle)){
File_Attributes attributes = system_load_attributes(handle);
char *file_memory = push_array(scratch, char, (i32)attributes.size);
if (file_memory != 0){
if (system->load_file(handle, file_memory, (i32)attributes.size)){
system->load_close(handle);
if (system_load_file(handle, file_memory, (i32)attributes.size)){
system_load_close(handle);
// TODO(allen): try(perform a diff maybe apply edits in reopen)
@ -943,7 +937,7 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl
file_create_from_string(models, file, SCu8(file_memory, attributes.size), attributes);
for (i32 i = 0; i < vptr_count; ++i){
view_set_file(system, models, vptrs[i], file);
view_set_file(models, vptrs[i], file);
vptrs[i]->file = file;
i64 line = line_numbers[i];
@ -954,11 +948,11 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl
result = BufferReopenResult_Reopened;
}
else{
system->load_close(handle);
system_load_close(handle);
}
}
else{
system->load_close(handle);
system_load_close(handle);
}
}
}
@ -983,7 +977,7 @@ Get_File_Attributes(Application_Links *app, String_Const_u8 file_name)
{
Models *models = (Models*)app->cmd_context;
Scratch_Block scratch(models->tctx, Scratch_Share);
return(models->system->quick_file_attributes(scratch, file_name));
return(system_quick_file_attributes(scratch, file_name));
}
function View*
@ -1232,7 +1226,7 @@ Panel_Split(Application_Links *app, Panel_ID panel_id, Panel_Split_Orientation o
if (layout_split_panel(layout, panel, (orientation == PanelSplit_LeftAndRight), &new_panel)){
Live_Views *live_set = &models->live_set;
View *new_view = live_set_alloc_view(&models->lifetime_allocator, live_set, new_panel);
view_set_file(models->system, models, new_view, models->scratch_buffer);
view_set_file(models, new_view, models->scratch_buffer);
result = true;
}
}
@ -1634,9 +1628,9 @@ View_Set_Buffer(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Se
Editing_File *file = working_set_get_file(&models->working_set, buffer_id);
if (api_check_buffer(file)){
if (file != view->file){
view_set_file(models->system, models, view, file);
view_set_file(models, view, file);
if (!(flags & SetBuffer_KeepOriginalGUI)){
view_quit_ui(models->system, models, view);
view_quit_ui(models, view);
}
}
result = true;
@ -1683,7 +1677,7 @@ View_End_UI_Mode(Application_Links *app, View_ID view_id)
View *view = imp_get_view(models, view_id);
b32 result = false;
if (api_check_view(view) && view->ui_mode){
view_quit_ui(models->system, models, view);
view_quit_ui(models, view);
view->ui_mode = false;
result = true;
}
@ -2123,7 +2117,6 @@ api(custom) function User_Input
Get_User_Input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
User_Input result = {};
if (app->type_coroutine == Co_Command){
Coroutine *coroutine = (Coroutine*)app->current_coroutine;
@ -2212,7 +2205,7 @@ Print_Message(Application_Links *app, String_Const_u8 message)
b32 result = false;
if (file != 0){
output_file_append(models, file, message);
file_cursor_to_end(models->system, models, file);
file_cursor_to_end(models, file);
result = true;
}
return(result);
@ -2226,7 +2219,7 @@ Log_String(Application_Links *app, String_Const_u8 str){
api(custom) function i32
Thread_Get_ID(Application_Links *app){
Models *models = (Models*)app->cmd_context;
return(models->system->thread_get_id());
return(system_thread_get_id());
}
api(custom) function Face_ID
@ -2240,13 +2233,12 @@ api(custom) function b32
Set_Global_Face(Application_Links *app, Face_ID id, b32 apply_to_all_buffers)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
b32 did_change = false;
Face *face = font_set_face_from_id(&models->font_set, id);
if (face != 0){
if (apply_to_all_buffers){
global_set_font_and_update_files(system, models, face);
global_set_font_and_update_files(models, face);
}
else{
models->global_face_id = face->id;
@ -2384,8 +2376,7 @@ Buffer_History_Set_Current_State_Index(Application_Links *app, Buffer_ID buffer_
if (api_check_buffer(file) && history_is_activated(&file->state.history)){
i32 max_index = history_get_record_count(&file->state.history);
if (0 <= index && index <= max_index){
System_Functions *system = models->system;
edit_change_current_history_state(system, models, file, index);
edit_change_current_history_state(models, file, index);
result = true;
}
}
@ -2465,7 +2456,6 @@ Get_Face_Description(Application_Links *app, Face_ID face_id)
api(custom) function Face_Metrics
Get_Face_Metrics(Application_Links *app, Face_ID face_id){
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Face_Metrics result = {};
if (face_id != 0){
Face *face = font_set_face_from_id(&models->font_set, face_id);
@ -2500,7 +2490,6 @@ Try_Create_New_Face(Application_Links *app, Face_Description *description)
Models *models = (Models*)app->cmd_context;
Face_ID result = 0;
if (is_running_coroutine(app)){
System_Functions *system = models->system;
Coroutine *coroutine = (Coroutine*)app->current_coroutine;
Assert(coroutine != 0);
((Face_Description**)coroutine->out)[0] = description;
@ -2521,7 +2510,6 @@ Try_Modify_Face(Application_Links *app, Face_ID id, Face_Description *descriptio
Models *models = (Models*)app->cmd_context;
b32 result = false;
if (is_running_coroutine(app)){
System_Functions *system = models->system;
Coroutine *coroutine = (Coroutine*)app->current_coroutine;
Assert(coroutine != 0);
((Face_Description**)coroutine->out)[0] = description;
@ -2543,7 +2531,7 @@ Try_Release_Face(Application_Links *app, Face_ID id, Face_ID replacement_id)
Font_Set *font_set = &models->font_set;
Face *face = font_set_face_from_id(font_set, id);
Face *replacement = font_set_face_from_id(font_set, replacement_id);
return(release_font_and_update(models->system, models, face, replacement));
return(release_font_and_update(models, face, replacement));
}
api(custom) function void
@ -2595,18 +2583,17 @@ Set_Hot_Directory(Application_Links *app, String_Const_u8 string)
{
Models *models = (Models*)app->cmd_context;
Hot_Directory *hot = &models->hot_directory;
hot_directory_set(models->system, hot, string);
hot_directory_set(hot, string);
return(true);
}
api(custom) function File_List
Get_File_List(Application_Links *app, Arena *arena, String_Const_u8 directory){
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
String_Const_u8 canonical_directory = system->get_canonical(arena, directory);
String_Const_u8 canonical_directory = system_get_canonical(arena, directory);
File_List list = {};
if (canonical_directory.str != 0){
list = system->get_file_list(arena, canonical_directory);
list = system_get_file_list(arena, canonical_directory);
}
return(list);
}
@ -2625,7 +2612,7 @@ api(custom) function void*
Memory_Allocate(Application_Links *app, i32 size)
{
Models *models = (Models*)app->cmd_context;
void *result = models->system->memory_allocate(size);
void *result = system_memory_allocate(size);
return(result);
}
@ -2633,22 +2620,21 @@ api(custom) function b32
Memory_Set_Protection(Application_Links *app, void *ptr, i32 size, Memory_Protect_Flags flags)
{
Models *models = (Models*)app->cmd_context;
return(models->system->memory_set_protection(ptr, size, flags));
return(system_memory_set_protection(ptr, size, flags));
}
api(custom) function void
Memory_Free(Application_Links *app, void *ptr, i32 size)
{
Models *models = (Models*)app->cmd_context;
models->system->memory_free(ptr, size);
system_memory_free(ptr, size);
}
api(custom) function String_Const_u8
Push_4ed_Path(Application_Links *app, Arena *arena)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
return(system->get_path(arena, SystemPath_Binary));
return(system_get_path(arena, SystemPath_Binary));
}
// TODO(allen): do(add a "shown but auto-hides on timer" setting for cursor show type)
@ -2656,7 +2642,7 @@ api(custom) function void
Show_Mouse_Cursor(Application_Links *app, Mouse_Cursor_Show_Type show)
{
Models *models = (Models*)app->cmd_context;
models->system->show_mouse_cursor(show);
system_show_mouse_cursor(show);
}
api(custom) function b32
@ -2670,7 +2656,7 @@ api(custom) function b32
Set_Fullscreen(Application_Links *app, b32 full_screen)
{
Models *models = (Models*)app->cmd_context;
b32 success = models->system->set_fullscreen(full_screen);
b32 success = system_set_fullscreen(full_screen);
if (!success){
print_message(app, string_u8_litexpr("ERROR: Failed to go fullscreen.\n"));
}
@ -2681,7 +2667,7 @@ api(custom) function b32
Is_Fullscreen(Application_Links *app)
{
Models *models = (Models*)app->cmd_context;
b32 result = models->system->is_fullscreen();
b32 result = system_is_fullscreen();
return(result);
}
@ -2709,8 +2695,7 @@ Get_Microseconds_Timestamp(Application_Links *app)
{
// TODO(allen): do(decrease indirection in API calls)
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
return(system->now_time());
return(system_now_time());
}
function Vec2
@ -2939,6 +2924,8 @@ Text_Layout_Character_On_Screen(Application_Links *app, Text_Layout_ID layout_id
f32 width = rect_width(rect);
Face *face = file_get_face(models, file);
Assert(layout->visible_line_number_range.first <= line_number);
f32 y = 0.f;
Buffer_Layout_Item_List line = {};
for (i64 line_number_it = layout->visible_line_number_range.first;;
@ -3019,11 +3006,10 @@ api(custom) function void
Open_Color_Picker(Application_Links *app, Color_Picker *picker)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
if (picker->finished){
*picker->finished = false;
}
system->open_color_picker(picker);
system_open_color_picker(picker);
}
api(custom) function void

View File

@ -35,7 +35,6 @@ enum App_State{
};
struct Models{
System_Functions *system;
Thread_Context *tctx;
Arena *arena;
@ -212,10 +211,9 @@ enum{
////////////////////////////////
struct Mutex_Lock{
Mutex_Lock(System_Functions *system, System_Mutex mutex);
Mutex_Lock(System_Mutex mutex);
~Mutex_Lock();
operator System_Mutex();
System_Functions *system;
System_Mutex mutex;
};

View File

@ -15,8 +15,16 @@
#include "4coder_base_types.h"
#include "4coder_table.h"
#include "4ed_font_interface.h"
#include "4ed_system.h"
#include "4ed_system_types.h"
#define DYNAMIC_LINK_API
#include "generated/system_api.h"
#define DYNAMIC_LINK_API
#include "generated/graphics_api.h"
#define DYNAMIC_LINK_API
#include "generated/font_api.h"
#include "4coder_string_match.h"
#include "4coder_base_types.cpp"
@ -55,6 +63,13 @@
#include "4ed_log.h"
#include "4ed_app_models.h"
#define DYNAMIC_LINK_API
#include "generated/system_api.cpp"
#define DYNAMIC_LINK_API
#include "generated/graphics_api.cpp"
#define DYNAMIC_LINK_API
#include "generated/font_api.cpp"
#include "4ed_allocator_models.cpp"
#include "4ed_log.cpp"
#include "4coder_log.cpp"

View File

@ -98,13 +98,13 @@ child_process_lookup_return_code(Child_Process_Container *container, Child_Proce
////////////////////////////////
internal b32
child_process_call(Models *models, System_Functions *system, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *id_out){
child_process_call(Models *models, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *id_out){
b32 result = false;
Scratch_Block scratch(&models->app_links);
String_Const_u8 path_n = push_string_copy(scratch, path);
String_Const_u8 command_n = push_string_copy(scratch, command);
CLI_Handles cli_handles = {};
if (system->cli_call(scratch, (char*)path_n.str, (char*)command_n.str, &cli_handles)){
if (system_cli_call(scratch, (char*)path_n.str, (char*)command_n.str, &cli_handles)){
Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes);
*id_out = new_process.id;
new_process.process->cli = cli_handles;

View File

@ -15,15 +15,13 @@ coroutine__pass_control(Coroutine *me, Coroutine *other,
Assert(me->state == CoroutineState_Active);
Assert(me->sys == other->sys);
System_Functions *system = me->system;
me->state = my_new_state;
other->state = CoroutineState_Active;
me->sys->active = other;
system->condition_variable_signal(other->cv);
system_condition_variable_signal(other->cv);
if (control == CoroutinePassControl_BlockMe){
for (;me->state != CoroutineState_Active;){
system->condition_variable_wait(me->cv, me->sys->lock);
system_condition_variable_wait(me->cv, me->sys->lock);
}
}
}
@ -31,18 +29,17 @@ coroutine__pass_control(Coroutine *me, Coroutine *other,
internal void
coroutine_main(void *ptr){
Coroutine *me = (Coroutine*)ptr;
System_Functions *system = me->system;
// NOTE(allen): Init handshake
Assert(me->state == CoroutineState_Dead);
system->mutex_acquire(me->sys->lock);
system_mutex_acquire(me->sys->lock);
me->sys->did_init = true;
system->condition_variable_signal(me->sys->init_cv);
system_condition_variable_signal(me->sys->init_cv);
for (;;){
// NOTE(allen): Wait until someone wakes us up, then go into our procedure.
for (;me->state != CoroutineState_Active;){
system->condition_variable_wait(me->cv, me->sys->lock);
system_condition_variable_wait(me->cv, me->sys->lock);
}
Assert(me->type != CoroutineType_Root);
Assert(me->yield_ctx != 0);
@ -62,41 +59,37 @@ coroutine_main(void *ptr){
internal void
coroutine_sub_init(Coroutine *co, Coroutine_Group *sys){
System_Functions *system = sys->system;
block_zero_struct(co);
co->system = system;
co->sys = sys;
co->state = CoroutineState_Dead;
co->type = CoroutineType_Sub;
co->cv = system->condition_variable_make();
co->cv = system_condition_variable_make();
sys->did_init = false;
co->thread = system->thread_launch(coroutine_main, co);
co->thread = system_thread_launch(coroutine_main, co);
for (;!sys->did_init;){
system->condition_variable_wait(sys->init_cv, sys->lock);
system_condition_variable_wait(sys->init_cv, sys->lock);
}
}
internal void
coroutine_system_init(System_Functions *system, Coroutine_Group *sys){
sys->arena = make_arena_system(system);
sys->system = system;
coroutine_system_init(Coroutine_Group *sys){
sys->arena = make_arena_system();
Coroutine *root = &sys->root;
sys->lock = system->mutex_make();
sys->init_cv = system->condition_variable_make();
sys->lock = system_mutex_make();
sys->init_cv = system_condition_variable_make();
sys->active = root;
block_zero_struct(root);
root->system = system;
root->sys = sys;
root->state = CoroutineState_Active;
root->type = CoroutineType_Root;
root->cv = system->condition_variable_make();
root->cv = system_condition_variable_make();
sys->unused = 0;
system->mutex_acquire(sys->lock);
system_mutex_acquire(sys->lock);
}
internal Coroutine*

View File

@ -33,7 +33,6 @@ struct Coroutine{
Coroutine *next;
void *in;
void *out;
System_Functions *system;
System_Thread thread;
System_Condition_Variable cv;
struct Coroutine_Group *sys;
@ -45,7 +44,6 @@ struct Coroutine{
struct Coroutine_Group{
Arena arena;
System_Functions *system;
System_Mutex lock;
System_Condition_Variable init_cv;
b32 did_init;

View File

@ -11,7 +11,6 @@
internal void
edit_pre_state_change(Models *models, Editing_File *file){
System_Functions *system = models->system;
file_add_dirty_flag(file, DirtyState_UnsavedChanges);
}
@ -242,7 +241,7 @@ file_end_file(Models *models, Editing_File *file){
}
internal void
edit__apply_record_forward(System_Functions *system, Models *models, Editing_File *file, Record *record, Edit_Behaviors behaviors_prototype){
edit__apply_record_forward(Models *models, Editing_File *file, Record *record, Edit_Behaviors behaviors_prototype){
// NOTE(allen): // NOTE(allen): // NOTE(allen): // NOTE(allen): // NOTE(allen):
// Whenever you change this also change the backward version!
@ -261,7 +260,7 @@ edit__apply_record_forward(System_Functions *system, Models *models, Editing_Fil
node != sentinel;
node = node->next){
Record *sub_record = CastFromMember(Record, node, node);
edit__apply_record_forward(system, models, file, sub_record, behaviors_prototype);
edit__apply_record_forward(models, file, sub_record, behaviors_prototype);
}
}break;
@ -273,7 +272,7 @@ edit__apply_record_forward(System_Functions *system, Models *models, Editing_Fil
}
internal void
edit__apply_record_backward(System_Functions *system, Models *models, Editing_File *file, Record *record, Edit_Behaviors behaviors_prototype){
edit__apply_record_backward(Models *models, Editing_File *file, Record *record, Edit_Behaviors behaviors_prototype){
// NOTE(allen): // NOTE(allen): // NOTE(allen): // NOTE(allen): // NOTE(allen):
// Whenever you change this also change the forward version!
@ -292,7 +291,7 @@ edit__apply_record_backward(System_Functions *system, Models *models, Editing_Fi
node != sentinel;
node = node->prev){
Record *sub_record = CastFromMember(Record, node, node);
edit__apply_record_backward(system, models, file, sub_record, behaviors_prototype);
edit__apply_record_backward(models, file, sub_record, behaviors_prototype);
}
}break;
@ -304,7 +303,7 @@ edit__apply_record_backward(System_Functions *system, Models *models, Editing_Fi
}
internal void
edit_change_current_history_state(System_Functions *system, Models *models, Editing_File *file, i32 target_index){
edit_change_current_history_state(Models *models, Editing_File *file, i32 target_index){
History *history = &file->state.history;
if (history->activated && file->state.current_record_index != target_index){
Assert(0 <= target_index && target_index <= history->record_count);
@ -322,13 +321,13 @@ edit_change_current_history_state(System_Functions *system, Models *models, Edit
current += 1;
record = CastFromMember(Record, node, record->node.next);
Assert(record != dummy_record);
edit__apply_record_forward(system, models, file, record, behaviors_prototype);
edit__apply_record_forward(models, file, record, behaviors_prototype);
} while (current != target_index);
}
else{
do{
Assert(record != dummy_record);
edit__apply_record_backward(system, models, file, record, behaviors_prototype);
edit__apply_record_backward(models, file, record, behaviors_prototype);
current -= 1;
record = CastFromMember(Record, node, record->node.prev);
} while (current != target_index);
@ -349,18 +348,17 @@ edit_merge_history_range(Models *models, Editing_File *file, History_Record_Inde
if (first_index < last_index){
i32 current_index = file->state.current_record_index;
if (first_index <= current_index && current_index < last_index){
System_Functions *system = models->system;
u32 in_range_handler = (flags & bitmask_2);
switch (in_range_handler){
case RecordMergeFlag_StateInRange_MoveStateForward:
{
edit_change_current_history_state(system, models, file, last_index);
edit_change_current_history_state(models, file, last_index);
current_index = last_index;
}break;
case RecordMergeFlag_StateInRange_MoveStateBackward:
{
edit_change_current_history_state(system, models, file, first_index);
edit_change_current_history_state(models, file, first_index);
current_index = first_index;
}break;
@ -431,7 +429,6 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
Editing_File *result = 0;
if (file_name.size > 0){
System_Functions *system = models->system;
Working_Set *working_set = &models->working_set;
Heap *heap = &models->heap;
@ -445,7 +442,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
// NOTE(allen): Try to get the file by canon name.
if (HasFlag(flags, BufferCreate_NeverAttachToFile) == 0){
if (get_canon_name(system, scratch, file_name, &canon)){
if (get_canon_name(scratch, file_name, &canon)){
has_canon_name = true;
file = working_set_contains_canon(working_set, string_from_file_name(&canon));
}
@ -471,7 +468,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
do_empty_buffer = true;
}
else{
if (!system->load_handle(scratch, (char*)canon.name_space, &handle)){
if (!system_load_handle(scratch, (char*)canon.name_space, &handle)){
do_empty_buffer = true;
}
}
@ -485,7 +482,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
file = working_set_allocate_file(working_set, &models->lifetime_allocator);
if (file != 0){
if (has_canon_name){
file_bind_file_name(system, working_set, file, string_from_file_name(&canon));
file_bind_file_name(working_set, file, string_from_file_name(&canon));
}
String_Const_u8 front = string_front_of_path(file_name);
buffer_bind_name(models, scratch, working_set, file, front);
@ -496,7 +493,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
}
}
else{
File_Attributes attributes = system->load_attributes(handle);
File_Attributes attributes = system_load_attributes(handle);
b32 in_heap_mem = false;
char *buffer = push_array(scratch, char, (i32)attributes.size);
@ -506,11 +503,11 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
in_heap_mem = true;
}
if (system->load_file(handle, buffer, (i32)attributes.size)){
system->load_close(handle);
if (system_load_file(handle, buffer, (i32)attributes.size)){
system_load_close(handle);
file = working_set_allocate_file(working_set, &models->lifetime_allocator);
if (file != 0){
file_bind_file_name(system, working_set, file, string_from_file_name(&canon));
file_bind_file_name(working_set, file, string_from_file_name(&canon));
String_Const_u8 front = string_front_of_path(file_name);
buffer_bind_name(models, scratch, working_set, file, front);
file_create_from_string(models, file, SCu8(buffer, (i32)attributes.size), attributes);
@ -518,7 +515,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
}
}
else{
system->load_close(handle);
system_load_close(handle);
}
if (in_heap_mem){

View File

@ -137,7 +137,7 @@ file_name_terminate(Editing_File_Name *name){
// TODO(allen): file_name should be String_Const_u8
internal b32
save_file_to_name(System_Functions *system, Models *models, Editing_File *file, u8 *file_name){
save_file_to_name(Models *models, Editing_File *file, u8 *file_name){
b32 result = false;
b32 using_actual_file_name = false;
@ -159,7 +159,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
if (!using_actual_file_name){
String_Const_u8 s_file_name = SCu8(file_name);
String_Const_u8 canonical_file_name = system->get_canonical(scratch, s_file_name);
String_Const_u8 canonical_file_name = system_get_canonical(scratch, s_file_name);
if (string_match(canonical_file_name, string_from_file_name(&file->canon))){
using_actual_file_name = true;
}
@ -167,14 +167,14 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
String_Const_u8 saveable_string = buffer_stringify(scratch, buffer, Ii64(0, buffer_size(buffer)));
File_Attributes new_attributes = system->save_file(scratch, (char*)file_name, saveable_string);
File_Attributes new_attributes = system_save_file(scratch, (char*)file_name, saveable_string);
if (new_attributes.last_write_time > 0){
if (using_actual_file_name){
file->state.ignore_behind_os = 1;
}
file->attributes = new_attributes;
}
LogEventF(log_string(M), scratch, file->id, 0, system->thread_get_id(),
LogEventF(log_string(M), scratch, file->id, 0, system_thread_get_id(),
"save file [last_write_time=0x%llx]", new_attributes.last_write_time);
file_clear_dirty_flags(file);
@ -184,8 +184,8 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
}
internal b32
save_file(System_Functions *system, Models *models, Editing_File *file){
return(save_file_to_name(system, models, file, 0));
save_file(Models *models, Editing_File *file){
return(save_file_to_name(models, file, 0));
}
////////////////////////////////
@ -210,7 +210,6 @@ file_compute_cursor(Editing_File *file, Buffer_Seek seek){
internal void
file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val, File_Attributes attributes){
System_Functions *system = models->system;
Thread_Context *tctx = models->tctx;
Scratch_Block scratch(tctx, Scratch_Share);
@ -240,7 +239,7 @@ file_create_from_string(Models *models, Editing_File *file, String_Const_u8 val,
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 name = SCu8(file->unique_name.name_space, file->unique_name.name_size);
name = string_escape(scratch, name);
LogEventF(log_string(M), scratch, file->id, 0, system->thread_get_id(),
LogEventF(log_string(M), scratch, file->id, 0, system_thread_get_id(),
"init file [lwt=0x%llx] [name=\"%.*s\"]",
attributes.last_write_time, string_expand(name));
end_temp(temp);

View File

@ -164,7 +164,7 @@ internal Face*
ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor){
String_Const_u8 file_name = {};
if (description->font.in_4coder_font_folder){
String_Const_u8 binary_path = sysfunc.get_path(arena, SystemPath_Binary);
String_Const_u8 binary_path = system_get_path(arena, SystemPath_Binary);
binary_path = string_mod_replace_character(binary_path, '\\', '/');
file_name = push_u8_stringf(arena, "%.*sfonts/%.*s", string_expand(binary_path),
string_expand(description->font.file_name));
@ -296,7 +296,7 @@ ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor
ft__bad_rect_store_finish(&pack);
Texture_Kind texture_kind = TextureKind_Mono;
u32 texture = sysfunc.get_texture(pack.dim, texture_kind);
u32 texture = graphics_get_texture(pack.dim, texture_kind);
face->texture_kind = texture_kind;
face->texture = texture;
@ -306,7 +306,7 @@ ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor
{
Vec3_i32 p = V3i32((i32)face->white.uv.x0, (i32)face->white.uv.y0, (i32)face->white.w);
Vec3_i32 dim = V3i32(white.dim.x, white.dim.y, 1);
sysfunc.fill_texture(texture_kind, texture, p, dim, white.data);
graphics_fill_texture(texture_kind, texture, p, dim, white.data);
face->white.uv.x1 = (face->white.uv.x0 + face->white.uv.x1)/texture_dim.x;
face->white.uv.y1 = (face->white.uv.y0 + face->white.uv.y1)/texture_dim.y;
face->white.uv.x0 = face->white.uv.x0/texture_dim.x;
@ -317,7 +317,7 @@ ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor
for (u16 i = 0; i < index_count; i += 1){
Vec3_i32 p = V3i32((i32)face->bounds[i].uv.x0, (i32)face->bounds[i].uv.y0, (i32)face->bounds[i].w);
Vec3_i32 dim = V3i32(glyph_bitmaps[i].dim.x, glyph_bitmaps[i].dim.y, 1);
sysfunc.fill_texture(texture_kind, texture, p, dim, glyph_bitmaps[i].data);
graphics_fill_texture(texture_kind, texture, p, dim, glyph_bitmaps[i].data);
face->bounds[i].uv.x1 = (face->bounds[i].uv.x0 + face->bounds[i].uv.x1)/texture_dim.x;
face->bounds[i].uv.y1 = (face->bounds[i].uv.y0 + face->bounds[i].uv.y1)/texture_dim.y;
face->bounds[i].uv.x0 = face->bounds[i].uv.x0/texture_dim.x;

View File

@ -67,19 +67,18 @@ font_set__free_face_slot(Font_Set *set, Font_Face_Slot *slot){
}
internal void
font_set_init(System_Functions *system, Font_Set *set){
font_set_init(Font_Set *set){
block_zero_struct(set);
set->system = system;
set->arena = make_arena_system(system);
set->arena = make_arena_system();
set->next_id_counter = 1;
set->id_to_slot_table = make_table_u64_u64(set->arena.base_allocator, 40);
set->scale_factor = system->get_screen_scale_factor();
set->scale_factor = system_get_screen_scale_factor();
}
internal Face*
font_set_new_face(Font_Set *set, Face_Description *description){
Arena arena = make_arena_system(set->system);
Face *face = set->system->font_make_face(&arena, description, set->scale_factor);
Arena arena = make_arena_system();
Face *face = font_make_face(&arena, description, set->scale_factor);
if (face != 0){
Font_Face_Slot *slot = font_set__alloc_face_slot(set);
slot->arena = arena;
@ -150,8 +149,8 @@ font_set_modify_face(Font_Set *set, Face_ID id, Face_Description *description){
Font_Face_Slot *slot = font_set__get_face_slot(set, id);
if (slot != 0){
i32 version_number = slot->face->version_number;
Arena arena = make_arena_system(set->system);
Face *face = set->system->font_make_face(&arena, description, set->scale_factor);
Arena arena = make_arena_system();
Face *face = font_make_face(&arena, description, set->scale_factor);
if (face != 0){
linalloc_clear(&slot->arena);
slot->arena = arena;

View File

@ -28,7 +28,6 @@ union Font_Face_Slot{
};
struct Font_Set{
struct System_Functions *system;
Arena arena;
Face_ID next_id_counter;
Font_Face_ID_Node *free_ids;

View File

@ -53,30 +53,30 @@ hot_directory_fixup(Hot_Directory *hot_directory){
}
internal void
hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String_Const_u8 str){
hot_directory_set(Hot_Directory *hot_directory, String_Const_u8 str){
linalloc_clear(&hot_directory->arena);
hot_directory->string = push_string_copy(&hot_directory->arena, str);
hot_directory->canonical = system->get_canonical(&hot_directory->arena, str);
hot_directory->file_list = system->get_file_list(&hot_directory->arena, hot_directory->canonical);
hot_directory->canonical = system_get_canonical(&hot_directory->arena, str);
hot_directory->file_list = system_get_file_list(&hot_directory->arena, hot_directory->canonical);
}
internal void
hot_directory_reload(System_Functions *system, Arena *scratch, Hot_Directory *hot_directory){
hot_directory_reload(Arena *scratch, Hot_Directory *hot_directory){
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 string = push_string_copy(scratch, hot_directory->string);
hot_directory_set(system, hot_directory, string);
hot_directory_set(hot_directory, string);
end_temp(temp);
}
internal void
hot_directory_init(System_Functions *system, Arena *scratch, Hot_Directory *hot_directory, String_Const_u8 directory){
hot_directory->arena = make_arena_system(system);
hot_directory_init(Arena *scratch, Hot_Directory *hot_directory, String_Const_u8 directory){
hot_directory->arena = make_arena_system();
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 dir = directory;
if (!character_is_slash(string_get_character(directory, directory.size - 1))){
dir = push_u8_stringf(scratch, "%.*s/", string_expand(directory));
}
hot_directory_set(system, hot_directory, dir);
hot_directory_set(hot_directory, dir);
end_temp(temp);
}

View File

@ -12,22 +12,19 @@
global Log global_log = {};
internal void
log_init(System_Functions *system){
global_log.mutex = system->mutex_make();
global_log.mutex_acquire = system->mutex_acquire;
global_log.mutex_release = system->mutex_release;
global_log.thread_get_id = system->thread_get_id;
global_log.arena = make_arena_system(system);
log_init(void){
global_log.mutex = system_mutex_make();
global_log.arena = make_arena_system();
}
internal b32
log_string(String_Const_u8 str){
b32 result = false;
i32 thread_id = global_log.thread_get_id();
i32 thread_id = system_thread_get_id();
if (global_log.disabled_thread_id != thread_id){
global_log.mutex_acquire(global_log.mutex);
system_mutex_acquire(global_log.mutex);
string_list_push(&global_log.arena, &global_log.list, push_string_copy(&global_log.arena, str));
global_log.mutex_release(global_log.mutex);
system_mutex_release(global_log.mutex);
result = true;
}
return(result);
@ -40,8 +37,8 @@ internal b32
log_flush(Models *models){
b32 result = false;
global_log.mutex_acquire(global_log.mutex);
global_log.disabled_thread_id = global_log.thread_get_id();
system_mutex_acquire(global_log.mutex);
global_log.disabled_thread_id = system_thread_get_id();
if (global_log.list.total_size > 0){
String_Const_u8 text = string_list_flatten(&global_log.arena, global_log.list);
@ -52,7 +49,7 @@ log_flush(Models *models){
block_zero_struct(&global_log.list);
global_log.disabled_thread_id = 0;
global_log.mutex_release(global_log.mutex);
system_mutex_release(global_log.mutex);
return(result);
}

View File

@ -17,9 +17,6 @@ struct Log{
Arena arena;
List_String_Const_u8 list;
volatile i32 disabled_thread_id;
System_Mutex_Acquire *mutex_acquire;
System_Mutex_Release *mutex_release;
System_Thread_Get_ID *thread_get_id;
};
#endif

View File

@ -143,8 +143,7 @@ begin_frame(Render_Target *target, void *font_set){
}
internal void
begin_render_section(Render_Target *target, System_Functions *system,
i32 frame_index, f32 literal_dt, f32 animation_dt){
begin_render_section(Render_Target *target, i32 frame_index, f32 literal_dt, f32 animation_dt){
target->clip_top = -1;
i32_Rect clip;
@ -160,7 +159,7 @@ begin_render_section(Render_Target *target, System_Functions *system,
}
internal void
end_render_section(Render_Target *target, System_Functions *system){
end_render_section(Render_Target *target){
Assert(target->clip_top == 0);
}

View File

@ -21,12 +21,12 @@ search_list_add_path(Arena *arena, Path_Search_List *list, String_Const_u8 path)
}
function void
search_list_add_system_path(System_Functions *system, Arena *arena, Path_Search_List *list, System_Path_Code path){
search_list_add_path__inner(arena, list, system->get_path(arena, path));
search_list_add_system_path(Arena *arena, Path_Search_List *list, System_Path_Code path){
search_list_add_path__inner(arena, list, system_get_path(arena, path));
}
function String_Const_u8
get_full_path(System_Functions *system, Arena *arena, Path_Search_List *search_list, String_Const_u8 relative){
get_full_path(Arena *arena, Path_Search_List *search_list, String_Const_u8 relative){
String_Const_u8 result = {};
Temp_Memory restore_point = begin_temp(arena);
umem buffer_cap = search_list->max_member_length + relative.size + 1;
@ -42,7 +42,7 @@ get_full_path(System_Functions *system, Arena *arena, Path_Search_List *search_l
u8 *path_base = relative_base - node_size;
block_copy(path_base, node->string.str, node_size);
String_Const_u8 name = SCu8(path_base, opl);
File_Attributes attribs = system->quick_file_attributes(arena, name);
File_Attributes attribs = system_quick_file_attributes(arena, name);
if (attribs.size > 0){
result = name;
break;

View File

@ -1,259 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 21.01.2014
*
* System functions for project codename "4ed"
*
*/
// TOP
// TODO(allen): rewrite using new arenas and strings!!!!! rewrite rewrite rewrite rewrite rewrite
#if !defined(FCODER_SYSTEM_INTERFACE_H)
#define FCODER_SYSTEM_INTERFACE_H
// types
struct Plat_Handle{
u32 d[4];
};
typedef Plat_Handle System_Library;
typedef Plat_Handle System_Thread;
typedef Plat_Handle System_Mutex;
typedef Plat_Handle System_Condition_Variable;
typedef void Thread_Function(void *ptr);
struct CLI_Handles{
Plat_Handle proc;
Plat_Handle out_read;
Plat_Handle out_write;
Plat_Handle in_read;
Plat_Handle in_write;
u32 scratch_space[4];
i32 exit;
};
typedef i32 System_Path_Code;
enum{
SystemPath_CurrentDirectory,
SystemPath_Binary,
};
// files
#define Sys_Get_Canonical_Sig(n) String_Const_u8 n(Arena *arena, String_Const_u8 name)
typedef Sys_Get_Canonical_Sig(System_Get_Canonical);
#define Sys_Get_File_List_Sig(name) File_List name(Arena *arena, String_Const_u8 directory)
typedef Sys_Get_File_List_Sig(System_Get_File_List);
// file load/save
#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(Arena *scratch, String_Const_u8 file_name)
typedef Sys_Quick_File_Attributes_Sig(System_Quick_File_Attributes);
#define Sys_Load_Handle_Sig(name) b32 name(Arena *scratch, char *filename, Plat_Handle *handle_out)
typedef Sys_Load_Handle_Sig(System_Load_Handle);
#define Sys_Load_Attributes_Sig(name) File_Attributes name(Plat_Handle handle)
typedef Sys_Load_Attributes_Sig(System_Load_Attributes);
#define Sys_Load_File_Sig(name) b32 name(Plat_Handle handle, char *buffer, u32 size)
typedef Sys_Load_File_Sig(System_Load_File);
#define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle)
typedef Sys_Load_Close_Sig(System_Load_Close);
#define Sys_Save_File_Sig(name) \
File_Attributes name(Arena *scratch, char *filename, String_Const_u8 data)
typedef Sys_Save_File_Sig(System_Save_File);
// library
#define Sys_Load_Library_Sig(name) \
b32 name(Arena *scratch, String_Const_u8 file_name, System_Library *out)
typedef Sys_Load_Library_Sig(System_Load_Library);
#define Sys_Release_Library_Sig(name) b32 name(System_Library handle)
typedef Sys_Release_Library_Sig(System_Release_Library);
#define Sys_Get_Proc_Sig(name) Void_Func *name(System_Library handle, char *proc_name)
typedef Sys_Get_Proc_Sig(System_Get_Proc);
// time
#define Sys_Now_Time_Sig(name) u64 name()
typedef Sys_Now_Time_Sig(System_Now_Time);
#define Sys_Wake_Up_Timer_Create_Sig(name) Plat_Handle name()
typedef Sys_Wake_Up_Timer_Create_Sig(System_Wake_Up_Timer_Create);
#define Sys_Wake_Up_Timer_Release_Sig(name) void name(Plat_Handle handle)
typedef Sys_Wake_Up_Timer_Release_Sig(System_Wake_Up_Timer_Release);
#define Sys_Wake_Up_Timer_Set_Sig(name) void name(Plat_Handle handle, u32 time_milliseconds)
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_Signal_Step_Sig(name) void name(u32 code)
typedef Sys_Signal_Step_Sig(System_Signal_Step);
#define Sys_Sleep_Sig(name) void name(u64 microseconds)
typedef Sys_Sleep_Sig(System_Sleep);
// clipboard
#define Sys_Post_Clipboard_Sig(name) void name(String_Const_u8 str)
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
// cli
#define Sys_CLI_Call_Sig(n, scratch, path, script, cli_out) \
b32 n(Arena *scratch, char *path, char *script, CLI_Handles *cli_out)
typedef Sys_CLI_Call_Sig(System_CLI_Call, scratch, path, script, cli_out);
#define Sys_CLI_Begin_Update_Sig(name) void name(CLI_Handles *cli)
typedef Sys_CLI_Begin_Update_Sig(System_CLI_Begin_Update);
#define Sys_CLI_Update_Step_Sig(name) b32 name(CLI_Handles *cli, char *dest, u32 max, u32 *amount)
typedef Sys_CLI_Update_Step_Sig(System_CLI_Update_Step);
#define Sys_CLI_End_Update_Sig(name) b32 name(CLI_Handles *cli)
typedef Sys_CLI_End_Update_Sig(System_CLI_End_Update);
//
#define Sys_Open_Color_Picker_Sig(name) void name(Color_Picker *picker)
typedef Sys_Open_Color_Picker_Sig(System_Open_Color_Picker);
#define Sys_Get_Screen_Scale_Factor_Sig(name) f32 name(void)
typedef Sys_Get_Screen_Scale_Factor_Sig(System_Get_Screen_Scale_Factor);
// thread
#define Sys_Thread_Launch_Sig(name) \
System_Thread name(Thread_Function *proc, void *ptr)
typedef Sys_Thread_Launch_Sig(System_Thread_Launch);
#define Sys_Thread_Join_Sig(name) void name(System_Thread thread)
typedef Sys_Thread_Join_Sig(System_Thread_Join);
#define Sys_Thread_Free_Sig(name) void name(System_Thread thread)
typedef Sys_Thread_Free_Sig(System_Thread_Free);
#define Sys_Thread_Get_ID_Sig(name) i32 name(void)
typedef Sys_Thread_Get_ID_Sig(System_Thread_Get_ID);
#define Sys_Mutex_Make_Sig(name) System_Mutex name(void)
typedef Sys_Mutex_Make_Sig(System_Mutex_Make);
#define Sys_Mutex_Acquire_Sig(name) void name(System_Mutex mutex)
typedef Sys_Mutex_Acquire_Sig(System_Mutex_Acquire);
#define Sys_Mutex_Release_Sig(name) void name(System_Mutex mutex)
typedef Sys_Mutex_Release_Sig(System_Mutex_Release);
#define Sys_Mutex_Free_Sig(name) void name(System_Mutex mutex)
typedef Sys_Mutex_Free_Sig(System_Mutex_Free);
#define Sys_Condition_Variable_Make_Sig(name) System_Condition_Variable name(void)
typedef Sys_Condition_Variable_Make_Sig(System_Condition_Variable_Make);
#define Sys_Condition_Variable_Wait_Sig(name) void name(System_Condition_Variable cv, System_Mutex mutex)
typedef Sys_Condition_Variable_Wait_Sig(System_Condition_Variable_Wait);
#define Sys_Condition_Variable_Signal_Sig(name) void name(System_Condition_Variable cv)
typedef Sys_Condition_Variable_Signal_Sig(System_Condition_Variable_Signal);
#define Sys_Condition_Variable_Free_Sig(name) void name(System_Condition_Variable cv)
typedef Sys_Condition_Variable_Free_Sig(System_Condition_Variable_Free);
// memory
#define Sys_Memory_Allocate_Sig(name) void* name(umem size)
typedef Sys_Memory_Allocate_Sig(System_Memory_Allocate);
#define Sys_Memory_Set_Protection_Sig(name) b32 name(void *ptr, umem size, u32 flags)
typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection);
#define Sys_Memory_Free_Sig(name) void name(void *ptr, umem size)
typedef Sys_Memory_Free_Sig(System_Memory_Free);
// file system
#define Sys_Get_Path_Sig(name) String_Const_u8 name(Arena *arena, System_Path_Code code)
typedef Sys_Get_Path_Sig(System_Get_Path);
// behavior and appearance options
#define Sys_Show_Mouse_Cursor_Sig(name) void name(i32 show)
typedef Sys_Show_Mouse_Cursor_Sig(System_Show_Mouse_Cursor);
#define Sys_Set_Fullscreen_Sig(name) b32 name(b32 full_screen)
typedef Sys_Set_Fullscreen_Sig(System_Set_Fullscreen);
#define Sys_Is_Fullscreen_Sig(name) b32 name()
typedef Sys_Is_Fullscreen_Sig(System_Is_Fullscreen);
struct System_Functions{
Font_Make_Face_Function *font_make_face;
Graphics_Get_Texture_Function *get_texture;
Graphics_Fill_Texture_Function *fill_texture;
// files
System_Get_Canonical *get_canonical;
System_Get_File_List *get_file_list;
System_Quick_File_Attributes *quick_file_attributes;
System_Load_Handle *load_handle;
System_Load_Attributes *load_attributes;
System_Load_File *load_file;
System_Load_Close *load_close;
System_Save_File *save_file;
// library
System_Load_Library *load_library;
System_Release_Library *release_library;
System_Get_Proc *get_proc;
// time
System_Now_Time *now_time;
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_Signal_Step *signal_step;
System_Sleep *sleep;
// clipboard
System_Post_Clipboard *post_clipboard;
// cli
System_CLI_Call *cli_call;
System_CLI_Begin_Update *cli_begin_update;
System_CLI_Update_Step *cli_update_step;
System_CLI_End_Update *cli_end_update;
// TODO(allen):
System_Open_Color_Picker *open_color_picker;
System_Get_Screen_Scale_Factor *get_screen_scale_factor;
// threads
System_Thread_Launch *thread_launch;
System_Thread_Join *thread_join;
System_Thread_Free *thread_free;
System_Thread_Get_ID *thread_get_id;
System_Mutex_Make *mutex_make;
System_Mutex_Acquire *mutex_acquire;
System_Mutex_Release *mutex_release;
System_Mutex_Free *mutex_free;
System_Condition_Variable_Make *condition_variable_make;
System_Condition_Variable_Wait *condition_variable_wait;
System_Condition_Variable_Signal *condition_variable_signal;
System_Condition_Variable_Free *condition_variable_free;
// custom
System_Memory_Allocate *memory_allocate;
System_Memory_Set_Protection *memory_set_protection;
System_Memory_Free *memory_free;
System_Get_Path *get_path;
System_Show_Mouse_Cursor *show_mouse_cursor;
System_Set_Fullscreen *set_fullscreen;
System_Is_Fullscreen *is_fullscreen;
};
#endif
// BOTTOM

View File

@ -6,12 +6,11 @@
internal void*
base_reserve__system(void *user_data, umem size, umem *size_out){
System_Functions *system = (System_Functions*)user_data;
umem extra_size = 128;
umem increased_size = size + extra_size;
size = round_up_umem(increased_size, KB(4));
*size_out = size - extra_size;
void *ptr = system->memory_allocate(size);
void *ptr = system_memory_allocate(size);
*(umem*)ptr = size;
ptr = (u8*)ptr + extra_size;
return(ptr);
@ -19,42 +18,41 @@ base_reserve__system(void *user_data, umem size, umem *size_out){
internal void
base_free__system(void *user_data, void *ptr){
System_Functions *system = (System_Functions*)user_data;
umem extra_size = 128;
ptr = (u8*)ptr - extra_size;
umem size = *(umem*)ptr;
system->memory_free(ptr, size);
system_memory_free(ptr, size);
}
internal Base_Allocator
make_base_allocator_system(System_Functions *system){
make_base_allocator_system(void){
return(make_base_allocator(base_reserve__system, 0, 0,
base_free__system, 0, system));
base_free__system, 0, 0));
}
global Base_Allocator base_allocator_system = {};
internal Base_Allocator*
get_base_allocator_system(System_Functions *system){
get_base_allocator_system(void){
if (base_allocator_system.reserve == 0){
base_allocator_system = make_base_allocator_system(system);
base_allocator_system = make_base_allocator_system();
}
return(&base_allocator_system);
}
internal Arena
make_arena_system(System_Functions *system, umem chunk_size, umem align){
return(make_arena(get_base_allocator_system(system), chunk_size, align));
make_arena_system(umem chunk_size, umem align){
return(make_arena(get_base_allocator_system(), chunk_size, align));
}
internal Arena
make_arena_system(System_Functions *system, umem chunk_size){
return(make_arena_system(system, chunk_size, 8));
make_arena_system(umem chunk_size){
return(make_arena_system(chunk_size, 8));
}
internal Arena
make_arena_system(System_Functions *system){
return(make_arena_system(system, KB(16), 8));
make_arena_system(void){
return(make_arena_system(KB(16), 8));
}
// BOTTOM

View File

@ -15,6 +15,12 @@ function API_Definition*
define_api(Arena *arena){
API_Definition *api = begin_api(arena, "system");
{
API_Call *call = api_call(arena, api, "get_path", "String_Const_u8");
api_param(arena, call, "Arena*", "arena");
api_param(arena, call, "System_Path_Code", "path_code");
}
{
API_Call *call = api_call(arena, api, "get_canonical", "String_Const_u8");
api_param(arena, call, "Arena*", "arena");
@ -77,7 +83,7 @@ define_api(Arena *arena){
}
{
API_Call *call = api_call(arena, api, "get_proc", "Void_Func");
API_Call *call = api_call(arena, api, "get_proc", "Void_Func*");
api_param(arena, call, "System_Library", "handle");
api_param(arena, call, "char*", "proc_name");
}

42
4ed_system_types.h Normal file
View File

@ -0,0 +1,42 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 21.01.2015
*
* System API types.
*
*/
// TOP
#if !defined(FCODER_SYSTEM_TYPES_H)
#define FCODER_SYSTEM_TYPES_H
struct Plat_Handle{
u32 d[4];
};
typedef Plat_Handle System_Library;
typedef Plat_Handle System_Thread;
typedef Plat_Handle System_Mutex;
typedef Plat_Handle System_Condition_Variable;
typedef void Thread_Function(void *ptr);
struct CLI_Handles{
Plat_Handle proc;
Plat_Handle out_read;
Plat_Handle out_write;
Plat_Handle in_read;
Plat_Handle in_write;
u32 scratch_space[4];
i32 exit;
};
typedef i32 System_Path_Code;
enum{
SystemPath_CurrentDirectory,
SystemPath_Binary,
};
#endif
// BOTTOM

View File

@ -369,7 +369,7 @@ view_post_paste_effect(View *view, f32 seconds, i64 start, i64 size, u32 color){
////////////////////////////////
internal void
view_set_file(System_Functions *system, Models *models, View *view, Editing_File *file){
view_set_file(Models *models, View *view, Editing_File *file){
Assert(file != 0);
Editing_File *old_file = view->file;
@ -408,7 +408,7 @@ file_is_viewed(Layout *layout, Editing_File *file){
}
internal void
adjust_views_looking_at_file_to_new_cursor(System_Functions *system, Models *models, Editing_File *file){
adjust_views_looking_at_file_to_new_cursor(Models *models, Editing_File *file){
Layout *layout = &models->layout;
for (Panel *panel = layout_get_first_open_panel(layout);
panel != 0;
@ -422,7 +422,7 @@ adjust_views_looking_at_file_to_new_cursor(System_Functions *system, Models *mod
}
internal void
global_set_font_and_update_files(System_Functions *system, Models *models, Face *new_global_face){
global_set_font_and_update_files(Models *models, Face *new_global_face){
for (Node *node = models->working_set.active_file_sentinel.next;
node != &models->working_set.active_file_sentinel;
node = node->next){
@ -433,7 +433,7 @@ global_set_font_and_update_files(System_Functions *system, Models *models, Face
}
internal b32
release_font_and_update(System_Functions *system, Models *models, Face *face, Face *replacement_face){
release_font_and_update(Models *models, Face *face, Face *replacement_face){
b32 success = false;
Assert(replacement_face != 0 && replacement_face != face);
if (font_set_release_face(&models->font_set, face->id)){
@ -465,7 +465,7 @@ finalize_color(Color_Table color_table, int_color color){
}
internal void
view_quit_ui(System_Functions *system, Models *models, View *view){
view_quit_ui(Models *models, View *view){
Assert(view != 0);
view->ui_mode = false;
if (view->ui_quit != 0){
@ -490,112 +490,5 @@ imp_get_view(Models *models, View_ID view_id){
return(view);
}
////////////////////////////////
#if 0
internal void
render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *view,
Rect_i32 rect,
Full_Cursor render_cursor,
Interval_i64 on_screen_range,
Buffer_Layout_Item_List list,
int_color *item_colors){
Cpp_Token_Array token_array = file->state.token_array;
b32 tokens_use = (token_array.tokens != 0);
i64 token_i = 0;
u32 main_color = color_table.vals[Stag_Default];
u32 special_color = color_table.vals[Stag_Special_Character];
u32 ghost_color = color_table.vals[Stag_Ghost_Character];
if (tokens_use){
Cpp_Get_Token_Result result = cpp_get_token(token_array, (i32)items->index);
main_color = get_token_color(color_table, token_array.tokens[result.token_index]);
token_i = result.token_index + 1;
}
{
i64 ind = item->index;
// NOTE(allen): Token scanning
u32 highlight_this_color = 0;
if (tokens_use && ind != prev_ind){
Token current_token = token_array.tokens[token_i-1];
if (token_i < token_array.count){
if (ind >= token_array.tokens[token_i].start){
for (;token_i < token_array.count && ind >= token_array.tokens[token_i].start; ++token_i){
main_color = get_token_color(color_table, token_array.tokens[token_i]);
current_token = token_array.tokens[token_i];
}
}
else if (ind >= current_token.start + current_token.size){
main_color = color_table.vals[Stag_Default];
}
}
if (current_token.type == CPP_TOKEN_JUNK && ind >= current_token.start && ind < current_token.start + current_token.size){
highlight_color = color_table.vals[Stag_Highlight_Junk];
}
else{
highlight_color = 0;
}
}
u32 char_color = main_color;
if (on_screen_range.min <= ind && ind < on_screen_range.max){
i64 index_shifted = ind - on_screen_range.min;
if (item_colors[index_shifted] != 0){
char_color = finalize_color(color_table, item_colors[index_shifted]);
}
}
if (HasFlag(item->flags, BRFlag_Special_Character)){
char_color = special_color;
}
else if (HasFlag(item->flags, BRFlag_Ghost_Character)){
char_color = ghost_color;
}
if (view->show_whitespace && highlight_color == 0 && codepoint_is_whitespace(item->codepoint)){
highlight_this_color = color_table.vals[Stag_Highlight_White];
}
else{
highlight_this_color = highlight_color;
}
// NOTE(allen): Perform highlight, wireframe, and ibar renders
u32 color_highlight = 0;
u32 color_wireframe = 0;
u32 color_ibar = 0;
if (highlight_this_color != 0){
if (color_highlight == 0){
color_highlight = highlight_this_color;
}
}
if (color_highlight != 0){
draw_rectangle(target, char_rect, color_highlight);
}
u32 fade_color = 0xFFFF00FF;
f32 fade_amount = 0.f;
if (file->state.paste_effect.seconds_down > 0.f &&
file->state.paste_effect.start <= ind &&
ind < file->state.paste_effect.end){
fade_color = file->state.paste_effect.color;
fade_amount = file->state.paste_effect.seconds_down;
fade_amount /= file->state.paste_effect.seconds_max;
}
char_color = color_blend(char_color, fade_amount, fade_color);
if (color_wireframe != 0){
draw_rectangle_outline(target, char_rect, color_wireframe);
}
}
}
#endif
// BOTTOM

View File

@ -17,17 +17,17 @@ working_set_file_default_settings(Working_Set *working_set, Editing_File *file){
////////////////////////////////
internal void
file_change_notification_check(System_Functions *system, Arena *scratch, Working_Set *working_set, Editing_File *file){
file_change_notification_check(Arena *scratch, Working_Set *working_set, Editing_File *file){
if (file->canon.name_size > 0 && !file->settings.unimportant){
String_Const_u8 name = SCu8(file->canon.name_space, file->canon.name_size);
File_Attributes attributes = system->quick_file_attributes(scratch, name);
File_Attributes attributes = system_quick_file_attributes(scratch, name);
if (attributes.last_write_time > file->attributes.last_write_time){
file_add_dirty_flag(file, DirtyState_UnloadedChanges);
if (file->external_mod_node.next == 0){
LogEventF(log_string(M), &working_set->arena, file->id, 0, system->thread_get_id(),
LogEventF(log_string(M), &working_set->arena, file->id, 0, system_thread_get_id(),
"external modification [lwt=0x%llx]", attributes.last_write_time);
dll_insert_back(&working_set->has_external_mod_sentinel, &file->external_mod_node);
system->signal_step(0);
system_signal_step(0);
}
}
file->attributes = attributes;
@ -37,12 +37,11 @@ file_change_notification_check(System_Functions *system, Arena *scratch, Working
internal void
file_change_notification_thread_main(void *ptr){
Models *models = (Models*)ptr;
System_Functions *system = models->system;
Arena arena = make_arena_system(system);
Arena arena = make_arena_system();
Working_Set *working_set = &models->working_set;
for (;;){
system->sleep(Thousand(250));
Mutex_Lock lock(system, working_set->mutex);
system_sleep(Thousand(250));
Mutex_Lock lock(working_set->mutex);
if (working_set->active_file_count > 0){
i32 check_count = working_set->active_file_count/16;
check_count = clamp(1, check_count, 100);
@ -57,7 +56,7 @@ file_change_notification_thread_main(void *ptr){
if (node == used){
node = node->next;
}
file_change_notification_check(system, &arena, working_set, file);
file_change_notification_check(&arena, working_set, file);
}
working_set->sync_check_iterator = node;
}
@ -117,8 +116,7 @@ working_set_get_file(Working_Set *working_set, Buffer_ID id){
internal void
working_set_init(Models *models, Working_Set *working_set){
block_zero_struct(working_set);
System_Functions *system = models->system;
working_set->arena = make_arena_system(system);
working_set->arena = make_arena_system();
working_set->id_counter = 1;
@ -126,14 +124,14 @@ working_set_init(Models *models, Working_Set *working_set){
dll_init_sentinel(&working_set->touch_order_sentinel);
local_const i32 slot_count = 128;
Base_Allocator *allocator = get_base_allocator_system(system);
Base_Allocator *allocator = get_base_allocator_system();
working_set->id_to_ptr_table = make_table_u64_u64(allocator, slot_count);
working_set->canon_table = make_table_Data_u64(allocator, slot_count);
working_set->name_table = make_table_Data_u64(allocator, slot_count);
dll_init_sentinel(&working_set->has_external_mod_sentinel);
working_set->mutex = system->mutex_make();
working_set->file_change_thread = system->thread_launch(file_change_notification_thread_main, models);
working_set->mutex = system_mutex_make();
working_set->file_change_thread = system_thread_launch(file_change_notification_thread_main, models);
}
internal Editing_File*
@ -187,7 +185,7 @@ working_set_remove_name(Working_Set *working_set, String_Const_u8 name){
}
internal Editing_File*
get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buffer_Identifier buffer){
get_file_from_identifier(Working_Set *working_set, Buffer_Identifier buffer){
Editing_File *file = 0;
if (buffer.id != 0){
file = working_set_get_file(working_set, buffer.id);
@ -269,9 +267,9 @@ working_set_clipboard_roll_down(Working_Set *working){
// TODO(allen): get rid of this???
internal b32
get_canon_name(System_Functions *system, Arena *scratch, String_Const_u8 file_name, Editing_File_Name *canon_name){
get_canon_name(Arena *scratch, String_Const_u8 file_name, Editing_File_Name *canon_name){
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 canonical = system->get_canonical(scratch, file_name);
String_Const_u8 canonical = system_get_canonical(scratch, file_name);
umem size = Min(sizeof(canon_name->name_space), canonical.size);
block_copy(canon_name->name_space, canonical.str, size);
canon_name->name_size = size;
@ -281,7 +279,7 @@ get_canon_name(System_Functions *system, Arena *scratch, String_Const_u8 file_na
}
internal void
file_bind_file_name(System_Functions *system, Working_Set *working_set, Editing_File *file, String_Const_u8 canon_file_name){
file_bind_file_name(Working_Set *working_set, Editing_File *file, String_Const_u8 canon_file_name){
Assert(file->unique_name.name_size == 0);
Assert(file->canon.name_size == 0);
umem size = canon_file_name.size;
@ -294,7 +292,7 @@ file_bind_file_name(System_Functions *system, Working_Set *working_set, Editing_
}
internal void
buffer_unbind_file(System_Functions *system, Working_Set *working_set, Editing_File *file){
buffer_unbind_file(Working_Set *working_set, Editing_File *file){
Assert(file->unique_name.name_size == 0);
Assert(file->canon.name_size != 0);
working_set_canon_remove(working_set, string_from_file_name(&file->canon));

View File

@ -13,8 +13,7 @@
#define FCODER_LOG_CPP
internal String_Const_u8
log_event(Arena *arena, String_Const_u8 event_name, String_Const_u8 src_name, i32 line_number,
i32 buffer, i32 view, i32 thread_id){
log_event(Arena *arena, String_Const_u8 event_name, String_Const_u8 src_name, i32 line_number, i32 buffer, i32 view, i32 thread_id){
List_String_Const_u8 list = {};
string_list_pushf(arena, &list, "%.*s:%d: %.*s",
string_expand(src_name), line_number, string_expand(event_name));

View File

@ -1,5 +1,6 @@
function void
system_api_fill_vtable(API_VTable_system *vtable){
vtable->get_path = system_get_path;
vtable->get_canonical = system_get_canonical;
vtable->get_file_list = system_get_file_list;
vtable->quick_file_attributes = system_quick_file_attributes;
@ -46,6 +47,7 @@ vtable->is_fullscreen = system_is_fullscreen;
#if defined(DYNAMIC_LINK_API)
function void
system_api_read_vtable(API_VTable_system *vtable){
system_get_path = vtable->get_path;
system_get_canonical = vtable->get_canonical;
system_get_file_list = vtable->get_file_list;
system_quick_file_attributes = vtable->quick_file_attributes;

View File

@ -1,3 +1,4 @@
#define system_get_path_sig() String_Const_u8 system_get_path(Arena* arena, System_Path_Code path_code)
#define system_get_canonical_sig() String_Const_u8 system_get_canonical(Arena* arena, String_Const_u8 name)
#define system_get_file_list_sig() File_List system_get_file_list(Arena* arena, String_Const_u8 directory)
#define system_quick_file_attributes_sig() File_Attributes system_quick_file_attributes(Arena* scratch, String_Const_u8 file_name)
@ -8,7 +9,7 @@
#define system_save_file_sig() File_Attributes system_save_file(Arena* scratch, char* file_name, String_Const_u8 data)
#define system_load_library_sig() b32 system_load_library(Arena* scratch, String_Const_u8 file_name, System_Library* out)
#define system_release_library_sig() b32 system_release_library(System_Library handle)
#define system_get_proc_sig() Void_Func system_get_proc(System_Library handle, char* proc_name)
#define system_get_proc_sig() Void_Func* system_get_proc(System_Library handle, char* proc_name)
#define system_now_time_sig() u64 system_now_time(void)
#define system_wake_up_timer_create_sig() Plat_Handle system_wake_up_timer_create(void)
#define system_wake_up_timer_release_sig() void system_wake_up_timer_release(Plat_Handle handle)
@ -40,6 +41,7 @@
#define system_show_mouse_cursor_sig() void system_show_mouse_cursor(i32 show)
#define system_set_fullscreen_sig() b32 system_set_fullscreen(b32 full_screen)
#define system_is_fullscreen_sig() b32 system_is_fullscreen(void)
typedef String_Const_u8 system_get_path_type(Arena* arena, System_Path_Code path_code);
typedef String_Const_u8 system_get_canonical_type(Arena* arena, String_Const_u8 name);
typedef File_List system_get_file_list_type(Arena* arena, String_Const_u8 directory);
typedef File_Attributes system_quick_file_attributes_type(Arena* scratch, String_Const_u8 file_name);
@ -50,7 +52,7 @@ typedef b32 system_load_close_type(Plat_Handle handle);
typedef File_Attributes system_save_file_type(Arena* scratch, char* file_name, String_Const_u8 data);
typedef b32 system_load_library_type(Arena* scratch, String_Const_u8 file_name, System_Library* out);
typedef b32 system_release_library_type(System_Library handle);
typedef Void_Func system_get_proc_type(System_Library handle, char* proc_name);
typedef Void_Func* system_get_proc_type(System_Library handle, char* proc_name);
typedef u64 system_now_time_type(void);
typedef Plat_Handle system_wake_up_timer_create_type(void);
typedef void system_wake_up_timer_release_type(Plat_Handle handle);
@ -83,6 +85,7 @@ typedef void system_show_mouse_cursor_type(i32 show);
typedef b32 system_set_fullscreen_type(b32 full_screen);
typedef b32 system_is_fullscreen_type(void);
struct API_VTable_system{
system_get_path_type *get_path;
system_get_canonical_type *get_canonical;
system_get_file_list_type *get_file_list;
system_quick_file_attributes_type *quick_file_attributes;
@ -127,6 +130,7 @@ system_set_fullscreen_type *set_fullscreen;
system_is_fullscreen_type *is_fullscreen;
};
#if defined(STATIC_LINK_API)
internal String_Const_u8 system_get_path(Arena* arena, System_Path_Code path_code);
internal String_Const_u8 system_get_canonical(Arena* arena, String_Const_u8 name);
internal File_List system_get_file_list(Arena* arena, String_Const_u8 directory);
internal File_Attributes system_quick_file_attributes(Arena* scratch, String_Const_u8 file_name);
@ -137,7 +141,7 @@ internal b32 system_load_close(Plat_Handle handle);
internal File_Attributes system_save_file(Arena* scratch, char* file_name, String_Const_u8 data);
internal b32 system_load_library(Arena* scratch, String_Const_u8 file_name, System_Library* out);
internal b32 system_release_library(System_Library handle);
internal Void_Func system_get_proc(System_Library handle, char* proc_name);
internal Void_Func* system_get_proc(System_Library handle, char* proc_name);
internal u64 system_now_time(void);
internal Plat_Handle system_wake_up_timer_create(void);
internal void system_wake_up_timer_release(Plat_Handle handle);
@ -171,6 +175,7 @@ internal b32 system_set_fullscreen(b32 full_screen);
internal b32 system_is_fullscreen(void);
#undef STATIC_LINK_API
#elif defined(DYNAMIC_LINK_API)
global system_get_path_type *system_get_path = 0;
global system_get_canonical_type *system_get_canonical = 0;
global system_get_file_list_type *system_get_file_list = 0;
global system_quick_file_attributes_type *system_quick_file_attributes = 0;

View File

@ -1,73 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 18.07.2017
*
* Code to link system functions using a name convention
*
*/
// TOP
// TODO(allen): Should auto-gen this!
#define SYSLINK(name) sysfunc.name = system_##name
internal void
link_system_code(void){
SYSLINK(get_canonical);
SYSLINK(get_file_list);
SYSLINK(quick_file_attributes);
SYSLINK(load_handle);
SYSLINK(load_attributes);
SYSLINK(load_file);
SYSLINK(load_close);
SYSLINK(save_file);
SYSLINK(load_library);
SYSLINK(release_library);
SYSLINK(get_proc);
SYSLINK(now_time);
SYSLINK(wake_up_timer_create);
SYSLINK(wake_up_timer_release);
SYSLINK(wake_up_timer_set);
SYSLINK(signal_step);
SYSLINK(sleep);
SYSLINK(post_clipboard);
SYSLINK(cli_call);
SYSLINK(cli_begin_update);
SYSLINK(cli_update_step);
SYSLINK(cli_end_update);
SYSLINK(open_color_picker);
SYSLINK(get_screen_scale_factor);
SYSLINK(thread_launch);
SYSLINK(thread_join);
SYSLINK(thread_free);
SYSLINK(thread_get_id);
SYSLINK(mutex_make);
SYSLINK(mutex_acquire);
SYSLINK(mutex_release);
SYSLINK(mutex_free);
SYSLINK(condition_variable_make);
SYSLINK(condition_variable_wait);
SYSLINK(condition_variable_signal);
SYSLINK(condition_variable_free);
SYSLINK(memory_allocate);
SYSLINK(memory_set_protection);
SYSLINK(memory_free);
SYSLINK(get_path);
SYSLINK(set_fullscreen);
SYSLINK(is_fullscreen);
SYSLINK(show_mouse_cursor);
}
// BOTTOM

View File

@ -1,97 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 19.07.2017
*
* Cross platform library constants
*
*/
// TOP
#error remove this file
#if 0
#if !defined(FRED_SHARED_LIBRARY_CONSTANTS_H)
#define FRED_SHARED_LIBRARY_CONSTANTS_H
// Wrapper functions
union Library;
internal b32
system_load_library_direct(Arena *scratch, Library *library, char *name);
internal void*
system_get_proc(Library *library, char *name);
internal void
system_free_library(Library *library);
// Shared logic
#define LIBRARY_TYPE_SIZE 32
#define AssertLibrarySizes() Assert(sizeof(Library) == LIBRARY_TYPE_SIZE)
typedef u32 Load_Library_Location;
enum{
LoadLibrary_CurrentDirectory,
LoadLibrary_BinaryDirectory,
};
internal b32
system_load_library(Arena *scratch, Library *library, char *name_cstr, Load_Library_Location location, char *full_file_out, u32 full_file_max){
Temp_Memory temp = begin_temp(scratch);
String_Const_char name = SCchar(name_cstr);
String_Const_char extension = string_file_extension(name);
if (!string_match(extension, string_litexpr( DLL ))){
String_Const_char full_name = push_stringf(scratch, "%.*s." DLL, string_expand(name));
name_cstr = full_name.str;
}
String_Const_u8 path = {};
switch (location){
case LoadLibrary_CurrentDirectory:
{
path = sysfunc.get_current_path(scratch);
}break;
case LoadLibrary_BinaryDirectory:
{
path = sysfunc.get_4ed_path(scratch);
}break;
//default: LOG("Invalid library location passed.\n"); break;
}
b32 success = false;
if (path.size > 0){
if (path.str[path.size - 1] != SLASH){
path = push_u8_stringf(scratch, "%.*s%c%.*s", string_expand(path), SLASH, string_expand(name));
}
else{
path = push_u8_stringf(scratch, "%.*s%.*s", string_expand(path), string_expand(name));
}
success = system_load_library_direct(scratch, library, (char*)path.str);
}
if (success && full_file_out != 0 && full_file_out > 0){
u32 fill_size = clamp_top((u32)(path.size), (u32)(full_file_max - 1));
block_copy(full_file_out, path.str, fill_size);
full_file_out[fill_size] = 0;
}
end_temp(temp);
return(success);
}
internal b32
system_load_library(Arena *scratch, Library *library, char *name, Load_Library_Location location){
return(system_load_library(scratch, library, name, location, 0, 0));
}
#endif
#endif
// BOTTOM

View File

@ -21,12 +21,23 @@
#include "api/4coder_types.h"
#include "4ed_font_interface.h"
#include "4ed_system_types.h"
#define STATIC_LINK_API
#include "generated/system_api.h"
#define STATIC_LINK_API
#include "generated/graphics_api.h"
#define STATIC_LINK_API
#include "generated/font_api.h"
#include "4ed_font_set.h"
#include "4ed_system.h"
#include "4ed_render_target.h"
#include "4ed_search_list.h"
#include "4ed.h"
#include "generated/system_api.cpp"
#include "generated/graphics_api.cpp"
#include "generated/font_api.cpp"
#include "4coder_base_types.cpp"
#include "4coder_stringf.cpp"
#include "4coder_hash_functions.cpp"
@ -105,8 +116,6 @@ struct Win32_Input_Chunk{
////////////////////////////////
global System_Functions sysfunc = {};
typedef i32 Win32_Object_Kind;
enum{
Win32ObjectKind_ERROR = 0,
@ -247,7 +256,7 @@ handle_type_ptr(void *ptr){
////////////////////////////////
internal
Sys_Load_Library_Sig(system_load_library){
system_load_library_sig(){
HMODULE lib = LoadLibrary_utf8String(scratch, file_name);
b32 result = false;
if (lib != 0){
@ -258,13 +267,13 @@ Sys_Load_Library_Sig(system_load_library){
}
internal
Sys_Release_Library_Sig(system_release_library){
system_release_library_sig(){
HMODULE lib = (HMODULE)handle_type(handle);
return(FreeLibrary(lib));
}
internal
Sys_Get_Proc_Sig(system_get_proc){
system_get_proc_sig(){
HMODULE lib = (HMODULE)handle_type(handle);
return((Void_Func*)(GetProcAddress(lib, proc_name)));
}
@ -307,12 +316,12 @@ win32_toggle_fullscreen(){
// TODO(allen): add a "shown but auto-hides on timer" setting here.
internal
Sys_Show_Mouse_Cursor_Sig(system_show_mouse_cursor){
system_show_mouse_cursor_sig(){
win32vars.cursor_show = show;
}
internal
Sys_Set_Fullscreen_Sig(system_set_fullscreen){
system_set_fullscreen_sig(){
// NOTE(allen): If the new value of full_screen does not match the current value,
// set toggle to true.
win32vars.do_toggle = (win32vars.full_screen != full_screen);
@ -321,10 +330,10 @@ Sys_Set_Fullscreen_Sig(system_set_fullscreen){
}
internal
Sys_Is_Fullscreen_Sig(system_is_fullscreen){
// NOTE(allen): Report the fullscreen status as it would be set at the beginning of the next frame.
// That is, take into account all fullscreen toggle requests that have come in already this frame.
// Read: "full_screen XOR do_toggle"
system_is_fullscreen_sig(){
// NOTE(allen): Report the fullscreen status as it would be set at the beginning of the
// next frame. That is, take into account all fullscreen toggle requests that have come in
// already this frame. Read: "full_screen XOR do_toggle"
b32 result = (win32vars.full_screen != win32vars.do_toggle);
return(result);
}
@ -353,10 +362,10 @@ win32_post_clipboard(Arena *scratch, char *text, i32 len){
}
internal
Sys_Post_Clipboard_Sig(system_post_clipboard){
system_post_clipboard_sig(){
Arena *arena = &win32vars.clip_post_arena;
if (arena->base_allocator == 0){
*arena = make_arena_system(&sysfunc);
*arena = make_arena_system();
}
else{
linalloc_clear(arena);
@ -432,14 +441,14 @@ win32_read_clipboard_contents(Arena *scratch){
//
internal
Sys_CLI_Call_Sig(system_cli_call, scratch, path, script_name, cli_out){
system_cli_call_sig(){
Assert(sizeof(Plat_Handle) >= sizeof(HANDLE));
char cmd[] = "c:\\windows\\system32\\cmd.exe";
char *env_variables = 0;
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 s = push_u8_stringf(scratch, "/C %s", script_name);
String_Const_u8 s = push_u8_stringf(scratch, "/C %s", script);
b32 success = false;
@ -504,14 +513,14 @@ struct CLI_Loop_Control{
};
internal
Sys_CLI_Begin_Update_Sig(system_cli_begin_update){
system_cli_begin_update_sig(){
Assert(sizeof(cli->scratch_space) >= sizeof(CLI_Loop_Control));
CLI_Loop_Control *loop = (CLI_Loop_Control*)cli->scratch_space;
loop->remaining_amount = 0;
}
internal
Sys_CLI_Update_Step_Sig(system_cli_update_step){
system_cli_update_step_sig(){
HANDLE handle = *(HANDLE*)&cli->out_read;
CLI_Loop_Control *loop = (CLI_Loop_Control*)cli->scratch_space;
b32 has_more = 0;
@ -547,7 +556,7 @@ Sys_CLI_Update_Step_Sig(system_cli_update_step){
}
internal
Sys_CLI_End_Update_Sig(system_cli_end_update){
system_cli_end_update_sig(){
b32 close_me = false;
HANDLE proc = *(HANDLE*)&cli->proc;
DWORD result = 0;
@ -583,6 +592,21 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
#include <GL/gl.h>
#include "opengl/4ed_opengl_render.cpp"
internal
graphics_get_texture_sig(){
return(gl__get_texture(dim, texture_kind));
}
internal
graphics_fill_texture_sig(){
return(gl__fill_texture(texture_kind, texture, p, dim, data));
}
internal
font_make_face_sig(){
return(ft__font_make_face(arena, description, scale_factor));
}
//
// Helpers
//
@ -834,7 +858,7 @@ win32_free_object(Win32_Object *object){
////////////////////////////////
internal
Sys_Now_Time_Sig(system_now_time){
system_now_time_sig(){
u64 result = 0;
LARGE_INTEGER t;
if (QueryPerformanceCounter(&t)){
@ -844,7 +868,7 @@ Sys_Now_Time_Sig(system_now_time){
}
internal
Sys_Wake_Up_Timer_Create_Sig(system_wake_up_timer_create){
system_wake_up_timer_create_sig(){
Win32_Object *object = win32_alloc_object(Win32ObjectKind_Timer);
dll_insert(&win32vars.timer_objects, &object->node);
object->timer.id = ++win32vars.timer_counter;
@ -852,7 +876,7 @@ Sys_Wake_Up_Timer_Create_Sig(system_wake_up_timer_create){
}
internal
Sys_Wake_Up_Timer_Release_Sig(system_wake_up_timer_release){
system_wake_up_timer_release_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(handle);
if (object->kind == Win32ObjectKind_Timer){
KillTimer(win32vars.window_handle, object->timer.id);
@ -861,7 +885,7 @@ Sys_Wake_Up_Timer_Release_Sig(system_wake_up_timer_release){
}
internal
Sys_Wake_Up_Timer_Set_Sig(system_wake_up_timer_set){
system_wake_up_timer_set_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(handle);
if (object->kind == Win32ObjectKind_Timer){
object->timer.id = SetTimer(win32vars.window_handle, object->timer.id, time_milliseconds, 0);
@ -869,12 +893,12 @@ Sys_Wake_Up_Timer_Set_Sig(system_wake_up_timer_set){
}
internal
Sys_Signal_Step_Sig(system_signal_step){
system_signal_step_sig(){
system_schedule_step(code);
}
internal
Sys_Sleep_Sig(system_sleep){
system_sleep_sig(){
u32 milliseconds = (u32)(microseconds/Thousand(1));
Sleep(milliseconds);
}
@ -895,7 +919,7 @@ win32_thread_wrapper(void *ptr){
}
internal
Sys_Thread_Launch_Sig(system_thread_launch){
system_thread_launch_sig(){
Win32_Object *object = win32_alloc_object(Win32ObjectKind_Thread);
object->thread.proc = proc;
object->thread.ptr = ptr;
@ -910,7 +934,7 @@ Sys_Thread_Launch_Sig(system_thread_launch){
}
internal
Sys_Thread_Join_Sig(system_thread_join){
system_thread_join_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(thread);
if (object->kind == Win32ObjectKind_Thread){
WaitForSingleObject(object->thread.thread, INFINITE);
@ -918,7 +942,7 @@ Sys_Thread_Join_Sig(system_thread_join){
}
internal
Sys_Thread_Free_Sig(system_thread_free){
system_thread_free_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(thread);
if (object->kind == Win32ObjectKind_Thread){
CloseHandle(object->thread.thread);
@ -927,20 +951,20 @@ Sys_Thread_Free_Sig(system_thread_free){
}
internal
Sys_Thread_Get_ID_Sig(system_thread_get_id){
system_thread_get_id_sig(){
DWORD result = GetCurrentThreadId();
return((i32)result);
}
internal
Sys_Mutex_Make_Sig(system_mutex_make){
system_mutex_make_sig(){
Win32_Object *object = win32_alloc_object(Win32ObjectKind_Mutex);
InitializeCriticalSection(&object->mutex);
return(handle_type(object));
}
internal
Sys_Mutex_Acquire_Sig(system_mutex_acquire){
system_mutex_acquire_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(mutex);
if (object->kind == Win32ObjectKind_Mutex){
EnterCriticalSection(&object->mutex);
@ -948,7 +972,7 @@ Sys_Mutex_Acquire_Sig(system_mutex_acquire){
}
internal
Sys_Mutex_Release_Sig(system_mutex_release){
system_mutex_release_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(mutex);
if (object->kind == Win32ObjectKind_Mutex){
LeaveCriticalSection(&object->mutex);
@ -956,7 +980,7 @@ Sys_Mutex_Release_Sig(system_mutex_release){
}
internal
Sys_Mutex_Free_Sig(system_mutex_free){
system_mutex_free_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(mutex);
if (object->kind == Win32ObjectKind_Mutex){
DeleteCriticalSection(&object->mutex);
@ -965,14 +989,14 @@ Sys_Mutex_Free_Sig(system_mutex_free){
}
internal
Sys_Condition_Variable_Make_Sig(system_condition_variable_make){
system_condition_variable_make_sig(){
Win32_Object *object = win32_alloc_object(Win32ObjectKind_CV);
InitializeConditionVariable(&object->cv);
return(handle_type(object));
}
internal
Sys_Condition_Variable_Wait_Sig(system_condition_variable_wait){
system_condition_variable_wait_sig(){
Win32_Object *object_cv = (Win32_Object*)handle_type_ptr(cv);
Win32_Object *object_mutex = (Win32_Object*)handle_type_ptr(mutex);
if (object_cv->kind == Win32ObjectKind_CV &&
@ -982,7 +1006,7 @@ Sys_Condition_Variable_Wait_Sig(system_condition_variable_wait){
}
internal
Sys_Condition_Variable_Signal_Sig(system_condition_variable_signal){
system_condition_variable_signal_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(cv);
if (object->kind == Win32ObjectKind_CV){
WakeConditionVariable(&object->cv);
@ -990,7 +1014,7 @@ Sys_Condition_Variable_Signal_Sig(system_condition_variable_signal){
}
internal
Sys_Condition_Variable_Free_Sig(system_condition_variable_free){
system_condition_variable_free_sig(){
Win32_Object *object = (Win32_Object*)handle_type_ptr(cv);
if (object->kind == Win32ObjectKind_CV){
win32_free_object(object);
@ -1487,28 +1511,29 @@ win32_gl_create_window(HWND *wnd_out, HGLRC *context_out, DWORD style, RECT rect
////////////////////////////////
#include "4ed_link_system_functions.cpp"
int CALL_CONVENTION
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
i32 argc = __argc;
char **argv = __argv;
// NOTE(allen): link
sysfunc.font_make_face = ft__font_make_face;
sysfunc.get_texture = gl__get_texture;
sysfunc.fill_texture = gl__fill_texture;
link_system_code();
// NOTE(allen): memory
Thread_Context _tctx = {};
thread_ctx_init(&_tctx, get_base_allocator_system(&sysfunc));
thread_ctx_init(&_tctx, get_base_allocator_system());
block_zero_struct(&win32vars);
win32vars.tctx = &_tctx;
API_VTable_system system_vtable = {};
system_api_fill_vtable(&system_vtable);
API_VTable_graphics graphics_vtable = {};
graphics_api_fill_vtable(&graphics_vtable);
API_VTable_font font_vtable = {};
font_api_fill_vtable(&font_vtable);
// TODO(allen): *arena;
target.arena = make_arena_system(&sysfunc);
target.arena = make_arena_system();
win32vars.cursor_show = MouseCursorShow_Always;
win32vars.prev_cursor_show = MouseCursorShow_Always;
@ -1537,9 +1562,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
App_Get_Functions *get_funcs = 0;
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
Path_Search_List search_list = {};
search_list_add_system_path(&sysfunc, scratch, &search_list, SystemPath_Binary);
search_list_add_system_path(scratch, &search_list, SystemPath_Binary);
String_Const_u8 core_path = get_full_path(&sysfunc, scratch, &search_list, SCu8("4ed_app.dll"));
String_Const_u8 core_path = get_full_path(scratch, &search_list, SCu8("4ed_app.dll"));
if (system_load_library(scratch, core_path, &core_library)){
get_funcs = (App_Get_Functions*)system_get_proc(core_library, "app_get_functions");
if (get_funcs != 0){
@ -1555,18 +1580,21 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
system_error_box(scratch, msg);
}
}
win32vars.log_string = app.get_logger(&sysfunc);
// NOTE(allen): send system vtable to core
app.load_vtables(&system_vtable, &font_vtable, &graphics_vtable);
win32vars.log_string = app.get_logger();
// NOTE(allen): init & command line parameters
Plat_Settings plat_settings = {};
void *base_ptr = 0;
{
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
String_Const_u8 curdir = sysfunc.get_path(scratch, SystemPath_CurrentDirectory);
String_Const_u8 curdir = system_get_path(scratch, SystemPath_CurrentDirectory);
curdir = string_mod_replace_character(curdir, '\\', '/');
char **files = 0;
i32 *file_count = 0;
base_ptr = app.read_command_line(win32vars.tctx, &sysfunc, curdir, &plat_settings, &files, &file_count, argc, argv);
base_ptr = app.read_command_line(win32vars.tctx, curdir, &plat_settings, &files, &file_count, argc, argv);
{
i32 end = *file_count;
i32 i = 0, j = 0;
@ -1591,8 +1619,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
String_Const_u8 default_file_name = string_u8_litexpr("custom_4coder.dll");
Path_Search_List search_list = {};
search_list_add_system_path(&sysfunc, scratch, &search_list, SystemPath_CurrentDirectory);
search_list_add_system_path(&sysfunc, scratch, &search_list, SystemPath_Binary);
search_list_add_system_path(scratch, &search_list, SystemPath_CurrentDirectory);
search_list_add_system_path(scratch, &search_list, SystemPath_Binary);
String_Const_u8 custom_file_names[2] = {};
i32 custom_file_count = 1;
if (plat_settings.custom_dll != 0){
@ -1607,7 +1635,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
}
String_Const_u8 custom_file_name = {};
for (i32 i = 0; i < custom_file_count; i += 1){
custom_file_name = get_full_path(&sysfunc, scratch, &search_list, custom_file_names[i]);
custom_file_name = get_full_path(scratch, &search_list, custom_file_names[i]);
if (custom_file_name.size > 0){
break;
}
@ -1711,9 +1739,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
{
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
String_Const_u8 curdir = sysfunc.get_path(scratch, SystemPath_CurrentDirectory);
String_Const_u8 curdir = system_get_path(scratch, SystemPath_CurrentDirectory);
curdir = string_mod_replace_character(curdir, '\\', '/');
app.init(&sysfunc, &target, base_ptr, win32vars.clipboard_contents, curdir, custom);
app.init(&target, base_ptr, win32vars.clipboard_contents, curdir, custom);
}
//
@ -1917,7 +1945,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// NOTE(allen): Application Core Update
Application_Step_Result result = {};
if (app.step != 0){
result = app.step(&sysfunc, &target, base_ptr, &input);
result = app.step(&target, base_ptr, &input);
}
else{
//LOG("app.step == 0 -- skipping\n");

View File

@ -25,18 +25,18 @@ system_file_can_be_made(Arena *scratch, u8 *filename){
//
internal void*
system_memory_allocate_extended(void *base, umem size){
win32_memory_allocate_extended(void *base, umem size){
void *result = VirtualAlloc(base, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
return(result);
}
internal
Sys_Memory_Allocate_Sig(system_memory_allocate){
return(system_memory_allocate_extended(0, size));
system_memory_allocate_sig(){
return(win32_memory_allocate_extended(0, size));
}
internal
Sys_Memory_Set_Protection_Sig(system_memory_set_protection){
system_memory_set_protection_sig(){
b32 result = false;
DWORD old_protect = 0;
DWORD protect = 0;
@ -57,7 +57,7 @@ Sys_Memory_Set_Protection_Sig(system_memory_set_protection){
}
internal
Sys_Memory_Free_Sig(system_memory_free){
system_memory_free_sig(){
VirtualFree(ptr, 0, MEM_RELEASE);
}
@ -66,9 +66,9 @@ Sys_Memory_Free_Sig(system_memory_free){
//
internal
Sys_Get_Path_Sig(system_get_path){
system_get_path_sig(){
String_Const_u8 result = {};
switch (code){
switch (path_code){
case SystemPath_CurrentDirectory:
{
DWORD size = GetCurrentDirectory_utf8(arena, 0, 0);
@ -122,7 +122,7 @@ win32_remove_unc_prefix_characters(String_Const_u8 path){
}
internal
Sys_Get_Canonical_Sig(system_get_canonical){
system_get_canonical_sig(){
String_Const_u8 result = {};
if ((character_is_alpha(string_get_character(name, 0)) &&
string_get_character(name, 1) == ':') ||
@ -207,7 +207,7 @@ win32_file_attributes_from_HANDLE(HANDLE file){
}
internal
Sys_Get_File_List_Sig(system_get_file_list){
system_get_file_list_sig(){
File_List result = {};
String_Const_u8 search_pattern = {};
if (character_is_slash(string_get_character(directory, directory.size - 1))){
@ -262,7 +262,7 @@ Sys_Get_File_List_Sig(system_get_file_list){
}
internal
Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){
system_quick_file_attributes_sig(){
WIN32_FILE_ATTRIBUTE_DATA info = {};
File_Attributes result = {};
if (GetFileAttributesEx_utf8String(scratch, file_name, GetFileExInfoStandard, &info)){
@ -274,24 +274,24 @@ Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){
}
internal
Sys_Load_Handle_Sig(system_load_handle){
system_load_handle_sig(){
b32 result = false;
HANDLE file = CreateFile_utf8(scratch, (u8*)filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
HANDLE file = CreateFile_utf8(scratch, (u8*)file_name, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
*(HANDLE*)handle_out = file;
*(HANDLE*)out = file;
result = true;
}
return(result);
}
internal
Sys_Load_Attributes_Sig(system_load_attributes){
system_load_attributes_sig(){
HANDLE file = *(HANDLE*)(&handle);
return(win32_file_attributes_from_HANDLE(file));
}
internal
Sys_Load_File_Sig(system_load_file){
system_load_file_sig(){
HANDLE file = *(HANDLE*)(&handle);
DWORD read_size = 0;
b32 result = false;
@ -304,7 +304,7 @@ Sys_Load_File_Sig(system_load_file){
}
internal
Sys_Load_Close_Sig(system_load_close){
system_load_close_sig(){
b32 result = false;
HANDLE file = *(HANDLE*)(&handle);
if (CloseHandle(file)){
@ -314,10 +314,10 @@ Sys_Load_Close_Sig(system_load_close){
}
internal
Sys_Save_File_Sig(system_save_file){
system_save_file_sig(){
File_Attributes result = {};
HANDLE file = CreateFile_utf8(scratch, (u8*)filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
HANDLE file = CreateFile_utf8(scratch, (u8*)file_name, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
u64 written_total = 0;
@ -364,9 +364,6 @@ int_color_from_colorref(COLORREF ref, int_color alpha_from){
return(result);
}
internal void
system_schedule_step(u32 code);
internal UINT_PTR CALLBACK
color_picker_hook(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam){
UINT_PTR result = 0;
@ -410,7 +407,7 @@ color_picker_hook(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam){
if(*picker->dest != new_color)
{
*picker->dest = new_color;
system_schedule_step(0);
system_signal_step(0);
}
}
}
@ -475,12 +472,12 @@ color_picker_thread(LPVOID Param)
}
internal
Sys_Open_Color_Picker_Sig(system_open_color_picker){
system_open_color_picker_sig(){
// TODO(allen): review
// NOTE(casey): Because this is going to be used by a semi-permanent thread, we need to copy
// it to system memory where it can live as long as it wants, no matter what we do over here
// on the 4coder threads.
Color_Picker *perm = (Color_Picker*)system_memory_allocate_extended(0, sizeof(Color_Picker));
// NOTE(casey): Because this is going to be used by a semi-permanent thread, we need to
// copy it to system memory where it can live as long as it wants, no matter what we do
// over here on the 4coder threads.
Color_Picker *perm = (Color_Picker*)system_memory_allocate(sizeof(Color_Picker));
*perm = *picker;
HANDLE ThreadHandle = CreateThread(0, 0, color_picker_thread, perm, 0, 0);
@ -488,7 +485,7 @@ Sys_Open_Color_Picker_Sig(system_open_color_picker){
}
internal
Sys_Get_Screen_Scale_Factor_Sig(system_get_screen_scale_factor){
system_get_screen_scale_factor_sig(){
return(win32vars.screen_scale_factor);
}

View File

@ -1,4 +1,10 @@
usability:
[] paste-next broken
[] select scope broken
[] auto-indent broken
[] cursor in wrong spot after build
Long Term
{
Features