public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            // For all chunks where currentTrans is newer than previousTrans
            // Copy currentTrans to previous trans
            if (ChangeVersionUtility.DidChange(chunk.GetComponentVersion(curRotationType), simStartComponentVersion))
            {
                var curRot  = chunk.GetNativeArray(curRotationType);
                var prevRot = chunk.GetNativeArray(prevRotationType);
                // FIXME: use a memcopy since size and layout must be identical
                for (int ent = 0; ent < curRot.Length; ++ent)
                {
                    prevRot[ent] = new PreviousSimulatedRotation {
                        Value = curRot[ent].Value
                    };
                }
            }

            // For all chunks where transform has changed since end of last simulation
            // Copy currentTargs to trans
            if (ChangeVersionUtility.DidChange(chunk.GetComponentVersion(rotationType), simEndComponentVersion))
            {
                // Transform was interpolated by the rendering system
                var curRot = chunk.GetNativeArray(curRotationType);
                var rot    = chunk.GetNativeArray(rotationType);
                // FIXME: use a memcopy since size and layout must be identical
                for (int ent = 0; ent < curRot.Length; ++ent)
                {
                    rot[ent] = new Rotation {
                        Value = curRot[ent].Value
                    };
                }
            }
        }
 public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
 {
     // If current was written after copying it to prev we need to interpolate, otherwise they must be identical
     if (ChangeVersionUtility.DidChange(chunk.GetComponentVersion(curRotationType),
                                        chunk.GetComponentVersion(prevRotationType)))
     {
         var prevRot = chunk.GetNativeArray(prevRotationType);
         var curRot  = chunk.GetNativeArray(curRotationType);
         var rot     = chunk.GetNativeArray(rotationType);
         for (var ent = 0; ent < rot.Length; ++ent)
         {
             var a = math.slerp(prevRot[ent].Value, curRot[ent].Value, curWeight);
             rot[ent] = new Rotation {
                 Value = a
             };
         }
     }
 }
 public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
 {
     // If current was written after copying it to prev we need to interpolate, otherwise they must be identical
     if (ChangeVersionUtility.DidChange(chunk.GetComponentVersion(curPositionType),
                                        chunk.GetComponentVersion(prevPositionType)))
     {
         var prevPos = chunk.GetNativeArray(prevPositionType);
         var curPos  = chunk.GetNativeArray(curPositionType);
         var pos     = chunk.GetNativeArray(positionType);
         for (var ent = 0; ent < pos.Length; ++ent)
         {
             var p = curPos[ent].Value * curWeight + prevPos[ent].Value * prevWeight;
             pos[ent] = new Translation {
                 Value = p
             };
         }
     }
 }
 public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
 {
     // For all chunks where trans has changed since start of simulation
     // Copy trans to currentTrans
     if (ChangeVersionUtility.DidChange(chunk.GetComponentVersion(rotationType), simStartComponentVersion))
     {
         // Transform was interpolated by the rendering system
         var curRot = chunk.GetNativeArray(curRotationType);
         var rot    = chunk.GetNativeArray(rotationType);
         // FIXME: use a memcopy since size and layout must be identical
         for (int ent = 0; ent < curRot.Length; ++ent)
         {
             curRot[ent] = new CurrentSimulatedRotation {
                 Value = rot[ent].Value
             };
         }
     }
 }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset)
        {
            var arrayPtr       = chunk.GetNativeArray(ComponentType).GetUnsafeReadOnlyPtr();
            var ptr            = (byte *)DataPtr;
            var versionPointer = (uint *)DataPtr;

            var version = chunk.GetComponentVersion(ComponentType);

            // TODO: Might be a problem with multithreading
            *versionPointer += version;

            for (var i = 0; i < chunk.Count; i++)
            {
                var copySizeInBytes = UnsafeUtility.SizeOf <T>();
                var destinationPtr  = ptr + (StepSize * (i + entityOffset)) + SlotOffset + ReactComponentQuerySystem.HeaderDataOffset;
                var srcPtr          = (byte *)arrayPtr + copySizeInBytes * i;

                UnsafeUtility.MemCpy(destinationPtr, srcPtr, copySizeInBytes);
            }
        }
Example #6
0
    public static void RecordEntityTrace(EntityManager entityManager, EntityManagerTrace trace)
    {
        int chunkI = 0;

        trace.GlobalSystemVersion = entityManager.GlobalSystemVersion;

        using (NativeArray <ArchetypeChunk> chunks = entityManager.GetAllChunks(Allocator.TempJob)) // needs to be temp job to preven unity error :(
        {
            for (int i = 0; i < chunks.Length; i++)
            {
                ArchetypeChunk chunk = chunks[i];

                while (chunkI >= trace.Chunks.Count)
                {
                    trace.Chunks.Add(s_chunkTracePool.Count > 0 ? s_chunkTracePool.Dequeue() : new ChunkTrace());
                }

                ChunkTrace chunkTrace = trace.Chunks[chunkI++];

                chunkTrace.OrderVersion = chunk.GetOrderVersion();
                chunkTrace.EntityCount  = chunk.ChunkEntityCount;
                chunkTrace.ComponentTraces.Clear();

                foreach (ComponentType componentType in chunk.Archetype.GetComponentTypes(Allocator.Temp))
                {
                    chunkTrace.ComponentTraces.Add(new ComponentTrace()
                    {
                        ComponentType = componentType,
                        Version       = chunk.GetComponentVersion(componentType)
                    });
                }
            }
        }

        int toRemove = trace.Chunks.Count - chunkI;

        for (int i = 0; i < toRemove; i++)
        {
            s_chunkTracePool.Enqueue(trace.Chunks.Pop());
        }
    }