From 2bd7ad1a285421d83d788c5ea9972c3b2523aa4d Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 31 Jul 2026 22:17:41 -0600 Subject: [PATCH] fix jitter kind of? --- src/frontend/il/app.cljs | 4 ++-- src/frontend/il/update.cljs | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/frontend/il/app.cljs b/src/frontend/il/app.cljs index 52494b9..744635f 100644 --- a/src/frontend/il/app.cljs +++ b/src/frontend/il/app.cljs @@ -23,7 +23,7 @@ right :a up :w down :s} (get-in @state [:player :keymap]) - speed (get-in @state [:player :speed] 5)] + speed (get-in @state [:player :speed] 2.33)] (swap! state update-in [:player :velocity] assoc :x (* speed (+ left right)) :y (* speed (+ up down)))))) @@ -49,7 +49,6 @@ entity-relative-mouse-pos (.toLocal ^js entity-layer global-mouse-pos) send-interval 25 ; Send every 25ms (10 tps) elapsed (.-elapsedMS t) - {player :player} @state {:keys [player entities players]} (-> (update @state :elapsed + elapsed) (update/update-state :entities dt layers) (update/update-state :players dt layers) @@ -77,6 +76,7 @@ x :x y :y} thing] (when renderable + (js/console.log "Rendering thing: " x y) (set! (.. renderable -x) x) (set! (.. renderable -y) y)))))) diff --git a/src/frontend/il/update.cljs b/src/frontend/il/update.cljs index adc391c..7e03119 100644 --- a/src/frontend/il/update.cljs +++ b/src/frontend/il/update.cljs @@ -20,20 +20,23 @@ (assoc e :renderable renderable)) e)) -(def min-distance-for-update 1) - (defn apply-server-position [e] (let [{:keys [x y tx ty]} e speed (get e :speed 15) + min-distance-for-update 1 has-server-pos (not (and (nil? tx) (nil? ty))) - has-actual-pos (not (and (nil? x) (nil? y)))] + has-actual-pos (not (and (nil? x) (nil? y))) + velocityless-entity (dissoc e :velocity)] (cond - (and (= x tx) (= y ty)) e - (and has-server-pos (not has-actual-pos)) (assoc e :x tx :y ty) + ; If the position given by the server is the same as the current position, do nothing + (and has-server-pos (= x tx) (= y ty)) velocityless-entity + ; When the entity has a rendered position, and a new server position (and has-server-pos has-actual-pos) (let [delta (ilmath/euclidean-distance x y tx ty)] - (cond - (> delta min-distance-for-update) (assoc e :velocity (ilmath/velocity-for x y tx ty speed) - :else e))) + (if (> delta min-distance-for-update) + (assoc velocityless-entity :velocity (ilmath/velocity-for x y tx ty speed)) + velocityless-entity)) + ; When the entity has no rendered position, and a new server position + has-server-pos (assoc velocityless-entity :x tx :y ty) :else e))) (defn apply-player-shoot [state mouse-pos] @@ -71,13 +74,12 @@ (assoc state key new-values))) (defn update-player [state dt send-interval layers mouse-pos sb] - (println state) (let [{player :player} state updated-player (-> player (apply-renderable layers) (assoc :shootbox sb) (apply-velocity dt))] - (if-not (nil? player) + (if-not (and (nil? player) (nil? (player :renderable))) (-> (assoc state :player updated-player) (apply-player-position send-interval) (apply-player-shoot mouse-pos))