MayaFlux 0.5.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 413 of file Encoder.cpp.

414{
415 m_last_error.clear();
416
417 State::TapestrySchema schema;
418
419 for (const auto& fabric : tapestry.all_fabrics()) {
420 const std::string fabric_id = fabric->name().empty()
421 ? std::to_string(fabric->id())
422 : fabric->name();
423
424 const std::string base_path = base_dir + "/" + fabric_id;
425
426 if (!encode(*fabric, base_path)) {
427 return false;
428 }
429
430 schema.fabrics.push_back(State::FabricRef {
431 .name = fabric_id,
432 .base_path = base_path,
433 });
434 }
435
436 for (const auto& [xname, xptr] : tapestry.all_expanses()) {
437 State::TapestryExpanseRecord xrec {
438 .name = xname,
439 .fn_name = xptr->fn_name(),
440 .on_enter_fn_name = xptr->on_enter_fn_name(),
441 .on_exit_fn_name = xptr->on_exit_fn_name(),
442 };
443 for (const auto& fabric : tapestry.all_fabrics()) {
444 for (uint32_t xid : fabric->all_expanse_ids()) {
445 if (fabric->get_expanse(xid) == xptr) {
446 const std::string fname = fabric->name().empty()
447 ? std::to_string(fabric->id())
448 : fabric->name();
449 xrec.fabric_names.push_back(fname);
450 break;
451 }
452 }
453 }
454 schema.expanses.push_back(std::move(xrec));
455 }
456
457 schema.user_state = std::move(user_state);
458
459 IO::JSONSerializer ser;
460 const std::string tapestry_path = base_dir + "/tapestry.json";
461 if (!ser.write(tapestry_path, schema)) {
462 m_last_error = "Failed to write tapestry schema: " + ser.last_error();
464 return false;
465 }
466
468 "StateEncoder: wrote {} fabrics to {}", schema.fabrics.size(), tapestry_path);
469 return true;
470}
#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:97
@ 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: