libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
TickableList.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <mutex>
5
8
9namespace Ship {
10
18class TickableList : public PartList<TickableComponent, std::shared_ptr<TickableComponent>> {
19 public:
20 using PartList<TickableComponent, std::shared_ptr<TickableComponent>>::PartList;
21
27
28 protected:
33 void Added(std::shared_ptr<TickableComponent> part, const bool forced) override;
34};
35
37#ifdef COMPONENT_THREAD_SAFE
38 const std::lock_guard<std::recursive_mutex> lock(GetMutex());
39#endif
40 auto& list = GetList();
41 std::stable_sort(list.begin(), list.end(),
42 [](const std::shared_ptr<TickableComponent>& a, const std::shared_ptr<TickableComponent>& b) {
43 return a->GetOrder() < b->GetOrder();
44 });
45 return *this;
46}
47
48inline void TickableList::Added(std::shared_ptr<TickableComponent> /*part*/, const bool /*forced*/) {
49 Sort();
50}
51
52} // namespace Ship
A thread-safe ordered list of Parts.
Definition PartList.h:114
std::recursive_mutex & GetMutex() const
Returns the internal recursive mutex used to guard list access.
Definition PartList.h:745
std::enable_if< std::is_same< P, std::shared_ptr< TickableComponent > >::value, std::vector< P > & >::type GetList()
Direct access to the underlying vector for strong-storage lists.
Definition PartList.h:733
Combines Tickable and Component, auto-registering with a Context.
Definition TickableComponent.h:42
Extends PartList<TickableComponent> with order-aware sorting.
Definition TickableList.h:18
void Added(std::shared_ptr< TickableComponent > part, const bool forced) override
Re-sorts the list after a component is added so that TickGroup / TickPriority ordering is honored dur...
Definition TickableList.h:48
TickableList & Sort()
Sorts the list by each component's composite order value.
Definition TickableList.h:36
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14