Removing shared scratch, passing in scratch on all system calls

master
Allen Webster 2019-08-16 08:01:17 -07:00
parent 98da59b05c
commit 6d7deff11e
17 changed files with 103 additions and 143 deletions

View File

@ -849,9 +849,11 @@ default_render_view(Application_Links *app, Frame_Info frame_info, View_ID view,
} }
} }
else{ else{
// TODO(allen): this doesn't actually work we aren't supposed to // TODO(allen): This doesn't actually work.
// assume that a function pointer is 64-bits I don't think. How // We aren't supposed to assume that a function
// should we attach a user named hook to a scope easily? // pointer is 64-bits I don't think. How
// should we attach a user named hook to a scope
// easily?
View_Render_Hook *hook = (View_Render_Hook*)render_hook_value; View_Render_Hook *hook = (View_Render_Hook*)render_hook_value;
hook(app, view, frame_info, inner); hook(app, view, frame_info, inner);
} }

View File

@ -399,9 +399,9 @@ CUSTOM_DOC("Tests the log parser")
case LogTagKind_String: case LogTagKind_String:
{ {
String_Const_u8 value = log_parse__get_string(&parse, node->value.value); String_Const_u8 string_value = log_parse__get_string(&parse, node->value.value);
string_list_pushf(scratch, &line, " [%.*s:%.*s]", string_list_pushf(scratch, &line, " [%.*s:%.*s]",
string_expand(tag_name), string_expand(value)); string_expand(tag_name), string_expand(string_value));
}break; }break;
} }
} }
@ -413,5 +413,6 @@ CUSTOM_DOC("Tests the log parser")
} }
} }
// BOTTOM // BOTTOM

View File

@ -1091,15 +1091,15 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl
{ {
Models *models = (Models*)app->cmd_context; Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system; System_Functions *system = models->system;
Arena *arena = &models->mem.arena;
Editing_File *file = imp_get_file(models, buffer_id); Editing_File *file = imp_get_file(models, buffer_id);
Buffer_Reopen_Result result = BufferReopenResult_Failed; Buffer_Reopen_Result result = BufferReopenResult_Failed;
if (api_check_buffer(file)){ if (api_check_buffer(file)){
if (file->canon.name_size > 0){ if (file->canon.name_size > 0){
Plat_Handle handle = {}; Plat_Handle handle = {};
if (system->load_handle((char*)file->canon.name_space, &handle)){ if (system->load_handle(arena, (char*)file->canon.name_space, &handle)){
File_Attributes attributes = system->load_attributes(handle); File_Attributes attributes = system->load_attributes(handle);
Arena *arena = &models->mem.arena;
Temp_Memory temp = begin_temp(arena); Temp_Memory temp = begin_temp(arena);
char *file_memory = push_array(arena, char, (i32)attributes.size); char *file_memory = push_array(arena, char, (i32)attributes.size);
@ -1176,8 +1176,8 @@ API_EXPORT File_Attributes
Get_File_Attributes(Application_Links *app, String_Const_u8 file_name) Get_File_Attributes(Application_Links *app, String_Const_u8 file_name)
{ {
Models *models = (Models*)app->cmd_context; Models *models = (Models*)app->cmd_context;
File_Attributes attributes = models->system->quick_file_attributes(file_name); Arena *arena = &models->mem.arena;
return(attributes); return(models->system->quick_file_attributes(arena, file_name));
} }
internal View* internal View*

View File

@ -98,7 +98,7 @@ child_process_call(Models *models, System_Functions *system, String_Const_u8 pat
String_Const_u8 path_n = push_string_copy(scratch, path); String_Const_u8 path_n = push_string_copy(scratch, path);
String_Const_u8 command_n = push_string_copy(scratch, command); String_Const_u8 command_n = push_string_copy(scratch, command);
CLI_Handles cli_handles = {}; CLI_Handles cli_handles = {};
if (system->cli_call((char*)path_n.str, (char*)command_n.str, &cli_handles)){ if (system->cli_call(scratch, (char*)path_n.str, (char*)command_n.str, &cli_handles)){
Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes); Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes);
*id_out = new_process.id; *id_out = new_process.id;
new_process.process->cli = cli_handles; new_process.process->cli = cli_handles;

View File

@ -549,7 +549,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags)
do_empty_buffer = true; do_empty_buffer = true;
} }
else{ else{
if (!system->load_handle((char*)canon.name_space, &handle)){ if (!system->load_handle(scratch, (char*)canon.name_space, &handle)){
do_empty_buffer = true; do_empty_buffer = true;
} }
} }

View File

@ -189,7 +189,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
} }
} }
File_Attributes new_attributes = system->save_file((char*)file_name, data, size); File_Attributes new_attributes = system->save_file(scratch, (char*)file_name, data, size);
if (new_attributes.last_write_time > 0){ if (new_attributes.last_write_time > 0){
if (using_actual_file_name){ if (using_actual_file_name){
file->state.ignore_behind_os = 1; file->state.ignore_behind_os = 1;

View File

@ -27,10 +27,10 @@ typedef Sys_Get_Canonical_Sig(System_Get_Canonical);
typedef Sys_Get_File_List_Sig(System_Get_File_List); typedef Sys_Get_File_List_Sig(System_Get_File_List);
// file load/save // file load/save
#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(String_Const_u8 file_name) #define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(Arena *scratch, String_Const_u8 file_name)
typedef Sys_Quick_File_Attributes_Sig(System_Quick_File_Attributes); typedef Sys_Quick_File_Attributes_Sig(System_Quick_File_Attributes);
#define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out) #define Sys_Load_Handle_Sig(name) b32 name(Arena *scratch, char *filename, Plat_Handle *handle_out)
typedef Sys_Load_Handle_Sig(System_Load_Handle); typedef Sys_Load_Handle_Sig(System_Load_Handle);
#define Sys_Load_Attributes_Sig(name) File_Attributes name(Plat_Handle handle) #define Sys_Load_Attributes_Sig(name) File_Attributes name(Plat_Handle handle)
@ -42,7 +42,7 @@ typedef Sys_Load_File_Sig(System_Load_File);
#define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle) #define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle)
typedef Sys_Load_Close_Sig(System_Load_Close); typedef Sys_Load_Close_Sig(System_Load_Close);
#define Sys_Save_File_Sig(name) File_Attributes name(char *filename, char *buffer, u32 size) #define Sys_Save_File_Sig(name) File_Attributes name(Arena *scratch, char *filename, char *buffer, u32 size)
typedef Sys_Save_File_Sig(System_Save_File); typedef Sys_Save_File_Sig(System_Save_File);
// time // time
@ -82,8 +82,8 @@ struct CLI_Handles{
i32 exit; i32 exit;
}; };
#define Sys_CLI_Call_Sig(n, path, script, cli_out) b32 n(char *path, char *script, CLI_Handles *cli_out) #define Sys_CLI_Call_Sig(n, scratch, path, script, cli_out) b32 n(Arena *scratch, char *path, char *script, CLI_Handles *cli_out)
typedef Sys_CLI_Call_Sig(System_CLI_Call, path, script, cli_out); typedef Sys_CLI_Call_Sig(System_CLI_Call, scratch, path, script, cli_out);
#define Sys_CLI_Begin_Update_Sig(name) void name(CLI_Handles *cli) #define Sys_CLI_Begin_Update_Sig(name) void name(CLI_Handles *cli)
typedef Sys_CLI_Begin_Update_Sig(System_CLI_Begin_Update); typedef Sys_CLI_Begin_Update_Sig(System_CLI_Begin_Update);

View File

@ -20,10 +20,10 @@ working_set_file_default_settings(Working_Set *working_set, Editing_File *file){
//////////////////////////////// ////////////////////////////////
internal void internal void
file_change_notification_check(System_Functions *system, Working_Set *working_set, Editing_File *file){ file_change_notification_check(System_Functions *system, Arena *scratch, Working_Set *working_set, Editing_File *file){
if (file->canon.name_size > 0 && !file->settings.unimportant){ if (file->canon.name_size > 0 && !file->settings.unimportant){
String_Const_u8 name = SCu8(file->canon.name_space, file->canon.name_size); String_Const_u8 name = SCu8(file->canon.name_space, file->canon.name_size);
File_Attributes attributes = system->quick_file_attributes(name); File_Attributes attributes = system->quick_file_attributes(scratch, name);
if (attributes.last_write_time > file->attributes.last_write_time){ if (attributes.last_write_time > file->attributes.last_write_time){
file_add_dirty_flag(file, DirtyState_UnloadedChanges); file_add_dirty_flag(file, DirtyState_UnloadedChanges);
if (file->external_mod_node.next == 0){ if (file->external_mod_node.next == 0){
@ -41,6 +41,7 @@ internal void
file_change_notification_thread_main(void *ptr){ file_change_notification_thread_main(void *ptr){
Models *models = (Models*)ptr; Models *models = (Models*)ptr;
System_Functions *system = models->system; System_Functions *system = models->system;
Arena arena = make_arena_system(system);
Working_Set *working_set = &models->working_set; Working_Set *working_set = &models->working_set;
for (;;){ for (;;){
system->sleep(Thousand(250)); system->sleep(Thousand(250));
@ -59,7 +60,7 @@ file_change_notification_thread_main(void *ptr){
if (node == used){ if (node == used){
node = node->next; node = node->next;
} }
file_change_notification_check(system, working_set, file); file_change_notification_check(system, &arena, working_set, file);
} }
working_set->sync_check_iterator = node; working_set->sync_check_iterator = node;
} }

View File

@ -10,7 +10,7 @@
// TOP // TOP
internal void internal void
memory_init(){ memory_init(Arena *scratch){
#if defined(FRED_INTERNAL) #if defined(FRED_INTERNAL)
# if ARCH_64BIT # if ARCH_64BIT
void *bases[] = { (void*)TB(1), (void*)TB(2), }; void *bases[] = { (void*)TB(1), (void*)TB(2), };
@ -40,22 +40,20 @@ memory_init(){
if (!alloc_success){ if (!alloc_success){
char msg[] = "Could not allocate sufficient memory. Please make sure you have atleast 512Mb of RAM free. (This requirement will be relaxed in the future)."; char msg[] = "Could not allocate sufficient memory. Please make sure you have atleast 512Mb of RAM free. (This requirement will be relaxed in the future).";
system_error_box(msg); system_error_box(scratch, msg);
} }
} }
internal void internal void
load_app_code(void){ load_app_code(Arena *scratch){
//LOG("Loading 4coder core...");
App_Get_Functions *get_funcs = 0; App_Get_Functions *get_funcs = 0;
if (system_load_library(&shared_vars.scratch, &libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){ if (system_load_library(scratch, &libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){
get_funcs = (App_Get_Functions*)system_get_proc(&libraries.app_code, "app_get_functions"); get_funcs = (App_Get_Functions*)system_get_proc(&libraries.app_code, "app_get_functions");
} }
else{ else{
char msg[] = "Could not load '4ed_app." DLL "'. This file should be in the same directory as the main '4ed' executable."; char msg[] = "Could not load '4ed_app." DLL "'. This file should be in the same directory as the main '4ed' executable.";
system_error_box(msg); system_error_box(scratch, msg);
} }
if (get_funcs != 0){ if (get_funcs != 0){
@ -63,7 +61,7 @@ load_app_code(void){
} }
else{ else{
char msg[] = "Failed to get application code from '4ed_app." DLL "'."; char msg[] = "Failed to get application code from '4ed_app." DLL "'.";
system_error_box(msg); system_error_box(scratch, msg);
} }
} }
@ -72,7 +70,7 @@ global char custom_fail_version_msg[] = "Failed to load custom code due to missi
global char custom_fail_missing_get_bindings_msg[] = "Failed to load custom code due to missing 'get_bindings' symbol. Try rebuilding with buildsuper."; global char custom_fail_missing_get_bindings_msg[] = "Failed to load custom code due to missing 'get_bindings' symbol. Try rebuilding with buildsuper.";
internal void internal void
load_custom_code(){ load_custom_code(Arena *scratch){
local_persist char *default_file = "custom_4coder"; local_persist char *default_file = "custom_4coder";
local_persist Load_Library_Location locations[] = { local_persist Load_Library_Location locations[] = {
LoadLibrary_CurrentDirectory, LoadLibrary_CurrentDirectory,
@ -95,7 +93,7 @@ load_custom_code(){
for (u32 i = 0; custom_files[i] != 0 && !has_library; ++i){ for (u32 i = 0; custom_files[i] != 0 && !has_library; ++i){
char *file = custom_files[i]; char *file = custom_files[i];
for (u32 j = 0; j < ArrayCount(locations) && !has_library; ++j){ for (u32 j = 0; j < ArrayCount(locations) && !has_library; ++j){
if (system_load_library(&shared_vars.scratch, &libraries.custom, file, locations[j], success_file, sizeof(success_file))){ if (system_load_library(scratch, &libraries.custom, file, locations[j], success_file, sizeof(success_file))){
has_library = true; has_library = true;
success_file[sizeof(success_file) - 1] = 0; success_file[sizeof(success_file) - 1] = 0;
} }
@ -103,21 +101,21 @@ load_custom_code(){
} }
if (!has_library){ if (!has_library){
system_error_box("Did not find a library for the custom layer."); system_error_box(scratch, "Did not find a library for the custom layer.");
} }
custom_api.get_alpha_4coder_version = (_Get_Version_Function*) custom_api.get_alpha_4coder_version = (_Get_Version_Function*)
system_get_proc(&libraries.custom, "get_alpha_4coder_version"); system_get_proc(&libraries.custom, "get_alpha_4coder_version");
if (custom_api.get_alpha_4coder_version == 0 || custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){ if (custom_api.get_alpha_4coder_version == 0 || custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
system_error_box(custom_fail_version_msg); system_error_box(scratch, custom_fail_version_msg);
} }
custom_api.get_bindings = (Get_Binding_Data_Function*) custom_api.get_bindings = (Get_Binding_Data_Function*)
system_get_proc(&libraries.custom, "get_bindings"); system_get_proc(&libraries.custom, "get_bindings");
if (custom_api.get_bindings == 0){ if (custom_api.get_bindings == 0){
system_error_box(custom_fail_missing_get_bindings_msg); system_error_box(scratch, custom_fail_missing_get_bindings_msg);
} }
//LOGF("Loaded custom file: %s\n", success_file); //LOGF("Loaded custom file: %s\n", success_file);
@ -132,7 +130,7 @@ read_command_line(Arena *scratch, i32 argc, char **argv){
char **files = 0; char **files = 0;
i32 *file_count = 0; i32 *file_count = 0;
app.read_command_line(&sysfunc, &memory_vars, curdir, &plat_settings, &files, &file_count, argc, argv); app.read_command_line(&sysfunc, &memory_vars, curdir, &plat_settings, &files, &file_count, argc, argv);
sysshared_filter_real_files(files, file_count); sysshared_filter_real_files(scratch, files, file_count);
end_temp(temp); end_temp(temp);
} }

View File

@ -16,7 +16,7 @@
union Library; union Library;
internal b32 internal b32
system_load_library_direct(Library *library, char *name); system_load_library_direct(Arena *scratch, Library *library, char *name);
internal void* internal void*
system_get_proc(Library *library, char *name); system_get_proc(Library *library, char *name);
@ -69,12 +69,12 @@ system_load_library(Arena *scratch, Library *library, char *name_cstr, Load_Libr
else{ else{
path = push_u8_stringf(scratch, "%.*s%.*s", string_expand(path), string_expand(name)); path = push_u8_stringf(scratch, "%.*s%.*s", string_expand(path), string_expand(name));
} }
success = system_load_library_direct(library, (char*)path.str); success = system_load_library_direct(scratch, library, (char*)path.str);
if (success && full_file_out != 0 && full_file_out > 0){ }
u32 fill_size = clamp_top((u32)(path.size), (u32)(full_file_max - 1)); if (success && full_file_out != 0 && full_file_out > 0){
block_copy(full_file_out, path.str, fill_size); u32 fill_size = clamp_top((u32)(path.size), (u32)(full_file_max - 1));
full_file_out[fill_size] = 0; block_copy(full_file_out, path.str, fill_size);
} full_file_out[fill_size] = 0;
} }
end_temp(temp); end_temp(temp);

View File

@ -18,7 +18,6 @@
internal void internal void
init_shared_vars(){ init_shared_vars(){
shared_vars.scratch = make_arena_system(&sysfunc);
shared_vars.font_scratch = make_arena_system(&sysfunc); shared_vars.font_scratch = make_arena_system(&sysfunc);
shared_vars.pixel_scratch = make_arena_system(&sysfunc); shared_vars.pixel_scratch = make_arena_system(&sysfunc);
} }
@ -28,11 +27,11 @@ init_shared_vars(){
// //
internal void internal void
sysshared_filter_real_files(char **files, i32 *file_count){ sysshared_filter_real_files(Arena *scratch, char **files, i32 *file_count){
i32 end = *file_count; i32 end = *file_count;
i32 i = 0, j = 0; i32 i = 0, j = 0;
for (; i < end; ++i){ for (; i < end; ++i){
if (system_file_can_be_made((u8*)files[i])){ if (system_file_can_be_made(scratch, (u8*)files[i])){
files[j] = files[i]; files[j] = files[i];
++j; ++j;
} }

View File

@ -24,11 +24,10 @@ struct File_Data{
}; };
global File_Data null_file_data = {}; global File_Data null_file_data = {};
#define Sys_File_Can_Be_Made_Sig(name) b32 name(u8 *filename) #define Sys_File_Can_Be_Made_Sig(name) b32 name(Arena *scratch, u8 *filename)
internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made);
struct Shared_Vars{ struct Shared_Vars{
Arena scratch;
Arena font_scratch; Arena font_scratch;
Arena pixel_scratch; Arena pixel_scratch;
}; };

View File

@ -392,12 +392,5 @@ Sys_File_Exists_Sig(system_file_exists){
return(result); return(result);
} }
internal b32
system_directory_exists(char *path){
struct stat st;
b32 result = (stat(path, &st) == 0 && S_ISDIR(st.st_mode));
return(result);
}
// BOTTOM // BOTTOM

View File

@ -63,7 +63,7 @@ enum{
}; };
internal void internal void
win32_output_error_string(i32 error_string_type); win32_output_error_string(Arena *scratch, i32 error_string_type);
////////////////////////////// //////////////////////////////
@ -153,6 +153,8 @@ struct Win32_Object{
}; };
struct Win32_Vars{ struct Win32_Vars{
Arena arena;
Win32_Input_Chunk input_chunk; Win32_Input_Chunk input_chunk;
b8 lctrl_lalt_is_altgr; b8 lctrl_lalt_is_altgr;
b8 got_useful_event; b8 got_useful_event;
@ -212,25 +214,28 @@ global Custom_API custom_api;
//////////////////////////////// ////////////////////////////////
#include "win32_error_box.cpp" internal void
system_error_box(Arena *scratch, char *msg, b32 shutdown = true){
//LOGF("error box: %s\n", msg);
MessageBox_utf8(scratch, 0, (u8*)msg, (u8*)"Error", 0);
if (shutdown){
exit(1);
}
}
//////////////////////////////// ////////////////////////////////
internal void internal void
win32_output_error_string(b32 use_error_box){ win32_output_error_string(Arena *scratch, b32 use_error_box){
DWORD error = GetLastError(); DWORD error = GetLastError();
char *str = 0; char *str = 0;
char *str_ptr = (char*)&str; char *str_ptr = (char*)&str;
if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, error, 0, str_ptr, 0, 0)){ if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, error, 0, str_ptr, 0, 0)){
//LOGF("win32 error:\n%s\n", str);
if (use_error_box){ if (use_error_box){
system_error_box(str, false); system_error_box(scratch, str, false);
} }
} }
else{
//LOGF("win32 error raw: %d\n", error);
}
} }
//////////////////////////////// ////////////////////////////////
@ -334,10 +339,10 @@ Sys_Is_Fullscreen_Sig(system_is_fullscreen){
// //
internal void internal void
win32_post_clipboard(char *text, i32 len){ win32_post_clipboard(Arena *scratch, char *text, i32 len){
if (OpenClipboard(win32vars.window_handle)){ if (OpenClipboard(win32vars.window_handle)){
if (!EmptyClipboard()){ if (!EmptyClipboard()){
win32_output_error_string(ErrorString_UseLog); win32_output_error_string(scratch, ErrorString_UseLog);
} }
HANDLE memory_handle = GlobalAlloc(GMEM_MOVEABLE, len + 1); HANDLE memory_handle = GlobalAlloc(GMEM_MOVEABLE, len + 1);
if (memory_handle){ if (memory_handle){
@ -373,8 +378,7 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){
} }
internal b32 internal b32
win32_read_clipboard_contents(void){ win32_read_clipboard_contents(Arena *scratch){
Arena *scratch = &shared_vars.scratch;
Temp_Memory temp = begin_temp(scratch); Temp_Memory temp = begin_temp(scratch);
b32 result = false; b32 result = false;
@ -456,14 +460,12 @@ win32_read_clipboard_contents(void){
// //
internal internal
Sys_CLI_Call_Sig(system_cli_call, path, script_name, cli_out){ Sys_CLI_Call_Sig(system_cli_call, scratch, path, script_name, cli_out){
Assert(sizeof(Plat_Handle) >= sizeof(HANDLE)); Assert(sizeof(Plat_Handle) >= sizeof(HANDLE));
char cmd[] = "c:\\windows\\system32\\cmd.exe"; char cmd[] = "c:\\windows\\system32\\cmd.exe";
char *env_variables = 0; char *env_variables = 0;
Arena *scratch = &shared_vars.scratch;
Temp_Memory temp = begin_temp(scratch); Temp_Memory temp = begin_temp(scratch);
String_Const_u8 s = push_u8_stringf(scratch, "/C %s", script_name); String_Const_u8 s = push_u8_stringf(scratch, "/C %s", script_name);
@ -495,7 +497,7 @@ Sys_CLI_Call_Sig(system_cli_call, path, script_name, cli_out){
startup.wShowWindow = SW_HIDE; startup.wShowWindow = SW_HIDE;
PROCESS_INFORMATION info = {}; PROCESS_INFORMATION info = {};
if (CreateProcess_utf8(&shared_vars.scratch, (u8*)cmd, s.str, 0, 0, TRUE, 0, env_variables, (u8*)path, &startup, &info)){ if (CreateProcess_utf8(scratch, (u8*)cmd, s.str, 0, 0, TRUE, 0, env_variables, (u8*)path, &startup, &info)){
success = true; success = true;
CloseHandle(info.hThread); CloseHandle(info.hThread);
*(HANDLE*)&cli_out->proc = info.hProcess; *(HANDLE*)&cli_out->proc = info.hProcess;
@ -1026,6 +1028,7 @@ Sys_Condition_Variable_Free_Sig(system_condition_variable_free){
internal LRESULT internal LRESULT
win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
LRESULT result = 0; LRESULT result = 0;
Arena *scratch = &win32vars.arena;
switch (uMsg){ switch (uMsg){
case WM_MENUCHAR:break; case WM_MENUCHAR:break;
@ -1249,7 +1252,7 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
case WM_CLIPBOARDUPDATE: case WM_CLIPBOARDUPDATE:
{ {
win32vars.got_useful_event = true; win32vars.got_useful_event = true;
LogEventLit(win32vars.log_string(M), &shared_vars.scratch, 0, 0, system_thread_get_id(), LogEventLit(win32vars.log_string(M), scratch, 0, 0, system_thread_get_id(),
"new clipboard contents"); "new clipboard contents");
}break; }break;
@ -1537,6 +1540,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// Memory init // Memory init
// //
win32vars.arena = make_arena_system(&sysfunc);
memset(&win32vars, 0, sizeof(win32vars)); memset(&win32vars, 0, sizeof(win32vars));
memset(&target, 0, sizeof(target)); memset(&target, 0, sizeof(target));
memset(&memory_vars, 0, sizeof(memory_vars)); memset(&memory_vars, 0, sizeof(memory_vars));
@ -1546,7 +1551,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
memset(&app, 0, sizeof(app)); memset(&app, 0, sizeof(app));
memset(&custom_api, 0, sizeof(custom_api)); memset(&custom_api, 0, sizeof(custom_api));
memory_init(); memory_init(&win32vars.arena);
win32vars.cursor_show = MouseCursorShow_Always; win32vars.cursor_show = MouseCursorShow_Always;
win32vars.prev_cursor_show = MouseCursorShow_Always; win32vars.prev_cursor_show = MouseCursorShow_Always;
@ -1564,16 +1569,16 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
init_shared_vars(); init_shared_vars();
load_app_code(); load_app_code(&win32vars.arena);
win32vars.log_string = app.get_logger(&sysfunc); win32vars.log_string = app.get_logger(&sysfunc);
read_command_line(&shared_vars.scratch, argc, argv); read_command_line(&win32vars.arena, argc, argv);
// //
// Load Custom Code // Load Custom Code
// //
#if defined(FRED_SUPER) #if defined(FRED_SUPER)
load_custom_code(); load_custom_code(&win32vars.arena);
#else #else
custom_api.get_bindings = get_bindings; custom_api.get_bindings = get_bindings;
#endif #endif
@ -1614,7 +1619,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// //
if (!AddClipboardFormatListener(win32vars.window_handle)){ if (!AddClipboardFormatListener(win32vars.window_handle)){
win32_output_error_string(ErrorString_UseLog); win32_output_error_string(&win32vars.arena, ErrorString_UseLog);
} }
win32vars.clip_max = KB(16); win32vars.clip_max = KB(16);
@ -1622,7 +1627,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
win32vars.clipboard_sequence = GetClipboardSequenceNumber(); win32vars.clipboard_sequence = GetClipboardSequenceNumber();
if (win32vars.clipboard_sequence == 0){ if (win32vars.clipboard_sequence == 0){
win32_post_clipboard("", 0); win32_post_clipboard(&win32vars.arena, "", 0);
win32vars.clipboard_sequence = GetClipboardSequenceNumber(); win32vars.clipboard_sequence = GetClipboardSequenceNumber();
win32vars.next_clipboard_is_self = 0; win32vars.next_clipboard_is_self = 0;
@ -1632,7 +1637,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
} }
} }
else{ else{
win32_read_clipboard_contents(); win32_read_clipboard_contents(&win32vars.arena);
} }
win32_keycode_init(); win32_keycode_init();
@ -1657,8 +1662,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// //
{ {
Temp_Memory temp = begin_temp(&shared_vars.scratch); Temp_Memory temp = begin_temp(&win32vars.arena);
String_Const_u8 curdir = sysfunc.get_current_path(&shared_vars.scratch); String_Const_u8 curdir = sysfunc.get_current_path(&win32vars.arena);
curdir = string_mod_replace_character(curdir, '\\', '/'); curdir = string_mod_replace_character(curdir, '\\', '/');
app.init(&sysfunc, &target, &memory_vars, win32vars.clipboard_contents, curdir, custom_api); app.init(&sysfunc, &target, &memory_vars, win32vars.clipboard_contents, curdir, custom_api);
end_temp(temp); end_temp(temp);
@ -1837,7 +1842,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
} }
// NOTE(allen): Frame Clipboard Input // NOTE(allen): Frame Clipboard Input
memset(&win32vars.clipboard_contents, 0, sizeof(win32vars.clipboard_contents)); block_zero_struct(&win32vars.clipboard_contents);
input.clipboard_changed = false; input.clipboard_changed = false;
if (win32vars.clipboard_sequence != 0){ if (win32vars.clipboard_sequence != 0){
DWORD new_number = GetClipboardSequenceNumber(); DWORD new_number = GetClipboardSequenceNumber();
@ -1847,7 +1852,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
} }
else{ else{
for (i32 R = 0; R < 4; ++R){ for (i32 R = 0; R < 4; ++R){
if (win32_read_clipboard_contents()){ if (win32_read_clipboard_contents(&win32vars.arena)){
input.clipboard_changed = true; input.clipboard_changed = true;
break; break;
} }
@ -1877,12 +1882,12 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// NOTE(allen): Post New Clipboard Content // NOTE(allen): Post New Clipboard Content
if (win32vars.clip_post.size > 0){ if (win32vars.clip_post.size > 0){
win32_post_clipboard((char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size); win32_post_clipboard(&win32vars.arena, (char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size);
} }
// NOTE(allen): Switch to New Title // NOTE(allen): Switch to New Title
if (result.has_new_title){ if (result.has_new_title){
SetWindowText_utf8(&shared_vars.scratch, win32vars.window_handle, (u8*)result.title_string); SetWindowText_utf8(&win32vars.arena, win32vars.window_handle, (u8*)result.title_string);
} }
// NOTE(allen): Switch to New Cursor // NOTE(allen): Switch to New Cursor

View File

@ -15,7 +15,7 @@
internal internal
Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ Sys_File_Can_Be_Made_Sig(system_file_can_be_made){
HANDLE file = CreateFile_utf8(&shared_vars.scratch, filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); HANDLE file = CreateFile_utf8(scratch, filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
b32 result = false; b32 result = false;
if (file != INVALID_HANDLE_VALUE){ if (file != INVALID_HANDLE_VALUE){
CloseHandle(file); CloseHandle(file);
@ -71,9 +71,9 @@ Sys_Memory_Free_Sig(system_memory_free){
internal internal
Sys_Get_Current_Path_Sig(system_get_current_path){ Sys_Get_Current_Path_Sig(system_get_current_path){
DWORD size = GetCurrentDirectory_utf8(&shared_vars.scratch, 0, 0); DWORD size = GetCurrentDirectory_utf8(arena, 0, 0);
u8 *out = push_array(arena, u8, size); u8 *out = push_array(arena, u8, size);
GetCurrentDirectory_utf8(&shared_vars.scratch, size, out); GetCurrentDirectory_utf8(arena, size, out);
return(SCu8(out, size - 1)); return(SCu8(out, size - 1));
} }
@ -84,7 +84,7 @@ Sys_Get_4ed_Path_Sig(system_get_4ed_path){
has_stashed_4ed_path = true; has_stashed_4ed_path = true;
local_const i32 binary_path_capacity = KB(32); local_const i32 binary_path_capacity = KB(32);
u8 *memory = (u8*)system_memory_allocate(binary_path_capacity); u8 *memory = (u8*)system_memory_allocate(binary_path_capacity);
i32 size = GetModuleFileName_utf8(&shared_vars.scratch, 0, memory, binary_path_capacity); i32 size = GetModuleFileName_utf8(arena, 0, memory, binary_path_capacity);
Assert(size <= binary_path_capacity - 1); Assert(size <= binary_path_capacity - 1);
win32vars.binary_path = SCu8(memory, size); win32vars.binary_path = SCu8(memory, size);
win32vars.binary_path = string_remove_last_folder(win32vars.binary_path); win32vars.binary_path = string_remove_last_folder(win32vars.binary_path);
@ -121,22 +121,20 @@ win32_remove_unc_prefix_characters(String_Const_u8 path){
internal internal
Sys_Get_Canonical_Sig(system_get_canonical){ Sys_Get_Canonical_Sig(system_get_canonical){
String_Const_u8 result = {}; String_Const_u8 result = {};
Arena *scratch = &shared_vars.scratch;
Temp_Memory temp = begin_temp(scratch);
if ((character_is_alpha(string_get_character(name, 0)) && if ((character_is_alpha(string_get_character(name, 0)) &&
string_get_character(name, 1) == ':') || string_get_character(name, 1) == ':') ||
string_match(string_prefix(name, 2), string_u8_litexpr("\\\\"))){ string_match(string_prefix(name, 2), string_u8_litexpr("\\\\"))){
u8 *c_name = push_array(scratch, u8, name.size + 1); u8 *c_name = push_array(arena, u8, name.size + 1);
block_copy(c_name, name.str, name.size); block_copy(c_name, name.str, name.size);
c_name[name.size] = 0; c_name[name.size] = 0;
HANDLE file = CreateFile_utf8(scratch, c_name, GENERIC_READ, 0, 0, OPEN_EXISTING, HANDLE file = CreateFile_utf8(arena, c_name, GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0); FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){ if (file != INVALID_HANDLE_VALUE){
DWORD capacity = GetFinalPathNameByHandle_utf8(scratch, file, 0, 0, 0); DWORD capacity = GetFinalPathNameByHandle_utf8(arena, file, 0, 0, 0);
u8 *buffer = push_array(arena, u8, capacity); u8 *buffer = push_array(arena, u8, capacity);
DWORD length = GetFinalPathNameByHandle_utf8(scratch, file, buffer, capacity, 0); DWORD length = GetFinalPathNameByHandle_utf8(arena, file, buffer, capacity, 0);
if (length > 0 && buffer[length - 1] == 0){ if (length > 0 && buffer[length - 1] == 0){
length -= 1; length -= 1;
} }
@ -148,19 +146,19 @@ Sys_Get_Canonical_Sig(system_get_canonical){
String_Const_u8 path = string_remove_front_of_path(name); String_Const_u8 path = string_remove_front_of_path(name);
String_Const_u8 front = string_front_of_path(name); String_Const_u8 front = string_front_of_path(name);
u8 *c_path = push_array(scratch, u8, path.size + 1); u8 *c_path = push_array(arena, u8, path.size + 1);
block_copy(c_path, path.str, path.size); block_copy(c_path, path.str, path.size);
c_path[path.size] = 0; c_path[path.size] = 0;
HANDLE dir = CreateFile_utf8(scratch, c_path, FILE_LIST_DIRECTORY, HANDLE dir = CreateFile_utf8(arena, c_path, FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0,
OPEN_EXISTING, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0);
if (dir != INVALID_HANDLE_VALUE){ if (dir != INVALID_HANDLE_VALUE){
DWORD capacity = GetFinalPathNameByHandle_utf8(scratch, dir, 0, 0, 0); DWORD capacity = GetFinalPathNameByHandle_utf8(arena, dir, 0, 0, 0);
u8 *buffer = push_array(arena, u8, capacity + front.size + 1); u8 *buffer = push_array(arena, u8, capacity + front.size + 1);
DWORD length = GetFinalPathNameByHandle_utf8(scratch, dir, buffer, capacity, 0); DWORD length = GetFinalPathNameByHandle_utf8(arena, dir, buffer, capacity, 0);
if (length > 0 && buffer[length - 1] == 0){ if (length > 0 && buffer[length - 1] == 0){
length -= 1; length -= 1;
} }
@ -174,7 +172,6 @@ Sys_Get_Canonical_Sig(system_get_canonical){
} }
} }
} }
end_temp(temp);
return(result); return(result);
} }
@ -209,18 +206,16 @@ win32_file_attributes_from_HANDLE(HANDLE file){
internal internal
Sys_Get_File_List_Sig(system_get_file_list){ Sys_Get_File_List_Sig(system_get_file_list){
File_List result = {}; File_List result = {};
Arena *scratch = &shared_vars.scratch;
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 search_pattern = {}; String_Const_u8 search_pattern = {};
if (character_is_slash(string_get_character(directory, directory.size - 1))){ if (character_is_slash(string_get_character(directory, directory.size - 1))){
search_pattern = push_u8_stringf(scratch, "%.*s*", string_expand(directory)); search_pattern = push_u8_stringf(arena, "%.*s*", string_expand(directory));
} }
else{ else{
search_pattern = push_u8_stringf(scratch, "%.*s\\*", string_expand(directory)); search_pattern = push_u8_stringf(arena, "%.*s\\*", string_expand(directory));
} }
WIN32_FIND_DATA find_data = {}; WIN32_FIND_DATA find_data = {};
HANDLE search = FindFirstFile_utf8(&shared_vars.scratch, search_pattern.str, &find_data); HANDLE search = FindFirstFile_utf8(arena, search_pattern.str, &find_data);
if (search != INVALID_HANDLE_VALUE){ if (search != INVALID_HANDLE_VALUE){
File_Info *first = 0; File_Info *first = 0;
File_Info *last = 0; File_Info *last = 0;
@ -260,7 +255,6 @@ Sys_Get_File_List_Sig(system_get_file_list){
} }
} }
end_temp(temp);
return(result); return(result);
} }
@ -268,7 +262,7 @@ internal
Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){ Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){
WIN32_FILE_ATTRIBUTE_DATA info = {}; WIN32_FILE_ATTRIBUTE_DATA info = {};
File_Attributes result = {}; File_Attributes result = {};
if (GetFileAttributesEx_utf8String(&shared_vars.scratch, file_name, GetFileExInfoStandard, &info)){ if (GetFileAttributesEx_utf8String(scratch, file_name, GetFileExInfoStandard, &info)){
result.size = ((u64)info.nFileSizeHigh << 32LL) | ((u64)info.nFileSizeLow); result.size = ((u64)info.nFileSizeHigh << 32LL) | ((u64)info.nFileSizeLow);
result.last_write_time = ((u64)info.ftLastWriteTime.dwHighDateTime << 32LL) | ((u64)info.ftLastWriteTime.dwLowDateTime); result.last_write_time = ((u64)info.ftLastWriteTime.dwHighDateTime << 32LL) | ((u64)info.ftLastWriteTime.dwLowDateTime);
result.flags = win32_convert_file_attribute_flags(info.dwFileAttributes); result.flags = win32_convert_file_attribute_flags(info.dwFileAttributes);
@ -279,7 +273,7 @@ Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){
internal internal
Sys_Load_Handle_Sig(system_load_handle){ Sys_Load_Handle_Sig(system_load_handle){
b32 result = false; b32 result = false;
HANDLE file = CreateFile_utf8(&shared_vars.scratch, (u8*)filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); HANDLE file = CreateFile_utf8(scratch, (u8*)filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){ if (file != INVALID_HANDLE_VALUE){
*(HANDLE*)handle_out = file; *(HANDLE*)handle_out = file;
result = true; result = true;
@ -319,7 +313,8 @@ Sys_Load_Close_Sig(system_load_close){
internal internal
Sys_Save_File_Sig(system_save_file){ Sys_Save_File_Sig(system_save_file){
File_Attributes result = {}; File_Attributes result = {};
HANDLE file = CreateFile_utf8(&shared_vars.scratch, (u8*)filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
HANDLE file = CreateFile_utf8(scratch, (u8*)filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){ if (file != INVALID_HANDLE_VALUE){
DWORD written_total = 0; DWORD written_total = 0;
@ -344,16 +339,6 @@ Sys_Save_File_Sig(system_save_file){
return(result); return(result);
} }
//
// File System
//
internal b32
system_directory_exists(char *path){
DWORD attrib = GetFileAttributes_utf8(&shared_vars.scratch, (u8*)path);
return(attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY));
}
// //
// Color picker // Color picker
// //

View File

@ -1,22 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 18.07.2017
*
* Windows fatal error message box.
*
*/
// TOP
internal void
system_error_box(char *msg, b32 shutdown = true){
//LOGF("error box: %s\n", msg);
MessageBox_utf8(&shared_vars.scratch, 0, (u8*)msg, (u8*)"Error", 0);
if (shutdown){
exit(1);
}
}
// BOTTOM

View File

@ -15,20 +15,19 @@ union Library{
}; };
internal b32 internal b32
system_load_library_direct(Library *library, char *name){ system_load_library_direct(Arena *scratch, Library *library, char *name){
AssertLibrarySizes(); AssertLibrarySizes();
library->lib = LoadLibraryA(name); library->lib = LoadLibraryA(name);
b32 success = (library->lib != 0); b32 success = (library->lib != 0);
if (!success){ if (!success){
win32_output_error_string(ErrorString_UseLog); win32_output_error_string(scratch, ErrorString_UseLog);
} }
return(success); return(success);
} }
internal void* internal void*
system_get_proc(Library *library, char *name){ system_get_proc(Library *library, char *name){
void *result = GetProcAddress(library->lib, name); return(GetProcAddress(library->lib, name));
return(result);
} }
internal void internal void