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.64 by root, Wed Nov 4 17:24:00 2009 UTC vs.
Revision 1.74 by root, Wed Nov 16 23:03:09 2016 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,2011,2012 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.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include <global.h> 23#include <global.h>
24#include <cmath> 24#include <cmath>
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;
47 51
48// temporary storage for the los algorithm, 52// temporary storage for the los algorithm,
49// one los_info for each lightable map space 53// one los_info for each lightable map space
50static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y]; 54static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y];
51 55
52struct point 56struct point8
53{ 57{
54 sint8 x, y; 58 sint8 x, y;
55}; 59};
56 60
57// minimum size, but must be a power of two 61// minimum size, but must be a power of two
58#define QUEUE_LENGTH ((MAP_CLIENT_X + MAP_CLIENT_Y) * 2) 62#define QUEUE_LENGTH ((MAP_CLIENT_X + MAP_CLIENT_Y) * 2)
59 63
60// a queue of spaces to calculate 64// a queue of spaces to calculate
61static point queue [QUEUE_LENGTH]; 65static point8 queue [QUEUE_LENGTH];
62static int q1, q2; // queue start, end 66static int q1, q2; // queue start, end
63 67
64/* 68/*
65 * Clears/initialises the los-array associated to the player 69 * Clears/initialises the los-array associated to the player
66 * controlling the object. 70 * controlling the object.
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->viewpoint, -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 {
306// brighten area, ignore los 312 // brighten area, ignore los
307sint8 313 sint8
308los_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
314sint8 320 sint8
315los_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
321sint8 327 sint8
322los_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
327template<sint8 change_it (sint8, sint8)> 334template<sint8 change_it (sint8, sint8)>
328static void 335static void
329apply_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)
330{ 337{
352static void 359static void
353apply_lights (player *pl) 360apply_lights (player *pl)
354{ 361{
355 object *op = pl->viewpoint; 362 object *op = pl->viewpoint;
356 int darklevel = op->map->darklevel (); 363 int darklevel = op->map->darklevel ();
357 maptile::outdoor_darkness = 4;//D
358 364
359 int half_x = pl->ns->mapx / 2; 365 int half_x = pl->ns->mapx / 2;
360 int half_y = pl->ns->mapy / 2; 366 int half_y = pl->ns->mapy / 2;
361 367
362 int pass2 = 0; // negative lights have an extra pass 368 int pass2 = 0; // negative lights have an extra pass
363 369
364 maprect *rects = pl->viewpoint->map->split_to_tiles ( 370 maprect *rects = pl->viewpoint->map->split_to_tiles (
371 mapwalk_buf,
365 pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS, 372 pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS,
366 pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS, 373 pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS,
367 pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1, 374 pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1,
368 pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1 375 pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1
369 ); 376 );
527 if (!pl->ob || !pl->ob->map || !pl->ns) 534 if (!pl->ob || !pl->ob->map || !pl->ns)
528 continue; 535 continue;
529 536
530 rv_vector rv; 537 rv_vector rv;
531 538
532 get_rangevector_from_mapcoord (map, x, y, pl->ob, &rv); 539 get_rangevector_from_mapcoord (pl->ob->map, x, y, pl->ob, &rv);
533 540
534 if ((abs (rv.distance_x) <= pl->ns->mapx / 2) && (abs (rv.distance_y) <= pl->ns->mapy / 2)) 541 if ((abs (rv.distance_x) <= pl->ns->mapx / 2) && (abs (rv.distance_y) <= pl->ns->mapy / 2))
535 pl->do_los = 1; 542 pl->do_los = 1;
536 } 543 }
537} 544}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines