fixes, performance improvements

This commit is contained in:
Moritz Zwerger 2023-11-10 23:03:45 +01:00
parent 0c4650a535
commit 242f43b90e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 33 additions and 11 deletions

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.entities.entities.decoration.armorstand
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kutil.bit.BitByte.isBitMask
import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.data.entities.data.EntityData
import de.bixilon.minosoft.data.entities.data.EntityDataField
@ -28,13 +29,31 @@ import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
class ArmorStand(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : LivingEntity(connection, entityType, data, position, rotation) {
private var flags = 0
init {
data.observe<Int>(FLAGS_DATA) { updateFlags(it ?: 0x00) }
updateFlags(data.get(FLAGS_DATA, 0x00))
}
private fun updateFlags(flags: Int) {
this.flags = flags
this.dimensions = when {
isMarker -> DIMENSIONS_MARKER
isSmall -> DIMENSIONS_SMALL
else -> DIMENSIONS
}
}
private fun getArmorStandFlag(bitMask: Int): Boolean {
return data.getBitMask(FLAGS_DATA, bitMask, 0x00)
return flags.isBitMask(bitMask)
}
override val canRaycast: Boolean get() = super.canRaycast && !isMarker
override val hitboxColor: RGBColor? get() = if (isMarker) null else super.hitboxColor
override var dimensions: Vec2 = DIMENSIONS
private set
@get:SynchronizedEntityData
val isSmall: Boolean
@ -76,12 +95,11 @@ class ArmorStand(connection: PlayConnection, entityType: EntityType, data: Entit
val rightLegRotation: Vec3
get() = data.get(RIGHT_LEG_ROTATION_DATA, Vec3(1.0f, 0.0f, 1.0f))
override val dimensions: Vec2
get() = when {
isMarker -> DIMENSIONS_MARKER
isSmall -> DIMENSIONS_SMALL
else -> DIMENSIONS
}
override fun tick() {
if (isMarker && age % 20 != 0) return // tick them really slow to improve performance
super.tick()
}
companion object : EntityFactory<ArmorStand> {

View File

@ -38,7 +38,7 @@ class TransformInstance(
fun pack(buffer: FloatBuffer, parent: Mat4, cache: Array<Mat4>) {
val temp = cache[this.id]
parent.times(value, temp)
parent.times(value, temp) // TODO: dom't multiply them on the rendering thread
val offset = this.id * Mat4.length
for (index in 0 until Mat4.length) {

View File

@ -41,8 +41,12 @@ class DefaultSkinProvider(
private fun load(skin: DefaultSkin) {
var loaded = 0
load(skin.name.skin("slim").texture())?.let { slim[skin.name] = it; loaded++ }
load(skin.name.skin("wide").texture())?.let { wide[skin.name] = it; loaded++ }
load(skin.name.skin("slim").texture())?.apply { slim[skin.name] = this; loaded++ }
val wide = load(skin.name.skin("wide").texture())?.apply { wide[skin.name] = this; loaded++ }
if (this.fallback == null && wide != null) {
fallback = PlayerSkin(wide, null, SkinModel.WIDE)
}
if (loaded > 0) {
return

View File

@ -46,7 +46,7 @@ object BenchmarkCommand : ConnectionCommand {
val random = Random()
val entities: MutableList<Entity> = ArrayList(count)
val spread = minOf(cbrt(count.toDouble()), 5.0)
val spread = maxOf(cbrt(count.toDouble()), 5.0)
for (id in 0 until count) {
val position = offset + Vec3d(random.nextDouble(-spread, spread), random.nextDouble(-spread, spread), random.nextDouble(-spread, spread))
val rotation = EntityRotation(random.nextFloat(-179.0f, 179.0f), random.nextFloat(-89.0f, 89.0f))