ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/los.C
(Generate patch)

Comparing deliantra/server/common/los.C (file contents):
Revision 1.63 by root, Tue Nov 3 23:44:20 2009 UTC vs.
Revision 1.69 by root, Fri Mar 26 01:04:44 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
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.
37struct los_info 41struct 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;
124 // spiral path algorithm below, except when very little 128 // spiral path algorithm below, except when very little
125 // area is visible, in which case it is slower. which evens 129 // area is visible, in which case it is slower. which evens
126 // out los calculation times between large and small los maps. 130 // out los calculation times between large and small los maps.
127 // apply_lights also iterates over this area, maybe these 131 // apply_lights also iterates over this area, maybe these
128 // two passes could be combined somehow. 132 // two passes could be combined somehow.
129 unordered_mapwalk (pl->observe, -half_x, -half_y, half_x, half_y) 133 unordered_mapwalk (mapwalk_buf, pl->viewpoint, -half_x, -half_y, half_x, half_y)
130 { 134 {
131 los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy]; 135 los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy];
132 l.flags = m->at (nx, ny).flags () & P_BLOCKSVIEW ? FLG_BLOCKED : 0; 136 l.flags = m->at (nx, ny).flags () & P_BLOCKSVIEW ? FLG_BLOCKED : 0;
133 } 137 }
134 } 138 }
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 :/
311namespace {
312 // brighten area, ignore los
306sint8 313 sint8
314 los_brighten_nolos (sint8 b, sint8 l)
315 {
316 return min (b, l);
317 }
318
319 // brighten area, but respect los
320 sint8
307los_brighten (sint8 b, sint8 l) 321 los_brighten (sint8 b, sint8 l)
308{ 322 {
309 return b == LOS_BLOCKED ? b : min (b, l); 323 return b == LOS_BLOCKED ? b : min (b, l);
310} 324 }
311 325
326 // darken area, respect los
312sint8 327 sint8
313los_darken (sint8 b, sint8 l) 328 los_darken (sint8 b, sint8 l)
314{ 329 {
315 return max (b, l); 330 return max (b, l);
316} 331 }
332};
317 333
318template<sint8 change_it (sint8, sint8)> 334template<sint8 change_it (sint8, sint8)>
319static void 335static void
320apply_light (player *pl, int dx, int dy, int light, const sint8 *atten_table) 336apply_light (player *pl, int dx, int dy, int light, const sint8 *atten_table)
321{ 337{
341 * mark those squares specially. 357 * mark those squares specially.
342 */ 358 */
343static void 359static void
344apply_lights (player *pl) 360apply_lights (player *pl)
345{ 361{
346 object *op = pl->observe; 362 object *op = pl->viewpoint;
347 int darklevel = op->map->darklevel (); 363 int darklevel = op->map->darklevel ();
348 364
349 int half_x = pl->ns->mapx / 2; 365 int half_x = pl->ns->mapx / 2;
350 int half_y = pl->ns->mapy / 2; 366 int half_y = pl->ns->mapy / 2;
351 367
352 int pass2 = 0; // negative lights have an extra pass 368 int pass2 = 0; // negative lights have an extra pass
353 369
354 maprect *rects = pl->observe->map->split_to_tiles ( 370 maprect *rects = pl->viewpoint->map->split_to_tiles (
371 mapwalk_buf,
355 pl->observe->x - half_x - MAX_LIGHT_RADIUS, 372 pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS,
356 pl->observe->y - half_y - MAX_LIGHT_RADIUS, 373 pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS,
357 pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1, 374 pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1,
358 pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 375 pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1
359 ); 376 );
360 377
361 /* If the player can see in the dark, increase light/vision radius */ 378 /* If the player can see in the dark, increase light/vision radius */
362 int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0; 379 int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0;
363 380
387 if (light < 0) 404 if (light < 0)
388 pass2 = 1; 405 pass2 = 1;
389 else 406 else
390 { 407 {
391 light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); 408 light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS);
392 apply_light<los_brighten> (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]); 409 apply_light<los_brighten> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, light, light_atten [light + MAX_LIGHT_RADIUS]);
393 } 410 }
394 } 411 }
395 412
396 /* grant some vision to the player, based on outside, outdoor, and darklevel */ 413 /* grant some vision to the player, based on outside, outdoor, and darklevel */
397 { 414 {
407 light = clamp (light + bonus, 0, MAX_VISION); 424 light = clamp (light + bonus, 0, MAX_VISION);
408 425
409 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); 426 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]);
410 } 427 }
411 } 428 }
429
430 // when we fly high, we have some minimum viewable area around us, like x-ray
431 if (op->move_type & MOVE_FLY_HIGH)
432 apply_light<los_brighten_nolos> (pl, 0, 0, 9, vision_atten [9]);
412 433
413 // possibly do 2nd pass for rare negative glow radii 434 // possibly do 2nd pass for rare negative glow radii
414 // for effect, those are always considered to be stronger than anything else 435 // for effect, those are always considered to be stronger than anything else
415 // but they can't darken a place completely 436 // but they can't darken a place completely
416 if (pass2) 437 if (pass2)
422 sint8 light = ms.light; 443 sint8 light = ms.light;
423 444
424 if (expect_false (light < 0)) 445 if (expect_false (light < 0))
425 { 446 {
426 light = clamp (light - bonus, 0, MAX_DARKNESS); 447 light = clamp (light - bonus, 0, MAX_DARKNESS);
427 apply_light<los_darken> (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); 448 apply_light<los_darken> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, -light, light_atten [light + MAX_LIGHT_RADIUS]);
428 } 449 }
429 } 450 }
430} 451}
431 452
432/* blinded_sight() - sets all viewable squares to blocked except 453/* blinded_sight() - sets all viewable squares to blocked except
450 if (ob->flag [FLAG_REMOVED])//D really needed? 471 if (ob->flag [FLAG_REMOVED])//D really needed?
451 return; 472 return;
452 473
453 if (ob->flag [FLAG_WIZLOOK]) 474 if (ob->flag [FLAG_WIZLOOK])
454 clear_los (0); 475 clear_los (0);
455 else if (observe->flag [FLAG_BLIND]) /* player is blind */ 476 else if (viewpoint->flag [FLAG_BLIND]) /* player is blind */
456 { 477 {
457 clear_los (); 478 clear_los ();
458 blinded_sight (this); 479 blinded_sight (this);
459 } 480 }
460 else 481 else
462 clear_los (); 483 clear_los ();
463 calculate_los (this); 484 calculate_los (this);
464 apply_lights (this); 485 apply_lights (this);
465 } 486 }
466 487
467 if (observe->flag [FLAG_XRAYS]) 488 if (viewpoint->flag [FLAG_XRAYS])
468 for (int dx = -2; dx <= 2; dx++) 489 for (int dx = -2; dx <= 2; dx++)
469 for (int dy = -2; dy <= 2; dy++) 490 for (int dy = -2; dy <= 2; dy++)
470 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); 491 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1);
471} 492}
472 493

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines