From 76ac6e2f6de69736f3f71857922b9d2896bfcf64 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Sun, 29 May 2022 11:59:17 +0200 Subject: [PATCH] Refactor --- src/Scene.cpp | 14 +++++--------- src/resources/CubeMap.h | 2 +- src/resources/Resource.cpp | 6 +++--- src/resources/Resource.h | 7 ++++--- src/resources/Texture.cpp | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Scene.cpp b/src/Scene.cpp index 2388122..0a8968a 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -54,13 +54,12 @@ Scene::Scene(std::vector shaderPrograms) // TODO: use geometry shader instead of model and load skybox before models. Skybox::Prototype skyboxPrototype = modelParser.getSkyboxPrototype(); - std::thread skyboxThread([=]() { - m_skybox = new Skybox(skyboxPrototype, - std::static_pointer_cast(ResourceHandler::instance().resource("cube")).get(), - Controller::getShaderProgramByName("skyboxProgram", shaderPrograms)); + m_skybox = + new Skybox(skyboxPrototype, std::static_pointer_cast(ResourceHandler::instance().resource("cube")).get(), + Controller::getShaderProgramByName("skyboxProgram", shaderPrograms)); - Log::logger().info("Loaded skybox: {}", skyboxPrototype.texturePath); - }); + Log::logger().info("Loaded skybox: {}", skyboxPrototype.texturePath); + m_skybox->initializeOnGPU(); std::vector entityPrototypes = modelParser.getEntityPrototypes(); @@ -127,9 +126,6 @@ Scene::Scene(std::vector shaderPrograms) } } m_lights = lights; - - skyboxThread.join(); - m_skybox->initializeOnGPU(); } Scene::~Scene() diff --git a/src/resources/CubeMap.h b/src/resources/CubeMap.h index f01d94d..22995b7 100644 --- a/src/resources/CubeMap.h +++ b/src/resources/CubeMap.h @@ -30,7 +30,7 @@ struct TextureCubeMapDescriptor class AbstractCubeMap : public AbstractTexture { public: - AbstractCubeMap(const std::string path) : AbstractTexture(path) + AbstractCubeMap(const std::string &path) : AbstractTexture(path) {} void bind(ShaderProgram *shaderProgram) const; diff --git a/src/resources/Resource.cpp b/src/resources/Resource.cpp index 4f28d86..244b514 100644 --- a/src/resources/Resource.cpp +++ b/src/resources/Resource.cpp @@ -3,9 +3,9 @@ ResourceId Resource::s_idCounter = 0; -Resource::Resource(const std::string &path) : m_id(s_idCounter++), m_path(path) +Resource::Resource(const std::filesystem::path &path) : m_id(s_idCounter++), m_path(path) { - Log::logger().info("Resource \"{}\" with id {} created", m_path, m_id); + Log::logger().info("Resource \"{}\" with id {} created", m_path.string(), m_id); } ResourceId Resource::id() const @@ -18,7 +18,7 @@ bool Resource::isInitialized() const return m_initialized; } -const std::string &Resource::resourcePath() const +const std::filesystem::path &Resource::resourcePath() const { return m_path; } diff --git a/src/resources/Resource.h b/src/resources/Resource.h index 9c7fe04..2e81329 100644 --- a/src/resources/Resource.h +++ b/src/resources/Resource.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -9,14 +10,14 @@ using ResourceId = uint64_t; class Resource { public: - Resource(const std::string &path); + Resource(const std::filesystem::path &path); Resource(const Resource &other) = delete; Resource(Resource &&other) = delete; Resource &operator=(const Resource &other) = delete; Resource &operator=(Resource &&other) = delete; ResourceId id() const; - const std::string &resourcePath() const; + const std::filesystem::path &resourcePath() const; protected: bool isInitialized() const; @@ -28,7 +29,7 @@ private: ResourceId m_id; static ResourceId s_idCounter; - std::string m_path; + std::filesystem::path m_path; friend class ResourceHandler; }; diff --git a/src/resources/Texture.cpp b/src/resources/Texture.cpp index c79fa32..774b1e4 100644 --- a/src/resources/Texture.cpp +++ b/src/resources/Texture.cpp @@ -9,7 +9,7 @@ Texture::Texture(const TextureDescriptor &descriptor) m_textureBuffer = stbi_load(resourcePath().c_str(), &m_textureWidth, &m_textureHeight, &m_numComponents, 0); if (!m_textureBuffer) - Log::logger().warn("Texture {} could not be loaded", resourcePath()); + Log::logger().warn("Texture {} could not be loaded", resourcePath().string()); } void Texture::initialize()