Implemented all system wake up timer functions.
parent
76069e9ac1
commit
dc213307a9
|
@ -83,13 +83,13 @@
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
typedef i32 Win32_Object_Kind;
|
||||
typedef i32 Mac_Object_Kind;
|
||||
enum{
|
||||
Win32ObjectKind_ERROR = 0,
|
||||
Win32ObjectKind_Timer = 1,
|
||||
Win32ObjectKind_Thread = 2,
|
||||
Win32ObjectKind_Mutex = 3,
|
||||
Win32ObjectKind_CV = 4,
|
||||
MacObjectKind_ERROR = 0,
|
||||
MacObjectKind_Timer = 1,
|
||||
MacObjectKind_Thread = 2,
|
||||
MacObjectKind_Mutex = 3,
|
||||
MacObjectKind_CV = 4,
|
||||
};
|
||||
|
||||
struct Mac_Object{
|
||||
|
@ -143,19 +143,19 @@ mac_alloc_object(Mac_Object_Kind kind){
|
|||
|
||||
if (!result){
|
||||
i32 count = 512;
|
||||
Mac_Object* objects = (Mac_Object*)system_memory_allocate(count * sizeof(Mac_Object), file_name_line_number);
|
||||
Mac_Object *objects = (Mac_Object*)system_memory_allocate(count * sizeof(Mac_Object), file_name_line_number_lit_u8);
|
||||
|
||||
// NOTE(yuval): Link the first chain of the dll to the sentinel
|
||||
// NOTE(yuval): Link the first node 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
|
||||
// NOTE(yuval): Link all dll nodes 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
|
||||
// NOTE(yuval): Link the last node 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;
|
||||
|
||||
|
@ -170,6 +170,14 @@ mac_alloc_object(Mac_Object_Kind kind){
|
|||
return(result);
|
||||
}
|
||||
|
||||
function
|
||||
mac_free_object(Mac_Object *object){
|
||||
if (object->node.next != 0){
|
||||
dll_remove(&object->node);
|
||||
}
|
||||
|
||||
dll_insert(&mac_vars.free_mac_objects, &object->node);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
|
|
|
@ -273,9 +273,6 @@ system_save_file_sig(){
|
|||
|
||||
i32 fd = open(file_name, O_WRONLY | O_TRUNC | O_CREAT, 00640);
|
||||
if (fd != -1) {
|
||||
u8* data_str = data.str;
|
||||
u64 data_size = data.size;
|
||||
|
||||
do{
|
||||
ssize_t bytes_written = write(fd, data.str, data.size);
|
||||
if (bytes_written == -1){
|
||||
|
@ -364,9 +361,9 @@ system_now_time_sig(){
|
|||
u64 now = mach_absolute_time();
|
||||
|
||||
// NOTE(yuval): Now time nanoseconds conversion
|
||||
f64 now_nano = (f64)(((f64)now) *
|
||||
((f64)mac_vars.timebase_info.numer) /
|
||||
((f64)mac_vars.timebase_info.denom));
|
||||
f64 now_nano = (f64)((f64)now *
|
||||
(f64)mac_vars.timebase_info.numer /
|
||||
(f64)mac_vars.timebase_info.denom);
|
||||
|
||||
// NOTE(yuval): Conversion to useconds
|
||||
u64 result = (u64)(now_nano * 1.0E-3);
|
||||
|
@ -375,24 +372,36 @@ system_now_time_sig(){
|
|||
|
||||
function
|
||||
system_wake_up_timer_create_sig(){
|
||||
Plat_Handle result = {};
|
||||
Mac_Object *object = mac_alloc_object(MacObjectKind_Timer);
|
||||
dll_insert(&mac_vars.timer_objects, &object->node);
|
||||
|
||||
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.0
|
||||
target: view
|
||||
selector: @selector(requestDisplay)
|
||||
userInfo: nil repeats:NO];
|
||||
object->timer.timer = nil;
|
||||
|
||||
Plat_Handle result = mac_to_plat_handle(object);
|
||||
return(result);
|
||||
}
|
||||
|
||||
function
|
||||
system_wake_up_timer_release_sig(){
|
||||
NotImplemented;
|
||||
Mac_Object *object = (Mac_Object*)mac_to_object(handle);
|
||||
if (object->kind == MacObjectKind_Timer){
|
||||
if ((object->timer != nil) && [object->timer isValid]) {
|
||||
[object->timer invalidate];
|
||||
mac_free_object(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function
|
||||
system_wake_up_timer_set_sig(){
|
||||
NotImplemented;
|
||||
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
|
||||
target: mac_vars.view
|
||||
selector: @selector(requestDisplay)
|
||||
userInfo: nil repeats:NO];
|
||||
}
|
||||
}
|
||||
|
||||
function
|
||||
|
|
Loading…
Reference in New Issue