diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 15d79a8942..a3514cf76a 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -766,9 +766,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, } public void drawCracks(){ - if(!damaged() || block.size > Block.maxCrackSize) return; + if(!damaged() || block.size > BlockRenderer.maxCrackSize) return; int id = pos(); - TextureRegion region = Block.cracks[block.size - 1][Mathf.clamp((int)((1f - healthf()) * Block.crackRegions), 0, Block.crackRegions-1)]; + TextureRegion region = renderer.blocks.cracks[block.size - 1][Mathf.clamp((int)((1f - healthf()) * BlockRenderer.crackRegions), 0, BlockRenderer.crackRegions-1)]; Draw.colorl(0.2f, 0.1f + (1f - healthf())* 0.6f); Draw.rect(region, x, y, (id%4)*90); Draw.color(); diff --git a/core/src/mindustry/graphics/BlockRenderer.java b/core/src/mindustry/graphics/BlockRenderer.java index a36230f0aa..223540e601 100644 --- a/core/src/mindustry/graphics/BlockRenderer.java +++ b/core/src/mindustry/graphics/BlockRenderer.java @@ -20,11 +20,14 @@ import static arc.Core.*; import static mindustry.Vars.*; public class BlockRenderer implements Disposable{ + public static final int crackRegions = 8, maxCrackSize = 9; + private static final int initialRequests = 32 * 32; private static final int expandr = 9; private static final Color shadowColor = new Color(0, 0, 0, 0.71f); public final FloorRenderer floor = new FloorRenderer(); + public TextureRegion[][] cracks; private Seq tileview = new Seq<>(false, initialRequests, Tile.class); private Seq lightview = new Seq<>(false, initialRequests, Tile.class); @@ -40,6 +43,15 @@ public class BlockRenderer implements Disposable{ public BlockRenderer(){ + Events.on(ClientLoadEvent.class, e -> { + cracks = new TextureRegion[maxCrackSize][crackRegions]; + for(int size = 1; size <= maxCrackSize; size++){ + for(int i = 0; i < crackRegions; i++){ + cracks[size - 1][i] = Core.atlas.find("cracks-" + size + "-" + i); + } + } + }); + Events.on(WorldLoadEvent.class, event -> { shadowEvents.clear(); lastCamY = lastCamX = -99; //invalidate camera position so blocks get updated diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index fee780e145..d493a7f7fe 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -129,7 +129,7 @@ public class LExecutor{ public void setnum(int index, double value){ Var v = vars[index]; if(v.constant) return; - v.numval = Double.isNaN(value) || Double.isInfinite(value) ? 0 : 0; + v.numval = Double.isNaN(value) || Double.isInfinite(value) ? 0 : value; v.objval = null; v.isobj = false; } diff --git a/core/src/mindustry/type/Sector.java b/core/src/mindustry/type/Sector.java index 59fc6de8da..db3587674b 100644 --- a/core/src/mindustry/type/Sector.java +++ b/core/src/mindustry/type/Sector.java @@ -304,10 +304,12 @@ public class Sector{ return Core.settings.getInt(key("secondsi-passed")); } + //TODO this is terrible private String key(String key){ return planet.name + "-s-" + id + "-" + key; } + //TODO this is terrible private void put(String key, Object value){ Core.settings.put(key(key), value); } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 95d9a426e0..53dde34460 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -35,8 +35,6 @@ import java.util.*; import static mindustry.Vars.*; public class Block extends UnlockableContent{ - public static final int crackRegions = 8, maxCrackSize = 9; - public boolean hasItems; public boolean hasLiquids; public boolean hasPower; @@ -212,8 +210,6 @@ public class Block extends UnlockableContent{ public @Load("@-team") TextureRegion teamRegion; public TextureRegion[] teamRegions; - //TODO make this not static - public static TextureRegion[][] cracks; protected static final Seq tempTiles = new Seq<>(); protected static final Seq tempTileEnts = new Seq<>(); @@ -687,15 +683,6 @@ public class Block extends UnlockableContent{ public void load(){ region = Core.atlas.find(name); - if(cracks == null || (cracks[0][0].texture != null && cracks[0][0].texture.isDisposed())){ - cracks = new TextureRegion[maxCrackSize][crackRegions]; - for(int size = 1; size <= maxCrackSize; size++){ - for(int i = 0; i < crackRegions; i++){ - cracks[size - 1][i] = Core.atlas.find("cracks-" + size + "-" + i); - } - } - } - ContentRegions.loadRegions(this); //load specific team regions