Proper way to change scenes within game

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
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Proper way to change scenes within game

Post by raistca »

Ok so I'm working on a game where there are basically two main views, the typical "world view" where you run around and the "battle view," where (spoiler alert!) you fight battles.
These two views will require totally different scenes, so I'm wondering what do I need to do in order to switch between them?

Thoughts I've had so far are: drop the device and make a new one (that doesn't seem to work so well)

And well that's all I've got. Suggestions very appreciated, examples will be returned with feet-kissing.
Iyad
Posts: 140
Joined: Sat Mar 07, 2009 1:18 am
Location: Montreal, Canada

Post by Iyad »

Dont drop the device only for changing the scene! Only try to program a efficient way to manage your scene meshes in both views. I would suggest that you save all elements from the world view when changing to battle view, then reloaded them back when the battle is ended. Or you can simply change the camera position, draw your battle view elsewhere, and return to old position in world view...
#include <Iyad.h>
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Post by raistca »

Well for now I'm just using a 2d map for the world view (and may keep it that way), how would that work since 2d images don't need cameras?

Also I'm not familiar with saving a scene, how do you do that?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

I have a somewhat simple way to manage a large scene without much trouble. Use empty scene nodes to create your scene structure, and create your scene using the empty scene nodes as the parents of your actual nodes. That way you can call the proper methods to remove all the children of an empty node and you can refill them again with new nodes. Then you can clear the texture cache from the unused textures and the mesh cache from the unused meshes, and that should do it.

You can save a scene with the saveScene method from the ISceneManager.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Post by raistca »

Ok that sounds like a good idea Mel, and thanks for the saveScene command, I hadn't really gotten to loading scene files and how exactly that plays out, but I guess I should check it out.

I guess basically when in battle view and I need to switch to map, I just need to save the scene and clear it, or just clear it and restart it later. After that, I probably need to remove the camera from the scene manager and then call my 2d drawing functions.

Does that sound right (about the camera thing especially)?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

No, it isn't a good idea at all. The save scene isn't meant to change dynamicaly between scenes. It serves to load and save scenes that are contained on themselves as a whole.

If you need to swap between scenes, you can keep both in memory. How? using empty scene nodes again (they are wonderful, and serve for almost anything! :D))

You may have the "stage scene" as the child of an empty scene node, and you can have your "map scene" view as the child of another scene node. When you need to swap between views, you can hide one scene node and display the other and viceversa.

When a parent node is hidden, the children nodes aren't rendered, so this can serve you to organize your scene better i guess you get the picture, right?

Other aproach, You can use more scene managers. With this it is even easier because you don't have to care about swapping the cameras between modes.

Unless you are short on RAM (iPhone/android...) keeping both scenes and swapping between them is the most eficient way.

One last remmark about the usage of empty scene nodes: set their position at (0.0.0), set their rotation to (0,0,0), set their scale to (1,1,1) so their transformations don't affect their children, and DISABLE their culling They have to be always rendered unless they are hidden. Or else, you may find that your scenes become invisible just because the scene node's AABB is out of the camera's field of view!.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

Mel wrote: Or else, you may find that your scenes become invisible just because the scene node's AABB is out of the camera's field of view!.
wait when you say that are you refering to empty scene node he would use? that is why i dont like empty scene nodes for using them purposes like that. maybe for spawns stuff but even then you should probably just make a custom object. i mean if it is not going to be rendered graphically yet you are still registering it with the scene manager (its derived from ISceneNode) and it has data like transform and stuff, then that's just overhead. yes its small but little things like that bug me and that is a big reason why i switched to lower level programming; you can whittle down your code to make it more efficient and sleek.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

I would use a state manager for this purpose, and maybe two scene managers. Might not be the best way, but I'd give it a try.
Working on game: Marrbles (Currently stopped).
raistca
Posts: 15
Joined: Sat Mar 26, 2011 5:26 am

Post by raistca »

Ok I think I've got it now. One question still lingers: you don't need a scene manager to do 2d drawing, so can you add 2d images to a scene manager? Or would these just be drawn over whatever 3d scene you have rendered?

It seems to me that Irrlicht should have many more tutorials to cover these kinds of things, or just provide more insight into the inner workings of the engine in the current tutorials, as they're a bit sparse. Is there a way for community members to submit tutorials to the website? Because I'm sure there are dozens of people who have code that could easily be brushed up into tutorial format and submitted.

Edit: I don't know what a state manager is, but I'll look into it
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Post by nespa »

a 2D map and a 3D scene?

-for 2D map use draw2DImage;

-in the main loop commute a switch to draw2DImage or not;

-draw2DImage will be after drawAll() command;
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

ChaiRuiPeng wrote:wait when you say that are you refering to empty scene node he would use? that is why i dont like empty scene nodes for using them purposes like that. maybe for spawns stuff but even then you should probably just make a custom object. i mean if it is not going to be rendered graphically yet you are still registering it with the scene manager (its derived from ISceneNode) and it has data like transform and stuff, then that's just overhead. yes its small but little things like that bug me and that is a big reason why i switched to lower level programming; you can whittle down your code to make it more efficient and sleek.
Yes, i suggested to have a scene composed of some empty nodes to use them as references, and mount his program around that.

I find more logic to have a scene composed out of scene objects than perhaps having any external list of objects for some purposes and work with them in the engine rendering them one by one. Besides, an empty node can have much more advantanges than drawbacks. Any object pending from an empty scene node can be hidden inmediately setting the parent as hidden, and transforming an empty scene node transforms all the children objects as well.

A scene is a graph, and it is more logic to work with the graph's entities than with any external routine, besides it is easier. I think that the main reason to have empty scene nodes is to have scene support points where you can do things taking advantage of the scene's hiearchy. Or simply, using them as reference points on the scene. Their advantage is that they are versatile.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply