simple hack for out-of-place render of terrain and lightmap

- Just made them not have negative value
This commit is contained in:
minjaesong
2017-09-14 02:13:37 +09:00
parent efe2e44957
commit f82eab9871
5 changed files with 20 additions and 12 deletions

View File

@@ -135,14 +135,14 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
init {
setHitboxDimension(2, 2, 0, 0)
hitbox.setPosition(
HQRNG().nextInt(demoWorld.width) * FeaturesDrawer.TILE_SIZE.toDouble(),
0.0 // placeholder; camera AI will take it over
38000.0,//HQRNG().nextInt(demoWorld.width) * FeaturesDrawer.TILE_SIZE.toDouble(),
0.0 // Y pos: placeholder; camera AI will take it over
)
noClip = true
}
}
demoWorld.time.timeDelta = 150
//demoWorld.time.timeDelta = 150
LightmapRendererNew.world = demoWorld
@@ -201,7 +201,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
}
fun updateScreen(delta: Float) {
Gdx.graphics.setTitle(TerrarumAppLoader.GAME_NAME +
Gdx.graphics.setTitle("WorldRenderTest" +
" — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" +
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
)
@@ -248,6 +248,12 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
}
private fun renderDemoWorld() {
println("camera TL: ${WorldCamera.x}, ${WorldCamera.y}")
println("camera CN: ${WorldCamera.gdxCamX}, ${WorldCamera.gdxCamY}")
println()
// draw skybox //
setCameraPosition(0f, 0f)
@@ -287,8 +293,8 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
//blendNormal()
batch.color = Color.WHITE
val xrem = -(WorldCamera.x % TILE_SIZEF)
val yrem = -(WorldCamera.y % TILE_SIZEF)
val xrem = -(WorldCamera.x.toFloat() fmod TILE_SIZEF)
val yrem = -(WorldCamera.y.toFloat() fmod TILE_SIZEF)
batch.draw(lightTex,
xrem,
yrem,

View File

@@ -287,8 +287,8 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
//blendNormal()
batch.color = Color.WHITE
val xrem = -(WorldCamera.x % TILE_SIZEF)
val yrem = -(WorldCamera.y % TILE_SIZEF)
val xrem = -(WorldCamera.x.toFloat() fmod TILE_SIZEF)
val yrem = -(WorldCamera.y.toFloat() fmod TILE_SIZEF)
batch.draw(lightTex,
xrem,
yrem,
@@ -471,7 +471,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
class TitleScreenController(val screen: FuckingWorldRenderer) : InputAdapter() {
class TitleScreenController(val screen: TitleScreen) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screen.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) }
return true

View File

@@ -309,3 +309,4 @@ class GameWorld(val width: Int, val height: Int) {
}
infix fun Int.fmod(other: Int) = Math.floorMod(this, other)
infix fun Float.fmod(other: Float) = if (this >= 0f) this % other else (this % other) + other

View File

@@ -11,6 +11,7 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ceilInt
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_TILES
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.io.BufferedOutputStream
@@ -748,7 +749,7 @@ object BlocksDrawer {
shader.setUniformi("tilemap", 2)
shader.setUniformi("tilemapDimension", tilesBuffer.width, tilesBuffer.height)
shader.setUniformf("tilesInAxes", tilesInHorizontal.toFloat(), tilesInVertical.toFloat())
shader.setUniformi("cameraTranslation", WorldCamera.x % TILE_SIZE, WorldCamera.y % TILE_SIZE)
shader.setUniformi("cameraTranslation", WorldCamera.x fmod TILE_SIZE, WorldCamera.y fmod TILE_SIZE)
shader.setUniformi("tileSizeInPx", TILE_SIZE)
shader.setUniformi("tilesInAtlas", tileAtlas.horizontalCount, tileAtlas.verticalCount) //depends on the tile atlas
shader.setUniformi("atlasTexSize", tileAtlas.texture.width, tileAtlas.texture.height) //depends on the tile atlas

View File

@@ -37,8 +37,7 @@ object WorldCamera {
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))
// position - (WH / 2)
x = (// X only: ROUNDWORLD implementation
player.hitbox.centeredX.toFloat() - width / 2).floorInt()
x = player.hitbox.startX.toFloat().floorInt() // X only: ROUNDWORLD implementation
y = (FastMath.clamp(
player.hitbox.centeredY.toFloat() - height / 2,
TILE_SIZE.toFloat(),
@@ -46,6 +45,7 @@ object WorldCamera {
)).floorInt().clampCameraY(world)
gdxCamX = x + (width / 2f).floor()
gdxCamY = y + (height / 2f).floor()
}