Don't generate collision models for every rendermodel in advance

(cherry picked from commit 82928cce8b6544466f4131b9bfd602ab2fa033d6)
This commit is contained in:
Robert Beckebans 2022-05-11 20:03:10 +02:00
parent a664f8599e
commit 3d269124b2
6 changed files with 34 additions and 11 deletions

View file

@ -100,22 +100,29 @@ public:
virtual void Preload( const char* mapName ) = 0;
// Gets the clip handle for a model.
virtual cmHandle_t LoadModel( const char* modelName ) = 0;
virtual cmHandle_t LoadModel( const char* modelName, const bool precache ) = 0;
// Sets up a trace model for collision with other trace models.
virtual cmHandle_t SetupTrmModel( const idTraceModel& trm, const idMaterial* material ) = 0;
// Creates a trace model from a collision model, returns true if succesfull.
virtual bool TrmFromModel( const char* modelName, idTraceModel& trm ) = 0;
// Gets the name of a model.
virtual const char* GetModelName( cmHandle_t model ) const = 0;
// Gets the bounds of a model.
virtual bool GetModelBounds( cmHandle_t model, idBounds& bounds ) const = 0;
// Gets all contents flags of brushes and polygons of a model ored together.
virtual bool GetModelContents( cmHandle_t model, int& contents ) const = 0;
// Gets a vertex of a model.
virtual bool GetModelVertex( cmHandle_t model, int vertexNum, idVec3& vertex ) const = 0;
// Gets an edge of a model.
virtual bool GetModelEdge( cmHandle_t model, int edgeNum, idVec3& start, idVec3& end ) const = 0;
// Gets a polygon of a model.
virtual bool GetModelPolygon( cmHandle_t model, int polygonNum, idFixedWinding& winding ) const = 0;
@ -123,14 +130,17 @@ public:
virtual void Translation( trace_t* results, const idVec3& start, const idVec3& end,
const idTraceModel* trm, const idMat3& trmAxis, int contentMask,
cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis ) = 0;
// Rotates a trace model and reports the first collision if any.
virtual void Rotation( trace_t* results, const idVec3& start, const idRotation& rotation,
const idTraceModel* trm, const idMat3& trmAxis, int contentMask,
cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis ) = 0;
// Returns the contents touched by the trace model or 0 if the trace model is in free space.
virtual int Contents( const idVec3& start,
const idTraceModel* trm, const idMat3& trmAxis, int contentMask,
cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis ) = 0;
// Stores all contact points of the trace model with the model, returns the number of contacts.
virtual int Contacts( contactInfo_t* contacts, const int maxContacts, const idVec3& start, const idVec6& dir, const float depth,
const idTraceModel* trm, const idMat3& trmAxis, int contentMask,
@ -138,13 +148,17 @@ public:
// Tests collision detection.
virtual void DebugOutput( const idVec3& origin ) = 0;
// Draws a model.
virtual void DrawModel( cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis,
const idVec3& viewOrigin, const float radius ) = 0;
// Prints model information, use -1 handle for accumulated model info.
virtual void ModelInfo( cmHandle_t model ) = 0;
// Lists all loaded models.
virtual void ListModels() = 0;
// Writes a collision model file for the given map entity.
virtual bool WriteCollisionModelForMapEntity( const idMapEntity* mapEnt, const char* filename, const bool testTraceModel = true ) = 0;
};

View file

@ -4339,7 +4339,7 @@ void idCollisionModelManagerLocal::Preload( const char* mapName )
const preloadEntry_s& p = manifest.GetPreloadByIndex( i );
if( p.resType == PRELOAD_COLLISION )
{
LoadModel( p.resourceName );
LoadModel( p.resourceName, false );
numLoaded++;
}
}
@ -4543,7 +4543,7 @@ bool idCollisionModelManagerLocal::GetModelPolygon( cmHandle_t model, int polygo
idCollisionModelManagerLocal::LoadModel
==================
*/
cmHandle_t idCollisionModelManagerLocal::LoadModel( const char* modelName )
cmHandle_t idCollisionModelManagerLocal::LoadModel( const char* modelName, const bool precache )
{
int handle;
@ -4601,6 +4601,12 @@ cmHandle_t idCollisionModelManagerLocal::LoadModel( const char* modelName )
}
}
// if only precaching .cm files do not waste memory converting render models
if( precache )
{
return 0;
}
// try to load a .ASE or .LWO model and convert it to a collision model
models[ numModels ] = LoadRenderModel( modelName );
if( models[ numModels ] != NULL )
@ -4780,7 +4786,7 @@ bool idCollisionModelManagerLocal::TrmFromModel( const char* modelName, idTraceM
{
cmHandle_t handle;
handle = LoadModel( modelName );
handle = LoadModel( modelName, false );
if( !handle )
{
common->Printf( "idCollisionModelManagerLocal::TrmFromModel: model %s not found.\n", modelName );

View file

@ -332,7 +332,7 @@ public:
void Preload( const char* mapName );
// get clip handle for model
cmHandle_t LoadModel( const char* modelName );
cmHandle_t LoadModel( const char* modelName, const bool precache );
// sets up a trace model for collision with other trace models
cmHandle_t SetupTrmModel( const idTraceModel& trm, const idMaterial* material );
// create trace model from a collision model, returns true if succesfull

View file

@ -1894,7 +1894,7 @@ void idGameLocal::CacheDictionaryMedia( const idDict* dict )
renderModelManager->FindModel( kv->GetValue() );
// precache .cm files only
collisionModelManager->LoadModel( kv->GetValue() );
collisionModelManager->LoadModel( kv->GetValue(), true );
}
}
kv = dict->MatchPrefix( "model", kv );

View file

@ -851,8 +851,9 @@ void idTarget_SetModel::Spawn()
{
// precache the render model
renderModelManager->FindModel( model );
// precache .cm files only
collisionModelManager->LoadModel( model );
collisionModelManager->LoadModel( model, true );
}
}

View file

@ -329,7 +329,7 @@ bool idClipModel::LoadModel( const char* name )
FreeTraceModel( traceModelIndex );
traceModelIndex = -1;
}
collisionModelHandle = collisionModelManager->LoadModel( name );
collisionModelHandle = collisionModelManager->LoadModel( name, false );
if( collisionModelHandle )
{
collisionModelManager->GetModelBounds( collisionModelHandle, bounds );
@ -560,7 +560,7 @@ void idClipModel::Restore( idRestoreGame* savefile )
savefile->ReadString( collisionModelName );
if( collisionModelName.Length() )
{
collisionModelHandle = collisionModelManager->LoadModel( collisionModelName );
collisionModelHandle = collisionModelManager->LoadModel( collisionModelName, false );
}
else
{
@ -788,7 +788,7 @@ idClipModel::CheckModel
*/
cmHandle_t idClipModel::CheckModel( const char* name )
{
return collisionModelManager->LoadModel( name );
return collisionModelManager->LoadModel( name, false );
}
@ -887,9 +887,11 @@ void idClip::Init()
memset( clipSectors, 0, MAX_SECTORS * sizeof( clipSector_t ) );
numClipSectors = 0;
touchCount = -1;
// get world map bounds
h = collisionModelManager->LoadModel( "worldMap" );
h = collisionModelManager->LoadModel( "worldMap", false );
collisionModelManager->GetModelBounds( h, worldBounds );
// create world sectors
CreateClipSectors_r( 0, worldBounds, maxSector );