Exemplo n.º 1
0
                public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
                {
                    bool didChunkChange =
                        chunk.DidChange(LocalToWorldType, m_LastSystemVersion) ||
                        chunk.DidChange(PositionType, m_LastSystemVersion) ||
                        chunk.DidChange(RotationType, m_LastSystemVersion) ||
                        chunk.DidChange(PhysicsColliderType, m_LastSystemVersion) ||
                        chunk.DidOrderChange(m_LastSystemVersion);

                    ChunkHasChangesOutput[chunkIndex] = didChunkChange ? 1 : 0;
                }
Exemplo n.º 2
0
                public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
                {
                    bool didBatchChange =
                        batchInChunk.DidChange(LocalToWorldType, m_LastSystemVersion) ||
                        batchInChunk.DidChange(PositionType, m_LastSystemVersion) ||
                        batchInChunk.DidChange(RotationType, m_LastSystemVersion) ||
                        batchInChunk.DidChange(PhysicsColliderType, m_LastSystemVersion) ||
                        batchInChunk.DidOrderChange(m_LastSystemVersion);

                    if (didBatchChange)
                    {
                        // Note that multiple worker threads may be running at the same time.
                        // They either write 1 to Result[0] or not write at all.  In case multiple
                        // threads are writing 1 to this variable, in C#, reads or writes of int
                        // data type are atomic, which guarantees that Result[0] is 1.
                        Result[0] = 1;
                    }
                }
Exemplo n.º 3
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset)
            {
                bool changed =
                    chunk.DidOrderChange(LastSystemVersion) ||
                    chunk.DidChange(TranslationTypeHandle, LastSystemVersion) ||
                    chunk.DidChange(NonUniformScaleTypeHandle, LastSystemVersion) ||
                    chunk.DidChange(ScaleTypeHandle, LastSystemVersion) ||
                    chunk.DidChange(CompositeScaleTypeHandle, LastSystemVersion) ||
                    chunk.DidChange(RotationTypeHandle, LastSystemVersion) ||
                    chunk.DidChange(CompositeRotationTypeHandle, LastSystemVersion);

                if (!changed)
                {
                    return;
                }

                var chunkTranslations       = chunk.GetNativeArray(TranslationTypeHandle);
                var chunkNonUniformScales   = chunk.GetNativeArray(NonUniformScaleTypeHandle);
                var chunkScales             = chunk.GetNativeArray(ScaleTypeHandle);
                var chunkCompositeScales    = chunk.GetNativeArray(CompositeScaleTypeHandle);
                var chunkRotations          = chunk.GetNativeArray(RotationTypeHandle);
                var chunkCompositeRotations = chunk.GetNativeArray(CompositeRotationTypeHandle);
                var chunkLocalToWorld       = chunk.GetNativeArray(LocalToWorldTypeHandle);
                var hasTranslation          = chunk.Has(TranslationTypeHandle);
                var hasCompositeRotation    = chunk.Has(CompositeRotationTypeHandle);
                var hasRotation             = chunk.Has(RotationTypeHandle);
                var hasAnyRotation          = hasCompositeRotation || hasRotation;
                var hasNonUniformScale      = chunk.Has(NonUniformScaleTypeHandle);
                var hasScale          = chunk.Has(ScaleTypeHandle);
                var hasCompositeScale = chunk.Has(CompositeScaleTypeHandle);
                var hasAnyScale       = hasScale || hasNonUniformScale || hasCompositeScale;
                var count             = chunk.Count;

                // #todo jump table when burst supports function pointers

                if (!hasAnyRotation)
                {
                    // 00 = invalid (must have at least one)
                    // 01
                    if (!hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = scale
                            };
                        }
                    }
                    // 10
                    else if (hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = float4x4.Translate(translation)
                            };
                        }
                    }
                    // 11
                    else if (hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var scale       = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(float4x4.Translate(translation), scale)
                            };
                        }
                    }
                }
                else if (hasCompositeRotation)
                {
                    // 00
                    if (!hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkCompositeRotations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = rotation
                            };
                        }
                    }
                    // 01
                    else if (!hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkCompositeRotations[i].Value;
                            var scale    = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(rotation, scale)
                            };
                        }
                    }
                    // 10
                    else if (hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkCompositeRotations[i].Value;
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(float4x4.Translate(translation), rotation)
                            };
                        }
                    }
                    // 11
                    else if (hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkCompositeRotations[i].Value;
                            var translation = chunkTranslations[i].Value;
                            var scale       = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(math.mul(float4x4.Translate(translation), rotation), scale)
                            };
                        }
                    }
                }
                else // if (hasRotation) -- Only in same WriteGroup if !hasCompositeRotation
                {
                    // 00
                    if (!hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkRotations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = new float4x4(rotation, float3.zero)
                            };
                        }
                    }
                    // 01
                    else if (!hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation = chunkRotations[i].Value;
                            var scale    = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(new float4x4(rotation, float3.zero), scale)
                            };
                        }
                    }
                    // 10
                    else if (hasTranslation && !hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkRotations[i].Value;
                            var translation = chunkTranslations[i].Value;

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = new float4x4(rotation, translation)
                            };
                        }
                    }
                    // 11
                    else if (hasTranslation && hasAnyScale)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var rotation    = chunkRotations[i].Value;
                            var translation = chunkTranslations[i].Value;
                            var scale       = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value);

                            chunkLocalToWorld[i] = new LocalToWorld
                            {
                                Value = math.mul(new float4x4(rotation, translation), scale)
                            };
                        }
                    }
                }
            }