diff --git a/custom/4coder_delta_rule.cpp b/custom/4coder_delta_rule.cpp index 83a7b1b5..9774dd19 100644 --- a/custom/4coder_delta_rule.cpp +++ b/custom/4coder_delta_rule.cpp @@ -53,7 +53,7 @@ delta_apply(Application_Links *app, View_ID view, } function Buffer_Point_Delta_Result -delta_apply(Application_Links *app, View_ID view, +delta_apply(Application_Links *app, View_ID view, Delta_Rule_Function *func, Data delta_ctx, f32 dt, Buffer_Scroll scroll){ return(delta_apply(app, view, func, delta_ctx, @@ -61,7 +61,7 @@ delta_apply(Application_Links *app, View_ID view, } function Buffer_Point_Delta_Result -delta_apply(Application_Links *app, View_ID view, +delta_apply(Application_Links *app, View_ID view, f32 dt, Buffer_Point position, Buffer_Point target){ View_Context ctx = view_current_context(app, view); Data delta_ctx = view_current_context_hook_memory(app, view, HookID_DeltaRule); @@ -70,7 +70,7 @@ delta_apply(Application_Links *app, View_ID view, } function Buffer_Point_Delta_Result -delta_apply(Application_Links *app, View_ID view, +delta_apply(Application_Links *app, View_ID view, f32 dt, Buffer_Scroll scroll){ View_Context ctx = view_current_context(app, view); Data delta_ctx = view_current_context_hook_memory(app, view, HookID_DeltaRule); @@ -119,7 +119,7 @@ delta_apply(Application_Links *app, View_ID view, } function Vec2_f32_Delta_Result -delta_apply(Application_Links *app, View_ID view, +delta_apply(Application_Links *app, View_ID view, f32 dt, Vec2_f32 position, Vec2_f32 target){ View_Context ctx = view_current_context(app, view); Data delta_ctx = view_current_context_hook_memory(app, view, HookID_DeltaRule); @@ -128,7 +128,7 @@ delta_apply(Application_Links *app, View_ID view, } function Vec2_f32_Delta_Result -delta_apply(Application_Links *app, View_ID view, +delta_apply(Application_Links *app, View_ID view, f32 dt, Basic_Scroll scroll){ View_Context ctx = view_current_context(app, view); Data delta_ctx = view_current_context_hook_memory(app, view, HookID_DeltaRule); diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 838f5c6c..c114b406 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -11,8 +11,8 @@ // TOP #define FPS 60 -#define frame_useconds (1000000 / FPS) -#define frame_nseconds (UINT64_C(1000000000) / FPS) +#define frame_useconds (Million(1) / FPS) +#define frame_nseconds (Billion(1) / FPS) #define SLASH '/' #define DLL "so" @@ -168,7 +168,6 @@ struct Linux_Vars { int epoll; int step_timer_fd; u64 last_step_time; - b32 step_pending; XCursor xcursors[APP_MOUSE_CURSOR_COUNT]; Application_Mouse_Cursor cursor; @@ -336,8 +335,8 @@ linux_system_get_file_list_filter(const struct dirent *dirent) { } internal u64 -linux_ns_from_timespec(const struct timespec timespec) { - return timespec.tv_nsec + UINT64_C(1000000000) * timespec.tv_sec; +linux_us_from_timespec(const struct timespec timespec) { + return timespec.tv_nsec/Thousand(1) + Million(1) * timespec.tv_sec; } internal File_Attribute_Flag @@ -351,29 +350,28 @@ internal File_Attributes linux_file_attributes_from_struct_stat(struct stat* file_stat) { File_Attributes result = {}; result.size = file_stat->st_size; - result.last_write_time = linux_ns_from_timespec(file_stat->st_mtim); + result.last_write_time = linux_us_from_timespec(file_stat->st_mtim); result.flags = linux_convert_file_attribute_flags(file_stat->st_mode); - return result; + return(result); } internal void linux_schedule_step(){ - if(!__sync_bool_compare_and_swap(&linuxvars.step_pending, 0, 1)) { - return; - } - u64 now = system_now_time(); u64 diff = (now - linuxvars.last_step_time); struct itimerspec its = {}; + timerfd_gettime(linuxvars.step_timer_fd, &its); - if(diff >= frame_nseconds) { + if (diff > frame_useconds) { its.it_value.tv_nsec = 1; + timerfd_settime(linuxvars.step_timer_fd, 0, &its, NULL); } else { - its.it_value.tv_nsec = frame_nseconds - diff; + if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0){ + its.it_value.tv_nsec = (frame_useconds - diff) * 1000UL; + timerfd_settime(linuxvars.step_timer_fd, 0, &its, NULL); + } } - - timerfd_settime(linuxvars.step_timer_fd, 0, &its, NULL); } enum wm_state_mode { @@ -583,8 +581,7 @@ linux_find_font(Face_Description* desc) { } } - FcPattern *pattern = FcPatternBuild( - 0, + FcPattern *pattern = FcPatternBuild(0, FC_POSTSCRIPT_NAME, FcTypeString, name, FC_SIZE, FcTypeDouble, size, FC_FONTFORMAT, FcTypeString, "TrueType", @@ -1455,8 +1452,7 @@ linux_handle_x11_events() { // Notify WM that we're still responding (don't grey our window out). else if(atom == linuxvars.atom__NET_WM_PING) { event.xclient.window = DefaultRootWindow(linuxvars.dpy); - XSendEvent( - linuxvars.dpy, + XSendEvent(linuxvars.dpy, event.xclient.window, False, SubstructureRedirectMask | SubstructureNotifyMask, @@ -1599,7 +1595,7 @@ main(int argc, char **argv){ //InitializeCriticalSection(&win32vars.thread_launch_mutex); //InitializeConditionVariable(&win32vars.thread_launch_cv); - linuxvars.clipboard_catch_all = true; + linuxvars.clipboard_catch_all = false; // NOTE(allen): load core System_Library core_library = {}; @@ -1666,7 +1662,7 @@ main(int argc, char **argv){ char custom_fail_version_msg[] = "Failed to load custom code due to a version mismatch. Try rebuilding with buildsuper."; char custom_fail_init_apis[] = "Failed to load custom code due to missing 'init_apis' symbol. Try rebuilding with buildsuper"; - Scratch_Block scratch(&linuxvars.tctx, Scratch_Share); + Scratch_Block scratch(&linuxvars.tctx); String_Const_u8 default_file_name = string_u8_litexpr("custom_4coder.so"); Path_Search_List search_list = {}; search_list_add_system_path(scratch, &search_list, SystemPath_CurrentDirectory); @@ -1729,6 +1725,7 @@ main(int argc, char **argv){ linux_schedule_step(); b32 first_step = true; + u64 timer_start = system_now_time(); for (;;) { @@ -1813,11 +1810,17 @@ main(int argc, char **argv){ gl_render(&render_target); glXSwapBuffers(linuxvars.dpy, linuxvars.win); + // TODO(allen): don't let the screen size change until HERE after the render + + // NOTE(allen): Schedule a step if necessary + if (result.animating){ + linux_schedule_step(); + } + first_step = false; linalloc_clear(linuxvars.frame_arena); block_zero_struct(&linuxvars.input.trans); - linuxvars.step_pending = false; } return 0; diff --git a/platform_linux/linux_4ed_functions.cpp b/platform_linux/linux_4ed_functions.cpp index db0e400d..0be85ad0 100644 --- a/platform_linux/linux_4ed_functions.cpp +++ b/platform_linux/linux_4ed_functions.cpp @@ -132,11 +132,13 @@ system_get_file_list(Arena* arena, String_Const_u8 directory){ (*fip)->file_name = push_u8_stringf(arena, "%.*s", d->d_reclen, name); struct stat st; - if(fstatat(fd, name, &st, 0) == -1){ + if (fstatat(fd, name, &st, 0) == -1){ perror("fstatat"); } + else{ + (*fip)->attributes = linux_file_attributes_from_struct_stat(&st); + } - (*fip)->attributes = linux_file_attributes_from_struct_stat(&st); fip = &(*fip)->next; result.count++; } @@ -163,9 +165,14 @@ system_get_file_list(Arena* arena, String_Const_u8 directory){ internal File_Attributes system_quick_file_attributes(Arena* scratch, String_Const_u8 file_name){ //LINUX_FN_DEBUG("%.*s", (int)file_name.size, file_name.str); + Temp_Memory_Block temp(scratch); + file_name = push_string_copy(scratch, file_name); + File_Attributes result = {}; struct stat file_stat; - stat((const char*)file_name.str, &file_stat); - return linux_file_attributes_from_struct_stat(&file_stat); + if (stat((const char*)file_name.str, &file_stat) == 0){ + result = linux_file_attributes_from_struct_stat(&file_stat); + } + return(result); } internal b32 @@ -182,9 +189,12 @@ system_load_handle(Arena* scratch, char* file_name, Plat_Handle* out){ internal File_Attributes system_load_attributes(Plat_Handle handle){ LINUX_FN_DEBUG(); + File_Attributes result = {}; struct stat file_stat; - fstat(*(int*)&handle, &file_stat); - return linux_file_attributes_from_struct_stat(&file_stat); + if (fstat(*(int*)&handle, &file_stat) == 0){ + result = linux_file_attributes_from_struct_stat(&file_stat); + } + return(result); } internal b32 @@ -212,15 +222,16 @@ system_save_file(Arena* scratch, char* file_name, String_Const_u8 data){ // TODO(inso): should probably put a \n on the end if it's a text file. - int fd = open(file_name, O_WRONLY, O_CREAT); + int fd = open(file_name, O_TRUNC|O_WRONLY|O_CREAT, 0666); if (fd != -1) { int bytes_written = write(fd, data.str, data.size); if (bytes_written == -1) { perror("write"); - } else if(bytes_written == data.size) { + } else if (bytes_written == data.size) { struct stat file_stat; - fstat(fd, &file_stat); - return linux_file_attributes_from_struct_stat(&file_stat); + if (fstat(fd, &file_stat) == 0){ + result = linux_file_attributes_from_struct_stat(&file_stat); + } } } else { perror("open"); @@ -256,8 +267,8 @@ internal u64 system_now_time(void){ //LINUX_FN_DEBUG(); struct timespec time; - clock_gettime(CLOCK_MONOTONIC_RAW, &time); - return linux_ns_from_timespec(time); + clock_gettime(CLOCK_MONOTONIC, &time); + return linux_us_from_timespec(time); } internal Plat_Handle @@ -554,7 +565,10 @@ internal System_Mutex system_mutex_make(void){ System_Mutex result = {}; Linux_Object* object = linux_alloc_object(LinuxObjectKind_Mutex); - pthread_mutex_init(&object->mutex, NULL); + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&object->mutex, &attr); *(Linux_Object**)&result = object; //LINUX_FN_DEBUG("%p", object); return result; diff --git a/platform_linux/linux_4ed_old.cpp b/platform_linux/linux_4ed_old.cpp index 6a050baf..d0cd237d 100644 --- a/platform_linux/linux_4ed_old.cpp +++ b/platform_linux/linux_4ed_old.cpp @@ -86,7 +86,7 @@ #define frame_useconds (1000000UL / FPS) #define LINUX_FN_DEBUG(fmt, ...) do { \ - /*LOGF("%s: " fmt "\n", __func__, ##__VA_ARGS__);*/ \ +/*LOGF("%s: " fmt "\n", __func__, ##__VA_ARGS__);*/ \ } while (0) // TODO(allen): Make an intrinsics header that uses the cracked OS to define a single set of intrinsic names. @@ -547,41 +547,41 @@ Sys_Font_Path(name, parameters){ Font_Path path = {}; FcPattern *pattern_regular = FcPatternBuild( - 0, - FC_POSTSCRIPT_NAME, FcTypeString, name, - FC_SIZE, FcTypeDouble, (double)parameters->pt_size, - FC_FONTFORMAT, FcTypeString, "TrueType", - FC_STYLE, FcTypeString, (FcChar8*)"Regular", - (void*)0); + 0, + FC_POSTSCRIPT_NAME, FcTypeString, name, + FC_SIZE, FcTypeDouble, (double)parameters->pt_size, + FC_FONTFORMAT, FcTypeString, "TrueType", + FC_STYLE, FcTypeString, (FcChar8*)"Regular", + (void*)0); FcPattern *pattern_styled = 0; if (parameters->italics || parameters->bold){ if (parameters->italics && !parameters->bold){ pattern_styled = FcPatternBuild( - 0, - FC_POSTSCRIPT_NAME, FcTypeString, name, - FC_SIZE, FcTypeDouble, (double)parameters->pt_size, - FC_FONTFORMAT, FcTypeString, "TrueType", - FC_STYLE, FcTypeString, (FcChar8*)"Italic", - (void*)0); + 0, + FC_POSTSCRIPT_NAME, FcTypeString, name, + FC_SIZE, FcTypeDouble, (double)parameters->pt_size, + FC_FONTFORMAT, FcTypeString, "TrueType", + FC_STYLE, FcTypeString, (FcChar8*)"Italic", + (void*)0); } else if (!parameters->italics && parameters->bold){ pattern_styled = FcPatternBuild( - 0, - FC_POSTSCRIPT_NAME, FcTypeString, name, - FC_SIZE, FcTypeDouble, (double)parameters->pt_size, - FC_FONTFORMAT, FcTypeString, "TrueType", - FC_STYLE, FcTypeString, (FcChar8*)"Bold", - (void*)0); + 0, + FC_POSTSCRIPT_NAME, FcTypeString, name, + FC_SIZE, FcTypeDouble, (double)parameters->pt_size, + FC_FONTFORMAT, FcTypeString, "TrueType", + FC_STYLE, FcTypeString, (FcChar8*)"Bold", + (void*)0); } else{ pattern_styled = FcPatternBuild( - 0, - FC_POSTSCRIPT_NAME, FcTypeString, name, - FC_SIZE, FcTypeDouble, (double)parameters->pt_size, - FC_FONTFORMAT, FcTypeString, "TrueType", - FC_STYLE, FcTypeString, (FcChar8*)"Bold Italic", - (void*)0); + 0, + FC_POSTSCRIPT_NAME, FcTypeString, name, + FC_SIZE, FcTypeDouble, (double)parameters->pt_size, + FC_FONTFORMAT, FcTypeString, "TrueType", + FC_STYLE, FcTypeString, (FcChar8*)"Bold Italic", + (void*)0); } } @@ -672,9 +672,9 @@ linux_get_loadable_fonts(Partition *part, Font_Setup_List *list){ } FcPattern* pat = FcPatternBuild( - 0, - FC_STYLE, FcTypeString, (FcChar8*)"Regular", - (void*)0); + 0, + FC_STYLE, FcTypeString, (FcChar8*)"Regular", + (void*)0); FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char*)0); FcFontSet* fs = FcFontList(fc_config, pat, os); if (fs != 0){ @@ -778,7 +778,7 @@ InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig *best_con if (glXCreateContextAttribsARB == 0){ //LOG("glXCreateContextAttribsARB() not found, using old-style GLX context\n" ); ctx = glXCreateNewContext( XDisplay, *best_config, GLX_RGBA_TYPE, 0, True ); - } + } else{ int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 2, @@ -926,7 +926,7 @@ ChooseGLXConfig(Display *XDisplay, int XScreenIndex) GLX_STENCIL_SIZE , 8, GLX_DOUBLEBUFFER , True, None - }; + }; int ConfigCount = 0; GLXFBConfig *Configs = glXChooseFBConfig(XDisplay, XScreenIndex, DesiredAttributes, &ConfigCount); @@ -1196,7 +1196,7 @@ LinuxGetXSettingsDPI(Display* dpy, int screen) Window xset_win = XGetSelectionOwner(dpy, XSET_SEL); if (xset_win == None){ // TODO(inso): listen for the ClientMessage about it becoming available? - // there's not much point atm if DPI scaling is only done at startup + // there's not much point atm if DPI scaling is only done at startup goto out; } @@ -1760,11 +1760,11 @@ linux_handle_x11_events(void) else if ((Atom)event.xclient.data.l[0] == linuxvars.atom__NET_WM_PING){ event.xclient.window = DefaultRootWindow(linuxvars.XDisplay); XSendEvent( - linuxvars.XDisplay, - event.xclient.window, - False, - SubstructureRedirectMask | SubstructureNotifyMask, - &event); + linuxvars.XDisplay, + event.xclient.window, + False, + SubstructureRedirectMask | SubstructureNotifyMask, + &event); } }break; @@ -1792,14 +1792,14 @@ linux_handle_x11_events(void) if (request.target == linuxvars.atom_TARGETS){ XChangeProperty( - request.display, - request.requestor, - request.property, - XA_ATOM, - 32, - PropModeReplace, - (u8*)atoms, - ArrayCount(atoms)); + request.display, + request.requestor, + request.property, + XA_ATOM, + 32, + PropModeReplace, + (u8*)atoms, + ArrayCount(atoms)); response.property = request.property; @@ -1814,15 +1814,15 @@ linux_handle_x11_events(void) if (found){ XChangeProperty( - request.display, - request.requestor, - request.property, - request.target, - 8, - PropModeReplace, - (u8*)linuxvars.clipboard_outgoing.str, - linuxvars.clipboard_outgoing.size - ); + request.display, + request.requestor, + request.property, + request.target, + 8, + PropModeReplace, + (u8*)linuxvars.clipboard_outgoing.str, + linuxvars.clipboard_outgoing.size + ); response.property = request.property; } @@ -1915,7 +1915,7 @@ main(int argc, char **argv){ memory_init(); // - // HACK(allen): + // HACK(allen): // Previously zipped stuff is here, it should be zipped in the new pattern now. // diff --git a/platform_unix/unix_4ed_functions.cpp b/platform_unix/unix_4ed_functions.cpp index d6fe65b7..693d6e15 100644 --- a/platform_unix/unix_4ed_functions.cpp +++ b/platform_unix/unix_4ed_functions.cpp @@ -9,6 +9,8 @@ // TOP +#error IS THIS STILL REAL? (February 27th 2020) + #if !defined(FD_CHECK) #define FD_CHECK() #endif diff --git a/platform_unix/unix_4ed_headers.h b/platform_unix/unix_4ed_headers.h index 7548359b..2a48e541 100644 --- a/platform_unix/unix_4ed_headers.h +++ b/platform_unix/unix_4ed_headers.h @@ -9,6 +9,8 @@ // TOP +#error IS THIS STILL REAL? (February 27th 2020) + #include #include #include diff --git a/platform_unix/unix_library_wrapper.h b/platform_unix/unix_library_wrapper.h index 0af75f92..b358ce34 100644 --- a/platform_unix/unix_library_wrapper.h +++ b/platform_unix/unix_library_wrapper.h @@ -9,6 +9,8 @@ // TOP +#error IS THIS STILL REAL? (February 27th 2020) + union Library{ void *lib; FixSize(LIBRARY_TYPE_SIZE); diff --git a/platform_unix/unix_threading_wrapper.h b/platform_unix/unix_threading_wrapper.h index a8d1afd9..15af8bd2 100644 --- a/platform_unix/unix_threading_wrapper.h +++ b/platform_unix/unix_threading_wrapper.h @@ -9,6 +9,8 @@ // TOP +#error IS THIS STILL REAL? (February 27th 2020) + #if !defined(MAC_THREADING_WRAPPER) #define MAC_THREADING_WRAPPER diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 423de917..5631f44c 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -1343,9 +1343,9 @@ win32_gl_create_window(HWND *wnd_out, HGLRC *context_out, DWORD style, RECT rect // NOTE(allen): Load wgl extensions #define LoadWGL(f,l) Stmnt((f) = (f##_Function*)wglGetProcAddress(#f); \ - (l) = (l) && win32_wgl_good((Void_Func*)(f));) - - b32 load_success = true; +(l) = (l) && win32_wgl_good((Void_Func*)(f));) + + b32 load_success = true; LoadWGL(wglCreateContextAttribsARB, load_success); LoadWGL(wglChoosePixelFormatARB, load_success); LoadWGL(wglGetExtensionsStringEXT, load_success); diff --git a/project.4coder b/project.4coder index c5484349..24fc991f 100644 --- a/project.4coder +++ b/project.4coder @@ -26,8 +26,8 @@ load_paths = { build_x64_win32 = "echo build: x64 & bin\\build.bat"; build_x86_win32 = "echo build: x86 & bin\\build.bat /DDEV_BUILD_X86"; -build_x64_linux = "echo build: x64 & bin/build.sh"; -build_x86_linux = "echo build: x86 & bin/build.sh -DDEV_BUILD_X86"; +build_x64_linux = "echo build: x64 & bin/build-linux.sh"; +build_x86_linux = "echo build: x86 & bin/build-linux.sh -DDEV_BUILD_X86"; build_x64_mac = "echo build: x64 & bin/build-mac.sh"; build_x86_mac = "echo build: x86 & bin/build-mac.sh -DDEV_BUILD_X86"; @@ -46,18 +46,20 @@ command_list = { { .name = "package", .out = "*compilation*", .footer_panel = false, .save_dirty_files = true, - .cmd = { {"echo package & bin\\package.bat", .os = "win" }, - {"echo package & bin/package.sh" , .os = "linux"}, + .cmd = { {"echo package & bin\\package.bat", .os = "win" }, + {"echo package & bin/package.sh" , .os = "linux"}, {"echo package & bin/package.sh" , .os = "mac" }, }, }, { .name = "run one time", .out = "*run*", .footer_panel = false, .save_dirty_files = false, .cmd = { { "pushd ..\\build & one_time", .os = "win" }, - { "pushd ../build & one_time", .os = "mac" }, }, }, + { "pushd ../build & one_time", .os = "linux" }, + { "pushd ../build & one_time", .os = "mac" }, }, }, { .name = "build custom api docs", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cmd = { { "custom\\bin\\build_one_time docs\\4ed_doc_custom_api_main.cpp ..\\build", .os = "win" }, + { "custom/bin/build_one_time.sh docs/4ed_doc_custom_api_main.cpp ../build", .os = "linux" }, { "custom/bin/build_one_time.sh docs/4ed_doc_custom_api_main.cpp ../build", .os = "mac" }, }, }, { .name = "build C++ lexer generator",