State Manager

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.
UrsaMajor
Posts: 3
Joined: Sun Mar 06, 2011 7:35 am

State Manager

Post by UrsaMajor »

Hi all,

I've problem with projecting of State Manager. Should I use a different Scene Manager for each state? Earlier I use one Scene Manager and when I was changing states I was setting Visible = false; for each Scene Node used in previous state. What do you think about it? Thanks for answers and sorry for my english :)
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: State Manager

Post by randomMesh »

UrsaMajor wrote:Hi all,

I've problem with projecting of State Manager. Should I use a different Scene Manager for each state? Earlier I use one Scene Manager and when I was changing states I was setting Visible = false; for each Scene Node used in previous state. What do you think about it? Thanks for answers and sorry for my english :)
The one by vitek works very well.
"Whoops..."
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: State Manager

Post by serengeor »

UrsaMajor wrote:Hi all,
... I was setting Visible = false; for each Scene Node used in previous state. What do you think about it?
Do you need your nodes to stay in the manager for later use or what? I would clean up the scene. tough if you need them to stay there, than I guess its ok, as long as you know what you're doing.
Working on game: Marrbles (Currently stopped).
UrsaMajor
Posts: 3
Joined: Sun Mar 06, 2011 7:35 am

Post by UrsaMajor »

Do you need your nodes to stay in the manager for later use or what?
Yes, I need them because when I change state from Level to Menu and then from Menu to Level I don't want reload them.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

well you could make that way simpler. just create a "state" node which is basicly just an empty scenenode and use that node as root for all the nodes in a specific state. when you than change the state just call remove on that state node. and all nodes will not be rendered nor processed. When you than come back to the state just call setParent(SceneManager->getRootSceneNode()) on the state node.

of course you will have to grab the state node otherwise it will be deleted on remove.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

UrsaMajor wrote:
Do you need your nodes to stay in the manager for later use or what?
Yes, I need them because when I change state from Level to Menu and then from Menu to Level I don't want reload them.
I had the same problem, I think it would be better to have menu in the same state. Tough I don't really know what your project configuration is, so its better to decide on your own how to do this.
Sudi wrote:well you could make that way simpler. just create a "state" node which is basicly just an empty scenenode and use that node as root for all the nodes in a specific state. when you than change the state just call remove on that state node. and all nodes will not be rendered nor processed. When you than come back to the state just call setParent(SceneManager->getRootSceneNode()) on the state node.

of course you will have to grab the state node otherwise it will be deleted on remove.
Erm, yeah lets hack irrlicht to do all the game engine job. :shock:
Working on game: Marrbles (Currently stopped).
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Actually that is not hacking the system its using the nature of a tree system... :P
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Now how about loading/unloading resources for every state?
Working on game: Marrbles (Currently stopped).
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Well that depends is the state actually left/closed? or is just put to sleep/backround?

if its closed sure delete all resources. but if it is just sleeping like your game is running and you open the ingame menu which actually should be a different state. then gamestate is just sitting in the background maybe even still running and waiting to be top state again.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

For me it looks like using a rock to do a hammer job :roll:
Working on game: Marrbles (Currently stopped).
Mikhail9
Posts: 54
Joined: Mon Jun 29, 2009 8:41 am

Post by Mikhail9 »

Sudi's method makes perfect sense for any case where you are going to go back to the state you just left, picking up exactly where you left off. This is common in games where you might hit ESC and go into a menu screen, then return to the game.

On top of that, it's highly efficient because you just pull the empty "state" root node out of the scene graph. It doesn't consume processing resources because it doesn't get touched by the scene manager during updates. And you don't wait forever for your assets to reload when you want to go back.

Of course, if you don't need those resources anymore at all, you would choose to remove that "state" node permanently, or destroy the scene manager and create a new one.

It depends on the application.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Mikhail9 wrote:Sudi's method makes perfect sense for any case where you are going to go back to the state you just left, picking up exactly where you left off. This is common in games where you might hit ESC and go into a menu screen, then return to the game.
You can also do that by just making the menu appear in the same state, thus you can have your objects visible. And making node invisible won't stop physics from not updating, unless using irrlicht animators, or doning checks if the root node is visible, but it looks way too unorganized.
Working on game: Marrbles (Currently stopped).
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

serengeor wrote: You can also do that by just making the menu appear in the same state, thus you can have your objects visible. And making node invisible won't stop physics from not updating, unless using irrlicht animators, or doning checks if the root node is visible, but it looks way too unorganized.
Making a menu in the same state as the game is actually pretty messy and unorganized. A menu is obviously a state so it deserves it own state with its own vars etc.
Besides we talked about irrlicht and not physics when you want to disable physics just don't call the physics update function while the game state is not active...simple right :!:
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Sudi wrote: Making a menu in the same state as the game is actually pretty messy and unorganized. A menu is obviously a state so it deserves it own state with its own vars etc.
Besides we talked about irrlicht and not physics when you want to disable physics just don't call the physics update function while the game state is not active...simple right :!:
Messy eh? And Making entities do the game framework job is not messy ? ok..
And by talking about menu, I was thinking of pause menu, and not many games really allow you to enter the main menu without quiting your game state.
Working on game: Marrbles (Currently stopped).
UrsaMajor
Posts: 3
Joined: Sun Mar 06, 2011 7:35 am

Post by UrsaMajor »

well you could make that way simpler. just create a "state" node which is basicly just an empty scenenode and use that node as root for all the nodes in a specific state. when you than change the state just call remove on that state node. and all nodes will not be rendered nor processed. When you than come back to the state just call setParent(SceneManager->getRootSceneNode()) on the state node.

of course you will have to grab the state node otherwise it will be deleted on remove.
It looks pretty good. :) Thanks.
And I have another question. I want make a simple transitions. I made a texture(rectangle 640x480 - for my default resolution) with half-transparent borders. It works good for 640x480, but when I change resolution, texture have the same resolution. How can I change resolution of this texture? I wrote this:

Code: Select all

	video::SMaterial material;
	material.setTexture(0,texture);
	core::matrix4 matrix = material.getTextureMatrix(0);
	matrix.setTextureScale(2.1f,2.0f);
	material.setTextureMatrix(0,matrix);
	texture = material.getTexture(0);
But, It doesn't work at all. Any ideas?


//EDIT: I managed to do that. I used gui::IGUIImage instead of video::ITexture. Here is the link for property usage of SetAlingment if someone have the same problem: http://irrlicht.sourceforge.net/phpBB2/ ... scaleimage
Post Reply