diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8ffe9921f..36eff8d0f 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -38,6 +38,7 @@ set(GAMESCRIPT mwscript/miscextensions.cpp mwscript/guiextensions.cpp mwscript/soundextensions.cpp + mwscript/skyextensions.cpp mwscript/extensions.cpp mwscript/globalscripts.cpp ) @@ -50,6 +51,7 @@ set(GAMESCRIPT_HEADER mwscript/miscextensions.hpp mwscript/guiextensions.hpp mwscript/soundextensions.hpp + mwscript/skyextensions.hpp mwscript/extensions.hpp mwscript/globalscripts.hpp ) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 95653d3a3..1edc72c88 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -217,8 +217,8 @@ void OMW::Engine::go() mScriptContext->setExtensions (&mExtensions); mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts, - *mScriptContext); - + *mScriptContext); + mEnvironment.mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(), *mScriptManager); diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 901ab405e..ef6cb3578 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -21,6 +21,26 @@ namespace MWRender CaelumManager (Ogre::RenderWindow* pRenderWindow, Ogre::Camera* pCamera); virtual ~CaelumManager (); + + virtual void enable() {} + + virtual void disable() {} + + virtual void setHour (double hour) {} + ///< will be called even when sky is disabled. + + virtual void setDay (int day) {} + ///< will be called even when sky is disabled. + + virtual int getMasserPhase() const { return 0; } + ///< 0 new moon, 1 waxing or waning cresecent, 2 waxing or waning half, + /// 3 waxing or waning gibbous, 4 full moon + + virtual int getSecundaPhase() const { return 0; } + ///< 0 new moon, 1 waxing or waning cresecent, 2 waxing or waning half, + /// 3 waxing or waning gibbous, 4 full moon + + virtual void setMoonColour (bool red) {} }; CaelumManager::CaelumManager (Ogre::RenderWindow* pRenderWindow, diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 35b8cca74..54a32eb90 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -18,6 +18,20 @@ namespace MWRender static SkyManager* create (Ogre::RenderWindow* pRenderWindow, Ogre::Camera* pCamera); virtual ~SkyManager() {} + + virtual void enable() = 0; + + virtual void disable() = 0; + + virtual void setHour (double hour) = 0; + + virtual void setDay (int day) = 0; + + virtual int getMasserPhase() const = 0; + + virtual int getSecundaPhase() const = 0; + + virtual void setMoonColour (bool red) = 0; }; } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index d968239bc..90c84c773 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -54,5 +54,10 @@ op 0x200001d: PlayLoopSound3D, explicit reference op 0x200001e: PlayLoopSound3DVP, explicit reference op 0x200001f: StopSound, explicit reference op 0x2000020: GetSoundPlaying, explicit reference -opcodes 0x2000021-0x3ffffff unused +op 0x2000021: ToggleSky +op 0x2000022: TurnMoonWhite +op 0x2000023: TurnMoonRed +op 0x2000024: GetMasserPhase +op 0x2000025: GetSecundaPhase +opcodes 0x2000026-0x3ffffff unused diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp index b688b2037..3d6566d62 100644 --- a/apps/openmw/mwscript/extensions.cpp +++ b/apps/openmw/mwscript/extensions.cpp @@ -5,6 +5,7 @@ #include "cellextensions.hpp" #include "miscextensions.hpp" #include "guiextensions.hpp" +#include "skyextensions.hpp" namespace MWScript { @@ -14,6 +15,7 @@ namespace MWScript Misc::registerExtensions (extensions); Gui::registerExtensions (extensions); Sound::registerExtensions (extensions); + Sky::registerExtensions (extensions); } } diff --git a/apps/openmw/mwscript/scriptmanager.cpp b/apps/openmw/mwscript/scriptmanager.cpp index 926dcb699..d9bbc62c1 100644 --- a/apps/openmw/mwscript/scriptmanager.cpp +++ b/apps/openmw/mwscript/scriptmanager.cpp @@ -19,6 +19,7 @@ #include "cellextensions.hpp" #include "miscextensions.hpp" #include "guiextensions.hpp" +#include "skyextensions.hpp" namespace MWScript { @@ -125,6 +126,7 @@ namespace MWScript Misc::installOpcodes (interpreter); Gui::installOpcodes (interpreter); Sound::installOpcodes (interpreter); + Sky::installOpcodes (interpreter); } } diff --git a/apps/openmw/mwscript/skyextensions.cpp b/apps/openmw/mwscript/skyextensions.cpp new file mode 100644 index 000000000..f53168240 --- /dev/null +++ b/apps/openmw/mwscript/skyextensions.cpp @@ -0,0 +1,107 @@ + +#include "skyextensions.hpp" + +#include + +#include +#include +#include + +#include "interpretercontext.hpp" + +namespace MWScript +{ + namespace Sky + { + class OpToggleSky : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getWorld().toggleSky(); + } + }; + + 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; + const int opcodeGetMasserPhase = 0x2000024; + const int opcodeGetSecundaPhase = 0x2000025; + + void registerExtensions (Compiler::Extensions& extensions) + { + extensions.registerInstruction ("togglesky", "", opcodeToggleSky); + extensions.registerInstruction ("ts", "", opcodeToggleSky); + extensions.registerInstruction ("turnmoonwhite", "", opcodeTurnMoonWhite); + extensions.registerInstruction ("turnmoonred", "", opcodeTurnMoonRed); + extensions.registerFunction ("getmasserphase", 'l', "", opcodeGetMasserPhase); + extensions.registerFunction ("getsecundaphase", 'l', "", opcodeGetSecundaPhase); + } + + void installOpcodes (Interpreter::Interpreter& interpreter) + { + interpreter.installSegment5 (opcodeToggleSky, new OpToggleSky); + interpreter.installSegment5 (opcodeTurnMoonWhite, new OpTurnMoonWhite); + interpreter.installSegment5 (opcodeTurnMoonRed, new OpTurnMoonRed); + interpreter.installSegment5 (opcodeGetMasserPhase, new OpGetMasserPhase); + interpreter.installSegment5 (opcodeGetSecundaPhase, new OpGetSecundaPhase); + } + } +} + diff --git a/apps/openmw/mwscript/skyextensions.hpp b/apps/openmw/mwscript/skyextensions.hpp new file mode 100644 index 000000000..b9bffb27e --- /dev/null +++ b/apps/openmw/mwscript/skyextensions.hpp @@ -0,0 +1,25 @@ +#ifndef GAME_SCRIPT_SKYEXTENSIONS_H +#define GAME_SCRIPT_SKYEXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace Interpreter +{ + class Interpreter; +} + +namespace MWScript +{ + /// \brief sky-related script functionality + namespace Sky + { + void registerExtensions (Compiler::Extensions& extensions); + + void installOpcodes (Interpreter::Interpreter& interpreter); + } +} + +#endif diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index d2d787e1c..f93b81890 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -144,7 +144,8 @@ namespace MWWorld World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, const std::string& master, const std::string& startCell, bool newGame) - : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0) + : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0), + mSky (false) { boost::filesystem::path masterPath (dataDir); masterPath /= master; @@ -180,11 +181,10 @@ namespace MWWorld iter!=mActiveCells.end(); ++iter) iter->second->show(); - // Optionally enable the sky - ///\todo FIXME - if (false) - mSkyManager = MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera()); - + mSkyManager = + MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera()); + + toggleSky(); } World::~World() @@ -297,6 +297,8 @@ namespace MWWorld mGlobalVariables->setFloat ("gamehour", hour); + mSkyManager->setHour (hour); + if (days>0) { setDay (days + mGlobalVariables->getInt ("year")); @@ -316,10 +318,44 @@ namespace MWWorld mGlobalVariables->setInt ("day", day); + mSkyManager->setDay (day); + if (year>0) { year += mGlobalVariables->getInt ("year"); mGlobalVariables->setInt ("year", year); } } + + void World::toggleSky() + { + if (mSky) + { + mSky = false; + mSkyManager->disable(); + } + else + { + mSky = true; + // TODO check for extorior or interior with sky. + mSkyManager->setHour (mGlobalVariables->getFloat ("gamehour")); + mSkyManager->setDay (mGlobalVariables->getInt ("day")); + mSkyManager->enable(); + } + } + + int World::getMasserPhase() const + { + return mSkyManager->getMasserPhase(); + } + + int World::getSecundaPhase() const + { + return mSkyManager->getSecundaPhase(); + } + + void World::setMoonColour (bool red) + { + mSkyManager->setMoonColour (red); + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 0929b3ffd..2873a69d1 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -51,6 +51,7 @@ namespace MWWorld std::map mInteriors; ScriptList mLocalScripts; MWWorld::Globals *mGlobalVariables; + bool mSky; // not implemented World (const World&); @@ -94,6 +95,14 @@ namespace MWWorld void setHour (double hour); void setDay (int day); + + void toggleSky(); + + int getMasserPhase() const; + + int getSecundaPhase() const; + + void setMoonColour (bool red); }; }