void Start() { test = GameObject.Find("LockstepManager").GetComponent <LockStepManager>(); List <byte> data = SerializationCtrl.Serialize(new byte[10000]); testArr = data.ToArray(); }
/// <summary> /// Sends the object array to all devices. /// </summary> /// <param name="rawData">a non-null object array</param> public void SendToAll(params object[] rawData) { PrintDebug(DebugLevel.DATA_ONLY, "SendToAll rawData={0}", rawData); if (rawData == null) { ReactToError("SendToAll called with a array rawData == null"); } RawNetworkData data = new RawNetworkData(); data.rawArr = rawData; if (IsNetworkEnabled()) { List <byte> byteList = SerializationCtrl.Serialize(data); ReactToSerializationError(); byte[] byteArr = byteList.ToArray(); H2LogPlayer.localPlayer.CmdServerReceiveRawData(byteArr); } else { data.OnReceive(this); } }
/// <summary> /// Add default classes used by the networking system to the SerializationCtrl. /// Query NetworkEvents from the EventManager and register them at the SerializationCtrl. /// </summary> public void Start() { // Data types used by the networking system SerializationCtrl.RegisterSerializer( typeof(List <NetworkData>), new SerializationCtrl.ListSerializer()); SerializationCtrl.RegisterSerializer( typeof(RawNetworkData), new SerializationCtrl.ClassSerializer()); SerializationCtrl.RegisterSerializer( typeof(RpcNetworkData), new SerializationCtrl.ClassSerializer()); SerializationCtrl.RegisterSerializer( typeof(RpcMsg), new SerializationCtrl.ClassSerializer()); SerializationCtrl.RegisterSerializer( typeof(EventNetworkData), new SerializationCtrl.ClassSerializer()); SerializationCtrl.RegisterSerializer( typeof(LockStepMessage), new SerializationCtrl.ClassSerializer()); SerializationCtrl.RegisterSerializer( typeof(Vector3), new Vector3Serializer()); CustomEventSystem.EventManager evtMngr = CustomEventSystem.EventManager.Instance; List <System.Type> nwEvtTypes = evtMngr.GetRegisteredNetworkEventTypes(); PrintDebug(DebugLevel.VERBOSE, "Start.NetworkEventCount {0}", nwEvtTypes.Count); foreach (var eventType in nwEvtTypes) { PrintDebug(DebugLevel.VERBOSE, "Start.AddNetworkEventType {0}", eventType); SerializationCtrl.RegisterSerializer( eventType, new SerializationCtrl.ClassSerializer()); } }
/// <summary> /// This method should be called after every time the SerializationCtrl is used to perform /// serialization or deserialization. This method will usethe ReactToError method to react /// to any errors during the serialization process. /// </summary> private void ReactToSerializationError() { foreach (var err in SerializationCtrl.GetCurrentErrors()) { ReactToError(err.GetFormatString(), err.GetFormatArgs()); } SerializationCtrl.ClearCurrentErrors(); }
public override void ReadBytes(DeserializationData data, object obj) { IList list = (IList)obj; int count = data.ReadInt4B(); for (int i = 0; i < count; i++) { object val = SerializationCtrl.Deserialize(data); list.Add(val); } }
/// <summary> /// Called by the H2LogPlayer when a Client has sent a LockStepMessage over the network. /// This method is supposed to buffer the data from the client for the next LockStep. /// </summary> /// <param name="byteArr">bytes from the network</param> public void ServerReceiveMessage(byte[] byteArr) { PrintDebug(DebugLevel.DEBUG, "ServerReceiveMessage (byte[])"); List <object> list = SerializationCtrl.Deserialize(byteArr); ReactToSerializationError(); LockStepMessage msg = (LockStepMessage)list[0]; ServerReceiveMessage(msg); }
/// <summary> /// Called by the H2LogPlayer after byte data was received from the server. /// This method is called on all devices, even the server. /// </summary> /// <param name="byteArr">bytes from the network</param> public void ClientProcessLockStep(byte[] byteArr) { PrintDebug(DebugLevel.DEBUG, "ClientProcessLockStep (byte[])"); List <object> list = SerializationCtrl.Deserialize(byteArr); ReactToSerializationError(); LockStepMessage msg = (LockStepMessage)list[0]; ClientProcessLockStep(msg); }
public override void ReadBytes(DeserializationData data, object obj) { Array arr = (Array)obj; long[] indices = { 0 }; for (int i = 0; i < arr.Length; i++) { indices[0] = i; object val = SerializationCtrl.Deserialize(data); arr.SetValue(val, indices); } }
public override void ReadBytes(DeserializationData data, object obj) { FieldInfo[] props = obj.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (var info in props) { object val = SerializationCtrl.Deserialize(data); info.SetValue(obj, val); } }
public override void WriteBytes(SerializationData data, object obj) { IList list = (IList)obj; int count = list.Count; data.WriteInt4B(count); for (int i = 0; i < count; i++) { object val = list[i]; SerializationCtrl.Serialize(data, val); } }
public override void WriteBytes(SerializationData data, object obj) { Array arr = (Array)obj; Type elementType = arr.GetType().GetElementType(); int elementTypeID = SerializationCtrl.GetSerializeID(elementType); int arrLength = arr.GetLength(0); data.WriteInt4B(elementTypeID); data.WriteInt4B(arrLength); long[] indices = { 0 }; for (int i = 0; i < arrLength; i++) { indices[0] = i; object val = arr.GetValue(indices); SerializationCtrl.Serialize(data, val); } }
/// <summary> /// If this device is the host then all currently buffered messages within the /// ServerSideBuffer will be sent out to all devices (including this one!). /// /// If this device is a client then all currently buffered messages within the /// ClientSideBuffer will be sent out to the host device (server). /// /// If networking is disabled this device will simply execute all local messages /// buffered in the ClientSideBuffer. /// </summary> private void SendLockStep() { PrintDebug(DebugLevel.DEBUG, "SendLockStep.IsHost={0}", IsHost()); if (IsHost()) { ServerSideBuffer.AddRange(ClientSideBuffer); LockStepMessage msg = BuildLockStepMessage(ServerSideBuffer); if (IsNetworkEnabled()) { List <byte> byteList = SerializationCtrl.Serialize(msg); ReactToSerializationError(); byte[] byteArr = byteList.ToArray(); foreach (var player in H2LogPlayer.instances) { player.RpcClientReceiveLockStep(byteArr); } } else { ClientProcessLockStep(msg); } ServerSideBuffer.Clear(); } else { LockStepMessage msg = BuildLockStepMessage(ClientSideBuffer); if (IsNetworkEnabled()) { List <byte> byteList = SerializationCtrl.Serialize(msg); ReactToSerializationError(); byte[] byteArr = byteList.ToArray(); H2LogPlayer.localPlayer.CmdServerReceiveLockStep(byteArr); } else { ServerReceiveMessage(msg); } } ClientSideBuffer.Clear(); }
public void ClientReceiveRawData(byte[] byteArr) { RawNetworkData data = (RawNetworkData)SerializationCtrl.Deserialize(byteArr, 0); data.OnReceive(this); }