├── .gitignore ├── 2dclip.cpp ├── 2dclip.h ├── COPYING ├── FUNK.WAD ├── Makefile ├── README.md ├── clip_ssectors.cpp ├── clip_ssectors.h ├── convert.cpp ├── convert.h ├── defs.h ├── doomlevel.h ├── dumpmap.cpp ├── dumpmap.h ├── entities.list ├── entities.list.template ├── globals.h ├── progress.cpp ├── progress.h ├── stdafx.cpp ├── stdafx.h ├── subtract_ssectors.cpp ├── subtract_ssectors.h ├── things.cpp ├── things.h ├── types.h ├── wad2map-todo.txt ├── wad2map.cpp ├── wad2map.dsp ├── wad2map.dsw ├── wad2map.opt ├── wad2map.txt ├── wadentries.cpp ├── wadentries.h ├── wadfile.cpp └── wadfile.h /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | wad2map 4 | -------------------------------------------------------------------------------- /2dclip.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | 2dclip.cpp 23 | 24 | Ted Mielczarek 25 | 12/10/1999 26 | 27 | This file contains the 2d clipping routines for forming ssectors. 28 | */ 29 | 30 | #include "stdafx.h" 31 | #include 32 | #include "2dclip.h" 33 | 34 | // find out which side of a line a point is on 35 | side PointLocation(point_t *p, line_t *l) 36 | { 37 | coord lofq; 38 | point_t v; 39 | 40 | // get a vector from line to point 41 | v.x = p->x - l->p.x; 42 | v.y = p->y - l->p.y; 43 | 44 | lofq = DOT_PROD(v,l->n); 45 | 46 | if(lofq < 0) 47 | return(left_side); 48 | 49 | if(lofq > 0) 50 | return(right_side); 51 | 52 | return(on_line); 53 | } 54 | 55 | /* 56 | PointInPoly 57 | 58 | Determine if the point p lies within the poly s 59 | */ 60 | bool PointInPoly(point_t *p, poly_t *s) 61 | { 62 | line_t l; 63 | int i; 64 | 65 | for(i=0;inum_verts-1;i++) { 66 | LineFromPoints(&l,s->p+i); 67 | if(PointLocation(p,&l) == left_side) 68 | return(false); 69 | } 70 | 71 | return(true); 72 | } 73 | 74 | bool IntersectPoint(line_t *l, point_t l2[2], point_t *result) 75 | { 76 | point_t d; 77 | double t; 78 | 79 | // get direction vector for l2 (the line segment 80 | d.x = l2[1].x - l2[0].x; 81 | d.y = l2[1].y - l2[0].y; 82 | 83 | // are the lines parallel? 84 | if(DOT_PROD(l->n,d) == 0) 85 | return(false); 86 | 87 | t = double(DOT_PROD(l->n,l->p) - DOT_PROD(l->n,l2[0])) / double(DOT_PROD(l->n,d)); 88 | 89 | if(t < 0 || t > 1) { 90 | // outside the line segment 91 | return(false); 92 | } 93 | 94 | // get intersect point 95 | #ifdef USE_FLOATING_POINT 96 | result->x = l2[0].x + t*d.x; 97 | result->y = l2[0].y + t*d.y; 98 | #else 99 | // if using int, round correctly 100 | result->x = int(floor(l2[0].x + t*d.x + 0.5)); 101 | result->y = int(floor(l2[0].y + t*d.y + 0.5)); 102 | #endif 103 | 104 | return(true); 105 | } 106 | 107 | void LineFromPoints(line_t *l, point_t p[2]) 108 | { 109 | // copy point A p[0] 110 | memcpy(&l->p,&p[0],sizeof(point_t)); 111 | 112 | // calc normal vector: 113 | // use negative inverse slope of direction vector 114 | l->n.x = p[1].y - p[0].y; 115 | l->n.y = -1*(p[1].x - p[0].x); 116 | } 117 | 118 | bool ClipPolyToLine(poly_t *poly, line_t *l, side keep) 119 | { 120 | int i; 121 | poly_t newpoly; 122 | point_t pt, tmp[2]; 123 | side from,to,drop; 124 | 125 | memset(&newpoly,0,sizeof(newpoly)); 126 | drop = OppositeSide(keep); 127 | 128 | // check first point 129 | if(PointLocation(&poly->p[0],l) != drop) 130 | memcpy(&newpoly.p[newpoly.num_verts++],&poly->p[0],sizeof(point_t)); 131 | 132 | // cycle thru poly points 133 | for(i=0;inum_verts-1;i++) { 134 | from = PointLocation(&poly->p[i],l); 135 | to = PointLocation(&poly->p[i+1],l); 136 | if(from != drop) { 137 | if(to != drop) 138 | // crosses in to in 139 | memcpy(&newpoly.p[newpoly.num_verts++],&poly->p[i+1],sizeof(point_t)); 140 | else { 141 | // check for points on line... 142 | if(from != on_line) { 143 | // crosses in to out, save crossing 144 | if(IntersectPoint(l,&poly->p[i],&pt)) 145 | memcpy(&newpoly.p[newpoly.num_verts++],&pt,sizeof(point_t)); 146 | } 147 | } 148 | } 149 | else { 150 | if(to != drop) { 151 | if(to != on_line) { 152 | // crosses out to in, save intersect point and "to" point 153 | if(IntersectPoint(l,&poly->p[i],&pt)) 154 | memcpy(&newpoly.p[newpoly.num_verts++],&pt,sizeof(point_t)); 155 | } 156 | // out to in, or out to on line, save 'to' 157 | memcpy(&newpoly.p[newpoly.num_verts++],&poly->p[i+1],sizeof(point_t)); 158 | } 159 | // out to out, save nothing 160 | } 161 | } 162 | 163 | // check last point to first point 164 | from = PointLocation(&poly->p[poly->num_verts-1],l); 165 | to = PointLocation(&poly->p[0],l); 166 | memcpy(tmp,&poly->p[poly->num_verts-1],sizeof(point_t)*2); 167 | memcpy(&tmp[1],&poly->p[0],sizeof(point_t)); 168 | if(from != drop) { 169 | if(to == drop) { 170 | // check for points on line... 171 | if(from != on_line) { 172 | // crosses in to out, save crossing 173 | if(IntersectPoint(l,tmp,&pt)) 174 | memcpy(&newpoly.p[newpoly.num_verts++],&pt,sizeof(point_t)); 175 | } 176 | } 177 | } 178 | else { 179 | if(to != drop) { 180 | if(to != on_line) { 181 | // crosses out to in, save intersect point 182 | if(IntersectPoint(l,tmp,&pt)) 183 | memcpy(&newpoly.p[newpoly.num_verts++],&pt,sizeof(point_t)); 184 | } 185 | } 186 | // out to out, save nothing 187 | } 188 | 189 | // check to see if all that's left is points on the line. this could screw stuff up. 190 | from = on_line; 191 | for(i=0;inum_verts > 2); 206 | } 207 | 208 | side OppositeSide(side s) 209 | { 210 | if(s == right_side) 211 | return(left_side); 212 | 213 | if(s == left_side) 214 | return(right_side); 215 | 216 | return(s); 217 | } 218 | 219 | /* 220 | CheckPolys 221 | 222 | Check all polys for duplicate vertices. 223 | 224 | Parameters: 225 | p: Array of polys to check 226 | n: Number of polys in array 227 | */ 228 | void CheckPolys(poly_t *p, int n) 229 | { 230 | int i,j,k; 231 | 232 | for(i=0;inum_verts < 3) { 268 | memset(p,0,sizeof(poly_t)); 269 | return(false); 270 | } 271 | 272 | for(j=0;jnum_verts-1;j++) { 273 | for(k=j;knum_verts;k++) { 274 | if(j==k) 275 | continue; 276 | if(PointsEqual(&p->p[j], &p->p[k])) { 277 | // degenerate poly! 278 | if(p->num_verts <= 3) { 279 | memset(p,0,sizeof(poly_t)); 280 | return(false); 281 | } 282 | RemovePoint(p,k); 283 | } 284 | } 285 | } 286 | 287 | // check to see if all points are colinear 288 | LineFromPoints(&l,p->p); 289 | isOk = false; 290 | for(j=2;jnum_verts;j++) { 291 | if(PointLocation(p->p+j,&l) != on_line) { 292 | isOk = true; 293 | break; 294 | } 295 | } 296 | 297 | return(isOk); 298 | } 299 | 300 | bool PointsEqual(point_t *p1, point_t *p2) 301 | { 302 | #ifdef USE_FLOATING_POINT 303 | if((fabs(p1->x - p2->x) < 0.1) && (fabs(p1->y - p2->y) < 0.1)) 304 | #else 305 | if(abs(p1->x - p2->x) < 3 && abs(p1->y - p2->y) < 3) 306 | #endif 307 | //if(p1->x == p2->x && p1->y == p2->y) 308 | return(true); 309 | 310 | return(false); 311 | } 312 | 313 | void RemovePoint(poly_t *p, int n) 314 | { 315 | int i,j; 316 | 317 | // number of verts after this 318 | i = p->num_verts - n - 1; 319 | 320 | // if any, move points back 321 | if(i > 0) 322 | for(j=0;jp[j+n],&p->p[j+n+1],sizeof(point_t)); 324 | 325 | // zero out last vertex 326 | p->p[p->num_verts - 1].x = 0; 327 | p->p[p->num_verts - 1].y = 0; 328 | 329 | // one less point 330 | p->num_verts--; 331 | } 332 | 333 | /* 334 | printpoint 335 | 336 | Print a point to a string as (x, y) 337 | */ 338 | void printpoint(char *s, point_t *p) 339 | { 340 | sprintf(s,"("CSPEC", "CSPEC")",p->x,p->y); 341 | } 342 | 343 | /* 344 | DumpPoly 345 | 346 | Dump all points in a poly to a file. 347 | */ 348 | void DumpPoly(FILE *f, poly_t *p) 349 | { 350 | int i; 351 | char szTmp[256]; 352 | 353 | for(i=0;inum_verts;i++) { 354 | printpoint(szTmp,p->p+i); 355 | fprintf(f,"%s, ",szTmp); 356 | } 357 | fprintf(f,"\n"); 358 | } 359 | -------------------------------------------------------------------------------- /2dclip.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | 2dclip.h 23 | 24 | Ted Mielczarek 25 | 12/10/1999 26 | 27 | This file contains prototypes for the functions in 2dclip.cpp, which 28 | are 2d clipping routines. 29 | */ 30 | #ifndef __2DCLIP_H_ 31 | #define __2DCLIP_H_ 32 | 33 | #include "types.h" 34 | 35 | typedef enum { 36 | on_line, 37 | left_side, 38 | right_side 39 | } side; 40 | 41 | // dot product macro 42 | #define DOT_PROD(a,b) ((a.x) * (b.x) + (a.y) * (b.y)) 43 | 44 | side PointLocation(point_t *p, line_t *l); 45 | bool PointInPoly(point_t *p, poly_t *s); 46 | bool IntersectPoint(line_t *l, point_t l2[2], point_t *result); 47 | void LineFromPoints(line_t *l, point_t p[2]); 48 | bool ClipPolyToLine(poly_t *poly, line_t *l, side keep); 49 | void CheckPolys(poly_t *p, int n); 50 | bool CheckPoly(poly_t *p); 51 | bool PointsEqual(point_t *p1, point_t *p2); 52 | void RemovePoint(poly_t *p, int n); 53 | void printpoint(char *s, point_t *p); 54 | void DumpPoly(FILE *f, poly_t *p); 55 | side OppositeSide(side s); 56 | 57 | #endif /* __2DCLIP_H_ */ 58 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 2, June 1991 4 | 5 | 6 | 7 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 8 | 9 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 10 | 11 | Everyone is permitted to copy and distribute verbatim copies 12 | 13 | of this license document, but changing it is not allowed. 14 | 15 | 16 | 17 | Preamble 18 | 19 | 20 | 21 | The licenses for most software are designed to take away your 22 | 23 | freedom to share and change it. By contrast, the GNU General Public 24 | 25 | License is intended to guarantee your freedom to share and change free 26 | 27 | software--to make sure the software is free for all its users. This 28 | 29 | General Public License applies to most of the Free Software 30 | 31 | Foundation's software and to any other program whose authors commit to 32 | 33 | using it. (Some other Free Software Foundation software is covered by 34 | 35 | the GNU Library General Public License instead.) You can apply it to 36 | 37 | your programs, too. 38 | 39 | 40 | 41 | When we speak of free software, we are referring to freedom, not 42 | 43 | price. Our General Public Licenses are designed to make sure that you 44 | 45 | have the freedom to distribute copies of free software (and charge for 46 | 47 | this service if you wish), that you receive source code or can get it 48 | 49 | if you want it, that you can change the software or use pieces of it 50 | 51 | in new free programs; and that you know you can do these things. 52 | 53 | 54 | 55 | To protect your rights, we need to make restrictions that forbid 56 | 57 | anyone to deny you these rights or to ask you to surrender the rights. 58 | 59 | These restrictions translate to certain responsibilities for you if you 60 | 61 | distribute copies of the software, or if you modify it. 62 | 63 | 64 | 65 | For example, if you distribute copies of such a program, whether 66 | 67 | gratis or for a fee, you must give the recipients all the rights that 68 | 69 | you have. You must make sure that they, too, receive or can get the 70 | 71 | source code. And you must show them these terms so they know their 72 | 73 | rights. 74 | 75 | 76 | 77 | We protect your rights with two steps: (1) copyright the software, and 78 | 79 | (2) offer you this license which gives you legal permission to copy, 80 | 81 | distribute and/or modify the software. 82 | 83 | 84 | 85 | Also, for each author's protection and ours, we want to make certain 86 | 87 | that everyone understands that there is no warranty for this free 88 | 89 | software. If the software is modified by someone else and passed on, we 90 | 91 | want its recipients to know that what they have is not the original, so 92 | 93 | that any problems introduced by others will not reflect on the original 94 | 95 | authors' reputations. 96 | 97 | 98 | 99 | Finally, any free program is threatened constantly by software 100 | 101 | patents. We wish to avoid the danger that redistributors of a free 102 | 103 | program will individually obtain patent licenses, in effect making the 104 | 105 | program proprietary. To prevent this, we have made it clear that any 106 | 107 | patent must be licensed for everyone's free use or not licensed at all. 108 | 109 | 110 | 111 | The precise terms and conditions for copying, distribution and 112 | 113 | modification follow. 114 | 115 | 116 | 117 | GNU GENERAL PUBLIC LICENSE 118 | 119 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 120 | 121 | 122 | 123 | 0. This License applies to any program or other work which contains 124 | 125 | a notice placed by the copyright holder saying it may be distributed 126 | 127 | under the terms of this General Public License. The "Program", below, 128 | 129 | refers to any such program or work, and a "work based on the Program" 130 | 131 | means either the Program or any derivative work under copyright law: 132 | 133 | that is to say, a work containing the Program or a portion of it, 134 | 135 | either verbatim or with modifications and/or translated into another 136 | 137 | language. (Hereinafter, translation is included without limitation in 138 | 139 | the term "modification".) Each licensee is addressed as "you". 140 | 141 | 142 | 143 | Activities other than copying, distribution and modification are not 144 | 145 | covered by this License; they are outside its scope. The act of 146 | 147 | running the Program is not restricted, and the output from the Program 148 | 149 | is covered only if its contents constitute a work based on the 150 | 151 | Program (independent of having been made by running the Program). 152 | 153 | Whether that is true depends on what the Program does. 154 | 155 | 156 | 157 | 1. You may copy and distribute verbatim copies of the Program's 158 | 159 | source code as you receive it, in any medium, provided that you 160 | 161 | conspicuously and appropriately publish on each copy an appropriate 162 | 163 | copyright notice and disclaimer of warranty; keep intact all the 164 | 165 | notices that refer to this License and to the absence of any warranty; 166 | 167 | and give any other recipients of the Program a copy of this License 168 | 169 | along with the Program. 170 | 171 | 172 | 173 | You may charge a fee for the physical act of transferring a copy, and 174 | 175 | you may at your option offer warranty protection in exchange for a fee. 176 | 177 | 178 | 179 | 2. You may modify your copy or copies of the Program or any portion 180 | 181 | of it, thus forming a work based on the Program, and copy and 182 | 183 | distribute such modifications or work under the terms of Section 1 184 | 185 | above, provided that you also meet all of these conditions: 186 | 187 | 188 | 189 | a) You must cause the modified files to carry prominent notices 190 | 191 | stating that you changed the files and the date of any change. 192 | 193 | 194 | 195 | b) You must cause any work that you distribute or publish, that in 196 | 197 | whole or in part contains or is derived from the Program or any 198 | 199 | part thereof, to be licensed as a whole at no charge to all third 200 | 201 | parties under the terms of this License. 202 | 203 | 204 | 205 | c) If the modified program normally reads commands interactively 206 | 207 | when run, you must cause it, when started running for such 208 | 209 | interactive use in the most ordinary way, to print or display an 210 | 211 | announcement including an appropriate copyright notice and a 212 | 213 | notice that there is no warranty (or else, saying that you provide 214 | 215 | a warranty) and that users may redistribute the program under 216 | 217 | these conditions, and telling the user how to view a copy of this 218 | 219 | License. (Exception: if the Program itself is interactive but 220 | 221 | does not normally print such an announcement, your work based on 222 | 223 | the Program is not required to print an announcement.) 224 | 225 | 226 | 227 | These requirements apply to the modified work as a whole. If 228 | 229 | identifiable sections of that work are not derived from the Program, 230 | 231 | and can be reasonably considered independent and separate works in 232 | 233 | themselves, then this License, and its terms, do not apply to those 234 | 235 | sections when you distribute them as separate works. But when you 236 | 237 | distribute the same sections as part of a whole which is a work based 238 | 239 | on the Program, the distribution of the whole must be on the terms of 240 | 241 | this License, whose permissions for other licensees extend to the 242 | 243 | entire whole, and thus to each and every part regardless of who wrote it. 244 | 245 | 246 | 247 | Thus, it is not the intent of this section to claim rights or contest 248 | 249 | your rights to work written entirely by you; rather, the intent is to 250 | 251 | exercise the right to control the distribution of derivative or 252 | 253 | collective works based on the Program. 254 | 255 | 256 | 257 | In addition, mere aggregation of another work not based on the Program 258 | 259 | with the Program (or with a work based on the Program) on a volume of 260 | 261 | a storage or distribution medium does not bring the other work under 262 | 263 | the scope of this License. 264 | 265 | 266 | 267 | 3. You may copy and distribute the Program (or a work based on it, 268 | 269 | under Section 2) in object code or executable form under the terms of 270 | 271 | Sections 1 and 2 above provided that you also do one of the following: 272 | 273 | 274 | 275 | a) Accompany it with the complete corresponding machine-readable 276 | 277 | source code, which must be distributed under the terms of Sections 278 | 279 | 1 and 2 above on a medium customarily used for software interchange; or, 280 | 281 | 282 | 283 | b) Accompany it with a written offer, valid for at least three 284 | 285 | years, to give any third party, for a charge no more than your 286 | 287 | cost of physically performing source distribution, a complete 288 | 289 | machine-readable copy of the corresponding source code, to be 290 | 291 | distributed under the terms of Sections 1 and 2 above on a medium 292 | 293 | customarily used for software interchange; or, 294 | 295 | 296 | 297 | c) Accompany it with the information you received as to the offer 298 | 299 | to distribute corresponding source code. (This alternative is 300 | 301 | allowed only for noncommercial distribution and only if you 302 | 303 | received the program in object code or executable form with such 304 | 305 | an offer, in accord with Subsection b above.) 306 | 307 | 308 | 309 | The source code for a work means the preferred form of the work for 310 | 311 | making modifications to it. For an executable work, complete source 312 | 313 | code means all the source code for all modules it contains, plus any 314 | 315 | associated interface definition files, plus the scripts used to 316 | 317 | control compilation and installation of the executable. However, as a 318 | 319 | special exception, the source code distributed need not include 320 | 321 | anything that is normally distributed (in either source or binary 322 | 323 | form) with the major components (compiler, kernel, and so on) of the 324 | 325 | operating system on which the executable runs, unless that component 326 | 327 | itself accompanies the executable. 328 | 329 | 330 | 331 | If distribution of executable or object code is made by offering 332 | 333 | access to copy from a designated place, then offering equivalent 334 | 335 | access to copy the source code from the same place counts as 336 | 337 | distribution of the source code, even though third parties are not 338 | 339 | compelled to copy the source along with the object code. 340 | 341 | 342 | 343 | 4. You may not copy, modify, sublicense, or distribute the Program 344 | 345 | except as expressly provided under this License. Any attempt 346 | 347 | otherwise to copy, modify, sublicense or distribute the Program is 348 | 349 | void, and will automatically terminate your rights under this License. 350 | 351 | However, parties who have received copies, or rights, from you under 352 | 353 | this License will not have their licenses terminated so long as such 354 | 355 | parties remain in full compliance. 356 | 357 | 358 | 359 | 5. You are not required to accept this License, since you have not 360 | 361 | signed it. However, nothing else grants you permission to modify or 362 | 363 | distribute the Program or its derivative works. These actions are 364 | 365 | prohibited by law if you do not accept this License. Therefore, by 366 | 367 | modifying or distributing the Program (or any work based on the 368 | 369 | Program), you indicate your acceptance of this License to do so, and 370 | 371 | all its terms and conditions for copying, distributing or modifying 372 | 373 | the Program or works based on it. 374 | 375 | 376 | 377 | 6. Each time you redistribute the Program (or any work based on the 378 | 379 | Program), the recipient automatically receives a license from the 380 | 381 | original licensor to copy, distribute or modify the Program subject to 382 | 383 | these terms and conditions. You may not impose any further 384 | 385 | restrictions on the recipients' exercise of the rights granted herein. 386 | 387 | You are not responsible for enforcing compliance by third parties to 388 | 389 | this License. 390 | 391 | 392 | 393 | 7. If, as a consequence of a court judgment or allegation of patent 394 | 395 | infringement or for any other reason (not limited to patent issues), 396 | 397 | conditions are imposed on you (whether by court order, agreement or 398 | 399 | otherwise) that contradict the conditions of this License, they do not 400 | 401 | excuse you from the conditions of this License. If you cannot 402 | 403 | distribute so as to satisfy simultaneously your obligations under this 404 | 405 | License and any other pertinent obligations, then as a consequence you 406 | 407 | may not distribute the Program at all. For example, if a patent 408 | 409 | license would not permit royalty-free redistribution of the Program by 410 | 411 | all those who receive copies directly or indirectly through you, then 412 | 413 | the only way you could satisfy both it and this License would be to 414 | 415 | refrain entirely from distribution of the Program. 416 | 417 | 418 | 419 | If any portion of this section is held invalid or unenforceable under 420 | 421 | any particular circumstance, the balance of the section is intended to 422 | 423 | apply and the section as a whole is intended to apply in other 424 | 425 | circumstances. 426 | 427 | 428 | 429 | It is not the purpose of this section to induce you to infringe any 430 | 431 | patents or other property right claims or to contest validity of any 432 | 433 | such claims; this section has the sole purpose of protecting the 434 | 435 | integrity of the free software distribution system, which is 436 | 437 | implemented by public license practices. Many people have made 438 | 439 | generous contributions to the wide range of software distributed 440 | 441 | through that system in reliance on consistent application of that 442 | 443 | system; it is up to the author/donor to decide if he or she is willing 444 | 445 | to distribute software through any other system and a licensee cannot 446 | 447 | impose that choice. 448 | 449 | 450 | 451 | This section is intended to make thoroughly clear what is believed to 452 | 453 | be a consequence of the rest of this License. 454 | 455 | 456 | 457 | 8. If the distribution and/or use of the Program is restricted in 458 | 459 | certain countries either by patents or by copyrighted interfaces, the 460 | 461 | original copyright holder who places the Program under this License 462 | 463 | may add an explicit geographical distribution limitation excluding 464 | 465 | those countries, so that distribution is permitted only in or among 466 | 467 | countries not thus excluded. In such case, this License incorporates 468 | 469 | the limitation as if written in the body of this License. 470 | 471 | 472 | 473 | 9. The Free Software Foundation may publish revised and/or new versions 474 | 475 | of the General Public License from time to time. Such new versions will 476 | 477 | be similar in spirit to the present version, but may differ in detail to 478 | 479 | address new problems or concerns. 480 | 481 | 482 | 483 | Each version is given a distinguishing version number. If the Program 484 | 485 | specifies a version number of this License which applies to it and "any 486 | 487 | later version", you have the option of following the terms and conditions 488 | 489 | either of that version or of any later version published by the Free 490 | 491 | Software Foundation. If the Program does not specify a version number of 492 | 493 | this License, you may choose any version ever published by the Free Software 494 | 495 | Foundation. 496 | 497 | 498 | 499 | 10. If you wish to incorporate parts of the Program into other free 500 | 501 | programs whose distribution conditions are different, write to the author 502 | 503 | to ask for permission. For software which is copyrighted by the Free 504 | 505 | Software Foundation, write to the Free Software Foundation; we sometimes 506 | 507 | make exceptions for this. Our decision will be guided by the two goals 508 | 509 | of preserving the free status of all derivatives of our free software and 510 | 511 | of promoting the sharing and reuse of software generally. 512 | 513 | 514 | 515 | NO WARRANTY 516 | 517 | 518 | 519 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 520 | 521 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 522 | 523 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 524 | 525 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 526 | 527 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 528 | 529 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 530 | 531 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 532 | 533 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 534 | 535 | REPAIR OR CORRECTION. 536 | 537 | 538 | 539 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 540 | 541 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 542 | 543 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 544 | 545 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 546 | 547 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 548 | 549 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 550 | 551 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 552 | 553 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 554 | 555 | POSSIBILITY OF SUCH DAMAGES. 556 | 557 | 558 | 559 | END OF TERMS AND CONDITIONS 560 | 561 | 562 | -------------------------------------------------------------------------------- /FUNK.WAD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luser/wad2map/19ce39d2f26d789cebb40b17eb7f35dff231880e/FUNK.WAD -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SOURCES := \ 2 | 2dclip.cpp \ 3 | clip_ssectors.cpp \ 4 | convert.cpp \ 5 | dumpmap.cpp \ 6 | progress.cpp \ 7 | stdafx.cpp \ 8 | subtract_ssectors.cpp \ 9 | things.cpp \ 10 | wad2map.cpp \ 11 | wadentries.cpp \ 12 | wadfile.cpp \ 13 | $(NULL) 14 | OBJS := $(SOURCES:.cpp=.o) 15 | 16 | CXXFLAGS := -g -O2 17 | 18 | BIN := wad2map 19 | 20 | $(BIN): $(OBJS) 21 | $(CXX) -o $@ $^ 22 | 23 | clean: 24 | rm -f $(BIN) $(OBJS) 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This program converts Doom levels from WAD files into Quake .map files (which need to be further compiled to actually be played in the Quake engine). 2 | 3 | This is some really old code I wrote back in 1999. I've fixed a few things so that it compiles with modern clang on OS X, and it looks like it still works, but YMMV. 4 | 5 | Copyright (C) 2016 Ted Mielczarek 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -------------------------------------------------------------------------------- /clip_ssectors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | clip_ssectors.cpp 23 | 24 | Ted Mielczarek 25 | 12-13-1999 26 | 27 | This file clips the ssectors using each node division line traversing the node tree until 28 | a ssector is hit, and then clips the ssector to the bounding segs of the ssector. 29 | */ 30 | #include "stdafx.h" 31 | #include "defs.h" 32 | #include "types.h" 33 | #include "2dclip.h" 34 | #include "doomlevel.h" 35 | #include "wadfile.h" 36 | #include "wadentries.h" 37 | #include "clip_ssectors.h" 38 | #include "progress.h" 39 | 40 | int ssDone; 41 | 42 | /* 43 | ClipSectors 44 | 45 | Take a doom level, and generate polygons of the ssectors. 46 | 47 | Parameters: 48 | level: Level data for the doom map. 49 | polys: An array of pointers to polys to fill. 50 | */ 51 | bool ClipSsectors(level_t *level, poly_t *polys) 52 | { 53 | poly_t thePoly; 54 | 55 | MakeWorldPoly(&thePoly,level); 56 | 57 | printf("Creating ssectors: "); 58 | // draw a progress bar to be nice 59 | InitProgress(20,'*',true); 60 | //DrawProgress(level->n_ssectors,0); 61 | ssDone = 0; 62 | // walk bsp tree 63 | RecurseNodes(level->nodes + (level->n_nodes - 1),&thePoly,level,polys); 64 | 65 | printf("\n"); 66 | // check all ssectors 67 | for(int i=0;in_ssectors;i++) { 68 | CheckPoly(polys+i); 69 | if(polys[i].num_verts < 3) 70 | OutputDebugString("Bad ssector\n"); 71 | } 72 | 73 | return(true); 74 | } 75 | 76 | void MakeWorldPoly(poly_t *thePoly, level_t *level) 77 | { 78 | // init thePoly to be a rectangle encompassing the entire level, with a 16 unit border 79 | memset(thePoly,0,sizeof(poly_t)); 80 | thePoly->num_verts = 4; 81 | thePoly->p[0].x = level->x_center - level->l_width / 2 - 16; 82 | thePoly->p[0].y = level->y_center - level->l_height / 2 - 16; 83 | thePoly->p[1].x = level->x_center - level->l_width / 2 - 16; 84 | thePoly->p[1].y = level->y_center + level->l_height / 2 + 16; 85 | thePoly->p[2].x = level->x_center + level->l_width / 2 + 16; 86 | thePoly->p[2].y = level->y_center + level->l_height / 2 + 16; 87 | thePoly->p[3].x = level->x_center + level->l_width / 2 + 16; 88 | thePoly->p[3].y = level->y_center - level->l_height / 2 - 16; 89 | } 90 | 91 | /* 92 | RecurseNodes 93 | 94 | Traverse the bsp tree, using node division lines to clip away at a polygon until 95 | it hits a ssector, then use the segs bounding that ssector to clip the rest of it. 96 | 97 | Parameters: 98 | node: The current node of the bsp tree. 99 | thePoly: The current polygon being clipped. 100 | level: The doom level data. 101 | polys: The full set of polys being created for this level. 102 | */ 103 | bool RecurseNodes(node_t *node, poly_t *thePoly, level_t *level, poly_t *polys) 104 | { 105 | poly_t newPoly; 106 | point_t p[2]; 107 | line_t l; 108 | segment_t *s; 109 | int i; 110 | short ssnum; 111 | 112 | //*********** 113 | // Left Child 114 | //*********** 115 | // copy poly 116 | memcpy(&newPoly,thePoly,sizeof(poly_t)); 117 | // clip it to the node split line and 118 | p[0].x = node->x; 119 | p[0].y = node->y; 120 | p[1].x = node->x + node->dx; 121 | p[1].y = node->y + node->dy; 122 | LineFromPoints(&l,p); 123 | ClipPolyToLine(&newPoly,&l,left_side); 124 | // is left node a ssector? 125 | if(node->left_child & 0x8000) { 126 | // clip it to the segs 127 | ssnum = node->left_child & 0x7FFF; 128 | for(i=0, s = &level->segs[level->ssectors[ssnum].startseg]; 129 | issectors[ssnum].numsegs; i++,s++) { 130 | // make clip line from seg 131 | p[0].x = level->vertices[s->from_vertex].x; 132 | p[0].y = level->vertices[s->from_vertex].y; 133 | p[1].x = level->vertices[s->to_vertex].x; 134 | p[1].y = level->vertices[s->to_vertex].y; 135 | LineFromPoints(&l,p); 136 | ClipPolyToLine(&newPoly,&l,right_side); 137 | } 138 | // set which sector this is part of 139 | if(level->ssectors[ssnum].numsegs > 0) { 140 | short segnum,linenum,sidenum; 141 | 142 | // could do this in one line, but it's ugly 143 | segnum = level->ssectors[ssnum].startseg; 144 | linenum = level->segs[segnum].linedef; 145 | sidenum = level->linedefs[linenum].sidedefs[level->segs[segnum].side]; 146 | newPoly.sector = level->sidedefs[sidenum].sector; 147 | } 148 | else 149 | newPoly.sector = -1; 150 | // now add it to the list of polys 151 | memcpy(&polys[ssnum],&newPoly,sizeof(poly_t)); 152 | ssDone++; 153 | // draw progress meter 154 | DrawProgress(level->n_ssectors,ssDone); 155 | } 156 | else { 157 | // otherwise, recurse 158 | RecurseNodes(&level->nodes[node->left_child],&newPoly,level,polys); 159 | } 160 | 161 | 162 | //*********** 163 | // Right Child 164 | //*********** 165 | // copy poly 166 | memcpy(&newPoly,thePoly,sizeof(poly_t)); 167 | // clip it to the node split line 168 | p[0].x = node->x; 169 | p[0].y = node->y; 170 | p[1].x = node->x + node->dx; 171 | p[1].y = node->y + node->dy; 172 | LineFromPoints(&l,p); 173 | ClipPolyToLine(&newPoly,&l,right_side); 174 | // is left node a ssector? 175 | if(node->right_child & 0x8000) { 176 | // clip it to the segs 177 | ssnum = node->right_child & 0x7FFF; 178 | for(i=0, s = &level->segs[level->ssectors[ssnum].startseg]; 179 | issectors[ssnum].numsegs; i++,s++) { 180 | // make clip line from seg 181 | p[0].x = level->vertices[s->from_vertex].x; 182 | p[0].y = level->vertices[s->from_vertex].y; 183 | p[1].x = level->vertices[s->to_vertex].x; 184 | p[1].y = level->vertices[s->to_vertex].y; 185 | LineFromPoints(&l,p); 186 | ClipPolyToLine(&newPoly,&l,right_side); 187 | } 188 | // set which sector this is part of 189 | if(level->ssectors[ssnum].numsegs > 0) { 190 | short segnum,linenum,sidenum; 191 | 192 | // could do this in one line, but it's ugly 193 | segnum = level->ssectors[ssnum].startseg; 194 | linenum = level->segs[segnum].linedef; 195 | sidenum = level->linedefs[linenum].sidedefs[level->segs[segnum].side]; 196 | newPoly.sector = level->sidedefs[sidenum].sector; 197 | } 198 | else 199 | newPoly.sector = -1; 200 | // now add it to the list of polys 201 | memcpy(&polys[ssnum],&newPoly,sizeof(poly_t)); 202 | ssDone++; 203 | // draw progress meter 204 | DrawProgress(level->n_ssectors,ssDone); 205 | } 206 | else { 207 | // recurse 208 | RecurseNodes(&level->nodes[node->right_child],&newPoly,level,polys); 209 | } 210 | 211 | return(true); 212 | } 213 | -------------------------------------------------------------------------------- /clip_ssectors.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | clip_ssectors.h 23 | 24 | Ted Mielczarek 25 | 12-13-1999 26 | 27 | This file contains the prototypes for the ssector clipping code. 28 | */ 29 | #ifndef __CLIP_SSECTORS_H_ 30 | #define __CLIP_SSECTORS_H_ 31 | 32 | bool ClipSsectors(level_t *level, poly_t *polys); 33 | void MakeWorldPoly(poly_t *thePoly, level_t *level); 34 | bool RecurseNodes(node_t *node, poly_t *thePoly, level_t *level, poly_t *polys); 35 | 36 | #endif /* __CLIP_SSECTORS_H_ */ 37 | -------------------------------------------------------------------------------- /convert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | convert.cpp 23 | 24 | Ted Mielczarek 25 | 1-13-2000 26 | 27 | This file contains the main routines for running through the conversion process. 28 | */ 29 | 30 | #include "stdafx.h" 31 | #include "defs.h" 32 | #include "wadfile.h" 33 | #include "convert.h" 34 | #include "types.h" 35 | #include "doomlevel.h" 36 | #include "wadentries.h" 37 | #include "clip_ssectors.h" 38 | #include "subtract_ssectors.h" 39 | #include "dumpmap.h" 40 | #include "globals.h" 41 | 42 | void strupper(char *s); 43 | 44 | bool DoConversion(CWadFile &wadFile) 45 | { 46 | levelentries le = W_NOT_LEVEL_ENTRY; 47 | char szEntry[256]; 48 | bool outOfEntries = false; 49 | // level data 50 | level_t level; 51 | poly_t *polys; 52 | poly_t *world; 53 | int nWorld; 54 | 55 | // no mapname specified, get first map 56 | if(mapname[0] == '\0') { 57 | wadFile.SeekFirst(szEntry); 58 | le = LookupLevelEntry(szEntry); 59 | while(le != W_D1LEVEL && le != W_D2LEVEL) { 60 | if(!wadFile.SeekNext(szEntry)) 61 | break; 62 | le = LookupLevelEntry(szEntry); 63 | } 64 | if(le != W_D1LEVEL && le != W_D2LEVEL) { 65 | fprintf(stderr,"No level entries found.\n"); 66 | return(false); 67 | } 68 | strcpy(mapname,szEntry); 69 | } 70 | else { 71 | strupper(mapname); 72 | if(!wadFile.SeekTo(mapname)) { 73 | fprintf(stderr,"Level %s not found.\n",mapname); 74 | return(false); 75 | } 76 | } 77 | 78 | 79 | // Conversion loop 80 | do { 81 | printf("\nConverting %s\n",mapname); 82 | 83 | if(!LoadLevelData(wadFile,&level,mapname)) { 84 | fprintf(stderr,"Could not load level data!"); 85 | return(false); 86 | } 87 | 88 | LevelExtents(&level); 89 | 90 | polys = new poly_t[level.n_ssectors]; 91 | // clip ssectors to node clipping lines 92 | ClipSsectors(&level,polys); 93 | // get world polys 94 | poly_t tmp; 95 | MakeWorldPoly(&tmp,&level); 96 | ClipWorldToPolys(&tmp,polys,level.n_ssectors,&world,nWorld); 97 | if(world == NULL) 98 | fprintf(stderr,"ClipWorldToPolys failed!\n"); 99 | 100 | // output a .map 101 | DumpMap(mapname,&level,polys,world,nWorld); 102 | 103 | // clean up memory 104 | CleanupLevel(&level); 105 | if(polys != NULL) { 106 | delete[] polys; 107 | polys = NULL; 108 | } 109 | if(world != NULL) { 110 | delete[] world; 111 | world = NULL; 112 | nWorld = 0; 113 | } 114 | 115 | // find next level, if using "convert all" 116 | if(convert_all) { 117 | wadFile.SeekTo(mapname); 118 | do { 119 | if(!wadFile.SeekNext(szEntry)) { 120 | outOfEntries = true; 121 | break; 122 | } 123 | le = LookupLevelEntry(szEntry); 124 | } while(le != W_D1LEVEL && le != W_D2LEVEL); 125 | strcpy(mapname,szEntry); 126 | } 127 | 128 | } while((le == W_D1LEVEL || le == W_D2LEVEL) && convert_all && !outOfEntries); 129 | return(true); 130 | } 131 | 132 | void strupper(char *s) 133 | { 134 | while(*s) 135 | *s++ = toupper(*s); 136 | } 137 | -------------------------------------------------------------------------------- /convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | convert.h 23 | 24 | Ted Mielczarek 25 | 1-13-2000 26 | */ 27 | #ifndef __CONVERT_H_ 28 | #define __CONVERT_H_ 29 | 30 | bool DoConversion(CWadFile &wadFile); 31 | 32 | #endif /* __CONVERT_H_ */ 33 | -------------------------------------------------------------------------------- /defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | defs.h 23 | 24 | Ted Mielczarek 25 | 1-13-2000 26 | 27 | Definitions of random stuff 28 | */ 29 | #ifndef __DEFS_H_ 30 | #define __DEFS_H_ 31 | 32 | #define MAJORVERSION 1 33 | #define MINORVERSION 0 34 | 35 | #ifndef max 36 | #define max(x,y) ((x > y)?(x):(y)) 37 | #define min(x,y) ((x < y)?(x):(y)) 38 | #endif 39 | 40 | #ifndef MAX_PATH 41 | #define MAX_PATH 1024 42 | #endif 43 | 44 | #define WHITESPACECHARS " \t\r\n" 45 | 46 | #ifndef OutputDebugString 47 | #if DEBUG 48 | #define OutputDebugString(x) fprintf(stderr,x) 49 | #else 50 | #define OutputDebugString 51 | #endif /* DEBUG */ 52 | #endif /* OutputDebugString */ 53 | 54 | #endif /* __DEFS_H_ */ 55 | -------------------------------------------------------------------------------- /doomlevel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | doomlevel.h 23 | 24 | Ted Mielczarek 25 | 12/07/1999 26 | 27 | Contains struct definitions for doom level data. 28 | */ 29 | #ifndef __DOOMLEVEL_H_ 30 | #define __DOOMLEVEL_H_ 31 | 32 | typedef struct linedef_s { 33 | short int from_vertex; 34 | short int to_vertex; 35 | short int attributes; 36 | short int type; 37 | short int sector_trigger; 38 | short int sidedefs[2]; 39 | } linedef_t; 40 | 41 | typedef struct sidedef_s { 42 | short int u_offset; 43 | short int v_offset; 44 | char uppertxt[8]; 45 | char lowertxt[8]; 46 | char walltxt[8]; 47 | short int sector; 48 | } sidedef_t; 49 | 50 | typedef struct vertex_s { 51 | short int x; 52 | short int y; 53 | } vertex_t; 54 | 55 | typedef struct segment_s { 56 | short int from_vertex; 57 | short int to_vertex; 58 | short int angle; 59 | short int linedef; 60 | short int side; 61 | short int distance; 62 | } segment_t; 63 | 64 | typedef struct ssector_s { 65 | short int numsegs; 66 | short int startseg; 67 | } ssector_t; 68 | 69 | typedef struct node_s { 70 | short int x; 71 | short int y; 72 | short int dx; 73 | short int dy; 74 | 75 | short int left_y_upper; 76 | short int left_y_lower; 77 | short int left_x_upper; 78 | short int left_x_lower; 79 | 80 | short int right_y_upper; 81 | short int right_y_lower; 82 | short int right_x_upper; 83 | short int right_x_lower; 84 | 85 | unsigned short int right_child; 86 | unsigned short int left_child; 87 | } node_t; 88 | 89 | typedef struct sector_s { 90 | short int floor_alt; 91 | short int ceiling_alt; 92 | char floortxt[8]; 93 | char ceiltxt[8]; 94 | short int brightness; 95 | short int special; 96 | short int trigger; 97 | } sector_t; 98 | 99 | typedef struct thing_s { 100 | short x; 101 | short y; 102 | short angle; 103 | short thingnum; 104 | short options; 105 | } thing_t; 106 | 107 | // This is just to contain all the level data nicely 108 | typedef struct level_s { 109 | linedef_t *linedefs; 110 | long n_linedefs; 111 | 112 | sidedef_t *sidedefs; 113 | long n_sidedefs; 114 | 115 | vertex_t *vertices; 116 | long n_vertices; 117 | 118 | segment_t *segs; 119 | long n_segs; 120 | 121 | ssector_t *ssectors; 122 | long n_ssectors; 123 | 124 | node_t *nodes; 125 | long n_nodes; 126 | 127 | sector_t *sectors; 128 | long n_sectors; 129 | 130 | thing_t *things; 131 | long n_things; 132 | 133 | short l_width, l_height, x_center, y_center; 134 | 135 | } level_t; 136 | 137 | #endif /* __DOOMLEVEL_H_ */ 138 | -------------------------------------------------------------------------------- /dumpmap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | dumpmap.cpp 23 | 24 | Ted Mielczarek 25 | 1-11-2000 26 | 27 | This file contains routines for exporting a .map file from all the polys 28 | generated from the doom level. 29 | */ 30 | 31 | #include "stdafx.h" 32 | #include "defs.h" 33 | #include "types.h" 34 | #include "doomlevel.h" 35 | #include "things.h" 36 | #include "dumpmap.h" 37 | #include "progress.h" 38 | 39 | const char* LAMETEX = "base_floor/diamond2c"; 40 | 41 | void DumpMap(char *mapname, level_t *l, poly_t *ss, poly_t *world, int nWorld) 42 | { 43 | char filename[MAX_PATH],tex[9],shader[256]; 44 | FILE *f; 45 | int i,j,c; 46 | short z_ceil,z_floor,z_max,z_min; 47 | point3d_t p[3]; 48 | sector_t *sec; 49 | int nBrushes; 50 | 51 | // create filename, open file 52 | strcpy(filename,mapname); 53 | strcat(filename,".map"); 54 | f = fopen(filename,"w"); 55 | if(f == NULL) 56 | return; 57 | 58 | printf("Writing brushes to mapfile: "); 59 | // init progress meter 60 | InitProgress(20,'*',true); 61 | // 2 brushes for each ssector (floor/ceiling) 62 | nBrushes = 2 * l->n_ssectors + nWorld; 63 | 64 | // put out some kinda comment 65 | fprintf(f,"// This map generated by Wad2Map v%d.%d\n",MAJORVERSION,MINORVERSION); 66 | 67 | // find max/min ceiling/floor 68 | z_max = short(0x8000); 69 | z_min = short(0x7FFF); 70 | for(i=0;in_sectors;i++) { 71 | z_max = max(z_max,l->sectors[i].ceiling_alt); 72 | z_min = min(z_min,l->sectors[i].floor_alt); 73 | } 74 | // make sure floors/ceilings are at least 16 thick 75 | z_max += 16; 76 | z_min -= 16; 77 | 78 | // output brushes 79 | c = 0; 80 | // worldspawn ent 81 | fprintf(f,"{\n\"classname\" \"worldspawn\"\n\"message\" \"%s\"\n",mapname); 82 | //------------------------------------------------------ 83 | // Ssector Polys 84 | //------------------------------------------------------ 85 | for(i=0;in_ssectors;i++) { 86 | // degenerate/erased polys 87 | if(ss[i].num_verts < 3) 88 | continue; 89 | 90 | // get floor/ceiling height 91 | if(ss[i].sector != -1) { 92 | sec = &l->sectors[ss[i].sector]; 93 | z_ceil = sec->ceiling_alt; 94 | z_floor = sec->floor_alt; 95 | } 96 | else { 97 | z_ceil = z_max - 16;; 98 | z_floor = z_min + 16;; 99 | } 100 | 101 | // output to map 102 | //** START FLOOR ** 103 | fprintf(f,"// brush %d\n",c++); 104 | fprintf(f,"{\n"); 105 | // output floor planes 106 | // clockwise plane for top floor plane 107 | p[0].x = 0; 108 | p[0].y = 0; 109 | p[1].x = 0; 110 | p[1].y = 1; 111 | p[2].x = 1; 112 | p[2].y = 1; 113 | p[0].z = p[1].z = p[2].z = z_floor; 114 | OutputPlane(f,p,LAMETEX); 115 | // counterclockwise plane for bottom floor plane 116 | p[0].x = 0; 117 | p[0].y = 0; 118 | p[1].x = 1; 119 | p[1].y = 0; 120 | p[2].x = 1; 121 | p[2].y = 1; 122 | p[0].z = p[1].z = p[2].z = z_min; 123 | OutputPlane(f,p,LAMETEX); 124 | // output sides 125 | for(j=0;jx_center + l->l_width / 2; 287 | xmin = l->x_center - l->l_width / 2; 288 | ymax = l->y_center + l->l_height / 2; 289 | ymin = l->y_center - l->l_height / 2; 290 | 291 | fprintf(f,"// Seal brushes\n"); 292 | // Top brush 293 | fprintf(f,"{\n"); 294 | // clockwise plane for top 295 | WriteZPlane(f,z_max,true); 296 | // counterclockwise plane for bottom 297 | WriteZPlane(f,z_max-16,false); 298 | // right side 299 | WriteXPlane(f,xmax+16,true); 300 | // left side 301 | WriteXPlane(f,xmin-16,false); 302 | // front side 303 | WriteYPlane(f,ymax+16,true); 304 | // back side 305 | WriteYPlane(f,ymin-16,false); 306 | fprintf(f,"}\n"); 307 | 308 | // Bottom brush 309 | fprintf(f,"{\n"); 310 | // clockwise plane for top 311 | WriteZPlane(f,z_min,true); 312 | // counterclockwise plane for bottom 313 | WriteZPlane(f,z_min-16,false); 314 | // right side 315 | WriteXPlane(f,xmax+16,true); 316 | // left side 317 | WriteXPlane(f,xmin-16,false); 318 | // front side 319 | WriteYPlane(f,ymax+16,true); 320 | // back side 321 | WriteYPlane(f,ymin-16,false); 322 | fprintf(f,"}\n"); 323 | 324 | // Right side brush 325 | fprintf(f,"{\n"); 326 | // clockwise plane for top 327 | WriteZPlane(f,z_max-16,true); 328 | // counterclockwise plane for bottom 329 | WriteZPlane(f,z_min,false); 330 | // right side 331 | WriteXPlane(f,xmax+16,true); 332 | // left side 333 | WriteXPlane(f,xmax,false); 334 | // front side 335 | WriteYPlane(f,ymax+16,true); 336 | // back side 337 | WriteYPlane(f,ymin-16,false); 338 | fprintf(f,"}\n"); 339 | 340 | // Left side brush 341 | fprintf(f,"{\n"); 342 | // clockwise plane for top 343 | WriteZPlane(f,z_max-16,true); 344 | // counterclockwise plane for bottom 345 | WriteZPlane(f,z_min,false); 346 | // right side 347 | WriteXPlane(f,xmin,true); 348 | // left side 349 | WriteXPlane(f,xmin-16,false); 350 | // front side 351 | WriteYPlane(f,ymax+16,true); 352 | // back side 353 | WriteYPlane(f,ymin-16,false); 354 | fprintf(f,"}\n"); 355 | 356 | // Front brush 357 | fprintf(f,"{\n"); 358 | // clockwise plane for top 359 | WriteZPlane(f,z_max-16,true); 360 | // counterclockwise plane for bottom 361 | WriteZPlane(f,z_min,false); 362 | // right side 363 | WriteXPlane(f,xmax,true); 364 | // left side 365 | WriteXPlane(f,xmin,false); 366 | // front side 367 | WriteYPlane(f,ymax+16,true); 368 | // back side 369 | WriteYPlane(f,ymax,false); 370 | fprintf(f,"}\n"); 371 | 372 | // Back brush 373 | fprintf(f,"{\n"); 374 | // clockwise plane for top 375 | WriteZPlane(f,z_max-16,true); 376 | // counterclockwise plane for bottom 377 | WriteZPlane(f,z_min,false); 378 | // right side 379 | WriteXPlane(f,xmax,true); 380 | // left side 381 | WriteXPlane(f,xmin,false); 382 | // front side 383 | WriteYPlane(f,ymin,true); 384 | // back side 385 | WriteYPlane(f,ymin-16,false); 386 | fprintf(f,"}\n"); 387 | } 388 | 389 | void WriteZPlane(FILE *f, int z, bool dir) 390 | { 391 | point3d_t p[3]; 392 | 393 | p[0].x = 0; 394 | p[0].y = 0; 395 | p[1].x = (dir)? 0 : 1; 396 | p[1].y = (dir)? 1 : 0; 397 | p[2].x = 1; 398 | p[2].y = 1; 399 | p[0].z = p[1].z = p[2].z = z; 400 | OutputPlane(f,p,LAMETEX); 401 | } 402 | 403 | void WriteXPlane(FILE *f, int x, bool dir) 404 | { 405 | point3d_t p[3]; 406 | 407 | p[0].x = x; 408 | p[0].y = 0; 409 | p[0].z = 0; 410 | p[1].x = x; 411 | p[1].y = (dir) ? 0 : 1; 412 | p[1].z = (dir) ? 1 : 0; 413 | p[2].x = x; 414 | p[2].y = 1; 415 | p[2].z = 1; 416 | OutputPlane(f,p,LAMETEX); 417 | } 418 | 419 | void WriteYPlane(FILE *f, int y, bool dir) 420 | { 421 | point3d_t p[3]; 422 | 423 | p[0].x = 0; 424 | p[0].y = y; 425 | p[0].z = 0; 426 | p[1].x = (dir) ? 1 : 0; 427 | p[1].y = y; 428 | p[1].z = (dir) ? 0 : 1; 429 | p[2].x = 1; 430 | p[2].y = y; 431 | p[2].z = 1; 432 | OutputPlane(f,p,LAMETEX); 433 | } 434 | 435 | void OutputPlane(FILE *f,point3d_t p[], const char *tex) 436 | { 437 | // output points 438 | fprintf(f,"( "CSPEC" "CSPEC" "CSPEC" ) ( "CSPEC" "CSPEC" "CSPEC" ) ( "CSPEC" "CSPEC" "CSPEC" ) ", 439 | p[0].x,p[0].y,p[0].z,p[1].x,p[1].y,p[1].z,p[2].x,p[2].y,p[2].z); 440 | // output texture 441 | fprintf(f,"%s ",tex); 442 | // output texcoords: x offset, y offset, rotation, x scale, y scale 443 | fprintf(f,"0 0 0 1.0 1.0\n"); 444 | } 445 | -------------------------------------------------------------------------------- /dumpmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | dumpmap.h 23 | 24 | Ted Mielczarek 25 | 1-11-2000 26 | 27 | This file contains prototypes for dumpmap.cpp, for outputting 28 | to a .map file. 29 | */ 30 | #ifndef __DUMPMAP_H_ 31 | #define __DUMPMAP_H_ 32 | 33 | void DumpMap(char *mapname, level_t *l, poly_t *ss, poly_t *world, int nWorld); 34 | void OutputPlane(FILE *f,point3d_t p[], const char *tex); 35 | void OutputSealBrushes(FILE *f, level_t *l, int z_max, int z_min); 36 | void WriteZPlane(FILE *f, int z, bool dir); 37 | void WriteXPlane(FILE *f, int x, bool dir); 38 | void WriteYPlane(FILE *f, int y, bool dir); 39 | #endif /* __DUMPMAP_H_ */ 40 | -------------------------------------------------------------------------------- /entities.list: -------------------------------------------------------------------------------- 1 | ; Wad2Map thing conversion options. 2 | ; Comments start with a semicolon. 3 | 4 | ; contents of a line: 5 | ; Doom thing number Quake entity name 6 | ; 1 info_player_start 7 | 8 | ; Also, to use a misc_model, preface the model path with a * 9 | ; Doom thing number Model path 10 | ; 15 *models/mapobjects/corpse/corpse.md3 11 | 12 | ; Probably don't want to change these 13 | 1 info_player_start ; Player start 14 | 11 info_player_deathmatch ; Deathmatch start 15 | 14 misc_teleporter_dest ; Teleport landing 16 | 17 | ; Weapons/Ammo 18 | 2001 weapon_shotgun ; Shotgun 19 | 82 weapon_shotgun ; Double-barreled shotgun 20 | 2002 weapon_railgun ; Chaingun 21 | 2003 weapon_rocketlauncher ; Rocket launcher 22 | 2004 weapon_plasmagun ; Plasma gun 23 | 2006 weapon_bfg ; Bfg9000 24 | 2007 ammo_bullets ; Ammo clip 25 | 2008 ammo_shells ; Shotgun shells 26 | 2010 ammo_rockets ; A rocket 27 | 2047 ammo_cells ; Cell charge 28 | 2048 ammo_bullets ; Box of Ammo 29 | 2049 ammo_shells ; Box of Shells 30 | 2046 ammo_rockets ; Box of Rockets 31 | 17 ammo_cells ; Cell charge pack 32 | 33 | ; Health/Armor 34 | 2011 item_health ; Stimpak 35 | 2012 item_health_large ; Medikit 36 | 2014 item_health_small ; Health Potion 37 | 2015 item_armor_shard ; Spirit Armor 38 | 2018 item_armor_body ; Green armor 39 | 2019 item_armor_combat ; Blue armor 40 | 83 item_regen ; Megasphere (nothing else to replace it with) 41 | 2013 item_health_mega ; Soulsphere 42 | 2022 item_enviro ; Invulnerability 43 | 2023 item_quad ; Berserk 44 | 2024 item_invis ; Invisibility 45 | 2025 item_enviro ; Radiation suit 46 | 47 | ; More Dead people 48 | 15 *models/mapobjects/corpse/corpse.md3 ; dead player 49 | 50 | -------------------------------------------------------------------------------- /entities.list.template: -------------------------------------------------------------------------------- 1 | ; Wad2Map thing conversion options. 2 | ; This is only a template! It will work, but you do not need to include 3 | ; lines for things that are ignored. They are included here just to have 4 | ; a complete reference. 5 | 6 | ; Comments start with a semicolon. 7 | 8 | ; contents of a line: 9 | ; Doom thing number Quake entity name 10 | ; 1 info_player_start 11 | 12 | ; Also, to use a misc_model, preface the model path with a * 13 | ; Doom thing number Model path 14 | ; 15 *models/mapobjects/corpse/corpse.md3 15 | 16 | ; Probably don't want to change these 17 | 1 info_player_start ; Player start 18 | 2 ; Player 2 start 19 | 3 ; Player 3 start 20 | 4 ; Player 4 start 21 | 11 info_player_deathmatch ; Deathmatch start 22 | 14 misc_teleporter_dest ; Teleport landing 23 | 24 | ; Monsters are ignored, but you could change this 25 | 3004 ; FORMER HUMAN 26 | 84 ; WOLFENSTEIN SS 27 | 9 ; FORMER HUMAN SERGEANT 28 | 65 ; HEAVY WEAPON DUDE 29 | 3001 ; IMP 30 | 3002 ; DEMON 31 | 58 ; SPECTRE 32 | 3006 ; LOST SOUL 33 | 3005 ; CACODEMON 34 | 69 ; HELL KNIGHT 35 | 3003 ; BARON OF HELL 36 | 68 ; ARACHNOTRON 37 | 71 ; PAIN ELEMENTAL 38 | 66 ; REVENANT 39 | 67 ; MANCUBUS 40 | 64 ; ARCH-VILE 41 | 7 ; SPIDER MASTERMIND 42 | 16 ; CYBER-DEMON 43 | 88 ; BOSS BRAIN (romero's head) 44 | 89 ; Boss Shooter 45 | 87 ; Spawn Spot 46 | 47 | ; Weapons/Ammo 48 | 2005 ; Chainsaw 49 | 2001 weapon_shotgun ; Shotgun 50 | 82 weapon_shotgun ; Double-barreled shotgun 51 | 2002 weapon_railgun ; Chaingun 52 | 2003 weapon_rocketlauncher ; Rocket launcher 53 | 2004 weapon_plasmagun ; Plasma gun 54 | 2006 weapon_bfg ; Bfg9000 55 | 2007 ammo_bullets ; Ammo clip 56 | 2008 ammo_shells ; Shotgun shells 57 | 2010 ammo_rockets ; A rocket 58 | 2047 ammo_cells ; Cell charge 59 | 2048 ammo_bullets ; Box of Ammo 60 | 2049 ammo_shells ; Box of Shells 61 | 2046 ammo_rockets ; Box of Rockets 62 | 17 ammo_cells ; Cell charge pack 63 | 8 ; Backpack 64 | 65 | ; Health/Armor 66 | 2011 item_health ; Stimpak 67 | 2012 item_health_large ; Medikit 68 | 2014 item_health_small ; Health Potion 69 | 2015 item_armor_shard ; Spirit Armor 70 | 2018 item_armor_body ; Green armor 71 | 2019 item_armor_combat ; Blue armor 72 | 83 item_regen ; Megasphere (nothing else to replace it with) 73 | 2013 item_health_mega ; Soulsphere 74 | 2022 item_enviro ; Invulnerability 75 | 2023 item_quad ; Berserk 76 | 2024 item_invis ; Invisibility 77 | 2025 item_enviro ; Radiation suit 78 | 2026 ; Computer map 79 | 2045 ; Lite Amplification goggles 80 | 81 | ; Keys are ignored 82 | 5 ; Blue keycard 83 | 40 ; Blue skullkey 84 | 13 ; Red keycard 85 | 38 ; Red skullkey 86 | 6 ; Yellow keycard 87 | 39 ; Yellow skullkey 88 | 89 | ; Misc stuff 90 | 2035 ; Barrel 91 | 72 ; Commander Keen 92 | 48 ; Tall, techno pillar 93 | 30 ; Tall green pillar 94 | 32 ; Tall red pillar 95 | 31 ; Short green pillar 96 | 36 ; Short green pillar with beating heart 97 | 33 ; Short red pillar 98 | 37 ; Short red pillar with skull 99 | 47 ; Stalagmite: small brown pointy stump 100 | 43 ; Burnt tree: gray tree 101 | 54 ; Large brown tree 102 | 103 | ; Lights (will do something with these) 104 | 2028 ; Floor lamp 105 | 85 ; Tall techno floor lamp 106 | 86 ; Short techno floor lamp 107 | 34 ; Candle 108 | 35 ; Candelabra 109 | 44 ; Tall blue firestick 110 | 45 ; Tall green firestick 111 | 46 ; Tall red firestick 112 | 55 ; Short blue firestick 113 | 56 ; Short green firestick 114 | 57 ; Short red firestick 115 | 70 ; Burning barrel 116 | 117 | ; More random stuff 118 | 41 ; Evil Eye: floating eye in symbol, over candle 119 | 42 ; Floating Skull: flaming skull-rock 120 | 121 | ; Dead people (hanging) 122 | 49 ; Hanging victim, twitching 123 | 63 ; Hanging victim, twitching 124 | 50 ; Hanging victim, arms out 125 | 59 ; Hanging victim, arms out 126 | 52 ; Hanging pair of legs 127 | 60 ; Hanging pair of legs 128 | 51 ; Hanging victim, 1-legged 129 | 61 ; Hanging victim, 1-legged 130 | 53 ; Hanging leg 131 | 62 ; Hanging leg 132 | 73 ; Hanging victim, guts removed 133 | 74 ; Hanging victim, guts and brain removed 134 | 75 ; Hanging torso, looking down 135 | 76 ; Hanging torso, open skull 136 | 77 ; Hanging torso, looking up 137 | 78 ; Hanging torso, brain removed 138 | 139 | ; More Dead people 140 | 25 ; Impaled human 141 | 26 ; Twitching impaled human 142 | 27 ; Skull on a pole 143 | 28 ; 5 skulls shish kebob 144 | 29 ; Pile of skulls and candles 145 | 10 ; Bloody mess (an exploded player) 146 | 12 ; Bloody mess, this thing is exactly the same as 10 147 | 24 ; Pool of blood and flesh 148 | 79 ; Pool of blood 149 | 80 ; Pool of blood 150 | 81 ; Pool of brains 151 | 15 ; Dead player 152 | 18 ; Dead former human 153 | 19 ; Dead former sergeant 154 | 20 ; Dead imp 155 | 21 ; Dead demon 156 | 22 ; Dead cacodemon 157 | 23 ; Dead lost soul (nothing) 158 | -------------------------------------------------------------------------------- /globals.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | globals.h 23 | 24 | Ted Mielczarek 25 | 1-13-2000 26 | 27 | This file contains extern definitions for the global variables 28 | in wad2map.cpp 29 | */ 30 | #ifndef __GLOBALS_H_ 31 | #define __GLOBALS_H_ 32 | 33 | extern char wadfilename[MAX_PATH]; 34 | 35 | extern char entityoptfilename[MAX_PATH]; 36 | #define DEFAULTENTITYFILE "entities.list" 37 | 38 | extern char textureoptfilename[MAX_PATH]; 39 | #define DEFAULTTEXTUREFILE "textures.list" 40 | 41 | extern char mapname[9]; 42 | extern bool convert_all; 43 | extern bool do_textures; 44 | 45 | #endif /* __GLOBALS_H_ */ 46 | -------------------------------------------------------------------------------- /progress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | progress.cpp 23 | 24 | Ted Mielczarek 25 | 1-13-2000 26 | 27 | Defines routines for drawing an ascii progress bar. 28 | */ 29 | 30 | #include "stdafx.h" 31 | #include "progress.h" 32 | 33 | int progLen = 10; 34 | char fillChar = '*'; 35 | char clearBuf[256] = "\0"; 36 | bool doPercent = false; 37 | 38 | void InitProgress(int len, char fill, bool drawPercent) 39 | { 40 | int i,c; 41 | 42 | if(len > 255) 43 | len = 255; 44 | 45 | progLen = len; 46 | fillChar = fill; 47 | doPercent = drawPercent; 48 | 49 | clearBuf[0] = '\0'; 50 | c = progLen+1; 51 | if(doPercent) 52 | c += 5; 53 | 54 | for(i=0;i 1000 30 | #pragma once 31 | #endif // _MSC_VER > 1000 32 | 33 | #include 34 | #if _MSC_VER 35 | #include 36 | #include 37 | #endif 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #endif // !defined(AFX_STDAFX_H__05681BA2_ADAE_11D3_910E_0000E82F44A6__INCLUDED_) 44 | -------------------------------------------------------------------------------- /subtract_ssectors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | subtract_ssectors.cpp 23 | 24 | Ted Mielczarek 25 | 12-21-1999 26 | 27 | This file contains routines to subtract the ssector polygons from the 28 | world polygon, creating the "wall" brushes. 29 | */ 30 | #include "stdafx.h" 31 | #include "defs.h" 32 | #include "types.h" 33 | #include "2dclip.h" 34 | #include "subtract_ssectors.h" 35 | #include "progress.h" 36 | 37 | // Globals 38 | poly_t *polyList[MAX_POLYS_IN_LIST]; 39 | int polyCount; 40 | 41 | /* 42 | ClipWorldToPolys 43 | 44 | Parameters: 45 | world: Poly surrounding entire level 46 | ss: List of polys to subtract from world 47 | n: Count of polys in ss 48 | out: Pointer to allocate list into to store returned polys 49 | count: Number of polys returned in out 50 | 51 | This function subtracts each poly in ss from world, and stores the results in 52 | out, and the number of polys created in count. 53 | */ 54 | bool ClipWorldToPolys(poly_t *world, poly_t ss[], int n, poly_t **out, int &count) 55 | { 56 | int i,c; 57 | 58 | // MUST DO THIS FIRST!! 59 | InitList(); 60 | 61 | // start out with world poly 62 | AddToList(world); 63 | 64 | printf("Subtracting ssectors from world: "); 65 | // init progress meter 66 | InitProgress(20,'*',true); 67 | //DrawProgress(n,0); 68 | 69 | // iterate through polys to subtract 70 | for(i=0;i 2) 72 | // subtract this poly from every poly in the world list 73 | Subtract(&ss[i]); 74 | // draw progress meter 75 | DrawProgress(n,i); 76 | } 77 | DrawProgress(n,i); 78 | printf("\n"); 79 | 80 | // make sure we didn't screw up 81 | if(polyCount > 0) { 82 | *out = new poly_t[polyCount]; 83 | count = polyCount; 84 | c = 0; 85 | for(i=0;i < MAX_POLYS_IN_LIST && c < polyCount; i++) 86 | if(polyList[i] != NULL) 87 | memcpy(&(*out)[c++],polyList[i],sizeof(poly_t)); 88 | } 89 | else // eek 90 | return(false); 91 | 92 | ClearList(); 93 | 94 | // check all polys 95 | for(i=0;inum_verts-1;i++) { 134 | LineFromPoints(&l,inter->p+i); 135 | memcpy(&save,&tmp,sizeof(poly_t)); 136 | if(ClipPolyToLine(&save,&l,left_side)) { 137 | if(CheckPoly(&save)) 138 | AddToList(&save); 139 | else 140 | OutputDebugString("Bad world brush\n"); 141 | 142 | ClipPolyToLine(&tmp,&l,right_side); 143 | } 144 | } 145 | 146 | // do last vert->first vert 147 | memcpy(p,inter->p+inter->num_verts-1,sizeof(point_t)); 148 | memcpy(p+1,inter->p,sizeof(point_t)); 149 | LineFromPoints(&l,p); 150 | memcpy(&save,&tmp,sizeof(poly_t)); 151 | if(ClipPolyToLine(&save,&l,left_side)) 152 | if(CheckPoly(&save)) 153 | AddToList(&save); 154 | else 155 | OutputDebugString("Bad world brush\n"); 156 | 157 | return(true); 158 | } 159 | 160 | bool PolyIntersect(poly_t *a, poly_t *b, poly_t *inter) 161 | { 162 | line_t l; 163 | int i; 164 | point_t p[2]; 165 | 166 | memcpy(inter,a,sizeof(poly_t)); 167 | // clip intersection poly (starts out as a) to each line in b 168 | for(i=0;inum_verts-1;i++) { 169 | LineFromPoints(&l,b->p+i); 170 | ClipPolyToLine(inter,&l,right_side); 171 | } 172 | 173 | // get line from last vert to first vert 174 | memcpy(p,b->p+b->num_verts-1,sizeof(point_t)); 175 | memcpy(p+1,b->p,sizeof(point_t)); 176 | LineFromPoints(&l,p); 177 | ClipPolyToLine(inter,&l,right_side); 178 | 179 | if(inter->num_verts > 2) 180 | return(true); 181 | 182 | return(false); 183 | } 184 | 185 | void InitList(void) 186 | { 187 | int i; 188 | 189 | for(i=0;isector = -1; 211 | memcpy(polyList[i],p,sizeof(poly_t)); 212 | polyCount++; 213 | return(true); 214 | } 215 | } 216 | // no slots free, this shouldn't happen 217 | return(false); 218 | } 219 | 220 | void ClearList(void) 221 | { 222 | int i; 223 | 224 | for(i=0;i 33 | #include "defs.h" 34 | #include "types.h" 35 | #include "doomlevel.h" 36 | #include "2dclip.h" 37 | #include "things.h" 38 | #include "progress.h" 39 | 40 | // Globals 41 | thingconvert_t things[MAX_DOOM_THINGS]; 42 | int numthings = 0; 43 | specialthing_t specialthings[] = { 44 | {'*', MiscModel} 45 | }; 46 | int numspecialthings = sizeof(specialthings) / sizeof(specialthing_t); 47 | 48 | // This function is only used if the thing convert file cannot be loaded 49 | void SetThingConvertDefaults(void) 50 | { 51 | memset(things,0,sizeof(things)); 52 | // just initialize this one for quick testing 53 | things[0].d_thing = 1; 54 | strcpy(things[0].q_entity,"info_player_start"); 55 | numthings++; 56 | } 57 | 58 | void LoadThingConvertFile(char *szFile) 59 | { 60 | FILE *f; 61 | char strIn[1024], qThing[256],*s,*ptr; 62 | long dThing; 63 | int i; 64 | 65 | f = fopen(szFile,"r"); 66 | if(f == NULL) { 67 | fprintf(stderr,"Could not open thing convert list %s, using defaults.\n",szFile); 68 | SetThingConvertDefaults(); 69 | return; 70 | } 71 | 72 | printf("Loading thing conversion options from %s\n",szFile); 73 | 74 | // initialize numthings 75 | numthings = 0; 76 | i = 0; 77 | 78 | while(!feof(f)) { 79 | if (fgets(strIn,1024,f) == NULL) 80 | break; 81 | if(feof(f)) 82 | break; 83 | 84 | i++; 85 | // look for thing number 86 | s = strtok(strIn,WHITESPACECHARS); 87 | // nothing on line 88 | if(s == NULL) 89 | continue; 90 | 91 | // just a comment 92 | if(*s == ';') 93 | continue; 94 | 95 | dThing = strtol(s,&ptr,0); 96 | if(*ptr != '\0' || errno == ERANGE) { 97 | fprintf(stderr,"LoadThingConvertFile: Bad thing number on line %d\n",i); 98 | continue; 99 | } 100 | 101 | // look for entity name 102 | s = strtok(NULL,WHITESPACECHARS); 103 | 104 | // skip things with nothing to convert to 105 | // blank line 106 | if(s == NULL) 107 | continue; 108 | // just a comment 109 | else if(*s == ';') 110 | continue; 111 | 112 | strcpy(qThing,s); 113 | 114 | // set values 115 | things[numthings].d_thing = short(dThing); 116 | strcpy(things[numthings].q_entity,qThing); 117 | numthings++; 118 | } 119 | 120 | fclose(f); 121 | } 122 | 123 | bool ConvertThings(FILE *f, level_t *l, poly_t *ss) 124 | { 125 | int i,c,z,st; 126 | thing_t *t = l->things; 127 | char szName[256]; 128 | 129 | printf("Converting things: "); 130 | InitProgress(20,'*',true); 131 | DrawProgress(l->n_things,0); 132 | 133 | c = 0; 134 | for(i=0; in_things; i++, t++) { 135 | if(LookupThing(t->thingnum,szName)) { 136 | // get z coordinate 137 | z = GetThingZ(l,t,ss); 138 | // see if it's a "special thing" 139 | st = LookupSpecialThing(szName[0]); 140 | // output thing 141 | fprintf(f,"// entity %d\n",c++); 142 | fprintf(f,"{\n"); 143 | // handle "special things" 144 | if(st != -1) 145 | specialthings[st].stp(f,szName+1,t,z); 146 | else { 147 | fprintf(f,"\"classname\" \"%s\"\n",szName); 148 | fprintf(f,"\"origin\" \"%d %d %d\"\n",t->x,t->y,z); 149 | fprintf(f,"\"angle\" \"%d\"\n",t->angle); 150 | } 151 | fprintf(f,"}\n\n"); 152 | } 153 | DrawProgress(l->n_things,i); 154 | } 155 | DrawProgress(l->n_things,i); 156 | printf("\n"); 157 | 158 | return(true); 159 | } 160 | 161 | bool LookupThing(short d_thing, char *q_entity) 162 | { 163 | int i; 164 | 165 | // lookup d_thing number in things list 166 | for(i=0;ix; 195 | p.y = t->y; 196 | 197 | for(i=0; in_ssectors; i++) { 198 | if(PointInPoly(&p,&ss[i])) 199 | return(l->sectors[ss[i].sector].floor_alt + 24); 200 | } 201 | 202 | return(0); 203 | } 204 | 205 | //-------------------------------------------------- 206 | // "Special Things" procedures 207 | //-------------------------------------------------- 208 | bool MiscModel(FILE *f, char *szModel, thing_t *t, int z) 209 | { 210 | if(*szModel == '\0') 211 | return(false); 212 | 213 | fprintf(f,"\"classname\" \"misc_model\"\n"); 214 | fprintf(f,"\"model\" \"%s\"\n",szModel); 215 | fprintf(f,"\"origin\" \"%d %d %d\"\n",t->x,t->y,z); 216 | return(true); 217 | } 218 | -------------------------------------------------------------------------------- /things.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | things.h 23 | 24 | Ted Mielczarek 25 | 1-11-2000 26 | 27 | This file contains definitions for things.cpp 28 | */ 29 | #ifndef __THINGS_H_ 30 | #define __THINGS_H_ 31 | 32 | // thing conversion list 33 | typedef struct thingconvert_s 34 | { 35 | short d_thing; 36 | char q_entity[256]; 37 | } thingconvert_t; 38 | 39 | typedef bool (*SPECIALTHINGPROC)(FILE *,char *, thing_t *, int); 40 | typedef struct specialthing_s 41 | { 42 | char c; 43 | SPECIALTHINGPROC stp; 44 | } specialthing_t; 45 | 46 | // number of unique things present in Doom 47 | #define MAX_DOOM_THINGS 123 48 | 49 | #define THING_SKILL_EASY 1 50 | #define THING_SKILL_MED (1<<1) 51 | #define THING_SKILL_HARD (1<<2) 52 | #define THING_DEAF (1<<3) 53 | #define THING_MULTI_ONLY (1<<4) 54 | 55 | void SetThingConvertDefaults(void); 56 | void LoadThingConvertFile(char *szFile); 57 | bool ConvertThings(FILE *f, level_t *l, poly_t *ss); 58 | bool LookupThing(short d_thing, char *q_entity); 59 | int LookupSpecialThing(char c); 60 | int GetThingZ(level_t *l, thing_t *t, poly_t *ss); 61 | // Special Thing procs 62 | bool MiscModel(FILE *f, char *szModel, thing_t *t, int z); 63 | #endif /* __THINGS_H_ */ 64 | -------------------------------------------------------------------------------- /types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | types.h 23 | 24 | Ted Mielczarek 25 | 12/10/1999 26 | 27 | This file contains data types for the program. 28 | */ 29 | #ifndef WAD2MAP_TYPES_H_ 30 | #define WAD2MAP_TYPES_H_ 31 | 32 | // we can use double or int 33 | #ifdef USE_FLOATING_POINT 34 | typedef double coord; 35 | #define CSPEC "%lf" 36 | #else 37 | typedef int coord; 38 | #define CSPEC "%d" 39 | #endif 40 | 41 | typedef unsigned char byte; 42 | typedef unsigned short word; 43 | typedef unsigned long dword; 44 | 45 | // point 46 | typedef struct point_s { 47 | coord x,y; 48 | } point_t; 49 | 50 | // 3d point (used for dumping maps) 51 | typedef struct point3d_s { 52 | coord x,y,z; 53 | } point3d_t; 54 | 55 | // point-normal form of a line 56 | typedef struct line_s { 57 | point_t n; // normal vector 58 | point_t p; // point 59 | } line_t; 60 | 61 | // is this enough? 62 | #define MAX_POLY_VERTS 256 63 | 64 | typedef struct poly_s { 65 | point_t p[MAX_POLY_VERTS]; // poly vertices 66 | int num_verts; // vertex count 67 | short sidedef[MAX_POLY_VERTS]; // to keep track of sidedefs/lines 68 | short sector; // sector this is a part of (-1 for none) 69 | } poly_t; 70 | 71 | #endif /* WAD2MAP_TYPES_H_ */ 72 | -------------------------------------------------------------------------------- /wad2map-todo.txt: -------------------------------------------------------------------------------- 1 | Wad2Map to-do list 2 | 1-16-2000 3 | 4 | Things to do immediately: 5 | * texture support 6 | * door/plat/etc support 7 | 8 | Things that need to be worked on: 9 | * Fix CSG Code - Still Producing some bad world brushes 10 | 11 | Things to do as a whole: 12 | + doom level structs 13 | + wad class 14 | + polygon clipping code 15 | + Ssector clipping from node division lines/segs 16 | + 2d CSG subtract ssector polys from world poly 17 | + Output brushes to map file 18 | * Combine brushes to reduce count 19 | + Convert things / config file format 20 | * Parse thing convert file 21 | * Assign textures - sector # for ssectors, sidedef # for world brushes (lower/upper for ssectors) 22 | * Handle doors/plats/etc 23 | * Handle water/lava 24 | * Handle skies 25 | * Convert pillars, other misc entities to brushes or misc models 26 | * Handle lighting (textures, entities, points?) 27 | + Texture converter 28 | * Have texture converter output shaders 29 | * Level scaling / shifting (is it needed?) 30 | * Texture replacing / config file format 31 | * Sky textures 32 | * Handmade shaders for doom textures (for best results) -------------------------------------------------------------------------------- /wad2map.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | wad2map.cpp 23 | 24 | Main entry point 25 | */ 26 | #include "stdafx.h" 27 | #include "defs.h" 28 | #include "types.h" 29 | #include "doomlevel.h" 30 | #include "wadfile.h" 31 | #include "convert.h" 32 | #include "globals.h" 33 | #include "things.h" 34 | 35 | // Local function prototypes 36 | int GetCommandlineOptions(int argc, char **argv); 37 | void usage(void); 38 | void License(void); 39 | 40 | // Global variables 41 | char wadfilename[MAX_PATH] = "\0", 42 | entityoptfilename[MAX_PATH] = DEFAULTENTITYFILE, 43 | textureoptfilename[MAX_PATH] = DEFAULTTEXTUREFILE; 44 | char mapname[9] = "\0"; 45 | bool convert_all = false, 46 | do_textures = false; 47 | 48 | // Function definitions 49 | int main(int argc, char **argv) 50 | { 51 | CWadFile theWad; 52 | int i; 53 | 54 | License(); 55 | 56 | if(argc < 2) 57 | usage(); 58 | 59 | // Check commandline options 60 | i = GetCommandlineOptions(argc,argv); 61 | 62 | // open wadfile and proceed 63 | if(!theWad.Open(argv[i])) { 64 | printf("Could not open %s for input!\n",argv[i]); 65 | exit(1); 66 | } 67 | 68 | // get thing/texture conversion data 69 | LoadThingConvertFile(entityoptfilename); 70 | 71 | // do all conversion 72 | DoConversion(theWad); 73 | // close up 74 | theWad.Close(); 75 | 76 | printf("Exiting...\n"); 77 | 78 | return(0); 79 | } 80 | 81 | int GetCommandlineOptions(int argc, char **argv) 82 | { 83 | int i; 84 | 85 | // check commandline options 86 | for(i=1;i 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=wad2map - Win32 Not Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "wad2map.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "wad2map.mak" CFG="wad2map - Win32 Not Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "wad2map - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "wad2map - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE "wad2map - Win32 Not Debug" (based on "Win32 (x86) Console Application") 23 | !MESSAGE 24 | 25 | # Begin Project 26 | # PROP AllowPerConfigDependencies 0 27 | # PROP Scc_ProjName "" 28 | # PROP Scc_LocalPath "" 29 | CPP=cl.exe 30 | RSC=rc.exe 31 | 32 | !IF "$(CFG)" == "wad2map - Win32 Release" 33 | 34 | # PROP BASE Use_MFC 0 35 | # PROP BASE Use_Debug_Libraries 0 36 | # PROP BASE Output_Dir "Release" 37 | # PROP BASE Intermediate_Dir "Release" 38 | # PROP BASE Target_Dir "" 39 | # PROP Use_MFC 0 40 | # PROP Use_Debug_Libraries 0 41 | # PROP Output_Dir "Release" 42 | # PROP Intermediate_Dir "Release" 43 | # PROP Ignore_Export_Lib 0 44 | # PROP Target_Dir "" 45 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c 46 | # ADD CPP /nologo /W4 /GX /Od /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /Yu"stdafx.h" /FD /c 47 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 48 | # ADD RSC /l 0x409 /d "NDEBUG" 49 | BSC32=bscmake.exe 50 | # ADD BASE BSC32 /nologo 51 | # ADD BSC32 /nologo 52 | LINK32=link.exe 53 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 54 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 55 | 56 | !ELSEIF "$(CFG)" == "wad2map - Win32 Debug" 57 | 58 | # PROP BASE Use_MFC 0 59 | # PROP BASE Use_Debug_Libraries 1 60 | # PROP BASE Output_Dir "Debug" 61 | # PROP BASE Intermediate_Dir "Debug" 62 | # PROP BASE Target_Dir "" 63 | # PROP Use_MFC 0 64 | # PROP Use_Debug_Libraries 1 65 | # PROP Output_Dir "Debug" 66 | # PROP Intermediate_Dir "Debug" 67 | # PROP Ignore_Export_Lib 0 68 | # PROP Target_Dir "" 69 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c 70 | # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c 71 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 72 | # ADD RSC /l 0x409 /d "_DEBUG" 73 | BSC32=bscmake.exe 74 | # ADD BASE BSC32 /nologo 75 | # ADD BSC32 /nologo 76 | LINK32=link.exe 77 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 78 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 79 | 80 | !ELSEIF "$(CFG)" == "wad2map - Win32 Not Debug" 81 | 82 | # PROP BASE Use_MFC 0 83 | # PROP BASE Use_Debug_Libraries 1 84 | # PROP BASE Output_Dir "wad2map___Win32_Not_Debug" 85 | # PROP BASE Intermediate_Dir "wad2map___Win32_Not_Debug" 86 | # PROP BASE Ignore_Export_Lib 0 87 | # PROP BASE Target_Dir "" 88 | # PROP Use_MFC 0 89 | # PROP Use_Debug_Libraries 1 90 | # PROP Output_Dir "Not_Debug" 91 | # PROP Intermediate_Dir "Not_Debug" 92 | # PROP Ignore_Export_Lib 0 93 | # PROP Target_Dir "" 94 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c 95 | # ADD CPP /nologo /ML /W3 /Gm /GX /ZI /Od /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c 96 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 97 | # ADD RSC /l 0x409 /d "NDEBUG" 98 | BSC32=bscmake.exe 99 | # ADD BASE BSC32 /nologo 100 | # ADD BSC32 /nologo 101 | LINK32=link.exe 102 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 103 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /pdbtype:sept 104 | # SUBTRACT LINK32 /debug 105 | 106 | !ENDIF 107 | 108 | # Begin Target 109 | 110 | # Name "wad2map - Win32 Release" 111 | # Name "wad2map - Win32 Debug" 112 | # Name "wad2map - Win32 Not Debug" 113 | # Begin Group "Source Files" 114 | 115 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 116 | # Begin Source File 117 | 118 | SOURCE=.\2dclip.cpp 119 | # End Source File 120 | # Begin Source File 121 | 122 | SOURCE=.\clip_ssectors.cpp 123 | # End Source File 124 | # Begin Source File 125 | 126 | SOURCE=.\convert.cpp 127 | # End Source File 128 | # Begin Source File 129 | 130 | SOURCE=.\dumpmap.cpp 131 | # End Source File 132 | # Begin Source File 133 | 134 | SOURCE=.\progress.cpp 135 | # End Source File 136 | # Begin Source File 137 | 138 | SOURCE=.\StdAfx.cpp 139 | # ADD CPP /Yc"stdafx.h" 140 | # End Source File 141 | # Begin Source File 142 | 143 | SOURCE=.\subtract_ssectors.cpp 144 | # End Source File 145 | # Begin Source File 146 | 147 | SOURCE=.\things.cpp 148 | # End Source File 149 | # Begin Source File 150 | 151 | SOURCE=.\wad2map.cpp 152 | # End Source File 153 | # Begin Source File 154 | 155 | SOURCE=.\wadentries.cpp 156 | # End Source File 157 | # Begin Source File 158 | 159 | SOURCE=.\WadFile.cpp 160 | # End Source File 161 | # End Group 162 | # Begin Group "Header Files" 163 | 164 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 165 | # Begin Source File 166 | 167 | SOURCE=.\2dclip.h 168 | # End Source File 169 | # Begin Source File 170 | 171 | SOURCE=.\clip_ssectors.h 172 | # End Source File 173 | # Begin Source File 174 | 175 | SOURCE=.\convert.h 176 | # End Source File 177 | # Begin Source File 178 | 179 | SOURCE=.\defs.h 180 | # End Source File 181 | # Begin Source File 182 | 183 | SOURCE=.\doomlevel.h 184 | # End Source File 185 | # Begin Source File 186 | 187 | SOURCE=.\dumpmap.h 188 | # End Source File 189 | # Begin Source File 190 | 191 | SOURCE=.\globals.h 192 | # End Source File 193 | # Begin Source File 194 | 195 | SOURCE=.\progress.h 196 | # End Source File 197 | # Begin Source File 198 | 199 | SOURCE=.\StdAfx.h 200 | # End Source File 201 | # Begin Source File 202 | 203 | SOURCE=.\subtract_ssectors.h 204 | # End Source File 205 | # Begin Source File 206 | 207 | SOURCE=.\things.h 208 | # End Source File 209 | # Begin Source File 210 | 211 | SOURCE=.\types.h 212 | # End Source File 213 | # Begin Source File 214 | 215 | SOURCE=.\wadentries.h 216 | # End Source File 217 | # Begin Source File 218 | 219 | SOURCE=.\WadFile.h 220 | # End Source File 221 | # End Group 222 | # End Target 223 | # End Project 224 | -------------------------------------------------------------------------------- /wad2map.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "wad2map"=.\wad2map.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /wad2map.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luser/wad2map/19ce39d2f26d789cebb40b17eb7f35dff231880e/wad2map.opt -------------------------------------------------------------------------------- /wad2map.txt: -------------------------------------------------------------------------------- 1 | Wad2Map 2 | A Doom to Quake3 level converter 3 | by Ted Mielczarek 4 | 5 | Wad2Map is just what its name states: A Doom wad to Quake map converter. Yes, 6 | now you can (more or less) play your favorite doom maps as Quake maps. I know, 7 | I know, there have been other converters, and they produce mostly crap. I'm not 8 | saying that Wad2Map is perfect, but it's a heck of a lot better than those. (In 9 | my opinion, anyway). 10 | 11 | Wad2Map is released under the GNU Public Lisence. See GPL.txt for details. 12 | 13 | Usage 14 | ---- 15 | You can simply run "wad2map somewad.wad" and Wad2Map will convert the first level 16 | it finds in that wad into a quake map. Or, you can take matters into your 17 | own hands and use some of the following commandline switches: 18 | 19 | -a 20 | Convert all levels in the wad. Fairly obvious as to the functionality. 21 | 22 | -m mapname 23 | Convert this map. If used with -a, also converts all maps after this in the wad. 24 | 25 | -e file 26 | Read the entity conversion list from this file. The default is entities.list. See 27 | that file for a description of the format. 28 | 29 | How exactly does it work? 30 | ---- 31 | Wad2Map determines the ssectors by using the node clipping lines to clip a world-size 32 | polygon down to size. Once it has created all the ssectors, it csg subtracts these 33 | polygons from a world-size polygon to get the rest of the world geometry (what you 34 | see as the walls). Fairly simple. Mostly. Unfortunately, it's not quite that simple, 35 | so it's not perfect. You will still get some bad brushes occasionally. Hopefully this 36 | will be fixed eventually. 37 | 38 | Credits 39 | ---- 40 | Wad2Map would not have been possible without the help of the following: 41 | 42 | Trey Harrison, who schooled me in some aspects of computational geometry. 43 | Stephen Crowley, who had the original idea. 44 | Matt Fell's Doom Specs - The Ultimate Doom Resource. 45 | Niklata's Quake Map Specs - An excellent guide to the .map format. 46 | The denizens of EFnet #QuakeEd, for being generally unhelpful. 47 | 48 | Etc. 49 | ---- 50 | The Wad2Map homepage is http://www.lehigh.edu/~tam4/wad2map 51 | The author, Ted Mielczarek, can be contacted via email at tam4@lehigh.edu. Please 52 | include Wad2Map in the subject line, or your mail is likely to be tossed aside. And 53 | don't complain about what's not implemented, unless you have an actual idea of how 54 | to do so. Praise (and money) are accepted. 55 | 56 | 57 | -Ted 58 | 2-11-2000 59 | -------------------------------------------------------------------------------- /wadentries.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | /* 22 | wadentries.cpp 23 | 24 | Ted Mielczarek 25 | 12/09/1999 26 | 27 | This file contains an index of doom level wad entries and 28 | a function to look them up into the enum defined in wadentries.h 29 | */ 30 | 31 | #include "stdafx.h" 32 | #include "defs.h" 33 | #include "wadfile.h" 34 | #include "doomlevel.h" 35 | #include "wadentries.h" 36 | 37 | // table of level entries 38 | const char WAD_ENTRY_NAMES[10][9] = 39 | { 40 | "THINGS", 41 | "LINEDEFS", 42 | "SIDEDEFS", 43 | "VERTEXES", 44 | "SEGS", 45 | "SSECTORS", 46 | "NODES", 47 | "SECTORS", 48 | "REJECT", 49 | "BLOCKMAP" 50 | }; 51 | 52 | levelentries LookupLevelEntry(char *s) 53 | { 54 | int i; 55 | 56 | if(strlen(s) == 4) 57 | if(s[0]=='E' && isdigit(s[1]) && s[2]=='M' && isdigit(s[3])) 58 | return(W_D1LEVEL); 59 | 60 | if(strlen(s) == 5) 61 | if(!strncmp(s,"MAP",3) && isdigit(s[3]) && isdigit(s[4])) 62 | return(W_D2LEVEL); 63 | 64 | for(i=0;in_vertices = wadFile.GetEntrySize() / sizeof(vertex_t); 88 | level->vertices = new vertex_t[level->n_vertices]; 89 | wadFile.GetEntryData(level->vertices); 90 | c++; 91 | break; 92 | case W_LINEDEFS: 93 | level->n_linedefs = wadFile.GetEntrySize() / sizeof(linedef_t); 94 | level->linedefs = new linedef_t[level->n_linedefs]; 95 | wadFile.GetEntryData(level->linedefs); 96 | c++; 97 | break; 98 | case W_SIDEDEFS: 99 | level->n_sidedefs = wadFile.GetEntrySize() / sizeof(sidedef_t); 100 | level->sidedefs = new sidedef_t[level->n_sidedefs]; 101 | wadFile.GetEntryData(level->sidedefs); 102 | c++; 103 | break; 104 | case W_SECTORS: 105 | level->n_sectors = wadFile.GetEntrySize() / sizeof(sector_t); 106 | level->sectors = new sector_t[level->n_sectors]; 107 | wadFile.GetEntryData(level->sectors); 108 | c++; 109 | break; 110 | case W_SEGS: 111 | level->n_segs = wadFile.GetEntrySize() / sizeof(segment_t); 112 | level->segs = new segment_t[level->n_segs]; 113 | wadFile.GetEntryData(level->segs); 114 | c++; 115 | break; 116 | case W_SSECTORS: 117 | level->n_ssectors = wadFile.GetEntrySize() / sizeof(ssector_t); 118 | level->ssectors = new ssector_t[level->n_ssectors]; 119 | wadFile.GetEntryData(level->ssectors); 120 | c++; 121 | break; 122 | case W_NODES: 123 | level->n_nodes = wadFile.GetEntrySize() / sizeof(node_t); 124 | level->nodes = new node_t[level->n_nodes]; 125 | wadFile.GetEntryData(level->nodes); 126 | c++; 127 | break; 128 | case W_THINGS: 129 | level->n_things = wadFile.GetEntrySize() / sizeof(thing_t); 130 | level->things = new thing_t[level->n_things]; 131 | wadFile.GetEntryData(level->things); 132 | c++; 133 | break; 134 | default: 135 | break; 136 | } 137 | } while(c < 8); 138 | 139 | return(true); 140 | } 141 | 142 | void LevelExtents(level_t *level) 143 | { 144 | int i; 145 | short xmin = short(0x7FFF); 146 | short xmax = short(0x8000); 147 | short ymin = short(0x7FFF); 148 | short ymax = short(0x8000); 149 | 150 | // get max/min x/y 151 | for(i=0;in_vertices;i++) { 152 | xmin = min(xmin,level->vertices[i].x); 153 | xmax = max(xmax,level->vertices[i].x); 154 | ymin = min(ymin,level->vertices[i].y); 155 | ymax = max(ymax,level->vertices[i].y); 156 | } 157 | 158 | // calc height, width, x/y center 159 | level->l_width = xmax - xmin; 160 | level->l_height = ymax - ymin; 161 | level->x_center = xmin + level->l_width / 2; 162 | level->y_center = ymin + level->l_height / 2; 163 | } 164 | 165 | void InitLevel(level_t *l) 166 | { 167 | memset(l,0,sizeof(level_t)); 168 | } 169 | 170 | void CleanupLevel(level_t *l) 171 | { 172 | if(l->linedefs != NULL) 173 | delete[] l->linedefs; 174 | if(l->nodes != NULL) 175 | delete[] l->nodes; 176 | if(l->sectors != NULL) 177 | delete[] l->sectors; 178 | if(l->segs != NULL) 179 | delete[] l->segs; 180 | if(l->sidedefs != NULL) 181 | delete[] l->sidedefs; 182 | if(l->ssectors != NULL) 183 | delete[] l->ssectors; 184 | if(l->vertices != NULL) 185 | delete[] l->vertices; 186 | if(l->things != NULL) 187 | delete[] l->things; 188 | 189 | memset(l,0,sizeof(level_t)); 190 | } 191 | 192 | void DumpLevel(char *filename, level_t *l) 193 | { 194 | FILE *f = fopen(filename,"w"); 195 | int i; 196 | 197 | if(f == NULL) 198 | return; 199 | 200 | fprintf(f,"Level Dump\n----------\n"); 201 | 202 | fprintf(f,"NODES\n-----\n"); 203 | for(i=0;in_nodes;i++) { 204 | fprintf(f,"Node %d:\n",i); 205 | fprintf(f,"x = %d\n" 206 | "y = %d\n" 207 | "dx = %d\n" 208 | "dy = %d\n" 209 | "left_y_upper = %d\n" 210 | "left_y_lower = %d\n" 211 | "left_x_upper = %d\n" 212 | "left_x_lower = %d\n" 213 | "right_y_upper = %d\n" 214 | "right_y_lower = %d\n" 215 | "right_x_upper = %d\n" 216 | "right_x_lower = %d\n" 217 | "left_child = %d\n" 218 | "right_child = %d\n\n", 219 | l->nodes[i].x,l->nodes[i].y, 220 | l->nodes[i].dx,l->nodes[i].dy, 221 | l->nodes[i].left_y_upper, 222 | l->nodes[i].left_y_lower, 223 | l->nodes[i].left_x_upper, 224 | l->nodes[i].left_x_lower, 225 | l->nodes[i].right_y_upper, 226 | l->nodes[i].right_y_lower, 227 | l->nodes[i].right_x_upper, 228 | l->nodes[i].right_x_lower, 229 | l->nodes[i].left_child, 230 | l->nodes[i].right_child); 231 | } 232 | 233 | fprintf(f,"SSECTORS\n--------\n"); 234 | for(i=0;in_ssectors;i++) { 235 | fprintf(f,"SSector %d:\n",i); 236 | fprintf(f, 237 | "numsegs = %d\n" 238 | "startseg = %d\n\n", 239 | l->ssectors[i].numsegs, 240 | l->ssectors[i].startseg); 241 | } 242 | 243 | fprintf(f,"SEGS\n----\n"); 244 | for(i=0;in_segs;i++) { 245 | fprintf(f,"Seg %d:\n",i); 246 | fprintf(f, 247 | "from_vertex = %d\n" 248 | "to_vertex = %d\n" 249 | "angle = %d\n" 250 | "linedef = %d\n" 251 | "side = %d\n" 252 | "distance = %d\n", 253 | l->segs[i].from_vertex, 254 | l->segs[i].to_vertex, 255 | l->segs[i].angle, 256 | l->segs[i].linedef, 257 | l->segs[i].side, 258 | l->segs[i].distance); 259 | } 260 | 261 | fclose(f); 262 | } 263 | -------------------------------------------------------------------------------- /wadentries.h: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at ted@mielczarek.org 20 | */ 21 | /* 22 | wadentries.h 23 | 24 | Ted Mielczarek 25 | 12/07/1999 26 | 27 | This file contains an enumeration of the different wad entry types. 28 | */ 29 | 30 | #ifndef __WADENTRIES_H_ 31 | #define __WADENTRIES_H_ 32 | 33 | typedef enum { 34 | W_THINGS = 0, 35 | W_LINEDEFS = 1, 36 | W_SIDEDEFS = 2, 37 | W_VERTEXES = 3, 38 | W_SEGS = 4, 39 | W_SSECTORS = 5, 40 | W_NODES = 6, 41 | W_SECTORS = 7, 42 | W_REJECT = 8, 43 | W_BLOCKMAP = 9, 44 | W_D1LEVEL, 45 | W_D2LEVEL, 46 | W_NOT_LEVEL_ENTRY 47 | } levelentries; 48 | 49 | extern const char WAD_ENTRY_NAMES[10][9]; 50 | #define NUM_LEVEL_ENTRIES 10 51 | 52 | // lookup function 53 | levelentries LookupLevelEntry(char *s); 54 | bool LoadLevelData(CWadFile &wadFile, level_t *level, char *szMap); 55 | void LevelExtents(level_t *level); 56 | void InitLevel(level_t *l); 57 | void CleanupLevel(level_t *l); 58 | void DumpLevel(char *filename, level_t *l); 59 | 60 | #endif /* __WADENTRIES_H_ */ 61 | -------------------------------------------------------------------------------- /wadfile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Wad2Map v1.0 3 | (c) 2000 Ted Mielczarek 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | You can contact the author of this program at tam4@lehigh.edu 20 | */ 21 | // WadFile.cpp: implementation of the CWadFile class. 22 | // 23 | ////////////////////////////////////////////////////////////////////// 24 | 25 | #include "stdafx.h" 26 | #include "wadfile.h" 27 | 28 | ////////////////////////////////////////////////////////////////////// 29 | // Construction/Destruction 30 | ////////////////////////////////////////////////////////////////////// 31 | 32 | CWadFile::CWadFile() 33 | { 34 | isOpen = false; 35 | wadfile = NULL; 36 | ZeroMemory(&header,sizeof(header)); 37 | directory = NULL; 38 | theWadType = NO_WAD; 39 | currentEntry = -1; 40 | } 41 | 42 | CWadFile::~CWadFile() 43 | { 44 | if(isOpen) 45 | Close(); 46 | } 47 | 48 | // Constructor with filename parameter 49 | CWadFile::CWadFile(char *szFile) 50 | { 51 | Open(szFile); 52 | } 53 | 54 | //------------------------------ 55 | // Open 56 | // Open a wad file with 57 | // the specified path/filename. 58 | // Return true for success, false 59 | // for failure. 60 | //------------------------------ 61 | bool CWadFile::Open(char *szFile) 62 | { 63 | if(isOpen) 64 | Close(); 65 | 66 | ZeroMemory(&header, sizeof(header)); 67 | 68 | wadfile = fopen(szFile,"rb"); 69 | 70 | if(wadfile == NULL) 71 | return(false); 72 | 73 | if(fread(&header,sizeof(wadheader_t),1,wadfile) != 1) { 74 | fclose(wadfile); 75 | return(false); 76 | } 77 | 78 | // Check wad type 79 | if(!strncmp(header.id,IWAD_ID,4)) 80 | // IWAD 81 | theWadType = IWAD; 82 | else if(!strncmp(header.id,PWAD_ID,4)) 83 | // PWAD 84 | theWadType = PWAD; 85 | else { 86 | // not a valid wadfile 87 | fclose(wadfile); 88 | return(false); 89 | } 90 | 91 | if(header.numlumps <= 0) { 92 | // empty wad 93 | theWadType = NO_WAD; 94 | fclose(wadfile); 95 | return(false); 96 | } 97 | 98 | if(fseek(wadfile,header.dirpos,SEEK_SET) != 0) { 99 | // couldn't find directory 100 | theWadType = NO_WAD; 101 | fclose(wadfile); 102 | return(false); 103 | } 104 | 105 | // allocate memory for wad directory 106 | directory = new waddirentry_t[header.numlumps]; 107 | 108 | if(directory == NULL) { // uh oh 109 | theWadType = NO_WAD; 110 | fclose(wadfile); 111 | return(false); 112 | } 113 | 114 | // attempt to read in directory 115 | if(fread(directory,sizeof(waddirentry_t),header.numlumps,wadfile) 116 | != unsigned(header.numlumps)) { 117 | delete[] directory; 118 | theWadType = NO_WAD; 119 | fclose(wadfile); 120 | return(false); 121 | } 122 | 123 | // start at first entry 124 | currentEntry = 0; 125 | if(fseek(wadfile,directory[0].offset,SEEK_SET) != 0) { 126 | delete[] directory; 127 | theWadType = NO_WAD; 128 | fclose(wadfile); 129 | return(false); 130 | } 131 | 132 | // wadfile is open 133 | isOpen = true; 134 | 135 | return(true); 136 | } 137 | 138 | //------------------------------ 139 | // IsOpen 140 | // Return true if a wadfile 141 | // is open, false if not. 142 | //------------------------------ 143 | bool CWadFile::IsOpen(void) 144 | { 145 | return(isOpen); 146 | } 147 | 148 | //------------------------------ 149 | // SeekTo 150 | // Find the first entry in 151 | // the wadfile with this name. 152 | // Return true if found, false 153 | // if not. 154 | //------------------------------ 155 | bool CWadFile::SeekTo(char *szEntry) 156 | { 157 | int i; 158 | 159 | if(szEntry == NULL || szEntry[0] == '\0') 160 | return(false); 161 | 162 | for(i=0;i 1000 29 | #pragma once 30 | #endif // _MSC_VER > 1000 31 | 32 | #include 33 | 34 | // This is defined for windows 35 | #ifndef ZeroMemory 36 | #define ZeroMemory(x,y) memset(x,0,y) 37 | #endif 38 | 39 | // Wad Header struct 40 | typedef struct s_wadheader 41 | { 42 | char id[4]; // wad id, either IWAD or PWAD 43 | uint32_t numlumps; // number of entries 44 | uint32_t dirpos; // offset to start of directory 45 | } wadheader_t; 46 | 47 | // Wad Directory Entry struct 48 | typedef struct s_waddirentry 49 | { 50 | uint32_t offset; // offset from start of wad, in bytes 51 | uint32_t size; // size, in bytes 52 | char name[8]; // name, padded with zeroes 53 | } waddirentry_t; 54 | 55 | // wad types 56 | static const char* IWAD_ID = "IWAD"; 57 | static const char* PWAD_ID = "PWAD"; 58 | 59 | enum wadtypes { 60 | NO_WAD, 61 | IWAD, 62 | PWAD 63 | }; 64 | 65 | class CWadFile 66 | { 67 | public: 68 | bool SeekFirst(char *szEntry); 69 | wadtypes WadType(void); 70 | void Close(void); 71 | long GetEntrySize(); 72 | bool GetEntryData(void *pData); 73 | bool SeekPrevious(char *szEntry); 74 | bool SeekNext(char *szEntry); 75 | bool SeekTo(char *szEntry); 76 | bool IsOpen(); 77 | bool Open(char *szFile); 78 | CWadFile(char *szFile); 79 | CWadFile(); 80 | virtual ~CWadFile(); 81 | 82 | private: 83 | bool isOpen; 84 | FILE *wadfile; 85 | wadheader_t header; 86 | waddirentry_t *directory; 87 | wadtypes theWadType; 88 | long currentEntry; 89 | }; 90 | 91 | #endif // !defined(AFX_WADFILE_H__852EB12B_ACEE_11D3_910E_0000E82F44A6__INCLUDED_) 92 | --------------------------------------------------------------------------------