Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
PropAudio.h
Go to the documentation of this file.
1
#pragma once
2
#include <algorithm>
3
#include <cmath>
4
#include <cstdint>
5
6
namespace
PropAudio
{
7
struct
Input
{
8
bool
active
=
false
,
advanced
=
false
,
contact
=
false
,
sleeping
=
false
,
impact
=
false
;
9
double
speedMps
=0,
rotationSpeedMps
=0;
10
std::uint64_t
frame
=0;
11
};
12
struct
Events
{
bool
startRolling
=
false
,
stopRolling
=
false
,
hit
=
false
,
stopAll
=
false
; };
13
// Audio presentation thresholds, not physical forces or material properties.
14
// Hysteresis bridges brief contact gaps as a faceted prop rolls over its rim.
15
class
State
{
16
bool
active
=
false
,
rolling
=
false
;
17
double
quietSeconds
=0,
hitCooldown
=0;
18
std::uint64_t
lastFrame
=0;
19
public
:
20
void
Reset
() { *
this
=
State
{}; }
21
Events
Update
(
double
dt,
const
Input
& input) {
22
Events
result;
23
if
(!input.
active
|| !std::isfinite(dt) || dt<=0 || dt>.25 ||
24
!std::isfinite(input.
speedMps
) || !std::isfinite(input.
rotationSpeedMps
)) {
25
result.
stopAll
=
active
;
Reset
();
return
result;
26
}
27
active
=
true
;
28
hitCooldown
=std::max(0.0,
hitCooldown
-dt);
29
if
(input.
frame
==
lastFrame
)
return
result;
30
lastFrame
=input.
frame
;
31
if
(input.
sleeping
) {
32
result.
stopRolling
=
rolling
;
rolling
=
false
;
quietSeconds
=0;
return
result;
33
}
34
// Render frames with no physics substep must not end a rolling episode.
35
if
(!input.
advanced
)
return
result;
36
if
(input.
impact
&&
hitCooldown
<=0) {result.
hit
=
true
;
hitCooldown
=.12;}
37
const
double
rollingSpeed=std::min(input.
speedMps
,input.
rotationSpeedMps
);
38
const
bool
moving=input.
contact
&& rollingSpeed>(
rolling
?.012:.03);
39
if
(moving) {
40
quietSeconds
=0;
41
if
(!
rolling
) {
rolling
=
true
;result.
startRolling
=
true
;}
42
}
else
if
(
rolling
) {
43
quietSeconds
+=dt;
44
if
(
quietSeconds
>=.12) {
rolling
=
false
;
quietSeconds
=0;result.
stopRolling
=
true
;}
45
}
46
return
result;
47
}
48
};
49
}
PropAudio::State
Definition
PropAudio.h:15
PropAudio::State::active
bool active
Definition
PropAudio.h:16
PropAudio::State::Update
Events Update(double dt, const Input &input)
Definition
PropAudio.h:21
PropAudio::State::Reset
void Reset()
Definition
PropAudio.h:20
PropAudio::State::lastFrame
std::uint64_t lastFrame
Definition
PropAudio.h:18
PropAudio::State::rolling
bool rolling
Definition
PropAudio.h:16
PropAudio::State::hitCooldown
double hitCooldown
Definition
PropAudio.h:17
PropAudio::State::quietSeconds
double quietSeconds
Definition
PropAudio.h:17
PropAudio
Definition
PropAudio.h:6
PropAudio::Events
Definition
PropAudio.h:12
PropAudio::Events::hit
bool hit
Definition
PropAudio.h:12
PropAudio::Events::startRolling
bool startRolling
Definition
PropAudio.h:12
PropAudio::Events::stopAll
bool stopAll
Definition
PropAudio.h:12
PropAudio::Events::stopRolling
bool stopRolling
Definition
PropAudio.h:12
PropAudio::Input
Definition
PropAudio.h:7
PropAudio::Input::sleeping
bool sleeping
Definition
PropAudio.h:8
PropAudio::Input::impact
bool impact
Definition
PropAudio.h:8
PropAudio::Input::rotationSpeedMps
double rotationSpeedMps
Definition
PropAudio.h:9
PropAudio::Input::active
bool active
Definition
PropAudio.h:8
PropAudio::Input::advanced
bool advanced
Definition
PropAudio.h:8
PropAudio::Input::contact
bool contact
Definition
PropAudio.h:8
PropAudio::Input::speedMps
double speedMps
Definition
PropAudio.h:9
PropAudio::Input::frame
std::uint64_t frame
Definition
PropAudio.h:10
PropAudio.h
Generated on
for Rise by
1.18.0