From c80f2a515e22893c2d1c9a6ff25ecc048785acec Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 28 Aug 2026 19:44:05 +0700 Subject: [PATCH] Engine doesn't need a separate input handler, clean up todos --- src/engine.clj | 7 ++----- src/game.clj | 6 +----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/engine.clj b/src/engine.clj index 1e2aa2b..af838f1 100644 --- a/src/engine.clj +++ b/src/engine.clj @@ -27,20 +27,18 @@ (println e)))) (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)}}] (if (rl/window-ready?) (println "Warning: Existing raylib window open, ignoring!") (do - (rl/set-trace-log-level! 0) + (rl/set-trace-log-level! rl/log-warning) (rl/init-window! width height title) (rl/set-target-fps! 30) (let [config (if config-path (edn/read-string (slurp config-path)) {})] (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 (reset! game-state (init config)) (catch Throwable t @@ -51,7 +49,6 @@ (let [config (:config @game-config)] (rl/with-drawing! (try - (swap! game-state #(input config %)) (swap! game-state #(update config %)) (draw config @game-state) (w/watch! (watch-fn config @game-state)) diff --git a/src/game.clj b/src/game.clj index 8dcc2ac..88ea70a 100644 --- a/src/game.clj +++ b/src/game.clj @@ -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 3))) (bit-clear 7))) -;; TODO: Is this working? Diagonals don't seem to be working (defn tile-bitset [game layer at-row at-col] (normalize-mask (reduce-kv (fn [acc i [_ [dy dx]]] @@ -227,6 +226,7 @@ (defn update-game [config game] (update-as-> [g game] + (handle-game-input config g) (when-let [mode (:drag-mode game)] (let [{mx :x my :y} (rl/get-mouse-position) row (quot my (* cell-size scale)) @@ -250,7 +250,6 @@ (rl/clear-background!* color-ground) (dotimes [layer num-layers] (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)] (draw-tile! game tilemap tx ty (* col cell-size scale) (* row cell-size scale) scale)))) (when (not (contains? game :draw-drag)) @@ -285,7 +284,6 @@ :height screen-height :config-path "game-config.edn" :init #'init-game - :input #'handle-game-input :update #'update-game :draw #'draw-game :watch-fn #'watch-game @@ -295,6 +293,4 @@ (future (-main)) (reset! @#'engine/game-state (init-game {})) (swap! @#'engine/game-state :assoc {}) - - #_(set-tile! @@#'engine/game-state 1 1 [2 2]) :-)