Page 1 of 1

Reuse Device Variable

Posted: Fri Feb 24, 2006 10:16 pm
by jrm
I have a menu that pops-up I then click on play game. When I am exiting my game I go back to that menu. So I try to createdevice again and set everything up. But when I do the while(device->Run()) it doesn't get into the loop. how do I get it to be reusable?

When closing this menu I do a closedevice and a drop.

Thank you,

JRM

Posted: Sun Feb 26, 2006 10:38 pm
by killzone721
I have answered a similar type of question somewhere in the form, maybe search is a good idea, but anyway, i can answer it again :wink:

To know the solution, it tahkes a bit oop programming, u might have heard, it is very common term for c++

so you want to make the device-run hing reusable....(if i know what u mean).........than its not very difficult to answer

you need to create a new function

void rundevice(); //creates a funtion any function

in this function you put the code where it runs Irrlicht

void rundevice()
{
while(device->run)
{
BLA BLA....
}
}

simply call to this function whenever you want to create the device

rundevice(); // calling to the function

MAKE SURE:

the device is a global variable

Irrlicht*device=0; // global variable when you call it before any function

HOPE THIS HELPS........ :wink:

Posted: Mon Feb 27, 2006 2:59 pm
by jrm
I am already doing this. But I am not removing, deleting, the object. Do I need to do that?

Code: Select all


bool MainMenu::Run()
{
    device = createDevice(video::EDT_SOFTWARE2,
		core::dimension2d<s32>(640,480), 8, FullScreen, false, false, this);
......
	while(device->run())
	{
.....
	}

        return PlayGame;  
and this is being called from the main program by:

MainMenu mm;
while (mm.Run())
{
//run game.
}

Thank you,

JRM

p.s. sometime searchers here are not easy.. there are so many posts and you have to go through hundreds if you want to find what you are looking for.

Posted: Mon Mar 06, 2006 9:12 pm
by jrm
So if I am recreating the device every time the function is called it should be a clean, and go through the run? Or could it need to reset the event handler? Or could it be the closeDevice and drop that could be causing the problem?

Thank you,

JRM

Posted: Mon Mar 13, 2006 8:47 pm
by jrm
I still haven't got this completely working. Here is what I am doing:

Code: Select all

   MainMenu mm;
  //The Run function creates, a Local to object, device object, then shows a setup menu for the program, returns true if the player wants to play
   while (mm.Run())
    {

        runGame();
    }
  

void runGame()
{
  //Create local device according to MainMenu options and set up with game object

  
  while(device->run() && !DoneHere)
  {
      //game logic.  If esc is pressed then it should quit back out to the menu
   }
   device->closeDevice();
   device->drop();
}
When I am supposed to get back to the menu it can't do the device->run(). Unless I don't do the closeDevice/Drop in the runGame. They are different variables for the devices. Do they need to be the same?

Thank you,

JRM

Posted: Tue Mar 14, 2006 12:29 pm
by Guest
You can have only one Irrlichtdevice variable throughout the whole program (or so it seems).

In a function where you call CreateDevice[ex] you can do this:

Code: Select all

if(device) {
  device->closeDevice();
  device->run();
  device->drop();
}

device = CreateDevice(blahblah);
The device->run() is important as it allows the old device to quit properly. Without it the new device quits instantly. Just remember to set device to NULL in the constructor or you'll crash. And remember that every mesh, light, node, etc. gets destroyd when the first device is closeDeviced().

This works for me as I only use one device first to make a configuration dialog and then from those I make a new device that stays throughout the game and has all the stuff in it.

Posted: Tue Mar 14, 2006 2:06 pm
by Guest
Although, now I am getting some crashes in CIrrDeviceWin32::resizeIfNecessary() (don't have a linux box to try this on) that seem to be related to the matter. They come after the second call to CreateDevice() with something like "Resizing window (100 12923924)" in the console window.

The first parameter seems to allways be 100, but second one is trashed. I wonder if someone could tell me whats going on.

Posted: Tue Mar 14, 2006 3:07 pm
by jrm
That was the issue. A program can only have one device in it. My menu works now!! Now off to more of the game play logic programming!

Thank you,

JRM

Posted: Wed Mar 15, 2006 5:53 pm
by jrm
Ok, Same issue, sorry everyone. Anyway, If I do a closeDevice() I can't get the run() to be true. But If I don't do the closeDevice() each time I change between the screens I keep getting new windows. I am going between a 640x480 setup screen to what ever the user selects as the game screen.

Thank you,

JRM

Posted: Wed Mar 15, 2006 7:10 pm
by Guest
jrm wrote:Anyway, If I do a closeDevice() I can't get the run() to be true.
Thats why you do the extra run() after you close the old device, then createDevice a new one and then you can continue the program with that new device instance. That extra run() lets the new device get true from run().