group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
SurfaceType.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <cstdint>
14#include <string_view>
15
27enum class SurfaceType : uint8_t
28{
29 Metal = 0,
31 Flesh = 2,
32 Wood = 3,
33 Energy = 4,
34 Count = 5,
35};
36
42[[nodiscard]] constexpr SurfaceType surfaceTypeFromMaterialName(std::string_view name) noexcept
43{
44 constexpr auto k_eqIgnoreCase = [](std::string_view a, std::string_view b) constexpr noexcept {
45 if (a.size() != b.size())
46 return false;
47 for (size_t i = 0; i < a.size(); ++i) {
48 const char ca = a[i] >= 'A' && a[i] <= 'Z' ? static_cast<char>(a[i] + 32) : a[i];
49 const char cb = b[i] >= 'A' && b[i] <= 'Z' ? static_cast<char>(b[i] + 32) : b[i];
50 if (ca != cb)
51 return false;
52 }
53 return true;
54 };
55
56 // Strip optional `mat_` prefix.
57 if (name.size() >= 4) {
58 const std::string_view prefix = name.substr(0, 4);
59 if (k_eqIgnoreCase(prefix, "mat_"))
60 name = name.substr(4);
61 }
62
63 if (k_eqIgnoreCase(name, "metal"))
64 return SurfaceType::Metal;
65 if (k_eqIgnoreCase(name, "concrete"))
67 if (k_eqIgnoreCase(name, "flesh"))
68 return SurfaceType::Flesh;
69 if (k_eqIgnoreCase(name, "wood"))
70 return SurfaceType::Wood;
71 if (k_eqIgnoreCase(name, "energy"))
74}
75
77[[nodiscard]] constexpr std::string_view surfaceTypeName(SurfaceType s) noexcept
78{
79 switch (s) {
80 case SurfaceType::Metal: return "Metal";
81 case SurfaceType::Concrete: return "Concrete";
82 case SurfaceType::Flesh: return "Flesh";
83 case SurfaceType::Wood: return "Wood";
84 case SurfaceType::Energy: return "Energy";
85 case SurfaceType::Count: break;
86 }
87 return "?";
88}
SurfaceType
Surface material hit by a projectile / hitscan / contact.
Definition SurfaceType.hpp:28
@ Energy
Definition SurfaceType.hpp:33
@ Wood
Definition SurfaceType.hpp:32
@ Flesh
Definition SurfaceType.hpp:31
@ Concrete
Definition SurfaceType.hpp:30
@ Count
Definition SurfaceType.hpp:34
@ Metal
Definition SurfaceType.hpp:29
constexpr SurfaceType surfaceTypeFromMaterialName(std::string_view name) noexcept
Parse a Blender material name into a SurfaceType.
Definition SurfaceType.hpp:42
constexpr std::string_view surfaceTypeName(SurfaceType s) noexcept
Display name for a SurfaceType. Used in debug UI / logging.
Definition SurfaceType.hpp:77