Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
ProceduralComponent.hpp
1#pragma once
2
3#include <Infinity/api.h>
4#include <Infinity/Procedural/ProceduralComponentDescription.hpp>
5#include <Infinity/Procedural/ComponentID.hpp>
6#include <Infinity/Engine/PRNG.hpp>
7#include <Infinity/Util/unordered_dense.h>
8#include <Infinity/Types/All.hpp>
9
10#include <vector>
11#include <string>
12#include <memory>
13
15{
16
17enum class ProceduralComponentRuntime : int8_t
18{
19 CPP = 1,
20 CSharp = 2,
21 Python = 3,
22 MIN = CPP,
23 MAX = Python
24};
25
26class ProceduralComponentImpl;
27
72class INFINITY_API_PUBLIC ProceduralComponent
73{
74 public:
84
89
91
99 uint32_t random();
100
107
114
125 virtual void execute() = 0;
126
133 bool hasIn(const std::string& name) const;
134
141 bool hasOut(const std::string& name) const;
142
155 template<typename T>
156 const T& getIn(const std::string& name) const
157 {
158 if constexpr (std::is_base_of_v<Infinity::Types::Core::Data, T>)
159 {
160 return *dynamic_cast<const T*>(getInData(name));
161 } else {
162 return dynamic_cast<const Infinity::Types::Core::Value<T>*>(getInData(name))->get();
163 }
164 }
165
176 template<typename T>
177 void setOut(const std::string& name, T&& val)
178 {
179 if constexpr (std::is_base_of_v<Infinity::Types::Core::Data, T>)
180 {
181 setOutData(name, std::make_shared<T>(std::move(val)));
182 } else {
183 setOutData(name, std::make_shared<Infinity::Types::Core::Value<T>>(val));
184 }
185 }
186
197 template<typename T>
198 void setOut(const std::string& name, const T& val)
199 {
200 if constexpr (std::is_base_of_v<Infinity::Types::Core::Data, T>)
201 {
202 setOutData(name, std::make_shared<T>(val));
203 } else {
204 setOutData(name, std::make_shared<Infinity::Types::Core::Value<T>>(val));
205 }
206 }
207
215 template<typename T>
216 void setOut(const std::string& name, const T* val)
217 {
218 setOutData(name, std::make_shared<T>(*val));
219 }
220
221 protected:
231 void forward(const std::string& from, const std::string& to);
232
238 void logError(const std::string& msg) const;
239
245 void logWarning(const std::string& msg) const;
246
252 void logInfo(const std::string& msg) const;
253
259 void logDebug(const std::string& msg) const;
260
261 private:
262 ProceduralComponent() = delete;
263
270 const Infinity::Types::Core::Base* getInData(const std::string& name) const;
271
278 void setOutData(const std::string& name, std::shared_ptr<const Infinity::Types::Core::Base> data);
279
280 std::unique_ptr<ProceduralComponentImpl> _impl;
281
282 friend class Infinity::Procedural::ProceduralComponentImpl;
283};
284
285}
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
Description and configuration data for a ProceduralComponent instance.
Definition ProceduralComponentDescription.hpp:48
Base class for procedural generation components.
Definition ProceduralComponent.hpp:73
void setOut(const std::string &name, const T &val)
Sets typed data on an output port (const reference overload).
Definition ProceduralComponent.hpp:198
Infinity::Engine::PRNG prng
Pseudo-random number generator for reproducible randomness.
Definition ProceduralComponent.hpp:90
ComponentID id() const
Gets the ComponentID identifying this component's type.
bool hasIn(const std::string &name) const
Checks if an input port with the given name exists.
void logDebug(const std::string &msg) const
Logs a debug message.
void logInfo(const std::string &msg) const
Logs an informational message.
virtual ~ProceduralComponent()
Virtual destructor.
void setOut(const std::string &name, const T *val)
Sets typed data on an output port from a pointer (copied).
Definition ProceduralComponent.hpp:216
ProceduralComponent(const ProceduralComponentDescription &desc)
Constructs a ProceduralComponent from a component description.
const T & getIn(const std::string &name) const
Retrieves typed data from an input port.
Definition ProceduralComponent.hpp:156
void setOut(const std::string &name, T &&val)
Sets typed data on an output port (rvalue reference overload).
Definition ProceduralComponent.hpp:177
ProceduralComponentRuntime runtime()
Gets runtime information about this component instance.
bool hasOut(const std::string &name) const
Checks if an output port with the given name exists.
void logError(const std::string &msg) const
Logs an error message.
void forward(const std::string &from, const std::string &to)
Forwards data from an input port directly to an output port.
uint32_t random()
Generates a random uint32 value using the component's PRNG.
virtual void execute()=0
Executes the component's procedural generation logic.
void logWarning(const std::string &msg) const
Logs a warning message.
Abstract base class for all Infinity Engine data types.
Definition Base.hpp:43
Template wrapper for primitive types to integrate with the Infinity type system.
Definition Value.hpp:89
Definition ComponentException.hpp:7
ProceduralComponentRuntime
Definition ProceduralComponent.hpp:18
Unique identifier for a procedural component.
Definition ComponentID.hpp:35