working on Mac event limitted execution

master
Allen Webster 2017-11-07 19:18:57 -05:00
parent 772adc67a3
commit fccb93ccf9
5 changed files with 80 additions and 26 deletions

View File

@ -3,7 +3,7 @@
#define PATCH 22 #define PATCH 22
// string // string
#define VN__(a,b,c) #a"."#b"."#c #define VN__(a,b,c) #a "." #b "." #c
#define VN_(a,b,c) VN__(a,b,c) #define VN_(a,b,c) VN__(a,b,c)
#define VERSION_NUMBER VN_(MAJOR,MINOR,PATCH) #define VERSION_NUMBER VN_(MAJOR,MINOR,PATCH)
#define VERSION_STRING "alpha " VERSION_NUMBER #define VERSION_STRING "alpha " VERSION_NUMBER

View File

@ -120,7 +120,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
parse_context_id = parse_context_language_rust; parse_context_id = parse_context_language_rust;
} }
if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc")){ if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc") || match(ext, "glsl") || match(ext, "m")){
if (parse_context_language_cpp == 0){ if (parse_context_language_cpp == 0){
init_language_cpp(app); init_language_cpp(app);
} }

View File

@ -125,10 +125,8 @@ Sys_Get_4ed_Path_Sig(system_get_4ed_path){
//////////////////////////////// ////////////////////////////////
internal void internal void
system_schedule_step(){ system_schedule_step(void){
// NOTE(allen): It is unclear to me right now what we might need to actually do here. osx_schedule_step();
// The run loop in a Cocoa app will keep rendering the app anyway, I might just need to set a
// "do_new_frame" variable of some kind to true here.
} }
//////////////////////////////// ////////////////////////////////
@ -189,7 +187,9 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){
// CLI // CLI
// //
// HACK(allen): ALMOST an exact duplicate from the Linux version. Just epoll doesn't port. deduplicate. // HACK(allen): ALMOST an exact duplicate from the Linux version. Just epoll doesn't port. deduplicate or switch to NSTask.
global i32 cli_count = 0;
internal internal
Sys_CLI_Call_Sig(system_cli_call){ Sys_CLI_Call_Sig(system_cli_call){
i32 pipe_fds[2]; i32 pipe_fds[2];
@ -231,7 +231,7 @@ Sys_CLI_Call_Sig(system_cli_call){
*(int*)&cli_out->out_read = pipe_fds[PIPE_FD_READ]; *(int*)&cli_out->out_read = pipe_fds[PIPE_FD_READ];
*(int*)&cli_out->out_write = pipe_fds[PIPE_FD_WRITE]; *(int*)&cli_out->out_write = pipe_fds[PIPE_FD_WRITE];
// TODO(allen): Getting updates when there is new something new on the pipe!? ++cli_count;
} }
return(true); return(true);
@ -288,6 +288,8 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
close(*(int*)&cli->out_read); close(*(int*)&cli->out_read);
close(*(int*)&cli->out_write); close(*(int*)&cli->out_write);
--cli_count;
} }
return(close_me); return(close_me);
@ -314,10 +316,10 @@ osx_free(void *ptr, umem size){
external void external void
osx_resize(int width, int height){ osx_resize(int width, int height){
osx_objc.width = width;
osx_objc.height = height;
if (width > 0 && height > 0){ if (width > 0 && height > 0){
osx_objc.width = width;
osx_objc.height = height;
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -326,6 +328,8 @@ osx_resize(int width, int height){
target.width = width; target.width = width;
target.height = height; target.height = height;
osx_schedule_step();
} }
} }
@ -379,7 +383,6 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
case 0xF712: c = key_f15; break; case 0xF712: c = key_f15; break;
case 0xF713: c = key_f16; break; case 0xF713: c = key_f16; break;
} }
fprintf(stdout, "INPUT: %c\n", (char)code);
b8 mods[MDFR_INDEX_COUNT] = {0}; b8 mods[MDFR_INDEX_COUNT] = {0};
@ -411,19 +414,29 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
else{ else{
osx_push_key(0, 0, 0, mods); osx_push_key(0, 0, 0, mods);
} }
osx_schedule_step();
} }
external void external void
osx_mouse(i32 mx, i32 my, u32 type){ osx_mouse(i32 mx, i32 my, u32 type){
osxvars.input.mouse.x = mx; i32 new_x = mx;
osxvars.input.mouse.y = osx_objc.height - my; i32 new_y = osx_objc.height - my;
if (new_x != osxvars.input.mouse.x && new_y != osxvars.input.mouse.y){
osxvars.input.mouse.x = new_x;
osxvars.input.mouse.y = new_y;
osx_schedule_step();
}
if (type == MouseType_Press){ if (type == MouseType_Press){
osxvars.input.mouse.press_l = true; osxvars.input.mouse.press_l = true;
osxvars.input.mouse.l = true; osxvars.input.mouse.l = true;
osx_schedule_step();
} }
if (type == MouseType_Release){ if (type == MouseType_Release){
osxvars.input.mouse.release_l = true; osxvars.input.mouse.release_l = true;
osxvars.input.mouse.l = false; osxvars.input.mouse.l = false;
osx_schedule_step();
} }
} }
@ -435,15 +448,18 @@ osx_mouse_wheel(float dx, float dy){
else if (dy < 0){ else if (dy < 0){
osxvars.input.mouse.wheel = -1; osxvars.input.mouse.wheel = -1;
} }
osx_schedule_step();
} }
external void external void
osx_try_to_close(void){ osx_try_to_close(void){
system_send_exit_signal(); system_send_exit_signal();
osx_schedule_step();
} }
external void external void
osx_step(void){ osx_step(void){
DBG_POINT();
Application_Step_Result result = {}; Application_Step_Result result = {};
result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT; result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
result.trying_to_kill = !osxvars.keep_running; result.trying_to_kill = !osxvars.keep_running;
@ -491,6 +507,10 @@ osx_step(void){
} }
launch_rendering(&sysfunc, &target); launch_rendering(&sysfunc, &target);
if (result.animating || cli_count > 0){
osx_schedule_step();
}
} }
external void external void
@ -598,7 +618,6 @@ osx_init(){
DBG_POINT(); DBG_POINT();
char cwd[4096]; char cwd[4096];
u32 size = sysfunc.get_current_path(cwd, sizeof(cwd)); u32 size = sysfunc.get_current_path(cwd, sizeof(cwd));
fprintf(stdout, "cwd = \"%.*s\"\n", size, cwd);
if (size == 0 || size >= sizeof(cwd)){ if (size == 0 || size >= sizeof(cwd)){
system_error_box("Could not get current directory at launch."); system_error_box("Could not get current directory at launch.");
} }

View File

@ -15,7 +15,7 @@
#include "4coder_API/version.h" #include "4coder_API/version.h"
#include "4coder_API/keycodes.h" #include "4coder_API/keycodes.h"
#define WINDOW_NAME "4coder" VERSION #define WINDOW_NAME "4coder " VERSION
#undef internal #undef internal
#undef global #undef global
@ -42,7 +42,7 @@ void
osx_post_to_clipboard(char *str){ osx_post_to_clipboard(char *str){
NSPasteboard *board = [NSPasteboard generalPasteboard]; NSPasteboard *board = [NSPasteboard generalPasteboard];
NSString *utf8_type = @"public.utf8-plain-text"; NSString *utf8_type = @"public.utf8-plain-text";
NSArray<NSString*> *typesArray = [NSArray arrayWithObjects: utf8_type, nil]; NSArray<NSString*> *typesArray = [NSArray arrayWithObjects: utf8_type, nil];
[board declareTypes:typesArray owner:nil]; [board declareTypes:typesArray owner:nil];
NSString *paste_string = [NSString stringWithUTF8String:str]; NSString *paste_string = [NSString stringWithUTF8String:str];
[board setString:paste_string forType:utf8_type]; [board setString:paste_string forType:utf8_type];
@ -68,10 +68,12 @@ osx_error_dialogue(char *str){
@interface My4coderView : NSOpenGLView{ @interface My4coderView : NSOpenGLView{
@public @public
CVDisplayLinkRef displayLink; //CVDisplayLinkRef displayLink;
} }
- (CVReturn)getFrameForTime:(const CVTimeStamp*)time; - (void)requestDisplay;
- (CVReturn)getFrame;
- (void)drawRect:(NSRect)bounds;
@end @end
#define DISPLINK_SIG(n) CVReturn n(CVDisplayLinkRef link, const CVTimeStamp *now, const CVTimeStamp *output, CVOptionFlags flags_in, CVOptionFlags *flags_out, void *context) #define DISPLINK_SIG(n) CVReturn n(CVDisplayLinkRef link, const CVTimeStamp *now, const CVTimeStamp *output, CVOptionFlags flags_in, CVOptionFlags *flags_out, void *context)
@ -103,7 +105,7 @@ static DISPLINK_SIG(osx_display_link);
- (void)mouseDown:(NSEvent*)event{ - (void)mouseDown:(NSEvent*)event{
NSPoint m = [event locationInWindow]; NSPoint m = [event locationInWindow];
osx_mouse(m.x, m.y, MouseType_Press); osx_mouse(m.x, m.y, MouseType_Press);
} }
- (void)mouseDragged:(NSEvent*)event{ - (void)mouseDragged:(NSEvent*)event{
@ -132,7 +134,12 @@ static DISPLINK_SIG(osx_display_link);
return(NO); return(NO);
} }
- (CVReturn)getFrameForTime:(const CVTimeStamp*)time{ - (void)requestDisplay{
NSRect rect = CGRectMake(0, 0, osx_objc.width, osx_objc.height);
[self setNeedsDisplayInRect:rect];
}
- (CVReturn)getFrame{
@autoreleasepool @autoreleasepool
{ {
if (osx_objc.running){ if (osx_objc.running){
@ -232,6 +239,10 @@ static DISPLINK_SIG(osx_display_link);
return self; return self;
} }
- (void)drawRect: (NSRect) bounds{
[self getFrame];
}
- (void)awakeFromNib - (void)awakeFromNib
{ {
[self init_gl]; [self init_gl];
@ -246,6 +257,7 @@ static DISPLINK_SIG(osx_display_link);
GLint swapInt = 1; GLint swapInt = 1;
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
#if 0
CVReturn cvreturn = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); CVReturn cvreturn = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
cvreturn = CVDisplayLinkSetOutputCallback(displayLink, &osx_display_link, (__bridge void*)(self)); cvreturn = CVDisplayLinkSetOutputCallback(displayLink, &osx_display_link, (__bridge void*)(self));
@ -254,14 +266,17 @@ static DISPLINK_SIG(osx_display_link);
cvreturn = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat); cvreturn = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
CVDisplayLinkStart(displayLink); CVDisplayLinkStart(displayLink);
#endif
} }
- (void)dealloc - (void)dealloc
{ {
[super dealloc]; [super dealloc];
#if 0
CVDisplayLinkStop(displayLink); CVDisplayLinkStop(displayLink);
CVDisplayLinkRelease(displayLink); CVDisplayLinkRelease(displayLink);
#endif
} }
- (BOOL)acceptsFirstResponder - (BOOL)acceptsFirstResponder
@ -280,12 +295,14 @@ static DISPLINK_SIG(osx_display_link);
} }
@end @end
#if 0
static static
DISPLINK_SIG(osx_display_link){ DISPLINK_SIG(osx_display_link){
My4coderView* view = (__bridge My4coderView*)context; My4coderView* view = (__bridge My4coderView*)context;
CVReturn result = [view getFrameForTime:output]; CVReturn result = [view getFrame];
return result; return result;
} }
#endif
@implementation AppDelegate @implementation AppDelegate
- (void)applicationDidFinishLaunching:(id)sender - (void)applicationDidFinishLaunching:(id)sender
@ -507,7 +524,7 @@ osx_file_listener_hash_always(u64 hash, void *name, i32 fd){
void void
osx_file_listener_init(void){ osx_file_listener_init(void){
memset(&file_change_queue, 0, sizeof(file_change_queue)); memset(&file_change_queue, 0, sizeof(file_change_queue));
file_change_queue.kq = kqueue(); file_change_queue.kq = kqueue();
osx_file_listener_grow_table(1024); osx_file_listener_grow_table(1024);
} }
@ -519,7 +536,7 @@ osx_add_file_listener(char *dir_name){
return; return;
} }
fprintf(stdout, "ADD_FILE_LISTENER: %s\n", dir_name); //fprintf(stdout, "ADD_FILE_LISTENER: %s\n", dir_name);
i32 fd = open(dir_name, O_EVTONLY); i32 fd = open(dir_name, O_EVTONLY);
if (fd <= 0){ if (fd <= 0){
@ -588,6 +605,21 @@ osx_get_file_change_event(char *buffer, i32 max, i32 *size){
return(result); return(result);
} }
My4coderView* view = 0;
void
osx_schedule_step(void){
//DBG_POINT();
#if 1
[NSTimer scheduledTimerWithTimeInterval: 0.0
target: view
selector: @selector(requestDisplay)
userInfo: nil repeats:NO];
#else
[view requestDisplay];
#endif
}
void void
osx_close_app(void){ osx_close_app(void){
[NSApp terminate: nil]; [NSApp terminate: nil];
@ -620,7 +652,7 @@ main(int argc, char **argv){
[window setAcceptsMouseMovedEvents:YES]; [window setAcceptsMouseMovedEvents:YES];
My4coderView* view = [[My4coderView alloc] init]; view = [[My4coderView alloc] init];
[view setFrame:[[window contentView] bounds]]; [view setFrame:[[window contentView] bounds]];
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

View File

@ -14,7 +14,7 @@
#include <stdio.h> #include <stdio.h>
#if 0 #if 1
#define DBG_POINT() fprintf(stdout, "%s\n", __FILE__ ":" LINE_STR ":") #define DBG_POINT() fprintf(stdout, "%s\n", __FILE__ ":" LINE_STR ":")
#else #else
#define DBG_POINT() #define DBG_POINT()
@ -102,6 +102,9 @@ osx_remove_file_listener(char *file_name);
external i32 external i32
osx_get_file_change_event(char *buffer, i32 max, i32 *size); osx_get_file_change_event(char *buffer, i32 max, i32 *size);
external void
osx_schedule_step(void);
external void external void
osx_close_app(void); osx_close_app(void);