1 //----------------------------------------------------------------------------
2 // EDGE WAD Support Code
3 //----------------------------------------------------------------------------
4 //
5 // Copyright (c) 1999-2008 The EDGE Team.
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 //----------------------------------------------------------------------------
18 //
19 // Based on the DOOM source code, released by Id Software under the
20 // following copyright:
21 //
22 // Copyright (C) 1993-1996 by id Software, Inc.
23 //
24 //----------------------------------------------------------------------------
25
26 #ifndef __W_WAD__
27 #define __W_WAD__
28
29 #include "dm_defs.h"
30
31 #include "epi/file.h"
32 #include "epi/utility.h"
33
34 typedef enum
35 {
36 FLKIND_IWad = 0, // iwad file
37 FLKIND_PWad, // normal .wad file
38 FLKIND_EWad, // EDGE.wad
39 FLKIND_GWad, // glbsp node wad
40 FLKIND_HWad, // deHacked wad
41
42 FLKIND_Lump, // raw lump (no extension)
43
44 FLKIND_DDF, // .ddf or .ldf file
45 FLKIND_Demo, // .lmp demo file
46 FLKIND_RTS, // .rts script
47 FLKIND_Deh // .deh or .bex file
48 }
49 filekind_e;
50
51 class wadtex_resource_c
52 {
53 public:
wadtex_resource_c()54 wadtex_resource_c() : palette(-1), pnames(-1), texture1(-1), texture2(-1)
55 { }
56
57 // lump numbers, or -1 if nonexistent
58 int palette;
59 int pnames;
60 int texture1;
61 int texture2;
62 };
63
64 typedef enum
65 {
66 LMPLST_Sprites,
67 LMPLST_Flats,
68 LMPLST_Patches
69 }
70 lumplist_e;
71
72 extern int numlumps;
73 extern int addwadnum;
74
75 void W_AddRawFilename(const char *file, int kind);
76 void W_InitMultipleFiles(void);
77 void W_ReadDDF(void);
78 void W_ReadCoalLumps(void);
79
80 int W_CheckNumForName2(const char *name);
81 int W_CheckNumForName_GFX(const char *name);
82 int W_GetNumForName2(const char *name);
83 int W_CheckNumForTexPatch(const char *name);
84
85 int W_LumpLength(int lump);
86
87 void W_DoneWithLump(const void *ptr);
88 void W_DoneWithLump_Flushable(const void *ptr);
89 const void *W_CacheLumpNum2(int lump);
90 const void *W_CacheLumpName2(const char *name);
91 void W_PreCacheLumpNum(int lump);
92 void W_PreCacheLumpName(const char *name);
93 void *W_LoadLumpNum(int lump);
94 void *W_LoadLumpName(const char *name);
95 bool W_VerifyLumpName(int lump, const char *name);
96 const char *W_GetLumpName(int lump);
97 int W_CacheInfo(int level);
98 byte *W_ReadLumpAlloc(int lump, int *length);
99
100 epi::file_c *W_OpenLump(int lump);
101 epi::file_c *W_OpenLump(const char *name);
102
103 const char *W_GetFileName(int lump);
104 int W_GetPaletteForLump(int lump);
105 int W_FindFlatSequence(const char *start, const char *end,
106 int *s_offset, int *e_offset);
107 epi::u32array_c& W_GetListLumps(int file, lumplist_e which);
108 void W_GetTextureLumps(int file, wadtex_resource_c *res);
109 void W_ProcessTX_HI(void);
110 int W_GetNumFiles(void);
111 int W_GetFileForLump(int lump);
112 void W_ShowLumps(int for_file, const char *match);
113 void W_ShowFiles(void);
114
115 // Define this only in an emergency. All these debug printfs quickly
116 // add up, and it takes only a few seconds to end up with a 40 meg debug file!
117 #ifdef WAD_CHECK
W_CheckNumForName3(const char * x,const char * file,int line)118 static int W_CheckNumForName3(const char *x, const char *file, int line)
119 {
120 Debug_Printf("Find '%s' @ %s:%d\n", x, file, line);
121 return W_CheckNumForName2(x);
122 }
123
W_GetNumForName3(const char * x,const char * file,int line)124 static int W_GetNumForName3(const char *x, const char *file, int line)
125 {
126 Debug_Printf("Find '%s' @ %s:%d\n", x, file, line);
127 return W_GetNumForName2(x);
128 }
129
W_CacheLumpNum3(int lump,const char * file,int line)130 static void *W_CacheLumpNum3(int lump, const char *file, int line)
131 {
132 Debug_Printf("Cache '%d' @ %s:%d\n", lump, file, line);
133 return W_CacheLumpNum2(lump, tag);
134 }
135
W_CacheLumpName3(const char * name,const char * file,int line)136 static void *W_CacheLumpName3(const char *name, const char *file, int line)
137 {
138 Debug_Printf("Cache '%s' @ %s:%d\n", name, file, line);
139 return W_CacheLumpName2(name, tag);
140 }
141
142 #define W_CheckNumForName(x) W_CheckNumForName3(x, __FILE__, __LINE__)
143 #define W_GetNumForName(x) W_GetNumForName3(x, __FILE__, __LINE__)
144 #define W_CacheLumpNum(x) W_CacheLumpNum3(x, __FILE__, __LINE__)
145 #define W_CacheLumpName(x) W_CacheLumpName3(x, __FILE__, __LINE__)
146
147 #else
148 #define W_CheckNumForName(x) W_CheckNumForName2(x)
149 #define W_GetNumForName(x) W_GetNumForName2(x)
150 #define W_CacheLumpNum(x) W_CacheLumpNum2(x)
151 #define W_CacheLumpName(x) W_CacheLumpName2(x)
152 #endif
153
154 #endif // __W_WAD__
155
156 //--- editor settings ---
157 // vi:ts=4:sw=4:noexpandtab
158