osb/source/game/StarImageMetadataDatabase.hpp

42 lines
1.2 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#ifndef STAR_IMAGE_METADATA_DATABASE_HPP
#define STAR_IMAGE_METADATA_DATABASE_HPP
#include "StarRect.hpp"
#include "StarMap.hpp"
#include "StarString.hpp"
#include "StarThread.hpp"
2023-06-24 12:49:47 +00:00
#include "StarAssetPath.hpp"
2023-06-20 04:33:09 +00:00
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:
2023-06-24 12:49:47 +00:00
Vec2U imageSize(AssetPath const& path) const;
List<Vec2I> imageSpaces(AssetPath const& path, Vec2F position, float fillLimit, bool flip) const;
RectU nonEmptyRegion(AssetPath const& path) const;
2023-06-20 04:33:09 +00:00
private:
// Removes image processing directives that don't affect image spaces /
// non-empty regions.
2023-06-24 12:49:47 +00:00
static AssetPath filterProcessing(AssetPath const& path);
2023-06-20 04:33:09 +00:00
2023-06-24 12:49:47 +00:00
Vec2U calculateImageSize(AssetPath const& path) const;
2023-06-20 04:33:09 +00:00
// Path, position, fillLimit, and flip
2023-06-24 12:49:47 +00:00
typedef tuple<AssetPath, Vec2I, float, bool> SpacesEntry;
2023-06-20 04:33:09 +00:00
mutable Mutex m_mutex;
2023-06-24 12:49:47 +00:00
mutable HashMap<AssetPath, Vec2U> m_sizeCache;
2023-06-20 04:33:09 +00:00
mutable HashMap<SpacesEntry, List<Vec2I>> m_spacesCache;
2023-06-24 12:49:47 +00:00
mutable HashMap<AssetPath, RectU> m_regionCache;
2023-06-20 04:33:09 +00:00
};
}
#endif