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

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

1#pragma once
2
3#include "../Rendering/ClientMath.h"
4#include <algorithm>
5#include <array>
6#include <cstring>
7#include "HornSounds.generated.h"
8
9namespace HornFrameFixture
10{
11constexpr int MAX_SCAN = 3;
12enum class VehicleType { T27, T120, T121, Car };
13enum class GameState { STATUS_GAME, Other };
14struct Vehicle
15{
16 bool active = true, hornPressed = false, crashHornFault = false;
17 bool isSimulator = false, groundvehicle = true, visible = true;
19 char hullname[8] = {};
20 float distance = 0.f;
21 RiseMath::Vector3 position;
22 RiseMath::Matrix matrixInvOrientation;
23};
25inline bool g_bEnabled = true, dead = false;
26inline int foregroundWindow = 1;
27inline int GetForegroundWindow() { return foregroundWindow; }
28namespace Rendering { inline int ClientWindow() { return 1; } }
29inline float Clamp(float value, float low, float high) { return std::clamp(value, low, high); }
30struct Viewscreen
31{
32 void SetHornPressed(bool pressed) { VehicleHorn::SetPressed(playerships[0].hornPressed, pressed); }
33};
34struct Game
35{
36 GameState displaystage = GameState::STATUS_GAME;
37 Viewscreen* viewscreen;
38};
39constexpr int BASS_ACTIVE_PLAYING = 1;
40inline std::array<bool, SOUND_ENUMERATION> playing{};
41inline int BASS_ChannelIsActive(int stream) { return playing[stream] ? BASS_ACTIVE_PLAYING : 0; }
42struct Sound
43{
44 Game* game;
45 float headPanScalar = 0.f;
46 VehicleHorn::Playback hornPlayback[4];
47 float hornVolume[4] = {}, hornPan[4] = {};
48 bool hornAttached[4] = {};
49 int sound_stream[SOUND_ENUMERATION], sound_streamFx[SOUND_ENUMERATION];
50
51 explicit Sound(Game* owner) : game(owner)
52 {
53 for (int i = 0; i < SOUND_ENUMERATION; ++i) sound_stream[i] = sound_streamFx[i] = i;
54 }
55 void Stop(SOUNDS sound) { playing[sound] = false; }
56 void PlayEx(SOUNDS sound, bool, float, float, float, bool, bool, bool) { playing[sound] = true; }
57 void FrameMoveHorns();
58};
59#include "HornFrame.generated.h"
60
61inline void Run()
62{
63 Viewscreen view;
64 Game game{GameState::STATUS_GAME, &view};
65 Sound sound(&game);
66 for (auto& vehicle : playerships) RiseMath::MatrixIdentity(&vehicle.matrixInvOrientation);
67 auto& own = playerships[0];
68 auto& remote = playerships[1];
69 remote.distance = .1f;
70 const auto silent = [&]() { return std::none_of(playing.begin(), playing.end(), [](bool on) { return on; }); };
71 const auto reset = [&]()
72 {
73 Check(silent(), "simulator entry immediately stops every horn section without a release tail");
74 for (int kind = 0; kind < 4; ++kind)
75 Check(sound.hornPlayback[kind].phase == VehicleHorn::Phase::Idle &&
76 sound.hornVolume[kind] == 0.f && sound.hornPan[kind] == 0.f && !sound.hornAttached[kind],
77 "simulator entry clears playback and cached source mix");
78 };
79
80 for (bool crash : {false, true})
81 for (bool fromRemote : {false, true})
83 {
84 auto& source = fromRemote ? remote : own;
85 source.hornPressed = !crash;
86 source.crashHornFault = crash;
87 sound.FrameMoveHorns();
88 Check(playing[SOUND_HORNMAMMOTH_START], "manual/received and crash horns play outside the simulator");
89 Check(sound.hornAttached[1] == !fromRemote, "only our own horn receives attached-camera mixing");
90 if (phase == VehicleHorn::Phase::Loop)
91 {
92 playing[SOUND_HORNMAMMOTH_START] = false;
93 sound.FrameMoveHorns();
94 Check(playing[SOUND_HORNMAMMOTH_LOOP], "held horn advances to sustain");
95 }
96 if (phase == VehicleHorn::Phase::End)
97 {
98 source.hornPressed = source.crashHornFault = false;
99 sound.FrameMoveHorns();
100 Check(playing[SOUND_HORNMAMMOTH_END], "ordinary release plays its tail outside the simulator");
101 }
102 own.isSimulator = true;
103 sound.FrameMoveHorns();
104 reset();
105 Check(!own.hornPressed, "simulator entry clears local held input");
106 source.hornPressed = source.crashHornFault = false;
107 sound.FrameMoveHorns();
108 reset();
109 own.isSimulator = false;
110 sound.FrameMoveHorns();
111 Check(silent(), "leaving simulator cannot replay a finished horn or cached tail");
112 }
113
114 remote.isSimulator = true;
115 remote.hornPressed = remote.crashHornFault = true;
116 sound.FrameMoveHorns();
117 Check(silent(), "simulated remote vehicles cannot emit manual or crash horns");
118 remote.isSimulator = false;
119 remote.hornPressed = remote.crashHornFault = false;
120 own.hornPressed = true;
121 sound.FrameMoveHorns();
122 Check(playing[SOUND_HORNMAMMOTH_START], "new real-world input works after simulator exit");
123 foregroundWindow = 0;
124 sound.FrameMoveHorns();
125 Check(!own.hornPressed && playing[SOUND_HORNMAMMOTH_END], "focus loss still releases the real-world horn");
126}
127}
GameState
Definition GameState.h:4
@ STATUS_GAME
Definition GameState.h:9
constexpr auto Clamp(T1 val, T2 min, T3 max)
VehicleType
Definition ServerTypes.h:60
@ T120
Definition ServerTypes.h:67
@ T27
Definition ServerTypes.h:82
@ T121
Definition ServerTypes.h:89
#define MAX_SCAN
SOUNDS
Definition Sound.h:23
@ SOUND_HORNMAMMOTH_LOOP
Definition Sound.h:340
@ SOUND_HORNMAMMOTH_START
Definition Sound.h:340
@ SOUND_ENUMERATION
Definition Sound.h:344
@ SOUND_HORNMAMMOTH_END
Definition Sound.h:340
Sound(GameClass *gameptr)
Definition Sound.cpp:69
DeathType dead
Definition globals.cpp:37
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
bool g_bEnabled
Definition globals.cpp:96
HWND ClientWindow()
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
Command SetPressed(bool &current, bool pressed)
Definition VehicleHorn.h:10
@ Game
Use the game audio system.
Definition discordpp.h:505