Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
BiometerState.h
Go to the documentation of this file.
1
#pragma once
2
#include <cmath>
3
4
namespace
BiometerState
5
{
6
inline
float
VerticalGMultiplier
(
float
verticalG)
7
{
8
// Keep corrupt inputs visible to diagnostics and the integration guard.
9
if
(!std::isfinite(verticalG))
return
verticalG;
10
if
(verticalG >= 1.f)
return
expf(.2f * (verticalG - 1.f));
11
if
(verticalG > 0.f)
return
1.05f;
// Existing microgravity approximation.
12
13
// Negative vertical G can slow the heart; taking fabs would reverse it.
14
// Preserve the existing 5%/G approximation through -3 G, then saturate.
15
// NASA HIDH table 6.5-5 describes bradycardia at -2 to -3 Gz; beyond
16
// that range this cap is a game-model guard, not a survivability model.
17
// See docs/Biometer.md. The bus uses standard G (9.80665 m/s^2).
18
const
float
boundedG = verticalG < -3.f ? -3.f : verticalG;
19
return
1.f + .05f * boundedG;
20
}
21
22
inline
float
Maximum
(
float
maximum)
23
{
24
// Fallback only for an uninitialized/corrupt game-character maximum.
25
return
std::isfinite(maximum) && maximum > 0 ? maximum : 180.f;
26
}
27
28
struct
Step
{
float
start
,
value
; };
29
30
inline
Step
Advance
(
float
previous,
float
target,
float
baseline,
float
maximum,
31
float
dt,
bool
dead
,
float
wakeFactor)
32
{
33
if
(
dead
)
return
{0, 0};
34
const
float
limit =
Maximum
(maximum);
35
const
float
rest = std::isfinite(baseline) && baseline > 0 ?
36
(baseline < limit ? baseline : limit) : (70.f < limit ? 70.f : limit);
37
const
bool
validTarget = std::isfinite(target) && target > 0;
38
const
float
boundedTarget = validTarget ? (target < limit ? target : limit) : rest;
39
float
start = std::isfinite(previous) && previous > 0 ?
40
(previous < limit ? previous : limit) : rest;
41
if
(previous == 0 && validTarget)
42
{
43
const
float
factor = std::isfinite(wakeFactor) && wakeFactor >= .7f && wakeFactor <= .9f ? wakeFactor : .8f;
44
start = boundedTarget * factor;
45
}
46
// Terrain/reposition impulses can produce negative or infinite targets.
47
// Preserve the last valid state; keep the raw target in diagnostics.
48
if
(!validTarget || !std::isfinite(dt) || dt <= 0)
return
{start, start};
49
const
float
duration = boundedTarget > start ? 5.f : 20.f;
50
const
float
blend = dt < duration ? dt / duration : 1.f;
51
const
float
value = start + (boundedTarget - start) * blend;
52
return
{start, value < limit ? value : limit};
53
}
54
55
inline
float
Effort
(
float
current,
float
baseline,
float
maximum)
56
{
57
if
(!std::isfinite(current) || !std::isfinite(baseline) || !std::isfinite(maximum) || maximum <= baseline)
58
return
0;
59
const
double
ratio = (double(current) - baseline) / (
double
(maximum) - baseline);
60
return
ratio > 1 ? 1.f : ratio > 0 ? float(ratio) : 0.f;
61
}
62
63
inline
float
AdvanceFrame
(
float
frame,
float
dt,
float
bpm,
unsigned
frameCount)
64
{
65
if
(!frameCount)
return
0;
66
double
phase = std::isfinite(frame) && frame >= 0 ? frame : 0;
67
if
(std::isfinite(dt) && dt > 0 && std::isfinite(bpm) && bpm > 0)
68
phase += double(dt) * bpm / 60.0 * frameCount;
69
const
float
wrapped = float(std::fmod(phase,
double
(frameCount)));
70
// A rounded float immediately below frameCount can become frameCount.
71
return
wrapped < frameCount ? wrapped : 0;
72
}
73
}
dead
DeathType dead
Definition
globals.cpp:37
BiometerState
Definition
BiometerState.h:5
BiometerState::Maximum
float Maximum(float maximum)
Definition
BiometerState.h:22
BiometerState::Effort
float Effort(float current, float baseline, float maximum)
Definition
BiometerState.h:55
BiometerState::Advance
Step Advance(float previous, float target, float baseline, float maximum, float dt, bool dead, float wakeFactor)
Definition
BiometerState.h:30
BiometerState::VerticalGMultiplier
float VerticalGMultiplier(float verticalG)
Definition
BiometerState.h:6
BiometerState::AdvanceFrame
float AdvanceFrame(float frame, float dt, float bpm, unsigned frameCount)
Definition
BiometerState.h:63
BiometerState::Step
Definition
BiometerState.h:28
BiometerState::Step::start
float start
Definition
BiometerState.h:28
BiometerState::Step::value
float value
Definition
BiometerState.h:28
Viewscreen
BiometerState.h
Generated on
for Rise by
1.18.0