Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
QualityValues.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
6
7#include <algorithm>
8#include <array>
9#include <cmath>
10#include <string_view>
11
12namespace esengine {
13
20
27
29 {QualityValue::LoopLights, "loopLights", 16.0f, 16.0f},
30 {QualityValue::TiledLights, "tiledLights", 96.0f, 96.0f},
31 {QualityValue::ShadowTiles, "shadowTiles", 16.0f, 16.0f},
32};
33
34inline constexpr u32 QUALITY_VALUE_COUNT = static_cast<u32>(QualityValue::Count);
35
36static_assert(std::size(QUALITY_VALUE_SPECS) == QUALITY_VALUE_COUNT, "one spec per QualityValue");
37
38constexpr bool qualitySpecsInOrder() {
39 for (u32 i = 0; i < QUALITY_VALUE_COUNT; ++i) {
40 if (static_cast<u32>(QUALITY_VALUE_SPECS[i].id) != i) return false;
41 }
42 return true;
43}
44static_assert(qualitySpecsInOrder(), "QUALITY_VALUE_SPECS is indexed by QualityValue");
45
46constexpr f32 qualityCap(QualityValue id) { return QUALITY_VALUE_SPECS[static_cast<u32>(id)].cap; }
47
49public:
51
52 void reset() {
53 for (u32 i = 0; i < QUALITY_VALUE_COUNT; ++i) values_[i] = QUALITY_VALUE_SPECS[i].fallback;
54 }
55
56 bool set(std::string_view name, f32 value) {
57 for (u32 i = 0; i < QUALITY_VALUE_COUNT; ++i) {
59 if (name != spec.name) continue;
60 values_[i] = std::isfinite(value) ? std::clamp(value, 0.0f, spec.cap) : spec.fallback;
61 return true;
62 }
63 return false;
64 }
65
66 f32 get(QualityValue id) const { return values_[static_cast<u32>(id)]; }
67
68 u32 count(QualityValue id) const { return static_cast<u32>(std::lround(get(id))); }
69
70private:
71 std::array<f32, QUALITY_VALUE_COUNT> values_{};
72};
73
74} // namespace esengine
Core type definitions and utilities for ESEngine.
u32 count(QualityValue id) const
f32 get(QualityValue id) const
bool set(std::string_view name, f32 value)
constexpr u32 QUALITY_VALUE_COUNT
constexpr bool qualitySpecsInOrder()
constexpr f32 qualityCap(QualityValue id)
constexpr QualityValueSpec QUALITY_VALUE_SPECS[]
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
float f32
32-bit floating point
Definition Types.hpp:59