explose base and imgui as plugin

This commit is contained in:
2023-11-02 00:14:34 +01:00
parent 0078850db4
commit 95a037ea35
8 changed files with 317 additions and 1 deletions

24
plugins/CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
add_library(plugin_crdtnotes SHARED
./plugin_crdtnotes.cpp
)
target_compile_features(plugin_crdtnotes PUBLIC cxx_std_17)
target_link_libraries(plugin_crdtnotes PUBLIC
solanaceae_crdtnotes
solanaceae_plugin
)
########################################
add_library(plugin_crdtnotes_imgui SHARED
./plugin_crdtnotes_imgui.cpp
)
target_compile_features(plugin_crdtnotes_imgui PUBLIC cxx_std_17)
target_link_libraries(plugin_crdtnotes_imgui PUBLIC
solanaceae_crdtnotes_imgui
solanaceae_plugin
)
########################################

View File

@ -0,0 +1,65 @@
#include <solanaceae/plugin/solana_plugin_v1.h>
#include <solanaceae/crdtnotes/crdtnotes.hpp>
//#include <solanaceae/util/config_model.hpp>
#include <memory>
#include <iostream>
#define RESOLVE_INSTANCE(x) static_cast<x*>(solana_api->resolveInstance(#x))
#define PROVIDE_INSTANCE(x, p, v) solana_api->provideInstance(#x, p, static_cast<x*>(v))
static std::unique_ptr<CRDTNotes> g_crdtn = nullptr;
extern "C" {
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) {
return "CRDTNotes";
}
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 CRDTN START()\n";
if (solana_api == nullptr) {
return 1;
}
//ConfigModelI* conf = nullptr;
{ // make sure required types are loaded
//conf = RESOLVE_INSTANCE(ConfigModelI);
//if (conf == nullptr) {
//std::cerr << "PLUGIN CRDTN missing ConfigModelI\n";
//return 2;
//}
}
// static store, could be anywhere tho
// construct with fetched dependencies
g_crdtn = std::make_unique<CRDTNotes>(/**conf*/);
// register types
PROVIDE_INSTANCE(CRDTNotes, "CRDTNotes", g_crdtn.get());
return 0;
}
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
std::cout << "PLUGIN CRDTN STOP()\n";
g_crdtn.reset();
}
SOLANA_PLUGIN_EXPORT void solana_plugin_tick(float delta) {
(void)delta;
//std::cout << "PLUGIN CRDTN TICK()\n";
//g_crdtn->iterate();
}
} // extern C

View File

@ -0,0 +1,82 @@
#include <solanaceae/plugin/solana_plugin_v1.h>
#include <solanaceae/crdtnotes_imgui/crdtnotes_imgui.hpp>
//#include <solanaceae/util/config_model.hpp>
#include <imgui.h>
#include <memory>
#include <iostream>
#define RESOLVE_INSTANCE(x) static_cast<x*>(solana_api->resolveInstance(#x))
#define PROVIDE_INSTANCE(x, p, v) solana_api->provideInstance(#x, p, static_cast<x*>(v))
static std::unique_ptr<CRDTNotesImGui> g_crdtn_imgui = nullptr;
extern "C" {
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) {
return "CRDTNIMGUIotesImGui";
}
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 CRDTNIMGUI START()\n";
if (solana_api == nullptr) {
return 1;
}
//ConfigModelI* conf = nullptr;
CRDTNotes* crdtn = nullptr;
ImGuiContext* imguic = nullptr;
{ // make sure required types are loaded
//conf = RESOLVE_INSTANCE(ConfigModelI);
crdtn = RESOLVE_INSTANCE(CRDTNotes);
imguic = RESOLVE_INSTANCE(ImGuiContext);
//if (conf == nullptr) {
//std::cerr << "PLUGIN CRDTNIMGUI missing ConfigModelI\n";
//return 2;
//}
if (crdtn == nullptr) {
std::cerr << "PLUGIN CRDTNIMGUI missing CRDTNotes\n";
return 2;
}
if (imguic == nullptr) {
std::cerr << "PLUGIN CRDTNIMGUI missing ImGuiContext\n";
return 2;
}
}
ImGui::SetCurrentContext(imguic);
// static store, could be anywhere tho
// construct with fetched dependencies
g_crdtn_imgui = std::make_unique<CRDTNotesImGui>(*crdtn);
// register types
PROVIDE_INSTANCE(CRDTNotesImGui, "CRDTNotesImGui", g_crdtn_imgui.get());
return 0;
}
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
std::cout << "PLUGIN CRDTNIMGUI STOP()\n";
g_crdtn_imgui.reset();
}
SOLANA_PLUGIN_EXPORT void solana_plugin_tick(float delta) {
(void)delta;
//std::cout << "PLUGIN CRDTNIMGUI TICK()\n";
g_crdtn_imgui->render();
}
} // extern C