From 161f605b2037cfab191f9dcd0b0ba6e00e8d5294 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 10 Mar 2025 22:57:15 +0100 Subject: [PATCH] port to contact4 --- plugins/plugin_factorio.cpp | 4 ++-- src/factorio.cpp | 19 +++++++------------ src/factorio.hpp | 7 ++++--- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/plugins/plugin_factorio.cpp b/plugins/plugin_factorio.cpp index e0af4f7..925b977 100644 --- a/plugins/plugin_factorio.cpp +++ b/plugins/plugin_factorio.cpp @@ -34,13 +34,13 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) try { auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); - auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1"); + auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I); auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI); // static store, could be anywhere tho // construct with fetched dependencies g_flp = std::make_unique(*conf); - g_f = std::make_unique(*conf, *cr, *rmm, *g_flp); + g_f = std::make_unique(*conf, *cs, *rmm, *g_flp); // register types PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get()); diff --git a/src/factorio.cpp b/src/factorio.cpp index 2652dd8..9c5e5d6 100644 --- a/src/factorio.cpp +++ b/src/factorio.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include @@ -16,9 +18,9 @@ void Factorio::sendToLinked(const std::string& message) { } } -Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModelI& rmm, FactorioLogParser& flp) : +Factorio::Factorio(ConfigModelI& conf, ContactStore4I& cs, RegistryMessageModelI& rmm, FactorioLogParser& flp) : _conf(conf), - _cr(cr), + _cs(cs), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _flp(flp), @@ -31,19 +33,12 @@ Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageMode const auto id_vec = hex2bin(contact_id); // search - Contact3Handle h; - auto view = _cr.view(); - for (const auto c : view) { - if (view.get(c).data == id_vec) { - h = Contact3Handle{_cr, c}; - std::cout << "Factorio: found contact for link.\n"; - break; - } - } + ContactHandle4 h = _cs.getOneContactByID(ByteSpan{id_vec}); if (!static_cast(h)) { // not found, create thin contact with just id - h = {_cr, _cr.create()}; + h = _cs.contactHandle(_cs.registry().create()); h.emplace(id_vec); + _cs.throwEventConstruct(h); std::cout << "Factorio: contact not found, created thin contact from ID. (" << contact_id << ")\n"; } _linked_contacts.push_back(h); diff --git a/src/factorio.hpp b/src/factorio.hpp index 280a825..efbfe34 100644 --- a/src/factorio.hpp +++ b/src/factorio.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "./factorio_log_parser.hpp" @@ -11,18 +12,18 @@ struct ConfigModelI; class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI { ConfigModelI& _conf; - Contact3Registry& _cr; + ContactStore4I& _cs; RegistryMessageModelI& _rmm; RegistryMessageModelI::SubscriptionReference _rmm_sr; FactorioLogParser& _flp; FactorioLogParser::SubscriptionReference _flp_sr; - std::vector _linked_contacts; + std::vector _linked_contacts; void sendToLinked(const std::string& message); public: - Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModelI& rmm, FactorioLogParser& flp); + Factorio(ConfigModelI& conf, ContactStore4I& cs, RegistryMessageModelI& rmm, FactorioLogParser& flp); virtual ~Factorio(void); protected: // rmm