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
Reuse Device Variable
-
- Posts: 19
- Joined: Thu Feb 09, 2006 1:45 am
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
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........
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........
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
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
I am already doing this. But I am not removing, deleting, the object. Do I need to do that?
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.
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;
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.
I still haven't got this completely working. Here is what I am doing:
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
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();
}
Thank you,
JRM
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:
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.
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);
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.
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.
The first parameter seems to allways be 100, but second one is trashed. I wonder if someone could tell me whats going on.
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
Thank you,
JRM