How to unload the current map and load a new one?

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
~ Dream
Posts: 12
Joined: Fri Jun 29, 2007 11:28 am
Location: The Dream World

How to unload the current map and load a new one?

Post by ~ Dream »

Hi, I need some help on unloading (or removing) the current map that is successfully loaded into another map. Below is the codes I added after driver->endScene(); and before int fps = driver->getFPS(); from the Collison tutorial.

Code: Select all

core::vector3df pos = camera->getPosition();
		double xC = pos.X;
		double yC = pos.Y;
		double zC = pos.Z;
		std::cout<<"X "<<xC<<" Y "<<yC<<" Z "<<zC<<std::endl;

		if (xC <= -2070 && xC >= -2170){
			if (yC <= 260 && yC >= 210){
				if (zC <= -1670 && zC >= -1700){
					//insert codes here to remove the first map?
device->getFileSystem()->addZipFileArchive("../maps/TeamTemple_q3a.pk3");
					q3levelmesh = smgr->getMesh("TeamTemple_q3a.bsp");
					q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));

					camera = 
						smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, true);
					camera->setPosition(core::vector3df(-2827,30,-701));

					anim = smgr->createCollisionResponseAnimator(
						selector, camera, core::vector3df(90,50,30),
						core::vector3df(0,-1,0), 
						core::vector3df(0,50,0));
					camera->addAnimator(anim);
					anim->drop();
				}
			}
		}
The current problem I have is that whenever I reach the location I specific, the current map (in my case, water.b3d) is loaded in the new coordinates instead of the other map (TeamTemple_q3a.pk3) I wanted to load.

Thanks for your time.
~ Dream
Quall
Posts: 154
Joined: Mon Mar 07, 2005 10:16 pm

Post by Quall »

I am not sure I understand your issue.

Is the q3levelmesh object already defined before this line?

Code: Select all

q3levelmesh = smgr->getMesh("TeamTemple_q3a.bsp"); 
If so I suggest you destroy it before re-defining.

Also, you never set the position of the new bsp mesh. Is that your issue?

Code: Select all

q3node->setPosition(core::vector3df(123,231,312));
~ Dream
Posts: 12
Joined: Fri Jun 29, 2007 11:28 am
Location: The Dream World

Post by ~ Dream »

hi, I wonder how do I destroy the originally created object? I'm quite new to C++.

And I also edited part of the codes to this.

Code: Select all

		if (xC <= -2070 && xC >= -2170){
			if (yC <= 260 && yC >= 210){
				if (zC <= -1670 && zC >= -1700){
					//remove the first map
					device->getFileSystem()->addZipFileArchive("../maps/TeamTemple_q3a.pk3");
					q3levelmesh = smgr->getMesh("TeamTemple_q3a.bsp");
					q3node = 0;
					q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));
					q3node->setPosition(core::vector3df(-1350,-1300,-1400));
					selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);

					camera = 
						smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, true);
					camera->setPosition(core::vector3df(-2827,30,-701));

					anim = smgr->createCollisionResponseAnimator(
						selector, camera, core::vector3df(90,50,30),
						core::vector3df(0,-1,0), 
						core::vector3df(0,50,0));
					camera->addAnimator(anim);
					anim->drop();
				}
			}
		}
It loads the second map but the camera first shows the first map at core::vector3df(-2827,30,-701) then the screen drops due to gravity and thus then reaches the second map. But if I use q3node->setPosition(core::vector3df(-1350,-130,-1400)); which was the location of the original map instead of q3node->setPosition(core::vector3df(-1350,-1300,-1400)); there will not be a dropping scene but the textures of the first map can be seen on the second map and thus the camera can walk through walls of the first map but not the second.
picture of first map
~ Dream
Post Reply