forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / Games / Quake / wad.c
blobc84f72c6d51ff6a76131b1fb6927987145c8d80f
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
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.
20 // wad.c
22 #include "quakedef.h"
24 int wad_numlumps;
25 lumpinfo_t *wad_lumps;
26 byte *wad_base;
28 void SwapPic (qpic_t *pic);
31 ==================
32 W_CleanupName
34 Lowercases name and pads with spaces and a terminating 0 to the length of
35 lumpinfo_t->name.
36 Used so lumpname lookups can proceed rapidly by comparing 4 chars at a time
37 Space padding is so names can be printed nicely in tables.
38 Can safely be performed in place.
39 ==================
41 void W_CleanupName (char *in, char *out)
43 int i;
44 int c;
46 for (i=0 ; i<16 ; i++ )
48 c = in[i];
49 if (!c)
50 break;
52 if (c >= 'A' && c <= 'Z')
53 c += ('a' - 'A');
54 out[i] = c;
57 for ( ; i< 16 ; i++ )
58 out[i] = 0;
64 ====================
65 W_LoadWadFile
66 ====================
68 void W_LoadWadFile (char *filename)
70 lumpinfo_t *lump_p;
71 wadinfo_t *header;
72 unsigned i;
73 int infotableofs;
75 wad_base = COM_LoadHunkFile (filename);
76 if (!wad_base)
77 Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
79 header = (wadinfo_t *)wad_base;
81 if (header->identification[0] != 'W'
82 || header->identification[1] != 'A'
83 || header->identification[2] != 'D'
84 || header->identification[3] != '2')
85 Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename);
87 wad_numlumps = LittleLong(header->numlumps);
88 infotableofs = LittleLong(header->infotableofs);
89 wad_lumps = (lumpinfo_t *)(wad_base + infotableofs);
91 for (i=0, lump_p = wad_lumps ; i<wad_numlumps ; i++,lump_p++)
93 lump_p->filepos = LittleLong(lump_p->filepos);
94 lump_p->size = LittleLong(lump_p->size);
95 W_CleanupName (lump_p->name, lump_p->name);
96 if (lump_p->type == TYP_QPIC)
97 SwapPic ( (qpic_t *)(wad_base + lump_p->filepos));
103 =============
104 W_GetLumpinfo
105 =============
107 lumpinfo_t *W_GetLumpinfo (char *name)
109 int i;
110 lumpinfo_t *lump_p;
111 char clean[16];
113 W_CleanupName (name, clean);
115 for (lump_p=wad_lumps, i=0 ; i<wad_numlumps ; i++,lump_p++)
117 if (!strcmp(clean, lump_p->name))
118 return lump_p;
121 Sys_Error ("W_GetLumpinfo: %s not found", name);
122 return NULL;
125 void *W_GetLumpName (char *name)
127 lumpinfo_t *lump;
129 lump = W_GetLumpinfo (name);
131 return (void *)(wad_base + lump->filepos);
134 void *W_GetLumpNum (int num)
136 lumpinfo_t *lump;
138 if (num < 0 || num > wad_numlumps)
139 Sys_Error ("W_GetLumpNum: bad number: %i", num);
141 lump = wad_lumps + num;
143 return (void *)(wad_base + lump->filepos);
147 =============================================================================
149 automatic byte swapping
151 =============================================================================
154 void SwapPic (qpic_t *pic)
156 pic->width = LittleLong(pic->width);
157 pic->height = LittleLong(pic->height);