2012-01-03 12:04:27 +00:00
|
|
|
/*
|
|
|
|
r_bsp.c
|
|
|
|
|
|
|
|
Common bsp rendering.
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include "strings.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
2021-07-26 02:15:51 +00:00
|
|
|
#include "QF/set.h"
|
2012-01-08 01:21:08 +00:00
|
|
|
#include "QF/sys.h"
|
2012-01-03 12:04:27 +00:00
|
|
|
|
2022-03-29 05:40:48 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2012-01-03 12:04:27 +00:00
|
|
|
|
2012-01-03 14:17:49 +00:00
|
|
|
static mleaf_t *r_oldviewleaf;
|
2021-07-26 02:15:51 +00:00
|
|
|
static set_t *solid;
|
2012-01-03 12:04:27 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
R_MarkLeaves (void)
|
|
|
|
{
|
2021-07-26 02:15:51 +00:00
|
|
|
set_t *vis;
|
2012-01-03 12:04:27 +00:00
|
|
|
int c;
|
|
|
|
mleaf_t *leaf;
|
|
|
|
mnode_t *node;
|
|
|
|
msurface_t **mark;
|
2022-03-14 06:27:43 +00:00
|
|
|
mod_brush_t *brush = &r_refdef.worldmodel->brush;
|
2012-01-03 12:04:27 +00:00
|
|
|
|
2022-03-14 06:27:43 +00:00
|
|
|
if (r_oldviewleaf == r_refdef.viewleaf && !r_novis->int_val)
|
2012-01-03 12:04:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
r_visframecount++;
|
2022-03-14 06:27:43 +00:00
|
|
|
r_oldviewleaf = r_refdef.viewleaf;
|
|
|
|
if (!r_refdef.viewleaf)
|
2012-01-29 07:09:35 +00:00
|
|
|
return;
|
2012-01-03 12:04:27 +00:00
|
|
|
|
|
|
|
if (r_novis->int_val) {
|
2012-01-03 14:17:49 +00:00
|
|
|
r_oldviewleaf = 0; // so vis will be recalcualted when novis gets
|
|
|
|
// turned off
|
2021-07-26 02:15:51 +00:00
|
|
|
if (!solid) {
|
|
|
|
solid = set_new ();
|
|
|
|
set_everything (solid);
|
|
|
|
}
|
2012-01-03 12:04:27 +00:00
|
|
|
vis = solid;
|
|
|
|
} else
|
2022-03-14 06:27:43 +00:00
|
|
|
vis = Mod_LeafPVS (r_refdef.viewleaf, r_refdef.worldmodel);
|
2012-01-03 12:04:27 +00:00
|
|
|
|
2021-07-27 03:32:40 +00:00
|
|
|
for (unsigned i = 0; i < brush->visleafs; i++) {
|
2021-07-26 02:15:51 +00:00
|
|
|
if (set_is_member (vis, i)) {
|
2021-02-03 02:41:38 +00:00
|
|
|
leaf = &brush->leafs[i + 1];
|
2012-01-03 12:04:27 +00:00
|
|
|
if ((c = leaf->nummarksurfaces)) {
|
|
|
|
mark = leaf->firstmarksurface;
|
|
|
|
do {
|
|
|
|
(*mark)->visframe = r_visframecount;
|
|
|
|
mark++;
|
|
|
|
} while (--c);
|
|
|
|
}
|
2021-02-03 02:41:38 +00:00
|
|
|
leaf->visframe = r_visframecount;
|
|
|
|
node = brush->leaf_parents[leaf - brush->leafs];
|
|
|
|
while (node) {
|
2012-01-03 12:04:27 +00:00
|
|
|
if (node->visframe == r_visframecount)
|
|
|
|
break;
|
|
|
|
node->visframe = r_visframecount;
|
2021-02-03 02:41:38 +00:00
|
|
|
node = brush->node_parents[node - brush->nodes];
|
|
|
|
}
|
2012-01-03 12:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-08 01:21:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
R_TextureAnimation
|
|
|
|
|
|
|
|
Returns the proper texture for a given time and base texture
|
|
|
|
*/
|
|
|
|
texture_t *
|
2021-07-22 06:39:28 +00:00
|
|
|
R_TextureAnimation (const entity_t *entity, msurface_t *surf)
|
2012-01-08 01:21:08 +00:00
|
|
|
{
|
|
|
|
texture_t *base = surf->texinfo->texture;
|
|
|
|
int count, relative;
|
|
|
|
|
2021-07-22 06:39:28 +00:00
|
|
|
if (entity->animation.frame) {
|
2012-01-08 01:21:08 +00:00
|
|
|
if (base->alternate_anims)
|
|
|
|
base = base->alternate_anims;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!base->anim_total)
|
|
|
|
return base;
|
|
|
|
|
2022-03-17 04:09:20 +00:00
|
|
|
relative = (int) (r_data->realtime * 10) % base->anim_total;
|
2012-01-08 01:21:08 +00:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
while (base->anim_min > relative || base->anim_max <= relative) {
|
|
|
|
base = base->anim_next;
|
|
|
|
if (!base)
|
|
|
|
Sys_Error ("R_TextureAnimation: broken cycle");
|
|
|
|
if (++count > 100)
|
|
|
|
Sys_Error ("R_TextureAnimation: infinite cycle");
|
|
|
|
}
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|