1#pragma once
2
3namespace PrecipitationAudioTest
4{
5using ThunderFixture::SOUNDS;
6using ThunderFixture::SOUND_PRECIP0;
7
8
9struct Mix
10{
12 struct View { Weather* ptrWeather; } view{&
weather};
14 struct Owner { View* viewscreen;
Logger* logger; } owner{&view, &logger};
15 Owner* game = &owner;
16 std::array<float, 5> gains{};
17 int warnings = 0;
19 static bool IsInvalidFloat(float value) { return !std::isfinite(value); }
20 void PlayEx(
SOUNDS sound,
bool,
float gain,
float,
float,
bool,
bool)
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;
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");
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;
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 }
79}
s_network_objects playerships[MAX_SCAN]
float Update(Component *components, std::size_t count, bool viewerInside)
bool Near(const Body &b, const Triangle &t, double extra)
Point Mix(Point a, Point b, float t)