2
0
luboslenco 1 сар өмнө
parent
commit
ab43bb25e7

+ 1 - 11
base/sources/backends/android_system.c

@@ -1111,19 +1111,9 @@ void android_main(struct android_app *application) {
 	(*activity->vm)->DetachCurrentThread(activity->vm);
 }
 
-void iron_init(const char *name, int width, int height, struct iron_window_options *win) {
+void iron_init(iron_window_options_t *win) {
 	iron_mutex_init(&unicode_mutex);
-
-	iron_window_options_t default_win;
-	if (win == NULL) {
-		iron_window_options_set_defaults(&default_win);
-		win = &default_win;
-	}
-	win->width = width;
-	win->height = height;
-
 	gpu_init(win->depth_bits, true);
-
 	#ifdef WITH_GAMEPAD
 	iron_internal_gamepad_trigger_connect(0);
 	#endif

+ 3 - 4
base/sources/backends/apple_video.m

@@ -9,8 +9,7 @@
 // #include <stdlib.h>
 // #include <string.h>
 
-// extern const char *iphonegetresourcepath(void);
-// extern const char *macgetresourcepath(void);
+// extern const char *iron_get_resource_path(void);
 
 // void iron_internal_video_sound_stream_init(iron_internal_video_sound_stream_t *stream, int channel_count, int frequency) {
 // 	stream->bufferSize = 1024 * 100;
@@ -126,9 +125,9 @@
 // 	video->impl.image_initialized = false;
 // 	char name[2048];
 // #ifdef IRON_IOS
-// 	strcpy(name, iphonegetresourcepath());
+// 	strcpy(name, iron_get_resource_path());
 // #else
-// 	strcpy(name, macgetresourcepath());
+// 	strcpy(name, iron_get_resource_path());
 // #endif
 // 	strcat(name, "/");
 // 	strcat(name, IRON_OUTDIR);

+ 6 - 15
base/sources/backends/ios_system.h

@@ -7,23 +7,14 @@
 @interface MyView : UIView <UIKeyInput> {
 @private
 	id<MTLDevice> device;
-	id<MTLCommandQueue> commandQueue;
-	id<MTLCommandBuffer> commandBuffer;
-	id<MTLRenderCommandEncoder> commandEncoder;
-	id<CAMetalDrawable> drawable;
+	id<MTLCommandQueue> queue;
 	id<MTLLibrary> library;
-	MTLRenderPassDescriptor *renderPassDescriptor;
-	CMMotionManager *motionManager;
-	bool hasAccelerometer;
-	float lastAccelerometerX, lastAccelerometerY, lastAccelerometerZ;
 }
-- (void)begin;
-- (void)end;
-- (void)showKeyboard;
-- (void)hideKeyboard;
-- (CAMetalLayer *)metalLayer;
-- (id<MTLDevice>)metalDevice;
-- (id<MTLCommandQueue>)metalQueue;
+- (void)show_keyboard;
+- (void)hide_keyboard;
+- (CAMetalLayer *)metal_layer;
+- (id<MTLDevice>)metal_device;
+- (id<MTLCommandQueue>)metal_queue;
 - (BOOL)hasText;
 - (void)insertText:(NSString *)text;
 - (void)deleteBackward;

+ 207 - 237
base/sources/backends/ios_system.m

@@ -8,16 +8,16 @@
 #import <Foundation/Foundation.h>
 #import <UIKit/UIKit.h>
 
-#define touchmaxcount 20
+#define MAX_TOUCH_COUNT 10
 
 extern char mobile_title[1024];
-static void *touches[touchmaxcount];
+static void *touches[MAX_TOUCH_COUNT];
 static int backing_width;
 static int backing_height;
 static bool shift_down = false;
 static bool visible;
-static MyView *myView;
-static MyViewController *myViewController;
+static MyView *my_view;
+static MyViewController *my_view_controller;
 static bool keyboard_shown = false;
 static char language[3];
 static char sysid[512];
@@ -25,10 +25,14 @@ static const char *video_formats[] = {"mp4", NULL};
 static void (*resize_callback)(int x, int y, void *data) = NULL;
 static void *resize_callback_data = NULL;
 
-void iron_internal_call_resize_callback(int width, int height);
+void iron_internal_call_resize_callback(int width, int height) {
+	if (resize_callback != NULL) {
+		resize_callback(width, height, resize_callback_data);
+	}
+}
 
 static int get_touch_index(void *touch) {
-	for (int i = 0; i < touchmaxcount; ++i) {
+	for (int i = 0; i < MAX_TOUCH_COUNT; ++i) {
 		if (touches[i] == touch) {
 			return i;
 		}
@@ -37,7 +41,7 @@ static int get_touch_index(void *touch) {
 }
 
 static int add_touch(void *touch) {
-	for (int i = 0; i < touchmaxcount; ++i) {
+	for (int i = 0; i < MAX_TOUCH_COUNT; ++i) {
 		if (touches[i] == NULL) {
 			touches[i] = touch;
 			return i;
@@ -47,7 +51,7 @@ static int add_touch(void *touch) {
 }
 
 static int remove_touch(void *touch) {
-	for (int i = 0; i < touchmaxcount; ++i) {
+	for (int i = 0; i < MAX_TOUCH_COUNT; ++i) {
 		if (touches[i] == touch) {
 			touches[i] = NULL;
 			return i;
@@ -64,6 +68,180 @@ int iron_window_height() {
 	return backing_height;
 }
 
+CAMetalLayer *get_metal_layer(void) {
+	return [my_view metal_layer];
+}
+
+id get_metal_device(void) {
+	return [my_view metal_device];
+}
+
+id get_metal_queue(void) {
+	return [my_view metal_queue];
+}
+
+void iron_display_init(void) {}
+
+iron_display_mode_t iron_display_current_mode(int display) {
+	iron_display_mode_t dm;
+	dm.width = iron_window_width();
+	dm.height = iron_window_height();
+	dm.frequency = (int)[[UIScreen mainScreen] maximumFramesPerSecond];
+	dm.bits_per_pixel = 32;
+	return dm;
+}
+
+int iron_count_displays(void) {
+	return 1;
+}
+
+int iron_primary_display(void) {
+	return 0;
+}
+
+void iron_internal_mouse_lock(void) {}
+void iron_internal_mouse_unlock(void) {}
+
+bool iron_mouse_can_lock(void) {
+	return false;
+}
+
+void iron_mouse_show(void) {}
+void iron_mouse_hide(void) {}
+void iron_mouse_set_position(int x, int y) {}
+void iron_mouse_get_position(int *x, int *y) {}
+void iron_mouse_set_cursor(int cursor_index) {}
+
+bool with_autoreleasepool(bool (*f)(void)) {
+	@autoreleasepool {
+		return f();
+	}
+}
+
+const char *iron_get_resource_path(void) {
+	return [[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:1];
+}
+
+bool iron_internal_handle_messages(void) {
+	SInt32 result;
+	do {
+		result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
+	} while (result == kCFRunLoopRunHandledSource);
+	return true;
+}
+
+void iron_set_keep_screen_on(bool on) {}
+
+void iron_keyboard_show(void) {
+	keyboard_shown = true;
+	[my_view show_keyboard];
+}
+
+void iron_keyboard_hide(void) {
+	keyboard_shown = false;
+	[my_view hide_keyboard];
+}
+
+bool iron_keyboard_active(void) {
+	return keyboard_shown;
+}
+
+void iron_load_url(const char *url) {
+	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
+}
+
+const char *iron_language(void) {
+	NSString *nsstr = [[NSLocale preferredLanguages] objectAtIndex:0];
+	const char *lang = [nsstr UTF8String];
+	language[0] = lang[0];
+	language[1] = lang[1];
+	language[2] = 0;
+	return language;
+}
+
+void iron_internal_shutdown(void) {}
+
+void iron_init(iron_window_options_t *win) {
+	gpu_init(win->depth_bits, true);
+}
+
+const char *iron_system_id(void) {
+	const char *name = [[[UIDevice currentDevice] name] UTF8String];
+	const char *vendorId = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] UTF8String];
+	strcpy(sysid, name);
+	strcat(sysid, "-");
+	strcat(sysid, vendorId);
+	return sysid;
+}
+
+const char *iron_internal_save_path(void) {
+	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+	NSString *resolvedPath = [paths objectAtIndex:0];
+	NSString *appName = [NSString stringWithUTF8String:iron_application_name()];
+	resolvedPath = [resolvedPath stringByAppendingPathComponent:appName];
+	NSFileManager *fileMgr = [[NSFileManager alloc] init];
+	NSError *error;
+	[fileMgr createDirectoryAtPath:resolvedPath withIntermediateDirectories:YES attributes:nil error:&error];
+	resolvedPath = [resolvedPath stringByAppendingString:@"/"];
+	return [resolvedPath cStringUsingEncoding:1];
+}
+
+const char **iron_video_formats(void) {
+	return video_formats;
+}
+
+double iron_frequency(void) {
+	mach_timebase_info_data_t info;
+	mach_timebase_info(&info);
+	return (double)info.denom / (double)info.numer / 1e-9;
+}
+
+uint64_t iron_timestamp(void) {
+	uint64_t time = mach_absolute_time();
+	return time;
+}
+
+int main(int argc, char *argv[]) {
+	int res = 0;
+	@autoreleasepool {
+		[IronSceneDelegate description]; // otherwise removed by the linker
+		res = UIApplicationMain(argc, argv, nil, nil);
+	}
+	return res;
+}
+
+int iron_window_x() {
+	return 0;
+}
+
+int iron_window_y() {
+	return 0;
+}
+
+void iron_window_resize(int width, int height) {}
+void iron_window_move(int x, int y) {}
+void iron_window_change_mode(iron_window_mode_t mode) {}
+void iron_window_destroy() {}
+void iron_window_show() {}
+void iron_window_hide() {}
+void iron_window_set_title(const char *title) {}
+void iron_window_create(iron_window_options_t *win) {}
+
+void iron_window_set_resize_callback(void (*callback)(int x, int y, void *data), void *data) {
+	resize_callback = callback;
+	resize_callback_data = data;
+}
+
+void iron_window_set_close_callback(bool (*callback)(void *), void *data) {}
+
+iron_window_mode_t iron_window_get_mode() {
+	return IRON_WINDOW_MODE_FULLSCREEN;
+}
+
+int iron_window_display() {
+	return 0;
+}
+
 @implementation MyView
 
 + (Class)layerClass {
@@ -83,33 +261,28 @@ int iron_window_height() {
 	backing_width = frame.size.width * self.contentScaleFactor;
 	backing_height = frame.size.height * self.contentScaleFactor;
 
-	for (int i = 0; i < touchmaxcount; ++i) {
+	for (int i = 0; i < MAX_TOUCH_COUNT; ++i) {
 		touches[i] = NULL;
 	}
 
 	device = MTLCreateSystemDefaultDevice();
-	commandQueue = [device newCommandQueue];
+	queue = [device newCommandQueue];
 	library = [device newDefaultLibrary];
 
-	CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
-	metalLayer.device = device;
-	metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
-	metalLayer.framebufferOnly = YES;
-	metalLayer.opaque = YES;
-	metalLayer.backgroundColor = nil;
+	CAMetalLayer *layer = (CAMetalLayer *)self.layer;
+	layer.device = device;
+	layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
+	layer.framebufferOnly = YES;
+	layer.opaque = YES;
+	layer.backgroundColor = nil;
 
 	[self addGestureRecognizer:[[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverGesture:)]];
 	return self;
 }
 
-- (void)begin {}
-- (void)end {}
-- (void)dealloc {}
-
 - (void)layoutSubviews {
 	backing_width = self.frame.size.width * self.contentScaleFactor;
 	backing_height = self.frame.size.height * self.contentScaleFactor;
-
 	gpu_resize(backing_width, backing_height);
 	iron_internal_call_resize_callback(backing_width, backing_height);
 }
@@ -197,11 +370,11 @@ int iron_window_height() {
 	}
 }
 
-- (void)showKeyboard {
+- (void)show_keyboard {
 	[self becomeFirstResponder];
 }
 
-- (void)hideKeyboard {
+- (void)hide_keyboard {
 	[self resignFirstResponder];
 }
 
@@ -277,45 +450,25 @@ int iron_window_height() {
 	iron_keyboard_hide();
 }
 
-- (CAMetalLayer *)metalLayer {
+- (CAMetalLayer *)metal_layer {
 	return (CAMetalLayer *)self.layer;
 }
 
-- (id<MTLDevice>)metalDevice {
+- (id<MTLDevice>)metal_device {
 	return device;
 }
 
-- (id<MTLCommandQueue>)metalQueue {
-	return commandQueue;
+- (id<MTLCommandQueue>)metal_queue {
+	return queue;
 }
 
 @end
 
-void showKeyboard(void) {
-	[myView showKeyboard];
-}
-
-void hideKeyboard(void) {
-	[myView hideKeyboard];
-}
-
-CAMetalLayer *getMetalLayer(void) {
-	return [myView metalLayer];
-}
-
-id getMetalDevice(void) {
-	return [myView metalDevice];
-}
-
-id getMetalQueue(void) {
-	return [myView metalQueue];
-}
-
 @implementation MyViewController
 
 - (void)loadView {
 	visible = true;
-	self.view = myView = [[MyView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+	self.view = my_view = [[MyView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 	[self.view addInteraction: [[UIDropInteraction alloc] initWithDelegate: self]];
 	[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
 }
@@ -352,8 +505,8 @@ void importFile(NSURL *url) {
 
 - (void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id<UIDropSession>)session {
 	CGPoint point = [session locationInView:self.view];
-	float x = point.x * myView.contentScaleFactor;
-	float y = point.y * myView.contentScaleFactor;
+	float x = point.x * my_view.contentScaleFactor;
+	float y = point.y * my_view.contentScaleFactor;
 	iron_internal_mouse_trigger_move(x, y);
 	iron_internal_surface_trigger_move(0, x, y);
 	for (UIDragItem *item in session.items) {
@@ -375,10 +528,6 @@ void importFile(NSURL *url) {
 
 @implementation IronSceneDelegate
 
-void loadURL(const char *url) {
-	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
-}
-
 - (void)mainLoop {
 	@autoreleasepool {
 		kickstart(0, NULL);
@@ -395,22 +544,18 @@ void loadURL(const char *url) {
 
 	UIWindowScene *windowScene = (UIWindowScene *)scene;
     self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
-    // self.window.frame = windowScene.coordinateSpace.bounds;
 	self.window.frame = [UIScreen mainScreen].bounds;
     [self.window setBackgroundColor:[UIColor blackColor]];
 
-	myViewController = [[MyViewController alloc] init];
-	myViewController.view.multipleTouchEnabled = YES;
-	[self.window setRootViewController:myViewController];
+	my_view_controller = [[MyViewController alloc] init];
+	my_view_controller.view.multipleTouchEnabled = YES;
+	[self.window setRootViewController:my_view_controller];
 	[self.window makeKeyAndVisible];
-
-	[myViewController setVisible:YES];
-    // iron_internal_foreground_callback();
+	[my_view_controller setVisible:YES];
 	[self performSelectorOnMainThread:@selector(mainLoop) withObject:nil waitUntilDone:NO];
 }
 
 - (void)sceneDidDisconnect:(UIScene *)scene {
-	[myViewController setVisible:NO];
 	iron_internal_shutdown_callback();
 }
 
@@ -423,190 +568,15 @@ void loadURL(const char *url) {
 }
 
 - (void)sceneWillEnterForeground:(UIScene *)scene {
-	[myViewController setVisible:YES];
     iron_internal_foreground_callback();
 }
 
 - (void)sceneDidEnterBackground:(UIScene *)scene {
-	[myViewController setVisible:NO];
     iron_internal_background_callback();
 }
 
 @end
 
-void iron_display_init(void) {}
-
-iron_display_mode_t iron_display_current_mode(int display) {
-	iron_display_mode_t dm;
-	dm.width = iron_window_width();
-	dm.height = iron_window_height();
-	dm.frequency = (int)[[UIScreen mainScreen] maximumFramesPerSecond];
-	dm.bits_per_pixel = 32;
-	return dm;
-}
-
-int iron_count_displays(void) {
-	return 1;
-}
-
-int iron_primary_display(void) {
-	return 0;
-}
-
-void iron_internal_mouse_lock(void) {}
-void iron_internal_mouse_unlock(void) {}
-
-bool iron_mouse_can_lock(void) {
-	return false;
-}
-
-void iron_mouse_show(void) {}
-void iron_mouse_hide(void) {}
-void iron_mouse_set_position(int x, int y) {}
-void iron_mouse_get_position(int *x, int *y) {}
-void iron_mouse_set_cursor(int cursor_index) {}
-
-bool with_autoreleasepool(bool (*f)(void)) {
-	@autoreleasepool {
-		return f();
-	}
-}
-
-const char *iphonegetresourcepath(void) {
-	return [[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:1];
-}
-
-bool iron_internal_handle_messages(void) {
-	SInt32 result;
-	do {
-		result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
-	} while (result == kCFRunLoopRunHandledSource);
-	return true;
-}
-
-void iron_set_keep_screen_on(bool on) {}
-
-void iron_keyboard_show(void) {
-	keyboard_shown = true;
-	showKeyboard();
-}
-
-void iron_keyboard_hide(void) {
-	keyboard_shown = false;
-	hideKeyboard();
-}
-
-bool iron_keyboard_active(void) {
-	return keyboard_shown;
-}
-
-void iron_load_url(const char *url) {
-	loadURL(url);
-}
-
-const char *iron_language(void) {
-	NSString *nsstr = [[NSLocale preferredLanguages] objectAtIndex:0];
-	const char *lang = [nsstr UTF8String];
-	language[0] = lang[0];
-	language[1] = lang[1];
-	language[2] = 0;
-	return language;
-}
-
-void iron_internal_shutdown(void) {}
-
-void iron_init(const char *name, int width, int height, struct iron_window_options *win) {
-	iron_window_options_t default_win;
-	if (win == NULL) {
-		iron_window_options_set_defaults(&default_win);
-		win = &default_win;
-	}
-	gpu_init(win->depth_bits, true);
-}
-
-const char *iron_system_id(void) {
-	const char *name = [[[UIDevice currentDevice] name] UTF8String];
-	const char *vendorId = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] UTF8String];
-	strcpy(sysid, name);
-	strcat(sysid, "-");
-	strcat(sysid, vendorId);
-	return sysid;
-}
-
-const char *iron_internal_save_path(void) {
-	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
-	NSString *resolvedPath = [paths objectAtIndex:0];
-	NSString *appName = [NSString stringWithUTF8String:iron_application_name()];
-	resolvedPath = [resolvedPath stringByAppendingPathComponent:appName];
-	NSFileManager *fileMgr = [[NSFileManager alloc] init];
-	NSError *error;
-	[fileMgr createDirectoryAtPath:resolvedPath withIntermediateDirectories:YES attributes:nil error:&error];
-	resolvedPath = [resolvedPath stringByAppendingString:@"/"];
-	return [resolvedPath cStringUsingEncoding:1];
-}
-
-const char **iron_video_formats(void) {
-	return video_formats;
-}
-
-double iron_frequency(void) {
-	mach_timebase_info_data_t info;
-	mach_timebase_info(&info);
-	return (double)info.denom / (double)info.numer / 1e-9;
-}
-
-uint64_t iron_timestamp(void) {
-	uint64_t time = mach_absolute_time();
-	return time;
-}
-
-int main(int argc, char *argv[]) {
-	int res = 0;
-	@autoreleasepool {
-		[IronSceneDelegate description]; // otherwise removed by the linker
-		res = UIApplicationMain(argc, argv, nil, nil);
-	}
-	return res;
-}
-
-int iron_window_x() {
-	return 0;
-}
-
-int iron_window_y() {
-	return 0;
-}
-
-void iron_window_resize(int width, int height) {}
-void iron_window_move(int x, int y) {}
-void iron_window_change_mode(iron_window_mode_t mode) {}
-void iron_window_destroy() {}
-void iron_window_show() {}
-void iron_window_hide() {}
-void iron_window_set_title(const char *title) {}
-void iron_window_create(iron_window_options_t *win) {}
-
-void iron_window_set_resize_callback(void (*callback)(int x, int y, void *data), void *data) {
-	resize_callback = callback;
-	resize_callback_data = data;
-}
-
-void iron_internal_call_resize_callback(int width, int height) {
-	if (resize_callback != NULL) {
-		resize_callback(width, height, resize_callback_data);
-	}
-}
-
-void iron_window_set_close_callback(bool (*callback)(void *), void *data) {}
-
-iron_window_mode_t iron_window_get_mode() {
-	return IRON_WINDOW_MODE_FULLSCREEN;
-}
-
-int iron_window_display() {
-	return 0;
-}
-
 #ifdef WITH_GAMEPAD
 
 const char *iron_gamepad_vendor(int gamepad) {

+ 3 - 18
base/sources/backends/linux_system.c

@@ -216,8 +216,7 @@ void iron_window_hide() {
 	xlib.XUnmapWindow(x11_ctx.display, window->window);
 }
 
-void iron_window_set_title(const char *_title) {
-	const char *title = _title == NULL ? "" : _title;
+void iron_window_set_title(const char *title) {
 	struct iron_x11_window *window = &x11_ctx.windows[0];
 	xlib.XChangeProperty(x11_ctx.display, window->window, x11_ctx.atoms.NET_WM_NAME, x11_ctx.atoms.UTF8_STRING, 8, PropModeReplace, (unsigned char *)title, strlen(title));
 	xlib.XChangeProperty(x11_ctx.display, window->window, x11_ctx.atoms.NET_WM_ICON_NAME, x11_ctx.atoms.UTF8_STRING, 8, PropModeReplace, (unsigned char *)title, strlen(title));
@@ -1095,28 +1094,14 @@ uint64_t iron_timestamp(void) {
 	return (uint64_t)now.tv_sec * 1000000 + (uint64_t)now.tv_usec;
 }
 
-void iron_init(const char *name, int width, int height, iron_window_options_t *win) {
+void iron_init(iron_window_options_t *win) {
 	gettimeofday(&start, NULL);
-
 	#ifdef WITH_GAMEPAD
 	iron_linux_initHIDGamepads();
 	#endif
-
 	iron_x11_init();
 	iron_display_init();
-	iron_set_app_name(name);
-
-	iron_window_options_t defaultWin;
-	if (win == NULL) {
-		iron_window_options_set_defaults(&defaultWin);
-		win = &defaultWin;
-	}
-	win->width = width;
-	win->height = height;
-	if (win->title == NULL) {
-		win->title = name;
-	}
-
+	iron_set_app_name(win->title);
 	iron_window_create(win);
 }
 

+ 5 - 17
base/sources/backends/macos_system.m

@@ -898,7 +898,7 @@ bool with_autoreleasepool(bool (*f)(void)) {
 	}
 }
 
-const char *macgetresourcepath(void) {
+const char *iron_get_resource_path(void) {
 	return [[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:NSUTF8StringEncoding];
 }
 
@@ -919,15 +919,15 @@ const char *macgetresourcepath(void) {
 
 static IronAppDelegate *delegate;
 
-CAMetalLayer *getMetalLayer(void) {
+CAMetalLayer *get_metal_layer(void) {
 	return [view metalLayer];
 }
 
-id getMetalDevice(void) {
+id get_metal_device(void) {
 	return [view metalDevice];
 }
 
-id getMetalQueue(void) {
+id get_metal_queue(void) {
 	return [view metalQueue];
 }
 
@@ -1018,7 +1018,7 @@ static void add_menubar(void) {
 	[NSApp setMainMenu:menubar];
 }
 
-void iron_init(const char *name, int width, int height, iron_window_options_t *win) {
+void iron_init(iron_window_options_t *win) {
 	@autoreleasepool {
 		myapp = [IronApplication sharedApplication];
 		[myapp finishLaunching];
@@ -1032,18 +1032,6 @@ void iron_init(const char *name, int width, int height, iron_window_options_t *w
 		#endif
 	}
 
-	iron_window_options_t defaultWindowOptions;
-	if (win == NULL) {
-		iron_window_options_set_defaults(&defaultWindowOptions);
-		win = &defaultWindowOptions;
-	}
-
-	win->width = width;
-	win->height = height;
-	if (win->title == NULL) {
-		win->title = name;
-	}
-
 	createWindow(win);
 	gpu_init(win->depth_bits, true);
 }

+ 23 - 23
base/sources/backends/metal_gpu.m

@@ -7,9 +7,9 @@
 #import <Metal/Metal.h>
 #import <MetalKit/MTKView.h>
 
-id getMetalLayer(void);
-id getMetalDevice(void);
-id getMetalQueue(void);
+id get_metal_layer(void);
+id get_metal_device(void);
+id get_metal_queue(void);
 
 bool gpu_transpose_mat = true;
 static id<MTLCommandBuffer> command_buffer = nil;
@@ -101,7 +101,7 @@ void gpu_render_target_init2(gpu_texture_t *target, int width, int height, gpu_t
 	target->buffer = NULL;
 
 	if (framebuffer_index < 0) {
-		id<MTLDevice> device = getMetalDevice();
+		id<MTLDevice> device = get_metal_device();
 		MTLTextureDescriptor *descriptor = [MTLTextureDescriptor new];
 		descriptor.textureType = MTLTextureType2D;
 		descriptor.width = width;
@@ -126,13 +126,13 @@ void gpu_resize_internal(int width, int height) {
 }
 
 static void next_drawable() {
-	CAMetalLayer *layer = getMetalLayer();
+	CAMetalLayer *layer = get_metal_layer();
 	drawable = [layer nextDrawable];
 	framebuffers[framebuffer_index].impl._tex = (__bridge void *)drawable.texture;
 }
 
 void gpu_init_internal(int depth_buffer_bits, bool vsync) {
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 
     MTLSamplerDescriptor *linear_desc = [MTLSamplerDescriptor new];
     linear_desc.minFilter = MTLSamplerMinMagFilterLinear;
@@ -201,7 +201,7 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t *depth
 		render_pass_desc.depthAttachment.storeAction = MTLStoreActionStore;
 	}
 
-	id<MTLCommandQueue> queue = getMetalQueue();
+	id<MTLCommandQueue> queue = get_metal_queue();
 
 	if (command_buffer == nil) {
 		command_buffer = [queue commandBuffer];
@@ -234,7 +234,7 @@ void gpu_execute_and_wait() {
 
 	[command_buffer commit];
 	gpu_wait();
-	id<MTLCommandQueue> queue = getMetalQueue();
+	id<MTLCommandQueue> queue = get_metal_queue();
 	command_buffer = [queue commandBuffer];
 
 	if (gpu_in_use) {
@@ -266,7 +266,7 @@ void gpu_present_internal() {
 	command_encoder = nil;
 
 	if (resized) {
-		CAMetalLayer *layer = getMetalLayer();
+		CAMetalLayer *layer = get_metal_layer();
 		layer.drawableSize = CGSizeMake(iron_window_width(), iron_window_height());
 		for (int i = 0; i < GPU_FRAMEBUFFER_COUNT; ++i) {
 			// gpu_texture_destroy(&framebuffers[i]);
@@ -355,12 +355,12 @@ void gpu_get_render_target_pixels(gpu_texture_t *render_target, uint8_t *data) {
 			id<MTLTexture> readback = (__bridge_transfer id<MTLTexture>)readback_buffer;
 			readback = nil;
 		}
-		id<MTLDevice> device = getMetalDevice();
+		id<MTLDevice> device = get_metal_device();
 		readback_buffer = (__bridge_retained void *)[device newBufferWithLength:buffer_size options:MTLResourceStorageModeShared];
 	}
 
 	// Copy render target to readback buffer
-	id<MTLCommandQueue> queue = getMetalQueue();
+	id<MTLCommandQueue> queue = get_metal_queue();
 	id<MTLCommandBuffer> command_buffer = [queue commandBuffer];
 	id<MTLBlitCommandEncoder> command_encoder = [command_buffer blitCommandEncoder];
 	[command_encoder copyFromTexture:(__bridge id<MTLTexture>)render_target->impl._tex
@@ -414,7 +414,7 @@ void gpu_pipeline_destroy(gpu_pipeline_t *pipeline) {
 }
 
 void gpu_pipeline_compile(gpu_pipeline_t *pipeline) {
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	NSError *error = nil;
 	id<MTLLibrary> library = [device newLibraryWithSource:[[NSString alloc] initWithBytes:pipeline->vertex_shader->impl.source length:pipeline->vertex_shader->impl.length encoding:NSUTF8StringEncoding] options:nil error:&error];
 	if (library == nil) {
@@ -546,7 +546,7 @@ void gpu_texture_init_from_bytes(gpu_texture_t *texture, void *data, int width,
 	descriptor.mipmapLevelCount = 1;
 	descriptor.usage = MTLTextureUsageShaderRead; // MTLTextureUsageShaderWrite
 
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	id<MTLTexture> tex = [device newTextureWithDescriptor:descriptor];
 	texture->impl._tex = (__bridge_retained void *)tex;
 	[tex replaceRegion:MTLRegionMake2D(0, 0, width, height)
@@ -574,7 +574,7 @@ void gpu_vertex_buffer_init(gpu_buffer_t *buffer, int count, gpu_vertex_structur
 		buffer->stride += gpu_vertex_data_size(element.data);
 	}
 
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	MTLResourceOptions options = MTLResourceCPUCacheModeWriteCombined;
 	options |= MTLResourceStorageModeShared;
 
@@ -593,7 +593,7 @@ void gpu_vertex_buffer_unlock(gpu_buffer_t *buf) {
 void gpu_constant_buffer_init(gpu_buffer_t *buffer, int size) {
 	buffer->count = size;
 	buffer->data = NULL;
-	buffer->impl.metal_buffer = (__bridge_retained void *)[getMetalDevice() newBufferWithLength:size options:MTLResourceOptionCPUCacheModeDefault];
+	buffer->impl.metal_buffer = (__bridge_retained void *)[get_metal_device() newBufferWithLength:size options:MTLResourceOptionCPUCacheModeDefault];
 }
 
 void gpu_constant_buffer_destroy(gpu_buffer_t *buffer) {
@@ -614,7 +614,7 @@ void gpu_constant_buffer_unlock(gpu_buffer_t *buffer) {
 void gpu_index_buffer_init(gpu_buffer_t *buffer, int indexCount) {
 	buffer->count = indexCount;
 
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	MTLResourceOptions options = MTLResourceCPUCacheModeWriteCombined;
 	options |= MTLResourceStorageModeShared;
 
@@ -667,7 +667,7 @@ static inst_t instances[1024];
 static int instances_count = 0;
 
 void gpu_raytrace_pipeline_init(gpu_raytrace_pipeline_t *pipeline, void *ray_shader, int ray_shader_size, gpu_buffer_t *constant_buffer) {
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	if (!device.supportsRaytracing) return;
 	constant_buf = constant_buffer;
 
@@ -690,13 +690,13 @@ void gpu_raytrace_pipeline_destroy(gpu_raytrace_pipeline_t *pipeline) {
 }
 
 bool gpu_raytrace_supported() {
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	return device.supportsRaytracing;
 }
 
 id<MTLAccelerationStructure> create_acceleration_sctructure(MTLAccelerationStructureDescriptor *descriptor) {
-	id<MTLDevice> device = getMetalDevice();
-	id<MTLCommandQueue> queue = getMetalQueue();
+	id<MTLDevice> device = get_metal_device();
+	id<MTLCommandQueue> queue = get_metal_queue();
 
 	MTLAccelerationStructureSizes accel_sizes = [device accelerationStructureSizesWithDescriptor:descriptor];
 	id<MTLAccelerationStructure> acceleration_structure = [device newAccelerationStructureWithSize:accel_sizes.accelerationStructureSize];
@@ -786,7 +786,7 @@ void gpu_raytrace_acceleration_structure_build(gpu_raytrace_acceleration_structu
 		return;
 	}
 
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	if (!device.supportsRaytracing) {
 		return;
 	}
@@ -850,11 +850,11 @@ void gpu_raytrace_set_target(gpu_texture_t *_output) {
 }
 
 void gpu_raytrace_dispatch_rays() {
-	id<MTLDevice> device = getMetalDevice();
+	id<MTLDevice> device = get_metal_device();
 	if (!device.supportsRaytracing) return;
 	dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
 
-	id<MTLCommandQueue> queue = getMetalQueue();
+	id<MTLCommandQueue> queue = get_metal_queue();
 	id<MTLCommandBuffer> command_buffer = [queue commandBuffer];
 	__block dispatch_semaphore_t sem = _semaphore;
 	[command_buffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) {

+ 3 - 12
base/sources/backends/wasm_system.c

@@ -49,18 +49,9 @@ __attribute__((import_module("imports"), import_name("js_time"))) int js_time();
 extern int iron_internal_window_width;
 extern int iron_internal_window_height;
 
-void iron_init(const char *name, int width, int height, iron_window_options_t *win) {
-	iron_window_options_t defaultWin;
-	if (win == NULL) {
-		iron_window_options_set_defaults(&defaultWin);
-		win = &defaultWin;
-	}
-	win->width = width;
-	win->height = height;
-
-	iron_internal_window_width = width;
-	iron_internal_window_height = height;
-
+void iron_init(iron_window_options_t *win) {
+	iron_internal_window_width = win->width;
+	iron_internal_window_height = win->height;
 	gpu_init(win->depth_bits, true);
 }
 

+ 2 - 27
base/sources/backends/windows_system.c

@@ -934,7 +934,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
 }
 #endif
 
-void iron_init(const char *name, int width, int height, iron_window_options_t *win) {
+void iron_init(iron_window_options_t *win) {
 	initKeyTranslation();
 	for (int i = 0; i < 256; ++i) {
 		keyPressed[i] = false;
@@ -955,18 +955,7 @@ void iron_init(const char *name, int width, int height, iron_window_options_t *w
 		keyPressed[i] = false;
 	}
 
-	iron_set_app_name(name);
-	iron_window_options_t defaultWin;
-	if (win == NULL) {
-		iron_window_options_set_defaults(&defaultWin);
-		win = &defaultWin;
-	}
-	win->width = width;
-	win->height = height;
-	if (win->title == NULL) {
-		win->title = name;
-	}
-
+	iron_set_app_name(win->title);
 	iron_window_create(win);
 
 	#ifdef WITH_GAMEPAD
@@ -1293,24 +1282,10 @@ void iron_window_set_title(const char *title) {
 }
 
 void iron_window_create(iron_window_options_t *win) {
-	iron_window_options_t defaultWin;
-
-	if (win == NULL) {
-		iron_window_options_set_defaults(&defaultWin);
-		win = &defaultWin;
-	}
-
-	if (win->title == NULL) {
-		win->title = "";
-	}
-
 	wchar_t wbuffer[1024];
 	MultiByteToWideChar(CP_UTF8, 0, win->title, -1, wbuffer, 1024);
-
 	createWindow(wbuffer, win->x, win->y, win->width, win->height, win->color_bits, win->frequency, win->features, win->mode, win->display_index);
-
 	gpu_init(win->depth_bits, win->vsync);
-
 	if (win->visible) {
 		iron_window_show();
 	}

+ 5 - 5
base/sources/iron.h

@@ -376,10 +376,10 @@ int usleep(unsigned int usec);
 #endif
 
 #ifdef IRON_MACOS
-const char *macgetresourcepath();
+const char *iron_get_resource_path();
 #endif
 #ifdef IRON_IOS
-const char *iphonegetresourcepath();
+const char *iron_get_resource_path();
 #endif
 
 #if defined(IRON_IOS) || defined(IRON_ANDROID)
@@ -817,7 +817,7 @@ void _iron_init(iron_window_options_t *ops) {
 	ops->display_index = -1;
 	ops->visible = enable_window;
 	ops->color_bits = 32;
-	iron_init(ops->title, ops->width, ops->height, ops);
+	iron_init(ops);
 	iron_random_init((int)(iron_time() * 1000));
 	iron_set_cut_callback(_cut, NULL);
 	iron_set_copy_callback(_copy, NULL);
@@ -1394,14 +1394,14 @@ i32 iron_sys_command(string_t *cmd) {
 string_t *iron_get_files_location() {
 	#ifdef IRON_MACOS
 	char path[1024];
-	strcpy(path, macgetresourcepath());
+	strcpy(path, iron_get_resource_path());
 	strcat(path, "/");
 	strcat(path, IRON_OUTDIR);
 	strcat(path, "/");
 	return path;
 	#elif defined(IRON_IOS)
 	char path[1024];
-	strcpy(path, iphonegetresourcepath());
+	strcpy(path, iron_get_resource_path());
 	strcat(path, "/");
 	strcat(path, IRON_OUTDIR);
 	strcat(path, "/");

+ 4 - 4
base/sources/iron_file.c

@@ -44,11 +44,11 @@ bool iron_file_reader_from_memory(iron_file_reader_t *reader, void *data, size_t
 }
 
 #ifdef IRON_IOS
-const char *iphonegetresourcepath(void);
+const char *iron_get_resource_path(void);
 #endif
 
 #ifdef IRON_MACOS
-const char *macgetresourcepath(void);
+const char *iron_get_resource_path(void);
 #endif
 
 #ifdef IRON_WINDOWS
@@ -125,7 +125,7 @@ static size_t iron_libc_file_reader_pos(iron_file_reader_t *reader) {
 bool iron_internal_file_reader_open(iron_file_reader_t *reader, const char *filename, int type) {
 	char filepath[1001];
 #ifdef IRON_IOS
-	strcpy(filepath, type == IRON_FILE_TYPE_SAVE ? iron_internal_save_path() : iphonegetresourcepath());
+	strcpy(filepath, type == IRON_FILE_TYPE_SAVE ? iron_internal_save_path() : iron_get_resource_path());
 	if (type != IRON_FILE_TYPE_SAVE) {
 		strcat(filepath, "/");
 		strcat(filepath, IRON_OUTDIR);
@@ -135,7 +135,7 @@ bool iron_internal_file_reader_open(iron_file_reader_t *reader, const char *file
 	strcat(filepath, filename);
 #endif
 #ifdef IRON_MACOS
-	strcpy(filepath, type == IRON_FILE_TYPE_SAVE ? iron_internal_save_path() : macgetresourcepath());
+	strcpy(filepath, type == IRON_FILE_TYPE_SAVE ? iron_internal_save_path() : iron_get_resource_path());
 	if (type != IRON_FILE_TYPE_SAVE) {
 		strcat(filepath, "/");
 		strcat(filepath, IRON_OUTDIR);

+ 0 - 17
base/sources/iron_system.c

@@ -76,23 +76,6 @@ void iron_error(const char *format, ...) {
 #endif
 }
 
-void iron_window_options_set_defaults(iron_window_options_t *win) {
-	iron_display_init();
-	win->title = NULL;
-	win->display_index = iron_primary_display();
-	win->mode = IRON_WINDOW_MODE_WINDOW;
-	win->x = -1;
-	win->y = -1;
-	win->width = 800;
-	win->height = 600;
-	win->visible = true;
-	win->features = IRON_WINDOW_FEATURE_RESIZEABLE | IRON_WINDOW_FEATURE_MINIMIZABLE | IRON_WINDOW_FEATURE_MAXIMIZABLE;
-	win->frequency = 60;
-	win->vsync = true;
-	win->color_bits = 32;
-	win->depth_bits = 32;
-}
-
 #if !defined(IRON_WASM) && !defined(IRON_ANDROID) && !defined(IRON_WINDOWS)
 double iron_time(void) {
 	return iron_timestamp() / iron_frequency();

+ 1 - 2
base/sources/iron_system.h

@@ -53,7 +53,6 @@ typedef struct iron_window_options {
 
 void iron_window_create(iron_window_options_t *win);
 void iron_window_destroy();
-void iron_window_options_set_defaults(iron_window_options_t *win);
 void iron_window_resize(int width, int height);
 void iron_window_move(int x, int y);
 void iron_window_change_mode(iron_window_mode_t mode);
@@ -71,7 +70,7 @@ void iron_window_set_close_callback(bool (*callback)(void *data), void *data);
 void iron_internal_call_resize_callback(int width, int height);
 bool iron_internal_call_close_callback();
 
-void iron_init(const char *name, int width, int height, iron_window_options_t *win);
+void iron_init(iron_window_options_t *win);
 const char *iron_application_name(void);
 void iron_set_app_name(const char *name);
 void iron_load_url(const char *url);