2026-05-11 23:06:39 +03:00
|
|
|
/*
|
|
|
|
|
* InfiniPaint
|
|
|
|
|
* Copyright (C) 2025-2026 Yousef Khadadeh
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-12-13 13:03:27 +03:00
|
|
|
#include "CanvasComponentAllocator.hpp"
|
2025-12-14 18:57:40 +03:00
|
|
|
#include "CanvasComponentContainer.hpp"
|
|
|
|
|
#include "../DrawingProgram/DrawingProgram.hpp"
|
2026-10-25 18:07:47 +01:00
|
|
|
#include "../DrawingProgram/Layers/DrawingProgramLayerListItem.hpp"
|
2025-12-15 15:36:42 +03:00
|
|
|
#include "../World.hpp"
|
|
|
|
|
#include <Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp>
|
|
|
|
|
#include "CanvasComponent.hpp"
|
2025-12-13 13:03:27 +03:00
|
|
|
|
|
|
|
|
CanvasComponentAllocator::CanvasComponentAllocator() {}
|
|
|
|
|
|
2025-12-15 15:36:42 +03:00
|
|
|
CanvasComponentAllocator::CanvasComponentAllocator(CanvasComponentType typeToAllocate) {
|
2025-12-13 13:03:27 +03:00
|
|
|
comp = std::unique_ptr<CanvasComponent>(CanvasComponent::allocate_comp(typeToAllocate));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 12:42:27 +03:00
|
|
|
void CanvasComponentAllocator::register_class(World& world) {
|
|
|
|
|
world.delayedUpdateObjectManager.register_class<CanvasComponentAllocator>(world.netObjMan, NetworkingObjects::DelayUpdateSerializedClassManager::CustomConstructors<CanvasComponentAllocator>{
|
2025-12-14 18:57:40 +03:00
|
|
|
.writeConstructor = [](const CanvasComponentAllocator& o, cereal::PortableBinaryOutputArchive& a) {
|
|
|
|
|
a(o.comp->get_type());
|
|
|
|
|
a(*o.comp);
|
|
|
|
|
},
|
2025-12-31 16:30:56 +03:00
|
|
|
.readConstructor = [](CanvasComponentAllocator& o, cereal::PortableBinaryInputArchive& a, const std::shared_ptr<NetServer::ClientData>& c) {
|
2025-12-15 15:36:42 +03:00
|
|
|
CanvasComponentType typeToAllocate;
|
2025-12-14 18:57:40 +03:00
|
|
|
a(typeToAllocate);
|
|
|
|
|
o.comp = std::unique_ptr<CanvasComponent>(CanvasComponent::allocate_comp(typeToAllocate));
|
|
|
|
|
a(*o.comp);
|
|
|
|
|
},
|
|
|
|
|
.writeUpdate = [](const CanvasComponentAllocator& o, cereal::PortableBinaryOutputArchive& a) {
|
|
|
|
|
a(*o.comp);
|
|
|
|
|
},
|
2025-12-31 16:30:56 +03:00
|
|
|
.readUpdate = [](CanvasComponentAllocator& o, cereal::PortableBinaryInputArchive& a, const std::shared_ptr<NetServer::ClientData>& c) {
|
2026-10-25 18:07:47 +01:00
|
|
|
// Host rejects client edits of fog/locked-layer components (still consume the payload).
|
|
|
|
|
if(c && o.comp && o.comp->compContainer && o.comp->compContainer->parentLayer
|
|
|
|
|
&& o.comp->compContainer->parentLayer->is_player_edit_blocked()) {
|
|
|
|
|
auto junk = std::unique_ptr<CanvasComponent>(CanvasComponent::allocate_comp(o.comp->get_type()));
|
|
|
|
|
a(*junk);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-12-14 18:57:40 +03:00
|
|
|
a(*o.comp);
|
|
|
|
|
},
|
|
|
|
|
.allocateCopy = [](const CanvasComponentAllocator& o) {
|
|
|
|
|
auto theCopy = std::make_shared<CanvasComponentAllocator>();
|
|
|
|
|
theCopy->comp = std::unique_ptr<CanvasComponent>(CanvasComponent::allocate_comp(o.comp->get_type()));
|
|
|
|
|
// Maybe do an assignment here
|
|
|
|
|
return theCopy;
|
|
|
|
|
},
|
|
|
|
|
.assignmentFunc = [](CanvasComponentAllocator& o, const CanvasComponentAllocator& o2) {
|
2025-12-15 15:36:42 +03:00
|
|
|
o.comp->set_data_from(*o2.comp);
|
2025-12-14 18:57:40 +03:00
|
|
|
},
|
2025-12-15 15:36:42 +03:00
|
|
|
.postUpdateFunc = [&drawP = world.drawProg](CanvasComponentAllocator& o) {
|
2025-12-14 18:57:40 +03:00
|
|
|
o.comp->compContainer->commit_update(drawP);
|
2026-10-25 18:07:47 +01:00
|
|
|
// Fog mesh reshape / content edit can change who is fully covered.
|
|
|
|
|
drawP.layerMan.mark_fog_client_projection_dirty();
|
2025-12-14 18:57:40 +03:00
|
|
|
}
|
2025-12-13 13:03:27 +03:00
|
|
|
});
|
|
|
|
|
}
|
2026-01-01 22:46:02 +03:00
|
|
|
|
|
|
|
|
void CanvasComponentAllocator::save_file(cereal::PortableBinaryOutputArchive& a) const {
|
|
|
|
|
a(comp->get_type());
|
|
|
|
|
comp->save_file(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CanvasComponentAllocator::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) {
|
|
|
|
|
CanvasComponentType t;
|
|
|
|
|
a(t);
|
|
|
|
|
comp = std::unique_ptr<CanvasComponent>(CanvasComponent::allocate_comp(t));
|
|
|
|
|
comp->load_file(a, version);
|
|
|
|
|
}
|