Amerio.Stephane Posted March 16, 2023 Share Posted March 16, 2023 Hi, I'm trying to move our network master/slave sync code to the IG::NetworkComponentBase architecture as explained here https://developer.unigine.com/en/docs/2.16.1/ig/custom_component?#network_ig_component but I can't make it to work. For example, based on the documentation, this code should replicate "value" from master to slave, but the slave always prints "-1", proving the data never reach it. I have no warnings/errors related to this in the logs. #pragma once #include <UnigineComponentSystem.h> #include <plugins/UnigineIGNetwork.h> class NetComponent : public Unigine::Plugins::IG::NetworkComponentBase { public: NET_COMPONENT_DEFINE(NetComponent, Unigine::Plugins::IG::NetworkComponentBase); COMPONENT_INIT(init); COMPONENT_UPDATE(update); private: void init(); void update(); NET_DEFINE_SLOT(setValue); void setValue(int value); int value = 0; }; #include "NetComponent.h" #include <UnigineGame.h> #include <UnigineVisualizer.h> NET_REGISTER_COMPONENT(NetComponent); using namespace Unigine; void NetComponent::init() { value = 0; IG_ONLY_FOR_SLAVE; value = -1; } void NetComponent::update() { Log::message("%s=%d\n", Unigine::Plugins::IG::Manager::get()->isMaster() ? "master":"slave", value); IG_ONLY_FOR_MASTER; setValue(Game::getFrame()); } void NetComponent::setValue(int value) { this->value = value; NET_CALL(setValue, value); } At compilation, VS2019 gives me this warning: 1>NetComponent.cpp 1>I:\wkspaces216\AH_UNG_DEV\include\plugins\UnigineIGNetwork.h(376,2): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data 1>I:\wkspaces216\AH_UNG_DEV\source\AH.Core\NetComponent.h(9): message : see reference to function template instantiation 'void Unigine::Plugins::IG::Sender::init<NetComponent,int,int>(T *,int,int)' being compiled 1> with 1> [ 1> T=NetComponent 1> ] 1>I:\wkspaces216\AH_UNG_DEV\include\plugins\UnigineIGNetwork.h(291,1): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data 1>I:\wkspaces216\AH_UNG_DEV\source\AH.Core\NetComponent.cpp(6): message : see reference to function template instantiation 'void Unigine::Plugins::IG::NetworkRegistrator::registrateNetworkComponent<NetComponent>(void)' being compiled What am I obviously missing here? Link to comment
cash-metall Posted March 17, 2023 Share Posted March 17, 2023 Hello! I copied your code, ran it and everything works correctly. the master sends data and it reaches the slave correctly. Right now all conponents inside IG work by this way. please describe in more detail if there is anything else in your project because I used an empty 2.16.1 project without any modifications. At the moment, only the problem with the order of the components is known. If the component was moved on the same node after initialization (property_num was changed), then there may be a delivery problem. Link to comment
Amerio.Stephane Posted March 17, 2023 Author Share Posted March 17, 2023 The NetComponent is compiled in a DLL, which is then loaded as a plugin with Unigine. We do this for multiple components, because it allows us to easily separate code development and allows to enable/distribute features without rebuilding the whole application. Indeed, when NetComponent is build along side the main app code, it does work. Though the documentation forgets to mention that you need a new line: IG::NetworkRegistrator::get()->init(); So, is it possible to have a network component in a DLL, or should be rework all of our code? Link to comment
cash-metall Posted March 17, 2023 Share Posted March 17, 2023 Yes, i got it. is it a usual shared library with your own logic or engine plugin? theoretically yes you can put it in a DLL or engine plugin but you have to also call IG::NetworkRegistrator::get()->init(); inside each library in initialization stage. I will run some tests today on move the component to the engine plugin - if I find any problems, I will add to the answer. Link to comment
cash-metall Posted March 17, 2023 Share Posted March 17, 2023 yes, i tested it in few plugins, and it works! i make two component each was builded in separete plugin. and start application with both plugins: ``` -extern_plugin "IG,IGTEST,IGTEST2" ``` ig.zip 1 1 Link to comment
Amerio.Stephane Posted March 17, 2023 Author Share Posted March 17, 2023 It works now! Thank very much! Link to comment
Amerio.Stephane Posted March 17, 2023 Author Share Posted March 17, 2023 What about the compilation warning? Am I doing anything wrong, or should it be fixed on your side? Link to comment
cash-metall Posted March 20, 2023 Share Posted March 20, 2023 On 3/17/2023 at 8:30 PM, Amerio.Stephane said: What about the compilation warning? Am I doing anything wrong, or should it be fixed on your side? it is harmless warning about type convertation size_t to int on our side. it shouldn't cause any problems, we'll mute it. Link to comment
Recommended Posts