vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
asset_type.h
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include "core/reflect.h"
7
8namespace Vkm::Engine {
9
20#define VKM_ASSET_KINDS(X) \
21 X(Mesh, MeshAsset, "mesh", "meshes") \
22 X(Texture, TextureAsset, "texture", "textures") \
23 X(Material, MaterialAsset, "material", "materials") \
24 X(Skeleton, SkeletonAsset, "skeleton", "skeletons") \
25 X(AnimationClip, AnimationClipAsset, "animationClip", "clips") \
26 X(AudioClip, AudioClipAsset, "audioClip", "sounds")
27
34#define VKM_ASSET_ENUMERATOR(tag, type, name, dir) tag,
35enum class AssetType : uint8_t {
36 VKM_ASSET_KINDS(VKM_ASSET_ENUMERATOR)
37
38 Count
39};
40#undef VKM_ASSET_ENUMERATOR
41
42#define VKM_ASSET_FORWARD_DECL(tag, type, name, dir) struct type;
43VKM_ASSET_KINDS(VKM_ASSET_FORWARD_DECL)
44#undef VKM_ASSET_FORWARD_DECL
45
52inline constexpr AssetType ASSET_DEPENDENCY_ORDER[] = {
53 AssetType::Texture,
54 AssetType::Material,
55 AssetType::Skeleton,
56 AssetType::AnimationClip,
57 AssetType::Mesh,
58 AssetType::AudioClip,
59};
60
61namespace detail {
62
63constexpr bool everyKindOrderedOnce() {
64 for (size_t kind = 0; kind < static_cast<size_t>(AssetType::Count); ++kind) {
65 size_t seen = 0;
66 for (const AssetType type : ASSET_DEPENDENCY_ORDER) seen += static_cast<size_t>(type) == kind ? 1 : 0;
67 if (seen != 1) return false;
68 }
69 return sizeof(ASSET_DEPENDENCY_ORDER) / sizeof(AssetType) == static_cast<size_t>(AssetType::Count);
70}
71static_assert(everyKindOrderedOnce(), "each VKM_ASSET_KINDS row needs one place in ASSET_DEPENDENCY_ORDER");
72
73} // namespace detail
74
81template<typename Asset>
82inline constexpr AssetType ASSET_TYPE = AssetType::Count;
83
84#define VKM_ASSET_TRAIT(tag, type, name, dir) \
85 template<> inline constexpr AssetType ASSET_TYPE<type> = AssetType::tag;
86VKM_ASSET_KINDS(VKM_ASSET_TRAIT)
87#undef VKM_ASSET_TRAIT
88
89} // namespace Vkm::Engine
90
91#define VKM_ASSET_NAME(tag, type, name, dir) name,
92VKM_ENUM_NAMES(::Vkm::Engine::AssetType, VKM_ASSET_KINDS(VKM_ASSET_NAME))
93#undef VKM_ASSET_NAME