From 57c0707284cb845773a06d1780db3e1f57fe89b4 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Wed, 25 Dec 2019 03:17:12 +0200 Subject: [PATCH] Implemented system_get_path. --- platform_mac/mac_4ed.cpp | 27 ++++- platform_mac/mac_4ed.mm | 16 +++ platform_mac/mac_4ed_functions.cpp | 128 +++++++++++++++----- platform_mac/mac_objective_c_to_cpp_links.h | 4 +- platform_win32/win32_4ed_functions.cpp | 4 +- 5 files changed, 140 insertions(+), 39 deletions(-) diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index 7272be87..ec82755a 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -36,6 +36,11 @@ #include "4ed_search_list.cpp" +#include "mac_objective_c_to_cpp_links.h" + +#include +#include + //////////////////////////////// #define SLASH '\\' @@ -54,12 +59,14 @@ struct Mac_Vars { Thread_Context *tctx; Arena* frame_arena; + + String_Const_u8 binary_path; }; //////////////////////////////// -Mac_Vars global_mac_vars; -global Render_Target global_target; +Mac_Vars mac_vars; +global Render_Target target; //////////////////////////////// @@ -75,8 +82,8 @@ mac_init() { get_base_allocator_system(), get_base_allocator_system()); - block_zero_struct(&global_mac_vars); - global_mac_vars.tctx = &_tctx; + block_zero_struct(&mac_vars); + mac_vars.tctx = &_tctx; API_VTable_system system_vtable = {}; system_api_fill_vtable(&system_vtable); @@ -88,6 +95,14 @@ mac_init() { font_api_fill_vtable(&font_vtable); // NOTE(yuval): Memory - global_mac_vars.frame_arena = reserve_arena(global_mac_vars.tctx); - global_target.arena = make_arena_system(KB(256)); + mac_vars.frame_arena = reserve_arena(mac_vars.tctx); + target.arena = make_arena_system(KB(256)); + +#if 0 + mac_vars.cursor_show = MouseCursorShow_Always; + mac_vars.prev_cursor_show = MouseCursorShow_Always; + + dll_init_sentinel(&mac_vars.free_mac_objects); + dll_init_sentinel(&mac_vars.timer_objects); +#endif } \ No newline at end of file diff --git a/platform_mac/mac_4ed.mm b/platform_mac/mac_4ed.mm index 538e2f4a..cdd47d24 100644 --- a/platform_mac/mac_4ed.mm +++ b/platform_mac/mac_4ed.mm @@ -1,6 +1,7 @@ /* Mac Objective C layer for 4coder */ #include "4coder_base_types.h" + #include "mac_objective_c_to_cpp_links.h" #undef function @@ -9,6 +10,13 @@ #undef external #include +#include // NOTE(yuval): Used for proc_pidpath + +#include +#include // NOTE(yuval): Used for getpid + +#define external extern "C" + @interface App_Delegate : NSObject @end @@ -33,6 +41,14 @@ } @end +external i32 +mac_get_binary_path(void *buffer, u32 size){ + pid_t pid = getpid(); + i32 bytes_read = proc_pidpath(pid, buffer, size); + + return bytes_read; +} + int main(int arg_count, char **args){ @autoreleasepool{ diff --git a/platform_mac/mac_4ed_functions.cpp b/platform_mac/mac_4ed_functions.cpp index 7288250c..e157019b 100644 --- a/platform_mac/mac_4ed_functions.cpp +++ b/platform_mac/mac_4ed_functions.cpp @@ -1,12 +1,47 @@ -/* General macOS Functions */ +/* macOS System/Graphics/Font API Implementations */ + +//////////////////////////////// function system_get_path_sig(){ String_Const_u8 result = {}; - NotImplemented; + switch (path_code){ + case SystemPath_CurrentDirectory: + { + char *working_dir = getcwd(NULL, 0); + u64 working_dir_length = cstring_length(working_dir); + + // TODO(yuval): Maybe use push_string_copy instead + u8 *out = push_array(arena, u8, working_dir_length); + block_copy(out, working_dir, working_dir_length); + + free(working_dir); + + result = SCu8(out, working_dir_length); + } break; + + case SystemPath_Binary: + { + local_persist b32 has_stashed_4ed_path = false; + if (!has_stashed_4ed_path){ + local_const i32 binary_path_capacity = KB(32); + u8 *memory = (u8*)system_memory_allocate(binary_path_capacity, string_u8_litexpr(file_name_line_number)); + i32 size = mac_get_binary_path(memory, binary_path_capacity); + Assert(size <= binary_path_capacity - 1); + + mac_vars.binary_path = SCu8(memory, size); + mac_vars.binary_path = string_remove_last_folder(mac_vars.binary_path); + mac_vars.binary_path.str[mac_vars.binary_path.size] = 0; + + has_stashed_4ed_path = true; + } + + result = push_string_copy(arena, mac_vars.binary_path); + } break; + } - return result; + return(result); } function @@ -15,7 +50,7 @@ system_get_canonical_sig(){ NotImplemented; - return result; + return(result); } function @@ -24,7 +59,7 @@ system_get_file_list_sig(){ NotImplemented; - return result; + return(result); } function @@ -33,7 +68,7 @@ system_quick_file_attributes_sig(){ NotImplemented; - return result; + return(result); } function @@ -42,7 +77,7 @@ system_load_handle_sig(){ NotImplemented; - return result; + return(result); } function @@ -51,7 +86,7 @@ system_load_attributes_sig(){ NotImplemented; - return result; + return(result); } function @@ -60,7 +95,7 @@ system_load_file_sig(){ NotImplemented; - return result; + return(result); } function @@ -69,7 +104,7 @@ system_load_close_sig(){ NotImplemented; - return result; + return(result); } function @@ -78,7 +113,7 @@ system_save_file_sig(){ NotImplemented; - return result; + return(result); } function @@ -87,7 +122,7 @@ system_load_library_sig(){ NotImplemented; - return result; + return(result); } function @@ -96,7 +131,7 @@ system_release_library_sig(){ NotImplemented; - return result; + return(result); } function @@ -105,7 +140,7 @@ system_get_proc_sig(){ NotImplemented; - return result; + return(result); } function @@ -114,7 +149,7 @@ system_now_time_sig(){ NotImplemented; - return result; + return(result); } function @@ -123,7 +158,7 @@ system_wake_up_timer_create_sig(){ NotImplemented; - return result; + return(result); } function @@ -157,7 +192,7 @@ system_cli_call_sig(){ NotImplemented; - return result; + return(result); } function @@ -171,7 +206,7 @@ system_cli_update_step_sig(){ NotImplemented; - return result; + return(result); } function @@ -180,7 +215,7 @@ system_cli_end_update_sig(){ NotImplemented; - return result; + return(result); } function @@ -194,7 +229,7 @@ system_get_screen_scale_factor_sig(){ NotImplemented; - return result; + return(result); } function @@ -203,7 +238,7 @@ system_thread_launch_sig(){ NotImplemented; - return result; + return(result); } function @@ -222,7 +257,7 @@ system_thread_get_id_sig(){ NotImplemented; - return result; + return(result); } function @@ -241,7 +276,7 @@ system_mutex_make_sig(){ NotImplemented; - return result; + return(result); } function @@ -265,7 +300,7 @@ system_condition_variable_make_sig(){ NotImplemented; - return result; + return(result); } function @@ -289,7 +324,7 @@ system_memory_allocate_sig(){ NotImplemented; - return result; + return(result); } function @@ -298,7 +333,7 @@ system_memory_set_protection_sig(){ NotImplemented; - return result; + return(result); } function @@ -312,7 +347,7 @@ system_memory_annotation_sig(){ NotImplemented; - return result; + return(result); } function @@ -326,7 +361,7 @@ system_set_fullscreen_sig(){ NotImplemented; - return result; + return(result); } function @@ -335,7 +370,7 @@ system_is_fullscreen_sig(){ NotImplemented; - return result; + return(result); } function @@ -344,5 +379,38 @@ system_get_keyboard_modifiers_sig(){ NotImplemented; - return result; + return(result); } + +//////////////////////////////// + +function +graphics_get_texture_sig(){ + u32 result = 0; + + NotImplemented; + + return(result); +} + +function +graphics_fill_texture_sig(){ + b32 result = false; + + NotImplemented; + + return(result); +} + +//////////////////////////////// + +function +font_make_face_sig(){ + Face* result = 0; + + NotImplemented; + + return(result); +} + +//////////////////////////////// \ No newline at end of file diff --git a/platform_mac/mac_objective_c_to_cpp_links.h b/platform_mac/mac_objective_c_to_cpp_links.h index 09605098..0dc4ae3a 100644 --- a/platform_mac/mac_objective_c_to_cpp_links.h +++ b/platform_mac/mac_objective_c_to_cpp_links.h @@ -4,10 +4,12 @@ #define MAC_OBJECTIVE_C_TO_CPP_LINKS_H // In C++ layer. -external void* +external void mac_init(); // In Objective-C layer. +external i32 +mac_get_binary_path(void* buffer, u32 size); #endif diff --git a/platform_win32/win32_4ed_functions.cpp b/platform_win32/win32_4ed_functions.cpp index 8e139ea1..5e7533b3 100644 --- a/platform_win32/win32_4ed_functions.cpp +++ b/platform_win32/win32_4ed_functions.cpp @@ -444,7 +444,7 @@ color_picker_hook(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam){ // Would it have killed you to update rgbResult continuously, or at least // provide a GetCurrentColor() call??? // - // Anyway, since the color picker doesn't tell us when the color is + // Anyway, since the color picker doesn't tell us when the color is // changed, what we do is watch for messages that repaint the color // swatch, which is dialog id 0x2c5, and then we sample it to see what // color it is. No, I'm not fucking kidding, that's what we do. @@ -533,7 +533,7 @@ internal system_open_color_picker_sig(){ // TODO(allen): review // NOTE(casey): Because this is going to be used by a semi-permanent thread, we need to - // copy it to system memory where it can live as long as it wants, no matter what we do + // copy it to system memory where it can live as long as it wants, no matter what we do // over here on the 4coder threads. Color_Picker *perm = (Color_Picker*)system_memory_allocate(sizeof(Color_Picker), string_u8_litexpr(file_name_line_number)); *perm = *picker;