Compare commits
2 Commits
4df6cfba90
...
Feature/In
Author | SHA1 | Date | |
---|---|---|---|
3c30bf7fb7 | |||
85f9c78adf |
@ -1,24 +1,40 @@
|
||||
#include "BarinkEngine.h"
|
||||
#include <phonon.h>
|
||||
|
||||
EngineStatistics* ES;
|
||||
BarinkEngine::InputManager InputSystem;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Setup performance sampler
|
||||
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();
|
||||
BarinkEngine::InputManager InputSystem = BarinkEngine::InputManager();
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
@ -57,6 +73,9 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// Shutdown Services
|
||||
delete ES;
|
||||
InputSystem.detach(&MainWindow);
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
25
BarinkEngine/EventSystem/EventEmitter.cpp
Normal file
25
BarinkEngine/EventSystem/EventEmitter.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "../Include/EventSystem/EventEmitter.h"
|
||||
|
||||
|
||||
void EventEmitter::Subscribe(EventListener& subscriber)
|
||||
{
|
||||
subscribers.push_back(&subscriber);
|
||||
}
|
||||
|
||||
void EventEmitter::Unsubscribe(EventListener& subscriber)
|
||||
{
|
||||
subscribers.remove(&subscriber);
|
||||
}
|
||||
|
||||
void EventEmitter::EmitEvent(Event& incident)
|
||||
{
|
||||
// Notify all subscribers an event has taken place
|
||||
for (auto it = subscribers.begin(); it != subscribers.end(); ++it)
|
||||
{
|
||||
(*it)->ReceiveEvent(incident);
|
||||
}
|
||||
}
|
||||
|
||||
EventEmitter::EventEmitter() {
|
||||
subscribers = std::list<EventListener*>{};
|
||||
}
|
@ -11,16 +11,13 @@
|
||||
#include <string>
|
||||
|
||||
class ModelImporter {
|
||||
|
||||
public:
|
||||
static std::vector<BarinkEngine::Mesh> 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<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
|
||||
|
||||
public:
|
||||
void Import(std::string path);
|
||||
|
||||
static std::vector<BarinkEngine::Mesh> Test();
|
||||
};
|
@ -13,6 +13,8 @@
|
||||
#include "Graphics/Renderer.h"
|
||||
#include "Graphics/GUI/GUIManager.h"
|
||||
#include "Scene.h"
|
||||
|
||||
|
||||
#include "PerfCounter.h"
|
||||
|
||||
|
||||
@ -20,3 +22,5 @@ extern void Start();
|
||||
extern void Update();
|
||||
extern void ImmediateGraphicsDraw();
|
||||
extern void Stop();
|
||||
|
||||
extern BarinkEngine::InputManager InputSystem;
|
9
BarinkEngine/Include/EventSystem/Event.h
Normal file
9
BarinkEngine/Include/EventSystem/Event.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
struct Event
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
|
||||
};
|
18
BarinkEngine/Include/EventSystem/EventEmitter.h
Normal file
18
BarinkEngine/Include/EventSystem/EventEmitter.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Event.h"
|
||||
#include "EventListener.h"
|
||||
|
||||
class EventEmitter {
|
||||
public:
|
||||
void Subscribe (EventListener& subscriber);
|
||||
void Unsubscribe(EventListener& subscriber);
|
||||
void EmitEvent(Event& incident);
|
||||
|
||||
|
||||
protected:
|
||||
std::list<EventListener*> subscribers;
|
||||
|
||||
|
||||
EventEmitter();
|
||||
|
||||
};
|
5
BarinkEngine/Include/EventSystem/EventListener.cpp
Normal file
5
BarinkEngine/Include/EventSystem/EventListener.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "EventListener.h"
|
||||
|
||||
void EventListener::ReceiveEvent(Event& incident)
|
||||
{
|
||||
}
|
8
BarinkEngine/Include/EventSystem/EventListener.h
Normal file
8
BarinkEngine/Include/EventSystem/EventListener.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "Event.h"
|
||||
#include <list>
|
||||
class EventListener{
|
||||
public:
|
||||
virtual void ReceiveEvent(Event& incident);
|
||||
|
||||
};
|
18
BarinkEngine/Include/EventSystem/InputSystemEvents.h
Normal file
18
BarinkEngine/Include/EventSystem/InputSystemEvents.h
Normal file
@ -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;
|
||||
|
||||
};
|
@ -28,10 +28,10 @@ public:
|
||||
|
||||
~Renderable();
|
||||
|
||||
static Renderable* Load();
|
||||
static Renderable* Load(std::string& path);
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
std::vector<BarinkEngine::Mesh> meshes;
|
||||
Renderable();
|
||||
Renderable(std::string& path);
|
||||
};
|
@ -3,12 +3,13 @@
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "../Include/EventSystem/EventListener.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class BarinkWindow{
|
||||
class BarinkWindow : EventListener {
|
||||
private:
|
||||
GLFWwindow* window;
|
||||
bool FullScreen;
|
||||
@ -18,12 +19,15 @@ class BarinkWindow{
|
||||
static bool InitGLFW();
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
BarinkWindow(const int width, const int height);
|
||||
~BarinkWindow();
|
||||
|
||||
GLFWwindow* windowptr();
|
||||
|
||||
void ReceiveEvent(Event& incident) override;
|
||||
bool WindowShouldClose();
|
||||
|
||||
void Poll();
|
||||
|
14
BarinkEngine/Include/Input/GLFWInput.h
Normal file
14
BarinkEngine/Include/Input/GLFWInput.h
Normal file
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -1,25 +1,29 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "Graphics/Window.h"
|
||||
#include "EventSystem/EventEmitter.h"
|
||||
#include "../Include/Input/GLFWInput.h"
|
||||
#include "BarinkEngine.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
class InputManager {
|
||||
class InputManager : public EventEmitter {
|
||||
public:
|
||||
InputManager();
|
||||
|
||||
void PollEvents();
|
||||
|
||||
void attach(BarinkWindow* window);
|
||||
void detach(BarinkWindow* 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);
|
||||
void setupGLFWInput(GLFWwindow* window);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::vector<BarinkWindow*> windows;
|
||||
std::list<BarinkWindow*> windows;
|
||||
|
||||
};
|
||||
}
|
||||
|
104
BarinkEngine/Input/GLFWInput.cpp
Normal file
104
BarinkEngine/Input/GLFWInput.cpp
Normal file
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,72 +1,44 @@
|
||||
#include "Input/InputManager.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <iostream>
|
||||
void BarinkEngine::InputManager::PollEvents()
|
||||
{
|
||||
for (std::vector<BarinkWindow*>::iterator it = windows.begin(); it != windows.end(); ++it) {
|
||||
(*it)->Poll();
|
||||
}
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_A && action == GLFW_PRESS)
|
||||
namespace BarinkEngine {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
|
||||
{
|
||||
if (entered) {
|
||||
// Cursor entered the window's screen space
|
||||
std::cout << "Cursor entered!" << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << "Cursor left!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
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;
|
||||
|
||||
void InputManager::attach(BarinkWindow* window)
|
||||
{
|
||||
windows.push_back(window);
|
||||
this->Subscribe((EventListener&)(*window));
|
||||
|
||||
}
|
||||
|
||||
void InputManager::detach(BarinkWindow* window)
|
||||
{
|
||||
windows.remove(window);
|
||||
this->Unsubscribe((EventListener&)*window);
|
||||
}
|
||||
|
||||
|
||||
InputManager::InputManager() : EventEmitter()
|
||||
{
|
||||
windows = std::list<BarinkWindow*>();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
BarinkEngine::InputManager::InputManager()
|
||||
{
|
||||
windows = std::vector<BarinkWindow*>();
|
||||
}
|
||||
|
@ -1,66 +1,13 @@
|
||||
#include "AssetManager/ModelImporter.h"
|
||||
|
||||
|
||||
void ModelImporter::ImportFBX(std::string path)
|
||||
std::vector<BarinkEngine::Mesh> 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<BarinkEngine::Mesh> 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<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
|
||||
|
@ -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);
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include "Graphics/Window.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "../Include/EventSystem/Event.h"
|
||||
|
||||
bool BarinkWindow::InitGLFW(){
|
||||
if(!glfwInit())
|
||||
@ -73,4 +74,14 @@ void BarinkWindow::Poll()
|
||||
void BarinkWindow::SwapBuffers()
|
||||
{
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
|
||||
void BarinkWindow::ReceiveEvent(Event& incident)
|
||||
{
|
||||
|
||||
|
||||
|
||||
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
|
||||
|
||||
}
|
BIN
Manuals/GLSL.std.450.pdf
Normal file
BIN
Manuals/GLSL.std.450.pdf
Normal file
Binary file not shown.
BIN
Manuals/SPIRV.pdf
Normal file
BIN
Manuals/SPIRV.pdf
Normal file
Binary file not shown.
@ -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;
|
||||
|
Reference in New Issue
Block a user