28 #import <AudioToolbox/AudioToolbox.h> |
28 #import <AudioToolbox/AudioToolbox.h> |
29 #import <CommonCrypto/CommonDigest.h> |
29 #import <CommonCrypto/CommonDigest.h> |
30 #import "PascalImports.h" |
30 #import "PascalImports.h" |
31 #import "hwconsts.h" |
31 #import "hwconsts.h" |
32 |
32 |
33 BOOL inline rotationManager (UIInterfaceOrientation interfaceOrientation) { |
|
34 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || |
|
35 (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); |
|
36 } |
|
37 |
33 |
38 NSInteger inline randomPort () { |
34 NSInteger inline randomPort () { |
39 srandom(time(NULL)); |
35 srandom(time(NULL)); |
40 NSInteger res = (random() % 64511) + 1024; |
36 NSInteger res = (random() % 64511) + 1024; |
41 return (res == NETGAME_DEFAULT_PORT) ? randomPort() : res; |
37 return (res == NETGAME_DEFAULT_PORT) ? randomPort() : res; |
42 } |
|
43 |
|
44 void popError (const char *title, const char *message) { |
|
45 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:title] |
|
46 message:[NSString stringWithUTF8String:message] |
|
47 delegate:nil |
|
48 cancelButtonTitle:@"Ok" |
|
49 otherButtonTitles:nil]; |
|
50 [alert show]; |
|
51 [alert release]; |
|
52 } |
38 } |
53 |
39 |
54 // by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html |
40 // by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html |
55 void print_free_memory () { |
41 void print_free_memory () { |
56 mach_port_t host_port; |
42 mach_port_t host_port; |
75 |
61 |
76 BOOL inline isApplePhone () { |
62 BOOL inline isApplePhone () { |
77 return (IS_IPAD() == NO); |
63 return (IS_IPAD() == NO); |
78 } |
64 } |
79 |
65 |
80 NSString *modelType () { |
66 NSString *getModelType () { |
81 size_t size; |
67 size_t size; |
82 // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space |
68 // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space |
83 sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
69 sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
84 char *name = (char *)malloc(sizeof(char) * size); |
70 char *name = (char *)malloc(sizeof(char) * size); |
85 // get the platform name |
71 // get the platform name |
89 |
75 |
90 return modelId; |
76 return modelId; |
91 } |
77 } |
92 |
78 |
93 void playSound (NSString *snd) { |
79 void playSound (NSString *snd) { |
94 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; |
80 if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == YES) { |
95 NSNumber *audio = [prefs objectForKey:@"sound"]; |
|
96 |
|
97 if (audio == nil || [audio boolValue] == YES) { |
|
98 // get the filename of the sound file: |
81 // get the filename of the sound file: |
99 NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd]; |
82 NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd]; |
100 |
83 |
101 // declare a system sound id and get a URL for the sound file |
84 // declare a system sound id and get a URL for the sound file |
102 SystemSoundID soundID; |
85 SystemSoundID soundID; |
107 AudioServicesPlaySystemSound(soundID); |
90 AudioServicesPlaySystemSound(soundID); |
108 } |
91 } |
109 } |
92 } |
110 |
93 |
111 NSArray *getAvailableColors (void) { |
94 NSArray *getAvailableColors (void) { |
|
95 // by default colors are ARGB but we do computation over RGB, hence we have to "& 0x00FFFFFF" before processing |
112 unsigned int colors[] = HW_TEAMCOLOR_ARRAY; |
96 unsigned int colors[] = HW_TEAMCOLOR_ARRAY; |
113 NSMutableArray *array = [[NSMutableArray alloc] init]; |
97 NSMutableArray *array = [[NSMutableArray alloc] init]; |
114 |
98 |
115 int i = 0; |
99 int i = 0; |
116 while(colors[i] != 0) |
100 while(colors[i] != 0) |