Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/PrecipitationAudioTests.h

Source at documentation-generation time. See Test catalog for fixture associations.

1#pragma once
2
3namespace PrecipitationAudioTest
4{
5using ThunderFixture::SOUNDS;
6using ThunderFixture::SOUND_PRECIP0;
7// Compile the production mix against the real weather getter, recording its
8// channel commands so transitions must stop previously playing rain loops.
9struct Mix
10{
11 Weather weather;
12 struct View { Weather* ptrWeather; } view{&weather};
13 Logger logger;
14 struct Owner { View* viewscreen; Logger* logger; } owner{&view, &logger};
15 Owner* game = &owner;
16 std::array<float, 5> gains{};
17 int warnings = 0;
18 void Trace(const char*, Logger::Level) { ++warnings; }
19 static bool IsInvalidFloat(float value) { return !std::isfinite(value); }
20 void PlayEx(SOUNDS sound, bool, float gain, float, float, bool, bool)
21 { gains[sound - SOUND_PRECIP0] = gain; }
22 void Stop(SOUNDS sound) { gains[sound - SOUND_PRECIP0] = 0; }
23 float Update(float percentVelocity)
24 {
25 float volume = 0, freq = 1, pan = 0;
26#include "PrecipitationAudio.generated.h"
27 float total = 0;
28 for (float gain : gains) {
29 Check(std::isfinite(gain) && gain >= 0, "rain mix produced invalid gain");
30 total += gain;
31 }
32 return total;
33 }
34};
35}
36
37static void PrecipitationAudioTests()
38{
39 using namespace PrecipitationAudioTest;
40 const bool wasSimulator = playerships[0].isSimulator, wasAbove = g_bAboveClouds;
41 playerships[0].isSimulator = false; g_bAboveClouds = false;
42 Mix mix;
43 for (float speed : {0.f, .5f, 1.f}) {
44 mix.weather.smoothPrecip = 16;
45 Check(mix.Update(speed) > 0, "heavy rain did not activate audio");
46 for (float dry : {3.f, 2.7f, 2.f}) {
47 mix.weather.smoothPrecip = dry;
48 Check(mix.Update(speed) == 0, "rain audio continued at or below 3");
49 }
50 float previous = 0;
51 for (int step = 1; step <= 130; ++step) {
52 mix.weather.smoothPrecip = 3.f + step * .1f;
53 const float current = mix.Update(speed);
54 Check(current > previous, "3-to-16 rain gain did not increase smoothly");
55 previous = current;
56 }
57 Check(Near(previous, .6f + .4f * speed), "maximum rain gain changed");
58 }
59 mix.weather.smoothPrecip = 6.25f;
60 mix.Update(0);
61 Check(Near(mix.gains[1], .3f) && mix.gains[0] == 0 && mix.gains[2] == 0,
62 "rain sample crossfade did not move to the 3-to-16 range");
63 Check(mix.warnings == 0, "normal dry weather generated a precipitation warning");
64
65 {
66 mix.weather.smoothPrecip = 16;
67 Check(mix.Update(1) == 1, "rain audio failed outside simulator");
68 playerships[0].isSimulator = true;
69 Check(mix.Update(1) == 0, "simulator entry retained rain loops");
70 mix.weather.precipOverride = 16;
71 Check(mix.Update(1) == 0, "diagnostic rain override activated simulator audio");
72 mix.weather.smoothPrecip = 2.7f;
73 playerships[0].isSimulator = false;
74 Check(mix.Update(1) == 0, "simulator exit replayed stale rain audio");
75 mix.weather.smoothPrecip = 16;
76 Check(mix.Update(1) == 1, "current rain did not resume after simulator exit");
77 }
78 playerships[0].isSimulator = wasSimulator; g_bAboveClouds = wasAbove;
79}
SOUNDS
Definition Sound.h:23
@ SOUND_PRECIP0
Definition Sound.h:137
Level
Definition Logger.h:23
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
bool g_bAboveClouds
Definition globals.cpp:16
float Update(Component *components, std::size_t count, bool viewerInside)
bool Near(const Body &b, const Triangle &t, double extra)
Definition RigidProp.h:141
Point Mix(Point a, Point b, float t)