/// <summary> /// Check if passed Component has a PackObject attribute, if so add it to the callback list for this NetObj /// </summary> private void AddPackObjects(Component comp) { if (comp == null) { return; } /// Add PackObjRecord System.Type compType = comp.GetType(); if (comp.GetType().GetCustomAttributes(typeof(PackObjectAttribute), false).Length != 0) { var packObjInfo = Compression.Internal.PackObjectDatabase.GetPackObjectInfo(compType); if (packObjInfo == null) { return; } var newrecord = new PackObjRecord() { component = comp, onReadyCallback = comp as IPackObjOnReadyChange, info = packObjInfo, packFrames = packObjInfo.FactoryFramesObj(comp, SimpleSyncSettings.FrameCount), prevReadyMask = new FastBitMask128(packObjInfo.fieldCount), readyMask = new FastBitMask128(packObjInfo.fieldCount) }; packObjRecords.Add(newrecord); // set any readyMask bits that are triggers to true - they are always ready. packObjIndexLookup.Add(comp, indexedPackObjs.Count); indexedPackObjs.Add(comp); } }
public bool OnSnapshot(int frameId) { #if !PUN_2_OR_NEWER return(false); #else if (!pv) { return(false); } if (pv.IsMine) { return(false); } if (!pv.enabled) { return(false); } /// TODO: Cache this properly ConnectionTick offsets; if (!TickManager.perConnOffsets.TryGetValue(pv.ControllerActorNr, out offsets)) { return(false); } if (!offsets.hadInitialSnapshot) { return(false); } if (offsets.advanceCount == 0) { return(false); } int snapFid = NetMaster.PreviousFrameId; int targFid; //Debug.Log(GetType().Name + " OnSnap - passed - advance count: " + offsets.advanceCount); int frameCount = SimpleSyncSettings.FrameCount; for (int a = 0; a < offsets.advanceCount; ++a) { targFid = frameId + a; if (targFid >= frameCount) { targFid -= frameCount; } int invalidateFId = targFid - SimpleSyncSettings.HalfFrameCount; if (invalidateFId < 0) { invalidateFId += frameCount; } /// Snap Pack Objects bool packSnapIsValid = packObjValidMask[snapFid]; //if (packSnapIsValid/* || packTargIsValid*/) { bool packTargIsValid = packObjValidMask[targFid]; int pcnt = packObjRecords.Count; for (int i = 0; i < pcnt; ++i) { PackObjRecord p = packObjRecords[i]; var snapf = p.packFrames[snapFid]; var targpf = p.packFrames[targFid]; /// update readymask with any new valid fields p.readyMask.OR(p.info.defaultReadyMask); p.readyMask.OR(snapf.isCompleteMask); Debug.Log(snapFid + " - " + p.readyMask.PrintMask(null) + " : " + p.info.defaultReadyMask.PrintMask(null) + " : " + snapf.isCompleteMask.PrintMask(null)); /// TODO: when extrapolation is implemented, it will replace this basic copy if (!packTargIsValid) { p.info.CopyFrameToFrame(snapf, targpf); } /// Snapshot callbacks - fire every net tick changed or not int maskOffset = 0; p.info.SnapObject(snapf, targpf, p.component, ref p.readyMask, ref maskOffset); /// Apply new Snap value / Callback only fires on changes if (packSnapIsValid) { maskOffset = 0; p.info.CopyFrameToObj(snapf, p.component, ref snapf.mask, ref maskOffset); } /// Ready Mask has Changed - Issue callback if (p.readyMask.Compare(p.prevReadyMask) == false) { Debug.Log("Ready change " + p.readyMask.AllAreTrue); OnPackObjReadyChange(p.component, p.readyMask.AllAreTrue ? ReadyStateEnum.Ready : ReadyStateEnum.Unready); IPackObjOnReadyChange onReadyCallback = p.onReadyCallback; if (!ReferenceEquals(onReadyCallback, null)) { onReadyCallback.OnPackObjReadyChange(p.readyMask, p.readyMask.AllAreTrue); } p.prevReadyMask.Copy(p.readyMask); } } } /// TODO: Needs a better home packObjValidMask[invalidateFId] = false; //Debug.Log(GetType().Name + " OnSnap - callback count " + onSnapshot.Count); /// Snap SyncObjs int cnt = onSnapshotCallbacks.Count; for (int i = 0; i < cnt; ++i) { onSnapshotCallbacks[i].OnSnapshot(targFid); } snapFid = targFid; #if SNS_WARNINGS //Debug.Log(currTargFrameId + " New Target Time on Buffer " + (bufferAddTime[currTargFrameId].HasValue ? (Time.time - bufferAddTime[currTargFrameId]).ToString() : "NULL")); bufferAddTime[targFid] = null; #endif } return(true); #endif }