Field of View: How the Dungeon Becomes Visible

One of the most defining features of a roguelike is limited visibility. You can only see what your character could realistically observe from their current position. Everything else remains hidden in darkness.

This mechanic is called Field of View (FOV), and it is essential for creating tension and exploration in games like Brogue and Sil-Q.

When reimplementing the engine in Swift, rebuilding the FOV system was one of the most important tasks.


Why Field of View Matters

Without FOV, a dungeon would behave more like a strategy map where everything is visible at all times.

Limiting visibility introduces several gameplay dynamics:

FOV is therefore not just a rendering detail—it is a core gameplay mechanic.


The Basic Problem

The challenge is simple to describe:

From the player’s position, determine which tiles are visible.

However, walls complicate the problem. A tile behind a wall should not be visible, even if it is nearby.

So the algorithm must account for line-of-sight blocking.


Common Approaches

Roguelikes historically use several FOV techniques:

Each method has different trade-offs in accuracy and performance.

For this Swift reimplementation, the engine uses a shadowcasting approach, which is widely used in roguelikes because it is both fast and visually natural.


The Idea Behind Shadowcasting

Shadowcasting works by scanning outward from the player in multiple directions and tracking where shadows appear.

Imagine the player standing in the center of the map. The algorithm examines the surrounding space in eight directional sectors.

As it scans outward, walls cast shadows that block visibility behind them.

For example:

Player -> . . . #
                #
                X

The wall blocks visibility behind it, so tile X is hidden.

Instead of testing every tile individually with expensive line-of-sight checks, shadowcasting tracks angular shadow ranges. Once a region is fully shadowed, the algorithm stops exploring that area.

This makes the algorithm both efficient and elegant.


Advantages of Shadowcasting

Shadowcasting has several properties that make it well suited for roguelikes:

Efficient

The algorithm explores only visible regions and avoids unnecessary checks.

Symmetrical

Visibility behaves consistently in all directions.

Natural Looking

Walls create realistic shadows rather than jagged visibility artifacts.

Scales Well

Even when recalculated every turn, the cost remains small on modern devices.


Swift Implementation Design

In the Swift reimplementation, FOV is implemented as a separate system rather than being embedded inside the rendering code.

This separation allows visibility to be reused by other gameplay systems, such as:

The core interface is conceptually simple:

func computeFOV(from origin: Pos, radius: Int)

The function fills a visibility grid marking which tiles are currently visible.


Visibility vs Memory

Roguelikes usually distinguish between two different concepts:

Currently Visible

Tiles the player can see right now.

Previously Seen

Tiles the player saw earlier but cannot currently see.

These are typically rendered differently:

The Swift engine stores this information in separate grids so the UI can render them appropriately.


Lighting and FOV

Another advantage of separating FOV from rendering is that it allows more advanced lighting systems.

For example, light sources such as:

can modify visibility dynamically.

Instead of computing only a binary visible/not-visible state, the system can support light intensity values for each tile.

This allows the dungeon to feel more atmospheric without significantly complicating the core algorithm.


Interaction with Gameplay Systems

FOV also interacts with many other mechanics.

For example:

Monster Awareness

Creatures usually only react to the player if they can see them.

Stealth

The player may be hidden if outside an enemy’s FOV.

Traps

Some traps remain hidden until they enter the player’s visible area.

Exploration Tracking

The game can record which tiles have been discovered.

Because of these interactions, the FOV system is recalculated frequently—often every time the player moves.

Fortunately, shadowcasting is fast enough that this remains inexpensive.


Performance Considerations

Although dungeon maps are not large, the FOV algorithm runs many times during gameplay.

The Swift implementation keeps performance high by:

On modern iPhones, the computation takes a fraction of a millisecond.


Reimplementing the System from Scratch

The Swift version does not port the original implementation directly. Instead, the algorithm is implemented from first principles using modern data structures.

This ensures:

The behavior remains familiar to players, but the implementation is entirely new.


Final Thoughts

Field of View is one of the systems that quietly defines the feel of a roguelike. It controls what the player knows, what remains hidden, and how the dungeon reveals itself over time.

Rebuilding the FOV system in Swift ensured that the new engine preserves the tension and exploration that make roguelikes so compelling, while fitting naturally into a modern architecture.