diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 0ca989ed..fb50d018 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -141,22 +141,24 @@ CUSTOM_COMMAND_SIG(open_my_files){ // any circumstance. push_parameter(app, par_name, literal("w:/4ed/data/test/basic.cpp")); exec_command(app, cmdid_interactive_open); - + +#if 0 exec_command(app, cmdid_change_active_panel); - + char my_file[256]; int my_file_len; - + my_file_len = sizeof("w:/4ed/data/test/basic.txt") - 1; for (int i = 0; i < my_file_len; ++i){ my_file[i] = ("w:/4ed/data/test/basic.txt")[i]; } - + // NOTE(allen|a3.1): null terminators are not needed for strings. push_parameter(app, par_name, my_file, my_file_len); exec_command(app, cmdid_interactive_open); - + exec_command(app, cmdid_change_active_panel); +#endif } CUSTOM_COMMAND_SIG(build_at_launch_location){ @@ -434,93 +436,7 @@ get_bindings(void *data, int size){ return(result); } -struct Custom_Vars{ - int initialized; - Partition part; -}; - -enum View_Mode{ - ViewMode_File, -}; - -struct View_Vars{ - int id; - View_Mode mode; - - GUI_Scroll_Vars scroll; - i32_Rect scroll_region; - - int buffer_id; -}; -inline View_Vars -view_vars_zero(){ - View_Vars vars = {0}; - return(vars); -} - -extern "C" void -view_routine(Application_Links *app, int view_id){ - Custom_Vars *vars = (Custom_Vars*)app->memory; - View_Vars view = {0}; - view.id = view_id; - - int show_scrollbar = 1; - - if (!vars->initialized){ - vars->initialized = 1; - vars->part = make_part(app->memory, app->memory_size); - push_struct(&vars->part, Custom_Vars); - } - - for(;;){ - Event_Message message = {0}; - message = app->get_event_message(app); - - switch (message.type){ - case EM_Open_View: - { - view = view_vars_zero(); - view.id = view_id; - }break; - - case EM_Frame: - { - GUI_Functions *guifn = app->get_gui_functions(app); - GUI *gui = app->get_gui(app, view_id); - - guifn->begin(gui); - guifn->top_bar(gui); - - switch (view.mode){ - case ViewMode_File: - // TODO(allen): Overlapped widget - GUI_id scroll_id; - scroll_id.id[1] = view.mode; - scroll_id.id[0] = view.buffer_id; - - guifn->get_scroll_vars(gui, scroll_id, &view.scroll, - &view.scroll_region); - guifn->begin_scrollable(gui, scroll_id, view.scroll, - 144.f, show_scrollbar); - guifn->file(gui, view.buffer_id); - guifn->end_scrollable(gui); - break; - } - - guifn->end(gui); - - // TODO(allen): Put this code in charge of dispatching - // to the command or command coroutine or whatever. - - // TODO(allen): Put this code in charge of when to process - // the GUI with input and retrieve new layout data. - }break; - - case EM_Close_View: - {}break; - } - } -} +#include "4coder_default_view.cpp" #endif diff --git a/4coder_default_view.cpp b/4coder_default_view.cpp new file mode 100644 index 00000000..122a2da3 --- /dev/null +++ b/4coder_default_view.cpp @@ -0,0 +1,89 @@ + +struct Custom_Vars{ + int initialized; + Partition part; +}; + +enum View_Mode{ + ViewMode_File, +}; + +struct View_Vars{ + int id; + View_Mode mode; + + GUI_Scroll_Vars scroll; + i32_Rect scroll_region; + + int buffer_id; +}; +inline View_Vars +view_vars_zero(){ + View_Vars vars = {0}; + return(vars); +} + +extern "C" void +view_routine(Application_Links *app, int view_id){ + Custom_Vars *vars = (Custom_Vars*)app->memory; + View_Vars view = {0}; + view.id = view_id; + + int show_scrollbar = 1; + + if (!vars->initialized){ + vars->initialized = 1; + vars->part = make_part(app->memory, app->memory_size); + push_struct(&vars->part, Custom_Vars); + } + + for(;;){ + Event_Message message = {0}; + message = app->get_event_message(app); + + switch (message.type){ + case EM_Open_View: + { + view = view_vars_zero(); + view.id = view_id; + }break; + + case EM_Frame: + { + GUI_Functions *guifn = app->get_gui_functions(app); + GUI *gui = app->get_gui(app, view_id); + + guifn->begin(gui); + guifn->top_bar(gui); + + switch (view.mode){ + case ViewMode_File: + // TODO(allen): Overlapped widget + GUI_id scroll_id; + scroll_id.id[1] = view.mode; + scroll_id.id[0] = view.buffer_id; + + guifn->get_scroll_vars(gui, scroll_id, &view.scroll, + &view.scroll_region); + guifn->begin_scrollable(gui, scroll_id, view.scroll, + 144.f, show_scrollbar); + guifn->file(gui, view.buffer_id); + guifn->end_scrollable(gui); + break; + } + + guifn->end(gui); + + // TODO(allen): Put this code in charge of dispatching + // to the command or command coroutine or whatever. + + // TODO(allen): Put this code in charge of when to process + // the GUI with input and retrieve new layout data. + }break; + + case EM_Close_View: + {}break; + } + } +} + diff --git a/4ed_mem.cpp b/4ed_mem.cpp index 535dbee8..72260d88 100644 --- a/4ed_mem.cpp +++ b/4ed_mem.cpp @@ -143,7 +143,9 @@ general_memory_attempt_merge(Bubble *left, Bubble *right){ internal void general_memory_free(General_Memory *general, void *memory){ Bubble *bubble = ((Bubble*)memory) - 1; - Assert((!FRED_INTERNAL) || (bubble->flags & MEM_BUBBLE_DEBUG_MASK) == MEM_BUBBLE_DEBUG); +#if FRED_INTERNAL + Assert((bubble->flags & MEM_BUBBLE_DEBUG_MASK) == MEM_BUBBLE_DEBUG); +#endif bubble->flags &= ~MEM_BUBBLE_USED; bubble->type = 0; Bubble *prev, *next; @@ -158,7 +160,9 @@ general_memory_reallocate(General_Memory *general, void *old, i32 old_size, i32 void *result = old; Bubble *bubble = ((Bubble*)old) - 1; bubble->type = type; - Assert((!FRED_INTERNAL) || (bubble->flags & MEM_BUBBLE_DEBUG_MASK) == MEM_BUBBLE_DEBUG); +#if FRED_INTERNAL + Assert((bubble->flags & MEM_BUBBLE_DEBUG_MASK) == MEM_BUBBLE_DEBUG); +#endif i32 additional_space = size - bubble->size; if (additional_space > 0){ Bubble *next = bubble->next; diff --git a/4ed_system.h b/4ed_system.h index 65e2dee7..a6ba628c 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -226,15 +226,15 @@ struct System_Functions{ System_File_Load_Begin *file_load_begin; System_File_Load_End *file_load_end; System_File_Save *file_save; - + // file system navigation (4coder_custom.h): 3 File_Exists_Function *file_exists; Directory_CD_Function *directory_cd; Get_4ed_Path_Function *get_4ed_path; - + // clipboard: 1 System_Post_Clipboard *post_clipboard; - + // time: 1 System_Time *time; @@ -249,14 +249,14 @@ struct System_Functions{ System_CLI_Begin_Update *cli_begin_update; System_CLI_Update_Step *cli_update_step; System_CLI_End_Update *cli_end_update; - + // threads: 5 System_Post_Job *post_job; System_Cancel_Job *cancel_job; System_Grow_Thread_Memory *grow_thread_memory; System_Acquire_Lock *acquire_lock; System_Release_Lock *release_lock; - + // debug: 3 INTERNAL_System_Sentinel *internal_sentinel; INTERNAL_System_Get_Thread_States *internal_get_thread_states; diff --git a/README.txt b/README.txt index 9d9b308d..5ca9b38e 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -Distribution Date: 24.5.2016 (dd.mm.yyyy) +Distribution Date: 28.5.2016 (dd.mm.yyyy) Thank you for contributing to the 4coder project! diff --git a/SUPERREADME.txt b/SUPERREADME.txt index e25362cb..820ddefc 100644 --- a/SUPERREADME.txt +++ b/SUPERREADME.txt @@ -1,4 +1,4 @@ -Distribution Date: 24.5.2016 (dd.mm.yyyy) +Distribution Date: 28.5.2016 (dd.mm.yyyy) Thank you for contributing to the 4coder project! diff --git a/build_all.bat b/build_all.bat index bf8abcb0..a5873ee7 100644 --- a/build_all.bat +++ b/build_all.bat @@ -21,8 +21,8 @@ if %ERRORLEVEL% neq 0 (set FirstError=1) popd pushd ..\build -call "..\code\buildsuper.bat" ..\code\4coder_default_bindings.cpp -REM call "..\code\buildsuper.bat" ..\code\power\4coder_experiments.cpp +REM call "..\code\buildsuper.bat" ..\code\4coder_default_bindings.cpp +call "..\code\buildsuper.bat" ..\code\power\4coder_experiments.cpp REM call "..\code\buildsuper.bat" ..\code\power\4coder_casey.cpp if %ERRORLEVEL% neq 0 (set FirstError=1) diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index 81bb017e..0bbe9361 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -4,6 +4,8 @@ #define NO_BINDING #include "../4coder_default_bindings.cpp" +#include + CUSTOM_COMMAND_SIG(kill_rect){ View_Summary view = app->get_active_view(app); Buffer_Summary buffer = app->get_buffer(app, view.buffer_id); @@ -377,10 +379,7 @@ get_bindings(void *data, int size){ return(result); } -extern "C" void -view_routine(Application_Links *app, int view_id){ - app->get_user_input(app, 0, 0); -} +#include "..\4coder_default_view.cpp" // BOTTOM diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 0710504c..3418f73e 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -200,7 +200,7 @@ Win32Ptr(void *h){ } // -// System Layer Memory +// Memory (not exposed to application, but needed in system_shared.cpp) // #if FRED_INTERNAL @@ -273,7 +273,7 @@ INTERNAL_system_debug_message(char *message){ #endif // -// Platform Layer File Services +// File // internal @@ -388,8 +388,7 @@ Sys_File_Save_Sig(system_file_save){ internal Sys_File_Time_Stamp_Sig(system_file_time_stamp){ - u64 result; - result = 0; + u64 result = 0; FILETIME last_write; WIN32_FILE_ATTRIBUTE_DATA data; @@ -539,6 +538,7 @@ Sys_File_Unique_Hash_Sig(system_file_unique_hash){ return(hash); } +// NOTE(allen): Exposed to the custom layer. internal FILE_EXISTS_SIG(system_file_exists){ char full_filename_space[1024]; @@ -571,6 +571,7 @@ b32 Win32DirectoryExists(char *path){ (attrib & FILE_ATTRIBUTE_DIRECTORY)); } +// NOTE(allen): Exposed to the custom layer. internal DIRECTORY_CD_SIG(system_directory_cd){ String directory = make_string(dir, *len, capacity); @@ -618,11 +619,16 @@ Sys_Get_Binary_Path_Sig(system_get_binary_path){ return(result); } +// NOTE(allen): Exposed to the custom layer. GET_4ED_PATH_SIG(system_get_4ed_path){ String str = make_string(out, 0, capacity); return(system_get_binary_path(&str)); } +// +// Clipboard +// + internal Sys_Post_Clipboard_Sig(system_post_clipboard){ if (OpenClipboard(win32vars.window_handle)){ @@ -640,6 +646,10 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ } } +// +// Multithreading +// + internal Sys_Acquire_Lock_Sig(system_acquire_lock){ WaitForSingleObject(win32vars.locks[id], INFINITE); @@ -650,38 +660,7 @@ Sys_Release_Lock_Sig(system_release_lock){ ReleaseSemaphore(win32vars.locks[id], 1, 0); } -internal void -Win32SetCursorFromUpdate(Application_Mouse_Cursor cursor){ - switch (cursor){ - case APP_MOUSE_CURSOR_ARROW: - SetCursor(win32vars.cursor_arrow); break; - - case APP_MOUSE_CURSOR_IBEAM: - SetCursor(win32vars.cursor_ibeam); break; - - case APP_MOUSE_CURSOR_LEFTRIGHT: - SetCursor(win32vars.cursor_leftright); break; - - case APP_MOUSE_CURSOR_UPDOWN: - SetCursor(win32vars.cursor_updown); break; - } -} - -internal void -Win32Resize(i32 width, i32 height){ - if (width > 0 && height > 0){ - glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, width, height, 0, -1, 1); - glScissor(0, 0, width, height); - - win32vars.target.width = width; - win32vars.target.height = height; - } -} - -internal DWORD WINAPI +internal DWORD JobThreadProc(LPVOID lpParameter){ Thread_Context *thread = (Thread_Context*)lpParameter; Work_Queue *queue = thread->queue; @@ -766,6 +745,8 @@ Sys_Post_Job_Sig(system_post_job){ return result; } +// TODO(allen): I would like to get rid of job canceling +// but I still don't know what exactly I would do without it. internal Sys_Cancel_Job_Sig(system_cancel_job){ Work_Queue *queue = exchange_vars.thread.queues + group_id; @@ -829,6 +810,10 @@ INTERNAL_get_thread_states(Thread_Group_ID id, bool8 *running, i32 *pending){ } #endif +// +// Coroutine +// + internal Win32_Coroutine* Win32AllocCoroutine(){ Win32_Coroutine *result = win32vars.coroutine_free; @@ -919,6 +904,10 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){ SwitchToFiber(coroutine->yield_handle); } +// +// Command Line Exectuion +// + internal Sys_CLI_Call_Sig(system_cli_call){ char cmd[] = "c:\\windows\\system32\\cmd.exe"; @@ -1060,6 +1049,40 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){ return close_me; } + +#include "system_shared.cpp" +#include "4ed_rendering.cpp" + +internal +Font_Load_Sig(system_draw_font_load){ + if (win32vars.font_part.base == 0){ + win32vars.font_part = Win32ScratchPartition(Mbytes(8)); + } + + i32 oversample = 2; + + for (b32 success = 0; success == 0;){ + success = draw_font_load(&win32vars.font_part, + font_out, + filename, + pt_size, + tab_width, + oversample); + + // TODO(allen): Make the growable partition something that can + // just be passed directly to font load and let it be grown there. + if (!success){ + Win32ScratchPartitionDouble(&win32vars.font_part); + } + } + + return(1); +} + +// +// Linkage to Custom and Application +// + internal b32 Win32LoadAppCode(){ b32 result = 0; @@ -1151,7 +1174,7 @@ Win32LoadSystemCode(){ win32vars.system->acquire_lock = system_acquire_lock; win32vars.system->release_lock = system_release_lock; -#ifdef FRED_INTERNAL +#if FRED_INTERNAL win32vars.system->internal_sentinel = INTERNAL_system_sentinel; win32vars.system->internal_get_thread_states = INTERNAL_get_thread_states; win32vars.system->internal_debug_message = INTERNAL_system_debug_message; @@ -1160,35 +1183,6 @@ Win32LoadSystemCode(){ win32vars.system->slash = '/'; } -#include "system_shared.cpp" -#include "4ed_rendering.cpp" - -internal -Font_Load_Sig(system_draw_font_load){ - if (win32vars.font_part.base == 0){ - win32vars.font_part = Win32ScratchPartition(Mbytes(8)); - } - - i32 oversample = 2; - - for (b32 success = 0; success == 0;){ - success = draw_font_load(&win32vars.font_part, - font_out, - filename, - pt_size, - tab_width, - oversample); - - // TODO(allen): Make the growable partition something that can - // just be passed directly to font load and let it be grown there. - if (!success){ - Win32ScratchPartitionDouble(&win32vars.font_part); - } - } - - return(1); -} - internal void Win32LoadRenderCode(){ win32vars.target.push_clip = draw_push_clip; @@ -1200,26 +1194,14 @@ Win32LoadRenderCode(){ win32vars.target.font_set.release_font = draw_release_font; } -internal void -Win32RedrawScreen(HDC hdc){ - launch_rendering(&win32vars.target); - glFlush(); - SwapBuffers(hdc); -} - -internal void -Win32RedrawFromUpdate(){ - PAINTSTRUCT ps; - HWND hwnd = win32vars.window_handle; - HDC hdc = BeginPaint(hwnd, &ps); - Win32RedrawScreen(hdc); - EndPaint(hwnd, &ps); -} +// +// Helpers +// globalvar u8 keycode_lookup_table[255]; internal void -keycode_init(){ +Win32KeycodeInit(){ keycode_lookup_table[VK_BACK] = key_back; keycode_lookup_table[VK_DELETE] = key_del; keycode_lookup_table[VK_UP] = key_up; @@ -1252,9 +1234,55 @@ keycode_init(){ keycode_lookup_table[VK_F16] = key_f16; } +internal void +Win32RedrawScreen(HDC hdc){ + launch_rendering(&win32vars.target); + glFlush(); + SwapBuffers(hdc); +} + +internal void +Win32RedrawFromUpdate(){ + PAINTSTRUCT ps; + HWND hwnd = win32vars.window_handle; + HDC hdc = BeginPaint(hwnd, &ps); + Win32RedrawScreen(hdc); + EndPaint(hwnd, &ps); +} + +internal void +Win32Resize(i32 width, i32 height){ + if (width > 0 && height > 0){ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, height, 0, -1, 1); + glScissor(0, 0, width, height); + + win32vars.target.width = width; + win32vars.target.height = height; + } +} + +internal void +Win32SetCursorFromUpdate(Application_Mouse_Cursor cursor){ + switch (cursor){ + case APP_MOUSE_CURSOR_ARROW: + SetCursor(win32vars.cursor_arrow); break; + + case APP_MOUSE_CURSOR_IBEAM: + SetCursor(win32vars.cursor_ibeam); break; + + case APP_MOUSE_CURSOR_LEFTRIGHT: + SetCursor(win32vars.cursor_leftright); break; + + case APP_MOUSE_CURSOR_UPDOWN: + SetCursor(win32vars.cursor_updown); break; + } +} + internal LRESULT -Win32Callback(HWND hwnd, UINT uMsg, - WPARAM wParam, LPARAM lParam){ +Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ LRESULT result = {}; switch (uMsg){ case WM_MENUCHAR: @@ -1562,7 +1590,6 @@ OpenGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsi OutputDebugStringA("\n"); } -#if 1 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, @@ -1572,12 +1599,6 @@ WinMain(HINSTANCE hInstance, int argc = __argc; char **argv = __argv; -#else -int main(int argc, char **argv){ - - HINSTANCE hInstance = GetModuleHandle(0); -#endif - HANDLE original_out = GetStdHandle(STD_OUTPUT_HANDLE); memset(&win32vars, 0, sizeof(win32vars)); @@ -1701,6 +1722,14 @@ int main(int argc, char **argv){ } #endif + if (win32vars.custom_api.get_bindings == 0){ + win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)get_bindings; + } + + if (win32vars.custom_api.view_routine == 0){ + win32vars.custom_api.view_routine = (View_Routine_Function*)view_routine; + } + FreeConsole(); sysshared_filter_real_files(files, file_count); @@ -1716,11 +1745,7 @@ int main(int argc, char **argv){ win32vars.start_time = ((u64)filetime.dwHighDateTime << 32) | (filetime.dwLowDateTime); win32vars.start_time /= 10; - keycode_init(); - - if (win32vars.custom_api.get_bindings == 0){ - win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)get_bindings; - } + Win32KeycodeInit(); Thread_Context background[4]; memset(background, 0, sizeof(background)); @@ -2074,6 +2099,14 @@ int main(int argc, char **argv){ return 0; } +#if 0 +// NOTE(allen): In case I want to switch back to a console +// application at some point. +int main(int argc, char **argv){ + HINSTANCE hInstance = GetModuleHandle(0); +} +#endif + // BOTTOM