[common] update for network

This commit is contained in:
2019-05-28 17:03:04 +03:00
parent ba13111a8e
commit 1d95de02e1
21 changed files with 130 additions and 20 deletions

View File

@@ -20,7 +20,7 @@ class Timer {
try {
run();
} catch (error:Dynamic) {
trace(error);
trace(haxework.log.BaseLogger.LoggerUtil.printError(error));
}
}
});

View File

@@ -5,7 +5,6 @@ import haxe.io.BytesBuffer;
import haxe.io.BytesInput;
import protohx.Message;
class PacketQueue<P:Message> {
public var packetClass(default, null):Class<P>;
@@ -73,4 +72,7 @@ class PacketQueue<P:Message> {
}
}
}
public function clean():Void {
bytesBuff = null;
}
}

View File

@@ -80,7 +80,9 @@ class FlashConnection<O:Message, I:Message> extends BaseConnection<O, I> {
var bytes = Bytes.ofData(data);
pushData(bytes);
} catch (error:Dynamic) {
handler.emit(ConnectionEvent.ERROR(error));
L.w("Connection", "onSocketData ", error);
queue.clean();
//handler.emit(ConnectionEvent.ERROR(error));
}
}

View File

@@ -1,6 +1,6 @@
package ru.m.tankz.bot;
import haxe.Timer;
import ru.m.Timer;
import ru.m.geom.Direction;
import ru.m.tankz.control.Control;
import ru.m.tankz.core.Tank;

View File

@@ -1,6 +1,6 @@
package ru.m.tankz.bot;
import haxe.Timer;
import ru.m.Timer;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.core.Tank;

View File

@@ -1,6 +1,6 @@
package ru.m.tankz.bot;
import haxe.Timer;
import ru.m.Timer;
import ru.m.tankz.control.Control;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.EntityType;

View File

@@ -4,7 +4,6 @@ import ru.m.geom.Direction;
import ru.m.geom.Line;
import ru.m.geom.Point;
import ru.m.tankz.config.Config;
import ru.m.tankz.core.Bullet;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.core.MobileEntity;
@@ -68,7 +67,7 @@ import ru.m.tankz.map.LevelMap;
}
public function update():Void {
var newTime:Float = Date.now().getTime();
var newTime:Float = Timer.stamp() * 1000;
var d:Float = newTime - time;
time = newTime;

View File

@@ -19,8 +19,8 @@ import ru.m.tankz.Type;
public var teams(default, null):Map<TeamId, Team>;
public var config(default, null):Config;
public var winner(default, null):Null<TeamId>;
public var state(default, null):GameState;
public var frame(default, null):Int;
@:provide var configBundle:IConfigBundle;
@@ -29,6 +29,7 @@ import ru.m.tankz.Type;
this.state = state;
this.teams = new Map();
this.config = configBundle.get(type);
this.frame = 0;
connect(this);
}

View File

@@ -1,6 +1,5 @@
package ru.m.tankz.game;
import haxe.ds.Option;
import ru.m.geom.Line;
import ru.m.geom.Point;
import ru.m.tankz.control.Control;
@@ -34,6 +33,7 @@ class GameRunner extends Game implements EngineListener {
}
private function update():Void {
frame++;
engine.update();
}
@@ -331,7 +331,10 @@ class GameRunner extends Game implements EngineListener {
gameEventSignal.emit(GameEvent.STOP(TANK(tankId)));
engine.stop(tankId);
case GameEvent.SPAWN(TANK(_, _, playerId, _)):
getPlayer(playerId).control.start();
var control = getPlayer(playerId).control;
if (control != null) {
control.start();
}
case GameEvent.SPAWN(BULLET(_, _, playerId, _)):
getPlayer(playerId).bullets++;
case GameEvent.DESTROY(EAGLE(id, shot)):
@@ -346,7 +349,9 @@ class GameRunner extends Game implements EngineListener {
var tank:Tank = engine.getEntity(id);
var team = getTeam(tank.playerId.team);
var player = getPlayer(tank.playerId);
player.control.stop();
if (player.control != null) {
player.control.stop();
}
player.tankId = 0; //ToDo: ?
team.onDestroy(player.id);
if (player.state.life > 0) {

View File

@@ -10,6 +10,7 @@ interface IGame extends GameListener {
public var config(default, null):Config;
public var winner(default, null):Null<TeamId>;
public var state(default, null):GameState;
public var frame(default, null):Int;
public var gameEventSignal(default, null):Signal<GameEvent>;

View File

@@ -19,6 +19,7 @@ class Team {
public function new(config:TeamConfig, points:Array<SpawnPoint>, state:TeamState = null) {
this.id = config.id;
this.config = config;
this.active = 0;
this.players = new Map();
for (playerConfig in config.players) {
var playerState = state == null ? null : state.players[playerConfig.index];

View File

@@ -6,7 +6,6 @@ import ru.m.tankz.game.record.GameRecord;
class GamePlayer extends Game {
private var frame:Int;
private var record:GameRecord;
private var data:Array<EventItem>;