Пример #1
0
            public void Execute(DynamicComponentTypeHandle *ghostChunkComponentTypesPtr,
                                int ghostChunkComponentTypesLength)
            {
                for (int i = 0; i < GhostChunks.Length; i++)
                {
                    ArchetypeChunk chunk    = GhostChunks[i];
                    var            entities = chunk.GetNativeArray(EntityTypeHandle);
                    var            buffers  = chunk.GetBufferAccessor(SnapshotBufferTypeHandle);
                    var            datas    = chunk.GetNativeArray(SnapshotComponentTypeHandle);
                    var            ghosts   = chunk.GetNativeArray(GhostComponentTypeHandle);

                    for (int ent = 0; ent < entities.Length; ent++)
                    {
                        GhostComponent ghostComponent = ghosts[ent];
                        var            typeState      = GhostTypeCollection[ghostComponent.GhostType];

                        SnapshotData snapshotData = datas[ent];
                        DynamicBuffer <SnapshotDataBuffer> snapshotDataBuffer = buffers[ent];

                        if (snapshotData.SnapshotSize == 0)
                        {
                            continue;
                        }

                        bool isGet = snapshotData.GetDataAtTick(snapshotDataBuffer, InterpolatedTargetTick,
                                                                InterpolatedTargetTickFraction,
                                                                out var dataAtTick);

                        int baseOffset        = typeState.FirstComponent;
                        int numBaseComponents = typeState.NumComponents;

                        // 跳过Tick
                        int offset = GlobalConstants.TickSize;

                        for (int j = 0; j < numBaseComponents; j++)
                        {
                            int compIdx = ComponentIndex[baseOffset + j].ComponentIndex;
                            GhostComponentSerializer   serializer  = ComponentSerializers[compIdx];
                            DynamicComponentTypeHandle dynamicType =
                                ghostChunkComponentTypesPtr[compIdx];

                            if (chunk.Has(dynamicType))
                            {
                                IntPtr compPtr = (IntPtr)chunk
                                                 .GetDynamicComponentDataArrayReinterpret <byte>(dynamicType,
                                                                                                 serializer.ComponentSize).GetUnsafePtr();

                                if (isGet)
                                {
                                    serializer.CopyFromSnapshot.Ptr.Invoke(
                                        compPtr + serializer.ComponentSize * ent,
                                        (IntPtr)(&dataAtTick), offset);
                                }
                            }

                            offset += serializer.DataSize;
                        }
                    }
                }
            }
Пример #2
0
 public void Register(GhostComponentSerializer info)
 {
     _pendingGhostComponentSerializers.Add(info);
 }