cocos2d游戏源码-x源码哪个好

Lines-master
AppController.mm
RootViewController.mm
base_nodes
draw_nodes
CMakeLists.txt
keypad_dispatcher
label_nodes
layers_scenes_transitions_nodes
menu_nodes
misc_nodes
particle_nodes
Simulation
AccelerometerDelegateWrapper.mm
CCAccelerometer.mm
CCApplication.mm
CCCommon.mm
CCDirectorCaller.mm
CCEGLView.mm
CCFileUtils.mm
CCImage.mm
CCThread.mm
EAGLView.mm
third_party
script_support
sprite_nodes
data_support
image_support
zip_support
text_input_node
tilemap_parallax_nodes
touch_dispatcher
CocosDenshion
SimpleAudioEngine.mm
extensions
CCControlExtension
CCEditBoxImplIOS.mm
CCEditBoxImplMac.mm
CCScrollView
LocalStorage
physics_nodes
proj.marmalade
cocos2dx-ext.mkf
cocos2dx-ext_public.defines.txt
LinesClasses
LinesImageResource
background.png
boardtest.png
chess0.png
chess1.png
chess2.png
chess3.png
chess4.png
chess5.png
chess6.png
CloseNormal.png
CloseSelected.png
Default.png
HelloWorld.png
Icon-72.png
Icon-Small-50.png
Icon-Small.png
Icon-Small@2x.png
Icon@2x.png
Info.plist
iTunesArtwork
Prefix.pch
Lines.xcodeproj
project.xcworkspace
xcuserdata
MySystem.xcuserdatad
UserInterfaceState.xcuserstate
contents.xcworkspacedata
xcuserdata
MySystem.xcuserdatad
xcdebugger
Breakpoints.xcbkptlist
Lines.xcscheme
xcschememanagement.plist
project.pbxproj
Default-568h@2x.png
/****************************************************************************
Copyright (c)
cocos2d-x.org
Copyright (c) 2009
Sindesso Pty Ltd /
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the &Software&), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED &AS IS&, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include &CCActionPageTurn3D.h&
#include &cocoa/CCZone.h&
#include &support/CCPointExtension.h&
NS_CC_BEGIN
CCPageTurn3D* CCPageTurn3D::create(float duration, const CCSize& gridSize)
CCPageTurn3D *pAction = new CCPageTurn3D();
if (pAction)
if (pAction-&initWithDuration(duration, gridSize))
pAction-&autorelease();
CC_SAFE_RELEASE_NULL(pAction);
* Update each tick
* Time is the percentage of the way through the duration
void CCPageTurn3D::update(float time)
float tt = MAX(0, time - 0.25f);
float deltaAy = (tt * tt * 500);
float ay = -100 - deltaAy;
float deltaTheta = - (float) M_PI_2 * sqrtf( time) ;
float theta = /*0.01f */ + (float) M_PI_2 +deltaT
float sinTheta = sinf(theta);
float cosTheta = cosf(theta);
for (int i = 0; i &= m_sGridSize. ++i)
for (int j = 0; j &= m_sGridSize. ++j)
// Get original vertex
ccVertex3F p = originalVertex(ccp(i ,j));
float R = sqrtf((p.x * p.x) + ((p.y - ay) * (p.y - ay)));
float r = R * sinT
float alpha = asinf( p.x / R );
float beta = alpha / sinT
float cosBeta = cosf( beta );
// If beta & PI then we've wrapped around the cone
// Reduce the radius to stop these points interfering with others
if (beta &= M_PI)
p.x = ( r * sinf(beta));
// Force X = 0 to stop wrapped
p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta));
// We scale z here to avoid the animation being
// too much bigger than the screen due to perspective transform
p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7;// &100& didn't work for
Stop z coord from dropping beneath underlying page in a transition
// issue #751
if( p.z & 0.5f )
p.z = 0.5f;
// Set new coords
setVertex(ccp(i, j), p);
Copyright(C)
OKBASE.NET All Rights Reserved 好库网 版权所有font_1002@2x.png
font_1003@2x.png
font_x.png
font_1004@2x.png
font_1014 @2x.png
font_1014@2x.png
loading@2x.png
pipei@2x.png
font_1002.spr
font_1003.spr
font_1004.spr
font_1014.spr
loading.spr
button_1001@2x.png
button_1002@2x.png
button_1007@2x.png
button_1008@2x.png
button_1009@2x.png
button_1010@2x.png
button_1011@2x.png
button_1012@2x.png
button_1013@2x.png
button_1014@2x.png
button_1017@2x.png
button_1019@2x.png
button_1020@2x.png
button_1044@2x.png
font_1011@2x.png
icon_1007@2x.png
icon_1009@2x.png
icon_1011@2x.png
icon_1013@2x.png
icon_1015@2x.png
icon_1027@2x.png
icon_1028@2x.png
icon_1029@2x.png
icon_1030@2x.png
icon_1031@2x.png
icon_1032@2x.png
icon_1048@2x.png
panle_@2x.png
panle_x.png
panle_@2x.png
panle_x.png
panle_@2x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_@2x.png
panle_x.png
panle_x.png
panle_1033@2x.png
panle_@2x.png
panle_1035@2x.png
panle_1038@2x.png
panle_x.png
panle_1040@2x.png
panle_x.png
panle_1044@2x.png
panle_1046@2x.png
panle_1047@2x.png
panle_@2x.png
panle_1049@2x.png
card_1061@2x.png
card_1062@2x.png
card_1063@2x.png
card_1064@2x.png
card_1065@2x.png
card_1066@2x.png
card_1067@2x.png
card_1068@2x.png
card_1069@2x.png
card_1070@2x.png
card_1071@2x.png
card_1072@2x.png
card_1073@2x.png
card_1074@2x.png
card_1075@2x.png
card_1076@2x.png
card_1077@2x.png
card_1078@2x.png
card_1079@2x.png
card_1080@2x.png
card_1081@2x.png
card_1082@2x.png
card_1083@2x.png
card_1084@2x.png
card_1085@2x.png
card_1086@2x.png
card_1087@2x.png
card_1088@2x.png
card_1089@2x.png
card_1090@2x.png
card_1091@2x.png
card_1092@2x.png
card_1093@2x.png
card_1094@2x.png
card_1095@2x.png
card_1096@2x.png
card_1097@2x.png
card_1098@2x.png
card_1099@2x.png
card_1100@2x.png
card_1101@2x.png
card_1102@2x.png
card_1103@2x.png
card_1104@2x.png
card_1105@2x.png
card_1106@2x.png
card_1107@2x.png
card_1108@2x.png
card_1109@2x.png
card_1110@2x.png
card_1111@2x.png
card_1112@2x.png
card_1113@2x.png
card_1114@2x.png
icon_1024@2x.png
panle_1045@2x.png
icon_1034@2x.png
icon_x.png
icon_1035@2x.png
icon_x.png
icon_1036@2x.png
icon_x.png
icon_1037@2x.png
icon_x.png
icon_1038@2x.png
icon_x.png
icon_1039@2x.png
icon_x.png
icon_1040@2x.png
icon_x.png
icon_1041@2x.png
icon_x.png
icon_1042@2x.png
icon_x.png
icon_1043@2x.png
icon_x.png
icon_1044@2x.png
icon_x.png
icon_1045@2x.png
icon_x.png
icon_1046@2x.png
icon_x.png
icon_1047@2x.png
icon_x.png
beijing@2x.jpg
beijing_1@2x.jpg
black@2x.png
bottom_x.png
button_1001@2x.png
button_1002@2x.png
button_1015@2x.png
button_1016@2x.png
button_1043@2x.png
card_1055@2x.png
font_1001@2x.png
font_1002@2x.png
font_1003@2x.png
font_1007@2x.png
font_1008@2x.png
font_1009@2x.png
font_1010@2x.png
font_1015@2x.png
ground_x.png
icon_1021@2x.png
icon_1022@2x.png
icon_1023@2x.png
icon_1024@2x.png
icon_1025@2x.png
icon_1026@2x.png
icon_1031@2x.png
icon_1033@2x.png
list_@2x.png
list_x.png
list_1017@2x.png
list_x.png
list_@2x.png
list_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_@2x.png
panel_x.png
panel_x.png
panel_@2x.png
panel_@2x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_1006@2x.png
panel_1007@2x.png
panel_x.png
panel_@2x.png
panle_@2x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_1022@2x.png
panle_1023@2x.png
panle_1024@2x.png
panle_1025@2x.png
panle_@2x.png
panle_x.png
panle_@2x.png
panle_1042@2x.png
panle_1043@2x.png
panle_1049@2x.png
panle_1051@2x.png
panle_1052@2x.png
panle_1067@2x.png
panle_x.png
panle_1069@2x.png
panle_x.png
panle_1071@2x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_1072@2x.png
panle_1073@2x.png
panle_1074@2x.png
panle_1075@2x.png
panle_1076@2x.png
tou_ming.9@2x.png
main_1041@2x.png
xuanyuan@2x.jpg
head_1001@2x.png
head_1002@2x.png
head_1003@2x.png
head_1004@2x.png
head_1005@2x.png
head_1006@2x.png
head_1007@2x.png
head_1008@2x.png
head_1009@2x.png
head_1010@2x.png
head_1011@2x.png
head_1012@2x.png
head_1013@2x.png
head_1014@2x.png
head_1015@2x.png
head_1016@2x.png
head_1017@2x.png
head_1018@2x.png
head_1019@2x.png
head_1020@2x.png
head_1021@2x.png
head_1022@2x.png
head_1023@2x.png
head_1024@2x.png
head_1025@2x.png
head_1026@2x.png
head_1027@2x.png
head_1028@2x.png
head_1029@2x.png
default@2x.jpg
logo1@2x.png
logo2@2x.png
logo@2x.png
worlBg@2x.jpg
imageupdate
backprogress@2x.png
default-568h@2x.jpg
default-Portrait@2x.jpg
default@2x.jpg
list_1116@2x.png
list_1172@2x.png
list_x.png
panel_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
backgroundmusic.mp3
button.mp3
dawang.mp3
givecard.mp3
liandui.mp3
rechoose.mp3
sandaiyi.mp3
sandaiyidui.mp3
shunzi.mp3
sidaier.mp3
sidailiangdui.mp3
wangzha.mp3
xiaowang.mp3
yaobuqi.mp3
zhadan.mp3
tabNameImg
button_1022@2x.png
button_1023@2x.png
button_1028@2x.png
button_1029@2x.png
button_1003@2x.png
button_1004@2x.png
button_1005@2x.png
button_1006@2x.png
button_1007@2x.png
button_1008@2x.png
button_1009@2x.png
button_1024@2x.png
button_1025@2x.png
button_1027@2x.png
font_1013@2x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panel_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_x.png
panle_1031@2x.png
panle_1032@2x.png
panle_1036@2x.png
panle_1037@2x.png
panle_x.png
panle_1039@2x.png
panle_1041@2x.png
panle_1048@2x.png
panle_1050@2x.png
panle_1053@2x.png
panle_1054@2x.png
panle_1055@2x.png
panle_1056@2x.png
panle_1057@2x.png
panle_1058@2x.png
panle_1059@2x.png
panle_1060@2x.png
panle_1064@2x.png
panle_1065@2x.png
panle_1066@2x.png
glew32.dll
libcurl.dll
libtiff.dll
msvcp100.dll
msvcp100d.dll
msvcr100d.dll
pthreadVCE2.dll
分服与充值中心表结构.sql
创建游戏帐号.sql
创建游戏数据库.sql
游戏库创建一键运行.bat
用户中心表结构.sql
配置库初始数据.sql
importdb.sql
rundbcreate.sh
Appstore.cfg.xml
ConfigModel
GameServer.exe
GameServer.exe.config
ICSharpCode.SharpZipLib.dll
IronPython.dll
IronPython.Modules.dll
KopiLua.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.dll
Mono.Cecil.dll
MySql.Data.dll
Newtonsoft.Json.dll
NLog.config
protobuf-net.dll
ServiceStack.Interfaces.dll
ServiceStack.Redis.dll
ServiceStack.Text.dll
ZyGames.Framework.dll
ZyGames.Framework.Game.dll
ZyGames.Doudizhu
Appstore.cfg.xml
Properties
ConfigModel
GameServer.exe
GameServer.exe.config
GameServer.pdb
ICSharpCode.SharpZipLib.dll
IronPython.dll
IronPython.Modules.dll
KopiLua.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.dll
Mono.Cecil.dll
MySql.Data.dll
Newtonsoft.Json.dll
NLog.config
protobuf-net.dll
ScutSMS Readme.chm
ScutSMS.exe
ServiceStack.Interfaces.dll
ServiceStack.Redis.dll
ServiceStack.Text.dll
ZyGames.Doudizhu.csproj
ZyGames.Framework.dll
ZyGames.Framework.Game.dll
ZyGames.Framework.Game.pdb
ZyGames.Framework.Game.xml
ZyGames.Framework.XML
ZyGames.Doudizhu_2013.sln
readme.txt
using System.Collections.G
using System.L
using System.T
namespace ZyGames.Doudizhu.Model
public enum AchieveType
/// &summary&
/// 全部成就
/// &/summary&
QuanBu = 0,
/// &summary&
/// 社区成就
/// &/summary&
/// &summary&
/// 比赛成就
/// &/summary&
/// &summary&
/// 游戏成就
/// &/summary&
Copyright(C)
OKBASE.NET All Rights Reserved 好库网 版权所有Lines-master
AppController.mm
RootViewController.mm
base_nodes
draw_nodes
CMakeLists.txt
keypad_dispatcher
label_nodes
layers_scenes_transitions_nodes
menu_nodes
misc_nodes
particle_nodes
Simulation
AccelerometerDelegateWrapper.mm
CCAccelerometer.mm
CCApplication.mm
CCCommon.mm
CCDirectorCaller.mm
CCEGLView.mm
CCFileUtils.mm
CCImage.mm
CCThread.mm
EAGLView.mm
third_party
script_support
sprite_nodes
data_support
image_support
zip_support
text_input_node
tilemap_parallax_nodes
touch_dispatcher
CocosDenshion
SimpleAudioEngine.mm
extensions
CCControlExtension
CCEditBoxImplIOS.mm
CCEditBoxImplMac.mm
CCScrollView
LocalStorage
physics_nodes
proj.marmalade
cocos2dx-ext.mkf
cocos2dx-ext_public.defines.txt
LinesClasses
LinesImageResource
background.png
boardtest.png
chess0.png
chess1.png
chess2.png
chess3.png
chess4.png
chess5.png
chess6.png
CloseNormal.png
CloseSelected.png
Default.png
HelloWorld.png
Icon-72.png
Icon-Small-50.png
Icon-Small.png
Icon-Small@2x.png
Icon@2x.png
Info.plist
iTunesArtwork
Prefix.pch
Lines.xcodeproj
project.xcworkspace
xcuserdata
MySystem.xcuserdatad
UserInterfaceState.xcuserstate
contents.xcworkspacedata
xcuserdata
MySystem.xcuserdatad
xcdebugger
Breakpoints.xcbkptlist
Lines.xcscheme
xcschememanagement.plist
project.pbxproj
Default-568h@2x.png
/****************************************************************************
Copyright (c)
cocos2d-x.org
Copyright (c)
Ricardo Quesada
Copyright (c) 2011
Zynga Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the &Software&), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED &AS IS&, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
// cocos2d
#include &CCTextureAtlas.h&
#include &CCTextureCache.h&
#include &ccMacros.h&
#include &shaders/CCGLProgram.h&
#include &shaders/ccGLStateCache.h&
#include &support/CCNotificationCenter.h&
#include &CCEventType.h&
#include &CCGL.h&
// support
#include &CCTexture2D.h&
#include &cocoa/CCString.h&
#include &stdlib.h&
//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong
// implementation CCTextureAtlas
NS_CC_BEGIN
CCTextureAtlas::CCTextureAtlas()
:m_pIndices(NULL)
,m_bDirty(false)
,m_pTexture(NULL)
,m_pQuads(NULL)
CCTextureAtlas::~CCTextureAtlas()
CCLOGINFO(&cocos2d: CCTextureAtlas deallocing %p.&, this);
CC_SAFE_FREE(m_pQuads);
CC_SAFE_FREE(m_pIndices);
glDeleteBuffers(2, m_pBuffersVBO);
#if CC_TEXTURE_ATLAS_USE_VAO
glDeleteVertexArrays(1, &m_uVAOname);
CC_SAFE_RELEASE(m_pTexture);
CCNotificationCenter::sharedNotificationCenter()-&removeObserver(this, EVNET_COME_TO_FOREGROUND);
unsigned int CCTextureAtlas::getTotalQuads()
return m_uTotalQ
unsigned int CCTextureAtlas::getCapacity()
return m_uC
CCTexture2D* CCTextureAtlas::getTexture()
return m_pT
void CCTextureAtlas::setTexture(CCTexture2D * var)
CC_SAFE_RETAIN(var);
CC_SAFE_RELEASE(m_pTexture);
m_pTexture =
ccV3F_C4B_T2F_Quad* CCTextureAtlas::getQuads()
//if someone accesses the quads directly, presume that changes will be made
m_bDirty =
return m_pQ
void CCTextureAtlas::setQuads(ccV3F_C4B_T2F_Quad *var)
m_pQuads =
// TextureAtlas - alloc & init
CCTextureAtlas * CCTextureAtlas::create(const char* file, unsigned int capacity)
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
if(pTextureAtlas && pTextureAtlas-&initWithFile(file, capacity))
pTextureAtlas-&autorelease();
return pTextureA
CC_SAFE_DELETE(pTextureAtlas);
return NULL;
CCTextureAtlas * CCTextureAtlas::createWithTexture(CCTexture2D *texture, unsigned int capacity)
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
if (pTextureAtlas && pTextureAtlas-&initWithTexture(texture, capacity))
pTextureAtlas-&autorelease();
return pTextureA
CC_SAFE_DELETE(pTextureAtlas);
return NULL;
bool CCTextureAtlas::initWithFile(const char * file, unsigned int capacity)
// retained in property
CCTexture2D *texture = CCTextureCache::sharedTextureCache()-&addImage(file);
if (texture)
return initWithTexture(texture, capacity);
CCLOG(&cocos2d: Could not open file: %s&, file);
bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity)
CCAssert(texture != NULL, &texture should not be null&);
m_uCapacity =
m_uTotalQuads = 0;
// retained in property
this-&m_pTexture =
CC_SAFE_RETAIN(m_pTexture);
// Re-initialization is not allowed
CCAssert(m_pQuads == NULL && m_pIndices == NULL, &&);
m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) );
m_pIndices = (GLushort *)malloc( m_uCapacity * 6 * sizeof(GLushort) );
if( ! ( m_pQuads && m_pIndices) && m_uCapacity & 0)
//CCLOG(&cocos2d: CCTextureAtlas: not enough memory&);
CC_SAFE_FREE(m_pQuads);
CC_SAFE_FREE(m_pIndices);
// release texture, should set it to null, because the destruction will
// release it too. see cocos2d-x issue #484
CC_SAFE_RELEASE_NULL(m_pTexture);
memset( m_pQuads, 0, m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) );
memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) );
// listen the event when app go to background
CCNotificationCenter::sharedNotificationCenter()-&addObserver(this,
callfuncO_selector(CCTextureAtlas::listenBackToForeground),
EVNET_COME_TO_FOREGROUND,
this-&setupIndices();
#if CC_TEXTURE_ATLAS_USE_VAO
setupVBOandVAO();
setupVBO();
m_bDirty =
void CCTextureAtlas::listenBackToForeground(CCObject *obj)
#if CC_TEXTURE_ATLAS_USE_VAO
setupVBOandVAO();
setupVBO();
// set m_bDirty to true to force it rebinding buffer
m_bDirty =
const char* CCTextureAtlas::description()
return CCString::createWithFormat(&&CCTextureAtlas | totalQuads = %u&&, m_uTotalQuads)-&getCString();
void CCTextureAtlas::setupIndices()
if (m_uCapacity == 0)
for( unsigned int i=0; i & m_uC i++)
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
m_pIndices[i*6+0] = i*4+0;
m_pIndices[i*6+1] = i*4+0;
m_pIndices[i*6+2] = i*4+2;
m_pIndices[i*6+3] = i*4+1;
m_pIndices[i*6+4] = i*4+3;
m_pIndices[i*6+5] = i*4+3;
m_pIndices[i*6+0] = i*4+0;
m_pIndices[i*6+1] = i*4+1;
m_pIndices[i*6+2] = i*4+2;
// inverted index. issue #179
m_pIndices[i*6+3] = i*4+3;
m_pIndices[i*6+4] = i*4+2;
m_pIndices[i*6+5] = i*4+1;
//TextureAtlas - VAO / VBO specific
#if CC_TEXTURE_ATLAS_USE_VAO
void CCTextureAtlas::setupVBOandVAO()
glGenVertexArrays(1, &m_uVAOname);
ccGLBindVAO(m_uVAOname);
#define kQuadSize sizeof(m_pQuads[0].bl)
glGenBuffers(2, &m_pBuffersVBO[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0]) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW);
// vertices
glEnableVertexAttribArray(kCCVertexAttrib_Position);
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, vertices));
glEnableVertexAttribArray(kCCVertexAttrib_Color);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, colors));
// tex coords
glEnableVertexAttribArray(kCCVertexAttrib_TexCoords);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, texCoords));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW);
// Must unbind the VAO before changing the element buffer.
ccGLBindVAO(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CHECK_GL_ERROR_DEBUG();
#else // CC_TEXTURE_ATLAS_USE_VAO
void CCTextureAtlas::setupVBO()
glGenBuffers(2, &m_pBuffersVBO[0]);
mapBuffers();
#endif // ! // CC_TEXTURE_ATLAS_USE_VAO
void CCTextureAtlas::mapBuffers()
// Avoid changing the element buffer for whatever VAO might be bound.
ccGLBindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0]) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
CHECK_GL_ERROR_DEBUG();
// TextureAtlas - Update, Insert, Move & Remove
void CCTextureAtlas::updateQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index)
CCAssert( index &= 0 && index & m_uCapacity, &updateQuadWithTexture: Invalid index&);
m_uTotalQuads = MAX( index+1, m_uTotalQuads);
m_pQuads[index] = *
m_bDirty =
void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index)
CCAssert( index & m_uCapacity, &insertQuadWithTexture: Invalid index&);
m_uTotalQuads++;
CCAssert( m_uTotalQuads &= m_uCapacity, &invalid totalQuads&);
// issue #575. index can be & totalQuads
unsigned int remaining = (m_uTotalQuads-1) -
// last object doesn't need to be moved
if( remaining & 0)
// texture coordinates
memmove( &m_pQuads[index+1],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining );
m_pQuads[index] = *
m_bDirty =
void CCTextureAtlas::insertQuads(ccV3F_C4B_T2F_Quad* quads, unsigned int index, unsigned int amount)
CCAssert(index + amount &= m_uCapacity, &insertQuadWithTexture: Invalid index + amount&);
m_uTotalQuads +=
CCAssert( m_uTotalQuads &= m_uCapacity, &invalid totalQuads&);
// issue #575. index can be & totalQuads
int remaining = (m_uTotalQuads-1) - index -
// last object doesn't need to be moved
if( remaining & 0)
// tex coordinates
memmove( &m_pQuads[index+amount],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining );
unsigned int max = index +
unsigned int j = 0;
for (unsigned int i = i & i++)
m_pQuads[index] = quads[j];
m_bDirty =
void CCTextureAtlas::insertQuadFromIndex(unsigned int oldIndex, unsigned int newIndex)
CCAssert( newIndex &= 0 && newIndex & m_uTotalQuads, &insertQuadFromIndex:atIndex: Invalid index&);
CCAssert( oldIndex &= 0 && oldIndex & m_uTotalQuads, &insertQuadFromIndex:atIndex: Invalid index&);
if( oldIndex == newIndex )
// because it is ambiguous in iphone, so we implement abs ourselves
// unsigned int howMany = abs( oldIndex - newIndex);
unsigned int howMany = (oldIndex - newIndex) & 0 ? (oldIndex - newIndex) :
(newIndex - oldIndex);
unsigned int dst = oldI
unsigned int src = oldIndex + 1;
if( oldIndex & newIndex)
dst = newIndex+1;
src = newI
// texture coordinates
ccV3F_C4B_T2F_Quad quadsBackup = m_pQuads[oldIndex];
memmove( &m_pQuads[dst],&m_pQuads[src], sizeof(m_pQuads[0]) * howMany );
m_pQuads[newIndex] = quadsB
m_bDirty =
void CCTextureAtlas::removeQuadAtIndex(unsigned int index)
CCAssert( index & m_uTotalQuads, &removeQuadAtIndex: Invalid index&);
unsigned int remaining = (m_uTotalQuads-1) -
// last object doesn't need to be moved
if( remaining )
// texture coordinates
memmove( &m_pQuads[index],&m_pQuads[index+1], sizeof(m_pQuads[0]) * remaining );
m_uTotalQuads--;
m_bDirty =
void CCTextureAtlas::removeQuadsAtIndex(unsigned int index, unsigned int amount)
CCAssert(index + amount &= m_uTotalQuads, &removeQuadAtIndex: index + amount out of bounds&);
unsigned int remaining = (m_uTotalQuads) - (index + amount);
m_uTotalQuads -=
if ( remaining )
memmove( &m_pQuads[index], &m_pQuads[index+amount], sizeof(m_pQuads[0]) * remaining );
m_bDirty =
void CCTextureAtlas::removeAllQuads()
m_uTotalQuads = 0;
// TextureAtlas - Resize
bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity)
if( newCapacity == m_uCapacity )
unsigned int uOldCapactiy = m_uC
// update capacity and totolQuads
m_uTotalQuads = MIN(m_uTotalQuads, newCapacity);
m_uCapacity = newC
ccV3F_C4B_T2F_Quad* tmpQuads = NULL;
GLushort* tmpIndices = NULL;
// when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL,
// so here must judge whether m_pQuads and m_pIndices is NULL.
if (m_pQuads == NULL)
tmpQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(m_pQuads[0]) );
if (tmpQuads != NULL)
memset(tmpQuads, 0, m_uCapacity * sizeof(m_pQuads[0]) );
tmpQuads = (ccV3F_C4B_T2F_Quad*)realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity );
if (tmpQuads != NULL && m_uCapacity & uOldCapactiy)
memset(tmpQuads+uOldCapactiy, 0, (m_uCapacity - uOldCapactiy)*sizeof(m_pQuads[0]) );
if (m_pIndices == NULL)
tmpIndices = (GLushort*)malloc( m_uCapacity * 6 * sizeof(m_pIndices[0]) );
if (tmpIndices != NULL)
memset( tmpIndices, 0, m_uCapacity * 6 * sizeof(m_pIndices[0]) );
tmpIndices = (GLushort*)realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 );
if (tmpIndices != NULL && m_uCapacity & uOldCapactiy)
memset( tmpIndices+uOldCapactiy, 0, (m_uCapacity-uOldCapactiy) * 6 * sizeof(m_pIndices[0]) );
if( ! ( tmpQuads && tmpIndices) ) {
CCLOG(&cocos2d: CCTextureAtlas: not enough memory&);
CC_SAFE_FREE(tmpQuads);
CC_SAFE_FREE(tmpIndices);
CC_SAFE_FREE(m_pQuads);
CC_SAFE_FREE(m_pIndices);
m_uCapacity = m_uTotalQuads = 0;
m_pQuads = tmpQ
m_pIndices = tmpI
setupIndices();
mapBuffers();
m_bDirty =
void CCTextureAtlas::increaseTotalQuadsWith(unsigned int amount)
m_uTotalQuads +=
void CCTextureAtlas::moveQuadsFromIndex(unsigned int oldIndex, unsigned int amount, unsigned int newIndex)
CCAssert(newIndex + amount &= m_uTotalQuads, &insertQuadFromIndex:atIndex: Invalid index&);
CCAssert(oldIndex & m_uTotalQuads, &insertQuadFromIndex:atIndex: Invalid index&);
if( oldIndex == newIndex )
//create buffer
size_t quadSize = sizeof(ccV3F_C4B_T2F_Quad);
ccV3F_C4B_T2F_Quad* tempQuads = (ccV3F_C4B_T2F_Quad*)malloc( quadSize * amount);
memcpy( tempQuads, &m_pQuads[oldIndex], quadSize * amount );
if (newIndex & oldIndex)
// move quads from newIndex to newIndex + amount to make room for buffer
memmove( &m_pQuads[newIndex], &m_pQuads[newIndex+amount], (oldIndex-newIndex)*quadSize);
// move quads above back
memmove( &m_pQuads[oldIndex], &m_pQuads[oldIndex+amount], (newIndex-oldIndex)*quadSize);
memcpy( &m_pQuads[newIndex], tempQuads, amount*quadSize);
free(tempQuads);
m_bDirty =
void CCTextureAtlas::moveQuadsFromIndex(unsigned int index, unsigned int newIndex)
CCAssert(newIndex + (m_uTotalQuads - index) &= m_uCapacity, &moveQuadsFromIndex move is out of bounds&);
memmove(m_pQuads + newIndex,m_pQuads + index, (m_uTotalQuads - index) * sizeof(m_pQuads[0]));
void CCTextureAtlas::fillWithEmptyQuadsFromIndex(unsigned int index, unsigned int amount)
ccV3F_C4B_T2F_Q
memset(&quad, 0, sizeof(quad));
unsigned int to = index +
for (unsigned int i = i & i++)
m_pQuads[i] =
// TextureAtlas - Drawing
void CCTextureAtlas::drawQuads()
this-&drawNumberOfQuads(m_uTotalQuads, 0);
void CCTextureAtlas::drawNumberOfQuads(unsigned int n)
this-&drawNumberOfQuads(n, 0);
void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
if (0 == n)
ccGLBindTexture2D(m_pTexture-&getName());
#if CC_TEXTURE_ATLAS_USE_VAO
// Using VBO and VAO
// XXX: update is done in draw... perhaps it should be done in a timer
if (m_bDirty)
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
// option 1: subdata
//glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] );
// option 2: data
glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW);
// option 3: orphaning + glMapBuffer
glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0]) * (n-start), NULL, GL_DYNAMIC_DRAW);
void *buf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
memcpy(buf, m_pQuads, sizeof(m_pQuads[0])* (n-start));
glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0);
m_bDirty =
ccGLBindVAO(m_uVAOname);
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) );
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) );
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
#else // ! CC_TEXTURE_ATLAS_USE_VAO
// Using VBO without VAO
#define kQuadSize sizeof(m_pQuads[0].bl)
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
// XXX: update is done in draw... perhaps it should be done in a timer
if (m_bDirty)
glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] );
m_bDirty =
ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
// vertices
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(ccV3F_C4B_T2F, vertices));
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof(ccV3F_C4B_T2F, colors));
// tex coords
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(ccV3F_C4B_T2F, texCoords));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei)n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])));
glDrawElements(GL_TRIANGLES, (GLsizei)n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])));
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif // CC_TEXTURE_ATLAS_USE_VAO
CC_INCREMENT_GL_DRAWS(1);
CHECK_GL_ERROR_DEBUG();
Copyright(C)
OKBASE.NET All Rights Reserved 好库网 版权所有}

我要回帖

更多关于 cocos2d游戏源码 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信