move in plugin
This commit is contained in:
parent
70620a901b
commit
7bbaa9b929
@ -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()
|
||||
|
||||
|
21
plugins/CMakeLists.txt
Normal file
21
plugins/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
||||
|
||||
########################################
|
||||
|
81
plugins/plugin_ngcft1.cpp
Normal file
81
plugins/plugin_ngcft1.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <solanaceae/plugin/solana_plugin_v1.h>
|
||||
|
||||
#include <solanaceae/ngc_ext/ngcext.hpp>
|
||||
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
||||
#include <solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp>
|
||||
|
||||
#include <entt/entt.hpp>
|
||||
#include <entt/fwd.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
static std::unique_ptr<NGCEXTEventProvider> g_ngcextep = nullptr;
|
||||
// TODO: make sep plug
|
||||
static std::unique_ptr<NGCFT1> g_ngcft1 = nullptr;
|
||||
static std::unique_ptr<SHA1_NGCFT1> 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<NGCEXTEventProvider>(*tox_i, *tox_event_provider_i);
|
||||
g_ngcft1 = std::make_unique<NGCFT1>(*tox_i, *tox_event_provider_i, *g_ngcextep.get());
|
||||
g_sha1_ngcft1 = std::make_unique<SHA1_NGCFT1>(*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<float>(ft_interval, sha_interval);
|
||||
}
|
||||
|
||||
} // extern C
|
||||
|
Loading…
Reference in New Issue
Block a user