diff --git a/Editor/resources/Shaders/gbuffer.shader b/Editor/resources/Shaders/gbuffer.shader index 9d7aa722..6b0a7aa7 100644 --- a/Editor/resources/Shaders/gbuffer.shader +++ b/Editor/resources/Shaders/gbuffer.shader @@ -23,7 +23,6 @@ void main() //T = normalize(T - dot(T, N) * N); //vec3 B = cross(N, T); - vec3 T = normalize((u_Model * vec4(Tangent, 0.0f)).xyz); vec3 N = normalize((u_Model * vec4(Normal, 0.0f)).xyz); vec3 B = normalize((u_Model * vec4(Bitangent, 0.0f)).xyz); @@ -83,10 +82,17 @@ void main() // Albedo gAlbedo = vec4(m_AlbedoColor, 1.0); if (u_HasAlbedo == 1) - gAlbedo.rgb = texture(m_Albedo, UV).rgb; + { + vec4 albedoSample = texture(m_Albedo, UV); + gAlbedo.rgb = albedoSample.rgb * m_AlbedoColor.rgb; + gAlbedo.a = albedoSample.a; + + if (albedoSample.a < 0.1f) + { + discard; + } + } - gAlbedo.rgb = texture(m_Albedo, UV).rgb * m_AlbedoColor.rgb; - // Material float finalMetalness = u_MetalnessValue; if (u_HasMetalness == 1) diff --git a/Editor/src/ComponentsPanel/SpritePanel.h b/Editor/src/ComponentsPanel/SpritePanel.h new file mode 100644 index 00000000..5db42544 --- /dev/null +++ b/Editor/src/ComponentsPanel/SpritePanel.h @@ -0,0 +1,73 @@ +#pragma once +#include "ComponentPanel.h" + +#include +#include +#include +#include + + +class SpritePanel : ComponentPanel +{ +public: + SpritePanel() = default; + ~SpritePanel() = default; + + void Draw(Nuake::Entity entity) override + { + if (!entity.HasComponent()) + { + return; + } + + auto& component = entity.GetComponent(); + BeginComponentTable(SPRITE, Nuake::SpriteComponent); + { + { + ImGui::Text("Sprite"); + ImGui::TableNextColumn(); + + std::string path = component.SpritePath; + ImGui::Button(path.empty() ? "Drag image" : component.SpritePath.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Image")) + { + char* file = (char*)payload->Data; + + std::string fullPath = std::string(file, 512); + path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath)); + component.SpritePath = path; + + component.LoadSprite(); + } + ImGui::EndDragDropTarget(); + } + + ImGui::TableNextColumn(); + ComponentTableReset(component.LockYRotation, false); + } + ImGui::TableNextColumn(); + { + ImGui::Text("Billboard"); + ImGui::TableNextColumn(); + + ImGui::Checkbox("##billboard", &component.Billboard); + ImGui::TableNextColumn(); + + ComponentTableReset(component.Billboard, false); + } + ImGui::TableNextColumn(); + { + ImGui::Text("Lock Y rotation"); + ImGui::TableNextColumn(); + + ImGui::Checkbox("##lockYRotation", &component.LockYRotation); + ImGui::TableNextColumn(); + + ComponentTableReset(component.LockYRotation, false); + } + } + EndComponentTable(); + } +}; \ No newline at end of file diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index b278e5cc..a5674899 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -14,13 +14,6 @@ EditorSelectionPanel::EditorSelectionPanel() { - mTransformPanel = TransformPanel(); - mLightPanel = LightPanel(); - mScriptPanel = ScriptPanel(); - mQuakeMapPanel = QuakeMapPanel(); - mCameraPanel = CameraPanel(); - mRigidbodyPanel = RigidbodyPanel(); - mBoxColliderPanel = BoxColliderPanel(); } void EditorSelectionPanel::ResolveFile(Ref file) @@ -100,6 +93,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) mTransformPanel.Draw(entity); mLightPanel.Draw(entity); mScriptPanel.Draw(entity); + mSpritePanel.Draw(entity); mMeshPanel.Draw(entity); mQuakeMapPanel.Draw(entity); mCameraPanel.Draw(entity); @@ -129,6 +123,7 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity) MenuItemComponent("Camera", Nuake::CameraComponent) MenuItemComponent("Light", Nuake::LightComponent) MenuItemComponent("Model", Nuake::ModelComponent) + MenuItemComponent("Sprite", Nuake::SpriteComponent) ImGui::Separator(); MenuItemComponent("Character Controller", Nuake::CharacterControllerComponent) MenuItemComponent("Rigid body", Nuake::RigidBodyComponent) diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 88b2cd7b..847406ad 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -18,6 +18,8 @@ #include "../ComponentsPanel/SphereColliderPanel.h" #include "../ComponentsPanel/MeshColliderPanel.h" #include "../ComponentsPanel/CharacterControllerPanel.h" +#include "../ComponentsPanel/SpritePanel.h" + class EditorSelectionPanel { private: @@ -33,7 +35,7 @@ private: MeshColliderPanel mMeshColliderPanel; CapsuleColliderPanel mCapsuleColliderPanel; CylinderColliderPanel mCylinderColliderPanel; - + SpritePanel mSpritePanel; CharacterControllerPanel mCharacterControllerPanel; Ref currentFile; diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 2e10a976..af7ae461 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -211,28 +211,42 @@ namespace Nuake { Editor->Selection = EditorSelection(file); } + } - if (ImGui::BeginDragDropSource()) + if (ImGui::BeginDragDropSource()) { char pathBuffer[256]; std::strncpy(pathBuffer, file->GetAbsolutePath().c_str(), sizeof(pathBuffer)); std::string dragType; if (fileExtension == ".wren") + { dragType = "_Script"; + } else if (fileExtension == ".map") + { dragType = "_Map"; + } else if (fileExtension == ".obj" || fileExtension == ".mdl" || fileExtension == ".gltf" || fileExtension == ".md3" || fileExtension == ".fbx") + { dragType = "_Model"; + } else if (fileExtension == ".interface") + { dragType = "_Interface"; + } else if (fileExtension == ".prefab") + { dragType = "_Prefab"; + } + else if (fileExtension == ".png" || fileExtension == ".jpg") + { + dragType = "_Image"; + } ImGui::SetDragDropPayload(dragType.c_str(), (void*)(pathBuffer), sizeof(pathBuffer)); ImGui::Text(file->GetName().c_str()); ImGui::EndDragDropSource(); } - } const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId); if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1)) @@ -532,8 +546,6 @@ namespace Nuake ImGui::EndChild(); ImGui::SameLine(); - avail = ImGui::GetContentRegionAvail(); - std::vector> paths = std::vector>(); Ref currentParent = m_CurrentDirectory; @@ -581,12 +593,13 @@ namespace Nuake } const uint32_t numButtonAfterPathBrowser = 2; + const uint32_t searchBarSize = 6; ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_ChildBg, colors[ImGuiCol_TitleBgCollapsed]); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4)); - ImGui::BeginChild("pathBrowser", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth) - 4.0, 24)); + ImGui::BeginChild("pathBrowser", ImVec2((ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth * searchBarSize)) - 4.0, 24)); for (int i = paths.size() - 1; i > 0; i--) { if (i != paths.size()) @@ -610,13 +623,23 @@ namespace Nuake ImGui::SameLine(); ImGui::Text("/"); } - ImGui::EndChild(); ImGui::PopStyleVar(); - ImGui::PopStyleVar(); ImGui::PopStyleColor(); + + ImGui::SameLine(); + + ImGui::BeginChild("searchBar", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth), 24)); + char buffer[256]; + memset(buffer, 0, sizeof(buffer)); + std::strncpy(buffer, m_searchKeyWord.c_str(), sizeof(buffer)); + if (ImGui::InputTextEx("##Search", "Asset search & filter ..", buffer, sizeof(buffer), ImVec2(ImGui::GetContentRegionAvail().x, 24), ImGuiInputTextFlags_EscapeClearsAll)) + { + m_searchKeyWord = std::string(buffer); + } + ImGui::EndChild(); ImGui::SameLine(); @@ -633,8 +656,9 @@ namespace Nuake } ImGui::PopStyleColor(); // Button color + + ImGui::SameLine(); } - ImGui::EndChild(); ImDrawList* drawList = ImGui::GetWindowDrawList(); @@ -668,13 +692,16 @@ namespace Nuake { for (Ref& d : m_CurrentDirectory->Directories) { - if (i + 1 % amount != 0) - ImGui::TableNextColumn(); - else - ImGui::TableNextRow(); + if(String::Sanitize(d->name).find(String::Sanitize(m_searchKeyWord)) != std::string::npos) + { + if (i + 1 % amount != 0) + ImGui::TableNextColumn(); + else + ImGui::TableNextRow(); - DrawDirectory(d, i); - i++; + DrawDirectory(d, i); + i++; + } } } @@ -682,13 +709,16 @@ namespace Nuake { for (auto f : m_CurrentDirectory->Files) { - if (i - 1 % amount != 0 || i == 1) - ImGui::TableNextColumn(); - else - ImGui::TableNextRow(); + if(String::Sanitize(f->GetName()).find(String::Sanitize(m_searchKeyWord)) != std::string::npos) + { + if (i - 1 % amount != 0 || i == 1) + ImGui::TableNextColumn(); + else + ImGui::TableNextRow(); - DrawFile(f, i); - i++; + DrawFile(f, i); + i++; + } } } diff --git a/Editor/src/Windows/FileSystemUI.h b/Editor/src/Windows/FileSystemUI.h index 9090aa85..514748fa 100644 --- a/Editor/src/Windows/FileSystemUI.h +++ b/Editor/src/Windows/FileSystemUI.h @@ -12,6 +12,7 @@ namespace Nuake { public: static Ref m_CurrentDirectory; bool m_hasClickedOnFile; + std::string m_searchKeyWord; FileSystemUI(EditorInterface* editor) { diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index c2ed7bac..0298be94 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -70,19 +70,15 @@ namespace Nuake newDir->Parent = directory; ScanDirectory(newDir); - directory->Directories.push_back(newDir); } else if (entry.is_regular_file()) { - std::string absolutePath = entry.path().string(); - std::string name = entry.path().filename().string(); - std::string extension = entry.path().extension().string(); + std::filesystem::path currentPath = entry.path(); + std::string absolutePath = currentPath.string(); + std::string name = currentPath.filename().string(); + std::string extension = currentPath.extension().string(); Ref newFile = CreateRef(directory, absolutePath, name, extension); - //newFile->Type = entry.path().extension().string(); - //newFile->name = entry.path().filename().string(); - //newFile->Parent = directory; - //newFile->fullPath = entry.path().string(); directory->Files.push_back(newFile); } } diff --git a/Nuake/src/Core/String.cpp b/Nuake/src/Core/String.cpp index 7c4ccc5a..db6be8a3 100644 --- a/Nuake/src/Core/String.cpp +++ b/Nuake/src/Core/String.cpp @@ -1,5 +1,6 @@ #include "String.h" #include +#include #include namespace Nuake @@ -36,6 +37,19 @@ namespace Nuake return result; } + std::string String::Sanitize(const std::string& keyword) + { + std::string sanitizedKeyword = keyword; + + // Remove spaces, underscores, and hyphens using regex + sanitizedKeyword = std::regex_replace(sanitizedKeyword, std::regex("[ _-]+"), ""); + + // Convert to lowercase + std::transform(sanitizedKeyword.begin(), sanitizedKeyword.end(), sanitizedKeyword.begin(), ::tolower); + + return sanitizedKeyword; + } + std::vector String::Split(const std::string& string, char delimiter) { std::vector result; diff --git a/Nuake/src/Core/String.h b/Nuake/src/Core/String.h index be3f6aa7..c3b55e17 100644 --- a/Nuake/src/Core/String.h +++ b/Nuake/src/Core/String.h @@ -15,6 +15,7 @@ namespace Nuake static bool EndsWith(const std::string& string, const std::string& end); static bool IsDigit(const char& character); static std::string RemoveWhiteSpace(const std::string& string); + static std::string Sanitize(const std::string& keyword); static std::vector Split(const std::string& string, char delimiter); static float ToFloat(const std::string& string); diff --git a/Nuake/src/Rendering/Renderer.cpp b/Nuake/src/Rendering/Renderer.cpp index 25f86f4f..92c61628 100644 --- a/Nuake/src/Rendering/Renderer.cpp +++ b/Nuake/src/Rendering/Renderer.cpp @@ -22,6 +22,7 @@ namespace Nuake unsigned int depthFBO; Ref Renderer::CubeMesh; + Ref Renderer::QuadMesh; Shader* Renderer::m_Shader; Shader* Renderer::m_SkyboxShader; @@ -62,13 +63,14 @@ namespace Nuake 4, 5, 0, 0, 5, 1 }; - float QuadVertices[] = { - -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, - -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, - -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f + std::vector QuadVertices + { + { Vector3(-1.0f, -1.0f, 0.0f), Vector2(0, 0), Vector3(0, 0, -1) }, + { Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) }, + { Vector3(-1.0f, 1.0f, 0.0f), Vector2(0.0f, 1.0f), Vector3(0, 0, -1) }, + { Vector3(1.0f, -1.0f, 0.0f), Vector2(1.0f, 0.0f), Vector3(0, 0, -1) }, + { Vector3(-1.0f, -1.0f, 0.0f), Vector2(0.0f, 0.0f), Vector3(0, 0, -1) }, + { Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) } }; @@ -84,24 +86,10 @@ namespace Nuake CubeMesh = CreateRef(); CubeMesh->AddSurface(CubeVertices, CubeIndices); CubeMesh->SetMaterial(material); - // Cube buffer - //CubeVertexArray = new VertexArray(); - //CubeVertexArray->Bind(); - //CubeVertexBuffer = new VertexBuffer(CubeVertices, sizeof(CubeVertices)); - // - VertexBufferLayout vblayout = VertexBufferLayout(); - vblayout.Push(3); - //CubeVertexArray->AddBuffer(*CubeVertexBuffer, vblayout); - // Quad buffer - QuadVertexArray = new VertexArray(); - QuadVertexArray->Bind(); - QuadVertexBuffer = new VertexBuffer(QuadVertices, sizeof(QuadVertices)); - - vblayout = VertexBufferLayout(); - vblayout.Push(3); - vblayout.Push(2); - QuadVertexArray->AddBuffer(*QuadVertexBuffer, vblayout); + QuadMesh = CreateRef(); + QuadMesh->AddSurface(QuadVertices, { 0, 1, 2, 3, 4, 5 }); + QuadMesh->SetMaterial(material); } void Renderer::LoadShaders() @@ -221,7 +209,7 @@ namespace Nuake m_DebugShader->SetUniformMat4f("u_Model", transform.GetGlobalTransform()); m_DebugShader->SetUniform4f("u_Color", color.r, color.g, color.b, color.a); - CubeVertexArray->Bind(); + CubeMesh->Bind(); RenderCommand::DrawArrays(0, 36); } @@ -233,7 +221,7 @@ namespace Nuake void Renderer::DrawQuad(Matrix4 transform) { - QuadVertexArray->Bind(); + QuadMesh->Bind(); RenderCommand::DrawArrays(0, 6); } } diff --git a/Nuake/src/Rendering/Renderer.h b/Nuake/src/Rendering/Renderer.h index 847e3b86..76c86b28 100644 --- a/Nuake/src/Rendering/Renderer.h +++ b/Nuake/src/Rendering/Renderer.h @@ -33,6 +33,7 @@ namespace Nuake { private: static RenderList m_RenderList; + public: static VertexArray* QuadVertexArray; static VertexBuffer* QuadVertexBuffer; @@ -51,6 +52,7 @@ namespace Nuake static Ref m_LightsUniformBuffer; static Ref CubeMesh; + static Ref QuadMesh; static void Init(); static void LoadShaders(); @@ -65,7 +67,6 @@ namespace Nuake // Lights static std::vector m_Lights; - static void RegisterLight(TransformComponent transform, LightComponent light); static void RegisterDeferredLight(TransformComponent transform, LightComponent light); // Debug diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index e1c49f86..db19889a 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -1,7 +1,9 @@ #include "SceneRenderer.h" #include "src/Rendering/Shaders/ShaderManager.h" -#include +#include "src/Scene/Components/BSPBrushComponent.h" +#include "src/Scene/Components/SpriteComponent.h" + #include namespace Nuake @@ -240,16 +242,18 @@ namespace Nuake mGBuffer->Bind(); mGBuffer->Clear(); { + // Init RenderCommand::Enable(RendererEnum::FACE_CULL); Shader* gBufferShader = ShaderManager::GetShader("resources/Shaders/gbuffer.shader"); gBufferShader->Bind(); gBufferShader->SetUniformMat4f("u_Projection", mProjection); gBufferShader->SetUniformMat4f("u_View", mView); - auto view = scene.m_Registry.view(); + // Models + auto view = scene.m_Registry.view(); for (auto e : view) { - auto [transform, mesh, parent, visibility] = view.get(e); + auto [transform, mesh, visibility] = view.get(e); if (mesh.ModelResource && visibility.Visible) { @@ -264,10 +268,11 @@ namespace Nuake RenderCommand::Disable(RendererEnum::FACE_CULL); Renderer::Flush(gBufferShader, false); - auto quakeView = scene.m_Registry.view(); + // Quake BSPs + auto quakeView = scene.m_Registry.view(); for (auto e : quakeView) { - auto [transform, model, parent, visibility] = quakeView.get(e); + auto [transform, model, visibility] = quakeView.get(e); if (model.IsTransparent || !visibility.Visible) continue; @@ -278,6 +283,39 @@ namespace Nuake } } Renderer::Flush(gBufferShader, false); + + // Sprites + auto spriteView = scene.m_Registry.view(); + for (auto e : spriteView) + { + auto [transform, sprite, visibility] = spriteView.get(e); + + if (!visibility.Visible || !sprite.SpriteMesh) + continue; + + auto& finalQuadTransform = transform.GetGlobalTransform(); + if (sprite.Billboard) + { + finalQuadTransform = glm::inverse(mView); + + if (sprite.LockYRotation) + { + // This locks the pitch rotation on the billboard, useful for trees, lamps, etc. + finalQuadTransform[1] = Vector4(0, 1, 0, 0); + finalQuadTransform[2] = Vector4(finalQuadTransform[2][0], 0, finalQuadTransform[2][2], 0); + finalQuadTransform = finalQuadTransform; + } + + // Translation + finalQuadTransform[3] = Vector4(transform.GetGlobalPosition(), 1.0f); + + // Scale + finalQuadTransform = glm::scale(finalQuadTransform, transform.GetGlobalScale()); + } + + Renderer::SubmitMesh(sprite.SpriteMesh, finalQuadTransform, (uint32_t)e); + } + Renderer::Flush(gBufferShader, false); } } diff --git a/Nuake/src/Rendering/Shaders/Shader.cpp b/Nuake/src/Rendering/Shaders/Shader.cpp index 895eb8c5..17a7fa2d 100644 --- a/Nuake/src/Rendering/Shaders/Shader.cpp +++ b/Nuake/src/Rendering/Shaders/Shader.cpp @@ -26,6 +26,8 @@ namespace Nuake Source = newSource; ProgramId = newProgramId; + + return true; } // Bind the shader diff --git a/Nuake/src/Rendering/Textures/MaterialManager.h b/Nuake/src/Rendering/Textures/MaterialManager.h index 525493fa..1495512d 100644 --- a/Nuake/src/Rendering/Textures/MaterialManager.h +++ b/Nuake/src/Rendering/Textures/MaterialManager.h @@ -29,7 +29,6 @@ namespace Nuake void LoadMaterials(); - void RegisterMaterial(Ref material); Ref LoadMaterial(std::string path); diff --git a/Nuake/src/Scene/Components/SpriteComponent.cpp b/Nuake/src/Scene/Components/SpriteComponent.cpp new file mode 100644 index 00000000..db0fdad0 --- /dev/null +++ b/Nuake/src/Scene/Components/SpriteComponent.cpp @@ -0,0 +1,70 @@ +#include "SpriteComponent.h" + +#include "src/Core/FileSystem.h" +#include "src/Rendering/Textures/TextureManager.h" +#include "src/Rendering/Textures/MaterialManager.h" +#include "src/Rendering/Vertex.h" + +namespace Nuake +{ + SpriteComponent::SpriteComponent() : + Billboard(false), + LockYRotation(false), + SpritePath("") + { + + } + + bool SpriteComponent::LoadSprite() + { + std::vector quadVertices = + { + { Vector3(-1.0f, -1.0f, 0.0f), Vector2(0, 0), Vector3(0, 0, -1) }, + { Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) }, + { Vector3(-1.0f, 1.0f, 0.0f), Vector2(0.0f, 1.0f), Vector3(0, 0, -1) }, + { Vector3(1.0f, -1.0f, 0.0f), Vector2(1.0f, 0.0f), Vector3(0, 0, -1) }, + { Vector3(-1.0f, -1.0f, 0.0f), Vector2(0.0f, 0.0f), Vector3(0, 0, -1) }, + { Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) } + }; + + SpriteMesh = CreateRef(); + SpriteMesh->AddSurface(quadVertices, { 0, 1, 2, 3, 4, 5 }); + + auto& material = MaterialManager::Get()->GetMaterial(FileSystem::Root + SpritePath); + SpriteMesh->SetMaterial(material); + + return true; + } + + json SpriteComponent::Serialize() + { + BEGIN_SERIALIZE(); + SERIALIZE_VAL(Billboard) + SERIALIZE_VAL(LockYRotation) + SERIALIZE_VAL(SpritePath) + END_SERIALIZE(); + } + + bool SpriteComponent::Deserialize(const std::string& str) + { + BEGIN_DESERIALIZE(); + + if (j.contains("Billboard")) + { + Billboard = j["Billboard"]; + } + + if (j.contains("LockYRotation")) + { + LockYRotation = j["LockYRotation"]; + } + + if (j.contains("SpritePath")) + { + SpritePath = j["SpritePath"]; + LoadSprite(); + } + + return true; + } +} \ No newline at end of file diff --git a/Nuake/src/Scene/Components/SpriteComponent.h b/Nuake/src/Scene/Components/SpriteComponent.h new file mode 100644 index 00000000..465abd3e --- /dev/null +++ b/Nuake/src/Scene/Components/SpriteComponent.h @@ -0,0 +1,25 @@ +#pragma once +#include "src/Core/Core.h" +#include "src/Resource/Serializable.h" +#include "src/Rendering/Textures/Texture.h" +#include "src/Rendering/Mesh/Mesh.h" + +namespace Nuake +{ + class SpriteComponent + { + public: + bool Billboard; + bool LockYRotation; + std::string SpritePath; + Ref SpriteMesh; + + SpriteComponent(); + + public: + bool LoadSprite(); + + json Serialize(); + bool Deserialize(const std::string& str); + }; +} diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index 30c9583a..87dbca05 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -1,19 +1,21 @@ -#include "../Components/ParentComponent.h" #include "Entity.h" -#include "../Components/NameComponent.h" -#include "../Components/TransformComponent.h" -#include "../Components/CameraComponent.h" -#include "../Components/QuakeMap.h" -#include "../Components/LightComponent.h" -#include "../Components/QuakeMap.h" -#include "../Components/WrenScriptComponent.h" -#include "../Components/CharacterControllerComponent.h" -#include "../Components/RigidbodyComponent.h" -#include "src/Scene/Components/BSPBrushComponent.h" +#include "src/Scene/Components/ParentComponent.h" +#include "src/Scene/Components/NameComponent.h" +#include "src/Scene/Components/TransformComponent.h" +#include "src/Scene/Components/CameraComponent.h" +#include "src/Scene/Components/QuakeMap.h" +#include "src/Scene/Components/LightComponent.h" +#include "src/Scene/Components/QuakeMap.h" +#include "src/Scene/Components/WrenScriptComponent.h" +#include "src/Scene/Components/CharacterControllerComponent.h" +#include "src/Scene/Components/RigidbodyComponent.h" +#include "src/Scene/Components/BSPBrushComponent.h" #include "src/Scene/Components/Components.h" -#include +#include "src/Scene/Components/BoxCollider.h" #include "src/Scene/Components/CapsuleColliderComponent.h" +#include "src/Scene/Components/SpriteComponent.h" + namespace Nuake { @@ -37,6 +39,8 @@ namespace Nuake SERIALIZE_OBJECT_REF_LBL("VisibilityComponent", GetComponent()) if (HasComponent()) SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent()) + if (HasComponent()) + SERIALIZE_OBJECT_REF_LBL("SpriteComponent", GetComponent()) if (HasComponent()) SERIALIZE_OBJECT_REF_LBL("QuakeMapComponent", GetComponent()) if (HasComponent()) @@ -78,6 +82,7 @@ namespace Nuake } DESERIALIZE_COMPONENT(NameComponent) DESERIALIZE_COMPONENT(ParentComponent) + DESERIALIZE_COMPONENT(SpriteComponent) DESERIALIZE_COMPONENT(CameraComponent) DESERIALIZE_COMPONENT(QuakeMapComponent) DESERIALIZE_COMPONENT(LightComponent) diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index abfcf8a3..5bc39d31 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -67,7 +67,7 @@ namespace Nuake SetWindowIcon("resources/Images/nuake-logo.png"); glfwMakeContextCurrent(m_Window); - //SetVSync(true) + SetVSync(true); Logger::Log("Driver detected " + std::string(((char*)glGetString(GL_VERSION))), "renderer"); @@ -248,7 +248,7 @@ namespace Nuake void Window::SetVSync(bool enabled) { - glfwSwapInterval(enabled ? 0 : 1); + glfwSwapInterval(enabled ? 1 : 0); } void Window::SetDecorated(bool enabled)