Oolite
Loading...
Searching...
No Matches
OOSoundSourcePool Class Reference

#include <OOSoundSourcePool.h>

Inheritance diagram for OOSoundSourcePool:
Collaboration diagram for OOSoundSourcePool:

Instance Methods

(id) - initWithCount:minRepeatTime:
(void) - playSoundWithKey:priority:expiryTime:overlap:position:
(void) - playSoundWithKey:priority:expiryTime:
(void) - playSoundWithKey:priority:
(void) - playSoundWithKey:priority:position:
(void) - playSoundWithKey:position:
(void) - playSoundWithKey:
(void) - playSoundWithKey:overlap:
(void) - playSoundWithKey:overlap:position:
(void) - dealloc [implementation]
(uint8_t) - selectSlotForPriority: [implementation]

Class Methods

(instancetype) + poolWithCount:minRepeatTime:

Private Attributes

struct OOSoundSourcePoolElement * _sources
uint8_t _count
uint8_t _latest
uint8_t _reserved
OOTimeDelta _minRepeat
OOTimeAbsolute _nextRepeat
NSString * _lastKey

Detailed Description

Definition at line 40 of file OOSoundSourcePool.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 80 of file OOSoundSourcePool.m.

81{
82 uint8_t i;
83
84 for (i = 0; i != _count; i++) {
85 [_sources[i].source release];
86 }
87 free(_sources);
88
89 [_lastKey release];
90
91 [super dealloc];
92}
struct OOSoundSourcePoolElement * _sources

References _count, _sources, and dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithCount:minRepeatTime:

- (id) initWithCount: (uint8_t) count
minRepeatTime: (OOTimeDelta) minRepeat 

Definition at line 55 of file OOSoundSourcePool.m.

55 :(uint8_t)count minRepeatTime:(OOTimeDelta)minRepeat
56{
57 if ((self = [super init])) {
58 // Sanity-check count
59 if (count == 0)
60 count = 1;
61 if (count == kNoSlot)
62 --count;
63 _count = count;
65
66 if (minRepeat < 0.0)
67 minRepeat = 0.0;
68 _minRepeat = minRepeat;
69
70 // Create source pool
71 _sources = calloc(sizeof(PoolElement), count);
72 if (_sources == NULL) {
73 [self release];
74 self = nil;
75 }
76 }
77 return self;
78}
unsigned count
return nil
@ kNoSlot
struct OOSoundSourcePoolElement PoolElement
double OOTimeDelta
Definition OOTypes.h:193

References _count, _minRepeat, _reserved, _sources, count, kNoSlot, and nil.

◆ playSoundWithKey:

- (void) playSoundWithKey: (NSString*) key

Definition at line 184 of file OOSoundSourcePool.m.

184 :(NSString*)key
185{
186 [self playSoundWithKey:key priority:1.0];
187}

References playSoundWithKey:priority:.

Referenced by PlayerEntity(Sound)::playBuyCommodity, PlayerEntity(Sound)::playBuyShip, PlayerEntity(Sound)::playCantBuyCommodity, PlayerEntity(Sound)::playCantBuyShip, PlayerEntity(Sound)::playCantSellCommodity, PlayerEntity(Sound)::playGameOver, and PlayerEntity(Sound)::playSellCommodity.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSoundWithKey:overlap:

- (void) playSoundWithKey: (NSString*) key
overlap: (BOOL) overlap 

Definition at line 194 of file OOSoundSourcePool.m.

194 :(NSString*)key overlap:(BOOL)overlap
195{
196 [self playSoundWithKey:key
197 priority:1.0
198 expiryTime:0.5
199 overlap:overlap
200 position:kZeroVector];
201}

References playSoundWithKey:priority:expiryTime:overlap:position:.

Here is the call graph for this function:

◆ playSoundWithKey:overlap:position:

- (void) playSoundWithKey: (NSString*) key
overlap: (BOOL) overlap
position: (Vector) position 

Definition at line 203 of file OOSoundSourcePool.m.

203 :(NSString*)key overlap:(BOOL)overlap position:(Vector)position
204{
205 [self playSoundWithKey:key
206 priority:1.0
207 expiryTime:0.5
208 overlap:overlap
209 position:position];
210}
struct Vector Vector

References playSoundWithKey:priority:expiryTime:overlap:position:.

Referenced by PlayerEntity(Sound)::playWeaponOverheated:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSoundWithKey:position:

- (void) playSoundWithKey: (NSString*) key
position: (Vector) position 

Definition at line 189 of file OOSoundSourcePool.m.

189 :(NSString*)key position:(Vector)position
190{
191 [self playSoundWithKey:key priority:1.0 position:position];
192}

References playSoundWithKey:priority:position:.

Referenced by PlayerEntity(Sound)::playAegisCloseToPlanet, PlayerEntity(Sound)::playAegisCloseToStation, PlayerEntity(Sound)::playDirectHit:weaponIdentifier:, PlayerEntity(Sound)::playEscapePodScooped, PlayerEntity(Sound)::playMineLaunched:weaponIdentifier:, PlayerEntity(Sound)::playMissileLaunched:weaponIdentifier:, PlayerEntity(Sound)::playScrapeDamage:, and PlayerEntity(Sound)::playShieldHit:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSoundWithKey:priority:

- (void) playSoundWithKey: (NSString*) key
priority: (float) priority 

Definition at line 176 of file OOSoundSourcePool.m.

176 :(NSString*)key
177 priority:(float)priority
178{
179 [self playSoundWithKey:key
180 priority:priority
181 expiryTime:0.5 + randf() * 0.1];
182}

References playSoundWithKey:priority:expiryTime:.

Referenced by PlayerEntity(Sound)::playLegacyScriptSound:, and playSoundWithKey:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSoundWithKey:priority:expiryTime:

- (void) playSoundWithKey: (NSString*) key
priority: (float) priority
expiryTime: (OOTimeDelta) expiryTime 

Definition at line 154 of file OOSoundSourcePool.m.

154 :(NSString*)key
155 priority:(float)priority
156 expiryTime:(OOTimeDelta)expiryTime
157{
158 [self playSoundWithKey:key
159 priority:priority
160 expiryTime:expiryTime
161 overlap:YES
162 position:kZeroVector];
163}

References playSoundWithKey:priority:expiryTime:overlap:position:.

Referenced by playSoundWithKey:priority:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSoundWithKey:priority:expiryTime:overlap:position:

- (void) playSoundWithKey: (NSString*) key
priority: (float) priority
expiryTime: (OOTimeDelta) expiryTime
overlap: (BOOL) overlap
position: (Vector) position 

Definition at line 94 of file OOSoundSourcePool.m.

94 :(NSString*)key
95 priority:(float)priority
96 expiryTime:(OOTimeDelta)expiryTime
97 overlap:(BOOL)overlap
98 position:(Vector)position
99{
100 uint8_t slot;
101 OOTimeAbsolute now, absExpiryTime;
102 PoolElement* element = NULL;
103 OOSound* sound = NULL;
104
105 // Convert expiry time to absolute
106 now = [UNIVERSE getTime];
107 absExpiryTime = expiryTime + now;
108
109 // Avoid repeats if required
110 if (now < _nextRepeat && [key isEqualToString:_lastKey])
111 return;
112 if (!overlap && _reserved != kNoSlot && [_sources[_reserved].source isPlaying])
113 return;
114
115 // Look for a slot in the source list to use
116 slot = [self selectSlotForPriority:priority];
117 if (slot == kNoSlot)
118 return;
119 element = &_sources[slot];
120
121 // Load sound
122 sound = [OOSound soundWithCustomSoundKey:key];
123 if (sound == nil)
124 return;
125
126 // Stop playing sound or set up sound source as appropriate
127 if (element->source != nil)
128 [element->source stop];
129 else {
130 element->source = [[OOSoundSource alloc] init];
131 if (element->source == nil)
132 return;
133 }
134 if (slot == _reserved)
135 _reserved = kNoSlot; // _reserved has finished playing!
136 if (!overlap)
137 _reserved = slot;
138
139 // Play and store metadata
140 [element->source setPosition:position];
141 [element->source playSound:sound];
142 element->expiryTime = absExpiryTime;
143 element->priority = priority;
144 if (_minRepeat > 0.0) {
145 _nextRepeat = now + _minRepeat;
146 [_lastKey release];
147 _lastKey = [key copy];
148 }
149
150 // Set staring search location for next slot lookup
151 _latest = slot;
152}
double OOTimeAbsolute
Definition OOTypes.h:192
OOTimeAbsolute _nextRepeat
id soundWithCustomSoundKey:(NSString *key)
Definition Universe.m:9950

References _lastKey, _latest, _minRepeat, _nextRepeat, _reserved, _sources, OOSoundSourcePoolElement::expiryTime, kNoSlot, nil, OOSoundSourcePoolElement::priority, selectSlotForPriority:, OOSound::soundWithCustomSoundKey:, and OOSoundSourcePoolElement::source.

Referenced by PlayerEntity(Sound)::playLaserHit:offset:weaponIdentifier:, playSoundWithKey:overlap:, playSoundWithKey:overlap:position:, playSoundWithKey:priority:expiryTime:, and playSoundWithKey:priority:position:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playSoundWithKey:priority:position:

- (void) playSoundWithKey: (NSString*) key
priority: (float) priority
position: (Vector) position 

Definition at line 165 of file OOSoundSourcePool.m.

165 :(NSString*)key
166 priority:(float)priority
167 position:(Vector)position
168{
169 [self playSoundWithKey:key
170 priority:priority
171 expiryTime:0.5 + randf() * 0.1
172 overlap:YES
173 position:position];
174}

References playSoundWithKey:priority:expiryTime:overlap:position:.

Referenced by PlayerEntity(Sound)::playAlertConditionRed, PlayerEntity(Sound)::playDockingDenied, PlayerEntity(Sound)::playEnergyLow, PlayerEntity(Sound)::playFuelLeak, PlayerEntity(Sound)::playHostileWarning, PlayerEntity(Sound)::playIncomingMissile:, playSoundWithKey:position:, PlayerEntity(Sound)::playWitchjumpBlocked, PlayerEntity(Sound)::playWitchjumpDistanceTooGreat, PlayerEntity(Sound)::playWitchjumpFailure, PlayerEntity(Sound)::playWitchjumpInsufficientFuel, and PlayerEntity(Sound)::playWitchjumpMisjump.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ poolWithCount:minRepeatTime:

+ (instancetype) poolWithCount: (uint8_t) count
minRepeatTime: (OOTimeDelta) minRepeat 

Definition at line 50 of file OOSoundSourcePool.m.

50 :(uint8_t)count minRepeatTime:(OOTimeDelta)minRepeat
51{
52 return [[[self alloc] initWithCount:count minRepeatTime:minRepeat] autorelease];
53}

◆ selectSlotForPriority:

- (uint8_t) selectSlotForPriority: (float) priority
implementation

Provided by category OOSoundSourcePool(Private).

Definition at line 216 of file OOSoundSourcePool.m.

216 :(float)priority
217{
218 uint8_t curr, count, expiredLower = kNoSlot, unexpiredLower = kNoSlot, expiredEqual = kNoSlot;
219 PoolElement* element = NULL;
220 OOTimeAbsolute now = [UNIVERSE getTime];
221
222#define NEXT(x) (((x) + 1) % _count)
223
224 curr = _latest;
225 count = _count;
226 do {
227 curr = NEXT(curr);
228 element = &_sources[curr];
229
230 if (element->source == nil || ![element->source isPlaying])
231 return curr; // Best type of slot: empty
232 else if (element->priority < priority) {
233 if (element->expiryTime <= now)
234 expiredLower = curr; // Second-best type: expired lower-priority
235 else if (curr != _reserved)
236 unexpiredLower = curr; // Third-best type: unexpired lower-priority
237 } else if (element->priority == priority && element->expiryTime <= now) {
238 expiredEqual = curr; // Fourth-best type: expired equal-priority.
239 }
240 } while (--count);
241
242 if (expiredLower != kNoSlot)
243 return expiredLower;
244 if (unexpiredLower != kNoSlot)
245 return unexpiredLower;
246 return expiredEqual; // Will be kNoSlot if none found
247}
#define NEXT(n)

Referenced by playSoundWithKey:priority:expiryTime:overlap:position:.

Here is the caller graph for this function:

Member Data Documentation

◆ _count

- (uint8_t) _count
private

Definition at line 43 of file OOSoundSourcePool.h.

Referenced by dealloc, and initWithCount:minRepeatTime:.

◆ _lastKey

- (NSString*) _lastKey
private

◆ _latest

- (uint8_t) _latest
private

◆ _minRepeat

- (OOTimeDelta) _minRepeat
private

◆ _nextRepeat

- (OOTimeAbsolute) _nextRepeat
private

◆ _reserved

- (uint8_t) _reserved
private

◆ _sources


The documentation for this class was generated from the following files: