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

◆ encode() [2/2]

bool MayaFlux::Nexus::StateEncoder::encode ( const Tapestry tapestry,
const std::string &  base_dir,
nlohmann::json  user_state = {} 
)

Encode all Fabrics in tapestry to base_dir.

Writes one EXR+JSON pair per Fabric under base_dir/{fabric_name_or_id}, then writes base_dir/tapestry.json as the envelope.

Parameters
tapestrySource Tapestry.
base_dirDirectory path. Must exist.
Returns
True on success.

Definition at line 407 of file Encoder.cpp.

408{
409 m_last_error.clear();
410
411 State::TapestrySchema schema;
412
413 for (const auto& fabric : tapestry.all_fabrics()) {
414 const std::string fabric_id = fabric->name().empty()
415 ? std::to_string(fabric->id())
416 : fabric->name();
417
418 const std::string base_path = base_dir + "/" + fabric_id;
419
420 if (!encode(*fabric, base_path)) {
421 return false;
422 }
423
424 schema.fabrics.push_back(State::FabricRef {
425 .name = fabric_id,
426 .base_path = base_path,
427 });
428 }
429
430 for (const auto& [xname, xptr] : tapestry.all_expanses()) {
431 State::TapestryExpanseRecord xrec {
432 .name = xname,
433 .fn_name = xptr->fn_name(),
434 .on_enter_fn_name = xptr->on_enter_fn_name(),
435 .on_exit_fn_name = xptr->on_exit_fn_name(),
436 };
437 for (const auto& fabric : tapestry.all_fabrics()) {
438 for (uint32_t xid : fabric->all_expanse_ids()) {
439 if (fabric->get_expanse(xid) == xptr) {
440 const std::string fname = fabric->name().empty()
441 ? std::to_string(fabric->id())
442 : fabric->name();
443 xrec.fabric_names.push_back(fname);
444 break;
445 }
446 }
447 }
448 schema.expanses.push_back(std::move(xrec));
449 }
450
451 schema.user_state = std::move(user_state);
452
453 IO::JSONSerializer ser;
454 const std::string tapestry_path = base_dir + "/tapestry.json";
455 if (!ser.write(tapestry_path, schema)) {
456 m_last_error = "Failed to write tapestry schema: " + ser.last_error();
458 return false;
459 }
460
462 "StateEncoder: wrote {} fabrics to {}", schema.fabrics.size(), tapestry_path);
463 return true;
464}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
bool encode(const Fabric &fabric, const std::string &base_path)
Encode the given Fabric to {base_path}.exr and {base_path}.json.
Definition Encoder.cpp:91
@ FileIO
Filesystem I/O operations.
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.

References MayaFlux::Nexus::Tapestry::all_expanses(), MayaFlux::Nexus::Tapestry::all_fabrics(), MayaFlux::Nexus::State::TapestrySchema::expanses, MayaFlux::Nexus::State::TapestrySchema::fabrics, MayaFlux::Journal::FileIO, MayaFlux::IO::JSONSerializer::last_error(), MF_ERROR, MF_INFO, MayaFlux::Nexus::State::FabricRef::name, MayaFlux::Nexus::State::TapestryExpanseRecord::name, MayaFlux::Journal::Nexus, MayaFlux::Nexus::State::TapestrySchema::user_state, and MayaFlux::IO::JSONSerializer::write().

+ Here is the call graph for this function: