Reuse Device Variable

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
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Reuse Device Variable

Post 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
killzone721
Posts: 19
Joined: Thu Feb 09, 2006 1:45 am

Post 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:
TO ALL THE AMATEURS OUT THERE LIKE ME......

AIM HIGH AND YOU MAKE SOMETHING PRETTY DECENT TO SHOW THE WORLD

CURRENTLY WORKING ON MY COMPANY WITH ME CREW MEMBERS. MY COMPANY IS CALLED
BIG DREAMS
AND WE ARE MAKE VERSION 0.1 FPS GAME
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post 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.
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post 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
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post 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
Guest

Post 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.
Guest

Post 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.
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post 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
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post 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
Guest

Post 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().
Post Reply