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