From e7ef3f208c109357538b1f68af10bcd78db95c95 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Fri, 8 Apr 2022 22:30:12 -0700 Subject: Changeset: 3 More work --- source/App.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'source/App.cpp') diff --git a/source/App.cpp b/source/App.cpp index c85dd9e..3907af9 100644 --- a/source/App.cpp +++ b/source/App.cpp @@ -1,30 +1,75 @@ #include "App.hpp" +#include "GLFW/glfw3.h" -#include -#include +#include void App::Init() { + if (mInitialized) return; + mInitialized = true; + mCurrentWorld = std::make_unique(); - auto worldRoot = mCurrentWorld->GetRoot(); + auto& worldRoot = mCurrentWorld->GetRoot(); constexpr int kPlayerCount = 2; for (int i = 0; i < kPlayerCount; ++i) { - auto player = new Player(mCurrentWorld.get()); + auto player = new Player(mCurrentWorld.get(), i); worldRoot.AddChild(player); mPlayers.push_back(player); } + + mCurrentWorld->Awaken(); + mEditor = EditorInstance_Alloc(this, mCurrentWorld.get()); } void App::Shutdown() { + if (!mInitialized) return; + mInitialized = false; + + EditorInstance_Free(mEditor); + mEditor = nullptr; + + mCurrentWorld->Resleep(); mCurrentWorld = nullptr; mPlayers.clear(); } void App::Show() { mCurrentWorld->Draw(); + + if (mEditorShown) { + EditorInstance_Show(mEditor); + } +} + +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) { @@ -33,3 +78,7 @@ void App::HandleKey(GLFWkeyboard* keyboard, int key, int action) { } } } + +void App::PushKeyCaptureCallback(KeyCaptureCallback callback) { + mKeyCaptureCallbacks.push_back(std::move(callback)); +} -- cgit v1.2.3-70-g09d2