fix entire rebuild on updates
This commit is contained in:
@@ -170,14 +170,40 @@ const useScene: UseSceneStore = create<SceneState>()(
|
||||
|
||||
export default useScene
|
||||
|
||||
// Subscribe to the temporal store (Undo/Redo events)
|
||||
useScene.temporal.subscribe((state, prevState) => {
|
||||
// Check if we just jumped in time (Undo/Redo)
|
||||
// If the 'nodes' object changed but it wasn't a normal 'set'
|
||||
const currentNodes = useScene.getState().nodes
|
||||
// Track previous temporal state lengths
|
||||
let prevPastLength = 0
|
||||
let prevFutureLength = 0
|
||||
|
||||
// Trigger a full scene re-validation
|
||||
Object.values(currentNodes).forEach((node) => {
|
||||
useScene.getState().markDirty(node.id)
|
||||
// Subscribe to the temporal store (Undo/Redo events)
|
||||
useScene.temporal.subscribe((state) => {
|
||||
const currentPastLength = state.pastStates.length
|
||||
const currentFutureLength = state.futureStates.length
|
||||
|
||||
console.log('Temporal state changed:', {
|
||||
pastStates: { prev: prevPastLength, current: currentPastLength },
|
||||
futureStates: { prev: prevFutureLength, current: currentFutureLength },
|
||||
})
|
||||
|
||||
// Undo: futureStates increases (state moved from past to future)
|
||||
// Redo: pastStates increases while futureStates decreases (state moved from future to past)
|
||||
const didUndo = currentFutureLength > prevFutureLength
|
||||
const didRedo = currentPastLength > prevPastLength && currentFutureLength < prevFutureLength
|
||||
|
||||
console.log('Detection:', { didUndo, didRedo })
|
||||
|
||||
if (didUndo || didRedo) {
|
||||
// Use RAF to ensure all middleware and store updates are complete
|
||||
requestAnimationFrame(() => {
|
||||
const currentNodes = useScene.getState().nodes
|
||||
|
||||
// Trigger a full scene re-validation after undo/redo
|
||||
Object.values(currentNodes).forEach((node) => {
|
||||
useScene.getState().markDirty(node.id)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Update tracked lengths
|
||||
prevPastLength = currentPastLength
|
||||
prevFutureLength = currentFutureLength
|
||||
})
|
||||
|
||||
@@ -22,14 +22,17 @@ const csgEvaluator = new Evaluator()
|
||||
// ============================================================================
|
||||
|
||||
export const WallSystem = () => {
|
||||
const { nodes, dirtyNodes, clearDirty } = useScene()
|
||||
const dirtyNodes = useScene((state) => state.dirtyNodes)
|
||||
const clearDirty = useScene((state) => state.clearDirty)
|
||||
|
||||
console.log('wall system rerendering')
|
||||
useFrame(() => {
|
||||
if (dirtyNodes.size === 0) return
|
||||
|
||||
// Collect dirty walls and their levels
|
||||
const dirtyWallsByLevel = new Map<string, Set<string>>()
|
||||
|
||||
const nodes = useScene.getState().nodes
|
||||
dirtyNodes.forEach((id) => {
|
||||
const node = nodes[id]
|
||||
if (!node || node.type !== 'wall') return
|
||||
@@ -45,6 +48,7 @@ export const WallSystem = () => {
|
||||
|
||||
// Process each level that has dirty walls
|
||||
for (const [levelId, dirtyWallIds] of dirtyWallsByLevel) {
|
||||
console.log(`Updating walls for level ${levelId}`)
|
||||
const levelWalls = getLevelWalls(levelId)
|
||||
const miterData = calculateLevelMiters(levelWalls)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user