co_ecs 0.9.0
Cobalt ECS
Loading...
Searching...
No Matches
co_ecs::chunk Class Reference

Chunk holds a 16 Kb block of memory that holds components in blocks: |A1|A2|A3|...padding|B1|B2|B3|...padding|C1|C2|C3...padding where A, B, C are component types and A1, B1, C1 and others are components instances. More...

#include <chunk.hpp>

Classes

struct  chunk_buffer
 Chunk buffer type. More...
 

Public Member Functions

 chunk (const blocks_type &blocks, std::size_t max_size)
 Construct a new chunk object.
 
 chunk (const chunk &rhs)=delete
 Deleted copy constructor.
 
auto operator= (const chunk &rhs) -> chunk &=delete
 Deleted copy assignment operator.
 
 chunk (chunk &&rhs) noexcept
 Move constructor.
 
auto operator= (chunk &&rhs) noexcept -> chunk &
 Move assignment operator.
 
 ~chunk ()
 Destroy the chunk object.
 
template<component... Args>
void emplace_back (entity ent, Args &&... args)
 Emplace back components into blocks.
 
void pop_back () noexcept
 Remove back elements from blocks.
 
auto swap_erase (std::size_t index, chunk &other) noexcept -> std::optional< entity >
 Swap end removes a components in blocks at position index and swaps it with the last element from other chunk. Returns std::optional of entity that has been moved or std::nullopt if no entities were moved.
 
auto move (std::size_t index, chunk &other_chunk) -> std::size_t
 Move components in blocks at position index into other_chunk.
 
auto copy (std::size_t index, chunk &other_chunk) -> std::size_t
 Copy components in blocks at position index into other_chunk.
 
constexpr void visit (std::size_t index, auto &&func) noexcept
 Visit components at given index.
 
constexpr void visit (std::size_t index, auto &&func) const noexcept
 Visit components at given index.
 
template<component T>
auto ptr_const (std::size_t index) const -> const T *
 Give a const pointer to a component T at index.
 
template<component T>
auto ptr_mut (std::size_t index) -> T *
 Give a pointer to a component T at index.
 
constexpr auto max_size () const noexcept -> std::size_t
 Get max size, how many elements can this chunk hold.
 
constexpr auto size () const noexcept -> std::size_t
 Return size.
 
constexpr auto full () const noexcept -> bool
 Check if chunk is full.
 
constexpr auto empty () const noexcept -> bool
 Check if chunk is empty.
 

Static Public Attributes

static constexpr std::size_t chunk_bytes = static_cast<const std::size_t>(16U * 1024)
 Chunk size in bytes.
 
static constexpr std::size_t alloc_alignment = alignof(entity)
 Block allocation alignment.
 

Friends

class base_registry
 

Detailed Description

Chunk holds a 16 Kb block of memory that holds components in blocks: |A1|A2|A3|...padding|B1|B2|B3|...padding|C1|C2|C3...padding where A, B, C are component types and A1, B1, C1 and others are components instances.

Constructor & Destructor Documentation

◆ chunk() [1/3]

co_ecs::chunk::chunk ( const blocks_type & blocks,
std::size_t max_size )
inline

Construct a new chunk object.

Parameters
blocksComponent blocks
max_sizeMaxium size of entries this chunk can hold

◆ chunk() [2/3]

co_ecs::chunk::chunk ( const chunk & rhs)
delete

Deleted copy constructor.

Parameters
rhsAnother chunk

◆ chunk() [3/3]

co_ecs::chunk::chunk ( chunk && rhs)
inlinenoexcept

Move constructor.

Parameters
rhsAnother chunk

◆ ~chunk()

co_ecs::chunk::~chunk ( )
inline

Destroy the chunk object.

Member Function Documentation

◆ copy()

auto co_ecs::chunk::copy ( std::size_t index,
chunk & other_chunk ) -> std::size_t
inline

Copy components in blocks at position index into other_chunk.

Parameters
indexIndex to move from
other_chunkChunk to move to
Returns
std::size_t Other chunk index

◆ emplace_back()

template<component... Args>
void co_ecs::chunk::emplace_back ( entity ent,
Args &&... args )
inline

Emplace back components into blocks.

Template Parameters
ArgsParameter pack
Parameters
entEntity to emplace
argscomponent arguments

◆ empty()

constexpr auto co_ecs::chunk::empty ( ) const -> bool
inlineconstexprnoexcept

Check if chunk is empty.

Returns
true If it is empty
false If it is not empty

◆ full()

constexpr auto co_ecs::chunk::full ( ) const -> bool
inlineconstexprnoexcept

Check if chunk is full.

Returns
true If it is full
false If it is not full

◆ max_size()

constexpr auto co_ecs::chunk::max_size ( ) const -> std::size_t
inlineconstexprnoexcept

Get max size, how many elements can this chunk hold.

Returns
std::size_t Max size of this chunk

◆ move()

auto co_ecs::chunk::move ( std::size_t index,
chunk & other_chunk ) -> std::size_t
inline

Move components in blocks at position index into other_chunk.

Parameters
indexIndex to move from
other_chunkChunk to move to
Returns
std::size_t Other chunk index

◆ operator=() [1/2]

auto co_ecs::chunk::operator= ( chunk && rhs) -> chunk&
inlinenoexcept

Move assignment operator.

Parameters
rhsRight hand side chunk
Returns
chunk& Resulting chunk

◆ operator=() [2/2]

auto co_ecs::chunk::operator= ( const chunk & rhs) -> chunk &=delete
delete

Deleted copy assignment operator.

Parameters
rhsAnother chunk

◆ pop_back()

void co_ecs::chunk::pop_back ( )
inlinenoexcept

Remove back elements from blocks.

◆ ptr_const()

template<component T>
auto co_ecs::chunk::ptr_const ( std::size_t index) const -> const T*
inline

Give a const pointer to a component T at index.

Template Parameters
TComponent type
Parameters
indexIndex
Returns
const T* Resulting pointer

◆ ptr_mut()

template<component T>
auto co_ecs::chunk::ptr_mut ( std::size_t index) -> T*
inline

Give a pointer to a component T at index.

Template Parameters
TComponent type
Parameters
indexIndex
Returns
const T* Resulting pointer

◆ size()

constexpr auto co_ecs::chunk::size ( ) const -> std::size_t
inlineconstexprnoexcept

Return size.

Returns
std::size_t Size

◆ swap_erase()

auto co_ecs::chunk::swap_erase ( std::size_t index,
chunk & other ) -> std::optional<entity>
inlinenoexcept

Swap end removes a components in blocks at position index and swaps it with the last element from other chunk. Returns std::optional of entity that has been moved or std::nullopt if no entities were moved.

Parameters
indexIndex to remove components from
otherOther chunk
Returns
std::optional<entity>

◆ visit() [1/2]

constexpr void co_ecs::chunk::visit ( std::size_t index,
auto && func ) const
inlineconstexprnoexcept

Visit components at given index.

Parameters
indexIndex of an entity
funcFunc to apply to components

◆ visit() [2/2]

constexpr void co_ecs::chunk::visit ( std::size_t index,
auto && func )
inlineconstexprnoexcept

Visit components at given index.

Parameters
indexIndex of an entity
funcFunc to apply to components

Friends And Related Symbol Documentation

◆ base_registry

friend class base_registry
friend

Member Data Documentation

◆ alloc_alignment

constexpr std::size_t co_ecs::chunk::alloc_alignment = alignof(entity)
staticconstexpr

Block allocation alignment.

◆ chunk_bytes

constexpr std::size_t co_ecs::chunk::chunk_bytes = static_cast<const std::size_t>(16U * 1024)
staticconstexpr

Chunk size in bytes.


The documentation for this class was generated from the following file: