More multiplayer fixes

This commit is contained in:
Anuken
2018-06-25 19:25:26 -04:00
parent f61f8a36f8
commit d89c33fbe8
8 changed files with 61 additions and 81 deletions

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.net;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf;
public class Interpolator {
@@ -11,19 +10,20 @@ public class Interpolator {
public Vector2 target = new Vector2();
public Vector2 last = new Vector2();
public float[] targets = {};
public float spacing = 1f;
public float time;
public long lastUpdated, updateSpacing;
//current state
public Vector2 pos = new Vector2();
public float[] values = {};
public void read(float cx, float cy, float x, float y, long sent, float... target1ds){
if(lastUpdated != 0) updateSpacing = TimeUtils.timeSinceMillis(lastUpdated);
lastUpdated = sent;
targets = target1ds;
time = 0f;
last.set(cx, cy);
target.set(x, y);
spacing = Math.min(Math.max(((TimeUtils.timeSinceMillis(sent) / 1000f) * 60f), 4f), 10);
}
public void reset(){
@@ -31,13 +31,36 @@ public class Interpolator {
targets = new float[0];
target.setZero();
last.setZero();
spacing = 1f;
time = 0f;
lastUpdated = updateSpacing = 0;
pos.setZero();
}
public void update(){
if(lastUpdated != 0){
float timeSinceUpdate = TimeUtils.timeSinceMillis(lastUpdated);
float alpha = Math.min(timeSinceUpdate / updateSpacing, 1f);
Mathf.lerp2(last, target, alpha);
pos.set(last).lerp(target, alpha);
if(values.length != targets.length){
values = new float[targets.length];
}
for (int i = 0; i < values.length; i++) {
values[i] = Mathf.slerp(values[i], targets[i], alpha);
}
if(target.dst(pos) > 128){
pos.set(target);
last.set(target);
}
}else{
pos.set(target);
}
/*
time += 1f / spacing * Math.min(Timers.delta(), 1f);
time = Mathf.clamp(time, 0, 2f);
@@ -56,7 +79,7 @@ public class Interpolator {
pos.set(target);
last.set(target);
time = 0f;
}
}*/
}
}