diff --git a/include/Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp b/include/Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp index 3b7fa9f..20c7528 100644 --- a/include/Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp +++ b/include/Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp @@ -1,4 +1,5 @@ #pragma once +#include "Helpers/Networking/NetLibrary.hpp" #include "NetObjWeakPtr.hpp" #include "cereal/archives/portable_binary.hpp" #include @@ -8,7 +9,7 @@ namespace NetworkingObjects { public: template void register_class(NetObjManagerTypeList& t) { t.register_class({ - .writeConstructorFuncClient = [&](const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a){client_write_func(o, a);}, + .writeConstructorFuncClient = [&](const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a){client_write_func(std::nullopt, o, a);}, .readConstructorFuncClient = [&](const NetObjPtr& o, cereal::PortableBinaryInputArchive& a, const std::shared_ptr&){delay_read_func(o, a);}, .readUpdateFuncClient = [&](const NetObjPtr& o, cereal::PortableBinaryInputArchive& a, const std::shared_ptr&){delay_read_func(o, a);}, .writeConstructorFuncServer = [&](const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a){server_write_func(o, a);}, @@ -16,17 +17,19 @@ namespace NetworkingObjects { .readUpdateFuncServer = [&](const NetObjPtr& o, cereal::PortableBinaryInputArchive& a, const std::shared_ptr&){server_read_update_func(o, a);} }); } - template void send_update_to_all(const NetworkingObjects::NetObjPtr& o) { - o.send_update_to_all(RELIABLE_COMMAND_CHANNEL, [&](const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a) { + template void send_update_to_all(const NetworkingObjects::NetObjPtr& o, bool finalUpdate) { + o.send_update_to_all(finalUpdate ? RELIABLE_COMMAND_CHANNEL : UNRELIABLE_COMMAND_CHANNEL, [&](const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a) { if(o.get_obj_man()->is_server()) server_write_func(o, a); else - client_write_func(o, a); + client_write_func(finalUpdate, o, a); }); } void update(); private: - template void client_write_func(const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a) { + template void client_write_func(std::optional finalUpdate, const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a) { + if(finalUpdate.has_value()) + a(finalUpdate.value()); a(*o); auto it = updatingObjs.find(o.get_net_id()); if(it == updatingObjs.end()) { @@ -83,15 +86,16 @@ namespace NetworkingObjects { template void server_read_update_func(const NetObjPtr& o, cereal::PortableBinaryInputArchive& a) { auto it = updatingObjs.find(o.get_net_id()); + bool finalUpdate; if(it == updatingObjs.end()) { - a(*o); - o.send_server_update_to_all_clients(RELIABLE_COMMAND_CHANNEL, [](const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a) { + a(finalUpdate, *o); + o.send_server_update_to_all_clients(finalUpdate ? RELIABLE_COMMAND_CHANNEL : UNRELIABLE_COMMAND_CHANNEL, [](const NetObjPtr& o, cereal::PortableBinaryOutputArchive& a) { a(*o); }); } else { auto& [netID, updatingObjData] = *it; - a(*std::static_pointer_cast(updatingObjData.objToUpdateCurrentData)); + a(finalUpdate, *std::static_pointer_cast(updatingObjData.objToUpdateCurrentData)); } } diff --git a/src/DrawingProgram/GridModifyTool.cpp b/src/DrawingProgram/GridModifyTool.cpp index f399e39..da5c01f 100644 --- a/src/DrawingProgram/GridModifyTool.cpp +++ b/src/DrawingProgram/GridModifyTool.cpp @@ -137,7 +137,7 @@ void GridModifyTool::tool_update() { selectionMode = 0; break; } - drawP.world.delayedUpdateObjectManager.send_update_to_all(grid); + drawP.world.delayedUpdateObjectManager.send_update_to_all(grid, false); } else selectionMode = 0; @@ -180,5 +180,5 @@ void GridModifyTool::draw(SkCanvas* canvas, const DrawData& drawData) { } void GridModifyTool::switch_tool(DrawingProgramToolType newTool) { - NetworkingObjects::generic_serialized_class_send_update_to_all(grid); + drawP.world.delayedUpdateObjectManager.send_update_to_all(grid, true); }