Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarImageMetadataDatabase.hpp
blob: 0a04b1f28654307c254b435a8c63b4a8e778cbf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once

#include "StarRect.hpp"
#include "StarMap.hpp"
#include "StarString.hpp"
#include "StarThread.hpp"
#include "StarAssetPath.hpp"
#include "StarTtlCache.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:
  ImageMetadataDatabase();
  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;
  void cleanup() const;

private:
  // Removes image processing directives that don't affect image spaces /
  // non-empty regions.
  static AssetPath filterProcessing(AssetPath const& path);

  Vec2U calculateImageSize(AssetPath const& path) const;

  // Path, position, fillLimit, and flip
  typedef tuple<AssetPath, Vec2I, float, bool> SpacesEntry;

  mutable Mutex m_mutex;
  mutable HashTtlCache<AssetPath, Vec2U> m_sizeCache;
  mutable HashTtlCache<SpacesEntry, List<Vec2I>> m_spacesCache;
  mutable HashTtlCache<AssetPath, RectU> m_regionCache;
};

}