Resource manager works over network

This commit is contained in:
Yousef Khadadeh 2025-12-16 13:48:21 +03:00
parent 859924663b
commit 86858d238e
5 changed files with 14 additions and 14 deletions

View file

@ -68,9 +68,6 @@ void DrawingProgram::set_component_list_callbacks() {
});
}
void DrawingProgram::init_client_callbacks() {
}
void DrawingProgram::scale_up(const WorldScalar& scaleUpAmount) {
//for(auto& c : components->get_data())
// c->obj->scale_up(scaleUpAmount);

View file

@ -23,7 +23,6 @@ class DrawingProgram {
public:
DrawingProgram(World& initWorld);
void init();
void init_client_callbacks();
void set_component_list_callbacks();
void toolbar_gui();
void tool_options_gui();

View file

@ -19,15 +19,21 @@ ResourceManager::ResourceManager(World& initWorld):
void ResourceManager::init_client_callbacks() {
world.con.client_add_recv_callback(SERVER_NEW_RESOURCE_ID, [&](cereal::PortableBinaryInputArchive& message) {
NetworkingObjects::NetObjID idBeingRetrieved;
message(idBeingRetrieved);
resourcesBeingRetrieved.emplace(idBeingRetrieved, 0);
if(!world.con.host_exists()) {
NetworkingObjects::NetObjID idBeingRetrieved;
message(idBeingRetrieved);
// 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
if(!world.netObjMan.get_obj_temporary_ref_from_id<ResourceData>(idBeingRetrieved))
resourcesBeingRetrieved.emplace(idBeingRetrieved, 0);
}
});
world.con.client_add_recv_callback(SERVER_NEW_RESOURCE_DATA, [&](cereal::PortableBinaryInputArchive& message) {
ResourceData newResource;
message(newResource);
resourceList.emplace_back(world.netObjMan.make_obj_direct_with_specific_id<ResourceData>(resourcesBeingRetrieved.begin()->first, newResource));
resourcesBeingRetrieved.clear();
if(!world.con.host_exists() && !resourcesBeingRetrieved.empty()) { // If the resource was sent for the second time, this will be empty, so we can ignore the message
ResourceData newResource;
message(newResource);
resourceList.emplace_back(world.netObjMan.make_obj_direct_with_specific_id<ResourceData>(resourcesBeingRetrieved.begin()->first, newResource));
resourcesBeingRetrieved.clear();
}
});
}

View file

@ -12,7 +12,6 @@ class MainServer {
~MainServer();
std::shared_ptr<NetServer> netServer;
std::unordered_map<ServerPortionID, ClientData> clients;
std::unordered_map<ServerClientID, NetLibrary::DownloadProgress> resource_download_progress();
private:
World& world;
void ensure_display_name_unique(std::string& displayName);

View file

@ -75,7 +75,6 @@ World::World(MainProgram& initMain, OpenWorldInfo& worldInfo):
}
}
drawProg.init_client_callbacks();
rMan.init_client_callbacks();
init_client_callbacks();
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, displayName, false);
@ -301,8 +300,8 @@ void World::start_hosting(const std::string& initNetSource, const std::string& s
return;
main.init_net_library();
con.init_local_p2p(*this, serverLocalID);
drawProg.init_client_callbacks();
rMan.init_client_callbacks();
rMan.init_server_callbacks();
init_client_callbacks();
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, displayName, true, drawData.cam.c, main.window.size.cast<float>().eval());
conType = CONNECTIONTYPE_SERVER;