5 registered members (Petra, AndrewAMD, VoroneTZ, 2 invisible),
822
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: the_clown]
#451024
04/27/15 12:12
04/27/15 12:12
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
It turns out that it works extremely well. Not everything inherits from Object though, only high level objects that are long lived, SceneNodes for example are objects whereas vectors (not the container kind) are not.
It does sacrifice a bit of cache locality, but brings tremendous up sides with it, so it's well worth it. Also given that many objects can form one/many-to-many relationships with each other, you would lose that cache locality anyway (parent -> child relationships of scene nodes for example).
There are many classes which don't inherit from object because they don't need to, and some go as far as being trivial classes to allow for fast copy operations.
On the other hand, we have one construct that is explicitly out to blow cache locality: The weak object table! Rayne gained smart pointer support that nicely wrap the Object class, and one of the smart pointers is a weak pointer which stores a reference to the object at runtime in the weak table. The weak table is a multi level hash table, with the top level having 8 buckets. The buckets are allocated as one large memory chunk, but each bucket is sized to be larger than a CPU cache line, so in an ideal world multiple CPUs accessing the weak table don't suffer from false sharing.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: the_clown]
#451278
05/01/15 12:56
05/01/15 12:56
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Actually, the scene itself should act as a container and retain the scene node. If you spawn for example a bunch of static scenery that you don't need to touch ever again, why be forced to keep a reference around and track that when the scene in reality is pretty much a container? When the scene is destroyed, it relinquishes all it references, and you don't need to track it.
There should also be ways to add and remove objects from a scene, for example, what if you have an object that is rather expensive to create so it's easier to just keep around and add it to the scene again when it's needed. An enemy for example, you shoot it dead, remove it from the scene and later put it back in when a new enemy needs to spawn. If your code requires a strong reference, then it should have it, no reason to force arbitrary limitations onto things.
There used to be a really dirty hack in Rayne that removed nodes that hit a retain count of 0 from the world, so over releasing a scene node was okay. I don't think that will make it back though.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
|