public bool TryGetOptimalAction(TStateKey stateKey, out TActionKey action) { action = default; bool actionsFound = ActionLookup.TryGetFirstValue(stateKey, out var actionKey, out var iterator); if (!actionsFound) { return(false); } var maxCumulativeReward = float.MinValue; do { var stateActionPair = new StateActionPair <TStateKey, TActionKey>(stateKey, actionKey); ActionInfoLookup.TryGetValue(stateActionPair, out var actionInfo); if (actionInfo.CumulativeRewardEstimate.Average > maxCumulativeReward) { action = actionKey; maxCumulativeReward = actionInfo.CumulativeRewardEstimate.Average; } } while (ActionLookup.TryGetNextValue(out actionKey, ref iterator)); return(true); }
public float4 SumForcesAndEnergiesCell(int i, Position p_i, int cell) { int j; Position p_j; float3 force = new float3(0f, 0f, 0f); float energy = 0f; NativeMultiHashMapIterator <int> pos_it; NativeMultiHashMapIterator <int> hash_it; if (cell_positions.TryGetFirstValue(cell, out p_j, out pos_it) && hash_map.TryGetFirstValue(cell, out j, out hash_it)) { if (i != j) { ComputeForceAndEnergy(p_i, p_j, ref energy, ref force); } while (cell_positions.TryGetNextValue(out p_j, ref pos_it) && hash_map.TryGetNextValue(out j, ref hash_it)) { if (i != j) { ComputeForceAndEnergy(p_i, p_j, ref energy, ref force); } } } return(new float4(force, energy)); }
private unsafe int FindNonDefaultSharedComponentIndex(int typeIndex, int hashCode, void *newData, FastEquality.TypeInfo typeInfo) { int itemIndex; NativeMultiHashMapIterator <int> iter; if (!m_HashLookup.TryGetFirstValue(hashCode, out itemIndex, out iter)) { return(-1); } do { var data = m_SharedComponentData[itemIndex]; if (data != null && m_SharedComponentType[itemIndex] == typeIndex) { ulong handle; var value = PinGCObjectAndGetAddress(data, out handle); var res = FastEquality.Equals(newData, value, typeInfo); UnsafeUtility.ReleaseGCObject(handle); if (res) { return(itemIndex); } } } while (m_HashLookup.TryGetNextValue(out itemIndex, ref iter)); return(-1); }
public void Execute(int index) { int cellHash = OverlappingCells[index]; if (InstigatorMap.TryGetFirstValue(cellHash, out FindAttackTargetDataTuple currentInstigatorTuple, out NativeMultiHashMapIterator <int> instigatorIterator) == false) { return; } do { if (TargetMap.TryGetFirstValue(cellHash, out FindAttackTargetDataTuple currentTargetTuple, out NativeMultiHashMapIterator <int> targetIterator) == false) { return; } do { if (CheckInRange(currentTargetTuple.Position, currentInstigatorTuple.Position, currentInstigatorTuple.RangeSqr)) { var attackTargetComponent = new AttackTargetComponent { Target = currentTargetTuple.Entity }; CommandBuffer.AddComponent(m_ThreadIndex, currentInstigatorTuple.Entity, attackTargetComponent); //CommandBuffer.AddComponent(chunkIndex, EntityToTestAgainst[j], new OccupiedAsTargetTag()); break; } } while (InstigatorMap.TryGetNextValue(out currentTargetTuple, ref targetIterator) == true); } while (InstigatorMap.TryGetNextValue(out currentInstigatorTuple, ref instigatorIterator) == true); }
bool UpdateStateValue(TStateKey stateKey, NativeMultiHashMap <TStateKey, TActionKey> actionLookup, NativeHashMap <TStateKey, StateInfo> stateInfoLookup, NativeHashMap <StateActionPair <TStateKey, TActionKey>, ActionInfo> actionInfoLookup) { var stateInfo = stateInfoLookup[stateKey]; // Handle case of no valid actions (mark complete) if (!actionLookup.TryGetFirstValue(stateKey, out var actionKey, out var iterator)) { if (!stateInfo.SubplanIsComplete) { // State was not marked terminal, so the value should be reset, as to not use the estimated value. stateInfo.CumulativeRewardEstimate = new BoundedValue(0, 0, 0); stateInfo.SubplanIsComplete = true; stateInfoLookup[stateKey] = stateInfo; return(true); } // Terminal state. No update required. return(false); } var originalValue = stateInfo.CumulativeRewardEstimate; var originalCompleteStatus = stateInfo.SubplanIsComplete; stateInfo.CumulativeRewardEstimate = new BoundedValue(float.MinValue, float.MinValue, float.MinValue); stateInfo.SubplanIsComplete = true; var maxLowerBound = float.MinValue; // Pick max action; find max lower bound do { var stateActionPair = new StateActionPair <TStateKey, TActionKey>(stateKey, actionKey); var actionInfo = actionInfoLookup[stateActionPair]; stateInfo.CumulativeRewardEstimate = stateInfo.CumulativeRewardEstimate.Average < actionInfo.CumulativeRewardEstimate.Average ? actionInfo.CumulativeRewardEstimate : stateInfo.CumulativeRewardEstimate; maxLowerBound = math.max(maxLowerBound, actionInfo.CumulativeRewardEstimate.LowerBound); }while (actionLookup.TryGetNextValue(out actionKey, ref iterator)); // Update complete status (ignore pruned actions) actionLookup.TryGetFirstValue(stateKey, out actionKey, out iterator); do { var stateActionPair = new StateActionPair <TStateKey, TActionKey>(stateKey, actionKey); var actionInfo = actionInfoLookup[stateActionPair]; if (actionInfo.CumulativeRewardEstimate.UpperBound >= maxLowerBound) { stateInfo.SubplanIsComplete &= actionInfo.SubplanIsComplete; } }while (actionLookup.TryGetNextValue(out actionKey, ref iterator)); // Reassign stateInfoLookup[stateKey] = stateInfo; return(!originalValue.Approximately(stateInfo.CumulativeRewardEstimate) || originalCompleteStatus != stateInfo.SubplanIsComplete); }
private NativeList <T> GetActorsFromRandomPoints(NativeArray <float3> points, Allocator allocator) { var hashMap = new NativeHashMap <int, bool>(points.Length, Allocator.Temp); for (int i = 0; i < points.Length; i++) { var hash = GetQuadrantHash(points[i]); hashMap.TryAdd(hash, true); } var actors = new NativeList <T>(allocator); var uniqueHashes = hashMap.GetKeyArray(Allocator.Temp); hashMap.Dispose(); for (int i = 0; i < uniqueHashes.Length; i++) { var hash = uniqueHashes[i]; if (_quadrantMap.TryGetFirstValue(hash, out var actor, out var it)) { do { actors.Add(actor); }while (_quadrantMap.TryGetNextValue(out actor, ref it)); } } uniqueHashes.Dispose(); return(actors); }
void TransformTree(Entity entity, float4x4 parentMatrix) { var position = new float3(); var rotation = quaternion.identity; if (positions.Exists(entity)) { position = positions[entity].Value; } if (rotations.Exists(entity)) { rotation = rotations[entity].Value; } if (localPositions.Exists(entity)) { var worldPosition = math.mul(parentMatrix, new float4(localPositions[entity].Value, 1.0f)); position = new float3(worldPosition.x, worldPosition.y, worldPosition.z); if (positions.Exists(entity)) { positions[entity] = new Position { Value = position }; } } if (localRotations.Exists(entity)) { var parentRotation = math.matrixToQuat(parentMatrix.m0.xyz, parentMatrix.m1.xyz, parentMatrix.m2.xyz); var localRotation = localRotations[entity].Value; rotation = math.mul(parentRotation, localRotation); if (rotations.Exists(entity)) { rotations[entity] = new Rotation { Value = rotation }; } } float4x4 matrix = math.rottrans(rotation, position); if (transformMatrices.Exists(entity)) { transformMatrices[entity] = new TransformMatrix { Value = matrix }; } Entity child; NativeMultiHashMapIterator <Entity> iterator; bool found = hierarchy.TryGetFirstValue(entity, out child, out iterator); while (found) { TransformTree(child, matrix); found = hierarchy.TryGetNextValue(out child, ref iterator); } }
public void Execute(int index) { // Cache int particleCount = particlesPosition.Length; float3 position = particlesPosition[index].Value; float3 velocity = particlesVelocity[index].Value; float pressure = particlesPressure[index]; float density = particlesDensity[index]; float3 forcePressure = new float3(0, 0, 0); float3 forceViscosity = new float3(0, 0, 0); int i, hash, j; int3 gridOffset; int3 gridPosition = GridHash.Quantize(position, settings.radius); bool found; // Physics // Find neighbors for (int oi = 0; oi < 27; oi++) { i = oi * 3; gridOffset = new int3(cellOffsetTable[i], cellOffsetTable[i + 1], cellOffsetTable[i + 2]); hash = GridHash.Hash(gridPosition + gridOffset); NativeMultiHashMapIterator <int> iterator; found = hashMap.TryGetFirstValue(hash, out j, out iterator); while (found) { // Neighbor found, get density if (index == j) { found = hashMap.TryGetNextValue(out j, ref iterator); continue; } float3 rij = particlesPosition[j].Value - position; float r2 = math.lengthsq(rij); float r = math.sqrt(r2); if (r < settings.smoothingRadius) { forcePressure += -math.normalize(rij) * settings.mass * (2.0f * pressure) / (2.0f * density) * (-45.0f / (PI * math.pow(settings.smoothingRadius, 6.0f))) * math.pow(settings.smoothingRadius - r, 2.0f); forceViscosity += settings.viscosity * settings.mass * (particlesVelocity[j].Value - velocity) / density * (45.0f / (PI * math.pow(settings.smoothingRadius, 6.0f))) * (settings.smoothingRadius - r); } // Next neighbor found = hashMap.TryGetNextValue(out j, ref iterator); } } // Gravity float3 forceGravity = new float3(0.0f, -9.81f, 0.0f) * density * settings.gravityMult; // Apply particlesForces[index] = forcePressure + forceViscosity + forceGravity; }
protected override unsafe void OnUpdate() { var time = new LifeTime { Value = Time.timeSinceLevelLoad }; var buf = PostUpdateCommands; toDestroyTuples.Clear(); foreach (var key in playerBulletPositionHashSet) { if (!playerBulletHashCodes.TryGetFirstValue(key, out var playerBulletItem, out var playerBulletIt) || !enemyHashCodes.TryGetFirstValue(key, out var enemyItem, out var enemyIt)) { continue; } var diffX = enemyItem.Position.x - playerBulletItem.Position.x; var diffY = enemyItem.Position.y - playerBulletItem.Position.y; if (diffX * diffX + diffY * diffY <= radiusSquared) { toDestroyTuples.Add(playerBulletItem); } while (enemyHashCodes.TryGetNextValue(out enemyItem, ref enemyIt)) { diffX = enemyItem.Position.x - playerBulletItem.Position.x; diffY = enemyItem.Position.y - playerBulletItem.Position.y; if (diffX * diffX + diffY * diffY <= radiusSquared) { toDestroyTuples.Add(playerBulletItem); } } while (playerBulletHashCodes.TryGetNextValue(out playerBulletItem, ref playerBulletIt)) { diffX = enemyItem.Position.x - playerBulletItem.Position.x; diffY = enemyItem.Position.y - playerBulletItem.Position.y; if (diffX * diffX + diffY * diffY <= radiusSquared) { toDestroyTuples.Add(playerBulletItem); } while (enemyHashCodes.TryGetNextValue(out enemyItem, ref enemyIt)) { diffX = enemyItem.Position.x - playerBulletItem.Position.x; diffY = enemyItem.Position.y - playerBulletItem.Position.y; if (diffX * diffX + diffY * diffY <= radiusSquared) { toDestroyTuples.Add(playerBulletItem); } } } } foreach (var toDestroy in toDestroyTuples) { BurstTakenoko(time, ref buf, toDestroy); } }
float GetWaterGain(PlantScript.PlantData plant) { float rootArea = (math.PI * plant.rootGrowth.x * plant.rootGrowth.y) + (math.pow(plant.rootGrowth.x / 2, 2) * 2); float overLapingRootArea = 0f; if (plantsInZones.TryGetFirstValue(plant.zone, out int targetPlant, out var iterator)) { do { float distance = GetDistanceToPlant(plant, allPlants[targetPlant]); float rootDistance = GetRootSize(plant) + GetRootSize(allPlants[targetPlant]); if (distance < rootDistance) { float reletiveDepth = (plant.rootGrowth.y - allPlants[targetPlant].rootGrowth.y) / plant.rootGrowth.y; float reletiveDistance = rootDistance - distance; overLapingRootArea += (reletiveDistance / 2) / (1 + reletiveDepth); } } while (plantsInZones.TryGetNextValue(out targetPlant, ref iterator)); } int zoneNumber; if (neiboringZones.TryGetFirstValue(plant.zone, out zoneNumber, out var iterator2)) { do { if (plantsInZones.TryGetFirstValue(zoneNumber, out targetPlant, out var iterator3)) { do { float distance = GetDistanceToPlant(plant, allPlants[targetPlant]); float rootDistance = GetRootSize(plant) + GetRootSize(allPlants[targetPlant]); if (distance < rootDistance) { float reletiveDepth = (plant.rootGrowth.y - allPlants[targetPlant].rootGrowth.y) / plant.rootGrowth.y; float reletiveDistance = rootDistance - distance; overLapingRootArea += (reletiveDistance / 2) / (1 + reletiveDepth); } } while (plantsInZones.TryGetNextValue(out targetPlant, ref iterator3)); } } while (neiboringZones.TryGetNextValue(out zoneNumber, ref iterator2)); } rootArea = rootArea - overLapingRootArea; float rootUnderWaterPercent = 1 - (zones[plant.zone].waterDepth / plant.rootGrowth.y); if (rootUnderWaterPercent < 0) { return(0); } return(rootUnderWaterPercent * rootArea * plant.rootDensity * .01f); }
public void NativeHashMap_RemoveFromMultiHashMap() { var hashMap = new NativeMultiHashMap <int, int> (16, Allocator.Temp); int iSquared; // Make sure inserting values work for (int i = 0; i < 8; ++i) { hashMap.Add(i, i * i); } for (int i = 0; i < 8; ++i) { hashMap.Add(i, i); } Assert.AreEqual(16, hashMap.Capacity, "HashMap grew larger than expected"); // Make sure reading the inserted values work for (int i = 0; i < 8; ++i) { NativeMultiHashMapIterator <int> it; Assert.IsTrue(hashMap.TryGetFirstValue(i, out iSquared, out it), "Failed get value from hash table"); Assert.AreEqual(iSquared, i, "Got the wrong value from the hash table"); Assert.IsTrue(hashMap.TryGetNextValue(out iSquared, ref it), "Failed get value from hash table"); Assert.AreEqual(iSquared, i * i, "Got the wrong value from the hash table"); } for (int rm = 0; rm < 8; ++rm) { Assert.AreEqual(2, hashMap.Remove(rm)); NativeMultiHashMapIterator <int> it; Assert.IsFalse(hashMap.TryGetFirstValue(rm, out iSquared, out it), "Failed to remove value from hash table"); for (int i = rm + 1; i < 8; ++i) { Assert.IsTrue(hashMap.TryGetFirstValue(i, out iSquared, out it), "Failed get value from hash table"); Assert.AreEqual(iSquared, i, "Got the wrong value from the hash table"); Assert.IsTrue(hashMap.TryGetNextValue(out iSquared, ref it), "Failed get value from hash table"); Assert.AreEqual(iSquared, i * i, "Got the wrong value from the hash table"); } } // Make sure entries were freed for (int i = 0; i < 8; ++i) { hashMap.Add(i, i * i); } for (int i = 0; i < 8; ++i) { hashMap.Add(i, i); } Assert.AreEqual(16, hashMap.Capacity, "HashMap grew larger than expected"); hashMap.Dispose(); }
private void FindTarget(int hasKey, float3 unitPosition, QuardrantType quardrantType, ref Entity selectedEntity, ref float selectedDistance) { QuardrantData data; NativeMultiHashMapIterator <int> iterator; if (multiHasMap.TryGetFirstValue(hasKey, out data, out iterator)) { do { if (quardrantType.type != data.quardrantEntity.type) { if (selectedEntity == Entity.Null) { selectedEntity = data.entity; selectedDistance = math.distance(unitPosition, data.position); } else { float curDistance = math.distance(unitPosition, data.position); if (curDistance < selectedDistance) { selectedEntity = data.entity; selectedDistance = math.distance(unitPosition, data.position); } } } }while(multiHasMap.TryGetNextValue(out data, ref iterator)); } }
private void BFS(ref NativeMultiHashMap <Entity, Entity> cons, ref NativeList <Entity> network, Entity curNode, EntityManager entityManager, int level, bool isOut, ref NativeHashMap <Entity, int> netTravelNodes) { if (cons.TryGetFirstValue(curNode, out var inoutCon, out var it)) { do { var con = entityManager.GetComponentData <Connection>(inoutCon); if (con.Level != level) { netTravelNodes.TryAdd(isOut ? con.StartNode : con.EndNode, 0); continue; } if (_conToNets.TryGetValue(inoutCon, out int _)) { continue; //visited } _conToNets.TryAdd(inoutCon, _networkCount); _bfsOpen.Enqueue(inoutCon); network.Add(inoutCon); } while (cons.TryGetNextValue(out inoutCon, ref it)); } }
public void Execute(int index) { Vector3 perceivedVelocity = Vector3.zero; int friendCount = 0; MobComponentData currentFrienData; NativeMultiHashMapIterator <int> frienderator = new NativeMultiHashMapIterator <int>(); bool success = friends.TryGetFirstValue(index, out currentFrienData, out frienderator); while (success) { friendCount++; float dist = Vector3.Distance(allMobs[index].Position, currentFrienData.Position); if (dist < radius) { perceivedVelocity += currentFrienData.Velocity; } success = friends.TryGetNextValue(out currentFrienData, ref frienderator); } perceivedVelocity = (friendCount > 1) ? perceivedVelocity / (friendCount) : perceivedVelocity; output[index] = new EqualizeSpeedJobOutput() { EqualizeSpeed = ((perceivedVelocity - allMobs[index].Velocity) / 8f) * scaler }; }
public void Execute() { var targets = TargetToEvent.GetKeyArray(Allocator.Temp); NativeList <PointerInputBuffer> eventList = new NativeList <PointerInputBuffer>(4, Allocator.Temp); for (int i = 0; i < targets.Length; i++) { var target = targets[i]; EventComparer eventComparer = new EventComparer(); if (TargetToEvent.TryGetFirstValue(target, out var item, out var it)) { var eventEntity = Ecb.CreateEntity(EventArchetype); Ecb.SetComponent(eventEntity, new PointerEvent { Target = target }); var buffer = Ecb.SetBuffer <PointerInputBuffer>(eventEntity); do { eventList.Add(item); } while (TargetToEvent.TryGetNextValue(out item, ref it)); eventList.Sort(eventComparer); buffer.ResizeUninitialized(eventList.Length); for (int j = 0; j < eventList.Length; j++) { buffer[j] = eventList[j]; } eventList.Clear(); eventList.Clear(); } } }
public void Execute(int index) { NativeMultiHashMapIterator <int> it; float3 nop; bool keepgoing = AgentMarkers.TryGetFirstValue(AgentData[index].ID, out nop, out it); if (!keepgoing) { return; } int totalCount = 1; while (AgentMarkers.TryGetNextValue(out nop, ref it)) { totalCount++; } Counter[index] = new Counter { Value = totalCount }; }
public bool FindMatchingStateInPlan(TStateKey stateKey, out TStateKey planStateKey) { if (PlanGraph.StateInfoLookup.ContainsKey(stateKey)) { planStateKey = stateKey; return(true); } var stateData = m_StateManager.GetStateData(stateKey, false); // todo might pass in state data from a different state manager var stateHashCode = stateKey.GetHashCode(); if (BinnedStateKeyLookup.TryGetFirstValue(stateHashCode, out planStateKey, out var iterator)) { do { var planStateData = m_StateManager.GetStateData(planStateKey, false); if (m_StateManager.Equals(planStateData, stateData)) { return(true); } } while (BinnedStateKeyLookup.TryGetNextValue(out planStateKey, ref iterator)); } return(false); }
public void Execute(Entity e, int jobIndex, ref Translation translation, ref VelocityComponent velocity, [ReadOnly] ref ProjectileComponent projectile) { if (translation.Value.y < 0.15f) { // find all the entities in the nearby quad and destroy it if within the radius int key = QuadrantSystem.GetPositionHashMapKey(translation.Value); if (QuadMap.TryGetFirstValue(key, out var data, out var it)) { do { float distance = distancesq(data.position, translation.Value); if (data.quadEntityData.type == QuadEntityType.Cavalry) { continue; } if (distance < projectile.DamageRadius) { CommandBuffer.DestroyEntity(jobIndex, data.e); } } while (QuadMap.TryGetNextValue(out data, ref it)); } CommandBuffer.DestroyEntity(jobIndex, e); } // apply gravity velocity.Value.y += -0.0098f * projectile.Weight; velocity.Value.y = clamp(velocity.Value.y, -10f, 100f); // apply air resistance velocity.Value.z += projectile.AirResistance * -0.0001f; velocity.Value.z = clamp(velocity.Value.z, 0.5f, 100f); translation.Value += velocity.Value * deltaTime; }
public static NativeArray <CollisionTriggerData>?CollectCollisionTriggerData(int frame, ref NativeMultiHashMap <Entity, CollisionTriggerData> nativeMultiHashMap, Entity e) { var count = nativeMultiHashMap.CountValuesForKey(e); NativeArray <CollisionTriggerData> collisions = new NativeArray <CollisionTriggerData>(count, Allocator.Temp); int idx = 0; if (nativeMultiHashMap.TryGetFirstValue(e, out var collInfo1, out var it)) { do { if (collInfo1.Frame < frame) { collInfo1.State = CollisionState.Exit; nativeMultiHashMap.Remove(it); } else if (collInfo1.Frame == frame) { // MBRIAU: What are we trying to clean up here? collInfo1.State = collInfo1.State == CollisionState.Stay ? CollisionState.Stay : CollisionState.Enter; } collisions[idx++] = collInfo1; }while (nativeMultiHashMap.TryGetNextValue(out collInfo1, ref it)); } return(collisions); }
private void Foreach(int key, Circle me, ref float2 avoidanceForce, ref float minTime) { if (targetMap.TryGetFirstValue(key, out EntitiesHashMap.MyData other, out NativeMultiHashMapIterator <int> iterator)) { do { if (math.lengthsq(other.position.xz - me.position) > maxTime * maxTime * 4f) { continue; } var circleOther = new Circle(other.position.xz, other.data.innerRadius, other.data2.direction.xz); var time = CalculateCirclesCollisionTime(me, circleOther); if (time <= 0 || time > maxTime) { continue; } var avoidance = CalculateCollisionAvoidance(me, circleOther, time, maxTime); if (minTime > time) { minTime = time; } avoidanceForce += avoidance; } while (targetMap.TryGetNextValue(out other, ref iterator)); } }
private void FindAttacker(int hashMapKey, float3 unitPosition, SectorEntity SectorEntity, ref Entity closestAttackerEntity, ref float closestAttackerDistance) { SectorData SectorData; NativeMultiHashMapIterator <int> nativeMultiHashMapIterator; if (SectorMultiHashMap.TryGetFirstValue(hashMapKey, out SectorData, out nativeMultiHashMapIterator)) { do { if (closestAttackerEntity == Entity.Null) { // No target closestAttackerEntity = SectorData.entity; closestAttackerDistance = math.distancesq(unitPosition, SectorData.position); } else { if (math.distancesq(unitPosition, SectorData.position) < closestAttackerDistance) { // This target is closer closestAttackerEntity = SectorData.entity; closestAttackerDistance = math.distancesq(unitPosition, SectorData.position); } } } while (SectorMultiHashMap.TryGetNextValue(out SectorData, ref nativeMultiHashMapIterator)); } }
private void Foreach(int key, QuadrantData me, ref float3 avoidanceForce, ref float3 convinientForce, ref int bros, float radius) { if (targetMap.TryGetFirstValue(key, out EntitiesHashMap.MyData other, out NativeMultiHashMapIterator <int> iterator)) { do { var direction = me.position - other.position; var distance = math.length(direction); if (me.broId == other.data2.broId && distance < 2 * radius) { convinientForce += other.data2.direction; bros++; distance *= 2f; } var distanceNormalized = (radius - distance) / (radius); if (distanceNormalized > 0f && distanceNormalized < 1f) { var dot = (math.dot(math.normalizesafe(-direction), math.normalizesafe(me.direction)) + 1f) * 0.5f; var forceMultiplyer = math.length(other.data2.direction) + 0.7f; var multiplyer = distanceNormalized * dot * forceMultiplyer; var multiplyerSin = math.sin(multiplyer * math.PI / 2f); avoidanceForce += math.normalizesafe(other.data2.direction) * multiplyerSin; avoidanceForce += direction / radius; } } while (targetMap.TryGetNextValue(out other, ref iterator)); } }
public void Execute(int index) { int squad = indices[index]; var allCnt = 0; var pausesCnt = 0; bool pause; NativeMultiHashMapIterator <int> iterator; if (squadPauses.TryGetFirstValue(squad, out pause, out iterator)) { do { if (pause) { pausesCnt++; } allCnt++; }while (squadPauses.TryGetNextValue(out pause, ref iterator)); } if ((float)pausesCnt / allCnt >= percent) { toResumeSquadsIndices.TryAdd(squad, squad); } }
/// <summary> /// /// </summary> /// <param name="h"></param> /// <param name="temp"></param> /// <returns></returns> public int GetIndex(int h, NativeStringView temp) { Assert.IsTrue(temp.Length <= kMaxCharsPerEntry); // about one printed page of text int itemIndex; NativeMultiHashMapIterator <int> iter; if (hash.TryGetFirstValue(h, out itemIndex, out iter)) { var l = length[itemIndex]; Assert.IsTrue(l <= kMaxCharsPerEntry); if (l == temp.Length) { var o = offset[itemIndex]; int matches; for (matches = 0; matches < l; ++matches) { if (temp[matches] != buffer[o + matches]) { break; } } if (matches == temp.Length) { return(itemIndex); } } } while (hash.TryGetNextValue(out itemIndex, ref iter)) { ; } return(-1); }
/// <summary> /// Update the store with the recorded BlobAsset/UnityObject associations. /// </summary> /// <remarks> /// User don't have to call this method because <see cref="Dispose"/> will do it. /// This method can be called multiple times, on the first one will matter. /// </remarks> public void UpdateBlobStore() { var keys = m_BlobPerUnityObject.GetUniqueKeyArray(Allocator.Temp); using (keys.Item1) { for (var k = 0; k < keys.Item2; ++k) { var key = keys.Item1[k]; var valueCount = m_BlobPerUnityObject.CountValuesForKey(key); var valueArray = new NativeArray <Hash128>(valueCount, Allocator.Temp); var i = 0; if (m_BlobPerUnityObject.TryGetFirstValue(key, out var value, out var iterator)) { do { valueArray[i++] = value; }while (m_BlobPerUnityObject.TryGetNextValue(out value, ref iterator)); valueArray.Sort(); } m_BlobAssetStore.UpdateBlobAssetForUnityObject <TB>(key, valueArray); valueArray.Dispose(); } } m_BlobPerUnityObject.Clear(); }
private bool Foreach(int key, float3 position, ref FightersHashMap.MyData output, bool found, Fighter me) { if (targetMap.TryGetFirstValue(key, out FightersHashMap.MyData other, out NativeMultiHashMapIterator <int> iterator)) { do { if (other.data.groupId == me.groupId) { continue; } var nowDistance = math.length(other.position - position); if (!found && nowDistance < me.viewRadius) { output = other; found = true; } else { var prevDist = math.length(output.position - position); if (prevDist > nowDistance) { output = other; } } } while (targetMap.TryGetNextValue(out other, ref iterator)); } return(found); }
public bool IsSpaceAvailableAt( NativeMultiHashMap <Entity, VehicleSegmentData> vehicleSegmentMap, Entity segmentEntity, float position, float vehicleSize ) { NativeMultiHashMapIterator <Entity> nativeMultiHashMapIterator; var vehicleFrontPos = position + vehicleSize / 2; var vehicleBackPos = vehicleFrontPos - vehicleSize; var canFit = true; if (vehicleSegmentMap.TryGetFirstValue(segmentEntity, out var segmentData, out nativeMultiHashMapIterator)) { do { if (vehicleFrontPos < segmentData.BackSegPosition) { continue; } if (vehicleBackPos > segmentData.BackSegPosition + segmentData.VehicleSize) { continue; } canFit = false; } while (vehicleSegmentMap.TryGetNextValue(out segmentData, ref nativeMultiHashMapIterator)); } return(canFit); }
public void Execute(int index) { Vector3 avoidance = Vector3.zero; MobComponentData currentFrienData; NativeMultiHashMapIterator <int> frienderator = new NativeMultiHashMapIterator <int>(); bool success = friends.TryGetFirstValue(index, out currentFrienData, out frienderator); while (success) { float dist = Vector3.Distance(allMobs[index].Position, currentFrienData.Position); if (dist > 0 && dist < radius) { Vector3 diff = Vector3.Normalize(allMobs[index].Position - currentFrienData.Position); diff = diff / dist; avoidance += diff; } success = friends.TryGetNextValue(out currentFrienData, ref frienderator); } output[index] = new PersonalSpaceJobOutput() { PersonalSpace = avoidance * scaler }; }
// パーティクル連動頂点ごと public void Execute(int index) { int vindex = vertexToParticleList[index]; if (vindex < 0) { return; } int pindex; if (vertexToParticleMap.TryGetFirstValue(vindex, out pindex, out iterator)) { // 頂点の姿勢 var pos = posList[vindex]; var rot = rotList[vindex]; // 仮想メッシュは直接スキニングするので恐らく正規化は必要ない //rot = math.normalize(rot); // 正規化しないとエラーになる場合がある do { // base pos basePosList[pindex] = pos; // base rot baseRotList[pindex] = rot; }while (vertexToParticleMap.TryGetNextValue(out pindex, ref iterator)); } }
public void Execute(int i) { NativeMultiHashMapIterator <int> hash_it; NativeMultiHashMapIterator <int> force_it; int j; Force force; int cell = hashes[i]; if (hash_map.TryGetFirstValue(cell, out j, out hash_it) && cell_forces.TryGetFirstValue(cell, out force, out force_it)) { if (i == j) { forces[i] = force; return; } while (hash_map.TryGetNextValue(out j, ref hash_it) && cell_forces.TryGetNextValue(out force, ref force_it)) { if (i == j) { forces[i] = force; return; } } } }