# HG changeset patch # User sam@sambook-windows.localdomain # Date 1723020862 -25200 # Node ID e0326aa067c8327d8808dbf9db35f83f09093f3c # Parent 4f1c3994009d59a8359f78ddea7a3db57a08591f fix: windows builds diff -r 4f1c3994009d -r e0326aa067c8 semicongine/audio/mixer.nim --- a/semicongine/audio/mixer.nim Tue Aug 06 23:43:27 2024 +0700 +++ b/semicongine/audio/mixer.nim Wed Aug 07 15:54:22 2024 +0700 @@ -297,7 +297,7 @@ # for thread priority (really necessary?) when defined(windows): - import ./thirdparty/winim/winim/inc/winbase + import ../thirdparty/winim/winim/inc/winbase when defined(linux): import std/posix diff -r 4f1c3994009d -r e0326aa067c8 semicongine/audio/platform/windows.nim --- a/semicongine/audio/platform/windows.nim Tue Aug 06 23:43:27 2024 +0700 +++ b/semicongine/audio/platform/windows.nim Wed Aug 07 15:54:22 2024 +0700 @@ -1,4 +1,9 @@ -import ./thirdparty/winim/winim/inc/mmsystem +import std/os + +import ../../thirdparty/winim/winim/inc/[mmsystem, windef] + +# import ../../thirdparty/winim/winim/inc/[windef, winuser, wincon, winbase] + template CheckWinMMResult*(call: untyped) = let value = call @@ -24,7 +29,7 @@ for i in 0 ..< buffers.len: result.buffers.add WAVEHDR( - lpData: cast[cstring](addr buffers[i][][0]), + lpData: cast[ptr CHAR](addr buffers[i][][0]), dwBufferLength: DWORD(buffers[i][].len * sizeof(Sample)), dwLoops: 1, ) diff -r 4f1c3994009d -r e0326aa067c8 semicongine/input.nim --- a/semicongine/input.nim Tue Aug 06 23:43:27 2024 +0700 +++ b/semicongine/input.nim Wed Aug 07 15:54:22 2024 +0700 @@ -68,6 +68,7 @@ of RestoredWindow: input.windowIsMinimized = false of GotFocus: + echo "got focus again" input.hasFocus = true of LostFocus: input.hasFocus = false diff -r 4f1c3994009d -r e0326aa067c8 semicongine/rendering.nim --- a/semicongine/rendering.nim Tue Aug 06 23:43:27 2024 +0700 +++ b/semicongine/rendering.nim Wed Aug 07 15:54:22 2024 +0700 @@ -1,8 +1,10 @@ +import std/logging import std/enumerate import std/hashes import std/macros import std/os import std/sequtils +import std/strformat import std/strutils import std/typetraits diff -r 4f1c3994009d -r e0326aa067c8 semicongine/rendering/platform/windows.nim --- a/semicongine/rendering/platform/windows.nim Tue Aug 06 23:43:27 2024 +0700 +++ b/semicongine/rendering/platform/windows.nim Wed Aug 07 15:54:22 2024 +0700 @@ -1,8 +1,10 @@ import std/tables import std/options -import ../../../thirdparty/winim/winim/inc/[windef, winuser, wincon, winbase] -import ../../../thirdparty/winim/winim/[winstr, utils] +import ../../core + +import ../../thirdparty/winim/winim/inc/[windef, winuser, wincon, winbase] +import ../../thirdparty/winim/winim/[winstr, utils] import ../../events @@ -71,12 +73,12 @@ proc windowHandler(hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} = case uMsg of WM_DESTROY: - currentEvents.add(Event(eventType: EventType.Quit)) + currentEvents.add(Event(eventType: events.EventType.Quit)) of WM_KEYDOWN, WM_SYSKEYDOWN: - let key = MapLeftRightKeys(INT(wParam), lParam) + let key = mapLeftRightKeys(INT(wParam), lParam) currentEvents.add(Event(eventType: KeyPressed, key: KeyTypeMap.getOrDefault(key, Key.UNKNOWN))) of WM_KEYUP, WM_SYSKEYUP: - let key = MapLeftRightKeys(INT(wParam), lParam) + let key = mapLeftRightKeys(INT(wParam), lParam) currentEvents.add(Event(eventType: KeyReleased, key: KeyTypeMap.getOrDefault(key, Key.UNKNOWN))) of WM_LBUTTONDOWN: currentEvents.add(Event(eventType: MousePressed, button: MouseButton.Mouse1)) @@ -116,7 +118,7 @@ proc createWindow*(title: string): NativeWindow = - when DEBUG: + when not defined(release): AllocConsole() discard stdin.reopen("conIN$", fmRead) discard stdout.reopen("conOUT$", fmWrite) @@ -128,7 +130,7 @@ windowName = T(title) windowClass = WNDCLASSEX( cbSize: UINT(WNDCLASSEX.sizeof), - lpfnWndProc: WindowHandler, + lpfnWndProc: windowHandler, hInstance: result.hInstance, lpszClassName: windowClassName, hcursor: currentCursor, @@ -151,6 +153,8 @@ result.g_wpPrev.length = UINT(sizeof(WINDOWPLACEMENT)) discard result.hwnd.ShowWindow(SW_SHOW) + discard result.hwnd.SetForegroundWindow() + discard result.hwnd.SetFocus() proc setTitle*(window: NativeWindow, title: string) = window.hwnd.SetWindowText(T(title)) @@ -187,13 +191,13 @@ proc pendingEvents*(window: NativeWindow): seq[Event] = # empty queue - currentEvents = newSeq[Event]() var msg: MSG # fill queue while PeekMessage(addr(msg), window.hwnd, 0, 0, PM_REMOVE): TranslateMessage(addr(msg)) DispatchMessage(addr(msg)) - return currentEvents + result = currentEvents + currentEvents.setLen(0) proc getMousePosition*(window: NativeWindow): Option[Vec2f] = var p: POINT @@ -203,7 +207,7 @@ return none(Vec2f) proc setMousePosition*(window: NativeWindow, x, y: int) = - checkWin32Result SetCursorPos(x, y) + checkWin32Result SetCursorPos(x.int32, y.int32) proc createNativeSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = assert instance.Valid diff -r 4f1c3994009d -r e0326aa067c8 tests/test_audio.nim --- a/tests/test_audio.nim Tue Aug 06 23:43:27 2024 +0700 +++ b/tests/test_audio.nim Wed Aug 07 15:54:22 2024 +0700 @@ -76,12 +76,11 @@ test3() while mixer[].isPlaying(): - discard mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5) # on windows we re-open stdin and this will not work when defined(linux): + discard mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5) echo "Press q and enter to exit" if stdin.readLine() == "q": mixer[].stop() elif defined(windows): - sleep(5) - mixer[].stop() + sleep(1000) \ No newline at end of file