### Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

### Topics - DavidD

Pages: [1]
1
##### Programming / Recursive shadowcasting wrong in wiki?
« on: January 04, 2012, 08:46:55 PM »
Hey there! I just registered so I'd like to say hey to the roguelike community!

Anyway, I read this article on the wiki. However, it seems that there's a bug in there somewhere. If you look at this picture I'm sure you'd understand:

http://imgur.com/okvVB

In the top picture, the algorithm works as expected, but when 2 tiles are added like in the second picture (the vertical wall doesn't matter, i exaggerated it) it acts weird and that's not at all the way I'd like it to look.

It's the same on all 4 sides. So it's the code posted in my link that's a bit faulty as a whole.

Is there an updated version or is it just like that?

This is my first octant just to show my syntax, all the other ones are the same except for a few other values

Code: [Select]
`            int x = 0;            int y = 0;            switch (octant)            {                case 1:                    y = playerPosition.Y - depth;                    x = (int)Math.Round(playerPosition.X - startSlope * depth);                    if (x < 0)                        break;                    if (x >= mapDimensions.X)                        break;                    if (y < 0)                        break;                    if (y >= mapDimensions.Y)                        break;                                        while (GetSlope(x, y, playerPosition.X, playerPosition.Y) >= endSlope)                    {                        if (IsWithinVisualRange(playerPosition.X, playerPosition.Y, x, y))                        {                            if (map[y][x].BlocksVision)                            {                                //if (TestCell(x - 1, y, playerPosition.X, playerPosition.Y, false, depth))                                if(!map[y][x - 1].BlocksVision)                                    RecursiveScan(playerPosition, depth + 1, octant, startSlope, GetSlope(x - 0.5, y + 0.5, playerPosition.X, playerPosition.Y));                                lightMap[y][x] = 1;                                visitedMap[y][x] = true;                            }                            else                            {                                //if (TestCell(x - 1, y, playerPosition.X, playerPosition.Y, true, depth))                                if(map[y][x - 1].BlocksVision)                                    startSlope = GetSlope(x - 0.5, y - 0.5, playerPosition.X, playerPosition.Y);                                lightMap[y][x] = 1;                                visitedMap[y][x] = true;                            }                        }                        x++;                    }                    x--;`

Pages: [1]