[1.12] Unique Id for Node

What it says on the tin: a place to discuss proposed new features.
User avatar
cc9cii
Greenskin
Posts: 103
Joined: Tue Sep 18, 2018 4:53 am
x 20

[1.12] Unique Id for Node

Post by cc9cii »

Hi,

Names in Nodes (and SceneNodes) are no longer unique and auto-generated ones without names just have bank strings (since version 1.11.0).

It would be quite useful to have unique ids, though, like the way Ogre 2.x does. Any plans for such in the near future?

Thanks,
paroj
OGRE Team Member
OGRE Team Member
Posts: 2108
Joined: Sun Mar 30, 2014 2:51 pm
x 1134

Re: [1.12] Unique Id for Node

Post by paroj »

cc9cii wrote: Thu Jul 23, 2020 7:46 am It would be quite useful to have unique ids, though, like the way Ogre 2.x does. Any plans for such in the near future?
whats wrong with using the returned SceneNode* for this?
User avatar
cc9cii
Greenskin
Posts: 103
Joined: Tue Sep 18, 2018 4:53 am
x 20

Re: [1.12] Unique Id for Node

Post by cc9cii »

Hi,

In most cases SceneNode* is enough. However there are some use-cases where having a non-pointer identifier is useful/convenient:
  • Because SceneNode and Node share the same identifier (Ogre::String or Ogre::IdType) it is possible to know just the parent and find the children using something like Node::getChildren() then getName()/getId(). Using this certain actions can be performed on the children.

    If using only SceneNode*, we would get back Node* from getChildren() then probably have to do a dynamic_cast to get SceneNode*. Not the end of the world, but a little less convenient.
  • I have a use-case where the SceneNode/Node identifier is used as the one that binds Ogre objects and Bullet objects. But sometimes we may wish to create only the collision (i.e. Bullet) object. If using a String/IdType identifier this is straight-forward, either by just creating a unique string or by using something like Ogre::Id::generateNewId<Ogre::Node>().

    If using only SceneNode*, a real SceneNode would have to be created and assigned to each of these collision objects then later destroyed. Admittedly, this could be better than using IdType since it is not possible to re-use the auto-generated numbers (but if using 64 bit number that would essentially become a non-issue).
  • Since we identify objects using the SceneNode, we allow console commands / scripts to use the identifier. Here having a string is most useful but numbers are ok. But it is not possible to use SceneNode* at all - we would have to maintain a map of SceneNode* to string/id and allow access to that map from many places. Again not impossible, but certainly way less convenient.
  • The last point is just for the sake of consistency between Ogre 1.x and Ogre 2.x. If anyone migrates from 1.12 to 2.2, it would be less challenging to do so (it is difficult enough as it is :))
Cheers,
paroj
OGRE Team Member
OGRE Team Member
Posts: 2108
Joined: Sun Mar 30, 2014 2:51 pm
x 1134

Re: [1.12] Unique Id for Node

Post by paroj »

cc9cii wrote: Thu Jul 23, 2020 11:37 pm
  • Because SceneNode and Node share the same identifier
in this case the also share the ptr. i.e.:

Code: Select all

Node* node = ...
static_cast<SceneNode>(node) == node
-> true
cc9cii wrote: Thu Jul 23, 2020 11:37 pm
  • Since we identify objects using the SceneNode, we allow console commands / scripts to use the identifier. Here having a string is most useful but numbers are ok. But it is not possible to use SceneNode* at all - we would have to maintain a map of SceneNode* to string/id and allow access to that map from many places.
this is exactly what the SceneManager is doing internally, if you provide a node-name at creation time. This means, you still can get the old behaviour, if you come up with node-names yourself (or instantiate a Ogre::NameGenerator).
The idea here is that users should not have to pay for what they dont use (memory overhead & slowed down creation time in this case).

I did not get your second example.
User avatar
cc9cii
Greenskin
Posts: 103
Joined: Tue Sep 18, 2018 4:53 am
x 20

Re: [1.12] Unique Id for Node

Post by cc9cii »

paroj wrote: Fri Jul 24, 2020 12:59 am I did not get your second example.
I guess I'm just saying that we were using Ogre auto-generated SceneNode names as object identifiers. Because it was a string (easy to use) and unique. A string could be, and was used as identifiers for *all* objects including objects without Ogre rendering (i.e. bullet collision objects).

Having extra few thousand of strings is not really an issue with memory and when they are no longer needed they are discarded anyway. But having extra thousands of SceneNode to use its pointers as identifiers wouldn't be so cheap (memory use) or fast to create/destroy. (i.e. the point I'm trying to make is that it doesn't make sense for this particular app to use SceneNode* as object identifiers, since you asked what's wrong with using them)