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
// 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 VERSION_NUMBER VN_(MAJOR,MINOR,PATCH)
#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;
}
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){
init_language_cpp(app);
}

View File

@ -125,10 +125,8 @@ Sys_Get_4ed_Path_Sig(system_get_4ed_path){
////////////////////////////////
internal void
system_schedule_step(){
// NOTE(allen): It is unclear to me right now what we might need to actually do here.
// 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.
system_schedule_step(void){
osx_schedule_step();
}
////////////////////////////////
@ -189,7 +187,9 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){
// 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
Sys_CLI_Call_Sig(system_cli_call){
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_write = pipe_fds[PIPE_FD_WRITE];
// TODO(allen): Getting updates when there is new something new on the pipe!?
++cli_count;
}
return(true);
@ -288,6 +288,8 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
close(*(int*)&cli->out_read);
close(*(int*)&cli->out_write);
--cli_count;
}
return(close_me);
@ -314,10 +316,10 @@ osx_free(void *ptr, umem size){
external void
osx_resize(int width, int height){
osx_objc.width = width;
osx_objc.height = height;
if (width > 0 && height > 0){
osx_objc.width = width;
osx_objc.height = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@ -326,6 +328,8 @@ osx_resize(int width, int height){
target.width = width;
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 0xF713: c = key_f16; break;
}
fprintf(stdout, "INPUT: %c\n", (char)code);
b8 mods[MDFR_INDEX_COUNT] = {0};
@ -411,19 +414,29 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
else{
osx_push_key(0, 0, 0, mods);
}
osx_schedule_step();
}
external void
osx_mouse(i32 mx, i32 my, u32 type){
osxvars.input.mouse.x = mx;
osxvars.input.mouse.y = osx_objc.height - my;
i32 new_x = mx;
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){
osxvars.input.mouse.press_l = true;
osxvars.input.mouse.l = true;
osx_schedule_step();
}
if (type == MouseType_Release){
osxvars.input.mouse.release_l = true;
osxvars.input.mouse.l = false;
osx_schedule_step();
}
}
@ -435,15 +448,18 @@ osx_mouse_wheel(float dx, float dy){
else if (dy < 0){
osxvars.input.mouse.wheel = -1;
}
osx_schedule_step();
}
external void
osx_try_to_close(void){
system_send_exit_signal();
osx_schedule_step();
}
external void
osx_step(void){
DBG_POINT();
Application_Step_Result result = {};
result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
result.trying_to_kill = !osxvars.keep_running;
@ -491,6 +507,10 @@ osx_step(void){
}
launch_rendering(&sysfunc, &target);
if (result.animating || cli_count > 0){
osx_schedule_step();
}
}
external void
@ -598,7 +618,6 @@ osx_init(){
DBG_POINT();
char cwd[4096];
u32 size = sysfunc.get_current_path(cwd, sizeof(cwd));
fprintf(stdout, "cwd = \"%.*s\"\n", size, cwd);
if (size == 0 || size >= sizeof(cwd)){
system_error_box("Could not get current directory at launch.");
}

View File

@ -15,7 +15,7 @@
#include "4coder_API/version.h"
#include "4coder_API/keycodes.h"
#define WINDOW_NAME "4coder" VERSION
#define WINDOW_NAME "4coder " VERSION
#undef internal
#undef global
@ -42,7 +42,7 @@ void
osx_post_to_clipboard(char *str){
NSPasteboard *board = [NSPasteboard generalPasteboard];
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];
NSString *paste_string = [NSString stringWithUTF8String:str];
[board setString:paste_string forType:utf8_type];
@ -68,10 +68,12 @@ osx_error_dialogue(char *str){
@interface My4coderView : NSOpenGLView{
@public
CVDisplayLinkRef displayLink;
//CVDisplayLinkRef displayLink;
}
- (CVReturn)getFrameForTime:(const CVTimeStamp*)time;
- (void)requestDisplay;
- (CVReturn)getFrame;
- (void)drawRect:(NSRect)bounds;
@end
#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{
NSPoint m = [event locationInWindow];
osx_mouse(m.x, m.y, MouseType_Press);
osx_mouse(m.x, m.y, MouseType_Press);
}
- (void)mouseDragged:(NSEvent*)event{
@ -132,7 +134,12 @@ static DISPLINK_SIG(osx_display_link);
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
{
if (osx_objc.running){
@ -232,6 +239,10 @@ static DISPLINK_SIG(osx_display_link);
return self;
}
- (void)drawRect: (NSRect) bounds{
[self getFrame];
}
- (void)awakeFromNib
{
[self init_gl];
@ -246,6 +257,7 @@ static DISPLINK_SIG(osx_display_link);
GLint swapInt = 1;
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
#if 0
CVReturn cvreturn = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
cvreturn = CVDisplayLinkSetOutputCallback(displayLink, &osx_display_link, (__bridge void*)(self));
@ -254,14 +266,17 @@ static DISPLINK_SIG(osx_display_link);
cvreturn = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
CVDisplayLinkStart(displayLink);
#endif
}
- (void)dealloc
{
[super dealloc];
#if 0
CVDisplayLinkStop(displayLink);
CVDisplayLinkRelease(displayLink);
#endif
}
- (BOOL)acceptsFirstResponder
@ -280,12 +295,14 @@ static DISPLINK_SIG(osx_display_link);
}
@end
#if 0
static
DISPLINK_SIG(osx_display_link){
My4coderView* view = (__bridge My4coderView*)context;
CVReturn result = [view getFrameForTime:output];
CVReturn result = [view getFrame];
return result;
}
#endif
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(id)sender
@ -507,7 +524,7 @@ osx_file_listener_hash_always(u64 hash, void *name, i32 fd){
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();
osx_file_listener_grow_table(1024);
}
@ -519,7 +536,7 @@ osx_add_file_listener(char *dir_name){
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);
if (fd <= 0){
@ -588,6 +605,21 @@ osx_get_file_change_event(char *buffer, i32 max, i32 *size){
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
osx_close_app(void){
[NSApp terminate: nil];
@ -620,7 +652,7 @@ main(int argc, char **argv){
[window setAcceptsMouseMovedEvents:YES];
My4coderView* view = [[My4coderView alloc] init];
view = [[My4coderView alloc] init];
[view setFrame:[[window contentView] bounds]];
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

View File

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