diff --git a/solanaceae/plugin/plugin.cpp b/solanaceae/plugin/plugin.cpp index 19b726a..8ae4b00 100644 --- a/solanaceae/plugin/plugin.cpp +++ b/solanaceae/plugin/plugin.cpp @@ -21,6 +21,7 @@ #define LINUX #endif +#include #include #include @@ -60,6 +61,7 @@ Plugin::Plugin(const char* path) { _fn_start = loadSymbol("solana_plugin_start"); _fn_stop = loadSymbol("solana_plugin_stop"); _fn_tick = loadSymbol("solana_plugin_tick"); + _fn_render = loadSymbol("solana_plugin_render"); // optional if (!_fn_name || !_fn_version || !_fn_start || !_fn_stop || !_fn_tick) { std::cerr << "PLG '" << path << "' misses functions\n"; @@ -127,8 +129,18 @@ void Plugin::stop(void) const { } // tick function -void Plugin::tick(float delta) const { +float Plugin::tick(float delta) const { assert(valid_plugin); - reinterpret_cast(_fn_tick)(delta); + return reinterpret_cast(_fn_tick)(delta); +} + +// render function +float Plugin::render(float delta) const { + assert(valid_plugin); + if (_fn_render != nullptr) { + return reinterpret_cast(_fn_tick)(delta); + } else { + return std::numeric_limits::max(); + } } diff --git a/solanaceae/plugin/plugin.hpp b/solanaceae/plugin/plugin.hpp index 5b94c14..0d5b1ab 100644 --- a/solanaceae/plugin/plugin.hpp +++ b/solanaceae/plugin/plugin.hpp @@ -19,6 +19,7 @@ struct Plugin { void* _fn_start = nullptr; void* _fn_stop = nullptr; void* _fn_tick = nullptr; + void* _fn_render = nullptr; void* loadSymbol(const char* name); @@ -37,8 +38,9 @@ struct Plugin { // stop function void stop(void) const; - // tick function - void tick(float delta) const; + // update functions + float tick(float delta) const; + float render(float delta) const; operator bool(void) const { return valid_plugin; diff --git a/solanaceae/plugin/plugin_manager.cpp b/solanaceae/plugin/plugin_manager.cpp index 772df0b..d9fc1ab 100644 --- a/solanaceae/plugin/plugin_manager.cpp +++ b/solanaceae/plugin/plugin_manager.cpp @@ -1,5 +1,7 @@ #include "./plugin_manager.hpp" +#include + #include // def @@ -45,9 +47,29 @@ bool PluginManager::add(const std::string& plug_path) { return true; } -void PluginManager::tick(float delta) { +float PluginManager::tick(float delta) { + float min_interval {std::numeric_limits::max()}; + for (const auto& p : _plugins) { - p.tick(delta); + const float plug_interval = p.tick(delta); + if (plug_interval < min_interval) { + min_interval = plug_interval; + } } + + return min_interval; +} + +float PluginManager::render(float delta) { + float min_interval {std::numeric_limits::max()}; + + for (const auto& p : _plugins) { + const float plug_interval = p.render(delta); + if (plug_interval < min_interval) { + min_interval = plug_interval; + } + } + + return min_interval; } diff --git a/solanaceae/plugin/plugin_manager.hpp b/solanaceae/plugin/plugin_manager.hpp index 539f13e..90afd20 100644 --- a/solanaceae/plugin/plugin_manager.hpp +++ b/solanaceae/plugin/plugin_manager.hpp @@ -39,6 +39,8 @@ struct PluginManager { bool add(const std::string& plug_path); - void tick(float delta); + // returns the minimum time until next call is wanted in seconds + float tick(float delta); + float render(float delta); }; diff --git a/solanaceae/plugin/solana_plugin_v1.h b/solanaceae/plugin/solana_plugin_v1.h index 34f3ad0..c0f687e 100644 --- a/solanaceae/plugin/solana_plugin_v1.h +++ b/solanaceae/plugin/solana_plugin_v1.h @@ -3,7 +3,7 @@ #include -#define SOLANA_PLUGIN_VERSION 6 +#define SOLANA_PLUGIN_VERSION 7 #if defined(_MSC_VER) || defined(__MINGW32__) #define SOLANA_PLUGIN_EXPORT __declspec(dllexport) @@ -15,6 +15,7 @@ #if defined(SOLANA_PLUGIN_HOST) #define SOLANA_PLUGIN_DECL + // TODO: this looks like decl should be used, but it isnt #else #define SOLANA_PLUGIN_DECL SOLANA_PLUGIN_EXPORT #endif @@ -34,7 +35,9 @@ struct SolanaAPI { // ---------- info ---------- +// TODO: change to exported struct, so we dont have to execute this code SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void); +// TODO: add author and other attributes // get the SOLANA_PLUGIN_VERSION the plugin was compiled with SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void); @@ -46,9 +49,14 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api); SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void); -// called periodically -SOLANA_PLUGIN_EXPORT void solana_plugin_tick(float delta); +// ---------- called periodically ---------- +// rendering needs to be called in a different interval AND needs to be garantied from mainthread +// the functions return the minimum time in seconds until the update should be called next +// for compute tasks +SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta); +// on frame rendering +SOLANA_PLUGIN_EXPORT float solana_plugin_render(float delta); #ifdef __cplusplus }