Skip to content

Commit

Permalink
Minimize reflection usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed May 24, 2024
1 parent 5221e5d commit 136b829
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ open class BasicTessellator: Tessellator, TileFactory {
protected val levelSetTriStripElementRange = Range()
protected var levelSetVertexTexCoordBuffer: FloatBufferObject? = null
protected var levelSetElementBuffer: ShortBufferObject? = null
protected var levelSetVertexTexCoordKey = this::class.simpleName + ".vertexTexCoordKey"
protected var levelSetElementKey = this::class.simpleName + ".elementKey"
protected var lastGlobeState: Globe.State? = null
/**
* Cache size should be adjusted in case of levelSet or detailControl changed.
Expand Down Expand Up @@ -167,12 +165,12 @@ open class BasicTessellator: Tessellator, TileFactory {
val triStripElements = levelSetTriStripElements ?: assembleTriStripElements(numLat, numLon).also { levelSetTriStripElements = it }

// Retrieve or create the level set's OpenGL vertex tex coord buffer object.
levelSetVertexTexCoordBuffer = rc.getBufferObject(levelSetVertexTexCoordKey) {
levelSetVertexTexCoordBuffer = rc.getBufferObject(LEVEL_SET_VERTEX_TEX_COORD_KEY) {
FloatBufferObject(GL_ARRAY_BUFFER, vertexTexCoords)
}

// Retrieve or create the level set's OpenGL element buffer object.
levelSetElementBuffer = rc.getBufferObject(levelSetElementKey) {
levelSetElementBuffer = rc.getBufferObject(LEVEL_SET_ELEMENT_KEY) {
ShortBufferObject(GL_ELEMENT_ARRAY_BUFFER, lineElements + triStripElements).also {
levelSetLineElementRange.upper = lineElements.size
levelSetTriStripElementRange.lower = lineElements.size
Expand Down Expand Up @@ -261,4 +259,9 @@ open class BasicTessellator: Tessellator, TileFactory {
}
return result
}

companion object {
private val LEVEL_SET_VERTEX_TEX_COORD_KEY = BasicTessellator::class.simpleName + ".vertexTexCoordKey"
private val LEVEL_SET_ELEMENT_KEY = BasicTessellator::class.simpleName + ".elementKey"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ open class TerrainTile(sector: Sector, level: Level, row: Int, column: Int): Til
protected var globeOffset: Globe.Offset? = null
var sortOrder = 0.0
protected set
private var pointBufferKey = this::class.simpleName + ".points.default" // This key will be replaced on prepare of each tile
private var heightBufferKey = this::class.simpleName + ".heights.default" // Use the same height buffer for all tiles by default
private var pointBufferKey = "TerrainTile.points.default" // This key will be replaced on prepare of each tile
private var heightBufferKey = "TerrainTile.heights.default" // Use the same height buffer for all tiles by default

public override val heightLimits get() = super.heightLimits

Expand Down Expand Up @@ -82,11 +82,11 @@ open class TerrainTile(sector: Sector, level: Level, row: Int, column: Int): Til
}

protected fun updateHeightBufferKey() {
heightBufferKey = this::class.simpleName + ".heights.$tileKey.${bufferSequence++}"
heightBufferKey = "TerrainTile.heights.$tileKey.${bufferSequence++}"
}

protected fun updatePointBufferKey() {
pointBufferKey = this::class.simpleName + ".points.$tileKey.${bufferSequence++}"
pointBufferKey = "TerrainTile.points.$tileKey.${bufferSequence++}"
}

companion object {
Expand Down

0 comments on commit 136b829

Please sign in to comment.