diff --git a/.gitignore b/.gitignore index 95b17eb..331f20d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ **.exp tetroid.lib build.bat +ols.json + +.vscode +.idea # orca samples 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..c722412 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,7 +19,7 @@ main :: proc() { } metal_main :: proc() -> (err: ^NS.Error) { - NS.scoped_autoreleasepool() + @static quit := false app := NS.Application.sharedApplication() app->setActivationPolicy(.Regular) // without this window is not brought to foreground on launch @@ -40,6 +40,11 @@ metal_main :: proc() -> (err: ^NS.Error) { window->initWithContentRect({window_origin, window_size}, { .Resizable, .Closable, .Titled, .Miniaturizable }, .Buffered, false) window->setTitle(NS.MakeConstantString("Use left/right arrow keys to rotate the triangle")) window->makeKeyAndOrderFront(nil) + window->setDelegate(NS.window_delegate_register_and_alloc({ + windowWillClose = proc(^NS.Notification) { + quit = true + }, + }, "MainWindowDelegate", context)) app->finishLaunching() @@ -74,24 +79,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 { + { + 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 +139,10 @@ metal_main :: proc() -> (err: ^NS.Error) { command_buffer->presentDrawable(drawable) command_buffer->commit() - app->sendEvent(event) app->updateWindows() } + + return nil } Frame_Data :: struct { @@ -158,8 +169,8 @@ build_shaders :: proc(device: ^MTL.Device) -> (library: ^MTL.Library, pso: ^MTL. }; v2f vertex vertex_main(device const Vertex_Data* vertex_data [[buffer(0)]], - device const Frame_Data* frame_data [[buffer(1)]], - uint vertex_id [[vertex_id]]) { + device const Frame_Data* frame_data [[buffer(1)]], + uint vertex_id [[vertex_id]]) { float a = frame_data->angle; float3x3 rotation_matrix = float3x3(sin(a), cos(a), 0.0, cos(a), -sin(a), 0.0, 0.0, 0.0, 1.0); float3 position = float3(vertex_data->positions[vertex_id]); 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: