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
|
|
|
|
|
|
|
void
|
2023-07-27 06:43:47 +00:00
|
|
|
R_MarkLeavesPVS (visstate_t *visstate, const set_t *pvs)
|
2012-01-03 12:04:27 +00:00
|
|
|
{
|
2023-07-27 06:43:47 +00:00
|
|
|
int visframecount = ++visstate->visframecount;
|
|
|
|
auto brush = visstate->brush;
|
2023-06-28 14:44:38 +00:00
|
|
|
auto node_visframes = visstate->node_visframes;
|
|
|
|
auto leaf_visframes = visstate->leaf_visframes;
|
|
|
|
auto face_visframes = visstate->face_visframes;
|
2023-08-05 17:32:11 +00:00
|
|
|
// If you're looking for the bug with the easy teleporter in the start map,
|
|
|
|
// you're looking in the wrong place: it's in either qfvis or qfbsp when
|
|
|
|
// doing water vis (though not specific to water vis, it's either the
|
|
|
|
// portal generation or the vising of the map).
|
2023-07-27 06:43:47 +00:00
|
|
|
for (auto li = set_first (pvs); li; li = set_next (li)) {
|
|
|
|
unsigned i = li->element;
|
2023-08-05 15:21:54 +00:00
|
|
|
auto leaf = &brush->leafs[i + 1];
|
|
|
|
int c;
|
|
|
|
if ((c = leaf->nummarksurfaces)) {
|
|
|
|
auto mark = brush->marksurfaces + leaf->firstmarksurface;
|
|
|
|
do {
|
|
|
|
face_visframes[*mark - brush->surfaces] = visframecount;
|
|
|
|
mark++;
|
|
|
|
} while (--c);
|
|
|
|
}
|
|
|
|
leaf_visframes[i + 1] = visframecount;
|
|
|
|
int node_id = brush->leaf_parents[leaf - brush->leafs];
|
|
|
|
while (node_id >= 0) {
|
|
|
|
if (node_visframes[node_id] == visframecount)
|
|
|
|
break;
|
|
|
|
node_visframes[node_id] = visframecount;
|
|
|
|
node_id = brush->node_parents[node_id];
|
2023-07-27 06:43:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_MarkLeaves (visstate_t *visstate, const mleaf_t *viewleaf)
|
|
|
|
{
|
2023-06-28 14:44:38 +00:00
|
|
|
auto brush = visstate->brush;
|
2023-08-05 02:51:01 +00:00
|
|
|
set_t vis = SET_STATIC_INIT (brush->visleafs, alloca);
|
2012-01-03 12:04:27 +00:00
|
|
|
|
2023-06-28 14:44:38 +00:00
|
|
|
if (visstate->viewleaf == viewleaf && !r_novis)
|
2012-01-03 12:04:27 +00:00
|
|
|
return;
|
|
|
|
|
2023-06-28 14:44:38 +00:00
|
|
|
visstate->viewleaf = viewleaf;
|
2022-05-05 05:58:47 +00:00
|
|
|
if (!viewleaf)
|
2012-01-29 07:09:35 +00:00
|
|
|
return;
|
2012-01-03 12:04:27 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (r_novis) {
|
2023-06-28 14:44:38 +00:00
|
|
|
// so vis will be recalculated when novis gets turned off
|
|
|
|
visstate->viewleaf = 0;
|
2023-08-05 02:51:01 +00:00
|
|
|
// force use of default vis (full visibility)
|
|
|
|
viewleaf = brush->leafs;
|
2023-06-28 14:44:38 +00:00
|
|
|
}
|
2023-08-05 02:51:01 +00:00
|
|
|
Mod_LeafPVS_set (viewleaf, brush, 0xff, &vis);
|
|
|
|
R_MarkLeavesPVS (visstate, &vis);
|
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 *
|
2022-10-25 10:36:09 +00:00
|
|
|
R_TextureAnimation (int frame, msurface_t *surf)
|
2012-01-08 01:21:08 +00:00
|
|
|
{
|
|
|
|
texture_t *base = surf->texinfo->texture;
|
|
|
|
int count, relative;
|
|
|
|
|
2022-10-25 10:36:09 +00:00
|
|
|
if (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;
|
|
|
|
}
|