diff --git a/src/main/hw/Timer.hx b/src/main/hw/Timer.hx new file mode 100644 index 0000000..8008850 --- /dev/null +++ b/src/main/hw/Timer.hx @@ -0,0 +1,60 @@ +package hw; + +#if cpp + +import haxe.Log; +import haxe.PosInfos; +import cpp.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(hw.log.BaseLogger.LoggerUtil.printError(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(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 diff --git a/src/main/hw/connect/WebSocketTools.hx b/src/main/hw/connect/WebSocketTools.hx deleted file mode 100644 index 601576a..0000000 --- a/src/main/hw/connect/WebSocketTools.hx +++ /dev/null @@ -1,24 +0,0 @@ -package hw.connect; - -import haxe.io.BytesOutput; - - -class WebSocketTools { - - public static function packet2string(packet:Message):String { - var b = new BytesOutput(); - packet.writeTo(b); - var data = b.getBytes(); - var res = new BytesOutput(); - //res.writeUInt16(data.length); - res.write(data); - return Base64.encodeBase64(res.getBytes()); - } - - public static function string2packet(data:String, packetClass:Class

):P { - var bytes = Base64.decodeBase64(data); - var packet:P = Type.createInstance(packetClass, []); - packet.mergeFrom(bytes); - return packet; - } -} diff --git a/src/main/hw/connect/fake/FakeConnection.hx b/src/main/hw/connect/fake/FakeConnection.hx index 945f043..3ef56fd 100644 --- a/src/main/hw/connect/fake/FakeConnection.hx +++ b/src/main/hw/connect/fake/FakeConnection.hx @@ -1,5 +1,6 @@ package hw.connect.fake; +import hw.connect.IConnection; import promhx.Promise; import protohx.Message; diff --git a/src/main/hw/connect/neko/NekoConnection.hx b/src/main/hw/connect/neko/NekoConnection.hx index 6be7dbb..cf915af 100755 --- a/src/main/hw/connect/neko/NekoConnection.hx +++ b/src/main/hw/connect/neko/NekoConnection.hx @@ -1,6 +1,6 @@ package hw.connect.neko; -import haxe.Timer; +import hw.Timer; import protohx.Message; import sys.net.Socket; diff --git a/src/main/hw/view/data/DataView.hx b/src/main/hw/view/data/DataView.hx index 3b5b9ac..dfe3022 100644 --- a/src/main/hw/view/data/DataView.hx +++ b/src/main/hw/view/data/DataView.hx @@ -45,7 +45,7 @@ class DataView> extends GroupView { view.content.removeEventListener(MouseEvent.CLICK, onItemClick); } objectIndexes = new Map(); - dataViews = Lambda.array(Lambda.mapi(data, factory)); + dataViews = [for (index in 0...data.length) factory(index, data[index])]; views = cast dataViews; for (i in 0...dataViews.length) { objectIndexes[dataViews[i].content] = i;