diff --git a/src/Resources/CoverAtlas.cpp b/src/Resources/CoverAtlas.cpp deleted file mode 100644 index be06606..0000000 --- a/src/Resources/CoverAtlas.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "CoverAtlas.hpp" - -#include -#include -#include -#include - -namespace fs = std::filesystem; - -sf::Sprite Textures::CoverAltas::at(const fs::path& path) const { - - std::size_t index; - if (path_to_index.find(path) != path_to_index.end()) { - index = path_to_index.at(path); - } else { - index = 0; - } - - auto location = get_detailed_location(index); - sf::IntRect rect(location.column*256, location.row*256, 256, 256); - sf::Sprite cover; - cover.setTexture(textures.at(location.texture_index)->getTexture()); - cover.setTextureRect(rect); - return cover; -} - -void Textures::CoverAltas::emplace_back(const fs::path& cover) { - - if (path_to_index.find(cover) != path_to_index.end()) { - return; - } - - sf::Texture cover_texture; - if (!cover_texture.loadFromFile(cover)) { - throw std::invalid_argument("Unable to load cover image : "+cover.string()); - } - std::size_t next_index = next_available_index(); - auto size = cover_texture.getSize(); - auto location = get_detailed_location(next_index); - sf::Sprite new_cover; - new_cover.setTexture(cover_texture); - new_cover.setScale(256.0f/size.x, 256.0f/size.y); - new_cover.setPosition(256.0f * location.column, 256.0f * location.row); - if (location.column == 0 and location.row == 0) { - // first cover means it's a new texture - textures.push_back(std::make_shared()); - textures.back()->create(1024, 1024); - } - textures.at(location.texture_index)->draw(new_cover); - textures.at(location.texture_index)->display(); - path_to_index[cover] = next_index; - index_to_path[next_index] = cover; -} - -void Textures::CoverAltas::efficient_reload(const std::vector& covers) { - - // Remove the paths that are not present in covers - auto it = path_to_index.begin(); - while (it != path_to_index.end()) { - if (std::find(covers.begin(), covers.end(), it->first) == covers.end()) { - index_to_path.erase(it->second); - it = path_to_index.erase(it); - } else { - ++it; - } - } - - // Add the covers that are not already in the altas - for (const auto& cover : covers) { - if (path_to_index.find(cover) == path_to_index.end()) { - this->emplace_back(cover); - } - } -} - -Textures::DetailedLocation Textures::get_detailed_location(std::size_t location) { - return {location / 16, (location % 16) / 4, location % 4}; -} - -std::size_t Textures::CoverAltas::next_available_index() { - std::size_t index = 0; - while (index_to_path.find(index) != index_to_path.end()) { - ++index; - } - return index; -} diff --git a/src/Resources/CoverAtlas.hpp b/src/Resources/CoverAtlas.hpp deleted file mode 100644 index 387f7a8..0000000 --- a/src/Resources/CoverAtlas.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include - -namespace Textures { - - /* - A CoverAltas stores 256x256 cover previews in a vector of 1024x1024 textures - */ - class CoverAltas { - public: - CoverAltas(); - // returns the sprite corresponding to the path - // returns a fallback texture if the path is unknown - sf::Sprite at(const fs::path& path) const; - void emplace_back(const fs::path& cover); - // only loads the images not already present in the atlas - // empties the slots not present in the vector - void efficient_reload(const std::vector& covers); - - private: - std::unordered_map path_to_index; - std::unordered_map index_to_path; - std::vector> textures; - std::size_t next_available_index(); - }; - - struct DetailedLocation { - std::size_t texture_index; - std::size_t row; - std::size_t column; - }; - - DetailedLocation get_detailed_location(std::size_t location); -} diff --git a/src/Resources/meson.build b/src/Resources/meson.build index 9f408f2..63b1974 100644 --- a/src/Resources/meson.build +++ b/src/Resources/meson.build @@ -4,6 +4,5 @@ sources += files( 'Marker.cpp', 'SharedResources.cpp', 'SpriteSheet.cpp', - 'SplitSpriteSheet.cpp', - # 'CoverAtlas.cpp', + 'SplitSpriteSheet.cpp' ) \ No newline at end of file