From 8e8ac6e5ec47544d2727738b56883fc60ae08072 Mon Sep 17 00:00:00 2001 From: Aaron Delasy Date: Fri, 8 Nov 2024 03:58:39 +0200 Subject: [PATCH] Cache actions count instead of actions itself --- components/ReplayVisualizer.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/ReplayVisualizer.tsx b/components/ReplayVisualizer.tsx index 4b8db37..35bf73c 100644 --- a/components/ReplayVisualizer.tsx +++ b/components/ReplayVisualizer.tsx @@ -24,7 +24,7 @@ export function ReplayVisualizer({ ), ); - const cachedActions = useRef(actions); + const actionsCount = useRef(actions.length); const canvas = useRef(null); const renderer = useRenderer(map, canvas, playerLabels, cellSize); @@ -35,10 +35,10 @@ export function ReplayVisualizer({ }, [renderer]); useEffect(() => { - const newActions = actions.slice(cachedActions.current.length); + const newActions = actions.slice(actionsCount.current); simulator.current.resetVisualEvents(); replay(simulator.current, newActions); - cachedActions.current.push(...newActions); + actionsCount.current += newActions.length; renderer?.render(simulator.current.getAllEntities()); }, [actions]);