public Control(Allocator allocator) { Allocator = allocator; Tree = new Tree <IntPtr>(allocator); ObstaclePool = new BlockPool <Obstacle>(128, 1, allocator); Map = new UnsafeHashMap <Entity, IntPtr>(128, allocator); }
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(); } } }
void HandleChunk(int idx, EntityComponentStore *dstEntityComponentStore, UnsafeHashMap <int, int> sharedComponentRemap) { var srcChunk = Chunks[idx].m_Chunk; var numSharedComponents = srcChunk->Archetype->NumSharedComponents; var dstSharedIndices = stackalloc int[numSharedComponents]; srcChunk->SharedComponentValues.CopyTo(dstSharedIndices, 0, numSharedComponents); for (int i = 0; i < numSharedComponents; i++) { dstSharedIndices[i] = sharedComponentRemap[dstSharedIndices[i]]; } var srcArchetype = srcChunk->Archetype; var dstArchetype = dstEntityComponentStore->GetOrCreateArchetype(srcArchetype->Types, srcArchetype->TypesCount); var dstChunk = dstEntityComponentStore->GetCleanChunkNoMetaChunk(dstArchetype, dstSharedIndices); dstChunk->metaChunkEntity = srcChunk->metaChunkEntity; ChunkDataUtility.SetChunkCountKeepMetaChunk(dstChunk, srcChunk->Count); dstChunk->Archetype->EntityCount += srcChunk->Count; dstChunk->SequenceNumber = srcChunk->SequenceNumber; ClonedChunks[idx] = new ArchetypeChunk { m_Chunk = dstChunk }; }
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); }
private void RecurseChildrenAndEnable(Entity entity, ref UnsafeHashMap <Entity, bool> metadata) { if (!Children.HasComponent(entity)) { return; } var children = Children[entity].AsNativeArray(); for (int i = 0; i < children.Length; i++) { var child = children[i].Value; CmdBuffer.AddComponent <EnableRenderingTag>(child); CmdBuffer.AddComponent <UpdateVertexColorTag>(child); metadata.TryGetValue(child, out bool isActive); if (isActive) { CmdBuffer.RemoveComponent <Disabled>(child); } RecurseChildrenAndEnable(child, ref metadata); } }
public PriorityQueue(int intialCapacity, Allocator allocator = Allocator.Persistent) { Assert.IsTrue(intialCapacity > 1, "capacity must be larger than 1"); _data = new List <T>(intialCapacity, allocator); _index = new UnsafeHashMap <int, int>(intialCapacity, allocator); Clear(); }
internal void Allocate(NavmeshComponent component) { Assert.IsTrue(math.all(component.Size > 0)); Assert.IsTrue(component.ExpectedVerts > 0); Max = component.Size / 2; _e = component.MergePointsDistance; _collinearMargin = component.CollinearMargin; _vertices = new PersistentStore <Vertex>(component.ExpectedVerts, Allocator.Persistent); _verticesSeq = new UnsafeList <IntPtr>(component.ExpectedVerts, Allocator.Persistent); _quadEdges = new PersistentStore <QuadEdge>(3 * component.ExpectedVerts, Allocator.Persistent); _constraints = new UnsafeHashMap <Entity, IntPtr>(component.ExpectedVerts, Allocator.Persistent); V = new HashSet <IntPtr>(16, Allocator.Persistent); C = new HashSet <IntPtr>(16, Allocator.Persistent); _edgeSearch = new EdgeSearch(100, 100, Allocator.Persistent); _qt = new QuadTree(math.max(component.Size.x, component.Size.y), 100, 10, Allocator.Persistent); _flipStack = new PtrStack <Edge>(32, Allocator.Persistent); _insertedPoints = new UnsafeList <Point>(64, Allocator.Persistent); _open = new PtrStack <Vertex>(64, Allocator.Persistent); _vlist = new UnsafeList <IntPtr>(64, Allocator.Persistent); _elist = new UnsafeList <IntPtr>(64, Allocator.Persistent); _creps = new Stack <UnsafeList>(2 * component.ExpectedVerts, Allocator.Persistent); for (int i = 0; i < 2 * component.ExpectedVerts; i++) { _creps.Push(new UnsafeList(UnsafeUtility.SizeOf <int>(), UnsafeUtility.AlignOf <int>(), CrepMinCapacity, Allocator.Persistent)); } DestroyedTriangles = new HashSet <int>(64, Allocator.Persistent); _refinementQueue = new Deque <IntPtr>(24, Allocator.Persistent); BuildBoundingBoxes(); }
/** * Deserialize the input string into a series of buffers */ internal TinyJsonData(string jsonString, Allocator allocator) { var config = JsonDataConfiguration.Default; m_Allocator = allocator; m_BoolBuffer = new NativeList <bool>(config.boolCapacity, m_Allocator); m_IntBuffer = new NativeList <int>(config.intCapacity, m_Allocator); m_FloatBuffer = new NativeList <float>(config.floatCapacity, m_Allocator); m_StringBuffer = new NativeList <FixedString4096>(config.stringCapacity, m_Allocator); m_ArrayBuffer = new NativeList <UnsafeList <JsonKeyHandle> >(config.arrayCapacity, m_Allocator); m_ObjectBuffer = new NativeList <UnsafeHashMap <FixedString128, JsonKeyHandle> >(config.objectCapacity, m_Allocator); m_JsonKeyBuffer = new NativeList <JsonKey>(config.intCapacity, m_Allocator); m_ValueRefFreeList = new NativeList <int>(config.intCapacity, m_Allocator); // parse existing json into a packed binary stream SerializedObjectReader reader; fixed(char *ptr = jsonString) { reader = new SerializedObjectReader(ptr, jsonString.Length, SerializedObjectReaderConfiguration.Default); } // determine the type and copy each field-value pair into the mutable map / buffers m_RootObjMap = new UnsafeHashMap <FixedString128, JsonKeyHandle>(config.fieldCapacity, m_Allocator); m_JsonKeyBuffer.Add(new JsonKey { Type = JsonValueType.Object, Location = 0 }); ReadObjectViewIntoMap(reader.ReadObject(), ref m_RootObjMap); reader.Dispose(); }
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}"); } } }
internal void Dispose() { if (uniqueParameters.IsCreated) { uniqueParameters.Dispose(); uniqueParameters = default; } uniqueParameterCount = 0; }
public void UnsafeHashMap_RemoveOnEmptyMap_DoesNotThrow() { var container = new UnsafeHashMap <int, int>(0, Allocator.Temp); Assert.DoesNotThrow(() => container.Remove(0)); Assert.DoesNotThrow(() => container.Remove(-425196)); container.Dispose(); }
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)); }
NativeHashMap(int capacity, Allocator allocator, int disposeSentinelStackDepth) { m_HashMapData = new UnsafeHashMap <TKey, TValue>(capacity, allocator, disposeSentinelStackDepth); #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, disposeSentinelStackDepth, allocator); #endif }
/** * Deserialize an object view into the object buffer. */ JsonKeyHandle DeserializeToObjectBuffer(SerializedObjectView objectView) { var newObjMap = new UnsafeHashMap <FixedString128, JsonKeyHandle>(50, m_Allocator); ReadObjectViewIntoMap(objectView, ref newObjMap); m_ObjectBuffer.Add(newObjMap); return(new JsonKeyHandle(ref this, JsonValueType.Object, m_ObjectBuffer.Length - 1)); }
void ComputeSmoothedNormalByJob(Mesh smoothedMesh, Mesh originalMesh, int maxOverlapvertices = 20) { int svc = smoothedMesh.vertexCount, ovc = originalMesh.vertexCount; // CollectNormalJob Data NativeArray <Vector3> normals = new NativeArray <Vector3>(smoothedMesh.normals, Allocator.Persistent), vertrx = new NativeArray <Vector3>(smoothedMesh.vertices, Allocator.Persistent), smoothedNormals = new NativeArray <Vector3>(svc, Allocator.Persistent); var result = new NativeArray <UnsafeHashMap <Vector3, Vector3> >(maxOverlapvertices, Allocator.Persistent); var resultParallel = new NativeArray <UnsafeHashMap <Vector3, Vector3> .ParallelWriter>(result.Length, Allocator.Persistent); // NormalBakeJob Data NativeArray <Vector3> normalsO = new NativeArray <Vector3>(originalMesh.normals, Allocator.Persistent), vertrxO = new NativeArray <Vector3>(originalMesh.vertices, Allocator.Persistent); var tangents = new NativeArray <Vector4>(originalMesh.tangents, Allocator.Persistent); var colors = new NativeArray <Color>(ovc, Allocator.Persistent); var uv2 = new NativeArray <Vector2>(ovc, Allocator.Persistent); for (int i = 0; i < result.Length; i++) { result[i] = new UnsafeHashMap <Vector3, Vector3>(svc, Allocator.Persistent); resultParallel[i] = result[i].AsParallelWriter(); } bool existColors = originalMesh.colors.Length == ovc; bool isFace = originalMesh.name.Contains("face") || originalMesh.name.Contains("Face"); if (existColors) { colors.CopyFrom(originalMesh.colors); } CollectNormalJob collectNormalJob = new CollectNormalJob(normals, vertrx, resultParallel); BakeNormalJob normalBakeJob = new BakeNormalJob( vertrxO, normalsO, tangents, result, existColors, isFace, colors, uv2); normalBakeJob.Schedule(ovc, 100, collectNormalJob.Schedule(svc, 100)).Complete(); var c = new Color[ovc]; colors.CopyTo(c); originalMesh.colors = c; if (isFace) { var _uv2 = new Vector2[ovc]; uv2.CopyTo(_uv2); originalMesh.uv2 = _uv2; } normals.Dispose(); vertrx.Dispose(); result.Dispose(); smoothedNormals.Dispose(); resultParallel.Dispose(); normalsO.Dispose(); vertrxO.Dispose(); tangents.Dispose(); colors.Dispose(); uv2.Dispose(); }
public void DeallocateSystemData(uint systemId) { if (!UnsafeHashMap.ContainsKey(SystemData, systemId)) { throw new InvalidOperationException(); } UnsafeUtility.Free((void *)UnsafeHashMap.Get <uint, IntPtr>(SystemData, systemId), Allocator.Persistent); UnsafeHashMap.Remove(SystemData, systemId); }
public void Dispose() { foreach (var val in UnsafeHashMap.GetIterator <uint, IntPtr>(SystemData)) { UnsafeUtility.Free((void *)val.value, Allocator.Persistent); } UnsafeHashMap.Free(SystemData); }
static void AddAssetDependencies(ConversionDependencies dependencies, ref UnsafeHashMap <GUID, byte> assets) { using (var keys = dependencies.AssetDependentsByInstanceId.GetKeyArray(Allocator.Temp)) { for (int i = 0; i < keys.Length; i++) { AssetDatabase.TryGetGUIDAndLocalFileIdentifier(keys[i], out var guid, out long _); assets.TryAdd(new GUID(guid), 1); } } }
internal JsonKeyHandle CreateNestedObject(out TinyJsonObject value) { var handle = new JsonKeyHandle(ref this, JsonValueType.Object, m_ObjectBuffer.Length); var objMap = new UnsafeHashMap <FixedString128, JsonKeyHandle>(10, m_Allocator); m_ObjectBuffer.Add(objMap); value = new TinyJsonObject { m_Data = this, Type = JsonValueType.Object }; value.m_Data.m_RootObjMap = objMap; return(handle); }
public ref SystemChunkData GetChunkData(uint systemId) { if (!UnsafeHashMap.ContainsKey(SystemToChunks, systemId)) { var data = new SystemChunkData { Chunks = new UnsafeList <ArchetypeChunk>(64, Allocator.Persistent) }; UnsafeHashMap.Set(SystemToChunks, systemId, UnsafeUtility.AddressOf(ref data), UnsafeUtility.SizeOf <SystemChunkData>()); return(ref UnsafeUtility.AsRef <SystemChunkData>(UnsafeHashMap.GetPtr(SystemToChunks, systemId))); } return(ref UnsafeUtility.AsRef <SystemChunkData>(UnsafeHashMap.GetPtr(SystemToChunks, systemId))); }
NativeHashMap(int capacity, Allocator allocator, int disposeSentinelStackDepth) { m_HashMapData = new UnsafeHashMap <TKey, TValue>(capacity, allocator); #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, disposeSentinelStackDepth, allocator); if (s_staticSafetyId.Data == 0) { CreateStaticSafetyId(); } AtomicSafetyHandle.SetStaticSafetyId(ref m_Safety, s_staticSafetyId.Data); #endif }
public ref SystemGhostData GetGhostData(uint systemId) { if (!UnsafeHashMap.ContainsKey(SystemToGhostIds, systemId)) { var data = new SystemGhostData { GhostIds = new UnsafeList <uint>(64, Allocator.Persistent) }; UnsafeHashMap.Set(SystemToGhostIds, systemId, UnsafeUtility.AddressOf(ref data), UnsafeUtility.SizeOf <SystemGhostData>()); return(ref UnsafeUtility.AsRef <SystemGhostData>(UnsafeHashMap.GetPtr(SystemToGhostIds, systemId))); } return(ref UnsafeUtility.AsRef <SystemGhostData>(UnsafeHashMap.GetPtr(SystemToGhostIds, systemId))); }
/** * Deserialize each field in an object */ void ReadObjectViewIntoMap(SerializedObjectView objView, ref UnsafeHashMap <FixedString128, JsonKeyHandle> objMap) { var serializedViewEnum = objView.GetEnumerator(); while (serializedViewEnum.MoveNext()) { var view = serializedViewEnum.Current; var typeInfo = DeserializeValueView(view.Value()); FixedString64 fs = default; fs.Append(view.Name().ToString()); objMap.TryAdd(fs, typeInfo); } serializedViewEnum.Dispose(); }
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(); } }
private void RecurseAddMetadata(ref UnsafeHashMap <Entity, bool> interactableMetadata, Transform current) { for (int i = 0; i < current.childCount; i++) { var child = current.GetChild(i); var childEntity = this.GetPrimaryEntity(child); interactableMetadata.TryAdd(GetPrimaryEntity(child), child.gameObject.activeSelf); if (child.childCount > 0) { RecurseAddMetadata(ref interactableMetadata, child); } } }
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); } }
/** * Initialize a mutable JSON container without deserializing existing data. */ internal TinyJsonData(Allocator allocator) { var config = JsonDataConfiguration.Default; m_Allocator = allocator; m_BoolBuffer = new NativeList <bool>(config.boolCapacity, m_Allocator); m_IntBuffer = new NativeList <int>(config.intCapacity, m_Allocator); m_FloatBuffer = new NativeList <float>(config.floatCapacity, m_Allocator); m_StringBuffer = new NativeList <FixedString4096>(config.stringCapacity, m_Allocator); m_ArrayBuffer = new NativeList <UnsafeList <JsonKeyHandle> >(config.arrayCapacity, m_Allocator); m_ObjectBuffer = new NativeList <UnsafeHashMap <FixedString128, JsonKeyHandle> >(config.objectCapacity, m_Allocator); m_RootObjMap = new UnsafeHashMap <FixedString128, JsonKeyHandle>(config.fieldCapacity, m_Allocator); m_JsonKeyBuffer = new NativeList <JsonKey>(config.intCapacity, m_Allocator); m_ValueRefFreeList = new NativeList <int>(config.intCapacity, m_Allocator); }
public void UnsafeHashMap_AddJob() { var container = new UnsafeHashMap <int, int>(32, Allocator.TempJob); var job = new UnsafeHashMapAddJob() { Writer = container.AsParallelWriter(), }; job.Schedule().Complete(); Assert.True(container.ContainsKey(123)); container.Dispose(); }
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(); } }
public LiveLinkConnection(Hash128 buildConfigurationGuid) { _BuildConfigurationGUID = buildConfigurationGuid; if (buildConfigurationGuid != default) { _BuildConfiguration = BuildConfiguration.LoadAsset(buildConfigurationGuid); if (_BuildConfiguration == null) { Debug.LogError($"Unable to load build configuration asset from guid {buildConfigurationGuid}."); } } Undo.postprocessModifications += PostprocessModifications; Undo.undoRedoPerformed += GlobalDirtyLiveLink; _RemovedScenes = new NativeList <Hash128>(Allocator.Persistent); m_AssetDependencies = new UnsafeHashMap <GUID, byte>(100, Allocator.Persistent); k_AllConnections.Add(this); }