Created basic Mac_Object structure and mac object allocation function.
This commit is contained in:
parent
8020dcf385
commit
76069e9ac1
|
@ -70,6 +70,113 @@
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
#define SLASH '/'
|
||||
#define DLL "so"
|
||||
|
||||
#include "4coder_hash_functions.cpp"
|
||||
#include "4coder_system_allocator.cpp"
|
||||
#include "4coder_malloc_allocator.cpp"
|
||||
#include "4coder_codepoint_map.cpp"
|
||||
|
||||
#include "4ed_mem.cpp"
|
||||
#include "4ed_font_set.cpp"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
typedef i32 Win32_Object_Kind;
|
||||
enum{
|
||||
Win32ObjectKind_ERROR = 0,
|
||||
Win32ObjectKind_Timer = 1,
|
||||
Win32ObjectKind_Thread = 2,
|
||||
Win32ObjectKind_Mutex = 3,
|
||||
Win32ObjectKind_CV = 4,
|
||||
};
|
||||
|
||||
struct Mac_Object{
|
||||
Node node;
|
||||
Mac_Object_Kind kind;
|
||||
|
||||
union{
|
||||
struct{
|
||||
NSTimer* timer;
|
||||
} timer;
|
||||
};
|
||||
};
|
||||
|
||||
struct Mac_Vars {
|
||||
Thread_Context *tctx;
|
||||
|
||||
Arena* frame_arena;
|
||||
|
||||
String_Const_u8 binary_path;
|
||||
|
||||
Node free_mac_objects;
|
||||
Node timer_objects;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
global Mac_Vars mac_vars;
|
||||
global Render_Target target;
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
function inline Plat_Handle
|
||||
mac_to_plat_handle(Mac_Object* object){
|
||||
Plat_Handle result = *(Plat_Handle*)(&object);
|
||||
return(result);
|
||||
}
|
||||
|
||||
function inline Mac_Object*
|
||||
mac_to_object(Plat_Handle handle){
|
||||
Mac_Object* result = *(Mac_Object**)(&handle);
|
||||
return(result);
|
||||
}
|
||||
|
||||
function
|
||||
mac_alloc_object(Mac_Object_Kind kind){
|
||||
Mac_Object* result = 0;
|
||||
|
||||
if (mac_vars.free_mac_objects.next != &mac_vars.free_mac_objects){
|
||||
result = CastFromMember(Mac_Object, node, mac_vars.free_mac_objects.next);
|
||||
}
|
||||
|
||||
if (!result){
|
||||
i32 count = 512;
|
||||
Mac_Object* objects = (Mac_Object*)system_memory_allocate(count * sizeof(Mac_Object), file_name_line_number);
|
||||
|
||||
// NOTE(yuval): Link the first chain of the dll to the sentinel
|
||||
objects[0].node.prev = &mac_vars.free_mac_objects;
|
||||
mac_vars.free_mac_objects.next = &objects[0].node;
|
||||
|
||||
// NOTE(yuval): Link all dll chains to each other
|
||||
for (i32 chain_index = 1; chain_index < count; chain_index += 1){
|
||||
objects[chain_index - 1].node.next = &objects[chain_index].node;
|
||||
objects[chain_index].node.prev = &objects[chain_index - 1].node;
|
||||
}
|
||||
|
||||
// NOTE(yuval): Link the last chain of the dll to the sentinel
|
||||
objects[count - 1].node.next = &mac_vars.free_mac_objects;
|
||||
mac_vars.free_mac_objects.prev = &objects[count - 1].node;
|
||||
|
||||
result = CastFromMember(Mac_Object, node, mac_vars.free_mac_objects.next);
|
||||
}
|
||||
|
||||
Assert(result);
|
||||
dll_remove(&result->node);
|
||||
block_zero_struct(result);
|
||||
result->kind = kind;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#import "mac_4ed_functions.mm"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@interface App_Delegate : NSObject<NSApplicationDelegate, NSWindowDelegate>
|
||||
@end
|
||||
|
||||
|
@ -96,38 +203,6 @@
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
#define SLASH '/'
|
||||
#define DLL "so"
|
||||
|
||||
#include "4coder_hash_functions.cpp"
|
||||
#include "4coder_system_allocator.cpp"
|
||||
#include "4coder_malloc_allocator.cpp"
|
||||
#include "4coder_codepoint_map.cpp"
|
||||
|
||||
#include "4ed_mem.cpp"
|
||||
#include "4ed_font_set.cpp"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
struct Mac_Vars {
|
||||
Thread_Context *tctx;
|
||||
|
||||
Arena* frame_arena;
|
||||
|
||||
String_Const_u8 binary_path;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
global Mac_Vars mac_vars;
|
||||
global Render_Target target;
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#import "mac_4ed_functions.mm"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
int
|
||||
main(int arg_count, char **args){
|
||||
@autoreleasepool{
|
||||
|
|
|
@ -203,13 +203,13 @@ system_quick_file_attributes_sig(){
|
|||
function inline Plat_Handle
|
||||
mac_to_plat_handle(i32 fd){
|
||||
Plat_Handle result = *(Plat_Handle*)(&fd);
|
||||
return result;
|
||||
return(result);
|
||||
}
|
||||
|
||||
function inline i32
|
||||
mac_to_fd(Plat_Handle handle){
|
||||
i32 result = *(i32*)(&handle);
|
||||
return result;
|
||||
return(result);
|
||||
}
|
||||
|
||||
function
|
||||
|
@ -304,13 +304,13 @@ system_save_file_sig(){
|
|||
function inline System_Library
|
||||
mac_to_system_library(void* dl_handle){
|
||||
System_Library result = *(System_Library*)(&dl_handle);
|
||||
return result;
|
||||
return(result);
|
||||
}
|
||||
|
||||
function inline void*
|
||||
mac_to_dl_handle(System_Library system_lib){
|
||||
void* result = *(void**)(&system_lib);
|
||||
return result;
|
||||
return(result);
|
||||
}
|
||||
|
||||
function
|
||||
|
@ -363,14 +363,13 @@ function
|
|||
system_now_time_sig(){
|
||||
u64 now = mach_absolute_time();
|
||||
|
||||
// NOTE(yuval): Elapsed nanoseconds calculation
|
||||
u64 result = (u64)(((f32)now) *
|
||||
((f32)mac_vars.timebase_info.numer) /
|
||||
((f32)mac_vars.timebase_info.denom));
|
||||
// NOTE(yuval): Now time nanoseconds conversion
|
||||
f64 now_nano = (f64)(((f64)now) *
|
||||
((f64)mac_vars.timebase_info.numer) /
|
||||
((f64)mac_vars.timebase_info.denom));
|
||||
|
||||
// NOTE(yuval): Conversion to useconds
|
||||
result *= 1.0E-3;
|
||||
|
||||
u64 result = (u64)(now_nano * 1.0E-3);
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
@ -378,7 +377,10 @@ function
|
|||
system_wake_up_timer_create_sig(){
|
||||
Plat_Handle result = {};
|
||||
|
||||
NotImplemented;
|
||||
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.0
|
||||
target: view
|
||||
selector: @selector(requestDisplay)
|
||||
userInfo: nil repeats:NO];
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue