Convert Scripts from singleton to injectable dependency
This commit is contained in:
parent
df1c0adccd
commit
b12ccfd9aa
5 changed files with 6 additions and 10 deletions
|
@ -262,7 +262,7 @@ void Game::loadModule(const string &name, string entry) {
|
|||
Walkmeshes::instance().invalidateCache();
|
||||
Textures::instance().invalidateCache();
|
||||
_audioFiles.invalidate();
|
||||
Scripts::instance().invalidate();
|
||||
_scripts.invalidate();
|
||||
_soundSets.invalidate();
|
||||
Lips::instance().invalidate();
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "../graphics/window.h"
|
||||
#include "../scene/pipeline/world.h"
|
||||
#include "../scene/scenegraph.h"
|
||||
#include "../script/scripts.h"
|
||||
#include "../video/video.h"
|
||||
|
||||
#include "console.h"
|
||||
|
@ -146,6 +147,7 @@ public:
|
|||
Routines &routines() { return _routines; }
|
||||
scene::SceneGraph &sceneGraph() { return _sceneGraph; }
|
||||
scene::WorldRenderPipeline &worldPipeline() { return _worldPipeline; }
|
||||
script::Scripts &scripts() { return _scripts; }
|
||||
ScriptRunner &scriptRunner() { return _scriptRunner; }
|
||||
SoundSets &soundSets() { return _soundSets; }
|
||||
Spells &spells() { return _spells; }
|
||||
|
@ -264,6 +266,7 @@ private:
|
|||
Routines _routines;
|
||||
scene::SceneGraph _sceneGraph;
|
||||
scene::WorldRenderPipeline _worldPipeline;
|
||||
script::Scripts _scripts;
|
||||
ScriptRunner _scriptRunner;
|
||||
SoundSets _soundSets;
|
||||
Spells _spells;
|
||||
|
|
|
@ -48,7 +48,7 @@ int ScriptRunner::run(const string &resRef, uint32_t callerId, uint32_t triggerr
|
|||
throw invalid_argument("Invalid triggerrerId");
|
||||
}
|
||||
|
||||
auto program = Scripts::instance().get(resRef);
|
||||
auto program = _game->scripts().get(resRef);
|
||||
if (!program) return -1;
|
||||
|
||||
auto ctx = make_unique<ExecutionContext>();
|
||||
|
|
|
@ -31,11 +31,6 @@ namespace reone {
|
|||
|
||||
namespace script {
|
||||
|
||||
Scripts &Scripts::instance() {
|
||||
static Scripts instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
Scripts::Scripts() : MemoryCache(bind(&Scripts::doGet, this, _1)) {
|
||||
}
|
||||
|
||||
|
|
|
@ -30,11 +30,9 @@ namespace script {
|
|||
|
||||
class Scripts : public MemoryCache<std::string, ScriptProgram> {
|
||||
public:
|
||||
static Scripts &instance();
|
||||
|
||||
private:
|
||||
Scripts();
|
||||
|
||||
private:
|
||||
std::shared_ptr<ScriptProgram> doGet(std::string resRef);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue