diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 93197f690c..b562e19eea 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -84,7 +84,7 @@ void MWScene::doPhysics (float duration, MWWorld::World& world, MWWorld::DoingPhysics scopeGuard; //set the DebugRenderingMode. To disable it,set it to 0 - eng->setDebugRenderingMode(1); +// eng->setDebugRenderingMode(1); //set the walkdirection to 0 (no movement) for every actor) for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) @@ -213,3 +213,16 @@ void MWScene::toggleCollisionMode() } } } + +void MWScene::toggleRenderMode (int mode) +{ + switch (mode) + { + case MWWorld::World::Render_CollisionDebug: + + // TODO use a proper function instead of accessing the member variable + // directly. + eng->setDebugRenderingMode (!eng->isDebugCreated); + break; + } +} diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index 292862ba49..aa567f7def 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -92,6 +92,11 @@ namespace MWRender /// Toggle collision mode for player. If disabled player object should ignore /// collisions and gravity. void 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); }; } diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index a84de3edd7..9c756e11f0 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -8,6 +8,7 @@ #include #include "../mwworld/world.hpp" +#include "../mwworld/player.hpp" #include "interpretercontext.hpp" @@ -84,9 +85,27 @@ namespace MWScript } }; + class OpGetInterior : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context + = static_cast (runtime.getContext()); + + bool interior = + context.getWorld().getPlayer().getPlayer().getCell()->cell->data.flags & + ESM::Cell::Interior; + + runtime.push (interior ? 1 : 0); + } + }; + const int opcodeCellChanged = 0x2000000; const int opcodeCOC = 0x2000026; const int opcodeCOE = 0x200008e; + const int opcodeGetInterior = 0x2000131; void registerExtensions (Compiler::Extensions& extensions) { @@ -95,6 +114,7 @@ namespace MWScript extensions.registerInstruction ("centeroncell", "S", opcodeCOC); extensions.registerInstruction ("coe", "ll", opcodeCOE); extensions.registerInstruction ("centeronexterior", "ll", opcodeCOE); + extensions.registerFunction ("getinterior", 'l', "", opcodeGetInterior); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -102,6 +122,7 @@ namespace MWScript interpreter.installSegment5 (opcodeCellChanged, new OpCellChanged); interpreter.installSegment5 (opcodeCOC, new OpCOC); interpreter.installSegment5 (opcodeCOE, new OpCOE); + interpreter.installSegment5 (opcodeGetInterior, new OpGetInterior); } } } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index ac78f80054..d803d0bac2 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -102,4 +102,6 @@ op 0x20000df-0x20000f9: SetSkill, explicit reference op 0x20000fa-0x2000114: ModSkill op 0x2000115-0x200012f: ModSKill, explicit reference op 0x2000130: ToggleCollision -opcodes 0x2000131-0x3ffffff unused +op 0x2000131: GetInterior +op 0x2000132: ToggleCollsionDebug +opcodes 0x2000133-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index a04065f9cf..9bfb8774d1 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -90,6 +90,18 @@ namespace MWScript } }; + class OpToggleCollisionDebug : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getWorld().toggleRenderMode (MWWorld::World::Render_CollisionDebug); + } + }; const int opcodeXBox = 0x200000c; const int opcodeOnActivate = 0x200000d; @@ -98,6 +110,7 @@ namespace MWScript const int opcodeLockExplicit = 0x20005; const int opcodeUnlock = 0x200008c; const int opcodeUnlockExplicit = 0x200008d; + const int opcodeToggleCollisionDebug = 0x2000132; void registerExtensions (Compiler::Extensions& extensions) { @@ -106,6 +119,10 @@ namespace MWScript extensions.registerInstruction ("activate", "", opcodeActivate); extensions.registerInstruction ("lock", "/l", opcodeLock, opcodeLockExplicit); extensions.registerInstruction ("unlock", "", opcodeUnlock, opcodeUnlockExplicit); + extensions.registerInstruction ("togglecollisionboxes", "", opcodeToggleCollisionDebug); + extensions.registerInstruction ("togglecollisiongrid", "", opcodeToggleCollisionDebug); + extensions.registerInstruction ("tcb", "", opcodeToggleCollisionDebug); + extensions.registerInstruction ("tcg", "", opcodeToggleCollisionDebug); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -117,6 +134,7 @@ namespace MWScript interpreter.installSegment3 (opcodeLockExplicit, new OpLock); interpreter.installSegment5 (opcodeUnlock, new OpUnlock); interpreter.installSegment5 (opcodeUnlockExplicit, new OpUnlock); + interpreter.installSegment5 (opcodeToggleCollisionDebug, new OpToggleCollisionDebug); } } } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index b30ee29a5f..8e3acab7f2 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -859,4 +859,9 @@ namespace MWWorld { mScene.toggleCollisionMode(); } + + void World::toggleRenderMode (RenderMode mode) + { + mScene.toggleRenderMode (mode); + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 5cd99d9cd2..d64fa57be1 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -50,6 +50,11 @@ namespace MWWorld public: typedef std::list > ScriptList; + enum RenderMode + { + Render_CollisionDebug + }; + private: typedef std::map CellRenderCollection; @@ -183,6 +188,9 @@ namespace MWWorld void toggleCollisionMode(); ///< Toggle collision mode for player. If disabled player object should ignore /// collisions and gravity. + + void toggleRenderMode (RenderMode mode); + ///< Toggle a render mode. }; }