MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ reconstruct() [2/2]

StateDecoder::ReconstructionResult MayaFlux::Nexus::StateDecoder::reconstruct ( Tapestry tapestry,
const std::string &  base_dir 
)

Reconstruct all Fabrics in tapestry from base_dir.

Reads tapestry.json, creates or finds Fabrics by name, calls reconstruct(fabric, base_path) for each, then restores Tapestry-level named Expanses and registers them on the listed Fabrics.

Parameters
tapestryTarget Tapestry. May be empty or partially populated.
base_dirDirectory path matching the one passed to encode().
Returns
ReconstructionResult aggregated across all Fabrics.

Definition at line 679 of file Decoder.cpp.

681{
682 ReconstructionResult total;
683
684 const std::string tapestry_path = base_dir + "/tapestry.json";
685 IO::JSONSerializer ser;
686 auto schema_opt = ser.read<State::TapestrySchema>(tapestry_path);
687 if (!schema_opt) {
688 m_last_error = "Failed to load tapestry schema: " + ser.last_error();
690 return total;
691 }
692 const auto& schema = *schema_opt;
693
694 for (const auto& ref : schema.fabrics) {
695 auto fabric = tapestry.get_fabric(ref.name);
696 if (!fabric) {
697 fabric = tapestry.create_fabric(ref.name);
698 }
699 auto result = reconstruct(*fabric, ref.base_path);
700 total.constructed += result.constructed;
701 total.patched += result.patched;
702 total.skipped += result.skipped;
703 for (auto& w : result.warnings)
704 total.warnings.push_back(ref.name + ": " + std::move(w));
705 }
706
707 for (const auto& xrec : schema.expanses) {
708 if (xrec.fn_name.empty()) {
709 total.warnings.push_back("TapestryExpanse '" + xrec.name + "': no fn_name, skipping");
710 continue;
711 }
712 Expanse::ContainsFn contains_fn;
713 Expanse::CrossingFn on_enter_fn;
714 Expanse::CrossingFn on_exit_fn;
715
716 for (const auto& fname : xrec.fabric_names) {
717 auto fabric = tapestry.get_fabric(fname);
718 if (!fabric)
719 continue;
720 if (!contains_fn) {
721 if (auto ptr = fabric->resolve_expanse_fn(xrec.fn_name); ptr && *ptr)
722 contains_fn = *ptr;
723 }
724 if (!on_enter_fn && !xrec.on_enter_fn_name.empty()) {
725 if (auto ptr = fabric->resolve_crossing_fn(xrec.on_enter_fn_name); ptr && *ptr)
726 on_enter_fn = *ptr;
727 }
728 if (!on_exit_fn && !xrec.on_exit_fn_name.empty()) {
729 if (auto ptr = fabric->resolve_crossing_fn(xrec.on_exit_fn_name); ptr && *ptr)
730 on_exit_fn = *ptr;
731 }
732 }
733
734 if (!contains_fn) {
735 total.warnings.push_back("TapestryExpanse '" + xrec.name
736 + "': fn '" + xrec.fn_name + "' not resolved, skipping");
737 continue;
738 }
739
740 auto expanse = tapestry.create_expanse(
741 xrec.name,
742 std::move(contains_fn),
743 std::move(on_enter_fn),
744 std::move(on_exit_fn));
745
746 for (const auto& fname : xrec.fabric_names) {
747 if (auto fabric = tapestry.get_fabric(fname))
748 fabric->add_expanse(expanse);
749 }
750 ++total.constructed;
751 }
752
753 total.user_state = schema.user_state;
754
756 "StateDecoder::reconstruct(Tapestry): constructed={} patched={} skipped={} warnings={}",
757 total.constructed, total.patched, total.skipped, total.warnings.size());
758 return total;
759}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
const uint8_t * ptr
std::function< void(uint32_t)> CrossingFn
Definition Expanse.hpp:34
std::function< bool(const glm::vec3 &)> ContainsFn
Definition Expanse.hpp:33
ReconstructionResult reconstruct(Fabric &fabric, const std::string &base_path)
Patch existing entities and construct missing ones from schema.
Definition Decoder.cpp:344
@ FileIO
Filesystem I/O operations.
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.

References MayaFlux::Nexus::StateDecoder::ReconstructionResult::constructed, MayaFlux::Nexus::Tapestry::create_expanse(), MayaFlux::Nexus::Tapestry::create_fabric(), MayaFlux::Journal::FileIO, MayaFlux::Nexus::Tapestry::get_fabric(), MayaFlux::IO::JSONSerializer::last_error(), m_last_error, MF_ERROR, MF_INFO, MayaFlux::Journal::Nexus, MayaFlux::Nexus::StateDecoder::ReconstructionResult::patched, ptr, MayaFlux::IO::JSONSerializer::read(), reconstruct(), MayaFlux::Nexus::StateDecoder::ReconstructionResult::skipped, MayaFlux::Nexus::StateDecoder::ReconstructionResult::user_state, and MayaFlux::Nexus::StateDecoder::ReconstructionResult::warnings.

+ Here is the call graph for this function: