Engine doesn't need a separate input handler, clean up todos
This commit is contained in:
parent
a9424226ba
commit
c80f2a515e
@ -27,20 +27,18 @@
|
|||||||
(println e))))
|
(println e))))
|
||||||
|
|
||||||
(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 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?)
|
(if (rl/window-ready?)
|
||||||
(println "Warning: Existing raylib window open, ignoring!")
|
(println "Warning: Existing raylib window open, ignoring!")
|
||||||
(do
|
(do
|
||||||
(rl/set-trace-log-level! 0)
|
(rl/set-trace-log-level! rl/log-warning)
|
||||||
(rl/init-window! width height title)
|
(rl/init-window! width height title)
|
||||||
(rl/set-target-fps! 30)
|
(rl/set-target-fps! 30)
|
||||||
(let [config (if config-path
|
(let [config (if config-path
|
||||||
(edn/read-string (slurp config-path))
|
(edn/read-string (slurp config-path))
|
||||||
{})]
|
{})]
|
||||||
(reset! game-config {:config-path config-path :config config})
|
(reset! game-config {:config-path config-path :config config})
|
||||||
;; TODO: We should actually not commit until the frame is complete, because if not we will re-enter
|
|
||||||
;; input and call it several times if update or draw throw
|
|
||||||
(try
|
(try
|
||||||
(reset! game-state (init config))
|
(reset! game-state (init config))
|
||||||
(catch Throwable t
|
(catch Throwable t
|
||||||
@ -51,7 +49,6 @@
|
|||||||
(let [config (:config @game-config)]
|
(let [config (:config @game-config)]
|
||||||
(rl/with-drawing!
|
(rl/with-drawing!
|
||||||
(try
|
(try
|
||||||
(swap! game-state #(input config %))
|
|
||||||
(swap! game-state #(update config %))
|
(swap! game-state #(update config %))
|
||||||
(draw config @game-state)
|
(draw config @game-state)
|
||||||
(w/watch! (watch-fn config @game-state))
|
(w/watch! (watch-fn config @game-state))
|
||||||
|
|||||||
@ -141,7 +141,6 @@
|
|||||||
(not (and (bit-test m 2) (bit-test m 1))) (bit-clear 6)
|
(not (and (bit-test m 2) (bit-test m 1))) (bit-clear 6)
|
||||||
(not (and (bit-test m 2) (bit-test m 3))) (bit-clear 7)))
|
(not (and (bit-test m 2) (bit-test m 3))) (bit-clear 7)))
|
||||||
|
|
||||||
;; TODO: Is this working? Diagonals don't seem to be working
|
|
||||||
(defn tile-bitset [game layer at-row at-col]
|
(defn tile-bitset [game layer at-row at-col]
|
||||||
(normalize-mask
|
(normalize-mask
|
||||||
(reduce-kv (fn [acc i [_ [dy dx]]]
|
(reduce-kv (fn [acc i [_ [dy dx]]]
|
||||||
@ -227,6 +226,7 @@
|
|||||||
|
|
||||||
(defn update-game [config game]
|
(defn update-game [config game]
|
||||||
(update-as-> [g game]
|
(update-as-> [g game]
|
||||||
|
(handle-game-input config g)
|
||||||
(when-let [mode (:drag-mode game)]
|
(when-let [mode (:drag-mode game)]
|
||||||
(let [{mx :x my :y} (rl/get-mouse-position)
|
(let [{mx :x my :y} (rl/get-mouse-position)
|
||||||
row (quot my (* cell-size scale))
|
row (quot my (* cell-size scale))
|
||||||
@ -250,7 +250,6 @@
|
|||||||
(rl/clear-background!* color-ground)
|
(rl/clear-background!* color-ground)
|
||||||
(dotimes [layer num-layers]
|
(dotimes [layer num-layers]
|
||||||
(do-grid [row rows col cols]
|
(do-grid [row rows col cols]
|
||||||
;; TODO: tile-at needs to return layer + row + col, so that's the data structure we need to save
|
|
||||||
(when-let [[tilemap [tx ty]] (tile-at game layer row col)]
|
(when-let [[tilemap [tx ty]] (tile-at game layer row col)]
|
||||||
(draw-tile! game tilemap tx ty (* col cell-size scale) (* row cell-size scale) scale))))
|
(draw-tile! game tilemap tx ty (* col cell-size scale) (* row cell-size scale) scale))))
|
||||||
(when (not (contains? game :draw-drag))
|
(when (not (contains? game :draw-drag))
|
||||||
@ -285,7 +284,6 @@
|
|||||||
:height screen-height
|
:height screen-height
|
||||||
:config-path "game-config.edn"
|
:config-path "game-config.edn"
|
||||||
:init #'init-game
|
:init #'init-game
|
||||||
:input #'handle-game-input
|
|
||||||
:update #'update-game
|
:update #'update-game
|
||||||
:draw #'draw-game
|
:draw #'draw-game
|
||||||
:watch-fn #'watch-game
|
:watch-fn #'watch-game
|
||||||
@ -295,6 +293,4 @@
|
|||||||
(future (-main))
|
(future (-main))
|
||||||
(reset! @#'engine/game-state (init-game {}))
|
(reset! @#'engine/game-state (init-game {}))
|
||||||
(swap! @#'engine/game-state :assoc {})
|
(swap! @#'engine/game-state :assoc {})
|
||||||
|
|
||||||
#_(set-tile! @@#'engine/game-state 1 1 [2 2])
|
|
||||||
:-)
|
:-)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user