载入中...
搜索中...
未找到
UnderwaterAudio.cpp
浏览该文件的文档.
2
3#include "audio/Source.h"
4
5#include <cmath>
6
7namespace eve::audio {
8
9Result<void> applyUnderwaterAudio(Source* submergeDown, Source* submergeUp, Source* ambience,
10 bool playDown, bool playUp, bool loopAmbience, float volume) {
11 if (!ambience || !std::isfinite(volume) || volume < 0.f || volume > 1.f)
14 "audio.underwater: ambience and normalized finite volume required"));
15
16 if (submergeDown) submergeDown->setVolume(volume);
17 if (submergeUp) submergeUp->setVolume(volume);
18 ambience->setVolume(volume);
19 ambience->setLooping(true);
20 if (playDown && submergeDown) submergeDown->play();
21 if (playUp && submergeUp) submergeUp->play();
22 if (loopAmbience) {
23 if (!ambience->isPlaying()) ambience->play();
24 } else if (ambience->isPlaying()) {
25 ambience->stop();
26 }
27 return Result<void>::success();
28}
29
30} // namespace eve::audio
double volume
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
A playable audio source (static buffer or streaming decoder). Not thread-safe for playback control ex...
Definition Source.h:30
void play()
Starts (or resumes) playback.
Definition Source.cpp:120
void setVolume(float v)
Sets source gain (clamped to >= 0).
Definition Source.cpp:181
bool isPlaying() const
True when playing.
Definition Source.cpp:175
void stop()
Stops playback and rewinds the play position.
Definition Source.cpp:140
void setLooping(bool l)
Enables/disables looping.
Definition Source.cpp:193
Result< void > applyUnderwaterAudio(Source *submergeDown, Source *submergeUp, Source *ambience, bool playDown, bool playUp, bool loopAmbience, float volume)
Apply one Pcg underwater audio transition to caller-owned sources.