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{
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;
23};
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{
33};
35{
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{
45 float headPanScalar = 0.f;
46 VehicleHorn::Playback hornPlayback[4];
47 float hornVolume[4] = {}, hornPan[4] = {};
48 bool hornAttached[4] = {};
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;
65 Sound sound(&game);
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)
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();
89 Check(sound.hornAttached[1] == !fromRemote, "only our own horn receives attached-camera mixing");
91 {
93 sound.FrameMoveHorns();
95 }
97 {
98 source.hornPressed = source.crashHornFault = false;
99 sound.FrameMoveHorns();
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();
123 foregroundWindow = 0;
124 sound.FrameMoveHorns();
125 Check(!own.hornPressed && playing[
SOUND_HORNMAMMOTH_END],
"focus loss still releases the real-world horn");
126}
127}
constexpr auto Clamp(T1 val, T2 min, T3 max)
@ SOUND_HORNMAMMOTH_START
Sound(GameClass *gameptr)
s_network_objects playerships[MAX_SCAN]
Matrix * MatrixIdentity(Matrix *out)
Command SetPressed(bool ¤t, bool pressed)
@ Game
Use the game audio system.