le2d v0.4.8
2D game engine framework
 
Loading...
Searching...
No Matches
vsync.hpp
Go to the documentation of this file.
1#pragma once
2#include <klib/enum_array.hpp>
3#include <cstdint>
4#include <optional>
5#include <string_view>
6
7namespace le {
8enum class Vsync : std::int8_t { Strict, Adaptive, MultiBuffer, Off, COUNT_ };
9
10inline constexpr auto vsync_str_v = klib::EnumArray<Vsync, std::string_view>{"strict", "adaptive", "multi", "off"};
11
12[[nodiscard]] constexpr auto parse_vsync(std::string_view const in) -> std::optional<Vsync> {
13 if (in.size() == 1 && in.front() >= '0') {
14 auto const ret = Vsync(in.front() - '0');
15 if (ret < Vsync::COUNT_) { return ret; }
16 }
17 for (auto v = Vsync{}; v < Vsync::COUNT_; v = Vsync(int(v) + 1)) {
18 if (vsync_str_v[v] == in) { return v; }
19 }
20 return {};
21}
22} // namespace le
Definition animation.hpp:8
Vsync
Definition vsync.hpp:8
constexpr auto vsync_str_v
Definition vsync.hpp:10
constexpr auto parse_vsync(std::string_view const in) -> std::optional< Vsync >
Definition vsync.hpp:12