| 39 | {} |
| 40 | |
| 41 | void 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 | |
| 61 | void ResourceManager::init_server_callbacks() { |
| 62 | world.netServer->add_recv_callback(CLIENT_NEW_RESOURCE_ID, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) { |
no test coverage detected