Example #1
0
        public void OnSpawn()
        {
            this.innerArray = PoolArray <T> .Spawn(this.Capacity);

            this.Capacity = 0;
            this.Count    = 0;
        }
Example #2
0
 /// <summary>
 /// Use this method to add an array of vertex indices (IBO)
 /// </summary>
 /// <param name="data">Array of vertex indices. Must be of type either byte[], short[] or int[]</param>
 public void AddArray(object data)
 {
     if (!m_Compiled && m_VboId != 0)
     {
         m_IboArray = new BufferArray(data);
     }
 }
Example #3
0
        public void RunTasks(Unity.Collections.NativeArray <PathTask> tasks, ref BufferArray <Path> results)
        {
            ArrayUtils.Resize(tasks.Length, ref Pathfinding.results);

            Pathfinding.pathfinding = this;

            var job = new RunTasksJob()
            {
                arr = tasks,
            };
            var jobHandle = job.Schedule(tasks.Length, 64);

            jobHandle.Complete();

            results = Pathfinding.results;

            /*
             * for (int i = 0; i < tasks.Count; ++i) {
             *
             *  var task = tasks[i];
             *  task.result = this.CalculatePath(task.@from, task.to, task.constraint, task.pathCornersModifier);
             *  tasks[i] = task;
             *
             * }*/
        }
Example #4
0
        public ListCopyable(int startCapacity)
        {
            this.Capacity   = startCapacity;
            this.innerArray = PoolArray <T> .Spawn(this.Capacity);

            this.Initialize();
        }
Example #5
0
 public static void Clear <T>(BufferArray <T> arr)
 {
     if (arr.arr != null)
     {
         System.Array.Clear(arr.arr, 0, arr.Length);
     }
 }
Example #6
0
 public void Recycle(ref BufferArray <T> value)
 {
     if (value != null)
     {
         PoolArray <T> .Recycle(ref value);
     }
 }
Example #7
0
        public void OnSpawn()
        {
            this.innerArray = PoolArray <T> .Spawn(this.Capacity);

            this.Capacity = 0;
            this.Initialize();
        }
Example #8
0
        public static void Recycle(BufferArray <T> buffer)
        {
            //buffer = new BufferArray<T>(null, 0);
            //return;

            T[] arr = buffer.arr;
            PoolArray <T> .Release(ref arr);
        }
Example #9
0
        public NativeDataBufferArray(BufferArray <T> data)
        {
            var mode = Unity.Collections.NativeLeakDetection.Mode;

            Unity.Collections.NativeLeakDetection.Mode = Unity.Collections.NativeLeakDetectionMode.Disabled;
            this.dataObject = new DataObject <NativeBufferArray <T>, NativeDataBufferArrayProvider <T> >(new NativeBufferArray <T>(data));
            Unity.Collections.NativeLeakDetection.Mode = mode;
            this.Length = data.Length;
        }
Example #10
0
 public SystemGroup(World world, string name)
 {
     this.name          = name;
     this.world         = world;
     this.worldIndex    = -1;
     this.systems       = new BufferArray <ISystemBase>();
     this.statesSystems = new BufferArray <ModuleState>();
     this.length        = 0;
     this.worldIndex    = world.AddSystemGroup(ref this);
 }
Example #11
0
        public void AddRange(BufferArray <T> items)
        {
            var arrayLength = items.Count;

            this.EnsureCapacity(this.Count + arrayLength + 1);
            for (var i = 0; i < arrayLength; i++)
            {
                this.innerArray.arr[this.Count++] = items.arr[i];
            }
        }
Example #12
0
        public static BufferArray <T> Spawn(int length)
        {
            //return new BufferArray<T>(new T[length], length);

            //UnityEngine.Debug.Log("Spawn request: " + length);
            var buffer = new BufferArray <T>(PoolArray <T> .Claim(length), length);

            System.Array.Clear(buffer.arr, 0, length);

            return(buffer);
        }
Example #13
0
        public static void Recycle(ref BufferArray <T> buffer)
        {
            T[] arr = buffer.arr;
            if (arr != null)
            {
                System.Array.Clear(arr, 0, arr.Length);
            }
            PoolArray <T> .Release(ref arr);

            buffer = new BufferArray <T>(null, 0);
        }
Example #14
0
        public static BufferArray <T> Spawn(int length, bool realSize = false)
        {
            var arr = PoolArray <T> .Claim(length);

            var size   = (realSize == true ? arr.Length : length);
            var buffer = new BufferArray <T>(arr, length, realSize == true ? arr.Length : -1);

            System.Array.Clear(buffer.arr, 0, size);

            return(buffer);
        }
Example #15
0
        public void AddRange(BufferArray <T> items)
        {
            var arrayLength = items.Count;

            this.EnsureCapacity(this.Count + arrayLength + 1);
            System.Array.Copy(items.arr, 0, this.innerArray.arr, this.Count, arrayLength);
            this.Count += arrayLength;

            /*for (var i = 0; i < arrayLength; i++) {
             *  this.innerArray.arr[this.Count++] = items.arr[i];
             * }*/
        }
Example #16
0
        public static void Recycle(BufferArray <T> buffer)
        {
            if (Pools.isActive == false)
            {
                buffer = default;
                return;
            }

            T[] arr = buffer.arr;
            //if (arr != null) System.Array.Clear(arr, 0, arr.Length);
            PoolArray <T> .Release(ref arr);
        }
Example #17
0
        void IModuleBase.OnConstruct()
        {
            this.isRequestsDirty = false;
            this.list            = PoolArray <Views> .Spawn(ViewsModule.VIEWS_CAPACITY);

            this.rendering = PoolHashSet <ViewInfo> .Spawn(ViewsModule.VIEWS_CAPACITY);

            this.registryPrefabToId = PoolDictionary <IView, ViewId> .Spawn(ViewsModule.REGISTRY_CAPACITY);

            this.registryIdToPrefab = PoolDictionary <ViewId, IView> .Spawn(ViewsModule.REGISTRY_CAPACITY);

            this.registryPrefabToProvider = PoolDictionary <ViewId, IViewsProvider> .Spawn(ViewsModule.REGISTRY_PROVIDERS_CAPACITY);

            this.registryPrefabToProviderInitializer = PoolDictionary <ViewId, IViewsProviderInitializerBase> .Spawn(ViewsModule.REGISTRY_PROVIDERS_CAPACITY);
        }
Example #18
0
        public void RunTasks <TMod, TProcessor>(Unity.Collections.NativeArray <PathTask> tasks, ref BufferArray <Path> results) where TMod : struct, IPathModifier where TProcessor : struct, IPathfindingProcessor
        {
            ArrayUtils.Resize(tasks.Length, ref Pathfinding.results);

            Pathfinding.pathfinding = this;

            var job = new RunTasksJob <TMod, TProcessor>()
            {
                arr = tasks,
            };

            for (int i = 0; i < tasks.Length; ++i)
            {
                var item = tasks[i];
                if (item.burstEnabled == true)
                {
                    job.Execute(i);
                    item.isValid = false;
                    tasks[i]     = item;
                }
            }

            var jobHandle = job.Schedule(tasks.Length, 64);

            jobHandle.Complete();

            for (int i = 0; i < tasks.Length; ++i)
            {
                var item = tasks[i];
                if (item.burstEnabled == true)
                {
                    item.isValid = true;
                    tasks[i]     = item;
                }
            }

            results = Pathfinding.results;

            /*
             * for (int i = 0; i < tasks.Count; ++i) {
             *
             *  var task = tasks[i];
             *  task.result = this.CalculatePath(task.@from, task.to, task.constraint, task.pathCornersModifier);
             *  tasks[i] = task;
             *
             * }*/
        }
Example #19
0
 protected void Dispose(bool manual)
 {
     if (manual)
     {
         if (m_VboId != 0)
         {
             Unbind();
             if (m_VboId != -1)
             {
                 GL.DeleteBuffer(ref m_VboId);
             }
             if (m_IboId != -1)
             {
                 GL.DeleteBuffer(ref m_IboId);
             }
             m_VboId    = 0;
             m_IboId    = 0;
             m_Arrays   = null;
             m_IboArray = null;
         }
     }
 }
Example #20
0
        /// <summary>
        /// Remove system manually
        /// Pool will not be used, OnDeconstruct() call
        /// </summary>
        /// <param name="instance"></param>
        public void RemoveSystem(ISystemBase instance)
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            var idx = this.systems.IndexOf(instance);

            if (idx >= 0)
            {
                if (instance is ISystemFilter systemFilter)
                {
                    systemFilter.filter = null;
                }

                instance.world     = null;
                this.systems       = this.systems.RemoveAt(idx);
                this.statesSystems = this.statesSystems.RemoveAt(idx);
                instance.OnDeconstruct();

                this.world.UpdateGroup(this);
            }
        }
Example #21
0
        public void Clone(BufferArray <T> from, ref BufferArray <T> to)
        {
            to = PoolArray <T> .Spawn(from.Length);

            ArrayUtils.Copy(in from, ref to);
        }
Example #22
0
 public DataBufferArray(BufferArray <T> data)
 {
     this.dataObject = new DataObject <BufferArray <T>, DataBufferArrayProvider <T> >(data);
     this.Length     = data.Length;
 }
Example #23
0
 public void Set(BufferArray <T> value)
 {
     this.dataObject.Set(value);
 }
Example #24
0
        static private BufferArray <Common.BufferElements.EntityBuffer> _ReleaseCompositesFromPatternGroup(EntityCommandBuffer commandBuffer, BufferArray <Common.BufferElements.EntityBuffer> a_compositeEntities, int i_prefabIndex)
        {
            // get number of composites in this patter group
            int i_compositesCount = a_compositeEntities [i_prefabIndex].Length;

            // iterate through owned composites, to detach them
            for (int i = 0; i < i_compositesCount; i++)
            {
                Common.BufferElements.EntityBuffer compositeEntityBuffer = a_compositeEntities [i_prefabIndex][i];

                // Set as not assigned
                // And reset position
                _ReleaseCompositesFromPatternRequest(commandBuffer, compositeEntityBuffer);
            }

            // fiinally clear store of detached compoenents
            a_compositeEntities [i_prefabIndex].Clear();

            return(a_compositeEntities);
        }
        public override void Update(BufferArray <Views> list, float deltaTime, bool hasChanged)
        {
            if (this.world.settings.useJobsForViews == false || this.world.settings.viewsSettings.unityGameObjectProviderDisableJobs == true)
            {
                return;
            }

            if (list.isEmpty == false)
            {
                if (hasChanged == true)
                {
                    if (this.tempList == null)
                    {
                        this.tempList = PoolList <MonoBehaviourView> .Spawn(list.Length);
                    }

                    var changed = false; //ArrayUtils.Resize(list.Length - 1, ref this.currentTransforms);

                    var k = 0;
                    for (int i = 0, length = list.Length; i < length; ++i)
                    {
                        var item = list.arr[i];
                        if (item.isNotEmpty == false)
                        {
                            continue;
                        }

                        for (int j = 0, count = item.Length; j < count; ++j)
                        {
                            var view = item[j] as MonoBehaviourView;
                            if (view == null)
                            {
                                continue;
                            }
                            if (view.applyStateJob == true)
                            {
                                changed |= ArrayUtils.Resize(k, ref this.currentTransforms);
                                var isNew = false;
                                if (k >= this.tempList.Count)
                                {
                                    this.tempList.Add(view);
                                    this.currentTransforms.arr[k] = view.transform;
                                    isNew = true;
                                }

                                var tempItem = this.tempList[k];
                                if (isNew == true ||
                                    tempItem.prefabSourceId != view.prefabSourceId ||
                                    tempItem.creationTick != view.creationTick ||
                                    tempItem.entity != view.entity)
                                {
                                    this.tempList[k] = view;
                                    this.currentTransforms.arr[k] = view.transform;
                                    changed = true;
                                }

                                ++k;
                            }
                        }
                    }

                    if (this.currentTransformArray.isCreated == false)
                    {
                        this.currentTransformArray = new TransformAccessArray(k);
                    }

                    if (changed == true)
                    {
                        this.currentTransformArray.SetTransforms(this.currentTransforms.arr);
                        //if (UnityGameObjectProvider.resultList != null) PoolList<MonoBehaviourView>.Recycle(ref UnityGameObjectProvider.resultList);
                        //var result = PoolList<MonoBehaviourView>.Spawn(this.tempList.Count);
                        //result.AddRange(this.tempList);
                        UnityGameObjectProvider.resultList  = this.tempList;
                        UnityGameObjectProvider.resultCount = k;
                    }
                }

                if (UnityGameObjectProvider.resultCount > 0 && this.currentTransformArray.isCreated == true)
                {
                    var job = new Job()
                    {
                        deltaTime = deltaTime,
                        length    = UnityGameObjectProvider.resultCount
                    };

                    var handle = job.Schedule(this.currentTransformArray);
                    handle.Complete();
                }
            }
        }
Example #26
0
        /// <summary>
        /// Assigns composite patter, to selected entity
        /// </summary>
        /// <param name="entityWithPatern"></param>
        static private EntityCommandBuffer _AssignComposites2Pattern(EntityCommandBuffer commandBuffer, RequestPatternSetupData requestPatternSetupData, int i_patternGroupIndex, EntityArray a_spareCompositeEntities)
        {
            //Entity assignComposites2PatternEntity = assignComposite2PatternData.a_entities [i_entityWithPaternIndex] ;
            //CompositeComponent compositeComponent = assignComposite2PatternData.a_compositeEntityRelatives [i_entityWithPaternIndex] ;

            Blocks.PatternComponent pattern = requestPatternSetupData.a_compositesInPattern [i_patternGroupIndex];
            BufferArray <Common.BufferElements.EntityBuffer> a_patternsStore = requestPatternSetupData.a_entityBuffer;

            int i_patternIndex       = pattern.i_patternIndex;
            int i_patternOffsetIndex = i_patternIndex * Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup;

            Entity requestPatternSetupEntity = requestPatternSetupData.a_entities [i_patternGroupIndex];


            // clear store for each pattern group entity
            a_patternsStore [i_patternGroupIndex].Clear();

            int i_spareEntitiesOffsetIndex = i_patternGroupIndex * Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup;

            // int i_patterGroupOffsetIndex = i_componentsPatternIndex * i_compositesCountPerPatternGroup ;
            // assign composite entity to entity with pattern
            for (int i_spareEntityIndex = 0; i_spareEntityIndex < Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup; i_spareEntityIndex++)
            {
                // get element from patern prefab to copy into group
                int i_compositeInPrefabIndex = i_patternOffsetIndex + i_spareEntityIndex;
                Blocks.Pattern.CompositeInPatternPrefabComponent compositeInPatternPrefab = Pattern.AddPatternPrefabSystem.a_patternPrefabs [i_compositeInPrefabIndex];

                // This composite is different type as previous composite.
                // This composite mesh will be scaled, to overlap next composite, if the type is the same.
                // Hence next mesh may be not required, hwen type is < 0
                if (compositeInPatternPrefab.i_compositePrefabIndex >= 0)
                {
                    // Assign relative references to composite
                    Blocks.CompositeComponent composite = new CompositeComponent()
                    {
                        blockEntity     = pattern.blockEntity,       // assign grand parent entity to composite
                        patternEntity   = requestPatternSetupEntity, // assign parent pattern group entity to composite
                        i_inPrefabIndex = i_compositeInPrefabIndex   // used prefab
                    };

                    Entity spareCompositeEntity = a_spareCompositeEntities [i_spareEntitiesOffsetIndex + i_spareEntityIndex];

                    Common.BufferElements.EntityBuffer spareEntityBuffer = new Common.BufferElements.EntityBuffer()
                    {
                        entity = spareCompositeEntity
                    };

                    // expand buffer array if is too small
                    a_patternsStore [i_patternGroupIndex].Add(spareEntityBuffer);

                    commandBuffer.SetComponent(spareCompositeEntity, composite);

                    MeshInstanceRenderer renderer;
                    switch (compositeInPatternPrefab.i_compositePrefabIndex)
                    {
                    case 1:
                        renderer = Bootstrap.octreeCenter02;
                        break;

                    case 2:
                        renderer = Bootstrap.octreeCenter03;
                        break;

                    case 3:
                        renderer = Bootstrap.octreeCenter04;
                        break;

                    case 4:
                        renderer = Bootstrap.octreeCenter05;
                        break;

                    case 5:
                        renderer = Bootstrap.octreeCenter06;
                        break;

                    case 6:
                        renderer = Bootstrap.octreeCenter07;
                        break;

                    default:
                        renderer = Bootstrap.octreeCenter01;
                        break;
                    }

                    commandBuffer.SetSharedComponent(spareCompositeEntity, renderer);

                    Position position = new Position()
                    {
                        Value = compositeInPatternPrefab.f3_position
                    };
                    commandBuffer.SetComponent(spareCompositeEntity, position);

                    Scale scale = new Scale()
                    {
                        Value = compositeInPatternPrefab.f3_scale * pattern.f_baseScale
                    };
                    commandBuffer.SetComponent(spareCompositeEntity, scale);

                    // Store composite back in
                    //Pattern.AddPatternPrefabSystem.a_patternPrefabs [ i_compositeInPrefabIndex ] = compositeInPatternPrefab ;

                    // Composite entity has been assigned
                    // Now is ready for rendering, or other processing
                    commandBuffer.RemoveComponent <Common.Components.IsNotAssignedTag> (spareCompositeEntity);
                }
                else
                {
                    // Iteration reached composite index in the prefab store, which should be ignored.
                    // Any later index for this prefab should also be ignored, as expanded mesh took its place.
                    break;
                }
            }

            return(commandBuffer);
        }
Example #27
0
 public ListCopyable(BufferArray <T> startArray)
 {
     this.innerArray = startArray;
     this.Count      = this.innerArray.Length;
     this.Capacity   = this.innerArray.Length;
 }
Example #28
0
 public void Initialize(int capacity)
 {
     this.buckets = PoolArray <Bucket> .Spawn(capacity);
 }