title: Optimize field of vision algorithm in a grid tiled map
body: <p>I am trying to implement Field of View algorithm in my game and I followed the great tutorial here : <a href="http://ncase.me/sight-and-light/" rel="nofollow noreferrer">sight-and-light</a> and here is what I got so far :</p>
  
  <p><a href="https://i.stack.imgur.com/lmNd5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lmNd5.png" alt="enter image description here"></a></p>
  
  <p>As you can see it works fine for me :)</p>
  
  <p>And then I try to use this algorithm in a tiled map. It also works fine but just a little bit slow so I am now trying to find a way to optimize the algorithm.</p>
  
  <p>Some information might help to optimize :</p>
  
  <ul>
  <li>The tiled map is Orthogonal</li>
  <li>All the tiles have the same size 32 * 32 and are square</li>
  <li>Tiles marked 0 means empty marked as 1 means a obstacle</li>
  <li>I have used Connected Component Labelling algorithm for a preprocess :
  
  <ul>
  <li>All the obstacles have been merged into several regions</li>
  <li>I know all the vertices position in each regions</li>
  </ul></li>
  </ul>
  
  <p>Something like this :</p>
  
  <p><a href="https://i.stack.imgur.com/48LwJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/48LwJ.png" alt="enter image description here"></a></p>
  
  <p>Say I have 9 connected regions ( 9 polygons ) and 40 vertices in total.</p>
  
  <p>Based on the algorithm in the above link, there will be :</p>
  
  <ul>
  <li>ray-cast : 40 * 3   ( 3 ray-cast per vertices in angle +- 0.00001)</li>
  <li>edges : 40 </li>
  <li>edge * ray-cast intersection test : 40 * 40 * 3 == 4800</li>
  </ul>
  
  <p>I think there should be a way to reduce the ray cast count and the edges count that I need to do the intersection calculation in a above situation but just could not figure out a good solution.</p>
  
  <p>Any suggestion will be appreciated, thanks :)</p>