ccUtils.cpp 20.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
/****************************************************************************
Copyright (c) 2010      cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#include "base/ccUtils.h"

#include <cmath>
#include <stdlib.h>
#include "md5/md5.h"

#include "base/CCDirector.h"
#include "base/CCAsyncTaskPool.h"
#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"
#include "renderer/CCRenderState.h"
#include "renderer/backend/Types.h"

#include "platform/CCImage.h"
#include "platform/CCFileUtils.h"
#include "2d/CCSprite.h"
#include "2d/CCRenderTexture.h"

NS_CC_BEGIN

int ccNextPOT(int x)
{
    x = x - 1;
    x = x | (x >> 1);
    x = x | (x >> 2);
    x = x | (x >> 4);
    x = x | (x >> 8);
    x = x | (x >>16);
    return x + 1;
}

namespace utils
{
/**
* Capture screen implementation, don't use it directly.
*/
void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename, const unsigned char* imageData, int width, int height)
{
    if(!imageData)
    {
        afterCaptured(false, "");
        return;
    }
    
    static bool startedCapture = false;

    if (startedCapture)
    {
        CCLOG("Screen capture is already working");
        if (afterCaptured)
        {
            afterCaptured(false, filename);
        }
        return;
    }
    else
    {
        startedCapture = true;
    }

    bool succeed = false;
    std::string outputFile = "";

    do
    {
        Image* image = new (std::nothrow) Image;
        if (image)
        {
            image->initWithRawData(imageData, width * height * 4, width, height, 8);
            if (FileUtils::getInstance()->isAbsolutePath(filename))
            {
                outputFile = filename;
            }
            else
            {
                CCASSERT(filename.find('/') == std::string::npos, "The existence of a relative path is not guaranteed!");
                outputFile = FileUtils::getInstance()->getWritablePath() + filename;
            }

            // Save image in AsyncTaskPool::TaskType::TASK_IO thread, and call afterCaptured in mainThread
            static bool succeedSaveToFile = false;
            std::function<void(void*)> mainThread = [afterCaptured, outputFile](void* /*param*/)
            {
                if (afterCaptured)
                {
                    afterCaptured(succeedSaveToFile, outputFile);
                }
                startedCapture = false;
            };

            AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_IO, std::move(mainThread), nullptr, [image, outputFile]()
            {
                succeedSaveToFile = image->saveToFile(outputFile);
                delete image;
            });
        }
        else
        {
            CCLOG("Malloc Image memory failed!");
            if (afterCaptured)
            {
                afterCaptured(succeed, outputFile);
            }
            startedCapture = false;
        }
    } while (0);
}

/*
 * Capture screen interface
 */
static EventListenerCustom* s_captureScreenListener;
static CaptureScreenCallbackCommand s_captureScreenCommand;
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
{
    if (s_captureScreenListener)
    {
        CCLOG("Warning: CaptureScreen has been called already, don't call more than once in one frame.");
        return;
    }
    s_captureScreenCommand.init(std::numeric_limits<float>::max());
    s_captureScreenCommand.func = std::bind(onCaptureScreen, afterCaptured, filename, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
    
    s_captureScreenListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_AFTER_DRAW, [](EventCustom* /*event*/) {
        auto director = Director::getInstance();
        director->getEventDispatcher()->removeEventListener((EventListener*)(s_captureScreenListener));
        s_captureScreenListener = nullptr;
        director->getRenderer()->addCommand(&s_captureScreenCommand);
        director->getRenderer()->render();
    });

}

static std::unordered_map<Node*, EventListenerCustom*> s_captureNodeListener;
void captureNode(Node* startNode, std::function<void(Image*)> imageCallback, float scale)
{
    if (s_captureNodeListener.find(startNode) != s_captureNodeListener.end())
    {
        CCLOG("Warning: current node has been captured already");
        return;
    }

    auto callback = [startNode, scale, imageCallback](EventCustom* /*event*/) {
        auto director = Director::getInstance();
        auto captureNodeListener = s_captureNodeListener[startNode];
        director->getEventDispatcher()->removeEventListener((EventListener*)(captureNodeListener));
        s_captureNodeListener.erase(startNode);
        auto& size = startNode->getContentSize();
        
        Director::getInstance()->setNextDeltaTimeZero(true);
        
        RenderTexture* finalRtx = nullptr;
        
        auto rtx = RenderTexture::create(size.width, size.height, backend::PixelFormat::RGBA8888, PixelFormat::D24S8);
        // rtx->setKeepMatrix(true);
        Point savedPos = startNode->getPosition();
        Point anchor;
        if (!startNode->isIgnoreAnchorPointForPosition()) {
            anchor = startNode->getAnchorPoint();
        }
        startNode->setPosition(Point(size.width * anchor.x, size.height * anchor.y));
        rtx->begin();
        startNode->visit();
        rtx->end();
        startNode->setPosition(savedPos);
        
        if (std::abs(scale - 1.0f) < 1e-6f/* no scale */)
            finalRtx = rtx;
        else {
            /* scale */
            auto finalRect = Rect(0, 0, size.width, size.height);
            Sprite *sprite = Sprite::createWithTexture(rtx->getSprite()->getTexture(), finalRect);
            sprite->setAnchorPoint(Point(0, 0));
            sprite->setFlippedY(true);
            finalRtx = RenderTexture::create(size.width * scale, size.height * scale, backend::PixelFormat::RGBA8888, PixelFormat::D24S8);
            
            sprite->setScale(scale); // or use finalRtx->setKeepMatrix(true);
            finalRtx->begin();
            sprite->visit();
            finalRtx->end();
        }
        Director::getInstance()->getRenderer()->render();
        
        finalRtx->newImage(imageCallback);
    };
    
    auto listener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_BEFORE_DRAW, callback);
    
    s_captureNodeListener[startNode] = listener;
}

std::vector<Node*> findChildren(const Node &node, const std::string &name)
{
    std::vector<Node*> vec;
    
    node.enumerateChildren(name, [&vec](Node* nodeFound) -> bool {
        vec.push_back(nodeFound);
        return false;
    });

    return vec;
}

#define MAX_ITOA_BUFFER_SIZE 256
double atof(const char* str)
{
    if (str == nullptr)
    {
        return 0.0;
    }
    
    char buf[MAX_ITOA_BUFFER_SIZE];
    strncpy(buf, str, MAX_ITOA_BUFFER_SIZE);
    
    // strip string, only remain 7 numbers after '.'
    char* dot = strchr(buf, '.');
    if (dot != nullptr && dot - buf + 8 <  MAX_ITOA_BUFFER_SIZE)
    {
        dot[8] = '\0';
    }
    
    return ::atof(buf);
}

double gettime()
{
    struct timeval tv;
    gettimeofday(&tv, nullptr);

    return (double)tv.tv_sec + (double)tv.tv_usec/1000000;
}

long long getTimeInMilliseconds()
{
    struct timeval tv;
    gettimeofday (&tv, nullptr);
    return (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000;
}

Rect getCascadeBoundingBox(Node *node)
{
    Rect cbb;
    Size contentSize = node->getContentSize();
    
    // check all children bounding box, get maximize box
    Node* child = nullptr;
    bool merge = false;
    for(auto object : node->getChildren())
    {
        child = dynamic_cast<Node*>(object);
        if (!child->isVisible()) continue;
        
        const Rect box = getCascadeBoundingBox(child);
        if (box.size.width <= 0 || box.size.height <= 0) continue;
        
        if (!merge)
        {
            cbb = box;
            merge = true;
        }
        else
        {
            cbb.merge(box);
        }
    }
    
    // merge content size
    if (contentSize.width > 0 && contentSize.height > 0)
    {
        const Rect box = RectApplyAffineTransform(Rect(0, 0, contentSize.width, contentSize.height), node->getNodeToWorldAffineTransform());
        if (!merge)
        {
            cbb = box;
        }
        else
        {
            cbb.merge(box);
        }
    }
    
    return cbb;
}

Sprite* createSpriteFromBase64Cached(const char* base64String, const char* key)
{
    Texture2D* texture = Director::getInstance()->getTextureCache()->getTextureForKey(key);

    if (texture == nullptr)
    {
        unsigned char* decoded;
        int length = base64Decode((const unsigned char*)base64String, (unsigned int)strlen(base64String), &decoded);

        Image *image = new (std::nothrow) Image();
        bool imageResult = image->initWithImageData(decoded, length);
        CCASSERT(imageResult, "Failed to create image from base64!");
        free(decoded);

        if (!imageResult) {
            CC_SAFE_RELEASE_NULL(image);
            return nullptr;
        }

        texture = Director::getInstance()->getTextureCache()->addImage(image, key);
        image->release();
    }

    Sprite* sprite = Sprite::createWithTexture(texture);
    
    return sprite;
}

Sprite* createSpriteFromBase64(const char* base64String)
{
    unsigned char* decoded;
    int length = base64Decode((const unsigned char*)base64String, (unsigned int)strlen(base64String), &decoded);

    Image *image = new (std::nothrow) Image();
    bool imageResult = image->initWithImageData(decoded, length);
    CCASSERT(imageResult, "Failed to create image from base64!");
    free(decoded);

    if (!imageResult) {
        CC_SAFE_RELEASE_NULL(image);
        return nullptr;
    }

    Texture2D *texture = new (std::nothrow) Texture2D();
    texture->initWithImage(image);
    texture->setAliasTexParameters();
    image->release();

    Sprite* sprite = Sprite::createWithTexture(texture);
    texture->release();

    return sprite;
}

Node* findChild(Node* levelRoot, const std::string& name)
{
    if (levelRoot == nullptr || name.empty())
        return nullptr;

    // Find this node
    auto target = levelRoot->getChildByName(name);
    if (target != nullptr)
        return target;

    // Find recursively
    for (auto& child : levelRoot->getChildren())
    {
        target = findChild(child, name);
        if (target != nullptr)
            return target;
    }
    return nullptr;
}

Node* findChild(Node* levelRoot, int tag)
{
    if (levelRoot == nullptr || tag == Node::INVALID_TAG)
        return nullptr;

    // Find this node
    auto target = levelRoot->getChildByTag(tag);
    if (target != nullptr)
        return target;

    // Find recursively
    for (auto& child : levelRoot->getChildren())
    {
        target = findChild(child, tag);
        if (target != nullptr)
            return target;
    }

    return nullptr;
}

std::string getFileMD5Hash(const std::string &filename)
{
    Data data;
    FileUtils::getInstance()->getContents(filename, &data);

    return getDataMD5Hash(data);
}

std::string getDataMD5Hash(const Data &data)
{
    static const unsigned int MD5_DIGEST_LENGTH = 16;

    if (data.isNull())
    {
        return std::string();
    }

    md5_state_t state;
    md5_byte_t digest[MD5_DIGEST_LENGTH];
    char hexOutput[(MD5_DIGEST_LENGTH << 1) + 1] = { 0 };

    md5_init(&state);
    md5_append(&state, (const md5_byte_t *)data.getBytes(), (int)data.getSize());
    md5_finish(&state, digest);

    for (int di = 0; di < 16; ++di)
        sprintf(hexOutput + di * 2, "%02x", digest[di]);

    return hexOutput;
}

LanguageType getLanguageTypeByISO2(const char* code)
{
    // this function is used by all platforms to get system language
    // except windows: cocos/platform/win32/CCApplication-win32.cpp
    LanguageType ret = LanguageType::ENGLISH;

    if (strncmp(code, "zh", 2) == 0)
    {
        ret = LanguageType::CHINESE;
    }
    else if (strncmp(code, "ja", 2) == 0)
    {
        ret = LanguageType::JAPANESE;
    }
    else if (strncmp(code, "fr", 2) == 0)
    {
        ret = LanguageType::FRENCH;
    }
    else if (strncmp(code, "it", 2) == 0)
    {
        ret = LanguageType::ITALIAN;
    }
    else if (strncmp(code, "de", 2) == 0)
    {
        ret = LanguageType::GERMAN;
    }
    else if (strncmp(code, "es", 2) == 0)
    {
        ret = LanguageType::SPANISH;
    }
    else if (strncmp(code, "nl", 2) == 0)
    {
        ret = LanguageType::DUTCH;
    }
    else if (strncmp(code, "ru", 2) == 0)
    {
        ret = LanguageType::RUSSIAN;
    }
    else if (strncmp(code, "hu", 2) == 0)
    {
        ret = LanguageType::HUNGARIAN;
    }
    else if (strncmp(code, "pt", 2) == 0)
    {
        ret = LanguageType::PORTUGUESE;
    }
    else if (strncmp(code, "ko", 2) == 0)
    {
        ret = LanguageType::KOREAN;
    }
    else if (strncmp(code, "ar", 2) == 0)
    {
        ret = LanguageType::ARABIC;
    }
    else if (strncmp(code, "nb", 2) == 0)
    {
        ret = LanguageType::NORWEGIAN;
    }
    else if (strncmp(code, "pl", 2) == 0)
    {
        ret = LanguageType::POLISH;
    }
    else if (strncmp(code, "tr", 2) == 0)
    {
        ret = LanguageType::TURKISH;
    }
    else if (strncmp(code, "uk", 2) == 0)
    {
        ret = LanguageType::UKRAINIAN;
    }
    else if (strncmp(code, "ro", 2) == 0)
    {
        ret = LanguageType::ROMANIAN;
    }
    else if (strncmp(code, "bg", 2) == 0)
    {
        ret = LanguageType::BULGARIAN;
    }
    else if (strncmp(code, "be", 2) == 0)
    {
        ret = LanguageType::BELARUSIAN;
    }
    return ret;
}
    
backend::BlendFactor toBackendBlendFactor(int factor)
{
    switch (factor) {
        case GLBlendConst::ONE:
            return backend::BlendFactor::ONE;
        case GLBlendConst::ZERO:
            return backend::BlendFactor::ZERO;
        case GLBlendConst::SRC_COLOR:
            return backend::BlendFactor::SRC_COLOR;
        case GLBlendConst::ONE_MINUS_SRC_COLOR:
            return backend::BlendFactor::ONE_MINUS_SRC_COLOR;
        case GLBlendConst::SRC_ALPHA:
            return backend::BlendFactor::SRC_ALPHA;
        case GLBlendConst::ONE_MINUS_SRC_ALPHA:
            return backend::BlendFactor::ONE_MINUS_SRC_ALPHA;
        case GLBlendConst::DST_COLOR:
            return backend::BlendFactor::DST_COLOR;
        case GLBlendConst::ONE_MINUS_DST_COLOR:
            return backend::BlendFactor::ONE_MINUS_DST_COLOR;
        case GLBlendConst::DST_ALPHA:
            return backend::BlendFactor::DST_ALPHA;
        case GLBlendConst::ONE_MINUS_DST_ALPHA:
            return backend::BlendFactor::ONE_MINUS_DST_ALPHA;
        case GLBlendConst::SRC_ALPHA_SATURATE:
            return backend::BlendFactor::SRC_ALPHA_SATURATE;
        case GLBlendConst::BLEND_COLOR:
            return backend::BlendFactor::BLEND_CLOLOR;
        case GLBlendConst::CONSTANT_ALPHA:
            return backend::BlendFactor::CONSTANT_ALPHA;
        case GLBlendConst::ONE_MINUS_CONSTANT_ALPHA:
            return backend::BlendFactor::ONE_MINUS_CONSTANT_ALPHA;
        default:
            assert(false);
            break;
    }
    return backend::BlendFactor::ONE;
}

int toGLBlendFactor(backend::BlendFactor blendFactor)
{
    int ret = GLBlendConst::ONE;
    switch (blendFactor)
    {
    case backend::BlendFactor::ZERO:
        ret = GLBlendConst::ZERO;
        break;
    case backend::BlendFactor::ONE:
        ret = GLBlendConst::ONE;
        break;
    case backend::BlendFactor::SRC_COLOR:
        ret = GLBlendConst::SRC_COLOR;
        break;
    case backend::BlendFactor::ONE_MINUS_SRC_COLOR:
        ret = GLBlendConst::ONE_MINUS_SRC_COLOR;
        break;
    case backend::BlendFactor::SRC_ALPHA:
        ret = GLBlendConst::SRC_ALPHA;
        break;
    case backend::BlendFactor::ONE_MINUS_SRC_ALPHA:
        ret = GLBlendConst::ONE_MINUS_SRC_ALPHA;
        break;
    case backend::BlendFactor::DST_COLOR:
        ret = GLBlendConst::DST_COLOR;
        break;
    case backend::BlendFactor::ONE_MINUS_DST_COLOR:
        ret = GLBlendConst::ONE_MINUS_DST_COLOR;
        break;
    case backend::BlendFactor::DST_ALPHA:
        ret = GLBlendConst::DST_ALPHA;
        break;
    case backend::BlendFactor::ONE_MINUS_DST_ALPHA:
        ret = GLBlendConst::ONE_MINUS_DST_ALPHA;
        break;
    case backend::BlendFactor::SRC_ALPHA_SATURATE:
        ret = GLBlendConst::SRC_ALPHA_SATURATE;
        break;
    case backend::BlendFactor::BLEND_CLOLOR:
        ret = GLBlendConst::BLEND_COLOR;
        break;
    default:
        break;
    }
    return ret;
}

backend::SamplerFilter toBackendSamplerFilter(int mode)
{
    switch (mode)
    {
    case GLTexParamConst::LINEAR:
    case GLTexParamConst::LINEAR_MIPMAP_LINEAR:
    case GLTexParamConst::LINEAR_MIPMAP_NEAREST:
    case GLTexParamConst::NEAREST_MIPMAP_LINEAR:
        return backend::SamplerFilter::LINEAR;
    case GLTexParamConst::NEAREST:
    case GLTexParamConst::NEAREST_MIPMAP_NEAREST:
        return backend::SamplerFilter::NEAREST;
    default:
        CCASSERT(false, "invalid GL sampler filter!");
        return backend::SamplerFilter::LINEAR;
    }
}

backend::SamplerAddressMode toBackendAddressMode(int mode)
{
    switch (mode)
    {
    case GLTexParamConst::REPEAT:
        return backend::SamplerAddressMode::REPEAT;
    case GLTexParamConst::CLAMP:
    case GLTexParamConst::CLAMP_TO_EDGE:
        return backend::SamplerAddressMode::CLAMP_TO_EDGE;
    case GLTexParamConst::MIRROR_REPEAT:
        return backend::SamplerAddressMode::MIRROR_REPEAT;
    default:
        CCASSERT(false, "invalid GL address mode");
        return backend::SamplerAddressMode::REPEAT;
    }
}

const Mat4& getAdjustMatrix()
{
    static cocos2d::Mat4 adjustMatrix = {
        1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 0.5, 0.5,
        0, 0, 0, 1
    };

    return adjustMatrix;
}

std::vector<float> getNormalMat3OfMat4(const Mat4 &mat)
{
    std::vector<float> normalMat(9);
    Mat4 mvInverse = mat;
    mvInverse.m[12] = mvInverse.m[13] = mvInverse.m[14] = 0.0f;
    mvInverse.inverse();
    mvInverse.transpose();
    normalMat[0] = mvInverse.m[0]; normalMat[1] = mvInverse.m[1]; normalMat[2] = mvInverse.m[2];
    normalMat[3] = mvInverse.m[4]; normalMat[4] = mvInverse.m[5]; normalMat[5] = mvInverse.m[6];
    normalMat[6] = mvInverse.m[8]; normalMat[7] = mvInverse.m[9]; normalMat[8] = mvInverse.m[10];
    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