mirror of
https://github.com/libretro/libretro-tyrquake.git
synced 2024-11-23 08:00:17 +00:00
wad: update wad API to take a wad_t structure
Instead of single global variables to access the one currently loaded wad, pass in a wad_t to access a specific wad. Currently this is only gfx.wad, so the global for this is held by NQ/host.c and QW/client/cl_main.c. Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
parent
c96289fb30
commit
fa3580ffb9
@ -56,6 +56,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* end.
|
||||
*/
|
||||
|
||||
wad_t host_gfx; /* "gfx.wad" */
|
||||
|
||||
quakeparms_t host_parms;
|
||||
|
||||
qboolean host_initialized; // true if into command execution
|
||||
@ -813,7 +815,7 @@ Host_Init(quakeparms_t *parms)
|
||||
Chase_Init();
|
||||
COM_Init();
|
||||
Host_InitLocal();
|
||||
W_LoadWadFile("gfx.wad");
|
||||
W_LoadWadFile(&host_gfx, "gfx.wad");
|
||||
Key_Init();
|
||||
Con_Init();
|
||||
M_Init();
|
||||
|
@ -23,9 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include "qtypes.h"
|
||||
#include "quakedef.h"
|
||||
#include "server.h"
|
||||
#include "wad.h"
|
||||
|
||||
// FIXME - some of this is out of place or badly named...
|
||||
|
||||
extern wad_t host_gfx; /* "gfx.wad" */
|
||||
|
||||
extern quakeparms_t host_parms;
|
||||
|
||||
extern cvar_t sys_ticrate;
|
||||
|
@ -45,11 +45,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include "screen.h"
|
||||
#include "sys.h"
|
||||
#include "view.h"
|
||||
#include "wad.h"
|
||||
|
||||
#ifndef GLQUAKE
|
||||
#include "d_iface.h"
|
||||
#endif
|
||||
|
||||
wad_t host_gfx; /* "gfx.wad" */
|
||||
|
||||
/* Argument completion function for the skin cvar */
|
||||
static struct stree_root * CL_Skin_Arg_f(const char *arg);
|
||||
|
||||
@ -1416,7 +1419,7 @@ Host_Init(quakeparms_t *parms)
|
||||
NET_Init(PORT_CLIENT);
|
||||
Netchan_Init();
|
||||
|
||||
W_LoadWadFile("gfx.wad");
|
||||
W_LoadWadFile(&host_gfx, "gfx.wad");
|
||||
Key_Init();
|
||||
Con_Init();
|
||||
M_Init();
|
||||
|
@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include "render.h"
|
||||
#include "sound.h"
|
||||
#include "vid.h"
|
||||
#include "wad.h"
|
||||
#include "zone.h"
|
||||
|
||||
//
|
||||
@ -348,6 +349,8 @@ extern dlight_t cl_dlights[MAX_DLIGHTS];
|
||||
//
|
||||
// cl_main
|
||||
//
|
||||
extern wad_t host_gfx; /* "gfx.wad" */
|
||||
|
||||
dlight_t *CL_AllocDlight(int key);
|
||||
|
||||
/* The standard dynamic light colors */
|
||||
|
@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include "zone.h"
|
||||
|
||||
#ifdef NQ_HACK
|
||||
#include "host.h"
|
||||
#include "sound.h"
|
||||
#endif
|
||||
#ifdef QW_HACK
|
||||
@ -70,7 +71,7 @@ static int menu_numcachepics;
|
||||
const qpic_t *
|
||||
Draw_PicFromWad(const char *name)
|
||||
{
|
||||
return W_GetLumpName(name);
|
||||
return W_GetLumpName(&host_gfx, name);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -126,9 +127,9 @@ Draw_Init
|
||||
void
|
||||
Draw_Init(void)
|
||||
{
|
||||
draw_chars = W_GetLumpName("conchars");
|
||||
draw_disc = W_GetLumpName("disc");
|
||||
draw_backtile = W_GetLumpName("backtile");
|
||||
draw_chars = W_GetLumpName(&host_gfx, "conchars");
|
||||
draw_disc = W_GetLumpName(&host_gfx, "disc");
|
||||
draw_backtile = W_GetLumpName(&host_gfx, "backtile");
|
||||
|
||||
r_rectdesc.width = draw_backtile->width;
|
||||
r_rectdesc.height = draw_backtile->height;
|
||||
|
@ -243,7 +243,7 @@ Draw_PicFromWad(const char *name)
|
||||
glpic_t *gl;
|
||||
scrap_t *scrap;
|
||||
|
||||
p = W_GetLumpName(name);
|
||||
p = W_GetLumpName(&host_gfx, name);
|
||||
gl = (glpic_t *)p->data;
|
||||
|
||||
// load little ones into the scrap
|
||||
@ -493,7 +493,7 @@ Draw_Init(void)
|
||||
// by hand, because we need to write the version
|
||||
// string into the background before turning
|
||||
// it into a texture
|
||||
draw_chars = W_GetLumpName("conchars");
|
||||
draw_chars = W_GetLumpName(&host_gfx, "conchars");
|
||||
for (i = 0; i < 256 * 64; i++)
|
||||
if (draw_chars[i] == 0)
|
||||
draw_chars[i] = 255; // proper transparent color
|
||||
|
@ -44,6 +44,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#ifdef NQ_HACK
|
||||
#include "host.h"
|
||||
#endif
|
||||
#ifdef QW_HACK
|
||||
#include "client.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@ -1498,9 +1501,9 @@ SCR_Init(void)
|
||||
scr_turtle = Draw_PicFromWad("turtle");
|
||||
#endif
|
||||
#ifdef QW_HACK
|
||||
scr_ram = W_GetLumpName("ram");
|
||||
scr_net = W_GetLumpName("net");
|
||||
scr_turtle = W_GetLumpName("turtle");
|
||||
scr_ram = W_GetLumpName(&host_gfx, "ram");
|
||||
scr_net = W_GetLumpName(&host_gfx, "net");
|
||||
scr_turtle = W_GetLumpName(&host_gfx, "turtle");
|
||||
|
||||
Cvar_RegisterVariable(&scr_allowsnap);
|
||||
Cmd_AddCommand("snap", SCR_RSShot_f);
|
||||
|
63
common/wad.c
63
common/wad.c
@ -24,12 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include "sys.h"
|
||||
#include "wad.h"
|
||||
|
||||
int wad_numlumps;
|
||||
lumpinfo_t *wad_lumps;
|
||||
byte *wad_base;
|
||||
|
||||
void SwapPic(qpic_t *pic);
|
||||
|
||||
/*
|
||||
==================
|
||||
W_CleanupName
|
||||
@ -47,7 +41,7 @@ W_CleanupName(const char *in, char *out)
|
||||
int i;
|
||||
int c;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
for (i = 0; i < LUMP_NAMELEN - 1; i++) {
|
||||
c = in[i];
|
||||
if (!c)
|
||||
break;
|
||||
@ -57,30 +51,29 @@ W_CleanupName(const char *in, char *out)
|
||||
out[i] = c;
|
||||
}
|
||||
|
||||
for (; i < 16; i++)
|
||||
for (; i < LUMP_NAMELEN; i++)
|
||||
out[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
====================
|
||||
W_LoadWadFile
|
||||
====================
|
||||
*/
|
||||
void
|
||||
W_LoadWadFile(const char *filename)
|
||||
W_LoadWadFile(wad_t *wad, const char *filename)
|
||||
{
|
||||
lumpinfo_t *lump_p;
|
||||
lumpinfo_t *lump;
|
||||
wadinfo_t *header;
|
||||
unsigned i;
|
||||
int infotableofs;
|
||||
|
||||
wad_base = COM_LoadHunkFile(filename);
|
||||
if (!wad_base)
|
||||
wad->base = COM_LoadHunkFile(filename);
|
||||
if (!wad->base)
|
||||
Sys_Error("%s: couldn't load %s", __func__, filename);
|
||||
|
||||
header = (wadinfo_t *)wad_base;
|
||||
header = (wadinfo_t *)wad->base;
|
||||
|
||||
if (header->identification[0] != 'W'
|
||||
|| header->identification[1] != 'A'
|
||||
@ -88,16 +81,16 @@ W_LoadWadFile(const char *filename)
|
||||
|| header->identification[3] != '2')
|
||||
Sys_Error("Wad file %s doesn't have WAD2 id", filename);
|
||||
|
||||
wad_numlumps = LittleLong(header->numlumps);
|
||||
wad->numlumps = LittleLong(header->numlumps);
|
||||
infotableofs = LittleLong(header->infotableofs);
|
||||
wad_lumps = (lumpinfo_t *)(wad_base + infotableofs);
|
||||
wad->lumps = (lumpinfo_t *)(wad->base + infotableofs);
|
||||
|
||||
for (i = 0, lump_p = wad_lumps; i < wad_numlumps; i++, lump_p++) {
|
||||
lump_p->filepos = LittleLong(lump_p->filepos);
|
||||
lump_p->size = LittleLong(lump_p->size);
|
||||
W_CleanupName(lump_p->name, lump_p->name);
|
||||
if (lump_p->type == TYP_QPIC)
|
||||
SwapPic((qpic_t *)(wad_base + lump_p->filepos));
|
||||
for (i = 0, lump = wad->lumps; i < wad->numlumps; i++, lump++) {
|
||||
lump->filepos = LittleLong(lump->filepos);
|
||||
lump->size = LittleLong(lump->size);
|
||||
W_CleanupName(lump->name, lump->name);
|
||||
if (lump->type == TYP_QPIC)
|
||||
SwapPic((qpic_t *)(wad->base + lump->filepos));
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,43 +101,43 @@ W_GetLumpinfo
|
||||
=============
|
||||
*/
|
||||
lumpinfo_t *
|
||||
W_GetLumpinfo(const char *name)
|
||||
W_GetLumpinfo(wad_t *wad, const char *name)
|
||||
{
|
||||
int i;
|
||||
lumpinfo_t *lump_p;
|
||||
char clean[16];
|
||||
lumpinfo_t *lump;
|
||||
char clean[LUMP_NAMELEN];
|
||||
|
||||
W_CleanupName(name, clean);
|
||||
|
||||
for (lump_p = wad_lumps, i = 0; i < wad_numlumps; i++, lump_p++) {
|
||||
if (!strcmp(clean, lump_p->name))
|
||||
return lump_p;
|
||||
for (lump = wad->lumps, i = 0; i < wad->numlumps; i++, lump++) {
|
||||
if (!strcmp(clean, lump->name))
|
||||
return lump;
|
||||
}
|
||||
|
||||
Sys_Error("%s: %s not found", __func__, name);
|
||||
}
|
||||
|
||||
void *
|
||||
W_GetLumpName(const char *name)
|
||||
W_GetLumpName(wad_t *wad, const char *name)
|
||||
{
|
||||
lumpinfo_t *lump;
|
||||
|
||||
lump = W_GetLumpinfo(name);
|
||||
lump = W_GetLumpinfo(wad, name);
|
||||
|
||||
return (void *)(wad_base + lump->filepos);
|
||||
return wad->base + lump->filepos;
|
||||
}
|
||||
|
||||
void *
|
||||
W_GetLumpNum(int num)
|
||||
W_GetLumpNum(wad_t *wad, int num)
|
||||
{
|
||||
lumpinfo_t *lump;
|
||||
|
||||
if (num < 0 || num > wad_numlumps)
|
||||
if (num < 0 || num >= wad->numlumps)
|
||||
Sys_Error("%s: bad number: %i", __func__, num);
|
||||
|
||||
lump = wad_lumps + num;
|
||||
lump = wad->lumps + num;
|
||||
|
||||
return (void *)(wad_base + lump->filepos);
|
||||
return wad->base + lump->filepos;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -51,6 +51,7 @@ typedef struct {
|
||||
int infotableofs;
|
||||
} wadinfo_t;
|
||||
|
||||
#define LUMP_NAMELEN 16
|
||||
typedef struct {
|
||||
int filepos;
|
||||
int disksize;
|
||||
@ -58,18 +59,20 @@ typedef struct {
|
||||
char type;
|
||||
char compression;
|
||||
char pad1, pad2;
|
||||
char name[16]; // must be null terminated
|
||||
char name[LUMP_NAMELEN]; // must be null terminated
|
||||
} lumpinfo_t;
|
||||
|
||||
extern int wad_numlumps;
|
||||
extern lumpinfo_t *wad_lumps;
|
||||
extern byte *wad_base;
|
||||
typedef struct {
|
||||
int numlumps;
|
||||
lumpinfo_t *lumps;
|
||||
byte *base;
|
||||
} wad_t;
|
||||
|
||||
void W_LoadWadFile(const char *filename);
|
||||
void W_LoadWadFile(wad_t *wad, const char *filename);
|
||||
void W_CleanupName(const char *in, char *out);
|
||||
lumpinfo_t *W_GetLumpinfo(const char *name);
|
||||
void *W_GetLumpName(const char *name);
|
||||
void *W_GetLumpNum(int num);
|
||||
lumpinfo_t *W_GetLumpinfo(wad_t *wad, const char *name);
|
||||
void *W_GetLumpName(wad_t *wad, const char *name);
|
||||
void *W_GetLumpNum(wad_t *wad, int num);
|
||||
|
||||
void SwapPic(qpic_t *pic);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user