From 0e70315f91ce6a3630f5bc8ca836702c4aeb0c4b Mon Sep 17 00:00:00 2001 From: cc9cii Date: Tue, 4 Nov 2014 20:43:04 +1100 Subject: [PATCH] Experimental, compiles and runs but crashes in some exit scenarios. --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/render/mousestate.cpp | 4 +++- apps/opencs/view/world/physicsmanager.cpp | 3 +++ apps/opencs/view/world/physicssystem.cpp | 25 +++++++++-------------- apps/opencs/view/world/physicssystem.hpp | 12 +++-------- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index ec6f802cf..b6c24e190 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -68,7 +68,7 @@ opencs_units (view/world opencs_units_noqt (view/world subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate - scripthighlighter idvalidator dialoguecreator physicssystem physicsmanager + scripthighlighter idvalidator dialoguecreator physicssystem physicsmanager physicsengine ) opencs_units (view/widget diff --git a/apps/opencs/view/render/mousestate.cpp b/apps/opencs/view/render/mousestate.cpp index af835d0a5..94ab9bc0b 100644 --- a/apps/opencs/view/render/mousestate.cpp +++ b/apps/opencs/view/render/mousestate.cpp @@ -266,7 +266,9 @@ namespace CSVRender void MouseState::mouseDoubleClickEvent (QMouseEvent *event) { - event->ignore(); + //event->ignore(); + mPhysics->toggleDebugRendering(mSceneManager); + mParent->flagAsModified(); } bool MouseState::wheelEvent (QWheelEvent *event) diff --git a/apps/opencs/view/world/physicsmanager.cpp b/apps/opencs/view/world/physicsmanager.cpp index f8e022e5d..2d8dcd95a 100644 --- a/apps/opencs/view/world/physicsmanager.cpp +++ b/apps/opencs/view/world/physicsmanager.cpp @@ -74,6 +74,9 @@ namespace CSVWorld 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) { CSVRender::SceneWidget *sceneWidget = static_cast(widget); diff --git a/apps/opencs/view/world/physicssystem.cpp b/apps/opencs/view/world/physicssystem.cpp index 73063b6be..98e3a71e9 100644 --- a/apps/opencs/view/world/physicssystem.cpp +++ b/apps/opencs/view/world/physicssystem.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include "physicsengine.hpp" #include #include "../../model/settings/usersettings.hpp" #include "../render/elements.hpp" @@ -15,17 +15,12 @@ namespace CSVWorld { PhysicsSystem::PhysicsSystem() { - // Create physics. shapeLoader is deleted by the physic engine - NifBullet::ManualBulletShapeLoader* shapeLoader = new NifBullet::ManualBulletShapeLoader(); - mEngine = new OEngine::Physic::PhysicEngine(shapeLoader); + mEngine = new PhysicsEngine(); } PhysicsSystem::~PhysicsSystem() { - // FIXME: OEngine does not behave well when multiple instances are created - // and deleted, sometimes resulting in crashes. Skip the deletion until the physics - // code is moved out of OEngine. - //delete mEngine; + delete mEngine; } // looks up the scene manager based on the scene node name (inefficient) @@ -56,8 +51,6 @@ namespace CSVWorld { mEngine->createAndAdjustRigidBody(mesh, referenceId, scale, position, rotation, - 0, // scaledBoxTranslation - 0, // boxRotation true, // raycasting placeable); } @@ -146,7 +139,7 @@ namespace CSVWorld // create a new physics object mEngine->createAndAdjustRigidBody(mesh, referenceId, scale, position, rotation, - 0, 0, true, placeable); + true, placeable); // update other scene managers if they have the referenceId // FIXME: rotation or scale not updated @@ -278,6 +271,8 @@ namespace CSVWorld void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget *sceneWidget) { mSceneWidgets[sceneMgr] = sceneWidget; + + mEngine->createDebugDraw(sceneMgr); } std::map PhysicsSystem::sceneWidgets() @@ -287,6 +282,8 @@ namespace CSVWorld void PhysicsSystem::removeSceneManager(Ogre::SceneManager *sceneMgr) { + mEngine->removeDebugDraw(sceneMgr); + mSceneWidgets.erase(sceneMgr); } @@ -310,8 +307,6 @@ namespace CSVWorld if(!sceneMgr) return; - mEngine->setSceneManager(sceneMgr); - CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); if(!(userSettings.setting("debug/mouse-picking", QString("false")) == "true" ? true : false)) { @@ -319,7 +314,7 @@ namespace CSVWorld return; } - mEngine->toggleDebugRendering(); - mEngine->stepSimulation(0.0167); // DebugDrawer::step() not directly accessible + mEngine->toggleDebugRendering(sceneMgr); + mEngine->stepDebug(sceneMgr); } } diff --git a/apps/opencs/view/world/physicssystem.hpp b/apps/opencs/view/world/physicssystem.hpp index 0036bf769..731e527b1 100644 --- a/apps/opencs/view/world/physicssystem.hpp +++ b/apps/opencs/view/world/physicssystem.hpp @@ -12,14 +12,6 @@ namespace Ogre class Camera; } -namespace OEngine -{ - namespace Physic - { - class PhysicEngine; - } -} - namespace CSVRender { class SceneWidget; @@ -27,13 +19,15 @@ namespace CSVRender namespace CSVWorld { + class PhysicsEngine; + class PhysicsSystem { std::map mSceneNodeToRefId; std::map > mRefIdToSceneNode; std::map mSceneNodeToMesh; std::map mSceneWidgets; - OEngine::Physic::PhysicEngine* mEngine; + PhysicsEngine* mEngine; std::multimap mTerrain; public: