fix coding style

This commit is contained in:
tangziwen 2014-12-19 11:22:59 +08:00
parent 591edd8bad
commit 1bbe9e249d
2 changed files with 111 additions and 116 deletions

View File

@ -1,27 +1,27 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2014 Chukong Technologies 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.
****************************************************************************/
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2014 Chukong Technologies 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.
****************************************************************************/
#include "Sprite3DTest.h"
#include "3d/CCAnimation3D.h"
@ -448,7 +448,7 @@ EffectSprite3D* EffectSprite3D::create(const std::string &path)
}
EffectSprite3D::EffectSprite3D()
: _defaultEffect(nullptr)
: _defaultEffect(nullptr)
{
}
@ -535,21 +535,21 @@ bool Effect3DOutline::init()
}
Effect3DOutline::Effect3DOutline()
: _outlineWidth(1.0f)
, _outlineColor(1, 1, 1)
, _sprite(nullptr)
: _outlineWidth(1.0f)
, _outlineColor(1, 1, 1)
, _sprite(nullptr)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
[this](EventCustom*)
{
auto glProgram = _glProgramState->getGLProgram();
glProgram->reset();
glProgram->initWithFilenames(_vertShaderFile, _fragShaderFile);
glProgram->link();
glProgram->updateUniforms();
}
);
[this](EventCustom*)
{
auto glProgram = _glProgramState->getGLProgram();
glProgram->reset();
glProgram->initWithFilenames(_vertShaderFile, _fragShaderFile);
glProgram->link();
glProgram->updateUniforms();
}
);
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
#endif
}
@ -609,13 +609,14 @@ void Effect3DOutline::setTarget(EffectSprite3D *sprite)
auto meshvertexattrib = mesh->getMeshVertexAttribute(i);
_glProgramState->setVertexAttribPointer(s_attributeNames[meshvertexattrib.vertexAttrib],
meshvertexattrib.size,
meshvertexattrib.type,
GL_FALSE,
mesh->getVertexSizeInBytes(),
(void*)offset);
meshvertexattrib.size,
meshvertexattrib.type,
GL_FALSE,
mesh->getVertexSizeInBytes(),
(void*)offset);
offset += meshvertexattrib.attribSizeBytes;
}
Color4F color(_sprite->getDisplayedColor());
color.a = _sprite->getDisplayedOpacity() / 255.0f;
_glProgramState->setUniformVec4("u_color", Vec4(color.r, color.g, color.b, color.a));
@ -647,7 +648,7 @@ void Effect3DOutline::draw(const Mat4 &transform)
if(_sprite && skin)
{
auto function = std::bind(MatrixPalleteCallBack, std::placeholders::_1, std::placeholders::_2,
skin->getMatrixPaletteSize(), (float*)skin->getMatrixPalette());
skin->getMatrixPaletteSize(), (float*)skin->getMatrixPalette());
_glProgramState->setUniformCallback("u_matrixPalette", function);
}
@ -901,11 +902,11 @@ void Sprite3DWithSkinOutlineTest::onTouchesEnded(const std::vector<Touch*>& touc
}
Animate3DTest::Animate3DTest()
: _hurt(nullptr)
, _swim(nullptr)
, _sprite(nullptr)
, _moveAction(nullptr)
, _elapseTransTime(0.f)
: _hurt(nullptr)
, _swim(nullptr)
, _sprite(nullptr)
, _moveAction(nullptr)
, _elapseTransTime(0.f)
{
addSprite3D();
@ -1036,8 +1037,8 @@ void Animate3DTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* ev
}
AttachmentTest::AttachmentTest()
: _hasWeapon(false)
, _sprite(nullptr)
: _hasWeapon(false)
, _sprite(nullptr)
{
auto s = Director::getInstance()->getWinSize();
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
@ -1092,8 +1093,9 @@ void AttachmentTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* e
}
_hasWeapon = !_hasWeapon;
}
Sprite3DReskinTest::Sprite3DReskinTest()
: _sprite(nullptr)
: _sprite(nullptr)
{
auto s = Director::getInstance()->getWinSize();
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
@ -1103,75 +1105,45 @@ Sprite3DReskinTest::Sprite3DReskinTest()
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
TTFConfig ttfConfig("fonts/arial.ttf", 20);
auto label1 = Label::createWithTTF(ttfConfig,"Hair");
auto item1 = MenuItemLabel::create(label1,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchHair,this) );
auto item1 = MenuItemLabel::create(label1,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
auto label2 = Label::createWithTTF(ttfConfig,"Glasses");
auto item2 = MenuItemLabel::create(label2, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchGlasses,this) );
auto item2 = MenuItemLabel::create(label2, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
auto label3 = Label::createWithTTF(ttfConfig,"Coat");
auto item3 = MenuItemLabel::create(label3,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchCoat,this) );
auto item3 = MenuItemLabel::create(label3,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
auto label4 = Label::createWithTTF(ttfConfig,"Pants");
auto item4 = MenuItemLabel::create(label4, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchPants,this) );
auto item4 = MenuItemLabel::create(label4, CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
auto label5 = Label::createWithTTF(ttfConfig,"Shoes");
auto item5 = MenuItemLabel::create(label5,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_switchShoes,this) );
auto item5 = MenuItemLabel::create(label5,CC_CALLBACK_1(Sprite3DReskinTest::menuCallback_reSkin,this) );
item1->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height*4 ) );
item2->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *5 ) );
item3->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height*6 ) );
item4->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *7 ) );
item5->setPosition( Vec2(VisibleRect::left().x+50, VisibleRect::bottom().y+item1->getContentSize().height *8 ) );
item1->setUserData((void*)SkinType::HAIR);
item2->setUserData((void*)SkinType::GLASSES);
item3->setUserData((void*)SkinType::UPPER_BODY);
item4->setUserData((void*)SkinType::PANTS);
item5->setUserData((void*)SkinType::SHOES);
auto pMenu1 = CCMenu::create(item1, item2, item3, item4, item5, nullptr);
pMenu1->setPosition(Vec2(0,0));
this->addChild(pMenu1, 10);
}
void Sprite3DReskinTest::menuCallback_switchHair(Ref* sender)
void Sprite3DReskinTest::menuCallback_reSkin(Ref* sender)
{
std::string str = _curSkin[SkinType::HAIR];
if (str == "Girl_Hair01")
_curSkin[SkinType::HAIR] = "Girl_Hair02";
else
_curSkin[SkinType::HAIR] = "Girl_Hair01";
applyCurSkin();
}
void Sprite3DReskinTest::menuCallback_switchGlasses(Ref* sender)
{
std::string str = _curSkin[SkinType::GLASSES];
if (str == "Girl_Glasses01")
_curSkin[SkinType::GLASSES] = "";
else
_curSkin[SkinType::GLASSES] = "Girl_Glasses01";
applyCurSkin();
}
void Sprite3DReskinTest::menuCallback_switchCoat(Ref* sender)
{
std::string str = _curSkin[SkinType::UPPER_BODY];
if (str == "Girl_UpperBody01")
_curSkin[SkinType::UPPER_BODY] = "Girl_UpperBody02";
else
_curSkin[SkinType::UPPER_BODY] = "Girl_UpperBody01";
applyCurSkin();
}
void Sprite3DReskinTest::menuCallback_switchPants(Ref* sender)
{
std::string str = _curSkin[SkinType::PANTS];
if (str == "Girl_LowerBody01")
_curSkin[SkinType::PANTS] = "Girl_LowerBody02";
else
_curSkin[SkinType::PANTS] = "Girl_LowerBody01";
applyCurSkin();
}
void Sprite3DReskinTest::menuCallback_switchShoes(Ref* sender)
{
std::string strShoes = _curSkin[SkinType::SHOES];
if (strShoes == "Girl_Shoes01")
_curSkin[SkinType::SHOES] = "Girl_Shoes02";
else
_curSkin[SkinType::SHOES] = "Girl_Shoes01";
applyCurSkin();
long index = (long)(((MenuItemLabel*)sender)->getUserData());
if (index < (int)SkinType::MAX_TYPE)
{
_curSkin[index] = (_curSkin[index] + 1) % _skins[index].size();
applyCurSkin();
}
}
std::string Sprite3DReskinTest::title() const
{
return "Testing Sprite3D Reskin";
}
std::string Sprite3DReskinTest::subtitle() const
{
return "";
@ -1194,13 +1166,36 @@ void Sprite3DReskinTest::addNewSpriteWithCoords(Vec2 p)
}
_sprite = sprite;
_curSkin[SkinType::UPPER_BODY] = "Girl_UpperBody01";
_curSkin[SkinType::PANTS] = "Girl_LowerBody01";
_curSkin[SkinType::SHOES] = "Girl_Shoes01";
_curSkin[SkinType::HAIR] = "Girl_Hair01";
_curSkin[SkinType::FACE] = "Girl_Face01";
_curSkin[SkinType::HAND] = "Girl_Hand01";
_curSkin[SkinType::GLASSES] = "";
auto& body = _skins[(int)SkinType::UPPER_BODY];
body.push_back("Girl_UpperBody01");
body.push_back("Girl_UpperBody02");
auto& pants = _skins[(int)SkinType::PANTS];
pants.push_back("Girl_LowerBody01");
pants.push_back("Girl_LowerBody02");
auto& shoes = _skins[(int)SkinType::SHOES];
shoes.push_back("Girl_Shoes01");
shoes.push_back("Girl_Shoes02");
auto& hair = _skins[(int)SkinType::HAIR];
hair.push_back("Girl_Hair01");
hair.push_back("Girl_Hair02");
auto& face = _skins[(int)SkinType::FACE];
face.push_back("Girl_Face01");
face.push_back("Girl_Face02");
auto& hand = _skins[(int)SkinType::HAND];
hand.push_back("Girl_Hand01");
hand.push_back("Girl_Hand02");
auto& glasses = _skins[(int)SkinType::GLASSES];
glasses.push_back("");
glasses.push_back("Girl_Glasses01");
memset(_curSkin, 0, (int)SkinType::MAX_TYPE * sizeof(int));
applyCurSkin();
}
@ -1213,8 +1208,8 @@ void Sprite3DReskinTest::applyCurSkin()
for (ssize_t i = 0; i < _sprite->getMeshCount(); i++) {
auto mesh = _sprite->getMeshByIndex(static_cast<int>(i));
bool isVisible = false;
for (auto& it : _curSkin) {
if (mesh->getName() == it.second)
for (int j = 0; j < (int)SkinType::MAX_TYPE; j++) {
if (mesh->getName() == _skins[j].at(_curSkin[j]))
{
isVisible = true;
break;
@ -1482,8 +1477,8 @@ void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, cons
}
Sprite3DMirrorTest::Sprite3DMirrorTest()
: _sprite(nullptr)
, _mirrorSprite(nullptr)
: _sprite(nullptr)
, _mirrorSprite(nullptr)
{
auto s = Director::getInstance()->getWinSize();
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );

View File

@ -321,14 +321,11 @@ public:
virtual std::string subtitle() const override;
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
void addNewSpriteWithCoords(Vec2 p);
void menuCallback_switchHair(Ref* sender);
void menuCallback_switchGlasses(Ref* sender);
void menuCallback_switchCoat(Ref* sender);
void menuCallback_switchPants(Ref* sender);
void menuCallback_switchShoes(Ref* sender);
void menuCallback_reSkin(Ref* sender);
protected:
void applyCurSkin();
enum class SkinType
{
UPPER_BODY = 0,
@ -338,8 +335,11 @@ protected:
FACE,
HAND,
GLASSES,
MAX_TYPE,
};
std::map<SkinType, std::string> _curSkin;
std::vector<std::string> _skins[(int)SkinType::MAX_TYPE]; //all skins
int _curSkin[(int)SkinType::MAX_TYPE]; //current skin index
cocos2d::Sprite3D* _sprite;
};
class Sprite3DWithOBBPerfromanceTest : public Sprite3DTestDemo