From adf48a6b9634bb7848a53a343ea496e003f0122d Mon Sep 17 00:00:00 2001 From: Vitalii Kravchenko Date: Mon, 26 Aug 2024 23:29:57 +0100 Subject: [PATCH] Cocoa Metal example (no SDL). --- .gitignore | 6 ++- .../02-argbuffers-no-sdl.odin | 44 ++++++++++--------- learn_metal/02-argbuffers/02-argbuffers.odin | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index cbb546f..c4559aa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,8 @@ **.exp tetroid.lib -build.bat \ No newline at end of file +build.bat +ols.json + +.vscode +.idea \ No newline at end of file diff --git a/learn_metal/02-argbuffers-no-sdl/02-argbuffers-no-sdl.odin b/learn_metal/02-argbuffers-no-sdl/02-argbuffers-no-sdl.odin index 1283ce1..1e96f83 100644 --- a/learn_metal/02-argbuffers-no-sdl/02-argbuffers-no-sdl.odin +++ b/learn_metal/02-argbuffers-no-sdl/02-argbuffers-no-sdl.odin @@ -19,8 +19,6 @@ main :: proc() { } metal_main :: proc() -> (err: ^NS.Error) { - NS.scoped_autoreleasepool() - app := NS.Application.sharedApplication() app->setActivationPolicy(.Regular) // without this window is not brought to foreground on launch defer app->release() @@ -74,24 +72,29 @@ metal_main :: proc() -> (err: ^NS.Error) { command_queue := device->newCommandQueue() defer command_queue->release() - for { - event := app->nextEventMatchingMask(NS.EventMaskAny, NS.Date.distantFuture(), NS.DefaultRunLoopMode, true) - - @static angle: f32 - - event_type := event->type() - #partial switch event_type { - case .KeyDown, .KeyUp: - code := NS.kVK(event->keyCode()) - #partial switch code { - case .LeftArrow: - angle -= 0.02 - case .RightArrow: - angle += 0.02 + @static angle: f32 + + for quit := false; !quit; { + { + NS.scoped_autoreleasepool() + event := app->nextEventMatchingMask(NS.EventMaskAny, NS.Date.distantFuture(), NS.DefaultRunLoopMode, true) + event_type := event->type() + #partial switch event_type { + case .KeyDown, .KeyUp: + code := NS.kVK(event->keyCode()) + #partial switch code { + case .Escape: + quit = true + case .LeftArrow: + angle -= 0.02 + case .RightArrow: + angle += 0.02 + } + fmt.println(event_type, code) + case: + fmt.println(event_type, event->locationInWindow(), event->modifierFlags()) } - fmt.println(event_type, code) - case: - fmt.println(event_type, event->locationInWindow(), event->modifierFlags()) + app->sendEvent(event) } frame_data := (^Frame_Data)(frame_data_buffer->contentsPointer()) @@ -129,9 +132,10 @@ metal_main :: proc() -> (err: ^NS.Error) { command_buffer->presentDrawable(drawable) command_buffer->commit() - app->sendEvent(event) app->updateWindows() } + + return nil } Frame_Data :: struct { diff --git a/learn_metal/02-argbuffers/02-argbuffers.odin b/learn_metal/02-argbuffers/02-argbuffers.odin index 03a5e5c..b7c765c 100644 --- a/learn_metal/02-argbuffers/02-argbuffers.odin +++ b/learn_metal/02-argbuffers/02-argbuffers.odin @@ -136,7 +136,7 @@ metal_main :: proc() -> (err: ^NS.Error) { defer command_queue->release() SDL.ShowWindow(window) - for quit := false; !quit; { + for quit := false; !quit; { for e: SDL.Event; SDL.PollEvent(&e); { #partial switch e.type { case .QUIT: