vkmEngine 1.0.15
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 X(Terrain, TerrainAsset, "terrain", "terrains")
28
35#define VKM_ASSET_ENUMERATOR(tag, type, name, dir) tag,
36enum class AssetType : uint8_t {
37 VKM_ASSET_KINDS(VKM_ASSET_ENUMERATOR)
38
39 Count
40};
41#undef VKM_ASSET_ENUMERATOR
42
43#define VKM_ASSET_FORWARD_DECL(tag, type, name, dir) struct type;
44VKM_ASSET_KINDS(VKM_ASSET_FORWARD_DECL)
45#undef VKM_ASSET_FORWARD_DECL
46
54inline constexpr AssetType ASSET_DEPENDENCY_ORDER[] = {
55 AssetType::Texture,
56 AssetType::Material,
57 AssetType::Skeleton,
58 AssetType::AnimationClip,
59 AssetType::Mesh,
60 AssetType::AudioClip,
61 AssetType::Terrain,
62};
63
64namespace detail {
65
66constexpr bool everyKindOrderedOnce() {
67 for (size_t kind = 0; kind < static_cast<size_t>(AssetType::Count); ++kind) {
68 size_t seen = 0;
69 for (const AssetType type : ASSET_DEPENDENCY_ORDER) seen += static_cast<size_t>(type) == kind ? 1 : 0;
70 if (seen != 1) return false;
71 }
72 return sizeof(ASSET_DEPENDENCY_ORDER) / sizeof(AssetType) == static_cast<size_t>(AssetType::Count);
73}
74static_assert(everyKindOrderedOnce(), "each VKM_ASSET_KINDS row needs one place in ASSET_DEPENDENCY_ORDER");
75
76} // namespace detail
77
84template<typename Asset>
85inline constexpr AssetType ASSET_TYPE = AssetType::Count;
86
87#define VKM_ASSET_TRAIT(tag, type, name, dir) \
88 template<> inline constexpr AssetType ASSET_TYPE<type> = AssetType::tag;
89VKM_ASSET_KINDS(VKM_ASSET_TRAIT)
90#undef VKM_ASSET_TRAIT
91
92} // namespace Vkm::Engine
93
94#define VKM_ASSET_NAME(tag, type, name, dir) name,
95VKM_ENUM_NAMES(::Vkm::Engine::AssetType, VKM_ASSET_KINDS(VKM_ASSET_NAME))
96#undef VKM_ASSET_NAME