#include "App.hpp" #include void App::Init() { if (mInitialized) return; mInitialized = true; mCurrentWorld = std::make_unique(); auto& worldRoot = mCurrentWorld->GetRoot(); constexpr int kPlayerCount = 2; for (int i = 0; i < kPlayerCount; ++i) { auto player = new Player(mCurrentWorld.get(), i); worldRoot.AddChild(player); mPlayers.push_back(player); } mCurrentWorld->Awaken(); mEditor = std::make_unique(this, mCurrentWorld.get()); } void App::Shutdown() { if (!mInitialized) return; mInitialized = false; mEditor = nullptr; mCurrentWorld->Resleep(); mCurrentWorld = nullptr; mPlayers.clear(); } void App::Show() { if (mEditorShown) { mEditor->Show(); } } void App::Update() { } void App::Draw() { mCurrentWorld->Draw(); } 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) { mEditorShown = !mEditorShown; } return; } case GLFW_KEY_F11: { // TODO fullscreen 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)); }