/
ccMacros.h
75 lines (58 loc) · 1.98 KB
/
ccMacros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* cocos2d for iPhone
*
* http://www.cocos2d-iphone.org
*
* Copyright (C) 2008,2009,2010 Ricardo Quesada
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
*
* You will find a copy of this license within the cocos2d for iPhone
* distribution inside the "LICENSE" file.
*
*/
#import <math.h>
/**
@file
cocos2d helper macros
*/
#if COCOS2D_DEBUG
//#define CCLOG(s, …) NSLog((@”%s %s:%d ” s), __func__, basename(__FILE__), __LINE__, ## __VA_ARGS__);
#define CCLOG(...) NSLog(__VA_ARGS__)
#else
#define CCLOG(...) do {} while (0)
#endif
//simple macro that swaps 2 variables
#define CC_SWAP( x, y ) \
({ __typeof__(x) temp = (x); \
x = y; y = temp; \
})
/// returns a random float between -1 and 1
#define CCRANDOM_MINUS1_1() ((random() / (float)0x3fffffff )-1.0f)
/// returns a random float between 0 and 1
#define CCRANDOM_0_1() ((random() / (float)0x7fffffff ))
/// converts degrees to radians
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0f * (float)M_PI)
/// converts radians to degrees
#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) / (float)M_PI * 180.0f)
/// default gl blend src function
//#define CC_BLEND_SRC GL_SRC_ALPHA
#define CC_BLEND_SRC GL_ONE
/// default gl blend dst function
#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
/// GL states that are enabled: GL_TEXTURE_2D
/// GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
#define CC_ENABLE_DEFAULT_GL_STATES() { \
glEnableClientState(GL_VERTEX_ARRAY); \
glEnableClientState(GL_COLOR_ARRAY); \
glEnableClientState(GL_TEXTURE_COORD_ARRAY); \
glEnable(GL_TEXTURE_2D); \
}
/// Disable default GL states: GL_TEXTURE_2D,
/// GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
#define CC_DISABLE_DEFAULT_GL_STATES() { \
glDisable(GL_TEXTURE_2D); \
glDisableClientState(GL_COLOR_ARRAY); \
glDisableClientState(GL_TEXTURE_COORD_ARRAY); \
glDisableClientState(GL_VERTEX_ARRAY); \
}