Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Containers::Array2D< T > Class Template Reference

Two-dimensional array container for grid-based data in procedural generation. More...

#include <Array2D.hpp>

Inheritance diagram for Infinity::Types::Containers::Array2D< T >:
[legend]
Collaboration diagram for Infinity::Types::Containers::Array2D< T >:
[legend]

Public Member Functions

 Array2D ()
 Default constructor.
 
 Array2D (size_t width, size_t height)
 Constructs a 2D array with specified dimensions.
 
 Array2D (size_t width, size_t height, Array< T > data)
 Constructs a 2D array from existing Array data with specified dimensions.
 
 Array2D (size_t width, size_t height, T *data)
 Constructs a 2D array by copying from a raw data pointer.
 
 Array2D (size_t colStride, const std::vector< T > &data)
 Constructs a 2D array from a 1D vector with column stride.
 
virtual ~Array2D ()
 Destructor.
 
std::unique_ptr< Core::Baseclone () const override
 
const Infinity::Types::TypeIDtypeId () const override
 Gets the TypeID for this Array2D type.
 
size_t width () const noexcept
 Gets the width (number of columns) of the 2D array.
 
size_t height () const noexcept
 Gets the height (number of rows) of the 2D array.
 
T & at (size_t x, size_t y)
 Accesses element at 2D coordinates.
 
const T & at (size_t x, size_t y) const
 Accesses element at 2D coordinates (const).
 
virtual size_t dimensions () const noexcept override
 Gets the number of dimensions in this container.
 
void resize (size_t width, size_t height)
 Resizes the 2D array to new dimensions.
 
- Public Member Functions inherited from Infinity::Types::Containers::Array< T >
 Array ()
 Default constructor.
 
 Array (size_t size)
 Constructs an array with specified size.
 
 Array (const T *data, size_t size)
 Constructs an array by copying data from a raw pointer.
 
 Array (const std::vector< T > &data)
 Constructs an array from a std::vector.
 
 Array (Core::span< T > data)
 Constructs an array from a span.
 
 Array (const Array &other)
 Copy constructor.
 
 Array (Array &&other) noexcept
 Move constructor.
 
virtual ~Array ()
 Destructor.
 
Arrayoperator= (const Array &rhs)
 Copy assignment operator.
 
Arrayoperator= (Array &&rhs) noexcept
 Move assignment operator.
 
virtual const Infinity::Types::TypeIDelementTypeId () override
 Gets the TypeID for the element type.
 
void copy (const T *data, size_t count)
 Replaces array contents by copying from raw data.
 
T & operator[] (size_t index)
 Accesses element at specified index (unchecked).
 
const T & operator[] (size_t index) const
 Accesses element at specified index (unchecked, const).
 
T & at (size_t index)
 Accesses element at specified index (checked).
 
const T & at (size_t index) const
 Accesses element at specified index (checked, const).
 
void push_back (const T &value)
 Appends an element to the end of the array.
 
template<typename... Args>
void emplace_back (Args &&... args)
 Constructs and appends an element in-place.
 
void insert (size_t index, const T &value)
 Inserts an element at the specified position.
 
void erase (size_t index)
 Removes the element at the specified position.
 
void reserve (size_t capacity)
 Reserves capacity for at least the specified number of elements.
 
virtual void resize (size_t newSize) override
 Resizes the array to contain the specified number of elements.
 
void shrink_to_fit ()
 Reduces capacity to match the current size.
 
void clear () noexcept
 Removes all elements from the array.
 
virtual bool containsData () const override
 Checks if the array contains Core::Data-derived types.
 
virtual bool containsValues () const override
 Checks if the array contains plain value types.
 
virtual std::shared_ptr< Core::DatadataAt (size_t index) override
 Gets a type-erased Data pointer to the element at the specified index.
 
virtual std::shared_ptr< const Core::DatadataAt (size_t index) const override
 Gets a const type-erased Data pointer to the element at the specified index.
 
virtual void setData (size_t index, const Core::Data &data) override
 Sets an element from type-erased Data.
 
T * data ()
 Gets a pointer to the underlying data array.
 
const T * data () const
 Gets a const pointer to the underlying data array.
 
T * releaseData ()
 Releases ownership of the underlying data array.
 
T & front ()
 Accesses the first element.
 
const T & front () const
 Accesses the first element (const).
 
T & back ()
 Accesses the last element.
 
const T & back () const
 Accesses the last element (const).
 
size_t size () const noexcept override
 Gets the number of elements in the array.
 
size_t capacity () const noexcept
 Gets the current capacity.
 
bool empty () const noexcept
 Checks if the array is empty.
 
virtual void * pointer (size_t index) override
 Gets a void pointer to the element at the specified index.
 
virtual const void * pointer (size_t index) const override
 Gets a const void pointer to the element at the specified index.
 
iterator begin () noexcept
 Returns an iterator to the beginning.
 
iterator end () noexcept
 Returns an iterator to the end.
 
const_iterator begin () const noexcept
 Returns a const iterator to the beginning.
 
const_iterator end () const noexcept
 Returns a const iterator to the end.
 
reverse_iterator rbegin () noexcept
 Returns a reverse iterator to the beginning.
 
reverse_iterator rend () noexcept
 Returns a reverse iterator to the end.
 
const_reverse_iterator rbegin () const noexcept
 Returns a const reverse iterator to the beginning.
 
const_reverse_iterator rend () const noexcept
 Returns a const reverse iterator to the end.
 
- Public Member Functions inherited from Infinity::Types::Containers::ArrayBase
 ArrayBase ()
 
 ArrayBase (const ArrayBase &other)
 
virtual ~ArrayBase ()=default
 Virtual destructor.
 
- Public Member Functions inherited from Infinity::Types::Core::Data
 Data ()
 
 Data (const Data &other)
 
 Data (Data &&other)
 
Dataoperator= (const Data &other)
 
Dataoperator= (Data &&other)
 
std::unique_ptr< Baseclone () const override
 
virtual ~Data ()
 Virtual destructor.
 
bool hasProperty (const std::string &key) const
 
template<typename T >
void setProperty (const std::string &key, T &&value)
 Sets a typed property value.
 
template<typename T >
void setProperty (const std::string &key, const T &value)
 Sets a typed property value.
 
void setProperty (const std::string &key, PropertyValue &&value)
 Sets a typed property value.
 
const PropertyValuegetProperty (const std::string &key) const
 Gets a property value without type checking.
 
template<typename T >
const T & getProperty (const std::string &key) const
 Gets a typed property value.
 
void removeProperty (const std::string &key)
 
- Public Member Functions inherited from Infinity::Types::Core::Base
virtual ~Base ()
 Virtual destructor.
 
virtual std::istream & legibleDataRead (std::istream &in) override
 Deserializes the object from a single-line text representation.
 
virtual std::ostream & legibleDataWrite (std::ostream &out) const override
 Serializes the object to a single-line text representation.
 

Friends

class Infinity::IO::Data::Array2DSerializer< T >
 

Additional Inherited Members

- Public Types inherited from Infinity::Types::Containers::Array< T >
using iterator = T *
 
using const_iterator = const T *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 
- Protected Member Functions inherited from Infinity::Types::Containers::Array< T >
void swap (Array &other) noexcept
 Swaps the contents with another array.
 
void reset () noexcept
 Resets the array to an empty state.
 
void _reallocate (size_t newCapacity)
 Reallocates the array with a new capacity.
 
void _delete () noexcept
 Deallocates the array's memory.
 
void _dealloc ()
 Deallocates the array's memory.
 
- Static Protected Member Functions inherited from Infinity::Types::Containers::Array< T >
static T * _alloc (size_t size)
 Allocates aligned memory for the specified number of elements.
 
- Protected Attributes inherited from Infinity::Types::Containers::Array< T >
Core::span< T > _data
 Span wrapping the allocated data.
 
size_t _capacity
 Total allocated capacity.
 
size_t _size
 Current number of elements.
 

Detailed Description

template<typename T>
class Infinity::Types::Containers::Array2D< T >

Two-dimensional array container for grid-based data in procedural generation.

Array2D<T> extends Array<T> to provide a 2D grid abstraction with row-major storage. It is the fundamental container for image-like data in the Infinity Engine, including textures, heightmaps, masks, and other spatially-organized data structures.

The class stores elements in row-major order (rows are contiguous in memory), making it cache-friendly for row-wise traversal. All underlying memory management, alignment, and type system integration is inherited from Array<T>.

Key features:

  • 2D indexing with at(x, y) for intuitive spatial access
  • Type aliases for common procedural generation data (Texture, Heightmap, Mask, etc.)
  • Inherits all Array<T> capabilities (serialization, iteration, SIMD alignment)
  • Seamless integration with ProceduralSystem input/output ports
  • Support for both scalar and vector element types

Common use cases in procedural generation:

  • Heightmaps for terrain generation
  • Texture synthesis and manipulation
  • Masks for spatial blending and selection
  • Splatmaps for multi-material terrain
  • Noise field storage
  • Per-pixel procedural effects
Template Parameters
TElement type (typically scalar or vector types)
Note
Storage is row-major: element at (x, y) is at index y * width + x
All memory is 64-byte aligned (inherited from Array<T>)

Example usage:

// Create a heightmap
Array2D<float> heightmap(512, 512);
for (size_t y = 0; y < heightmap.height(); ++y) {
for (size_t x = 0; x < heightmap.width(); ++x) {
heightmap.at(x, y) = generateHeight(x, y);
}
}
// Use with ProceduralSystem
system->setIn("terrain_heightmap", std::move(heightmap));
// Create an RGBA texture
Array2D<Math::Vector4ub> texture(1024, 1024);
texture.at(512, 512) = Math::Vector4ub{255, 0, 0, 255}; // Red pixel
// Common type aliases
Texture colorMap(256, 256); // RGBA texture
Heightmap terrain(1024, 1024); // Float heightmap
Mask blendMask(512, 512); // Float mask
Splatmap materialMap(512, 512); // Uint8 splatmap
Two-dimensional array container for grid-based data in procedural generation.
Definition Array2D.hpp:82
Array2D< float > Mask
Single-channel float mask for spatial blending and selection.
Definition Array2D.hpp:354
Array2D< float > Heightmap
Single-channel float heightmap for terrain generation.
Definition Array2D.hpp:336
Array2D< uint8_t > Splatmap
8-bit splatmap for terrain material blending.
Definition Array2D.hpp:285
Array2D< Math::Vector4ub > Texture
Default texture type (RGBA, 8-bit per channel).
Definition Array2D.hpp:327
Template structure representing a 4-component vector.
Definition Vector4.hpp:85

Constructor & Destructor Documentation

◆ Array2D() [1/5]

template<typename T >
Infinity::Types::Containers::Array2D< T >::Array2D ( )
inline

Default constructor.

Constructs an empty 2D array with zero width and height.

◆ Array2D() [2/5]

template<typename T >
Infinity::Types::Containers::Array2D< T >::Array2D ( size_t  width,
size_t  height 
)
inline

Constructs a 2D array with specified dimensions.

Allocates memory for width × height elements and default-constructs them. Elements are stored in row-major order.

Parameters
widthNumber of columns (horizontal dimension).
heightNumber of rows (vertical dimension).

◆ Array2D() [3/5]

template<typename T >
Infinity::Types::Containers::Array2D< T >::Array2D ( size_t  width,
size_t  height,
Array< T >  data 
)
inline

Constructs a 2D array from existing Array data with specified dimensions.

Takes ownership of the provided Array's data and interprets it as a 2D grid.

Parameters
widthNumber of columns.
heightNumber of rows.
dataArray containing width × height elements.
Warning
The data array must contain exactly width × height elements.

◆ Array2D() [4/5]

template<typename T >
Infinity::Types::Containers::Array2D< T >::Array2D ( size_t  width,
size_t  height,
T *  data 
)
inline

Constructs a 2D array by copying from a raw data pointer.

Allocates new memory and copies width × height elements from the pointer.

Parameters
widthNumber of columns.
heightNumber of rows.
dataPointer to source data (must contain at least width × height elements).

◆ Array2D() [5/5]

template<typename T >
Infinity::Types::Containers::Array2D< T >::Array2D ( size_t  colStride,
const std::vector< T > &  data 
)
inline

Constructs a 2D array from a 1D vector with column stride.

Interprets the vector data as a 2D array where each colStride elements form a row. Width is calculated as data.size() / colStride.

Parameters
colStrideNumber of elements per row (height).
dataVector containing the flattened 2D data.
Note
This constructor is useful for loading data from row-major serialized formats.

◆ ~Array2D()

template<typename T >
virtual Infinity::Types::Containers::Array2D< T >::~Array2D ( )
inlinevirtual

Destructor.

Properly destroys all elements and deallocates memory (inherited from Array<T>).

Member Function Documentation

◆ at() [1/2]

template<typename T >
T & Infinity::Types::Containers::Array2D< T >::at ( size_t  x,
size_t  y 
)
inline

Accesses element at 2D coordinates.

Provides intuitive 2D indexing into the row-major storage.

Parameters
xColumn index (0 to width-1).
yRow index (0 to height-1).
Returns
Reference to the element at (x, y).
Note
Elements are stored in row-major order: index = y * width + x
Currently does not perform bounds checking.

◆ at() [2/2]

template<typename T >
const T & Infinity::Types::Containers::Array2D< T >::at ( size_t  x,
size_t  y 
) const
inline

Accesses element at 2D coordinates (const).

Provides intuitive 2D indexing into the row-major storage.

Parameters
xColumn index (0 to width-1).
yRow index (0 to height-1).
Returns
Const reference to the element at (x, y).
Note
Elements are stored in row-major order: index = y * width + x
Currently does not perform bounds checking.

◆ clone()

template<typename T >
std::unique_ptr< Core::Base > Infinity::Types::Containers::Array2D< T >::clone ( ) const
inlineoverridevirtual

◆ dimensions()

template<typename T >
virtual size_t Infinity::Types::Containers::Array2D< T >::dimensions ( ) const
inlineoverridevirtualnoexcept

Gets the number of dimensions in this container.

Returns
Always returns 2 for Array2D (two-dimensional).

Reimplemented from Infinity::Types::Containers::Array< T >.

◆ height()

template<typename T >
size_t Infinity::Types::Containers::Array2D< T >::height ( ) const
inlinenoexcept

Gets the height (number of rows) of the 2D array.

Returns
Height of the array.

◆ resize()

template<typename T >
void Infinity::Types::Containers::Array2D< T >::resize ( size_t  width,
size_t  height 
)
inline

Resizes the 2D array to new dimensions.

Reallocates the array to hold width × height elements. If the new size is larger, new elements are default-constructed. If smaller, excess elements are destroyed. Existing data is preserved where possible (up to min of old/new dimensions).

Parameters
widthNew number of columns.
heightNew number of rows.
Note
This completely replaces the array contents. For simple size changes preserving data in row-major order, consider the underlying Array resize.

◆ typeId()

template<typename T >
const Infinity::Types::TypeID & Infinity::Types::Containers::Array2D< T >::typeId ( ) const
inlineoverridevirtual

Gets the TypeID for this Array2D type.

Returns
TypeID identifying this Array2D<T> specialization.

Reimplemented from Infinity::Types::Containers::Array< T >.

◆ width()

template<typename T >
size_t Infinity::Types::Containers::Array2D< T >::width ( ) const
inlinenoexcept

Gets the width (number of columns) of the 2D array.

Returns
Width of the array.

Friends And Related Symbol Documentation

◆ Infinity::IO::Data::Array2DSerializer< T >

template<typename T >
friend class Infinity::IO::Data::Array2DSerializer< T >
friend