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