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))
|
||||
}
|
||||
|
||||
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)
|
||||
// if any of cell change operation fails, entire generation fails... leaving world in inconsistent state,
|
||||
// but also limiting damage by exiting early.
|
||||
@ -482,12 +493,6 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
|
||||
if (playerStart != null)
|
||||
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 {
|
||||
for ((obj, direction) in placedObjects) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user