Large-scale bugfix: fixed #76, as well as many other timer bugs
This commit is contained in:
@@ -26,6 +26,7 @@ import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -37,6 +38,7 @@ public class NetClient extends Module {
|
||||
private final static float dataTimeout = 60*18; //18 seconds timeout
|
||||
private final static float playerSyncTime = 2;
|
||||
|
||||
private Timer timer = new Timer(5);
|
||||
private boolean connecting = false;
|
||||
private boolean gotData = false;
|
||||
private boolean kicked = false;
|
||||
@@ -75,7 +77,7 @@ public class NetClient extends Module {
|
||||
Net.handleClient(Disconnect.class, packet -> {
|
||||
if (kicked) return;
|
||||
|
||||
Timers.runFor(3f, ui.loadfrag::hide);
|
||||
Timers.runTask(3f, ui.loadfrag::hide);
|
||||
|
||||
state.set(State.menu);
|
||||
|
||||
@@ -153,7 +155,8 @@ public class NetClient extends Module {
|
||||
state.wavetime = packet.countdown;
|
||||
state.wave = packet.wave;
|
||||
|
||||
Timers.resetTime(packet.time + (float) (TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0));
|
||||
//removed: messing with time isn't necessary anymore
|
||||
//Timers.resetTime(packet.time + (float) (TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0));
|
||||
|
||||
ui.hudfrag.updateItems();
|
||||
});
|
||||
@@ -334,7 +337,9 @@ public class NetClient extends Module {
|
||||
}
|
||||
|
||||
void sync(){
|
||||
if(Timers.get("syncPlayer", playerSyncTime)){
|
||||
|
||||
if(timer.get(0, playerSyncTime)){
|
||||
|
||||
byte[] bytes = new byte[player.getWriteSize() + 8];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||
buffer.putLong(TimeUtils.millis());
|
||||
@@ -345,7 +350,7 @@ public class NetClient extends Module {
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
if(Timers.get("updatePing", 60)){
|
||||
if(timer.get(1, playerSyncTime)){
|
||||
Net.updatePing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -34,11 +35,16 @@ import java.nio.ByteBuffer;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class NetServer extends Module{
|
||||
private final static float serverSyncTime = 4, itemSyncTime = 10, blockSyncTime = 120;
|
||||
|
||||
private final static int timerEntitySync = 0;
|
||||
private final static int timerStateSync = 1;
|
||||
|
||||
/**Maps connection IDs to players.*/
|
||||
IntMap<Player> connections = new IntMap<>();
|
||||
ObjectMap<String, ByteArray> weapons = new ObjectMap<>();
|
||||
float serverSyncTime = 4, itemSyncTime = 10, blockSyncTime = 120;
|
||||
boolean closing = false;
|
||||
private IntMap<Player> connections = new IntMap<>();
|
||||
private ObjectMap<String, ByteArray> weapons = new ObjectMap<>();
|
||||
private boolean closing = false;
|
||||
private Timer timer = new Timer(5);
|
||||
|
||||
public NetServer(){
|
||||
|
||||
@@ -218,7 +224,7 @@ public class NetServer extends Module{
|
||||
|
||||
void sync(){
|
||||
|
||||
if(Timers.get("serverSync", serverSyncTime)){
|
||||
if(timer.get(timerEntitySync, serverSyncTime)){
|
||||
//scan through all groups with syncable entities
|
||||
for(EntityGroup<?> group : Entities.getAllGroups()) {
|
||||
if(group.size() == 0 || !(group.all().first() instanceof SyncEntity)) continue;
|
||||
@@ -283,7 +289,7 @@ public class NetServer extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
if(Timers.get("serverItemSync", itemSyncTime)){
|
||||
if(timer.get(timerStateSync, itemSyncTime)){
|
||||
StateSyncPacket packet = new StateSyncPacket();
|
||||
packet.items = state.inventory.getItems();
|
||||
packet.countdown = state.wavetime;
|
||||
@@ -294,6 +300,7 @@ public class NetServer extends Module{
|
||||
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
/*
|
||||
if(Timers.get("serverBlockSync", blockSyncTime)){
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ import io.anuke.ucore.entities.BulletEntity;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Bullet extends BulletEntity{
|
||||
public Timer timer = new Timer(3);
|
||||
|
||||
public Bullet(BulletType type, Entity owner, float x, float y, float angle){
|
||||
super(type, owner, angle);
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
|
||||
public void update(Bullet b){
|
||||
if(Timers.get(b, "smoke", 4)){
|
||||
if(b.timer.get(0, 4)){
|
||||
Effects.effect(Fx.railsmoke, b.x, b.y);
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
|
||||
public void update(Bullet b){
|
||||
if(Timers.get(b, "smoke", 2)){
|
||||
if(b.timer.get(0, 2)){
|
||||
Effects.effect(Fx.empspark, b.x + Mathf.range(2), b.y + Mathf.range(2));
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
|
||||
public void update(Bullet b){
|
||||
if(Timers.get(b, "smoke", 7)){
|
||||
if(b.timer.get(0, 7)){
|
||||
Effects.effect(Fx.smoke, b.x + Mathf.range(2), b.y + Mathf.range(2));
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
|
||||
public void update(Bullet b){
|
||||
if(Timers.get(b, "smoke", 7)){
|
||||
if(b.timer.get(0, 7)){
|
||||
Effects.effect(Fx.smoke, b.x + Mathf.range(2), b.y + Mathf.range(2));
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
|
||||
public void update(Bullet b){
|
||||
if(Timers.get(b, "smoke", 4)){
|
||||
if(b.timer.get(0, 4)){
|
||||
Effects.effect(Fx.smoke, b.x + Mathf.range(2), b.y + Mathf.range(2));
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
|
||||
public void update(Bullet b){
|
||||
if(Timers.get(b, "smoke", 4)){
|
||||
if(b.timer.get(0, 4)){
|
||||
Effects.effect(Fx.smoke, b.x + Mathf.range(2), b.y + Mathf.range(2));
|
||||
}
|
||||
}
|
||||
@@ -391,7 +391,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
|
||||
public void update(Bullet b){
|
||||
if(Timers.get(b, "smoke", 4)){
|
||||
if(b.timer.get(0, 4)){
|
||||
Effects.effect(Fx.chainsmoke, b.x, b.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -26,6 +27,11 @@ public class Player extends SyncEntity{
|
||||
static final float speed = 1.1f;
|
||||
static final float dashSpeed = 1.8f;
|
||||
|
||||
static final int timerDash = 0;
|
||||
static final int timerShootLeft = 1;
|
||||
static final int timerShootRight = 2;
|
||||
static final int timerRegen = 20;
|
||||
|
||||
public String name = "name";
|
||||
public boolean isAndroid;
|
||||
public Color color = new Color();
|
||||
@@ -40,6 +46,7 @@ public class Player extends SyncEntity{
|
||||
|
||||
public int clientid;
|
||||
public boolean isLocal = false;
|
||||
public Timer timer = new Timer(4);
|
||||
|
||||
private Vector2 movement = new Vector2();
|
||||
private Translator tr = new Translator();
|
||||
@@ -168,7 +175,7 @@ public class Player extends SyncEntity{
|
||||
|
||||
float speed = dashing ? (debug ? Player.dashSpeed * 5f : Player.dashSpeed) : Player.speed;
|
||||
|
||||
if(health < maxhealth && Timers.get(this, "regen", 20))
|
||||
if(health < maxhealth && timer.get(timerRegen, 20 ))
|
||||
health ++;
|
||||
|
||||
health = Mathf.clamp(health, -1, maxhealth);
|
||||
@@ -191,7 +198,7 @@ public class Player extends SyncEntity{
|
||||
weaponRight.update(player, false);
|
||||
}
|
||||
|
||||
if(dashing && Timers.get(this, "dashfx", 3) && movement.len() > 0){
|
||||
if(dashing && timer.get(timerDash, 3) && movement.len() > 0){
|
||||
Effects.effect(Fx.dashsmoke, x + Angles.trnsx(angle + 180f, 3f), y + Angles.trnsy(angle + 180f, 3f));
|
||||
}
|
||||
|
||||
@@ -255,7 +262,7 @@ public class Player extends SyncEntity{
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer data) {
|
||||
if(Net.client()) {
|
||||
if(Net.client() || isLocal) {
|
||||
data.putFloat(x);
|
||||
data.putFloat(y);
|
||||
}else{
|
||||
@@ -290,11 +297,11 @@ public class Player extends SyncEntity{
|
||||
float tx = x + Angles.trnsx(angle + 180f, 3f);
|
||||
float ty = y + Angles.trnsy(angle + 180f, 3f);
|
||||
|
||||
if(isAndroid && i.target.dst(i.last) > 2f && Timers.get(this, "dashfx", 2)){
|
||||
if(isAndroid && i.target.dst(i.last) > 2f && timer.get(timerDash, 1)){
|
||||
Effects.effect(Fx.dashsmoke, tx, ty);
|
||||
}
|
||||
|
||||
if(dashing && !dead && Timers.get(this, "dashfx", 3) && i.target.dst(i.last) > 1f){
|
||||
if(dashing && !dead && timer.get(timerDash, 3) && i.target.dst(i.last) > 1f){
|
||||
Effects.effect(Fx.dashsmoke, tx, ty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +227,7 @@ public class NetworkIO {
|
||||
float timerTime = stream.readFloat();
|
||||
long timestamp = stream.readLong();
|
||||
|
||||
Timers.clear();
|
||||
Timers.resetTime(timerTime + (TimeUtils.timeSinceMillis(timestamp) / 1000f) * 60f);
|
||||
|
||||
//general state
|
||||
|
||||
@@ -9,7 +9,6 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@@ -98,9 +97,11 @@ public class Weapon extends Upgrade{
|
||||
}
|
||||
|
||||
public void update(Player p, boolean left){
|
||||
if(Timers.get(p, "reload"+left, reload)){
|
||||
int t = left ? 1 : 2;
|
||||
int t2 = !left ? 1 : 2;
|
||||
if(p.timer.get(t, reload)){
|
||||
if(roundrobin){
|
||||
Timers.reset(p, "reload" + !left, reload/2f);
|
||||
p.timer.reset(t2, reload/2f);
|
||||
}
|
||||
float ang = Angles.mouseAngle(p.x, p.y);
|
||||
tr.trns(ang - 90, 3f * Mathf.sign(left), length);
|
||||
|
||||
@@ -3,7 +3,10 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.entities.enemies.EnemyTypes;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.builders.button;
|
||||
import io.anuke.ucore.scene.builders.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
@@ -12,6 +15,7 @@ import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Log.LogHandler;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -57,8 +61,19 @@ public class DebugFragment implements Fragment {
|
||||
netClient.clearRecieved();
|
||||
});
|
||||
row();
|
||||
new button("spawn", () -> {});
|
||||
new button("spawn", () -> {
|
||||
for(int i = 0; i < 30; i ++){
|
||||
new Enemy(EnemyTypes.blast).set(player.x + Mathf.range(50f), player.y + Mathf.range(50f)).add();
|
||||
}
|
||||
});
|
||||
row();
|
||||
new button("time", () -> {
|
||||
Timers.resetTime(10368000);
|
||||
});
|
||||
row();
|
||||
new button("time2", () -> {
|
||||
Timers.resetTime(0);
|
||||
});
|
||||
}}.end();
|
||||
|
||||
row();
|
||||
@@ -114,6 +129,8 @@ public class DebugFragment implements Fragment {
|
||||
StringBuilder result = join(
|
||||
"net.active: " + Net.active(),
|
||||
"net.server: " + Net.server(),
|
||||
"net.client: " + Net.client(),
|
||||
"state: " + state.getState(),
|
||||
Net.client() ?
|
||||
"chat.open: " + ui.chatfrag.chatOpen() + "\n" +
|
||||
"chat.messages: " + ui.chatfrag.getMessagesSize() + "\n" +
|
||||
@@ -122,6 +139,7 @@ public class DebugFragment implements Fragment {
|
||||
"players: " + playerGroup.size(),
|
||||
"enemies: " + enemyGroup.size(),
|
||||
"tiles: " + tileGroup.size(),
|
||||
"time: " + Timers.time(),
|
||||
world.getCore() != null && world.getCore().entity != null ? "core.health: " + world.getCore().entity.health : "",
|
||||
"core: " + world.getCore(),
|
||||
"state.gameover: " + state.gameOver,
|
||||
|
||||
Reference in New Issue
Block a user