mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 22:15:32 +00:00
Delay removing physics until the document is closed. Also other general cleanup.
This commit is contained in:
parent
1ee64c7087
commit
c6a2461fbd
6 changed files with 54 additions and 37 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include "../world/vartypedelegate.hpp"
|
#include "../world/vartypedelegate.hpp"
|
||||||
#include "../world/recordstatusdelegate.hpp"
|
#include "../world/recordstatusdelegate.hpp"
|
||||||
#include "../world/idtypedelegate.hpp"
|
#include "../world/idtypedelegate.hpp"
|
||||||
|
#include "../world/physicsmanager.hpp"
|
||||||
|
|
||||||
#include "../../model/settings/usersettings.hpp"
|
#include "../../model/settings/usersettings.hpp"
|
||||||
|
|
||||||
|
@ -218,6 +219,7 @@ void CSVDoc::ViewManager::removeDocAndView (CSMDoc::Document *document)
|
||||||
mDocumentManager.removeDocument(document);
|
mDocumentManager.removeDocument(document);
|
||||||
(*iter)->deleteLater();
|
(*iter)->deleteLater();
|
||||||
mViews.erase (iter);
|
mViews.erase (iter);
|
||||||
|
CSVWorld::PhysicsManager::instance()->removeDocument(document);
|
||||||
|
|
||||||
updateIndices();
|
updateIndices();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -927,8 +927,7 @@ void CSVRender::WorldspaceWidget::placeObject(const std::string sceneNode, const
|
||||||
|
|
||||||
// FIXME: adjustRigidBody() seems to lose objects, work around by deleting and recreating objects
|
// FIXME: adjustRigidBody() seems to lose objects, work around by deleting and recreating objects
|
||||||
//mPhysics->moveObject(sceneNode, pos, xr*yr*zr);
|
//mPhysics->moveObject(sceneNode, pos, xr*yr*zr);
|
||||||
std::string mesh = mPhysics->sceneNodeToMesh(sceneNode);
|
mPhysics->replaceObject(sceneNode, refId, cellref.mScale, pos, xr*yr*zr);
|
||||||
mPhysics->replaceObject(mesh, sceneNode, refId, cellref.mScale, pos, xr*yr*zr);
|
|
||||||
|
|
||||||
// update all SceneWidgets and their SceneManagers
|
// update all SceneWidgets and their SceneManagers
|
||||||
updateSceneWidgets();
|
updateSceneWidgets();
|
||||||
|
|
|
@ -34,11 +34,28 @@ namespace CSVWorld
|
||||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.find(doc);
|
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.find(doc);
|
||||||
if(iter == mSceneWidgets.end())
|
if(iter == mSceneWidgets.end())
|
||||||
{
|
{
|
||||||
mSceneWidgets[doc] = std::list<CSVRender::SceneWidget *> {}; // zero elements
|
mSceneWidgets[doc] = std::list<CSVRender::SceneWidget *> (); // zero elements
|
||||||
mPhysics[doc] = new PhysicsSystem();
|
mPhysics[doc] = new PhysicsSystem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// destroy physics, called from CSVDoc::ViewManager
|
||||||
|
void PhysicsManager::removeDocument(CSMDoc::Document *doc)
|
||||||
|
{
|
||||||
|
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *>::iterator iter = mPhysics.find(doc);
|
||||||
|
if(iter != mPhysics.end())
|
||||||
|
{
|
||||||
|
delete iter->second;
|
||||||
|
mPhysics.erase(iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator it = mSceneWidgets.find(doc);
|
||||||
|
if(it != mSceneWidgets.end())
|
||||||
|
{
|
||||||
|
mSceneWidgets.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// called from CSVRender::WorldspaceWidget() to get widgets' association with Document&
|
// called from CSVRender::WorldspaceWidget() to get widgets' association with Document&
|
||||||
PhysicsSystem *PhysicsManager::addSceneWidget(CSMDoc::Document &doc, CSVRender::WorldspaceWidget *widget)
|
PhysicsSystem *PhysicsManager::addSceneWidget(CSMDoc::Document &doc, CSVRender::WorldspaceWidget *widget)
|
||||||
{
|
{
|
||||||
|
@ -72,12 +89,8 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
(*iter).second.erase(itWidget);
|
(*iter).second.erase(itWidget);
|
||||||
|
|
||||||
if((*iter).second.empty()) // last one for the document
|
//if((*iter).second.empty()) // last one for the document
|
||||||
{
|
// NOTE: do not delete physics until the document itself is closed
|
||||||
delete mPhysics[(*iter).first];
|
|
||||||
mPhysics.erase((*iter).first);
|
|
||||||
mSceneWidgets.erase(iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
static PhysicsManager *mPhysicsManagerInstance;
|
static PhysicsManager *mPhysicsManagerInstance;
|
||||||
|
|
||||||
//std::map<CSVRender::SceneWidget *, Ogre::SceneManager*> mSceneManagers;
|
|
||||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> > mSceneWidgets;
|
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> > mSceneWidgets;
|
||||||
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *> mPhysics;
|
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *> mPhysics;
|
||||||
|
|
||||||
|
@ -43,15 +42,12 @@ namespace CSVWorld
|
||||||
static PhysicsManager *instance();
|
static PhysicsManager *instance();
|
||||||
|
|
||||||
void setupPhysics(CSMDoc::Document *);
|
void setupPhysics(CSMDoc::Document *);
|
||||||
#if 0
|
|
||||||
void addSceneManager(CSVRender::SceneWidget *sceneWidget, Ogre::SceneManager *sceneMgr);
|
|
||||||
|
|
||||||
void removeSceneManager(CSVRender::SceneWidget *sceneWidget);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PhysicsSystem *addSceneWidget(CSMDoc::Document &doc, CSVRender::WorldspaceWidget *widget);
|
PhysicsSystem *addSceneWidget(CSMDoc::Document &doc, CSVRender::WorldspaceWidget *widget);
|
||||||
|
|
||||||
void removeSceneWidget(CSVRender::WorldspaceWidget *widget);
|
void removeSceneWidget(CSVRender::WorldspaceWidget *widget);
|
||||||
|
|
||||||
|
void removeDocument(CSMDoc::Document *doc);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ namespace CSVWorld
|
||||||
delete mEngine;
|
delete mEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: looks up the scene manager based on the scene node name (highly inefficient)
|
// looks up the scene manager based on the scene node name (inefficient)
|
||||||
// NOTE: referenceId is assumed to be unique per document
|
// NOTE: referenceId is assumed to be unique per document
|
||||||
// NOTE: searching is done here rather than after rayTest, so slower to load but
|
// NOTE: searching is done here rather than after rayTest, hence slower to load but
|
||||||
// faster to find (not verified w/ perf test)
|
// faster to find (guessing, not verified w/ perf test)
|
||||||
void PhysicsSystem::addObject(const std::string &mesh,
|
void PhysicsSystem::addObject(const std::string &mesh,
|
||||||
const std::string &sceneNodeName, const std::string &referenceId, float scale,
|
const std::string &sceneNodeName, const std::string &referenceId, float scale,
|
||||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable)
|
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable)
|
||||||
|
@ -48,7 +48,12 @@ namespace CSVWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!foundSceneManager)
|
if(!foundSceneManager)
|
||||||
return; // FIXME: should this be an exception
|
{
|
||||||
|
std::cerr << "Attempt to add an object without a corresponding SceneManager: "
|
||||||
|
+ referenceId + " : " + sceneNodeName << std::endl;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// update physics, only one physics model per referenceId
|
// update physics, only one physics model per referenceId
|
||||||
if(mEngine->getRigidBody(referenceId, true) == NULL)
|
if(mEngine->getRigidBody(referenceId, true) == NULL)
|
||||||
|
@ -61,7 +66,7 @@ namespace CSVWorld
|
||||||
placeable);
|
placeable);
|
||||||
|
|
||||||
// update other scene managers if they have the referenceId (may have moved)
|
// update other scene managers if they have the referenceId (may have moved)
|
||||||
// FIXME: this bit not needed if object has not moved
|
// NOTE: this part is not needed if object has not moved
|
||||||
iter = mSceneManagers.begin();
|
iter = mSceneManagers.begin();
|
||||||
for(; iter != mSceneManagers.end(); ++iter)
|
for(; iter != mSceneManagers.end(); ++iter)
|
||||||
{
|
{
|
||||||
|
@ -99,7 +104,12 @@ namespace CSVWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sceneManager)
|
if(!sceneManager)
|
||||||
return; // FIXME: maybe this should be an exception
|
{
|
||||||
|
std::cerr << "Attempt to remove an object without a corresponding SceneManager: "
|
||||||
|
+ sceneNodeName << std::endl;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// illustration: erase the object "K" from the object map
|
// illustration: erase the object "K" from the object map
|
||||||
//
|
//
|
||||||
|
@ -123,7 +133,7 @@ namespace CSVWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// should the physics model be deleted?
|
// check whether the physics model be deleted
|
||||||
if(force || mRefIdToSceneNode.find(referenceId) == mRefIdToSceneNode.end())
|
if(force || mRefIdToSceneNode.find(referenceId) == mRefIdToSceneNode.end())
|
||||||
{
|
{
|
||||||
mEngine->removeRigidBody(referenceId);
|
mEngine->removeRigidBody(referenceId);
|
||||||
|
@ -132,10 +142,11 @@ namespace CSVWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSystem::replaceObject(const std::string &mesh,
|
void PhysicsSystem::replaceObject(const std::string &sceneNodeName,
|
||||||
const std::string &sceneNodeName, const std::string &referenceId, float scale,
|
const std::string &referenceId, float scale, const Ogre::Vector3 &position,
|
||||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable)
|
const Ogre::Quaternion &rotation, bool placeable)
|
||||||
{
|
{
|
||||||
|
std::string mesh = mSceneNodeToMesh[sceneNodeName];
|
||||||
removeObject(sceneNodeName, true); // force delete
|
removeObject(sceneNodeName, true); // force delete
|
||||||
addObject(mesh, sceneNodeName, referenceId, scale, position, rotation, placeable);
|
addObject(mesh, sceneNodeName, referenceId, scale, position, rotation, placeable);
|
||||||
}
|
}
|
||||||
|
@ -259,11 +270,6 @@ namespace CSVWorld
|
||||||
return mSceneNodeToRefId[sceneNodeName];
|
return mSceneNodeToRefId[sceneNodeName];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PhysicsSystem::sceneNodeToMesh(std::string sceneNodeName)
|
|
||||||
{
|
|
||||||
return mSceneNodeToMesh[sceneNodeName];
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget * sceneWidget)
|
void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget * sceneWidget)
|
||||||
{
|
{
|
||||||
mSceneManagers.push_back(sceneMgr);
|
mSceneManagers.push_back(sceneMgr);
|
||||||
|
@ -293,7 +299,7 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
// FIXME: should check if sceneMgr is in the list
|
// FIXME: should check if sceneMgr is in the list
|
||||||
if(!sceneMgr)
|
if(!sceneMgr)
|
||||||
return; // FIXME: maybe this should be an exception
|
return;
|
||||||
|
|
||||||
mEngine->setSceneManager(sceneMgr);
|
mEngine->setSceneManager(sceneMgr);
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,9 @@ namespace CSVWorld
|
||||||
|
|
||||||
PhysicsSystem();
|
PhysicsSystem();
|
||||||
~PhysicsSystem();
|
~PhysicsSystem();
|
||||||
|
|
||||||
void addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget * scene);
|
void addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget * scene);
|
||||||
|
|
||||||
void removeSceneManager(Ogre::SceneManager *sceneMgr);
|
void removeSceneManager(Ogre::SceneManager *sceneMgr);
|
||||||
|
|
||||||
void addObject(const std::string &mesh,
|
void addObject(const std::string &mesh,
|
||||||
|
@ -52,10 +54,9 @@ namespace CSVWorld
|
||||||
|
|
||||||
void removeObject(const std::string &sceneNodeName, bool force = false);
|
void removeObject(const std::string &sceneNodeName, bool force = false);
|
||||||
|
|
||||||
void replaceObject(const std::string &mesh,
|
void replaceObject(const std::string &sceneNodeName,
|
||||||
const std::string &sceneNodeName, const std::string &referenceId, float scale,
|
const std::string &referenceId, float scale, const Ogre::Vector3 &position,
|
||||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
|
const Ogre::Quaternion &rotation, bool placeable=false);
|
||||||
bool placeable=false);
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -75,8 +76,7 @@ namespace CSVWorld
|
||||||
|
|
||||||
std::string sceneNodeToRefId(std::string sceneNodeName);
|
std::string sceneNodeToRefId(std::string sceneNodeName);
|
||||||
|
|
||||||
std::string sceneNodeToMesh(std::string sceneNodeName);
|
// for multi-scene manager per physics engine
|
||||||
|
|
||||||
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets();
|
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -85,6 +85,7 @@ namespace CSVWorld
|
||||||
const std::string referenceId, const Ogre::Vector3 &position);
|
const std::string referenceId, const Ogre::Vector3 &position);
|
||||||
|
|
||||||
void updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position);
|
void updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position);
|
||||||
|
|
||||||
std::string refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr);
|
std::string refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue