forked from teamnwah/openmw-tes3coop
added script manager (doesn't do anything yet); local scriptes for active cells are passed on to the script manager
This commit is contained in:
parent
a06b84ac86
commit
2064c43d89
8 changed files with 179 additions and 7 deletions
|
@ -37,9 +37,11 @@ set(GAMEINPUT_HEADER
|
|||
apps/openmw/mwinput/inputmanager.hpp)
|
||||
source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER})
|
||||
|
||||
# set(GAMESCRIPT)
|
||||
set(GAMESCRIPT
|
||||
apps/openmw/mwscript/scriptmanager.cpp)
|
||||
set(GAMESCRIPT_HEADER
|
||||
apps/openmw/mwscript/locals.hpp)
|
||||
apps/openmw/mwscript/locals.hpp
|
||||
apps/openmw/mwscript/scriptmanager.hpp)
|
||||
source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER})
|
||||
|
||||
set(APPS ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT})
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "components/bsa/bsa_archive.hpp"
|
||||
|
||||
#include "mwinput/inputmanager.hpp"
|
||||
#include "mwscript/scriptmanager.hpp"
|
||||
|
||||
#include "world.hpp"
|
||||
|
||||
|
@ -24,8 +25,17 @@ protected:
|
|||
OMW::Engine* mpEngine;
|
||||
};
|
||||
|
||||
void OMW::Engine::executeLocalScripts()
|
||||
{
|
||||
for (World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin());
|
||||
iter!=mWorld->getLocalScripts().end(); ++iter)
|
||||
{
|
||||
mScriptManager->run (iter->first);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
OMW::Engine::Engine() : mWorld(NULL), mDebug (false)
|
||||
OMW::Engine::Engine() : mWorld(NULL), mDebug (false), mScriptManager (0)
|
||||
{
|
||||
mspCommandServer.reset(
|
||||
new OMW::CommandServer::Server(&mCommandQueue, kCommandServerPort));
|
||||
|
@ -35,6 +45,7 @@ OMW::Engine::~Engine()
|
|||
{
|
||||
// mspCommandServer->stop();
|
||||
delete mWorld;
|
||||
delete mScriptManager;
|
||||
}
|
||||
|
||||
// Load all BSA files in data directory.
|
||||
|
@ -97,6 +108,11 @@ void OMW::Engine::enableDebugMode()
|
|||
{
|
||||
mDebug = true;
|
||||
}
|
||||
|
||||
void OMW::Engine::enableVerboseScripts()
|
||||
{
|
||||
mVerboseScripts = true;
|
||||
}
|
||||
|
||||
void OMW::Engine::processCommands()
|
||||
{
|
||||
|
@ -143,6 +159,10 @@ void OMW::Engine::go()
|
|||
// Create the world
|
||||
mWorld = new World (mOgre, mDataDir, mMaster, mCellName);
|
||||
|
||||
mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts);
|
||||
|
||||
executeLocalScripts(); // TODO move into a framelistener
|
||||
|
||||
std::cout << "Setting up input system\n";
|
||||
|
||||
// Sets up the input system
|
||||
|
|
|
@ -6,11 +6,17 @@
|
|||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "components/engine/ogre/renderer.hpp"
|
||||
#include "apps/openmw/mwrender/mwscene.hpp"
|
||||
#include "components/misc/tsdeque.hpp"
|
||||
#include "components/commandserver/server.hpp"
|
||||
#include "components/commandserver/command.hpp"
|
||||
|
||||
#include "mwrender/mwscene.hpp"
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
class ScriptManager;
|
||||
}
|
||||
|
||||
namespace OMW
|
||||
{
|
||||
class World;
|
||||
|
@ -27,10 +33,13 @@ namespace OMW
|
|||
std::string mMaster;
|
||||
World *mWorld;
|
||||
bool mDebug;
|
||||
bool mVerboseScripts;
|
||||
|
||||
TsDeque<OMW::Command> mCommandQueue;
|
||||
std::auto_ptr<OMW::CommandServer::Server> mspCommandServer;
|
||||
|
||||
MWScript::ScriptManager *mScriptManager;
|
||||
|
||||
// not implemented
|
||||
Engine (const Engine&);
|
||||
Engine& operator= (const Engine&);
|
||||
|
@ -42,6 +51,8 @@ namespace OMW
|
|||
/// Load all BSA files in data directory.
|
||||
void loadBSA();
|
||||
|
||||
void executeLocalScripts();
|
||||
|
||||
public:
|
||||
|
||||
Engine();
|
||||
|
@ -63,6 +74,9 @@ namespace OMW
|
|||
/// - non-exclusive input
|
||||
void enableDebugMode();
|
||||
|
||||
/// Enable verbose script output
|
||||
void enableVerboseScripts();
|
||||
|
||||
/// Process pending commands
|
||||
void processCommands();
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
|
|||
("master", bpo::value<std::string>()->default_value ("Morrowind"),
|
||||
"master file")
|
||||
( "debug", "debug mode" )
|
||||
( "script-verbose", "verbose script output" )
|
||||
;
|
||||
|
||||
bpo::variables_map variables;
|
||||
|
@ -54,6 +55,9 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
|
|||
|
||||
if (variables.count ("debug"))
|
||||
engine.enableDebugMode();
|
||||
|
||||
if (variables.count ("script-verbose"))
|
||||
engine.enableVerboseScripts();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
19
apps/openmw/mwscript/scriptmanager.cpp
Normal file
19
apps/openmw/mwscript/scriptmanager.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
#include "scriptmanager.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
ScriptManager::ScriptManager (const ESMS::ESMStore& store, bool verbose)
|
||||
: mStore (store), mVerbose (verbose)
|
||||
{}
|
||||
|
||||
void ScriptManager::run (const std::string& name/*, Compiler::Context& compilerContext,
|
||||
Interpreter::Context& interpreterContext, Locals& locals*/)
|
||||
{
|
||||
std::cout << "script request: " << name << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
47
apps/openmw/mwscript/scriptmanager.hpp
Normal file
47
apps/openmw/mwscript/scriptmanager.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef GAME_SCRIPT_SCRIPTMANAGER_H
|
||||
#define GAME_SCRIPT_SCRIPTMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <components/interpreter/types.hpp>
|
||||
|
||||
namespace ESMS
|
||||
{
|
||||
struct ESMStore;
|
||||
}
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
class Context;
|
||||
}
|
||||
|
||||
namespace Interpreter
|
||||
{
|
||||
class Context;
|
||||
}
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
struct Locals;
|
||||
|
||||
class ScriptManager
|
||||
{
|
||||
const ESMS::ESMStore& mStore;
|
||||
bool mVerbose;
|
||||
|
||||
std::map<std::string, std::vector<Interpreter::Type_Code> > mScripts;
|
||||
|
||||
public:
|
||||
|
||||
ScriptManager (const ESMS::ESMStore& store, bool verbose);
|
||||
|
||||
void run (const std::string& name/*, Compiler::Context& compilerContext,
|
||||
Interpreter::Context& interpreterContext, Locals& locals*/);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -7,8 +7,50 @@
|
|||
#include "apps/openmw/mwrender/sky.hpp"
|
||||
#include "apps/openmw/mwrender/interior.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
void listCellScripts (ESMS::CellRefList<T, OMW::RefData>& cellRefList,
|
||||
OMW::World::ScriptList& scriptList)
|
||||
{
|
||||
for (typename ESMS::CellRefList<T, OMW::RefData>::List::iterator iter (
|
||||
cellRefList.list.begin());
|
||||
iter!=cellRefList.list.end(); ++iter)
|
||||
{
|
||||
if (!iter->base->script.empty())
|
||||
scriptList.push_back (
|
||||
std::make_pair (iter->base->script, static_cast<MWScript::Locals *> (0)));
|
||||
|
||||
// TODO local variables
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace OMW
|
||||
{
|
||||
void World::insertInteriorScripts (ESMS::CellStore<OMW::RefData>& cell)
|
||||
{
|
||||
listCellScripts (cell.activators, mLocalScripts);
|
||||
listCellScripts (cell.potions, mLocalScripts);
|
||||
listCellScripts (cell.appas, mLocalScripts);
|
||||
listCellScripts (cell.armors, mLocalScripts);
|
||||
listCellScripts (cell.books, mLocalScripts);
|
||||
listCellScripts (cell.clothes, mLocalScripts);
|
||||
listCellScripts (cell.containers, mLocalScripts);
|
||||
listCellScripts (cell.creatures, mLocalScripts);
|
||||
listCellScripts (cell.doors, mLocalScripts);
|
||||
listCellScripts (cell.ingreds, mLocalScripts);
|
||||
listCellScripts (cell.lights, mLocalScripts);
|
||||
listCellScripts (cell.lockpicks, mLocalScripts);
|
||||
listCellScripts (cell.miscItems, mLocalScripts);
|
||||
listCellScripts (cell.npcs, mLocalScripts);
|
||||
listCellScripts (cell.probes, mLocalScripts);
|
||||
listCellScripts (cell.repairs, mLocalScripts);
|
||||
listCellScripts (cell.weapons, mLocalScripts);
|
||||
}
|
||||
|
||||
World::World (Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
|
||||
const std::string& master, const std::string& startCell)
|
||||
: mSkyManager (0), mScene (renderer), mPlayerPos (mScene.getCamera())
|
||||
|
@ -24,6 +66,8 @@ namespace OMW
|
|||
|
||||
mInteriors[startCell].loadInt (startCell, mStore, mEsm);
|
||||
|
||||
insertInteriorScripts (mInteriors[startCell]);
|
||||
|
||||
std::cout << "\nSetting up cell rendering\n";
|
||||
|
||||
// This connects the cell data with the rendering scene.
|
||||
|
@ -58,4 +102,14 @@ namespace OMW
|
|||
{
|
||||
return mPlayerPos;
|
||||
}
|
||||
|
||||
ESMS::ESMStore& World::getStore()
|
||||
{
|
||||
return mStore;
|
||||
}
|
||||
|
||||
const World::ScriptList& World::getLocalScripts() const
|
||||
{
|
||||
return mLocalScripts;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "apps/openmw/mwrender/playerpos.hpp"
|
||||
#include "apps/openmw/mwrender/mwscene.hpp"
|
||||
|
||||
#include "apps/openmw/refdata.hpp"
|
||||
#include "refdata.hpp"
|
||||
|
||||
namespace Render
|
||||
{
|
||||
|
@ -30,6 +30,12 @@ namespace OMW
|
|||
|
||||
class World
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<std::pair<std::string, MWScript::Locals *> > ScriptList;
|
||||
|
||||
private:
|
||||
|
||||
typedef ESMS::CellStore<RefData> CellStore;
|
||||
typedef std::map<CellStore *, MWRender::CellRender *> CellRenderCollection;
|
||||
|
||||
|
@ -41,11 +47,14 @@ namespace OMW
|
|||
ESM::ESMReader mEsm;
|
||||
ESMS::ESMStore mStore;
|
||||
std::map<std::string, CellStore> mInteriors;
|
||||
ScriptList mLocalScripts;
|
||||
|
||||
// not implemented
|
||||
World (const World&);
|
||||
World& operator= (const World&);
|
||||
|
||||
void insertInteriorScripts (ESMS::CellStore<OMW::RefData>& cell);
|
||||
|
||||
public:
|
||||
|
||||
World (Render::OgreRenderer& renderer, const boost::filesystem::path& master,
|
||||
|
@ -54,8 +63,11 @@ namespace OMW
|
|||
~World();
|
||||
|
||||
MWRender::PlayerPos& getPlayerPos();
|
||||
|
||||
|
||||
|
||||
ESMS::ESMStore& getStore();
|
||||
|
||||
const ScriptList& getLocalScripts() const;
|
||||
///< Names and local variable state of all local scripts in active cells.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue