LkEngine 0.1.2
 
Loading...
Searching...
No Matches
LayerStack.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "Layer.h"
8
9namespace LkEngine {
10
24 class LLayerStack : public LObject
25 {
26 public:
27 LLayerStack() = default;
29
33 void Destroy();
34
38 FORCEINLINE void PushLayer(LLayer* Layer)
39 {
40 if (auto Iter = Layers.emplace((Layers.begin() + InsertIndex), Layer); Iter != Layers.end())
41 {
42 InsertIndex++;
43 (*Iter)->OnAttach();
44 }
45 }
46
50 FORCEINLINE void PushLayer(TObjectPtr<LLayer> Layer)
51 {
52 if (auto Iter = Layers.emplace((Layers.begin() + InsertIndex), Layer); Iter != Layers.end())
53 {
54 InsertIndex++;
55 (*Iter)->OnAttach();
56 }
57 }
58
62 FORCEINLINE void PushOverlay(TObjectPtr<LLayer> Overlay)
63 {
64 if (Layers.emplace_back(Overlay))
65 {
66 Overlay->OnAttach();
67 }
68 }
69
73 FORCEINLINE void PopLayer(TObjectPtr<LLayer> Layer)
74 {
75 auto Iter = std::find(Layers.begin(), Layers.begin() + InsertIndex, Layer);
76 if (Iter != (Layers.begin() + InsertIndex))
77 {
78 Layer->OnDetach();
79
80 Layers.erase(Iter);
81 InsertIndex--;
82 }
83 }
84
88 FORCEINLINE void PopOverlay(TObjectPtr<LLayer> Overlay)
89 {
90 auto Iter = std::find(Layers.begin() + InsertIndex, Layers.end(), Overlay);
91 if (Iter != Layers.end())
92 {
93 Overlay->OnDetach();
94
95 Layers.erase(Iter);
96 }
97 }
98
99 FORCEINLINE TObjectPtr<LLayer> operator[](const std::size_t LayerIndex)
100 {
101 LK_ASSERT((LayerIndex >= 0) && (LayerIndex < Layers.size()), "Invalid layer index: {}", LayerIndex);
102 return Layers[LayerIndex];
103 }
104
105 FORCEINLINE TObjectPtr<LLayer> operator[](const std::size_t LayerIndex) const
106 {
107 LK_ASSERT((LayerIndex >= 0) && (LayerIndex < Layers.size()), "Invalid layer index: {}", LayerIndex);
108 return Layers.at(LayerIndex);
109 }
110
114 FORCEINLINE int Count() const
115 {
116 return static_cast<int>(Layers.size());
117 }
118
119 std::vector<TObjectPtr<LLayer>>::iterator begin() { return Layers.begin(); }
120 std::vector<TObjectPtr<LLayer>>::iterator end() { return Layers.end(); }
121
122 private:
127 std::vector<TObjectPtr<LLayer>> Layers{};
128
133 uint32_t InsertIndex = 0;
134
135 LCLASS(LLayerStack);
136 };
137
138
139}
Base layer.
Definition LayerStack.h:25
FORCEINLINE void PushLayer(TObjectPtr< LLayer > Layer)
Push a layer to top of the layer stack.
Definition LayerStack.h:50
FORCEINLINE void PopLayer(TObjectPtr< LLayer > Layer)
Pop a layer from the stack.
Definition LayerStack.h:73
FORCEINLINE void PushLayer(LLayer *Layer)
Push a layer to top of the layer stack.
Definition LayerStack.h:38
void Destroy()
Destroy the layer stack, releasing all layers.
Definition LayerStack.cpp:15
FORCEINLINE void PushOverlay(TObjectPtr< LLayer > Overlay)
Push an overlay to top of the stack.
Definition LayerStack.h:62
FORCEINLINE void PopOverlay(TObjectPtr< LLayer > Overlay)
Pop an overlay from the stack.
Definition LayerStack.h:88
FORCEINLINE int Count() const
Get the count of layers.
Definition LayerStack.h:114
Definition Layer.h:23
Definition Object.h:46
Definition ObjectPtr.h:102
#define LCLASS(Class)
Definition CoreMacros.h:226
Definition Asset.h:11