Toast Engine
Loading...
Searching...
No Matches
voxel_palette.hpp
Go to the documentation of this file.
1
6
7#pragma once
8#include <array>
9#include <cstdint>
10#include <memory>
11#include <string>
12#include <string_view>
15#include <vector>
16
17namespace assets {
18
19class PhysicsMaterial;
21
22inline constexpr uint32_t k_palette_material_slots = voxel::k_max_physical_materials;
23
25 std::string name;
26
27 uint64_t physics_uid = 0;
28 uint64_t destruction_uid = 0;
29
30 uint64_t impact_sound = 0;
31 std::array<uint8_t, 3> dust_colour {128, 128, 128};
32 std::string tag;
33
34 [[nodiscard]]
35 auto operator==(const VoxelMaterialSlot&) const -> bool = default;
36};
37
38using VoxelMaterialSlots = std::array<VoxelMaterialSlot, k_palette_material_slots>;
39
40class TOAST_API VoxelPalette : public Asset, public ISaveable {
41public:
42 VoxelPalette(voxel::Palette palette, VoxelMaterialSlots slots, std::vector<uint8_t> defaulted);
43
45 [[nodiscard]]
46 static auto fromToml(const toml::table& table) -> std::unique_ptr<VoxelPalette>;
47
48 void reload(const toml::table& table);
49
50 [[nodiscard]]
51 auto type() const -> std::string_view override {
52 return "voxel_palette";
53 }
54
55 [[nodiscard]]
56 auto serialize(SaveMode mode) const -> std::vector<uint8_t> override;
57
58 [[nodiscard]]
59 auto palette() const noexcept -> const voxel::Palette& {
60 return m_palette;
61 }
62
63 [[nodiscard]]
64 auto slots() const noexcept -> const VoxelMaterialSlots& {
65 return m_slots;
66 }
67
68 [[nodiscard]]
69 auto materialLibrary() const -> const voxel::MaterialLibrary&;
70
72 [[nodiscard]]
73 auto defaultedEntries() const noexcept -> const std::vector<uint8_t>& {
74 return m_defaulted;
75 }
76
77private:
78 struct Parsed {
79 voxel::Palette palette;
80 VoxelMaterialSlots slots;
81 std::vector<uint8_t> defaulted;
82 };
83
84 [[nodiscard]]
85 static auto parseToml(const toml::table& table) -> Parsed;
86
87 voxel::Palette m_palette;
88 VoxelMaterialSlots m_slots;
89 std::vector<uint8_t> m_defaulted;
90
91 mutable voxel::MaterialLibrary m_library;
92 mutable std::array<Handle<PhysicsMaterial>, k_palette_material_slots> m_physics;
93 mutable std::array<Handle<DestructionMaterial>, k_palette_material_slots> m_destruction;
94};
95
96}
Definition destruction_material.hpp:18
Inherit from this class to allow an asset to be saved.
Definition core_types.hpp:33
Definition physics_material.hpp:14
static auto fromToml(const toml::table &table) -> std::unique_ptr< VoxelPalette >
Throws on values an entry cannot hold and leaves material existence to validatePalette.
Definition voxel_palette.cpp:80
auto defaultedEntries() const noexcept -> const std::vector< uint8_t > &
Round tripped so the warning survives a save.
Definition voxel_palette.hpp:73
Base types for the asset system.
SaveMode
Definition core_types.hpp:25
Definition voxel_palette.hpp:24
Definition palette.hpp:143
Entry 0 is the empty voxel and must stay all zero.
Definition palette.hpp:59