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.68 by root, Sun Feb 7 04:22:32 2010 UTC vs.
Revision 1.77 by root, Sat Nov 17 23:40:00 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 6 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 7 * 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 8 * 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 9 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 10 * option) any later version.
10 * 11 *
11 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the Affero GNU General Public License 17 * 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 18 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 19 * <http://www.gnu.org/licenses/>.
19 * 20 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 22 */
22 23
23#include <global.h> 24#include <global.h>
24#include <cmath> 25#include <cmath>
51 52
52// temporary storage for the los algorithm, 53// temporary storage for the los algorithm,
53// one los_info for each lightable map space 54// one los_info for each lightable map space
54static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y]; 55static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y];
55 56
56struct point 57struct point8
57{ 58{
58 sint8 x, y; 59 sint8 x, y;
59}; 60};
60 61
61// minimum size, but must be a power of two 62// minimum size, but must be a power of two
62#define QUEUE_LENGTH ((MAP_CLIENT_X + MAP_CLIENT_Y) * 2) 63#define QUEUE_LENGTH ((MAP_CLIENT_X + MAP_CLIENT_Y) * 2)
63 64
64// a queue of spaces to calculate 65// a queue of spaces to calculate
65static point queue [QUEUE_LENGTH]; 66static point8 queue [QUEUE_LENGTH];
66static int q1, q2; // queue start, end 67static int q1, q2; // queue start, end
67 68
68/* 69/*
69 * Clears/initialises the los-array associated to the player 70 * Clears/initialises the los-array associated to the player
70 * controlling the object. 71 * controlling the object.
174 l.culled &= !xi->visible; 175 l.culled &= !xi->visible;
175 176
176 /* merge input space */ 177 /* merge input space */
177 if (expect_false (xi->xo || xi->yo)) 178 if (expect_false (xi->xo || xi->yo))
178 { 179 {
179 // The X input can provide two main pieces of information: 180 // The X input can provide two main pieces of information:
180 // 1. Progressive X obscurity. 181 // 1. Progressive X obscurity.
181 // 2. Recessive Y obscurity. 182 // 2. Recessive Y obscurity.
182 183
183 // Progressive X obscurity, favouring recessive input angle 184 // Progressive X obscurity, favouring recessive input angle
184 if (xi->xe > 0 && l.xo == 0) 185 if (xi->xe > 0 && l.xo == 0)
209 l.culled &= !yi->visible; 210 l.culled &= !yi->visible;
210 211
211 /* merge input space */ 212 /* merge input space */
212 if (expect_false (yi->yo || yi->xo)) 213 if (expect_false (yi->yo || yi->xo))
213 { 214 {
214 // The Y input can provide two main pieces of information: 215 // The Y input can provide two main pieces of information:
215 // 1. Progressive Y obscurity. 216 // 1. Progressive Y obscurity.
216 // 2. Recessive X obscurity. 217 // 2. Recessive X obscurity.
217 218
218 // Progressive Y obscurity, favouring recessive input angle 219 // Progressive Y obscurity, favouring recessive input angle
219 if (yi->ye > 0 && l.yo == 0) 220 if (yi->ye > 0 && l.yo == 0)
260 } 261 }
261 262
262 } 263 }
263 264
264 // Expands by the unit length in each component's current direction. 265 // Expands by the unit length in each component's current direction.
265 // If a component has no direction, then it is expanded in both of its 266 // If a component has no direction, then it is expanded in both of its
266 // positive and negative directions. 267 // positive and negative directions.
267 if (!l.culled) 268 if (!l.culled)
268 { 269 {
269 if (dx >= 0) enqueue (dx + 1, dy, FLG_XI); 270 if (dx >= 0) enqueue (dx + 1, dy, FLG_XI);
270 if (dx <= 0) enqueue (dx - 1, dy, FLG_XI); 271 if (dx <= 0) enqueue (dx - 1, dy, FLG_XI);
351 for (int ay = ay0; ay <= ay1; ay++) 352 for (int ay = ay0; ay <= ay1; ay++)
352 pl->los[ax][ay] = 353 pl->los[ax][ay] =
353 change_it (pl->los[ax][ay], atten_table [idistance (ax - dx, ay - dy)]); 354 change_it (pl->los[ax][ay], atten_table [idistance (ax - dx, ay - dy)]);
354} 355}
355 356
356/* add light, by finding all (non-null) nearby light sources, then 357/* add light, by finding all (non-null) nearby light sources, then
357 * mark those squares specially. 358 * mark those squares specially.
358 */ 359 */
359static void 360static void
360apply_lights (player *pl) 361apply_lights (player *pl)
361{ 362{
448 apply_light<los_darken> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); 449 apply_light<los_darken> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, -light, light_atten [light + MAX_LIGHT_RADIUS]);
449 } 450 }
450 } 451 }
451} 452}
452 453
453/* blinded_sight() - sets all viewable squares to blocked except 454/* blinded_sight() - sets all viewable squares to blocked except
454 * for the one the central one that the player occupies. A little 455 * for the one the central one that the player occupies. A little
455 * odd that you can see yourself (and what your standing on), but 456 * odd that you can see yourself (and what your standing on), but
456 * really need for any reasonable game play. 457 * really need for any reasonable game play.
457 */ 458 */
458static void 459static void
534 if (!pl->ob || !pl->ob->map || !pl->ns) 535 if (!pl->ob || !pl->ob->map || !pl->ns)
535 continue; 536 continue;
536 537
537 rv_vector rv; 538 rv_vector rv;
538 539
539 get_rangevector_from_mapcoord (map, x, y, pl->ob, &rv); 540 get_rangevector_from_mapcoord (pl->ob->map, x, y, pl->ob, &rv);
540 541
541 if ((abs (rv.distance_x) <= pl->ns->mapx / 2) && (abs (rv.distance_y) <= pl->ns->mapy / 2)) 542 if ((abs (rv.distance_x) <= pl->ns->mapx / 2) && (abs (rv.distance_y) <= pl->ns->mapy / 2))
542 pl->do_los = 1; 543 pl->do_los = 1;
543 } 544 }
544} 545}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines