public void UnsafeHashMap_Performance_RepeatLookup([Values(10, 100, 1000, 10000, 100000, 1000000, 2500000, 10000000)] int insertions)
    {
        using (var container = new UnsafeHashMap <int, int>(insertions, Allocator.Persistent))
        {
            using (var addedKeys = new NativeList <int>(insertions, Allocator.Persistent))
            {
                Random.InitState(0);
                for (int i = 0; i < insertions; i++)
                {
                    int randKey = Random.Range(0, insertions);
                    container.Add(randKey, randKey);
                    addedKeys.Add(randKey);
                }

                Measure.Method(() =>
                {
                    for (int i = 0; i < insertions; i++)
                    {
                        int randKey = addedKeys[i];
                        Assert.IsTrue(container.TryGetValue(randKey, out _));
                    }
                })
                .WarmupCount(10)
                .MeasurementCount(10)
                .Run();
            }
        }
    }
Ejemplo n.º 2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        bool hasNoGrid = m_GridQuery.IsEmptyIgnoreFilter;

        if (hasNoGrid)
        {
            var settings = GetSingleton <AntManagerSettings>();
            int mapSize  = settings.MapSize;

            World.EntityManager.CreateEntity(typeof(PheromoneGrid));

            var values = new UnsafeHashMap <int, float>(mapSize * mapSize, Allocator.Persistent);

            for (int i = 0; i < mapSize * mapSize; ++i)
            {
                values.Add(i, 0f);
            }

            var grid = new PheromoneGrid {
                Values = values
            };
            SetSingleton(grid);
        }

        return(inputDeps);
    }
Ejemplo n.º 3
0
    public void UnsafeHashMap_ForEach([Values(10, 1000)] int n)
    {
        var seen = new NativeArray <int>(n, Allocator.Temp);

        using (var container = new UnsafeHashMap <int, int>(32, Allocator.TempJob))
        {
            for (int i = 0; i < n; i++)
            {
                container.Add(i, i * 37);
            }

            var count = 0;
            foreach (var kv in container)
            {
                int value;
                Assert.True(container.TryGetValue(kv.Key, out value));
                Assert.AreEqual(value, kv.Value);
                Assert.AreEqual(kv.Key * 37, kv.Value);

                seen[kv.Key] = seen[kv.Key] + 1;
                ++count;
            }

            Assert.AreEqual(container.Count(), count);
            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(1, seen[i], $"Incorrect key count {i}");
            }
        }
    }
Ejemplo n.º 4
0
 internal bool RegisterParameter(int parameter)
 {
     if (parameter == 0)
     {
         return(false);
     }
     if (!uniqueParameters.TryGetValue(parameter, out var item))
     {
         var index = uniqueParameterCount;
         uniqueParameterCount++;
         if (uniqueParameters.Capacity < uniqueParameterCount)
         {
             uniqueParameters.Capacity = Mathf.CeilToInt(uniqueParameterCount * 1.5f);
         }
         uniqueParameters.Add(parameter,
                              new ChiselLayerParameterIndex
         {
             count = 1,
             index = index
         });
         return(true);
     }
     else
     {
         item.count++;
         uniqueParameters[parameter] = item;
         return(false);
     }
 }
Ejemplo n.º 5
0
        public ref T AllocateSystemData <T>(uint systemId)
            where T : struct
        {
            var ptr = UnsafeUtility.Malloc(UnsafeUtility.SizeOf <T>(), UnsafeUtility.AlignOf <T>(), Allocator.Persistent);

            UnsafeHashMap.Add(SystemData, systemId, (IntPtr)ptr);
            return(ref UnsafeUtilityEx.AsRef <T>(ptr));
        }
    public void UnsafeHashMap_Performance_Count([Values(10, 100, 1000, 10000, 100000, 1000000, 2500000, 10000000)] int capacity)
    {
        using (var container = new UnsafeHashMap <int, int>(capacity, Allocator.Persistent))
        {
            container.Add(1, 1);

            Measure.Method(() =>
            {
                container.Count();
            })
            .WarmupCount(10)
            .MeasurementCount(10)
            .Run();
        }
    }
Ejemplo n.º 7
0
            public void Execute()
            {
                var dstEntityComponentStore = DstEntityManager.GetCheckedEntityDataAccess()->EntityComponentStore;

                var remapping = new UnsafeHashMap <int, int>(SrcSharedComponentIndices.Length, Allocator.Temp);

                for (int i = 0; i < SrcSharedComponentIndices.Length; i++)
                {
                    remapping.Add(SrcSharedComponentIndices[i], DstSharedComponentIndices[i]);
                }
                for (int i = 0; i < Chunks.Length; i++)
                {
                    HandleChunk(i, dstEntityComponentStore, remapping);
                }
            }
 public void UnsafeHashMap_Performance_RepeatInsert([Values(10, 100, 1000, 10000, 100000, 1000000, 2500000, 10000000)] int insertions)
 {
     using (var container = new UnsafeHashMap <int, int>(insertions, Allocator.Persistent))
     {
         Random.InitState(0);
         Measure.Method(() =>
         {
             for (int i = 0; i < insertions; i++)
             {
                 int randKey = Random.Range(0, insertions);
                 container.Add(randKey, randKey);
             }
         })
         .WarmupCount(10)
         .MeasurementCount(10)
         .Run();
     }
 }
        internal int AddSystemType(long typeHash, FixedString64 debugName, UnmanagedComponentSystemDelegates delegates)
        {
            if (m_TypeHashToIndex.TryGetValue(typeHash, out int index))
            {
                if (m_DebugNames[index] != debugName)
                {
                    Debug.LogError($"Type hash {typeHash} for {debugName} collides with {m_DebugNames[index]}. Skipping this type. Rename the type to avoid the collision.");
                    return(-1);
                }

                m_Delegates[index] = delegates;
                return(index);
            }
            else
            {
                int newIndex = m_Delegates.Length;
                m_TypeHashToIndex.Add(typeHash, newIndex);
                m_DebugNames.Add(debugName);
                m_Delegates.Add(delegates);
                return(newIndex);
            }
        }
        void AddLiveLinkChangeSet(Hash128 sceneGUID, List <LiveLinkChangeSet> changeSets, LiveLinkMode mode)
        {
            var liveLink  = GetLiveLink(sceneGUID);
            var editScene = _GUIDToEditScene[sceneGUID];

            // The current behaviour is that we do incremental conversion until we release the hot control
            // This is to avoid any unexpected stalls
            // Optimally the undo system would tell us if only properties have changed, but currently we don't have such an event stream.
            var sceneDirtyID   = GetSceneDirtyID(editScene);
            var updateLiveLink = true;

            if (IsHotControlActive())
            {
                if (liveLink != null)
                {
                    sceneDirtyID = liveLink.LiveLinkDirtyID;
                }
                else
                {
                    updateLiveLink = false;
                    EditorUpdateUtility.EditModeQueuePlayerLoopUpdate();
                }
            }
            else
            {
                if (liveLink != null && liveLink.LiveLinkDirtyID != sceneDirtyID)
                {
                    liveLink.RequestCleanConversion();
                }
            }

            if (updateLiveLink)
            {
                //@TODO: need one place that LiveLinkDiffGenerators are managed. UpdateLiveLink does a Dispose()
                // but this must be paired with membership in _SceneGUIDToLiveLink. not good to have multiple places
                // doing ownership management.
                //
                // also: when implementing an improvement to this, be sure to deal with exceptions, which can occur
                // during conversion.

                if (liveLink != null)
                {
                    _SceneGUIDToLiveLink.Remove(sceneGUID);
                }

                try
                {
                    changeSets.Add(LiveLinkDiffGenerator.UpdateLiveLink(editScene, sceneGUID, ref liveLink, sceneDirtyID, mode, _BuildConfiguration, out var assetDependencies));
                    if (assetDependencies.IsCreated)
                    {
                        m_AssetDependencies.Clear();
                        foreach (var asset in assetDependencies)
                        {
                            m_AssetDependencies.Add(asset, 1);
                        }
                        assetDependencies.Dispose();
                    }
                }
                finally
                {
                    if (liveLink != null)
                    {
                        _SceneGUIDToLiveLink.Add(sceneGUID, liveLink);
                    }
                }
            }
        }