FIX: Cyclic Includes of Scene and duplicate std::variant
This commit is contained in:
parent
d6445092c2
commit
8690efe184
@ -268,6 +268,7 @@ add_library(Engine STATIC
|
||||
engine/src/core/events/ApplicationEvents.h
|
||||
engine/src/core/events/EventChannels.cpp
|
||||
engine/src/core/events/EventChannels.h
|
||||
engine/src/core/events/ApplicationEvents.cpp
|
||||
)
|
||||
target_include_directories(Engine PUBLIC engine/src ${dr_libs_SOURCE_DIR})
|
||||
target_link_libraries(Engine PUBLIC OpenGL::GL glfw glad glm::glm imgui spdlog::spdlog tinyobjloader stb_image OpenAL::OpenAL NetworkCore)
|
||||
|
||||
@ -23,7 +23,7 @@ namespace engine {
|
||||
if constexpr (std::is_same_v<T, QuitRequested>) {
|
||||
m_window->requestWindowClose();
|
||||
} else if constexpr (std::is_same_v<T, SceneSwitchRequested>) {
|
||||
m_sceneManager.switchTo(e.nextScene, std::move(e.onSceneLoaded));
|
||||
m_sceneManager.switchTo(std::move(e.nextScene), std::move(e.onSceneLoaded));
|
||||
}
|
||||
}, event);
|
||||
});
|
||||
|
||||
14
engine/src/core/events/ApplicationEvents.cpp
Normal file
14
engine/src/core/events/ApplicationEvents.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by sebastian on 07.08.26.
|
||||
//
|
||||
#include "ApplicationEvents.h"
|
||||
#include "layer/Scene.h" // hier ist Scene vollständig bekannt
|
||||
|
||||
SceneSwitchRequested::SceneSwitchRequested() = default;
|
||||
|
||||
SceneSwitchRequested::SceneSwitchRequested(std::unique_ptr<engine::Scene> scene, std::function<void()> callback) : nextScene(std::move(scene)), onSceneLoaded(std::move(callback)){
|
||||
}
|
||||
|
||||
SceneSwitchRequested::~SceneSwitchRequested() = default;
|
||||
SceneSwitchRequested::SceneSwitchRequested(SceneSwitchRequested&&) noexcept = default;
|
||||
SceneSwitchRequested& SceneSwitchRequested::operator=(SceneSwitchRequested&&) noexcept = default;
|
||||
@ -4,17 +4,28 @@
|
||||
|
||||
#ifndef COLORRACE_APPLICATIONEVENTS_H
|
||||
#define COLORRACE_APPLICATIONEVENTS_H
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
#include "layer/Scene.h"
|
||||
|
||||
namespace engine {
|
||||
class Scene;
|
||||
}
|
||||
|
||||
struct QuitRequested {};
|
||||
|
||||
struct SceneSwitchRequested {
|
||||
std::unique_ptr<engine::Scene> nextScene;
|
||||
std::function<void()> onSceneLoaded;
|
||||
|
||||
SceneSwitchRequested();
|
||||
SceneSwitchRequested(std::unique_ptr<engine::Scene> scene, std::function<void()> callback);
|
||||
~SceneSwitchRequested();
|
||||
SceneSwitchRequested(SceneSwitchRequested&&) noexcept;
|
||||
SceneSwitchRequested& operator=(SceneSwitchRequested&&) noexcept;
|
||||
};
|
||||
|
||||
|
||||
using ApplicationEvents = std::variant<QuitRequested>;
|
||||
using ApplicationEvents = std::variant<QuitRequested, SceneSwitchRequested>;
|
||||
#endif //COLORRACE_APPLICATIONEVENTS_H
|
||||
|
||||
@ -71,8 +71,12 @@ void MainMenuUiLayer::onAttachImpl() {
|
||||
if (e.success) {
|
||||
spdlog::info("Received positive Connection Result");
|
||||
m_connectionError = false;
|
||||
std::unique_ptr<LobbyScene> lobbyScene = std::make_unique<LobbyScene>(m_applicationEventBus, getInputStack(), getKeyboard(), getMouse());
|
||||
|
||||
std::unique_ptr<engine::Scene> lobbyScene = std::make_unique<LobbyScene>(m_applicationEventBus, getInputStack(), getKeyboard(), getMouse());
|
||||
m_closeConnectPopup = true;
|
||||
ApplicationEvents switchToLobby = SceneSwitchRequested{std::move(lobbyScene), []() {
|
||||
spdlog::info("Lobby Scene loaded");
|
||||
}};
|
||||
m_applicationEventBus->publish(switchToLobby);
|
||||
} else {
|
||||
spdlog::info("Received negative Connection Result");
|
||||
m_connectionError = true;
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#include "LobbyScene.h"
|
||||
|
||||
#include "LobbyUiLayer.h"
|
||||
|
||||
std::vector<engine::AssetRequest> LobbyScene::getRequiredAssets() const {
|
||||
std::vector<engine::AssetRequest> requests;
|
||||
requests.emplace_back(engine::TextureRequest("lobby_background", "assets/textures/multiplayer_lobby.png"));
|
||||
@ -12,6 +14,8 @@ std::vector<engine::AssetRequest> LobbyScene::getRequiredAssets() const {
|
||||
|
||||
void LobbyScene::onEnter() {
|
||||
Scene::onEnter();
|
||||
|
||||
addLayer(std::make_unique<LobbyUiLayer>(m_keyboard, m_mouse, getAnimationEventBus(), m_applicationEventBus, *assetManager));
|
||||
}
|
||||
|
||||
void LobbyScene::onExit() {
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#include "LobbyUiLayer.h"
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
void LobbyUiLayer::onAttachImpl() {
|
||||
Layer::onAttachImpl();
|
||||
|
||||
@ -12,8 +14,17 @@ void LobbyUiLayer::onAttachImpl() {
|
||||
backgroundImage = std::make_unique<engine::GUITexture>(backgroundTexture, glm::vec2(0,0), glm::vec2(1,1));
|
||||
}
|
||||
|
||||
void LobbyUiLayer::onDetachImpl() {
|
||||
Layer::onDetachImpl();
|
||||
}
|
||||
|
||||
void LobbyUiLayer::onRender() {
|
||||
std::vector<engine::GUITexture> guiElements;
|
||||
guiElements.emplace_back(*backgroundImage);
|
||||
m_guiRenderer.render(guiElements);
|
||||
}
|
||||
}
|
||||
|
||||
void LobbyUiLayer::onUpdate(float deltaTime) {
|
||||
Layer::onUpdate(deltaTime);
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
LobbyUiLayer(engine::Keyboard &keyboard, engine::Mouse &mouse,
|
||||
engine::EventBus<engine::animation::AnimationMarkerEvent> &animationEventBus,
|
||||
const std::shared_ptr<engine::EventBus<std::variant<QuitRequested>>> &applicationEventBus, engine::AssetManager& assetManager)
|
||||
const std::shared_ptr<engine::EventBus<ApplicationEvents>> &applicationEventBus, engine::AssetManager& assetManager)
|
||||
: Layer(keyboard, mouse, animationEventBus, applicationEventBus), m_assetManager(assetManager) {
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user