Merge pull request #382 from minggo/master

upgrade to 1.0.0-final 07-11
This commit is contained in:
minggo 2011-07-11 20:25:17 -07:00
commit 933fa42a0a
18 changed files with 160 additions and 53 deletions

View File

@ -41,6 +41,7 @@ CCAtlasNode::CCAtlasNode()
, m_pTextureAtlas(NULL)
, m_bIsOpacityModifyRGB(false)
, m_cOpacity(0)
, m_uQuadsToDraw(0)
{
}
@ -93,6 +94,8 @@ bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, uns
this->calculateMaxItems();
m_uQuadsToDraw = itemsToRender;
return true;
}
@ -115,6 +118,8 @@ void CCAtlasNode::updateAtlasValues()
// CCAtlasNode - draw
void CCAtlasNode::draw()
{
CCNode::draw();
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
// Unneeded states: GL_COLOR_ARRAY
@ -129,7 +134,7 @@ void CCAtlasNode::draw()
glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
}
m_pTextureAtlas->drawQuads();
m_pTextureAtlas->drawNumberOfQuads(m_uQuadsToDraw, 0);
if( newBlend )
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
@ -241,4 +246,14 @@ CCTextureAtlas * CCAtlasNode::getTextureAtlas()
return m_pTextureAtlas;
}
unsigned int CCAtlasNode::getQuadsToDraw()
{
return m_uQuadsToDraw;
}
void CCAtlasNode::setQuadsToDraw(unsigned int uQuadsToDraw)
{
m_uQuadsToDraw = uQuadsToDraw;
}
} // namespace cocos2d

View File

@ -67,6 +67,9 @@ protected:
CC_PROPERTY(GLubyte, m_cOpacity, Opacity);
CC_PROPERTY(ccColor3B, m_tColor, Color);
// quads to draw
CC_PROPERTY(unsigned int, m_uQuadsToDraw, QuadsToDraw);
public:
CCAtlasNode();
virtual ~CCAtlasNode();

View File

@ -64,7 +64,9 @@ namespace cocos2d{
virtual void updateAtlasValues();
virtual void setString(const char *label);
virtual const char* getString(void);
virtual void draw();
#if CC_LABELATLAS_DEBUG_DRAW
virtual void draw();
#endif
virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; }
protected:

View File

@ -148,15 +148,15 @@ namespace cocos2d{
class CC_DLL CCMenuItemFont : public CCMenuItemLabel
{
public:
CCMenuItemFont(){}
CCMenuItemFont() : m_nFontSize(0), m_strFontName(""){}
virtual ~CCMenuItemFont(){}
/** set font size */
/** set default font size */
static void setFontSize(int s);
/** get font size */
/** get default font size */
static int fontSize();
/** set the font name */
/** set the default font name */
static void setFontName(const char *name);
/** get the font name */
/** get the default font name */
static const char *fontName();
/** creates a menu item from a string without target/selector. To be used with CCMenuItemToggle */
static CCMenuItemFont * itemFromString(const char *value);
@ -164,6 +164,29 @@ namespace cocos2d{
static CCMenuItemFont * itemFromString(const char *value, SelectorProtocol* target, SEL_MenuHandler selector);
/** initializes a menu item from a string with a target/selector */
bool initFromString(const char *value, SelectorProtocol* target, SEL_MenuHandler selector);
/** set font size
* c++ can not overload static and non-static member functions with the same parameter types
* so change the name to setFontSizeObj
*/
void setFontSizeObj(int s);
/** get font size */
int getFontSize();
/** set the font name
* c++ can not overload static and non-static member functions with the same parameter types
* so change the name to setFontNameObj
*/
void setFontNameObj(const char* name);
const char* getFontName();
protected:
void recreateLabel();
int m_nFontSize;
std::string m_strFontName;
};
/** @brief CCMenuItemSprite accepts CCNode<CCRGBAProtocol> objects as items.

View File

@ -49,7 +49,9 @@ To enabled set it to 1. Disabled by default.
@since v0.99.5
*/
#ifndef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 0
#endif
/** @def CC_FONT_LABEL_SUPPORT
If enabled, FontLabel will be used to render .ttf files.
@ -60,7 +62,9 @@ To enabled set it to 1. Disabled by default.
Only valid for cocos2d-ios. Not supported on cocos2d-mac
*/
#ifndef CC_FONT_LABEL_SUPPORT
#define CC_FONT_LABEL_SUPPORT 1
#endif
/** @def CC_DIRECTOR_FAST_FPS
If enabled, then the FPS will be drawn using CCLabelAtlas (fast rendering).
@ -69,7 +73,9 @@ To enabled set it to 1. Disabled by default.
To enable set it to a value different than 0. Enabled by default.
*/
#ifndef CC_DIRECTOR_FAST_FPS
#define CC_DIRECTOR_FAST_FPS 1
#endif
/** @def CC_DIRECTOR_FPS_INTERVAL
Senconds between FPS updates.
@ -78,7 +84,9 @@ To enabled set it to 1. Disabled by default.
Default value: 0.1f
*/
#define CC_DIRECTOR_FPS_INTERVAL (0.5f)
#ifndef CC_DIRECTOR_FPS_INTERVAL
#define CC_DIRECTOR_FPS_INTERVAL (0.1f)
#endif
/** @def CC_DIRECTOR_DISPATCH_FAST_EVENTS
If enabled, and only when it is used with CCFastDirector, the main loop will wait 0.04 seconds to
@ -90,7 +98,9 @@ To enabled set it to 1. Disabled by default.
@warning This feature is experimental
*/
#ifndef CC_DIRECTOR_DISPATCH_FAST_EVENTS
#define CC_DIRECTOR_DISPATCH_FAST_EVENTS 0
#endif
/** @def CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
If enabled, cocos2d-mac will run on the Display Link thread. If disabled cocos2d-mac will run in its own thread.
@ -103,7 +113,9 @@ To enable set it to a 1, to disable it set to 0. Enabled by default.
Only valid for cocos2d-mac. Not supported on cocos2d-ios.
*/
#ifndef CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
#define CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD 1
#endif
/** @def CC_COCOSNODE_RENDER_SUBPIXEL
If enabled, the CCNode objects (CCSprite, CCLabel,etc) will be able to render in subpixels.
@ -111,7 +123,9 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios.
To enable set it to 1. Enabled by default.
*/
#ifndef CC_COCOSNODE_RENDER_SUBPIXEL
#define CC_COCOSNODE_RENDER_SUBPIXEL 1
#endif
/** @def CC_SPRITEBATCHNODE_RENDER_SUBPIXEL
If enabled, the CCSprite objects rendered with CCSpriteBatchNode will be able to render in subpixels.
@ -119,7 +133,9 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios.
To enable set it to 1. Enabled by default.
*/
#ifndef CC_SPRITEBATCHNODE_RENDER_SUBPIXEL
#define CC_SPRITEBATCHNODE_RENDER_SUBPIXEL 1
#endif
/** @def CC_USES_VBO
If enabled, batch nodes (texture atlas and particle system) will use VBO instead of vertex list (VBO is recommended by Apple)
@ -130,11 +146,13 @@ Disabled by default on iPhone with ARMv6 processors.
@since v0.99.5
*/
#ifndef CC_USES_VBO
#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
#define CC_USES_VBO 0
#else
#define CC_USES_VBO 1
#endif
#endif
/** @def CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
If enabled, CCNode will transform the nodes using a cached Affine matrix.
@ -148,7 +166,9 @@ Disabled by default on iPhone with ARMv6 processors.
To enable set it to a value different than 0. Enabled by default.
*/
#ifndef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
#define CC_NODE_TRANSFORM_USING_AFFINE_MATRIX 1
#endif
/** @def CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
If most of your imamges have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images).
@ -158,7 +178,9 @@ To enable set it to a value different than 0. Enabled by default.
@since v0.99.5
*/
#ifndef CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
#define CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA 1
#endif
/** @def CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
Use GL_TRIANGLE_STRIP instead of GL_TRIANGLES when rendering the texture atlas.
@ -167,7 +189,9 @@ To enable set it to a value different than 0. Enabled by default.
To enable set it to a value different than 0. Disabled by default.
*/
#ifndef CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
#define CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP 0
#endif
/** @def CC_TEXTURE_NPOT_SUPPORT
If enabled, NPOT textures will be used where available. Only 3rd gen (and newer) devices support NPOT textures.
@ -184,7 +208,9 @@ To enable set it to a value different than 0. Enabled by default.
@since v0.99.2
*/
#ifndef CC_TEXTURE_NPOT_SUPPORT
#define CC_TEXTURE_NPOT_SUPPORT 0
#endif
/** @def CC_RETINA_DISPLAY_SUPPORT
If enabled, cocos2d supports retina display.
@ -199,7 +225,9 @@ This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loade
@since v0.99.5
*/
#ifndef CC_RETINA_DISPLAY_SUPPORT
#define CC_RETINA_DISPLAY_SUPPORT 1
#endif
/** @def CC_RETINA_DISPLAY_FILENAME_SUFFIX
It's the suffix that will be appended to the files in order to load "retina display" images.
@ -211,7 +239,9 @@ Platforms: Only used on Retina Display devices like iPhone 4.
@since v0.99.5
*/
#ifndef CC_RETINA_DISPLAY_FILENAME_SUFFIX
#define CC_RETINA_DISPLAY_FILENAME_SUFFIX "-hd"
#endif
/** @def CC_USE_LA88_LABELS_ON_NEON_ARCH
If enabled, it will use LA88 (16-bit textures) on Neon devices for CCLabelTTF objects.
@ -224,7 +254,9 @@ Platforms: Only used on ARM Neon architectures like iPhone 3GS or newer and iPad
@since v0.99.5
*/
#ifndef CC_USE_LA88_LABELS_ON_NEON_ARCH
#define CC_USE_LA88_LABELS_ON_NEON_ARCH 0
#endif
/** @def CC_SPRITE_DEBUG_DRAW
If enabled, all subclasses of CCSprite will draw a bounding box
@ -238,7 +270,9 @@ Platforms: Only used on ARM Neon architectures like iPhone 3GS or newer and iPad
1 -- draw bounding box
2 -- draw texture box
*/
#ifndef CC_SPRITE_DEBUG_DRAW
#define CC_SPRITE_DEBUG_DRAW 0
#endif
/** @def CC_SPRITEBATCHNODE_DEBUG_DRAW
If enabled, all subclasses of CCSprite that are rendered using an CCSpriteBatchNode draw a bounding box.
@ -246,7 +280,9 @@ Useful for debugging purposes only. It is recommened to leave it disabled.
To enable set it to a value different than 0. Disabled by default.
*/
#ifndef CC_SPRITEBATCHNODE_DEBUG_DRAW
#define CC_SPRITEBATCHNODE_DEBUG_DRAW 0
#endif
/** @def CC_LABELBMFONT_DEBUG_DRAW
If enabled, all subclasses of CCLabelBMFont will draw a bounding box
@ -254,7 +290,9 @@ Useful for debugging purposes only. It is recommened to leave it disabled.
To enable set it to a value different than 0. Disabled by default.
*/
#ifndef CC_LABELBMFONT_DEBUG_DRAW
#define CC_LABELBMFONT_DEBUG_DRAW 0
#endif
/** @def CC_LABELATLAS_DEBUG_DRAW
If enabled, all subclasses of LabeltAtlas will draw a bounding box
@ -262,7 +300,9 @@ To enable set it to a value different than 0. Disabled by default.
To enable set it to a value different than 0. Disabled by default.
*/
#ifndef CC_LABELATLAS_DEBUG_DRAW
#define CC_LABELATLAS_DEBUG_DRAW 0
#endif
/** @def CC_ENABLE_PROFILERS
If enabled, will activate various profilers withing cocos2d. This statistical data will be output to the console
@ -271,16 +311,9 @@ To enable set it to a value different than 0. Disabled by default.
To enable set it to a value different than 0. Disabled by default.
*/
#ifndef CC_ENABLE_PROFILERS
#define CC_ENABLE_PROFILERS 0
/** @def CC_COMPATIBILITY_WITH_0_8
Enable it if you want to support v0.8 compatbility.
Basically, classes without namespaces will work.
It is recommended to disable compatibility once you have migrated your game to v0.9 to avoid class name polution
To enable set it to a value different than 0. Disabled by default.
*/
#define CC_COMPATIBILITY_WITH_0_8 0
#endif
#if CC_RETINA_DISPLAY_SUPPORT
#define CC_IS_RETINA_DISPLAY_SUPPORTED 1

View File

@ -134,6 +134,8 @@ namespace cocos2d{
s.width = (float)(len * m_uItemWidth);
s.height = (float)(m_uItemHeight);
this->setContentSizeInPixels(s);
m_uQuadsToDraw = len;
}
const char* CCLabelAtlas::getString(void)
@ -143,46 +145,17 @@ namespace cocos2d{
//CCLabelAtlas - draw
// XXX: overriding draw from AtlasNode
#if CC_LABELATLAS_DEBUG_DRAW
void CCLabelAtlas::draw()
{
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
// Unneeded states: GL_COLOR_ARRAY
glDisableClientState(GL_COLOR_ARRAY);
CCAtlasNode::draw();
// glColor4ub isn't implement on some android devices
// glColor4ub( m_tColor.r, m_tColor.g, m_tColor.b, m_cOpacity);
glColor4f(((GLfloat)m_tColor.r) / 255, ((GLfloat)m_tColor.g) / 255, ((GLfloat)m_tColor.b) / 255, ((GLfloat)m_cOpacity) / 255);
bool newBlend = (m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST);
if(newBlend)
{
glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
}
m_pTextureAtlas->drawNumberOfQuads(m_sString.length(), 0);
if( newBlend )
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
// is this chepear than saving/restoring color state ?
// XXX: There is no need to restore the color to (255,255,255,255). Objects should use the color
// XXX: that they need
// glColor4ub( 255, 255, 255, 255);
// Restore Default GL state. Enable GL_COLOR_ARRAY
glEnableClientState(GL_COLOR_ARRAY);
#if CC_LABELATLAS_DEBUG_DRAW
CCSize s = this->getContentSize();
CCPoint vertices[4]={
ccp(0,0),ccp(s.width,0),
ccp(s.width,s.height),ccp(0,s.height),
};
ccDrawPoly(vertices, 4, true);
#endif // CC_LABELATLAS_DEBUG_DRAW
}
#endif
} // namespace cocos2d

View File

@ -437,7 +437,9 @@ void CCLayerColor::updateColor()
}
void CCLayerColor::draw()
{
{
CCLayer::draw();
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY, GL_COLOR_ARRAY
// Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY

View File

@ -111,6 +111,8 @@ void CCTransitionScene::sceneOrder()
void CCTransitionScene::draw()
{
CCScene::draw();
if( m_bIsInSceneOnTop ) {
m_pOutScene->visit();
m_pInScene->visit();

View File

@ -384,7 +384,7 @@ namespace cocos2d{
pChild->setPosition(ccp(x - winSize.width / 2,
y - pChild->getContentSize().height / 2));
x += w + 10;
x += w;
++columnsOccupied;
if (columnsOccupied >= rowColumns)

View File

@ -329,6 +329,10 @@ namespace cocos2d{
bool CCMenuItemFont::initFromString(const char *value, SelectorProtocol* target, SEL_MenuHandler selector)
{
CCAssert( value != NULL && strlen(value) != 0, "Value length must be greater than 0");
this->setFontName(_fontName.c_str());
this->setFontSize(_fontSize);
CCLabelTTF *label = CCLabelTTF::labelWithString(value, _fontName.c_str(), (float)_fontSize);
if (CCMenuItemLabel::initWithLabel(label, target, selector))
{
@ -336,6 +340,36 @@ namespace cocos2d{
}
return true;
}
void CCMenuItemFont::recreateLabel()
{
CCLabelTTF *label = CCLabelTTF::labelWithString(m_pLabel->convertToLabelProtocol()->getString(),
m_strFontName.c_str(), (float)m_nFontSize);
this->setLabel(label);
}
void CCMenuItemFont::setFontSizeObj(int s)
{
m_nFontSize = s;
recreateLabel();
}
int CCMenuItemFont::getFontSize()
{
return m_nFontSize;
}
void CCMenuItemFont::setFontNameObj(const char* name)
{
m_strFontName = name;
recreateLabel();
}
const char* CCMenuItemFont::getFontName()
{
return m_strFontName.c_str();
}
//
//CCMenuItemSprite
//

View File

@ -535,6 +535,8 @@ CCPoint CCProgressTimer::boundaryTexCoord(char index)
void CCProgressTimer::draw(void)
{
CCNode::draw();
if(! m_pVertexData)
{
return;

View File

@ -255,6 +255,8 @@ void CCRibbon::addPointAt(CCPoint location, float width)
void CCRibbon::draw()
{
CCNode::draw();
if (m_pSegments->count() > 0)
{
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY

View File

@ -94,6 +94,8 @@ void CCParticleSystemPoint::postStep()
}
void CCParticleSystemPoint::draw()
{
CCParticleSystem::draw();
if (m_uParticleIdx==0)
{
return;

View File

@ -272,7 +272,8 @@ void CCParticleSystemQuad::postStep()
// overriding draw method
void CCParticleSystemQuad::draw()
{
{ CCParticleSystem::draw();
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Unneeded states: -

View File

@ -84,6 +84,12 @@
if (multiSampling_)
{
if ( msaaColorbuffer_)
{
glDeleteRenderbuffersOES(1, &msaaColorbuffer_);
msaaColorbuffer_ = 0;
}
/* Create the offscreen MSAA color buffer.
After rendering, the contents of this will be blitted into ColorRenderbuffer */

View File

@ -657,6 +657,8 @@ void CCSprite::getTransformValues(struct transformValues_ *tv)
void CCSprite::draw(void)
{
CCNode::draw();
assert(! m_bUsesBatchNode);
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY

View File

@ -280,6 +280,8 @@ namespace cocos2d
// draw
void CCSpriteBatchNode::draw(void)
{
CCNode::draw();
// Optimization: Fast Dispatch
if (m_pobTextureAtlas->getTotalQuads() == 0)
{

View File

@ -50,7 +50,10 @@ MenuLayer1::MenuLayer1()
item3->setColor( ccc3(200,200,255) );
// Font Item
CCMenuItem *item4 = CCMenuItemFont::itemFromString("I toggle enable items", this, menu_selector(MenuLayer1::menuCallbackEnable) );
CCMenuItemFont *item4 = CCMenuItemFont::itemFromString("I toggle enable items", this, menu_selector(MenuLayer1::menuCallbackEnable) );
item4->setFontSizeObj(20);
item4->setFontName("Marker Felt");
// Label Item (CCLabelBMFont)
CCLabelBMFont* label = CCLabelBMFont::labelWithString("configuration", "fonts/bitmapFontTest3.fnt");