[connect] fixes
This commit is contained in:
60
src/main/hw/Timer.hx
Normal file
60
src/main/hw/Timer.hx
Normal file
@@ -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<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,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<P:Message>(data:String, packetClass:Class<P>):P {
|
||||
var bytes = Base64.decodeBase64(data);
|
||||
var packet:P = Type.createInstance(packetClass, []);
|
||||
packet.mergeFrom(bytes);
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package hw.connect.fake;
|
||||
|
||||
import hw.connect.IConnection;
|
||||
import promhx.Promise;
|
||||
import protohx.Message;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package hw.connect.neko;
|
||||
|
||||
import haxe.Timer;
|
||||
import hw.Timer;
|
||||
import protohx.Message;
|
||||
import sys.net.Socket;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class DataView<D, V:IView<Dynamic>> 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;
|
||||
|
||||
Reference in New Issue
Block a user