fix entire rebuild on updates

This commit is contained in:
wass08
2026-02-02 09:40:11 +09:00
parent 6c99851006
commit ff4e2fc2fe
2 changed files with 39 additions and 9 deletions
+34 -8
View File
@@ -170,14 +170,40 @@ const useScene: UseSceneStore = create<SceneState>()(
export default useScene export default useScene
// Subscribe to the temporal store (Undo/Redo events) // Track previous temporal state lengths
useScene.temporal.subscribe((state, prevState) => { let prevPastLength = 0
// Check if we just jumped in time (Undo/Redo) let prevFutureLength = 0
// If the 'nodes' object changed but it wasn't a normal 'set'
const currentNodes = useScene.getState().nodes
// Trigger a full scene re-validation // Subscribe to the temporal store (Undo/Redo events)
Object.values(currentNodes).forEach((node) => { useScene.temporal.subscribe((state) => {
useScene.getState().markDirty(node.id) 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 = () => { 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)