Author Topic: FOV algorithms  (Read 11622 times)

mughinn

  • Newcomer
  • Posts: 39
  • Karma: +0/-0
    • View Profile
FOV algorithms
« on: December 26, 2012, 02:05:13 AM »
So I'm adding LOS to a roguelike I'm creating.

I've tried implementing a very basic one that i didn't like (creating a Bresenham's line between the player and every tile in FOV and check if it was clear). This method, although fast, created some things that I didn't like, like having random tiles being highlighted surrounded by the dark.

Now I've done a raycasting one, and, for me, it looks bad. Also, I'm still discussing with myself if it should have asymmetry, and considering the gameplay options it adds.

I'd love some kind of comparison or some algorithm I can use, that is somewhat fast and looks good.

What I don't like about raycasting is something like this:

.........
...@..#
.........
....#.....
..........

where you can see just behind a pillar.

Thanks for any advice you can give.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: FOV algorithms
« Reply #1 on: December 26, 2012, 02:19:30 AM »

mughinn

  • Newcomer
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: FOV algorithms
« Reply #2 on: December 26, 2012, 01:38:32 PM »
Well thanks, I ended up in the Restrictive Precise Angle Shadowcasting article in Roguebasin, It seems good, I'll try to implement it in my language and come back to say how it went.

XLambda

  • Rogueliker
  • ***
  • Posts: 208
  • Karma: +0/-0
    • MSN Messenger - tau_iota@live.de
    • View Profile
    • The Weird Rogue
Re: FOV algorithms
« Reply #3 on: December 26, 2012, 06:51:41 PM »
Well thanks, I ended up in the Restrictive Precise Angle Shadowcasting article in Roguebasin, It seems good, I'll try to implement it in my language and come back to say how it went.

You can find good implementations of many FOV algorithms in the libtcod source.

mughinn

  • Newcomer
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: FOV algorithms
« Reply #4 on: December 27, 2012, 09:43:29 PM »
The good thing, the thing works.
The bad thing, the thing doesn't work right.

And thanks XLambda, I ended up there :)

I'd pass my code, but 174 lines of Racket don't seem good for anyone, also, my code usually embarrasses me.
Is there any implementation in Lisp, Haskell or similar?
I'm still trying though, if someone finds an example in a somewhat functional language I'd be incredibly happy, until that happens or I'm happy enough with my beast, until then, wish me luck :P
« Last Edit: December 27, 2012, 09:45:13 PM by mughinn »

Feufochmar

  • Newcomer
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • Email
Re: FOV algorithms
« Reply #5 on: December 29, 2012, 12:18:47 PM »
There is a libtcod wrapper for Racket (https://github.com/lewis1711/pltcod). So you can use libtcod FOV algorithms from Racket.

mughinn

  • Newcomer
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: FOV algorithms
« Reply #6 on: December 30, 2012, 05:49:27 AM »
Well, I actually wanted to implement it myself and not just use a library.

I think i got it now, It's sitting at 105 lines, and it's purely functional (if I'm not missing anything), there are some things I don't know if they should work that way, for example:


..........
.........@
    ## ##.
         .


or this:


...#
...  
...#
...  
...##
.....
..@..


Should it work that way? showing extra walls (in a way, as I can guess parts with no walls that way).

Alex E

  • Rogueliker
  • ***
  • Posts: 118
  • Karma: +0/-0
    • View Profile
    • Email
Re: FOV algorithms
« Reply #7 on: December 30, 2012, 11:34:31 PM »

..........
.........@
    ## ##.
         .


or this:


...#
...  
...#
...  
...##
.....
..@..


I'd say this is more of how it should look like, assuming those are walls.


...........
..........@
    ######.
         #.


and this:


...#
...#
...#
...#
...##
.....
..@..

« Last Edit: December 30, 2012, 11:37:22 PM by Mosenzov »

mughinn

  • Newcomer
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: FOV algorithms
« Reply #8 on: December 31, 2012, 02:01:51 PM »
No, the blank spaces are grass, and if it is that way, I actually like it, It seems at how in reality you would notice the walls, and notice that those spaces aren't walls, an yet you can't see what's in there.
Thanks for the help everyone, if someone wants, i can post the code.