Fix for off-screen players and laggy interpolation

This commit is contained in:
Anuken
2018-11-15 12:37:07 -05:00
parent 5e0886d744
commit 8f99530795
4 changed files with 21 additions and 3 deletions

View File

@@ -45,7 +45,7 @@ import static io.anuke.mindustry.Vars.*;
public class NetClient extends Module{
private final static float dataTimeout = 60 * 18;
private final static float playerSyncTime = 2;
private final static float viewScale = 1.75f;
private final static float viewScale = 2f;
private Timer timer = new Timer(5);
/**Whether the client is currently connecting.*/

View File

@@ -494,7 +494,7 @@ public class NetServer extends Module{
//check for syncable groups
for(EntityGroup<?> group : Entities.getAllGroups()){
if(group.isEmpty() || !(group.all().get(0) instanceof SyncTrait)) continue;
//clipping is done by represntatives
//clipping is done by representatives
SyncTrait represent = (SyncTrait) group.all().get(0);
//make sure mapping is enabled for this group

View File

@@ -809,6 +809,12 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
//region read and write methods
@Override
public boolean isClipped(){
return false;
}
@Override
public void writeSave(DataOutput stream) throws IOException{
stream.writeBoolean(isLocal);

View File

@@ -1,7 +1,9 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.mindustry.net.Interpolator;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.util.Tmp;
import java.io.DataInput;
import java.io.DataOutput;
@@ -24,8 +26,18 @@ public interface SyncTrait extends Entity, TypeTrait{
/**Interpolate entity position only. Override if you need to interpolate rotations or other values.*/
default void interpolate(){
if(getInterpolator() == null)
if(getInterpolator() == null){
throw new RuntimeException("This entity must have an interpolator to interpolate()!");
}
if(isClipped()){
//move off screen when no longer in bounds
if(!Tmp.r1.setSize(Core.camera.viewportWidth * Core.camera.zoom, Core.camera.viewportHeight * Core.camera.zoom)
.setCenter(Core.camera.position.x, Core.camera.position.y).contains(getX(), getY())){
set(-99999f, -99999f);
return;
}
}
getInterpolator().update();