2021-01-30 22:39:06 +01:00
|
|
|
#pragma once
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <hex.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>
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <string_view>
|
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:
|
2021-09-08 15:18:24 +02:00
|
|
|
Node(std::string unlocalizedTitle, std::vector<Attribute> attributes);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
virtual ~Node() = default;
|
|
|
|
|
2022-10-06 09:14:46 +02:00
|
|
|
[[nodiscard]] int getId() const { return this->m_id; }
|
|
|
|
void setId(int id) { this->m_id = id; }
|
2021-05-17 23:17:58 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] const std::string &getUnlocalizedName() const { return this->m_unlocalizedName; }
|
2021-09-08 15:18:24 +02:00
|
|
|
void setUnlocalizedName(const std::string &unlocalizedName) { this->m_unlocalizedName = unlocalizedName; }
|
2021-05-17 23:17:58 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] const std::string &getUnlocalizedTitle() const { return this->m_unlocalizedTitle; }
|
|
|
|
[[nodiscard]] std::vector<Attribute> &getAttributes() { return this->m_attributes; }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void setCurrentOverlay(prv::Overlay *overlay) {
|
|
|
|
this->m_overlay = overlay;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
virtual void store(nlohmann::json &j) { hex::unused(j); }
|
|
|
|
virtual void load(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() {
|
|
|
|
for (auto &attribute : this->m_attributes)
|
|
|
|
attribute.getOutputData().reset();
|
|
|
|
}
|
|
|
|
|
2021-03-07 13:20:33 +01:00
|
|
|
void resetProcessedInputs() {
|
|
|
|
this->m_processedInputs.clear();
|
|
|
|
}
|
|
|
|
|
2022-10-06 09:14:46 +02:00
|
|
|
void setPosition(ImVec2 pos) {
|
|
|
|
this->m_position = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getPosition() const {
|
|
|
|
return this->m_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setIdCounter(int id) {
|
2022-02-01 18:09:40 +01:00
|
|
|
if (id > Node::s_idCounter)
|
|
|
|
Node::s_idCounter = id;
|
|
|
|
}
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
private:
|
2022-10-06 09:14:46 +02:00
|
|
|
int m_id;
|
2021-05-17 23:17:58 +02:00
|
|
|
std::string 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
|
|
|
|
2022-10-06 09:14:46 +02:00
|
|
|
static int s_idCounter;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
Attribute *getConnectedInputAttribute(u32 index) {
|
2021-01-31 16:11:25 +01:00
|
|
|
if (index >= this->getAttributes().size())
|
|
|
|
throw std::runtime_error("Attribute index out of bounds!");
|
|
|
|
|
|
|
|
auto &connectedAttribute = this->getAttributes()[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) {
|
|
|
|
const auto &[iter, inserted] = this->m_processedInputs.insert(index);
|
|
|
|
if (!inserted)
|
|
|
|
throwNodeError("Recursion detected!");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
std::vector<u8> getBufferOnInput(u32 index);
|
2022-10-26 08:54:08 +02:00
|
|
|
i128 getIntegerOnInput(u32 index);
|
|
|
|
long double getFloatOnInput(u32 index);
|
2021-02-04 01:14:05 +01:00
|
|
|
|
2022-03-04 20:52:39 +01:00
|
|
|
void setBufferOnOutput(u32 index, const std::vector<u8> &data);
|
2022-10-26 08:54:08 +02:00
|
|
|
void setIntegerOnOutput(u32 index, i128 integer);
|
|
|
|
void setFloatOnOutput(u32 index, long double floatingPoint);
|
2021-01-31 16:11:25 +01:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
void setOverlayData(u64 address, const std::vector<u8> &data);
|
2021-01-30 22:39:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|