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);
…
}
}
Currently, [url=https://zdoom.org/wiki/ZScript_global_variables#Creating_Global_Variables]the process for making a global variable in ZScript[/url] 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]
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);
…
}
}
[/code]