Ejemplo n.º 1
0
        private void DrawMapRect(MapRect mapRect, Color color)
        {
            Vector3 p1 = m_voxelMap.GetWorldPosition(mapRect.P0, GameConstants.MinVoxelActorWeight, MapPos.Align.Minus, MapPos.Align.Minus);
            Vector3 p2 = m_voxelMap.GetWorldPosition(mapRect.P3, GameConstants.MinVoxelActorWeight, MapPos.Align.Minus, MapPos.Align.Plus);
            Vector3 p3 = m_voxelMap.GetWorldPosition(mapRect.P1, GameConstants.MinVoxelActorWeight, MapPos.Align.Plus, MapPos.Align.Plus);
            Vector3 p4 = m_voxelMap.GetWorldPosition(mapRect.P2, GameConstants.MinVoxelActorWeight, MapPos.Align.Plus, MapPos.Align.Minus);

            p1.y = p2.y = p3.y = p4.y = p4.y + GameConstants.UnitSize;

            GL.PushMatrix();

            m_debugMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            GL.Color(color);

            GL.Vertex(p1);
            GL.Vertex(p2);

            GL.Vertex(p2);
            GL.Vertex(p3);

            GL.Vertex(p3);
            GL.Vertex(p4);

            GL.Vertex(p4);
            GL.Vertex(p1);

            GL.End();

            GL.PopMatrix();
        }
Ejemplo n.º 2
0
        public void Draw(int cullingMask)
        {
            MapRect mapBounds = m_voxelMap.MapBounds;

            int     size    = m_voxelMap.Map.GetMapSizeWith(GameConstants.MinVoxelActorWeight);
            MapRect mapRect = new MapRect(0, 0, size, size);

            MapRect padRect = new MapRect(m_voxelMap.MapBoundsPadding, m_voxelMap.MapBoundsPadding, size - m_voxelMap.MapBoundsPadding * 2, size - m_voxelMap.MapBoundsPadding * 2);

            DrawMapRect(mapBounds, Color.gray);
            DrawMapRect(mapRect, Color.white);
            DrawMapRect(padRect, Color.red);
        }
Ejemplo n.º 3
0
        private void Awake()
        {
            m_gameState    = Dependencies.GameState;
            m_settings     = Dependencies.Settings;
            m_inputManager = Dependencies.InputManager;
            m_voxelMap     = Dependencies.Map;

            MapRect rect = m_voxelMap.MapBounds;
            Vector3 p0   = m_voxelMap.GetWorldPosition(rect.P0, GameConstants.MinVoxelActorWeight);
            Vector3 p1   = m_voxelMap.GetWorldPosition(rect.P1, GameConstants.MinVoxelActorWeight);

            m_allowedRadius = (p1 - p0).magnitude / 2.0f;
            m_boundsCenter  = p0 + (p1 - p0) / 2.0f;
        }
Ejemplo n.º 4
0
        private IEnumerator Fit()
        {
            yield return(new WaitForEndOfFrame());

            CalculateRootRadius();

            float offset = m_rootRadius - m_rootRadius * Mathf.Sqrt(2.0f) / 2.0f;

            Rect mapBoundsRect = m_rtMapBounds.rect;

            mapBoundsRect.width  -= 2 * offset;
            mapBoundsRect.height -= 2 * offset;

            float mapSize = mapBoundsRect.width;

            MapRect mapBounds     = m_voxelMap.MapBounds;
            int     size          = Mathf.Max(mapBounds.RowsCount, mapBounds.ColsCount);
            float   pixelsPerUnit = mapSize / size;

            float mapBoundsWidth  = mapBounds.ColsCount * pixelsPerUnit;
            float mapBoundsHeight = mapBounds.RowsCount * pixelsPerUnit;

            Vector3 mapBoundsTopLeft     = new Vector3(mapBounds.Col * pixelsPerUnit, mapBounds.Row * pixelsPerUnit, 0);
            Vector3 mapBoundsBottomRight = mapBoundsTopLeft + new Vector3(mapBoundsWidth, mapBoundsHeight);


            float   scaledMapSize = m_voxelMap.Map.GetMapSizeWith(GameConstants.MinVoxelActorWeight) * pixelsPerUnit;
            Vector3 offsetMin     = -mapBoundsTopLeft + new Vector3(offset, offset, 0);
            Vector3 offsetMax     = new Vector3(scaledMapSize - mapBoundsBottomRight.x, scaledMapSize - mapBoundsBottomRight.y, 0) - new Vector3(offset, offset, 0);

            RectTransform rtFogOfWar = m_fogOfWar.GetComponent <RectTransform>();

            rtFogOfWar.offsetMin = offsetMin;
            rtFogOfWar.offsetMax = offsetMax;

            RectTransform rtForeground = m_foreground.GetComponent <RectTransform>();

            rtForeground.offsetMin = offsetMin;
            rtForeground.offsetMax = offsetMax;

            RectTransform rtBackground = m_background.GetComponent <RectTransform>();

            rtBackground.offsetMin = offsetMin;
            rtBackground.offsetMax = offsetMax;

            ProjectCamera(m_rtMapBounds.rotation);
        }
Ejemplo n.º 5
0
        private void CreateTextures()
        {
            int size = m_voxelMap.Map.GetMapSizeWith(0);

            m_bounds = new MapRect(0, 0, m_voxelMap.Map.GetMapSizeWith(2), m_voxelMap.Map.GetMapSizeWith(2));

            int toZeroWeight = (1 << GameConstants.MinVoxelActorWeight);

            m_bounds.ColsCount *= toZeroWeight;
            m_bounds.RowsCount *= toZeroWeight;
            m_bounds.Col       *= toZeroWeight;
            m_bounds.Row       *= toZeroWeight;

            float centerRow  = m_bounds.Row + m_bounds.RowsCount / 2.0f;
            float centerCol  = m_bounds.Col + m_bounds.ColsCount / 2.0f;
            int   boundsSize = Mathf.Max(m_bounds.ColsCount, m_bounds.RowsCount);

            Vector2 p0 = new Vector2(Mathf.Max(0, centerRow - boundsSize / 2.0f), Mathf.Max(0, centerCol - boundsSize / 2.0f));
            Vector2 p1 = new Vector2(Mathf.Min(size, centerRow + boundsSize / 2.0f), Mathf.Min(size, centerCol + boundsSize / 2.0f));

            p0.x = Mathf.FloorToInt((p0.x) / toZeroWeight) * toZeroWeight;
            p0.y = Mathf.FloorToInt((p0.y) / toZeroWeight) * toZeroWeight;

            p1.x = Mathf.CeilToInt((p1.x) / toZeroWeight) * toZeroWeight;
            p1.y = Mathf.CeilToInt((p1.y) / toZeroWeight) * toZeroWeight;

            m_bounds.Row = (int)p0.x;
            m_bounds.Col = (int)p0.y;

            m_bounds.RowsCount = (int)(p1.x - p0.x);
            m_bounds.ColsCount = (int)(p1.y - p0.y);
            boundsSize         = Mathf.Max(m_bounds.ColsCount, m_bounds.RowsCount);
            m_bounds.RowsCount = boundsSize;
            m_bounds.ColsCount = boundsSize;

            size    = boundsSize;
            m_scale = Mathf.Max(m_desiredResolution / size, 1);
            size   *= m_scale;

            CalculateStaticMapHeight();
            m_bgTexture = CreateTexture(size, m_skyColor, out m_bgColors);
            m_fgTexture = CreateTexture(size, new Color(1, 1, 1, 0), out m_fgColors);

            int playersCount = m_gameState.PlayersCount;

            m_fogOfWarTextures = CreateTexture(size, m_fogOfWarColor, playersCount, out m_fogOfWarColors);

            BeginUpdate();
            m_updateRequired = true;

            Draw(m_voxelMap.Map.Root, new Coordinate(0, 0, 0, m_voxelMap.Map.Weight), m_bgColors, size, cell => cell.First.GetLastStatic(), data => m_groundBaseColor);
            Draw(m_voxelMap.Map.Root, new Coordinate(0, 0, 0, m_voxelMap.Map.Weight), m_fgColors, size,
                 cell => GetLast(cell),
                 data => m_materialCache.GetPrimaryColor(data.Owner));

            m_voxelMap.Map.ForEach((cell, pos, weight) =>
            {
                for (int i = 0; i < cell.ObservedBy.Length; ++i)
                {
                    if (cell.ObservedBy[i] > 0)
                    {
                        Color32[] fogOfWarColors = m_fogOfWarColors[i];
                        if (fogOfWarColors != null)
                        {
                            Fill(fogOfWarColors, new Coordinate(pos, weight, 0), m_transparentColor);
                        }
                    }
                }
            });

            m_bgTexture.SetPixels32(m_bgColors);
            m_bgTexture.Apply();

            EndUpdate();
        }
Ejemplo n.º 6
0
        private void CalculateBounds()
        {
            int weight = GameConstants.MinVoxelActorWeight;
            int size   = m_map.GetMapSizeWith(weight);

            Debug.Assert(size >= m_minMapBoundsSize, "map size < m_minMapBoundsSize");

            MapPos min = new MapPos(0, 0);
            MapPos max = new MapPos(size - 1, size - 1);

            MapCell col0 = m_map.Get(0, 0, weight);

            for (int row = 0; row < size; ++row)
            {
                MapCell cell     = col0;
                bool    nonEmpty = false;
                for (int col = 0; col < size; ++col)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPCol;
                }

                if (nonEmpty)
                {
                    min.Row = row;
                    break;
                }
                else
                {
                    min.Row = row;
                }

                col0 = col0.SiblingPRow;
            }

            col0 = m_map.Get(size - 1, 0, weight);
            for (int row = size - 1; row >= 0; --row)
            {
                MapCell cell     = col0;
                bool    nonEmpty = false;
                for (int col = 0; col < size; ++col)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPCol;
                }

                if (nonEmpty)
                {
                    max.Row = row;
                    break;
                }
                else
                {
                    max.Row = row;
                }

                col0 = col0.SiblingMRow;
            }

            MapCell row0 = m_map.Get(0, 0, weight);

            for (int col = 0; col < size; ++col)
            {
                MapCell cell     = row0;
                bool    nonEmpty = false;
                for (int row = 0; row < size; ++row)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPRow;
                }

                if (nonEmpty)
                {
                    min.Col = col;
                    break;
                }
                else
                {
                    min.Col = col;
                }

                row0 = row0.SiblingPCol;
            }

            row0 = m_map.Get(0, size - 1, weight);
            for (int col = size - 1; col >= 0; --col)
            {
                MapCell cell     = row0;
                bool    nonEmpty = false;
                for (int row = 0; row < size; ++row)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPRow;
                }

                if (nonEmpty)
                {
                    max.Col = col;
                    break;
                }
                else
                {
                    max.Col = col;
                }

                row0 = row0.SiblingMCol;
            }

            if (min.Col > max.Col)
            {
                min.Col = max.Col;
            }

            if (min.Row > max.Row)
            {
                min.Row = max.Row;
            }

            int centerCol = min.Col + (max.Col - min.Col) / 2 + 1;
            int centerRow = min.Row + (max.Row - min.Row) / 2 + 1;

            int minCol = Mathf.Max(0, centerCol - m_minMapBoundsSize / 2);
            int minRow = Mathf.Max(0, centerRow - m_minMapBoundsSize / 2);

            int maxCol = minCol + (m_minMapBoundsSize - 1);
            int maxRow = minRow + (m_minMapBoundsSize - 1);

            if (maxCol >= size)
            {
                maxCol = size - 1;
                minCol = maxCol - (m_minMapBoundsSize - 1);
            }

            if (maxRow >= size)
            {
                maxRow = size - 1;
                minRow = maxRow - (m_minMapBoundsSize - 1);
            }

            if (minCol < min.Col)
            {
                min.Col = minCol;
            }
            if (minRow < min.Row)
            {
                min.Row = minRow;
            }
            if (maxCol > max.Col)
            {
                max.Col = maxCol;
            }
            if (maxRow > max.Row)
            {
                max.Row = maxRow;
            }

            Debug.Assert(min.Col >= m_mapBoundsPadding, "min.Col < m_mapBoundsPadding");
            Debug.Assert(min.Row >= m_mapBoundsPadding, "min.Row < m_mapBoundsPadding");
            Debug.Assert(max.Col < size - m_mapBoundsPadding, "min.Col >= m_mapBoundsPadding");
            Debug.Assert(max.Row < size - m_mapBoundsPadding, "min.Row >= m_mapBoundsPadding");

            m_mapBounds = new MapRect(min, max);
        }