From 96149974822764c4a7a29fa92bd8986836baa0a8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 10 Dec 2021 11:55:17 -0500 Subject: [PATCH] Temporary measure to reduce atlas size --- .../src/mindustry/graphics/BlockRenderer.java | 3 +- .../src/mindustry/graphics/LightRenderer.java | 1 - core/src/mindustry/world/Tile.java | 37 ++++++++++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/core/src/mindustry/graphics/BlockRenderer.java b/core/src/mindustry/graphics/BlockRenderer.java index 257486ccd6..fc5ec177ce 100644 --- a/core/src/mindustry/graphics/BlockRenderer.java +++ b/core/src/mindustry/graphics/BlockRenderer.java @@ -21,7 +21,8 @@ import static arc.Core.*; import static mindustry.Vars.*; public class BlockRenderer{ - public static final int crackRegions = 8, maxCrackSize = 9; + //TODO cracks take up far to much space, so I had to limit it to 7. this means larger blocks won't have cracks - draw tiling mirrored stuff instead? + public static final int crackRegions = 8, maxCrackSize = 7; private static final int initialRequests = 32 * 32; private static final Color shadowColor = new Color(0, 0, 0, 0.71f), blendShadowColor = Color.white.cpy().lerp(Color.black, shadowColor.a); diff --git a/core/src/mindustry/graphics/LightRenderer.java b/core/src/mindustry/graphics/LightRenderer.java index 1a83e7d548..c28da979de 100644 --- a/core/src/mindustry/graphics/LightRenderer.java +++ b/core/src/mindustry/graphics/LightRenderer.java @@ -69,7 +69,6 @@ public class LightRenderer{ float u2 = lmid.u2; float v2 = lmid.v; - Vec2 v1 = Tmp.v1.trnsExact(rot + 90f, stroke); float lx1 = x - v1.x, ly1 = y - v1.y, lx2 = x + v1.x, ly2 = y + v1.y, diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 300e8d0e2d..4d6652635d 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -21,6 +21,8 @@ import mindustry.world.blocks.environment.*; import static mindustry.Vars.*; public class Tile implements Position, QuadTreeObject, Displayable{ + private static boolean tileChangeLock = false; + private static boolean tilePreChangeLock = false; private static final TileChangeEvent tileChange = new TileChangeEvent(); private static final TilePreChangeEvent preChange = new TilePreChangeEvent(); private static final ObjectSet tileSet = new ObjectSet<>(); @@ -530,9 +532,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{ } protected void preChanged(){ - if(!world.isGenerating()){ - Events.fire(preChange.set(this)); - } + firePreChange(); if(build != null){ //only call removed() for the center block - this only gets called once. @@ -552,7 +552,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{ //reset entity and block *manually* - thus, preChanged() will not be called anywhere else, for multiblocks if(other != this){ //do not remove own entity so it can be processed in changed() //manually call pre-change event for other tile - Events.fire(preChange.set(other)); + other.firePreChange(); other.build = null; other.block = Blocks.air; @@ -619,7 +619,34 @@ public class Tile implements Position, QuadTreeObject, Displayable{ protected void fireChanged(){ if(!world.isGenerating()){ - Events.fire(tileChange.set(this)); + + //A TileChangeEvent may cause other TileChangeEvents to occur, and if that happens, allocate a new instance. + boolean wasLocked = tileChangeLock; + var eventInst = wasLocked ? new TileChangeEvent() : tileChange; + tileChangeLock = true; + + Events.fire(eventInst.set(this)); + + //unlock after it's done + if(!wasLocked){ + tileChangeLock = false; + } + } + } + + protected void firePreChange(){ + if(!world.isGenerating()){ + + //same as above + boolean wasLocked = tilePreChangeLock; + var eventInst = wasLocked ? new TilePreChangeEvent() : preChange; + tilePreChangeLock = true; + + Events.fire(eventInst.set(this)); + + if(!wasLocked){ + tilePreChangeLock = false; + } } }