#include "App.hpp" #include App::App() { auto& worldRoot = mWorld.GetRoot(); constexpr int kPlayerCount = 2; for (int i = 0; i < kPlayerCount; ++i) { auto player = new Player(&mWorld, i); worldRoot.AddChild(player); mPlayers.push_back(player); }; #if defined(BRUSSEL_DEV_ENV) SetGameRunning(false); SetEditorVisible(true); #else SetGameRunning(true); #endif // TODO this renders nothing, fix mGameCamera.Move(glm::vec3(0, 0, 1)); mGameCamera.LookAt(glm::vec3(0, 0, 0)); mGameCamera.SetHasPerspective(false); mEditorCamera.Move(glm::vec3(0, 0, 1)); mEditorCamera.LookAt(glm::vec3(0, 0, 0)); mGameCamera.SetHasPerspective(false); } App::~App() { } bool App::IsGameRunning() const { return mGameRunning; } void App::SetGameRunning(bool running) { if (mGameRunning != running) { mGameRunning = running; if (running) { mWorld.Awaken(); } else { mWorld.Resleep(); } } } bool App::IsEditorVisible() const { return mEditorVisible; } void App::SetEditorVisible(bool visible) { if (mEditorVisible != visible) { mEditorVisible = visible; if (visible) { if (mEditor == nullptr) { mEditor = std::make_unique(this, &mWorld); } } } } void App::Show() { if (mEditorVisible) { mEditor->Show(); } } void App::Update() { if (IsGameRunning()) { mWorld.Update(); } } void App::Draw(float currentTime, float deltaTime) { Camera* camera; if (IsGameRunning()) { camera = &mGameCamera; } else { camera = &mEditorCamera; } mRenderer.BeginFrame(*camera, currentTime, deltaTime); PodVector stack; stack.push_back(&mWorld.GetRoot()); while (!stack.empty()) { auto obj = stack.back(); stack.pop_back(); for (auto child : obj->GetChildren()) { stack.push_back(child); } auto renderObjects = obj->GetRenderObjects(); mRenderer.Draw(renderObjects.data(), renderObjects.size()); } mRenderer.EndFrame(); } void App::HandleMouse(int button, int action) { } void App::HandleMouseMotion(double xOff, double yOff) { } void App::HandleKey(GLFWkeyboard* keyboard, int key, int action) { if (!mKeyCaptureCallbacks.empty()) { auto& callback = mKeyCaptureCallbacks.front(); bool remove = callback(key, action); if (remove) { mKeyCaptureCallbacks.pop_front(); } } switch (key) { case GLFW_KEY_F3: { if (action == GLFW_PRESS) { SetEditorVisible(!IsEditorVisible()); } return; } } for (auto& player : mPlayers) { for (auto playerKeyboard : player->boundKeyboards) { if (playerKeyboard == keyboard) { player->HandleKeyInput(key, action); } } } } void App::PushKeyCaptureCallback(KeyCaptureCallback callback) { mKeyCaptureCallbacks.push_back(std::move(callback)); }