Can the process of setting something be explained to me?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Sparrow
Posts: 10
Joined: Mon Jul 02, 2012 4:14 pm

Can the process of setting something be explained to me?

Post by Sparrow »

Hey Guys, I've just started working with irrlicht 2 days ago after finding it to be the engine which has the best easy to usefull ratio of the tons I saw on the net. I'm working my way through the tutorials, and there's one thing that I just can't get around my head (actually quite a lot, but I'll bother you with that later) and that's things like this:

selector = smgr->createTriangleSelector(node);
node->setTriangleSelector(selector);
selector->drop();

Why do we drop the function that is used to do something to a node before we have even used it on the node. What I'm seeing is that it's not a function as such, but more of a process of attaching an appendage to a node which it will keep for the rest of the main loop?

If I'm not being clear, just shout.

Thanks
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Can the process of setting something be explained to me

Post by greenya »

You must do drop() for any create*() call you do.
In you particular example setTriangleSelector() will do grab() on selector arg (this way he states that he is going to use it and call drop() after all internally; for example when you do another setTriangleSelector() old selector will get drop() call and new one will get grab()). This is called "reference counting" as far as i know.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Can the process of setting something be explained to me

Post by randomMesh »

Yes, but the examples are stupid. You should drop things AFTER you are done with them, not right after initialization.
"Whoops..."
Sparrow
Posts: 10
Joined: Mon Jul 02, 2012 4:14 pm

Re: Can the process of setting something be explained to me

Post by Sparrow »

Thanks for the quick replies.

I see it's doing all this stuff in the main loop, it creates, edits then drops again. I don't get why you can't create outside the loop, and only have a function call for the transformations, or updates or things. All these pointers are also confusing, but that's not bad, I have to learn to see in pointers.
I'm not used to working with an engine in this way, it feels very hands off, I never see any of the functions that actually make the thing tick, its all just references of references. But, that's why I chose this engine, it seems more down to earth than most.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Can the process of setting something be explained to me

Post by hybrid »

Triangle selectors shouldn't be created in the render loop, these are resources which can be created one. And the examples in the SDK should be updated to not drop things before their last use. Maybe not the first one, to make relations clear between create* and drop. But all others were updated some time ago.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Can the process of setting something be explained to me

Post by REDDemon »

reference counting should take a tutorial separed from others. There's always someone asking about how to use reference counted stuff. Any idea to add a new example to SDK?
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply