Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Procedural::ProceduralSystem Class Reference

Main interface for a directed acyclic graph of procedural components. More...

#include <ProceduralSystem.hpp>

Public Member Functions

 ProceduralSystem (const std::filesystem::path &file)
 Loads a ProceduralSystem from a file.
 
 ProceduralSystem (const std::vector< unsigned char > &buffer, const std::filesystem::path &loadPath={})
 Creates a ProceduralSystem from a binary buffer.
 
 ProceduralSystem (ProceduralSystem &&other)
 Move constructor.
 
 ~ProceduralSystem ()
 Destructor.
 
ProceduralSystemoperator= (ProceduralSystem &&other)
 Move assignment operator.
 
std::string id () const
 Gets the unique identifier for this system.
 
void execute ()
 Executes the procedural system.
 
void setSeed (uint64_t seed)
 Sets the random seed for the entire system.
 
bool setLoop (int start, int stop, int step)
 Configures the system to loop over a range of integer values.
 
bool setLoop (std::string portName)
 Configures the system to loop over values from an input port.
 
void clearLoop ()
 Clears any configured loop behavior.
 
template<typename T >
const T & getIn (const std::string &name) const
 Retrieves typed data from an input port.
 
template<typename T >
const T & getOut (const std::string &name) const
 Retrieves typed data from an output port.
 
template<typename T >
void setIn (const std::string &name, T &&val)
 Sets typed data on an input port (rvalue reference overload).
 
template<typename T >
void setIn (const std::string &name, const T &val)
 Sets typed data on an input port (const reference overload).
 
template<typename T >
void setIn (const std::string &name, const T *val)
 Sets typed data on an input port from a pointer (copied).
 

Friends

class ProceduralSystemImpl
 

Detailed Description

Main interface for a directed acyclic graph of procedural components.

ProceduralSystem represents a complete procedural generation pipeline composed of interconnected ProceduralComponents arranged in a directed acyclic graph (DAG). Systems can be loaded from files, executed to generate outputs, and configured with input parameters and random seeds.

A ProceduralSystem manages:

  • Component instantiation and lifecycle
  • Data flow between connected components
  • Execution ordering based on dependencies
  • Input/output ports for external interaction
  • Optional looping behavior for iterative generation
  • Random seed propagation to all components

Systems are the primary execution unit in the Infinity Engine and can contain nested sub-systems, allowing for hierarchical procedural generation workflows. Systems are typically accessed through an InfinityCore rather than loaded directly.

Example usage:

// Load a core and retrieve a system
InfinityCore core("terrain.infinitycore");
auto& system = core.getSystem("TerrainGenerator");
// Configure inputs
system->setIn("resolution", 1024);
system->setIn("scale", 50.0f);
system->setSeed(12345);
// Execute the system
system->execute();
// Retrieve outputs
const Mesh& terrain = system->getOut<Mesh>("terrain_mesh");
const Texture& heightmap = system->getOut<Texture>("heightmap");

See Working with Procedural Systems for an in-depth guide on using Procedural Systems.

Constructor & Destructor Documentation

◆ ProceduralSystem() [1/3]

Infinity::Procedural::ProceduralSystem::ProceduralSystem ( const std::filesystem::path &  file)
explicit

Loads a ProceduralSystem from a file.

Deserializes a complete procedural system, including all component descriptions, connections, and configuration. Automatically detects file format and instantiates all required components from registered plugins.

Parameters
filePath to the system file (.prcb/.yaml).
Exceptions
std::runtime_errorif the file cannot be read, parsed, or if required component types are not registered.

◆ ProceduralSystem() [2/3]

Infinity::Procedural::ProceduralSystem::ProceduralSystem ( const std::vector< unsigned char > &  buffer,
const std::filesystem::path &  loadPath = {} 
)

Creates a ProceduralSystem from a binary buffer.

Deserializes a procedural system from in-memory binary data.

Parameters
bufferVector containing the serialized system data.
loadPathOptional path indicating where this system conceptually resides (used as the base path for loading component files).
Exceptions
std::runtime_errorif the buffer is invalid or if required component types are not registered.

◆ ProceduralSystem() [3/3]

Infinity::Procedural::ProceduralSystem::ProceduralSystem ( ProceduralSystem &&  other)

Move constructor.

Parameters
otherThe ProceduralSystem to move from.

◆ ~ProceduralSystem()

Infinity::Procedural::ProceduralSystem::~ProceduralSystem ( )

Destructor.

Cleans up all component instances and releases resources.

Member Function Documentation

◆ clearLoop()

void Infinity::Procedural::ProceduralSystem::clearLoop ( )

Clears any configured loop behavior.

Removes loop configuration, causing the system to execute only once per execute() call.

◆ execute()

void Infinity::Procedural::ProceduralSystem::execute ( )

Executes the procedural system.

Runs all components in the system in dependency order, propagating data through the graph. If a loop is configured, executes the system multiple times with the loop variable. After execution, output data is available via getOut().

Exceptions
std::runtime_errorif execution fails due to missing inputs, component errors, or cyclic dependencies.

◆ getIn()

template<typename T >
const T & Infinity::Procedural::ProceduralSystem::getIn ( const std::string &  name) const
inline

Retrieves typed data from an input port.

If T is derived from Infinity::Types::Core::Data, returns the data directly. Otherwise, unwraps the value from Infinity::Types::Core::Value<T>.

Template Parameters
TThe expected type of the input data.
Parameters
nameThe name of the input port.
Returns
Const reference to the input data of type T.
Exceptions
std::bad_castif the input data is not of type T.
std::runtime_errorif the input port doesn't exist or has no data.

◆ getOut()

template<typename T >
const T & Infinity::Procedural::ProceduralSystem::getOut ( const std::string &  name) const
inline

Retrieves typed data from an output port.

If T is derived from Infinity::Types::Core::Data, returns the data directly. Otherwise, unwraps the value from Infinity::Types::Core::Value<T>.

Output data is only available after execute() has been called.

Template Parameters
TThe expected type of the output data.
Parameters
nameThe name of the output port.
Returns
Const reference to the output data of type T.
Exceptions
std::bad_castif the output data is not of type T.
std::runtime_errorif the output port doesn't exist, has no data, or execute() has not been called.

◆ id()

std::string Infinity::Procedural::ProceduralSystem::id ( ) const

Gets the unique identifier for this system.

Returns
The system's ID string.

◆ operator=()

ProceduralSystem & Infinity::Procedural::ProceduralSystem::operator= ( ProceduralSystem &&  other)

Move assignment operator.

Parameters
otherThe ProceduralSystem to move from.
Returns
Reference to this system.

◆ setIn() [1/3]

template<typename T >
void Infinity::Procedural::ProceduralSystem::setIn ( const std::string &  name,
const T &  val 
)
inline

Sets typed data on an input port (const reference overload).

If T is derived from Infinity::Types::Core::Data, stores it directly. Otherwise, wraps it in Infinity::Types::Core::Value<T>.

Template Parameters
TThe type of the input data.
Parameters
nameThe name of the input port.
valConst reference to the data to set (copied).

◆ setIn() [2/3]

template<typename T >
void Infinity::Procedural::ProceduralSystem::setIn ( const std::string &  name,
const T *  val 
)
inline

Sets typed data on an input port from a pointer (copied).

Template Parameters
TThe type of the input data.
Parameters
nameThe name of the input port.
valPointer to the data to set (dereferenced and copied).

◆ setIn() [3/3]

template<typename T >
void Infinity::Procedural::ProceduralSystem::setIn ( const std::string &  name,
T &&  val 
)
inline

Sets typed data on an input port (rvalue reference overload).

If T is derived from Infinity::Types::Core::Data, stores it directly. Otherwise, wraps it in Infinity::Types::Core::Value<T>.

Template Parameters
TThe type of the input data.
Parameters
nameThe name of the input port.
valRvalue reference to the data to set (moved).

◆ setLoop() [1/2]

bool Infinity::Procedural::ProceduralSystem::setLoop ( int  start,
int  stop,
int  step 
)

Configures the system to loop over a range of integer values.

Sets up an integer loop that will execute the system multiple times, incrementing a loop variable from start to stop (exclusive) by step. The loop variable can be accessed by components within the system.

Parameters
startThe starting value of the loop (inclusive).
stopThe ending value of the loop (exclusive).
stepThe increment value for each iteration.
Returns
True if the loop was successfully configured, false otherwise.

◆ setLoop() [2/2]

bool Infinity::Procedural::ProceduralSystem::setLoop ( std::string  portName)

Configures the system to loop over values from an input port.

Sets up a loop that iterates over a collection provided via the specified input port. The system will execute once for each element in the collection.

Parameters
portNameThe name of the input port containing the collection to iterate over.
Returns
True if the loop was successfully configured, false otherwise.

◆ setSeed()

void Infinity::Procedural::ProceduralSystem::setSeed ( uint64_t  seed)

Sets the random seed for the entire system.

Propagates the seed to all components in the system, ensuring reproducible generation. Each component derives its own seed deterministically from this base seed and its position in the graph.

Parameters
seedThe random seed value.

Friends And Related Symbol Documentation

◆ ProceduralSystemImpl

friend class ProceduralSystemImpl
friend