mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
rudimentary fluid rendering so that I can work on it
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
CatStdout
|
||||
CheatWarnTest
|
||||
CodexEdictis
|
||||
ExportAtlas
|
||||
ExportCodices
|
||||
ExportMap
|
||||
ExportMap2
|
||||
|
||||
|
@@ -46,8 +46,7 @@ object WorldSimulator {
|
||||
const val FLUID_MAX_MASS = 1f // The normal, un-pressurized mass of a full water cell
|
||||
const val FLUID_MAX_COMP = 0.02f // How much excess water a cell can store, compared to the cell above it. A tile of fluid can contain more than MaxMass water.
|
||||
const val FLUID_MIN_MASS = net.torvald.terrarum.gameworld.FLUID_MIN_MASS //Ignore cells that are almost dry (smaller than epsilon of float16)
|
||||
const val WIRE_MIN_FLOW = 0.0001f
|
||||
const val minFlow = 0.01f
|
||||
const val minFlow = 1f / 512f
|
||||
const val maxSpeed = 1f // max units of water moved out of one block to another, per timestamp
|
||||
|
||||
// END OF FLUID-RELATED STUFFS
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import net.torvald.gdx.graphics.PixmapIO2
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-07-15.
|
||||
*/
|
||||
class ExportAtlas : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val dir = App.defaultDir + "/Exports/"
|
||||
val dirAsFile = File(dir)
|
||||
if (!dirAsFile.exists()) {
|
||||
dirAsFile.mkdir()
|
||||
}
|
||||
|
||||
PixmapIO2.writeTGA(Gdx.files.absolute("$dir${args[1]}.tga"), App.tileMaker.atlas, false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: exportatlas <name>")
|
||||
Echo("Exports current tile atlas into an image.")
|
||||
Echo("The image can be found at %appdata%/terrarum/Exports")
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ internal object ExportMap : ConsoleCommand {
|
||||
override fun printUsage() {
|
||||
|
||||
Echo("Usage: export <name>")
|
||||
Echo("Exports current map into echo image.")
|
||||
Echo("Exports current map into an image.")
|
||||
Echo("The image can be found at %appdata%/terrarum/Exports")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ class ItemBottomlessWaterBucket(originalID: ItemID) : GameItem(originalID) {
|
||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
|
||||
val mx = Terrarum.mouseTileX; val my =Terrarum.mouseTileY
|
||||
INGAME.world.setFluid(mx, my, Fluid.WATER, 1f)
|
||||
printdbg(this, "Pouring water at ($mx, $my)")
|
||||
return 0L
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,6 @@ internal object BlocksDrawer {
|
||||
val tileItemWall: TextureRegionPack
|
||||
val tileItemWallGlow: TextureRegionPack
|
||||
val tileItemWallEmissive: TextureRegionPack
|
||||
val tilesFluid: TextureRegionPack
|
||||
val tilesGlow: TextureRegionPack
|
||||
val tilesEmissive: TextureRegionPack
|
||||
|
||||
@@ -69,7 +68,6 @@ internal object BlocksDrawer {
|
||||
val WALL = GameWorld.WALL
|
||||
val TERRAIN = GameWorld.TERRAIN
|
||||
val ORES = GameWorld.ORES
|
||||
//val WIRE = GameWorld.WIRE
|
||||
val FLUID = -2
|
||||
val OCCLUSION = 31337
|
||||
|
||||
@@ -92,7 +90,6 @@ internal object BlocksDrawer {
|
||||
private lateinit var terrainTilesBuffer: Array<IntArray>
|
||||
private lateinit var wallTilesBuffer: Array<IntArray>
|
||||
private lateinit var oreTilesBuffer: Array<IntArray>
|
||||
//private lateinit var wireTilesBuffer: Array<IntArray>
|
||||
private lateinit var fluidTilesBuffer: Array<IntArray>
|
||||
private lateinit var occlusionBuffer: Array<IntArray>
|
||||
private var tilesBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888)
|
||||
@@ -120,8 +117,6 @@ internal object BlocksDrawer {
|
||||
TextureRegionPack(Texture(App.tileMaker.atlasHibernal), TILE_SIZE, TILE_SIZE),
|
||||
)
|
||||
|
||||
//tilesWire = TextureRegionPack(ModMgr.getGdxFile("basegame", "wires/wire.tga"), TILE_SIZE, TILE_SIZE)
|
||||
tilesFluid = TextureRegionPack(Texture(App.tileMaker.atlasFluid), TILE_SIZE, TILE_SIZE)
|
||||
tilesGlow = TextureRegionPack(Texture(App.tileMaker.atlasGlow), TILE_SIZE, TILE_SIZE)
|
||||
tilesEmissive = TextureRegionPack(Texture(App.tileMaker.atlasEmissive), TILE_SIZE, TILE_SIZE)
|
||||
|
||||
@@ -247,13 +242,7 @@ internal object BlocksDrawer {
|
||||
renderUsingBuffer(FLUID, projectionMatrix, false, drawEmissive)
|
||||
|
||||
|
||||
|
||||
gdxBlendNormalStraightAlpha()
|
||||
|
||||
/*if (selectedWireRenderClass.isNotBlank()) {
|
||||
//println("Wires! draw: $drawWires") // use F10 instead
|
||||
renderUsingBuffer(WIRE, projectionMatrix, false)
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,7 +351,7 @@ internal object BlocksDrawer {
|
||||
TERRAIN -> world.layerTerrain.unsafeGetTile(wx, wy)
|
||||
ORES -> world.layerOres.unsafeGetTile(wx, wy)//.also { println(it) }
|
||||
FLUID -> world.layerFluids.unsafeGetTile1(wx, wy).let { (number, fill) ->
|
||||
if (fill < 1f/30f) 0
|
||||
if (number == 65535 || fill < 1f/30f) 0
|
||||
else number
|
||||
}
|
||||
OCCLUSION -> 0
|
||||
@@ -414,6 +403,7 @@ internal object BlocksDrawer {
|
||||
}
|
||||
|
||||
val renderTag = if (mode == OCCLUSION) occlusionRenderTag else App.tileMaker.getRenderTag(thisTile)
|
||||
|
||||
val tileNumberBase = renderTag.tileNumber
|
||||
var tileNumber = if (thisTile == 0 && mode != OCCLUSION) 0
|
||||
// special case: actorblocks and F3 key
|
||||
@@ -436,7 +426,7 @@ internal object BlocksDrawer {
|
||||
|
||||
// hide tiles with super low lights, kinda like Minecraft's Orebfuscator
|
||||
val lightAtXY = LightmapRenderer.getLight(x, y) ?: Cvec(0)
|
||||
if (maxOf(lightAtXY.fastLum(), lightAtXY.a) <= 1.5f / 255f) {
|
||||
if (mode != FLUID && mode != OCCLUSION && maxOf(lightAtXY.fastLum(), lightAtXY.a) <= 1.5f / 255f) {
|
||||
tileNumber = 2 // black solid
|
||||
}
|
||||
|
||||
@@ -700,7 +690,6 @@ internal object BlocksDrawer {
|
||||
TERRAIN -> terrainTilesBuffer
|
||||
WALL -> wallTilesBuffer
|
||||
ORES -> oreTilesBuffer
|
||||
//WIRE -> wireTilesBuffer
|
||||
FLUID -> fluidTilesBuffer
|
||||
OCCLUSION -> occlusionBuffer
|
||||
else -> throw IllegalArgumentException()
|
||||
@@ -723,22 +712,19 @@ internal object BlocksDrawer {
|
||||
|
||||
|
||||
val tileAtlas = when (mode) {
|
||||
TERRAIN, ORES, WALL, OCCLUSION -> tilesTerrain
|
||||
//WIRE -> tilesWire
|
||||
FLUID -> tilesFluid
|
||||
TERRAIN, ORES, WALL, OCCLUSION, FLUID -> tilesTerrain
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
val sourceBuffer = when(mode) {
|
||||
TERRAIN -> terrainTilesBuffer
|
||||
WALL -> wallTilesBuffer
|
||||
ORES -> oreTilesBuffer
|
||||
//WIRE -> wireTilesBuffer
|
||||
FLUID -> fluidTilesBuffer
|
||||
OCCLUSION -> occlusionBuffer
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
val vertexColour = when (mode) {
|
||||
TERRAIN, /*WIRE,*/ ORES, FLUID, OCCLUSION -> Color.WHITE
|
||||
TERRAIN, ORES, FLUID, OCCLUSION -> Color.WHITE
|
||||
WALL -> WALL_OVERLAY_COLOUR
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
@@ -798,7 +784,6 @@ internal object BlocksDrawer {
|
||||
0f
|
||||
)
|
||||
shader.setUniformf("mulBlendIntensity", if (mode == OCCLUSION) occlusionIntensity else 1f)
|
||||
//shader.setUniformf("drawBreakage", if (mode == WIRE) 0f else 1f)
|
||||
tilesQuad.render(shader, GL20.GL_TRIANGLE_FAN)
|
||||
|
||||
//tilesBufferAsTex.dispose()
|
||||
@@ -897,7 +882,6 @@ internal object BlocksDrawer {
|
||||
tileItemWall.dispose()
|
||||
tileItemWallGlow.dispose()
|
||||
tileItemWallEmissive.dispose()
|
||||
tilesFluid.dispose()
|
||||
tilesBuffer.dispose()
|
||||
_tilesBufferAsTex.dispose()
|
||||
tilesQuad.tryDispose()
|
||||
|
||||
@@ -47,7 +47,6 @@ class CreateTileAtlas {
|
||||
lateinit var atlasSerotinal: Pixmap
|
||||
lateinit var atlasAutumnal: Pixmap
|
||||
lateinit var atlasHibernal: Pixmap
|
||||
lateinit var atlasFluid: Pixmap
|
||||
lateinit var atlasGlow: Pixmap // glowing won't be affected by the season... for now
|
||||
lateinit var atlasEmissive: Pixmap // glowing won't be affected by the season... for now
|
||||
lateinit var itemTerrainTexture: Texture
|
||||
@@ -146,7 +145,6 @@ class CreateTileAtlas {
|
||||
atlasSerotinal = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
|
||||
atlasAutumnal = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
|
||||
atlasHibernal = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
|
||||
atlasFluid = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
|
||||
atlasGlow = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
|
||||
atlasEmissive = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
|
||||
|
||||
@@ -508,7 +506,6 @@ class CreateTileAtlas {
|
||||
SEROTINAL -> atlasSerotinal.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
|
||||
AUTUMNAL -> atlasAutumnal.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
|
||||
HIBERNAL -> atlasHibernal.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
|
||||
FLUID -> atlasFluid.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
|
||||
GLOW -> atlasGlow.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
|
||||
EMISSIVE -> atlasEmissive.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
|
||||
else -> throw IllegalArgumentException("Unknown draw source $source")
|
||||
@@ -556,7 +553,6 @@ class CreateTileAtlas {
|
||||
atlasSerotinal.dispose()
|
||||
atlasAutumnal.dispose()
|
||||
atlasHibernal.dispose()
|
||||
atlasFluid.dispose()
|
||||
atlasGlow.dispose()
|
||||
atlasEmissive.dispose()
|
||||
//itemTerrainTexture.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemTerrain (TextureRegionPack)'
|
||||
@@ -570,7 +566,7 @@ class CreateTileAtlas {
|
||||
}
|
||||
|
||||
private enum class AtlasSource {
|
||||
/*FOUR_SEASONS, SUMMER, AUTUMN, WINTER, SPRING,*/ FLUID, GLOW, EMISSIVE,
|
||||
/*FOUR_SEASONS, SUMMER, AUTUMN, WINTER, SPRING,*/ GLOW, EMISSIVE,
|
||||
SIX_SEASONS, PREVERNAL, VERNAL, AESTIVAL, SEROTINAL, AUTUMNAL, HIBERNAL,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user