diff --git a/Editor/resources/Scenes/test.scene b/Editor/resources/Scenes/test.scene index a3e44599..3edfafd6 100644 --- a/Editor/resources/Scenes/test.scene +++ b/Editor/resources/Scenes/test.scene @@ -91,7 +91,7 @@ }, "QuakeMapComponent": { "HasCollisions": true, - "Path": "C:\\Dev\\Nuake\\Editor\\resources\\Maps\\debug.map" + "Path": "Maps/debug.map" }, "TransformComponent": { "Rotation": { diff --git a/Editor/src/EditorInterface.cpp b/Editor/src/EditorInterface.cpp index eae772eb..f7067f18 100644 --- a/Editor/src/EditorInterface.cpp +++ b/Editor/src/EditorInterface.cpp @@ -132,7 +132,9 @@ void EditorInterface::DrawViewport() ImGui::End(); */ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - if(ImGui::Begin("Viewport")) + + std::string name = ICON_FA_GAMEPAD + std::string(" Scene"); + if(ImGui::Begin(name.c_str())) { ImGui::PopStyleVar(); @@ -291,7 +293,8 @@ void EditorInterface::DrawSceneTree() if (!scene) return; - if (ImGui::Begin("Environnement")) + + if (ImGui::Begin(" Environnement")) { auto env = Engine::GetCurrentScene()->GetEnvironment(); if (ImGui::CollapsingHeader("Procedural Sky")) @@ -314,7 +317,9 @@ void EditorInterface::DrawSceneTree() } ImGui::End(); - if(ImGui::Begin("Scene")) + + std::string title = ICON_FA_TREE + std::string(" Hierarchy"); + if(ImGui::Begin(title.c_str())) { // Buttons to add and remove entity. ImGui::BeginChild("Buttons", ImVec2(300, 20), false); @@ -333,10 +338,10 @@ void EditorInterface::DrawSceneTree() // Unselect delted entity. m_SelectedEntity = scene->GetAllEntities().at(0); } - ImGui::EndChild(); } + ImGui::Separator(); // Draw a tree of entities. for (Entity e : scene->GetAllEntities()) { @@ -482,6 +487,16 @@ void EditorInterface::DrawEntityPropreties() if (ImGui::InputText("##ScriptPath", pathBuffer, sizeof(pathBuffer))) path = FileSystem::AbsoluteToRelative(std::string(pathBuffer)); + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script")) + { + char* file = (char*)payload->Data; + std::string fullPath = std::string(file, 256); + path = FileSystem::AbsoluteToRelative(fullPath); + } + ImGui::EndDragDropTarget(); + } ImGui::SameLine(); @@ -600,12 +615,26 @@ void EditorInterface::DrawEntityPropreties() { path = std::string(pathBuffer); } + + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map")) + { + char* file = (char*)payload->Data; + std::string fullPath = std::string(file, 256); + path = FileSystem::AbsoluteToRelative(fullPath); + } + ImGui::EndDragDropTarget(); + } + ImGui::SameLine(); if (ImGui::Button("Browse")) { path = FileDialog::OpenFile(".map"); } + + component.Path = path; ImGui::Checkbox("Build collisions?", &component.HasCollisions); @@ -800,14 +829,57 @@ void EditorInterface::DrawDirectoryExplorer() ImGui::End(); } +bool LogErrors = true; +bool LogWarnings = true; +bool LogDebug = true; void EditorInterface::DrawLogger() { if (ImGui::Begin("Logger")) { - for (auto l : Logger::GetLogs()) - { - ImGui::TextWrapped(l.c_str()); - } + ImGui::Checkbox("Errors", &LogErrors); + ImGui::SameLine(); + ImGui::Checkbox("Warning", &LogWarnings); + ImGui::SameLine(); + ImGui::Checkbox("Debug", &LogDebug); + + //ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + //if (ImGui::BeginChild("Log window", ImGui::GetContentRegionAvail(), false)) + //{ + //ImGui::PopStyleVar(); + ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable; + + if (ImGui::BeginTable("LogTable", 3, flags)) + { + ImGui::TableSetupScrollFreeze(0, 1); + ImGui::TableSetupColumn("Severity"); + ImGui::TableSetupColumn("Time"); + ImGui::TableSetupColumn("Message"); + ImGui::TableHeadersRow(); + ImGui::TableNextColumn(); + for (auto& l : Logger::GetLogs()) + { + if (l.type == LOG_TYPE::VERBOSE && !LogDebug) + continue; + if (l.type == LOG_TYPE::WARNING && !LogWarnings) + continue; + if (l.type == LOG_TYPE::CRITICAL && !LogErrors) + continue; + ImGui::Text("-"); + ImGui::TableNextColumn(); + ImGui::Text(l.time.c_str()); + ImGui::TableNextColumn(); + ImGui::TextWrapped(l.message.c_str()); + + ImGui::TableNextColumn(); + } + + ImGui::EndTable(); + } + + + //ImGui::EndChild(); + //} + } ImGui::End(); @@ -1010,19 +1082,20 @@ void NewProject() void OpenProject() { // Parse the project and load it. - std::string projectPath = "C:/Dev/Nuake/Editor/resources/test.project";//FileDialog::OpenFile(".project"); + std::string projectPath = FileDialog::OpenFile(".project"); FileSystem::SetRootDirectory(projectPath + "/../"); Ref project = Project::New(); if (!project->Deserialize(FileSystem::ReadFile(projectPath, true))) { - Logger::Log("Error loading project: " + projectPath); + Logger::Log("Error loading project: " + projectPath, CRITICAL); return; } project->FullPath = projectPath; Engine::LoadProject(project); + // Create new interface named test. //userInterface = UI::UserInterface::New("test"); @@ -1038,7 +1111,7 @@ void OpenScene() Ref scene = Scene::New(); if (!scene->Deserialize(FileSystem::ReadFile(projectPath, true))) { - Logger::Log("Error failed loading scene: " + projectPath); + Logger::Log("Error failed loading scene: " + projectPath, CRITICAL); return; } @@ -1066,8 +1139,11 @@ void EditorInterface::Draw() NewProject(); ImGui::SameLine(); - if (ImGui::Button("Open a project")) + if (ImGui::Button("Open a project")) { OpenProject(); + filesystem.m_CurrentDirectory = FileSystem::RootDirectory; + } + ImGui::EndPopup(); } diff --git a/Editor/src/FileSystemUI.cpp b/Editor/src/FileSystemUI.cpp index dde7f83a..f3ff52e1 100644 --- a/Editor/src/FileSystemUI.cpp +++ b/Editor/src/FileSystemUI.cpp @@ -1,44 +1,17 @@ #include "FileSystemUI.h" + #include + +#include #include #include "src/Scene/Components/ParentComponent.h" #include #include #include "EditorInterface.h" - // TODO: add filetree in same panel void FileSystemUI::Draw() { - Ref rootDirectory = FileSystem::GetFileTree(); - if (!rootDirectory) - return; - if (ImGui::Begin("Tree browser")) - { - if (ImGui::BeginPopupContextItem("item context menu")) - { - if (ImGui::Selectable("Set to zero")); - if (ImGui::Selectable("Set to PI")); - ImGui::SetNextItemWidth(-1); - ImGui::EndPopup(); - } - ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth; - bool is_selected = m_CurrentDirectory == FileSystem::RootDirectory; - if (is_selected) - base_flags |= ImGuiTreeNodeFlags_Selected; - std::string icon = ICON_FA_FOLDER; - - bool open = ImGui::TreeNodeEx((icon + " " + rootDirectory->name).c_str(), base_flags); - if (ImGui::IsItemClicked()) - { - m_CurrentDirectory = FileSystem::RootDirectory; - } - if (open) - { - EditorInterfaceDrawFiletree(rootDirectory); - ImGui::TreePop(); - } - } - ImGui::End(); + } void FileSystemUI::DrawDirectoryContent() @@ -54,7 +27,7 @@ void FileSystemUI::EditorInterfaceDrawFiletree(Ref dir) { for (auto d : dir->Directories) { - ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth; + ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth; bool is_selected = m_CurrentDirectory == d; if (is_selected) base_flags |= ImGuiTreeNodeFlags_Selected; @@ -135,16 +108,27 @@ void FileSystemUI::DrawFile(Ref file) icon = ICON_FA_BROOM; if (file->Type == ".ogg" || file->Type == ".mp3" || file->Type == ".wav" || file->Type == ".flac") icon = ICON_FA_FILE_AUDIO; - if (file->Type == ".cpp" || file->Type == ".h" || file->Type == ".cs" || file->Type == ".py" || file->Type == ".lua") + if (file->Type == ".wren") icon = ICON_FA_FILE_CODE; - if (ImGui::Button(icon, ImVec2(100, 100))) + + std::string fullName = icon + std::string("##") + file->fullPath; + if (ImGui::Button(fullName.c_str(), ImVec2(100, 100))) { - if (ImGui::BeginPopupContextItem("item context menu")) - { - if (ImGui::Selectable("Set to zero")); - if (ImGui::Selectable("Set to PI")); - ImGui::EndPopup(); - } + + } + + if (ImGui::BeginDragDropSource()) + { + char pathBuffer[256]; + std::strncpy(pathBuffer, file->fullPath.c_str(), sizeof(pathBuffer)); + std::string dragType; + if (file->Type == ".wren") + dragType = "_Script"; + else if (file->Type == ".map") + dragType = "_Map"; + ImGui::SetDragDropPayload(dragType.c_str(), (void*)(pathBuffer), sizeof(pathBuffer)); + ImGui::Text(file->name.c_str()); + ImGui::EndDragDropSource(); } } ImGui::Text(file->name.c_str()); @@ -152,110 +136,205 @@ void FileSystemUI::DrawFile(Ref file) } +bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f) +{ + using namespace ImGui; + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiID id = window->GetID("##Splitter"); + ImRect bb; + bb.Min = window->DC.CursorPos + (split_vertically ? ImVec2(*size1, 0.0f) : ImVec2(0.0f, *size1)); + bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f); + return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 0.0f); +} +float h = 200; +static float sz1 = 300; +static float sz2 = 300; void FileSystemUI::DrawDirectoryExplorer() { if (ImGui::Begin("File browser")) { - // Wrapping. - int width = ImGui::GetWindowWidth(); - ImVec2 buttonSize = ImVec2(100, 100); - int amount = (width / 100); // -2 because button overflow width + ... button. - int i = 1; // current amount of item per row. - if (ImGui::BeginTable("ssss", amount)) + Ref rootDirectory = FileSystem::GetFileTree(); + if (!rootDirectory) + return; + + ImVec2 avail = ImGui::GetContentRegionAvail(); + Splitter(true, 4.0f, &sz1, &sz2, 100, 8, avail.y); + + if (ImGui::BeginChild("Tree browser", ImVec2(sz1, avail.y))) { - // Button to go up a level. - if (m_CurrentDirectory != FileSystem::RootDirectory) - { - ImGui::TableNextColumn(); - if (ImGui::Button("..", ImVec2(100, 100))) - m_CurrentDirectory = m_CurrentDirectory->Parent; - ImGui::TableNextColumn(); - // Increment item per row tracker. - i++; - } - - // Exit if no current directory. - if (!m_CurrentDirectory) { - ImGui::EndTable(); - ImGui::End(); - return; - } - - if (m_CurrentDirectory && m_CurrentDirectory->Directories.size() > 0) - { - for (auto d : m_CurrentDirectory->Directories) - { - DrawDirectory(d); - if (i - 1 % amount != 0) - ImGui::TableNextColumn(); - else - ImGui::TableNextRow(); - i++; - } - } - if (m_CurrentDirectory && m_CurrentDirectory->Files.size() > 0) - { - for (auto f : m_CurrentDirectory->Files) - { - DrawFile(f); - if (i - 1 % amount != 0) - ImGui::TableNextColumn(); - else - ImGui::TableNextRow(); - i++; - } - } if (ImGui::BeginPopupContextItem("item context menu")) { - float value; - if (ImGui::Selectable("Set to zero")) value = 0.0f; - if (ImGui::Selectable("Set to PI")) value = 3.1415f; + if (ImGui::Selectable("Set to zero")); + if (ImGui::Selectable("Set to PI")); ImGui::SetNextItemWidth(-1); - ImGui::DragFloat("##Value", &value, 0.1f, 0.0f, 0.0f); ImGui::EndPopup(); } - if (ImGui::BeginPopupContextWindow()) - { - if (ImGui::Button("New Wren script")) - { - ImGui::OpenPopup("CreateNewFile"); - - } - if (ImGui::MenuItem("New interface script")) - { - } - if (ImGui::MenuItem("New Scene")) - { - } - if (ImGui::MenuItem("New folder")) - { - } - if (ImGui::MenuItem("New interface")) - { - } - if (ImGui::MenuItem("New stylesheet")) - { - } - if (ImGui::BeginPopup("CreateNewFile")) - { - static char name[32] = "Label1"; - char buf[64]; - sprintf(buf, "Button: %s###Button", name); // ### operator override ID ignoring the preceding label + ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth; - ImGui::Text("Edit name:"); - ImGui::InputText("##edit", name, IM_ARRAYSIZE(name)); - if (ImGui::Button("Close")) - ImGui::CloseCurrentPopup(); - if(ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter))) - ImGui::CloseCurrentPopup(); - ImGui::EndPopup(); - } - ImGui::EndPopup(); + bool is_selected = m_CurrentDirectory == FileSystem::RootDirectory; + if (is_selected) + base_flags |= ImGuiTreeNodeFlags_Selected | ImGuiTreeNodeFlags_DefaultOpen; + std::string icon = ICON_FA_FOLDER; + + bool open = ImGui::TreeNodeEx((icon + " " + rootDirectory->name).c_str(), base_flags); + if (ImGui::IsItemClicked()) + { + m_CurrentDirectory = FileSystem::RootDirectory; + } + if (open) + { + EditorInterfaceDrawFiletree(rootDirectory); + ImGui::TreePop(); } - - ImGui::EndTable(); } + ImGui::EndChild(); + ImGui::SameLine(); + + avail = ImGui::GetContentRegionAvail(); + + std::vector> paths = std::vector>(); + + Ref currentParent = m_CurrentDirectory; + paths.push_back(m_CurrentDirectory); + while (currentParent != nullptr) { + paths.push_back(currentParent); + currentParent = currentParent->Parent; + } + + + avail = ImGui::GetContentRegionAvail(); + if (ImGui::BeginChild("Wrapper", avail)) + { + avail.y = 30; + if (ImGui::BeginChild("ariane", avail)) + { + for (int i = paths.size() - 1; i > 0; i--) { + if (i != paths.size()) + ImGui::SameLine(); + if (ImGui::Button(paths[i]->name.c_str())) { + m_CurrentDirectory = paths[i]; + } + + ImGui::SameLine(); + ImGui::Text("/"); + } + + ImGui::EndChild(); + } + + avail = ImGui::GetContentRegionAvail(); + + if (ImGui::BeginChild("Content", avail)) + { + // Wrapping. + int width = ImGui::GetWindowWidth() * 0.8f; + ImVec2 buttonSize = ImVec2(80, 80); + int amount = (width / 100); // -2 because button overflow width + ... button. + int i = 1; // current amount of item per row. + if (ImGui::BeginTable("ssss", amount)) + { + // Button to go up a level. + if (m_CurrentDirectory != FileSystem::RootDirectory) + { + ImGui::TableNextColumn(); + if (ImGui::Button("..", ImVec2(100, 100))) + m_CurrentDirectory = m_CurrentDirectory->Parent; + ImGui::TableNextColumn(); + // Increment item per row tracker. + i++; + } + + // Exit if no current directory. + if (!m_CurrentDirectory) { + ImGui::EndTable(); + ImGui::End(); + return; + } + + if (m_CurrentDirectory && m_CurrentDirectory->Directories.size() > 0) + { + for (auto d : m_CurrentDirectory->Directories) + { + DrawDirectory(d); + if (i - 1 % amount != 0) + ImGui::TableNextColumn(); + else + ImGui::TableNextRow(); + i++; + } + } + if (m_CurrentDirectory && m_CurrentDirectory->Files.size() > 0) + { + for (auto f : m_CurrentDirectory->Files) + { + DrawFile(f); + if (i - 1 % amount != 0) + ImGui::TableNextColumn(); + else + ImGui::TableNextRow(); + i++; + } + } + if (ImGui::BeginPopupContextItem("item context menu")) + { + float value; + if (ImGui::Selectable("Set to zero")) value = 0.0f; + if (ImGui::Selectable("Set to PI")) value = 3.1415f; + ImGui::SetNextItemWidth(-1); + ImGui::DragFloat("##Value", &value, 0.1f, 0.0f, 0.0f); + ImGui::EndPopup(); + } + if (ImGui::BeginPopupContextWindow()) + { + if (ImGui::Button("New Wren script")) + { + ImGui::OpenPopup("CreateNewFile"); + + } + if (ImGui::MenuItem("New interface script")) + { + } + if (ImGui::MenuItem("New Scene")) + { + } + if (ImGui::MenuItem("New folder")) + { + } + if (ImGui::MenuItem("New interface")) + { + } + if (ImGui::MenuItem("New stylesheet")) + { + } + if (ImGui::BeginPopup("CreateNewFile")) + { + static char name[32] = "Label1"; + char buf[64]; + sprintf(buf, "Button: %s###Button", name); // ### operator override ID ignoring the preceding label + + ImGui::Text("Edit name:"); + ImGui::InputText("##edit", name, IM_ARRAYSIZE(name)); + if (ImGui::Button("Close")) + ImGui::CloseCurrentPopup(); + if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter))) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + } + ImGui::EndPopup(); + } + + + ImGui::EndTable(); + } + + + } + ImGui::EndChild(); + + } + ImGui::EndChild(); } diff --git a/Editor/src/FileSystemUI.h b/Editor/src/FileSystemUI.h index 472ada0f..bacaa188 100644 --- a/Editor/src/FileSystemUI.h +++ b/Editor/src/FileSystemUI.h @@ -6,9 +6,13 @@ class FileSystemUI { private: - Ref m_CurrentDirectory; + public: + Ref m_CurrentDirectory; + FileSystemUI() { + m_CurrentDirectory = FileSystem::RootDirectory; + } void Draw(); void DrawDirectoryContent(); void DrawFiletree(); diff --git a/Nuake/src/Core/Logger.cpp b/Nuake/src/Core/Logger.cpp index a86e2f97..819aab3a 100644 --- a/Nuake/src/Core/Logger.cpp +++ b/Nuake/src/Core/Logger.cpp @@ -4,19 +4,30 @@ #include #include -std::vector Logger::logs = std::vector(); +std::vector Logger::m_Logs = std::vector(); -void Logger::Log(std::string log) +void Logger::Log(std::string log, LOG_TYPE type) { char buff[100]; time_t now = time(0); strftime(buff, 100, "%Y-%m-%d %H:%M:%S.000", localtime(&now)); - std::string msg = "["+ std::string(buff) + "]" + std::string(" - ") + log; + + LogEntry newLog = { + type, + buff, + log + }; + + std::string msg = "[" + std::string(buff) + "]" + std::string(" - ") + log; printf((msg + "\n").c_str()); - logs.push_back(msg); + + if (m_Logs.size() >= MAX_LOG) + m_Logs.erase(m_Logs.begin()); + + m_Logs.push_back(newLog); } -std::vector Logger::GetLogs() +std::vector Logger::GetLogs() { - return logs; + return m_Logs; } \ No newline at end of file diff --git a/Nuake/src/Core/Logger.h b/Nuake/src/Core/Logger.h index 94e19241..9be0d17d 100644 --- a/Nuake/src/Core/Logger.h +++ b/Nuake/src/Core/Logger.h @@ -9,7 +9,7 @@ enum LOG_TYPE CRITICAL }; -struct Log +struct LogEntry { LOG_TYPE type; std::string time; @@ -18,10 +18,9 @@ struct Log class Logger { - const int MAX_LOG = 64; - static std::vector logs; - static std::vector m_Logs; // TODO: Use log struct. + static const int MAX_LOG = 64; + static std::vector m_Logs; // TODO: Use log struct. public: - static void Log(std::string log); - static std::vector GetLogs(); + static void Log(std::string log, LOG_TYPE type = VERBOSE); + static std::vector GetLogs(); }; \ No newline at end of file diff --git a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp index 1ac80ad7..fdfd21c9 100644 --- a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp +++ b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp @@ -27,8 +27,5 @@ void BulletDebugDrawer::drawContactPoint(const btVector3& PointOnB, const btVect glColor3f(color.x(), color.y(), color.z()); glVertex3f(PointOnB.x(), PointOnB.y(), PointOnB.z()); glEnd(); - - - } diff --git a/Nuake/src/Resource/Project.cpp b/Nuake/src/Resource/Project.cpp index 22989505..c8b7521b 100644 --- a/Nuake/src/Resource/Project.cpp +++ b/Nuake/src/Resource/Project.cpp @@ -109,7 +109,7 @@ bool Project::Deserialize(const std::string& str) std::string sceneContent = FileSystem::ReadFile(scenePath, false); if (!this->DefaultScene->Deserialize(sceneContent)) { - Logger::Log("Error loading scene: " + scenePath); + Logger::Log("Error loading scene: " + scenePath, CRITICAL); } else { diff --git a/Nuake/src/Scene/Components/ParentComponent.h b/Nuake/src/Scene/Components/ParentComponent.h index 667588c7..1b1ddb77 100644 --- a/Nuake/src/Scene/Components/ParentComponent.h +++ b/Nuake/src/Scene/Components/ParentComponent.h @@ -14,11 +14,21 @@ struct ParentComponent SERIALIZE_VAL(HasParent); if(HasParent) SERIALIZE_VAL_LBL("Parent", Parent.GetHandle()); + + //int i = 0; + //for (auto& c : Children) { + // j["Children"][0] = c.GetHandle(); + // i++; + //} + END_SERIALIZE(); } bool Deserialize(std::string str) { + BEGIN_DESERIALIZE(); + + //this->Parent = Entity{ j["Parent"], Engine::GetCurrentScene().get() }; return true; diff --git a/Nuake/src/Scene/Components/QuakeMap.cpp b/Nuake/src/Scene/Components/QuakeMap.cpp index a6a3fa3f..4e59b237 100644 --- a/Nuake/src/Scene/Components/QuakeMap.cpp +++ b/Nuake/src/Scene/Components/QuakeMap.cpp @@ -16,108 +16,9 @@ void QuakeMapComponent::Load(std::string path, bool collisions) return; Path = path; - - //Build(); } -void QuakeMapComponent::Build() -{ - //m_Meshes.clear(); - //map_parser_load(Path.c_str()); - // - //geo_generator_run(); - // - //Ref DefaultMaterial = MaterialManager::Get()->GetMaterial("resources/Textures/default/Default.png"); - //for (int e = 0; e < entity_count; ++e) - //{ - // entity* entity_inst = &entities[e]; - // entity_geometry* entity_geo_inst = &entity_geo[e]; - // - // - // for (int b = 0; b < entity_inst->brush_count; ++b) - // { - // brush* brush_inst = &entity_inst->brushes[b]; - // brush_geometry* brush_geo_inst = &entity_geo_inst->brushes[b]; - // - // std::vector vertices; - // std::vector indices; - // - // int index_offset = 0; - // int lastTextureID = -1; - // std::string lastTexturePath = ""; - // for (int f = 0; f < brush_inst->face_count; ++f) - // { - // face* face = &brush_inst->faces[f]; - // texture_data* texture = &textures[face->texture_idx]; - // if (std::string(texture->name) == "__TB_empty") { - // texture->height = 1; - // texture->width = 1; - // } - // else { - // std::string path = "resources/Textures/" + std::string(texture->name) + ".png"; - // auto tex = TextureManager::Get()->GetTexture(path); - // texture->height = tex->GetHeight(); - // texture->width = tex->GetWidth(); - // } - // - // - // face_geometry* face_geo_inst = &brush_geo_inst->faces[f]; - // //printf("Face %d\n", f); - // for (int i = 0; i < face_geo_inst->vertex_count; ++i) - // { - // face_vertex vertex = face_geo_inst->vertices[i]; - // vertex_uv vertex_uv = get_standard_uv(vertex.vertex, face, texture->width, texture->height); - // vertices.push_back(Vertex{ - // glm::vec3((vertex.vertex.y - brush_inst->center.y) * (1.0f / 64), - // (vertex.vertex.z - brush_inst->center.z) * (1.0f / 64), - // (vertex.vertex.x - brush_inst->center.x) * (1.0f / 64)), - // glm::vec2(vertex_uv.u, 1.0 - vertex_uv.v), - // glm::vec3(vertex.normal.y, vertex.normal.z, vertex.normal.x), - // glm::vec3(vertex.tangent.y, vertex.tangent.z, vertex.tangent.x), glm::vec3(0.0, 1.0, 0.0), 0.0f - // }); - // - // //printf("vertex: (%f %f %f), normal: (%f %f %f)\n", - // // vertex.vertex.x, vertex.vertex.y, vertex.vertex.z, - // // vertex.normal.x, vertex.normal.y, vertex.normal.z); - // } - // - // //puts("Indices:"); - // for (int i = 0; i < (face_geo_inst->vertex_count - 2) * 3; ++i) - // { - // unsigned int index = face_geo_inst->indices[i]; - // //printf("index: %d\n", index_offset + index); - // indices.push_back(index_offset + (unsigned int)index); - // } - // if (lastTextureID != face->texture_idx) - // { - // lastTexturePath = "resources/Textures/" + std::string(texture->name) + ".png"; - // if (std::string(texture->name) == "__TB_empty") - // m_Meshes.push_back(CreateRef(vertices, indices, DefaultMaterial)); - // else - // m_Meshes.push_back(CreateRef(vertices, indices, MaterialManager::Get()->GetMaterial(lastTexturePath))); - // - // - // - // index_offset = 0; - // vertices.clear(); - // indices.clear(); - // lastTextureID = face->texture_idx; - // - // - // } - // else - // { - // index_offset += (face_geo_inst->vertex_count); - // } - // } - // - // if (vertices.size() > 0) - // m_Meshes.push_back(CreateRef(vertices, indices, MaterialManager::Get()->GetMaterial(lastTexturePath))); - // //putchar('\n'); - // //putchar('\n'); - // } - //} -} + void QuakeMapComponent::DrawEditor() { diff --git a/Nuake/src/Scene/Components/QuakeMap.h b/Nuake/src/Scene/Components/QuakeMap.h index 35072248..88d5454f 100644 --- a/Nuake/src/Scene/Components/QuakeMap.h +++ b/Nuake/src/Scene/Components/QuakeMap.h @@ -14,8 +14,7 @@ public: std::string Path; bool HasCollisions = false; void Load(std::string path, bool collisions); - void Build(); - void Rebuild(); + void Draw(); void DrawEditor(); @@ -32,7 +31,6 @@ public: BEGIN_DESERIALIZE(); this->Path = j["Path"]; this->HasCollisions = j["HasCollisions"]; - Build(); // Maybe have some kind of loading bar or something. return true; } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index 6882fe2d..5d18eefc 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include "src/Core/FileSystem.h" extern "C" { #include "libmap/h/map_parser.h" #include @@ -282,7 +282,7 @@ void QuakeMapBuilder::BuildQuakeMap(Entity& ent, bool Collisions) currentParent.Children.clear(); - map_parser_load(quakeMapC.Path.c_str()); + map_parser_load(std::string(FileSystem::Root + quakeMapC.Path).c_str()); geo_generator_run(); DefaultMaterial = MaterialManager::Get()->GetMaterial("resources/Textures/default/Default.png"); diff --git a/Nuake/src/Scripting/ScriptingEngine.cpp b/Nuake/src/Scripting/ScriptingEngine.cpp index 4f8831cd..eaeffb51 100644 --- a/Nuake/src/Scripting/ScriptingEngine.cpp +++ b/Nuake/src/Scripting/ScriptingEngine.cpp @@ -23,16 +23,19 @@ void errorFn(WrenVM* vm, WrenErrorType errorType, { case WREN_ERROR_COMPILE: { + std::string t = "Script error in: " + std::string(module)+ " line:" + std::to_string(line) + " \n error: "+ msg; + Logger::Log(t, CRITICAL); Engine::ExitPlayMode(); - printf("[%s line %d] [Error] %s\n", module, line, msg); } break; case WREN_ERROR_STACK_TRACE: { - printf("[%s line %d] in %s\n", module, line, msg); + std::string t = "Script Stack trace: " + std::string(module) + " line:" + std::to_string(line) + " \n stack: " + msg; + Logger::Log(t, CRITICAL); } break; case WREN_ERROR_RUNTIME: { - printf("[Runtime Error] %s\n", msg); + std::string t = "Script Runtime Error: " + std::string(msg); + Logger::Log(t, WARNING); } break; } diff --git a/Nuake/src/UI/Font/FontLoader.h b/Nuake/src/UI/Font/FontLoader.h index ae751952..2afbe0fe 100644 --- a/Nuake/src/UI/Font/FontLoader.h +++ b/Nuake/src/UI/Font/FontLoader.h @@ -88,7 +88,7 @@ public: // Load file if (!font->load(path.c_str())) - Logger::Log("Failed to laod font"); + Logger::Log("Failed to load font", CRITICAL); // Load charset ASCII std::vector glyphs; @@ -105,7 +105,7 @@ public: fonts.push_back(fontGeometry); if (glyphs.empty()) - Logger::Log("No glyphs loaded."); + Logger::Log("No glyphs loaded.", CRITICAL); // Create atlas params msdf_atlas::TightAtlasPacker::DimensionsConstraint atlasSizeConstraint = msdf_atlas::TightAtlasPacker::DimensionsConstraint::MULTIPLE_OF_FOUR_SQUARE; @@ -120,7 +120,7 @@ public: // Pack atlas if (int remaining = atlasPacker.pack(glyphs.data(), glyphs.size())) { if (remaining < 0) { - Logger::Log("Failed to pack atlas."); + Logger::Log("Failed to pack atlas.", CRITICAL); } else { printf("Error: Could not fit %d out of %d glyphs into the atlas.\n", remaining, (int)glyphs.size()); diff --git a/Nuake/src/UI/Font/FontManager.cpp b/Nuake/src/UI/Font/FontManager.cpp index d2119545..69eff7e4 100644 --- a/Nuake/src/UI/Font/FontManager.cpp +++ b/Nuake/src/UI/Font/FontManager.cpp @@ -15,6 +15,6 @@ Ref FontManager::GetFont(const std::string& font) if (newFont) return newFont; - Logger::Log("Error: failed to load font " + font); + Logger::Log("Error: failed to load font " + font, CRITICAL); return nullptr; } \ No newline at end of file diff --git a/Nuake/src/UI/InterfaceParser.cpp b/Nuake/src/UI/InterfaceParser.cpp index c2ed807f..c4b2750d 100644 --- a/Nuake/src/UI/InterfaceParser.cpp +++ b/Nuake/src/UI/InterfaceParser.cpp @@ -31,7 +31,7 @@ Ref InterfaceParser::Parse(const std::string path) std::string name = doc.first_child().name(); if (name != "Canvas") { - Logger::Log("InterfaceParser error: First child should be a canvas - " + path); + Logger::Log("InterfaceParser error: First child should be a canvas - " + path, CRITICAL); return nullptr; } diff --git a/Nuake/src/UI/UserInterface.cpp b/Nuake/src/UI/UserInterface.cpp index 44e5ed97..52db4ad0 100644 --- a/Nuake/src/UI/UserInterface.cpp +++ b/Nuake/src/UI/UserInterface.cpp @@ -18,7 +18,7 @@ namespace UI if (!Root) { - Logger::Log("Failed to generate interface structure"); + Logger::Log("Failed to generate interface structure", CRITICAL); } yoga_config = YGConfigNew(); @@ -38,7 +38,7 @@ namespace UI Root = InterfaceParser::Parse("resources/Interface/Testing.interface"); if (!Root) { - Logger::Log("Failed to generate interface structure"); + Logger::Log("Failed to generate interface structure", CRITICAL); } yoga_config = YGConfigNew(); @@ -89,8 +89,6 @@ namespace UI CreateYogaLayoutRecursive(n, newYogaNode); index++; } - - Logger::Log(std::to_string(YGNodeGetChildCount(yoga_node))); } void UserInterface::Draw(Vector2 size) diff --git a/Nuake/src/Vendors/imgui/imgui_internal.h b/Nuake/src/Vendors/imgui/imgui_internal.h index 755d95c2..3cd84227 100644 --- a/Nuake/src/Vendors/imgui/imgui_internal.h +++ b/Nuake/src/Vendors/imgui/imgui_internal.h @@ -6,6 +6,7 @@ // #define IMGUI_DEFINE_MATH_OPERATORS // To implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators) +#define IMGUI_DEFINE_MATH_OPERATORS /* Index of this file: diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index fd3b2c89..db680191 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -89,16 +89,16 @@ int Window::Init() { if (!glfwInit()) { - Logger::Log("glfw initialization failed."); + Logger::Log("glfw initialization failed.", CRITICAL); return -1; } // Create window - m_Window = glfwCreateWindow(m_Width, m_Height, "Editor - Dev build", NULL, NULL); + m_Window = glfwCreateWindow(m_Width, m_Height, "Nuake - Dev build", NULL, NULL); if (!m_Window) { - Logger::Log("Window creation failed."); + Logger::Log("Window creation failed.", CRITICAL); return -1; } @@ -108,7 +108,7 @@ int Window::Init() if (glewInit() != GLEW_OK) { - Logger::Log("GLEW initialization failed!"); + Logger::Log("GLEW initialization failed!", CRITICAL); return -1; }