master
Allen Webster 2020-02-28 13:54:01 -08:00
commit 2b4fa0cc59
10 changed files with 129 additions and 102 deletions

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;
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;
} else {
its.it_value.tv_nsec = frame_nseconds - diff;
}
timerfd_settime(linuxvars.step_timer_fd, 0, &its, NULL);
} else {
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);
}
}
}
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;

View File

@ -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 = &(*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;

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.

View File

@ -9,6 +9,8 @@
// TOP
#error IS THIS STILL REAL? (February 27th 2020)
#if !defined(FD_CHECK)
#define FD_CHECK()
#endif

View File

@ -9,6 +9,8 @@
// TOP
#error IS THIS STILL REAL? (February 27th 2020)
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>

View File

@ -9,6 +9,8 @@
// TOP
#error IS THIS STILL REAL? (February 27th 2020)
union Library{
void *lib;
FixSize(LIBRARY_TYPE_SIZE);

View File

@ -9,6 +9,8 @@
// TOP
#error IS THIS STILL REAL? (February 27th 2020)
#if !defined(MAC_THREADING_WRAPPER)
#define MAC_THREADING_WRAPPER

View File

@ -1343,7 +1343,7 @@ 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));)
(l) = (l) && win32_wgl_good((Void_Func*)(f));)
b32 load_success = true;
LoadWGL(wglCreateContextAttribsARB, load_success);

View File

@ -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";
@ -53,11 +53,13 @@ command_list = {
{ .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 = "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",