split MWWord::World::update into multiple functions

This commit is contained in:
Nathan Jeffords 2013-01-07 22:48:24 -08:00
parent e31cd1c805
commit 86f691d3d5
2 changed files with 152 additions and 113 deletions

View file

@ -884,8 +884,6 @@ namespace MWWorld
void World::update (float duration, bool paused)
{
/// \todo split this function up into subfunctions
mWorldScene->update (duration, paused);
float pitch, yaw;
@ -895,6 +893,13 @@ namespace MWWorld
mWeatherManager->update (duration);
performUpdateSceneQueries ();
updateWindowManager ();
}
void World::updateWindowManager ()
{
// inform the GUI about focused object
MWWorld::Ptr object = searchPtrViaHandle(mFacedHandle);
@ -918,7 +923,10 @@ namespace MWWorld
screenCoords[0], screenCoords[1], screenCoords[2], screenCoords[3]);
}
}
}
void World::performUpdateSceneQueries ()
{
if (!mRendering->occlusionQuerySupported())
{
// cast a ray from player to sun to detect if the sun is visible
@ -936,9 +944,20 @@ namespace MWWorld
{
MWRender::OcclusionQuery* query = mRendering->getOcclusionQuery();
if (!query->occlusionTestPending())
{
processFacedQueryResults (query);
beginFacedQueryProcess (query);
}
}
}
void World::processFacedQueryResults (MWRender::OcclusionQuery* query)
{
// get result of last query
if (mNumFacing == 0) mFacedHandle = "";
if (mNumFacing == 0)
{
mFacedHandle = "";
}
else if (mNumFacing == 1)
{
bool result = query->getTestResult();
@ -949,7 +968,10 @@ namespace MWWorld
bool result = query->getTestResult();
mFacedHandle = result ? mFaced2Name : mFaced1Name;
}
}
void World::beginFacedQueryProcess (MWRender::OcclusionQuery* query)
{
// send new query
// figure out which object we want to test against
std::vector < std::pair < float, std::string > > results;
@ -960,7 +982,9 @@ namespace MWWorld
results = mPhysics->getFacedObjects(x, y);
}
else
{
results = mPhysics->getFacedObjects();
}
// ignore the player and other things we're not interested in
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
@ -980,6 +1004,16 @@ namespace MWWorld
mNumFacing = 0;
}
else if (results.size() == 1)
{
beginSingleFacedQueryProcess (query, results);
}
else
{
beginDoubleFacedQueryProcess (query, results);
}
}
void World::beginSingleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results)
{
mFaced1 = getPtrViaHandle(results.front().second);
mFaced1Name = results.front().second;
@ -1002,12 +1036,13 @@ namespace MWWorld
query->occlusionTest(pos, node);
}
else
void World::beginDoubleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results)
{
mFaced1Name = results.front().second;
mFaced2Name = results[1].second;
mFaced1 = getPtrViaHandle(results.front().second);
mFaced2 = getPtrViaHandle(results[1].second);
mFaced1Name = results.at (0).second;
mFaced2Name = results.at (1).second;
mFaced1 = getPtrViaHandle(results.at (0).second);
mFaced2 = getPtrViaHandle(results.at (1).second);
mNumFacing = 2;
btVector3 p;
@ -1015,10 +1050,10 @@ namespace MWWorld
{
float x, y;
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
p = mPhysics->getRayPoint(results[1].first, x, y);
p = mPhysics->getRayPoint(results.at (1).first, x, y);
}
else
p = mPhysics->getRayPoint(results[1].first);
p = mPhysics->getRayPoint(results.at (1).first);
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
Ogre::SceneNode* node1 = mFaced1.getRefData().getBaseNode();
Ogre::SceneNode* node2 = mFaced2.getRefData().getBaseNode();
@ -1048,9 +1083,6 @@ namespace MWWorld
query->occlusionTest(pos, node2);
}
}
}
}
bool World::isCellExterior() const
{

View file

@ -90,6 +90,13 @@ namespace MWWorld
virtual void
copyObjectToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos);
void updateWindowManager ();
void performUpdateSceneQueries ();
void processFacedQueryResults (MWRender::OcclusionQuery* query);
void beginFacedQueryProcess (MWRender::OcclusionQuery* query);
void beginSingleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results);
void beginDoubleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results);
public:
World (OEngine::Render::OgreRenderer& renderer,