update imgui and new versioned plugin api
This commit is contained in:
@@ -2,23 +2,19 @@
|
||||
|
||||
#include <solanaceae/zox/ngc_hs.hpp>
|
||||
#include <solanaceae/toxcore/tox_interface.hpp>
|
||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
// fwd
|
||||
struct ContactModelI;
|
||||
class RegistryMessageModel;
|
||||
|
||||
#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<ZoxNGCHistorySync> g_zngchs = nullptr;
|
||||
|
||||
constexpr const char* plugin_name = "ZoxNGCHistorySync";
|
||||
|
||||
extern "C" {
|
||||
|
||||
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) {
|
||||
return "ZoxNGCHistorySync";
|
||||
return plugin_name;
|
||||
}
|
||||
|
||||
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
|
||||
@@ -26,76 +22,41 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
|
||||
}
|
||||
|
||||
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) {
|
||||
std::cout << "PLUGIN ZNGCHS START()\n";
|
||||
std::cout << "PLUGIN " << plugin_name << " START()\n";
|
||||
|
||||
if (solana_api == nullptr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ToxI* tox_i = nullptr;
|
||||
ToxEventProviderI* tox_event_provider_i = nullptr;
|
||||
ZoxNGCEventProviderI* zox_ngc_event_provider_i = nullptr;
|
||||
Contact3Registry* cr = nullptr;
|
||||
ToxContactModel2* tcm = nullptr;
|
||||
RegistryMessageModel* rmm = nullptr;
|
||||
try {
|
||||
auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI);
|
||||
auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
|
||||
auto* zox_ngc_event_provider_i = PLUG_RESOLVE_INSTANCE(ZoxNGCEventProviderI);
|
||||
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
|
||||
auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
|
||||
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel);
|
||||
|
||||
{ // make sure required types are loaded
|
||||
tox_i = RESOLVE_INSTANCE(ToxI);
|
||||
tox_event_provider_i = RESOLVE_INSTANCE(ToxEventProviderI);
|
||||
zox_ngc_event_provider_i = RESOLVE_INSTANCE(ZoxNGCEventProviderI);
|
||||
cr = RESOLVE_INSTANCE(Contact3Registry);
|
||||
tcm = RESOLVE_INSTANCE(ToxContactModel2);
|
||||
rmm = RESOLVE_INSTANCE(RegistryMessageModel);
|
||||
// static store, could be anywhere tho
|
||||
// construct with fetched dependencies
|
||||
g_zngchs = std::make_unique<ZoxNGCHistorySync>(*tox_event_provider_i, *zox_ngc_event_provider_i, *tox_i, *cr, *tcm, *rmm);
|
||||
|
||||
if (tox_i == nullptr) {
|
||||
std::cerr << "PLUGIN ZNGCHS missing ToxI\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (tox_event_provider_i == nullptr) {
|
||||
std::cerr << "PLUGIN ZNGCHS missing ToxEventProviderI\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (zox_ngc_event_provider_i == nullptr) {
|
||||
std::cerr << "PLUGIN ZNGCHS missing ZoxNGCEventProviderI\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (cr == nullptr) {
|
||||
std::cerr << "PLUGIN ZNGCHS missing ContactModelI\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (tcm == nullptr) {
|
||||
std::cerr << "PLUGIN ZNGCHS missing ToxContactModel2\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (rmm == nullptr) {
|
||||
std::cerr << "PLUGIN ZNGCHS missing RegistryMessageModel\n";
|
||||
return 2;
|
||||
}
|
||||
// register types
|
||||
PLUG_PROVIDE_INSTANCE(ZoxNGCHistorySync, plugin_name, g_zngchs.get());
|
||||
} catch (const ResolveException& e) {
|
||||
std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
// static store, could be anywhere tho
|
||||
// construct with fetched dependencies
|
||||
g_zngchs = std::make_unique<ZoxNGCHistorySync>(*tox_event_provider_i, *zox_ngc_event_provider_i, *tox_i, *cr, *tcm, *rmm);
|
||||
|
||||
// register types
|
||||
PROVIDE_INSTANCE(ZoxNGCHistorySync, "ZoxNGCHistorySync", g_zngchs.get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
|
||||
std::cout << "PLUGIN ZNGCHS STOP()\n";
|
||||
std::cout << "PLUGIN " << plugin_name << " STOP()\n";
|
||||
|
||||
g_zngchs.reset();
|
||||
}
|
||||
|
||||
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) {
|
||||
//std::cout << "PLUGIN ZNGCHS TICK()\n";
|
||||
g_zngchs->tick(delta);
|
||||
|
||||
return 0.1f; // TODO: use the actual timers
|
||||
|
||||
Reference in New Issue
Block a user