1 /*
2 * s_linedefs.cc
3 * AYM 1998-11-22
4 */
5
6
7 /*
8 This file is part of Yadex.
9
10 Yadex incorporates code from DEU 5.21 that was put in the public domain in
11 1994 by Rapha�l Quinet and Brendon Wyber.
12
13 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
14
15 This program is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any later
18 version.
19
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
26 Place, Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29
30 #include "yadex.h"
31 #include "bitvec.h"
32 #include "levels.h"
33 #include "objects.h"
34 #include "objid.h"
35 #include "s_linedefs.h"
36 #include "selectn.h"
37
38
39 /*
40 * linedefs_of_sector
41 * Return a bit vector of all linedefs used by the sector.
42 * It's up to the caller to delete the bit vector after use.
43 */
linedefs_of_sector(obj_no_t s)44 bitvec_c *linedefs_of_sector (obj_no_t s)
45 {
46 bitvec_c *linedefs = new bitvec_c (NumLineDefs);
47 for (int n = 0; n < NumLineDefs; n++)
48 if (is_sidedef (LineDefs[n].sidedef1)
49 && SideDefs[LineDefs[n].sidedef1].sector == s
50 || is_sidedef (LineDefs[n].sidedef2)
51 && SideDefs[LineDefs[n].sidedef2].sector == s)
52 linedefs->set (n);
53 return linedefs;
54 }
55
56
57 /*
58 * linedefs_of_sectors
59 * Return a bit vector of all linedefs used by the sectors.
60 * It's up to the caller to delete the bit vector after use.
61 */
linedefs_of_sectors(SelPtr list)62 bitvec_c *linedefs_of_sectors (SelPtr list)
63 {
64 bitvec_c *sectors = list_to_bitvec (list, NumSectors);
65 bitvec_c *linedefs = new bitvec_c (NumLineDefs);
66 for (int n = 0; n < NumLineDefs; n++)
67 if ( is_sidedef (LineDefs[n].sidedef1)
68 && sectors->get (SideDefs[LineDefs[n].sidedef1].sector)
69 || is_sidedef (LineDefs[n].sidedef2)
70 && sectors->get (SideDefs[LineDefs[n].sidedef2].sector))
71 linedefs->set (n);
72 delete sectors;
73 return linedefs;
74 }
75
76
77 /*
78 * linedefs_of_sector
79 * Returns the number of linedefs that face sector <s>
80 * and, if that number is greater than zero, sets <array>
81 * to point on a newly allocated array filled with the
82 * numbers of those linedefs. It's up to the caller to
83 * delete[] the array after use.
84 */
linedefs_of_sector(obj_no_t s,obj_no_t * & array)85 int linedefs_of_sector (obj_no_t s, obj_no_t *&array)
86 {
87 int count = 0;
88 for (int n = 0; n < NumLineDefs; n++)
89 if ( is_sidedef (LineDefs[n].sidedef1)
90 && SideDefs[LineDefs[n].sidedef1].sector == s
91 || is_sidedef (LineDefs[n].sidedef2)
92 && SideDefs[LineDefs[n].sidedef2].sector == s)
93 count++;
94 if (count > 0)
95 {
96 array = new obj_no_t[count];
97 count = 0;
98 for (int n = 0; n < NumLineDefs; n++)
99 if ( is_sidedef (LineDefs[n].sidedef1)
100 && SideDefs[LineDefs[n].sidedef1].sector == s
101 || is_sidedef (LineDefs[n].sidedef2)
102 && SideDefs[LineDefs[n].sidedef2].sector == s)
103 array[count++] = n;
104 }
105 return count;
106 }
107
108
109