From 91c940a853428b5c1f221bae239bfb7d0d0929c6 Mon Sep 17 00:00:00 2001 From: chaigler Date: Wed, 24 Jan 2018 14:22:26 -0500 Subject: [PATCH] Fixes for compiling without Advanced Lighting Building without Advanced Lighting (TORQUE_ADVANCED_LIGHTING unchecked in CMake) generated linker errors and an alert when the game attempted to set the light manager. --- Engine/source/T3D/levelInfo.cpp | 11 +++++++-- .../shaderGen/GLSL/shaderGenGLSLInit.cpp | 4 ++++ .../shaderGen/HLSL/shaderGenHLSLInit.cpp | 5 +++- Templates/BaseGame/game/core/globals.cs | 4 ++++ Templates/BaseGame/game/core/lighting.cs | 24 +++++++++++++------ Templates/BaseGame/game/data/defaults.cs | 4 ---- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Engine/source/T3D/levelInfo.cpp b/Engine/source/T3D/levelInfo.cpp index c442bcda13..67c2ff8666 100644 --- a/Engine/source/T3D/levelInfo.cpp +++ b/Engine/source/T3D/levelInfo.cpp @@ -26,8 +26,10 @@ #include "console/consoleTypes.h" #include "core/stream/bitStream.h" #include "scene/sceneManager.h" +#if defined(TORQUE_ADVANCED_LIGHTING) #include "lighting/advanced/advancedLightManager.h" #include "lighting/advanced/advancedLightBinManager.h" +#endif #include "sfx/sfxAmbience.h" #include "sfx/sfxSoundscape.h" #include "sfx/sfxSystem.h" @@ -101,16 +103,21 @@ LevelInfo::LevelInfo() mAccuTextureName = ""; mAccuTexture = NULL; +#if defined(TORQUE_ADVANCED_LIGHTING) // Register with the light manager activation signal, and we need to do it first // so the advanced light bin manager can be instructed about MRT lightmaps LightManager::smActivateSignal.notify(this, &LevelInfo::_onLMActivate, 0.01f); +#endif } //----------------------------------------------------------------------------- LevelInfo::~LevelInfo() { +#if defined(TORQUE_ADVANCED_LIGHTING) LightManager::smActivateSignal.remove(this, &LevelInfo::_onLMActivate); +#endif + if (!mAccuTexture.isNull()) { mAccuTexture.free(); @@ -334,7 +341,7 @@ void LevelInfo::_updateSceneGraph() // If the level info specifies that MRT pre-pass should be used in this scene // enable it via the appropriate light manager // (Basic lighting doesn't do anything different right now) -#ifndef TORQUE_DEDICATED +#if !defined(TORQUE_DEDICATED) && defined(TORQUE_ADVANCED_LIGHTING) if(isClientObject()) _onLMActivate(LIGHTMGR->getId(), true); #endif @@ -347,7 +354,7 @@ void LevelInfo::_updateSceneGraph() void LevelInfo::_onLMActivate(const char *lm, bool enable) { -#ifndef TORQUE_DEDICATED +#if !defined(TORQUE_DEDICATED) && defined(TORQUE_ADVANCED_LIGHTING) // Advanced light manager if(enable && String(lm) == String("ADVLM")) { diff --git a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp index 0827c7beed..e385adcdbd 100644 --- a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp +++ b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp @@ -35,7 +35,9 @@ #include "shaderGen/GLSL/accuFeatureGLSL.h" // Deferred Shading +#if defined(TORQUE_ADVANCED_LIGHTING) #include "lighting/advanced/glsl/deferredShadingFeaturesGLSL.h" +#endif static ShaderGen::ShaderGenInitDelegate sInitDelegate; @@ -100,11 +102,13 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureGLSL ); // Deferred Shading +#if defined(TORQUE_ADVANCED_LIGHTING) FEATUREMGR->registerFeature( MFT_isDeferred, new NamedFeatureGLSL( "Deferred Material" ) ); FEATUREMGR->registerFeature( MFT_DeferredSpecMap, new DeferredSpecMapGLSL ); FEATUREMGR->registerFeature( MFT_DeferredSpecVars, new DeferredSpecVarsGLSL ); FEATUREMGR->registerFeature( MFT_DeferredMatInfoFlags, new DeferredMatInfoFlagsGLSL ); FEATUREMGR->registerFeature( MFT_DeferredEmptySpec, new DeferredEmptySpecGLSL ); +#endif FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureGLSL( "skybox" ) ); FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureGLSL ); } diff --git a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp index 68c48435d2..c098851514 100644 --- a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp +++ b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp @@ -33,7 +33,9 @@ #include "materials/materialFeatureTypes.h" #include "core/module.h" // Deferred Shading +#if defined(TORQUE_ADVANCED_LIGHTING) #include "lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h" +#endif #include "shaderGen/HLSL/accuFeatureHLSL.h" static ShaderGen::ShaderGenInitDelegate sInitDelegate; @@ -100,12 +102,13 @@ void _initShaderGenHLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_ForwardShading, new NamedFeatureHLSL( "Forward Shaded Material" ) ); FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureHLSL ); - +#if defined(TORQUE_ADVANCED_LIGHTING) FEATUREMGR->registerFeature( MFT_isDeferred, new NamedFeatureHLSL( "Deferred Material" ) ); FEATUREMGR->registerFeature( MFT_DeferredSpecMap, new DeferredSpecMapHLSL ); FEATUREMGR->registerFeature( MFT_DeferredSpecVars, new DeferredSpecVarsHLSL ); FEATUREMGR->registerFeature( MFT_DeferredMatInfoFlags, new DeferredMatInfoFlagsHLSL ); FEATUREMGR->registerFeature( MFT_DeferredEmptySpec, new DeferredEmptySpecHLSL ); +#endif FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureHLSL( "skybox" ) ); FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureHLSL ); } diff --git a/Templates/BaseGame/game/core/globals.cs b/Templates/BaseGame/game/core/globals.cs index d4e4f1ca3d..5627ed7046 100644 --- a/Templates/BaseGame/game/core/globals.cs +++ b/Templates/BaseGame/game/core/globals.cs @@ -100,3 +100,7 @@ // SoftShadow - Does a simple soft shadow // SoftShadowHighQuality $pref::Shadows::filterMode = "SoftShadow"; + +/// This is the default list of light managers ordered from +/// most to least desirable for initialization. +$lightManager::defaults = "Advanced Lighting" TAB "Basic Lighting"; diff --git a/Templates/BaseGame/game/core/lighting.cs b/Templates/BaseGame/game/core/lighting.cs index 9ece7d1a07..ca890b3f40 100644 --- a/Templates/BaseGame/game/core/lighting.cs +++ b/Templates/BaseGame/game/core/lighting.cs @@ -40,16 +40,26 @@ function initLightingSystems(%manager) exec( %file ); %file = findNextFile( %pattern ); } - - // Try the perfered one first. - %success = setLightManager(%manager); - - // Did we completely fail to initialize a light manager? - if (!%success) + + // Try to initialize the selected light manager directly + // If this fails, try to initialize the light managers in order from most to least preferable + if (setLightManager(%manager)) { + return true; + } + else + { + for(%i = 0; %i < getFieldCount($lightManager::defaults); %i++) + { + %success = setLightManager(getField($lightManager::defaults, %i)); + + if (%success) + return true; + } + // If we completely failed to initialize a light // manager then the 3d scene cannot be rendered. - quitWithErrorMessage( "Failed to set a light manager!" ); + quitWithErrorMessage( "Failed to set a light manager!" ); } } diff --git a/Templates/BaseGame/game/data/defaults.cs b/Templates/BaseGame/game/data/defaults.cs index 33d7cd8f7e..ae01802c87 100644 --- a/Templates/BaseGame/game/data/defaults.cs +++ b/Templates/BaseGame/game/data/defaults.cs @@ -64,10 +64,6 @@ /// will try the defaults below. $pref::lightManager = ""; -/// This is the default list of light managers ordered from -/// most to least desirable for initialization. -$lightManager::defaults = "Advanced Lighting"; - /// A scale to apply to the camera view distance /// typically used for tuning performance. $pref::camera::distanceScale = 1.0;