[client] add GameRoomFrame
This commit is contained in:
60
src/common/haxe/ru/m/Timer.hx
Normal file
60
src/common/haxe/ru/m/Timer.hx
Normal file
@@ -0,0 +1,60 @@
|
||||
package ru.m;
|
||||
|
||||
#if neko
|
||||
|
||||
import haxe.Log;
|
||||
import haxe.PosInfos;
|
||||
import neko.vm.Thread;
|
||||
|
||||
class Timer {
|
||||
|
||||
private var sleep:Float;
|
||||
private var stopped:Bool;
|
||||
|
||||
public function new(time_ms:Int) {
|
||||
this.sleep = time_ms / 1000.0;
|
||||
this.stopped = false;
|
||||
Thread.create(function() {
|
||||
while (!stopped) {
|
||||
Sys.sleep(sleep);
|
||||
try {
|
||||
run();
|
||||
} catch (error:Dynamic) {
|
||||
trace(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function stop() {
|
||||
stopped = true;
|
||||
}
|
||||
|
||||
public dynamic function run() {}
|
||||
|
||||
public static function delay(f:Void -> Void, time_ms:Int) {
|
||||
var t = new Timer(time_ms);
|
||||
t.run = function() {
|
||||
t.stop();
|
||||
f();
|
||||
};
|
||||
return t;
|
||||
}
|
||||
|
||||
public static function measure<T>(f:Void -> T, ?pos:PosInfos):T {
|
||||
var t0 = stamp();
|
||||
var r = f();
|
||||
Log.trace((stamp() - t0) + "s", pos);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static inline function stamp():Float {
|
||||
return Sys.time();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef Timer = haxe.Timer;
|
||||
|
||||
#end
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import haxe.Timer;
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.Timer;
|
||||
|
||||
class Modificator extends Signal2<Int, Bool> {
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import haxe.ds.Option;
|
||||
import haxe.Timer;
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.geom.Line;
|
||||
import ru.m.geom.Point;
|
||||
@@ -18,6 +17,7 @@ import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.game.Spawner;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.Timer;
|
||||
|
||||
class GameRunner implements EngineListener implements GameListener {
|
||||
@:provide var controlFactory:IControlFactory;
|
||||
|
||||
@@ -13,7 +13,10 @@ class State {
|
||||
public var hits:Int;
|
||||
|
||||
public function new() {
|
||||
|
||||
score = 0;
|
||||
frags = 0;
|
||||
shots = 0;
|
||||
hits = 0;
|
||||
}
|
||||
|
||||
public function add(state:State) {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import haxe.Timer;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
import ru.m.Timer;
|
||||
|
||||
typedef SpawnTask = {
|
||||
var point:SpawnPoint;
|
||||
|
||||
@@ -50,6 +50,7 @@ message JoinGameRequest {
|
||||
|
||||
message JoinGameResponse {
|
||||
ru.m.tankz.proto.core.GameProto game = 1;
|
||||
ru.m.tankz.proto.core.UserProto user = 2;
|
||||
}
|
||||
|
||||
// Leave Game
|
||||
@@ -57,6 +58,7 @@ message LeaveGameRequest {}
|
||||
|
||||
message LeaveGameResponse {
|
||||
ru.m.tankz.proto.core.GameProto game = 1;
|
||||
ru.m.tankz.proto.core.UserProto user = 2;
|
||||
}
|
||||
|
||||
// Start Game
|
||||
@@ -89,5 +91,7 @@ message Response {
|
||||
JoinGameResponse joinGame = 5;
|
||||
LeaveGameResponse leaveGame = 6;
|
||||
StartGameResponse startGame = 7;
|
||||
|
||||
ErrorResponse error = 999;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user