Merge pull request #6384 from dabingnn/v3_optimize

change tab to space for CCDirector.cpp
This commit is contained in:
James Chen 2014-04-28 09:54:43 +08:00
commit cbcf2e2bc8
2 changed files with 82 additions and 82 deletions

View File

@ -201,38 +201,38 @@ Director::~Director(void)
void Director::setDefaultValues(void)
{
Configuration *conf = Configuration::getInstance();
Configuration *conf = Configuration::getInstance();
// default FPS
double fps = conf->getValue("cocos2d.x.fps", Value(kDefaultFPS)).asDouble();
_oldAnimationInterval = _animationInterval = 1.0 / fps;
// default FPS
double fps = conf->getValue("cocos2d.x.fps", Value(kDefaultFPS)).asDouble();
_oldAnimationInterval = _animationInterval = 1.0 / fps;
// Display FPS
_displayStats = conf->getValue("cocos2d.x.display_fps", Value(false)).asBool();
// Display FPS
_displayStats = conf->getValue("cocos2d.x.display_fps", Value(false)).asBool();
// GL projection
// GL projection
std::string projection = conf->getValue("cocos2d.x.gl.projection", Value("3d")).asString();
if (projection == "3d")
_projection = Projection::_3D;
else if (projection == "2d")
_projection = Projection::_2D;
else if (projection == "custom")
_projection = Projection::CUSTOM;
else
CCASSERT(false, "Invalid projection value");
if (projection == "3d")
_projection = Projection::_3D;
else if (projection == "2d")
_projection = Projection::_2D;
else if (projection == "custom")
_projection = Projection::CUSTOM;
else
CCASSERT(false, "Invalid projection value");
// Default pixel format for PNG images with alpha
// Default pixel format for PNG images with alpha
std::string pixel_format = conf->getValue("cocos2d.x.texture.pixel_format_for_png", Value("rgba8888")).asString();
if (pixel_format == "rgba8888")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
else if(pixel_format == "rgba4444")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
else if(pixel_format == "rgba5551")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1);
if (pixel_format == "rgba8888")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
else if(pixel_format == "rgba4444")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
else if(pixel_format == "rgba5551")
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1);
// PVR v2 has alpha premultiplied ?
bool pvr_alpha_premultipled = conf->getValue("cocos2d.x.texture.pvrv2_has_alpha_premultiplied", Value(false)).asBool();
Texture2D::PVRImagesHavePremultipliedAlpha(pvr_alpha_premultipled);
// PVR v2 has alpha premultiplied ?
bool pvr_alpha_premultipled = conf->getValue("cocos2d.x.texture.pvrv2_has_alpha_premultiplied", Value(false)).asBool();
Texture2D::PVRImagesHavePremultipliedAlpha(pvr_alpha_premultipled);
}
void Director::setGLDefaultValues()
@ -359,7 +359,7 @@ void Director::calculateDeltaTime()
}
float Director::getDeltaTime() const
{
return _deltaTime;
return _deltaTime;
}
void Director::setOpenGLView(GLView *openGLView)
{
@ -367,9 +367,9 @@ void Director::setOpenGLView(GLView *openGLView)
if (_openGLView != openGLView)
{
// Configuration. Gather GPU info
Configuration *conf = Configuration::getInstance();
conf->gatherGPUInfo();
// Configuration. Gather GPU info
Configuration *conf = Configuration::getInstance();
conf->gatherGPUInfo();
CCLOG("%s\n",conf->getInfo().c_str());
if(_openGLView)
@ -721,7 +721,7 @@ static void GLToClipTransform(Matrix *transformOut)
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Matrix projection;
Matrix projection;
projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
@ -729,7 +729,7 @@ static void GLToClipTransform(Matrix *transformOut)
projection = Director::getInstance()->getOpenGLView()->getReverseOrientationMatrix() * projection;
#endif
Matrix modelview;
Matrix modelview;
modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
*transformOut = projection * modelview;
}
@ -737,37 +737,37 @@ static void GLToClipTransform(Matrix *transformOut)
Vector2 Director::convertToGL(const Vector2& uiPoint)
{
Matrix transform;
GLToClipTransform(&transform);
GLToClipTransform(&transform);
Matrix transformInv;
Matrix transformInv;
transform.invert(&transformInv);
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w
float zClip = transform.m[14]/transform.m[15];
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w
float zClip = transform.m[14]/transform.m[15];
Size glSize = _openGLView->getDesignResolutionSize();
Vector4 clipCoord(2.0f*uiPoint.x/glSize.width - 1.0f, 1.0f - 2.0f*uiPoint.y/glSize.height, zClip, 1);
Vector4 clipCoord(2.0f*uiPoint.x/glSize.width - 1.0f, 1.0f - 2.0f*uiPoint.y/glSize.height, zClip, 1);
Vector4 glCoord;
Vector4 glCoord;
//transformInv.transformPoint(clipCoord, &glCoord);
transformInv.transformVector(clipCoord, &glCoord);
float factor = 1.0/glCoord.w;
return Vector2(glCoord.x * factor, glCoord.y * factor);
return Vector2(glCoord.x * factor, glCoord.y * factor);
}
Vector2 Director::convertToUI(const Vector2& glPoint)
{
Matrix transform;
GLToClipTransform(&transform);
GLToClipTransform(&transform);
Vector4 clipCoord;
// Need to calculate the zero depth from the transform.
Vector4 glCoord(glPoint.x, glPoint.y, 0.0, 1);
Vector4 clipCoord;
// Need to calculate the zero depth from the transform.
Vector4 glCoord(glPoint.x, glPoint.y, 0.0, 1);
transform.transformVector(glCoord, &clipCoord);
Size glSize = _openGLView->getDesignResolutionSize();
Size glSize = _openGLView->getDesignResolutionSize();
float factor = 1.0/glCoord.w;
return Vector2(glSize.width*(clipCoord.x*0.5 + 0.5) * factor, glSize.height*(-clipCoord.y*0.5 + 0.5) * factor);
return Vector2(glSize.width*(clipCoord.x*0.5 + 0.5) * factor, glSize.height*(-clipCoord.y*0.5 + 0.5) * factor);
}
const Size& Director::getWinSize(void) const
@ -888,24 +888,24 @@ void Director::popToSceneStackLevel(int level)
if (level >= c)
return;
// pop stack until reaching desired level
while (c > level)
// pop stack until reaching desired level
while (c > level)
{
auto current = _scenesStack.back();
if (current->isRunning())
if (current->isRunning())
{
current->onExitTransitionDidStart();
current->onExit();
}
}
current->cleanup();
_scenesStack.popBack();
--c;
}
--c;
}
_nextScene = _scenesStack.back();
_sendCleanupToScene = false;
_sendCleanupToScene = false;
}
void Director::end()
@ -1103,7 +1103,7 @@ void Director::getFPSImageData(unsigned char** datapointer, ssize_t* length)
{
// XXX fixed me if it should be used
*datapointer = cc_fps_images_png;
*length = cc_fps_images_len();
*length = cc_fps_images_len();
}
void Director::createStatsLabel()

View File

@ -73,7 +73,7 @@ const char* GLProgram::UNIFORM_NAME_TIME = "CC_Time";
const char* GLProgram::UNIFORM_NAME_SIN_TIME = "CC_SinTime";
const char* GLProgram::UNIFORM_NAME_COS_TIME = "CC_CosTime";
const char* GLProgram::UNIFORM_NAME_RANDOM01 = "CC_Random01";
const char* GLProgram::UNIFORM_NAME_SAMPLER = "CC_Texture0";
const char* GLProgram::UNIFORM_NAME_SAMPLER = "CC_Texture0";
const char* GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE = "CC_alpha_value";
// Attribute names
@ -140,7 +140,7 @@ bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar*
if (!compileShader(&_vertShader, GL_VERTEX_SHADER, vShaderByteArray))
{
CCLOG("cocos2d: ERROR: Failed to compile vertex shader");
return false;
return false;
}
}
@ -150,7 +150,7 @@ bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar*
if (!compileShader(&_fragShader, GL_FRAGMENT_SHADER, fShaderByteArray))
{
CCLOG("cocos2d: ERROR: Failed to compile fragment shader");
return false;
return false;
}
}
@ -246,11 +246,11 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source
if (! status)
{
GLsizei length;
glGetShaderiv(*shader, GL_SHADER_SOURCE_LENGTH, &length);
GLchar* src = (GLchar *)malloc(sizeof(GLchar) * length);
glGetShaderiv(*shader, GL_SHADER_SOURCE_LENGTH, &length);
GLchar* src = (GLchar *)malloc(sizeof(GLchar) * length);
glGetShaderSource(*shader, length, nullptr, src);
CCLOG("cocos2d: ERROR: Failed to compile shader:\n%s", src);
glGetShaderSource(*shader, length, nullptr, src);
CCLOG("cocos2d: ERROR: Failed to compile shader:\n%s", src);
if (type == GL_VERTEX_SHADER)
{
@ -285,26 +285,26 @@ void GLProgram::bindAttribLocation(const char* attributeName, GLuint index) cons
void GLProgram::updateUniforms()
{
_uniforms[UNIFORM_P_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_P_MATRIX);
_uniforms[UNIFORM_MV_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_MV_MATRIX);
_uniforms[UNIFORM_MVP_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_MVP_MATRIX);
_uniforms[UNIFORM_MV_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_MV_MATRIX);
_uniforms[UNIFORM_MVP_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_MVP_MATRIX);
_uniforms[UNIFORM_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_TIME);
_uniforms[UNIFORM_SIN_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_SIN_TIME);
_uniforms[UNIFORM_COS_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_COS_TIME);
_uniforms[UNIFORM_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_TIME);
_uniforms[UNIFORM_SIN_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_SIN_TIME);
_uniforms[UNIFORM_COS_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_COS_TIME);
_uniforms[UNIFORM_RANDOM01] = glGetUniformLocation(_program, UNIFORM_NAME_RANDOM01);
_uniforms[UNIFORM_SAMPLER] = glGetUniformLocation(_program, UNIFORM_NAME_SAMPLER);
_flags.usesP = _uniforms[UNIFORM_P_MATRIX] != -1;
_flags.usesMV = _uniforms[UNIFORM_MV_MATRIX] != -1;
_flags.usesMV = _uniforms[UNIFORM_MV_MATRIX] != -1;
_flags.usesMVP = _uniforms[UNIFORM_MVP_MATRIX] != -1;
_flags.usesTime = (
_flags.usesTime = (
_uniforms[UNIFORM_TIME] != -1 ||
_uniforms[UNIFORM_SIN_TIME] != -1 ||
_uniforms[UNIFORM_COS_TIME] != -1
);
_flags.usesRandom = _uniforms[UNIFORM_RANDOM01] != -1;
_flags.usesRandom = _uniforms[UNIFORM_RANDOM01] != -1;
this->use();
@ -629,7 +629,7 @@ void GLProgram::setUniformsForBuiltins()
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Matrix matrixMV;
Matrix matrixMV;
matrixMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
setUniformsForBuiltins(matrixMV);
@ -650,19 +650,19 @@ void GLProgram::setUniformsForBuiltins(const Matrix &matrixMV)
setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_MVP_MATRIX], matrixMVP.m, 1);
}
if(_flags.usesTime) {
Director *director = Director::getInstance();
// This doesn't give the most accurate global time value.
// Cocos2D doesn't store a high precision time value, so this will have to do.
// Getting Mach time per frame per shader using time could be extremely expensive.
if(_flags.usesTime) {
Director *director = Director::getInstance();
// This doesn't give the most accurate global time value.
// Cocos2D doesn't store a high precision time value, so this will have to do.
// Getting Mach time per frame per shader using time could be extremely expensive.
float time = director->getTotalFrames() * director->getAnimationInterval();
setUniformLocationWith4f(_uniforms[GLProgram::UNIFORM_TIME], time/10.0, time, time*2, time*4);
setUniformLocationWith4f(_uniforms[GLProgram::UNIFORM_SIN_TIME], time/8.0, time/4.0, time/2.0, sinf(time));
setUniformLocationWith4f(_uniforms[GLProgram::UNIFORM_COS_TIME], time/8.0, time/4.0, time/2.0, cosf(time));
}
}
if(_flags.usesRandom)
if(_flags.usesRandom)
setUniformLocationWith4f(_uniforms[GLProgram::UNIFORM_RANDOM01], CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1());
}