[common] bullet with bricks collision
This commit is contained in:
60
src/common/haxe/ru/m/connect/BaseConnection.hx
Executable file
60
src/common/haxe/ru/m/connect/BaseConnection.hx
Executable file
@@ -0,0 +1,60 @@
|
||||
package ru.m.connect;
|
||||
|
||||
import haxework.dispath.Dispatcher;
|
||||
import haxework.dispath.IDispatcher;
|
||||
import haxework.provider.Provider;
|
||||
import haxe.io.Bytes;
|
||||
import protohx.Message;
|
||||
import ru.m.connect.IConnection;
|
||||
|
||||
class BaseConnection implements IConnection {
|
||||
public var handler(default,default):IDispatcher<IConnectionHandler>;
|
||||
public var packetHandler(default,default):IDispatcher<IPacketHandler>;
|
||||
public var connected(default, null):Bool;
|
||||
public var queue(default, null):PacketQueue;
|
||||
public var builder(default, null):IPacketBuilder;
|
||||
|
||||
public function new() {
|
||||
this.builder = Provider.get(IPacketBuilder);
|
||||
this.queue = new PacketQueue(builder);
|
||||
this.handler = new Dispatcher<IConnectionHandler>();
|
||||
this.packetHandler = new Dispatcher<IPacketHandler>();
|
||||
}
|
||||
|
||||
public function connect():Void {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
public function disconnect():Void {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
public function pushData(bytes:Bytes):Void {
|
||||
queue.addBytes(bytes);
|
||||
while (queue.hasMsg()) {
|
||||
var packet:Message = queue.popMsg();
|
||||
try {
|
||||
receive(packet);
|
||||
} catch (error:Dynamic) {
|
||||
trace(error);
|
||||
handler.dispatch(function(h) h.onError(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
public function send(packet:Message):Void {
|
||||
#if proto_debug L.d("Send", Type.getClassName(Type.getClass(packet)).split(".").pop()); #end
|
||||
}
|
||||
|
||||
public function receive(packet:Message):Void {
|
||||
#if proto_debug L.d("Receive", Type.getClassName(Type.getClass(packet)).split(".").pop()); #end
|
||||
var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop();
|
||||
packetHandler.dispatch(function(h) {
|
||||
var method = Reflect.field(h, name);
|
||||
if (method != null && Reflect.isFunction(method)) {
|
||||
Reflect.callMethod(h, method, [packet]);
|
||||
} else {
|
||||
h.onPacket(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user