cocos2d for iPhone 1.0.0
2D engine for iOS and OS X
/Users/rquesada/progs/cocos2d-iphone/cocos2d/ccMacros.h
Go to the documentation of this file.
00001 /*
00002  * cocos2d for iPhone: http://www.cocos2d-iphone.org
00003  *
00004  * Copyright (c) 2008-2010 Ricardo Quesada
00005  * Copyright (c) 2011 Zynga Inc.
00006  * 
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to deal
00009  * in the Software without restriction, including without limitation the rights
00010  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  * 
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023  * THE SOFTWARE.
00024  */
00025 
00026 
00027 #import <math.h>
00028 #import "ccConfig.h"
00029 
00030 #import <Foundation/Foundation.h>
00031 #import <Availability.h>
00032 
00038 /*
00039  * if COCOS2D_DEBUG is not defined, or if it is 0 then
00040  *      all CCLOGXXX macros will be disabled
00041  *
00042  * if COCOS2D_DEBUG==1 then:
00043  *              CCLOG() will be enabled
00044  *              CCLOGERROR() will be enabled
00045  *              CCLOGINFO()     will be disabled
00046  *
00047  * if COCOS2D_DEBUG==2 or higher then:
00048  *              CCLOG() will be enabled
00049  *              CCLOGERROR() will be enabled
00050  *              CCLOGINFO()     will be enabled 
00051  */
00052 #if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
00053 #define CCLOG(...) do {} while (0)
00054 #define CCLOGINFO(...) do {} while (0)
00055 #define CCLOGERROR(...) do {} while (0)
00056 
00057 #elif COCOS2D_DEBUG == 1
00058 #define CCLOG(...) NSLog(__VA_ARGS__)
00059 #define CCLOGERROR(...) NSLog(__VA_ARGS__)
00060 #define CCLOGINFO(...) do {} while (0)
00061 
00062 #elif COCOS2D_DEBUG > 1
00063 #define CCLOG(...) NSLog(__VA_ARGS__)
00064 #define CCLOGERROR(...) NSLog(__VA_ARGS__)
00065 #define CCLOGINFO(...) NSLog(__VA_ARGS__)
00066 #endif // COCOS2D_DEBUG
00067 
00071 #define CC_SWAP( x, y )                 \
00072 ({ __typeof__(x) temp  = (x);           \
00073                 x = y; y = temp;                \
00074 })
00075 
00076 
00080 #define CCRANDOM_MINUS1_1() ((random() / (float)0x3fffffff )-1.0f)
00081 
00085 #define CCRANDOM_0_1() ((random() / (float)0x7fffffff ))
00086 
00090 #define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180
00091 
00095 #define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180
00096 
00100 #if CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
00101 #define CC_BLEND_SRC GL_ONE
00102 #define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
00103 #else
00104 #define CC_BLEND_SRC GL_SRC_ALPHA
00105 #define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
00106 #endif // ! CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
00107 
00115 #define CC_ENABLE_DEFAULT_GL_STATES() {                         \
00116         glEnableClientState(GL_VERTEX_ARRAY);                   \
00117         glEnableClientState(GL_COLOR_ARRAY);                    \
00118         glEnableClientState(GL_TEXTURE_COORD_ARRAY);    \
00119         glEnable(GL_TEXTURE_2D);                                                \
00120 }
00121 
00129 #define CC_DISABLE_DEFAULT_GL_STATES() {                        \
00130         glDisable(GL_TEXTURE_2D);                                               \
00131         glDisableClientState(GL_TEXTURE_COORD_ARRAY);   \
00132         glDisableClientState(GL_COLOR_ARRAY);                   \
00133         glDisableClientState(GL_VERTEX_ARRAY);                  \
00134 }
00135 
00154 #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
00155 
00156 #define CC_DIRECTOR_INIT()                                                                                                                                              \
00157 do      {                                                                                                                                                                                       \
00158         window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];                                       \
00159         if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )                                                         \
00160                 [CCDirector setDirectorType:kCCDirectorTypeNSTimer];                                                                    \
00161         CCDirector *__director = [CCDirector sharedDirector];                                                                           \
00162         [__director setDeviceOrientation:kCCDeviceOrientationPortrait];                                                         \
00163         [__director setDisplayFPS:NO];                                                                                                                          \
00164         [__director setAnimationInterval:1.0/60];                                                                                                       \
00165         EAGLView *__glView = [EAGLView viewWithFrame:[window bounds]                                                            \
00166                                                                         pixelFormat:kEAGLColorFormatRGB565                                                      \
00167                                                                         depthFormat:0 /* GL_DEPTH_COMPONENT24_OES */                            \
00168                                                          preserveBackbuffer:NO                                                                                          \
00169                                                                          sharegroup:nil                                                                                         \
00170                                                                   multiSampling:NO                                                                                              \
00171                                                                 numberOfSamples:0                                                                                               \
00172                                                                                                         ];                                                                                      \
00173         [__director setOpenGLView:__glView];                                                                                                            \
00174         [window addSubview:__glView];                                                                                                                           \
00175         [window makeKeyAndVisible];                                                                                                                                     \
00176 } while(0)
00177 
00178 
00179 #elif __MAC_OS_X_VERSION_MAX_ALLOWED
00180 
00181 #import "Platforms/Mac/MacWindow.h"
00182 
00183 #define CC_DIRECTOR_INIT(__WINSIZE__)                                                                                                                   \
00184 do      {                                                                                                                                                                                       \
00185         NSRect frameRect = NSMakeRect(0, 0, (__WINSIZE__).width, (__WINSIZE__).height);                         \
00186         self.window = [[MacWindow alloc] initWithFrame:frameRect fullscreen:NO];                                        \
00187         self.glView = [[MacGLView alloc] initWithFrame:frameRect shareContext:nil];                                     \
00188         [self.window setContentView:self.glView];                                                                                                       \
00189         CCDirector *__director = [CCDirector sharedDirector];                                                                           \
00190         [__director setDisplayFPS:NO];                                                                                                                          \
00191         [__director setOpenGLView:self.glView];                                                                                                         \
00192         [(CCDirectorMac*)__director setOriginalWinSize:__WINSIZE__];                                                            \
00193         [self.window makeMainWindow];                                                                                                                           \
00194         [self.window makeKeyAndOrderFront:self];                                                                                                        \
00195 } while(0)
00196 
00197 #endif
00198 
00199  
00206 #define CC_DIRECTOR_END()                                                                               \
00207 do {                                                                                                                    \
00208         CCDirector *__director = [CCDirector sharedDirector];           \
00209         CC_GLVIEW *__view = [__director openGLView];                            \
00210         [__view removeFromSuperview];                                                           \
00211         [__director end];                                                                                       \
00212 } while(0)
00213 
00214 
00215 #if CC_IS_RETINA_DISPLAY_SUPPORTED
00216 
00217 /****************************/
00219 /****************************/
00220 
00225 #import "Platforms/iOS/CCDirectorIOS.h"
00226 #define CC_CONTENT_SCALE_FACTOR() __ccContentScaleFactor
00227 
00228 
00232 #define CC_RECT_PIXELS_TO_POINTS(__pixels__)                                                                                                                                            \
00233         CGRectMake( (__pixels__).origin.x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).origin.y / CC_CONTENT_SCALE_FACTOR(),       \
00234                         (__pixels__).size.width / CC_CONTENT_SCALE_FACTOR(), (__pixels__).size.height / CC_CONTENT_SCALE_FACTOR() )
00235 
00239 #define CC_RECT_POINTS_TO_PIXELS(__points__)                                                                                                                                            \
00240         CGRectMake( (__points__).origin.x * CC_CONTENT_SCALE_FACTOR(), (__points__).origin.y * CC_CONTENT_SCALE_FACTOR(),       \
00241                         (__points__).size.width * CC_CONTENT_SCALE_FACTOR(), (__points__).size.height * CC_CONTENT_SCALE_FACTOR() )
00242 
00243 #else // retina disabled
00244 
00245 /*****************************/
00247 /*****************************/
00248 
00249 #define CC_CONTENT_SCALE_FACTOR() 1
00250 #define CC_RECT_PIXELS_TO_POINTS(__pixels__) __pixels__
00251 #define CC_RECT_POINTS_TO_PIXELS(__points__) __points__
00252 
00253 #endif // CC_IS_RETINA_DISPLAY_SUPPORTED
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

cocos2d for iPhone API Reference - Generated using Doxygen 1.7.4