From 9a5a6eac2b3ec6b4601f88b79f7e03cb281bdf7c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 27 Jan 2011 09:29:55 +0100 Subject: [PATCH 1/2] stop reporting changes originating from physics system back to physics system --- apps/openmw/CMakeLists.txt | 2 ++ apps/openmw/mwrender/mwscene.cpp | 3 +++ apps/openmw/mwworld/doingphysics.cpp | 22 ++++++++++++++++++++++ apps/openmw/mwworld/doingphysics.hpp | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 apps/openmw/mwworld/doingphysics.cpp create mode 100644 apps/openmw/mwworld/doingphysics.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 5d10b4fed..1873583c1 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -125,6 +125,7 @@ set(GAMEWORLD mwworld/actiontake.cpp mwworld/containerutil.cpp mwworld/player.cpp + mwworld/doingphysics.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -143,6 +144,7 @@ set(GAMEWORLD_HEADER mwworld/manualref.hpp mwworld/containerutil.hpp mwworld/player.hpp + mwworld/doingphysics.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 92d0fbac5..6a0920b94 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -11,6 +11,7 @@ #include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwworld/ptr.hpp" +#include "../mwworld/doingphysics.hpp" #include #include "player.hpp" @@ -100,6 +101,8 @@ std::pair MWScene::getFacedHandle (MWWorld::World& world) void MWScene::doPhysics (float duration, MWWorld::World& world) { + // stop changes to world from being reported back to the physics system + MWWorld::DoingPhysics scopeGuard; } diff --git a/apps/openmw/mwworld/doingphysics.cpp b/apps/openmw/mwworld/doingphysics.cpp new file mode 100644 index 000000000..63c6244e9 --- /dev/null +++ b/apps/openmw/mwworld/doingphysics.cpp @@ -0,0 +1,22 @@ + +#include "doingphysics.hpp" + +namespace MWWorld +{ + int DoingPhysics::sCounter = 0; + + DoingPhysics::DoingPhysics() + { + ++sCounter; + } + + DoingPhysics::~DoingPhysics() + { + --sCounter; + } + + bool DoingPhysics::isDoingPhysics() + { + return sCounter>0; + } +} diff --git a/apps/openmw/mwworld/doingphysics.hpp b/apps/openmw/mwworld/doingphysics.hpp new file mode 100644 index 000000000..7ea2b0f41 --- /dev/null +++ b/apps/openmw/mwworld/doingphysics.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_MWWORLD_DOINGPHYSICS_H +#define GAME_MWWORLD_DOINGPHYSICS_H + +namespace MWWorld +{ + ///< Scope guard for blocking physics updates during physics simulation. + class DoingPhysics + { + static int sCounter; + + private: + + DoingPhysics (const DoingPhysics&); + DoingPhysics& operator= (const DoingPhysics&); + + public: + + DoingPhysics(); + + ~DoingPhysics(); + + static bool isDoingPhysics(); + }; +} + +#endif From 5486c70edf0ae172b33c0edbd99658cc29424a34 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 27 Jan 2011 09:46:54 +0100 Subject: [PATCH 2/2] connected object-manipulator functions in world to physics interface --- apps/openmw/mwworld/world.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 44bfa9112..52547adc2 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -21,6 +21,7 @@ #include "refdata.hpp" #include "globals.hpp" +#include "doingphysics.hpp" namespace { @@ -745,14 +746,17 @@ namespace MWWorld if (MWRender::CellRender *render = searchRender (ptr.getCell())) { - render->deleteObject (ptr.getRefData().getHandle()); - ptr.getRefData().setHandle (""); - if (mActiveCells.find (ptr.getCell())!=mActiveCells.end()) { Class::get (ptr).disable (ptr, mEnvironment); mEnvironment.mSoundManager->stopSound3D (ptr); + + if (!DoingPhysics::isDoingPhysics()) + mScene.removeObject (ptr.getRefData().getHandle()); } + + render->deleteObject (ptr.getRefData().getHandle()); + ptr.getRefData().setHandle (""); } } } @@ -778,6 +782,9 @@ namespace MWWorld if (mCurrentCell->cell->data.gridX!=cellX || mCurrentCell->cell->data.gridY!=cellY) { changeCell (cellX, cellY, mPlayer->getPlayer().getCellRef().pos); + + if (!DoingPhysics::isDoingPhysics()) + mScene.moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z)); } } }