Skip to content

Commit d2847f8

Browse files
committed
feat: inline lump model implementation
Signed-off-by: Michael Pollind <[email protected]>
1 parent fbda0cf commit d2847f8

1 file changed

Lines changed: 45 additions & 48 deletions

File tree

source/ref_gl/r_q3bsp.c

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2222
// r_q3bsp.c -- Q3 BSP model loading
2323

2424
#include "r_local.h"
25+
#include "r_model.h"
2526

2627
typedef struct
2728
{
@@ -558,50 +559,6 @@ static void Mod_LoadVertexes_RBSP( const lump_t *l )
558559
}
559560
}
560561

561-
/*
562-
* Mod_LoadSubmodels
563-
*/
564-
static void Mod_LoadSubmodels( const lump_t *l )
565-
{
566-
int i, j, count;
567-
dmodel_t *in;
568-
mmodel_t *out;
569-
mbrushmodel_t *bmodel;
570-
model_t *mod_inline;
571-
572-
in = ( void * )( mod_base + l->fileofs );
573-
if( l->filelen % sizeof( *in ) )
574-
ri.Com_Error( ERR_DROP, "Mod_LoadSubmodels: funny lump size in %s", loadmodel->name );
575-
count = l->filelen / sizeof( *in );
576-
out = Q_CallocAligned(count, 16, sizeof( *out ));
577-
Q_LinkToPool(out, loadmodel->mempool);
578-
579-
mod_inline = Q_CallocAligned(count, 16, sizeof( *mod_inline )+sizeof( *bmodel ));
580-
Q_LinkToPool(mod_inline, loadmodel->mempool);
581-
582-
loadmodel->extradata = bmodel = ( mbrushmodel_t * )( ( uint8_t * )mod_inline + count*sizeof( *mod_inline ) );
583-
584-
loadbmodel = bmodel;
585-
loadbmodel->submodels = out;
586-
loadbmodel->numsubmodels = count;
587-
loadbmodel->inlines = mod_inline;
588-
589-
for( i = 0; i < count; i++, in++, out++ )
590-
{
591-
mod_inline[i].extradata = bmodel + i;
592-
593-
for( j = 0; j < 3; j++ )
594-
{
595-
// spread the mins / maxs by a pixel
596-
out->mins[j] = LittleFloat( in->mins[j] ) - 1;
597-
out->maxs[j] = LittleFloat( in->maxs[j] ) + 1;
598-
}
599-
600-
out->radius = RadiusFromBounds( out->mins, out->maxs );
601-
out->firstface = LittleLong( in->firstface );
602-
out->numfaces = LittleLong( in->numfaces );
603-
}
604-
}
605562

606563
/*
607564
* Mod_LoadShaderrefs
@@ -1864,7 +1821,6 @@ static void Mod_Finish( const lump_t *faces, const lump_t *light, vec3_t gridSiz
18641821
void Mod_LoadQ3BrushModel( model_t *mod, model_t *parent, void *buffer, bspFormatDesc_t *format )
18651822
{
18661823
int i;
1867-
dheader_t *header;
18681824
vec3_t gridSize, ambient, outline;
18691825

18701826
mod->type = mod_brush;
@@ -1876,15 +1832,56 @@ void Mod_LoadQ3BrushModel( model_t *mod, model_t *parent, void *buffer, bspForma
18761832

18771833
mod_bspFormat = format;
18781834

1879-
header = (dheader_t *)buffer;
1880-
mod_base = (uint8_t *)header;
1835+
dheader_t* const header = (dheader_t *)buffer;
1836+
mod_base = (uint8_t *)buffer;
18811837

18821838
// swap all the lumps
18831839
for( i = 0; i < sizeof( dheader_t )/4; i++ )
18841840
( (int *)header )[i] = LittleLong( ( (int *)header )[i] );
18851841

1842+
lump_t* const model_lumps = &header->lumps[LUMP_MODELS];
1843+
1844+
if( model_lumps->filelen % sizeof(dmodel_t) ) {
1845+
ri.Com_Error( ERR_DROP, "Mod_LoadSubmodels: funny lump size in %s", loadmodel->name );
1846+
}
1847+
1848+
1849+
{
1850+
const size_t count = model_lumps->filelen / sizeof( dmodel_t );
1851+
dmodel_t *const q3_model = (void *)( (uint8_t *)buffer + model_lumps->fileofs );
1852+
1853+
uint8_t *const sub_model_mem = Q_CallocAligned( count, 16, sizeof( mbrushmodel_t ) + sizeof( model_t ) );
1854+
mmodel_t *const models = Q_CallocAligned( count, 16, sizeof( mmodel_t ) );
1855+
1856+
Q_LinkToPool( models, loadmodel->mempool );
1857+
Q_LinkToPool( sub_model_mem, loadmodel->mempool );
1858+
1859+
model_t *const inline_models = (model_t *)sub_model_mem;
1860+
mbrushmodel_t *const brush_models = (mbrushmodel_t *)( sub_model_mem + ( sizeof( model_t ) * count ) );
1861+
1862+
loadmodel->extradata = brush_models;
1863+
1864+
loadbmodel = brush_models;
1865+
loadbmodel->submodels = models;
1866+
loadbmodel->numsubmodels = count;
1867+
loadbmodel->inlines = inline_models;
1868+
1869+
for( size_t i = 0; i < count; i++ ) {
1870+
inline_models[i].extradata = &brush_models[i];
1871+
1872+
for( size_t j = 0; j < 3; j++ ) {
1873+
// spread the mins / maxs by a pixel
1874+
models[i].mins[j] = LittleFloat( q3_model[i].mins[j] ) - 1;
1875+
models[i].maxs[j] = LittleFloat( q3_model[i].maxs[j] ) + 1;
1876+
}
1877+
1878+
models[i].radius = RadiusFromBounds( models[i].mins, models[i].maxs );
1879+
models[i].firstface = LittleLong( q3_model[i].firstface );
1880+
models[i].numfaces = LittleLong( q3_model[i].numfaces );
1881+
}
1882+
}
1883+
18861884
// load into heap
1887-
Mod_LoadSubmodels( &header->lumps[LUMP_MODELS] );
18881885
Mod_LoadEntities( &header->lumps[LUMP_ENTITIES], gridSize, ambient, outline );
18891886
Mod_LoadLighting( &header->lumps[LUMP_LIGHTING], &header->lumps[LUMP_FACES] );
18901887
Mod_LoadShaderrefs( &header->lumps[LUMP_SHADERREFS] );

0 commit comments

Comments
 (0)