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); 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){ for(Smethod elem : entry.value){

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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