Skip to content

Commit

Permalink
concurrent async in async fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HollowHorizon committed Feb 4, 2024
1 parent 4892a49 commit 14917e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ru.hollowhorizon.hollowengine.common.scripting.story.nodes.base.serialize
open class StoryStateMachine(val server: MinecraftServer, val team: Team) : IContextBuilder {
val variables = ArrayList<StoryVariable<*>>()
val startTasks = ArrayList<() -> Unit>()
val onTickTasks = ArrayList<() -> Unit>()
var extra = CompoundTag()
internal val nodes = ArrayList<Node>()
internal val asyncNodes = ArrayList<Node>()
Expand All @@ -33,7 +34,12 @@ open class StoryStateMachine(val server: MinecraftServer, val team: Team) : ICon
fun tick(event: ServerTickEvent) {
if (event.phase != TickEvent.Phase.END) return

asyncNodeIds.removeIf { !asyncNodes[it].tick() }
onTickTasks.forEach { it() }
onTickTasks.clear()

val toRemove = asyncNodeIds.mapNotNull { if(!asyncNodes[it].tick()) it else null }

toRemove.forEach(asyncNodeIds::remove)

if(currentIndex >= nodes.size) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,15 @@ interface IContextBuilder {
}

fun AsyncProperty.stop() = +SimpleNode {
stateMachine.asyncNodeIds.remove(this@stop.index)
stateMachine.onTickTasks += {
stateMachine.asyncNodeIds.remove(this@stop.index)
}
}

fun AsyncProperty.resume() = +SimpleNode {
stateMachine.asyncNodeIds.add(this@resume.index)
stateMachine.onTickTasks += {
stateMachine.asyncNodeIds.add(this@resume.index)
}
}

// @Serializable Крч, сам сделаешь. Просил сам сделать класс xD
Expand Down

0 comments on commit 14917e6

Please sign in to comment.