Game Development Community

new = singleton

by Steve Acaster · in Torque 3D Professional · 10/14/2009 (7:39 pm) · 5 replies

I noticed that (eg - some materials) "new material" has changed to "singleton material", though "new" still works fine. Is this just to keep everything "nice and tidy"? Does the use of "singleton" over "new" enable more options in the background?

Just curious, that's all.

#1
10/14/2009 (7:44 pm)
I think the problem with new is that it overwrites the old. With singleton another attempt to create the same thing is just dropped and returns the originally generated one
#2
10/14/2009 (8:38 pm)
@Steve - Brief Singleton Syntax.

Let's say you have the following:

new ShaderData( SSAOShader )
{   
   DXVertexShaderFile 	= "shaders/common/postFx/postFxV.hlsl";
   DXPixelShaderFile 	= "shaders/common/postFx/ssao/SSAO_P.hlsl";            
   pixVersion = 3.0;
};

If you were to perform another new ShaderData(SSAOShader), the second one will fail to create. Now, if you are using singletons, it's a different story. If you create a second singleton ShaderData(SSAOShader), the properties of the second object will update/override the original.
#3
10/14/2009 (9:21 pm)
michael,
.. that's how new used to behave in TGE, ennit ?
#4
10/14/2009 (10:36 pm)
@Orion - I know it did not fully support what the singleton keyword can do. It may have completely overridden instead of just updating.
#5
10/15/2009 (3:59 am)
yes.. it does seem different.
in TGE, if you issued a second New with the same object name,
it created a new object and assigned the global name to it.

so both objects would report their name the same, and answer to the same namespace, but referencing the global name would reference the latter.

this was sometimes hell and sometimes convenient.

interesting, this new stuff. ;)