project_files/HedgewarsMobile/Classes/AudioManagerController.m
author Wuzzy <almikes@aol.com>
Sat, 30 Sep 2017 23:52:08 +0200
changeset 12627 07fdda8c13a2
parent 10108 c68cf030eded
child 12877 00215a7ec5f5
permissions -rw-r--r--
TrophyRace: Fix game never eliminating any hogs after a hog skipped or ran out of time Warning: This commit _might_ invalidate past records, but I'm not sure if this is actually the case. Note that only the eliminiation part of the script is touched, not the actual race logic. Even if records are actually broken by this, I and sheepluva have decided that it's more imporant to fix this very, VERY stupid and old bug than to preserve records.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     1
/*
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
6700
e04da46ee43c the most important commit of the year
koda
parents: 6667
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     4
 *
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     8
 *
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    13
 *
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 8441
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    17
 */
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    18
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    19
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    20
#import "AudioManagerController.h"
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    21
#import "AVFoundation/AVAudioPlayer.h"
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    22
#import "MXAudioPlayerFadeOperation.h"
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    23
6832
fae8fd118da9 dates are no more!
koda
parents: 6700
diff changeset
    24
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    25
#define DEFAULT_VOLUME    0.45f
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    26
#define FADEOUT_DURATION  3.0f
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    27
#define FADEIN_DURATION   2.0f
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    28
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    29
static AudioManagerController *mainInstance;
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    30
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    31
@implementation AudioManagerController
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    32
@synthesize backgroundMusic, clickSound, backSound, selSound, audioFaderQueue;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    33
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    34
+(id) mainManager {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    35
    if (mainInstance == nil)
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    36
        mainInstance = [[self alloc] init];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    37
    return mainInstance;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    38
}
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    39
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    40
-(id) init {
6908
896ed2afcfb8 ios: turn on more warning messages and start correcting them
koda
parents: 6871
diff changeset
    41
    if ((self = [super init])) {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    42
        self.backgroundMusic = nil;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    43
        self.clickSound = -1;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    44
        self.backSound = -1;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    45
        self.selSound = -1;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    46
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    47
        self.audioFaderQueue = nil;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    48
    }
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    49
    return self;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    50
}
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    51
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    52
-(void) dealloc {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    53
    [self unloadSounds];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    54
    releaseAndNil(backgroundMusic);
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    55
    releaseAndNil(audioFaderQueue);
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    56
    mainInstance = nil;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    57
    [super dealloc];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    58
}
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    59
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    60
-(void) didReceiveMemoryWarning {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    61
    if (self.backgroundMusic.playing == NO)
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    62
        self.backgroundMusic = nil;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    63
    if ([self.audioFaderQueue operationCount] == 0)
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    64
        self.audioFaderQueue = nil;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    65
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    66
    [self unloadSounds];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    67
    MSG_MEMCLEAN();
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    68
}
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    69
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    70
#pragma mark -
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    71
#pragma mark background music control
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    72
-(void) playBackgroundMusic {
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    73
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    74
        return;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    75
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    76
    if (self.backgroundMusic == nil) {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    77
        NSString *musicString = [[NSBundle mainBundle] pathForResource:@"hwclassic" ofType:@"mp3"];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    78
        self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicString] error:nil];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    79
        self.backgroundMusic.delegate = nil;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    80
        self.backgroundMusic.numberOfLoops = -1;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    81
    }
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
    82
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    83
    self.backgroundMusic.volume = DEFAULT_VOLUME;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    84
    [self.backgroundMusic play];
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    85
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    86
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    87
-(void) pauseBackgroundMusic {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    88
    [self.backgroundMusic pause];
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    89
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    90
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    91
-(void) stopBackgroundMusic {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    92
    [self.backgroundMusic stop];
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    93
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    94
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    95
-(void) fadeOutBackgroundMusic {
6667
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    96
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    97
        return;
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    98
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    99
    if (self.audioFaderQueue == nil)
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   100
        self.audioFaderQueue = [[NSOperationQueue alloc] init];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   101
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   102
    MXAudioPlayerFadeOperation *fadeOut = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:self.backgroundMusic
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   103
                                                                                             toVolume:0.0
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   104
                                                                                         overDuration:FADEOUT_DURATION];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   105
    [self.audioFaderQueue addOperation:fadeOut];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   106
    [fadeOut release];
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   107
}
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   108
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   109
-(void) fadeInBackgroundMusic {
6667
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
   110
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
   111
        return;
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
   112
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   113
    if (self.audioFaderQueue == nil)
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   114
        self.audioFaderQueue = [[NSOperationQueue alloc] init];
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   115
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   116
    [self playBackgroundMusic];
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   117
    MXAudioPlayerFadeOperation *fadeIn = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:self.backgroundMusic
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   118
                                                                                            toVolume:DEFAULT_VOLUME
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   119
                                                                                        overDuration:FADEIN_DURATION];
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   120
    [audioFaderQueue addOperation:fadeIn];
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   121
    [fadeIn release];
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   122
}
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   123
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   124
#pragma mark -
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   125
#pragma mark sound effects control
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   126
-(SystemSoundID) loadSound:(NSString *)snd {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   127
    SystemSoundID soundID;
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   128
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   129
    // get the filename of the sound file in a NSURL format
6871
5aadbfe02613 ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents: 6869
diff changeset
   130
    NSString *path = [[NSBundle mainBundle] pathForResource:snd ofType:@"caf"];
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   131
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   132
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   133
    // use audio sevices to create and play the sound
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   134
    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   135
    return soundID;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   136
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   137
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   138
-(void) unloadSounds {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   139
    AudioServicesDisposeSystemSoundID(clickSound), clickSound = -1;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   140
    AudioServicesDisposeSystemSoundID(backSound), backSound = -1;
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   141
    AudioServicesDisposeSystemSoundID(selSound), selSound = -1;
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   142
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   143
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   144
-(void) playClickSound {
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   145
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   146
        return;
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   147
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   148
    if (self.clickSound == -1)
6871
5aadbfe02613 ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents: 6869
diff changeset
   149
        self.clickSound = [self loadSound:@"clickSound"];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   150
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   151
    AudioServicesPlaySystemSound(self.clickSound);
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   152
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   153
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   154
-(void) playBackSound {
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   155
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   156
        return;
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   157
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   158
    if (self.backSound == -1)
6871
5aadbfe02613 ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents: 6869
diff changeset
   159
        self.backSound = [self loadSound:@"backSound"];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   160
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   161
    AudioServicesPlaySystemSound(self.backSound);
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   162
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   163
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   164
-(void) playSelectSound {
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   165
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   166
        return;
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   167
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   168
    if (self.selSound == -1)
6871
5aadbfe02613 ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents: 6869
diff changeset
   169
        self.selSound = [self loadSound:@"selSound"];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   170
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   171
    AudioServicesPlaySystemSound(self.selSound);
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   172
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   173
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   174
@end