Moving source files to a src folder

pull/13/head
Nigel Barink 2022-08-06 18:21:42 +02:00
parent e31fd036ea
commit 5a06b068f3
28 changed files with 589 additions and 585 deletions

View File

@ -3,12 +3,13 @@
#include "Scene/SceneNodeTypes.h" #include "Scene/SceneNodeTypes.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "../../src/Scene/SceneNodeTypes.cpp"
/* /*
* Define a helper class to more easily build a proper scene * Define a helper class to more easily build a proper scene
*/ */
static class SceneBuilder { static class SceneBuilder {
static Group* AddGroup(std::string name); static Group* AddGroup(std::string name);
static SceneObject* AddVisual(std::string name, Renderable& object, glm::vec3 position ); static BarinkEngine::SceneObject* AddVisual(std::string name, BarinkEngine::Renderable& object, glm::vec3 position );
}; };

View File

@ -52,10 +52,10 @@ project "BarinkEngine"
files { files {
"../libs/glad/src/glad.c", "../libs/glad/src/glad.c",
"./*.cpp", "./src/*.cpp",
"./*.h", "./Include/*.h",
"./**/*.cpp", "./src/**/*.cpp",
"./**/*.h" "./Include/**/*.h"
} }

View File

@ -1,64 +1,64 @@
#include "BarinkEngine.h" #include "BarinkEngine.h"
#include <phonon.h> #include <phonon.h>
EngineStatistics* ES; EngineStatistics* ES;
BarinkEngine::InputManager InputSystem; BarinkEngine::InputManager InputSystem;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Setup performance sampler // Setup performance sampler
PerfomanceSamplerInit(); PerfomanceSamplerInit();
// Startup services // Startup services
BarinkWindow MainWindow = BarinkWindow(800, 600); BarinkWindow MainWindow = BarinkWindow(800, 600);
BarinkEngine::Renderer renderer = BarinkEngine::Renderer(); BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
InputSystem = BarinkEngine::InputManager(); InputSystem = BarinkEngine::InputManager();
InputSystem.attach(&MainWindow); InputSystem.attach(&MainWindow);
GUIManager GUISystem = GUIManager(&MainWindow); GUIManager GUISystem = GUIManager(&MainWindow);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// First call to setup game // First call to setup game
Start(); Start();
// Runtime loop // Runtime loop
while (!MainWindow.WindowShouldClose()) { while (!MainWindow.WindowShouldClose()) {
SamplePerformance(); SamplePerformance();
// Execute main logic // Execute main logic
InputSystem.PollEvents(); InputSystem.PollEvents();
Update(); Update();
renderer.Render(); renderer.Render();
ImmediateGraphicsDraw(); ImmediateGraphicsDraw();
GUISystem.Render(); GUISystem.Render();
MainWindow.SwapBuffers(); MainWindow.SwapBuffers();
} }
// Shutdown game // Shutdown game
Stop(); Stop();
// Shutdown Services // Shutdown Services
delete ES; delete ES;
return 0; return 0;
} }

View File

@ -1,47 +1,47 @@
#include "Graphics/Buffer.h" #include "Graphics/Buffer.h"
int GpuBuffer::getBufferID() { int GpuBuffer::getBufferID() {
return id; return id;
} }
void GpuBuffer::createBuffer() { void GpuBuffer::createBuffer() {
glGenBuffers(1, (GLuint*) &id); glGenBuffers(1, (GLuint*) &id);
} }
void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) { void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
if (elementBuffer) { if (elementBuffer) {
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
} }
else { else {
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
} }
} }
void GpuBuffer::Bind(bool elementBuffer = false ) { void GpuBuffer::Bind(bool elementBuffer = false ) {
if (elementBuffer) { if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
} }
else { else {
glBindBuffer(GL_ARRAY_BUFFER, id); glBindBuffer(GL_ARRAY_BUFFER, id);
} }
} }
void GpuBuffer::Unbind(bool elementBuffer = false) { void GpuBuffer::Unbind(bool elementBuffer = false) {
if (elementBuffer) { if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
} }
else { else {
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
} }
void GpuBuffer::Delete() { void GpuBuffer::Delete() {
glDeleteBuffers(1, (GLuint*) &id); glDeleteBuffers(1, (GLuint*) &id);
} }

View File

@ -1,10 +1,10 @@
#include "../Include/Graphics/Material.h" #include "../Include/Graphics/Material.h"
Material::Material(const Shader& shader) : Material::Material(const Shader& shader) :
shader(shader) { shader(shader) {
} }
void Material::Apply() { void Material::Apply() {
shader.setUniformVec3("Color", Color); shader.setUniformVec3("Color", Color);
} }

View File

@ -1,94 +1,94 @@
#include "AssetManager/ModelImporter.h" #include "AssetManager/ModelImporter.h"
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path) BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
{ {
SceneObject* root = new SceneObject(std::string(path), nullptr); SceneObject* root = new SceneObject(std::string(path), nullptr);
Assimp::Importer importer; Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs); const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
aiNode* currentNode = scene->mRootNode; aiNode* currentNode = scene->mRootNode;
std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene); std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene);
return root; return root;
} }
std::vector<BarinkEngine::Mesh> BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene) std::vector<BarinkEngine::Mesh> BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene)
{ {
std::vector<BarinkEngine::Mesh> meshes; std::vector<BarinkEngine::Mesh> meshes;
for (unsigned int i = 0; i < node->mNumMeshes; i++) { for (unsigned int i = 0; i < node->mNumMeshes; i++) {
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]]; aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
meshes.push_back(processMesh(mesh, scene)); meshes.push_back(processMesh(mesh, scene));
} }
for (unsigned int i = 0; i < node->mNumChildren; i++) { for (unsigned int i = 0; i < node->mNumChildren; i++) {
auto m2 = processNode(node->mChildren[i], scene); auto m2 = processNode(node->mChildren[i], scene);
for(auto m : m2) { for(auto m : m2) {
meshes.push_back(m); meshes.push_back(m);
} }
} }
return meshes; return meshes;
} }
BarinkEngine::Mesh BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) { BarinkEngine::Mesh BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
std::vector<BarinkEngine::Vertex> vertices; std::vector<BarinkEngine::Vertex> vertices;
ProcessVertices(mesh, vertices); ProcessVertices(mesh, vertices);
ProcessIndices(mesh, indices); ProcessIndices(mesh, indices);
BarinkEngine::Mesh result; BarinkEngine::Mesh result;
result.vertices = vertices; result.vertices = vertices;
result.elements = indices; result.elements = indices;
return result; return result;
} }
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices) { void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices) {
// Process vertices // Process vertices
for (unsigned int i = 0; i < mesh->mNumVertices; i++) { for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
BarinkEngine::Vertex v{}; BarinkEngine::Vertex v{};
glm::vec3 vector; glm::vec3 vector;
vector.x = mesh->mVertices[i].x; vector.x = mesh->mVertices[i].x;
vector.y = mesh->mVertices[i].y; vector.y = mesh->mVertices[i].y;
vector.z = mesh->mVertices[i].z; vector.z = mesh->mVertices[i].z;
v.vertices = vector; v.vertices = vector;
if (mesh->mTextureCoords[0]) { if (mesh->mTextureCoords[0]) {
glm::vec2 texCoord; glm::vec2 texCoord;
texCoord.x = mesh->mTextureCoords[0][i].x; texCoord.x = mesh->mTextureCoords[0][i].x;
texCoord.y = mesh->mTextureCoords[0][i].y; texCoord.y = mesh->mTextureCoords[0][i].y;
v.uv = texCoord; v.uv = texCoord;
} }
out_vertices.push_back(v); out_vertices.push_back(v);
} }
} }
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) { void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
// Process Indices // Process Indices
for (unsigned int i = 0; i < mesh->mNumFaces; i++) { for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
aiFace face = mesh->mFaces[i]; aiFace face = mesh->mFaces[i];
if (face.mNumIndices < 3) if (face.mNumIndices < 3)
continue; continue;
for (unsigned int j = 0; j < face.mNumIndices; j++) { for (unsigned int j = 0; j < face.mNumIndices; j++) {
out_indices.push_back(face.mIndices[j]); out_indices.push_back(face.mIndices[j]);
} }
} }
} }

View File

@ -1,53 +1,53 @@
#include "Graphics/Renderable.h" #include "Graphics/Renderable.h"
#include "AssetManager/ModelImporter.h" #include "AssetManager/ModelImporter.h"
#include "PerfCounter.h" #include "PerfCounter.h"
BarinkEngine::Renderable::Renderable() BarinkEngine::Renderable::Renderable()
{ {
/* /*
VAO.Create(); VAO.Create();
VAO.Bind(); VAO.Bind();
vertexBuffer.createBuffer(); vertexBuffer.createBuffer();
vertexBuffer.Bind(false); vertexBuffer.Bind(false);
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false); vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false);
elementBuffer.createBuffer(); elementBuffer.createBuffer();
elementBuffer.Bind(true); elementBuffer.Bind(true);
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true); elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex)); VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices)); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices));
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
//vertexBuffer.Unbind(false); //vertexBuffer.Unbind(false);
VAO.Unbind(); VAO.Unbind();
*/ */
} }
BarinkEngine::Renderable::~Renderable() BarinkEngine::Renderable::~Renderable()
{ {
// glDeleteBuffers(1, &UV_id); // glDeleteBuffers(1, &UV_id);
} }
// Draw call Example !! // Draw call Example !!
/* /*
VAO.Bind(); VAO.Bind();
elementBuffer.Bind(true); elementBuffer.Bind(true);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0); glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0);
texture->Bind(); texture->Bind();
ES->verts = meshes[0].vertices.size(); ES->verts = meshes[0].vertices.size();
ES->DC++; ES->DC++;
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL); glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
VAO.Unbind(); VAO.Unbind();
*/ */

View File

@ -1,25 +1,25 @@
#include "Graphics/Renderer.h" #include "Graphics/Renderer.h"
BarinkEngine::Renderer::Renderer() BarinkEngine::Renderer::Renderer()
{ {
models = std::vector<Renderable*>(); models = std::vector<Renderable*>();
} }
BarinkEngine::Renderer::~Renderer() BarinkEngine::Renderer::~Renderer()
{ {
// CleanUp! // CleanUp!
} }
void BarinkEngine::Renderer::Render() void BarinkEngine::Renderer::Render()
{ {
for (auto model : models) { for (auto model : models) {
//model->Draw(); //model->Draw();
} }
} }
void BarinkEngine::Renderer::Submit(Renderable* model) void BarinkEngine::Renderer::Submit(Renderable* model)
{ {
models.push_back(model); models.push_back(model);
} }

View File

@ -1,40 +1,40 @@
#include "../Include/Graphics/Texture.h" #include "../Include/Graphics/Texture.h"
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "Graphics/stb_image.h" #include "Graphics/stb_image.h"
#include <iostream> #include <iostream>
Texture::Texture(const std::string texturePath) { Texture::Texture(const std::string texturePath) {
int width, height, channels; int width, height, channels;
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0); unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
std::cout << channels << std::endl; std::cout << channels << std::endl;
if (data) { if (data) {
glGenTextures(1, &Id); glGenTextures(1, &Id);
glBindTexture(GL_TEXTURE_2D, Id); glBindTexture(GL_TEXTURE_2D, Id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} }
else { else {
spdlog::error("Failed to load image (%s)", texturePath ); spdlog::error("Failed to load image (%s)", texturePath );
} }
stbi_image_free(data); stbi_image_free(data);
} }
void Texture::Bind() { void Texture::Bind() {
glBindTexture(GL_TEXTURE_2D, Id); glBindTexture(GL_TEXTURE_2D, Id);
} }
void Texture::Unbind() { void Texture::Unbind() {
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }

View File

@ -1,25 +1,25 @@
#include "Graphics/VertexArray.h" #include "Graphics/VertexArray.h"
#include <glad/glad.h> #include <glad/glad.h>
void VertexArray::Create(){ void VertexArray::Create(){
glGenVertexArrays(1, &id); glGenVertexArrays(1, &id);
} }
void VertexArray::Bind(){ void VertexArray::Bind(){
glBindVertexArray(id); glBindVertexArray(id);
} }
void VertexArray::Unbind(){ void VertexArray::Unbind(){
glBindVertexArray(0); glBindVertexArray(0);
} }
void VertexArray::Delete() { void VertexArray::Delete() {
glDeleteVertexArrays(1, &id); glDeleteVertexArrays(1, &id);
} }
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){ void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0); glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
} }

View File

@ -1,11 +1,11 @@
#version 440 core #version 440 core
out vec4 FragColor; out vec4 FragColor;
uniform vec3 Color; uniform vec3 Color;
in vec2 TexCoord; in vec2 TexCoord;
uniform sampler2D Texture; uniform sampler2D Texture;
void main(){ void main(){
FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f); FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f);
} }

View File

@ -1,84 +1,84 @@
#include "Graphics/Window.h" #include "Graphics/Window.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include "../Include/EventSystem/Event.h" #include "../Include/EventSystem/Event.h"
bool BarinkWindow::InitGLFW(){ bool BarinkWindow::InitGLFW(){
if(!glfwInit()) if(!glfwInit())
{ {
spdlog::error("Failed to initialise GLFW!"); spdlog::error("Failed to initialise GLFW!");
return false; return false;
} }
return true; return true;
} }
BarinkWindow::BarinkWindow(const int width, const int height) : BarinkWindow::BarinkWindow(const int width, const int height) :
Width(width), Height(height), FullScreen(false){ Width(width), Height(height), FullScreen(false){
if (InitGLFW()==false) { if (InitGLFW()==false) {
exit(-1); exit(-1);
} }
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL); window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
if( !window) if( !window)
{ {
spdlog::error("GLFW failed to create window!"); spdlog::error("GLFW failed to create window!");
glfwTerminate(); glfwTerminate();
return; return;
} }
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
printf("Failed to initialize GLAD!\n"); printf("Failed to initialize GLAD!\n");
exit(-1); exit(-1);
} }
// Set vsync off !! // Set vsync off !!
glfwSwapInterval(0); glfwSwapInterval(0);
VulkanSupported = glfwVulkanSupported(); VulkanSupported = glfwVulkanSupported();
glfwGetFramebufferSize(window, &Width, &Height); glfwGetFramebufferSize(window, &Width, &Height);
glViewport(0,0, Width, Height); glViewport(0,0, Width, Height);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
} }
BarinkWindow::~BarinkWindow(){ BarinkWindow::~BarinkWindow(){
glfwTerminate(); glfwTerminate();
} }
GLFWwindow* BarinkWindow::windowptr() GLFWwindow* BarinkWindow::windowptr()
{ {
return window; return window;
} }
bool BarinkWindow::WindowShouldClose(){ bool BarinkWindow::WindowShouldClose(){
return glfwWindowShouldClose(window); return glfwWindowShouldClose(window);
} }
void BarinkWindow::Poll() void BarinkWindow::Poll()
{ {
glfwPollEvents(); glfwPollEvents();
} }
void BarinkWindow::SwapBuffers() void BarinkWindow::SwapBuffers()
{ {
glfwSwapBuffers(window); glfwSwapBuffers(window);
} }
void BarinkWindow::ReceiveEvent(Event& incident) void BarinkWindow::ReceiveEvent(Event& incident)
{ {
std::cout << "EVENT RECEIVED: " << incident.name << std::endl; std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
} }

View File

@ -1,118 +1,118 @@
#include "BarinkEngine.h" #include "BarinkEngine.h"
#include "Input/InputManager.h" #include "Input/InputManager.h"
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include <iostream> #include <iostream>
void BarinkEngine::InputManager::PollEvents() void BarinkEngine::InputManager::PollEvents()
{ {
for (auto it = windows.begin(); it != windows.end(); ++it) { for (auto it = windows.begin(); it != windows.end(); ++it) {
(*it)->Poll(); (*it)->Poll();
} }
} }
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{ {
Event KeyEvent{}; Event KeyEvent{};
KeyEvent.name = "KEY"; KeyEvent.name = "KEY";
InputSystem.EmitEvent(KeyEvent); InputSystem.EmitEvent(KeyEvent);
if (key == GLFW_KEY_A && action == GLFW_PRESS) if (key == GLFW_KEY_A && action == GLFW_PRESS)
{ {
std::cout << "'a' key was pressed" << std::endl; std::cout << "'a' key was pressed" << std::endl;
} }
} }
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y) void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y)
{ {
//std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl; //std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl;
Event CursorPosUpdate{}; Event CursorPosUpdate{};
CursorPosUpdate.name = "UPDATE::CURSOR:POSITION"; CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
InputSystem.EmitEvent(CursorPosUpdate); InputSystem.EmitEvent(CursorPosUpdate);
} }
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered) void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
{ {
if (entered) { if (entered) {
Event mouseEntered {}; Event mouseEntered {};
mouseEntered.name = "Mouse Entered Window's confines!"; mouseEntered.name = "Mouse Entered Window's confines!";
mouseEntered.argc = 0; mouseEntered.argc = 0;
InputSystem.EmitEvent(mouseEntered); InputSystem.EmitEvent(mouseEntered);
} }
else { else {
Event mouseLeft{}; Event mouseLeft{};
mouseLeft.name = "Mouse Left Window's confines!"; mouseLeft.name = "Mouse Left Window's confines!";
mouseLeft.argc = 0; mouseLeft.argc = 0;
InputSystem.EmitEvent(mouseLeft); InputSystem.EmitEvent(mouseLeft);
} }
} }
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{ {
Event MouseButtonEvent{}; Event MouseButtonEvent{};
MouseButtonEvent.name = "MOUSEBUTTON"; MouseButtonEvent.name = "MOUSEBUTTON";
InputSystem.EmitEvent(MouseButtonEvent); InputSystem.EmitEvent(MouseButtonEvent);
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) { if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
std::cout << "Right mouse button was pressed!" << std::endl; std::cout << "Right mouse button was pressed!" << std::endl;
} }
} }
void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{ {
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl; std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
Event ScrollEvent{}; Event ScrollEvent{};
ScrollEvent.name = "SCROLL"; ScrollEvent.name = "SCROLL";
InputSystem.EmitEvent(ScrollEvent); InputSystem.EmitEvent(ScrollEvent);
} }
void BarinkEngine::InputManager::attach(BarinkWindow* window) void BarinkEngine::InputManager::attach(BarinkWindow* window)
{ {
windows.push_back(window); windows.push_back(window);
// Attach callbacks // Attach callbacks
glfwSetKeyCallback(window->windowptr(), KeyCallback); glfwSetKeyCallback(window->windowptr(), KeyCallback);
glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback); glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback);
glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback); glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback);
glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback); glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
glfwSetScrollCallback(window->windowptr(), ScrollCallback); glfwSetScrollCallback(window->windowptr(), ScrollCallback);
this->Subscribe( (EventListener&)(*window)); this->Subscribe( (EventListener&)(*window));
} }
BarinkEngine::InputManager::InputManager() : EventEmitter () BarinkEngine::InputManager::InputManager() : EventEmitter ()
{ {
windows = std::vector<BarinkWindow*>(); windows = std::vector<BarinkWindow*>();
} }

View File

@ -1,30 +1,33 @@
#include "GUI.h" #include "GUI.h"
void SceneExplorer(Scene& scene, std::string PanelName) { void SceneExplorer(Scene& scene, std::string PanelName) {
ImGui::Begin(PanelName.c_str()); if (ImGui::Begin(PanelName.c_str())) {
ImGui::ListBoxHeader("##ObjectList");
ImGui::ListBoxHeader("##ObjectList"); Node& current = scene.GetRoot();
Node& current = scene.GetRoot(); Node* next = &current;
Node* next = &current; // Show first node
ImGui::Selectable(next->name.c_str(), true);
// Show first node ImGui::Indent();
ImGui::Selectable(next->name.c_str(), true);
ImGui::Indent(); if (next->children.size() != 0) {
for (auto child : next->children)
if (next->children.size() != 0) { {
for (auto child : next->children) std::string& name = child->name;
{ ImGui::Selectable(name.c_str(), false);
std::string& name = child->name; }
ImGui::Selectable(name.c_str(), false);
} }
}
ImGui::ListBoxFooter(); ImGui::ListBoxFooter();
}
ImGui::End(); ImGui::End();
} }
void CameraTool(Camera* cam) { void CameraTool(Camera* cam) {