From 19b630104c766dc6e3d642ccbfbf2f289f9b3391 Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Mon, 5 Jun 2023 17:47:40 +0200 Subject: [PATCH] Big clean up, getting ready for new AssetManagement * Removing Old EventSystem * Removing Assets from Editor project * Clean up of EditorLayer.h * Moving primitives of renderer out of their subfolder --- .gitattributes | 1 + Editor/premake5.lua | 1 - Editor/rsc/Yoggie2.jpeg | 3 + Editor/src/AssetManagement/Asset.h | 56 ---- Editor/src/AssetManagement/AssetFinder.h | 105 ------- .../AssetLoaders/AssetLoader.h | 9 - .../AssetLoaders/ModelLoader.cpp | 109 ------- .../AssetLoaders/ModelLoader.h | 8 - Editor/src/AssetManagement/AssetRegistry.cpp | 140 --------- Editor/src/AssetManagement/AssetRegistry.h | 26 -- Editor/src/EditorLayer.h | 276 ++++++++---------- Editor/src/{PropertyPanels => }/Inspector.cpp | 4 +- Editor/src/{PropertyPanels => }/Inspector.h | 2 +- Editor/src/{Project => }/Project.cpp | 0 Editor/src/{Project => }/Project.h | 0 Editor/src/Project/Settings.cpp | 48 --- Editor/src/Project/Settings.h | 30 -- Editor/src/app.cpp | 1 - YoggieEngine/premake5.lua | 3 +- YoggieEngine/src/Assets/Asset.h | 21 ++ YoggieEngine/src/Assets/AssetImporter.cpp | 143 +++++++++ YoggieEngine/src/Assets/AssetImporter.h | 12 + YoggieEngine/src/Assets/AssetManager.h | 16 + .../src/Assets/AssetManagerEditor.cpp | 41 +++ YoggieEngine/src/Assets/AssetManagerEditor.h | 11 + YoggieEngine/src/Assets/AssetMetadata.h | 7 + .../src/Assets}/uuid.h | 16 +- YoggieEngine/src/EventSystem/Event.h | 12 - YoggieEngine/src/EventSystem/EventEmitter.cpp | 28 -- YoggieEngine/src/EventSystem/EventEmitter.h | 16 - YoggieEngine/src/EventSystem/EventListener.h | 9 - .../src/Graphics/{Memory => }/Buffer.cpp | 0 .../src/Graphics/{Memory => }/Buffer.h | 0 .../src/Graphics/{Primitives => }/Camera.h | 0 .../src/Graphics/{Primitives => }/CubeMap.cpp | 0 .../src/Graphics/{Primitives => }/CubeMap.h | 0 .../Graphics/{Primitives => }/DrawCommand.h | 0 .../src/Graphics/{Memory => }/FrameBuffer.cpp | 0 .../src/Graphics/{Memory => }/Framebuffer.h | 0 .../Graphics/{Primitives => }/Material.cpp | 0 .../src/Graphics/{Primitives => }/Material.h | 0 .../src/Graphics/{Primitives => }/Mesh.h | 0 YoggieEngine/src/Graphics/OpenglAPI.cpp | 5 + YoggieEngine/src/Graphics/RenderSurface.h | 4 +- YoggieEngine/src/Graphics/Renderable.h | 9 - YoggieEngine/src/Graphics/Renderer.cpp | 14 +- YoggieEngine/src/Graphics/Renderer.h | 4 +- .../src/Graphics/{Primitives => }/Shader.cpp | 0 .../src/Graphics/{Primitives => }/Shader.h | 9 +- .../src/Graphics/{Primitives => }/Texture.cpp | 6 +- .../src/Graphics/{Primitives => }/Texture.h | 8 +- .../Graphics/{Memory => }/UniformBuffer.cpp | 0 .../src/Graphics/{Memory => }/UniformBuffer.h | 0 .../src/Graphics/{Primitives => }/Vertex.h | 0 .../src/Graphics/{Memory => }/VertexArray.cpp | 0 .../src/Graphics/{Memory => }/VertexArray.h | 0 YoggieEngine/src/Platform/Window.h | 3 - YoggieEngine/src/Scene/Scene.cpp | 50 ---- .../src/Scene}/SceneSerializer.cpp | 1 + .../src/Scene}/SceneSerializer.h | 0 YoggieEngine/src/Scene/UUID.h | 16 - YoggieEngine/src/YoggieEngine.h | 15 +- 62 files changed, 431 insertions(+), 867 deletions(-) create mode 100644 Editor/rsc/Yoggie2.jpeg delete mode 100644 Editor/src/AssetManagement/Asset.h delete mode 100644 Editor/src/AssetManagement/AssetFinder.h delete mode 100644 Editor/src/AssetManagement/AssetLoaders/AssetLoader.h delete mode 100644 Editor/src/AssetManagement/AssetLoaders/ModelLoader.cpp delete mode 100644 Editor/src/AssetManagement/AssetLoaders/ModelLoader.h delete mode 100644 Editor/src/AssetManagement/AssetRegistry.cpp delete mode 100644 Editor/src/AssetManagement/AssetRegistry.h rename Editor/src/{PropertyPanels => }/Inspector.cpp (99%) rename Editor/src/{PropertyPanels => }/Inspector.h (94%) rename Editor/src/{Project => }/Project.cpp (100%) rename Editor/src/{Project => }/Project.h (100%) delete mode 100644 Editor/src/Project/Settings.cpp delete mode 100644 Editor/src/Project/Settings.h create mode 100644 YoggieEngine/src/Assets/Asset.h create mode 100644 YoggieEngine/src/Assets/AssetImporter.cpp create mode 100644 YoggieEngine/src/Assets/AssetImporter.h create mode 100644 YoggieEngine/src/Assets/AssetManager.h create mode 100644 YoggieEngine/src/Assets/AssetManagerEditor.cpp create mode 100644 YoggieEngine/src/Assets/AssetManagerEditor.h create mode 100644 YoggieEngine/src/Assets/AssetMetadata.h rename {Editor/src/AssetManagement => YoggieEngine/src/Assets}/uuid.h (78%) delete mode 100644 YoggieEngine/src/EventSystem/Event.h delete mode 100644 YoggieEngine/src/EventSystem/EventEmitter.cpp delete mode 100644 YoggieEngine/src/EventSystem/EventEmitter.h delete mode 100644 YoggieEngine/src/EventSystem/EventListener.h rename YoggieEngine/src/Graphics/{Memory => }/Buffer.cpp (100%) rename YoggieEngine/src/Graphics/{Memory => }/Buffer.h (100%) rename YoggieEngine/src/Graphics/{Primitives => }/Camera.h (100%) rename YoggieEngine/src/Graphics/{Primitives => }/CubeMap.cpp (100%) rename YoggieEngine/src/Graphics/{Primitives => }/CubeMap.h (100%) rename YoggieEngine/src/Graphics/{Primitives => }/DrawCommand.h (100%) rename YoggieEngine/src/Graphics/{Memory => }/FrameBuffer.cpp (100%) rename YoggieEngine/src/Graphics/{Memory => }/Framebuffer.h (100%) rename YoggieEngine/src/Graphics/{Primitives => }/Material.cpp (100%) rename YoggieEngine/src/Graphics/{Primitives => }/Material.h (100%) rename YoggieEngine/src/Graphics/{Primitives => }/Mesh.h (100%) delete mode 100644 YoggieEngine/src/Graphics/Renderable.h rename YoggieEngine/src/Graphics/{Primitives => }/Shader.cpp (100%) rename YoggieEngine/src/Graphics/{Primitives => }/Shader.h (85%) rename YoggieEngine/src/Graphics/{Primitives => }/Texture.cpp (93%) rename YoggieEngine/src/Graphics/{Primitives => }/Texture.h (59%) rename YoggieEngine/src/Graphics/{Memory => }/UniformBuffer.cpp (100%) rename YoggieEngine/src/Graphics/{Memory => }/UniformBuffer.h (100%) rename YoggieEngine/src/Graphics/{Primitives => }/Vertex.h (100%) rename YoggieEngine/src/Graphics/{Memory => }/VertexArray.cpp (100%) rename YoggieEngine/src/Graphics/{Memory => }/VertexArray.h (100%) rename {Editor/src/AssetManagement => YoggieEngine/src/Scene}/SceneSerializer.cpp (99%) rename {Editor/src/AssetManagement => YoggieEngine/src/Scene}/SceneSerializer.h (100%) delete mode 100644 YoggieEngine/src/Scene/UUID.h diff --git a/.gitattributes b/.gitattributes index afa1ec1..d0e571d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ *.png filter=lfs diff=lfs merge=lfs -text *.webp filter=lfs diff=lfs merge=lfs -text *.xcf filter=lfs diff=lfs merge=lfs -text +*.jpeg filter=lfs diff=lfs merge=lfs -text diff --git a/Editor/premake5.lua b/Editor/premake5.lua index 24736ee..d6a3a10 100644 --- a/Editor/premake5.lua +++ b/Editor/premake5.lua @@ -6,7 +6,6 @@ buildmessage "Building editor ..." links{ "YoggieEngine", "ImGuizmo", - "yaml-cpp", "nfd" } diff --git a/Editor/rsc/Yoggie2.jpeg b/Editor/rsc/Yoggie2.jpeg new file mode 100644 index 0000000..e81e88d --- /dev/null +++ b/Editor/rsc/Yoggie2.jpeg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de43dd6152aebb1d305680d38a2f99e594d1d764b7f114335f37822d381bfb4c +size 39681 diff --git a/Editor/src/AssetManagement/Asset.h b/Editor/src/AssetManagement/Asset.h deleted file mode 100644 index dd62cf4..0000000 --- a/Editor/src/AssetManagement/Asset.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once -#include "../../YoggieEngine/src/YoggieEngine.h" -#include -#include -#include "uuid.h" - -enum class ASSET_TYPE { - Unknown = -1, - Mesh, - Texture, - Material, - Shader, - Model, - File -}; - -class Asset { -public: - Asset(const char* name): name(name) {} - - virtual ASSET_TYPE GetType() { return detectAssetType(); } - - const char* GetName() const { return name.c_str(); } - void setName(std::string& name) { name = name.c_str(); } - void setFilPath(std::string& path) { file = std::filesystem::path(path); } - - std::string getId() { return Id.String(); } - - -protected: - uuid::v4::UUID Id = uuid::v4::UUID::New(); - - std::string name; - std::filesystem::path file; - - - - ASSET_TYPE detectAssetType() { - auto ext = (file.extension()).string(); - if (ext == ".obj" || ext == ".gltf" || ext == ".fbx" || ext == ".stl") { - return ASSET_TYPE::Model; - } - else if (ext == ".yproj") { - return ASSET_TYPE::File; - } - else if (ext == ".vs" || ext == ".fs") { - return ASSET_TYPE::File; - } - else { - spdlog::warn("unknown file!"); - return ASSET_TYPE::Unknown; - } - } - - -}; \ No newline at end of file diff --git a/Editor/src/AssetManagement/AssetFinder.h b/Editor/src/AssetManagement/AssetFinder.h deleted file mode 100644 index 25aca38..0000000 --- a/Editor/src/AssetManagement/AssetFinder.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once -#include "../../YoggieEngine/src/YoggieEngine.h" -#include "../EditorWindow.h" -#include "AssetRegistry.h" - -const char* hidden_extensions [] { - ".exe", - ".pdb", - ".idb", - ".dll", - ".ini" -}; - -class AssetFinder : public EditorWindow { -public: - AssetFinder () : EditorWindow("Assets") {} - AssetFinder(const std::filesystem::path& projectdirectory) : EditorWindow("Assets") - { - assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png"); - - spdlog::info("asset iconID: {0}", assetIcon.GetID()); - - for (auto& dir_entry : std::filesystem::directory_iterator(projectdirectory)) { - auto filepath = dir_entry.path(); - - if (dir_entry.is_directory() || dir_entry.is_symlink() || dir_entry.is_socket()) - continue; - - bool has_hidden_extension = false; - for (auto hide : hidden_extensions) { - if (filepath.extension() == hide) - { - has_hidden_extension = true; - break; - } - } - - if (has_hidden_extension) - continue; - - Asset asset(filepath.filename().string().c_str()); - - auto filepathStr = filepath.string(); - asset.setFilPath(filepathStr); - spdlog::info("Created asset: {0}", asset.GetName()); - files.push_back(asset); - - - } - - } - - void Draw() override { - - ImGui::DragInt("IconSize", &iconSize, 1, 30, 90); - ImGui::DragInt("Maximum Columns", &maxColumns, 1, 1, 6); - if (ImGui::BeginTable("##resources", 3)) - { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f)); - - - - int row = 0; - int column = 0; - for (auto& asset : files ) { - if (column % 3 == 0) { - ImGui::TableNextRow(); - column = 0; - row++; - } - - ImGui::TableSetColumnIndex(column); - - ImGui::ImageButton( - (ImTextureID)assetIcon.GetID(), - ImVec2{ (float)iconSize, (float)iconSize }); - ImGui::Text(asset.GetName(), row); - - - - column++; - } - - - - ImGui::PopStyleColor(3); - ImGui::EndTable(); - - - } - } - -private: - std::vector files = std::vector(); - - int iconSize = 60; - int maxColumns = 3; - - YoggieEngine::Texture folderIcon; - YoggieEngine::Texture assetIcon; - -}; - diff --git a/Editor/src/AssetManagement/AssetLoaders/AssetLoader.h b/Editor/src/AssetManagement/AssetLoaders/AssetLoader.h deleted file mode 100644 index ff38519..0000000 --- a/Editor/src/AssetManagement/AssetLoaders/AssetLoader.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include -#include "../Asset.h" -class AssetLoader { -public: - virtual Asset LoadAsset(std::filesystem::path& path) = 0; - // virtual void PackageAsset(Asset& asset ) = 0; - -}; \ No newline at end of file diff --git a/Editor/src/AssetManagement/AssetLoaders/ModelLoader.cpp b/Editor/src/AssetManagement/AssetLoaders/ModelLoader.cpp deleted file mode 100644 index c6aa37d..0000000 --- a/Editor/src/AssetManagement/AssetLoaders/ModelLoader.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "ModelLoader.h" -#include -#include -#include - - - -void ProcessVertices(aiMesh* mesh, std::vector& out_vertices) { - for (unsigned int i = 0; i < mesh->mNumVertices; i++) { - YoggieEngine::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& out_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]); - } - } -} - - - -YoggieEngine::Mesh processMesh(aiMesh* mesh, const aiScene* scene) { - std::vector indices; - std::vector vertices; - - ProcessVertices(mesh, vertices); - ProcessIndices(mesh, indices); - - YoggieEngine::Mesh result; - result.vertices = vertices; - result.elements = indices; - - return result; - -} - -std::vector processNode(aiNode* node, const aiScene* scene) { - - std::vector meshes = std::vector(); - - 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; - - -} - -Asset ModelLoader::LoadAsset(std::filesystem::path& path) { - - - - Assimp::Importer importer; - - const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs); - - aiNode* currentNode = scene->mRootNode; - - - spdlog::info("Loading meshes!" ); - - auto meshes = processNode(currentNode, scene); - - spdlog::info("Model file contained {0} meshes", meshes.size() ); - - - - return Asset("Mesh"); - - - -} \ No newline at end of file diff --git a/Editor/src/AssetManagement/AssetLoaders/ModelLoader.h b/Editor/src/AssetManagement/AssetLoaders/ModelLoader.h deleted file mode 100644 index 58b0fd5..0000000 --- a/Editor/src/AssetManagement/AssetLoaders/ModelLoader.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "AssetLoader.h" - -class ModelLoader : AssetLoader { -public: - Asset LoadAsset(std::filesystem::path& path); - -}; \ No newline at end of file diff --git a/Editor/src/AssetManagement/AssetRegistry.cpp b/Editor/src/AssetManagement/AssetRegistry.cpp deleted file mode 100644 index c235de2..0000000 --- a/Editor/src/AssetManagement/AssetRegistry.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "AssetRegistry.h" - -#include -#include -#include -/* -* this is still a very naive approach to the asset manager -*/ - -AssetRegistry::AssetRegistry() -{ -} - - -void AssetRegistry::RegisterAsset(Asset& asset) -{ - Assets.try_emplace(asset.getId() , asset); -} - - -void AssetRegistry::UnregisterAsset(Asset& asset) { - Assets.erase(asset.getId()); -} - - - - -YoggieEngine::Mesh* AssetRegistry::LoadFromAssetFile(const std::filesystem::path assetPath) -{ - YoggieEngine::Mesh* imported = nullptr; - - std::ifstream AssetFile; - AssetFile.open(assetPath, std::ios::binary); - if (AssetFile.is_open()) { - - char* Header = (char*)malloc(8); - unsigned long long Vsize = 0; - uint32_t Vnum = 0; - uint32_t Enum = 0; - - // Read header - AssetFile.read(Header, 8); - AssetFile.read((char*)&Vsize, sizeof(unsigned long long)); - AssetFile.read((char*)&Vnum, sizeof(uint32_t)); - AssetFile.read((char*)&Enum, sizeof(uint32_t)); - - // print Header info - spdlog::info("File has header: {0}", Header); - spdlog::info ( "Vertex size: {0}", Vsize ); - spdlog::info("Number of Vertices: {0}" ,Vnum ); - spdlog::info ("Number of Elements: " , Enum ); - free(Header); - - - imported = new YoggieEngine::Mesh(); - // Load Vertices (Vertex + UV ) - imported->vertices = std::vector < YoggieEngine::Vertex>(); - for (int i = 0; i < Vnum; i++) - { - YoggieEngine::Vertex data = YoggieEngine::Vertex(); - AssetFile.read((char*)&data, Vsize); - - imported->vertices.push_back(data); - - } - - // skip x bytes - AssetFile.ignore(sizeof(char) * 3); - - // Load Elements - imported->elements = std::vector(); - for (int i = 0; i < Enum; i++) { - unsigned int data = 0; - AssetFile.read((char*)&data, sizeof(unsigned int)); - imported->elements.push_back(data); - } - - } - else { - spdlog::error( "Failed ot open mesh " ); - } - - return imported; - - -} -/* - - -YoggieEngine::Renderable* AssetRegistry::LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder) -{ - - * auto model = (YoggieEngine::ModelImporter()).Import(srcPath.string()); - YoggieEngine::Mesh* exportMesh = model->renderable->mesh; - std::filesystem::path MeshFileName = assetFolder / srcPath.filename().replace_extension(".mesh"); - spdlog::info( "Save path: {0}" , MeshFileName ); - - std::ofstream meshAsset; - meshAsset.open(MeshFileName, std::ios::binary); - if (meshAsset.is_open()) { - - // write a header - static const char* HEADER = "MESH"; - meshAsset.write(HEADER, sizeof(HEADER)); - auto Vsize = sizeof(YoggieEngine::Vertex); - spdlog::info( "size of vertex: {0}" ,Vsize ); - spdlog::info("Addr of vSize: {0}" , &Vsize ); - auto Vnum = exportMesh->vertices.size(); - auto Enum = exportMesh->elements.size(); - - meshAsset.write((char*)&Vsize, sizeof(unsigned long long)); - meshAsset.write((char*)&Vnum, sizeof(uint32_t)); - meshAsset.write((char*)&Enum, sizeof(uint32_t)); - // write all vertices - for (auto& vertice : exportMesh->vertices) - { - meshAsset.write((char*)&vertice, sizeof(vertice)); - } - - // write 3 x 0 byte - meshAsset.write((const char*)"\0\0\0", sizeof(char) * 3); - - // write all indices - for (auto index : exportMesh->elements) { - meshAsset.write((char*)&index, sizeof(index)); - } - - - meshAsset.close(); - } - else { - - spdlog::error("Failed to create/open mesh file."); - } - - return model->renderable; - - return nullptr; -} - */ diff --git a/Editor/src/AssetManagement/AssetRegistry.h b/Editor/src/AssetManagement/AssetRegistry.h deleted file mode 100644 index 81932b7..0000000 --- a/Editor/src/AssetManagement/AssetRegistry.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include -#include "Asset.h" -#include "uuid.h" - -class AssetRegistry { -public: - - AssetRegistry(); - //AssetRegistry(AssetPack); - - void RegisterAsset(Asset& asset); - void UnregisterAsset(Asset& asset); - - - - void Update(); - - - static YoggieEngine::Mesh* LoadFromAssetFile(const std::filesystem::path assetPath); -// static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder); - -private: - int unique_number = 0; - std::map Assets = std::map (); -}; \ No newline at end of file diff --git a/Editor/src/EditorLayer.h b/Editor/src/EditorLayer.h index 6b6194c..a470edf 100644 --- a/Editor/src/EditorLayer.h +++ b/Editor/src/EditorLayer.h @@ -1,31 +1,16 @@ #pragma once #include #include -#include -#include -#include #include - -#include "AssetManagement/SceneSerializer.h" -#include "AssetManagement/AssetFinder.h" -#include "PropertyPanels/Inspector.h" -#include "AssetManagement/uuid.h" -#include "Project/Settings.h" -#include "Console.h" -#include "AssetManagement/AssetLoaders/ModelLoader.h" -#include "IconsMaterialDesign.h" -#include "Project/Project.h" #include -#include "EditorCamera.h" -#include "../../YoggieEngine/src/Graphics/Memory/VertexArray.h" -#include "../../YoggieEngine/src/Graphics/Memory/Buffer.h" +#include "Inspector.h" +#include "Console.h" +#include "IconsMaterialDesign.h" +#include "Project.h" +#include "EditorCamera.h" using namespace YoggieEngine; -const float movement_speed = 0.1f; -static float lastX = 400, lastY = 300; -const float sensitivity = 0.1; -static bool firstMouse = true; class EditorLayer : public Layer { @@ -33,129 +18,31 @@ class EditorLayer : public Layer { public: EditorLayer() : Layer(), - Logo("rsc/Yoggie.png"), inspector(Selected), scene(), renderer() { - - spdlog::info("Colour attachment id: {0}", renderer.getCurrentFrameBuffer().GetColourAttachment()); - - Selected = YoggieEngine::Entity((entt::entity)-1, &scene); - - AssetRegistry assetManager = AssetRegistry(); - // ModelLoader modelLoader = ModelLoader(); + Logo.Load("rsc/Yoggie.png"); spdlog::info("{0}", project.GetProjectDirectory().string()); - - //auto latern = modelLoader.LoadAsset(std::filesystem::path("build/debug/Models/Latern.gltf")); - //spdlog::info("Loaded mesh: {0}", latern.GetName()); - + Selected = YoggieEngine::Entity((entt::entity)-1, &scene); + } void OnStartup() override { std::string path = (std::filesystem::current_path()).string(); project.setProjectDirectory(path); - assetsView = AssetFinder(project.GetProjectDirectory()); LoadLastOrEmptyProject(); - - - auto cubePath = std::filesystem::path("build/debug/Models/cube.obj"); - - cube = (ModelLoader()).LoadAsset(cubePath); - //Settings settings = Settings(); //Console console = Console(); } void OnUpdate() override { scene.Update(); - - auto components = scene.getReg().view(); - for(auto component : components){ - auto& renderComponent = YoggieEngine::Entity(component, &scene).GetComponent(); - - renderComponent.mesh = cube; - - if (renderComponent.VAO == 0 || renderComponent.IBO == 0) { - VertexArray va = VertexArray(); - Buffer vertexBuffer = Buffer(); - Buffer elementBuffer = Buffer(); - - va.Create(); - va.Bind(); - - vertexBuffer.createBuffer(); - vertexBuffer.Bind(false); - vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(Vertex), false); - - elementBuffer.createBuffer(); - elementBuffer.Bind(true); - elementBuffer.setBufferData((void*)&renderComponent.mesh.elements[0], renderComponent.mesh.elements.size() * sizeof(unsigned int), true); - - va.AttachAttribute(0, 3, sizeof(Vertex)); - - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - - va.Unbind(); - vertexBuffer.Unbind(false); - elementBuffer.Unbind(true); - - renderComponent.VAO = va.getID(); - renderComponent.IBO = elementBuffer.getBufferID(); - - } - - - - - } - - - renderer.Render(scene, *camera); - - } - bool OnKey(int key, int mode) override { - - if (SceneisFocused) { - if (key == YOGGIE_KEY_UP) - camera->Rotation.x += movement_speed; - if (key == YOGGIE_KEY_DOWN) - camera->Rotation.x -= movement_speed; - - if (key == YOGGIE_KEY_LEFT) - camera->Rotation.y += movement_speed; - - if (key == YOGGIE_KEY_RIGHT) - camera->Rotation.y -= movement_speed; - - - - if (key == YOGGIE_KEY_A) - camera->Position += glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed; - - if (key == YOGGIE_KEY_S) - camera->Position += glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed; - - if (key == YOGGIE_KEY_D) - camera->Position -= glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed; - - if (key == GLFW_KEY_W) - camera->Position -= glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed; - - } - - - return true; - } - - ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE; void OnUI() override { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { ImGui::GetWindowWidth(), 7 }); @@ -272,15 +159,6 @@ public: switch (result) { case(NFD_OKAY): { - YoggieEngine::Mesh* importedMesh = AssetRegistry::LoadFromAssetFile(path); - if (importedMesh != nullptr) - { - auto full_name = std::filesystem::path(path); - // auto importedModel = scene.AddEntity(full_name.filename().u8string()); - // auto& rendererComponent = importedModel.AddComponent(); - // rendererComponent.mesh = *importedMesh; - - } } break; @@ -307,13 +185,6 @@ public: ImGui::SameLine(ImGui::GetWindowWidth() - 120); - /* - ImGui::PopStyleColor(); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.1f, 0.1f, 0.1f, 0.01f)); - if (ImGui::Button(ICON_MD_MINIMIZE)) { spdlog::info("Minimize"); } - if (ImGui::Button(ICON_MD_MAXIMIZE)) { spdlog::info("Maximize"); } - if (ImGui::Button(ICON_MD_CLOSE)) { spdlog::info("Quit"); } - */ ImGui::PopStyleColor(1); ImGui::PopStyleVar(); @@ -412,7 +283,7 @@ public: // spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); SceneisFocused = ImGui::IsWindowFocused() || ImGui::IsWindowHovered(); ImGui::Image((ImTextureID)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(), - ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()},ImVec2{1,1}, ImVec2{0,0}); + ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()}); @@ -472,14 +343,74 @@ public: ImGui::End(); - inspector.Update(); + /* + { + ImGui::Begin("Asset", nullptr); + + const char* hidden_extensions[]{ + ".exe", + ".pdb", + ".idb", + ".dll", + ".ini" + }; - //settings.Update(); - //console.Update(); + std::vector files = std::vector(); - assetsView.Update(); + int iconSize = 60; + int maxColumns = 3; + YoggieEngine::Texture folderIcon; + YoggieEngine::Texture assetIcon; + + assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png"); + + + ImGui::DragInt("IconSize", &iconSize, 1, 30, 90); + ImGui::DragInt("Max. Columns", &maxColumns, 1, 1, 6); + + if (ImGui::BeginTable("##Resources", 3)) { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f)); + + int row = 0; + int column = 0; + for (auto& asset : files) { + if (column % 3 == 0) { + ImGui::TableNextRow(); + column = 0; + row++; + } + + ImGui::TableSetColumnIndex(column); + + ImGui::ImageButton( + (ImTextureID)assetIcon.GetID(), + ImVec2{ (float)iconSize, (float)iconSize }); + ImGui::Text(asset.GetName(), row); + + + + column++; + } + + + + ImGui::PopStyleColor(3); + ImGui::EndTable(); + + + + } + + ImGui::End(); + + } + */ + + ImGui::ShowDemoWindow(); //ImGui::ShowMetricsWindow(); } @@ -496,23 +427,64 @@ public: } + + bool OnKey(int key, int mode) override { + float movement_speed = 0.10f; + + if (SceneisFocused) { + if (key == YOGGIE_KEY_UP) + camera->Rotation.x += movement_speed; + + if (key == YOGGIE_KEY_DOWN) + camera->Rotation.x -= movement_speed; + + if (key == YOGGIE_KEY_LEFT) + camera->Rotation.y += movement_speed; + + if (key == YOGGIE_KEY_RIGHT) + camera->Rotation.y -= movement_speed; + + + + if (key == YOGGIE_KEY_A) + camera->Position += glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed; + + if (key == YOGGIE_KEY_S) + camera->Position += glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed; + + if (key == YOGGIE_KEY_D) + camera->Position -= glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed; + + if (key == GLFW_KEY_W) + camera->Position -= glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed; + + } + + + return true; + } + + + private: Inspector inspector; - AssetFinder assetsView; + Renderer renderer; + + EditorCamera* camera = new EditorCamera(); + - bool SimulatePhysics = true; - YoggieEngine::Entity Selected; Project project; Scene scene; - char* path = nullptr; - Texture Logo; - Renderer renderer; - EditorCamera* camera = new EditorCamera(); - Mesh cube ; + + bool SimulatePhysics = true; bool SceneisFocused = false; + YoggieEngine::Entity Selected; + ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE; - + char* path = nullptr; + Texture Logo; + void LoadLastOrEmptyProject() { // Check if there is a last known loaded project and // load that one . @@ -536,7 +508,7 @@ private: { Project::LoadProject(ini["cache"]["project"], project); - LoadScene(ini["cache"]["scene"], scene); + ///LoadScene(ini["cache"]["scene"], scene); } else diff --git a/Editor/src/PropertyPanels/Inspector.cpp b/Editor/src/Inspector.cpp similarity index 99% rename from Editor/src/PropertyPanels/Inspector.cpp rename to Editor/src/Inspector.cpp index 5f08a3c..125cdfd 100644 --- a/Editor/src/PropertyPanels/Inspector.cpp +++ b/Editor/src/Inspector.cpp @@ -1,6 +1,6 @@ #include "Inspector.h" -#include "../TransformVec3.h" -#include "../IconsMaterialDesign.h" +#include "TransformVec3.h" +#include "IconsMaterialDesign.h" void Inspector::Draw() { diff --git a/Editor/src/PropertyPanels/Inspector.h b/Editor/src/Inspector.h similarity index 94% rename from Editor/src/PropertyPanels/Inspector.h rename to Editor/src/Inspector.h index 0a2647f..3c9ad70 100644 --- a/Editor/src/PropertyPanels/Inspector.h +++ b/Editor/src/Inspector.h @@ -1,6 +1,6 @@ #pragma once #include "../../YoggieEngine/src/YoggieEngine.h" -#include "../EditorWindow.h" +#include "EditorWindow.h" typedef void (*voidFunction) (void); diff --git a/Editor/src/Project/Project.cpp b/Editor/src/Project.cpp similarity index 100% rename from Editor/src/Project/Project.cpp rename to Editor/src/Project.cpp diff --git a/Editor/src/Project/Project.h b/Editor/src/Project.h similarity index 100% rename from Editor/src/Project/Project.h rename to Editor/src/Project.h diff --git a/Editor/src/Project/Settings.cpp b/Editor/src/Project/Settings.cpp deleted file mode 100644 index e9c7e83..0000000 --- a/Editor/src/Project/Settings.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "Settings.h" - -void Settings::Draw() { - ImGui::LabelText("##title-settings", "Fine grain control over the engine!"); - - if (ImGui::BeginCombo("Graphics API", GraphicsAPI[selectedGfxAPI])) { - for (int i = 0; i < 3; i++) { - bool isSelected = i == selectedGfxAPI; - if (ImGui::Selectable(GraphicsAPI[i], isSelected)) { - selectedGfxAPI = i; - } - - if (isSelected) - ImGui::SetItemDefaultFocus(); - } - - ImGui::EndCombo(); - } - - ImGui::NewLine(); - - if (ImGui::BeginCombo("Physics Engine", PhysicsEngine[selectedPhysicsEngine])) { - for (int i = 0; i < 2; i++) { - bool isSelected = i == selectedPhysicsEngine; - if (ImGui::Selectable(PhysicsEngine[i], isSelected)) { - selectedGfxAPI = i; - } - - if (isSelected) - ImGui::SetItemDefaultFocus(); - } - - ImGui::EndCombo(); - } - - ImGui::InputFloat3("Gravity", glm::value_ptr(Gravity)); - - ImGui::NewLine(); - if (ImGui::Button("Show Advanced options ")) { - ShowAdvancedOptions = !ShowAdvancedOptions; - } - - if (ShowAdvancedOptions) - { - ImGui::Checkbox("Debug Engine", &DebugEngine); - - } -} \ No newline at end of file diff --git a/Editor/src/Project/Settings.h b/Editor/src/Project/Settings.h deleted file mode 100644 index 20138bf..0000000 --- a/Editor/src/Project/Settings.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include "../../YoggieEngine/src/YoggieEngine.h" -#include "../EditorWindow.h" - - -class Settings : public EditorWindow { -public: - Settings() : EditorWindow("Settings") {} - - void Draw() override; - -private: - int selectedGfxAPI = 0; - int selectedPhysicsEngine = 0; - glm::vec3 Gravity = glm::vec3(0.0f, -9.81f, 0.0f); - bool ShowAdvancedOptions = false; - bool DebugEngine = false; - - const char* PhysicsEngine[2] = { - "PhysX", - "Jolt Physics" - }; - - const char* GraphicsAPI[3] = { - "OpenGL", - "Vulkan", - "Metal (Apple)" - }; - -}; diff --git a/Editor/src/app.cpp b/Editor/src/app.cpp index 7227d54..016f3ce 100644 --- a/Editor/src/app.cpp +++ b/Editor/src/app.cpp @@ -12,7 +12,6 @@ public: void Run() override { PushLayer(new EditorLayer()); - Application::Run(); } diff --git a/YoggieEngine/premake5.lua b/YoggieEngine/premake5.lua index bdacb64..40efa83 100644 --- a/YoggieEngine/premake5.lua +++ b/YoggieEngine/premake5.lua @@ -40,7 +40,7 @@ project "YoggieEngine" "../libs/steam-audio/include", "../libs/ImGui", - + "../libs/yaml-cpp/include" } links { @@ -51,6 +51,7 @@ project "YoggieEngine" "assimp-vc143-mtd", "glfw3", "ImGui", + "yaml-cpp", "PhysX_64", "PhysXCooking_64", diff --git a/YoggieEngine/src/Assets/Asset.h b/YoggieEngine/src/Assets/Asset.h new file mode 100644 index 0000000..9d5bc5f --- /dev/null +++ b/YoggieEngine/src/Assets/Asset.h @@ -0,0 +1,21 @@ +#pragma once +#include "uuid.h" + + +typedef uuid::v4::UUID AssetHandle; + +enum class AssetType { + Unknown = -1, + Mesh, + Texture, + Material, + Shader +}; + +struct Asset { + //AssetHandle Handle; + + //template + //static AssetType GetType(T t) { return t.GetType(); } + virtual AssetType GetType() { return AssetType::Unknown; } +}; diff --git a/YoggieEngine/src/Assets/AssetImporter.cpp b/YoggieEngine/src/Assets/AssetImporter.cpp new file mode 100644 index 0000000..de61d52 --- /dev/null +++ b/YoggieEngine/src/Assets/AssetImporter.cpp @@ -0,0 +1,143 @@ +#include +#include "AssetImporter.h" +#include +#include +#include + +namespace YoggieEngine { + + void ProcessVertices(aiMesh* mesh, std::vector& out_vertices) { + for (unsigned int i = 0; i < mesh->mNumVertices; i++) { + YoggieEngine::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& out_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]); + } + } + } + + YoggieEngine::Mesh processMesh(aiMesh* mesh, const aiScene* scene) { + std::vector indices; + std::vector vertices; + + ProcessVertices(mesh, vertices); + ProcessIndices(mesh, indices); + + YoggieEngine::Mesh result; + result.vertices = vertices; + result.elements = indices; + + return result; + + } + + std::vector processNode(aiNode* node, const aiScene* scene) { + + std::vector meshes = std::vector(); + + 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; + + + } + + void LoadModelFile(std::filesystem::path path) { + Assimp::Importer importer; + const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs); + aiNode* currentNode = scene->mRootNode; + auto meshes = processNode(currentNode, scene); + } + + bool IsSupportedImageFormat(const std::string& extension) { + static std::vector supported_image_extensions = { "jpeg", "jpg", "png","bmp","hdr","psd","tga","gif","pic","psd","pgm","ppm" }; + + for (auto support_extension : supported_image_extensions) { + if (extension == support_extension) + return true; + } + + + return false; + } + + Asset AssetImporter::ImportAsset(AssetMetadata& metadata) { + + static Asset emptyAsset; + + + // Check file extension so we can choose our loader + if (metadata.filepath.has_extension() == true) + { + spdlog::error("Asset file has no extension!"); + } + + const auto extension = metadata.filepath.extension().string(); + + // Handle as Model file + bool IsSupportedModelFile = importer.IsExtensionSupported(extension); + if (IsSupportedModelFile) { + LoadModelFile(metadata.filepath); + return emptyAsset; + } + + + + // Handle as Texture + if (IsSupportedImageFormat(extension)) + { + Texture texture; + texture.Load(metadata.filepath.string()); + return texture; + } + + // Handle as shader + if (extension == "glsl" || extension == "vert" || extension == "frag") { + //Shader shader; + //shader. + return emptyAsset; + } + + return emptyAsset; + + } +}; diff --git a/YoggieEngine/src/Assets/AssetImporter.h b/YoggieEngine/src/Assets/AssetImporter.h new file mode 100644 index 0000000..fdb754b --- /dev/null +++ b/YoggieEngine/src/Assets/AssetImporter.h @@ -0,0 +1,12 @@ +#pragma once +#include "AssetMetadata.h" +#include +namespace YoggieEngine{ + class AssetImporter { + public: + static Asset ImportAsset(AssetMetadata& metadata); + private: + static Assimp::Importer importer; + + }; +} diff --git a/YoggieEngine/src/Assets/AssetManager.h b/YoggieEngine/src/Assets/AssetManager.h new file mode 100644 index 0000000..4162b22 --- /dev/null +++ b/YoggieEngine/src/Assets/AssetManager.h @@ -0,0 +1,16 @@ +#pragma once +#include +#include "AssetMetaData.h" + +typedef std::map AssetRegistry; + +class AssetManager { +public: + virtual Asset& GetAsset(AssetHandle handle) = 0; + +protected: + //AssetRegistry Assets; + //std::map LoadedAssets; + + +}; \ No newline at end of file diff --git a/YoggieEngine/src/Assets/AssetManagerEditor.cpp b/YoggieEngine/src/Assets/AssetManagerEditor.cpp new file mode 100644 index 0000000..a3f33ec --- /dev/null +++ b/YoggieEngine/src/Assets/AssetManagerEditor.cpp @@ -0,0 +1,41 @@ +#include "YoggieEngine.h" +#include "AssetManagerEditor.h" +#include "AssetImporter.h" +using namespace YoggieEngine; + +Asset& AssetManagerEditor::GetAsset(AssetHandle handle) +{ + static Asset EmptyAsset{}; + + // 1. Check if handle is valid + if (IsAssetHandleValid(handle) == false) + return EmptyAsset; + + // 2. check if asset needs loading + Asset asset; + if (IsAssetLoaded(handle)) { + // asset = LoadedAssets.at(handle); + } + else { + // Load asset + // Get MetaData + //auto& metadata = Assets[handle]; + + // Load Asset + //asset = AssetImporter::ImportAsset(metadata); + + } + + // 3. return asset. + return asset; + +} + +bool AssetManagerEditor::IsAssetHandleValid(AssetHandle handle) +{ + return false;///return Assets.find(handle) != Assets.end(); +} + +bool AssetManagerEditor::IsAssetLoaded(AssetHandle handle ) { + return false;//return LoadedAssets.find(handle) != LoadedAssets.end(); +} \ No newline at end of file diff --git a/YoggieEngine/src/Assets/AssetManagerEditor.h b/YoggieEngine/src/Assets/AssetManagerEditor.h new file mode 100644 index 0000000..f4f9de8 --- /dev/null +++ b/YoggieEngine/src/Assets/AssetManagerEditor.h @@ -0,0 +1,11 @@ +#pragma once +#include "AssetManager.h" + +class AssetManagerEditor : public AssetManager { +public: + Asset& GetAsset(AssetHandle handle) override; +private: + bool IsAssetHandleValid(AssetHandle handle); + bool IsAssetLoaded(AssetHandle handle); + +}; \ No newline at end of file diff --git a/YoggieEngine/src/Assets/AssetMetadata.h b/YoggieEngine/src/Assets/AssetMetadata.h new file mode 100644 index 0000000..f4404f2 --- /dev/null +++ b/YoggieEngine/src/Assets/AssetMetadata.h @@ -0,0 +1,7 @@ +#pragma once +#include +#include "Asset.h" +struct AssetMetadata{ + AssetHandle handle; + std::filesystem::path filepath; +}; \ No newline at end of file diff --git a/Editor/src/AssetManagement/uuid.h b/YoggieEngine/src/Assets/uuid.h similarity index 78% rename from Editor/src/AssetManagement/uuid.h rename to YoggieEngine/src/Assets/uuid.h index 3fe0102..b9dd316 100644 --- a/Editor/src/AssetManagement/uuid.h +++ b/YoggieEngine/src/Assets/uuid.h @@ -16,23 +16,24 @@ namespace uuid::v4 class UUID { public: - // Factory method for creating UUID object. - static UUID New() + UUID() {} + + // method for creating UUID object. + void generate () { - UUID uuid; std::random_device rd; std::mt19937 engine{ rd() }; std::uniform_int_distribution dist{ 0, 256 }; //Limits of the interval for (int index = 0; index < 16; ++index) { - uuid._data[index] = (unsigned char)dist(engine); + _data[index] = (unsigned char)dist(engine); } - uuid._data[6] = ((uuid._data[6] & 0x0f) | 0x40); // Version 4 - uuid._data[8] = ((uuid._data[8] & 0x3f) | 0x80); // Variant is 10 + _data[6] = ((_data[6] & 0x0f) | 0x40); // Version 4 + _data[8] = ((_data[8] & 0x3f) | 0x80); // Variant is 10 - return uuid; + } // Returns UUID as formatted string @@ -54,7 +55,6 @@ namespace uuid::v4 } private: - UUID() {} unsigned char _data[16] = { 0 }; }; diff --git a/YoggieEngine/src/EventSystem/Event.h b/YoggieEngine/src/EventSystem/Event.h deleted file mode 100644 index 778b597..0000000 --- a/YoggieEngine/src/EventSystem/Event.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -namespace YoggieEngine { - - struct Event - { - public: - std::string name; - int argc; - void** argv; - - }; -} \ No newline at end of file diff --git a/YoggieEngine/src/EventSystem/EventEmitter.cpp b/YoggieEngine/src/EventSystem/EventEmitter.cpp deleted file mode 100644 index 5f92467..0000000 --- a/YoggieEngine/src/EventSystem/EventEmitter.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include "EventEmitter.h" - -namespace YoggieEngine { - - 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{}; - } -} \ No newline at end of file diff --git a/YoggieEngine/src/EventSystem/EventEmitter.h b/YoggieEngine/src/EventSystem/EventEmitter.h deleted file mode 100644 index 2a9530d..0000000 --- a/YoggieEngine/src/EventSystem/EventEmitter.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -namespace YoggieEngine{ - class EventEmitter { - public: - void Subscribe(EventListener& subscriber); - void Unsubscribe(EventListener& subscriber); - - protected: - std::list subscribers; - void EmitEvent(Event& incident); - - EventEmitter(); - - }; -} diff --git a/YoggieEngine/src/EventSystem/EventListener.h b/YoggieEngine/src/EventSystem/EventListener.h deleted file mode 100644 index faa6745..0000000 --- a/YoggieEngine/src/EventSystem/EventListener.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "Event.h" -namespace YoggieEngine { - class EventListener { - public: - virtual void ReceiveEvent(Event& incident) = 0; - - }; -} diff --git a/YoggieEngine/src/Graphics/Memory/Buffer.cpp b/YoggieEngine/src/Graphics/Buffer.cpp similarity index 100% rename from YoggieEngine/src/Graphics/Memory/Buffer.cpp rename to YoggieEngine/src/Graphics/Buffer.cpp diff --git a/YoggieEngine/src/Graphics/Memory/Buffer.h b/YoggieEngine/src/Graphics/Buffer.h similarity index 100% rename from YoggieEngine/src/Graphics/Memory/Buffer.h rename to YoggieEngine/src/Graphics/Buffer.h diff --git a/YoggieEngine/src/Graphics/Primitives/Camera.h b/YoggieEngine/src/Graphics/Camera.h similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/Camera.h rename to YoggieEngine/src/Graphics/Camera.h diff --git a/YoggieEngine/src/Graphics/Primitives/CubeMap.cpp b/YoggieEngine/src/Graphics/CubeMap.cpp similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/CubeMap.cpp rename to YoggieEngine/src/Graphics/CubeMap.cpp diff --git a/YoggieEngine/src/Graphics/Primitives/CubeMap.h b/YoggieEngine/src/Graphics/CubeMap.h similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/CubeMap.h rename to YoggieEngine/src/Graphics/CubeMap.h diff --git a/YoggieEngine/src/Graphics/Primitives/DrawCommand.h b/YoggieEngine/src/Graphics/DrawCommand.h similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/DrawCommand.h rename to YoggieEngine/src/Graphics/DrawCommand.h diff --git a/YoggieEngine/src/Graphics/Memory/FrameBuffer.cpp b/YoggieEngine/src/Graphics/FrameBuffer.cpp similarity index 100% rename from YoggieEngine/src/Graphics/Memory/FrameBuffer.cpp rename to YoggieEngine/src/Graphics/FrameBuffer.cpp diff --git a/YoggieEngine/src/Graphics/Memory/Framebuffer.h b/YoggieEngine/src/Graphics/Framebuffer.h similarity index 100% rename from YoggieEngine/src/Graphics/Memory/Framebuffer.h rename to YoggieEngine/src/Graphics/Framebuffer.h diff --git a/YoggieEngine/src/Graphics/Primitives/Material.cpp b/YoggieEngine/src/Graphics/Material.cpp similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/Material.cpp rename to YoggieEngine/src/Graphics/Material.cpp diff --git a/YoggieEngine/src/Graphics/Primitives/Material.h b/YoggieEngine/src/Graphics/Material.h similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/Material.h rename to YoggieEngine/src/Graphics/Material.h diff --git a/YoggieEngine/src/Graphics/Primitives/Mesh.h b/YoggieEngine/src/Graphics/Mesh.h similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/Mesh.h rename to YoggieEngine/src/Graphics/Mesh.h diff --git a/YoggieEngine/src/Graphics/OpenglAPI.cpp b/YoggieEngine/src/Graphics/OpenglAPI.cpp index 71097cd..348e2a2 100644 --- a/YoggieEngine/src/Graphics/OpenglAPI.cpp +++ b/YoggieEngine/src/Graphics/OpenglAPI.cpp @@ -30,7 +30,11 @@ namespace YoggieEngine { void OpenGLApi::DrawTriangles(Render3DComponent rc) { glBindVertexArray(rc.VAO); + glCheckError(); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rc.IBO); + glCheckError(); + glDrawElements(GL_TRIANGLES, static_cast (rc.mesh.elements.size()), GL_UNSIGNED_INT, 0); glCheckError(); glBindVertexArray(0); @@ -41,6 +45,7 @@ namespace YoggieEngine { void OpenGLApi::DrawCubeMap(unsigned int VertexAttributeObject, CubeMap CubeTexture) { glDepthMask(GL_FALSE); + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, CubeTexture.getID()); //glCheckError(); // INVALID ENUM FOR SOME REASON glBindVertexArray(VertexAttributeObject); diff --git a/YoggieEngine/src/Graphics/RenderSurface.h b/YoggieEngine/src/Graphics/RenderSurface.h index de27a76..7908439 100644 --- a/YoggieEngine/src/Graphics/RenderSurface.h +++ b/YoggieEngine/src/Graphics/RenderSurface.h @@ -1,6 +1,6 @@ #pragma once -#include "../Graphics/Memory/Buffer.h" -#include "../Graphics/Memory/VertexArray.h" +#include "../Graphics/Buffer.h" +#include "../Graphics/VertexArray.h" namespace YoggieEngine { diff --git a/YoggieEngine/src/Graphics/Renderable.h b/YoggieEngine/src/Graphics/Renderable.h deleted file mode 100644 index 9a1fd78..0000000 --- a/YoggieEngine/src/Graphics/Renderable.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -namespace YoggieEngine { - - struct Renderable { - Mesh* mesh; - Material* material; - Texture* texture; - }; -} \ No newline at end of file diff --git a/YoggieEngine/src/Graphics/Renderer.cpp b/YoggieEngine/src/Graphics/Renderer.cpp index f4282b3..be66a4a 100644 --- a/YoggieEngine/src/Graphics/Renderer.cpp +++ b/YoggieEngine/src/Graphics/Renderer.cpp @@ -2,13 +2,12 @@ #include "Renderer.h" #include "../Scene/Components.h" -#include "../Graphics/Memory/Buffer.h" -#include "../Graphics/Memory/VertexArray.h" -#include "Renderable.h" -#include "Memory/Framebuffer.h" +#include "../Graphics/Buffer.h" +#include "../Graphics/VertexArray.h" +#include "Framebuffer.h" #include "../Scene/Components.h" #include"../Scene/Scene.h" -#include "Primitives/Camera.h" +#include "Camera.h" #include "OpenglAPI.h" namespace YoggieEngine { @@ -95,6 +94,7 @@ Renderer::Renderer() : }; skybox = CubeMap(faces); + grassTexture.Load("build/Debug/Texture/grass.png"); } @@ -162,7 +162,7 @@ void Renderer::Render(Scene& scene , Camera MainCamera){ SkyboxShader.Use(); SkyboxShader.setUniformMat4("projection", MainCamera.getProjection(width, height)); - SkyboxShader.setUniformMat4("view", glm::inverse( glm::mat4(glm::mat3(MainCamera.getTransform())))); + SkyboxShader.setUniformMat4("view", glm::inverse(glm::mat4(glm::mat3(MainCamera.getTransform())))); if (!skyboxVAO) { unsigned int VBO; @@ -268,7 +268,7 @@ void Renderer::Render(Scene& scene , Camera MainCamera){ if (transparentVAO == 0) { unsigned int transparentVBO; float transparentVertices[] = { - // positions // texture Coords (swapped y coordinates because texture is flipped upside down) + // positions // texture Coords 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, diff --git a/YoggieEngine/src/Graphics/Renderer.h b/YoggieEngine/src/Graphics/Renderer.h index d0f5711..3aec024 100644 --- a/YoggieEngine/src/Graphics/Renderer.h +++ b/YoggieEngine/src/Graphics/Renderer.h @@ -3,7 +3,7 @@ #include #include "../PerfCounter.h" #include "../Scene/Scene.h" -#include "Memory/Framebuffer.h" +#include "Framebuffer.h" namespace YoggieEngine { @@ -58,7 +58,7 @@ namespace YoggieEngine { // blending Shader BlendingShader; CubeMap skybox; - Texture grassTexture = Texture("build/Debug/Texture/grass.png"); + Texture grassTexture; unsigned int transparentVAO = 0; unsigned int skyboxVAO = 0; diff --git a/YoggieEngine/src/Graphics/Primitives/Shader.cpp b/YoggieEngine/src/Graphics/Shader.cpp similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/Shader.cpp rename to YoggieEngine/src/Graphics/Shader.cpp diff --git a/YoggieEngine/src/Graphics/Primitives/Shader.h b/YoggieEngine/src/Graphics/Shader.h similarity index 85% rename from YoggieEngine/src/Graphics/Primitives/Shader.h rename to YoggieEngine/src/Graphics/Shader.h index 990a5ff..0ca4c72 100644 --- a/YoggieEngine/src/Graphics/Primitives/Shader.h +++ b/YoggieEngine/src/Graphics/Shader.h @@ -1,12 +1,17 @@ #pragma once - +#include "Assets/Asset.h" namespace YoggieEngine { - class Shader { + class Shader : public Asset{ private: char* readFile(const char* filePath); + + + AssetType GetType() override{ return AssetType::Shader; } public: Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath); + + void Use() const; void setUniformMat4(std::string uniformName, const glm::mat4& matrix4)const; void setUniformVec4(std::string uniformName, const glm::vec4& vector4)const; diff --git a/YoggieEngine/src/Graphics/Primitives/Texture.cpp b/YoggieEngine/src/Graphics/Texture.cpp similarity index 93% rename from YoggieEngine/src/Graphics/Primitives/Texture.cpp rename to YoggieEngine/src/Graphics/Texture.cpp index 90acd80..d6ab1b8 100644 --- a/YoggieEngine/src/Graphics/Primitives/Texture.cpp +++ b/YoggieEngine/src/Graphics/Texture.cpp @@ -2,10 +2,11 @@ #include "Texture.h" namespace YoggieEngine { - Texture::Texture(const std::string texturePath , bool Transparency) { + + void Texture::Load(const std::string texturePath, bool Transparency) { int channels; unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0); - + if (data) { glGenTextures(1, &Id); glBindTexture(GL_TEXTURE_2D, Id); @@ -30,7 +31,6 @@ namespace YoggieEngine { spdlog::error("Failed to load image ({0})", texturePath); } stbi_image_free(data); - } void Texture::Bind() { diff --git a/YoggieEngine/src/Graphics/Primitives/Texture.h b/YoggieEngine/src/Graphics/Texture.h similarity index 59% rename from YoggieEngine/src/Graphics/Primitives/Texture.h rename to YoggieEngine/src/Graphics/Texture.h index b7e2a2c..405fdc1 100644 --- a/YoggieEngine/src/Graphics/Primitives/Texture.h +++ b/YoggieEngine/src/Graphics/Texture.h @@ -1,14 +1,18 @@ #pragma once +#include "Assets/Asset.h" + namespace YoggieEngine { - class Texture { + class Texture : public Asset { public: Texture() = default; - Texture(const std::string texturePath, bool Transparency = false); + void Load(const std::string texturePath, bool Transparency = false); void Bind(); void Unbind(); const unsigned int GetID() const { return Id; } const ImVec2 getSize() { return {(float)width, (float)height}; } + + AssetType GetType() override { return AssetType::Texture; } private: unsigned int Id; int width; diff --git a/YoggieEngine/src/Graphics/Memory/UniformBuffer.cpp b/YoggieEngine/src/Graphics/UniformBuffer.cpp similarity index 100% rename from YoggieEngine/src/Graphics/Memory/UniformBuffer.cpp rename to YoggieEngine/src/Graphics/UniformBuffer.cpp diff --git a/YoggieEngine/src/Graphics/Memory/UniformBuffer.h b/YoggieEngine/src/Graphics/UniformBuffer.h similarity index 100% rename from YoggieEngine/src/Graphics/Memory/UniformBuffer.h rename to YoggieEngine/src/Graphics/UniformBuffer.h diff --git a/YoggieEngine/src/Graphics/Primitives/Vertex.h b/YoggieEngine/src/Graphics/Vertex.h similarity index 100% rename from YoggieEngine/src/Graphics/Primitives/Vertex.h rename to YoggieEngine/src/Graphics/Vertex.h diff --git a/YoggieEngine/src/Graphics/Memory/VertexArray.cpp b/YoggieEngine/src/Graphics/VertexArray.cpp similarity index 100% rename from YoggieEngine/src/Graphics/Memory/VertexArray.cpp rename to YoggieEngine/src/Graphics/VertexArray.cpp diff --git a/YoggieEngine/src/Graphics/Memory/VertexArray.h b/YoggieEngine/src/Graphics/VertexArray.h similarity index 100% rename from YoggieEngine/src/Graphics/Memory/VertexArray.h rename to YoggieEngine/src/Graphics/VertexArray.h diff --git a/YoggieEngine/src/Platform/Window.h b/YoggieEngine/src/Platform/Window.h index 322947e..25e271c 100644 --- a/YoggieEngine/src/Platform/Window.h +++ b/YoggieEngine/src/Platform/Window.h @@ -1,7 +1,4 @@ #pragma once -#include "../EventSystem/Event.h" -#include "../EventSystem/EventListener.h" - namespace YoggieEngine { class NativeWindow { diff --git a/YoggieEngine/src/Scene/Scene.cpp b/YoggieEngine/src/Scene/Scene.cpp index 09ba79b..e5140ac 100644 --- a/YoggieEngine/src/Scene/Scene.cpp +++ b/YoggieEngine/src/Scene/Scene.cpp @@ -31,61 +31,11 @@ namespace YoggieEngine{ void Scene::Start() { // Execute start functions in scripts etc.... - } void Scene::Update() { // Execute Update functions in scripts etc.... - - // Update transforms - - auto& transforms = m_registry.view(); - transforms.each([&](auto ent, TransformComponent& transform) { - - glm::mat4 rotationX = - glm::rotate( - glm::mat4(1.0f), - glm::radians(transform.Rotation.x), - glm::vec3(1.f, 0.f, 0.0f) - ); - glm::mat4 rotationY = - glm::rotate( - glm::mat4(1.0f), - glm::radians(transform.Rotation.y), - glm::vec3(0.f, 1.f, 0.0f) - ); - glm::mat4 rotationZ = - glm::rotate( - glm::mat4(1.0f), - transform.Rotation.z, - glm::vec3(0.f, 0.f, 1.0f) - ); - - glm::mat4 rotationMatrix = rotationY * rotationX * rotationZ; - glm::mat4 translationMatrix = glm::translate(glm::mat4(1.0f), transform.Position); - glm::mat4 ScaleMatrix = glm::scale(glm::mat4(1.0f), transform.Scale); - - Entity entity( ent, this ); - - - if (entity.HasComponent()) - { - auto& entityRelation = entity.GetComponent(); - Entity parent = entityRelation.Parent; - TransformComponent parentTransform = parent.GetComponent(); - glm::mat4 Model = translationMatrix * rotationMatrix * ScaleMatrix; - transform.LocalTransform = parentTransform.LocalTransform * Model; - } - else { - transform.LocalTransform = translationMatrix * rotationMatrix * ScaleMatrix; - - } - - }); - - - } void Scene::FixedUpdate() diff --git a/Editor/src/AssetManagement/SceneSerializer.cpp b/YoggieEngine/src/Scene/SceneSerializer.cpp similarity index 99% rename from Editor/src/AssetManagement/SceneSerializer.cpp rename to YoggieEngine/src/Scene/SceneSerializer.cpp index c0b4531..bc1e3cc 100644 --- a/Editor/src/AssetManagement/SceneSerializer.cpp +++ b/YoggieEngine/src/Scene/SceneSerializer.cpp @@ -1,3 +1,4 @@ +#include #include "SceneSerializer.h" #include "../../YoggieEngine/src/YoggieEngine.h" #include diff --git a/Editor/src/AssetManagement/SceneSerializer.h b/YoggieEngine/src/Scene/SceneSerializer.h similarity index 100% rename from Editor/src/AssetManagement/SceneSerializer.h rename to YoggieEngine/src/Scene/SceneSerializer.h diff --git a/YoggieEngine/src/Scene/UUID.h b/YoggieEngine/src/Scene/UUID.h deleted file mode 100644 index 913cc0b..0000000 --- a/YoggieEngine/src/Scene/UUID.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include - -class UUID { - -public: - static uint64_t Generate() - { - return ++last; - } - -private: - static uint64_t last ; - -}; - diff --git a/YoggieEngine/src/YoggieEngine.h b/YoggieEngine/src/YoggieEngine.h index d18cb2d..f94eedc 100644 --- a/YoggieEngine/src/YoggieEngine.h +++ b/YoggieEngine/src/YoggieEngine.h @@ -33,19 +33,16 @@ extern "C" // Main library stuff #include "Platform/Platform.h" -#include "Graphics/Primitives/Mesh.h" -#include "Graphics/Primitives/Shader.h" -#include "Graphics/Primitives/Texture.h" -#include "Graphics/Primitives/CubeMap.h" -#include "Graphics/Primitives/Camera.h" -#include "Graphics/Primitives/Material.h" +#include "Graphics/Mesh.h" +#include "Graphics/Shader.h" +#include "Graphics/Texture.h" +#include "Graphics/CubeMap.h" +#include "Graphics/Camera.h" +#include "Graphics/Material.h" #include "Graphics/Renderer.h" #include "Physics/Physics.h" -#include "EventSystem/EventEmitter.h" -#include "EventSystem/EventListener.h" - #include "Input/Keyboard.h" #include "Input/InputManager.h"