Skip to content

Commit 4930d15

Browse files
committed
Merge commit '5dd10214bfb878bda131e2c988ea2bd2eb2829a1' into scgamex-v3
* commit '5dd10214bfb878bda131e2c988ea2bd2eb2829a1': Changed shader data types mediump to highp to remove possible sprite joggling on some Android phones. (cocos2d#19633) remove redundant user-defined copy constructor and destructor, (cocos2d#19636) move parseIntegerList to a free function in ccUtils, add few testcases (cocos2d#19634) update binding generator (cocos2d#19625) rewrite parseIntegerList with better performance (cocos2d#19619) prefer delegate constructor over new(this) (cocos2d#19613) fix outdated documentation [ci skip] (cocos2d#19618) Optimize calls to std::string::find() and friends when the needle passed is a single character string literal. The character literal overload is more efficient. (cocos2d#19614) add build test option for cmake (cocos2d#19608) End the NS_CC properly. (cocos2d#19603) fix static token array in headfile (cocos2d#19164) fix base/CMakeLists.txt (cocos2d#19575) Fix bug: can't play video in obbfile. (cocos2d#19476) use CC_SAFE_DELETE_ARRAY instead of CC_SAFE_DELETE (cocos2d#19580) Update CCArmature.cpp (cocos2d#19579) revert threads (cocos2d#19572) [windows] use PostMessage to replace SendMessage (cocos2d#19569) [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (cocos2d#19563) Only send the ON_PERCENTAGE_CHANGED if and only if the percentage value has actually changed. (cocos2d#19556) # Conflicts: # cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_ui_auto_api.js # cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.cpp # cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.hpp # cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp # cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp # cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp # cocos/scripting/lua-bindings/auto/api/Slider.lua # cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp # cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp # cocos/scripting/lua-bindings/manual/Cocos2dxLuaLoader.cpp # cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp # extensions/Particle3D/PU/CCPUParticleSystem3D.cpp # extensions/Particle3D/PU/CCPURendererTranslator.cpp # extensions/Particle3D/PU/CCPUScriptTranslator.cpp # extensions/Particle3D/PU/CCPUScriptTranslator.h
2 parents 3fd04f3 + 5dd1021 commit 4930d15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+191
-183
lines changed

CMakeLists.txt

+10-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ AssureOutOfSourceBuilds()
4141
# works before build libcocos2d
4242
include(CocosBuildSet)
4343

44+
# build options
45+
option(BUILD_TESTS "Build tests" ON)
46+
4447
# default tests include lua, js test project, so we set those option on to build libs
4548
set(BUILD_LUA_LIBS ON)
4649
set(BUILD_JS_LIBS ON)
@@ -50,8 +53,10 @@ add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
5053
# prevent tests project to build "cocos2d-x/cocos" again
5154
set(BUILD_ENGINE_DONE ON)
5255
# add engine all tests project
53-
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
54-
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
55-
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
56-
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
57-
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
56+
if (BUILD_TESTS)
57+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
58+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
59+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
60+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
61+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
62+
endif()

cocos/2d/CCFontAtlas.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ std::string FontAtlas::getFontName() const
488488
{
489489
std::string fontName = _fontFreeType ? _fontFreeType->getFontName() : "";
490490
if(fontName.empty()) return fontName;
491-
auto idx = fontName.rfind("/");
491+
auto idx = fontName.rfind('/');
492492
if (idx != std::string::npos) { return fontName.substr(idx + 1); }
493-
idx = fontName.rfind("\\");
493+
idx = fontName.rfind('\\');
494494
if (idx != std::string::npos) { return fontName.substr(idx + 1); }
495495
return fontName;
496496
}

cocos/2d/CCFontCharMap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ NS_CC_BEGIN
3535
FontCharMap * FontCharMap::create(const std::string& plistFile)
3636
{
3737
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(plistFile);
38-
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
38+
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of('/'))+"/";
3939

4040
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr);
4141

cocos/2d/CCLabelAtlas.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& fnt
105105
bool LabelAtlas::initWithString(const std::string& theString, const std::string& fntFile)
106106
{
107107
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(fntFile);
108-
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
108+
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of('/'))+"/";
109109

110110
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr);
111111

cocos/2d/CCSprite.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class CC_DLL Sprite : public Node, public TextureProtocol
184184
* A SpriteFrame will be fetched from the SpriteFrameCache by spriteFrameName param.
185185
* If the SpriteFrame doesn't exist it will raise an exception.
186186
*
187-
* @param spriteFrameName A null terminated string which indicates the sprite frame name.
187+
* @param spriteFrameName The name of sprite frame.
188188
* @return An autoreleased sprite object.
189189
*/
190190
static Sprite* createWithSpriteFrameName(const std::string& spriteFrameName);

cocos/2d/CCSpriteFrameCache.cpp

+7-29
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ THE SOFTWARE.
3939
#include "base/CCNS.h"
4040
#include "base/ccMacros.h"
4141
#include "base/ccUTF8.h"
42+
#include "base/ccUtils.h"
4243
#include "base/CCDirector.h"
4344
#include "renderer/CCTexture2D.h"
4445
#include "renderer/CCTextureCache.h"
@@ -78,27 +79,6 @@ SpriteFrameCache::~SpriteFrameCache()
7879
{
7980
}
8081

81-
void SpriteFrameCache::parseIntegerList(const std::string &string, std::vector<int> &res)
82-
{
83-
std::string delim(" ");
84-
85-
size_t n = std::count(string.begin(), string.end(), ' ');
86-
res.resize(n+1);
87-
88-
size_t start = 0U;
89-
size_t end = string.find(delim);
90-
91-
int i=0;
92-
while (end != std::string::npos)
93-
{
94-
res[i++] = atoi(string.substr(start, end - start).c_str());
95-
start = end + delim.length();
96-
end = string.find(delim, start);
97-
}
98-
99-
res[i] = atoi(string.substr(start, end).c_str());
100-
}
101-
10282
void SpriteFrameCache::initializePolygonInfo(const Size &textureSize,
10383
const Size &spriteSize,
10484
const std::vector<int> &vertices,
@@ -266,12 +246,10 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
266246

267247
if(frameDict.find("vertices") != frameDict.end())
268248
{
269-
std::vector<int> vertices;
270-
parseIntegerList(frameDict["vertices"].asString(), vertices);
271-
std::vector<int> verticesUV;
272-
parseIntegerList(frameDict["verticesUV"].asString(), verticesUV);
273-
std::vector<int> indices;
274-
parseIntegerList(frameDict["triangles"].asString(), indices);
249+
using cocos2d::utils::parseIntegerList;
250+
std::vector<int> vertices = parseIntegerList(frameDict["vertices"].asString());
251+
std::vector<int> verticesUV = parseIntegerList(frameDict["verticesUV"].asString());
252+
std::vector<int> indices = parseIntegerList(frameDict["triangles"].asString());
275253

276254
PolygonInfo info;
277255
initializePolygonInfo(textureSize, spriteSourceSize, vertices, verticesUV, indices, info);
@@ -414,7 +392,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist)
414392
texturePath = plist;
415393

416394
// remove .xxx
417-
size_t startPos = texturePath.find_last_of(".");
395+
size_t startPos = texturePath.find_last_of('.');
418396
texturePath = texturePath.erase(startPos);
419397

420398
// append .png
@@ -716,7 +694,7 @@ bool SpriteFrameCache::reloadTexture(const std::string& plist)
716694
texturePath = plist;
717695

718696
// remove .xxx
719-
size_t startPos = texturePath.find_last_of(".");
697+
size_t startPos = texturePath.find_last_of('.');
720698
texturePath = texturePath.erase(startPos);
721699

722700
// append .png

cocos/2d/CCSpriteFrameCache.h

-3
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,6 @@ class CC_DLL SpriteFrameCache : public Ref
304304
*/
305305
void removeSpriteFramesFromDictionary(ValueMap& dictionary);
306306

307-
/** Parses list of space-separated integers */
308-
void parseIntegerList(const std::string &string, std::vector<int> &res);
309-
310307
/** Configures PolygonInfo class with the passed sizes + triangles */
311308
void initializePolygonInfo(const Size &textureSize,
312309
const Size &spriteSize,

cocos/2d/CCTMXXMLParser.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
298298
_externalTilesetFilename = externalTilesetFilename;
299299

300300
// Tileset file will be relative to the map file. So we need to convert it to an absolute path
301-
if (_TMXFileName.find_last_of("/") != string::npos)
301+
if (_TMXFileName.find_last_of('/') != string::npos)
302302
{
303-
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
303+
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of('/') + 1);
304304
externalTilesetFilename = dir + externalTilesetFilename;
305305
}
306306
else
@@ -434,12 +434,12 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
434434

435435
if (!_externalTilesetFullPath.empty())
436436
{
437-
string dir = _externalTilesetFullPath.substr(0, _externalTilesetFullPath.find_last_of("/") + 1);
437+
string dir = _externalTilesetFullPath.substr(0, _externalTilesetFullPath.find_last_of('/') + 1);
438438
tileset->_sourceImage = dir + imagename;
439439
}
440-
else if (_TMXFileName.find_last_of("/") != string::npos)
440+
else if (_TMXFileName.find_last_of('/') != string::npos)
441441
{
442-
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
442+
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of('/') + 1);
443443
tileset->_sourceImage = dir + imagename;
444444
}
445445
else

cocos/3d/CCAABB.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ AABB::AABB(const Vec3& min, const Vec3& max)
3737
set(min, max);
3838
}
3939

40-
AABB::AABB(const AABB& box)
41-
{
42-
set(box._min,box._max);
43-
}
44-
4540
Vec3 AABB::getCenter()
4641
{
4742
Vec3 center;

cocos/3d/CCAABB.h

-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class CC_DLL AABB
5555
*/
5656
AABB(const Vec3& min, const Vec3& max);
5757

58-
/**
59-
* Constructor.
60-
*/
61-
AABB(const AABB& box);
62-
6358
/**
6459
* Gets the center point of the bounding box.
6560
*/

cocos/3d/CCBundle3D.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
225225
int i = 0;
226226
char str[20];
227227
std::string dir = "";
228-
auto last = fullPath.rfind("/");
228+
auto last = fullPath.rfind('/');
229229
if (last != std::string::npos)
230230
dir = fullPath.substr(0, last + 1);
231231
for (auto& material : materials) {

cocos/base/CCConsole.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ namespace {
123123
if (Director::getInstance()->getOpenGLView())
124124
{
125125
HWND hwnd = Director::getInstance()->getOpenGLView()->getWin32Window();
126-
SendMessage(hwnd,
126+
PostMessage(hwnd,
127127
WM_COPYDATA,
128128
(WPARAM)(HWND)hwnd,
129129
(LPARAM)(LPVOID)&myCDS);
@@ -585,7 +585,7 @@ void Console::Command::commandGeneric(int fd, const std::string& args)
585585
{
586586
// The first argument (including the empty)
587587
std::string key(args);
588-
auto pos = args.find(" ");
588+
auto pos = args.find(' ');
589589
if ((pos != std::string::npos) && (0 < pos)) {
590590
key = args.substr(0, pos);
591591
}

cocos/base/CCProperties.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1117,12 +1117,12 @@ void calculateNamespacePath(const std::string& urlString, std::string& fileStrin
11171117
{
11181118
// If the url references a specific namespace within the file,
11191119
// calculate the full namespace path to the final namespace.
1120-
size_t loc = urlString.rfind("#");
1120+
size_t loc = urlString.rfind('#');
11211121
if (loc != std::string::npos)
11221122
{
11231123
fileString = urlString.substr(0, loc);
11241124
std::string namespacePathString = urlString.substr(loc + 1);
1125-
while ((loc = namespacePathString.find("/")) != std::string::npos)
1125+
while ((loc = namespacePathString.find('/')) != std::string::npos)
11261126
{
11271127
namespacePath.push_back(namespacePathString.substr(0, loc));
11281128
namespacePathString = namespacePathString.substr(loc + 1);

cocos/base/CCProtocols.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class CC_DLL LabelProtocol
236236
/**
237237
* Sets a new label using a string
238238
*
239-
* @param label A null terminated string
239+
* @param label The name of the new label.
240240
* @js NA
241241
* @lua NA
242242
*/

cocos/base/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ elseif(ANDROID)
1010
base/CCUserDefault-android.cpp
1111
base/CCController-android.cpp
1212
)
13-
elseif(LINUX)
13+
elseif(LINUX OR WINDOWS)
1414
set(COCOS_BASE_SPECIFIC_SRC
1515
base/CCController-linux-win32.cpp
1616
)

cocos/base/ZipUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ std::vector<std::string> ZipFile::listFiles(const std::string &pathname) const
627627
if(filename.substr(0, dirname.length()) == dirname)
628628
{
629629
std::string suffix = filename.substr(dirname.length());
630-
auto pos = suffix.find("/");
630+
auto pos = suffix.find('/');
631631
if (pos == std::string::npos)
632632
{
633633
fileSet.insert(suffix);

cocos/base/ccUtils.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ THE SOFTWARE.
3434
#include "base/CCAsyncTaskPool.h"
3535
#include "base/CCEventDispatcher.h"
3636
#include "base/base64.h"
37+
#include "base/ccUTF8.h"
3738
#include "renderer/CCCustomCommand.h"
3839
#include "renderer/CCRenderer.h"
3940
#include "renderer/CCTextureCache.h"
@@ -124,7 +125,7 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
124125
}
125126
else
126127
{
127-
CCASSERT(filename.find("/") == std::string::npos, "The existence of a relative path is not guaranteed!");
128+
CCASSERT(filename.find('/') == std::string::npos, "The existence of a relative path is not guaranteed!");
128129
outputFile = FileUtils::getInstance()->getWritablePath() + filename;
129130
}
130131

@@ -526,6 +527,24 @@ LanguageType getLanguageTypeByISO2(const char* code)
526527
return ret;
527528
}
528529

530+
std::vector<int> parseIntegerList(const std::string &intsString) {
531+
std::vector<int> result;
532+
533+
const char *cStr = intsString.c_str();
534+
char *endptr;
535+
536+
for (long int i = strtol(cStr, &endptr, 10); endptr != cStr; i = strtol(cStr, &endptr, 10)) {
537+
if (errno == ERANGE) {
538+
errno = 0;
539+
CCLOGWARN("%s contains out of range integers", intsString.c_str());
540+
}
541+
result.push_back(static_cast<int>(i));
542+
cStr= endptr;
543+
}
544+
545+
return result;
546+
}
547+
529548
}
530549

531550
NS_CC_END

cocos/base/ccUtils.h

+8
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ namespace utils
188188
* @lua NA
189189
*/
190190
CC_DLL LanguageType getLanguageTypeByISO2(const char* code);
191+
192+
/**
193+
@brief Parses a list of space-separated integers.
194+
@return Vector of ints.
195+
* @js NA
196+
* @lua NA
197+
*/
198+
CC_DLL std::vector<int> parseIntegerList(const std::string &intsString);
191199
}
192200

193201
NS_CC_END

cocos/editor-support/cocosbuilder/CCBReader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ bool CCBReader::readSequences()
951951

952952
std::string CCBReader::lastPathComponent(const char* pPath) {
953953
std::string path(pPath);
954-
size_t slashPos = path.find_last_of("/");
954+
size_t slashPos = path.find_last_of('/');
955955
if(slashPos != std::string::npos) {
956956
return path.substr(slashPos + 1, path.length() - slashPos);
957957
}
@@ -960,7 +960,7 @@ std::string CCBReader::lastPathComponent(const char* pPath) {
960960

961961
std::string CCBReader::deletePathExtension(const char* pPath) {
962962
std::string path(pPath);
963-
size_t dotPos = path.find_last_of(".");
963+
size_t dotPos = path.find_last_of('.');
964964
if(dotPos != std::string::npos) {
965965
return path.substr(0, dotPos);
966966
}

cocos/editor-support/cocostudio/CCActionManagerEx.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
6363
{
6464
std::string path = jsonName;
6565
this->_studioVersionNumber = version;
66-
ssize_t pos = path.find_last_of("/");
66+
ssize_t pos = path.find_last_of('/');
6767
std::string fileName = path.substr(pos+1,path.length());
6868
cocos2d::Vector<ActionObject*> actionList;
6969
int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist");
@@ -83,7 +83,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
8383
stExpCocoNode* pCocoNode)
8484
{
8585
std::string path = file;
86-
ssize_t pos = path.find_last_of("/");
86+
ssize_t pos = path.find_last_of('/');
8787
std::string fileName = path.substr(pos+1,path.length());
8888
cocos2d::Vector<ActionObject*> actionList;
8989

@@ -116,7 +116,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
116116
ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
117117
{
118118
std::string path = jsonName;
119-
ssize_t pos = path.find_last_of("/");
119+
ssize_t pos = path.find_last_of('/');
120120
std::string fileName = path.substr(pos+1,path.length());
121121
auto iterator = _actionDic.find(fileName);
122122
if (iterator == _actionDic.end())

cocos/editor-support/cocostudio/CCArmature.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ void Armature::setBody(cpBody *body)
717717
{
718718
detector->setBody(body);
719719
}
720-
});
720+
}
721721
}
722722
}
723723
}

0 commit comments

Comments
 (0)