Skip to content

Commit

Permalink
Merge branch 'v3' into downloader_decouple
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Aug 11, 2015
2 parents 8252464 + 6f4ed8a commit 9272765
Show file tree
Hide file tree
Showing 100 changed files with 2,200 additions and 1,289 deletions.
4 changes: 2 additions & 2 deletions build/cocos2d_tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6187,7 +6187,7 @@
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
INFOPLIST_FILE = "$(SRCROOT)/../tests/js-tests/project/proj.mac/Test_Info.plist";
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_LDFLAGS = (
"-pagezero_size",
10000,
Expand Down Expand Up @@ -6220,7 +6220,7 @@
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
INFOPLIST_FILE = "$(SRCROOT)/../tests/js-tests/project/proj.mac/Test_Info.plist";
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_LDFLAGS = (
"-pagezero_size",
10000,
Expand Down
80 changes: 53 additions & 27 deletions cocos/2d/CCLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class LabelLetter : public Sprite
CC_SAFE_DELETE(letter);
return nullptr;
}

CREATE_FUNC(LabelLetter);

virtual void updateTransform() override
{
Expand All @@ -77,6 +79,15 @@ class LabelLetter : public Sprite
float y1 = _offsetPosition.y;
float x2 = x1 + size.width;
float y2 = y1 + size.height;
if (_flippedX)
{
std::swap(x1, x2);
}
if (_flippedY)
{
std::swap(y1, y2);
}

float x = _transformToBatch.m[12];
float y = _transformToBatch.m[13];

Expand Down Expand Up @@ -746,26 +757,28 @@ void Label::updateQuads()

for (int ctr = 0; ctr < _lengthOfString; ++ctr)
{
auto& letterDef = _fontAtlas->_letterDefinitions[_lettersInfo[ctr].utf16Char];

if (letterDef.validDefinition)
if (_lettersInfo[ctr].valid)
{
auto& letterDef = _fontAtlas->_letterDefinitions[_lettersInfo[ctr].utf16Char];

_reusedRect.size.height = letterDef.height;
_reusedRect.size.width = letterDef.width;
_reusedRect.origin.x = letterDef.U;
_reusedRect.origin.y = letterDef.V;

auto py = _lettersInfo[ctr].positionY + _letterOffsetY;
if (py > _tailoredTopY)
{
auto clipTop = py - _tailoredTopY;
_reusedRect.origin.y += clipTop;
_reusedRect.size.height -= clipTop;
py -= clipTop;
}
if (py - letterDef.height < _tailoredBottomY)
{
_reusedRect.size.height = (py < _tailoredBottomY) ? 0.f : (py - _tailoredBottomY);
if (_labelHeight > 0.f) {
if (py > _tailoredTopY)
{
auto clipTop = py - _tailoredTopY;
_reusedRect.origin.y += clipTop;
_reusedRect.size.height -= clipTop;
py -= clipTop;
}
if (py - letterDef.height < _tailoredBottomY)
{
_reusedRect.size.height = (py < _tailoredBottomY) ? 0.f : (py - _tailoredBottomY);
}
}

if (_reusedRect.size.height > 0.f && _reusedRect.size.width > 0.f)
Expand Down Expand Up @@ -1351,10 +1364,10 @@ void Label::setSystemFontSize(float fontSize)
}

///// PROTOCOL STUFF
Sprite * Label::getLetter(int letterIndex)
Sprite* Label::getLetter(int letterIndex)
{
Sprite* letter = nullptr;
do
do
{
if (_systemFontDirty || _currentLabelType == LabelType::STRING_TEXTURE)
{
Expand Down Expand Up @@ -1390,23 +1403,36 @@ Sprite * Label::getLetter(int letterIndex)

if (letter == nullptr)
{
letter = LabelLetter::createWithTexture(_fontAtlas->getTexture(textureID), uvRect);
letter->setTextureAtlas(_batchNodes.at(textureID)->getTextureAtlas());
letter->setAtlasIndex(letterInfo.atlasIndex);

auto px = letterInfo.positionX + uvRect.size.width / 2 + _linesOffsetX[letterInfo.lineIndex];
auto py = letterInfo.positionY - uvRect.size.height / 2 + _letterOffsetY;
letter->setPosition(px,py);
letter->setOpacity(_realOpacity);
if (letterDef.width <= 0.f || letterDef.height <= 0.f)
{
letter = LabelLetter::create();
}
else
{
letter = LabelLetter::createWithTexture(_fontAtlas->getTexture(textureID), uvRect);
letter->setTextureAtlas(_batchNodes.at(textureID)->getTextureAtlas());
letter->setAtlasIndex(letterInfo.atlasIndex);
auto px = letterInfo.positionX + uvRect.size.width / 2 + _linesOffsetX[letterInfo.lineIndex];
auto py = letterInfo.positionY - uvRect.size.height / 2 + _letterOffsetY;
letter->setPosition(px,py);
letter->setOpacity(_realOpacity);
}

addChild(letter);

_letters[letterIndex] = letter;
}
else if (contentDirty)
{
letter->setTexture(_fontAtlas->getTexture(textureID));
letter->setTextureRect(uvRect, false, uvRect.size);
letter->setTextureAtlas(_batchNodes.at(textureID)->getTextureAtlas());
if (letterDef.width <= 0.f || letterDef.height <= 0.f)
{
letter->setTextureAtlas(nullptr);
}
else
{
letter->setTexture(_fontAtlas->getTexture(textureID));
letter->setTextureRect(uvRect, false, uvRect.size);
letter->setTextureAtlas(_batchNodes.at(textureID)->getTextureAtlas());
}
}
}
} while (false);
Expand Down
15 changes: 8 additions & 7 deletions cocos/2d/CCMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ void Menu::removeChild(Node* child, bool cleanup)

bool Menu::onTouchBegan(Touch* touch, Event* event)
{
if (_state != Menu::State::WAITING || ! _visible || !_enabled)
auto camera = Camera::getVisitingCamera();
if (_state != Menu::State::WAITING || ! _visible || !_enabled || !camera)
{
return false;
}
Expand All @@ -266,10 +267,11 @@ bool Menu::onTouchBegan(Touch* touch, Event* event)
}
}

_selectedItem = this->getItemForTouch(touch);
_selectedItem = this->getItemForTouch(touch, camera);
if (_selectedItem)
{
_state = Menu::State::TRACKING_TOUCH;
_selectedWithCamera = camera;
_selectedItem->selected();

return true;
Expand All @@ -288,6 +290,7 @@ void Menu::onTouchEnded(Touch* touch, Event* event)
_selectedItem->activate();
}
_state = Menu::State::WAITING;
_selectedWithCamera = nullptr;
this->release();
}

Expand All @@ -306,7 +309,7 @@ void Menu::onTouchCancelled(Touch* touch, Event* event)
void Menu::onTouchMoved(Touch* touch, Event* event)
{
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchMoved] -- invalid state");
MenuItem *currentItem = this->getItemForTouch(touch);
MenuItem *currentItem = this->getItemForTouch(touch, _selectedWithCamera);
if (currentItem != _selectedItem)
{
if (_selectedItem)
Expand Down Expand Up @@ -553,12 +556,10 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
}
}

MenuItem* Menu::getItemForTouch(Touch *touch)
MenuItem* Menu::getItemForTouch(Touch *touch, const Camera *camera)
{
Vec2 touchLocation = touch->getLocation();
auto camera = Camera::getVisitingCamera();

if (!_children.empty() && nullptr != camera)
if (!_children.empty())
{
for (auto iter = _children.crbegin(); iter != _children.crend(); ++iter)
{
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CC_DLL Menu : public Layer
/**
* @js ctor
*/
Menu() : _selectedItem(nullptr) {}
Menu() : _selectedItem(nullptr), _selectedWithCamera(nullptr) {}
virtual ~Menu();

/** initializes an empty Menu */
Expand All @@ -195,10 +195,10 @@ class CC_DLL Menu : public Layer
/** whether or not the menu will receive events */
bool _enabled;

virtual MenuItem* getItemForTouch(Touch * touch);
virtual MenuItem* getItemForTouch(Touch * touch, const Camera *camera);
State _state;
MenuItem *_selectedItem;

const Camera *_selectedWithCamera;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Menu);
};
Expand Down
17 changes: 17 additions & 0 deletions cocos/2d/CCSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)

Sprite::Sprite(void)
: _batchNode(nullptr)
, _textureAtlas(nullptr)
, _shouldBeHidden(false)
, _texture(nullptr)
, _spriteFrame(nullptr)
Expand Down Expand Up @@ -607,6 +608,16 @@ void Sprite::updateTransform(void)

float x2 = x1 + size.width;
float y2 = y1 + size.height;

if (_flippedX)
{
std::swap(x1, x2);
}
if (_flippedY)
{
std::swap(y1, y2);
}

float x = _transformToBatch.m[12];
float y = _transformToBatch.m[13];

Expand Down Expand Up @@ -922,6 +933,9 @@ void Sprite::setFlippedX(bool flippedX)
auto& v = _polyInfo.triangles.verts[i].vertices;
v.x = _contentSize.width -v.x;
}
if (_textureAtlas) {
setDirty(true);
}
}
}

Expand All @@ -939,6 +953,9 @@ void Sprite::setFlippedY(bool flippedY)
auto& v = _polyInfo.triangles.verts[i].vertices;
v.y = _contentSize.height -v.y;
}
if (_textureAtlas) {
setDirty(true);
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions cocos/3d/CCBundle3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ bool Bundle3D::load(const std::string& path)
getModelRelativePath(path);

bool ret = false;
std::string ext = path.substr(path.length() - 4, 4);
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
std::string ext = FileUtils::getInstance()->getFileExtension(path);
if (ext == ".c3t")
{
_isBinary = false;
Expand Down Expand Up @@ -2151,8 +2150,7 @@ std::vector<Vec3> Bundle3D::getTrianglesList(const std::string& path)
return trianglesList;

auto bundle = Bundle3D::createBundle();
std::string ext = path.substr(path.length() - 4, 4);
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
std::string ext = FileUtils::getInstance()->getFileExtension(path);
MeshDatas meshs;
if (ext == ".obj")
{
Expand Down
3 changes: 1 addition & 2 deletions cocos/3d/CCSprite3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ bool Sprite3D::loadFromFile(const std::string& path, NodeDatas* nodedatas, MeshD
{
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);

std::string ext = path.substr(path.length() - 4, 4);
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
std::string ext = FileUtils::getInstance()->getFileExtension(path);
if (ext == ".obj")
{
return Bundle3D::loadObj(*meshdatas, *materialdatas, *nodedatas, fullPath);
Expand Down
7 changes: 6 additions & 1 deletion cocos/audio/android/jni/cddandroidAndroidJavaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ AndroidJavaEngine::AndroidJavaEngine()
}
}

AndroidJavaEngine::~AndroidJavaEngine() {
AndroidJavaEngine::~AndroidJavaEngine()
{
if (_implementBaseOnAudioEngine)
{
stopAllEffects();
}
cocos2d::JniMethodInfo methodInfo;

if (!getJNIStaticMethodInfo(methodInfo, "end", "()V")) {
Expand Down
22 changes: 14 additions & 8 deletions cocos/audio/win32/AudioEngine-win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,34 @@ AudioCache* AudioEngineImpl::preload(const std::string& filePath, std::function<
break;
}

auto ext = strchr(filePath.c_str(), '.');
AudioCache::FileFormat fileFormat = AudioCache::FileFormat::UNKNOWN;

if (_stricmp(ext, ".ogg") == 0){
std::string fileExtension = FileUtils::getInstance()->getFileExtension(filePath);
if (fileExtension == ".ogg")
{
fileFormat = AudioCache::FileFormat::OGG;
}
else if (_stricmp(ext, ".mp3") == 0){
else if (fileExtension == ".mp3")
{
fileFormat = AudioCache::FileFormat::MP3;

if (MPG123_LAZYINIT){
if (MPG123_LAZYINIT)
{
auto error = mpg123_init();
if (error == MPG123_OK){
if (error == MPG123_OK)
{
MPG123_LAZYINIT = false;
}
else{
else
{
log("Basic setup goes wrong: %s", mpg123_plain_strerror(error));
break;
}
}
}
else{
log("unsupported media type:%s\n", ext);
else
{
log("Unsupported media type file: %s\n", filePath.c_str());
break;
}

Expand Down
9 changes: 4 additions & 5 deletions cocos/audio/win32/MciPlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MciPlayer.h"
#include <tchar.h>
#include "platform/CCFileUtils.h"

#define WIN_CLASS_NAME "CocosDenshionCallbackWnd"
#define BREAK_IF(cond) if (cond) break;
Expand Down Expand Up @@ -79,10 +80,8 @@ void MciPlayer::Open(const char* pFileName, UINT uId)
// pBuf = new WCHAR[nLen + 1];
// BREAK_IF(! pBuf);
// MultiByteToWideChar(CP_ACP, 0, pFileName, nLen + 1, pBuf, nLen + 1);

std::string strFile(pFileName);
int nPos = strFile.rfind(".") + 1;
strExt = strFile.substr(nPos, strFile.length() - nPos);

strExt = cocos2d::FileUtils::getInstance()->getFileExtension(pFileName);

Close();

Expand Down Expand Up @@ -141,7 +140,7 @@ void MciPlayer::Pause()

void MciPlayer::Resume()
{
if (strExt == "mid" || strExt == "MID")
if (strExt == ".mid")
{
// midi not supprt MCI_RESUME, should get the position and use MCI_FROM
MCI_STATUS_PARMS mciStatusParms;
Expand Down
Loading

0 comments on commit 9272765

Please sign in to comment.