mapchange ?

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
Angelus
Posts: 7
Joined: Thu Apr 06, 2006 4:51 pm

mapchange ?

Post by Angelus »

Hello,
i´ve got a basic question on mapchanges ...
How can i load a new map, when my camera arrives at a specific position in the current map (for example a door or something like that ...) ?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Check the position or collision and if you there, unload the old meshes and create new ones...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
cadue
Posts: 72
Joined: Mon Mar 13, 2006 8:33 pm
Location: Italy - Friuli - Monfalcone - Staranzano

Post by cadue »

It's simple:

Code: Select all


//load first map
IAnimatedMeshSceneNode* map1 = smgr->addAnimatedMeshSceneNode(smgr->getMesh(...));

//load second map
IAnimatedMeshSceneNode* map2 = smgr->addAnimatedMeshSceneNode(smgr->getMesh(...));
map2->setVisible(false);
//create camera
ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();



while(device->run())
{

vector3df camPos = camera->getPosition();
if(camPos.X > ... && camPos.X < ... && camPos.Z > ... && camPos.Z < ...){
map1->setVisible(false);
map2->setVisible(true);
}

smgr->drawAll();
guienv->drawAll();   
driver->endScene();

}

excuse me for my bad english and for my ignorance...but I'm 14 and i come from Italy, where the study of english is a optional (-:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Yes, you can do it this way if you're using only a few meshes...
But you'll have all meshes in memory, all the time !!!
Let's say you have a really big game with many maps (for example The Elder Scrolls series), then you have 100s of maps in memory...
Not talking about all the object meshes...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Angelus
Posts: 7
Joined: Thu Apr 06, 2006 4:51 pm

Post by Angelus »

thank you ... i will try it
luckymutt
Posts: 453
Joined: Sun Mar 06, 2005 11:56 pm
Location: C-Ville

Post by luckymutt »

@Acki -
would the only way to do it be to load and unload meshes like:

Code: Select all

while(device->run()) 
{
if(camera blah...) {
 drop->first mesh
 IAnimatedMeshSceneNode* map2 = smg->addAnimatedMeshSceneNode(smgr->getMesh(...));
...
...
...
}
:?:
I thought I read somewhere that it wasn't good to load/unload in the 'while'...but I dunno
Join us in the Irrlicht chatroom:
[url]irc://irc.freenode.net/irrlicht[/url]

I love deadlines. I like the whooshing sound they make as they fly by. -D.Adams
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, it's always done inside the while, because it's the main loop...
Even if you call a function, it's always inside the main loop...
What you never should do is to do this between beginScene and endScene !!!

Now, I would call a function, create a loading screen and do the removings and creatings in there ...

Code: Select all

while(device->run()){
  driver->beginScene(true, true, SColor(255,100,101,140));
  smgr->drawAll();
  guienv->drawAll();
  driver->endScene();
  if(cam == endPos) loadNewMap();
}

void loadNewMap(){
  guienv->addImage(loadingScreen);
  driver->beginScene(true, true, SColor(255,100,101,140));
  guienv->drawAll();
  driver->endScene();
  smgr->getRootSceneNode()->removeAll();
  // create new map and objects
  ...
}

BTW: always think about there are many ways to do something, this is only one solution I think it's a good choice...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply