Compare commits

...

3 Commits

Author SHA1 Message Date
ab5599f1fc Started development of BECS - the basic ECS system for the engine 2022-08-06 18:24:05 +02:00
3639f967e1 Ignore untracked file changes in some submodules
These files are probably nothing of great importance to our
development and thus have no business showing up in our git status
2022-08-06 18:22:10 +02:00
5a06b068f3 Moving source files to a src folder 2022-08-06 18:21:42 +02:00
33 changed files with 636 additions and 585 deletions

3
.gitmodules vendored
View File

@ -4,12 +4,14 @@
[submodule "glm"]
path = libs/glm
url = https://github.com/nigelbarink/glm.git
ignore = untracked
[submodule "spdlog"]
path = libs/spdlog
url = https://github.com/nigelbarink/spdlog.git
[submodule "tinygltf"]
path = libs/tinygltf
url = https://github.com/syoyo/tinygltf.git
ignore = untracked
[submodule "GorrillaAudio"]
path = libs/GorillaAudio
url = https://github.com/mewspring/gorilla-audio.git
@ -22,6 +24,7 @@
[submodule "libs/steam-audio"]
path = libs/steam-audio
url = https://github.com/ValveSoftware/steam-audio.git
ignore = untracked
[submodule "libs/physx"]
path = libs/physx
url = https://git.barink.dev/Nigel/PhysX.git

View File

@ -0,0 +1,7 @@
#pragma once
namespace BECS {
struct Component {
};
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <vector>
#include "Component.h"
namespace BECS {
typedef unsigned long int Entity;
}

View File

@ -0,0 +1,7 @@
#pragma once
namespace BECS {
struct System {
};
}

View File

@ -0,0 +1,17 @@
#pragma once
#include "System.h"
#include <vector>
#include "Component.h"
#include "Entity.h"
namespace BECS {
struct World {
private:
std::vector<System> systems;
std::vector<Component> components;
std::vector<Entity> entities;
};
}

View File

@ -3,12 +3,13 @@
#include "Scene/SceneNodeTypes.h"
#include <glm/glm.hpp>
#include "../../src/Scene/SceneNodeTypes.cpp"
/*
* Define a helper class to more easily build a proper scene
*/
static class SceneBuilder {
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 {
"../libs/glad/src/glad.c",
"./*.cpp",
"./*.h",
"./**/*.cpp",
"./**/*.h"
"./src/*.cpp",
"./Include/*.h",
"./src/**/*.cpp",
"./Include/**/*.h"
}

View File

@ -1,64 +1,64 @@
#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);
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
InputSystem = BarinkEngine::InputManager();
InputSystem.attach(&MainWindow);
GUIManager GUISystem = GUIManager(&MainWindow);
glEnable(GL_DEPTH_TEST);
// First call to setup game
Start();
// Runtime loop
while (!MainWindow.WindowShouldClose()) {
SamplePerformance();
// Execute main logic
InputSystem.PollEvents();
Update();
renderer.Render();
ImmediateGraphicsDraw();
GUISystem.Render();
MainWindow.SwapBuffers();
}
// Shutdown game
Stop();
// Shutdown Services
delete ES;
return 0;
}
#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);
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
InputSystem = BarinkEngine::InputManager();
InputSystem.attach(&MainWindow);
GUIManager GUISystem = GUIManager(&MainWindow);
glEnable(GL_DEPTH_TEST);
// First call to setup game
Start();
// Runtime loop
while (!MainWindow.WindowShouldClose()) {
SamplePerformance();
// Execute main logic
InputSystem.PollEvents();
Update();
renderer.Render();
ImmediateGraphicsDraw();
GUISystem.Render();
MainWindow.SwapBuffers();
}
// Shutdown game
Stop();
// Shutdown Services
delete ES;
return 0;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,118 +1,118 @@
#include "BarinkEngine.h"
#include "Input/InputManager.h"
#include "GLFW/glfw3.h"
#include "spdlog/spdlog.h"
#include <iostream>
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)
{
Event KeyEvent{};
KeyEvent.name = "KEY";
InputSystem.EmitEvent(KeyEvent);
if (key == GLFW_KEY_A && action == GLFW_PRESS)
{
std::cout << "'a' key was pressed" << std::endl;
}
}
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 BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
Event ScrollEvent{};
ScrollEvent.name = "SCROLL";
InputSystem.EmitEvent(ScrollEvent);
}
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<BarinkWindow*>();
}
#include "BarinkEngine.h"
#include "Input/InputManager.h"
#include "GLFW/glfw3.h"
#include "spdlog/spdlog.h"
#include <iostream>
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)
{
Event KeyEvent{};
KeyEvent.name = "KEY";
InputSystem.EmitEvent(KeyEvent);
if (key == GLFW_KEY_A && action == GLFW_PRESS)
{
std::cout << "'a' key was pressed" << std::endl;
}
}
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 BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
Event ScrollEvent{};
ScrollEvent.name = "SCROLL";
InputSystem.EmitEvent(ScrollEvent);
}
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<BarinkWindow*>();
}

View File

@ -1,30 +1,33 @@
#include "GUI.h"
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::Selectable(next->name.c_str(), true);
ImGui::Indent();
ImGui::Indent();
if (next->children.size() != 0) {
for (auto child : next->children)
{
std::string& name = child->name;
ImGui::Selectable(name.c_str(), false);
if (next->children.size() != 0) {
for (auto child : next->children)
{
std::string& name = child->name;
ImGui::Selectable(name.c_str(), false);
}
}
}
ImGui::ListBoxFooter();
ImGui::ListBoxFooter();
}
ImGui::End();
}
void CameraTool(Camera* cam) {