# HG changeset patch # User sam@sambook-windows.localdomain # Date 1718450251 -25200 # Node ID dd757eb5ca860a0cc25d69333916d2d71e3ddfaa # Parent c43d4e62b89baab0e48885e7382ee464aca8aad0 fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity diff -r c43d4e62b89b -r dd757eb5ca86 semicongine/engine.nim --- a/semicongine/engine.nim Sat Jun 15 17:16:06 2024 +0700 +++ b/semicongine/engine.nim Sat Jun 15 18:17:31 2024 +0700 @@ -154,15 +154,17 @@ engine.renderer.get.Destroy(scene) proc RenderScene*(engine: var Engine, scene: var Scene) = + if WindowIsMinimized(): + return assert engine.renderer.isSome, "Renderer has not yet been initialized, call 'engine.InitRenderer' first" assert engine.renderer.get.HasScene(scene), &"Scene '{scene.name}' has not been loaded yet" let t0 = getMonoTime() - engine.renderer.get.StartNewFrame() - scene.SetShaderGlobal(ASPECT_RATIO_ATTRIBUTE, engine.GetAspectRatio) - engine.renderer.get.UpdateMeshData(scene) - engine.renderer.get.UpdateUniformData(scene) - engine.renderer.get.Render(scene) + if engine.renderer.get.StartNewFrame(): + scene.SetShaderGlobal(ASPECT_RATIO_ATTRIBUTE, engine.GetAspectRatio) + engine.renderer.get.UpdateMeshData(scene) + engine.renderer.get.UpdateUniformData(scene) + engine.renderer.get.Render(scene) if engine.showFps: let nanoSecs = getMonoTime().ticks - t0.ticks diff -r c43d4e62b89b -r dd757eb5ca86 semicongine/events.nim --- a/semicongine/events.nim Sat Jun 15 17:16:06 2024 +0700 +++ b/semicongine/events.nim Sat Jun 15 18:17:31 2024 +0700 @@ -1,7 +1,7 @@ type EventType* = enum Quit - ResizedWindow + ResizedWindow, MinimizedWindow, RestoredWindow KeyPressed, KeyReleased MousePressed, MouseReleased, MouseMoved, MouseWheel diff -r c43d4e62b89b -r dd757eb5ca86 semicongine/input.nim --- a/semicongine/input.nim Sat Jun 15 17:16:06 2024 +0700 +++ b/semicongine/input.nim Sat Jun 15 18:17:31 2024 +0700 @@ -21,6 +21,7 @@ mouseMove: Vec2f mouseWheel: float32 windowWasResized: bool = true + windowIsMinimized: bool = false # warning, shit is not thread safe var input: Input @@ -60,6 +61,11 @@ input.mousePosition = newPos of MouseWheel: input.mouseWheel = event.amount + of MinimizedWindow: + input.windowIsMinimized = true + of RestoredWindow: + input.windowIsMinimized = false + return not killed proc KeyIsDown*(key: Key): bool = key in input.keyIsDown @@ -80,6 +86,7 @@ proc MouseMove*(): auto = input.mouseMove proc MouseWheel*(): auto = input.mouseWheel proc WindowWasResized*(): auto = input.windowWasResized +proc WindowIsMinimized*(): auto = input.windowIsMinimized # actions as a slight abstraction over raw input diff -r c43d4e62b89b -r dd757eb5ca86 semicongine/platform/windows/window.nim --- a/semicongine/platform/windows/window.nim Sat Jun 15 17:16:06 2024 +0700 +++ b/semicongine/platform/windows/window.nim Sat Jun 15 18:17:31 2024 +0700 @@ -66,6 +66,13 @@ currentEvents.add(Event(eventType: events.MouseMoved, x: GET_X_LPARAM(lParam), y: GET_Y_LPARAM(lParam))) of WM_MOUSEWHEEL: currentEvents.add(Event(eventType: events.MouseWheel, amount: float32(GET_WHEEL_DELTA_WPARAM(wParam)) / WHEEL_DELTA)) + of WM_SIZING: + currentEvents.add(Event(eventType: ResizedWindow)) + of WM_SIZE: + if wParam == SIZE_MINIMIZED: + currentEvents.add(Event(eventType: MinimizedWindow)) + elif wParam == SIZE_RESTORED: + currentEvents.add(Event(eventType: RestoredWindow)) of WM_SETCURSOR: if LOWORD(lParam) == HTCLIENT: SetCursor(currentCursor) diff -r c43d4e62b89b -r dd757eb5ca86 semicongine/renderer.nim --- a/semicongine/renderer.nim Sat Jun 15 17:16:06 2024 +0700 +++ b/semicongine/renderer.nim Sat Jun 15 18:17:31 2024 +0700 @@ -369,9 +369,8 @@ offset += uniform.Size scene.ClearDirtyShaderGlobals() -proc StartNewFrame*(renderer: var Renderer) = - # TODO: chance for an infinity-loop? - while not renderer.swapchain.AcquireNextFrame(): +proc StartNewFrame*(renderer: var Renderer): bool = + if not renderer.swapchain.AcquireNextFrame(): checkVkResult renderer.device.vk.vkDeviceWaitIdle() let res = renderer.swapchain.Recreate() if res.isSome: @@ -379,7 +378,10 @@ renderer.swapchain = res.get() checkVkResult renderer.device.vk.vkDeviceWaitIdle() oldSwapchain.Destroy() + else: + return false renderer.nextFrameReady = true + return true proc Render*(renderer: var Renderer, scene: Scene) = assert scene in renderer.scenedata