Compare commits
2 Commits
60f6c9281b
...
5dd3cc1b73
| Author | SHA1 | Date | |
|---|---|---|---|
| 5dd3cc1b73 | |||
| b98f46f425 |
@@ -155,6 +155,9 @@ void Application::Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderPresent(m_Renderer);
|
SDL_RenderPresent(m_Renderer);
|
||||||
|
|
||||||
|
// handle layercommands here after each frame
|
||||||
|
m_LayerStack.ProcessCommands();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "LayerStack.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -8,12 +9,22 @@ Layer::Layer(const std::string &name, bool isActive) : m_LayerName(name), m_isAc
|
|||||||
|
|
||||||
void Layer::QueueTransition(std::unique_ptr<Layer> toLayer) {
|
void Layer::QueueTransition(std::unique_ptr<Layer> toLayer) {
|
||||||
// TODO: redo this based on the event video
|
// TODO: redo this based on the event video
|
||||||
|
// basically handle it like the other layer stuff
|
||||||
|
// put it into a vector and go over the list at the end of the application loop
|
||||||
auto &layerStack = Application::Get().m_LayerStack;
|
auto &layerStack = Application::Get().m_LayerStack;
|
||||||
for (auto &layer : layerStack) {
|
|
||||||
if (layer.get() == this) {
|
LayerCommand command;
|
||||||
layer = std::move(toLayer);
|
command.action = LayerAction::Transition;
|
||||||
return;
|
command.targetLayer = this;
|
||||||
}
|
command.newLayer = std::move(toLayer);
|
||||||
}
|
|
||||||
|
layerStack.SubmitCommand(std::move(command));
|
||||||
|
|
||||||
|
// for (auto &layer : layerStack) {
|
||||||
|
// if (layer.get() == this) {
|
||||||
|
// layer = std::move(toLayer);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
} // namespace SakuraVNE
|
} // namespace SakuraVNE
|
||||||
|
|||||||
@@ -7,10 +7,40 @@ namespace SakuraVNE {
|
|||||||
LayerStack::~LayerStack() {
|
LayerStack::~LayerStack() {
|
||||||
for (auto &layer : m_LayerStack) {
|
for (auto &layer : m_LayerStack) {
|
||||||
layer->OnDetach();
|
layer->OnDetach();
|
||||||
// delete layer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LayerStack::SubmitCommand(LayerCommand command) { m_CommandQueue.push_back(std::move(command)); }
|
||||||
|
|
||||||
|
void LayerStack::ProcessCommands() {
|
||||||
|
if (m_CommandQueue.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &command : m_CommandQueue) {
|
||||||
|
switch (command.action) {
|
||||||
|
case LayerAction::Pop:
|
||||||
|
PopLayer(command.targetLayer);
|
||||||
|
break;
|
||||||
|
case LayerAction::Push:
|
||||||
|
PushLayer(std::move(command.newLayer));
|
||||||
|
break;
|
||||||
|
case LayerAction::Transition:
|
||||||
|
auto it = std::find_if(m_LayerStack.begin(), m_LayerStack.end(), [&](const std::unique_ptr<Layer> &layer) { return layer.get() == command.targetLayer; });
|
||||||
|
|
||||||
|
if (it != m_LayerStack.end()) {
|
||||||
|
(*it)->OnDetach();
|
||||||
|
command.newLayer->OnAttach();
|
||||||
|
|
||||||
|
*it = std::move(command.newLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_CommandQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void LayerStack::PushLayer(std::unique_ptr<Layer> layer) {
|
void LayerStack::PushLayer(std::unique_ptr<Layer> layer) {
|
||||||
m_LayerStack.emplace(m_LayerStack.begin() + m_LayerIndex, std::move(layer));
|
m_LayerStack.emplace(m_LayerStack.begin() + m_LayerIndex, std::move(layer));
|
||||||
m_LayerIndex++;
|
m_LayerIndex++;
|
||||||
|
|||||||
@@ -6,6 +6,14 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace SakuraVNE {
|
namespace SakuraVNE {
|
||||||
|
enum class LayerAction { Push, Pop, Transition };
|
||||||
|
|
||||||
|
struct LayerCommand {
|
||||||
|
LayerAction action;
|
||||||
|
Layer *targetLayer;
|
||||||
|
std::unique_ptr<Layer> newLayer;
|
||||||
|
};
|
||||||
|
|
||||||
class LayerStack {
|
class LayerStack {
|
||||||
public:
|
public:
|
||||||
LayerStack() = default;
|
LayerStack() = default;
|
||||||
@@ -26,11 +34,15 @@ public:
|
|||||||
std::vector<std::unique_ptr<Layer>>::const_reverse_iterator rbegin() const { return m_LayerStack.rbegin(); }
|
std::vector<std::unique_ptr<Layer>>::const_reverse_iterator rbegin() const { return m_LayerStack.rbegin(); }
|
||||||
std::vector<std::unique_ptr<Layer>>::const_reverse_iterator rend() const { return m_LayerStack.rend(); }
|
std::vector<std::unique_ptr<Layer>>::const_reverse_iterator rend() const { return m_LayerStack.rend(); }
|
||||||
|
|
||||||
|
void SubmitCommand(LayerCommand command);
|
||||||
|
void ProcessCommands();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// this is only used for the tests for now, so it will be taken out of the release build
|
// this is only used for the tests for now, so it will be taken out of the release build
|
||||||
inline const std::vector<std::unique_ptr<Layer>> &GetLayers() const { return m_LayerStack; }
|
inline const std::vector<std::unique_ptr<Layer>> &GetLayers() const { return m_LayerStack; }
|
||||||
#endif
|
#endif
|
||||||
private:
|
private:
|
||||||
|
std::vector<LayerCommand> m_CommandQueue;
|
||||||
std::vector<std::unique_ptr<Layer>> m_LayerStack;
|
std::vector<std::unique_ptr<Layer>> m_LayerStack;
|
||||||
unsigned int m_LayerIndex = 0;
|
unsigned int m_LayerIndex = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ void Window::Create() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add the window callbacks here as seperate functions because sdl functions that way
|
|
||||||
// each of them will get a function which will receive a window event filled in with the window's data (id (i guess))
|
|
||||||
// and then they will dispatch it to the event system using the same raise event
|
|
||||||
|
|
||||||
void Window::ProcessEvent(const SDL_Event &event) {
|
void Window::ProcessEvent(const SDL_Event &event) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_EVENT_WINDOW_CLOSE_REQUESTED: {
|
case SDL_EVENT_WINDOW_CLOSE_REQUESTED: {
|
||||||
|
|||||||
Reference in New Issue
Block a user