|
|
1.1 root 1: // wad.c
2:
3: #include "quakedef.h"
4:
5: int wad_numlumps;
6: lumpinfo_t *wad_lumps;
7: byte *wad_base;
8:
9: void SwapPic (qpic_t *pic);
10:
11: /*
12: ==================
13: W_CleanupName
14:
15: Lowercases name and pads with spaces and a terminating 0 to the length of
16: lumpinfo_t->name.
17: Used so lumpname lookups can proceed rapidly by comparing 4 chars at a time
18: Space padding is so names can be printed nicely in tables.
19: Can safely be performed in place.
20: ==================
21: */
22: void W_CleanupName (char *in, char *out)
23: {
24: int i;
25: int c;
26:
27: for (i=0 ; i<16 ; i++ )
28: {
29: c = in[i];
30: if (!c)
31: break;
32:
33: if (c >= 'A' && c <= 'Z')
34: c += ('a' - 'A');
35: out[i] = c;
36: }
37:
38: for ( ; i< 16 ; i++ )
39: out[i] = 0;
40: }
41:
42:
43:
44: /*
45: ====================
46: W_LoadWadFile
47: ====================
48: */
49: void W_LoadWadFile (char *filename)
50: {
51: lumpinfo_t *lump_p;
52: wadinfo_t *header;
53: unsigned i;
54: int infotableofs;
55:
56: wad_base = COM_LoadHunkFile (filename);
57: if (!wad_base)
58: Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
59:
60: header = (wadinfo_t *)wad_base;
61:
62: if (header->identification[0] != 'W'
63: || header->identification[1] != 'A'
64: || header->identification[2] != 'D'
65: || header->identification[3] != '2')
66: Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename);
67:
68: wad_numlumps = LittleLong(header->numlumps);
69: infotableofs = LittleLong(header->infotableofs);
70: wad_lumps = (lumpinfo_t *)(wad_base + infotableofs);
71:
72: for (i=0, lump_p = wad_lumps ; i<wad_numlumps ; i++,lump_p++)
73: {
74: lump_p->filepos = LittleLong(lump_p->filepos);
75: lump_p->size = LittleLong(lump_p->size);
76: W_CleanupName (lump_p->name, lump_p->name);
77: if (lump_p->type == TYP_QPIC)
78: SwapPic ( (qpic_t *)(wad_base + lump_p->filepos));
79: }
80: }
81:
82:
83: /*
84: =============
85: W_GetLumpinfo
86: =============
87: */
88: lumpinfo_t *W_GetLumpinfo (char *name)
89: {
90: int i;
91: lumpinfo_t *lump_p;
92: char clean[16];
93:
94: W_CleanupName (name, clean);
95:
96: for (lump_p=wad_lumps, i=0 ; i<wad_numlumps ; i++,lump_p++)
97: {
98: if (!strcmp(clean, lump_p->name))
99: return lump_p;
100: }
101:
102: Sys_Error ("W_GetLumpinfo: %s not found", name);
103: return NULL;
104: }
105:
106: void *W_GetLumpName (char *name)
107: {
108: lumpinfo_t *lump;
109:
110: lump = W_GetLumpinfo (name);
111:
112: return (void *)(wad_base + lump->filepos);
113: }
114:
115: void *W_GetLumpNum (int num)
116: {
117: lumpinfo_t *lump;
118:
119: if (num < 0 || num > wad_numlumps)
120: Sys_Error ("W_GetLumpNum: bad number: %i", num);
121:
122: lump = wad_lumps + num;
123:
124: return (void *)(wad_base + lump->filepos);
125: }
126:
127: /*
128: =============================================================================
129:
130: automatic byte swapping
131:
132: =============================================================================
133: */
134:
135: void SwapPic (qpic_t *pic)
136: {
137: pic->width = LittleLong(pic->width);
138: pic->height = LittleLong(pic->height);
139: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.