Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
hardness.hpp
Go to the documentation of this file.
1
7
8
#pragma once
9
10
#include <array>
11
#include <cstdint>
12
#include <optional>
13
#include <string_view>
14
15
namespace
physics {
16
17
enum class
Hardness : uint8_t {
18
soft,
19
medium,
20
hard,
21
};
22
23
inline
constexpr
std::array<std::string_view, 3> k_hardness_names {
"soft"
,
"medium"
,
"hard"
};
24
25
inline
constexpr
Hardness k_hardest = Hardness::hard;
26
27
[[nodiscard]]
28
constexpr
auto
hardnessName(Hardness hardness) -> std::string_view {
29
const
auto
index =
static_cast<
size_t
>
(hardness);
30
return
index < k_hardness_names.size() ? k_hardness_names[index] : std::string_view {};
31
}
32
33
[[nodiscard]]
34
constexpr
auto
hardnessFromName(std::string_view name) -> std::optional<Hardness> {
35
for
(
size_t
i = 0; i < k_hardness_names.size(); ++i) {
36
if
(k_hardness_names[i] == name) {
37
return
static_cast<
Hardness
>
(i);
38
}
39
}
40
return
std::nullopt;
41
}
42
43
[[nodiscard]]
44
constexpr
auto
canBreak(Hardness max_hardness, Hardness material) ->
bool
{
45
return
static_cast<
uint8_t
>
(material) <=
static_cast<
uint8_t
>
(max_hardness);
46
}
47
48
}
engine
src
toast
physics
hardness.hpp
Generated by
1.17.0