mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
improve hitbox performance
This commit is contained in:
parent
11f207fc54
commit
e328f36c48
@ -174,12 +174,8 @@ abstract class Entity(
|
|||||||
val ticksFrozen: Int
|
val ticksFrozen: Int
|
||||||
get() = data.get(TICKS_FROZEN_DATA, 0)
|
get() = data.get(TICKS_FROZEN_DATA, 0)
|
||||||
|
|
||||||
|
|
||||||
open val hitboxColor: RGBColor?
|
open val hitboxColor: RGBColor?
|
||||||
get() = when {
|
get() = ChatColors.WHITE
|
||||||
isInvisible -> ChatColors.GREEN
|
|
||||||
else -> ChatColors.WHITE
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun forceTick(time: Long = millis()) {
|
fun forceTick(time: Long = millis()) {
|
||||||
|
@ -25,6 +25,7 @@ import de.bixilon.minosoft.data.entities.entities.properties.StatusEffectPropert
|
|||||||
import de.bixilon.minosoft.data.registries.effects.attributes.EntityAttributes
|
import de.bixilon.minosoft.data.registries.effects.attributes.EntityAttributes
|
||||||
import de.bixilon.minosoft.data.registries.effects.attributes.MinecraftAttributes
|
import de.bixilon.minosoft.data.registries.effects.attributes.MinecraftAttributes
|
||||||
import de.bixilon.minosoft.data.registries.entities.EntityType
|
import de.bixilon.minosoft.data.registries.entities.EntityType
|
||||||
|
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor
|
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.spell.AmbientEntityEffectParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.spell.AmbientEntityEffectParticle
|
||||||
@ -90,6 +91,13 @@ abstract class LivingEntity(connection: PlayConnection, entityType: EntityType,
|
|||||||
open val isSleeping: Boolean
|
open val isSleeping: Boolean
|
||||||
get() = bedPosition != null
|
get() = bedPosition != null
|
||||||
|
|
||||||
|
|
||||||
|
override val hitboxColor: RGBColor?
|
||||||
|
get() = when {
|
||||||
|
isInvisible -> ChatColors.GREEN
|
||||||
|
else -> super.hitboxColor
|
||||||
|
}
|
||||||
|
|
||||||
override fun createPhysics(): LivingEntityPhysics<*> {
|
override fun createPhysics(): LivingEntityPhysics<*> {
|
||||||
return LivingEntityPhysics(this)
|
return LivingEntityPhysics(this)
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ class AABB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun grow(size: Float): AABB {
|
fun grow(size: Float): AABB {
|
||||||
return AABB(min - size, max + size)
|
return grow(size.toDouble())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Double.isIn(min: Double, max: Double): Boolean {
|
private fun Double.isIn(min: Double, max: Double): Boolean {
|
||||||
|
@ -72,9 +72,10 @@ class EntityHitbox(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val lazy = model.renderer.profile.hitbox.lazy
|
||||||
val shrunk = aabb.shrink(0.01f)
|
val shrunk = aabb.shrink(0.01f)
|
||||||
val mesh = LineMesh(model.context)
|
val mesh = LineMesh(model.context, if (lazy) 1488 else 2496)
|
||||||
if (model.renderer.profile.hitbox.lazy) {
|
if (lazy) {
|
||||||
mesh.drawLazyAABB(shrunk, color = data.color)
|
mesh.drawLazyAABB(shrunk, color = data.color)
|
||||||
} else {
|
} else {
|
||||||
mesh.drawAABB(aabb = shrunk, color = data.color, margin = 0.1f)
|
mesh.drawAABB(aabb = shrunk, color = data.color, margin = 0.1f)
|
||||||
|
@ -20,19 +20,15 @@ import de.bixilon.minosoft.gui.rendering.RenderContext
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer
|
import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
|
||||||
|
|
||||||
open class GenericColorMesh(context: RenderContext, primitiveType: PrimitiveTypes = context.renderSystem.preferredPrimitiveType) : Mesh(context, GenericColorMeshStruct, primitiveType) {
|
open class GenericColorMesh(context: RenderContext, primitiveType: PrimitiveTypes = context.renderSystem.preferredPrimitiveType, initialCacheSize: Int = 1000) : Mesh(context, GenericColorMeshStruct, primitiveType, initialCacheSize) {
|
||||||
|
|
||||||
fun addVertex(position: Vec3, color: RGBColor?) {
|
fun addVertex(position: Vec3, color: RGBColor?) {
|
||||||
data.add(position.x)
|
data.add(position.array)
|
||||||
data.add(position.y)
|
|
||||||
data.add(position.z)
|
|
||||||
data.add((color ?: ChatColors.WHITE).rgba.buffer())
|
data.add((color ?: ChatColors.WHITE).rgba.buffer())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addVertex(position: Vec3, color: Float) {
|
fun addVertex(position: Vec3, color: Float) {
|
||||||
data.add(position.x)
|
data.add(position.array)
|
||||||
data.add(position.y)
|
|
||||||
data.add(position.z)
|
|
||||||
data.add(color)
|
data.add(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,19 +24,19 @@ import de.bixilon.minosoft.gui.rendering.RenderContext
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer
|
import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
||||||
|
|
||||||
open class LineMesh(context: RenderContext) : GenericColorMesh(context) {
|
open class LineMesh(context: RenderContext, initialCacheSize: Int = 1000) : GenericColorMesh(context, initialCacheSize = initialCacheSize) {
|
||||||
|
|
||||||
fun drawLine(start: Vec3, end: Vec3, lineWidth: Float = RenderConstants.DEFAULT_LINE_WIDTH, color: RGBColor) {
|
fun drawLine(start: Vec3, end: Vec3, lineWidth: Float = RenderConstants.DEFAULT_LINE_WIDTH, color: RGBColor) {
|
||||||
data.ensureSize(4 * order.size * GenericColorMeshStruct.FLOATS_PER_VERTEX)
|
data.ensureSize(4 * order.size * GenericColorMeshStruct.FLOATS_PER_VERTEX)
|
||||||
|
|
||||||
val direction = (end - start).normalize()
|
val direction = (end - start).normalizeAssign()
|
||||||
val normal1 = Vec3(direction.z, direction.z, direction.x - direction.y)
|
val normal1 = Vec3(direction.z, direction.z, direction.x - direction.y)
|
||||||
if (normal1 == Vec3.EMPTY) {
|
if (normal1 == Vec3.EMPTY) {
|
||||||
normal1.x = normal1.z
|
normal1.x = normal1.z
|
||||||
normal1.z = direction.z
|
normal1.z = direction.z
|
||||||
}
|
}
|
||||||
normal1.normalizeAssign()
|
normal1.normalizeAssign()
|
||||||
val normal2 = (direction cross normal1).normalize()
|
val normal2 = (direction cross normal1).normalizeAssign()
|
||||||
|
|
||||||
val halfLineWidth = lineWidth / 2
|
val halfLineWidth = lineWidth / 2
|
||||||
val directionWidth = direction * halfLineWidth
|
val directionWidth = direction * halfLineWidth
|
||||||
@ -64,10 +64,10 @@ open class LineMesh(context: RenderContext) : GenericColorMesh(context) {
|
|||||||
|
|
||||||
private fun drawLineQuad(start: Vec3, end: Vec3, normal1: Vec3, normal2: Vec3, directionWidth: Vec3, color: Float) {
|
private fun drawLineQuad(start: Vec3, end: Vec3, normal1: Vec3, normal2: Vec3, directionWidth: Vec3, color: Float) {
|
||||||
val positions = arrayOf(
|
val positions = arrayOf(
|
||||||
start + normal2 - directionWidth,
|
Vec3(start.x + normal2.x - directionWidth.x, start.y + normal2.y - directionWidth.y, start.z + normal2.z - directionWidth.z),
|
||||||
start + normal1 - directionWidth,
|
Vec3(start.x + normal1.x - directionWidth.x, start.y + normal1.y - directionWidth.y, start.z + normal1.z - directionWidth.z),
|
||||||
end + normal1 + directionWidth,
|
Vec3(end.x + normal1.x + directionWidth.x, end.y + normal1.y + directionWidth.y, end.z + normal1.z + directionWidth.z),
|
||||||
end + normal2 + directionWidth,
|
Vec3(end.x + normal2.x + directionWidth.x, end.y + normal2.y + directionWidth.y, end.z + normal2.z + directionWidth.z),
|
||||||
)
|
)
|
||||||
for ((positionIndex, _) in order) {
|
for ((positionIndex, _) in order) {
|
||||||
addVertex(positions[positionIndex], color)
|
addVertex(positions[positionIndex], color)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user