Misc fixes

This commit is contained in:
DBotThePony 2024-04-18 21:24:24 +07:00
parent eb6fef150e
commit dc585273b7
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 13 additions and 11 deletions

View File

@ -476,7 +476,7 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
val placedObjects = placedObjects.entries val placedObjects = placedObjects.entries
.map { (pos, data) -> .map { (pos, data) ->
try { 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) { } catch (err: Throwable) {
LOGGER.error("Exception while creating dungeon object ${data.prototype} at $pos", err) LOGGER.error("Exception while creating dungeon object ${data.prototype} at $pos", err)
null to data.direction null to data.direction

View File

@ -300,10 +300,12 @@ class WorldTemplate(val geometry: WorldGeometry) {
} }
private val cellCache = Caffeine.newBuilder() private val cellCache = Caffeine.newBuilder()
.maximumSize(150_000L) .maximumSize(1_500_000L) // plentiful of space, and allows for high hit ratio (around 79%) in most situations
.expireAfterAccess(Duration.ofMinutes(1)) // downside is memory consumption, but why should it matter when we save 80% of cpu time?
.expireAfterAccess(Duration.ofSeconds(20))
.executor(Starbound.EXECUTOR) .executor(Starbound.EXECUTOR)
.scheduler(Starbound) .scheduler(Starbound)
// .recordStats()
.build<Vector2i, CellInfo> { (x, y) -> cellInfo0(x, y) } .build<Vector2i, CellInfo> { (x, y) -> cellInfo0(x, y) }
fun cellInfo(x: Int, y: Int): CellInfo { fun cellInfo(x: Int, y: Int): CellInfo {

View File

@ -110,8 +110,8 @@ class ContainerObject(config: Registry.Entry<ObjectDefinition>) : WorldObject(co
return data return data
} }
private fun randomizeContents(random: RandomGenerator) { private fun randomizeContents(random: RandomGenerator, threatLevel: Double) {
var level = world.template.threatLevel var level = threatLevel
level = lookupProperty("level") { JsonPrimitive(level) }.asDouble level = lookupProperty("level") { JsonPrimitive(level) }.asDouble
level += lookupProperty("levelAdjustment") { JsonPrimitive(0.0) }.asDouble level += lookupProperty("levelAdjustment") { JsonPrimitive(0.0) }.asDouble
@ -144,9 +144,9 @@ class ContainerObject(config: Registry.Entry<ObjectDefinition>) : WorldObject(co
} }
} }
override fun randomize(random: RandomGenerator) { override fun randomize(random: RandomGenerator, threatLevel: Double) {
super.randomize(random) super.randomize(random, threatLevel)
randomizeContents(random) randomizeContents(random, threatLevel)
} }
override fun onJoinWorld(world: World<*, *>) { override fun onJoinWorld(world: World<*, *>) {
@ -162,9 +162,9 @@ class ContainerObject(config: Registry.Entry<ObjectDefinition>) : WorldObject(co
val seed = lookupProperty("treasureSeed") val seed = lookupProperty("treasureSeed")
if (seed.isJsonNull) { if (seed.isJsonNull) {
randomizeContents(world.random) randomizeContents(world.random, world.template.threatLevel)
} else { } else {
randomizeContents(random(seed.asLong)) randomizeContents(random(seed.asLong), world.template.threatLevel)
} }
} }
} }

View File

@ -138,7 +138,7 @@ open class WorldObject(val config: Registry.Entry<ObjectDefinition>) : TileEntit
/** /**
* called by DungeonWorld to deterministically randomize parameters * called by DungeonWorld to deterministically randomize parameters
*/ */
open fun randomize(random: RandomGenerator) { open fun randomize(random: RandomGenerator, threatLevel: Double) {
} }