MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / init_client_callbacks

Method init_client_callbacks

src/ResourceManager.cpp:41–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39{}
40
41void ResourceManager::init_client_callbacks() {
42 world.netClient->add_recv_callback(SERVER_NEW_RESOURCE_ID, [&](cereal::PortableBinaryInputArchive& message) {
43 NetworkingObjects::NetObjID idBeingRetrieved;
44 message(idBeingRetrieved);
45 // There is a scenario where the resource id and data messages can be sent twice for the same resource (a resource can be sent early before CLIENT_INITIAL_DATA is sent, and then resent with CLIENT_INITIAL_DATA), so check if resource already exists, and only keep track of the ID if the resource doesn't exist yet
46 if(!world.netObjMan.get_obj_temporary_ref_from_id<ResourceData>(idBeingRetrieved))
47 resourcesBeingRetrieved.emplace(idBeingRetrieved, std::weak_ptr<NetServer::ClientData>());
48 world.main.g.gui.set_to_layout();
49 });
50 world.netClient->add_recv_callback(SERVER_NEW_RESOURCE_DATA, [&](cereal::PortableBinaryInputArchive& message) {
51 if(!resourcesBeingRetrieved.empty()) { // If the resource was sent for the second time, this will be empty, so we can ignore the message
52 ResourceData newResource;
53 message(newResource);
54 resourceList.emplace_back(world.netObjMan.make_obj_direct_with_specific_id<ResourceData>(resourcesBeingRetrieved.begin()->first, newResource));
55 resourcesBeingRetrieved.clear();
56 }
57 world.main.g.gui.set_to_layout();
58 });
59}
60
61void ResourceManager::init_server_callbacks() {
62 world.netServer->add_recv_callback(CLIENT_NEW_RESOURCE_ID, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) {

Callers 1

init_clientMethod · 0.45

Calls 5

set_to_layoutMethod · 0.80
add_recv_callbackMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected