diff options
author | rtk0c <[email protected]> | 2022-04-08 22:30:12 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-04-08 22:30:12 -0700 |
commit | e7ef3f208c109357538b1f68af10bcd78db95c95 (patch) | |
tree | 066d614ae0f079e53602d7c0fd972998c546c8c1 /source/App.cpp | |
parent | f163e8f37123e651ea80b690793845b31ddb8639 (diff) |
Changeset: 3 More work
Diffstat (limited to 'source/App.cpp')
-rw-r--r-- | source/App.cpp | 57 |
1 files changed, 53 insertions, 4 deletions
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 <imgui.h> -#include <memory> +#include <utility> void App::Init() { + if (mInitialized) return; + mInitialized = true; + mCurrentWorld = std::make_unique<GameWorld>(); - 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)); +} |