mirror of https://github.com/axmolengine/axmol.git
sync 19634 and fix conflict (#19930)
This commit is contained in:
parent
e93d4cb1d6
commit
ad54a24cf0
|
@ -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"
|
||||
|
@ -77,24 +78,6 @@ SpriteFrameCache::~SpriteFrameCache()
|
|||
{
|
||||
}
|
||||
|
||||
void SpriteFrameCache::parseIntegerList(const std::string &string, std::vector<int> &res)
|
||||
{
|
||||
size_t n = std::count(string.begin(), string.end(), ' ');
|
||||
res.resize(n + 1);
|
||||
|
||||
const char *cStr = string.c_str();
|
||||
char *endptr;
|
||||
|
||||
int i = 0;
|
||||
do {
|
||||
long int val = strtol(cStr, &endptr, 10);
|
||||
if (endptr == cStr)
|
||||
return;
|
||||
res[i++] = static_cast<int>(val);
|
||||
cStr = endptr;
|
||||
} while (*endptr != '\0');
|
||||
}
|
||||
|
||||
void SpriteFrameCache::initializePolygonInfo(const Size &textureSize,
|
||||
const Size &spriteSize,
|
||||
const std::vector<int> &vertices,
|
||||
|
@ -260,12 +243,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);
|
||||
|
|
|
@ -291,9 +291,6 @@ protected:
|
|||
*/
|
||||
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,
|
||||
|
|
|
@ -35,6 +35,7 @@ THE SOFTWARE.
|
|||
#include "base/CCEventDispatcher.h"
|
||||
#include "base/base64.h"
|
||||
#include "base/ccConstants.h"
|
||||
#include "base/ccUTF8.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCTextureCache.h"
|
||||
|
@ -667,6 +668,24 @@ std::vector<float> getNormalMat3OfMat4(const Mat4 &mat)
|
|||
return normalMat;
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -207,6 +207,13 @@ namespace utils
|
|||
*/
|
||||
CC_DLL std::vector<float> getNormalMat3OfMat4(const Mat4 &mat);
|
||||
|
||||
/**
|
||||
@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
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "UnitTest.h"
|
||||
#include "ui/UIHelper.h"
|
||||
#include "network/Uri.h"
|
||||
#include "base/ccUtils.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace cocos2d::network;
|
||||
|
@ -73,6 +74,7 @@ UnitTests::UnitTests()
|
|||
ADD_TEST_CASE(ValueTest);
|
||||
ADD_TEST_CASE(UTFConversionTest);
|
||||
ADD_TEST_CASE(UIHelperSubStringTest);
|
||||
ADD_TEST_CASE(ParseIntegerListTest);
|
||||
ADD_TEST_CASE(ParseUriTest);
|
||||
ADD_TEST_CASE(ResizableBufferAdapterTest);
|
||||
#ifdef UNIT_TEST_FOR_OPTIMIZED_MATH_UTIL
|
||||
|
@ -920,6 +922,35 @@ std::string UIHelperSubStringTest::subtitle() const
|
|||
return "ui::Helper::getSubStringOfUTF8String Test";
|
||||
}
|
||||
|
||||
// ParseIntegerListTest
|
||||
void ParseIntegerListTest::onEnter() {
|
||||
UnitTestDemo::onEnter();
|
||||
|
||||
{
|
||||
using cocos2d::utils::parseIntegerList;
|
||||
|
||||
std::vector<int> res1{};
|
||||
EXPECT_EQ(res1, parseIntegerList(""));
|
||||
|
||||
std::vector<int> res2{1};
|
||||
EXPECT_EQ(res2, parseIntegerList("1"));
|
||||
|
||||
std::vector<int> res3{1, 2};
|
||||
EXPECT_EQ(res3, parseIntegerList("1 2"));
|
||||
|
||||
std::vector<int> res4{2, 4, 3, 1, 4, 2, 0, 4, 1, 0, 4, 5};
|
||||
EXPECT_EQ(res4, parseIntegerList("2 4 3 1 4 2 0 4 1 0 4 5"));
|
||||
|
||||
std::vector<int> res5{73, 48, 57, 117, 27, 117, 29, 77, 14, 62, 26, 7, 55, 2};
|
||||
EXPECT_EQ(res5, parseIntegerList("73 48 57 117 27 117 29 77 14 62 26 7 55 2"));
|
||||
}
|
||||
}
|
||||
|
||||
std::string ParseIntegerListTest::subtitle() const
|
||||
{
|
||||
return "utils::parseIntegerList Test";
|
||||
}
|
||||
|
||||
// ParseUriTest
|
||||
void ParseUriTest::onEnter()
|
||||
{
|
||||
|
|
|
@ -79,6 +79,15 @@ public:
|
|||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class ParseIntegerListTest : public UnitTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ParseIntegerListTest);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class ParseUriTest : public UnitTestDemo
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue