Debian Codegraph @

Sources/Jazz2/Actors/Environment/AmbientSound.cpp

raw
1 #include "AmbientSound.h"
2 #include "../../ILevelHandler.h"
3 #include "../Player.h"
4
5 namespace Jazz2::Actors::Environment
6 {
7 AmbientSound::AmbientSound()
8 {
9 }
10
11 AmbientSound::~AmbientSound()
12 {
13 // TODO: Fade-out
14 if (_sound != nullptr) {
15 _sound->stop();
16 _sound = nullptr;
17 }
18 }
19
20 void AmbientSound::Preload(const ActorActivationDetails& details)
21 {
22 PreloadMetadataAsync("Common/AmbientSound"_s);
23 }
24
25 Task<bool> AmbientSound::OnActivatedAsync(const ActorActivationDetails& details)
26 {
27 // TODO: Implement Fade:1|Sine:1
28
29 _sfx = details.Params[0];
30 _gain = 0.2f * (details.Params[1] / 255.0f);
31
32 SetState(ActorState::ForceDisableCollisions, true);
33 SetState(ActorState::CanBeFrozen | ActorState::CollideWithTileset | ActorState::CollideWithSolidObjects | ActorState::CollideWithOtherActors | ActorState::ApplyGravitation, false);
34
35 async_await RequestMetadataAsync("Common/AmbientSound"_s);
36
37 switch (_sfx) {
38 case 0: _sound = PlaySfx("AmbientWind"_s, _gain); break;
39 case 1: _sound = PlaySfx("AmbientFire"_s, _gain); break;
40 case 2: _sound = PlaySfx("AmbientScienceNoise"_s, _gain); break;
41 }
42
43 // TODO: Fade-in
44 if (_sound != nullptr) {
45 _sound->setLooping(true);
46 }
47
48 async_return true;
49 }
50 }