Пример #1
0
        private Vector3I?GetCubeFromBone(Vector3I bone, MyCubeGrid grid)
        {
            Vector3I result = Vector3I.Zero;

            result = bone / 2;

            if (grid.CubeExists(result))
            {
                return(result);
            }

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    for (int k = -1; k <= 1; k++)
                    {
                        Vector3I current = result + new Vector3I(i, j, k);
                        Vector3I test    = bone - current * 2;

                        if (test.X > 2 || test.Y > 2 || test.Z > 2)
                        {
                            continue;
                        }

                        if (grid.CubeExists(current))
                        {
                            return(current);
                        }
                    }
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Gets all cubes which are affected by bone.
        /// </summary>
        /// <param name="onlyExisting">Returns only cubes which were added to skeleton.</param>
        public void GetAffectedCubes(Vector3I cube, Vector3I boneOffset, List <Vector3I> resultList, MyCubeGrid grid)
        {
            Debug.Assert(BoneDensity == 2, "This algorithm requires BoneDensity to be 2");

            Vector3I dist = boneOffset - Vector3I.One;
            Vector3I sign = Vector3I.Sign(dist);

            dist *= sign;

            Vector3I offset;

            for (offset.X = 0; offset.X <= dist.X; offset.X++)
            {
                for (offset.Y = 0; offset.Y <= dist.Y; offset.Y++)
                {
                    for (offset.Z = 0; offset.Z <= dist.Z; offset.Z++)
                    {
                        var targetCube = cube + offset * sign;
                        if (grid.CubeExists(targetCube))
                        {
                            resultList.Add(targetCube);
                        }
                    }
                }
            }
        }
Пример #3
0
        public void RemoveUnusedBones(MyCubeGrid grid)
        {
            ProfilerShort.Begin("RemoveUnusedBones");
            if (m_tmpRemovedCubes.Count != 0)
            {
                Debug.Assert(m_testedCubes.Count == 0);
                Debug.Assert(m_usedBones.Count == 0);

                foreach (var cube in m_tmpRemovedCubes)
                {
                    if (grid.CubeExists(cube))
                    {
                        if (!m_testedCubes.Contains(cube))
                        {
                            m_testedCubes.Add(cube);
                            AddUsedBones(cube);
                        }
                        continue;
                    }

                    Vector3I centerBonePos = cube * BoneDensity + Vector3I.One;
                    Vector3I dir, neighbor;

                    // Iterate over all the neighbors of the cube and check whether they are present in the grid
                    for (int x = -1; x <= 1; ++x) 
                        for (int y = -1; y <= 1; ++y)
                            for (int z = -1; z <= 1; ++z)
                            {
                                dir.X = x;
                                dir.Y = y;
                                dir.Z = z;
                                neighbor = cube + dir;

                                if (grid.CubeExists(neighbor) && !m_testedCubes.Contains(neighbor))
                                {
                                    m_testedCubes.Add(neighbor);
                                    AddUsedBones(neighbor);
                                }
                            }
                }

                foreach (var cube in m_tmpRemovedCubes)
                {
                    Vector3I pos = cube * BoneDensity;
                    for (int x = 0; x <= BoneDensity; ++x)
                    {
                        for (int y = 0; y <= BoneDensity; ++y)
                        {
                            for (int z = 0; z <= BoneDensity; ++z)
                            {
                                if (!m_usedBones.Contains(pos)) ClearBone(ref pos);

                                pos.Z++;
                            }
                            pos.Y++;
                            pos.Z -= BoneDensity + 1;
                        }
                        pos.X++;
                        pos.Y -= BoneDensity + 1;
                    }
                }

                m_testedCubes.Clear();
                m_usedBones.Clear();
                m_tmpRemovedCubes.Clear();
            }
            ProfilerShort.End();
        }
Пример #4
0
        /// <summary>
        /// Gets all cubes which are affected by bone.
        /// </summary>
        /// <param name="onlyExisting">Returns only cubes which were added to skeleton.</param>
        public void GetAffectedCubes(Vector3I cube, Vector3I boneOffset, List<Vector3I> resultList, MyCubeGrid grid)
        {
            Debug.Assert(BoneDensity == 2, "This algorithm requires BoneDensity to be 2");

            Vector3I dist = boneOffset - Vector3I.One;
            Vector3I sign = Vector3I.Sign(dist);
            dist *= sign;

            Vector3I offset;
            for (offset.X = 0; offset.X <= dist.X; offset.X++)
            {
                for (offset.Y = 0; offset.Y <= dist.Y; offset.Y++)
                {
                    for (offset.Z = 0; offset.Z <= dist.Z; offset.Z++)
                    {
                        var targetCube = cube + offset * sign;
                        if (grid.CubeExists(targetCube)) resultList.Add(targetCube);
                    }
                }
            }
        }
Пример #5
0
        private Vector3I? GetCubeFromBone(Vector3I bone, MyCubeGrid grid)
        {
            Vector3I result = Vector3I.Zero;
            result = bone / 2;

            if (grid.CubeExists(result))
            {
                return result;
            }

            for (int i = -1; i <= 1; i++)
                for (int j = -1; j <=1; j++)
                    for (int k = -1; k <= 1; k++)
                    {
                        Vector3I current = result + new Vector3I(i, j, k);
                        Vector3I test = bone - current * 2;

                        if (test.X > 2 || test.Y > 2 || test.Z > 2)
                            continue;

                        if (grid.CubeExists(current))
                        {
                            return current;
                        }
                    }

            return null;
        }
Пример #6
0
        public void RemoveUnusedBones(MyCubeGrid grid)
        {
            ProfilerShort.Begin("RemoveUnusedBones");
            if (m_tmpRemovedCubes.Count() != 0)
            {
                Debug.Assert(m_testedCubes.Count() == 0);
                Debug.Assert(m_usedBones.Count() == 0);

                foreach (var cube in m_tmpRemovedCubes)
                {
                    if (grid.CubeExists(cube))
                    {
                        if (!m_testedCubes.Contains(cube))
                        {
                            m_testedCubes.Add(cube);
                            AddUsedBones(cube);
                        }
                        continue;
                    }

                    Vector3I centerBonePos = cube * BoneDensity + Vector3I.One;
                    Vector3I dir, neighbor;

                    // Iterate over all the neighbors of the cube and check whether they are present in the grid
                    for (int x = -1; x <= 1; ++x)
                    {
                        for (int y = -1; y <= 1; ++y)
                        {
                            for (int z = -1; z <= 1; ++z)
                            {
                                dir.X    = x;
                                dir.Y    = y;
                                dir.Z    = z;
                                neighbor = cube + dir;

                                if (grid.CubeExists(neighbor) && !m_testedCubes.Contains(neighbor))
                                {
                                    m_testedCubes.Add(neighbor);
                                    AddUsedBones(neighbor);
                                }
                            }
                        }
                    }
                }

                foreach (var cube in m_tmpRemovedCubes)
                {
                    Vector3I pos = cube * BoneDensity;
                    for (int x = 0; x <= BoneDensity; ++x)
                    {
                        for (int y = 0; y <= BoneDensity; ++y)
                        {
                            for (int z = 0; z <= BoneDensity; ++z)
                            {
                                if (!m_usedBones.Contains(pos))
                                {
                                    ClearBone(ref pos);
                                }

                                pos.Z++;
                            }
                            pos.Y++;
                            pos.Z -= BoneDensity + 1;
                        }
                        pos.X++;
                        pos.Y -= BoneDensity + 1;
                    }
                }

                m_testedCubes.Clear();
                m_usedBones.Clear();
                m_tmpRemovedCubes.Clear();
            }
            ProfilerShort.End();
        }