2019-12-24 14:57:05 +00:00
|
|
|
/* Mac Objective C layer for 4coder */
|
|
|
|
|
2019-12-24 00:46:58 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2019-12-23 23:22:56 +00:00
|
|
|
|
2019-12-24 14:57:05 +00:00
|
|
|
#define FPS 60
|
|
|
|
#define frame_useconds (1000000 / FPS)
|
|
|
|
|
|
|
|
#include "4coder_base_types.h"
|
|
|
|
#include "4coder_version.h"
|
|
|
|
#include "4coder_events.h"
|
|
|
|
|
|
|
|
#include "4coder_system_types.h"
|
|
|
|
#define STATIC_LINK_API
|
|
|
|
#include "generated/system_api.h"
|
|
|
|
|
|
|
|
#include "generated/system_api.cpp"
|
|
|
|
|
|
|
|
#include "4coder_base_types.cpp"
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
#define SLASH '\\'
|
|
|
|
#define DLL "dll"
|
|
|
|
|
|
|
|
#include "4coder_hash_functions.cpp"
|
|
|
|
#include "4coder_system_allocator.cpp"
|
|
|
|
#include "4coder_codepoint_map.cpp"
|
|
|
|
|
|
|
|
#include "4ed_mem.cpp"
|
|
|
|
#include "4ed_font_set.cpp"
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-12-24 00:53:25 +00:00
|
|
|
@interface App_Delegate : NSObject<NSApplicationDelegate, NSWindowDelegate>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation App_Delegate
|
|
|
|
- (void)applicationDidFinishLaunching:(id)sender{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)notification{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)windowWillResize:(NSWindow*)window toSize:(NSSize)frame_size{
|
|
|
|
// frame_size.height = ((f32)frame_size.width / global_aspect_ratio);
|
|
|
|
return frame_size;
|
|
|
|
}
|
|
|
|
|
2019-12-24 14:57:05 +00:00
|
|
|
- (void)windowWillClose:(id)sender{
|
2019-12-24 00:53:25 +00:00
|
|
|
// global_running = false;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2019-12-23 00:39:44 +00:00
|
|
|
int
|
|
|
|
main(int arg_count, char **args){
|
2019-12-23 23:22:56 +00:00
|
|
|
@autoreleasepool{
|
2019-12-24 14:57:05 +00:00
|
|
|
// NOTE(yuval): Create NSApplication & Delegate
|
2019-12-23 23:22:56 +00:00
|
|
|
NSApplication* app = [NSApplication sharedApplication];
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
|
|
|
|
App_Delegate* app_delegate = [[App_Delegate alloc] init];
|
|
|
|
[app setDelegate:app_delegate];
|
|
|
|
|
|
|
|
[NSApp finishLaunching];
|
|
|
|
|
2019-12-24 14:57:05 +00:00
|
|
|
// NOTE(yuval): Context Setup
|
2019-12-23 23:22:56 +00:00
|
|
|
Thread_Context _tctx = {};
|
|
|
|
thread_ctx_init(&_tctx, ThreadKind_Main,
|
|
|
|
get_base_allocator_system(),
|
|
|
|
get_base_allocator_system());
|
|
|
|
|
|
|
|
block_zero_struct(&global_mac_vars);
|
|
|
|
global_mac_vars.tctx = &_tctx;
|
|
|
|
|
2019-12-24 14:57:05 +00:00
|
|
|
API_VTable_system system_vtable = {};
|
|
|
|
system_api_fill_vtable(&system_vtable);
|
|
|
|
|
|
|
|
API_VTable_graphics graphics_vtable = {};
|
|
|
|
graphics_api_fill_vtable(&graphics_vtable);
|
|
|
|
|
|
|
|
API_VTable_font font_vtable = {};
|
|
|
|
font_api_fill_vtable(&font_vtable);
|
|
|
|
|
|
|
|
// NOTE(yuval): Memory
|
|
|
|
global_mac_vars.frame_arena = reserve_arena(global_mac_vars.tctx);
|
|
|
|
global_target.arean = make_arena_system(KB(256));
|
|
|
|
|
2019-12-23 23:22:56 +00:00
|
|
|
// NOTE(yuval): Application Core Update
|
|
|
|
Application_Step_Result result = {};
|
|
|
|
if (app.step != 0){
|
|
|
|
result = app.step(mac_vars.tctx, &target, base_ptr, &input);
|
|
|
|
}
|
2019-12-23 00:39:44 +00:00
|
|
|
}
|
|
|
|
}
|