equal
deleted
inserted
replaced
24 #import <sys/sysctl.h> |
24 #import <sys/sysctl.h> |
25 #import <netinet/in.h> |
25 #import <netinet/in.h> |
26 #import <SystemConfiguration/SCNetworkReachability.h> |
26 #import <SystemConfiguration/SCNetworkReachability.h> |
27 #import "hwconsts.h" |
27 #import "hwconsts.h" |
28 #import "EngineProtocolNetwork.h" |
28 #import "EngineProtocolNetwork.h" |
|
29 #import "SDL_uikitwindow.h" |
29 |
30 |
30 static NSString *cachedModel = nil; |
31 static NSString *cachedModel = nil; |
31 static NSArray *cachedColors = nil; |
32 static NSArray *cachedColors = nil; |
32 |
33 |
33 static TGameType gameType = gtNone; |
34 static TGameType gameType = gtNone; |
60 +(BOOL) isGameRunning { |
61 +(BOOL) isGameRunning { |
61 return (gameStatus == gsInGame); |
62 return (gameStatus == gsInGame); |
62 } |
63 } |
63 |
64 |
64 #pragma mark - |
65 #pragma mark - |
65 #pragma mark Helper Functions |
66 #pragma mark Helper Functions with cache |
66 +(NSString *)modelType { |
67 +(NSString *)modelType { |
67 if (cachedModel == nil) { |
68 if (cachedModel == nil) { |
68 size_t size; |
69 size_t size; |
69 // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space |
70 // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space |
70 sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
71 sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
92 [array release]; |
93 [array release]; |
93 } |
94 } |
94 return cachedColors; |
95 return cachedColors; |
95 } |
96 } |
96 |
97 |
|
98 +(void) releaseCache { |
|
99 [cachedModel release], cachedModel = nil; |
|
100 [cachedColors release], cachedColors = nil; |
|
101 } |
|
102 |
|
103 #pragma mark - |
|
104 #pragma mark Helper Functions without cache |
97 +(NSInteger) randomPort { |
105 +(NSInteger) randomPort { |
98 srandom(time(NULL)); |
106 srandom(time(NULL)); |
99 NSInteger res = (random() % 64511) + 1024; |
107 NSInteger res = (random() % 64511) + 1024; |
100 // recall self until you get a free port |
108 // recall self until you get a free port |
101 if (res == NETGAME_DEFAULT_PORT || res == [EngineProtocolNetwork activeEnginePort]) |
109 if (res == NETGAME_DEFAULT_PORT || res == [EngineProtocolNetwork activeEnginePort]) |
136 [testConnection release]; |
144 [testConnection release]; |
137 |
145 |
138 return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO; |
146 return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO; |
139 } |
147 } |
140 |
148 |
141 +(void) releaseCache { |
149 +(UIView *)mainSDLViewInstance { |
142 [cachedModel release], cachedModel = nil; |
150 SDL_Window *window = HW_getSDLWindow(); |
143 [cachedColors release], cachedColors = nil; |
151 if (window == NULL) { |
|
152 SDL_SetError("Window does not exist"); |
|
153 return nil; |
|
154 } |
|
155 SDL_WindowData *data = (SDL_WindowData *)window->driverdata; |
|
156 SDL_uikitview *view = data != NULL ? data->view : nil; |
|
157 return view; |
144 } |
158 } |
145 |
159 |
146 @end |
160 @end |