Skip to content

Commit

Permalink
fixed editor app reload
Browse files Browse the repository at this point in the history
  • Loading branch information
fabmax committed Dec 10, 2023
1 parent bd6187c commit 2cf54a3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ abstract class NodeModel(val nodeData: SceneNodeData) {
it.destroyComponent()
check(!it.isCreated) { "Component not destroyed: $it" }
}
components.clear()
onNodeUpdate.clear()
drawNode.release()
drawNode.parent?.removeNode(drawNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class SceneModel(sceneData: SceneNodeData, val project: EditorProject) : NodeMod
}

private fun disposeCreatedScene() {
nodeModels.values.forEach { it.destroyComponents() }
nodeModels.values.forEach {
it.destroyComponents()
project.entities -= it
}
nodeModels.clear()
nodesToNodeModels.clear()

drawNode.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ abstract class AoPipeline : BaseReleasable() {
depthPass = NormalLinearDepthMapPass(drawNode, mapWidth, mapHeight)
depthPass.camera = proxyCamera
depthPass.isUpdateDrawNode = false
depthPass.isReleaseDrawNode = false
depthPass.onBeforeCollectDrawCommands += { ev ->
proxyCamera.sync(ev)
}
Expand Down
7 changes: 7 additions & 0 deletions kool-core/src/commonMain/kotlin/de/fabmax/kool/scene/Node.kt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ open class Node(name: String? = null) : BaseReleasable() {
return null
}

fun traverse(block: (Node) -> Unit) {
block(this)
children.forEach {
it.traverse(block)
}
}

open fun collectTag(result: MutableList<Node>, tag: String, value: String? = null) {
if (tags.hasTag(tag, value)) {
result += this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ open class Scene(name: String? = null) : Node(name) {
super.release()

mainRenderPass.renderPass.release()
offscreenPasses.update()
for (i in offscreenPasses.indices) {
offscreenPasses[i].release()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,9 @@ class KoolEditor(val ctx: KoolContext, val paths: ProjectPaths) {
editorCameraTransform.addNode(editorOverlay.camera)

// dispose old scene + objects
EditorState.projectModel.getCreatedScenes().map { it.drawNode }.let { oldScenes ->
ctx.scenes -= oldScenes.toSet()
oldScenes.forEach {
it.removeOffscreenPass(selectionOverlay.selectionPass)
it.release()
}
EditorState.projectModel.getCreatedScenes().forEach { sceneModel ->
ctx.scenes -= sceneModel.drawNode
sceneModel.drawNode.removeOffscreenPass(selectionOverlay.selectionPass)
}
EditorState.loadedApp.value?.app?.onDispose(ctx)
selectionOverlay.selectionPass.disposePipelines(ctx)
Expand All @@ -288,7 +285,7 @@ class KoolEditor(val ctx: KoolContext, val paths: ProjectPaths) {
// add scene objects from new app
EditorState.projectModel.getCreatedScenes().let { newScenes ->
if (newScenes.size != 1) {
logW { "Unusual number of scene, currently only single scene setups are supported" }
logW { "Unsupported number of scene, currently only single scene setups are supported" }
}
newScenes.firstOrNull()?.let { sceneModel ->
val scene = sceneModel.drawNode
Expand Down

0 comments on commit 2cf54a3

Please sign in to comment.