Fast global/static variables

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is ON
[img] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Fast global/static variables

Re: Fast global/static variables

by Leonard2 » Fri Nov 24, 2017 12:41 pm

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.

Re: Fast global/static variables

by Graf Zahl » Fri Nov 24, 2017 11:13 am

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.

Re: Fast global/static variables

by Leonard2 » Fri Nov 24, 2017 9:34 am

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.

Re: Fast global/static variables

by Major Cooke » Fri Nov 24, 2017 8:13 am

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.

Re: Fast global/static variables

by argv » Thu Nov 23, 2017 3:50 pm

Ah, good point. Okay, that's fine too!

Re: Fast global/static variables

by Graf Zahl » Mon Nov 20, 2017 1:25 am

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.

Fast global/static variables

by argv » Sun Nov 19, 2017 11:27 pm

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);
			…
	}
}

Top