Skip to content

Commit

Permalink
Merge commit '5dd10214bfb878bda131e2c988ea2bd2eb2829a1' into scgamex-v3
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stevetranby committed Apr 26, 2019
2 parents 3fd04f3 + 5dd1021 commit 4930d15
Show file tree
Hide file tree
Showing 48 changed files with 191 additions and 183 deletions.
15 changes: 10 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ AssureOutOfSourceBuilds()
# works before build libcocos2d
include(CocosBuildSet)

# build options
option(BUILD_TESTS "Build tests" ON)

# default tests include lua, js test project, so we set those option on to build libs
set(BUILD_LUA_LIBS ON)
set(BUILD_JS_LIBS ON)
Expand All @@ -50,8 +53,10 @@ add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
# prevent tests project to build "cocos2d-x/cocos" again
set(BUILD_ENGINE_DONE ON)
# add engine all tests project
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
if (BUILD_TESTS)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
endif()
4 changes: 2 additions & 2 deletions cocos/2d/CCFontAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ std::string FontAtlas::getFontName() const
{
std::string fontName = _fontFreeType ? _fontFreeType->getFontName() : "";
if(fontName.empty()) return fontName;
auto idx = fontName.rfind("/");
auto idx = fontName.rfind('/');
if (idx != std::string::npos) { return fontName.substr(idx + 1); }
idx = fontName.rfind("\\");
idx = fontName.rfind('\\');
if (idx != std::string::npos) { return fontName.substr(idx + 1); }
return fontName;
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCFontCharMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ NS_CC_BEGIN
FontCharMap * FontCharMap::create(const std::string& plistFile)
{
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(plistFile);
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of('/'))+"/";

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

Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCLabelAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& fnt
bool LabelAtlas::initWithString(const std::string& theString, const std::string& fntFile)
{
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(fntFile);
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of('/'))+"/";

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

Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CC_DLL Sprite : public Node, public TextureProtocol
* A SpriteFrame will be fetched from the SpriteFrameCache by spriteFrameName param.
* If the SpriteFrame doesn't exist it will raise an exception.
*
* @param spriteFrameName A null terminated string which indicates the sprite frame name.
* @param spriteFrameName The name of sprite frame.
* @return An autoreleased sprite object.
*/
static Sprite* createWithSpriteFrameName(const std::string& spriteFrameName);
Expand Down
36 changes: 7 additions & 29 deletions cocos/2d/CCSpriteFrameCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ THE SOFTWARE.
#include "base/CCNS.h"
#include "base/ccMacros.h"
#include "base/ccUTF8.h"
#include "base/ccUtils.h"
#include "base/CCDirector.h"
#include "renderer/CCTexture2D.h"
#include "renderer/CCTextureCache.h"
Expand Down Expand Up @@ -78,27 +79,6 @@ SpriteFrameCache::~SpriteFrameCache()
{
}

void SpriteFrameCache::parseIntegerList(const std::string &string, std::vector<int> &res)
{
std::string delim(" ");

size_t n = std::count(string.begin(), string.end(), ' ');
res.resize(n+1);

size_t start = 0U;
size_t end = string.find(delim);

int i=0;
while (end != std::string::npos)
{
res[i++] = atoi(string.substr(start, end - start).c_str());
start = end + delim.length();
end = string.find(delim, start);
}

res[i] = atoi(string.substr(start, end).c_str());
}

void SpriteFrameCache::initializePolygonInfo(const Size &textureSize,
const Size &spriteSize,
const std::vector<int> &vertices,
Expand Down Expand Up @@ -266,12 +246,10 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu

if(frameDict.find("vertices") != frameDict.end())
{
std::vector<int> vertices;
parseIntegerList(frameDict["vertices"].asString(), vertices);
std::vector<int> verticesUV;
parseIntegerList(frameDict["verticesUV"].asString(), verticesUV);
std::vector<int> indices;
parseIntegerList(frameDict["triangles"].asString(), indices);
using cocos2d::utils::parseIntegerList;
std::vector<int> vertices = parseIntegerList(frameDict["vertices"].asString());
std::vector<int> verticesUV = parseIntegerList(frameDict["verticesUV"].asString());
std::vector<int> indices = parseIntegerList(frameDict["triangles"].asString());

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

// remove .xxx
size_t startPos = texturePath.find_last_of(".");
size_t startPos = texturePath.find_last_of('.');
texturePath = texturePath.erase(startPos);

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

// remove .xxx
size_t startPos = texturePath.find_last_of(".");
size_t startPos = texturePath.find_last_of('.');
texturePath = texturePath.erase(startPos);

// append .png
Expand Down
3 changes: 0 additions & 3 deletions cocos/2d/CCSpriteFrameCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ class CC_DLL SpriteFrameCache : public Ref
*/
void removeSpriteFramesFromDictionary(ValueMap& dictionary);

/** Parses list of space-separated integers */
void parseIntegerList(const std::string &string, std::vector<int> &res);

/** Configures PolygonInfo class with the passed sizes + triangles */
void initializePolygonInfo(const Size &textureSize,
const Size &spriteSize,
Expand Down
10 changes: 5 additions & 5 deletions cocos/2d/CCTMXXMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
_externalTilesetFilename = externalTilesetFilename;

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

if (!_externalTilesetFullPath.empty())
{
string dir = _externalTilesetFullPath.substr(0, _externalTilesetFullPath.find_last_of("/") + 1);
string dir = _externalTilesetFullPath.substr(0, _externalTilesetFullPath.find_last_of('/') + 1);
tileset->_sourceImage = dir + imagename;
}
else if (_TMXFileName.find_last_of("/") != string::npos)
else if (_TMXFileName.find_last_of('/') != string::npos)
{
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of('/') + 1);
tileset->_sourceImage = dir + imagename;
}
else
Expand Down
5 changes: 0 additions & 5 deletions cocos/3d/CCAABB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ AABB::AABB(const Vec3& min, const Vec3& max)
set(min, max);
}

AABB::AABB(const AABB& box)
{
set(box._min,box._max);
}

Vec3 AABB::getCenter()
{
Vec3 center;
Expand Down
5 changes: 0 additions & 5 deletions cocos/3d/CCAABB.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ class CC_DLL AABB
*/
AABB(const Vec3& min, const Vec3& max);

/**
* Constructor.
*/
AABB(const AABB& box);

/**
* Gets the center point of the bounding box.
*/
Expand Down
2 changes: 1 addition & 1 deletion cocos/3d/CCBundle3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
int i = 0;
char str[20];
std::string dir = "";
auto last = fullPath.rfind("/");
auto last = fullPath.rfind('/');
if (last != std::string::npos)
dir = fullPath.substr(0, last + 1);
for (auto& material : materials) {
Expand Down
4 changes: 2 additions & 2 deletions cocos/base/CCConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace {
if (Director::getInstance()->getOpenGLView())
{
HWND hwnd = Director::getInstance()->getOpenGLView()->getWin32Window();
SendMessage(hwnd,
PostMessage(hwnd,
WM_COPYDATA,
(WPARAM)(HWND)hwnd,
(LPARAM)(LPVOID)&myCDS);
Expand Down Expand Up @@ -585,7 +585,7 @@ void Console::Command::commandGeneric(int fd, const std::string& args)
{
// The first argument (including the empty)
std::string key(args);
auto pos = args.find(" ");
auto pos = args.find(' ');
if ((pos != std::string::npos) && (0 < pos)) {
key = args.substr(0, pos);
}
Expand Down
4 changes: 2 additions & 2 deletions cocos/base/CCProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,12 +1117,12 @@ void calculateNamespacePath(const std::string& urlString, std::string& fileStrin
{
// If the url references a specific namespace within the file,
// calculate the full namespace path to the final namespace.
size_t loc = urlString.rfind("#");
size_t loc = urlString.rfind('#');
if (loc != std::string::npos)
{
fileString = urlString.substr(0, loc);
std::string namespacePathString = urlString.substr(loc + 1);
while ((loc = namespacePathString.find("/")) != std::string::npos)
while ((loc = namespacePathString.find('/')) != std::string::npos)
{
namespacePath.push_back(namespacePathString.substr(0, loc));
namespacePathString = namespacePathString.substr(loc + 1);
Expand Down
2 changes: 1 addition & 1 deletion cocos/base/CCProtocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class CC_DLL LabelProtocol
/**
* Sets a new label using a string
*
* @param label A null terminated string
* @param label The name of the new label.
* @js NA
* @lua NA
*/
Expand Down
2 changes: 1 addition & 1 deletion cocos/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ elseif(ANDROID)
base/CCUserDefault-android.cpp
base/CCController-android.cpp
)
elseif(LINUX)
elseif(LINUX OR WINDOWS)
set(COCOS_BASE_SPECIFIC_SRC
base/CCController-linux-win32.cpp
)
Expand Down
2 changes: 1 addition & 1 deletion cocos/base/ZipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ std::vector<std::string> ZipFile::listFiles(const std::string &pathname) const
if(filename.substr(0, dirname.length()) == dirname)
{
std::string suffix = filename.substr(dirname.length());
auto pos = suffix.find("/");
auto pos = suffix.find('/');
if (pos == std::string::npos)
{
fileSet.insert(suffix);
Expand Down
21 changes: 20 additions & 1 deletion cocos/base/ccUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THE SOFTWARE.
#include "base/CCAsyncTaskPool.h"
#include "base/CCEventDispatcher.h"
#include "base/base64.h"
#include "base/ccUTF8.h"
#include "renderer/CCCustomCommand.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCTextureCache.h"
Expand Down Expand Up @@ -124,7 +125,7 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
}
else
{
CCASSERT(filename.find("/") == std::string::npos, "The existence of a relative path is not guaranteed!");
CCASSERT(filename.find('/') == std::string::npos, "The existence of a relative path is not guaranteed!");
outputFile = FileUtils::getInstance()->getWritablePath() + filename;
}

Expand Down Expand Up @@ -526,6 +527,24 @@ LanguageType getLanguageTypeByISO2(const char* code)
return ret;
}

std::vector<int> parseIntegerList(const std::string &intsString) {
std::vector<int> result;

const char *cStr = intsString.c_str();
char *endptr;

for (long int i = strtol(cStr, &endptr, 10); endptr != cStr; i = strtol(cStr, &endptr, 10)) {
if (errno == ERANGE) {
errno = 0;
CCLOGWARN("%s contains out of range integers", intsString.c_str());
}
result.push_back(static_cast<int>(i));
cStr= endptr;
}

return result;
}

}

NS_CC_END
8 changes: 8 additions & 0 deletions cocos/base/ccUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ namespace utils
* @lua NA
*/
CC_DLL LanguageType getLanguageTypeByISO2(const char* code);

/**
@brief Parses a list of space-separated integers.
@return Vector of ints.
* @js NA
* @lua NA
*/
CC_DLL std::vector<int> parseIntegerList(const std::string &intsString);
}

NS_CC_END
Expand Down
4 changes: 2 additions & 2 deletions cocos/editor-support/cocosbuilder/CCBReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ bool CCBReader::readSequences()

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

std::string CCBReader::deletePathExtension(const char* pPath) {
std::string path(pPath);
size_t dotPos = path.find_last_of(".");
size_t dotPos = path.find_last_of('.');
if(dotPos != std::string::npos) {
return path.substr(0, dotPos);
}
Expand Down
6 changes: 3 additions & 3 deletions cocos/editor-support/cocostudio/CCActionManagerEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
{
std::string path = jsonName;
this->_studioVersionNumber = version;
ssize_t pos = path.find_last_of("/");
ssize_t pos = path.find_last_of('/');
std::string fileName = path.substr(pos+1,path.length());
cocos2d::Vector<ActionObject*> actionList;
int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist");
Expand All @@ -83,7 +83,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
stExpCocoNode* pCocoNode)
{
std::string path = file;
ssize_t pos = path.find_last_of("/");
ssize_t pos = path.find_last_of('/');
std::string fileName = path.substr(pos+1,path.length());
cocos2d::Vector<ActionObject*> actionList;

Expand Down Expand Up @@ -116,7 +116,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
{
std::string path = jsonName;
ssize_t pos = path.find_last_of("/");
ssize_t pos = path.find_last_of('/');
std::string fileName = path.substr(pos+1,path.length());
auto iterator = _actionDic.find(fileName);
if (iterator == _actionDic.end())
Expand Down
2 changes: 1 addition & 1 deletion cocos/editor-support/cocostudio/CCArmature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ void Armature::setBody(cpBody *body)
{
detector->setBody(body);
}
});
}
}
}
}
Expand Down
Loading

0 comments on commit 4930d15

Please sign in to comment.