Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Petra, AndrewAMD, VoroneTZ, 2 invisible), 822 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 6 of 6 1 2 3 4 5 6
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 Offline
Expert
WretchedSid  Offline
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: WretchedSid] #451273
05/01/15 09:18
05/01/15 09:18
Joined: Nov 2008
Posts: 946
T
the_clown Offline OP
User
the_clown  Offline OP
User
T

Joined: Nov 2008
Posts: 946
Ah, I thought the weak table was to store the weak pointers for access from the object for bookkeeping - this way around it actually makes more sense.
One thing I'm still struggling with is the fact that everybody can just go and retain an object - what if you want to force deletion of an object? Like, for example, a SceneNode that should be removed from the scene? As far as I understand it, someone somewhere could always be storing a reference to it via a Retain() call, and would not be notified of the deletion because he's not using a weak pointer, so he's left with a dangling pointer. I wonder if there's a way to solve that, besides forcing everyone to use the weak pointer type.

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 Offline
Expert
WretchedSid  Offline
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
Page 6 of 6 1 2 3 4 5 6

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1