mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 19:39:04 +07:00
Conduit autotile, cleanup
This commit is contained in:
parent
20462b91d4
commit
335c1779ef
@ -141,6 +141,9 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
rotation = Mathf.mod(rotation + (int)Core.input.axisTap(Binding.rotate), 4);
|
||||
if(Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0 && isPlacing() && mode == placing){
|
||||
updateLine(selectX, selectY);
|
||||
}
|
||||
|
||||
Tile cursor = tileAt(Core.input.mouseX(), Core.input.mouseY());
|
||||
|
||||
@ -225,7 +228,7 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
if(mode == placing && block != null){
|
||||
if (!overrideLineRotation && !Core.input.keyDown(Binding.diagonal_placement) && (selectX != cursorX || selectY != cursorY) && ((int) Core.input.axisTap(Binding.rotate) != 0)){
|
||||
if(!overrideLineRotation && !Core.input.keyDown(Binding.diagonal_placement) && (selectX != cursorX || selectY != cursorY) && ((int) Core.input.axisTap(Binding.rotate) != 0)){
|
||||
rotation = ((int)((Angles.angle(selectX, selectY, cursorX, cursorY) + 45) / 90f)) % 4;
|
||||
overrideLineRotation = true;
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
|
||||
float angle = Angles.angle(startX, startY, endX, endY);
|
||||
int baseRotation = rotation;
|
||||
if (!overrideLineRotation || diagonal){
|
||||
if(!overrideLineRotation || diagonal){
|
||||
baseRotation = (startX == endX && startY == endY) ? rotation : ((int)((angle + 45) / 90f)) % 4;
|
||||
}
|
||||
|
||||
@ -491,7 +491,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
Point2 next = i == points.size - 1 ? null : points.get(i + 1);
|
||||
line.x = point.x;
|
||||
line.y = point.y;
|
||||
if (!overrideLineRotation || diagonal){
|
||||
if(!overrideLineRotation || diagonal){
|
||||
line.rotation = next != null ? Tile.relativeTo(point.x, point.y, next.x, next.y) : baseRotation;
|
||||
}else{
|
||||
line.rotation = rotation;
|
||||
|
96
core/src/io/anuke/mindustry/world/blocks/Autotiler.java
Normal file
96
core/src/io/anuke/mindustry/world/blocks/Autotiler.java
Normal file
@ -0,0 +1,96 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface Autotiler{
|
||||
class AutotilerHolder{
|
||||
static final int[] blendresult = new int[3];
|
||||
static final BuildRequest[] directionals = new BuildRequest[4];
|
||||
}
|
||||
|
||||
default @Nullable int[] getTiling(BuildRequest req, Eachable<BuildRequest> list){
|
||||
if(req.tile() == null) return null;
|
||||
BuildRequest[] directionals = AutotilerHolder.directionals;
|
||||
|
||||
Arrays.fill(directionals, null);
|
||||
list.each(other -> {
|
||||
if(other.breaking || other == req) return;
|
||||
|
||||
int i = 0;
|
||||
for(Point2 point : Geometry.d4){
|
||||
int x = req.x + point.x, y = req.y + point.y;
|
||||
if(x >= other.x -(other.block.size - 1) / 2 && x <= other.x + (other.block.size / 2) && y >= other.y -(other.block.size - 1) / 2 && y <= other.y + (other.block.size / 2)){
|
||||
directionals[i] = other;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
});
|
||||
|
||||
return buildBlending(req.tile(), req.rotation, directionals);
|
||||
}
|
||||
|
||||
default int[] buildBlending(Tile tile, int rotation, BuildRequest[] directional){
|
||||
int[] blendresult = AutotilerHolder.blendresult;
|
||||
blendresult[0] = 0;
|
||||
blendresult[1] = blendresult[2] = 1;
|
||||
int num =
|
||||
(blends(tile, rotation, directional, 2) && blends(tile, rotation, directional, 1) && blends(tile, rotation, directional, 3)) ? 0 :
|
||||
(blends(tile, rotation, directional, 1) && blends(tile, rotation, directional, 3)) ? 1 :
|
||||
(blends(tile, rotation, directional, 1) && blends(tile, rotation, directional, 2)) ? 2 :
|
||||
(blends(tile, rotation, directional, 3) && blends(tile, rotation, directional, 2)) ? 3 :
|
||||
blends(tile, rotation, directional, 1) ? 4 :
|
||||
blends(tile, rotation, directional, 3) ? 5 :
|
||||
-1;
|
||||
transformCase(num, blendresult);
|
||||
return blendresult;
|
||||
}
|
||||
|
||||
default void transformCase(int num, int[] bits){
|
||||
if(num == 0){
|
||||
bits[0] = 3;
|
||||
}else if(num == 1){
|
||||
bits[0] = 4;
|
||||
}else if(num == 2){
|
||||
bits[0] = 2;
|
||||
}else if(num == 3){
|
||||
bits[0] = 2;
|
||||
bits[2] = -1;
|
||||
}else if(num == 4){
|
||||
bits[0] = 1;
|
||||
bits[2] = -1;
|
||||
}else if(num == 5){
|
||||
bits[0] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
default boolean blends(Tile tile, int rotation, @Nullable BuildRequest[] directional, int direction){
|
||||
int realDir = Mathf.mod(rotation - direction, 4);
|
||||
if(directional != null && directional[realDir] != null){
|
||||
BuildRequest req = directional[realDir];
|
||||
if(blends(tile, rotation, req.x, req.y, req.rotation, req.block)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return blends(tile, rotation, direction);
|
||||
}
|
||||
|
||||
default boolean blends(Tile tile, int rotation, int direction){
|
||||
Tile other = tile.getNearby(Mathf.mod(rotation - direction, 4));
|
||||
if(other != null) other = other.link();
|
||||
return other != null && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
}
|
||||
|
||||
default boolean lookingAt(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
return (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery)
|
||||
|| (!otherblock.rotate || Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y)));
|
||||
}
|
||||
|
||||
boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock);
|
||||
}
|
@ -16,7 +16,7 @@ public class ArmoredConveyor extends Conveyor{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
return otherblock.outputsItems() && (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery)
|
||||
|| ((!otherblock.rotate && Edges.getFacingEdge(otherblock, otherx, othery, tile).relativeTo(tile) == tile.rotation()) || Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y)));
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
package io.anuke.mindustry.world.blocks.distribution;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.LiquidBlock;
|
||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
import io.anuke.mindustry.world.modules.*;
|
||||
|
||||
public class Conduit extends LiquidBlock{
|
||||
public class Conduit extends LiquidBlock implements Autotiler{
|
||||
protected final int timerFlow = timers++;
|
||||
|
||||
protected TextureRegion[] topRegions = new TextureRegion[7];
|
||||
@ -39,29 +40,30 @@ public class Conduit extends LiquidBlock{
|
||||
super.onProximityUpdate(tile);
|
||||
|
||||
ConduitEntity entity = tile.entity();
|
||||
entity.blendbits = 0;
|
||||
entity.blendrot = 0;
|
||||
|
||||
if(blends(tile, 2) && blends(tile, 1) && blends(tile, 3)){
|
||||
entity.blendbits = 3;
|
||||
}else if(blends(tile, 1) && blends(tile, 3)){
|
||||
entity.blendbits = 6;
|
||||
}else if(blends(tile, 1) && blends(tile, 2)){
|
||||
entity.blendbits = 2;
|
||||
}else if(blends(tile, 3) && blends(tile, 2)){
|
||||
entity.blendbits = 4;
|
||||
}else if(blends(tile, 1)){
|
||||
entity.blendbits = 5;
|
||||
}else if(blends(tile, 3)){
|
||||
entity.blendbits = 1;
|
||||
}
|
||||
int[] bits = buildBlending(tile, tile.rotation(), null);
|
||||
entity.blendbits = bits[0];
|
||||
}
|
||||
|
||||
private boolean blends(Tile tile, int direction){
|
||||
Tile other = tile.getNearby(Mathf.mod(tile.rotation() - direction, 4));
|
||||
if(other != null) other = other.link();
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
int[] bits = getTiling(req, list);
|
||||
|
||||
return other != null && other.block().hasLiquids && other.block().outputsLiquid && ((tile.getNearby(tile.rotation()) == other) || (!other.block().rotate || other.getNearby(other.rotation()) == tile));
|
||||
if(bits == null) return;
|
||||
|
||||
Draw.colorl(0.34f);
|
||||
Draw.rect(botRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90);
|
||||
Draw.color();
|
||||
Draw.rect(topRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transformCase(int num, int[] bits){
|
||||
bits[0] = num == 0 ? 3 : num == 1 ? 6 : num == 2 ? 2 : num == 3 ? 4 : num == 4 ? 5 : num == 6 ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
return otherblock.hasLiquids && otherblock.outputsLiquid && lookingAt(tile, rotation, otherx, othery, otherrot, otherblock);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,7 +115,6 @@ public class Conduit extends LiquidBlock{
|
||||
public static class ConduitEntity extends TileEntity{
|
||||
public float smoothLiquid;
|
||||
|
||||
byte blendbits;
|
||||
int blendrot;
|
||||
int blendbits;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
@ -15,14 +14,14 @@ import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
import io.anuke.mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Conveyor extends Block{
|
||||
public class Conveyor extends Block implements Autotiler{
|
||||
private static final float itemSpace = 0.4f;
|
||||
private static final float minmove = 1f / (Short.MAX_VALUE - 2);
|
||||
private static ItemPos drawpos = new ItemPos();
|
||||
@ -103,76 +102,17 @@ public class Conveyor extends Block{
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
if(req.tile() == null) return;
|
||||
int[] bits = getTiling(req, list);
|
||||
|
||||
Arrays.fill(directionals, null);
|
||||
list.each(other -> {
|
||||
if(other.breaking || other == req) return;
|
||||
|
||||
int i = 0;
|
||||
for(Point2 point : Geometry.d4){
|
||||
int x = req.x + point.x, y = req.y + point.y;
|
||||
if(x >= other.x -(other.block.size - 1) / 2 && x <= other.x + (other.block.size / 2) && y >= other.y -(other.block.size - 1) / 2 && y <= other.y + (other.block.size / 2)){
|
||||
directionals[i] = other;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
});
|
||||
|
||||
int[] bits = buildBlending(req.tile(), req.rotation, directionals);
|
||||
if(bits == null) return;
|
||||
|
||||
TextureRegion region = regions[bits[0]][0];
|
||||
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * bits[1] * Draw.scl, region.getHeight() * bits[2] * Draw.scl, req.rotation * 90);
|
||||
}
|
||||
|
||||
protected int[] buildBlending(Tile tile, int rotation, BuildRequest[] directional){
|
||||
int blendbits = 0;
|
||||
int blendsclx = 1, blendscly = 1;
|
||||
|
||||
if(blends(tile, rotation, directional, 2) && blends(tile, rotation, directional, 1) && blends(tile, rotation, directional, 3)){
|
||||
blendbits = 3;
|
||||
}else if(blends(tile, rotation, directional, 1) && blends(tile, rotation, directional, 3)){
|
||||
blendbits = 4;
|
||||
}else if(blends(tile, rotation, directional, 1) && blends(tile, rotation, directional, 2)){
|
||||
blendbits = 2;
|
||||
}else if(blends(tile, rotation, directional, 3) && blends(tile, rotation, directional, 2)){
|
||||
blendbits = 2;
|
||||
blendscly = -1;
|
||||
}else if(blends(tile, rotation, directional, 1)){
|
||||
blendbits = 1;
|
||||
blendscly = -1;
|
||||
}else if(blends(tile, rotation, directional, 3)){
|
||||
blendbits = 1;
|
||||
}
|
||||
|
||||
blendresult[0] = blendbits;
|
||||
blendresult[1] = blendsclx;
|
||||
blendresult[2] = blendscly;
|
||||
return blendresult;
|
||||
}
|
||||
|
||||
protected boolean blends(Tile tile, int rotation, @Nullable BuildRequest[] directional, int direction){
|
||||
int realDir = Mathf.mod(rotation - direction, 4);
|
||||
if(directional != null && directional[realDir] != null){
|
||||
BuildRequest req = directional[realDir];
|
||||
//Log.info("Check if blends: {0},{1} {2} | {3},{4} {5}", tile.x, tile.y, rotation, req.x, req.y, req.rotation);
|
||||
if(blends(tile, rotation, req.x, req.y, req.rotation, req.block)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return blends(tile, rotation, direction);
|
||||
}
|
||||
|
||||
protected boolean blends(Tile tile, int rotation, int direction){
|
||||
Tile other = tile.getNearby(Mathf.mod(rotation - direction, 4));
|
||||
if(other != null) other = other.link();
|
||||
return other != null && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
}
|
||||
|
||||
protected boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
return otherblock.outputsItems() && (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery)
|
||||
|| (!otherblock.rotate || Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y)));
|
||||
@Override
|
||||
public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
return otherblock.outputsItems() && lookingAt(tile, rotation, otherx, othery, otherrot, otherblock);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=59cff366c4d46577b659e153183eb824eaafd7f7
|
||||
archash=5b52af54b7f87db9732c4fa97781b2f2ae09c5ab
|
||||
|
Loading…
Reference in New Issue
Block a user