added CellChanged script function

pull/7/head
Marc Zinnschlag 15 years ago
parent 32eafaa301
commit f0c492ae22

@ -39,13 +39,17 @@ source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER})
set(GAMESCRIPT set(GAMESCRIPT
apps/openmw/mwscript/scriptmanager.cpp apps/openmw/mwscript/scriptmanager.cpp
apps/openmw/mwscript/interpretercontext.cpp) apps/openmw/mwscript/interpretercontext.cpp
apps/openmw/mwscript/cellextensions.cpp
apps/openmw/mwscript/extensions.cpp)
set(GAMESCRIPT_HEADER set(GAMESCRIPT_HEADER
apps/openmw/mwscript/locals.hpp apps/openmw/mwscript/locals.hpp
apps/openmw/mwscript/scriptmanager.hpp apps/openmw/mwscript/scriptmanager.hpp
apps/openmw/mwscript/compilercontext.hpp apps/openmw/mwscript/compilercontext.hpp
apps/openmw/mwscript/compilercontextscript.hpp apps/openmw/mwscript/compilercontextscript.hpp
apps/openmw/mwscript/interpretercontext.hpp) apps/openmw/mwscript/interpretercontext.hpp
apps/openmw/mwscript/cellextensions.hpp
apps/openmw/mwscript/extensions.hpp)
source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER}) source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER})
set(APPS ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT}) set(APPS ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT})

@ -11,6 +11,7 @@
#include "mwscript/scriptmanager.hpp" #include "mwscript/scriptmanager.hpp"
#include "mwscript/compilercontextscript.hpp" #include "mwscript/compilercontextscript.hpp"
#include "mwscript/interpretercontext.hpp" #include "mwscript/interpretercontext.hpp"
#include "mwscript/extensions.hpp"
#include "world.hpp" #include "world.hpp"
@ -161,7 +162,10 @@ void OMW::Engine::go()
// Create the world // Create the world
mWorld = new World (mOgre, mDataDir, mMaster, mCellName); mWorld = new World (mOgre, mDataDir, mMaster, mCellName);
MWScript::registerExtensions (mExtensions);
mScriptContext = new MWScript::CompilerContextScript; mScriptContext = new MWScript::CompilerContextScript;
mScriptContext->setExtensions (&mExtensions);
mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts, mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts,
*mScriptContext); *mScriptContext);

@ -11,6 +11,7 @@
#include "components/misc/tsdeque.hpp" #include "components/misc/tsdeque.hpp"
#include "components/commandserver/server.hpp" #include "components/commandserver/server.hpp"
#include "components/commandserver/command.hpp" #include "components/commandserver/command.hpp"
#include <components/compiler/extensions.hpp>
#include "mwrender/mwscene.hpp" #include "mwrender/mwscene.hpp"
@ -46,6 +47,7 @@ namespace OMW
std::auto_ptr<OMW::CommandServer::Server> mspCommandServer; std::auto_ptr<OMW::CommandServer::Server> mspCommandServer;
MWScript::ScriptManager *mScriptManager; MWScript::ScriptManager *mScriptManager;
Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext; Compiler::Context *mScriptContext;
// not implemented // not implemented

@ -0,0 +1,42 @@
#include "cellextensions.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 Cell
{
class OpCellChanged : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context
= static_cast<InterpreterContext&> (runtime.getContext());
runtime.push (context.cellChanged() ? 1 : 0);
}
};
const int opcodeCellChanged = 0x2000000;
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerFunction ("cellchanged", 'l', "", opcodeCellChanged);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeCellChanged, new OpCellChanged);
}
}
}

@ -0,0 +1,27 @@
#ifndef GAME_SCRIPT_CELLEXTENSIONS_H
#define GAME_SCRIPT_CELLEXTENSIONS_H
namespace Compiler
{
class Extensions;
}
namespace Interpreter
{
class Interpreter;
}
namespace MWScript
{
/// \brief cell-related script functionality
namespace Cell
{
void registerExtensions (Compiler::Extensions& extensions);
void installOpcodes (Interpreter::Interpreter& interpreter);
}
}
#endif

@ -0,0 +1,26 @@
OpenMW Extensions:
Segment 0:
(not implemented yet)
opcodes 0x20-0x3f unused
Segment 1:
(not implemented yet)
opcodes 0x20-0x3f unused
Segment 2:
(not implemented yet)
opcodes 0x200-0x3ff unused
Segment 3:
(not implemented yet)
opcodes 0x200-0x3ff unused
Segment 4:
(not implemented yet)
opcodes 0x200-0x3ff unused
Segment 5:
op 2000000: push 1 if cell has changed since last frame, 0 if not
opcodes 0x2000001-0x3ffffff unused

@ -0,0 +1,13 @@
#include "extensions.hpp"
#include "cellextensions.hpp"
namespace MWScript
{
void registerExtensions (Compiler::Extensions& extensions)
{
Cell::registerExtensions (extensions);
}
}

@ -0,0 +1,14 @@
#ifndef GAME_SCRIPT_EXTENSIONS_H
#define GAME_SCRIPT_EXTENSIONS_H
namespace Compiler
{
class Extensions;
}
namespace MWScript
{
void registerExtensions (Compiler::Extensions& extensions);
}
#endif

@ -5,6 +5,7 @@
#include <iostream> #include <iostream>
#include "locals.hpp" #include "locals.hpp"
#include "../world.hpp"
namespace MWScript namespace MWScript
{ {
@ -68,5 +69,10 @@ namespace MWScript
if (!buttons.empty()) if (!buttons.empty())
std::cerr << "error: message box buttons not supported" << std::endl; std::cerr << "error: message box buttons not supported" << std::endl;
} }
bool InterpreterContext::cellChanged()
{
return mWorld.hasCellChanged();
}
} }

@ -36,6 +36,8 @@ namespace MWScript
virtual void messageBox (const std::string& message, virtual void messageBox (const std::string& message,
const std::vector<std::string>& buttons); const std::vector<std::string>& buttons);
virtual bool cellChanged();
}; };
} }

@ -10,6 +10,7 @@
#include <components/esm_store/store.hpp> #include <components/esm_store/store.hpp>
#include <components/compiler/scanner.hpp> #include <components/compiler/scanner.hpp>
#include <components/compiler/context.hpp>
#include <components/interpreter/installopcodes.hpp> #include <components/interpreter/installopcodes.hpp>
#include <components/interpreter/interpreter.hpp> #include <components/interpreter/interpreter.hpp>
@ -39,7 +40,7 @@ namespace MWScript
{ {
std::istringstream input (script->scriptText); std::istringstream input (script->scriptText);
Compiler::Scanner scanner (mErrorHandler, input); Compiler::Scanner scanner (mErrorHandler, input, mCompilerContext.getExtensions());
scanner.scan (mParser); scanner.scan (mParser);
@ -99,7 +100,7 @@ namespace MWScript
try try
{ {
Interpreter::Interpreter interpreter (interpreterContext); Interpreter::Interpreter interpreter (interpreterContext);
Interpreter::installOpcodes (interpreter); installOpcodes (interpreter);
interpreter.run (&iter->second[0], iter->second.size()); interpreter.run (&iter->second[0], iter->second.size());
} }
catch (...) catch (...)
@ -108,5 +109,10 @@ namespace MWScript
iter->second.clear(); // don't execute again. iter->second.clear(); // don't execute again.
} }
} }
void ScriptManager::installOpcodes (Interpreter::Interpreter& interpreter)
{
Interpreter::installOpcodes (interpreter);
}
} }

@ -23,6 +23,7 @@ namespace Compiler
namespace Interpreter namespace Interpreter
{ {
class Context; class Context;
class Interpreter;
} }
namespace MWScript namespace MWScript
@ -45,6 +46,8 @@ namespace MWScript
Compiler::Context& compilerContext); Compiler::Context& compilerContext);
void run (const std::string& name, Interpreter::Context& interpreterContext); void run (const std::string& name, Interpreter::Context& interpreterContext);
static void installOpcodes (Interpreter::Interpreter& interpreter);
}; };
}; };

@ -115,4 +115,10 @@ namespace OMW
{ {
return mLocalScripts; return mLocalScripts;
} }
bool World::hasCellChanged() const
{
// Cell change not implemented yet.
return false;
}
} }

@ -68,6 +68,9 @@ namespace OMW
const ScriptList& getLocalScripts() const; const ScriptList& getLocalScripts() const;
///< Names and local variable state of all local scripts in active cells. ///< Names and local variable state of all local scripts in active cells.
bool hasCellChanged() const;
///< Has the player moved to a different cell, since the last frame?
}; };
} }

Loading…
Cancel
Save