protected override void OnCreateManager(int capacity) { networkFactory = new NetworkFactory(EntityManager); var types = reflectionUtility.ComponentTypes; var type = typeof(NetworkReceiveSystem); for (int i = 0; i < types.Length; i++) { var addMethod = GetMethod(types[i], type, "AddComponent"); var addInfo = new NetworkMethodInfo <NetworkReceiveSystem, Entity, List <ComponentField> >(addMethod); AddComponentsMethods.Add(types[i], addInfo); var removeMethod = GetMethod(types[i], type, "RemoveComponent"); var removeInfo = new NetworkMethodInfo <NetworkReceiveSystem, Entity>(removeMethod); RemoveComponentsMethods.Add(types[i], removeInfo); var setMethod = GetMethod(types[i], type, "SetComponent"); var setInfo = new NetworkMethodInfo <NetworkReceiveSystem, Entity, List <ComponentField> >(setMethod); SetComponentsMethods.Add(types[i], setInfo); var updateMethod = GetMethod(types[i], type, "UpdateComponent"); var updateInfo = new NetworkMethod <NetworkReceiveSystem>(updateMethod); UpdateComponentsMethods.Add(updateInfo); var destroyMethod = GetMethod(types[i], type, "RemoveComponentOnDestroyEntity"); var destroyInfo = new NetworkMethodInfo <NetworkReceiveSystem, Entity>(destroyMethod); RemoveComponentOnDestroyEntityMethods.Add(destroyInfo); } messageSerializer = new NetworkMessageSerializer <SyncEntities>(); }
private void ReceivingThread() { while (state == State.Running) { try { INetworkMessage message = NetworkMessageSerializer.Deserialize(networkStream); message.InitializeOnReceived(this); Debug.Log("Received " + message); messagesToProcess.Enqueue(message); message.PostEvent(); didReceiveSinceLastUpdate = true; } catch (ThreadAbortException) { return; } catch (Exception ex) { Debug.Log("Exception while deserializing a network message: " + ex); Close(); } } }
protected override void OnCreateManager(int capacity) { messageSerializer = new NetworkMessageSerializer <SyncEntities>(); ComponentType[] componentTypes = reflectionUtility.ComponentTypes; networkFactory = new NetworkFactory(EntityManager); Type networkSystemType = typeof(NetworkSendSystem); for (int i = 0; i < componentTypes.Length; i++) { AddedComponentsMethods.Add( new NetworkMethod <NetworkSendSystem>(networkSystemType .GetMethod("AddedComponents", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); RemovedComponentsMethods.Add( new NetworkMethod <NetworkSendSystem>(networkSystemType .GetMethod("RemovedComponents", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); UpdateComponentsMethods.Add( new NetworkMethod <NetworkSendSystem>(networkSystemType .GetMethod("UpdateDataState", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); AddComponentDataOnEntityAddedMethods.Add( new NetworkInOutMethodInfo <NetworkSendSystem, Entity, NetworkComponent>(networkSystemType .GetMethod("AddComponentDataOnEntityAdded", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); RemoveComponentOnDestroyEntityMethods.Add( new NetworkMethodInfo <NetworkSendSystem, Entity>(networkSystemType .GetMethod("RemoveComponentOnDestroyEntity", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); } }
public static void Main(string[] args) { var intermediateAssembly = args[0]; var referencedAssemblies = args[1].Split(';'); var networkMessageSerializer = new NetworkMessageSerializer(); networkMessageSerializer.ImplementNetworkMessageSerializer(intermediateAssembly, referencedAssemblies); }
public INetworkMessageSerializer GetRpcMessageSerializer() { ISerializeInfo[] _serializeInfo = new ISerializeInfo[1]; _serializeInfo[0] = new ProtoBufSerializeInfo <Apc>(Apc.Parser); INetworkMessageSerializer _defaultSerializer = new NetworkMessageSerializer(new AppMessageTypeInfo(_serializeInfo)); return(_defaultSerializer); }
public static void Main(string[] args) { var intermediateAssembly = args[0]; var referencedAssemblies = args[1].Split(';'); var networkMessageSerializer = new NetworkMessageSerializer(); networkMessageSerializer.ImplementNetworkMessageSerializer(intermediateAssembly, referencedAssemblies); }
public static MessageHandler Write(CancelableTcpClient client, MessageTransferLookUp lookUp) { var messageData = NetworkMessageSerializer.Get(lookUp); return((opCode, toSend) => { int length = messageData.serialize(opCode, toSend); client.Write(messageData.buffer, 0, length); return length; }); }
public static NetworkMessageStream Open(int port, string address, MonoBehaviour parent, MessageTransferLookUp lookUp) { var addr = IPAddress.Parse(address); var client = new CancelableTcpClient(new TcpClient(address, port)); var messageData = NetworkMessageSerializer.Get(lookUp); var recieve = ConnectionRead.Read(client, parent, lookUp); MessageHandler send = ConnectionWrite.Write(client, lookUp); return(new NetworkMessageStream(send, recieve)); }
void Process(NetworkingEntity e) { var queue = e.outgoingMessages.queue; if (queue.Count <= 0) { return; } var message = queue.Dequeue(); e.ReplaceOutgoingMessages(queue); byte[] bytes = NetworkMessageSerializer.Serialize(message); Send(bytes, e.connection.id); }
protected override void OnCreateManager(int capacity) { messageSerializer = new NetworkMessageSerializer <SyncEntities>(); ComponentType[] componentTypes = reflectionUtility.ComponentTypes; GetComponentGroup(typeof(NetworkSync)); Type networkSystemType = typeof(NetworkSyncFullStatedSystem); for (int i = 0; i < componentTypes.Length; i++) { var method = new NetworkInOutMethodInfo <NetworkSyncFullStatedSystem, Entity, NetworkComponent>(networkSystemType .GetMethod("GetComponentData", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType())); GetComponentDataMethods.Add(method); } }
protected override void OnCreateManager() { messageSerializer = new NetworkMessageSerializer <NetworkSyncDataContainer>(); ComponentType[] componentTypes = reflectionUtility.ComponentTypes.ToArray(); GetComponentGroup(typeof(NetworkSync)); Type networkSystemType = typeof(NetworkSyncFullStatedSystem); for (int i = 0; i < componentTypes.Length; i++) { GetComponentDataMethods.Add( new NetworkInOutMethodInfo <NetworkSyncFullStatedSystem, Entity, ComponentDataContainer>(networkSystemType .GetMethod("GetComponentData", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); } Enabled = networkManager != null; }
void OnReceive(int connectionId, int receivedMessageSize) { //Debug.LogFormat("Received {0} bytes from connectionId {1}", receivedMessageSize, connectionId); var e = networking.GetEntityWithConnection(connectionId); if (e == null) { return; } // TODO Pool these message arrays to avoid tons of allocations and GC. var bytes = new byte[receivedMessageSize]; Array.Copy(messageBuffer, bytes, receivedMessageSize); var message = NetworkMessageSerializer.Deserialize(bytes); EnqueueIncomingMessage(message, e); }
private void SendAllMessagesInQueue() { INetworkMessage message; while (messagesToSend.TryDequeue(out message)) { Assert.IsNotNull(message); Debug.Log("Sending " + message); try { NetworkMessageSerializer.Serialize(message, networkStream); didSendSinceLastUpdate = true; } catch (Exception ex) { Debug.Log("Exception while serializing a network message: " + ex); Close(); break; } } }
protected override void OnCreateManager() { networkFactory = new NetworkFactory(EntityManager); ComponentType[] componentTypes = reflectionUtility.ComponentTypes.ToArray(); Type networkSystemType = typeof(NetworkReceiveSystem); for (int i = 0; i < componentTypes.Length; i++) { AddComponentsMethods.Add(componentTypes[i], new NetworkMethodInfo <NetworkReceiveSystem, Entity, List <MemberDataContainer> >(networkSystemType .GetMethod("AddComponent", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); RemoveComponentsMethods.Add(componentTypes[i], new NetworkMethodInfo <NetworkReceiveSystem, Entity>(networkSystemType .GetMethod("RemoveComponent", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); SetComponentsMethods.Add(componentTypes[i], new NetworkMethodInfo <NetworkReceiveSystem, Entity, List <MemberDataContainer> >(networkSystemType .GetMethod("SetComponent", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); UpdateComponentsMethods.Add( new NetworkMethodInfo <NetworkReceiveSystem>(networkSystemType .GetMethod("UpdateComponent", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); RemoveComponentOnDestroyEntityMethods.Add( new NetworkMethodInfo <NetworkReceiveSystem, Entity>(networkSystemType .GetMethod("RemoveComponentOnDestroyEntity", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(componentTypes[i].GetManagedType()))); } messageSerializer = new NetworkMessageSerializer <NetworkSyncDataContainer>(); Enabled = networkManager != null; }
public INetworkMessageSerializer GetRpcMessageSerializer() { INetworkMessageSerializer _defaultSerializer = new NetworkMessageSerializer(new AppMessageTypeInfo(new ProtoBufSerializeInfo <Apc>(Apc.Parser))); return(_defaultSerializer); }