Just noticed there wasn’t a generic object in TempVars and I decided to implement something simple. It’s nothing very complicated, but it works.
I’m currently using this because many of my geometry spatials have user data set to them, but only those that have certain capabilities have it set. So when iterating through a node I’ve got to check if the user data is null. By using a generic object all I have to do is check if it’s null. If it isn’t then I can apply whatever “transformation”, if it is, I simply ignore the geometry.
Maybe that could be helpful to someone?
I’m not sure if more than 1 could be useful…
[patch]
+++ Locally Modified (Based On LOCAL)
@@ -227,4 +227,8 @@
*/
public final float[] bihSwapTmp = new float[9];
public final ArrayList<BIHStackData> bihStack = new ArrayList<BIHStackData>();
/**
* Generic Object<br />
*/<br />
public final MiscObject object = new MiscObject();
Using a TempVars.object.get/set I don’t have to instantiate a new object every frame to check. The “Something” only exists for geometries which support rotation (rotation period and orbital period). If I don’t do this check and hit a spatial without that userData I’ll get a crash if I try to cast it to a float.
If you call getUserData(“Thing”) on a spatial with a “Thing” that isn’t set you get a null when you fetch it. Right? So, if I want to rotate a node by X radian every frame, or a spatial (planet, sun, moon, etc) I have to check if that userData has been set on the spatial if I want to apply a rotation to it. To do so I would do the above:
[java]
Object blah = geom.getUserData(“Something”);
if (blah != null) {
// do this
}
[/java]
But that means that every frame I have to make an Object that I have to discard immediately after. By using a TempVars it’s MUCH easier on the GC.
The point is that there is no reason to have your temporary container object. It just creates extra garbage on the stack and extra method calls at best and creates a needless object at worst.
Object obj = spatial.getUserData( “foo” )
Will never cause additional GC because no object is created.
@pspeed said:
The point is that there is no reason to have your temporary container object. It just creates extra garbage on the stack and extra method calls at best and creates a needless object at worst.
Object obj = spatial.getUserData( "foo" )
Will never cause additional GC because no object is created.
So in a solar system with 10 planets (each with a potential of 0-5 moons) and up to 2 stars, each of these having a "PeriodRotation" and "OrbitRotation" set as UserData won't be creating new objects when fetched (to check for their existence) so I can rotate them when they do exist?
Considering that right now the game runs around 500FPS and assuming an average # of moons, all ~35 000 calls are not benefiting from this?
Creates no instances… it only grabs a reference. Which is all you would have been doing with your extra wrapper… plus two extra method calls and two extra field dereferences.
@madjack said:
Considering that right now the game runs around 500FPS and assuming an average # of moons, all ~35 000 calls are not benefiting from this?
No, they are actually suffering a little when you use the wrapper. A hardly noticeable amount but you are doing more work with the wrapper version... about 5 times as much.