diff --git a/BarinkEngine/BarinkEngine.cpp b/BarinkEngine/BarinkEngine.cpp index 914eebf..a078e49 100644 --- a/BarinkEngine/BarinkEngine.cpp +++ b/BarinkEngine/BarinkEngine.cpp @@ -1,5 +1,4 @@ #include "BarinkEngine.h" -#include EngineStatistics* ES; BarinkEngine::InputManager InputSystem; @@ -9,17 +8,33 @@ int main(int argc, char* argv[]) { PerfomanceSamplerInit(); - // Startup services - BarinkWindow MainWindow = BarinkWindow(800, 600); + // Create the window + BarinkWindow MainWindow = BarinkWindow(800, 600); + // ================================================= + // Startup services + // ================================================= + + // Startup Renderer BarinkEngine::Renderer renderer = BarinkEngine::Renderer(); + + + // Startup InputManager InputSystem = BarinkEngine::InputManager(); InputSystem.attach(&MainWindow); + InputSystem.setupGLFWInput(MainWindow.windowptr()); + + + // Startup GUI System GUIManager GUISystem = GUIManager(&MainWindow); + + + // Enable depth testing + // NOTE: TODO Move this into the renderer glEnable(GL_DEPTH_TEST); @@ -58,6 +73,9 @@ int main(int argc, char* argv[]) { // Shutdown Services delete ES; + InputSystem.detach(&MainWindow); + + return 0; } diff --git a/BarinkEngine/Include/AssetManager/ModelImporter.h b/BarinkEngine/Include/AssetManager/ModelImporter.h index be98a83..f00be0d 100644 --- a/BarinkEngine/Include/AssetManager/ModelImporter.h +++ b/BarinkEngine/Include/AssetManager/ModelImporter.h @@ -11,16 +11,13 @@ #include class ModelImporter { + +public: + static std::vector Import(std::string path); + + private: - void ImportFBX(std::string path); - void ImportBlend(std::string path); - void ImportGLTF(std::string path); - void ImportOBJ(std::string path); static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene); static std::vector ModelImporter::processNode(aiNode* node, const aiScene* scene); -public: - void Import(std::string path); - - static std::vector Test(); }; \ No newline at end of file diff --git a/BarinkEngine/Include/BarinkEngine.h b/BarinkEngine/Include/BarinkEngine.h index 6471ec1..1513e0b 100644 --- a/BarinkEngine/Include/BarinkEngine.h +++ b/BarinkEngine/Include/BarinkEngine.h @@ -13,6 +13,8 @@ #include "Graphics/Renderer.h" #include "Graphics/GUI/GUIManager.h" #include "Scene.h" + + #include "PerfCounter.h" diff --git a/BarinkEngine/Include/EventSystem/Event.h b/BarinkEngine/Include/EventSystem/Event.h index 9489364..4c51ef5 100644 --- a/BarinkEngine/Include/EventSystem/Event.h +++ b/BarinkEngine/Include/EventSystem/Event.h @@ -5,7 +5,5 @@ struct Event { public: std::string name; - int argc; - void** argv; - + }; \ No newline at end of file diff --git a/BarinkEngine/Include/EventSystem/EventEmitter.h b/BarinkEngine/Include/EventSystem/EventEmitter.h index aa3144c..218a0c7 100644 --- a/BarinkEngine/Include/EventSystem/EventEmitter.h +++ b/BarinkEngine/Include/EventSystem/EventEmitter.h @@ -6,10 +6,12 @@ class EventEmitter { public: void Subscribe (EventListener& subscriber); void Unsubscribe(EventListener& subscriber); + void EmitEvent(Event& incident); + protected: std::list subscribers; - void EmitEvent(Event& incident); + EventEmitter(); diff --git a/BarinkEngine/Include/EventSystem/InputSystemEvents.h b/BarinkEngine/Include/EventSystem/InputSystemEvents.h new file mode 100644 index 0000000..5b123e0 --- /dev/null +++ b/BarinkEngine/Include/EventSystem/InputSystemEvents.h @@ -0,0 +1,18 @@ +#pragma once +#include "Event.h" + + +struct KEY_DOWN_EVENT : public Event { +public: + int scancode; + int keycode; + int mods; +}; + +struct KEY_UP_EVENT : public Event { +public: + int scancode; + int keycode; + int mods; + +}; diff --git a/BarinkEngine/Include/Graphics/Renderable.h b/BarinkEngine/Include/Graphics/Renderable.h index e7c2ee9..399d6b8 100644 --- a/BarinkEngine/Include/Graphics/Renderable.h +++ b/BarinkEngine/Include/Graphics/Renderable.h @@ -28,10 +28,10 @@ public: ~Renderable(); - static Renderable* Load(); + static Renderable* Load(std::string& path); void Draw(); private: std::vector meshes; - Renderable(); + Renderable(std::string& path); }; \ No newline at end of file diff --git a/BarinkEngine/Include/Input/GLFWInput.h b/BarinkEngine/Include/Input/GLFWInput.h new file mode 100644 index 0000000..916c64c --- /dev/null +++ b/BarinkEngine/Include/Input/GLFWInput.h @@ -0,0 +1,14 @@ +#pragma once +#include "GLFW/glfw3.h" + +namespace BarinkEngine { + namespace Input { + + void BE_GLFW_KEYS(GLFWwindow* window, int key, int scancode, int action, int mods); + void BE_GLFW_CURSOR_POSITION(GLFWwindow* window, double x, double y); + void BE_GLFW_CURSOR_ENTER(GLFWwindow* window, int entered); + void BE_GLFW_MOUSE_BUTTON(GLFWwindow* window, int button, int action, int mods); + void BE_GLFW_SCROLL(GLFWwindow* window, double xoffset, double yoffset); + + } +} diff --git a/BarinkEngine/Include/Input/InputManager.h b/BarinkEngine/Include/Input/InputManager.h index 5a9e2c0..71e257a 100644 --- a/BarinkEngine/Include/Input/InputManager.h +++ b/BarinkEngine/Include/Input/InputManager.h @@ -1,27 +1,29 @@ #pragma once -#include +#include + #include "Graphics/Window.h" #include "EventSystem/EventEmitter.h" +#include "../Include/Input/GLFWInput.h" +#include "BarinkEngine.h" namespace BarinkEngine { - class InputManager : EventEmitter { + class InputManager : public EventEmitter { public: InputManager(); void PollEvents(); + void attach(BarinkWindow* window); + void detach(BarinkWindow* window); + void setupGLFWInput(GLFWwindow* window); - // GLFW Handlers - static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); - static void CursorPositionCallback(GLFWwindow* window, double x, double y); - static void CursorEnterCallback(GLFWwindow* window, int entered); - static void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); - static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); + + private: - std::vector windows; + std::list windows; }; } diff --git a/BarinkEngine/Input/GLFWInput.cpp b/BarinkEngine/Input/GLFWInput.cpp new file mode 100644 index 0000000..c4c3524 --- /dev/null +++ b/BarinkEngine/Input/GLFWInput.cpp @@ -0,0 +1,104 @@ +#include "BarinkEngine.h" +#include "../Include/Input/GLFWInput.h" +#include "../Include/EventSystem/InputSystemEvents.h" +#include "../Include/Input/InputManager.h" + + +namespace BarinkEngine { + namespace Input { + + + void BE_GLFW_KEYS(GLFWwindow* window, int key, int scancode, int action, int mods) + { + + switch (action) + { + case GLFW_KEY_DOWN: { + KEY_DOWN_EVENT keydown{}; + keydown.name = "KEY::DOWN"; + keydown.mods = mods; + keydown.scancode = scancode; + keydown.keycode = key; + + InputSystem.EmitEvent(keydown); + break; + + } + + case GLFW_KEY_UP: { + KEY_UP_EVENT keyup{}; + keyup.name = "KEY::DOWN"; + keyup.mods = mods; + keyup.scancode = scancode; + keyup.keycode = key; + + InputSystem.EmitEvent(keyup); + break; + + } + + + + default: + Event KeyEvent{}; + KeyEvent.name = "KEY"; + + InputSystem.EmitEvent(KeyEvent); + + break; + } + + + } + + void BE_GLFW_CURSOR_POSITION(GLFWwindow* window, double x, double y) + { + Event CursorPosUpdate{}; + CursorPosUpdate.name = "UPDATE::CURSOR:POSITION"; + + InputSystem.EmitEvent(CursorPosUpdate); + + + } + + void BE_GLFW_CURSOR_ENTER(GLFWwindow* window, int entered) + { + if (entered) { + Event mouseEntered{}; + mouseEntered.name = "Mouse Entered Window's confines!"; + + InputSystem.EmitEvent(mouseEntered); + + + + } + else { + Event mouseLeft{}; + mouseLeft.name = "Mouse Left Window's confines!"; + + InputSystem.EmitEvent(mouseLeft); + + + } + } + + + void BE_GLFW_MOUSE_BUTTON(GLFWwindow* window, int button, int action, int mods) + { + Event MouseButtonEvent{}; + MouseButtonEvent.name = "MOUSEBUTTON"; + + InputSystem.EmitEvent(MouseButtonEvent); + } + + + void BE_GLFW_SCROLL(GLFWwindow* window, double xoffset, double yoffset) + { + Event ScrollEvent{}; + ScrollEvent.name = "SCROLL"; + + InputSystem.EmitEvent(ScrollEvent); + + } + } +} \ No newline at end of file diff --git a/BarinkEngine/Input/InputManager.cpp b/BarinkEngine/Input/InputManager.cpp index 9922080..8bd5450 100644 --- a/BarinkEngine/Input/InputManager.cpp +++ b/BarinkEngine/Input/InputManager.cpp @@ -1,118 +1,44 @@ -#include "BarinkEngine.h" #include "Input/InputManager.h" -#include "GLFW/glfw3.h" -#include "spdlog/spdlog.h" -#include -void BarinkEngine::InputManager::PollEvents() -{ - for (auto it = windows.begin(); it != windows.end(); ++it) { - (*it)->Poll(); - } -} -void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) -{ +namespace BarinkEngine { - Event KeyEvent{}; - KeyEvent.name = "KEY"; - - InputSystem.EmitEvent(KeyEvent); - - - if (key == GLFW_KEY_A && action == GLFW_PRESS) + void InputManager::PollEvents() { - - std::cout << "'a' key was pressed" << std::endl; + for (auto it = windows.begin(); it != windows.end(); ++it) { + (*it)->Poll(); + } } -} -void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y) -{ - //std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl; - Event CursorPosUpdate{}; - CursorPosUpdate.name = "UPDATE::CURSOR:POSITION"; - - InputSystem.EmitEvent(CursorPosUpdate); - - - -} - -void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered) -{ - if (entered) { - Event mouseEntered {}; - mouseEntered.name = "Mouse Entered Window's confines!"; - mouseEntered.argc = 0; - - InputSystem.EmitEvent(mouseEntered); - - - - } - else { - Event mouseLeft{}; - mouseLeft.name = "Mouse Left Window's confines!"; - mouseLeft.argc = 0; - - InputSystem.EmitEvent(mouseLeft); - - - } -} - - -void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) -{ - - Event MouseButtonEvent{}; - MouseButtonEvent.name = "MOUSEBUTTON"; - - InputSystem.EmitEvent(MouseButtonEvent); - - - if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) { - std::cout << "Right mouse button was pressed!" << std::endl; + void InputManager::setupGLFWInput(GLFWwindow* window) { + // Attach callbacks + glfwSetKeyCallback(window, BarinkEngine::Input::BE_GLFW_KEYS); + glfwSetCursorPosCallback(window, BarinkEngine::Input::BE_GLFW_CURSOR_POSITION); + glfwSetCursorEnterCallback(window, BarinkEngine::Input::BE_GLFW_CURSOR_ENTER); + glfwSetMouseButtonCallback(window, BarinkEngine::Input::BE_GLFW_MOUSE_BUTTON); + glfwSetScrollCallback(window, BarinkEngine::Input::BE_GLFW_SCROLL); } -} -void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) -{ - std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl; - - Event ScrollEvent{}; - ScrollEvent.name = "SCROLL"; + void InputManager::attach(BarinkWindow* window) + { + windows.push_back(window); + this->Subscribe((EventListener&)(*window)); - InputSystem.EmitEvent(ScrollEvent); + } + + void InputManager::detach(BarinkWindow* window) + { + windows.remove(window); + this->Unsubscribe((EventListener&)*window); + } + + + InputManager::InputManager() : EventEmitter() + { + windows = std::list(); + } } - -void BarinkEngine::InputManager::attach(BarinkWindow* window) -{ - - windows.push_back(window); - - // Attach callbacks - glfwSetKeyCallback(window->windowptr(), KeyCallback); - glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback); - glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback); - glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback); - glfwSetScrollCallback(window->windowptr(), ScrollCallback); - - this->Subscribe( (EventListener&)(*window)); - - - -} - -BarinkEngine::InputManager::InputManager() : EventEmitter () -{ - windows = std::vector(); -} - - - diff --git a/BarinkEngine/graphics/ModelImporter.cpp b/BarinkEngine/graphics/ModelImporter.cpp index e66528e..b1ff37f 100644 --- a/BarinkEngine/graphics/ModelImporter.cpp +++ b/BarinkEngine/graphics/ModelImporter.cpp @@ -1,66 +1,13 @@ #include "AssetManager/ModelImporter.h" -void ModelImporter::ImportFBX(std::string path) +std::vector ModelImporter::Import(std::string path) { - //spdlog::warn("ImportFBX not implemented!"); -} - -void ModelImporter::ImportBlend(std::string path) -{ - //spdlog::warn("ImportBlend not implemented!"); -} - -void ModelImporter::ImportGLTF(std::string path) -{ - //spdlog::warn("ImportGLTF not implemented!"); -} - -void ModelImporter::ImportOBJ(std::string path) -{ - //spdlog::warn("ImportOBJ not implemented!"); -} - -void ModelImporter::Import(std::string path) -{ - //spdlog::warn("Import not implemented!"); -} - -std::vector ModelImporter::Test() { - - /* - spdlog::info("====== Tiny GLTF ======"); - tinygltf::Model loadedModel; - tinygltf::TinyGLTF loader; - std::string error; - std::string warn; - bool ret = loader.LoadASCIIFromFile(&loadedModel, &error, &warn, "./Build/SandboxApplication/Debug/sponza.gltf"); - - if (!warn.empty()) - spdlog::warn("TinyGLTF Warning: {}", warn); - if (!error.empty()) - spdlog::error("TinyGLTF Error: {}", error); - if (!ret) { - spdlog::error("TinyGLTF Error: Failed to parse glTF"); - exit(-1); - } - - spdlog::info("Meshes in model: {}", loadedModel.meshes.size()); - spdlog::info("Primitives in mesh: {}", loadedModel.meshes[0].primitives.size()); - - */ - - - //spdlog::info("======= Assimp ======"); - Assimp::Importer importer; - const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Models/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs); - + const aiScene* scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs); aiNode* currentNode = scene->mRootNode; - return processNode(currentNode, scene); - - + return processNode(currentNode, scene); } std::vector ModelImporter::processNode(aiNode* node, const aiScene* scene) { diff --git a/BarinkEngine/graphics/Renderable.cpp b/BarinkEngine/graphics/Renderable.cpp index 5109edf..1461f6a 100644 --- a/BarinkEngine/graphics/Renderable.cpp +++ b/BarinkEngine/graphics/Renderable.cpp @@ -3,14 +3,14 @@ #include "PerfCounter.h" -Renderable* Renderable::Load() +Renderable* Renderable::Load(std::string& path) { - return new Renderable(); + return new Renderable(path); } -Renderable::Renderable() +Renderable::Renderable(std::string& path) { - meshes = ModelImporter::Test(); + meshes = ModelImporter::Import(path); transform.Scale = glm::vec3(1.0f); transform.Rotation = glm::vec3(0.0f, 0.0f, 0.0f); diff --git a/BarinkEngine/graphics/window.cpp b/BarinkEngine/graphics/window.cpp index 3843a0c..fe94504 100644 --- a/BarinkEngine/graphics/window.cpp +++ b/BarinkEngine/graphics/window.cpp @@ -79,6 +79,9 @@ void BarinkWindow::SwapBuffers() void BarinkWindow::ReceiveEvent(Event& incident) { + + + std::cout << "EVENT RECEIVED: " << incident.name << std::endl; } \ No newline at end of file diff --git a/Manuals/GLSL.std.450.pdf b/Manuals/GLSL.std.450.pdf new file mode 100644 index 0000000..3eaf959 Binary files /dev/null and b/Manuals/GLSL.std.450.pdf differ diff --git a/Manuals/SPIRV.pdf b/Manuals/SPIRV.pdf new file mode 100644 index 0000000..dc781f4 Binary files /dev/null and b/Manuals/SPIRV.pdf differ diff --git a/SandboxApplication/Sandbox.cpp b/SandboxApplication/Sandbox.cpp index b52438f..5039fd7 100644 --- a/SandboxApplication/Sandbox.cpp +++ b/SandboxApplication/Sandbox.cpp @@ -66,11 +66,13 @@ void Start() { matCube2 = new Material(*shader); matCube2->Color = glm::vec3(0.0, 1.0f, 0.0); + std::string cubePath = "build/SandboxApplication/Debug/Models/Cube.obj"; + std::string lanternPath = "build/SandboxApplication/Debug/Models/Latern.gltf"; /* * load meshes */ - Cube = Renderable::Load(); - Cube2 = Renderable::Load(); + Cube = Renderable::Load(lanternPath); + Cube2 = Renderable::Load(cubePath); Cube->addChild(*Cube2); Cube->shader = shader;