Explorar o código

Chapter 4 mac

Sanjay Madhav %!s(int64=8) %!d(string=hai) anos
pai
achega
70ddf554ae

+ 31 - 9
Chapter04/Chapter5-mac.xcodeproj/project.pbxproj → Chapter04/Chapter04-mac.xcodeproj/project.pbxproj

@@ -19,10 +19,12 @@
 		9223C4801F009428009A94D7 /* SpriteComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C4761F009428009A94D7 /* SpriteComponent.cpp */; };
 		9223C48B1F0CA3CE009A94D7 /* MoveComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C48A1F0CA3CE009A94D7 /* MoveComponent.cpp */; };
 		9223C48F1F0CA67A009A94D7 /* Tile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C48D1F0CA67A009A94D7 /* Tile.cpp */; };
-		9223C4941F0CA766009A94D7 /* CollisionComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C4901F0CA766009A94D7 /* CollisionComponent.cpp */; };
 		9223C4951F0CA766009A94D7 /* CircleComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C4911F0CA766009A94D7 /* CircleComponent.cpp */; };
 		9223C4981F0DBD69009A94D7 /* Grid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9223C4961F0DBD69009A94D7 /* Grid.cpp */; };
 		92D324FB1B697389005A86C7 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92D324FA1B697389005A86C7 /* CoreFoundation.framework */; };
+		92E3918B1FE87D6000D8C362 /* AIState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 92E391861FE87D6000D8C362 /* AIState.cpp */; };
+		92E3918C1FE87D6000D8C362 /* AIComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 92E391881FE87D6000D8C362 /* AIComponent.cpp */; };
+		92E3918D1FE87D6000D8C362 /* Search.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 92E3918A1FE87D6000D8C362 /* Search.cpp */; };
 		92E46E941B6353E50035CD21 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92E46E931B6353E50035CD21 /* OpenGL.framework */; };
 /* End PBXBuildFile section */
 
@@ -50,13 +52,16 @@
 		9223C48C1F0CA3D4009A94D7 /* MoveComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MoveComponent.h; sourceTree = "<group>"; };
 		9223C48D1F0CA67A009A94D7 /* Tile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Tile.cpp; sourceTree = "<group>"; };
 		9223C48E1F0CA67A009A94D7 /* Tile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tile.h; sourceTree = "<group>"; };
-		9223C4901F0CA766009A94D7 /* CollisionComponent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CollisionComponent.cpp; sourceTree = "<group>"; };
 		9223C4911F0CA766009A94D7 /* CircleComponent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CircleComponent.cpp; sourceTree = "<group>"; };
-		9223C4921F0CA766009A94D7 /* CollisionComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollisionComponent.h; sourceTree = "<group>"; };
 		9223C4931F0CA766009A94D7 /* CircleComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CircleComponent.h; sourceTree = "<group>"; };
 		9223C4961F0DBD69009A94D7 /* Grid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Grid.cpp; sourceTree = "<group>"; };
 		9223C4971F0DBD69009A94D7 /* Grid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Grid.h; sourceTree = "<group>"; };
 		92D324FA1B697389005A86C7 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
+		92E391861FE87D6000D8C362 /* AIState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIState.cpp; sourceTree = "<group>"; };
+		92E391871FE87D6000D8C362 /* AIComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIComponent.h; sourceTree = "<group>"; };
+		92E391881FE87D6000D8C362 /* AIComponent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIComponent.cpp; sourceTree = "<group>"; };
+		92E391891FE87D6000D8C362 /* AIState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIState.h; sourceTree = "<group>"; };
+		92E3918A1FE87D6000D8C362 /* Search.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Search.cpp; sourceTree = "<group>"; };
 		92E46DF71B634EA30035CD21 /* Game-mac */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Game-mac"; sourceTree = BUILT_PRODUCTS_DIR; };
 		92E46E931B6353E50035CD21 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
 /* End PBXFileReference section */
@@ -79,14 +84,16 @@
 			children = (
 				9223C4681F009428009A94D7 /* Actor.cpp */,
 				9223C4691F009428009A94D7 /* Actor.h */,
+				92E391881FE87D6000D8C362 /* AIComponent.cpp */,
+				92E391871FE87D6000D8C362 /* AIComponent.h */,
+				92E391861FE87D6000D8C362 /* AIState.cpp */,
+				92E391891FE87D6000D8C362 /* AIState.h */,
 				9203E9F71F0F12FE00F9FFC2 /* Bullet.cpp */,
 				9203E9F81F0F12FE00F9FFC2 /* Bullet.h */,
 				9223C46E1F009428009A94D7 /* Component.cpp */,
 				9223C46F1F009428009A94D7 /* Component.h */,
 				9223C4911F0CA766009A94D7 /* CircleComponent.cpp */,
 				9223C4931F0CA766009A94D7 /* CircleComponent.h */,
-				9223C4901F0CA766009A94D7 /* CollisionComponent.cpp */,
-				9223C4921F0CA766009A94D7 /* CollisionComponent.h */,
 				9203E9F11F0DE24000F9FFC2 /* Enemy.cpp */,
 				9203E9F21F0DE24000F9FFC2 /* Enemy.h */,
 				9223C4671F009428009A94D7 /* Game.cpp */,
@@ -100,6 +107,7 @@
 				9223C48C1F0CA3D4009A94D7 /* MoveComponent.h */,
 				9203E9F41F0DF13600F9FFC2 /* NavComponent.cpp */,
 				9203E9F51F0DF13600F9FFC2 /* NavComponent.h */,
+				92E3918A1FE87D6000D8C362 /* Search.cpp */,
 				9223C4761F009428009A94D7 /* SpriteComponent.cpp */,
 				9223C4771F009428009A94D7 /* SpriteComponent.h */,
 				9223C48D1F0CA67A009A94D7 /* Tile.cpp */,
@@ -146,7 +154,7 @@
 		92E46DEF1B634EA30035CD21 /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 0830;
+				LastUpgradeCheck = 0920;
 				ORGANIZATIONNAME = "Sanjay Madhav";
 				TargetAttributes = {
 					92E46DF61B634EA30035CD21 = {
@@ -154,7 +162,7 @@
 					};
 				};
 			};
-			buildConfigurationList = 92E46DF21B634EA30035CD21 /* Build configuration list for PBXProject "Chapter5-mac" */;
+			buildConfigurationList = 92E46DF21B634EA30035CD21 /* Build configuration list for PBXProject "Chapter04-mac" */;
 			compatibilityVersion = "Xcode 3.2";
 			developmentRegion = English;
 			hasScannedForEncodings = 0;
@@ -192,11 +200,11 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				9223C4941F0CA766009A94D7 /* CollisionComponent.cpp in Sources */,
 				9223C47D1F009428009A94D7 /* Main.cpp in Sources */,
 				9223C47E1F009428009A94D7 /* Math.cpp in Sources */,
 				9203E9F01F0DD69900F9FFC2 /* Tower.cpp in Sources */,
 				9223C4781F009428009A94D7 /* Game.cpp in Sources */,
+				92E3918B1FE87D6000D8C362 /* AIState.cpp in Sources */,
 				9203E9F61F0DF13600F9FFC2 /* NavComponent.cpp in Sources */,
 				9223C4801F009428009A94D7 /* SpriteComponent.cpp in Sources */,
 				9223C48B1F0CA3CE009A94D7 /* MoveComponent.cpp in Sources */,
@@ -205,6 +213,8 @@
 				9203E9F91F0F12FE00F9FFC2 /* Bullet.cpp in Sources */,
 				9223C4951F0CA766009A94D7 /* CircleComponent.cpp in Sources */,
 				9223C47C1F009428009A94D7 /* Component.cpp in Sources */,
+				92E3918C1FE87D6000D8C362 /* AIComponent.cpp in Sources */,
+				92E3918D1FE87D6000D8C362 /* Search.cpp in Sources */,
 				9223C48F1F0CA67A009A94D7 /* Tile.cpp in Sources */,
 				9223C4981F0DBD69009A94D7 /* Grid.cpp in Sources */,
 			);
@@ -221,14 +231,20 @@
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
 				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
 				CLANG_WARN_CONSTANT_CONVERSION = YES;
 				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
 				CLANG_WARN_EMPTY_BODY = YES;
 				CLANG_WARN_ENUM_CONVERSION = YES;
 				CLANG_WARN_INFINITE_RECURSION = YES;
 				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
 				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -266,14 +282,20 @@
 				CLANG_CXX_LIBRARY = "libc++";
 				CLANG_ENABLE_MODULES = YES;
 				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
 				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
 				CLANG_WARN_CONSTANT_CONVERSION = YES;
 				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
 				CLANG_WARN_EMPTY_BODY = YES;
 				CLANG_WARN_ENUM_CONVERSION = YES;
 				CLANG_WARN_INFINITE_RECURSION = YES;
 				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
 				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
 				CLANG_WARN_SUSPICIOUS_MOVE = YES;
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -356,7 +378,7 @@
 /* End XCBuildConfiguration section */
 
 /* Begin XCConfigurationList section */
-		92E46DF21B634EA30035CD21 /* Build configuration list for PBXProject "Chapter5-mac" */ = {
+		92E46DF21B634EA30035CD21 /* Build configuration list for PBXProject "Chapter04-mac" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
 				92E46DFC1B634EA40035CD21 /* Debug */,

+ 1 - 1
Chapter04/Chapter5-mac.xcodeproj/project.xcworkspace/contents.xcworkspacedata → Chapter04/Chapter04-mac.xcodeproj/project.xcworkspace/contents.xcworkspacedata

@@ -2,6 +2,6 @@
 <Workspace
    version = "1.0">
    <FileRef
-      location = "self:/Users/Sanjay/gameprogcpp-solutions/Chapter05-new/Chapter5-mac.xcodeproj">
+      location = "self:/Users/Sanjay/gameprogcpp-final/Chapter04/Chapter04-mac.xcodeproj">
    </FileRef>
 </Workspace>

+ 7 - 5
Chapter04/Chapter5-mac.xcodeproj/xcshareddata/xcschemes/Game-mac.xcscheme → Chapter04/Chapter04-mac.xcodeproj/xcshareddata/xcschemes/Game-mac.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0830"
+   LastUpgradeVersion = "0920"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"
@@ -17,7 +17,7 @@
                BlueprintIdentifier = "92E46DF61B634EA30035CD21"
                BuildableName = "Game-mac"
                BlueprintName = "Game-mac"
-               ReferencedContainer = "container:Chapter5-mac.xcodeproj">
+               ReferencedContainer = "container:Chapter04-mac.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
       </BuildActionEntries>
@@ -26,6 +26,7 @@
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      language = ""
       shouldUseLaunchSchemeArgsEnv = "YES">
       <Testables>
       </Testables>
@@ -35,7 +36,7 @@
             BlueprintIdentifier = "92E46DF61B634EA30035CD21"
             BuildableName = "Game-mac"
             BlueprintName = "Game-mac"
-            ReferencedContainer = "container:Chapter5-mac.xcodeproj">
+            ReferencedContainer = "container:Chapter04-mac.xcodeproj">
          </BuildableReference>
       </MacroExpansion>
       <AdditionalOptions>
@@ -45,6 +46,7 @@
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      language = ""
       launchStyle = "0"
       useCustomWorkingDirectory = "YES"
       customWorkingDirectory = "$(SRCROOT)"
@@ -59,7 +61,7 @@
             BlueprintIdentifier = "92E46DF61B634EA30035CD21"
             BuildableName = "Game-mac"
             BlueprintName = "Game-mac"
-            ReferencedContainer = "container:Chapter5-mac.xcodeproj">
+            ReferencedContainer = "container:Chapter04-mac.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
       <AdditionalOptions>
@@ -78,7 +80,7 @@
             BlueprintIdentifier = "92E46DF61B634EA30035CD21"
             BuildableName = "Game-mac"
             BlueprintName = "Game-mac"
-            ReferencedContainer = "container:Chapter5-mac.xcodeproj">
+            ReferencedContainer = "container:Chapter04-mac.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
    </ProfileAction>

+ 16 - 17
Chapter04/Math.cpp

@@ -99,12 +99,13 @@ Vector3 Vector3::Transform(const Vector3& v, const Quaternion& q)
 void Matrix4::Invert()
 {
 	// Thanks slow math
-	float tmp[12]; /* temp array for pairs */
-	float src[16]; /* array of transpose source matrix */
-	float dst[16]; /* storage */
-	float det; /* determinant */
-	/* transpose matrix */
+	// This is a really janky way to unroll everything...
+	float tmp[12];
+	float src[16];
+	float dst[16];
+	float det;
 
+	// Transpose matrix
 	// row 1 to col 1
 	src[0] = mat[0][0];
 	src[4] = mat[0][1];
@@ -129,13 +130,7 @@ void Matrix4::Invert()
 	src[11] = mat[3][2];
 	src[15] = mat[3][3];
 
-	// 	for (int i = 0; i < 4; i++) {
-	// 		src[i] = mat[i*4];
-	// 		src[i + 4] = mat[i*4 + 1];
-	// 		src[i + 8] = mat[i*4 + 2];
-	// 		src[i + 12] = mat[i*4 + 3];
-	// 	}
-	/* calculate pairs for first 8 elements (cofactors) */
+	// Calculate cofactors
 	tmp[0] = src[10] * src[15];
 	tmp[1] = src[11] * src[14];
 	tmp[2] = src[9] * src[15];
@@ -148,7 +143,7 @@ void Matrix4::Invert()
 	tmp[9] = src[10] * src[12];
 	tmp[10] = src[8] * src[13];
 	tmp[11] = src[9] * src[12];
-	/* calculate first 8 elements (cofactors) */
+	
 	dst[0] = tmp[0] * src[5] + tmp[3] * src[6] + tmp[4] * src[7];
 	dst[0] -= tmp[1] * src[5] + tmp[2] * src[6] + tmp[5] * src[7];
 	dst[1] = tmp[1] * src[4] + tmp[6] * src[6] + tmp[9] * src[7];
@@ -165,7 +160,7 @@ void Matrix4::Invert()
 	dst[6] -= tmp[2] * src[0] + tmp[7] * src[1] + tmp[10] * src[3];
 	dst[7] = tmp[4] * src[0] + tmp[9] * src[1] + tmp[10] * src[2];
 	dst[7] -= tmp[5] * src[0] + tmp[8] * src[1] + tmp[11] * src[2];
-	/* calculate pairs for second 8 elements (cofactors) */
+	
 	tmp[0] = src[2] * src[7];
 	tmp[1] = src[3] * src[6];
 	tmp[2] = src[1] * src[7];
@@ -178,7 +173,7 @@ void Matrix4::Invert()
 	tmp[9] = src[2] * src[4];
 	tmp[10] = src[0] * src[5];
 	tmp[11] = src[1] * src[4];
-	/* calculate second 8 elements (cofactors) */
+	
 	dst[8] = tmp[0] * src[13] + tmp[3] * src[14] + tmp[4] * src[15];
 	dst[8] -= tmp[1] * src[13] + tmp[2] * src[14] + tmp[5] * src[15];
 	dst[9] = tmp[1] * src[12] + tmp[6] * src[14] + tmp[9] * src[15];
@@ -195,12 +190,16 @@ void Matrix4::Invert()
 	dst[14] -= tmp[10] * src[11] + tmp[2] * src[8] + tmp[7] * src[9];
 	dst[15] = tmp[10] * src[10] + tmp[4] * src[8] + tmp[9] * src[9];
 	dst[15] -= tmp[8] * src[9] + tmp[11] * src[10] + tmp[5] * src[8];
-	/* calculate determinant */
+	
+	// Calculate determinant
 	det = src[0] * dst[0] + src[1] * dst[1] + src[2] * dst[2] + src[3] * dst[3];
-	/* calculate matrix inverse */
+	
+	// Inverse of matrix is divided by determinant
 	det = 1 / det;
 	for (int j = 0; j < 16; j++)
+	{
 		dst[j] *= det;
+	}
 
 	// Set it back
 	for (int i = 0; i < 4; i++)