diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/game/StarImageMetadataDatabase.hpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/game/StarImageMetadataDatabase.hpp')
-rw-r--r-- | source/game/StarImageMetadataDatabase.hpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/source/game/StarImageMetadataDatabase.hpp b/source/game/StarImageMetadataDatabase.hpp new file mode 100644 index 0000000..1f29da6 --- /dev/null +++ b/source/game/StarImageMetadataDatabase.hpp @@ -0,0 +1,40 @@ +#ifndef STAR_IMAGE_METADATA_DATABASE_HPP +#define STAR_IMAGE_METADATA_DATABASE_HPP + +#include "StarRect.hpp" +#include "StarMap.hpp" +#include "StarString.hpp" +#include "StarThread.hpp" + +namespace Star { + +STAR_CLASS(ImageMetadataDatabase); + +// Caches image size, image spaces, and nonEmptyRegion completely until a +// reload, does not expire cached values in a TTL based way like Assets, +// because they are expensive to compute and cheap to keep around. +class ImageMetadataDatabase { +public: + Vec2U imageSize(String const& path) const; + List<Vec2I> imageSpaces(String const& path, Vec2F position, float fillLimit, bool flip) const; + RectU nonEmptyRegion(String const& path) const; + +private: + // Removes image processing directives that don't affect image spaces / + // non-empty regions. + static String filterProcessing(String const& path); + + Vec2U calculateImageSize(String const& path) const; + + // Path, position, fillLimit, and flip + typedef tuple<String, Vec2I, float, bool> SpacesEntry; + + mutable Mutex m_mutex; + mutable StringMap<Vec2U> m_sizeCache; + mutable HashMap<SpacesEntry, List<Vec2I>> m_spacesCache; + mutable StringMap<RectU> m_regionCache; +}; + +} + +#endif |