From 0d795d59c83c20fad99b368e64e2b2ea343b997a Mon Sep 17 00:00:00 2001 From: GlFolker <63218676+GlennFolker@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:42:05 +0700 Subject: [PATCH] Per-tile edge regions (#9601) * Delegate more methods into Planet * Per-tile edges * You win, IntelliJ --- .../world/blocks/environment/Floor.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/core/src/mindustry/world/blocks/environment/Floor.java b/core/src/mindustry/world/blocks/environment/Floor.java index db9ae24a3f..6089faf74f 100644 --- a/core/src/mindustry/world/blocks/environment/Floor.java +++ b/core/src/mindustry/world/blocks/environment/Floor.java @@ -77,7 +77,7 @@ public class Floor extends Block{ public int blendId = -1; protected TextureRegion[][] edges; - protected Seq blenders = new Seq<>(); + protected Seq blenders = new Seq<>(); protected Bits blended = new Bits(256); protected int[] dirs = new int[8]; protected TextureRegion edgeRegion; @@ -182,13 +182,17 @@ public class Floor extends Block{ @Override public void drawBase(Tile tile){ Mathf.rand.setSeed(tile.pos()); - Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy()); + Draw.rect(variantRegions[variant(tile.x, tile.y)], tile.worldx(), tile.worldy()); Draw.alpha(1f); drawEdges(tile); drawOverlay(tile); } + public int variant(int x, int y){ + return Mathf.randomSeed(Point2.pack(x, y), 0, Math.max(0, variantRegions.length - 1)); + } + public void drawOverlay(Tile tile){ Floor floor = tile.overlay(); if(floor != Blocks.air && floor != this){ @@ -236,8 +240,8 @@ public class Floor extends Block{ for(int i = 0; i < 8; i++){ Point2 point = Geometry.d8[i]; Tile other = tile.nearby(point); - //special case: empty is, well, empty, so never draw emptyness on top, as that would just be an incorrect black texture - if(other != null && other.floor().cacheLayer == layer && other.floor().edges() != null && other.floor() != Blocks.empty){ + //special case: empty is, well, empty, so never draw emptiness on top, as that would just be an incorrect black texture + if(other != null && other.floor().cacheLayer == layer && other.floor().edges(tile.x, tile.y) != null && other.floor() != Blocks.empty){ if(!blended.getAndSet(other.floor().id)){ blenders.add(other.floor()); dirs[i] = other.floorID(); @@ -258,8 +262,7 @@ public class Floor extends Block{ Point2 point = Geometry.d8[i]; Tile other = tile.nearby(point); - if(other != null && doEdge(tile, other, other.floor()) && other.floor().cacheLayer == realCache && other.floor().edges() != null && other.floor() != Blocks.empty){ - + if(other != null && doEdge(tile, other, other.floor()) && other.floor().cacheLayer == realCache && other.floor().edges(tile.x, tile.y) != null && other.floor() != Blocks.empty){ if(!blended.getAndSet(other.floor().id)){ blenders.add(other.floor()); } @@ -273,12 +276,12 @@ public class Floor extends Block{ protected void drawBlended(Tile tile, boolean checkId){ blenders.sort(a -> a.id); - for(Block block : blenders){ + for(Floor block : blenders){ for(int i = 0; i < 8; i++){ Point2 point = Geometry.d8[i]; Tile other = tile.nearby(point); if(other != null && other.floor() == block && (!checkId || dirs[i] == block.id)){ - TextureRegion region = edge((Floor)block, 1 - point.x, 1 - point.y); + TextureRegion region = block.edge(tile.x, tile.y, 1 - point.x, 1 - point.y); Draw.rect(region, tile.worldx(), tile.worldy()); } } @@ -305,17 +308,23 @@ public class Floor extends Block{ return blendId; } + /** Returns the edge array that should be used to draw at the specified tile position. */ + protected TextureRegion[][] edges(int x, int y){ + return blendGroup.asFloor().edges; + } + + protected TextureRegion edge(int x, int y, int rx, int ry){ + return edges(x, y)[rx][2 - ry]; + } + + @Deprecated protected TextureRegion[][] edges(){ - return ((Floor)blendGroup).edges; + return edges(0, 0); } /** @return whether the edges from {@param other} should be drawn onto this tile **/ protected boolean doEdge(Tile tile, Tile otherTile, Floor other){ - return (other.realBlendId(otherTile) > realBlendId(tile) || edges() == null); - } - - TextureRegion edge(Floor block, int x, int y){ - return block.edges()[x][2 - y]; + return (other.realBlendId(otherTile) > realBlendId(tile) || edges(tile.x, tile.y) == null); } public static class UpdateRenderState{ @@ -328,5 +337,4 @@ public class Floor extends Block{ this.floor = floor; } } - }