Merge branch 'adxeproject:dev' into partical-system-animation

This commit is contained in:
Turky Mohammed 2022-06-12 17:26:54 +03:00 committed by GitHub
commit 31dcd4eb25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 6212 additions and 1683 deletions

View File

@ -4,7 +4,6 @@ on:
push: push:
branches: branches:
- dev - dev
- main
paths: paths:
- core/**/* - core/**/*
- extensions/**/* - extensions/**/*
@ -31,10 +30,10 @@ jobs:
run: tools\win-ci\genbindings.ps1 run: tools\win-ci\genbindings.ps1
- name: Commit genbindings changes - name: Commit genbindings changes
uses: EndBug/add-and-commit@v7.5.0 uses: EndBug/add-and-commit@v9.0.0
with: with:
committer_name: GitHub Actions committer_name: GitHub Actions
committer_email: 41898282+github-actions[bot]@users.noreply.github.com committer_email: 41898282+github-actions[bot]@users.noreply.github.com
message: 'Committing genbindings changes [skip ci]' message: 'Committing genbindings changes'
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,6 +1,6 @@
# adxe # adxe
[![dev](https://img.shields.io/badge/v1.0.0-beta6-yellow.svg)](https://github.com/adxeproject/adxe/releases) [![dev](https://img.shields.io/github/v/release/adxeproject/adxe?include_prereleases&label=release)](https://github.com/adxeproject/adxe/releases)
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/adxeproject/adxe/blob/master/LICENSE) [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/adxeproject/adxe/blob/master/LICENSE)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1c5628dea478449ea0c6e1b0e30c3be9)](https://app.codacy.com/gh/adxeproject/adxe?utm_source=github.com&utm_medium=referral&utm_content=adxeproject/adxe&utm_campaign=Badge_Grade_Settings) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/1c5628dea478449ea0c6e1b0e30c3be9)](https://app.codacy.com/gh/adxeproject/adxe?utm_source=github.com&utm_medium=referral&utm_content=adxeproject/adxe&utm_campaign=Badge_Grade_Settings)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/adxeproject/adxe/pulls) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/adxeproject/adxe/pulls)
@ -99,7 +99,7 @@ Open [APPENDIX.md](APPENDIX.md) for additional information and see [Milestones](
4. Start Android Studio and Open [Tools][SDKManager], then switch to ```SDK Tools```, check the ```Show Package Details```, choose the following tools and click the button ```Apply``` to install them: 4. Start Android Studio and Open [Tools][SDKManager], then switch to ```SDK Tools```, check the ```Show Package Details```, choose the following tools and click the button ```Apply``` to install them:
* Android SDK Platform 29 r5 * Android SDK Platform 29 r5
* Android SDK Build-Tools 29.0.2 * Android SDK Build-Tools 29.0.2
* NDK r19c+ * NDK r23c+
* CMake 3.10+ * CMake 3.10+
5. Wait for ```Gradle sync``` finish. 5. Wait for ```Gradle sync``` finish.
6. Note: If you use non-sdk provided CMake edition, you will need to download ```ninja``` from https://github.com/ninja-build/ninja/releases, and copy ```ninja.exe``` to cmake's bin directory 6. Note: If you use non-sdk provided CMake edition, you will need to download ```ninja``` from https://github.com/ninja-build/ninja/releases, and copy ```ninja.exe``` to cmake's bin directory

View File

@ -1,6 +1,6 @@
# adxe # adxe
[![dev](https://img.shields.io/badge/v1.0.0-beta6-yellow.svg)](https://github.com/adxeproject/adxe/releases) [![dev](https://img.shields.io/github/v/release/adxeproject/adxe?include_prereleases&label=release)](https://github.com/adxeproject/adxe/releases)
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/adxeproject/adxe/blob/master/LICENSE) [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/adxeproject/adxe/blob/master/LICENSE)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1c5628dea478449ea0c6e1b0e30c3be9)](https://app.codacy.com/gh/adxeproject/adxe?utm_source=github.com&utm_medium=referral&utm_content=adxeproject/adxe&utm_campaign=Badge_Grade_Settings) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/1c5628dea478449ea0c6e1b0e30c3be9)](https://app.codacy.com/gh/adxeproject/adxe?utm_source=github.com&utm_medium=referral&utm_content=adxeproject/adxe&utm_campaign=Badge_Grade_Settings)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/adxeproject/adxe/pulls) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/adxeproject/adxe/pulls)
@ -73,7 +73,7 @@
3. 通过 [Tools][SdkManagers] 打开sdk管理工具选择如下SDK Platforms和SDK Tools后 点击按钮 ```Apply``` 一路跟着引导安装即可: 3. 通过 [Tools][SdkManagers] 打开sdk管理工具选择如下SDK Platforms和SDK Tools后 点击按钮 ```Apply``` 一路跟着引导安装即可:
* Android SDK Platform 29 r5 (在SDK Platforms页签) * Android SDK Platform 29 r5 (在SDK Platforms页签)
* Android SDK Build-Tools 29.0.2 * Android SDK Build-Tools 29.0.2
* NDK r19c+ * NDK r23c+
* CMake 3.10+ * CMake 3.10+
5. 等待Gradle sync完成后Build APKs安装运行 5. 等待Gradle sync完成后Build APKs安装运行

View File

@ -55,7 +55,7 @@ macro(cocos2dx_depend)
find_library(APPLICATIONSERVICES_LIBRARY ApplicationServices) find_library(APPLICATIONSERVICES_LIBRARY ApplicationServices)
find_library(IOKIT_LIBRARY IOKit) find_library(IOKIT_LIBRARY IOKit)
find_library(APPKIT_LIBRARY AppKit) find_library(APPKIT_LIBRARY AppKit)
find_library(ICONV_LIBRARY iconv) #find_library(ICONV_LIBRARY iconv)
find_library(AUDIOUNIT_LIBRARY AudioUnit) find_library(AUDIOUNIT_LIBRARY AudioUnit)
find_library(COREAUDIO_LIBRARY CoreAudio) find_library(COREAUDIO_LIBRARY CoreAudio)
find_library(SYSTEMCONFIGURATION_LIBRARY SystemConfiguration) find_library(SYSTEMCONFIGURATION_LIBRARY SystemConfiguration)
@ -66,7 +66,7 @@ macro(cocos2dx_depend)
${IOKIT_LIBRARY} ${IOKIT_LIBRARY}
${COCOS_APPLE_LIBS} ${COCOS_APPLE_LIBS}
${APPKIT_LIBRARY} ${APPKIT_LIBRARY}
${ICONV_LIBRARY} #${ICONV_LIBRARY}
${AUDIOUNIT_LIBRARY} ${AUDIOUNIT_LIBRARY}
${COREAUDIO_LIBRARY} ${COREAUDIO_LIBRARY}
${SYSTEMCONFIGURATION_LIBRARY} ${SYSTEMCONFIGURATION_LIBRARY}
@ -84,7 +84,7 @@ macro(cocos2dx_depend)
find_library(AV_FOUNDATION_LIBRARY AVFoundation) find_library(AV_FOUNDATION_LIBRARY AVFoundation)
find_library(WEBKIT_LIBRARY WebKit) find_library(WEBKIT_LIBRARY WebKit)
find_library(ZLIB z) find_library(ZLIB z)
find_library(ICONVLIB iconv) #find_library(ICONVLIB iconv)
list(APPEND PLATFORM_SPECIFIC_LIBS list(APPEND PLATFORM_SPECIFIC_LIBS
${UIKIT_LIBRARY} ${UIKIT_LIBRARY}
${OPENGLES_LIBRARY} ${OPENGLES_LIBRARY}
@ -98,7 +98,7 @@ macro(cocos2dx_depend)
${WEBKIT_LIBRARY} ${WEBKIT_LIBRARY}
${COCOS_APPLE_LIBS} ${COCOS_APPLE_LIBS}
${ZLIB} ${ZLIB}
${ICONVLIB} #${ICONVLIB}
) )
endif() endif()
endif() endif()

View File

@ -2,7 +2,7 @@
Copyright (c) 2013 Zynga Inc. Copyright (c) 2013 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2021 Bytedance Inc. Copyright (c) 2021-2022 Bytedance Inc.
https://adxeproject.github.io/ https://adxeproject.github.io/
@ -27,7 +27,6 @@
#include "2d/CCFontAtlas.h" #include "2d/CCFontAtlas.h"
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID #if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
# include <iconv.h>
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
# include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h" # include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
#endif #endif
@ -125,14 +124,6 @@ FontAtlas::~FontAtlas()
releaseTextures(); releaseTextures();
delete[] _currentPageData; delete[] _currentPageData;
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
if (_iconv)
{
iconv_close(_iconv);
_iconv = nullptr;
}
#endif
} }
void FontAtlas::initTextureWithZeros(Texture2D* texture) void FontAtlas::initTextureWithZeros(Texture2D* texture)
@ -229,80 +220,9 @@ bool FontAtlas::getLetterDefinitionForChar(char32_t utf32Char, FontLetterDefinit
} }
} }
void FontAtlas::conversionU32TOGB2312(const std::u32string& u32Text, void FontAtlas::findNewCharacters(const std::u32string& u32Text, std::unordered_set<char32_t>& charset)
std::unordered_map<unsigned int, unsigned int>& charCodeMap)
{
size_t strLen = u32Text.length();
auto gb2312StrSize = strLen * 2;
auto gb2312Text = new char[gb2312StrSize];
memset(gb2312Text, 0, gb2312StrSize);
switch (_fontFreeType->getEncoding())
{
case FT_ENCODING_GB2312:
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
std::u16string u16Text;
cocos2d::StringUtils::UTF32ToUTF16(u32Text, u16Text);
WideCharToMultiByte(936, NULL, (LPCWCH)u16Text.c_str(), strLen, (LPSTR)gb2312Text, gb2312StrSize, NULL, NULL);
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
conversionEncodingJNI((char*)u32Text.c_str(), gb2312StrSize, "UTF-32LE", gb2312Text, "GB2312");
#else
if (_iconv == nullptr)
{
_iconv = iconv_open("GBK//TRANSLIT", "UTF-32LE");
}
if (_iconv == (iconv_t)-1)
{
CCLOG("conversion from utf32 to gb2312 not available");
}
else
{
char* pin = (char*)u32Text.c_str();
char* pout = gb2312Text;
size_t inLen = strLen * 2;
size_t outLen = gb2312StrSize;
iconv(_iconv, (char**)&pin, &inLen, &pout, &outLen);
}
#endif
}
break;
default:
CCLOG("Unsupported encoding:%d", _fontFreeType->getEncoding());
break;
}
unsigned short gb2312Code = 0;
unsigned char* dst = (unsigned char*)&gb2312Code;
char32_t u32Code;
for (size_t index = 0, gbIndex = 0; index < strLen; ++index)
{
u32Code = u32Text[index];
if (u32Code < 256)
{
charCodeMap[u32Code] = u32Code;
gbIndex += 1;
}
else
{
dst[0] = gb2312Text[gbIndex + 1];
dst[1] = gb2312Text[gbIndex];
charCodeMap[u32Code] = gb2312Code;
gbIndex += 2;
}
}
delete[] gb2312Text;
}
void FontAtlas::findNewCharacters(const std::u32string& u32Text,
std::unordered_map<unsigned int, unsigned int>& charCodeMap)
{ {
std::u32string newChars; std::u32string newChars;
FT_Encoding charEncoding = _fontFreeType->getEncoding();
// find new characters // find new characters
if (_letterDefinitions.empty()) if (_letterDefinitions.empty())
@ -338,25 +258,8 @@ void FontAtlas::findNewCharacters(const std::u32string& u32Text,
if (!newChars.empty()) if (!newChars.empty())
{ {
switch (charEncoding) for (auto u32Code : newChars)
{ charset.insert(u32Code);
case FT_ENCODING_UNICODE:
{
for (auto u32Code : newChars)
{
charCodeMap[u32Code] = u32Code;
}
break;
}
case FT_ENCODING_GB2312:
{
conversionU32TOGB2312(newChars, charCodeMap);
break;
}
default:
CCLOG("FontAtlas::findNewCharacters: Unsupported encoding:%d", charEncoding);
break;
}
} }
} }
@ -370,9 +273,9 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
if (!_currentPageData) if (!_currentPageData)
reinit(); reinit();
std::unordered_map<unsigned int, unsigned int> codeMapOfNewChar; std::unordered_set<char32_t> charCodeSet;
findNewCharacters(utf32Text, codeMapOfNewChar); findNewCharacters(utf32Text, charCodeSet);
if (codeMapOfNewChar.empty()) if (charCodeSet.empty())
{ {
return false; return false;
} }
@ -390,9 +293,9 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
int startY = (int)_currentPageOrigY; int startY = (int)_currentPageOrigY;
for (auto&& it : codeMapOfNewChar) for (auto charCode : charCodeSet)
{ {
auto bitmap = _fontFreeType->getGlyphBitmap(it.second, bitmapWidth, bitmapHeight, tempRect, tempDef.xAdvance); auto bitmap = _fontFreeType->getGlyphBitmap(charCode, bitmapWidth, bitmapHeight, tempRect, tempDef.xAdvance);
if (bitmap && bitmapWidth > 0 && bitmapHeight > 0) if (bitmap && bitmapWidth > 0 && bitmapHeight > 0)
{ {
tempDef.validDefinition = true; tempDef.validDefinition = true;
@ -471,7 +374,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
_currentPageOrigX += 1; _currentPageOrigX += 1;
} }
_letterDefinitions[it.first] = tempDef; _letterDefinitions[charCode] = tempDef;
} }
updateTextureContent(pixelFormat, startY); updateTextureContent(pixelFormat, startY);

View File

@ -2,7 +2,7 @@
Copyright (c) 2013 Zynga Inc. Copyright (c) 2013 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2021 Bytedance Inc. Copyright (c) 2021-2022 Bytedance Inc.
https://adxeproject.github.io/ https://adxeproject.github.io/
@ -120,10 +120,7 @@ protected:
void releaseTextures(); void releaseTextures();
void findNewCharacters(const std::u32string& u32Text, std::unordered_map<unsigned int, unsigned int>& charCodeMap); void findNewCharacters(const std::u32string& u32Text, std::unordered_set<char32_t>& charCodeSet);
void conversionU32TOGB2312(const std::u32string& u32Text,
std::unordered_map<unsigned int, unsigned int>& charCodeMap);
void initTextureWithZeros(Texture2D* texture); void initTextureWithZeros(Texture2D* texture);
@ -141,7 +138,6 @@ protected:
float _lineHeight = 0.f; float _lineHeight = 0.f;
Font* _font = nullptr; Font* _font = nullptr;
FontFreeType* _fontFreeType = nullptr; FontFreeType* _fontFreeType = nullptr;
void* _iconv = nullptr;
// Dynamic GlyphCollection related stuff // Dynamic GlyphCollection related stuff
int _currentPage = 0; int _currentPage = 0;

View File

@ -54,8 +54,7 @@ void FontAtlasCache::purgeCachedData()
FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config) FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config)
{ {
auto realFontFilename = FileUtils::getInstance()->getNewFilename( auto realFontFilename = config->fontFilePath; // resolves real file path, to prevent storing multiple atlases for the same file.
config->fontFilePath); // resolves real file path, to prevent storing multiple atlases for the same file.
bool useDistanceField = config->distanceFieldEnabled; bool useDistanceField = config->distanceFieldEnabled;
if (config->outlineSize > 0) if (config->outlineSize > 0)
{ {
@ -97,8 +96,7 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(std::string_view fontFileName)
FontAtlas* FontAtlasCache::getFontAtlasFNT(std::string_view fontFileName, std::string_view subTextureKey) FontAtlas* FontAtlasCache::getFontAtlasFNT(std::string_view fontFileName, std::string_view subTextureKey)
{ {
const auto realFontFilename = FileUtils::getInstance()->getNewFilename( const auto realFontFilename = fontFileName; // resolves real file path, to prevent storing multiple atlases for the same file.
fontFileName); // resolves real file path, to prevent storing multiple atlases for the same file.
std::string atlasName{subTextureKey}; std::string atlasName{subTextureKey};
atlasName.append(" ", 1).append(realFontFilename); atlasName.append(" ", 1).append(realFontFilename);
@ -125,8 +123,7 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(std::string_view fontFileName, std::s
FontAtlas* FontAtlasCache::getFontAtlasFNT(std::string_view fontFileName, const Rect& imageRect, bool imageRotated) FontAtlas* FontAtlasCache::getFontAtlasFNT(std::string_view fontFileName, const Rect& imageRect, bool imageRotated)
{ {
const auto realFontFilename = FileUtils::getInstance()->getNewFilename( const auto realFontFilename = fontFileName; // resolves real file path, to prevent storing multiple atlases for the same file.
fontFileName); // resolves real file path, to prevent storing multiple atlases for the same file.
char keyPrefix[ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE]; char keyPrefix[ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE];
snprintf(keyPrefix, ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE, "%.2f %.2f ", imageRect.origin.x, imageRect.origin.y); snprintf(keyPrefix, ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE, "%.2f %.2f ", imageRect.origin.x, imageRect.origin.y);
std::string atlasName(keyPrefix); std::string atlasName(keyPrefix);

View File

@ -2,7 +2,7 @@
Copyright (c) 2013 Zynga Inc. Copyright (c) 2013 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2021 Bytedance Inc. Copyright (c) 2021-2022 Bytedance Inc.
https://adxeproject.github.io/ https://adxeproject.github.io/
@ -59,7 +59,7 @@ typedef struct _DataRef
unsigned int referenceCount = 0; unsigned int referenceCount = 0;
} DataRef; } DataRef;
static std::unordered_map<std::string, DataRef> s_cacheFontData; static hlookup::string_map<DataRef> s_cacheFontData;
// ------ freetype2 stream parsing support --- // ------ freetype2 stream parsing support ---
static unsigned long ft_stream_read_callback(FT_Stream stream, static unsigned long ft_stream_read_callback(FT_Stream stream,
@ -149,7 +149,6 @@ FT_Library FontFreeType::getFTLibrary()
FontFreeType::FontFreeType(bool distanceFieldEnabled /* = false */, float outline /* = 0 */) FontFreeType::FontFreeType(bool distanceFieldEnabled /* = false */, float outline /* = 0 */)
: _fontFace(nullptr) : _fontFace(nullptr)
, _stroker(nullptr) , _stroker(nullptr)
, _encoding(FT_ENCODING_UNICODE)
, _distanceFieldEnabled(distanceFieldEnabled) , _distanceFieldEnabled(distanceFieldEnabled)
, _outlineSize(0.0f) , _outlineSize(0.0f)
, _ascender(0) , _ascender(0)
@ -170,16 +169,12 @@ FontFreeType::FontFreeType(bool distanceFieldEnabled /* = false */, float outlin
} }
// clang-format on // clang-format on
bool FontFreeType::loadFontFace(std::string_view fontName, float fontSize) bool FontFreeType::loadFontFace(std::string_view fontPath, float fontSize)
{ {
FT_Face face; FT_Face face;
// save font name locally
_fontName = fontName;
_fontSize = fontSize;
if (_streamParsingEnabled) if (_streamParsingEnabled)
{ {
auto fullPath = FileUtils::getInstance()->fullPathForFilename(_fontName); auto fullPath = FileUtils::getInstance()->fullPathForFilename(fontPath);
if (fullPath.empty()) if (fullPath.empty())
return false; return false;
@ -207,15 +202,15 @@ bool FontFreeType::loadFontFace(std::string_view fontName, float fontSize)
else else
{ {
DataRef* sharableData; DataRef* sharableData;
auto it = s_cacheFontData.find(_fontName); auto it = s_cacheFontData.find(fontPath);
if (it != s_cacheFontData.end()) if (it != s_cacheFontData.end())
{ {
sharableData = &it->second; sharableData = &it->second;
} }
else else
{ {
sharableData = &s_cacheFontData[_fontName]; sharableData = &s_cacheFontData[fontPath];
sharableData->data = FileUtils::getInstance()->getDataFromFile(_fontName); sharableData->data = FileUtils::getInstance()->getDataFromFile(fontPath);
} }
++sharableData->referenceCount; ++sharableData->referenceCount;
@ -225,66 +220,55 @@ bool FontFreeType::loadFontFace(std::string_view fontName, float fontSize)
return false; return false;
} }
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE)) do
{ {
int foundIndex = -1; if (!face->charmap || face->charmap->encoding != FT_ENCODING_UNICODE)
for (int charmapIndex = 0; charmapIndex < face->num_charmaps; charmapIndex++) break;
// set the requested font size
int dpi = 72;
int fontSizePoints = (int)(64.f * fontSize * CC_CONTENT_SCALE_FACTOR());
if (FT_Set_Char_Size(face, fontSizePoints, fontSizePoints, dpi, dpi))
break;
// store the face globally
_fontFace = face;
_fontSize = fontSize;
_fontName = fontPath;
// Notes:
// a. Since freetype 2.8.1 the TT matrics isn't sync to size_matrics, see the function 'tt_size_request' in
// truetype/ttdriver.c b. The TT spec always asks for ROUND, not FLOOR or CEIL, see also the function
// 'tt_size_reset' in truetype/ttobjs.c
// ** Please see description of FT_Size_Metrics_ in freetype.h about this solution
// FT_PIX_ROUND is copy from freetype/internal/ftobjs.h
auto& size_metrics = _fontFace->size->metrics;
if (_doNativeBytecodeHinting && !strcmp(FT_Get_Font_Format(face), "TrueType"))
{ {
if (face->charmaps[charmapIndex]->encoding != FT_ENCODING_NONE)
{
foundIndex = charmapIndex;
break;
}
}
if (foundIndex == -1)
{
return false;
}
_encoding = face->charmaps[foundIndex]->encoding;
if (FT_Select_Charmap(face, _encoding))
{
return false;
}
}
// set the requested font size
int dpi = 72;
int fontSizePoints = (int)(64.f * fontSize * CC_CONTENT_SCALE_FACTOR());
if (FT_Set_Char_Size(face, fontSizePoints, fontSizePoints, dpi, dpi))
return false;
// store the face globally
_fontFace = face;
// Notes:
// a. Since freetype 2.8.1 the TT matrics isn't sync to size_matrics, see the function 'tt_size_request' in
// truetype/ttdriver.c b. The TT spec always asks for ROUND, not FLOOR or CEIL, see also the function
// 'tt_size_reset' in truetype/ttobjs.c
// ** Please see description of FT_Size_Metrics_ in freetype.h about this solution
// FT_PIX_ROUND is copy from freetype/internal/ftobjs.h
auto& size_metrics = _fontFace->size->metrics;
if (_doNativeBytecodeHinting && !strcmp(FT_Get_Font_Format(face), "TrueType"))
{
#if !defined(FT_PIX_ROUND) #if !defined(FT_PIX_ROUND)
# define FT_TYPEOF(type) # define FT_TYPEOF(type)
# define FT_PIX_FLOOR(x) ((x) & ~FT_TYPEOF(x) 63) # define FT_PIX_FLOOR(x) ((x) & ~FT_TYPEOF(x) 63)
# define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32) # define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
#endif #endif
_ascender = FT_PIX_ROUND(FT_MulFix(face->ascender, size_metrics.y_scale)); _ascender = FT_PIX_ROUND(FT_MulFix(face->ascender, size_metrics.y_scale));
_descender = FT_PIX_ROUND(FT_MulFix(face->descender, size_metrics.y_scale)); _descender = FT_PIX_ROUND(FT_MulFix(face->descender, size_metrics.y_scale));
} }
else else
{ {
_ascender = size_metrics.ascender; _ascender = size_metrics.ascender;
_descender = size_metrics.descender; _descender = size_metrics.descender;
} }
_lineHeight = (_ascender - _descender) >> 6; _lineHeight = (_ascender - _descender) >> 6;
// done and good // done and good
return true; return true;
} while (false);
FT_Done_Face(face);
cocos2d::log("Init font '%s' failed, only unicode ttf/ttc was supported.", fontPath.data());
return false;
} }
FontFreeType::~FontFreeType() FontFreeType::~FontFreeType()
@ -386,7 +370,7 @@ const char* FontFreeType::getFontFamily() const
return _fontFace->family_name; return _fontFace->family_name;
} }
unsigned char* FontFreeType::getGlyphBitmap(uint32_t theChar, unsigned char* FontFreeType::getGlyphBitmap(char32_t charCode,
int32_t& outWidth, int32_t& outWidth,
int32_t& outHeight, int32_t& outHeight,
Rect& outRect, Rect& outRect,
@ -400,11 +384,11 @@ unsigned char* FontFreeType::getGlyphBitmap(uint32_t theChar,
break; break;
// @remark: glyphIndex=0 means charactor is mssing on current font face // @remark: glyphIndex=0 means charactor is mssing on current font face
auto glyphIndex = FT_Get_Char_Index(_fontFace, static_cast<FT_ULong>(theChar)); auto glyphIndex = FT_Get_Char_Index(_fontFace, static_cast<FT_ULong>(charCode));
#if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG > 0 #if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG > 0
if (glyphIndex == 0) if (glyphIndex == 0)
{ {
char32_t ntcs[2] = {theChar, (char32_t)0}; char32_t ntcs[2] = {charCode, (char32_t)0};
std::u32string_view charUTF32(ntcs, 1); std::u32string_view charUTF32(ntcs, 1);
std::string charUTF8; std::string charUTF8;
cocos2d::StringUtils::UTF32ToUTF8(charUTF32, charUTF8); cocos2d::StringUtils::UTF32ToUTF8(charUTF32, charUTF8);

View File

@ -2,7 +2,7 @@
Copyright (c) 2013 Zynga Inc. Copyright (c) 2013 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2021 Bytedance Inc. Copyright (c) 2021-2022 Bytedance Inc.
https://adxeproject.github.io/ https://adxeproject.github.io/
@ -45,7 +45,7 @@ class CC_DLL FontFreeType : public Font
public: public:
static const int DistanceMapSpread; static const int DistanceMapSpread;
static FontFreeType* create(std::string_view fontName, static FontFreeType* create(std::string_view fontPath,
float fontSize, float fontSize,
GlyphCollection glyphs, GlyphCollection glyphs,
std::string_view customGlyphs, std::string_view customGlyphs,
@ -89,11 +89,9 @@ public:
int32_t bitmapWidth, int32_t bitmapWidth,
int32_t bitmapHeight); int32_t bitmapHeight);
FT_Encoding getEncoding() const { return _encoding; }
int* getHorizontalKerningForTextUTF32(const std::u32string& text, int& outNumLetters) const override; int* getHorizontalKerningForTextUTF32(const std::u32string& text, int& outNumLetters) const override;
unsigned char* getGlyphBitmap(uint32_t theChar, unsigned char* getGlyphBitmap(char32_t charCode,
int32_t& outWidth, int32_t& outWidth,
int32_t& outHeight, int32_t& outHeight,
Rect& outRect, Rect& outRect,
@ -119,7 +117,7 @@ private:
FontFreeType(bool distanceFieldEnabled = false, float outline = 0); FontFreeType(bool distanceFieldEnabled = false, float outline = 0);
virtual ~FontFreeType(); virtual ~FontFreeType();
bool loadFontFace(std::string_view fontName, float fontSize); bool loadFontFace(std::string_view fontPath, float fontSize);
static bool initFreeType(); static bool initFreeType();
@ -132,7 +130,6 @@ private:
FT_Face _fontFace; FT_Face _fontFace;
std::unique_ptr<FT_StreamRec> _fontStream; std::unique_ptr<FT_StreamRec> _fontStream;
FT_Stroker _stroker; FT_Stroker _stroker;
FT_Encoding _encoding;
std::string _fontName; std::string _fontName;
float _fontSize; float _fontSize;

View File

@ -131,7 +131,7 @@ void log(const char* format, ...)
va_end(args); va_end(args);
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf.c_str()); __android_log_print(ANDROID_LOG_DEBUG, "adxe debug info", "%s", buf.c_str());
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 #elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
buf.push_back('\n'); buf.push_back('\n');

View File

@ -210,7 +210,7 @@ Value& Value::operator=(Value&& other)
switch (other.getTypeFamily()) switch (other.getTypeFamily())
{ {
case Type::INTEGER: case Type::INTEGER:
_field.uintVal = other._field.uintVal; _field.uint64Val = other._field.uint64Val;
break; break;
case Type::FLOAT: case Type::FLOAT:
_field.floatVal = other._field.floatVal; _field.floatVal = other._field.floatVal;

View File

@ -405,7 +405,7 @@ std::string getDataMD5Hash(const Data& data)
return computeDigest(std::string_view{(const char*)data.getBytes(), (size_t)data.getSize()}, "md5"sv); return computeDigest(std::string_view{(const char*)data.getBytes(), (size_t)data.getSize()}, "md5"sv);
} }
CC_DLL std::string computeDigest(std::string_view data, std::string_view algorithm) std::string computeDigest(std::string_view data, std::string_view algorithm)
{ {
const EVP_MD* md = nullptr; const EVP_MD* md = nullptr;
unsigned char mdValue[EVP_MAX_MD_SIZE] = {0}; unsigned char mdValue[EVP_MAX_MD_SIZE] = {0};

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc. Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2021 Bytedance Inc. Copyright (c) 2021-2022 Bytedance Inc.
https://adxeproject.github.io/ https://adxeproject.github.io/
@ -206,7 +206,8 @@ public:
_cancelled = true; _cancelled = true;
if (this->_sockfd != -1) if (this->_sockfd != -1)
{ {
::shutdown(this->_sockfd, SD_BOTH); // may cause curl CURLE_SEND_ERROR(55) or CURLE_RECV_ERROR(56) if(::shutdown(this->_sockfd, SD_BOTH) == -1) // may cause curl CURLE_SEND_ERROR(55) or CURLE_RECV_ERROR(56)
::closesocket(this->_sockfd);
this->_sockfd = -1; this->_sockfd = -1;
} }
} }

View File

@ -35,7 +35,6 @@ THE SOFTWARE.
#include "base/ccMacros.h" #include "base/ccMacros.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
#include "platform/CCSAXParser.h" #include "platform/CCSAXParser.h"
//#include "base/ccUtils.h"
#include "platform/CCPosixFileStream.h" #include "platform/CCPosixFileStream.h"
#ifdef MINIZIP_FROM_SYSTEM #ifdef MINIZIP_FROM_SYSTEM
@ -50,19 +49,19 @@ THE SOFTWARE.
# include "yasio/cxx17/string_view.hpp" # include "yasio/cxx17/string_view.hpp"
#endif #endif
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
# include "tinydir/tinydir.h"
#endif
#include "pugixml/pugixml.hpp" #include "pugixml/pugixml.hpp"
#define DECLARE_GUARD (void)0 #define DECLARE_GUARD (void)0
#if CC_TARGET_PLATFORM != CC_PLATFORM_IOS && \ #if CC_TARGET_PLATFORM != CC_PLATFORM_IOS && \
(CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID || (defined(__NDK_MAJOR__) && __NDK_MAJOR__ >= 22)) (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID || (defined(__NDK_MAJOR__) && __NDK_MAJOR__ >= 22))
# define ADXE_HAVE_STDFS 1
# include <filesystem> # include <filesystem>
namespace stdfs = std::filesystem; namespace stdfs = std::filesystem;
#else
#include "ghc/filesystem.hpp"
namespace stdfs = ghc::filesystem;
#endif
# if defined(_WIN32) # if defined(_WIN32)
inline stdfs::path toFspath(const std::string_view& pathSV) inline stdfs::path toFspath(const std::string_view& pathSV)
{ {
@ -74,10 +73,6 @@ inline stdfs::path toFspath(const std::string_view& pathSV)
return stdfs::path{pathSV}; return stdfs::path{pathSV};
} }
# endif # endif
#else
# include "tinydir/tinydir.h"
# define ADXE_HAVE_STDFS 0
#endif
NS_CC_BEGIN NS_CC_BEGIN
@ -163,7 +158,7 @@ public:
void startElement(void* ctx, const char* name, const char** atts) override void startElement(void* ctx, const char* name, const char** atts) override
{ {
const std::string sName(name); const std::string sName(name);
if (sName == "dict") if (sName == "dict"sv)
{ {
if (_resultType == SAX_RESULT_DICT && _rootDict.empty()) if (_resultType == SAX_RESULT_DICT && _rootDict.empty())
{ {
@ -197,23 +192,23 @@ public:
_stateStack.push(_state); _stateStack.push(_state);
_dictStack.push(_curDict); _dictStack.push(_curDict);
} }
else if (sName == "key") else if (sName == "key"sv)
{ {
_state = SAX_KEY; _state = SAX_KEY;
} }
else if (sName == "integer") else if (sName == "integer"sv)
{ {
_state = SAX_INT; _state = SAX_INT;
} }
else if (sName == "real") else if (sName == "real"sv)
{ {
_state = SAX_REAL; _state = SAX_REAL;
} }
else if (sName == "string") else if (sName == "string"sv)
{ {
_state = SAX_STRING; _state = SAX_STRING;
} }
else if (sName == "array") else if (sName == "array"sv)
{ {
_state = SAX_ARRAY; _state = SAX_ARRAY;
@ -253,7 +248,7 @@ public:
{ {
SAXState curState = _stateStack.empty() ? SAX_DICT : _stateStack.top(); SAXState curState = _stateStack.empty() ? SAX_DICT : _stateStack.top();
const std::string sName((char*)name); const std::string sName((char*)name);
if (sName == "dict") if (sName == "dict"sv)
{ {
_stateStack.pop(); _stateStack.pop();
_dictStack.pop(); _dictStack.pop();
@ -262,7 +257,7 @@ public:
_curDict = _dictStack.top(); _curDict = _dictStack.top();
} }
} }
else if (sName == "array") else if (sName == "array"sv)
{ {
_stateStack.pop(); _stateStack.pop();
_arrayStack.pop(); _arrayStack.pop();
@ -271,7 +266,7 @@ public:
_curArray = _arrayStack.top(); _curArray = _arrayStack.top();
} }
} }
else if (sName == "true") else if (sName == "true"sv)
{ {
if (SAX_ARRAY == curState) if (SAX_ARRAY == curState)
{ {
@ -282,7 +277,7 @@ public:
(*_curDict)[_curKey] = Value(true); (*_curDict)[_curKey] = Value(true);
} }
} }
else if (sName == "false") else if (sName == "false"sv)
{ {
if (SAX_ARRAY == curState) if (SAX_ARRAY == curState)
{ {
@ -293,22 +288,22 @@ public:
(*_curDict)[_curKey] = Value(false); (*_curDict)[_curKey] = Value(false);
} }
} }
else if (sName == "string" || sName == "integer" || sName == "real") else if (sName == "string"sv || sName == "integer"sv || sName == "real"sv)
{ {
if (SAX_ARRAY == curState) if (SAX_ARRAY == curState)
{ {
if (sName == "string") if (sName == "string"sv)
_curArray->push_back(Value(_curValue)); _curArray->push_back(Value(_curValue));
else if (sName == "integer") else if (sName == "integer"sv)
_curArray->push_back(Value(atoi(_curValue.c_str()))); _curArray->push_back(Value(atoi(_curValue.c_str())));
else else
_curArray->push_back(Value(std::atof(_curValue.c_str()))); _curArray->push_back(Value(std::atof(_curValue.c_str())));
} }
else if (SAX_DICT == curState) else if (SAX_DICT == curState)
{ {
if (sName == "string") if (sName == "string"sv)
(*_curDict)[_curKey] = Value(_curValue); (*_curDict)[_curKey] = Value(_curValue);
else if (sName == "integer") else if (sName == "integer"sv)
(*_curDict)[_curKey] = Value(atoi(_curValue.c_str())); (*_curDict)[_curKey] = Value(atoi(_curValue.c_str()));
else else
(*_curDict)[_curKey] = Value(std::atof(_curValue.c_str())); (*_curDict)[_curKey] = Value(std::atof(_curValue.c_str()));
@ -423,25 +418,25 @@ static void generateElementForObject(const Value& value, pugi::xml_node& parent)
// object is String // object is String
if (value.getType() == Value::Type::STRING) if (value.getType() == Value::Type::STRING)
{ {
auto node = parent.append_child("string"); auto node = parent.append_child("string"sv);
node.append_child(pugi::xml_node_type::node_pcdata).set_value(value.asString().c_str()); node.append_child(pugi::xml_node_type::node_pcdata).set_value(value.asString());
} }
// object is integer // object is integer
else if (value.getType() == Value::Type::INTEGER) else if (value.getType() == Value::Type::INTEGER)
{ {
auto node = parent.append_child("integer"); auto node = parent.append_child("integer"sv);
node.append_child(pugi::xml_node_type::node_pcdata).set_value(value.asString().c_str()); node.append_child(pugi::xml_node_type::node_pcdata).set_value(value.asString());
} }
// object is real // object is real
else if (value.getType() == Value::Type::FLOAT || value.getType() == Value::Type::DOUBLE) else if (value.getType() == Value::Type::FLOAT || value.getType() == Value::Type::DOUBLE)
{ {
auto node = parent.append_child("real"); auto node = parent.append_child("real"sv);
node.append_child(pugi::xml_node_type::node_pcdata).set_value(value.asString().c_str()); node.append_child(pugi::xml_node_type::node_pcdata).set_value(value.asString());
} }
// object is bool // object is bool
else if (value.getType() == Value::Type::BOOLEAN) else if (value.getType() == Value::Type::BOOLEAN)
{ {
parent.append_child(value.asString().c_str()); parent.append_child(value.asString());
} }
// object is Array // object is Array
else if (value.getType() == Value::Type::VECTOR) else if (value.getType() == Value::Type::VECTOR)
@ -453,11 +448,11 @@ static void generateElementForObject(const Value& value, pugi::xml_node& parent)
static void generateElementForDict(const ValueMap& dict, pugi::xml_node& parent) static void generateElementForDict(const ValueMap& dict, pugi::xml_node& parent)
{ {
auto dictDS = parent.append_child("dict"); auto dictDS = parent.append_child("dict"sv);
for (const auto& iter : dict) for (const auto& iter : dict)
{ {
auto key = dictDS.append_child("key"); auto key = dictDS.append_child("key"sv);
key.append_child(pugi::xml_node_type::node_pcdata).set_value(iter.first.c_str()); key.append_child(pugi::xml_node_type::node_pcdata).set_value(iter.first);
generateElementForObject(iter.second, dictDS); generateElementForObject(iter.second, dictDS);
} }
@ -465,7 +460,7 @@ static void generateElementForDict(const ValueMap& dict, pugi::xml_node& parent)
static void generateElementForArray(const ValueVector& array, pugi::xml_node& parent) static void generateElementForArray(const ValueVector& array, pugi::xml_node& parent)
{ {
auto arrayDS = parent.append_child("array"); auto arrayDS = parent.append_child("array"sv);
for (const auto& value : array) for (const auto& value : array)
{ {
generateElementForObject(value, arrayDS); generateElementForObject(value, arrayDS);
@ -646,26 +641,6 @@ void FileUtils::writeValueVectorToFile(ValueVector vecData,
std::move(callback), std::move(vecData)); std::move(callback), std::move(vecData));
} }
std::string FileUtils::getNewFilename(std::string_view filename) const
{
std::string newFileName;
DECLARE_GUARD;
// in Lookup Filename dictionary ?
auto iter = _filenameLookupDict.find(filename);
if (iter == _filenameLookupDict.end())
{
newFileName = filename;
}
else
{
newFileName = iter->second.asString();
}
return newFileName;
}
std::string FileUtils::getPathForFilename(std::string_view filename, std::string FileUtils::getPathForFilename(std::string_view filename,
std::string_view resolutionDirectory, std::string_view resolutionDirectory,
std::string_view searchPath) const std::string_view searchPath) const
@ -724,16 +699,13 @@ std::string FileUtils::fullPathForFilename(std::string_view filename) const
return cacheIter->second; return cacheIter->second;
} }
// Get the new file name.
const std::string newFilename(getNewFilename(filename));
std::string fullpath; std::string fullpath;
for (const auto& searchIt : _searchPathArray) for (const auto& searchIt : _searchPathArray)
{ {
for (const auto& resolutionIt : _searchResolutionsOrderArray) for (const auto& resolutionIt : _searchResolutionsOrderArray)
{ {
fullpath = this->getPathForFilename(newFilename, resolutionIt, searchIt); fullpath = this->getPathForFilename(filename, resolutionIt, searchIt);
if (!fullpath.empty()) if (!fullpath.empty())
{ {
@ -781,13 +753,11 @@ std::string FileUtils::fullPathForDirectory(std::string_view dir) const
longdir += "/"; longdir += "/";
} }
const std::string newdirname(getNewFilename(longdir));
for (const auto& searchIt : _searchPathArray) for (const auto& searchIt : _searchPathArray)
{ {
for (const auto& resolutionIt : _searchResolutionsOrderArray) for (const auto& resolutionIt : _searchResolutionsOrderArray)
{ {
fullpath = this->getPathForDirectory(newdirname, resolutionIt, searchIt); fullpath = this->getPathForDirectory(longdir, resolutionIt, searchIt);
if (!fullpath.empty() && isDirectoryExistInternal(fullpath)) if (!fullpath.empty() && isDirectoryExistInternal(fullpath))
{ {
// Using the filename passed in as key. // Using the filename passed in as key.
@ -808,7 +778,7 @@ std::string FileUtils::fullPathForDirectory(std::string_view dir) const
std::string FileUtils::fullPathFromRelativeFile(std::string_view filename, std::string_view relativeFile) const std::string FileUtils::fullPathFromRelativeFile(std::string_view filename, std::string_view relativeFile) const
{ {
return std::string{relativeFile.substr(0, relativeFile.rfind('/') + 1)}.append(getNewFilename(filename)); return std::string{relativeFile.substr(0, relativeFile.rfind('/') + 1)}.append(filename);
} }
void FileUtils::setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder) void FileUtils::setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder)
@ -977,35 +947,6 @@ void FileUtils::addSearchPath(std::string_view searchpath, const bool front)
} }
} }
void FileUtils::setFilenameLookupDictionary(const ValueMap& filenameLookupDict)
{
DECLARE_GUARD;
_fullPathCache.clear();
_fullPathCacheDir.clear();
_filenameLookupDict = filenameLookupDict;
}
void FileUtils::loadFilenameLookupDictionaryFromFile(std::string_view filename)
{
const std::string fullPath = fullPathForFilename(filename);
if (!fullPath.empty())
{
ValueMap dict = getValueMapFromFile(fullPath);
if (!dict.empty())
{
ValueMap& metadata = dict["metadata"].asValueMap();
int version = metadata["version"].asInt();
if (version != 1)
{
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %d. Filename: %s", version,
filename.data());
return;
}
setFilenameLookupDictionary(dict["filenames"].asValueMap());
}
}
}
std::string FileUtils::getFullPathForFilenameWithinDirectory(std::string_view directory, std::string FileUtils::getFullPathForFilenameWithinDirectory(std::string_view directory,
std::string_view filename) const std::string_view filename) const
{ {
@ -1176,10 +1117,9 @@ std::unique_ptr<FileStream> FileUtils::openFileStream(std::string_view filePath,
} }
/* !!!Notes for c++fs /* !!!Notes for c++fs
a. ios: require ios 13.0+ a. ios: require ios 13.0+, currently use ghc as workaround in lower ios 13.0- devices
b. android: require ndk-r22+ b. android: require ndk-r22+
*/ */
#if ADXE_HAVE_STDFS
std::vector<std::string> FileUtils::listFiles(std::string_view dirPath) const std::vector<std::string> FileUtils::listFiles(std::string_view dirPath) const
{ {
const auto fullPath = fullPathForDirectory(dirPath); const auto fullPath = fullPathForDirectory(dirPath);
@ -1206,9 +1146,7 @@ std::vector<std::string> FileUtils::listFiles(std::string_view dirPath) const
std::string pathStr = entry.path().string(); std::string pathStr = entry.path().string();
# endif # endif
if (isDir) if (isDir)
{
pathStr += '/'; pathStr += '/';
}
files.emplace_back(std::move(pathStr)); files.emplace_back(std::move(pathStr));
} }
} }
@ -1240,100 +1178,11 @@ void FileUtils::listFilesRecursively(std::string_view dirPath, std::vector<std::
std::string pathStr = entry.path().string(); std::string pathStr = entry.path().string();
# endif # endif
if (isDir) if (isDir)
{
pathStr += '/'; pathStr += '/';
}
files->emplace_back(std::move(pathStr)); files->emplace_back(std::move(pathStr));
} }
} }
} }
#else
std::vector<std::string> FileUtils::listFiles(std::string_view dirPath) const
{
std::vector<std::string> files;
std::string fullpath = fullPathForDirectory(dirPath);
if (!fullpath.empty() && isDirectoryExist(fullpath))
{
tinydir_dir dir;
std::string fullpathstr = fullpath;
if (tinydir_open(&dir, &fullpathstr[0]) != -1)
{
while (dir.has_next)
{
tinydir_file file;
if (tinydir_readfile(&dir, &file) == -1)
{
// Error getting file
break;
}
std::string filepath = file.path;
if (strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0)
{
if (file.is_dir)
filepath.push_back('/');
files.push_back(std::move(filepath));
}
if (tinydir_next(&dir) == -1)
{
// Error getting next file
break;
}
}
}
tinydir_close(&dir);
}
return files;
}
void FileUtils::listFilesRecursively(std::string_view dirPath, std::vector<std::string>* files) const
{
std::string fullpath = fullPathForDirectory(dirPath);
if (isDirectoryExist(fullpath))
{
tinydir_dir dir;
std::string fullpathstr = fullpath;
if (tinydir_open(&dir, &fullpathstr[0]) != -1)
{
while (dir.has_next)
{
tinydir_file file;
if (tinydir_readfile(&dir, &file) == -1)
{
// Error getting file
break;
}
if (strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0)
{
std::string filepath = file.path;
if (file.is_dir)
{
filepath.push_back('/');
files->push_back(filepath);
listFilesRecursively(filepath, files);
}
else
{
files->push_back(std::move(filepath));
}
}
if (tinydir_next(&dir) == -1)
{
// Error getting next file
break;
}
}
}
tinydir_close(&dir);
}
}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// windows os implement should override in platform specific FileUtiles class // windows os implement should override in platform specific FileUtiles class

View File

@ -293,49 +293,6 @@ public:
*/ */
virtual std::string fullPathForFilename(std::string_view filename) const; virtual std::string fullPathForFilename(std::string_view filename) const;
/**
* Loads the filenameLookup dictionary from the contents of a filename.
*
* @note The plist file name should follow the format below:
*
* @code
* <?xml version="1.0" encoding="UTF-8"?>
* <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
* <plist version="1.0">
* <dict>
* <key>filenames</key>
* <dict>
* <key>sounds/click.wav</key>
* <string>sounds/click.caf</string>
* <key>sounds/endgame.wav</key>
* <string>sounds/endgame.caf</string>
* <key>sounds/gem-0.wav</key>
* <string>sounds/gem-0.caf</string>
* </dict>
* <key>metadata</key>
* <dict>
* <key>version</key>
* <integer>1</integer>
* </dict>
* </dict>
* </plist>
* @endcode
* @param filename The plist file name.
*
@since v2.1
* @js loadFilenameLookup
* @lua loadFilenameLookup
*/
virtual void loadFilenameLookupDictionaryFromFile(std::string_view filename);
/**
* Sets the filenameLookup dictionary.
*
* @param filenameLookupDict The dictionary for replacing filename.
* @since v2.1
*/
virtual void setFilenameLookupDictionary(const ValueMap& filenameLookupDict);
/** /**
* Gets full path from a file name and the path of the relative file. * Gets full path from a file name and the path of the relative file.
* @param filename The file name. * @param filename The file name.
@ -820,15 +777,6 @@ public:
/** Returns the full path cache. */ /** Returns the full path cache. */
const hlookup::string_map<std::string> getFullPathCache() const { return _fullPathCache; } const hlookup::string_map<std::string> getFullPathCache() const { return _fullPathCache; }
/**
* Gets the new filename from the filename lookup dictionary.
* It is possible to have a override names.
* @param filename The original filename.
* @return The new filename after searching in the filename lookup dictionary.
* If the original filename wasn't in the dictionary, it will return the original filename.
*/
virtual std::string getNewFilename(std::string_view filename) const;
/** /**
* Checks whether a file exists without considering search paths and resolution orders. * Checks whether a file exists without considering search paths and resolution orders.
* @param filename The file (with absolute path) to look up for * @param filename The file (with absolute path) to look up for
@ -909,15 +857,6 @@ protected:
*/ */
mutable std::recursive_mutex _mutex; mutable std::recursive_mutex _mutex;
/** Dictionary used to lookup filenames based on a key.
* It is used internally by the following methods:
*
* std::string fullPathForFilename(const char*);
*
* @since v2.1
*/
ValueMap _filenameLookupDict;
/** /**
* The vector contains resolution folders. * The vector contains resolution folders.
* The lower index of the element in this vector, the higher priority for this resolution directory. * The lower index of the element in this vector, the higher priority for this resolution directory.

View File

@ -105,59 +105,6 @@ bool FileUtilsAndroid::init()
return FileUtils::init(); return FileUtils::init();
} }
std::string FileUtilsAndroid::getNewFilename(std::string_view filename) const
{
std::string newFileName = FileUtils::getNewFilename(filename);
// ../xxx do not fix this path
auto pos = newFileName.find("../");
if (pos == std::string::npos || pos == 0)
{
return newFileName;
}
std::vector<std::string> v(3);
v.resize(0);
auto change = false;
size_t size = newFileName.size();
size_t idx = 0;
bool noexit = true;
while (noexit)
{
pos = newFileName.find('/', idx);
std::string tmp;
if (pos == std::string::npos)
{
tmp = newFileName.substr(idx, size - idx);
noexit = false;
}
else
{
tmp = newFileName.substr(idx, pos - idx + 1);
}
auto t = v.size();
if (t > 0 && v[t - 1].compare("../") != 0 && (tmp.compare("../") == 0 || tmp.compare("..") == 0))
{
v.pop_back();
change = true;
}
else
{
v.push_back(tmp);
}
idx = pos + 1;
}
if (change)
{
newFileName.clear();
for (auto& s : v)
{
newFileName.append(s);
}
}
return newFileName;
}
bool FileUtilsAndroid::isFileExistInternal(std::string_view strFilePath) const bool FileUtilsAndroid::isFileExistInternal(std::string_view strFilePath) const
{ {

View File

@ -64,8 +64,6 @@ public:
/* override functions */ /* override functions */
bool init() override; bool init() override;
virtual std::string getNewFilename(std::string_view filename) const override;
virtual FileUtils::Status getContents(std::string_view filename, ResizableBuffer* buffer) const override; virtual FileUtils::Status getContents(std::string_view filename, ResizableBuffer* buffer) const override;
virtual std::string getWritablePath() const override; virtual std::string getWritablePath() const override;

View File

@ -171,8 +171,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
Log.d(TAG, "onResume()"); Log.d(TAG, "onResume()");
paused = false; paused = false;
super.onResume(); super.onResume();
this.hideVirtualButton(); if (this.hasFocus) {
resumeIfHasFocus(); resume();
}
} }
@Override @Override
@ -181,7 +182,15 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
this.hasFocus = hasFocus; this.hasFocus = hasFocus;
resumeIfHasFocus(); if (this.hasFocus && !paused) {
resume();
}
}
private void resume() {
this.hideVirtualButton();
Cocos2dxHelper.onResume();
mGLSurfaceView.onResume();
} }
private void resumeIfHasFocus() { private void resumeIfHasFocus() {
@ -190,9 +199,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
boolean readyToPlay = !isDeviceLocked() && !isDeviceAsleep(); boolean readyToPlay = !isDeviceLocked() && !isDeviceAsleep();
if(hasFocus && readyToPlay) { if(hasFocus && readyToPlay) {
this.hideVirtualButton(); resume();
Cocos2dxHelper.onResume();
mGLSurfaceView.onResume();
} }
} }

View File

@ -96,7 +96,9 @@ class adxetools {
return new VersionComparator().compare(ver1, ver2); return new VersionComparator().compare(ver1, ver2);
} }
static String[] findNDK(String ndkVer){ static String[] findNDK(){
def ndkVer = "23.2.8568313" // ndk-r23c
def allowNewerNdk = false def allowNewerNdk = false
if(ndkVer.endsWith('+')) { if(ndkVer.endsWith('+')) {
allowNewerNdk = true allowNewerNdk = true

View File

@ -1,14 +1,11 @@
// //
// Copyright (c) 2014-2020 @HALX99 - All Rights Reserved // Copyright (c) 2014-2022 @HALX99 - All Rights Reserved
// //
#ifndef _UITEXTFIELD_CPP_H_ #ifndef _UITEXTFIELD_CPP_H_
#define _UITEXTFIELD_CPP_H_ #define _UITEXTFIELD_CPP_H_
#include "UITextFieldEx.h" #include "UITextFieldEx.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
// #include "CCGLView.h"
//#include "NXMacroDefs.h"
//#include "purelib/utils/iconvw.h"
/// cocos2d singleton objects /// cocos2d singleton objects
#define CCDIRECTOR cocos2d::Director::getInstance() #define CCDIRECTOR cocos2d::Director::getInstance()

View File

@ -32132,56 +32132,6 @@ int lua_cocos2dx_FileUtils_getStringFromFile(lua_State* tolua_S)
return 0; return 0;
} }
int lua_cocos2dx_FileUtils_setFilenameLookupDictionary(lua_State* tolua_S)
{
int argc = 0;
cocos2d::FileUtils* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_setFilenameLookupDictionary'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::ValueMap arg0;
ok &= luaval_to_ccvaluemap(tolua_S, 2, &arg0, "cc.FileUtils:setFilenameLookupDictionary");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_setFilenameLookupDictionary'", nullptr);
return 0;
}
cobj->setFilenameLookupDictionary(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:setFilenameLookupDictionary",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_setFilenameLookupDictionary'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_FileUtils_getNativeWritableAbsolutePath(lua_State* tolua_S) int lua_cocos2dx_FileUtils_getNativeWritableAbsolutePath(lua_State* tolua_S)
{ {
int argc = 0; int argc = 0;
@ -32565,56 +32515,6 @@ int lua_cocos2dx_FileUtils_getDefaultResourceRootPath(lua_State* tolua_S)
return 0; return 0;
} }
int lua_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile(lua_State* tolua_S)
{
int argc = 0;
cocos2d::FileUtils* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
std::string_view arg0;
ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "cc.FileUtils:loadFilenameLookupDictionaryFromFile");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile'", nullptr);
return 0;
}
cobj->loadFilenameLookupDictionaryFromFile(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:loadFilenameLookupDictionaryFromFile",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_FileUtils_isPopupNotify(lua_State* tolua_S) int lua_cocos2dx_FileUtils_isPopupNotify(lua_State* tolua_S)
{ {
int argc = 0; int argc = 0;
@ -32859,56 +32759,6 @@ int lua_cocos2dx_FileUtils_getOriginalSearchPaths(lua_State* tolua_S)
return 0; return 0;
} }
int lua_cocos2dx_FileUtils_getNewFilename(lua_State* tolua_S)
{
int argc = 0;
cocos2d::FileUtils* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_getNewFilename'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
std::string_view arg0;
ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "cc.FileUtils:getNewFilename");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_getNewFilename'", nullptr);
return 0;
}
std::string ret = cobj->getNewFilename(arg0);
lua_pushlstring(tolua_S,ret.c_str(),ret.length());
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:getNewFilename",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_getNewFilename'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_FileUtils_listFiles(lua_State* tolua_S) int lua_cocos2dx_FileUtils_listFiles(lua_State* tolua_S)
{ {
int argc = 0; int argc = 0;
@ -34623,20 +34473,17 @@ int lua_register_cocos2dx_FileUtils(lua_State* tolua_S)
tolua_beginmodule(tolua_S,"FileUtils"); tolua_beginmodule(tolua_S,"FileUtils");
tolua_function(tolua_S,"fullPathForFilename",lua_cocos2dx_FileUtils_fullPathForFilename); tolua_function(tolua_S,"fullPathForFilename",lua_cocos2dx_FileUtils_fullPathForFilename);
tolua_function(tolua_S,"getStringFromFile",lua_cocos2dx_FileUtils_getStringFromFile); tolua_function(tolua_S,"getStringFromFile",lua_cocos2dx_FileUtils_getStringFromFile);
tolua_function(tolua_S,"setFilenameLookupDictionary",lua_cocos2dx_FileUtils_setFilenameLookupDictionary);
tolua_function(tolua_S,"getNativeWritableAbsolutePath",lua_cocos2dx_FileUtils_getNativeWritableAbsolutePath); tolua_function(tolua_S,"getNativeWritableAbsolutePath",lua_cocos2dx_FileUtils_getNativeWritableAbsolutePath);
tolua_function(tolua_S,"removeFile",lua_cocos2dx_FileUtils_removeFile); tolua_function(tolua_S,"removeFile",lua_cocos2dx_FileUtils_removeFile);
tolua_function(tolua_S,"listFilesRecursivelyAsync",lua_cocos2dx_FileUtils_listFilesRecursivelyAsync); tolua_function(tolua_S,"listFilesRecursivelyAsync",lua_cocos2dx_FileUtils_listFilesRecursivelyAsync);
tolua_function(tolua_S,"isAbsolutePath",lua_cocos2dx_FileUtils_isAbsolutePath); tolua_function(tolua_S,"isAbsolutePath",lua_cocos2dx_FileUtils_isAbsolutePath);
tolua_function(tolua_S,"renameFile",lua_cocos2dx_FileUtils_renameFile); tolua_function(tolua_S,"renameFile",lua_cocos2dx_FileUtils_renameFile);
tolua_function(tolua_S,"getDefaultResourceRootPath",lua_cocos2dx_FileUtils_getDefaultResourceRootPath); tolua_function(tolua_S,"getDefaultResourceRootPath",lua_cocos2dx_FileUtils_getDefaultResourceRootPath);
tolua_function(tolua_S,"loadFilenameLookup",lua_cocos2dx_FileUtils_loadFilenameLookupDictionaryFromFile);
tolua_function(tolua_S,"isPopupNotify",lua_cocos2dx_FileUtils_isPopupNotify); tolua_function(tolua_S,"isPopupNotify",lua_cocos2dx_FileUtils_isPopupNotify);
tolua_function(tolua_S,"getValueVectorFromFile",lua_cocos2dx_FileUtils_getValueVectorFromFile); tolua_function(tolua_S,"getValueVectorFromFile",lua_cocos2dx_FileUtils_getValueVectorFromFile);
tolua_function(tolua_S,"getSearchPaths",lua_cocos2dx_FileUtils_getSearchPaths); tolua_function(tolua_S,"getSearchPaths",lua_cocos2dx_FileUtils_getSearchPaths);
tolua_function(tolua_S,"writeToFile",lua_cocos2dx_FileUtils_writeToFile); tolua_function(tolua_S,"writeToFile",lua_cocos2dx_FileUtils_writeToFile);
tolua_function(tolua_S,"getOriginalSearchPaths",lua_cocos2dx_FileUtils_getOriginalSearchPaths); tolua_function(tolua_S,"getOriginalSearchPaths",lua_cocos2dx_FileUtils_getOriginalSearchPaths);
tolua_function(tolua_S,"getNewFilename",lua_cocos2dx_FileUtils_getNewFilename);
tolua_function(tolua_S,"listFiles",lua_cocos2dx_FileUtils_listFiles); tolua_function(tolua_S,"listFiles",lua_cocos2dx_FileUtils_listFiles);
tolua_function(tolua_S,"getValueMapFromFile",lua_cocos2dx_FileUtils_getValueMapFromFile); tolua_function(tolua_S,"getValueMapFromFile",lua_cocos2dx_FileUtils_getValueMapFromFile);
tolua_function(tolua_S,"getFileSize",lua_cocos2dx_FileUtils_getFileSize); tolua_function(tolua_S,"getFileSize",lua_cocos2dx_FileUtils_getFileSize);

View File

@ -2325,9 +2325,6 @@ int register_all_cocos2dx(lua_State* tolua_S);

View File

@ -9,7 +9,7 @@ android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
// setup ndk // setup ndk
def ndkInfo = adxetools.findNDK("19.2.5345600+") def ndkInfo = adxetools.findNDK()
ndkVersion = ndkInfo[0] ndkVersion = ndkInfo[0]
if(ndkInfo[1]) { if(ndkInfo[1]) {
ndkPath = ndkInfo[1] ndkPath = ndkInfo[1]

View File

@ -7,7 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.0' classpath 'com.android.tools.build:gradle:7.2.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip

View File

@ -9,7 +9,7 @@ android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
// setup ndk // setup ndk
def ndkInfo = adxetools.findNDK("19.2.5345600+") def ndkInfo = adxetools.findNDK()
ndkVersion = ndkInfo[0] ndkVersion = ndkInfo[0]
if(ndkInfo[1]) { if(ndkInfo[1]) {
ndkPath = ndkInfo[1] ndkPath = ndkInfo[1]

View File

@ -7,7 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.0' classpath 'com.android.tools.build:gradle:7.2.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip

View File

@ -30,7 +30,6 @@ FileUtilsTests::FileUtilsTests()
{ {
ADD_TEST_CASE(TestResolutionDirectories); ADD_TEST_CASE(TestResolutionDirectories);
ADD_TEST_CASE(TestSearchPath); ADD_TEST_CASE(TestSearchPath);
ADD_TEST_CASE(TestFilenameLookup);
ADD_TEST_CASE(TestIsFileExist); ADD_TEST_CASE(TestIsFileExist);
ADD_TEST_CASE(TestIsDirectoryExist); ADD_TEST_CASE(TestIsDirectoryExist);
ADD_TEST_CASE(TestFileFuncs); ADD_TEST_CASE(TestFileFuncs);
@ -208,44 +207,6 @@ std::string TestSearchPath::subtitle() const
return "See the console, can see a orange box and a 'about' picture, except Android"; return "See the console, can see a orange box and a 'about' picture, except Android";
} }
// TestFilenameLookup
void TestFilenameLookup::onEnter()
{
FileUtilsDemo::onEnter();
auto sharedFileUtils = FileUtils::getInstance();
ValueMap dict;
dict["grossini.bmp"] = Value("Images/grossini.png");
dict["grossini.xcf"] = Value("Images/grossini.png");
sharedFileUtils->setFilenameLookupDictionary(dict);
// Instead of loading carlitos.xcf, it will load grossini.png
auto sprite = Sprite::create("grossini.xcf");
this->addChild(sprite);
auto s = Director::getInstance()->getWinSize();
sprite->setPosition(s.width / 2, s.height / 2);
}
void TestFilenameLookup::onExit()
{
FileUtils* sharedFileUtils = FileUtils::getInstance();
// reset filename lookup
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
FileUtilsDemo::onExit();
}
std::string TestFilenameLookup::title() const
{
return "FileUtils: filename lookup";
}
// TestIsFileExist // TestIsFileExist
void TestIsFileExist::onEnter() void TestIsFileExist::onEnter()
@ -276,9 +237,6 @@ void TestIsFileExist::onExit()
FileUtils* sharedFileUtils = FileUtils::getInstance(); FileUtils* sharedFileUtils = FileUtils::getInstance();
// reset filename lookup
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
FileUtilsDemo::onExit(); FileUtilsDemo::onExit();
} }
@ -997,7 +955,6 @@ void TestUnicodePath::onExit()
FileUtils* sharedFileUtils = FileUtils::getInstance(); FileUtils* sharedFileUtils = FileUtils::getInstance();
sharedFileUtils->purgeCachedEntries(); sharedFileUtils->purgeCachedEntries();
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
FileUtilsDemo::onExit(); FileUtilsDemo::onExit();
} }
@ -1037,12 +994,6 @@ void TestIsFileExistAsync::onEnter()
void TestIsFileExistAsync::onExit() void TestIsFileExistAsync::onExit()
{ {
FileUtils* sharedFileUtils = FileUtils::getInstance();
// reset filename lookup
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
FileUtilsDemo::onExit(); FileUtilsDemo::onExit();
} }

View File

@ -64,16 +64,6 @@ private:
std::vector<std::string> _defaultResolutionsOrderArray; std::vector<std::string> _defaultResolutionsOrderArray;
}; };
class TestFilenameLookup : public FileUtilsDemo
{
public:
CREATE_FUNC(TestFilenameLookup);
virtual void onEnter() override;
virtual void onExit() override;
virtual std::string title() const override;
};
class TestIsFileExist : public FileUtilsDemo class TestIsFileExist : public FileUtilsDemo
{ {
public: public:

View File

@ -80,7 +80,6 @@ FontTests::FontTests()
}); });
} }
ADD_TEST_CASE(FontNoReplacementTest); ADD_TEST_CASE(FontNoReplacementTest);
ADD_TEST_CASE(FontReplacementTest);
} }
void FontTest::showFont(std::string_view fontFile) void FontTest::showFont(std::string_view fontFile)
@ -162,7 +161,6 @@ FontNoReplacementTest* FontNoReplacementTest::create()
FontNoReplacementTest::FontNoReplacementTest() FontNoReplacementTest::FontNoReplacementTest()
{ {
_replace = false;
} }
FontNoReplacementTest::~FontNoReplacementTest() FontNoReplacementTest::~FontNoReplacementTest()
@ -176,7 +174,6 @@ FontNoReplacementTest::~FontNoReplacementTest()
FontFreeType::releaseFont("fonts/Abduction.ttf"); FontFreeType::releaseFont("fonts/Abduction.ttf");
FontAtlasCache::unloadFontAtlasTTF("fonts/Schwarzwald.ttf"); FontAtlasCache::unloadFontAtlasTTF("fonts/Schwarzwald.ttf");
FontFreeType::releaseFont("fonts/Schwarzwald.ttf"); FontFreeType::releaseFont("fonts/Schwarzwald.ttf");
FileUtils::getInstance()->setFilenameLookupDictionary(ValueMap());
} }
void FontNoReplacementTest::onEnter() void FontNoReplacementTest::onEnter()
@ -184,17 +181,6 @@ void FontNoReplacementTest::onEnter()
TestCase::onEnter(); TestCase::onEnter();
std::string suffix; std::string suffix;
if (_replace)
{
ValueMap dict{{"fonts/A Damn Mess.ttf", Value("fonts/arial.ttf")},
{"fonts/Abberancy.ttf", Value("fonts/arial.ttf")},
{"fonts/Abduction.ttf", Value("fonts/arial.ttf")},
{"fonts/Schwarzwald.ttf", Value("fonts/arial.ttf")}};
FileUtils::getInstance()->setFilenameLookupDictionary(dict);
suffix = " replaced by arial.ttf";
}
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
auto blockSize = Size(s.width / 3, 200); auto blockSize = Size(s.width / 3, 200);
@ -253,29 +239,3 @@ std::string FontNoReplacementTest::title() const
{ {
return "Font no replacement test"; return "Font no replacement test";
} }
FontReplacementTest* FontReplacementTest::create()
{
auto ret = new FontReplacementTest;
if (ret->init())
{
ret->autorelease();
}
else
{
delete ret;
ret = nullptr;
}
return ret;
}
FontReplacementTest::FontReplacementTest()
{
_replace = true;
}
std::string FontReplacementTest::title() const
{
return "Font replacement test";
}

View File

@ -65,18 +65,6 @@ public:
protected: protected:
FontNoReplacementTest(); FontNoReplacementTest();
bool _replace;
};
class FontReplacementTest : public FontNoReplacementTest
{
public:
static FontReplacementTest* create();
virtual std::string title() const override;
protected:
FontReplacementTest();
}; };
#endif // _FONT_TEST_H_ #endif // _FONT_TEST_H_

View File

@ -9,7 +9,7 @@ android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
// setup ndk // setup ndk
def ndkInfo = adxetools.findNDK("19.2.5345600+") def ndkInfo = adxetools.findNDK()
ndkVersion = ndkInfo[0] ndkVersion = ndkInfo[0]
if(ndkInfo[1]) { if(ndkInfo[1]) {
ndkPath = ndkInfo[1] ndkPath = ndkInfo[1]

View File

@ -7,7 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.0' classpath 'com.android.tools.build:gradle:7.2.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip

View File

@ -9,7 +9,7 @@ android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
// setup ndk // setup ndk
def ndkInfo = adxetools.findNDK("19.2.5345600+") def ndkInfo = adxetools.findNDK()
ndkVersion = ndkInfo[0] ndkVersion = ndkInfo[0]
if(ndkInfo[1]) { if(ndkInfo[1]) {
ndkPath = ndkInfo[1] ndkPath = ndkInfo[1]

View File

@ -7,7 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.0' classpath 'com.android.tools.build:gradle:7.2.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip

View File

@ -9,7 +9,7 @@ android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
// setup ndk // setup ndk
def ndkInfo = adxetools.findNDK("19.2.5345600+") def ndkInfo = adxetools.findNDK()
ndkVersion = ndkInfo[0] ndkVersion = ndkInfo[0]
if(ndkInfo[1]) { if(ndkInfo[1]) {
ndkPath = ndkInfo[1] ndkPath = ndkInfo[1]

View File

@ -7,7 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.0' classpath 'com.android.tools.build:gradle:7.2.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip

View File

@ -78,11 +78,11 @@ function AMTestScene1.create()
local strInfo = "" local strInfo = ""
if assetId == cc.AssetsManagerExStatic.VERSION_ID then if assetId == cc.AssetsManagerExStatic.VERSION_ID then
strInfo = string.format("Version file: %d%%", percent) strInfo = string.format("Version file: %.3f%%", percent)
elseif assetId == cc.AssetsManagerExStatic.MANIFEST_ID then elseif assetId == cc.AssetsManagerExStatic.MANIFEST_ID then
strInfo = string.format("Manifest file: %d%%", percent) strInfo = string.format("Manifest file: %.3f%%", percent)
else else
strInfo = string.format("%d%%", percent) strInfo = string.format("%.3f%%", percent)
end end
progress:setString(strInfo) progress:setString(strInfo)
elseif eventCode == cc.EventAssetsManagerEx.EventCode.ERROR_DOWNLOAD_MANIFEST or elseif eventCode == cc.EventAssetsManagerEx.EventCode.ERROR_DOWNLOAD_MANIFEST or

View File

@ -80,6 +80,11 @@
- Version: git d78c3d2 - Version: git d78c3d2
- License: MIT - License: MIT
## GHC (iOS devices only)
- Upstream: https://github.com/gulrak/filesystem
- Version: 1.5.12
- License: MIT
## jni.hpp ## jni.hpp
- Upstream: https://github.com/mapbox/jni.hpp - Upstream: https://github.com/mapbox/jni.hpp
- Version: v4.0.0 - Version: v4.0.0

6049
thirdparty/ghc/filesystem.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +0,0 @@
Copyright (c) 2013-2016, tinydir authors:
- Cong Xu
- Lautis Sun
- Baudouin Feildel
- Andargor <andargor@yahoo.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,17 +0,0 @@
{
"name": "tinydir",
"description": "Lightweight, portable and easy to integrate C directory and file reader",
"license": "BSD-2-Clause",
"keywords": [
"dir",
"directory",
"file",
"reader",
"filesystem"
],
"src": [
"tinydir.h"
],
"version": "1.2.4",
"repo": "cxong/tinydir"
}

View File

@ -1,831 +0,0 @@
/*
Copyright (c) 2013-2019, tinydir authors:
- Cong Xu
- Lautis Sun
- Baudouin Feildel
- Andargor <andargor@yahoo.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TINYDIR_H
#define TINYDIR_H
#ifdef __cplusplus
extern "C" {
#endif
#if ((defined _UNICODE) && !(defined UNICODE))
#define UNICODE
#endif
#if ((defined UNICODE) && !(defined _UNICODE))
#define _UNICODE
#endif
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <tchar.h>
# pragma warning(push)
# pragma warning (disable : 4996)
#else
# include <dirent.h>
# include <libgen.h>
# include <sys/stat.h>
# include <stddef.h>
#endif
#ifdef __MINGW32__
# include <tchar.h>
#endif
/* types */
/* Windows UNICODE wide character support */
#if defined _MSC_VER || defined __MINGW32__
# define _tinydir_char_t TCHAR
# define TINYDIR_STRING(s) _TEXT(s)
# define _tinydir_strlen _tcslen
# define _tinydir_strcpy _tcscpy
# define _tinydir_strcat _tcscat
# define _tinydir_strcmp _tcscmp
# define _tinydir_strrchr _tcsrchr
# define _tinydir_strncmp _tcsncmp
#else
# define _tinydir_char_t char
# define TINYDIR_STRING(s) s
# define _tinydir_strlen strlen
# define _tinydir_strcpy strcpy
# define _tinydir_strcat strcat
# define _tinydir_strcmp strcmp
# define _tinydir_strrchr strrchr
# define _tinydir_strncmp strncmp
#endif
#if (defined _MSC_VER || defined __MINGW32__)
# include <windows.h>
# define _TINYDIR_PATH_MAX MAX_PATH
#elif defined __linux__
# include <limits.h>
# ifdef PATH_MAX
# define _TINYDIR_PATH_MAX PATH_MAX
# endif
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
# include <sys/param.h>
# if defined(BSD)
# include <limits.h>
# ifdef PATH_MAX
# define _TINYDIR_PATH_MAX PATH_MAX
# endif
# endif
#endif
#ifndef _TINYDIR_PATH_MAX
#define _TINYDIR_PATH_MAX 4096
#endif
#ifdef _MSC_VER
/* extra chars for the "\\*" mask */
# define _TINYDIR_PATH_EXTRA 2
#else
# define _TINYDIR_PATH_EXTRA 0
#endif
#define _TINYDIR_FILENAME_MAX 256
#if (defined _MSC_VER || defined __MINGW32__)
#define _TINYDIR_DRIVE_MAX 3
#endif
#ifdef _MSC_VER
# define _TINYDIR_FUNC static __inline
#elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# define _TINYDIR_FUNC static __inline__
#else
# define _TINYDIR_FUNC static inline
#endif
/* readdir_r usage; define TINYDIR_USE_READDIR_R to use it (if supported) */
#ifdef TINYDIR_USE_READDIR_R
/* readdir_r is a POSIX-only function, and may not be available under various
* environments/settings, e.g. MinGW. Use readdir fallback */
#if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE ||\
_POSIX_SOURCE
# define _TINYDIR_HAS_READDIR_R
#endif
#if _POSIX_C_SOURCE >= 200112L
# define _TINYDIR_HAS_FPATHCONF
# include <unistd.h>
#endif
#if _BSD_SOURCE || _SVID_SOURCE || \
(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
# define _TINYDIR_HAS_DIRFD
# include <sys/types.h>
#endif
#if defined _TINYDIR_HAS_FPATHCONF && defined _TINYDIR_HAS_DIRFD &&\
defined _PC_NAME_MAX
# define _TINYDIR_USE_FPATHCONF
#endif
#if defined __MINGW32__ || !defined _TINYDIR_HAS_READDIR_R ||\
!(defined _TINYDIR_USE_FPATHCONF || defined NAME_MAX)
# define _TINYDIR_USE_READDIR
#endif
/* Use readdir by default */
#else
# define _TINYDIR_USE_READDIR
#endif
/* MINGW32 has two versions of dirent, ASCII and UNICODE*/
#ifndef _MSC_VER
#if (defined __MINGW32__) && (defined _UNICODE)
#define _TINYDIR_DIR _WDIR
#define _tinydir_dirent _wdirent
#define _tinydir_opendir _wopendir
#define _tinydir_readdir _wreaddir
#define _tinydir_closedir _wclosedir
#else
#define _TINYDIR_DIR DIR
#define _tinydir_dirent dirent
#define _tinydir_opendir opendir
#define _tinydir_readdir readdir
#define _tinydir_closedir closedir
#endif
#endif
/* Allow user to use a custom allocator by defining _TINYDIR_MALLOC and _TINYDIR_FREE. */
#if defined(_TINYDIR_MALLOC) && defined(_TINYDIR_FREE)
#elif !defined(_TINYDIR_MALLOC) && !defined(_TINYDIR_FREE)
#else
#error "Either define both alloc and free or none of them!"
#endif
#if !defined(_TINYDIR_MALLOC)
#define _TINYDIR_MALLOC(_size) malloc(_size)
#define _TINYDIR_FREE(_ptr) free(_ptr)
#endif /* !defined(_TINYDIR_MALLOC) */
typedef struct tinydir_file
{
_tinydir_char_t path[_TINYDIR_PATH_MAX];
_tinydir_char_t name[_TINYDIR_FILENAME_MAX];
_tinydir_char_t *extension;
int is_dir;
int is_reg;
#ifndef _MSC_VER
#ifdef __MINGW32__
struct _stat _s;
#else
struct stat _s;
#endif
#endif
} tinydir_file;
typedef struct tinydir_dir
{
_tinydir_char_t path[_TINYDIR_PATH_MAX];
int has_next;
size_t n_files;
tinydir_file *_files;
#ifdef _MSC_VER
HANDLE _h;
WIN32_FIND_DATA _f;
#else
_TINYDIR_DIR *_d;
struct _tinydir_dirent *_e;
#ifndef _TINYDIR_USE_READDIR
struct _tinydir_dirent *_ep;
#endif
#endif
} tinydir_dir;
/* declarations */
_TINYDIR_FUNC
int tinydir_open(tinydir_dir *dir, const _tinydir_char_t *path);
_TINYDIR_FUNC
int tinydir_open_sorted(tinydir_dir *dir, const _tinydir_char_t *path);
_TINYDIR_FUNC
void tinydir_close(tinydir_dir *dir);
_TINYDIR_FUNC
int tinydir_next(tinydir_dir *dir);
_TINYDIR_FUNC
int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file);
_TINYDIR_FUNC
int tinydir_readfile_n(const tinydir_dir *dir, tinydir_file *file, size_t i);
_TINYDIR_FUNC
int tinydir_open_subdir_n(tinydir_dir *dir, size_t i);
_TINYDIR_FUNC
int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path);
_TINYDIR_FUNC
void _tinydir_get_ext(tinydir_file *file);
_TINYDIR_FUNC
int _tinydir_file_cmp(const void *a, const void *b);
#ifndef _MSC_VER
#ifndef _TINYDIR_USE_READDIR
_TINYDIR_FUNC
size_t _tinydir_dirent_buf_size(_TINYDIR_DIR *dirp);
#endif
#endif
/* definitions*/
_TINYDIR_FUNC
int tinydir_open(tinydir_dir *dir, const _tinydir_char_t *path)
{
#ifndef _MSC_VER
#ifndef _TINYDIR_USE_READDIR
int error;
int size; /* using int size */
#endif
#else
_tinydir_char_t path_buf[_TINYDIR_PATH_MAX];
#endif
_tinydir_char_t *pathp;
if (dir == NULL || path == NULL || _tinydir_strlen(path) == 0)
{
errno = EINVAL;
return -1;
}
if (_tinydir_strlen(path) + _TINYDIR_PATH_EXTRA >= _TINYDIR_PATH_MAX)
{
errno = ENAMETOOLONG;
return -1;
}
/* initialise dir */
dir->_files = NULL;
#ifdef _MSC_VER
dir->_h = INVALID_HANDLE_VALUE;
#else
dir->_d = NULL;
#ifndef _TINYDIR_USE_READDIR
dir->_ep = NULL;
#endif
#endif
tinydir_close(dir);
_tinydir_strcpy(dir->path, path);
/* Remove trailing slashes */
pathp = &dir->path[_tinydir_strlen(dir->path) - 1];
while (pathp != dir->path && (*pathp == TINYDIR_STRING('\\') || *pathp == TINYDIR_STRING('/')))
{
*pathp = TINYDIR_STRING('\0');
pathp++;
}
#ifdef _MSC_VER
_tinydir_strcpy(path_buf, dir->path);
_tinydir_strcat(path_buf, TINYDIR_STRING("\\*"));
#if (defined WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP)
dir->_h = FindFirstFileEx(path_buf, FindExInfoStandard, &dir->_f, FindExSearchNameMatch, NULL, 0);
#else
dir->_h = FindFirstFile(path_buf, &dir->_f);
#endif
if (dir->_h == INVALID_HANDLE_VALUE)
{
errno = ENOENT;
#else
dir->_d = _tinydir_opendir(path);
if (dir->_d == NULL)
{
#endif
goto bail;
}
/* read first file */
dir->has_next = 1;
#ifndef _MSC_VER
#ifdef _TINYDIR_USE_READDIR
dir->_e = _tinydir_readdir(dir->_d);
#else
/* allocate dirent buffer for readdir_r */
size = _tinydir_dirent_buf_size(dir->_d); /* conversion to int */
if (size == -1) return -1;
dir->_ep = (struct _tinydir_dirent*)_TINYDIR_MALLOC(size);
if (dir->_ep == NULL) return -1;
error = readdir_r(dir->_d, dir->_ep, &dir->_e);
if (error != 0) return -1;
#endif
if (dir->_e == NULL)
{
dir->has_next = 0;
}
#endif
return 0;
bail:
tinydir_close(dir);
return -1;
}
_TINYDIR_FUNC
int tinydir_open_sorted(tinydir_dir *dir, const _tinydir_char_t *path)
{
/* Count the number of files first, to pre-allocate the files array */
size_t n_files = 0;
if (tinydir_open(dir, path) == -1)
{
return -1;
}
while (dir->has_next)
{
n_files++;
if (tinydir_next(dir) == -1)
{
goto bail;
}
}
tinydir_close(dir);
if (n_files == 0 || tinydir_open(dir, path) == -1)
{
return -1;
}
dir->n_files = 0;
dir->_files = (tinydir_file *)_TINYDIR_MALLOC(sizeof *dir->_files * n_files);
if (dir->_files == NULL)
{
goto bail;
}
while (dir->has_next)
{
tinydir_file *p_file;
dir->n_files++;
p_file = &dir->_files[dir->n_files - 1];
if (tinydir_readfile(dir, p_file) == -1)
{
goto bail;
}
if (tinydir_next(dir) == -1)
{
goto bail;
}
/* Just in case the number of files has changed between the first and
second reads, terminate without writing into unallocated memory */
if (dir->n_files == n_files)
{
break;
}
}
qsort(dir->_files, dir->n_files, sizeof(tinydir_file), _tinydir_file_cmp);
return 0;
bail:
tinydir_close(dir);
return -1;
}
_TINYDIR_FUNC
void tinydir_close(tinydir_dir *dir)
{
if (dir == NULL)
{
return;
}
memset(dir->path, 0, sizeof(dir->path));
dir->has_next = 0;
dir->n_files = 0;
_TINYDIR_FREE(dir->_files);
dir->_files = NULL;
#ifdef _MSC_VER
if (dir->_h != INVALID_HANDLE_VALUE)
{
FindClose(dir->_h);
}
dir->_h = INVALID_HANDLE_VALUE;
#else
if (dir->_d)
{
_tinydir_closedir(dir->_d);
}
dir->_d = NULL;
dir->_e = NULL;
#ifndef _TINYDIR_USE_READDIR
_TINYDIR_FREE(dir->_ep);
dir->_ep = NULL;
#endif
#endif
}
_TINYDIR_FUNC
int tinydir_next(tinydir_dir *dir)
{
if (dir == NULL)
{
errno = EINVAL;
return -1;
}
if (!dir->has_next)
{
errno = ENOENT;
return -1;
}
#ifdef _MSC_VER
if (FindNextFile(dir->_h, &dir->_f) == 0)
#else
#ifdef _TINYDIR_USE_READDIR
dir->_e = _tinydir_readdir(dir->_d);
#else
if (dir->_ep == NULL)
{
return -1;
}
if (readdir_r(dir->_d, dir->_ep, &dir->_e) != 0)
{
return -1;
}
#endif
if (dir->_e == NULL)
#endif
{
dir->has_next = 0;
#ifdef _MSC_VER
if (GetLastError() != ERROR_SUCCESS &&
GetLastError() != ERROR_NO_MORE_FILES)
{
tinydir_close(dir);
errno = EIO;
return -1;
}
#endif
}
return 0;
}
_TINYDIR_FUNC
int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
{
const _tinydir_char_t *filename;
if (dir == NULL || file == NULL)
{
errno = EINVAL;
return -1;
}
#ifdef _MSC_VER
if (dir->_h == INVALID_HANDLE_VALUE)
#else
if (dir->_e == NULL)
#endif
{
errno = ENOENT;
return -1;
}
filename =
#ifdef _MSC_VER
dir->_f.cFileName;
#else
dir->_e->d_name;
#endif
if (_tinydir_strlen(dir->path) +
_tinydir_strlen(filename) + 1 + _TINYDIR_PATH_EXTRA >=
_TINYDIR_PATH_MAX)
{
/* the path for the file will be too long */
errno = ENAMETOOLONG;
return -1;
}
if (_tinydir_strlen(filename) >= _TINYDIR_FILENAME_MAX)
{
errno = ENAMETOOLONG;
return -1;
}
_tinydir_strcpy(file->path, dir->path);
if (_tinydir_strcmp(dir->path, TINYDIR_STRING("/")) != 0)
_tinydir_strcat(file->path, TINYDIR_STRING("/"));
_tinydir_strcpy(file->name, filename);
_tinydir_strcat(file->path, filename);
#ifndef _MSC_VER
#ifdef __MINGW32__
if (_tstat(
#elif (defined _BSD_SOURCE) || (defined _DEFAULT_SOURCE) \
|| ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) \
|| ((defined _POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L))
if (lstat(
#else
if (stat(
#endif
file->path, &file->_s) == -1)
{
return -1;
}
#endif
_tinydir_get_ext(file);
file->is_dir =
#ifdef _MSC_VER
!!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
#else
S_ISDIR(file->_s.st_mode);
#endif
file->is_reg =
#ifdef _MSC_VER
!!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) ||
(
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) &&
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) &&
#ifdef FILE_ATTRIBUTE_INTEGRITY_STREAM
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_INTEGRITY_STREAM) &&
#endif
#ifdef FILE_ATTRIBUTE_NO_SCRUB_DATA
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NO_SCRUB_DATA) &&
#endif
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) &&
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY));
#else
S_ISREG(file->_s.st_mode);
#endif
return 0;
}
_TINYDIR_FUNC
int tinydir_readfile_n(const tinydir_dir *dir, tinydir_file *file, size_t i)
{
if (dir == NULL || file == NULL)
{
errno = EINVAL;
return -1;
}
if (i >= dir->n_files)
{
errno = ENOENT;
return -1;
}
memcpy(file, &dir->_files[i], sizeof(tinydir_file));
_tinydir_get_ext(file);
return 0;
}
_TINYDIR_FUNC
int tinydir_open_subdir_n(tinydir_dir *dir, size_t i)
{
_tinydir_char_t path[_TINYDIR_PATH_MAX];
if (dir == NULL)
{
errno = EINVAL;
return -1;
}
if (i >= dir->n_files || !dir->_files[i].is_dir)
{
errno = ENOENT;
return -1;
}
_tinydir_strcpy(path, dir->_files[i].path);
tinydir_close(dir);
if (tinydir_open_sorted(dir, path) == -1)
{
return -1;
}
return 0;
}
/* Open a single file given its path */
_TINYDIR_FUNC
int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
{
tinydir_dir dir;
int result = 0;
int found = 0;
_tinydir_char_t dir_name_buf[_TINYDIR_PATH_MAX];
_tinydir_char_t file_name_buf[_TINYDIR_FILENAME_MAX];
_tinydir_char_t *dir_name;
_tinydir_char_t *base_name;
#if (defined _MSC_VER || defined __MINGW32__)
_tinydir_char_t drive_buf[_TINYDIR_PATH_MAX];
_tinydir_char_t ext_buf[_TINYDIR_FILENAME_MAX];
#endif
if (file == NULL || path == NULL || _tinydir_strlen(path) == 0)
{
errno = EINVAL;
return -1;
}
if (_tinydir_strlen(path) + _TINYDIR_PATH_EXTRA >= _TINYDIR_PATH_MAX)
{
errno = ENAMETOOLONG;
return -1;
}
/* Get the parent path */
#if (defined _MSC_VER || defined __MINGW32__)
#if ((defined _MSC_VER) && (_MSC_VER >= 1400))
errno = _tsplitpath_s(
path,
drive_buf, _TINYDIR_DRIVE_MAX,
dir_name_buf, _TINYDIR_FILENAME_MAX,
file_name_buf, _TINYDIR_FILENAME_MAX,
ext_buf, _TINYDIR_FILENAME_MAX);
#else
_tsplitpath(
path,
drive_buf,
dir_name_buf,
file_name_buf,
ext_buf);
#endif
if (errno)
{
return -1;
}
/* _splitpath_s not work fine with only filename and widechar support */
#ifdef _UNICODE
if (drive_buf[0] == L'\xFEFE')
drive_buf[0] = '\0';
if (dir_name_buf[0] == L'\xFEFE')
dir_name_buf[0] = '\0';
#endif
/* Emulate the behavior of dirname by returning "." for dir name if it's
empty */
if (drive_buf[0] == '\0' && dir_name_buf[0] == '\0')
{
_tinydir_strcpy(dir_name_buf, TINYDIR_STRING("."));
}
/* Concatenate the drive letter and dir name to form full dir name */
_tinydir_strcat(drive_buf, dir_name_buf);
dir_name = drive_buf;
/* Concatenate the file name and extension to form base name */
_tinydir_strcat(file_name_buf, ext_buf);
base_name = file_name_buf;
#else
_tinydir_strcpy(dir_name_buf, path);
dir_name = dirname(dir_name_buf);
_tinydir_strcpy(file_name_buf, path);
base_name = basename(file_name_buf);
#endif
/* Special case: if the path is a root dir, open the parent dir as the file */
#if (defined _MSC_VER || defined __MINGW32__)
if (_tinydir_strlen(base_name) == 0)
#else
if ((_tinydir_strcmp(base_name, TINYDIR_STRING("/"))) == 0)
#endif
{
memset(file, 0, sizeof * file);
file->is_dir = 1;
file->is_reg = 0;
_tinydir_strcpy(file->path, dir_name);
file->extension = file->path + _tinydir_strlen(file->path);
return 0;
}
/* Open the parent directory */
if (tinydir_open(&dir, dir_name) == -1)
{
return -1;
}
/* Read through the parent directory and look for the file */
while (dir.has_next)
{
if (tinydir_readfile(&dir, file) == -1)
{
result = -1;
goto bail;
}
if (_tinydir_strcmp(file->name, base_name) == 0)
{
/* File found */
found = 1;
break;
}
tinydir_next(&dir);
}
if (!found)
{
result = -1;
errno = ENOENT;
}
bail:
tinydir_close(&dir);
return result;
}
_TINYDIR_FUNC
void _tinydir_get_ext(tinydir_file *file)
{
_tinydir_char_t *period = _tinydir_strrchr(file->name, TINYDIR_STRING('.'));
if (period == NULL)
{
file->extension = &(file->name[_tinydir_strlen(file->name)]);
}
else
{
file->extension = period + 1;
}
}
_TINYDIR_FUNC
int _tinydir_file_cmp(const void *a, const void *b)
{
const tinydir_file *fa = (const tinydir_file *)a;
const tinydir_file *fb = (const tinydir_file *)b;
if (fa->is_dir != fb->is_dir)
{
return -(fa->is_dir - fb->is_dir);
}
return _tinydir_strncmp(fa->name, fb->name, _TINYDIR_FILENAME_MAX);
}
#ifndef _MSC_VER
#ifndef _TINYDIR_USE_READDIR
/*
The following authored by Ben Hutchings <ben@decadent.org.uk>
from https://womble.decadent.org.uk/readdir_r-advisory.html
*/
/* Calculate the required buffer size (in bytes) for directory *
* entries read from the given directory handle. Return -1 if this *
* this cannot be done. *
* *
* This code does not trust values of NAME_MAX that are less than *
* 255, since some systems (including at least HP-UX) incorrectly *
* define it to be a smaller value. */
_TINYDIR_FUNC
size_t _tinydir_dirent_buf_size(_TINYDIR_DIR *dirp)
{
long name_max;
size_t name_end;
/* parameter may be unused */
(void)dirp;
#if defined _TINYDIR_USE_FPATHCONF
name_max = fpathconf(dirfd(dirp), _PC_NAME_MAX);
if (name_max == -1)
#if defined(NAME_MAX)
name_max = (NAME_MAX > 255) ? NAME_MAX : 255;
#else
return (size_t)(-1);
#endif
#elif defined(NAME_MAX)
name_max = (NAME_MAX > 255) ? NAME_MAX : 255;
#else
#error "buffer size for readdir_r cannot be determined"
#endif
name_end = (size_t)offsetof(struct _tinydir_dirent, d_name) + name_max + 1;
return (name_end > sizeof(struct _tinydir_dirent) ?
name_end : sizeof(struct _tinydir_dirent));
}
#endif
#endif
#ifdef __cplusplus
}
#endif
# if defined (_MSC_VER)
# pragma warning(pop)
# endif
#endif

View File

@ -28,9 +28,9 @@ COCOS2D_X = os.path.abspath(os.path.join(DIR_PATH, "../.."))
ROOT_DIR = os.path.abspath(os.path.join(COCOS2D_X, "..")) ROOT_DIR = os.path.abspath(os.path.join(COCOS2D_X, ".."))
# cmdlinetools download page: https://developer.android.com/studio#command-tools # cmdlinetools download page: https://developer.android.com/studio#command-tools
# commandlinetools-linux-8092744_latest.zip # commandlinetools-win-8512546_latest.zip
CMDLINETOOLS_REV = "8092744" CMDLINETOOLS_REV = "8512546"
NDK_VER = "19.2.5345600" # "r19c" NDK_VER = "23.2.8568313" # "r23c LTS"
# ANDROID_NDK = os.path.join(ROOT_DIR, "android-ndk-" + NDK_VER) # ANDROID_NDK = os.path.join(ROOT_DIR, "android-ndk-" + NDK_VER)
ANDROID_SDK = os.path.join(ROOT_DIR, "android-sdk") ANDROID_SDK = os.path.join(ROOT_DIR, "android-sdk")