… | |
… | |
32 | FLG_YI = 0x02, // we have an y-parent |
32 | FLG_YI = 0x02, // we have an y-parent |
33 | FLG_BLOCKED = 0x04, // this space blocks the view |
33 | FLG_BLOCKED = 0x04, // this space blocks the view |
34 | FLG_QUEUED = 0x80 // already queued in queue, or border |
34 | FLG_QUEUED = 0x80 // already queued in queue, or border |
35 | }; |
35 | }; |
36 | |
36 | |
|
|
37 | // it is important for performance reasons that this structure |
|
|
38 | // has a size easily computable by the cpu (*8 is perfect). |
|
|
39 | // it is possible to move culled and visible into flags, at |
|
|
40 | // some speed loss. |
37 | struct los_info |
41 | struct los_info |
38 | { |
42 | { |
39 | uint8 flags; // FLG_xxx |
43 | uint8 flags; // FLG_xxx |
40 | uint8 culled; // culled from "tree" |
44 | uint8 culled; // culled from "tree" |
41 | uint8 visible; |
45 | uint8 visible; |
… | |
… | |
81 | |
85 | |
82 | los_info &l = los[x][y]; |
86 | los_info &l = los[x][y]; |
83 | |
87 | |
84 | l.flags |= flags; |
88 | l.flags |= flags; |
85 | |
89 | |
86 | if (l.flags & FLG_QUEUED) |
90 | if (expect_false (l.flags & FLG_QUEUED)) |
87 | return; |
91 | return; |
88 | |
92 | |
89 | l.flags |= FLG_QUEUED; |
93 | l.flags |= FLG_QUEUED; |
90 | |
94 | |
91 | queue[q1].x = dx; |
95 | queue[q1].x = dx; |
… | |
… | |
301 | for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) |
305 | for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) |
302 | vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4; |
306 | vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4; |
303 | } |
307 | } |
304 | } los_init; |
308 | } los_init; |
305 | |
309 | |
|
|
310 | // the following functions cannot be static, due to c++ stupidity :/ |
|
|
311 | namespace { |
306 | // brighten area, ignore los |
312 | // brighten area, ignore los |
307 | sint8 |
313 | sint8 |
308 | los_brighten_nolos (sint8 b, sint8 l) |
314 | los_brighten_nolos (sint8 b, sint8 l) |
309 | { |
315 | { |
310 | return min (b, l); |
316 | return min (b, l); |
311 | } |
317 | } |
312 | |
318 | |
313 | // brighten area, but respect los |
319 | // brighten area, but respect los |
314 | sint8 |
320 | sint8 |
315 | los_brighten (sint8 b, sint8 l) |
321 | los_brighten (sint8 b, sint8 l) |
316 | { |
322 | { |
317 | return b == LOS_BLOCKED ? b : min (b, l); |
323 | return b == LOS_BLOCKED ? b : min (b, l); |
318 | } |
324 | } |
319 | |
325 | |
320 | // darken area, respect los |
326 | // darken area, respect los |
321 | sint8 |
327 | sint8 |
322 | los_darken (sint8 b, sint8 l) |
328 | los_darken (sint8 b, sint8 l) |
323 | { |
329 | { |
324 | return max (b, l); |
330 | return max (b, l); |
325 | } |
331 | } |
|
|
332 | }; |
326 | |
333 | |
327 | template<sint8 change_it (sint8, sint8)> |
334 | template<sint8 change_it (sint8, sint8)> |
328 | static void |
335 | static void |
329 | apply_light (player *pl, int dx, int dy, int light, const sint8 *atten_table) |
336 | apply_light (player *pl, int dx, int dy, int light, const sint8 *atten_table) |
330 | { |
337 | { |