1+ #if HAVE_SCRIPTING
2+
13#include " convar.h"
24#include " Script/Script.h"
35#include " backend.h"
46
57namespace gamescope
68{
7- #if HAVE_SCRIPTING
89 namespace detail
910 {
1011 struct ConVarScriptRegistrar
@@ -30,23 +31,33 @@ namespace gamescope
3031 };
3132 }
3233
33- static auto s_ConCommandType = detail::ConVarScriptRegistrar::RegisterConCommand();
34- static auto s_CVBool = detail::ConVarScriptRegistrar::RegisterConVarType<bool >();
35- static auto s_CVInt = detail::ConVarScriptRegistrar::RegisterConVarType<int >();
36- static auto s_CVFloat = detail::ConVarScriptRegistrar::RegisterConVarType<float >();
37- static auto s_CVU32 = detail::ConVarScriptRegistrar::RegisterConVarType<uint32_t >();
38- static auto s_CVU64 = detail::ConVarScriptRegistrar::RegisterConVarType<uint64_t >();
39- static auto s_CVString = detail::ConVarScriptRegistrar::RegisterConVarType<std::string>();
40- static auto s_CVVCS = detail::ConVarScriptRegistrar::RegisterConVarType<VirtualConnectorStrategy>();
41- static auto s_CVTCM = detail::ConVarScriptRegistrar::RegisterConVarType<TouchClickMode>();
42-
4334 void ConCommand::RegisterScript ( std::string_view name, ConCommand *cmd )
4435 {
4536 CScriptScopedLock ().Manager ().Gamescope ().Convars .Base [name] = cmd;
4637 }
47- #else
48- void ConCommand::RegisterScript ( std::string_view, ConCommand * )
38+
39+ template <typename T>
40+ void ConVar<T>::RegisterScript( std::string_view name, ConVar<T> *cv )
4941 {
42+ CScriptScopedLock ().Manager ().Gamescope ().Convars .Base [name] = cv;
5043 }
51- #endif
44+
45+ #define REGISTER_CONVAR_TYPE_IMPL ( T, N ) \
46+ static auto s_ConVarType_##N = detail::ConVarScriptRegistrar::RegisterConVarType<T>(); \
47+ template void ConVar<T>::RegisterScript( std::string_view, ConVar<T> * );
48+
49+ #define REGISTER_CONVAR_TYPE_EXPAND ( T, N ) REGISTER_CONVAR_TYPE_IMPL ( T, N )
50+ #define REGISTER_CONVAR_TYPE ( T ) REGISTER_CONVAR_TYPE_EXPAND ( T, __COUNTER__ )
51+
52+ static auto s_ConCommandType = detail::ConVarScriptRegistrar::RegisterConCommand();
53+ REGISTER_CONVAR_TYPE ( bool )
54+ REGISTER_CONVAR_TYPE( int )
55+ REGISTER_CONVAR_TYPE( float )
56+ REGISTER_CONVAR_TYPE( uint32_t )
57+ REGISTER_CONVAR_TYPE( uint64_t )
58+ REGISTER_CONVAR_TYPE( std::string )
59+ REGISTER_CONVAR_TYPE( VirtualConnectorStrategy )
60+ REGISTER_CONVAR_TYPE( TouchClickMode )
5261}
62+
63+ #endif
0 commit comments