Per-tile edge regions (#9601)
* Delegate more methods into Planet * Per-tile edges * You win, IntelliJ
This commit is contained in:
@@ -77,7 +77,7 @@ public class Floor extends Block{
|
|||||||
public int blendId = -1;
|
public int blendId = -1;
|
||||||
|
|
||||||
protected TextureRegion[][] edges;
|
protected TextureRegion[][] edges;
|
||||||
protected Seq<Block> blenders = new Seq<>();
|
protected Seq<Floor> blenders = new Seq<>();
|
||||||
protected Bits blended = new Bits(256);
|
protected Bits blended = new Bits(256);
|
||||||
protected int[] dirs = new int[8];
|
protected int[] dirs = new int[8];
|
||||||
protected TextureRegion edgeRegion;
|
protected TextureRegion edgeRegion;
|
||||||
@@ -182,13 +182,17 @@ public class Floor extends Block{
|
|||||||
@Override
|
@Override
|
||||||
public void drawBase(Tile tile){
|
public void drawBase(Tile tile){
|
||||||
Mathf.rand.setSeed(tile.pos());
|
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);
|
Draw.alpha(1f);
|
||||||
drawEdges(tile);
|
drawEdges(tile);
|
||||||
drawOverlay(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){
|
public void drawOverlay(Tile tile){
|
||||||
Floor floor = tile.overlay();
|
Floor floor = tile.overlay();
|
||||||
if(floor != Blocks.air && floor != this){
|
if(floor != Blocks.air && floor != this){
|
||||||
@@ -236,8 +240,8 @@ public class Floor extends Block{
|
|||||||
for(int i = 0; i < 8; i++){
|
for(int i = 0; i < 8; i++){
|
||||||
Point2 point = Geometry.d8[i];
|
Point2 point = Geometry.d8[i];
|
||||||
Tile other = tile.nearby(point);
|
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
|
//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() != null && other.floor() != Blocks.empty){
|
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)){
|
if(!blended.getAndSet(other.floor().id)){
|
||||||
blenders.add(other.floor());
|
blenders.add(other.floor());
|
||||||
dirs[i] = other.floorID();
|
dirs[i] = other.floorID();
|
||||||
@@ -258,8 +262,7 @@ public class Floor extends Block{
|
|||||||
Point2 point = Geometry.d8[i];
|
Point2 point = Geometry.d8[i];
|
||||||
Tile other = tile.nearby(point);
|
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)){
|
if(!blended.getAndSet(other.floor().id)){
|
||||||
blenders.add(other.floor());
|
blenders.add(other.floor());
|
||||||
}
|
}
|
||||||
@@ -273,12 +276,12 @@ public class Floor extends Block{
|
|||||||
protected void drawBlended(Tile tile, boolean checkId){
|
protected void drawBlended(Tile tile, boolean checkId){
|
||||||
blenders.sort(a -> a.id);
|
blenders.sort(a -> a.id);
|
||||||
|
|
||||||
for(Block block : blenders){
|
for(Floor block : blenders){
|
||||||
for(int i = 0; i < 8; i++){
|
for(int i = 0; i < 8; i++){
|
||||||
Point2 point = Geometry.d8[i];
|
Point2 point = Geometry.d8[i];
|
||||||
Tile other = tile.nearby(point);
|
Tile other = tile.nearby(point);
|
||||||
if(other != null && other.floor() == block && (!checkId || dirs[i] == block.id)){
|
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());
|
Draw.rect(region, tile.worldx(), tile.worldy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,17 +308,23 @@ public class Floor extends Block{
|
|||||||
return blendId;
|
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(){
|
protected TextureRegion[][] edges(){
|
||||||
return ((Floor)blendGroup).edges;
|
return edges(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return whether the edges from {@param other} should be drawn onto this tile **/
|
/** @return whether the edges from {@param other} should be drawn onto this tile **/
|
||||||
protected boolean doEdge(Tile tile, Tile otherTile, Floor other){
|
protected boolean doEdge(Tile tile, Tile otherTile, Floor other){
|
||||||
return (other.realBlendId(otherTile) > realBlendId(tile) || edges() == null);
|
return (other.realBlendId(otherTile) > realBlendId(tile) || edges(tile.x, tile.y) == null);
|
||||||
}
|
|
||||||
|
|
||||||
TextureRegion edge(Floor block, int x, int y){
|
|
||||||
return block.edges()[x][2 - y];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class UpdateRenderState{
|
public static class UpdateRenderState{
|
||||||
@@ -328,5 +337,4 @@ public class Floor extends Block{
|
|||||||
this.floor = floor;
|
this.floor = floor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user