Oolite 1.91.0.7668-250429-8542c40
All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 87 of file OOSoundSourcePool.m.

88{
89 uint8_t i;
90
91 for (i = 0; i != _count; i++)
92 {
93 [_sources[i].source release];
94 }
95 free(_sources);
96
97 [_lastKey release];
98
99 [super dealloc];
100}
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 62 of file OOSoundSourcePool.m.

62 :(uint8_t)count minRepeatTime:(OOTimeDelta)minRepeat
63{
64 if ((self = [super init]))
65 {
66 // Sanity-check count
67 if (count == 0) count = 1;
68 if (count == kNoSlot) --count;
69 _count = count;
71
72 if (minRepeat < 0.0) minRepeat = 0.0;
73 _minRepeat = minRepeat;
74
75 // Create source pool
76 _sources = calloc(sizeof(PoolElement), count);
77 if (_sources == NULL)
78 {
79 [self release];
80 self = nil;
81 }
82 }
83 return self;
84}
unsigned count
return nil
@ kNoSlot
struct OOSoundSourcePoolElement PoolElement
double OOTimeDelta
Definition OOTypes.h:224

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

◆ playSoundWithKey:

- (void) playSoundWithKey: (NSString *) key

Definition at line 191 of file OOSoundSourcePool.m.

191 :(NSString *)key
192{
193 [self playSoundWithKey:key priority:1.0];
194}

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 203 of file OOSoundSourcePool.m.

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

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 213 of file OOSoundSourcePool.m.

213 :(NSString *)key overlap:(BOOL)overlap position:(Vector)position
214{
215 [self playSoundWithKey:key
216 priority:1.0
217 expiryTime:0.5
218 overlap:overlap
219 position:position];
220}

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 197 of file OOSoundSourcePool.m.

197 :(NSString *)key position:(Vector)position
198{
199 [self playSoundWithKey:key priority:1.0 position:position];
200}

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 182 of file OOSoundSourcePool.m.

182 :(NSString *)key
183 priority:(float)priority
184{
185 [self playSoundWithKey:key
186 priority:priority
187 expiryTime:0.5 + randf() * 0.1];
188}

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 158 of file OOSoundSourcePool.m.

158 :(NSString *)key
159 priority:(float)priority
160 expiryTime:(OOTimeDelta)expiryTime
161{
162 [self playSoundWithKey:key
163 priority:priority
164 expiryTime:expiryTime
165 overlap:YES
166 position:kZeroVector];
167}

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 103 of file OOSoundSourcePool.m.

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

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 170 of file OOSoundSourcePool.m.

170 :(NSString *)key
171 priority:(float)priority
172 position:(Vector)position
173{
174 [self playSoundWithKey:key
175 priority:priority
176 expiryTime:0.5 + randf() * 0.1
177 overlap:YES
178 position:position];
179}

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 56 of file OOSoundSourcePool.m.

56 :(uint8_t)count minRepeatTime:(OOTimeDelta)minRepeat
57{
58 return [[[self alloc] initWithCount:count minRepeatTime:minRepeat] autorelease];
59}

◆ selectSlotForPriority:

- (uint8_t) selectSlotForPriority: (float) priority
implementation

Provided by category OOSoundSourcePool(Private).

Definition at line 228 of file OOSoundSourcePool.m.

228 :(float)priority
229{
230 uint8_t curr, count, expiredLower = kNoSlot, unexpiredLower = kNoSlot, expiredEqual = kNoSlot;
231 PoolElement *element = NULL;
232 OOTimeAbsolute now = [UNIVERSE getTime];
233
234#define NEXT(x) (((x) + 1) % _count)
235
236 curr = _latest;
237 count = _count;
238 do
239 {
240 curr = NEXT(curr);
241 element = &_sources[curr];
242
243 if (element->source == nil || ![element->source isPlaying]) return curr; // Best type of slot: empty
244 else if (element->priority < priority)
245 {
246 if (element->expiryTime <= now) expiredLower = curr; // Second-best type: expired lower-priority
247 else if (curr != _reserved) unexpiredLower = curr; // Third-best type: unexpired lower-priority
248 }
249 else if (element->priority == priority && element->expiryTime <= now)
250 {
251 expiredEqual = curr; // Fourth-best type: expired equal-priority.
252 }
253 } while (--count);
254
255 if (expiredLower != kNoSlot) return expiredLower;
256 if (unexpiredLower != kNoSlot) return unexpiredLower;
257 return expiredEqual; // Will be kNoSlot if none found
258}
#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 44 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: