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
"
2
namespace
monopoly::data
3
{
4
std::size_t
BitmapRuntimeCache::releaseUnused
()
noexcept
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
>
11
BitmapRuntimeCache::resolve
(
12
DataId
id
,
LegacyDataType
sourceType,
SharedDataBytes
bytes
)
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
=
23
std::unexpected(
BitmapError
{
BitmapErrorCode::UnsupportedDataType
, {},
24
"bitmap runtime supports only DataBMP and DataUAP"
});
25
if
(sourceType ==
LegacyDataType::Bitmap
)
26
decoded
=
decodeLegacyBitmapRGBA8
(*
bytes
);
27
else
if
(sourceType ==
LegacyDataType::Uap
)
28
decoded
=
decodeLegacyUapRGBA8
(*
bytes
);
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
}
BitmapRuntime.hpp
bytes
std::vector< std::byte > bytes
Definition
BoardTextureRuntime.cpp:15
id
data::DataId id
Definition
EscapeConfirmationPlayback.cpp:13
index
unsigned index
Definition
ModernIBarSkin.cpp:25
monopoly::data::BitmapRuntimeCache::releaseUnused
std::size_t releaseUnused() noexcept
Definition
BitmapRuntime.cpp:4
monopoly::data::BitmapRuntimeCache::resolve
std::expected< std::shared_ptr< const BitmapRuntimeAsset >, BitmapError > resolve(DataId id, LegacyDataType sourceType, SharedDataBytes bytes)
Definition
BitmapRuntime.cpp:11
monopoly::data
Definition
ArchiveAssembly.cpp:21
monopoly::data::DataId
std::uint32_t DataId
Definition
DataBanks.hpp:10
monopoly::data::LegacyDataType
LegacyDataType
Definition
LegacyDataArchive.hpp:24
monopoly::data::LegacyDataType::Bitmap
@ Bitmap
monopoly::data::LegacyDataType::Uap
@ Uap
monopoly::data::SharedDataBytes
std::shared_ptr< const DataBytes > SharedDataBytes
Definition
LegacyDataArchive.hpp:152
monopoly::data::decodeLegacyUapRGBA8
std::expected< LegacyBitmapRGBA8, BitmapError > decodeLegacyUapRGBA8(std::span< const std::byte > bytes, std::size_t maxPixels)
Definition
LegacyBitmap.cpp:179
monopoly::data::decodeLegacyBitmapRGBA8
std::expected< LegacyBitmapRGBA8, BitmapError > decodeLegacyBitmapRGBA8(std::span< const std::byte > bytes, std::size_t maxPixels)
Definition
LegacyBitmap.cpp:411
monopoly::data::BitmapErrorCode::UnsupportedDataType
@ UnsupportedDataType
monopoly::data::BitmapErrorCode::ReadFailed
@ ReadFailed
monopoly::data::BitmapError
Definition
LegacyBitmap.hpp:35
monopoly::data::BitmapRuntimeAsset
Definition
BitmapRuntime.hpp:12
BitmapRuntime.cpp
Generated by
1.9.8