cache ur rocks

This commit is contained in:
2023-08-19 06:58:55 +10:00
parent 745476a7a0
commit 9cde1d98e2

View File

@ -19,8 +19,6 @@ import com.badlogic.gdx.utils.Array
import com.badlogic.gdx.utils.ScreenUtils
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
import ktx.math.times
import org.lwjgl.system.MathUtil
import kotlin.random.Random
class Game: ApplicationAdapter()
{
@ -40,7 +38,7 @@ class Game: ApplicationAdapter()
private lateinit var cubeInstance: ModelInstance
private lateinit var floorInstance: ModelInstance
private lateinit var suzanneInstance: ModelInstance
private lateinit var rocks: kotlin.Array<ModelInstance>
private lateinit var rockBatch: ModelCache
private fun makeCube(texture: Texture): Model
{
@ -186,7 +184,7 @@ class Game: ApplicationAdapter()
val s = kotlin.math.sqrt((1.0f - z) / w)
Quaternion(x, y, s * u, s * v)
}
rocks = Array(50) { i->
val rocks = Array(50) { i->
ModelInstance(rock, Matrix4(
Vector3(
rand.nextFloat(16.0f),
@ -195,6 +193,12 @@ class Game: ApplicationAdapter()
randQuaternion(rand),
Util.one * rand.nextFloat(0.6f, 1.2f)))
}
rockBatch = ModelCache().apply {
begin()
add(rocks.asIterable())
end()
}
suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f)
}
@ -253,7 +257,7 @@ class Game: ApplicationAdapter()
modelBatch.begin(colin.camera)
modelBatch.render(floorInstance, env)
modelBatch.render(rocks.asIterable(), env)
modelBatch.render(rockBatch, env)
modelBatch.render(cubeInstance, env)
modelBatch.render(suzanneInstance, env)
modelBatch.end()
@ -269,6 +273,7 @@ class Game: ApplicationAdapter()
override fun dispose()
{
rockBatch.dispose()
floor.dispose()
cube.dispose()
modelBatch.dispose()