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 c9de055d..e5227924 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt @@ -476,7 +476,7 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar val placedObjects = placedObjects.entries .map { (pos, data) -> try { - WorldObject.create(data.prototype, pos, data.parameters).also { it?.randomize(random) } to data.direction + WorldObject.create(data.prototype, pos, data.parameters).also { it?.randomize(random, parent.template.threatLevel) } to data.direction } catch (err: Throwable) { LOGGER.error("Exception while creating dungeon object ${data.prototype} at $pos", err) null to data.direction diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt index e4c969dd..d8a59a06 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt @@ -300,10 +300,12 @@ class WorldTemplate(val geometry: WorldGeometry) { } private val cellCache = Caffeine.newBuilder() - .maximumSize(150_000L) - .expireAfterAccess(Duration.ofMinutes(1)) + .maximumSize(1_500_000L) // plentiful of space, and allows for high hit ratio (around 79%) in most situations + // downside is memory consumption, but why should it matter when we save 80% of cpu time? + .expireAfterAccess(Duration.ofSeconds(20)) .executor(Starbound.EXECUTOR) .scheduler(Starbound) + // .recordStats() .build { (x, y) -> cellInfo0(x, y) } fun cellInfo(x: Int, y: Int): CellInfo { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/ContainerObject.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/ContainerObject.kt index 9da85dd4..a2b409b5 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/ContainerObject.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/ContainerObject.kt @@ -110,8 +110,8 @@ class ContainerObject(config: Registry.Entry) : WorldObject(co return data } - private fun randomizeContents(random: RandomGenerator) { - var level = world.template.threatLevel + private fun randomizeContents(random: RandomGenerator, threatLevel: Double) { + var level = threatLevel level = lookupProperty("level") { JsonPrimitive(level) }.asDouble level += lookupProperty("levelAdjustment") { JsonPrimitive(0.0) }.asDouble @@ -144,9 +144,9 @@ class ContainerObject(config: Registry.Entry) : WorldObject(co } } - override fun randomize(random: RandomGenerator) { - super.randomize(random) - randomizeContents(random) + override fun randomize(random: RandomGenerator, threatLevel: Double) { + super.randomize(random, threatLevel) + randomizeContents(random, threatLevel) } override fun onJoinWorld(world: World<*, *>) { @@ -162,9 +162,9 @@ class ContainerObject(config: Registry.Entry) : WorldObject(co val seed = lookupProperty("treasureSeed") if (seed.isJsonNull) { - randomizeContents(world.random) + randomizeContents(world.random, world.template.threatLevel) } else { - randomizeContents(random(seed.asLong)) + randomizeContents(random(seed.asLong), world.template.threatLevel) } } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt index 6a170261..f1e13315 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt @@ -138,7 +138,7 @@ open class WorldObject(val config: Registry.Entry) : TileEntit /** * called by DungeonWorld to deterministically randomize parameters */ - open fun randomize(random: RandomGenerator) { + open fun randomize(random: RandomGenerator, threatLevel: Double) { }