joybox 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +6 -0
  4. data/Gemfile.lock +27 -0
  5. data/LICENSE +22 -0
  6. data/README.md +86 -0
  7. data/Rakefile +14 -0
  8. data/app/app_delegate.rb +49 -0
  9. data/app/layers/box2d_layer.rb +109 -0
  10. data/app/layers/cocos2d_layer.rb +14 -0
  11. data/app/layers/cocos_motion_layer.rb +145 -0
  12. data/app/layers/menu_layer.rb +59 -0
  13. data/joybox.gemspec +25 -0
  14. data/lib/joybox.rb +47 -0
  15. data/lib/joybox/box2d/body.rb +106 -0
  16. data/lib/joybox/box2d/world.rb +79 -0
  17. data/lib/joybox/cocos2d/actions/actions.rb +7 -0
  18. data/lib/joybox/cocos2d/actions/move.rb +31 -0
  19. data/lib/joybox/cocos2d/actions/repeat.rb +24 -0
  20. data/lib/joybox/cocos2d/actions/rotate.rb +31 -0
  21. data/lib/joybox/cocos2d/actions/scale.rb +31 -0
  22. data/lib/joybox/cocos2d/actions/sequence.rb +22 -0
  23. data/lib/joybox/cocos2d/actions/skew.rb +36 -0
  24. data/lib/joybox/cocos2d/cocos2d.rb +15 -0
  25. data/lib/joybox/cocos2d/common/cg_point.rb +37 -0
  26. data/lib/joybox/cocos2d/common/color.rb +49 -0
  27. data/lib/joybox/cocos2d/common/gc_size.rb +39 -0
  28. data/lib/joybox/cocos2d/common/ns_set.rb +5 -0
  29. data/lib/joybox/cocos2d/common/numeric.rb +14 -0
  30. data/lib/joybox/cocos2d/common/screen.rb +39 -0
  31. data/lib/joybox/cocos2d/common/ui_touch.rb +15 -0
  32. data/lib/joybox/cocos2d/configuration/configuration.rb +68 -0
  33. data/lib/joybox/cocos2d/configuration/file_utils.rb +33 -0
  34. data/lib/joybox/cocos2d/configuration/gl_view.rb +44 -0
  35. data/lib/joybox/cocos2d/configuration/texture_2d.rb +27 -0
  36. data/lib/joybox/cocos2d/core/layer.rb +87 -0
  37. data/lib/joybox/cocos2d/core/node.rb +26 -0
  38. data/lib/joybox/cocos2d/core/physics_sprite.rb +52 -0
  39. data/lib/joybox/cocos2d/core/scene.rb +24 -0
  40. data/lib/joybox/cocos2d/core/sprite.rb +43 -0
  41. data/lib/joybox/cocos2d/core/sprite_batch.rb +24 -0
  42. data/lib/joybox/cocos2d/director.rb +43 -0
  43. data/lib/joybox/cocos2d/macros.rb +234 -0
  44. data/lib/joybox/cocos2d/ui/label.rb +34 -0
  45. data/lib/joybox/cocos2d/ui/menu.rb +25 -0
  46. data/lib/joybox/cocos2d/ui/menu_image.rb +22 -0
  47. data/lib/joybox/cocos2d/ui/menu_label.rb +45 -0
  48. data/lib/joybox/cocos2d/ui/ui.rb +7 -0
  49. data/lib/joybox/version.rb +3 -0
  50. data/resources/box2d/blocks_sprite_sheet.png +0 -0
  51. data/resources/cocos_motion/dot.png +0 -0
  52. data/resources/cocos_motion/dot_selected.png +0 -0
  53. data/resources/cocos_motion/grossini.png +0 -0
  54. data/resources/cocos_motion/grossinis_sister.png +0 -0
  55. data/resources/cocos_motion/grossinis_sister_two.png +0 -0
  56. data/resources/cocos_motion/left_arrow.png +0 -0
  57. data/resources/cocos_motion/left_arrow_selected.png +0 -0
  58. data/resources/cocos_motion/right_arrow.png +0 -0
  59. data/resources/cocos_motion/right_arrow_selected.png +0 -0
  60. data/resources/fps_images-hd.png +0 -0
  61. data/resources/fps_images-ipadhd.png +0 -0
  62. data/resources/fps_images.png +0 -0
  63. data/spec/lib/joybox/cocos2d/cocos2d_spec.rb +7 -0
  64. data/spec/lib/joybox/cocos2d/macros_spec.rb +37 -0
  65. data/spec/main_spec.rb +9 -0
  66. data/vendor/Box2D.framework/Box2D +0 -0
  67. data/vendor/Box2D.framework/Box2D.framework.bridgesupport +166 -0
  68. data/vendor/Box2D.framework/Versions/A/Box2D +0 -0
  69. data/vendor/Box2D.framework/Versions/A/Headers/Collision/B2DContactListener.h +25 -0
  70. data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DEdgeShape.h +17 -0
  71. data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DPolygonShape.h +16 -0
  72. data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DShape.h +15 -0
  73. data/vendor/Box2D.framework/Versions/A/Headers/Dynamics/B2DBody.h +43 -0
  74. data/vendor/Box2D.framework/Versions/A/Headers/Dynamics/B2DWorld.h +41 -0
  75. data/vendor/Box2D.framework/Versions/A/Resources/Box2DConfig.cmake +3 -0
  76. data/vendor/Box2D.framework/Versions/A/Resources/CMakeLists.txt +205 -0
  77. data/vendor/Cocos2D/Cocos2D.bridgesupport +7808 -0
  78. data/vendor/Cocos2D/include/CCAction.h +195 -0
  79. data/vendor/Cocos2D/include/CCActionCamera.h +73 -0
  80. data/vendor/Cocos2D/include/CCActionCatmullRom.h +139 -0
  81. data/vendor/Cocos2D/include/CCActionEase.h +159 -0
  82. data/vendor/Cocos2D/include/CCActionGrid.h +165 -0
  83. data/vendor/Cocos2D/include/CCActionGrid3D.h +205 -0
  84. data/vendor/Cocos2D/include/CCActionInstant.h +227 -0
  85. data/vendor/Cocos2D/include/CCActionInterval.h +431 -0
  86. data/vendor/Cocos2D/include/CCActionManager.h +113 -0
  87. data/vendor/Cocos2D/include/CCActionPageTurn3D.h +42 -0
  88. data/vendor/Cocos2D/include/CCActionProgressTimer.h +59 -0
  89. data/vendor/Cocos2D/include/CCActionTiledGrid.h +211 -0
  90. data/vendor/Cocos2D/include/CCActionTween.h +62 -0
  91. data/vendor/Cocos2D/include/CCAnimation.h +150 -0
  92. data/vendor/Cocos2D/include/CCAnimationCache.h +74 -0
  93. data/vendor/Cocos2D/include/CCArray.h +119 -0
  94. data/vendor/Cocos2D/include/CCAtlasNode.h +96 -0
  95. data/vendor/Cocos2D/include/CCCamera.h +98 -0
  96. data/vendor/Cocos2D/include/CCConfiguration.h +126 -0
  97. data/vendor/Cocos2D/include/CCDirector.h +344 -0
  98. data/vendor/Cocos2D/include/CCDirectorIOS.h +104 -0
  99. data/vendor/Cocos2D/include/CCDrawingPrimitives.h +139 -0
  100. data/vendor/Cocos2D/include/CCES2Renderer.h +83 -0
  101. data/vendor/Cocos2D/include/CCESRenderer.h +54 -0
  102. data/vendor/Cocos2D/include/CCFileUtils.h +188 -0
  103. data/vendor/Cocos2D/include/CCGL.h +72 -0
  104. data/vendor/Cocos2D/include/CCGLProgram.h +150 -0
  105. data/vendor/Cocos2D/include/CCGLView.h +160 -0
  106. data/vendor/Cocos2D/include/CCGrabber.h +44 -0
  107. data/vendor/Cocos2D/include/CCGrid.h +130 -0
  108. data/vendor/Cocos2D/include/CCLabelAtlas.h +68 -0
  109. data/vendor/Cocos2D/include/CCLabelBMFont.h +216 -0
  110. data/vendor/Cocos2D/include/CCLabelTTF.h +132 -0
  111. data/vendor/Cocos2D/include/CCLayer.h +280 -0
  112. data/vendor/Cocos2D/include/CCMenu.h +100 -0
  113. data/vendor/Cocos2D/include/CCMenuItem.h +423 -0
  114. data/vendor/Cocos2D/include/CCMotionStreak.h +87 -0
  115. data/vendor/Cocos2D/include/CCNS.h +54 -0
  116. data/vendor/Cocos2D/include/CCNode+Debug.h +39 -0
  117. data/vendor/Cocos2D/include/CCNode.h +569 -0
  118. data/vendor/Cocos2D/include/CCParallaxNode.h +50 -0
  119. data/vendor/Cocos2D/include/CCParticleBatchNode.h +99 -0
  120. data/vendor/Cocos2D/include/CCParticleExamples.h +95 -0
  121. data/vendor/Cocos2D/include/CCParticleSystem.h +453 -0
  122. data/vendor/Cocos2D/include/CCParticleSystemQuad.h +73 -0
  123. data/vendor/Cocos2D/include/CCProfiling.h +89 -0
  124. data/vendor/Cocos2D/include/CCProgressTimer.h +94 -0
  125. data/vendor/Cocos2D/include/CCProtocols.h +132 -0
  126. data/vendor/Cocos2D/include/CCRenderTexture.h +139 -0
  127. data/vendor/Cocos2D/include/CCScene.h +43 -0
  128. data/vendor/Cocos2D/include/CCScheduler.h +230 -0
  129. data/vendor/Cocos2D/include/CCShaderCache.h +60 -0
  130. data/vendor/Cocos2D/include/CCSprite.h +288 -0
  131. data/vendor/Cocos2D/include/CCSpriteBatchNode.h +138 -0
  132. data/vendor/Cocos2D/include/CCSpriteFrame.h +126 -0
  133. data/vendor/Cocos2D/include/CCSpriteFrameCache.h +121 -0
  134. data/vendor/Cocos2D/include/CCTMXLayer.h +164 -0
  135. data/vendor/Cocos2D/include/CCTMXObjectGroup.h +67 -0
  136. data/vendor/Cocos2D/include/CCTMXTiledMap.h +145 -0
  137. data/vendor/Cocos2D/include/CCTMXXMLParser.h +217 -0
  138. data/vendor/Cocos2D/include/CCTexture2D.h +357 -0
  139. data/vendor/Cocos2D/include/CCTextureAtlas.h +188 -0
  140. data/vendor/Cocos2D/include/CCTextureCache.h +146 -0
  141. data/vendor/Cocos2D/include/CCTexturePVR.h +129 -0
  142. data/vendor/Cocos2D/include/CCTileMapAtlas.h +83 -0
  143. data/vendor/Cocos2D/include/CCTouchDelegateProtocol.h +75 -0
  144. data/vendor/Cocos2D/include/CCTouchDispatcher.h +120 -0
  145. data/vendor/Cocos2D/include/CCTouchHandler.h +93 -0
  146. data/vendor/Cocos2D/include/CCTransition.h +296 -0
  147. data/vendor/Cocos2D/include/CCTransitionPageTurn.h +60 -0
  148. data/vendor/Cocos2D/include/CCTransitionProgress.h +62 -0
  149. data/vendor/Cocos2D/include/CCVertex.h +36 -0
  150. data/vendor/Cocos2D/include/CGPointExtension.h +344 -0
  151. data/vendor/Cocos2D/include/CocosDenshion/CDAudioManager.h +243 -0
  152. data/vendor/Cocos2D/include/CocosDenshion/CDConfig.h +60 -0
  153. data/vendor/Cocos2D/include/CocosDenshion/CDOpenALSupport.h +77 -0
  154. data/vendor/Cocos2D/include/CocosDenshion/CDXPropertyModifierAction.h +45 -0
  155. data/vendor/Cocos2D/include/CocosDenshion/CocosDenshion.h +440 -0
  156. data/vendor/Cocos2D/include/CocosDenshion/SimpleAudioEngine.h +90 -0
  157. data/vendor/Cocos2D/include/NSThread+performBlock.h +22 -0
  158. data/vendor/Cocos2D/include/OpenGL_Internal.h +86 -0
  159. data/vendor/Cocos2D/include/RubyMotionSchedule.h +7 -0
  160. data/vendor/Cocos2D/include/TGAlib.h +55 -0
  161. data/vendor/Cocos2D/include/TransformUtils.h +36 -0
  162. data/vendor/Cocos2D/include/ZipUtils.h +91 -0
  163. data/vendor/Cocos2D/include/base64.h +33 -0
  164. data/vendor/Cocos2D/include/ccCArray.h +229 -0
  165. data/vendor/Cocos2D/include/ccConfig.h +245 -0
  166. data/vendor/Cocos2D/include/ccDeprecated.h +300 -0
  167. data/vendor/Cocos2D/include/ccGLStateCache.h +138 -0
  168. data/vendor/Cocos2D/include/ccMacros.h +353 -0
  169. data/vendor/Cocos2D/include/ccShader_PositionColor_frag.h +12 -0
  170. data/vendor/Cocos2D/include/ccShader_PositionColor_vert.h +17 -0
  171. data/vendor/Cocos2D/include/ccShader_PositionTextureA8Color_frag.h +16 -0
  172. data/vendor/Cocos2D/include/ccShader_PositionTextureA8Color_vert.h +21 -0
  173. data/vendor/Cocos2D/include/ccShader_PositionTextureColorAlphaTest_frag.h +23 -0
  174. data/vendor/Cocos2D/include/ccShader_PositionTextureColor_frag.h +14 -0
  175. data/vendor/Cocos2D/include/ccShader_PositionTextureColor_vert.h +22 -0
  176. data/vendor/Cocos2D/include/ccShader_PositionTexture_frag.h +13 -0
  177. data/vendor/Cocos2D/include/ccShader_PositionTexture_uColor_frag.h +16 -0
  178. data/vendor/Cocos2D/include/ccShader_PositionTexture_uColor_vert.h +18 -0
  179. data/vendor/Cocos2D/include/ccShader_PositionTexture_vert.h +17 -0
  180. data/vendor/Cocos2D/include/ccShader_Position_uColor_frag.h +12 -0
  181. data/vendor/Cocos2D/include/ccShader_Position_uColor_vert.h +19 -0
  182. data/vendor/Cocos2D/include/ccShaders.h +45 -0
  183. data/vendor/Cocos2D/include/ccTypes.h +374 -0
  184. data/vendor/Cocos2D/include/ccUtils.h +36 -0
  185. data/vendor/Cocos2D/include/cocos2d.h +178 -0
  186. data/vendor/Cocos2D/include/kazmath/GL/mat4stack.h +51 -0
  187. data/vendor/Cocos2D/include/kazmath/GL/matrix.h +58 -0
  188. data/vendor/Cocos2D/include/kazmath/aabb.h +53 -0
  189. data/vendor/Cocos2D/include/kazmath/kazmath.h +39 -0
  190. data/vendor/Cocos2D/include/kazmath/mat3.h +75 -0
  191. data/vendor/Cocos2D/include/kazmath/mat4.h +93 -0
  192. data/vendor/Cocos2D/include/kazmath/neon_matrix_impl.h +41 -0
  193. data/vendor/Cocos2D/include/kazmath/plane.h +70 -0
  194. data/vendor/Cocos2D/include/kazmath/quaternion.h +113 -0
  195. data/vendor/Cocos2D/include/kazmath/ray2.h +50 -0
  196. data/vendor/Cocos2D/include/kazmath/utility.h +74 -0
  197. data/vendor/Cocos2D/include/kazmath/vec2.h +64 -0
  198. data/vendor/Cocos2D/include/kazmath/vec3.h +68 -0
  199. data/vendor/Cocos2D/include/kazmath/vec4.h +68 -0
  200. data/vendor/Cocos2D/include/uthash.h +972 -0
  201. data/vendor/Cocos2D/include/utlist.h +490 -0
  202. data/vendor/Cocos2D/libCocosDenshion.a +0 -0
  203. data/vendor/Cocos2D/libcocos2d.a +0 -0
  204. metadata +277 -0
@@ -0,0 +1,138 @@
1
+ /*
2
+ * cocos2d for iPhone: http://www.cocos2d-iphone.org
3
+ *
4
+ * Copyright (c) 2011 Ricardo Quesada
5
+ * Copyright (c) 2011 Zynga Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+
26
+ #import <TargetConditionals.h>
27
+ #import "ccMacros.h"
28
+ #import "Platforms/CCGL.h"
29
+
30
+ @class CCGLProgram;
31
+
32
+ /** vertex attrib flags */
33
+ enum {
34
+ kCCVertexAttribFlag_None = 0,
35
+
36
+ kCCVertexAttribFlag_Position = 1 << 0,
37
+ kCCVertexAttribFlag_Color = 1 << 1,
38
+ kCCVertexAttribFlag_TexCoords = 1 << 2,
39
+
40
+ kCCVertexAttribFlag_PosColorTex = ( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color | kCCVertexAttribFlag_TexCoords ),
41
+ };
42
+
43
+ /** GL server side states */
44
+ typedef enum {
45
+ // CC_GL_SCISSOR_TEST = 1 << 0,
46
+ // CC_GL_STENCIL_TEST = 1 << 1,
47
+ // CC_GL_DEPTH_TEST = 1 << 2,
48
+ CC_GL_BLEND = 1 << 3,
49
+ // CC_GL_DITHER = 1 << 4,
50
+
51
+ // CC_GL_ALL = ( CC_GL_SCISSOR_TEST | CC_GL_STENCIL_TEST | CC_GL_DEPTH_TEST | CC_GL_BLEND | CC_GL_DITHER ),
52
+ CC_GL_ALL = ( CC_GL_BLEND ),
53
+
54
+ } ccGLServerState;
55
+
56
+ #ifdef __cplusplus
57
+ extern "C" {
58
+ #endif
59
+
60
+ /** @file ccGLStateCache.h
61
+ */
62
+
63
+ /** Invalidates the GL state cache.
64
+ If CC_ENABLE_GL_STATE_CACHE it will reset the GL state cache.
65
+ @since v2.0.0
66
+ */
67
+ void ccGLInvalidateStateCache( void );
68
+
69
+ /** Uses the GL program in case program is different than the current one.
70
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly.
71
+ @since v2.0.0
72
+ */
73
+ void ccGLUseProgram( GLuint program );
74
+
75
+ /** Deletes the GL program. If it is the one that is being used, it invalidates it.
76
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly.
77
+ @since v2.0.0
78
+ */
79
+ void ccGLDeleteProgram( GLuint program );
80
+
81
+ /** Uses a blending function in case it not already used.
82
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly.
83
+ @since v2.0.0
84
+ */
85
+ void ccGLBlendFunc(GLenum sfactor, GLenum dfactor);
86
+
87
+ /** sets the projection matrix as dirty
88
+ @since v2.0.0
89
+ */
90
+ void ccSetProjectionMatrixDirty( void );
91
+
92
+ /** Will enable the vertex attribs that are passed as flags.
93
+ Possible flags:
94
+
95
+ * kCCVertexAttribFlag_Position
96
+ * kCCVertexAttribFlag_Color
97
+ * kCCVertexAttribFlag_TexCoords
98
+
99
+ These flags can be ORed. The flags that are not present, will be disabled.
100
+
101
+ @since v2.0.0
102
+ */
103
+ void ccGLEnableVertexAttribs( unsigned int flags );
104
+
105
+ /** If the active texture is not textureEnum, then it will active it.
106
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.
107
+ @since v2.0.0
108
+ */
109
+ void ccGLActiveTexture(GLenum textureEnum );
110
+
111
+ /** Returns the active texture.
112
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glGetIntegerv(GL_ACTIVE_TEXTURE);
113
+ @since v2.0.0
114
+ */
115
+ GLenum ccGLGetActiveTexture( void );
116
+
117
+
118
+ /** If the texture is not already bound, it binds it.
119
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
120
+ @since v2.0.0
121
+ */
122
+ void ccGLBindTexture2D(GLuint textureId );
123
+
124
+ /** It will delete a given texture. If the texture was bound, it will invalidate the cached.
125
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
126
+ @since v2.0.0
127
+ */
128
+ void ccGLDeleteTexture(GLuint textureId);
129
+
130
+ /** It will enable / disable the server side GL states.
131
+ If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glEnable() directly.
132
+ @since v2.0.0
133
+ */
134
+ void ccGLEnable( ccGLServerState flags );
135
+
136
+ #ifdef __cplusplus
137
+ }
138
+ #endif
@@ -0,0 +1,353 @@
1
+ /*
2
+ * cocos2d for iPhone: http://www.cocos2d-iphone.org
3
+ *
4
+ * Copyright (c) 2008-2010 Ricardo Quesada
5
+ * Copyright (c) 2011 Zynga Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+
26
+
27
+ #import <math.h>
28
+ #import "ccConfig.h"
29
+
30
+ #import <Foundation/Foundation.h>
31
+ #import <Availability.h>
32
+
33
+ /**
34
+ @file
35
+ cocos2d helper macros
36
+ */
37
+
38
+ #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
39
+ #define __CC_PLATFORM_IOS 1
40
+ #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
41
+ #define __CC_PLATFORM_MAC 1
42
+ #endif
43
+
44
+ /*
45
+ * if COCOS2D_DEBUG is not defined, or if it is 0 then
46
+ * all CCLOGXXX macros will be disabled
47
+ *
48
+ * if COCOS2D_DEBUG==1 then:
49
+ * CCLOG() will be enabled
50
+ * CCLOGERROR() will be enabled
51
+ * CCLOGINFO() will be disabled
52
+ *
53
+ * if COCOS2D_DEBUG==2 or higher then:
54
+ * CCLOG() will be enabled
55
+ * CCLOGERROR() will be enabled
56
+ * CCLOGINFO() will be enabled
57
+ */
58
+
59
+
60
+ #define __CCLOGWITHFUNCTION(s, ...) \
61
+ NSLog(@"%s : %@",__FUNCTION__,[NSString stringWithFormat:(s), ##__VA_ARGS__])
62
+
63
+ #define __CCLOG(s, ...) \
64
+ NSLog(@"%@",[NSString stringWithFormat:(s), ##__VA_ARGS__])
65
+
66
+
67
+ #if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
68
+ #define CCLOG(...) do {} while (0)
69
+ #define CCLOGWARN(...) do {} while (0)
70
+ #define CCLOGINFO(...) do {} while (0)
71
+
72
+ #elif COCOS2D_DEBUG == 1
73
+ #define CCLOG(...) __CCLOG(__VA_ARGS__)
74
+ #define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__)
75
+ #define CCLOGINFO(...) do {} while (0)
76
+
77
+ #elif COCOS2D_DEBUG > 1
78
+ #define CCLOG(...) __CCLOG(__VA_ARGS__)
79
+ #define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__)
80
+ #define CCLOGINFO(...) __CCLOG(__VA_ARGS__)
81
+ #endif // COCOS2D_DEBUG
82
+
83
+
84
+ /** @def CC_SWAP
85
+ simple macro that swaps 2 variables
86
+ */
87
+ #define CC_SWAP( x, y ) \
88
+ ({ __typeof__(x) temp = (x); \
89
+ x = y; y = temp; \
90
+ })
91
+
92
+
93
+ /** @def CCRANDOM_MINUS1_1
94
+ returns a random float between -1 and 1
95
+ */
96
+ #define CCRANDOM_MINUS1_1() ((random() / (float)0x3fffffff )-1.0f)
97
+
98
+ /** @def CCRANDOM_0_1
99
+ returns a random float between 0 and 1
100
+ */
101
+ #define CCRANDOM_0_1() ((random() / (float)0x7fffffff ))
102
+
103
+ /** @def CC_DEGREES_TO_RADIANS
104
+ converts degrees to radians
105
+ */
106
+ #define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180
107
+
108
+ /** @def CC_RADIANS_TO_DEGREES
109
+ converts radians to degrees
110
+ */
111
+ #define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180
112
+
113
+ #define kCCRepeatForever UINT_MAX -1
114
+ /** @def CC_BLEND_SRC
115
+ default gl blend src function. Compatible with premultiplied alpha images.
116
+ */
117
+ #define CC_BLEND_SRC GL_ONE
118
+ #define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
119
+
120
+ /** @def CC_DIRECTOR_INIT
121
+ - Initializes an CCGLView with 0-bit depth format, and RGB565 render buffer.
122
+ - The CCGLView view will have multiple touches disabled.
123
+ - It will create a UIWindow and it will assign it the 'window_' ivar. 'window_' must be declared before calling this marcro.
124
+ - It will create a UINavigationController and it will assign it the 'navigationController_' ivar. 'navController_' must be declared before using this macro.
125
+ - The director_ will be the root view controller of the navController.
126
+ - It will connect the CCGLView to the Director
127
+ - It will connect the UINavController view to the UIWindow.
128
+ - It will try to run at 60 FPS.
129
+ - It will connect the director with the CCGLView.
130
+
131
+ IMPORTANT: If you want to use another type of render buffer (eg: RGBA8)
132
+ or if you want to use a 16-bit or 24-bit depth buffer, you should NOT
133
+ use this macro. Instead, you should create the CCGLView manually.
134
+
135
+ @since v0.99.4
136
+ */
137
+
138
+ #ifdef __CC_PLATFORM_IOS
139
+
140
+ #define CC_DIRECTOR_INIT() \
141
+ do { \
142
+ window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; \
143
+ director_ = (CCDirectorIOS*)[CCDirector sharedDirector]; \
144
+ [director_ setDisplayStats:NO]; \
145
+ [director_ setAnimationInterval:1.0/60]; \
146
+ CCGLView *__glView = [CCGLView viewWithFrame:[window_ bounds] \
147
+ pixelFormat:kEAGLColorFormatRGB565 \
148
+ depthFormat:0 /* GL_DEPTH_COMPONENT24_OES */ \
149
+ preserveBackbuffer:NO \
150
+ sharegroup:nil \
151
+ multiSampling:NO \
152
+ numberOfSamples:0 \
153
+ ]; \
154
+ [director_ setView:__glView]; \
155
+ [director_ setDelegate:self]; \
156
+ director_.wantsFullScreenLayout = YES; \
157
+ if( ! [director_ enableRetinaDisplay:YES] ) \
158
+ CCLOG(@"Retina Display Not supported"); \
159
+ navController_ = [[UINavigationController alloc] initWithRootViewController:director_]; \
160
+ navController_.navigationBarHidden = YES; \
161
+ [window_ addSubview:navController_.view]; \
162
+ [window_ makeKeyAndVisible]; \
163
+ } while(0)
164
+
165
+
166
+ #elif __CC_PLATFORM_MAC
167
+
168
+ #define CC_DIRECTOR_INIT(__WINSIZE__) \
169
+ do { \
170
+ NSRect frameRect = NSMakeRect(0, 0, (__WINSIZE__).width, (__WINSIZE__).height); \
171
+ window_ = [[CCWindow alloc] initWithFrame:frameRect fullscreen:NO]; \
172
+ glView_ = [[CCGLView alloc] initWithFrame:frameRect shareContext:nil]; \
173
+ [self.window setContentView:self.glView]; \
174
+ director_ = (CCDirectorMac*) [CCDirector sharedDirector]; \
175
+ [director_ setDisplayStats:NO]; \
176
+ [director_ setView:self.glView]; \
177
+ [director_ setOriginalWinSize:__WINSIZE__]; \
178
+ [self.window makeMainWindow]; \
179
+ [self.window makeKeyAndOrderFront:self]; \
180
+ [self.window center]; \
181
+ } while(0)
182
+
183
+ #endif
184
+
185
+ /** @def CC_NODE_DRAW_SETUP
186
+ Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix
187
+ @since v2.0
188
+ */
189
+ #define CC_NODE_DRAW_SETUP() \
190
+ do { \
191
+ ccGLEnable( glServerState_ ); \
192
+ NSAssert1(shaderProgram_, @"No shader program set for node: %@", self); \
193
+ [shaderProgram_ use]; \
194
+ [shaderProgram_ setUniformForModelViewProjectionMatrix]; \
195
+ } while(0)
196
+
197
+
198
+ /** @def CC_DIRECTOR_END
199
+ Stops and removes the director from memory.
200
+ Removes the CCGLView from its parent
201
+
202
+ @since v0.99.4
203
+ */
204
+ #define CC_DIRECTOR_END() \
205
+ do { \
206
+ CCDirector *__director = [CCDirector sharedDirector]; \
207
+ [__director end]; \
208
+ } while(0)
209
+
210
+
211
+
212
+
213
+ #if __CC_PLATFORM_IOS
214
+
215
+ /****************************/
216
+ /** RETINA DISPLAY ENABLED **/
217
+ /****************************/
218
+
219
+ /** @def CC_CONTENT_SCALE_FACTOR
220
+ On Mac it returns 1;
221
+ On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1
222
+ */
223
+ extern float __ccContentScaleFactor;
224
+ #define CC_CONTENT_SCALE_FACTOR() __ccContentScaleFactor
225
+
226
+
227
+ /** @def CC_RECT_PIXELS_TO_POINTS
228
+ Converts a rect in pixels to points
229
+ */
230
+ #define CC_RECT_PIXELS_TO_POINTS(__rect_in_pixels__) \
231
+ CGRectMake( (__rect_in_pixels__).origin.x / CC_CONTENT_SCALE_FACTOR(), (__rect_in_pixels__).origin.y / CC_CONTENT_SCALE_FACTOR(), \
232
+ (__rect_in_pixels__).size.width / CC_CONTENT_SCALE_FACTOR(), (__rect_in_pixels__).size.height / CC_CONTENT_SCALE_FACTOR() )
233
+
234
+ /** @def CC_RECT_POINTS_TO_PIXELS
235
+ Converts a rect in points to pixels
236
+ */
237
+ #define CC_RECT_POINTS_TO_PIXELS(__rect_in_points_points__) \
238
+ CGRectMake( (__rect_in_points_points__).origin.x * CC_CONTENT_SCALE_FACTOR(), (__rect_in_points_points__).origin.y * CC_CONTENT_SCALE_FACTOR(), \
239
+ (__rect_in_points_points__).size.width * CC_CONTENT_SCALE_FACTOR(), (__rect_in_points_points__).size.height * CC_CONTENT_SCALE_FACTOR() )
240
+
241
+ /** @def CC_POINT_PIXELS_TO_POINTS
242
+ Converts a rect in pixels to points
243
+ */
244
+ #define CC_POINT_PIXELS_TO_POINTS(__pixels__) \
245
+ CGPointMake( (__pixels__).x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).y / CC_CONTENT_SCALE_FACTOR())
246
+
247
+ /** @def CC_POINT_POINTS_TO_PIXELS
248
+ Converts a rect in points to pixels
249
+ */
250
+ #define CC_POINT_POINTS_TO_PIXELS(__points__) \
251
+ CGPointMake( (__points__).x * CC_CONTENT_SCALE_FACTOR(), (__points__).y * CC_CONTENT_SCALE_FACTOR())
252
+
253
+ /** @def CC_POINT_PIXELS_TO_POINTS
254
+ Converts a rect in pixels to points
255
+ */
256
+ #define CC_SIZE_PIXELS_TO_POINTS(__size_in_pixels__) \
257
+ CGSizeMake( (__size_in_pixels__).width / CC_CONTENT_SCALE_FACTOR(), (__size_in_pixels__).height / CC_CONTENT_SCALE_FACTOR())
258
+
259
+ /** @def CC_POINT_POINTS_TO_PIXELS
260
+ Converts a rect in points to pixels
261
+ */
262
+ #define CC_SIZE_POINTS_TO_PIXELS(__size_in_points__) \
263
+ CGSizeMake( (__size_in_points__).width * CC_CONTENT_SCALE_FACTOR(), (__size_in_points__).height * CC_CONTENT_SCALE_FACTOR())
264
+
265
+
266
+ #elif defined(__CC_PLATFORM_MAC)
267
+
268
+ /*****************************/
269
+ /** RETINA DISPLAY DISABLED **/
270
+ /*****************************/
271
+
272
+ #define CC_CONTENT_SCALE_FACTOR() 1
273
+ #define CC_RECT_PIXELS_TO_POINTS(__pixels__) __pixels__
274
+ #define CC_RECT_POINTS_TO_PIXELS(__points__) __points__
275
+ #define CC_SIZE_PIXELS_TO_POINTS(__pixels__) __pixels__
276
+ #define CC_SIZE_POINTS_TO_PIXELS(__points__) __points__
277
+ #define CC_POINT_PIXELS_TO_POINTS(__pixels__) __pixels__
278
+ #define CC_POINT_POINTS_TO_PIXELS(__points__) __points__
279
+
280
+
281
+ #endif // __CC_PLATFORM_MAC
282
+
283
+
284
+ /**********************/
285
+ /** Profiling Macros **/
286
+ /**********************/
287
+ #if CC_ENABLE_PROFILERS
288
+
289
+ #define CC_PROFILER_DISPLAY_TIMERS() [[CCProfiler sharedProfiler] displayTimers]
290
+ #define CC_PROFILER_PURGE_ALL() [[CCProfiler sharedProfiler] releaseAllTimers]
291
+
292
+ #define CC_PROFILER_START(__name__) CCProfilingBeginTimingBlock(__name__)
293
+ #define CC_PROFILER_STOP(__name__) CCProfilingEndTimingBlock(__name__)
294
+ #define CC_PROFILER_RESET(__name__) CCProfilingResetTimingBlock(__name__)
295
+
296
+ #define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingBeginTimingBlock(__name__); } while(0)
297
+ #define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingEndTimingBlock(__name__); } while(0)
298
+ #define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingResetTimingBlock(__name__); } while(0)
299
+
300
+ #define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ CCProfilingBeginTimingBlock( [NSString stringWithFormat:@"%08X - %@", __id__, __name__] ); } while(0)
301
+ #define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ CCProfilingEndTimingBlock( [NSString stringWithFormat:@"%08X - %@", __id__, __name__] ); } while(0)
302
+ #define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ CCProfilingResetTimingBlock( [NSString stringWithFormat:@"%08X - %@", __id__, __name__] ); } while(0)
303
+
304
+
305
+ #else
306
+
307
+ #define CC_PROFILER_DISPLAY_TIMERS() do {} while (0)
308
+ #define CC_PROFILER_PURGE_ALL() do {} while (0)
309
+
310
+ #define CC_PROFILER_START(__name__) do {} while (0)
311
+ #define CC_PROFILER_STOP(__name__) do {} while (0)
312
+ #define CC_PROFILER_RESET(__name__) do {} while (0)
313
+
314
+ #define CC_PROFILER_START_CATEGORY(__cat__, __name__) do {} while(0)
315
+ #define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do {} while(0)
316
+ #define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do {} while(0)
317
+
318
+ #define CC_PROFILER_START_INSTANCE(__id__, __name__) do {} while(0)
319
+ #define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do {} while(0)
320
+ #define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do {} while(0)
321
+
322
+ #endif
323
+
324
+ /*****************/
325
+ /** ARC Macros **/
326
+ /*****************/
327
+ #if defined(__has_feature) && __has_feature(objc_arc)
328
+ // ARC (used for inline functions)
329
+ #define CC_ARC_RETAIN(value) value
330
+ #define CC_ARC_RELEASE(value) value = 0
331
+ #define CC_ARC_UNSAFE_RETAINED __unsafe_unretained
332
+
333
+ #else
334
+ // No ARC
335
+ #define CC_ARC_RETAIN(value) [value retain]
336
+ #define CC_ARC_RELEASE(value) [value release]
337
+ #define CC_ARC_UNSAFE_RETAINED
338
+ #endif
339
+
340
+ /** @def CC_INCREMENT_GL_DRAWS_BY_ONE
341
+ Increments the GL Draws counts by one.
342
+ The number of calls per frame are displayed on the screen when the CCDirector's stats are enabled.
343
+ */
344
+ extern NSUInteger __ccNumberOfDraws;
345
+ #define CC_INCREMENT_GL_DRAWS(__n__) __ccNumberOfDraws += __n__
346
+
347
+ /*******************/
348
+ /** Notifications **/
349
+ /*******************/
350
+ /** @def CCAnimationFrameDisplayedNotification
351
+ Notification name when a CCSpriteFrame is displayed
352
+ */
353
+ #define CCAnimationFrameDisplayedNotification @"CCAnimationFrameDisplayedNotification"