Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/RenderingOptions.h
Show All 13 Lines | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
/** | /** | ||||
* Keeps track of the settings used for rendering. | * Keeps track of the settings used for rendering. | ||||
* Ideally this header file should remain very quick to parse, | * Ideally this header file should remain very quick to parse, | ||||
* so avoid including other headers here unless absolutely necessary. | * so avoid including other headers here unless absolutely necessary. | ||||
* | |||||
* Lifetime concerns: g_RenderingOptions always exists, but hooks are tied to the configDB's lifetime | |||||
* an the renderer may or may not actually exist. | |||||
*/ | */ | ||||
#ifndef INCLUDED_RENDERINGOPTIONS | #ifndef INCLUDED_RENDERINGOPTIONS | ||||
#define INCLUDED_RENDERINGOPTIONS | #define INCLUDED_RENDERINGOPTIONS | ||||
class CStr8; | class CStr8; | ||||
class CRenderer; | class CRenderer; | ||||
Show All 20 Lines | class CRenderingOptions | ||||
// The renderer needs access to our private variables directly because capabilities have not yet been extracted | // The renderer needs access to our private variables directly because capabilities have not yet been extracted | ||||
// and thus sometimes it needs to change the rendering options without the side-effects. | // and thus sometimes it needs to change the rendering options without the side-effects. | ||||
friend class CRenderer; | friend class CRenderer; | ||||
public: | public: | ||||
CRenderingOptions(); | CRenderingOptions(); | ||||
~CRenderingOptions(); | ~CRenderingOptions(); | ||||
void ReadConfig(); | void ReadConfigAndSetupHooks(); | ||||
void ClearHooks(); | |||||
#define OPTION_DEFAULT_SETTER(NAME, TYPE) \ | #define OPTION_DEFAULT_SETTER(NAME, TYPE) \ | ||||
public: void Set##NAME(TYPE value) { m_##NAME = value; }\ | public: void Set##NAME(TYPE value) { m_##NAME = value; }\ | ||||
#define OPTION_CUSTOM_SETTER(NAME, TYPE) \ | #define OPTION_CUSTOM_SETTER(NAME, TYPE) \ | ||||
public: void Set##NAME(TYPE value);\ | public: void Set##NAME(TYPE value);\ | ||||
#define OPTION_GETTER(NAME, TYPE)\ | #define OPTION_GETTER(NAME, TYPE)\ | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#undef OPTION_DEFAULT_SETTER | #undef OPTION_DEFAULT_SETTER | ||||
#undef OPTION_CUSTOM_SETTER | #undef OPTION_CUSTOM_SETTER | ||||
#undef OPTION_GETTER | #undef OPTION_GETTER | ||||
#undef OPTION_DEF | #undef OPTION_DEF | ||||
#undef OPTION | #undef OPTION | ||||
#undef OPTION_WITH_SIDE_EFFECT | #undef OPTION_WITH_SIDE_EFFECT | ||||
private: | private: | ||||
/** | |||||
* Registers a config hook for config variable @name that updates @variable. | |||||
* Also immediately updates variable with the value of the config. | |||||
*/ | |||||
template<typename T> | |||||
void SetupConfig(CStr8 name, T& variable); | |||||
/** | |||||
* Registers a config hook for config variable @name. | |||||
* Also immediately triggers the hook. | |||||
*/ | |||||
void SetupConfig(CStr8 name, std::function<void()> hook); | |||||
class ConfigHooks; | class ConfigHooks; | ||||
std::unique_ptr<ConfigHooks> m_ConfigHooks; // Hide this via PImpl to avoid including ConfigDB.h here. | std::unique_ptr<ConfigHooks> m_ConfigHooks; // Hide this via PImpl to avoid including ConfigDB.h here. | ||||
}; | }; | ||||
extern CRenderingOptions g_RenderingOptions; | extern CRenderingOptions g_RenderingOptions; | ||||
#endif // INCLUDED_RENDERINGOPTIONS | #endif // INCLUDED_RENDERINGOPTIONS |
Wildfire Games · Phabricator