void PhysCreateVirtualTerrain( CBaseEntity *pWorld, const objectparams_t &defaultParams ) { char nameBuf[1024]; for ( int i = 0; i < MAX_MAP_DISPINFO; i++ ) { CPhysCollide *pCollide = modelinfo->GetCollideForVirtualTerrain( i ); if ( pCollide ) { solid_t solid; solid.params = defaultParams; solid.params.enableCollisions = true; solid.params.pGameData = static_cast<void *>(pWorld); Q_snprintf(nameBuf, sizeof(nameBuf), "vdisp_%04d", i ); solid.params.pName = nameBuf; int surfaceData = physprops->GetSurfaceIndex( "default" ); // create this as part of the world IPhysicsObject *pObject = physenv->CreatePolyObjectStatic( pCollide, surfaceData, vec3_origin, vec3_angle, &solid.params ); pObject->SetCallbackFlags( pObject->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); pObject->SetCollisionHints( COLLISION_HINT_STATICSOLID ); } } }
IPhysicsObject *PhysCreateWorld_Shared( CBaseEntity *pWorld, vcollide_t *pWorldCollide, const objectparams_t &defaultParams ) { solid_t solid; fluid_t fluid; int surfaceData = physprops->GetSurfaceIndex( "default" ); objectparams_t params = defaultParams; params.pGameData = static_cast<void *>(pWorld); params.pName = "world"; IPhysicsObject *pWorldPhysics = physenv->CreatePolyObjectStatic( pWorldCollide->solids[0], surfaceData, vec3_origin, vec3_angle, ¶ms ); // hint - saves vphysics some work pWorldPhysics->SetCallbackFlags( pWorldPhysics->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); //PhysCheckAdd( world, "World" ); // walk the world keys in case there are some fluid volumes to create IVPhysicsKeyParser *pParse = physcollision->VPhysicsKeyParserCreate( pWorldCollide ); bool bCreateVirtualTerrain = false; while ( !pParse->Finished() ) { const char *pBlock = pParse->GetCurrentBlockName(); if ( !strcmpi( pBlock, "solid" ) || !strcmpi( pBlock, "staticsolid" ) ) { solid.params = defaultParams; pParse->ParseSolid( &solid, &g_SolidSetup ); solid.params.enableCollisions = true; solid.params.pGameData = static_cast<void *>(pWorld); solid.params.pName = "world"; int surfaceData = physprops->GetSurfaceIndex( "default" ); // already created world above if ( solid.index == 0 ) continue; if ( !pWorldCollide->solids[solid.index] ) { // this implies that the collision model is a mopp and the physics DLL doesn't support that. bCreateVirtualTerrain = true; continue; } // create this as part of the world IPhysicsObject *pObject = physenv->CreatePolyObjectStatic( pWorldCollide->solids[solid.index], surfaceData, vec3_origin, vec3_angle, &solid.params ); // invalid collision model or can't create, ignore if (!pObject) continue; pObject->SetCallbackFlags( pObject->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); Assert( solid.contents != 0 ); pObject->SetContents( solid.contents ); if ( solid.contents & CONTENTS_SOLID ) { pObject->SetCollisionHints(COLLISION_HINT_STATICSOLID); } if ( !pWorldPhysics ) { pWorldPhysics = pObject; } } else if ( !strcmpi( pBlock, "fluid" ) ) { pParse->ParseFluid( &fluid, NULL ); // create a fluid for floating if ( fluid.index > 0 ) { solid.params = defaultParams; // copy world's params solid.params.enableCollisions = true; solid.params.pName = "fluid"; solid.params.pGameData = static_cast<void *>(pWorld); fluid.params.pGameData = static_cast<void *>(pWorld); int surfaceData = physprops->GetSurfaceIndex( fluid.surfaceprop ); // create this as part of the world IPhysicsObject *pWater = physenv->CreatePolyObjectStatic( pWorldCollide->solids[fluid.index], surfaceData, vec3_origin, vec3_angle, &solid.params ); pWater->SetCallbackFlags( pWater->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); physenv->CreateFluidController( pWater, &fluid.params ); } } else if ( !strcmpi( pBlock, "materialtable" ) ) { int surfaceTable[128]; memset( surfaceTable, 0, sizeof(surfaceTable) ); pParse->ParseSurfaceTable( surfaceTable, NULL ); physprops->SetWorldMaterialIndexTable( surfaceTable, 128 ); } else if ( !strcmpi(pBlock, "virtualterrain" ) ) { bCreateVirtualTerrain = true; pParse->SkipBlock(); } else { // unknown chunk??? pParse->SkipBlock(); } } physcollision->VPhysicsKeyParserDestroy( pParse ); if ( bCreateVirtualTerrain && physcollision->SupportsVirtualMesh() ) { PhysCreateVirtualTerrain( pWorld, defaultParams ); } return pWorldPhysics; }