Reorganising the game engine structure. Getting things ready for real development of the engine

This commit is contained in:
Nigel Barink 2022-05-27 22:47:36 +02:00
parent 4625ca657b
commit 3446bc2399
22 changed files with 326 additions and 221 deletions

View File

@ -0,0 +1,34 @@
#include "Include/BarinkEngine.h"
extern void Start(int argc, char* argv[]);
extern void UpdateApplication();
using namespace BarinkEngine;
bool ShouldQuit = false;
int main(int argc, char* argv[]) {
// Start Engine
Engine::Startup();
Start(argc, argv);
while (!ShouldQuit) {
//InputManager::PollEvents();
UpdateApplication();
}
// Kill Engine
Engine::Shutdown();
return 0;
}

10
BarinkEngine/Engine.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "include/BarinkEngine.h"
namespace BarinkEngine {
void Engine::Startup() {
std::cout << "Starting Engine! vroom vroom!" << std::endl;
}
void Engine::Shutdown() {
std::cout << "ShutDown Engine!" << std::endl;
}
};

View File

@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include <string>
#include <filesystem>
#include "Engine.h"
#include <spdlog/spdlog.h>
/*
#include "../MemoryManager.h"
#include <glm/glm.hpp>
#include <MyGraphicsEngine/Shader.h>
#include <MyGraphicsEngine/Window.h>
#include <MyGraphicsEngine/Camera.h>
#include <MyGraphicsEngine/Renderable.h>
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
*/

View File

@ -0,0 +1,10 @@
#pragma once
namespace BarinkEngine {
static class Engine {
public:
static void Startup();
static void Shutdown();
};
};

34
BarinkEngine/premake5.lua Normal file
View File

@ -0,0 +1,34 @@
project "BarinkEngine"
kind "StaticLib"
buildmessage "Building BarinkEngine"
includedirs{
"./../libs/lua/include",
"./libs/spdlog/include",
"./../libs/glm",
"./../MyGraphicsEngine/include",
"./../libs/GorillaAudio/include"
}
libdirs {
"./../libs/lua",
"./../libs/spdlog/build/Release"
}
links {
"lua54",
"spdlog",
"MyGraphicsEngine"
}
files {
"./*.cpp",
"./*.h",
"./**/*.cpp",
"./**/*.h"
}

17
MemoryManager.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <iostream>
#include <stdlib.h>
static int HeapAllocations = 0;
static int HeapDeallocations = 0;
void* operator new(std::size_t sz) {
HeapAllocations++;
return std::malloc(sz);
}
void operator delete(void* ptr) noexcept {
HeapDeallocations++;
std::free(ptr);
}

View File

@ -1,4 +1,4 @@
#include <MyGraphicsEngine/Buffer.h> #include "include/MyGraphicsEngine/Buffer.h"
int Buffer::getBufferID() { int Buffer::getBufferID() {

View File

@ -1,4 +1,4 @@
#include <MyGraphicsEngine/Camera.h> #include "include/MyGraphicsEngine/Camera.h"
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom) Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
: Position(position), Rotation(rotation), Zoom(zoom) { : Position(position), Rotation(rotation), Zoom(zoom) {

View File

@ -3,27 +3,27 @@
void ModelImporter::ImportFBX(std::string path) void ModelImporter::ImportFBX(std::string path)
{ {
spdlog::warn("ImportFBX not implemented!"); //spdlog::warn("ImportFBX not implemented!");
} }
void ModelImporter::ImportBlend(std::string path) void ModelImporter::ImportBlend(std::string path)
{ {
spdlog::warn("ImportBlend not implemented!"); //spdlog::warn("ImportBlend not implemented!");
} }
void ModelImporter::ImportGLTF(std::string path) void ModelImporter::ImportGLTF(std::string path)
{ {
spdlog::warn("ImportGLTF not implemented!"); //spdlog::warn("ImportGLTF not implemented!");
} }
void ModelImporter::ImportOBJ(std::string path) void ModelImporter::ImportOBJ(std::string path)
{ {
spdlog::warn("ImportOBJ not implemented!"); //spdlog::warn("ImportOBJ not implemented!");
} }
void ModelImporter::Import(std::string path) void ModelImporter::Import(std::string path)
{ {
spdlog::warn("Import not implemented!"); //spdlog::warn("Import not implemented!");
} }
std::vector<BarinkEngine::Mesh> ModelImporter::Test() { std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
@ -51,7 +51,7 @@ std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
*/ */
spdlog::info("======= Assimp ======"); //spdlog::info("======= Assimp ======");
Assimp::Importer importer; Assimp::Importer importer;
const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs); const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
@ -94,7 +94,7 @@ BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene
vertices.push_back(vector); vertices.push_back(vector);
} }
spdlog::info("{} == {}", mesh->mNumVertices, vertices.size()); //spdlog::info("{} == {}", mesh->mNumVertices, vertices.size());
// Process Indices // Process Indices
for (unsigned int i = 0; i < mesh->mNumFaces; i++) { for (unsigned int i = 0; i < mesh->mNumFaces; i++) {

View File

@ -1,4 +1,5 @@
#include "Renderable.h" #include "include/MyGraphicsEngine/Renderable.h"
#include "include/AssetManager/ModelImporter.h"
Renderable Renderable::Load() Renderable Renderable::Load()
{ {

View File

@ -1,4 +1,4 @@
#include "MyGraphicsEngine/Shader.h" #include "include/MyGraphicsEngine/Shader.h"
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath) Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
{ {
@ -6,7 +6,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
int succes; int succes;
char* vertexCode = readFile(vertexShaderPath.c_str()); char* vertexCode = readFile(vertexShaderPath.c_str());
spdlog::info(vertexCode); //spdlog::info(vertexCode);
unsigned int vertId = glCreateShader(GL_VERTEX_SHADER); unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertId, 1, &vertexCode, NULL); glShaderSource(vertId, 1, &vertexCode, NULL);
@ -15,13 +15,13 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes); glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes);
if(!succes){ if(!succes){
glGetShaderInfoLog(vertId, 512, NULL, infoLog); glGetShaderInfoLog(vertId, 512, NULL, infoLog);
spdlog::error( "Vertex shader has compile error {}", infoLog); //spdlog::error( "Vertex shader has compile error {}", infoLog);
return; return;
} }
char* fragmentCode = readFile(fragmentShaderPath.c_str()); char* fragmentCode = readFile(fragmentShaderPath.c_str());
spdlog::info(fragmentCode); //spdlog::info(fragmentCode);
unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER); unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
@ -33,7 +33,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes); glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes);
if(!succes){ if(!succes){
glGetShaderInfoLog(fragId, 512, NULL, infoLog); glGetShaderInfoLog(fragId, 512, NULL, infoLog);
spdlog::error("Fragment shader has compile error {}", infoLog); //spdlog::error("Fragment shader has compile error {}", infoLog);
return; return;
} }
@ -63,7 +63,7 @@ char* Shader::readFile (const char* filePath){
file.open(filePath); file.open(filePath);
if(file.is_open() == false){ if(file.is_open() == false){
spdlog::info("File not found."); //spdlog::info("File not found.");
return nullptr; return nullptr;
} }
@ -74,7 +74,7 @@ char* Shader::readFile (const char* filePath){
// Undo previous seek. // Undo previous seek.
file.seekg(0, std::ios::beg); file.seekg(0, std::ios::beg);
spdlog::info("filesize: {}", filesize); //spdlog::info("filesize: {}", filesize);
// Create a big enough buffer for the file // Create a big enough buffer for the file

View File

@ -1,4 +1,4 @@
#include <MyGraphicsEngine/VertexArray.h> #include "include/MyGraphicsEngine/VertexArray.h"
#include <glad/glad.h> #include <glad/glad.h>
void VertexArray::Create(){ void VertexArray::Create(){

View File

@ -4,11 +4,10 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION
#define TINYGLTF_NO_EXTERNAL_IMAGE #define TINYGLTF_NO_EXTERNAL_IMAGE
#include <MyGraphicsEngine/Mesh.h> #include "../MyGraphicsEngine/Mesh.h"
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include <spdlog/spdlog.h>
#include <string> #include <string>
class ModelImporter { class ModelImporter {

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <glm/glm.hpp> #include <glm/glm.hpp>
namespace BarinkEngine{ namespace BarinkEngine{
class Mesh { class Mesh {

View File

@ -0,0 +1,30 @@
#pragma once
#include <vector>
#include "Mesh.h"
#include "Transform.h"
#include "Buffer.h"
#include "VertexArray.h"
/*
#include <MyGraphicsEngine/AssetManager/ModelImporter.h>
#include <MyGraphicsEngine/MyGraphicsEngine/Buffer.h>
#include <MyGraphicsEngine/MyGraphicsEngine/VertexArray.h>
*/
class Renderable {
private:
std::vector<BarinkEngine::Mesh> meshes;
Renderable();
public:
Buffer vertexBuffer;
Buffer elementBuffer;
VertexArray VAO;
Transform transform;
~Renderable();
static Renderable Load();
void Draw();
};

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <glad/glad.h> #include <glad/glad.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <spdlog/spdlog.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>

View File

@ -1,9 +1,13 @@
#pragma once #pragma once
#include <glad/glad.h>
#define GLFW_STATIC #define GLFW_STATIC
#include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
class BarinkWindow{ class BarinkWindow{
private: private:
GLFWwindow* window; GLFWwindow* window;

View File

@ -0,0 +1,49 @@
project "MyGraphicsEngine"
kind "StaticLib"
buildmessage "Building MyGraphicsEngine ..."
includedirs {
"../libs/assimp/include",
"../libs/glad/include",
"../libs/glfw/include",
"../libs/tinygltf",
"../libs/glew/include",
"../libs/glm",
"../libs/ImGui",
}
libdirs{
"../libs/assimp/lib/Debug",
"../libs/glfw/build/src/Debug",
"../libs/ImGui"
}
links {
"assimp-vc143-mtd",
"glfw3",
}
files {
"../libs/ImGui/*.cpp",
"../libs/ImGui/backends/imgui_impl_glfw.cpp",
"../libs/ImGui/backends/imgui_impl_Opengl3.cpp",
"../libs/glad/src/glad.c",
"./*.cpp",
"./*.h",
"./**/*.cpp",
"./**/*.shader",
"./**/*.h"
}
-- NOTE: make these copy instructions more flexible
ok, err = os.copyfile("shaders/fragment.shader", "../build/SandboxApplication/Debug/test.fs")
if err then error("Copy fragment shader source failed!") end
ok, err = os.copyfile("shaders/vertex.shader", "../build/SandboxApplication/Debug/test.vs")
if err then error("Copy vertex shader source failed!") end

View File

@ -1,11 +1,12 @@
#include "MyGraphicsEngine/Window.h" #include "include/MyGraphicsEngine/Window.h"
#include <spdlog/spdlog.h> #include <stdlib.h>
#include <stdio.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;
} }
@ -22,7 +23,7 @@ Width(width), Height(height), FullScreen(false){
if( !window) if( !window)
{ {
spdlog::error("GLFW failed to create window!"); // spdlog::error("GLFW failed to create window!");
glfwTerminate(); glfwTerminate();
return; return;
} }

View File

@ -1,24 +0,0 @@
#pragma once
#include <vector>
#include <spdlog/spdlog.h>
#include <MyGraphicsEngine/Mesh.h>
#include <MyGraphicsEngine/Transform.h>
#include <include/AssetManager/ModelImporter.h>
#include <include/MyGraphicsEngine/Buffer.h>
#include <include/MyGraphicsEngine/VertexArray.h>
class Renderable {
private:
std::vector<BarinkEngine::Mesh> meshes;
Renderable();
public:
Buffer vertexBuffer;
Buffer elementBuffer;
VertexArray VAO;
Transform transform;
~Renderable();
static Renderable Load();
void Draw();
};

View File

@ -1,30 +1,18 @@
#include <string> #include <BarinkEngine.h>
#include <MyGraphicsEngine/Shader.h> void Start(int argc, char* argv[]) {
#include <MyGraphicsEngine/Window.h>
#include <MyGraphicsEngine/Camera.h>
#include <glm/glm.hpp> std::cout << "Hello start!" << std::endl;
std::cout << "h" << std::endl;
// BarinkWindow GameWindow(800, 600);
#include "imgui.h" }
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#include "Renderable.h"
#include <filesystem>
void UpdateApplication()
extern "C"
{ {
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
} }
/* /*
#include <gorilla/gau.h>
#include <gorilla/ga.h>
*/
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@ -34,8 +22,6 @@ int main(int argc, char* argv[]) {
spdlog::info("Working directory: {}", cwd); spdlog::info("Working directory: {}", cwd);
BarinkWindow GameWindow(800, 600);
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
@ -61,21 +47,6 @@ int main(int argc, char* argv[]) {
luaL_dofile(L,"build/SandboxApplication/Debug/script.lua"); luaL_dofile(L,"build/SandboxApplication/Debug/script.lua");
/*
* gau_Manager* mgr;
ga_Mixer* mixer;
ga_Sound sound;
ga_Handle handle;
gau_SampleSourceLoop* loopSrc = 0;
gau_SampleSourceLoop** pLoopSrc = &loopSrc;
gc_int32 loop = 0;
gc_int32 quit = 0;
gc_initialize(0);
mgr = gau_manager_create();
mixer = gau_manager_mixer(mgr);
*/
char* lua_code = new char[255]; char* lua_code = new char[255];
memset(lua_code, '\0', 255); memset(lua_code, '\0', 255);
@ -162,3 +133,4 @@ int main(int argc, char* argv[]) {
} }
*/

View File

@ -1,99 +1,14 @@
workspace "BarinkEngine" workspace "BarinkEngine"
configurations { "Debug", "Test", "Release" } configurations { "Debug", "Test", "Release" }
language "C++" language "C++"
cppdialect "C++17" cppdialect "C++17"
targetdir "./build/%{prj.name}/%{cfg.buildcfg}" targetdir "./build/%{prj.name}/%{cfg.buildcfg}"
objdir "./intermediates/%{prj.name}/%{cfg.buildcfg}" objdir "./intermediates/%{prj.name}/%{cfg.buildcfg}"
architecture "x86_64" architecture "x86_64"
project "SandboxApplication"
kind "ConsoleApp"
buildmessage "Building BarinkEngineSandbox ..."
includedirs {
"./libs/assimp/include",
"./libs/glad/include",
"./MyGraphicsEngine",
"./MyGraphicsEngine/include",
"./libs/spdlog/include",
"./libs/glm",
"./libs/GorillaAudio/include",
"./libs/lua/include",
"./libs/glfw/include",
"./libs/ImGui",
"./libs/lua/include"
}
libdirs{
"./libs/spdlog/build/Release",
"./libs/glfw/build/src/Debug",
"./libs/lua",
"./libs/ImGui"
}
links{
"lua54",
"spdlog",
"glfw3",
"MyGraphicsEngine"
}
files {
"./libs/ImGui/*.cpp",
"./libs/ImGui/backends/imgui_impl_glfw.cpp",
"./libs/ImGui/backends/imgui_impl_Opengl3.cpp",
"SandboxApplication/*.cpp"
}
defines {"DEBUG"}
symbols "On"
-- NOTE: make these copy instructions more flexible
ok, err = os.copyfile("MyGraphicsEngine/shaders/fragment.shader", "build/SandboxApplication/Debug/test.fs")
if err then error("Copy fragment shader source failed!") end
ok, err = os.copyfile("MyGraphicsEngine/shaders/vertex.shader", "build/SandboxApplication/Debug/test.vs")
if err then error("Copy vertex shader source failed!") end
project "MyGraphicsEngine"
kind "StaticLib"
buildmessage "Building MyGraphicsEngine ..."
includedirs {
"./libs/assimp/include",
"./libs/glad/include",
"./libs/glfw/include",
"./libs/tinygltf",
"./libs/glew/include",
"./libs/spdlog/include",
"./libs/glm",
"./MyGraphicsEngine/include"
}
libdirs{
"./libs/spdlog/build/Release",
"./libs/assimp/lib/Debug",
"./libs/glfw/build/src/Debug"
}
links {
"spdlog",
"assimp-vc143-mtd",
"glfw3"
}
files {
"./libs/glad/src/glad.c",
"./MyGraphicsEngine/**/*.*" ,
"./MyGraphicsEngine/*.*"
}
filter "configurations:Debug" filter "configurations:Debug"
defines {"DEBUG"} defines {"DEBUG"}
@ -102,3 +17,27 @@ workspace "BarinkEngine"
filter "configurations:Release" filter "configurations:Release"
defines {"NDEBUG"} defines {"NDEBUG"}
optimize "On" optimize "On"
project "SandboxApplication"
kind "ConsoleApp"
buildmessage "Building Sandbox ..."
links{
"BarinkEngine"
}
includedirs{
"./BarinkEngine/include"
}
files {
"./SandboxApplication/*.h",
"./SandboxApplication/*.cpp"
}
include("./BarinkEngine")
include("./MyGraphicsEngine")