blob: 8990cd4fd1987de15dae222c16ee366702223b2f (
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
|
#include "Z2AudioLib/Z2SoundHandles.h"
#include "JSystem/JAudio2/JAISoundInfo.h"
Z2SoundHandles::Z2SoundHandles() {
handleNum_ = 0;
}
Z2SoundHandles::~Z2SoundHandles() {
deleteHandlesPool();
}
void Z2SoundHandles::initHandlesPool(u8 handleNum) {
handleNum_ = handleNum;
}
void Z2SoundHandles::deleteHandlesPool() {
JSULink<Z2SoundHandlePool>* i;
while (i = getFirst(), i != NULL) {
Z2SoundHandlePool* handle = i->getObject();
JUT_ASSERT(48, handle->getSupervisor() == this);
remove(handle);
delete handle;
}
handleNum_ = 0;
}
Z2SoundHandlePool* Z2SoundHandles::getHandleSoundID(JAISoundID soundID) {
JSULink<Z2SoundHandlePool>* i;
for (i = getFirst(); i != NULL; i = i->getNext()) {
Z2SoundHandlePool* handle = i->getObject();
if (handle->isSoundAttached()) {
if ((*handle)->getID() == soundID) {
return handle;
}
}
}
return NULL;
}
Z2SoundHandlePool* Z2SoundHandles::getHandleUserData(u32 userData) {
JSULink<Z2SoundHandlePool>* i;
for (i = getFirst(); i != NULL; i = i->getNext()) {
Z2SoundHandlePool* handle = i->getObject();
if (handle->isSoundAttached()) {
if ((*handle)->getUserData() == userData) {
return handle;
}
}
}
return NULL;
}
Z2SoundHandlePool* Z2SoundHandles::getFreeHandle() {
JSULink<Z2SoundHandlePool>* i;
for (i = getFirst(); i != NULL; i = i->getNext()) {
Z2SoundHandlePool* handle = i->getObject();
if (!handle->isSoundAttached()) {
return handle;
}
}
if (getNumHandles() < handleNum_) {
Z2SoundHandlePool* handle = new Z2SoundHandlePool();
if (handle != NULL) {
append(handle);
JUT_ASSERT(113, handle->getSupervisor() == this);
return handle;
}
JUT_WARN_DEVICE(118, 1, "%s", "cannot Alloc Handle !!\n");
}
return NULL;
}
Z2SoundHandlePool* Z2SoundHandles::getLowPrioSound(JAISoundID soundID) {
JAISoundInfo* soundInfo = JASGlobalInstance<JAISoundInfo>::getInstance();
u32 low_prio = 0xFFFF;
Z2SoundHandlePool* rethandle = NULL;
JSULink<Z2SoundHandlePool>* i;
for (i = getFirst(); i != NULL; i = i->getNext()) {
Z2SoundHandlePool* handle = i->getObject();
if (!handle->isSoundAttached()) {
return handle;
}
u32 prio = soundInfo->getPriority((*handle)->getID());
if (prio < low_prio) {
low_prio = prio;
rethandle = handle;
}
}
#if DEBUG
if (rethandle != NULL) {
JUT_ASSERT(163, rethandle->getSupervisor() == this);
}
#endif
if (soundInfo->getPriority(soundID) >= low_prio) {
return rethandle;
}
return NULL;
}
void Z2SoundHandles::stopAllSounds(u32 fadeTime) {
JSULink<Z2SoundHandlePool>* i;
for (i = getFirst(); i != NULL; i = i->getNext()) {
JAISoundHandle* handle = i->getObject();
if (handle && (*handle)) {
(*handle)->stop(fadeTime);
}
}
}
bool Z2SoundHandles::isActive() const {
for (JSULink<Z2SoundHandlePool>*i = getFirst(); i != NULL; i = i->getNext()) {
if (i->getObject()->isSoundAttached()) {
return true;
}
}
return false;
}
void Z2SoundHandles::setPos(const JGeometry::TVec3<f32>& pos) {
JSULink<Z2SoundHandlePool>* i;
for (i = getFirst(); i != NULL; i = i->getNext()) {
Z2SoundHandlePool* handle = i->getObject();
JUT_ASSERT(209, handle);
JUT_ASSERT(210, handle->getSupervisor() == this);
if (handle->isSoundAttached()) {
(*handle)->setPos(pos);
}
else {
remove(handle);
delete handle;
}
}
}
|