Field of View (FOV) computation

FOV algorithms return a set coordinates, visible from a starting place. Computing these works in the same fashion as Map generators do: using a user-supplied callback function. This time, however, user has to supply two callbacks:

Input callback is called by the FOV algorithm to retrieve visibility information for a given coordinate pair. This callback must return true (light passes) or false (light does nto pass). Output callback is called with these arguments: x, y, r and visibility: the meaning is that "the place at [x,y] is visible with a distance of r". The last argument specifies the amount of visibility (0..1).

FOV computation is initiated by calling the compute method with the following arguments:

  1. x
  2. y
  3. r – maximum visibility radius
  4. callback – output callback function

Precise shadowcasting

For now, there is only one FOV algorithm available: the Precise Shadowcasting.

ROT.RNG.setSeed(12345); ROT.DEFAULT_WIDTH = 80; ROT.DEFAULT_HEIGHT = 30; var display = new ROT.Display({fontSize:12}); SHOW(display.getContainer()); /* create a map */ var data = {}; new ROT.Map.Uniform().create(function(x, y, type) { data[x+","+y] = type; display.DEBUG(x, y, type); }); /* input callback */ var lightPasses = function(x, y) { var key = x+","+y; if (key in data) { return (data[key] == 0); } return false; } var fov = new ROT.FOV.PreciseShadowcasting(lightPasses); /* output callback */ fov.compute(50, 22, 10, function(x, y, r, visibility) { var ch = (r ? "" : "@"); var color = (data[x+","+y] ? "#aa0": "#660"); display.draw(x, y, ch, "#fff", color); });