//----------------------------------------------------------------------------- // Purpose: Called when the DLL is first loaded. // Input : engineFactory - // Output : int //----------------------------------------------------------------------------- int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CGlobalVarsBase *pGlobals ) { InitCRTMemDebug(); MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); // Hook up global variables gpGlobals = pGlobals; // We aren't happy unless we get all of our interfaces. if( !(engine = (IVEngineClient *)appSystemFactory( VENGINE_CLIENT_INTERFACE_VERSION, NULL )) || !(modelrender = (IVModelRender *)appSystemFactory( VENGINE_HUDMODEL_INTERFACE_VERSION, NULL )) || !(effects = (IVEfx *)appSystemFactory( VENGINE_EFFECTS_INTERFACE_VERSION, NULL )) || !(cvar = (ICvar *)appSystemFactory( VENGINE_CVAR_INTERFACE_VERSION, NULL )) || !(enginetrace = (IEngineTrace *)appSystemFactory( INTERFACEVERSION_ENGINETRACE_CLIENT, NULL )) || !(render = (IVRenderView *)appSystemFactory( VENGINE_RENDERVIEW_INTERFACE_VERSION, NULL )) || !(debugoverlay = (IVDebugOverlay *)appSystemFactory( VDEBUG_OVERLAY_INTERFACE_VERSION, NULL )) || !(materials = (IMaterialSystem *)appSystemFactory( MATERIAL_SYSTEM_INTERFACE_VERSION, NULL )) || !(engineCache = (IVEngineCache*)appSystemFactory(VENGINE_CACHE_INTERFACE_VERSION, NULL )) || !(modelinfo = (IVModelInfo *)appSystemFactory(VMODELINFO_CLIENT_INTERFACE_VERSION, NULL )) || !(netgraph = (INetGraph *)appSystemFactory(VNETGRAPH_INTERFACE_VERSION, NULL )) || !(enginevgui = (IEngineVGui *)appSystemFactory(VENGINE_VGUI_VERSION, NULL )) || !(networkstringtable = (INetworkStringTableClient *)appSystemFactory(INTERFACENAME_NETWORKSTRINGTABLECLIENT,NULL)) || !(partition = (ISpatialPartition *)appSystemFactory(INTERFACEVERSION_SPATIALPARTITION, NULL)) || !(shadowmgr = (IShadowMgr *)appSystemFactory(ENGINE_SHADOWMGR_INTERFACE_VERSION, NULL)) || !(staticpropmgr = (IStaticPropMgrClient *)appSystemFactory(INTERFACEVERSION_STATICPROPMGR_CLIENT, NULL)) || !(enginesound = (IEngineSound *)appSystemFactory(IENGINESOUND_CLIENT_INTERFACE_VERSION, NULL)) || !(filesystem = (IFileSystem *)appSystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL)) || !(random = (IUniformRandomStream *)appSystemFactory(VENGINE_CLIENT_RANDOM_INTERFACE_VERSION, NULL)) || !(gameuifuncs = (IGameUIFuncs * )appSystemFactory( VENGINE_GAMEUIFUNCS_VERSION, NULL )) || !(gameeventmanager = (IGameEventManager *)appSystemFactory(INTERFACEVERSION_GAMEEVENTSMANAGER,NULL)) ) { return false; } g_pMaterialSystemHardwareConfig = materials->GetHardwareConfig( MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, NULL ); if( !g_pMaterialSystemHardwareConfig ) { return false; } SetScreenSize(); // Hook up the gaussian random number generator s_GaussianRandomStream.AttachToStream( random ); // Initialize the console variables. ConCommandBaseMgr::OneTimeInit(&g_ConVarAccessor); if(!Initializer::InitializeAllObjects()) return false; if(!g_ParticleMgr.Init(8192, materials)) return false; // load used game events gameeventmanager->LoadEventsFromFile("resource/gameevents.res"); if(!VGui_Startup( appSystemFactory )) return false; g_pMatSystemSurface = (IMatSystemSurface*)vgui::surface()->QueryInterface( MAT_SYSTEM_SURFACE_INTERFACE_VERSION ); if (!g_pMatSystemSurface) return false; // Add the client systems. // Client Leaf System has to be initialized first, since DetailObjectSystem uses it IGameSystem::Add( GameStringSystem() ); IGameSystem::Add( ClientLeafSystem() ); IGameSystem::Add( DetailObjectSystem() ); IGameSystem::Add( ViewportClientSystem() ); IGameSystem::Add( ClientEffectPrecacheSystem() ); IGameSystem::Add( g_pClientShadowMgr ); IGameSystem::Add( ClientThinkList() ); IGameSystem::Add( ClientSoundscapeSystem() ); #if defined( CLIENT_DLL ) && defined( COPY_CHECK_STRESSTEST ) IGameSystem::Add( GetPredictionCopyTester() ); #endif modemanager->Init( ); gHUD.Init(); g_pClientMode->Init(); if( !IGameSystem::InitAllSystems() ) return false; g_pClientMode->Enable(); view->Init(); vieweffects->Init(); C_BaseTempEntity::PrecacheTempEnts(); input->Init_All(); VGui_CreateGlobalPanels(); InitSmokeFogOverlay(); C_TerrainMod_Init(); // Register user messages.. CUserMessageRegister::RegisterAll(); ClientVoiceMgr_Init(); // Embed voice status icons inside chat element { CHudChat *chatElement = GET_HUDELEMENT( CHudChat ); vgui::VPANEL parent = enginevgui->GetPanel( PANEL_CLIENTDLL ); if ( chatElement ) { parent = chatElement->GetVoiceArea()->GetVPanel(); } GetClientVoiceMgr()->Init( &g_VoiceStatusHelper, parent ); } if ( !PhysicsDLLInit( physicsFactory ) ) return false; g_pGameSaveRestoreBlockSet->AddBlockHandler( GetEntitiySaveRestoreBlockHandler() ); g_pGameSaveRestoreBlockSet->AddBlockHandler( GetPhysSaveRestoreBlockHandler() ); return true; }
void CClientLeafSystem::CollateRenderablesInLeaf( int leaf, int worldListLeafIndex, SetupRenderInfo_t &info ) { bool portalTestEnts = r_PortalTestEnts.GetBool() && !r_portalsopenall.GetBool(); // Collate everything. unsigned short idx = m_RenderablesInLeaf.FirstElement(leaf); for ( ;idx != m_RenderablesInLeaf.InvalidIndex(); idx = m_RenderablesInLeaf.NextElement(idx) ) { ClientRenderHandle_t handle = m_RenderablesInLeaf.Element(idx); RenderableInfo_t& renderable = m_Renderables[handle]; // Early out on static props if we don't want to render them if ((!m_DrawStaticProps) && (renderable.m_Flags & RENDER_FLAGS_STATIC_PROP)) continue; // Early out if we're told to not draw small objects (top view only, /* that's why we don't check the z component). if (!m_DrawSmallObjects) { CCachedRenderInfo& cachedInfo = m_CachedRenderInfos[renderable.m_CachedRenderInfo]; float sizeX = cachedInfo.m_Maxs.x - cachedInfo.m_Mins.x; float sizeY = cachedInfo.m_Maxs.y - cachedInfo.m_Mins.y; if ((sizeX < 50.f) && (sizeY < 50.f)) continue; }*/ Assert( m_DrawSmallObjects ); // MOTODO // Don't hit the same ent in multiple leaves twice. if ( renderable.m_RenderGroup != RENDER_GROUP_TRANSLUCENT_ENTITY ) { if ( renderable.m_RenderFrame2 == info.m_nRenderFrame ) continue; renderable.m_RenderFrame2 = info.m_nRenderFrame; } else { // Translucent entities already have had ComputeTranslucentRenderLeaf called on them // so m_RenderLeaf should be set to the nearest leaf, so that's what we want here. if ( renderable.m_RenderLeaf != leaf ) continue; } // Prevent culling if the renderable is invisible // NOTE: OPAQUE objects can have alpha == 0. // They are made to be opaque because they don't have to be sorted. unsigned char nAlpha = renderable.m_pRenderable->GetFxBlend(); if ( nAlpha == 0 ) continue; Vector absMins, absMaxs; CalcRenderableWorldSpaceAABB( renderable.m_pRenderable, absMins, absMaxs ); // If the renderable is inside an area, cull it using the frustum for that area. if ( portalTestEnts && renderable.m_Area != -1 ) { VPROF( "r_PortalTestEnts" ); if ( !engine->DoesBoxTouchAreaFrustum( absMins, absMaxs, renderable.m_Area ) ) continue; } else { // cull with main frustum if ( engine->CullBox( absMins, absMaxs ) ) continue; } // UNDONE: Investigate speed tradeoffs of occlusion culling brush models too? if ( renderable.m_Flags & RENDER_FLAGS_STUDIO_MODEL ) { // test to see if this renderable is occluded by the engine's occlusion system if ( engine->IsOccluded( absMins, absMaxs ) ) continue; } if( renderable.m_RenderGroup != RENDER_GROUP_TRANSLUCENT_ENTITY ) { RenderGroup_t group = (RenderGroup_t)renderable.m_RenderGroup; AddRenderableToRenderList( *info.m_pRenderList, renderable.m_pRenderable, worldListLeafIndex, group, handle); } else { bool bTwoPass = ((renderable.m_Flags & RENDER_FLAGS_TWOPASS) != 0) && ( nAlpha == 255 ); AddRenderableToRenderList( *info.m_pRenderList, renderable.m_pRenderable, worldListLeafIndex, (RenderGroup_t)renderable.m_RenderGroup, handle, bTwoPass ); // Add to both lists if it's a two-pass model... if (bTwoPass) { AddRenderableToRenderList( *info.m_pRenderList, renderable.m_pRenderable, worldListLeafIndex, RENDER_GROUP_OPAQUE_ENTITY, handle, bTwoPass ); } } } // Do detail objects. // These don't have render handles! if ( IsPC() && info.m_bDrawDetailObjects && ShouldDrawDetailObjectsInLeaf( leaf, info.m_nDetailBuildFrame ) ) { idx = m_Leaf[leaf].m_FirstDetailProp; int count = m_Leaf[leaf].m_DetailPropCount; while( --count >= 0 ) { IClientRenderable* pRenderable = DetailObjectSystem()->GetDetailModel(idx); // FIXME: This if check here is necessary because the detail object system also maintains // lists of sprites... if (pRenderable) { if( pRenderable->IsTransparent() ) { // Lots of the detail entities are invsible so avoid sorting them and all that. if( pRenderable->GetFxBlend() > 0 ) { AddRenderableToRenderList( *info.m_pRenderList, pRenderable, worldListLeafIndex, RENDER_GROUP_TRANSLUCENT_ENTITY, DETAIL_PROP_RENDER_HANDLE ); } } else { AddRenderableToRenderList( *info.m_pRenderList, pRenderable, worldListLeafIndex, RENDER_GROUP_OPAQUE_ENTITY, DETAIL_PROP_RENDER_HANDLE ); } } ++idx; } } }