new linux shit

This commit is contained in:
Allen Webster 2016-02-01 00:03:42 -05:00
parent 951b992b2f
commit 8195020bfd
16 changed files with 4959 additions and 4688 deletions

View File

@ -12,10 +12,11 @@
#define literal(s) s, (sizeof(s)-1) #define literal(s) s, (sizeof(s)-1)
#endif #endif
// NOTE(allen|a3.1): All of your custom ids should be >= mapid_user_custom. // NOTE(allen|a3.3): All of your custom ids should be enumerated
// I recommend enumerating your own map ids as shown here. // as shown here, they may start at 0, and you can only have
// 2^24 of them so don't be wasteful!
enum My_Maps{ enum My_Maps{
my_code_map = mapid_user_custom, my_code_map,
my_html_map my_html_map
}; };
@ -73,8 +74,8 @@ CUSTOM_COMMAND_SIG(open_in_other){
CUSTOM_COMMAND_SIG(open_my_files){ CUSTOM_COMMAND_SIG(open_my_files){
// NOTE(allen|a3.1): The command cmdid_interactive_open can now open // NOTE(allen|a3.1): The command cmdid_interactive_open can now open
// a file specified on the parameter stack. If the file does not // a file specified on the parameter stack. If the file does not exist
// exist cmdid_interactive_open behaves as usual. // cmdid_interactive_open behaves as usual.
push_parameter(app, cmd_context, par_name, literal("w:/4ed/data/test/basic.cpp")); push_parameter(app, cmd_context, par_name, literal("w:/4ed/data/test/basic.cpp"));
exec_command(cmd_context, cmdid_interactive_open); exec_command(cmd_context, cmdid_interactive_open);
@ -224,11 +225,9 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind_me(context, ']', MDFR_NONE, write_and_auto_tab); bind_me(context, ']', MDFR_NONE, write_and_auto_tab);
bind_me(context, ';', MDFR_NONE, write_and_auto_tab); bind_me(context, ';', MDFR_NONE, write_and_auto_tab);
#if 0
bind(context, '\t', MDFR_NONE, cmdid_auto_tab_line_at_cursor); bind(context, '\t', MDFR_NONE, cmdid_auto_tab_line_at_cursor);
bind(context, '\t', MDFR_CTRL, cmdid_auto_tab_range); bind(context, '\t', MDFR_CTRL, cmdid_auto_tab_range);
bind(context, '\t', MDFR_CTRL | MDFR_SHIFT, cmdid_write_character); bind(context, '\t', MDFR_CTRL | MDFR_SHIFT, cmdid_write_character);
#endif
end_map(context); end_map(context);

View File

@ -287,7 +287,6 @@ struct Application_Links{
struct Custom_API{ struct Custom_API{
Get_Binding_Data_Function *get_bindings; Get_Binding_Data_Function *get_bindings;
Set_Extra_Font_Function *set_extra_font;
}; };
// NOTE(allen): definitions for the buffer that communicates to 4ed.exe // NOTE(allen): definitions for the buffer that communicates to 4ed.exe
@ -302,12 +301,12 @@ enum Binding_Unit_Type{
}; };
enum Map_ID{ enum Map_ID{
mapid_global, mapid_global = (1 << 24),
mapid_file, mapid_file,
// NOTE(allen): mapid_nomap will remain empty even if you attempt to fill it // NOTE(allen): mapid_nomap will remain empty even if you attempt to fill it
// it is for setting a map's parent to nothing // it is for setting a map's parent to nothing, in cases where you don't want
mapid_nomap, // to inherit from global (which is the default).
mapid_user_custom = 100 mapid_nomap
}; };
struct Binding_Unit{ struct Binding_Unit{

View File

@ -77,7 +77,7 @@ begin_bind_helper(void *data, int size){
inline void inline void
begin_map(Bind_Helper *helper, int mapid){ begin_map(Bind_Helper *helper, int mapid){
if (helper->group != 0 && helper->error == 0) helper->error = BH_ERR_MISSING_END; if (helper->group != 0 && helper->error == 0) helper->error = BH_ERR_MISSING_END;
if (!helper->error && mapid >= mapid_user_custom) ++helper->header->header.user_map_count; if (!helper->error && mapid < mapid_global) ++helper->header->header.user_map_count;
Binding_Unit unit; Binding_Unit unit;
unit.type = unit_map_begin; unit.type = unit_map_begin;
@ -170,7 +170,7 @@ bind_me_vanilla_keys(Bind_Helper *helper, unsigned char modifiers, Custom_Comman
inline void inline void
inherit_map(Bind_Helper *helper, int mapid){ inherit_map(Bind_Helper *helper, int mapid){
if (helper->group == 0 && helper->error == 0) helper->error = BH_ERR_MISSING_BEGIN; if (helper->group == 0 && helper->error == 0) helper->error = BH_ERR_MISSING_BEGIN;
if (!helper->error && mapid >= mapid_user_custom) ++helper->header->header.user_map_count; if (!helper->error && mapid < mapid_global) ++helper->header->header.user_map_count;
Binding_Unit unit; Binding_Unit unit;
unit.type = unit_inherit; unit.type = unit_inherit;

View File

@ -126,7 +126,7 @@ FCPP_LINK bool append_int_to_str(int x, String *s_out);
FCPP_LINK int str_to_int(char *s); FCPP_LINK int str_to_int(char *s);
FCPP_LINK int str_to_int(String s); FCPP_LINK int str_to_int(String s);
FCPP_LINK int hexchar_to_int(char c); FCPP_LINK int hexchar_to_int(char c);
FCPP_LINK int int_to_hexchar(char c); FCPP_LINK char int_to_hexchar(int c);
FCPP_LINK int hexstr_to_int(String s); FCPP_LINK int hexstr_to_int(String s);
FCPP_LINK int copy_fast_unsafe(char *dest, char *src); FCPP_LINK int copy_fast_unsafe(char *dest, char *src);

View File

@ -220,6 +220,7 @@ enum Cpp_Token_Type{
CPP_PP_UNKNOWN, CPP_PP_UNKNOWN,
CPP_TOKEN_DEFINED, CPP_TOKEN_DEFINED,
CPP_TOKEN_INCLUDE_FILE, CPP_TOKEN_INCLUDE_FILE,
CPP_TOKEN_ERROR_MESSAGE,
// NOTE(allen): used in the parser // NOTE(allen): used in the parser
CPP_TOKEN_EOF CPP_TOKEN_EOF
@ -256,6 +257,7 @@ enum Cpp_Preprocessor_State{
CPP_LEX_PP_BODY, CPP_LEX_PP_BODY,
CPP_LEX_PP_BODY_IF, CPP_LEX_PP_BODY_IF,
CPP_LEX_PP_NUMBER, CPP_LEX_PP_NUMBER,
CPP_LEX_PP_ERROR,
CPP_LEX_PP_JUNK, CPP_LEX_PP_JUNK,
// NEVER ADD BELOW THIS // NEVER ADD BELOW THIS
CPP_LEX_PP_COUNT CPP_LEX_PP_COUNT
@ -450,6 +452,7 @@ FCPP_GLOBAL String_And_Flag keyword_strings[] = {
{"long", CPP_TOKEN_KEY_MODIFIER}, {"long", CPP_TOKEN_KEY_MODIFIER},
{"short", CPP_TOKEN_KEY_MODIFIER}, {"short", CPP_TOKEN_KEY_MODIFIER},
{"unsigned", CPP_TOKEN_KEY_MODIFIER},
{"const", CPP_TOKEN_KEY_QUALIFIER}, {"const", CPP_TOKEN_KEY_QUALIFIER},
{"volatile", CPP_TOKEN_KEY_QUALIFIER}, {"volatile", CPP_TOKEN_KEY_QUALIFIER},
@ -766,7 +769,7 @@ cpp_read_junk_line(Cpp_File file, int pos){
--pos; --pos;
} }
result.pos = pos; result.pos = pos;
result.token.size = pos - result.token.start - 1; result.token.size = pos - result.token.start;
} }
return result; return result;
@ -1348,6 +1351,9 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
lex.pp_state = CPP_LEX_PP_NUMBER; lex.pp_state = CPP_LEX_PP_NUMBER;
break; break;
case CPP_PP_ERROR: case CPP_PP_ERROR:
lex.pp_state = CPP_LEX_PP_ERROR;
break;
case CPP_PP_UNKNOWN: case CPP_PP_UNKNOWN:
case CPP_PP_ELSE: case CPP_PP_ELSE:
case CPP_PP_ENDIF: case CPP_PP_ENDIF:
@ -1383,7 +1389,8 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
} }
else{ else{
if (lex.pp_state == CPP_LEX_PP_IDENTIFIER){ switch (lex.pp_state){
case CPP_LEX_PP_IDENTIFIER:
if (!char_is_alpha_numeric(current)){ if (!char_is_alpha_numeric(current)){
has_result = 0; has_result = 0;
lex.pp_state = CPP_LEX_PP_JUNK; lex.pp_state = CPP_LEX_PP_JUNK;
@ -1394,8 +1401,9 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
lex.pos = result.pos; lex.pos = result.pos;
lex.pp_state = CPP_LEX_PP_JUNK; lex.pp_state = CPP_LEX_PP_JUNK;
} }
} break;
else if (lex.pp_state == CPP_LEX_PP_MACRO_IDENTIFIER){
case CPP_LEX_PP_MACRO_IDENTIFIER:
if (!char_is_alpha_numeric(current)){ if (!char_is_alpha_numeric(current)){
has_result = 0; has_result = 0;
lex.pp_state = CPP_LEX_PP_JUNK; lex.pp_state = CPP_LEX_PP_JUNK;
@ -1406,9 +1414,9 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
lex.pos = result.pos; lex.pos = result.pos;
lex.pp_state = CPP_LEX_PP_BODY; lex.pp_state = CPP_LEX_PP_BODY;
} }
} break;
else if (lex.pp_state == CPP_LEX_PP_INCLUDE){ case CPP_LEX_PP_INCLUDE:
if (current != '"' && current != '<'){ if (current != '"' && current != '<'){
has_result = 0; has_result = 0;
lex.pp_state = CPP_LEX_PP_JUNK; lex.pp_state = CPP_LEX_PP_JUNK;
@ -1418,8 +1426,9 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
lex.pos = result.pos; lex.pos = result.pos;
lex.pp_state = CPP_LEX_PP_JUNK; lex.pp_state = CPP_LEX_PP_JUNK;
} }
} break;
else if (lex.pp_state == CPP_LEX_PP_BODY){
case CPP_LEX_PP_BODY:
if (current == '#'){ if (current == '#'){
result = cpp_read_pp_operator(file, lex.pos); result = cpp_read_pp_operator(file, lex.pos);
} }
@ -1428,8 +1437,9 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
} }
lex.pos = result.pos; lex.pos = result.pos;
result.token.flags |= CPP_TFLAG_PP_BODY; result.token.flags |= CPP_TFLAG_PP_BODY;
} break;
else if (lex.pp_state == CPP_LEX_PP_BODY_IF){
case CPP_LEX_PP_BODY_IF:
if (current == '#'){ if (current == '#'){
result = cpp_read_pp_operator(file, lex.pos); result = cpp_read_pp_operator(file, lex.pos);
} }
@ -1438,9 +1448,9 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
} }
lex.pos = result.pos; lex.pos = result.pos;
result.token.flags |= CPP_TFLAG_PP_BODY; result.token.flags |= CPP_TFLAG_PP_BODY;
} break;
else if (lex.pp_state == CPP_LEX_PP_NUMBER){ case CPP_LEX_PP_NUMBER:
if (!char_is_numeric(current)){ if (!char_is_numeric(current)){
has_result = 0; has_result = 0;
lex.pp_state = CPP_LEX_PP_JUNK; lex.pp_state = CPP_LEX_PP_JUNK;
@ -1451,8 +1461,17 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
result.token.flags |= CPP_TFLAG_PP_BODY; result.token.flags |= CPP_TFLAG_PP_BODY;
lex.pp_state = CPP_LEX_PP_INCLUDE; lex.pp_state = CPP_LEX_PP_INCLUDE;
} }
} break;
else{
case CPP_LEX_PP_ERROR:
result = cpp_read_junk_line(file, lex.pos);
lex.pos = result.pos;
result.token.type = CPP_TOKEN_ERROR_MESSAGE;
result.token.flags |= CPP_TFLAG_PP_BODY;
break;
default:
{
bool took_comment = 0; bool took_comment = 0;
if (current == '/' && lex.pos + 1 < file.size){ if (current == '/' && lex.pos + 1 < file.size){
if (file.data[lex.pos + 1] == '/'){ if (file.data[lex.pos + 1] == '/'){
@ -1472,6 +1491,8 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
lex.pos = result.pos; lex.pos = result.pos;
result.token.flags |= CPP_TFLAG_PP_BODY; result.token.flags |= CPP_TFLAG_PP_BODY;
} }
}break;
} }
} }
} }

195
4ed.cpp
View File

@ -122,7 +122,7 @@ app_get_map_index(App_Vars *vars, i32 mapid){
internal Command_Map* internal Command_Map*
app_get_map(App_Vars *vars, i32 mapid){ app_get_map(App_Vars *vars, i32 mapid){
Command_Map *map = 0; Command_Map *map = 0;
if (mapid >= mapid_user_custom) map = vars->user_maps + mapid - mapid_user_custom; if (mapid < mapid_global) map = vars->user_maps + mapid;
else if (mapid == mapid_global) map = &vars->map_top; else if (mapid == mapid_global) map = &vars->map_top;
else if (mapid == mapid_file) map = &vars->map_file; else if (mapid == mapid_file) map = &vars->map_file;
return map; return map;
@ -1065,10 +1065,12 @@ COMMAND_DECL(kill_buffer){
COMMAND_DECL(toggle_line_wrap){ COMMAND_DECL(toggle_line_wrap){
ProfileMomentFunction(); ProfileMomentFunction();
REQ_FILE_VIEW(view); REQ_FILE_VIEW(view);
REQ_FILE(file, view);
Relative_Scrolling scrolling = view_get_relative_scrolling(view); Relative_Scrolling scrolling = view_get_relative_scrolling(view);
if (view->unwrapped_lines){ if (view->unwrapped_lines){
view->unwrapped_lines = 0; view->unwrapped_lines = 0;
file->settings.unwrapped_lines = 0;
view->target_x = 0; view->target_x = 0;
view->cursor = view->cursor =
view_compute_cursor_from_pos(view, view->cursor.pos); view_compute_cursor_from_pos(view, view->cursor.pos);
@ -1076,6 +1078,7 @@ COMMAND_DECL(toggle_line_wrap){
} }
else{ else{
view->unwrapped_lines = 1; view->unwrapped_lines = 1;
file->settings.unwrapped_lines = 1;
view->cursor = view->cursor =
view_compute_cursor_from_pos(view, view->cursor.pos); view_compute_cursor_from_pos(view, view->cursor.pos);
view->preferred_x = view->cursor.unwrapped_x; view->preferred_x = view->cursor.unwrapped_x;
@ -1660,6 +1663,8 @@ COMMAND_DECL(set_settings){
if (view->unwrapped_lines){ if (view->unwrapped_lines){
if (v){ if (v){
view->unwrapped_lines = 0; view->unwrapped_lines = 0;
file->settings.unwrapped_lines = 0;
if (!file->state.is_loading){ if (!file->state.is_loading){
Relative_Scrolling scrolling = view_get_relative_scrolling(view); Relative_Scrolling scrolling = view_get_relative_scrolling(view);
view->target_x = 0; view->target_x = 0;
@ -1672,6 +1677,7 @@ COMMAND_DECL(set_settings){
else{ else{
if (!v){ if (!v){
view->unwrapped_lines = 1; view->unwrapped_lines = 1;
file->settings.unwrapped_lines = 1;
if (!file->state.is_loading){ if (!file->state.is_loading){
Relative_Scrolling scrolling = view_get_relative_scrolling(view); Relative_Scrolling scrolling = view_get_relative_scrolling(view);
@ -1688,7 +1694,7 @@ COMMAND_DECL(set_settings){
int v = dynamic_to_int(&param->param.value); int v = dynamic_to_int(&param->param.value);
if (v == mapid_global) file->settings.base_map_id = mapid_global; if (v == mapid_global) file->settings.base_map_id = mapid_global;
else if (v == mapid_file) file->settings.base_map_id = mapid_file; else if (v == mapid_file) file->settings.base_map_id = mapid_file;
else if (v >= mapid_user_custom){ else if (v < mapid_global){
int index = app_get_map_index(vars, v); int index = app_get_map_index(vars, v);
if (index < vars->user_map_count) file->settings.base_map_id = v; if (index < vars->user_map_count) file->settings.base_map_id = v;
else file->settings.base_map_id = mapid_file; else file->settings.base_map_id = mapid_file;
@ -2047,16 +2053,23 @@ setup_debug_commands(Command_Map *commands, Partition *part, Key_Codes *codes, C
internal void internal void
setup_ui_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ setup_ui_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){
map_init(commands, part, 12, parent); map_init(commands, part, 32, parent);
commands->vanilla_keyboard_default.function = command_null; commands->vanilla_keyboard_default.function = command_null;
map_add(commands, codes->left, MDFR_NONE, command_null); // TODO(allen): This is hacky, when the new UI stuff happens, let's fix it, and by that
map_add(commands, codes->right, MDFR_NONE, command_null); // I mean actually fix it, don't just say you fixed it with something stupid again.
map_add(commands, codes->up, MDFR_NONE, command_null); u8 mdfr;
map_add(commands, codes->down, MDFR_NONE, command_null); u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL};
map_add(commands, codes->back, MDFR_NONE, command_null); for (i32 i = 0; i < 4; ++i){
map_add(commands, codes->esc, MDFR_NONE, command_close_minor_view); mdfr = mdfr_array[i];
map_add(commands, codes->left, mdfr, command_null);
map_add(commands, codes->right, mdfr, command_null);
map_add(commands, codes->up, mdfr, command_null);
map_add(commands, codes->down, mdfr, command_null);
map_add(commands, codes->back, mdfr, command_null);
map_add(commands, codes->esc, mdfr, command_close_minor_view);
}
} }
internal void internal void
@ -2492,86 +2505,134 @@ HOOK_SIG(default_open_file_hook){
} }
enum Command_Line_Action{ enum Command_Line_Action{
CLAct_Nothing,
CLAct_Ignore, CLAct_Ignore,
CLAct_UserFile, CLAct_UserFile,
CLAct_CustomDLL, CLAct_CustomDLL,
CLAct_InitialFilePosition, CLAct_InitialFilePosition,
CLAct_WindowSize, CLAct_WindowSize,
CLAct_WindowMaximize,
CLAct_WindowPosition, CLAct_WindowPosition,
CLAct_Count CLAct_Count
}; };
void void
init_command_line_settings(App_Settings *settings, App_Plat_Settings *plat_settings, init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
Command_Line_Parameters clparams){ Command_Line_Parameters clparams){
char *arg; char *arg;
Command_Line_Action action; Command_Line_Action action = CLAct_Nothing;
i32 i,index; i32 i,index;
b32 strict = 0; b32 strict = 0;
settings->init_files_max = ArrayCount(settings->init_files); settings->init_files_max = ArrayCount(settings->init_files);
for (i = 1; i < clparams.argc; ++i){ for (i = 1; i <= clparams.argc; ++i){
arg = clparams.argv[i]; if (i == clparams.argc) arg = "";
if (arg[0] == '-'){ else arg = clparams.argv[i];
action = CLAct_Ignore; switch (action){
switch (arg[1]){ case CLAct_Nothing:
case 'u': action = CLAct_UserFile; strict = 0; break; {
case 'U': action = CLAct_UserFile; strict = 1; break; if (arg[0] == '-'){
action = CLAct_Ignore;
switch (arg[1]){
case 'u': action = CLAct_UserFile; strict = 0; break;
case 'U': action = CLAct_UserFile; strict = 1; break;
case 'd': action = CLAct_CustomDLL; strict = 0; break; case 'd': action = CLAct_CustomDLL; strict = 0; break;
case 'D': action = CLAct_CustomDLL; strict = 1; break; case 'D': action = CLAct_CustomDLL; strict = 1; break;
case 'l': action = CLAct_InitialFilePosition; break; case 'l': action = CLAct_InitialFilePosition; break;
case 'w': action = CLAct_WindowSize; break; case 'w': action = CLAct_WindowSize; break;
case 'p': action = CLAct_WindowPosition; break; case 'W': action = CLAct_WindowMaximize; break;
} case 'p': action = CLAct_WindowPosition; break;
}
}
else if (arg[0] != 0){
if (settings->init_files_count < settings->init_files_max){
index = settings->init_files_count++;
settings->init_files[index] = arg;
}
}
}break;
switch (action){
case CLAct_UserFile: case CLAct_UserFile:
{
settings->user_file_is_strict = strict; settings->user_file_is_strict = strict;
++i;
if (i < clparams.argc){ if (i < clparams.argc){
settings->user_file = clparams.argv[i]; settings->user_file = clparams.argv[i];
} }
break; action = CLAct_Nothing;
}break;
case CLAct_CustomDLL: case CLAct_CustomDLL:
{
plat_settings->custom_dll_is_strict = strict; plat_settings->custom_dll_is_strict = strict;
++i;
if (i < clparams.argc){ if (i < clparams.argc){
plat_settings->custom_dll = clparams.argv[i]; plat_settings->custom_dll = clparams.argv[i];
} }
break; action = CLAct_Nothing;
}break;
case CLAct_InitialFilePosition: case CLAct_InitialFilePosition:
++i; {
if (i < clparams.argc){ if (i < clparams.argc){
settings->initial_line = str_to_int(clparams.argv[i]); settings->initial_line = str_to_int(clparams.argv[i]);
} }
break; action = CLAct_Nothing;
}break;
case CLAct_WindowSize: case CLAct_WindowSize:
break; {
if (i + 1 < clparams.argc){
plat_settings->set_window_size = 1;
plat_settings->window_w = str_to_int(clparams.argv[i]);
plat_settings->window_h = str_to_int(clparams.argv[i+1]);
++i;
}
action = CLAct_Nothing;
}break;
case CLAct_WindowMaximize:
{
--i;
plat_settings->maximize_window = 1;
action = CLAct_Nothing;
}break;
case CLAct_WindowPosition: case CLAct_WindowPosition:
break; {
} if (i + 1 < clparams.argc){
plat_settings->set_window_pos = 1;
plat_settings->window_x = str_to_int(clparams.argv[i]);
plat_settings->window_y = str_to_int(clparams.argv[i+1]);
} ++i;
else{ }
if (settings->init_files_count < settings->init_files_max){ action = CLAct_Nothing;
index = settings->init_files_count++; }break;
settings->init_files[index] = arg;
}
} }
} }
} }
internal App_Vars*
app_setup_memory(Application_Memory *memory){
Partition _partition = partition_open(memory->vars_memory, memory->vars_memory_size);
App_Vars *vars = push_struct(&_partition, App_Vars);
Assert(vars);
*vars = {};
vars->mem.part = _partition;
general_memory_open(&vars->mem.general, memory->target_memory, memory->target_memory_size);
return(vars);
}
App_Read_Command_Line_Sig(app_read_command_line){ App_Read_Command_Line_Sig(app_read_command_line){
i32 output_size = 0; i32 output_size = 0;
//init_command_line_settings(); App_Vars *vars = app_setup_memory(memory);
init_command_line_settings(&vars->settings, plat_settings, clparams);
return(output_size); return(output_size);
} }
@ -2579,17 +2640,11 @@ App_Read_Command_Line_Sig(app_read_command_line){
App_Init_Sig(app_init){ App_Init_Sig(app_init){
app_links_init(system); app_links_init(system);
Partition _partition = partition_open(memory->vars_memory, memory->vars_memory_size); App_Vars *vars = (App_Vars*)memory->vars_memory;
App_Vars *vars = push_struct(&_partition, App_Vars);
Assert(vars);
*vars = {};
vars->config_api = api; vars->config_api = api;
vars->mem.part = _partition;
Partition *partition = &vars->mem.part; Partition *partition = &vars->mem.part;
target->partition = partition; target->partition = partition;
general_memory_open(&vars->mem.general, memory->target_memory, memory->target_memory_size);
i32 panel_max_count = vars->layout.panel_max_count = 16; i32 panel_max_count = vars->layout.panel_max_count = 16;
i32 divider_max_count = panel_max_count - 1; i32 divider_max_count = panel_max_count - 1;
vars->layout.panel_count = 1; vars->layout.panel_count = 1;
@ -2687,7 +2742,7 @@ App_Init_Sig(app_init){
map_init(mapptr, &vars->mem.part, table_max, global); map_init(mapptr, &vars->mem.part, table_max, global);
did_file = 1; did_file = 1;
} }
else if (mapid >= mapid_user_custom){ else if (mapid < mapid_global){
i32 index = app_get_or_add_map_index(vars, mapid); i32 index = app_get_or_add_map_index(vars, mapid);
Assert(index < user_map_count); Assert(index < user_map_count);
mapptr = vars->user_maps + index; mapptr = vars->user_maps + index;
@ -2702,7 +2757,7 @@ App_Init_Sig(app_init){
int mapid = unit->map_inherit.mapid; int mapid = unit->map_inherit.mapid;
if (mapid == mapid_global) parent = &vars->map_top; if (mapid == mapid_global) parent = &vars->map_top;
else if (mapid == mapid_file) parent = &vars->map_file; else if (mapid == mapid_file) parent = &vars->map_file;
else if (mapid >= mapid_user_custom){ else if (mapid < mapid_global){
i32 index = app_get_or_add_map_index(vars, mapid); i32 index = app_get_or_add_map_index(vars, mapid);
if (index < user_map_count) parent = vars->user_maps + index; if (index < user_map_count) parent = vars->user_maps + index;
else parent = 0; else parent = 0;
@ -2819,27 +2874,6 @@ App_Init_Sig(app_init){
font_set_add(partition, vars->font_set, file_name, name, pt_size); font_set_add(partition, vars->font_set, file_name, name, pt_size);
} }
#if 0
if (vars->config_api.set_extra_font){
Extra_Font extra;
extra.size = 17;
vars->config_api.set_extra_font(&extra);
memory_used = 0;
if (app_load_font(target,
vars->fonts.fonts + font_count, extra.file_name, extra.size,
partition_current(partition),
&memory_used, 4, make_string_slowly(extra.font_name))){
++font_count;
}
else{
vars->fonts.fonts[font_count] = {};
}
push_block(partition, memory_used);
}
vars->fonts.count = font_count;
#endif
} }
// NOTE(allen): file setup // NOTE(allen): file setup
@ -2918,6 +2952,7 @@ App_Step_Sig(app_step){
copy(dest, make_string((char*)clipboard.str, clipboard.size)); copy(dest, make_string((char*)clipboard.str, clipboard.size));
} }
// TODO(allen): profile this make sure it's not costing me too much power.
// NOTE(allen): check files are up to date // NOTE(allen): check files are up to date
for (i32 i = 0; i < vars->working_set.file_index_count; ++i){ for (i32 i = 0; i < vars->working_set.file_index_count; ++i){
Editing_File *file = vars->working_set.files + i; Editing_File *file = vars->working_set.files + i;
@ -3277,9 +3312,19 @@ App_Step_Sig(app_step){
Temp_Memory param_stack_temp = begin_temp_memory(&vars->mem.part); Temp_Memory param_stack_temp = begin_temp_memory(&vars->mem.part);
command_data.part = partition_sub_part(&vars->mem.part, 16 << 10); command_data.part = partition_sub_part(&vars->mem.part, 16 << 10);
if (first_step && vars->hooks[hook_start]){ if (first_step){
vars->hooks[hook_start](&command_data, &app_links); if (vars->hooks[hook_start]){
command_data.part.pos = 0; vars->hooks[hook_start](&command_data, &app_links);
command_data.part.pos = 0;
}
char *file_name;
i32 i;
for (i = 0; i < vars->settings.init_file_count; ++i){
file_name = vars->settings.init_files[i];
// TODO(allen): open files, do not attach to view
//app_open_file(system, vars, exchange,live_set, working_set, panel,command, string.str, string.size);
}
} }
// NOTE(allen): command input to active view // NOTE(allen): command input to active view
@ -3366,7 +3411,7 @@ App_Step_Sig(app_step){
Assert(view_->do_view); Assert(view_->do_view);
b32 active = (panel == active_panel); b32 active = (panel == active_panel);
Input_Summary input = (active)?(active_input):(dead_input); Input_Summary input = (active)?(active_input):(dead_input);
if (panel == mouse_panel){ if (panel == mouse_panel && !mouse_data.out_of_window){
input.mouse = mouse_data; input.mouse = mouse_data;
} }
if (view_->do_view(system, exchange, view_, panel->inner, active_view, if (view_->do_view(system, exchange, view_, panel->inner, active_view,

8
4ed.h
View File

@ -125,15 +125,21 @@ struct Command_Line_Parameters{
int argc; int argc;
}; };
struct App_Plat_Settings{ struct Plat_Settings{
char *custom_dll; char *custom_dll;
b32 custom_dll_is_strict; b32 custom_dll_is_strict;
i32 window_w, window_h;
i32 window_x, window_y;
b8 set_window_pos, set_window_size;
b8 maximize_window;
}; };
#define App_Read_Command_Line_Sig(name) \ #define App_Read_Command_Line_Sig(name) \
i32 name(System_Functions *system, \ i32 name(System_Functions *system, \
Application_Memory *memory, \ Application_Memory *memory, \
String current_directory, \ String current_directory, \
Plat_Settings *plat_settings, \
Command_Line_Parameters clparams \ Command_Line_Parameters clparams \
) )

View File

@ -13,7 +13,7 @@ struct App_Settings{
char *user_file; char *user_file;
b32 user_file_is_strict; b32 user_file_is_strict;
char *init_files[4]; char *init_files[8];
i32 init_files_count; i32 init_files_count;
i32 init_files_max; i32 init_files_max;

View File

@ -99,6 +99,7 @@ struct Editing_File_Settings{
Font_Set *set; Font_Set *set;
i32 base_map_id; i32 base_map_id;
i32 dos_write_mode; i32 dos_write_mode;
b32 unwrapped_lines;
b8 tokens_exist; b8 tokens_exist;
b8 super_locked; b8 super_locked;
b8 is_initialized; b8 is_initialized;
@ -1111,7 +1112,8 @@ struct File_View{
f32 scroll_y, target_y, vel_y; f32 scroll_y, target_y, vel_y;
f32 scroll_x, target_x, vel_x; f32 scroll_x, target_x, vel_x;
f32 preferred_x; f32 preferred_x;
Full_Cursor scroll_y_cursor; i32 scroll_i;
union{ union{
Incremental_Search isearch; Incremental_Search isearch;
struct{ struct{
@ -1220,21 +1222,26 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
i32 result = 0; i32 result = 0;
#if BUFFER_EXPERIMENT_SCALPEL <= 3 #if BUFFER_EXPERIMENT_SCALPEL <= 3
i32 max = buffer_size(&file->state.buffer) + file->state.buffer.line_count; i32 max, size;
byte *data = (byte*)general_memory_allocate(&mem->general, max, 0); byte *data;
b32 dos_write_mode = file->settings.dos_write_mode;
if (dos_write_mode)
max = buffer_size(&file->state.buffer) + file->state.buffer.line_count + 1;
else
max = buffer_size(&file->state.buffer);
data = (byte*)general_memory_allocate(&mem->general, max, 0);
Assert(data); Assert(data);
i32 size;
if (file->settings.dos_write_mode){ if (dos_write_mode)
size = buffer_convert_out(&file->state.buffer, (char*)data, max); size = buffer_convert_out(&file->state.buffer, (char*)data, max);
} else
else{ buffer_stringify(&file->state.buffer, 0, size = max, (char*)data);
size = buffer_size(&file->state.buffer);
buffer_stringify(&file->state.buffer, 0, size, (char*)data);
}
i32 filename_len = str_size(filename); i32 filename_len = str_size(filename);
result = exchange_save_file(exchange, filename, filename_len, result = exchange_save_file(exchange, filename, filename_len,
data, size, max); data, size, max);
if (result == 0){ if (result == 0){
general_memory_free(&mem->general, data); general_memory_free(&mem->general, data);
@ -2293,6 +2300,7 @@ view_set_file(System_Functions *system, File_View *view,
view->font_advance = info->advance; view->font_advance = info->advance;
view->font_height = info->height; view->font_height = info->height;
view->font_set = set; view->font_set = set;
view->unwrapped_lines = file->settings.unwrapped_lines;
file->settings.set = set; file->settings.set = set;
view->cursor = {}; view->cursor = {};
@ -2647,6 +2655,83 @@ file_pre_edit_maintenance(System_Functions *system,
file->state.last_4ed_edit_time = system->time(); file->state.last_4ed_edit_time = system->time();
} }
struct Cursor_Fix_Descriptor{
b32 is_batch;
union{
struct{
Buffer_Edit *batch;
i32 batch_size;
};
struct{
i32 start, end;
i32 shift_amount;
};
};
};
internal void
file_edit_cursor_fix(System_Functions *system,
Partition *part, General_Memory *general,
Editing_File *file, Editing_Layout *layout,
Cursor_Fix_Descriptor desc){
Full_Cursor temp_cursor;
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);
i32 panel_count = layout->panel_count;
i32 cursor_count = 0;
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);
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);
}
}
if (cursor_count > 0){
buffer_sort_cursors(cursors, cursor_count);
if (desc.is_batch){
buffer_batch_edit_update_cursors(cursors, cursor_count,
desc.batch, desc.batch_size);
}
else{
buffer_update_cursors(cursors, cursor_count,
desc.start, desc.end,
desc.shift_amount + (desc.end - desc.start));
}
buffer_unsort_cursors(cursors, cursor_count);
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);
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;
temp_cursor = view_compute_cursor_from_pos(current_view, current_view->scroll_i);
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;
}
else{
current_view->target_y += (temp_cursor.wrapped_y - current_view->scroll_y);
current_view->scroll_y = temp_cursor.wrapped_y;
}
}
}
}
end_temp_memory(cursor_temp);
}
internal void internal void
file_do_single_edit(System_Functions *system, file_do_single_edit(System_Functions *system,
Mem_Options *mem, Editing_File *file, Mem_Options *mem, Editing_File *file,
@ -2722,40 +2807,14 @@ file_do_single_edit(System_Functions *system,
#endif #endif
#if BUFFER_EXPERIMENT_SCALPEL <= 3 #if BUFFER_EXPERIMENT_SCALPEL <= 3
Temp_Memory cursor_temp = begin_temp_memory(&mem->part); Cursor_Fix_Descriptor desc = {};
i32 cursor_max = layout->panel_max_count * 2; desc.start = start;
Cursor_With_Index *cursors = push_array(&mem->part, Cursor_With_Index, cursor_max); desc.end = end;
desc.shift_amount = shift_amount;
i32 cursor_count = 0; file_edit_cursor_fix(system, part, general,
current_panel = layout->panels; file, layout, desc);
for (i32 i = 0; i < panel_count; ++i, ++current_panel){
File_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);
}
}
if (cursor_count > 0){
buffer_sort_cursors(cursors, cursor_count);
buffer_update_cursors(cursors, cursor_count,
start, end, shift_amount + (end - start));
buffer_unsort_cursors(cursors, cursor_count);
}
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);
if (current_view && current_view->file == file){
view_cursor_move(current_view, cursors[cursor_count++].pos);
current_view->mark = cursors[cursor_count++].pos;
current_view->preferred_x = view_get_cursor_x(current_view);
}
}
end_temp_memory(cursor_temp);
#endif #endif
} }
@ -2834,41 +2893,14 @@ view_do_white_batch_edit(System_Functions *system, Mem_Options *mem, File_View *
} }
// NOTE(allen): cursor fixing // NOTE(allen): cursor fixing
{ Cursor_Fix_Descriptor desc = {};
Temp_Memory cursor_temp = begin_temp_memory(part); desc.is_batch = 1;
i32 cursor_max = layout->panel_max_count * 2; desc.batch = batch;
Cursor_With_Index *cursors = push_array(part, Cursor_With_Index, cursor_max); desc.batch_size = batch_size;
i32 panel_count = layout->panel_count; file_edit_cursor_fix(system, part, general,
i32 cursor_count = 0; file, layout, desc);
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);
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);
}
}
if (cursor_count > 0){
buffer_sort_cursors(cursors, cursor_count);
buffer_batch_edit_update_cursors(cursors, cursor_count, batch, batch_size);
buffer_unsort_cursors(cursors, cursor_count);
}
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);
if (current_view && current_view->file == file){
view_cursor_move(current_view, cursors[cursor_count++].pos);
current_view->mark = cursors[cursor_count++].pos;
current_view->preferred_x = view_get_cursor_x(current_view);
}
}
end_temp_memory(cursor_temp);
}
#endif #endif
} }
@ -4168,10 +4200,27 @@ draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *t
if (font) advance_data = font->advance_data; if (font) advance_data = font->advance_data;
i32 count; i32 count;
Full_Cursor render_cursor;
Buffer_Render_Options opts = {}; Buffer_Render_Options opts = {};
buffer_get_render_data(&file->state.buffer, view->line_wrap_y, items, max, &count,
(f32)rect.x0, (f32)rect.y0, view->scroll_x, view->scroll_y, !view->unwrapped_lines, f32 *wraps = view->line_wrap_y;
(f32)max_x, (f32)max_y, advance_data, (f32)line_height, opts); f32 scroll_x = view->scroll_x;
f32 scroll_y = view->scroll_y;
{
render_cursor = buffer_get_start_cursor(&file->state.buffer, wraps, scroll_y,
!view->unwrapped_lines, (f32)max_x, advance_data, (f32)line_height);
view->scroll_i = render_cursor.pos;
buffer_get_render_data(&file->state.buffer, items, max, &count,
(f32)rect.x0, (f32)rect.y0,
scroll_x, scroll_y, render_cursor,
!view->unwrapped_lines,
(f32)max_x, (f32)max_y,
advance_data, (f32)line_height,
opts);
}
Assert(count > 0); Assert(count > 0);
@ -4212,9 +4261,11 @@ draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *t
Buffer_Render_Item *item = items; Buffer_Render_Item *item = items;
i32 prev_ind = -1; i32 prev_ind = -1;
u32 highlight_color = 0; u32 highlight_color = 0;
u32 highlight_this_color = 0;
for (i32 i = 0; i < count; ++i, ++item){ for (i32 i = 0; i < count; ++i, ++item){
i32 ind = item->index; i32 ind = item->index;
highlight_this_color = 0;
if (tokens_use && ind != prev_ind){ if (tokens_use && ind != prev_ind){
Cpp_Token current_token = token_stack.tokens[token_i-1]; Cpp_Token current_token = token_stack.tokens[token_i-1];
@ -4231,23 +4282,39 @@ draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *t
} }
if (current_token.type == CPP_TOKEN_JUNK && if (current_token.type == CPP_TOKEN_JUNK &&
i >= current_token.start && i <= current_token.start + current_token.size){ i >= current_token.start && i < current_token.start + current_token.size){
highlight_color = style->main.highlight_junk_color; highlight_color = style->main.highlight_junk_color;
} }
else{
highlight_color = 0;
}
} }
u32 char_color = main_color;
u32 char_color = main_color;
if (item->flags & BRFlag_Special_Character) char_color = special_color; if (item->flags & BRFlag_Special_Character) char_color = special_color;
f32_Rect char_rect = f32R(item->x0, item->y0, item->x1, item->y1);
if (view->show_whitespace && highlight_color == 0 &&
char_is_whitespace((char)item->glyphid)){
highlight_this_color = style->main.highlight_white_color;
}
else{
highlight_this_color = highlight_color;
}
if (cursor_begin <= ind && ind < cursor_end && (ind != prev_ind || cursor_begin < ind)){ if (cursor_begin <= ind && ind < cursor_end && (ind != prev_ind || cursor_begin < ind)){
if (is_active){ if (is_active){
draw_rectangle(target, f32R(item->x0, item->y0, item->x1, item->y1), cursor_color); draw_rectangle(target, char_rect, cursor_color);
char_color = at_cursor_color; char_color = at_cursor_color;
} }
else draw_rectangle_outline(target, f32R(item->x0, item->y0, item->x1, item->y1), cursor_color); else{
if (!view->show_temp_highlight){
draw_rectangle_outline(target, char_rect, cursor_color);
}
}
} }
else if (highlight_color){ else if (highlight_this_color){
draw_rectangle(target, f32R(item->x0, item->y0, item->x1, item->y1), highlight_color); draw_rectangle(target, char_rect, highlight_this_color);
} }
u32 fade_color = 0xFFFF00FF; u32 fade_color = 0xFFFF00FF;
@ -4263,7 +4330,7 @@ draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *t
char_color = color_blend(char_color, fade_amount, fade_color); char_color = color_blend(char_color, fade_amount, fade_color);
if (ind == view->mark && prev_ind != ind){ if (ind == view->mark && prev_ind != ind){
draw_rectangle_outline(target, f32R(item->x0, item->y0, item->x1, item->y1), mark_color); draw_rectangle_outline(target, char_rect, mark_color);
} }
if (item->glyphid != 0){ if (item->glyphid != 0){
font_draw_glyph(target, font_id, (u8)item->glyphid, font_draw_glyph(target, font_id, (u8)item->glyphid,

View File

@ -15,27 +15,18 @@ internal void
keycode_init(Key_Codes *codes){ keycode_init(Key_Codes *codes){
set_dynamic_key_names(codes); set_dynamic_key_names(codes);
u16 code, loose; keycode_lookup_table[KEY_BACKSPACE] = codes->back;
for (u16 i = 0; i < 255; ++i){ keycode_lookup_table[KEY_DELETE] = codes->del;
if (i >= 'a' && i <= 'z'){ keycode_lookup_table[KEY_UP] = codes->up;
keycode_lookup_table[i] = i + ('A' - 'a'); keycode_lookup_table[KEY_DOWN] = codes->down;
loose_keycode_lookup_table[i] = 0; keycode_lookup_table[KEY_LEFT] = codes->left;
} keycode_lookup_table[KEY_RIGHT] = codes->right;
keycode_lookup_table[KEY_INSERT] = codes->insert;
else if (i >= '0' && i <= '9'){ keycode_lookup_table[KEY_HOME] = codes->home;
keycode_lookup_table[i] = i; keycode_lookup_table[KEY_END] = codes->end;
loose_keycode_lookup_table[i] = 0; keycode_lookup_table[KEY_PAGEUP] = codes->page_up;
} keycode_lookup_table[KEY_PAGEDOWN] = codes->page_down;
keycode_lookup_table[KEY_ESC] = codes->esc;
else{
loose = 0;
switch (i){
}
keycode_lookup_table[i] = code;
loose_keycode_lookup_table[i] = loose;
}
}
} }
// BOTTOM // BOTTOM

View File

@ -112,7 +112,7 @@ _OutDbgStr(u8*);
TMax(u8, 255); TMax(u8, 255);
TMax(u16, 65535); TMax(u16, 65535);
TMax(u32, 4294967295); TMax(u32, 4294967295);
TMax(u64, 18446744073709551615); TMax(u64, 18446744073709551615U);
TMax(i8, 127); TMax(i8, 127);
TMax(i16, 32767); TMax(i16, 32767);

View File

@ -1145,13 +1145,33 @@ struct Buffer_Render_Options{
b8 show_slash_t; b8 show_slash_t;
}; };
internal_4tech Full_Cursor
buffer_get_start_cursor(Buffer_Type *buffer, float *wraps, float scroll_y,
int wrapped, float width, float *advance_data, float font_height){
Full_Cursor result;
if (wrapped){
result = buffer_cursor_from_wrapped_xy(buffer, 0, scroll_y, 0, wraps,
width, font_height, advance_data);
}
else{
result = buffer_cursor_from_unwrapped_xy(buffer, 0, scroll_y, 0, wraps,
width, font_height, advance_data);
}
return(result);
}
internal_4tech void internal_4tech void
buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *items, int max, int *count, buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, int max, int *count,
float port_x, float port_y, float scroll_x, float scroll_y, int wrapped, float port_x, float port_y,
float width, float height, float *advance_data, float font_height, float scroll_x, float scroll_y, Full_Cursor start_cursor,
int wrapped,
float width, float height,
float *advance_data, float font_height,
Buffer_Render_Options opts){ Buffer_Render_Options opts){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
Full_Cursor start_cursor;
Buffer_Render_Item *item; Buffer_Render_Item *item;
char *data; char *data;
int size, end; int size, end;
@ -1165,16 +1185,8 @@ buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *it
shift_x = port_x - scroll_x; shift_x = port_x - scroll_x;
shift_y = port_y - scroll_y; shift_y = port_y - scroll_y;
if (wrapped){ if (wrapped) shift_y += start_cursor.wrapped_y;
start_cursor = buffer_cursor_from_wrapped_xy(buffer, 0, scroll_y, 0, wraps, else shift_y += start_cursor.unwrapped_y;
width, font_height, advance_data);
shift_y += start_cursor.wrapped_y;
}
else{
start_cursor = buffer_cursor_from_unwrapped_xy(buffer, 0, scroll_y, 0, wraps,
width, font_height, advance_data);
shift_y += start_cursor.unwrapped_y;
}
x = shift_x; x = shift_x;
y = shift_y; y = shift_y;

View File

@ -1,3 +1,3 @@
@echo off @echo off
call "w:\4ed\code\buildsuper.bat" call "w:\4ed\misc\builddbg.bat"

View File

@ -9,50 +9,7 @@
// TOP // TOP
#ifdef FRED_NOT_PACKAGE #include "4ed_config.h"
#define FRED_INTERNAL 1
#define FRED_SLOW 1
#define FRED_PRINT_DEBUG 1
#define FRED_PRINT_DEBUG_FILE_LINE 0
#define FRED_PROFILING 1
#define FRED_PROFILING_OS 0
#define FRED_FULL_ERRORS 0
#else
#define FRED_SLOW 0
#define FRED_INTERNAL 0
#define FRED_PRINT_DEBUG 0
#define FRED_PRINT_DEBUG_FILE_LINE 0
#define FRED_PROFILING 0
#define FRED_PROFILING_OS 0
#define FRED_FULL_ERRORS 0
#endif
#define SOFTWARE_RENDER 0
#if FRED_INTERNAL == 0
# undef FRED_PRINT_DEBUG
# define FRED_PRINT_DEBUG 0
# undef FRED_PROFILING
# define FRED_PROFILING 0
# undef FRED_PROFILING_OS
# define FRED_PROFILING_OS 0
#endif
#if FRED_PRINT_DEBUG == 0
# undef FRED_PRINT_DEBUG_FILE_LINE
# define FRED_PRINT_DEBUG_FILE_LINE 0
# undef FRED_PRINT_DEBUG_FILE_LINE
# define FRED_PROFILING_OS 0
#endif
#define FPS 30
#define frame_useconds (1000000 / FPS)
#include "4ed_meta.h" #include "4ed_meta.h"
@ -60,334 +17,480 @@
#include "4cpp_types.h" #include "4cpp_types.h"
#define FCPP_STRING_IMPLEMENTATION #define FCPP_STRING_IMPLEMENTATION
#include "4cpp_string.h" #include "4coder_string.h"
#include "4ed_mem.cpp" #include "4ed_mem.cpp"
#include "4ed_math.cpp" #include "4ed_math.cpp"
#include "4coder_custom.h" #include "4coder_custom.h"
#include "4ed_system.h" #include "4ed_system.h"
#include "4ed.h"
#include "4ed_rendering.h" #include "4ed_rendering.h"
#include "4ed.h"
#include <sys/stat.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <GL/gl.h>
#include <stdio.h> #include <stdio.h>
#include <memory.h>
#include <math.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <xmmintrin.h>
#include <linux/fs.h>
#include <X11/extensions/XInput2.h>
#include <linux/input.h>
#include "4ed_internal.h" #include "4ed_internal.h"
#include "4ed_linux_keyboard.cpp" #include "4ed_linux_keyboard.cpp"
#define printe(m) printf("%s:%d: %s\n", __FILE__, __LINE__, #m) // NOTE(allen): Thanks to Casey for providing the linux OpenGL launcher.
/* TODO(allen):
struct Linux_Vars{ 1. get 4coder rendering it's blank self
Key_Codes codes; 2. get input working
Key_Input_Data input; (release linux version)
Mouse_State mouse; 3. add in extra stuff as it is completed in windows
Render_Target target;
Application_Memory mem;
b32 keep_going;
b32 force_redraw;
Clipboard_Contents clipboard; */
void *app_code, *custom; static bool ctxErrorOccurred = false;
static int XInput2OpCode = 0;
System_Functions *system; internal int
App_Functions app; ctxErrorHandler( Display *dpy, XErrorEvent *ev )
Config_API config_api; {
ctxErrorOccurred = true;
}; return 0;
Linux_Vars linuxvars;
internal
Sys_Get_Memory_Sig(system_get_memory_){
void *ptr = 0;
i32 prot = PROT_READ | PROT_WRITE;
i32 flags = MAP_PRIVATE | MAP_ANON;
#if FRED_INTERNAL
ptr = mmap(0, size + sizeof(Sys_Bubble), prot, flags, -1, 0);
Sys_Bubble *bubble = (Sys_Bubble*)ptr;
bubble->flags = MEM_BUBBLE_SYS_DEBUG;
bubble->line_number = line_number;
bubble->file_name = file_name;
bubble->size = size;
//WaitForSingleObject(win32vars.DEBUG_sysmem_lock, INFINITE);
insert_bubble(&win32vars.internal_bubble, bubble);
//ReleaseSemaphore(win32vars.DEBUG_sysmem_lock, 1, 0);
ptr = bubble + 1;
#else
ptr = mmap(0, size + sizeof(i32), prot, flags, -1, 0);
i32 *size_ptr = (i32*)ptr;
*size_ptr = size;
ptr = size_ptr + 1;
#endif
return ptr;
} }
#define system_get_memory(size) system_get_memory_(size, __LINE__, __FILE__) internal GLXContext
InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig &bestFbc, b32 &IsLegacy)
{
IsLegacy = false;
internal typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
Sys_Free_Memory_Sig(system_free_memory){ const char *glxExts = glXQueryExtensionsString(XDisplay, DefaultScreen(XDisplay));
if (block){
#if FRED_INTERNAL glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
Sys_Bubble *bubble = ((Sys_Bubble*)block) - 1; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
Assert((bubble->flags & MEM_BUBBLE_DEBUG_MASK) == MEM_BUBBLE_SYS_DEBUG); glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
//WaitForSingleObject(win32vars.DEBUG_sysmem_lock, INFINITE);
remove_bubble(bubble); GLXContext ctx = 0;
//ReleaseSemaphore(win32vars.DEBUG_sysmem_lock, 1, 0); ctxErrorOccurred = false;
munmap(bubble, bubble->size); int (*oldHandler)(Display*, XErrorEvent*) =
#else XSetErrorHandler(&ctxErrorHandler);
i32 *size_ptr = (i32*)block - 1; if (!glXCreateContextAttribsARB)
munmap(size_ptr, *size_ptr); {
#endif printf( "glXCreateContextAttribsARB() not found"
" ... using old-style GLX context\n" );
ctx = glXCreateNewContext( XDisplay, bestFbc, GLX_RGBA_TYPE, 0, True );
} }
} else
{
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
//GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
None
};
internal printf("\nAttribs: %d %d %d %d %d\n",
Sys_Time_Sig(system_time){ context_attribs[0],
i64 result = 0; context_attribs[1],
struct timespec tp; context_attribs[2],
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0){ context_attribs[3],
result = tp.tv_sec*1000000 + tp.tv_nsec/1000; context_attribs[4]);
}
return result;
}
internal printf( "Creating context\n" );
Sys_Load_File_Sig(system_load_file){ ctx = glXCreateContextAttribsARB( XDisplay, bestFbc, 0,
File_Data result = {}; True, context_attribs );
i32 prot = PROT_READ;
i32 flags = MAP_PRIVATE | MAP_ANON;
struct stat sb; XSync( XDisplay, False );
if (stat(filename, &sb) == 0){ if ( !ctxErrorOccurred && ctx )
result.size = sb.st_size; {
result.data = system_get_memory(result.size); printf( "Created GL 4.3 context\n" );
if (result.data){ }
i32 file = open(filename, O_RDONLY); else
i32 result_size = read(file, result.data, result.size); {
Assert(result_size == result.size); ctxErrorOccurred = false;
close(file);
context_attribs[1] = 4;
context_attribs[3] = 0;
printf( "Creating context\n" );
ctx = glXCreateContextAttribsARB( XDisplay, bestFbc, 0,
True, context_attribs );
XSync( XDisplay, False );
if ( !ctxErrorOccurred && ctx )
{
printf( "Created GL 4.0 context\n" );
}
else
{
context_attribs[1] = 1;
context_attribs[3] = 0;
ctxErrorOccurred = false;
printf( "Failed to create GL 4.0 context"
" ... using old-style GLX context\n" );
ctx = glXCreateContextAttribsARB( XDisplay, bestFbc, 0,
True, context_attribs );
IsLegacy = true;
}
} }
} }
return result; XSync( XDisplay, False );
} XSetErrorHandler( oldHandler );
internal if ( ctxErrorOccurred || !ctx )
Sys_Save_File_Sig(system_save_file){ {
i32 file = open(filename, O_CREAT | O_WRONLY); printf( "Failed to create an OpenGL context\n" );
if (!file) return 0; exit(1);
}
i32 result_size = write(file, data, size); if ( ! glXIsDirect ( XDisplay, ctx ) )
Assert(result_size == size); {
printf( "Indirect GLX rendering context obtained\n" );
}
else
{
printf( "Direct GLX rendering context obtained\n" );
}
close(file); printf( "Making context current\n" );
return 1; glXMakeCurrent( XDisplay, XWindow, ctx );
GLint n;
char *Vendor = (char *)glGetString(GL_VENDOR);
char *Renderer = (char *)glGetString(GL_RENDERER);
char *Version = (char *)glGetString(GL_VERSION);
char *Extensions = (char *)glGetString(GL_EXTENSIONS);
printf("GL_VENDOR: %s\n", Vendor);
printf("GL_RENDERER: %s\n", Renderer);
printf("GL_VERSION: %s\n", Version);
printf("GL_EXTENSIONS: %s\n", Extensions);
return(ctx);
} }
internal b32 internal b32
LinuxLoadAppCode(){ GLXSupportsModernContexts(Display *XDisplay)
b32 result = 0; {
b32 Result = false;
char app_code_file[] = "4ed_app.so"; int GLXMajor, GLXMinor;
i32 app_code_file_len = sizeof(app_code_file) - 1;
char path[1024]; char *XVendor = ServerVendor(XDisplay);
i32 size = readlink("/proc/self/exe", path, printf("XWindows vendor: %s\n", XVendor);
1024 - app_code_file_len - 1); if(glXQueryVersion(XDisplay, &GLXMajor, &GLXMinor))
{
for (--size; printf("GLX version %d.%d\n", GLXMajor, GLXMinor);
path[size] != '/' && size > 0; if(((GLXMajor == 1 ) && (GLXMinor >= 3)) ||
--size); (GLXMajor > 1))
memcpy(path + size + 1, app_code_file, app_code_file_len + 1); {
Result = true;
linuxvars.app_code = 0; }
if (linuxvars.app_code){
result = 1;
linuxvars.app.init = (App_Init*)0;
linuxvars.app.step = (App_Step*)0;
}
else{
// TODO(allen): initialization failure
printe(app_code);
} }
return result; return(Result);
} }
internal typedef struct glx_config_result{
Sys_Acquire_Lock_Sig(system_acquire_lock){ b32 Found;
AllowLocal(id); GLXFBConfig BestConfig;
} XVisualInfo BestInfo;
} glx_config_result;
internal internal glx_config_result
Sys_Release_Lock_Sig(system_release_lock){ ChooseGLXConfig(Display *XDisplay, int XScreenIndex)
AllowLocal(id); {
} glx_config_result Result = {0};
internal int DesiredAttributes[] =
Sys_Force_Redraw_Sig(system_force_redraw){ {
linuxvars.force_redraw = 1; GLX_X_RENDERABLE , True,
} GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
GLX_RENDER_TYPE , GLX_RGBA_BIT,
internal void GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
LinuxLoadSystemCode(){ GLX_RED_SIZE , 8,
linuxvars.system->get_memory_full = system_get_memory_; GLX_GREEN_SIZE , 8,
linuxvars.system->free_memory = system_free_memory; GLX_BLUE_SIZE , 8,
GLX_ALPHA_SIZE , 8,
linuxvars.system->load_file = system_load_file; GLX_DEPTH_SIZE , 24,
linuxvars.system->save_file = system_save_file; GLX_STENCIL_SIZE , 8,
GLX_DOUBLEBUFFER , True,
#if 0 //GLX_SAMPLE_BUFFERS , 1,
linuxvars.system->file_time_stamp = system_file_time_stamp; //GLX_SAMPLES , 4,
linuxvars.system->time_stamp_now = system_time_stamp_now; None
linuxvars.system->free_file = system_free_file; };
linuxvars.system->get_current_directory = system_get_current_directory;
linuxvars.system->get_easy_directory = system_get_easy_directory;
linuxvars.system->get_file_list = system_get_file_list;
linuxvars.system->free_file_list = system_free_file_list;
linuxvars.system->post_clipboard = system_post_clipboard;
linuxvars.system->time = system_time;
linuxvars.system->cli_call = system_cli_call;
linuxvars.system->cli_begin_update = system_cli_begin_update;
linuxvars.system->cli_update_step = system_cli_update_step;
linuxvars.system->cli_end_update = system_cli_end_update;
linuxvars.system->thread_get_id = system_thread_get_id;
linuxvars.system->thread_current_job_id = system_thread_current_job_id;
linuxvars.system->post_job = system_post_job;
linuxvars.system->cancel_job = system_cancel_job;
linuxvars.system->job_is_pending = system_job_is_pending;
linuxvars.system->grow_thread_memory = system_grow_thread_memory;
linuxvars.system->acquire_lock = system_acquire_lock;
linuxvars.system->release_lock = system_release_lock;
linuxvars.system->force_redraw = system_force_redraw;
linuxvars.system->internal_sentinel = INTERNAL_system_sentinel;
linuxvars.system->internal_get_thread_states = INTERNAL_get_thread_states;
#endif
}
internal void
LinuxShowScreen(){
}
int main(){
linuxvars = {};
if (!LinuxLoadAppCode()){
return(1);
}
System_Functions system_;
System_Functions *system = &system_;
linuxvars.system = system;
LinuxLoadSystemCode();
{ {
void *base; int ConfigCount;
#if FRED_INTERNAL GLXFBConfig *Configs = glXChooseFBConfig(XDisplay,
base = (void*)Mbytes(128); XScreenIndex,
#else DesiredAttributes,
base = (void*)0; &ConfigCount);
#endif
i32 prot = PROT_READ | PROT_WRITE;
i32 flags = MAP_PRIVATE | MAP_ANON;
linuxvars.mem.vars_memory_size = Mbytes(2);
linuxvars.mem.vars_memory = mmap(base, linuxvars.mem.vars_memory_size,
prot, flags, -1, 0);
#if FRED_INTERNAL
base = (void*)Mbytes(160);
#else
base = (void*)0;
#endif
linuxvars.mem.target_memory_size = Mbytes(64);
linuxvars.mem.target_memory = mmap(base, linuxvars.mem.target_memory_size,
prot, flags, -1, 0);
}
i32 width = 800;
i32 height = 600;
i32 bpp = 24;
linuxvars.target.width = width;
linuxvars.target.height = height;
keycode_init(&linuxvars.codes);
system_acquire_lock(FRAME_LOCK);
b32 first = 1;
linuxvars.keep_going = 1;
i64 timer_start = system_time();
for (;linuxvars.keep_going;){
linuxvars.input = {};
linuxvars.clipboard = {};
linuxvars.mouse.wheel = 0;
linuxvars.force_redraw = 0;
for (;0;){
}
linuxvars.mouse.left_button_prev = linuxvars.mouse.left_button;
linuxvars.mouse.right_button_prev = linuxvars.mouse.right_button;
#if 0 #if 0
Application_Step_Result app_result = int DiffValues[GLXValueCount];
linuxvars.app.step(linuxvars.system, #endif
&linuxvars.codes, {for(int ConfigIndex = 0;
&linuxvars.input, ConfigIndex < ConfigCount;
&linuxvars.mouse, ++ConfigIndex)
&linuxvars.target, {
&linuxvars.mem, GLXFBConfig &Config = Configs[ConfigIndex];
linuxvars.clipboard, XVisualInfo *VisualInfo = glXGetVisualFromFBConfig(XDisplay, Config);
1, first, linuxvars.force_redraw);
#else #if 0
Application_Step_Result app_result = {}; printf(" Option %d:\n", ConfigIndex);
printf(" Depth: %d\n", VisualInfo->depth);
printf(" Bits per channel: %d\n", VisualInfo->bits_per_rgb);
printf(" Mask: R%06x G%06x B%06x\n",
(uint32)VisualInfo->red_mask,
(uint32)VisualInfo->green_mask,
(uint32)VisualInfo->blue_mask);
printf(" Class: %d\n", VisualInfo->c_class);
#endif #endif
if (1 || linuxvars.force_redraw){ #if 0
//glClearColor(1.f, 1.f, 0.f, 1.f); {for(int ValueIndex = 0;
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ValueIndex < GLXValueCount;
LinuxShowScreen(); ++ValueIndex)
linuxvars.force_redraw = 0; {
} glx_value_info &ValueInfo = GLXValues[ValueIndex];
int Value;
glXGetFBConfigAttrib(XDisplay, Config, ValueInfo.ID, &Value);
if(DiffValues[ValueIndex] != Value)
{
printf(" %s: %d\n", ValueInfo.Name, Value);
DiffValues[ValueIndex] = Value;
}
}}
#endif
i64 timer_target = timer_start + frame_useconds; // TODO(casey): How the hell are you supposed to pick a config here??
i64 timer_end = system_time(); if(ConfigIndex == 0)
for (;timer_end < timer_target;){ {
i64 samount = timer_target - timer_end; Result.Found = true;
usleep(samount); Result.BestConfig = Config;
timer_end = system_time(); Result.BestInfo = *VisualInfo;
} }
timer_start = system_time();
XFree(VisualInfo);
}}
XFree(Configs);
} }
return(0); return(Result);
}
internal void
InitializeXInput(Display *dpy, Window XWindow)
{
int event, error;
if(XQueryExtension(dpy, "XInputExtension", &XInput2OpCode, &event, &error))
{
int major = 2, minor = 0;
if(XIQueryVersion(dpy, &major, &minor) != BadRequest)
{
printf("XInput initialized");
}
else
{
printf("XI2 not available. Server supports %d.%d\n", major, minor);
}
}
else
{
printf("X Input extension not available.\n");
}
/*
TODO(casey): So, this is all one big clusterfuck I guess.
The problem here is that you want to be able to get input
from all possible devices that could be a mouse or keyboard
(or gamepad, or whatever). So you'd like to be able to
register events for XIAllDevices, so that when a new
input device is connected, you will start receiving
input from it automatically, without having to periodically
poll XIQueryDevice to see if a new device has appeared.
UNFORTUNATELY, this is not actually possible in Linux because
there was a bug in Xorg (as of early 2013, it is still not
fixed in most distributions people are using, AFAICT) which
makes the XServer return an error if you actually try to
do this :(
But EVENTUALLY, if that shit gets fixed, then that is
the way this should work.
*/
#if 0
int DeviceCount;
XIDeviceInfo *DeviceInfo = XIQueryDevice(dpy, XIAllDevices, &DeviceCount);
{for(int32x DeviceIndex = 0;
DeviceIndex < DeviceCount;
++DeviceIndex)
{
XIDeviceInfo *Device = DeviceInfo + DeviceIndex;
printf("Device %d: %s\n", Device->deviceid, Device->name);
}}
XIFreeDeviceInfo(DeviceInfo);
#endif
XIEventMask Mask = {0};
Mask.deviceid = XIAllDevices;
Mask.mask_len = XIMaskLen(XI_RawMotion);
size_t MaskSize = Mask.mask_len * sizeof(char unsigned);
Mask.mask = (char unsigned *)alloca(MaskSize);
memset(Mask.mask, 0, MaskSize);
if(Mask.mask)
{
XISetMask(Mask.mask, XI_ButtonPress);
XISetMask(Mask.mask, XI_ButtonRelease);
XISetMask(Mask.mask, XI_KeyPress);
XISetMask(Mask.mask, XI_KeyRelease);
XISetMask(Mask.mask, XI_Motion);
XISetMask(Mask.mask, XI_DeviceChanged);
XISetMask(Mask.mask, XI_Enter);
XISetMask(Mask.mask, XI_Leave);
XISetMask(Mask.mask, XI_FocusIn);
XISetMask(Mask.mask, XI_FocusOut);
XISetMask(Mask.mask, XI_HierarchyChanged);
XISetMask(Mask.mask, XI_PropertyEvent);
XISelectEvents(dpy, XWindow, &Mask, 1);
XSync(dpy, False);
Mask.deviceid = XIAllMasterDevices;
memset(Mask.mask, 0, MaskSize);
XISetMask(Mask.mask, XI_RawKeyPress);
XISetMask(Mask.mask, XI_RawKeyRelease);
XISetMask(Mask.mask, XI_RawButtonPress);
XISetMask(Mask.mask, XI_RawButtonRelease);
XISetMask(Mask.mask, XI_RawMotion);
XISelectEvents(dpy, DefaultRootWindow(dpy), &Mask, 1);
}
}
int
main(int ArgCount, char **Args)
{
Display *XDisplay = XOpenDisplay(0);
if(XDisplay && GLXSupportsModernContexts(XDisplay))
{
int XScreenCount = ScreenCount(XDisplay);
for(int XScreenIndex = 0;
XScreenIndex < XScreenCount;
++XScreenIndex)
{
Screen *XScreen = ScreenOfDisplay(XDisplay, XScreenIndex);
int WinWidth = WidthOfScreen(XScreen);
int WinHeight = HeightOfScreen(XScreen);
glx_config_result Config = ChooseGLXConfig(XDisplay, XScreenIndex);
if(Config.Found)
{
Colormap cmap;
XSetWindowAttributes swa;
swa.colormap = cmap = XCreateColormap(XDisplay,
RootWindow(XDisplay, Config.BestInfo.screen ),
Config.BestInfo.visual, AllocNone);
swa.background_pixmap = None;
swa.border_pixel = 0;
swa.event_mask = StructureNotifyMask;
Window XWindow = XCreateWindow(XDisplay,
RootWindow(XDisplay, Config.BestInfo.screen),
0, 0, WinWidth, WinHeight,
0, Config.BestInfo.depth, InputOutput,
Config.BestInfo.visual,
CWBorderPixel|CWColormap|CWEventMask, &swa );
if(XWindow)
{
XStoreName(XDisplay, XWindow, "4coder");
XMapWindow(XDisplay, XWindow);
InitializeXInput(XDisplay, XWindow);
b32 IsLegacy = false;
GLXContext GLContext =
InitializeOpenGLContext(XDisplay, XWindow, Config.BestConfig, IsLegacy);
XWindowAttributes WinAttribs;
if(XGetWindowAttributes(XDisplay, XWindow, &WinAttribs))
{
WinWidth = WinAttribs.width;
WinHeight = WinAttribs.height;
}
XRaiseWindow(XDisplay, XWindow);
XSync(XDisplay, False);
for(;;)
{
while(XPending(XDisplay))
{
XEvent Event;
XNextEvent(XDisplay, &Event);
if((Event.xcookie.type == GenericEvent) &&
(Event.xcookie.extension == XInput2OpCode) &&
XGetEventData(XDisplay, &Event.xcookie))
{
switch(Event.xcookie.evtype)
{
case XI_Motion:
{
Window root_return, child_return;
int root_x_return, root_y_return;
int MouseX, MouseY;
unsigned int mask_return;
XQueryPointer(XDisplay,
XWindow,
&root_return, &child_return,
&root_x_return, &root_y_return,
&MouseX, &MouseY,
&mask_return);
} break;
case XI_ButtonPress:
case XI_ButtonRelease:
{
b32 Down = (Event.xcookie.evtype == XI_ButtonPress);
XIDeviceEvent *DevEvent = (XIDeviceEvent *)Event.xcookie.data;
int Button = DevEvent->detail;
} break;
case XI_KeyPress:
case XI_KeyRelease:
{
b32 Down = (Event.xcookie.evtype == XI_KeyPress);
XIDeviceEvent *DevEvent = (XIDeviceEvent *)Event.xcookie.data;
int VK = DevEvent->detail;
} break;
}
XFreeEventData(XDisplay, &Event.xcookie);
}
}
// Draw some stuff here?
glXSwapBuffers(XDisplay, XWindow);
}
}
}
}
}
} }
// BOTTOM // BOTTOM

BIN
vc120.pdb

Binary file not shown.

View File

@ -23,6 +23,7 @@
#include "4ed_math.cpp" #include "4ed_math.cpp"
#include "4ed_dll_reader.h" #include "4ed_dll_reader.h"
#include "4coder_custom.h" #include "4coder_custom.h"
#include "4ed_system.h" #include "4ed_system.h"
#include "4ed_rendering.h" #include "4ed_rendering.h"
@ -143,6 +144,7 @@ struct Win32_Vars{
DLL_Loaded custom_dll; DLL_Loaded custom_dll;
#endif #endif
Plat_Settings settings;
System_Functions *system; System_Functions *system;
App_Functions app; App_Functions app;
Custom_API custom_api; Custom_API custom_api;
@ -156,7 +158,6 @@ struct Win32_Vars{
Win32_Font_Load_Parameters used_font_param; Win32_Font_Load_Parameters used_font_param;
Win32_Font_Load_Parameters free_font_param; Win32_Font_Load_Parameters free_font_param;
Partition fnt_part; Partition fnt_part;
}; };
globalvar Win32_Vars win32vars; globalvar Win32_Vars win32vars;
@ -1524,6 +1525,7 @@ WinMain(HINSTANCE hInstance,
memory_vars.target_memory = VirtualAlloc(base, memory_vars.target_memory_size, memory_vars.target_memory = VirtualAlloc(base, memory_vars.target_memory_size,
MEM_COMMIT | MEM_RESERVE, MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE); PAGE_READWRITE);
//
if (!memory_vars.vars_memory){ if (!memory_vars.vars_memory){
return 4; return 4;
@ -1546,9 +1548,12 @@ WinMain(HINSTANCE hInstance,
win32vars.app.read_command_line(system, win32vars.app.read_command_line(system,
&memory_vars, &memory_vars,
current_directory, current_directory,
&win32vars.settings,
clparams); clparams);
if (output_size > 0){ //
if (output_size > 0){
// TODO
} }
if (output_size != 0) return 0; if (output_size != 0) return 0;
@ -1566,13 +1571,21 @@ WinMain(HINSTANCE hInstance,
keycode_init(&win32vars.key_codes); keycode_init(&win32vars.key_codes);
#ifdef FRED_SUPER #ifdef FRED_SUPER
win32vars.custom = LoadLibraryA("4coder_custom.dll"); char *custom_file_default = "4coder_custom.dll";
char *custom_file;
if (win32vars.settings.custom_dll) custom_file = win32vars.settings.custom_dll;
else custom_file = custom_file_default;
win32vars.custom = LoadLibraryA(custom_file);
if (!win32vars.custom && custom_file != custom_file_default){
if (!win32vars.settings.custom_dll_is_strict){
win32vars.custom = LoadLibraryA(custom_file_default);
}
}
if (win32vars.custom){ if (win32vars.custom){
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*) win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)
GetProcAddress(win32vars.custom, "get_bindings"); GetProcAddress(win32vars.custom, "get_bindings");
win32vars.custom_api.set_extra_font = (Set_Extra_Font_Function*)
GetProcAddress(win32vars.custom, "set_extra_font");
} }
#endif #endif
@ -1630,8 +1643,15 @@ WinMain(HINSTANCE hInstance,
} }
RECT window_rect = {}; RECT window_rect = {};
window_rect.right = 800;
window_rect.bottom = 600; if (win32vars.settings.set_window_size){
window_rect.right = win32vars.settings.window_w;
window_rect.bottom = win32vars.settings.window_h;
}
else{
window_rect.right = 800;
window_rect.bottom = 600;
}
if (!AdjustWindowRect(&window_rect, WS_OVERLAPPEDWINDOW, false)){ if (!AdjustWindowRect(&window_rect, WS_OVERLAPPEDWINDOW, false)){
// TODO(allen): non-fatal diagnostics // TODO(allen): non-fatal diagnostics
@ -1639,12 +1659,29 @@ WinMain(HINSTANCE hInstance,
#define WINDOW_NAME "4coder-window" #define WINDOW_NAME "4coder-window"
i32 window_x;
i32 window_y;
i32 window_style;
if (win32vars.settings.set_window_pos){
window_x = win32vars.settings.window_x;
window_y = win32vars.settings.window_y;
}
else{
window_x = CW_USEDEFAULT;
window_y = CW_USEDEFAULT;
}
window_style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
if (win32vars.settings.maximize_window){
window_style |= WS_MAXIMIZE;
}
HWND window_handle = {}; HWND window_handle = {};
window_handle = CreateWindowA( window_handle = CreateWindowA(
window_class.lpszClassName, window_class.lpszClassName,
WINDOW_NAME, WINDOW_NAME, window_style,
WS_OVERLAPPEDWINDOW | WS_VISIBLE, window_x, window_y,
CW_USEDEFAULT, CW_USEDEFAULT,
window_rect.right - window_rect.left, window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top, window_rect.bottom - window_rect.top,
0, 0, hInstance, 0); 0, 0, hInstance, 0);
@ -1660,15 +1697,6 @@ WinMain(HINSTANCE hInstance,
GetClientRect(window_handle, &window_rect); GetClientRect(window_handle, &window_rect);
#if 0
RAWINPUTDEVICE device;
device.usUsagePage = 0x1;
device.usUsage = 0x6;
device.dwFlags = 0;
device.hwndTarget = window_handle;
RegisterRawInputDevices(&device, 1, sizeof(device));
#endif
static PIXELFORMATDESCRIPTOR pfd = { static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), sizeof(PIXELFORMATDESCRIPTOR),
1, 1,