Various multiplayer tweaks

This commit is contained in:
Anuken
2018-02-03 12:20:36 -05:00
parent 608343b9d1
commit a31c4b273d
9 changed files with 82 additions and 26 deletions

View File

@@ -97,7 +97,7 @@ public class Vars{
Color.valueOf("ffcaa8"), Color.valueOf("ffcaa8"),
Color.valueOf("008551"), Color.valueOf("008551"),
Color.valueOf("00e339"), Color.valueOf("00e339"),
Color.valueOf("222e53"), Color.valueOf("423c7b"),
Color.valueOf("4b5ef1"), Color.valueOf("4b5ef1"),
Color.valueOf("2cabfe"), Color.valueOf("2cabfe"),
}; };

View File

@@ -37,7 +37,6 @@ public class NetClient extends Module {
boolean gotData = false; boolean gotData = false;
boolean kicked = false; boolean kicked = false;
IntSet recieved = new IntSet(); IntSet recieved = new IntSet();
IntSet dead = new IntSet();
float playerSyncTime = 2; float playerSyncTime = 2;
float dataTimeout = 60*18; //18 seconds timeout float dataTimeout = 60*18; //18 seconds timeout
@@ -46,7 +45,6 @@ public class NetClient extends Module {
Net.handleClient(Connect.class, packet -> { Net.handleClient(Connect.class, packet -> {
Net.setClientLoaded(false); Net.setClientLoaded(false);
recieved.clear(); recieved.clear();
dead.clear();
connecting = true; connecting = true;
gotData = false; gotData = false;
kicked = false; kicked = false;
@@ -162,7 +160,7 @@ public class NetClient extends Module {
//duplicates. //duplicates.
if (group.getByID(packet.entity.id) != null || if (group.getByID(packet.entity.id) != null ||
recieved.contains(packet.entity.id) || dead.contains(packet.entity.id)) return; recieved.contains(packet.entity.id)) return;
recieved.add(packet.entity.id); recieved.add(packet.entity.id);
@@ -171,10 +169,14 @@ public class NetClient extends Module {
Log.info("Recieved entity {0}", packet.entity.id); Log.info("Recieved entity {0}", packet.entity.id);
}); });
Net.handleClient(EnemyDeathPacket.class, spawn -> { Net.handleClient(EnemyDeathPacket.class, packet -> {
Enemy enemy = enemyGroup.getByID(spawn.id); Enemy enemy = enemyGroup.getByID(packet.id);
if (enemy != null) enemy.type.onDeath(enemy, true); if (enemy != null){
dead.add(spawn.id); enemy.type.onDeath(enemy, true);
}else{
Log.err("Got remove for null entity! {0}", packet.id);
}
recieved.add(packet.id);
}); });
Net.handleClient(BulletPacket.class, packet -> { Net.handleClient(BulletPacket.class, packet -> {
@@ -310,7 +312,6 @@ public class NetClient extends Module {
public void clearRecieved(){ public void clearRecieved(){
recieved.clear(); recieved.clear();
dead.clear();
} }
void sync(){ void sync(){

View File

@@ -1,6 +1,8 @@
package io.anuke.mindustry.entities; package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
@@ -14,7 +16,9 @@ import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.SolidEntity; import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@@ -50,8 +54,13 @@ public class Player extends SyncEntity{
@Override @Override
public void damage(int amount){ public void damage(int amount){
if(!debug && !isAndroid) if(debug || isAndroid) return;
super.damage(amount);
health -= amount;
if(health <= 0 && !dead && isLocal){ //remote players don't die normally
onDeath();
dead = true;
}
} }
@Override @Override
@@ -67,8 +76,6 @@ public class Player extends SyncEntity{
@Override @Override
public void onDeath(){ public void onDeath(){
if(!isLocal) return;
remove(); remove();
if(Net.active()){ if(Net.active()){
NetEvents.handlePlayerDeath(); NetEvents.handlePlayerDeath();
@@ -264,18 +271,40 @@ public class Player extends SyncEntity{
short health = data.getShort(); short health = data.getShort();
byte dashing = data.get(); byte dashing = data.get();
interpolator.target.set(x, y);
interpolator.targetrot = angle; interpolator.targetrot = angle;
this.health = health; this.health = health;
this.dashing = dashing == 1; this.dashing = dashing == 1;
if(interpolator.lastread == 0){
interpolator.lastread = TimeUtils.millis();
interpolator.spacing = 1f;
interpolator.target.set(x, y);
interpolator.last.set(x, y);
this.x = x;
this.y = y;
return;
}
interpolator.time = 0f;
interpolator.spacing = Math.max(TimeUtils.timeSinceMillis(interpolator.lastread) / 1000f * 60f, 0.1f);
interpolator.last.set(this.x, this.y);
interpolator.target.set(x, y);
interpolator.lastread = TimeUtils.millis();
Log.info("Taken {0} frames to move {1}", interpolator.spacing, interpolator.last.dst(interpolator.target));
} }
@Override @Override
public void interpolate() { public void interpolate() {
Interpolator i = interpolator; Interpolator i = interpolator;
if(i.target.dst(x, y) > 16 && !isAndroid){
set(i.target.x, i.target.y); i.time += 1f / i.spacing * Timers.delta();
}
lerp2(Tmp.v2.set(i.last), i.target, i.time);
/*
if(isAndroid && i.target.dst(x, y) > 2f && Timers.get(this, "dashfx", 2)){ if(isAndroid && i.target.dst(x, y) > 2f && Timers.get(this, "dashfx", 2)){
Angles.translation(angle + 180, 3f); Angles.translation(angle + 180, 3f);
@@ -285,11 +314,25 @@ public class Player extends SyncEntity{
if(dashing && !dead && Timers.get(this, "dashfx", 3)){ if(dashing && !dead && Timers.get(this, "dashfx", 3)){
Angles.translation(angle + 180, 3f); Angles.translation(angle + 180, 3f);
Effects.effect(Fx.dashsmoke, x + Angles.x(), y + Angles.y()); Effects.effect(Fx.dashsmoke, x + Angles.x(), y + Angles.y());
} }*/
x = Tmp.v2.x;
y = Tmp.v2.y;
x = Mathf.lerpDelta(x, i.target.x, 0.4f);
y = Mathf.lerpDelta(y, i.target.y, 0.4f);
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f); angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
Log.info("{0}, {1}, t={2}, s={5}, l={3}, t={4}", x, y, i.time, i.last, i.target, i.spacing);
if(i.target.dst(x, y) > 24 && !isAndroid){
Log.info("clamping");
// set(i.target.x, i.target.y);
}
}
private Vector2 lerp2 (Vector2 v, Vector2 target, float alpha) {
v.x = (v.x) + ((target.x - v.x) * alpha);
v.y = (v.y) + ((target.y - v.y) * alpha);
return v;
} }
public Color getColor(){ public Color getColor(){

View File

@@ -43,5 +43,8 @@ public abstract class SyncEntity extends DestructibleEntity{
public Vector2 delta = new Vector2(); public Vector2 delta = new Vector2();
public Vector2 last = new Vector2(); public Vector2 last = new Vector2();
public float targetrot; public float targetrot;
public long lastread;
public float spacing = 1f;
public float time;
} }
} }

View File

@@ -82,7 +82,7 @@ public class EnemyType {
if(showPaths){ if(showPaths){
Draw.tscl(0.25f); Draw.tscl(0.25f);
Draw.text((int)enemy.idletime + " " + enemy.node + "\n" + Strings.toFixed(enemy.totalMove.x, 2) + ", " Draw.text((int)enemy.idletime + " " + enemy.node + " " + enemy.id + "\n" + Strings.toFixed(enemy.totalMove.x, 2) + ", "
+ Strings.toFixed(enemy.totalMove.x, 2), enemy.x, enemy.y); + Strings.toFixed(enemy.totalMove.x, 2), enemy.x, enemy.y);
Draw.tscl(fontscale); Draw.tscl(fontscale);
} }

View File

@@ -25,8 +25,10 @@ public class DebugFragment implements Fragment {
@Override @Override
public void print(String text, Object... args){ public void print(String text, Object... args){
super.print(text, args); super.print(text, args);
log.append(Log.format(text, args)); if(log.length() < 1000) {
log.append("\n"); log.append(Log.format(text, args));
log.append("\n");
}
} }
}); });
} }
@@ -57,7 +59,7 @@ public class DebugFragment implements Fragment {
netClient.clearRecieved(); netClient.clearRecieved();
}); });
row(); row();
new button("spawn", () -> new Enemy(EnemyTypes.blast).set(player.x, player.y).add()); new button("spawn", () -> new Enemy(EnemyTypes.standard).set(player.x, player.y).add());
row(); row();
new button("stuff", () -> netClient.test()); new button("stuff", () -> netClient.test());
row(); row();

View File

@@ -23,7 +23,7 @@ public class Junction extends Block{
int dir = source.relativeTo(tile.x, tile.y); int dir = source.relativeTo(tile.x, tile.y);
Tile to = tile.getNearby(temptiles)[dir]; Tile to = tile.getNearby(temptiles)[dir];
Timers.run(30, ()->{ Timers.run(30, () -> {
if(to == null) return; if(to == null) return;
to.block().handleItem(item, to, tile); to.block().handleItem(item, to, tile);
}); });

View File

@@ -15,7 +15,7 @@ import static io.anuke.mindustry.Vars.headless;
import static io.anuke.mindustry.Vars.playerGroup; import static io.anuke.mindustry.Vars.playerGroup;
public class KryoRegistrator { public class KryoRegistrator {
public static boolean fakeLag = false; public static boolean fakeLag = true;
public static final int fakeLagAmount = 500; public static final int fakeLagAmount = 500;
static{ static{

View File

@@ -293,6 +293,13 @@ public class KryoServer implements ServerProvider {
Log.err(e); Log.err(e);
} }
Log.info("Disposed server."); Log.info("Disposed server.");
for(Thread thread : Thread.getAllStackTraces().keySet()){
if(!thread.isDaemon()){
Log.info(thread.toString());
thread.interrupt();
}
}
} }
private void handleException(Throwable e){ private void handleException(Throwable e){