Use linked map and linked set so placements appear in the same order as they were supplied by dungeon parts
This commit is contained in:
parent
c91b448e66
commit
8987dc5270
@ -30,6 +30,7 @@ import ru.dbotthepony.kstarbound.world.entities.tile.TileEntity
|
||||
import ru.dbotthepony.kstarbound.world.entities.tile.WorldObject
|
||||
import ru.dbotthepony.kstarbound.world.physics.Poly
|
||||
import java.util.Collections
|
||||
import java.util.LinkedHashSet
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.function.Consumer
|
||||
import java.util.random.RandomGenerator
|
||||
@ -148,11 +149,11 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
|
||||
|
||||
private val pendingLiquids = HashMap<Vector2i, AbstractLiquidState>(8192, 0.5f)
|
||||
|
||||
private val openLocalWires = HashMap<String, HashSet<Vector2i>>()
|
||||
private val globalWires = HashMap<String, HashSet<Vector2i>>()
|
||||
private val openLocalWires = LinkedHashMap<String, LinkedHashSet<Vector2i>>()
|
||||
private val globalWires = LinkedHashMap<String, LinkedHashSet<Vector2i>>()
|
||||
private val localWires = ArrayList<HashSet<Vector2i>>()
|
||||
|
||||
private val placedObjects = HashMap<Vector2i, PlacedObject>()
|
||||
private val placedObjects = LinkedHashMap<Vector2i, PlacedObject>()
|
||||
|
||||
var playerStart: Vector2d? = null
|
||||
|
||||
@ -172,7 +173,7 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
|
||||
|
||||
fun placeWiring(x: Int, y: Int, group: String, partLocal: Boolean) {
|
||||
val table = if (partLocal) openLocalWires else globalWires
|
||||
table.computeIfAbsent(group) { HashSet() }.add(geometry.wrap(Vector2i(x, y)))
|
||||
table.computeIfAbsent(group) { LinkedHashSet() }.add(geometry.wrap(Vector2i(x, y)))
|
||||
}
|
||||
|
||||
fun requestLiquid(x: Int, y: Int, liquid: AbstractLiquidState) {
|
||||
@ -481,14 +482,11 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
|
||||
if (playerStart != null)
|
||||
parent.setPlayerSpawn(playerStart!!, false)
|
||||
|
||||
val placedObjects = placedObjects.entries.stream()
|
||||
.sorted { o1, o2 -> o1.key.y.compareTo(o2.key.y) } // place objects from bottom to top
|
||||
// so objects stacked on each other can be properly placed
|
||||
val placedObjects = placedObjects.entries
|
||||
.map { (pos, data) ->
|
||||
WorldObject.create(data.prototype, pos, data.parameters) to data.direction
|
||||
}
|
||||
.filter { it.first != null }
|
||||
.toList()
|
||||
|
||||
parent.eventLoop.supplyAsync {
|
||||
for ((obj, direction) in placedObjects) {
|
||||
|
Loading…
Reference in New Issue
Block a user