View Single Post
PatriotGames
AlliedModders Donor
Join Date: Feb 2012
Location: root@irs:/# rm -rf /
Old 02-05-2019 , 21:37   Re: To hook or not to hook, that is the question.
Reply With Quote #5

Quote:
Originally Posted by impossible_cc View Post
Edit:
if all of that is int, not convar, then do like this
PHP Code:
void SomeFunction()
{
    
g_cvSomeCvar.IntValue =  g_iAnotherCvar g_iYetAnotherCvar g_iSomeConstant;

Thank you, impossible_cc. So the IntValue methodmap property can work like both GetConVarInt and SetConVarInt functions even in the same statement. Interesting...

Quote:
Originally Posted by asherkin View Post
There is no difference pre- or post-methodmaps, convar handles have always been cached, and convars do the value conversions when they're set so getting values is just copying memory.
So there's no performance advantage to hooking cvar change and creating a var (bool, int, float) to track it over simply calling the cvar value? And...
PHP Code:
void SomeFunction()
{
    
g_cvSomeCvar.IntValue g_iAnotherCvar.IntValue g_iYetAnotherCvar.IntValue g_iSomeConstant;

    
// and...
    
    
SetConVarInt(g_cvSomeCvar) = (GetConVarInt(g_iAnotherCvar) + GetConVarInt(g_iYetAnotherCvar) * g_iSomeConstant);

    
// are equivalent and one has no performance advantage over the other?

So, when and why would we use:
PHP Code:
g_cvMyCvar.AddChangeHook(MyCallback); 
Thank you for the help,
PG

Last edited by PatriotGames; 02-05-2019 at 21:58.
PatriotGames is offline