예제 #1
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            GhostDeserializerState deserializerState = new GhostDeserializerState
            {
                GhostMap = GhostMap
            };
            NativeArray <Entity> ghostEntityArray = chunk.GetNativeArray(ghostEntityType);
            BufferAccessor <NetCodePlayModeTestGhostObjectSnapshotData> ghostSnapshotDataArray =
                chunk.GetBufferAccessor(ghostSnapshotDataType);
            NativeArray <Rotation>    ghostRotationArray    = chunk.GetNativeArray(ghostRotationType);
            NativeArray <Translation> ghostTranslationArray = chunk.GetNativeArray(ghostTranslationType);

#if UNITY_EDITOR || DEVELOPMENT_BUILD
            int minMaxOffset = ThreadIndex * (JobsUtility.CacheLineSize / 4);
#endif
            for (int entityIndex = 0; entityIndex < ghostEntityArray.Length; ++entityIndex)
            {
                DynamicBuffer <NetCodePlayModeTestGhostObjectSnapshotData>
                snapshot = ghostSnapshotDataArray[entityIndex];
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                uint latestTick = snapshot.GetLatestTick();
                if (latestTick != 0)
                {
                    if (minMaxSnapshotTick[minMaxOffset] == 0 ||
                        SequenceHelpers.IsNewer(minMaxSnapshotTick[minMaxOffset], latestTick))
                    {
                        minMaxSnapshotTick[minMaxOffset] = latestTick;
                    }

                    if (minMaxSnapshotTick[minMaxOffset + 1] == 0 ||
                        SequenceHelpers.IsNewer(latestTick, minMaxSnapshotTick[minMaxOffset + 1]))
                    {
                        minMaxSnapshotTick[minMaxOffset + 1] = latestTick;
                    }
                }
#endif
                NetCodePlayModeTestGhostObjectSnapshotData snapshotData;
                snapshot.GetDataAtTick(targetTick, targetTickFraction, out snapshotData);

                Rotation    ghostRotation    = ghostRotationArray[entityIndex];
                Translation ghostTranslation = ghostTranslationArray[entityIndex];
                ghostRotation.Value                = snapshotData.GetRotationValue(deserializerState);
                ghostTranslation.Value             = snapshotData.GetTranslationValue(deserializerState);
                ghostRotationArray[entityIndex]    = ghostRotation;
                ghostTranslationArray[entityIndex] = ghostTranslation;
            }
        }
예제 #2
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            GhostDeserializerState deserializerState = new GhostDeserializerState
            {
                GhostMap = GhostMap
            };
            NativeArray <Entity> ghostEntityArray = chunk.GetNativeArray(ghostEntityType);
            BufferAccessor <NetCodePlayModeTestGhostObjectSnapshotData> ghostSnapshotDataArray =
                chunk.GetBufferAccessor(ghostSnapshotDataType);
            NativeArray <PredictedGhostComponent> predictedGhostComponentArray =
                chunk.GetNativeArray(predictedGhostComponentType);
            NativeArray <Rotation>    ghostRotationArray    = chunk.GetNativeArray(ghostRotationType);
            NativeArray <Translation> ghostTranslationArray = chunk.GetNativeArray(ghostTranslationType);

#if UNITY_EDITOR || DEVELOPMENT_BUILD
            int minMaxOffset = ThreadIndex * (JobsUtility.CacheLineSize / 4);
#endif
            for (int entityIndex = 0; entityIndex < ghostEntityArray.Length; ++entityIndex)
            {
                DynamicBuffer <NetCodePlayModeTestGhostObjectSnapshotData>
                snapshot = ghostSnapshotDataArray[entityIndex];
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                uint latestTick = snapshot.GetLatestTick();
                if (latestTick != 0)
                {
                    if (minMaxSnapshotTick[minMaxOffset] == 0 ||
                        SequenceHelpers.IsNewer(minMaxSnapshotTick[minMaxOffset], latestTick))
                    {
                        minMaxSnapshotTick[minMaxOffset] = latestTick;
                    }

                    if (minMaxSnapshotTick[minMaxOffset + 1] == 0 ||
                        SequenceHelpers.IsNewer(latestTick, minMaxSnapshotTick[minMaxOffset + 1]))
                    {
                        minMaxSnapshotTick[minMaxOffset + 1] = latestTick;
                    }
                }
#endif
                NetCodePlayModeTestGhostObjectSnapshotData snapshotData;
                snapshot.GetDataAtTick(targetTick, out snapshotData);

                PredictedGhostComponent predictedData = predictedGhostComponentArray[entityIndex];
                uint lastPredictedTickInst            = lastPredictedTick;
                if (lastPredictedTickInst == 0 || predictedData.AppliedTick != snapshotData.Tick)
                {
                    lastPredictedTickInst = snapshotData.Tick;
                }
                else if (!SequenceHelpers.IsNewer(lastPredictedTickInst, snapshotData.Tick))
                {
                    lastPredictedTickInst = snapshotData.Tick;
                }

                if (minPredictedTick[ThreadIndex] == 0 ||
                    SequenceHelpers.IsNewer(minPredictedTick[ThreadIndex], lastPredictedTickInst))
                {
                    minPredictedTick[ThreadIndex] = lastPredictedTickInst;
                }

                predictedGhostComponentArray[entityIndex] = new PredictedGhostComponent
                {
                    AppliedTick = snapshotData.Tick, PredictionStartTick = lastPredictedTickInst
                };
                if (lastPredictedTickInst != snapshotData.Tick)
                {
                    continue;
                }

                Rotation    ghostRotation    = ghostRotationArray[entityIndex];
                Translation ghostTranslation = ghostTranslationArray[entityIndex];
                ghostRotation.Value                = snapshotData.GetRotationValue(deserializerState);
                ghostTranslation.Value             = snapshotData.GetTranslationValue(deserializerState);
                ghostRotationArray[entityIndex]    = ghostRotation;
                ghostTranslationArray[entityIndex] = ghostTranslation;
            }
        }