Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
ProceduralSystem.hpp
1#pragma once
2
3#include <Infinity/api.h>
4#include <Infinity/Types/All.hpp>
5
6#include <filesystem>
7#include <vector>
8#include <memory>
9#include <string>
10
11namespace Infinity::Procedural {
12
13class ProceduralSystemImpl;
14
57class INFINITY_API_PUBLIC ProceduralSystem
58{
59 public:
71 explicit ProceduralSystem(const std::filesystem::path& file);
72
84 ProceduralSystem(const std::vector<unsigned char>& buffer, const std::filesystem::path& loadPath = {});
85
92
99
107
113 std::string id() const;
114
126 void execute();
127
137 void setSeed(uint64_t seed);
138
151 bool setLoop(int start, int stop, int step);
152
162 bool setLoop(std::string portName);
163
170 void clearLoop();
171
184 template<typename T>
185 const T& getIn(const std::string& name) const
186 {
187 if constexpr (std::is_base_of_v<Infinity::Types::Core::Data, T>)
188 {
189 return *dynamic_cast<const T*>(getInData(name));
190 } else {
191 return dynamic_cast<const Infinity::Types::Core::Value<T>*>(getInData(name))->get();
192 }
193 }
194
210 template<typename T>
211 const T& getOut(const std::string& name) const
212 {
213 if constexpr (std::is_base_of_v<Infinity::Types::Core::Data, T>)
214 {
215 return *dynamic_cast<const T*>(getOutData(name));
216 } else {
217 return dynamic_cast<const Infinity::Types::Core::Value<T>*>(getOutData(name))->get();
218 }
219 }
220
231 template<typename T>
232 void setIn(const std::string& name, T&& val)
233 {
234 if constexpr (std::is_base_of_v<Infinity::Types::Core::Data, T>)
235 {
236 setInData(name, std::make_shared<T>(std::move(val)));
237 } else {
238 setInData(name, std::make_shared<Infinity::Types::Core::Value<T>>(val));
239 }
240 }
241
252 template<typename T>
253 void setIn(const std::string& name, const T& val)
254 {
255 if constexpr (std::is_base_of_v<Infinity::Types::Core::Data, T>)
256 {
257 setInData(name, std::make_shared<T>(val));
258 } else {
259 setInData(name, std::make_shared<Infinity::Types::Core::Value<T>>(val));
260 }
261 }
262
270 template<typename T>
271 void setIn(const std::string& name, const T* val)
272 {
273 setInData(name, std::make_shared<T>(*val));
274 }
275
276 private:
277 ProceduralSystem() = delete;
278 ProceduralSystem(std::unique_ptr<ProceduralSystemImpl>&& impl);
279
286 const Infinity::Types::Core::Base* getInData(const std::string& name) const;
287
294 const Infinity::Types::Core::Base* getOutData(const std::string& name) const;
295
302 void setInData(const std::string& name, std::shared_ptr<const Infinity::Types::Core::Base> data);
303
304 std::unique_ptr<ProceduralSystemImpl> _impl;
305
306 friend class ProceduralSystemImpl;
307};
308
309}
Main interface for a directed acyclic graph of procedural components.
Definition ProceduralSystem.hpp:58
const T & getIn(const std::string &name) const
Retrieves typed data from an input port.
Definition ProceduralSystem.hpp:185
bool setLoop(int start, int stop, int step)
Configures the system to loop over a range of integer values.
std::string id() const
Gets the unique identifier for this system.
void clearLoop()
Clears any configured loop behavior.
bool setLoop(std::string portName)
Configures the system to loop over values from an input port.
void execute()
Executes the procedural system.
void setSeed(uint64_t seed)
Sets the random seed for the entire system.
const T & getOut(const std::string &name) const
Retrieves typed data from an output port.
Definition ProceduralSystem.hpp:211
void setIn(const std::string &name, T &&val)
Sets typed data on an input port (rvalue reference overload).
Definition ProceduralSystem.hpp:232
ProceduralSystem(const std::filesystem::path &file)
Loads a ProceduralSystem from a file.
ProceduralSystem(ProceduralSystem &&other)
Move constructor.
void setIn(const std::string &name, const T &val)
Sets typed data on an input port (const reference overload).
Definition ProceduralSystem.hpp:253
void setIn(const std::string &name, const T *val)
Sets typed data on an input port from a pointer (copied).
Definition ProceduralSystem.hpp:271
ProceduralSystem & operator=(ProceduralSystem &&other)
Move assignment operator.
ProceduralSystem(const std::vector< unsigned char > &buffer, const std::filesystem::path &loadPath={})
Creates a ProceduralSystem from a binary buffer.
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