mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-11 09:36:37 +00:00
Add missing files for multi-document support.
This commit is contained in:
parent
b328aa1fb9
commit
1ee64c7087
87
apps/opencs/view/world/physicsmanager.cpp
Normal file
87
apps/opencs/view/world/physicsmanager.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "physicsmanager.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../render/worldspacewidget.hpp"
|
||||
#include "physicssystem.hpp"
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
PhysicsManager *PhysicsManager::mPhysicsManagerInstance = 0;
|
||||
|
||||
PhysicsManager::PhysicsManager()
|
||||
{
|
||||
assert(!mPhysicsManagerInstance);
|
||||
mPhysicsManagerInstance = this;
|
||||
}
|
||||
|
||||
PhysicsManager::~PhysicsManager()
|
||||
{
|
||||
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *>::iterator iter = mPhysics.begin();
|
||||
for(; iter != mPhysics.end(); ++iter)
|
||||
delete iter->second; // shouldn't be any left but just in case
|
||||
}
|
||||
|
||||
PhysicsManager *PhysicsManager::instance()
|
||||
{
|
||||
assert(mPhysicsManagerInstance);
|
||||
return mPhysicsManagerInstance;
|
||||
}
|
||||
|
||||
// create a physics instance per document, called from CSVDoc::View() to get Document*
|
||||
void PhysicsManager::setupPhysics(CSMDoc::Document *doc)
|
||||
{
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.find(doc);
|
||||
if(iter == mSceneWidgets.end())
|
||||
{
|
||||
mSceneWidgets[doc] = std::list<CSVRender::SceneWidget *> {}; // zero elements
|
||||
mPhysics[doc] = new PhysicsSystem();
|
||||
}
|
||||
}
|
||||
|
||||
// called from CSVRender::WorldspaceWidget() to get widgets' association with Document&
|
||||
PhysicsSystem *PhysicsManager::addSceneWidget(CSMDoc::Document &doc, CSVRender::WorldspaceWidget *widget)
|
||||
{
|
||||
CSVRender::SceneWidget *sceneWidget = static_cast<CSVRender::SceneWidget *>(widget);
|
||||
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.begin();
|
||||
for(; iter != mSceneWidgets.end(); ++iter)
|
||||
{
|
||||
if((*iter).first == &doc)
|
||||
{
|
||||
(*iter).second.push_back(sceneWidget);
|
||||
return mPhysics[(*iter).first]; // TODO: consider using shared_ptr instead
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("No physics system found for the given document.");
|
||||
}
|
||||
|
||||
// delete physics when the last scene widget for the document is closed
|
||||
void PhysicsManager::removeSceneWidget(CSVRender::WorldspaceWidget *widget)
|
||||
{
|
||||
CSVRender::SceneWidget *sceneWidget = static_cast<CSVRender::SceneWidget *>(widget);
|
||||
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> >::iterator iter = mSceneWidgets.begin();
|
||||
for(; iter != mSceneWidgets.end(); ++iter)
|
||||
{
|
||||
std::list<CSVRender::SceneWidget *>::iterator itWidget = (*iter).second.begin();
|
||||
for(; itWidget != (*iter).second.end(); ++itWidget)
|
||||
{
|
||||
if((*itWidget) == sceneWidget)
|
||||
{
|
||||
(*iter).second.erase(itWidget);
|
||||
|
||||
if((*iter).second.empty()) // last one for the document
|
||||
{
|
||||
delete mPhysics[(*iter).first];
|
||||
mPhysics.erase((*iter).first);
|
||||
mSceneWidgets.erase(iter);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
apps/opencs/view/world/physicsmanager.hpp
Normal file
58
apps/opencs/view/world/physicsmanager.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef CSV_WORLD_PHYSICSMANAGER_H
|
||||
#define CSV_WORLD_PHYSICSMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class SceneManager;
|
||||
}
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class WorldspaceWidget;
|
||||
class SceneWidget;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class PhysicsSystem;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class PhysicsManager
|
||||
{
|
||||
static PhysicsManager *mPhysicsManagerInstance;
|
||||
|
||||
//std::map<CSVRender::SceneWidget *, Ogre::SceneManager*> mSceneManagers;
|
||||
std::map<CSMDoc::Document *, std::list<CSVRender::SceneWidget *> > mSceneWidgets;
|
||||
std::map<CSMDoc::Document *, CSVWorld::PhysicsSystem *> mPhysics;
|
||||
|
||||
public:
|
||||
|
||||
PhysicsManager();
|
||||
~PhysicsManager();
|
||||
|
||||
static PhysicsManager *instance();
|
||||
|
||||
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);
|
||||
|
||||
void removeSceneWidget(CSVRender::WorldspaceWidget *widget);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSV_WORLD_PHYSICSMANAGER_H
|
Loading…
Reference in New Issue
Block a user