mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-22 22:07:31 +03:00
Fixed junction clogs, tunnel conveyors, power and interpolation
This commit is contained in:
parent
d74a836d99
commit
3c38deeba8
@ -270,6 +270,7 @@ public class NetClient extends Module {
|
||||
|
||||
Net.handleClient(ItemTransferPacket.class, packet -> {
|
||||
Tile tile = world.tile(packet.position);
|
||||
if(tile == null || tile.entity == null) return;
|
||||
Tile next = tile.getNearby(packet.rotation);
|
||||
tile.entity.items[packet.itemid] --;
|
||||
next.block().handleItem(Item.getByID(packet.itemid), next, tile);
|
||||
|
@ -277,7 +277,7 @@ public class Player extends SyncEntity{
|
||||
interpolator.time = 0f;
|
||||
interpolator.last.set(this.x, this.y);
|
||||
interpolator.target.set(x, y);
|
||||
interpolator.spacing = Math.max(((TimeUtils.timeSinceMillis(time) / 1000f) * 60f), 4f);
|
||||
interpolator.spacing = Math.min(Math.max(((TimeUtils.timeSinceMillis(time) / 1000f) * 60f), 4f), 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -291,6 +291,12 @@ public class Player extends SyncEntity{
|
||||
x = Tmp.v2.x;
|
||||
y = Tmp.v2.y;
|
||||
|
||||
if(i.target.dst(x, y) > 128){
|
||||
set(i.target.x, i.target.y);
|
||||
i.time = 0f;
|
||||
i.last.set(i.target);
|
||||
}
|
||||
|
||||
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
|
||||
|
||||
if(isAndroid && i.target.dst(i.last) > 2f && Timers.get(this, "dashfx", 2)){
|
||||
|
@ -142,7 +142,7 @@ public class Enemy extends SyncEntity {
|
||||
interpolator.time = 0f;
|
||||
interpolator.last.set(this.x, this.y);
|
||||
interpolator.target.set(x, y);
|
||||
interpolator.spacing = Math.max(((TimeUtils.timeSinceMillis(time) / 1000f) * 60f), 4f);
|
||||
interpolator.spacing = Math.min(Math.max(((TimeUtils.timeSinceMillis(time) / 1000f) * 60f), 4f), 10f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,7 @@ import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Net{
|
||||
public static final int version = 17;
|
||||
public static final int version = 18;
|
||||
|
||||
private static boolean server;
|
||||
private static boolean active;
|
||||
|
@ -77,7 +77,7 @@ public class Recipes {
|
||||
|
||||
new Recipe(power, DefenseBlocks.shieldgenerator, stack(Item.titanium, 30), stack(Item.dirium, 30)),
|
||||
|
||||
new Recipe(distribution, DistributionBlocks.teleporter, stack(Item.steel, 20), stack(Item.dirium, 15)),
|
||||
new Recipe(distribution, DistributionBlocks.teleporter, stack(Item.steel, 30), stack(Item.dirium, 40)),
|
||||
|
||||
new Recipe(power, DefenseBlocks.repairturret, stack(Item.iron, 30)),
|
||||
new Recipe(power, DefenseBlocks.megarepairturret, stack(Item.iron, 20), stack(Item.steel, 30)),
|
||||
|
@ -8,7 +8,8 @@ import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
|
||||
public class Junction extends Block{
|
||||
float speed = 20; //frames taken to go through this junction
|
||||
protected float speed = 20; //frames taken to go through this junction
|
||||
protected int capacity = 16;
|
||||
|
||||
public Junction(String name) {
|
||||
super(name);
|
||||
@ -24,37 +25,49 @@ public class Junction extends Block{
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
JunctionEntity entity = tile.entity();
|
||||
entity.items[entity.index ++] = Bits.packInt((short)item.id, source.relativeTo(tile.x, tile.y));
|
||||
boolean x = tile.x == source.x;
|
||||
int value = Bits.packInt((short)item.id, source.relativeTo(tile.x, tile.y));
|
||||
if(x){
|
||||
entity.bx.add(value);
|
||||
}else{
|
||||
entity.by.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
JunctionEntity entity = tile.entity();
|
||||
|
||||
if(entity.index > 0){
|
||||
entity.time += Timers.delta();
|
||||
if(entity.time >= speed){
|
||||
int i = entity.items[-- entity.index];
|
||||
for(int i = 0; i < 2; i ++){
|
||||
Buffer buffer = (i == 0 ? entity.bx : entity.by);
|
||||
if(buffer.index > 0){
|
||||
buffer.time += Timers.delta();
|
||||
if(buffer.time >= speed){
|
||||
int val = buffer.items[buffer.index - 1];
|
||||
|
||||
int item = Bits.getLeftShort(i);
|
||||
int direction = Bits.getRightShort(i);
|
||||
Item item = Item.getByID(Bits.getLeftShort(val));
|
||||
int direction = Bits.getRightShort(val);
|
||||
Tile dest = tile.getNearby(direction);
|
||||
|
||||
Tile target = tile.getNearby(direction);
|
||||
if(dest == null || !dest.block().acceptItem(item, dest, tile)) continue;
|
||||
|
||||
target.block().handleItem(Item.getByID(item), target, tile);
|
||||
dest.block().handleItem(item, dest, tile);
|
||||
|
||||
entity.time = 0f;
|
||||
buffer.time = 0f;
|
||||
buffer.index --;
|
||||
}
|
||||
}else{
|
||||
buffer.time = 0f;
|
||||
}
|
||||
}else{
|
||||
entity.time = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
JunctionEntity entity = tile.entity();
|
||||
boolean x = tile.x == source.x;
|
||||
|
||||
if(entity.index >= entity.items.length - 1) return false;
|
||||
if((x && entity.bx.full()) || (!x && entity.by.full())) return false;
|
||||
int dir = source.relativeTo(tile.x, tile.y);
|
||||
if(dir == -1) return false;
|
||||
Tile to = tile.getNearby(dir);
|
||||
@ -67,8 +80,21 @@ public class Junction extends Block{
|
||||
}
|
||||
|
||||
class JunctionEntity extends TileEntity{
|
||||
int[] items = new int[16]; //16 item buffer
|
||||
Buffer bx = new Buffer();
|
||||
Buffer by = new Buffer();
|
||||
}
|
||||
|
||||
class Buffer{
|
||||
int[] items = new int[capacity];
|
||||
int index;
|
||||
float time;
|
||||
|
||||
void add(int id){
|
||||
items[index ++] = id;
|
||||
}
|
||||
|
||||
boolean full(){
|
||||
return index >= items.length - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
public class TunnelConveyor extends Junction{
|
||||
public class TunnelConveyor extends Block{
|
||||
protected int maxdist = 3;
|
||||
protected float speed = 20; //frames taken to go through this tunnel
|
||||
protected int capacity = 16;
|
||||
|
||||
protected TunnelConveyor(String name) {
|
||||
super(name);
|
||||
@ -16,7 +17,6 @@ public class TunnelConveyor extends Junction{
|
||||
update = true;
|
||||
solid = true;
|
||||
health = 70;
|
||||
speed = 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,43 +26,38 @@ public class TunnelConveyor extends Junction{
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
TunnelEntity entity = tile.entity();
|
||||
|
||||
Tile tunnel = getDestTunnel(tile, item);
|
||||
if(tunnel == null) return;
|
||||
Tile to = tunnel.getNearby(tunnel.getRotation());
|
||||
if(to == null) return;
|
||||
Block before = to.block();
|
||||
|
||||
Timers.run(25, () -> {
|
||||
if(to.block() != before) return;
|
||||
//TODO fix
|
||||
try {
|
||||
to.block().handleItem(item, to, tunnel);
|
||||
}catch (NullPointerException e){
|
||||
Log.err(e);
|
||||
}
|
||||
});
|
||||
|
||||
entity.buffer[entity.index ++] = item.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
JunctionEntity entity = tile.entity();
|
||||
TunnelEntity entity = tile.entity();
|
||||
|
||||
if(entity.index > 0){
|
||||
entity.time += Timers.delta();
|
||||
if(entity.time >= speed){
|
||||
int i = entity.items[-- entity.index];
|
||||
entity.time = 0f;
|
||||
int i = entity.buffer[entity.index - 1];
|
||||
|
||||
int itemid = Bits.getLeftShort(i);
|
||||
|
||||
Item item = Item.getByID(itemid);
|
||||
Item item = Item.getByID(i);
|
||||
|
||||
Tile tunnel = getDestTunnel(tile, item);
|
||||
if(tunnel == null) return;
|
||||
Tile target = tunnel.getNearby(tunnel.getRotation());
|
||||
if(target == null) return;
|
||||
|
||||
if(!target.block().acceptItem(item, target, tunnel)) return;
|
||||
|
||||
target.block().handleItem(item, target, tunnel);
|
||||
|
||||
entity.index --;
|
||||
entity.time = 0f;
|
||||
}
|
||||
}else{
|
||||
entity.time = 0f;
|
||||
@ -71,6 +66,10 @@ public class TunnelConveyor extends Junction{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
TunnelEntity entity = tile.entity();
|
||||
|
||||
if(entity.index >= entity.buffer.length - 1) return false;
|
||||
|
||||
int rot = source.relativeTo(tile.x, tile.y);
|
||||
if(rot != (tile.getRotation() + 2)%4) return false;
|
||||
Tile tunnel = getDestTunnel(tile, item);
|
||||
@ -82,7 +81,12 @@ public class TunnelConveyor extends Junction{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new TunnelEntity();
|
||||
}
|
||||
|
||||
Tile getDestTunnel(Tile tile, Item item){
|
||||
Tile dest = tile;
|
||||
int rel = (tile.getRotation() + 2)%4;
|
||||
@ -96,4 +100,10 @@ public class TunnelConveyor extends Junction{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class TunnelEntity extends TileEntity {
|
||||
int[] buffer = new int[capacity];
|
||||
int index;
|
||||
float time;
|
||||
}
|
||||
}
|
||||
|
@ -161,8 +161,8 @@ public class Generator extends PowerBlock{
|
||||
continue;
|
||||
|
||||
PowerAcceptor p = (PowerAcceptor) target.block();
|
||||
float transmit = entity.power * Timers.delta();
|
||||
if(p.acceptsPower(target) && entity.power >= transmit){
|
||||
float transmit = Math.min(powerSpeed * Timers.delta(), entity.power);
|
||||
if(p.acceptsPower(target)){
|
||||
float accepted = p.addPower(target, transmit);
|
||||
entity.power -= accepted;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class KryoClient implements ClientProvider{
|
||||
};
|
||||
|
||||
if(KryoRegistrator.fakeLag){
|
||||
client.addListener(new LagListener(0, KryoRegistrator.fakeLagAmount, listener));
|
||||
client.addListener(new LagListener(KryoRegistrator.fakeLagMin, KryoRegistrator.fakeLagMax, listener));
|
||||
}else{
|
||||
client.addListener(listener);
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ import static io.anuke.mindustry.Vars.playerGroup;
|
||||
|
||||
public class KryoRegistrator {
|
||||
public static boolean fakeLag = false;
|
||||
public static final int fakeLagAmount = 500;
|
||||
public static final int fakeLagMax = 1000;
|
||||
public static final int fakeLagMin = 0;
|
||||
|
||||
static{
|
||||
Log.set(Log.LEVEL_WARN);
|
||||
|
@ -105,7 +105,7 @@ public class KryoServer implements ServerProvider {
|
||||
};
|
||||
|
||||
if(KryoRegistrator.fakeLag){
|
||||
server.addListener(new LagListener(0, KryoRegistrator.fakeLagAmount, listener));
|
||||
server.addListener(new LagListener(KryoRegistrator.fakeLagMin, KryoRegistrator.fakeLagMax, listener));
|
||||
}else{
|
||||
server.addListener(listener);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user