Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
SoundInstanceManager.h
Go to the documentation of this file.
1#ifndef NW4HBM_SND_SOUND_INSTANCE_MANAGER_H
2#define NW4HBM_SND_SOUND_INSTANCE_MANAGER_H
3
4#include <new>
5
6#include <revolution/types.h>
7
8#include "InstancePool.h"
9
10#include "../ut/Lock.h"
11#include "../ut/inlines.h"
12
13#include <revolution/os.h>
14
15#include "../db/assert.h"
16
17namespace nw4hbm {
18 namespace snd {
19 namespace detail {
20
21 template <typename T>
22 class SoundInstanceManager {
23 public:
25 NW4HBM_ASSERT_CHECK_NULL(59, buffer);
26 return mPool.Create(buffer, size);
27 }
28
29 void Destroy(void* buffer, u32 size) {
30 NW4HBM_ASSERT_CHECK_NULL(76, buffer);
31 mPool.Destroy(buffer, size);
32 }
33
34 T* Alloc(int priority) {
35 NW4R_ASSERT_MINMAXLT(92, priority, 0, 127);
37 T* sound;
38
39 void* ptr = mPool.Alloc();
40
41 if (ptr != NULL) {
42 sound = new (ptr) T(this);
43 } else {
44 if (mPriorityList.IsEmpty()) {
45 return NULL;
46 }
47 sound = &mPriorityList.GetFront();
48
49 if (sound == NULL) {
50 return NULL;
51 }
52
53 if (priority < sound->CalcCurrentPlayerPriority()) {
54 return NULL;
55 }
56 sound->Stop();
57
58 ptr = mPool.Alloc();
59 NW4HBM_ASSERT_CHECK_NULL(114, ptr);
60 sound = new (ptr) T(this);
61 }
62
63 InsertPriorityList(sound, priority);
64 return sound;
65 }
66
67 void Free(T* sound) {
68 NW4HBM_ASSERT_CHECK_NULL(134, sound);
70
71 if (mPriorityList.IsEmpty()) {
72 return;
73 }
74
75 RemovePriorityList(sound);
76 sound->~T();
77 mPool.Free(sound);
78 }
79
81
82 u32 GetFreeCount() const { return mPool.Count(); }
83
85 if (mPriorityList.IsEmpty()) {
86 return NULL;
87 }
88
89 return static_cast<T*>(&mPriorityList.GetFront());
90 }
91
92 void InsertPriorityList(T* sound, int priority) {
93 TPrioList::Iterator it = mPriorityList.GetBeginIter();
94
95 for (; it != mPriorityList.GetEndIter(); it++) {
96 if (priority < it->CalcCurrentPlayerPriority()) {
97 break;
98 }
99 }
100
101 mPriorityList.Insert(it, sound);
102 }
103
104 void RemovePriorityList(T* sound) { mPriorityList.Erase(sound); }
105
107 TPrioList listsByPrio[T::PRIORITY_MAX + 1];
108
109 while (!mPriorityList.IsEmpty()) {
110 T& rSound = mPriorityList.GetFront();
112 listsByPrio[rSound.CalcCurrentPlayerPriority()].PushBack(&rSound);
113 }
114
115 for (int i = 0; i < T::PRIORITY_MAX + 1; i++) {
116 while (!listsByPrio[i].IsEmpty()) {
117 T& rSound = listsByPrio[i].GetFront();
118 listsByPrio[i].PopFront();
119 mPriorityList.PushBack(&rSound);
120 }
121 }
122 }
123
124 void UpdatePriority(T* sound, int priority) {
125 RemovePriorityList(sound);
126 InsertPriorityList(sound, priority);
127 }
128
129 private:
130 typedef ut::LinkList<T, offsetof(T, mPriorityLink)> TPrioList;
131
132 private:
135 };
136
137 } // namespace detail
138 } // namespace snd
139} // namespace nw4hbm
140
141#endif
Definition InstancePool.h:53
ut::LinkList< T, offsetof(T, mPriorityLink)> TPrioList
Definition SoundInstanceManager.h:130
void Destroy(void *buffer, u32 size)
Definition SoundInstanceManager.h:29
u32 Create(void *buffer, u32 size)
Definition SoundInstanceManager.h:24
TPrioList mPriorityList
Definition SoundInstanceManager.h:134
u32 GetActiveCount() const
Definition SoundInstanceManager.h:80
u32 GetFreeCount() const
Definition SoundInstanceManager.h:82
void Free(T *sound)
Definition SoundInstanceManager.h:67
T * Alloc(int priority)
Definition SoundInstanceManager.h:34
void InsertPriorityList(T *sound, int priority)
Definition SoundInstanceManager.h:92
void UpdatePriority(T *sound, int priority)
Definition SoundInstanceManager.h:124
T * GetLowestPrioritySound()
Definition SoundInstanceManager.h:84
void SortPriorityList()
Definition SoundInstanceManager.h:106
void RemovePriorityList(T *sound)
Definition SoundInstanceManager.h:104
MemoryPool< T > mPool
Definition SoundInstanceManager.h:133
Definition Lock.h:32
u32 GetSize() const
Definition LinkList.h:127
bool IsEmpty() const
Definition LinkList.h:128
void PopFront()
Definition LinkList.h:130
static OSTime buffer
Definition ai.c:24
unsigned int size
Definition __os.h:106
int i
Definition e_log.c:92
unsigned long u32
Definition types.h:12
static const double T[]
Definition k_tan.c:106
Definition HBMAnmController.h:6