2025-07-06 20:43:53 +03:00
|
|
|
#pragma once
|
2025-12-16 12:02:08 +03:00
|
|
|
#include <Helpers/NetworkingObjects/NetObjOwnerPtr.hpp>
|
2025-07-06 20:43:53 +03:00
|
|
|
#include <include/codec/SkCodec.h>
|
2025-12-16 12:02:08 +03:00
|
|
|
#include "Helpers/NetworkingObjects/NetObjID.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
#include "ResourceDisplay/ResourceDisplay.hpp"
|
2025-10-10 10:34:12 +03:00
|
|
|
#include <Helpers/Networking/NetLibrary.hpp>
|
2025-12-16 12:02:08 +03:00
|
|
|
#include <Helpers/NetworkingObjects/NetObjUnorderedSet.hpp>
|
2026-01-01 23:28:26 +03:00
|
|
|
#include <Helpers/VersionNumber.hpp>
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
class World;
|
|
|
|
|
|
|
|
|
|
struct ResourceData {
|
|
|
|
|
std::string name;
|
|
|
|
|
std::shared_ptr<std::string> data;
|
|
|
|
|
template <typename Archive> void save(Archive& a) const {
|
|
|
|
|
a(name, *data);
|
|
|
|
|
}
|
|
|
|
|
template <typename Archive> void load(Archive& a) {
|
|
|
|
|
data = std::make_shared<std::string>();
|
|
|
|
|
a(name, *data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ResourceManager {
|
|
|
|
|
public:
|
|
|
|
|
ResourceManager(World& initWorld);
|
|
|
|
|
void update();
|
|
|
|
|
void init_client_callbacks();
|
2025-12-16 12:02:08 +03:00
|
|
|
void init_server_callbacks();
|
2025-12-16 12:54:12 +03:00
|
|
|
NetworkingObjects::NetObjTemporaryPtr<ResourceData> add_resource_file(const std::filesystem::path& filePath);
|
|
|
|
|
const NetworkingObjects::NetObjOwnerPtr<ResourceData>& add_resource(const ResourceData& resource);
|
2025-12-16 12:02:08 +03:00
|
|
|
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);
|
2025-12-29 19:57:36 +03:00
|
|
|
std::unordered_map<NetworkingObjects::NetObjID, ResourceData> copy_resource_set_to_map(const std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
|
2026-02-19 22:29:24 +03:00
|
|
|
void clear_display_cache();
|
2025-08-07 17:45:10 +03:00
|
|
|
|
2026-01-01 23:28:26 +03:00
|
|
|
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
|
|
|
|
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
|
|
|
|
|
2025-08-07 17:45:10 +03:00
|
|
|
World& world;
|
2025-07-06 20:43:53 +03:00
|
|
|
private:
|
2025-12-16 12:02:08 +03:00
|
|
|
std::unordered_map<NetworkingObjects::NetObjID, std::unique_ptr<ResourceDisplay>> displays;
|
2025-10-09 21:02:19 +03:00
|
|
|
|
2025-12-17 14:46:27 +03:00
|
|
|
std::unordered_map<NetworkingObjects::NetObjID, std::weak_ptr<NetServer::ClientData>> resourcesBeingRetrieved;
|
2025-12-16 12:02:08 +03:00
|
|
|
std::vector<NetworkingObjects::NetObjOwnerPtr<ResourceData>> resourceList;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
static std::array<const SkCodecs::Decoder, 5> decoders;
|
|
|
|
|
};
|
|
|
|
|
|