MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
matrix::anonymous_namespace{rain.cpp} Namespace Reference

Functions

bool acquire_ttf ()
std::function< SDL_Color()> make_tinted_head_color (SDL_Color base_color)
std::function< SDL_Color(int)> make_tinted_level_color (SDL_Color base_color)
std::optional< SDL_Color > parse_color_spec (const std::string &spec)
std::optional< Uint8 > parse_u8_component (const std::string &value, int base)
void release_ttf ()
std::string trim_copy (const std::string &value)

Variables

constexpr int default_surface_height = 720
constexpr int default_surface_width = 1280
std::mutex ttf_mutex
std::size_t ttf_refcount = 0

Function Documentation

◆ acquire_ttf()

bool matrix::anonymous_namespace{rain.cpp}::acquire_ttf ( )

Definition at line 19 of file rain.cpp.

19 {
20 std::lock_guard<std::mutex> lock(ttf_mutex);
21 if (ttf_refcount == 0 && !TTF_Init()) {
22 return false;
23 }
25 return true;
26 }

◆ make_tinted_head_color()

std::function< SDL_Color()> matrix::anonymous_namespace{rain.cpp}::make_tinted_head_color ( SDL_Color base_color)

Definition at line 109 of file rain.cpp.

109 {
110 return [base_color]() {
111 return SDL_Color{base_color.r, base_color.g, base_color.b, 255};
112 };
113 }

◆ make_tinted_level_color()

std::function< SDL_Color(int)> matrix::anonymous_namespace{rain.cpp}::make_tinted_level_color ( SDL_Color base_color)

Definition at line 97 of file rain.cpp.

97 {
98 return [base_color](int level) {
99 constexpr int max_level = 7;
100 const float t = std::clamp(static_cast<float>(level) / static_cast<float>(max_level), 0.0f, 1.0f);
101 const Uint8 r = static_cast<Uint8>(std::lerp(0.0f, static_cast<float>(base_color.r), std::pow(t, 1.0f)));
102 const Uint8 g = static_cast<Uint8>(std::lerp(0.0f, static_cast<float>(base_color.g), std::pow(t, 1.0f)));
103 const Uint8 b = static_cast<Uint8>(std::lerp(0.0f, static_cast<float>(base_color.b), std::pow(t, 1.0f)));
104 const Uint8 a = static_cast<Uint8>(std::lerp(95.0f, 235.0f, t));
105 return SDL_Color{r, g, b, a};
106 };
107 }

◆ parse_color_spec()

std::optional< SDL_Color > matrix::anonymous_namespace{rain.cpp}::parse_color_spec ( const std::string & spec)

Definition at line 60 of file rain.cpp.

60 {
61 const std::string value = trim_copy(spec);
62 if (value.empty()) {
63 return std::nullopt;
64 }
65
66 if (value.front() == '#') {
67 if (value.size() != 7) {
68 return std::nullopt;
69 }
70 const auto r = parse_u8_component(value.substr(1, 2), 16);
71 const auto g = parse_u8_component(value.substr(3, 2), 16);
72 const auto b = parse_u8_component(value.substr(5, 2), 16);
73 if (!r || !g || !b) {
74 return std::nullopt;
75 }
76 return SDL_Color{*r, *g, *b, 255};
77 }
78
79 const std::size_t first = value.find(',');
80 if (first == std::string::npos) {
81 return std::nullopt;
82 }
83 const std::size_t second = value.find(',', first + 1);
84 if (second == std::string::npos || value.find(',', second + 1) != std::string::npos) {
85 return std::nullopt;
86 }
87
88 const auto r = parse_u8_component(value.substr(0, first), 10);
89 const auto g = parse_u8_component(value.substr(first + 1, second - first - 1), 10);
90 const auto b = parse_u8_component(value.substr(second + 1), 10);
91 if (!r || !g || !b) {
92 return std::nullopt;
93 }
94 return SDL_Color{*r, *g, *b, 255};
95 }
std::optional< Uint8 > parse_u8_component(const std::string &value, int base)
Definition rain.cpp:48
std::string trim_copy(const std::string &value)
Definition rain.cpp:39

◆ parse_u8_component()

std::optional< Uint8 > matrix::anonymous_namespace{rain.cpp}::parse_u8_component ( const std::string & value,
int base )

Definition at line 48 of file rain.cpp.

48 {
49 int parsed = 0;
50 const std::string trimmed = trim_copy(value);
51 const char *begin = trimmed.data();
52 const char *end = trimmed.data() + trimmed.size();
53 const std::from_chars_result result = std::from_chars(begin, end, parsed, base);
54 if (result.ec != std::errc{} || result.ptr != end || parsed < 0 || parsed > 255) {
55 return std::nullopt;
56 }
57 return static_cast<Uint8>(parsed);
58 }

◆ release_ttf()

void matrix::anonymous_namespace{rain.cpp}::release_ttf ( )

Definition at line 28 of file rain.cpp.

28 {
29 std::lock_guard<std::mutex> lock(ttf_mutex);
30 if (ttf_refcount == 0) {
31 return;
32 }
34 if (ttf_refcount == 0) {
35 TTF_Quit();
36 }
37 }

◆ trim_copy()

std::string matrix::anonymous_namespace{rain.cpp}::trim_copy ( const std::string & value)

Definition at line 39 of file rain.cpp.

39 {
40 const auto begin = value.find_first_not_of(" \t\r\n");
41 if (begin == std::string::npos) {
42 return {};
43 }
44 const auto end = value.find_last_not_of(" \t\r\n");
45 return value.substr(begin, end - begin + 1);
46 }

Variable Documentation

◆ default_surface_height

int matrix::anonymous_namespace{rain.cpp}::default_surface_height = 720
constexpr

Definition at line 14 of file rain.cpp.

◆ default_surface_width

int matrix::anonymous_namespace{rain.cpp}::default_surface_width = 1280
constexpr

Definition at line 13 of file rain.cpp.

◆ ttf_mutex

std::mutex matrix::anonymous_namespace{rain.cpp}::ttf_mutex

Definition at line 16 of file rain.cpp.

◆ ttf_refcount

std::size_t matrix::anonymous_namespace{rain.cpp}::ttf_refcount = 0

Definition at line 17 of file rain.cpp.