std::vector<bspModel_t> bspModels

This commit is contained in:
Garux 2021-09-24 12:11:11 +03:00
parent 0e0a295330
commit 6e2fc92576
18 changed files with 180 additions and 133 deletions

View File

@ -1025,8 +1025,6 @@ int repackBSPMain( Args& args ){
free( bspModels );
bspModels = NULL;
Sys_Printf( "freed bspModels\n" );
//numBSPModels = 0;
//allocatedBSPModels = 0;
}
if ( bspShaders != 0 ) {
Sys_Printf( "freed bspShaders\n" );

View File

@ -90,11 +90,6 @@ static void autocaulk_write(){
*/
static void ProcessAdvertisements( void ) {
const char* modelKey;
int modelNum;
bspModel_t* adModel;
bspDrawSurface_t* adSurface;
Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" );
for ( const auto& e : entities ) {
@ -102,7 +97,7 @@ static void ProcessAdvertisements( void ) {
/* is an advertisement? */
if ( e.classname_is( "advertisement" ) ) {
modelKey = e.valueForKey( "model" );
const char* modelKey = e.valueForKey( "model" );
if ( strlen( modelKey ) > MAX_QPATH - 1 ) {
Error( "Model Key for entity exceeds ad struct string length." );
@ -112,27 +107,25 @@ static void ProcessAdvertisements( void ) {
bspAds[numBSPAds].cellId = e.intForKey( "cellId" );
strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
modelKey++;
modelNum = atoi( modelKey );
adModel = &bspModels[modelNum];
const bspModel_t& adModel = bspModels[atoi( modelKey + 1 )];
if ( adModel->numBSPSurfaces != 1 ) {
if ( adModel.numBSPSurfaces != 1 ) {
Error( "Ad cell id %d has more than one surface.", bspAds[numBSPAds].cellId );
}
adSurface = &bspDrawSurfaces[adModel->firstBSPSurface];
const bspDrawSurface_t& adSurface = bspDrawSurfaces[adModel.firstBSPSurface];
// store the normal for use at run time.. all ad verts are assumed to
// have identical normals (because they should be a simple rectangle)
// so just use the first vert's normal
bspAds[numBSPAds].normal = bspDrawVerts[adSurface->firstVert].normal;
bspAds[numBSPAds].normal = bspDrawVerts[adSurface.firstVert].normal;
// store the ad quad for quick use at run time
if ( adSurface->surfaceType == MST_PATCH ) {
int v0 = adSurface->firstVert + adSurface->patchHeight - 1;
int v1 = adSurface->firstVert + adSurface->numVerts - 1;
int v2 = adSurface->firstVert + adSurface->numVerts - adSurface->patchWidth;
int v3 = adSurface->firstVert;
if ( adSurface.surfaceType == MST_PATCH ) {
int v0 = adSurface.firstVert + adSurface.patchHeight - 1;
int v1 = adSurface.firstVert + adSurface.numVerts - 1;
int v2 = adSurface.firstVert + adSurface.numVerts - adSurface.patchWidth;
int v3 = adSurface.firstVert;
bspAds[numBSPAds].rect[0] = bspDrawVerts[v0].xyz;
bspAds[numBSPAds].rect[1] = bspDrawVerts[v1].xyz;
bspAds[numBSPAds].rect[2] = bspDrawVerts[v2].xyz;
@ -576,7 +569,7 @@ void ProcessModels( void ){
}
/* process the model */
Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
Sys_FPrintf( SYS_VRB, "############### model %zu ###############\n", bspModels.size() );
if ( mapEntityNum == 0 ) {
ProcessWorldModel();
}
@ -591,7 +584,7 @@ void ProcessModels( void ){
/* restore -v setting */
verbose = oldVerbose;
Sys_FPrintf( SYS_VRB, "%9i bspModels in total\n", numBSPModels );
Sys_FPrintf( SYS_VRB, "%9zu bspModels in total\n", bspModels.size() );
/* write fogs */
EmitFogs();

View File

@ -141,6 +141,19 @@ void SwapBlock( int *block, int size ){
block[ i ] = LittleLong( block[ i ] );
}
/*
SwapBlock()
if all values are 32 bits, this can be used to swap everything
*/
template<typename T>
void SwapBlock( std::vector<T>& block ){
const size_t size = ( sizeof( T ) * block.size() ) >> 2; // get size in integers
/* swap */
int *intptr = reinterpret_cast<int *>( block.data() );
for ( size_t i = 0; i < size; ++i )
intptr[ i ] = LittleLong( intptr[ i ] );
}
/*
@ -153,7 +166,7 @@ void SwapBSPFile( void ){
shaderInfo_t *si;
/* models */
SwapBlock( (int*) bspModels, numBSPModels * sizeof( bspModels[ 0 ] ) );
SwapBlock( bspModels );
/* shaders (don't swap the name) */
for ( i = 0; i < numBSPShaders; i++ )
@ -337,7 +350,7 @@ void AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, in
SafeWrite( file, data, length );
/* write padding zeros */
SafeWrite( file, (const byte[3]){ 0, 0, 0 }, ( ( length + 3 ) & ~3 ) - length );
SafeWrite( file, std::array<byte, 3>{}.data(), ( ( length + 3 ) & ~3 ) - length );
}
@ -450,8 +463,8 @@ void PrintBSPFileSizes( void ){
Sys_Printf( "Abstracted BSP file components (*actual sizes may differ)\n" );
/* print various and sundry bits */
Sys_Printf( "%9d models %9d\n",
numBSPModels, (int) ( numBSPModels * sizeof( bspModel_t ) ) );
Sys_Printf( "%9zu models %9zu\n",
bspModels.size(), bspModels.size() * sizeof( bspModels[0] ) );
Sys_Printf( "%9d shaders %9d\n",
numBSPShaders, (int) ( numBSPShaders * sizeof( bspShader_t ) ) );
Sys_Printf( "%9d brushes %9d\n",

View File

@ -0,0 +1,81 @@
/* -------------------------------------------------------------------------------
Copyright (C) 1999-2007 id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
GtkRadiant 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.
GtkRadiant 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 GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
----------------------------------------------------------------------------------
This code has been altered significantly from its original form, to support
several games based on the Quake III Arena engine, in the form of "Q3Map2."
------------------------------------------------------------------------------- */
#pragma once
/* dependencies */
#include "q3map2.h"
/*
AddLump()
adds a lump to an outgoing bsp file
*/
template<typename T>
void AddLump( FILE *file, bspLump_t& lump, const std::vector<T>& data ){
const int length = sizeof( T ) * data.size();
/* add lump to bsp file header */
lump.offset = LittleLong( ftell( file ) );
lump.length = LittleLong( length );
/* write lump to file */
SafeWrite( file, data.data(), length );
/* write padding zeros */
SafeWrite( file, std::array<byte, 3>{}.data(), ( ( length + 3 ) & ~3 ) - length );
}
/*
CopyLump()
copies a bsp file lump into a destination buffer
*/
template<typename T>
void CopyLump( bspHeader_t *header, int lump, std::vector<T>& data ){
/* get lump length and offset */
const int length = header->lumps[ lump ].length;
const int offset = header->lumps[ lump ].offset;
const int size = sizeof( T );
/* handle erroneous cases */
if ( length == 0 ) {
return;
}
if ( length % size ) {
if ( force ) {
Sys_Warning( "CopyLump: odd lump size (%d) in lump %d\n", length, lump );
return;
}
else{
Error( "CopyLump: odd lump size (%d) in lump %d", length, lump );
}
}
/* copy block of memory and return */
data = { ( T* )( (byte*) header + offset ), ( T* )( (byte*) header + offset + length ) };
}

View File

@ -30,6 +30,7 @@
/* dependencies */
#include "q3map2.h"
#include "bspfile_abstract.h"
@ -434,7 +435,7 @@ void LoadIBSPFile( const char *filename ){
/* load/convert lumps */
numBSPShaders = CopyLump_Allocate( (bspHeader_t*) header, LUMP_SHADERS, (void **) &bspShaders, sizeof( bspShader_t ), &allocatedBSPShaders );
numBSPModels = CopyLump_Allocate( (bspHeader_t*) header, LUMP_MODELS, (void **) &bspModels, sizeof( bspModel_t ), &allocatedBSPModels );
CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels );
numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes );
@ -558,7 +559,7 @@ void WriteIBSPFile( const char *filename ){
AddBrushSidesLump( file, header );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_MODELS, bspModels, numBSPModels * sizeof( bspModel_t ) );
AddLump( file, header->lumps[LUMP_MODELS], bspModels );
AddDrawVertsLump( file, header );
AddDrawSurfacesLump( file, header );
AddLump( file, (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, numBSPVisBytes );

View File

@ -30,6 +30,7 @@
/* dependencies */
#include "q3map2.h"
#include "bspfile_abstract.h"
@ -225,7 +226,7 @@ void LoadRBSPFile( const char *filename ){
/* load/convert lumps */
numBSPShaders = CopyLump_Allocate( (bspHeader_t*) header, LUMP_SHADERS, (void **) &bspShaders, sizeof( bspShader_t ), &allocatedBSPShaders );
numBSPModels = CopyLump_Allocate( (bspHeader_t*) header, LUMP_MODELS, (void **) &bspModels, sizeof( bspModel_t ), &allocatedBSPModels );
CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels );
numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes );
@ -311,7 +312,7 @@ void WriteRBSPFile( const char *filename ){
AddLump( file, (bspHeader_t*) header, LUMP_BRUSHSIDES, bspBrushSides, numBSPBrushSides * sizeof( bspBrushSides[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_MODELS, bspModels, numBSPModels * sizeof( bspModel_t ) );
AddLump( file, header->lumps[LUMP_MODELS], bspModels );
AddLump( file, (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVerts[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, numBSPVisBytes );

View File

@ -41,7 +41,7 @@
int numLightmapsASE = 0;
static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const int* lmIndices ){
static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const int* lmIndices ){
int i, v, face, a, b, c;
bspDrawVert_t *dv;
char name[ 1024 ];
@ -181,17 +181,14 @@ static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSur
exports a bsp model to an ase chunk
*/
static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, const Vector3& origin, const int* lmIndices ){
int i, s;
bspDrawSurface_t *ds;
static void ConvertModel( FILE *f, int modelNum, const Vector3& origin, const int* lmIndices ){
const bspModel_t& model = bspModels[ modelNum ];
/* go through each drawsurf in the model */
for ( i = 0; i < model->numBSPSurfaces; i++ )
for ( int i = 0; i < model.numBSPSurfaces; i++ )
{
s = i + model->firstBSPSurface;
ds = &bspDrawSurfaces[ s ];
ConvertSurface( f, model, modelNum, ds, s, origin, lmIndices );
const int s = model.firstBSPSurface + i;
ConvertSurface( f, modelNum, &bspDrawSurfaces[ s ], s, origin, lmIndices );
}
}
@ -328,7 +325,6 @@ int ConvertBSPToASE( char *bspName ){
int modelNum;
FILE *f;
bspShader_t *shader;
bspModel_t *model;
entity_t *e;
int lmIndices[ numBSPShaders ];
@ -394,10 +390,9 @@ int ConvertBSPToASE( char *bspName ){
}
modelNum = atoi( key + 1 );
}
model = &bspModels[ modelNum ];
/* convert model */
ConvertModel( f, model, modelNum, e->vectorForKey( "origin" ), lmIndices );
ConvertModel( f, modelNum, e->vectorForKey( "origin" ), lmIndices );
}
/* close the file and return */

View File

@ -478,10 +478,10 @@ int ScaleBSPMain( Args& args ){
}
/* scale models */
for ( i = 0; i < numBSPModels; i++ )
for ( auto& model : bspModels )
{
bspModels[ i ].minmax.mins *= scale;
bspModels[ i ].minmax.maxs *= scale;
model.minmax.mins *= scale;
model.minmax.maxs *= scale;
}
/* scale nodes */
@ -647,10 +647,10 @@ int ShiftBSPMain( Args& args ){
}
/* shift models */
for ( i = 0; i < numBSPModels; i++ )
for ( auto& model : bspModels )
{
bspModels[ i ].minmax.mins += shift;
bspModels[ i ].minmax.maxs += shift;
model.minmax.mins += shift;
model.minmax.maxs += shift;
}
/* shift nodes */
@ -726,7 +726,7 @@ void PseudoCompileBSP( bool need_tree ){
}
/* process the model */
Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
Sys_FPrintf( SYS_VRB, "############### model %zu ###############\n", bspModels.size() );
BeginModel();
entity->firstDrawSurf = numMapDrawSurfs;

View File

@ -155,7 +155,7 @@ static void write_json( const char *directory ){
}
{
doc.RemoveAllMembers();
for_indexed( auto&& model : Span( bspModels, numBSPModels ) ){
for_indexed( const auto& model : bspModels ){
rapidjson::Value value( rapidjson::kObjectType );
{
rapidjson::Value minmax( rapidjson::kObjectType );
@ -390,9 +390,8 @@ static void read_json( const char *directory ){
}
{
const auto doc = load_json( StringOutputStream( 256 )( directory, "models.json" ) );
static std::vector<bspModel_t> items;
for( auto&& obj : doc.GetObj() ){
auto&& item = items.emplace_back();
auto&& item = bspModels.emplace_back();
value_to( obj.value["minmax"].GetObj().operator[]("mins"), item.minmax.mins );
value_to( obj.value["minmax"].GetObj().operator[]("maxs"), item.minmax.maxs );
item.firstBSPSurface = obj.value["firstBSPSurface"].GetInt();
@ -400,8 +399,6 @@ static void read_json( const char *directory ){
item.firstBSPBrush = obj.value["firstBSPBrush"].GetInt();
item.numBSPBrushes = obj.value["numBSPBrushes"].GetInt();
}
bspModels = items.data();
numBSPModels = items.size();
}
{
const auto doc = load_json( StringOutputStream( 256 )( directory, "planes.json" ) );

View File

@ -816,7 +816,7 @@ static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, const Vector3&
exports a bsp model to a map file
*/
static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, const Vector3& origin, bool brushPrimitives ){
static void ConvertModel( FILE *f, const bspModel_t& model, const Vector3& origin, bool brushPrimitives ){
int i, num;
bspBrush_t *brush;
bspDrawSurface_t *ds;
@ -842,9 +842,9 @@ static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, const Vector
}
/* go through each brush in the model */
for ( i = 0; i < model->numBSPBrushes; i++ )
for ( i = 0; i < model.numBSPBrushes; i++ )
{
num = i + model->firstBSPBrush;
num = i + model.firstBSPBrush;
brush = &bspBrushes[ num ];
if( fast ){
ConvertBrushFast( f, num, brush, origin, brushPrimitives );
@ -855,9 +855,9 @@ static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, const Vector
}
/* go through each drawsurf in the model */
for ( i = 0; i < model->numBSPSurfaces; i++ )
for ( i = 0; i < model.numBSPSurfaces; i++ )
{
num = i + model->firstBSPSurface;
num = i + model.firstBSPSurface;
ds = &bspDrawSurfaces[ num ];
/* we only love patches */
@ -908,7 +908,6 @@ static void ConvertEPairs( FILE *f, entity_t *e, bool skip_origin ){
int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
int modelNum;
FILE *f;
bspModel_t *model;
entity_t *e;
const char *value;
@ -956,11 +955,8 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
/* only handle bsp models */
if ( modelNum >= 0 ) {
/* get model */
model = &bspModels[ modelNum ];
/* convert model */
ConvertModel( f, model, modelNum, e->vectorForKey( "origin" ), brushPrimitives );
ConvertModel( f, bspModels[ modelNum ], e->vectorForKey( "origin" ), brushPrimitives );
}
/* end entity */

View File

@ -44,7 +44,7 @@ int lastLightmap = -1;
int objVertexCount = 0;
int objLastShaderNum = -1;
static void ConvertSurfaceToOBJ( FILE *f, bspModel_t *model, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const int* lmIndices ){
static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const int* lmIndices ){
int i, v, a, b, c;
bspDrawVert_t *dv;
@ -127,17 +127,14 @@ static void ConvertSurfaceToOBJ( FILE *f, bspModel_t *model, int modelNum, bspDr
exports a bsp model to an ase chunk
*/
static void ConvertModelToOBJ( FILE *f, bspModel_t *model, int modelNum, const Vector3& origin, const int* lmIndices ){
int i, s;
bspDrawSurface_t *ds;
static void ConvertModelToOBJ( FILE *f, int modelNum, const Vector3& origin, const int* lmIndices ){
const bspModel_t& model = bspModels[ modelNum ];
/* go through each drawsurf in the model */
for ( i = 0; i < model->numBSPSurfaces; i++ )
for ( int i = 0; i < model.numBSPSurfaces; i++ )
{
s = i + model->firstBSPSurface;
ds = &bspDrawSurfaces[ s ];
ConvertSurfaceToOBJ( f, model, modelNum, ds, s, origin, lmIndices );
const int s = model.firstBSPSurface + i;
ConvertSurfaceToOBJ( f, modelNum, &bspDrawSurfaces[ s ], s, origin, lmIndices );
}
}
@ -299,7 +296,6 @@ int ConvertBSPToOBJ( char *bspName ){
int modelNum;
FILE *f, *fmtl;
bspShader_t *shader;
bspModel_t *model;
entity_t *e;
const char *key;
int lmIndices[ numBSPShaders ];
@ -355,10 +351,9 @@ int ConvertBSPToOBJ( char *bspName ){
}
modelNum = atoi( key + 1 );
}
model = &bspModels[ modelNum ];
/* convert model */
ConvertModelToOBJ( f, model, modelNum, e->vectorForKey( "origin" ), lmIndices );
ConvertModelToOBJ( f, modelNum, e->vectorForKey( "origin" ), lmIndices );
}
if ( lightmapsAsTexcoord ) {

View File

@ -561,10 +561,6 @@ void CreateSurfaceLights( void ){
void SetEntityOrigins( void ){
int j, k, f;
const char *key;
int modelnum;
bspModel_t *dm;
bspDrawSurface_t *ds;
/* ydnar: copy drawverts into private storage for nefarious purposes */
@ -575,12 +571,12 @@ void SetEntityOrigins( void ){
for ( const auto& e : entities )
{
/* get entity and model */
key = e.valueForKey( "model" );
const char *key = e.valueForKey( "model" );
if ( key[ 0 ] != '*' ) {
continue;
}
modelnum = atoi( key + 1 );
dm = &bspModels[ modelnum ];
const int modelnum = atoi( key + 1 );
const bspModel_t& dm = bspModels[ modelnum ];
/* get entity origin */
Vector3 origin( 0 );
@ -589,15 +585,15 @@ void SetEntityOrigins( void ){
}
/* set origin for all surfaces for this model */
for ( j = 0; j < dm->numBSPSurfaces; j++ )
for ( j = 0; j < dm.numBSPSurfaces; j++ )
{
/* get drawsurf */
ds = &bspDrawSurfaces[ dm->firstBSPSurface + j ];
const bspDrawSurface_t& ds = bspDrawSurfaces[ dm.firstBSPSurface + j ];
/* set its verts */
for ( k = 0; k < ds->numVerts; k++ )
for ( k = 0; k < ds.numVerts; k++ )
{
f = ds->firstVert + k;
f = ds.firstVert + k;
yDrawVerts[ f ].xyz = origin + bspDrawVerts[ f ].xyz;
}
}

View File

@ -818,7 +818,7 @@ static int TriangulateTraceNode_r( int nodeNum ){
filters a bsp model's surfaces into the raytracing tree
*/
static void PopulateWithBSPModel( bspModel_t *model, const Matrix4& transform ){
static void PopulateWithBSPModel( const bspModel_t& model, const Matrix4& transform ){
int i, j, x, y, pw[ 5 ], r, nodeNum;
bspDrawSurface_t *ds;
surfaceInfo_t *info;
@ -829,17 +829,12 @@ static void PopulateWithBSPModel( bspModel_t *model, const Matrix4& transform ){
traceWinding_t tw;
/* dummy check */
if ( model == NULL ) {
return;
}
/* walk the list of surfaces in this model and fill out the info structs */
for ( i = 0; i < model->numBSPSurfaces; i++ )
for ( i = 0; i < model.numBSPSurfaces; i++ )
{
/* get surface and info */
ds = &bspDrawSurfaces[ model->firstBSPSurface + i ];
info = &surfaceInfos[ model->firstBSPSurface + i ];
ds = &bspDrawSurfaces[ model.firstBSPSurface + i ];
info = &surfaceInfos[ model.firstBSPSurface + i ];
if ( info->si == NULL ) {
continue;
}
@ -873,7 +868,7 @@ static void PopulateWithBSPModel( bspModel_t *model, const Matrix4& transform ){
/* setup trace info */
ti.si = info->si;
ti.castShadows = info->castShadows;
ti.surfaceNum = model->firstBSPBrush + i;
ti.surfaceNum = model.firstBSPBrush + i;
ti.skipGrid = ( ds->surfaceType == MST_PATCH );
/* choose which node (normal or skybox) */
@ -1054,13 +1049,13 @@ static void PopulateWithPicoModel( int castShadows, const std::vector<const AssM
*/
static void PopulateTraceNodes( void ){
int m;
size_t m;
const char *value;
/* add worldspawn triangles */
Matrix4 transform( g_matrix4_identity );
PopulateWithBSPModel( &bspModels[ 0 ], transform );
PopulateWithBSPModel( bspModels[ 0 ], transform );
/* walk each entity list */
for ( std::size_t i = 1; i < entities.size(); ++i )
@ -1114,10 +1109,10 @@ static void PopulateTraceNodes( void ){
/* bsp model */
case '*':
m = atoi( &value[ 1 ] );
if ( m <= 0 || m >= numBSPModels ) {
if ( m <= 0 || m >= bspModels.size() ) {
continue;
}
PopulateWithBSPModel( &bspModels[ m ], transform );
PopulateWithBSPModel( bspModels[ m ], transform );
break;
/* external model */
@ -1139,10 +1134,10 @@ static void PopulateTraceNodes( void ){
/* bsp model */
case '*':
m = atoi( &value[ 1 ] );
if ( m <= 0 || m >= numBSPModels ) {
if ( m <= 0 || m >= bspModels.size() ) {
continue;
}
PopulateWithBSPModel( &bspModels[ m ], transform );
PopulateWithBSPModel( bspModels[ m ], transform );
break;
/* external model */

View File

@ -961,16 +961,13 @@ void SetupSurfaceLightmaps( void ){
sortSurfaces = safe_calloc( numBSPDrawSurfaces * sizeof( int ) );
/* walk each model in the bsp */
for ( i = 0; i < numBSPModels; i++ )
for ( const bspModel_t& model : bspModels )
{
/* get model */
model = &bspModels[ i ];
/* walk the list of surfaces in this model and fill out the info structs */
for ( j = 0; j < model->numBSPSurfaces; j++ )
for ( j = 0; j < model.numBSPSurfaces; j++ )
{
/* make surface index */
num = model->firstBSPSurface + j;
num = model.firstBSPSurface + j;
/* copy index to sort list */
sortSurfaces[ num ] = num;

View File

@ -35,7 +35,7 @@
struct minimap_t
{
bspModel_t *model;
const bspModel_t *model;
int width;
int height;
int samples;

View File

@ -2334,9 +2334,7 @@ inline Vector3 gridSize = { 64, 64, 128 };
Q_EXTERN std::size_t numBSPEntities Q_ASSIGN( 0 );
Q_EXTERN std::vector<entity_t> entities;
Q_EXTERN int numBSPModels Q_ASSIGN( 0 );
Q_EXTERN int allocatedBSPModels Q_ASSIGN( 0 );
Q_EXTERN bspModel_t* bspModels Q_ASSIGN( NULL );
Q_EXTERN std::vector<bspModel_t> bspModels;
Q_EXTERN int numBSPShaders Q_ASSIGN( 0 );
Q_EXTERN int allocatedBSPShaders Q_ASSIGN( 0 );

View File

@ -2066,8 +2066,8 @@ void EmitDrawVerts( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
/* expand model bounds
necessary because of misc_model surfaces on entities
note: does not happen on worldspawn as its bounds is only used for determining lightgrid bounds */
if ( numBSPModels > 0 ) {
bspModels[ numBSPModels ].minmax.extend( dv->xyz );
if ( bspModels.size() > 1 ) {
bspModels.back().minmax.extend( dv->xyz );
}
/* debug color? */

View File

@ -347,7 +347,7 @@ void SetLightStyles( void ){
void BeginBSPFile( void ){
/* these values may actually be initialized if the file existed when loaded, so clear them explicitly */
numBSPModels = 0;
bspModels.clear();
numBSPNodes = 0;
numBSPBrushSides = 0;
numBSPLeafSurfaces = 0;
@ -542,11 +542,8 @@ void BeginModel( void ){
MinMax minmax;
MinMax lgMinmax; /* ydnar: lightgrid mins/maxs */
/* test limits */
AUTOEXPAND_BY_REALLOC_BSP( Models, 256 );
/* get model and entity */
bspModel_t *mod = &bspModels[ numBSPModels ];
bspModel_t& mod = bspModels.emplace_back();
const entity_t& e = entities[ mapEntityNum ];
/* bound the brushes */
@ -574,12 +571,12 @@ void BeginModel( void ){
/* ydnar: lightgrid mins/maxs */
if ( lgMinmax.valid() ) {
/* use lightgrid bounds */
mod->minmax = lgMinmax;
mod.minmax = lgMinmax;
}
else
{
/* use brush/patch bounds */
mod->minmax = minmax;
mod.minmax = minmax;
}
/* note size */
@ -588,8 +585,8 @@ void BeginModel( void ){
Sys_FPrintf( SYS_VRB, "Lightgrid bounds: { %f %f %f } { %f %f %f }\n", lgMinmax.mins[0], lgMinmax.mins[1], lgMinmax.mins[2], lgMinmax.maxs[0], lgMinmax.maxs[1], lgMinmax.maxs[2] );
/* set firsts */
mod->firstBSPSurface = numBSPDrawSurfaces;
mod->firstBSPBrush = numBSPBrushes;
mod.firstBSPSurface = numBSPDrawSurfaces;
mod.firstBSPBrush = numBSPBrushes;
}
@ -601,21 +598,15 @@ void BeginModel( void ){
*/
void EndModel( entity_t *e, node_t *headnode ){
bspModel_t *mod;
/* note it */
Sys_FPrintf( SYS_VRB, "--- EndModel ---\n" );
/* emit the bsp */
mod = &bspModels[ numBSPModels ];
bspModel_t& mod = bspModels.back();
EmitDrawNode_r( headnode );
/* set surfaces and brushes */
mod->numBSPSurfaces = numBSPDrawSurfaces - mod->firstBSPSurface;
mod->firstBSPBrush = e->firstBrush;
mod->numBSPBrushes = e->numBrushes;
/* increment model count */
numBSPModels++;
mod.numBSPSurfaces = numBSPDrawSurfaces - mod.firstBSPSurface;
mod.firstBSPBrush = e->firstBrush;
mod.numBSPBrushes = e->numBrushes;
}