Merge pull request #932 from 0lvin/shared_models_logic

Shared models logic
This commit is contained in:
Yamagi 2023-01-21 18:07:54 +01:00 committed by GitHub
commit 2e939b10e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 988 additions and 1741 deletions

View file

@ -927,6 +927,7 @@ REFGL1_OBJS_ := \
src/client/refresh/gl1/gl1_surf.o \
src/client/refresh/gl1/gl1_warp.o \
src/client/refresh/gl1/gl1_sdl.o \
src/client/refresh/files/surf.o \
src/client/refresh/files/models.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/stb.o \
@ -958,6 +959,7 @@ REFGL3_OBJS_ := \
src/client/refresh/gl3/gl3_surf.o \
src/client/refresh/gl3/gl3_warp.o \
src/client/refresh/gl3/gl3_shaders.o \
src/client/refresh/files/surf.o \
src/client/refresh/files/models.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/stb.o \
@ -1000,6 +1002,7 @@ REFSOFT_OBJS_ := \
src/client/refresh/soft/sw_scan.o \
src/client/refresh/soft/sw_sprite.o \
src/client/refresh/soft/sw_surf.o \
src/client/refresh/files/surf.o \
src/client/refresh/files/models.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/stb.o \

View file

@ -292,6 +292,501 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata,
skins[i] = find_image ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
return pheader->num_frames;
}
// Unknow format, no images associated with it
/* Unknow format, no images associated with it */
return 0;
}
/*
=================
Mod_SetParent
=================
*/
static void
Mod_SetParent(mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != CONTENTS_NODE)
{
return;
}
Mod_SetParent (node->children[0], node);
Mod_SetParent (node->children[1], node);
}
/*
=================
Mod_NumberLeafs
=================
*/
static void
Mod_NumberLeafs(mleaf_t *leafs, mnode_t *node, int *r_leaftovis, int *r_vistoleaf,
int *numvisleafs)
{
if (node->contents != CONTENTS_NODE)
{
mleaf_t *leaf;
int leafnum;
leaf = (mleaf_t *)node;
leafnum = leaf - leafs;
if (leaf->contents & CONTENTS_SOLID)
{
return;
}
r_leaftovis[leafnum] = *numvisleafs;
r_vistoleaf[*numvisleafs] = leafnum;
(*numvisleafs) ++;
return;
}
Mod_NumberLeafs(leafs, node->children[0], r_leaftovis, r_vistoleaf,
numvisleafs);
Mod_NumberLeafs(leafs, node->children[1], r_leaftovis, r_vistoleaf,
numvisleafs);
}
/*
=================
Mod_LoadNodes
=================
*/
void
Mod_LoadNodes(const char *name, cplane_t *planes, int numplanes, mleaf_t *leafs,
int numleafs, mnode_t **nodes, int *numnodes, const byte *mod_base,
const lump_t *l)
{
int r_leaftovis[MAX_MAP_LEAFS], r_vistoleaf[MAX_MAP_LEAFS];
int i, count, numvisleafs;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
*nodes = out;
*numnodes = count;
for (i = 0; i < count; i++, in++, out++)
{
int j, planenum;
for (j = 0; j < 3; j++)
{
out->minmaxs[j] = LittleShort(in->mins[j]);
out->minmaxs[3 + j] = LittleShort(in->maxs[j]);
}
planenum = LittleLong(in->planenum);
if (planenum < 0 || planenum >= numplanes)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d < %d planenum.",
__func__, planenum, numplanes);
}
out->plane = planes + planenum;
out->firstsurface = LittleShort(in->firstface);
out->numsurfaces = LittleShort(in->numfaces);
out->contents = CONTENTS_NODE; /* differentiate from leafs */
for (j = 0; j < 2; j++)
{
int leafnum;
leafnum = LittleLong(in->children[j]);
if (leafnum >= 0)
{
if (leafnum < 0 || leafnum >= *numnodes)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d nodenum as leaf.",
__func__, leafnum);
}
out->children[j] = *nodes + leafnum;
}
else
{
leafnum = -1 - leafnum;
if (leafnum < 0 || leafnum >= numleafs)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d leafnum.",
__func__, leafnum);
}
out->children[j] = (mnode_t *)(leafs + leafnum);
}
}
}
Mod_SetParent(*nodes, NULL); /* sets nodes and leafs */
numvisleafs = 0;
Mod_NumberLeafs (leafs, *nodes, r_leaftovis, r_vistoleaf, &numvisleafs);
}
/*
=================
Mod_LoadVisibility
=================
*/
void
Mod_LoadVisibility (dvis_t **vis, const byte *mod_base, const lump_t *l)
{
dvis_t *out;
int i;
if (!l->filelen)
{
*vis = NULL;
return;
}
out = Hunk_Alloc(l->filelen);
*vis = out;
memcpy(out, mod_base + l->fileofs, l->filelen);
out->numclusters = LittleLong(out->numclusters);
for (i = 0; i < out->numclusters; i++)
{
out->bitofs[i][0] = LittleLong(out->bitofs[i][0]);
out->bitofs[i][1] = LittleLong(out->bitofs[i][1]);
}
}
/*
=================
Mod_LoadVertexes
extra for skybox
=================
*/
void
Mod_LoadVertexes(const char *name, mvertex_t **vertexes, int *numvertexes,
const byte *mod_base, const lump_t *l, int extra)
{
dvertex_t *in;
mvertex_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count + extra)*sizeof(*out));
/*
* FIXME: Recheck with soft render
* Fix for the problem where the games dumped core
* when changing levels.
*/
memset(out, 0, (count + extra) * sizeof(*out));
*vertexes = out;
*numvertexes = count;
for (i = 0; i < count; i++, in++, out++)
{
out->position[0] = LittleFloat(in->point[0]);
out->position[1] = LittleFloat(in->point[1]);
out->position[2] = LittleFloat(in->point[2]);
}
}
/*
=================
Mod_LoadLighting
=================
*/
void
Mod_LoadLighting(byte **lightdata, const byte *mod_base, const lump_t *l)
{
int size;
if (!l->filelen)
{
*lightdata = NULL;
return;
}
size = l->filelen;
*lightdata = Hunk_Alloc(size);
memcpy(*lightdata, mod_base + l->fileofs, size);
}
/*
=================
Mod_LoadTexinfo
extra for skybox in soft render
=================
*/
void
Mod_LoadTexinfo(const char *name, mtexinfo_t **texinfo, int *numtexinfo,
const byte *mod_base, const lump_t *l, findimage_t find_image,
struct image_s *notexture, int extra)
{
texinfo_t *in;
mtexinfo_t *out, *step;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count + extra)*sizeof(*out));
*texinfo = out;
*numtexinfo = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
struct image_s *image;
int j, next;
for (j = 0; j < 4; j++)
{
out->vecs[0][j] = LittleFloat(in->vecs[0][j]);
out->vecs[1][j] = LittleFloat(in->vecs[1][j]);
}
out->flags = LittleLong (in->flags);
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;
}
// count animation frames
for (i=0 ; i<count ; i++)
{
out = (*texinfo) + i;
out->numframes = 1;
for (step = out->next ; step && step != out ; step=step->next)
{
out->numframes++;
}
}
}
/*
=================
Mod_LoadEdges
extra is used for skybox, which adds 6 surfaces
=================
*/
void
Mod_LoadEdges(const char *name, medge_t **edges, int *numedges,
const byte *mod_base, const lump_t *l, int extra)
{
dedge_t *in;
medge_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count + extra) * sizeof(*out));
*edges = out;
*numedges = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
out->v[0] = (unsigned short)LittleShort(in->v[0]);
out->v[1] = (unsigned short)LittleShort(in->v[1]);
}
}
/*
=================
Mod_LoadPlanes
extra is used for skybox, which adds 6 surfaces
=================
*/
void
Mod_LoadPlanes(const char *name, cplane_t **planes, int *numplanes,
const byte *mod_base, const lump_t *l, int extra)
{
int i;
cplane_t *out;
dplane_t *in;
int count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, name);
}
count = l->filelen / sizeof(*in);
// FIXME: why double of count
out = Hunk_Alloc((count * 2 + extra) * sizeof(*out));
*planes = out;
*numplanes = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
int bits, j;
bits = 0;
for (j=0 ; j<3 ; j++)
{
out->normal[j] = LittleFloat (in->normal[j]);
if (out->normal[j] < 0)
bits |= 1<<j;
}
out->dist = LittleFloat (in->dist);
out->type = LittleLong (in->type);
out->signbits = bits;
}
}
/*
=================
Mod_LoadSurfedges
=================
*/
void
Mod_LoadSurfedges(const char *name, int **surfedges, int *numsurfedges,
const byte *mod_base, const lump_t *l, int extra)
{
int i, count;
int *in, *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count + extra)*sizeof(*out)); // extra for skybox
*surfedges = out;
*numsurfedges = count;
for ( i=0 ; i<count ; i++)
out[i] = LittleLong (in[i]);
}
/*
=================
Mod_LoadSurfedges
calculate the size that Hunk_Alloc(), called by Mod_Load*() from Mod_LoadBrushModel(),
will use (=> includes its padding), so we'll know how big the hunk needs to be
extra is used for skybox, which adds 6 surfaces
=================
*/
int
Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra)
{
if (l->filelen % inSize)
{
// Mod_Load*() will error out on this because of "funny size"
// don't error out here because in Mod_Load*() it can print the functionname
// (=> tells us what kind of lump) before shutting down the game
return 0;
}
int count = l->filelen / inSize + extra;
int size = count * outSize;
// round to cacheline, like Hunk_Alloc() does
size = (size + 31) & ~31;
return size;
}
/*
===============
Mod_PointInLeaf
===============
*/
mleaf_t *
Mod_PointInLeaf(const vec3_t p, mnode_t *node)
{
if (!node)
{
ri.Sys_Error(ERR_DROP, "%s: bad node.", __func__);
return NULL;
}
while (1)
{
float d;
cplane_t *plane;
if (node->contents != CONTENTS_NODE)
{
return (mleaf_t *)node;
}
plane = node->plane;
d = DotProduct(p, plane->normal) - plane->dist;
if (d > 0)
{
node = node->children[0];
}
else
{
node = node->children[1];
}
}
return NULL; /* never reached */
}

View file

@ -0,0 +1,183 @@
/*
* 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.
*
* =======================================================================
*
* Surface logic
*
* =======================================================================
*/
#include "../ref_shared.h"
/*
===============
R_TextureAnimation
Returns the proper texture for a given time and base texture
===============
*/
struct image_s *
R_TextureAnimation(const entity_t *currententity, const mtexinfo_t *tex)
{
int c;
if (!tex->next)
return tex->image;
if (!currententity)
return tex->image;
c = currententity->frame % tex->numframes;
while (c && tex)
{
tex = tex->next;
c--;
}
return tex->image;
}
qboolean
R_AreaVisible(const byte *areabits, mleaf_t *pleaf)
{
int area;
// check for door connected areas
if (!areabits)
return true;
area = pleaf->area;
if ((areabits[area >> 3] & (1 << (area & 7))))
return true;
return false; // not visible
}
/*
=============
R_MarkLights
bit: 1 << i for light number i, will be or'ed into msurface_t::dlightbits
if surface is affected by this light
=============
*/
void
R_MarkLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount,
marksurfacelights_t mark_surface_lights)
{
cplane_t *splitplane;
float dist;
int intensity;
if (node->contents != CONTENTS_NODE)
return;
splitplane = node->plane;
dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
intensity = light->intensity;
if (dist > intensity - DLIGHT_CUTOFF) // (dist > light->intensity)
{
R_MarkLights (light, bit, node->children[0], r_dlightframecount,
mark_surface_lights);
return;
}
if (dist < -intensity + DLIGHT_CUTOFF) // (dist < -light->intensity)
{
R_MarkLights(light, bit, node->children[1], r_dlightframecount,
mark_surface_lights);
return;
}
mark_surface_lights(light, bit, node, r_dlightframecount);
R_MarkLights(light, bit, node->children[0], r_dlightframecount,
mark_surface_lights);
R_MarkLights(light, bit, node->children[1], r_dlightframecount,
mark_surface_lights);
}
/*
* Returns true if the box is completely outside the frustom
*/
qboolean
R_CullBox(vec3_t mins, vec3_t maxs, cplane_t *frustum)
{
int i;
for (i = 0; i < 4; i++)
{
if (BOX_ON_PLANE_SIDE(mins, maxs, frustum + i) == 2)
{
return true;
}
}
return false;
}
static int
R_SignbitsForPlane(cplane_t *out)
{
int bits, j;
/* for fast box on planeside test */
bits = 0;
for (j = 0; j < 3; j++)
{
if (out->normal[j] < 0)
{
bits |= 1 << j;
}
}
return bits;
}
void
R_SetFrustum(vec3_t vup, vec3_t vpn, vec3_t vright, vec3_t r_origin,
float fov_x, float fov_y, cplane_t *frustum)
{
int i;
/* rotate VPN right by FOV_X/2 degrees */
RotatePointAroundVector(frustum[0].normal, vup, vpn,
-(90 - fov_x / 2));
/* rotate VPN left by FOV_X/2 degrees */
RotatePointAroundVector(frustum[1].normal,
vup, vpn, 90 - fov_x / 2);
/* rotate VPN up by FOV_X/2 degrees */
RotatePointAroundVector(frustum[2].normal,
vright, vpn, 90 - fov_y / 2);
/* rotate VPN down by FOV_X/2 degrees */
RotatePointAroundVector(frustum[3].normal, vright, vpn,
-(90 - fov_y / 2));
for (i = 0; i < 4; i++)
{
frustum[i].type = PLANE_ANYZ;
frustum[i].dist = DotProduct(r_origin, frustum[i].normal);
frustum[i].signbits = R_SignbitsForPlane(&frustum[i]);
}
}

View file

@ -154,7 +154,7 @@ LoadM32(const char *origname, imagetype_t type, loadimage_t load_image)
return NULL;
}
if (size < sizeof(m8tex_t))
if (size < sizeof(m32tex_t))
{
R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name);
ri.FS_FreeFile((void *)mt);

View file

@ -26,8 +26,6 @@
#include "header/local.h"
#define DLIGHT_CUTOFF 64
int r_dlightframecount;
vec3_t pointcolor;
cplane_t *lightplane; /* used as shadow plane */
@ -121,39 +119,19 @@ R_RenderDlights(void)
}
void
R_MarkLights(dlight_t *light, int bit, mnode_t *node)
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
cplane_t *splitplane;
float dist;
msurface_t *surf;
int i;
int sidebit;
if (node->contents != -1)
{
return;
}
splitplane = node->plane;
dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
if (dist > light->intensity - DLIGHT_CUTOFF)
{
R_MarkLights(light, bit, node->children[0]);
return;
}
if (dist < -light->intensity + DLIGHT_CUTOFF)
{
R_MarkLights(light, bit, node->children[1]);
return;
}
msurface_t *surf;
int i;
/* mark the polygons */
surf = r_worldmodel->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
int sidebit;
float dist;
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
@ -178,9 +156,6 @@ R_MarkLights(dlight_t *light, int bit, mnode_t *node)
surf->dlightbits |= bit;
}
R_MarkLights(light, bit, node->children[0]);
R_MarkLights(light, bit, node->children[1]);
}
void
@ -201,7 +176,8 @@ R_PushDlights(void)
for (i = 0; i < r_newrefdef.num_dlights; i++, l++)
{
R_MarkLights(l, 1 << i, r_worldmodel->nodes);
R_MarkLights(l, 1 << i, r_worldmodel->nodes, r_dlightframecount,
R_MarkSurfaceLights);
}
}
@ -220,7 +196,7 @@ R_RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
int maps;
int r;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return -1; /* didn't hit anything */
}

View file

@ -120,7 +120,7 @@ cvar_t *gl1_ztrick;
cvar_t *gl_zfix;
cvar_t *gl_finish;
cvar_t *r_clear;
cvar_t *gl_cull;
cvar_t *r_cull;
cvar_t *gl_polyblend;
cvar_t *gl1_flashblend;
cvar_t *gl1_saturatelighting;
@ -143,30 +143,6 @@ cvar_t *gl1_stereo_convergence;
refimport_t ri;
/*
* Returns true if the box is completely outside the frustom
*/
qboolean
R_CullBox(vec3_t mins, vec3_t maxs)
{
int i;
if (!gl_cull->value)
{
return false;
}
for (i = 0; i < 4; i++)
{
if (BOX_ON_PLANE_SIDE(mins, maxs, &frustum[i]) == 2)
{
return true;
}
}
return false;
}
void
R_RotateForEntity(entity_t *e)
{
@ -642,51 +618,6 @@ R_PolyBlend(void)
glColor4f(1, 1, 1, 1);
}
int
R_SignbitsForPlane(cplane_t *out)
{
int bits, j;
/* for fast box on planeside test */
bits = 0;
for (j = 0; j < 3; j++)
{
if (out->normal[j] < 0)
{
bits |= 1 << j;
}
}
return bits;
}
void
R_SetFrustum(void)
{
int i;
/* rotate VPN right by FOV_X/2 degrees */
RotatePointAroundVector(frustum[0].normal, vup, vpn,
-(90 - r_newrefdef.fov_x / 2));
/* rotate VPN left by FOV_X/2 degrees */
RotatePointAroundVector(frustum[1].normal,
vup, vpn, 90 - r_newrefdef.fov_x / 2);
/* rotate VPN up by FOV_X/2 degrees */
RotatePointAroundVector(frustum[2].normal,
vright, vpn, 90 - r_newrefdef.fov_y / 2);
/* rotate VPN down by FOV_X/2 degrees */
RotatePointAroundVector(frustum[3].normal, vright, vpn,
-(90 - r_newrefdef.fov_y / 2));
for (i = 0; i < 4; i++)
{
frustum[i].type = PLANE_ANYZ;
frustum[i].dist = DotProduct(r_origin, frustum[i].normal);
frustum[i].signbits = R_SignbitsForPlane(&frustum[i]);
}
}
void
R_SetupFrame(void)
{
@ -703,9 +634,15 @@ R_SetupFrame(void)
/* current viewcluster */
if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL))
{
if (!r_worldmodel)
{
ri.Sys_Error(ERR_DROP, "%s: bad world model", __func__);
return;
}
r_oldviewcluster = r_viewcluster;
r_oldviewcluster2 = r_viewcluster2;
leaf = Mod_PointInLeaf(r_origin, r_worldmodel);
leaf = Mod_PointInLeaf(r_origin, r_worldmodel->nodes);
r_viewcluster = r_viewcluster2 = leaf->cluster;
/* check above and below so crossing solid water doesn't draw wrong */
@ -716,7 +653,7 @@ R_SetupFrame(void)
VectorCopy(r_origin, temp);
temp[2] -= 16;
leaf = Mod_PointInLeaf(temp, r_worldmodel);
leaf = Mod_PointInLeaf(temp, r_worldmodel->nodes);
if (!(leaf->contents & CONTENTS_SOLID) &&
(leaf->cluster != r_viewcluster2))
@ -731,7 +668,7 @@ R_SetupFrame(void)
VectorCopy(r_origin, temp);
temp[2] += 16;
leaf = Mod_PointInLeaf(temp, r_worldmodel);
leaf = Mod_PointInLeaf(temp, r_worldmodel->nodes);
if (!(leaf->contents & CONTENTS_SOLID) &&
(leaf->cluster != r_viewcluster2))
@ -843,7 +780,7 @@ R_SetupGL(void)
glGetFloatv(GL_MODELVIEW_MATRIX, r_world_matrix);
/* set drawing parms */
if (gl_cull->value)
if (r_cull->value)
{
glEnable(GL_CULL_FACE);
}
@ -1114,7 +1051,8 @@ R_RenderView(refdef_t *fd)
R_SetupFrame();
R_SetFrustum();
R_SetFrustum(vup, vpn, vright, r_origin, r_newrefdef.fov_x, r_newrefdef.fov_y,
frustum);
R_SetupGL();
@ -1260,7 +1198,7 @@ R_Register(void)
gl_zfix = ri.Cvar_Get("gl_zfix", "0", 0);
gl_finish = ri.Cvar_Get("gl_finish", "0", CVAR_ARCHIVE);
r_clear = ri.Cvar_Get("r_clear", "0", 0);
gl_cull = ri.Cvar_Get("gl_cull", "1", 0);
r_cull = ri.Cvar_Get("r_cull", "1", 0);
gl_polyblend = ri.Cvar_Get("gl_polyblend", "1", 0);
gl1_flashblend = ri.Cvar_Get("gl1_flashblend", "0", 0);
r_fixsurfsky = ri.Cvar_Get("r_fixsurfsky", "0", CVAR_ARCHIVE);

View file

@ -70,43 +70,6 @@ Mod_HasFreeSpace(void)
return (mod_numknown + mod_max) < MAX_MOD_KNOWN;
}
mleaf_t *
Mod_PointInLeaf(vec3_t p, model_t *model)
{
mnode_t *node;
float d;
cplane_t *plane;
if (!model || !model->nodes)
{
ri.Sys_Error(ERR_DROP, "%s: bad model", __func__);
}
node = model->nodes;
while (1)
{
if (node->contents != -1)
{
return (mleaf_t *)node;
}
plane = node->plane;
d = DotProduct(p, plane->normal) - plane->dist;
if (d > 0)
{
node = node->children[0];
}
else
{
node = node->children[1];
}
}
return NULL; /* never reached */
}
const byte *
Mod_ClusterPVS(int cluster, const model_t *model)
{
@ -290,71 +253,6 @@ Mod_ForName (char *name, model_t *parent_model, qboolean crash)
return mod;
}
static void
Mod_LoadLighting(model_t *loadmodel, byte *mod_base, lump_t *l)
{
if (!l->filelen)
{
loadmodel->lightdata = NULL;
return;
}
loadmodel->lightdata = Hunk_Alloc(l->filelen);
memcpy(loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
}
static void
Mod_LoadVisibility(model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i;
if (!l->filelen)
{
loadmodel->vis = NULL;
return;
}
loadmodel->vis = Hunk_Alloc(l->filelen);
memcpy(loadmodel->vis, mod_base + l->fileofs, l->filelen);
loadmodel->vis->numclusters = LittleLong(loadmodel->vis->numclusters);
for (i = 0; i < loadmodel->vis->numclusters; i++)
{
loadmodel->vis->bitofs[i][0] = LittleLong(loadmodel->vis->bitofs[i][0]);
loadmodel->vis->bitofs[i][1] = LittleLong(loadmodel->vis->bitofs[i][1]);
}
}
static void
Mod_LoadVertexes(model_t *loadmodel, byte *mod_base, lump_t *l)
{
dvertex_t *in;
mvertex_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->vertexes = out;
loadmodel->numvertexes = count;
for (i = 0; i < count; i++, in++, out++)
{
out->position[0] = LittleFloat(in->point[0]);
out->position[1] = LittleFloat(in->point[1]);
out->position[2] = LittleFloat(in->point[2]);
}
}
static void
Mod_LoadSubmodels (model_t *loadmodel, byte *mod_base, lump_t *l)
{
@ -414,103 +312,6 @@ Mod_LoadSubmodels (model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
static void
Mod_LoadEdges(model_t *loadmodel, byte *mod_base, lump_t *l)
{
dedge_t *in;
medge_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count + 1) * sizeof(*out));
loadmodel->edges = out;
loadmodel->numedges = count;
for (i = 0; i < count; i++, in++, out++)
{
out->v[0] = (unsigned short)LittleShort(in->v[0]);
out->v[1] = (unsigned short)LittleShort(in->v[1]);
}
}
static void
Mod_LoadTexinfo(model_t *loadmodel, byte *mod_base, lump_t *l)
{
texinfo_t *in;
mtexinfo_t *out, *step;
int i, j, count;
int next;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->texinfo = out;
loadmodel->numtexinfo = count;
for (i = 0; i < count; i++, in++, out++)
{
image_t *image;
for (j = 0; j < 4; j++)
{
out->vecs[0][j] = LittleFloat(in->vecs[0][j]);
out->vecs[1][j] = LittleFloat(in->vecs[1][j]);
}
out->flags = LittleLong(in->flags);
next = LittleLong(in->nexttexinfo);
if (next > 0)
{
out->next = loadmodel->texinfo + next;
}
else
{
out->next = NULL;
}
image = GetTexImage(in->texture, (findimage_t)R_FindImage);
if (!image)
{
R_Printf(PRINT_ALL, "%s: Couldn't load %s\n",
__func__, in->texture);
image = r_notexture;
}
out->image = image;
}
/* count animation frames */
for (i = 0; i < count; i++)
{
out = &loadmodel->texinfo[i];
out->numframes = 1;
for (step = out->next; step && step != out; step = step->next)
{
out->numframes++;
}
}
}
/*
* Fills in s->texturemins[] and s->extents[]
*/
@ -685,6 +486,11 @@ Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l)
out->flags |= SURF_PLANEBACK;
}
if (planenum < 0 || planenum >= loadmodel->numplanes)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;
ti = LittleShort(in->texinfo);
@ -753,74 +559,6 @@ Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l)
LM_EndBuildingLightmaps();
}
static void
Mod_SetParent(mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != -1)
{
return;
}
Mod_SetParent(node->children[0], node);
Mod_SetParent(node->children[1], node);
}
static void
Mod_LoadNodes(model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, j, count, p;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->nodes = out;
loadmodel->numnodes = count;
for (i = 0; i < count; i++, in++, out++)
{
for (j = 0; j < 3; j++)
{
out->minmaxs[j] = LittleShort(in->mins[j]);
out->minmaxs[3 + j] = LittleShort(in->maxs[j]);
}
p = LittleLong(in->planenum);
out->plane = loadmodel->planes + p;
out->firstsurface = LittleShort(in->firstface);
out->numsurfaces = LittleShort(in->numfaces);
out->contents = -1; /* differentiate from leafs */
for (j = 0; j < 2; j++)
{
p = LittleLong(in->children[j]);
if (p >= 0)
{
out->children[j] = loadmodel->nodes + p;
}
else
{
out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
}
}
}
Mod_SetParent(loadmodel->nodes, NULL); /* sets nodes and leafs */
}
static void
Mod_LoadLeafs(model_t *loadmodel, byte *mod_base, lump_t *l)
{
@ -906,102 +644,6 @@ Mod_LoadMarksurfaces(model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
static void
Mod_LoadSurfedges(model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, count;
int *in, *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
if ((count < 1) || (count >= MAX_MAP_SURFEDGES))
{
ri.Sys_Error(ERR_DROP, "%s: bad surfedges count in %s: %i",
__func__, loadmodel->name, count);
}
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->surfedges = out;
loadmodel->numsurfedges = count;
for (i = 0; i < count; i++)
{
out[i] = LittleLong(in[i]);
}
}
static void
Mod_LoadPlanes(model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, j;
cplane_t *out;
dplane_t *in;
int count;
int bits;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * 2 * sizeof(*out));
loadmodel->planes = out;
loadmodel->numplanes = count;
for (i = 0; i < count; i++, in++, out++)
{
bits = 0;
for (j = 0; j < 3; j++)
{
out->normal[j] = LittleFloat(in->normal[j]);
if (out->normal[j] < 0)
{
bits |= 1 << j;
}
}
out->dist = LittleFloat(in->dist);
out->type = LittleLong(in->type);
out->signbits = bits;
}
}
// calculate the size that Hunk_Alloc(), called by Mod_Load*() from Mod_LoadBrushModel(),
// will use (=> includes its padding), so we'll know how big the hunk needs to be
static int calcLumpHunkSize(const lump_t *l, int inSize, int outSize)
{
if (l->filelen % inSize)
{
// Mod_Load*() will error out on this because of "funny size"
// don't error out here because in Mod_Load*() it can print the functionname
// (=> tells us what kind of lump) before shutting down the game
return 0;
}
int count = l->filelen / inSize;
int size = count * outSize;
// round to cacheline, like Hunk_Alloc() does
size = (size + 31) & ~31;
return size;
}
static void
Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
{
@ -1034,36 +676,44 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
// calculate the needed hunksize from the lumps
int hunkSize = 0;
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_EDGES], sizeof(dedge_t), sizeof(medge_t));
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_EDGES], sizeof(dedge_t), sizeof(medge_t), 0);
hunkSize += sizeof(medge_t) + 31; // for count+1 in Mod_LoadEdges()
int surfEdgeCount = (header->lumps[LUMP_SURFEDGES].filelen+sizeof(int)-1)/sizeof(int);
if(surfEdgeCount < MAX_MAP_SURFEDGES) // else it errors out later anyway
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LIGHTING], 1, 1);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t)*2);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LIGHTING], 1, 1, 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t)*2, 0);
hunkSize += calcTexinfoAndFacesSize(mod_base, &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *)); // yes, out is indeeed a pointer!
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFS], sizeof(dleaf_t), sizeof(mleaf_t));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_NODES], sizeof(dnode_t), sizeof(mnode_t));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(model_t));
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *), 0); // yes, out is indeeed a pointer!
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1, 0);
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), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(model_t), 0);
mod->extradata = Hunk_Begin(hunkSize);
mod->type = mod_brush;
/* load into heap */
Mod_LoadVertexes(mod, mod_base, &header->lumps[LUMP_VERTEXES]);
Mod_LoadEdges(mod, mod_base, &header->lumps[LUMP_EDGES]);
Mod_LoadSurfedges(mod, mod_base, &header->lumps[LUMP_SURFEDGES]);
Mod_LoadLighting(mod, mod_base, &header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes(mod, mod_base, &header->lumps[LUMP_PLANES]);
Mod_LoadTexinfo(mod, mod_base, &header->lumps[LUMP_TEXINFO]);
Mod_LoadVertexes(mod->name, &mod->vertexes, &mod->numvertexes, mod_base,
&header->lumps[LUMP_VERTEXES], 0);
Mod_LoadEdges(mod->name, &mod->edges, &mod->numedges,
mod_base, &header->lumps[LUMP_EDGES], 1);
Mod_LoadSurfedges(mod->name, &mod->surfedges, &mod->numsurfedges,
mod_base, &header->lumps[LUMP_SURFEDGES], 0);
Mod_LoadLighting(&mod->lightdata, mod_base, &header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes (mod->name, &mod->planes, &mod->numplanes,
mod_base, &header->lumps[LUMP_PLANES], 0);
Mod_LoadTexinfo(mod->name, &mod->texinfo, &mod->numtexinfo,
mod_base, &header->lumps[LUMP_TEXINFO], (findimage_t)R_FindImage,
r_notexture, 0);
Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES]);
Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadVisibility (&mod->vis, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]);
Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadNodes(mod->name, mod->planes, mod->numplanes, mod->leafs,
mod->numleafs, &mod->nodes, &mod->numnodes, mod_base,
&header->lumps[LUMP_NODES]);
Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]);
mod->numframes = 2; /* regular and alternate animation */
}

View file

@ -42,30 +42,6 @@ qboolean LM_AllocBlock(int w, int h, int *x, int *y);
void R_SetCacheState(msurface_t *surf);
void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
/*
* Returns the proper texture for a given time and base texture
*/
static image_t *
R_TextureAnimation(entity_t *currententity, mtexinfo_t *tex)
{
int c;
if (!tex->next)
{
return tex->image;
}
c = currententity->frame % tex->numframes;
while (c)
{
tex = tex->next;
c--;
}
return tex->image;
}
static void
R_DrawGLPoly(glpoly_t *p)
{
@ -122,7 +98,7 @@ R_DrawGLFlowingPoly(msurface_t *fa)
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
YQ2_VLAFREE(tex);
}
@ -674,7 +650,9 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel)
for (k = 0; k < r_newrefdef.num_dlights; k++, lt++)
{
R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode);
R_MarkLights(lt, 1 << k,
currentmodel->nodes + currentmodel->firstnode,
r_dlightframecount, R_MarkSurfaceLights);
}
}
@ -756,7 +734,7 @@ R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel)
VectorAdd(currententity->origin, currentmodel->maxs, maxs);
}
if (R_CullBox(mins, maxs))
if (r_cull->value && R_CullBox(mins, maxs, frustum))
{
return;
}
@ -831,24 +809,19 @@ R_RecursiveWorldNode(entity_t *currententity, mnode_t *node)
return;
}
if (R_CullBox(node->minmaxs, node->minmaxs + 3))
if (r_cull->value && R_CullBox(node->minmaxs, node->minmaxs + 3, frustum))
{
return;
}
/* if a leaf node, draw stuff */
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
pleaf = (mleaf_t *)node;
/* check for door connected areas */
if (r_newrefdef.areabits)
{
if (!(r_newrefdef.areabits[pleaf->area >> 3] & (1 << (pleaf->area & 7))))
{
return; /* not visible */
}
}
if (!R_AreaVisible(r_newrefdef.areabits, pleaf))
return; // not visible
mark = pleaf->firstmarksurface;
c = pleaf->nummarksurfaces;

View file

@ -213,7 +213,7 @@ extern cvar_t *gl_finish;
extern cvar_t *gl1_ztrick;
extern cvar_t *gl_zfix;
extern cvar_t *r_clear;
extern cvar_t *gl_cull;
extern cvar_t *r_cull;
extern cvar_t *gl1_polyblend;
extern cvar_t *gl1_flashblend;
extern cvar_t *r_modulate;
@ -267,16 +267,17 @@ void R_DrawAlphaSurfaces(void);
void R_InitParticleTexture(void);
void Draw_InitLocal(void);
void R_SubdivideSurface(model_t *loadmodel, msurface_t *fa);
qboolean R_CullBox(vec3_t mins, vec3_t maxs);
void R_RotateForEntity(entity_t *e);
void R_MarkLeaves(void);
extern int r_dlightframecount;
glpoly_t *WaterWarpPolyVerts(glpoly_t *p);
void R_EmitWaterPolys(msurface_t *fa);
void R_AddSkySurface(msurface_t *fa);
void R_ClearSkyBox(void);
void R_DrawSkyBox(void);
void R_MarkLights(dlight_t *light, int bit, mnode_t *node);
void R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
void COM_StripExtension(char *in, char *out);

View file

@ -72,42 +72,6 @@ typedef struct msurface_s
byte *samples; /* [numstyles*surfsize] */
} msurface_t;
typedef struct mnode_s
{
/* common with leaf */
int contents; /* -1, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* node specific */
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
/* common with node */
int contents; /* wil be a negative contents number */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* leaf specific */
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
} mleaf_t;
/* Whole model */
typedef struct model_s
@ -180,7 +144,6 @@ typedef struct model_s
void Mod_Init(void);
void Mod_ClearAll(void);
mleaf_t *Mod_PointInLeaf(vec3_t p, model_t *model);
const byte *Mod_ClusterPVS(int cluster, const model_t *model);
void Mod_Modellist_f(void);

View file

@ -29,47 +29,25 @@
extern gl3lightmapstate_t gl3_lms;
#define DLIGHT_CUTOFF 64
static int r_dlightframecount;
int r_dlightframecount;
static vec3_t pointcolor;
static cplane_t *lightplane; /* used as shadow plane */
vec3_t lightspot;
void // bit: 1 << i for light number i, will be or'ed into msurface_t::dlightbits if surface is affected by this light
GL3_MarkLights(dlight_t *light, int bit, mnode_t *node)
void
GL3_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
cplane_t *splitplane;
float dist;
msurface_t *surf;
int i;
int sidebit;
if (node->contents != -1)
{
return;
}
splitplane = node->plane;
dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
if (dist > light->intensity - DLIGHT_CUTOFF)
{
GL3_MarkLights(light, bit, node->children[0]);
return;
}
if (dist < -light->intensity + DLIGHT_CUTOFF)
{
GL3_MarkLights(light, bit, node->children[1]);
return;
}
msurface_t *surf;
int i;
/* mark the polygons */
surf = gl3_worldmodel->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
int sidebit;
float dist;
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
@ -94,9 +72,6 @@ GL3_MarkLights(dlight_t *light, int bit, mnode_t *node)
surf->dlightbits |= bit;
}
GL3_MarkLights(light, bit, node->children[0]);
GL3_MarkLights(light, bit, node->children[1]);
}
void
@ -115,7 +90,7 @@ GL3_PushDlights(void)
for (i = 0; i < gl3_newrefdef.num_dlights; i++, l++)
{
gl3UniDynLight* udl = &gl3state.uniLightsData.dynLights[i];
GL3_MarkLights(l, 1 << i, gl3_worldmodel->nodes);
R_MarkLights(l, 1 << i, gl3_worldmodel->nodes, r_dlightframecount, GL3_MarkSurfaceLights);
VectorCopy(l->origin, udl->origin);
VectorCopy(l->color, udl->color);
@ -147,7 +122,7 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
int maps;
int r;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
return -1; /* didn't hit anything */
}

View file

@ -121,7 +121,7 @@ cvar_t *r_novis;
cvar_t *r_speeds;
cvar_t *gl_finish;
cvar_t *gl_cull;
cvar_t *r_cull;
cvar_t *gl_zfix;
cvar_t *r_fullbright;
cvar_t *r_modulate;
@ -262,7 +262,7 @@ GL3_Register(void)
r_modulate = ri.Cvar_Get("r_modulate", "1", CVAR_ARCHIVE);
gl_zfix = ri.Cvar_Get("gl_zfix", "0", 0);
r_clear = ri.Cvar_Get("r_clear", "0", 0);
gl_cull = ri.Cvar_Get("gl_cull", "1", 0);
r_cull = ri.Cvar_Get("r_cull", "1", 0);
r_lockpvs = ri.Cvar_Get("r_lockpvs", "0", 0);
r_novis = ri.Cvar_Get("r_novis", "0", 0);
r_speeds = ri.Cvar_Get("r_speeds", "0", 0);
@ -302,7 +302,6 @@ GL3_Register(void)
//gl_zfix = ri.Cvar_Get("gl_zfix", "0", 0);
//gl_finish = ri.Cvar_Get("gl_finish", "0", CVAR_ARCHIVE);
r_clear = ri.Cvar_Get("r_clear", "0", 0);
// gl_cull = ri.Cvar_Get("gl_cull", "1", 0);
//gl1_flashblend = ri.Cvar_Get("gl1_flashblend", "0", 0);
//gl_texturemode = ri.Cvar_Get("gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE);
@ -1023,7 +1022,7 @@ GL3_DrawParticles(void)
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
#ifdef YQ2_GL3_GLES
if(gl_cull->value != 0.0f)
if(r_cull->value != 0.0f)
glEnable(GL_CULL_FACE);
#else
glDisable(GL_PROGRAM_POINT_SIZE);
@ -1139,51 +1138,6 @@ GL3_DrawEntitiesOnList(void)
}
static int
SignbitsForPlane(cplane_t *out)
{
int bits, j;
/* for fast box on planeside test */
bits = 0;
for (j = 0; j < 3; j++)
{
if (out->normal[j] < 0)
{
bits |= 1 << j;
}
}
return bits;
}
static void
SetFrustum(void)
{
int i;
/* rotate VPN right by FOV_X/2 degrees */
RotatePointAroundVector(frustum[0].normal, vup, vpn,
-(90 - gl3_newrefdef.fov_x / 2));
/* rotate VPN left by FOV_X/2 degrees */
RotatePointAroundVector(frustum[1].normal,
vup, vpn, 90 - gl3_newrefdef.fov_x / 2);
/* rotate VPN up by FOV_X/2 degrees */
RotatePointAroundVector(frustum[2].normal,
vright, vpn, 90 - gl3_newrefdef.fov_y / 2);
/* rotate VPN down by FOV_X/2 degrees */
RotatePointAroundVector(frustum[3].normal, vright, vpn,
-(90 - gl3_newrefdef.fov_y / 2));
for (i = 0; i < 4; i++)
{
frustum[i].type = PLANE_ANYZ;
frustum[i].dist = DotProduct(gl3_origin, frustum[i].normal);
frustum[i].signbits = SignbitsForPlane(&frustum[i]);
}
}
static void
SetupFrame(void)
{
@ -1200,9 +1154,15 @@ SetupFrame(void)
/* current viewcluster */
if (!(gl3_newrefdef.rdflags & RDF_NOWORLDMODEL))
{
if (!gl3_worldmodel)
{
ri.Sys_Error(ERR_DROP, "%s: bad world model", __func__);
return;
}
gl3_oldviewcluster = gl3_viewcluster;
gl3_oldviewcluster2 = gl3_viewcluster2;
leaf = GL3_Mod_PointInLeaf(gl3_origin, gl3_worldmodel);
leaf = Mod_PointInLeaf(gl3_origin, gl3_worldmodel->nodes);
gl3_viewcluster = gl3_viewcluster2 = leaf->cluster;
/* check above and below so crossing solid water doesn't draw wrong */
@ -1213,7 +1173,7 @@ SetupFrame(void)
VectorCopy(gl3_origin, temp);
temp[2] -= 16;
leaf = GL3_Mod_PointInLeaf(temp, gl3_worldmodel);
leaf = Mod_PointInLeaf(temp, gl3_worldmodel->nodes);
if (!(leaf->contents & CONTENTS_SOLID) &&
(leaf->cluster != gl3_viewcluster2))
@ -1228,7 +1188,7 @@ SetupFrame(void)
VectorCopy(gl3_origin, temp);
temp[2] += 16;
leaf = GL3_Mod_PointInLeaf(temp, gl3_worldmodel);
leaf = Mod_PointInLeaf(temp, gl3_worldmodel->nodes);
if (!(leaf->contents & CONTENTS_SOLID) &&
(leaf->cluster != gl3_viewcluster2))
@ -1496,7 +1456,7 @@ SetupGL(void)
GL3_UpdateUBO3D();
/* set drawing parms */
if (gl_cull->value)
if (r_cull->value)
{
glEnable(GL_CULL_FACE);
}
@ -1653,7 +1613,8 @@ GL3_RenderView(refdef_t *fd)
SetupFrame();
SetFrustum();
R_SetFrustum(vup, vpn, vright, gl3_origin,
gl3_newrefdef.fov_x, gl3_newrefdef.fov_y, frustum);
SetupGL();

View file

@ -64,43 +64,6 @@ Mod_HasFreeSpace(void)
return (mod_numknown + mod_max) < MAX_MOD_KNOWN;
}
mleaf_t *
GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model)
{
mnode_t *node;
float d;
cplane_t *plane;
if (!model || !model->nodes)
{
ri.Sys_Error(ERR_DROP, "%s: bad model", __func__);
}
node = model->nodes;
while (1)
{
if (node->contents != -1)
{
return (mleaf_t *)node;
}
plane = node->plane;
d = DotProduct(p, plane->normal) - plane->dist;
if (d > 0)
{
node = node->children[0];
}
else
{
node = node->children[1];
}
}
return NULL; /* never reached */
}
const byte*
GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model)
{
@ -158,71 +121,6 @@ GL3_Mod_Init(void)
memset(mod_novis, 0xff, sizeof(mod_novis));
}
static void
Mod_LoadLighting(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
if (!l->filelen)
{
loadmodel->lightdata = NULL;
return;
}
loadmodel->lightdata = Hunk_Alloc(l->filelen);
memcpy(loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
}
static void
Mod_LoadVisibility(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i;
if (!l->filelen)
{
loadmodel->vis = NULL;
return;
}
loadmodel->vis = Hunk_Alloc(l->filelen);
memcpy(loadmodel->vis, mod_base + l->fileofs, l->filelen);
loadmodel->vis->numclusters = LittleLong(loadmodel->vis->numclusters);
for (i = 0; i < loadmodel->vis->numclusters; i++)
{
loadmodel->vis->bitofs[i][0] = LittleLong(loadmodel->vis->bitofs[i][0]);
loadmodel->vis->bitofs[i][1] = LittleLong(loadmodel->vis->bitofs[i][1]);
}
}
static void
Mod_LoadVertexes(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
dvertex_t *in;
mvertex_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->vertexes = out;
loadmodel->numvertexes = count;
for (i = 0; i < count; i++, in++, out++)
{
out->position[0] = LittleFloat(in->point[0]);
out->position[1] = LittleFloat(in->point[1]);
out->position[2] = LittleFloat(in->point[2]);
}
}
static void
Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
@ -282,102 +180,6 @@ Mod_LoadSubmodels(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
static void
Mod_LoadEdges(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
dedge_t *in;
medge_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count + 1) * sizeof(*out));
loadmodel->edges = out;
loadmodel->numedges = count;
for (i = 0; i < count; i++, in++, out++)
{
out->v[0] = (unsigned short)LittleShort(in->v[0]);
out->v[1] = (unsigned short)LittleShort(in->v[1]);
}
}
static void
Mod_LoadTexinfo(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
texinfo_t *in;
mtexinfo_t *out, *step;
int i, j, count;
int next;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->texinfo = out;
loadmodel->numtexinfo = count;
for (i = 0; i < count; i++, in++, out++)
{
gl3image_t *image;
for (j = 0; j < 4; j++)
{
out->vecs[0][j] = LittleFloat(in->vecs[0][j]);
out->vecs[1][j] = LittleFloat(in->vecs[1][j]);
}
out->flags = LittleLong(in->flags);
next = LittleLong(in->nexttexinfo);
if (next > 0)
{
out->next = loadmodel->texinfo + next;
}
else
{
out->next = NULL;
}
image = GetTexImage(in->texture, (findimage_t)GL3_FindImage);
if (!image)
{
R_Printf(PRINT_ALL, "%s: Couldn't load %s\n",
__func__, in->texture);
image = gl3_notexture;
}
out->image = image;
}
/* count animation frames */
for (i = 0; i < count; i++)
{
out = &loadmodel->texinfo[i];
out->numframes = 1;
for (step = out->next; step && step != out; step = step->next)
{
out->numframes++;
}
}
}
/*
* Fills in s->texturemins[] and s->extents[]
*/
@ -555,6 +357,11 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
out->flags |= SURF_PLANEBACK;
}
if (planenum < 0 || planenum >= loadmodel->numplanes)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;
ti = LittleShort(in->texinfo);
@ -623,74 +430,6 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
GL3_LM_EndBuildingLightmaps();
}
static void
Mod_SetParent(mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != -1)
{
return;
}
Mod_SetParent(node->children[0], node);
Mod_SetParent(node->children[1], node);
}
static void
Mod_LoadNodes(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, j, count, p;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->nodes = out;
loadmodel->numnodes = count;
for (i = 0; i < count; i++, in++, out++)
{
for (j = 0; j < 3; j++)
{
out->minmaxs[j] = LittleShort(in->mins[j]);
out->minmaxs[3 + j] = LittleShort(in->maxs[j]);
}
p = LittleLong(in->planenum);
out->plane = loadmodel->planes + p;
out->firstsurface = LittleShort(in->firstface);
out->numsurfaces = LittleShort(in->numfaces);
out->contents = -1; /* differentiate from leafs */
for (j = 0; j < 2; j++)
{
p = LittleLong(in->children[j]);
if (p >= 0)
{
out->children[j] = loadmodel->nodes + p;
}
else
{
out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
}
}
}
Mod_SetParent(loadmodel->nodes, NULL); /* sets nodes and leafs */
}
static void
Mod_LoadLeafs(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
@ -775,102 +514,6 @@ Mod_LoadMarksurfaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
static void
Mod_LoadSurfedges(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, count;
int *in, *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
if ((count < 1) || (count >= MAX_MAP_SURFEDGES))
{
ri.Sys_Error(ERR_DROP, "%s: bad surfedges count in %s: %i",
__func__, loadmodel->name, count);
}
out = Hunk_Alloc(count * sizeof(*out));
loadmodel->surfedges = out;
loadmodel->numsurfedges = count;
for (i = 0; i < count; i++)
{
out[i] = LittleLong(in[i]);
}
}
static void
Mod_LoadPlanes(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, j;
cplane_t *out;
dplane_t *in;
int count;
int bits;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count * 2 * sizeof(*out));
loadmodel->planes = out;
loadmodel->numplanes = count;
for (i = 0; i < count; i++, in++, out++)
{
bits = 0;
for (j = 0; j < 3; j++)
{
out->normal[j] = LittleFloat(in->normal[j]);
if (out->normal[j] < 0)
{
bits |= 1 << j;
}
}
out->dist = LittleFloat(in->dist);
out->type = LittleLong(in->type);
out->signbits = bits;
}
}
// calculate the size that Hunk_Alloc(), called by Mod_Load*() from Mod_LoadBrushModel(),
// will use (=> includes its padding), so we'll know how big the hunk needs to be
static int calcLumpHunkSize(const lump_t *l, int inSize, int outSize)
{
if (l->filelen % inSize)
{
// Mod_Load*() will error out on this because of "funny size"
// don't error out here because in Mod_Load*() it can print the functionname
// (=> tells us what kind of lump) before shutting down the game
return 0;
}
int count = l->filelen / inSize;
int size = count * outSize;
// round to cacheline, like Hunk_Alloc() does
size = (size + 31) & ~31;
return size;
}
static void
Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen)
{
@ -903,36 +546,44 @@ Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen)
// calculate the needed hunksize from the lumps
int hunkSize = 0;
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_EDGES], sizeof(dedge_t), sizeof(medge_t));
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_EDGES], sizeof(dedge_t), sizeof(medge_t), 0);
hunkSize += sizeof(medge_t) + 31; // for count+1 in Mod_LoadEdges()
int surfEdgeCount = (header->lumps[LUMP_SURFEDGES].filelen+sizeof(int)-1)/sizeof(int);
if(surfEdgeCount < MAX_MAP_SURFEDGES) // else it errors out later anyway
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LIGHTING], 1, 1);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t)*2);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LIGHTING], 1, 1, 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t)*2, 0);
hunkSize += calcTexinfoAndFacesSize(mod_base, &header->lumps[LUMP_FACES], &header->lumps[LUMP_TEXINFO]);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *)); // yes, out is indeeed a pointer!
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFS], sizeof(dleaf_t), sizeof(mleaf_t));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_NODES], sizeof(dnode_t), sizeof(mnode_t));
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(gl3model_t));
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *), 0); // yes, out is indeeed a pointer!
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1, 0);
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), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(gl3model_t), 0);
mod->extradata = Hunk_Begin(hunkSize);
mod->type = mod_brush;
/* load into heap */
Mod_LoadVertexes(mod, mod_base, &header->lumps[LUMP_VERTEXES]);
Mod_LoadEdges(mod, mod_base, &header->lumps[LUMP_EDGES]);
Mod_LoadSurfedges(mod, mod_base, &header->lumps[LUMP_SURFEDGES]);
Mod_LoadLighting(mod, mod_base, &header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes(mod, mod_base, &header->lumps[LUMP_PLANES]);
Mod_LoadTexinfo(mod, mod_base, &header->lumps[LUMP_TEXINFO]);
Mod_LoadVertexes(mod->name, &mod->vertexes, &mod->numvertexes, mod_base,
&header->lumps[LUMP_VERTEXES], 0);
Mod_LoadEdges(mod->name, &mod->edges, &mod->numedges,
mod_base, &header->lumps[LUMP_EDGES], 1);
Mod_LoadSurfedges(mod->name, &mod->surfedges, &mod->numsurfedges,
mod_base, &header->lumps[LUMP_SURFEDGES], 0);
Mod_LoadLighting(&mod->lightdata, mod_base, &header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes (mod->name, &mod->planes, &mod->numplanes,
mod_base, &header->lumps[LUMP_PLANES], 0);
Mod_LoadTexinfo (mod->name, &mod->texinfo, &mod->numtexinfo,
mod_base, &header->lumps[LUMP_TEXINFO], (findimage_t)GL3_FindImage,
gl3_notexture, 0);
Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES]);
Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadVisibility(&mod->vis, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]);
Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadNodes(mod->name, mod->planes, mod->numplanes, mod->leafs,
mod->numleafs, &mod->nodes, &mod->numnodes, mod_base,
&header->lumps[LUMP_NODES]);
Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]);
mod->numframes = 2; /* regular and alternate animation */
}

View file

@ -132,55 +132,6 @@ void GL3_SurfShutdown(void)
gl3state.vaoAlias = 0;
}
/*
* Returns true if the box is completely outside the frustom
*/
static qboolean
CullBox(vec3_t mins, vec3_t maxs)
{
int i;
if (!gl_cull->value)
{
return false;
}
for (i = 0; i < 4; i++)
{
if (BOX_ON_PLANE_SIDE(mins, maxs, &frustum[i]) == 2)
{
return true;
}
}
return false;
}
/*
* Returns the proper texture for a given time and base texture
*/
static gl3image_t *
TextureAnimation(entity_t *currententity, mtexinfo_t *tex)
{
int c;
if (!tex->next)
{
return tex->image;
}
c = currententity->frame % tex->numframes;
while (c)
{
tex = tex->next;
c--;
}
return tex->image;
}
static void
SetLightFlags(msurface_t *surf)
{
@ -345,7 +296,7 @@ RenderBrushPoly(entity_t *currententity, msurface_t *fa)
c_brush_polys++;
image = TextureAnimation(currententity, fa->texinfo);
image = R_TextureAnimation(currententity, fa->texinfo);
if (fa->flags & SURF_DRAWTURB)
{
@ -490,7 +441,7 @@ static void
RenderLightmappedPoly(entity_t *currententity, msurface_t *surf)
{
int map;
gl3image_t *image = TextureAnimation(currententity, surf->texinfo);
gl3image_t *image = R_TextureAnimation(currententity, surf->texinfo);
hmm_vec4 lmScales[MAX_LIGHTMAPS_PER_SURFACE] = {0};
lmScales[0] = HMM_Vec4(1.0f, 1.0f, 1.0f, 1.0f);
@ -540,7 +491,8 @@ DrawInlineBModel(entity_t *currententity, gl3model_t *currentmodel)
for (k = 0; k < gl3_newrefdef.num_dlights; k++, lt++)
{
GL3_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode);
R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode,
r_dlightframecount, GL3_MarkSurfaceLights);
}
psurf = &currentmodel->surfaces[currentmodel->firstmodelsurface];
@ -621,7 +573,7 @@ GL3_DrawBrushModel(entity_t *e, gl3model_t *currentmodel)
VectorAdd(e->origin, currentmodel->maxs, maxs);
}
if (CullBox(mins, maxs))
if (r_cull->value && R_CullBox(mins, maxs, frustum))
{
return;
}
@ -688,24 +640,20 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node)
return;
}
if (CullBox(node->minmaxs, node->minmaxs + 3))
if (r_cull->value && R_CullBox(node->minmaxs, node->minmaxs + 3, frustum))
{
return;
}
/* if a leaf node, draw stuff */
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
pleaf = (mleaf_t *)node;
/* check for door connected areas */
if (gl3_newrefdef.areabits)
{
if (!(gl3_newrefdef.areabits[pleaf->area >> 3] & (1 << (pleaf->area & 7))))
{
return; /* not visible */
}
}
// check for door connected areas
if (!R_AreaVisible(gl3_newrefdef.areabits, pleaf))
return; // not visible
mark = pleaf->firstmarksurface;
c = pleaf->nummarksurfaces;
@ -782,7 +730,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node)
/* add to the translucent chain */
surf->texturechain = gl3_alpha_surfaces;
gl3_alpha_surfaces = surf;
gl3_alpha_surfaces->texinfo->image = TextureAnimation(currententity, surf->texinfo);
gl3_alpha_surfaces->texinfo->image = R_TextureAnimation(currententity, surf->texinfo);
}
else
{
@ -798,7 +746,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node)
#endif // 0
{
/* the polygon is visible, so add it to the texture sorted chain */
image = TextureAnimation(currententity, surf->texinfo);
image = R_TextureAnimation(currententity, surf->texinfo);
surf->texturechain = image->texturechain;
image->texturechain = surf;
}

View file

@ -381,7 +381,6 @@ GL3_BindEBO(GLuint ebo)
extern void GL3_BufferAndDraw3D(const gl3_3D_vtx_t* verts, int numVerts, GLenum drawMode);
extern qboolean GL3_CullBox(vec3_t mins, vec3_t maxs);
extern void GL3_RotateForEntity(entity_t *e);
// gl3_sdl.c
@ -406,7 +405,6 @@ extern struct model_s * GL3_RegisterModel(char *name);
extern void GL3_EndRegistration(void);
extern void GL3_Mod_Modellist_f(void);
extern const byte* GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model);
extern mleaf_t* GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model);
// gl3_draw.c
extern void GL3_Draw_InitLocal(void);
@ -450,7 +448,9 @@ extern qboolean GL3_ImageHasFreeSpace(void);
extern void GL3_ImageList_f(void);
// gl3_light.c
extern void GL3_MarkLights(dlight_t *light, int bit, mnode_t *node);
extern int r_dlightframecount;
extern void GL3_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
extern void GL3_PushDlights(void);
extern void GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color);
extern void GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride);
@ -522,7 +522,7 @@ extern cvar_t *gl_nobind;
extern cvar_t *r_lockpvs;
extern cvar_t *r_novis;
extern cvar_t *gl_cull;
extern cvar_t *r_cull;
extern cvar_t *gl_zfix;
extern cvar_t *r_fullbright;

View file

@ -88,42 +88,6 @@ typedef struct msurface_s
byte *samples; /* [numstyles*surfsize] */
} msurface_t;
typedef struct mnode_s
{
/* common with leaf */
int contents; /* -1, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* node specific */
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
/* common with node */
int contents; /* wil be a negative contents number */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* leaf specific */
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
} mleaf_t;
/* Whole model */
// this, must be struct model_s, not gl3model_s,

View file

@ -137,6 +137,44 @@ typedef struct mtexinfo_s
struct image_s *image;
} mtexinfo_t;
#define CONTENTS_NODE -1
typedef struct mnode_s
{
/* common with leaf */
int contents; /* CONTENTS_NODE, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* node specific */
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
/* common with leaf */
int contents; /* CONTENTS_NODE, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* leaf specific */
int cluster;
int area;
struct msurface_s **firstmarksurface;
int nummarksurfaces;
int key; /* BSP sequence number for leaf's contents */
} mleaf_t;
/* Shared models func */
typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type);
extern void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
@ -150,7 +188,39 @@ extern struct image_s *GetSkyImage(const char *skyname, const char* surfname,
qboolean palettedtexture, findimage_t find_image);
extern struct image_s *GetTexImage(const char *name, findimage_t find_image);
extern struct image_s *R_FindPic(const char *name, findimage_t find_image);
extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type,
qboolean r_retexturing, loadimage_t load_image);
extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext,
imagetype_t type, qboolean r_retexturing, loadimage_t load_image);
extern void Mod_LoadNodes(const char *name, cplane_t *planes, int numplanes,
mleaf_t *leafs, int numleafs, mnode_t **nodes, int *numnodes,
const byte *mod_base, const lump_t *l);
extern void Mod_LoadVertexes(const char *name, mvertex_t **vertexes, int *numvertexes,
const byte *mod_base, const lump_t *l, int extra);
extern void Mod_LoadVisibility(dvis_t **vis, const byte *mod_base, const lump_t *l);
extern void Mod_LoadLighting(byte **lightdata, const byte *mod_base, const lump_t *l);
extern void Mod_LoadTexinfo(const char *name, mtexinfo_t **texinfo, int *numtexinfo,
const byte *mod_base, const lump_t *l, findimage_t find_image,
struct image_s *notexture, int extra);
extern void Mod_LoadEdges(const char *name, medge_t **edges, int *numedges,
const byte *mod_base, const lump_t *l, int extra);
extern void Mod_LoadPlanes (const char *name, cplane_t **planes, int *numplanes,
const byte *mod_base, const lump_t *l, int extra);
extern void Mod_LoadSurfedges (const char *name, int **surfedges, int *numsurfedges,
const byte *mod_base, const lump_t *l, int extra);
extern int Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra);
extern mleaf_t *Mod_PointInLeaf(const vec3_t p, mnode_t *node);
/* Surface logic */
#define DLIGHT_CUTOFF 64
typedef void (*marksurfacelights_t)(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
extern void R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount,
marksurfacelights_t mark_surface_lights);
extern struct image_s *R_TextureAnimation(const entity_t *currententity,
const mtexinfo_t *tex);
extern qboolean R_AreaVisible(const byte *areabits, mleaf_t *pleaf);
extern qboolean R_CullBox(vec3_t mins, vec3_t maxs, cplane_t *frustum);
extern void R_SetFrustum(vec3_t vup, vec3_t vpn, vec3_t vright, vec3_t r_origin,
float fov_x, float fov_y, cplane_t *frustum);
#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */

View file

@ -441,10 +441,12 @@ extern cvar_t *r_lerpmodels;
extern cvar_t *r_lightlevel;
extern cvar_t *r_modulate;
extern cvar_t *r_fixsurfsky;
extern cvar_t *r_cull;
extern clipplane_t view_clipplanes[4];
extern int *pfrustum_indexes[4];
extern cplane_t frustum[4];
//=============================================================================

View file

@ -69,47 +69,6 @@ typedef struct msurface_s
struct msurface_s *nextalphasurface;
} msurface_t;
#define CONTENTS_NODE -1
typedef struct mnode_s
{
// common with leaf
int contents; // CONTENTS_NODE, to differentiate from leafs
int visframe; // node needs to be traversed if current
/* FIXME: is different type in other renders */
short minmaxs[6]; // for bounding box culling
struct mnode_s *parent;
// node specific
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
// common with node
int contents; // wil be something other than CONTENTS_NODE
int visframe; // node needs to be traversed if current
short minmaxs[6]; // for bounding box culling
struct mnode_s *parent;
// leaf specific
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
int key; // BSP sequence number for leaf's contents
} mleaf_t;
//===================================================================
//

View file

@ -138,25 +138,6 @@ R_RotateBmodel(const entity_t *currententity)
R_TransformFrustum ();
}
static qboolean
R_AreaVisible(mleaf_t *pleaf)
{
int area;
// check for door connected areas
if (!r_newrefdef.areabits)
return true;
area = pleaf->area;
if ((r_newrefdef.areabits[area>>3] & (1<<(area&7))))
return true;
return false; // not visible
}
/*
================
R_RecursiveClipBPoly
@ -320,7 +301,7 @@ R_RecursiveClipBPoly(entity_t *currententity, bedge_t *pedges, mnode_t *pnode, m
{
int r_currentbkey;
if (!R_AreaVisible((mleaf_t *)pn))
if (!R_AreaVisible(r_newrefdef.areabits, (mleaf_t *)pn))
continue;
r_currentbkey = ((mleaf_t *)pn)->key;
@ -469,9 +450,6 @@ R_DrawSubmodelPolygons(entity_t *currententity, const model_t *currentmodel, int
}
}
static int c_drawnode;
/*
================
R_RecursiveWorldNode
@ -486,10 +464,19 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod
mleaf_t *pleaf;
if (node->contents == CONTENTS_SOLID)
{
return; // solid
}
if (node->visframe != r_visframecount)
{
return;
}
if (r_cull->value && R_CullBox(node->minmaxs, node->minmaxs + 3, frustum))
{
return;
}
// cull the clipping planes if not trivial accept
// FIXME: the compiler is doing a lousy job of optimizing here; it could be
@ -510,17 +497,17 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod
pindex = pfrustum_indexes[i];
rejectpt[0] = (float)node->minmaxs[pindex[0]];
rejectpt[1] = (float)node->minmaxs[pindex[1]];
rejectpt[2] = (float)node->minmaxs[pindex[2]];
rejectpt[0] = node->minmaxs[pindex[0]];
rejectpt[1] = node->minmaxs[pindex[1]];
rejectpt[2] = node->minmaxs[pindex[2]];
d = DotProduct (rejectpt, view_clipplanes[i].normal);
d -= view_clipplanes[i].dist;
if (d <= 0)
return;
acceptpt[0] = (float)node->minmaxs[pindex[3+0]];
acceptpt[1] = (float)node->minmaxs[pindex[3+1]];
acceptpt[2] = (float)node->minmaxs[pindex[3+2]];
acceptpt[0] = node->minmaxs[pindex[3+0]];
acceptpt[1] = node->minmaxs[pindex[3+1]];
acceptpt[2] = node->minmaxs[pindex[3+2]];
d = DotProduct (acceptpt, view_clipplanes[i].normal);
d -= view_clipplanes[i].dist;
@ -530,15 +517,13 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod
}
}
c_drawnode++;
// if a leaf node, draw stuff
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
{
msurface_t **mark;
pleaf = (mleaf_t *)node;
if (!R_AreaVisible(pleaf))
if (!R_AreaVisible(r_newrefdef.areabits, pleaf))
return; // not visible
mark = pleaf->firstmarksurface;
@ -650,8 +635,6 @@ R_RenderWorld (entity_t *currententity)
if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
return;
c_drawnode=0;
// auto cycle the world frame for texture animation
currententity->frame = (int)(r_newrefdef.time*2);

View file

@ -331,7 +331,7 @@ R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int real
/* Code used with HIColor calls */
if (bits == 32)
{
image_t *image;
image_t *image = NULL;
byte *pic8;
pic8 = malloc(data_size);

View file

@ -29,44 +29,15 @@ DYNAMIC LIGHTS
=============================================================================
*/
/*
=============
R_MarkLights
=============
*/
static void
R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
cplane_t *splitplane;
float dist;
msurface_t *surf;
int i;
if (node->contents != -1)
return;
splitplane = node->plane;
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist;
i = light->intensity;
if (i < 0)
i = -i;
if (dist > i) // (dist > light->intensity)
{
R_MarkLights (light, bit, node->children[0], r_dlightframecount);
return;
}
if (dist < -i) // (dist < -light->intensity)
{
R_MarkLights (light, bit, node->children[1], r_dlightframecount);
return;
}
// mark the polygons
surf = r_worldmodel->surfaces + node->firstsurface;
for (i=0 ; i<node->numsurfaces ; i++, surf++)
for (i = 0; i < node->numsurfaces; i++, surf++)
{
if (surf->dlightframe != r_dlightframecount)
{
@ -75,12 +46,8 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
}
surf->dlightbits |= bit;
}
R_MarkLights (light, bit, node->children[0], r_dlightframecount);
R_MarkLights (light, bit, node->children[1], r_dlightframecount);
}
/*
=============
R_PushDlights
@ -96,7 +63,7 @@ R_PushDlights (const model_t *model)
{
R_MarkLights ( l, 1<<i,
model->nodes + model->firstnode,
r_framecount);
r_framecount, R_MarkSurfaceLights);
}
}
@ -122,7 +89,7 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor)
int maps;
int r;
if (node->contents != -1)
if (node->contents != CONTENTS_NODE)
return -1; // didn't hit anything
// calculate mid point
@ -334,7 +301,7 @@ R_AddDynamicLights (drawsurf_t* drawsurf)
dist = DotProduct (dl->origin, surf->plane->normal) -
surf->plane->dist;
rad -= fabs(dist);
minlight = 32; // dl->minlight;
minlight = DLIGHT_CUTOFF; // dl->minlight;
if (rad < minlight)
continue;
minlight = rad - minlight;

View file

@ -174,6 +174,7 @@ static cvar_t *vid_gamma;
static cvar_t *r_lockpvs;
static cvar_t *r_palettedtexture;
cvar_t *r_cull;
// sw_vars.c
@ -414,6 +415,7 @@ R_RegisterVariables (void)
r_customheight = ri.Cvar_Get("r_customheight", "768", CVAR_ARCHIVE);
r_fixsurfsky = ri.Cvar_Get("r_fixsurfsky", "0", CVAR_ARCHIVE);
r_palettedtexture = ri.Cvar_Get("r_palettedtexture", "0", 0);
r_cull = ri.Cvar_Get("r_cull", "1", 0);
vid_fullscreen = ri.Cvar_Get( "vid_fullscreen", "0", CVAR_ARCHIVE );
vid_gamma = ri.Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE );
@ -1008,7 +1010,7 @@ R_FindTopnode (vec3_t mins, vec3_t maxs)
}
splitplane = node->plane;
sides = BOX_ON_PLANE_SIDE(mins, maxs, (cplane_t *)splitplane);
sides = BOX_ON_PLANE_SIDE(mins, maxs, splitplane);
if (sides == 3)
return node; // this is the splitter
@ -1299,6 +1301,9 @@ VectorCompareRound(const vec3_t v1, const vec3_t v2)
return 1;
}
cplane_t frustum[4];
/*
================
RE_RenderFrame
@ -1343,6 +1348,9 @@ RE_RenderFrame (refdef_t *fd)
R_SetupFrame ();
R_SetFrustum(vup, vpn, vright, r_origin, r_newrefdef.fov_x, r_newrefdef.fov_y,
frustum);
// Using the current view cluster (r_viewcluster), retrieve and decompress
// the PVS (Potentially Visible Set)
R_MarkLeaves (); // done here so we know if we're in water

View file

@ -27,7 +27,6 @@ cvar_t *sw_mipscale;
float verticalFieldOfView;
int d_minmip;
float d_scalemip[NUM_MIPS-1];
static mleaf_t *r_viewleaf;
static int r_frustum_indexes[4*6];
static const float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8};
@ -306,40 +305,6 @@ R_ViewChanged (const vrect_t *vr)
D_ViewChanged ();
}
/*
===============
Mod_PointInLeaf
===============
*/
static mleaf_t *
Mod_PointInLeaf (const vec3_t p, const model_t *model)
{
mnode_t *node;
if (!model || !model->nodes)
{
ri.Sys_Error(ERR_DROP, "%s: bad model", __func__);
return NULL;
}
node = model->nodes;
while (node->contents == -1)
{
float d;
cplane_t *plane;
plane = node->plane;
d = DotProduct (p,plane->normal) - plane->dist;
if (d > 0)
node = node->children[0];
else
node = node->children[1];
}
return (mleaf_t *)node;
}
/*
===============
R_SetupFrame
@ -369,9 +334,17 @@ R_SetupFrame (void)
// current viewleaf
if ( !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) )
{
mleaf_t *r_viewleaf;
if (!r_worldmodel)
{
ri.Sys_Error(ERR_DROP, "%s: bad world model", __func__);
return;
}
// Determine what is the current view cluster (walking the BSP tree)
// and store it in r_viewcluster
r_viewleaf = Mod_PointInLeaf (r_origin, r_worldmodel);
r_viewleaf = Mod_PointInLeaf (r_origin, r_worldmodel->nodes);
r_viewcluster = r_viewleaf->cluster;
}

View file

@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen);
static byte mod_novis[MAX_MAP_LEAFS/8];
static YQ2_ALIGNAS_TYPE(int) byte mod_novis[MAX_MAP_LEAFS/8];
#define MAX_MOD_KNOWN 512
static model_t mod_known[MAX_MOD_KNOWN];
@ -263,124 +263,6 @@ Mod_ClusterPVS (int cluster, const model_t *model)
===============================================================================
*/
/*
=================
Mod_LoadLighting
Converts the 24 bit lighting down to 8 bit
by taking the brightest component
=================
*/
static void
Mod_LoadLighting (model_t *loadmodel, byte *mod_base, lump_t *l)
{
int size;
if (!l->filelen)
{
loadmodel->lightdata = NULL;
return;
}
size = l->filelen;
loadmodel->lightdata = Hunk_Alloc(size);
memcpy(loadmodel->lightdata, mod_base + l->fileofs, size);
}
static int r_leaftovis[MAX_MAP_LEAFS];
static int r_vistoleaf[MAX_MAP_LEAFS];
static int r_numvisleafs;
static void
R_NumberLeafs (model_t *loadmodel, mnode_t *node)
{
if (node->contents != -1)
{
mleaf_t *leaf;
int leafnum;
leaf = (mleaf_t *)node;
leafnum = leaf - loadmodel->leafs;
if (leaf->contents & CONTENTS_SOLID)
return;
r_leaftovis[leafnum] = r_numvisleafs;
r_vistoleaf[r_numvisleafs] = leafnum;
r_numvisleafs++;
return;
}
R_NumberLeafs (loadmodel, node->children[0]);
R_NumberLeafs (loadmodel, node->children[1]);
}
/*
=================
Mod_LoadVisibility
=================
*/
static void
Mod_LoadVisibility (model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i;
if (!l->filelen)
{
loadmodel->vis = NULL;
return;
}
loadmodel->vis = Hunk_Alloc(l->filelen);
memcpy (loadmodel->vis, mod_base + l->fileofs, l->filelen);
loadmodel->vis->numclusters = LittleLong (loadmodel->vis->numclusters);
for (i=0 ; i<loadmodel->vis->numclusters ; i++)
{
loadmodel->vis->bitofs[i][0] = LittleLong (loadmodel->vis->bitofs[i][0]);
loadmodel->vis->bitofs[i][1] = LittleLong (loadmodel->vis->bitofs[i][1]);
}
}
/*
=================
Mod_LoadVertexes
=================
*/
static void
Mod_LoadVertexes (model_t *loadmodel, byte *mod_base, lump_t *l)
{
dvertex_t *in;
mvertex_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count+8)*sizeof(*out)); // extra for skybox
/*
* Fix for the problem where the games dumped core
* when changing levels.
*/
memset( out, 0, (count + 6) * sizeof( *out ) );
loadmodel->vertexes = out;
loadmodel->numvertexes = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
out->position[0] = LittleFloat (in->point[0]);
out->position[1] = LittleFloat (in->point[1]);
out->position[2] = LittleFloat (in->point[2]);
}
}
/*
=================
Mod_LoadSubmodels
@ -443,109 +325,6 @@ Mod_LoadSubmodels (model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
/*
=================
Mod_LoadEdges
=================
*/
static void
Mod_LoadEdges (model_t *loadmodel, byte *mod_base, lump_t *l)
{
dedge_t *in;
medge_t *out;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count + 13) * sizeof(*out)); // extra for skybox
loadmodel->edges = out;
loadmodel->numedges = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
out->v[0] = (unsigned short)LittleShort(in->v[0]);
out->v[1] = (unsigned short)LittleShort(in->v[1]);
}
}
/*
=================
Mod_LoadTexinfo
=================
*/
static void
Mod_LoadTexinfo (model_t *loadmodel, byte *mod_base, lump_t *l)
{
texinfo_t *in;
mtexinfo_t *out, *step;
int i, count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count+6)*sizeof(*out)); // extra for skybox
loadmodel->texinfo = out;
loadmodel->numtexinfo = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
image_t *image;
int j, next;
for (j = 0; j < 4; j++)
{
out->vecs[0][j] = LittleFloat(in->vecs[0][j]);
out->vecs[1][j] = LittleFloat(in->vecs[1][j]);
}
out->flags = LittleLong (in->flags);
next = LittleLong (in->nexttexinfo);
if (next > 0)
out->next = loadmodel->texinfo + next;
/*
* Fix for the problem where the game
* domed core when loading a new level.
*/
else {
out->next = NULL;
}
image = GetTexImage(in->texture, (findimage_t)R_FindImage);
if (!image)
{
R_Printf(PRINT_ALL, "%s: Couldn't load %s\n",
__func__, in->texture);
image = r_notexture_mip;
}
out->image = image;
}
// count animation frames
for (i=0 ; i<count ; i++)
{
out = &loadmodel->texinfo[i];
out->numframes = 1;
for (step = out->next ; step && step != out ; step=step->next)
out->numframes++;
}
}
/*
================
CalcSurfaceExtents
@ -572,11 +351,15 @@ CalcSurfaceExtents (model_t *loadmodel, msurface_t *s)
mvertex_t *v;
e = loadmodel->surfedges[s->firstedge+i];
if (e >= 0)
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
else
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
if (e >= 0)
{
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
}
else
{
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
}
for (j=0 ; j<2 ; j++)
{
val = v->position[0] * tex->vecs[j][0] +
@ -635,7 +418,7 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l)
for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
{
int planenum, side;
int planenum, side, ti;
out->firstedge = LittleLong(in->firstedge);
out->numedges = LittleShort(in->numedges);
@ -651,9 +434,19 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l)
if (side)
out->flags |= SURF_PLANEBACK;
if (planenum < 0 || planenum >= loadmodel->numplanes)
{
ri.Sys_Error(ERR_DROP, "%s: Incorrect %d planenum.",
__func__, planenum);
}
out->plane = loadmodel->planes + planenum;
out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
ti = LittleShort(in->texinfo);
if (ti < 0 || ti >= loadmodel->numtexinfo)
{
ri.Sys_Error(ERR_DROP, "%s: bad texinfo number", __func__);
}
out->texinfo = loadmodel->texinfo + ti;
CalcSurfaceExtents (loadmodel, out);
@ -664,6 +457,7 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l)
}
i = LittleLong(in->lightofs);
if (i == -1)
{
out->samples = NULL;
@ -714,78 +508,6 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
/*
=================
Mod_SetParent
=================
*/
static void
Mod_SetParent (mnode_t *node, mnode_t *parent)
{
node->parent = parent;
if (node->contents != -1)
return;
Mod_SetParent (node->children[0], node);
Mod_SetParent (node->children[1], node);
}
/*
=================
Mod_LoadNodes
=================
*/
static void
Mod_LoadNodes (model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, count;
dnode_t *in;
mnode_t *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc(count*sizeof(*out));
loadmodel->nodes = out;
loadmodel->numnodes = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
int j, p;
for (j=0 ; j<3 ; j++)
{
out->minmaxs[j] = LittleShort (in->mins[j]);
out->minmaxs[3+j] = LittleShort (in->maxs[j]);
}
p = LittleLong(in->planenum);
out->plane = loadmodel->planes + p;
out->firstsurface = LittleShort (in->firstface);
out->numsurfaces = LittleShort (in->numfaces);
out->contents = CONTENTS_NODE; // differentiate from leafs
for (j=0 ; j<2 ; j++)
{
p = LittleLong (in->children[j]);
if (p >= 0)
out->children[j] = loadmodel->nodes + p;
else
out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
}
}
Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
}
/*
=================
Mod_LoadLeafs
@ -878,102 +600,6 @@ Mod_LoadMarksurfaces (model_t *loadmodel, byte *mod_base, lump_t *l)
}
}
/*
=================
Mod_LoadSurfedges
=================
*/
static void
Mod_LoadSurfedges (model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i, count;
int *in, *out;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count+24)*sizeof(*out)); // extra for skybox
loadmodel->surfedges = out;
loadmodel->numsurfedges = count;
for ( i=0 ; i<count ; i++)
out[i] = LittleLong (in[i]);
}
/*
=================
Mod_LoadPlanes
=================
*/
static void
Mod_LoadPlanes (model_t *loadmodel, byte *mod_base, lump_t *l)
{
int i;
cplane_t *out;
dplane_t *in;
int count;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
{
ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s",
__func__, loadmodel->name);
}
count = l->filelen / sizeof(*in);
out = Hunk_Alloc((count+6)*sizeof(*out)); // extra for skybox
loadmodel->planes = out;
loadmodel->numplanes = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
int bits, j;
bits = 0;
for (j=0 ; j<3 ; j++)
{
out->normal[j] = LittleFloat (in->normal[j]);
if (out->normal[j] < 0)
bits |= 1<<j;
}
out->dist = LittleFloat (in->dist);
out->type = LittleLong (in->type);
out->signbits = bits;
}
}
// calculate the size that Hunk_Alloc(), called by Mod_Load*() from Mod_LoadBrushModel(),
// will use (=> includes its padding), so we'll know how big the hunk needs to be
// extra is used for skybox, which adds 6 surfaces
static int calcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra)
{
if (l->filelen % inSize)
{
// Mod_Load*() will error out on this because of "funny size"
// don't error out here because in Mod_Load*() it can print the functionname
// (=> tells us what kind of lump) before shutting down the game
return 0;
}
int count = l->filelen / inSize + extra;
int size = count * outSize;
// round to cacheline, like Hunk_Alloc() does
size = (size + 31) & ~31;
return size;
}
/*
=================
Mod_LoadBrushModel
@ -1006,11 +632,11 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
// calculate the needed hunksize from the lumps
int hunkSize = 0;
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t), 8);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_EDGES], sizeof(dedge_t), sizeof(medge_t), 13);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t), 8);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_EDGES], sizeof(dedge_t), sizeof(medge_t), 13);
float surfEdgeCount = (float)header->lumps[LUMP_SURFEDGES].filelen / sizeof(int);
if(surfEdgeCount < MAX_MAP_SURFEDGES) // else it errors out later anyway
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int), 24);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int), 24);
// lighting is a special case, because we keep only 1 byte out of 3
// (=> no colored lighting in soft renderer by default)
@ -1021,14 +647,14 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
hunkSize += size;
}
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), 6);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_TEXINFO], sizeof(texinfo_t), sizeof(mtexinfo_t), 6);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_FACES], sizeof(dface_t), sizeof(msurface_t), 6);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *), 0); // yes, out is indeeed a pointer!
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1, 0);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_LEAFS], sizeof(dleaf_t), sizeof(mleaf_t), 0);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_NODES], sizeof(dnode_t), sizeof(mnode_t), 0);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(model_t), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t)*2, 6);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_TEXINFO], sizeof(texinfo_t), sizeof(mtexinfo_t), 6);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_FACES], sizeof(dface_t), sizeof(msurface_t), 6);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFFACES], sizeof(short), sizeof(msurface_t *), 0); // yes, out is indeeed a pointer!
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], 1, 1, 0);
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), 0);
hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(model_t), 0);
hunkSize += 1048576; // 1MB extra just in case
@ -1037,22 +663,27 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
mod->type = mod_brush;
// load into heap
Mod_LoadVertexes (mod, mod_base, &header->lumps[LUMP_VERTEXES]);
Mod_LoadEdges (mod, mod_base, &header->lumps[LUMP_EDGES]);
Mod_LoadSurfedges (mod, mod_base, &header->lumps[LUMP_SURFEDGES]);
Mod_LoadLighting (mod, mod_base, &header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes (mod, mod_base, &header->lumps[LUMP_PLANES]);
Mod_LoadTexinfo (mod, mod_base, &header->lumps[LUMP_TEXINFO]);
Mod_LoadVertexes (mod->name, &mod->vertexes, &mod->numvertexes, mod_base,
&header->lumps[LUMP_VERTEXES], 8);
Mod_LoadEdges (mod->name, &mod->edges, &mod->numedges,
mod_base, &header->lumps[LUMP_EDGES], 13);
Mod_LoadSurfedges (mod->name, &mod->surfedges, &mod->numsurfedges,
mod_base, &header->lumps[LUMP_SURFEDGES], 24);
Mod_LoadLighting (&mod->lightdata, mod_base, &header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes (mod->name, &mod->planes, &mod->numplanes,
mod_base, &header->lumps[LUMP_PLANES], 6);
Mod_LoadTexinfo (mod->name, &mod->texinfo, &mod->numtexinfo,
mod_base, &header->lumps[LUMP_TEXINFO], (findimage_t)R_FindImage,
r_notexture_mip, 6);
Mod_LoadFaces (mod, mod_base, &header->lumps[LUMP_FACES]);
Mod_LoadMarksurfaces (mod, mod_base, &header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility (mod, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadVisibility (&mod->vis, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadLeafs (mod, mod_base, &header->lumps[LUMP_LEAFS]);
Mod_LoadNodes (mod, mod_base, &header->lumps[LUMP_NODES]);
Mod_LoadNodes (mod->name, mod->planes, mod->numplanes, mod->leafs,
mod->numleafs, &mod->nodes, &mod->numnodes, mod_base,
&header->lumps[LUMP_NODES]);
Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]);
r_numvisleafs = 0;
R_NumberLeafs (mod, mod->nodes);
R_InitSkyBox (mod);
}

View file

@ -36,34 +36,6 @@ static int sc_size;
static surfcache_t *sc_rover;
surfcache_t *sc_base;
/*
===============
R_TextureAnimation
Returns the proper texture for a given time and base texture
===============
*/
static image_t *
R_TextureAnimation (const entity_t *currententity, mtexinfo_t *tex)
{
int c;
if (!tex->next)
return tex->image;
if (!currententity)
return tex->image;
c = currententity->frame % tex->numframes;
while (c && tex)
{
tex = tex->next;
c--;
}
return tex->image;
}
/*
* Color light apply is not required
*/

View file

@ -90,6 +90,7 @@ replacement_t replacements[] = {
{"gl_anisotropic", "r_anisotropic"},
{"gl_lightmap", "r_lighmap"},
{"gl1_polyblend", "gl_polyblend"},
{"gl_cull", "r_cull"},
{"intensity", "gl1_intensity"}
};