diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml
index 57927c5a7..db0626632 100644
--- a/.idea/markdown-navigator/profiles_settings.xml
+++ b/.idea/markdown-navigator/profiles_settings.xml
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
diff --git a/assets/mods/basegame/blocks/wire.tga.gz b/assets/mods/basegame/blocks/wire.tga.gz
index 49883b596..ee55db2ef 100644
--- a/assets/mods/basegame/blocks/wire.tga.gz
+++ b/assets/mods/basegame/blocks/wire.tga.gz
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:70dd73f3c1f0a96a885c3832a45fbb5ea2b24b39f9d3c9c50f685c4818ccf510
-size 74343
+oid sha256:081448d4efc77e674ea0e7a07ecfd806546353ac585a4c7ec85a04c73058b412
+size 31643
diff --git a/assets/tiling.frag b/assets/tiling.frag
index 4ab31c5f2..cb783e518 100644
--- a/assets/tiling.frag
+++ b/assets/tiling.frag
@@ -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);
diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java
index 826f0e41a..7c01c707e 100644
--- a/src/net/torvald/terrarum/AppLoader.java
+++ b/src/net/torvald/terrarum/AppLoader.java
@@ -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 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 //
diff --git a/src/net/torvald/terrarum/modulebasegame/items/WirePieceSignalWire.kt b/src/net/torvald/terrarum/modulebasegame/items/WirePieceSignalWire.kt
index 228777759..ac284c5b8 100644
--- a/src/net/torvald/terrarum/modulebasegame/items/WirePieceSignalWire.kt
+++ b/src/net/torvald/terrarum/modulebasegame/items/WirePieceSignalWire.kt
@@ -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)
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt
index 731adfc9e..e73ed529c 100644
--- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt
+++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt
@@ -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()
diff --git a/work_files/graphics/terrain/wire_single_items.psd b/work_files/graphics/terrain/wire_single_items.psd
index 826e16a47..f5496f0c3 100644
--- a/work_files/graphics/terrain/wire_single_items.psd
+++ b/work_files/graphics/terrain/wire_single_items.psd
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:69a2698668bb60f740a733657aa19eb00c57b0323f7bdb19a3fdba2d78cd8600
-size 496250
+oid sha256:1c4c34c352932cc173d70c71c9244364c9d9df53fe2f2c1d4de402680f2998f4
+size 628894