//-------------------------------------------------------------------------------------------------- // Name: CBreakableGlassSystem // Desc: Constructor //-------------------------------------------------------------------------------------------------- CBreakableGlassSystem::CBreakableGlassSystem() : m_enabled(false) { // Add physics callback if (IPhysicalWorld* pPhysWorld = gEnv->pPhysicalWorld) { const float listenerPriority = 2001.0f; pPhysWorld->AddEventClient(EventPhysCollision::id, &CBreakableGlassSystem::HandleImpact, 1, listenerPriority); } // Hook up debug cvars if (m_pGlassCVars = new SBreakableGlassCVars()) { #ifdef GLASS_DEBUG_MODE // Rendering REGISTER_CVAR2("g_glassSystem_draw", &m_pGlassCVars->m_draw, 1, VF_CHEAT, "Toggles drawing of glass nodes"); REGISTER_CVAR2("g_glassSystem_drawWireframe", &m_pGlassCVars->m_drawWireframe, 0, VF_CHEAT, "Toggles drawing of glass node wireframe"); REGISTER_CVAR2("g_glassSystem_drawDebugData", &m_pGlassCVars->m_drawDebugData, 0, VF_CHEAT, "Toggles drawing of glass node break/impact data"); REGISTER_CVAR2("g_glassSystem_drawFragData", &m_pGlassCVars->m_drawFragData, 0, VF_CHEAT, "Toggles drawing of glass physicalized fragment data"); // Impact decals REGISTER_CVAR2("g_glassSystem_decalAlwaysRebuild", &m_pGlassCVars->m_decalAlwaysRebuild, 0, VF_CHEAT, "Forces decals to rebuild every frame, allowing real-time tweaking."); REGISTER_CVAR2("g_glassSystem_decalScale", &m_pGlassCVars->m_decalScale, 2.5f, VF_CHEAT, "Scale of procedural impact decals on glass"); REGISTER_CVAR2("g_glassSystem_decalMinRadius", &m_pGlassCVars->m_decalMinRadius, 0.25f, VF_CHEAT, "Minimum size of decal around impact"); REGISTER_CVAR2("g_glassSystem_decalMaxRadius", &m_pGlassCVars->m_decalMaxRadius, 1.25f, VF_CHEAT, "Maximum size of decal around impact"); REGISTER_CVAR2("g_glassSystem_decalRandChance", &m_pGlassCVars->m_decalRandChance, 0.67f, VF_CHEAT, "Chance for a decal to randomly be scaled up"); REGISTER_CVAR2("g_glassSystem_decalRandScale", &m_pGlassCVars->m_decalRandScale, 1.6f, VF_CHEAT, "Scale of decal if selected randomly"); REGISTER_CVAR2("g_glassSystem_decalMinImpactSpeed", &m_pGlassCVars->m_minImpactSpeed, 400.0f, VF_CHEAT, "Minimum speed for an impact to use the bullet decal"); // Physicalized fragments REGISTER_CVAR2("g_glassSystem_fragImpulseScale", &m_pGlassCVars->m_fragImpulseScale, 5.0f, VF_CHEAT, "Scales impulse applied to fragments when physicalized"); REGISTER_CVAR2("g_glassSystem_fragAngImpulseScale", &m_pGlassCVars->m_fragAngImpulseScale, 0.1f, VF_CHEAT, "Scales *angular* impulse applied to fragments when physicalized"); REGISTER_CVAR2("g_glassSystem_fragImpulseDampen", &m_pGlassCVars->m_fragImpulseDampen, 0.3f, VF_CHEAT, "Dampens impulse applied to non-directly impacted fragments"); REGISTER_CVAR2("g_glassSystem_fragAngImpulseDampen", &m_pGlassCVars->m_fragAngImpulseDampen, 0.4f, VF_CHEAT, "Dampens *angular* impulse applied to non-directly impacted fragments"); REGISTER_CVAR2("g_glassSystem_fragSpread", &m_pGlassCVars->m_fragSpread, 1.5f, VF_CHEAT, "Spread velocity to apply to impacted fragments"); REGISTER_CVAR2("g_glassSystem_fragMaxSpeed", &m_pGlassCVars->m_fragMaxSpeed, 4.0f, VF_CHEAT, "Maximum speed to apply to physicalized fragments"); // Impact breaks REGISTER_CVAR2("g_glassSystem_impactSplitMinRadius", &m_pGlassCVars->m_impactSplitMinRadius, 0.05f, VF_CHEAT, "Minimum radius for split around impact"); REGISTER_CVAR2("g_glassSystem_impactSplitRandMin", &m_pGlassCVars->m_impactSplitRandMin, 0.5f, VF_CHEAT, "Minimum radius variation for split around impact"); REGISTER_CVAR2("g_glassSystem_impactSplitRandMax", &m_pGlassCVars->m_impactSplitRandMax, 1.5f, VF_CHEAT, "Maximum radius variation for split around impact"); REGISTER_CVAR2("g_glassSystem_impactEdgeFadeScale", &m_pGlassCVars->m_impactEdgeFadeScale, 2.0f, VF_CHEAT, "Scales radial crack fade distance"); // Particle effects REGISTER_CVAR2("g_glassSystem_particleFXEnable", &m_pGlassCVars->m_particleFXEnable, 1, VF_CHEAT, "Toggles particle effects being played when fragments are broken"); REGISTER_CVAR2("g_glassSystem_particleFXUseColours", &m_pGlassCVars->m_particleFXUseColours, 0, VF_CHEAT, "Toggles particle effects being coloured to match the glass"); REGISTER_CVAR2("g_glassSystem_particleFXScale", &m_pGlassCVars->m_particleFXScale, 0.25f, VF_CHEAT, "Scales the glass particle effects spawned"); #endif // GLASS_DEBUG_MODE } // Add callback for system enabled cvar IConsole* pConsole = gEnv->pConsole; ICVar* pSysEnabledCvar = pConsole ? pConsole->GetCVar("g_glassSystemEnable") : NULL; if (pSysEnabledCvar) { m_enabled = (pSysEnabledCvar->GetIVal() != 0); pSysEnabledCvar->SetOnChangeCallback(OnEnabledCVarChange); } }//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------- // Name: ~CBreakableGlassSystem // Desc: Destructor //-------------------------------------------------------------------------------------------------- CBreakableGlassSystem::~CBreakableGlassSystem() { // Release all nodes and data ResetAll(); #ifdef GLASS_DEBUG_MODE // Remove debug cvars after all nodes that could be using them if (IConsole* pConsole = gEnv->pConsole) { pConsole->UnregisterVariable("g_glassSystem_draw"); pConsole->UnregisterVariable("g_glassSystem_drawWireframe"); pConsole->UnregisterVariable("g_glassSystem_drawDebugData"); pConsole->UnregisterVariable("g_glassSystem_drawFragData"); pConsole->UnregisterVariable("g_glassSystem_decalAlwaysRebuild"); pConsole->UnregisterVariable("g_glassSystem_decalScale"); pConsole->UnregisterVariable("g_glassSystem_decalMinRadius"); pConsole->UnregisterVariable("g_glassSystem_decalMaxRadius"); pConsole->UnregisterVariable("g_glassSystem_decalRandChance"); pConsole->UnregisterVariable("g_glassSystem_decalRandScale"); pConsole->UnregisterVariable("g_glassSystem_decalMinImpactSpeed"); pConsole->UnregisterVariable("g_glassSystem_fragImpulseScale"); pConsole->UnregisterVariable("g_glassSystem_fragAngImpulseScale"); pConsole->UnregisterVariable("g_glassSystem_fragImpulseDampen"); pConsole->UnregisterVariable("g_glassSystem_fragAngImpulseDampen"); pConsole->UnregisterVariable("g_glassSystem_fragSpread"); pConsole->UnregisterVariable("g_glassSystem_fragMaxSpeed"); pConsole->UnregisterVariable("g_glassSystem_particleFXEnable"); pConsole->UnregisterVariable("g_glassSystem_particleFXUseColours"); pConsole->UnregisterVariable("g_glassSystem_particleFXScale"); } #endif // GLASS_DEBUG_MODE SAFE_DELETE(m_pGlassCVars); // Remove system enabled cvar callback IConsole* pConsole = gEnv->pConsole; ICVar* pSysEnabledCVar = pConsole ? pConsole->GetCVar("g_glassSystemEnable") : NULL; if (pSysEnabledCVar) { pSysEnabledCVar->SetOnChangeCallback(NULL); } // Remove physics callback if (IPhysicalWorld* pPhysWorld = gEnv->pPhysicalWorld) { pPhysWorld->RemoveEventClient(EventPhysCollision::id, &CBreakableGlassSystem::HandleImpact, 1); } }//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------- // Name: SetPostEffectCVarCallbacks // Desc: Sets Post effect CVar callbacks for testing and tweaking post effect values //-------------------------------------------------------------------------------------------------- void GameSDKCGameEffectsSystem::SetPostEffectCVarCallbacks() { #if DEBUG_GAME_FX_SYSTEM ICVar* postEffectCvar = NULL; const char postEffectNames[][64] = { "g_postEffect.FilterGrain_Amount", "g_postEffect.FilterRadialBlurring_Amount", "g_postEffect.FilterRadialBlurring_ScreenPosX", "g_postEffect.FilterRadialBlurring_ScreenPosY", "g_postEffect.FilterRadialBlurring_Radius", "g_postEffect.Global_User_ColorC", "g_postEffect.Global_User_ColorM", "g_postEffect.Global_User_ColorY", "g_postEffect.Global_User_ColorK", "g_postEffect.Global_User_Brightness", "g_postEffect.Global_User_Contrast", "g_postEffect.Global_User_Saturation", "g_postEffect.Global_User_ColorHue", "g_postEffect.HUD3D_Interference", "g_postEffect.HUD3D_FOV"}; int postEffectNameCount = sizeof(postEffectNames)/sizeof(*postEffectNames); if(postEffectNameCount > 0) { // Calc name offset const char* postEffectName = postEffectNames[0]; s_postEffectCVarNameOffset = 0; while((*postEffectName) != 0) { s_postEffectCVarNameOffset++; if((*postEffectName) == '.') { break; } postEffectName++; } // Set callback functions for(int i=0; i<postEffectNameCount; i++) { postEffectCvar = gEnv->pConsole->GetCVar(postEffectNames[i]); if(postEffectCvar) { postEffectCvar->SetOnChangeCallback(PostEffectCVarCallback); } } } #endif }//-------------------------------------------------------------------------------------------------
int CGameStartup::Update(bool haveFocus, unsigned int updateFlags) { #if defined(JOBMANAGER_SUPPORT_PROFILING) gEnv->GetJobManager()->SetFrameStartTime(gEnv->pTimer->GetAsyncTime()); #endif int returnCode = 0; if (gEnv->pConsole) { #if CRY_PLATFORM_WINDOWS if(gEnv && gEnv->pRenderer && gEnv->pRenderer->GetHWND()) { bool focus = (::GetFocus() == gEnv->pRenderer->GetHWND()); static bool focused = focus; if (focus != focused) { if (GetISystem()->GetISystemEventDispatcher()) { GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_CHANGE_FOCUS, focus, 0); } focused = focus; } } #endif } if (m_pGame) { returnCode = m_pGame->Update(haveFocus, updateFlags); } if (!m_fullScreenCVarSetup && gEnv->pConsole) { ICVar *pVar = gEnv->pConsole->GetCVar("r_Fullscreen"); if (pVar) { pVar->SetOnChangeCallback(FullScreenCVarChanged); m_fullScreenCVarSetup = true; } } #if ENABLE_AUTO_TESTER s_autoTesterSingleton.Update(); #endif return returnCode; }
void CUIHUD3D::InitEventSystem() { assert(gEnv->pSystem); if (gEnv->pSystem) gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener( this ); if(gEnv->pFlashUI) gEnv->pFlashUI->RegisterModule(this, "CUIHUD3D"); m_Offsets.push_back( SHudOffset(1.2f, 1.4f, -0.2f) ); m_Offsets.push_back( SHudOffset(1.33f, 1.3f, -0.1f) ); m_Offsets.push_back( SHudOffset(1.6f, 1.1f, -0.1f) ); m_Offsets.push_back( SHudOffset(1.77f, 1.0f, 0.0f) ); ICVar* pShowHudVar = gEnv->pConsole->GetCVar("hud_hide"); if (pShowHudVar) pShowHudVar->SetOnChangeCallback( &OnVisCVarChange ); }
int CGameStartup::Update(bool haveFocus, unsigned int updateFlags) { CRYPROFILE_SCOPE_PROFILE_MARKER("MT: MainLoop"); #if defined(JOBMANAGER_SUPPORT_PROFILING) gEnv->GetJobManager()->SetFrameStartTime(gEnv->pTimer->GetAsyncTime()); #endif int returnCode = 0; if (gEnv && gEnv->pSystem && gEnv->pConsole) { #ifdef WIN32 if(gEnv && gEnv->pRenderer && gEnv->pRenderer->GetHWND()) { bool focus = (::GetFocus() == gEnv->pRenderer->GetHWND()); static bool focused = focus; if (focus != focused) { if(gEnv->pSystem->GetISystemEventDispatcher()) { gEnv->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_CHANGE_FOCUS, focus, 0); } focused = focus; } } #endif } // update the game if (m_pMod) { returnCode = m_pMod->Update(haveFocus, updateFlags); } #if defined(ENABLE_STATS_AGENT) CStatsAgent::Update(); #endif #if defined(JOBMANAGER_SUPPORT_FRAMEPROFILER) // Update Backend profilers uint32 timeSample = JobManager::IWorkerBackEndProfiler::GetTimeSample(); assert(gEnv); PREFAST_ASSUME(gEnv); const JobManager::IBackend * const __restrict pBackends[] = { gEnv->GetJobManager()->GetBackEnd(JobManager::eBET_Thread), gEnv->GetJobManager()->GetBackEnd(JobManager::eBET_Blocking), }; for(int i=0; i<sizeof(pBackends)/sizeof(pBackends[0]); ++i) { if(pBackends[i]) { JobManager::IWorkerBackEndProfiler* pWorkerProfiler = pBackends[i]->GetBackEndWorkerProfiler(); pWorkerProfiler->Update(timeSample); } } #endif // ghetto fullscreen detection, because renderer does not provide any kind of listener if (!m_fullScreenCVarSetup && gEnv && gEnv->pSystem && gEnv->pConsole) { ICVar *pVar = gEnv->pConsole->GetCVar("r_Fullscreen"); if (pVar) { pVar->SetOnChangeCallback(FullScreenCVarChanged); m_fullScreenCVarSetup = true; } } #if ENABLE_AUTO_TESTER s_autoTesterSingleton.Update(); #endif GCOV_FLUSH_UPDATE; return returnCode; }