Lots of reworking. Completed support for game history, including Turn class. Changed Game API around quite a bit.
1 /* Copyright © 2008 Jens Alfke. All Rights Reserved.
3 Redistribution and use in source and binary forms, with or without modification, are permitted
4 provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright notice, this list of conditions
7 and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of
9 conditions and the following disclaimer in the documentation and/or other materials provided
10 with the distribution.
12 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
13 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
14 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
15 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
17 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
18 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
19 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 #import <AudioToolbox/AudioToolbox.h>
28 void setObj( id *variable, id newValue )
30 if( *variable != newValue ) {
32 *variable = [newValue retain];
36 void setObjCopy( id<NSCopying> *variable, id<NSCopying> newValue )
38 if( *variable != newValue ) {
40 *variable = [(id)newValue copy];
45 void DelayFor( NSTimeInterval interval )
47 NSDate *end = [NSDate dateWithTimeIntervalSinceNow: interval];
48 while( [end timeIntervalSinceNow] > 0 ) {
49 if( ! [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: end] )
56 static SystemSoundID GetSound( NSString *name )
58 static NSMutableDictionary *sSoundIDs;
59 NSNumber *soundIDObj = [sSoundIDs objectForKey: name];
61 NSLog(@"Loading sound '%@'",name);
62 NSString *type = name.pathExtension;
65 NSString *path = [[NSBundle mainBundle] pathForResource: name.stringByDeletingPathExtension
69 url = [NSURL fileURLWithPath: path];
71 NSLog(@"Couldn't find sound %@",name);
74 //url = [NSURL fileURLWithPath: [@"/Library/Sounds/" stringByAppendingPathComponent: name]];
75 SystemSoundID soundID;
76 if( AudioServicesCreateSystemSoundID((CFURLRef)url,&soundID) != noErr ) {
77 NSLog(@"Couldn't load sound %@",url);
81 soundIDObj = [NSNumber numberWithUnsignedInt: soundID];
83 sSoundIDs = [[NSMutableDictionary alloc] init];
84 [sSoundIDs setObject: soundIDObj forKey: name];
86 return [soundIDObj unsignedIntValue];
91 void PreloadSound( NSString* name )
96 NSSound *sound = [[NSSound soundNamed: @"Pop"] copy];
104 void PlaySound( NSString* name )
107 AudioServicesPlaySystemSound( GetSound(name) );
109 [[NSSound soundNamed: name] play];
116 AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);