mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-22 22:07:31 +03:00
Various multiplayer tweaks
This commit is contained in:
parent
608343b9d1
commit
a31c4b273d
@ -97,7 +97,7 @@ public class Vars{
|
||||
Color.valueOf("ffcaa8"),
|
||||
Color.valueOf("008551"),
|
||||
Color.valueOf("00e339"),
|
||||
Color.valueOf("222e53"),
|
||||
Color.valueOf("423c7b"),
|
||||
Color.valueOf("4b5ef1"),
|
||||
Color.valueOf("2cabfe"),
|
||||
};
|
||||
|
@ -37,7 +37,6 @@ public class NetClient extends Module {
|
||||
boolean gotData = false;
|
||||
boolean kicked = false;
|
||||
IntSet recieved = new IntSet();
|
||||
IntSet dead = new IntSet();
|
||||
float playerSyncTime = 2;
|
||||
float dataTimeout = 60*18; //18 seconds timeout
|
||||
|
||||
@ -46,7 +45,6 @@ public class NetClient extends Module {
|
||||
Net.handleClient(Connect.class, packet -> {
|
||||
Net.setClientLoaded(false);
|
||||
recieved.clear();
|
||||
dead.clear();
|
||||
connecting = true;
|
||||
gotData = false;
|
||||
kicked = false;
|
||||
@ -162,7 +160,7 @@ public class NetClient extends Module {
|
||||
|
||||
//duplicates.
|
||||
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);
|
||||
|
||||
@ -171,10 +169,14 @@ public class NetClient extends Module {
|
||||
Log.info("Recieved entity {0}", packet.entity.id);
|
||||
});
|
||||
|
||||
Net.handleClient(EnemyDeathPacket.class, spawn -> {
|
||||
Enemy enemy = enemyGroup.getByID(spawn.id);
|
||||
if (enemy != null) enemy.type.onDeath(enemy, true);
|
||||
dead.add(spawn.id);
|
||||
Net.handleClient(EnemyDeathPacket.class, packet -> {
|
||||
Enemy enemy = enemyGroup.getByID(packet.id);
|
||||
if (enemy != null){
|
||||
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 -> {
|
||||
@ -310,7 +312,6 @@ public class NetClient extends Module {
|
||||
|
||||
public void clearRecieved(){
|
||||
recieved.clear();
|
||||
dead.clear();
|
||||
}
|
||||
|
||||
void sync(){
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
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.Shaders;
|
||||
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.graphics.Draw;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@ -50,8 +54,13 @@ public class Player extends SyncEntity{
|
||||
|
||||
@Override
|
||||
public void damage(int amount){
|
||||
if(!debug && !isAndroid)
|
||||
super.damage(amount);
|
||||
if(debug || isAndroid) return;
|
||||
|
||||
health -= amount;
|
||||
if(health <= 0 && !dead && isLocal){ //remote players don't die normally
|
||||
onDeath();
|
||||
dead = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,8 +76,6 @@ public class Player extends SyncEntity{
|
||||
|
||||
@Override
|
||||
public void onDeath(){
|
||||
if(!isLocal) return;
|
||||
|
||||
remove();
|
||||
if(Net.active()){
|
||||
NetEvents.handlePlayerDeath();
|
||||
@ -264,18 +271,40 @@ public class Player extends SyncEntity{
|
||||
short health = data.getShort();
|
||||
byte dashing = data.get();
|
||||
|
||||
interpolator.target.set(x, y);
|
||||
interpolator.targetrot = angle;
|
||||
this.health = health;
|
||||
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
|
||||
public void interpolate() {
|
||||
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)){
|
||||
Angles.translation(angle + 180, 3f);
|
||||
@ -285,11 +314,25 @@ public class Player extends SyncEntity{
|
||||
if(dashing && !dead && Timers.get(this, "dashfx", 3)){
|
||||
Angles.translation(angle + 180, 3f);
|
||||
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);
|
||||
|
||||
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(){
|
||||
|
@ -43,5 +43,8 @@ public abstract class SyncEntity extends DestructibleEntity{
|
||||
public Vector2 delta = new Vector2();
|
||||
public Vector2 last = new Vector2();
|
||||
public float targetrot;
|
||||
public long lastread;
|
||||
public float spacing = 1f;
|
||||
public float time;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class EnemyType {
|
||||
|
||||
if(showPaths){
|
||||
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);
|
||||
Draw.tscl(fontscale);
|
||||
}
|
||||
|
@ -25,8 +25,10 @@ public class DebugFragment implements Fragment {
|
||||
@Override
|
||||
public void print(String text, Object... args){
|
||||
super.print(text, args);
|
||||
log.append(Log.format(text, args));
|
||||
log.append("\n");
|
||||
if(log.length() < 1000) {
|
||||
log.append(Log.format(text, args));
|
||||
log.append("\n");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -57,7 +59,7 @@ public class DebugFragment implements Fragment {
|
||||
netClient.clearRecieved();
|
||||
});
|
||||
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();
|
||||
new button("stuff", () -> netClient.test());
|
||||
row();
|
||||
|
@ -23,7 +23,7 @@ public class Junction extends Block{
|
||||
int dir = source.relativeTo(tile.x, tile.y);
|
||||
Tile to = tile.getNearby(temptiles)[dir];
|
||||
|
||||
Timers.run(30, ()->{
|
||||
Timers.run(30, () -> {
|
||||
if(to == null) return;
|
||||
to.block().handleItem(item, to, tile);
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ import static io.anuke.mindustry.Vars.headless;
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
|
||||
public class KryoRegistrator {
|
||||
public static boolean fakeLag = false;
|
||||
public static boolean fakeLag = true;
|
||||
public static final int fakeLagAmount = 500;
|
||||
|
||||
static{
|
||||
|
@ -293,6 +293,13 @@ public class KryoServer implements ServerProvider {
|
||||
Log.err(e);
|
||||
}
|
||||
Log.info("Disposed server.");
|
||||
|
||||
for(Thread thread : Thread.getAllStackTraces().keySet()){
|
||||
if(!thread.isDaemon()){
|
||||
Log.info(thread.toString());
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleException(Throwable e){
|
||||
|
Loading…
Reference in New Issue
Block a user