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
5
#include "
../../core/Types.hpp
"
6
7
#include <algorithm>
8
#include <array>
9
#include <cmath>
10
#include <string_view>
11
12
namespace
esengine
{
13
14
enum class
QualityValue
:
u32
{
15
LoopLights
,
16
TiledLights
,
17
ShadowTiles
,
18
Count
,
19
};
20
21
struct
QualityValueSpec
{
22
QualityValue
id
;
23
const
char
*
name
;
24
f32
fallback
;
25
f32
cap
;
26
};
27
28
inline
constexpr
QualityValueSpec
QUALITY_VALUE_SPECS
[] = {
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
34
inline
constexpr
u32
QUALITY_VALUE_COUNT
=
static_cast<
u32
>
(
QualityValue::Count
);
35
36
static_assert
(std::size(
QUALITY_VALUE_SPECS
) ==
QUALITY_VALUE_COUNT
,
"one spec per QualityValue"
);
37
38
constexpr
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
}
44
static_assert
(
qualitySpecsInOrder
(),
"QUALITY_VALUE_SPECS is indexed by QualityValue"
);
45
46
constexpr
f32
qualityCap
(
QualityValue
id
) {
return
QUALITY_VALUE_SPECS
[
static_cast<
u32
>
(id)].cap; }
47
48
class
QualityValues
{
49
public
:
50
QualityValues
() {
reset
(); }
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) {
58
const
QualityValueSpec
& spec =
QUALITY_VALUE_SPECS
[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
70
private
:
71
std::array<f32, QUALITY_VALUE_COUNT> values_{};
72
};
73
74
}
// namespace esengine
Types.hpp
Core type definitions and utilities for ESEngine.
esengine::QualityValues::count
u32 count(QualityValue id) const
Definition
QualityValues.hpp:68
esengine::QualityValues::reset
void reset()
Definition
QualityValues.hpp:52
esengine::QualityValues::QualityValues
QualityValues()
Definition
QualityValues.hpp:50
esengine::QualityValues::get
f32 get(QualityValue id) const
Definition
QualityValues.hpp:66
esengine::QualityValues::set
bool set(std::string_view name, f32 value)
Definition
QualityValues.hpp:56
esengine
Definition
EasingFunctions.hpp:10
esengine::QUALITY_VALUE_COUNT
constexpr u32 QUALITY_VALUE_COUNT
Definition
QualityValues.hpp:34
esengine::QualityValue
QualityValue
Definition
QualityValues.hpp:14
esengine::QualityValue::ShadowTiles
@ ShadowTiles
Definition
QualityValues.hpp:17
esengine::QualityValue::TiledLights
@ TiledLights
Definition
QualityValues.hpp:16
esengine::QualityValue::Count
@ Count
Definition
QualityValues.hpp:18
esengine::QualityValue::LoopLights
@ LoopLights
Definition
QualityValues.hpp:15
esengine::qualitySpecsInOrder
constexpr bool qualitySpecsInOrder()
Definition
QualityValues.hpp:38
esengine::qualityCap
constexpr f32 qualityCap(QualityValue id)
Definition
QualityValues.hpp:46
esengine::BatchBreak::Count
@ Count
Definition
DrawCommand.hpp:72
esengine::QUALITY_VALUE_SPECS
constexpr QualityValueSpec QUALITY_VALUE_SPECS[]
Definition
QualityValues.hpp:28
esengine::u32
std::uint32_t u32
Unsigned 32-bit integer.
Definition
Types.hpp:45
esengine::f32
float f32
32-bit floating point
Definition
Types.hpp:59
esengine::QualityValueSpec
Definition
QualityValues.hpp:21
esengine::QualityValueSpec::name
const char * name
Definition
QualityValues.hpp:23
esengine::QualityValueSpec::id
QualityValue id
Definition
QualityValues.hpp:22
esengine::QualityValueSpec::fallback
f32 fallback
Definition
QualityValues.hpp:24
esengine::QualityValueSpec::cap
f32 cap
Definition
QualityValues.hpp:25
src
esengine
renderer
frame
QualityValues.hpp
Generated by
1.15.0