Advertisement
Guest User

Untitled

a guest
Aug 21st, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. void recursiveLightCalculation(int x, int y, double lightLevel, LightMap & lightMap, SolidMap & solid)
  2. {
  3. //if the light is brighter here, then it already calculated all that this would
  4. if (lightLevel <= lightMap.get(x, y))
  5. return;
  6.  
  7.  
  8. lightMap.set(x, y, lightLevel);
  9.  
  10. if (x - 1 >= 0 && !solid.isSolid(x - 1, y))
  11. recursiveLightCalculation(x - 1, y, lightLevel - 1, lightMap, solid);
  12.  
  13. if (y - 1 >= 0 && !solid.isSolid(x, y - 1))
  14. recursiveLightCalculation(x, y - 1, lightLevel - 1, lightMap, solid);
  15.  
  16. if (x + 1 < lightMap.getSize().x && !solid.isSolid(x + 1, y))
  17. recursiveLightCalculation(x + 1, y, lightLevel - 1, lightMap, solid);
  18.  
  19. if (y + 1 < lightMap.getSize().y && !solid.isSolid(x, y + 1))
  20. recursiveLightCalculation(x, y + 1, lightLevel - 1, lightMap, solid);
  21.  
  22. if (x - 1 >= 0 && y - 1 >= 0 && !solid.isSolid(x - 1, y - 1))
  23. recursiveLightCalculation(x - 1, y - 1, lightLevel - std::sqrt(2), lightMap, solid);
  24.  
  25. if (x - 1 >= 0 && y + 1 < lightMap.getSize().y && !solid.isSolid(x - 1, y + 1))
  26. recursiveLightCalculation(x - 1, y + 1, lightLevel - std::sqrt(2), lightMap, solid);
  27.  
  28. if (x + 1 < lightMap.getSize().x && y - 1 >= 0 && !solid.isSolid(x + 1, y - 1))
  29. recursiveLightCalculation(x + 1, y - 1, lightLevel - std::sqrt(2), lightMap, solid);
  30.  
  31. if (x + 1 < lightMap.getSize().x && y + 1 < lightMap.getSize().y && !solid.isSolid(x + 1, y + 1))
  32. recursiveLightCalculation(x + 1, y + 1, lightLevel - std::sqrt(2), lightMap, solid);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement