MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Encoder.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include "Schema.hpp"
6
7namespace MayaFlux::Nexus {
8
9/**
10 * @class StateEncoder
11 * @brief Serializes Fabric state to an EXR texture and JSON schema.
12 *
13 * v1 scope: encodes all three Kinds (Emitter, Sensor, Agent) that have a
14 * position set. Output:
15 * {base}.exr RGBA32F, width=N entities, height=3 rows:
16 * row 0: position.xyz, intensity
17 * row 1: color.rgb, size
18 * row 2: radius, query_radius, 0, 0
19 * {base}.json Schema v2 with per-entity records (id, kind, fields) and
20 * per-channel ranges for denormalization.
21 *
22 * Entities without a position are skipped. Unnamed callables emit a warning
23 * but are still encoded. Optional fields (color, size) are written as null
24 * in the schema; the EXR channels are zeroed but the decoder ignores them.
25 */
26class MAYAFLUX_API StateEncoder {
27public:
28 StateEncoder() = default;
29 ~StateEncoder() = default;
30
31 StateEncoder(const StateEncoder&) = delete;
35
36 /**
37 * @brief Encode the given Fabric to {base_path}.exr and {base_path}.json.
38 * @param fabric Source of entity state. Only Emitters with a position
39 * are encoded in v0.
40 * @param base_path Path stem without extension.
41 * @return True on success. On failure call last_error().
42 */
43 [[nodiscard]] bool encode(const Fabric& fabric, const std::string& base_path);
44
45 /**
46 * @brief Encode all Fabrics in @p tapestry to @p base_dir.
47 *
48 * Writes one EXR+JSON pair per Fabric under base_dir/{fabric_name_or_id},
49 * then writes base_dir/tapestry.json as the envelope.
50 *
51 * @param tapestry Source Tapestry.
52 * @param base_dir Directory path. Must exist.
53 * @return True on success.
54 */
55 [[nodiscard]] bool encode(const Tapestry& tapestry, const std::string& base_dir, nlohmann::json user_state = {});
56
57 /**
58 * @brief Last error message, empty if no error.
59 */
60 [[nodiscard]] const std::string& last_error() const { return m_last_error; }
61
62private:
63 std::string m_last_error;
64};
65
66} // namespace MayaFlux::Nexus
Orchestrates spatial indexing and scheduling for Nexus objects.
Definition Fabric.hpp:38
StateEncoder & operator=(const StateEncoder &)=delete
const std::string & last_error() const
Last error message, empty if no error.
Definition Encoder.hpp:60
StateEncoder & operator=(StateEncoder &&)=default
StateEncoder(const StateEncoder &)=delete
StateEncoder(StateEncoder &&)=default
Serializes Fabric state to an EXR texture and JSON schema.
Definition Encoder.hpp:26
Owner of one or more Fabrics and the shared state they rely on.
Definition Tapestry.hpp:25