示例#1
0
        tile FragmentShader(VertexOut vertex, Field <tile> Tiles, Field <data> Select, Field <vec4> Random, [TileType.Vals] float type)
        {
            tile here   = Tiles[Here];
            data select = Select[Here];
            vec4 rndv   = Random[Here];

            float rnd = rndv.x * rndv.x * rndv.x * rndv.x;

            if (Something(select))
            {
                here.type = type;

                if (type == TileType.Grass)
                {
                    here.i = RndFint(rnd, _0, _6); here.j = _31;
                }
                else if (type == TileType.Dirt)
                {
                    here.i = RndFint(rnd, _0, _9); here.j = _30;
                }
                else if (type == TileType.Trees)
                {
                    here.i = _0; here.j = _25;
                }
            }

            return(here);
        }
示例#2
0
        tile FragmentShader(VertexOut vertex, Field <tile> Tiles, Field <data> Select)
        {
            tile here   = Tiles[Here];
            data select = Select[Here];

            tile
                right      = Tiles[RightOne],
                up         = Tiles[UpOne],
                left       = Tiles[LeftOne],
                down       = Tiles[DownOne],
                up_right   = Tiles[UpRight],
                up_left    = Tiles[UpLeft],
                down_right = Tiles[DownRight],
                down_left  = Tiles[DownLeft];

            if (here.type == TileType.Dirt)
            {
                DirtGrassInterface(ref here, ref right, ref up, ref left, ref down, ref up_right, ref up_left, ref down_right, ref down_left);
            }
            else if (here.type == TileType.Grass || here.type == TileType.Trees)
            {
                GrassTreeInterface(ref here, ref right, ref up, ref left, ref down, ref up_right, ref up_left, ref down_right, ref down_left);
            }

            return(here);
        }
示例#3
0
        protected color Sprite(tile c, vec2 pos, PointSampler Texture, bool solid_blend_flag, float solid_blend)
        {
            color clr = color.TransparentBlack;

            if (pos.x > 1 || pos.y > 1 || pos.x < 0 || pos.y < 0)
            {
                return(clr);
            }

            pos = pos * .98f + vec(.01f, .01f);

            pos.x += Float(c.i);
            pos.y += Float(c.j);
            pos   *= TileSpriteSheet.SpriteSize;

            clr = Texture[pos];

            if (solid_blend_flag)
            {
                color solid_clr = FarColor[Int(c.type), 6 + (int)(c.type)];
                clr = solid_blend * clr + (1 - solid_blend) * solid_clr;
            }

            return(clr);
        }
示例#4
0
        tile FragmentShader(VertexOut vertex, Field <tile> Tiles, Field <geo> Geo)
        {
            tile tile_here = Tiles[Here];
            geo  geo_here  = Geo[Here];

            if (IsValid(geo_here.dir))
            {
                tile_here.type = TileType.Trees;
            }

            return(tile_here);
        }
示例#5
0
        color FragmentShader(VertexOut vertex, Field <tile> Tiles, PointSampler Texture,
                             [Vals.Bool] bool solid_blend_flag, float solid_blend)
        {
            color output = color.TransparentBlack;

            vec2 subcell_pos = get_subcell_pos(vertex, Tiles.Size);

            tile here = tile.Nothing;

            here.i    = _0;
            here.j    = _25;
            here.type = TileType.Trees;

            output += Sprite(here, subcell_pos, Texture, solid_blend_flag, solid_blend);

            return(output);
        }
示例#6
0
        data FragmentShader(VertexOut vertex, Field <tile> Tiles, Field <unit> Units, Field <data> Data)
        {
            tile tile_here = Tiles[Here];
            unit unit_here = Units[Here];
            data data_here = Data[Here];

            if (IsBlockingTile(tile_here))
            {
                data_here           = data.Nothing;
                data_here.direction = Dir.Stationary;
            }
            else
            {
                if (BlockingTileHere(unit_here))
                {
                    data_here = data.Nothing;
                }
            }

            return(data_here);
        }
示例#7
0
        color FragmentShader(VertexOut vertex, Field <tile> Tiles, PointSampler Texture, [Vals.Bool] bool draw_grid,
                             [Vals.Bool] bool solid_blend_flag, float solid_blend)
        {
            color output = color.TransparentBlack;

            tile here = Tiles[Here];

            vec2 subcell_pos = get_subcell_pos(vertex, Tiles.Size);

            if (here.type > _0)
            {
                output += Sprite(here, subcell_pos, Texture, solid_blend_flag, solid_blend);

                if (draw_grid)
                {
                    output += GridLines(subcell_pos);
                }
            }

            return(output);
        }
示例#8
0
        unit FragmentShader(VertexOut vertex, Field <tile> Tiles, Field <unit> Units)
        {
            tile tile_here = Tiles[Here];
            unit unit_here = Units[Here];

            if (IsBlockingTile(tile_here))
            {
                unit_here.type   = UnitType.BlockingTile;
                unit_here.player = Player.None;
                unit_here.team   = Team.None;
            }
            else
            {
                if (BlockingTileHere(unit_here))
                {
                    unit_here.type   = UnitType.None;
                    unit_here.player = Player.None;
                    unit_here.team   = Team.None;
                }
            }

            return(unit_here);
        }
示例#9
0
 protected static bool IsBlockingTile(tile t)
 {
     return(t.type >= TileType.FirstBlockingTileType ||
            t.type == TileType.Grass && t.j != _31);
 }
示例#10
0
        void GrassTreeInterface(ref tile here, ref tile right, ref tile up, ref tile left, ref tile down, ref tile up_right, ref tile up_left, ref tile down_right, ref tile down_left)
        {
            if (here.type == TileType.Trees)
            {
                // If this is a tree with trees on both sides of it
                if (left.type == TileType.Trees && right.type == TileType.Trees ||
                    up_left.type == TileType.Trees && up_right.type == TileType.Trees)
                {
                    // If there is a full row of 3 trees underneath this tree, then this is a "full" center tree tile
                    if (up_left.type == TileType.Trees && up.type == TileType.Trees && up_right.type == TileType.Trees)
                    {
                        here.type = TileType.Trees;
                        here.i    = _0;
                        here.j    = _25;
                    }

                    // otherwise if we at least have a tree directly beneath us, there are 3 possibilities (missing left, missing right, or both)
                    else if (up_left.type != TileType.Trees && up.type == TileType.Trees && up_right.type == TileType.Trees)
                    {
                        here.type = TileType.Trees;
                        here.i    = _0;
                        here.j    = _22;
                    }

                    else if (up_left.type == TileType.Trees && up.type == TileType.Trees && up_right.type != TileType.Trees)
                    {
                        here.type = TileType.Trees;
                        here.i    = _3;
                        here.j    = _22;
                    }

                    else if (up_left.type != TileType.Trees && up.type == TileType.Trees && up_right.type != TileType.Trees)
                    {
                        here.type = TileType.Trees;
                        here.i    = _6;
                        here.j    = _22;
                    }

                    // otherwise there are no trees beneath us, so we are just a side tree tile
                    else
                    {
                        here.type = TileType.Trees;
                        here.i    = _0;
                        here.j    = _24;
                    }
                }

                // Corner piece, bottom left
                else if (right.type == TileType.Trees && up.type != TileType.Trees)
                {
                    here.type = TileType.Trees;
                    here.i    = _0;
                    here.j    = _21;
                }

                // Corner piece, bottom right
                else if (left.type == TileType.Trees && up.type != TileType.Trees)
                {
                    here.type = TileType.Trees;
                    here.i    = _2;
                    here.j    = _21;
                }

                // Side piece, left side
                else if ((right.type == TileType.Trees || up_right.type == TileType.Trees) && up.type == TileType.Trees)
                {
                    here.type = TileType.Trees;
                    here.i    = _0;
                    here.j    = _20;
                }

                // Side piece, right side
                else if ((left.type == TileType.Trees || up_left.type == TileType.Trees) && up.type == TileType.Trees)
                {
                    here.type = TileType.Trees;
                    here.i    = _2;
                    here.j    = _20;
                }

                // Single tree
                else if (up.type != TileType.Trees)
                {
                    here.type = TileType.Trees;
                    here.i    = _0;
                    here.j    = _19;
                }

                // Single tree, with a tree below it
                else if (up.type == TileType.Trees)
                {
                    here.type = TileType.Trees;
                    here.i    = _1;
                    here.j    = _19;
                }
            }

            // Tree tops (caps) are drawn on grass tiles
            else if (here.type == TileType.Grass)
            {
                // If there is a full row of 3 trees underneath this tree, then this is a "full" tree cap tile
                if (up_left.type == TileType.Trees && up.type == TileType.Trees && up_right.type == TileType.Trees)
                {
                    here.type = TileType.Grass;
                    here.i    = _0;
                    here.j    = _23;
                }

                // If there is a tree below us and down left or down right, then this is a tree cap corner
                else if (up_left.type != TileType.Trees && up.type == TileType.Trees && up_right.type == TileType.Trees)
                {
                    here.type = TileType.Grass;
                    here.i    = _4;
                    here.j    = _21;
                }

                else if (up_left.type == TileType.Trees && up.type == TileType.Trees && up_right.type != TileType.Trees)
                {
                    here.type = TileType.Grass;
                    here.i    = _6;
                    here.j    = _21;
                }

                // If there is a tree below us but not down left or down right, then this is a lone tree cap
                else if (up_left.type != TileType.Trees && up.type == TileType.Trees && up_right.type != TileType.Trees)
                {
                    here.type = TileType.Grass;
                    here.i    = _0;
                    here.j    = _18;
                }

                else
                {
                    if (here.j != _31)
                    {
                        here.i = _0;
                        here.j = _31;
                    }
                }
            }
        }
示例#11
0
        void DirtGrassInterface(ref tile here, ref tile right, ref tile up, ref tile left, ref tile down, ref tile up_right, ref tile up_left, ref tile down_right, ref tile down_left)
        {
            bool grass_on_left   = left.type == TileType.Grass || up_left.type == TileType.Grass || down_left.type == TileType.Grass;
            bool grass_on_right  = right.type == TileType.Grass || up_right.type == TileType.Grass || down_right.type == TileType.Grass;
            bool grass_on_top    = up_left.type == TileType.Grass || up.type == TileType.Grass || up_right.type == TileType.Grass;
            bool grass_on_bottom = down_left.type == TileType.Grass || down.type == TileType.Grass || down_right.type == TileType.Grass;

            // If we're straddled on two opposite sides by grass, or if any tile adjacent to us is trees, then just turn into grass
            if (left.type == TileType.Grass && right.type == TileType.Grass ||
                up.type == TileType.Grass && down.type == TileType.Grass ||
                up.type == TileType.Trees || right.type == TileType.Trees || down.type == TileType.Trees || left.type == TileType.Trees)
            {
                here.type = TileType.Grass;
                here.i    = _0;
                here.j    = _31;
            }

            // If two adjacent sides are grass, then use a 2-grass corner piece
            else if (left.type == TileType.Grass && up.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _2;
                here.j    = _26;
            }

            else if (up.type == TileType.Grass && right.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _0;
                here.j    = _26;
            }

            else if (right.type == TileType.Grass && down.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _4;
                here.j    = _26;
            }

            else if (down.type == TileType.Grass && left.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _6;
                here.j    = _26;
            }

            else
            if (grass_on_left && right.type == TileType.Grass ||
                grass_on_right && left.type == TileType.Grass ||
                grass_on_top && down.type == TileType.Grass ||
                grass_on_bottom && up.type == TileType.Grass)
            {
                here.type = TileType.Grass;
                here.i    = _0;
                here.j    = _31;
            }

            // If a single side is grass, then use a 1-grass side piece
            else if (right.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _0;
                here.j    = _28;
            }

            else if (up.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _3;
                here.j    = _28;
            }

            else if (left.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _6;
                here.j    = _28;
            }

            else if (down.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _9;
                here.j    = _28;
            }

            // If a single diagonal corner is grass, then use a 1-grass diagonal corner
            else if (down_left.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _0;
                here.j    = _27;
            }

            else if (down_right.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _2;
                here.j    = _27;
            }

            else if (up_left.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _4;
                here.j    = _27;
            }

            else if (up_right.type == TileType.Grass)
            {
                here.type = TileType.Dirt;
                here.i    = _6;
                here.j    = _27;
            }

            else
            {
                if (here.j != _30)
                {
                    here.i = _0;
                    here.j = _30;
                }
            }
        }
示例#12
0
        geo FragmentShader(VertexOut vertex, Field <tile> Tiles, [Vals.Bool] bool Anti)
        {
            tile
           here       = Tiles[Here],
           right      = Tiles[RightOne],
           up         = Tiles[UpOne],
           left       = Tiles[LeftOne],
           down       = Tiles[DownOne],
           up_right   = Tiles[UpRight],
           up_left    = Tiles[UpLeft],
           down_right = Tiles[DownRight],
           down_left  = Tiles[DownLeft];

            if (IsBlockingTile(here))
            {
                return(geo.Nothing);
            }

            float dir = 0;

            if (IsBlockingTile(up_left))
            {
                dir = Anti ? Dir.Left  : Dir.Up;
            }
            if (IsBlockingTile(up_right))
            {
                dir = Anti ? Dir.Up    : Dir.Right;
            }
            if (IsBlockingTile(down_right))
            {
                dir = Anti ? Dir.Right : Dir.Down;
            }
            if (IsBlockingTile(down_left))
            {
                dir = Anti ? Dir.Down  : Dir.Left;
            }

            if (Anti)
            {
                if (IsBlockingTile(right))
                {
                    dir = Dir.Up;
                    if (IsBlockingTile(up))
                    {
                        dir = Dir.Left;
                        if (IsBlockingTile(left))
                        {
                            dir = Dir.Down;
                        }
                    }
                }

                if (IsBlockingTile(up))
                {
                    dir = Dir.Left;
                    if (IsBlockingTile(left))
                    {
                        dir = Dir.Down;
                        if (IsBlockingTile(down))
                        {
                            dir = Dir.Right;
                        }
                    }
                }

                if (IsBlockingTile(left))
                {
                    dir = Dir.Down;
                    if (IsBlockingTile(down))
                    {
                        dir = Dir.Right;
                        if (IsBlockingTile(right))
                        {
                            dir = Dir.Up;
                        }
                    }
                }

                if (IsBlockingTile(down))
                {
                    dir = Dir.Right;
                    if (IsBlockingTile(right))
                    {
                        dir = Dir.Up;
                        if (IsBlockingTile(up))
                        {
                            dir = Dir.Left;
                        }
                    }
                }
            }
            else
            {
                if (IsBlockingTile(right))
                {
                    dir = Dir.Down;
                    if (IsBlockingTile(down))
                    {
                        dir = Dir.Left;
                        if (IsBlockingTile(left))
                        {
                            dir = Dir.Up;
                        }
                    }
                }

                if (IsBlockingTile(up))
                {
                    dir = Dir.Right;
                    if (IsBlockingTile(right))
                    {
                        dir = Dir.Down;
                        if (IsBlockingTile(down))
                        {
                            dir = Dir.Left;
                        }
                    }
                }

                if (IsBlockingTile(left))
                {
                    dir = Dir.Up;
                    if (IsBlockingTile(up))
                    {
                        dir = Dir.Right;
                        if (IsBlockingTile(right))
                        {
                            dir = Dir.Down;
                        }
                    }
                }

                if (IsBlockingTile(down))
                {
                    dir = Dir.Left;
                    if (IsBlockingTile(left))
                    {
                        dir = Dir.Up;
                        if (IsBlockingTile(up))
                        {
                            dir = Dir.Right;
                        }
                    }
                }
            }

            geo output = geo.Nothing;

            output.dir = dir;

            int surround_count =
                (IsBlockingTile(up)    ? 1 : 0) +
                (IsBlockingTile(left)  ? 1 : 0) +
                (IsBlockingTile(down)  ? 1 : 0) +
                (IsBlockingTile(right) ? 1 : 0);

            if (output.dir > _0 && surround_count == 3)
            {
                output.bad = _true;
            }

            return(output);
        }
示例#13
0
        dirward FragmentShader(VertexOut vertex, Field <tile> Tiles, Field <geo> Geo, Field <dirward> Dirward, [Dir.Vals] float dir)
        {
            tile
           here = Tiles[Here];

            geo
                geo_here       = Geo[Here],
                geo_right      = Geo[RightOne],
                geo_up         = Geo[UpOne],
                geo_left       = Geo[LeftOne],
                geo_down       = Geo[DownOne],
                geo_up_right   = Geo[UpRight],
                geo_up_left    = Geo[UpLeft],
                geo_down_right = Geo[DownRight],
                geo_down_left  = Geo[DownLeft];

            dirward
                dirward_here       = Dirward[Here],
                dirward_right      = Dirward[RightOne],
                dirward_up         = Dirward[UpOne],
                dirward_left       = Dirward[LeftOne],
                dirward_down       = Dirward[DownOne],
                dirward_up_right   = Dirward[UpRight],
                dirward_up_left    = Dirward[UpLeft],
                dirward_down_right = Dirward[DownRight],
                dirward_down_left  = Dirward[DownLeft];

            if (IsBlockingTile(here))
            {
                return(dirward.Nothing);
            }

            dirward output = dirward.Nothing;

            dirward forward = dirward.Nothing, forward_right = dirward.Nothing, forward_left = dirward.Nothing, rightward = dirward.Nothing, leftward = dirward.Nothing;
            geo     geo_forward = geo.Nothing, geo_forward_right = geo.Nothing, geo_forward_left = geo.Nothing, geo_rightward = geo.Nothing, geo_leftward = geo.Nothing;

            // Get the surrounding dirward info and store it relative to the direction we consider forward
            if (dir == Dir.Up)
            {
                forward       = dirward_up;
                forward_right = dirward_up_right;
                forward_left  = dirward_up_left;
                rightward     = dirward_right;
                leftward      = dirward_left;

                geo_forward       = geo_up;
                geo_forward_right = geo_up_right;
                geo_forward_left  = geo_up_left;
                geo_rightward     = geo_right;
                geo_leftward      = geo_left;
            }
            else if (dir == Dir.Right)
            {
                forward       = dirward_right;
                forward_right = dirward_down_right;
                forward_left  = dirward_up_right;
                rightward     = dirward_down;
                leftward      = dirward_up;

                geo_forward       = geo_right;
                geo_forward_right = geo_down_right;
                geo_forward_left  = geo_up_right;
                geo_rightward     = geo_down;
                geo_leftward      = geo_up;
            }
            else if (dir == Dir.Down)
            {
                forward       = dirward_down;
                forward_right = dirward_down_left;
                forward_left  = dirward_down_right;
                rightward     = dirward_left;
                leftward      = dirward_right;

                geo_forward       = geo_down;
                geo_forward_right = geo_down_left;
                geo_forward_left  = geo_down_right;
                geo_rightward     = geo_left;
                geo_leftward      = geo_right;
            }
            else if (dir == Dir.Left)
            {
                forward       = dirward_left;
                forward_right = dirward_up_left;
                forward_left  = dirward_down_left;
                rightward     = dirward_up;
                leftward      = dirward_down;

                geo_forward       = geo_left;
                geo_forward_right = geo_up_left;
                geo_forward_left  = geo_down_left;
                geo_rightward     = geo_up;
                geo_leftward      = geo_down;
            }

            if (geo_here.dir > 0 && IsBlockingTile(Tiles[dir_to_vec(dir)]))
            {
                output = dirward_here;

                output.geo_id       = geo_here.geo_id;
                output.dist_to_wall = _0;
            }

            else if (ValidDirward(forward) && forward.geo_id == geo_forward.geo_id)
            {
                output = forward;       output.dist_to_wall += _1;
            }
            else if (ValidDirward(forward_right) && forward_right.geo_id == geo_forward_right.geo_id)
            {
                output = forward_right; output.dist_to_wall += _1;
            }
            else if (ValidDirward(forward_left) && forward_left.geo_id == geo_forward_left.geo_id)
            {
                output = forward_left;  output.dist_to_wall += _1;
            }
            //else if (ValidDirward(rightward)     && rightward.geo_id     == geo_rightward.geo_id)     { output = rightward;     output.dist_to_wall += _0; }
            //else if (ValidDirward(leftward)      && leftward.geo_id      == geo_leftward.geo_id)      { output = leftward;      output.dist_to_wall += _0; }

            return(output);
        }
示例#14
0
        geo FragmentShader(VertexOut vertex, Field <tile> Tiles, Field <geo> Geo, [Vals.Bool] bool Anti)
        {
            tile
           here       = Tiles[Here],
           right      = Tiles[RightOne],
           up         = Tiles[UpOne],
           left       = Tiles[LeftOne],
           down       = Tiles[DownOne],
           up_right   = Tiles[UpRight],
           up_left    = Tiles[UpLeft],
           down_right = Tiles[DownRight],
           down_left  = Tiles[DownLeft];

            geo
                geo_here       = Geo[Here],
                geo_right      = Geo[RightOne],
                geo_up         = Geo[UpOne],
                geo_left       = Geo[LeftOne],
                geo_down       = Geo[DownOne],
                geo_up_right   = Geo[UpRight],
                geo_up_left    = Geo[UpLeft],
                geo_down_right = Geo[DownRight],
                geo_down_left  = Geo[DownLeft];

            if (IsBlockingTile(here))
            {
                return(geo.Nothing);
            }

            geo output = geo_here;

            if (!(IsBlockingTile(right) && IsBlockingTile(left)) &&
                (geo_here.dir == Dir.Up && geo_up.dir == Dir.Down || geo_here.dir == Dir.Down && geo_down.dir == Dir.Up))
            {
                output.dir = IsBlockingTile(right) ? Dir.Left : Dir.Right;
            }

            if (!(IsBlockingTile(up) && IsBlockingTile(down)) &&
                (geo_here.dir == Dir.Right && geo_right.dir == Dir.Left || geo_here.dir == Dir.Left && geo_left.dir == Dir.Right))
            {
                output.dir = IsBlockingTile(up) ? Dir.Down : Dir.Up;
            }

            if (Geo[dir_to_vec(output.dir)].bad == _true && geo_here.bad == _false)
            {
                output.dir = Reverse(output.dir);
            }

            int surround_count =
                (IsBlockingTile(up)    ? 1 : 0) +
                (IsBlockingTile(left)  ? 1 : 0) +
                (IsBlockingTile(down)  ? 1 : 0) +
                (IsBlockingTile(right) ? 1 : 0);

            float bad_count = geo_up.bad + geo_left.bad + geo_down.bad + geo_right.bad;

            if (surround_count >= 2 && bad_count >= _1 ||
                geo_up.bad == _true && geo_down.bad == _true ||
                geo_right.bad == _true && geo_left.bad == _true)
            {
                output.bad = _true;
            }

            return(output);
        }