Experimental, compiles and runs but crashes in some exit scenarios.

loadfix
cc9cii 10 years ago
parent d48a2759f6
commit 0e70315f91

@ -68,7 +68,7 @@ opencs_units (view/world
opencs_units_noqt (view/world opencs_units_noqt (view/world
subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate
scripthighlighter idvalidator dialoguecreator physicssystem physicsmanager scripthighlighter idvalidator dialoguecreator physicssystem physicsmanager physicsengine
) )
opencs_units (view/widget opencs_units (view/widget

@ -266,7 +266,9 @@ namespace CSVRender
void MouseState::mouseDoubleClickEvent (QMouseEvent *event) void MouseState::mouseDoubleClickEvent (QMouseEvent *event)
{ {
event->ignore(); //event->ignore();
mPhysics->toggleDebugRendering(mSceneManager);
mParent->flagAsModified();
} }
bool MouseState::wheelEvent (QWheelEvent *event) bool MouseState::wheelEvent (QWheelEvent *event)

@ -74,6 +74,9 @@ namespace CSVWorld
throw std::runtime_error("No physics system found for the given document."); throw std::runtime_error("No physics system found for the given document.");
} }
// deprecated by removeDocument() and may be deleted in future code updates
// however there may be some value in removing the deleted scene widgets from the
// list so that the list does not grow forever
void PhysicsManager::removeSceneWidget(CSVRender::WorldspaceWidget *widget) void PhysicsManager::removeSceneWidget(CSVRender::WorldspaceWidget *widget)
{ {
CSVRender::SceneWidget *sceneWidget = static_cast<CSVRender::SceneWidget *>(widget); CSVRender::SceneWidget *sceneWidget = static_cast<CSVRender::SceneWidget *>(widget);

@ -6,7 +6,7 @@
#include <OgreCamera.h> #include <OgreCamera.h>
#include <OgreSceneManager.h> #include <OgreSceneManager.h>
#include <openengine/bullet/physic.hpp> #include "physicsengine.hpp"
#include <components/nifbullet/bulletnifloader.hpp> #include <components/nifbullet/bulletnifloader.hpp>
#include "../../model/settings/usersettings.hpp" #include "../../model/settings/usersettings.hpp"
#include "../render/elements.hpp" #include "../render/elements.hpp"
@ -15,17 +15,12 @@ namespace CSVWorld
{ {
PhysicsSystem::PhysicsSystem() PhysicsSystem::PhysicsSystem()
{ {
// Create physics. shapeLoader is deleted by the physic engine mEngine = new PhysicsEngine();
NifBullet::ManualBulletShapeLoader* shapeLoader = new NifBullet::ManualBulletShapeLoader();
mEngine = new OEngine::Physic::PhysicEngine(shapeLoader);
} }
PhysicsSystem::~PhysicsSystem() PhysicsSystem::~PhysicsSystem()
{ {
// FIXME: OEngine does not behave well when multiple instances are created delete mEngine;
// and deleted, sometimes resulting in crashes. Skip the deletion until the physics
// code is moved out of OEngine.
//delete mEngine;
} }
// looks up the scene manager based on the scene node name (inefficient) // looks up the scene manager based on the scene node name (inefficient)
@ -56,8 +51,6 @@ namespace CSVWorld
{ {
mEngine->createAndAdjustRigidBody(mesh, mEngine->createAndAdjustRigidBody(mesh,
referenceId, scale, position, rotation, referenceId, scale, position, rotation,
0, // scaledBoxTranslation
0, // boxRotation
true, // raycasting true, // raycasting
placeable); placeable);
} }
@ -146,7 +139,7 @@ namespace CSVWorld
// create a new physics object // create a new physics object
mEngine->createAndAdjustRigidBody(mesh, referenceId, scale, position, rotation, mEngine->createAndAdjustRigidBody(mesh, referenceId, scale, position, rotation,
0, 0, true, placeable); true, placeable);
// update other scene managers if they have the referenceId // update other scene managers if they have the referenceId
// FIXME: rotation or scale not updated // FIXME: rotation or scale not updated
@ -278,6 +271,8 @@ namespace CSVWorld
void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget *sceneWidget) void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget *sceneWidget)
{ {
mSceneWidgets[sceneMgr] = sceneWidget; mSceneWidgets[sceneMgr] = sceneWidget;
mEngine->createDebugDraw(sceneMgr);
} }
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> PhysicsSystem::sceneWidgets() std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> PhysicsSystem::sceneWidgets()
@ -287,6 +282,8 @@ namespace CSVWorld
void PhysicsSystem::removeSceneManager(Ogre::SceneManager *sceneMgr) void PhysicsSystem::removeSceneManager(Ogre::SceneManager *sceneMgr)
{ {
mEngine->removeDebugDraw(sceneMgr);
mSceneWidgets.erase(sceneMgr); mSceneWidgets.erase(sceneMgr);
} }
@ -310,8 +307,6 @@ namespace CSVWorld
if(!sceneMgr) if(!sceneMgr)
return; return;
mEngine->setSceneManager(sceneMgr);
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
if(!(userSettings.setting("debug/mouse-picking", QString("false")) == "true" ? true : false)) if(!(userSettings.setting("debug/mouse-picking", QString("false")) == "true" ? true : false))
{ {
@ -319,7 +314,7 @@ namespace CSVWorld
return; return;
} }
mEngine->toggleDebugRendering(); mEngine->toggleDebugRendering(sceneMgr);
mEngine->stepSimulation(0.0167); // DebugDrawer::step() not directly accessible mEngine->stepDebug(sceneMgr);
} }
} }

@ -12,14 +12,6 @@ namespace Ogre
class Camera; class Camera;
} }
namespace OEngine
{
namespace Physic
{
class PhysicEngine;
}
}
namespace CSVRender namespace CSVRender
{ {
class SceneWidget; class SceneWidget;
@ -27,13 +19,15 @@ namespace CSVRender
namespace CSVWorld namespace CSVWorld
{ {
class PhysicsEngine;
class PhysicsSystem class PhysicsSystem
{ {
std::map<std::string, std::string> mSceneNodeToRefId; std::map<std::string, std::string> mSceneNodeToRefId;
std::map<std::string, std::map<Ogre::SceneManager *, std::string> > mRefIdToSceneNode; std::map<std::string, std::map<Ogre::SceneManager *, std::string> > mRefIdToSceneNode;
std::map<std::string, std::string> mSceneNodeToMesh; std::map<std::string, std::string> mSceneNodeToMesh;
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> mSceneWidgets; std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> mSceneWidgets;
OEngine::Physic::PhysicEngine* mEngine; PhysicsEngine* mEngine;
std::multimap<std::string, Ogre::SceneManager *> mTerrain; std::multimap<std::string, Ogre::SceneManager *> mTerrain;
public: public:

Loading…
Cancel
Save