1 /*
2 * l_unlink.cc
3 * AYM 1998-11-07
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 "selectn.h"
36
37
38 /*
39 * unlink_sidedef
40 *
41 * For all linedefs in the <linedefs>, see whether the sidedefs
42 * are used by any other linedef _not_in_<linedefs>_. If they
43 * are, duplicate the sidedefs and assign the new duplicate to
44 * the linedef.
45 * If <side1> is set, take care of the first sidedef.
46 * If <side2> is set, take care of the second sidedef.
47 * Both can be set, of course.
48 *
49 * This function is intended to "unlink" duplicated linedefs.
50 */
unlink_sidedef(SelPtr linedefs,int side1,int side2)51 void unlink_sidedef (SelPtr linedefs, int side1, int side2)
52 {
53 // Array of NumSideDefs bits that tell whether the
54 // sidedef is used by the linedefs in <linedefs>.
55 bitvec_c sd_used_in (NumSideDefs);
56
57 // Array of NumSideDefs bits that tell whether the
58 // sidedef is used by the linedefs _not_ in <linedefs>.
59 bitvec_c sd_used_out (NumSideDefs);
60
61 SelPtr cur;
62 int n;
63
64 ObjectsNeeded (OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
65
66 // Put in sd_used_in a list of all sidedefs
67 // that are used by linedefs in <linedefs>.
68 // and in sd_used_out a list of all sidedefs
69 // that are used by linedefs not in <linedefs>
70
71 for (n = 0; n < NumLineDefs; n++)
72 {
73 if (IsSelected (linedefs, n))
74 {
75 if (side1 && is_sidedef (LineDefs[n].sidedef1))
76 sd_used_in.set (LineDefs[n].sidedef1);
77 if (side2 && is_sidedef (LineDefs[n].sidedef2))
78 sd_used_in.set (LineDefs[n].sidedef2);
79 }
80 else
81 {
82 if (is_sidedef (LineDefs[n].sidedef1))
83 sd_used_out.set (LineDefs[n].sidedef1);
84 if (is_sidedef (LineDefs[n].sidedef2))
85 sd_used_out.set (LineDefs[n].sidedef2);
86 }
87 }
88
89 // For all sidedefs that are used both by a linedef
90 // in <linedefs> and a linedef _not_ in <linedefs>,
91 // duplicate the sidedef and make all the linedefs
92 // in <linedefs> use the copy instead.
93
94 for (n = 0; n < NumSideDefs; n++)
95 {
96 if (sd_used_in.get (n) && sd_used_out.get (n))
97 {
98 InsertObject (OBJ_SIDEDEFS, n, 0, 0);
99 for (cur = linedefs; cur; cur = cur->next)
100 {
101 if (side1 && LineDefs[cur->objnum].sidedef1 == n)
102 LineDefs[cur->objnum].sidedef1 = NumSideDefs - 1;
103 if (side2 && LineDefs[cur->objnum].sidedef2 == n)
104 LineDefs[cur->objnum].sidedef2 = NumSideDefs - 1;
105 }
106 }
107 }
108 }
109
110
111
112
113