Page 1 of 1

Can't get rid of IAnimatedMeshSceneNode's

Posted: Sun Mar 01, 2009 6:03 pm
by Sollos
In my game, I have enemy models as IAnimatedMeshSceneNode's; and I'm trying to find a way to be able to remove them from my game world. I try to use drop(), remove(), setVisible(false), but none of them work.

main.cpp

Code: Select all

for (secondIter = destination.begin(); secondIter != destination.end(); secondIter++)
{
enemy zombie(driver, smgr, 3000, false, origin.getX(), origin.getZ(), player->getPosition().X, player->getPosition().Z);
}
enemy.cpp

Code: Select all

if (timer.elasped(3000))
{
//mob->remove();
//mob->drop();
//mob->setVisible(false);
}

Posted: Sun Mar 01, 2009 6:08 pm
by bitplane
remove() should work fine, can you reproduce the problem using the hello world example?
If so, it's probably a problem with your code. Make sure you're removing the correct node!

edit: I'm having trouble understanding what that code does. Looks like you're creating lots of zombies in a loop, but they only exist local to that loop and will be destroyed when you leave it. Do they clean up after themselves?

Posted: Sun Mar 01, 2009 6:32 pm
by Sollos
bitplane wrote:remove() should work fine, can you reproduce the problem using the hello world example?
If so, it's probably a problem with your code. Make sure you're removing the correct node!

edit: I'm having trouble understanding what that code does. Looks like you're creating lots of zombies in a loop, but they only exist local to that loop and will be destroyed when you leave it. Do they clean up after themselves?
Nope. Once the zombies reach their objective position, they just chill out there forever.

I'll go back and try to see if I can get it to work in a more hello-world example.

Posted: Sun Mar 01, 2009 6:44 pm
by vitek
Sollos wrote:Nope. Once the zombies reach their objective position, they just chill out there forever.
So you create the zombie, it moves to the destination position, and waits there, all in the loop you show above? When does the scene get rendered then?

It looks to me like you have some misunderstanding about how the engine works or what your code does. Any local variable declared inside a scope will be destroyed at the end of that scope. That means that each enemy object you construct inside the loop will be destructed automatically before the next loop iteration. That loop essentially creates a enemy and then immediately destroys it, repeating N times. This means that the code that you have with the timer will never execute because the enemy is destroyed as soon as it is created (the elapsed time never reaches 3000 before the zombie is destroyed). If the scene nodes remain after running this loop, then you need to remember to call mob->remove() from the enemy destructor. This is also a pretty good hint that you need to define (or at least declare private) a copy constructor and assignment operator.

Travis

Posted: Mon Mar 02, 2009 8:24 pm
by Sollos
Still haven't been able to figure it out. I added the destructor since I didn't have it before, but the enemy models still go to their destination and just stay there forever.

enemy.cpp

Code: Select all

#include "enemy.h"

irr::scene::IAnimatedMeshSceneNode* mob;

enemy::enemy()
{

}

enemy::~enemy()
{
        mob->remove();
}

void enemy::killHumansKThx(irr::video::IVideoDriver* driver, irr::scene::ISceneManager* smgr, int speed, bool repeat, int initX, int initZ, int finalX, int finalZ)
{
        mob = smgr->addAnimatedMeshSceneNode(smgr->getMesh("media/hydralisk/tris.md2"));

        if (mob)
        {
                irr::scene::ISceneNodeAnimator* anim1 = smgr->createFlyStraightAnimator(
                        irr::core::vector3df(initX, -65, initZ),
                        irr::core::vector3df(finalX, -65, finalZ),
                        speed, repeat);

                if (anim1)
                {
                        mob->addAnimator(anim1);
                        anim1->drop();
                }

                mob->setMaterialFlag(irr::video::EMF_LIGHTING, false);
                mob->setMD2Animation(irr::scene::EMAT_RUN);
                mob->setScale(irr::core::vector3df(2.5f, 2.5f, 2.5f));
                mob->setMaterialTexture(0, driver->getTexture("media/hydralisk/lisc.pcx"));
        }
}
main.cpp

Code: Select all

void createZombies (irr::scene::ICameraSceneNode* player, irr::video::IVideoDriver* driver, irr::scene::ISceneManager* smgr)
{
        for (Iter = waypointSystem.begin(); Iter != waypointSystem.end(); Iter++)
        {
                twovar origin = (*Iter).first;
                std::vector<twovar> destination = (*Iter).second;

                std::vector<twovar>::iterator secondIter;
                for (secondIter = destination.begin(); secondIter != destination.end(); secondIter++)
                {
                        zombie.killHumansKThx(driver, smgr, 3000, false, origin.getX(), origin.getZ(), (int) player->getPosition().X, (int) player->getPosition().Z);
                        zombie.setRotation(irr::core::vector3df(0,directionSolver(origin.getX(), origin.getZ(), secondIter->getX(), secondIter->getZ()),0));
                }
        }
}
I left out a lot of unneccessary code, so the variables that might seem undefined, are defined and working properly.