add dedicated stopAll()

should not change abi
This commit is contained in:
Green Sky 2025-04-11 20:46:50 +02:00
parent e25ee67e42
commit d03d2dae67
No known key found for this signature in database
GPG Key ID: DBE05085D874AB4A
4 changed files with 27 additions and 9 deletions

View File

@ -108,6 +108,8 @@ Plugin::Plugin(Plugin&& other) {
_fn_render = other._fn_render;
other._fn_render = nullptr;
_running = other._running;
}
// unloads the plugin
@ -122,14 +124,22 @@ Plugin::~Plugin(void) {
}
// runs the start function
uint32_t Plugin::start(SolanaAPI* solana_api) const {
uint32_t Plugin::start(SolanaAPI* solana_api) {
assert(valid_plugin);
if (_running) {
return 1;
}
_running = true;
return reinterpret_cast<decltype(&solana_plugin_start)>(_fn_start)(solana_api);
}
// stop function
void Plugin::stop(void) const {
void Plugin::stop(void) {
assert(valid_plugin);
if (!_running) {
return;
}
_running = false;
reinterpret_cast<decltype(&solana_plugin_stop)>(_fn_stop)();
}

View File

@ -22,6 +22,8 @@ struct Plugin {
void* _fn_tick = nullptr;
void* _fn_render = nullptr;
bool _running = false;
void* loadSymbol(const char* name);
// loads lib and gets name (and version)
@ -32,12 +34,11 @@ struct Plugin {
// unloads the plugin
~Plugin(void);
// runs the start function
uint32_t start(SolanaAPI* solana_api) const;
uint32_t start(SolanaAPI* solana_api);
// stop function
void stop(void) const;
void stop(void);
// update functions
float tick(float delta) const;

View File

@ -26,10 +26,7 @@ void g_provideInstance__internal(const char* id, const char* version, const char
} // extern C
PluginManager::~PluginManager(void) {
// destruct in reverse!
for (auto it = _plugins.rbegin(); it != _plugins.rend(); it++) {
it->stop();
}
stopAll();
}
bool PluginManager::add(const std::string& plug_path) {
@ -48,6 +45,13 @@ bool PluginManager::add(const std::string& plug_path) {
return true;
}
void PluginManager::stopAll(void) {
// destruct in reverse!
for (auto it = _plugins.rbegin(); it != _plugins.rend(); it++) {
it->stop();
}
}
float PluginManager::tick(float delta) {
float min_interval {std::numeric_limits<float>::max()};

View File

@ -47,6 +47,9 @@ struct PluginManager {
bool add(const std::string& plug_path);
// stops, but does not remove/unload, all plugins
void stopAll(void);
// returns the minimum time until next call is wanted in seconds
float tick(float delta);
float render(float delta);