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

Base class for procedural generation components. More...

#include <ProceduralComponent.hpp>

Collaboration diagram for Infinity::Procedural::ProceduralComponent:
[legend]

Public Member Functions

 ProceduralComponent (const ProceduralComponentDescription &desc)
 Constructs a ProceduralComponent from a component description.
 
virtual ~ProceduralComponent ()
 Virtual destructor.
 
uint32_t random ()
 Generates a random uint32 value using the component's PRNG.
 
ComponentID id () const
 Gets the ComponentID identifying this component's type.
 
ProceduralComponentRuntime runtime ()
 Gets runtime information about this component instance.
 
virtual void execute ()=0
 Executes the component's procedural generation logic.
 
bool hasIn (const std::string &name) const
 Checks if an input port with the given name exists.
 
bool hasOut (const std::string &name) const
 Checks if an output port with the given name exists.
 
template<typename T >
const T & getIn (const std::string &name) const
 Retrieves typed data from an input port.
 
template<typename T >
void setOut (const std::string &name, T &&val)
 Sets typed data on an output port (rvalue reference overload).
 
template<typename T >
void setOut (const std::string &name, const T &val)
 Sets typed data on an output port (const reference overload).
 
template<typename T >
void setOut (const std::string &name, const T *val)
 Sets typed data on an output port from a pointer (copied).
 

Public Attributes

Infinity::Engine::PRNG prng
 Pseudo-random number generator for reproducible randomness.
 

Protected Member Functions

void forward (const std::string &from, const std::string &to)
 Forwards data from an input port directly to an output port.
 
void logError (const std::string &msg) const
 Logs an error message.
 
void logWarning (const std::string &msg) const
 Logs a warning message.
 
void logInfo (const std::string &msg) const
 Logs an informational message.
 
void logDebug (const std::string &msg) const
 Logs a debug message.
 

Friends

class Infinity::Procedural::ProceduralComponentImpl
 

Detailed Description

Base class for procedural generation components.

ProceduralComponent represents a single unit of procedural behavior in the Infinity Engine. Components are nodes in a procedural generation graph that receive input data, perform computations, and produce output data. They are the fundamental building blocks that plugin developers extend to create custom procedural generation functionality.

Each component has:

  • A unique ComponentID identifying its type
  • Named input ports for receiving data from other components
  • Named output ports for producing data for downstream components
  • A PRNG for reproducible random number generation
  • Logging capabilities for diagnostics

To create a custom component, inherit from ProceduralComponent and implement the execute() method to define the component's behavior.

Example implementation:

class MyMeshGenerator : public ProceduralComponent
{
public:
MyMeshGenerator(const ProceduralComponentDescription& desc)
void execute() override
{
// Read input parameters
int subdivisions = getIn<int>("subdivisions");
float scale = getIn<float>("scale");
// Generate mesh
Mesh result = generateMesh(subdivisions, scale);
// Write output
setOut("mesh", result);
}
};
Description and configuration data for a ProceduralComponent instance.
Definition ProceduralComponentDescription.hpp:48
Base class for procedural generation components.
Definition ProceduralComponent.hpp:73

See Creating Your First Procedural Component for a detailed guide on how to build Procedural Components.

Constructor & Destructor Documentation

◆ ProceduralComponent()

Infinity::Procedural::ProceduralComponent::ProceduralComponent ( const ProceduralComponentDescription desc)

Constructs a ProceduralComponent from a component description.

Initializes the component with metadata, input/output port connections, and configuration from the description.

Parameters
descThe component description containing initialization parameters.

◆ ~ProceduralComponent()

virtual Infinity::Procedural::ProceduralComponent::~ProceduralComponent ( )
virtual

Virtual destructor.

Member Function Documentation

◆ execute()

virtual void Infinity::Procedural::ProceduralComponent::execute ( )
pure virtual

Executes the component's procedural generation logic.

This pure virtual method must be implemented by derived classes to define the component's behavior. The implementation should read from input ports using getIn(), perform its computations, and write to output ports using setOut().

The execute() method is called by the engine when all of the component's input dependencies are satisfied.

◆ forward()

void Infinity::Procedural::ProceduralComponent::forward ( const std::string &  from,
const std::string &  to 
)
protected

Forwards data from an input port directly to an output port.

Efficiently passes input data through to an output without copying. Useful for passthrough components or when data doesn't need to be modified.

Parameters
fromThe name of the input port to read from.
toThe name of the output port to write to.

◆ getIn()

template<typename T >
const T & Infinity::Procedural::ProceduralComponent::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.

◆ hasIn()

bool Infinity::Procedural::ProceduralComponent::hasIn ( const std::string &  name) const

Checks if an input port with the given name exists.

Parameters
nameThe name of the input port to check.
Returns
True if the input port exists, false otherwise.

◆ hasOut()

bool Infinity::Procedural::ProceduralComponent::hasOut ( const std::string &  name) const

Checks if an output port with the given name exists.

Parameters
nameThe name of the output port to check.
Returns
True if the output port exists, false otherwise.

◆ id()

ComponentID Infinity::Procedural::ProceduralComponent::id ( ) const

Gets the ComponentID identifying this component's type.

Returns
The ComponentID (group and name) for this component type.

◆ logDebug()

void Infinity::Procedural::ProceduralComponent::logDebug ( const std::string &  msg) const
protected

Logs a debug message.

Parameters
msgThe debug message to log.

◆ logError()

void Infinity::Procedural::ProceduralComponent::logError ( const std::string &  msg) const
protected

Logs an error message.

Parameters
msgThe error message to log.

◆ logInfo()

void Infinity::Procedural::ProceduralComponent::logInfo ( const std::string &  msg) const
protected

Logs an informational message.

Parameters
msgThe info message to log.

◆ logWarning()

void Infinity::Procedural::ProceduralComponent::logWarning ( const std::string &  msg) const
protected

Logs a warning message.

Parameters
msgThe warning message to log.

◆ random()

uint32_t Infinity::Procedural::ProceduralComponent::random ( )

Generates a random uint32 value using the component's PRNG.

Convenience method equivalent to calling prng().

Returns
A random uint32_t value.

◆ runtime()

ProceduralComponentRuntime Infinity::Procedural::ProceduralComponent::runtime ( )

Gets runtime information about this component instance.

Returns
Runtime metadata for this component.

◆ setOut() [1/3]

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

Sets typed data on an output 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 output data.
Parameters
nameThe name of the output port.
valConst reference to the data to set (copied).

◆ setOut() [2/3]

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

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

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

◆ setOut() [3/3]

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

Sets typed data on an output 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 output data.
Parameters
nameThe name of the output port.
valRvalue reference to the data to set (moved).

Friends And Related Symbol Documentation

◆ Infinity::Procedural::ProceduralComponentImpl

friend class Infinity::Procedural::ProceduralComponentImpl
friend

Member Data Documentation

◆ prng

Infinity::Engine::PRNG Infinity::Procedural::ProceduralComponent::prng

Pseudo-random number generator for reproducible randomness.