Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
WindshieldWipers.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <algorithm>
4
#include <cmath>
5
6
// Event 29 and vehicle metadata bit 10 carry an on/off command. Every vehicle
7
// advances its own phase at the same fixed rate; OFF returns the blades to park.
8
namespace
WindshieldWipers
9
{
10
// DIX translations are kilometres. Use the same one-millimetre minimum for
11
// rain clearing and audio; comparing squared travel to 1e-6 requires a metre.
12
inline
bool
HasBladeMotion
(
int
type,
unsigned
primitives,
float
axisLengthSq,
13
float
hingeExtent,
float
travelLengthSq)
14
{
15
constexpr
float
minTravelKm = .000001f;
16
return
type == 47 && primitives > 0
17
&& ((axisLengthSq > .000001f && std::fabs(hingeExtent) > .000001f)
18
|| travelLengthSq > minTravelKm * minTravelKm);
19
}
20
21
// Local keybind/crash requests send an event only when the switch changes.
22
// Received events and metadata assign the switch directly, without an echo.
23
inline
bool
SetEnabled
(
bool
& current,
bool
enabled)
24
{
25
if
(current == enabled)
return
false
;
26
current = enabled;
27
return
true
;
28
}
29
30
struct
Motion
31
{
32
float
phase
= 0.f;
33
static
constexpr
float
rate
= 1.2f;
// Complete out-and-back cycles per second.
34
bool
moving
=
false
;
35
36
void
Update
(
float
elapsed,
bool
enabled,
bool
powered =
true
)
37
{
38
moving
=
false
;
39
if
(!powered || !std::isfinite(elapsed) || elapsed <= 0.f)
return
;
40
if
(!enabled &&
phase
== 0.f)
return
;
41
phase
+= (std::min)(elapsed, .25f) *
rate
;
42
if
(
phase
>= 1.f)
43
phase
= enabled ?
phase
- std::floor(
phase
) : 0.f;
44
moving
= enabled ||
phase
!= 0.f;
45
}
46
};
47
}
WindshieldWipers
Definition
WindshieldWipers.h:9
WindshieldWipers::SetEnabled
bool SetEnabled(bool ¤t, bool enabled)
Definition
WindshieldWipers.h:23
WindshieldWipers::HasBladeMotion
bool HasBladeMotion(int type, unsigned primitives, float axisLengthSq, float hingeExtent, float travelLengthSq)
Definition
WindshieldWipers.h:12
WindshieldWipers::Motion
Definition
WindshieldWipers.h:31
WindshieldWipers::Motion::moving
bool moving
Definition
WindshieldWipers.h:34
WindshieldWipers::Motion::rate
static constexpr float rate
Definition
WindshieldWipers.h:33
WindshieldWipers::Motion::phase
float phase
Definition
WindshieldWipers.h:32
WindshieldWipers::Motion::Update
void Update(float elapsed, bool enabled, bool powered=true)
Definition
WindshieldWipers.h:36
Viewscreen
WindshieldWipers.h
Generated on
for Rise by
1.18.0