Use net objects in resource manager
This commit is contained in:
parent
9e049f0201
commit
9187518290
14 changed files with 113 additions and 179 deletions
|
|
@ -1,13 +1,10 @@
|
|||
#pragma once
|
||||
#include "SharedTypes.hpp"
|
||||
#include <Helpers/NetworkingObjects/NetObjOwnerPtr.hpp>
|
||||
#include <include/codec/SkCodec.h>
|
||||
#include <include/core/SkImage.h>
|
||||
#include "Helpers/NetworkingObjects/NetObjID.hpp"
|
||||
#include "ResourceDisplay/ResourceDisplay.hpp"
|
||||
#include <cereal/types/utility.hpp>
|
||||
#include <cereal/types/string.hpp>
|
||||
#include <cereal/types/unordered_map.hpp>
|
||||
#include <queue>
|
||||
#include <Helpers/Networking/NetLibrary.hpp>
|
||||
#include <Helpers/NetworkingObjects/NetObjUnorderedSet.hpp>
|
||||
|
||||
class World;
|
||||
|
||||
|
|
@ -26,34 +23,21 @@ struct ResourceData {
|
|||
class ResourceManager {
|
||||
public:
|
||||
ResourceManager(World& initWorld);
|
||||
template <typename Archive> void serialize(Archive& a) {
|
||||
a(resources);
|
||||
}
|
||||
template <typename Archive> void save_strip_unused_resources(Archive& a, const std::unordered_set<ServerClientID>& usedResources) const {
|
||||
std::unordered_map<ServerClientID, ResourceData> strippedResources = resources;
|
||||
std::erase_if(strippedResources, [&](const auto& p) {
|
||||
return !usedResources.contains(p.first);
|
||||
});
|
||||
a(strippedResources);
|
||||
}
|
||||
void update();
|
||||
void copy_resource_set_to_map(const std::unordered_set<ServerClientID>& resourceSet, std::unordered_map<ServerClientID, ResourceData>& resourceMap) const;
|
||||
void init_client_callbacks();
|
||||
ServerClientID add_resource_file(const std::filesystem::path& filePath);
|
||||
ServerClientID add_resource(const ResourceData& resource);
|
||||
ResourceDisplay* get_display_data(const ServerClientID& fileID);
|
||||
std::optional<ResourceData> get_resource(const ServerClientID& id) const;
|
||||
ClientPortionID get_max_id(ServerPortionID serverID) const;
|
||||
const std::unordered_map<ServerClientID, ResourceData>& resource_list();
|
||||
float get_resource_retrieval_progress(const ServerClientID& id);
|
||||
void init_server_callbacks();
|
||||
NetworkingObjects::NetObjID add_resource_file(const std::filesystem::path& filePath);
|
||||
NetworkingObjects::NetObjID add_resource(const ResourceData& resource);
|
||||
ResourceDisplay* get_display_data(const NetworkingObjects::NetObjID& fileID);
|
||||
const std::vector<NetworkingObjects::NetObjOwnerPtr<ResourceData>>& resource_list();
|
||||
float get_resource_retrieval_progress(const NetworkingObjects::NetObjID& id);
|
||||
|
||||
World& world;
|
||||
private:
|
||||
std::unordered_map<ServerClientID, NetLibrary::DownloadProgress> serverDownloadProgress;
|
||||
ServerClientID resourceBeingRetrievedClient = {0, 0};
|
||||
std::unordered_map<NetworkingObjects::NetObjID, std::unique_ptr<ResourceDisplay>> displays;
|
||||
|
||||
std::unordered_map<ServerClientID, ResourceData> resources;
|
||||
std::unordered_map<ServerClientID, std::unique_ptr<ResourceDisplay>> displays;
|
||||
std::unordered_map<NetworkingObjects::NetObjID, uint64_t> resourcesBeingRetrieved;
|
||||
std::vector<NetworkingObjects::NetObjOwnerPtr<ResourceData>> resourceList;
|
||||
|
||||
static std::array<const SkCodecs::Decoder, 5> decoders;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue