mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 07:09:40 +00:00
added sky-related script functions and instructions
This commit is contained in:
parent
d27c548710
commit
f3b70e05a9
11 changed files with 231 additions and 9 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
107
apps/openmw/mwscript/skyextensions.cpp
Normal file
107
apps/openmw/mwscript/skyextensions.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
|
||||
#include "skyextensions.hpp"
|
||||
|
||||
#include <components/compiler/extensions.hpp>
|
||||
|
||||
#include <components/interpreter/interpreter.hpp>
|
||||
#include <components/interpreter/runtime.hpp>
|
||||
#include <components/interpreter/opcodes.hpp>
|
||||
|
||||
#include "interpretercontext.hpp"
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
namespace Sky
|
||||
{
|
||||
class OpToggleSky : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
InterpreterContext& context =
|
||||
static_cast<InterpreterContext&> (runtime.getContext());
|
||||
|
||||
context.getWorld().toggleSky();
|
||||
}
|
||||
};
|
||||
|
||||
class OpTurnMoonWhite : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
InterpreterContext& context =
|
||||
static_cast<InterpreterContext&> (runtime.getContext());
|
||||
|
||||
context.getWorld().setMoonColour (false);
|
||||
}
|
||||
};
|
||||
|
||||
class OpTurnMoonRed : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
InterpreterContext& context =
|
||||
static_cast<InterpreterContext&> (runtime.getContext());
|
||||
|
||||
context.getWorld().setMoonColour (true);
|
||||
}
|
||||
};
|
||||
|
||||
class OpGetMasserPhase : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
InterpreterContext& context =
|
||||
static_cast<InterpreterContext&> (runtime.getContext());
|
||||
|
||||
runtime.push (context.getWorld().getMasserPhase());
|
||||
}
|
||||
};
|
||||
|
||||
class OpGetSecundaPhase : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
InterpreterContext& context =
|
||||
static_cast<InterpreterContext&> (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
apps/openmw/mwscript/skyextensions.hpp
Normal file
25
apps/openmw/mwscript/skyextensions.hpp
Normal file
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace MWWorld
|
|||
std::map<std::string, Ptr::CellStore> 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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue