2021-01-30 22:39:06 +01:00
|
|
|
#pragma once
|
2023-11-10 20:47:08 +01:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <hex.hpp>
|
2023-12-19 12:22:28 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
#include <hex/helpers/intrinsics.hpp>
|
2021-01-30 22:39:06 +01:00
|
|
|
#include <hex/data_processor/attribute.hpp>
|
|
|
|
|
2021-03-07 13:20:33 +01:00
|
|
|
#include <set>
|
2023-03-12 18:27:29 +01:00
|
|
|
#include <span>
|
2021-03-07 13:20:33 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2022-10-06 09:14:46 +02:00
|
|
|
#include <imgui.h>
|
2021-08-29 14:18:45 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
namespace hex::prv {
|
|
|
|
class Provider;
|
|
|
|
class Overlay;
|
|
|
|
}
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
namespace hex::dp {
|
|
|
|
|
|
|
|
class Node {
|
|
|
|
public:
|
2023-12-19 12:22:28 +01:00
|
|
|
Node(UnlocalizedString unlocalizedTitle, std::vector<Attribute> attributes);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
virtual ~Node() = default;
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] int getId() const { return m_id; }
|
|
|
|
void setId(int id) { m_id = id; }
|
2021-05-17 23:17:58 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] const UnlocalizedString &getUnlocalizedName() const { return m_unlocalizedName; }
|
|
|
|
void setUnlocalizedName(const UnlocalizedString &unlocalizedName) { m_unlocalizedName = unlocalizedName; }
|
2021-05-17 23:17:58 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] const UnlocalizedString &getUnlocalizedTitle() const { return m_unlocalizedTitle; }
|
|
|
|
void setUnlocalizedTitle(std::string title) { m_unlocalizedTitle = std::move(title); }
|
2023-02-09 23:07:04 +01:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] std::vector<Attribute> &getAttributes() { return m_attributes; }
|
|
|
|
[[nodiscard]] const std::vector<Attribute> &getAttributes() const { return m_attributes; }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void setCurrentOverlay(prv::Overlay *overlay) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_overlay = overlay;
|
2021-01-31 16:11:25 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
virtual void drawNode() { }
|
2021-01-31 16:11:25 +01:00
|
|
|
virtual void process() = 0;
|
2021-02-04 01:14:05 +01:00
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
virtual void store(nlohmann::json &j) const { hex::unused(j); }
|
|
|
|
virtual void load(const nlohmann::json &j) { hex::unused(j); }
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
struct NodeError {
|
|
|
|
Node *node;
|
|
|
|
std::string message;
|
|
|
|
};
|
2021-02-04 01:14:05 +01:00
|
|
|
|
|
|
|
void resetOutputData() {
|
2023-12-19 13:10:25 +01:00
|
|
|
for (auto &attribute : m_attributes)
|
2023-02-12 17:33:53 +01:00
|
|
|
attribute.clearOutputData();
|
2021-02-04 01:14:05 +01:00
|
|
|
}
|
|
|
|
|
2021-03-07 13:20:33 +01:00
|
|
|
void resetProcessedInputs() {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_processedInputs.clear();
|
2021-03-07 13:20:33 +01:00
|
|
|
}
|
|
|
|
|
2022-10-06 09:14:46 +02:00
|
|
|
void setPosition(ImVec2 pos) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_position = pos;
|
2022-10-06 09:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getPosition() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_position;
|
2022-10-06 09:14:46 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 13:50:51 +02:00
|
|
|
static void setIdCounter(int id);
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-02-12 17:33:53 +01:00
|
|
|
const std::vector<u8>& getBufferOnInput(u32 index);
|
|
|
|
const i128& getIntegerOnInput(u32 index);
|
2023-09-20 10:48:44 +02:00
|
|
|
const double& getFloatOnInput(u32 index);
|
2023-02-09 23:07:04 +01:00
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
void setBufferOnOutput(u32 index, std::span<const u8> data);
|
2023-02-09 23:07:04 +01:00
|
|
|
void setIntegerOnOutput(u32 index, i128 integer);
|
2023-09-20 10:48:44 +02:00
|
|
|
void setFloatOnOutput(u32 index, double floatingPoint);
|
2023-02-09 23:07:04 +01:00
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
private:
|
2022-10-06 09:14:46 +02:00
|
|
|
int m_id;
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString m_unlocalizedTitle, m_unlocalizedName;
|
2021-01-30 22:39:06 +01:00
|
|
|
std::vector<Attribute> m_attributes;
|
2021-03-07 13:20:33 +01:00
|
|
|
std::set<u32> m_processedInputs;
|
2021-01-31 16:11:25 +01:00
|
|
|
prv::Overlay *m_overlay = nullptr;
|
2022-10-06 09:14:46 +02:00
|
|
|
ImVec2 m_position;
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2023-11-30 10:22:15 +01:00
|
|
|
static int s_idCounter;
|
|
|
|
|
2023-02-12 17:33:53 +01:00
|
|
|
Attribute& getAttribute(u32 index) {
|
2021-01-31 16:11:25 +01:00
|
|
|
if (index >= this->getAttributes().size())
|
|
|
|
throw std::runtime_error("Attribute index out of bounds!");
|
|
|
|
|
2023-02-12 17:33:53 +01:00
|
|
|
return this->getAttributes()[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
Attribute *getConnectedInputAttribute(u32 index) {
|
|
|
|
const auto &connectedAttribute = this->getAttribute(index).getConnectedAttributes();
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
if (connectedAttribute.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return connectedAttribute.begin()->second;
|
|
|
|
}
|
2021-01-31 16:11:25 +01:00
|
|
|
|
2021-03-07 13:20:33 +01:00
|
|
|
void markInputProcessed(u32 index) {
|
2023-12-19 13:10:25 +01:00
|
|
|
const auto &[iter, inserted] = m_processedInputs.insert(index);
|
2021-03-07 13:20:33 +01:00
|
|
|
if (!inserted)
|
|
|
|
throwNodeError("Recursion detected!");
|
|
|
|
}
|
|
|
|
|
2023-10-19 23:34:05 +02:00
|
|
|
void unmarkInputProcessed(u32 index) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_processedInputs.erase(index);
|
2023-10-19 23:34:05 +02:00
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
protected:
|
2021-09-08 15:18:24 +02:00
|
|
|
[[noreturn]] void throwNodeError(const std::string &message) {
|
2022-08-26 00:18:08 +02:00
|
|
|
throw NodeError { this, message };
|
2021-02-04 01:14:05 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void setOverlayData(u64 address, const std::vector<u8> &data);
|
2021-02-04 01:14:05 +01:00
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void setAttributes(std::vector<Attribute> attributes) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_attributes = std::move(attributes);
|
2021-01-31 16:11:25 +01:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
for (auto &attr : m_attributes)
|
2023-02-09 23:07:04 +01:00
|
|
|
attr.setParentNode(this);
|
|
|
|
}
|
2021-01-30 22:39:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|