├── 9781430258308.jpg ├── Chapter10 └── Chapter10 │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ ├── org.eclipse.cdt.codan.core.prefs │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── assets │ ├── sounds │ │ ├── impact.ogg │ │ └── jump.ogg │ └── test.tga │ ├── jni │ ├── Android.mk │ ├── AndroidIndices.h │ ├── AndroidVerts.h │ ├── Application.mk │ ├── Chapter10.cpp │ ├── Chapter10App.cpp │ ├── Chapter10App.h │ ├── Chapter10Task.cpp │ ├── Chapter10Task.h │ ├── CubeIndices.h │ ├── CubeVerts.h │ ├── DroidRunnerLevel.cpp │ ├── DroidRunnerLevel.h │ ├── Framework │ │ ├── Application │ │ │ ├── Application.cpp │ │ │ └── Application.h │ │ ├── Audio │ │ │ ├── AudioManager.cpp │ │ │ └── AudioManager.h │ │ ├── Collision │ │ │ ├── CollisionBin.cpp │ │ │ ├── CollisionBin.h │ │ │ ├── CollisionListener.h │ │ │ ├── CollisionManager.cpp │ │ │ └── CollisionManager.h │ │ ├── EventManager │ │ │ ├── Event.cpp │ │ │ ├── Event.h │ │ │ ├── EventHandler.h │ │ │ ├── EventId.h │ │ │ ├── EventManager.cpp │ │ │ └── EventManager.h │ │ ├── GameObjects │ │ │ ├── Component.h │ │ │ ├── Components │ │ │ │ ├── BoundObjectComponent.cpp │ │ │ │ ├── BoundObjectComponent.h │ │ │ │ ├── CameraComponent.cpp │ │ │ │ ├── CameraComponent.h │ │ │ │ ├── CollisionComponent.cpp │ │ │ │ ├── CollisionComponent.h │ │ │ │ ├── RenderableComponent.cpp │ │ │ │ ├── RenderableComponent.h │ │ │ │ ├── TransformComponent.cpp │ │ │ │ └── TransformComponent.h │ │ │ ├── GameObject.cpp │ │ │ └── GameObject.h │ │ ├── Kernel │ │ │ ├── Kernel.cpp │ │ │ ├── Kernel.h │ │ │ └── Task.h │ │ ├── Math │ │ │ ├── Functions.h │ │ │ ├── Matrix3.cpp │ │ │ ├── Matrix3.h │ │ │ ├── Matrix4.cpp │ │ │ ├── Matrix4.h │ │ │ ├── Plane.cpp │ │ │ ├── Plane.h │ │ │ ├── Transform.cpp │ │ │ ├── Transform.h │ │ │ ├── Vector3.cpp │ │ │ ├── Vector3.h │ │ │ ├── Vector4.cpp │ │ │ └── Vector4.h │ │ ├── Platform │ │ │ ├── Android.cpp │ │ │ └── Android.h │ │ ├── Renderer │ │ │ ├── Geometry │ │ │ │ ├── Geometry.cpp │ │ │ │ └── Geometry.h │ │ │ ├── Materials │ │ │ │ └── Material.h │ │ │ ├── Renderable.h │ │ │ ├── Renderer.cpp │ │ │ ├── Renderer.h │ │ │ ├── Shaders │ │ │ │ ├── BasicShader.cpp │ │ │ │ ├── BasicShader.h │ │ │ │ ├── Shader.cpp │ │ │ │ ├── Shader.h │ │ │ │ ├── TextureShader.cpp │ │ │ │ ├── TextureShader.h │ │ │ │ ├── TransformAmbientDiffuseShader.cpp │ │ │ │ ├── TransformAmbientDiffuseShader.h │ │ │ │ ├── TransformAmbientDiffuseSpecularShader.cpp │ │ │ │ ├── TransformAmbientDiffuseSpecularShader.h │ │ │ │ ├── TransformAmbientShader.cpp │ │ │ │ ├── TransformAmbientShader.h │ │ │ │ ├── TransformShader.cpp │ │ │ │ └── TransformShader.h │ │ │ └── Textures │ │ │ │ ├── Texture.cpp │ │ │ │ └── Texture.h │ │ └── Utilities │ │ │ ├── File.cpp │ │ │ ├── File.h │ │ │ ├── Hash.h │ │ │ ├── Singleton.h │ │ │ ├── TGAFile.cpp │ │ │ ├── TGAFile.h │ │ │ ├── Timer.cpp │ │ │ └── Timer.h │ ├── MovementComponent.cpp │ ├── MovementComponent.h │ ├── PatrolComponent.cpp │ ├── PatrolComponent.h │ └── Tiles.h │ ├── keystore │ └── Chapter10.keystore │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── Chapter2 └── HelloDroid │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── default.properties │ ├── jni │ ├── Android.mk │ ├── Application.mk │ └── main.cpp │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── Chapter4 └── Chapter4 │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── Chapter4.cpp │ └── Framework │ │ ├── Application │ │ ├── Application.cpp │ │ └── Application.h │ │ ├── Kernel │ │ ├── Kernel.cpp │ │ ├── Kernel.h │ │ └── Task.h │ │ ├── Platform │ │ ├── Android.cpp │ │ └── Android.h │ │ └── Utilities │ │ ├── Timer.cpp │ │ └── Timer.h │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── Chapter5 └── Chapter5 │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ ├── org.eclipse.cdt.codan.core.prefs │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── assets │ └── test.tga │ ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── Chapter5.cpp │ ├── Chapter5App.cpp │ ├── Chapter5App.h │ ├── Chapter5Task.cpp │ ├── Chapter5Task.h │ └── Framework │ │ ├── Application │ │ ├── Application.cpp │ │ └── Application.h │ │ ├── Kernel │ │ ├── Kernel.cpp │ │ ├── Kernel.h │ │ └── Task.h │ │ ├── Platform │ │ ├── Android.cpp │ │ └── Android.h │ │ ├── Renderer │ │ ├── Geometry │ │ │ ├── Geometry.cpp │ │ │ └── Geometry.h │ │ ├── Renderable.h │ │ ├── Renderer.cpp │ │ ├── Renderer.h │ │ ├── Shaders │ │ │ ├── BasicShader.cpp │ │ │ ├── BasicShader.h │ │ │ ├── Shader.cpp │ │ │ ├── Shader.h │ │ │ ├── TextureShader.cpp │ │ │ └── TextureShader.h │ │ └── Textures │ │ │ ├── Texture.cpp │ │ │ └── Texture.h │ │ └── Utilities │ │ ├── File.cpp │ │ ├── File.h │ │ ├── TGAFile.cpp │ │ ├── TGAFile.h │ │ ├── Timer.cpp │ │ └── Timer.h │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── Chapter6 └── Chapter6 │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ ├── org.eclipse.cdt.codan.core.prefs │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── assets │ └── test.tga │ ├── jni │ ├── Android.mk │ ├── AndroidIndices.h │ ├── AndroidVerts.h │ ├── Application.mk │ ├── Chapter6.cpp │ ├── Chapter6App.cpp │ ├── Chapter6App.h │ ├── Chapter6Task.cpp │ ├── Chapter6Task.h │ ├── Framework │ │ ├── Application │ │ │ ├── Application.cpp │ │ │ └── Application.h │ │ ├── EventManager │ │ │ ├── Event.cpp │ │ │ ├── Event.h │ │ │ ├── EventHandler.h │ │ │ ├── EventId.h │ │ │ ├── EventManager.cpp │ │ │ └── EventManager.h │ │ ├── GameObjects │ │ │ ├── Component.h │ │ │ ├── Components │ │ │ │ ├── RenderableComponent.cpp │ │ │ │ ├── RenderableComponent.h │ │ │ │ ├── TransformComponent.cpp │ │ │ │ └── TransformComponent.h │ │ │ ├── GameObject.cpp │ │ │ └── GameObject.h │ │ ├── Kernel │ │ │ ├── Kernel.cpp │ │ │ ├── Kernel.h │ │ │ └── Task.h │ │ ├── Math │ │ │ ├── Functions.h │ │ │ ├── Matrix3.cpp │ │ │ ├── Matrix3.h │ │ │ ├── Matrix4.cpp │ │ │ ├── Matrix4.h │ │ │ ├── Plane.cpp │ │ │ ├── Plane.h │ │ │ ├── Transform.cpp │ │ │ ├── Transform.h │ │ │ ├── Vector3.cpp │ │ │ ├── Vector3.h │ │ │ ├── Vector4.cpp │ │ │ └── Vector4.h │ │ ├── Platform │ │ │ ├── Android.cpp │ │ │ └── Android.h │ │ ├── Renderer │ │ │ ├── Geometry │ │ │ │ ├── Geometry.cpp │ │ │ │ └── Geometry.h │ │ │ ├── Renderable.h │ │ │ ├── Renderer.cpp │ │ │ ├── Renderer.h │ │ │ ├── Shaders │ │ │ │ ├── BasicShader.cpp │ │ │ │ ├── BasicShader.h │ │ │ │ ├── Shader.cpp │ │ │ │ ├── Shader.h │ │ │ │ ├── TextureShader.cpp │ │ │ │ ├── TextureShader.h │ │ │ │ ├── TransformShader.cpp │ │ │ │ └── TransformShader.h │ │ │ └── Textures │ │ │ │ ├── Texture.cpp │ │ │ │ └── Texture.h │ │ └── Utilities │ │ │ ├── File.cpp │ │ │ ├── File.h │ │ │ ├── Hash.h │ │ │ ├── Singleton.h │ │ │ ├── TGAFile.cpp │ │ │ ├── TGAFile.h │ │ │ ├── Timer.cpp │ │ │ └── Timer.h │ ├── MovementComponent.cpp │ ├── MovementComponent.h │ ├── PatrolComponent.cpp │ └── PatrolComponent.h │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── Chapter7 └── Chapter7 │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ ├── org.eclipse.cdt.codan.core.prefs │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── assets │ └── test.tga │ ├── jni │ ├── Android.mk │ ├── AndroidIndices.h │ ├── AndroidVerts.h │ ├── Application.mk │ ├── Chapter7.cpp │ ├── Chapter7App.cpp │ ├── Chapter7App.h │ ├── Chapter7Task.cpp │ ├── Chapter7Task.h │ ├── CubeIndices.h │ ├── CubeVerts.h │ ├── DroidRunnerLevel.cpp │ ├── DroidRunnerLevel.h │ ├── Framework │ │ ├── Application │ │ │ ├── Application.cpp │ │ │ └── Application.h │ │ ├── Collision │ │ │ ├── CollisionBin.cpp │ │ │ ├── CollisionBin.h │ │ │ ├── CollisionListener.h │ │ │ ├── CollisionManager.cpp │ │ │ └── CollisionManager.h │ │ ├── EventManager │ │ │ ├── Event.cpp │ │ │ ├── Event.h │ │ │ ├── EventHandler.h │ │ │ ├── EventId.h │ │ │ ├── EventManager.cpp │ │ │ └── EventManager.h │ │ ├── GameObjects │ │ │ ├── Component.h │ │ │ ├── Components │ │ │ │ ├── CollisionComponent.cpp │ │ │ │ ├── CollisionComponent.h │ │ │ │ ├── RenderableComponent.cpp │ │ │ │ ├── RenderableComponent.h │ │ │ │ ├── TransformComponent.cpp │ │ │ │ └── TransformComponent.h │ │ │ ├── GameObject.cpp │ │ │ └── GameObject.h │ │ ├── Kernel │ │ │ ├── Kernel.cpp │ │ │ ├── Kernel.h │ │ │ └── Task.h │ │ ├── Math │ │ │ ├── Functions.h │ │ │ ├── Matrix3.cpp │ │ │ ├── Matrix3.h │ │ │ ├── Matrix4.cpp │ │ │ ├── Matrix4.h │ │ │ ├── Plane.cpp │ │ │ ├── Plane.h │ │ │ ├── Transform.cpp │ │ │ ├── Transform.h │ │ │ ├── Vector3.cpp │ │ │ ├── Vector3.h │ │ │ ├── Vector4.cpp │ │ │ └── Vector4.h │ │ ├── Platform │ │ │ ├── Android.cpp │ │ │ └── Android.h │ │ ├── Renderer │ │ │ ├── Geometry │ │ │ │ ├── Geometry.cpp │ │ │ │ └── Geometry.h │ │ │ ├── Renderable.h │ │ │ ├── Renderer.cpp │ │ │ ├── Renderer.h │ │ │ ├── Shaders │ │ │ │ ├── BasicShader.cpp │ │ │ │ ├── BasicShader.h │ │ │ │ ├── Shader.cpp │ │ │ │ ├── Shader.h │ │ │ │ ├── TextureShader.cpp │ │ │ │ ├── TextureShader.h │ │ │ │ ├── TransformShader.cpp │ │ │ │ └── TransformShader.h │ │ │ └── Textures │ │ │ │ ├── Texture.cpp │ │ │ │ └── Texture.h │ │ └── Utilities │ │ │ ├── File.cpp │ │ │ ├── File.h │ │ │ ├── Hash.h │ │ │ ├── Singleton.h │ │ │ ├── TGAFile.cpp │ │ │ ├── TGAFile.h │ │ │ ├── Timer.cpp │ │ │ └── Timer.h │ ├── MovementComponent.cpp │ ├── MovementComponent.h │ ├── PatrolComponent.cpp │ └── PatrolComponent.h │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── Chapter8 └── Chapter8 │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ ├── org.eclipse.cdt.codan.core.prefs │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── assets │ └── test.tga │ ├── jni │ ├── Android.mk │ ├── AndroidIndices.h │ ├── AndroidVerts.h │ ├── Application.mk │ ├── Chapter8.cpp │ ├── Chapter8App.cpp │ ├── Chapter8App.h │ ├── Chapter8Task.cpp │ ├── Chapter8Task.h │ ├── CubeIndices.h │ ├── CubeVerts.h │ ├── DroidRunnerLevel.cpp │ ├── DroidRunnerLevel.h │ ├── Framework │ │ ├── Application │ │ │ ├── Application.cpp │ │ │ └── Application.h │ │ ├── Collision │ │ │ ├── CollisionBin.cpp │ │ │ ├── CollisionBin.h │ │ │ ├── CollisionListener.h │ │ │ ├── CollisionManager.cpp │ │ │ └── CollisionManager.h │ │ ├── EventManager │ │ │ ├── Event.cpp │ │ │ ├── Event.h │ │ │ ├── EventHandler.h │ │ │ ├── EventId.h │ │ │ ├── EventManager.cpp │ │ │ └── EventManager.h │ │ ├── GameObjects │ │ │ ├── Component.h │ │ │ ├── Components │ │ │ │ ├── BoundObjectComponent.cpp │ │ │ │ ├── BoundObjectComponent.h │ │ │ │ ├── CameraComponent.cpp │ │ │ │ ├── CameraComponent.h │ │ │ │ ├── CollisionComponent.cpp │ │ │ │ ├── CollisionComponent.h │ │ │ │ ├── RenderableComponent.cpp │ │ │ │ ├── RenderableComponent.h │ │ │ │ ├── TransformComponent.cpp │ │ │ │ └── TransformComponent.h │ │ │ ├── GameObject.cpp │ │ │ └── GameObject.h │ │ ├── Kernel │ │ │ ├── Kernel.cpp │ │ │ ├── Kernel.h │ │ │ └── Task.h │ │ ├── Math │ │ │ ├── Functions.h │ │ │ ├── Matrix3.cpp │ │ │ ├── Matrix3.h │ │ │ ├── Matrix4.cpp │ │ │ ├── Matrix4.h │ │ │ ├── Plane.cpp │ │ │ ├── Plane.h │ │ │ ├── Transform.cpp │ │ │ ├── Transform.h │ │ │ ├── Vector3.cpp │ │ │ ├── Vector3.h │ │ │ ├── Vector4.cpp │ │ │ └── Vector4.h │ │ ├── Platform │ │ │ ├── Android.cpp │ │ │ └── Android.h │ │ ├── Renderer │ │ │ ├── Geometry │ │ │ │ ├── Geometry.cpp │ │ │ │ └── Geometry.h │ │ │ ├── Renderable.h │ │ │ ├── Renderer.cpp │ │ │ ├── Renderer.h │ │ │ ├── Shaders │ │ │ │ ├── BasicShader.cpp │ │ │ │ ├── BasicShader.h │ │ │ │ ├── Shader.cpp │ │ │ │ ├── Shader.h │ │ │ │ ├── TextureShader.cpp │ │ │ │ ├── TextureShader.h │ │ │ │ ├── TransformShader.cpp │ │ │ │ └── TransformShader.h │ │ │ └── Textures │ │ │ │ ├── Texture.cpp │ │ │ │ └── Texture.h │ │ └── Utilities │ │ │ ├── File.cpp │ │ │ ├── File.h │ │ │ ├── Hash.h │ │ │ ├── Singleton.h │ │ │ ├── TGAFile.cpp │ │ │ ├── TGAFile.h │ │ │ ├── Timer.cpp │ │ │ └── Timer.h │ ├── MovementComponent.cpp │ ├── MovementComponent.h │ ├── PatrolComponent.cpp │ ├── PatrolComponent.h │ └── Tiles.h │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── Chapter9 └── Chapter9 │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── .settings │ ├── org.eclipse.cdt.codan.core.prefs │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── assets │ └── test.tga │ ├── jni │ ├── Android.mk │ ├── AndroidIndices.h │ ├── AndroidVerts.h │ ├── Application.mk │ ├── Chapter9.cpp │ ├── Chapter9App.cpp │ ├── Chapter9App.h │ ├── Chapter9Task.cpp │ ├── Chapter9Task.h │ ├── CubeIndices.h │ ├── CubeVerts.h │ ├── DroidRunnerLevel.cpp │ ├── DroidRunnerLevel.h │ ├── Framework │ │ ├── Application │ │ │ ├── Application.cpp │ │ │ └── Application.h │ │ ├── Collision │ │ │ ├── CollisionBin.cpp │ │ │ ├── CollisionBin.h │ │ │ ├── CollisionListener.h │ │ │ ├── CollisionManager.cpp │ │ │ └── CollisionManager.h │ │ ├── EventManager │ │ │ ├── Event.cpp │ │ │ ├── Event.h │ │ │ ├── EventHandler.h │ │ │ ├── EventId.h │ │ │ ├── EventManager.cpp │ │ │ └── EventManager.h │ │ ├── GameObjects │ │ │ ├── Component.h │ │ │ ├── Components │ │ │ │ ├── BoundObjectComponent.cpp │ │ │ │ ├── BoundObjectComponent.h │ │ │ │ ├── CameraComponent.cpp │ │ │ │ ├── CameraComponent.h │ │ │ │ ├── CollisionComponent.cpp │ │ │ │ ├── CollisionComponent.h │ │ │ │ ├── RenderableComponent.cpp │ │ │ │ ├── RenderableComponent.h │ │ │ │ ├── TransformComponent.cpp │ │ │ │ └── TransformComponent.h │ │ │ ├── GameObject.cpp │ │ │ └── GameObject.h │ │ ├── Kernel │ │ │ ├── Kernel.cpp │ │ │ ├── Kernel.h │ │ │ └── Task.h │ │ ├── Math │ │ │ ├── Functions.h │ │ │ ├── Matrix3.cpp │ │ │ ├── Matrix3.h │ │ │ ├── Matrix4.cpp │ │ │ ├── Matrix4.h │ │ │ ├── Plane.cpp │ │ │ ├── Plane.h │ │ │ ├── Transform.cpp │ │ │ ├── Transform.h │ │ │ ├── Vector3.cpp │ │ │ ├── Vector3.h │ │ │ ├── Vector4.cpp │ │ │ └── Vector4.h │ │ ├── Platform │ │ │ ├── Android.cpp │ │ │ └── Android.h │ │ ├── Renderer │ │ │ ├── Geometry │ │ │ │ ├── Geometry.cpp │ │ │ │ └── Geometry.h │ │ │ ├── Materials │ │ │ │ └── Material.h │ │ │ ├── Renderable.h │ │ │ ├── Renderer.cpp │ │ │ ├── Renderer.h │ │ │ ├── Shaders │ │ │ │ ├── BasicShader.cpp │ │ │ │ ├── BasicShader.h │ │ │ │ ├── Shader.cpp │ │ │ │ ├── Shader.h │ │ │ │ ├── TextureShader.cpp │ │ │ │ ├── TextureShader.h │ │ │ │ ├── TransformAmbientDiffuseShader.cpp │ │ │ │ ├── TransformAmbientDiffuseShader.h │ │ │ │ ├── TransformAmbientDiffuseSpecularShader.cpp │ │ │ │ ├── TransformAmbientDiffuseSpecularShader.h │ │ │ │ ├── TransformAmbientShader.cpp │ │ │ │ ├── TransformAmbientShader.h │ │ │ │ ├── TransformShader.cpp │ │ │ │ └── TransformShader.h │ │ │ └── Textures │ │ │ │ ├── Texture.cpp │ │ │ │ └── Texture.h │ │ └── Utilities │ │ │ ├── File.cpp │ │ │ ├── File.h │ │ │ ├── Hash.h │ │ │ ├── Singleton.h │ │ │ ├── TGAFile.cpp │ │ │ ├── TGAFile.h │ │ │ ├── Timer.cpp │ │ │ └── Timer.h │ ├── MovementComponent.cpp │ ├── MovementComponent.h │ ├── PatrolComponent.cpp │ ├── PatrolComponent.h │ └── Tiles.h │ ├── proguard-project.txt │ ├── project.properties │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── values-v11 │ └── styles.xml │ ├── values-v14 │ └── styles.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── LICENSE.txt ├── README.md └── contributing.md /9781430258308.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/9781430258308.jpg -------------------------------------------------------------------------------- /Chapter10/Chapter10/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/assets/sounds/impact.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter10/Chapter10/assets/sounds/impact.ogg -------------------------------------------------------------------------------- /Chapter10/Chapter10/assets/sounds/jump.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter10/Chapter10/assets/sounds/jump.ogg -------------------------------------------------------------------------------- /Chapter10/Chapter10/assets/test.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter10/Chapter10/assets/test.tga -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 2 | APP_STL := stlport_static 3 | NDK_TOOLCHAIN_VERSION := 4.7 4 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Chapter10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Chapter10App.h" 4 | #include 5 | 6 | void android_main(struct android_app* state) 7 | { 8 | sleep(5); 9 | 10 | app_dummy(); 11 | 12 | Chapter10App app(state); 13 | 14 | if (app.Initialize()) 15 | { 16 | app.Run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Chapter10App.cpp: -------------------------------------------------------------------------------- 1 | #include "Chapter10App.h" 2 | 3 | Chapter10App::Chapter10App(android_app* pState) 4 | : Framework::Application(pState) 5 | , m_chapter10Task(Framework::Task::GAME_PRIORITY) 6 | { 7 | } 8 | 9 | Chapter10App::~Chapter10App() 10 | { 11 | 12 | } 13 | 14 | bool Chapter10App::Initialize() 15 | { 16 | bool success = Framework::Application::Initialize(); 17 | 18 | if (success) 19 | { 20 | m_kernel.AddTask(&m_chapter10Task); 21 | } 22 | 23 | return success; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Chapter10App.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER10APP_H_ 2 | #define CHAPTER10APP_H_ 3 | 4 | #include "Framework/Application/Application.h" 5 | #include "Chapter10Task.h" 6 | #include 7 | 8 | class Chapter10App 9 | : public Framework::Application 10 | { 11 | private: 12 | Chapter10Task m_chapter10Task; 13 | 14 | public: 15 | Chapter10App(android_app* pState); 16 | virtual ~Chapter10App(); 17 | 18 | virtual bool Initialize(); 19 | }; 20 | 21 | #endif // CHAPTER10APP_H_ 22 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Chapter10Task.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER10TASK_H_ 2 | #define CHAPTER10TASK_H_ 3 | 4 | #include "Framework/Kernel/Task.h" 5 | #include "DroidRunnerLevel.h" 6 | 7 | class Chapter10Task 8 | : public Framework::Task 9 | { 10 | private: 11 | DroidRunnerLevel* m_pLevel; 12 | 13 | public: 14 | Chapter10Task(const unsigned int priority); 15 | virtual ~Chapter10Task(); 16 | 17 | // From Task 18 | virtual bool Start(); 19 | virtual void OnSuspend(); 20 | virtual void Update(); 21 | virtual void OnResume(); 22 | virtual void Stop(); 23 | }; 24 | 25 | #endif // CHAPTER10TASK_H_ 26 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/CubeIndices.h: -------------------------------------------------------------------------------- 1 | 0,2,1, 2 | 0,3,2, 3 | 4,6,7, 4 | 4,5,6, 5 | 0,5,4, 6 | 0,1,5, 7 | 1,6,5, 8 | 1,2,6, 9 | 2,7,6, 10 | 2,3,7, 11 | 4,3,0, 12 | 4,7,3, 13 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/CubeVerts.h: -------------------------------------------------------------------------------- 1 | -3.0,-3.0,-3.0, 2 | -0.5773491859436035,-0.5773491859436035,-0.5773491859436035, 3 | -3.0,-3.0,3.0, 4 | -0.5773491859436035,-0.5773491859436035,0.5773491859436035, 5 | 3.0,-3.0,3.0, 6 | 0.5773491859436035,-0.5773491859436035,0.5773491859436035, 7 | 3.0,-3.0,-3.0, 8 | 0.5773491859436035,-0.5773491859436035,-0.5773491859436035, 9 | -3.0,3.0,-3.0, 10 | -0.5773491859436035,0.5773491859436035,-0.5773491859436035, 11 | -3.0,3.0,3.0, 12 | -0.5773491859436035,0.5773491859436035,0.5773491859436035, 13 | 3.0,3.0,3.0, 14 | 0.5773491859436035,0.5773491859436035,0.5773491859436035, 15 | 3.0,3.0,-3.0, 16 | 0.5773491859436035,0.5773491859436035,-0.5773491859436035, 17 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Application/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H_ 2 | #define APPLICATION_H_ 3 | 4 | #include "../Kernel/Kernel.h" 5 | #include "../Platform/Android.h" 6 | #include 7 | 8 | namespace Framework 9 | { 10 | class Application 11 | { 12 | protected: 13 | android_app* m_pAppState; 14 | Kernel m_kernel; 15 | Android m_androidTask; 16 | 17 | virtual void CreateSingletons(); 18 | virtual void DestroySingletons(); 19 | 20 | public: 21 | explicit Application(android_app* state); 22 | virtual ~Application(); 23 | 24 | virtual bool Initialize(); 25 | virtual void Run(); 26 | }; 27 | } 28 | 29 | #endif // APPLICATION_H_ 30 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Collision/CollisionBin.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONBIN_H_ 2 | #define COLLISIONBIN_H_ 3 | 4 | #include 5 | #include "../GameObjects/Components/CollisionComponent.h" 6 | 7 | namespace Framework 8 | { 9 | class CollisionBin 10 | { 11 | private: 12 | typedef std::vector CollisionComponentVector; 13 | typedef CollisionComponentVector::iterator CollisionComponentVectorIterator; 14 | 15 | CollisionComponentVector m_collisionObjects; 16 | CollisionComponentVectorIterator m_currentObject; 17 | 18 | public: 19 | CollisionBin(); 20 | ~CollisionBin(); 21 | 22 | void AddObject(CollisionComponent* pCollisionComponent); 23 | CollisionComponent* GetFirst(); 24 | CollisionComponent* GetNext(); 25 | void Clear(); 26 | }; 27 | } 28 | 29 | #endif // COLLISIONBIN_H_ 30 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Collision/CollisionListener.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONLISTENER_H_ 2 | #define COLLISIONLISTENER_H_ 3 | 4 | namespace Framework 5 | { 6 | struct CollisionEventData; 7 | 8 | class CollisionListener 9 | { 10 | public: 11 | virtual void HandleCollision(CollisionEventData* pData) = 0; 12 | }; 13 | } 14 | 15 | #endif // COLLISIONLISTENER_H_ 16 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Collision/CollisionManager.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONMANAGER_H_ 2 | #define COLLISIONMANAGER_H_ 3 | 4 | #include "../Utilities/Singleton.h" 5 | #include 6 | #include "CollisionBin.h" 7 | 8 | namespace Framework 9 | { 10 | class CollisionManager 11 | : public Singleton 12 | { 13 | private: 14 | typedef std::vector CollisionBinVector; 15 | 16 | CollisionBinVector m_collisionBins; 17 | 18 | public: 19 | CollisionManager(); 20 | ~CollisionManager(); 21 | 22 | void AddCollisionBin(); 23 | void AddObjectToBin(const unsigned int binIndex, CollisionComponent* pObject); 24 | void TestAgainstBin(const unsigned int binIndex, CollisionComponent* pObject); 25 | void ClearBin(const unsigned int binIndex); 26 | }; 27 | } 28 | 29 | #endif // COLLISIONMANAGER_H_ 30 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/EventManager/Event.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_H_ 2 | #define EVENT_H_ 3 | 4 | #include 5 | #include "EventHandler.h" 6 | #include "EventId.h" 7 | 8 | namespace Framework 9 | { 10 | class Event 11 | { 12 | private: 13 | typedef std::vector EventHandlerList; 14 | typedef EventHandlerList::iterator EventHandlerListIterator; 15 | 16 | EventHandlerList m_listeners; 17 | EventID m_id; 18 | void* m_pData; 19 | 20 | public: 21 | explicit Event(EventID eventId); 22 | ~Event(); 23 | 24 | void Send(void* pData); 25 | void SendToHandler(EventHandler& eventHandler, void* pData); 26 | void AttachListener(EventHandler& eventHandler); 27 | void DetachListener(EventHandler& eventHandler); 28 | 29 | EventID GetID() const { return m_id; } 30 | void* GetData() { return m_pData; } 31 | }; 32 | } 33 | 34 | #endif // EVENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/EventManager/EventHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTHANDLER_H_ 2 | #define EVENTHANDLER_H_ 3 | 4 | namespace Framework 5 | { 6 | class Event; 7 | 8 | class EventHandler 9 | { 10 | public: 11 | virtual ~EventHandler() {} 12 | 13 | virtual void HandleEvent(Event* pEvent) = 0; 14 | }; 15 | } 16 | 17 | #endif // EVENTHANDLER_H_ 18 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/EventManager/EventId.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTID_H_ 2 | #define EVENTID_H_ 3 | 4 | namespace Framework 5 | { 6 | class GameObject; 7 | 8 | typedef unsigned int EventID; 9 | 10 | static const EventID UPDATE_EVENT = 0; 11 | static const EventID POSTUPDATE_EVENT = 1; 12 | static const EventID RENDER_EVENT = 2; 13 | static const EventID JUMP_EVENT = 3; 14 | static const EventID COLLISION_EVENT = 4; 15 | static const EventID PAUSEAPP_EVENT = 5; 16 | static const EventID RESUMEAPP_EVENT = 6; 17 | static const EventID PLAYERJUMP_EVENT = 7; 18 | 19 | struct CollisionEventData 20 | { 21 | GameObject* m_pCollider; 22 | }; 23 | } 24 | 25 | #endif // EVENTID_H_ 26 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/GameObjects/Component.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENT_H_ 2 | #define COMPONENT_H_ 3 | 4 | #include "../Utilities/Hash.h" 5 | 6 | namespace Framework 7 | { 8 | class GameObject; 9 | 10 | class Component 11 | { 12 | private: 13 | GameObject* m_pOwner; 14 | 15 | public: 16 | explicit Component(GameObject* pOwner) 17 | : m_pOwner(pOwner) 18 | { 19 | } 20 | 21 | virtual ~Component() {} 22 | 23 | virtual void Initialize() = 0; 24 | 25 | GameObject* GetOwner() { return m_pOwner; } 26 | }; 27 | } 28 | 29 | #endif /* COMPONENT_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/GameObjects/Components/CameraComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMERACOMPONENT_H_ 2 | #define CAMERACOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../EventManager/EventHandler.h" 6 | #include "../../Renderer/Renderer.h" 7 | 8 | namespace Framework 9 | { 10 | class CameraComponent 11 | : public Component 12 | , public EventHandler 13 | { 14 | private: 15 | static const unsigned int s_id = 3; 16 | 17 | float m_frustumParameters[Renderer::NUM_PARAMS]; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit CameraComponent(GameObject* pOwner); 23 | virtual ~CameraComponent(); 24 | 25 | virtual void Initialize() {} 26 | 27 | void SetFrustum(const float verticalFieldOfView, const float aspectRatio, const float near, const float far); 28 | 29 | virtual void HandleEvent(Event* pEvent); 30 | }; 31 | } 32 | 33 | #endif // CAMERACOMPONENT_H_ 34 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/GameObjects/Components/RenderableComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERABLECOMPONENT_H_ 2 | #define RENDERABLECOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Renderer/Renderable.h" 6 | #include "../../EventManager/EventHandler.h" 7 | #include "../../EventManager/EventId.h" 8 | 9 | namespace Framework 10 | { 11 | class RenderableComponent 12 | : public Component 13 | , public EventHandler 14 | { 15 | private: 16 | static const unsigned int s_id = 1; 17 | 18 | Renderable m_renderable; 19 | 20 | public: 21 | static unsigned int GetId() { return s_id; } 22 | 23 | explicit RenderableComponent(GameObject* pOwner); 24 | virtual ~RenderableComponent(); 25 | 26 | virtual void Initialize(); 27 | 28 | Renderable& GetRenderable() { return m_renderable; } 29 | 30 | virtual void HandleEvent(Event* pEvent); 31 | }; 32 | } 33 | 34 | #endif // RENDERABLECOMPONENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/GameObjects/Components/TransformComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "TransformComponent.h" 2 | 3 | namespace Framework 4 | { 5 | TransformComponent::TransformComponent(GameObject* pOwner) 6 | : Component(pOwner) 7 | { 8 | 9 | } 10 | 11 | TransformComponent::~TransformComponent() 12 | { 13 | 14 | } 15 | 16 | void TransformComponent::Initialize() 17 | { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/GameObjects/Components/TransformComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMCOMPONENT_H_ 2 | #define TRANSFORMCOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Math/Transform.h" 6 | 7 | namespace Framework 8 | { 9 | class GameObject; 10 | 11 | class TransformComponent 12 | : public Component 13 | { 14 | private: 15 | static const unsigned int s_id = 0; 16 | 17 | Transform m_transform; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit TransformComponent(GameObject* pOwner); 23 | virtual ~TransformComponent(); 24 | 25 | virtual void Initialize(); 26 | 27 | Transform& GetTransform() { return m_transform; } 28 | const Transform& GetTransform() const { return m_transform; } 29 | }; 30 | } 31 | 32 | #endif // TRANSFORMCOMPONENT_H_ 33 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/GameObjects/GameObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GameObject.h" 2 | #include 3 | 4 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__)) 5 | 6 | namespace Framework 7 | { 8 | GameObject::GameObject() 9 | { 10 | 11 | } 12 | 13 | GameObject::~GameObject() 14 | { 15 | for (ComponentUnorderedMapIterator iter = m_components.begin(); iter != m_components.end(); ++iter) 16 | { 17 | Component* pComponent = iter->second; 18 | if (pComponent) 19 | { 20 | delete pComponent; 21 | pComponent = NULL; 22 | } 23 | } 24 | } 25 | 26 | Component* GameObject::GetComponent(unsigned int id) 27 | { 28 | ComponentUnorderedMapIterator result = m_components.find(id); 29 | return result == m_components.end() 30 | ? NULL 31 | : result->second; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef KERNEL_H_ 2 | #define KERNEL_H_ 3 | 4 | #include 5 | #include "Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Kernel 10 | { 11 | private: 12 | typedef std::list TaskList; 13 | typedef std::list::iterator TaskListIterator; 14 | 15 | TaskList m_tasks; 16 | TaskList m_pausedTasks; 17 | 18 | void PriorityAdd(Task* pTask); 19 | 20 | public: 21 | Kernel(); 22 | virtual ~Kernel(); 23 | 24 | void Execute(); 25 | 26 | bool AddTask(Task* pTask); 27 | void SuspendTask(Task* task); 28 | void ResumeTask(Task* task); 29 | void RemoveTask(Task* task); 30 | void KillAllTasks(); 31 | 32 | bool HasTasks() { return m_tasks.size(); } 33 | }; 34 | } 35 | 36 | #endif // KERNEL_H_ 37 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Math/Functions.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONS_H_ 2 | #define FUNCTIONS_H_ 3 | 4 | namespace Framework 5 | { 6 | template 7 | inline const T& MIN(const T& a, const T& b) 8 | { 9 | return (a < b) ? a : b; 10 | } 11 | 12 | template 13 | inline const T& MAX(const T& a, const T& b) 14 | { 15 | return (a > b) ? a : b; 16 | } 17 | 18 | inline uint32_t UpperPow2(uint32_t v) 19 | { 20 | --v; 21 | v |= v >> 1; 22 | v |= v >> 2; 23 | v |= v >> 4; 24 | v |= v >> 8; 25 | v |= v >> 16; 26 | return ++v; 27 | } 28 | } 29 | 30 | #endif // FUNCTIONS_H_ 31 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Math/Matrix3.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX3_H_ 2 | #define MATRIX3_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Matrix4; 9 | 10 | class Matrix3 11 | { 12 | public: 13 | float m_m[9]; 14 | 15 | Matrix3(); 16 | virtual ~Matrix3(); 17 | 18 | void Identify(); 19 | Vector3 Transform(const Vector3& in) const; 20 | Vector3 TransformTranspose(const Vector3& in) const; 21 | void RotateAroundX(const float radians); 22 | void RotateAroundY(const float radians); 23 | void RotateAroundZ(const float radians); 24 | 25 | Matrix3& operator=(const Matrix3& in); 26 | Matrix3& operator=(const Matrix4& in); 27 | 28 | Matrix3 Multiply(const Matrix3& input) const; 29 | }; 30 | 31 | } /* namespace Framework */ 32 | #endif /* MATRIX3_H_ */ 33 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Math/Matrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX4_H_ 2 | #define MATRIX4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Vector4; 9 | class Matrix3; 10 | 11 | class Matrix4 12 | { 13 | public: 14 | enum Rows 15 | { 16 | X, 17 | Y, 18 | Z, 19 | W, 20 | NUM_ROWS 21 | }; 22 | 23 | float m_m[16]; 24 | 25 | Matrix4(); 26 | virtual ~Matrix4(); 27 | 28 | void Identify(); 29 | Vector3 Transform(const Vector3& in) const; 30 | Vector3 TransformTranspose(const Vector3& in) const; 31 | Vector4 Multiply(const Vector4& in) const; 32 | void RotateAroundX(float radians); 33 | void RotateAroundY(float radians); 34 | void RotateAroundZ(float radians); 35 | void Multiply(const Matrix4& in, Matrix4& out) const; 36 | 37 | Matrix4 Transpose() const; 38 | 39 | Matrix4& operator=(const Matrix3& in); 40 | Matrix4& operator=(const Matrix4& in); 41 | 42 | Vector4 GetRow(const Rows row) const; 43 | }; 44 | 45 | } /* namespace Framework */ 46 | #endif /* MATRIX4_H_ */ 47 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Math/Plane.cpp: -------------------------------------------------------------------------------- 1 | #include "Plane.h" 2 | 3 | namespace Framework 4 | { 5 | Plane::Plane() 6 | : m_d(0.0f) 7 | { 8 | } 9 | 10 | Plane::Plane(const Vector3& point, const Vector3& normal) 11 | { 12 | BuildPlane(point, normal); 13 | } 14 | 15 | Plane::~Plane() 16 | { 17 | 18 | } 19 | 20 | void Plane::BuildPlane(const Vector3& point, const Vector3& normal) 21 | { 22 | m_normal = normal; 23 | m_normal.Normalize(); 24 | m_d = m_normal.Dot(point); 25 | } 26 | 27 | bool Plane::IsInFront(const Vector4& point) const 28 | { 29 | return IsInFront(Vector3(point.m_x, point.m_y, point.m_z)); 30 | } 31 | 32 | bool Plane::IsInFront(const Vector3& point) const 33 | { 34 | return m_normal.Dot(point) >= m_d; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Math/Plane.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANE_H_ 2 | #define PLANE_H_ 3 | 4 | #include "Vector4.h" 5 | #include "Vector3.h" 6 | 7 | namespace Framework 8 | { 9 | class Plane 10 | { 11 | private: 12 | Vector3 m_normal; 13 | float m_d; 14 | 15 | public: 16 | Plane(); 17 | Plane(const Vector3& point, const Vector3& normal); 18 | ~Plane(); 19 | 20 | void BuildPlane(const Vector3& point, const Vector3& normal); 21 | 22 | bool IsInFront(const Vector4& point) const; 23 | bool IsInFront(const Vector3& point) const; 24 | }; 25 | } 26 | 27 | #endif // PLANE_H_ 28 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Math/Vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR3_H_ 2 | #define VECTOR3_H_ 3 | 4 | #include "Vector4.h" 5 | 6 | namespace Framework 7 | { 8 | 9 | class Vector3 10 | { 11 | public: 12 | float m_x; 13 | float m_y; 14 | float m_z; 15 | 16 | Vector3(); 17 | Vector3(const float x, const float y, const float z); 18 | virtual ~Vector3(); 19 | 20 | void Set(const Vector3& in); 21 | void Multiply(const float scalar); 22 | void Divide(const float scalar); 23 | void Add(const Vector3& in); 24 | void Subtract(const Vector3& in); 25 | void Negate(); 26 | float Length() const; 27 | float LengthSquared() const; 28 | void Normalize(); 29 | void GetNormal(Vector3& normal); 30 | 31 | Vector3& operator=(const Vector3& in); 32 | Vector3& operator=(const Vector4& in); 33 | 34 | float Dot(const Vector3& in) const; 35 | Vector3 Cross(const Vector3& in) const; 36 | }; 37 | 38 | } /* namespace Framework */ 39 | 40 | #endif /* VECTOR3_H_ */ 41 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Math/Vector4.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR4_H_ 2 | #define VECTOR4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector4 8 | { 9 | public: 10 | float m_x; 11 | float m_y; 12 | float m_z; 13 | float m_w; 14 | 15 | Vector4(); 16 | Vector4(const float x, const float y, const float z, const float w); 17 | virtual ~Vector4(); 18 | 19 | void Set(Vector4& in); 20 | void Multiply(float scalar); 21 | void Divide(float scalar); 22 | void Add(Vector4& in); 23 | void Subtract(Vector4& in); 24 | 25 | Vector4& operator=(const Vector4& in); 26 | }; 27 | 28 | } /* namespace Framework */ 29 | #endif /* VECTOR4_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Platform/Android.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROID_H_ 2 | #define ANDROID_H_ 3 | 4 | #include 5 | #include "../Kernel/Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Renderer; 10 | 11 | class Android 12 | : public Task 13 | { 14 | private: 15 | static bool m_bClosing; 16 | android_app* m_pState; 17 | 18 | public: 19 | Android(android_app* pState, const unsigned int priority); 20 | virtual ~Android(); 21 | 22 | android_app* GetAppState() { return m_pState; } 23 | 24 | virtual bool Start(); 25 | virtual void OnSuspend(); 26 | virtual void Update(); 27 | virtual void OnResume(); 28 | virtual void Stop(); 29 | 30 | static void ClearClosing() { m_bClosing = false; } 31 | static bool IsClosing() { return m_bClosing; } 32 | }; 33 | } 34 | 35 | #endif // ANDROID_H_ 36 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Renderer/Geometry/Geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Geometry.cpp 3 | * 4 | * Created on: 05/06/2012 5 | * Author: bruce 6 | */ 7 | 8 | #include "Geometry.h" 9 | 10 | namespace Framework 11 | { 12 | Geometry::Geometry() 13 | : m_numVertices(0) 14 | , m_numIndices(0) 15 | , m_pVertices(NULL) 16 | , m_pIndices(NULL) 17 | , m_numVertexPositionElements(0) 18 | , m_numTexCoordElements(0) 19 | , m_vertexStride(0) 20 | { 21 | } 22 | 23 | Geometry::~Geometry() 24 | { 25 | } 26 | } // Framework 27 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Renderer/Shaders/BasicShader.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSHADER_H_ 2 | #define BASICSHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class BasicShader 9 | : public Shader 10 | { 11 | private: 12 | GLint m_positionAttributeHandle; 13 | 14 | public: 15 | BasicShader(); 16 | virtual ~BasicShader(); 17 | 18 | virtual void Link(); 19 | virtual void Setup(Renderable& renderable); 20 | }; 21 | } 22 | 23 | #endif // BASICSHADER_H_ 24 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Renderer/Shaders/Shader.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_H_ 2 | #define SHADER_H_ 3 | 4 | #include 5 | #include 6 | #include "../Renderable.h" 7 | 8 | namespace Framework 9 | { 10 | class Shader 11 | { 12 | private: 13 | void LoadShader(GLenum shaderType, std::string& shaderCode); 14 | 15 | protected: 16 | GLuint m_vertexShaderId; 17 | GLuint m_fragmentShaderId; 18 | GLint m_programId; 19 | 20 | std::string m_vertexShaderCode; 21 | std::string m_fragmentShaderCode; 22 | 23 | bool m_isLinked; 24 | 25 | public: 26 | Shader(); 27 | virtual ~Shader(); 28 | 29 | virtual void Link(); 30 | virtual void Setup(Renderable& renderable); 31 | 32 | bool IsLinked() { return m_isLinked; } 33 | }; 34 | } 35 | 36 | #endif // SHADER_H_ 37 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Renderer/Shaders/TextureShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURESHADER_H_ 2 | #define TEXTURESHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class Texture; 9 | 10 | class TextureShader 11 | : public Shader 12 | { 13 | private: 14 | Texture* m_pTexture; 15 | GLint m_positionAttributeHandle; 16 | GLint m_texCoordAttributeHandle; 17 | GLint m_samplerHandle; 18 | 19 | public: 20 | TextureShader(); 21 | virtual ~TextureShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | 26 | void SetTexture(Texture* pTexture); 27 | Texture* GetTexture(); 28 | }; 29 | 30 | inline void TextureShader::SetTexture(Texture* pTexture) 31 | { 32 | m_pTexture = pTexture; 33 | } 34 | 35 | inline Texture* TextureShader::GetTexture() 36 | { 37 | return m_pTexture; 38 | } 39 | } 40 | 41 | #endif // TEXTURESHADER_H_ 42 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Renderer/Shaders/TransformAmbientDiffuseShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMAMBIENTDIFFUSESHADER_H_ 2 | #define TRANSFORMAMBIENTDIFFUSESHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformAmbientDiffuseShader 10 | : public Shader 11 | { 12 | private: 13 | GLint m_modelViewProjUniformHandle; 14 | GLint m_modelITMatrixUniformHandle; 15 | GLint m_positionAttributeHandle; 16 | GLint m_normalAttributeHandle; 17 | GLint m_ambientColorUniformHandle; 18 | GLint m_diffuseColorUniformHandle; 19 | GLint m_ambientLightUniformHandle; 20 | GLint m_diffuseLightUniformHandle; 21 | GLint m_lightDirectionUniformHandle; 22 | 23 | public: 24 | TransformAmbientDiffuseShader(); 25 | virtual ~TransformAmbientDiffuseShader(); 26 | 27 | virtual void Link(); 28 | virtual void Setup(Renderable& renderable); 29 | }; 30 | } 31 | 32 | #endif // TRANSFORMAMBIENTDIFFUSESHADER_H_ 33 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Renderer/Shaders/TransformAmbientShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMAMBIENTSHADER_H_ 2 | #define TRANSFORMAMBIENTSHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformAmbientShader 10 | : public Shader 11 | { 12 | private: 13 | GLint m_transformUniformHandle; 14 | GLint m_positionAttributeHandle; 15 | GLint m_normalAttributeHandle; 16 | GLint m_colorUniformHandle; 17 | GLint m_ambientLightUniformHandle; 18 | 19 | public: 20 | TransformAmbientShader(); 21 | virtual ~TransformAmbientShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | }; 26 | } 27 | 28 | #endif // TRANSFORMAMBIENTSHADER_H_ 29 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Renderer/Shaders/TransformShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMSHADER_H_ 2 | #define TRANSFORMSHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformShader 10 | : public Shader 11 | { 12 | private: 13 | GLint m_transformUniformHandle; 14 | GLint m_positionAttributeHandle; 15 | GLint m_colorAttributeHandle; 16 | 17 | public: 18 | TransformShader(); 19 | virtual ~TransformShader(); 20 | 21 | virtual void Link(); 22 | virtual void Setup(Renderable& renderable); 23 | }; 24 | } 25 | 26 | #endif // TRANSFORMSHADER_H_ 27 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Utilities/File.cpp: -------------------------------------------------------------------------------- 1 | #include "File.h" 2 | #include 3 | 4 | namespace Framework 5 | { 6 | AAssetManager* File::m_pAssetManager = NULL; 7 | 8 | File::File(std::string name) 9 | : m_filename(name) 10 | { 11 | assert(m_pAssetManager != NULL); 12 | m_pAsset = NULL; 13 | } 14 | 15 | File::~File() 16 | { 17 | Close(); 18 | } 19 | 20 | bool File::Open() 21 | { 22 | assert(m_pAssetManager != NULL); 23 | 24 | m_pAsset = AAssetManager_open(m_pAssetManager, m_filename.c_str(), AASSET_MODE_UNKNOWN); 25 | return !!m_pAsset; 26 | } 27 | 28 | void File::Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead) 29 | { 30 | bytesRead = AAsset_read(m_pAsset, pBuffer, bytesToRead); 31 | } 32 | 33 | void File::Close() 34 | { 35 | if (m_pAsset) 36 | { 37 | AAsset_close(m_pAsset); 38 | m_pAsset = NULL; 39 | } 40 | } 41 | 42 | unsigned int File::Length() const 43 | { 44 | return AAsset_getLength(m_pAsset); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Utilities/File.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H_ 2 | #define FILE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace Framework 8 | { 9 | class File 10 | { 11 | private: 12 | std::string m_filename; 13 | static AAssetManager* m_pAssetManager; 14 | AAsset* m_pAsset; 15 | 16 | public: 17 | explicit File(std::string name); 18 | virtual ~File(); 19 | 20 | bool Open(); 21 | void Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead); 22 | void Close(); 23 | 24 | unsigned int Length() const; 25 | 26 | static const size_t READ_FAILED = 0xFFFFFFFF; 27 | 28 | static void SetAssetManager(AAssetManager* pAssetManager) { m_pAssetManager = pAssetManager; } 29 | }; 30 | } 31 | 32 | #endif // FILE_H_ 33 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Utilities/Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_H_ 2 | #define HASH_H_ 3 | 4 | #include 5 | 6 | namespace Framework 7 | { 8 | // SDBM Hash 9 | inline unsigned int Hash(const std::string& key) 10 | { 11 | unsigned int result = 0; 12 | 13 | for (unsigned int i=0; i 5 | 6 | namespace Framework 7 | { 8 | template 9 | class Singleton 10 | { 11 | private: 12 | static T* ms_singleton; 13 | 14 | public: 15 | Singleton() 16 | { 17 | assert(!ms_singleton); 18 | ms_singleton = static_cast(this); 19 | } 20 | 21 | ~Singleton() 22 | { 23 | assert(ms_singleton); 24 | ms_singleton = 0; 25 | } 26 | 27 | static T& GetSingleton() { return *ms_singleton; } 28 | static T* GetSingletonPtr() { return ms_singleton; } 29 | }; 30 | 31 | template T* Singleton::ms_singleton = 0; 32 | } 33 | 34 | #endif // SINGLETON_H_ 35 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/jni/Framework/Utilities/TGAFile.cpp: -------------------------------------------------------------------------------- 1 | #include "TGAFile.h" 2 | 3 | namespace Framework 4 | { 5 | TGAFile::TGAFile(void* pData) 6 | { 7 | size_t size = sizeof(unsigned short); 8 | m_pHeader = static_cast(pData); 9 | m_pImageData = static_cast(static_cast(pData) + sizeof(TGAHeader)); 10 | } 11 | 12 | TGAFile::~TGAFile() 13 | { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/keystore/Chapter10.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter10/Chapter10/keystore/Chapter10.keystore -------------------------------------------------------------------------------- /Chapter10/Chapter10/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter10/Chapter10/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter10/Chapter10/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter10/Chapter10/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter10/Chapter10/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter10/Chapter10/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter10/Chapter10/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Chapter10 4 | 5 | -------------------------------------------------------------------------------- /Chapter10/Chapter10/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-10 12 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2010 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := hellodroid 20 | LOCAL_SRC_FILES := main.cpp 21 | LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 22 | LOCAL_STATIC_LIBRARIES := android_native_app_glue 23 | 24 | include $(BUILD_SHARED_LIBRARY) 25 | 26 | $(call import-module,android/native_app_glue) 27 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 -------------------------------------------------------------------------------- /Chapter2/HelloDroid/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter2/HelloDroid/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter2/HelloDroid/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter2/HelloDroid/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter2/HelloDroid/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter2/HelloDroid/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter2/HelloDroid/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | HelloDroid 4 | 5 | -------------------------------------------------------------------------------- /Chapter2/HelloDroid/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_ARM_MODE := arm 6 | LOCAL_MODULE := Chapter4 7 | LOCAL_C_INCLUDES := $(LOCAL_PATH) 8 | LOCAL_SRC_FILES := Chapter4.cpp \ 9 | Framework/Application/Application.cpp \ 10 | Framework/Kernel/Kernel.cpp \ 11 | Framework/Platform/Android.cpp \ 12 | Framework/Utilities/Timer.cpp 13 | LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 14 | LOCAL_STATIC_LIBRARIES := android_native_app_glue 15 | 16 | include $(BUILD_SHARED_LIBRARY) 17 | 18 | $(call import-module,android/native_app_glue) 19 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 2 | APP_STL := stlport_static -------------------------------------------------------------------------------- /Chapter4/Chapter4/jni/Chapter4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Framework/Application/Application.h" 4 | 5 | void android_main(struct android_app* state) 6 | { 7 | app_dummy(); 8 | 9 | Framework::Application app(state); 10 | 11 | if (app.Initialize()) 12 | { 13 | app.Run(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/jni/Framework/Application/Application.cpp: -------------------------------------------------------------------------------- 1 | #include "Application.h" 2 | 3 | namespace Framework 4 | { 5 | Application::Application(android_app* state) 6 | : m_androidTask(state, Task::PLATFORM_PRIORITY) 7 | , m_timerTask(Task::TIMER_PRIORITY) 8 | { 9 | } 10 | 11 | Application::~Application() 12 | { 13 | 14 | } 15 | 16 | bool Application::Initialize() 17 | { 18 | bool ret = true; 19 | 20 | m_kernel.AddTask(&m_androidTask); 21 | m_kernel.AddTask(&m_timerTask); 22 | 23 | return ret; 24 | } 25 | 26 | void Application::Run() 27 | { 28 | m_kernel.Execute(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/jni/Framework/Application/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H_ 2 | #define APPLICATION_H_ 3 | 4 | #include "../Kernel/Kernel.h" 5 | #include "../Platform/Android.h" 6 | #include "../Utilities/Timer.h" 7 | #include 8 | 9 | namespace Framework 10 | { 11 | class Application 12 | { 13 | private: 14 | Kernel m_kernel; 15 | Android m_androidTask; 16 | Timer m_timerTask; 17 | 18 | public: 19 | Application(android_app* state); 20 | virtual ~Application(); 21 | 22 | bool Initialize(); 23 | void Run(); 24 | }; 25 | } 26 | 27 | #endif // APPLICATION_H_ 28 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/jni/Framework/Kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef KERNEL_H_ 2 | #define KERNEL_H_ 3 | 4 | #include 5 | #include "Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Kernel 10 | { 11 | private: 12 | typedef std::list TaskList; 13 | typedef std::list::iterator TaskListIterator; 14 | 15 | TaskList m_tasks; 16 | TaskList m_pausedTasks; 17 | 18 | void PriorityAdd(Task* pTask); 19 | 20 | public: 21 | Kernel(); 22 | virtual ~Kernel(); 23 | 24 | void Execute(); 25 | 26 | bool AddTask(Task* pTask); 27 | void SuspendTask(Task* task); 28 | void ResumeTask(Task* task); 29 | void RemoveTask(Task* task); 30 | void KillAllTasks(); 31 | 32 | bool HasTasks() { return m_tasks.size(); } 33 | }; 34 | } 35 | 36 | #endif // KERNEL_H_ 37 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/jni/Framework/Platform/Android.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROID_H_ 2 | #define ANDROID_H_ 3 | 4 | #include 5 | #include "../Kernel/Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Android 10 | : public Task 11 | { 12 | private: 13 | static bool m_bClosing; 14 | static bool m_bPaused; 15 | android_app* m_pState; 16 | 17 | public: 18 | Android(android_app* pState, const unsigned int priority); 19 | virtual ~Android(); 20 | 21 | android_app* GetAppState() { return m_pState; } 22 | 23 | virtual bool Start(); 24 | virtual void OnSuspend(); 25 | virtual void Update(); 26 | virtual void OnResume(); 27 | virtual void Stop(); 28 | 29 | static void ClearClosing() { m_bClosing = false; } 30 | static bool IsClosing() { return m_bClosing; } 31 | static void SetPaused(const bool paused) { m_bPaused = paused; } 32 | static bool IsPaused() { return m_bPaused; } 33 | }; 34 | } 35 | 36 | #endif // ANDROID_H_ 37 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter4/Chapter4/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter4/Chapter4/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter4/Chapter4/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter4/Chapter4/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter4/Chapter4/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter4/Chapter4/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Chapter2 4 | 5 | -------------------------------------------------------------------------------- /Chapter4/Chapter4/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/assets/test.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter5/Chapter5/assets/test.tga -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 2 | APP_STL := stlport_static -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Chapter5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Chapter5App.h" 4 | #include 5 | 6 | void android_main(struct android_app* state) 7 | { 8 | sleep(5); 9 | 10 | app_dummy(); 11 | 12 | Chapter5App app(state); 13 | 14 | if (app.Initialize()) 15 | { 16 | app.Run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Chapter5App.cpp: -------------------------------------------------------------------------------- 1 | #include "Chapter5App.h" 2 | 3 | Chapter5App::Chapter5App(android_app* pState) 4 | : Framework::Application(pState) 5 | , m_chapter5Task(&m_rendererTask, Framework::Task::GAME_PRIORITY) 6 | { 7 | } 8 | 9 | Chapter5App::~Chapter5App() 10 | { 11 | 12 | } 13 | 14 | bool Chapter5App::Initialize() 15 | { 16 | bool success = Framework::Application::Initialize(); 17 | 18 | if (success) 19 | { 20 | m_kernel.AddTask(&m_chapter5Task); 21 | } 22 | 23 | return success; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Chapter5App.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER5APP_H_ 2 | #define CHAPTER5APP_H_ 3 | 4 | #include "Framework/Application/Application.h" 5 | #include "Chapter5Task.h" 6 | #include 7 | 8 | class Chapter5App 9 | : public Framework::Application 10 | { 11 | private: 12 | Chapter5Task m_chapter5Task; 13 | 14 | public: 15 | Chapter5App(android_app* pState); 16 | virtual ~Chapter5App(); 17 | 18 | virtual bool Initialize(); 19 | }; 20 | 21 | #endif // CHAPTER5APP_H_ 22 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Application/Application.cpp: -------------------------------------------------------------------------------- 1 | #include "Application.h" 2 | #include "../Utilities/File.h" 3 | 4 | namespace Framework 5 | { 6 | Application::Application(android_app* state) 7 | : m_rendererTask(state, Task::RENDER_PRIORITY) 8 | , m_androidTask(state, Task::PLATFORM_PRIORITY, &m_rendererTask) 9 | , m_timerTask(Task::TIMER_PRIORITY) 10 | { 11 | File::SetAssetManager(state->activity->assetManager); 12 | } 13 | 14 | Application::~Application() 15 | { 16 | 17 | } 18 | 19 | bool Application::Initialize() 20 | { 21 | bool ret = true; 22 | 23 | m_kernel.AddTask(&m_androidTask); 24 | m_kernel.AddTask(&m_timerTask); 25 | m_kernel.AddTask(&m_rendererTask); 26 | 27 | return ret; 28 | } 29 | 30 | void Application::Run() 31 | { 32 | m_kernel.Execute(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Application/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H_ 2 | #define APPLICATION_H_ 3 | 4 | #include "../Kernel/Kernel.h" 5 | #include "../Platform/Android.h" 6 | #include "../Renderer/Renderer.h" 7 | #include "../Utilities/Timer.h" 8 | #include 9 | 10 | namespace Framework 11 | { 12 | class Application 13 | { 14 | protected: 15 | Kernel m_kernel; 16 | Android m_androidTask; 17 | Timer m_timerTask; 18 | Renderer m_rendererTask; 19 | 20 | public: 21 | explicit Application(android_app* state); 22 | virtual ~Application(); 23 | 24 | virtual bool Initialize(); 25 | virtual void Run(); 26 | }; 27 | } 28 | 29 | #endif // APPLICATION_H_ 30 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef KERNEL_H_ 2 | #define KERNEL_H_ 3 | 4 | #include 5 | #include "Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Kernel 10 | { 11 | private: 12 | typedef std::list TaskList; 13 | typedef std::list::iterator TaskListIterator; 14 | 15 | TaskList m_tasks; 16 | TaskList m_pausedTasks; 17 | 18 | void PriorityAdd(Task* pTask); 19 | 20 | public: 21 | Kernel(); 22 | virtual ~Kernel(); 23 | 24 | void Execute(); 25 | 26 | bool AddTask(Task* pTask); 27 | void SuspendTask(Task* task); 28 | void ResumeTask(Task* task); 29 | void RemoveTask(Task* task); 30 | void KillAllTasks(); 31 | 32 | bool HasTasks() { return m_tasks.size(); } 33 | }; 34 | } 35 | 36 | #endif // KERNEL_H_ 37 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Platform/Android.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROID_H_ 2 | #define ANDROID_H_ 3 | 4 | #include 5 | #include "../Kernel/Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Renderer; 10 | 11 | class Android 12 | : public Task 13 | { 14 | private: 15 | static bool m_bClosing; 16 | static bool m_bPaused; 17 | android_app* m_pState; 18 | 19 | public: 20 | Android(android_app* pState, const unsigned int priority, Renderer* pRenderer); 21 | virtual ~Android(); 22 | 23 | android_app* GetAppState() { return m_pState; } 24 | 25 | virtual bool Start(); 26 | virtual void OnSuspend(); 27 | virtual void Update(); 28 | virtual void OnResume(); 29 | virtual void Stop(); 30 | 31 | static void ClearClosing() { m_bClosing = false; } 32 | static bool IsClosing() { return m_bClosing; } 33 | static void SetPaused(const bool paused) { m_bPaused = paused; } 34 | static bool IsPaused() { return m_bPaused; } 35 | }; 36 | } 37 | 38 | #endif // ANDROID_H_ 39 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Renderer/Geometry/Geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Geometry.cpp 3 | * 4 | * Created on: 05/06/2012 5 | * Author: bruce 6 | */ 7 | 8 | #include "Geometry.h" 9 | 10 | namespace Framework 11 | { 12 | Geometry::Geometry() 13 | : m_numVertices(0) 14 | , m_numIndices(0) 15 | , m_pVertices(NULL) 16 | , m_pIndices(NULL) 17 | , m_numVertexPositionElements(0) 18 | , m_numTexCoordElements(0) 19 | , m_vertexStride(0) 20 | { 21 | } 22 | 23 | Geometry::~Geometry() 24 | { 25 | } 26 | } // Framework 27 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Renderer/Shaders/BasicShader.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSHADER_H_ 2 | #define BASICSHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class BasicShader 9 | : public Shader 10 | { 11 | private: 12 | GLint m_positionAttributeHandle; 13 | 14 | public: 15 | BasicShader(); 16 | virtual ~BasicShader(); 17 | 18 | virtual void Link(); 19 | virtual void Setup(Renderable& renderable); 20 | }; 21 | } 22 | 23 | #endif // BASICSHADER_H_ 24 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Renderer/Shaders/Shader.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_H_ 2 | #define SHADER_H_ 3 | 4 | #include 5 | #include 6 | #include "../Renderable.h" 7 | 8 | namespace Framework 9 | { 10 | class Shader 11 | { 12 | private: 13 | void LoadShader(GLenum shaderType, std::string& shaderCode); 14 | 15 | protected: 16 | GLuint m_vertexShaderId; 17 | GLuint m_fragmentShaderId; 18 | GLint m_programId; 19 | 20 | std::string m_vertexShaderCode; 21 | std::string m_fragmentShaderCode; 22 | 23 | bool m_isLinked; 24 | 25 | public: 26 | Shader(); 27 | virtual ~Shader(); 28 | 29 | virtual void Link(); 30 | virtual void Setup(Renderable& renderable); 31 | 32 | bool IsLinked() { return m_isLinked; } 33 | }; 34 | } 35 | 36 | #endif // SHADER_H_ 37 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Renderer/Shaders/TextureShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURESHADER_H_ 2 | #define TEXTURESHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class Texture; 9 | 10 | class TextureShader 11 | : public Shader 12 | { 13 | private: 14 | Texture* m_pTexture; 15 | GLint m_positionAttributeHandle; 16 | GLint m_texCoordAttributeHandle; 17 | GLint m_samplerHandle; 18 | 19 | public: 20 | TextureShader(); 21 | virtual ~TextureShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | 26 | void SetTexture(Texture* pTexture); 27 | Texture* GetTexture(); 28 | }; 29 | 30 | inline void TextureShader::SetTexture(Texture* pTexture) 31 | { 32 | m_pTexture = pTexture; 33 | } 34 | 35 | inline Texture* TextureShader::GetTexture() 36 | { 37 | return m_pTexture; 38 | } 39 | } 40 | 41 | #endif // TEXTURESHADER_H_ 42 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Renderer/Textures/Texture.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURE_H_ 2 | #define TEXTURE_H_ 3 | 4 | #include 5 | 6 | namespace Framework 7 | { 8 | class Texture 9 | { 10 | public: 11 | struct Header 12 | { 13 | unsigned int m_width; 14 | unsigned int m_height; 15 | unsigned int m_bytesPerPixel; 16 | unsigned int m_dataSize; 17 | 18 | Header() 19 | : m_width(0) 20 | , m_height(0) 21 | , m_bytesPerPixel(0) 22 | , m_dataSize(0) 23 | { 24 | 25 | } 26 | 27 | Header(const Header& header) 28 | { 29 | m_width = header.m_width; 30 | m_height = header.m_height; 31 | m_bytesPerPixel = header.m_bytesPerPixel; 32 | m_dataSize = header.m_dataSize; 33 | } 34 | }; 35 | 36 | private: 37 | GLuint m_id; 38 | Header m_header; 39 | void* m_pImageData; 40 | 41 | public: 42 | Texture(); 43 | ~Texture(); 44 | 45 | void SetData(Header& header, void* pImageData); 46 | 47 | GLuint GetId() const { return m_id; } 48 | 49 | void Init(); 50 | }; 51 | } 52 | 53 | #endif // TEXTURE_H_ 54 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Utilities/File.cpp: -------------------------------------------------------------------------------- 1 | #include "File.h" 2 | #include 3 | 4 | namespace Framework 5 | { 6 | AAssetManager* File::m_pAssetManager = NULL; 7 | 8 | File::File(std::string name) 9 | : m_filename(name) 10 | { 11 | assert(m_pAssetManager != NULL); 12 | m_pAsset = NULL; 13 | } 14 | 15 | File::~File() 16 | { 17 | Close(); 18 | } 19 | 20 | bool File::Open() 21 | { 22 | assert(m_pAssetManager != NULL); 23 | 24 | m_pAsset = AAssetManager_open(m_pAssetManager, m_filename.c_str(), AASSET_MODE_UNKNOWN); 25 | return !!m_pAsset; 26 | } 27 | 28 | void File::Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead) 29 | { 30 | bytesRead = AAsset_read(m_pAsset, pBuffer, bytesToRead); 31 | } 32 | 33 | void File::Close() 34 | { 35 | if (m_pAsset) 36 | { 37 | AAsset_close(m_pAsset); 38 | m_pAsset = NULL; 39 | } 40 | } 41 | 42 | unsigned int File::Length() const 43 | { 44 | return AAsset_getLength(m_pAsset); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Utilities/File.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H_ 2 | #define FILE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace Framework 8 | { 9 | class File 10 | { 11 | private: 12 | std::string m_filename; 13 | static AAssetManager* m_pAssetManager; 14 | AAsset* m_pAsset; 15 | 16 | public: 17 | explicit File(std::string name); 18 | virtual ~File(); 19 | 20 | bool Open(); 21 | void Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead); 22 | void Close(); 23 | 24 | unsigned int Length() const; 25 | 26 | static const size_t READ_FAILED = 0xFFFFFFFF; 27 | 28 | static void SetAssetManager(AAssetManager* pAssetManager) { m_pAssetManager = pAssetManager; } 29 | }; 30 | } 31 | 32 | #endif // FILE_H_ 33 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/jni/Framework/Utilities/TGAFile.cpp: -------------------------------------------------------------------------------- 1 | #include "TGAFile.h" 2 | 3 | namespace Framework 4 | { 5 | TGAFile::TGAFile(void* pData) 6 | { 7 | size_t size = sizeof(unsigned short); 8 | m_pHeader = static_cast(pData); 9 | m_pImageData = static_cast(static_cast(pData) + sizeof(TGAHeader)); 10 | } 11 | 12 | TGAFile::~TGAFile() 13 | { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter5/Chapter5/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter5/Chapter5/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter5/Chapter5/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter5/Chapter5/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter5/Chapter5/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter5/Chapter5/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Chapter5 4 | 5 | -------------------------------------------------------------------------------- /Chapter5/Chapter5/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/assets/test.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter6/Chapter6/assets/test.tga -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 2 | APP_STL := stlport_static -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Chapter6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Chapter6App.h" 4 | #include 5 | 6 | void android_main(struct android_app* state) 7 | { 8 | sleep(5); 9 | 10 | app_dummy(); 11 | 12 | Chapter6App app(state); 13 | 14 | if (app.Initialize()) 15 | { 16 | app.Run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Chapter6App.cpp: -------------------------------------------------------------------------------- 1 | #include "Chapter6App.h" 2 | 3 | Chapter6App::Chapter6App(android_app* pState) 4 | : Framework::Application(pState) 5 | , m_chapter6Task(Framework::Task::GAME_PRIORITY) 6 | { 7 | } 8 | 9 | Chapter6App::~Chapter6App() 10 | { 11 | 12 | } 13 | 14 | bool Chapter6App::Initialize() 15 | { 16 | bool success = Framework::Application::Initialize(); 17 | 18 | if (success) 19 | { 20 | m_kernel.AddTask(&m_chapter6Task); 21 | } 22 | 23 | return success; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Chapter6App.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER6APP_H_ 2 | #define CHAPTER6APP_H_ 3 | 4 | #include "Framework/Application/Application.h" 5 | #include "Chapter6Task.h" 6 | #include 7 | 8 | class Chapter6App 9 | : public Framework::Application 10 | { 11 | private: 12 | Chapter6Task m_chapter6Task; 13 | 14 | public: 15 | Chapter6App(android_app* pState); 16 | virtual ~Chapter6App(); 17 | 18 | virtual bool Initialize(); 19 | }; 20 | 21 | #endif // CHAPTER6APP_H_ 22 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Chapter6Task.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER6TASK_H_ 2 | #define CHAPTER6TASK_H_ 3 | 4 | #include "Framework/Kernel/Task.h" 5 | #include "Framework/Renderer/Geometry/Geometry.h" 6 | #include "Framework/Renderer/Textures/Texture.h" 7 | #include "Framework/Renderer/Shaders/TransformShader.h" 8 | #include "Framework/Renderer/Renderable.h" 9 | #include "Framework/Utilities/File.h" 10 | #include "Framework/GameObjects/GameObject.h" 11 | 12 | class Chapter6Task 13 | : public Framework::Task 14 | { 15 | private: 16 | Framework::Geometry m_geometry; 17 | Framework::TransformShader m_transformShader; 18 | 19 | Framework::GameObject m_playerObject; 20 | Framework::GameObject m_aiObject; 21 | 22 | public: 23 | Chapter6Task(const unsigned int priority); 24 | virtual ~Chapter6Task(); 25 | 26 | // From Task 27 | virtual bool Start(); 28 | virtual void OnSuspend(); 29 | virtual void Update(); 30 | virtual void OnResume(); 31 | virtual void Stop(); 32 | }; 33 | 34 | #endif // CHAPTER6TASK_H_ 35 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Application/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H_ 2 | #define APPLICATION_H_ 3 | 4 | #include "../Kernel/Kernel.h" 5 | #include "../Platform/Android.h" 6 | #include 7 | 8 | namespace Framework 9 | { 10 | class Application 11 | { 12 | protected: 13 | android_app* m_pAppState; 14 | Kernel m_kernel; 15 | Android m_androidTask; 16 | 17 | virtual void CreateSingletons(); 18 | virtual void DestroySingletons(); 19 | 20 | public: 21 | explicit Application(android_app* state); 22 | virtual ~Application(); 23 | 24 | virtual bool Initialize(); 25 | virtual void Run(); 26 | }; 27 | } 28 | 29 | #endif // APPLICATION_H_ 30 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/EventManager/Event.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_H_ 2 | #define EVENT_H_ 3 | 4 | #include 5 | #include "EventHandler.h" 6 | #include "EventId.h" 7 | 8 | namespace Framework 9 | { 10 | class Event 11 | { 12 | private: 13 | typedef std::vector EventHandlerList; 14 | typedef EventHandlerList::iterator EventHandlerListIterator; 15 | 16 | EventHandlerList m_listeners; 17 | EventID m_id; 18 | 19 | public: 20 | explicit Event(EventID eventId); 21 | ~Event(); 22 | 23 | void Send(); 24 | void SendToHandler(EventHandler& eventHandler); 25 | void AttachListener(EventHandler& eventHandler); 26 | void DetachListener(EventHandler& eventHandler); 27 | 28 | EventID GetID() const { return m_id; } 29 | }; 30 | } 31 | 32 | #endif // EVENT_H_ 33 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/EventManager/EventHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTHANDLER_H_ 2 | #define EVENTHANDLER_H_ 3 | 4 | namespace Framework 5 | { 6 | class Event; 7 | 8 | class EventHandler 9 | { 10 | public: 11 | virtual ~EventHandler() {} 12 | 13 | virtual void HandleEvent(Event* pEvent) = 0; 14 | }; 15 | } 16 | 17 | #endif // EVENTHANDLER_H_ 18 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/EventManager/EventId.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTID_H_ 2 | #define EVENTID_H_ 3 | 4 | namespace Framework 5 | { 6 | typedef unsigned int EventID; 7 | 8 | static const EventID UPDATE_EVENT = 0; 9 | static const EventID RENDER_EVENT = 1; 10 | static const EventID JUMP_EVENT = 2; 11 | } 12 | 13 | #endif // EVENTID_H_ 14 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/GameObjects/Component.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENT_H_ 2 | #define COMPONENT_H_ 3 | 4 | #include "../Utilities/Hash.h" 5 | 6 | namespace Framework 7 | { 8 | class GameObject; 9 | 10 | class Component 11 | { 12 | private: 13 | GameObject* m_pOwner; 14 | 15 | public: 16 | explicit Component(GameObject* pOwner) 17 | : m_pOwner(pOwner) 18 | { 19 | } 20 | 21 | virtual ~Component() {} 22 | 23 | virtual void Initialize() = 0; 24 | 25 | GameObject* GetOwner() { return m_pOwner; } 26 | }; 27 | } 28 | 29 | #endif /* COMPONENT_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/GameObjects/Components/RenderableComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERABLECOMPONENT_H_ 2 | #define RENDERABLECOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Renderer/Renderable.h" 6 | #include "../../EventManager/EventHandler.h" 7 | #include "../../EventManager/EventId.h" 8 | 9 | namespace Framework 10 | { 11 | class RenderableComponent 12 | : public Component 13 | , public EventHandler 14 | { 15 | private: 16 | static const unsigned int s_id = 1; 17 | 18 | Renderable m_renderable; 19 | 20 | public: 21 | static unsigned int GetId() { return s_id; } 22 | 23 | explicit RenderableComponent(GameObject* pOwner); 24 | virtual ~RenderableComponent(); 25 | 26 | virtual void Initialize(); 27 | 28 | Renderable& GetRenderable() { return m_renderable; } 29 | 30 | virtual void HandleEvent(Event* pEvent); 31 | }; 32 | } 33 | 34 | #endif // RENDERABLECOMPONENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/GameObjects/Components/TransformComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "TransformComponent.h" 2 | 3 | namespace Framework 4 | { 5 | TransformComponent::TransformComponent(GameObject* pOwner) 6 | : Component(pOwner) 7 | { 8 | 9 | } 10 | 11 | TransformComponent::~TransformComponent() 12 | { 13 | 14 | } 15 | 16 | void TransformComponent::Initialize() 17 | { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/GameObjects/Components/TransformComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMCOMPONENT_H_ 2 | #define TRANSFORMCOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Math/Transform.h" 6 | 7 | namespace Framework 8 | { 9 | class GameObject; 10 | 11 | class TransformComponent 12 | : public Component 13 | { 14 | private: 15 | static const unsigned int s_id = 0; 16 | 17 | Transform m_transform; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit TransformComponent(GameObject* pOwner); 23 | virtual ~TransformComponent(); 24 | 25 | virtual void Initialize(); 26 | 27 | Transform& GetTransform() { return m_transform; } 28 | }; 29 | } 30 | 31 | #endif // TRANSFORMCOMPONENT_H_ 32 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/GameObjects/GameObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GameObject.h" 2 | 3 | namespace Framework 4 | { 5 | GameObject::GameObject() 6 | { 7 | 8 | } 9 | 10 | GameObject::~GameObject() 11 | { 12 | for (ComponentUnorderedMapIterator iter = m_components.begin(); iter != m_components.end(); ++iter) 13 | { 14 | Component* pComponent = iter->second; 15 | if (pComponent) 16 | { 17 | delete pComponent; 18 | pComponent = NULL; 19 | } 20 | } 21 | } 22 | 23 | Component* GameObject::GetComponent(unsigned int id) 24 | { 25 | ComponentUnorderedMapIterator result = m_components.find(id); 26 | return result == m_components.end() 27 | ? NULL 28 | : result->second; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef KERNEL_H_ 2 | #define KERNEL_H_ 3 | 4 | #include 5 | #include "Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Kernel 10 | { 11 | private: 12 | typedef std::list TaskList; 13 | typedef std::list::iterator TaskListIterator; 14 | 15 | TaskList m_tasks; 16 | TaskList m_pausedTasks; 17 | 18 | void PriorityAdd(Task* pTask); 19 | 20 | public: 21 | Kernel(); 22 | virtual ~Kernel(); 23 | 24 | void Execute(); 25 | 26 | bool AddTask(Task* pTask); 27 | void SuspendTask(Task* task); 28 | void ResumeTask(Task* task); 29 | void RemoveTask(Task* task); 30 | void KillAllTasks(); 31 | 32 | bool HasTasks() { return m_tasks.size(); } 33 | }; 34 | } 35 | 36 | #endif // KERNEL_H_ 37 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Math/Functions.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONS_H_ 2 | #define FUNCTIONS_H_ 3 | 4 | namespace Framework 5 | { 6 | template 7 | inline const T& MIN(const T& a, const T& b) 8 | { 9 | return (a < b) ? a : b; 10 | } 11 | 12 | template 13 | inline const T& MAX(const T& a, const T& b) 14 | { 15 | return (a > b) ? a : b; 16 | } 17 | 18 | inline uint32_t UpperPow2(uint32_t v) 19 | { 20 | --v; 21 | v |= v >> 1; 22 | v |= v >> 2; 23 | v |= v >> 4; 24 | v |= v >> 8; 25 | v |= v >> 16; 26 | return ++v; 27 | } 28 | } 29 | 30 | #endif // FUNCTIONS_H_ 31 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Math/Matrix3.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX3_H_ 2 | #define MATRIX3_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Matrix4; 9 | 10 | class Matrix3 11 | { 12 | public: 13 | float m_m[9]; 14 | 15 | Matrix3(); 16 | virtual ~Matrix3(); 17 | 18 | void Identify(); 19 | Vector3 Transform(const Vector3& in) const; 20 | Vector3 TransformTranspose(const Vector3& in) const; 21 | void RotateAroundX(const float radians); 22 | void RotateAroundY(const float radians); 23 | void RotateAroundZ(const float radians); 24 | 25 | Matrix3& operator=(const Matrix3& in); 26 | Matrix3& operator=(const Matrix4& in); 27 | 28 | Matrix3 Multiply(const Matrix3& input) const; 29 | }; 30 | 31 | } /* namespace Framework */ 32 | #endif /* MATRIX3_H_ */ 33 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Math/Matrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX4_H_ 2 | #define MATRIX4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Vector4; 9 | class Matrix3; 10 | 11 | class Matrix4 12 | { 13 | public: 14 | enum Rows 15 | { 16 | X, 17 | Y, 18 | Z, 19 | W, 20 | NUM_ROWS 21 | }; 22 | 23 | float m_m[16]; 24 | 25 | Matrix4(); 26 | virtual ~Matrix4(); 27 | 28 | void Identify(); 29 | Vector3 Transform(const Vector3& in) const; 30 | Vector3 TransformTranspose(const Vector3& in) const; 31 | Vector4 Multiply(const Vector4& in) const; 32 | void RotateAroundX(float radians); 33 | void RotateAroundY(float radians); 34 | void RotateAroundZ(float radians); 35 | void Multiply(const Matrix4& in, Matrix4& out) const; 36 | 37 | Matrix4 Transpose() const; 38 | 39 | Matrix4& operator=(const Matrix3& in); 40 | Matrix4& operator=(const Matrix4& in); 41 | 42 | Vector4 GetRow(const Rows row) const; 43 | }; 44 | 45 | } /* namespace Framework */ 46 | #endif /* MATRIX4_H_ */ 47 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Math/Plane.cpp: -------------------------------------------------------------------------------- 1 | #include "Plane.h" 2 | 3 | namespace Framework 4 | { 5 | Plane::Plane() 6 | : m_d(0.0f) 7 | { 8 | } 9 | 10 | Plane::Plane(const Vector3& point, const Vector3& normal) 11 | { 12 | BuildPlane(point, normal); 13 | } 14 | 15 | Plane::~Plane() 16 | { 17 | 18 | } 19 | 20 | void Plane::BuildPlane(const Vector3& point, const Vector3& normal) 21 | { 22 | m_normal = normal; 23 | m_normal.Normalize(); 24 | m_d = m_normal.Dot(point); 25 | } 26 | 27 | bool Plane::IsInFront(const Vector4& point) const 28 | { 29 | return IsInFront(Vector3(point.m_x, point.m_y, point.m_z)); 30 | } 31 | 32 | bool Plane::IsInFront(const Vector3& point) const 33 | { 34 | return m_normal.Dot(point) >= m_d; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Math/Plane.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANE_H_ 2 | #define PLANE_H_ 3 | 4 | #include "Vector4.h" 5 | #include "Vector3.h" 6 | 7 | namespace Framework 8 | { 9 | class Plane 10 | { 11 | private: 12 | Vector3 m_normal; 13 | float m_d; 14 | 15 | public: 16 | Plane(); 17 | Plane(const Vector3& point, const Vector3& normal); 18 | ~Plane(); 19 | 20 | void BuildPlane(const Vector3& point, const Vector3& normal); 21 | 22 | bool IsInFront(const Vector4& point) const; 23 | bool IsInFront(const Vector3& point) const; 24 | }; 25 | } 26 | 27 | #endif // PLANE_H_ 28 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Math/Vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR3_H_ 2 | #define VECTOR3_H_ 3 | 4 | #include "Vector4.h" 5 | 6 | namespace Framework 7 | { 8 | 9 | class Vector3 10 | { 11 | public: 12 | float m_x; 13 | float m_y; 14 | float m_z; 15 | 16 | Vector3(); 17 | Vector3(const float x, const float y, const float z); 18 | virtual ~Vector3(); 19 | 20 | void Set(const Vector3& in); 21 | void Multiply(const float scalar); 22 | void Divide(const float scalar); 23 | void Add(const Vector3& in); 24 | void Subtract(const Vector3& in); 25 | void Negate(); 26 | float Length() const; 27 | float LengthSquared() const; 28 | void Normalize(); 29 | void GetNormal(Vector3& normal); 30 | 31 | Vector3& operator=(const Vector3& in); 32 | Vector3& operator=(const Vector4& in); 33 | 34 | float Dot(const Vector3& in) const; 35 | Vector3 Cross(const Vector3& in) const; 36 | }; 37 | 38 | } /* namespace Framework */ 39 | 40 | #endif /* VECTOR3_H_ */ 41 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Math/Vector4.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR4_H_ 2 | #define VECTOR4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector4 8 | { 9 | public: 10 | float m_x; 11 | float m_y; 12 | float m_z; 13 | float m_w; 14 | 15 | Vector4(); 16 | Vector4(const float x, const float y, const float z, const float w); 17 | virtual ~Vector4(); 18 | 19 | void Set(Vector4& in); 20 | void Multiply(float scalar); 21 | void Divide(float scalar); 22 | void Add(Vector4& in); 23 | void Subtract(Vector4& in); 24 | 25 | Vector4& operator=(const Vector4& in); 26 | }; 27 | 28 | } /* namespace Framework */ 29 | #endif /* VECTOR4_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Platform/Android.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROID_H_ 2 | #define ANDROID_H_ 3 | 4 | #include 5 | #include "../Kernel/Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Renderer; 10 | 11 | class Android 12 | : public Task 13 | { 14 | private: 15 | static bool m_bClosing; 16 | static bool m_bPaused; 17 | android_app* m_pState; 18 | 19 | public: 20 | Android(android_app* pState, const unsigned int priority); 21 | virtual ~Android(); 22 | 23 | android_app* GetAppState() { return m_pState; } 24 | 25 | virtual bool Start(); 26 | virtual void OnSuspend(); 27 | virtual void Update(); 28 | virtual void OnResume(); 29 | virtual void Stop(); 30 | 31 | static void ClearClosing() { m_bClosing = false; } 32 | static bool IsClosing() { return m_bClosing; } 33 | static void SetPaused(const bool paused) { m_bPaused = paused; } 34 | static bool IsPaused() { return m_bPaused; } 35 | }; 36 | } 37 | 38 | #endif // ANDROID_H_ 39 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Renderer/Geometry/Geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Geometry.cpp 3 | * 4 | * Created on: 05/06/2012 5 | * Author: bruce 6 | */ 7 | 8 | #include "Geometry.h" 9 | 10 | namespace Framework 11 | { 12 | Geometry::Geometry() 13 | : m_numVertices(0) 14 | , m_numIndices(0) 15 | , m_pVertices(NULL) 16 | , m_pIndices(NULL) 17 | , m_numVertexPositionElements(0) 18 | , m_numTexCoordElements(0) 19 | , m_vertexStride(0) 20 | { 21 | } 22 | 23 | Geometry::~Geometry() 24 | { 25 | } 26 | } // Framework 27 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Renderer/Shaders/BasicShader.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSHADER_H_ 2 | #define BASICSHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class BasicShader 9 | : public Shader 10 | { 11 | private: 12 | GLint m_positionAttributeHandle; 13 | 14 | public: 15 | BasicShader(); 16 | virtual ~BasicShader(); 17 | 18 | virtual void Link(); 19 | virtual void Setup(Renderable& renderable); 20 | }; 21 | } 22 | 23 | #endif // BASICSHADER_H_ 24 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Renderer/Shaders/Shader.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_H_ 2 | #define SHADER_H_ 3 | 4 | #include 5 | #include 6 | #include "../Renderable.h" 7 | 8 | namespace Framework 9 | { 10 | class Shader 11 | { 12 | private: 13 | void LoadShader(GLenum shaderType, std::string& shaderCode); 14 | 15 | protected: 16 | GLuint m_vertexShaderId; 17 | GLuint m_fragmentShaderId; 18 | GLint m_programId; 19 | 20 | std::string m_vertexShaderCode; 21 | std::string m_fragmentShaderCode; 22 | 23 | bool m_isLinked; 24 | 25 | public: 26 | Shader(); 27 | virtual ~Shader(); 28 | 29 | virtual void Link(); 30 | virtual void Setup(Renderable& renderable); 31 | 32 | bool IsLinked() { return m_isLinked; } 33 | }; 34 | } 35 | 36 | #endif // SHADER_H_ 37 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Renderer/Shaders/TextureShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURESHADER_H_ 2 | #define TEXTURESHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class Texture; 9 | 10 | class TextureShader 11 | : public Shader 12 | { 13 | private: 14 | Texture* m_pTexture; 15 | GLint m_positionAttributeHandle; 16 | GLint m_texCoordAttributeHandle; 17 | GLint m_samplerHandle; 18 | 19 | public: 20 | TextureShader(); 21 | virtual ~TextureShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | 26 | void SetTexture(Texture* pTexture); 27 | Texture* GetTexture(); 28 | }; 29 | 30 | inline void TextureShader::SetTexture(Texture* pTexture) 31 | { 32 | m_pTexture = pTexture; 33 | } 34 | 35 | inline Texture* TextureShader::GetTexture() 36 | { 37 | return m_pTexture; 38 | } 39 | } 40 | 41 | #endif // TEXTURESHADER_H_ 42 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Renderer/Shaders/TransformShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMSHADER_H_ 2 | #define TRANSFORMSHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformShader 10 | : public Shader 11 | { 12 | private: 13 | Matrix4 m_projection; 14 | 15 | GLint m_transformUniformHandle; 16 | GLint m_positionAttributeHandle; 17 | GLint m_colorAttributeHandle; 18 | 19 | public: 20 | TransformShader(); 21 | virtual ~TransformShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | }; 26 | } 27 | 28 | #endif // TRANSFORMSHADER_H_ 29 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Renderer/Textures/Texture.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURE_H_ 2 | #define TEXTURE_H_ 3 | 4 | #include 5 | 6 | namespace Framework 7 | { 8 | class Texture 9 | { 10 | public: 11 | struct Header 12 | { 13 | unsigned int m_width; 14 | unsigned int m_height; 15 | unsigned int m_bytesPerPixel; 16 | unsigned int m_dataSize; 17 | 18 | Header() 19 | : m_width(0) 20 | , m_height(0) 21 | , m_bytesPerPixel(0) 22 | , m_dataSize(0) 23 | { 24 | 25 | } 26 | 27 | Header(const Header& header) 28 | { 29 | m_width = header.m_width; 30 | m_height = header.m_height; 31 | m_bytesPerPixel = header.m_bytesPerPixel; 32 | m_dataSize = header.m_dataSize; 33 | } 34 | }; 35 | 36 | private: 37 | GLuint m_id; 38 | Header m_header; 39 | void* m_pImageData; 40 | 41 | public: 42 | Texture(); 43 | ~Texture(); 44 | 45 | void SetData(Header& header, void* pImageData); 46 | 47 | GLuint GetId() const { return m_id; } 48 | 49 | void Init(); 50 | }; 51 | } 52 | 53 | #endif // TEXTURE_H_ 54 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Utilities/File.cpp: -------------------------------------------------------------------------------- 1 | #include "File.h" 2 | #include 3 | 4 | namespace Framework 5 | { 6 | AAssetManager* File::m_pAssetManager = NULL; 7 | 8 | File::File(std::string name) 9 | : m_filename(name) 10 | { 11 | assert(m_pAssetManager != NULL); 12 | m_pAsset = NULL; 13 | } 14 | 15 | File::~File() 16 | { 17 | Close(); 18 | } 19 | 20 | bool File::Open() 21 | { 22 | assert(m_pAssetManager != NULL); 23 | 24 | m_pAsset = AAssetManager_open(m_pAssetManager, m_filename.c_str(), AASSET_MODE_UNKNOWN); 25 | return !!m_pAsset; 26 | } 27 | 28 | void File::Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead) 29 | { 30 | bytesRead = AAsset_read(m_pAsset, pBuffer, bytesToRead); 31 | } 32 | 33 | void File::Close() 34 | { 35 | if (m_pAsset) 36 | { 37 | AAsset_close(m_pAsset); 38 | m_pAsset = NULL; 39 | } 40 | } 41 | 42 | unsigned int File::Length() const 43 | { 44 | return AAsset_getLength(m_pAsset); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Utilities/File.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H_ 2 | #define FILE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace Framework 8 | { 9 | class File 10 | { 11 | private: 12 | std::string m_filename; 13 | static AAssetManager* m_pAssetManager; 14 | AAsset* m_pAsset; 15 | 16 | public: 17 | explicit File(std::string name); 18 | virtual ~File(); 19 | 20 | bool Open(); 21 | void Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead); 22 | void Close(); 23 | 24 | unsigned int Length() const; 25 | 26 | static const size_t READ_FAILED = 0xFFFFFFFF; 27 | 28 | static void SetAssetManager(AAssetManager* pAssetManager) { m_pAssetManager = pAssetManager; } 29 | }; 30 | } 31 | 32 | #endif // FILE_H_ 33 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Utilities/Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_H_ 2 | #define HASH_H_ 3 | 4 | #include 5 | 6 | namespace Framework 7 | { 8 | // SDBM Hash 9 | inline unsigned int Hash(const std::string& key) 10 | { 11 | unsigned int result = 0; 12 | 13 | for (unsigned int i=0; i 5 | 6 | namespace Framework 7 | { 8 | template 9 | class Singleton 10 | { 11 | private: 12 | static T* ms_singleton; 13 | 14 | public: 15 | Singleton() 16 | { 17 | assert(!ms_singleton); 18 | ms_singleton = static_cast(this); 19 | } 20 | 21 | ~Singleton() 22 | { 23 | assert(ms_singleton); 24 | ms_singleton = 0; 25 | } 26 | 27 | static T& GetSingleton() { return *ms_singleton; } 28 | static T* GetSingletonPtr() { return ms_singleton; } 29 | }; 30 | 31 | template T* Singleton::ms_singleton = 0; 32 | } 33 | 34 | #endif // SINGLETON_H_ 35 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/Framework/Utilities/TGAFile.cpp: -------------------------------------------------------------------------------- 1 | #include "TGAFile.h" 2 | 3 | namespace Framework 4 | { 5 | TGAFile::TGAFile(void* pData) 6 | { 7 | size_t size = sizeof(unsigned short); 8 | m_pHeader = static_cast(pData); 9 | m_pImageData = static_cast(static_cast(pData) + sizeof(TGAHeader)); 10 | } 11 | 12 | TGAFile::~TGAFile() 13 | { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/jni/MovementComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef MOVEMENTCOMPONENT_H_ 2 | #define MOVEMENTCOMPONENT_H_ 3 | 4 | #include "Framework/GameObjects/Component.h" 5 | #include "Framework/EventManager/EventHandler.h" 6 | #include "Framework/Math/Vector3.h" 7 | 8 | namespace Framework 9 | { 10 | class GameObject; 11 | } 12 | 13 | class MovementComponent 14 | : public Framework::Component 15 | , public Framework::EventHandler 16 | { 17 | private: 18 | static const unsigned int s_id = 9; 19 | 20 | Framework::Vector3 m_acceleration; 21 | Framework::Vector3 m_velocity; 22 | 23 | public: 24 | static unsigned int GetId() { return s_id; } 25 | 26 | explicit MovementComponent(Framework::GameObject* pObject); 27 | virtual ~MovementComponent(); 28 | 29 | virtual void Initialize(); 30 | 31 | virtual void HandleEvent(Framework::Event* pEvent); 32 | }; 33 | 34 | #endif // MOVEMENTCOMPONENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter6/Chapter6/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter6/Chapter6/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter6/Chapter6/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter6/Chapter6/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter6/Chapter6/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter6/Chapter6/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Chapter6 4 | 5 | -------------------------------------------------------------------------------- /Chapter6/Chapter6/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/assets/test.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter7/Chapter7/assets/test.tga -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 2 | APP_STL := stlport_static -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Chapter7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Chapter7App.h" 4 | #include 5 | 6 | void android_main(struct android_app* state) 7 | { 8 | sleep(5); 9 | 10 | app_dummy(); 11 | 12 | Chapter7App app(state); 13 | 14 | if (app.Initialize()) 15 | { 16 | app.Run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Chapter7App.cpp: -------------------------------------------------------------------------------- 1 | #include "Chapter7App.h" 2 | 3 | Chapter7App::Chapter7App(android_app* pState) 4 | : Framework::Application(pState) 5 | , m_chapter7Task(Framework::Task::GAME_PRIORITY) 6 | { 7 | } 8 | 9 | Chapter7App::~Chapter7App() 10 | { 11 | 12 | } 13 | 14 | bool Chapter7App::Initialize() 15 | { 16 | bool success = Framework::Application::Initialize(); 17 | 18 | if (success) 19 | { 20 | m_kernel.AddTask(&m_chapter7Task); 21 | } 22 | 23 | return success; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Chapter7App.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER7APP_H_ 2 | #define CHAPTER7APP_H_ 3 | 4 | #include "Framework/Application/Application.h" 5 | #include "Chapter7Task.h" 6 | #include 7 | 8 | class Chapter7App 9 | : public Framework::Application 10 | { 11 | private: 12 | Chapter7Task m_chapter7Task; 13 | 14 | public: 15 | Chapter7App(android_app* pState); 16 | virtual ~Chapter7App(); 17 | 18 | virtual bool Initialize(); 19 | }; 20 | 21 | #endif // CHAPTER7APP_H_ 22 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Chapter7Task.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER7TASK_H_ 2 | #define CHAPTER7TASK_H_ 3 | 4 | #include "Framework/Kernel/Task.h" 5 | #include "DroidRunnerLevel.h" 6 | 7 | class Chapter7Task 8 | : public Framework::Task 9 | { 10 | private: 11 | DroidRunnerLevel m_level; 12 | 13 | public: 14 | Chapter7Task(const unsigned int priority); 15 | virtual ~Chapter7Task(); 16 | 17 | // From Task 18 | virtual bool Start(); 19 | virtual void OnSuspend(); 20 | virtual void Update(); 21 | virtual void OnResume(); 22 | virtual void Stop(); 23 | }; 24 | 25 | #endif // CHAPTER7TASK_H_ 26 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/CubeIndices.h: -------------------------------------------------------------------------------- 1 | 0,2,1, 2 | 0,3,2, 3 | 4,6,7, 4 | 4,5,6, 5 | 0,5,4, 6 | 0,1,5, 7 | 1,6,5, 8 | 1,2,6, 9 | 2,7,6, 10 | 2,3,7, 11 | 4,3,0, 12 | 4,7,3, 13 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/CubeVerts.h: -------------------------------------------------------------------------------- 1 | 3.0,-3.0,3.0, 2 | 3.0,-3.0,-3.0, 3 | -3.0,-3.0,-3.0, 4 | -3.0,-3.0,3.0, 5 | 3.0,3.0,3.0, 6 | 3.0,3.0,-3.0, 7 | -3.0,3.0,-3.0, 8 | -3.0,3.0,3.0, 9 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Application/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H_ 2 | #define APPLICATION_H_ 3 | 4 | #include "../Kernel/Kernel.h" 5 | #include "../Platform/Android.h" 6 | #include 7 | 8 | namespace Framework 9 | { 10 | class Application 11 | { 12 | protected: 13 | android_app* m_pAppState; 14 | Kernel m_kernel; 15 | Android m_androidTask; 16 | 17 | virtual void CreateSingletons(); 18 | virtual void DestroySingletons(); 19 | 20 | public: 21 | explicit Application(android_app* state); 22 | virtual ~Application(); 23 | 24 | virtual bool Initialize(); 25 | virtual void Run(); 26 | }; 27 | } 28 | 29 | #endif // APPLICATION_H_ 30 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Collision/CollisionBin.cpp: -------------------------------------------------------------------------------- 1 | #include "CollisionBin.h" 2 | 3 | namespace Framework 4 | { 5 | CollisionBin::CollisionBin() 6 | { 7 | 8 | } 9 | 10 | CollisionBin::~CollisionBin() 11 | { 12 | m_collisionObjects.clear(); 13 | } 14 | 15 | void CollisionBin::AddObject(CollisionComponent* pCollisionComponent) 16 | { 17 | m_collisionObjects.push_back(pCollisionComponent); 18 | } 19 | 20 | CollisionComponent* CollisionBin::GetFirst() 21 | { 22 | m_currentObject = m_collisionObjects.begin(); 23 | return m_currentObject != m_collisionObjects.end() 24 | ? *m_currentObject 25 | : NULL; 26 | } 27 | 28 | CollisionComponent* CollisionBin::GetNext() 29 | { 30 | CollisionComponent* pRet = NULL; 31 | 32 | if (m_currentObject != m_collisionObjects.end()) 33 | { 34 | ++m_currentObject; 35 | pRet = m_currentObject != m_collisionObjects.end() 36 | ? *m_currentObject 37 | : NULL; 38 | } 39 | 40 | return pRet; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Collision/CollisionBin.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONBIN_H_ 2 | #define COLLISIONBIN_H_ 3 | 4 | #include 5 | #include "../GameObjects/Components/CollisionComponent.h" 6 | 7 | namespace Framework 8 | { 9 | class CollisionBin 10 | { 11 | private: 12 | typedef std::vector CollisionComponentVector; 13 | typedef CollisionComponentVector::iterator CollisionComponentVectorIterator; 14 | 15 | CollisionComponentVector m_collisionObjects; 16 | CollisionComponentVectorIterator m_currentObject; 17 | 18 | public: 19 | CollisionBin(); 20 | ~CollisionBin(); 21 | 22 | void AddObject(CollisionComponent* pCollisionComponent); 23 | CollisionComponent* GetFirst(); 24 | CollisionComponent* GetNext(); 25 | }; 26 | } 27 | 28 | #endif // COLLISIONBIN_H_ 29 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Collision/CollisionListener.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONLISTENER_H_ 2 | #define COLLISIONLISTENER_H_ 3 | 4 | namespace Framework 5 | { 6 | struct CollisionEventData; 7 | 8 | class CollisionListener 9 | { 10 | public: 11 | virtual void HandleCollision(CollisionEventData* pData) = 0; 12 | }; 13 | } 14 | 15 | #endif // COLLISIONLISTENER_H_ 16 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Collision/CollisionManager.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONMANAGER_H_ 2 | #define COLLISIONMANAGER_H_ 3 | 4 | #include "../Utilities/Singleton.h" 5 | #include 6 | #include "CollisionBin.h" 7 | 8 | namespace Framework 9 | { 10 | class CollisionManager 11 | : public Singleton 12 | { 13 | private: 14 | typedef std::vector CollisionBinVector; 15 | 16 | CollisionBinVector m_collisionBins; 17 | 18 | public: 19 | CollisionManager(); 20 | ~CollisionManager(); 21 | 22 | void AddCollisionBin(); 23 | void AddObjectToBin(const unsigned int binIndex, CollisionComponent* pObject); 24 | void TestAgainstBin(const unsigned int binIndex, CollisionComponent* pObject); 25 | }; 26 | } 27 | 28 | #endif // COLLISIONMANAGER_H_ 29 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/EventManager/Event.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_H_ 2 | #define EVENT_H_ 3 | 4 | #include 5 | #include "EventHandler.h" 6 | #include "EventId.h" 7 | 8 | namespace Framework 9 | { 10 | class Event 11 | { 12 | private: 13 | typedef std::vector EventHandlerList; 14 | typedef EventHandlerList::iterator EventHandlerListIterator; 15 | 16 | EventHandlerList m_listeners; 17 | EventID m_id; 18 | void* m_pData; 19 | 20 | public: 21 | explicit Event(EventID eventId); 22 | ~Event(); 23 | 24 | void Send(void* pData); 25 | void SendToHandler(EventHandler& eventHandler, void* pData); 26 | void AttachListener(EventHandler& eventHandler); 27 | void DetachListener(EventHandler& eventHandler); 28 | 29 | EventID GetID() const { return m_id; } 30 | void* GetData() { return m_pData; } 31 | }; 32 | } 33 | 34 | #endif // EVENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/EventManager/EventHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTHANDLER_H_ 2 | #define EVENTHANDLER_H_ 3 | 4 | namespace Framework 5 | { 6 | class Event; 7 | 8 | class EventHandler 9 | { 10 | public: 11 | virtual ~EventHandler() {} 12 | 13 | virtual void HandleEvent(Event* pEvent) = 0; 14 | }; 15 | } 16 | 17 | #endif // EVENTHANDLER_H_ 18 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/EventManager/EventId.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTID_H_ 2 | #define EVENTID_H_ 3 | 4 | namespace Framework 5 | { 6 | class GameObject; 7 | 8 | typedef unsigned int EventID; 9 | 10 | static const EventID UPDATE_EVENT = 0; 11 | static const EventID POSTUPDATE_EVENT = 1; 12 | static const EventID RENDER_EVENT = 2; 13 | static const EventID JUMP_EVENT = 3; 14 | static const EventID COLLISION_EVENT = 4; 15 | 16 | struct CollisionEventData 17 | { 18 | GameObject* m_pCollider; 19 | }; 20 | } 21 | 22 | #endif // EVENTID_H_ 23 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/GameObjects/Component.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENT_H_ 2 | #define COMPONENT_H_ 3 | 4 | #include "../Utilities/Hash.h" 5 | 6 | namespace Framework 7 | { 8 | class GameObject; 9 | 10 | class Component 11 | { 12 | private: 13 | GameObject* m_pOwner; 14 | 15 | public: 16 | explicit Component(GameObject* pOwner) 17 | : m_pOwner(pOwner) 18 | { 19 | } 20 | 21 | virtual ~Component() {} 22 | 23 | virtual void Initialize() = 0; 24 | 25 | GameObject* GetOwner() { return m_pOwner; } 26 | }; 27 | } 28 | 29 | #endif /* COMPONENT_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/GameObjects/Components/RenderableComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERABLECOMPONENT_H_ 2 | #define RENDERABLECOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Renderer/Renderable.h" 6 | #include "../../EventManager/EventHandler.h" 7 | #include "../../EventManager/EventId.h" 8 | 9 | namespace Framework 10 | { 11 | class RenderableComponent 12 | : public Component 13 | , public EventHandler 14 | { 15 | private: 16 | static const unsigned int s_id = 1; 17 | 18 | Renderable m_renderable; 19 | 20 | public: 21 | static unsigned int GetId() { return s_id; } 22 | 23 | explicit RenderableComponent(GameObject* pOwner); 24 | virtual ~RenderableComponent(); 25 | 26 | virtual void Initialize(); 27 | 28 | Renderable& GetRenderable() { return m_renderable; } 29 | 30 | virtual void HandleEvent(Event* pEvent); 31 | }; 32 | } 33 | 34 | #endif // RENDERABLECOMPONENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/GameObjects/Components/TransformComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "TransformComponent.h" 2 | 3 | namespace Framework 4 | { 5 | TransformComponent::TransformComponent(GameObject* pOwner) 6 | : Component(pOwner) 7 | { 8 | 9 | } 10 | 11 | TransformComponent::~TransformComponent() 12 | { 13 | 14 | } 15 | 16 | void TransformComponent::Initialize() 17 | { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/GameObjects/Components/TransformComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMCOMPONENT_H_ 2 | #define TRANSFORMCOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Math/Transform.h" 6 | 7 | namespace Framework 8 | { 9 | class GameObject; 10 | 11 | class TransformComponent 12 | : public Component 13 | { 14 | private: 15 | static const unsigned int s_id = 0; 16 | 17 | Transform m_transform; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit TransformComponent(GameObject* pOwner); 23 | virtual ~TransformComponent(); 24 | 25 | virtual void Initialize(); 26 | 27 | Transform& GetTransform() { return m_transform; } 28 | }; 29 | } 30 | 31 | #endif // TRANSFORMCOMPONENT_H_ 32 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/GameObjects/GameObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GameObject.h" 2 | #include 3 | 4 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__)) 5 | 6 | namespace Framework 7 | { 8 | GameObject::GameObject() 9 | { 10 | 11 | } 12 | 13 | GameObject::~GameObject() 14 | { 15 | LOGI("HIT!"); 16 | for (ComponentUnorderedMapIterator iter = m_components.begin(); iter != m_components.end(); ++iter) 17 | { 18 | Component* pComponent = iter->second; 19 | if (pComponent) 20 | { 21 | delete pComponent; 22 | pComponent = NULL; 23 | } 24 | } 25 | } 26 | 27 | Component* GameObject::GetComponent(unsigned int id) 28 | { 29 | ComponentUnorderedMapIterator result = m_components.find(id); 30 | return result == m_components.end() 31 | ? NULL 32 | : result->second; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef KERNEL_H_ 2 | #define KERNEL_H_ 3 | 4 | #include 5 | #include "Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Kernel 10 | { 11 | private: 12 | typedef std::list TaskList; 13 | typedef std::list::iterator TaskListIterator; 14 | 15 | TaskList m_tasks; 16 | TaskList m_pausedTasks; 17 | 18 | void PriorityAdd(Task* pTask); 19 | 20 | public: 21 | Kernel(); 22 | virtual ~Kernel(); 23 | 24 | void Execute(); 25 | 26 | bool AddTask(Task* pTask); 27 | void SuspendTask(Task* task); 28 | void ResumeTask(Task* task); 29 | void RemoveTask(Task* task); 30 | void KillAllTasks(); 31 | 32 | bool HasTasks() { return m_tasks.size(); } 33 | }; 34 | } 35 | 36 | #endif // KERNEL_H_ 37 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Math/Functions.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONS_H_ 2 | #define FUNCTIONS_H_ 3 | 4 | namespace Framework 5 | { 6 | template 7 | inline const T& MIN(const T& a, const T& b) 8 | { 9 | return (a < b) ? a : b; 10 | } 11 | 12 | template 13 | inline const T& MAX(const T& a, const T& b) 14 | { 15 | return (a > b) ? a : b; 16 | } 17 | 18 | inline uint32_t UpperPow2(uint32_t v) 19 | { 20 | --v; 21 | v |= v >> 1; 22 | v |= v >> 2; 23 | v |= v >> 4; 24 | v |= v >> 8; 25 | v |= v >> 16; 26 | return ++v; 27 | } 28 | } 29 | 30 | #endif // FUNCTIONS_H_ 31 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Math/Matrix3.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX3_H_ 2 | #define MATRIX3_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Matrix4; 9 | 10 | class Matrix3 11 | { 12 | public: 13 | float m_m[9]; 14 | 15 | Matrix3(); 16 | virtual ~Matrix3(); 17 | 18 | void Identify(); 19 | Vector3 Transform(const Vector3& in) const; 20 | Vector3 TransformTranspose(const Vector3& in) const; 21 | void RotateAroundX(const float radians); 22 | void RotateAroundY(const float radians); 23 | void RotateAroundZ(const float radians); 24 | 25 | Matrix3& operator=(const Matrix3& in); 26 | Matrix3& operator=(const Matrix4& in); 27 | 28 | Matrix3 Multiply(const Matrix3& input) const; 29 | }; 30 | 31 | } /* namespace Framework */ 32 | #endif /* MATRIX3_H_ */ 33 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Math/Matrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX4_H_ 2 | #define MATRIX4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Vector4; 9 | class Matrix3; 10 | 11 | class Matrix4 12 | { 13 | public: 14 | enum Rows 15 | { 16 | X, 17 | Y, 18 | Z, 19 | W, 20 | NUM_ROWS 21 | }; 22 | 23 | float m_m[16]; 24 | 25 | Matrix4(); 26 | virtual ~Matrix4(); 27 | 28 | void Identify(); 29 | Vector3 Transform(const Vector3& in) const; 30 | Vector3 TransformTranspose(const Vector3& in) const; 31 | Vector4 Multiply(const Vector4& in) const; 32 | void RotateAroundX(float radians); 33 | void RotateAroundY(float radians); 34 | void RotateAroundZ(float radians); 35 | void Multiply(const Matrix4& in, Matrix4& out) const; 36 | 37 | Matrix4 Transpose() const; 38 | 39 | Matrix4& operator=(const Matrix3& in); 40 | Matrix4& operator=(const Matrix4& in); 41 | 42 | Vector4 GetRow(const Rows row) const; 43 | }; 44 | 45 | } /* namespace Framework */ 46 | #endif /* MATRIX4_H_ */ 47 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Math/Plane.cpp: -------------------------------------------------------------------------------- 1 | #include "Plane.h" 2 | 3 | namespace Framework 4 | { 5 | Plane::Plane() 6 | : m_d(0.0f) 7 | { 8 | } 9 | 10 | Plane::Plane(const Vector3& point, const Vector3& normal) 11 | { 12 | BuildPlane(point, normal); 13 | } 14 | 15 | Plane::~Plane() 16 | { 17 | 18 | } 19 | 20 | void Plane::BuildPlane(const Vector3& point, const Vector3& normal) 21 | { 22 | m_normal = normal; 23 | m_normal.Normalize(); 24 | m_d = m_normal.Dot(point); 25 | } 26 | 27 | bool Plane::IsInFront(const Vector4& point) const 28 | { 29 | return IsInFront(Vector3(point.m_x, point.m_y, point.m_z)); 30 | } 31 | 32 | bool Plane::IsInFront(const Vector3& point) const 33 | { 34 | return m_normal.Dot(point) >= m_d; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Math/Plane.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANE_H_ 2 | #define PLANE_H_ 3 | 4 | #include "Vector4.h" 5 | #include "Vector3.h" 6 | 7 | namespace Framework 8 | { 9 | class Plane 10 | { 11 | private: 12 | Vector3 m_normal; 13 | float m_d; 14 | 15 | public: 16 | Plane(); 17 | Plane(const Vector3& point, const Vector3& normal); 18 | ~Plane(); 19 | 20 | void BuildPlane(const Vector3& point, const Vector3& normal); 21 | 22 | bool IsInFront(const Vector4& point) const; 23 | bool IsInFront(const Vector3& point) const; 24 | }; 25 | } 26 | 27 | #endif // PLANE_H_ 28 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Math/Vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR3_H_ 2 | #define VECTOR3_H_ 3 | 4 | #include "Vector4.h" 5 | 6 | namespace Framework 7 | { 8 | 9 | class Vector3 10 | { 11 | public: 12 | float m_x; 13 | float m_y; 14 | float m_z; 15 | 16 | Vector3(); 17 | Vector3(const float x, const float y, const float z); 18 | virtual ~Vector3(); 19 | 20 | void Set(const Vector3& in); 21 | void Multiply(const float scalar); 22 | void Divide(const float scalar); 23 | void Add(const Vector3& in); 24 | void Subtract(const Vector3& in); 25 | void Negate(); 26 | float Length() const; 27 | float LengthSquared() const; 28 | void Normalize(); 29 | void GetNormal(Vector3& normal); 30 | 31 | Vector3& operator=(const Vector3& in); 32 | Vector3& operator=(const Vector4& in); 33 | 34 | float Dot(const Vector3& in) const; 35 | Vector3 Cross(const Vector3& in) const; 36 | }; 37 | 38 | } /* namespace Framework */ 39 | 40 | #endif /* VECTOR3_H_ */ 41 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Math/Vector4.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR4_H_ 2 | #define VECTOR4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector4 8 | { 9 | public: 10 | float m_x; 11 | float m_y; 12 | float m_z; 13 | float m_w; 14 | 15 | Vector4(); 16 | Vector4(const float x, const float y, const float z, const float w); 17 | virtual ~Vector4(); 18 | 19 | void Set(Vector4& in); 20 | void Multiply(float scalar); 21 | void Divide(float scalar); 22 | void Add(Vector4& in); 23 | void Subtract(Vector4& in); 24 | 25 | Vector4& operator=(const Vector4& in); 26 | }; 27 | 28 | } /* namespace Framework */ 29 | #endif /* VECTOR4_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Platform/Android.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROID_H_ 2 | #define ANDROID_H_ 3 | 4 | #include 5 | #include "../Kernel/Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Renderer; 10 | 11 | class Android 12 | : public Task 13 | { 14 | private: 15 | static bool m_bClosing; 16 | static bool m_bPaused; 17 | android_app* m_pState; 18 | 19 | public: 20 | Android(android_app* pState, const unsigned int priority); 21 | virtual ~Android(); 22 | 23 | android_app* GetAppState() { return m_pState; } 24 | 25 | virtual bool Start(); 26 | virtual void OnSuspend(); 27 | virtual void Update(); 28 | virtual void OnResume(); 29 | virtual void Stop(); 30 | 31 | static void ClearClosing() { m_bClosing = false; } 32 | static bool IsClosing() { return m_bClosing; } 33 | static void SetPaused(const bool paused) { m_bPaused = paused; } 34 | static bool IsPaused() { return m_bPaused; } 35 | }; 36 | } 37 | 38 | #endif // ANDROID_H_ 39 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Renderer/Geometry/Geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Geometry.cpp 3 | * 4 | * Created on: 05/06/2012 5 | * Author: bruce 6 | */ 7 | 8 | #include "Geometry.h" 9 | 10 | namespace Framework 11 | { 12 | Geometry::Geometry() 13 | : m_numVertices(0) 14 | , m_numIndices(0) 15 | , m_pVertices(NULL) 16 | , m_pIndices(NULL) 17 | , m_numVertexPositionElements(0) 18 | , m_numTexCoordElements(0) 19 | , m_vertexStride(0) 20 | { 21 | } 22 | 23 | Geometry::~Geometry() 24 | { 25 | } 26 | } // Framework 27 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Renderer/Shaders/BasicShader.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSHADER_H_ 2 | #define BASICSHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class BasicShader 9 | : public Shader 10 | { 11 | private: 12 | GLint m_positionAttributeHandle; 13 | 14 | public: 15 | BasicShader(); 16 | virtual ~BasicShader(); 17 | 18 | virtual void Link(); 19 | virtual void Setup(Renderable& renderable); 20 | }; 21 | } 22 | 23 | #endif // BASICSHADER_H_ 24 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Renderer/Shaders/Shader.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_H_ 2 | #define SHADER_H_ 3 | 4 | #include 5 | #include 6 | #include "../Renderable.h" 7 | 8 | namespace Framework 9 | { 10 | class Shader 11 | { 12 | private: 13 | void LoadShader(GLenum shaderType, std::string& shaderCode); 14 | 15 | protected: 16 | GLuint m_vertexShaderId; 17 | GLuint m_fragmentShaderId; 18 | GLint m_programId; 19 | 20 | std::string m_vertexShaderCode; 21 | std::string m_fragmentShaderCode; 22 | 23 | bool m_isLinked; 24 | 25 | public: 26 | Shader(); 27 | virtual ~Shader(); 28 | 29 | virtual void Link(); 30 | virtual void Setup(Renderable& renderable); 31 | 32 | bool IsLinked() { return m_isLinked; } 33 | }; 34 | } 35 | 36 | #endif // SHADER_H_ 37 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Renderer/Shaders/TextureShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURESHADER_H_ 2 | #define TEXTURESHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class Texture; 9 | 10 | class TextureShader 11 | : public Shader 12 | { 13 | private: 14 | Texture* m_pTexture; 15 | GLint m_positionAttributeHandle; 16 | GLint m_texCoordAttributeHandle; 17 | GLint m_samplerHandle; 18 | 19 | public: 20 | TextureShader(); 21 | virtual ~TextureShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | 26 | void SetTexture(Texture* pTexture); 27 | Texture* GetTexture(); 28 | }; 29 | 30 | inline void TextureShader::SetTexture(Texture* pTexture) 31 | { 32 | m_pTexture = pTexture; 33 | } 34 | 35 | inline Texture* TextureShader::GetTexture() 36 | { 37 | return m_pTexture; 38 | } 39 | } 40 | 41 | #endif // TEXTURESHADER_H_ 42 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Renderer/Shaders/TransformShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMSHADER_H_ 2 | #define TRANSFORMSHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformShader 10 | : public Shader 11 | { 12 | private: 13 | Matrix4 m_projection; 14 | 15 | GLint m_transformUniformHandle; 16 | GLint m_positionAttributeHandle; 17 | GLint m_colorAttributeHandle; 18 | 19 | public: 20 | TransformShader(); 21 | virtual ~TransformShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | }; 26 | } 27 | 28 | #endif // TRANSFORMSHADER_H_ 29 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Utilities/File.cpp: -------------------------------------------------------------------------------- 1 | #include "File.h" 2 | #include 3 | 4 | namespace Framework 5 | { 6 | AAssetManager* File::m_pAssetManager = NULL; 7 | 8 | File::File(std::string name) 9 | : m_filename(name) 10 | { 11 | assert(m_pAssetManager != NULL); 12 | m_pAsset = NULL; 13 | } 14 | 15 | File::~File() 16 | { 17 | Close(); 18 | } 19 | 20 | bool File::Open() 21 | { 22 | assert(m_pAssetManager != NULL); 23 | 24 | m_pAsset = AAssetManager_open(m_pAssetManager, m_filename.c_str(), AASSET_MODE_UNKNOWN); 25 | return !!m_pAsset; 26 | } 27 | 28 | void File::Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead) 29 | { 30 | bytesRead = AAsset_read(m_pAsset, pBuffer, bytesToRead); 31 | } 32 | 33 | void File::Close() 34 | { 35 | if (m_pAsset) 36 | { 37 | AAsset_close(m_pAsset); 38 | m_pAsset = NULL; 39 | } 40 | } 41 | 42 | unsigned int File::Length() const 43 | { 44 | return AAsset_getLength(m_pAsset); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Utilities/File.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H_ 2 | #define FILE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace Framework 8 | { 9 | class File 10 | { 11 | private: 12 | std::string m_filename; 13 | static AAssetManager* m_pAssetManager; 14 | AAsset* m_pAsset; 15 | 16 | public: 17 | explicit File(std::string name); 18 | virtual ~File(); 19 | 20 | bool Open(); 21 | void Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead); 22 | void Close(); 23 | 24 | unsigned int Length() const; 25 | 26 | static const size_t READ_FAILED = 0xFFFFFFFF; 27 | 28 | static void SetAssetManager(AAssetManager* pAssetManager) { m_pAssetManager = pAssetManager; } 29 | }; 30 | } 31 | 32 | #endif // FILE_H_ 33 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Utilities/Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_H_ 2 | #define HASH_H_ 3 | 4 | #include 5 | 6 | namespace Framework 7 | { 8 | // SDBM Hash 9 | inline unsigned int Hash(const std::string& key) 10 | { 11 | unsigned int result = 0; 12 | 13 | for (unsigned int i=0; i 5 | 6 | namespace Framework 7 | { 8 | template 9 | class Singleton 10 | { 11 | private: 12 | static T* ms_singleton; 13 | 14 | public: 15 | Singleton() 16 | { 17 | assert(!ms_singleton); 18 | ms_singleton = static_cast(this); 19 | } 20 | 21 | ~Singleton() 22 | { 23 | assert(ms_singleton); 24 | ms_singleton = 0; 25 | } 26 | 27 | static T& GetSingleton() { return *ms_singleton; } 28 | static T* GetSingletonPtr() { return ms_singleton; } 29 | }; 30 | 31 | template T* Singleton::ms_singleton = 0; 32 | } 33 | 34 | #endif // SINGLETON_H_ 35 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/jni/Framework/Utilities/TGAFile.cpp: -------------------------------------------------------------------------------- 1 | #include "TGAFile.h" 2 | 3 | namespace Framework 4 | { 5 | TGAFile::TGAFile(void* pData) 6 | { 7 | size_t size = sizeof(unsigned short); 8 | m_pHeader = static_cast(pData); 9 | m_pImageData = static_cast(static_cast(pData) + sizeof(TGAHeader)); 10 | } 11 | 12 | TGAFile::~TGAFile() 13 | { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter7/Chapter7/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter7/Chapter7/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter7/Chapter7/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter7/Chapter7/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter7/Chapter7/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter7/Chapter7/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Chapter7 4 | 5 | -------------------------------------------------------------------------------- /Chapter7/Chapter7/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/assets/test.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter8/Chapter8/assets/test.tga -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 2 | APP_STL := stlport_static 3 | NDK_TOOLCHAIN_VERSION := 4.7 4 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Chapter8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Chapter8App.h" 4 | #include 5 | 6 | void android_main(struct android_app* state) 7 | { 8 | sleep(5); 9 | 10 | app_dummy(); 11 | 12 | Chapter8App app(state); 13 | 14 | if (app.Initialize()) 15 | { 16 | app.Run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Chapter8App.cpp: -------------------------------------------------------------------------------- 1 | #include "Chapter8App.h" 2 | 3 | Chapter8App::Chapter8App(android_app* pState) 4 | : Framework::Application(pState) 5 | , m_chapter8Task(Framework::Task::GAME_PRIORITY) 6 | { 7 | } 8 | 9 | Chapter8App::~Chapter8App() 10 | { 11 | 12 | } 13 | 14 | bool Chapter8App::Initialize() 15 | { 16 | bool success = Framework::Application::Initialize(); 17 | 18 | if (success) 19 | { 20 | m_kernel.AddTask(&m_chapter8Task); 21 | } 22 | 23 | return success; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Chapter8App.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER8APP_H_ 2 | #define CHAPTER8APP_H_ 3 | 4 | #include "Framework/Application/Application.h" 5 | #include "Chapter8Task.h" 6 | #include 7 | 8 | class Chapter8App 9 | : public Framework::Application 10 | { 11 | private: 12 | Chapter8Task m_chapter8Task; 13 | 14 | public: 15 | Chapter8App(android_app* pState); 16 | virtual ~Chapter8App(); 17 | 18 | virtual bool Initialize(); 19 | }; 20 | 21 | #endif // CHAPTER8APP_H_ 22 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Chapter8Task.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER8TASK_H_ 2 | #define CHAPTER8TASK_H_ 3 | 4 | #include "Framework/Kernel/Task.h" 5 | #include "DroidRunnerLevel.h" 6 | 7 | class Chapter8Task 8 | : public Framework::Task 9 | { 10 | private: 11 | DroidRunnerLevel* m_pLevel; 12 | 13 | public: 14 | Chapter8Task(const unsigned int priority); 15 | virtual ~Chapter8Task(); 16 | 17 | // From Task 18 | virtual bool Start(); 19 | virtual void OnSuspend(); 20 | virtual void Update(); 21 | virtual void OnResume(); 22 | virtual void Stop(); 23 | }; 24 | 25 | #endif // CHAPTER8TASK_H_ 26 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/CubeIndices.h: -------------------------------------------------------------------------------- 1 | 0,2,1, 2 | 0,3,2, 3 | 4,6,7, 4 | 4,5,6, 5 | 0,5,4, 6 | 0,1,5, 7 | 1,6,5, 8 | 1,2,6, 9 | 2,7,6, 10 | 2,3,7, 11 | 4,3,0, 12 | 4,7,3, 13 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/CubeVerts.h: -------------------------------------------------------------------------------- 1 | 3.0,-3.0,3.0, 2 | 3.0,-3.0,-3.0, 3 | -3.0,-3.0,-3.0, 4 | -3.0,-3.0,3.0, 5 | 3.0,3.0,3.0, 6 | 3.0,3.0,-3.0, 7 | -3.0,3.0,-3.0, 8 | -3.0,3.0,3.0, 9 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Application/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H_ 2 | #define APPLICATION_H_ 3 | 4 | #include "../Kernel/Kernel.h" 5 | #include "../Platform/Android.h" 6 | #include 7 | 8 | namespace Framework 9 | { 10 | class Application 11 | { 12 | protected: 13 | android_app* m_pAppState; 14 | Kernel m_kernel; 15 | Android m_androidTask; 16 | 17 | virtual void CreateSingletons(); 18 | virtual void DestroySingletons(); 19 | 20 | public: 21 | explicit Application(android_app* state); 22 | virtual ~Application(); 23 | 24 | virtual bool Initialize(); 25 | virtual void Run(); 26 | }; 27 | } 28 | 29 | #endif // APPLICATION_H_ 30 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Collision/CollisionBin.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONBIN_H_ 2 | #define COLLISIONBIN_H_ 3 | 4 | #include 5 | #include "../GameObjects/Components/CollisionComponent.h" 6 | 7 | namespace Framework 8 | { 9 | class CollisionBin 10 | { 11 | private: 12 | typedef std::vector CollisionComponentVector; 13 | typedef CollisionComponentVector::iterator CollisionComponentVectorIterator; 14 | 15 | CollisionComponentVector m_collisionObjects; 16 | CollisionComponentVectorIterator m_currentObject; 17 | 18 | public: 19 | CollisionBin(); 20 | ~CollisionBin(); 21 | 22 | void AddObject(CollisionComponent* pCollisionComponent); 23 | CollisionComponent* GetFirst(); 24 | CollisionComponent* GetNext(); 25 | void Clear(); 26 | }; 27 | } 28 | 29 | #endif // COLLISIONBIN_H_ 30 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Collision/CollisionListener.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONLISTENER_H_ 2 | #define COLLISIONLISTENER_H_ 3 | 4 | namespace Framework 5 | { 6 | struct CollisionEventData; 7 | 8 | class CollisionListener 9 | { 10 | public: 11 | virtual void HandleCollision(CollisionEventData* pData) = 0; 12 | }; 13 | } 14 | 15 | #endif // COLLISIONLISTENER_H_ 16 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Collision/CollisionManager.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONMANAGER_H_ 2 | #define COLLISIONMANAGER_H_ 3 | 4 | #include "../Utilities/Singleton.h" 5 | #include 6 | #include "CollisionBin.h" 7 | 8 | namespace Framework 9 | { 10 | class CollisionManager 11 | : public Singleton 12 | { 13 | private: 14 | typedef std::vector CollisionBinVector; 15 | 16 | CollisionBinVector m_collisionBins; 17 | 18 | public: 19 | CollisionManager(); 20 | ~CollisionManager(); 21 | 22 | void AddCollisionBin(); 23 | void AddObjectToBin(const unsigned int binIndex, CollisionComponent* pObject); 24 | void TestAgainstBin(const unsigned int binIndex, CollisionComponent* pObject); 25 | void ClearBin(const unsigned int binIndex); 26 | }; 27 | } 28 | 29 | #endif // COLLISIONMANAGER_H_ 30 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/EventManager/Event.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_H_ 2 | #define EVENT_H_ 3 | 4 | #include 5 | #include "EventHandler.h" 6 | #include "EventId.h" 7 | 8 | namespace Framework 9 | { 10 | class Event 11 | { 12 | private: 13 | typedef std::vector EventHandlerList; 14 | typedef EventHandlerList::iterator EventHandlerListIterator; 15 | 16 | EventHandlerList m_listeners; 17 | EventID m_id; 18 | void* m_pData; 19 | 20 | public: 21 | explicit Event(EventID eventId); 22 | ~Event(); 23 | 24 | void Send(void* pData); 25 | void SendToHandler(EventHandler& eventHandler, void* pData); 26 | void AttachListener(EventHandler& eventHandler); 27 | void DetachListener(EventHandler& eventHandler); 28 | 29 | EventID GetID() const { return m_id; } 30 | void* GetData() { return m_pData; } 31 | }; 32 | } 33 | 34 | #endif // EVENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/EventManager/EventHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTHANDLER_H_ 2 | #define EVENTHANDLER_H_ 3 | 4 | namespace Framework 5 | { 6 | class Event; 7 | 8 | class EventHandler 9 | { 10 | public: 11 | virtual ~EventHandler() {} 12 | 13 | virtual void HandleEvent(Event* pEvent) = 0; 14 | }; 15 | } 16 | 17 | #endif // EVENTHANDLER_H_ 18 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/EventManager/EventId.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTID_H_ 2 | #define EVENTID_H_ 3 | 4 | namespace Framework 5 | { 6 | class GameObject; 7 | 8 | typedef unsigned int EventID; 9 | 10 | static const EventID UPDATE_EVENT = 0; 11 | static const EventID POSTUPDATE_EVENT = 1; 12 | static const EventID RENDER_EVENT = 2; 13 | static const EventID JUMP_EVENT = 3; 14 | static const EventID COLLISION_EVENT = 4; 15 | static const EventID PAUSEAPP_EVENT = 5; 16 | static const EventID RESUMEAPP_EVENT = 6; 17 | 18 | struct CollisionEventData 19 | { 20 | GameObject* m_pCollider; 21 | }; 22 | } 23 | 24 | #endif // EVENTID_H_ 25 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/GameObjects/Component.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENT_H_ 2 | #define COMPONENT_H_ 3 | 4 | #include "../Utilities/Hash.h" 5 | 6 | namespace Framework 7 | { 8 | class GameObject; 9 | 10 | class Component 11 | { 12 | private: 13 | GameObject* m_pOwner; 14 | 15 | public: 16 | explicit Component(GameObject* pOwner) 17 | : m_pOwner(pOwner) 18 | { 19 | } 20 | 21 | virtual ~Component() {} 22 | 23 | virtual void Initialize() = 0; 24 | 25 | GameObject* GetOwner() { return m_pOwner; } 26 | }; 27 | } 28 | 29 | #endif /* COMPONENT_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/GameObjects/Components/CameraComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMERACOMPONENT_H_ 2 | #define CAMERACOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../EventManager/EventHandler.h" 6 | #include "../../Renderer/Renderer.h" 7 | 8 | namespace Framework 9 | { 10 | class CameraComponent 11 | : public Component 12 | , public EventHandler 13 | { 14 | private: 15 | static const unsigned int s_id = 3; 16 | 17 | float m_frustumParameters[Renderer::NUM_PARAMS]; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit CameraComponent(GameObject* pOwner); 23 | virtual ~CameraComponent(); 24 | 25 | virtual void Initialize() {} 26 | 27 | void SetFrustum(const float verticalFieldOfView, const float aspectRatio, const float near, const float far); 28 | 29 | virtual void HandleEvent(Event* pEvent); 30 | }; 31 | } 32 | 33 | #endif // CAMERACOMPONENT_H_ 34 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/GameObjects/Components/RenderableComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERABLECOMPONENT_H_ 2 | #define RENDERABLECOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Renderer/Renderable.h" 6 | #include "../../EventManager/EventHandler.h" 7 | #include "../../EventManager/EventId.h" 8 | 9 | namespace Framework 10 | { 11 | class RenderableComponent 12 | : public Component 13 | , public EventHandler 14 | { 15 | private: 16 | static const unsigned int s_id = 1; 17 | 18 | Renderable m_renderable; 19 | 20 | public: 21 | static unsigned int GetId() { return s_id; } 22 | 23 | explicit RenderableComponent(GameObject* pOwner); 24 | virtual ~RenderableComponent(); 25 | 26 | virtual void Initialize(); 27 | 28 | Renderable& GetRenderable() { return m_renderable; } 29 | 30 | virtual void HandleEvent(Event* pEvent); 31 | }; 32 | } 33 | 34 | #endif // RENDERABLECOMPONENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/GameObjects/Components/TransformComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "TransformComponent.h" 2 | 3 | namespace Framework 4 | { 5 | TransformComponent::TransformComponent(GameObject* pOwner) 6 | : Component(pOwner) 7 | { 8 | 9 | } 10 | 11 | TransformComponent::~TransformComponent() 12 | { 13 | 14 | } 15 | 16 | void TransformComponent::Initialize() 17 | { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/GameObjects/Components/TransformComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMCOMPONENT_H_ 2 | #define TRANSFORMCOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Math/Transform.h" 6 | 7 | namespace Framework 8 | { 9 | class GameObject; 10 | 11 | class TransformComponent 12 | : public Component 13 | { 14 | private: 15 | static const unsigned int s_id = 0; 16 | 17 | Transform m_transform; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit TransformComponent(GameObject* pOwner); 23 | virtual ~TransformComponent(); 24 | 25 | virtual void Initialize(); 26 | 27 | Transform& GetTransform() { return m_transform; } 28 | const Transform& GetTransform() const { return m_transform; } 29 | }; 30 | } 31 | 32 | #endif // TRANSFORMCOMPONENT_H_ 33 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/GameObjects/GameObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GameObject.h" 2 | #include 3 | 4 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__)) 5 | 6 | namespace Framework 7 | { 8 | GameObject::GameObject() 9 | { 10 | 11 | } 12 | 13 | GameObject::~GameObject() 14 | { 15 | for (ComponentUnorderedMapIterator iter = m_components.begin(); iter != m_components.end(); ++iter) 16 | { 17 | Component* pComponent = iter->second; 18 | if (pComponent) 19 | { 20 | delete pComponent; 21 | pComponent = NULL; 22 | } 23 | } 24 | } 25 | 26 | Component* GameObject::GetComponent(unsigned int id) 27 | { 28 | ComponentUnorderedMapIterator result = m_components.find(id); 29 | return result == m_components.end() 30 | ? NULL 31 | : result->second; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef KERNEL_H_ 2 | #define KERNEL_H_ 3 | 4 | #include 5 | #include "Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Kernel 10 | { 11 | private: 12 | typedef std::list TaskList; 13 | typedef std::list::iterator TaskListIterator; 14 | 15 | TaskList m_tasks; 16 | TaskList m_pausedTasks; 17 | 18 | void PriorityAdd(Task* pTask); 19 | 20 | public: 21 | Kernel(); 22 | virtual ~Kernel(); 23 | 24 | void Execute(); 25 | 26 | bool AddTask(Task* pTask); 27 | void SuspendTask(Task* task); 28 | void ResumeTask(Task* task); 29 | void RemoveTask(Task* task); 30 | void KillAllTasks(); 31 | 32 | bool HasTasks() { return m_tasks.size(); } 33 | }; 34 | } 35 | 36 | #endif // KERNEL_H_ 37 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Math/Functions.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONS_H_ 2 | #define FUNCTIONS_H_ 3 | 4 | namespace Framework 5 | { 6 | template 7 | inline const T& MIN(const T& a, const T& b) 8 | { 9 | return (a < b) ? a : b; 10 | } 11 | 12 | template 13 | inline const T& MAX(const T& a, const T& b) 14 | { 15 | return (a > b) ? a : b; 16 | } 17 | 18 | inline uint32_t UpperPow2(uint32_t v) 19 | { 20 | --v; 21 | v |= v >> 1; 22 | v |= v >> 2; 23 | v |= v >> 4; 24 | v |= v >> 8; 25 | v |= v >> 16; 26 | return ++v; 27 | } 28 | } 29 | 30 | #endif // FUNCTIONS_H_ 31 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Math/Matrix3.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX3_H_ 2 | #define MATRIX3_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Matrix4; 9 | 10 | class Matrix3 11 | { 12 | public: 13 | float m_m[9]; 14 | 15 | Matrix3(); 16 | virtual ~Matrix3(); 17 | 18 | void Identify(); 19 | Vector3 Transform(const Vector3& in) const; 20 | Vector3 TransformTranspose(const Vector3& in) const; 21 | void RotateAroundX(const float radians); 22 | void RotateAroundY(const float radians); 23 | void RotateAroundZ(const float radians); 24 | 25 | Matrix3& operator=(const Matrix3& in); 26 | Matrix3& operator=(const Matrix4& in); 27 | 28 | Matrix3 Multiply(const Matrix3& input) const; 29 | }; 30 | 31 | } /* namespace Framework */ 32 | #endif /* MATRIX3_H_ */ 33 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Math/Matrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX4_H_ 2 | #define MATRIX4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Vector4; 9 | class Matrix3; 10 | 11 | class Matrix4 12 | { 13 | public: 14 | enum Rows 15 | { 16 | X, 17 | Y, 18 | Z, 19 | W, 20 | NUM_ROWS 21 | }; 22 | 23 | float m_m[16]; 24 | 25 | Matrix4(); 26 | virtual ~Matrix4(); 27 | 28 | void Identify(); 29 | Vector3 Transform(const Vector3& in) const; 30 | Vector3 TransformTranspose(const Vector3& in) const; 31 | Vector4 Multiply(const Vector4& in) const; 32 | void RotateAroundX(float radians); 33 | void RotateAroundY(float radians); 34 | void RotateAroundZ(float radians); 35 | void Multiply(const Matrix4& in, Matrix4& out) const; 36 | 37 | Matrix4 Transpose() const; 38 | 39 | Matrix4& operator=(const Matrix3& in); 40 | Matrix4& operator=(const Matrix4& in); 41 | 42 | Vector4 GetRow(const Rows row) const; 43 | }; 44 | 45 | } /* namespace Framework */ 46 | #endif /* MATRIX4_H_ */ 47 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Math/Plane.cpp: -------------------------------------------------------------------------------- 1 | #include "Plane.h" 2 | 3 | namespace Framework 4 | { 5 | Plane::Plane() 6 | : m_d(0.0f) 7 | { 8 | } 9 | 10 | Plane::Plane(const Vector3& point, const Vector3& normal) 11 | { 12 | BuildPlane(point, normal); 13 | } 14 | 15 | Plane::~Plane() 16 | { 17 | 18 | } 19 | 20 | void Plane::BuildPlane(const Vector3& point, const Vector3& normal) 21 | { 22 | m_normal = normal; 23 | m_normal.Normalize(); 24 | m_d = m_normal.Dot(point); 25 | } 26 | 27 | bool Plane::IsInFront(const Vector4& point) const 28 | { 29 | return IsInFront(Vector3(point.m_x, point.m_y, point.m_z)); 30 | } 31 | 32 | bool Plane::IsInFront(const Vector3& point) const 33 | { 34 | return m_normal.Dot(point) >= m_d; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Math/Plane.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANE_H_ 2 | #define PLANE_H_ 3 | 4 | #include "Vector4.h" 5 | #include "Vector3.h" 6 | 7 | namespace Framework 8 | { 9 | class Plane 10 | { 11 | private: 12 | Vector3 m_normal; 13 | float m_d; 14 | 15 | public: 16 | Plane(); 17 | Plane(const Vector3& point, const Vector3& normal); 18 | ~Plane(); 19 | 20 | void BuildPlane(const Vector3& point, const Vector3& normal); 21 | 22 | bool IsInFront(const Vector4& point) const; 23 | bool IsInFront(const Vector3& point) const; 24 | }; 25 | } 26 | 27 | #endif // PLANE_H_ 28 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Math/Vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR3_H_ 2 | #define VECTOR3_H_ 3 | 4 | #include "Vector4.h" 5 | 6 | namespace Framework 7 | { 8 | 9 | class Vector3 10 | { 11 | public: 12 | float m_x; 13 | float m_y; 14 | float m_z; 15 | 16 | Vector3(); 17 | Vector3(const float x, const float y, const float z); 18 | virtual ~Vector3(); 19 | 20 | void Set(const Vector3& in); 21 | void Multiply(const float scalar); 22 | void Divide(const float scalar); 23 | void Add(const Vector3& in); 24 | void Subtract(const Vector3& in); 25 | void Negate(); 26 | float Length() const; 27 | float LengthSquared() const; 28 | void Normalize(); 29 | void GetNormal(Vector3& normal); 30 | 31 | Vector3& operator=(const Vector3& in); 32 | Vector3& operator=(const Vector4& in); 33 | 34 | float Dot(const Vector3& in) const; 35 | Vector3 Cross(const Vector3& in) const; 36 | }; 37 | 38 | } /* namespace Framework */ 39 | 40 | #endif /* VECTOR3_H_ */ 41 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Math/Vector4.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR4_H_ 2 | #define VECTOR4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector4 8 | { 9 | public: 10 | float m_x; 11 | float m_y; 12 | float m_z; 13 | float m_w; 14 | 15 | Vector4(); 16 | Vector4(const float x, const float y, const float z, const float w); 17 | virtual ~Vector4(); 18 | 19 | void Set(Vector4& in); 20 | void Multiply(float scalar); 21 | void Divide(float scalar); 22 | void Add(Vector4& in); 23 | void Subtract(Vector4& in); 24 | 25 | Vector4& operator=(const Vector4& in); 26 | }; 27 | 28 | } /* namespace Framework */ 29 | #endif /* VECTOR4_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Platform/Android.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROID_H_ 2 | #define ANDROID_H_ 3 | 4 | #include 5 | #include "../Kernel/Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Renderer; 10 | 11 | class Android 12 | : public Task 13 | { 14 | private: 15 | static bool m_bClosing; 16 | android_app* m_pState; 17 | 18 | public: 19 | Android(android_app* pState, const unsigned int priority); 20 | virtual ~Android(); 21 | 22 | android_app* GetAppState() { return m_pState; } 23 | 24 | virtual bool Start(); 25 | virtual void OnSuspend(); 26 | virtual void Update(); 27 | virtual void OnResume(); 28 | virtual void Stop(); 29 | 30 | static void ClearClosing() { m_bClosing = false; } 31 | static bool IsClosing() { return m_bClosing; } 32 | }; 33 | } 34 | 35 | #endif // ANDROID_H_ 36 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Renderer/Geometry/Geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Geometry.cpp 3 | * 4 | * Created on: 05/06/2012 5 | * Author: bruce 6 | */ 7 | 8 | #include "Geometry.h" 9 | 10 | namespace Framework 11 | { 12 | Geometry::Geometry() 13 | : m_numVertices(0) 14 | , m_numIndices(0) 15 | , m_pVertices(NULL) 16 | , m_pIndices(NULL) 17 | , m_numVertexPositionElements(0) 18 | , m_numTexCoordElements(0) 19 | , m_vertexStride(0) 20 | { 21 | } 22 | 23 | Geometry::~Geometry() 24 | { 25 | } 26 | } // Framework 27 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Renderer/Shaders/BasicShader.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSHADER_H_ 2 | #define BASICSHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class BasicShader 9 | : public Shader 10 | { 11 | private: 12 | GLint m_positionAttributeHandle; 13 | 14 | public: 15 | BasicShader(); 16 | virtual ~BasicShader(); 17 | 18 | virtual void Link(); 19 | virtual void Setup(Renderable& renderable); 20 | }; 21 | } 22 | 23 | #endif // BASICSHADER_H_ 24 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Renderer/Shaders/Shader.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_H_ 2 | #define SHADER_H_ 3 | 4 | #include 5 | #include 6 | #include "../Renderable.h" 7 | 8 | namespace Framework 9 | { 10 | class Shader 11 | { 12 | private: 13 | void LoadShader(GLenum shaderType, std::string& shaderCode); 14 | 15 | protected: 16 | GLuint m_vertexShaderId; 17 | GLuint m_fragmentShaderId; 18 | GLint m_programId; 19 | 20 | std::string m_vertexShaderCode; 21 | std::string m_fragmentShaderCode; 22 | 23 | bool m_isLinked; 24 | 25 | public: 26 | Shader(); 27 | virtual ~Shader(); 28 | 29 | virtual void Link(); 30 | virtual void Setup(Renderable& renderable); 31 | 32 | bool IsLinked() { return m_isLinked; } 33 | }; 34 | } 35 | 36 | #endif // SHADER_H_ 37 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Renderer/Shaders/TextureShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURESHADER_H_ 2 | #define TEXTURESHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class Texture; 9 | 10 | class TextureShader 11 | : public Shader 12 | { 13 | private: 14 | Texture* m_pTexture; 15 | GLint m_positionAttributeHandle; 16 | GLint m_texCoordAttributeHandle; 17 | GLint m_samplerHandle; 18 | 19 | public: 20 | TextureShader(); 21 | virtual ~TextureShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | 26 | void SetTexture(Texture* pTexture); 27 | Texture* GetTexture(); 28 | }; 29 | 30 | inline void TextureShader::SetTexture(Texture* pTexture) 31 | { 32 | m_pTexture = pTexture; 33 | } 34 | 35 | inline Texture* TextureShader::GetTexture() 36 | { 37 | return m_pTexture; 38 | } 39 | } 40 | 41 | #endif // TEXTURESHADER_H_ 42 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Renderer/Shaders/TransformShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMSHADER_H_ 2 | #define TRANSFORMSHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformShader 10 | : public Shader 11 | { 12 | private: 13 | GLint m_transformUniformHandle; 14 | GLint m_positionAttributeHandle; 15 | GLint m_colorAttributeHandle; 16 | 17 | public: 18 | TransformShader(); 19 | virtual ~TransformShader(); 20 | 21 | virtual void Link(); 22 | virtual void Setup(Renderable& renderable); 23 | }; 24 | } 25 | 26 | #endif // TRANSFORMSHADER_H_ 27 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Utilities/File.cpp: -------------------------------------------------------------------------------- 1 | #include "File.h" 2 | #include 3 | 4 | namespace Framework 5 | { 6 | AAssetManager* File::m_pAssetManager = NULL; 7 | 8 | File::File(std::string name) 9 | : m_filename(name) 10 | { 11 | assert(m_pAssetManager != NULL); 12 | m_pAsset = NULL; 13 | } 14 | 15 | File::~File() 16 | { 17 | Close(); 18 | } 19 | 20 | bool File::Open() 21 | { 22 | assert(m_pAssetManager != NULL); 23 | 24 | m_pAsset = AAssetManager_open(m_pAssetManager, m_filename.c_str(), AASSET_MODE_UNKNOWN); 25 | return !!m_pAsset; 26 | } 27 | 28 | void File::Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead) 29 | { 30 | bytesRead = AAsset_read(m_pAsset, pBuffer, bytesToRead); 31 | } 32 | 33 | void File::Close() 34 | { 35 | if (m_pAsset) 36 | { 37 | AAsset_close(m_pAsset); 38 | m_pAsset = NULL; 39 | } 40 | } 41 | 42 | unsigned int File::Length() const 43 | { 44 | return AAsset_getLength(m_pAsset); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Utilities/File.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H_ 2 | #define FILE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace Framework 8 | { 9 | class File 10 | { 11 | private: 12 | std::string m_filename; 13 | static AAssetManager* m_pAssetManager; 14 | AAsset* m_pAsset; 15 | 16 | public: 17 | explicit File(std::string name); 18 | virtual ~File(); 19 | 20 | bool Open(); 21 | void Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead); 22 | void Close(); 23 | 24 | unsigned int Length() const; 25 | 26 | static const size_t READ_FAILED = 0xFFFFFFFF; 27 | 28 | static void SetAssetManager(AAssetManager* pAssetManager) { m_pAssetManager = pAssetManager; } 29 | }; 30 | } 31 | 32 | #endif // FILE_H_ 33 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Utilities/Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_H_ 2 | #define HASH_H_ 3 | 4 | #include 5 | 6 | namespace Framework 7 | { 8 | // SDBM Hash 9 | inline unsigned int Hash(const std::string& key) 10 | { 11 | unsigned int result = 0; 12 | 13 | for (unsigned int i=0; i 5 | 6 | namespace Framework 7 | { 8 | template 9 | class Singleton 10 | { 11 | private: 12 | static T* ms_singleton; 13 | 14 | public: 15 | Singleton() 16 | { 17 | assert(!ms_singleton); 18 | ms_singleton = static_cast(this); 19 | } 20 | 21 | ~Singleton() 22 | { 23 | assert(ms_singleton); 24 | ms_singleton = 0; 25 | } 26 | 27 | static T& GetSingleton() { return *ms_singleton; } 28 | static T* GetSingletonPtr() { return ms_singleton; } 29 | }; 30 | 31 | template T* Singleton::ms_singleton = 0; 32 | } 33 | 34 | #endif // SINGLETON_H_ 35 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/jni/Framework/Utilities/TGAFile.cpp: -------------------------------------------------------------------------------- 1 | #include "TGAFile.h" 2 | 3 | namespace Framework 4 | { 5 | TGAFile::TGAFile(void* pData) 6 | { 7 | size_t size = sizeof(unsigned short); 8 | m_pHeader = static_cast(pData); 9 | m_pImageData = static_cast(static_cast(pData) + sizeof(TGAHeader)); 10 | } 11 | 12 | TGAFile::~TGAFile() 13 | { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter8/Chapter8/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter8/Chapter8/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter8/Chapter8/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter8/Chapter8/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter8/Chapter8/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter8/Chapter8/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Chapter8 4 | 5 | -------------------------------------------------------------------------------- /Chapter8/Chapter8/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/assets/test.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter9/Chapter9/assets/test.tga -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-9 2 | APP_STL := stlport_static 3 | NDK_TOOLCHAIN_VERSION := 4.7 4 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Chapter9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Chapter9App.h" 4 | #include 5 | 6 | void android_main(struct android_app* state) 7 | { 8 | sleep(5); 9 | 10 | app_dummy(); 11 | 12 | Chapter9App app(state); 13 | 14 | if (app.Initialize()) 15 | { 16 | app.Run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Chapter9App.cpp: -------------------------------------------------------------------------------- 1 | #include "Chapter9App.h" 2 | 3 | Chapter9App::Chapter9App(android_app* pState) 4 | : Framework::Application(pState) 5 | , m_chapter9Task(Framework::Task::GAME_PRIORITY) 6 | { 7 | } 8 | 9 | Chapter9App::~Chapter9App() 10 | { 11 | 12 | } 13 | 14 | bool Chapter9App::Initialize() 15 | { 16 | bool success = Framework::Application::Initialize(); 17 | 18 | if (success) 19 | { 20 | m_kernel.AddTask(&m_chapter9Task); 21 | } 22 | 23 | return success; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Chapter9App.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER9APP_H_ 2 | #define CHAPTER9APP_H_ 3 | 4 | #include "Framework/Application/Application.h" 5 | #include "Chapter9Task.h" 6 | #include 7 | 8 | class Chapter9App 9 | : public Framework::Application 10 | { 11 | private: 12 | Chapter9Task m_chapter9Task; 13 | 14 | public: 15 | Chapter9App(android_app* pState); 16 | virtual ~Chapter9App(); 17 | 18 | virtual bool Initialize(); 19 | }; 20 | 21 | #endif // CHAPTER9APP_H_ 22 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Chapter9Task.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAPTER9TASK_H_ 2 | #define CHAPTER9TASK_H_ 3 | 4 | #include "Framework/Kernel/Task.h" 5 | #include "DroidRunnerLevel.h" 6 | 7 | class Chapter9Task 8 | : public Framework::Task 9 | { 10 | private: 11 | DroidRunnerLevel* m_pLevel; 12 | 13 | public: 14 | Chapter9Task(const unsigned int priority); 15 | virtual ~Chapter9Task(); 16 | 17 | // From Task 18 | virtual bool Start(); 19 | virtual void OnSuspend(); 20 | virtual void Update(); 21 | virtual void OnResume(); 22 | virtual void Stop(); 23 | }; 24 | 25 | #endif // CHAPTER9TASK_H_ 26 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/CubeIndices.h: -------------------------------------------------------------------------------- 1 | 0,2,1, 2 | 0,3,2, 3 | 4,6,7, 4 | 4,5,6, 5 | 0,5,4, 6 | 0,1,5, 7 | 1,6,5, 8 | 1,2,6, 9 | 2,7,6, 10 | 2,3,7, 11 | 4,3,0, 12 | 4,7,3, 13 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/CubeVerts.h: -------------------------------------------------------------------------------- 1 | -3.0,-3.0,-3.0, 2 | -0.5773491859436035,-0.5773491859436035,-0.5773491859436035, 3 | -3.0,-3.0,3.0, 4 | -0.5773491859436035,-0.5773491859436035,0.5773491859436035, 5 | 3.0,-3.0,3.0, 6 | 0.5773491859436035,-0.5773491859436035,0.5773491859436035, 7 | 3.0,-3.0,-3.0, 8 | 0.5773491859436035,-0.5773491859436035,-0.5773491859436035, 9 | -3.0,3.0,-3.0, 10 | -0.5773491859436035,0.5773491859436035,-0.5773491859436035, 11 | -3.0,3.0,3.0, 12 | -0.5773491859436035,0.5773491859436035,0.5773491859436035, 13 | 3.0,3.0,3.0, 14 | 0.5773491859436035,0.5773491859436035,0.5773491859436035, 15 | 3.0,3.0,-3.0, 16 | 0.5773491859436035,0.5773491859436035,-0.5773491859436035, 17 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Application/Application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H_ 2 | #define APPLICATION_H_ 3 | 4 | #include "../Kernel/Kernel.h" 5 | #include "../Platform/Android.h" 6 | #include 7 | 8 | namespace Framework 9 | { 10 | class Application 11 | { 12 | protected: 13 | android_app* m_pAppState; 14 | Kernel m_kernel; 15 | Android m_androidTask; 16 | 17 | virtual void CreateSingletons(); 18 | virtual void DestroySingletons(); 19 | 20 | public: 21 | explicit Application(android_app* state); 22 | virtual ~Application(); 23 | 24 | virtual bool Initialize(); 25 | virtual void Run(); 26 | }; 27 | } 28 | 29 | #endif // APPLICATION_H_ 30 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Collision/CollisionBin.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONBIN_H_ 2 | #define COLLISIONBIN_H_ 3 | 4 | #include 5 | #include "../GameObjects/Components/CollisionComponent.h" 6 | 7 | namespace Framework 8 | { 9 | class CollisionBin 10 | { 11 | private: 12 | typedef std::vector CollisionComponentVector; 13 | typedef CollisionComponentVector::iterator CollisionComponentVectorIterator; 14 | 15 | CollisionComponentVector m_collisionObjects; 16 | CollisionComponentVectorIterator m_currentObject; 17 | 18 | public: 19 | CollisionBin(); 20 | ~CollisionBin(); 21 | 22 | void AddObject(CollisionComponent* pCollisionComponent); 23 | CollisionComponent* GetFirst(); 24 | CollisionComponent* GetNext(); 25 | void Clear(); 26 | }; 27 | } 28 | 29 | #endif // COLLISIONBIN_H_ 30 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Collision/CollisionListener.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONLISTENER_H_ 2 | #define COLLISIONLISTENER_H_ 3 | 4 | namespace Framework 5 | { 6 | struct CollisionEventData; 7 | 8 | class CollisionListener 9 | { 10 | public: 11 | virtual void HandleCollision(CollisionEventData* pData) = 0; 12 | }; 13 | } 14 | 15 | #endif // COLLISIONLISTENER_H_ 16 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Collision/CollisionManager.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISIONMANAGER_H_ 2 | #define COLLISIONMANAGER_H_ 3 | 4 | #include "../Utilities/Singleton.h" 5 | #include 6 | #include "CollisionBin.h" 7 | 8 | namespace Framework 9 | { 10 | class CollisionManager 11 | : public Singleton 12 | { 13 | private: 14 | typedef std::vector CollisionBinVector; 15 | 16 | CollisionBinVector m_collisionBins; 17 | 18 | public: 19 | CollisionManager(); 20 | ~CollisionManager(); 21 | 22 | void AddCollisionBin(); 23 | void AddObjectToBin(const unsigned int binIndex, CollisionComponent* pObject); 24 | void TestAgainstBin(const unsigned int binIndex, CollisionComponent* pObject); 25 | void ClearBin(const unsigned int binIndex); 26 | }; 27 | } 28 | 29 | #endif // COLLISIONMANAGER_H_ 30 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/EventManager/Event.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_H_ 2 | #define EVENT_H_ 3 | 4 | #include 5 | #include "EventHandler.h" 6 | #include "EventId.h" 7 | 8 | namespace Framework 9 | { 10 | class Event 11 | { 12 | private: 13 | typedef std::vector EventHandlerList; 14 | typedef EventHandlerList::iterator EventHandlerListIterator; 15 | 16 | EventHandlerList m_listeners; 17 | EventID m_id; 18 | void* m_pData; 19 | 20 | public: 21 | explicit Event(EventID eventId); 22 | ~Event(); 23 | 24 | void Send(void* pData); 25 | void SendToHandler(EventHandler& eventHandler, void* pData); 26 | void AttachListener(EventHandler& eventHandler); 27 | void DetachListener(EventHandler& eventHandler); 28 | 29 | EventID GetID() const { return m_id; } 30 | void* GetData() { return m_pData; } 31 | }; 32 | } 33 | 34 | #endif // EVENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/EventManager/EventHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTHANDLER_H_ 2 | #define EVENTHANDLER_H_ 3 | 4 | namespace Framework 5 | { 6 | class Event; 7 | 8 | class EventHandler 9 | { 10 | public: 11 | virtual ~EventHandler() {} 12 | 13 | virtual void HandleEvent(Event* pEvent) = 0; 14 | }; 15 | } 16 | 17 | #endif // EVENTHANDLER_H_ 18 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/EventManager/EventId.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTID_H_ 2 | #define EVENTID_H_ 3 | 4 | namespace Framework 5 | { 6 | class GameObject; 7 | 8 | typedef unsigned int EventID; 9 | 10 | static const EventID UPDATE_EVENT = 0; 11 | static const EventID POSTUPDATE_EVENT = 1; 12 | static const EventID RENDER_EVENT = 2; 13 | static const EventID JUMP_EVENT = 3; 14 | static const EventID COLLISION_EVENT = 4; 15 | static const EventID PAUSEAPP_EVENT = 5; 16 | static const EventID RESUMEAPP_EVENT = 6; 17 | 18 | struct CollisionEventData 19 | { 20 | GameObject* m_pCollider; 21 | }; 22 | } 23 | 24 | #endif // EVENTID_H_ 25 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/GameObjects/Component.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENT_H_ 2 | #define COMPONENT_H_ 3 | 4 | #include "../Utilities/Hash.h" 5 | 6 | namespace Framework 7 | { 8 | class GameObject; 9 | 10 | class Component 11 | { 12 | private: 13 | GameObject* m_pOwner; 14 | 15 | public: 16 | explicit Component(GameObject* pOwner) 17 | : m_pOwner(pOwner) 18 | { 19 | } 20 | 21 | virtual ~Component() {} 22 | 23 | virtual void Initialize() = 0; 24 | 25 | GameObject* GetOwner() { return m_pOwner; } 26 | }; 27 | } 28 | 29 | #endif /* COMPONENT_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/GameObjects/Components/CameraComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMERACOMPONENT_H_ 2 | #define CAMERACOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../EventManager/EventHandler.h" 6 | #include "../../Renderer/Renderer.h" 7 | 8 | namespace Framework 9 | { 10 | class CameraComponent 11 | : public Component 12 | , public EventHandler 13 | { 14 | private: 15 | static const unsigned int s_id = 3; 16 | 17 | float m_frustumParameters[Renderer::NUM_PARAMS]; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit CameraComponent(GameObject* pOwner); 23 | virtual ~CameraComponent(); 24 | 25 | virtual void Initialize() {} 26 | 27 | void SetFrustum(const float verticalFieldOfView, const float aspectRatio, const float near, const float far); 28 | 29 | virtual void HandleEvent(Event* pEvent); 30 | }; 31 | } 32 | 33 | #endif // CAMERACOMPONENT_H_ 34 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/GameObjects/Components/RenderableComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERABLECOMPONENT_H_ 2 | #define RENDERABLECOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Renderer/Renderable.h" 6 | #include "../../EventManager/EventHandler.h" 7 | #include "../../EventManager/EventId.h" 8 | 9 | namespace Framework 10 | { 11 | class RenderableComponent 12 | : public Component 13 | , public EventHandler 14 | { 15 | private: 16 | static const unsigned int s_id = 1; 17 | 18 | Renderable m_renderable; 19 | 20 | public: 21 | static unsigned int GetId() { return s_id; } 22 | 23 | explicit RenderableComponent(GameObject* pOwner); 24 | virtual ~RenderableComponent(); 25 | 26 | virtual void Initialize(); 27 | 28 | Renderable& GetRenderable() { return m_renderable; } 29 | 30 | virtual void HandleEvent(Event* pEvent); 31 | }; 32 | } 33 | 34 | #endif // RENDERABLECOMPONENT_H_ 35 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/GameObjects/Components/TransformComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "TransformComponent.h" 2 | 3 | namespace Framework 4 | { 5 | TransformComponent::TransformComponent(GameObject* pOwner) 6 | : Component(pOwner) 7 | { 8 | 9 | } 10 | 11 | TransformComponent::~TransformComponent() 12 | { 13 | 14 | } 15 | 16 | void TransformComponent::Initialize() 17 | { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/GameObjects/Components/TransformComponent.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMCOMPONENT_H_ 2 | #define TRANSFORMCOMPONENT_H_ 3 | 4 | #include "../Component.h" 5 | #include "../../Math/Transform.h" 6 | 7 | namespace Framework 8 | { 9 | class GameObject; 10 | 11 | class TransformComponent 12 | : public Component 13 | { 14 | private: 15 | static const unsigned int s_id = 0; 16 | 17 | Transform m_transform; 18 | 19 | public: 20 | static unsigned int GetId() { return s_id; } 21 | 22 | explicit TransformComponent(GameObject* pOwner); 23 | virtual ~TransformComponent(); 24 | 25 | virtual void Initialize(); 26 | 27 | Transform& GetTransform() { return m_transform; } 28 | const Transform& GetTransform() const { return m_transform; } 29 | }; 30 | } 31 | 32 | #endif // TRANSFORMCOMPONENT_H_ 33 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/GameObjects/GameObject.cpp: -------------------------------------------------------------------------------- 1 | #include "GameObject.h" 2 | #include 3 | 4 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__)) 5 | 6 | namespace Framework 7 | { 8 | GameObject::GameObject() 9 | { 10 | 11 | } 12 | 13 | GameObject::~GameObject() 14 | { 15 | for (ComponentUnorderedMapIterator iter = m_components.begin(); iter != m_components.end(); ++iter) 16 | { 17 | Component* pComponent = iter->second; 18 | if (pComponent) 19 | { 20 | delete pComponent; 21 | pComponent = NULL; 22 | } 23 | } 24 | } 25 | 26 | Component* GameObject::GetComponent(unsigned int id) 27 | { 28 | ComponentUnorderedMapIterator result = m_components.find(id); 29 | return result == m_components.end() 30 | ? NULL 31 | : result->second; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef KERNEL_H_ 2 | #define KERNEL_H_ 3 | 4 | #include 5 | #include "Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Kernel 10 | { 11 | private: 12 | typedef std::list TaskList; 13 | typedef std::list::iterator TaskListIterator; 14 | 15 | TaskList m_tasks; 16 | TaskList m_pausedTasks; 17 | 18 | void PriorityAdd(Task* pTask); 19 | 20 | public: 21 | Kernel(); 22 | virtual ~Kernel(); 23 | 24 | void Execute(); 25 | 26 | bool AddTask(Task* pTask); 27 | void SuspendTask(Task* task); 28 | void ResumeTask(Task* task); 29 | void RemoveTask(Task* task); 30 | void KillAllTasks(); 31 | 32 | bool HasTasks() { return m_tasks.size(); } 33 | }; 34 | } 35 | 36 | #endif // KERNEL_H_ 37 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Math/Functions.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONS_H_ 2 | #define FUNCTIONS_H_ 3 | 4 | namespace Framework 5 | { 6 | template 7 | inline const T& MIN(const T& a, const T& b) 8 | { 9 | return (a < b) ? a : b; 10 | } 11 | 12 | template 13 | inline const T& MAX(const T& a, const T& b) 14 | { 15 | return (a > b) ? a : b; 16 | } 17 | 18 | inline uint32_t UpperPow2(uint32_t v) 19 | { 20 | --v; 21 | v |= v >> 1; 22 | v |= v >> 2; 23 | v |= v >> 4; 24 | v |= v >> 8; 25 | v |= v >> 16; 26 | return ++v; 27 | } 28 | } 29 | 30 | #endif // FUNCTIONS_H_ 31 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Math/Matrix3.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX3_H_ 2 | #define MATRIX3_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Matrix4; 9 | 10 | class Matrix3 11 | { 12 | public: 13 | float m_m[9]; 14 | 15 | Matrix3(); 16 | virtual ~Matrix3(); 17 | 18 | void Identify(); 19 | Vector3 Transform(const Vector3& in) const; 20 | Vector3 TransformTranspose(const Vector3& in) const; 21 | void RotateAroundX(const float radians); 22 | void RotateAroundY(const float radians); 23 | void RotateAroundZ(const float radians); 24 | 25 | Matrix3& operator=(const Matrix3& in); 26 | Matrix3& operator=(const Matrix4& in); 27 | 28 | Matrix3 Multiply(const Matrix3& input) const; 29 | }; 30 | 31 | } /* namespace Framework */ 32 | #endif /* MATRIX3_H_ */ 33 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Math/Matrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX4_H_ 2 | #define MATRIX4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector3; 8 | class Vector4; 9 | class Matrix3; 10 | 11 | class Matrix4 12 | { 13 | public: 14 | enum Rows 15 | { 16 | X, 17 | Y, 18 | Z, 19 | W, 20 | NUM_ROWS 21 | }; 22 | 23 | float m_m[16]; 24 | 25 | Matrix4(); 26 | virtual ~Matrix4(); 27 | 28 | void Identify(); 29 | Vector3 Transform(const Vector3& in) const; 30 | Vector3 TransformTranspose(const Vector3& in) const; 31 | Vector4 Multiply(const Vector4& in) const; 32 | void RotateAroundX(float radians); 33 | void RotateAroundY(float radians); 34 | void RotateAroundZ(float radians); 35 | void Multiply(const Matrix4& in, Matrix4& out) const; 36 | 37 | Matrix4 Transpose() const; 38 | 39 | Matrix4& operator=(const Matrix3& in); 40 | Matrix4& operator=(const Matrix4& in); 41 | 42 | Vector4 GetRow(const Rows row) const; 43 | }; 44 | 45 | } /* namespace Framework */ 46 | #endif /* MATRIX4_H_ */ 47 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Math/Plane.cpp: -------------------------------------------------------------------------------- 1 | #include "Plane.h" 2 | 3 | namespace Framework 4 | { 5 | Plane::Plane() 6 | : m_d(0.0f) 7 | { 8 | } 9 | 10 | Plane::Plane(const Vector3& point, const Vector3& normal) 11 | { 12 | BuildPlane(point, normal); 13 | } 14 | 15 | Plane::~Plane() 16 | { 17 | 18 | } 19 | 20 | void Plane::BuildPlane(const Vector3& point, const Vector3& normal) 21 | { 22 | m_normal = normal; 23 | m_normal.Normalize(); 24 | m_d = m_normal.Dot(point); 25 | } 26 | 27 | bool Plane::IsInFront(const Vector4& point) const 28 | { 29 | return IsInFront(Vector3(point.m_x, point.m_y, point.m_z)); 30 | } 31 | 32 | bool Plane::IsInFront(const Vector3& point) const 33 | { 34 | return m_normal.Dot(point) >= m_d; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Math/Plane.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANE_H_ 2 | #define PLANE_H_ 3 | 4 | #include "Vector4.h" 5 | #include "Vector3.h" 6 | 7 | namespace Framework 8 | { 9 | class Plane 10 | { 11 | private: 12 | Vector3 m_normal; 13 | float m_d; 14 | 15 | public: 16 | Plane(); 17 | Plane(const Vector3& point, const Vector3& normal); 18 | ~Plane(); 19 | 20 | void BuildPlane(const Vector3& point, const Vector3& normal); 21 | 22 | bool IsInFront(const Vector4& point) const; 23 | bool IsInFront(const Vector3& point) const; 24 | }; 25 | } 26 | 27 | #endif // PLANE_H_ 28 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Math/Vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR3_H_ 2 | #define VECTOR3_H_ 3 | 4 | #include "Vector4.h" 5 | 6 | namespace Framework 7 | { 8 | 9 | class Vector3 10 | { 11 | public: 12 | float m_x; 13 | float m_y; 14 | float m_z; 15 | 16 | Vector3(); 17 | Vector3(const float x, const float y, const float z); 18 | virtual ~Vector3(); 19 | 20 | void Set(const Vector3& in); 21 | void Multiply(const float scalar); 22 | void Divide(const float scalar); 23 | void Add(const Vector3& in); 24 | void Subtract(const Vector3& in); 25 | void Negate(); 26 | float Length() const; 27 | float LengthSquared() const; 28 | void Normalize(); 29 | void GetNormal(Vector3& normal); 30 | 31 | Vector3& operator=(const Vector3& in); 32 | Vector3& operator=(const Vector4& in); 33 | 34 | float Dot(const Vector3& in) const; 35 | Vector3 Cross(const Vector3& in) const; 36 | }; 37 | 38 | } /* namespace Framework */ 39 | 40 | #endif /* VECTOR3_H_ */ 41 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Math/Vector4.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR4_H_ 2 | #define VECTOR4_H_ 3 | 4 | namespace Framework 5 | { 6 | 7 | class Vector4 8 | { 9 | public: 10 | float m_x; 11 | float m_y; 12 | float m_z; 13 | float m_w; 14 | 15 | Vector4(); 16 | Vector4(const float x, const float y, const float z, const float w); 17 | virtual ~Vector4(); 18 | 19 | void Set(Vector4& in); 20 | void Multiply(float scalar); 21 | void Divide(float scalar); 22 | void Add(Vector4& in); 23 | void Subtract(Vector4& in); 24 | 25 | Vector4& operator=(const Vector4& in); 26 | }; 27 | 28 | } /* namespace Framework */ 29 | #endif /* VECTOR4_H_ */ 30 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Platform/Android.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROID_H_ 2 | #define ANDROID_H_ 3 | 4 | #include 5 | #include "../Kernel/Task.h" 6 | 7 | namespace Framework 8 | { 9 | class Renderer; 10 | 11 | class Android 12 | : public Task 13 | { 14 | private: 15 | static bool m_bClosing; 16 | android_app* m_pState; 17 | 18 | public: 19 | Android(android_app* pState, const unsigned int priority); 20 | virtual ~Android(); 21 | 22 | android_app* GetAppState() { return m_pState; } 23 | 24 | virtual bool Start(); 25 | virtual void OnSuspend(); 26 | virtual void Update(); 27 | virtual void OnResume(); 28 | virtual void Stop(); 29 | 30 | static void ClearClosing() { m_bClosing = false; } 31 | static bool IsClosing() { return m_bClosing; } 32 | }; 33 | } 34 | 35 | #endif // ANDROID_H_ 36 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Renderer/Geometry/Geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Geometry.cpp 3 | * 4 | * Created on: 05/06/2012 5 | * Author: bruce 6 | */ 7 | 8 | #include "Geometry.h" 9 | 10 | namespace Framework 11 | { 12 | Geometry::Geometry() 13 | : m_numVertices(0) 14 | , m_numIndices(0) 15 | , m_pVertices(NULL) 16 | , m_pIndices(NULL) 17 | , m_numVertexPositionElements(0) 18 | , m_numTexCoordElements(0) 19 | , m_vertexStride(0) 20 | { 21 | } 22 | 23 | Geometry::~Geometry() 24 | { 25 | } 26 | } // Framework 27 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Renderer/Shaders/BasicShader.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSHADER_H_ 2 | #define BASICSHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class BasicShader 9 | : public Shader 10 | { 11 | private: 12 | GLint m_positionAttributeHandle; 13 | 14 | public: 15 | BasicShader(); 16 | virtual ~BasicShader(); 17 | 18 | virtual void Link(); 19 | virtual void Setup(Renderable& renderable); 20 | }; 21 | } 22 | 23 | #endif // BASICSHADER_H_ 24 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Renderer/Shaders/Shader.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_H_ 2 | #define SHADER_H_ 3 | 4 | #include 5 | #include 6 | #include "../Renderable.h" 7 | 8 | namespace Framework 9 | { 10 | class Shader 11 | { 12 | private: 13 | void LoadShader(GLenum shaderType, std::string& shaderCode); 14 | 15 | protected: 16 | GLuint m_vertexShaderId; 17 | GLuint m_fragmentShaderId; 18 | GLint m_programId; 19 | 20 | std::string m_vertexShaderCode; 21 | std::string m_fragmentShaderCode; 22 | 23 | bool m_isLinked; 24 | 25 | public: 26 | Shader(); 27 | virtual ~Shader(); 28 | 29 | virtual void Link(); 30 | virtual void Setup(Renderable& renderable); 31 | 32 | bool IsLinked() { return m_isLinked; } 33 | }; 34 | } 35 | 36 | #endif // SHADER_H_ 37 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Renderer/Shaders/TextureShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURESHADER_H_ 2 | #define TEXTURESHADER_H_ 3 | 4 | #include "Shader.h" 5 | 6 | namespace Framework 7 | { 8 | class Texture; 9 | 10 | class TextureShader 11 | : public Shader 12 | { 13 | private: 14 | Texture* m_pTexture; 15 | GLint m_positionAttributeHandle; 16 | GLint m_texCoordAttributeHandle; 17 | GLint m_samplerHandle; 18 | 19 | public: 20 | TextureShader(); 21 | virtual ~TextureShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | 26 | void SetTexture(Texture* pTexture); 27 | Texture* GetTexture(); 28 | }; 29 | 30 | inline void TextureShader::SetTexture(Texture* pTexture) 31 | { 32 | m_pTexture = pTexture; 33 | } 34 | 35 | inline Texture* TextureShader::GetTexture() 36 | { 37 | return m_pTexture; 38 | } 39 | } 40 | 41 | #endif // TEXTURESHADER_H_ 42 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Renderer/Shaders/TransformAmbientDiffuseShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMAMBIENTDIFFUSESHADER_H_ 2 | #define TRANSFORMAMBIENTDIFFUSESHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformAmbientDiffuseShader 10 | : public Shader 11 | { 12 | private: 13 | GLint m_modelViewProjUniformHandle; 14 | GLint m_modelITMatrixUniformHandle; 15 | GLint m_positionAttributeHandle; 16 | GLint m_normalAttributeHandle; 17 | GLint m_ambientColorUniformHandle; 18 | GLint m_diffuseColorUniformHandle; 19 | GLint m_ambientLightUniformHandle; 20 | GLint m_diffuseLightUniformHandle; 21 | GLint m_lightDirectionUniformHandle; 22 | 23 | public: 24 | TransformAmbientDiffuseShader(); 25 | virtual ~TransformAmbientDiffuseShader(); 26 | 27 | virtual void Link(); 28 | virtual void Setup(Renderable& renderable); 29 | }; 30 | } 31 | 32 | #endif // TRANSFORMAMBIENTDIFFUSESHADER_H_ 33 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Renderer/Shaders/TransformAmbientShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMAMBIENTSHADER_H_ 2 | #define TRANSFORMAMBIENTSHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformAmbientShader 10 | : public Shader 11 | { 12 | private: 13 | GLint m_transformUniformHandle; 14 | GLint m_positionAttributeHandle; 15 | GLint m_normalAttributeHandle; 16 | GLint m_colorUniformHandle; 17 | GLint m_ambientLightUniformHandle; 18 | 19 | public: 20 | TransformAmbientShader(); 21 | virtual ~TransformAmbientShader(); 22 | 23 | virtual void Link(); 24 | virtual void Setup(Renderable& renderable); 25 | }; 26 | } 27 | 28 | #endif // TRANSFORMAMBIENTSHADER_H_ 29 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Renderer/Shaders/TransformShader.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMSHADER_H_ 2 | #define TRANSFORMSHADER_H_ 3 | 4 | #include "../../Math/Matrix4.h" 5 | #include "Shader.h" 6 | 7 | namespace Framework 8 | { 9 | class TransformShader 10 | : public Shader 11 | { 12 | private: 13 | GLint m_transformUniformHandle; 14 | GLint m_positionAttributeHandle; 15 | GLint m_colorAttributeHandle; 16 | 17 | public: 18 | TransformShader(); 19 | virtual ~TransformShader(); 20 | 21 | virtual void Link(); 22 | virtual void Setup(Renderable& renderable); 23 | }; 24 | } 25 | 26 | #endif // TRANSFORMSHADER_H_ 27 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Utilities/File.cpp: -------------------------------------------------------------------------------- 1 | #include "File.h" 2 | #include 3 | 4 | namespace Framework 5 | { 6 | AAssetManager* File::m_pAssetManager = NULL; 7 | 8 | File::File(std::string name) 9 | : m_filename(name) 10 | { 11 | assert(m_pAssetManager != NULL); 12 | m_pAsset = NULL; 13 | } 14 | 15 | File::~File() 16 | { 17 | Close(); 18 | } 19 | 20 | bool File::Open() 21 | { 22 | assert(m_pAssetManager != NULL); 23 | 24 | m_pAsset = AAssetManager_open(m_pAssetManager, m_filename.c_str(), AASSET_MODE_UNKNOWN); 25 | return !!m_pAsset; 26 | } 27 | 28 | void File::Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead) 29 | { 30 | bytesRead = AAsset_read(m_pAsset, pBuffer, bytesToRead); 31 | } 32 | 33 | void File::Close() 34 | { 35 | if (m_pAsset) 36 | { 37 | AAsset_close(m_pAsset); 38 | m_pAsset = NULL; 39 | } 40 | } 41 | 42 | unsigned int File::Length() const 43 | { 44 | return AAsset_getLength(m_pAsset); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Utilities/File.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H_ 2 | #define FILE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace Framework 8 | { 9 | class File 10 | { 11 | private: 12 | std::string m_filename; 13 | static AAssetManager* m_pAssetManager; 14 | AAsset* m_pAsset; 15 | 16 | public: 17 | explicit File(std::string name); 18 | virtual ~File(); 19 | 20 | bool Open(); 21 | void Read(void* pBuffer, const unsigned int bytesToRead, size_t& bytesRead); 22 | void Close(); 23 | 24 | unsigned int Length() const; 25 | 26 | static const size_t READ_FAILED = 0xFFFFFFFF; 27 | 28 | static void SetAssetManager(AAssetManager* pAssetManager) { m_pAssetManager = pAssetManager; } 29 | }; 30 | } 31 | 32 | #endif // FILE_H_ 33 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Utilities/Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_H_ 2 | #define HASH_H_ 3 | 4 | #include 5 | 6 | namespace Framework 7 | { 8 | // SDBM Hash 9 | inline unsigned int Hash(const std::string& key) 10 | { 11 | unsigned int result = 0; 12 | 13 | for (unsigned int i=0; i 5 | 6 | namespace Framework 7 | { 8 | template 9 | class Singleton 10 | { 11 | private: 12 | static T* ms_singleton; 13 | 14 | public: 15 | Singleton() 16 | { 17 | assert(!ms_singleton); 18 | ms_singleton = static_cast(this); 19 | } 20 | 21 | ~Singleton() 22 | { 23 | assert(ms_singleton); 24 | ms_singleton = 0; 25 | } 26 | 27 | static T& GetSingleton() { return *ms_singleton; } 28 | static T* GetSingletonPtr() { return ms_singleton; } 29 | }; 30 | 31 | template T* Singleton::ms_singleton = 0; 32 | } 33 | 34 | #endif // SINGLETON_H_ 35 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/jni/Framework/Utilities/TGAFile.cpp: -------------------------------------------------------------------------------- 1 | #include "TGAFile.h" 2 | 3 | namespace Framework 4 | { 5 | TGAFile::TGAFile(void* pData) 6 | { 7 | size_t size = sizeof(unsigned short); 8 | m_pHeader = static_cast(pData); 9 | m_pImageData = static_cast(static_cast(pData) + sizeof(TGAHeader)); 10 | } 11 | 12 | TGAFile::~TGAFile() 13 | { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter9/Chapter9/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter9/Chapter9/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter9/Chapter9/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter9/Chapter9/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/Chapter9/Chapter9/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Chapter9/Chapter9/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Chapter9 4 | 5 | -------------------------------------------------------------------------------- /Chapter9/Chapter9/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-android-cpp-game-dev/f08f0712ee614309d3101d914a731e2ba5ffb0d0/LICENSE.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Beginning Android C++ Game Development*](http://www.apress.com/9781430258308) by Bruce Sutherland (Apress, 2013). 4 | 5 | ![Cover image](9781430258308.jpg) 6 | 7 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 8 | 9 | ## Releases 10 | 11 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 12 | 13 | ## Contributions 14 | 15 | See the file Contributing.md for more information on how you can contribute to this repository. 16 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! --------------------------------------------------------------------------------