Enzo
Loading...
Searching...
No Matches
NodeSnapshot.h
1#pragma once
2#include "Engine/Core/Path.h"
3#include "Engine/Core/Types.h"
4#include "Engine/Serializer/ParameterSerializable.h"
5#include <cereal/cereal.hpp>
6#include <cereal/types/vector.hpp>
7#include <string>
8#include <vector>
9
10namespace enzo::nt {
11class Node;
12
25{
26 public:
28 static NodeSnapshot capture(Node& node);
29
33 void restore(NodeId nodeId) const;
34
36 const Path& getPath() const { return path_; }
37
38 private:
39 friend class cereal::access;
40
41 template <class Archive> void save(Archive& archive) const
42 {
43 archive(
44 cereal::make_nvp("typeName", typeName_),
45 cereal::make_nvp("path", path_.getString()),
46 cereal::make_nvp("posX", position_.x()),
47 cereal::make_nvp("posY", position_.y()),
48 cereal::make_nvp("parameters", parameters_)
49 );
50 }
51
52 template <class Archive> void load(Archive& archive)
53 {
54 std::string path;
55 float posX = 0;
56 float posY = 0;
57 archive(
58 cereal::make_nvp("typeName", typeName_),
59 cereal::make_nvp("path", path),
60 cereal::make_nvp("posX", posX),
61 cereal::make_nvp("posY", posY),
62 cereal::make_nvp("parameters", parameters_)
63 );
64 path_ = Path(path);
65 position_ = {posX, posY};
66 }
67
68 std::string typeName_;
69 Path path_;
70 Vector2 position_ = {0.f, 0.f};
71 std::vector<ParameterSerializable> parameters_;
72};
73} // namespace enzo::nt
Basic attribute, parameter, and node types for Enzo.
uint64_t NodeId
The unique ID assigned to each node in the network.
Definition Types.h:306
A default path class for creation and manipulation of tree-based paths.
Definition Path.h:14
const std::string & getString() const
Return the path of the Path as an std::string.
Definition Path.cpp:161
Everything one node carries, held apart from the network so it can be rebuilt.
Definition NodeSnapshot.h:25
const Path & getPath() const
Returns the path the node sat at, whose leaf is the node name.
Definition NodeSnapshot.h:36
void restore(NodeId nodeId) const
Rebuilds the node under the given id with the path, position, and parameters it had.
Definition NodeSnapshot.cpp:22
static NodeSnapshot capture(Node &node)
Returns a snapshot of the node as it stands.
Definition NodeSnapshot.cpp:8
The unique runtime representation of a node.
Definition Node.h:18