Fixed more unit warp

This commit is contained in:
Anuken 2020-09-04 11:07:01 -04:00
parent af47e7662f
commit c7522ff89f
8 changed files with 57 additions and 43 deletions

View file

@ -468,6 +468,17 @@ public class EntityProcess extends BaseProcessor{
mbuilder.addStatement("$L = $L", field.name(), field.name() + EntityIO.targetSuf);
}
}
//SPECIAL CASE: method to snap to current position so interpolation doesn't go wild
if(first.name().equals("snapInterpolation")){
mbuilder.addStatement("updateSpacing = 16");
mbuilder.addStatement("lastUpdated = $T.millis()", Time.class);
for(Svar field : syncedFields){
//reset last+current state to target position
mbuilder.addStatement("$L = $L", field.name() + EntityIO.lastSuf, field.name());
mbuilder.addStatement("$L = $L", field.name() + EntityIO.targetSuf, field.name());
}
}
}
for(Smethod elem : entry.value){

View file

@ -585,8 +585,11 @@ public class NetClient implements ApplicationListener{
}
Unit unit = player.dead() ? Nulls.unit : player.unit();
int uid = player.dead() ? -1 : unit.id;
Call.clientSnapshot(lastSent++,
Call.clientSnapshot(
lastSent++,
uid,
player.dead(),
unit.x, unit.y,
player.unit().aimX(), player.unit().aimY(),
@ -597,7 +600,8 @@ public class NetClient implements ApplicationListener{
player.boosting, player.shooting, ui.chatfrag.shown(), control.input.isBuilding,
requests,
Core.camera.position.x, Core.camera.position.y,
Core.camera.width * viewScale, Core.camera.height * viewScale);
Core.camera.width * viewScale, Core.camera.height * viewScale
);
}
if(timer.get(1, 60)){

View file

@ -174,7 +174,7 @@ public class NetServer implements ApplicationListener{
return;
}
boolean preventDuplicates = headless && netServer.admins.getStrict();
boolean preventDuplicates = headless && netServer.admins.isStrict();
if(preventDuplicates){
if(Groups.player.contains(p -> p.name.trim().equalsIgnoreCase(packet.name.trim()))){
@ -485,7 +485,7 @@ public class NetServer implements ApplicationListener{
data.stream = new ByteArrayInputStream(stream.toByteArray());
player.con.sendStream(data);
Log.debug("Packed @ compressed bytes of world data.", stream.size());
Log.debug("Packed @ invalid world data.", stream.size());
}
public void addPacketHandler(String type, Cons2<Player, String> handler){
@ -539,6 +539,7 @@ public class NetServer implements ApplicationListener{
public static void clientSnapshot(
Player player,
int snapshotID,
int unitID,
boolean dead,
float x, float y,
float pointerX, float pointerY,
@ -562,7 +563,7 @@ public class NetServer implements ApplicationListener{
if(invalid(rotation)) rotation = 0f;
if(invalid(baseRotation)) baseRotation = 0f;
boolean verifyPosition = !player.dead() && netServer.admins.getStrict() && headless;
boolean verifyPosition = netServer.admins.isStrict() && headless;
if(con.lastReceivedClientTime == 0) con.lastReceivedClientTime = Time.millis() - 16;
@ -580,7 +581,6 @@ public class NetServer implements ApplicationListener{
boosting = false;
}
//TODO these need to be assigned elsewhere
player.mouseX = pointerX;
player.mouseY = pointerY;
player.typing = chatting;
@ -635,41 +635,37 @@ public class NetServer implements ApplicationListener{
if(unit.isGrounded()){
maxSpeed *= unit.floorSpeedMultiplier();
}
unit.vel.set(xVelocity, yVelocity).limit(maxSpeed);
float maxMove = elapsed / 1000f * 60f * maxSpeed * 1.1f;
if(con.lastUnit != unit){
con.lastUnit = unit;
con.lastPosition.set(unit);
}
//if the player think they're dead their position should be ignored
if(dead){
x = unit.x;
y = unit.y;
}
vector.set(x, y).sub(con.lastPosition);
vector.limit(maxMove);
float prevx = unit.x, prevy = unit.y;
unit.set(con.lastPosition);
if(!unit.isFlying()){
unit.move(vector.x, vector.y);
}else{
unit.trns(vector.x, vector.y);
}
//set last position after movement
con.lastPosition.set(unit);
//ignore the position if the player thinks they're dead, or the unit is wrong
boolean ignorePosition = dead || unit.id != unitID;
float newx = unit.x, newy = unit.y;
if(!verifyPosition){
unit.set(prevx, prevy);
newx = x;
newy = y;
}else if(!Mathf.within(x, y, newx, newy, correctDist) && !dead){
Call.setPosition(player.con, newx, newy); //teleport and correct position when necessary
if(!ignorePosition){
unit.vel.set(xVelocity, yVelocity).limit(maxSpeed);
vector.set(x, y).sub(unit);
vector.limit(maxMove);
float prevx = unit.x, prevy = unit.y;
//unit.set(con.lastPosition);
if(!unit.isFlying()){
unit.move(vector.x, vector.y);
}else{
unit.trns(vector.x, vector.y);
}
newx = unit.x;
newy = unit.y;
if(!verifyPosition){
unit.set(prevx, prevy);
newx = x;
newy = y;
}else if(!Mathf.within(x, y, newx, newy, correctDist)){
Call.setPosition(player.con, newx, newy); //teleport and correct position when necessary
}
}
//write sync data to the buffer

View file

@ -179,6 +179,11 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
if(unit != Nulls.unit){
unit.team(team);
unit.controller(this);
//this player just became remote, snap the interpolation so it doesn't go wild
if(unit.isRemote()){
unit.snapInterpolation();
}
}
Events.fire(new UnitChangeEvent(base(), unit));

View file

@ -13,6 +13,7 @@ abstract class SyncComp implements Entityc{
//all these method bodies are internally generated
void snapSync(){}
void snapInterpolation(){}
void readSync(Reads read){}
void writeSync(Writes write){}
void readSyncManual(FloatBuffer buffer){}

View file

@ -168,7 +168,7 @@ public class Administration{
Core.settings.put("playerlimit", limit);
}
public boolean getStrict(){
public boolean isStrict(){
return Config.strict.bool();
}

View file

@ -1,6 +1,5 @@
package mindustry.net;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
@ -12,15 +11,13 @@ import mindustry.net.Packets.*;
import java.io.*;
import static mindustry.Vars.netServer;
import static mindustry.Vars.*;
public abstract class NetConnection{
public final String address;
public String uuid = "AAAAAAAA", usid = uuid;
public boolean mobile, modclient;
public @Nullable Player player;
public @Nullable Unitc lastUnit;
public Vec2 lastPosition = new Vec2();
public boolean kicked = false;
/** ID of last received client snapshot. */

View file

@ -63,7 +63,7 @@ public class Bar extends Element{
if(fraction == null) return;
float computed = Mathf.clamp(fraction.get());
if(!Mathf.equal(lastValue, computed)){
if(lastValue > computed){
blink = 1f;
lastValue = computed;
}