From f52e6bd5ef9dad530134a39ba1446b64caab6755 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 26 Apr 2011 21:38:21 +0200 Subject: [PATCH] made toggle-type script instructions more verbose --- apps/openmw/mwrender/mwscene.cpp | 13 +++-- apps/openmw/mwrender/mwscene.hpp | 6 ++- apps/openmw/mwscript/controlextensions.cpp | 4 +- apps/openmw/mwscript/miscextensions.cpp | 6 ++- apps/openmw/mwscript/skyextensions.cpp | 55 +++++++++++----------- apps/openmw/mwworld/world.cpp | 12 +++-- apps/openmw/mwworld/world.hpp | 9 ++-- 7 files changed, 63 insertions(+), 42 deletions(-) diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 890bf2cd6..e4d449bf2 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -191,7 +191,7 @@ void MWScene::scaleObject (const std::string& handle, float scale) } -void MWScene::toggleCollisionMode() +bool MWScene::toggleCollisionMode() { for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) { @@ -203,6 +203,7 @@ void MWScene::toggleCollisionMode() act->setGravity(0.); act->setVerticalVelocity(0); mFreeFly = true; + return false; } else { @@ -210,11 +211,15 @@ void MWScene::toggleCollisionMode() act->enableCollisions(true); act->setGravity(4.); act->setVerticalVelocity(0); + return true; } } + + return false; // This should never happen, but it shall not bother us now, since + // this part of the code needs a rewrite anyway. } -void MWScene::toggleRenderMode (int mode) +bool MWScene::toggleRenderMode (int mode) { switch (mode) { @@ -223,6 +228,8 @@ void MWScene::toggleRenderMode (int mode) // TODO use a proper function instead of accessing the member variable // directly. eng->setDebugRenderingMode (!eng->isDebugCreated); - break; + return eng->isDebugCreated; } + + return false; } diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index fd14fcce0..7429ff21e 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -91,12 +91,14 @@ namespace MWRender /// Toggle collision mode for player. If disabled player object should ignore /// collisions and gravity. - void toggleCollisionMode(); + /// \return Resulting mode + bool toggleCollisionMode(); /// Toggle render mode /// \todo Using an int instead of a enum here to avoid cyclic includes. Will be fixed /// when the mw*-refactoring is done. - void toggleRenderMode (int mode); + /// \return Resulting mode + bool toggleRenderMode (int mode); }; } diff --git a/apps/openmw/mwscript/controlextensions.cpp b/apps/openmw/mwscript/controlextensions.cpp index e687b1352..3d65c5705 100644 --- a/apps/openmw/mwscript/controlextensions.cpp +++ b/apps/openmw/mwscript/controlextensions.cpp @@ -46,7 +46,9 @@ namespace MWScript InterpreterContext& context = static_cast (runtime.getContext()); - context.getWorld().toggleCollisionMode(); + bool enabled = context.getWorld().toggleCollisionMode(); + + context.messageBox (enabled ? "Collsion -> On" : "Collision -> Off"); } }; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 9bfb8774d..e1c9eae3b 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -99,7 +99,11 @@ namespace MWScript InterpreterContext& context = static_cast (runtime.getContext()); - context.getWorld().toggleRenderMode (MWWorld::World::Render_CollisionDebug); + bool enabled = + context.getWorld().toggleRenderMode (MWWorld::World::Render_CollisionDebug); + + context.messageBox (enabled ? + "Collsion Mesh Rendering -> On" : "Collision Mesh Rendering -> Off"); } }; diff --git a/apps/openmw/mwscript/skyextensions.cpp b/apps/openmw/mwscript/skyextensions.cpp index f53168240..1a761e3bb 100644 --- a/apps/openmw/mwscript/skyextensions.cpp +++ b/apps/openmw/mwscript/skyextensions.cpp @@ -16,68 +16,70 @@ namespace MWScript class OpToggleSky : public Interpreter::Opcode0 { public: - + virtual void execute (Interpreter::Runtime& runtime) { InterpreterContext& context = static_cast (runtime.getContext()); - - context.getWorld().toggleSky(); - } - }; - + + bool enabled = context.getWorld().toggleSky(); + + context.messageBox (enabled ? "Sky -> On" : "Sky -> Off"); + } + }; + class OpTurnMoonWhite : public Interpreter::Opcode0 { public: - + virtual void execute (Interpreter::Runtime& runtime) { InterpreterContext& context = static_cast (runtime.getContext()); - + context.getWorld().setMoonColour (false); - } - }; + } + }; class OpTurnMoonRed : public Interpreter::Opcode0 { public: - + virtual void execute (Interpreter::Runtime& runtime) { InterpreterContext& context = static_cast (runtime.getContext()); - + context.getWorld().setMoonColour (true); - } - }; - + } + }; + class OpGetMasserPhase : public Interpreter::Opcode0 { public: - + virtual void execute (Interpreter::Runtime& runtime) { InterpreterContext& context = static_cast (runtime.getContext()); - + runtime.push (context.getWorld().getMasserPhase()); - } - }; + } + }; class OpGetSecundaPhase : public Interpreter::Opcode0 { public: - + virtual void execute (Interpreter::Runtime& runtime) { InterpreterContext& context = static_cast (runtime.getContext()); - + runtime.push (context.getWorld().getSecundaPhase()); - } - }; - + } + }; + const int opcodeToggleSky = 0x2000021; const int opcodeTurnMoonWhite = 0x2000022; const int opcodeTurnMoonRed = 0x2000023; @@ -93,7 +95,7 @@ namespace MWScript extensions.registerFunction ("getmasserphase", 'l', "", opcodeGetMasserPhase); extensions.registerFunction ("getsecundaphase", 'l', "", opcodeGetSecundaPhase); } - + void installOpcodes (Interpreter::Interpreter& interpreter) { interpreter.installSegment5 (opcodeToggleSky, new OpToggleSky); @@ -101,7 +103,6 @@ namespace MWScript interpreter.installSegment5 (opcodeTurnMoonRed, new OpTurnMoonRed); interpreter.installSegment5 (opcodeGetMasserPhase, new OpGetMasserPhase); interpreter.installSegment5 (opcodeGetSecundaPhase, new OpGetSecundaPhase); - } + } } } - diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 63019349c..a4001169d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -645,12 +645,13 @@ namespace MWWorld mSkyManager->setDate (mGlobalVariables->getInt ("day"), month); } - void World::toggleSky() + bool World::toggleSky() { if (mSky) { mSky = false; mSkyManager->disable(); + return false; } else { @@ -660,6 +661,7 @@ namespace MWWorld mSkyManager->setDate (mGlobalVariables->getInt ("day"), mGlobalVariables->getInt ("month")); mSkyManager->enable(); + return true; } } @@ -853,13 +855,13 @@ namespace MWWorld mScene.doPhysics (duration, *this, actors); } - void World::toggleCollisionMode() + bool World::toggleCollisionMode() { - mScene.toggleCollisionMode(); + return mScene.toggleCollisionMode(); } - void World::toggleRenderMode (RenderMode mode) + bool World::toggleRenderMode (RenderMode mode) { - mScene.toggleRenderMode (mode); + return mScene.toggleRenderMode (mode); } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 6965aebc6..739353394 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -147,7 +147,8 @@ namespace MWWorld void setDay (int day); - void toggleSky(); + bool toggleSky(); + ///< \return Resulting mode int getMasserPhase() const; @@ -185,12 +186,14 @@ namespace MWWorld float duration); ///< Run physics simulation and modify \a world accordingly. - void toggleCollisionMode(); + bool toggleCollisionMode(); ///< Toggle collision mode for player. If disabled player object should ignore /// collisions and gravity. + ///< \return Resulting mode - void toggleRenderMode (RenderMode mode); + bool toggleRenderMode (RenderMode mode); ///< Toggle a render mode. + ///< \return Resulting mode }; }