Serialization works in new version

This commit is contained in:
Yousef Khadadeh 2025-11-16 16:39:12 +03:00
parent 6b3ce01e94
commit 79f7135746
23 changed files with 186 additions and 56 deletions

View file

@ -174,7 +174,7 @@ void DrawingProgram::parallel_loop_all_components(std::function<void(const std::
parallel_loop_container(components.client_list(), func);
}
std::unordered_set<ServerClientID> DrawingProgram::get_used_resources() {
std::unordered_set<ServerClientID> DrawingProgram::get_used_resources() const {
std::unordered_set<ServerClientID> toRet;
for(auto& c : components.client_list())
c->obj->get_used_resources(toRet);
@ -559,6 +559,23 @@ void DrawingProgram::initialize_draw_data(cereal::PortableBinaryInputArchive& a)
compCache.test_rebuild(components.client_list(), true);
}
void DrawingProgram::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) {
uint64_t compCount;
a(compCount);
for(uint64_t i = 0; i < compCount; i++) {
DrawComponentType t;
a(t);
auto newComp = DrawComponent::allocate_comp_type(t);
a(newComp->id, newComp->coords);
newComp->load_file(a, version);
components.init_emplace_back(newComp);
}
parallel_loop_all_components([&](const auto& c){
c->obj->commit_update(*this, false);
});
compCache.test_rebuild(components.client_list(), true);
}
void DrawingProgram::client_erase_set(std::unordered_set<CollabListType::ObjectInfoPtr> erasedComponents) {
std::unordered_set<ServerClientID> idsToErase;
for(auto& c : erasedComponents)
@ -687,11 +704,12 @@ void DrawingProgram::draw_drag_circle(SkCanvas* canvas, const Vector2f& sPos, co
canvas->drawCircle(sPos.x(), sPos.y(), constantRadius, paintOutline);
}
void DrawingProgram::write_to_file(cereal::PortableBinaryOutputArchive& a) {
void DrawingProgram::save_file(cereal::PortableBinaryOutputArchive& a) const {
auto& cList = components.client_list();
a((uint64_t)cList.size());
for(size_t i = 0; i < cList.size(); i++) {
a(cList[i]->obj->get_type(), cList[i]->obj->id, cList[i]->obj->coords, *cList[i]->obj);
a(cList[i]->obj->get_type(), cList[i]->obj->id, cList[i]->obj->coords);
cList[i]->obj->save_file(a);
}
}

View file

@ -30,10 +30,13 @@ class DrawingProgram {
void update();
void scale_up(const WorldScalar& scaleUpAmount);
void draw(SkCanvas* canvas, const DrawData& drawData);
void initialize_draw_data(cereal::PortableBinaryInputArchive& a);
std::unordered_set<ServerClientID> get_used_resources();
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
std::unordered_set<ServerClientID> get_used_resources() const;
ClientPortionID get_max_id(ServerPortionID serverID);
void write_to_file(cereal::PortableBinaryOutputArchive& a);
void save_file(cereal::PortableBinaryOutputArchive& a) const;
World& world;
bool prevent_undo_or_redo();