public void Execute(int index) { BioClouds.CloudData currentCloudData = CloudData[index]; float3 currentCellPosition; int desiredCellQnt = 0; int cellCount = 0; NativeMultiHashMapIterator <int> it; bool keepgoing = CloudMarkersMap.TryGetFirstValue(currentCloudData.ID, out currentCellPosition, out it); if (!keepgoing) { return; } //Debug.Log("DESIRED1"); cellCount++; if (CheckDesiredPosition(currentCellPosition)) { desiredCellQnt++; } while (CloudMarkersMap.TryGetNextValue(out currentCellPosition, ref it)) { cellCount++; if (CheckDesiredPosition(currentCellPosition)) { desiredCellQnt++; } } float cloudDensity; if (cloudDensities.TryGetValue(currentCloudData.ID, out cloudDensity)) { //Debug.Log("DESIRED2"); //Debug.Log(cloudDensity); int agentQuantity = (int)(desiredCellQnt * cloudDensity * BioClouds.Parameters.Instance.CellArea); desiredQuantity.TryAdd(currentCloudData.ID, agentQuantity); } }
//Index = per cloud public void Execute(int index) { float3 currentCellPosition; int cellCount = 0; NativeMultiHashMapIterator <int> it; if (!CloudMarkersMap.TryGetFirstValue(CloudData[index].ID, out currentCellPosition, out it)) { return; } cellCount++; while (CloudMarkersMap.TryGetNextValue(out currentCellPosition, ref it)) { cellCount++; } float totalArea = cellCount * CellArea; CloudData cData = CloudData[index]; float delta = cData.AgentQuantity / totalArea; Color densityColor = Parameters.Density2Color(delta, CloudData[index].ID); if (!CloudMarkersMap.TryGetFirstValue(CloudData[index].ID, out currentCellPosition, out it)) { return; } int2 grid_cell = GridConverter.PositionToGridCell(new float3(currentCellPosition.x, currentCellPosition.y, currentCellPosition.z)); tex_mat[grid_cell.y * mat_rows + grid_cell.x] = densityColor; cloudDensities.TryAdd(CloudData[index].ID, delta); while (CloudMarkersMap.TryGetNextValue(out currentCellPosition, ref it)) { grid_cell = GridConverter.PositionToGridCell(new float3(currentCellPosition.x, currentCellPosition.y, currentCellPosition.z)); tex_mat[grid_cell.y * mat_rows + grid_cell.x] = densityColor; } }
public void Execute(int index) { float3 currentCellPosition; int cellCount = 0; NativeMultiHashMapIterator <int> it; bool keepgoing = CloudMarkersMap.TryGetFirstValue(CloudData[index].ID, out currentCellPosition, out it); if (!keepgoing) { return; } cellCount++; while (CloudMarkersMap.TryGetNextValue(out currentCellPosition, ref it)) { cellCount++; } float totalArea = cellCount * CellArea; CloudData cData = CloudData[index]; float delta = cData.AgentQuantity / totalArea; float beta = math.min((math.pow(delta, 2f) / math.pow(cData.PreferredDensity, 2f)), 2f); beta = beta - 1.0f; float maxChange = cData.MaxSpeed; float radiusChange = math.max(-maxChange, (math.min(maxChange, cData.RadiusChangeSpeed * (beta) * cData.Radius))); cData.Radius += radiusChange; CloudData[index] = cData; }
public void Execute(int index) { CloudData currentCloudData = CloudData[index]; CloudGoal currentCloudGoal = CloudGoal[index]; Position currentCloudPosition = Position[index]; int[] desiredCells = GridConverter.RadiusInGrid(currentCloudPosition.Value, currentCloudData.Radius); float3 desiredSum = float3.zero; for (int i = 0; i < desiredCells.Length; i++) { float3 partial; if (cellid2pos.TryGetValue(desiredCells[i], out partial)) { var s = math.length(partial - currentCloudPosition.Value); if (s <= currentCloudData.Radius) { desiredSum += (math.normalize(partial - currentCloudPosition.Value)) * (currentCloudData.Radius - s); } } } float3 currentCellPosition; int cellCount = 0; NativeMultiHashMapIterator <int> it; float3 posSum = float3.zero; bool keepgoing = CloudMarkersMap.TryGetFirstValue(currentCloudData.ID, out currentCellPosition, out it); if (!keepgoing) { return; } cellCount++; var t = math.length(currentCellPosition - currentCloudPosition.Value); posSum += (math.normalize(currentCellPosition - currentCloudPosition.Value)) * (currentCloudData.Radius - t); bool right_desempate = false; if (!right_desempate && math.cross(currentCloudPosition.Value, currentCellPosition - currentCloudPosition.Value).z < 0) { extraWeightCellId.TryAdd(currentCloudData.ID, GridConverter.Position2CellID(currentCellPosition)); right_desempate = true; } while (CloudMarkersMap.TryGetNextValue(out currentCellPosition, ref it)) { cellCount++; t = math.length(currentCellPosition - currentCloudPosition.Value); if (t <= currentCloudData.Radius) { posSum += (math.normalize(currentCellPosition - currentCloudPosition.Value)) * (currentCloudData.Radius - t); } if (!right_desempate && math.cross(currentCloudPosition.Value, currentCellPosition - currentCloudPosition.Value).z < 0) { extraWeightCellId.TryAdd(currentCloudData.ID, GridConverter.Position2CellID(currentCellPosition)); right_desempate = true; } } sumVec[index] = posSum; dessumVec[index] = desiredSum; dotVec[index] = math.dot((CloudGoal[index].SubGoal - currentCloudPosition.Value), posSum - desiredSum); }
private void SplitCloud(int index) { var cell_map = bioClouds.created_cell_ids; Debug.Log("Split cloud"); CloudData data = m_CloudGroup.CloudData[index]; CloudSplitData fatherData = m_CloudGroup.CloudSplitData[index]; float3 basePosition = m_CloudGroup.Position[index].Value; float3 offset; float slice = (360.0f / (float)(divisions)); int total_agents = data.AgentQuantity; int agents_slice = Mathf.CeilToInt(data.AgentQuantity / (divisions + 1)); for (int i = 0; i <= divisions; i++) { if (total_agents <= 0) { break; } offset.x = math.cos(math.radians(((slice * (i)) + (slice / 2f)))); offset.y = math.sin(math.radians(((slice * (i)) + (slice / 2f)))); offset.z = 0f; offset *= (m_CloudGroup.CloudData[index].Radius * spawnDistanceFromRadius); CloudLateSpawn lateSpawn = new CloudLateSpawn(); lateSpawn.agentQuantity = math.min(agents_slice, total_agents); if (i == divisions) { lateSpawn.position = basePosition; } else { lateSpawn.position = basePosition + offset; } //if (!cell_map.Contains(GridConverter.Position2CellID(lateSpawn.position))) // continue; if (i == divisions) { lateSpawn.agentQuantity += data.AgentQuantity % (divisions + 1); } total_agents -= lateSpawn.agentQuantity; lateSpawn.goal = m_CloudGroup.CloudGoal[index].EndGoal; lateSpawn.cloudType = data.Type; lateSpawn.preferredDensity = data.PreferredDensity; lateSpawn.radiusChangeSpeed = data.RadiusChangeSpeed; lateSpawn.splitCount = m_CloudGroup.CloudSplitData[index].splitCount + 1; lateSpawn.fatherID = data.ID; lateSpawn.radiusMultiplier = radiusMultiplier; //if (total_agents != 0 && i == divisions) // lateSpawn.agentQuantity += total_agents; bioClouds.cloudLateSpawns.Add(lateSpawn); } bioClouds.entitiesToDestroy.Add(m_CloudGroup.Entities[index]); }