I create inventory item which do effect function do some effect depending of cvar variables.
But at map with huge amount of actors, find cvar function inside of it cause extremely heavy lags, up to game freeze.
So, is there are any way to create local, mods, storage of variable, which can be acessed, and changed, by any actor? And I say not only about cvars.
Easily accessible storage of variables
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: Easily accessible storage of variables
I assume you mean actor variables like stamina or mass, rather than cvars (console variables) like autoaim and allowcrouch.
In which case I too would like to know this - is there a generic "findvariable" function in ZS?
In which case I too would like to know this - is there a generic "findvariable" function in ZS?
Re: Easily accessible storage of variables
I can try to answer this specifically regarding CVars. One thing I do is cache the result of FindCVar in an instance variable so I don't have to do it every tick. That might help, although I have not measured this to see if it actually makes a difference on speed. See this class, which does FindCVar inside PostBeginPlay, after which it can just call SetInt and GetInt on the CVar.
If it's still too slow after that tweak, then perhaps the Get call on the CVar is also slow. In that case, perhaps you could try making a global variable singleton (or maybe an EventHandler) that polls the CVar on Tick and caches the value in a global variable? I'm not sure if this would actually help... you'd have to try it and see.
If it's still too slow after that tweak, then perhaps the Get call on the CVar is also slow. In that case, perhaps you could try making a global variable singleton (or maybe an EventHandler) that polls the CVar on Tick and caches the value in a global variable? I'm not sure if this would actually help... you'd have to try it and see.
Re: Easily accessible storage of variables
Be careful with this! CVar objects can't be saved to a save file properly so without the transient keyword, this will cause a crash upon saving. If you define the CVar as being transient CVar whatever; it won't crash on saving, but this keyword means that the object isn't serialised, so you need to get the object back upon loading a save (I believe that StaticEventHandlers allow you to use WorldLoaded for this).Eliot_L wrote:I can try to answer this specifically regarding CVars. One thing I do is cache the result of FindCVar in an instance variable so I don't have to do it every tick.
Re: Easily accessible storage of variables
Thanks for the tip! I'll set mine to transient, they don't need to persist.
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: Easily accessible storage of variables
This applies to CVar objects only, right? Not any int, string, etc. that you might get from it?Gutawer wrote:CVar objects can't be saved to a save file properly so without the transient keyword, this will cause a crash upon saving.
Re: Easily accessible storage of variables
Yeah I think it's just to tell the ZScript runtime not to try to save/load the CVar object.
It would be awfully handy if there was a virtual function for a class getting deserialized so you could more easily handle the case of having to re-initialize your transient members, but I don't see such a thing at the moment. Or just a way to lazy-initialize them. For now I might get rid of this as it may be more trouble than it's worth to handle save/load scenario...
It would be awfully handy if there was a virtual function for a class getting deserialized so you could more easily handle the case of having to re-initialize your transient members, but I don't see such a thing at the moment. Or just a way to lazy-initialize them. For now I might get rid of this as it may be more trouble than it's worth to handle save/load scenario...