diff options
| author | Alexander Gavrilov | 2011-12-30 18:12:15 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2011-12-30 18:12:15 +0400 |
| commit | 53346328e8cc12dc2bb800534aefcb4eabb15502 (patch) | |
| tree | 0d4486e577dfda7cda01d26b1643a7cbee4bed1d /library/PluginManager.cpp | |
| parent | 298e2fe92d7b709be4528f2eb15380bdd92a54da (diff) | |
| download | dfhack-53346328e8cc12dc2bb800534aefcb4eabb15502.tar.gz dfhack-53346328e8cc12dc2bb800534aefcb4eabb15502.tar.bz2 dfhack-53346328e8cc12dc2bb800534aefcb4eabb15502.tar.xz | |
Notify plugins about game being loaded or unloaded.
As a test, make seadwatch deactivate on these events.
Diffstat (limited to 'library/PluginManager.cpp')
| -rw-r--r-- | library/PluginManager.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index d37c3fbf..997b8e59 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -135,6 +135,7 @@ Plugin::Plugin(Core * core, const std::string & filepath, const std::string & _f plugin_shutdown = 0; plugin_status = 0; plugin_onupdate = 0; + plugin_onstatechange = 0; state = PS_UNLOADED; access = new RefLock(); } @@ -192,6 +193,7 @@ bool Plugin::load() plugin_status = (command_result (*)(Core *, std::string &)) LookupPlugin(plug, "plugin_status"); plugin_onupdate = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_onupdate"); plugin_shutdown = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_shutdown"); + plugin_onstatechange = (command_result (*)(Core *, state_change_event)) LookupPlugin(plug, "plugin_onstatechange"); //name = _PlugName(); plugin_lib = plug; if(plugin_init(&c,commands) == CR_OK) @@ -299,6 +301,19 @@ command_result Plugin::on_update() return cr; } +command_result Plugin::on_state_change(state_change_event event) +{ + Core & c = Core::getInstance(); + command_result cr = CR_NOT_IMPLEMENTED; + access->lock_add(); + if(state == PS_LOADED && plugin_onstatechange) + { + cr = plugin_onstatechange(&c, event); + } + access->lock_sub(); + return cr; +} + Plugin::plugin_state Plugin::getState() const { return state; @@ -370,6 +385,15 @@ void PluginManager::OnUpdate( void ) all_plugins[i]->on_update(); } } + +void PluginManager::OnStateChange( state_change_event event ) +{ + for(int i = 0; i < all_plugins.size(); i++) + { + all_plugins[i]->on_state_change(event); + } +} + // FIXME: doesn't check name collisions! void PluginManager::registerCommands( Plugin * p ) { |
