From eb6fef150ebe3d2f9b1f1c84b85c43b873e77d53 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 18 Apr 2024 21:05:57 +0700 Subject: [PATCH] Rearrange code execution so objects are generated parallel to applying tile changes to world --- .../kstarbound/defs/dungeon/DungeonWorld.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt index 6068af6c..c9de055d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt @@ -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 {