aboutsummaryrefslogtreecommitdiff
path: root/source/30-game
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-07-07 19:31:19 -0700
committerrtk0c <[email protected]>2022-07-07 19:31:19 -0700
commiteeed6d84f4324387597be05e6ed1df4b3adfca9c (patch)
tree039f2ed112d8671001e2ba4d11533ea1406a41b0 /source/30-game
parenta98b0495a957ed15900c052bcad00b3c48367546 (diff)
Changeset: 80 Add skeleton for keyboard management GUI in editor
Diffstat (limited to 'source/30-game')
-rw-r--r--source/30-game/EditorAccessories.cpp22
-rw-r--r--source/30-game/EditorAccessories.hpp6
-rw-r--r--source/30-game/EditorCorePrivate.cpp9
-rw-r--r--source/30-game/EditorCorePrivate.hpp6
-rw-r--r--source/30-game/Input.cpp23
-rw-r--r--source/30-game/Input.hpp23
-rw-r--r--source/30-game/main.cpp29
7 files changed, 112 insertions, 6 deletions
diff --git a/source/30-game/EditorAccessories.cpp b/source/30-game/EditorAccessories.cpp
index 08d08ec..821d41e 100644
--- a/source/30-game/EditorAccessories.cpp
+++ b/source/30-game/EditorAccessories.cpp
@@ -1,6 +1,26 @@
#include "EditorAccessories.hpp"
+#include "Input.hpp"
+
+#define GLFW_INCLUDE_NONE
+#include <GLFW/glfw3.h>
+
#include <imgui.h>
-void EditorSettings::Show() {
+void EditorKeyboardViewer::Show(bool* open) {
+ ImGui::Begin("Keyboards", open);
+
+ int count;
+ GLFWkeyboard** keyboards = glfwGetKeyboards(&count);
+
+ for (int i = 0; i < count; ++i) {
+ GLFWkeyboard* keyboard = keyboards[i];
+ auto attachment = static_cast<GlfwKeyboardAttachment*>(glfwGetKeyboardUserPointer(keyboard));
+
+ ImGui::BulletText("%s", glfwGetKeyboardName(keyboard));
+ ImGui::Indent();
+ ImGui::Unindent();
+ }
+
+ ImGui::End();
}
diff --git a/source/30-game/EditorAccessories.hpp b/source/30-game/EditorAccessories.hpp
index 687b509..56a8238 100644
--- a/source/30-game/EditorAccessories.hpp
+++ b/source/30-game/EditorAccessories.hpp
@@ -1,6 +1,8 @@
#pragma once
-class EditorSettings {
+#include "Player.hpp"
+
+class EditorKeyboardViewer {
public:
- void Show();
+ void Show(bool* open = nullptr);
};
diff --git a/source/30-game/EditorCorePrivate.cpp b/source/30-game/EditorCorePrivate.cpp
index b335c60..e52c795 100644
--- a/source/30-game/EditorCorePrivate.cpp
+++ b/source/30-game/EditorCorePrivate.cpp
@@ -407,7 +407,9 @@ struct CreatableGameObject {
void SaveRendererBindings(const Renderer& renderer) {
auto file = Utils::OpenCstdioFile("assets/GameRendererBindings.json", Utils::WriteTruncate);
if (!file) return;
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char writerBuffer[65536];
rapidjson::FileWriteStream stream(file, writerBuffer, sizeof(writerBuffer));
@@ -459,6 +461,7 @@ void EditorInstance::Show() {
ImGui::MenuItem("Command Palette", "Ctrl+Shift+P", &mWindowVisible_CommandPalette);
ImGui::MenuItem("Inspector", nullptr, &mWindowVisible_Inspector);
ImGui::MenuItem("Content Browser", "Ctrl+Space", &mWindowVisible_ContentBrowser);
+ ImGui::MenuItem("Keyboard Viewer", nullptr, &mWindowVisible_KeyboardViewer);
ImGui::MenuItem("World Structure", nullptr, &mWindowVisible_WorldStructure);
ImGui::MenuItem("World Properties", nullptr, &mWindowVisible_WorldProperties);
ImGui::EndMenu();
@@ -483,6 +486,10 @@ void EditorInstance::Show() {
mEdContentBrowser.Show(&mWindowVisible_ContentBrowser);
}
+ if (mWindowVisible_KeyboardViewer) {
+ mEdKbViewer.Show(&mWindowVisible_KeyboardViewer);
+ }
+
auto& camera = *mApp->GetActiveCamera();
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
ImGuizmo::SetDrawlist(ImGui::GetBackgroundDrawList());
diff --git a/source/30-game/EditorCorePrivate.hpp b/source/30-game/EditorCorePrivate.hpp
index e70f5ec..4071e7a 100644
--- a/source/30-game/EditorCorePrivate.hpp
+++ b/source/30-game/EditorCorePrivate.hpp
@@ -1,10 +1,10 @@
#pragma once
-#include "EditorCore.hpp"
-
#include "App.hpp"
+#include "EditorAccessories.hpp"
#include "EditorAttachment.hpp"
#include "EditorCommandPalette.hpp"
+#include "EditorCore.hpp"
#include "EditorUtils.hpp"
#include "EditorWorldGuides.hpp"
#include "GameObject.hpp"
@@ -86,6 +86,7 @@ private:
EditorCommandPalette mEdCommandPalette;
EditorInspector mEdInspector;
EditorContentBrowser mEdContentBrowser;
+ EditorKeyboardViewer mEdKbViewer;
EditorWorldGuides mEdGuides;
GuizmoState mGuizmo;
glm::vec3 mDragCam_CamInitial;
@@ -101,6 +102,7 @@ private:
bool mWindowVisible_ContentBrowser = true;
bool mWindowVisible_WorldStructure = true;
bool mWindowVisible_WorldProperties = true;
+ bool mWindowVisible_KeyboardViewer = false;
bool mDragCam_Happening = false;
bool mMoveCamKeyboard = false;
bool mMoveCamScrollWheel = false;
diff --git a/source/30-game/Input.cpp b/source/30-game/Input.cpp
new file mode 100644
index 0000000..9f304ff
--- /dev/null
+++ b/source/30-game/Input.cpp
@@ -0,0 +1,23 @@
+#include "Input.hpp"
+
+#include <cassert>
+
+GLFWkeyboard* InputState::FindKeyboard(std::string_view name) {
+ assert(false);
+ // TODO
+}
+
+GlfwKeyboardAttachment* InputState::ConnectKeyboard(GLFWkeyboard* keyboard) {
+ auto attachment = new GlfwKeyboardAttachment();
+ glfwSetKeyboardUserPointer(keyboard, attachment);
+
+ return attachment;
+}
+
+void InputState::DisconnectKeyboard(GLFWkeyboard* keyboard) {
+ InputState::instance->DisconnectKeyboard(keyboard);
+ auto attachment = static_cast<GlfwKeyboardAttachment*>(glfwGetKeyboardUserPointer(keyboard));
+ // Defensive: this GLFWkeyboard* will be deleted after this callback ends anyways
+ glfwSetKeyboardUserPointer(keyboard, nullptr);
+ delete attachment;
+}
diff --git a/source/30-game/Input.hpp b/source/30-game/Input.hpp
new file mode 100644
index 0000000..feb50f0
--- /dev/null
+++ b/source/30-game/Input.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#define GLFW_INCLUDE_NONE
+#include <GLFW/glfw3.h>
+
+#include <string_view>
+#include <utility>
+#include <vector>
+
+/// Extra data attached to a GLFWkeyboard object
+struct GlfwKeyboardAttachment {
+};
+
+class InputState {
+public:
+ static inline InputState* instance = nullptr;
+
+public:
+ GLFWkeyboard* FindKeyboard(std::string_view name);
+
+ GlfwKeyboardAttachment* ConnectKeyboard(GLFWkeyboard* keyboard);
+ void DisconnectKeyboard(GLFWkeyboard* keyboard);
+};
diff --git a/source/30-game/main.cpp b/source/30-game/main.cpp
index d98f225..59d6fea 100644
--- a/source/30-game/main.cpp
+++ b/source/30-game/main.cpp
@@ -3,6 +3,7 @@
#include "AppConfig.hpp"
#include "CommonVertexIndex.hpp"
#include "ImGuiGuizmo.hpp"
+#include "Input.hpp"
#include "Ires.hpp"
#include "Level.hpp"
#include "Material.hpp"
@@ -36,6 +37,23 @@ void GlfwErrorCallback(int error, const char* description) {
fprintf(stderr, "[GLFW] Error %d: %s\n", error, description);
}
+void GlfwKeyboardCallback(GLFWkeyboard* keyboard, int event) {
+ if (InputState::instance == nullptr) {
+ // Called before initialization, skipping because we'll do a collect pass anyways when initializing
+ return;
+ }
+
+ switch (event) {
+ case GLFW_CONNECTED: {
+ InputState::instance->ConnectKeyboard(keyboard);
+ } break;
+
+ case GLFW_DISCONNECTED: {
+ InputState::instance->DisconnectKeyboard(keyboard);
+ } break;
+ }
+}
+
void OpenGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
}
@@ -194,6 +212,7 @@ int main(int argc, char* argv[]) {
}
glfwSetErrorCallback(&GlfwErrorCallback);
+ glfwSetKeyboardCallback(&GlfwKeyboardCallback);
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
@@ -276,6 +295,16 @@ int main(int argc, char* argv[]) {
ImGui_ImplOpenGL2_Init();
}
+ InputState::instance = new InputState();
+ {
+ int count;
+ GLFWkeyboard** list = glfwGetKeyboards(&count);
+ for (int i = 0; i < count; ++i) {
+ GLFWkeyboard* keyboard = list[i];
+ InputState::instance->ConnectKeyboard(keyboard);
+ }
+ }
+
IresManager::instance = new IresManager();
IresManager::instance->DiscoverFilesDesignatedLocation();