Add support for the 'qbsim' variant of q2bsp.

This commit is contained in:
Shpoike 2023-08-13 01:24:38 +01:00
parent 1f9f3635f0
commit 88514bda4f
4 changed files with 288 additions and 151 deletions

View file

@ -693,7 +693,7 @@ typedef struct
short maxs[3]; short maxs[3];
unsigned short firstface; unsigned short firstface;
unsigned short numfaces; // counting both sides unsigned short numfaces; // counting both sides
} q2dnode_t; } q2dsnode_t;
typedef struct typedef struct
{ {
@ -730,7 +730,23 @@ typedef struct
unsigned short firstleafbrush; unsigned short firstleafbrush;
unsigned short numleafbrushes; unsigned short numleafbrushes;
} q2dleaf_t; } q2dsleaf_t;
typedef struct
{
int contents; // OR of all brushes (not needed?)
int cluster;
int area;
float mins[3]; // for frustum culling
float maxs[3];
unsigned int firstleafface;
unsigned int numleaffaces;
unsigned int firstleafbrush;
unsigned int numleafbrushes;
} q2dlleaf_t;
typedef struct typedef struct
{ {
@ -749,7 +765,12 @@ typedef struct
{ {
unsigned short planenum; // facing out of the leaf unsigned short planenum; // facing out of the leaf
short texinfo; short texinfo;
} q2dbrushside_t; } q2dsbrushside_t;
typedef struct
{
unsigned int planenum; // facing out of the leaf
int texinfo;
} q2dlbrushside_t;
typedef struct typedef struct
{ {

View file

@ -51,8 +51,8 @@ extern cvar_t r_shadow_bumpscale_basetexture;
//these are in model.c (or gl_model.c) //these are in model.c (or gl_model.c)
qboolean Mod_LoadVertexes (model_t *loadmodel, qbyte *mod_base, lump_t *l); qboolean Mod_LoadVertexes (model_t *loadmodel, qbyte *mod_base, lump_t *l);
qboolean Mod_LoadVertexNormals (model_t *loadmodel, bspx_header_t *bspx, qbyte *mod_base, lump_t *l); qboolean Mod_LoadVertexNormals (model_t *loadmodel, bspx_header_t *bspx, qbyte *mod_base, lump_t *l);
qboolean Mod_LoadEdges (model_t *loadmodel, qbyte *mod_base, lump_t *l, qboolean lm); qboolean Mod_LoadEdges (model_t *loadmodel, qbyte *mod_base, lump_t *l, subbsp_t lm);
qboolean Mod_LoadMarksurfaces (model_t *loadmodel, qbyte *mod_base, lump_t *l, qboolean lm); qboolean Mod_LoadMarksurfaces (model_t *loadmodel, qbyte *mod_base, lump_t *l, subbsp_t lm);
qboolean Mod_LoadSurfedges (model_t *loadmodel, qbyte *mod_base, lump_t *l); qboolean Mod_LoadSurfedges (model_t *loadmodel, qbyte *mod_base, lump_t *l);
void Mod_LoadEntities (model_t *loadmodel, qbyte *mod_base, lump_t *l); void Mod_LoadEntities (model_t *loadmodel, qbyte *mod_base, lump_t *l);
@ -1659,9 +1659,10 @@ Mod_LoadFaces
================= =================
*/ */
#ifdef HAVE_CLIENT #ifdef HAVE_CLIENT
static qboolean CModQ2_LoadFaces (model_t *mod, qbyte *mod_base, lump_t *l, lump_t *lightlump, qboolean lightofsisdouble, bspx_header_t *bspx) static qboolean CModQ2_LoadFaces (model_t *mod, qbyte *mod_base, lump_t *l, lump_t *lightlump, qboolean lightofsisdouble, bspx_header_t *bspx, qboolean isbig)
{ {
dsface_t *in; dsface_t *ins = NULL;
dlface_t *inl = NULL;
msurface_t *out; msurface_t *out;
int i, count, surfnum; int i, count, surfnum;
int planenum, side; int planenum, side;
@ -1676,13 +1677,16 @@ static qboolean CModQ2_LoadFaces (model_t *mod, qbyte *mod_base, lump_t *l, lump
lightmapoverrides_t overrides = {0}; lightmapoverrides_t overrides = {0};
overrides.defaultshift = LMSHIFT_DEFAULT; overrides.defaultshift = LMSHIFT_DEFAULT;
in = (void *)(mod_base + l->fileofs); if (!isbig && !(l->filelen % sizeof(*ins)))
if (l->filelen % sizeof(*in)) ins = (void *)(mod_base + l->fileofs);
else if (isbig && !(l->filelen % sizeof(*inl)))
inl = (void *)(mod_base + l->fileofs);
else
{ {
Con_Printf ("MOD_LoadBmodel: funny lump size in %s\n",mod->name); Con_Printf ("MOD_LoadBmodel: funny lump size in %s\n",mod->name);
return false; return false;
} }
count = l->filelen / sizeof(*in); count = l->filelen / (isbig?sizeof(*inl):sizeof(*ins));
out = ZG_Malloc(&mod->memgroup, (count+6)*sizeof(*out)); //spare for skybox out = ZG_Malloc(&mod->memgroup, (count+6)*sizeof(*out)); //spare for skybox
mod->surfaces = out; mod->surfaces = out;
@ -1709,20 +1713,50 @@ static qboolean CModQ2_LoadFaces (model_t *mod, qbyte *mod_base, lump_t *l, lump
else else
decoupledlm = NULL; //wrong size somehow... discard it. decoupledlm = NULL; //wrong size somehow... discard it.
for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++) for ( surfnum=0 ; surfnum<count ; surfnum++, out++)
{ {
out->firstedge = LittleLong(in->firstedge); if (isbig)
out->numedges = (unsigned short)LittleShort(in->numedges); {
out->firstedge = LittleLong(inl->firstedge);
out->numedges = (unsigned int)LittleLong(inl->numedges);
planenum = (unsigned int)LittleLong(inl->planenum);
side = (unsigned int)LittleLong(inl->side);
ti = (unsigned int)LittleLong (inl->texinfo);
lofs = LittleLong(inl->lightofs);
for (i=0 ; i<4 ; i++)
{
style = inl->styles[i];
if (style == 0xff)
style = INVALID_LIGHTSTYLE;
else if (mod->lightmaps.maxstyle < style)
mod->lightmaps.maxstyle = style;
out->styles[i] = style;
}
inl++;
}
else
{
out->firstedge = LittleLong(ins->firstedge);
out->numedges = (unsigned short)LittleShort(ins->numedges);
planenum = (unsigned short)LittleShort(ins->planenum);
side = (unsigned short)LittleShort(ins->side);
ti = (unsigned short)LittleShort (ins->texinfo);
lofs = LittleLong(ins->lightofs);
for (i=0 ; i<4 ; i++)
{
style = ins->styles[i];
if (style == 0xff)
style = INVALID_LIGHTSTYLE;
else if (mod->lightmaps.maxstyle < style)
mod->lightmaps.maxstyle = style;
out->styles[i] = style;
}
ins++;
}
out->plane = mod->planes + planenum;
out->flags = 0; out->flags = 0;
planenum = (unsigned short)LittleShort(in->planenum);
side = (unsigned short)LittleShort(in->side);
if (side) if (side)
out->flags |= SURF_PLANEBACK; out->flags |= SURF_PLANEBACK;
out->plane = mod->planes + planenum;
ti = (unsigned short)LittleShort (in->texinfo);
if (ti < 0 || ti >= mod->numtexinfo) if (ti < 0 || ti >= mod->numtexinfo)
{ {
Con_Printf (CON_ERROR "MOD_LoadBmodel: bad texinfo number\n"); Con_Printf (CON_ERROR "MOD_LoadBmodel: bad texinfo number\n");
@ -1770,8 +1804,6 @@ static qboolean CModQ2_LoadFaces (model_t *mod, qbyte *mod_base, lump_t *l, lump
{ {
if (overrides.offsets) if (overrides.offsets)
lofs = overrides.offsets[surfnum]; lofs = overrides.offsets[surfnum];
else
lofs = LittleLong(in->lightofs);
CalcSurfaceExtents (mod, out); CalcSurfaceExtents (mod, out);
if (overrides.extents) if (overrides.extents)
@ -1806,18 +1838,6 @@ static qboolean CModQ2_LoadFaces (model_t *mod, qbyte *mod_base, lump_t *l, lump
out->styles[i] = style; out->styles[i] = style;
} }
} }
else
{
for (i=0 ; i<4 ; i++)
{
style = in->styles[i];
if (style == 0xff)
style = INVALID_LIGHTSTYLE;
else if (mod->lightmaps.maxstyle < style)
mod->lightmaps.maxstyle = style;
out->styles[i] = style;
}
}
for ( ; i<MAXCPULIGHTMAPS ; i++) for ( ; i<MAXCPULIGHTMAPS ; i++)
out->styles[i] = INVALID_LIGHTSTYLE; out->styles[i] = INVALID_LIGHTSTYLE;
if (lofs == ~0u) if (lofs == ~0u)
@ -1850,20 +1870,20 @@ CMod_LoadNodes
================= =================
*/ */
static qboolean CModQ2_LoadNodes (model_t *mod, qbyte *mod_base, lump_t *l) static qboolean CModQ2_LoadNodes (model_t *mod, qbyte *mod_base, lump_t *l, qboolean isbig)
{ {
q2dnode_t *in; q2dsnode_t *ins;
dl2node_t *inl;
int child; int child;
mnode_t *out; mnode_t *out;
int i, j, count; int i, j, count;
in = (void *)(mod_base + l->fileofs); if (l->filelen % (isbig?sizeof(*inl):sizeof(*ins)))
if (l->filelen % sizeof(*in))
{ {
Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n"); Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n");
return false; return false;
} }
count = l->filelen / sizeof(*in); count = l->filelen / (isbig?sizeof(*inl):sizeof(*ins));
if (count < 1) if (count < 1)
{ {
@ -1881,30 +1901,60 @@ static qboolean CModQ2_LoadNodes (model_t *mod, qbyte *mod_base, lump_t *l)
mod->nodes = out; mod->nodes = out;
mod->numnodes = count; mod->numnodes = count;
for (i=0 ; i<count ; i++, out++, in++) if (isbig)
{ {
memset(out, 0, sizeof(*out)); inl = (void *)(mod_base + l->fileofs);
for (i=0 ; i<count ; i++, out++, inl++)
for (j=0 ; j<3 ; j++)
{ {
out->minmaxs[j] = LittleShort (in->mins[j]); for (j=0 ; j<3 ; j++)
out->minmaxs[3+j] = LittleShort (in->maxs[j]); {
out->minmaxs[j] = LittleFloat (inl->mins[j]);
out->minmaxs[3+j] = LittleFloat (inl->maxs[j]);
}
out->plane = mod->planes + LittleLong(inl->planenum);
out->firstsurface = (unsigned int)LittleLong (inl->firstface);
out->numsurfaces = (unsigned int)LittleLong (inl->numfaces);
out->contents = -1; // differentiate from leafs
for (j=0 ; j<2 ; j++)
{
child = LittleLong (inl->children[j]);
out->childnum[j] = child;
if (child < 0)
out->children[j] = (mnode_t *)(mod->leafs + -1-child);
else
out->children[j] = mod->nodes + child;
}
} }
}
out->plane = mod->planes + LittleLong(in->planenum); else
{
out->firstsurface = (unsigned short)LittleShort (in->firstface); ins = (void *)(mod_base + l->fileofs);
out->numsurfaces = (unsigned short)LittleShort (in->numfaces); for (i=0 ; i<count ; i++, out++, ins++)
out->contents = -1; // differentiate from leafs
for (j=0 ; j<2 ; j++)
{ {
child = LittleLong (in->children[j]); for (j=0 ; j<3 ; j++)
out->childnum[j] = child; {
if (child < 0) out->minmaxs[j] = LittleShort (ins->mins[j]);
out->children[j] = (mnode_t *)(mod->leafs + -1-child); out->minmaxs[3+j] = LittleShort (ins->maxs[j]);
else }
out->children[j] = mod->nodes + child;
out->plane = mod->planes + LittleLong(ins->planenum);
out->firstsurface = (unsigned short)LittleShort (ins->firstface);
out->numsurfaces = (unsigned short)LittleShort (ins->numfaces);
out->contents = -1; // differentiate from leafs
for (j=0 ; j<2 ; j++)
{
child = LittleLong (ins->children[j]);
out->childnum[j] = child;
if (child < 0)
out->children[j] = (mnode_t *)(mod->leafs + -1-child);
else
out->children[j] = mod->nodes + child;
}
} }
} }
@ -1963,20 +2013,20 @@ static qboolean CModQ2_LoadBrushes (model_t *mod, qbyte *mod_base, lump_t *l)
CMod_LoadLeafs CMod_LoadLeafs
================= =================
*/ */
static qboolean CModQ2_LoadLeafs (model_t *mod, qbyte *mod_base, lump_t *l) static qboolean CModQ2_LoadLeafs (model_t *mod, qbyte *mod_base, lump_t *l, qboolean isbig)
{ {
int i, j; int i, j;
mleaf_t *out; mleaf_t *out;
q2dleaf_t *in; q2dsleaf_t *ins;
q2dlleaf_t *inl;
int count; int count;
in = (void *)(mod_base + l->fileofs); if (l->filelen % (isbig?sizeof(*inl):sizeof(*ins)))
if (l->filelen % sizeof(*in))
{ {
Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n"); Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n");
return false; return false;
} }
count = l->filelen / sizeof(*in); count = l->filelen / (isbig?sizeof(*inl):sizeof(*ins));
if (count < 1) if (count < 1)
{ {
@ -1996,31 +2046,62 @@ static qboolean CModQ2_LoadLeafs (model_t *mod, qbyte *mod_base, lump_t *l)
mod->leafs = out; mod->leafs = out;
mod->numleafs = count; mod->numleafs = count;
for ( i=0 ; i<count ; i++, in++, out++) memset(out, 0, sizeof(*out)*count);
if (isbig)
{ {
memset(out, 0, sizeof(*out)); inl = (void *)(mod_base + l->fileofs);
for ( i=0 ; i<count ; i++, inl++, out++)
for (j=0 ; j<3 ; j++)
{ {
out->minmaxs[j] = LittleShort (in->mins[j]); for (j=0 ; j<3 ; j++)
out->minmaxs[3+j] = LittleShort (in->maxs[j]); {
out->minmaxs[j] = LittleFloat (inl->mins[j]);
out->minmaxs[3+j] = LittleFloat (inl->maxs[j]);
}
out->contents = LittleLong (inl->contents);
out->cluster = (unsigned int)LittleLong (inl->cluster);
if (out->cluster == 0xffffffff)
out->cluster = -1;
out->area = (unsigned int)LittleLong (inl->area);
out->firstleafbrush = (unsigned int)LittleLong (inl->firstleafbrush);
out->numleafbrushes = (unsigned int)LittleLong (inl->numleafbrushes);
out->firstmarksurface = mod->marksurfaces +
(unsigned int)LittleLong(inl->firstleafface);
out->nummarksurfaces = (unsigned int)LittleLong(inl->numleaffaces);
if (out->cluster >= mod->numclusters)
mod->numclusters = out->cluster + 1;
} }
}
else
{
ins = (void *)(mod_base + l->fileofs);
for ( i=0 ; i<count ; i++, ins++, out++)
{
for (j=0 ; j<3 ; j++)
{
out->minmaxs[j] = LittleShort (ins->mins[j]);
out->minmaxs[3+j] = LittleShort (ins->maxs[j]);
}
out->contents = LittleLong (in->contents); out->contents = LittleLong (ins->contents);
out->cluster = (unsigned short)LittleShort (in->cluster); out->cluster = (unsigned short)LittleShort (ins->cluster);
if (out->cluster == 0xffff) if (out->cluster == 0xffff)
out->cluster = -1; out->cluster = -1;
out->area = (unsigned short)LittleShort (in->area); out->area = (unsigned short)LittleShort (ins->area);
out->firstleafbrush = (unsigned short)LittleShort (in->firstleafbrush); out->firstleafbrush = (unsigned short)LittleShort (ins->firstleafbrush);
out->numleafbrushes = (unsigned short)LittleShort (in->numleafbrushes); out->numleafbrushes = (unsigned short)LittleShort (ins->numleafbrushes);
out->firstmarksurface = mod->marksurfaces + out->firstmarksurface = mod->marksurfaces +
(unsigned short)LittleShort(in->firstleafface); (unsigned short)LittleShort(ins->firstleafface);
out->nummarksurfaces = (unsigned short)LittleShort(in->numleaffaces); out->nummarksurfaces = (unsigned short)LittleShort(ins->numleaffaces);
if (out->cluster >= mod->numclusters) if (out->cluster >= mod->numclusters)
mod->numclusters = out->cluster + 1; mod->numclusters = out->cluster + 1;
}
} }
out = mod->leafs; out = mod->leafs;
mod->pvsbytes = ((mod->numclusters + 31)>>3)&~3; mod->pvsbytes = ((mod->numclusters + 31)>>3)&~3;
@ -2093,21 +2174,21 @@ static qboolean CModQ2_LoadPlanes (model_t *mod, qbyte *mod_base, lump_t *l)
CMod_LoadLeafBrushes CMod_LoadLeafBrushes
================= =================
*/ */
static qboolean CModQ2_LoadLeafBrushes (model_t *mod, qbyte *mod_base, lump_t *l) static qboolean CModQ2_LoadLeafBrushes (model_t *mod, qbyte *mod_base, lump_t *l, qboolean isbig)
{ {
cminfo_t *prv = (cminfo_t*)mod->meshinfo; cminfo_t *prv = (cminfo_t*)mod->meshinfo;
int i; int i;
q2cbrush_t **out; q2cbrush_t **out;
unsigned short *in; unsigned short *ins;
unsigned int *inl;
int count; int count;
in = (void *)(mod_base + l->fileofs); if (l->filelen % (isbig?sizeof(*inl):sizeof(*ins)))
if (l->filelen % sizeof(*in))
{ {
Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n"); Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n");
return false; return false;
} }
count = l->filelen / sizeof(*in); count = l->filelen / (isbig?sizeof(*inl):sizeof(*ins));
if (count < 1) if (count < 1)
{ {
@ -2125,8 +2206,18 @@ static qboolean CModQ2_LoadLeafBrushes (model_t *mod, qbyte *mod_base, lump_t *l
out = prv->leafbrushes = ZG_Malloc(&mod->memgroup, sizeof(*out) * (count+prv->numbrushes)); out = prv->leafbrushes = ZG_Malloc(&mod->memgroup, sizeof(*out) * (count+prv->numbrushes));
prv->numleafbrushes = count; prv->numleafbrushes = count;
for ( i=0 ; i<count ; i++, in++, out++) if (isbig)
*out = prv->brushes + (unsigned short)(short)LittleShort (*in); {
inl = (void *)(mod_base + l->fileofs);
for ( i=0 ; i<count ; i++, inl++, out++)
*out = prv->brushes + (unsigned int)LittleLong (*inl);
}
else
{
ins = (void *)(mod_base + l->fileofs);
for ( i=0 ; i<count ; i++, ins++, out++)
*out = prv->brushes + (unsigned short)(short)LittleShort (*ins);
}
return true; return true;
} }
@ -2136,22 +2227,22 @@ static qboolean CModQ2_LoadLeafBrushes (model_t *mod, qbyte *mod_base, lump_t *l
CMod_LoadBrushSides CMod_LoadBrushSides
================= =================
*/ */
static qboolean CModQ2_LoadBrushSides (model_t *mod, qbyte *mod_base, lump_t *l) static qboolean CModQ2_LoadBrushSides (model_t *mod, qbyte *mod_base, lump_t *l, qboolean isbig)
{ {
cminfo_t *prv = (cminfo_t*)mod->meshinfo; cminfo_t *prv = (cminfo_t*)mod->meshinfo;
unsigned int i, j; unsigned int i, j;
q2cbrushside_t *out; q2cbrushside_t *out;
q2dbrushside_t *in; q2dsbrushside_t *ins;
q2dlbrushside_t *inl;
int count; int count;
int num; int num;
in = (void *)(mod_base + l->fileofs); if (l->filelen % (isbig?sizeof(*inl):sizeof(*ins)))
if (l->filelen % sizeof(*in))
{ {
Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n"); Con_Printf (CON_ERROR "MOD_LoadBmodel: funny lump size\n");
return false; return false;
} }
count = l->filelen / sizeof(*in); count = l->filelen / (isbig?sizeof(*inl):sizeof(*ins));
// need to save space for box planes // need to save space for box planes
if (count > SANITY_MAX_MAP_BRUSHSIDES) if (count > SANITY_MAX_MAP_BRUSHSIDES)
@ -2163,15 +2254,33 @@ static qboolean CModQ2_LoadBrushSides (model_t *mod, qbyte *mod_base, lump_t *l)
out = prv->brushsides = ZG_Malloc(&mod->memgroup, sizeof(*out) * count); out = prv->brushsides = ZG_Malloc(&mod->memgroup, sizeof(*out) * count);
prv->numbrushsides = count; prv->numbrushsides = count;
for ( i=0 ; i<count ; i++, in++, out++) if (isbig)
{ {
num = (unsigned short)LittleShort (in->planenum); inl = (void *)(mod_base + l->fileofs);
out->plane = &mod->planes[num]; for ( i=0 ; i<count ; i++, inl++, out++)
j = (unsigned short)LittleShort (in->texinfo); {
if (j >= mod->numtexinfo) num = (unsigned int)LittleLong (inl->planenum);
out->surface = &nullsurface; out->plane = &mod->planes[num];
else j = (unsigned int)LittleLong (inl->texinfo);
out->surface = &prv->surfaces[j]; if (j >= mod->numtexinfo)
out->surface = &nullsurface;
else
out->surface = &prv->surfaces[j];
}
}
else
{
ins = (void *)(mod_base + l->fileofs);
for ( i=0 ; i<count ; i++, ins++, out++)
{
num = (unsigned short)LittleShort (ins->planenum);
out->plane = &mod->planes[num];
j = (unsigned short)LittleShort (ins->texinfo);
if (j >= mod->numtexinfo)
out->surface = &nullsurface;
else
out->surface = &prv->surfaces[j];
}
} }
return true; return true;
@ -2204,7 +2313,7 @@ static qboolean CModQ2_LoadAreas (model_t *mod, qbyte *mod_base, lump_t *l)
return false; return false;
} }
out = prv->q2areas = ZG_Malloc(&mod->memgroup, sizeof(*out) * count);; out = prv->q2areas = ZG_Malloc(&mod->memgroup, sizeof(*out) * count);
prv->numareas = count; prv->numareas = count;
for ( i=0 ; i<count ; i++, in++, out++) for ( i=0 ; i<count ; i++, in++, out++)
@ -4622,6 +4731,7 @@ static cmodel_t *CM_LoadMap (model_t *mod, qbyte *filein, size_t filelen, qboole
unsigned int facesize = 0; unsigned int facesize = 0;
#endif #endif
cminfo_t *prv; cminfo_t *prv;
qboolean isbig;
COM_FileBase (mod->name, loadname, sizeof(loadname)); COM_FileBase (mod->name, loadname, sizeof(loadname));
@ -4942,6 +5052,8 @@ static cmodel_t *CM_LoadMap (model_t *mod, qbyte *filein, size_t filelen, qboole
#ifdef Q2BSPS #ifdef Q2BSPS
case BSPVERSION_Q2: case BSPVERSION_Q2:
case BSPVERSION_Q2W: case BSPVERSION_Q2W:
isbig = *mod_base == 'Q'; //'qbism'
mod->lightmaps.width = LMBLOCK_SIZE_MAX; mod->lightmaps.width = LMBLOCK_SIZE_MAX;
mod->lightmaps.height = LMBLOCK_SIZE_MAX; mod->lightmaps.height = LMBLOCK_SIZE_MAX;
@ -4995,11 +5107,11 @@ static cmodel_t *CM_LoadMap (model_t *mod, qbyte *filein, size_t filelen, qboole
noerrors = noerrors && CModQ2_LoadSurfaces (mod, mod_base, &header.lumps[Q2LUMP_TEXINFO]); noerrors = noerrors && CModQ2_LoadSurfaces (mod, mod_base, &header.lumps[Q2LUMP_TEXINFO]);
noerrors = noerrors && CModQ2_LoadPlanes (mod, mod_base, &header.lumps[Q2LUMP_PLANES]); noerrors = noerrors && CModQ2_LoadPlanes (mod, mod_base, &header.lumps[Q2LUMP_PLANES]);
noerrors = noerrors && CModQ2_LoadVisibility (mod, mod_base, &header.lumps[Q2LUMP_VISIBILITY]); noerrors = noerrors && CModQ2_LoadVisibility (mod, mod_base, &header.lumps[Q2LUMP_VISIBILITY]);
noerrors = noerrors && CModQ2_LoadBrushSides (mod, mod_base, &header.lumps[Q2LUMP_BRUSHSIDES]); noerrors = noerrors && CModQ2_LoadBrushSides (mod, mod_base, &header.lumps[Q2LUMP_BRUSHSIDES], isbig);
noerrors = noerrors && CModQ2_LoadBrushes (mod, mod_base, &header.lumps[Q2LUMP_BRUSHES]); noerrors = noerrors && CModQ2_LoadBrushes (mod, mod_base, &header.lumps[Q2LUMP_BRUSHES]);
noerrors = noerrors && CModQ2_LoadLeafBrushes (mod, mod_base, &header.lumps[Q2LUMP_LEAFBRUSHES]); noerrors = noerrors && CModQ2_LoadLeafBrushes (mod, mod_base, &header.lumps[Q2LUMP_LEAFBRUSHES], isbig);
noerrors = noerrors && CModQ2_LoadLeafs (mod, mod_base, &header.lumps[Q2LUMP_LEAFS]); noerrors = noerrors && CModQ2_LoadLeafs (mod, mod_base, &header.lumps[Q2LUMP_LEAFS], isbig);
noerrors = noerrors && CModQ2_LoadNodes (mod, mod_base, &header.lumps[Q2LUMP_NODES]); noerrors = noerrors && CModQ2_LoadNodes (mod, mod_base, &header.lumps[Q2LUMP_NODES], isbig);
noerrors = noerrors && CModQ2_LoadSubmodels (mod, mod_base, &header.lumps[Q2LUMP_MODELS]); noerrors = noerrors && CModQ2_LoadSubmodels (mod, mod_base, &header.lumps[Q2LUMP_MODELS]);
noerrors = noerrors && CModQ2_LoadAreas (mod, mod_base, &header.lumps[Q2LUMP_AREAS]); noerrors = noerrors && CModQ2_LoadAreas (mod, mod_base, &header.lumps[Q2LUMP_AREAS]);
noerrors = noerrors && CModQ2_LoadAreaPortals (mod, mod_base, &header.lumps[Q2LUMP_AREAPORTALS]); noerrors = noerrors && CModQ2_LoadAreaPortals (mod, mod_base, &header.lumps[Q2LUMP_AREAPORTALS]);
@ -5008,41 +5120,39 @@ static cmodel_t *CM_LoadMap (model_t *mod, qbyte *filein, size_t filelen, qboole
break; break;
#ifdef HAVE_CLIENT #ifdef HAVE_CLIENT
default: default:
{ // load into heap
// load into heap noerrors = noerrors && Mod_LoadVertexes (mod, mod_base, &header.lumps[Q2LUMP_VERTEXES]);
noerrors = noerrors && Mod_LoadVertexes (mod, mod_base, &header.lumps[Q2LUMP_VERTEXES]); noerrors = noerrors && Mod_LoadEdges (mod, mod_base, &header.lumps[Q2LUMP_EDGES], isbig?sb_long2:sb_none);
noerrors = noerrors && Mod_LoadEdges (mod, mod_base, &header.lumps[Q2LUMP_EDGES], false); noerrors = noerrors && Mod_LoadSurfedges (mod, mod_base, &header.lumps[Q2LUMP_SURFEDGES]);
noerrors = noerrors && Mod_LoadSurfedges (mod, mod_base, &header.lumps[Q2LUMP_SURFEDGES]); noerrors = noerrors && CModQ2_LoadSurfaces (mod, mod_base, &header.lumps[Q2LUMP_TEXINFO]);
noerrors = noerrors && CModQ2_LoadSurfaces (mod, mod_base, &header.lumps[Q2LUMP_TEXINFO]); noerrors = noerrors && CModQ2_LoadPlanes (mod, mod_base, &header.lumps[Q2LUMP_PLANES]);
noerrors = noerrors && CModQ2_LoadPlanes (mod, mod_base, &header.lumps[Q2LUMP_PLANES]); noerrors = noerrors && CModQ2_LoadTexInfo (mod, mod_base, &header.lumps[Q2LUMP_TEXINFO], loadname);
noerrors = noerrors && CModQ2_LoadTexInfo (mod, mod_base, &header.lumps[Q2LUMP_TEXINFO], loadname); if (noerrors)
if (noerrors) Mod_LoadEntities (mod, mod_base, &header.lumps[Q2LUMP_ENTITIES]);
Mod_LoadEntities (mod, mod_base, &header.lumps[Q2LUMP_ENTITIES]); noerrors = noerrors && CModQ2_LoadFaces (mod, mod_base, &header.lumps[Q2LUMP_FACES], &header.lumps[Q2LUMP_LIGHTING], header.version == BSPVERSION_Q2W, bspx, isbig);
noerrors = noerrors && CModQ2_LoadFaces (mod, mod_base, &header.lumps[Q2LUMP_FACES], &header.lumps[Q2LUMP_LIGHTING], header.version == BSPVERSION_Q2W, bspx); Mod_LoadVertexNormals(mod, bspx, mod_base, (header.version == BSPVERSION_Q2W)?&header.lumps[19]:NULL);
Mod_LoadVertexNormals(mod, bspx, mod_base, (header.version == BSPVERSION_Q2W)?&header.lumps[19]:NULL); noerrors = noerrors && Mod_LoadMarksurfaces (mod, mod_base, &header.lumps[Q2LUMP_LEAFFACES], isbig?sb_long2:sb_none);
noerrors = noerrors && Mod_LoadMarksurfaces (mod, mod_base, &header.lumps[Q2LUMP_LEAFFACES], false); noerrors = noerrors && CModQ2_LoadVisibility (mod, mod_base, &header.lumps[Q2LUMP_VISIBILITY]);
noerrors = noerrors && CModQ2_LoadVisibility (mod, mod_base, &header.lumps[Q2LUMP_VISIBILITY]); noerrors = noerrors && CModQ2_LoadBrushSides (mod, mod_base, &header.lumps[Q2LUMP_BRUSHSIDES], isbig);
noerrors = noerrors && CModQ2_LoadBrushSides (mod, mod_base, &header.lumps[Q2LUMP_BRUSHSIDES]); noerrors = noerrors && CModQ2_LoadBrushes (mod, mod_base, &header.lumps[Q2LUMP_BRUSHES]);
noerrors = noerrors && CModQ2_LoadBrushes (mod, mod_base, &header.lumps[Q2LUMP_BRUSHES]); noerrors = noerrors && CModQ2_LoadLeafBrushes (mod, mod_base, &header.lumps[Q2LUMP_LEAFBRUSHES], isbig);
noerrors = noerrors && CModQ2_LoadLeafBrushes (mod, mod_base, &header.lumps[Q2LUMP_LEAFBRUSHES]); noerrors = noerrors && CModQ2_LoadLeafs (mod, mod_base, &header.lumps[Q2LUMP_LEAFS], isbig);
noerrors = noerrors && CModQ2_LoadLeafs (mod, mod_base, &header.lumps[Q2LUMP_LEAFS]); noerrors = noerrors && CModQ2_LoadNodes (mod, mod_base, &header.lumps[Q2LUMP_NODES], isbig);
noerrors = noerrors && CModQ2_LoadNodes (mod, mod_base, &header.lumps[Q2LUMP_NODES]); noerrors = noerrors && CModQ2_LoadSubmodels (mod, mod_base, &header.lumps[Q2LUMP_MODELS]);
noerrors = noerrors && CModQ2_LoadSubmodels (mod, mod_base, &header.lumps[Q2LUMP_MODELS]); noerrors = noerrors && CModQ2_LoadAreas (mod, mod_base, &header.lumps[Q2LUMP_AREAS]);
noerrors = noerrors && CModQ2_LoadAreas (mod, mod_base, &header.lumps[Q2LUMP_AREAS]); noerrors = noerrors && CModQ2_LoadAreaPortals (mod, mod_base, &header.lumps[Q2LUMP_AREAPORTALS]);
noerrors = noerrors && CModQ2_LoadAreaPortals (mod, mod_base, &header.lumps[Q2LUMP_AREAPORTALS]);
if (!noerrors) if (!noerrors)
{ {
return NULL; return NULL;
}
mod->funcs.LightPointValues = GLQ2BSP_LightPointValues;
mod->funcs.StainNode = GLR_Q2BSP_StainNode;
mod->funcs.MarkLights = Q2BSP_MarkLights;
mod->funcs.PrepareFrame = CM_PrepareFrame;
#ifdef RTLIGHTS
mod->funcs.GenerateShadowMesh = Q2BSP_GenerateShadowMesh;
#endif
} }
mod->funcs.LightPointValues = GLQ2BSP_LightPointValues;
mod->funcs.StainNode = GLR_Q2BSP_StainNode;
mod->funcs.MarkLights = Q2BSP_MarkLights;
mod->funcs.PrepareFrame = CM_PrepareFrame;
#ifdef RTLIGHTS
mod->funcs.GenerateShadowMesh = Q2BSP_GenerateShadowMesh;
#endif
break; break;
#endif #endif
} }

View file

@ -2944,7 +2944,10 @@ qboolean Mod_BSPXRW_Read(struct bspxrw *ctx, const char *fname)
ctx->lumps = 0; ctx->lumps = 0;
ctx->totallumps = 0; ctx->totallumps = 0;
i = LittleLong(*(int*)ctx->origfile); if (ctx->origsize < 4)
i = 0;
else
i = LittleLong(*(int*)ctx->origfile);
switch(i) switch(i)
{ {
case 29: case 29:
@ -2977,6 +2980,7 @@ qboolean Mod_BSPXRW_Read(struct bspxrw *ctx, const char *fname)
#endif #endif
default: default:
Mod_BSPXRW_Free(ctx); Mod_BSPXRW_Free(ctx);
Con_Printf(CON_ERROR"%s: Unknown 'IBSP' revision\n", fname);
return false; return false;
} }
break; break;
@ -2987,19 +2991,21 @@ qboolean Mod_BSPXRW_Read(struct bspxrw *ctx, const char *fname)
ctx->lumpofs = 8; ctx->lumpofs = 8;
switch(i) switch(i)
{ {
case BSPVERSION_RBSP: case BSPVERSION_RBSP: //both rbsp+fbsp are version 1, with the only difference being lightmap sizes.
ctx->fg = fg_quake3; ctx->fg = fg_quake3;
ctx->corelumps = 18; ctx->corelumps = 18;
corelumpnames = q3corelumpnames; corelumpnames = q3corelumpnames;
break; break;
default: default:
Mod_BSPXRW_Free(ctx); Mod_BSPXRW_Free(ctx);
Con_Printf(CON_ERROR"%s: Unknown 'RBSP'/'FBSP' revision\n", fname);
return false; return false;
} }
break; break;
#endif #endif
default: default:
Mod_BSPXRW_Free(ctx); Mod_BSPXRW_Free(ctx);
Con_Printf(CON_ERROR"%s: Unknown file magic\n", fname);
return false; return false;
} }

View file

@ -708,18 +708,18 @@ void Mod_Init (qboolean initial)
#endif #endif
//q2/q3bsps //q2/q3bsps
#if defined(Q2BSPS) || defined(Q3BSPS) #ifdef Q3BSPS
#ifndef Q2BSPS Mod_RegisterModelFormatMagic(NULL, "RTCW Map (bsp)", "IBSP\57\0\0\0",8, Mod_LoadQ2BrushModel);
Mod_RegisterModelFormatMagic(NULL, "Quake3 Map (bsp)", IDBSPHEADER, Mod_LoadQ2BrushModel); Mod_RegisterModelFormatMagic(NULL, "Quake3 Map (bsp)", "IBSP\56\0\0\0",8, Mod_LoadQ2BrushModel);
#elif !defined(Q3BSPS)
Mod_RegisterModelFormatMagic(NULL, "Quake2 Map (bsp)", IDBSPHEADER, Mod_LoadQ2BrushModel);
#else
Mod_RegisterModelFormatMagic(NULL, "Quake2/Quake3 Map (bsp)", IDBSPHEADER, Mod_LoadQ2BrushModel);
#endif #endif
#ifdef Q2BSPS
Mod_RegisterModelFormatMagic(NULL, "Quake2 Map (bsp)", "IBSP\46\0\0\0",8, Mod_LoadQ2BrushModel);
Mod_RegisterModelFormatMagic(NULL, "Quake2World Map (bsp)", "IBSP\105\0\0\0",8, Mod_LoadQ2BrushModel);
Mod_RegisterModelFormatMagic(NULL, "Qbism (Quake2) Map (bsp)", "QBSP\46\0\0\0",8, Mod_LoadQ2BrushModel);
#endif #endif
#ifdef RFBSPS #ifdef RFBSPS
Mod_RegisterModelFormatMagic(NULL, "Raven Map (bsp)", "RBSP",4, Mod_LoadQ2BrushModel); Mod_RegisterModelFormatMagic(NULL, "Raven Map (bsp)", "RBSP\1\0\0\0",8, Mod_LoadQ2BrushModel);
Mod_RegisterModelFormatMagic(NULL, "QFusion Map (bsp)", "FBSP",4, Mod_LoadQ2BrushModel); Mod_RegisterModelFormatMagic(NULL, "QFusion Map (bsp)", "FBSP\1\0\0\0",8, Mod_LoadQ2BrushModel);
#endif #endif
//doom maps //doom maps