From 50b8a646146f115eb072efabeebe9206f34a9e43 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Mon, 30 Dec 2019 02:33:30 +0200 Subject: [PATCH] The projects compiles. --- platform_mac/mac_4ed.mm | 48 +++++++++++++++++++++++++++---- platform_mac/mac_4ed_functions.mm | 6 ++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/platform_mac/mac_4ed.mm b/platform_mac/mac_4ed.mm index 9a87b069..aa0790b7 100644 --- a/platform_mac/mac_4ed.mm +++ b/platform_mac/mac_4ed.mm @@ -52,6 +52,7 @@ #import #include // NOTE(yuval): Used for proc_pidpath +#include // NOTE(yuval): Used for mach_absolute_time, mach_timebase_info, mach_timebase_info_data_t #include // NOTE(yuval): Used for opendir, readdir #include // NOTE(yuval): Used for dlopen, dlclose, dlsym @@ -83,6 +84,16 @@ //////////////////////////////// +@interface App_Delegate : NSObject +@end + +@interface Opengl_View : NSOpenGLView +@end + +//////////////////////////////// + +//////////////////////////////// + typedef i32 Mac_Object_Kind; enum{ MacObjectKind_ERROR = 0, @@ -110,6 +121,11 @@ struct Mac_Vars { String_Const_u8 binary_path; + NSWindow* window; + Opengl_View* view; + + mach_timebase_info_data_t timebase_info; + Node free_mac_objects; Node timer_objects; }; @@ -133,7 +149,7 @@ mac_to_object(Plat_Handle handle){ return(result); } -function +function Mac_Object* mac_alloc_object(Mac_Object_Kind kind){ Mac_Object *result = 0; @@ -170,7 +186,7 @@ mac_alloc_object(Mac_Object_Kind kind){ return(result); } -function +function void mac_free_object(Mac_Object *object){ if (object->node.next != 0){ dll_remove(&object->node); @@ -185,9 +201,6 @@ mac_free_object(Mac_Object *object){ //////////////////////////////// -@interface App_Delegate : NSObject -@end - @implementation App_Delegate - (void)applicationDidFinishLaunching:(id)sender{ } @@ -209,6 +222,28 @@ mac_free_object(Mac_Object *object){ } @end +@implementation Opengl_View +- (id)init { + self = [super init]; + return self; +} + +- (void)prepareOpenGL { + [super prepareOpenGL]; + [[self openGLContext] makeCurrentContext]; +} + +- (void)reshape { + [super reshape]; + + NSRect bounds = [self bounds]; + // [global_opengl_context makeCurrentContext]; + // [global_opengl_context update]; + // glViewport(0, 0, (GLsizei)bounds.size.width, + // (GLsizei)bounds.size.height); +} +@end + //////////////////////////////// int @@ -265,6 +300,9 @@ main(int arg_count, char **args){ dll_init_sentinel(&mac_vars.free_mac_objects); dll_init_sentinel(&mac_vars.timer_objects); + + // NOTE(yuval): Get the timebase info + mach_timebase_info(&mac_vars.timebase_info); #endif #if 0 diff --git a/platform_mac/mac_4ed_functions.mm b/platform_mac/mac_4ed_functions.mm index b98780d8..35e406e0 100644 --- a/platform_mac/mac_4ed_functions.mm +++ b/platform_mac/mac_4ed_functions.mm @@ -385,8 +385,8 @@ function system_wake_up_timer_release_sig(){ Mac_Object *object = (Mac_Object*)mac_to_object(handle); if (object->kind == MacObjectKind_Timer){ - if ((object->timer != nil) && [object->timer isValid]) { - [object->timer invalidate]; + if ((object->timer.timer != nil) && [object->timer.timer isValid]) { + [object->timer.timer invalidate]; mac_free_object(object); } } @@ -397,7 +397,7 @@ system_wake_up_timer_set_sig(){ Mac_Object *object = (Mac_Object*)mac_to_object(handle); if (object->kind == MacObjectKind_Timer){ f64 time_seconds = ((f64)time_milliseconds / 1000.0); - object->timer = [NSTimer scheduledTimerWithTimeInterval: time_seconds + object->timer.timer = [NSTimer scheduledTimerWithTimeInterval: time_seconds target: mac_vars.view selector: @selector(requestDisplay) userInfo: nil repeats:NO];