Loading net/include/net/replication_system.hpp +4 −4 Original line number Diff line number Diff line Loading @@ -14,21 +14,21 @@ namespace net { void next_round() override; void register_property( com::ContextItem* owner, com::ContextItem* object, const std::string& getter_name, const std::string& setter_name, double update_interval = 0.0); void register_property( const std::vector<std::string>& owner_path, const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name, double update_interval = 0.0); void unregister_property( com::ContextItem* owner, com::ContextItem* object, const std::string& getter_name, const std::string& setter_name); void unregister_property( const std::vector<std::string>& owner_path, const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name); Loading net/include/net/types.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ namespace net { struct ReplicatedProperty { com::ContextItem* owner; com::ContextItem* object; std::string getter_name; std::string setter_name; com::Reflection::ValuePtr last_value; Loading net/src/replication_system.cpp +22 −22 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ namespace net { } void ReplicationSystem::register_property(ContextItem* owner, const std::string& getter_name, void ReplicationSystem::register_property(ContextItem* object, const std::string& getter_name, const std::string& setter_name, double update_interval) { if (driver()->mode() != SocketMode::SERVER) Loading @@ -63,31 +63,31 @@ namespace net { LOG(LSL_ERROR, "[ReplicationSystem] Only the server can register replicated properties"); return; } if (!owner || !owner->reflection()) if (!object || !object->reflection()) { LOG(LSL_ERROR, "[ReplicationSystem] Invalid owner for replicated property"); LOG(LSL_ERROR, "[ReplicationSystem] Invalid object for replicated property"); return; } if (!owner->reflection()->functions().contains(getter_name)) if (!object->reflection()->functions().contains(getter_name)) { LOG(LSL_ERROR, "[ReplicationSystem] Getter function " << getter_name << " not found in owner " << owner->name()); "[ReplicationSystem] Getter function " << getter_name << " not found in object " << owner->name()); return; } if (!owner->reflection()->functions().contains(setter_name)) if (!object->reflection()->functions().contains(setter_name)) { LOG(LSL_ERROR, "[ReplicationSystem] Setter function " << setter_name << " not found in owner " << owner->name()); "[ReplicationSystem] Setter function " << setter_name << " not found in object " << owner->name()); return; } ReplicatedProperty property; property.owner = owner; property.object = object; property.getter_name = getter_name; property.setter_name = setter_name; property.update_interval = update_interval; const auto& getter_function = owner->reflection()->functions().at(getter_name); const auto& getter_function = object->reflection()->functions().at(getter_name); property.getter_func = getter_function.code; property.last_value = com::make_default_value(getter_function.param_types[0]); Loading @@ -101,15 +101,15 @@ namespace net { static_cast<scalar>(config()->replication_full_resend_interval()) ); m_replicated_properties[owner].push_back(property); m_replicated_properties[object].push_back(property); } void ReplicationSystem::register_property(const std::vector<std::string>& owner_path, void ReplicationSystem::register_property(const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name, double update_interval) { auto owner = com::Folder::root()->locate<com::ContextItem>(owner_path); auto owner = com::Folder::root()->locate<com::ContextItem>(object_path); if (!owner) { LOG(LSL_ERROR, "[ReplicationSystem] Owner not found at path " << owner_path); Loading @@ -119,20 +119,20 @@ namespace net { register_property(owner, getter_name, setter_name, update_interval); } void ReplicationSystem::unregister_property(com::ContextItem* owner, const std::string& getter_name, const std::string& setter_name) void ReplicationSystem::unregister_property(com::ContextItem* object, const std::string& getter_name, const std::string& setter_name) { if (!owner) if (!object) { LOG(LSL_ERROR, "[ReplicationSystem] Invalid owner for replicated property"); LOG(LSL_ERROR, "[ReplicationSystem] Invalid object for replicated property"); return; } if (!m_replicated_properties.contains(owner)) if (!m_replicated_properties.contains(object)) { LOG(LSL_ERROR, "[ReplicationSystem] No replicated properties found for owner " << owner->name()); LOG(LSL_ERROR, "[ReplicationSystem] No replicated properties found for object " << owner->name()); return; } auto& properties = m_replicated_properties[owner]; auto& properties = m_replicated_properties[object]; std::erase_if(properties, [&](const ReplicatedProperty& prop) { Loading @@ -141,13 +141,13 @@ namespace net { if (properties.empty()) { m_replicated_properties.erase(owner); m_replicated_properties.erase(object); } } void ReplicationSystem::unregister_property(const std::vector<std::string>& owner_path, const std::string& getter_name, const std::string& setter_name) void ReplicationSystem::unregister_property(const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name) { auto owner = com::Folder::root()->locate<com::ContextItem>(owner_path); auto owner = com::Folder::root()->locate<com::ContextItem>(object_path); if (!owner) { LOG(LSL_ERROR, "[ReplicationSystem] Owner not found at path " << owner_path); Loading Loading @@ -221,7 +221,7 @@ namespace net { serializer.value1b(PacketType::REPLICATION); utils::serialize_path(serializer, property.owner->path(com::Folder::root())); utils::serialize_path(serializer, property.object->path(com::Folder::root())); serializer.text1b(property.setter_name, MAX_STRING_LENGTH); utils::serialize_reflection_value(serializer, value); Loading Loading
net/include/net/replication_system.hpp +4 −4 Original line number Diff line number Diff line Loading @@ -14,21 +14,21 @@ namespace net { void next_round() override; void register_property( com::ContextItem* owner, com::ContextItem* object, const std::string& getter_name, const std::string& setter_name, double update_interval = 0.0); void register_property( const std::vector<std::string>& owner_path, const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name, double update_interval = 0.0); void unregister_property( com::ContextItem* owner, com::ContextItem* object, const std::string& getter_name, const std::string& setter_name); void unregister_property( const std::vector<std::string>& owner_path, const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name); Loading
net/include/net/types.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ namespace net { struct ReplicatedProperty { com::ContextItem* owner; com::ContextItem* object; std::string getter_name; std::string setter_name; com::Reflection::ValuePtr last_value; Loading
net/src/replication_system.cpp +22 −22 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ namespace net { } void ReplicationSystem::register_property(ContextItem* owner, const std::string& getter_name, void ReplicationSystem::register_property(ContextItem* object, const std::string& getter_name, const std::string& setter_name, double update_interval) { if (driver()->mode() != SocketMode::SERVER) Loading @@ -63,31 +63,31 @@ namespace net { LOG(LSL_ERROR, "[ReplicationSystem] Only the server can register replicated properties"); return; } if (!owner || !owner->reflection()) if (!object || !object->reflection()) { LOG(LSL_ERROR, "[ReplicationSystem] Invalid owner for replicated property"); LOG(LSL_ERROR, "[ReplicationSystem] Invalid object for replicated property"); return; } if (!owner->reflection()->functions().contains(getter_name)) if (!object->reflection()->functions().contains(getter_name)) { LOG(LSL_ERROR, "[ReplicationSystem] Getter function " << getter_name << " not found in owner " << owner->name()); "[ReplicationSystem] Getter function " << getter_name << " not found in object " << owner->name()); return; } if (!owner->reflection()->functions().contains(setter_name)) if (!object->reflection()->functions().contains(setter_name)) { LOG(LSL_ERROR, "[ReplicationSystem] Setter function " << setter_name << " not found in owner " << owner->name()); "[ReplicationSystem] Setter function " << setter_name << " not found in object " << owner->name()); return; } ReplicatedProperty property; property.owner = owner; property.object = object; property.getter_name = getter_name; property.setter_name = setter_name; property.update_interval = update_interval; const auto& getter_function = owner->reflection()->functions().at(getter_name); const auto& getter_function = object->reflection()->functions().at(getter_name); property.getter_func = getter_function.code; property.last_value = com::make_default_value(getter_function.param_types[0]); Loading @@ -101,15 +101,15 @@ namespace net { static_cast<scalar>(config()->replication_full_resend_interval()) ); m_replicated_properties[owner].push_back(property); m_replicated_properties[object].push_back(property); } void ReplicationSystem::register_property(const std::vector<std::string>& owner_path, void ReplicationSystem::register_property(const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name, double update_interval) { auto owner = com::Folder::root()->locate<com::ContextItem>(owner_path); auto owner = com::Folder::root()->locate<com::ContextItem>(object_path); if (!owner) { LOG(LSL_ERROR, "[ReplicationSystem] Owner not found at path " << owner_path); Loading @@ -119,20 +119,20 @@ namespace net { register_property(owner, getter_name, setter_name, update_interval); } void ReplicationSystem::unregister_property(com::ContextItem* owner, const std::string& getter_name, const std::string& setter_name) void ReplicationSystem::unregister_property(com::ContextItem* object, const std::string& getter_name, const std::string& setter_name) { if (!owner) if (!object) { LOG(LSL_ERROR, "[ReplicationSystem] Invalid owner for replicated property"); LOG(LSL_ERROR, "[ReplicationSystem] Invalid object for replicated property"); return; } if (!m_replicated_properties.contains(owner)) if (!m_replicated_properties.contains(object)) { LOG(LSL_ERROR, "[ReplicationSystem] No replicated properties found for owner " << owner->name()); LOG(LSL_ERROR, "[ReplicationSystem] No replicated properties found for object " << owner->name()); return; } auto& properties = m_replicated_properties[owner]; auto& properties = m_replicated_properties[object]; std::erase_if(properties, [&](const ReplicatedProperty& prop) { Loading @@ -141,13 +141,13 @@ namespace net { if (properties.empty()) { m_replicated_properties.erase(owner); m_replicated_properties.erase(object); } } void ReplicationSystem::unregister_property(const std::vector<std::string>& owner_path, const std::string& getter_name, const std::string& setter_name) void ReplicationSystem::unregister_property(const std::vector<std::string>& object_path, const std::string& getter_name, const std::string& setter_name) { auto owner = com::Folder::root()->locate<com::ContextItem>(owner_path); auto owner = com::Folder::root()->locate<com::ContextItem>(object_path); if (!owner) { LOG(LSL_ERROR, "[ReplicationSystem] Owner not found at path " << owner_path); Loading Loading @@ -221,7 +221,7 @@ namespace net { serializer.value1b(PacketType::REPLICATION); utils::serialize_path(serializer, property.owner->path(com::Folder::root())); utils::serialize_path(serializer, property.object->path(com::Folder::root())); serializer.text1b(property.setter_name, MAX_STRING_LENGTH); utils::serialize_reflection_value(serializer, value); Loading