mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
blocksdrawer now draws wire
This commit is contained in:
2
.idea/markdown-navigator/profiles_settings.xml
generated
2
.idea/markdown-navigator/profiles_settings.xml
generated
@@ -1,3 +1,3 @@
|
||||
<component name="MarkdownNavigator.ProfileManager">
|
||||
<settings default="" pdf-export="" />
|
||||
<settings default="" pdf-export="" plain-text-search-scope="Project Files" />
|
||||
</component>
|
||||
Binary file not shown.
@@ -40,6 +40,8 @@ uniform vec4 colourFilter = vec4(1, 1, 1, 1); // used by WALL to darken it
|
||||
|
||||
uniform ivec2 cameraTranslation = ivec2(0, 0);
|
||||
|
||||
uniform float drawBreakage = 1f;
|
||||
|
||||
|
||||
ivec2 getTileXY(int tileNumber) {
|
||||
return ivec2(tileNumber % int(tilesInAtlas.x), tileNumber / int(tilesInAtlas.x));
|
||||
@@ -108,7 +110,13 @@ void main() {
|
||||
|
||||
vec4 finalTile = mix(tileCol, tileAltCol, tilesBlend);
|
||||
|
||||
vec4 finalBreakage = texture2D(tilesAtlas, finalUVCoordForBreakage);
|
||||
vec4 finalBreakage;
|
||||
if (drawBreakage == 0f) {
|
||||
finalBreakage = vec4(0f);
|
||||
}
|
||||
else {
|
||||
finalBreakage = texture2D(tilesAtlas, finalUVCoordForBreakage);
|
||||
}
|
||||
|
||||
vec4 finalColor = vec4(mix(finalTile.rgb, finalBreakage.rgb, finalBreakage.a), finalTile.a);
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.github.strikerx3.jxinput.XInputDevice;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.torvald.util.ArrayListMap;
|
||||
import net.torvald.getcpuname.GetCpuName;
|
||||
import net.torvald.terrarum.blockstats.MinimapComposer;
|
||||
import net.torvald.terrarum.controller.GdxControllerAdapter;
|
||||
@@ -34,10 +33,12 @@ import net.torvald.terrarum.worlddrawer.BlocksDrawer;
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer;
|
||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack;
|
||||
import net.torvald.util.ArrayListMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
|
||||
import static net.torvald.terrarum.TerrarumKt.gdxClearAndSetBlend;
|
||||
@@ -284,11 +285,14 @@ public class AppLoader implements ApplicationListener {
|
||||
private FrameBuffer renderFBO;
|
||||
|
||||
public static CommonResourcePool resourcePool;
|
||||
public static HashSet<File> tempFilePool = new HashSet();
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
resourcePool = CommonResourcePool.INSTANCE;
|
||||
|
||||
newTempFile("wenquanyi.tga"); // temp file required by the font
|
||||
|
||||
|
||||
// set basis of draw
|
||||
logoBatch = new SpriteBatch();
|
||||
@@ -376,13 +380,6 @@ public class AppLoader implements ApplicationListener {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @link http://bilgin.esme.org/BitsAndBytes/KalmanFilterforDummies
|
||||
*/
|
||||
private void updateKalmanRenderDelta() {
|
||||
// moved to LwjglGraphics
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Gdx.gl.glDisable(GL20.GL_DITHER);
|
||||
@@ -544,8 +541,7 @@ public class AppLoader implements ApplicationListener {
|
||||
|
||||
ModMgr.INSTANCE.disposeMods();
|
||||
|
||||
// delete temp files
|
||||
new File("./tmp_wenquanyi.tga").delete(); // FIXME this is pretty much ad-hoc
|
||||
deleteTempfiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -702,6 +698,17 @@ public class AppLoader implements ApplicationListener {
|
||||
//dirs.forEach { if (!it.exists()) it.mkdirs() }
|
||||
}
|
||||
|
||||
public static File newTempFile(String filename) {
|
||||
File tempfile = new File("./tmp_" + filename);
|
||||
tempFilePool.add(tempfile);
|
||||
return tempfile;
|
||||
}
|
||||
|
||||
private static void deleteTempfiles() {
|
||||
for (File file : tempFilePool) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
// CONFIG //
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame.items
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.blockproperties.Wire
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
@@ -31,10 +30,10 @@ class WirePieceSignalWire(override val originalID: ItemID) : GameItem() {
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(delta: Float): Boolean {
|
||||
return BlockBase.wireStartPrimaryUse(this, Wire.BIT_SIGNAL_RED, delta)
|
||||
return BlockBase.wireStartPrimaryUse(this, 64, delta)
|
||||
}
|
||||
|
||||
override fun effectWhenEquipped(delta: Float) {
|
||||
BlockBase.wireEffectWhenEquipped(Wire.BIT_SIGNAL_RED, delta)
|
||||
BlockBase.wireEffectWhenEquipped(64, delta)
|
||||
}
|
||||
}
|
||||
@@ -123,10 +123,8 @@ internal object BlocksDrawer {
|
||||
TextureRegionPack(Texture(CreateTileAtlas.atlasWinter), TILE_SIZE, TILE_SIZE)
|
||||
)
|
||||
|
||||
// unzip tga.gz for tilesWire and tilesFluid
|
||||
|
||||
//TODO
|
||||
tilesWire = TextureRegionPack(Texture(8, 8, Pixmap.Format.RGBA8888), 1, 1)
|
||||
//TODO make wire work with the TileAtlas system
|
||||
tilesWire = TextureRegionPack(ModMgr.getGdxFile("basegame", "blocks/wire.tga"), TILE_SIZE, TILE_SIZE)
|
||||
tilesFluid = TextureRegionPack(Texture(CreateTileAtlas.atlasFluid), TILE_SIZE, TILE_SIZE)
|
||||
|
||||
|
||||
@@ -267,14 +265,11 @@ internal object BlocksDrawer {
|
||||
|
||||
/**
|
||||
* Turns bitmask-with-single-bit-set into its bit index. The LSB is counted as 1, and thus the index starts at one.
|
||||
* @return 0 -> null, 1 -> 0, 2 -> 1, 4 -> 2, 8 -> 3, 16 -> 4, ...
|
||||
* @return 0 -> -1, 1 -> 0, 2 -> 1, 4 -> 2, 8 -> 3, 16 -> 4, ...
|
||||
*/
|
||||
private fun Int.toBitOrd(): Int? {
|
||||
//if (this > 0 && !FastMath.isPowerOfTwo(this)) throw IllegalArgumentException("value must be power of two: $this")
|
||||
//else {
|
||||
val k = FastMath.intLog2(this, -1)
|
||||
return if (k == -1) null else k
|
||||
//}
|
||||
private fun Int.toBitOrd(): Int {
|
||||
val k = FastMath.intLog2(this, -1)
|
||||
return k
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +307,7 @@ internal object BlocksDrawer {
|
||||
val thisTile = when (mode) {
|
||||
WALL -> world.getTileFromWall(x, y)
|
||||
TERRAIN -> world.getTileFromTerrain(x, y)
|
||||
WIRE -> world.getWiringBlocks(x, y).and(drawWires).toBitOrd()
|
||||
WIRE -> world.getWiringBlocks(x, y).and(drawWires).toBitOrd() * 16
|
||||
FLUID -> world.getFluid(x, y).type.abs()
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
@@ -323,6 +318,9 @@ internal object BlocksDrawer {
|
||||
val nearbyTilesInfo = if (mode == FLUID) {
|
||||
getNearbyTilesInfoFluids(x, y)
|
||||
}
|
||||
else if (mode == WIRE) {
|
||||
getNearbyWiringInfo(x, y, thisTile)
|
||||
}
|
||||
else if (isPlatform(thisTile)) {
|
||||
getNearbyTilesInfoPlatform(x, y)
|
||||
}
|
||||
@@ -343,10 +341,16 @@ internal object BlocksDrawer {
|
||||
val tileNumberBase =
|
||||
if (mode == FLUID)
|
||||
CreateTileAtlas.fluidToTileNumber(world.getFluid(x, y))
|
||||
else if (mode == WIRE)
|
||||
thisTile
|
||||
else
|
||||
renderTag.tileNumber
|
||||
val tileNumber = if (thisTile == 0) 0
|
||||
val tileNumber = if (mode != WIRE && thisTile == 0) 0
|
||||
// special case: fluids
|
||||
else if (mode == FLUID) tileNumberBase + connectLut47[nearbyTilesInfo]
|
||||
// special case: wires
|
||||
else if (mode == WIRE) tileNumberBase + connectLut16[nearbyTilesInfo]
|
||||
// rest of the cases: terrain and walls
|
||||
else tileNumberBase + when (renderTag.maskType) {
|
||||
CreateTileAtlas.RenderTag.MASK_NA -> 0
|
||||
CreateTileAtlas.RenderTag.MASK_16 -> connectLut16[nearbyTilesInfo]
|
||||
@@ -370,7 +374,11 @@ internal object BlocksDrawer {
|
||||
|
||||
// draw a tile
|
||||
|
||||
if (mode == FLUID) {
|
||||
if (mode == WIRE && thisTile < 0) {
|
||||
// no wire here, draw block id 255 (bottom right)
|
||||
writeToBuffer(mode, bufferX, bufferY, 15, 15, 0)
|
||||
}
|
||||
else if (mode == FLUID || mode == WIRE) {
|
||||
writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, 0)
|
||||
}
|
||||
else {
|
||||
@@ -409,6 +417,25 @@ internal object BlocksDrawer {
|
||||
return ret
|
||||
}
|
||||
|
||||
/**
|
||||
* @param wire -1 for none, 0 for signal red, 1 for untility prototype, 2 for low power, 3 for high power;
|
||||
* log of bits defined in [net.torvald.terrarum.blockproperties.Wire]
|
||||
*
|
||||
* @return offset from the spritesheet's "base" tile number, 0..15.
|
||||
*/
|
||||
private fun getNearbyWiringInfo(x: Int, y: Int, wire: Int): Int {
|
||||
val nearbyTiles = getNearbyTilesPos(x, y).map { world.getWiringBlocks(it.x, it.y).and(drawWires).toBitOrd() * 16 }
|
||||
|
||||
var ret = 0
|
||||
for (i in 0 until nearbyTiles.size) {
|
||||
if (nearbyTiles[i] == wire) {
|
||||
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun getNearbyTilesInfoConMutual(x: Int, y: Int, mode: Int): Int {
|
||||
val nearbyTiles = getNearbyTilesPos(x, y).map { world.getTileFrom(mode, it.x, it.y) ?: Block.NULL }
|
||||
|
||||
@@ -608,6 +635,7 @@ internal object BlocksDrawer {
|
||||
else
|
||||
0f
|
||||
)
|
||||
shader.setUniformf("drawBreakage", if (mode == WIRE) 0f else 1f)
|
||||
tilesQuad.render(shader, GL20.GL_TRIANGLES)
|
||||
shader.end()
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user