mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 06:24:06 +09:00
various patches and renaming; thai-variable font sheet
This commit is contained in:
@@ -13,26 +13,32 @@ import net.torvald.terrarum.worlddrawer.WorldCamera.y
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera.height
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera.width
|
||||
import org.lwjgl.BufferUtils
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.lwjgl.opengl.GL15
|
||||
import org.lwjgl.opengl.*
|
||||
import org.newdawn.slick.*
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.FloatBuffer
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-19.
|
||||
*/
|
||||
object BlocksDrawer {
|
||||
object BlocksDrawer_NEW {
|
||||
private val world: GameWorld = Terrarum.ingame!!.world
|
||||
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
|
||||
|
||||
// TODO modular
|
||||
val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "blocks/terrain.tga.gz"), TILE_SIZE, TILE_SIZE) // 64 MB
|
||||
val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "blocks/test.tga.gz"), TILE_SIZE, TILE_SIZE) // 64 MB
|
||||
val terrainHorizontalTiles = tilesTerrain.horizontalCount
|
||||
val tilesWire = SpriteSheet(ModMgr.getPath("basegame", "blocks/wire.tga.gz"), TILE_SIZE, TILE_SIZE) // 4 MB
|
||||
val wireHorizontalTiles = tilesWire.horizontalCount
|
||||
|
||||
val tilesTerrainTexBuffer: ByteBuffer = BufferUtils.createByteBuffer(tilesTerrain.texture.textureData.size)
|
||||
init {
|
||||
tilesTerrainTexBuffer.put(tilesTerrain.texture.textureData)
|
||||
tilesTerrainTexBuffer.rewind()
|
||||
}
|
||||
|
||||
|
||||
val tileItemWall = Image(TILE_SIZE * 16, TILE_SIZE * GameWorld.TILES_SUPPORTED / 16) // 4 MB
|
||||
|
||||
@@ -57,8 +63,8 @@ object BlocksDrawer {
|
||||
|
||||
|
||||
|
||||
val VBO_WIDTH = Terrarum.ingame!!.ZOOM_MIN.inv().times(Terrarum.WIDTH).div(TILE_SIZE).ceil() + 2
|
||||
val VBO_HEIGHT = Terrarum.ingame!!.ZOOM_MIN.inv().times(Terrarum.HEIGHT).div(TILE_SIZE).ceil() + 2
|
||||
val VBO_WIDTH = Terrarum.ingame!!.ZOOM_MIN.inv().times(Terrarum.WIDTH).div(TILE_SIZE).ceil() + 3
|
||||
val VBO_HEIGHT = Terrarum.ingame!!.ZOOM_MIN.inv().times(Terrarum.HEIGHT).div(TILE_SIZE).ceil() + 3
|
||||
val cameraTileX: Int
|
||||
get() = WorldCamera.x.div(TILE_SIZE)
|
||||
val cameraTileY: Int
|
||||
@@ -108,18 +114,22 @@ object BlocksDrawer {
|
||||
|
||||
|
||||
// generate VBO
|
||||
worldVBOTexture = BufferUtils.createFloatBuffer(12 * VBO_WIDTH * VBO_HEIGHT)
|
||||
worldVBOVertex = BufferUtils.createFloatBuffer(12 * VBO_WIDTH * VBO_HEIGHT)
|
||||
worldVBOTexture = BufferUtils.createFloatBuffer(8 * VBO_WIDTH * VBO_HEIGHT)
|
||||
worldVBOVertex = BufferUtils.createFloatBuffer(8 * VBO_WIDTH * VBO_HEIGHT)
|
||||
|
||||
for (y in 0..VBO_HEIGHT - 1) {
|
||||
for (x in 0..VBO_WIDTH - 1) {
|
||||
val x = x * TILE_SIZEF
|
||||
val y = y * TILE_SIZEF
|
||||
worldVBOVertex.put(floatArrayOf(
|
||||
worldVBOVertex.put(floatArrayOf( // fixed points (triangles); won't need to be re-assigned
|
||||
//x , y ,
|
||||
//x + TILE_SIZEF, y ,
|
||||
//x , y + TILE_SIZEF,
|
||||
//x + TILE_SIZEF, y ,
|
||||
//x + TILE_SIZEF, y + TILE_SIZEF,
|
||||
//x , y + TILE_SIZEF
|
||||
x, y,
|
||||
x + TILE_SIZEF, y,
|
||||
x, y + TILE_SIZEF,
|
||||
x + TILE_SIZEF, y,
|
||||
x + TILE_SIZEF, y + TILE_SIZEF,
|
||||
x, y + TILE_SIZEF
|
||||
))
|
||||
@@ -129,7 +139,7 @@ object BlocksDrawer {
|
||||
|
||||
worldVBOVertexID = GL15.glGenBuffers()
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, worldVBOVertexID) //Bind buffer (also specifies type of buffer)
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, worldVBOVertex, GL15.GL_DYNAMIC_DRAW) //Send up the data and specify usage hint.
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, worldVBOVertex, GL15.GL_STATIC_DRAW) //Send up the data and specify usage hint.
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0)
|
||||
|
||||
worldVBOTextureID = GL15.glGenBuffers()
|
||||
@@ -494,7 +504,7 @@ object BlocksDrawer {
|
||||
}
|
||||
|
||||
// draw a breakage
|
||||
if (mode == TERRAIN || mode == WALL) {
|
||||
/*if (mode == TERRAIN || mode == WALL) {
|
||||
val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y)
|
||||
val maxHealth = BlockCodex[world.getTileFromTerrain(x, y)].strength
|
||||
val stage = (breakage / maxHealth).times(breakAnimSteps).roundInt()
|
||||
@@ -503,7 +513,7 @@ object BlocksDrawer {
|
||||
// alpha blending works, but no GL blend func...
|
||||
drawTile(mode, x, y, 5 + stage, 0)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
} // end if (is illuminated)
|
||||
@@ -534,44 +544,55 @@ object BlocksDrawer {
|
||||
}
|
||||
|
||||
// draw - fill up the VBO buffer
|
||||
worldVBOTexture.rewind()
|
||||
for (y in 0..VBO_HEIGHT - 1) {
|
||||
for (x in 0..VBO_WIDTH - 1) {
|
||||
val vx = x * TILE_SIZEF
|
||||
val vy = y * TILE_SIZEF
|
||||
|
||||
val tileID = regionBuffer[y][x]
|
||||
val tileX = (tileID % terrainHorizontalTiles) * TILE_SIZEF
|
||||
val tileY = (tileID / terrainHorizontalTiles) * TILE_SIZEF
|
||||
worldVBOTexture.put(floatArrayOf( // feed GL_TRIANGLE data
|
||||
tileX, tileY,
|
||||
tileX + TILE_SIZEF, tileY,
|
||||
tileX, tileY + TILE_SIZEF,
|
||||
tileX + TILE_SIZEF, tileY,
|
||||
tileX + TILE_SIZEF, tileY + TILE_SIZEF,
|
||||
tileX, tileY + TILE_SIZEF
|
||||
))
|
||||
|
||||
worldVBOTexture.put(floatArrayOf( // feed GL_TRIANGLE data (note: bottom-left is zero)
|
||||
Math.random().toFloat(), Math.random().toFloat(),
|
||||
Math.random().toFloat(), Math.random().toFloat(),
|
||||
Math.random().toFloat(), Math.random().toFloat(),
|
||||
Math.random().toFloat(), Math.random().toFloat()
|
||||
//Math.random().toFloat() * 4096f, Math.random().toFloat() * 4096f,
|
||||
//Math.random().toFloat() * 4096f, Math.random().toFloat() * 4096f
|
||||
)) // FIXME texCoords are wrong?!
|
||||
}
|
||||
}
|
||||
worldVBOTexture.rewind()
|
||||
|
||||
|
||||
// draw - render the VBO
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, when (mode) {
|
||||
val texToBind = when (mode) {
|
||||
TERRAIN, WALL -> tilesTerrain
|
||||
WIRE -> tilesWire
|
||||
else -> throw Error("mode not TERRAIN/WALL/WIRE")
|
||||
}.texture.textureID)
|
||||
}.texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texToBind.textureID)
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT)
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT)
|
||||
|
||||
|
||||
//inGLMatrixStack { // disabled for debugging: won't hotswap
|
||||
GL11.glPushMatrix()
|
||||
|
||||
GL11.glTranslatef(WorldCamera.x.clampTileSize().toFloat() - TILE_SIZEF, WorldCamera.y.clampTileSize().toFloat(), 0f)
|
||||
//GL11.glTranslatef(0f, 0f, 0f)
|
||||
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY)
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, worldVBOVertexID)
|
||||
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0)
|
||||
|
||||
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY)
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, worldVBOTextureID)
|
||||
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0)
|
||||
|
||||
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6 * VBO_WIDTH * VBO_HEIGHT)
|
||||
// for some reason, using 2 VBOs are faster -- presumably because you must fill EVERY ELEMENT when you're using java.nio.Buffer
|
||||
|
||||
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY)
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, worldVBOVertexID)
|
||||
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0)
|
||||
|
||||
GL11.glDrawArrays(GL11.GL_QUADS, 0, 4 * VBO_WIDTH * VBO_HEIGHT)
|
||||
|
||||
GL11.glPopMatrix()
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user