sys: First attempt at reducing build times

This commit is contained in:
WerWolv
2021-08-29 14:18:45 +02:00
parent f60f9f9fc9
commit 02d31d2d2a
38 changed files with 2885 additions and 1535 deletions

View File

@@ -1,4 +1,7 @@
#pragma once
#include <hex.hpp>
#include <string_view>
namespace hex::dp {
@@ -16,14 +19,8 @@ namespace hex::dp {
In, Out
};
Attribute(IOType ioType, Type type, std::string_view unlocalizedName) : m_id(SharedData::dataProcessorAttrIdCounter++), m_ioType(ioType), m_type(type), m_unlocalizedName(unlocalizedName) {
}
~Attribute() {
for (auto &[linkId, attr] : this->getConnectedAttributes())
attr->removeConnectedAttribute(linkId);
}
Attribute(IOType ioType, Type type, std::string_view unlocalizedName);
~Attribute();
[[nodiscard]] u32 getID() const { return this->m_id; }
void setID(u32 id) { this->m_id = id; }

View File

@@ -1,10 +1,12 @@
#pragma once
#include <hex.hpp>
namespace hex::dp {
class Link {
public:
Link(u32 from, u32 to) : m_id(SharedData::dataProcessorLinkIdCounter++), m_from(from), m_to(to) { }
Link(u32 from, u32 to);
[[nodiscard]] u32 getID() const { return this->m_id; }
void setID(u32 id) { this->m_id = id; }

View File

@@ -1,20 +1,22 @@
#pragma once
#include <hex.hpp>
#include <hex/data_processor/attribute.hpp>
#include <hex/helpers/utils.hpp>
#include <set>
#include <string_view>
#include <vector>
#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>
namespace hex::prv { class Provider; class Overlay; }
namespace hex::dp {
class Node {
public:
Node(std::string_view unlocalizedTitle, std::vector<Attribute> attributes) : m_id(SharedData::dataProcessorNodeIdCounter++), m_unlocalizedTitle(unlocalizedTitle), m_attributes(std::move(attributes)) {
for (auto &attr : this->m_attributes)
attr.setParentNode(this);
}
Node(std::string_view unlocalizedTitle, std::vector<Attribute> attributes);
virtual ~Node() = default;
@@ -34,7 +36,7 @@ namespace hex::dp {
virtual void drawNode() { }
virtual void process() = 0;
virtual nlohmann::json store() { return nullptr; }
virtual void store(nlohmann::json &j) { }
virtual void load(nlohmann::json &j) { }
using NodeError = std::pair<Node*, std::string>;
@@ -79,121 +81,15 @@ namespace hex::dp {
throw NodeError(this, message);
}
std::vector<u8> getBufferOnInput(u32 index) {
auto attribute = this->getConnectedInputAttribute(index);
std::vector<u8> getBufferOnInput(u32 index);
u64 getIntegerOnInput(u32 index);
float getFloatOnInput(u32 index);
if (attribute == nullptr)
throwNodeError(hex::format("Nothing connected to input '{0}'", static_cast<const char*>(LangEntry(this->m_attributes[index].getUnlocalizedName()))));
void setBufferOnOutput(u32 index, std::vector<u8> data);
void setIntegerOnOutput(u32 index, u64 integer);
void setFloatOnOutput(u32 index, float floatingPoint);
if (attribute->getType() != Attribute::Type::Buffer)
throwNodeError("Tried to read buffer from non-buffer attribute");
markInputProcessed(index);
attribute->getParentNode()->process();
auto &outputData = attribute->getOutputData();
if (!outputData.has_value())
throw std::runtime_error("No data available at connected attribute");
return outputData.value();
}
u64 getIntegerOnInput(u32 index) {
auto attribute = this->getConnectedInputAttribute(index);
if (attribute == nullptr)
throwNodeError(hex::format("Nothing connected to input '{0}'", static_cast<const char*>(LangEntry(this->m_attributes[index].getUnlocalizedName()))));
if (attribute->getType() != Attribute::Type::Integer)
throwNodeError("Tried to read integer from non-integer attribute");
markInputProcessed(index);
attribute->getParentNode()->process();
auto &outputData = attribute->getOutputData();
if (!outputData.has_value())
throw std::runtime_error("No data available at connected attribute");
if (outputData->size() < sizeof(u64))
throw std::runtime_error("Not enough data provided for integer");
return *reinterpret_cast<u64*>(outputData->data());
}
float getFloatOnInput(u32 index) {
auto attribute = this->getConnectedInputAttribute(index);
if (attribute == nullptr)
throwNodeError(hex::format("Nothing connected to input '{0}'", static_cast<const char*>(LangEntry(this->m_attributes[index].getUnlocalizedName()))));
if (attribute->getType() != Attribute::Type::Float)
throwNodeError("Tried to read float from non-float attribute");
markInputProcessed(index);
attribute->getParentNode()->process();
auto &outputData = attribute->getOutputData();
if (!outputData.has_value())
throw std::runtime_error("No data available at connected attribute");
if (outputData->size() < sizeof(float))
throw std::runtime_error("Not enough data provided for float");
return *reinterpret_cast<float*>(outputData->data());
}
void setBufferOnOutput(u32 index, std::vector<u8> data) {
if (index >= this->getAttributes().size())
throw std::runtime_error("Attribute index out of bounds!");
auto &attribute = this->getAttributes()[index];
if (attribute.getIOType() != Attribute::IOType::Out)
throw std::runtime_error("Tried to set output data of an input attribute!");
attribute.getOutputData() = data;
}
void setIntegerOnOutput(u32 index, u64 integer) {
if (index >= this->getAttributes().size())
throw std::runtime_error("Attribute index out of bounds!");
auto &attribute = this->getAttributes()[index];
if (attribute.getIOType() != Attribute::IOType::Out)
throw std::runtime_error("Tried to set output data of an input attribute!");
std::vector<u8> buffer(sizeof(u64), 0);
std::memcpy(buffer.data(), &integer, sizeof(u64));
attribute.getOutputData() = buffer;
}
void setFloatOnOutput(u32 index, float floatingPoint) {
if (index >= this->getAttributes().size())
throw std::runtime_error("Attribute index out of bounds!");
auto &attribute = this->getAttributes()[index];
if (attribute.getIOType() != Attribute::IOType::Out)
throw std::runtime_error("Tried to set output data of an input attribute!");
std::vector<u8> buffer(sizeof(float), 0);
std::memcpy(buffer.data(), &floatingPoint, sizeof(float));
attribute.getOutputData() = buffer;
}
void setOverlayData(u64 address, const std::vector<u8> &data) {
if (this->m_overlay == nullptr)
throw std::runtime_error("Tried setting overlay data on a node that's not the end of a chain!");
this->m_overlay->setAddress(address);
this->m_overlay->getData() = data;
}
void setOverlayData(u64 address, const std::vector<u8> &data);
};