1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 21:49:55 +00:00

Keep track of terrain in physics engine. Should resolve crash exiting after opening multiple subviews of the same cell.

This commit is contained in:
cc9cii 2014-11-01 00:03:09 +11:00
parent ac7acb2c22
commit ade7f09203
4 changed files with 33 additions and 11 deletions

View file

@ -61,7 +61,7 @@ bool CSVRender::Cell::addObjects (int start, int end)
CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager, CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
const std::string& id, const Ogre::Vector3& origin) const std::string& id, const Ogre::Vector3& origin)
: mData (data), mId (Misc::StringUtils::lowerCase (id)) : mData (data), mId (Misc::StringUtils::lowerCase (id)), mSceneMgr(sceneManager)
{ {
mCellNode = sceneManager->getRootSceneNode()->createChildSceneNode(); mCellNode = sceneManager->getRootSceneNode()->createChildSceneNode();
mCellNode->setPosition (origin); mCellNode->setPosition (origin);
@ -88,7 +88,7 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
{ {
float verts = ESM::Land::LAND_SIZE; float verts = ESM::Land::LAND_SIZE;
float worldsize = ESM::Land::REAL_SIZE; float worldsize = ESM::Land::REAL_SIZE;
CSVWorld::PhysicsSystem::instance()->addHeightField( CSVWorld::PhysicsSystem::instance()->addHeightField(sceneManager,
esmLand->mLandData->mHeights, esmLand->mX, esmLand->mY, 0, worldsize / (verts-1), verts); esmLand->mLandData->mHeights, esmLand->mX, esmLand->mY, 0, worldsize / (verts-1), verts);
} }
} }
@ -105,7 +105,7 @@ CSVRender::Cell::~Cell()
{ {
const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get(); const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get();
if(esmLand) if(esmLand)
CSVWorld::PhysicsSystem::instance()->removeHeightField(esmLand->mX, esmLand->mY); CSVWorld::PhysicsSystem::instance()->removeHeightField(mSceneMgr, esmLand->mX, esmLand->mY);
} }
} }

View file

@ -32,6 +32,7 @@ namespace CSVRender
Ogre::SceneNode *mCellNode; Ogre::SceneNode *mCellNode;
std::map<std::string, Object *> mObjects; std::map<std::string, Object *> mObjects;
std::auto_ptr<Terrain::TerrainGrid> mTerrain; std::auto_ptr<Terrain::TerrainGrid> mTerrain;
Ogre::SceneManager *mSceneMgr;
/// Ignored if cell does not have an object with the given ID. /// Ignored if cell does not have an object with the given ID.
/// ///

View file

@ -129,15 +129,35 @@ namespace CSVWorld
position, rotation); position, rotation);
} }
void PhysicsSystem::addHeightField(float* heights, void PhysicsSystem::addHeightField(Ogre::SceneManager *sceneManager,
int x, int y, float yoffset, float triSize, float sqrtVerts) float* heights, int x, int y, float yoffset, float triSize, float sqrtVerts)
{ {
mEngine->addHeightField(heights, x, y, yoffset, triSize, sqrtVerts); std::string name = "HeightField_"
+ QString::number(x).toStdString() + "_" + QString::number(y).toStdString();
if(mTerrain.find(name) == mTerrain.end())
mEngine->addHeightField(heights, x, y, yoffset, triSize, sqrtVerts);
mTerrain.insert(std::pair<std::string, Ogre::SceneManager *>(name, sceneManager));
} }
void PhysicsSystem::removeHeightField(int x, int y) void PhysicsSystem::removeHeightField(Ogre::SceneManager *sceneManager, int x, int y)
{ {
mEngine->removeHeightField(x, y); std::string name = "HeightField_"
+ QString::number(x).toStdString() + "_" + QString::number(y).toStdString();
if(mTerrain.count(name) == 1)
mEngine->removeHeightField(x, y);
std::multimap<std::string, Ogre::SceneManager *>::iterator iter = mTerrain.begin();
for(; iter != mTerrain.end(); ++iter)
{
if((*iter).second == sceneManager)
{
mTerrain.erase(iter);
break;
}
}
} }
// sceneMgr: to lookup the scene node name from the object's referenceId // sceneMgr: to lookup the scene node name from the object's referenceId

View file

@ -37,6 +37,7 @@ namespace CSVWorld
std::list<Ogre::SceneManager *> mSceneManagers; // FIXME: change to list per OEngine std::list<Ogre::SceneManager *> mSceneManagers; // FIXME: change to list per OEngine
std::list<CSVRender::SceneWidget *> mSceneWidgets; // FIXME: change to list per OEngine std::list<CSVRender::SceneWidget *> mSceneWidgets; // FIXME: change to list per OEngine
OEngine::Physic::PhysicEngine* mEngine; OEngine::Physic::PhysicEngine* mEngine;
std::multimap<std::string, Ogre::SceneManager *> mTerrain;
public: public:
@ -57,10 +58,10 @@ namespace CSVWorld
void moveObject(const std::string &sceneNodeName, void moveObject(const std::string &sceneNodeName,
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation); const Ogre::Vector3 &position, const Ogre::Quaternion &rotation);
void addHeightField(float* heights, void addHeightField(Ogre::SceneManager *sceneManager,
int x, int y, float yoffset, float triSize, float sqrtVerts); float* heights, int x, int y, float yoffset, float triSize, float sqrtVerts);
void removeHeightField(int x, int y); void removeHeightField(Ogre::SceneManager *sceneManager, int x, int y);
void toggleDebugRendering(Ogre::SceneManager *sceneMgr); void toggleDebugRendering(Ogre::SceneManager *sceneMgr);