diff --git a/CMakeLists.txt b/CMakeLists.txt index db0772c..d77dd15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,21 @@ -cmake_minimum_required(VERSION 3.9 FATAL_ERROR) +cmake_minimum_required(VERSION 3.24 FATAL_ERROR) add_subdirectory(./external) project(solanaceae) +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(SOLANACEAE_NGCFT1_STANDALONE ON) +else() + set(SOLANACEAE_NGCFT1_STANDALONE OFF) +endif() +message("II SOLANACEAE_NGCFT1_STANDALONE " ${SOLANACEAE_NGCFT1_STANDALONE}) + +option(SOLANACEAE_NGCFT1_BUILD_PLUGINS "Build the solanaceae_ngcft1 plugins" ${SOLANACEAE_NGCFT1_BUILD_PLUGINS}) + +# TODO: move this stuff to src +######################################## + add_library(solanaceae_ngcext ./solanaceae/ngc_ext/ngcext.hpp ./solanaceae/ngc_ext/ngcext.cpp @@ -159,3 +171,9 @@ if (SOLANACEAE_NGCHS2_BUILD_TESTING) endif() +######################################## + +if (SOLANACEAE_NGCFT1_BUILD_PLUGINS) + add_subdirectory(./plugins) +endif() + diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 0000000..45914b2 --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR) + +######################################## + +add_library(plugin_ngcft1 MODULE + ./plugin_ngcft1.cpp +) +target_compile_features(plugin_ngcft1 PUBLIC cxx_std_17) +set_target_properties(plugin_ngcft1 PROPERTIES + C_VISIBILITY_PRESET hidden +) +target_compile_definitions(plugin_ngcft1 PUBLIC ENTT_API_IMPORT) +target_link_libraries(plugin_ngcft1 PUBLIC + solanaceae_plugin + solanaceae_ngcext + solanaceae_ngcft1 + solanaceae_sha1_ngcft1 +) + +######################################## + diff --git a/plugins/plugin_ngcft1.cpp b/plugins/plugin_ngcft1.cpp new file mode 100644 index 0000000..4d1446c --- /dev/null +++ b/plugins/plugin_ngcft1.cpp @@ -0,0 +1,81 @@ +#include + +#include +#include +#include + +#include +#include + +#include +#include + +static std::unique_ptr g_ngcextep = nullptr; +// TODO: make sep plug +static std::unique_ptr g_ngcft1 = nullptr; +static std::unique_ptr g_sha1_ngcft1 = nullptr; + +constexpr const char* plugin_name = "NGCEXT"; + +extern "C" { + +SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) { + return plugin_name; +} + +SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { + return SOLANA_PLUGIN_VERSION; +} + +SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) { + std::cout << "PLUGIN " << plugin_name << " START()\n"; + + if (solana_api == nullptr) { + return 1; + } + + try { + auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2); + auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI); + auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI); + auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1"); + auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI); + auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2); + + // static store, could be anywhere tho + // construct with fetched dependencies + g_ngcextep = std::make_unique(*tox_i, *tox_event_provider_i); + g_ngcft1 = std::make_unique(*tox_i, *tox_event_provider_i, *g_ngcextep.get()); + g_sha1_ngcft1 = std::make_unique(*os, *cr, *rmm, *g_ngcft1.get(), *tcm, *tox_event_provider_i, *g_ngcextep.get()); + + // register types + PLUG_PROVIDE_INSTANCE(NGCEXTEventProviderI, plugin_name, g_ngcextep.get()); + + PLUG_PROVIDE_INSTANCE(NGCFT1EventProviderI, plugin_name, g_ngcft1.get()); + PLUG_PROVIDE_INSTANCE(NGCFT1, plugin_name, g_ngcft1.get()); + + PLUG_PROVIDE_INSTANCE(SHA1_NGCFT1, plugin_name, g_sha1_ngcft1.get()); + } catch (const ResolveException& e) { + std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n"; + return 2; + } + + return 0; +} + +SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { + std::cout << "PLUGIN " << plugin_name << " STOP()\n"; + + g_sha1_ngcft1.reset(); + g_ngcft1.reset(); + g_ngcextep.reset(); +} + +SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) { + const float ft_interval = g_ngcft1->iterate(delta); + const float sha_interval = g_sha1_ngcft1->iterate(delta); + return std::min(ft_interval, sha_interval); +} + +} // extern C +