blob: 7f0b1d5a29c2378d5c36dbb4578283b72317104e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#include "nw4r/snd/snd_ExternalSoundPlayer.h"
/* Original source:
* kiwi515/ogws
* src/nw4r/snd/snd_ExternalSoundPlayer.cpp
*/
/*******************************************************************************
* headers
*/
#include <decomp.h>
#include "common.h" // nullptr
#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_SoundThread.h"
#include "nw4r/NW4RAssert.hpp"
#include "nw4r/snd/snd_global.h"
/*******************************************************************************
* types
*/
// forward declarations
namespace nw4r { namespace ut { struct LinkListNode; }}
/*******************************************************************************
* functions
*/
namespace nw4r { namespace snd { namespace detail {
ExternalSoundPlayer::ExternalSoundPlayer() : mPlayableCount(1) {}
ExternalSoundPlayer::~ExternalSoundPlayer() {
NW4R_RANGE_FOR_NO_AUTO_INC(it, mSoundList)
{
decltype(it) curItr = it++;
curItr->DetachExternalSoundPlayer(this);
}
}
#if 0
// not sure which one uses this exactly, maybe StopAllSound?
DECOMP_FORCE_CLASS_METHOD(
BasicSound::ExtSoundPlayerPlayLinkList,
GetPointerFromNode(static_cast<ut::LinkListNode *>(nullptr)));
#endif
void ExternalSoundPlayer::StopAllSound(int fadeFrames)
{
NW4R_RANGE_FOR_NO_AUTO_INC(it, mSoundList)
{
it++->Stop(fadeFrames);
}
}
void ExternalSoundPlayer::PauseAllSound(bool flag, int fadeFrames)
{
NW4R_RANGE_FOR_NO_AUTO_INC(it, mSoundList)
{
it++->Pause(flag, fadeFrames);
}
}
void ExternalSoundPlayer::DetachSoundActorAll(SoundActor *sound)
{
NW4R_RANGE_FOR_NO_AUTO_INC(it, mSoundList)
{
it++->DetachSoundActor(sound);
}
}
bool ExternalSoundPlayer::AppendSound(BasicSound *sound)
{
NW4RAssertPointerNonnull_Line(129, sound);
SoundThread::AutoLock lock;
int allocPriority = sound->CalcCurrentPlayerPriority();
if (GetPlayableSoundCount() == 0)
return false;
while (GetPlayingSoundCount() >= GetPlayableSoundCount())
{
BasicSound *dropSound = GetLowestPrioritySound();
if (!dropSound)
return false;
if (allocPriority < dropSound->CalcCurrentPlayerPriority())
return false;
dropSound->Shutdown();
}
mSoundList.PushBack(sound);
sound->AttachExternalSoundPlayer(this);
return true;
}
void ExternalSoundPlayer::SetPlayableSoundCount(int count) {
mPlayableCount = count;
while (GetPlayingSoundCount() > GetPlayableSoundCount()) {
GetLowestPrioritySound()->Shutdown();
}
}
void ExternalSoundPlayer::RemoveSound(BasicSound *sound)
{
mSoundList.Erase(sound);
sound->DetachExternalSoundPlayer(this);
}
bool ExternalSoundPlayer::detail_CanPlaySound(int startPriority)
{
if (GetPlayableSoundCount() == 0)
return false;
if (GetPlayingSoundCount() >= GetPlayableSoundCount())
{
BasicSound *dropSound = GetLowestPrioritySound();
if (!dropSound)
return false;
if (startPriority < dropSound->CalcCurrentPlayerPriority())
return false;
}
return true;
}
BasicSound *ExternalSoundPlayer::GetLowestPrioritySound()
{
int priority = 128;
BasicSound *sound = nullptr;
NW4R_RANGE_FOR(itr, mSoundList)
{
int itrPriority = itr->CalcCurrentPlayerPriority();
if (priority > itrPriority)
{
sound = &(*itr);
priority = itrPriority;
}
}
return sound;
}
}}} // namespace nw4r::snd::detail
|