Put linux now time on microseconds so dt is computed correctly; fix a bug in linux_schedule_step

This commit is contained in:
Allen Webster 2020-02-27 20:04:46 -08:00
parent d934161447
commit e300b209c1
6 changed files with 88 additions and 85 deletions

View File

@ -252,7 +252,7 @@ App_Init_Sig(app_init){
working_set_init(models, &models->working_set);
Mutex_Lock file_order_lock(models->working_set.mutex);
// NOTE(allen):
// NOTE(allen):
global_history_init(&models->global_history);
text_layout_init(tctx, &models->text_layouts);

View File

@ -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);

View File

@ -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);
}
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 = {};
@ -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;

View File

@ -267,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

View File

@ -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.
//

View File

@ -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);