public SerializationFlags OnNetDeserialize(int originFrameId, int localFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { var frame = frames[localFrameId]; //frame.phase = floatCrusher.ReadValue(buffer, ref bitposition); frame.content = FrameContents.Complete; if (movement == Movement.Oscillate) { frame.cphase = (uint)floatCrusher.ReadCValue(buffer, ref bitposition); frame.phase = floatCrusher.Decode(frame.cphase); } return(SerializationFlags.HasChanged); }
public SerializationFlags OnNetDeserialize(int originFrameId, byte[] buffer, ref int bitposition, FrameArrival frameArrival) { var frame = frames[originFrameId]; // First read content, hold off on applying content to frame until we are sure we want to keep it. bool hascontent = buffer.Read(ref bitposition, 1) != 0; int ownerActorId = hascontent ? (int)buffer.ReadPackedBytes(ref bitposition, 32) : -1; // Ignore incoming updates if we are the current owner and the source is not the recognized controller. // Leaves frame as it was - since this might overwrite valid data. if (photonView.IsMine) // && hascontent && ownerActorId != && photonView.ControllerActorNr != netObj.originHistory[originFrameId]) { //Debug.LogError("fid:" + originFrameId + " DES IGNORE newown: " + frame.ownerActorId); return(SerializationFlags.None); } if (hascontent) { frame.content = FrameContents.Complete; frame.ownerActorId = ownerActorId; //Debug.LogError("fid:" + originFrameId + " DES newown: " + frame.ownerActorId + " cur:" + NetMaster.CurrentFrameId + " ctr:" + photonView.OwnerActorNr + ":" + photonView.ControllerActorNr) ; return(SerializationFlags.HasContent); } else { frame.content = FrameContents.Empty; return(SerializationFlags.None); } }
public virtual SerializationFlags OnNetDeserialize(int originFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { Frame frame = frames[originFrameId]; int sendEveryXTick = TickEngineSettings.sendEveryXTick; if (buffer.ReadBool(ref bitposition)) { frame.triggerMask = buffer.ReadUInt32(ref bitposition, sendEveryXTick); frame.content = FrameContents.Complete; return(SerializationFlags.HasContent); } else { frame.triggerMask = 0; frame.content = FrameContents.Empty; return(SerializationFlags.None); } }
public SerializationFlags OnNetDeserialize(int originFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { /// Needs to ignore any incoming updates that are the server/relay mirroring back what we sent var frame = (IsMine) ? offtickFrame : frames[originFrameId]; /// If frame is empty, we are done here. Typically means object was disabled. if (!buffer.ReadBool(ref bitposition)) { return(SerializationFlags.None); } bool isKeyframe = IsKeyframe(originFrameId); var flags = vitals.Deserialize(frame.vitalsData, buffer, ref bitposition, isKeyframe); frame.content = (flags & SerializationFlags.IsComplete) != 0 ? FrameContents.Complete : (flags & SerializationFlags.HasContent) != 0 ? FrameContents.Partial : FrameContents.Empty; //Debug.LogWarning(frame.frameId + " <b>DES " + frame.vitalsData.datas[0].Value + "</b> " + frame.vitalsData.datas[0].Value); return(flags); }
/// <summary> /// Notify tick manager of an incoming frame, so it can register/modify offsets for that connection. /// Returns FrameId translated into localFrameId. /// </summary> public static ConnectionTickOffsets LogIncomingFrame(int connId, int originFrameId, out FrameArrival arrival) { ConnectionTickOffsets offsets; int frameCount = TickEngineSettings.frameCount; //Debug.Log("conn: " + connId + " fid: " + originFrameId); if (!perConnOffsets.TryGetValue(connId, out offsets) || offsets == null) { LogNewConnection(connId, originFrameId, frameCount, out offsets); } int localFrameId = originFrameId + offsets.originToLocalFrame; if (localFrameId >= frameCount) { localFrameId -= frameCount; } offsets.frameArriveTime[originFrameId] = Time.time; int currTargFrameId = NetMaster.CurrentFrameId; // offsets.currTargFrameId; //bool frameIsInFuture; int frameOffsetFromCurrentTarg; if (localFrameId == currTargFrameId) { //frameIsInFuture = false; frameOffsetFromCurrentTarg = 0; } else { /// Flag frame as valid if it is still in the future frameOffsetFromCurrentTarg = currTargFrameId - localFrameId; if (frameOffsetFromCurrentTarg < 0) { frameOffsetFromCurrentTarg += frameCount; } if (frameOffsetFromCurrentTarg >= TickEngineSettings.halfFrameCount) { frameOffsetFromCurrentTarg -= frameCount; } //frameIsInFuture = frameOffsetFromCurrentTarg != 0 && frameOffsetFromCurrentTarg < TickEngineSettings.halfFrameCount; } #if UNITY_EDITOR const string STR_TAG = "\nSeeing many of these messages indicates a buffer underrun, due to an unstable connection, too small a buffer setting, or too high a tick rate."; #endif if (frameOffsetFromCurrentTarg >= 0) { if (frameOffsetFromCurrentTarg == 0) { #if UNITY_EDITOR if (TickEngineSettings.LogLevel == TickEngineSettings.LogInfoLevel.All) { string strframes = " Incoming Frame: <b>" + originFrameId + "</b> Current Interpolation: " + offsets.ConvertFrameLocalToOrigin(NetMaster.PreviousFrameId) + "->" + offsets.ConvertFrameLocalToOrigin(currTargFrameId); Debug.Log("<b>Late Update </b>conn: " + connId + " " + strframes + ". Already interpolating to this frame. Not critically late, but getting close." + STR_TAG); } #endif } else if (frameOffsetFromCurrentTarg == 1) { #if UNITY_EDITOR if (TickEngineSettings.LogLevel >= TickEngineSettings.LogInfoLevel.WarningsAndErrors) { string strframes = " Incoming Frame: <b>" + originFrameId + "</b> Current Interpolation: " + offsets.ConvertFrameLocalToOrigin(NetMaster.PreviousFrameId) + "->" + offsets.ConvertFrameLocalToOrigin(currTargFrameId); Debug.LogWarning("<b>Critically Late Update</b> conn: " + connId + " " + strframes + " Already applied and now interpolating from this frame. Snapshots will be rewound and reapplied." + STR_TAG); } #endif } else if (frameOffsetFromCurrentTarg >= TickEngineSettings.halfFrameCount) { #if UNITY_EDITOR string strframes = " Incoming Frame: <b>" + originFrameId + "</b> Current Interpolation: " + offsets.ConvertFrameLocalToOrigin(NetMaster.PreviousFrameId) + "->" + offsets.ConvertFrameLocalToOrigin(currTargFrameId); Debug.LogError("<b>Critically Late Update</b> conn: " + connId + " " + strframes + " DATA LOSS HAS OCCURRED EVEN FOR RELIABLE PACKETS. Increase Buffer size in " + typeof(TickEngineSettings).Name + "." + STR_TAG); #endif } else { #if UNITY_EDITOR if (TickEngineSettings.LogLevel >= TickEngineSettings.LogInfoLevel.WarningsAndErrors) { string strframes = " Incoming Frame: <b>" + originFrameId + "</b> Current Interpolation: " + offsets.ConvertFrameLocalToOrigin(NetMaster.PreviousFrameId) + "->" + offsets.ConvertFrameLocalToOrigin(currTargFrameId); Debug.LogWarning("<b>Critically Late Update</b> conn: " + connId + " " + strframes + " Already applied and now interpolating from this frame. Snapshots will be rewound and reapplied" + STR_TAG); } #endif } } else if (frameOffsetFromCurrentTarg <= (-(TickEngineSettings.halfFrameCount))) { #if UNITY_EDITOR string strframes = " Incoming Frame: <b>" + originFrameId + "</b> Current Interpolation: " + offsets.ConvertFrameLocalToOrigin(NetMaster.PreviousFrameId) + "->" + offsets.ConvertFrameLocalToOrigin(currTargFrameId); Debug.LogError("<b>Critically Late Update</b> conn: " + connId + " " + strframes + " DATA LOSS HAS OCCURRED EVEN FOR RELIABLE PACKETS. Increase Buffer size in " + typeof(TickEngineSettings).Name + "." + STR_TAG); #endif } arrival = (FrameArrival)frameOffsetFromCurrentTarg; //Debug.Log(Time.time + " ARRIVAL " + arrival + " fid:" + originFrameId + " half: " + TickEngineSettings.halfFrameCount); bool frameIsInFuture = frameOffsetFromCurrentTarg <= 0; offsets.frameArrivedTooLate |= !frameIsInFuture; offsets.validFrameMask.Set(originFrameId, true /*frameIsInFuture*/); return(offsets); }
public SerializationFlags OnNetDeserialize(int originFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { Frame frame = frames[originFrameId]; if (!buffer.ReadBool(ref bitposition)) { //if (GetComponent<SyncPickup>()) // Debug.LogError(originFrameId + " No Content"); return(SerializationFlags.None); } SerializationFlags flags = SerializationFlags.HasContent; /// Read State frame.state = (ObjState)buffer.Read(ref bitposition, 6); bool isAttached = (frame.state & ObjState.Mounted) != 0; if (!isAttached) { frame.content = FrameContents.Complete; } else if (IsKeyframe(originFrameId) || buffer.Read(ref bitposition, 1) == 1) { /// Read attached if ((frame.state & ObjState.Mounted) != 0) { frame.mountToViewID = (int?)buffer.ReadPackedBytes(ref bitposition, 32); if (bitsForMountType > 0) { int mountidx = (int)buffer.Read(ref bitposition, bitsForMountType); int mountTypeId = indexToMountTypeId[mountidx]; frame.mountTypeId = (int?)mountTypeId; } else { frame.mountTypeId = 0; } } frame.content = FrameContents.Complete; } /// State is attached, but because this is a delta frame the parent info is missing else { frame.mountToViewID = null; frame.mountTypeId = null; frame.content = FrameContents.Partial; } //if (GetComponent<SyncPickup>()) // Debug.Log(Time.time + " " + flags + " " + name + " <b> fr: " + frame.frameId + " <color=purple>DES STATE</color></b> " + frame.content + " " + frame.state + // ((frame.state & ObjState.Visible) != 0 ? " VISIBLE " : " ") + // ((frame.state & ObjState.Mounted) != 0 ? " MOUNTED " + frame.mountToViewID : " ") // ); return(flags); }
public SerializationFlags OnNetDeserialize(int originFrameId, int localFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { //if (arrival != FrameArrival.IsFuture && snapFrame != null) // Debug.Log("arrival lcl: " + localFrameId + " sn:" + snapFrame.frameId + " " + arrival); #if PUN_2_OR_NEWER /// Needs to ignore any incoming updates that are the server/relay mirroring back what we sent var frame = (pv.IsMine) ? offtickFrame : frames[localFrameId]; #else Frame frame = null; #endif /// If enabled flag is false, we are done here. if (!buffer.ReadBool(ref bitposition)) { frame.content = FrameContents.Empty; return(SerializationFlags.None); } frame.content = FrameContents.Complete; bool _hasTeleported = buffer.ReadBool(ref bitposition); frame.hasTeleported = _hasTeleported; if (_hasTeleported) { //Debug.Log(localFrameId + " RCV TELE : trgf: " + (targFrame != null ? targFrame.frameId.ToString() : "null")); transformCrusher.Read(frame.telecm, buffer, ref bitposition); transformCrusher.Decompress(frame.telem, frame.telecm); } transformCrusher.Read(frame.cm, buffer, ref bitposition); transformCrusher.Decompress(frame.m, frame.cm); //if (GetComponent<SyncPickup>()) // Debug.Log(Time.time + " " + name + " <b>" + localFrameId + " DES TRANS</b> " + frame.m.position + " -> " + frame.telem.position + (_hasTeleported ? " <b>tele</b>" : "")); return /*frame.hasTeleported ? SerializationFlags.ForceReliable :*/ (SerializationFlags.HasChanged); }
public SerializationFlags OnNetDeserialize(int originFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { Frame frame = frames[originFrameId]; // Get first content bool to see if we have any contacts at all. bool hasContent = buffer.ReadBool(ref bitposition); if (hasContent) { /// if pickup event bool do { var tes = frame.contactRecords; var te = new ContactRecord( (int)buffer.ReadPackedBytes(ref bitposition, 32), (byte)buffer.ReadPackedBits(ref bitposition, 8), (ContactType)(1 << (int)buffer.Read(ref bitposition, 2)) ); //Debug.LogError(name + " DES: " + te); tes.Add(te); } // Loop for all contact records. while (buffer.ReadBool(ref bitposition)); frame.content = FrameContents.Complete; return(SerializationFlags.HasContent /*| SerializationFlags.ForceReliable*/); } // No contact records frame.content = FrameContents.Empty; return(SerializationFlags.None); }
public SerializationFlags OnNetDeserialize(int originFrameId, int localFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { WeaponFrame frame = frames[localFrameId]; SerializationFlags flags = SerializationFlags.None; if (buffer.ReadBool(ref bitposition)) { frame.triggerMask = buffer.ReadUInt32(ref bitposition, sendEveryXTick); flags |= SerializationFlags.HasChanged /*| SerializationFlags.ForceReliable*/; } else { frame.triggerMask = 0; } frame.hitmask = (uint)buffer.Read(ref bitposition, sendEveryXTick); for (int i = 0; i < sendEveryXTick; ++i) { if ((frame.hitmask & (1 << i)) != 0) { flags |= frame.netHits[i].Deserialize(buffer, ref bitposition, NetObj.bitsForColliderIndex); } } frame.content = flags == SerializationFlags.None ? FrameContents.Empty : FrameContents.Complete; return(flags); }
public SerializationFlags OnNetDeserialize(int originFrameId, int localFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { Frame frame = frames[localFrameId]; SerializationFlags flags = SerializationFlags.HasChanged; /// if pickup event bool if (buffer.ReadBool(ref bitposition)) { int netObjId = (int)buffer.ReadPackedBytes(ref bitposition, MasterNetAdapter.BITS_FOR_NETID); frame.triggeredById = netObjId; flags = SerializationFlags.HasChanged /*| SerializationFlags.ForceReliable*/; } else { frame.triggeredById = null; } frame.content = FrameContents.Complete; return(flags); }
public void OnDeserialize(int sourceFrameId, int originFrameId, int localframeId, byte[] buffer, ref int bitposition, bool hasData) { #if SNS_WARNINGS bufferAddTime[localframeId] = Time.time; #endif SerializationFlags flags = SerializationFlags.None; if (hasData) { #if SNS_WARNINGS /// Integrity check if (buffer.Read(ref bitposition, 8) != 111) { Debug.LogError("Failed Integrity check pre PackObjs."); } #endif FrameArrival arrival = NetMaster.CheckFrameArrival(localframeId); /// Deserialize Pack Objects //int prevFrameId = ((localframeId == 0) ? SimpleSyncSettings.FrameCount : localframeId) - 1; int pcnt = packObjRecords.Count; for (int i = 0; i < pcnt; ++i) { var p = packObjRecords[i]; var pframe = p.packFrames[localframeId]; int mcnt = p.info.fieldCount; for (int m = 0; m < mcnt; ++m) { pframe.mask[m] = buffer.ReadBool(ref bitposition); } int maskOffset = 0; Debug.Log("PRE"); var flag = p.info.UnpackFrameFromBuffer(pframe, ref pframe.mask, ref pframe.isCompleteMask, ref maskOffset, buffer, ref bitposition, originFrameId, SerializationFlags.None); flags |= flag; //Debug.Log(localframeId + " Des READY? flg: " + flag + " " + p.readyMask.AllAreTrue + " " + p.readyMask.PrintMask(null) + " " // + p.readyMask.Seg1 + ":" + p.readyMask.AllTrue1 + " " + p.readyMask.Seg2 + ":" + p.readyMask.AllTrue2); /// Experimental - Apply valid values as they arrive if pack object isn't fully ready. Ensure even a late arriving full update counts toward Ready if (!p.readyMask.AllAreTrue /*&& (flag & SerializationFlags.IsComplete) != 0*/) { /// Add any always ready bits (Triggers) p.readyMask.OR(p.info.defaultReadyMask); p.readyMask.OR(pframe.isCompleteMask); /// Only write to syncvars that are not already marked as valid FastBitMask128 newchangesmask = !p.readyMask & pframe.isCompleteMask; maskOffset = 0; p.info.CopyFrameToObj(pframe, p.component, ref newchangesmask, ref maskOffset); Debug.Log(localframeId + "<b> Des PRE COMPLETE? </b>" + p.readyMask.AllAreTrue + " " + p.readyMask.PrintMask(null) + " " + p.readyMask.Seg1 + ":" + p.readyMask.AllTrue1 + " " + p.readyMask.Seg2 + ":" + p.readyMask.AllTrue2); } } packObjValidMask[localframeId] = true; #if SNS_WARNINGS /// Integrity check if (buffer.Read(ref bitposition, 8) != 123) { Debug.LogError(name + " Failed Integrity check post PackObjs. " + localframeId); } #endif /// Deserialize SyncObjs int cnt = onNetDeserializeCallbacks.Count; for (int i = 0; i < cnt; ++i) { var flag = onNetDeserializeCallbacks[i].OnNetDeserialize(originFrameId, localframeId, buffer, ref bitposition, arrival); flags |= flag; /// Experimental - immediately apply complete frames to unready sync objects. //if (arrival == FrameArrival.IsLate && (flag & SerializationFlags.IsComplete) != 0 && !syncObjReadyMask[i]) // Debug.Log("Call an early Apply here when a method exists for that."); } #if SNS_WARNINGS /// Integrity check if (buffer.Read(ref bitposition, 8) != 234) { Debug.LogError(name + " Failed Integrity check post SyncObjs. " + localframeId); } #endif } }
public SerializationFlags OnNetDeserialize(int originFrameId, int localFrameId, byte[] buffer, ref int bitposition, FrameArrival arrival) { Frame frame = frames[localFrameId]; SerializationFlags flags = SerializationFlags.HasChanged; /// Read State frame.state = (ObjState)buffer.Read(ref bitposition, 5); bool isAttached = (frame.state & ObjState.Attached) != 0; if (!isAttached) { frame.content = FrameContents.Complete; } else if (IsKeyframe(originFrameId) || buffer.Read(ref bitposition, 1) == 1) { ///// Read isRespawn bool //frame.respawn = buffer.Read(ref bitposition, 1) == 0 ? false : true; /// Read attached if ((frame.state & ObjState.Attached) != 0) { frame.attachedToNetId = (int?)buffer.ReadPackedBytes(ref bitposition, 32); if (bitsForMountType > 0) { int mountidx = (int)buffer.Read(ref bitposition, bitsForMountType); int mountTypeId = indexToMountTypeId[mountidx]; frame.attachedToMountTypeId = (int?)mountTypeId; } else { frame.attachedToMountTypeId = 0; } } frame.content = FrameContents.Complete; } /// State is attached, but because this is a delta frame the parent info is missing else { frame.attachedToNetId = null; frame.attachedToMountTypeId = null; frame.content = FrameContents.Partial; } //if (GetComponent<SyncPickup>()) // Debug.Log(Time.time + " " + name + " <b>[" + frame.frameId + "] DES State </b> " + frame.state + " " + // (frame.isCompleteFrame ? (frame.attachedToNetId + ":" + frame.attachedToMountTypeId) : " empty")); return(flags); }
public SerializationFlags OnNetDeserialize(int originFrameId, byte[] buffer, ref int bitposition, FrameArrival frameArrival) { Frame frame = frames[originFrameId]; SerializationFlags flags = SerializationFlags.None; bool iskeyframe = IsKeyframe(originFrameId); if (!iskeyframe) { frame.content = FrameContents.Empty; return(flags); } if (respawnEnable) { /// Read ticksToRespawn if (buffer.ReadBool(ref bitposition)) { frame.ticksUntilRespawn = (int)buffer.Read(ref bitposition, bitsForTicksUntilRespawn); flags |= SerializationFlags.HasContent; } else { frame.ticksUntilRespawn = -1; } } if (despawnEnable) { if (buffer.ReadBool(ref bitposition)) { frame.ticksUntilDespawn = (int)buffer.Read(ref bitposition, bitsForTicksUntilDespawn); flags |= SerializationFlags.HasContent; } else { frame.ticksUntilDespawn = -1; } } frame.content = FrameContents.Complete; return(flags); }