entity
Entity/Component System for C++
entity::component::dense_pool< T > Class Template Reference

Description

template<typename T>
class entity::component::dense_pool< T >

Definition at line 53 of file dense_pool.hpp.

Instances and minimal complete definitions

struct  window
 

Friends

class creation_queue< dense_pool< T > >
 
class destruction_queue< dense_pool< T > >
 

Public Types

typedef iterator_impl iterator
 
typedef T type
 

Public Member Functions

template<typename... Args>
void auto_create_components (entity_pool &owner_pool, Args &&...constructor_args)
 
iterator begin ()
 
template<typename... Args>
T * create (entity e, Args &&...args)
 
 dense_pool (entity_pool &owner_pool, T const &default_value=T())
 
void destroy (entity e)
 
iterator end ()
 
T * get (entity e)
 
T const * get (entity e) const
 
std::size_t size ()
 
window view ()
 

Methods

template<typename T >
friend class creation_queue< dense_pool< T > >
friend

Definition at line 352 of file dense_pool.hpp.

template<typename T >
friend class destruction_queue< dense_pool< T > >
friend

Definition at line 353 of file dense_pool.hpp.

Member Function Documentation

template<typename T >
template<typename... Args>
void entity::component::dense_pool< T >::auto_create_components ( entity_pool owner_pool,
Args &&...  constructor_args 
)

Definition at line 244 of file dense_pool.hpp.

References entity::entity_pool::signal_list::on_entity_create, and entity::entity_pool::signals().

245  {
246  slots_.entity_create_handler =
247  owner_pool.signals().on_entity_create.connect(
248  std::function<void(entity)>(
249  [this, constructor_args...](entity e)
250  {
251  create_entity_slot(e);
252  create(e, constructor_args...);
253  }
254  )
255  )
256  ;
257  }
template<typename T >
iterator entity::component::dense_pool< T >::begin ( )

Definition at line 326 of file dense_pool.hpp.

327  {
328  return iterator(this, 0);
329  }
template<typename T >
template<typename... Args>
T* entity::component::dense_pool< T >::create ( entity  e,
Args &&...  args 
)

Definition at line 277 of file dense_pool.hpp.

Referenced by entity::component::dense_pool< T >::dense_pool().

278  {
279  set_available(e.index(), false);
280  T* ret_val = get_component(e.index());
281  new(ret_val) T(std::forward<Args>(args)...);
282  ++used_count_;
283  return ret_val;
284  }
template<typename T >
void entity::component::dense_pool< T >::destroy ( entity  e)

Definition at line 296 of file dense_pool.hpp.

297  {
298  BOOST_ASSERT(!is_available(e.index()) && "Trying to destroy un-allocated component.");
299  --used_count_;
300  T* p = get_component(e.index());
301  p->~T();
302 
303  set_available(e.index(), true);
304  }
template<typename T >
iterator entity::component::dense_pool< T >::end ( )

Definition at line 331 of file dense_pool.hpp.

332  {
333  return iterator(this, available_.size());
334  }
template<typename T >
T* entity::component::dense_pool< T >::get ( entity  e)

Definition at line 306 of file dense_pool.hpp.

307  {
308  if(is_available(e.index()))
309  {
310  return nullptr;
311  }
312 
313  return get_component(e.index());
314  }
template<typename T >
T const* entity::component::dense_pool< T >::get ( entity  e) const

Definition at line 316 of file dense_pool.hpp.

317  {
318  if(is_available(e.index()))
319  {
320  return nullptr;
321  }
322 
323  return get_component(e.index());
324  }
template<typename T >
std::size_t entity::component::dense_pool< T >::size ( )

Definition at line 341 of file dense_pool.hpp.

342  {
343  return used_count_;
344  }
template<typename T >
window entity::component::dense_pool< T >::view ( )

Definition at line 336 of file dense_pool.hpp.

337  {
338  return window(this);
339  }

Member Typedef Documentation

template<typename T >
typedef iterator_impl entity::component::dense_pool< T >::iterator

Definition at line 127 of file dense_pool.hpp.

template<typename T >
typedef T entity::component::dense_pool< T >::type

Definition at line 126 of file dense_pool.hpp.

Constructor & Destructor Documentation

template<typename T >
entity::component::dense_pool< T >::dense_pool ( entity_pool owner_pool,
T const &  default_value = T() 
)

Definition at line 186 of file dense_pool.hpp.

References entity::entity_pool::begin(), entity::component::dense_pool< T >::create(), entity::entity_pool::end(), entity::for_each(), entity::entity_pool::signal_list::on_entity_create, entity::entity_pool::signal_list::on_entity_destroy, entity::entity_pool::signal_list::on_entity_swap, entity::entity_pool::signals(), and entity::entity_pool::size().

187  : used_count_(0)
188  {
189  components_.resize(owner_pool.size());
190  available_.resize(owner_pool.size(), true);
191 
192  #if ENTITY_SUPPORT_VARIADICS
193  auto create_func = &dense_pool::create<T const&>;
194  #else
195  auto create_func = &dense_pool::create;
196  #endif
197 
198  // Create default values for existing entities.
200  owner_pool.begin(),
201  owner_pool.end(),
202  boost::bind(
203  create_func,
204  this,
205  ::_1,
206  boost::ref(default_value)
207  )
208  );
209 
210  slots_.entity_create_handler =
211  owner_pool.signals().on_entity_create.connect(
212  boost::bind(
213  &dense_pool::handle_create_entity,
214  this,
215  ::_1
216  )
217  )
218  ;
219 
220  slots_.entity_destroy_handler =
221  owner_pool.signals().on_entity_destroy.connect(
222  boost::bind(
223  &dense_pool::handle_destroy_entity,
224  this,
225  ::_1
226  )
227  )
228  ;
229 
230  slots_.entity_swap_handler =
231  owner_pool.signals().on_entity_swap.connect(
232  boost::bind(
233  &dense_pool::handle_swap_entity,
234  this,
235  ::_1,
236  ::_2
237  )
238  )
239  ;
240  }
T * create(entity e, Args &&...args)
Definition: dense_pool.hpp:277
void for_each(EntityList const &entities, ComponentPoolTuple &&p, iterator_traits::is_incremental_tag, Fn f)
Definition: for_each.hpp:37