mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-01-31 05:10:33 +00:00
maps: share Vis decode code
This commit is contained in:
parent
726e4616db
commit
1ca588ef5e
12 changed files with 99 additions and 170 deletions
|
@ -659,7 +659,6 @@ set(GL1-Source
|
|||
${REF_SRC_DIR}/files/surf.c
|
||||
${REF_SRC_DIR}/files/wal.c
|
||||
${REF_SRC_DIR}/files/warp.c
|
||||
${REF_SRC_DIR}/files/pvs.c
|
||||
${COMMON_SRC_DIR}/shared/utils.c
|
||||
${COMMON_SRC_DIR}/shared/shared.c
|
||||
${COMMON_SRC_DIR}/cmodels.c
|
||||
|
@ -710,7 +709,6 @@ set(GL3-Source
|
|||
${REF_SRC_DIR}/files/surf.c
|
||||
${REF_SRC_DIR}/files/wal.c
|
||||
${REF_SRC_DIR}/files/warp.c
|
||||
${REF_SRC_DIR}/files/pvs.c
|
||||
${COMMON_SRC_DIR}/shared/utils.c
|
||||
${COMMON_SRC_DIR}/shared/shared.c
|
||||
${COMMON_SRC_DIR}/cmodels.c
|
||||
|
@ -767,7 +765,6 @@ set(GL4-Source
|
|||
${REF_SRC_DIR}/files/surf.c
|
||||
${REF_SRC_DIR}/files/wal.c
|
||||
${REF_SRC_DIR}/files/warp.c
|
||||
${REF_SRC_DIR}/files/pvs.c
|
||||
${COMMON_SRC_DIR}/shared/utils.c
|
||||
${COMMON_SRC_DIR}/shared/shared.c
|
||||
${COMMON_SRC_DIR}/cmodels.c
|
||||
|
@ -823,7 +820,6 @@ set(SOFT-Source
|
|||
${REF_SRC_DIR}/files/surf.c
|
||||
${REF_SRC_DIR}/files/wal.c
|
||||
${REF_SRC_DIR}/files/warp.c
|
||||
${REF_SRC_DIR}/files/pvs.c
|
||||
${COMMON_SRC_DIR}/shared/utils.c
|
||||
${COMMON_SRC_DIR}/shared/shared.c
|
||||
${COMMON_SRC_DIR}/cmodels.c
|
||||
|
@ -870,7 +866,6 @@ set(VK-Source
|
|||
${REF_SRC_DIR}/files/surf.c
|
||||
${REF_SRC_DIR}/files/wal.c
|
||||
${REF_SRC_DIR}/files/warp.c
|
||||
${REF_SRC_DIR}/files/pvs.c
|
||||
${COMMON_SRC_DIR}/shared/utils.c
|
||||
${COMMON_SRC_DIR}/shared/shared.c
|
||||
${COMMON_SRC_DIR}/cmodels.c
|
||||
|
|
5
Makefile
5
Makefile
|
@ -1164,7 +1164,6 @@ REFGL1_OBJS_ := \
|
|||
src/client/refresh/files/stb.o \
|
||||
src/client/refresh/files/wal.o \
|
||||
src/client/refresh/files/warp.o \
|
||||
src/client/refresh/files/pvs.o \
|
||||
src/common/shared/shared.o \
|
||||
src/common/shared/utils.o \
|
||||
src/common/cmodels.o \
|
||||
|
@ -1207,7 +1206,6 @@ REFGL3_OBJS_ := \
|
|||
src/client/refresh/files/stb.o \
|
||||
src/client/refresh/files/wal.o \
|
||||
src/client/refresh/files/warp.o \
|
||||
src/client/refresh/files/pvs.o \
|
||||
src/common/shared/shared.o \
|
||||
src/common/shared/utils.o \
|
||||
src/common/cmodels.o \
|
||||
|
@ -1253,7 +1251,6 @@ REFGL4_OBJS_ := \
|
|||
src/client/refresh/files/stb.o \
|
||||
src/client/refresh/files/wal.o \
|
||||
src/client/refresh/files/warp.o \
|
||||
src/client/refresh/files/pvs.o \
|
||||
src/common/shared/shared.o \
|
||||
src/common/cmodels.o \
|
||||
src/common/md4.o
|
||||
|
@ -1300,7 +1297,6 @@ REFSOFT_OBJS_ := \
|
|||
src/client/refresh/files/stb.o \
|
||||
src/client/refresh/files/wal.o \
|
||||
src/client/refresh/files/warp.o \
|
||||
src/client/refresh/files/pvs.o \
|
||||
src/common/shared/shared.o \
|
||||
src/common/shared/utils.o \
|
||||
src/common/cmodels.o \
|
||||
|
@ -1347,7 +1343,6 @@ REFVK_OBJS_ := \
|
|||
src/client/refresh/files/stb.o \
|
||||
src/client/refresh/files/wal.o \
|
||||
src/client/refresh/files/warp.o \
|
||||
src/client/refresh/files/pvs.o \
|
||||
src/common/shared/shared.o \
|
||||
src/common/shared/utils.o \
|
||||
src/common/cmodels.o \
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 1997-2001 Id Software, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* The PVS Decompress
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include "../ref_shared.h"
|
||||
|
||||
|
||||
/*
|
||||
===================
|
||||
Mod_DecompressVis
|
||||
===================
|
||||
*/
|
||||
const byte *
|
||||
Mod_DecompressVis(const byte *in, const byte* numvisibility, int row)
|
||||
{
|
||||
YQ2_ALIGNAS_TYPE(int) static byte decompressed[MAX_MAP_LEAFS / 8];
|
||||
int c;
|
||||
byte *out;
|
||||
|
||||
out = decompressed;
|
||||
|
||||
if (!in && !numvisibility)
|
||||
{
|
||||
/* no vis info, so make all visible */
|
||||
while (row)
|
||||
{
|
||||
*out++ = 0xff;
|
||||
row--;
|
||||
}
|
||||
|
||||
return decompressed;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (*in && (in + 2) < numvisibility)
|
||||
{
|
||||
*out++ = *in++;
|
||||
continue;
|
||||
}
|
||||
|
||||
c = in[1];
|
||||
in += 2;
|
||||
|
||||
while (c)
|
||||
{
|
||||
*out++ = 0;
|
||||
c--;
|
||||
}
|
||||
}
|
||||
while (out - decompressed < row);
|
||||
|
||||
return decompressed;
|
||||
}
|
||||
|
||||
float
|
||||
Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs)
|
||||
{
|
||||
int i;
|
||||
vec3_t corner;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
|
||||
}
|
||||
|
||||
return VectorLength(corner);
|
||||
}
|
|
@ -67,7 +67,8 @@ Mod_ClusterPVS(int cluster, const model_t *model)
|
|||
{
|
||||
if (!model->vis)
|
||||
{
|
||||
memset(mod_novis, 0xFF, sizeof(mod_novis));
|
||||
Mod_DecompressVis(NULL, mod_novis, NULL,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
|
@ -82,10 +83,11 @@ Mod_ClusterPVS(int cluster, const model_t *model)
|
|||
Com_Error(ERR_DROP, "%s: bad cluster", __func__);
|
||||
}
|
||||
|
||||
return Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS],
|
||||
Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS], mod_novis,
|
||||
(byte *)model->vis + model->numvisibility,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -68,7 +68,8 @@ GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model)
|
|||
{
|
||||
if (!model->vis)
|
||||
{
|
||||
memset(mod_novis, 0xFF, sizeof(mod_novis));
|
||||
Mod_DecompressVis(NULL, mod_novis, NULL,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
|
@ -83,10 +84,11 @@ GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model)
|
|||
Com_Error(ERR_DROP, "%s: bad cluster", __func__);
|
||||
}
|
||||
|
||||
return Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS],
|
||||
Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS], mod_novis,
|
||||
(byte *)model->vis + model->numvisibility,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -68,7 +68,8 @@ GL4_Mod_ClusterPVS(int cluster, const gl4model_t *model)
|
|||
{
|
||||
if (!model->vis)
|
||||
{
|
||||
memset(mod_novis, 0xFF, sizeof(mod_novis));
|
||||
Mod_DecompressVis(NULL, mod_novis, NULL,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
|
@ -83,10 +84,11 @@ GL4_Mod_ClusterPVS(int cluster, const gl4model_t *model)
|
|||
Com_Error(ERR_DROP, "%s: bad cluster", __func__);
|
||||
}
|
||||
|
||||
return Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS],
|
||||
Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS], mod_novis,
|
||||
(byte *)model->vis + model->numvisibility,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -110,10 +110,6 @@ extern void SmoothColorImage(unsigned *dst, size_t size, size_t rstep);
|
|||
extern void scale2x(const byte *src, byte *dst, int width, int height);
|
||||
extern void scale3x(const byte *src, byte *dst, int width, int height);
|
||||
|
||||
extern float Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs);
|
||||
extern const byte* Mod_DecompressVis(const byte *in, const byte* numvisibility,
|
||||
int row);
|
||||
|
||||
/* Shared models struct */
|
||||
|
||||
enum {
|
||||
|
|
|
@ -71,7 +71,8 @@ Mod_ClusterPVS(int cluster, const model_t *model)
|
|||
{
|
||||
if (!model->vis)
|
||||
{
|
||||
memset(mod_novis, 0xFF, sizeof(mod_novis));
|
||||
Mod_DecompressVis(NULL, mod_novis, NULL,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
|
@ -86,10 +87,11 @@ Mod_ClusterPVS(int cluster, const model_t *model)
|
|||
Com_Error(ERR_DROP, "%s: bad cluster", __func__);
|
||||
}
|
||||
|
||||
return Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS],
|
||||
Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS], mod_novis,
|
||||
(byte *)model->vis + model->numvisibility,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -41,7 +41,8 @@ Mod_ClusterPVS(int cluster, const model_t *model)
|
|||
{
|
||||
if (!model->vis)
|
||||
{
|
||||
memset(mod_novis, 0xFF, sizeof(mod_novis));
|
||||
Mod_DecompressVis(NULL, mod_novis, NULL,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
|
@ -56,10 +57,11 @@ Mod_ClusterPVS(int cluster, const model_t *model)
|
|||
Com_Error(ERR_DROP, "%s: bad cluster", __func__);
|
||||
}
|
||||
|
||||
return Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS],
|
||||
Mod_DecompressVis((byte *)model->vis +
|
||||
model->vis->bitofs[cluster][DVIS_PVS], mod_novis,
|
||||
(byte *)model->vis + model->numvisibility,
|
||||
(model->vis->numclusters + 7) >> 3);
|
||||
return mod_novis;
|
||||
}
|
||||
|
||||
//===============================================================================
|
||||
|
|
|
@ -144,3 +144,69 @@ Mod_LoadPlanes(const char *name, cplane_t **planes, int *numplanes,
|
|||
out->signbits = bits;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Mod_DecompressVis
|
||||
===================
|
||||
*/
|
||||
void
|
||||
Mod_DecompressVis(const byte *in, byte *out, const byte* numvisibility, int row)
|
||||
{
|
||||
byte *out_p;
|
||||
|
||||
out_p = out;
|
||||
|
||||
if (!in || !numvisibility)
|
||||
{
|
||||
/* no vis info, so make all visible */
|
||||
while (row)
|
||||
{
|
||||
*out_p++ = 0xff;
|
||||
row--;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
int c;
|
||||
|
||||
if (*in && (in + 2) < numvisibility)
|
||||
{
|
||||
*out_p++ = *in++;
|
||||
continue;
|
||||
}
|
||||
|
||||
c = in[1];
|
||||
in += 2;
|
||||
|
||||
if ((out_p - out) + c > row)
|
||||
{
|
||||
c = row - (out_p - out);
|
||||
Com_DPrintf("%s: warning: Vis decompression overrun\n", __func__);
|
||||
}
|
||||
|
||||
while (c)
|
||||
{
|
||||
*out_p++ = 0;
|
||||
c--;
|
||||
}
|
||||
}
|
||||
while (out_p - out < row);
|
||||
}
|
||||
|
||||
float
|
||||
Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs)
|
||||
{
|
||||
int i;
|
||||
vec3_t corner;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
|
||||
}
|
||||
|
||||
return VectorLength(corner);
|
||||
}
|
||||
|
|
|
@ -2061,60 +2061,12 @@ CM_MapSurfaces(int surfnum)
|
|||
return cmod->map_surfaces + surfnum;
|
||||
}
|
||||
|
||||
static void
|
||||
CM_DecompressVis(byte *in, byte *out)
|
||||
{
|
||||
int c;
|
||||
byte *out_p;
|
||||
int row;
|
||||
|
||||
row = (cmod->numclusters + 7) >> 3;
|
||||
out_p = out;
|
||||
|
||||
if (!in || !cmod->numvisibility)
|
||||
{
|
||||
/* no vis info, so make all visible */
|
||||
while (row)
|
||||
{
|
||||
*out_p++ = 0xff;
|
||||
row--;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (*in)
|
||||
{
|
||||
*out_p++ = *in++;
|
||||
continue;
|
||||
}
|
||||
|
||||
c = in[1];
|
||||
in += 2;
|
||||
|
||||
if ((out_p - out) + c > row)
|
||||
{
|
||||
c = row - (out_p - out);
|
||||
Com_DPrintf("warning: Vis decompression overrun\n");
|
||||
}
|
||||
|
||||
while (c)
|
||||
{
|
||||
*out_p++ = 0;
|
||||
c--;
|
||||
}
|
||||
}
|
||||
while (out_p - out < row);
|
||||
}
|
||||
|
||||
static byte *
|
||||
CM_Cluster(int cluster, int type, byte *buffer)
|
||||
{
|
||||
if (!cmod->map_vis)
|
||||
{
|
||||
memset(buffer, 0xFF, (cmod->numclusters + 7) >> 3);
|
||||
Mod_DecompressVis(NULL, buffer, NULL, (cmod->numclusters + 7) >> 3);
|
||||
}
|
||||
else if (cluster == -1)
|
||||
{
|
||||
|
@ -2127,8 +2079,10 @@ CM_Cluster(int cluster, int type, byte *buffer)
|
|||
Com_Error(ERR_DROP, "%s: bad cluster", __func__);
|
||||
}
|
||||
|
||||
CM_DecompressVis((byte *)cmod->map_vis +
|
||||
cmod->map_vis->bitofs[cluster][type], buffer);
|
||||
Mod_DecompressVis((byte *)cmod->map_vis +
|
||||
cmod->map_vis->bitofs[cluster][type], buffer,
|
||||
(byte *)cmod->map_vis + cmod->numvisibility,
|
||||
(cmod->numclusters + 7) >> 3);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
|
|
@ -57,5 +57,8 @@ extern void Mod_LoadPlanes(const char *name, cplane_t **planes, int *numplanes,
|
|||
const byte *mod_base, const lump_t *l);
|
||||
extern byte *Mod_Load2QBSP(const char *name, byte *in, size_t filesize,
|
||||
size_t *out_len, maptype_t *maptype);
|
||||
extern float Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs);
|
||||
extern void Mod_DecompressVis(const byte *in, byte *out, const byte* numvisibility,
|
||||
int row);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue