1
//------------------------------------------------------------------------
2
// WAD : WAD read/write functions.
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
7
// Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
//------------------------------------------------------------------------
21
#ifndef __GLBSP_WAD_H__
22
#define __GLBSP_WAD_H__
36
enum { IWAD, PWAD } kind;
38
// number of entries in directory
41
// offset to start of directory
44
// current directory entries
45
struct lump_s *dir_head;
46
struct lump_s *dir_tail;
49
struct lump_s *current_level;
51
// array of level names found
52
const char ** level_names;
60
typedef struct level_s
65
// the child lump list
66
struct lump_s *children;
68
// for normal levels, this is the associated GL level lump
71
// information on overflow
78
/* this level information holds GL lumps */
79
#define LEVEL_IS_GL 0x0002
81
/* limit flags, to show what went wrong */
82
#define LIMIT_VERTEXES 0x000001
83
#define LIMIT_SECTORS 0x000002
84
#define LIMIT_SIDEDEFS 0x000004
85
#define LIMIT_LINEDEFS 0x000008
87
#define LIMIT_SEGS 0x000010
88
#define LIMIT_SSECTORS 0x000020
89
#define LIMIT_NODES 0x000040
91
#define LIMIT_GL_VERT 0x000100
92
#define LIMIT_GL_SEGS 0x000200
93
#define LIMIT_GL_SSECT 0x000400
94
#define LIMIT_GL_NODES 0x000800
96
#define LIMIT_BAD_SIDE 0x001000
97
#define LIMIT_BMAP_TRUNC 0x002000
98
#define LIMIT_BLOCKMAP 0x004000
99
#define LIMIT_ZDBSP 0x008000
104
typedef struct lump_s
113
// offset to start of lump
127
// level information, usually NULL
132
/* this lump should be copied from the input wad */
133
#define LUMP_COPY_ME 0x0004
135
/* this lump shouldn't be written to the output wad */
136
#define LUMP_IGNORE_ME 0x0008
138
/* this lump needs to be loaded */
139
#define LUMP_READ_ME 0x0100
141
/* this lump is new (didn't exist in the original) */
142
#define LUMP_NEW 0x0200
145
/* ----- function prototypes --------------------- */
147
// check if the filename has the given extension. Returns 1 if yes,
150
int CheckExtension(const char *filename, const char *ext);
152
// remove any extension from the given filename, and add the given
153
// extension, and return the newly creating filename.
155
char *ReplaceExtension(const char *filename, const char *ext);
157
// open the input wad file and read the contents into memory. When
158
// 'load_all' is false, lumps other than level info will be marked as
159
// copyable instead of loaded.
161
// Returns GLBSP_E_OK if all went well, otherwise an error code (in
162
// which case cur_comms->message has been set and all files/memory
165
glbsp_ret_e ReadWadFile(const char *filename);
167
// open the output wad file and write the contents. Any lumps marked
168
// as copyable will be copied from the input file instead of from
169
// memory. Lumps marked as ignorable will be skipped.
171
// Returns GLBSP_E_OK if all went well, otherwise an error code (in
172
// which case cur_comms->message has been set -- but no files/memory
175
glbsp_ret_e WriteWadFile(const char *filename);
177
// close all wad files and free any memory.
178
void CloseWads(void);
180
// delete the GWA file that is associated with the given normal
181
// wad file. It doesn't have to exist.
183
void DeleteGwaFile(const char *base_wad_name);
185
// returns the number of levels found in the wad.
186
int CountLevels(void);
188
// find the next level lump in the wad directory, and store the
189
// reference in 'wad.current_level'. Call this straight after
190
// ReadWadFile() to get the first level. Returns 1 if found,
191
// otherwise 0 if there are no more levels in the wad.
193
int FindNextLevel(void);
195
// return the current level name
196
const char *GetLevelName(void);
198
// find the level lump with the given name in the current level, and
199
// return a reference to it. Returns NULL if no such lump exists.
200
// Level lumps are always present in memory (i.e. never marked
203
lump_t *FindLevelLump(const char *name);
205
// tests if the level lump contains nothing but zeros.
206
int CheckLevelLumpZero(lump_t *lump);
208
// create a new lump in the current level with the given name. If
209
// such a lump already exists, it is truncated to zero length.
211
lump_t *CreateLevelLump(const char *name);
212
lump_t *CreateGLLump(const char *name);
214
// append some raw data to the end of the given level lump (created
215
// with the above function).
217
void AppendLevelLump(lump_t *lump, const void *data, int length);
219
// for the current GL lump, add a keyword/value pair into the
220
// level marker lump.
221
void AddGLTextLine(const char *keyword, const char *value);
223
// Zlib compression support
224
void ZLibBeginLump(lump_t *lump);
225
void ZLibAppendLump(const void *data, int length);
226
void ZLibFinishLump(void);
228
// mark the fact that this level failed to build.
229
void MarkSoftFailure(int soft);
230
void MarkHardFailure(int hard);
231
void MarkV5Switch(int v5);
232
void MarkZDSwitch(void);
234
// alert the user if any levels failed to build properly.
235
void ReportFailedLevels(void);
238
/* ----- conversion macros ----------------------- */
241
#define UINT8(x) ((uint8_g) (x))
242
#define SINT8(x) ((sint8_g) (x))
244
#define UINT16(x) Endian_U16(x)
245
#define UINT32(x) Endian_U32(x)
247
#define SINT16(x) ((sint16_g) Endian_U16((uint16_g) (x)))
248
#define SINT32(x) ((sint32_g) Endian_U32((uint32_g) (x)))
251
#endif /* __GLBSP_WAD_H__ */