diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index af31d79c6e..73a33eb03f 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -819b72559f8be48c41958b0afb4c6513207b453a \ No newline at end of file +5b8d2ae9f19e1ca958245cf11e144d18d6ee3f89 \ No newline at end of file diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 3e40e41419..11f9998d6c 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -231,6 +231,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8; bool existNewLetter = false; + int bottomHeight = _commonLineHeight - _fontAscender; + for (int i = 0; i < length; ++i) { auto outIterator = _fontLetterDefinitions.find(utf16String[i]); @@ -248,6 +250,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.height = tempRect.size.height + _letterPadding; tempDef.offsetX = tempRect.origin.x + offsetAdjust; tempDef.offsetY = _fontAscender + tempRect.origin.y - offsetAdjust; + tempDef.clipBottom = bottomHeight - (tempDef.height + tempRect.origin.y + offsetAdjust); if (_currentPageOrigX + tempDef.width > CacheTextureWidth) { @@ -290,6 +293,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.offsetX = 0; tempDef.offsetY = 0; tempDef.textureID = 0; + tempDef.clipBottom = 0; _currentPageOrigX += 1; } diff --git a/cocos/2d/CCFontAtlas.h b/cocos/2d/CCFontAtlas.h index 2d3eb615a3..a10fe9eb9f 100644 --- a/cocos/2d/CCFontAtlas.h +++ b/cocos/2d/CCFontAtlas.h @@ -50,6 +50,8 @@ struct FontLetterDefinition int textureID; bool validDefinition; int xAdvance; + + int clipBottom; }; class CC_DLL FontAtlas : public Ref diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 55220b4df4..7314019dac 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -340,6 +340,8 @@ void Label::reset() _textColor = Color4B::WHITE; _textColorF = Color4F::WHITE; setColor(Color3B::WHITE); + + _clipEnabled = false; } void Label::updateShaderProgram() diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 93130c4e10..c2e2be23b8 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -217,6 +217,10 @@ public: virtual Sprite * getLetter(int lettetIndex); + /** clip upper and lower margin for reduce height of label. + */ + void setClipMarginEnabled(bool clipEnabled) { _clipEnabled = clipEnabled; } + bool isClipMarginEnabled() const { return _clipEnabled; } // font related stuff int getCommonLineHeight() const; @@ -365,6 +369,8 @@ protected: Color4B _textColor; Color4F _textColorF; + bool _clipEnabled; + private: CC_DISALLOW_COPY_AND_ASSIGN(Label); diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index 9f0efe1eaa..119456caa6 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -321,6 +321,16 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) FontLetterDefinition tempDefinition; Point letterPosition; const auto& kernings = theLabel->_horizontalKernings; + + float clipTop = 0; + float clipBottom = 0; + int lineIndex = 0; + bool lineStart = true; + bool clip = false; + if (theLabel->_currentLabelType == Label::LabelType::TTF && theLabel->_clipEnabled) + { + clip = true; + } for (unsigned int i = 0; i < stringLen; i++) { @@ -337,9 +347,10 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) charYOffset = -1; charAdvance = -1; } - + if (c == '\n') { + lineIndex++; nextFontPositionX = 0; nextFontPositionY -= theLabel->_commonLineHeight; @@ -347,8 +358,30 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) if(nextFontPositionY < theLabel->_commonLineHeight) break; + lineStart = true; continue; } + else if (clip && tempDefinition.height > 0.0f) + { + if (lineStart) + { + if (lineIndex == 0) + { + clipTop = charYOffset; + } + lineStart = false; + clipBottom = tempDefinition.clipBottom; + } + else if(tempDefinition.clipBottom < clipBottom) + { + clipBottom = tempDefinition.clipBottom; + } + + if (lineIndex == 0 && charYOffset < clipTop) + { + clipTop = charYOffset; + } + } letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor; letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor; @@ -382,11 +415,26 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) } tmpSize.height = totalHeight; + if (theLabel->_labelHeight > 0) { tmpSize.height = theLabel->_labelHeight * contentScaleFactor; } + + if (clip) + { + int clipTotal = (clipTop + clipBottom) / contentScaleFactor; + tmpSize.height -= clipTotal * contentScaleFactor; + clipBottom /= contentScaleFactor; + + for (int i = 0; i < theLabel->_limitShowCount; i++) + { + theLabel->_lettersInfo[i].position.y -= clipBottom; + } + } + theLabel->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize)); + return true; } diff --git a/cocos/2d/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp index a43563d862..564298eca3 100644 --- a/cocos/2d/CCTexture2D.cpp +++ b/cocos/2d/CCTexture2D.cpp @@ -1199,6 +1199,9 @@ void Texture2D::generateMipmap() GL::bindTexture2D( _name ); glGenerateMipmap(GL_TEXTURE_2D); _hasMipmaps = true; +#if CC_ENABLE_CACHE_TEXTURE_DATA + VolatileTextureMgr::setHasMipmaps(this, _hasMipmaps); +#endif } bool Texture2D::hasMipmaps() const diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 0e7bd4f647..38ef71f31a 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -635,6 +635,12 @@ void VolatileTextureMgr::addStringTexture(Texture2D *tt, const char* text, const vt->_fontDefinition = fontDefinition; } +void VolatileTextureMgr::setHasMipmaps(Texture2D *t, bool hasMipmaps) +{ + VolatileTexture *vt = findVolotileTexture(t); + vt->_hasMipmaps = hasMipmaps; +} + void VolatileTextureMgr::setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams) { VolatileTexture *vt = findVolotileTexture(t); @@ -717,6 +723,9 @@ void VolatileTextureMgr::reloadAllTextures() default: break; } + if (vt->_hasMipmaps) { + vt->_texture->generateMipmap(); + } vt->_texture->setTexParameters(vt->_texParams); } diff --git a/cocos/2d/CCTextureCache.h b/cocos/2d/CCTextureCache.h index 8ebd4821b5..39b1a8e957 100644 --- a/cocos/2d/CCTextureCache.h +++ b/cocos/2d/CCTextureCache.h @@ -251,6 +251,7 @@ protected: std::string _fileName; + bool _hasMipmaps; Texture2D::TexParams _texParams; std::string _text; FontDefinition _fontDefinition; @@ -264,6 +265,7 @@ public: static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize); static void addImage(Texture2D *tt, Image *image); + static void setHasMipmaps(Texture2D *t, bool hasMipmaps); static void setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams); static void removeTexture(Texture2D *t); static void reloadAllTextures(); diff --git a/cocos/network/WebSocket.cpp b/cocos/network/WebSocket.cpp index 4ba4b708a0..4e98591d24 100644 --- a/cocos/network/WebSocket.cpp +++ b/cocos/network/WebSocket.cpp @@ -187,16 +187,19 @@ void WsThreadHelper::update(float dt) WsMessage *msg = nullptr; // Returns quickly if no message - std::lock_guard lk(_UIWsMessageQueueMutex); + _UIWsMessageQueueMutex.lock(); if (0 == _UIWsMessageQueue->size()) { + _UIWsMessageQueueMutex.unlock(); return; } // Gets message msg = *(_UIWsMessageQueue->begin()); _UIWsMessageQueue->pop_front(); + + _UIWsMessageQueueMutex.unlock(); if (_ws) { diff --git a/templates/cocos2dx_files.json.REMOVED.git-id b/templates/cocos2dx_files.json.REMOVED.git-id index 5a0b0a9028..089a8e7561 100644 --- a/templates/cocos2dx_files.json.REMOVED.git-id +++ b/templates/cocos2dx_files.json.REMOVED.git-id @@ -1 +1 @@ -fa70974de744fb12ec4f753989e6e0a7eb9fc73a \ No newline at end of file +d53bc7d6e68a49984c5971344f59bba8414d142b \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp index 4f80334657..05e2fc128a 100644 --- a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp +++ b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp @@ -38,6 +38,7 @@ static std::function createFunctions[] = { CL(TexturePVRv3Premult), + CL(TextureMipMap), CL(TextureMemoryAlloc), CL(TextureAlias), CL(TexturePVRMipMap), diff --git a/tools/travis-scripts/generate-bindings.sh b/tools/travis-scripts/generate-bindings.sh index 19978804e3..0a2b428b57 100755 --- a/tools/travis-scripts/generate-bindings.sh +++ b/tools/travis-scripts/generate-bindings.sh @@ -23,6 +23,8 @@ ELAPSEDSECS=`date +%s` COCOS_BRANCH="update_lua_bindings_$ELAPSEDSECS" COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git" PULL_REQUEST_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" +FETCH_REMOTE_BRANCH="develop" +COMMIT_PATH="cocos/scripting/lua-bindings/auto" # Exit on error set -e @@ -88,12 +90,14 @@ pushd "$PROJECT_ROOT" git status echo -echo Comparing with HEAD ... +echo Comparing with origin HEAD ... echo +git fetch origin ${FETCH_REMOTE_BRANCH} + # Don't exit on non-zero return value set +e -git diff --stat --exit-code +git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH} DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ] diff --git a/tools/travis-scripts/generate-cocosfiles.sh b/tools/travis-scripts/generate-cocosfiles.sh index 1014bc303e..82837b2a6d 100755 --- a/tools/travis-scripts/generate-cocosfiles.sh +++ b/tools/travis-scripts/generate-cocosfiles.sh @@ -6,6 +6,8 @@ PROJECT_ROOT="$DIR"/../.. COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json" PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json" +FETCH_REMOTE_BRANCH="develop" +COMMIT_PATH="templates/cocos2dx_files.json" # Exit on error set -e @@ -51,12 +53,14 @@ pushd "$PROJECT_ROOT" git status echo -echo Comparing with HEAD ... +echo Comparing with origin HEAD ... echo +git fetch origin ${FETCH_REMOTE_BRANCH} + # Don't exit on non-zero return value set +e -git diff --stat --exit-code +git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH} DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ]