How to really "clear" a scene
Posted: Sat Sep 07, 2013 5:38 am
Hi,
I'm having trouble getting the scene manager to fully clear the current scene.
I have separated my code into lots of different "modes." Modes are things like:
splash_screen_mode
main_menu_mode
graphics_menu_mode
audio_menu_mode
level_1_mode
level_2_mode
...
game_over_mode
Each mode has an "init_scene" member that looks like this (for example):
Basically, it just sets up the lights, cameras, and meshes for whatever is happening in this particular mode. Now, the code that actually calls this init_scene() method is the application's main loop, and it works like this:
What I'm seeing is that the call to "m_scene->clear()" isn't really clearing the meshes. They still sort of exist, behind the scenes, which causes problems. If I switch from "level_1_mode" to "main_menu_mode" (which would happen whenever the user presses the ESC key while playing level 1, for example) and then switch back to "level_1_mode" (user changed some menu options and then pressed ESC key again to return to the game), the method level_1_mode::init_scene() gets called a second time, but the world mesh isn't really destroyed and recreated. It's still the same one that was created on the first call, which means that it's already scaled, which means that it gets scaled again and is now the wrong size.
How do I really clear the scene so that all meshes are fully reloaded each time I switch to a new mode? I've experimented and found that completely destroying and recreating the Irrlicht device does the trick, but that isn't very desirable, because it closes the whole window, etc...
I'm having trouble getting the scene manager to fully clear the current scene.
I have separated my code into lots of different "modes." Modes are things like:
splash_screen_mode
main_menu_mode
graphics_menu_mode
audio_menu_mode
level_1_mode
level_2_mode
...
game_over_mode
Each mode has an "init_scene" member that looks like this (for example):
Code: Select all
void level_1_mode::init_scene(irr::scene::ISceneManager *scene)
{
m_camera_node = scene->addCameraSceneNode();
m_camera_node->setUpVector(v3f(0.0f, 0.0f, 1.0f));
m_camera_node->setFOV(0.6f * math::pi);
irr::scene::ILightSceneNode *light = scene->addLightSceneNode();
light->getLightData().SpecularColor.set(0.3f, 0.3f, 0.3f);
light->setLightType(irr::video::ELT_DIRECTIONAL);
light->setRotation(v3f(45.0f, 135.0f, 0.0f));
m_world_center_node = scene->addEmptySceneNode();
m_world_center_node->setPosition(v3f(0.0f, -WORLD_RADIUS, 0.0f));
irr::scene::IAnimatedMesh *world_mesh = scene->getMesh("level_a1.obj");
scene->getMeshManipulator()->scale(world_mesh, v3f(WORLD_MODEL_SCALE, WORLD_MODEL_SCALE, WORLD_MODEL_SCALE));
scene->addMeshSceneNode(world_mesh, m_world_center_node, -1, v3f(0.0f, WORLD_RADIUS, 0.0f));
}Code: Select all
while (m_device->run())
{
if (change_to_new_mode)
{
// Clear everything from the current mode's scene
m_scene->clear();
// Switch to the new mode
m_current_mode = new_mode;
// Initialize the new mode's scene
m_game_modes[m_current_mode]->init_scene(m_scene);
}
}How do I really clear the scene so that all meshes are fully reloaded each time I switch to a new mode? I've experimented and found that completely destroying and recreating the Irrlicht device does the trick, but that isn't very desirable, because it closes the whole window, etc...