Autogenerated interpolation
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
package mindustry.net;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
|
||||
public class Interpolator{
|
||||
//used for movement
|
||||
public Vec2 target = new Vec2();
|
||||
public Vec2 last = new Vec2();
|
||||
public float[] targets = {};
|
||||
public float[] lasts = {};
|
||||
public long lastUpdated, updateSpacing;
|
||||
|
||||
//current state
|
||||
public Vec2 pos = new Vec2();
|
||||
public float[] values = {};
|
||||
|
||||
public void read(float cx, float cy, float x, float y, float... target1ds){
|
||||
if(lastUpdated != 0) updateSpacing = Time.timeSinceMillis(lastUpdated);
|
||||
|
||||
lastUpdated = Time.millis();
|
||||
|
||||
targets = target1ds;
|
||||
if(lasts.length != values.length){
|
||||
lasts = new float[values.length];
|
||||
}
|
||||
System.arraycopy(values, 0, lasts, 0, values.length);
|
||||
last.set(cx, cy);
|
||||
target.set(x, y);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
values = new float[0];
|
||||
targets = new float[0];
|
||||
target.setZero();
|
||||
last.setZero();
|
||||
lastUpdated = 0;
|
||||
updateSpacing = 16; //1 frame
|
||||
pos.setZero();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(lastUpdated != 0 && updateSpacing != 0){
|
||||
float timeSinceUpdate = Time.timeSinceMillis(lastUpdated);
|
||||
float alpha = Math.min(timeSinceUpdate / updateSpacing, 2f);
|
||||
|
||||
pos.set(last).lerpPast(target, alpha);
|
||||
|
||||
if(values.length != targets.length){
|
||||
values = new float[targets.length];
|
||||
}
|
||||
|
||||
if(lasts.length != targets.length){
|
||||
lasts = new float[targets.length];
|
||||
}
|
||||
|
||||
for(int i = 0; i < values.length; i++){
|
||||
values[i] = Mathf.slerp(lasts[i], targets[i], alpha);
|
||||
}
|
||||
}else{
|
||||
pos.set(target);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.net;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
@@ -18,6 +19,8 @@ public abstract class NetConnection{
|
||||
public String uuid = "AAAAAAAA", usid = uuid;
|
||||
public boolean mobile, modclient;
|
||||
public @Nullable Playerc player;
|
||||
public @Nullable Unitc lastUnit;
|
||||
public Vec2 lastPosition = new Vec2();
|
||||
|
||||
/** ID of last recieved client snapshot. */
|
||||
public int lastRecievedClientSnapshot = -1;
|
||||
|
||||
Reference in New Issue
Block a user