Skip to content

Commit

Permalink
Cache actions count instead of actions itself
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Nov 8, 2024
1 parent 5db6ae3 commit 8e8ac6e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/ReplayVisualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function ReplayVisualizer({
),
);

const cachedActions = useRef(actions);
const actionsCount = useRef(actions.length);
const canvas = useRef<HTMLCanvasElement | null>(null);
const renderer = useRenderer(map, canvas, playerLabels, cellSize);

Expand All @@ -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]);

Expand Down

0 comments on commit 8e8ac6e

Please sign in to comment.