Replace Node Mesh for create Next Level

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
Greeg
Posts: 11
Joined: Wed Nov 25, 2015 11:57 am

Replace Node Mesh for create Next Level

Post by Greeg »

I'm creating new levels.
I do so...
I make "goto" in c++ and replace code execution on the create Irrlicht device line. And replase path in create node mesh place. Further, collision creating too, according to the rest of the program. Irrlicht create new device and run it with my new scene. All working. But device old windows is remain. Seems old windows not working becouse old scene immobilized. But it all incorrectly.
How correctly replace Node Mesh and update collision manadger for this new mesh?

Code: Select all

 
LevelRun:
int screenW=GetSystemMetrics(SM_CXSCREEN);//Получить ширину экрана
int  screenH=GetSystemMetrics(SM_CYSCREEN);//Получить высоту  экрана
    IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9,
    core::dimension2d<u32>(screenW,screenH),32, false, true); 
    device->getCursorControl()->setVisible(false);
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* scenemgr = device->getSceneManager();
    lstr = "media/";
    lstr+=LevelX;
    lstr+="/Scene.3ds";
        scene::IAnimatedMeshSceneNode* node = scenemgr->addAnimatedMeshSceneNode(
        scenemgr->getMesh(lstr));
      
    if (node)
    {
        node->setMaterialType(video::EMT_LIGHTMAP_LIGHTING);
        node->setMaterialFlag(video::EMF_LIGHTING, false);  
    }
 
        scene::IAnimatedMeshSceneNode* ComboBox = scenemgr->addAnimatedMeshSceneNode(
        scenemgr->getMesh("media/ComboBox.3ds"));
        ComboBox->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
 
        scene::IAnimatedMeshSceneNode* LevelUP = scenemgr->addAnimatedMeshSceneNode(
        scenemgr->getMesh("media/LevelUP.3ds"));
        LevelUP->setMaterialType(video::EMT_LIGHTMAP_LIGHTING);
        LevelUP->setMaterialFlag(video::EMF_LIGHTING, false);
        LevelUP->setPosition(core::vector3df(10000, 0, 0));
        LevelUP->setVisible(false);
   
    irr::scene::ICameraSceneNode* camera = scenemgr->addCameraSceneNodeFPS(0,150.0f,3.5f,-1,0,0,false,5.0f,false,true);
    camera->render();
    scene::ITriangleSelector* selector = scenemgr->createTriangleSelector(node);
    node->setTriangleSelector(selector);
    selector->drop();
    scene::ISceneCollisionManager* collMan = scenemgr->getSceneCollisionManager();
 
    scene::ISceneNodeAnimator* anim = scenemgr->createCollisionResponseAnimator(selector, ComboBox, core::vector3df(1, 1, 1), core::vector3df(0, 0, 0));
    selector->drop();
    ComboBox->addAnimator(anim);
    anim->drop();
 
    video::ITexture* stexture = driver->addTexture(core::dimension2d<u32>(1,1), "texture", video::ECF_A8R8G8B8);
    s32* p = (s32*)stexture->lock();
    p[0] = video::SColor(255,255,0,0).color;
    stexture->unlock();
    MyEventReceiver* receiver = new MyEventReceiver();
    device->setEventReceiver(receiver);
    while(device->run())
...
goto LevelRun;
...
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Replace Node Mesh for create Next Level

Post by CuteAlien »

Phew, there's several ways to approach this. First of all - you do _not_ want to create a new device for new levels. The device is connected with the window and you want to keep that open throughout in your game.

Now the easiest solution is - just don't remove old levels. Instead make the corresponding scenenode invisible and create a new one for the new stuff. Thought at some point this might mean you need too much memory (but do some quick calculations if that's really the case for your game - in most smaller games it simply doesn't matter). In that case - you can remove nodes (they have a remove() function) and you can clear meshes by accessing getMeshCache() from the scenemanager which has functions to remove meshes. Removing textures is more tricky. IVideoDriver has functions for it, but you have to be certain the textures are no longer needed by any meshes (for example: You use a texture in your first 2 levels. Then you can't remove the texture after level 1 easily).

Then a thing about c++ - you do not ever need "goto"! (every rule has exceptions, but for now forget about those and just never use goto). If you want to clear a scene then write a function that clears the scene. If you want to load a new scene then write a function to load scenes. And then call those functions when you need them (for example when the user presses a certain button).
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
Greeg
Posts: 11
Joined: Wed Nov 25, 2015 11:57 am

Re: Replace Node Mesh for create Next Level

Post by Greeg »

Thanks for your help.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Replace Node Mesh for create Next Level

Post by Mel »

goto is an unconditional jump, But if you need to go to a certain instruction, just write instead of the GOTO. if you need to jump back to repeat a certain code, use

do{
...
code
...
}while(true)

for instance. It is less risky, and when you need it, you may change the while condition to acomodate your needs, and, for instance, exit the loop at any moment. And read a good book about C++, is a friendly recomendation :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Greeg
Posts: 11
Joined: Wed Nov 25, 2015 11:57 am

Re: Replace Node Mesh for create Next Level

Post by Greeg »

I found solution right for me. It's scenemgr->clear();

Code: Select all

 
irr::IrrlichtDevice *device = device = createDevice(video::EDT_DIRECT3D9,
    core::dimension2d<u32>(screenW,screenH),32, false, true); 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* scenemgr = device->getSceneManager();
 
LevelRun:
    scenemgr->clear();
        //Next Node Mesh Links...
 
Clear() - delete old nodes from scene. And I can load node again, with new Pathes. It without Create new Device.
Post Reply