private bool DecideSplit(int index)
        {
            float3 future_position = m_CloudGroup.Position[index].Value + m_CloudGroup.CloudStep[index].Delta * framesForward;

            var future_cells  = GridConverter.RadiusInGrid(future_position, m_CloudGroup.CloudData[index].Radius);
            var current_cells = GridConverter.RadiusInGrid(m_CloudGroup.Position[index].Value, m_CloudGroup.CloudData[index].Radius);

            int avaiable_future_cells  = 0;
            int avaiable_current_cells = 0;
            var cell_map = m_CellMarks.Cell2OwningCloud;


            foreach (int cell_id in current_cells)
            {
                //if avaiable, test if id is different.
                if (!(cell_map.TryGetValue(cell_id, out int result) && result == m_CloudGroup.CloudData[index].ID) && bioClouds.created_cell_ids.Contains(cell_id))
                {
                    avaiable_current_cells++;
                }
            }

            foreach (int cell_id in future_cells)
            {
                //if avaiable, test if id is different.
                if (!(cell_map.TryGetValue(cell_id, out int result) && result == m_CloudGroup.CloudData[index].ID) && bioClouds.created_cell_ids.Contains(cell_id))
                {
                    avaiable_future_cells++;
                }
            }

            return((avaiable_future_cells / avaiable_current_cells) < split_threshold);
        }
예제 #2
0
            public void Execute(int index)
            {
                var celllist = GridConverter.RadiusInGrid(Position[index].Value, CloudData[index].Radius);

                var cloudId = CloudData[index].ID;

                tagQuantity[index] = celllist.Length;
                cloudPos.TryAdd(CloudData[index].ID, new CloudIDPosRadius()
                {
                    position = Position[index].Value, ID = CloudData[index].ID, Radius = CloudData[index].Radius, MinRadius = CloudData[index].MinRadius
                });

                foreach (int i in celllist)
                {
                    if (cellIDmap.TryGetValue(i, out float3 cellPos))
                    {
                        if (math.distance(cellPos, Position[index].Value) >= CloudData[index].Radius)
                        {
                            continue;
                        }
                    }
                    cellTagMap.Add(i, cloudId);
                }
            }
            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);
            }