Skip to content

Commit

Permalink
Try at removing instances renderer directly after removal
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSi committed Dec 5, 2023
1 parent e382e2e commit 2806766
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 5 deletions.
14 changes: 14 additions & 0 deletions newIDE/app/src/InstancesEditor/InstancesRenderer/LayerRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,18 @@ export default class LayerRenderer {
}
}

destroyInstanceRenderers(instances: gdInitialInstance[]) {
console.log('layer.destroyInstanceRenderers: ', instances.length)
for (let instanceToDestroy of instances) {
console.log('instance to destroy for object ', instanceToDestroy.getObjectName())
const renderedInstance = this.renderedInstances[instanceToDestroy.ptr]
if (renderedInstance) {
console.log("DESTROY")
renderedInstance.onRemovedFromScene();
}
}
}

/**
* Remove rendered instances that are not associated to any instance anymore
* (this can happen after an instance has been deleted).
Expand All @@ -753,7 +765,9 @@ export default class LayerRenderer {
if (this.renderedInstances.hasOwnProperty(i)) {
const renderedInstance = this.renderedInstances[i];
if (!renderedInstance.wasUsed) {
console.log("was not used, on remove from scene")
renderedInstance.onRemovedFromScene();
console.log("delete rendered instance")
delete this.renderedInstances[i];
} else renderedInstance.wasUsed = false;
}
Expand Down
12 changes: 12 additions & 0 deletions newIDE/app/src/InstancesEditor/InstancesRenderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ export default class InstancesRenderer {
}
}

destroyInstanceRenderers(instances: gdInitialInstance[]) {
console.log("DESTROY INSTANCES RENDERERS")
for (let i in this.layersRenderers) {
if (this.layersRenderers.hasOwnProperty(i)) {
const layerRenderer = this.layersRenderers[i];

console.log("DESTROY INSTANCES RENDERERS in layer")
layerRenderer.destroyInstanceRenderers(instances);
}
}
}

/**
* Clean up rendered layers that are not existing anymore
*/
Expand Down
2 changes: 2 additions & 0 deletions newIDE/app/src/InstancesEditor/SelectedInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ export default class SelectedInstances {
}

const instance = selection[i];
console.log(instance, instance.getObjectName())

const instanceRect = this.instanceMeasurer.getInstanceAABB(
instance,
new Rectangle()
Expand Down
10 changes: 9 additions & 1 deletion newIDE/app/src/InstancesEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ export default class InstancesEditor extends Component<Props> {
);
};

destroyInstanceRenderers = (instances: gdInitialInstance[]) => {
console.log('instancesEditor.destroyInstanceRenderers: ', instances.length);
this.instancesRenderer.destroyInstanceRenderers(instances);
};

/**
* Immediately add serialized instances at the given
* position (in scene coordinates).
Expand Down Expand Up @@ -783,7 +788,10 @@ export default class InstancesEditor extends Component<Props> {
return;
}

console.log('on down instance, select');
console.log(
'on down instance, select, object name:',
instance.getObjectName()
);
this.props.instancesSelection.selectInstance({
instance,
multiSelect: this.keyboardShortcuts.shouldMultiSelect(),
Expand Down
1 change: 1 addition & 0 deletions newIDE/app/src/SceneEditor/EditorsDisplay.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ export type SceneEditorsDisplayInterface = {|
preventSnapToGrid?: boolean,
addInstancesInTheForeground?: boolean,
|}) => Array<gdInitialInstance>,
destroyInstanceRenderers: (gdInitialInstance[]) => void,
|},
|};
3 changes: 3 additions & 0 deletions newIDE/app/src/SceneEditor/MosaicEditorsDisplay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ const MosaicEditorsDisplay = React.forwardRef<
addSerializedInstances: editor
? editor.addSerializedInstances
: () => [],
destroyInstanceRenderers: editor
? editor.destroyInstanceRenderers
: () => {},
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ const SwipeableDrawerEditorsDisplay = React.forwardRef<
addSerializedInstances: editor
? editor.addSerializedInstances
: () => [],
destroyInstanceRenderers: editor
? editor.destroyInstanceRenderers
: () => {},
},
};
});
Expand Down
14 changes: 10 additions & 4 deletions newIDE/app/src/SceneEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,12 +1216,18 @@ export default class SceneEditor extends React.Component<Props, State> {
console.log('removeInstance');
this.props.initialInstances.removeInstance(instance);
});
const { editorDisplay } = this;
if (editorDisplay) {
editorDisplay.instancesHandlers.destroyInstanceRenderers(
selectedInstances
);
}

console.log('clearSelection');
console.log('clearSelection', selectedInstances.length);
this.instancesSelection.clearSelection();
if (this.editorDisplay) {
console.log('clearHighlightedInstance');
this.editorDisplay.instancesHandlers.clearHighlightedInstance();
if (editorDisplay) {
console.log('clearHighlightedInstance', selectedInstances.length);
editorDisplay.instancesHandlers.clearHighlightedInstance();
}

console.log('setting state');
Expand Down

0 comments on commit 2806766

Please sign in to comment.