Pointer to pointer array of scene nodes

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.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Pointer to pointer array of scene nodes

Post by serengeor »

robmar wrote:what size constant? I think this all seems so simple, that is until you try it! Then you get Error! Void and abstract class ptr to ptrs not legal...
Array of pointers is always possible, array of abstract objects is not possible.
If you had taken a look at the link I gave you where this code was you would see that it compiled fine and executed like it should.
CuteAlier wrote:But what I couldn't figure out is the additional size restriction - so the function can only pass a pointer to an array of a certain size.
Could you clarify this sentence?
Working on game: Marrbles (Currently stopped).
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

Well, in the first post - he uses MAX_LIGHTS. So I thought the idea is passing an array of a constant size - and only of that constant size. I didn't try for long, but I failed with restricting the function parameter to allow only that (passing that as value is again easy syntax).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Pointer to pointer array of scene nodes

Post by randomMesh »

I didn't try it, but maybe ellipses can help here.
"Whoops..."
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Please no more comments unless you have tried it and proved it! Thanks!
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Pointer to pointer array of scene nodes

Post by randomMesh »

Lol, i won't write your code. If you don't want hints and suggestions, don't ask questions here.
"Whoops..."
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

Don't confuse him even more - there is no need for eclipses here :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Don´t waste your time then if you´re not interested in bothering to test even your own ideas.

The aim is to find the best way to have a ptr to an array of ptrs, and ideally using [indexing] for access, not ptr+offset math, which isn´t always portable.

Ellipses, eclipses, brackets ?? [], parenthesis == ()!?
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Pointer to pointer array of scene nodes

Post by randomMesh »

Pathetic.

Ever heard of brainstorming? I won't stop posting my thoughts. Feel free to ignore them if you think they can't help.
"Whoops..."
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Well sure, any ideas welcome, feel free to post!
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Pointer to pointer array of scene nodes

Post by randomMesh »

If i got you right, you want to pass a void pointer to an array of ILightSceneNode pointers to a callback.

This compiles on g++ 4.4.5.

Code: Select all

 
#include <irrlicht.h>
 
void someCallback(void* array[], unsigned int numLights)
{
    for (unsigned int i = 0; i < numLights; ++i)
    {
        irr::scene::ILightSceneNode* light = reinterpret_cast<irr::scene::ILightSceneNode*>(array[i]);
        light->setID(i+1);
    }
}
 
int main()
{
    irr::IrrlichtDevice* device = irr::createDevice(irr::video::EDT_NULL);
    irr::scene::ISceneManager* smgr = device->getSceneManager();
 
    unsigned int numLights = 2;
 
    irr::scene::ILightSceneNode* someLightSceneNodeArray[numLights];
 
    someLightSceneNodeArray[0] = smgr->addLightSceneNode();
    someLightSceneNodeArray[1] = smgr->addLightSceneNode();
 
    someCallback(reinterpret_cast<void**>(someLightSceneNodeArray), numLights);
 
    printf("ID is %d\n", someLightSceneNodeArray[0]->getID());
    printf("ID is %d\n", someLightSceneNodeArray[1]->getID());
 
    device->drop();
 
    return 0;
}
 
"Whoops..."
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Pointer to pointer array of scene nodes

Post by serengeor »

robmar wrote: The aim is to find the best way to have a ptr to an array of ptrs, and ideally using [indexing] for access, not ptr+offset math, which isn´t always portable.
Well my snippet does that just fine, so I don't really get what else you need.

I don't really think size restriction is a good idea anyways.

Seriously, here's another test if you don't believe it works: http://ideone.com/YTFGtC

And why would you even need ptr+offset, it's not "2D" array.
Working on game: Marrbles (Currently stopped).
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

@ randomMesh: Isn't a static_cast enough in this case? Should be I think (and yeah, I'm not compiling - done enough coding today ^_^).
edit: Also I agree it's certainly better passing the size parameter instead of a constant size. I'm just curious about the constant thing because I can't figure that one out (at least not without starting to browse google etc).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Pointer to pointer array of scene nodes

Post by randomMesh »

No, using a static_cast would give an error

Code: Select all

 
error: invalid static_cast from type ‘irr::scene::ILightSceneNode* [(((unsigned int)(((int)numLights) + -0x00000000000000001)) + 1)]’ to type ‘void**’
 
"Whoops..."
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

Seems that it's indeed needed in second case. Confusing.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

@randonmesh: No, it was to be able to pass a (ILightSceneNode *array[8]) pointer to a callback, so the callback could extract light positions directly.

VS C++ rejects it saying its an abstract class and not allowed, so I´ve had to pass (vector3df *array[8]), which works, but then I have to reload the array in the run loop each frame cycle.

As the size of the array is related to the size of a memory pointer, which is the same for all things, can´t see why the compiler should not allow it for classes, or void ptrs, which is even stranger!

There must be some ISO wisdom there somewhere... or something obvious... but what?
Post Reply