# Precise Shadowcasting in JavaScript

From RogueBasin

(Difference between revisions)

Line 7: | Line 7: | ||

== General algorithm workflow == | == General algorithm workflow == | ||

− | == | + | # Let <code>[x,y]</code> be the player coordinates |

+ | # Initialize the empty shadow queue | ||

+ | # For <code>R=1</code> up to maximum visibility range do: | ||

+ | ## Retrieve all cells whose range from <code>[x,y]</code> is <code>R</code> | ||

+ | ## Make sure these cells are in correct order (clockwise or counter-clockwise; every iteration starting at the same angle) | ||

+ | ## For every cell in this "ring": | ||

+ | ### Determine the corresponding arc <code>[a1,a2]</code> | ||

+ | ### Consult the shadow queue to determine whether <code>[a1,a2]</code> is fully shadowed | ||

+ | ### If no part of <code>[a1,a2]</code> is visible, mark the cell as invisible and advance to next cell | ||

+ | ### If some part of <code>[a1,a2]</code> is visible, merge it into the shadow queue; mark the cell as visible | ||

+ | |||

+ | == Tweaks, tricks and advanced topics == | ||

=== Symbolic angles === | === Symbolic angles === |

## Revision as of 17:25, 3 January 2013

This pages describes and explains the Precise Shadowcasting algorithm, developed and implemented by Ondřej Žára in rot.js.

**WORK IN PROGRESS**

## Contents |

## About

## General algorithm workflow

- Let
`[x,y]`

be the player coordinates - Initialize the empty shadow queue
- For
`R=1`

up to maximum visibility range do:- Retrieve all cells whose range from
`[x,y]`

is`R`

- Make sure these cells are in correct order (clockwise or counter-clockwise; every iteration starting at the same angle)
- For every cell in this "ring":
- Determine the corresponding arc
`[a1,a2]`

- Consult the shadow queue to determine whether
`[a1,a2]`

is fully shadowed - If no part of
`[a1,a2]`

is visible, mark the cell as invisible and advance to next cell - If some part of
`[a1,a2]`

is visible, merge it into the shadow queue; mark the cell as visible

- Determine the corresponding arc

- Retrieve all cells whose range from