mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-11-11 14:56:10 +03:00
Better player interpolation, block nearby usage fixes
This commit is contained in:
parent
6a235a4833
commit
938a946419
@ -59,8 +59,8 @@ public class NetServer extends Module{
|
||||
player.name = packet.name;
|
||||
player.isAndroid = packet.android;
|
||||
player.set(world.getSpawnX(), world.getSpawnY());
|
||||
player.interpolator.last.set(player.x, player.y);
|
||||
player.interpolator.target.set(player.x, player.y);
|
||||
player.setNet(player.x, player.y);
|
||||
player.setNet(player.x, player.y);
|
||||
player.color.set(packet.color);
|
||||
connections.put(id, player);
|
||||
|
||||
|
@ -16,7 +16,6 @@ import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
@ -252,6 +251,7 @@ public class Player extends SyncEntity{
|
||||
color.set(buffer.getInt());
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
setNet(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -261,6 +261,7 @@ public class Player extends SyncEntity{
|
||||
data.putFloat(angle);
|
||||
data.putShort((short)health);
|
||||
data.put((byte)(dashing ? 1 : 0));
|
||||
data.putLong(TimeUtils.millis());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -270,30 +271,16 @@ public class Player extends SyncEntity{
|
||||
float angle = data.getFloat();
|
||||
short health = data.getShort();
|
||||
byte dashing = data.get();
|
||||
long time = data.getLong();
|
||||
|
||||
interpolator.targetrot = angle;
|
||||
this.health = health;
|
||||
this.dashing = dashing == 1;
|
||||
|
||||
if(interpolator.lastread == 0){
|
||||
interpolator.lastread = TimeUtils.millis();
|
||||
interpolator.spacing = 1f;
|
||||
interpolator.target.set(x, y);
|
||||
interpolator.last.set(x, y);
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
interpolator.time = 0f;
|
||||
interpolator.spacing = Math.max(TimeUtils.timeSinceMillis(interpolator.lastread) / 1000f * 60f, 0.1f);
|
||||
interpolator.last.set(this.x, this.y);
|
||||
interpolator.target.set(x, y);
|
||||
|
||||
interpolator.lastread = TimeUtils.millis();
|
||||
Log.info("Taken {0} frames to move {1}", interpolator.spacing, interpolator.last.dst(interpolator.target));
|
||||
interpolator.spacing = Math.max(((TimeUtils.timeSinceMillis(time) / 1000f) * 60f), 1f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -304,29 +291,22 @@ public class Player extends SyncEntity{
|
||||
|
||||
lerp2(Tmp.v2.set(i.last), i.target, i.time);
|
||||
|
||||
/*
|
||||
|
||||
if(isAndroid && i.target.dst(x, y) > 2f && Timers.get(this, "dashfx", 2)){
|
||||
|
||||
if(isAndroid && i.target.dst(i.last) > 2f && Timers.get(this, "dashfx", 2)){
|
||||
Angles.translation(angle + 180, 3f);
|
||||
Effects.effect(Fx.dashsmoke, x + Angles.x(), y + Angles.y());
|
||||
}
|
||||
|
||||
if(dashing && !dead && Timers.get(this, "dashfx", 3)){
|
||||
if(dashing && !dead && Timers.get(this, "dashfx", 3) && i.target.dst(i.last) > 1f){
|
||||
Angles.translation(angle + 180, 3f);
|
||||
Effects.effect(Fx.dashsmoke, x + Angles.x(), y + Angles.y());
|
||||
}*/
|
||||
}
|
||||
|
||||
x = Tmp.v2.x;
|
||||
y = Tmp.v2.y;
|
||||
|
||||
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
|
||||
|
||||
Log.info("{0}, {1}, t={2}, s={5}, l={3}, t={4}", x, y, i.time, i.last, i.target, i.spacing);
|
||||
|
||||
if(i.target.dst(x, y) > 24 && !isAndroid){
|
||||
Log.info("clamping");
|
||||
// set(i.target.x, i.target.y);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 lerp2 (Vector2 v, Vector2 target, float alpha) {
|
||||
|
@ -10,11 +10,11 @@ import java.nio.ByteBuffer;
|
||||
public abstract class SyncEntity extends DestructibleEntity{
|
||||
private static ObjectIntMap<Class<? extends SyncEntity>> writeSizes = new ObjectIntMap<>();
|
||||
|
||||
public transient Interpolator interpolator = new Interpolator();
|
||||
protected transient Interpolator interpolator = new Interpolator();
|
||||
|
||||
static{
|
||||
setWriteSize(Enemy.class, 4 + 4 + 2 + 2);
|
||||
setWriteSize(Player.class, 4 + 4 + 4 + 2 + 1);
|
||||
setWriteSize(Player.class, 4 + 4 + 4 + 2 + 1 + 8);
|
||||
}
|
||||
|
||||
public abstract void writeSpawn(ByteBuffer data);
|
||||
@ -38,12 +38,19 @@ public abstract class SyncEntity extends DestructibleEntity{
|
||||
writeSizes.put(type, size);
|
||||
}
|
||||
|
||||
public <T extends SyncEntity> T setNet(float x, float y){
|
||||
set(x, y);
|
||||
interpolator.target.set(x, y);
|
||||
interpolator.last.set(x, y);
|
||||
interpolator.spacing = 1f;
|
||||
interpolator.time = 0f;
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
public class Interpolator {
|
||||
public Vector2 target = new Vector2();
|
||||
public Vector2 delta = new Vector2();
|
||||
public Vector2 last = new Vector2();
|
||||
public float targetrot;
|
||||
public long lastread;
|
||||
public float spacing = 1f;
|
||||
public float time;
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ public class Enemy extends SyncEntity {
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
health = buffer.getShort();
|
||||
setNet(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -268,7 +268,7 @@ public class Packets {
|
||||
entity = (SyncEntity) ClassReflection.newInstance(group.getType());
|
||||
entity.id = id;
|
||||
entity.readSpawn(buffer);
|
||||
entity.interpolator.target.set(entity.x, entity.y);
|
||||
entity.setNet(entity.x, entity.y);
|
||||
}catch (ReflectionException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -179,10 +179,8 @@ public class Block{
|
||||
byte i = tile.getDump();
|
||||
byte pdump = (byte)(i % 4);
|
||||
|
||||
Tile[] tiles = tile.getNearby(temptiles);
|
||||
|
||||
for(int j = 0; j < 4; j ++){
|
||||
Tile other = tiles[i];
|
||||
Tile other = tile.getNearby(i);
|
||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
tile.setDump((byte)((i+1)%4));
|
||||
@ -209,10 +207,8 @@ public class Block{
|
||||
|
||||
int i = tile.getDump()%4;
|
||||
|
||||
Tile[] tiles = tile.getNearby(temptiles);
|
||||
|
||||
for(int j = 0; j < 4; j ++){
|
||||
Tile other = tiles[i];
|
||||
Tile other = tile.getNearby(i);
|
||||
|
||||
if(i == direction || direction == -1){
|
||||
for(Item item : Item.getAllItems()){
|
||||
@ -239,7 +235,7 @@ public class Block{
|
||||
* Try offloading an item to a nearby container. Returns true if success.
|
||||
*/
|
||||
protected boolean offloadDir(Tile tile, Item item){
|
||||
Tile other = tile.getNearby()[tile.getRotation()];
|
||||
Tile other = tile.getNearby(tile.getRotation());
|
||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
return true;
|
||||
|
@ -57,7 +57,7 @@ public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0.01f && entity.timer.get(timerFlow, 1)){
|
||||
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -66,7 +66,7 @@ public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0.01f){
|
||||
tryMoveLiquid(tile, tile.getNearby()[tile.getDump()]);
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.getDump()));
|
||||
tile.setDump((byte)Mathf.mod(tile.getDump() + 1, 4));
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,17 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.mindustry.world.blocks.types.production.Generator;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class PowerBooster extends Generator{
|
||||
protected final int timerGenerate = timers++;
|
||||
|
||||
@ -101,7 +103,7 @@ public class PowerBooster extends Generator{
|
||||
|
||||
//TODO better distribution scheme
|
||||
if(i == 0 && acceptors > 0){
|
||||
flow = Mathf.clamp(p.power / acceptors, 0f, powerSpeed / acceptors);
|
||||
flow = Mathf.clamp(p.power / acceptors, 0f, powerSpeed / acceptors * Timers.delta());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class TunnelConveyor extends Junction{
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
Tile tunnel = getDestTunnel(tile, item);
|
||||
if(tunnel == null) return;
|
||||
Tile to = tunnel.getNearby()[tunnel.getRotation()];
|
||||
Tile to = tunnel.getNearby(tunnel.getRotation());
|
||||
if(to == null) return;
|
||||
Block before = to.block();
|
||||
|
||||
@ -76,7 +76,7 @@ public class TunnelConveyor extends Junction{
|
||||
Tile tunnel = getDestTunnel(tile, item);
|
||||
|
||||
if(tunnel != null){
|
||||
Tile to = tunnel.getNearby()[tunnel.getRotation()];
|
||||
Tile to = tunnel.getNearby(tunnel.getRotation());
|
||||
return to != null && !(to.block() instanceof TunnelConveyor) && to.block().acceptItem(item, to, tunnel);
|
||||
}else{
|
||||
return false;
|
||||
@ -87,10 +87,10 @@ public class TunnelConveyor extends Junction{
|
||||
Tile dest = tile;
|
||||
int rel = (tile.getRotation() + 2)%4;
|
||||
for(int i = 0; i < maxdist; i ++){
|
||||
dest = dest.getNearby()[rel];
|
||||
dest = dest.getNearby(rel);
|
||||
if(dest != null && dest.block() instanceof TunnelConveyor && dest.getRotation() == rel
|
||||
&& dest.getNearby()[rel] != null
|
||||
&& dest.getNearby()[rel].block().acceptItem(item, dest.getNearby()[rel], dest)){
|
||||
&& dest.getNearby(rel) != null
|
||||
&& dest.getNearby(rel).block().acceptItem(item, dest.getNearby(rel), dest)){
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
@ -161,9 +161,10 @@ public class Generator extends PowerBlock{
|
||||
continue;
|
||||
|
||||
PowerAcceptor p = (PowerAcceptor) target.block();
|
||||
if(p.acceptsPower(target) && entity.power >= powerSpeed){
|
||||
float accepted = p.addPower(target, powerSpeed);
|
||||
entity.power -= (accepted);
|
||||
float transmit = entity.power * Timers.delta();
|
||||
if(p.acceptsPower(target) && entity.power >= transmit){
|
||||
float accepted = p.addPower(target, transmit);
|
||||
entity.power -= accepted;
|
||||
}
|
||||
|
||||
}
|
||||
@ -228,9 +229,7 @@ public class Generator extends PowerBlock{
|
||||
rotation = Mathf.mod(rotation, 4);
|
||||
GridPoint2 point = Geometry.d4[rotation];
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(i = 1; i < laserRange; i++){
|
||||
for(int i = 1; i < laserRange; i++){
|
||||
Tile other = world.tile(tile.x + i * point.x, tile.y + i * point.y);
|
||||
|
||||
if(other != null && other.block() instanceof PowerAcceptor){
|
||||
|
@ -293,13 +293,6 @@ public class KryoServer implements ServerProvider {
|
||||
Log.err(e);
|
||||
}
|
||||
Log.info("Disposed server.");
|
||||
|
||||
for(Thread thread : Thread.getAllStackTraces().keySet()){
|
||||
if(!thread.isDaemon()){
|
||||
Log.info(thread.toString());
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleException(Throwable e){
|
||||
|
Loading…
Reference in New Issue
Block a user