Engine: Check if window already exists, fix load texture and add window-ready?

This commit is contained in:
Joseph Ferano 2026-08-23 07:41:12 +07:00
parent 93e8ea751f
commit 2186777587
2 changed files with 42 additions and 38 deletions

View File

@ -20,6 +20,9 @@
(defn run-game! (defn run-game!
[{:keys [title width height config-path init input update draw unload watch-fn] [{:keys [title width height config-path init input update draw unload watch-fn]
:or {title "Untitled" width 1200 height 900 watch-fn (constantly nil)}}] :or {title "Untitled" width 1200 height 900 watch-fn (constantly nil)}}]
(if (rl/window-ready?)
(println "Warning: Existing raylib window open, ignoring!")
(do
(rl/set-trace-log-level! rl/log-warning) (rl/set-trace-log-level! rl/log-warning)
(rl/init-window! width height title) (rl/init-window! width height title)
(rl/set-target-fps! 60) (rl/set-target-fps! 60)
@ -53,4 +56,4 @@
(rl/close-window!) (rl/close-window!)
(reset! last-error nil) (reset! last-error nil)
(reset! game-state nil) (reset! game-state nil)
(reset! game-config nil))) (reset! game-config nil)))))

View File

@ -179,6 +179,7 @@
(defcfn set-target-fps! "SetTargetFPS" [::mem/int] ::mem/void) (defcfn set-target-fps! "SetTargetFPS" [::mem/int] ::mem/void)
(defcfn set-trace-log-level! "SetTraceLogLevel" [::mem/int] ::mem/void) (defcfn set-trace-log-level! "SetTraceLogLevel" [::mem/int] ::mem/void)
(defcfn window-should-close? "WindowShouldClose" [] ::bool) (defcfn window-should-close? "WindowShouldClose" [] ::bool)
(defcfn window-ready? "IsWindowReady" [] ::bool)
(defcfn begin-drawing! "BeginDrawing" [] ::mem/void) (defcfn begin-drawing! "BeginDrawing" [] ::mem/void)
(defcfn end-drawing! "EndDrawing" [] ::mem/void) (defcfn end-drawing! "EndDrawing" [] ::mem/void)
@ -259,10 +260,6 @@
(defcfn measure-text "MeasureText" [::mem/c-string ::mem/int] ::mem/int) (defcfn measure-text "MeasureText" [::mem/c-string ::mem/int] ::mem/int)
(defn load-texture [path]
(let [tex (load-texture-raw* path)]
(assoc tex :seg (texture-seg tex))))
(def ^:private draw-text-raw!* (def ^:private draw-text-raw!*
(ffi/make-downcall "DrawText" (ffi/make-downcall "DrawText"
[::mem/c-string ::mem/int ::mem/int ::mem/int ::color] ::mem/void)) [::mem/c-string ::mem/int ::mem/int ::mem/int ::color] ::mem/void))
@ -343,6 +340,10 @@
(defn texture-seg [tex] (defn texture-seg [tex]
(mem/serialize tex ::texture arena)) (mem/serialize tex ::texture arena))
(defn load-texture [path]
(let [tex (load-texture-raw* path)]
(assoc tex :seg (texture-seg tex))))
(defn n-patch-info-seg [{:keys [source left top right bottom layout]}] (defn n-patch-info-seg [{:keys [source left top right bottom layout]}]
(mem/serialize {:source source :left (int left) :top (int top) (mem/serialize {:source source :left (int left) :top (int top)
:right (int right) :bottom (int bottom) :layout (int layout)} :right (int right) :bottom (int bottom) :layout (int layout)}