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