unifying use of working_set's table

This commit is contained in:
Allen Webster 2016-02-07 16:15:58 -05:00
parent 959bdcd8cf
commit 5abea3ce3c
8 changed files with 3158 additions and 3139 deletions

22
4ed.cpp
View File

@ -789,6 +789,7 @@ app_open_file_background(App_Vars *vars, Exchange *exchange, Working_Set *workin
if (file_id){
result.is_new = 1;
result.file = file.file;
file_init_strings(result.file);
file_set_name(result.file, filename.str);
file_set_to_loading(result.file);
table_add(&working_set->table, result.file->name.source_path, file.index);
@ -923,16 +924,17 @@ COMMAND_DECL(save){
ProfileMomentFunction();
REQ_FILE_VIEW(view);
REQ_FILE(file, view);
USE_VARS(vars);
USE_MEM(mem);
USE_EXCHANGE(exchange);
USE_WORKING_SET(working_set);
USE_DELAY(delay);
USE_PANEL(panel);
delayed_action(delay, DACT_SAVE, file->name.source_path, panel);
#if 0
String *file_path = &file->name.source_path;
if (file_path->size > 0){
i32 sys_id = file_save(system, exchange, mem, file, file_path->str);
app_push_file_binding(vars, sys_id, get_file_id(working_set, file));
}
#endif
}
COMMAND_DECL(interactive_save_as){
@ -1678,6 +1680,7 @@ build(System_Functions *system, Mem_Options *mem,
Font_Set *font_set, Style *style,
Live_Views *live_set, Exchange *exchange,
Panel *panel, Command_Data *command,
String hot_directory,
char *buffer_name, i32 buffer_name_len,
char *path, i32 path_len,
char *script, i32 script_len,
@ -1725,7 +1728,7 @@ build(System_Functions *system, Mem_Options *mem,
if (file){
file_create_super_locked(system, mem, file, buffer_name, font_set, style->font_id);
file->settings.unimportant = 1;
table_add(&working_set->table, file->name.live_name, index);
table_add(&working_set->table, file->name.source_path, index);
if (bind_to_new_view){
View *new_view = live_set_alloc_view(live_set, mem);
@ -1735,7 +1738,6 @@ build(System_Functions *system, Mem_Options *mem,
view_set_file(system, file_view, file, font_set, style,
vars->hooks[hook_open_file], command, &app_links);
new_view->map = app_get_map(vars, file->settings.base_map_id);
}
i32 i = vars->cli_processes.count++;
@ -1830,6 +1832,7 @@ COMMAND_DECL(build){
build(system, mem, vars, working_set,
font_set, style, live_set, exchange,
panel, command,
vars->hot_directory.string,
buffer_name, buffer_name_len,
path, path_len,
script, script_len,
@ -1877,6 +1880,7 @@ COMMAND_DECL(build_here){
build(system, mem, vars, working_set,
font_set, style, live_set, exchange,
panel, command,
vars->hot_directory.string,
buffer_name, buffer_name_len,
path.str, path.size,
dir.str, dir.size,
@ -3461,7 +3465,8 @@ App_Step_Sig(app_step){
if (fview){
Editing_File *file = fview->file;
if (file && !file->state.is_dummy){
file_save_and_set_names(system, exchange, mem, file, string->str);
i32 sys_id = file_save_and_set_names(system, exchange, mem, file, string->str);
app_push_file_binding(vars, sys_id, get_file_id(working_set, file));
}
}
}break;
@ -3470,7 +3475,8 @@ App_Step_Sig(app_step){
{
Editing_File *file = working_set_lookup_file(working_set, *string);
if (!file->state.is_dummy){
file_save(system, exchange, mem, file, file->name.source_path.str);
i32 sys_id = file_save(system, exchange, mem, file, file->name.source_path.str);
app_push_file_binding(vars, sys_id, get_file_id(working_set, file));
}
}break;

File diff suppressed because it is too large Load Diff

View File

@ -1205,15 +1205,18 @@ file_init_strings(Editing_File *file){
inline void
file_set_name(Editing_File *file, char *filename){
if (file->name.live_name.str == 0) file_init_strings(file);
if (filename[0] == '*'){
copy(&file->name.live_name, filename);
String f, ext;
Assert(file->name.live_name.str != 0);
f = make_string_slowly(filename);
copy_checked(&file->name.source_path, f);
file->name.live_name.size = 0;
get_front_of_directory(&file->name.live_name, f);
if (file->name.source_path.size == file->name.live_name.size){
file->name.extension.size = 0;
}
else{
String f, ext;
f = make_string_slowly(filename);
copy_checked(&file->name.source_path, f);
get_front_of_directory(&file->name.live_name, f);
ext = file_extension(f);
copy(&file->name.extension, ext);
}
@ -1270,8 +1273,8 @@ inline b32
file_save_and_set_names(System_Functions *system, Exchange *exchange,
Mem_Options *mem, Editing_File *file, char *filename){
b32 result = 0;
if (file_save(system, exchange, mem, file, filename)){
result = 1;
result = file_save(system, exchange, mem, file, filename);
if (result){
file_set_name(file, filename);
}
return result;
@ -2223,7 +2226,7 @@ view_compute_cursor_from_unwrapped_xy(File_View *view, f32 seek_x, f32 seek_y,
#endif
}
inline Full_Cursor
internal Full_Cursor
view_compute_cursor_from_wrapped_xy(File_View *view, f32 seek_x, f32 seek_y,
b32 round_down = 0){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
@ -2246,7 +2249,7 @@ view_compute_cursor_from_wrapped_xy(File_View *view, f32 seek_x, f32 seek_y,
#endif
}
inline Full_Cursor
internal Full_Cursor
view_compute_cursor_from_line_pos(File_View *view, i32 line, i32 pos){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
Editing_File *file = view->file;
@ -2726,20 +2729,22 @@ file_edit_cursor_fix(System_Functions *system,
Editing_File *file, Editing_Layout *layout,
Cursor_Fix_Descriptor desc){
Full_Cursor temp_cursor;
File_View *current_view;
Temp_Memory cursor_temp = begin_temp_memory(part);
i32 cursor_max = layout->panel_max_count * 2;
Cursor_With_Index *cursors = push_array(part, Cursor_With_Index, cursor_max);
f32 y_offset = 0, y_position = 0;
i32 cursor_count = 0;
i32 panel_count = layout->panel_count;
Panel *current_panel = layout->panels;
for (i32 i = 0; i < panel_count; ++i, ++current_panel){
File_View *current_view = view_to_file_view(current_panel->view);
current_view = view_to_file_view(current_panel->view);
if (current_view && current_view->file == file){
view_measure_wraps(system, general, current_view);
write_cursor_with_index(cursors, &cursor_count, current_view->cursor.pos);
write_cursor_with_index(cursors, &cursor_count, current_view->mark);
write_cursor_with_index(cursors, &cursor_count, current_view->scroll_i);
write_cursor_with_index(cursors, &cursor_count, current_view->scroll_i - 1);
}
}
@ -2760,21 +2765,25 @@ file_edit_cursor_fix(System_Functions *system,
cursor_count = 0;
current_panel = layout->panels;
for (i32 i = 0; i < panel_count; ++i, ++current_panel){
File_View *current_view = view_to_file_view(current_panel->view);
current_view = view_to_file_view(current_panel->view);
if (current_view && current_view->file == file){
view_cursor_move(current_view, cursors[cursor_count++].pos);
current_view->preferred_x = view_get_cursor_x(current_view);
current_view->mark = cursors[cursor_count++].pos;
current_view->scroll_i = cursors[cursor_count++].pos;
current_view->scroll_i = cursors[cursor_count++].pos + 1;
temp_cursor = view_compute_cursor_from_pos(current_view, current_view->scroll_i);
y_offset = MOD(current_view->scroll_y, current_view->font_height);
if (current_view->unwrapped_lines){
current_view->target_y += (temp_cursor.unwrapped_y - current_view->scroll_y);
current_view->scroll_y = temp_cursor.unwrapped_y;
y_position = temp_cursor.unwrapped_y + y_offset;
current_view->target_y += (y_position - current_view->scroll_y);
current_view->scroll_y = y_position;
}
else{
current_view->target_y += (temp_cursor.wrapped_y - current_view->scroll_y);
current_view->scroll_y = temp_cursor.wrapped_y;
y_position = temp_cursor.wrapped_y + y_offset;
current_view->target_y += (y_position - current_view->scroll_y);
current_view->scroll_y = y_position;
}
}
}
@ -4189,19 +4198,19 @@ draw_file_bar(File_View *view, Interactive_Bar *bar, Render_Target *target){
intbar_draw_string(target, bar, line_number, base_color);
if (file){
if (!file->settings.unimportant){
switch (buffer_get_sync(file)){
case SYNC_BEHIND_OS:
{
persist String out_of_sync = make_lit_string(" !");
intbar_draw_string(target, bar, out_of_sync, pop2_color);
}break;
case SYNC_UNSAVED:
{
persist String out_of_sync = make_lit_string(" *");
intbar_draw_string(target, bar, out_of_sync, pop2_color);
}break;
case SYNC_BEHIND_OS:
{
persist String out_of_sync = make_lit_string(" !");
intbar_draw_string(target, bar, out_of_sync, pop2_color);
}break;
case SYNC_UNSAVED:
{
persist String out_of_sync = make_lit_string(" *");
intbar_draw_string(target, bar, out_of_sync, pop2_color);
}break;
}
}
}

View File

@ -1,230 +1,230 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 19.09.2015
*
* File editing view for 4coder
*
*/
// TOP
enum Interactive_View_Action{
INTV_OPEN,
INTV_SAVE_AS,
INTV_NEW,
INTV_SWITCH,
INTV_KILL,
INTV_SURE_TO_KILL
};
enum Interactive_View_Interaction{
INTV_SYS_FILE_LIST,
INTV_LIVE_FILE_LIST,
INTV_SURE_TO_KILL_INTER
};
struct Interactive_View{
View view_base;
Hot_Directory *hot_directory;
Style *style;
Working_Set *working_set;
Delay *delay;
Font_Set *font_set;
UI_State state;
Interactive_View_Interaction interaction;
Interactive_View_Action action;
char query_[256];
String query;
char dest_[256];
String dest;
i32 user_action;
};
inline Interactive_View*
view_to_interactive_view(View *view){
Interactive_View *result = 0;
if (view->type == VIEW_TYPE_INTERACTIVE)
result = (Interactive_View*)view;
return result;
}
internal void
interactive_view_complete(Interactive_View *view){
Panel *panel = view->view_base.panel;
switch (view->action){
case INTV_OPEN:
delayed_action(view->delay, DACT_OPEN,
view->hot_directory->string, panel);
break;
case INTV_SAVE_AS:
delayed_action(view->delay, DACT_SAVE_AS, view->hot_directory->string, panel);
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
case INTV_NEW:
delayed_action(view->delay, DACT_NEW, view->hot_directory->string, panel);
break;
case INTV_SWITCH:
delayed_action(view->delay, DACT_SWITCH, view->dest, panel);
break;
case INTV_KILL:
delayed_action(view->delay, DACT_TRY_KILL, view->dest, panel);
break;
case INTV_SURE_TO_KILL:
switch (view->user_action){
case 0:
delayed_action(view->delay, DACT_KILL, view->dest, panel);
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
case 1:
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
case 2:
delayed_action(view->delay, DACT_SAVE, view->dest, panel);
delayed_action(view->delay, DACT_KILL, view->dest, panel);
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
}
break;
}
}
internal i32
step_draw_int_view(System_Functions *system, Interactive_View *view,
Render_Target *target, i32_Rect rect,
Input_Summary *user_input, b32 input_stage){
i32 result = 0;
UI_State state =
ui_state_init(&view->state, target, user_input,
view->style, view->font_set, view->working_set, input_stage);
UI_Layout layout;
begin_layout(&layout, rect);
b32 new_dir = 0;
b32 complete = 0;
do_label(&state, &layout, view->query, 1.f);
b32 case_sensitive = 0;
switch (view->interaction){
case INTV_SYS_FILE_LIST:
{
b32 is_new = (view->action == INTV_NEW);
if (do_file_list_box(system, &state,
&layout, view->hot_directory, 0, !is_new, case_sensitive,
&new_dir, &complete, 0)){
result = 1;
}
if (new_dir){
hot_directory_reload(system,
view->hot_directory, view->working_set);
}
}break;
case INTV_LIVE_FILE_LIST:
if (do_live_file_list_box(system, &state, &layout, view->working_set, &view->dest, &complete)){
result = 1;
}
break;
case INTV_SURE_TO_KILL_INTER:
{
i32 action = -1;
char s_[256];
String s = make_fixed_width_string(s_);
append(&s, view->dest);
append(&s, " has unsaved changes, kill it?");
do_label(&state, &layout, s, 1.f);
i32 id = 0;
if (do_list_option(++id, &state, &layout, make_lit_string("(Y)es"))){
action = 0;
}
if (do_list_option(++id, &state, &layout, make_lit_string("(N)o"))){
action = 1;
}
if (do_list_option(++id, &state, &layout, make_lit_string("(S)ave and kill"))){
action = 2;
}
if (action == -1 && input_stage){
i32 key_count = user_input->keys.count;
for (i32 i = 0; i < key_count; ++i){
Key_Event_Data key = user_input->keys.keys[i];
switch (key.character){
case 'y': case 'Y': action = 0; break;
case 'n': case 'N': action = 1; break;
case 's': case 'S': action = 2; break;
}
if (action == -1 && key.keycode == state.codes->esc) action = 1;
if (action != -1) break;
}
}
if (action != -1){
complete = 1;
view->user_action = action;
}
}break;
}
if (complete){
interactive_view_complete(view);
}
if (ui_finish_frame(&view->state, &state, &layout, rect, 0, 0)){
result = 1;
}
return result;
}
Do_View_Sig(do_interactive_view){
i32 result = 0;
view->mouse_cursor_type = APP_MOUSE_CURSOR_ARROW;
Interactive_View *int_view = (Interactive_View*)view;
switch (message){
case VMSG_STEP: case VMSG_DRAW:
result = step_draw_int_view(system, int_view, target, rect, user_input, (message == VMSG_STEP));
break;
}
return result;
}
internal Interactive_View*
interactive_view_init(System_Functions *system, View *view,
Hot_Directory *hot_dir, Style *style,
Working_Set *working_set, Font_Set *font_set, Delay *delay){
Interactive_View *result = (Interactive_View*)view;
view->type = VIEW_TYPE_INTERACTIVE;
view->do_view = do_interactive_view;
result->hot_directory = hot_dir;
hot_directory_clean_end(hot_dir);
hot_directory_reload(system, hot_dir, working_set);
result->query = make_fixed_width_string(result->query_);
result->dest = make_fixed_width_string(result->dest_);
result->style = style;
result->working_set = working_set;
result->font_set = font_set;
result->delay = delay;
return result;
}
// BOTTOM
/*
* Mr. 4th Dimention - Allen Webster
*
* 19.09.2015
*
* File editing view for 4coder
*
*/
// TOP
enum Interactive_View_Action{
INTV_OPEN,
INTV_SAVE_AS,
INTV_NEW,
INTV_SWITCH,
INTV_KILL,
INTV_SURE_TO_KILL
};
enum Interactive_View_Interaction{
INTV_SYS_FILE_LIST,
INTV_LIVE_FILE_LIST,
INTV_SURE_TO_KILL_INTER
};
struct Interactive_View{
View view_base;
Hot_Directory *hot_directory;
Style *style;
Working_Set *working_set;
Delay *delay;
Font_Set *font_set;
UI_State state;
Interactive_View_Interaction interaction;
Interactive_View_Action action;
char query_[256];
String query;
char dest_[256];
String dest;
i32 user_action;
};
inline Interactive_View*
view_to_interactive_view(View *view){
Interactive_View *result = 0;
if (view->type == VIEW_TYPE_INTERACTIVE)
result = (Interactive_View*)view;
return result;
}
internal void
interactive_view_complete(Interactive_View *view){
Panel *panel = view->view_base.panel;
switch (view->action){
case INTV_OPEN:
delayed_action(view->delay, DACT_OPEN,
view->hot_directory->string, panel);
break;
case INTV_SAVE_AS:
delayed_action(view->delay, DACT_SAVE_AS, view->hot_directory->string, panel);
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
case INTV_NEW:
delayed_action(view->delay, DACT_NEW, view->hot_directory->string, panel);
break;
case INTV_SWITCH:
delayed_action(view->delay, DACT_SWITCH, view->dest, panel);
break;
case INTV_KILL:
delayed_action(view->delay, DACT_TRY_KILL, view->dest, panel);
break;
case INTV_SURE_TO_KILL:
switch (view->user_action){
case 0:
delayed_action(view->delay, DACT_KILL, view->dest, panel);
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
case 1:
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
case 2:
delayed_action(view->delay, DACT_SAVE, view->dest, panel);
delayed_action(view->delay, DACT_KILL, view->dest, panel);
delayed_action(view->delay, DACT_CLOSE_MINOR, {}, panel);
break;
}
break;
}
}
internal i32
step_draw_int_view(System_Functions *system, Interactive_View *view,
Render_Target *target, i32_Rect rect,
Input_Summary *user_input, b32 input_stage){
i32 result = 0;
UI_State state =
ui_state_init(&view->state, target, user_input,
view->style, view->font_set, view->working_set, input_stage);
UI_Layout layout;
begin_layout(&layout, rect);
b32 new_dir = 0;
b32 complete = 0;
do_label(&state, &layout, view->query, 1.f);
b32 case_sensitive = 0;
switch (view->interaction){
case INTV_SYS_FILE_LIST:
{
b32 is_new = (view->action == INTV_NEW);
if (do_file_list_box(system, &state,
&layout, view->hot_directory, 0, !is_new, case_sensitive,
&new_dir, &complete, 0)){
result = 1;
}
if (new_dir){
hot_directory_reload(system,
view->hot_directory, view->working_set);
}
}break;
case INTV_LIVE_FILE_LIST:
if (do_live_file_list_box(system, &state, &layout, view->working_set, &view->dest, &complete)){
result = 1;
}
break;
case INTV_SURE_TO_KILL_INTER:
{
i32 action = -1;
char s_[256];
String s = make_fixed_width_string(s_);
append(&s, view->dest);
append(&s, " has unsaved changes, kill it?");
do_label(&state, &layout, s, 1.f);
i32 id = 0;
if (do_list_option(++id, &state, &layout, make_lit_string("(Y)es"))){
action = 0;
}
if (do_list_option(++id, &state, &layout, make_lit_string("(N)o"))){
action = 1;
}
if (do_list_option(++id, &state, &layout, make_lit_string("(S)ave and kill"))){
action = 2;
}
if (action == -1 && input_stage){
i32 key_count = user_input->keys.count;
for (i32 i = 0; i < key_count; ++i){
Key_Event_Data key = user_input->keys.keys[i];
switch (key.character){
case 'y': case 'Y': action = 0; break;
case 'n': case 'N': action = 1; break;
case 's': case 'S': action = 2; break;
}
if (action == -1 && key.keycode == state.codes->esc) action = 1;
if (action != -1) break;
}
}
if (action != -1){
complete = 1;
view->user_action = action;
}
}break;
}
if (complete){
interactive_view_complete(view);
}
if (ui_finish_frame(&view->state, &state, &layout, rect, 0, 0)){
result = 1;
}
return result;
}
Do_View_Sig(do_interactive_view){
i32 result = 0;
view->mouse_cursor_type = APP_MOUSE_CURSOR_ARROW;
Interactive_View *int_view = (Interactive_View*)view;
switch (message){
case VMSG_STEP: case VMSG_DRAW:
result = step_draw_int_view(system, int_view, target, rect, user_input, (message == VMSG_STEP));
break;
}
return result;
}
internal Interactive_View*
interactive_view_init(System_Functions *system, View *view,
Hot_Directory *hot_dir, Style *style,
Working_Set *working_set, Font_Set *font_set, Delay *delay){
Interactive_View *result = (Interactive_View*)view;
view->type = VIEW_TYPE_INTERACTIVE;
view->do_view = do_interactive_view;
result->hot_directory = hot_dir;
hot_directory_clean_end(hot_dir);
hot_directory_reload(system, hot_dir, working_set);
result->query = make_fixed_width_string(result->query_);
result->dest = make_fixed_width_string(result->dest_);
result->style = style;
result->working_set = working_set;
result->font_set = font_set;
result->delay = delay;
return result;
}
// BOTTOM

File diff suppressed because it is too large Load Diff

View File

@ -1,191 +1,191 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 21.01.2014
*
* System functions for project codename "4ed"
*
*/
// TOP
struct Plat_Handle{
u32 d[4];
};
struct File_Info{
String filename;
b32 folder;
};
struct File_List{
void *block;
File_Info *infos;
i32 count, block_size;
};
#define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename)
typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp);
// TODO(allen): make directory a char* to signal that it must be null terminated
#define Sys_Set_File_List_Sig(name) void name(File_List *file_list, String directory)
typedef Sys_Set_File_List_Sig(System_Set_File_List);
#define Sys_Post_Clipboard_Sig(name) void name(String str)
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
#define Sys_Time_Sig(name) u64 name()
typedef Sys_Time_Sig(System_Time);
// cli
struct CLI_Handles{
Plat_Handle proc;
Plat_Handle out_read;
Plat_Handle out_write;
u32 scratch_space[4];
i32 exit;
};
#define Sys_CLI_Call_Sig(name) b32 name(char *path, char *script_name, CLI_Handles *cli_out)
typedef Sys_CLI_Call_Sig(System_CLI_Call);
#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);
// thread
struct Thread_Context;
enum Lock_ID{
FRAME_LOCK,
INPUT_LOCK,
FONT_LOCK,
RENDER_LOCK,
CANCEL_LOCK0,
CANCEL_LOCK1,
CANCEL_LOCK2,
CANCEL_LOCK3,
CANCEL_LOCK4,
CANCEL_LOCK5,
CANCEL_LOCK6,
CANCEL_LOCK7,
LOCK_COUNT
};
enum Thread_Group_ID{
BACKGROUND_THREADS,
THREAD_GROUP_COUNT
};
struct Thread_Memory{
void *data;
i32 size;
i32 id;
};
struct Thread_Exchange;
struct System_Functions;
#define Job_Callback_Sig(name) void name( \
System_Functions *system, Thread_Context *thread, Thread_Memory *memory, \
Thread_Exchange *exchange, void *data[2])
typedef Job_Callback_Sig(Job_Callback);
struct Job_Data{
Job_Callback *callback;
void *data[2];
i32 memory_request;
};
struct Full_Job_Data{
Job_Data job;
u32 job_memory_index;
u32 running_thread;
b32 finished;
u32 id;
};
struct Work_Queue{
Full_Job_Data jobs[256];
Plat_Handle semaphore;
volatile u32 write_position;
volatile u32 read_position;
};
#define THREAD_NOT_ASSIGNED 0xFFFFFFFF
#define JOB_ID_WRAP (ArrayCount(queue->jobs) * 4)
#define QUEUE_WRAP (ArrayCount(queue->jobs))
struct Thread_Exchange{
Work_Queue queues[THREAD_GROUP_COUNT];
volatile u32 force_redraw;
};
#define Sys_Post_Job_Sig(name) u32 name(Thread_Group_ID group_id, Job_Data job)
typedef Sys_Post_Job_Sig(System_Post_Job);
#define Sys_Cancel_Job_Sig(name) void name(Thread_Group_ID group_id, u32 job_id)
typedef Sys_Cancel_Job_Sig(System_Cancel_Job);
#define Sys_Grow_Thread_Memory_Sig(name) void name(Thread_Memory *memory)
typedef Sys_Grow_Thread_Memory_Sig(System_Grow_Thread_Memory);
#define Sys_Acquire_Lock_Sig(name) void name(i32 id)
typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock);
#define Sys_Release_Lock_Sig(name) void name(i32 id)
typedef Sys_Release_Lock_Sig(System_Release_Lock);
// debug
#define INTERNAL_Sys_Sentinel_Sig(name) Bubble* name()
typedef INTERNAL_Sys_Sentinel_Sig(INTERNAL_System_Sentinel);
#define INTERNAL_Sys_Get_Thread_States_Sig(name) void name(Thread_Group_ID id, b8 *running, i32 *pending)
typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
#define INTERNAL_Sys_Debug_Message_Sig(name) void name(char *message)
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
struct System_Functions{
// files: 2
System_File_Time_Stamp *file_time_stamp;
System_Set_File_List *set_file_list;
// file system navigation (4coder_custom.h): 2
Directory_Has_File *directory_has_file;
Directory_CD *directory_cd;
// clipboard: 1
System_Post_Clipboard *post_clipboard;
// time: 1
System_Time *time;
// cli: 4
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;
// threads: 5
System_Post_Job *post_job;
System_Cancel_Job *cancel_job;
System_Grow_Thread_Memory *grow_thread_memory;
System_Acquire_Lock *acquire_lock;
System_Release_Lock *release_lock;
// debug: 3
INTERNAL_System_Sentinel *internal_sentinel;
INTERNAL_System_Get_Thread_States *internal_get_thread_states;
INTERNAL_System_Debug_Message *internal_debug_message;
};
// BOTTOM
/*
* Mr. 4th Dimention - Allen Webster
*
* 21.01.2014
*
* System functions for project codename "4ed"
*
*/
// TOP
struct Plat_Handle{
u32 d[4];
};
struct File_Info{
String filename;
b32 folder;
};
struct File_List{
void *block;
File_Info *infos;
i32 count, block_size;
};
#define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename)
typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp);
// TODO(allen): make directory a char* to signal that it must be null terminated
#define Sys_Set_File_List_Sig(name) void name(File_List *file_list, String directory)
typedef Sys_Set_File_List_Sig(System_Set_File_List);
#define Sys_Post_Clipboard_Sig(name) void name(String str)
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
#define Sys_Time_Sig(name) u64 name()
typedef Sys_Time_Sig(System_Time);
// cli
struct CLI_Handles{
Plat_Handle proc;
Plat_Handle out_read;
Plat_Handle out_write;
u32 scratch_space[4];
i32 exit;
};
#define Sys_CLI_Call_Sig(name) b32 name(char *path, char *script_name, CLI_Handles *cli_out)
typedef Sys_CLI_Call_Sig(System_CLI_Call);
#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);
// thread
struct Thread_Context;
enum Lock_ID{
FRAME_LOCK,
INPUT_LOCK,
FONT_LOCK,
RENDER_LOCK,
CANCEL_LOCK0,
CANCEL_LOCK1,
CANCEL_LOCK2,
CANCEL_LOCK3,
CANCEL_LOCK4,
CANCEL_LOCK5,
CANCEL_LOCK6,
CANCEL_LOCK7,
LOCK_COUNT
};
enum Thread_Group_ID{
BACKGROUND_THREADS,
THREAD_GROUP_COUNT
};
struct Thread_Memory{
void *data;
i32 size;
i32 id;
};
struct Thread_Exchange;
struct System_Functions;
#define Job_Callback_Sig(name) void name( \
System_Functions *system, Thread_Context *thread, Thread_Memory *memory, \
Thread_Exchange *exchange, void *data[2])
typedef Job_Callback_Sig(Job_Callback);
struct Job_Data{
Job_Callback *callback;
void *data[2];
i32 memory_request;
};
struct Full_Job_Data{
Job_Data job;
u32 job_memory_index;
u32 running_thread;
b32 finished;
u32 id;
};
struct Work_Queue{
Full_Job_Data jobs[256];
Plat_Handle semaphore;
volatile u32 write_position;
volatile u32 read_position;
};
#define THREAD_NOT_ASSIGNED 0xFFFFFFFF
#define JOB_ID_WRAP (ArrayCount(queue->jobs) * 4)
#define QUEUE_WRAP (ArrayCount(queue->jobs))
struct Thread_Exchange{
Work_Queue queues[THREAD_GROUP_COUNT];
volatile u32 force_redraw;
};
#define Sys_Post_Job_Sig(name) u32 name(Thread_Group_ID group_id, Job_Data job)
typedef Sys_Post_Job_Sig(System_Post_Job);
#define Sys_Cancel_Job_Sig(name) void name(Thread_Group_ID group_id, u32 job_id)
typedef Sys_Cancel_Job_Sig(System_Cancel_Job);
#define Sys_Grow_Thread_Memory_Sig(name) void name(Thread_Memory *memory)
typedef Sys_Grow_Thread_Memory_Sig(System_Grow_Thread_Memory);
#define Sys_Acquire_Lock_Sig(name) void name(i32 id)
typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock);
#define Sys_Release_Lock_Sig(name) void name(i32 id)
typedef Sys_Release_Lock_Sig(System_Release_Lock);
// debug
#define INTERNAL_Sys_Sentinel_Sig(name) Bubble* name()
typedef INTERNAL_Sys_Sentinel_Sig(INTERNAL_System_Sentinel);
#define INTERNAL_Sys_Get_Thread_States_Sig(name) void name(Thread_Group_ID id, b8 *running, i32 *pending)
typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
#define INTERNAL_Sys_Debug_Message_Sig(name) void name(char *message)
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
struct System_Functions{
// files: 2
System_File_Time_Stamp *file_time_stamp;
System_Set_File_List *set_file_list;
// file system navigation (4coder_custom.h): 2
Directory_Has_File *directory_has_file;
Directory_CD *directory_cd;
// clipboard: 1
System_Post_Clipboard *post_clipboard;
// time: 1
System_Time *time;
// cli: 4
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;
// threads: 5
System_Post_Job *post_job;
System_Cancel_Job *cancel_job;
System_Grow_Thread_Memory *grow_thread_memory;
System_Acquire_Lock *acquire_lock;
System_Release_Lock *release_lock;
// debug: 3
INTERNAL_System_Sentinel *internal_sentinel;
INTERNAL_System_Get_Thread_States *internal_get_thread_states;
INTERNAL_System_Debug_Message *internal_debug_message;
};
// BOTTOM

BIN
vc120.pdb

Binary file not shown.

View File

@ -75,6 +75,8 @@ struct Win32_Input_Chunk_Transient{
b8 mouse_r_press, mouse_r_release;
b32 out_of_window;
i16 mouse_wheel;
b32 redraw;
};
struct Win32_Input_Chunk_Persistent{
@ -411,7 +413,6 @@ Sys_Set_File_List_Sig(system_set_file_list){
info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
info->filename.str = name;
char *name_base = name;
i32 i = 0;
for(;find_data.cFileName[i];++i) *name++ = find_data.cFileName[i];
info->filename.size = i;
@ -1247,6 +1248,7 @@ Win32Callback(HWND hwnd, UINT uMsg,
i32 new_height = HIWORD(lParam);
Win32Resize(new_width, new_height);
win32vars.input_chunk.trans.redraw = 1;
}
}break;
@ -1378,7 +1380,9 @@ UpdateLoop(LPVOID param){
u32 redraw = exchange_vars.thread.force_redraw;
if (redraw) exchange_vars.thread.force_redraw = 0;
redraw = redraw || input_chunk.trans.redraw;
Key_Input_Data input_data;
Mouse_State mouse;
Application_Step_Result result;