diff --git a/platform_all/4ed_work_queues.cpp b/platform_all/4ed_work_queues.cpp index 75540681..215830d3 100644 --- a/platform_all/4ed_work_queues.cpp +++ b/platform_all/4ed_work_queues.cpp @@ -117,7 +117,7 @@ PLAT_THREAD_SIG(job_thread_proc){ // with the cancel job routine, which may try to cancel this job // at the same time that we try to run it - i32 safe_running_thread =InterlockedCompareExchange(&full_job->running_thread, thread->id, THREAD_NOT_ASSIGNED); + i32 safe_running_thread = InterlockedCompareExchange(&full_job->running_thread, thread->id, THREAD_NOT_ASSIGNED); if (safe_running_thread == THREAD_NOT_ASSIGNED){ thread->job_id = full_job->id; diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 5f1b9636..eeb46e71 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -89,6 +89,7 @@ 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. #define InterlockedCompareExchange(dest, ex, comp) \ __sync_val_compare_and_swap((dest), (comp), (ex)) diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index 2b70c6c8..8acb2416 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -48,11 +48,17 @@ #include #include +#include + //////////////////////////////// #include "4ed_shared_thread_constants.h" #include "unix_threading_wrapper.h" +// TODO(allen): Make an intrinsics header that uses the cracked OS to define a single set of intrinsic names. +#define InterlockedCompareExchange(dest, ex, comp) \ +__sync_val_compare_and_swap((dest), (comp), (ex)) + //////////////////////////////// #define SLASH '/' @@ -67,6 +73,8 @@ global System_Functions sysfunc; //////////////////////////////// +#include "osx_objective_c_to_cpp_links.h" +OSX_Vars osx; global Render_Target target; global Application_Memory memory_vars; global Plat_Settings plat_settings; @@ -79,15 +87,52 @@ global Coroutine_System_Auto_Alloc coroutines; //////////////////////////////// -#include "unix_4ed_functions.cpp" - -#include "osx_objective_c_to_cpp_links.h" -OSX_Vars osx; - -#include +#include "mac_error_box.cpp" //////////////////////////////// +#include "unix_4ed_functions.cpp" +#include "4ed_shared_file_handling.cpp" + +//////////////////////////////// + +internal void +system_schedule_step(){ + // NOTE(allen): It is unclear to me right now what we might need to actually do here. + // The run loop in a Cocoa app will keep rendering the app anyway, I might just need to set a + // "do_new_frame" variable of some kind to true here. +} + +//////////////////////////////// + +#include "4ed_work_queues.cpp" + +//////////////////////////////// + +// TODO(allen): add a "shown but auto-hides on timer" setting here. +internal +Sys_Show_Mouse_Cursor_Sig(system_show_mouse_cursor){ + // TODO(allen) +} + +internal +Sys_Set_Fullscreen_Sig(system_set_fullscreen){ + osx.do_toggle = (osx.full_screen != full_screen); + return(true); +} + +internal +Sys_Is_Fullscreen_Sig(system_is_fullscreen){ + b32 result = (osx.full_screen != osx.do_toggle); + return(result); +} + +// HACK(allen): Why does this work differently from the win32 version!? +internal +Sys_Send_Exit_Signal_Sig(system_send_exit_signal){ + osx.running = false; +} + #include "4ed_coroutine_functions.cpp" // @@ -107,8 +152,7 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ } memcpy(osx.clipboard_space, str.str, str.size); osx.clipboard_space[str.size] = 0; - string = osx.clipboard_space - ; + string = osx.clipboard_space; } osx_post_to_clipboard(string); } @@ -120,27 +164,27 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ internal Sys_CLI_Call_Sig(system_cli_call){ // b32 #(char *path, char *script_name, CLI_Handles *cli_out) - // TODO + NotImplemented; return(true); } internal Sys_CLI_Begin_Update_Sig(system_cli_begin_update){ // void #(CLI_Handles *cli) - // TODO + NotImplemented; } internal Sys_CLI_Update_Step_Sig(system_cli_update_step){ // b32 #(CLI_Handles *cli, char *dest, u32 max, u32 *amount) - // TODO + NotImplemented; return(0); } internal Sys_CLI_End_Update_Sig(system_cli_end_update){ // b32 #(CLI_Handles *cli) - // TODO + NotImplemented; return(false); } @@ -197,7 +241,7 @@ osx_init(){ // Memory init // - memset(&linuxvars, 0, sizeof(linuxvars)); + memset(&osx, 0, sizeof(osx)); memset(&target, 0, sizeof(target)); memset(&memory_vars, 0, sizeof(memory_vars)); memset(&plat_settings, 0, sizeof(plat_settings)); diff --git a/platform_mac/mac_4ed.m b/platform_mac/mac_4ed.m index 51bd8e3c..b9f9158b 100644 --- a/platform_mac/mac_4ed.m +++ b/platform_mac/mac_4ed.m @@ -38,6 +38,16 @@ osx_post_to_clipboard(char *str){ osx.just_posted_to_clipboard = true; } +void +osx_error_dialogue(char *str){ + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:@"OK"]; + NSString *text = [NSString stringWithUTF8String:str]; + [alert setMessageText:text]; + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; +} + // // Entry point, OpenGL window setup. // diff --git a/platform_mac/mac_error_box.cpp b/platform_mac/mac_error_box.cpp new file mode 100644 index 00000000..88793746 --- /dev/null +++ b/platform_mac/mac_error_box.cpp @@ -0,0 +1,19 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 26.09.2017 + * + * Mac error box implementation. + * + */ + +// TOP + +internal void +system_error_box(char *msg){ + osx_error_dialogue(msg); + exit(1); +} + +// BOTTOM + diff --git a/osx_objective_c_to_cpp_links.h b/platform_mac/osx_objective_c_to_cpp_links.h similarity index 93% rename from osx_objective_c_to_cpp_links.h rename to platform_mac/osx_objective_c_to_cpp_links.h index 91598f98..eb00b9d8 100644 --- a/osx_objective_c_to_cpp_links.h +++ b/platform_mac/osx_objective_c_to_cpp_links.h @@ -39,6 +39,9 @@ typedef struct OSX_Vars{ char *clipboard_space; umem clipboard_space_max; + + b32 full_screen; + b32 do_toggle; } OSX_Vars; // In C++ layer. @@ -69,6 +72,9 @@ osx_init(); external void osx_post_to_clipboard(char *str); +external void +osx_error_dialogue(char *str); + #endif // BOTTOM