Fast global/static variables

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Fast global/static variables

Post by argv »

Currently, the process for making a global variable in ZScript implies a severe performance penalty (from iterating over all live thinkers, plus adding to think time per tic) and/or a waste of memory (from having a pointer to the MyGlobalVariables instance in every object that needs access to it).

Please consider adding support for global/static variables that doesn't involve such an expensive lookup, preferably with some way to initialize them at startup (without the overhead of using an event handler for this purpose).

Alternatively, you might add “singleton objects”: a declaration of an object that has its own type, has exactly one global instance at all times, and is constructed and initialized at startup. Example of this idea:

Code: Select all

object MyGlobalVariables
{
	int testVar;

	{
		testVar = 42;
		Console.Printf("MyGlobalVariables.testVar was initialized to %d.", testVar);
	}
}

class MyActorClass : Actor
{
	states
	{
		Spawn:
			TNT1 A 0 nodelay A_SomeAction(MyGlobalVariables.testVar);
			…
	}
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Fast global/static variables

Post by Graf Zahl »

No, definitely not like this. What you MAY get is global UI variables, but global play variables are definitely out. They will have to be stored in the playsim and serialized along with it and the only way to do that is as a thinker. Just as importantly, they will have to be reset when the user starts a new game. The best that can be done is to optimize the access to a global variable storage object, but that's it.
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Re: Fast global/static variables

Post by argv »

Ah, good point. Okay, that's fine too!
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Fast global/static variables

Post by Major Cooke »

How can that be optimized? I'd like to know so I can do so with my own.

Right now I'm more-so just relying upon an event handler to store it and do all that jazz in itself.
User avatar
Leonard2
Posts: 313
Joined: Tue Aug 14, 2012 6:10 pm

Re: Fast global/static variables

Post by Leonard2 »

Graf Zahl wrote:The best that can be done is to optimize the access to a global variable storage object, but that's it.
Why wasn't that done as a temporary solution?
That could be done while we wait on something like this.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Fast global/static variables

Post by Graf Zahl »

How about "I didn't have the time to do it yet"? Just to refresh your memory, ever since I started a new job I barely have any free time left to work on GZDoom and really prefer to spend my weekends away from the computer.
User avatar
Leonard2
Posts: 313
Joined: Tue Aug 14, 2012 6:10 pm

Re: Fast global/static variables

Post by Leonard2 »

That's fine, no need to be on the defensive here, I was genuinely asking in case you had decided against this because the post I linked is from 2016 and I wasn't really aware of your situation at that point.
Post Reply

Return to “Feature Suggestions [GZDoom]”