MayaFlux 0.4.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 672 of file Decoder.cpp.

674{
675 ReconstructionResult total;
676
677 const std::string tapestry_path = base_dir + "/tapestry.json";
678 IO::JSONSerializer ser;
679 auto schema_opt = ser.read<State::TapestrySchema>(tapestry_path);
680 if (!schema_opt) {
681 m_last_error = "Failed to load tapestry schema: " + ser.last_error();
683 return total;
684 }
685 const auto& schema = *schema_opt;
686
687 for (const auto& ref : schema.fabrics) {
688 auto fabric = tapestry.get_fabric(ref.name);
689 if (!fabric) {
690 fabric = tapestry.create_fabric(ref.name);
691 }
692 auto result = reconstruct(*fabric, ref.base_path);
693 total.constructed += result.constructed;
694 total.patched += result.patched;
695 total.skipped += result.skipped;
696 for (auto& w : result.warnings)
697 total.warnings.push_back(ref.name + ": " + std::move(w));
698 }
699
700 for (const auto& xrec : schema.expanses) {
701 if (xrec.fn_name.empty()) {
702 total.warnings.push_back("TapestryExpanse '" + xrec.name + "': no fn_name, skipping");
703 continue;
704 }
705 Expanse::ContainsFn contains_fn;
706 Expanse::CrossingFn on_enter_fn;
707 Expanse::CrossingFn on_exit_fn;
708
709 for (const auto& fname : xrec.fabric_names) {
710 auto fabric = tapestry.get_fabric(fname);
711 if (!fabric)
712 continue;
713 if (!contains_fn) {
714 if (auto ptr = fabric->resolve_expanse_fn(xrec.fn_name); ptr && *ptr)
715 contains_fn = *ptr;
716 }
717 if (!on_enter_fn && !xrec.on_enter_fn_name.empty()) {
718 if (auto ptr = fabric->resolve_crossing_fn(xrec.on_enter_fn_name); ptr && *ptr)
719 on_enter_fn = *ptr;
720 }
721 if (!on_exit_fn && !xrec.on_exit_fn_name.empty()) {
722 if (auto ptr = fabric->resolve_crossing_fn(xrec.on_exit_fn_name); ptr && *ptr)
723 on_exit_fn = *ptr;
724 }
725 }
726
727 if (!contains_fn) {
728 total.warnings.push_back("TapestryExpanse '" + xrec.name
729 + "': fn '" + xrec.fn_name + "' not resolved, skipping");
730 continue;
731 }
732
733 auto expanse = tapestry.create_expanse(
734 xrec.name,
735 std::move(contains_fn),
736 std::move(on_enter_fn),
737 std::move(on_exit_fn));
738
739 for (const auto& fname : xrec.fabric_names) {
740 if (auto fabric = tapestry.get_fabric(fname))
741 fabric->add_expanse(expanse);
742 }
743 ++total.constructed;
744 }
745
746 total.user_state = schema.user_state;
747
749 "StateDecoder::reconstruct(Tapestry): constructed={} patched={} skipped={} warnings={}",
750 total.constructed, total.patched, total.skipped, total.warnings.size());
751 return total;
752}
#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:337
@ 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: