Can now save/load resources
This commit is contained in:
parent
9913eb6c8e
commit
b5877ff3ca
13 changed files with 59 additions and 0 deletions
|
|
@ -545,6 +545,10 @@ void DrawingProgram::save_file(cereal::PortableBinaryOutputArchive& a) const {
|
|||
layerMan.save_file(a);
|
||||
}
|
||||
|
||||
void DrawingProgram::get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) {
|
||||
layerMan.get_used_resources(resourceSet);
|
||||
}
|
||||
|
||||
void DrawingProgram::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
if(drawData.dontUseDrawProgCache)
|
||||
layerMan.draw(canvas, drawData);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class DrawingProgram {
|
|||
void init_client_callbacks();
|
||||
void add_file_to_canvas_by_path(const std::filesystem::path& filePath, Vector2f dropPos, bool addInSameThread);
|
||||
void add_file_to_canvas_by_data(const std::string& fileName, std::string_view fileBuffer, Vector2f dropPos);
|
||||
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet);
|
||||
|
||||
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
||||
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||
|
|
|
|||
|
|
@ -70,3 +70,8 @@ void DrawingProgramLayer::save_file(cereal::PortableBinaryOutputArchive& a) cons
|
|||
for(auto& comp : *components)
|
||||
comp.obj->save_file(a);
|
||||
}
|
||||
|
||||
void DrawingProgramLayer::get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const {
|
||||
for(auto& comp : *components)
|
||||
comp.obj->get_comp().get_used_resources(resourceSet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ class DrawingProgramLayer {
|
|||
|
||||
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version, DrawingProgramLayerManager& layerMan);
|
||||
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||
|
||||
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
|
||||
private:
|
||||
std::function<void(const CanvasComponentContainer::ObjInfoIterator& c)> eraseCallback;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -69,3 +69,8 @@ void DrawingProgramLayerFolder::save_file(cereal::PortableBinaryOutputArchive& a
|
|||
for(auto& listItem : *folderList)
|
||||
listItem.obj->save_file(a);
|
||||
}
|
||||
|
||||
void DrawingProgramLayerFolder::get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const {
|
||||
for(auto& listItem : *folderList)
|
||||
listItem.obj->get_used_resources(resourceSet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,4 +21,6 @@ class DrawingProgramLayerFolder {
|
|||
|
||||
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version, DrawingProgramLayerManager& layerMan);
|
||||
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||
|
||||
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -121,6 +121,13 @@ void DrawingProgramLayerListItem::save_file(cereal::PortableBinaryOutputArchive&
|
|||
layerData->save_file(a);
|
||||
}
|
||||
|
||||
void DrawingProgramLayerListItem::get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const {
|
||||
if(folderData)
|
||||
folderData->get_used_resources(resourceSet);
|
||||
else
|
||||
layerData->get_used_resources(resourceSet);
|
||||
}
|
||||
|
||||
void DrawingProgramLayerListItem::draw(SkCanvas* canvas, const DrawData& drawData) const {
|
||||
if(displayData->visible) {
|
||||
SkPaint layerPaint;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <Helpers/NetworkingObjects/NetObjManager.hpp>
|
||||
#include <Helpers/NetworkingObjects/NetObjOrderedList.hpp>
|
||||
#include <Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp>
|
||||
#include <unordered_set>
|
||||
#include "DrawingProgramLayerFolder.hpp"
|
||||
#include "DrawingProgramLayer.hpp"
|
||||
#include "SerializedBlendMode.hpp"
|
||||
|
|
@ -29,6 +30,7 @@ class DrawingProgramLayerListItem {
|
|||
void get_flattened_component_list(std::vector<CanvasComponentContainer::ObjInfo*>& objList) const;
|
||||
void get_flattened_layer_list(std::vector<DrawingProgramLayerListItem*>& objList);
|
||||
void scale_up(const WorldScalar& scaleUpAmount);
|
||||
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
|
||||
|
||||
void set_alpha(DrawingProgramLayerManager& layerMan, float newAlpha) const;
|
||||
float get_alpha() const;
|
||||
|
|
|
|||
|
|
@ -120,3 +120,7 @@ void DrawingProgramLayerManager::load_file(cereal::PortableBinaryInputArchive& a
|
|||
void DrawingProgramLayerManager::save_file(cereal::PortableBinaryOutputArchive& a) const {
|
||||
layerTreeRoot->save_file(a);
|
||||
}
|
||||
|
||||
void DrawingProgramLayerManager::get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) {
|
||||
layerTreeRoot->get_used_resources(resourceSet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class DrawingProgramLayerManager {
|
|||
|
||||
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
||||
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet);
|
||||
|
||||
bool layer_tree_root_exists();
|
||||
const DrawingProgramLayerListItem& get_layer_root();
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "World.hpp"
|
||||
#include "ResourceDisplay/FileResourceDisplay.hpp"
|
||||
#include <cereal/archives/portable_binary.hpp>
|
||||
#include <cereal/types/unordered_map.hpp>
|
||||
|
||||
ResourceManager::ResourceManager(World& initWorld):
|
||||
world(initWorld)
|
||||
|
|
@ -180,3 +181,22 @@ std::unordered_map<NetworkingObjects::NetObjID, ResourceData> ResourceManager::c
|
|||
const std::vector<NetworkingObjects::NetObjOwnerPtr<ResourceData>>& ResourceManager::resource_list() {
|
||||
return resourceList;
|
||||
}
|
||||
|
||||
void ResourceManager::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) {
|
||||
std::unordered_map<NetworkingObjects::NetObjID, ResourceData> loadedResources;
|
||||
a(loadedResources);
|
||||
for(auto& [netID, rData] : loadedResources)
|
||||
resourceList.emplace_back(world.netObjMan.make_obj_direct_with_specific_id<ResourceData>(netID, rData));
|
||||
}
|
||||
|
||||
void ResourceManager::save_file(cereal::PortableBinaryOutputArchive& a) const {
|
||||
std::unordered_set<NetworkingObjects::NetObjID> usedResources;
|
||||
world.drawProg.get_used_resources(usedResources);
|
||||
std::unordered_map<NetworkingObjects::NetObjID, ResourceData> strippedResources;
|
||||
for(auto& n : resourceList)
|
||||
strippedResources.emplace(n.get_net_id(), *n);
|
||||
std::erase_if(strippedResources, [&](const auto& p) {
|
||||
return !usedResources.contains(p.first);
|
||||
});
|
||||
a(strippedResources);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "ResourceDisplay/ResourceDisplay.hpp"
|
||||
#include <Helpers/Networking/NetLibrary.hpp>
|
||||
#include <Helpers/NetworkingObjects/NetObjUnorderedSet.hpp>
|
||||
#include <Helpers/VersionNumber.hpp>
|
||||
|
||||
class World;
|
||||
|
||||
|
|
@ -33,6 +34,9 @@ class ResourceManager {
|
|||
float get_resource_retrieval_progress(const NetworkingObjects::NetObjID& id);
|
||||
std::unordered_map<NetworkingObjects::NetObjID, ResourceData> copy_resource_set_to_map(const std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
|
||||
|
||||
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
||||
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||
|
||||
World& world;
|
||||
private:
|
||||
std::unordered_map<NetworkingObjects::NetObjID, std::unique_ptr<ResourceDisplay>> displays;
|
||||
|
|
|
|||
|
|
@ -433,6 +433,7 @@ void World::save_file(cereal::PortableBinaryOutputArchive& a) const {
|
|||
drawProg.save_file(a);
|
||||
bMan.save_file(a);
|
||||
gridMan.save_file(a);
|
||||
rMan.save_file(a);
|
||||
}
|
||||
|
||||
void World::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) {
|
||||
|
|
@ -441,6 +442,7 @@ void World::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber versi
|
|||
drawProg.load_file(a, version);
|
||||
bMan.load_file(a, version);
|
||||
gridMan.load_file(a, version);
|
||||
rMan.load_file(a, version);
|
||||
}
|
||||
|
||||
WorldScalar World::calculate_zoom_from_uniform_zoom(WorldScalar uniformZoom, WorldVec oldWindowSize) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue