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
This commit is contained in:
parent
e5e335f505
commit
e1033ca9f7
@ -1353,14 +1353,66 @@ void IrrDriver::displayFPS()
|
|||||||
font->draw( fpsString.c_str(), core::rect< s32 >(100,0,400,50), fpsColor, false );
|
font->draw( fpsString.c_str(), core::rect< s32 >(100,0,400,50), fpsColor, false );
|
||||||
} // updateFPS
|
} // updateFPS
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
void IrrDriver::drawDebugMeshes()
|
||||||
void drawJoint(bool drawline, bool drawname,
|
|
||||||
irr::scene::ISkinnedMesh::SJoint* joint,
|
|
||||||
ISkinnedMesh* mesh, int id)
|
|
||||||
{
|
{
|
||||||
//if (joint->PositionKeys.size() == 0) return;
|
for (unsigned int n=0; n<m_debug_meshes.size(); n++)
|
||||||
|
{
|
||||||
|
IMesh* mesh = m_debug_meshes[n]->getMesh();
|
||||||
|
ISkinnedMesh* smesh = static_cast<ISkinnedMesh*>(mesh);
|
||||||
|
const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints =
|
||||||
|
smesh->getAllJoints();
|
||||||
|
|
||||||
|
for (unsigned int j=0; j<joints.size(); 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; n<m_debug_meshes.size(); n++)
|
||||||
|
{
|
||||||
|
IMesh* mesh = m_debug_meshes[n]->getMesh();
|
||||||
|
|
||||||
|
|
||||||
|
ISkinnedMesh* smesh = static_cast<ISkinnedMesh*>(mesh);
|
||||||
|
const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints =
|
||||||
|
smesh->getAllJoints();
|
||||||
|
|
||||||
|
for (unsigned int j=0; j<joints.size(); j++)
|
||||||
|
{
|
||||||
|
IMesh* mesh = m_debug_meshes[n]->getMesh();
|
||||||
|
ISkinnedMesh* smesh = static_cast<ISkinnedMesh*>(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;
|
irr::scene::ISkinnedMesh::SJoint* parent = NULL;
|
||||||
const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints
|
const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints
|
||||||
= mesh->getAllJoints();
|
= mesh->getAllJoints();
|
||||||
@ -1490,6 +1542,14 @@ void drawJoint(bool drawline, bool drawname,
|
|||||||
*/
|
*/
|
||||||
void IrrDriver::update(float dt)
|
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
|
// If the resolution should be switched, do it now. This will delete the
|
||||||
// old device and create a new one.
|
// old device and create a new one.
|
||||||
if (m_resolution_changing!=RES_CHANGE_NONE)
|
if (m_resolution_changing!=RES_CHANGE_NONE)
|
||||||
@ -1499,19 +1559,19 @@ void IrrDriver::update(float dt)
|
|||||||
new ConfirmResolutionDialog();
|
new ConfirmResolutionDialog();
|
||||||
m_resolution_changing = RES_CHANGE_NONE;
|
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();
|
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;
|
const bool inRace = world!=NULL;
|
||||||
|
|
||||||
@ -1525,34 +1585,14 @@ void IrrDriver::update(float dt)
|
|||||||
// Start the RTT for post-processing.
|
// Start the RTT for post-processing.
|
||||||
// We do this before beginScene() because we want to capture the glClear()
|
// We do this before beginScene() because we want to capture the glClear()
|
||||||
// because of tracks that do not have skyboxes (generally add-on tracks)
|
// because of tracks that do not have skyboxes (generally add-on tracks)
|
||||||
m_post_processing.beginCapture();
|
m_post_processing.beginCapture();
|
||||||
|
|
||||||
m_video_driver->beginScene(back_buffer_clear,
|
|
||||||
true, world->getClearColor());
|
|
||||||
}
|
}
|
||||||
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)
|
if (inRace)
|
||||||
{
|
{
|
||||||
@ -1561,11 +1601,6 @@ void IrrDriver::update(float dt)
|
|||||||
RaceGUIBase *rg = world->getRaceGUI();
|
RaceGUIBase *rg = world->getRaceGUI();
|
||||||
if (rg) rg->update(dt);
|
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; i<world->getNumKarts(); i++)
|
for(unsigned int i=0; i<world->getNumKarts(); i++)
|
||||||
{
|
{
|
||||||
@ -1648,48 +1683,8 @@ void IrrDriver::update(float dt)
|
|||||||
} // just to mark the begin/end scene block
|
} // just to mark the begin/end scene block
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
for (unsigned int n=0; n<debug_meshes.size(); n++)
|
drawDebugMeshes();
|
||||||
{
|
|
||||||
IMesh* mesh = debug_meshes[n]->getMesh();
|
|
||||||
ISkinnedMesh* smesh = static_cast<ISkinnedMesh*>(mesh);
|
|
||||||
const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints =
|
|
||||||
smesh->getAllJoints();
|
|
||||||
|
|
||||||
for (unsigned int j=0; j<joints.size(); j++)
|
|
||||||
{
|
|
||||||
//drawJoint(debug_meshes[n]->getFrameNr(), 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; n<debug_meshes.size(); n++)
|
|
||||||
{
|
|
||||||
IMesh* mesh = debug_meshes[n]->getMesh();
|
|
||||||
|
|
||||||
|
|
||||||
ISkinnedMesh* smesh = static_cast<ISkinnedMesh*>(mesh);
|
|
||||||
const core::array< irr::scene::ISkinnedMesh::SJoint * >& joints =
|
|
||||||
smesh->getAllJoints();
|
|
||||||
|
|
||||||
for (unsigned int j=0; j<joints.size(); j++)
|
|
||||||
{
|
|
||||||
IMesh* mesh = debug_meshes[n]->getMesh();
|
|
||||||
ISkinnedMesh* smesh = static_cast<ISkinnedMesh*>(mesh);
|
|
||||||
|
|
||||||
drawJoint(true, false, joints[j], smesh, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_video_driver->endScene();
|
m_video_driver->endScene();
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
#include <vector2d.h>
|
#include <vector2d.h>
|
||||||
#include <dimension2d.h>
|
#include <dimension2d.h>
|
||||||
#include <SColor.h>
|
#include <SColor.h>
|
||||||
#include <IrrlichtDevice.h>
|
#include "IrrlichtDevice.h"
|
||||||
|
#include "ISkinnedMesh.h"
|
||||||
namespace irr
|
namespace irr
|
||||||
{
|
{
|
||||||
namespace scene { class ISceneManager; class IMesh; class IAnimatedMeshSceneNode; class IAnimatedMesh;
|
namespace scene { class ISceneManager; class IMesh; class IAnimatedMeshSceneNode; class IAnimatedMesh;
|
||||||
@ -109,6 +110,17 @@ private:
|
|||||||
|
|
||||||
bool m_request_screenshot;
|
bool m_request_screenshot;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
/** Used to visualise skeletons. */
|
||||||
|
std::vector<irr::scene::IAnimatedMeshSceneNode*> m_debug_meshes;
|
||||||
|
|
||||||
|
void drawDebugMeshes();
|
||||||
|
void drawJoint(bool drawline, bool drawname,
|
||||||
|
irr::scene::ISkinnedMesh::SJoint* joint,
|
||||||
|
irr::scene::ISkinnedMesh* mesh, int id);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IrrDriver();
|
IrrDriver();
|
||||||
~IrrDriver();
|
~IrrDriver();
|
||||||
@ -218,7 +230,17 @@ public:
|
|||||||
bool supportsSplatting();
|
bool supportsSplatting();
|
||||||
|
|
||||||
void requestScreenshot();
|
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 --------------------
|
// --------------------- RTT --------------------
|
||||||
/**
|
/**
|
||||||
* Class that provides RTT (currently, only when no other 3D rendering
|
* Class that provides RTT (currently, only when no other 3D rendering
|
||||||
@ -285,10 +307,6 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
std::vector<irr::scene::IAnimatedMeshSceneNode*> debug_meshes;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
}; // IrrDriver
|
}; // IrrDriver
|
||||||
|
|
||||||
|
@ -803,6 +803,26 @@ namespace GUIEngine
|
|||||||
gui_messages.clear();
|
gui_messages.clear();
|
||||||
} // 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()
|
void cleanForGame()
|
||||||
|
@ -199,6 +199,8 @@ namespace GUIEngine
|
|||||||
* \note Do not use directly. Use a state manager instead to get higher-level functionnality.
|
* \note Do not use directly. Use a state manager instead to get higher-level functionnality.
|
||||||
*/
|
*/
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
void update(float dt);
|
||||||
|
|
||||||
/** \brief like GUIEngine::clear, but to be called before going into game */
|
/** \brief like GUIEngine::clear, but to be called before going into game */
|
||||||
void cleanForGame();
|
void cleanForGame();
|
||||||
|
@ -306,6 +306,13 @@ void PlayerController::skidBonusTriggered()
|
|||||||
*/
|
*/
|
||||||
void PlayerController::update(float dt)
|
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
|
// 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
|
// matter, but if it's physics replay the gradual steering causes
|
||||||
// incorrect results, since the stored values are already adjusted.
|
// incorrect results, since the stored values are already adjusted.
|
||||||
|
@ -183,7 +183,7 @@ KartModel::~KartModel()
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#if SKELETON_DEBUG
|
#if SKELETON_DEBUG
|
||||||
irr_driver->debug_meshes.clear();
|
irr_driver->clearDebugMeshes();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models)
|
|||||||
std::string debug_name = m_model_filename+" (animated-kart-model)";
|
std::string debug_name = m_model_filename+" (animated-kart-model)";
|
||||||
node->setName(debug_name.c_str());
|
node->setName(debug_name.c_str());
|
||||||
#if SKELETON_DEBUG
|
#if SKELETON_DEBUG
|
||||||
irr_driver->debug_meshes.push_back(m_animated_node);
|
irr_driber->addDebugMesh(m_animated_node);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
m_animated_node->setLoopMode(false);
|
m_animated_node->setLoopMode(false);
|
||||||
|
@ -155,7 +155,10 @@ void MainLoop::run()
|
|||||||
#ifdef ENABLE_WIIUSE
|
#ifdef ENABLE_WIIUSE
|
||||||
wiimote_manager->update();
|
wiimote_manager->update();
|
||||||
#endif
|
#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);
|
PROFILER_PUSH_CPU_MARKER("IrrDriver update", 0x00, 0x00, 0x7F);
|
||||||
irr_driver->update(dt);
|
irr_driver->update(dt);
|
||||||
PROFILER_POP_CPU_MARKER();
|
PROFILER_POP_CPU_MARKER();
|
||||||
|
@ -299,12 +299,12 @@ public:
|
|||||||
/** Returns the color to clear the back buffer. */
|
/** Returns the color to clear the back buffer. */
|
||||||
const irr::video::SColor& getClearColor() const { return m_clear_color; }
|
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. */
|
/** Sets the color to use when clearing the back buffer. */
|
||||||
void setClearbackBufferColor(irr::video::SColor color)
|
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 */
|
/** Override if you want to know when a kart presses fire */
|
||||||
virtual void onFirePressed(Controller* who) {}
|
virtual void onFirePressed(Controller* who) {}
|
||||||
|
@ -1640,7 +1640,6 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
|||||||
}
|
}
|
||||||
else if(m_sky_type==SKY_COLOR)
|
else if(m_sky_type==SKY_COLOR)
|
||||||
{
|
{
|
||||||
World::getWorld()->setClearBackBuffer(true);
|
|
||||||
World::getWorld()->setClearbackBufferColor(m_sky_color);
|
World::getWorld()->setClearbackBufferColor(m_sky_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user