Completely implemented new interpolation

This commit is contained in:
Anuken
2018-02-03 20:43:48 -05:00
parent 23c1edc3fa
commit da22f8fbce
8 changed files with 39 additions and 35 deletions

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.graphics.Shaders;
@@ -261,22 +260,20 @@ public class Player extends SyncEntity{
data.putFloat(angle);
data.putShort((short)health);
data.put((byte)(dashing ? 1 : 0));
data.putLong(TimeUtils.millis());
}
@Override
public void read(ByteBuffer data) {
public void read(ByteBuffer data, long time) {
float x = data.getFloat();
float y = data.getFloat();
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;
interpolator.targetrot = angle;
interpolator.time = 0f;
interpolator.last.set(this.x, this.y);
interpolator.target.set(x, y);
@@ -289,9 +286,12 @@ public class Player extends SyncEntity{
i.time += 1f / i.spacing * Timers.delta();
lerp2(Tmp.v2.set(i.last), i.target, i.time);
Mathf.lerp2(Tmp.v2.set(i.last), i.target, i.time);
x = Tmp.v2.x;
y = Tmp.v2.y;
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
if(isAndroid && i.target.dst(i.last) > 2f && Timers.get(this, "dashfx", 2)){
Angles.translation(angle + 180, 3f);
@@ -302,17 +302,6 @@ public class Player extends SyncEntity{
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);
}
private Vector2 lerp2 (Vector2 v, Vector2 target, float alpha) {
v.x = (v.x) + ((target.x - v.x) * alpha);
v.y = (v.y) + ((target.y - v.y) * alpha);
return v;
}
public Color getColor(){

View File

@@ -14,14 +14,14 @@ public abstract class SyncEntity extends DestructibleEntity{
static{
setWriteSize(Enemy.class, 4 + 4 + 2 + 2);
setWriteSize(Player.class, 4 + 4 + 4 + 2 + 1 + 8);
setWriteSize(Player.class, 4 + 4 + 4 + 2 + 1);
}
public abstract void writeSpawn(ByteBuffer data);
public abstract void readSpawn(ByteBuffer data);
public abstract void write(ByteBuffer data);
public abstract void read(ByteBuffer data);
public abstract void read(ByteBuffer data, long time);
public abstract void interpolate();
public int getWriteSize(){

View File

@@ -1,16 +1,19 @@
package io.anuke.mindustry.entities.enemies;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timer;
import io.anuke.ucore.util.Tmp;
import java.nio.ByteBuffer;
@@ -126,27 +129,33 @@ public class Enemy extends SyncEntity {
}
@Override
public void read(ByteBuffer data) {
public void read(ByteBuffer data, long time) {
float x = data.getFloat();
float y = data.getFloat();
short angle = data.getShort();
short health = data.getShort();
interpolator.target.set(x, y);
interpolator.targetrot = angle/2f;
this.health = health;
interpolator.targetrot = angle / 2f;
interpolator.time = 0f;
interpolator.last.set(this.x, this.y);
interpolator.target.set(x, y);
interpolator.spacing = Math.max(((TimeUtils.timeSinceMillis(time) / 1000f) * 60f), 1f);
}
@Override
public void interpolate() {
Interpolator i = interpolator;
if(i.target.dst(x, y) > 16){
set(i.target.x, i.target.y);
}
x = Mathf.lerpDelta(x, i.target.x, 0.4f);
y = Mathf.lerpDelta(y, i.target.y, 0.4f);
i.time += 1f / i.spacing * Timers.delta();
Mathf.lerp2(Tmp.v2.set(i.last), i.target, i.time);
x = Tmp.v2.x;
y = Tmp.v2.y;
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
}