NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
asset.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <map>
15#include <vector>
16
18#include "NNL/common/io.hpp"
19namespace nnl {
20
28
33namespace asset {
39
57using Asset = std::map<u32, Buffer>;
68using AssetView = std::map<u32, BufferView>;
69
82bool IsOfType(BufferView buffer);
83
84bool IsOfType(const std::filesystem::path& path);
85
86bool IsOfType(Reader& f);
87
103
104Asset Import(const std::filesystem::path& path);
105
130[[nodiscard]] Buffer Export(const Asset& asset_container);
131
132void Export(const Asset& asset_container, const std::filesystem::path& path);
133
134void Export(const Asset& asset_container, Writer& f);
135
136[[nodiscard]] Buffer Export(const AssetView& asset_container);
137
138void Export(const AssetView& asset_container, const std::filesystem::path& path);
139
140void Export(const AssetView& asset_container, Writer& f);
141
143
150
160enum Category : u32 {
162 kAsset3DModel = 0b10000001,
165 kAsset3DAnim = 0b10000010,
167 kAsset3DAction = 0b10000100,
168 kAsset3DEffect = 0b10001000,
170 kSoundBank = 0b1'00000000,
172 kBitmapTextFont = 0b101'0'00000000,
174 kBitmapTextFull = 0b110'0'00000000,
175 kUIConfigs = 0b1'000'0'00000000,
176 kUIConfigTextureContainer = 0b1'0'000'0'00000000,
177 kPlaceholder = 0x80000000
178};
179
191namespace Asset3D {
192
193constexpr u32 kModel = 0;
194constexpr u32 kTextureContainer = 1;
196constexpr u32 kActionConfig = 3;
197constexpr u32 kColboxConfig = 4;
198constexpr u32 kCollectionSpline = 5;
201constexpr u32 kTextureContainer2 = 6;
203constexpr u32 kCollision = 7;
204constexpr u32 kShadowCollision = 8;
206
207} // namespace Asset3D
208
217namespace SoundBank {
218
219constexpr u32 kPHD = 0;
221constexpr u32 kPBD = 1;
223
224} // namespace SoundBank
225
236namespace BitmapText {
237
238constexpr u32 kTextureContainer = 0;
239constexpr u32 kAdvanceWidth = 1;
240constexpr u32 kText = 2;
241
242} // namespace BitmapText
243
252
257
259
260namespace raw {
261NNL_PACK(struct RFileRecord {
262 u32 offset = 0;
263 u32 size = 0;
264});
265
266static_assert(sizeof(RFileRecord) == 0x8);
267
268template <typename TData>
269struct RAsset {
270 std::vector<RFileRecord> file_records;
271 // Maps of offsets (used in the structures above) to their data:
272 std::multimap<u32, TData> file_buffers; // offsets may repeat if empty buffers present
273};
274
275RAsset<Buffer> Parse(Reader& f);
276
277RAsset<BufferView> ParseView(BufferView buffer);
278
279Asset Convert(RAsset<Buffer>&& rasset);
280
281AssetView Convert(RAsset<BufferView>&& rasset);
282
283} // namespace raw
284
285} // namespace asset
286
287} // namespace nnl
Contains macros and definitions for fixed-width types.
Category
Classification for asset container layouts.
Definition asset.hpp:160
Category Categorize(const Asset &asset)
Determines the category of an asset by analyzing its contents.
@ kAsset3DAction
Contains only kActionConfig.
Definition asset.hpp:167
@ kBitmapTextFull
Consists of kTextureContainer, glyph spacing, kText.
Definition asset.hpp:174
@ kSoundBank
Definition asset.hpp:170
@ kUnknown
Unknown.
Definition asset.hpp:161
@ kBitmapTextFont
Definition asset.hpp:172
@ kAsset3DEffect
Definition asset.hpp:168
@ kPlaceholder
No entries.
Definition asset.hpp:177
@ kAsset3DAnim
Definition asset.hpp:165
@ kUIConfigs
Consists of multiple kUIConfig's.
Definition asset.hpp:175
@ kAsset3DModel
Definition asset.hpp:162
@ kUIConfigTextureContainer
Consists of pairs of kUIConfig and kTextureContainer.
Definition asset.hpp:176
std::map< u32, BufferView > AssetView
A non-owning view of an asset container.
Definition asset.hpp:68
Buffer Export(const Asset &asset_container)
Converts an asset container to a binary file representation.
bool IsOfType(BufferView buffer)
Tests if the provided file is an asset container.
Asset Import(BufferView buffer)
Parses a binary file and converts it into an Asset object.
AssetView ImportView(BufferView buffer)
Parses a binary file and converts it into an AssetView object.
std::map< u32, Buffer > Asset
A container for related parts of a complete asset.
Definition asset.hpp:57
std::uint32_t u32
32-bit unsigned integer
Definition fixed_type.hpp:60
#define NNL_PACK(...)
A structure packing directive.
Definition fixed_type.hpp:41
Reader implementation for read-only memory buffers.
Definition io.hpp:598
Abstract class for writing data.
Definition io.hpp:136
Abstract class for reading data.
Definition io.hpp:78
std::vector< u8 > Buffer
A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted...
Definition io.hpp:40
Provides classes for reading and writing binary data to and from various sources.
Constants for accessing entries in an asset container that stores a 3D object.
Definition asset.hpp:191
constexpr u32 kTextureContainer2
Definition asset.hpp:201
constexpr u32 kColboxConfig
Definition asset.hpp:197
constexpr u32 kCollision
Definition asset.hpp:203
constexpr u32 kShadowCollision
Definition asset.hpp:204
constexpr u32 kTextureContainer
Definition asset.hpp:194
constexpr u32 kVisanimationContainer
Definition asset.hpp:205
constexpr u32 kCollectionSpline
Definition asset.hpp:198
constexpr u32 kActionConfig
Definition asset.hpp:196
constexpr u32 kModel
Definition asset.hpp:193
constexpr u32 kAnimationContainer
Definition asset.hpp:195
Constants for accessing entries in an asset container that stores a bitmap text archive.
Definition asset.hpp:236
constexpr u32 kAdvanceWidth
A plain u8 array specifying the advance width for each character of kText.
Definition asset.hpp:239
constexpr u32 kText
Definition asset.hpp:240
constexpr u32 kTextureContainer
Definition asset.hpp:238
Constants for accessing entries in an asset container that stores a PHD/PBD sound bank,...
Definition asset.hpp:217
constexpr u32 kPBD
Definition asset.hpp:221
constexpr u32 kPHD
Definition asset.hpp:219
Provides structures and functions to manage containers of interrelated asset parts.
Definition asset.hpp:33
Definition exception.hpp:56