DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
wad.h File Reference
#include <stdint.h>
+ Include dependency graph for wad.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lumpinfo_t
 
struct  qpic_t
 
struct  wadinfo_t
 

Macros

#define CMP_LZSS   1
 
#define CMP_NONE   0
 
#define TYP_LABEL   1
 
#define TYP_LUMPY   64
 
#define TYP_MIPTEX   68
 
#define TYP_NONE   0
 
#define TYP_PALETTE   64
 
#define TYP_QPIC   66
 
#define TYP_QTEX   65
 
#define TYP_SOUND   67
 

Functions

unsigned char * W_ConvertWAD3TextureBGRA (struct sizebuf_s *sb)
 
unsigned char * W_GetLumpName (const char *name, int64_t *returnfilesize)
 
unsigned char * W_GetTextureBGRA (char *name)
 
void W_LoadTextureWadFile (char *filename, int complain)
 
void W_UnloadAll (void)
 

Macro Definition Documentation

◆ CMP_LZSS

#define CMP_LZSS   1

Definition at line 33 of file wad.h.

◆ CMP_NONE

#define CMP_NONE   0

Definition at line 32 of file wad.h.

◆ TYP_LABEL

#define TYP_LABEL   1

Definition at line 36 of file wad.h.

◆ TYP_LUMPY

#define TYP_LUMPY   64

Definition at line 38 of file wad.h.

◆ TYP_MIPTEX

#define TYP_MIPTEX   68

Definition at line 43 of file wad.h.

◆ TYP_NONE

#define TYP_NONE   0

Definition at line 35 of file wad.h.

◆ TYP_PALETTE

#define TYP_PALETTE   64

Definition at line 39 of file wad.h.

◆ TYP_QPIC

#define TYP_QPIC   66

Definition at line 41 of file wad.h.

◆ TYP_QTEX

#define TYP_QTEX   65

Definition at line 40 of file wad.h.

◆ TYP_SOUND

#define TYP_SOUND   67

Definition at line 42 of file wad.h.

Function Documentation

◆ W_ConvertWAD3TextureBGRA()

unsigned char * W_ConvertWAD3TextureBGRA ( struct sizebuf_s * sb)

◆ W_GetLumpName()

unsigned char * W_GetLumpName ( const char * name,
int64_t * returnfilesize )

Definition at line 114 of file wad.c.

115{
116 int i;
117 fs_offset_t filesize;
118 lumpinfo_t *lump;
119 char clean[16];
120 wadinfo_t *header;
121 int infotableofs;
122
123 W_CleanupName (name, clean);
124
125 if (!wad.gfx_base)
126 {
127 if ((wad.gfx_base = FS_LoadFile ("gfx.wad", cls.permanentmempool, false, &filesize)))
128 {
129 if (memcmp(wad.gfx_base, "WAD2", 4))
130 {
131 Con_Print("gfx.wad doesn't have WAD2 id\n");
133 wad.gfx_base = NULL;
134 }
135 else
136 {
137 header = (wadinfo_t *)wad.gfx_base;
139 infotableofs = LittleLong(header->infotableofs);
140 wad.gfx.lumps = (lumpinfo_t *)(wad.gfx_base + infotableofs);
141
142 // byteswap the gfx.wad lumps in place
144 }
145 }
146 }
147
148 for (lump = wad.gfx.lumps, i = 0;i < wad.gfx.numlumps;i++, lump++)
149 {
150 if (!strcmp(clean, lump->name))
151 {
152 if (returnfilesize)
153 *returnfilesize = lump->size;
154 return (wad.gfx_base + lump->filepos);
155 }
156 }
157 return NULL;
158}
client_static_t cls
Definition cl_main.c:116
#define LittleLong(l)
Definition common.h:92
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
unsigned char * FS_LoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3540
int64_t fs_offset_t
Definition fs.h:37
const GLchar * name
Definition glquake.h:601
int i
#define NULL
Definition qtypes.h:12
mempool_t * permanentmempool
Definition client.h:572
int filepos
Definition wad.h:62
char name[16]
Definition wad.h:68
int size
Definition wad.h:64
lumpinfo_t * lumps
Definition wad.c:30
int numlumps
Definition wad.c:29
int numlumps
Definition wad.h:56
int infotableofs
Definition wad.h:57
mwad_t gfx
Definition wad.c:37
unsigned char * gfx_base
Definition wad.c:36
static wadstate_t wad
Definition wad.c:42
static void W_SwapLumps(int numlumps, lumpinfo_t *lumps)
Definition wad.c:75
static void W_CleanupName(const char *in, char *out)
Definition wad.c:55
#define Mem_Free(mem)
Definition zone.h:96

References cls, Con_Print(), lumpinfo_t::filepos, FS_LoadFile(), wadstate_t::gfx, wadstate_t::gfx_base, i, wadinfo_t::infotableofs, LittleLong, mwad_t::lumps, Mem_Free, lumpinfo_t::name, name, NULL, mwad_t::numlumps, wadinfo_t::numlumps, client_static_t::permanentmempool, lumpinfo_t::size, W_CleanupName(), W_SwapLumps(), and wad.

Referenced by Image_GetStockPicSize(), and loadimagepixelsbgra().

◆ W_GetTextureBGRA()

unsigned char * W_GetTextureBGRA ( char * name)

Definition at line 277 of file wad.c.

278{
279 unsigned int i, k;
280 sizebuf_t sb;
281 unsigned char *data;
282 mwad_t *w;
283 char texname[17];
284 size_t range;
285
286 texname[16] = 0;
287 W_CleanupName(name, texname);
288 if (!wad.hlwads.mempool)
291 for (k = 0;k < range;k++)
292 {
294 if (!w)
295 continue;
296 for (i = 0;i < (unsigned int)w->numlumps;i++)
297 {
298 if (!strcmp(texname, w->lumps[i].name)) // found it
299 {
300 if (FS_Seek(w->file, w->lumps[i].filepos, SEEK_SET))
301 {Con_Print("W_GetTexture: corrupt WAD3 file\n");return NULL;}
302
303 MSG_InitReadBuffer(&sb, (unsigned char *)Mem_Alloc(tempmempool, w->lumps[i].disksize), w->lumps[i].disksize);
304 if (!sb.data)
305 return NULL;
306 if (FS_Read(w->file, sb.data, w->lumps[i].size) < w->lumps[i].disksize)
307 {Con_Print("W_GetTexture: corrupt WAD3 file\n");return NULL;}
308
310 Mem_Free(sb.data);
311 return data;
312 }
313 }
314 }
316 return NULL;
317}
void MSG_InitReadBuffer(sizebuf_t *buf, unsigned char *data, int size)
Definition com_msg.c:249
fs_offset_t FS_Read(qfile_t *file, void *buffer, size_t buffersize)
Definition fs.c:3066
int FS_Seek(qfile_t *file, fs_offset_t offset, int whence)
Definition fs.c:3359
static int(ZEXPORT *qz_inflate)(z_stream *strm
GLubyte GLubyte GLubyte GLubyte w
Definition glquake.h:782
GLsizeiptr const GLvoid * data
Definition glquake.h:639
int image_height
Definition image.c:10
int image_width
Definition image.c:9
mempool_t * mempool
Definition zone.h:137
Definition wad.c:27
unsigned char * data
Definition common.h:52
memexpandablearray_t hlwads
Definition wad.c:38
unsigned char * W_ConvertWAD3TextureBGRA(sizebuf_t *sb)
Definition wad.c:226
size_t Mem_ExpandableArray_IndexRange(const memexpandablearray_t *l)
Definition zone.c:763
void Mem_ExpandableArray_NewArray(memexpandablearray_t *l, mempool_t *mempool, size_t recordsize, int numrecordsperarray)
Definition zone.c:675
void * Mem_ExpandableArray_RecordAtIndex(const memexpandablearray_t *l, size_t index)
Definition zone.c:780
mempool_t * tempmempool
Definition zone.c:794
#define Mem_Alloc(pool, size)
Definition zone.h:92

References cls, Con_Print(), data, sizebuf_t::data, FS_Read(), FS_Seek(), wadstate_t::hlwads, i, image_height, image_width, int(), Mem_Alloc, Mem_ExpandableArray_IndexRange(), Mem_ExpandableArray_NewArray(), Mem_ExpandableArray_RecordAtIndex(), Mem_Free, memexpandablearray_t::mempool, MSG_InitReadBuffer(), name, NULL, client_static_t::permanentmempool, tempmempool, w, W_CleanupName(), W_ConvertWAD3TextureBGRA(), and wad.

Referenced by Mod_Q1BSP_LoadTextures().

◆ W_LoadTextureWadFile()

void W_LoadTextureWadFile ( char * filename,
int complain )

Definition at line 165 of file wad.c.

166{
167 wadinfo_t header;
168 int infotableofs;
169 qfile_t *file;
170 int numlumps;
171 mwad_t *w;
172
173 file = FS_OpenVirtualFile(filename, false);
174 if (!file)
175 {
176 if (complain)
177 Con_Printf(CON_ERROR "W_LoadTextureWadFile: couldn't find %s\n", filename);
178 return;
179 }
180
181 if (FS_Read(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
182 {Con_Print(CON_ERROR "W_LoadTextureWadFile: unable to read wad header\n");FS_Close(file);file = NULL;return;}
183
184 if(memcmp(header.identification, "WAD3", 4))
185 {Con_Printf(CON_ERROR "W_LoadTextureWadFile: Wad file %s doesn't have WAD3 id\n",filename);FS_Close(file);file = NULL;return;}
186
187 numlumps = LittleLong(header.numlumps);
188 if (numlumps < 1 || numlumps > 65536)
189 {Con_Printf(CON_ERROR "W_LoadTextureWadFile: invalid number of lumps (%i)\n", numlumps);FS_Close(file);file = NULL;return;}
190 infotableofs = LittleLong(header.infotableofs);
191 if (FS_Seek (file, infotableofs, SEEK_SET))
192 {Con_Print(CON_ERROR "W_LoadTextureWadFile: unable to seek to lump table\n");FS_Close(file);file = NULL;return;}
193
194 if (!wad.hlwads.mempool)
197 w->file = file;
198 w->numlumps = numlumps;
199 w->lumps = (lumpinfo_t *) Mem_Alloc(cls.permanentmempool, w->numlumps * sizeof(lumpinfo_t));
200
201 if (!w->lumps)
202 {
203 Con_Print(CON_ERROR "W_LoadTextureWadFile: unable to allocate temporary memory for lump table\n");
204 FS_Close(w->file);
205 w->file = NULL;
206 w->numlumps = 0;
207 return;
208 }
209
210 if (FS_Read(file, w->lumps, sizeof(lumpinfo_t) * w->numlumps) != (fs_offset_t)sizeof(lumpinfo_t) * numlumps)
211 {
212 Con_Print(CON_ERROR "W_LoadTextureWadFile: unable to read lump table\n");
213 FS_Close(w->file);
214 w->file = NULL;
215 w->numlumps = 0;
216 Mem_Free(w->lumps);
217 w->lumps = NULL;
218 return;
219 }
220
221 W_SwapLumps(w->numlumps, w->lumps);
222
223 // leaves the file open
224}
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
#define CON_ERROR
Definition console.h:102
qfile_t * FS_OpenVirtualFile(const char *filepath, qbool quiet)
Definition fs.c:2928
int FS_Close(qfile_t *file)
Definition fs.c:2970
char identification[4]
Definition wad.h:55
void * Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
Definition zone.c:695

References cls, CON_ERROR, Con_Print(), Con_Printf(), FS_Close(), FS_OpenVirtualFile(), FS_Read(), FS_Seek(), wadstate_t::hlwads, wadinfo_t::identification, wadinfo_t::infotableofs, LittleLong, Mem_Alloc, Mem_ExpandableArray_AllocRecord(), Mem_ExpandableArray_NewArray(), Mem_Free, memexpandablearray_t::mempool, NULL, wadinfo_t::numlumps, client_static_t::permanentmempool, w, W_SwapLumps(), and wad.

Referenced by Mod_Q1BSP_ParseWadsFromEntityLump().

◆ W_UnloadAll()

void W_UnloadAll ( void )

Definition at line 87 of file wad.c.

88{
89 unsigned int i;
90 mwad_t *w;
91 // free gfx.wad if it is loaded
92 if (wad.gfx_base)
95 // close all hlwad files and free their lumps data
97 {
99 if (!w)
100 continue;
101 if (w->file)
102 FS_Close(w->file);
103 w->file = NULL;
104 if (w->lumps)
105 Mem_Free(w->lumps);
106 w->lumps = NULL;
107 }
108 // free the hlwads array
110 // clear all state
111 memset(&wad, 0, sizeof(wad));
112}
void Mem_ExpandableArray_FreeArray(memexpandablearray_t *l)
Definition zone.c:683

References FS_Close(), wadstate_t::gfx_base, wadstate_t::hlwads, i, Mem_ExpandableArray_FreeArray(), Mem_ExpandableArray_IndexRange(), Mem_ExpandableArray_RecordAtIndex(), Mem_Free, NULL, w, and wad.

Referenced by FS_Rescan().