internal void AddCreateCommand(EntityCommandBufferChain *chain, ECBCommand op, EntityArchetype archetype)
        {
            if (chain->m_PrevCreateCommand != null &&
                chain->m_PrevCreateCommand->Archetype == archetype &&
                chain->m_PrevCreateCommand->BatchCount < kMaxBatchCount)
            {
                ++chain->m_PrevCreateCommand->BatchCount;

                var data = (CreateCommand *)Reserve(chain, sizeof(CreateCommand));

                data->Header.CommandType = (int)op;
                data->Header.TotalSize   = sizeof(CreateCommand);
                data->Archetype          = archetype;
                data->BatchCount         = 0;
            }
            else
            {
                var data = (CreateCommand *)Reserve(chain, sizeof(CreateCommand));

                data->Header.CommandType = (int)op;
                data->Header.TotalSize   = sizeof(CreateCommand);
                data->Archetype          = archetype;
                data->BatchCount         = 1;

                chain->m_PrevCreateCommand = data;
            }
        }
示例#2
0
        internal byte *Reserve(EntityCommandBufferChain *chain, int size)
        {
            if (chain->m_Tail == null || chain->m_Tail->Capacity < size)
            {
                var chunkSize = math.max(m_MinimumChunkSize, size);

                var c    = (ECBChunk *)UnsafeUtility.Malloc(sizeof(ECBChunk) + chunkSize, 16, m_Allocator);
                var prev = chain->m_Tail;
                c->Next = null;
                c->Prev = prev;
                c->Used = 0;
                c->Size = chunkSize;

                if (prev != null)
                {
                    prev->Next = c;
                }

                if (chain->m_Head == null)
                {
                    chain->m_Head = c;
                }

                chain->m_Tail = c;
            }

            var offset = chain->m_Tail->Bump(size);
            var ptr    = (byte *)chain->m_Tail + sizeof(ECBChunk) + offset;

            return(ptr);
        }
示例#3
0
        internal void AddEntitySharedComponentCommand <T>(EntityCommandBufferChain *chain, ECBCommand op, Entity e, int hashCode, object boxedObject)
            where T : struct
        {
            var typeIndex  = TypeManager.GetTypeIndex <T>();
            var sizeNeeded = Align(sizeof(EntitySharedComponentCommand), 8);

            var data = (EntitySharedComponentCommand *)Reserve(chain, sizeNeeded);

            data->Header.Header.CommandType = (int)op;
            data->Header.Header.TotalSize   = sizeNeeded;
            data->Header.Entity             = e;
            data->ComponentTypeIndex        = typeIndex;
            data->HashCode = hashCode;

            if (boxedObject != null)
            {
                data->BoxedObject = GCHandle.Alloc(boxedObject);
                // We need to store all GCHandles on a cleanup list so we can dispose them later, regardless of if playback occurs or not.
                data->Prev           = chain->m_CleanupList;
                chain->m_CleanupList = data;
            }
            else
            {
                data->BoxedObject = new GCHandle();
            }
        }
示例#4
0
        internal unsafe void AddEntityCommand(EntityCommandBufferChain *chain, int jobIndex, ECBCommand op, Entity e)
        {
            int num1;

            if ((chain.m_PrevEntityCommand == null) || !(chain.m_PrevEntityCommand.Entity == e))
            {
                num1 = 0;
            }
            else
            {
                num1 = (int)(chain.m_PrevEntityCommand.BatchCount < 0x200);
            }
            if (num1 == 0)
            {
                EntityCommand *commandPtr2 = (EntityCommand *)ref this.Reserve(chain, jobIndex, sizeof(EntityCommand));
                commandPtr2->Header.CommandType = (int)op;
                commandPtr2->Header.TotalSize   = sizeof(EntityCommand);
                commandPtr2->Header.SortIndex   = chain.m_LastSortIndex;
                commandPtr2->Entity             = e;
                commandPtr2->BatchCount         = 1;
                chain.m_PrevEntityCommand       = commandPtr2;
            }
            else
            {
                int *numPtr1 = (int *)ref chain.m_PrevEntityCommand.BatchCount;
                numPtr1[0]++;
                EntityCommand *commandPtr = (EntityCommand *)ref this.Reserve(chain, jobIndex, sizeof(EntityCommand));
                commandPtr->Header.CommandType = (int)op;
                commandPtr->Header.TotalSize   = sizeof(EntityCommand);
                commandPtr->Header.SortIndex   = chain.m_LastSortIndex;
                commandPtr->Entity             = e;
                commandPtr->BatchCount         = 0;
            }
        }
        internal void AddEntityCommand(EntityCommandBufferChain *chain, ECBCommand op, Entity e)
        {
            if (chain->m_PrevEntityCommand != null &&
                chain->m_PrevEntityCommand->Entity == e &&
                chain->m_PrevEntityCommand->BatchCount < kMaxBatchCount)
            {
                ++chain->m_PrevEntityCommand->BatchCount;

                var data = (EntityCommand *)Reserve(chain, sizeof(EntityCommand));

                data->Header.CommandType = (int)op;
                data->Header.TotalSize   = sizeof(EntityCommand);
                data->Entity             = e;
                data->BatchCount         = 0;
            }
            else
            {
                var data = (EntityCommand *)Reserve(chain, sizeof(EntityCommand));

                data->Header.CommandType = (int)op;
                data->Header.TotalSize   = sizeof(EntityCommand);
                data->Entity             = e;
                data->BatchCount         = 1;

                chain->m_PrevEntityCommand = data;
            }
        }
示例#6
0
        internal void AddCreateCommand(EntityCommandBufferChain *chain, ECBCommand op, EntityArchetype archetype)
        {
            var data = (CreateCommand *)Reserve(chain, sizeof(CreateCommand));

            data->Header.CommandType = (int)op;
            data->Header.TotalSize   = sizeof(CreateCommand);
            data->Archetype          = archetype;
        }
示例#7
0
 internal unsafe void DestroyConcurrentAccess()
 {
     if (this.m_ThreadedChains != null)
     {
         UnsafeUtility.Free((void *)this.m_ThreadedChains, this.m_Allocator);
         this.m_ThreadedChains = null;
     }
 }
示例#8
0
        internal void AddEntityCommand(EntityCommandBufferChain *chain, ECBCommand op, Entity e)
        {
            var data = (EntityCommand *)Reserve(chain, sizeof(EntityCommand));

            data->Header.CommandType = (int)op;
            data->Header.TotalSize   = sizeof(EntityCommand);
            data->Entity             = e;
        }
示例#9
0
 internal void DestroyConcurrentAccess()
 {
     if (m_ThreadedChains != null)
     {
         UnsafeUtility.Free(m_ThreadedChains, m_Allocator);
         m_ThreadedChains = null;
     }
 }
示例#10
0
 internal unsafe void InitConcurrentAccess()
 {
     if (this.m_ThreadedChains == null)
     {
         int num = sizeof(EntityCommandBufferChain) * 0x80;
         this.m_ThreadedChains = (EntityCommandBufferChain *)UnsafeUtility.Malloc((long)num, 0x40, this.m_Allocator);
         UnsafeUtility.MemClear((void *)this.m_ThreadedChains, (long)num);
     }
 }
示例#11
0
        internal unsafe void AddEntityComponentTypeCommand(EntityCommandBufferChain *chain, int jobIndex, ECBCommand op, Entity e, ComponentType t)
        {
            int size = Align(sizeof(EntityComponentCommand), 8);
            EntityComponentCommand *commandPtr = (EntityComponentCommand *)ref this.Reserve(chain, jobIndex, size);

            commandPtr->Header.Header.CommandType = (int)op;
            commandPtr->Header.Header.TotalSize   = size;
            commandPtr->Header.Header.SortIndex   = chain.m_LastSortIndex;
            commandPtr->Header.Entity             = e;
            commandPtr->ComponentTypeIndex        = t.TypeIndex;
        }
示例#12
0
        internal void AddEntityComponentTypeCommand(EntityCommandBufferChain *chain, ECBCommand op, Entity e, ComponentType t)
        {
            var sizeNeeded = Align(sizeof(EntityComponentCommand), 8);

            var data = (EntityComponentCommand *)Reserve(chain, sizeNeeded);

            data->Header.Header.CommandType = (int)op;
            data->Header.Header.TotalSize   = sizeNeeded;
            data->Header.Entity             = e;
            data->ComponentTypeIndex        = t.TypeIndex;
        }
        public DynamicBuffer <T> CreateBufferCommand <T>(ECBCommand commandType, EntityCommandBufferChain *chain, Entity e) where T : struct, IBufferElementData
        {
            BufferHeader *header = AddEntityBufferCommand <T>(chain, commandType, e);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            var safety = m_BufferSafety;
            AtomicSafetyHandle.UseSecondaryVersion(ref safety);
            return(new DynamicBuffer <T>(header, safety));
#else
            return(new DynamicBuffer <T>(header));
#endif
        }
示例#14
0
        internal void InitConcurrentAccess()
        {
            if (m_ThreadedChains != null)
            {
                return;
            }

            // PERF: It's be great if we had a way to actually get the number of worst-case threads so we didn't have to allocate 128.
            int allocSize = sizeof(EntityCommandBufferChain) * JobsUtility.MaxJobThreadCount;

            m_ThreadedChains = (EntityCommandBufferChain *)UnsafeUtility.Malloc(allocSize, 8, m_Allocator);
            UnsafeUtility.MemClear(m_ThreadedChains, allocSize);
        }
示例#15
0
        internal unsafe void AddEntityComponentCommand <T>(EntityCommandBufferChain *chain, int jobIndex, ECBCommand op, Entity e, T component) where T : struct
        {
            int num2 = UnsafeUtility.SizeOf <T>();
            int size = Align(sizeof(EntityComponentCommand) + num2, 8);
            EntityComponentCommand *commandPtr = (EntityComponentCommand *)this.Reserve(chain, jobIndex, size);

            commandPtr->Header.Header.CommandType = (int)op;
            commandPtr->Header.Header.TotalSize   = size;
            commandPtr->Header.Header.SortIndex   = chain.m_LastSortIndex;
            commandPtr->Header.Entity             = e;
            commandPtr->ComponentTypeIndex        = TypeManager.GetTypeIndex <T>();
            commandPtr->ComponentSize             = num2;
            UnsafeUtility.CopyStructureToPtr <T>(ref component, (void *)(commandPtr + 1));
        }
示例#16
0
        internal unsafe BufferHeader *AddEntityBufferCommand <T>(EntityCommandBufferChain *chain, int jobIndex, ECBCommand op, Entity e) where T : struct, IBufferElementData
        {
            TypeManager.TypeInfo typeInfo = TypeManager.GetTypeInfo <T>();
            int size = Align(sizeof(EntityBufferCommand) + typeInfo.SizeInChunk, 8);
            EntityBufferCommand *commandPtr = (EntityBufferCommand *)ref this.Reserve(chain, jobIndex, size);

            commandPtr->Header.Header.CommandType = (int)op;
            commandPtr->Header.Header.TotalSize   = size;
            commandPtr->Header.Header.SortIndex   = chain.m_LastSortIndex;
            commandPtr->Header.Entity             = e;
            commandPtr->ComponentTypeIndex        = TypeManager.GetTypeIndex <T>();
            commandPtr->ComponentSize             = typeInfo.SizeInChunk;
            BufferHeader.Initialize(&commandPtr->TempBuffer, typeInfo.BufferCapacity);
            return(&commandPtr->TempBuffer);
        }
示例#17
0
        internal void AddEntityComponentCommand <T>(EntityCommandBufferChain *chain, ECBCommand op, Entity e, T component) where T : struct
        {
            var typeSize   = UnsafeUtility.SizeOf <T>();
            var typeIndex  = TypeManager.GetTypeIndex <T>();
            var sizeNeeded = Align(sizeof(EntityComponentCommand) + typeSize, 8);

            var data = (EntityComponentCommand *)Reserve(chain, sizeNeeded);

            data->Header.Header.CommandType = (int)op;
            data->Header.Header.TotalSize   = sizeNeeded;
            data->Header.Entity             = e;
            data->ComponentTypeIndex        = typeIndex;
            data->ComponentSize             = typeSize;

            UnsafeUtility.CopyStructureToPtr(ref component, (byte *)(data + 1));
        }
        internal BufferHeader *AddEntityBufferCommand <T>(EntityCommandBufferChain *chain, ECBCommand op, Entity e) where T : struct, IBufferElementData
        {
            var typeIndex  = TypeManager.GetTypeIndex <T>();
            var type       = TypeManager.GetTypeInfo <T>();
            var sizeNeeded = Align(sizeof(EntityBufferCommand) + type.SizeInChunk, 8);

            var data = (EntityBufferCommand *)Reserve(chain, sizeNeeded);

            data->Header.Header.CommandType = (int)op;
            data->Header.Header.TotalSize   = sizeNeeded;
            data->Header.Entity             = e;
            data->ComponentTypeIndex        = typeIndex;
            data->ComponentSize             = type.SizeInChunk;

            BufferHeader.Initialize(&data->TempBuffer, type.BufferCapacity);
            return(&data->TempBuffer);
        }
示例#19
0
        internal unsafe void AddEntitySharedComponentCommand <T>(EntityCommandBufferChain *chain, int jobIndex, ECBCommand op, Entity e, int hashCode, object boxedObject) where T : struct
        {
            int size = Align(sizeof(EntitySharedComponentCommand), 8);
            EntitySharedComponentCommand *commandPtr = (EntitySharedComponentCommand *)ref this.Reserve(chain, jobIndex, size);

            commandPtr->Header.Header.CommandType = (int)op;
            commandPtr->Header.Header.TotalSize   = size;
            commandPtr->Header.Header.SortIndex   = chain.m_LastSortIndex;
            commandPtr->Header.Entity             = e;
            commandPtr->ComponentTypeIndex        = TypeManager.GetTypeIndex <T>();
            commandPtr->HashCode = hashCode;
            if (boxedObject == null)
            {
                commandPtr->BoxedObject = new GCHandle();
            }
            else
            {
                commandPtr->BoxedObject = GCHandle.Alloc(boxedObject);
                commandPtr->Prev        = chain.m_CleanupList;
                chain.m_CleanupList     = commandPtr;
            }
        }
示例#20
0
        internal unsafe byte *Reserve(EntityCommandBufferChain *chain, int jobIndex, int size)
        {
            int num = jobIndex;

            if (num < chain.m_LastSortIndex)
            {
                EntityCommandBufferChain *chainPtr = (EntityCommandBufferChain *)ref UnsafeUtility.Malloc((long)sizeof(EntityCommandBufferChain), 8, this.m_Allocator);
                chainPtr[0] = chain[0];
                UnsafeUtility.MemClear((void *)chain, (long)sizeof(EntityCommandBufferChain));
                chain.m_NextChain = chainPtr;
            }
            chain.m_LastSortIndex = num;
            if ((chain.m_Tail == null) || (chain.m_Tail.Capacity < size))
            {
                int       num3     = math.max(this.m_MinimumChunkSize, size);
                ECBChunk *chunkPtr = (ECBChunk *)ref UnsafeUtility.Malloc((long)(sizeof(ECBChunk) + num3), 0x10, this.m_Allocator);
                ECBChunk *tail     = chain.m_Tail;
                chunkPtr->Next = null;
                chunkPtr->Prev = tail;
                chunkPtr->Used = 0;
                chunkPtr->Size = num3;
                if (tail != null)
                {
                    tail->Next = chunkPtr;
                }
                if (chain.m_Head == null)
                {
                    chain.m_Head = chunkPtr;
                    Interlocked.Increment(ref this.m_RecordedChainCount);
                }
                chain.m_Tail = chunkPtr;
            }
            int num2 = chain.m_Tail.Bump(size);

            return((byte *)((chain.m_Tail + 1) + num2));
        }
示例#21
0
        public unsafe DynamicBuffer <T> CreateBufferCommand <T>(ECBCommand commandType, EntityCommandBufferChain *chain, int jobIndex, Entity e, AtomicSafetyHandle bufferSafety, AtomicSafetyHandle arrayInvalidationSafety) where T : struct, IBufferElementData
        {
            AtomicSafetyHandle handle = bufferSafety;

            AtomicSafetyHandle.UseSecondaryVersion(ref handle);
            return(new DynamicBuffer <T>(this.AddEntityBufferCommand <T>(chain, jobIndex, commandType, e), handle, arrayInvalidationSafety, false));
        }