Trail length FPS independence
This commit is contained in:
@@ -97,12 +97,11 @@ public class Trail{
|
|||||||
|
|
||||||
/** Removes the last point from the trail at intervals. */
|
/** Removes the last point from the trail at intervals. */
|
||||||
public void shorten(){
|
public void shorten(){
|
||||||
if((counter += Time.delta) >= 1f){
|
int count = (int)(counter += Time.delta);
|
||||||
if(points.size >= 3){
|
counter -= count;
|
||||||
points.removeRange(0, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
counter %= 1f;
|
if(points.size + ((count - 1) * 3) > length * 3){
|
||||||
|
points.removeRange(0, Math.min(3 * count - 1, points.size - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,18 +112,27 @@ public class Trail{
|
|||||||
|
|
||||||
/** Adds a new point to the trail at intervals. */
|
/** Adds a new point to the trail at intervals. */
|
||||||
public void update(float x, float y, float width){
|
public void update(float x, float y, float width){
|
||||||
//TODO fix longer trails at low FPS
|
int count = (int)(counter += Time.delta);
|
||||||
if((counter += Time.delta) >= 1f){
|
counter -= count;
|
||||||
if(points.size > length*3){
|
|
||||||
points.removeRange(0, 2);
|
if(count > 0){
|
||||||
|
int toRemove = points.size + (count - 1 - length) * 3;
|
||||||
|
if(toRemove > 0){
|
||||||
|
points.removeRange(0, Math.min(toRemove - 1, points.size - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
points.add(x, y, width);
|
//if lastX is -1, this trail has never updated, so only add one point - there is nothing to interpolate with
|
||||||
|
if(count == 1 || lastX == -1f){
|
||||||
counter %= 1f;
|
points.add(x, y, width);
|
||||||
|
}else{
|
||||||
|
for(int i = 0; i < count; i++){
|
||||||
|
float f = (i + 1f) / count;
|
||||||
|
points.add(Mathf.lerp(lastX, x, f), Mathf.lerp(lastY, y, f), Mathf.lerp(lastW, width, f));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update last position regardless, so it joins
|
//update last position regardless, so it joins at the origin
|
||||||
lastAngle = -Angles.angleRad(x, y, lastX, lastY);
|
lastAngle = -Angles.angleRad(x, y, lastX, lastY);
|
||||||
lastX = x;
|
lastX = x;
|
||||||
lastY = y;
|
lastY = y;
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ org.gradle.caching=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=e312cc96f5
|
archash=4ea3d3b7e8
|
||||||
|
|||||||
Reference in New Issue
Block a user