2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
gl_refrag.c - store entity fragments
|
|
|
|
Copyright (C) 2010 Uncle Mike
|
|
|
|
|
|
|
|
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 3 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.
|
|
|
|
*/
|
|
|
|
|
2019-03-17 17:14:53 +01:00
|
|
|
#include "common.h"
|
2018-04-13 18:23:45 +02:00
|
|
|
#include "entity_types.h"
|
|
|
|
#include "studio.h"
|
2019-03-06 14:23:33 +01:00
|
|
|
#include "world.h" // BOX_ON_PLANE_SIDE
|
2019-03-17 17:14:53 +01:00
|
|
|
#include "client.h"
|
2020-02-10 11:07:06 +01:00
|
|
|
#include "xash3d_mathlib.h"
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
ENTITY FRAGMENT FUNCTIONS
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static efrag_t **lastlink;
|
|
|
|
static mnode_t *r_pefragtopnode;
|
|
|
|
static vec3_t r_emins, r_emaxs;
|
|
|
|
static cl_entity_t *r_addent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
R_SplitEntityOnNode
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
static void R_SplitEntityOnNode( mnode_t *node )
|
|
|
|
{
|
|
|
|
efrag_t *ef;
|
|
|
|
mleaf_t *leaf;
|
|
|
|
int sides;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
if( node->contents == CONTENTS_SOLID )
|
|
|
|
return;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02: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
|
2019-03-17 17:14:53 +01:00
|
|
|
ef = clgame.free_efrags;
|
2018-04-13 18:23:45 +02:00
|
|
|
if( !ef )
|
|
|
|
{
|
2019-03-17 17:14:53 +01:00
|
|
|
Con_Printf( S_ERROR "too many efrags!\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
return; // no free fragments...
|
|
|
|
}
|
|
|
|
|
2019-03-17 17:14:53 +01:00
|
|
|
clgame.free_efrags = ef->entnext;
|
2018-04-13 18:23:45 +02:00
|
|
|
ef->entity = r_addent;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
|
|
|
// add the entity link
|
2018-04-13 18:23:45 +02:00
|
|
|
*lastlink = ef;
|
|
|
|
lastlink = &ef->entnext;
|
|
|
|
ef->entnext = NULL;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// set the leaf links
|
|
|
|
ef->leaf = leaf;
|
|
|
|
ef->leafnext = leaf->efrags;
|
|
|
|
leaf->efrags = ef;
|
|
|
|
return;
|
|
|
|
}
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// NODE_MIXED
|
2018-06-19 15:22:30 +02:00
|
|
|
sides = BOX_ON_PLANE_SIDE( r_emins, r_emaxs, node->plane );
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02: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;
|
|
|
|
}
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// recurse down the contacted sides
|
|
|
|
if( sides & 1 ) R_SplitEntityOnNode( node->children[0] );
|
|
|
|
if( sides & 2 ) R_SplitEntityOnNode( node->children[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
R_AddEfrags
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void R_AddEfrags( cl_entity_t *ent )
|
|
|
|
{
|
2018-10-04 08:08:48 +02:00
|
|
|
matrix3x4 transform;
|
|
|
|
vec3_t outmins, outmaxs;
|
2018-04-13 18:23:45 +02:00
|
|
|
int i;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
if( !ent->model )
|
|
|
|
return;
|
|
|
|
|
|
|
|
r_addent = ent;
|
|
|
|
lastlink = &ent->efrag;
|
|
|
|
r_pefragtopnode = NULL;
|
|
|
|
|
2018-10-04 08:08:48 +02:00
|
|
|
// handle entity rotation for right bbox expanding
|
|
|
|
Matrix3x4_CreateFromEntity( transform, ent->angles, vec3_origin, 1.0f );
|
|
|
|
Matrix3x4_TransformAABB( transform, ent->model->mins, ent->model->maxs, outmins, outmaxs );
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
{
|
2018-10-04 08:08:48 +02:00
|
|
|
r_emins[i] = ent->origin[i] + outmins[i];
|
|
|
|
r_emaxs[i] = ent->origin[i] + outmaxs[i];
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2019-03-17 17:14:53 +01:00
|
|
|
R_SplitEntityOnNode( cl.worldmodel->nodes );
|
2018-04-13 18:23:45 +02:00
|
|
|
ent->topnode = r_pefragtopnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
R_StoreEfrags
|
|
|
|
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void R_StoreEfrags( efrag_t **ppefrag, int framecount )
|
|
|
|
{
|
|
|
|
cl_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_studio:
|
|
|
|
case mod_sprite:
|
|
|
|
if( pent->visframe != framecount )
|
|
|
|
{
|
2019-03-17 17:14:53 +01:00
|
|
|
if( CL_AddVisibleEntity( pent, ET_FRAGMENTED ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
// mark that we've recorded this entity for this frame
|
2019-03-17 17:14:53 +01:00
|
|
|
pent->curstate.messagenum = cl.parsecount;
|
2018-04-13 18:23:45 +02:00
|
|
|
pent->visframe = framecount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ppefrag = &pefrag->leafnext;
|
|
|
|
break;
|
2021-01-03 02:28:45 +01:00
|
|
|
default:
|
2018-04-13 18:23:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-23 19:49:46 +01:00
|
|
|
}
|