changeset 1303:e0326aa067c8

fix: windows builds
author sam@sambook-windows.localdomain
date Wed, 07 Aug 2024 15:54:22 +0700
parents 4f1c3994009d
children 49428fc7921c
files semicongine/audio/mixer.nim semicongine/audio/platform/windows.nim semicongine/input.nim semicongine/rendering.nim semicongine/rendering/platform/windows.nim tests/test_audio.nim
diffstat 6 files changed, 27 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- 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,
     )
--- 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
--- 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
 
--- 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
--- 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