From 8d21ed68745feef3185be64fe0adbc6c52f7c176 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Thu, 18 Apr 2024 00:18:07 +0300 Subject: [PATCH] renders: remove support of QBSP map format Map should be converted from any format to QBSP before render by Mod_Load2QBSP --- src/client/refresh/files/maps.c | 296 ++--------------------------- src/client/refresh/gl1/gl1_model.c | 269 ++------------------------ src/client/refresh/gl3/gl3_model.c | 269 ++------------------------ src/client/refresh/gl4/gl4_model.c | 269 ++------------------------ src/client/refresh/soft/sw_model.c | 277 ++------------------------- src/client/refresh/vk/vk_model.c | 269 ++------------------------ src/common/cmodels.c | 16 +- src/server/sv_send.c | 2 +- 8 files changed, 85 insertions(+), 1582 deletions(-) diff --git a/src/client/refresh/files/maps.c b/src/client/refresh/files/maps.c index 0081f0d7..2e4ab6cf 100644 --- a/src/client/refresh/files/maps.c +++ b/src/client/refresh/files/maps.c @@ -413,70 +413,6 @@ Mod_CalcSurfaceExtents(const int *surfedges, mvertex_t *vertexes, medge_t *edges } } -void -Mod_LoadTexinfoRBSP(const char *name, mtexinfo_t **texinfo, int *numtexinfo, - const byte *mod_base, const lump_t *l, findimage_t find_image, - struct image_s *notexture, maptype_t maptype) -{ - texrinfo_t *in; - mtexinfo_t *out; - int i, count; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, name); - } - - count = l->filelen / sizeof(*in); - /* extra for skybox in soft render */ - out = Hunk_Alloc((count + EXTRA_LUMP_TEXINFO) * sizeof(*out)); - - *texinfo = out; - *numtexinfo = count; - - for ( i=0 ; ivecs[0][j] = LittleFloat(in->vecs[0][j]); - out->vecs[1][j] = LittleFloat(in->vecs[1][j]); - } - - /* Convert flags for game type */ - out->flags = Mod_LoadSurfConvertFlags(LittleLong(in->flags), maptype); - - next = LittleLong(in->nexttexinfo); - if (next > 0) - { - out->next = *texinfo + next; - } - else - { - /* - * Fix for the problem where the game - * domed core when loading a new level. - */ - out->next = NULL; - } - - image = GetTexImage(in->texture, find_image); - if (!image) - { - R_Printf(PRINT_ALL, "%s: Couldn't load %s\n", - __func__, in->texture); - image = notexture; - } - - out->image = image; - } -} - void Mod_LoadTexinfoQ2(const char *name, mtexinfo_t **texinfo, int *numtexinfo, const byte *mod_base, const lump_t *l, findimage_t find_image, @@ -559,16 +495,8 @@ Mod_LoadTexinfo(const char *name, mtexinfo_t **texinfo, int *numtexinfo, { int i; - if (maptype == map_sin) - { - Mod_LoadTexinfoRBSP(name, texinfo, numtexinfo, mod_base, l, find_image, - notexture, maptype); - } - else - { - Mod_LoadTexinfoQ2(name, texinfo, numtexinfo, mod_base, l, find_image, - notexture, maptype); - } + Mod_LoadTexinfoQ2(name, texinfo, numtexinfo, mod_base, l, find_image, + notexture, maptype); // count animation frames for (i = 0; i < *numtexinfo; i++) @@ -785,14 +713,7 @@ Mod_LoadBSPX(int filesize, const byte *mod_base, maptype_t maptype) header = (dheader_t*)mod_base; xofs = 0; - numlumps = HEADER_LUMPS; - if ((header->version == BSPDKMVERSION) && - (maptype == map_daikatana)) - { - numlumps = 21; - } - - for (i = 0; i < numlumps; i++) + for (i = 0; i < HEADER_LUMPS; i++) { xofs = Q_max(xofs, (header->lumps[i].fileofs + header->lumps[i].filelen + 3) & ~3); @@ -1343,156 +1264,6 @@ Mod_LoadBSPXLightGrid(const bspx_header_t *bspx_header, const byte *mod_base) return grid; } -static int -calcTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl) -{ - dface_t* face_in = (void *)(mod_base + fl->fileofs); - const texinfo_t* texinfo_in = (void *)(mod_base + tl->fileofs); - - if (fl->filelen % sizeof(*face_in) || tl->filelen % sizeof(*texinfo_in)) - { - // will error out when actually loading it - return 0; - } - - int ret = 0; - - int face_count = fl->filelen / sizeof(*face_in); - int texinfo_count = tl->filelen / sizeof(*texinfo_in); - - { - int baseSize = (face_count + EXTRA_LUMP_FACES) * sizeof(msurface_t); - baseSize = (baseSize + 31) & ~31; - ret += baseSize; - - int ti_size = texinfo_count * sizeof(mtexinfo_t); - ti_size = (ti_size + 31) & ~31; - ret += ti_size; - } - - int numWarpFaces = 0; - - for (int surfnum = 0; surfnum < face_count; surfnum++, face_in++) - { - int numverts = LittleShort(face_in->numedges); - int ti = LittleShort(face_in->texinfo); - int texFlags = LittleLong(texinfo_in[ti].flags); - - if ((ti < 0) || (ti >= texinfo_count)) - { - return 0; // will error out - } - - /* set the drawing flags */ - if (texFlags & SURF_WARP) - { - if (numverts > 60) - return 0; // will error out in R_SubdividePolygon() - - // R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */ - // for each (pot. recursive) call to R_SubdividePolygon(): - // sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t) - - // this is tricky, how much is allocated depends on the size of the surface - // which we don't know (we'd need the vertices etc to know, but we can't load - // those without allocating...) - // so we just count warped faces and use a generous estimate below - - ++numWarpFaces; - } - else - { - // LM_BuildPolygonFromSurface(out); - // => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t)); - int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t); - polySize = (polySize + 31) & ~31; - ret += polySize; - } - } - - // yeah, this is a bit hacky, but it looks like for each warped face - // 256-55000 bytes are allocated (usually on the lower end), - // so just assume 48k per face to be safe - ret += numWarpFaces * 49152; - - return ret; -} - -static int -calcRBSPTexinfoAndFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl) -{ - drface_t* face_in = (void *)(mod_base + fl->fileofs); - const texrinfo_t* texinfo_in = (void *)(mod_base + tl->fileofs); - - if (fl->filelen % sizeof(*face_in) || tl->filelen % sizeof(*texinfo_in)) - { - // will error out when actually loading it - return 0; - } - - int ret = 0; - - int face_count = fl->filelen / sizeof(*face_in); - int texinfo_count = tl->filelen / sizeof(*texinfo_in); - - { - int baseSize = (face_count + EXTRA_LUMP_FACES) * sizeof(msurface_t); - baseSize = (baseSize + 31) & ~31; - ret += baseSize; - - int ti_size = texinfo_count * sizeof(mtexinfo_t); - ti_size = (ti_size + 31) & ~31; - ret += ti_size; - } - - int numWarpFaces = 0; - - for (int surfnum = 0; surfnum < face_count; surfnum++, face_in++) - { - int numverts = LittleShort(face_in->numedges); - int ti = LittleShort(face_in->texinfo); - int texFlags = LittleLong(texinfo_in[ti].flags); - - if ((ti < 0) || (ti >= texinfo_count)) - { - return 0; // will error out - } - - /* set the drawing flags */ - if (texFlags & SURF_WARP) - { - if (numverts > 60) - return 0; // will error out in R_SubdividePolygon() - - // R_SubdivideSurface(out, loadmodel); /* cut up polygon for warps */ - // for each (pot. recursive) call to R_SubdividePolygon(): - // sizeof(mpoly_t) + ((numverts - 4) + 2) * sizeof(mvtx_t) - - // this is tricky, how much is allocated depends on the size of the surface - // which we don't know (we'd need the vertices etc to know, but we can't load - // those without allocating...) - // so we just count warped faces and use a generous estimate below - - ++numWarpFaces; - } - else - { - // LM_BuildPolygonFromSurface(out); - // => poly = Hunk_Alloc(sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t)); - int polySize = sizeof(mpoly_t) + (numverts - 4) * sizeof(mvtx_t); - polySize = (polySize + 31) & ~31; - ret += polySize; - } - } - - // yeah, this is a bit hacky, but it looks like for each warped face - // 256-55000 bytes are allocated (usually on the lower end), - // so just assume 48k per face to be safe - ret += numWarpFaces * 49152; - - return ret; -} - static int calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *tl) { @@ -1575,63 +1346,22 @@ Mod_CalcNonModelLumpHunkSize(const byte *mod_base, const dheader_t *header, hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t), EXTRA_LUMP_VERTEXES); - - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_EDGES], - sizeof(dedge_t), sizeof(medge_t), EXTRA_LUMP_EDGES); - - if (maptype == map_sin) - { - hunkSize += calcRBSPTexinfoAndFacesSize(mod_base, - &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); - } - else - { - hunkSize += calcTexinfoAndFacesSize(mod_base, - &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); - } - - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], - sizeof(short), sizeof(msurface_t *), 0); // yes, out is indeed a pointer! - - if ((maptype == map_daikatana) && - (header->lumps[LUMP_LEAFS].filelen % sizeof(ddkleaf_t) == 0)) - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(ddkleaf_t), sizeof(mleaf_t), 0); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dleaf_t), sizeof(mleaf_t), 0); - } - - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_EDGES], - sizeof(dqedge_t), sizeof(medge_t), EXTRA_LUMP_EDGES); - hunkSize += calcTexinfoAndQFacesSize(mod_base, - &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], - sizeof(int), sizeof(msurface_t *), 0); // yes, out is indeed a pointer! - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dqleaf_t), sizeof(mleaf_t), 0); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } - + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_EDGES], + sizeof(dqedge_t), sizeof(medge_t), EXTRA_LUMP_EDGES); + hunkSize += calcTexinfoAndQFacesSize(mod_base, + &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]); + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], + sizeof(int), sizeof(msurface_t *), 0); // yes, out is indeed a pointer! + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], + sizeof(dqleaf_t), sizeof(mleaf_t), 0); + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], + sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int), EXTRA_LUMP_SURFEDGES); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LIGHTING], 1, 1, 0); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), EXTRA_LUMP_PLANES); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1, 0); diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 08d4daa6..cac99d19 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -159,15 +159,15 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l) for (j = 0; j < 3; j++) { /* spread the mins / maxs by a pixel */ - out->mins[j] = LittleFloat(in->mins[j]) - 1; - out->maxs[j] = LittleFloat(in->maxs[j]) + 1; - out->origin[j] = LittleFloat(in->origin[j]); + out->mins[j] = in->mins[j] - 1; + out->maxs[j] = in->maxs[j] + 1; + out->origin[j] = in->origin[j]; } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->firstnode = LittleLong(in->headnode); - out->firstmodelsurface = LittleLong(in->firstface); - out->nummodelsurfaces = LittleLong(in->numfaces); + out->firstnode = in->headnode; + out->firstmodelsurface = in->firstface; + out->nummodelsurfaces = in->numfaces; // visleafs out->numleafs = 0; // check limits @@ -179,236 +179,6 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l) } } -static void -Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - dface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - -static void -Mod_LoadRFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - drface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - static void Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, const bspx_header_t *bspx_header) @@ -445,8 +215,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, { int side, ti, planenum, lightofs; - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleLong(in->numedges); + out->firstedge = in->firstedge; + out->numedges = in->numedges; if (out->numedges < 3) { @@ -456,8 +226,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, out->flags = 0; out->polys = NULL; - planenum = LittleLong(in->planenum); - side = LittleLong(in->side); + planenum = in->planenum; + side = in->side; if (side) { @@ -588,24 +358,7 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) r_notexture, maptype); LM_BeginBuildingLightmaps(mod); - - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if (maptype == map_sin) - { - Mod_LoadRFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - else - { - Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - } - else - { - Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - + Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); LM_EndBuildingLightmaps(); Mod_LoadQBSPMarksurfaces(mod->name, &mod->marksurfaces, &mod->nummarksurfaces, diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 7435603a..48096122 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -160,15 +160,15 @@ Mod_LoadSubmodels(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l) for (j = 0; j < 3; j++) { /* spread the mins / maxs by a pixel */ - out->mins[j] = LittleFloat(in->mins[j]) - 1; - out->maxs[j] = LittleFloat(in->maxs[j]) + 1; - out->origin[j] = LittleFloat(in->origin[j]); + out->mins[j] = in->mins[j] - 1; + out->maxs[j] = in->maxs[j] + 1; + out->origin[j] = in->origin[j]; } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->firstnode = LittleLong(in->headnode); - out->firstmodelsurface = LittleLong(in->firstface); - out->nummodelsurfaces = LittleLong(in->numfaces); + out->firstnode = in->headnode; + out->firstmodelsurface = in->firstface; + out->nummodelsurfaces = in->numfaces; // visleafs out->numleafs = 0; // check limits @@ -180,236 +180,6 @@ Mod_LoadSubmodels(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l) } } -static void -Mod_LoadFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - dface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - -static void -Mod_LoadRFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - drface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - static void Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l, const bspx_header_t *bspx_header) @@ -446,8 +216,8 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l, { int side, ti, planenum, lightofs; - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleLong(in->numedges); + out->firstedge = in->firstedge; + out->numedges = in->numedges; if (out->numedges < 3) { @@ -457,8 +227,8 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l, out->flags = 0; out->polys = NULL; - planenum = LittleLong(in->planenum); - side = LittleLong(in->side); + planenum = in->planenum; + side = in->side; if (side) { @@ -589,24 +359,7 @@ Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int filelen) gl3_notexture, maptype); LM_BeginBuildingLightmaps(mod); - - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if (maptype == map_sin) - { - Mod_LoadRFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - else - { - Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - } - else - { - Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - + Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); LM_EndBuildingLightmaps(); Mod_LoadQBSPMarksurfaces(mod->name, &mod->marksurfaces, &mod->nummarksurfaces, diff --git a/src/client/refresh/gl4/gl4_model.c b/src/client/refresh/gl4/gl4_model.c index 65e4d3a3..c0103e17 100644 --- a/src/client/refresh/gl4/gl4_model.c +++ b/src/client/refresh/gl4/gl4_model.c @@ -160,15 +160,15 @@ Mod_LoadSubmodels(gl4model_t *loadmodel, byte *mod_base, lump_t *l) for (j = 0; j < 3; j++) { /* spread the mins / maxs by a pixel */ - out->mins[j] = LittleFloat(in->mins[j]) - 1; - out->maxs[j] = LittleFloat(in->maxs[j]) + 1; - out->origin[j] = LittleFloat(in->origin[j]); + out->mins[j] = in->mins[j] - 1; + out->maxs[j] = in->maxs[j] + 1; + out->origin[j] = in->origin[j]; } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->firstnode = LittleLong(in->headnode); - out->firstmodelsurface = LittleLong(in->firstface); - out->nummodelsurfaces = LittleLong(in->numfaces); + out->firstnode = in->headnode; + out->firstmodelsurface = in->firstface; + out->nummodelsurfaces = in->numfaces; // visleafs out->numleafs = 0; // check limits @@ -180,236 +180,6 @@ Mod_LoadSubmodels(gl4model_t *loadmodel, byte *mod_base, lump_t *l) } } -static void -Mod_LoadFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - dface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - -static void -Mod_LoadRFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - drface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - static void Mod_LoadQFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l, const bspx_header_t *bspx_header) @@ -446,8 +216,8 @@ Mod_LoadQFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l, { int side, ti, planenum, lightofs; - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleLong(in->numedges); + out->firstedge = in->firstedge; + out->numedges = in->numedges; if (out->numedges < 3) { @@ -457,8 +227,8 @@ Mod_LoadQFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l, out->flags = 0; out->polys = NULL; - planenum = LittleLong(in->planenum); - side = LittleLong(in->side); + planenum = in->planenum; + side = in->side; if (side) { @@ -589,24 +359,7 @@ Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int filelen) gl4_notexture, maptype); LM_BeginBuildingLightmaps(mod); - - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if (maptype == map_sin) - { - Mod_LoadRFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - else - { - Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - } - else - { - Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - + Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); LM_EndBuildingLightmaps(); Mod_LoadQBSPMarksurfaces(mod->name, &mod->marksurfaces, &mod->nummarksurfaces, diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index efeac37f..f586136c 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -163,15 +163,15 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l) for (j = 0; j < 3; j++) { /* spread the mins / maxs by a pixel */ - out->mins[j] = LittleFloat(in->mins[j]) - 1; - out->maxs[j] = LittleFloat(in->maxs[j]) + 1; - out->origin[j] = LittleFloat(in->origin[j]); + out->mins[j] = in->mins[j] - 1; + out->maxs[j] = in->maxs[j] + 1; + out->origin[j] = in->origin[j]; } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->firstnode = LittleLong(in->headnode); - out->firstmodelsurface = LittleLong(in->firstface); - out->nummodelsurfaces = LittleLong(in->numfaces); + out->firstnode = in->headnode; + out->firstmodelsurface = in->firstface; + out->nummodelsurfaces = in->numfaces; // visleafs out->numleafs = 0; // check limits @@ -183,244 +183,6 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l) } } -static void -Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum; - msurface_t *out; - dface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = -1; - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (!out->texinfo->image) - continue; - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - continue; - } - } - - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - continue; - } - - //============== - // this marks flowing surfaces as turbulent. - if (out->texinfo->flags & SURF_FLOWING) - { - out->flags |= SURF_DRAWTURB; - for (i=0 ; i<2 ; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - continue; - } - //============== - } -} - -static void -Mod_LoadRFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum; - msurface_t *out; - drface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = -1; - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, in->lightofs); - - if (!out->texinfo->image) - continue; - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - continue; - } - } - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - continue; - } - - //============== - // this marks flowing surfaces as turbulent. - if (out->texinfo->flags & SURF_FLOWING) - { - out->flags |= SURF_DRAWTURB; - for (i=0 ; i<2 ; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - continue; - } - //============== - } -} - static void Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, const bspx_header_t *bspx_header) @@ -447,8 +209,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, { int side, ti, planenum, lightofs; - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleLong(in->numedges); + out->firstedge = in->firstedge; + out->numedges = in->numedges; if (out->numedges < 3) { @@ -458,8 +220,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, out->flags = 0; out->polys = NULL; - planenum = LittleLong(in->planenum); - side = LittleLong(in->side); + planenum = in->planenum; + side = in->side; if (side) { @@ -602,22 +364,9 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) Mod_LoadTexinfo(mod->name, &mod->texinfo, &mod->numtexinfo, mod_base, &header->lumps[LUMP_TEXINFO], (findimage_t)R_FindImage, r_notexture_mip, maptype); - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if (maptype == map_sin) - { - Mod_LoadRFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - else - { - Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - } - else - { - Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } + + Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); + Mod_LoadQBSPMarksurfaces(mod->name, &mod->marksurfaces, &mod->nummarksurfaces, mod->surfaces, mod->numsurfaces, mod_base, &header->lumps[LUMP_LEAFFACES], header->ident); diff --git a/src/client/refresh/vk/vk_model.c b/src/client/refresh/vk/vk_model.c index 28e86ea7..b3a36a9b 100644 --- a/src/client/refresh/vk/vk_model.c +++ b/src/client/refresh/vk/vk_model.c @@ -134,15 +134,15 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l) for (j = 0; j < 3; j++) { /* spread the mins / maxs by a pixel */ - out->mins[j] = LittleFloat(in->mins[j]) - 1; - out->maxs[j] = LittleFloat(in->maxs[j]) + 1; - out->origin[j] = LittleFloat(in->origin[j]); + out->mins[j] = in->mins[j] - 1; + out->maxs[j] = in->maxs[j] + 1; + out->origin[j] = in->origin[j]; } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->firstnode = LittleLong(in->headnode); - out->firstmodelsurface = LittleLong(in->firstface); - out->nummodelsurfaces = LittleLong(in->numfaces); + out->firstnode = in->headnode; + out->firstmodelsurface = in->firstface; + out->nummodelsurfaces = in->numfaces; // visleafs out->numleafs = 0; // check limits @@ -154,236 +154,6 @@ Mod_LoadSubmodels(model_t *loadmodel, const byte *mod_base, const lump_t *l) } } -static void -Mod_LoadFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - dface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - -static void -Mod_LoadRFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, - const bspx_header_t *bspx_header) -{ - int i, count, surfnum, lminfosize; - const dlminfo_t *lminfos; - msurface_t *out; - drface_t *in; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - Com_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc((count + EXTRA_LUMP_FACES) * sizeof(*out)); - - loadmodel->surfaces = out; - loadmodel->numsurfaces = count; - - lminfos = Mod_LoadBSPXFindLump(bspx_header, "DECOUPLED_LM", &lminfosize, mod_base); - if ((lminfos != NULL) && - (lminfosize / sizeof(dlminfo_t) != loadmodel->numsurfaces)) - { - R_Printf(PRINT_ALL, "%s: [%s] decoupled_lm size " YQ2_COM_PRIdS " does not match surface count %d\n", - __func__, loadmodel->name, lminfosize / sizeof(dlminfo_t), loadmodel->numsurfaces); - lminfos = NULL; - } - - for (surfnum = 0; surfnum < count; surfnum++, in++, out++) - { - int side, ti, planenum, lightofs; - - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleShort(in->numedges); - - if (out->numedges < 3) - { - Com_Error(ERR_DROP, "%s: Surface with %d edges", - __func__, out->numedges); - } - out->flags = 0; - out->polys = NULL; - - planenum = LittleShort(in->planenum); - side = LittleShort(in->side); - - if (side) - { - out->flags |= SURF_PLANEBACK; - } - - if (planenum < 0 || planenum >= loadmodel->numplanes) - { - Com_Error(ERR_DROP, "%s: Incorrect %d planenum.", - __func__, planenum); - } - out->plane = loadmodel->planes + planenum; - - ti = LittleShort(in->texinfo); - - if ((ti < 0) || (ti >= loadmodel->numtexinfo)) - { - Com_Error(ERR_DROP, "%s: bad texinfo number", - __func__); - } - - out->texinfo = loadmodel->texinfo + ti; - - lightofs = Mod_LoadBSPXDecoupledLM(lminfos, surfnum, out); - if (lightofs < 0) { - memcpy(out->lmvecs, out->texinfo->vecs, sizeof(out->lmvecs)); - out->lmshift = DEFAULT_LMSHIFT; - out->lmvlen[0] = 1.0f; - out->lmvlen[1] = 1.0f; - - Mod_CalcSurfaceExtents(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); - - lightofs = in->lightofs; - } - - Mod_LoadSetSurfaceLighting(loadmodel->lightdata, loadmodel->numlightdata, - out, in->styles, lightofs); - - /* set the drawing flags */ - if (out->texinfo->flags & SURF_WARP) - { - out->flags |= SURF_DRAWTURB; - - for (i = 0; i < 2; i++) - { - out->extents[i] = 16384; - out->texturemins[i] = -8192; - } - - R_SubdivideSurface(loadmodel->surfedges, loadmodel->vertexes, - loadmodel->edges, out); /* cut up polygon for warps */ - } - - if (r_fixsurfsky->value) - { - if (out->texinfo->flags & SURF_SKY) - { - out->flags |= SURF_DRAWSKY; - } - } - - LM_CreateLightmapsPoligon(loadmodel, out); - } -} - static void Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, const bspx_header_t *bspx_header) @@ -420,8 +190,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, { int side, ti, planenum, lightofs; - out->firstedge = LittleLong(in->firstedge); - out->numedges = LittleLong(in->numedges); + out->firstedge = in->firstedge; + out->numedges = in->numedges; if (out->numedges < 3) { @@ -431,8 +201,8 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, out->flags = 0; out->polys = NULL; - planenum = LittleLong(in->planenum); - side = LittleLong(in->side); + planenum = in->planenum; + side = in->side; if (side) { @@ -563,24 +333,7 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) r_notexture, maptype); LM_BeginBuildingLightmaps(mod); - - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if (maptype == map_sin) - { - Mod_LoadRFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - else - { - Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - } - else - { - Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); - } - + Mod_LoadQFaces(mod, mod_base, &header->lumps[LUMP_FACES], bspx_header); LM_EndBuildingLightmaps(); Mod_LoadQBSPMarksurfaces(mod->name, &mod->marksurfaces, &mod->nummarksurfaces, diff --git a/src/common/cmodels.c b/src/common/cmodels.c index e6e7db82..2cfad292 100644 --- a/src/common/cmodels.c +++ b/src/common/cmodels.c @@ -1127,12 +1127,24 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len, if (xofs + sizeof(bspx_header_t) < filesize) { - result_size += (filesize - xofs); + bspx_header_t* xheader; + + xheader = (bspx_header_t*)(inbuf + xofs); + if (LittleLong(xheader->ident) == BSPXHEADER) + { + result_size += (filesize - xofs); + result_size += 4; + } + else + { + /* Have some other data at the end of file, just skip it */ + xofs = filesize; + } } - result_size += 4; outbuf = malloc(result_size); outheader = (dheader_t*)outbuf; + memset(outheader, 0, sizeof(dheader_t)); outheader->ident = QBSPHEADER; outheader->version = BSPVERSION; int ofs = sizeof(dheader_t); diff --git a/src/server/sv_send.c b/src/server/sv_send.c index 7a3b4ef5..acd68bd9 100644 --- a/src/server/sv_send.c +++ b/src/server/sv_send.c @@ -370,7 +370,7 @@ SV_StartSound(vec3_t origin, edict_t *entity, int channel, int soundindex, MSG_WriteByte(&sv.multicast, svc_sound); MSG_WriteByte(&sv.multicast, flags); - if (IS_QII97_PROTOCOL(sv_client->protocol)) + if (sv_client && IS_QII97_PROTOCOL(sv_client->protocol)) { MSG_WriteByte(&sv.multicast, soundindex); }