mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +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:
parent
ac7acb2c22
commit
ade7f09203
4 changed files with 33 additions and 11 deletions
|
@ -61,7 +61,7 @@ bool CSVRender::Cell::addObjects (int start, int end)
|
|||
|
||||
CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
|
||||
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->setPosition (origin);
|
||||
|
@ -88,7 +88,7 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
|
|||
{
|
||||
float verts = ESM::Land::LAND_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);
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ CSVRender::Cell::~Cell()
|
|||
{
|
||||
const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get();
|
||||
if(esmLand)
|
||||
CSVWorld::PhysicsSystem::instance()->removeHeightField(esmLand->mX, esmLand->mY);
|
||||
CSVWorld::PhysicsSystem::instance()->removeHeightField(mSceneMgr, esmLand->mX, esmLand->mY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace CSVRender
|
|||
Ogre::SceneNode *mCellNode;
|
||||
std::map<std::string, Object *> mObjects;
|
||||
std::auto_ptr<Terrain::TerrainGrid> mTerrain;
|
||||
Ogre::SceneManager *mSceneMgr;
|
||||
|
||||
/// Ignored if cell does not have an object with the given ID.
|
||||
///
|
||||
|
|
|
@ -129,15 +129,35 @@ namespace CSVWorld
|
|||
position, rotation);
|
||||
}
|
||||
|
||||
void PhysicsSystem::addHeightField(float* heights,
|
||||
int x, int y, float yoffset, float triSize, float sqrtVerts)
|
||||
void PhysicsSystem::addHeightField(Ogre::SceneManager *sceneManager,
|
||||
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
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace CSVWorld
|
|||
std::list<Ogre::SceneManager *> mSceneManagers; // FIXME: change to list per OEngine
|
||||
std::list<CSVRender::SceneWidget *> mSceneWidgets; // FIXME: change to list per OEngine
|
||||
OEngine::Physic::PhysicEngine* mEngine;
|
||||
std::multimap<std::string, Ogre::SceneManager *> mTerrain;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -57,10 +58,10 @@ namespace CSVWorld
|
|||
void moveObject(const std::string &sceneNodeName,
|
||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation);
|
||||
|
||||
void addHeightField(float* heights,
|
||||
int x, int y, float yoffset, float triSize, float sqrtVerts);
|
||||
void addHeightField(Ogre::SceneManager *sceneManager,
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue