Exemplo n.º 1
0
 public SlopeMode GetOtherMode(SlopeMode mode)
 {
     if (mode == SlopeMode.Relaxed)
     {
         return(SlopeMode.Strict);
     }
     return(SlopeMode.Relaxed);
 }
Exemplo n.º 2
0
 private void UpdateToggle(KeyCode keyCode)
 {
     if (Input.GetKeyDown(keyCode) || Input.GetKeyUp(keyCode))
     {
         mode = config.GetOtherMode(mode);
         Apply();
     }
 }
Exemplo n.º 3
0
 private void UpdateHold(KeyCode keyCode)
 {
     if (Input.GetKeyDown(keyCode))
     {
         mode = config.GetNonDefaultMode();
         Apply();
     }
     if (Input.GetKeyUp(keyCode))
     {
         mode = config.DefaultMode;
         Apply();
     }
 }
Exemplo n.º 4
0
        private void CheckInit()
        {
            if (config == null)
            {
                return;
            }
            config = Config.Deserialize(ConfigPath);
            config.UpdateNetworkTypes();
            config.Serialize(ConfigPath);

            mode = config.DefaultMode;
            Apply();
        }
Exemplo n.º 5
0
        public float GetLimit(SlopeMode mode)
        {
            switch (mode)
            {
            case SlopeMode.Relaxed:
                return(RelaxedLimit);

            case SlopeMode.Strict:
                return(StrictLimit);

            default:
                throw new ArgumentException("Unexpected slope mode: " + mode);
            }
        }
Exemplo n.º 6
0
        // Example map Y axis (example tiles given as [id, height]
        // [5, 1]
        // [5, 1]
        // [5, 1]
        // The unoptimised renderer will render 6 triangles, while the optimised renderer only renders 2
        // triangles by "stretching" one tile across the three tiles on the Y axis.

        // Obviously, the optimised renderer performs best with large flat maps of the same terrain type.
        // The optimised renderer generally increases performance on nearly all maps, and in theory,
        // never gives worse performance than the unoptimised renderer. (most maps have at least some flat terrain of the same type)

        // Unfortunately, the optimised renderer does take longer to build the map terrain,
        // and this will probably need to be addressed when editable terrain is suported.

        // But believe me kid, it makes a difference.
        void PerformTileStretching(int x, int y, int width, bool[] shouldDrawTiles, SlopeMode[] slopes, TerrainMap map)
        {
            SlopeMode currentSlope = tileSlopeMode;
            byte      terrainId    = map[x, y].TerrainId;

            if (currentSlope == SlopeMode.Flat)
            {
                int index   = (y * width) + x;
                int stretch = 1;
                while (y < width && slopes[index] == SlopeMode.Flat && map[x, y].TerrainId == terrainId)
                {
                    // Don't set the first tile to 'don't draw'.
                    if (stretch > 1)
                    {
                        shouldDrawTiles[index] = false;
                    }
                    y++;
                    index += width;
                    stretch++;
                }
                stretchY = (stretch / 2f);
            }
        }
Exemplo n.º 7
0
        protected override void BuildTerrain(TerrainMap map, ref int totalTriangles)
        {
            verticesCount = 0;
            TileDrawInfo drawInfo = new TileDrawInfo();

            SlopeMode[] slopes = new SlopeMode[map.Width * map.Length];

            int verticesPerElement = PrimitiveElementSize;
            int lengthX            = map.Width;
            int lengthY            = map.Length;

            index = 0;

            // First pass - calculate the slope map.
            for (int y = 0; y < lengthY; y++)
            {
                for (int x = 0; x < lengthX; x++)
                {
                    Tile tile = map[x, y];
                    drawInfo.CurrentTile = tile;
                    bool leftExists   = x > 0;
                    bool behindExists = y > 0;
                    bool rightExists  = x < lengthX - 1;
                    bool frontExists  = y < lengthY - 1;

                    if (leftExists && behindExists)
                    {
                        drawInfo.LeftBehind = map[x - 1, y - 1];
                    }
                    if (leftExists && frontExists)
                    {
                        drawInfo.LeftFront = map[x - 1, y + 1];
                    }
                    if (rightExists && behindExists)
                    {
                        drawInfo.RightBehind = map[x + 1, y - 1];
                    }
                    if (rightExists && frontExists)
                    {
                        drawInfo.RightFront = map[x + 1, y + 1];
                    }

                    if (leftExists)
                    {
                        drawInfo.Left = map[x - 1, y];
                    }
                    if (behindExists)
                    {
                        drawInfo.Behind = map[x, y - 1];
                    }
                    if (rightExists)
                    {
                        drawInfo.Right = map[x + 1, y];
                    }
                    if (frontExists)
                    {
                        drawInfo.Front = map[x, y + 1];
                    }

                    slopes[(y * map.Width) + x] = CalculateSlope(drawInfo);
                }
            }

            int width = map.Width;

            // Second pass - actually render the tile
            bool[] shouldDrawTiles = new bool[map.Width * map.Length];
            for (int i = 0; i < shouldDrawTiles.Length; i++)
            {
                shouldDrawTiles[i] = true;
            }

            for (int y = 0; y < lengthY; y++)
            {
                for (int x = 0; x < lengthX; x++)
                {
                    Tile tile = map[x, y];
                    drawInfo.CurrentTile = tile;
                    int arrayIndex = (y * width) + x;
                    tileSlopeMode = slopes[arrayIndex];
                    stretchY      = 1;
                    if (shouldDrawTiles[arrayIndex])
                    {
                        PerformTileStretching(x, y, width, shouldDrawTiles, slopes, map);
                        RenderTile(drawInfo, index);
                        verticesCount += verticesPerElement;
                        index         += verticesPerElement;
                    }
                }
            }
            totalTriangles += drawInfo.TotalTriangles;
        }