diff --git a/apps/opencs/view/render/cell.cpp b/apps/opencs/view/render/cell.cpp index d414498db..f21d6b40b 100644 --- a/apps/opencs/view/render/cell.cpp +++ b/apps/opencs/view/render/cell.cpp @@ -96,6 +96,19 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager, CSVRender::Cell::~Cell() { + // TODO: maybe store the cell coordinates rather than searching for them in the destructor? + if(mTerrain.get()) + { + const CSMWorld::IdCollection& land = mData.getLand(); + int landIndex = land.searchId(mId); + if (landIndex != -1) + { + const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get(); + if(esmLand) + CSVWorld::PhysicsSystem::instance()->removeHeightField(esmLand->mX, esmLand->mY); + } + } + for (std::map::iterator iter (mObjects.begin()); iter!=mObjects.end(); ++iter) delete iter->second; diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index 01164366a..474c79b35 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -33,11 +33,12 @@ void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node) void CSVRender::Object::clear() { + if(!mObject.isNull()) + CSVWorld::PhysicsSystem::instance()->removeObject(mBase->getName()); + mObject.setNull(); clearSceneNode (mBase); - - // FIXME: also clear bullet objects } void CSVRender::Object::update() diff --git a/apps/opencs/view/world/physicssystem.cpp b/apps/opencs/view/world/physicssystem.cpp index f5f82c033..fa43a57a4 100644 --- a/apps/opencs/view/world/physicssystem.cpp +++ b/apps/opencs/view/world/physicssystem.cpp @@ -53,6 +53,15 @@ namespace CSVWorld PhysicsSystem::~PhysicsSystem() { + std::map >::iterator iter = mSelectedEntities.begin(); + for(;iter != mSelectedEntities.end(); ++iter) + { + removeHitPoint(mSceneMgr, iter->first); + Ogre::SceneNode *scene = mSceneMgr->getSceneNode(iter->first); + scene->removeAndDestroyAllChildren(); + mSceneMgr->destroySceneNode(iter->first); + } + delete mEngine; } @@ -152,6 +161,11 @@ namespace CSVWorld mEngine->addHeightField(heights, x, y, yoffset, triSize, sqrtVerts); } + void PhysicsSystem::removeHeightField(int x, int y) + { + mEngine->removeHeightField(x, y); + } + void PhysicsSystem::toggleDebugRendering() { CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); diff --git a/apps/opencs/view/world/physicssystem.hpp b/apps/opencs/view/world/physicssystem.hpp index 2ae17b5e3..c2115bc0f 100644 --- a/apps/opencs/view/world/physicssystem.hpp +++ b/apps/opencs/view/world/physicssystem.hpp @@ -53,11 +53,13 @@ namespace CSVWorld void addHeightField(float* heights, int x, int y, float yoffset, float triSize, float sqrtVerts); + void removeHeightField(int x, int y); + void toggleDebugRendering(); std::pair castRay(float mouseX, float mouseY, - Ogre::Vector3* normal, std::string* hit, - Ogre::Camera *camera, bool ignoreHeightMap); + Ogre::Vector3* normal, std::string* hit, + Ogre::Camera *camera, bool ignoreHeightMap); }; }