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)
#endif
// NOTE(allen|a3.1): All of your custom ids should be >= mapid_user_custom.
// I recommend enumerating your own map ids as shown here.
// NOTE(allen|a3.3): All of your custom ids should be enumerated
// 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{
my_code_map = mapid_user_custom,
my_code_map,
my_html_map
};
@ -73,8 +74,8 @@ CUSTOM_COMMAND_SIG(open_in_other){
CUSTOM_COMMAND_SIG(open_my_files){
// NOTE(allen|a3.1): The command cmdid_interactive_open can now open
// a file specified on the parameter stack. If the file does not
// exist cmdid_interactive_open behaves as usual.
// a file specified on the parameter stack. If the file does not exist
// cmdid_interactive_open behaves as usual.
push_parameter(app, cmd_context, par_name, literal("w:/4ed/data/test/basic.cpp"));
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);
#if 0
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 | MDFR_SHIFT, cmdid_write_character);
#endif
end_map(context);

View File

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

View File

@ -77,7 +77,7 @@ begin_bind_helper(void *data, int size){
inline void
begin_map(Bind_Helper *helper, int mapid){
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;
unit.type = unit_map_begin;
@ -170,7 +170,7 @@ bind_me_vanilla_keys(Bind_Helper *helper, unsigned char modifiers, Custom_Comman
inline void
inherit_map(Bind_Helper *helper, int mapid){
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;
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(String s);
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 copy_fast_unsafe(char *dest, char *src);

View File

@ -220,6 +220,7 @@ enum Cpp_Token_Type{
CPP_PP_UNKNOWN,
CPP_TOKEN_DEFINED,
CPP_TOKEN_INCLUDE_FILE,
CPP_TOKEN_ERROR_MESSAGE,
// NOTE(allen): used in the parser
CPP_TOKEN_EOF
@ -256,6 +257,7 @@ enum Cpp_Preprocessor_State{
CPP_LEX_PP_BODY,
CPP_LEX_PP_BODY_IF,
CPP_LEX_PP_NUMBER,
CPP_LEX_PP_ERROR,
CPP_LEX_PP_JUNK,
// NEVER ADD BELOW THIS
CPP_LEX_PP_COUNT
@ -450,6 +452,7 @@ FCPP_GLOBAL String_And_Flag keyword_strings[] = {
{"long", CPP_TOKEN_KEY_MODIFIER},
{"short", CPP_TOKEN_KEY_MODIFIER},
{"unsigned", CPP_TOKEN_KEY_MODIFIER},
{"const", CPP_TOKEN_KEY_QUALIFIER},
{"volatile", CPP_TOKEN_KEY_QUALIFIER},
@ -766,7 +769,7 @@ cpp_read_junk_line(Cpp_File file, int pos){
--pos;
}
result.pos = pos;
result.token.size = pos - result.token.start - 1;
result.token.size = pos - result.token.start;
}
return result;
@ -1348,6 +1351,9 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
lex.pp_state = CPP_LEX_PP_NUMBER;
break;
case CPP_PP_ERROR:
lex.pp_state = CPP_LEX_PP_ERROR;
break;
case CPP_PP_UNKNOWN:
case CPP_PP_ELSE:
case CPP_PP_ENDIF:
@ -1383,7 +1389,8 @@ cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex_data){
}
else{
if (lex.pp_state == CPP_LEX_PP_IDENTIFIER){
switch (lex.pp_state){
case CPP_LEX_PP_IDENTIFIER:
if (!char_is_alpha_numeric(current)){
has_result = 0;
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.pp_state = CPP_LEX_PP_JUNK;
}
}
else if (lex.pp_state == CPP_LEX_PP_MACRO_IDENTIFIER){
break;
case CPP_LEX_PP_MACRO_IDENTIFIER:
if (!char_is_alpha_numeric(current)){
has_result = 0;
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.pp_state = CPP_LEX_PP_BODY;
}
}
break;
else if (lex.pp_state == CPP_LEX_PP_INCLUDE){
case CPP_LEX_PP_INCLUDE:
if (current != '"' && current != '<'){
has_result = 0;
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.pp_state = CPP_LEX_PP_JUNK;
}
}
else if (lex.pp_state == CPP_LEX_PP_BODY){
break;
case CPP_LEX_PP_BODY:
if (current == '#'){
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;
result.token.flags |= CPP_TFLAG_PP_BODY;
}
else if (lex.pp_state == CPP_LEX_PP_BODY_IF){
break;
case CPP_LEX_PP_BODY_IF:
if (current == '#'){
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;
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)){
has_result = 0;
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;
lex.pp_state = CPP_LEX_PP_INCLUDE;
}
}
else{
break;
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;
if (current == '/' && lex.pos + 1 < file.size){
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;
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*
app_get_map(App_Vars *vars, i32 mapid){
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_file) map = &vars->map_file;
return map;
@ -1065,10 +1065,12 @@ COMMAND_DECL(kill_buffer){
COMMAND_DECL(toggle_line_wrap){
ProfileMomentFunction();
REQ_FILE_VIEW(view);
REQ_FILE(file, view);
Relative_Scrolling scrolling = view_get_relative_scrolling(view);
if (view->unwrapped_lines){
view->unwrapped_lines = 0;
file->settings.unwrapped_lines = 0;
view->target_x = 0;
view->cursor =
view_compute_cursor_from_pos(view, view->cursor.pos);
@ -1076,6 +1078,7 @@ COMMAND_DECL(toggle_line_wrap){
}
else{
view->unwrapped_lines = 1;
file->settings.unwrapped_lines = 1;
view->cursor =
view_compute_cursor_from_pos(view, view->cursor.pos);
view->preferred_x = view->cursor.unwrapped_x;
@ -1660,6 +1663,8 @@ COMMAND_DECL(set_settings){
if (view->unwrapped_lines){
if (v){
view->unwrapped_lines = 0;
file->settings.unwrapped_lines = 0;
if (!file->state.is_loading){
Relative_Scrolling scrolling = view_get_relative_scrolling(view);
view->target_x = 0;
@ -1672,6 +1677,7 @@ COMMAND_DECL(set_settings){
else{
if (!v){
view->unwrapped_lines = 1;
file->settings.unwrapped_lines = 1;
if (!file->state.is_loading){
Relative_Scrolling scrolling = view_get_relative_scrolling(view);
@ -1688,7 +1694,7 @@ COMMAND_DECL(set_settings){
int v = dynamic_to_int(&param->param.value);
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_user_custom){
else if (v < mapid_global){
int index = app_get_map_index(vars, v);
if (index < vars->user_map_count) file->settings.base_map_id = v;
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
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;
map_add(commands, codes->left, MDFR_NONE, command_null);
map_add(commands, codes->right, MDFR_NONE, command_null);
map_add(commands, codes->up, MDFR_NONE, command_null);
map_add(commands, codes->down, MDFR_NONE, command_null);
map_add(commands, codes->back, MDFR_NONE, command_null);
map_add(commands, codes->esc, MDFR_NONE, command_close_minor_view);
// TODO(allen): This is hacky, when the new UI stuff happens, let's fix it, and by that
// I mean actually fix it, don't just say you fixed it with something stupid again.
u8 mdfr;
u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL};
for (i32 i = 0; i < 4; ++i){
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
@ -2492,86 +2505,134 @@ HOOK_SIG(default_open_file_hook){
}
enum Command_Line_Action{
CLAct_Nothing,
CLAct_Ignore,
CLAct_UserFile,
CLAct_CustomDLL,
CLAct_InitialFilePosition,
CLAct_WindowSize,
CLAct_WindowMaximize,
CLAct_WindowPosition,
CLAct_Count
};
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){
char *arg;
Command_Line_Action action;
Command_Line_Action action = CLAct_Nothing;
i32 i,index;
b32 strict = 0;
settings->init_files_max = ArrayCount(settings->init_files);
for (i = 1; i < clparams.argc; ++i){
arg = clparams.argv[i];
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;
for (i = 1; i <= clparams.argc; ++i){
if (i == clparams.argc) arg = "";
else arg = clparams.argv[i];
switch (action){
case CLAct_Nothing:
{
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 = 1; break;
case 'd': action = CLAct_CustomDLL; strict = 0; 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 'p': action = CLAct_WindowPosition; break;
}
case 'w': action = CLAct_WindowSize; 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:
{
settings->user_file_is_strict = strict;
++i;
if (i < clparams.argc){
settings->user_file = clparams.argv[i];
}
break;
action = CLAct_Nothing;
}break;
case CLAct_CustomDLL:
{
plat_settings->custom_dll_is_strict = strict;
++i;
if (i < clparams.argc){
plat_settings->custom_dll = clparams.argv[i];
}
break;
action = CLAct_Nothing;
}break;
case CLAct_InitialFilePosition:
++i;
{
if (i < clparams.argc){
settings->initial_line = str_to_int(clparams.argv[i]);
}
break;
action = CLAct_Nothing;
}break;
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:
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]);
}
else{
if (settings->init_files_count < settings->init_files_max){
index = settings->init_files_count++;
settings->init_files[index] = arg;
}
++i;
}
action = CLAct_Nothing;
}break;
}
}
}
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){
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);
}
@ -2579,17 +2640,11 @@ App_Read_Command_Line_Sig(app_read_command_line){
App_Init_Sig(app_init){
app_links_init(system);
Partition _partition = partition_open(memory->vars_memory, memory->vars_memory_size);
App_Vars *vars = push_struct(&_partition, App_Vars);
Assert(vars);
*vars = {};
App_Vars *vars = (App_Vars*)memory->vars_memory;
vars->config_api = api;
vars->mem.part = _partition;
Partition *partition = &vars->mem.part;
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 divider_max_count = panel_max_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);
did_file = 1;
}
else if (mapid >= mapid_user_custom){
else if (mapid < mapid_global){
i32 index = app_get_or_add_map_index(vars, mapid);
Assert(index < user_map_count);
mapptr = vars->user_maps + index;
@ -2702,7 +2757,7 @@ App_Init_Sig(app_init){
int mapid = unit->map_inherit.mapid;
if (mapid == mapid_global) parent = &vars->map_top;
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);
if (index < user_map_count) parent = vars->user_maps + index;
else parent = 0;
@ -2819,27 +2874,6 @@ App_Init_Sig(app_init){
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
@ -2918,6 +2952,7 @@ App_Step_Sig(app_step){
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
for (i32 i = 0; i < vars->working_set.file_index_count; ++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);
command_data.part = partition_sub_part(&vars->mem.part, 16 << 10);
if (first_step && vars->hooks[hook_start]){
vars->hooks[hook_start](&command_data, &app_links);
command_data.part.pos = 0;
if (first_step){
if (vars->hooks[hook_start]){
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
@ -3366,7 +3411,7 @@ App_Step_Sig(app_step){
Assert(view_->do_view);
b32 active = (panel == active_panel);
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;
}
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;
};
struct App_Plat_Settings{
struct Plat_Settings{
char *custom_dll;
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) \
i32 name(System_Functions *system, \
Application_Memory *memory, \
String current_directory, \
Plat_Settings *plat_settings, \
Command_Line_Parameters clparams \
)

View File

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

View File

@ -99,6 +99,7 @@ struct Editing_File_Settings{
Font_Set *set;
i32 base_map_id;
i32 dos_write_mode;
b32 unwrapped_lines;
b8 tokens_exist;
b8 super_locked;
b8 is_initialized;
@ -1111,7 +1112,8 @@ struct File_View{
f32 scroll_y, target_y, vel_y;
f32 scroll_x, target_x, vel_x;
f32 preferred_x;
Full_Cursor scroll_y_cursor;
i32 scroll_i;
union{
Incremental_Search isearch;
struct{
@ -1220,21 +1222,26 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
i32 result = 0;
#if BUFFER_EXPERIMENT_SCALPEL <= 3
i32 max = buffer_size(&file->state.buffer) + file->state.buffer.line_count;
byte *data = (byte*)general_memory_allocate(&mem->general, max, 0);
i32 max, size;
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);
i32 size;
if (file->settings.dos_write_mode){
if (dos_write_mode)
size = buffer_convert_out(&file->state.buffer, (char*)data, max);
}
else{
size = buffer_size(&file->state.buffer);
buffer_stringify(&file->state.buffer, 0, size, (char*)data);
}
else
buffer_stringify(&file->state.buffer, 0, size = max, (char*)data);
i32 filename_len = str_size(filename);
result = exchange_save_file(exchange, filename, filename_len,
data, size, max);
data, size, max);
if (result == 0){
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_height = info->height;
view->font_set = set;
view->unwrapped_lines = file->settings.unwrapped_lines;
file->settings.set = set;
view->cursor = {};
@ -2647,6 +2655,83 @@ file_pre_edit_maintenance(System_Functions *system,
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
file_do_single_edit(System_Functions *system,
Mem_Options *mem, Editing_File *file,
@ -2722,40 +2807,14 @@ file_do_single_edit(System_Functions *system,
#endif
#if BUFFER_EXPERIMENT_SCALPEL <= 3
Temp_Memory cursor_temp = begin_temp_memory(&mem->part);
i32 cursor_max = layout->panel_max_count * 2;
Cursor_With_Index *cursors = push_array(&mem->part, Cursor_With_Index, cursor_max);
Cursor_Fix_Descriptor desc = {};
desc.start = start;
desc.end = end;
desc.shift_amount = shift_amount;
i32 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_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);
}
}
file_edit_cursor_fix(system, part, general,
file, layout, desc);
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
}
@ -2834,41 +2893,14 @@ view_do_white_batch_edit(System_Functions *system, Mem_Options *mem, File_View *
}
// NOTE(allen): cursor fixing
{
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);
Cursor_Fix_Descriptor desc = {};
desc.is_batch = 1;
desc.batch = batch;
desc.batch_size = batch_size;
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);
}
}
file_edit_cursor_fix(system, part, general,
file, layout, desc);
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
}
@ -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;
i32 count;
Full_Cursor render_cursor;
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)max_x, (f32)max_y, advance_data, (f32)line_height, opts);
f32 *wraps = view->line_wrap_y;
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);
@ -4212,9 +4261,11 @@ draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *t
Buffer_Render_Item *item = items;
i32 prev_ind = -1;
u32 highlight_color = 0;
u32 highlight_this_color = 0;
for (i32 i = 0; i < count; ++i, ++item){
i32 ind = item->index;
highlight_this_color = 0;
if (tokens_use && ind != prev_ind){
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 &&
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;
}
else{
highlight_color = 0;
}
}
u32 char_color = main_color;
u32 char_color = main_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 (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;
}
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){
draw_rectangle(target, f32R(item->x0, item->y0, item->x1, item->y1), highlight_color);
else if (highlight_this_color){
draw_rectangle(target, char_rect, highlight_this_color);
}
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);
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){
font_draw_glyph(target, font_id, (u8)item->glyphid,

View File

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

View File

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

View File

@ -1145,13 +1145,33 @@ struct Buffer_Render_Options{
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
buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *items, int max, int *count,
float port_x, float port_y, float scroll_x, float scroll_y, int wrapped,
float width, float height, float *advance_data, float font_height,
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, Full_Cursor start_cursor,
int wrapped,
float width, float height,
float *advance_data, float font_height,
Buffer_Render_Options opts){
Buffer_Stringify_Type loop;
Full_Cursor start_cursor;
Buffer_Render_Item *item;
char *data;
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_y = port_y - scroll_y;
if (wrapped){
start_cursor = buffer_cursor_from_wrapped_xy(buffer, 0, scroll_y, 0, wraps,
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;
}
if (wrapped) shift_y += start_cursor.wrapped_y;
else shift_y += start_cursor.unwrapped_y;
x = shift_x;
y = shift_y;

View File

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

View File

@ -9,50 +9,7 @@
// TOP
#ifdef FRED_NOT_PACKAGE
#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_config.h"
#include "4ed_meta.h"
@ -60,334 +17,480 @@
#include "4cpp_types.h"
#define FCPP_STRING_IMPLEMENTATION
#include "4cpp_string.h"
#include "4coder_string.h"
#include "4ed_mem.cpp"
#include "4ed_math.cpp"
#include "4coder_custom.h"
#include "4ed_system.h"
#include "4ed.h"
#include "4ed_rendering.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 "4ed.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_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{
Key_Codes codes;
Key_Input_Data input;
Mouse_State mouse;
Render_Target target;
Application_Memory mem;
b32 keep_going;
b32 force_redraw;
1. get 4coder rendering it's blank self
2. get input working
(release linux version)
3. add in extra stuff as it is completed in windows
Clipboard_Contents clipboard;
*/
void *app_code, *custom;
System_Functions *system;
App_Functions app;
Config_API config_api;
};
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;
static bool ctxErrorOccurred = false;
static int XInput2OpCode = 0;
internal int
ctxErrorHandler( Display *dpy, XErrorEvent *ev )
{
ctxErrorOccurred = true;
return 0;
}
#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
Sys_Free_Memory_Sig(system_free_memory){
if (block){
#if FRED_INTERNAL
Sys_Bubble *bubble = ((Sys_Bubble*)block) - 1;
Assert((bubble->flags & MEM_BUBBLE_DEBUG_MASK) == MEM_BUBBLE_SYS_DEBUG);
//WaitForSingleObject(win32vars.DEBUG_sysmem_lock, INFINITE);
remove_bubble(bubble);
//ReleaseSemaphore(win32vars.DEBUG_sysmem_lock, 1, 0);
munmap(bubble, bubble->size);
#else
i32 *size_ptr = (i32*)block - 1;
munmap(size_ptr, *size_ptr);
#endif
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
const char *glxExts = glXQueryExtensionsString(XDisplay, DefaultScreen(XDisplay));
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
GLXContext ctx = 0;
ctxErrorOccurred = false;
int (*oldHandler)(Display*, XErrorEvent*) =
XSetErrorHandler(&ctxErrorHandler);
if (!glXCreateContextAttribsARB)
{
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
Sys_Time_Sig(system_time){
i64 result = 0;
struct timespec tp;
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0){
result = tp.tv_sec*1000000 + tp.tv_nsec/1000;
}
return result;
}
printf("\nAttribs: %d %d %d %d %d\n",
context_attribs[0],
context_attribs[1],
context_attribs[2],
context_attribs[3],
context_attribs[4]);
internal
Sys_Load_File_Sig(system_load_file){
File_Data result = {};
i32 prot = PROT_READ;
i32 flags = MAP_PRIVATE | MAP_ANON;
printf( "Creating context\n" );
ctx = glXCreateContextAttribsARB( XDisplay, bestFbc, 0,
True, context_attribs );
struct stat sb;
if (stat(filename, &sb) == 0){
result.size = sb.st_size;
result.data = system_get_memory(result.size);
if (result.data){
i32 file = open(filename, O_RDONLY);
i32 result_size = read(file, result.data, result.size);
Assert(result_size == result.size);
close(file);
XSync( XDisplay, False );
if ( !ctxErrorOccurred && ctx )
{
printf( "Created GL 4.3 context\n" );
}
else
{
ctxErrorOccurred = false;
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
Sys_Save_File_Sig(system_save_file){
i32 file = open(filename, O_CREAT | O_WRONLY);
if (!file) return 0;
if ( ctxErrorOccurred || !ctx )
{
printf( "Failed to create an OpenGL context\n" );
exit(1);
}
i32 result_size = write(file, data, size);
Assert(result_size == size);
if ( ! glXIsDirect ( XDisplay, ctx ) )
{
printf( "Indirect GLX rendering context obtained\n" );
}
else
{
printf( "Direct GLX rendering context obtained\n" );
}
close(file);
return 1;
printf( "Making context current\n" );
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
LinuxLoadAppCode(){
b32 result = 0;
GLXSupportsModernContexts(Display *XDisplay)
{
b32 Result = false;
char app_code_file[] = "4ed_app.so";
i32 app_code_file_len = sizeof(app_code_file) - 1;
int GLXMajor, GLXMinor;
char path[1024];
i32 size = readlink("/proc/self/exe", path,
1024 - app_code_file_len - 1);
for (--size;
path[size] != '/' && size > 0;
--size);
memcpy(path + size + 1, app_code_file, app_code_file_len + 1);
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);
char *XVendor = ServerVendor(XDisplay);
printf("XWindows vendor: %s\n", XVendor);
if(glXQueryVersion(XDisplay, &GLXMajor, &GLXMinor))
{
printf("GLX version %d.%d\n", GLXMajor, GLXMinor);
if(((GLXMajor == 1 ) && (GLXMinor >= 3)) ||
(GLXMajor > 1))
{
Result = true;
}
}
return result;
return(Result);
}
internal
Sys_Acquire_Lock_Sig(system_acquire_lock){
AllowLocal(id);
}
typedef struct glx_config_result{
b32 Found;
GLXFBConfig BestConfig;
XVisualInfo BestInfo;
} glx_config_result;
internal
Sys_Release_Lock_Sig(system_release_lock){
AllowLocal(id);
}
internal glx_config_result
ChooseGLXConfig(Display *XDisplay, int XScreenIndex)
{
glx_config_result Result = {0};
internal
Sys_Force_Redraw_Sig(system_force_redraw){
linuxvars.force_redraw = 1;
}
internal void
LinuxLoadSystemCode(){
linuxvars.system->get_memory_full = system_get_memory_;
linuxvars.system->free_memory = system_free_memory;
linuxvars.system->load_file = system_load_file;
linuxvars.system->save_file = system_save_file;
#if 0
linuxvars.system->file_time_stamp = system_file_time_stamp;
linuxvars.system->time_stamp_now = system_time_stamp_now;
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();
int DesiredAttributes[] =
{
GLX_X_RENDERABLE , True,
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
GLX_RENDER_TYPE , GLX_RGBA_BIT,
GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
GLX_RED_SIZE , 8,
GLX_GREEN_SIZE , 8,
GLX_BLUE_SIZE , 8,
GLX_ALPHA_SIZE , 8,
GLX_DEPTH_SIZE , 24,
GLX_STENCIL_SIZE , 8,
GLX_DOUBLEBUFFER , True,
//GLX_SAMPLE_BUFFERS , 1,
//GLX_SAMPLES , 4,
None
};
{
void *base;
#if FRED_INTERNAL
base = (void*)Mbytes(128);
#else
base = (void*)0;
#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;
int ConfigCount;
GLXFBConfig *Configs = glXChooseFBConfig(XDisplay,
XScreenIndex,
DesiredAttributes,
&ConfigCount);
#if 0
Application_Step_Result app_result =
linuxvars.app.step(linuxvars.system,
&linuxvars.codes,
&linuxvars.input,
&linuxvars.mouse,
&linuxvars.target,
&linuxvars.mem,
linuxvars.clipboard,
1, first, linuxvars.force_redraw);
#else
Application_Step_Result app_result = {};
int DiffValues[GLXValueCount];
#endif
{for(int ConfigIndex = 0;
ConfigIndex < ConfigCount;
++ConfigIndex)
{
GLXFBConfig &Config = Configs[ConfigIndex];
XVisualInfo *VisualInfo = glXGetVisualFromFBConfig(XDisplay, Config);
#if 0
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
if (1 || linuxvars.force_redraw){
//glClearColor(1.f, 1.f, 0.f, 1.f);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
LinuxShowScreen();
linuxvars.force_redraw = 0;
}
#if 0
{for(int ValueIndex = 0;
ValueIndex < GLXValueCount;
++ValueIndex)
{
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;
i64 timer_end = system_time();
for (;timer_end < timer_target;){
i64 samount = timer_target - timer_end;
usleep(samount);
timer_end = system_time();
}
timer_start = system_time();
// TODO(casey): How the hell are you supposed to pick a config here??
if(ConfigIndex == 0)
{
Result.Found = true;
Result.BestConfig = Config;
Result.BestInfo = *VisualInfo;
}
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

BIN
vc120.pdb

Binary file not shown.

View File

@ -23,6 +23,7 @@
#include "4ed_math.cpp"
#include "4ed_dll_reader.h"
#include "4coder_custom.h"
#include "4ed_system.h"
#include "4ed_rendering.h"
@ -143,6 +144,7 @@ struct Win32_Vars{
DLL_Loaded custom_dll;
#endif
Plat_Settings settings;
System_Functions *system;
App_Functions app;
Custom_API custom_api;
@ -156,7 +158,6 @@ struct Win32_Vars{
Win32_Font_Load_Parameters used_font_param;
Win32_Font_Load_Parameters free_font_param;
Partition fnt_part;
};
globalvar Win32_Vars win32vars;
@ -1524,6 +1525,7 @@ WinMain(HINSTANCE hInstance,
memory_vars.target_memory = VirtualAlloc(base, memory_vars.target_memory_size,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
//
if (!memory_vars.vars_memory){
return 4;
@ -1546,9 +1548,12 @@ WinMain(HINSTANCE hInstance,
win32vars.app.read_command_line(system,
&memory_vars,
current_directory,
&win32vars.settings,
clparams);
if (output_size > 0){
//
if (output_size > 0){
// TODO
}
if (output_size != 0) return 0;
@ -1566,13 +1571,21 @@ WinMain(HINSTANCE hInstance,
keycode_init(&win32vars.key_codes);
#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){
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)
GetProcAddress(win32vars.custom, "get_bindings");
win32vars.custom_api.set_extra_font = (Set_Extra_Font_Function*)
GetProcAddress(win32vars.custom, "set_extra_font");
}
#endif
@ -1630,8 +1643,15 @@ WinMain(HINSTANCE hInstance,
}
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)){
// TODO(allen): non-fatal diagnostics
@ -1639,12 +1659,29 @@ WinMain(HINSTANCE hInstance,
#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 = {};
window_handle = CreateWindowA(
window_class.lpszClassName,
WINDOW_NAME,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
WINDOW_NAME, window_style,
window_x, window_y,
window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top,
0, 0, hInstance, 0);
@ -1660,15 +1697,6 @@ WinMain(HINSTANCE hInstance,
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 = {
sizeof(PIXELFORMATDESCRIPTOR),
1,