1999-12-25 05:22:39 +00:00
|
|
|
/*
|
2000-03-24 11:25:06 +00:00
|
|
|
r_efrag.c
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 11:25:06 +00:00
|
|
|
(description)
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 11:25:06 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 11:25:06 +00:00
|
|
|
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.
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 11:25:06 +00:00
|
|
|
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.
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 11:25:06 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
1999-12-25 05:22:39 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-24 11:25:06 +00:00
|
|
|
#include <quakedef.h>
|
|
|
|
#include <r_local.h>
|
2000-01-29 18:46:26 +00:00
|
|
|
#include <console.h>
|
2000-02-07 04:18:27 +00:00
|
|
|
#include <mathlib.h>
|
|
|
|
#include <sys.h>
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
mnode_t *r_pefragtopnode;
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
ENTITY FRAGMENT FUNCTIONS
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
efrag_t **lastlink;
|
|
|
|
|
|
|
|
vec3_t r_emins, r_emaxs;
|
|
|
|
|
|
|
|
entity_t *r_addent;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
R_RemoveEfrags
|
|
|
|
|
|
|
|
Call when removing an object from the world or moving it to another position
|
|
|
|
================
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
void
|
|
|
|
R_RemoveEfrags ( entity_t *ent )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
efrag_t *ef, *old, *walk, **prev;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
ef = ent->efrag;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
while (ef)
|
|
|
|
{
|
|
|
|
prev = &ef->leaf->efrags;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
walk = *prev;
|
|
|
|
if (!walk)
|
|
|
|
break;
|
|
|
|
if (walk == ef)
|
|
|
|
{ // remove this fragment
|
|
|
|
*prev = ef->leafnext;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prev = &walk->leafnext;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
old = ef;
|
|
|
|
ef = ef->entnext;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// put it on the free list
|
|
|
|
old->entnext = cl.free_efrags;
|
|
|
|
cl.free_efrags = old;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
|
|
|
ent->efrag = NULL;
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
R_SplitEntityOnNode
|
|
|
|
===================
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
void
|
|
|
|
R_SplitEntityOnNode ( mnode_t *node )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
efrag_t *ef;
|
|
|
|
mplane_t *splitplane;
|
|
|
|
mleaf_t *leaf;
|
|
|
|
int sides;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (node->contents == CONTENTS_SOLID)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// add an efrag if the node is a leaf
|
|
|
|
|
|
|
|
if ( node->contents < 0)
|
|
|
|
{
|
|
|
|
if (!r_pefragtopnode)
|
|
|
|
r_pefragtopnode = node;
|
|
|
|
|
|
|
|
leaf = (mleaf_t *)node;
|
|
|
|
|
|
|
|
// grab an efrag off the free list
|
|
|
|
ef = cl.free_efrags;
|
|
|
|
if (!ef)
|
|
|
|
{
|
|
|
|
Con_Printf ("Too many efrags!\n");
|
|
|
|
return; // no free fragments...
|
|
|
|
}
|
|
|
|
cl.free_efrags = cl.free_efrags->entnext;
|
|
|
|
|
|
|
|
ef->entity = r_addent;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
|
|
|
// add the entity link
|
1999-12-25 05:22:39 +00:00
|
|
|
*lastlink = ef;
|
|
|
|
lastlink = &ef->entnext;
|
|
|
|
ef->entnext = NULL;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// set the leaf links
|
|
|
|
ef->leaf = leaf;
|
|
|
|
ef->leafnext = leaf->efrags;
|
|
|
|
leaf->efrags = ef;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// NODE_MIXED
|
|
|
|
|
|
|
|
splitplane = node->plane;
|
|
|
|
sides = BOX_ON_PLANE_SIDE(r_emins, r_emaxs, splitplane);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (sides == 3)
|
|
|
|
{
|
|
|
|
// split on this plane
|
|
|
|
// if this is the first splitter of this bmodel, remember it
|
|
|
|
if (!r_pefragtopnode)
|
|
|
|
r_pefragtopnode = node;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// recurse down the contacted sides
|
|
|
|
if (sides & 1)
|
|
|
|
R_SplitEntityOnNode (node->children[0]);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (sides & 2)
|
|
|
|
R_SplitEntityOnNode (node->children[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
R_SplitEntityOnNode2
|
|
|
|
===================
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
void
|
|
|
|
R_SplitEntityOnNode2 ( mnode_t *node )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
mplane_t *splitplane;
|
|
|
|
int sides;
|
|
|
|
|
|
|
|
if (node->visframe != r_visframecount)
|
|
|
|
return;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (node->contents < 0)
|
|
|
|
{
|
|
|
|
if (node->contents != CONTENTS_SOLID)
|
2000-08-20 13:33:48 +00:00
|
|
|
r_pefragtopnode = node; // we've reached a non-solid leaf, so it's
|
|
|
|
// visible and not BSP clipped
|
1999-12-25 05:22:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
splitplane = node->plane;
|
|
|
|
sides = BOX_ON_PLANE_SIDE(r_emins, r_emaxs, splitplane);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (sides == 3)
|
|
|
|
{
|
|
|
|
// remember first splitter
|
|
|
|
r_pefragtopnode = node;
|
|
|
|
return;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// not split yet; recurse down the contacted side
|
|
|
|
if (sides & 1)
|
|
|
|
R_SplitEntityOnNode2 (node->children[0]);
|
|
|
|
else
|
|
|
|
R_SplitEntityOnNode2 (node->children[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
R_AddEfrags
|
|
|
|
===========
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
void
|
|
|
|
R_AddEfrags ( entity_t *ent )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
model_t *entmodel;
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (!ent->model)
|
|
|
|
return;
|
|
|
|
|
2000-02-07 04:18:27 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
if (ent == &r_worldentity)
|
2000-02-07 04:18:27 +00:00
|
|
|
#else
|
|
|
|
if (ent == cl_entities)
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
return; // never add the world
|
|
|
|
|
|
|
|
r_addent = ent;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
lastlink = &ent->efrag;
|
|
|
|
r_pefragtopnode = NULL;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
entmodel = ent->model;
|
|
|
|
|
|
|
|
for (i=0 ; i<3 ; i++)
|
|
|
|
{
|
|
|
|
r_emins[i] = ent->origin[i] + entmodel->mins[i];
|
|
|
|
r_emaxs[i] = ent->origin[i] + entmodel->maxs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
R_SplitEntityOnNode (cl.worldmodel->nodes);
|
|
|
|
|
|
|
|
ent->topnode = r_pefragtopnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
R_StoreEfrags
|
|
|
|
|
|
|
|
// FIXME: a lot of this goes away with edge-based
|
|
|
|
================
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
void
|
|
|
|
R_StoreEfrags ( efrag_t **ppefrag )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
entity_t *pent;
|
|
|
|
model_t *clmodel;
|
|
|
|
efrag_t *pefrag;
|
|
|
|
|
|
|
|
|
|
|
|
while ((pefrag = *ppefrag) != NULL)
|
|
|
|
{
|
|
|
|
pent = pefrag->entity;
|
|
|
|
clmodel = pent->model;
|
|
|
|
|
|
|
|
switch (clmodel->type)
|
|
|
|
{
|
|
|
|
case mod_alias:
|
|
|
|
case mod_brush:
|
|
|
|
case mod_sprite:
|
|
|
|
pent = pefrag->entity;
|
|
|
|
|
|
|
|
if ((pent->visframe != r_framecount) &&
|
|
|
|
(cl_numvisedicts < MAX_VISEDICTS))
|
|
|
|
{
|
|
|
|
cl_visedicts[cl_numvisedicts++] = *pent;
|
|
|
|
|
|
|
|
// mark that we've recorded this entity for this frame
|
|
|
|
pent->visframe = r_framecount;
|
|
|
|
}
|
|
|
|
|
|
|
|
ppefrag = &pefrag->leafnext;
|
|
|
|
break;
|
|
|
|
|
2000-03-19 15:59:51 +00:00
|
|
|
default:
|
1999-12-25 05:22:39 +00:00
|
|
|
Sys_Error ("R_StoreEfrags: Bad entity type %d\n", clmodel->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|