From e1033ca9f7d5ce78b114b3bd5465d29ae4df229a Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 28 Feb 2013 01:05:27 +0000 Subject: [PATCH] Started to restructure rendering loop - moved things out of rendering loop, cleaned up code, ... git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12531 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/graphics/irr_driver.cpp | 173 ++++++++++----------- src/graphics/irr_driver.hpp | 30 +++- src/guiengine/engine.cpp | 20 +++ src/guiengine/engine.hpp | 2 + src/karts/controller/player_controller.cpp | 7 + src/karts/kart_model.cpp | 4 +- src/main_loop.cpp | 5 +- src/modes/world.hpp | 8 +- src/tracks/track.cpp | 1 - 9 files changed, 147 insertions(+), 103 deletions(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 1d868cced..4acf665a0 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1353,14 +1353,66 @@ void IrrDriver::displayFPS() font->draw( fpsString.c_str(), core::rect< s32 >(100,0,400,50), fpsColor, false ); } // updateFPS +// ---------------------------------------------------------------------------- #ifdef DEBUG - -void drawJoint(bool drawline, bool drawname, - irr::scene::ISkinnedMesh::SJoint* joint, - ISkinnedMesh* mesh, int id) +void IrrDriver::drawDebugMeshes() { - //if (joint->PositionKeys.size() == 0) return; + for (unsigned int n=0; ngetMesh(); + ISkinnedMesh* smesh = static_cast(mesh); + const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints = + smesh->getAllJoints(); + + for (unsigned int j=0; jsetMaterial(material); + getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix); + + for (unsigned int n=0; ngetMesh(); + + + ISkinnedMesh* smesh = static_cast(mesh); + const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints = + smesh->getAllJoints(); + + for (unsigned int j=0; jgetMesh(); + ISkinnedMesh* smesh = static_cast(mesh); + + drawJoint(true, false, joints[j], smesh, j); + } + } +} // drawDebugMeshes + +// ---------------------------------------------------------------------------- +/** Draws a joing for debugging skeletons. + * \param drawline If true draw a line to the parent. + * \param drawname If true draw the name of the joint. + * \param joint The joint to draw. + * \param mesh The mesh whose skeleton is drawn (only used to get + * all joints to find the parent). + * \param id Index, which (%4) determines the color to use. + */ +void IrrDriver::drawJoint(bool drawline, bool drawname, + irr::scene::ISkinnedMesh::SJoint* joint, + ISkinnedMesh* mesh, int id) +{ irr::scene::ISkinnedMesh::SJoint* parent = NULL; const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints = mesh->getAllJoints(); @@ -1490,6 +1542,14 @@ void drawJoint(bool drawline, bool drawname, */ void IrrDriver::update(float dt) { + // User aborted (e.g. closed window) + // ================================= + if (!m_device->run()) + { + main_loop->abort(); + return; + } + // If the resolution should be switched, do it now. This will delete the // old device and create a new one. if (m_resolution_changing!=RES_CHANGE_NONE) @@ -1499,19 +1559,19 @@ void IrrDriver::update(float dt) new ConfirmResolutionDialog(); m_resolution_changing = RES_CHANGE_NONE; } - - if (!m_device->run()) - { - main_loop->abort(); - } - if (UserConfigParams::m_gamepad_debug) - { - // Print a dividing line so that it's easier to see which events - // get received in which order in the one frame. - Log::debug("irr_driver", "-------------------------------------\n"); - } - + World *world = World::getWorld(); + + // Handle cut scenes (which do not have any karts in it) + // ===================================================== + if (world && world->getNumKarts() == 0) + { + m_video_driver->beginScene(/*backBuffer clear*/false, /*zBuffer*/true, + world->getClearColor()); + m_scene_manager->drawAll(); + m_video_driver->endScene(); + return; + } const bool inRace = world!=NULL; @@ -1525,34 +1585,14 @@ void IrrDriver::update(float dt) // Start the RTT for post-processing. // We do this before beginScene() because we want to capture the glClear() // because of tracks that do not have skyboxes (generally add-on tracks) - m_post_processing.beginCapture(); - - m_video_driver->beginScene(back_buffer_clear, - true, world->getClearColor()); + m_post_processing.beginCapture(); } - else + + m_video_driver->beginScene(back_buffer_clear, /*zBuffer*/ true, + world ? world->getClearColor() + : video::SColor(255,100,101,140)); + { - m_video_driver->beginScene(back_buffer_clear, - true, video::SColor(255,100,101,140)); - } - - { - PROFILER_PUSH_CPU_MARKER("Update GUI widgets", 0x7F, 0x7F, 0x00); - - // Just to mark the begin/end scene block - GUIEngine::GameState state = StateManager::get()->getGameState(); - if (state != GUIEngine::GAME) - { - // This code needs to go outside beginScene() / endScene() since - // the model view widget will do off-screen rendering there - GUIEngine::Widget* widget; - for_in (widget, GUIEngine::needsUpdate) - { - widget->update(dt); - } - } - - PROFILER_POP_CPU_MARKER(); if (inRace) { @@ -1561,11 +1601,6 @@ void IrrDriver::update(float dt) RaceGUIBase *rg = world->getRaceGUI(); if (rg) rg->update(dt); - // No kart, this must be a cutscene - if (world->getNumKarts() == 0) - { - m_scene_manager->drawAll(); - } for(unsigned int i=0; igetNumKarts(); i++) { @@ -1648,48 +1683,8 @@ void IrrDriver::update(float dt) } // just to mark the begin/end scene block #ifdef DEBUG - for (unsigned int n=0; ngetMesh(); - ISkinnedMesh* smesh = static_cast(mesh); - const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints = - smesh->getAllJoints(); + drawDebugMeshes(); - for (unsigned int j=0; jgetFrameNr(), joints[j]); - drawJoint( false, true, joints[j], smesh, j); - } - } - - video::SColor color(255,255,255,255); - video::SMaterial material; - material.Thickness = 2; - material.AmbientColor = color; - material.DiffuseColor = color; - material.EmissiveColor= color; - material.BackfaceCulling = false; - material.setFlag(video::EMF_LIGHTING, false); - getVideoDriver()->setMaterial(material); - getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix); - - for (unsigned int n=0; ngetMesh(); - - - ISkinnedMesh* smesh = static_cast(mesh); - const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints = - smesh->getAllJoints(); - - for (unsigned int j=0; jgetMesh(); - ISkinnedMesh* smesh = static_cast(mesh); - - drawJoint(true, false, joints[j], smesh, j); - } - } #endif m_video_driver->endScene(); diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 80ea32818..054a45275 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -34,7 +34,8 @@ #include #include #include -#include +#include "IrrlichtDevice.h" +#include "ISkinnedMesh.h" namespace irr { namespace scene { class ISceneManager; class IMesh; class IAnimatedMeshSceneNode; class IAnimatedMesh; @@ -109,6 +110,17 @@ private: bool m_request_screenshot; +#ifdef DEBUG + /** Used to visualise skeletons. */ + std::vector m_debug_meshes; + + void drawDebugMeshes(); + void drawJoint(bool drawline, bool drawname, + irr::scene::ISkinnedMesh::SJoint* joint, + irr::scene::ISkinnedMesh* mesh, int id); + +#endif + public: IrrDriver(); ~IrrDriver(); @@ -218,7 +230,17 @@ public: bool supportsSplatting(); void requestScreenshot(); - +#ifdef DEBUG + /** Removes debug meshes. */ + void clearDebugMesh() { m_debug_meshes.clear(); } + // ------------------------------------------------------------------------ + /** Adds a debug mesh to be displaed. */ + void addDebugMesh(scene::IAnimatedMeshSceneNode *node) + { + m_debug_meshes.push_back(node); + } // addDebugMesh + +#endif // --------------------- RTT -------------------- /** * Class that provides RTT (currently, only when no other 3D rendering @@ -285,10 +307,6 @@ public: }; -#ifdef DEBUG - std::vector debug_meshes; -#endif - }; // IrrDriver diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index d1fa0c338..ee884600b 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -803,6 +803,26 @@ namespace GUIEngine gui_messages.clear(); } // clear + // ------------------------------------------------------------------------ + /** Updates all widgets that need to be updated. + * \param dt Time step size. + */ + void update(float dt) + { + // Just to mark the begin/end scene block + GUIEngine::GameState state = StateManager::get()->getGameState(); + if (state != GUIEngine::GAME) + { + // This code needs to go outside beginScene() / endScene() since + // the model view widget will do off-screen rendering there + GUIEngine::Widget* widget; + for_in (widget, GUIEngine::needsUpdate) + { + widget->update(dt); + } + } + + } // ------------------------------------------------------------------------ void cleanForGame() diff --git a/src/guiengine/engine.hpp b/src/guiengine/engine.hpp index 8488aabaf..96c93c8d5 100644 --- a/src/guiengine/engine.hpp +++ b/src/guiengine/engine.hpp @@ -199,6 +199,8 @@ namespace GUIEngine * \note Do not use directly. Use a state manager instead to get higher-level functionnality. */ void clear(); + + void update(float dt); /** \brief like GUIEngine::clear, but to be called before going into game */ void cleanForGame(); diff --git a/src/karts/controller/player_controller.cpp b/src/karts/controller/player_controller.cpp index fff6d85a4..996306bf5 100644 --- a/src/karts/controller/player_controller.cpp +++ b/src/karts/controller/player_controller.cpp @@ -306,6 +306,13 @@ void PlayerController::skidBonusTriggered() */ void PlayerController::update(float dt) { + if (UserConfigParams::m_gamepad_debug) + { + // Print a dividing line so that it's easier to see which events + // get received in which order in the one frame. + Log::debug("irr_driver", "-------------------------------------\n"); + } + // Don't do steering if it's replay. In position only replay it doesn't // matter, but if it's physics replay the gradual steering causes // incorrect results, since the stored values are already adjusted. diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index d22184405..b4785c863 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -183,7 +183,7 @@ KartModel::~KartModel() #ifdef DEBUG #if SKELETON_DEBUG - irr_driver->debug_meshes.clear(); + irr_driver->clearDebugMeshes(); #endif #endif @@ -297,7 +297,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models) std::string debug_name = m_model_filename+" (animated-kart-model)"; node->setName(debug_name.c_str()); #if SKELETON_DEBUG - irr_driver->debug_meshes.push_back(m_animated_node); + irr_driber->addDebugMesh(m_animated_node); #endif #endif m_animated_node->setLoopMode(false); diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 4229ba11d..9728d93e7 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -155,7 +155,10 @@ void MainLoop::run() #ifdef ENABLE_WIIUSE wiimote_manager->update(); #endif - + PROFILER_PUSH_CPU_MARKER("Update GUI widgets", 0x7F, 0x7F, 0x00); + GUIEngine::update(dt); + PROFILER_POP_CPU_MARKER(); + PROFILER_PUSH_CPU_MARKER("IrrDriver update", 0x00, 0x00, 0x7F); irr_driver->update(dt); PROFILER_POP_CPU_MARKER(); diff --git a/src/modes/world.hpp b/src/modes/world.hpp index a5202a400..41ae94fc4 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -299,12 +299,12 @@ public: /** Returns the color to clear the back buffer. */ const irr::video::SColor& getClearColor() const { return m_clear_color; } // ------------------------------------------------------------------------ - /** Forces clearing of the back buffer. */ - void setClearBackBuffer(bool enabled) { m_clear_back_buffer = enabled; } - // ------------------------------------------------------------------------ /** Sets the color to use when clearing the back buffer. */ void setClearbackBufferColor(irr::video::SColor color) - { m_clear_color = color; } + { + m_clear_color = color; + m_clear_back_buffer = true; + } // ------------------------------------------------------------------------ /** Override if you want to know when a kart presses fire */ virtual void onFirePressed(Controller* who) {} diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index ad579d7a2..309c3e374 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1640,7 +1640,6 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) } else if(m_sky_type==SKY_COLOR) { - World::getWorld()->setClearBackBuffer(true); World::getWorld()->setClearbackBufferColor(m_sky_color); }