Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
BitmapRuntime.cpp
Go to the documentation of this file.
1#include "BitmapRuntime.hpp"
2namespace monopoly::data
3{
5 {
6 return std::erase_if(assets_, [](const auto& entry)
7 { return entry.second.use_count() == 1; });
8 }
9
10 std::expected<std::shared_ptr<const BitmapRuntimeAsset>, BitmapError>
13 {
14 if (!bytes)
15 return std::unexpected(BitmapError{BitmapErrorCode::ReadFailed, {},
16 "missing immutable bitmap payload"});
17 const auto found = assets_.find(id);
18 if (found != assets_.end() && found->second->source == bytes &&
19 found->second->sourceType == sourceType)
20 return found->second;
21
22 std::expected<LegacyBitmapRGBA8, BitmapError> decoded =
24 "bitmap runtime supports only DataBMP and DataUAP"});
25 if (sourceType == LegacyDataType::Bitmap)
27 else if (sourceType == LegacyDataType::Uap)
29 if (!decoded) return std::unexpected(decoded.error());
30
31 auto asset = std::make_shared<const BitmapRuntimeAsset>(
32 BitmapRuntimeAsset{id, sourceType, std::move(bytes), std::move(*decoded)});
33 assets_.insert_or_assign(id, asset);
34 return asset;
35 }
36}
std::vector< std::byte > bytes
data::DataId id
unsigned index
std::size_t releaseUnused() noexcept
std::expected< std::shared_ptr< const BitmapRuntimeAsset >, BitmapError > resolve(DataId id, LegacyDataType sourceType, SharedDataBytes bytes)
std::uint32_t DataId
Definition DataBanks.hpp:10
std::shared_ptr< const DataBytes > SharedDataBytes
std::expected< LegacyBitmapRGBA8, BitmapError > decodeLegacyUapRGBA8(std::span< const std::byte > bytes, std::size_t maxPixels)
std::expected< LegacyBitmapRGBA8, BitmapError > decodeLegacyBitmapRGBA8(std::span< const std::byte > bytes, std::size_t maxPixels)