From 30414c756e4a6b25fb87c8ec558ee2a6e3d4180b Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Sat, 4 Nov 2023 19:15:33 +0100 Subject: [PATCH] Revert "Mesh: Force use FragmentedArrayFloatList" This reverts commit 0a06695d --- .../gui/rendering/gui/gui/GUIMeshElement.kt | 4 ++-- .../hud/elements/other/CrosshairHUDElement.kt | 4 ++-- .../gui/rendering/gui/mesh/GUIMesh.kt | 3 +-- .../gui/rendering/particle/ParticleMesh.kt | 4 ++-- .../rendering/particle/ParticleRenderer.kt | 6 ++--- .../minosoft/gui/rendering/util/mesh/Mesh.kt | 23 +++++++++++-------- .../gui/rendering/util/vec/vec2/Vec2Util.kt | 4 +++- 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIMeshElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIMeshElement.kt index c2df68c08..23c8e8095 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIMeshElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIMeshElement.kt @@ -33,7 +33,7 @@ import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util.EMPTY import de.bixilon.minosoft.util.Initializable -import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList +import de.bixilon.minosoft.util.collections.floats.FloatListUtil open class GUIMeshElement( val element: T, @@ -42,7 +42,7 @@ open class GUIMeshElement( override val context: RenderContext = guiRenderer.context private val clickCounter = MouseClickCounter() private var _mesh: GUIMesh? = null - var mesh: GUIMesh = GUIMesh(context, guiRenderer.halfSize, FragmentedArrayFloatList(1000)) + var mesh: GUIMesh = GUIMesh(context, guiRenderer.halfSize, FloatListUtil.direct(1000)) override val skipDraw: Boolean get() = if (element is BaseDrawable) element.skipDraw else false protected var lastRevision = 0L diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt index b3f35ac66..a32a32266 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt @@ -28,7 +28,7 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.debug.DebugHUDElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMesh import de.bixilon.minosoft.gui.rendering.system.base.BlendingFunctions -import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList +import de.bixilon.minosoft.util.collections.floats.BufferedArrayFloatList class CrosshairHUDElement(guiRenderer: GUIRenderer) : CustomHUDElement(guiRenderer) { private val profile = guiRenderer.connection.profiles.gui @@ -91,7 +91,7 @@ class CrosshairHUDElement(guiRenderer: GUIRenderer) : CustomHUDElement(guiRender mesh?.unload() this.mesh = null - val mesh = GUIMesh(context, guiRenderer.halfSize, FragmentedArrayFloatList(42)) + val mesh = GUIMesh(context, guiRenderer.halfSize, BufferedArrayFloatList(42)) val start = (guiRenderer.scaledSize - CROSSHAIR_SIZE) / 2 mesh.addQuad(start, start + CROSSHAIR_SIZE, crosshairAtlasElement, crosshairProfile.color, null) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt index e56a4ce45..ad5edd7d3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt @@ -22,12 +22,11 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderIdenti import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct -import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList class GUIMesh( context: RenderContext, val halfSize: Vec2, - data: FragmentedArrayFloatList, + data: AbstractFloatList, ) : Mesh(context, GUIMeshStruct, initialCacheSize = 40000, clearOnLoad = false, data = data), GUIVertexConsumer { private val whiteTexture = context.textures.whiteTexture override val order = context.system.quadOrder diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt index 6f750d524..e4fe83ebf 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt @@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.particle import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec3.Vec3d +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer @@ -23,9 +24,8 @@ import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveType import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct -import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList -class ParticleMesh(context: RenderContext, data: FragmentedArrayFloatList) : Mesh(context, ParticleMeshStruct, PrimitiveTypes.POINT, -1, clearOnLoad = false, data = data) { +class ParticleMesh(context: RenderContext, data: AbstractFloatList) : Mesh(context, ParticleMeshStruct, PrimitiveTypes.POINT, -1, clearOnLoad = false, data = data) { fun addVertex(position: Vec3d, scale: Float, texture: Texture, tintColor: RGBColor, uvMin: FloatArray? = null, uvMax: FloatArray? = null, light: Int) { val minTransformedUV = if (uvMin == null) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt index 0f89fda2f..d97e9c327 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt @@ -39,7 +39,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates.Companion.disconnected import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.util.chunk.ChunkUtil.isInViewDistance -import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList +import de.bixilon.minosoft.util.collections.floats.BufferedArrayFloatList class ParticleRenderer( @@ -53,8 +53,8 @@ class ParticleRenderer( private val translucentShader = renderSystem.createShader(minosoft("particle")) { ParticleShader(it, false) } // There is no opaque mesh because it is simply not needed (every particle has transparency) - private var transparentMesh = ParticleMesh(context, FragmentedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX)) - private var translucentMesh = ParticleMesh(context, FragmentedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX)) + private var transparentMesh = ParticleMesh(context, BufferedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX)) + private var translucentMesh = ParticleMesh(context, BufferedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX)) private val particlesLock = SimpleLock() private var particles: MutableList = mutableListOf() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt index cd62e6f16..a97f2ad26 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt @@ -15,12 +15,15 @@ package de.bixilon.minosoft.gui.rendering.util.mesh import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec3.Vec3 +import de.bixilon.kutil.cast.CastUtil.nullCast import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.FloatVertexBuffer import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes +import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList -import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList +import de.bixilon.minosoft.util.collections.floats.FloatListUtil abstract class Mesh( val context: RenderContext, @@ -28,15 +31,15 @@ abstract class Mesh( val quadType: PrimitiveTypes = context.system.quadType, var initialCacheSize: Int = 10000, val clearOnLoad: Boolean = true, - data: FragmentedArrayFloatList? = null, + data: AbstractFloatList? = null, val onDemand: Boolean = false, ) : AbstractVertexConsumer { override val order = context.system.legacyQuadOrder - private var _data: FragmentedArrayFloatList? = data ?: if (onDemand) null else FragmentedArrayFloatList(initialCacheSize) - var data: FragmentedArrayFloatList + private var _data: AbstractFloatList? = data ?: if (onDemand) null else FloatListUtil.direct(initialCacheSize) + var data: AbstractFloatList get() { if (_data == null && onDemand) { - _data = FragmentedArrayFloatList(initialCacheSize) + _data = FloatListUtil.direct(initialCacheSize) } return _data.unsafeCast() } @@ -85,14 +88,14 @@ abstract class Mesh( fun unload() { when (state) { MeshStates.LOADED -> buffer.unload() - MeshStates.PREPARING, MeshStates.FINISHED -> _data?.unload() + MeshStates.PREPARING, MeshStates.FINISHED -> _data?.nullCast()?.unload() else -> throw IllegalStateException("Mesh is already unloaded") } state = MeshStates.UNLOADED } - inline fun addXQuad(start: Vec2, x: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addXQuad(start: Vec2, x: Float, end: Vec2, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val positions = arrayOf( Vec3(x, start.x, start.y), Vec3(x, start.x, end.y), @@ -102,7 +105,7 @@ abstract class Mesh( addQuad(positions, uvStart, uvEnd, vertexConsumer) } - inline fun addYQuad(start: Vec2, y: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addYQuad(start: Vec2, y: Float, end: Vec2, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val positions = arrayOf( Vec3(start.x, y, end.y), Vec3(end.x, y, end.y), @@ -112,7 +115,7 @@ abstract class Mesh( addQuad(positions, uvStart, uvEnd, vertexConsumer) } - inline fun addZQuad(start: Vec2, z: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addZQuad(start: Vec2, z: Float, end: Vec2, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val positions = arrayOf( Vec3(start.x, start.y, z), Vec3(start.x, end.y, z), @@ -122,7 +125,7 @@ abstract class Mesh( addQuad(positions, uvStart, uvEnd, vertexConsumer) } - inline fun addQuad(positions: Array, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addQuad(positions: Array, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val texturePositions = arrayOf( uvStart, Vec2(uvStart.x, uvEnd.y), diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/vec2/Vec2Util.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/vec2/Vec2Util.kt index d36a849e2..6b4760fb3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/vec2/Vec2Util.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/vec2/Vec2Util.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -19,6 +19,8 @@ import de.bixilon.kutil.math.interpolation.FloatInterpolation.interpolateSine import de.bixilon.kutil.primitive.FloatUtil.toFloat object Vec2Util { + val EMPTY = Vec2.EMPTY + val ONE = Vec2(1.0f) val Vec2.Companion.MIN: Vec2 get() = Vec2(Float.MIN_VALUE, Float.MIN_VALUE)