diff --git a/Aircraft.xcodeproj/project.pbxproj b/Aircraft.xcodeproj/project.pbxproj index b67579d..428e030 100644 --- a/Aircraft.xcodeproj/project.pbxproj +++ b/Aircraft.xcodeproj/project.pbxproj @@ -610,6 +610,8 @@ 9FB043F516B9D93D0067A04F /* battleFieldBar_self@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9FB043E516B9D93D0067A04F /* battleFieldBar_self@2x.png */; }; 9FB0B4F5169CFBAD00416B93 /* ABattleFieldModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FB0B4F4169CFBAD00416B93 /* ABattleFieldModel.m */; }; 9FB0B4F6169CFBAD00416B93 /* ABattleFieldModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FB0B4F4169CFBAD00416B93 /* ABattleFieldModel.m */; }; + E43FB4E41713627700C163A2 /* ADiagnostic.m in Sources */ = {isa = PBXBuildFile; fileRef = E43FB4E31713627700C163A2 /* ADiagnostic.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + E43FB4E51713627700C163A2 /* ADiagnostic.m in Sources */ = {isa = PBXBuildFile; fileRef = E43FB4E31713627700C163A2 /* ADiagnostic.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -960,6 +962,8 @@ 9FB043E516B9D93D0067A04F /* battleFieldBar_self@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "battleFieldBar_self@2x.png"; path = "Aircraft/res/battleFieldBar_self@2x.png"; sourceTree = ""; }; 9FB0B4F3169CFBAC00416B93 /* ABattleFieldModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ABattleFieldModel.h; path = Model/ABattleFieldModel.h; sourceTree = ""; }; 9FB0B4F4169CFBAD00416B93 /* ABattleFieldModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ABattleFieldModel.m; path = Model/ABattleFieldModel.m; sourceTree = ""; }; + E43FB4E21713627700C163A2 /* ADiagnostic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADiagnostic.h; sourceTree = ""; }; + E43FB4E31713627700C163A2 /* ADiagnostic.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADiagnostic.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1034,6 +1038,8 @@ 9F049CD516842BBA007F5AC2 /* AAppDelegate.m */, 0CD7213116C6C73D001BAD5D /* ASetting.h */, 0CD7213216C6C73D001BAD5D /* ASetting.m */, + E43FB4E21713627700C163A2 /* ADiagnostic.h */, + E43FB4E31713627700C163A2 /* ADiagnostic.m */, 9F049CCC16842BBA007F5AC2 /* Supporting Files */, ); path = Aircraft; @@ -2095,6 +2101,7 @@ 0CA9D30E16D5B7A00059D7D4 /* ALoadSavedGameScreenViewController.m in Sources */, 0CA9D31616D5E1190059D7D4 /* ASavedRecordItem.m in Sources */, 0CA9D32D16D5F0870059D7D4 /* ASavedGameRecord.m in Sources */, + E43FB4E41713627700C163A2 /* ADiagnostic.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2142,6 +2149,7 @@ 0CA9D30F16D5B7A00059D7D4 /* ALoadSavedGameScreenViewController.m in Sources */, 0CA9D31716D5E1190059D7D4 /* ASavedRecordItem.m in Sources */, 0CA9D32E16D5F0870059D7D4 /* ASavedGameRecord.m in Sources */, + E43FB4E51713627700C163A2 /* ADiagnostic.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2225,8 +2233,10 @@ GCC_PREFIX_HEADER = "Aircraft/Aircraft-Prefix.pch"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", + "A_LOG_VERBOSE=1", + "A_ASSERT_ENABLED=1", "LITE_VERSION=1", - "$(inherited)", + "A_LOG_ERROR=1", ); INFOPLIST_FILE = "Aircraft/Aircraft-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 5.0; @@ -2262,6 +2272,9 @@ GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "PLUS_VERSION=1", + "A_ASSERT_ENABLED=1", + "A_LOG_VERBOSE=1", + A_LOG_ERROR, ); INFOPLIST_FILE = AircraftPlusInfo.plist; IPHONEOS_DEPLOYMENT_TARGET = 5.0; diff --git a/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/Yufei.xcuserdatad/UserInterfaceState.xcuserstate b/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/Yufei.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..82f665d Binary files /dev/null and b/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/Yufei.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/feesfu.xcuserdatad/UserInterfaceState.xcuserstate b/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/feesfu.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..cbb318f Binary files /dev/null and b/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/feesfu.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/feesfu.xcuserdatad/WorkspaceSettings.xcsettings b/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/feesfu.xcuserdatad/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..659c876 --- /dev/null +++ b/Aircraft.xcodeproj/project.xcworkspace/xcuserdata/feesfu.xcuserdatad/WorkspaceSettings.xcsettings @@ -0,0 +1,10 @@ + + + + + HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges + + SnapshotAutomaticallyBeforeSignificantChanges + + + diff --git a/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/Aircraft.xcscheme b/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/Aircraft.xcscheme new file mode 100644 index 0000000..f79f3d4 --- /dev/null +++ b/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/Aircraft.xcscheme @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/AircraftPlus.xcscheme b/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/AircraftPlus.xcscheme new file mode 100644 index 0000000..29aa479 --- /dev/null +++ b/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/AircraftPlus.xcscheme @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/xcschememanagement.plist b/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..33a10c4 --- /dev/null +++ b/Aircraft.xcodeproj/xcuserdata/Yufei.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,32 @@ + + + + + SchemeUserState + + Aircraft.xcscheme + + orderHint + 0 + + AircraftPlus.xcscheme + + orderHint + 1 + + + SuppressBuildableAutocreation + + 9F049CC016842BBA007F5AC2 + + primary + + + 9F049D2A1684367F007F5AC2 + + primary + + + + + diff --git a/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/Aircraft.xcscheme b/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/Aircraft.xcscheme new file mode 100644 index 0000000..f79f3d4 --- /dev/null +++ b/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/Aircraft.xcscheme @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/AircraftPlus.xcscheme b/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/AircraftPlus.xcscheme new file mode 100644 index 0000000..29aa479 --- /dev/null +++ b/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/AircraftPlus.xcscheme @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/xcschememanagement.plist b/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..33a10c4 --- /dev/null +++ b/Aircraft.xcodeproj/xcuserdata/feesfu.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,32 @@ + + + + + SchemeUserState + + Aircraft.xcscheme + + orderHint + 0 + + AircraftPlus.xcscheme + + orderHint + 1 + + + SuppressBuildableAutocreation + + 9F049CC016842BBA007F5AC2 + + primary + + + 9F049D2A1684367F007F5AC2 + + primary + + + + + diff --git a/Aircraft/.DS_Store b/Aircraft/.DS_Store index a499aa0..e9c411f 100644 Binary files a/Aircraft/.DS_Store and b/Aircraft/.DS_Store differ diff --git a/Aircraft/ADiagnostic.h b/Aircraft/ADiagnostic.h new file mode 100755 index 0000000..dcce4d0 --- /dev/null +++ b/Aircraft/ADiagnostic.h @@ -0,0 +1,66 @@ +// +// ADiagnostic.h +// +// +// Created by Yufei Lang on 6/28/12. +// Copyright (c) 2012 Yufei Lang. All rights reserved. +// + +#import + +@interface ADiagnostic : NSObject +{ +@private + NSString *_assertMessage; +} + +/*! + @discussion retrieves the singleton instance + */ ++ (ADiagnostic *)sharedInstance; + +/*! + @abstract log the message in the console. + @discussion Diaplay file name and line number is it is an error log. + */ ++ (void)logWithfileName:(const char *)fileName lineNumber:(int)lineNumber logType:(int)flag Message:(NSString *)message, ...; + +/*! + @discussion displays the alert message and asserts + */ +- (void)assertFromFile:(const char *)fileName atLineNumber:(int)lineNumber message:(NSString *)message, ...; + +@end + +#define LOG_FLAG_ERROR (1 << 0) // 0...0001 +#define LOG_FLAG_WARN (1 << 1) // 0...0010 +#define LOG_FLAG_INFO (1 << 2) // 0...0100 +#define LOG_FLAG_VERBOSE (1 << 3) // 0...1000 + +#if A_ASSERT_ENABLED +#define AAssert(condition, desc, ...) \ +do { \ +if (!(condition)) [[ADiagnostic sharedInstance] assertFromFile:__FILE__ atLineNumber:__LINE__ message:desc, ##__VA_ARGS__];\ +} while(0) +#else +#define AAssert(condition, desc, ...) +#endif + + +#if A_LOG_VERBOSE +#define LogVerbose(fmt, ...) \ +do {\ +[ADiagnostic logWithfileName:__FILE__ lineNumber:__LINE__ logType:LOG_FLAG_VERBOSE Message:fmt, ##__VA_ARGS__];\ +} while(0) +#else +#define LogVerbose(fmt, ...) +#endif + +#if A_LOG_ERROR +#define LogError(fmt, ...) \ +do { \ +[ADiagnostic logWithfileName:__FILE__ lineNumber:__LINE__ logType:LOG_FLAG_ERROR Message:fmt, ##__VA_ARGS__];\ +} while(0) +#else +#define LogError(fmt, ...) +#endif \ No newline at end of file diff --git a/Aircraft/ADiagnostic.m b/Aircraft/ADiagnostic.m new file mode 100755 index 0000000..70101a6 --- /dev/null +++ b/Aircraft/ADiagnostic.m @@ -0,0 +1,141 @@ +// +// ADiagnostic.m +// +// +// Created by Yufei Lang on 6/28/12. +// Copyright (c) 2012 Yufei Lang. All rights reserved. +// + +#import "ADiagnostic.h" + +@implementation ADiagnostic + ++ (ADiagnostic *)sharedInstance +{ + static ADiagnostic *diag; + if (nil == diag) + { + diag = [[ADiagnostic alloc] init]; + } + return diag; +} + ++ (void)logWithfileName:(const char *)fileName lineNumber:(int)lineNumber logType:(int)flag Message:(NSString *)message, ... +{ + va_list args; + va_start(args, message); + NSString *msg = [[NSString alloc] initWithFormat:message arguments:args]; + va_end(args); + + if (flag == LOG_FLAG_VERBOSE) + { + // for those verbose logs, do not show file name and line number. [Yufei Lang] + // NSLog(@"[Log verbose]: %@\n[File:%@][Line:%d]", msg, ExtractFileNameWithoutExtension(fileName, NO), lineNumber); + NSLog(@"[Log verbose]: %@", msg); + } + else if (flag == LOG_FLAG_ERROR) + { + NSLog(@"[Log error]: %@\n[File:%@][Line:%d]", msg, ExtractFileNameWithoutExtension(fileName, NO), lineNumber); + } + + [msg release]; +} + +- (void)assertFromFile:(const char *)fileName atLineNumber:(int)lineNumber message:(NSString *)message, ... +{ + va_list args; + va_start(args, message); + _assertMessage = [[[NSString alloc] initWithFormat:message arguments:args] autorelease]; + va_end(args); + + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Assertion happened" + message:[NSString stringWithFormat:@"Reason: %@\nWhere: %@\nAt line: %d", + _assertMessage, + ExtractFileNameWithoutExtension(fileName, NO), + lineNumber] + delegate:self + cancelButtonTitle:@"Abort app" + otherButtonTitles:nil]; + [alert show]; + [alert release]; +} + +- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; +{ + NSAssert(NO, _assertMessage); + _assertMessage = nil; +} + +NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy) +{ + if (filePath == NULL) return nil; + + char *lastSlash = NULL; + char *lastDot = NULL; + + char *p = (char *)filePath; + + while (*p != '\0') + { + if (*p == '/') + lastSlash = p; + else if (*p == '.') + lastDot = p; + + p++; + } + + char *subStr; + NSUInteger subLen; + + if (lastSlash) + { + if (lastDot) + { + // lastSlash -> lastDot + subStr = lastSlash + 1; + subLen = lastDot - subStr; + } + else + { + // lastSlash -> endOfString + subStr = lastSlash + 1; + subLen = p - subStr; + } + } + else + { + if (lastDot) + { + // startOfString -> lastDot + subStr = (char *)filePath; + subLen = lastDot - subStr; + } + else + { + // startOfString -> endOfString + subStr = (char *)filePath; + subLen = p - subStr; + } + } + + if (copy) + { + return [[[NSString alloc] initWithBytes:subStr + length:subLen + encoding:NSUTF8StringEncoding] autorelease]; + } + else + { + // We can take advantage of the fact that __FILE__ is a string literal. + // Specifically, we don't need to waste time copying the string. + // We can just tell NSString to point to a range within the string literal. + + return [[[NSString alloc] initWithBytesNoCopy:subStr + length:subLen + encoding:NSUTF8StringEncoding + freeWhenDone:NO] autorelease]; + } +} + +@end \ No newline at end of file