Rearrange code execution so objects are generated parallel to applying tile changes to world
This commit is contained in:
parent
fc6938fc35
commit
eb6fef150e
@ -473,6 +473,17 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
|
|||||||
}, parent.eventLoop))
|
}, parent.eventLoop))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val placedObjects = placedObjects.entries
|
||||||
|
.map { (pos, data) ->
|
||||||
|
try {
|
||||||
|
WorldObject.create(data.prototype, pos, data.parameters).also { it?.randomize(random) } to data.direction
|
||||||
|
} catch (err: Throwable) {
|
||||||
|
LOGGER.error("Exception while creating dungeon object ${data.prototype} at $pos", err)
|
||||||
|
null to data.direction
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.filter { it.first != null }
|
||||||
|
|
||||||
// wait for all chunks to be loaded (and cell changes to be applied)
|
// wait for all chunks to be loaded (and cell changes to be applied)
|
||||||
// if any of cell change operation fails, entire generation fails... leaving world in inconsistent state,
|
// if any of cell change operation fails, entire generation fails... leaving world in inconsistent state,
|
||||||
// but also limiting damage by exiting early.
|
// but also limiting damage by exiting early.
|
||||||
@ -482,12 +493,6 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
|
|||||||
if (playerStart != null)
|
if (playerStart != null)
|
||||||
parent.setPlayerSpawn(playerStart!!, false)
|
parent.setPlayerSpawn(playerStart!!, false)
|
||||||
|
|
||||||
val placedObjects = placedObjects.entries
|
|
||||||
.map { (pos, data) ->
|
|
||||||
WorldObject.create(data.prototype, pos, data.parameters).also { it?.randomize(random) } to data.direction
|
|
||||||
}
|
|
||||||
.filter { it.first != null }
|
|
||||||
|
|
||||||
parent.eventLoop.supplyAsync {
|
parent.eventLoop.supplyAsync {
|
||||||
for ((obj, direction) in placedObjects) {
|
for ((obj, direction) in placedObjects) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user