mirror of https://github.com/axmolengine/axmol.git
Merge remote-tracking branch 'upstream/develop' into develop
Conflicts: cocos/scripting/auto-generated tools/bindings-generator
This commit is contained in:
commit
b55aec2fa0
|
@ -1,3 +1,28 @@
|
||||||
|
#/****************************************************************************
|
||||||
|
# Copyright (c) 2013 cocos2d-x.org
|
||||||
|
# Copyright (c) 2012-2013 martell malone
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
# ****************************************************************************/
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
project (Cocos2dx)
|
project (Cocos2dx)
|
||||||
|
|
||||||
|
@ -170,12 +195,6 @@ if(WIN32)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
link_directories(
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/gles/prebuilt
|
|
||||||
)
|
|
||||||
|
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# msys2 Pacman Manager for cocos2d-x
|
||||||
|
|
||||||
|
#/****************************************************************************
|
||||||
|
# Copyright (c) 2012-2013 Martell Malone
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
# ****************************************************************************/
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
THISDIR="$(dirname $0)"
|
||||||
|
test "$THISDIR" = "." && THISDIR=${PWD}
|
||||||
|
OSTYPE=${OSTYPE//[0-9.]/}
|
||||||
|
HOST_ARCH=$(uname -m)
|
||||||
|
|
||||||
|
if [ "${HOST_ARCH}" = "i686" ]; then
|
||||||
|
BITS=32
|
||||||
|
elif [ "${HOST_ARCH}" = "x86_64" ]; then
|
||||||
|
BITS=64
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${OSTYPE}" = "msys" ]; then
|
||||||
|
|
||||||
|
CC=${HOST_ARCH}-w64-mingw32-gcc
|
||||||
|
CXX=${HOST_ARCH}-w64-mingw32-g++
|
||||||
|
PP=mingw-w64-${HOST_ARCH}
|
||||||
|
|
||||||
|
MINGW_PACKAGES=(glfw glew libwebp libjpeg-turbo libpng freetype libiconv zlib curl
|
||||||
|
make gcc binutils headers cmake libxml2)
|
||||||
|
|
||||||
|
MINGW_PACKAGES=(${MINGW_PACKAGES[@]/#/${PP}-})
|
||||||
|
|
||||||
|
pacman -S --force --noconfirm --needed ${MINGW_PACKAGES[@]}
|
||||||
|
|
||||||
|
mkdir -p mingw${BITS} && cd mingw${BITS}
|
||||||
|
|
||||||
|
export PATH=/mingw${BITS}/bin:${PATH}
|
||||||
|
|
||||||
|
cmake -G"MinGW Makefiles" -DCMAKE_MAKE_PROGRAM="mingw32-make" \
|
||||||
|
-DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" ../..
|
||||||
|
|
||||||
|
mingw32-make
|
||||||
|
fi
|
|
@ -1 +1 @@
|
||||||
4367613b05de13587c6cd0fb07aeef45f44afcfc
|
42f742346aec806886a8fd399aa42f689cafa71c
|
|
@ -1 +1 @@
|
||||||
edf83dc058b5630510ac8d327ae8db62ab062cc6
|
133130a8ae8d6597399a7de05ba9b63ee55f5e2d
|
|
@ -129,8 +129,10 @@ platform/CCThread.cpp \
|
||||||
../base/CCObject.cpp \
|
../base/CCObject.cpp \
|
||||||
../base/CCSet.cpp \
|
../base/CCSet.cpp \
|
||||||
../base/CCString.cpp \
|
../base/CCString.cpp \
|
||||||
|
../base/CCValue.cpp \
|
||||||
../base/etc1.cpp \
|
../base/etc1.cpp \
|
||||||
../base/s3tc.cpp \
|
../base/s3tc.cpp \
|
||||||
|
../base/CCConsole.cpp \
|
||||||
../math/kazmath/src/aabb.c \
|
../math/kazmath/src/aabb.c \
|
||||||
../math/kazmath/src/mat3.c \
|
../math/kazmath/src/mat3.c \
|
||||||
../math/kazmath/src/mat4.c \
|
../math/kazmath/src/mat4.c \
|
||||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
||||||
#include "CCActionInterval.h"
|
#include "CCActionInterval.h"
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
|
#include "CCString.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
//
|
//
|
||||||
|
|
|
@ -43,7 +43,7 @@ NS_CC_BEGIN;
|
||||||
* Implementation of PointArray
|
* Implementation of PointArray
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PointArray* PointArray::create(unsigned int capacity)
|
PointArray* PointArray::create(int capacity)
|
||||||
{
|
{
|
||||||
PointArray* pointArray = new PointArray();
|
PointArray* pointArray = new PointArray();
|
||||||
if (pointArray)
|
if (pointArray)
|
||||||
|
@ -63,7 +63,7 @@ PointArray* PointArray::create(unsigned int capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PointArray::initWithCapacity(unsigned int capacity)
|
bool PointArray::initWithCapacity(int capacity)
|
||||||
{
|
{
|
||||||
_controlPoints = new vector<Point*>();
|
_controlPoints = new vector<Point*>();
|
||||||
|
|
||||||
|
@ -126,19 +126,19 @@ void PointArray::addControlPoint(Point controlPoint)
|
||||||
_controlPoints->push_back(new Point(controlPoint.x, controlPoint.y));
|
_controlPoints->push_back(new Point(controlPoint.x, controlPoint.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PointArray::insertControlPoint(Point &controlPoint, unsigned int index)
|
void PointArray::insertControlPoint(Point &controlPoint, int index)
|
||||||
{
|
{
|
||||||
Point *temp = new Point(controlPoint.x, controlPoint.y);
|
Point *temp = new Point(controlPoint.x, controlPoint.y);
|
||||||
_controlPoints->insert(_controlPoints->begin() + index, temp);
|
_controlPoints->insert(_controlPoints->begin() + index, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point PointArray::getControlPointAtIndex(unsigned int index)
|
Point PointArray::getControlPointAtIndex(int index)
|
||||||
{
|
{
|
||||||
index = MIN(_controlPoints->size()-1, MAX(index, 0));
|
index = static_cast<int>(MIN(_controlPoints->size()-1, MAX(index, 0)));
|
||||||
return *(_controlPoints->at(index));
|
return *(_controlPoints->at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, unsigned int index)
|
void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, int index)
|
||||||
{
|
{
|
||||||
|
|
||||||
Point *temp = _controlPoints->at(index);
|
Point *temp = _controlPoints->at(index);
|
||||||
|
@ -146,7 +146,7 @@ void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, unsigned int
|
||||||
temp->y = controlPoint.y;
|
temp->y = controlPoint.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PointArray::removeControlPointAtIndex(unsigned int index)
|
void PointArray::removeControlPointAtIndex(int index)
|
||||||
{
|
{
|
||||||
vector<Point*>::iterator iter = _controlPoints->begin() + index;
|
vector<Point*>::iterator iter = _controlPoints->begin() + index;
|
||||||
Point* pRemovedPoint = *iter;
|
Point* pRemovedPoint = *iter;
|
||||||
|
@ -154,9 +154,9 @@ void PointArray::removeControlPointAtIndex(unsigned int index)
|
||||||
delete pRemovedPoint;
|
delete pRemovedPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int PointArray::count() const
|
int PointArray::count() const
|
||||||
{
|
{
|
||||||
return _controlPoints->size();
|
return static_cast<int>(_controlPoints->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
PointArray* PointArray::reverse() const
|
PointArray* PointArray::reverse() const
|
||||||
|
@ -177,11 +177,11 @@ PointArray* PointArray::reverse() const
|
||||||
|
|
||||||
void PointArray::reverseInline()
|
void PointArray::reverseInline()
|
||||||
{
|
{
|
||||||
unsigned long l = _controlPoints->size();
|
auto l = _controlPoints->size();
|
||||||
Point *p1 = nullptr;
|
Point *p1 = nullptr;
|
||||||
Point *p2 = nullptr;
|
Point *p2 = nullptr;
|
||||||
int x, y;
|
int x, y;
|
||||||
for (unsigned int i = 0; i < l/2; ++i)
|
for (int i = 0; i < l/2; ++i)
|
||||||
{
|
{
|
||||||
p1 = _controlPoints->at(i);
|
p1 = _controlPoints->at(i);
|
||||||
p2 = _controlPoints->at(l-i-1);
|
p2 = _controlPoints->at(l-i-1);
|
||||||
|
@ -291,7 +291,7 @@ CardinalSplineTo* CardinalSplineTo::clone() const
|
||||||
|
|
||||||
void CardinalSplineTo::update(float time)
|
void CardinalSplineTo::update(float time)
|
||||||
{
|
{
|
||||||
unsigned int p;
|
int p;
|
||||||
float lt;
|
float lt;
|
||||||
|
|
||||||
// eg.
|
// eg.
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
/** creates and initializes a Points array with capacity
|
/** creates and initializes a Points array with capacity
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
static PointArray* create(unsigned int capacity);
|
static PointArray* create(int capacity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
|
@ -77,7 +77,7 @@ public:
|
||||||
/** initializes a Catmull Rom config with a capacity hint
|
/** initializes a Catmull Rom config with a capacity hint
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
bool initWithCapacity(unsigned int capacity);
|
bool initWithCapacity(int capacity);
|
||||||
|
|
||||||
/** appends a control point
|
/** appends a control point
|
||||||
* @js NA
|
* @js NA
|
||||||
|
@ -87,27 +87,27 @@ public:
|
||||||
/** inserts a controlPoint at index
|
/** inserts a controlPoint at index
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
void insertControlPoint(Point &controlPoint, unsigned int index);
|
void insertControlPoint(Point &controlPoint, int index);
|
||||||
|
|
||||||
/** replaces an existing controlPoint at index
|
/** replaces an existing controlPoint at index
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
void replaceControlPoint(Point &controlPoint, unsigned int index);
|
void replaceControlPoint(Point &controlPoint, int index);
|
||||||
|
|
||||||
/** get the value of a controlPoint at a given index
|
/** get the value of a controlPoint at a given index
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
Point getControlPointAtIndex(unsigned int index);
|
Point getControlPointAtIndex(int index);
|
||||||
|
|
||||||
/** deletes a control point at a given index
|
/** deletes a control point at a given index
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
void removeControlPointAtIndex(unsigned int index);
|
void removeControlPointAtIndex(int index);
|
||||||
|
|
||||||
/** returns the number of objects of the control point array
|
/** returns the number of objects of the control point array
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
unsigned int count() const;
|
int count() const;
|
||||||
|
|
||||||
/** returns a new copy of the array reversed. User is responsible for releasing this copy
|
/** returns a new copy of the array reversed. User is responsible for releasing this copy
|
||||||
* @js NA
|
* @js NA
|
||||||
|
|
|
@ -198,21 +198,21 @@ Sequence* Sequence::createWithVariableList(FiniteTimeAction *pAction1, va_list a
|
||||||
return ((Sequence*)pPrev);
|
return ((Sequence*)pPrev);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sequence* Sequence::create(Array* arrayOfActions)
|
Sequence* Sequence::create(const Vector<FiniteTimeAction*>& arrayOfActions)
|
||||||
{
|
{
|
||||||
Sequence* pRet = NULL;
|
Sequence* pRet = NULL;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
long count = arrayOfActions->count();
|
auto count = arrayOfActions.size();
|
||||||
CC_BREAK_IF(count == 0);
|
CC_BREAK_IF(count == 0);
|
||||||
|
|
||||||
FiniteTimeAction* prev = static_cast<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(0));
|
auto prev = arrayOfActions.at(0);
|
||||||
|
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
{
|
{
|
||||||
for (long i = 1; i < count; ++i)
|
for (int i = 1; i < count; ++i)
|
||||||
{
|
{
|
||||||
prev = createWithTwoActions(prev, static_cast<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(i)));
|
prev = createWithTwoActions(prev, arrayOfActions.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -571,19 +571,19 @@ Spawn* Spawn::createWithVariableList(FiniteTimeAction *pAction1, va_list args)
|
||||||
return ((Spawn*)pPrev);
|
return ((Spawn*)pPrev);
|
||||||
}
|
}
|
||||||
|
|
||||||
Spawn* Spawn::create(Array *arrayOfActions)
|
Spawn* Spawn::create(const Vector<FiniteTimeAction*>& arrayOfActions)
|
||||||
{
|
{
|
||||||
Spawn* pRet = NULL;
|
Spawn* pRet = NULL;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
long count = arrayOfActions->count();
|
auto count = arrayOfActions.size();
|
||||||
CC_BREAK_IF(count == 0);
|
CC_BREAK_IF(count == 0);
|
||||||
FiniteTimeAction* prev = static_cast<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(0));
|
auto prev = arrayOfActions.at(0);
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < arrayOfActions->count(); ++i)
|
for (int i = 1; i < arrayOfActions.size(); ++i)
|
||||||
{
|
{
|
||||||
prev = createWithTwoActions(prev, static_cast<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(i)));
|
prev = createWithTwoActions(prev, arrayOfActions.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -591,7 +591,7 @@ Spawn* Spawn::create(Array *arrayOfActions)
|
||||||
// If only one action is added to Spawn, make up a Spawn by adding a simplest finite time action.
|
// If only one action is added to Spawn, make up a Spawn by adding a simplest finite time action.
|
||||||
prev = createWithTwoActions(prev, ExtraAction::create());
|
prev = createWithTwoActions(prev, ExtraAction::create());
|
||||||
}
|
}
|
||||||
pRet = (Spawn*)prev;
|
pRet = static_cast<Spawn*>(prev);
|
||||||
}while (0);
|
}while (0);
|
||||||
|
|
||||||
return pRet;
|
return pRet;
|
||||||
|
@ -2003,31 +2003,28 @@ Animate::~Animate()
|
||||||
CC_SAFE_DELETE(_splitTimes);
|
CC_SAFE_DELETE(_splitTimes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Animate::initWithAnimation(Animation *pAnimation)
|
bool Animate::initWithAnimation(Animation* animation)
|
||||||
{
|
{
|
||||||
CCASSERT( pAnimation!=NULL, "Animate: argument Animation must be non-NULL");
|
CCASSERT( animation!=NULL, "Animate: argument Animation must be non-NULL");
|
||||||
|
|
||||||
float singleDuration = pAnimation->getDuration();
|
float singleDuration = animation->getDuration();
|
||||||
|
|
||||||
if ( ActionInterval::initWithDuration(singleDuration * pAnimation->getLoops() ) )
|
if ( ActionInterval::initWithDuration(singleDuration * animation->getLoops() ) )
|
||||||
{
|
{
|
||||||
_nextFrame = 0;
|
_nextFrame = 0;
|
||||||
setAnimation(pAnimation);
|
setAnimation(animation);
|
||||||
_origFrame = NULL;
|
_origFrame = NULL;
|
||||||
_executedLoops = 0;
|
_executedLoops = 0;
|
||||||
|
|
||||||
_splitTimes->reserve(pAnimation->getFrames()->count());
|
_splitTimes->reserve(animation->getFrames().size());
|
||||||
|
|
||||||
float accumUnitsOfTime = 0;
|
float accumUnitsOfTime = 0;
|
||||||
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
|
float newUnitOfTimeValue = singleDuration / animation->getTotalDelayUnits();
|
||||||
|
|
||||||
Array* pFrames = pAnimation->getFrames();
|
auto frames = animation->getFrames();
|
||||||
CCARRAY_VERIFY_TYPE(pFrames, AnimationFrame*);
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
for (auto& frame : frames)
|
||||||
CCARRAY_FOREACH(pFrames, pObj)
|
|
||||||
{
|
{
|
||||||
AnimationFrame* frame = static_cast<AnimationFrame*>(pObj);
|
|
||||||
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
||||||
accumUnitsOfTime += frame->getDelayUnits();
|
accumUnitsOfTime += frame->getDelayUnits();
|
||||||
_splitTimes->push_back(value);
|
_splitTimes->push_back(value);
|
||||||
|
@ -2099,20 +2096,20 @@ void Animate::update(float t)
|
||||||
t = fmodf(t, 1.0f);
|
t = fmodf(t, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array* frames = _animation->getFrames();
|
auto frames = _animation->getFrames();
|
||||||
long numberOfFrames = frames->count();
|
auto numberOfFrames = frames.size();
|
||||||
SpriteFrame *frameToDisplay = NULL;
|
SpriteFrame *frameToDisplay = NULL;
|
||||||
|
|
||||||
for( int i=_nextFrame; i < numberOfFrames; i++ ) {
|
for( int i=_nextFrame; i < numberOfFrames; i++ ) {
|
||||||
float splitTime = _splitTimes->at(i);
|
float splitTime = _splitTimes->at(i);
|
||||||
|
|
||||||
if( splitTime <= t ) {
|
if( splitTime <= t ) {
|
||||||
AnimationFrame* frame = static_cast<AnimationFrame*>(frames->getObjectAtIndex(i));
|
AnimationFrame* frame = frames.at(i);
|
||||||
frameToDisplay = frame->getSpriteFrame();
|
frameToDisplay = frame->getSpriteFrame();
|
||||||
static_cast<Sprite*>(_target)->setDisplayFrame(frameToDisplay);
|
static_cast<Sprite*>(_target)->setDisplayFrame(frameToDisplay);
|
||||||
|
|
||||||
Dictionary* dict = frame->getUserInfo();
|
const ValueMap& dict = frame->getUserInfo();
|
||||||
if( dict )
|
if ( !dict.empty() )
|
||||||
{
|
{
|
||||||
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:AnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:AnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
||||||
}
|
}
|
||||||
|
@ -2127,27 +2124,24 @@ void Animate::update(float t)
|
||||||
|
|
||||||
Animate* Animate::reverse() const
|
Animate* Animate::reverse() const
|
||||||
{
|
{
|
||||||
Array* pOldArray = _animation->getFrames();
|
auto oldArray = _animation->getFrames();
|
||||||
Array* pNewArray = Array::createWithCapacity(pOldArray->count());
|
Vector<AnimationFrame*> newArray(oldArray.size());
|
||||||
|
|
||||||
CCARRAY_VERIFY_TYPE(pOldArray, AnimationFrame*);
|
if (oldArray.size() > 0)
|
||||||
|
|
||||||
if (pOldArray->count() > 0)
|
|
||||||
{
|
{
|
||||||
Object* pObj = NULL;
|
for (auto iter = oldArray.crbegin(); iter != oldArray.crend(); ++iter)
|
||||||
CCARRAY_FOREACH_REVERSE(pOldArray, pObj)
|
|
||||||
{
|
{
|
||||||
AnimationFrame* pElement = static_cast<AnimationFrame*>(pObj);
|
AnimationFrame* animFrame = *iter;
|
||||||
if (! pElement)
|
if (!animFrame)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNewArray->addObject(pElement->clone());
|
newArray.pushBack(animFrame->clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation *newAnim = Animation::create(pNewArray, _animation->getDelayPerUnit(), _animation->getLoops());
|
Animation *newAnim = Animation::create(newArray, _animation->getDelayPerUnit(), _animation->getLoops());
|
||||||
newAnim->setRestoreOriginalFrame(_animation->getRestoreOriginalFrame());
|
newAnim->setRestoreOriginalFrame(_animation->getRestoreOriginalFrame());
|
||||||
return Animate::create(newAnim);
|
return Animate::create(newAnim);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include "CCAnimation.h"
|
#include "CCAnimation.h"
|
||||||
|
#include <CCVector.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -99,7 +100,7 @@ public:
|
||||||
* in lua :local create(local object1,local object2, ...)
|
* in lua :local create(local object1,local object2, ...)
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
static Sequence* create(Array *arrayOfActions);
|
static Sequence* create(const Vector<FiniteTimeAction*>& arrayOfActions);
|
||||||
/** helper constructor to create an array of sequence-able actions */
|
/** helper constructor to create an array of sequence-able actions */
|
||||||
static Sequence* createWithVariableList(FiniteTimeAction *pAction1, va_list args);
|
static Sequence* createWithVariableList(FiniteTimeAction *pAction1, va_list args);
|
||||||
/** creates the action */
|
/** creates the action */
|
||||||
|
@ -246,7 +247,7 @@ public:
|
||||||
static Spawn* createWithVariableList(FiniteTimeAction *pAction1, va_list args);
|
static Spawn* createWithVariableList(FiniteTimeAction *pAction1, va_list args);
|
||||||
|
|
||||||
/** helper constructor to create an array of spawned actions given an array */
|
/** helper constructor to create an array of spawned actions given an array */
|
||||||
static Spawn* create(Array *arrayOfActions);
|
static Spawn* create(const Vector<FiniteTimeAction*>& arrayOfActions);
|
||||||
|
|
||||||
/** creates the Spawn action */
|
/** creates the Spawn action */
|
||||||
static Spawn* createWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2);
|
static Spawn* createWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2);
|
||||||
|
|
|
@ -40,7 +40,7 @@ NS_CC_BEGIN
|
||||||
typedef struct _hashElement
|
typedef struct _hashElement
|
||||||
{
|
{
|
||||||
struct _ccArray *actions;
|
struct _ccArray *actions;
|
||||||
Object *target;
|
Node *target;
|
||||||
int actionIndex;
|
int actionIndex;
|
||||||
Action *currentAction;
|
Action *currentAction;
|
||||||
bool currentActionSalvaged;
|
bool currentActionSalvaged;
|
||||||
|
@ -87,7 +87,7 @@ void ActionManager::actionAllocWithHashElement(tHashElement *element)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::removeActionAtIndex(long index, tHashElement *element)
|
void ActionManager::removeActionAtIndex(int index, tHashElement *element)
|
||||||
{
|
{
|
||||||
Action *action = (Action*)element->actions->arr[index];
|
Action *action = (Action*)element->actions->arr[index];
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ void ActionManager::removeActionAtIndex(long index, tHashElement *element)
|
||||||
|
|
||||||
// pause / resume
|
// pause / resume
|
||||||
|
|
||||||
void ActionManager::pauseTarget(Object *target)
|
void ActionManager::pauseTarget(Node *target)
|
||||||
{
|
{
|
||||||
tHashElement *element = NULL;
|
tHashElement *element = NULL;
|
||||||
HASH_FIND_PTR(_targets, &target, element);
|
HASH_FIND_PTR(_targets, &target, element);
|
||||||
|
@ -130,7 +130,7 @@ void ActionManager::pauseTarget(Object *target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::resumeTarget(Object *target)
|
void ActionManager::resumeTarget(Node *target)
|
||||||
{
|
{
|
||||||
tHashElement *element = NULL;
|
tHashElement *element = NULL;
|
||||||
HASH_FIND_PTR(_targets, &target, element);
|
HASH_FIND_PTR(_targets, &target, element);
|
||||||
|
@ -140,30 +140,27 @@ void ActionManager::resumeTarget(Object *target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set* ActionManager::pauseAllRunningActions()
|
Vector<Node*> ActionManager::pauseAllRunningActions()
|
||||||
{
|
{
|
||||||
Set *idsWithActions = new Set();
|
Vector<Node*> idsWithActions;
|
||||||
idsWithActions->autorelease();
|
|
||||||
|
|
||||||
for (tHashElement *element=_targets; element != NULL; element = (tHashElement *)element->hh.next)
|
for (tHashElement *element=_targets; element != NULL; element = (tHashElement *)element->hh.next)
|
||||||
{
|
{
|
||||||
if (! element->paused)
|
if (! element->paused)
|
||||||
{
|
{
|
||||||
element->paused = true;
|
element->paused = true;
|
||||||
idsWithActions->addObject(element->target);
|
idsWithActions.pushBack(element->target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return idsWithActions;
|
return std::move(idsWithActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::resumeTargets(cocos2d::Set *targetsToResume)
|
void ActionManager::resumeTargets(const Vector<Node*>& targetsToResume)
|
||||||
{
|
{
|
||||||
SetIterator iter;
|
targetsToResume.forEach([this](Node* node){
|
||||||
for (iter = targetsToResume->begin(); iter != targetsToResume->end(); ++iter)
|
this->resumeTarget(node);
|
||||||
{
|
});
|
||||||
resumeTarget(*iter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
@ -196,17 +193,17 @@ void ActionManager::addAction(Action *action, Node *target, bool paused)
|
||||||
|
|
||||||
// remove
|
// remove
|
||||||
|
|
||||||
void ActionManager::removeAllActions(void)
|
void ActionManager::removeAllActions()
|
||||||
{
|
{
|
||||||
for (tHashElement *element = _targets; element != NULL; )
|
for (tHashElement *element = _targets; element != NULL; )
|
||||||
{
|
{
|
||||||
Object *target = element->target;
|
auto target = element->target;
|
||||||
element = (tHashElement*)element->hh.next;
|
element = (tHashElement*)element->hh.next;
|
||||||
removeAllActionsFromTarget(target);
|
removeAllActionsFromTarget(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::removeAllActionsFromTarget(Object *target)
|
void ActionManager::removeAllActionsFromTarget(Node *target)
|
||||||
{
|
{
|
||||||
// explicit null handling
|
// explicit null handling
|
||||||
if (target == NULL)
|
if (target == NULL)
|
||||||
|
@ -253,7 +250,7 @@ void ActionManager::removeAction(Action *action)
|
||||||
HASH_FIND_PTR(_targets, &target, element);
|
HASH_FIND_PTR(_targets, &target, element);
|
||||||
if (element)
|
if (element)
|
||||||
{
|
{
|
||||||
long i = ccArrayGetIndexOfObject(element->actions, action);
|
auto i = ccArrayGetIndexOfObject(element->actions, action);
|
||||||
if (i != CC_INVALID_INDEX)
|
if (i != CC_INVALID_INDEX)
|
||||||
{
|
{
|
||||||
removeActionAtIndex(i, element);
|
removeActionAtIndex(i, element);
|
||||||
|
@ -265,7 +262,7 @@ void ActionManager::removeAction(Action *action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::removeActionByTag(int tag, Object *target)
|
void ActionManager::removeActionByTag(int tag, Node *target)
|
||||||
{
|
{
|
||||||
CCASSERT(tag != Action::INVALID_TAG, "");
|
CCASSERT(tag != Action::INVALID_TAG, "");
|
||||||
CCASSERT(target != NULL, "");
|
CCASSERT(target != NULL, "");
|
||||||
|
@ -275,8 +272,8 @@ void ActionManager::removeActionByTag(int tag, Object *target)
|
||||||
|
|
||||||
if (element)
|
if (element)
|
||||||
{
|
{
|
||||||
long limit = element->actions->num;
|
auto limit = element->actions->num;
|
||||||
for (long i = 0; i < limit; ++i)
|
for (int i = 0; i < limit; ++i)
|
||||||
{
|
{
|
||||||
Action *action = (Action*)element->actions->arr[i];
|
Action *action = (Action*)element->actions->arr[i];
|
||||||
|
|
||||||
|
@ -293,7 +290,7 @@ void ActionManager::removeActionByTag(int tag, Object *target)
|
||||||
|
|
||||||
// XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
// XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
||||||
// and, it is not possible to get the address of a reference
|
// and, it is not possible to get the address of a reference
|
||||||
Action* ActionManager::getActionByTag(int tag, const Object *target) const
|
Action* ActionManager::getActionByTag(int tag, const Node *target) const
|
||||||
{
|
{
|
||||||
CCASSERT(tag != Action::INVALID_TAG, "");
|
CCASSERT(tag != Action::INVALID_TAG, "");
|
||||||
|
|
||||||
|
@ -304,8 +301,8 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const
|
||||||
{
|
{
|
||||||
if (element->actions != NULL)
|
if (element->actions != NULL)
|
||||||
{
|
{
|
||||||
long limit = element->actions->num;
|
auto limit = element->actions->num;
|
||||||
for (long i = 0; i < limit; ++i)
|
for (int i = 0; i < limit; ++i)
|
||||||
{
|
{
|
||||||
Action *action = (Action*)element->actions->arr[i];
|
Action *action = (Action*)element->actions->arr[i];
|
||||||
|
|
||||||
|
@ -327,7 +324,7 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const
|
||||||
|
|
||||||
// XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
// XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
||||||
// and, it is not possible to get the address of a reference
|
// and, it is not possible to get the address of a reference
|
||||||
long ActionManager::getNumberOfRunningActionsInTarget(const Object *target) const
|
int ActionManager::getNumberOfRunningActionsInTarget(const Node *target) const
|
||||||
{
|
{
|
||||||
tHashElement *element = NULL;
|
tHashElement *element = NULL;
|
||||||
HASH_FIND_PTR(_targets, &target, element);
|
HASH_FIND_PTR(_targets, &target, element);
|
||||||
|
|
|
@ -29,13 +29,11 @@ THE SOFTWARE.
|
||||||
#define __ACTION_CCACTION_MANAGER_H__
|
#define __ACTION_CCACTION_MANAGER_H__
|
||||||
|
|
||||||
#include "CCAction.h"
|
#include "CCAction.h"
|
||||||
#include "CCArray.h"
|
#include "CCVector.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class Set;
|
|
||||||
|
|
||||||
struct _hashElement;
|
struct _hashElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,55 +76,55 @@ public:
|
||||||
|
|
||||||
/** Removes all actions from all the targets.
|
/** Removes all actions from all the targets.
|
||||||
*/
|
*/
|
||||||
void removeAllActions(void);
|
void removeAllActions();
|
||||||
|
|
||||||
/** Removes all actions from a certain target.
|
/** Removes all actions from a certain target.
|
||||||
All the actions that belongs to the target will be removed.
|
All the actions that belongs to the target will be removed.
|
||||||
*/
|
*/
|
||||||
void removeAllActionsFromTarget(Object *target);
|
void removeAllActionsFromTarget(Node *target);
|
||||||
|
|
||||||
/** Removes an action given an action reference.
|
/** Removes an action given an action reference.
|
||||||
*/
|
*/
|
||||||
void removeAction(Action *pAction);
|
void removeAction(Action *pAction);
|
||||||
|
|
||||||
/** Removes an action given its tag and the target */
|
/** Removes an action given its tag and the target */
|
||||||
void removeActionByTag(int tag, Object *target);
|
void removeActionByTag(int tag, Node *target);
|
||||||
|
|
||||||
/** Gets an action given its tag an a target
|
/** Gets an action given its tag an a target
|
||||||
@return the Action the with the given tag
|
@return the Action the with the given tag
|
||||||
*/
|
*/
|
||||||
Action* getActionByTag(int tag, const Object *target) const;
|
Action* getActionByTag(int tag, const Node *target) const;
|
||||||
|
|
||||||
/** Returns the numbers of actions that are running in a certain target.
|
/** Returns the numbers of actions that are running in a certain target.
|
||||||
* Composable actions are counted as 1 action. Example:
|
* Composable actions are counted as 1 action. Example:
|
||||||
* - If you are running 1 Sequence of 7 actions, it will return 1.
|
* - If you are running 1 Sequence of 7 actions, it will return 1.
|
||||||
* - If you are running 7 Sequences of 2 actions, it will return 7.
|
* - If you are running 7 Sequences of 2 actions, it will return 7.
|
||||||
*/
|
*/
|
||||||
long getNumberOfRunningActionsInTarget(const Object *target) const;
|
int getNumberOfRunningActionsInTarget(const Node *target) const;
|
||||||
|
|
||||||
/** @deprecated use getNumberOfRunningActionsInTarget() instead */
|
/** @deprecated use getNumberOfRunningActionsInTarget() instead */
|
||||||
CC_DEPRECATED_ATTRIBUTE inline unsigned int numberOfRunningActionsInTarget(Object *target) const { return getNumberOfRunningActionsInTarget(target); }
|
CC_DEPRECATED_ATTRIBUTE inline int numberOfRunningActionsInTarget(Node *target) const { return getNumberOfRunningActionsInTarget(target); }
|
||||||
|
|
||||||
/** Pauses the target: all running actions and newly added actions will be paused.
|
/** Pauses the target: all running actions and newly added actions will be paused.
|
||||||
*/
|
*/
|
||||||
void pauseTarget(Object *target);
|
void pauseTarget(Node *target);
|
||||||
|
|
||||||
/** Resumes the target. All queued actions will be resumed.
|
/** Resumes the target. All queued actions will be resumed.
|
||||||
*/
|
*/
|
||||||
void resumeTarget(Object *target);
|
void resumeTarget(Node *target);
|
||||||
|
|
||||||
/** Pauses all running actions, returning a list of targets whose actions were paused.
|
/** Pauses all running actions, returning a list of targets whose actions were paused.
|
||||||
*/
|
*/
|
||||||
Set* pauseAllRunningActions();
|
Vector<Node*> pauseAllRunningActions();
|
||||||
|
|
||||||
/** Resume a set of targets (convenience function to reverse a pauseAllRunningActions call)
|
/** Resume a set of targets (convenience function to reverse a pauseAllRunningActions call)
|
||||||
*/
|
*/
|
||||||
void resumeTargets(Set *targetsToResume);
|
void resumeTargets(const Vector<Node*>& targetsToResume);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// declared in ActionManager.m
|
// declared in ActionManager.m
|
||||||
|
|
||||||
void removeActionAtIndex(long index, struct _hashElement *pElement);
|
void removeActionAtIndex(int index, struct _hashElement *pElement);
|
||||||
void deleteHashElement(struct _hashElement *pElement);
|
void deleteHashElement(struct _hashElement *pElement);
|
||||||
void actionAllocWithHashElement(struct _hashElement *pElement);
|
void actionAllocWithHashElement(struct _hashElement *pElement);
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
|
@ -32,15 +32,28 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
AnimationFrame* AnimationFrame::create(SpriteFrame* spriteFrame, float delayUnits, const ValueMap& userInfo)
|
||||||
|
{
|
||||||
|
auto ret = new AnimationFrame();
|
||||||
|
if (ret && ret->initWithSpriteFrame(spriteFrame, delayUnits, userInfo))
|
||||||
|
{
|
||||||
|
ret->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
AnimationFrame::AnimationFrame()
|
AnimationFrame::AnimationFrame()
|
||||||
: _spriteFrame(NULL)
|
: _spriteFrame(NULL)
|
||||||
, _delayUnits(0.0f)
|
, _delayUnits(0.0f)
|
||||||
, _userInfo(NULL)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnimationFrame::initWithSpriteFrame(SpriteFrame* spriteFrame, float delayUnits, Dictionary* userInfo)
|
bool AnimationFrame::initWithSpriteFrame(SpriteFrame* spriteFrame, float delayUnits, const ValueMap& userInfo)
|
||||||
{
|
{
|
||||||
setSpriteFrame(spriteFrame);
|
setSpriteFrame(spriteFrame);
|
||||||
setDelayUnits(delayUnits);
|
setDelayUnits(delayUnits);
|
||||||
|
@ -54,7 +67,6 @@ AnimationFrame::~AnimationFrame()
|
||||||
CCLOGINFO( "deallocing AnimationFrame: %p", this);
|
CCLOGINFO( "deallocing AnimationFrame: %p", this);
|
||||||
|
|
||||||
CC_SAFE_RELEASE(_spriteFrame);
|
CC_SAFE_RELEASE(_spriteFrame);
|
||||||
CC_SAFE_RELEASE(_userInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationFrame* AnimationFrame::clone() const
|
AnimationFrame* AnimationFrame::clone() const
|
||||||
|
@ -63,7 +75,7 @@ AnimationFrame* AnimationFrame::clone() const
|
||||||
auto frame = new AnimationFrame();
|
auto frame = new AnimationFrame();
|
||||||
frame->initWithSpriteFrame(_spriteFrame->clone(),
|
frame->initWithSpriteFrame(_spriteFrame->clone(),
|
||||||
_delayUnits,
|
_delayUnits,
|
||||||
_userInfo != NULL ? _userInfo->clone() : NULL);
|
_userInfo);
|
||||||
|
|
||||||
frame->autorelease();
|
frame->autorelease();
|
||||||
return frame;
|
return frame;
|
||||||
|
@ -80,7 +92,7 @@ Animation* Animation::create(void)
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation* Animation::createWithSpriteFrames(Array *frames, float delay/* = 0.0f*/)
|
Animation* Animation::createWithSpriteFrames(const Vector<SpriteFrame*>& frames, float delay/* = 0.0f*/)
|
||||||
{
|
{
|
||||||
Animation *pAnimation = new Animation();
|
Animation *pAnimation = new Animation();
|
||||||
pAnimation->initWithSpriteFrames(frames, delay);
|
pAnimation->initWithSpriteFrames(frames, delay);
|
||||||
|
@ -89,7 +101,7 @@ Animation* Animation::createWithSpriteFrames(Array *frames, float delay/* = 0.0f
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation* Animation::create(Array* arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops /* = 1 */)
|
Animation* Animation::create(const Vector<AnimationFrame*>& arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops /* = 1 */)
|
||||||
{
|
{
|
||||||
Animation *pAnimation = new Animation();
|
Animation *pAnimation = new Animation();
|
||||||
pAnimation->initWithAnimationFrames(arrayOfAnimationFrameNames, delayPerUnit, loops);
|
pAnimation->initWithAnimationFrames(arrayOfAnimationFrameNames, delayPerUnit, loops);
|
||||||
|
@ -99,49 +111,36 @@ Animation* Animation::create(Array* arrayOfAnimationFrameNames, float delayPerUn
|
||||||
|
|
||||||
bool Animation::init()
|
bool Animation::init()
|
||||||
{
|
{
|
||||||
return initWithSpriteFrames(NULL, 0.0f);
|
_loops = 1;
|
||||||
|
_delayPerUnit = 0.0f;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Animation::initWithSpriteFrames(Array *pFrames, float delay/* = 0.0f*/)
|
bool Animation::initWithSpriteFrames(const Vector<SpriteFrame*>& frames, float delay/* = 0.0f*/)
|
||||||
{
|
{
|
||||||
CCARRAY_VERIFY_TYPE(pFrames, SpriteFrame*);
|
|
||||||
|
|
||||||
_loops = 1;
|
_loops = 1;
|
||||||
_delayPerUnit = delay;
|
_delayPerUnit = delay;
|
||||||
Array* pTmpFrames = Array::create();
|
|
||||||
setFrames(pTmpFrames);
|
|
||||||
|
|
||||||
if (pFrames != NULL)
|
for (auto& spriteFrame : frames)
|
||||||
{
|
{
|
||||||
Object* pObj = NULL;
|
auto animFrame = AnimationFrame::create(spriteFrame, 1, ValueMap());
|
||||||
CCARRAY_FOREACH(pFrames, pObj)
|
_frames.pushBack(animFrame);
|
||||||
{
|
|
||||||
SpriteFrame* frame = static_cast<SpriteFrame*>(pObj);
|
|
||||||
AnimationFrame *animFrame = new AnimationFrame();
|
|
||||||
animFrame->initWithSpriteFrame(frame, 1, NULL);
|
|
||||||
_frames->addObject(animFrame);
|
|
||||||
animFrame->release();
|
|
||||||
|
|
||||||
_totalDelayUnits++;
|
_totalDelayUnits++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Animation::initWithAnimationFrames(Array* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops)
|
bool Animation::initWithAnimationFrames(const Vector<AnimationFrame*>& arrayOfAnimationFrames, float delayPerUnit, unsigned int loops)
|
||||||
{
|
{
|
||||||
CCARRAY_VERIFY_TYPE(arrayOfAnimationFrames, AnimationFrame*);
|
|
||||||
|
|
||||||
_delayPerUnit = delayPerUnit;
|
_delayPerUnit = delayPerUnit;
|
||||||
_loops = loops;
|
_loops = loops;
|
||||||
|
|
||||||
setFrames(Array::createWithArray(arrayOfAnimationFrames));
|
setFrames(arrayOfAnimationFrames);
|
||||||
|
|
||||||
Object* pObj = NULL;
|
for (auto& animFrame : _frames)
|
||||||
CCARRAY_FOREACH(_frames, pObj)
|
|
||||||
{
|
{
|
||||||
AnimationFrame* animFrame = static_cast<AnimationFrame*>(pObj);
|
|
||||||
_totalDelayUnits += animFrame->getDelayUnits();
|
_totalDelayUnits += animFrame->getDelayUnits();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -151,7 +150,6 @@ Animation::Animation()
|
||||||
: _totalDelayUnits(0.0f)
|
: _totalDelayUnits(0.0f)
|
||||||
, _delayPerUnit(0.0f)
|
, _delayPerUnit(0.0f)
|
||||||
, _duration(0.0f)
|
, _duration(0.0f)
|
||||||
, _frames(NULL)
|
|
||||||
, _restoreOriginalFrame(false)
|
, _restoreOriginalFrame(false)
|
||||||
, _loops(0)
|
, _loops(0)
|
||||||
{
|
{
|
||||||
|
@ -161,15 +159,12 @@ Animation::Animation()
|
||||||
Animation::~Animation(void)
|
Animation::~Animation(void)
|
||||||
{
|
{
|
||||||
CCLOGINFO("deallocing Animation: %p", this);
|
CCLOGINFO("deallocing Animation: %p", this);
|
||||||
CC_SAFE_RELEASE(_frames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::addSpriteFrame(SpriteFrame *pFrame)
|
void Animation::addSpriteFrame(SpriteFrame* spriteFrame)
|
||||||
{
|
{
|
||||||
AnimationFrame *animFrame = new AnimationFrame();
|
AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, 1.0f, ValueMap());
|
||||||
animFrame->initWithSpriteFrame(pFrame, 1.0f, NULL);
|
_frames.pushBack(animFrame);
|
||||||
_frames->addObject(animFrame);
|
|
||||||
animFrame->release();
|
|
||||||
|
|
||||||
// update duration
|
// update duration
|
||||||
_totalDelayUnits++;
|
_totalDelayUnits++;
|
||||||
|
|
|
@ -29,9 +29,11 @@ THE SOFTWARE.
|
||||||
#include "CCPlatformConfig.h"
|
#include "CCPlatformConfig.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCDictionary.h"
|
#include "CCValue.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
|
#include "CCVector.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -56,17 +58,10 @@ class CC_DLL AnimationFrame : public Object, public Clonable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @js ctor
|
* Creates the animation frame with a spriteframe, number of delay units and a notification user info
|
||||||
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
AnimationFrame();
|
static AnimationFrame* create(SpriteFrame* spriteFrame, float delayUnits, const ValueMap& userInfo);
|
||||||
/**
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual ~AnimationFrame();
|
|
||||||
|
|
||||||
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
|
|
||||||
bool initWithSpriteFrame(SpriteFrame* spriteFrame, float delayUnits, Dictionary* userInfo);
|
|
||||||
|
|
||||||
SpriteFrame* getSpriteFrame() const { return _spriteFrame; };
|
SpriteFrame* getSpriteFrame() const { return _spriteFrame; };
|
||||||
|
|
||||||
|
@ -86,13 +81,12 @@ public:
|
||||||
/** @brief Gets user infomation
|
/** @brief Gets user infomation
|
||||||
A AnimationFrameDisplayedNotification notification will be broadcast when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcast.
|
A AnimationFrameDisplayedNotification notification will be broadcast when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcast.
|
||||||
*/
|
*/
|
||||||
Dictionary* getUserInfo() const { return _userInfo; };
|
const ValueMap& getUserInfo() const { return _userInfo; };
|
||||||
|
ValueMap& getUserInfo() { return _userInfo; };
|
||||||
|
|
||||||
/** Sets user infomation */
|
/** Sets user infomation */
|
||||||
void setUserInfo(Dictionary* userInfo)
|
void setUserInfo(const ValueMap& userInfo)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(userInfo);
|
|
||||||
CC_SAFE_RELEASE(_userInfo);
|
|
||||||
_userInfo = userInfo;
|
_userInfo = userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +94,20 @@ public:
|
||||||
virtual AnimationFrame *clone() const override;
|
virtual AnimationFrame *clone() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @js ctor
|
||||||
|
*/
|
||||||
|
AnimationFrame();
|
||||||
|
/**
|
||||||
|
* @js NA
|
||||||
|
* @lua NA
|
||||||
|
*/
|
||||||
|
virtual ~AnimationFrame();
|
||||||
|
|
||||||
|
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
|
||||||
|
bool initWithSpriteFrame(SpriteFrame* spriteFrame, float delayUnits, const ValueMap& userInfo);
|
||||||
|
|
||||||
/** SpriteFrameName to be used */
|
/** SpriteFrameName to be used */
|
||||||
SpriteFrame* _spriteFrame;
|
SpriteFrame* _spriteFrame;
|
||||||
|
|
||||||
|
@ -107,7 +115,10 @@ protected:
|
||||||
float _delayUnits;
|
float _delayUnits;
|
||||||
|
|
||||||
/** A AnimationFrameDisplayedNotification notification will be broadcast when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcast. */
|
/** A AnimationFrameDisplayedNotification notification will be broadcast when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcast. */
|
||||||
Dictionary* _userInfo;
|
ValueMap _userInfo;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CC_DISALLOW_COPY_AND_ASSIGN(AnimationFrame);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,34 +146,13 @@ public:
|
||||||
The frames will be added with one "delay unit".
|
The frames will be added with one "delay unit".
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
static Animation* createWithSpriteFrames(Array* arrayOfSpriteFrameNames, float delay = 0.0f);
|
static Animation* createWithSpriteFrames(const Vector<SpriteFrame*>& arrayOfSpriteFrameNames, float delay = 0.0f);
|
||||||
|
|
||||||
/* Creates an animation with an array of AnimationFrame, the delay per units in seconds and and how many times it should be executed.
|
/* Creates an animation with an array of AnimationFrame, the delay per units in seconds and and how many times it should be executed.
|
||||||
@since v2.0
|
@since v2.0
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
static Animation* create(Array *arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops = 1);
|
static Animation* create(const Vector<AnimationFrame*>& arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops = 1);
|
||||||
/**
|
|
||||||
* @js ctor
|
|
||||||
*/
|
|
||||||
Animation();
|
|
||||||
/**
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
virtual ~Animation(void);
|
|
||||||
|
|
||||||
bool init();
|
|
||||||
|
|
||||||
/** Initializes a Animation with frames and a delay between frames
|
|
||||||
@since v0.99.5
|
|
||||||
*/
|
|
||||||
bool initWithSpriteFrames(Array *pFrames, float delay = 0.0f);
|
|
||||||
|
|
||||||
/** Initializes a Animation with AnimationFrame
|
|
||||||
@since v2.0
|
|
||||||
*/
|
|
||||||
bool initWithAnimationFrames(Array* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops);
|
|
||||||
|
|
||||||
/** Adds a SpriteFrame to a Animation.
|
/** Adds a SpriteFrame to a Animation.
|
||||||
The frame will be added with one "delay unit".
|
The frame will be added with one "delay unit".
|
||||||
|
@ -199,13 +189,11 @@ public:
|
||||||
float getDuration() const;
|
float getDuration() const;
|
||||||
|
|
||||||
/** Gets the array of AnimationFrames */
|
/** Gets the array of AnimationFrames */
|
||||||
Array* getFrames() const { return _frames; };
|
const Vector<AnimationFrame*>& getFrames() const { return _frames; };
|
||||||
|
|
||||||
/** Sets the array of AnimationFrames */
|
/** Sets the array of AnimationFrames */
|
||||||
void setFrames(Array* frames)
|
void setFrames(const Vector<AnimationFrame*>& frames)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(frames);
|
|
||||||
CC_SAFE_RELEASE(_frames);
|
|
||||||
_frames = frames;
|
_frames = frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +213,22 @@ public:
|
||||||
virtual Animation *clone() const override;
|
virtual Animation *clone() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Animation();
|
||||||
|
virtual ~Animation(void);
|
||||||
|
|
||||||
|
/** Initializes a Animation */
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
/** Initializes a Animation with frames and a delay between frames
|
||||||
|
@since v0.99.5
|
||||||
|
*/
|
||||||
|
bool initWithSpriteFrames(const Vector<SpriteFrame*>& arrayOfSpriteFrameNames, float delay = 0.0f);
|
||||||
|
|
||||||
|
/** Initializes a Animation with AnimationFrame
|
||||||
|
@since v2.0
|
||||||
|
*/
|
||||||
|
bool initWithAnimationFrames(const Vector<AnimationFrame*>& arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops);
|
||||||
|
|
||||||
/** total Delay units of the Animation. */
|
/** total Delay units of the Animation. */
|
||||||
float _totalDelayUnits;
|
float _totalDelayUnits;
|
||||||
|
|
||||||
|
@ -235,13 +239,16 @@ protected:
|
||||||
float _duration;
|
float _duration;
|
||||||
|
|
||||||
/** array of AnimationFrames */
|
/** array of AnimationFrames */
|
||||||
Array* _frames;
|
Vector<AnimationFrame*> _frames;
|
||||||
|
|
||||||
/** whether or not it shall restore the original frame when the animation finishes */
|
/** whether or not it shall restore the original frame when the animation finishes */
|
||||||
bool _restoreOriginalFrame;
|
bool _restoreOriginalFrame;
|
||||||
|
|
||||||
/** how many times the animation is going to loop. 0 means animation is not animated. 1, animation is executed one time, ... */
|
/** how many times the animation is going to loop. 0 means animation is not animated. 1, animation is executed one time, ... */
|
||||||
unsigned int _loops;
|
unsigned int _loops;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CC_DISALLOW_COPY_AND_ASSIGN(Animation);
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of sprite_nodes group
|
// end of sprite_nodes group
|
||||||
|
|
|
@ -55,25 +55,21 @@ void AnimationCache::destroyInstance()
|
||||||
|
|
||||||
bool AnimationCache::init()
|
bool AnimationCache::init()
|
||||||
{
|
{
|
||||||
_animations = new Dictionary;
|
|
||||||
_animations->init();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationCache::AnimationCache()
|
AnimationCache::AnimationCache()
|
||||||
: _animations(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationCache::~AnimationCache()
|
AnimationCache::~AnimationCache()
|
||||||
{
|
{
|
||||||
CCLOGINFO("deallocing AnimationCache: %p", this);
|
CCLOGINFO("deallocing AnimationCache: %p", this);
|
||||||
CC_SAFE_RELEASE(_animations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationCache::addAnimation(Animation *animation, const std::string& name)
|
void AnimationCache::addAnimation(Animation *animation, const std::string& name)
|
||||||
{
|
{
|
||||||
_animations->setObject(animation, name);
|
_animations.insert(name, animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationCache::removeAnimation(const std::string& name)
|
void AnimationCache::removeAnimation(const std::string& name)
|
||||||
|
@ -81,157 +77,143 @@ void AnimationCache::removeAnimation(const std::string& name)
|
||||||
if (name.size()==0)
|
if (name.size()==0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_animations->removeObjectForKey(name);
|
_animations.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation* AnimationCache::getAnimation(const std::string& name)
|
Animation* AnimationCache::getAnimation(const std::string& name)
|
||||||
{
|
{
|
||||||
return (Animation*)_animations->objectForKey(name);
|
return _animations.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationCache::parseVersion1(Dictionary* animations)
|
void AnimationCache::parseVersion1(const ValueMap& animations)
|
||||||
{
|
{
|
||||||
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
|
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
|
||||||
|
|
||||||
DictElement* element = NULL;
|
for (auto iter = animations.cbegin(); iter != animations.cend(); ++iter)
|
||||||
CCDICT_FOREACH(animations, element)
|
|
||||||
{
|
{
|
||||||
Dictionary* animationDict = static_cast<Dictionary*>(element->getObject());
|
const ValueMap& animationDict = iter->second.asValueMap();
|
||||||
Array* frameNames = static_cast<Array*>(animationDict->objectForKey("frames"));
|
const ValueVector& frameNames = animationDict.at("frames").asValueVector();
|
||||||
float delay = animationDict->valueForKey("delay")->floatValue();
|
float delay = animationDict.at("delay").asFloat();
|
||||||
Animation* animation = NULL;
|
Animation* animation = nullptr;
|
||||||
|
|
||||||
if ( frameNames == NULL )
|
if ( frameNames.empty() )
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", element->getStrKey());
|
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", iter->first.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array* frames = Array::createWithCapacity(frameNames->count());
|
Vector<AnimationFrame*> frames(static_cast<int>(frameNames.size()));
|
||||||
frames->retain();
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
for (auto& frameName : frameNames)
|
||||||
CCARRAY_FOREACH(frameNames, pObj)
|
|
||||||
{
|
{
|
||||||
const std::string& frameName = static_cast<String*>(pObj)->getCString();
|
SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName.asString());
|
||||||
SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName);
|
|
||||||
|
|
||||||
if ( ! spriteFrame ) {
|
if ( ! spriteFrame ) {
|
||||||
CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", element->getStrKey(), frameName.c_str());
|
CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", iter->first.c_str(), frameName.asString().c_str());
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationFrame* animFrame = new AnimationFrame();
|
AnimationFrame* animFrame = AnimationFrame::create(spriteFrame, 1, ValueMap());
|
||||||
animFrame->initWithSpriteFrame(spriteFrame, 1, NULL);
|
frames.pushBack(animFrame);
|
||||||
frames->addObject(animFrame);
|
|
||||||
animFrame->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( frames->count() == 0 ) {
|
if ( frames.size() == 0 )
|
||||||
CCLOG("cocos2d: AnimationCache: None of the frames for animation '%s' were found in the SpriteFrameCache. Animation is not being added to the Animation Cache.", element->getStrKey());
|
{
|
||||||
|
CCLOG("cocos2d: AnimationCache: None of the frames for animation '%s' were found in the SpriteFrameCache. Animation is not being added to the Animation Cache.", iter->first.c_str());
|
||||||
continue;
|
continue;
|
||||||
} else if ( frames->count() != frameNames->count() ) {
|
}
|
||||||
CCLOG("cocos2d: AnimationCache: An animation in your dictionary refers to a frame which is not in the SpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", element->getStrKey());
|
else if ( frames.size() != frameNames.size() )
|
||||||
|
{
|
||||||
|
CCLOG("cocos2d: AnimationCache: An animation in your dictionary refers to a frame which is not in the SpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", iter->first.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
animation = Animation::create(frames, delay, 1);
|
animation = Animation::create(frames, delay, 1);
|
||||||
|
|
||||||
AnimationCache::getInstance()->addAnimation(animation, element->getStrKey());
|
AnimationCache::getInstance()->addAnimation(animation, iter->first.c_str());
|
||||||
frames->release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationCache::parseVersion2(Dictionary* animations)
|
void AnimationCache::parseVersion2(const ValueMap& animations)
|
||||||
{
|
{
|
||||||
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
|
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
|
||||||
|
|
||||||
DictElement* element = NULL;
|
for (auto iter = animations.cbegin(); iter != animations.cend(); ++iter)
|
||||||
CCDICT_FOREACH(animations, element)
|
|
||||||
{
|
{
|
||||||
const char* name = element->getStrKey();
|
std::string name = iter->first;
|
||||||
Dictionary* animationDict = static_cast<Dictionary*>(element->getObject());
|
ValueMap& animationDict = const_cast<ValueMap&>(iter->second.asValueMap());
|
||||||
|
|
||||||
const String* loops = animationDict->valueForKey("loops");
|
const Value& loops = animationDict["loops"];
|
||||||
bool restoreOriginalFrame = animationDict->valueForKey("restoreOriginalFrame")->boolValue();
|
bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].asBool();
|
||||||
|
|
||||||
Array* frameArray = static_cast<Array*>(animationDict->objectForKey("frames"));
|
ValueVector& frameArray = animationDict["frames"].asValueVector();
|
||||||
|
|
||||||
if ( frameArray == NULL ) {
|
if ( frameArray.empty() )
|
||||||
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name);
|
{
|
||||||
|
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array of AnimationFrames
|
// Array of AnimationFrames
|
||||||
Array* array = Array::createWithCapacity(frameArray->count());
|
Vector<AnimationFrame*> array(static_cast<int>(frameArray.size()));
|
||||||
array->retain();
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
for (auto& obj : frameArray)
|
||||||
CCARRAY_FOREACH(frameArray, pObj)
|
|
||||||
{
|
{
|
||||||
Dictionary* entry = static_cast<Dictionary*>(pObj);
|
ValueMap& entry = obj.asValueMap();
|
||||||
|
std::string spriteFrameName = entry["spriteframe"].asString();
|
||||||
const char* spriteFrameName = entry->valueForKey("spriteframe")->getCString();
|
|
||||||
SpriteFrame *spriteFrame = frameCache->getSpriteFrameByName(spriteFrameName);
|
SpriteFrame *spriteFrame = frameCache->getSpriteFrameByName(spriteFrameName);
|
||||||
|
|
||||||
if( ! spriteFrame ) {
|
if( ! spriteFrame ) {
|
||||||
CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", name, spriteFrameName);
|
CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", name.c_str(), spriteFrameName.c_str());
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float delayUnits = entry->valueForKey("delayUnits")->floatValue();
|
float delayUnits = entry["delayUnits"].asFloat();
|
||||||
Dictionary* userInfo = (Dictionary*)entry->objectForKey("notification");
|
Value& userInfo = entry["notification"];
|
||||||
|
|
||||||
AnimationFrame *animFrame = new AnimationFrame();
|
AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, delayUnits, userInfo.asValueMap());
|
||||||
animFrame->initWithSpriteFrame(spriteFrame, delayUnits, userInfo);
|
|
||||||
|
|
||||||
array->addObject(animFrame);
|
array.pushBack(animFrame);
|
||||||
animFrame->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float delayPerUnit = animationDict->valueForKey("delayPerUnit")->floatValue();
|
float delayPerUnit = animationDict["delayPerUnit"].asFloat();
|
||||||
Animation *animation = new Animation();
|
Animation *animation = Animation::create(array, delayPerUnit, loops.getType() != Value::Type::NONE ? loops.asInt() : 1);
|
||||||
animation->initWithAnimationFrames(array, delayPerUnit, 0 != loops->length() ? loops->intValue() : 1);
|
|
||||||
array->release();
|
|
||||||
|
|
||||||
animation->setRestoreOriginalFrame(restoreOriginalFrame);
|
animation->setRestoreOriginalFrame(restoreOriginalFrame);
|
||||||
|
|
||||||
AnimationCache::getInstance()->addAnimation(animation, name);
|
AnimationCache::getInstance()->addAnimation(animation, name);
|
||||||
animation->release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationCache::addAnimationsWithDictionary(Dictionary* dictionary)
|
void AnimationCache::addAnimationsWithDictionary(const ValueMap& dictionary)
|
||||||
|
{
|
||||||
|
if ( dictionary.find("animations") == dictionary.end() )
|
||||||
{
|
{
|
||||||
Dictionary* animations = (Dictionary*)dictionary->objectForKey("animations");
|
|
||||||
|
|
||||||
if ( animations == NULL ) {
|
|
||||||
CCLOG("cocos2d: AnimationCache: No animations were found in provided dictionary.");
|
CCLOG("cocos2d: AnimationCache: No animations were found in provided dictionary.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Value& animations = dictionary.at("animations");
|
||||||
unsigned int version = 1;
|
unsigned int version = 1;
|
||||||
Dictionary* properties = (Dictionary*)dictionary->objectForKey("properties");
|
|
||||||
if( properties )
|
|
||||||
{
|
|
||||||
version = properties->valueForKey("format")->intValue();
|
|
||||||
Array* spritesheets = (Array*)properties->objectForKey("spritesheets");
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
if( dictionary.find("properties") != dictionary.end() )
|
||||||
CCARRAY_FOREACH(spritesheets, pObj)
|
|
||||||
{
|
{
|
||||||
String* name = static_cast<String*>(pObj);
|
const ValueMap& properties = dictionary.at("properties").asValueMap();
|
||||||
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(name->getCString());
|
version = properties.at("format").asInt();
|
||||||
}
|
const ValueVector& spritesheets = properties.at("spritesheets").asValueVector();
|
||||||
|
|
||||||
|
std::for_each(spritesheets.cbegin(), spritesheets.cend(), [](const Value& value){
|
||||||
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(value.asString());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case 1:
|
case 1:
|
||||||
parseVersion1(animations);
|
parseVersion1(animations.asValueMap());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
parseVersion2(animations);
|
parseVersion2(animations.asValueMap());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CCASSERT(false, "Invalid animation format");
|
CCASSERT(false, "Invalid animation format");
|
||||||
|
@ -244,9 +226,9 @@ void AnimationCache::addAnimationsWithFile(const std::string& plist)
|
||||||
CCASSERT( plist.size()>0, "Invalid texture file name");
|
CCASSERT( plist.size()>0, "Invalid texture file name");
|
||||||
|
|
||||||
std::string path = FileUtils::getInstance()->fullPathForFilename(plist);
|
std::string path = FileUtils::getInstance()->fullPathForFilename(plist);
|
||||||
Dictionary* dict = Dictionary::createWithContentsOfFile(path.c_str());
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(path);
|
||||||
|
|
||||||
CCASSERT( dict, "CCAnimationCache: File could not be found");
|
CCASSERT( !dict.empty(), "CCAnimationCache: File could not be found");
|
||||||
|
|
||||||
addAnimationsWithDictionary(dict);
|
addAnimationsWithDictionary(dict);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ THE SOFTWARE.
|
||||||
#define __CC_ANIMATION_CACHE_H__
|
#define __CC_ANIMATION_CACHE_H__
|
||||||
|
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCDictionary.h"
|
#include "CCMap.h"
|
||||||
|
#include "CCValue.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -104,7 +104,7 @@ public:
|
||||||
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
||||||
@since v1.1
|
@since v1.1
|
||||||
*/
|
*/
|
||||||
void addAnimationsWithDictionary(Dictionary* dictionary);
|
void addAnimationsWithDictionary(const ValueMap& dictionary);
|
||||||
|
|
||||||
/** Adds an animation from a plist file.
|
/** Adds an animation from a plist file.
|
||||||
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
||||||
|
@ -115,11 +115,11 @@ public:
|
||||||
void addAnimationsWithFile(const std::string& plist);
|
void addAnimationsWithFile(const std::string& plist);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseVersion1(Dictionary* animations);
|
void parseVersion1(const ValueMap& animations);
|
||||||
void parseVersion2(Dictionary* animations);
|
void parseVersion2(const ValueMap& animations);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Dictionary* _animations;
|
Map<std::string, Animation*> _animations;
|
||||||
static AnimationCache* s_pSharedAnimationCache;
|
static AnimationCache* s_pSharedAnimationCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ AtlasNode::~AtlasNode()
|
||||||
CC_SAFE_RELEASE(_textureAtlas);
|
CC_SAFE_RELEASE(_textureAtlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
AtlasNode * AtlasNode::create(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender)
|
AtlasNode * AtlasNode::create(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender)
|
||||||
{
|
{
|
||||||
AtlasNode * pRet = new AtlasNode();
|
AtlasNode * pRet = new AtlasNode();
|
||||||
if (pRet->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender))
|
if (pRet->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender))
|
||||||
|
@ -73,14 +73,14 @@ AtlasNode * AtlasNode::create(const std::string& tile, long tileWidth, long tile
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtlasNode::initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender)
|
bool AtlasNode::initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender)
|
||||||
{
|
{
|
||||||
CCASSERT(tile.size() > 0, "file size should not be empty");
|
CCASSERT(tile.size() > 0, "file size should not be empty");
|
||||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile);
|
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile);
|
||||||
return initWithTexture(texture, tileWidth, tileHeight, itemsToRender);
|
return initWithTexture(texture, tileWidth, tileHeight, itemsToRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtlasNode::initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender)
|
bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender)
|
||||||
{
|
{
|
||||||
_itemWidth = tileWidth;
|
_itemWidth = tileWidth;
|
||||||
_itemHeight = tileHeight;
|
_itemHeight = tileHeight;
|
||||||
|
@ -245,12 +245,12 @@ TextureAtlas * AtlasNode::getTextureAtlas() const
|
||||||
return _textureAtlas;
|
return _textureAtlas;
|
||||||
}
|
}
|
||||||
|
|
||||||
long AtlasNode::getQuadsToDraw() const
|
int AtlasNode::getQuadsToDraw() const
|
||||||
{
|
{
|
||||||
return _quadsToDraw;
|
return _quadsToDraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtlasNode::setQuadsToDraw(long uQuadsToDraw)
|
void AtlasNode::setQuadsToDraw(int uQuadsToDraw)
|
||||||
{
|
{
|
||||||
_quadsToDraw = uQuadsToDraw;
|
_quadsToDraw = uQuadsToDraw;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** creates a AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
/** creates a AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
||||||
static AtlasNode * create(const std::string& filename, long tileWidth, long tileHeight, long itemsToRender);
|
static AtlasNode * create(const std::string& filename, int tileWidth, int tileHeight, int itemsToRender);
|
||||||
|
|
||||||
/** updates the Atlas (indexed vertex array).
|
/** updates the Atlas (indexed vertex array).
|
||||||
* Shall be overridden in subclasses
|
* Shall be overridden in subclasses
|
||||||
|
@ -62,8 +62,8 @@ public:
|
||||||
void setTextureAtlas(TextureAtlas* textureAtlas);
|
void setTextureAtlas(TextureAtlas* textureAtlas);
|
||||||
TextureAtlas* getTextureAtlas() const;
|
TextureAtlas* getTextureAtlas() const;
|
||||||
|
|
||||||
void setQuadsToDraw(long quadsToDraw);
|
void setQuadsToDraw(int quadsToDraw);
|
||||||
long getQuadsToDraw() const;
|
int getQuadsToDraw() const;
|
||||||
|
|
||||||
|
|
||||||
// Overrides
|
// Overrides
|
||||||
|
@ -95,10 +95,10 @@ protected:
|
||||||
virtual ~AtlasNode();
|
virtual ~AtlasNode();
|
||||||
|
|
||||||
/** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
/** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
||||||
bool initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender);
|
bool initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender);
|
||||||
|
|
||||||
/** initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/
|
/** initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/
|
||||||
bool initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender);
|
bool initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender);
|
||||||
|
|
||||||
void calculateMaxItems();
|
void calculateMaxItems();
|
||||||
void updateBlendFunc();
|
void updateBlendFunc();
|
||||||
|
@ -108,14 +108,14 @@ protected:
|
||||||
void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor);
|
void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor);
|
||||||
|
|
||||||
//! chars per row
|
//! chars per row
|
||||||
long _itemsPerRow;
|
int _itemsPerRow;
|
||||||
//! chars per column
|
//! chars per column
|
||||||
long _itemsPerColumn;
|
int _itemsPerColumn;
|
||||||
|
|
||||||
//! width of each char
|
//! width of each char
|
||||||
long _itemWidth;
|
int _itemWidth;
|
||||||
//! height of each char
|
//! height of each char
|
||||||
long _itemHeight;
|
int _itemHeight;
|
||||||
|
|
||||||
Color3B _colorUnmodified;
|
Color3B _colorUnmodified;
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ protected:
|
||||||
BlendFunc _blendFunc;
|
BlendFunc _blendFunc;
|
||||||
|
|
||||||
// quads to draw
|
// quads to draw
|
||||||
long _quadsToDraw;
|
int _quadsToDraw;
|
||||||
// color uniform
|
// color uniform
|
||||||
GLint _uniformColor;
|
GLint _uniformColor;
|
||||||
// This varible is only used for LabelAtlas FPS display. So plz don't modify its value.
|
// This varible is only used for LabelAtlas FPS display. So plz don't modify its value.
|
||||||
|
|
|
@ -39,13 +39,10 @@ static GLint g_sStencilBits = -1;
|
||||||
static void setProgram(Node *n, GLProgram *p)
|
static void setProgram(Node *n, GLProgram *p)
|
||||||
{
|
{
|
||||||
n->setShaderProgram(p);
|
n->setShaderProgram(p);
|
||||||
if (!n->getChildren()) return;
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
n->getChildren().forEach([p](Node* child){
|
||||||
CCARRAY_FOREACH(n->getChildren(), pObj)
|
setProgram(child, p);
|
||||||
{
|
});
|
||||||
setProgram(static_cast<Node*>(pObj), p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClippingNode::ClippingNode()
|
ClippingNode::ClippingNode()
|
||||||
|
|
|
@ -540,8 +540,6 @@ CC_DEPRECATED_ATTRIBUTE typedef Bool CCBool;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Float CCFloat;
|
CC_DEPRECATED_ATTRIBUTE typedef Float CCFloat;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Double CCDouble;
|
CC_DEPRECATED_ATTRIBUTE typedef Double CCDouble;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Data CCData;
|
CC_DEPRECATED_ATTRIBUTE typedef Data CCData;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Set CCSet;
|
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Array CCArray;
|
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Dictionary CCDictionary;
|
CC_DEPRECATED_ATTRIBUTE typedef Dictionary CCDictionary;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef DataVisitor CCDataVisitor;
|
CC_DEPRECATED_ATTRIBUTE typedef DataVisitor CCDataVisitor;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef PrettyPrinter CCPrettyPrinter;
|
CC_DEPRECATED_ATTRIBUTE typedef PrettyPrinter CCPrettyPrinter;
|
||||||
|
@ -549,7 +547,6 @@ CC_DEPRECATED_ATTRIBUTE typedef Acceleration CCAcceleration;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef TextureAtlas CCTextureAtlas;
|
CC_DEPRECATED_ATTRIBUTE typedef TextureAtlas CCTextureAtlas;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Configuration CCConfiguration;
|
CC_DEPRECATED_ATTRIBUTE typedef Configuration CCConfiguration;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef PointArray CCPointArray;
|
CC_DEPRECATED_ATTRIBUTE typedef PointArray CCPointArray;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef SetIterator CCSetIterator;
|
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef RemoveSelf CCRemoveSelf;
|
CC_DEPRECATED_ATTRIBUTE typedef RemoveSelf CCRemoveSelf;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef IMEDelegate CCIMEDelegate;
|
CC_DEPRECATED_ATTRIBUTE typedef IMEDelegate CCIMEDelegate;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef IMEKeyboardNotificationInfo CCIMEKeyboardNotificationInfo;
|
CC_DEPRECATED_ATTRIBUTE typedef IMEKeyboardNotificationInfo CCIMEKeyboardNotificationInfo;
|
||||||
|
@ -568,7 +565,6 @@ CC_DEPRECATED_ATTRIBUTE typedef Speed CCSpeed;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Follow CCFollow;
|
CC_DEPRECATED_ATTRIBUTE typedef Follow CCFollow;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef GLProgram CCGLProgram;
|
CC_DEPRECATED_ATTRIBUTE typedef GLProgram CCGLProgram;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Touch CCTouch;
|
CC_DEPRECATED_ATTRIBUTE typedef Touch CCTouch;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Set CCSet;
|
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Texture2D CCTexture2D;
|
CC_DEPRECATED_ATTRIBUTE typedef Texture2D CCTexture2D;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Node CCNode;
|
CC_DEPRECATED_ATTRIBUTE typedef Node CCNode;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef NodeRGBA CCNodeRGBA;
|
CC_DEPRECATED_ATTRIBUTE typedef NodeRGBA CCNodeRGBA;
|
||||||
|
@ -1028,6 +1024,12 @@ CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLBindVAO(GLuint vaoId) { GL::bindV
|
||||||
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLEnable( int flags ) { /* ignore */ };
|
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLEnable( int flags ) { /* ignore */ };
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef int ccGLServerState;
|
CC_DEPRECATED_ATTRIBUTE typedef int ccGLServerState;
|
||||||
|
|
||||||
|
CC_DEPRECATED_ATTRIBUTE typedef __Set CCSet;
|
||||||
|
CC_DEPRECATED_ATTRIBUTE typedef __SetIterator CCSetIterator;
|
||||||
|
CC_DEPRECATED_ATTRIBUTE typedef __Set Set;
|
||||||
|
CC_DEPRECATED_ATTRIBUTE typedef __SetIterator SetIterator;
|
||||||
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -110,8 +110,7 @@ bool Director::init(void)
|
||||||
|
|
||||||
_notificationNode = nullptr;
|
_notificationNode = nullptr;
|
||||||
|
|
||||||
_scenesStack = new Array();
|
_scenesStack.reserve(15);
|
||||||
_scenesStack->initWithCapacity(15);
|
|
||||||
|
|
||||||
// projection delegate if "Custom" projection is used
|
// projection delegate if "Custom" projection is used
|
||||||
_projectionDelegate = nullptr;
|
_projectionDelegate = nullptr;
|
||||||
|
@ -164,7 +163,6 @@ Director::~Director(void)
|
||||||
|
|
||||||
CC_SAFE_RELEASE(_runningScene);
|
CC_SAFE_RELEASE(_runningScene);
|
||||||
CC_SAFE_RELEASE(_notificationNode);
|
CC_SAFE_RELEASE(_notificationNode);
|
||||||
CC_SAFE_RELEASE(_scenesStack);
|
|
||||||
CC_SAFE_RELEASE(_scheduler);
|
CC_SAFE_RELEASE(_scheduler);
|
||||||
CC_SAFE_RELEASE(_actionManager);
|
CC_SAFE_RELEASE(_actionManager);
|
||||||
CC_SAFE_RELEASE(_eventDispatcher);
|
CC_SAFE_RELEASE(_eventDispatcher);
|
||||||
|
@ -597,10 +595,10 @@ void Director::replaceScene(Scene *scene)
|
||||||
CCASSERT(_runningScene, "Use runWithScene: instead to start the director");
|
CCASSERT(_runningScene, "Use runWithScene: instead to start the director");
|
||||||
CCASSERT(scene != nullptr, "the scene should not be null");
|
CCASSERT(scene != nullptr, "the scene should not be null");
|
||||||
|
|
||||||
unsigned int index = _scenesStack->count();
|
int index = _scenesStack.size();
|
||||||
|
|
||||||
_sendCleanupToScene = true;
|
_sendCleanupToScene = true;
|
||||||
_scenesStack->replaceObjectAtIndex(index - 1, scene);
|
_scenesStack.replace(index - 1, scene);
|
||||||
|
|
||||||
_nextScene = scene;
|
_nextScene = scene;
|
||||||
}
|
}
|
||||||
|
@ -611,7 +609,7 @@ void Director::pushScene(Scene *scene)
|
||||||
|
|
||||||
_sendCleanupToScene = false;
|
_sendCleanupToScene = false;
|
||||||
|
|
||||||
_scenesStack->addObject(scene);
|
_scenesStack.pushBack(scene);
|
||||||
_nextScene = scene;
|
_nextScene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,8 +617,8 @@ void Director::popScene(void)
|
||||||
{
|
{
|
||||||
CCASSERT(_runningScene != nullptr, "running scene should not null");
|
CCASSERT(_runningScene != nullptr, "running scene should not null");
|
||||||
|
|
||||||
_scenesStack->removeLastObject();
|
_scenesStack.popBack();
|
||||||
unsigned int c = _scenesStack->count();
|
int c = _scenesStack.size();
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
{
|
{
|
||||||
|
@ -629,7 +627,7 @@ void Director::popScene(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_sendCleanupToScene = true;
|
_sendCleanupToScene = true;
|
||||||
_nextScene = (Scene*)_scenesStack->getObjectAtIndex(c - 1);
|
_nextScene = _scenesStack.at(c - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,7 +639,7 @@ void Director::popToRootScene(void)
|
||||||
void Director::popToSceneStackLevel(int level)
|
void Director::popToSceneStackLevel(int level)
|
||||||
{
|
{
|
||||||
CCASSERT(_runningScene != nullptr, "A running Scene is needed");
|
CCASSERT(_runningScene != nullptr, "A running Scene is needed");
|
||||||
int c = static_cast<int>(_scenesStack->count());
|
int c = _scenesStack.size();
|
||||||
|
|
||||||
// level 0? -> end
|
// level 0? -> end
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
|
@ -657,7 +655,7 @@ void Director::popToSceneStackLevel(int level)
|
||||||
// pop stack until reaching desired level
|
// pop stack until reaching desired level
|
||||||
while (c > level)
|
while (c > level)
|
||||||
{
|
{
|
||||||
Scene *current = (Scene*)_scenesStack->getLastObject();
|
auto current = _scenesStack.back();
|
||||||
|
|
||||||
if (current->isRunning())
|
if (current->isRunning())
|
||||||
{
|
{
|
||||||
|
@ -666,11 +664,11 @@ void Director::popToSceneStackLevel(int level)
|
||||||
}
|
}
|
||||||
|
|
||||||
current->cleanup();
|
current->cleanup();
|
||||||
_scenesStack->removeLastObject();
|
_scenesStack.popBack();
|
||||||
--c;
|
--c;
|
||||||
}
|
}
|
||||||
|
|
||||||
_nextScene = (Scene*)_scenesStack->getLastObject();
|
_nextScene = _scenesStack.back();
|
||||||
_sendCleanupToScene = false;
|
_sendCleanupToScene = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,7 +699,7 @@ void Director::purgeDirector()
|
||||||
|
|
||||||
// remove all objects, but don't release it.
|
// remove all objects, but don't release it.
|
||||||
// runWithScene might be executed after 'end'.
|
// runWithScene might be executed after 'end'.
|
||||||
_scenesStack->removeAllObjects();
|
_scenesStack.clear();
|
||||||
|
|
||||||
stopAnimation();
|
stopAnimation();
|
||||||
|
|
||||||
|
@ -857,7 +855,7 @@ void Director::calculateMPF()
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the FPS image data pointer and len
|
// returns the FPS image data pointer and len
|
||||||
void Director::getFPSImageData(unsigned char** datapointer, long* length)
|
void Director::getFPSImageData(unsigned char** datapointer, ssize_t* length)
|
||||||
{
|
{
|
||||||
// XXX fixed me if it should be used
|
// XXX fixed me if it should be used
|
||||||
*datapointer = cc_fps_images_png;
|
*datapointer = cc_fps_images_png;
|
||||||
|
@ -880,7 +878,7 @@ void Director::createStatsLabel()
|
||||||
Texture2D::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat();
|
Texture2D::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat();
|
||||||
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
||||||
unsigned char *data = nullptr;
|
unsigned char *data = nullptr;
|
||||||
long dataLength = 0;
|
ssize_t dataLength = 0;
|
||||||
getFPSImageData(&data, &dataLength);
|
getFPSImageData(&data, &dataLength);
|
||||||
|
|
||||||
Image* image = new Image();
|
Image* image = new Image();
|
||||||
|
@ -1037,9 +1035,6 @@ void DisplayLinkDirector::mainLoop()
|
||||||
}
|
}
|
||||||
else if (! _invalid)
|
else if (! _invalid)
|
||||||
{
|
{
|
||||||
// invoke call back from other thread
|
|
||||||
ThreadHelper::doCallback();
|
|
||||||
|
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// release the objects
|
// release the objects
|
||||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCArray.h"
|
#include "CCVector.h"
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "kazmath/mat4.h"
|
#include "kazmath/mat4.h"
|
||||||
#include "CCLabelAtlas.h"
|
#include "CCLabelAtlas.h"
|
||||||
|
@ -379,7 +379,7 @@ protected:
|
||||||
void showStats();
|
void showStats();
|
||||||
void createStatsLabel();
|
void createStatsLabel();
|
||||||
void calculateMPF();
|
void calculateMPF();
|
||||||
void getFPSImageData(unsigned char** datapointer, long* length);
|
void getFPSImageData(unsigned char** datapointer, ssize_t* length);
|
||||||
|
|
||||||
/** calculates delta time since last time it was called */
|
/** calculates delta time since last time it was called */
|
||||||
void calculateDeltaTime();
|
void calculateDeltaTime();
|
||||||
|
@ -446,7 +446,7 @@ protected:
|
||||||
bool _sendCleanupToScene;
|
bool _sendCleanupToScene;
|
||||||
|
|
||||||
/* scheduled scenes */
|
/* scheduled scenes */
|
||||||
Array* _scenesStack;
|
Vector<Scene*> _scenesStack;
|
||||||
|
|
||||||
/* last time the main loop was updated */
|
/* last time the main loop was updated */
|
||||||
struct timeval *_lastUpdate;
|
struct timeval *_lastUpdate;
|
||||||
|
|
|
@ -142,7 +142,7 @@ DrawNode* DrawNode::create()
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawNode::ensureCapacity(long count)
|
void DrawNode::ensureCapacity(int count)
|
||||||
{
|
{
|
||||||
CCASSERT(count>=0, "capacity must be >= 0");
|
CCASSERT(count>=0, "capacity must be >= 0");
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ void DrawNode::drawSegment(const Point &from, const Point &to, float radius, con
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor)
|
void DrawNode::drawPolygon(Point *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor)
|
||||||
{
|
{
|
||||||
CCASSERT(count >= 0, "invalid count value");
|
CCASSERT(count >= 0, "invalid count value");
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f
|
||||||
struct ExtrudeVerts* extrude = (struct ExtrudeVerts*)malloc(sizeof(struct ExtrudeVerts)*count);
|
struct ExtrudeVerts* extrude = (struct ExtrudeVerts*)malloc(sizeof(struct ExtrudeVerts)*count);
|
||||||
memset(extrude, 0, sizeof(struct ExtrudeVerts)*count);
|
memset(extrude, 0, sizeof(struct ExtrudeVerts)*count);
|
||||||
|
|
||||||
for (long i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
Vertex2F v0 = __v2f(verts[(i-1+count)%count]);
|
Vertex2F v0 = __v2f(verts[(i-1+count)%count]);
|
||||||
Vertex2F v1 = __v2f(verts[i]);
|
Vertex2F v1 = __v2f(verts[i]);
|
||||||
|
@ -362,15 +362,15 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f
|
||||||
|
|
||||||
bool outline = (borderColor.a > 0.0 && borderWidth > 0.0);
|
bool outline = (borderColor.a > 0.0 && borderWidth > 0.0);
|
||||||
|
|
||||||
unsigned int triangle_count = 3*count - 2;
|
auto triangle_count = 3*count - 2;
|
||||||
unsigned int vertex_count = 3*triangle_count;
|
auto vertex_count = 3*triangle_count;
|
||||||
ensureCapacity(vertex_count);
|
ensureCapacity(vertex_count);
|
||||||
|
|
||||||
V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
|
V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
|
||||||
V2F_C4B_T2F_Triangle *cursor = triangles;
|
V2F_C4B_T2F_Triangle *cursor = triangles;
|
||||||
|
|
||||||
float inset = (outline == false ? 0.5 : 0.0);
|
float inset = (outline == false ? 0.5 : 0.0);
|
||||||
for (long i = 0; i < count-2; i++)
|
for (int i = 0; i < count-2; i++)
|
||||||
{
|
{
|
||||||
Vertex2F v0 = v2fsub(__v2f(verts[0 ]), v2fmult(extrude[0 ].offset, inset));
|
Vertex2F v0 = v2fsub(__v2f(verts[0 ]), v2fmult(extrude[0 ].offset, inset));
|
||||||
Vertex2F v1 = v2fsub(__v2f(verts[i+1]), v2fmult(extrude[i+1].offset, inset));
|
Vertex2F v1 = v2fsub(__v2f(verts[i+1]), v2fmult(extrude[i+1].offset, inset));
|
||||||
|
@ -385,9 +385,9 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f
|
||||||
*cursor++ = tmp;
|
*cursor++ = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(long i = 0; i < count; i++)
|
for(int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
long j = (i+1)%count;
|
int j = (i+1)%count;
|
||||||
Vertex2F v0 = __v2f(verts[i]);
|
Vertex2F v0 = __v2f(verts[i]);
|
||||||
Vertex2F v1 = __v2f(verts[j]);
|
Vertex2F v1 = __v2f(verts[j]);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
* In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor)
|
* In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor)
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
void drawPolygon(Point *verts, long count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
|
void drawPolygon(Point *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
|
||||||
|
|
||||||
/** Clear the geometry in the node's buffer. */
|
/** Clear the geometry in the node's buffer. */
|
||||||
void clear();
|
void clear();
|
||||||
|
@ -92,13 +92,13 @@ protected:
|
||||||
virtual ~DrawNode();
|
virtual ~DrawNode();
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
|
|
||||||
void ensureCapacity(long count);
|
void ensureCapacity(int count);
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
GLuint _vao;
|
GLuint _vao;
|
||||||
GLuint _vbo;
|
GLuint _vbo;
|
||||||
|
|
||||||
long _bufferCapacity;
|
int _bufferCapacity;
|
||||||
GLsizei _bufferCount;
|
GLsizei _bufferCount;
|
||||||
V2F_C4B_T2F *_buffer;
|
V2F_C4B_T2F *_buffer;
|
||||||
|
|
||||||
|
|
|
@ -190,17 +190,17 @@ EventDispatcher::~EventDispatcher()
|
||||||
void EventDispatcher::visitTarget(Node* node)
|
void EventDispatcher::visitTarget(Node* node)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Array* children = node->getChildren();
|
auto& children = node->getChildren();
|
||||||
int childrenCount = children ? children->count() : 0;
|
|
||||||
|
auto childrenCount = children.size();
|
||||||
|
|
||||||
if(childrenCount > 0)
|
if(childrenCount > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
Node* child = nullptr;
|
Node* child = nullptr;
|
||||||
// visit children zOrder < 0
|
// visit children zOrder < 0
|
||||||
for( ; i < childrenCount; i++ )
|
for( ; i < childrenCount; i++ )
|
||||||
{
|
{
|
||||||
child = static_cast<Node*>( children->getObjectAtIndex(i) );
|
child = children.at(i);
|
||||||
|
|
||||||
if ( child && child->getZOrder() < 0 )
|
if ( child && child->getZOrder() < 0 )
|
||||||
visitTarget(child);
|
visitTarget(child);
|
||||||
|
@ -212,7 +212,7 @@ void EventDispatcher::visitTarget(Node* node)
|
||||||
|
|
||||||
for( ; i < childrenCount; i++ )
|
for( ; i < childrenCount; i++ )
|
||||||
{
|
{
|
||||||
child = static_cast<Node*>( children->getObjectAtIndex(i) );
|
child = children.at(i);
|
||||||
if (child)
|
if (child)
|
||||||
visitTarget(child);
|
visitTarget(child);
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
|
||||||
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
|
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
|
||||||
auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners();
|
auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners();
|
||||||
|
|
||||||
long i = 0;
|
int i = 0;
|
||||||
// priority < 0
|
// priority < 0
|
||||||
if (fixedPriorityListeners)
|
if (fixedPriorityListeners)
|
||||||
{
|
{
|
||||||
|
@ -527,7 +527,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
|
||||||
if (!shouldStopPropagation)
|
if (!shouldStopPropagation)
|
||||||
{
|
{
|
||||||
// priority > 0
|
// priority > 0
|
||||||
for (; i < static_cast<long>(fixedPriorityListeners->size()); ++i)
|
for (; i < fixedPriorityListeners->size(); ++i)
|
||||||
{
|
{
|
||||||
auto l = fixedPriorityListeners->at(i);
|
auto l = fixedPriorityListeners->at(i);
|
||||||
|
|
||||||
|
@ -976,7 +976,7 @@ void EventDispatcher::sortEventListenersOfFixedPriority(EventListener::ListenerI
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: Should use binary search
|
// FIXME: Should use binary search
|
||||||
long index = 0;
|
int index = 0;
|
||||||
for (auto& listener : *fixedlisteners)
|
for (auto& listener : *fixedlisteners)
|
||||||
{
|
{
|
||||||
if (listener->getFixedPriority() >= 0)
|
if (listener->getFixedPriority() >= 0)
|
||||||
|
@ -1080,7 +1080,7 @@ void EventDispatcher::removeCustomEventListeners(const std::string& customEventN
|
||||||
|
|
||||||
void EventDispatcher::removeAllEventListeners()
|
void EventDispatcher::removeAllEventListeners()
|
||||||
{
|
{
|
||||||
std::vector<int> types(_listeners.size());
|
std::vector<EventListener::ListenerID> types(_listeners.size());
|
||||||
|
|
||||||
for (auto iter = _listeners.begin(); iter != _listeners.end(); ++iter)
|
for (auto iter = _listeners.begin(); iter != _listeners.end(); ++iter)
|
||||||
{
|
{
|
||||||
|
|
|
@ -136,12 +136,12 @@ private:
|
||||||
|
|
||||||
inline std::vector<EventListener*>* getFixedPriorityListeners() const { return _fixedListeners; };
|
inline std::vector<EventListener*>* getFixedPriorityListeners() const { return _fixedListeners; };
|
||||||
inline std::vector<EventListener*>* getSceneGraphPriorityListeners() const { return _sceneGraphListeners; };
|
inline std::vector<EventListener*>* getSceneGraphPriorityListeners() const { return _sceneGraphListeners; };
|
||||||
inline long getGt0Index() const { return _gt0Index; };
|
inline int getGt0Index() const { return _gt0Index; };
|
||||||
inline void setGt0Index(long index) { _gt0Index = index; };
|
inline void setGt0Index(int index) { _gt0Index = index; };
|
||||||
private:
|
private:
|
||||||
std::vector<EventListener*>* _fixedListeners;
|
std::vector<EventListener*>* _fixedListeners;
|
||||||
std::vector<EventListener*>* _sceneGraphListeners;
|
std::vector<EventListener*>* _sceneGraphListeners;
|
||||||
long _gt0Index;
|
int _gt0Index;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Adds event listener with item */
|
/** Adds event listener with item */
|
||||||
|
|
|
@ -141,7 +141,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
||||||
}
|
}
|
||||||
|
|
||||||
float scaleFactor = CC_CONTENT_SCALE_FACTOR();
|
float scaleFactor = CC_CONTENT_SCALE_FACTOR();
|
||||||
int newLetterCount = fontDefs.size();
|
size_t newLetterCount = fontDefs.size();
|
||||||
float glyphWidth;
|
float glyphWidth;
|
||||||
for (int i = 0; i < newLetterCount; ++i)
|
for (int i = 0; i < newLetterCount; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -149,7 +149,7 @@ FontAtlas * FontFNT::createFontAtlas()
|
||||||
if (!_configuration->_fontDefDictionary)
|
if (!_configuration->_fontDefDictionary)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
int numGlyphs = _configuration->_characterSet->size();
|
size_t numGlyphs = _configuration->_characterSet->size();
|
||||||
if (!numGlyphs)
|
if (!numGlyphs)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
||||||
{
|
{
|
||||||
FT_Face face;
|
FT_Face face;
|
||||||
|
|
||||||
long len = 0;
|
ssize_t len = 0;
|
||||||
_ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len);
|
_ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len);
|
||||||
if (!_ttfData)
|
if (!_ttfData)
|
||||||
return false;
|
return false;
|
||||||
|
@ -297,7 +297,7 @@ int FontFreeType::getAdvanceForChar(unsigned short theChar) const
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// get to the advance for this glyph
|
// get to the advance for this glyph
|
||||||
return (_fontRef->glyph->advance.x >> 6);
|
return (static_cast<int>(_fontRef->glyph->advance.x >> 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
int FontFreeType::getBearingXForChar(unsigned short theChar) const
|
int FontFreeType::getBearingXForChar(unsigned short theChar) const
|
||||||
|
@ -316,7 +316,7 @@ int FontFreeType::getBearingXForChar(unsigned short theChar) const
|
||||||
if (FT_Load_Glyph(_fontRef, glyphIndex, FT_LOAD_DEFAULT))
|
if (FT_Load_Glyph(_fontRef, glyphIndex, FT_LOAD_DEFAULT))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (_fontRef->glyph->metrics.horiBearingX >>6);
|
return (static_cast<int>(_fontRef->glyph->metrics.horiBearingX >>6));
|
||||||
}
|
}
|
||||||
|
|
||||||
int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const
|
int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const
|
||||||
|
@ -346,12 +346,12 @@ int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsign
|
||||||
if (FT_Get_Kerning( _fontRef, glyphIndex1, glyphIndex2, FT_KERNING_DEFAULT, &kerning))
|
if (FT_Get_Kerning( _fontRef, glyphIndex1, glyphIndex2, FT_KERNING_DEFAULT, &kerning))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (kerning.x >> 6);
|
return (static_cast<int>(kerning.x >> 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
int FontFreeType::getFontMaxHeight() const
|
int FontFreeType::getFontMaxHeight() const
|
||||||
{
|
{
|
||||||
return (_fontRef->size->metrics.height >> 6);
|
return (static_cast<int>(_fontRef->size->metrics.height >> 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char * FontFreeType::getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const
|
unsigned char * FontFreeType::getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const
|
||||||
|
|
|
@ -113,13 +113,13 @@ bool GridBase::initWithSize(const Size& gridSize)
|
||||||
Director *pDirector = Director::getInstance();
|
Director *pDirector = Director::getInstance();
|
||||||
Size s = pDirector->getWinSizeInPixels();
|
Size s = pDirector->getWinSizeInPixels();
|
||||||
|
|
||||||
unsigned long POTWide = ccNextPOT((unsigned int)s.width);
|
auto POTWide = ccNextPOT((unsigned int)s.width);
|
||||||
unsigned long POTHigh = ccNextPOT((unsigned int)s.height);
|
auto POTHigh = ccNextPOT((unsigned int)s.height);
|
||||||
|
|
||||||
// we only use rgba8888
|
// we only use rgba8888
|
||||||
Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888;
|
Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888;
|
||||||
|
|
||||||
long dataLen = POTWide * POTHigh * 4;
|
auto dataLen = POTWide * POTHigh * 4;
|
||||||
void *data = calloc(dataLen, 1);
|
void *data = calloc(dataLen, 1);
|
||||||
if (! data)
|
if (! data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,7 +95,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _active;
|
bool _active;
|
||||||
long _reuseGrid;
|
int _reuseGrid;
|
||||||
Size _gridSize;
|
Size _gridSize;
|
||||||
Texture2D *_texture;
|
Texture2D *_texture;
|
||||||
Point _step;
|
Point _step;
|
||||||
|
|
|
@ -249,19 +249,16 @@ void Label::alignText()
|
||||||
LabelTextFormatter::alignText(this);
|
LabelTextFormatter::alignText(this);
|
||||||
|
|
||||||
int strLen = cc_wcslen(_currentUTF16String);
|
int strLen = cc_wcslen(_currentUTF16String);
|
||||||
if (_children && _children->count() != 0)
|
|
||||||
|
_children.forEach([this, &strLen](Node* child){
|
||||||
|
if (child)
|
||||||
{
|
{
|
||||||
for (auto child: *_children)
|
int tag = child->getTag();
|
||||||
{
|
|
||||||
Node* pNode = static_cast<Node*>( child );
|
|
||||||
if (pNode)
|
|
||||||
{
|
|
||||||
int tag = pNode->getTag();
|
|
||||||
if(tag < 0 || tag >= strLen)
|
if(tag < 0 || tag >= strLen)
|
||||||
SpriteBatchNode::removeChild(pNode, true);
|
SpriteBatchNode::removeChild(child, true);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_reusedLetter->setBatchNode(nullptr);
|
_reusedLetter->setBatchNode(nullptr);
|
||||||
|
|
||||||
int vaildIndex = 0;
|
int vaildIndex = 0;
|
||||||
|
@ -376,7 +373,7 @@ Sprite * Label::updateSpriteWithLetterDefinition(Sprite *spriteToUpdate, const F
|
||||||
{
|
{
|
||||||
spriteToUpdate->setBatchNode(this);
|
spriteToUpdate->setBatchNode(this);
|
||||||
spriteToUpdate->setTexture(theTexture);
|
spriteToUpdate->setTexture(theTexture);
|
||||||
spriteToUpdate->setDisplayFrame(frame);
|
spriteToUpdate->setSpriteFrame(frame);
|
||||||
spriteToUpdate->setAnchorPoint(Point(theDefinition.anchorX, theDefinition.anchorY));
|
spriteToUpdate->setAnchorPoint(Point(theDefinition.anchorX, theDefinition.anchorY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,21 +591,18 @@ bool Label::isOpacityModifyRGB() const
|
||||||
void Label::setOpacityModifyRGB(bool isOpacityModifyRGB)
|
void Label::setOpacityModifyRGB(bool isOpacityModifyRGB)
|
||||||
{
|
{
|
||||||
_isOpacityModifyRGB = isOpacityModifyRGB;
|
_isOpacityModifyRGB = isOpacityModifyRGB;
|
||||||
if (_children && _children->count() != 0)
|
|
||||||
|
_children.forEach([this](Node* child){
|
||||||
|
if (child)
|
||||||
{
|
{
|
||||||
for (auto child: *_children)
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
|
||||||
{
|
|
||||||
Node* pNode = static_cast<Node*>( child );
|
|
||||||
if (pNode)
|
|
||||||
{
|
|
||||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(pNode);
|
|
||||||
if (pRGBAProtocol)
|
if (pRGBAProtocol)
|
||||||
{
|
{
|
||||||
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
|
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
_reusedLetter->setOpacityModifyRGB(true);
|
_reusedLetter->setOpacityModifyRGB(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,13 +634,13 @@ void Label::updateDisplayedOpacity(GLubyte parentOpacity)
|
||||||
{
|
{
|
||||||
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
||||||
|
|
||||||
for (auto child: *_children)
|
_children.forEach([this](Node* child){
|
||||||
{
|
|
||||||
Sprite *item = static_cast<Sprite*>( child );
|
Sprite *item = static_cast<Sprite*>( child );
|
||||||
item->updateDisplayedOpacity(_displayedOpacity);
|
item->updateDisplayedOpacity(_displayedOpacity);
|
||||||
}
|
});
|
||||||
|
|
||||||
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
||||||
int count = _textureAtlas->getTotalQuads();
|
auto count = _textureAtlas->getTotalQuads();
|
||||||
Color4B color4( _displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity );
|
Color4B color4( _displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity );
|
||||||
if (_isOpacityModifyRGB)
|
if (_isOpacityModifyRGB)
|
||||||
{
|
{
|
||||||
|
@ -706,14 +700,13 @@ void Label::updateDisplayedColor(const Color3B& parentColor)
|
||||||
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
||||||
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
||||||
|
|
||||||
for (auto child: *_children)
|
_children.forEach([this](Node* child){
|
||||||
{
|
|
||||||
Sprite *item = static_cast<Sprite*>( child );
|
Sprite *item = static_cast<Sprite*>( child );
|
||||||
item->updateDisplayedColor(_displayedColor);
|
item->updateDisplayedColor(_displayedColor);
|
||||||
}
|
});
|
||||||
|
|
||||||
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
||||||
int count = _textureAtlas->getTotalQuads();
|
auto count = _textureAtlas->getTotalQuads();
|
||||||
Color4B color4( _displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity );
|
Color4B color4( _displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity );
|
||||||
|
|
||||||
// special opacity for premultiplied textures
|
// special opacity for premultiplied textures
|
||||||
|
|
|
@ -42,7 +42,7 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
//CCLabelAtlas - Creation & Init
|
//CCLabelAtlas - Creation & Init
|
||||||
|
|
||||||
LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap)
|
LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||||
{
|
{
|
||||||
LabelAtlas *pRet = new LabelAtlas();
|
LabelAtlas *pRet = new LabelAtlas();
|
||||||
if(pRet && pRet->initWithString(string, charMapFile, itemWidth, itemHeight, startCharMap))
|
if(pRet && pRet->initWithString(string, charMapFile, itemWidth, itemHeight, startCharMap))
|
||||||
|
@ -54,15 +54,15 @@ LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& cha
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LabelAtlas::initWithString(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap)
|
bool LabelAtlas::initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||||
{
|
{
|
||||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(charMapFile);
|
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(charMapFile);
|
||||||
return initWithString(string, texture, itemWidth, itemHeight, startCharMap);
|
return initWithString(string, texture, itemWidth, itemHeight, startCharMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LabelAtlas::initWithString(const std::string& string, Texture2D* texture, long itemWidth, long itemHeight, long startCharMap)
|
bool LabelAtlas::initWithString(const std::string& string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||||
{
|
{
|
||||||
if (AtlasNode::initWithTexture(texture, itemWidth, itemHeight, string.size()))
|
if (AtlasNode::initWithTexture(texture, itemWidth, itemHeight, static_cast<int>(string.size())))
|
||||||
{
|
{
|
||||||
_mapStartChar = startCharMap;
|
_mapStartChar = startCharMap;
|
||||||
this->setString(string);
|
this->setString(string);
|
||||||
|
@ -112,7 +112,7 @@ bool LabelAtlas::initWithString(const std::string& theString, const std::string&
|
||||||
//CCLabelAtlas - Atlas generation
|
//CCLabelAtlas - Atlas generation
|
||||||
void LabelAtlas::updateAtlasValues()
|
void LabelAtlas::updateAtlasValues()
|
||||||
{
|
{
|
||||||
size_t n = _string.length();
|
auto n = _string.length();
|
||||||
|
|
||||||
const unsigned char *s = (unsigned char*)_string.c_str();
|
const unsigned char *s = (unsigned char*)_string.c_str();
|
||||||
|
|
||||||
|
@ -127,9 +127,9 @@ void LabelAtlas::updateAtlasValues()
|
||||||
itemHeightInPixels = _itemHeight;
|
itemHeightInPixels = _itemHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCASSERT( static_cast<long>(n) <= _textureAtlas->getCapacity(), "updateAtlasValues: Invalid String length");
|
CCASSERT(n <= _textureAtlas->getCapacity(), "updateAtlasValues: Invalid String length");
|
||||||
V3F_C4B_T2F_Quad* quads = _textureAtlas->getQuads();
|
V3F_C4B_T2F_Quad* quads = _textureAtlas->getQuads();
|
||||||
for(long i = 0; i < static_cast<long>(n); i++) {
|
for(int i = 0; i < n; i++) {
|
||||||
|
|
||||||
unsigned char a = s[i] - _mapStartChar;
|
unsigned char a = s[i] - _mapStartChar;
|
||||||
float row = (float) (a % _itemsPerRow);
|
float row = (float) (a % _itemsPerRow);
|
||||||
|
@ -177,9 +177,9 @@ void LabelAtlas::updateAtlasValues()
|
||||||
}
|
}
|
||||||
if (n > 0 ){
|
if (n > 0 ){
|
||||||
_textureAtlas->setDirty(true);
|
_textureAtlas->setDirty(true);
|
||||||
long totalQuads = _textureAtlas->getTotalQuads();
|
auto totalQuads = _textureAtlas->getTotalQuads();
|
||||||
if (static_cast<long>(n) > totalQuads) {
|
if (n > totalQuads) {
|
||||||
_textureAtlas->increaseTotalQuadsWith(n - totalQuads);
|
_textureAtlas->increaseTotalQuadsWith(static_cast<int>(n - totalQuads));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,10 +187,10 @@ void LabelAtlas::updateAtlasValues()
|
||||||
//CCLabelAtlas - LabelProtocol
|
//CCLabelAtlas - LabelProtocol
|
||||||
void LabelAtlas::setString(const std::string &label)
|
void LabelAtlas::setString(const std::string &label)
|
||||||
{
|
{
|
||||||
size_t len = label.size();
|
auto len = label.size();
|
||||||
if (static_cast<long>(len) > _textureAtlas->getTotalQuads())
|
if (len > _textureAtlas->getTotalQuads())
|
||||||
{
|
{
|
||||||
_textureAtlas->resizeCapacity(len);
|
_textureAtlas->resizeCapacity(static_cast<int>(len));
|
||||||
}
|
}
|
||||||
_string.clear();
|
_string.clear();
|
||||||
_string = label;
|
_string = label;
|
||||||
|
@ -200,7 +200,7 @@ void LabelAtlas::setString(const std::string &label)
|
||||||
|
|
||||||
this->setContentSize(s);
|
this->setContentSize(s);
|
||||||
|
|
||||||
_quadsToDraw = len;
|
_quadsToDraw = static_cast<int>(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& LabelAtlas::getString(void) const
|
const std::string& LabelAtlas::getString(void) const
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
/** creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
||||||
static LabelAtlas * create(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap);
|
static LabelAtlas * create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||||
|
|
||||||
/** creates the LabelAtlas with a string and a configuration file
|
/** creates the LabelAtlas with a string and a configuration file
|
||||||
@since v2.0
|
@since v2.0
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
static LabelAtlas* create(const std::string& string, const std::string& fntFile);
|
static LabelAtlas* create(const std::string& string, const std::string& fntFile);
|
||||||
|
|
||||||
/** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
/** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
||||||
bool initWithString(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap);
|
bool initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||||
|
|
||||||
/** initializes the LabelAtlas with a string and a configuration file
|
/** initializes the LabelAtlas with a string and a configuration file
|
||||||
@since v2.0
|
@since v2.0
|
||||||
|
@ -83,7 +83,7 @@ public:
|
||||||
bool initWithString(const std::string& string, const std::string& fntFile);
|
bool initWithString(const std::string& string, const std::string& fntFile);
|
||||||
|
|
||||||
/** initializes the LabelAtlas with a string, a texture, the width and height in points of each element and the starting char of the atlas */
|
/** initializes the LabelAtlas with a string, a texture, the width and height in points of each element and the starting char of the atlas */
|
||||||
bool initWithString(const std::string& string, Texture2D* texture, long itemWidth, long itemHeight, long startCharMap);
|
bool initWithString(const std::string& string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||||
|
|
||||||
// super methods
|
// super methods
|
||||||
virtual void updateAtlasValues();
|
virtual void updateAtlasValues();
|
||||||
|
@ -99,7 +99,7 @@ protected:
|
||||||
// string to render
|
// string to render
|
||||||
std::string _string;
|
std::string _string;
|
||||||
// the first char in the charmap
|
// the first char in the charmap
|
||||||
long _mapStartChar;
|
int _mapStartChar;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of GUI group
|
// end of GUI group
|
||||||
|
|
|
@ -267,8 +267,8 @@ void CCBMFontConfiguration::parseImageFileName(std::string line, const std::stri
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// page ID. Sanity check
|
// page ID. Sanity check
|
||||||
long index = line.find('=')+1;
|
auto index = line.find('=')+1;
|
||||||
long index2 = line.find(' ', index);
|
auto index2 = line.find(' ', index);
|
||||||
std::string value = line.substr(index, index2-index);
|
std::string value = line.substr(index, index2-index);
|
||||||
CCASSERT(atoi(value.c_str()) == 0, "LabelBMFont file could not be found");
|
CCASSERT(atoi(value.c_str()) == 0, "LabelBMFont file could not be found");
|
||||||
// file
|
// file
|
||||||
|
@ -288,8 +288,8 @@ void CCBMFontConfiguration::parseInfoArguments(std::string line)
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// padding
|
// padding
|
||||||
long index = line.find("padding=");
|
auto index = line.find("padding=");
|
||||||
long index2 = line.find(' ', index);
|
auto index2 = line.find(' ', index);
|
||||||
std::string value = line.substr(index, index2-index);
|
std::string value = line.substr(index, index2-index);
|
||||||
sscanf(value.c_str(), "padding=%d,%d,%d,%d", &_padding.top, &_padding.right, &_padding.bottom, &_padding.left);
|
sscanf(value.c_str(), "padding=%d,%d,%d,%d", &_padding.top, &_padding.right, &_padding.bottom, &_padding.left);
|
||||||
CCLOG("cocos2d: padding: %d,%d,%d,%d", _padding.left, _padding.top, _padding.right, _padding.bottom);
|
CCLOG("cocos2d: padding: %d,%d,%d,%d", _padding.left, _padding.top, _padding.right, _padding.bottom);
|
||||||
|
@ -303,8 +303,8 @@ void CCBMFontConfiguration::parseCommonArguments(std::string line)
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Height
|
// Height
|
||||||
long index = line.find("lineHeight=");
|
auto index = line.find("lineHeight=");
|
||||||
long index2 = line.find(' ', index);
|
auto index2 = line.find(' ', index);
|
||||||
std::string value = line.substr(index, index2-index);
|
std::string value = line.substr(index, index2-index);
|
||||||
sscanf(value.c_str(), "lineHeight=%d", &_commonHeight);
|
sscanf(value.c_str(), "lineHeight=%d", &_commonHeight);
|
||||||
// scaleW. sanity check
|
// scaleW. sanity check
|
||||||
|
@ -334,8 +334,8 @@ void CCBMFontConfiguration::parseCharacterDefinition(std::string line, ccBMFontD
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Character ID
|
// Character ID
|
||||||
long index = line.find("id=");
|
auto index = line.find("id=");
|
||||||
long index2 = line.find(' ', index);
|
auto index2 = line.find(' ', index);
|
||||||
std::string value = line.substr(index, index2-index);
|
std::string value = line.substr(index, index2-index);
|
||||||
sscanf(value.c_str(), "id=%u", &characterDefinition->charID);
|
sscanf(value.c_str(), "id=%u", &characterDefinition->charID);
|
||||||
|
|
||||||
|
@ -385,8 +385,8 @@ void CCBMFontConfiguration::parseKerningEntry(std::string line)
|
||||||
|
|
||||||
// first
|
// first
|
||||||
int first;
|
int first;
|
||||||
long index = line.find("first=");
|
auto index = line.find("first=");
|
||||||
long index2 = line.find(' ', index);
|
auto index2 = line.find(' ', index);
|
||||||
std::string value = line.substr(index, index2-index);
|
std::string value = line.substr(index, index2-index);
|
||||||
sscanf(value.c_str(), "first=%d", &first);
|
sscanf(value.c_str(), "first=%d", &first);
|
||||||
|
|
||||||
|
@ -494,7 +494,7 @@ bool LabelBMFont::initWithString(const std::string& theString, const std::string
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SpriteBatchNode::initWithTexture(texture, theString.size()))
|
if (SpriteBatchNode::initWithTexture(texture, static_cast<int>(theString.size())))
|
||||||
{
|
{
|
||||||
_width = width;
|
_width = width;
|
||||||
_alignment = alignment;
|
_alignment = alignment;
|
||||||
|
@ -746,18 +746,10 @@ void LabelBMFont::setString(unsigned short *newString, bool needUpdateLabel)
|
||||||
CC_SAFE_DELETE_ARRAY(tmp);
|
CC_SAFE_DELETE_ARRAY(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_children && _children->count() != 0)
|
_children.forEach([](Node* child){
|
||||||
{
|
child->setVisible(false);
|
||||||
Object* child;
|
});
|
||||||
CCARRAY_FOREACH(_children, child)
|
|
||||||
{
|
|
||||||
Node* pNode = static_cast<Node*>( child );
|
|
||||||
if (pNode)
|
|
||||||
{
|
|
||||||
pNode->setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->createFontChars();
|
this->createFontChars();
|
||||||
|
|
||||||
if (needUpdateLabel) {
|
if (needUpdateLabel) {
|
||||||
|
@ -830,22 +822,16 @@ void LabelBMFont::setOpacity(GLubyte opacity)
|
||||||
void LabelBMFont::setOpacityModifyRGB(bool var)
|
void LabelBMFont::setOpacityModifyRGB(bool var)
|
||||||
{
|
{
|
||||||
_isOpacityModifyRGB = var;
|
_isOpacityModifyRGB = var;
|
||||||
if (_children && _children->count() != 0)
|
_children.forEach([this](Node* child){
|
||||||
|
if (child)
|
||||||
{
|
{
|
||||||
Object* child;
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
|
||||||
CCARRAY_FOREACH(_children, child)
|
|
||||||
{
|
|
||||||
Node* pNode = static_cast<Node*>( child );
|
|
||||||
if (pNode)
|
|
||||||
{
|
|
||||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(pNode);
|
|
||||||
if (pRGBAProtocol)
|
if (pRGBAProtocol)
|
||||||
{
|
{
|
||||||
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
|
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bool LabelBMFont::isOpacityModifyRGB() const
|
bool LabelBMFont::isOpacityModifyRGB() const
|
||||||
{
|
{
|
||||||
|
@ -854,28 +840,24 @@ bool LabelBMFont::isOpacityModifyRGB() const
|
||||||
|
|
||||||
void LabelBMFont::updateDisplayedOpacity(GLubyte parentOpacity)
|
void LabelBMFont::updateDisplayedOpacity(GLubyte parentOpacity)
|
||||||
{
|
{
|
||||||
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
_displayedOpacity = _realOpacity * parentOpacity/255.0f;
|
||||||
|
|
||||||
Object* pObj;
|
_children.forEach([this](Node* child){
|
||||||
CCARRAY_FOREACH(_children, pObj)
|
Sprite *item = static_cast<Sprite*>( child );
|
||||||
{
|
|
||||||
Sprite *item = static_cast<Sprite*>( pObj );
|
|
||||||
item->updateDisplayedOpacity(_displayedOpacity);
|
item->updateDisplayedOpacity(_displayedOpacity);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void LabelBMFont::updateDisplayedColor(const Color3B& parentColor)
|
void LabelBMFont::updateDisplayedColor(const Color3B& parentColor)
|
||||||
{
|
{
|
||||||
_displayedColor.r = _realColor.r * parentColor.r/255.0;
|
_displayedColor.r = _realColor.r * parentColor.r/255.0f;
|
||||||
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
_displayedColor.g = _realColor.g * parentColor.g/255.0f;
|
||||||
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
_displayedColor.b = _realColor.b * parentColor.b/255.0f;
|
||||||
|
|
||||||
Object* pObj;
|
_children.forEach([this](Node* child){
|
||||||
CCARRAY_FOREACH(_children, pObj)
|
Sprite *item = static_cast<Sprite*>( child );
|
||||||
{
|
|
||||||
Sprite *item = static_cast<Sprite*>( pObj );
|
|
||||||
item->updateDisplayedColor(_displayedColor);
|
item->updateDisplayedColor(_displayedColor);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LabelBMFont::isCascadeColorEnabled() const
|
bool LabelBMFont::isCascadeColorEnabled() const
|
||||||
|
@ -917,7 +899,7 @@ void LabelBMFont::updateLabel()
|
||||||
{
|
{
|
||||||
// Step 1: Make multiline
|
// Step 1: Make multiline
|
||||||
vector<unsigned short> str_whole = cc_utf16_vec_from_utf16_str(_string);
|
vector<unsigned short> str_whole = cc_utf16_vec_from_utf16_str(_string);
|
||||||
unsigned int stringLength = str_whole.size();
|
size_t stringLength = str_whole.size();
|
||||||
vector<unsigned short> multiline_string;
|
vector<unsigned short> multiline_string;
|
||||||
multiline_string.reserve( stringLength );
|
multiline_string.reserve( stringLength );
|
||||||
vector<unsigned short> last_word;
|
vector<unsigned short> last_word;
|
||||||
|
@ -928,8 +910,8 @@ void LabelBMFont::updateLabel()
|
||||||
float startOfLine = -1, startOfWord = -1;
|
float startOfLine = -1, startOfWord = -1;
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
|
||||||
Array* children = getChildren();
|
auto children = getChildren();
|
||||||
for (int j = 0; j < children->count(); j++)
|
for (int j = 0; j < children.size(); j++)
|
||||||
{
|
{
|
||||||
Sprite* characterSprite;
|
Sprite* characterSprite;
|
||||||
unsigned int justSkipped = 0;
|
unsigned int justSkipped = 0;
|
||||||
|
@ -1068,7 +1050,7 @@ void LabelBMFont::updateLabel()
|
||||||
|
|
||||||
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
||||||
|
|
||||||
int size = multiline_string.size();
|
size_t size = multiline_string.size();
|
||||||
unsigned short* str_new = new unsigned short[size + 1];
|
unsigned short* str_new = new unsigned short[size + 1];
|
||||||
|
|
||||||
for (int j = 0; j < size; ++j)
|
for (int j = 0; j < size; ++j)
|
||||||
|
@ -1096,14 +1078,14 @@ void LabelBMFont::updateLabel()
|
||||||
if (_string[ctr] == '\n' || _string[ctr] == 0)
|
if (_string[ctr] == '\n' || _string[ctr] == 0)
|
||||||
{
|
{
|
||||||
float lineWidth = 0.0f;
|
float lineWidth = 0.0f;
|
||||||
unsigned int line_length = last_line.size();
|
size_t line_length = last_line.size();
|
||||||
// if last line is empty we must just increase lineNumber and work with next line
|
// if last line is empty we must just increase lineNumber and work with next line
|
||||||
if (line_length == 0)
|
if (line_length == 0)
|
||||||
{
|
{
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int index = i + line_length - 1 + lineNumber;
|
int index = static_cast<int>(i + line_length - 1 + lineNumber);
|
||||||
if (index < 0) continue;
|
if (index < 0) continue;
|
||||||
|
|
||||||
Sprite* lastChar = static_cast<Sprite*>( getChildByTag(index) );
|
Sprite* lastChar = static_cast<Sprite*>( getChildByTag(index) );
|
||||||
|
|
|
@ -39,7 +39,7 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
|
||||||
{
|
{
|
||||||
// Step 1: Make multiline
|
// Step 1: Make multiline
|
||||||
vector<unsigned short> strWhole = cc_utf16_vec_from_utf16_str(theLabel->getUTF8String());
|
vector<unsigned short> strWhole = cc_utf16_vec_from_utf16_str(theLabel->getUTF8String());
|
||||||
unsigned int stringLength = strWhole.size();
|
size_t stringLength = strWhole.size();
|
||||||
|
|
||||||
vector<unsigned short> multiline_string;
|
vector<unsigned short> multiline_string;
|
||||||
multiline_string.reserve( stringLength );
|
multiline_string.reserve( stringLength );
|
||||||
|
@ -197,7 +197,7 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
|
||||||
|
|
||||||
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
||||||
|
|
||||||
int size = multiline_string.size();
|
size_t size = multiline_string.size();
|
||||||
unsigned short* strNew = new unsigned short[size + 1];
|
unsigned short* strNew = new unsigned short[size + 1];
|
||||||
|
|
||||||
for (int j = 0; j < size; ++j)
|
for (int j = 0; j < size; ++j)
|
||||||
|
@ -231,7 +231,7 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
||||||
if (currentChar == '\n' || currentChar == 0)
|
if (currentChar == '\n' || currentChar == 0)
|
||||||
{
|
{
|
||||||
float lineWidth = 0.0f;
|
float lineWidth = 0.0f;
|
||||||
unsigned int lineLength = lastLine.size();
|
size_t lineLength = lastLine.size();
|
||||||
|
|
||||||
// if last line is empty we must just increase lineNumber and work with next line
|
// if last line is empty we must just increase lineNumber and work with next line
|
||||||
if (lineLength == 0)
|
if (lineLength == 0)
|
||||||
|
@ -239,7 +239,7 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int index = i + lineLength - 1 + lineNumber;
|
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
||||||
if (index < 0) continue;
|
if (index < 0) continue;
|
||||||
|
|
||||||
if(currentChar == 0)
|
if(currentChar == 0)
|
||||||
|
|
|
@ -499,15 +499,13 @@ void LayerRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
|
||||||
|
|
||||||
if (_cascadeOpacityEnabled)
|
if (_cascadeOpacityEnabled)
|
||||||
{
|
{
|
||||||
Object *obj = NULL;
|
_children.forEach([this](Node* obj){
|
||||||
CCARRAY_FOREACH(_children, obj)
|
|
||||||
{
|
|
||||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
item->updateDisplayedOpacity(_displayedOpacity);
|
item->updateDisplayedOpacity(_displayedOpacity);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,15 +517,13 @@ void LayerRGBA::updateDisplayedColor(const Color3B& parentColor)
|
||||||
|
|
||||||
if (_cascadeColorEnabled)
|
if (_cascadeColorEnabled)
|
||||||
{
|
{
|
||||||
Object *obj = NULL;
|
_children.forEach([this](Node* obj){
|
||||||
CCARRAY_FOREACH(_children, obj)
|
|
||||||
{
|
|
||||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
item->updateDisplayedColor(_displayedColor);
|
item->updateDisplayedColor(_displayedColor);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,19 +916,14 @@ void LayerGradient::setCompressedInterpolation(bool compress)
|
||||||
|
|
||||||
LayerMultiplex::LayerMultiplex()
|
LayerMultiplex::LayerMultiplex()
|
||||||
: _enabledLayer(0)
|
: _enabledLayer(0)
|
||||||
, _layers(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerMultiplex::~LayerMultiplex()
|
LayerMultiplex::~LayerMultiplex()
|
||||||
{
|
{
|
||||||
if (_layers)
|
_layers.forEach([](Layer* layer){
|
||||||
{
|
layer->cleanup();
|
||||||
for (auto& item : *_layers)
|
});
|
||||||
{
|
|
||||||
static_cast<Layer*>(item)->cleanup();
|
|
||||||
}
|
|
||||||
_layers->release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerMultiplex * LayerMultiplex::create(Layer * layer, ...)
|
LayerMultiplex * LayerMultiplex::create(Layer * layer, ...)
|
||||||
|
@ -971,7 +962,7 @@ LayerMultiplex* LayerMultiplex::create()
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerMultiplex* LayerMultiplex::createWithArray(Array* arrayOfLayers)
|
LayerMultiplex* LayerMultiplex::createWithArray(const Vector<Layer*>& arrayOfLayers)
|
||||||
{
|
{
|
||||||
LayerMultiplex* pRet = new LayerMultiplex();
|
LayerMultiplex* pRet = new LayerMultiplex();
|
||||||
if (pRet && pRet->initWithArray(arrayOfLayers))
|
if (pRet && pRet->initWithArray(arrayOfLayers))
|
||||||
|
@ -987,17 +978,13 @@ LayerMultiplex* LayerMultiplex::createWithArray(Array* arrayOfLayers)
|
||||||
|
|
||||||
void LayerMultiplex::addLayer(Layer* layer)
|
void LayerMultiplex::addLayer(Layer* layer)
|
||||||
{
|
{
|
||||||
CCASSERT(_layers, "");
|
_layers.pushBack(layer);
|
||||||
_layers->addObject(layer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LayerMultiplex::init()
|
bool LayerMultiplex::init()
|
||||||
{
|
{
|
||||||
if (Layer::init())
|
if (Layer::init())
|
||||||
{
|
{
|
||||||
_layers = Array::create();
|
|
||||||
_layers->retain();
|
|
||||||
|
|
||||||
_enabledLayer = 0;
|
_enabledLayer = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1008,34 +995,32 @@ bool LayerMultiplex::initWithLayers(Layer *layer, va_list params)
|
||||||
{
|
{
|
||||||
if (Layer::init())
|
if (Layer::init())
|
||||||
{
|
{
|
||||||
_layers = Array::createWithCapacity(5);
|
_layers.reserve(5);
|
||||||
_layers->retain();
|
_layers.pushBack(layer);
|
||||||
_layers->addObject(layer);
|
|
||||||
|
|
||||||
Layer *l = va_arg(params,Layer*);
|
Layer *l = va_arg(params,Layer*);
|
||||||
while( l ) {
|
while( l ) {
|
||||||
_layers->addObject(l);
|
_layers.pushBack(l);
|
||||||
l = va_arg(params,Layer*);
|
l = va_arg(params,Layer*);
|
||||||
}
|
}
|
||||||
|
|
||||||
_enabledLayer = 0;
|
_enabledLayer = 0;
|
||||||
this->addChild((Node*)_layers->getObjectAtIndex(_enabledLayer));
|
this->addChild(_layers.at(_enabledLayer));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LayerMultiplex::initWithArray(Array* arrayOfLayers)
|
bool LayerMultiplex::initWithArray(const Vector<Layer*>& arrayOfLayers)
|
||||||
{
|
{
|
||||||
if (Layer::init())
|
if (Layer::init())
|
||||||
{
|
{
|
||||||
_layers = Array::createWithCapacity(arrayOfLayers->count());
|
_layers.reserve(arrayOfLayers.size());
|
||||||
_layers->addObjectsFromArray(arrayOfLayers);
|
_layers.insert(arrayOfLayers);
|
||||||
_layers->retain();
|
|
||||||
|
|
||||||
_enabledLayer = 0;
|
_enabledLayer = 0;
|
||||||
this->addChild((Node*)_layers->getObjectAtIndex(_enabledLayer));
|
this->addChild(_layers.at(_enabledLayer));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1043,27 +1028,26 @@ bool LayerMultiplex::initWithArray(Array* arrayOfLayers)
|
||||||
|
|
||||||
void LayerMultiplex::switchTo(int n)
|
void LayerMultiplex::switchTo(int n)
|
||||||
{
|
{
|
||||||
CCASSERT( n < _layers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
CCASSERT( n < _layers.size(), "Invalid index in MultiplexLayer switchTo message" );
|
||||||
|
|
||||||
this->removeChild((Node*)_layers->getObjectAtIndex(_enabledLayer), true);
|
this->removeChild(_layers.at(_enabledLayer), true);
|
||||||
|
|
||||||
_enabledLayer = n;
|
_enabledLayer = n;
|
||||||
|
|
||||||
this->addChild((Node*)_layers->getObjectAtIndex(n));
|
this->addChild(_layers.at(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerMultiplex::switchToAndReleaseMe(int n)
|
void LayerMultiplex::switchToAndReleaseMe(int n)
|
||||||
{
|
{
|
||||||
CCASSERT( n < _layers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
CCASSERT( n < _layers.size(), "Invalid index in MultiplexLayer switchTo message" );
|
||||||
|
|
||||||
this->removeChild((Node*)_layers->getObjectAtIndex(_enabledLayer), true);
|
this->removeChild(_layers.at(_enabledLayer), true);
|
||||||
|
|
||||||
//[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]];
|
_layers.replace(_enabledLayer, nullptr);
|
||||||
_layers->replaceObjectAtIndex(_enabledLayer, NULL);
|
|
||||||
|
|
||||||
_enabledLayer = n;
|
_enabledLayer = n;
|
||||||
|
|
||||||
this->addChild((Node*)_layers->getObjectAtIndex(n));
|
this->addChild(_layers.at(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -70,10 +70,10 @@ public:
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesBegan(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesBegan(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesMoved(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesMoved(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesEnded(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesEnded(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesCancelled(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesCancelled(__Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
|
||||||
|
|
||||||
/* Callback function should not be deprecated, it will generate lots of warnings.
|
/* Callback function should not be deprecated, it will generate lots of warnings.
|
||||||
Since 'setTouchEnabled' was deprecated, it will make warnings if developer overrides onTouchXXX and invokes setTouchEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
|
Since 'setTouchEnabled' was deprecated, it will make warnings if developer overrides onTouchXXX and invokes setTouchEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
|
||||||
|
@ -412,7 +412,7 @@ public:
|
||||||
@since v2.1
|
@since v2.1
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
static LayerMultiplex* createWithArray(Array* arrayOfLayers);
|
static LayerMultiplex* createWithArray(const Vector<Layer*>& arrayOfLayers);
|
||||||
|
|
||||||
/** creates a LayerMultiplex with one or more layers using a variable argument list.
|
/** creates a LayerMultiplex with one or more layers using a variable argument list.
|
||||||
* @code
|
* @code
|
||||||
|
@ -430,6 +430,21 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
static LayerMultiplex * createWithLayer(Layer* layer);
|
static LayerMultiplex * createWithLayer(Layer* layer);
|
||||||
|
|
||||||
|
|
||||||
|
void addLayer(Layer* layer);
|
||||||
|
|
||||||
|
/** switches to a certain layer indexed by n.
|
||||||
|
The current (old) layer will be removed from it's parent with 'cleanup=true'.
|
||||||
|
*/
|
||||||
|
void switchTo(int n);
|
||||||
|
/** release the current layer and switches to another layer indexed by n.
|
||||||
|
The current (old) layer will be removed from it's parent with 'cleanup=true'.
|
||||||
|
*/
|
||||||
|
void switchToAndReleaseMe(int n);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @js ctor
|
* @js ctor
|
||||||
*/
|
*/
|
||||||
|
@ -450,22 +465,13 @@ public:
|
||||||
/** initializes a MultiplexLayer with an array of layers
|
/** initializes a MultiplexLayer with an array of layers
|
||||||
@since v2.1
|
@since v2.1
|
||||||
*/
|
*/
|
||||||
bool initWithArray(Array* arrayOfLayers);
|
bool initWithArray(const Vector<Layer*>& arrayOfLayers);
|
||||||
|
|
||||||
void addLayer(Layer* layer);
|
|
||||||
|
|
||||||
/** switches to a certain layer indexed by n.
|
|
||||||
The current (old) layer will be removed from it's parent with 'cleanup=true'.
|
|
||||||
*/
|
|
||||||
void switchTo(int n);
|
|
||||||
/** release the current layer and switches to another layer indexed by n.
|
|
||||||
The current (old) layer will be removed from it's parent with 'cleanup=true'.
|
|
||||||
*/
|
|
||||||
void switchToAndReleaseMe(int n);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
unsigned int _enabledLayer;
|
unsigned int _enabledLayer;
|
||||||
Array* _layers;
|
Vector<Layer*> _layers;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CC_DISALLOW_COPY_AND_ASSIGN(LayerMultiplex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ THE SOFTWARE.
|
||||||
#include "CCInteger.h"
|
#include "CCInteger.h"
|
||||||
#include "CCEventListenerTouch.h"
|
#include "CCEventListenerTouch.h"
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
@ -38,18 +37,6 @@ using namespace std;
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static std::vector<unsigned int> ccarray_to_std_vector(Array* pArray)
|
|
||||||
{
|
|
||||||
std::vector<unsigned int> ret;
|
|
||||||
Object* pObj;
|
|
||||||
CCARRAY_FOREACH(pArray, pObj)
|
|
||||||
{
|
|
||||||
Integer* pInteger = static_cast<Integer*>(pObj);
|
|
||||||
ret.push_back((unsigned int)pInteger->getValue());
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kDefaultPadding = 5,
|
kDefaultPadding = 5,
|
||||||
|
@ -81,36 +68,36 @@ Menu * Menu::create(MenuItem* item, ...)
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu* Menu::createWithArray(Array* pArrayOfItems)
|
Menu* Menu::createWithArray(const Vector<MenuItem*>& arrayOfItems)
|
||||||
{
|
{
|
||||||
Menu *pRet = new Menu();
|
auto ret = new Menu();
|
||||||
if (pRet && pRet->initWithArray(pArrayOfItems))
|
if (ret && ret->initWithArray(arrayOfItems))
|
||||||
{
|
{
|
||||||
pRet->autorelease();
|
ret->autorelease();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pRet;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu* Menu::createWithItems(MenuItem* item, va_list args)
|
Menu* Menu::createWithItems(MenuItem* item, va_list args)
|
||||||
{
|
{
|
||||||
Array* pArray = NULL;
|
Vector<MenuItem*> items;
|
||||||
if( item )
|
if( item )
|
||||||
{
|
{
|
||||||
pArray = Array::create(item, NULL);
|
items.pushBack(item);
|
||||||
MenuItem *i = va_arg(args, MenuItem*);
|
MenuItem *i = va_arg(args, MenuItem*);
|
||||||
while(i)
|
while(i)
|
||||||
{
|
{
|
||||||
pArray->addObject(i);
|
items.pushBack(i);
|
||||||
i = va_arg(args, MenuItem*);
|
i = va_arg(args, MenuItem*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Menu::createWithArray(pArray);
|
return Menu::createWithArray(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu* Menu::createWithItem(MenuItem* item)
|
Menu* Menu::createWithItem(MenuItem* item)
|
||||||
|
@ -120,10 +107,10 @@ Menu* Menu::createWithItem(MenuItem* item)
|
||||||
|
|
||||||
bool Menu::init()
|
bool Menu::init()
|
||||||
{
|
{
|
||||||
return initWithArray(NULL);
|
return initWithArray(Vector<MenuItem*>());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Menu::initWithArray(Array* pArrayOfItems)
|
bool Menu::initWithArray(const Vector<MenuItem*>& arrayOfItems)
|
||||||
{
|
{
|
||||||
if (Layer::init())
|
if (Layer::init())
|
||||||
{
|
{
|
||||||
|
@ -137,17 +124,13 @@ bool Menu::initWithArray(Array* pArrayOfItems)
|
||||||
|
|
||||||
setPosition(Point(s.width/2, s.height/2));
|
setPosition(Point(s.width/2, s.height/2));
|
||||||
|
|
||||||
if (pArrayOfItems != NULL)
|
|
||||||
{
|
|
||||||
int z=0;
|
int z=0;
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(pArrayOfItems, pObj)
|
for (auto& item : arrayOfItems)
|
||||||
{
|
{
|
||||||
MenuItem* item = static_cast<MenuItem*>(pObj);
|
|
||||||
this->addChild(item, z);
|
this->addChild(item, z);
|
||||||
z++;
|
z++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_selectedItem = NULL;
|
_selectedItem = NULL;
|
||||||
_state = Menu::State::WAITING;
|
_state = Menu::State::WAITING;
|
||||||
|
@ -242,7 +225,7 @@ bool Menu::onTouchBegan(Touch* touch, Event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectedItem = this->itemForTouch(touch);
|
_selectedItem = this->getItemForTouch(touch);
|
||||||
if (_selectedItem)
|
if (_selectedItem)
|
||||||
{
|
{
|
||||||
_state = Menu::State::TRACKING_TOUCH;
|
_state = Menu::State::TRACKING_TOUCH;
|
||||||
|
@ -282,7 +265,7 @@ void Menu::onTouchCancelled(Touch* touch, Event* event)
|
||||||
void Menu::onTouchMoved(Touch* touch, Event* event)
|
void Menu::onTouchMoved(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchMoved] -- invalid state");
|
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchMoved] -- invalid state");
|
||||||
MenuItem *currentItem = this->itemForTouch(touch);
|
MenuItem *currentItem = this->getItemForTouch(touch);
|
||||||
if (currentItem != _selectedItem)
|
if (currentItem != _selectedItem)
|
||||||
{
|
{
|
||||||
if (_selectedItem)
|
if (_selectedItem)
|
||||||
|
@ -306,33 +289,23 @@ void Menu::alignItemsVertically()
|
||||||
void Menu::alignItemsVerticallyWithPadding(float padding)
|
void Menu::alignItemsVerticallyWithPadding(float padding)
|
||||||
{
|
{
|
||||||
float height = -padding;
|
float height = -padding;
|
||||||
if (_children && _children->count() > 0)
|
|
||||||
{
|
_children.forEach([&](Node* child){
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
height += child->getContentSize().height * child->getScaleY() + padding;
|
height += child->getContentSize().height * child->getScaleY() + padding;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
float y = height / 2.0f;
|
float y = height / 2.0f;
|
||||||
if (_children && _children->count() > 0)
|
|
||||||
{
|
_children.forEach([&](Node* child){
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
child->setPosition(Point(0, y - child->getContentSize().height * child->getScaleY() / 2.0f));
|
child->setPosition(Point(0, y - child->getContentSize().height * child->getScaleY() / 2.0f));
|
||||||
y -= child->getContentSize().height * child->getScaleY() + padding;
|
y -= child->getContentSize().height * child->getScaleY() + padding;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::alignItemsHorizontally(void)
|
void Menu::alignItemsHorizontally(void)
|
||||||
|
@ -342,35 +315,23 @@ void Menu::alignItemsHorizontally(void)
|
||||||
|
|
||||||
void Menu::alignItemsHorizontallyWithPadding(float padding)
|
void Menu::alignItemsHorizontallyWithPadding(float padding)
|
||||||
{
|
{
|
||||||
|
|
||||||
float width = -padding;
|
float width = -padding;
|
||||||
if (_children && _children->count() > 0)
|
_children.forEach([&](Node* child){
|
||||||
{
|
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
width += child->getContentSize().width * child->getScaleX() + padding;
|
width += child->getContentSize().width * child->getScaleX() + padding;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
float x = -width / 2.0f;
|
float x = -width / 2.0f;
|
||||||
if (_children && _children->count() > 0)
|
|
||||||
{
|
_children.forEach([&](Node* child){
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
child->setPosition(Point(x + child->getContentSize().width * child->getScaleX() / 2.0f, 0));
|
child->setPosition(Point(x + child->getContentSize().width * child->getScaleX() / 2.0f, 0));
|
||||||
x += child->getContentSize().width * child->getScaleX() + padding;
|
x += child->getContentSize().width * child->getScaleX() + padding;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::alignItemsInColumns(int columns, ...)
|
void Menu::alignItemsInColumns(int columns, ...)
|
||||||
|
@ -386,36 +347,29 @@ void Menu::alignItemsInColumns(int columns, ...)
|
||||||
void Menu::alignItemsInColumns(int columns, va_list args)
|
void Menu::alignItemsInColumns(int columns, va_list args)
|
||||||
{
|
{
|
||||||
CCASSERT(columns >= 0, "Columns must be >= 0");
|
CCASSERT(columns >= 0, "Columns must be >= 0");
|
||||||
Array* rows = Array::create();
|
ValueVector rows;
|
||||||
while (columns)
|
while (columns)
|
||||||
{
|
{
|
||||||
rows->addObject(Integer::create(columns));
|
rows.push_back(Value(columns));
|
||||||
columns = va_arg(args, int);
|
columns = va_arg(args, int);
|
||||||
}
|
}
|
||||||
alignItemsInColumnsWithArray(rows);
|
alignItemsInColumnsWithArray(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
|
||||||
{
|
{
|
||||||
vector<unsigned int> rows = ccarray_to_std_vector(rowsArray);
|
|
||||||
|
|
||||||
int height = -5;
|
int height = -5;
|
||||||
unsigned int row = 0;
|
int row = 0;
|
||||||
unsigned int rowHeight = 0;
|
int rowHeight = 0;
|
||||||
unsigned int columnsOccupied = 0;
|
int columnsOccupied = 0;
|
||||||
unsigned int rowColumns;
|
int rowColumns = 0;
|
||||||
|
|
||||||
if (_children && _children->count() > 0)
|
_children.forEach([&](Node* child){
|
||||||
{
|
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
CCASSERT(row < rows.size(), "");
|
CCASSERT(row < rows.size(), "");
|
||||||
|
|
||||||
rowColumns = rows[row];
|
rowColumns = rows[row].asInt();
|
||||||
// can not have zero columns on a row
|
// can not have zero columns on a row
|
||||||
CCASSERT(rowColumns, "");
|
CCASSERT(rowColumns, "");
|
||||||
|
|
||||||
|
@ -432,8 +386,7 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
||||||
++row;
|
++row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// check if too many rows/columns for available menu items
|
// check if too many rows/columns for available menu items
|
||||||
CCASSERT(! columnsOccupied, "");
|
CCASSERT(! columnsOccupied, "");
|
||||||
|
@ -447,17 +400,14 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
||||||
float x = 0.0;
|
float x = 0.0;
|
||||||
float y = (float)(height / 2);
|
float y = (float)(height / 2);
|
||||||
|
|
||||||
if (_children && _children->count() > 0)
|
_children.forEach([&](Node* child){
|
||||||
|
if (child)
|
||||||
{
|
{
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
if (rowColumns == 0)
|
if (rowColumns == 0)
|
||||||
{
|
{
|
||||||
rowColumns = rows[row];
|
rowColumns = rows[row].asInt();
|
||||||
w = winSize.width / (1 + rowColumns);
|
w = winSize.width / (1 + rowColumns);
|
||||||
x = w;
|
x = w;
|
||||||
}
|
}
|
||||||
|
@ -482,7 +432,7 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::alignItemsInRows(int rows, ...)
|
void Menu::alignItemsInRows(int rows, ...)
|
||||||
|
@ -497,41 +447,34 @@ void Menu::alignItemsInRows(int rows, ...)
|
||||||
|
|
||||||
void Menu::alignItemsInRows(int rows, va_list args)
|
void Menu::alignItemsInRows(int rows, va_list args)
|
||||||
{
|
{
|
||||||
Array* pArray = Array::create();
|
ValueVector array;
|
||||||
while (rows)
|
while (rows)
|
||||||
{
|
{
|
||||||
pArray->addObject(Integer::create(rows));
|
array.push_back(Value(rows));
|
||||||
rows = va_arg(args, int);
|
rows = va_arg(args, int);
|
||||||
}
|
}
|
||||||
alignItemsInRowsWithArray(pArray);
|
alignItemsInRowsWithArray(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
|
||||||
{
|
{
|
||||||
vector<unsigned int> columns = ccarray_to_std_vector(columnArray);
|
vector<int> columnWidths;
|
||||||
|
vector<int> columnHeights;
|
||||||
vector<unsigned int> columnWidths;
|
|
||||||
vector<unsigned int> columnHeights;
|
|
||||||
|
|
||||||
int width = -10;
|
int width = -10;
|
||||||
int columnHeight = -5;
|
int columnHeight = -5;
|
||||||
unsigned int column = 0;
|
int column = 0;
|
||||||
unsigned int columnWidth = 0;
|
int columnWidth = 0;
|
||||||
unsigned int rowsOccupied = 0;
|
int rowsOccupied = 0;
|
||||||
unsigned int columnRows;
|
int columnRows;
|
||||||
|
|
||||||
if (_children && _children->count() > 0)
|
_children.forEach([&](Node* child){
|
||||||
{
|
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
// check if too many menu items for the amount of rows/columns
|
// check if too many menu items for the amount of rows/columns
|
||||||
CCASSERT(column < columns.size(), "");
|
CCASSERT(column < columns.size(), "");
|
||||||
|
|
||||||
columnRows = columns[column];
|
columnRows = columns[column].asInt();
|
||||||
// can't have zero rows on a column
|
// can't have zero rows on a column
|
||||||
CCASSERT(columnRows, "");
|
CCASSERT(columnRows, "");
|
||||||
|
|
||||||
|
@ -554,8 +497,7 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
||||||
++column;
|
++column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// check if too many rows/columns for available menu items.
|
// check if too many rows/columns for available menu items.
|
||||||
CCASSERT(! rowsOccupied, "");
|
CCASSERT(! rowsOccupied, "");
|
||||||
|
@ -568,17 +510,12 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
||||||
float x = (float)(-width / 2);
|
float x = (float)(-width / 2);
|
||||||
float y = 0.0;
|
float y = 0.0;
|
||||||
|
|
||||||
if (_children && _children->count() > 0)
|
_children.forEach([&](Node* child){
|
||||||
{
|
|
||||||
Object* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Node* child = dynamic_cast<Node*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
if (columnRows == 0)
|
if (columnRows == 0)
|
||||||
{
|
{
|
||||||
columnRows = columns[column];
|
columnRows = columns[column].asInt();
|
||||||
y = (float) columnHeights[column];
|
y = (float) columnHeights[column];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,20 +538,18 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
||||||
++column;
|
++column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItem* Menu::itemForTouch(Touch *touch)
|
MenuItem* Menu::getItemForTouch(Touch *touch)
|
||||||
{
|
{
|
||||||
Point touchLocation = touch->getLocation();
|
Point touchLocation = touch->getLocation();
|
||||||
|
|
||||||
if (_children && _children->count() > 0)
|
if (!_children.empty())
|
||||||
{
|
{
|
||||||
Object* pObject = NULL;
|
for (auto iter = _children.crbegin(); iter != _children.crend(); ++iter)
|
||||||
CCARRAY_FOREACH_REVERSE(_children, pObject)
|
|
||||||
{
|
{
|
||||||
MenuItem* child = dynamic_cast<MenuItem*>(pObject);
|
MenuItem* child = dynamic_cast<MenuItem*>(*iter);
|
||||||
if (child && child->isVisible() && child->isEnabled())
|
if (child && child->isVisible() && child->isEnabled())
|
||||||
{
|
{
|
||||||
Point local = child->convertToNodeSpace(touchLocation);
|
Point local = child->convertToNodeSpace(touchLocation);
|
||||||
|
|
|
@ -27,8 +27,9 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCMenuItem.h"
|
#include "CCMenuItem.h"
|
||||||
#include "CCLayer.h"
|
#include "CCLayer.h"
|
||||||
|
#include "CCVector.h"
|
||||||
#include "CCEventTouch.h"
|
#include "CCEventTouch.h"
|
||||||
|
#include "CCValue.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ public:
|
||||||
static Menu* create(MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
static Menu* create(MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||||
|
|
||||||
/** creates a Menu with a Array of MenuItem objects */
|
/** creates a Menu with a Array of MenuItem objects */
|
||||||
static Menu* createWithArray(Array* pArrayOfItems);
|
static Menu* createWithArray(const Vector<MenuItem*>& arrayOfItems);
|
||||||
|
|
||||||
/** creates a Menu with it's item, then use addChild() to add
|
/** creates a Menu with it's item, then use addChild() to add
|
||||||
* other items. It is used for script, it can't init with undetermined
|
* other items. It is used for script, it can't init with undetermined
|
||||||
|
@ -91,12 +92,12 @@ public:
|
||||||
/** align items in rows of columns */
|
/** align items in rows of columns */
|
||||||
void alignItemsInColumns(int columns, ...) CC_REQUIRES_NULL_TERMINATION;
|
void alignItemsInColumns(int columns, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||||
void alignItemsInColumns(int columns, va_list args);
|
void alignItemsInColumns(int columns, va_list args);
|
||||||
void alignItemsInColumnsWithArray(Array* rows);
|
void alignItemsInColumnsWithArray(const ValueVector& rows);
|
||||||
|
|
||||||
/** align items in columns of rows */
|
/** align items in columns of rows */
|
||||||
void alignItemsInRows(int rows, ...) CC_REQUIRES_NULL_TERMINATION;
|
void alignItemsInRows(int rows, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||||
void alignItemsInRows(int rows, va_list args);
|
void alignItemsInRows(int rows, va_list args);
|
||||||
void alignItemsInRowsWithArray(Array* columns);
|
void alignItemsInRowsWithArray(const ValueVector& columns);
|
||||||
|
|
||||||
virtual bool isEnabled() const { return _enabled; }
|
virtual bool isEnabled() const { return _enabled; }
|
||||||
virtual void setEnabled(bool value) { _enabled = value; };
|
virtual void setEnabled(bool value) { _enabled = value; };
|
||||||
|
@ -129,12 +130,12 @@ protected:
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
/** initializes a Menu with a NSArray of MenuItem objects */
|
/** initializes a Menu with a NSArray of MenuItem objects */
|
||||||
bool initWithArray(Array* pArrayOfItems);
|
bool initWithArray(const Vector<MenuItem*>& arrayOfItems);
|
||||||
|
|
||||||
/** whether or not the menu will receive events */
|
/** whether or not the menu will receive events */
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
|
|
||||||
MenuItem* itemForTouch(Touch * touch);
|
MenuItem* getItemForTouch(Touch * touch);
|
||||||
State _state;
|
State _state;
|
||||||
MenuItem *_selectedItem;
|
MenuItem *_selectedItem;
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static long _globalFontSize = kItemSize;
|
static int _globalFontSize = kItemSize;
|
||||||
static std::string _globalFontName = "Marker Felt";
|
static std::string _globalFontName = "Marker Felt";
|
||||||
static bool _globalFontNameRelease = false;
|
static bool _globalFontNameRelease = false;
|
||||||
|
|
||||||
|
@ -310,13 +310,13 @@ void MenuItemLabel::setEnabled(bool enabled)
|
||||||
//CCMenuItemAtlasFont
|
//CCMenuItemAtlasFont
|
||||||
//
|
//
|
||||||
|
|
||||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap)
|
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap)
|
||||||
{
|
{
|
||||||
return MenuItemAtlasFont::create(value, charMapFile, itemWidth, itemHeight, startCharMap, (const ccMenuCallback&)nullptr);
|
return MenuItemAtlasFont::create(value, charMapFile, itemWidth, itemHeight, startCharMap, (const ccMenuCallback&)nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: deprecated
|
// XXX: deprecated
|
||||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
||||||
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
||||||
|
@ -324,7 +324,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* cha
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback)
|
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||||
{
|
{
|
||||||
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
||||||
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, callback);
|
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, callback);
|
||||||
|
@ -333,14 +333,14 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: deprecated
|
// XXX: deprecated
|
||||||
bool MenuItemAtlasFont::initWithString(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
bool MenuItemAtlasFont::initWithString(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
CC_SAFE_RETAIN(_target);
|
CC_SAFE_RETAIN(_target);
|
||||||
return initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, std::bind(selector,target, std::placeholders::_1) );
|
return initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, std::bind(selector,target, std::placeholders::_1) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback)
|
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||||
{
|
{
|
||||||
CCASSERT( value.size() != 0, "value length must be greater than 0");
|
CCASSERT( value.size() != 0, "value length must be greater than 0");
|
||||||
LabelAtlas *label = new LabelAtlas();
|
LabelAtlas *label = new LabelAtlas();
|
||||||
|
@ -357,12 +357,12 @@ bool MenuItemAtlasFont::initWithString(const std::string& value, const std::stri
|
||||||
//CCMenuItemFont
|
//CCMenuItemFont
|
||||||
//
|
//
|
||||||
|
|
||||||
void MenuItemFont::setFontSize(long s)
|
void MenuItemFont::setFontSize(int s)
|
||||||
{
|
{
|
||||||
_globalFontSize = s;
|
_globalFontSize = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
long MenuItemFont::getFontSize()
|
int MenuItemFont::getFontSize()
|
||||||
{
|
{
|
||||||
return _globalFontSize;
|
return _globalFontSize;
|
||||||
}
|
}
|
||||||
|
@ -449,13 +449,13 @@ void MenuItemFont::recreateLabel()
|
||||||
this->setLabel(label);
|
this->setLabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemFont::setFontSizeObj(long s)
|
void MenuItemFont::setFontSizeObj(int s)
|
||||||
{
|
{
|
||||||
_fontSize = s;
|
_fontSize = s;
|
||||||
recreateLabel();
|
recreateLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
long MenuItemFont::getFontSizeObj() const
|
int MenuItemFont::getFontSizeObj() const
|
||||||
{
|
{
|
||||||
return _fontSize;
|
return _fontSize;
|
||||||
}
|
}
|
||||||
|
@ -806,37 +806,21 @@ void MenuItemImage::setDisabledSpriteFrame(SpriteFrame * frame)
|
||||||
//
|
//
|
||||||
|
|
||||||
// XXX: deprecated
|
// XXX: deprecated
|
||||||
MenuItemToggle * MenuItemToggle::createWithTarget(Object* target, SEL_MenuHandler selector, Array* menuItems)
|
MenuItemToggle * MenuItemToggle::createWithTarget(Object* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems)
|
||||||
{
|
{
|
||||||
MenuItemToggle *ret = new MenuItemToggle();
|
MenuItemToggle *ret = new MenuItemToggle();
|
||||||
ret->MenuItem::initWithTarget(target, selector);
|
ret->MenuItem::initWithTarget(target, selector);
|
||||||
ret->_subItems = Array::create();
|
ret->_subItems = menuItems;
|
||||||
ret->_subItems->retain();
|
|
||||||
|
|
||||||
for (int z=0; z < menuItems->count(); z++)
|
|
||||||
{
|
|
||||||
MenuItem* menuItem = (MenuItem*)menuItems->getObjectAtIndex(z);
|
|
||||||
ret->_subItems->addObject(menuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret->_selectedIndex = UINT_MAX;
|
ret->_selectedIndex = UINT_MAX;
|
||||||
ret->setSelectedIndex(0);
|
ret->setSelectedIndex(0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, Array* menuItems)
|
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, const Vector<MenuItem*>& menuItems)
|
||||||
{
|
{
|
||||||
MenuItemToggle *ret = new MenuItemToggle();
|
MenuItemToggle *ret = new MenuItemToggle();
|
||||||
ret->MenuItem::initWithCallback(callback);
|
ret->MenuItem::initWithCallback(callback);
|
||||||
ret->_subItems = Array::create();
|
ret->_subItems = menuItems;
|
||||||
ret->_subItems->retain();
|
|
||||||
|
|
||||||
for (int z=0; z < menuItems->count(); z++)
|
|
||||||
{
|
|
||||||
MenuItem* menuItem = (MenuItem*)menuItems->getObjectAtIndex(z);
|
|
||||||
ret->_subItems->addObject(menuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret->_selectedIndex = UINT_MAX;
|
ret->_selectedIndex = UINT_MAX;
|
||||||
ret->setSelectedIndex(0);
|
ret->setSelectedIndex(0);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -884,14 +868,13 @@ bool MenuItemToggle::initWithTarget(Object* target, SEL_MenuHandler selector, Me
|
||||||
bool MenuItemToggle::initWithCallback(const ccMenuCallback &callback, MenuItem *item, va_list args)
|
bool MenuItemToggle::initWithCallback(const ccMenuCallback &callback, MenuItem *item, va_list args)
|
||||||
{
|
{
|
||||||
MenuItem::initWithCallback(callback);
|
MenuItem::initWithCallback(callback);
|
||||||
this->_subItems = Array::create();
|
|
||||||
this->_subItems->retain();
|
|
||||||
int z = 0;
|
int z = 0;
|
||||||
MenuItem *i = item;
|
MenuItem *i = item;
|
||||||
while(i)
|
while(i)
|
||||||
{
|
{
|
||||||
z++;
|
z++;
|
||||||
_subItems->addObject(i);
|
_subItems.pushBack(i);
|
||||||
i = va_arg(args, MenuItem*);
|
i = va_arg(args, MenuItem*);
|
||||||
}
|
}
|
||||||
_selectedIndex = UINT_MAX;
|
_selectedIndex = UINT_MAX;
|
||||||
|
@ -910,11 +893,10 @@ MenuItemToggle* MenuItemToggle::create(MenuItem *item)
|
||||||
bool MenuItemToggle::initWithItem(MenuItem *item)
|
bool MenuItemToggle::initWithItem(MenuItem *item)
|
||||||
{
|
{
|
||||||
MenuItem::initWithCallback((const ccMenuCallback&)nullptr);
|
MenuItem::initWithCallback((const ccMenuCallback&)nullptr);
|
||||||
setSubItems(Array::create());
|
|
||||||
|
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
_subItems->addObject(item);
|
_subItems.pushBack(item);
|
||||||
}
|
}
|
||||||
_selectedIndex = UINT_MAX;
|
_selectedIndex = UINT_MAX;
|
||||||
this->setSelectedIndex(0);
|
this->setSelectedIndex(0);
|
||||||
|
@ -927,24 +909,19 @@ bool MenuItemToggle::initWithItem(MenuItem *item)
|
||||||
|
|
||||||
void MenuItemToggle::addSubItem(MenuItem *item)
|
void MenuItemToggle::addSubItem(MenuItem *item)
|
||||||
{
|
{
|
||||||
_subItems->addObject(item);
|
_subItems.pushBack(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItemToggle::~MenuItemToggle()
|
MenuItemToggle::~MenuItemToggle()
|
||||||
{
|
{
|
||||||
if (_subItems)
|
_subItems.forEach([](MenuItem* item){
|
||||||
{
|
item->cleanup();
|
||||||
for (auto& item : *_subItems)
|
});
|
||||||
{
|
|
||||||
static_cast<MenuItem*>(item)->cleanup();
|
|
||||||
}
|
|
||||||
_subItems->release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemToggle::setSelectedIndex(unsigned int index)
|
void MenuItemToggle::setSelectedIndex(unsigned int index)
|
||||||
{
|
{
|
||||||
if( index != _selectedIndex && _subItems->count() > 0 )
|
if( index != _selectedIndex && _subItems.size() > 0 )
|
||||||
{
|
{
|
||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
MenuItem *currentItem = (MenuItem*)getChildByTag(kCurrentItem);
|
MenuItem *currentItem = (MenuItem*)getChildByTag(kCurrentItem);
|
||||||
|
@ -953,7 +930,7 @@ void MenuItemToggle::setSelectedIndex(unsigned int index)
|
||||||
currentItem->removeFromParentAndCleanup(false);
|
currentItem->removeFromParentAndCleanup(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItem* item = (MenuItem*)_subItems->getObjectAtIndex(_selectedIndex);
|
MenuItem* item = _subItems.at(_selectedIndex);
|
||||||
this->addChild(item, 0, kCurrentItem);
|
this->addChild(item, 0, kCurrentItem);
|
||||||
Size s = item->getContentSize();
|
Size s = item->getContentSize();
|
||||||
this->setContentSize(s);
|
this->setContentSize(s);
|
||||||
|
@ -964,13 +941,13 @@ void MenuItemToggle::setSelectedIndex(unsigned int index)
|
||||||
void MenuItemToggle::selected()
|
void MenuItemToggle::selected()
|
||||||
{
|
{
|
||||||
MenuItem::selected();
|
MenuItem::selected();
|
||||||
static_cast<MenuItem*>(_subItems->getObjectAtIndex(_selectedIndex))->selected();
|
_subItems.at(_selectedIndex)->selected();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemToggle::unselected()
|
void MenuItemToggle::unselected()
|
||||||
{
|
{
|
||||||
MenuItem::unselected();
|
MenuItem::unselected();
|
||||||
static_cast<MenuItem*>(_subItems->getObjectAtIndex(_selectedIndex))->unselected();
|
_subItems.at(_selectedIndex)->unselected();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuItemToggle::activate()
|
void MenuItemToggle::activate()
|
||||||
|
@ -978,7 +955,7 @@ void MenuItemToggle::activate()
|
||||||
// update index
|
// update index
|
||||||
if( _enabled )
|
if( _enabled )
|
||||||
{
|
{
|
||||||
unsigned int newIndex = (_selectedIndex + 1) % _subItems->count();
|
unsigned int newIndex = (_selectedIndex + 1) % _subItems.size();
|
||||||
this->setSelectedIndex(newIndex);
|
this->setSelectedIndex(newIndex);
|
||||||
}
|
}
|
||||||
MenuItem::activate();
|
MenuItem::activate();
|
||||||
|
@ -989,21 +966,15 @@ void MenuItemToggle::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
MenuItem::setEnabled(enabled);
|
MenuItem::setEnabled(enabled);
|
||||||
|
|
||||||
if(_subItems && _subItems->count() > 0)
|
_subItems.forEach([&enabled](MenuItem* item){
|
||||||
{
|
item->setEnabled(enabled);
|
||||||
Object* pObj = NULL;
|
});
|
||||||
CCARRAY_FOREACH(_subItems, pObj)
|
|
||||||
{
|
|
||||||
MenuItem* pItem = static_cast<MenuItem*>(pObj);
|
|
||||||
pItem->setEnabled(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItem* MenuItemToggle::getSelectedItem()
|
MenuItem* MenuItemToggle::getSelectedItem()
|
||||||
{
|
{
|
||||||
return static_cast<MenuItem*>(_subItems->getObjectAtIndex(_selectedIndex));
|
return _subItems.at(_selectedIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -212,11 +212,11 @@ class CC_DLL MenuItemAtlasFont : public MenuItemLabel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** creates a menu item from a string and atlas with a target/selector */
|
/** creates a menu item from a string and atlas with a target/selector */
|
||||||
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap);
|
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap);
|
||||||
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
||||||
CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||||
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
||||||
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback);
|
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
@ -230,9 +230,9 @@ protected:
|
||||||
virtual ~MenuItemAtlasFont(){}
|
virtual ~MenuItemAtlasFont(){}
|
||||||
|
|
||||||
/** initializes a menu item from a string and atlas with a target/selector */
|
/** initializes a menu item from a string and atlas with a target/selector */
|
||||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||||
/** initializes a menu item from a string and atlas with a target/selector */
|
/** initializes a menu item from a string and atlas with a target/selector */
|
||||||
bool initWithString(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback);
|
bool initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(MenuItemAtlasFont);
|
CC_DISALLOW_COPY_AND_ASSIGN(MenuItemAtlasFont);
|
||||||
|
@ -253,10 +253,10 @@ public:
|
||||||
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
|
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
|
||||||
|
|
||||||
/** set default font size */
|
/** set default font size */
|
||||||
static void setFontSize(long size);
|
static void setFontSize(int size);
|
||||||
/** get default font size */
|
/** get default font size */
|
||||||
static long getFontSize();
|
static int getFontSize();
|
||||||
CC_DEPRECATED_ATTRIBUTE static unsigned int fontSize() { return MenuItemFont::getFontSize(); };
|
CC_DEPRECATED_ATTRIBUTE static int fontSize() { return MenuItemFont::getFontSize(); };
|
||||||
/** set the default font name */
|
/** set the default font name */
|
||||||
static void setFontName(const std::string& name);
|
static void setFontName(const std::string& name);
|
||||||
/** get the default font name */
|
/** get the default font name */
|
||||||
|
@ -268,13 +268,13 @@ public:
|
||||||
* so change the name to setFontSizeObj
|
* so change the name to setFontSizeObj
|
||||||
* @js setFontSize
|
* @js setFontSize
|
||||||
*/
|
*/
|
||||||
void setFontSizeObj(long size);
|
void setFontSizeObj(int size);
|
||||||
|
|
||||||
/** get font size
|
/** get font size
|
||||||
* @js getFontSize
|
* @js getFontSize
|
||||||
*/
|
*/
|
||||||
long getFontSizeObj() const;
|
int getFontSizeObj() const;
|
||||||
CC_DEPRECATED_ATTRIBUTE unsigned int fontSizeObj() const { return getFontSizeObj(); };
|
CC_DEPRECATED_ATTRIBUTE int fontSizeObj() const { return getFontSizeObj(); };
|
||||||
|
|
||||||
/** set the font name
|
/** set the font name
|
||||||
* c++ can not overload static and non-static member functions with the same parameter types
|
* c++ can not overload static and non-static member functions with the same parameter types
|
||||||
|
@ -309,7 +309,7 @@ protected:
|
||||||
|
|
||||||
void recreateLabel();
|
void recreateLabel();
|
||||||
|
|
||||||
long _fontSize;
|
int _fontSize;
|
||||||
std::string _fontName;
|
std::string _fontName;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -453,8 +453,19 @@ private:
|
||||||
class CC_DLL MenuItemToggle : public MenuItem
|
class CC_DLL MenuItemToggle : public MenuItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** creates a menu item from a Array with a target selector
|
||||||
|
* @js NA
|
||||||
|
* @lua NA
|
||||||
|
*/
|
||||||
|
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle * createWithTarget(Object* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems);
|
||||||
|
/** creates a menu item from a list of items with a target/selector
|
||||||
|
* @js NA
|
||||||
|
* @lua NA
|
||||||
|
*/
|
||||||
|
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle* createWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, ...)CC_REQUIRES_NULL_TERMINATION;
|
||||||
|
|
||||||
/** creates a menu item from a Array with a callable object */
|
/** creates a menu item from a Array with a callable object */
|
||||||
static MenuItemToggle * createWithCallback(const ccMenuCallback& callback, Array* menuItems);
|
static MenuItemToggle * createWithCallback(const ccMenuCallback& callback, const Vector<MenuItem*>& menuItems);
|
||||||
/** creates a menu item from a list of items with a callable object */
|
/** creates a menu item from a list of items with a callable object */
|
||||||
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||||
/** creates a menu item with no target/selector and no items */
|
/** creates a menu item with no target/selector and no items */
|
||||||
|
@ -481,13 +492,11 @@ public:
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
|
inline const Vector<MenuItem*>& getSubItems() const { return _subItems; };
|
||||||
inline Array* getSubItems() const { return _subItems; };
|
inline Vector<MenuItem*>& getSubItems() { return _subItems; };
|
||||||
|
|
||||||
/** Sets the array that contains the subitems. */
|
/** Sets the array that contains the subitems. */
|
||||||
inline void setSubItems(Array* items) {
|
inline void setSubItems(const Vector<MenuItem*>& items) {
|
||||||
CC_SAFE_RETAIN(items);
|
|
||||||
CC_SAFE_RELEASE(_subItems);
|
|
||||||
_subItems = items;
|
_subItems = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,22 +507,11 @@ public:
|
||||||
virtual void setEnabled(bool var) override;
|
virtual void setEnabled(bool var) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** creates a menu item from a Array with a target selector
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle * createWithTarget(Object* target, SEL_MenuHandler selector, Array* menuItems);
|
|
||||||
/** creates a menu item from a list of items with a target/selector
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
*/
|
|
||||||
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle* createWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, ...)CC_REQUIRES_NULL_TERMINATION;
|
|
||||||
/**
|
/**
|
||||||
* @js ctor
|
* @js ctor
|
||||||
*/
|
*/
|
||||||
MenuItemToggle()
|
MenuItemToggle()
|
||||||
: _selectedIndex(0)
|
: _selectedIndex(0)
|
||||||
, _subItems(NULL)
|
|
||||||
{}
|
{}
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
|
@ -537,7 +535,7 @@ protected:
|
||||||
/** Array that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
|
/** Array that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
*/
|
*/
|
||||||
Array* _subItems;
|
Vector<MenuItem*> _subItems;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(MenuItemToggle);
|
CC_DISALLOW_COPY_AND_ASSIGN(MenuItemToggle);
|
||||||
|
|
|
@ -114,7 +114,6 @@ Node::Node(void)
|
||||||
// lazy alloc
|
// lazy alloc
|
||||||
, _grid(NULL)
|
, _grid(NULL)
|
||||||
, _ZOrder(0)
|
, _ZOrder(0)
|
||||||
, _children(NULL)
|
|
||||||
, _parent(NULL)
|
, _parent(NULL)
|
||||||
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
|
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
|
||||||
, _tag(Node::INVALID_TAG)
|
, _tag(Node::INVALID_TAG)
|
||||||
|
@ -169,21 +168,13 @@ Node::~Node()
|
||||||
CC_SAFE_RELEASE(_shaderProgram);
|
CC_SAFE_RELEASE(_shaderProgram);
|
||||||
CC_SAFE_RELEASE(_userObject);
|
CC_SAFE_RELEASE(_userObject);
|
||||||
|
|
||||||
if(_children && _children->count() > 0)
|
for (auto& child : _children)
|
||||||
{
|
{
|
||||||
Object* child;
|
if (child)
|
||||||
CCARRAY_FOREACH(_children, child)
|
|
||||||
{
|
{
|
||||||
Node* node = static_cast<Node*>(child);
|
child->_parent = NULL;
|
||||||
if (node)
|
|
||||||
{
|
|
||||||
node->_parent = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// children
|
|
||||||
CC_SAFE_RELEASE(_children);
|
|
||||||
|
|
||||||
removeAllComponents();
|
removeAllComponents();
|
||||||
|
|
||||||
|
@ -404,9 +395,9 @@ void Node::setPositionY(float y)
|
||||||
setPosition(Point(_position.x, y));
|
setPosition(Point(_position.x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
long Node::getChildrenCount() const
|
int Node::getChildrenCount() const
|
||||||
{
|
{
|
||||||
return _children ? _children->count() : 0;
|
return _children.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// camera getter: lazy alloc
|
/// camera getter: lazy alloc
|
||||||
|
@ -584,7 +575,9 @@ void Node::cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
// timers
|
// timers
|
||||||
arrayMakeObjectsPerformSelector(_children, cleanup, Node*);
|
_children.forEach([](Node* child){
|
||||||
|
child->cleanup();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -596,25 +589,19 @@ const char* Node::description() const
|
||||||
// lazy allocs
|
// lazy allocs
|
||||||
void Node::childrenAlloc(void)
|
void Node::childrenAlloc(void)
|
||||||
{
|
{
|
||||||
_children = Array::createWithCapacity(4);
|
_children.reserve(4);
|
||||||
_children->retain();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* Node::getChildByTag(int aTag)
|
Node* Node::getChildByTag(int aTag)
|
||||||
{
|
{
|
||||||
CCASSERT( aTag != Node::INVALID_TAG, "Invalid tag");
|
CCASSERT( aTag != Node::INVALID_TAG, "Invalid tag");
|
||||||
|
|
||||||
if(_children && _children->count() > 0)
|
for (auto& child : _children)
|
||||||
{
|
{
|
||||||
Object* child;
|
if(child && child->_tag == aTag)
|
||||||
CCARRAY_FOREACH(_children, child)
|
return child;
|
||||||
{
|
|
||||||
Node* pNode = static_cast<Node*>(child);
|
|
||||||
if(pNode && pNode->_tag == aTag)
|
|
||||||
return pNode;
|
|
||||||
}
|
}
|
||||||
}
|
return nullptr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* "add" logic MUST only be on this method
|
/* "add" logic MUST only be on this method
|
||||||
|
@ -626,7 +613,7 @@ void Node::addChild(Node *child, int zOrder, int tag)
|
||||||
CCASSERT( child != NULL, "Argument must be non-nil");
|
CCASSERT( child != NULL, "Argument must be non-nil");
|
||||||
CCASSERT( child->_parent == NULL, "child already added. It can't be added again");
|
CCASSERT( child->_parent == NULL, "child already added. It can't be added again");
|
||||||
|
|
||||||
if( ! _children )
|
if (_children.empty())
|
||||||
{
|
{
|
||||||
this->childrenAlloc();
|
this->childrenAlloc();
|
||||||
}
|
}
|
||||||
|
@ -691,12 +678,12 @@ void Node::removeFromParentAndCleanup(bool cleanup)
|
||||||
void Node::removeChild(Node* child, bool cleanup /* = true */)
|
void Node::removeChild(Node* child, bool cleanup /* = true */)
|
||||||
{
|
{
|
||||||
// explicit nil handling
|
// explicit nil handling
|
||||||
if (_children == NULL)
|
if (_children.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long index = _children->getIndexOfObject(child);
|
auto index = _children.getIndex(child);
|
||||||
if( index != CC_INVALID_INDEX )
|
if( index != CC_INVALID_INDEX )
|
||||||
this->detachChild( child, index, cleanup );
|
this->detachChild( child, index, cleanup );
|
||||||
}
|
}
|
||||||
|
@ -725,38 +712,36 @@ void Node::removeAllChildren()
|
||||||
void Node::removeAllChildrenWithCleanup(bool cleanup)
|
void Node::removeAllChildrenWithCleanup(bool cleanup)
|
||||||
{
|
{
|
||||||
// not using detachChild improves speed here
|
// not using detachChild improves speed here
|
||||||
if ( _children && _children->count() > 0 )
|
if (!_children.empty())
|
||||||
{
|
{
|
||||||
Object* child;
|
for (auto& child : _children)
|
||||||
CCARRAY_FOREACH(_children, child)
|
|
||||||
{
|
{
|
||||||
Node* pNode = static_cast<Node*>(child);
|
if (child)
|
||||||
if (pNode)
|
|
||||||
{
|
{
|
||||||
// IMPORTANT:
|
// IMPORTANT:
|
||||||
// -1st do onExit
|
// -1st do onExit
|
||||||
// -2nd cleanup
|
// -2nd cleanup
|
||||||
if(_running)
|
if(_running)
|
||||||
{
|
{
|
||||||
pNode->onExitTransitionDidStart();
|
child->onExitTransitionDidStart();
|
||||||
pNode->onExit();
|
child->onExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanup)
|
if (cleanup)
|
||||||
{
|
{
|
||||||
pNode->cleanup();
|
child->cleanup();
|
||||||
}
|
}
|
||||||
// set parent nil at the end
|
// set parent nil at the end
|
||||||
pNode->setParent(NULL);
|
child->setParent(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_children->removeAllObjects();
|
_children.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::detachChild(Node *child, long childIndex, bool doCleanup)
|
void Node::detachChild(Node *child, int childIndex, bool doCleanup)
|
||||||
{
|
{
|
||||||
// IMPORTANT:
|
// IMPORTANT:
|
||||||
// -1st do onExit
|
// -1st do onExit
|
||||||
|
@ -783,9 +768,9 @@ void Node::detachChild(Node *child, long childIndex, bool doCleanup)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set parent nil at the end
|
// set parent nil at the end
|
||||||
child->setParent(NULL);
|
child->setParent(nullptr);
|
||||||
|
|
||||||
_children->removeObjectAtIndex(childIndex);
|
_children.remove(childIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -793,7 +778,7 @@ void Node::detachChild(Node *child, long childIndex, bool doCleanup)
|
||||||
void Node::insertChild(Node* child, int z)
|
void Node::insertChild(Node* child, int z)
|
||||||
{
|
{
|
||||||
_reorderChildDirty = true;
|
_reorderChildDirty = true;
|
||||||
_children->addObject(child);
|
_children.pushBack(child);
|
||||||
child->_setZOrder(z);
|
child->_setZOrder(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,24 +795,24 @@ void Node::sortAllChildren()
|
||||||
#if 0
|
#if 0
|
||||||
if (_reorderChildDirty)
|
if (_reorderChildDirty)
|
||||||
{
|
{
|
||||||
int i,j,length = _children->count();
|
int i,j,length = _children.size();
|
||||||
|
|
||||||
// insertion sort
|
// insertion sort
|
||||||
for(i=1; i<length; i++)
|
for(i=1; i<length; i++)
|
||||||
{
|
{
|
||||||
j = i-1;
|
j = i-1;
|
||||||
auto tempI = static_cast<Node*>( _children->getObjectAtIndex(i) );
|
auto tempI = static_cast<Node*>( _children.at(i) );
|
||||||
auto tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );
|
auto tempJ = static_cast<Node*>( _children.at(j) );
|
||||||
|
|
||||||
//continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
|
//continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
|
||||||
while(j>=0 && ( tempI->_ZOrder < tempJ->_ZOrder || ( tempI->_ZOrder == tempJ->_ZOrder && tempI->_orderOfArrival < tempJ->_orderOfArrival ) ) )
|
while(j>=0 && ( tempI->_ZOrder < tempJ->_ZOrder || ( tempI->_ZOrder == tempJ->_ZOrder && tempI->_orderOfArrival < tempJ->_orderOfArrival ) ) )
|
||||||
{
|
{
|
||||||
_children->fastSetObject( tempJ, j+1 );
|
_children.fastSetObject( tempJ, j+1 );
|
||||||
j = j-1;
|
j = j-1;
|
||||||
if(j>=0)
|
if(j>=0)
|
||||||
tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );
|
tempJ = static_cast<Node*>( _children.at(j) );
|
||||||
}
|
}
|
||||||
_children->fastSetObject(tempI, j+1);
|
_children.fastSetObject(tempI, j+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//don't need to check children recursively, that's done in visit of each child
|
//don't need to check children recursively, that's done in visit of each child
|
||||||
|
@ -836,7 +821,7 @@ void Node::sortAllChildren()
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if( _reorderChildDirty ) {
|
if( _reorderChildDirty ) {
|
||||||
std::sort( std::begin(*_children), std::end(*_children), nodeComparisonLess );
|
std::sort( std::begin(_children), std::end(_children), nodeComparisonLess );
|
||||||
_reorderChildDirty = false;
|
_reorderChildDirty = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -869,13 +854,13 @@ void Node::visit()
|
||||||
this->transform();
|
this->transform();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if(_children && _children->count() > 0)
|
if(!_children.empty())
|
||||||
{
|
{
|
||||||
sortAllChildren();
|
sortAllChildren();
|
||||||
// draw children zOrder < 0
|
// draw children zOrder < 0
|
||||||
for( ; i < _children->count(); i++ )
|
for( ; i < _children.size(); i++ )
|
||||||
{
|
{
|
||||||
auto node = static_cast<Node*>( _children->getObjectAtIndex(i) );
|
auto node = _children.at(i);
|
||||||
|
|
||||||
if ( node && node->_ZOrder < 0 )
|
if ( node && node->_ZOrder < 0 )
|
||||||
node->visit();
|
node->visit();
|
||||||
|
@ -885,12 +870,10 @@ void Node::visit()
|
||||||
// self draw
|
// self draw
|
||||||
this->draw();
|
this->draw();
|
||||||
|
|
||||||
for( ; i < _children->count(); i++ )
|
// Uses std::for_each to improve performance.
|
||||||
{
|
std::for_each(_children.cbegin()+i, _children.cend(), [](Node* node){
|
||||||
auto node = static_cast<Node*>( _children->getObjectAtIndex(i) );
|
|
||||||
if (node)
|
|
||||||
node->visit();
|
node->visit();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -955,7 +938,9 @@ void Node::onEnter()
|
||||||
{
|
{
|
||||||
_isTransitionFinished = false;
|
_isTransitionFinished = false;
|
||||||
|
|
||||||
arrayMakeObjectsPerformSelector(_children, onEnter, Node*);
|
_children.forEach([](Node* child){
|
||||||
|
child->onEnter();
|
||||||
|
});
|
||||||
|
|
||||||
this->resume();
|
this->resume();
|
||||||
|
|
||||||
|
@ -974,7 +959,9 @@ void Node::onEnterTransitionDidFinish()
|
||||||
{
|
{
|
||||||
_isTransitionFinished = true;
|
_isTransitionFinished = true;
|
||||||
|
|
||||||
arrayMakeObjectsPerformSelector(_children, onEnterTransitionDidFinish, Node*);
|
_children.forEach([](Node* child){
|
||||||
|
child->onEnterTransitionDidFinish();
|
||||||
|
});
|
||||||
|
|
||||||
if (_scriptType != kScriptTypeNone)
|
if (_scriptType != kScriptTypeNone)
|
||||||
{
|
{
|
||||||
|
@ -987,7 +974,10 @@ void Node::onEnterTransitionDidFinish()
|
||||||
|
|
||||||
void Node::onExitTransitionDidStart()
|
void Node::onExitTransitionDidStart()
|
||||||
{
|
{
|
||||||
arrayMakeObjectsPerformSelector(_children, onExitTransitionDidStart, Node*);
|
_children.forEach([](Node* child){
|
||||||
|
child->onExitTransitionDidStart();
|
||||||
|
});
|
||||||
|
|
||||||
if (_scriptType != kScriptTypeNone)
|
if (_scriptType != kScriptTypeNone)
|
||||||
{
|
{
|
||||||
int action = kNodeOnExitTransitionDidStart;
|
int action = kNodeOnExitTransitionDidStart;
|
||||||
|
@ -1010,7 +1000,9 @@ void Node::onExit()
|
||||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
arrayMakeObjectsPerformSelector(_children, onExit, Node*);
|
_children.forEach([](Node* child){
|
||||||
|
child->onExit();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setEventDispatcher(EventDispatcher* dispatcher)
|
void Node::setEventDispatcher(EventDispatcher* dispatcher)
|
||||||
|
@ -1063,7 +1055,7 @@ Action * Node::getActionByTag(int tag)
|
||||||
return _actionManager->getActionByTag(tag, this);
|
return _actionManager->getActionByTag(tag, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Node::getNumberOfRunningActions() const
|
int Node::getNumberOfRunningActions() const
|
||||||
{
|
{
|
||||||
return _actionManager->getNumberOfRunningActionsInTarget(this);
|
return _actionManager->getNumberOfRunningActionsInTarget(this);
|
||||||
}
|
}
|
||||||
|
@ -1358,7 +1350,9 @@ bool Node::updatePhysicsTransform()
|
||||||
void Node::updateTransform()
|
void Node::updateTransform()
|
||||||
{
|
{
|
||||||
// Recursively iterate over children
|
// Recursively iterate over children
|
||||||
arrayMakeObjectsPerformSelector(_children, updateTransform, Node*);
|
_children.forEach([](Node* child){
|
||||||
|
child->updateTransform();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Component* Node::getComponent(const char *pName)
|
Component* Node::getComponent(const char *pName)
|
||||||
|
@ -1467,15 +1461,13 @@ void NodeRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
|
||||||
|
|
||||||
if (_cascadeOpacityEnabled)
|
if (_cascadeOpacityEnabled)
|
||||||
{
|
{
|
||||||
Object* pObj;
|
_children.forEach([this](Node* child){
|
||||||
CCARRAY_FOREACH(_children, pObj)
|
RGBAProtocol* item = dynamic_cast<RGBAProtocol*>(child);
|
||||||
{
|
|
||||||
RGBAProtocol* item = dynamic_cast<RGBAProtocol*>(pObj);
|
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
item->updateDisplayedOpacity(_displayedOpacity);
|
item->updateDisplayedOpacity(_displayedOpacity);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1524,15 +1516,13 @@ void NodeRGBA::updateDisplayedColor(const Color3B& parentColor)
|
||||||
|
|
||||||
if (_cascadeColorEnabled)
|
if (_cascadeColorEnabled)
|
||||||
{
|
{
|
||||||
Object *obj = NULL;
|
_children.forEach([this](Node* child){
|
||||||
CCARRAY_FOREACH(_children, obj)
|
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(child);
|
||||||
{
|
|
||||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
item->updateDisplayedColor(_displayedColor);
|
item->updateDisplayedColor(_displayedColor);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,7 @@
|
||||||
#include "CCScriptSupport.h"
|
#include "CCScriptSupport.h"
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCEventDispatcher.h"
|
#include "CCEventDispatcher.h"
|
||||||
|
#include "CCVector.h"
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -614,15 +613,15 @@ public:
|
||||||
*
|
*
|
||||||
* @return An array of children
|
* @return An array of children
|
||||||
*/
|
*/
|
||||||
virtual Array* getChildren() { return _children; }
|
virtual Vector<Node*>& getChildren() { return _children; }
|
||||||
virtual const Array *getChildren() const { return _children; }
|
virtual const Vector<Node*>& getChildren() const { return _children; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the amount of children.
|
* Get the amount of children.
|
||||||
*
|
*
|
||||||
* @return The amount of children.
|
* @return The amount of children.
|
||||||
*/
|
*/
|
||||||
long getChildrenCount() const;
|
int getChildrenCount() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the parent node
|
* Sets the parent node
|
||||||
|
@ -1043,10 +1042,10 @@ public:
|
||||||
*
|
*
|
||||||
* @return The number of actions that are running plus the ones that are schedule to run
|
* @return The number of actions that are running plus the ones that are schedule to run
|
||||||
*/
|
*/
|
||||||
unsigned int getNumberOfRunningActions() const;
|
int getNumberOfRunningActions() const;
|
||||||
|
|
||||||
/** @deprecated Use getNumberOfRunningActions() instead */
|
/** @deprecated Use getNumberOfRunningActions() instead */
|
||||||
CC_DEPRECATED_ATTRIBUTE unsigned int numberOfRunningActions() const { return getNumberOfRunningActions(); };
|
CC_DEPRECATED_ATTRIBUTE int numberOfRunningActions() const { return getNumberOfRunningActions(); };
|
||||||
|
|
||||||
/// @} end of Actions
|
/// @} end of Actions
|
||||||
|
|
||||||
|
@ -1403,7 +1402,7 @@ protected:
|
||||||
void insertChild(Node* child, int z);
|
void insertChild(Node* child, int z);
|
||||||
|
|
||||||
/// Removes a child, call child->onExit(), do cleanup, remove it from children array.
|
/// Removes a child, call child->onExit(), do cleanup, remove it from children array.
|
||||||
void detachChild(Node *child, long index, bool doCleanup);
|
void detachChild(Node *child, int index, bool doCleanup);
|
||||||
|
|
||||||
/// Convert cocos2d coordinates to UI windows coordinate.
|
/// Convert cocos2d coordinates to UI windows coordinate.
|
||||||
Point convertToWindowSpace(const Point& nodePoint) const;
|
Point convertToWindowSpace(const Point& nodePoint) const;
|
||||||
|
@ -1441,7 +1440,7 @@ protected:
|
||||||
|
|
||||||
int _ZOrder; ///< z-order value that affects the draw order
|
int _ZOrder; ///< z-order value that affects the draw order
|
||||||
|
|
||||||
Array *_children; ///< array of children nodes
|
Vector<Node*> _children; ///< array of children nodes
|
||||||
Node *_parent; ///< weak reference to parent node
|
Node *_parent; ///< weak reference to parent node
|
||||||
|
|
||||||
int _tag; ///< a tag. Can be any number you assigned just to identify this node
|
int _tag; ///< a tag. Can be any number you assigned just to identify this node
|
||||||
|
|
|
@ -95,9 +95,7 @@ bool ParticleBatchNode::initWithTexture(Texture2D *tex, int capacity)
|
||||||
_textureAtlas = new TextureAtlas();
|
_textureAtlas = new TextureAtlas();
|
||||||
_textureAtlas->initWithTexture(tex, capacity);
|
_textureAtlas->initWithTexture(tex, capacity);
|
||||||
|
|
||||||
// no lazy alloc in this node
|
_children.reserve(capacity);
|
||||||
_children = new Array();
|
|
||||||
_children->initWithCapacity(capacity);
|
|
||||||
|
|
||||||
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
||||||
|
|
||||||
|
@ -171,7 +169,7 @@ void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag)
|
||||||
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
||||||
CCASSERT( child->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "CCParticleSystem is not using the same texture id");
|
CCASSERT( child->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "CCParticleSystem is not using the same texture id");
|
||||||
// If this is the 1st children, then copy blending function
|
// If this is the 1st children, then copy blending function
|
||||||
if( _children->count() == 0 )
|
if (_children.empty())
|
||||||
{
|
{
|
||||||
setBlendFunc(child->getBlendFunc());
|
setBlendFunc(child->getBlendFunc());
|
||||||
}
|
}
|
||||||
|
@ -179,16 +177,15 @@ void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag)
|
||||||
CCASSERT( _blendFunc.src == child->getBlendFunc().src && _blendFunc.dst == child->getBlendFunc().dst, "Can't add a ParticleSystem that uses a different blending function");
|
CCASSERT( _blendFunc.src == child->getBlendFunc().src && _blendFunc.dst == child->getBlendFunc().dst, "Can't add a ParticleSystem that uses a different blending function");
|
||||||
|
|
||||||
//no lazy sorting, so don't call super addChild, call helper instead
|
//no lazy sorting, so don't call super addChild, call helper instead
|
||||||
unsigned int pos = addChildHelper(child,zOrder,tag);
|
auto pos = addChildHelper(child,zOrder,tag);
|
||||||
|
|
||||||
//get new atlasIndex
|
//get new atlasIndex
|
||||||
int atlasIndex = 0;
|
int atlasIndex = 0;
|
||||||
|
|
||||||
if (pos != 0)
|
if (pos != 0)
|
||||||
{
|
{
|
||||||
ParticleSystem* p = (ParticleSystem*)_children->getObjectAtIndex(pos-1);
|
ParticleSystem* p = static_cast<ParticleSystem*>(_children.at(pos-1));
|
||||||
atlasIndex = p->getAtlasIndex() + p->getTotalParticles();
|
atlasIndex = p->getAtlasIndex() + p->getTotalParticles();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -205,21 +202,17 @@ void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag)
|
||||||
// XXX research whether lazy sorting + freeing current quads and calloc a new block with size of capacity would be faster
|
// XXX research whether lazy sorting + freeing current quads and calloc a new block with size of capacity would be faster
|
||||||
// XXX or possibly using vertexZ for reordering, that would be fastest
|
// XXX or possibly using vertexZ for reordering, that would be fastest
|
||||||
// this helper is almost equivalent to Node's addChild, but doesn't make use of the lazy sorting
|
// this helper is almost equivalent to Node's addChild, but doesn't make use of the lazy sorting
|
||||||
unsigned int ParticleBatchNode::addChildHelper(ParticleSystem* child, int z, int aTag)
|
int ParticleBatchNode::addChildHelper(ParticleSystem* child, int z, int aTag)
|
||||||
{
|
{
|
||||||
CCASSERT( child != NULL, "Argument must be non-nil");
|
CCASSERT( child != NULL, "Argument must be non-nil");
|
||||||
CCASSERT( child->getParent() == NULL, "child already added. It can't be added again");
|
CCASSERT( child->getParent() == NULL, "child already added. It can't be added again");
|
||||||
|
|
||||||
if( ! _children )
|
_children.reserve(4);
|
||||||
{
|
|
||||||
_children = new Array();
|
|
||||||
_children->initWithCapacity(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
//don't use a lazy insert
|
//don't use a lazy insert
|
||||||
unsigned int pos = searchNewPositionInChildrenForZ(z);
|
auto pos = searchNewPositionInChildrenForZ(z);
|
||||||
|
|
||||||
_children->insertObject(child, pos);
|
_children.insert(pos, child);
|
||||||
|
|
||||||
child->setTag(aTag);
|
child->setTag(aTag);
|
||||||
child->_setZOrder(z);
|
child->_setZOrder(z);
|
||||||
|
@ -239,7 +232,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
||||||
{
|
{
|
||||||
CCASSERT( aChild != NULL, "Child must be non-NULL");
|
CCASSERT( aChild != NULL, "Child must be non-NULL");
|
||||||
CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != NULL, "CCParticleBatchNode only supports QuadParticleSystems as children");
|
CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != NULL, "CCParticleBatchNode only supports QuadParticleSystems as children");
|
||||||
CCASSERT( _children->containsObject(aChild), "Child doesn't belong to batch" );
|
CCASSERT( _children.contains(aChild), "Child doesn't belong to batch" );
|
||||||
|
|
||||||
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
||||||
|
|
||||||
|
@ -249,9 +242,9 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// no reordering if only 1 child
|
// no reordering if only 1 child
|
||||||
if( _children->count() > 1)
|
if (!_children.empty())
|
||||||
{
|
{
|
||||||
unsigned int newIndex = 0, oldIndex = 0;
|
int newIndex = 0, oldIndex = 0;
|
||||||
|
|
||||||
getCurrentIndex(&oldIndex, &newIndex, child, zOrder);
|
getCurrentIndex(&oldIndex, &newIndex, child, zOrder);
|
||||||
|
|
||||||
|
@ -260,8 +253,8 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
||||||
|
|
||||||
// reorder _children->array
|
// reorder _children->array
|
||||||
child->retain();
|
child->retain();
|
||||||
_children->removeObjectAtIndex(oldIndex);
|
_children.remove(oldIndex);
|
||||||
_children->insertObject(child, newIndex);
|
_children.insert(newIndex, child);
|
||||||
child->release();
|
child->release();
|
||||||
|
|
||||||
// save old altasIndex
|
// save old altasIndex
|
||||||
|
@ -272,10 +265,10 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
||||||
|
|
||||||
// Find new AtlasIndex
|
// Find new AtlasIndex
|
||||||
int newAtlasIndex = 0;
|
int newAtlasIndex = 0;
|
||||||
for( int i=0;i < _children->count();i++)
|
for( int i=0;i < _children.size();i++)
|
||||||
{
|
{
|
||||||
ParticleSystem* pNode = (ParticleSystem*)_children->getObjectAtIndex(i);
|
ParticleSystem* node = static_cast<ParticleSystem*>(_children.at(i));
|
||||||
if( pNode == child )
|
if( node == child )
|
||||||
{
|
{
|
||||||
newAtlasIndex = child->getAtlasIndex();
|
newAtlasIndex = child->getAtlasIndex();
|
||||||
break;
|
break;
|
||||||
|
@ -292,17 +285,17 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
||||||
child->_setZOrder(zOrder);
|
child->_setZOrder(zOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleBatchNode::getCurrentIndex(unsigned int* oldIndex, unsigned int* newIndex, Node* child, int z)
|
void ParticleBatchNode::getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z)
|
||||||
{
|
{
|
||||||
bool foundCurrentIdx = false;
|
bool foundCurrentIdx = false;
|
||||||
bool foundNewIdx = false;
|
bool foundNewIdx = false;
|
||||||
|
|
||||||
int minusOne = 0;
|
int minusOne = 0;
|
||||||
unsigned int count = _children->count();
|
auto count = _children.size();
|
||||||
|
|
||||||
for( unsigned int i=0; i < count; i++ )
|
for( int i=0; i < count; i++ )
|
||||||
{
|
{
|
||||||
Node* pNode = (Node *)_children->getObjectAtIndex(i);
|
Node* pNode = _children.at(i);
|
||||||
|
|
||||||
// new index
|
// new index
|
||||||
if( pNode->getZOrder() > z && ! foundNewIdx )
|
if( pNode->getZOrder() > z && ! foundNewIdx )
|
||||||
|
@ -337,25 +330,25 @@ void ParticleBatchNode::getCurrentIndex(unsigned int* oldIndex, unsigned int* ne
|
||||||
|
|
||||||
if( ! foundNewIdx )
|
if( ! foundNewIdx )
|
||||||
{
|
{
|
||||||
*newIndex = count;
|
*newIndex = static_cast<int>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
*newIndex += minusOne;
|
*newIndex += minusOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ParticleBatchNode::searchNewPositionInChildrenForZ(int z)
|
int ParticleBatchNode::searchNewPositionInChildrenForZ(int z)
|
||||||
{
|
{
|
||||||
unsigned int count = _children->count();
|
auto count = _children.size();
|
||||||
|
|
||||||
for( unsigned int i=0; i < count; i++ )
|
for( int i=0; i < count; i++ )
|
||||||
{
|
{
|
||||||
Node *child = (Node *)_children->getObjectAtIndex(i);
|
Node *child = _children.at(i);
|
||||||
if (child->getZOrder() > z)
|
if (child->getZOrder() > z)
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return static_cast<int>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// override removeChild:
|
// override removeChild:
|
||||||
|
@ -366,7 +359,7 @@ void ParticleBatchNode::removeChild(Node* aChild, bool cleanup)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != NULL, "CCParticleBatchNode only supports QuadParticleSystems as children");
|
CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != NULL, "CCParticleBatchNode only supports QuadParticleSystems as children");
|
||||||
CCASSERT(_children->containsObject(aChild), "CCParticleBatchNode doesn't contain the sprite. Can't remove it");
|
CCASSERT(_children.contains(aChild), "CCParticleBatchNode doesn't contain the sprite. Can't remove it");
|
||||||
|
|
||||||
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
||||||
Node::removeChild(child, cleanup);
|
Node::removeChild(child, cleanup);
|
||||||
|
@ -383,14 +376,16 @@ void ParticleBatchNode::removeChild(Node* aChild, bool cleanup)
|
||||||
updateAllAtlasIndexes();
|
updateAllAtlasIndexes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleBatchNode::removeChildAtIndex(unsigned int index, bool doCleanup)
|
void ParticleBatchNode::removeChildAtIndex(int index, bool doCleanup)
|
||||||
{
|
{
|
||||||
removeChild((ParticleSystem *)_children->getObjectAtIndex(index),doCleanup);
|
removeChild(_children.at(index), doCleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
void ParticleBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
||||||
{
|
{
|
||||||
arrayMakeObjectsPerformSelectorWithObject(_children, setBatchNode, NULL, ParticleSystem*);
|
_children.forEach([](Node* child){
|
||||||
|
static_cast<ParticleSystem*>(child)->setBatchNode(nullptr);
|
||||||
|
});
|
||||||
|
|
||||||
Node::removeAllChildrenWithCleanup(doCleanup);
|
Node::removeAllChildrenWithCleanup(doCleanup);
|
||||||
|
|
||||||
|
@ -417,7 +412,7 @@ void ParticleBatchNode::draw(void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ParticleBatchNode::increaseAtlasCapacityTo(unsigned int quantity)
|
void ParticleBatchNode::increaseAtlasCapacityTo(int quantity)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: ParticleBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].",
|
CCLOG("cocos2d: ParticleBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].",
|
||||||
(long)_textureAtlas->getCapacity(),
|
(long)_textureAtlas->getCapacity(),
|
||||||
|
@ -431,7 +426,7 @@ void ParticleBatchNode::increaseAtlasCapacityTo(unsigned int quantity)
|
||||||
}
|
}
|
||||||
|
|
||||||
//sets a 0'd quad into the quads array
|
//sets a 0'd quad into the quads array
|
||||||
void ParticleBatchNode::disableParticle(unsigned int particleIndex)
|
void ParticleBatchNode::disableParticle(int particleIndex)
|
||||||
{
|
{
|
||||||
V3F_C4B_T2F_Quad* quad = &((_textureAtlas->getQuads())[particleIndex]);
|
V3F_C4B_T2F_Quad* quad = &((_textureAtlas->getQuads())[particleIndex]);
|
||||||
quad->br.vertices.x = quad->br.vertices.y = quad->tr.vertices.x = quad->tr.vertices.y = quad->tl.vertices.x = quad->tl.vertices.y = quad->bl.vertices.x = quad->bl.vertices.y = 0.0f;
|
quad->br.vertices.x = quad->br.vertices.y = quad->tr.vertices.x = quad->tr.vertices.y = quad->tl.vertices.x = quad->tl.vertices.y = quad->bl.vertices.x = quad->bl.vertices.y = 0.0f;
|
||||||
|
@ -467,20 +462,18 @@ void ParticleBatchNode::insertChild(ParticleSystem* system, int index)
|
||||||
//rebuild atlas indexes
|
//rebuild atlas indexes
|
||||||
void ParticleBatchNode::updateAllAtlasIndexes()
|
void ParticleBatchNode::updateAllAtlasIndexes()
|
||||||
{
|
{
|
||||||
Object *pObj = NULL;
|
int index = 0;
|
||||||
unsigned int index = 0;
|
|
||||||
|
|
||||||
CCARRAY_FOREACH(_children,pObj)
|
_children.forEach([&index](Node* child){
|
||||||
{
|
ParticleSystem* partiSys = static_cast<ParticleSystem*>(child);
|
||||||
ParticleSystem* child = static_cast<ParticleSystem*>(pObj);
|
partiSys->setAtlasIndex(index);
|
||||||
child->setAtlasIndex(index);
|
index += partiSys->getTotalParticles();
|
||||||
index += child->getTotalParticles();
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParticleBatchNode - CocosNodeTexture protocol
|
// ParticleBatchNode - CocosNodeTexture protocol
|
||||||
|
|
||||||
void ParticleBatchNode::updateBlendFunc(void)
|
void ParticleBatchNode::updateBlendFunc()
|
||||||
{
|
{
|
||||||
if( ! _textureAtlas->getTexture()->hasPremultipliedAlpha())
|
if( ! _textureAtlas->getTexture()->hasPremultipliedAlpha())
|
||||||
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||||
|
@ -497,7 +490,7 @@ void ParticleBatchNode::setTexture(Texture2D* texture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D* ParticleBatchNode::getTexture(void) const
|
Texture2D* ParticleBatchNode::getTexture() const
|
||||||
{
|
{
|
||||||
return _textureAtlas->getTexture();
|
return _textureAtlas->getTexture();
|
||||||
}
|
}
|
||||||
|
@ -507,7 +500,7 @@ void ParticleBatchNode::setBlendFunc(const BlendFunc &blendFunc)
|
||||||
_blendFunc = blendFunc;
|
_blendFunc = blendFunc;
|
||||||
}
|
}
|
||||||
// returns the blending function used for the texture
|
// returns the blending function used for the texture
|
||||||
const BlendFunc& ParticleBatchNode::getBlendFunc(void) const
|
const BlendFunc& ParticleBatchNode::getBlendFunc() const
|
||||||
{
|
{
|
||||||
return _blendFunc;
|
return _blendFunc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,11 +91,11 @@ public:
|
||||||
/** Inserts a child into the ParticleBatchNode */
|
/** Inserts a child into the ParticleBatchNode */
|
||||||
void insertChild(ParticleSystem* system, int index);
|
void insertChild(ParticleSystem* system, int index);
|
||||||
|
|
||||||
void removeChildAtIndex(unsigned int index, bool doCleanup);
|
void removeChildAtIndex(int index, bool doCleanup);
|
||||||
void removeAllChildrenWithCleanup(bool doCleanup);
|
void removeAllChildrenWithCleanup(bool doCleanup);
|
||||||
|
|
||||||
/** disables a particle by inserting a 0'd quad into the texture atlas */
|
/** disables a particle by inserting a 0'd quad into the texture atlas */
|
||||||
void disableParticle(unsigned int particleIndex);
|
void disableParticle(int particleIndex);
|
||||||
|
|
||||||
/** Gets the texture atlas used for drawing the quads */
|
/** Gets the texture atlas used for drawing the quads */
|
||||||
inline TextureAtlas* getTextureAtlas() const { return _textureAtlas; };
|
inline TextureAtlas* getTextureAtlas() const { return _textureAtlas; };
|
||||||
|
@ -129,10 +129,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateAllAtlasIndexes();
|
void updateAllAtlasIndexes();
|
||||||
void increaseAtlasCapacityTo(unsigned int quantity);
|
void increaseAtlasCapacityTo(int quantity);
|
||||||
unsigned int searchNewPositionInChildrenForZ(int z);
|
int searchNewPositionInChildrenForZ(int z);
|
||||||
void getCurrentIndex(unsigned int* oldIndex, unsigned int* newIndex, Node* child, int z);
|
void getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z);
|
||||||
unsigned int addChildHelper(ParticleSystem* child, int z, int aTag);
|
int addChildHelper(ParticleSystem* child, int z, int aTag);
|
||||||
void updateBlendFunc(void);
|
void updateBlendFunc(void);
|
||||||
/** the texture atlas used for drawing the quads */
|
/** the texture atlas used for drawing the quads */
|
||||||
TextureAtlas* _textureAtlas;
|
TextureAtlas* _textureAtlas;
|
||||||
|
|
|
@ -169,9 +169,9 @@ bool ParticleSystem::initWithFile(const std::string& plistFile)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
_plistFile = FileUtils::getInstance()->fullPathForFilename(plistFile);
|
_plistFile = FileUtils::getInstance()->fullPathForFilename(plistFile);
|
||||||
Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(_plistFile.c_str());
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(_plistFile.c_str());
|
||||||
|
|
||||||
CCASSERT( dict != NULL, "Particles: file not found");
|
CCASSERT( !dict.empty(), "Particles: file not found");
|
||||||
|
|
||||||
// XXX compute path from a path, should define a function somewhere to do it
|
// XXX compute path from a path, should define a function somewhere to do it
|
||||||
string listFilePath = plistFile;
|
string listFilePath = plistFile;
|
||||||
|
@ -185,113 +185,110 @@ bool ParticleSystem::initWithFile(const std::string& plistFile)
|
||||||
bRet = this->initWithDictionary(dict, "");
|
bRet = this->initWithDictionary(dict, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
dict->release();
|
|
||||||
|
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParticleSystem::initWithDictionary(Dictionary *dictionary)
|
bool ParticleSystem::initWithDictionary(ValueMap& dictionary)
|
||||||
{
|
{
|
||||||
return initWithDictionary(dictionary, "");
|
return initWithDictionary(dictionary, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::string& dirname)
|
bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string& dirname)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = nullptr;
|
||||||
unsigned char *deflated = NULL;
|
unsigned char *deflated = nullptr;
|
||||||
Image *image = NULL;
|
Image *image = nullptr;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int maxParticles = dictionary->valueForKey("maxParticles")->intValue();
|
int maxParticles = dictionary["maxParticles"].asInt();
|
||||||
// self, not super
|
// self, not super
|
||||||
if(this->initWithTotalParticles(maxParticles))
|
if(this->initWithTotalParticles(maxParticles))
|
||||||
{
|
{
|
||||||
// Emitter name in particle designer 2.0
|
// Emitter name in particle designer 2.0
|
||||||
const String * configNameConstStr = dictionary->valueForKey("configName");
|
_configName = dictionary["configName"].asString();
|
||||||
_configName = configNameConstStr->getCString();
|
|
||||||
|
|
||||||
// angle
|
// angle
|
||||||
_angle = dictionary->valueForKey("angle")->floatValue();
|
_angle = dictionary["angle"].asFloat();
|
||||||
_angleVar = dictionary->valueForKey("angleVariance")->floatValue();
|
_angleVar = dictionary["angleVariance"].asFloat();
|
||||||
|
|
||||||
// duration
|
// duration
|
||||||
_duration = dictionary->valueForKey("duration")->floatValue();
|
_duration = dictionary["duration"].asFloat();
|
||||||
|
|
||||||
// blend function
|
// blend function
|
||||||
if (_configName.length()>0)
|
if (_configName.length()>0)
|
||||||
{
|
{
|
||||||
_blendFunc.src = dictionary->valueForKey("blendFuncSource")->floatValue();
|
_blendFunc.src = dictionary["blendFuncSource"].asFloat();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_blendFunc.src = dictionary->valueForKey("blendFuncSource")->intValue();
|
_blendFunc.src = dictionary["blendFuncSource"].asInt();
|
||||||
}
|
}
|
||||||
_blendFunc.dst = dictionary->valueForKey("blendFuncDestination")->intValue();
|
_blendFunc.dst = dictionary["blendFuncDestination"].asInt();
|
||||||
|
|
||||||
// color
|
// color
|
||||||
_startColor.r = dictionary->valueForKey("startColorRed")->floatValue();
|
_startColor.r = dictionary["startColorRed"].asFloat();
|
||||||
_startColor.g = dictionary->valueForKey("startColorGreen")->floatValue();
|
_startColor.g = dictionary["startColorGreen"].asFloat();
|
||||||
_startColor.b = dictionary->valueForKey("startColorBlue")->floatValue();
|
_startColor.b = dictionary["startColorBlue"].asFloat();
|
||||||
_startColor.a = dictionary->valueForKey("startColorAlpha")->floatValue();
|
_startColor.a = dictionary["startColorAlpha"].asFloat();
|
||||||
|
|
||||||
_startColorVar.r = dictionary->valueForKey("startColorVarianceRed")->floatValue();
|
_startColorVar.r = dictionary["startColorVarianceRed"].asFloat();
|
||||||
_startColorVar.g = dictionary->valueForKey("startColorVarianceGreen")->floatValue();
|
_startColorVar.g = dictionary["startColorVarianceGreen"].asFloat();
|
||||||
_startColorVar.b = dictionary->valueForKey("startColorVarianceBlue")->floatValue();
|
_startColorVar.b = dictionary["startColorVarianceBlue"].asFloat();
|
||||||
_startColorVar.a = dictionary->valueForKey("startColorVarianceAlpha")->floatValue();
|
_startColorVar.a = dictionary["startColorVarianceAlpha"].asFloat();
|
||||||
|
|
||||||
_endColor.r = dictionary->valueForKey("finishColorRed")->floatValue();
|
_endColor.r = dictionary["finishColorRed"].asFloat();
|
||||||
_endColor.g = dictionary->valueForKey("finishColorGreen")->floatValue();
|
_endColor.g = dictionary["finishColorGreen"].asFloat();
|
||||||
_endColor.b = dictionary->valueForKey("finishColorBlue")->floatValue();
|
_endColor.b = dictionary["finishColorBlue"].asFloat();
|
||||||
_endColor.a = dictionary->valueForKey("finishColorAlpha")->floatValue();
|
_endColor.a = dictionary["finishColorAlpha"].asFloat();
|
||||||
|
|
||||||
_endColorVar.r = dictionary->valueForKey("finishColorVarianceRed")->floatValue();
|
_endColorVar.r = dictionary["finishColorVarianceRed"].asFloat();
|
||||||
_endColorVar.g = dictionary->valueForKey("finishColorVarianceGreen")->floatValue();
|
_endColorVar.g = dictionary["finishColorVarianceGreen"].asFloat();
|
||||||
_endColorVar.b = dictionary->valueForKey("finishColorVarianceBlue")->floatValue();
|
_endColorVar.b = dictionary["finishColorVarianceBlue"].asFloat();
|
||||||
_endColorVar.a = dictionary->valueForKey("finishColorVarianceAlpha")->floatValue();
|
_endColorVar.a = dictionary["finishColorVarianceAlpha"].asFloat();
|
||||||
|
|
||||||
// particle size
|
// particle size
|
||||||
_startSize = dictionary->valueForKey("startParticleSize")->floatValue();
|
_startSize = dictionary["startParticleSize"].asFloat();
|
||||||
_startSizeVar = dictionary->valueForKey("startParticleSizeVariance")->floatValue();
|
_startSizeVar = dictionary["startParticleSizeVariance"].asFloat();
|
||||||
_endSize = dictionary->valueForKey("finishParticleSize")->floatValue();
|
_endSize = dictionary["finishParticleSize"].asFloat();
|
||||||
_endSizeVar = dictionary->valueForKey("finishParticleSizeVariance")->floatValue();
|
_endSizeVar = dictionary["finishParticleSizeVariance"].asFloat();
|
||||||
|
|
||||||
// position
|
// position
|
||||||
float x = dictionary->valueForKey("sourcePositionx")->floatValue();
|
float x = dictionary["sourcePositionx"].asFloat();
|
||||||
float y = dictionary->valueForKey("sourcePositiony")->floatValue();
|
float y = dictionary["sourcePositiony"].asFloat();
|
||||||
this->setPosition( Point(x,y) );
|
this->setPosition( Point(x,y) );
|
||||||
_posVar.x = dictionary->valueForKey("sourcePositionVariancex")->floatValue();
|
_posVar.x = dictionary["sourcePositionVariancex"].asFloat();
|
||||||
_posVar.y = dictionary->valueForKey("sourcePositionVariancey")->floatValue();
|
_posVar.y = dictionary["sourcePositionVariancey"].asFloat();
|
||||||
|
|
||||||
// Spinning
|
// Spinning
|
||||||
_startSpin = dictionary->valueForKey("rotationStart")->floatValue();
|
_startSpin = dictionary["rotationStart"].asFloat();
|
||||||
_startSpinVar = dictionary->valueForKey("rotationStartVariance")->floatValue();
|
_startSpinVar = dictionary["rotationStartVariance"].asFloat();
|
||||||
_endSpin= dictionary->valueForKey("rotationEnd")->floatValue();
|
_endSpin= dictionary["rotationEnd"].asFloat();
|
||||||
_endSpinVar= dictionary->valueForKey("rotationEndVariance")->floatValue();
|
_endSpinVar= dictionary["rotationEndVariance"].asFloat();
|
||||||
|
|
||||||
_emitterMode = (Mode) dictionary->valueForKey("emitterType")->intValue();
|
_emitterMode = (Mode) dictionary["emitterType"].asInt();
|
||||||
|
|
||||||
// Mode A: Gravity + tangential accel + radial accel
|
// Mode A: Gravity + tangential accel + radial accel
|
||||||
if (_emitterMode == Mode::GRAVITY)
|
if (_emitterMode == Mode::GRAVITY)
|
||||||
{
|
{
|
||||||
// gravity
|
// gravity
|
||||||
modeA.gravity.x = dictionary->valueForKey("gravityx")->floatValue();
|
modeA.gravity.x = dictionary["gravityx"].asFloat();
|
||||||
modeA.gravity.y = dictionary->valueForKey("gravityy")->floatValue();
|
modeA.gravity.y = dictionary["gravityy"].asFloat();
|
||||||
|
|
||||||
// speed
|
// speed
|
||||||
modeA.speed = dictionary->valueForKey("speed")->floatValue();
|
modeA.speed = dictionary["speed"].asFloat();
|
||||||
modeA.speedVar = dictionary->valueForKey("speedVariance")->floatValue();
|
modeA.speedVar = dictionary["speedVariance"].asFloat();
|
||||||
|
|
||||||
// radial acceleration
|
// radial acceleration
|
||||||
modeA.radialAccel = dictionary->valueForKey("radialAcceleration")->floatValue();
|
modeA.radialAccel = dictionary["radialAcceleration"].asFloat();
|
||||||
modeA.radialAccelVar = dictionary->valueForKey("radialAccelVariance")->floatValue();
|
modeA.radialAccelVar = dictionary["radialAccelVariance"].asFloat();
|
||||||
|
|
||||||
// tangential acceleration
|
// tangential acceleration
|
||||||
modeA.tangentialAccel = dictionary->valueForKey("tangentialAcceleration")->floatValue();
|
modeA.tangentialAccel = dictionary["tangentialAcceleration"].asFloat();
|
||||||
modeA.tangentialAccelVar = dictionary->valueForKey("tangentialAccelVariance")->floatValue();
|
modeA.tangentialAccelVar = dictionary["tangentialAccelVariance"].asFloat();
|
||||||
|
|
||||||
// rotation is dir
|
// rotation is dir
|
||||||
modeA.rotationIsDir = dictionary->valueForKey("rotationIsDir")->boolValue();
|
modeA.rotationIsDir = dictionary["rotationIsDir"].asBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
// or Mode B: radius movement
|
// or Mode B: radius movement
|
||||||
|
@ -299,31 +296,31 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
||||||
{
|
{
|
||||||
if (_configName.length()>0)
|
if (_configName.length()>0)
|
||||||
{
|
{
|
||||||
modeB.startRadius = dictionary->valueForKey("maxRadius")->intValue();
|
modeB.startRadius = dictionary["maxRadius"].asInt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
modeB.startRadius = dictionary->valueForKey("maxRadius")->floatValue();
|
modeB.startRadius = dictionary["maxRadius"].asFloat();
|
||||||
}
|
}
|
||||||
modeB.startRadiusVar = dictionary->valueForKey("maxRadiusVariance")->floatValue();
|
modeB.startRadiusVar = dictionary["maxRadiusVariance"].asFloat();
|
||||||
if (_configName.length()>0)
|
if (_configName.length()>0)
|
||||||
{
|
{
|
||||||
modeB.endRadius = dictionary->valueForKey("minRadius")->intValue();
|
modeB.endRadius = dictionary["minRadius"].asInt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
modeB.endRadius = dictionary->valueForKey("minRadius")->floatValue();
|
modeB.endRadius = dictionary["minRadius"].asFloat();
|
||||||
}
|
}
|
||||||
modeB.endRadiusVar = 0.0f;
|
modeB.endRadiusVar = 0.0f;
|
||||||
if (_configName.length()>0)
|
if (_configName.length()>0)
|
||||||
{
|
{
|
||||||
modeB.rotatePerSecond = dictionary->valueForKey("rotatePerSecond")->intValue();
|
modeB.rotatePerSecond = dictionary["rotatePerSecond"].asInt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
modeB.rotatePerSecond = dictionary->valueForKey("rotatePerSecond")->floatValue();
|
modeB.rotatePerSecond = dictionary["rotatePerSecond"].asFloat();
|
||||||
}
|
}
|
||||||
modeB.rotatePerSecondVar = dictionary->valueForKey("rotatePerSecondVariance")->floatValue();
|
modeB.rotatePerSecondVar = dictionary["rotatePerSecondVariance"].asFloat();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
CCASSERT( false, "Invalid emitterType in config file");
|
CCASSERT( false, "Invalid emitterType in config file");
|
||||||
|
@ -331,8 +328,8 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
||||||
}
|
}
|
||||||
|
|
||||||
// life span
|
// life span
|
||||||
_life = dictionary->valueForKey("particleLifespan")->floatValue();
|
_life = dictionary["particleLifespan"].asFloat();
|
||||||
_lifeVar = dictionary->valueForKey("particleLifespanVariance")->floatValue();
|
_lifeVar = dictionary["particleLifespanVariance"].asFloat();
|
||||||
|
|
||||||
// emission Rate
|
// emission Rate
|
||||||
_emissionRate = _totalParticles / _life;
|
_emissionRate = _totalParticles / _life;
|
||||||
|
@ -345,7 +342,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
||||||
|
|
||||||
// texture
|
// texture
|
||||||
// Try to get the texture from the cache
|
// Try to get the texture from the cache
|
||||||
std::string textureName = dictionary->valueForKey("textureFileName")->getCString();
|
std::string textureName = dictionary["textureFileName"].asString();
|
||||||
|
|
||||||
size_t rPos = textureName.rfind('/');
|
size_t rPos = textureName.rfind('/');
|
||||||
|
|
||||||
|
@ -385,19 +382,19 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *textureData = dictionary->valueForKey("textureImageData")->getCString();
|
std::string textureData = dictionary["textureImageData"].asString();
|
||||||
CCASSERT(textureData, "");
|
CCASSERT(!textureData.empty(), "");
|
||||||
|
|
||||||
long dataLen = strlen(textureData);
|
auto dataLen = textureData.size();
|
||||||
if (dataLen != 0)
|
if (dataLen != 0)
|
||||||
{
|
{
|
||||||
// if it fails, try to get it from the base64-gzipped data
|
// if it fails, try to get it from the base64-gzipped data
|
||||||
int decodeLen = base64Decode((unsigned char*)textureData, (unsigned int)dataLen, &buffer);
|
int decodeLen = base64Decode((unsigned char*)textureData.c_str(), (unsigned int)dataLen, &buffer);
|
||||||
CCASSERT( buffer != NULL, "CCParticleSystem: error decoding textureImageData");
|
CCASSERT( buffer != nullptr, "CCParticleSystem: error decoding textureImageData");
|
||||||
CC_BREAK_IF(!buffer);
|
CC_BREAK_IF(!buffer);
|
||||||
|
|
||||||
int deflatedLen = ZipUtils::inflateMemory(buffer, decodeLen, &deflated);
|
ssize_t deflatedLen = ZipUtils::inflateMemory(buffer, decodeLen, &deflated);
|
||||||
CCASSERT( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");
|
CCASSERT( deflated != nullptr, "CCParticleSystem: error ungzipping textureImageData");
|
||||||
CC_BREAK_IF(!deflated);
|
CC_BREAK_IF(!deflated);
|
||||||
|
|
||||||
// For android, we should retain it in VolatileTexture::addImage which invoked in Director::getInstance()->getTextureCache()->addUIImage()
|
// For android, we should retain it in VolatileTexture::addImage which invoked in Director::getInstance()->getTextureCache()->addUIImage()
|
||||||
|
@ -413,7 +410,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
||||||
}
|
}
|
||||||
if (_configName.length()>0)
|
if (_configName.length()>0)
|
||||||
{
|
{
|
||||||
_yCoordFlipped = dictionary->valueForKey("yCoordFlipped")->intValue();
|
_yCoordFlipped = dictionary["yCoordFlipped"].asInt();
|
||||||
}
|
}
|
||||||
CCASSERT( this->_texture != NULL, "CCParticleSystem: error loading the texture");
|
CCASSERT( this->_texture != NULL, "CCParticleSystem: error loading the texture");
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCDictionary.h"
|
#include "CCValue.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -386,12 +386,12 @@ protected:
|
||||||
/** initializes a QuadParticleSystem from a Dictionary.
|
/** initializes a QuadParticleSystem from a Dictionary.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
bool initWithDictionary(Dictionary *dictionary);
|
bool initWithDictionary(ValueMap& dictionary);
|
||||||
|
|
||||||
/** initializes a particle system from a NSDictionary and the path from where to load the png
|
/** initializes a particle system from a NSDictionary and the path from where to load the png
|
||||||
@since v2.1
|
@since v2.1
|
||||||
*/
|
*/
|
||||||
bool initWithDictionary(Dictionary *dictionary, const std::string& dirname);
|
bool initWithDictionary(ValueMap& dictionary, const std::string& dirname);
|
||||||
|
|
||||||
//! Initializes a system with a fixed number of particles
|
//! Initializes a system with a fixed number of particles
|
||||||
virtual bool initWithTotalParticles(int numberOfParticles);
|
virtual bool initWithTotalParticles(int numberOfParticles);
|
||||||
|
|
|
@ -198,8 +198,8 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat
|
||||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||||
|
|
||||||
// textures must be power of two squared
|
// textures must be power of two squared
|
||||||
long powW = 0;
|
int powW = 0;
|
||||||
long powH = 0;
|
int powH = 0;
|
||||||
|
|
||||||
if (Configuration::getInstance()->supportsNPOT())
|
if (Configuration::getInstance()->supportsNPOT())
|
||||||
{
|
{
|
||||||
|
@ -212,7 +212,7 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat
|
||||||
powH = ccNextPOT(h);
|
powH = ccNextPOT(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
long dataLen = (long)(powW * powH * 4);
|
auto dataLen = powW * powH * 4;
|
||||||
data = malloc(dataLen);
|
data = malloc(dataLen);
|
||||||
CC_BREAK_IF(! data);
|
CC_BREAK_IF(! data);
|
||||||
|
|
||||||
|
@ -528,16 +528,12 @@ void RenderTexture::draw()
|
||||||
//! make sure all children are drawn
|
//! make sure all children are drawn
|
||||||
sortAllChildren();
|
sortAllChildren();
|
||||||
|
|
||||||
Object *pElement;
|
_children.forEach([this](Node* child){
|
||||||
CCARRAY_FOREACH(_children, pElement)
|
|
||||||
{
|
|
||||||
Node *child = static_cast<Node*>(pElement);
|
|
||||||
|
|
||||||
if (child != _sprite)
|
if (child != _sprite)
|
||||||
{
|
{
|
||||||
child->visit();
|
child->visit();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
end();
|
end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,25 +132,17 @@ void Scene::addChildToPhysicsWorld(Node* child)
|
||||||
{
|
{
|
||||||
if (_physicsWorld)
|
if (_physicsWorld)
|
||||||
{
|
{
|
||||||
std::function<void(Object*)> addToPhysicsWorldFunc = nullptr;
|
std::function<void(Node*)> addToPhysicsWorldFunc = nullptr;
|
||||||
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Object* obj) -> void
|
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Node* node) -> void
|
||||||
{
|
{
|
||||||
|
|
||||||
if (dynamic_cast<Node*>(obj) != nullptr)
|
|
||||||
{
|
|
||||||
Node* node = dynamic_cast<Node*>(obj);
|
|
||||||
|
|
||||||
if (node->getPhysicsBody())
|
if (node->getPhysicsBody())
|
||||||
{
|
{
|
||||||
_physicsWorld->addBody(node->getPhysicsBody());
|
_physicsWorld->addBody(node->getPhysicsBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* subChild = nullptr;
|
node->getChildren().forEach([addToPhysicsWorldFunc](Node* n){
|
||||||
CCARRAY_FOREACH(node->getChildren(), subChild)
|
addToPhysicsWorldFunc(n);
|
||||||
{
|
});
|
||||||
addToPhysicsWorldFunc(subChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
addToPhysicsWorldFunc(child);
|
addToPhysicsWorldFunc(child);
|
||||||
|
|
|
@ -256,15 +256,15 @@ Scheduler::Scheduler(void)
|
||||||
, _currentTarget(nullptr)
|
, _currentTarget(nullptr)
|
||||||
, _currentTargetSalvaged(false)
|
, _currentTargetSalvaged(false)
|
||||||
, _updateHashLocked(false)
|
, _updateHashLocked(false)
|
||||||
, _scriptHandlerEntries(nullptr)
|
, _scriptHandlerEntries(20)
|
||||||
{
|
{
|
||||||
|
// I don't expect to have more than 30 functions to all per frame
|
||||||
|
_functionsToPerform.reserve(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scheduler::~Scheduler(void)
|
Scheduler::~Scheduler(void)
|
||||||
{
|
{
|
||||||
unscheduleAll();
|
unscheduleAll();
|
||||||
CC_SAFE_RELEASE(_scriptHandlerEntries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::removeHashElement(_hashSelectorEntry *element)
|
void Scheduler::removeHashElement(_hashSelectorEntry *element)
|
||||||
|
@ -629,10 +629,7 @@ void Scheduler::unscheduleAllWithMinPriority(int minPriority)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_scriptHandlerEntries)
|
_scriptHandlerEntries.clear();
|
||||||
{
|
|
||||||
_scriptHandlerEntries->removeAllObjects();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::unscheduleAllForTarget(Object *target)
|
void Scheduler::unscheduleAllForTarget(Object *target)
|
||||||
|
@ -674,20 +671,15 @@ void Scheduler::unscheduleAllForTarget(Object *target)
|
||||||
unsigned int Scheduler::scheduleScriptFunc(unsigned int handler, float interval, bool paused)
|
unsigned int Scheduler::scheduleScriptFunc(unsigned int handler, float interval, bool paused)
|
||||||
{
|
{
|
||||||
SchedulerScriptHandlerEntry* entry = SchedulerScriptHandlerEntry::create(handler, interval, paused);
|
SchedulerScriptHandlerEntry* entry = SchedulerScriptHandlerEntry::create(handler, interval, paused);
|
||||||
if (!_scriptHandlerEntries)
|
_scriptHandlerEntries.pushBack(entry);
|
||||||
{
|
|
||||||
_scriptHandlerEntries = Array::createWithCapacity(20);
|
|
||||||
_scriptHandlerEntries->retain();
|
|
||||||
}
|
|
||||||
_scriptHandlerEntries->addObject(entry);
|
|
||||||
return entry->getEntryId();
|
return entry->getEntryId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)
|
void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)
|
||||||
{
|
{
|
||||||
for (int i = _scriptHandlerEntries->count() - 1; i >= 0; i--)
|
for (int i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
SchedulerScriptHandlerEntry* entry = static_cast<SchedulerScriptHandlerEntry*>(_scriptHandlerEntries->getObjectAtIndex(i));
|
SchedulerScriptHandlerEntry* entry = _scriptHandlerEntries.at(i);
|
||||||
if (entry->getEntryId() == (int)scheduleScriptEntryID)
|
if (entry->getEntryId() == (int)scheduleScriptEntryID)
|
||||||
{
|
{
|
||||||
entry->markedForDeletion();
|
entry->markedForDeletion();
|
||||||
|
@ -763,22 +755,21 @@ bool Scheduler::isTargetPaused(Object *target)
|
||||||
return false; // should never get here
|
return false; // should never get here
|
||||||
}
|
}
|
||||||
|
|
||||||
Set* Scheduler::pauseAllTargets()
|
Vector<Object*> Scheduler::pauseAllTargets()
|
||||||
{
|
{
|
||||||
return pauseAllTargetsWithMinPriority(PRIORITY_SYSTEM);
|
return pauseAllTargetsWithMinPriority(PRIORITY_SYSTEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set* Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
Vector<Object*> Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||||
{
|
{
|
||||||
Set* idsWithSelectors = new Set();// setWithCapacity:50];
|
Vector<Object*> idsWithSelectors(50);
|
||||||
idsWithSelectors->autorelease();
|
|
||||||
|
|
||||||
// Custom Selectors
|
// Custom Selectors
|
||||||
for(tHashTimerEntry *element = _hashForTimers; element != nullptr;
|
for(tHashTimerEntry *element = _hashForTimers; element != nullptr;
|
||||||
element = (tHashTimerEntry*)element->hh.next)
|
element = (tHashTimerEntry*)element->hh.next)
|
||||||
{
|
{
|
||||||
element->paused = true;
|
element->paused = true;
|
||||||
idsWithSelectors->addObject(element->target);
|
idsWithSelectors.pushBack(element->target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates selectors
|
// Updates selectors
|
||||||
|
@ -790,7 +781,7 @@ Set* Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||||
if(entry->priority >= minPriority)
|
if(entry->priority >= minPriority)
|
||||||
{
|
{
|
||||||
entry->paused = true;
|
entry->paused = true;
|
||||||
idsWithSelectors->addObject(entry->target);
|
idsWithSelectors.pushBack(entry->target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -800,7 +791,7 @@ Set* Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||||
DL_FOREACH_SAFE( _updates0List, entry, tmp )
|
DL_FOREACH_SAFE( _updates0List, entry, tmp )
|
||||||
{
|
{
|
||||||
entry->paused = true;
|
entry->paused = true;
|
||||||
idsWithSelectors->addObject(entry->target);
|
idsWithSelectors.pushBack(entry->target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,20 +800,27 @@ Set* Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||||
if(entry->priority >= minPriority)
|
if(entry->priority >= minPriority)
|
||||||
{
|
{
|
||||||
entry->paused = true;
|
entry->paused = true;
|
||||||
idsWithSelectors->addObject(entry->target);
|
idsWithSelectors.pushBack(entry->target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return idsWithSelectors;
|
return std::move(idsWithSelectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::resumeTargets(Set* targetsToResume)
|
void Scheduler::resumeTargets(const Vector<Object*>& targetsToResume)
|
||||||
{
|
{
|
||||||
SetIterator iter;
|
targetsToResume.forEach([this](Object* obj){
|
||||||
for (iter = targetsToResume->begin(); iter != targetsToResume->end(); ++iter)
|
this->resumeTarget(obj);
|
||||||
{
|
});
|
||||||
resumeTarget(*iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scheduler::performFunctionInCocosThread(const std::function<void ()> &function)
|
||||||
|
{
|
||||||
|
_performMutex.lock();
|
||||||
|
|
||||||
|
_functionsToPerform.push_back(function);
|
||||||
|
|
||||||
|
_performMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
|
@ -835,6 +833,10 @@ void Scheduler::update(float dt)
|
||||||
dt *= _timeScale;
|
dt *= _timeScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Selector callbacks
|
||||||
|
//
|
||||||
|
|
||||||
// Iterate over all the Updates' selectors
|
// Iterate over all the Updates' selectors
|
||||||
tListEntry *entry, *tmp;
|
tListEntry *entry, *tmp;
|
||||||
|
|
||||||
|
@ -904,23 +906,6 @@ void Scheduler::update(float dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over all the script callbacks
|
|
||||||
if (_scriptHandlerEntries)
|
|
||||||
{
|
|
||||||
for (int i = _scriptHandlerEntries->count() - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
SchedulerScriptHandlerEntry* eachEntry = static_cast<SchedulerScriptHandlerEntry*>(_scriptHandlerEntries->getObjectAtIndex(i));
|
|
||||||
if (eachEntry->isMarkedForDeletion())
|
|
||||||
{
|
|
||||||
_scriptHandlerEntries->removeObjectAtIndex(i);
|
|
||||||
}
|
|
||||||
else if (!eachEntry->isPaused())
|
|
||||||
{
|
|
||||||
eachEntry->getTimer()->update(dt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete all updates that are marked for deletion
|
// delete all updates that are marked for deletion
|
||||||
// updates with priority < 0
|
// updates with priority < 0
|
||||||
DL_FOREACH_SAFE(_updatesNegList, entry, tmp)
|
DL_FOREACH_SAFE(_updatesNegList, entry, tmp)
|
||||||
|
@ -950,8 +935,43 @@ void Scheduler::update(float dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateHashLocked = false;
|
_updateHashLocked = false;
|
||||||
|
|
||||||
_currentTarget = nullptr;
|
_currentTarget = nullptr;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Script callbacks
|
||||||
|
//
|
||||||
|
|
||||||
|
// Iterate over all the script callbacks
|
||||||
|
if (!_scriptHandlerEntries.empty())
|
||||||
|
{
|
||||||
|
for (auto i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
SchedulerScriptHandlerEntry* eachEntry = _scriptHandlerEntries.at(i);
|
||||||
|
if (eachEntry->isMarkedForDeletion())
|
||||||
|
{
|
||||||
|
_scriptHandlerEntries.remove(i);
|
||||||
|
}
|
||||||
|
else if (!eachEntry->isPaused())
|
||||||
|
{
|
||||||
|
eachEntry->getTimer()->update(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Functions allocated from another thread
|
||||||
|
//
|
||||||
|
|
||||||
|
// Testing size is faster than locking / unlocking.
|
||||||
|
// And almost never there will be functions scheduled to be called.
|
||||||
|
if( !_functionsToPerform.empty() ) {
|
||||||
|
_performMutex.lock();
|
||||||
|
for( const auto &function : _functionsToPerform ) {
|
||||||
|
function();
|
||||||
|
}
|
||||||
|
_functionsToPerform.clear();
|
||||||
|
_performMutex.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,12 @@ THE SOFTWARE.
|
||||||
#define __CCSCHEDULER_H__
|
#define __CCSCHEDULER_H__
|
||||||
|
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
|
#include "CCVector.h"
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +41,6 @@ NS_CC_BEGIN
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Set;
|
|
||||||
//
|
//
|
||||||
// Timer
|
// Timer
|
||||||
//
|
//
|
||||||
|
@ -104,8 +107,7 @@ protected:
|
||||||
struct _listEntry;
|
struct _listEntry;
|
||||||
struct _hashSelectorEntry;
|
struct _hashSelectorEntry;
|
||||||
struct _hashUpdateEntry;
|
struct _hashUpdateEntry;
|
||||||
|
class SchedulerScriptHandlerEntry;
|
||||||
class Array;
|
|
||||||
|
|
||||||
/** @brief Scheduler is responsible for triggering the scheduled callbacks.
|
/** @brief Scheduler is responsible for triggering the scheduled callbacks.
|
||||||
You should not use NSTimer. Instead use this class.
|
You should not use NSTimer. Instead use this class.
|
||||||
|
@ -243,21 +245,27 @@ public:
|
||||||
You should NEVER call this method, unless you know what you are doing.
|
You should NEVER call this method, unless you know what you are doing.
|
||||||
@since v2.0.0
|
@since v2.0.0
|
||||||
*/
|
*/
|
||||||
Set* pauseAllTargets();
|
Vector<Object*> pauseAllTargets();
|
||||||
|
|
||||||
/** Pause all selectors from all targets with a minimum priority.
|
/** Pause all selectors from all targets with a minimum priority.
|
||||||
You should only call this with kPriorityNonSystemMin or higher.
|
You should only call this with kPriorityNonSystemMin or higher.
|
||||||
@since v2.0.0
|
@since v2.0.0
|
||||||
*/
|
*/
|
||||||
Set* pauseAllTargetsWithMinPriority(int minPriority);
|
Vector<Object*> pauseAllTargetsWithMinPriority(int minPriority);
|
||||||
|
|
||||||
/** Resume selectors on a set of targets.
|
/** Resume selectors on a set of targets.
|
||||||
This can be useful for undoing a call to pauseAllSelectors.
|
This can be useful for undoing a call to pauseAllSelectors.
|
||||||
@since v2.0.0
|
@since v2.0.0
|
||||||
*/
|
*/
|
||||||
void resumeTargets(Set* targetsToResume);
|
void resumeTargets(const Vector<Object*>& targetsToResume);
|
||||||
|
|
||||||
private:
|
/** calls a function on the cocos2d thread. Useful when you need to call a cocos2d function from another thread.
|
||||||
|
This function is thread safe.
|
||||||
|
@since v3.0
|
||||||
|
*/
|
||||||
|
void performFunctionInCocosThread( const std::function<void()> &function);
|
||||||
|
|
||||||
|
protected:
|
||||||
void removeHashElement(struct _hashSelectorEntry *element);
|
void removeHashElement(struct _hashSelectorEntry *element);
|
||||||
void removeUpdateFromHash(struct _listEntry *entry);
|
void removeUpdateFromHash(struct _listEntry *entry);
|
||||||
|
|
||||||
|
@ -266,7 +274,7 @@ private:
|
||||||
void priorityIn(struct _listEntry **list, Object *target, int priority, bool paused);
|
void priorityIn(struct _listEntry **list, Object *target, int priority, bool paused);
|
||||||
void appendIn(struct _listEntry **list, Object *target, bool paused);
|
void appendIn(struct _listEntry **list, Object *target, bool paused);
|
||||||
|
|
||||||
protected:
|
|
||||||
float _timeScale;
|
float _timeScale;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -283,7 +291,11 @@ protected:
|
||||||
bool _currentTargetSalvaged;
|
bool _currentTargetSalvaged;
|
||||||
// If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
// If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
||||||
bool _updateHashLocked;
|
bool _updateHashLocked;
|
||||||
Array* _scriptHandlerEntries;
|
Vector<SchedulerScriptHandlerEntry*> _scriptHandlerEntries;
|
||||||
|
|
||||||
|
// Used for "perform Function"
|
||||||
|
std::vector<std::function<void()>> _functionsToPerform;
|
||||||
|
std::mutex _performMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of global group
|
// end of global group
|
||||||
|
|
|
@ -613,7 +613,7 @@ void Sprite::draw(void)
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
setGLBufferData(&_quad, 4 * kQuadSize, 0);
|
setGLBufferData(&_quad, 4 * kQuadSize, 0);
|
||||||
#else
|
#else
|
||||||
long offset = (long)&_quad;
|
size_t offset = (size_t)&_quad;
|
||||||
#endif // EMSCRIPTEN
|
#endif // EMSCRIPTEN
|
||||||
|
|
||||||
// vertex
|
// vertex
|
||||||
|
@ -696,7 +696,7 @@ void Sprite::addChild(Node *child, int zOrder, int tag)
|
||||||
void Sprite::reorderChild(Node *child, int zOrder)
|
void Sprite::reorderChild(Node *child, int zOrder)
|
||||||
{
|
{
|
||||||
CCASSERT(child != NULL, "");
|
CCASSERT(child != NULL, "");
|
||||||
CCASSERT(_children->containsObject(child), "");
|
CCASSERT(_children.contains(child), "");
|
||||||
|
|
||||||
if (zOrder == child->getZOrder())
|
if (zOrder == child->getZOrder())
|
||||||
{
|
{
|
||||||
|
@ -726,15 +726,13 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup)
|
||||||
{
|
{
|
||||||
if (_batchNode)
|
if (_batchNode)
|
||||||
{
|
{
|
||||||
Object* object = NULL;
|
_children.forEach([this](Node* child){
|
||||||
CCARRAY_FOREACH(_children, object)
|
Sprite* sprite = dynamic_cast<Sprite*>(child);
|
||||||
|
if (sprite)
|
||||||
{
|
{
|
||||||
Sprite* child = dynamic_cast<Sprite*>(object);
|
_batchNode->removeSpriteFromAtlas(sprite);
|
||||||
if (child)
|
|
||||||
{
|
|
||||||
_batchNode->removeSpriteFromAtlas(child);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::removeAllChildrenWithCleanup(cleanup);
|
Node::removeAllChildrenWithCleanup(cleanup);
|
||||||
|
@ -769,12 +767,14 @@ void Sprite::sortAllChildren()
|
||||||
_children->fastSetObject(tempI, j+1);
|
_children->fastSetObject(tempI, j+1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
std::sort(std::begin(*_children), std::end(*_children), nodeComparisonLess);
|
std::sort(std::begin(_children), std::end(_children), nodeComparisonLess);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( _batchNode)
|
if ( _batchNode)
|
||||||
{
|
{
|
||||||
arrayMakeObjectsPerformSelector(_children, sortAllChildren, Sprite*);
|
_children.forEach([](Node* child){
|
||||||
|
child->sortAllChildren();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_reorderChildDirty = false;
|
_reorderChildDirty = false;
|
||||||
|
@ -809,15 +809,13 @@ void Sprite::setDirtyRecursively(bool bValue)
|
||||||
// recursively set dirty
|
// recursively set dirty
|
||||||
if (_hasChildren)
|
if (_hasChildren)
|
||||||
{
|
{
|
||||||
Object* object = NULL;
|
_children.forEach([](Node* child){
|
||||||
CCARRAY_FOREACH(_children, object)
|
Sprite* sp = dynamic_cast<Sprite*>(child);
|
||||||
|
if (sp)
|
||||||
{
|
{
|
||||||
Sprite* child = dynamic_cast<Sprite*>(object);
|
sp->setDirtyRecursively(true);
|
||||||
if (child)
|
|
||||||
{
|
|
||||||
child->setDirtyRecursively(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1062,7 +1060,7 @@ void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName,
|
||||||
|
|
||||||
CCASSERT(a, "CCSprite#setDisplayFrameWithAnimationName: Frame not found");
|
CCASSERT(a, "CCSprite#setDisplayFrameWithAnimationName: Frame not found");
|
||||||
|
|
||||||
AnimationFrame* frame = static_cast<AnimationFrame*>( a->getFrames()->getObjectAtIndex(frameIndex) );
|
AnimationFrame* frame = a->getFrames().at(frameIndex);
|
||||||
|
|
||||||
CCASSERT(frame, "CCSprite#setDisplayFrame. Invalid frame");
|
CCASSERT(frame, "CCSprite#setDisplayFrame. Invalid frame");
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity
|
||||||
* creation with File Image
|
* creation with File Image
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, long capacity/* = DEFAULT_CAPACITY*/)
|
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, int capacity/* = DEFAULT_CAPACITY*/)
|
||||||
{
|
{
|
||||||
SpriteBatchNode *batchNode = new SpriteBatchNode();
|
SpriteBatchNode *batchNode = new SpriteBatchNode();
|
||||||
batchNode->initWithFile(fileImage, capacity);
|
batchNode->initWithFile(fileImage, capacity);
|
||||||
|
@ -76,7 +76,7 @@ SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, long capacity/*
|
||||||
/*
|
/*
|
||||||
* init with Texture2D
|
* init with Texture2D
|
||||||
*/
|
*/
|
||||||
bool SpriteBatchNode::initWithTexture(Texture2D *tex, long capacity)
|
bool SpriteBatchNode::initWithTexture(Texture2D *tex, int capacity)
|
||||||
{
|
{
|
||||||
CCASSERT(capacity>=0, "Capacity must be >= 0");
|
CCASSERT(capacity>=0, "Capacity must be >= 0");
|
||||||
|
|
||||||
|
@ -92,9 +92,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, long capacity)
|
||||||
|
|
||||||
updateBlendFunc();
|
updateBlendFunc();
|
||||||
|
|
||||||
// no lazy alloc in this node
|
_children.reserve(capacity);
|
||||||
_children = new Array();
|
|
||||||
_children->initWithCapacity(capacity);
|
|
||||||
|
|
||||||
_descendants.reserve(capacity);
|
_descendants.reserve(capacity);
|
||||||
|
|
||||||
|
@ -112,7 +110,7 @@ bool SpriteBatchNode::init()
|
||||||
/*
|
/*
|
||||||
* init with FileImage
|
* init with FileImage
|
||||||
*/
|
*/
|
||||||
bool SpriteBatchNode::initWithFile(const char* fileImage, long capacity)
|
bool SpriteBatchNode::initWithFile(const char* fileImage, int capacity)
|
||||||
{
|
{
|
||||||
Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage);
|
Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage);
|
||||||
return initWithTexture(texture2D, capacity);
|
return initWithTexture(texture2D, capacity);
|
||||||
|
@ -187,7 +185,7 @@ void SpriteBatchNode::addChild(Node *child, int zOrder, int tag)
|
||||||
void SpriteBatchNode::reorderChild(Node *child, int zOrder)
|
void SpriteBatchNode::reorderChild(Node *child, int zOrder)
|
||||||
{
|
{
|
||||||
CCASSERT(child != NULL, "the child should not be null");
|
CCASSERT(child != NULL, "the child should not be null");
|
||||||
CCASSERT(_children->containsObject(child), "Child doesn't belong to Sprite");
|
CCASSERT(_children.contains(child), "Child doesn't belong to Sprite");
|
||||||
|
|
||||||
if (zOrder == child->getZOrder())
|
if (zOrder == child->getZOrder())
|
||||||
{
|
{
|
||||||
|
@ -209,7 +207,7 @@ void SpriteBatchNode::removeChild(Node *child, bool cleanup)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCASSERT(_children->containsObject(sprite), "sprite batch node should contain the child");
|
CCASSERT(_children.contains(sprite), "sprite batch node should contain the child");
|
||||||
|
|
||||||
// cleanup before removing
|
// cleanup before removing
|
||||||
removeSpriteFromAtlas(sprite);
|
removeSpriteFromAtlas(sprite);
|
||||||
|
@ -219,8 +217,8 @@ void SpriteBatchNode::removeChild(Node *child, bool cleanup)
|
||||||
|
|
||||||
void SpriteBatchNode::removeChildAtIndex(int index, bool doCleanup)
|
void SpriteBatchNode::removeChildAtIndex(int index, bool doCleanup)
|
||||||
{
|
{
|
||||||
CCASSERT(index>=0 && index < _children->count(), "Invalid index");
|
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
|
||||||
removeChild( static_cast<Sprite*>(_children->getObjectAtIndex(index)), doCleanup);
|
removeChild(_children.at(index), doCleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
void SpriteBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
||||||
|
@ -265,25 +263,25 @@ void SpriteBatchNode::sortAllChildren()
|
||||||
_children->fastSetObject(tempI, j+1);
|
_children->fastSetObject(tempI, j+1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
std::sort(std::begin(*_children), std::end(*_children), nodeComparisonLess);
|
std::sort(std::begin(_children), std::end(_children), nodeComparisonLess);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//sorted now check all children
|
//sorted now check all children
|
||||||
if (_children->count() > 0)
|
if (!_children.empty())
|
||||||
{
|
{
|
||||||
//first sort all children recursively based on zOrder
|
//first sort all children recursively based on zOrder
|
||||||
arrayMakeObjectsPerformSelector(_children, sortAllChildren, Sprite*);
|
_children.forEach([](Node* child){
|
||||||
|
child->sortAllChildren();
|
||||||
|
});
|
||||||
|
|
||||||
int index=0;
|
int index=0;
|
||||||
|
|
||||||
Object* obj = NULL;
|
|
||||||
//fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
|
//fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
|
||||||
// and at the same time reorder descendants and the quads to the right index
|
// and at the same time reorder descendants and the quads to the right index
|
||||||
CCARRAY_FOREACH(_children, obj)
|
_children.forEach([this, &index](Node* child){
|
||||||
{
|
Sprite* sp = static_cast<Sprite*>(child);
|
||||||
Sprite* child = static_cast<Sprite*>(obj);
|
updateAtlasIndex(sp, &index);
|
||||||
updateAtlasIndex(child, &index);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_reorderChildDirty=false;
|
_reorderChildDirty=false;
|
||||||
|
@ -292,12 +290,8 @@ void SpriteBatchNode::sortAllChildren()
|
||||||
|
|
||||||
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
||||||
{
|
{
|
||||||
int count = 0;
|
auto& array = sprite->getChildren();
|
||||||
Array* array = sprite->getChildren();
|
auto count = array.size();
|
||||||
if (array != NULL)
|
|
||||||
{
|
|
||||||
count = array->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
int oldIndex = 0;
|
int oldIndex = 0;
|
||||||
|
|
||||||
|
@ -315,7 +309,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
||||||
{
|
{
|
||||||
bool needNewIndex=true;
|
bool needNewIndex=true;
|
||||||
|
|
||||||
if (static_cast<Sprite*>(array->getObjectAtIndex(0) )->getZOrder() >= 0)
|
if (array.at(0)->getZOrder() >= 0)
|
||||||
{
|
{
|
||||||
//all children are in front of the parent
|
//all children are in front of the parent
|
||||||
oldIndex = sprite->getAtlasIndex();
|
oldIndex = sprite->getAtlasIndex();
|
||||||
|
@ -330,11 +324,9 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
||||||
needNewIndex = false;
|
needNewIndex = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* obj = NULL;
|
array.forEach([&](Node* child){
|
||||||
CCARRAY_FOREACH(array,obj)
|
Sprite* sp = static_cast<Sprite*>(child);
|
||||||
{
|
if (needNewIndex && sp->getZOrder() >= 0)
|
||||||
Sprite* child = static_cast<Sprite*>(obj);
|
|
||||||
if (needNewIndex && child->getZOrder() >= 0)
|
|
||||||
{
|
{
|
||||||
oldIndex = sprite->getAtlasIndex();
|
oldIndex = sprite->getAtlasIndex();
|
||||||
sprite->setAtlasIndex(*curIndex);
|
sprite->setAtlasIndex(*curIndex);
|
||||||
|
@ -344,11 +336,10 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
||||||
}
|
}
|
||||||
(*curIndex)++;
|
(*curIndex)++;
|
||||||
needNewIndex = false;
|
needNewIndex = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAtlasIndex(child, curIndex);
|
updateAtlasIndex(sp, curIndex);
|
||||||
}
|
});
|
||||||
|
|
||||||
if (needNewIndex)
|
if (needNewIndex)
|
||||||
{//all children have a zOrder < 0)
|
{//all children have a zOrder < 0)
|
||||||
|
@ -399,7 +390,9 @@ void SpriteBatchNode::draw(void)
|
||||||
|
|
||||||
CC_NODE_DRAW_SETUP();
|
CC_NODE_DRAW_SETUP();
|
||||||
|
|
||||||
arrayMakeObjectsPerformSelector(_children, updateTransform, Sprite*);
|
_children.forEach([](Node* child){
|
||||||
|
child->updateTransform();
|
||||||
|
});
|
||||||
|
|
||||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||||
|
|
||||||
|
@ -415,9 +408,9 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
|
||||||
// this is likely computationally expensive
|
// this is likely computationally expensive
|
||||||
int quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
|
int quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
|
||||||
|
|
||||||
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].",
|
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%d] to [%d].",
|
||||||
(long)_textureAtlas->getCapacity(),
|
_textureAtlas->getCapacity(),
|
||||||
(long)quantity);
|
quantity);
|
||||||
|
|
||||||
if (! _textureAtlas->resizeCapacity(quantity))
|
if (! _textureAtlas->resizeCapacity(quantity))
|
||||||
{
|
{
|
||||||
|
@ -429,22 +422,17 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
|
||||||
|
|
||||||
int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
|
int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
|
||||||
{
|
{
|
||||||
CCASSERT(index>=0 && index < _children->count(), "Invalid index");
|
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
|
||||||
|
|
||||||
Array *children = parent->getChildren();
|
auto& children = parent->getChildren();
|
||||||
|
|
||||||
if (children && children->count() > 0)
|
children.forEach([this, &index](Node* child){
|
||||||
|
Sprite* sp = static_cast<Sprite*>(child);
|
||||||
|
if (sp && (sp->getZOrder() < 0))
|
||||||
{
|
{
|
||||||
Object* object = NULL;
|
index = rebuildIndexInOrder(sp, index);
|
||||||
CCARRAY_FOREACH(children, object)
|
|
||||||
{
|
|
||||||
Sprite* child = static_cast<Sprite*>(object);
|
|
||||||
if (child && (child->getZOrder() < 0))
|
|
||||||
{
|
|
||||||
index = rebuildIndexInOrder(child, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ignore self (batch node)
|
// ignore self (batch node)
|
||||||
if (! parent->isEqual(this))
|
if (! parent->isEqual(this))
|
||||||
|
@ -453,61 +441,56 @@ int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (children && children->count() > 0)
|
children.forEach([this, &index](Node* child){
|
||||||
|
Sprite* sp = static_cast<Sprite*>(child);
|
||||||
|
if (sp && (sp->getZOrder() >= 0))
|
||||||
{
|
{
|
||||||
Object* object = NULL;
|
index = rebuildIndexInOrder(sp, index);
|
||||||
CCARRAY_FOREACH(children, object)
|
|
||||||
{
|
|
||||||
Sprite* child = static_cast<Sprite*>(object);
|
|
||||||
if (child && (child->getZOrder() >= 0))
|
|
||||||
{
|
|
||||||
index = rebuildIndexInOrder(child, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
|
int SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
|
||||||
{
|
{
|
||||||
Array *children = sprite->getChildren();
|
auto& children = sprite->getChildren();
|
||||||
|
|
||||||
if (! children || children->count() == 0)
|
if (children.size() == 0)
|
||||||
{
|
{
|
||||||
return sprite->getAtlasIndex();
|
return sprite->getAtlasIndex();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return highestAtlasIndexInChild( static_cast<Sprite*>(children->getLastObject()));
|
return highestAtlasIndexInChild( static_cast<Sprite*>(children.back()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
|
int SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
|
||||||
{
|
{
|
||||||
Array *children = sprite->getChildren();
|
auto& children = sprite->getChildren();
|
||||||
|
|
||||||
if (! children || children->count() == 0)
|
if (children.size() == 0)
|
||||||
{
|
{
|
||||||
return sprite->getAtlasIndex();
|
return sprite->getAtlasIndex();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return lowestAtlasIndexInChild(static_cast<Sprite*>(children->getObjectAtIndex(0)));
|
return lowestAtlasIndexInChild(static_cast<Sprite*>(children.at(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
|
int SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
|
||||||
{
|
{
|
||||||
Array *siblings = sprite->getParent()->getChildren();
|
auto& siblings = sprite->getParent()->getChildren();
|
||||||
int childIndex = siblings->getIndexOfObject(sprite);
|
auto childIndex = siblings.getIndex(sprite);
|
||||||
|
|
||||||
// ignore parent Z if parent is spriteSheet
|
// ignore parent Z if parent is spriteSheet
|
||||||
bool ignoreParent = (SpriteBatchNode*)(sprite->getParent()) == this;
|
bool ignoreParent = (SpriteBatchNode*)(sprite->getParent()) == this;
|
||||||
Sprite *prev = NULL;
|
Sprite *prev = NULL;
|
||||||
if (childIndex > 0 && childIndex != -1)
|
if (childIndex > 0 && childIndex != -1)
|
||||||
{
|
{
|
||||||
prev = static_cast<Sprite*>(siblings->getObjectAtIndex(childIndex - 1));
|
prev = static_cast<Sprite*>(siblings.at(childIndex - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// first child of the sprite sheet
|
// first child of the sprite sheet
|
||||||
|
@ -568,7 +551,7 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
|
||||||
}
|
}
|
||||||
|
|
||||||
_descendants.push_back(sprite);
|
_descendants.push_back(sprite);
|
||||||
int index = _descendants.size()-1;
|
int index = static_cast<int>(_descendants.size()-1);
|
||||||
|
|
||||||
sprite->setAtlasIndex(index);
|
sprite->setAtlasIndex(index);
|
||||||
|
|
||||||
|
@ -576,13 +559,9 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
|
||||||
_textureAtlas->insertQuad(&quad, index);
|
_textureAtlas->insertQuad(&quad, index);
|
||||||
|
|
||||||
// add children recursively
|
// add children recursively
|
||||||
|
sprite->getChildren().forEach([this](Node* child){
|
||||||
Object* obj = nullptr;
|
appendChild(static_cast<Sprite*>(child));
|
||||||
CCARRAY_FOREACH(sprite->getChildren(), obj)
|
});
|
||||||
{
|
|
||||||
Sprite* child = static_cast<Sprite*>(obj);
|
|
||||||
appendChild(child);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
||||||
|
@ -606,19 +585,14 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove children recursively
|
// remove children recursively
|
||||||
Array *children = sprite->getChildren();
|
auto& children = sprite->getChildren();
|
||||||
if (children && children->count() > 0)
|
children.forEach([this](Node* obj){
|
||||||
{
|
Sprite* child = static_cast<Sprite*>(obj);
|
||||||
Object* object = NULL;
|
|
||||||
CCARRAY_FOREACH(children, object)
|
|
||||||
{
|
|
||||||
Sprite* child = static_cast<Sprite*>(object);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
removeSpriteFromAtlas(child);
|
removeSpriteFromAtlas(child);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatchNode::updateBlendFunc(void)
|
void SpriteBatchNode::updateBlendFunc(void)
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
The file will be loaded using the TextureMgr.
|
The file will be loaded using the TextureMgr.
|
||||||
*/
|
*/
|
||||||
static SpriteBatchNode* create(const char* fileImage, long capacity = DEFAULT_CAPACITY);
|
static SpriteBatchNode* create(const char* fileImage, int capacity = DEFAULT_CAPACITY);
|
||||||
/**
|
/**
|
||||||
* @js ctor
|
* @js ctor
|
||||||
*/
|
*/
|
||||||
|
@ -88,14 +88,14 @@ public:
|
||||||
/** initializes a SpriteBatchNode with a texture2d and capacity of children.
|
/** initializes a SpriteBatchNode with a texture2d and capacity of children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
*/
|
*/
|
||||||
bool initWithTexture(Texture2D *tex, long capacity);
|
bool initWithTexture(Texture2D *tex, int capacity);
|
||||||
/** initializes a SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
|
/** initializes a SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
The file will be loaded using the TextureMgr.
|
The file will be loaded using the TextureMgr.
|
||||||
* @js init
|
* @js init
|
||||||
* @lua init
|
* @lua init
|
||||||
*/
|
*/
|
||||||
bool initWithFile(const char* fileImage, long capacity);
|
bool initWithFile(const char* fileImage, int capacity);
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
/** returns the TextureAtlas object */
|
/** returns the TextureAtlas object */
|
||||||
|
|
|
@ -64,22 +64,18 @@ void SpriteFrameCache::destroyInstance()
|
||||||
|
|
||||||
bool SpriteFrameCache::init(void)
|
bool SpriteFrameCache::init(void)
|
||||||
{
|
{
|
||||||
_spriteFrames= new Dictionary();
|
_spriteFrames.reserve(20);
|
||||||
_spriteFrames->init();
|
_spriteFramesAliases.reserve(20);
|
||||||
_spriteFramesAliases = new Dictionary();
|
|
||||||
_spriteFramesAliases->init();
|
|
||||||
_loadedFileNames = new std::set<std::string>();
|
_loadedFileNames = new std::set<std::string>();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteFrameCache::~SpriteFrameCache(void)
|
SpriteFrameCache::~SpriteFrameCache(void)
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_spriteFrames);
|
|
||||||
CC_SAFE_RELEASE(_spriteFramesAliases);
|
|
||||||
CC_SAFE_DELETE(_loadedFileNames);
|
CC_SAFE_DELETE(_loadedFileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Texture2D *pobTexture)
|
void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Texture2D* texture)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Supported Zwoptex Formats:
|
Supported Zwoptex Formats:
|
||||||
|
@ -90,25 +86,25 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
||||||
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
|
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Dictionary *metadataDict = (Dictionary*)dictionary->objectForKey("metadata");
|
|
||||||
Dictionary *framesDict = (Dictionary*)dictionary->objectForKey("frames");
|
ValueMap& framesDict = dictionary["frames"].asValueMap();
|
||||||
int format = 0;
|
int format = 0;
|
||||||
|
|
||||||
// get the format
|
// get the format
|
||||||
if(metadataDict != NULL)
|
if (dictionary.find("metadata") != dictionary.end())
|
||||||
{
|
{
|
||||||
format = metadataDict->valueForKey("format")->intValue();
|
ValueMap& metadataDict = dictionary["metadata"].asValueMap();
|
||||||
|
format = metadataDict["format"].asInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the format
|
// check the format
|
||||||
CCASSERT(format >=0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");
|
CCASSERT(format >=0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");
|
||||||
|
|
||||||
DictElement* element = NULL;
|
for (auto iter = framesDict.begin(); iter != framesDict.end(); ++iter)
|
||||||
CCDICT_FOREACH(framesDict, element)
|
|
||||||
{
|
{
|
||||||
Dictionary* frameDict = static_cast<Dictionary*>(element->getObject());
|
ValueMap& frameDict = iter->second.asValueMap();
|
||||||
std::string spriteFrameName = element->getStrKey();
|
std::string spriteFrameName = iter->first;
|
||||||
SpriteFrame* spriteFrame = static_cast<SpriteFrame*>(_spriteFrames->objectForKey(spriteFrameName));
|
SpriteFrame* spriteFrame = _spriteFrames.at(spriteFrameName);
|
||||||
if (spriteFrame)
|
if (spriteFrame)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -116,14 +112,14 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
||||||
|
|
||||||
if(format == 0)
|
if(format == 0)
|
||||||
{
|
{
|
||||||
float x = frameDict->valueForKey("x")->floatValue();
|
float x = frameDict["x"].asFloat();
|
||||||
float y = frameDict->valueForKey("y")->floatValue();
|
float y = frameDict["y"].asFloat();
|
||||||
float w = frameDict->valueForKey("width")->floatValue();
|
float w = frameDict["width"].asFloat();
|
||||||
float h = frameDict->valueForKey("height")->floatValue();
|
float h = frameDict["height"].asFloat();
|
||||||
float ox = frameDict->valueForKey("offsetX")->floatValue();
|
float ox = frameDict["offsetX"].asFloat();
|
||||||
float oy = frameDict->valueForKey("offsetY")->floatValue();
|
float oy = frameDict["offsetY"].asFloat();
|
||||||
int ow = frameDict->valueForKey("originalWidth")->intValue();
|
int ow = frameDict["originalWidth"].asInt();
|
||||||
int oh = frameDict->valueForKey("originalHeight")->intValue();
|
int oh = frameDict["originalHeight"].asInt();
|
||||||
// check ow/oh
|
// check ow/oh
|
||||||
if(!ow || !oh)
|
if(!ow || !oh)
|
||||||
{
|
{
|
||||||
|
@ -134,7 +130,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
||||||
oh = abs(oh);
|
oh = abs(oh);
|
||||||
// create frame
|
// create frame
|
||||||
spriteFrame = new SpriteFrame();
|
spriteFrame = new SpriteFrame();
|
||||||
spriteFrame->initWithTexture(pobTexture,
|
spriteFrame->initWithTexture(texture,
|
||||||
Rect(x, y, w, h),
|
Rect(x, y, w, h),
|
||||||
false,
|
false,
|
||||||
Point(ox, oy),
|
Point(ox, oy),
|
||||||
|
@ -143,21 +139,21 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
||||||
}
|
}
|
||||||
else if(format == 1 || format == 2)
|
else if(format == 1 || format == 2)
|
||||||
{
|
{
|
||||||
Rect frame = RectFromString(frameDict->valueForKey("frame")->getCString());
|
Rect frame = RectFromString(frameDict["frame"].asString());
|
||||||
bool rotated = false;
|
bool rotated = false;
|
||||||
|
|
||||||
// rotation
|
// rotation
|
||||||
if (format == 2)
|
if (format == 2)
|
||||||
{
|
{
|
||||||
rotated = frameDict->valueForKey("rotated")->boolValue();
|
rotated = frameDict["rotated"].asBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
Point offset = PointFromString(frameDict->valueForKey("offset")->getCString());
|
Point offset = PointFromString(frameDict["offset"].asString());
|
||||||
Size sourceSize = SizeFromString(frameDict->valueForKey("sourceSize")->getCString());
|
Size sourceSize = SizeFromString(frameDict["sourceSize"].asString());
|
||||||
|
|
||||||
// create frame
|
// create frame
|
||||||
spriteFrame = new SpriteFrame();
|
spriteFrame = new SpriteFrame();
|
||||||
spriteFrame->initWithTexture(pobTexture,
|
spriteFrame->initWithTexture(texture,
|
||||||
frame,
|
frame,
|
||||||
rotated,
|
rotated,
|
||||||
offset,
|
offset,
|
||||||
|
@ -167,31 +163,28 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
||||||
else if (format == 3)
|
else if (format == 3)
|
||||||
{
|
{
|
||||||
// get values
|
// get values
|
||||||
Size spriteSize = SizeFromString(frameDict->valueForKey("spriteSize")->getCString());
|
Size spriteSize = SizeFromString(frameDict["spriteSize"].asString());
|
||||||
Point spriteOffset = PointFromString(frameDict->valueForKey("spriteOffset")->getCString());
|
Point spriteOffset = PointFromString(frameDict["spriteOffset"].asString());
|
||||||
Size spriteSourceSize = SizeFromString(frameDict->valueForKey("spriteSourceSize")->getCString());
|
Size spriteSourceSize = SizeFromString(frameDict["spriteSourceSize"].asString());
|
||||||
Rect textureRect = RectFromString(frameDict->valueForKey("textureRect")->getCString());
|
Rect textureRect = RectFromString(frameDict["textureRect"].asString());
|
||||||
bool textureRotated = frameDict->valueForKey("textureRotated")->boolValue();
|
bool textureRotated = frameDict["textureRotated"].asBool();
|
||||||
|
|
||||||
// get aliases
|
// get aliases
|
||||||
Array* aliases = (Array*) (frameDict->objectForKey("aliases"));
|
ValueVector& aliases = frameDict["aliases"].asValueVector();
|
||||||
String * frameKey = new String(spriteFrameName);
|
|
||||||
|
|
||||||
Object* pObj = NULL;
|
std::for_each(aliases.cbegin(), aliases.cend(), [this, &spriteFrameName](const Value& value){
|
||||||
CCARRAY_FOREACH(aliases, pObj)
|
std::string oneAlias = value.asString();
|
||||||
{
|
if (_spriteFramesAliases.find(oneAlias) != _spriteFramesAliases.end())
|
||||||
std::string oneAlias = static_cast<String*>(pObj)->getCString();
|
|
||||||
if (_spriteFramesAliases->objectForKey(oneAlias.c_str()))
|
|
||||||
{
|
{
|
||||||
CCLOGWARN("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
CCLOGWARN("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
_spriteFramesAliases->setObject(frameKey, oneAlias.c_str());
|
_spriteFramesAliases[oneAlias] = Value(spriteFrameName);
|
||||||
}
|
});
|
||||||
frameKey->release();
|
|
||||||
// create frame
|
// create frame
|
||||||
spriteFrame = new SpriteFrame();
|
spriteFrame = new SpriteFrame();
|
||||||
spriteFrame->initWithTexture(pobTexture,
|
spriteFrame->initWithTexture(texture,
|
||||||
Rect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
|
Rect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
|
||||||
textureRotated,
|
textureRotated,
|
||||||
spriteOffset,
|
spriteOffset,
|
||||||
|
@ -199,7 +192,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
||||||
}
|
}
|
||||||
|
|
||||||
// add sprite frame
|
// add sprite frame
|
||||||
_spriteFrames->setObject(spriteFrame, spriteFrameName);
|
_spriteFrames.insert(spriteFrameName, spriteFrame);
|
||||||
spriteFrame->release();
|
spriteFrame->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,10 +200,9 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
||||||
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist, Texture2D *pobTexture)
|
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist, Texture2D *pobTexture)
|
||||||
{
|
{
|
||||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist);
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist);
|
||||||
Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||||
|
|
||||||
addSpriteFramesWithDictionary(dict, pobTexture);
|
addSpriteFramesWithDictionary(dict, pobTexture);
|
||||||
dict->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName)
|
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName)
|
||||||
|
@ -235,15 +227,15 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist)
|
||||||
if (_loadedFileNames->find(pszPlist) == _loadedFileNames->end())
|
if (_loadedFileNames->find(pszPlist) == _loadedFileNames->end())
|
||||||
{
|
{
|
||||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist);
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist);
|
||||||
Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||||
|
|
||||||
string texturePath("");
|
string texturePath("");
|
||||||
|
|
||||||
Dictionary* metadataDict = static_cast<Dictionary*>( dict->objectForKey("metadata") );
|
if (dict.find("metadata") != dict.end())
|
||||||
if (metadataDict)
|
|
||||||
{
|
{
|
||||||
|
ValueMap& metadataDict = dict["metadata"].asValueMap();
|
||||||
// try to read texture file name from meta data
|
// try to read texture file name from meta data
|
||||||
texturePath = metadataDict->valueForKey("textureFileName")->getCString();
|
texturePath = metadataDict["textureFileName"].asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!texturePath.empty())
|
if (!texturePath.empty())
|
||||||
|
@ -277,37 +269,39 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: SpriteFrameCache: Couldn't load texture");
|
CCLOG("cocos2d: SpriteFrameCache: Couldn't load texture");
|
||||||
}
|
}
|
||||||
dict->release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFrameCache::addSpriteFrame(SpriteFrame *pobFrame, const std::string& pszFrameName)
|
void SpriteFrameCache::addSpriteFrame(SpriteFrame* frame, const std::string& frameName)
|
||||||
{
|
{
|
||||||
_spriteFrames->setObject(pobFrame, pszFrameName);
|
_spriteFrames.insert(frameName, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFrameCache::removeSpriteFrames(void)
|
void SpriteFrameCache::removeSpriteFrames()
|
||||||
{
|
{
|
||||||
_spriteFrames->removeAllObjects();
|
_spriteFrames.clear();
|
||||||
_spriteFramesAliases->removeAllObjects();
|
_spriteFramesAliases.clear();
|
||||||
_loadedFileNames->clear();
|
_loadedFileNames->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFrameCache::removeUnusedSpriteFrames(void)
|
void SpriteFrameCache::removeUnusedSpriteFrames()
|
||||||
{
|
{
|
||||||
bool bRemoved = false;
|
bool bRemoved = false;
|
||||||
DictElement* element = NULL;
|
std::vector<std::string> toRemoveFrames;
|
||||||
CCDICT_FOREACH(_spriteFrames, element)
|
|
||||||
|
for (auto iter = _spriteFrames.begin(); iter != _spriteFrames.end(); ++iter)
|
||||||
{
|
{
|
||||||
SpriteFrame* spriteFrame = static_cast<SpriteFrame*>(element->getObject());
|
SpriteFrame* spriteFrame = iter->second;
|
||||||
if( spriteFrame->retainCount() == 1 )
|
if( spriteFrame->retainCount() == 1 )
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", element->getStrKey());
|
toRemoveFrames.push_back(iter->first);
|
||||||
_spriteFrames->removeObjectForElememt(element);
|
CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", iter->first.c_str());
|
||||||
bRemoved = true;
|
bRemoved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_spriteFrames.remove(toRemoveFrames);
|
||||||
|
|
||||||
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
|
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
|
||||||
if( bRemoved )
|
if( bRemoved )
|
||||||
{
|
{
|
||||||
|
@ -323,16 +317,16 @@ void SpriteFrameCache::removeSpriteFrameByName(const std::string& name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Is this an alias ?
|
// Is this an alias ?
|
||||||
String* key = (String*)_spriteFramesAliases->objectForKey(name);
|
std::string key = _spriteFramesAliases[name].asString();
|
||||||
|
|
||||||
if (key)
|
if (!key.empty())
|
||||||
{
|
{
|
||||||
_spriteFrames->removeObjectForKey(key->getCString());
|
_spriteFrames.remove(key);
|
||||||
_spriteFramesAliases->removeObjectForKey(key->getCString());
|
_spriteFramesAliases.erase(key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_spriteFrames->removeObjectForKey(name);
|
_spriteFrames.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
|
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
|
||||||
|
@ -342,13 +336,13 @@ void SpriteFrameCache::removeSpriteFrameByName(const std::string& name)
|
||||||
void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist)
|
void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist)
|
||||||
{
|
{
|
||||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);
|
||||||
Dictionary* dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||||
if (dict == nullptr)
|
if (dict.empty())
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFile: create dict by %s fail.",plist.c_str());
|
CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFile: create dict by %s fail.",plist.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
removeSpriteFramesFromDictionary((Dictionary*)dict);
|
removeSpriteFramesFromDictionary(dict);
|
||||||
|
|
||||||
// remove it from the cache
|
// remove it from the cache
|
||||||
set<string>::iterator ret = _loadedFileNames->find(plist);
|
set<string>::iterator ret = _loadedFileNames->find(plist);
|
||||||
|
@ -356,54 +350,51 @@ void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist)
|
||||||
{
|
{
|
||||||
_loadedFileNames->erase(ret);
|
_loadedFileNames->erase(ret);
|
||||||
}
|
}
|
||||||
dict->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFrameCache::removeSpriteFramesFromDictionary(Dictionary* dictionary)
|
void SpriteFrameCache::removeSpriteFramesFromDictionary(ValueMap& dictionary)
|
||||||
{
|
{
|
||||||
Dictionary* framesDict = static_cast<Dictionary*>(dictionary->objectForKey("frames"));
|
ValueMap framesDict = dictionary["frames"].asValueMap();
|
||||||
Array* keysToRemove = Array::create();
|
std::vector<std::string> keysToRemove;
|
||||||
|
|
||||||
DictElement* element = NULL;
|
for (auto iter = framesDict.cbegin(); iter != framesDict.cend(); ++iter)
|
||||||
CCDICT_FOREACH(framesDict, element)
|
|
||||||
{
|
{
|
||||||
if (_spriteFrames->objectForKey(element->getStrKey()))
|
if (_spriteFrames.at(iter->first))
|
||||||
{
|
{
|
||||||
keysToRemove->addObject(String::create(element->getStrKey()));
|
keysToRemove.push_back(iter->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_spriteFrames->removeObjectsForKeys(keysToRemove);
|
_spriteFrames.remove(keysToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture)
|
void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture)
|
||||||
{
|
{
|
||||||
Array* keysToRemove = Array::create();
|
std::vector<std::string> keysToRemove;
|
||||||
|
|
||||||
DictElement* element = NULL;
|
for (auto iter = _spriteFrames.cbegin(); iter != _spriteFrames.cend(); ++iter)
|
||||||
CCDICT_FOREACH(_spriteFrames, element)
|
|
||||||
{
|
{
|
||||||
string key = element->getStrKey();
|
std::string key = iter->first;
|
||||||
SpriteFrame* frame = static_cast<SpriteFrame*>(_spriteFrames->objectForKey(key.c_str()));
|
SpriteFrame* frame = _spriteFrames.at(key);
|
||||||
if (frame && (frame->getTexture() == texture))
|
if (frame && (frame->getTexture() == texture))
|
||||||
{
|
{
|
||||||
keysToRemove->addObject(String::create(element->getStrKey()));
|
keysToRemove.push_back(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_spriteFrames->removeObjectsForKeys(keysToRemove);
|
_spriteFrames.remove(keysToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)
|
SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)
|
||||||
{
|
{
|
||||||
SpriteFrame* frame = (SpriteFrame*)_spriteFrames->objectForKey(name);
|
SpriteFrame* frame = _spriteFrames.at(name);
|
||||||
if (!frame)
|
if (!frame)
|
||||||
{
|
{
|
||||||
// try alias dictionary
|
// try alias dictionary
|
||||||
String *key = (String*)_spriteFramesAliases->objectForKey(name);
|
std::string key = _spriteFramesAliases[name].asString();
|
||||||
if (key)
|
if (!key.empty())
|
||||||
{
|
{
|
||||||
frame = (SpriteFrame*)_spriteFrames->objectForKey(key->getCString());
|
frame = _spriteFrames.at(key);
|
||||||
if (!frame)
|
if (!frame)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: SpriteFrameCache: Frame '%s' not found", name.c_str());
|
CCLOG("cocos2d: SpriteFrameCache: Frame '%s' not found", name.c_str());
|
||||||
|
@ -414,3 +405,4 @@ SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -37,13 +37,13 @@ THE SOFTWARE.
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
|
#include "CCValue.h"
|
||||||
|
#include "CCMap.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class Dictionary;
|
|
||||||
class Array;
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// MARMALADE: Made this protected not private, as deriving from this class is pretty useful
|
// MARMALADE: Made this protected not private, as deriving from this class is pretty useful
|
||||||
SpriteFrameCache() : _spriteFrames(NULL), _spriteFramesAliases(NULL){}
|
SpriteFrameCache(){}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -115,13 +115,13 @@ public:
|
||||||
* In the medium term: it will allocate more resources.
|
* In the medium term: it will allocate more resources.
|
||||||
* In the long term: it will be the same.
|
* In the long term: it will be the same.
|
||||||
*/
|
*/
|
||||||
void removeSpriteFrames(void);
|
void removeSpriteFrames();
|
||||||
|
|
||||||
/** Removes unused sprite frames.
|
/** Removes unused sprite frames.
|
||||||
* Sprite Frames that have a retain count of 1 will be deleted.
|
* Sprite Frames that have a retain count of 1 will be deleted.
|
||||||
* It is convenient to call this method after when starting a new Scene.
|
* It is convenient to call this method after when starting a new Scene.
|
||||||
*/
|
*/
|
||||||
void removeUnusedSpriteFrames(void);
|
void removeUnusedSpriteFrames();
|
||||||
|
|
||||||
/** Deletes an sprite frame from the sprite frame cache. */
|
/** Deletes an sprite frame from the sprite frame cache. */
|
||||||
void removeSpriteFrameByName(const std::string& name);
|
void removeSpriteFrameByName(const std::string& name);
|
||||||
|
@ -153,16 +153,16 @@ public:
|
||||||
private:
|
private:
|
||||||
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
|
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
|
||||||
*/
|
*/
|
||||||
void addSpriteFramesWithDictionary(Dictionary* dictionary, Texture2D *texture);
|
void addSpriteFramesWithDictionary(ValueMap& dictionary, Texture2D *texture);
|
||||||
|
|
||||||
/** Removes multiple Sprite Frames from Dictionary.
|
/** Removes multiple Sprite Frames from Dictionary.
|
||||||
* @since v0.99.5
|
* @since v0.99.5
|
||||||
*/
|
*/
|
||||||
void removeSpriteFramesFromDictionary(Dictionary* dictionary);
|
void removeSpriteFramesFromDictionary(ValueMap& dictionary);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Dictionary* _spriteFrames;
|
Map<std::string, SpriteFrame*> _spriteFrames;
|
||||||
Dictionary* _spriteFramesAliases;
|
ValueMap _spriteFramesAliases;
|
||||||
std::set<std::string>* _loadedFileNames;
|
std::set<std::string>* _loadedFileNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
|
||||||
_minGID = layerInfo->_minGID;
|
_minGID = layerInfo->_minGID;
|
||||||
_maxGID = layerInfo->_maxGID;
|
_maxGID = layerInfo->_maxGID;
|
||||||
_opacity = layerInfo->_opacity;
|
_opacity = layerInfo->_opacity;
|
||||||
setProperties(Dictionary::createWithDictionary(layerInfo->getProperties()));
|
setProperties(layerInfo->getProperties());
|
||||||
_contentScaleFactor = Director::getInstance()->getContentScaleFactor();
|
_contentScaleFactor = Director::getInstance()->getContentScaleFactor();
|
||||||
|
|
||||||
// tilesetInfo
|
// tilesetInfo
|
||||||
|
@ -112,14 +112,12 @@ TMXLayer::TMXLayer()
|
||||||
,_tiles(NULL)
|
,_tiles(NULL)
|
||||||
,_tileSet(NULL)
|
,_tileSet(NULL)
|
||||||
,_layerOrientation(TMXOrientationOrtho)
|
,_layerOrientation(TMXOrientationOrtho)
|
||||||
,_properties(NULL)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TMXLayer::~TMXLayer()
|
TMXLayer::~TMXLayer()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_tileSet);
|
CC_SAFE_RELEASE(_tileSet);
|
||||||
CC_SAFE_RELEASE(_reusedTile);
|
CC_SAFE_RELEASE(_reusedTile);
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
|
|
||||||
if (_atlasIndexArray)
|
if (_atlasIndexArray)
|
||||||
{
|
{
|
||||||
|
@ -193,28 +191,28 @@ void TMXLayer::setupTiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TMXLayer - Properties
|
// TMXLayer - Properties
|
||||||
String* TMXLayer::getProperty(const char *propertyName) const
|
Value TMXLayer::getProperty(const std::string& propertyName) const
|
||||||
{
|
{
|
||||||
return static_cast<String*>(_properties->objectForKey(propertyName));
|
if (_properties.find(propertyName) != _properties.end())
|
||||||
|
return _properties.at(propertyName);
|
||||||
|
|
||||||
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TMXLayer::parseInternalProperties()
|
void TMXLayer::parseInternalProperties()
|
||||||
{
|
{
|
||||||
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
||||||
|
|
||||||
String *vertexz = getProperty("cc_vertexz");
|
auto vertexz = getProperty("cc_vertexz");
|
||||||
if (vertexz)
|
if (!vertexz.isNull())
|
||||||
{
|
{
|
||||||
|
std::string vertexZStr = vertexz.asString();
|
||||||
// If "automatic" is on, then parse the "cc_alpha_func" too
|
// If "automatic" is on, then parse the "cc_alpha_func" too
|
||||||
if (vertexz->_string == "automatic")
|
if (vertexZStr == "automatic")
|
||||||
{
|
{
|
||||||
_useAutomaticVertexZ = true;
|
_useAutomaticVertexZ = true;
|
||||||
String *alphaFuncVal = getProperty("cc_alpha_func");
|
auto alphaFuncVal = getProperty("cc_alpha_func");
|
||||||
float alphaFuncValue = 0.0f;
|
float alphaFuncValue = alphaFuncVal.asFloat();
|
||||||
if (alphaFuncVal != NULL)
|
|
||||||
{
|
|
||||||
alphaFuncValue = alphaFuncVal->floatValue();
|
|
||||||
}
|
|
||||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST));
|
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST));
|
||||||
|
|
||||||
GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
||||||
|
@ -228,7 +226,7 @@ void TMXLayer::parseInternalProperties()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_vertexZvalue = vertexz->intValue();
|
_vertexZvalue = vertexz.asInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,7 +379,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
||||||
setupTileSprite(tile, pos, gid);
|
setupTileSprite(tile, pos, gid);
|
||||||
|
|
||||||
// get atlas index
|
// get atlas index
|
||||||
unsigned int indexForZ = atlasIndexForNewZ(z);
|
unsigned int indexForZ = atlasIndexForNewZ(static_cast<int>(z));
|
||||||
|
|
||||||
// Optimization: add the quad without adding a child
|
// Optimization: add the quad without adding a child
|
||||||
this->insertQuadFromSprite(tile, indexForZ);
|
this->insertQuadFromSprite(tile, indexForZ);
|
||||||
|
@ -390,25 +388,23 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
||||||
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
|
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
|
||||||
|
|
||||||
// update possible children
|
// update possible children
|
||||||
if (_children && _children->count()>0)
|
|
||||||
{
|
_children.forEach([&indexForZ](Node* child){
|
||||||
Object* pObject = nullptr;
|
Sprite* sp = static_cast<Sprite*>(child);
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Sprite* child = static_cast<Sprite*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
unsigned int ai = child->getAtlasIndex();
|
int ai = sp->getAtlasIndex();
|
||||||
if ( ai >= indexForZ )
|
if ( ai >= indexForZ )
|
||||||
{
|
{
|
||||||
child->setAtlasIndex(ai+1);
|
sp->setAtlasIndex(ai+1);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_tiles[z] = gid;
|
_tiles[z] = gid;
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
||||||
{
|
{
|
||||||
Rect rect = _tileSet->rectForGID(gid);
|
Rect rect = _tileSet->rectForGID(gid);
|
||||||
|
@ -461,6 +457,7 @@ static inline int compareInts(const void * a, const void * b)
|
||||||
{
|
{
|
||||||
return ((*(int*)a) - (*(int*)b));
|
return ((*(int*)a) - (*(int*)b));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int TMXLayer::atlasIndexForExistantZ(unsigned int z)
|
unsigned int TMXLayer::atlasIndexForExistantZ(unsigned int z)
|
||||||
{
|
{
|
||||||
int key=z;
|
int key=z;
|
||||||
|
@ -471,6 +468,7 @@ unsigned int TMXLayer::atlasIndexForExistantZ(unsigned int z)
|
||||||
int index = ((size_t)item - (size_t)_atlasIndexArray->arr) / sizeof(void*);
|
int index = ((size_t)item - (size_t)_atlasIndexArray->arr) / sizeof(void*);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int TMXLayer::atlasIndexForNewZ(int z)
|
unsigned int TMXLayer::atlasIndexForNewZ(int z)
|
||||||
{
|
{
|
||||||
// XXX: This can be improved with a sort of binary search
|
// XXX: This can be improved with a sort of binary search
|
||||||
|
@ -558,7 +556,7 @@ void TMXLayer::removeChild(Node* node, bool cleanup)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCASSERT(_children->containsObject(sprite), "Tile does not belong to TMXLayer");
|
CCASSERT(_children.contains(sprite), "Tile does not belong to TMXLayer");
|
||||||
|
|
||||||
unsigned int atlasIndex = sprite->getAtlasIndex();
|
unsigned int atlasIndex = sprite->getAtlasIndex();
|
||||||
unsigned int zz = (size_t)_atlasIndexArray->arr[atlasIndex];
|
unsigned int zz = (size_t)_atlasIndexArray->arr[atlasIndex];
|
||||||
|
@ -596,12 +594,8 @@ void TMXLayer::removeTileAt(const Point& pos)
|
||||||
_textureAtlas->removeQuadAtIndex(atlasIndex);
|
_textureAtlas->removeQuadAtIndex(atlasIndex);
|
||||||
|
|
||||||
// update possible children
|
// update possible children
|
||||||
if (_children && _children->count()>0)
|
_children.forEach([&atlasIndex](Node* obj){
|
||||||
{
|
Sprite* child = static_cast<Sprite*>(obj);
|
||||||
Object* pObject = nullptr;
|
|
||||||
CCARRAY_FOREACH(_children, pObject)
|
|
||||||
{
|
|
||||||
Sprite* child = static_cast<Sprite*>(pObject);
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
unsigned int ai = child->getAtlasIndex();
|
unsigned int ai = child->getAtlasIndex();
|
||||||
|
@ -610,8 +604,7 @@ void TMXLayer::removeTileAt(const Point& pos)
|
||||||
child->setAtlasIndex(ai-1);
|
child->setAtlasIndex(ai-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,8 +137,8 @@ public:
|
||||||
CC_DEPRECATED_ATTRIBUTE Point positionAt(const Point& tileCoordinate) { return getPositionAt(tileCoordinate); };
|
CC_DEPRECATED_ATTRIBUTE Point positionAt(const Point& tileCoordinate) { return getPositionAt(tileCoordinate); };
|
||||||
|
|
||||||
/** return the value for the specific property name */
|
/** return the value for the specific property name */
|
||||||
String* getProperty(const char *propertyName) const;
|
Value getProperty(const std::string& propertyName) const;
|
||||||
CC_DEPRECATED_ATTRIBUTE String* propertyNamed(const char *propertyName) const { return getProperty(propertyName); };
|
CC_DEPRECATED_ATTRIBUTE Value propertyNamed(const std::string& propertyName) const { return getProperty(propertyName); };
|
||||||
|
|
||||||
/** Creates the tiles */
|
/** Creates the tiles */
|
||||||
void setupTiles();
|
void setupTiles();
|
||||||
|
@ -174,10 +174,9 @@ public:
|
||||||
inline void setLayerOrientation(unsigned int orientation) { _layerOrientation = orientation; };
|
inline void setLayerOrientation(unsigned int orientation) { _layerOrientation = orientation; };
|
||||||
|
|
||||||
/** properties from the layer. They can be added using Tiled */
|
/** properties from the layer. They can be added using Tiled */
|
||||||
inline Dictionary* getProperties() const { return _properties; };
|
inline const ValueMap& getProperties() const { return _properties; };
|
||||||
inline void setProperties(Dictionary* properties) {
|
inline ValueMap& getProperties() { return _properties; };
|
||||||
CC_SAFE_RETAIN(properties);
|
inline void setProperties(const ValueMap& properties) {
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
_properties = properties;
|
_properties = properties;
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
|
@ -244,7 +243,7 @@ protected:
|
||||||
/** Layer orientation, which is the same as the map orientation */
|
/** Layer orientation, which is the same as the map orientation */
|
||||||
unsigned int _layerOrientation;
|
unsigned int _layerOrientation;
|
||||||
/** properties from the layer. They can be added using Tiled */
|
/** properties from the layer. They can be added using Tiled */
|
||||||
Dictionary* _properties;
|
ValueMap _properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of tilemap_parallax_nodes group
|
// end of tilemap_parallax_nodes group
|
||||||
|
|
|
@ -35,41 +35,38 @@ TMXObjectGroup::TMXObjectGroup()
|
||||||
: _groupName("")
|
: _groupName("")
|
||||||
, _positionOffset(Point::ZERO)
|
, _positionOffset(Point::ZERO)
|
||||||
{
|
{
|
||||||
_objects = Array::create();
|
|
||||||
_objects->retain();
|
|
||||||
_properties = new Dictionary();
|
|
||||||
_properties->init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TMXObjectGroup::~TMXObjectGroup()
|
TMXObjectGroup::~TMXObjectGroup()
|
||||||
{
|
{
|
||||||
CCLOGINFO("deallocing TMXObjectGroup: %p", this);
|
CCLOGINFO("deallocing TMXObjectGroup: %p", this);
|
||||||
CC_SAFE_RELEASE(_objects);
|
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary* TMXObjectGroup::getObject(const char *objectName) const
|
ValueMap TMXObjectGroup::getObject(const std::string& objectName) const
|
||||||
{
|
{
|
||||||
if (_objects && _objects->count() > 0)
|
if (!_objects.empty())
|
||||||
{
|
{
|
||||||
Object* pObj = nullptr;
|
for (const auto& v : _objects)
|
||||||
CCARRAY_FOREACH(_objects, pObj)
|
|
||||||
{
|
{
|
||||||
Dictionary* pDict = static_cast<Dictionary*>(pObj);
|
const ValueMap& dict = v.asValueMap();
|
||||||
String *name = static_cast<String*>(pDict->objectForKey("name"));
|
if (dict.find("name") != dict.end())
|
||||||
if (name && name->_string == objectName)
|
|
||||||
{
|
{
|
||||||
return pDict;
|
if (dict.at("name").asString() == objectName)
|
||||||
|
return dict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// object not found
|
// object not found
|
||||||
return NULL;
|
return ValueMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
String* TMXObjectGroup::getProperty(const char* propertyName) const
|
Value TMXObjectGroup::getProperty(const std::string& propertyName) const
|
||||||
{
|
{
|
||||||
return static_cast<String*>(_properties->objectForKey(propertyName));
|
if (_properties.find(propertyName) != _properties.end())
|
||||||
|
return _properties.at(propertyName);
|
||||||
|
|
||||||
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
#include "CCArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCDictionary.h"
|
#include "CCValue.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -55,20 +55,20 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ~TMXObjectGroup();
|
virtual ~TMXObjectGroup();
|
||||||
|
|
||||||
inline const char* getGroupName(){ return _groupName.c_str(); }
|
inline const std::string& getGroupName(){ return _groupName; }
|
||||||
inline void setGroupName(const char *groupName){ _groupName = groupName; }
|
inline void setGroupName(const std::string& groupName){ _groupName = groupName; }
|
||||||
|
|
||||||
/** return the value for the specific property name */
|
/** return the value for the specific property name */
|
||||||
String* getProperty(const char* propertyName) const;
|
Value getProperty(const std::string& propertyName) const;
|
||||||
|
|
||||||
CC_DEPRECATED_ATTRIBUTE String *propertyNamed(const char* propertyName) const { return getProperty(propertyName); };
|
CC_DEPRECATED_ATTRIBUTE Value propertyNamed(const std::string& propertyName) const { return getProperty(propertyName); };
|
||||||
|
|
||||||
/** return the dictionary for the specific object name.
|
/** return the dictionary for the specific object name.
|
||||||
It will return the 1st object found on the array for the given name.
|
It will return the 1st object found on the array for the given name.
|
||||||
*/
|
*/
|
||||||
Dictionary* getObject(const char *objectName) const;
|
ValueMap getObject(const std::string& objectName) const;
|
||||||
|
|
||||||
CC_DEPRECATED_ATTRIBUTE Dictionary* objectNamed(const char *objectName) const { return getObject(objectName); };
|
CC_DEPRECATED_ATTRIBUTE ValueMap objectNamed(const std::string& objectName) const { return getObject(objectName); };
|
||||||
|
|
||||||
/** Gets the offset position of child objects */
|
/** Gets the offset position of child objects */
|
||||||
inline const Point& getPositionOffset() const { return _positionOffset; };
|
inline const Point& getPositionOffset() const { return _positionOffset; };
|
||||||
|
@ -77,22 +77,20 @@ public:
|
||||||
inline void setPositionOffset(const Point& offset) { _positionOffset = offset; };
|
inline void setPositionOffset(const Point& offset) { _positionOffset = offset; };
|
||||||
|
|
||||||
/** Gets the list of properties stored in a dictionary */
|
/** Gets the list of properties stored in a dictionary */
|
||||||
inline Dictionary* getProperties() const { return _properties; };
|
inline const ValueMap& getProperties() const { return _properties; };
|
||||||
|
inline ValueMap& getProperties() { return _properties; };
|
||||||
|
|
||||||
/** Sets the list of properties */
|
/** Sets the list of properties */
|
||||||
inline void setProperties(Dictionary* properties) {
|
inline void setProperties(const ValueMap& properties) {
|
||||||
CC_SAFE_RETAIN(properties);
|
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
_properties = properties;
|
_properties = properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Gets the array of the objects */
|
/** Gets the array of the objects */
|
||||||
inline Array* getObjects() const { return _objects; };
|
inline const ValueVector& getObjects() const { return _objects; };
|
||||||
|
inline ValueVector& getObjects() { return _objects; };
|
||||||
|
|
||||||
/** Sets the array of the objects */
|
/** Sets the array of the objects */
|
||||||
inline void setObjects(Array* objects) {
|
inline void setObjects(const ValueVector& objects) {
|
||||||
CC_SAFE_RETAIN(objects);
|
|
||||||
CC_SAFE_RELEASE(_objects);
|
|
||||||
_objects = objects;
|
_objects = objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,9 +100,9 @@ protected:
|
||||||
/** offset position of child objects */
|
/** offset position of child objects */
|
||||||
Point _positionOffset;
|
Point _positionOffset;
|
||||||
/** list of properties stored in a dictionary */
|
/** list of properties stored in a dictionary */
|
||||||
Dictionary* _properties;
|
ValueMap _properties;
|
||||||
/** array of the objects */
|
/** array of the objects */
|
||||||
Array* _objects;
|
ValueVector _objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of tilemap_parallax_nodes group
|
// end of tilemap_parallax_nodes group
|
||||||
|
|
|
@ -42,7 +42,7 @@ TMXTiledMap * TMXTiledMap::create(const std::string& tmxFile)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(ret);
|
CC_SAFE_DELETE(ret);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||||
|
@ -54,7 +54,7 @@ TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(ret);
|
CC_SAFE_DELETE(ret);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
||||||
|
@ -69,7 +69,7 @@ bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CCASSERT( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
|
CCASSERT( !mapInfo->getTilesets().empty(), "TMXTiledMap: Map not found. Please check the filename.");
|
||||||
buildWithMapInfo(mapInfo);
|
buildWithMapInfo(mapInfo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -81,7 +81,7 @@ bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& r
|
||||||
|
|
||||||
TMXMapInfo *mapInfo = TMXMapInfo::createWithXML(tmxString, resourcePath);
|
TMXMapInfo *mapInfo = TMXMapInfo::createWithXML(tmxString, resourcePath);
|
||||||
|
|
||||||
CCASSERT( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
|
CCASSERT( !mapInfo->getTilesets().empty(), "TMXTiledMap: Map not found. Please check the filename.");
|
||||||
buildWithMapInfo(mapInfo);
|
buildWithMapInfo(mapInfo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -90,16 +90,11 @@ bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& r
|
||||||
TMXTiledMap::TMXTiledMap()
|
TMXTiledMap::TMXTiledMap()
|
||||||
:_mapSize(Size::ZERO)
|
:_mapSize(Size::ZERO)
|
||||||
,_tileSize(Size::ZERO)
|
,_tileSize(Size::ZERO)
|
||||||
,_objectGroups(NULL)
|
|
||||||
,_properties(NULL)
|
|
||||||
,_tileProperties(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TMXTiledMap::~TMXTiledMap()
|
TMXTiledMap::~TMXTiledMap()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
CC_SAFE_RELEASE(_objectGroups);
|
|
||||||
CC_SAFE_RELEASE(_tileProperties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
|
@ -118,14 +113,13 @@ TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
|
||||||
TMXTilesetInfo * TMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
|
TMXTilesetInfo * TMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
|
||||||
{
|
{
|
||||||
Size size = layerInfo->_layerSize;
|
Size size = layerInfo->_layerSize;
|
||||||
Array* tilesets = mapInfo->getTilesets();
|
auto& tilesets = mapInfo->getTilesets();
|
||||||
if (tilesets && tilesets->count()>0)
|
if (tilesets.size()>0)
|
||||||
{
|
{
|
||||||
TMXTilesetInfo* tileset = NULL;
|
TMXTilesetInfo* tileset = nullptr;
|
||||||
Object* pObj = NULL;
|
for (auto iter = tilesets.crbegin(); iter != tilesets.crend(); ++iter)
|
||||||
CCARRAY_FOREACH_REVERSE(tilesets, pObj)
|
|
||||||
{
|
{
|
||||||
tileset = static_cast<TMXTilesetInfo*>(pObj);
|
tileset = *iter;
|
||||||
if (tileset)
|
if (tileset)
|
||||||
{
|
{
|
||||||
for( unsigned int y=0; y < size.height; y++ )
|
for( unsigned int y=0; y < size.height; y++ )
|
||||||
|
@ -157,7 +151,7 @@ TMXTilesetInfo * TMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInf
|
||||||
|
|
||||||
// If all the tiles are 0, return empty tileset
|
// If all the tiles are 0, return empty tileset
|
||||||
CCLOG("cocos2d: Warning: TMX Layer '%s' has no tiles", layerInfo->_name.c_str());
|
CCLOG("cocos2d: Warning: TMX Layer '%s' has no tiles", layerInfo->_name.c_str());
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
||||||
|
@ -166,28 +160,15 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
||||||
_tileSize = mapInfo->getTileSize();
|
_tileSize = mapInfo->getTileSize();
|
||||||
_mapOrientation = mapInfo->getOrientation();
|
_mapOrientation = mapInfo->getOrientation();
|
||||||
|
|
||||||
CC_SAFE_RELEASE(_objectGroups);
|
|
||||||
_objectGroups = mapInfo->getObjectGroups();
|
_objectGroups = mapInfo->getObjectGroups();
|
||||||
CC_SAFE_RETAIN(_objectGroups);
|
|
||||||
|
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
_properties = mapInfo->getProperties();
|
_properties = mapInfo->getProperties();
|
||||||
CC_SAFE_RETAIN(_properties);
|
|
||||||
|
|
||||||
CC_SAFE_RELEASE(_tileProperties);
|
|
||||||
_tileProperties = mapInfo->getTileProperties();
|
_tileProperties = mapInfo->getTileProperties();
|
||||||
CC_SAFE_RETAIN(_tileProperties);
|
|
||||||
|
|
||||||
int idx=0;
|
int idx=0;
|
||||||
|
|
||||||
Array* layers = mapInfo->getLayers();
|
mapInfo->getLayers().forEach([&idx, this, &mapInfo](TMXLayerInfo* layerInfo){
|
||||||
if (layers && layers->count()>0)
|
|
||||||
{
|
|
||||||
TMXLayerInfo* layerInfo = NULL;
|
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(layers, pObj)
|
|
||||||
{
|
|
||||||
layerInfo = static_cast<TMXLayerInfo*>(pObj);
|
|
||||||
if (layerInfo && layerInfo->_visible)
|
if (layerInfo && layerInfo->_visible)
|
||||||
{
|
{
|
||||||
TMXLayer *child = parseLayer(layerInfo, mapInfo);
|
TMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||||
|
@ -202,18 +183,17 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
||||||
|
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public
|
// public
|
||||||
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
|
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
|
||||||
{
|
{
|
||||||
CCASSERT(layerName.size() > 0, "Invalid layer name!");
|
CCASSERT(layerName.size() > 0, "Invalid layer name!");
|
||||||
Object* pObj = NULL;
|
|
||||||
CCARRAY_FOREACH(_children, pObj)
|
for (auto& child : _children)
|
||||||
{
|
{
|
||||||
TMXLayer* layer = dynamic_cast<TMXLayer*>(pObj);
|
TMXLayer* layer = dynamic_cast<TMXLayer*>(child);
|
||||||
if(layer)
|
if(layer)
|
||||||
{
|
{
|
||||||
if(layerName.compare( layer->getLayerName()) == 0)
|
if(layerName.compare( layer->getLayerName()) == 0)
|
||||||
|
@ -224,20 +204,19 @@ TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// layer not found
|
// layer not found
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
|
TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
|
||||||
{
|
{
|
||||||
CCASSERT(groupName.size() > 0, "Invalid group name!");
|
CCASSERT(groupName.size() > 0, "Invalid group name!");
|
||||||
|
|
||||||
if (_objectGroups && _objectGroups->count()>0)
|
if (_objectGroups.size()>0)
|
||||||
{
|
{
|
||||||
TMXObjectGroup* objectGroup = NULL;
|
TMXObjectGroup* objectGroup = nullptr;
|
||||||
Object* pObj = NULL;
|
for (auto iter = _objectGroups.cbegin(); iter != _objectGroups.cend(); ++iter)
|
||||||
CCARRAY_FOREACH(_objectGroups, pObj)
|
|
||||||
{
|
{
|
||||||
objectGroup = static_cast<TMXObjectGroup*>(pObj);
|
objectGroup = *iter;
|
||||||
if (objectGroup && objectGroup->getGroupName() == groupName)
|
if (objectGroup && objectGroup->getGroupName() == groupName)
|
||||||
{
|
{
|
||||||
return objectGroup;
|
return objectGroup;
|
||||||
|
@ -246,17 +225,23 @@ TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// objectGroup not found
|
// objectGroup not found
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
String* TMXTiledMap::getProperty(const std::string& propertyName) const
|
Value TMXTiledMap::getProperty(const std::string& propertyName) const
|
||||||
{
|
{
|
||||||
return static_cast<String*>(_properties->objectForKey(propertyName));
|
if (_properties.find(propertyName) != _properties.end())
|
||||||
|
return _properties.at(propertyName);
|
||||||
|
|
||||||
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary* TMXTiledMap::getPropertiesForGID(int GID) const
|
Value TMXTiledMap::getPropertiesForGID(int GID) const
|
||||||
{
|
{
|
||||||
return static_cast<Dictionary*>(_tileProperties->objectForKey(GID));
|
if (_tileProperties.find(GID) != _tileProperties.end())
|
||||||
|
return _tileProperties.at(GID);
|
||||||
|
|
||||||
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCTMXObjectGroup.h"
|
#include "CCTMXObjectGroup.h"
|
||||||
|
#include "CCValue.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -132,16 +133,16 @@ public:
|
||||||
CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const char *groupName) const { return getObjectGroup(groupName); };
|
CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const char *groupName) const { return getObjectGroup(groupName); };
|
||||||
|
|
||||||
/** return the value for the specific property name */
|
/** return the value for the specific property name */
|
||||||
String *getProperty(const std::string& propertyName) const;
|
Value getProperty(const std::string& propertyName) const;
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE String *propertyNamed(const char *propertyName) const { return getProperty(propertyName); };
|
CC_DEPRECATED_ATTRIBUTE Value propertyNamed(const char *propertyName) const { return getProperty(propertyName); };
|
||||||
|
|
||||||
/** return properties dictionary for tile GID */
|
/** return properties dictionary for tile GID */
|
||||||
Dictionary* getPropertiesForGID(int GID) const;
|
Value getPropertiesForGID(int GID) const;
|
||||||
CC_DEPRECATED_ATTRIBUTE Dictionary* propertiesForGID(int GID) const { return getPropertiesForGID(GID); };
|
CC_DEPRECATED_ATTRIBUTE Value propertiesForGID(int GID) const { return getPropertiesForGID(GID); };
|
||||||
|
|
||||||
/** the map's size property measured in tiles */
|
/** the map's size property measured in tiles */
|
||||||
inline const Size& getMapSize() const { return _mapSize; };
|
inline const Size& getMapSize() const { return _mapSize; };
|
||||||
|
@ -156,18 +157,15 @@ public:
|
||||||
inline void setMapOrientation(int mapOrientation) { _mapOrientation = mapOrientation; };
|
inline void setMapOrientation(int mapOrientation) { _mapOrientation = mapOrientation; };
|
||||||
|
|
||||||
/** object groups */
|
/** object groups */
|
||||||
inline Array* getObjectGroups() const { return _objectGroups; };
|
inline const Vector<TMXObjectGroup*>& getObjectGroups() const { return _objectGroups; };
|
||||||
inline void setObjectGroups(Array* groups) {
|
inline Vector<TMXObjectGroup*>& getObjectGroups() { return _objectGroups; };
|
||||||
CC_SAFE_RETAIN(groups);
|
inline void setObjectGroups(const Vector<TMXObjectGroup*>& groups) {
|
||||||
CC_SAFE_RELEASE(_objectGroups);
|
|
||||||
_objectGroups = groups;
|
_objectGroups = groups;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** properties */
|
/** properties */
|
||||||
inline Dictionary* getProperties() const { return _properties; };
|
inline ValueMap& getProperties() { return _properties; };
|
||||||
inline void setProperties(Dictionary* properties) {
|
inline void setProperties(const ValueMap& properties) {
|
||||||
CC_SAFE_RETAIN(properties);
|
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
_properties = properties;
|
_properties = properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -199,12 +197,12 @@ protected:
|
||||||
/** map orientation */
|
/** map orientation */
|
||||||
int _mapOrientation;
|
int _mapOrientation;
|
||||||
/** object groups */
|
/** object groups */
|
||||||
Array* _objectGroups;
|
Vector<TMXObjectGroup*> _objectGroups;
|
||||||
/** properties */
|
/** properties */
|
||||||
Dictionary* _properties;
|
ValueMap _properties;
|
||||||
|
|
||||||
//! tile properties
|
//! tile properties
|
||||||
Dictionary* _tileProperties;
|
IntValueMap _tileProperties;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(TMXTiledMap);
|
CC_DISALLOW_COPY_AND_ASSIGN(TMXTiledMap);
|
||||||
|
|
|
@ -38,47 +38,33 @@ using namespace std;
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static const char* valueForKey(const char *key, std::unordered_map<std::string, std::string>* dict)
|
|
||||||
{
|
|
||||||
if (dict)
|
|
||||||
{
|
|
||||||
std::unordered_map<std::string, std::string>::iterator it = dict->find(key);
|
|
||||||
return it!=dict->end() ? it->second.c_str() : "";
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
// implementation TMXLayerInfo
|
// implementation TMXLayerInfo
|
||||||
TMXLayerInfo::TMXLayerInfo()
|
TMXLayerInfo::TMXLayerInfo()
|
||||||
: _name("")
|
: _name("")
|
||||||
, _tiles(NULL)
|
, _tiles(nullptr)
|
||||||
, _ownTiles(true)
|
, _ownTiles(true)
|
||||||
, _minGID(100000)
|
, _minGID(100000)
|
||||||
, _maxGID(0)
|
, _maxGID(0)
|
||||||
, _offset(Point::ZERO)
|
, _offset(Point::ZERO)
|
||||||
{
|
{
|
||||||
_properties = new Dictionary();
|
|
||||||
_properties->init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TMXLayerInfo::~TMXLayerInfo()
|
TMXLayerInfo::~TMXLayerInfo()
|
||||||
{
|
{
|
||||||
CCLOGINFO("deallocing TMXLayerInfo: %p", this);
|
CCLOGINFO("deallocing TMXLayerInfo: %p", this);
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
if( _ownTiles && _tiles )
|
if( _ownTiles && _tiles )
|
||||||
{
|
{
|
||||||
free(_tiles);
|
free(_tiles);
|
||||||
_tiles = NULL;
|
_tiles = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary * TMXLayerInfo::getProperties()
|
ValueMap TMXLayerInfo::getProperties()
|
||||||
{
|
{
|
||||||
return _properties;
|
return _properties;
|
||||||
}
|
}
|
||||||
void TMXLayerInfo::setProperties(Dictionary* var)
|
void TMXLayerInfo::setProperties(ValueMap var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
_properties = var;
|
_properties = var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +107,7 @@ TMXMapInfo * TMXMapInfo::create(const std::string& tmxFile)
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||||
|
@ -133,17 +119,11 @@ TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string& resourcePath)
|
void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string& resourcePath)
|
||||||
{
|
{
|
||||||
_tilesets = Array::create();
|
|
||||||
_tilesets->retain();
|
|
||||||
|
|
||||||
_layers = Array::create();
|
|
||||||
_layers->retain();
|
|
||||||
|
|
||||||
if (tmxFileName.size() > 0)
|
if (tmxFileName.size() > 0)
|
||||||
{
|
{
|
||||||
_TMXFileName = FileUtils::getInstance()->fullPathForFilename(tmxFileName);
|
_TMXFileName = FileUtils::getInstance()->fullPathForFilename(tmxFileName);
|
||||||
|
@ -154,13 +134,7 @@ void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string&
|
||||||
_resources = resourcePath;
|
_resources = resourcePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
_objectGroups = Array::createWithCapacity(4);
|
_objectGroups.reserve(4);
|
||||||
_objectGroups->retain();
|
|
||||||
|
|
||||||
_properties = new Dictionary();
|
|
||||||
_properties->init();
|
|
||||||
_tileProperties = new Dictionary();
|
|
||||||
_tileProperties->init();
|
|
||||||
|
|
||||||
// tmp vars
|
// tmp vars
|
||||||
_currentString = "";
|
_currentString = "";
|
||||||
|
@ -184,13 +158,8 @@ bool TMXMapInfo::initWithTMXFile(const std::string& tmxFile)
|
||||||
TMXMapInfo::TMXMapInfo()
|
TMXMapInfo::TMXMapInfo()
|
||||||
: _mapSize(Size::ZERO)
|
: _mapSize(Size::ZERO)
|
||||||
, _tileSize(Size::ZERO)
|
, _tileSize(Size::ZERO)
|
||||||
, _layers(NULL)
|
|
||||||
, _tilesets(NULL)
|
|
||||||
, _objectGroups(NULL)
|
|
||||||
, _layerAttribs(0)
|
, _layerAttribs(0)
|
||||||
, _storingCharacters(false)
|
, _storingCharacters(false)
|
||||||
, _properties(NULL)
|
|
||||||
, _tileProperties(NULL)
|
|
||||||
, _currentFirstGID(0)
|
, _currentFirstGID(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -198,16 +167,11 @@ TMXMapInfo::TMXMapInfo()
|
||||||
TMXMapInfo::~TMXMapInfo()
|
TMXMapInfo::~TMXMapInfo()
|
||||||
{
|
{
|
||||||
CCLOGINFO("deallocing TMXMapInfo: %p", this);
|
CCLOGINFO("deallocing TMXMapInfo: %p", this);
|
||||||
CC_SAFE_RELEASE(_tilesets);
|
|
||||||
CC_SAFE_RELEASE(_layers);
|
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
CC_SAFE_RELEASE(_tileProperties);
|
|
||||||
CC_SAFE_RELEASE(_objectGroups);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMXMapInfo::parseXMLString(const std::string& xmlString)
|
bool TMXMapInfo::parseXMLString(const std::string& xmlString)
|
||||||
{
|
{
|
||||||
int len = xmlString.size();
|
size_t len = xmlString.size();
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -244,24 +208,24 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
CC_UNUSED_PARAM(ctx);
|
CC_UNUSED_PARAM(ctx);
|
||||||
TMXMapInfo *pTMXMapInfo = this;
|
TMXMapInfo *pTMXMapInfo = this;
|
||||||
std::string elementName = (char*)name;
|
std::string elementName = (char*)name;
|
||||||
std::unordered_map<std::string, std::string> *attributeDict = new std::unordered_map<std::string, std::string>();
|
ValueMap attributeDict;
|
||||||
if (atts && atts[0])
|
if (atts && atts[0])
|
||||||
{
|
{
|
||||||
for(int i = 0; atts[i]; i += 2)
|
for(int i = 0; atts[i]; i += 2)
|
||||||
{
|
{
|
||||||
std::string key = (char*)atts[i];
|
std::string key = (char*)atts[i];
|
||||||
std::string value = (char*)atts[i+1];
|
std::string value = (char*)atts[i+1];
|
||||||
attributeDict->insert(pair<std::string, std::string>(key, value));
|
attributeDict.insert(std::make_pair(key, Value(value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (elementName == "map")
|
if (elementName == "map")
|
||||||
{
|
{
|
||||||
std::string version = valueForKey("version", attributeDict);
|
std::string version = attributeDict["version"].asString();
|
||||||
if ( version != "1.0")
|
if ( version != "1.0")
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %s", version.c_str());
|
CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %s", version.c_str());
|
||||||
}
|
}
|
||||||
std::string orientationStr = valueForKey("orientation", attributeDict);
|
std::string orientationStr = attributeDict["orientation"].asString();
|
||||||
if (orientationStr == "orthogonal")
|
if (orientationStr == "orthogonal")
|
||||||
pTMXMapInfo->setOrientation(TMXOrientationOrtho);
|
pTMXMapInfo->setOrientation(TMXOrientationOrtho);
|
||||||
else if (orientationStr == "isometric")
|
else if (orientationStr == "isometric")
|
||||||
|
@ -272,12 +236,12 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", pTMXMapInfo->getOrientation());
|
CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", pTMXMapInfo->getOrientation());
|
||||||
|
|
||||||
Size s;
|
Size s;
|
||||||
s.width = (float)atof(valueForKey("width", attributeDict));
|
s.width = attributeDict["width"].asFloat();
|
||||||
s.height = (float)atof(valueForKey("height", attributeDict));
|
s.height = attributeDict["height"].asFloat();
|
||||||
pTMXMapInfo->setMapSize(s);
|
pTMXMapInfo->setMapSize(s);
|
||||||
|
|
||||||
s.width = (float)atof(valueForKey("tilewidth", attributeDict));
|
s.width = attributeDict["tilewidth"].asFloat();
|
||||||
s.height = (float)atof(valueForKey("tileheight", attributeDict));
|
s.height = attributeDict["tileheight"].asFloat();
|
||||||
pTMXMapInfo->setTileSize(s);
|
pTMXMapInfo->setTileSize(s);
|
||||||
|
|
||||||
// The parent element is now "map"
|
// The parent element is now "map"
|
||||||
|
@ -286,7 +250,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
else if (elementName == "tileset")
|
else if (elementName == "tileset")
|
||||||
{
|
{
|
||||||
// If this is an external tileset then start parsing that
|
// If this is an external tileset then start parsing that
|
||||||
std::string externalTilesetFilename = valueForKey("source", attributeDict);
|
std::string externalTilesetFilename = attributeDict["source"].asString();
|
||||||
if (externalTilesetFilename != "")
|
if (externalTilesetFilename != "")
|
||||||
{
|
{
|
||||||
// Tileset file will be relative to the map file. So we need to convert it to an absolute path
|
// Tileset file will be relative to the map file. So we need to convert it to an absolute path
|
||||||
|
@ -301,31 +265,31 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
}
|
}
|
||||||
externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename.c_str());
|
externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename.c_str());
|
||||||
|
|
||||||
_currentFirstGID = (unsigned int)atoi(valueForKey("firstgid", attributeDict));
|
_currentFirstGID = (unsigned int)attributeDict["firstgid"].asInt();
|
||||||
|
|
||||||
pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str());
|
pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TMXTilesetInfo *tileset = new TMXTilesetInfo();
|
TMXTilesetInfo *tileset = new TMXTilesetInfo();
|
||||||
tileset->_name = valueForKey("name", attributeDict);
|
tileset->_name = attributeDict["name"].asString();
|
||||||
if (_currentFirstGID == 0)
|
if (_currentFirstGID == 0)
|
||||||
{
|
{
|
||||||
tileset->_firstGid = (unsigned int)atoi(valueForKey("firstgid", attributeDict));
|
tileset->_firstGid = (unsigned int)attributeDict["firstgid"].asInt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tileset->_firstGid = _currentFirstGID;
|
tileset->_firstGid = _currentFirstGID;
|
||||||
_currentFirstGID = 0;
|
_currentFirstGID = 0;
|
||||||
}
|
}
|
||||||
tileset->_spacing = (unsigned int)atoi(valueForKey("spacing", attributeDict));
|
tileset->_spacing = (unsigned int)attributeDict["spacing"].asInt();
|
||||||
tileset->_margin = (unsigned int)atoi(valueForKey("margin", attributeDict));
|
tileset->_margin = (unsigned int)attributeDict["margin"].asInt();
|
||||||
Size s;
|
Size s;
|
||||||
s.width = (float)atof(valueForKey("tilewidth", attributeDict));
|
s.width = attributeDict["tilewidth"].asFloat();
|
||||||
s.height = (float)atof(valueForKey("tileheight", attributeDict));
|
s.height = attributeDict["tileheight"].asFloat();
|
||||||
tileset->_tileSize = s;
|
tileset->_tileSize = s;
|
||||||
|
|
||||||
pTMXMapInfo->getTilesets()->addObject(tileset);
|
pTMXMapInfo->getTilesets().pushBack(tileset);
|
||||||
tileset->release();
|
tileset->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,9 +297,9 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
{
|
{
|
||||||
if (pTMXMapInfo->getParentElement() == TMXPropertyLayer)
|
if (pTMXMapInfo->getParentElement() == TMXPropertyLayer)
|
||||||
{
|
{
|
||||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||||
Size layerSize = layer->_layerSize;
|
Size layerSize = layer->_layerSize;
|
||||||
unsigned int gid = (unsigned int)atoi(valueForKey("gid", attributeDict));
|
unsigned int gid = (unsigned int)attributeDict["gid"].asInt();
|
||||||
int tilesAmount = layerSize.width*layerSize.height;
|
int tilesAmount = layerSize.width*layerSize.height;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -367,44 +331,41 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TMXTilesetInfo* info = (TMXTilesetInfo*)pTMXMapInfo->getTilesets()->getLastObject();
|
TMXTilesetInfo* info = pTMXMapInfo->getTilesets().back();
|
||||||
Dictionary *dict = new Dictionary();
|
pTMXMapInfo->setParentGID(info->_firstGid + attributeDict["id"].asInt());
|
||||||
dict->init();
|
//FIXME:XXX Why insert an empty dict?
|
||||||
pTMXMapInfo->setParentGID(info->_firstGid + atoi(valueForKey("id", attributeDict)));
|
pTMXMapInfo->getTileProperties()[pTMXMapInfo->getParentGID()] = Value(ValueMap());
|
||||||
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
|
|
||||||
CC_SAFE_RELEASE(dict);
|
|
||||||
|
|
||||||
pTMXMapInfo->setParentElement(TMXPropertyTile);
|
pTMXMapInfo->setParentElement(TMXPropertyTile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (elementName == "layer")
|
else if (elementName == "layer")
|
||||||
{
|
{
|
||||||
TMXLayerInfo *layer = new TMXLayerInfo();
|
TMXLayerInfo *layer = new TMXLayerInfo();
|
||||||
layer->_name = valueForKey("name", attributeDict);
|
layer->_name = attributeDict["name"].asString();
|
||||||
|
|
||||||
Size s;
|
Size s;
|
||||||
s.width = (float)atof(valueForKey("width", attributeDict));
|
s.width = attributeDict["width"].asFloat();
|
||||||
s.height = (float)atof(valueForKey("height", attributeDict));
|
s.height = attributeDict["height"].asFloat();
|
||||||
layer->_layerSize = s;
|
layer->_layerSize = s;
|
||||||
|
|
||||||
std::string visible = valueForKey("visible", attributeDict);
|
layer->_visible = attributeDict["visible"].asBool();
|
||||||
layer->_visible = !(visible == "0");
|
|
||||||
|
|
||||||
std::string opacity = valueForKey("opacity", attributeDict);
|
Value& opacityValue = attributeDict["opacity"];
|
||||||
if( opacity != "" )
|
|
||||||
|
if( !opacityValue.isNull() )
|
||||||
{
|
{
|
||||||
layer->_opacity = (unsigned char)(255 * atof(opacity.c_str()));
|
layer->_opacity = (unsigned char)(255.0f * opacityValue.asFloat());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
layer->_opacity = 255;
|
layer->_opacity = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
float x = (float)atof(valueForKey("x", attributeDict));
|
float x = attributeDict["x"].asFloat();
|
||||||
float y = (float)atof(valueForKey("y", attributeDict));
|
float y = attributeDict["y"].asFloat();
|
||||||
layer->_offset = Point(x,y);
|
layer->_offset = Point(x,y);
|
||||||
|
|
||||||
pTMXMapInfo->getLayers()->addObject(layer);
|
pTMXMapInfo->getLayers().pushBack(layer);
|
||||||
layer->release();
|
layer->release();
|
||||||
|
|
||||||
// The parent element is now "layer"
|
// The parent element is now "layer"
|
||||||
|
@ -414,13 +375,13 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
else if (elementName == "objectgroup")
|
else if (elementName == "objectgroup")
|
||||||
{
|
{
|
||||||
TMXObjectGroup *objectGroup = new TMXObjectGroup();
|
TMXObjectGroup *objectGroup = new TMXObjectGroup();
|
||||||
objectGroup->setGroupName(valueForKey("name", attributeDict));
|
objectGroup->setGroupName(attributeDict["name"].asString());
|
||||||
Point positionOffset;
|
Point positionOffset;
|
||||||
positionOffset.x = (float)atof(valueForKey("x", attributeDict)) * pTMXMapInfo->getTileSize().width;
|
positionOffset.x = attributeDict["x"].asFloat() * pTMXMapInfo->getTileSize().width;
|
||||||
positionOffset.y = (float)atof(valueForKey("y", attributeDict)) * pTMXMapInfo->getTileSize().height;
|
positionOffset.y = attributeDict["y"].asFloat() * pTMXMapInfo->getTileSize().height;
|
||||||
objectGroup->setPositionOffset(positionOffset);
|
objectGroup->setPositionOffset(positionOffset);
|
||||||
|
|
||||||
pTMXMapInfo->getObjectGroups()->addObject(objectGroup);
|
pTMXMapInfo->getObjectGroups().pushBack(objectGroup);
|
||||||
objectGroup->release();
|
objectGroup->release();
|
||||||
|
|
||||||
// The parent element is now "objectgroup"
|
// The parent element is now "objectgroup"
|
||||||
|
@ -429,10 +390,10 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
}
|
}
|
||||||
else if (elementName == "image")
|
else if (elementName == "image")
|
||||||
{
|
{
|
||||||
TMXTilesetInfo* tileset = (TMXTilesetInfo*)pTMXMapInfo->getTilesets()->getLastObject();
|
TMXTilesetInfo* tileset = pTMXMapInfo->getTilesets().back();
|
||||||
|
|
||||||
// build full path
|
// build full path
|
||||||
std::string imagename = valueForKey("source", attributeDict);
|
std::string imagename = attributeDict["source"].asString();
|
||||||
|
|
||||||
if (_TMXFileName.find_last_of("/") != string::npos)
|
if (_TMXFileName.find_last_of("/") != string::npos)
|
||||||
{
|
{
|
||||||
|
@ -446,14 +407,14 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
}
|
}
|
||||||
else if (elementName == "data")
|
else if (elementName == "data")
|
||||||
{
|
{
|
||||||
std::string encoding = valueForKey("encoding", attributeDict);
|
std::string encoding = attributeDict["encoding"].asString();
|
||||||
std::string compression = valueForKey("compression", attributeDict);
|
std::string compression = attributeDict["compression"].asString();
|
||||||
|
|
||||||
if (encoding == "")
|
if (encoding == "")
|
||||||
{
|
{
|
||||||
pTMXMapInfo->setLayerAttribs(pTMXMapInfo->getLayerAttribs() | TMXLayerAttribNone);
|
pTMXMapInfo->setLayerAttribs(pTMXMapInfo->getLayerAttribs() | TMXLayerAttribNone);
|
||||||
|
|
||||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||||
Size layerSize = layer->_layerSize;
|
Size layerSize = layer->_layerSize;
|
||||||
int tilesAmount = layerSize.width*layerSize.height;
|
int tilesAmount = layerSize.width*layerSize.height;
|
||||||
|
|
||||||
|
@ -498,56 +459,36 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
}
|
}
|
||||||
else if (elementName == "object")
|
else if (elementName == "object")
|
||||||
{
|
{
|
||||||
char buffer[32] = {0};
|
TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().back();
|
||||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject();
|
|
||||||
|
|
||||||
// The value for "type" was blank or not a valid class name
|
// The value for "type" was blank or not a valid class name
|
||||||
// Create an instance of TMXObjectInfo to store the object and its properties
|
// Create an instance of TMXObjectInfo to store the object and its properties
|
||||||
Dictionary *dict = new Dictionary();
|
ValueMap dict;
|
||||||
dict->init();
|
|
||||||
// Parse everything automatically
|
// Parse everything automatically
|
||||||
const char* pArray[] = {"name", "type", "width", "height", "gid"};
|
const char* pArray[] = {"name", "type", "width", "height", "gid"};
|
||||||
|
|
||||||
for(size_t i = 0; i < sizeof(pArray)/sizeof(pArray[0]); ++i )
|
for(size_t i = 0; i < sizeof(pArray)/sizeof(pArray[0]); ++i )
|
||||||
{
|
{
|
||||||
const char* key = pArray[i];
|
const char* key = pArray[i];
|
||||||
String* obj = new String(valueForKey(key, attributeDict));
|
Value value = attributeDict[key];
|
||||||
if( obj )
|
dict[key] = value;
|
||||||
{
|
|
||||||
obj->autorelease();
|
|
||||||
dict->setObject(obj, key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// But X and Y since they need special treatment
|
// But X and Y since they need special treatment
|
||||||
// X
|
// X
|
||||||
|
|
||||||
const char* value = valueForKey("x", attributeDict);
|
int x = attributeDict["x"].asInt() + (int)objectGroup->getPositionOffset().x;
|
||||||
if (value)
|
dict["x"] = Value(x);
|
||||||
{
|
|
||||||
int x = atoi(value) + (int)objectGroup->getPositionOffset().x;
|
|
||||||
sprintf(buffer, "%d", x);
|
|
||||||
String* pStr = new String(buffer);
|
|
||||||
pStr->autorelease();
|
|
||||||
dict->setObject(pStr, "x");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Y
|
// Y
|
||||||
value = valueForKey("y", attributeDict);
|
int y = attributeDict["y"].asInt() + (int)objectGroup->getPositionOffset().y;
|
||||||
if (value) {
|
|
||||||
int y = atoi(value) + (int)objectGroup->getPositionOffset().y;
|
|
||||||
|
|
||||||
// Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
|
// Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
|
||||||
y = (int)(_mapSize.height * _tileSize.height) - y - atoi(valueForKey("height", attributeDict));
|
y = (int)(_mapSize.height * _tileSize.height) - y - attributeDict["height"].asInt();
|
||||||
sprintf(buffer, "%d", y);
|
dict["y"] = Value(y);
|
||||||
String* pStr = new String(buffer);
|
|
||||||
pStr->autorelease();
|
|
||||||
dict->setObject(pStr, "y");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the object to the objectGroup
|
// Add the object to the objectGroup
|
||||||
objectGroup->getObjects()->addObject(dict);
|
objectGroup->getObjects().push_back(Value(dict));
|
||||||
dict->release();
|
|
||||||
|
|
||||||
// The parent element is now "object"
|
// The parent element is now "object"
|
||||||
pTMXMapInfo->setParentElement(TMXPropertyObject);
|
pTMXMapInfo->setParentElement(TMXPropertyObject);
|
||||||
|
@ -558,70 +499,61 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
if ( pTMXMapInfo->getParentElement() == TMXPropertyNone )
|
if ( pTMXMapInfo->getParentElement() == TMXPropertyNone )
|
||||||
{
|
{
|
||||||
CCLOG( "TMX tile map: Parent element is unsupported. Cannot add property named '%s' with value '%s'",
|
CCLOG( "TMX tile map: Parent element is unsupported. Cannot add property named '%s' with value '%s'",
|
||||||
valueForKey("name", attributeDict), valueForKey("value",attributeDict) );
|
attributeDict["name"].asString().c_str(), attributeDict["value"].asString().c_str() );
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyMap )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyMap )
|
||||||
{
|
{
|
||||||
// The parent element is the map
|
// The parent element is the map
|
||||||
String *value = new String(valueForKey("value", attributeDict));
|
Value value = attributeDict["value"];
|
||||||
std::string key = valueForKey("name", attributeDict);
|
std::string key = attributeDict["name"].asString();
|
||||||
pTMXMapInfo->getProperties()->setObject(value, key.c_str());
|
pTMXMapInfo->getProperties().insert(std::make_pair(key, value));
|
||||||
value->release();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
||||||
{
|
{
|
||||||
// The parent element is the last layer
|
// The parent element is the last layer
|
||||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||||
String *value = new String(valueForKey("value", attributeDict));
|
Value value = attributeDict["value"];
|
||||||
std::string key = valueForKey("name", attributeDict);
|
std::string key = attributeDict["name"].asString();
|
||||||
// Add the property to the layer
|
// Add the property to the layer
|
||||||
layer->getProperties()->setObject(value, key.c_str());
|
layer->getProperties().insert(std::make_pair(key, value));
|
||||||
value->release();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
||||||
{
|
{
|
||||||
// The parent element is the last object group
|
// The parent element is the last object group
|
||||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject();
|
TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().back();
|
||||||
String *value = new String(valueForKey("value", attributeDict));
|
Value value = attributeDict["value"];
|
||||||
const char* key = valueForKey("name", attributeDict);
|
std::string key = attributeDict["name"].asString();
|
||||||
objectGroup->getProperties()->setObject(value, key);
|
objectGroup->getProperties().insert(std::make_pair(key, value));
|
||||||
value->release();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
||||||
{
|
{
|
||||||
// The parent element is the last object
|
// The parent element is the last object
|
||||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject();
|
TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().back();
|
||||||
Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject();
|
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
||||||
|
|
||||||
const char* propertyName = valueForKey("name", attributeDict);
|
std::string propertyName = attributeDict["name"].asString();
|
||||||
String *propertyValue = new String(valueForKey("value", attributeDict));
|
dict[propertyName] = attributeDict["value"];
|
||||||
dict->setObject(propertyValue, propertyName);
|
|
||||||
propertyValue->release();
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile )
|
||||||
{
|
{
|
||||||
Dictionary* dict = (Dictionary*)pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID());
|
IntValueMap& dict = pTMXMapInfo->getTileProperties().at(pTMXMapInfo->getParentGID()).asIntKeyMap();
|
||||||
|
|
||||||
const char* propertyName = valueForKey("name", attributeDict);
|
int propertyName = attributeDict["name"].asInt();
|
||||||
String *propertyValue = new String(valueForKey("value", attributeDict));
|
dict[propertyName] = attributeDict["value"];
|
||||||
dict->setObject(propertyValue, propertyName);
|
|
||||||
propertyValue->release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (elementName == "polygon")
|
else if (elementName == "polygon")
|
||||||
{
|
{
|
||||||
// find parent object's dict and add polygon-points to it
|
// find parent object's dict and add polygon-points to it
|
||||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->getLastObject();
|
TMXObjectGroup* objectGroup = _objectGroups.back();
|
||||||
Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject();
|
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
||||||
|
|
||||||
// get points value string
|
// get points value string
|
||||||
const char* value = valueForKey("points", attributeDict);
|
std::string value = attributeDict["points"].asString();
|
||||||
if(value)
|
if (!value.empty())
|
||||||
{
|
{
|
||||||
Array* pointsArray = Array::createWithCapacity(10);
|
ValueVector pointsArray;
|
||||||
|
pointsArray.reserve(10);
|
||||||
|
|
||||||
// parse points string into a space-separated set of points
|
// parse points string into a space-separated set of points
|
||||||
stringstream pointsStream(value);
|
stringstream pointsStream(value);
|
||||||
|
@ -631,50 +563,42 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
// parse each point combo into a comma-separated x,y point
|
// parse each point combo into a comma-separated x,y point
|
||||||
stringstream pointStream(pointPair);
|
stringstream pointStream(pointPair);
|
||||||
string xStr,yStr;
|
string xStr,yStr;
|
||||||
char buffer[32] = {0};
|
|
||||||
|
|
||||||
Dictionary* pointDict = new Dictionary;
|
ValueMap pointDict;
|
||||||
pointDict->init();
|
|
||||||
|
|
||||||
// set x
|
// set x
|
||||||
if(std::getline(pointStream, xStr, ','))
|
if(std::getline(pointStream, xStr, ','))
|
||||||
{
|
{
|
||||||
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||||
sprintf(buffer, "%d", x);
|
pointDict["x"] = Value(x);
|
||||||
String* pStr = new String(buffer);
|
|
||||||
pStr->autorelease();
|
|
||||||
pointDict->setObject(pStr, "x");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set y
|
// set y
|
||||||
if(std::getline(pointStream, yStr, ','))
|
if(std::getline(pointStream, yStr, ','))
|
||||||
{
|
{
|
||||||
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||||
sprintf(buffer, "%d", y);
|
pointDict["y"] = Value(y);
|
||||||
String* pStr = new String(buffer);
|
|
||||||
pStr->autorelease();
|
|
||||||
pointDict->setObject(pStr, "y");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to points array
|
// add to points array
|
||||||
pointsArray->addObject(pointDict);
|
pointsArray.push_back(Value(pointDict));
|
||||||
pointDict->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dict->setObject(pointsArray, "points");
|
dict["points"] = Value(pointsArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (elementName == "polyline")
|
else if (elementName == "polyline")
|
||||||
{
|
{
|
||||||
// find parent object's dict and add polyline-points to it
|
// find parent object's dict and add polyline-points to it
|
||||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->getLastObject();
|
TMXObjectGroup* objectGroup = _objectGroups.back();
|
||||||
Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject();
|
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
||||||
|
|
||||||
// get points value string
|
// get points value string
|
||||||
const char* value = valueForKey("points", attributeDict);
|
std::string value = attributeDict["points"].asString();
|
||||||
if(value)
|
if (!value.empty())
|
||||||
{
|
{
|
||||||
Array* pointsArray = Array::createWithCapacity(10);
|
ValueVector pointsArray;
|
||||||
|
pointsArray.reserve(10);
|
||||||
|
|
||||||
// parse points string into a space-separated set of points
|
// parse points string into a space-separated set of points
|
||||||
stringstream pointsStream(value);
|
stringstream pointsStream(value);
|
||||||
|
@ -684,45 +608,30 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
// parse each point combo into a comma-separated x,y point
|
// parse each point combo into a comma-separated x,y point
|
||||||
stringstream pointStream(pointPair);
|
stringstream pointStream(pointPair);
|
||||||
string xStr,yStr;
|
string xStr,yStr;
|
||||||
char buffer[32] = {0};
|
|
||||||
|
|
||||||
Dictionary* pointDict = new Dictionary;
|
ValueMap pointDict;
|
||||||
pointDict->init();
|
|
||||||
|
|
||||||
// set x
|
// set x
|
||||||
if(std::getline(pointStream, xStr, ','))
|
if(std::getline(pointStream, xStr, ','))
|
||||||
{
|
{
|
||||||
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||||
sprintf(buffer, "%d", x);
|
pointDict["x"] = Value(x);
|
||||||
String* pStr = new String(buffer);
|
|
||||||
pStr->autorelease();
|
|
||||||
pointDict->setObject(pStr, "x");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set y
|
// set y
|
||||||
if(std::getline(pointStream, yStr, ','))
|
if(std::getline(pointStream, yStr, ','))
|
||||||
{
|
{
|
||||||
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||||
sprintf(buffer, "%d", y);
|
pointDict["y"] = Value(y);
|
||||||
String* pStr = new String(buffer);
|
|
||||||
pStr->autorelease();
|
|
||||||
pointDict->setObject(pStr, "y");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to points array
|
// add to points array
|
||||||
pointsArray->addObject(pointDict);
|
pointsArray.push_back(Value(pointDict));
|
||||||
pointDict->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dict->setObject(pointsArray, "polylinePoints");
|
dict["polylinePoints"] = Value(pointsArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributeDict)
|
|
||||||
{
|
|
||||||
attributeDict->clear();
|
|
||||||
delete attributeDict;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TMXMapInfo::endElement(void *ctx, const char *name)
|
void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
|
@ -739,7 +648,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
{
|
{
|
||||||
pTMXMapInfo->setStoringCharacters(false);
|
pTMXMapInfo->setStoringCharacters(false);
|
||||||
|
|
||||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||||
|
|
||||||
std::string currentString = pTMXMapInfo->getCurrentString();
|
std::string currentString = pTMXMapInfo->getCurrentString();
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
|
@ -752,18 +661,16 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
|
|
||||||
if( pTMXMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib) )
|
if( pTMXMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib) )
|
||||||
{
|
{
|
||||||
unsigned char *deflated;
|
unsigned char *deflated = nullptr;
|
||||||
Size s = layer->_layerSize;
|
Size s = layer->_layerSize;
|
||||||
// int sizeHint = s.width * s.height * sizeof(uint32_t);
|
// int sizeHint = s.width * s.height * sizeof(uint32_t);
|
||||||
int sizeHint = (int)(s.width * s.height * sizeof(unsigned int));
|
ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);
|
||||||
|
|
||||||
int inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
|
ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
|
||||||
CCASSERT(inflatedLen == sizeHint, "");
|
CCASSERT(inflatedLen == sizeHint, "");
|
||||||
|
|
||||||
inflatedLen = (size_t)&inflatedLen; // XXX: to avoid warnings in compiler
|
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = nullptr;
|
||||||
|
|
||||||
if( ! deflated )
|
if( ! deflated )
|
||||||
{
|
{
|
||||||
|
@ -782,7 +689,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
}
|
}
|
||||||
else if (pTMXMapInfo->getLayerAttribs() & TMXLayerAttribNone)
|
else if (pTMXMapInfo->getLayerAttribs() & TMXLayerAttribNone)
|
||||||
{
|
{
|
||||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||||
Size layerSize = layer->_layerSize;
|
Size layerSize = layer->_layerSize;
|
||||||
int tilesAmount = layerSize.width * layerSize.height;
|
int tilesAmount = layerSize.width * layerSize.height;
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,17 @@ THE SOFTWARE.
|
||||||
#define __CC_TM_XML_PARSER__
|
#define __CC_TM_XML_PARSER__
|
||||||
|
|
||||||
#include "CCArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCDictionary.h"
|
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "platform/CCSAXParser.h"
|
#include "platform/CCSAXParser.h"
|
||||||
|
#include "CCVector.h"
|
||||||
|
#include "CCValue.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class TMXLayerInfo;
|
||||||
class TMXObjectGroup;
|
class TMXObjectGroup;
|
||||||
|
class TMXTilesetInfo;
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
* Internal TMX parser
|
* Internal TMX parser
|
||||||
|
@ -99,10 +101,10 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ~TMXLayerInfo();
|
virtual ~TMXLayerInfo();
|
||||||
|
|
||||||
void setProperties(Dictionary *properties);
|
void setProperties(ValueMap properties);
|
||||||
Dictionary* getProperties();
|
ValueMap getProperties();
|
||||||
|
|
||||||
Dictionary *_properties;
|
ValueMap _properties;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
Size _layerSize;
|
Size _layerSize;
|
||||||
unsigned int *_tiles;
|
unsigned int *_tiles;
|
||||||
|
@ -193,10 +195,8 @@ public:
|
||||||
/* initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */
|
/* initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */
|
||||||
bool parseXMLString(const std::string& xmlString);
|
bool parseXMLString(const std::string& xmlString);
|
||||||
|
|
||||||
Dictionary* getTileProperties() { return _tileProperties; };
|
IntValueMap& getTileProperties() { return _tileProperties; };
|
||||||
void setTileProperties(Dictionary* tileProperties) {
|
void setTileProperties(const IntValueMap& tileProperties) {
|
||||||
CC_SAFE_RETAIN(tileProperties);
|
|
||||||
CC_SAFE_RELEASE(_tileProperties);
|
|
||||||
_tileProperties = tileProperties;
|
_tileProperties = tileProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -213,26 +213,23 @@ public:
|
||||||
inline void setTileSize(const Size& tileSize) { _tileSize = tileSize; };
|
inline void setTileSize(const Size& tileSize) { _tileSize = tileSize; };
|
||||||
|
|
||||||
/// Layers
|
/// Layers
|
||||||
inline Array* getLayers() const { return _layers; };
|
inline const Vector<TMXLayerInfo*>& getLayers() const { return _layers; };
|
||||||
inline void setLayers(Array* layers) {
|
inline Vector<TMXLayerInfo*>& getLayers() { return _layers; };
|
||||||
CC_SAFE_RETAIN(layers);
|
inline void setLayers(const Vector<TMXLayerInfo*>& layers) {
|
||||||
CC_SAFE_RELEASE(_layers);
|
|
||||||
_layers = layers;
|
_layers = layers;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// tilesets
|
/// tilesets
|
||||||
inline Array* getTilesets() const { return _tilesets; };
|
inline const Vector<TMXTilesetInfo*>& getTilesets() const { return _tilesets; };
|
||||||
inline void setTilesets(Array* tilesets) {
|
inline Vector<TMXTilesetInfo*>& getTilesets() { return _tilesets; };
|
||||||
CC_SAFE_RETAIN(tilesets);
|
inline void setTilesets(const Vector<TMXTilesetInfo*>& tilesets) {
|
||||||
CC_SAFE_RELEASE(_tilesets);
|
|
||||||
_tilesets = tilesets;
|
_tilesets = tilesets;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// ObjectGroups
|
/// ObjectGroups
|
||||||
inline Array* getObjectGroups() const { return _objectGroups; };
|
inline const Vector<TMXObjectGroup*>& getObjectGroups() const { return _objectGroups; };
|
||||||
inline void setObjectGroups(Array* groups) {
|
inline Vector<TMXObjectGroup*>& getObjectGroups() { return _objectGroups; };
|
||||||
CC_SAFE_RETAIN(groups);
|
inline void setObjectGroups(const Vector<TMXObjectGroup*>& groups) {
|
||||||
CC_SAFE_RELEASE(_objectGroups);
|
|
||||||
_objectGroups = groups;
|
_objectGroups = groups;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -254,10 +251,8 @@ public:
|
||||||
inline void setStoringCharacters(bool storingCharacters) { _storingCharacters = storingCharacters; };
|
inline void setStoringCharacters(bool storingCharacters) { _storingCharacters = storingCharacters; };
|
||||||
|
|
||||||
/// properties
|
/// properties
|
||||||
inline Dictionary* getProperties() const { return _properties; };
|
inline ValueMap getProperties() const { return _properties; };
|
||||||
inline void setProperties(Dictionary* properties) {
|
inline void setProperties(ValueMap properties) {
|
||||||
CC_SAFE_RETAIN(properties);
|
|
||||||
CC_SAFE_RELEASE(_properties);
|
|
||||||
_properties = properties;
|
_properties = properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -293,11 +288,11 @@ protected:
|
||||||
/// tiles width & height
|
/// tiles width & height
|
||||||
Size _tileSize;
|
Size _tileSize;
|
||||||
/// Layers
|
/// Layers
|
||||||
Array* _layers;
|
Vector<TMXLayerInfo*> _layers;
|
||||||
/// tilesets
|
/// tilesets
|
||||||
Array* _tilesets;
|
Vector<TMXTilesetInfo*> _tilesets;
|
||||||
/// ObjectGroups
|
/// ObjectGroups
|
||||||
Array* _objectGroups;
|
Vector<TMXObjectGroup*> _objectGroups;
|
||||||
/// parent element
|
/// parent element
|
||||||
int _parentElement;
|
int _parentElement;
|
||||||
/// parent GID
|
/// parent GID
|
||||||
|
@ -307,7 +302,7 @@ protected:
|
||||||
/// is storing characters?
|
/// is storing characters?
|
||||||
bool _storingCharacters;
|
bool _storingCharacters;
|
||||||
/// properties
|
/// properties
|
||||||
Dictionary* _properties;
|
ValueMap _properties;
|
||||||
|
|
||||||
//! tmx filename
|
//! tmx filename
|
||||||
std::string _TMXFileName;
|
std::string _TMXFileName;
|
||||||
|
@ -316,7 +311,7 @@ protected:
|
||||||
//! current string
|
//! current string
|
||||||
std::string _currentString;
|
std::string _currentString;
|
||||||
//! tile properties
|
//! tile properties
|
||||||
Dictionary* _tileProperties;
|
IntValueMap _tileProperties;
|
||||||
unsigned int _currentFirstGID;
|
unsigned int _currentFirstGID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ void TextFieldTTF::insertText(const char * text, int len)
|
||||||
std::string sInsert(text, len);
|
std::string sInsert(text, len);
|
||||||
|
|
||||||
// insert \n means input end
|
// insert \n means input end
|
||||||
int nPos = sInsert.find('\n');
|
int nPos = static_cast<int>(sInsert.find('\n'));
|
||||||
if ((int)sInsert.npos != nPos)
|
if ((int)sInsert.npos != nPos)
|
||||||
{
|
{
|
||||||
len = nPos;
|
len = nPos;
|
||||||
|
@ -201,7 +201,7 @@ void TextFieldTTF::insertText(const char * text, int len)
|
||||||
|
|
||||||
void TextFieldTTF::deleteBackward()
|
void TextFieldTTF::deleteBackward()
|
||||||
{
|
{
|
||||||
int nStrLen = _inputText.length();
|
size_t nStrLen = _inputText.length();
|
||||||
if (! nStrLen)
|
if (! nStrLen)
|
||||||
{
|
{
|
||||||
// there is no string
|
// there is no string
|
||||||
|
@ -279,7 +279,7 @@ void TextFieldTTF::setString(const std::string &text)
|
||||||
{
|
{
|
||||||
static char bulletString[] = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00};
|
static char bulletString[] = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00};
|
||||||
std::string displayText;
|
std::string displayText;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
if (text.length()>0)
|
if (text.length()>0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,7 +49,7 @@ TextPageDef::TextPageDef(int pageNum, int width, int height): _pageNum(pageNum
|
||||||
|
|
||||||
TextPageDef::~TextPageDef()
|
TextPageDef::~TextPageDef()
|
||||||
{
|
{
|
||||||
int numLines = _lines.size();
|
size_t numLines = _lines.size();
|
||||||
|
|
||||||
for( int c = 0; c<numLines; ++c )
|
for( int c = 0; c<numLines; ++c )
|
||||||
{
|
{
|
||||||
|
@ -122,8 +122,8 @@ TextFontPagesDef::TextFontPagesDef()
|
||||||
|
|
||||||
TextFontPagesDef::~TextFontPagesDef()
|
TextFontPagesDef::~TextFontPagesDef()
|
||||||
{
|
{
|
||||||
int numPages = _pages.size();
|
size_t numPages = _pages.size();
|
||||||
for( int c = 0; c < numPages; ++c )
|
for( size_t c = 0; c < numPages; ++c )
|
||||||
{
|
{
|
||||||
if (_pages[c])
|
if (_pages[c])
|
||||||
delete _pages[c];
|
delete _pages[c];
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
float getHeight() const { return _height; }
|
float getHeight() const { return _height; }
|
||||||
|
|
||||||
void addGlyph(GlyphDef theGlyph) { _glyphs.push_back(theGlyph); }
|
void addGlyph(GlyphDef theGlyph) { _glyphs.push_back(theGlyph); }
|
||||||
int getNumGlyph() const { return _glyphs.size(); }
|
int getNumGlyph() const { return static_cast<int>(_glyphs.size()); }
|
||||||
const GlyphDef & getGlyphAt(int index) const { return _glyphs[index]; }
|
const GlyphDef & getGlyphAt(int index) const { return _glyphs[index]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -115,7 +115,7 @@ public:
|
||||||
~TextPageDef();
|
~TextPageDef();
|
||||||
|
|
||||||
void addLine(TextLineDef *theLine) { _lines.push_back(theLine); }
|
void addLine(TextLineDef *theLine) { _lines.push_back(theLine); }
|
||||||
int getNumLines() const { return _lines.size(); }
|
int getNumLines() const { return static_cast<int>(_lines.size()); }
|
||||||
TextLineDef * getLineAt(int index) const { return _lines[index]; }
|
TextLineDef * getLineAt(int index) const { return _lines[index]; }
|
||||||
int getWidth() const { return _width; }
|
int getWidth() const { return _width; }
|
||||||
int getHeight() const { return _height; }
|
int getHeight() const { return _height; }
|
||||||
|
@ -156,7 +156,7 @@ public:
|
||||||
~TextFontPagesDef();
|
~TextFontPagesDef();
|
||||||
|
|
||||||
void addPage(TextPageDef *newPage) { _pages.push_back(newPage); }
|
void addPage(TextPageDef *newPage) { _pages.push_back(newPage); }
|
||||||
int getNumPages() const { return _pages.size(); }
|
int getNumPages() const { return static_cast<int>(_pages.size()); }
|
||||||
TextPageDef* getPageAt(int index) const { return _pages[index]; }
|
TextPageDef* getPageAt(int index) const { return _pages[index]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -119,9 +119,9 @@ static bool _PVRHaveAlphaPremultiplied = false;
|
||||||
//conventer function
|
//conventer function
|
||||||
|
|
||||||
// IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBB
|
// IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBB
|
||||||
void Texture2D::convertI8ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertI8ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i=0; i < dataLen; ++i)
|
for (ssize_t i=0; i < dataLen; ++i)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //R
|
*outData++ = data[i]; //R
|
||||||
*outData++ = data[i]; //G
|
*outData++ = data[i]; //G
|
||||||
|
@ -130,9 +130,9 @@ void Texture2D::convertI8ToRGB888(const unsigned char* data, long dataLen, unsig
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB
|
// IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB
|
||||||
void Texture2D::convertAI88ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertAI88ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 1; i < l; i += 2)
|
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //R
|
*outData++ = data[i]; //R
|
||||||
*outData++ = data[i]; //G
|
*outData++ = data[i]; //G
|
||||||
|
@ -141,9 +141,9 @@ void Texture2D::convertAI88ToRGB888(const unsigned char* data, long dataLen, uns
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBBAAAAAAAA
|
// IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBBAAAAAAAA
|
||||||
void Texture2D::convertI8ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertI8ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < dataLen; ++i)
|
for (ssize_t i = 0; i < dataLen; ++i)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //R
|
*outData++ = data[i]; //R
|
||||||
*outData++ = data[i]; //G
|
*outData++ = data[i]; //G
|
||||||
|
@ -153,9 +153,9 @@ void Texture2D::convertI8ToRGBA8888(const unsigned char* data, long dataLen, uns
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA
|
// IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA
|
||||||
void Texture2D::convertAI88ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertAI88ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 1; i < l; i += 2)
|
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //R
|
*outData++ = data[i]; //R
|
||||||
*outData++ = data[i]; //G
|
*outData++ = data[i]; //G
|
||||||
|
@ -165,7 +165,7 @@ void Texture2D::convertAI88ToRGBA8888(const unsigned char* data, long dataLen, u
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIII -> RRRRRGGGGGGBBBBB
|
// IIIIIIII -> RRRRRGGGGGGBBBBB
|
||||||
void Texture2D::convertI8ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertI8ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0; i < dataLen; ++i)
|
for (int i = 0; i < dataLen; ++i)
|
||||||
|
@ -177,10 +177,10 @@ void Texture2D::convertI8ToRGB565(const unsigned char* data, long dataLen, unsig
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIIIAAAAAAAA -> RRRRRGGGGGGBBBBB
|
// IIIIIIIIAAAAAAAA -> RRRRRGGGGGGBBBBB
|
||||||
void Texture2D::convertAI88ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertAI88ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0, l = dataLen - 1; i < l; i += 2)
|
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F8) << 8 //R
|
*out16++ = (data[i] & 0x00F8) << 8 //R
|
||||||
| (data[i] & 0x00FC) << 3 //G
|
| (data[i] & 0x00FC) << 3 //G
|
||||||
|
@ -189,10 +189,10 @@ void Texture2D::convertAI88ToRGB565(const unsigned char* data, long dataLen, uns
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIII -> RRRRGGGGBBBBAAAA
|
// IIIIIIII -> RRRRGGGGBBBBAAAA
|
||||||
void Texture2D::convertI8ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertI8ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0; i < dataLen; ++i)
|
for (ssize_t i = 0; i < dataLen; ++i)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F0) << 8 //R
|
*out16++ = (data[i] & 0x00F0) << 8 //R
|
||||||
| (data[i] & 0x00F0) << 4 //G
|
| (data[i] & 0x00F0) << 4 //G
|
||||||
|
@ -202,10 +202,10 @@ void Texture2D::convertI8ToRGBA4444(const unsigned char* data, long dataLen, uns
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIIIAAAAAAAA -> RRRRGGGGBBBBAAAA
|
// IIIIIIIIAAAAAAAA -> RRRRGGGGBBBBAAAA
|
||||||
void Texture2D::convertAI88ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertAI88ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0, l = dataLen - 1; i < l; i += 2)
|
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F0) << 8 //R
|
*out16++ = (data[i] & 0x00F0) << 8 //R
|
||||||
| (data[i] & 0x00F0) << 4 //G
|
| (data[i] & 0x00F0) << 4 //G
|
||||||
|
@ -215,7 +215,7 @@ void Texture2D::convertAI88ToRGBA4444(const unsigned char* data, long dataLen, u
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIII -> RRRRRGGGGGBBBBBA
|
// IIIIIIII -> RRRRRGGGGGBBBBBA
|
||||||
void Texture2D::convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertI8ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0; i < dataLen; ++i)
|
for (int i = 0; i < dataLen; ++i)
|
||||||
|
@ -228,10 +228,10 @@ void Texture2D::convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsig
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIIIAAAAAAAA -> RRRRRGGGGGBBBBBA
|
// IIIIIIIIAAAAAAAA -> RRRRRGGGGGBBBBBA
|
||||||
void Texture2D::convertAI88ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertAI88ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0, l = dataLen - 1; i < l; i += 2)
|
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F8) << 8 //R
|
*out16++ = (data[i] & 0x00F8) << 8 //R
|
||||||
| (data[i] & 0x00F8) << 3 //G
|
| (data[i] & 0x00F8) << 3 //G
|
||||||
|
@ -241,10 +241,10 @@ void Texture2D::convertAI88ToRGB5A1(const unsigned char* data, long dataLen, uns
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIII -> IIIIIIIIAAAAAAAA
|
// IIIIIIII -> IIIIIIIIAAAAAAAA
|
||||||
void Texture2D::convertI8ToAI88(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertI8ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0; i < dataLen; ++i)
|
for (ssize_t i = 0; i < dataLen; ++i)
|
||||||
{
|
{
|
||||||
*out16++ = 0xFF00 //A
|
*out16++ = 0xFF00 //A
|
||||||
| data[i]; //I
|
| data[i]; //I
|
||||||
|
@ -252,27 +252,27 @@ void Texture2D::convertI8ToAI88(const unsigned char* data, long dataLen, unsigne
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIIIAAAAAAAA -> AAAAAAAA
|
// IIIIIIIIAAAAAAAA -> AAAAAAAA
|
||||||
void Texture2D::convertAI88ToA8(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertAI88ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < dataLen; i += 2)
|
for (ssize_t i = 1; i < dataLen; i += 2)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //A
|
*outData++ = data[i]; //A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IIIIIIIIAAAAAAAA -> IIIIIIII
|
// IIIIIIIIAAAAAAAA -> IIIIIIII
|
||||||
void Texture2D::convertAI88ToI8(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertAI88ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 1; i < l; i += 2)
|
for (ssize_t i = 0, l = dataLen - 1; i < l; i += 2)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //R
|
*outData++ = data[i]; //R
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA
|
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA
|
||||||
void Texture2D::convertRGB888ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGB888ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 2; i < l; i += 3)
|
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //R
|
*outData++ = data[i]; //R
|
||||||
*outData++ = data[i + 1]; //G
|
*outData++ = data[i + 1]; //G
|
||||||
|
@ -282,9 +282,9 @@ void Texture2D::convertRGB888ToRGBA8888(const unsigned char* data, long dataLen,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB
|
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB
|
||||||
void Texture2D::convertRGBA8888ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGBA8888ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 3; i < l; i += 4)
|
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
|
||||||
{
|
{
|
||||||
*outData++ = data[i]; //R
|
*outData++ = data[i]; //R
|
||||||
*outData++ = data[i + 1]; //G
|
*outData++ = data[i + 1]; //G
|
||||||
|
@ -293,10 +293,10 @@ void Texture2D::convertRGBA8888ToRGB888(const unsigned char* data, long dataLen,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGGBBBBB
|
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGGBBBBB
|
||||||
void Texture2D::convertRGB888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGB888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0, l = dataLen - 2; i < l; i += 3)
|
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F8) << 8 //R
|
*out16++ = (data[i] & 0x00F8) << 8 //R
|
||||||
| (data[i + 1] & 0x00FC) << 3 //G
|
| (data[i + 1] & 0x00FC) << 3 //G
|
||||||
|
@ -305,10 +305,10 @@ void Texture2D::convertRGB888ToRGB565(const unsigned char* data, long dataLen, u
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRGGGGGGBBBBB
|
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRGGGGGGBBBBB
|
||||||
void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0, l = dataLen - 3; i < l; i += 4)
|
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F8) << 8 //R
|
*out16++ = (data[i] & 0x00F8) << 8 //R
|
||||||
| (data[i + 1] & 0x00FC) << 3 //G
|
| (data[i + 1] & 0x00FC) << 3 //G
|
||||||
|
@ -317,36 +317,36 @@ void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, long dataLen,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIII
|
// RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIII
|
||||||
void Texture2D::convertRGB888ToI8(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 2; i < l; i += 3)
|
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
|
||||||
{
|
{
|
||||||
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIII
|
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIII
|
||||||
void Texture2D::convertRGBA8888ToI8(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGBA8888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 3; i < l; i += 4)
|
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
|
||||||
{
|
{
|
||||||
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> AAAAAAAA
|
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> AAAAAAAA
|
||||||
void Texture2D::convertRGBA8888ToA8(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGBA8888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen -3; i < l; i += 4)
|
for (ssize_t i = 0, l = dataLen -3; i < l; i += 4)
|
||||||
{
|
{
|
||||||
*outData++ = data[i + 3]; //A
|
*outData++ = data[i + 3]; //A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIIIAAAAAAAA
|
// RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIIIAAAAAAAA
|
||||||
void Texture2D::convertRGB888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGB888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 2; i < l; i += 3)
|
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
|
||||||
{
|
{
|
||||||
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
||||||
*outData++ = 0xFF;
|
*outData++ = 0xFF;
|
||||||
|
@ -355,9 +355,9 @@ void Texture2D::convertRGB888ToAI88(const unsigned char* data, long dataLen, uns
|
||||||
|
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIIIAAAAAAAA
|
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIIIAAAAAAAA
|
||||||
void Texture2D::convertRGBA8888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGBA8888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
for (int i = 0, l = dataLen - 3; i < l; i += 4)
|
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
|
||||||
{
|
{
|
||||||
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
*outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000
|
||||||
*outData++ = data[i + 3];
|
*outData++ = data[i + 3];
|
||||||
|
@ -365,10 +365,10 @@ void Texture2D::convertRGBA8888ToAI88(const unsigned char* data, long dataLen, u
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRGGGGBBBBAAAA
|
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRGGGGBBBBAAAA
|
||||||
void Texture2D::convertRGB888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGB888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0, l = dataLen - 2; i < l; i += 3)
|
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
|
||||||
{
|
{
|
||||||
*out16++ = ((data[i] & 0x00F0) << 8 //R
|
*out16++ = ((data[i] & 0x00F0) << 8 //R
|
||||||
| (data[i + 1] & 0x00F0) << 4 //G
|
| (data[i + 1] & 0x00F0) << 4 //G
|
||||||
|
@ -378,10 +378,10 @@ void Texture2D::convertRGB888ToRGBA4444(const unsigned char* data, long dataLen,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRGGGGBBBBAAAA
|
// RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRGGGGBBBBAAAA
|
||||||
void Texture2D::convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGBA8888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (int i = 0, l = dataLen - 3; i < l; i += 4)
|
for (ssize_t i = 0, l = dataLen - 3; i < l; i += 4)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F0) << 8 //R
|
*out16++ = (data[i] & 0x00F0) << 8 //R
|
||||||
| (data[i + 1] & 0x00F0) << 4 //G
|
| (data[i + 1] & 0x00F0) << 4 //G
|
||||||
|
@ -391,10 +391,10 @@ void Texture2D::convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLe
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA
|
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA
|
||||||
void Texture2D::convertRGB888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGB888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (long i = 0, l = dataLen - 2; i < l; i += 3)
|
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 3)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F8) << 8 //R
|
*out16++ = (data[i] & 0x00F8) << 8 //R
|
||||||
| (data[i + 1] & 0x00F8) << 3 //G
|
| (data[i + 1] & 0x00F8) << 3 //G
|
||||||
|
@ -404,10 +404,10 @@ void Texture2D::convertRGB888ToRGB5A1(const unsigned char* data, long dataLen, u
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA
|
// RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA
|
||||||
void Texture2D::convertRGBA8888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData)
|
void Texture2D::convertRGBA8888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData)
|
||||||
{
|
{
|
||||||
unsigned short* out16 = (unsigned short*)outData;
|
unsigned short* out16 = (unsigned short*)outData;
|
||||||
for (long i = 0, l = dataLen - 2; i < l; i += 4)
|
for (ssize_t i = 0, l = dataLen - 2; i < l; i += 4)
|
||||||
{
|
{
|
||||||
*out16++ = (data[i] & 0x00F8) << 8 //R
|
*out16++ = (data[i] & 0x00F8) << 8 //R
|
||||||
| (data[i + 1] & 0x00F8) << 3 //G
|
| (data[i + 1] & 0x00F8) << 3 //G
|
||||||
|
@ -451,12 +451,12 @@ Texture2D::PixelFormat Texture2D::getPixelFormat() const
|
||||||
return _pixelFormat;
|
return _pixelFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
long Texture2D::getPixelsWide() const
|
int Texture2D::getPixelsWide() const
|
||||||
{
|
{
|
||||||
return _pixelsWide;
|
return _pixelsWide;
|
||||||
}
|
}
|
||||||
|
|
||||||
long Texture2D::getPixelsHigh() const
|
int Texture2D::getPixelsHigh() const
|
||||||
{
|
{
|
||||||
return _pixelsHigh;
|
return _pixelsHigh;
|
||||||
}
|
}
|
||||||
|
@ -529,14 +529,14 @@ bool Texture2D::hasPremultipliedAlpha() const
|
||||||
return _hasPremultipliedAlpha;
|
return _hasPremultipliedAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Texture2D::initWithData(const void *data, long dataLen, Texture2D::PixelFormat pixelFormat, long pixelsWide, long pixelsHigh, const Size& contentSize)
|
bool Texture2D::initWithData(const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize)
|
||||||
{
|
{
|
||||||
CCASSERT(dataLen>0 && pixelsWide>0 && pixelsHigh>0, "Invalid size");
|
CCASSERT(dataLen>0 && pixelsWide>0 && pixelsHigh>0, "Invalid size");
|
||||||
|
|
||||||
//if data has no mipmaps, we will consider it has only one mipmap
|
//if data has no mipmaps, we will consider it has only one mipmap
|
||||||
MipmapInfo mipmap;
|
MipmapInfo mipmap;
|
||||||
mipmap.address = (unsigned char*)data;
|
mipmap.address = (unsigned char*)data;
|
||||||
mipmap.len = dataLen;
|
mipmap.len = static_cast<int>(dataLen);
|
||||||
return initWithMipmaps(&mipmap, 1, pixelFormat, pixelsWide, pixelsHigh);
|
return initWithMipmaps(&mipmap, 1, pixelFormat, pixelsWide, pixelsHigh);
|
||||||
|
|
||||||
//update information
|
//update information
|
||||||
|
@ -546,7 +546,7 @@ bool Texture2D::initWithData(const void *data, long dataLen, Texture2D::PixelFor
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat pixelFormat, long pixelsWide, long pixelsHigh)
|
bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat pixelFormat, int pixelsWide, int pixelsHigh)
|
||||||
{
|
{
|
||||||
//the pixelFormat must be a certain value
|
//the pixelFormat must be a certain value
|
||||||
CCASSERT(pixelFormat != PixelFormat::NONE && pixelFormat != PixelFormat::AUTO, "the \"pixelFormat\" param must be a certain value!");
|
CCASSERT(pixelFormat != PixelFormat::NONE && pixelFormat != PixelFormat::AUTO, "the \"pixelFormat\" param must be a certain value!");
|
||||||
|
@ -622,8 +622,8 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat
|
||||||
CHECK_GL_ERROR_DEBUG(); // clean possible GL error
|
CHECK_GL_ERROR_DEBUG(); // clean possible GL error
|
||||||
|
|
||||||
// Specify OpenGL texture image
|
// Specify OpenGL texture image
|
||||||
long width = pixelsWide;
|
int width = pixelsWide;
|
||||||
long height = pixelsHigh;
|
int height = pixelsHigh;
|
||||||
|
|
||||||
for (int i = 0; i < mipmapsNum; ++i)
|
for (int i = 0; i < mipmapsNum; ++i)
|
||||||
{
|
{
|
||||||
|
@ -641,7 +641,7 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat
|
||||||
|
|
||||||
if (i > 0 && (width != height || ccNextPOT(width) != width ))
|
if (i > 0 && (width != height || ccNextPOT(width) != width ))
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: Texture2D. WARNING. Mipmap level %u is not squared. Texture won't render correctly. width=%ld != height=%ld", i, width, height);
|
CCLOG("cocos2d: Texture2D. WARNING. Mipmap level %u is not squared. Texture won't render correctly. width=%d != height=%d", i, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum err = glGetError();
|
GLenum err = glGetError();
|
||||||
|
@ -742,7 +742,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* outTempData = NULL;
|
unsigned char* outTempData = NULL;
|
||||||
int outTempDataLen = 0;
|
ssize_t outTempDataLen = 0;
|
||||||
|
|
||||||
pixelFormat = convertDataToFormat(tempData, tempDataLen, renderFormat, pixelFormat, &outTempData, &outTempDataLen);
|
pixelFormat = convertDataToFormat(tempData, tempDataLen, renderFormat, pixelFormat, &outTempData, &outTempDataLen);
|
||||||
|
|
||||||
|
@ -774,7 +774,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen)
|
Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
|
@ -823,7 +823,7 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, l
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen)
|
Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
|
@ -878,7 +878,7 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data,
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen)
|
Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
|
@ -926,7 +926,7 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen)
|
Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (format)
|
switch (format)
|
||||||
|
@ -998,7 +998,7 @@ rgb(2) -> 1235678
|
||||||
rgba(1) -> 12345678
|
rgba(1) -> 12345678
|
||||||
|
|
||||||
*/
|
*/
|
||||||
Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, long dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, int* outDataLen)
|
Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen)
|
||||||
{
|
{
|
||||||
switch (originFormat)
|
switch (originFormat)
|
||||||
{
|
{
|
||||||
|
@ -1243,7 +1243,7 @@ void Texture2D::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied)
|
||||||
|
|
||||||
void Texture2D::generateMipmap()
|
void Texture2D::generateMipmap()
|
||||||
{
|
{
|
||||||
CCASSERT( static_cast<unsigned long>(_pixelsWide) == ccNextPOT(_pixelsWide) && static_cast<unsigned long>(_pixelsHigh) == ccNextPOT(_pixelsHigh), "Mipmap texture only works in POT textures");
|
CCASSERT(_pixelsWide == ccNextPOT(_pixelsWide) && _pixelsHigh == ccNextPOT(_pixelsHigh), "Mipmap texture only works in POT textures");
|
||||||
GL::bindTexture2D( _name );
|
GL::bindTexture2D( _name );
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
_hasMipmaps = true;
|
_hasMipmaps = true;
|
||||||
|
@ -1256,8 +1256,8 @@ bool Texture2D::hasMipmaps() const
|
||||||
|
|
||||||
void Texture2D::setTexParameters(const TexParams &texParams)
|
void Texture2D::setTexParameters(const TexParams &texParams)
|
||||||
{
|
{
|
||||||
CCASSERT( (static_cast<unsigned long>(_pixelsWide) == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) &&
|
CCASSERT((_pixelsWide == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) &&
|
||||||
(static_cast<unsigned long>(_pixelsHigh) == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE),
|
(_pixelsHigh == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE),
|
||||||
"GL_CLAMP_TO_EDGE should be used in NPOT dimensions");
|
"GL_CLAMP_TO_EDGE should be used in NPOT dimensions");
|
||||||
|
|
||||||
GL::bindTexture2D( _name );
|
GL::bindTexture2D( _name );
|
||||||
|
|
|
@ -217,10 +217,10 @@ public:
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
bool initWithData(const void *data, long dataLen, Texture2D::PixelFormat pixelFormat, long pixelsWide, long pixelsHigh, const Size& contentSize);
|
bool initWithData(const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize);
|
||||||
|
|
||||||
/** Initializes with mipmaps */
|
/** Initializes with mipmaps */
|
||||||
bool initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, Texture2D::PixelFormat pixelFormat, long pixelsWide, long pixelsHigh);
|
bool initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Drawing extensions to make it easy to draw basic quads using a Texture2D object.
|
Drawing extensions to make it easy to draw basic quads using a Texture2D object.
|
||||||
|
@ -327,10 +327,10 @@ public:
|
||||||
Texture2D::PixelFormat getPixelFormat() const;
|
Texture2D::PixelFormat getPixelFormat() const;
|
||||||
|
|
||||||
/** Gets the width of the texture in pixels */
|
/** Gets the width of the texture in pixels */
|
||||||
long getPixelsWide() const;
|
int getPixelsWide() const;
|
||||||
|
|
||||||
/** Gets the height of the texture in pixels */
|
/** Gets the height of the texture in pixels */
|
||||||
long getPixelsHigh() const;
|
int getPixelsHigh() const;
|
||||||
|
|
||||||
/** Gets the texture name */
|
/** Gets the texture name */
|
||||||
GLuint getName() const;
|
GLuint getName() const;
|
||||||
|
@ -361,56 +361,56 @@ private:
|
||||||
Convert the format to the format param you specified, if the format is PixelFormat::Automatic, it will detect it automatically and convert to the closest format for you.
|
Convert the format to the format param you specified, if the format is PixelFormat::Automatic, it will detect it automatically and convert to the closest format for you.
|
||||||
It will return the converted format to you. if the outData != data, you must delete it manually.
|
It will return the converted format to you. if the outData != data, you must delete it manually.
|
||||||
*/
|
*/
|
||||||
static PixelFormat convertDataToFormat(const unsigned char* data, long dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, int* outDataLen);
|
static PixelFormat convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
||||||
|
|
||||||
static PixelFormat convertI8ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen);
|
static PixelFormat convertI8ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
||||||
static PixelFormat convertAI88ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen);
|
static PixelFormat convertAI88ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
||||||
static PixelFormat convertRGB888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen);
|
static PixelFormat convertRGB888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
||||||
static PixelFormat convertRGBA8888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen);
|
static PixelFormat convertRGBA8888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
||||||
|
|
||||||
//I8 to XXX
|
//I8 to XXX
|
||||||
static void convertI8ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertI8ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertI8ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertI8ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertI8ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertI8ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertI8ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertI8ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertI8ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertI8ToAI88(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertI8ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
|
|
||||||
//AI88 to XXX
|
//AI88 to XXX
|
||||||
static void convertAI88ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertAI88ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertAI88ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertAI88ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertAI88ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertAI88ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertAI88ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertAI88ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertAI88ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertAI88ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertAI88ToA8(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertAI88ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertAI88ToI8(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertAI88ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
|
|
||||||
//RGB888 to XXX
|
//RGB888 to XXX
|
||||||
static void convertRGB888ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGB888ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGB888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGB888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGB888ToI8(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGB888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGB888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGB888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGB888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGB888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGB888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
|
|
||||||
//RGBA8888 to XXX
|
//RGBA8888 to XXX
|
||||||
static void convertRGBA8888ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGBA8888ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGBA8888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGBA8888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGBA8888ToI8(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGBA8888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGBA8888ToA8(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGBA8888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGBA8888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGBA8888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGBA8888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
static void convertRGBA8888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData);
|
static void convertRGBA8888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** pixel format of the texture */
|
/** pixel format of the texture */
|
||||||
Texture2D::PixelFormat _pixelFormat;
|
Texture2D::PixelFormat _pixelFormat;
|
||||||
|
|
||||||
/** width in pixels */
|
/** width in pixels */
|
||||||
long _pixelsWide;
|
int _pixelsWide;
|
||||||
|
|
||||||
/** height in pixels */
|
/** height in pixels */
|
||||||
long _pixelsHigh;
|
int _pixelsHigh;
|
||||||
|
|
||||||
/** texture name */
|
/** texture name */
|
||||||
GLuint _name;
|
GLuint _name;
|
||||||
|
|
|
@ -74,12 +74,12 @@ TextureAtlas::~TextureAtlas()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
long TextureAtlas::getTotalQuads() const
|
int TextureAtlas::getTotalQuads() const
|
||||||
{
|
{
|
||||||
return _totalQuads;
|
return _totalQuads;
|
||||||
}
|
}
|
||||||
|
|
||||||
long TextureAtlas::getCapacity() const
|
int TextureAtlas::getCapacity() const
|
||||||
{
|
{
|
||||||
return _capacity;
|
return _capacity;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ void TextureAtlas::setQuads(V3F_C4B_T2F_Quad* quads)
|
||||||
|
|
||||||
// TextureAtlas - alloc & init
|
// TextureAtlas - alloc & init
|
||||||
|
|
||||||
TextureAtlas * TextureAtlas::create(const char* file, long capacity)
|
TextureAtlas * TextureAtlas::create(const char* file, int capacity)
|
||||||
{
|
{
|
||||||
TextureAtlas * textureAtlas = new TextureAtlas();
|
TextureAtlas * textureAtlas = new TextureAtlas();
|
||||||
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
|
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
|
||||||
|
@ -122,7 +122,7 @@ TextureAtlas * TextureAtlas::create(const char* file, long capacity)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, long capacity)
|
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, int capacity)
|
||||||
{
|
{
|
||||||
TextureAtlas * textureAtlas = new TextureAtlas();
|
TextureAtlas * textureAtlas = new TextureAtlas();
|
||||||
if (textureAtlas && textureAtlas->initWithTexture(texture, capacity))
|
if (textureAtlas && textureAtlas->initWithTexture(texture, capacity))
|
||||||
|
@ -134,7 +134,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, long capacity
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureAtlas::initWithFile(const char * file, long capacity)
|
bool TextureAtlas::initWithFile(const char * file, int capacity)
|
||||||
{
|
{
|
||||||
// retained in property
|
// retained in property
|
||||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file);
|
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file);
|
||||||
|
@ -150,7 +150,7 @@ bool TextureAtlas::initWithFile(const char * file, long capacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureAtlas::initWithTexture(Texture2D *texture, long capacity)
|
bool TextureAtlas::initWithTexture(Texture2D *texture, int capacity)
|
||||||
{
|
{
|
||||||
CCASSERT(capacity>=0, "Capacity must be >= 0");
|
CCASSERT(capacity>=0, "Capacity must be >= 0");
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ void TextureAtlas::listenBackToForeground(Object *obj)
|
||||||
|
|
||||||
const char* TextureAtlas::description() const
|
const char* TextureAtlas::description() const
|
||||||
{
|
{
|
||||||
return String::createWithFormat("<TextureAtlas | totalQuads = %ld>", _totalQuads)->getCString();
|
return String::createWithFormat("<TextureAtlas | totalQuads = %d>", _totalQuads)->getCString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ void TextureAtlas::mapBuffers()
|
||||||
|
|
||||||
// TextureAtlas - Update, Insert, Move & Remove
|
// TextureAtlas - Update, Insert, Move & Remove
|
||||||
|
|
||||||
void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, long index)
|
void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, int index)
|
||||||
{
|
{
|
||||||
CCASSERT( index >= 0 && index < _capacity, "updateQuadWithTexture: Invalid index");
|
CCASSERT( index >= 0 && index < _capacity, "updateQuadWithTexture: Invalid index");
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, long index)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, long index)
|
void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, int index)
|
||||||
{
|
{
|
||||||
CCASSERT( index>=0 && index<_capacity, "insertQuadWithTexture: Invalid index");
|
CCASSERT( index>=0 && index<_capacity, "insertQuadWithTexture: Invalid index");
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, long index)
|
||||||
CCASSERT( _totalQuads <= _capacity, "invalid totalQuads");
|
CCASSERT( _totalQuads <= _capacity, "invalid totalQuads");
|
||||||
|
|
||||||
// issue #575. index can be > totalQuads
|
// issue #575. index can be > totalQuads
|
||||||
unsigned int remaining = (_totalQuads-1) - index;
|
auto remaining = (_totalQuads-1) - index;
|
||||||
|
|
||||||
// last object doesn't need to be moved
|
// last object doesn't need to be moved
|
||||||
if( remaining > 0)
|
if( remaining > 0)
|
||||||
|
@ -354,7 +354,7 @@ void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, long index)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount)
|
void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount)
|
||||||
{
|
{
|
||||||
CCASSERT(index>=0 && amount>=0 && index+amount<=_capacity, "insertQuadWithTexture: Invalid index + amount");
|
CCASSERT(index>=0 && amount>=0 && index+amount<=_capacity, "insertQuadWithTexture: Invalid index + amount");
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount)
|
||||||
CCASSERT( _totalQuads <= _capacity, "invalid totalQuads");
|
CCASSERT( _totalQuads <= _capacity, "invalid totalQuads");
|
||||||
|
|
||||||
// issue #575. index can be > totalQuads
|
// issue #575. index can be > totalQuads
|
||||||
long remaining = (_totalQuads-1) - index - amount;
|
auto remaining = (_totalQuads-1) - index - amount;
|
||||||
|
|
||||||
// last object doesn't need to be moved
|
// last object doesn't need to be moved
|
||||||
if( remaining > 0)
|
if( remaining > 0)
|
||||||
|
@ -373,9 +373,9 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long max = index + amount;
|
auto max = index + amount;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (long i = index; i < max ; i++)
|
for (int i = index; i < max ; i++)
|
||||||
{
|
{
|
||||||
_quads[index] = quads[j];
|
_quads[index] = quads[j];
|
||||||
index++;
|
index++;
|
||||||
|
@ -385,7 +385,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount)
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::insertQuadFromIndex(long oldIndex, long newIndex)
|
void TextureAtlas::insertQuadFromIndex(int oldIndex, int newIndex)
|
||||||
{
|
{
|
||||||
CCASSERT( newIndex >= 0 && newIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
CCASSERT( newIndex >= 0 && newIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||||
CCASSERT( oldIndex >= 0 && oldIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
CCASSERT( oldIndex >= 0 && oldIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||||
|
@ -396,9 +396,9 @@ void TextureAtlas::insertQuadFromIndex(long oldIndex, long newIndex)
|
||||||
}
|
}
|
||||||
// because it is ambiguous in iphone, so we implement abs ourselves
|
// because it is ambiguous in iphone, so we implement abs ourselves
|
||||||
// unsigned int howMany = abs( oldIndex - newIndex);
|
// unsigned int howMany = abs( oldIndex - newIndex);
|
||||||
long howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex);
|
auto howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex);
|
||||||
long dst = oldIndex;
|
auto dst = oldIndex;
|
||||||
long src = oldIndex + 1;
|
auto src = oldIndex + 1;
|
||||||
if( oldIndex > newIndex)
|
if( oldIndex > newIndex)
|
||||||
{
|
{
|
||||||
dst = newIndex+1;
|
dst = newIndex+1;
|
||||||
|
@ -414,11 +414,11 @@ void TextureAtlas::insertQuadFromIndex(long oldIndex, long newIndex)
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::removeQuadAtIndex(long index)
|
void TextureAtlas::removeQuadAtIndex(int index)
|
||||||
{
|
{
|
||||||
CCASSERT( index>=0 && index<_totalQuads, "removeQuadAtIndex: Invalid index");
|
CCASSERT( index>=0 && index<_totalQuads, "removeQuadAtIndex: Invalid index");
|
||||||
|
|
||||||
long remaining = (_totalQuads-1) - index;
|
auto remaining = (_totalQuads-1) - index;
|
||||||
|
|
||||||
// last object doesn't need to be moved
|
// last object doesn't need to be moved
|
||||||
if( remaining )
|
if( remaining )
|
||||||
|
@ -433,11 +433,11 @@ void TextureAtlas::removeQuadAtIndex(long index)
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::removeQuadsAtIndex(long index, long amount)
|
void TextureAtlas::removeQuadsAtIndex(int index, int amount)
|
||||||
{
|
{
|
||||||
CCASSERT(index>=0 && amount>=0 && index+amount<=_totalQuads, "removeQuadAtIndex: index + amount out of bounds");
|
CCASSERT(index>=0 && amount>=0 && index+amount<=_totalQuads, "removeQuadAtIndex: index + amount out of bounds");
|
||||||
|
|
||||||
long remaining = (_totalQuads) - (index + amount);
|
auto remaining = (_totalQuads) - (index + amount);
|
||||||
|
|
||||||
_totalQuads -= amount;
|
_totalQuads -= amount;
|
||||||
|
|
||||||
|
@ -455,14 +455,14 @@ void TextureAtlas::removeAllQuads()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextureAtlas - Resize
|
// TextureAtlas - Resize
|
||||||
bool TextureAtlas::resizeCapacity(long newCapacity)
|
bool TextureAtlas::resizeCapacity(int newCapacity)
|
||||||
{
|
{
|
||||||
CCASSERT(newCapacity>=0, "capacity >= 0");
|
CCASSERT(newCapacity>=0, "capacity >= 0");
|
||||||
if( newCapacity == _capacity )
|
if( newCapacity == _capacity )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
long oldCapactiy = _capacity;
|
auto oldCapactiy = _capacity;
|
||||||
// update capacity and totolQuads
|
// update capacity and totolQuads
|
||||||
_totalQuads = MIN(_totalQuads, newCapacity);
|
_totalQuads = MIN(_totalQuads, newCapacity);
|
||||||
_capacity = newCapacity;
|
_capacity = newCapacity;
|
||||||
|
@ -529,13 +529,13 @@ bool TextureAtlas::resizeCapacity(long newCapacity)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::increaseTotalQuadsWith(long amount)
|
void TextureAtlas::increaseTotalQuadsWith(int amount)
|
||||||
{
|
{
|
||||||
CCASSERT(amount>=0, "amount >= 0");
|
CCASSERT(amount>=0, "amount >= 0");
|
||||||
_totalQuads += amount;
|
_totalQuads += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::moveQuadsFromIndex(long oldIndex, long amount, long newIndex)
|
void TextureAtlas::moveQuadsFromIndex(int oldIndex, int amount, int newIndex)
|
||||||
{
|
{
|
||||||
CCASSERT(oldIndex>=0 && amount>=0 && newIndex>=0, "values must be >= 0");
|
CCASSERT(oldIndex>=0 && amount>=0 && newIndex>=0, "values must be >= 0");
|
||||||
CCASSERT(newIndex + amount <= _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
CCASSERT(newIndex + amount <= _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||||
|
@ -567,7 +567,7 @@ void TextureAtlas::moveQuadsFromIndex(long oldIndex, long amount, long newIndex)
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::moveQuadsFromIndex(long index, long newIndex)
|
void TextureAtlas::moveQuadsFromIndex(int index, int newIndex)
|
||||||
{
|
{
|
||||||
CCASSERT(index>=0 && newIndex>=0, "values must be >= 0");
|
CCASSERT(index>=0 && newIndex>=0, "values must be >= 0");
|
||||||
CCASSERT(newIndex + (_totalQuads - index) <= _capacity, "moveQuadsFromIndex move is out of bounds");
|
CCASSERT(newIndex + (_totalQuads - index) <= _capacity, "moveQuadsFromIndex move is out of bounds");
|
||||||
|
@ -575,14 +575,14 @@ void TextureAtlas::moveQuadsFromIndex(long index, long newIndex)
|
||||||
memmove(_quads + newIndex,_quads + index, (_totalQuads - index) * sizeof(_quads[0]));
|
memmove(_quads + newIndex,_quads + index, (_totalQuads - index) * sizeof(_quads[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::fillWithEmptyQuadsFromIndex(long index, long amount)
|
void TextureAtlas::fillWithEmptyQuadsFromIndex(int index, int amount)
|
||||||
{
|
{
|
||||||
CCASSERT(index>=0 && amount>=0, "values must be >= 0");
|
CCASSERT(index>=0 && amount>=0, "values must be >= 0");
|
||||||
V3F_C4B_T2F_Quad quad;
|
V3F_C4B_T2F_Quad quad;
|
||||||
memset(&quad, 0, sizeof(quad));
|
memset(&quad, 0, sizeof(quad));
|
||||||
|
|
||||||
long to = index + amount;
|
auto to = index + amount;
|
||||||
for (long i = index ; i < to ; i++)
|
for (int i = index ; i < to ; i++)
|
||||||
{
|
{
|
||||||
_quads[i] = quad;
|
_quads[i] = quad;
|
||||||
}
|
}
|
||||||
|
@ -595,13 +595,13 @@ void TextureAtlas::drawQuads()
|
||||||
this->drawNumberOfQuads(_totalQuads, 0);
|
this->drawNumberOfQuads(_totalQuads, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::drawNumberOfQuads(long numberOfQuads)
|
void TextureAtlas::drawNumberOfQuads(int numberOfQuads)
|
||||||
{
|
{
|
||||||
CCASSERT(numberOfQuads>=0, "numberOfQuads must be >= 0");
|
CCASSERT(numberOfQuads>=0, "numberOfQuads must be >= 0");
|
||||||
this->drawNumberOfQuads(numberOfQuads, 0);
|
this->drawNumberOfQuads(numberOfQuads, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAtlas::drawNumberOfQuads(long numberOfQuads, long start)
|
void TextureAtlas::drawNumberOfQuads(int numberOfQuads, int start)
|
||||||
{
|
{
|
||||||
CCASSERT(numberOfQuads>=0 && start>=0, "numberOfQuads and start must be >= 0");
|
CCASSERT(numberOfQuads>=0 && start>=0, "numberOfQuads and start must be >= 0");
|
||||||
|
|
||||||
|
|
|
@ -59,13 +59,13 @@ public:
|
||||||
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
||||||
* The TextureAtlas capacity can be increased in runtime.
|
* The TextureAtlas capacity can be increased in runtime.
|
||||||
*/
|
*/
|
||||||
static TextureAtlas* create(const char* file , long capacity);
|
static TextureAtlas* create(const char* file , int capacity);
|
||||||
|
|
||||||
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
||||||
* with an initial capacity for n Quads.
|
* with an initial capacity for n Quads.
|
||||||
* The TextureAtlas capacity can be increased in runtime.
|
* The TextureAtlas capacity can be increased in runtime.
|
||||||
*/
|
*/
|
||||||
static TextureAtlas* createWithTexture(Texture2D *texture, long capacity);
|
static TextureAtlas* createWithTexture(Texture2D *texture, int capacity);
|
||||||
/**
|
/**
|
||||||
* @js ctor
|
* @js ctor
|
||||||
*/
|
*/
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
*
|
*
|
||||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||||
*/
|
*/
|
||||||
bool initWithFile(const char* file, long capacity);
|
bool initWithFile(const char* file, int capacity);
|
||||||
|
|
||||||
/** initializes a TextureAtlas with a previously initialized Texture2D object, and
|
/** initializes a TextureAtlas with a previously initialized Texture2D object, and
|
||||||
* with an initial capacity for Quads.
|
* with an initial capacity for Quads.
|
||||||
|
@ -89,43 +89,43 @@ public:
|
||||||
*
|
*
|
||||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||||
*/
|
*/
|
||||||
bool initWithTexture(Texture2D *texture, long capacity);
|
bool initWithTexture(Texture2D *texture, int capacity);
|
||||||
|
|
||||||
/** updates a Quad (texture, vertex and color) at a certain index
|
/** updates a Quad (texture, vertex and color) at a certain index
|
||||||
* index must be between 0 and the atlas capacity - 1
|
* index must be between 0 and the atlas capacity - 1
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
void updateQuad(V3F_C4B_T2F_Quad* quad, long index);
|
void updateQuad(V3F_C4B_T2F_Quad* quad, int index);
|
||||||
|
|
||||||
/** Inserts a Quad (texture, vertex and color) at a certain index
|
/** Inserts a Quad (texture, vertex and color) at a certain index
|
||||||
index must be between 0 and the atlas capacity - 1
|
index must be between 0 and the atlas capacity - 1
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
void insertQuad(V3F_C4B_T2F_Quad* quad, long index);
|
void insertQuad(V3F_C4B_T2F_Quad* quad, int index);
|
||||||
|
|
||||||
/** Inserts a c array of quads at a given index
|
/** Inserts a c array of quads at a given index
|
||||||
index must be between 0 and the atlas capacity - 1
|
index must be between 0 and the atlas capacity - 1
|
||||||
this method doesn't enlarge the array when amount + index > totalQuads
|
this method doesn't enlarge the array when amount + index > totalQuads
|
||||||
@since v1.1
|
@since v1.1
|
||||||
*/
|
*/
|
||||||
void insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount);
|
void insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount);
|
||||||
|
|
||||||
/** Removes the quad that is located at a certain index and inserts it at a new index
|
/** Removes the quad that is located at a certain index and inserts it at a new index
|
||||||
This operation is faster than removing and inserting in a quad in 2 different steps
|
This operation is faster than removing and inserting in a quad in 2 different steps
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
*/
|
*/
|
||||||
void insertQuadFromIndex(long fromIndex, long newIndex);
|
void insertQuadFromIndex(int fromIndex, int newIndex);
|
||||||
|
|
||||||
/** removes a quad at a given index number.
|
/** removes a quad at a given index number.
|
||||||
The capacity remains the same, but the total number of quads to be drawn is reduced in 1
|
The capacity remains the same, but the total number of quads to be drawn is reduced in 1
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
*/
|
*/
|
||||||
void removeQuadAtIndex(long index);
|
void removeQuadAtIndex(int index);
|
||||||
|
|
||||||
/** removes a amount of quads starting from index
|
/** removes a amount of quads starting from index
|
||||||
@since 1.1
|
@since 1.1
|
||||||
*/
|
*/
|
||||||
void removeQuadsAtIndex(long index, long amount);
|
void removeQuadsAtIndex(int index, int amount);
|
||||||
/** removes all Quads.
|
/** removes all Quads.
|
||||||
The TextureAtlas capacity remains untouched. No memory is freed.
|
The TextureAtlas capacity remains untouched. No memory is freed.
|
||||||
The total number of quads to be drawn will be 0
|
The total number of quads to be drawn will be 0
|
||||||
|
@ -138,19 +138,19 @@ public:
|
||||||
* It returns true if the resize was successful.
|
* It returns true if the resize was successful.
|
||||||
* If it fails to resize the capacity it will return false with a new capacity of 0.
|
* If it fails to resize the capacity it will return false with a new capacity of 0.
|
||||||
*/
|
*/
|
||||||
bool resizeCapacity(long capacity);
|
bool resizeCapacity(int capacity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by ParticleBatchNode
|
Used internally by ParticleBatchNode
|
||||||
don't use this unless you know what you're doing
|
don't use this unless you know what you're doing
|
||||||
@since 1.1
|
@since 1.1
|
||||||
*/
|
*/
|
||||||
void increaseTotalQuadsWith(long amount);
|
void increaseTotalQuadsWith(int amount);
|
||||||
|
|
||||||
/** Moves an amount of quads from oldIndex at newIndex
|
/** Moves an amount of quads from oldIndex at newIndex
|
||||||
@since v1.1
|
@since v1.1
|
||||||
*/
|
*/
|
||||||
void moveQuadsFromIndex(long oldIndex, long amount, long newIndex);
|
void moveQuadsFromIndex(int oldIndex, int amount, int newIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Moves quads from index till totalQuads to the newIndex
|
Moves quads from index till totalQuads to the newIndex
|
||||||
|
@ -158,26 +158,26 @@ public:
|
||||||
This method doesn't enlarge the array if newIndex + quads to be moved > capacity
|
This method doesn't enlarge the array if newIndex + quads to be moved > capacity
|
||||||
@since 1.1
|
@since 1.1
|
||||||
*/
|
*/
|
||||||
void moveQuadsFromIndex(long index, long newIndex);
|
void moveQuadsFromIndex(int index, int newIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ensures that after a realloc quads are still empty
|
Ensures that after a realloc quads are still empty
|
||||||
Used internally by ParticleBatchNode
|
Used internally by ParticleBatchNode
|
||||||
@since 1.1
|
@since 1.1
|
||||||
*/
|
*/
|
||||||
void fillWithEmptyQuadsFromIndex(long index, long amount);
|
void fillWithEmptyQuadsFromIndex(int index, int amount);
|
||||||
|
|
||||||
/** draws n quads
|
/** draws n quads
|
||||||
* n can't be greater than the capacity of the Atlas
|
* n can't be greater than the capacity of the Atlas
|
||||||
*/
|
*/
|
||||||
void drawNumberOfQuads(long n);
|
void drawNumberOfQuads(int n);
|
||||||
|
|
||||||
/** draws n quads from an index (offset).
|
/** draws n quads from an index (offset).
|
||||||
n + start can't be greater than the capacity of the atlas
|
n + start can't be greater than the capacity of the atlas
|
||||||
|
|
||||||
@since v1.0
|
@since v1.0
|
||||||
*/
|
*/
|
||||||
void drawNumberOfQuads(long numberOfQuads, long start);
|
void drawNumberOfQuads(int numberOfQuads, int start);
|
||||||
|
|
||||||
/** draws all the Atlas's Quads
|
/** draws all the Atlas's Quads
|
||||||
*/
|
*/
|
||||||
|
@ -197,10 +197,10 @@ public:
|
||||||
const char* description() const;
|
const char* description() const;
|
||||||
|
|
||||||
/** Gets the quantity of quads that are going to be drawn */
|
/** Gets the quantity of quads that are going to be drawn */
|
||||||
long getTotalQuads() const;
|
int getTotalQuads() const;
|
||||||
|
|
||||||
/** Gets the quantity of quads that can be stored with the current texture atlas size */
|
/** Gets the quantity of quads that can be stored with the current texture atlas size */
|
||||||
long getCapacity() const;
|
int getCapacity() const;
|
||||||
|
|
||||||
/** Gets the texture of the texture atlas */
|
/** Gets the texture of the texture atlas */
|
||||||
Texture2D* getTexture() const;
|
Texture2D* getTexture() const;
|
||||||
|
@ -226,9 +226,9 @@ protected:
|
||||||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||||
bool _dirty; //indicates whether or not the array buffer of the VBO needs to be updated
|
bool _dirty; //indicates whether or not the array buffer of the VBO needs to be updated
|
||||||
/** quantity of quads that are going to be drawn */
|
/** quantity of quads that are going to be drawn */
|
||||||
long _totalQuads;
|
int _totalQuads;
|
||||||
/** quantity of quads that can be stored with the current texture atlas size */
|
/** quantity of quads that can be stored with the current texture atlas size */
|
||||||
long _capacity;
|
int _capacity;
|
||||||
/** Texture of the texture atlas */
|
/** Texture of the texture atlas */
|
||||||
Texture2D* _texture;
|
Texture2D* _texture;
|
||||||
/** Quads that are going to be rendered */
|
/** Quads that are going to be rendered */
|
||||||
|
|
|
@ -34,7 +34,6 @@ THE SOFTWARE.
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "platform/CCThread.h"
|
|
||||||
#include "ccUtils.h"
|
#include "ccUtils.h"
|
||||||
#include "CCScheduler.h"
|
#include "CCScheduler.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
|
@ -93,18 +92,6 @@ const char* TextureCache::description() const
|
||||||
return String::createWithFormat("<TextureCache | Number of textures = %lu>", _textures.size() )->getCString();
|
return String::createWithFormat("<TextureCache | Number of textures = %lu>", _textures.size() )->getCString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dictionary* TextureCache::snapshotTextures()
|
|
||||||
//{
|
|
||||||
// Dictionary* pRet = new Dictionary();
|
|
||||||
// DictElement* pElement = NULL;
|
|
||||||
// CCDICT_FOREACH(_textures, pElement)
|
|
||||||
// {
|
|
||||||
// pRet->setObject(pElement->getObject(), pElement->getStrKey());
|
|
||||||
// }
|
|
||||||
// pRet->autorelease();
|
|
||||||
// return pRet;
|
|
||||||
//}
|
|
||||||
|
|
||||||
void TextureCache::addImageAsync(const std::string &path, Object *target, SEL_CallFuncO selector)
|
void TextureCache::addImageAsync(const std::string &path, Object *target, SEL_CallFuncO selector)
|
||||||
{
|
{
|
||||||
Texture2D *texture = NULL;
|
Texture2D *texture = NULL;
|
||||||
|
@ -446,7 +433,7 @@ void TextureCache::dumpCachedTextureInfo() const
|
||||||
Texture2D* tex = it->second;
|
Texture2D* tex = it->second;
|
||||||
unsigned int bpp = tex->getBitsPerPixelForFormat();
|
unsigned int bpp = tex->getBitsPerPixelForFormat();
|
||||||
// Each texture takes up width * height * bytesPerPixel bytes.
|
// Each texture takes up width * height * bytesPerPixel bytes.
|
||||||
long bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8;
|
auto bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8;
|
||||||
totalBytes += bytes;
|
totalBytes += bytes;
|
||||||
count++;
|
count++;
|
||||||
log("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
log("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
||||||
|
@ -607,7 +594,7 @@ void VolatileTextureMgr::reloadAllTextures()
|
||||||
case VolatileTexture::kImageFile:
|
case VolatileTexture::kImageFile:
|
||||||
{
|
{
|
||||||
Image* image = new Image();
|
Image* image = new Image();
|
||||||
long size = 0;
|
ssize_t size = 0;
|
||||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size);
|
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size);
|
||||||
|
|
||||||
if (image && image->initWithImageData(pBuffer, size))
|
if (image && image->initWithImageData(pBuffer, size))
|
||||||
|
|
|
@ -58,7 +58,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLEle
|
||||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||||
*doc = xmlDoc;
|
*doc = xmlDoc;
|
||||||
//CCFileData data(UserDefault::getInstance()->getXMLFilePath().c_str(),"rt");
|
//CCFileData data(UserDefault::getInstance()->getXMLFilePath().c_str(),"rt");
|
||||||
long nSize;
|
ssize_t nSize;
|
||||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize);
|
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize);
|
||||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||||
if(NULL == pXmlBuffer)
|
if(NULL == pXmlBuffer)
|
||||||
|
@ -404,7 +404,7 @@ void UserDefault::setDataForKey(const char* pKey, const Data& value) {
|
||||||
|
|
||||||
char *encodedData = 0;
|
char *encodedData = 0;
|
||||||
|
|
||||||
base64Encode(value.getBytes(), value.getSize(), &encodedData);
|
base64Encode(value.getBytes(), static_cast<unsigned int>(value.getSize()), &encodedData);
|
||||||
|
|
||||||
setValueForKey(pKey, encodedData);
|
setValueForKey(pKey, encodedData);
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||||
*doc = xmlDoc;
|
*doc = xmlDoc;
|
||||||
long size;
|
ssize_t size;
|
||||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||||
if(NULL == pXmlBuffer)
|
if(NULL == pXmlBuffer)
|
||||||
|
@ -420,11 +420,11 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned char *bytes = {0};
|
unsigned char *bytes = {0};
|
||||||
unsigned long size = 0;
|
int size = 0;
|
||||||
|
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
bytes = (unsigned char*)data.bytes;
|
bytes = (unsigned char*)data.bytes;
|
||||||
size = data.length;
|
size = static_cast<int>(data.length);
|
||||||
}
|
}
|
||||||
Data *ret = new Data(bytes, size);
|
Data *ret = new Data(bytes, size);
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||||
*doc = xmlDoc;
|
*doc = xmlDoc;
|
||||||
long size;
|
ssize_t size;
|
||||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||||
if(NULL == pXmlBuffer)
|
if(NULL == pXmlBuffer)
|
||||||
|
@ -470,7 +470,7 @@ void UserDefault::setDataForKey(const char* pKey, const Data& value)
|
||||||
|
|
||||||
CCLOG("SET DATA ENCODED: --%s", encodedData);
|
CCLOG("SET DATA ENCODED: --%s", encodedData);
|
||||||
|
|
||||||
return setStringForKeyJNI(pKey, encodedData);
|
setStringForKeyJNI(pKey, encodedData);
|
||||||
|
|
||||||
if (encodedData)
|
if (encodedData)
|
||||||
free(encodedData);
|
free(encodedData);
|
||||||
|
|
|
@ -39,7 +39,7 @@ bool ZipUtils::s_bEncryptionKeyIsValid = false;
|
||||||
|
|
||||||
// --------------------- ZipUtils ---------------------
|
// --------------------- ZipUtils ---------------------
|
||||||
|
|
||||||
inline void ZipUtils::decodeEncodedPvr(unsigned int *data, long len)
|
inline void ZipUtils::decodeEncodedPvr(unsigned int *data, ssize_t len)
|
||||||
{
|
{
|
||||||
const int enclen = 1024;
|
const int enclen = 1024;
|
||||||
const int securelen = 512;
|
const int securelen = 512;
|
||||||
|
@ -108,7 +108,7 @@ inline void ZipUtils::decodeEncodedPvr(unsigned int *data, long len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned int ZipUtils::checksumPvr(const unsigned int *data, long len)
|
inline unsigned int ZipUtils::checksumPvr(const unsigned int *data, ssize_t len)
|
||||||
{
|
{
|
||||||
unsigned int cs = 0;
|
unsigned int cs = 0;
|
||||||
const int cslen = 128;
|
const int cslen = 128;
|
||||||
|
@ -127,12 +127,12 @@ inline unsigned int ZipUtils::checksumPvr(const unsigned int *data, long len)
|
||||||
// Should buffer factor be 1.5 instead of 2 ?
|
// Should buffer factor be 1.5 instead of 2 ?
|
||||||
#define BUFFER_INC_FACTOR (2)
|
#define BUFFER_INC_FACTOR (2)
|
||||||
|
|
||||||
int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long *outLength, long outLenghtHint)
|
int ZipUtils::inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t *outLength, ssize_t outLenghtHint)
|
||||||
{
|
{
|
||||||
/* ret value */
|
/* ret value */
|
||||||
int err = Z_OK;
|
int err = Z_OK;
|
||||||
|
|
||||||
long bufferSize = outLenghtHint;
|
ssize_t bufferSize = outLenghtHint;
|
||||||
*out = (unsigned char*)malloc(bufferSize);
|
*out = (unsigned char*)malloc(bufferSize);
|
||||||
|
|
||||||
z_stream d_stream; /* decompression stream */
|
z_stream d_stream; /* decompression stream */
|
||||||
|
@ -141,9 +141,9 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned c
|
||||||
d_stream.opaque = (voidpf)0;
|
d_stream.opaque = (voidpf)0;
|
||||||
|
|
||||||
d_stream.next_in = in;
|
d_stream.next_in = in;
|
||||||
d_stream.avail_in = inLength;
|
d_stream.avail_in = static_cast<unsigned int>(inLength);
|
||||||
d_stream.next_out = *out;
|
d_stream.next_out = *out;
|
||||||
d_stream.avail_out = bufferSize;
|
d_stream.avail_out = static_cast<unsigned int>(bufferSize);
|
||||||
|
|
||||||
/* window size to hold 256k */
|
/* window size to hold 256k */
|
||||||
if( (err = inflateInit2(&d_stream, 15 + 32)) != Z_OK )
|
if( (err = inflateInit2(&d_stream, 15 + 32)) != Z_OK )
|
||||||
|
@ -182,7 +182,7 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned c
|
||||||
}
|
}
|
||||||
|
|
||||||
d_stream.next_out = *out + bufferSize;
|
d_stream.next_out = *out + bufferSize;
|
||||||
d_stream.avail_out = bufferSize;
|
d_stream.avail_out = static_cast<unsigned int>(bufferSize);
|
||||||
bufferSize *= BUFFER_INC_FACTOR;
|
bufferSize *= BUFFER_INC_FACTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,9 +192,9 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned c
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long outLengthHint)
|
ssize_t ZipUtils::inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t outLengthHint)
|
||||||
{
|
{
|
||||||
long outLength = 0;
|
ssize_t outLength = 0;
|
||||||
int err = inflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint);
|
int err = inflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint);
|
||||||
|
|
||||||
if (err != Z_OK || *out == NULL) {
|
if (err != Z_OK || *out == NULL) {
|
||||||
|
@ -225,7 +225,7 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned c
|
||||||
return outLength;
|
return outLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZipUtils::inflateMemory(unsigned char *in, long inLength, unsigned char **out)
|
ssize_t ZipUtils::inflateMemory(unsigned char *in, ssize_t inLength, unsigned char **out)
|
||||||
{
|
{
|
||||||
// 256k for hint
|
// 256k for hint
|
||||||
return inflateMemoryWithHint(in, inLength, out, 256 * 1024);
|
return inflateMemoryWithHint(in, inLength, out, 256 * 1024);
|
||||||
|
@ -363,7 +363,7 @@ bool ZipUtils::isGZipBuffer(const unsigned char *buffer, long len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsigned char **out)
|
int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, ssize_t bufferLen, unsigned char **out)
|
||||||
{
|
{
|
||||||
struct CCZHeader *header = (struct CCZHeader*) buffer;
|
struct CCZHeader *header = (struct CCZHeader*) buffer;
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsi
|
||||||
|
|
||||||
// decrypt
|
// decrypt
|
||||||
unsigned int* ints = (unsigned int*)(buffer+12);
|
unsigned int* ints = (unsigned int*)(buffer+12);
|
||||||
int enclen = (bufferLen-12)/4;
|
ssize_t enclen = (bufferLen-12)/4;
|
||||||
|
|
||||||
decodeEncodedPvr(ints, enclen);
|
decodeEncodedPvr(ints, enclen);
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsi
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long destlen = len;
|
unsigned long destlen = len;
|
||||||
unsigned long source = (unsigned long) buffer + sizeof(*header);
|
size_t source = (size_t) buffer + sizeof(*header);
|
||||||
int ret = uncompress(*out, &destlen, (Bytef*)source, bufferLen - sizeof(*header) );
|
int ret = uncompress(*out, &destlen, (Bytef*)source, bufferLen - sizeof(*header) );
|
||||||
|
|
||||||
if( ret != Z_OK )
|
if( ret != Z_OK )
|
||||||
|
@ -591,7 +591,7 @@ bool ZipFile::fileExists(const std::string &fileName) const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *ZipFile::getFileData(const std::string &fileName, long *size)
|
unsigned char *ZipFile::getFileData(const std::string &fileName, ssize_t *size)
|
||||||
{
|
{
|
||||||
unsigned char * buffer = NULL;
|
unsigned char * buffer = NULL;
|
||||||
if (size)
|
if (size)
|
||||||
|
@ -614,7 +614,7 @@ unsigned char *ZipFile::getFileData(const std::string &fileName, long *size)
|
||||||
CC_BREAK_IF(UNZ_OK != nRet);
|
CC_BREAK_IF(UNZ_OK != nRet);
|
||||||
|
|
||||||
buffer = (unsigned char*)malloc(fileInfo.uncompressed_size);
|
buffer = (unsigned char*)malloc(fileInfo.uncompressed_size);
|
||||||
int CC_UNUSED nSize = unzReadCurrentFile(_data->zipFile, buffer, fileInfo.uncompressed_size);
|
int CC_UNUSED nSize = unzReadCurrentFile(_data->zipFile, buffer, static_cast<unsigned int>(fileInfo.uncompressed_size));
|
||||||
CCASSERT(nSize == 0 || nSize == (int)fileInfo.uncompressed_size, "the file size is wrong");
|
CCASSERT(nSize == 0 || nSize == (int)fileInfo.uncompressed_size, "the file size is wrong");
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
|
|
|
@ -65,8 +65,8 @@ namespace cocos2d
|
||||||
*
|
*
|
||||||
@since v0.8.1
|
@since v0.8.1
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE static int ccInflateMemory(unsigned char *in, long inLength, unsigned char **out) { return inflateMemory(in, inLength, out); }
|
CC_DEPRECATED_ATTRIBUTE static ssize_t ccInflateMemory(unsigned char *in, ssize_t inLength, unsigned char **out) { return inflateMemory(in, inLength, out); }
|
||||||
static int inflateMemory(unsigned char *in, long inLength, unsigned char **out);
|
static ssize_t inflateMemory(unsigned char *in, ssize_t inLength, unsigned char **out);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inflates either zlib or gzip deflated memory. The inflated memory is
|
* Inflates either zlib or gzip deflated memory. The inflated memory is
|
||||||
|
@ -78,8 +78,8 @@ namespace cocos2d
|
||||||
*
|
*
|
||||||
@since v1.0.0
|
@since v1.0.0
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE static int ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long outLengthHint) { return inflateMemoryWithHint(in, inLength, out, outLengthHint); }
|
CC_DEPRECATED_ATTRIBUTE static ssize_t ccInflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t outLengthHint) { return inflateMemoryWithHint(in, inLength, out, outLengthHint); }
|
||||||
static int inflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long outLengthHint);
|
static ssize_t inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t outLengthHint);
|
||||||
|
|
||||||
/** inflates a GZip file into memory
|
/** inflates a GZip file into memory
|
||||||
*
|
*
|
||||||
|
@ -105,8 +105,8 @@ namespace cocos2d
|
||||||
*
|
*
|
||||||
* @since v3.0
|
* @since v3.0
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE static bool ccIsGZipBuffer(const unsigned char *buffer, long len) { return isGZipBuffer(buffer, len); }
|
CC_DEPRECATED_ATTRIBUTE static bool ccIsGZipBuffer(const unsigned char *buffer, ssize_t len) { return isGZipBuffer(buffer, len); }
|
||||||
static bool isGZipBuffer(const unsigned char *buffer, long len);
|
static bool isGZipBuffer(const unsigned char *buffer, ssize_t len);
|
||||||
|
|
||||||
/** inflates a CCZ file into memory
|
/** inflates a CCZ file into memory
|
||||||
*
|
*
|
||||||
|
@ -123,8 +123,8 @@ namespace cocos2d
|
||||||
*
|
*
|
||||||
* @since v3.0
|
* @since v3.0
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE static int ccInflateCCZBuffer(const unsigned char *buffer, long len, unsigned char **out) { return inflateCCZBuffer(buffer, len, out); }
|
CC_DEPRECATED_ATTRIBUTE static int ccInflateCCZBuffer(const unsigned char *buffer, ssize_t len, unsigned char **out) { return inflateCCZBuffer(buffer, len, out); }
|
||||||
static int inflateCCZBuffer(const unsigned char *buffer, long len, unsigned char **out);
|
static int inflateCCZBuffer(const unsigned char *buffer, ssize_t len, unsigned char **out);
|
||||||
|
|
||||||
/** test a file is a CCZ format file or not
|
/** test a file is a CCZ format file or not
|
||||||
*
|
*
|
||||||
|
@ -141,8 +141,8 @@ namespace cocos2d
|
||||||
*
|
*
|
||||||
* @since v3.0
|
* @since v3.0
|
||||||
*/
|
*/
|
||||||
CC_DEPRECATED_ATTRIBUTE static bool ccIsCCZBuffer(const unsigned char *buffer, long len) { return isCCZBuffer(buffer, len); }
|
CC_DEPRECATED_ATTRIBUTE static bool ccIsCCZBuffer(const unsigned char *buffer, ssize_t len) { return isCCZBuffer(buffer, len); }
|
||||||
static bool isCCZBuffer(const unsigned char *buffer, long len);
|
static bool isCCZBuffer(const unsigned char *buffer, ssize_t len);
|
||||||
|
|
||||||
/** Sets the pvr.ccz encryption key parts separately for added
|
/** Sets the pvr.ccz encryption key parts separately for added
|
||||||
* security.
|
* security.
|
||||||
|
@ -199,9 +199,9 @@ namespace cocos2d
|
||||||
static void setPvrEncryptionKey(unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3, unsigned int keyPart4);
|
static void setPvrEncryptionKey(unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3, unsigned int keyPart4);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int inflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long *outLength, long outLenghtHint);
|
static int inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t *outLength, ssize_t outLenghtHint);
|
||||||
static inline void decodeEncodedPvr (unsigned int *data, long len);
|
static inline void decodeEncodedPvr (unsigned int *data, ssize_t len);
|
||||||
static inline unsigned int checksumPvr(const unsigned int *data, long len);
|
static inline unsigned int checksumPvr(const unsigned int *data, ssize_t len);
|
||||||
|
|
||||||
static unsigned int s_uEncryptedPvrKeyParts[4];
|
static unsigned int s_uEncryptedPvrKeyParts[4];
|
||||||
static unsigned int s_uEncryptionKey[1024];
|
static unsigned int s_uEncryptionKey[1024];
|
||||||
|
@ -264,7 +264,7 @@ namespace cocos2d
|
||||||
*
|
*
|
||||||
* @since v2.0.5
|
* @since v2.0.5
|
||||||
*/
|
*/
|
||||||
unsigned char *getFileData(const std::string &fileName, long *size);
|
unsigned char *getFileData(const std::string &fileName, ssize_t *size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Internal data like zip file pointer / file list array and so on */
|
/** Internal data like zip file pointer / file list array and so on */
|
||||||
|
|
|
@ -28,10 +28,10 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
const long CC_INVALID_INDEX = -1;
|
const int CC_INVALID_INDEX = -1;
|
||||||
|
|
||||||
/** Allocates and initializes a new array with specified capacity */
|
/** Allocates and initializes a new array with specified capacity */
|
||||||
ccArray* ccArrayNew(long capacity)
|
ccArray* ccArrayNew(int capacity)
|
||||||
{
|
{
|
||||||
if (capacity == 0)
|
if (capacity == 0)
|
||||||
capacity = 7;
|
capacity = 7;
|
||||||
|
@ -68,13 +68,13 @@ void ccArrayDoubleCapacity(ccArray *arr)
|
||||||
arr->arr = newArr;
|
arr->arr = newArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ccArrayEnsureExtraCapacity(ccArray *arr, long extra)
|
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra)
|
||||||
{
|
{
|
||||||
while (arr->max < arr->num + extra)
|
while (arr->max < arr->num + extra)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%lu] to [%lu].",
|
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
|
||||||
(long) arr->max,
|
arr->max,
|
||||||
(long) arr->max*2);
|
arr->max*2);
|
||||||
|
|
||||||
ccArrayDoubleCapacity(arr);
|
ccArrayDoubleCapacity(arr);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, long extra)
|
||||||
|
|
||||||
void ccArrayShrink(ccArray *arr)
|
void ccArrayShrink(ccArray *arr)
|
||||||
{
|
{
|
||||||
long newSize = 0;
|
int newSize = 0;
|
||||||
|
|
||||||
//only resize when necessary
|
//only resize when necessary
|
||||||
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
|
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
|
||||||
|
@ -104,11 +104,11 @@ void ccArrayShrink(ccArray *arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */
|
/** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */
|
||||||
long ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
int ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
||||||
{
|
{
|
||||||
const long arrNum = arr->num;
|
const auto arrNum = arr->num;
|
||||||
Object** ptr = arr->arr;
|
Object** ptr = arr->arr;
|
||||||
for(long i = 0; i < arrNum; ++i, ++ptr)
|
for (int i = 0; i < arrNum; ++i, ++ptr)
|
||||||
{
|
{
|
||||||
if (*ptr == object)
|
if (*ptr == object)
|
||||||
return i;
|
return i;
|
||||||
|
@ -143,7 +143,7 @@ void ccArrayAppendObjectWithResize(ccArray *arr, Object* object)
|
||||||
enough capacity. */
|
enough capacity. */
|
||||||
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
|
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
|
||||||
{
|
{
|
||||||
for(long i = 0; i < plusArr->num; i++)
|
for (int i = 0; i < plusArr->num; i++)
|
||||||
{
|
{
|
||||||
ccArrayAppendObject(arr, plusArr->arr[i]);
|
ccArrayAppendObject(arr, plusArr->arr[i]);
|
||||||
}
|
}
|
||||||
|
@ -157,14 +157,14 @@ void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts an object at index */
|
/** Inserts an object at index */
|
||||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, long index)
|
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index)
|
||||||
{
|
{
|
||||||
CCASSERT(index<=arr->num, "Invalid index. Out of bounds");
|
CCASSERT(index<=arr->num, "Invalid index. Out of bounds");
|
||||||
CCASSERT(object != NULL, "Invalid parameter!");
|
CCASSERT(object != NULL, "Invalid parameter!");
|
||||||
|
|
||||||
ccArrayEnsureExtraCapacity(arr, 1);
|
ccArrayEnsureExtraCapacity(arr, 1);
|
||||||
|
|
||||||
long remaining = arr->num - index;
|
int remaining = arr->num - index;
|
||||||
if (remaining > 0)
|
if (remaining > 0)
|
||||||
{
|
{
|
||||||
memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Object*) * remaining );
|
memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Object*) * remaining );
|
||||||
|
@ -176,7 +176,7 @@ void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, long index)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Swaps two objects */
|
/** Swaps two objects */
|
||||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, long index1, long index2)
|
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2)
|
||||||
{
|
{
|
||||||
CCASSERT(index1>=0 && index1 < arr->num, "(1) Invalid index. Out of bounds");
|
CCASSERT(index1>=0 && index1 < arr->num, "(1) Invalid index. Out of bounds");
|
||||||
CCASSERT(index2>=0 && index2 < arr->num, "(2) Invalid index. Out of bounds");
|
CCASSERT(index2>=0 && index2 < arr->num, "(2) Invalid index. Out of bounds");
|
||||||
|
@ -198,7 +198,7 @@ void ccArrayRemoveAllObjects(ccArray *arr)
|
||||||
|
|
||||||
/** Removes object at specified index and pushes back all subsequent objects.
|
/** Removes object at specified index and pushes back all subsequent objects.
|
||||||
Behavior undefined if index outside [0, num-1]. */
|
Behavior undefined if index outside [0, num-1]. */
|
||||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj/* = true*/)
|
void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj/* = true*/)
|
||||||
{
|
{
|
||||||
CCASSERT(arr && arr->num > 0 && index>=0 && index < arr->num, "Invalid index. Out of bounds");
|
CCASSERT(arr && arr->num > 0 && index>=0 && index < arr->num, "Invalid index. Out of bounds");
|
||||||
if (bReleaseObj)
|
if (bReleaseObj)
|
||||||
|
@ -208,7 +208,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj/* = t
|
||||||
|
|
||||||
arr->num--;
|
arr->num--;
|
||||||
|
|
||||||
long remaining = arr->num - index;
|
int remaining = arr->num - index;
|
||||||
if(remaining>0)
|
if(remaining>0)
|
||||||
{
|
{
|
||||||
memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Object*));
|
memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Object*));
|
||||||
|
@ -218,16 +218,16 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj/* = t
|
||||||
/** Removes object at specified index and fills the gap with the last object,
|
/** Removes object at specified index and fills the gap with the last object,
|
||||||
thereby avoiding the need to push back subsequent objects.
|
thereby avoiding the need to push back subsequent objects.
|
||||||
Behavior undefined if index outside [0, num-1]. */
|
Behavior undefined if index outside [0, num-1]. */
|
||||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, long index)
|
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, int index)
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(arr->arr[index]);
|
CC_SAFE_RELEASE(arr->arr[index]);
|
||||||
long last = --arr->num;
|
auto last = --arr->num;
|
||||||
arr->arr[index] = arr->arr[last];
|
arr->arr[index] = arr->arr[last];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
||||||
{
|
{
|
||||||
long index = ccArrayGetIndexOfObject(arr, object);
|
auto index = ccArrayGetIndexOfObject(arr, object);
|
||||||
if (index != CC_INVALID_INDEX)
|
if (index != CC_INVALID_INDEX)
|
||||||
{
|
{
|
||||||
ccArrayFastRemoveObjectAtIndex(arr, index);
|
ccArrayFastRemoveObjectAtIndex(arr, index);
|
||||||
|
@ -238,7 +238,7 @@ void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
||||||
found the function has no effect. */
|
found the function has no effect. */
|
||||||
void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true*/)
|
void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true*/)
|
||||||
{
|
{
|
||||||
long index = ccArrayGetIndexOfObject(arr, object);
|
auto index = ccArrayGetIndexOfObject(arr, object);
|
||||||
if (index != CC_INVALID_INDEX)
|
if (index != CC_INVALID_INDEX)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObjectAtIndex(arr, index, bReleaseObj);
|
ccArrayRemoveObjectAtIndex(arr, index, bReleaseObj);
|
||||||
|
@ -249,7 +249,7 @@ void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true
|
||||||
first matching instance in arr will be removed. */
|
first matching instance in arr will be removed. */
|
||||||
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
for(long i = 0; i < minusArr->num; i++)
|
for (int i = 0; i < minusArr->num; i++)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
||||||
}
|
}
|
||||||
|
@ -259,10 +259,9 @@ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
matching instances in arr will be removed. */
|
matching instances in arr will be removed. */
|
||||||
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
long back = 0;
|
int back = 0;
|
||||||
long i = 0;
|
|
||||||
|
|
||||||
for( i = 0; i < arr->num; i++)
|
for (int i = 0; i < arr->num; i++)
|
||||||
{
|
{
|
||||||
if (ccArrayContainsObject(minusArr, arr->arr[i]))
|
if (ccArrayContainsObject(minusArr, arr->arr[i]))
|
||||||
{
|
{
|
||||||
|
@ -282,7 +281,7 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
// #pragma mark ccCArray for Values (c structures)
|
// #pragma mark ccCArray for Values (c structures)
|
||||||
|
|
||||||
/** Allocates and initializes a new C array with specified capacity */
|
/** Allocates and initializes a new C array with specified capacity */
|
||||||
ccCArray* ccCArrayNew(long capacity)
|
ccCArray* ccCArrayNew(int capacity)
|
||||||
{
|
{
|
||||||
if (capacity == 0)
|
if (capacity == 0)
|
||||||
{
|
{
|
||||||
|
@ -317,15 +316,15 @@ void ccCArrayDoubleCapacity(ccCArray *arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Increases array capacity such that max >= num + extra. */
|
/** Increases array capacity such that max >= num + extra. */
|
||||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, long extra)
|
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra)
|
||||||
{
|
{
|
||||||
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
|
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns index of first occurrence of value, CC_INVALID_INDEX if value not found. */
|
/** Returns index of first occurrence of value, CC_INVALID_INDEX if value not found. */
|
||||||
long ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
|
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
|
||||||
{
|
{
|
||||||
for(long i = 0; i < arr->num; i++)
|
for(int i = 0; i < arr->num; i++)
|
||||||
{
|
{
|
||||||
if( arr->arr[i] == value )
|
if( arr->arr[i] == value )
|
||||||
return i;
|
return i;
|
||||||
|
@ -340,11 +339,11 @@ bool ccCArrayContainsValue(ccCArray *arr, void* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
||||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, long index)
|
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, int index)
|
||||||
{
|
{
|
||||||
CCASSERT( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
|
CCASSERT( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
|
||||||
|
|
||||||
long remaining = arr->num - index;
|
auto remaining = arr->num - index;
|
||||||
// make sure it has enough capacity
|
// make sure it has enough capacity
|
||||||
if (arr->num + 1 == arr->max)
|
if (arr->num + 1 == arr->max)
|
||||||
{
|
{
|
||||||
|
@ -385,7 +384,7 @@ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value)
|
||||||
enough capacity. */
|
enough capacity. */
|
||||||
void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr)
|
void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr)
|
||||||
{
|
{
|
||||||
for( long i = 0; i < plusArr->num; i++)
|
for( int i = 0; i < plusArr->num; i++)
|
||||||
{
|
{
|
||||||
ccCArrayAppendValue(arr, plusArr->arr[i]);
|
ccCArrayAppendValue(arr, plusArr->arr[i]);
|
||||||
}
|
}
|
||||||
|
@ -408,9 +407,9 @@ void ccCArrayRemoveAllValues(ccCArray *arr)
|
||||||
Behavior undefined if index outside [0, num-1].
|
Behavior undefined if index outside [0, num-1].
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
*/
|
*/
|
||||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, long index)
|
void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index)
|
||||||
{
|
{
|
||||||
for( long last = --arr->num; index < last; index++)
|
for( int last = --arr->num; index < last; index++)
|
||||||
{
|
{
|
||||||
arr->arr[index] = arr->arr[index + 1];
|
arr->arr[index] = arr->arr[index + 1];
|
||||||
}
|
}
|
||||||
|
@ -421,9 +420,9 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, long index)
|
||||||
Behavior undefined if index outside [0, num-1].
|
Behavior undefined if index outside [0, num-1].
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
*/
|
*/
|
||||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, long index)
|
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, int index)
|
||||||
{
|
{
|
||||||
long last = --arr->num;
|
auto last = --arr->num;
|
||||||
arr->arr[index] = arr->arr[last];
|
arr->arr[index] = arr->arr[last];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,7 +431,7 @@ void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, long index)
|
||||||
*/
|
*/
|
||||||
void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
||||||
{
|
{
|
||||||
long index = ccCArrayGetIndexOfValue(arr, value);
|
auto index = ccCArrayGetIndexOfValue(arr, value);
|
||||||
if (index != CC_INVALID_INDEX)
|
if (index != CC_INVALID_INDEX)
|
||||||
{
|
{
|
||||||
ccCArrayRemoveValueAtIndex(arr, index);
|
ccCArrayRemoveValueAtIndex(arr, index);
|
||||||
|
@ -444,7 +443,7 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
||||||
*/
|
*/
|
||||||
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||||
{
|
{
|
||||||
for(long i = 0; i < minusArr->num; i++)
|
for(int i = 0; i < minusArr->num; i++)
|
||||||
{
|
{
|
||||||
ccCArrayRemoveValue(arr, minusArr->arr[i]);
|
ccCArrayRemoveValue(arr, minusArr->arr[i]);
|
||||||
}
|
}
|
||||||
|
@ -455,9 +454,9 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||||
*/
|
*/
|
||||||
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||||
{
|
{
|
||||||
long back = 0;
|
int back = 0;
|
||||||
|
|
||||||
for(long i = 0; i < arr->num; i++)
|
for(int i = 0; i < arr->num; i++)
|
||||||
{
|
{
|
||||||
if( ccCArrayContainsValue(minusArr, arr->arr[i]) )
|
if( ccCArrayContainsValue(minusArr, arr->arr[i]) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,20 +51,20 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
extern const long CC_INVALID_INDEX;
|
extern const int CC_INVALID_INDEX;
|
||||||
|
|
||||||
// Easy integration
|
// Easy integration
|
||||||
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
||||||
__object__=__array__->arr[0]; for(long i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
|
__object__=__array__->arr[0]; for(int i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
|
||||||
|
|
||||||
|
|
||||||
typedef struct _ccArray {
|
typedef struct _ccArray {
|
||||||
long num, max;
|
int num, max;
|
||||||
Object** arr;
|
Object** arr;
|
||||||
} ccArray;
|
} ccArray;
|
||||||
|
|
||||||
/** Allocates and initializes a new array with specified capacity */
|
/** Allocates and initializes a new array with specified capacity */
|
||||||
ccArray* ccArrayNew(long capacity);
|
ccArray* ccArrayNew(int capacity);
|
||||||
|
|
||||||
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
|
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
|
||||||
void ccArrayFree(ccArray*& arr);
|
void ccArrayFree(ccArray*& arr);
|
||||||
|
@ -73,13 +73,13 @@ void ccArrayFree(ccArray*& arr);
|
||||||
void ccArrayDoubleCapacity(ccArray *arr);
|
void ccArrayDoubleCapacity(ccArray *arr);
|
||||||
|
|
||||||
/** Increases array capacity such that max >= num + extra. */
|
/** Increases array capacity such that max >= num + extra. */
|
||||||
void ccArrayEnsureExtraCapacity(ccArray *arr, long extra);
|
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra);
|
||||||
|
|
||||||
/** shrinks the array so the memory footprint corresponds with the number of items */
|
/** shrinks the array so the memory footprint corresponds with the number of items */
|
||||||
void ccArrayShrink(ccArray *arr);
|
void ccArrayShrink(ccArray *arr);
|
||||||
|
|
||||||
/** Returns index of first occurrence of object, NSNotFound if object not found. */
|
/** Returns index of first occurrence of object, NSNotFound if object not found. */
|
||||||
long ccArrayGetIndexOfObject(ccArray *arr, Object* object);
|
int ccArrayGetIndexOfObject(ccArray *arr, Object* object);
|
||||||
|
|
||||||
/** Returns a Boolean value that indicates whether object is present in array. */
|
/** Returns a Boolean value that indicates whether object is present in array. */
|
||||||
bool ccArrayContainsObject(ccArray *arr, Object* object);
|
bool ccArrayContainsObject(ccArray *arr, Object* object);
|
||||||
|
@ -98,22 +98,22 @@ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr);
|
||||||
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr);
|
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr);
|
||||||
|
|
||||||
/** Inserts an object at index */
|
/** Inserts an object at index */
|
||||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, long index);
|
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index);
|
||||||
|
|
||||||
/** Swaps two objects */
|
/** Swaps two objects */
|
||||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, long index1, long index2);
|
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2);
|
||||||
|
|
||||||
/** Removes all objects from arr */
|
/** Removes all objects from arr */
|
||||||
void ccArrayRemoveAllObjects(ccArray *arr);
|
void ccArrayRemoveAllObjects(ccArray *arr);
|
||||||
|
|
||||||
/** Removes object at specified index and pushes back all subsequent objects.
|
/** Removes object at specified index and pushes back all subsequent objects.
|
||||||
Behavior undefined if index outside [0, num-1]. */
|
Behavior undefined if index outside [0, num-1]. */
|
||||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj = true);
|
void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj = true);
|
||||||
|
|
||||||
/** Removes object at specified index and fills the gap with the last object,
|
/** Removes object at specified index and fills the gap with the last object,
|
||||||
thereby avoiding the need to push back subsequent objects.
|
thereby avoiding the need to push back subsequent objects.
|
||||||
Behavior undefined if index outside [0, num-1]. */
|
Behavior undefined if index outside [0, num-1]. */
|
||||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, long index);
|
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, int index);
|
||||||
|
|
||||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object);
|
void ccArrayFastRemoveObject(ccArray *arr, Object* object);
|
||||||
|
|
||||||
|
@ -133,12 +133,12 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr);
|
||||||
// #pragma mark ccCArray for Values (c structures)
|
// #pragma mark ccCArray for Values (c structures)
|
||||||
|
|
||||||
typedef struct _ccCArray {
|
typedef struct _ccCArray {
|
||||||
long num, max;
|
int num, max;
|
||||||
void** arr;
|
void** arr;
|
||||||
} ccCArray;
|
} ccCArray;
|
||||||
|
|
||||||
/** Allocates and initializes a new C array with specified capacity */
|
/** Allocates and initializes a new C array with specified capacity */
|
||||||
ccCArray* ccCArrayNew(long capacity);
|
ccCArray* ccCArrayNew(int capacity);
|
||||||
|
|
||||||
/** Frees C array after removing all remaining values. Silently ignores nil arr. */
|
/** Frees C array after removing all remaining values. Silently ignores nil arr. */
|
||||||
void ccCArrayFree(ccCArray *arr);
|
void ccCArrayFree(ccCArray *arr);
|
||||||
|
@ -147,16 +147,16 @@ void ccCArrayFree(ccCArray *arr);
|
||||||
void ccCArrayDoubleCapacity(ccCArray *arr);
|
void ccCArrayDoubleCapacity(ccCArray *arr);
|
||||||
|
|
||||||
/** Increases array capacity such that max >= num + extra. */
|
/** Increases array capacity such that max >= num + extra. */
|
||||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, long extra);
|
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra);
|
||||||
|
|
||||||
/** Returns index of first occurrence of value, NSNotFound if value not found. */
|
/** Returns index of first occurrence of value, NSNotFound if value not found. */
|
||||||
long ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
|
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
|
||||||
|
|
||||||
/** Returns a Boolean value that indicates whether value is present in the C array. */
|
/** Returns a Boolean value that indicates whether value is present in the C array. */
|
||||||
bool ccCArrayContainsValue(ccCArray *arr, void* value);
|
bool ccCArrayContainsValue(ccCArray *arr, void* value);
|
||||||
|
|
||||||
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
||||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, long index);
|
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, int index);
|
||||||
|
|
||||||
/** Appends an value. Behavior undefined if array doesn't have enough capacity. */
|
/** Appends an value. Behavior undefined if array doesn't have enough capacity. */
|
||||||
void ccCArrayAppendValue(ccCArray *arr, void* value);
|
void ccCArrayAppendValue(ccCArray *arr, void* value);
|
||||||
|
@ -178,14 +178,14 @@ void ccCArrayRemoveAllValues(ccCArray *arr);
|
||||||
Behavior undefined if index outside [0, num-1].
|
Behavior undefined if index outside [0, num-1].
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
*/
|
*/
|
||||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, long index);
|
void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index);
|
||||||
|
|
||||||
/** Removes value at specified index and fills the gap with the last value,
|
/** Removes value at specified index and fills the gap with the last value,
|
||||||
thereby avoiding the need to push back subsequent values.
|
thereby avoiding the need to push back subsequent values.
|
||||||
Behavior undefined if index outside [0, num-1].
|
Behavior undefined if index outside [0, num-1].
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
*/
|
*/
|
||||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, long index);
|
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, int index);
|
||||||
|
|
||||||
/** Searches for the first occurrence of value and removes it. If value is not found the function has no effect.
|
/** Searches for the first occurrence of value and removes it. If value is not found the function has no effect.
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
|
|
|
@ -266,4 +266,9 @@ To enable set it to a value different than 0. Disabled by default.
|
||||||
#define CC_LUA_ENGINE_DEBUG 0
|
#define CC_LUA_ENGINE_DEBUG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Use physics integration API */
|
||||||
|
#ifndef CC_USE_PHYSICS
|
||||||
|
#define CC_USE_PHYSICS
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // __CCCONFIG_H__
|
#endif // __CCCONFIG_H__
|
||||||
|
|
|
@ -129,7 +129,7 @@ static const char *const g_utf8_skip = utf8_skip_data;
|
||||||
* */
|
* */
|
||||||
unsigned int cc_utf8_find_last_not_char(std::vector<unsigned short> str, unsigned short c)
|
unsigned int cc_utf8_find_last_not_char(std::vector<unsigned short> str, unsigned short c)
|
||||||
{
|
{
|
||||||
int len = str.size();
|
int len = static_cast<int>(str.size());
|
||||||
|
|
||||||
int i = len - 1;
|
int i = len - 1;
|
||||||
for (; i >= 0; --i)
|
for (; i >= 0; --i)
|
||||||
|
@ -148,7 +148,7 @@ unsigned int cc_utf8_find_last_not_char(std::vector<unsigned short> str, unsigne
|
||||||
* */
|
* */
|
||||||
static void cc_utf8_trim_from(std::vector<unsigned short>* str, int index)
|
static void cc_utf8_trim_from(std::vector<unsigned short>* str, int index)
|
||||||
{
|
{
|
||||||
int size = str->size();
|
int size = static_cast<int>(str->size());
|
||||||
if (index >= size || index < 0)
|
if (index >= size || index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ bool isspace_unicode(unsigned short ch)
|
||||||
|
|
||||||
void cc_utf8_trim_ws(std::vector<unsigned short>* str)
|
void cc_utf8_trim_ws(std::vector<unsigned short>* str)
|
||||||
{
|
{
|
||||||
int len = str->size();
|
int len = static_cast<int>(str->size());
|
||||||
|
|
||||||
if ( len <= 0 )
|
if ( len <= 0 )
|
||||||
return;
|
return;
|
||||||
|
@ -277,7 +277,7 @@ cc_utf8_get_char (const char * p)
|
||||||
|
|
||||||
unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1 */, int* rUtf16Size/* = NULL */)
|
unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1 */, int* rUtf16Size/* = NULL */)
|
||||||
{
|
{
|
||||||
int len = cc_utf8_strlen(str_old, length);
|
unsigned short len = cc_utf8_strlen(str_old, length);
|
||||||
if (rUtf16Size != NULL) {
|
if (rUtf16Size != NULL) {
|
||||||
*rUtf16Size = len;
|
*rUtf16Size = len;
|
||||||
}
|
}
|
||||||
|
@ -335,21 +335,23 @@ cc_unichar_to_utf8 (unsigned short c,
|
||||||
first = 0xc0;
|
first = 0xc0;
|
||||||
len = 2;
|
len = 2;
|
||||||
}
|
}
|
||||||
else if (c < 0x10000)
|
// XXX FIXME
|
||||||
{
|
// These conditions are alwasy true.
|
||||||
first = 0xe0;
|
// else if (c < 0x10000)
|
||||||
len = 3;
|
// {
|
||||||
}
|
// first = 0xe0;
|
||||||
else if (c < 0x200000)
|
// len = 3;
|
||||||
{
|
// }
|
||||||
first = 0xf0;
|
// else if (c < 0x200000)
|
||||||
len = 4;
|
// {
|
||||||
}
|
// first = 0xf0;
|
||||||
else if (c < 0x4000000)
|
// len = 4;
|
||||||
{
|
// }
|
||||||
first = 0xf8;
|
// else if (c < 0x4000000)
|
||||||
len = 5;
|
// {
|
||||||
}
|
// first = 0xf8;
|
||||||
|
// len = 5;
|
||||||
|
// }
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
first = 0xfc;
|
first = 0xfc;
|
||||||
|
@ -452,7 +454,7 @@ cc_utf16_to_utf8 (const unsigned short *str,
|
||||||
}
|
}
|
||||||
|
|
||||||
/********** DIFFERENT for UTF8/UCS4 **********/
|
/********** DIFFERENT for UTF8/UCS4 **********/
|
||||||
n_bytes += UTF8_LENGTH (wc);
|
n_bytes += UTF8_LENGTH (static_cast<unsigned int>(wc));
|
||||||
|
|
||||||
next1:
|
next1:
|
||||||
in++;
|
in++;
|
||||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
unsigned long ccNextPOT(unsigned long x)
|
int ccNextPOT(int x)
|
||||||
{
|
{
|
||||||
x = x - 1;
|
x = x - 1;
|
||||||
x = x | (x >> 1);
|
x = x | (x >> 1);
|
||||||
|
|
|
@ -43,7 +43,7 @@ Examples:
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned long ccNextPOT( unsigned long value );
|
int ccNextPOT(int value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,8 @@ THE SOFTWARE.
|
||||||
#include "CCDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCArray.h"
|
#include "CCArray.h"
|
||||||
|
#include "CCVector.h"
|
||||||
|
#include "CCMap.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCSet.h"
|
#include "CCSet.h"
|
||||||
#include "CCAutoreleasePool.h"
|
#include "CCAutoreleasePool.h"
|
||||||
|
@ -70,6 +72,7 @@ THE SOFTWARE.
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
#include "CCNS.h"
|
#include "CCNS.h"
|
||||||
#include "CCData.h"
|
#include "CCData.h"
|
||||||
|
#include "CCValue.h"
|
||||||
|
|
||||||
// draw nodes
|
// draw nodes
|
||||||
#include "CCDrawingPrimitives.h"
|
#include "CCDrawingPrimitives.h"
|
||||||
|
@ -199,6 +202,7 @@ THE SOFTWARE.
|
||||||
#include "ccUTF8.h"
|
#include "ccUTF8.h"
|
||||||
#include "CCNotificationCenter.h"
|
#include "CCNotificationCenter.h"
|
||||||
#include "CCProfiling.h"
|
#include "CCProfiling.h"
|
||||||
|
#include "CCConsole.h"
|
||||||
#include "CCUserDefault.h"
|
#include "CCUserDefault.h"
|
||||||
#include "CCVertex.h"
|
#include "CCVertex.h"
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;CC_USE_PHYSICS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
|
@ -121,7 +121,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;CC_USE_PHYSICS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
|
@ -169,6 +169,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
||||||
<ClCompile Include="..\base\CCAffineTransform.cpp" />
|
<ClCompile Include="..\base\CCAffineTransform.cpp" />
|
||||||
<ClCompile Include="..\base\CCArray.cpp" />
|
<ClCompile Include="..\base\CCArray.cpp" />
|
||||||
<ClCompile Include="..\base\CCAutoreleasePool.cpp" />
|
<ClCompile Include="..\base\CCAutoreleasePool.cpp" />
|
||||||
|
<ClCompile Include="..\base\CCConsole.cpp" />
|
||||||
<ClCompile Include="..\base\CCData.cpp" />
|
<ClCompile Include="..\base\CCData.cpp" />
|
||||||
<ClCompile Include="..\base\CCDataVisitor.cpp" />
|
<ClCompile Include="..\base\CCDataVisitor.cpp" />
|
||||||
<ClCompile Include="..\base\CCDictionary.cpp" />
|
<ClCompile Include="..\base\CCDictionary.cpp" />
|
||||||
|
@ -177,6 +178,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
||||||
<ClCompile Include="..\base\CCObject.cpp" />
|
<ClCompile Include="..\base\CCObject.cpp" />
|
||||||
<ClCompile Include="..\base\CCSet.cpp" />
|
<ClCompile Include="..\base\CCSet.cpp" />
|
||||||
<ClCompile Include="..\base\CCString.cpp" />
|
<ClCompile Include="..\base\CCString.cpp" />
|
||||||
|
<ClCompile Include="..\base\CCValue.cpp" />
|
||||||
<ClCompile Include="..\base\etc1.cpp" />
|
<ClCompile Include="..\base\etc1.cpp" />
|
||||||
<ClCompile Include="..\base\s3tc.cpp" />
|
<ClCompile Include="..\base\s3tc.cpp" />
|
||||||
<ClCompile Include="..\math\kazmath\src\aabb.c" />
|
<ClCompile Include="..\math\kazmath\src\aabb.c" />
|
||||||
|
@ -327,6 +329,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
||||||
<ClInclude Include="..\base\CCArray.h" />
|
<ClInclude Include="..\base\CCArray.h" />
|
||||||
<ClInclude Include="..\base\CCAutoreleasePool.h" />
|
<ClInclude Include="..\base\CCAutoreleasePool.h" />
|
||||||
<ClInclude Include="..\base\CCBool.h" />
|
<ClInclude Include="..\base\CCBool.h" />
|
||||||
|
<ClInclude Include="..\base\CCConsole.h" />
|
||||||
<ClInclude Include="..\base\CCData.h" />
|
<ClInclude Include="..\base\CCData.h" />
|
||||||
<ClInclude Include="..\base\CCDataVisitor.h" />
|
<ClInclude Include="..\base\CCDataVisitor.h" />
|
||||||
<ClInclude Include="..\base\CCDictionary.h" />
|
<ClInclude Include="..\base\CCDictionary.h" />
|
||||||
|
@ -334,12 +337,15 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
||||||
<ClInclude Include="..\base\CCFloat.h" />
|
<ClInclude Include="..\base\CCFloat.h" />
|
||||||
<ClInclude Include="..\base\CCGeometry.h" />
|
<ClInclude Include="..\base\CCGeometry.h" />
|
||||||
<ClInclude Include="..\base\CCInteger.h" />
|
<ClInclude Include="..\base\CCInteger.h" />
|
||||||
|
<ClInclude Include="..\base\CCMap.h" />
|
||||||
<ClInclude Include="..\base\CCNS.h" />
|
<ClInclude Include="..\base\CCNS.h" />
|
||||||
<ClInclude Include="..\base\CCObject.h" />
|
<ClInclude Include="..\base\CCObject.h" />
|
||||||
<ClInclude Include="..\base\CCPlatformConfig.h" />
|
<ClInclude Include="..\base\CCPlatformConfig.h" />
|
||||||
<ClInclude Include="..\base\CCPlatformMacros.h" />
|
<ClInclude Include="..\base\CCPlatformMacros.h" />
|
||||||
<ClInclude Include="..\base\CCSet.h" />
|
<ClInclude Include="..\base\CCSet.h" />
|
||||||
<ClInclude Include="..\base\CCString.h" />
|
<ClInclude Include="..\base\CCString.h" />
|
||||||
|
<ClInclude Include="..\base\CCValue.h" />
|
||||||
|
<ClInclude Include="..\base\CCVector.h" />
|
||||||
<ClInclude Include="..\base\etc1.h" />
|
<ClInclude Include="..\base\etc1.h" />
|
||||||
<ClInclude Include="..\base\s3tc.h" />
|
<ClInclude Include="..\base\s3tc.h" />
|
||||||
<ClInclude Include="..\math\kazmath\include\kazmath\aabb.h" />
|
<ClInclude Include="..\math\kazmath\include\kazmath\aabb.h" />
|
||||||
|
|
|
@ -560,6 +560,12 @@
|
||||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp">
|
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp">
|
||||||
<Filter>physics\chipmunk</Filter>
|
<Filter>physics\chipmunk</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\base\CCConsole.cpp">
|
||||||
|
<Filter>base</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\base\CCValue.cpp">
|
||||||
|
<Filter>base</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
||||||
|
@ -1125,5 +1131,17 @@
|
||||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h">
|
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h">
|
||||||
<Filter>physics\chipmunk</Filter>
|
<Filter>physics\chipmunk</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\base\CCConsole.h">
|
||||||
|
<Filter>base</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\base\CCMap.h">
|
||||||
|
<Filter>base</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\base\CCValue.h">
|
||||||
|
<Filter>base</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\base\CCVector.h">
|
||||||
|
<Filter>base</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -7,7 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup>
|
<ItemDefinitionGroup>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>opengl32.lib;glew32.lib;libzlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;libwebp.lib;libiconv.lib;glfw3.lib;freetype250.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>opengl32.lib;glew32.lib;libzlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;libwebp.lib;libiconv.lib;glfw3.lib;freetype250.lib;winmm.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace {
|
||||||
static Touch* g_touches[EventTouch::MAX_TOUCHES] = { NULL };
|
static Touch* g_touches[EventTouch::MAX_TOUCHES] = { NULL };
|
||||||
static unsigned int g_indexBitsUsed = 0;
|
static unsigned int g_indexBitsUsed = 0;
|
||||||
// System touch pointer ID (It may not be ascending order number) <-> Ascending order number from 0
|
// System touch pointer ID (It may not be ascending order number) <-> Ascending order number from 0
|
||||||
static std::map<long, int> g_touchIdReorderMap;
|
static std::map<int, int> g_touchIdReorderMap;
|
||||||
|
|
||||||
static int getUnUsedIndex()
|
static int getUnUsedIndex()
|
||||||
{
|
{
|
||||||
|
@ -198,9 +198,9 @@ const std::string& EGLViewProtocol::getViewName() const
|
||||||
return _viewName;
|
return _viewName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesBegin(int num, long ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
long id = 0;
|
int id = 0;
|
||||||
float x = 0.0f;
|
float x = 0.0f;
|
||||||
float y = 0.0f;
|
float y = 0.0f;
|
||||||
int nUnusedIndex = 0;
|
int nUnusedIndex = 0;
|
||||||
|
@ -248,9 +248,9 @@ void EGLViewProtocol::handleTouchesBegin(int num, long ids[], float xs[], float
|
||||||
dispatcher->dispatchEvent(&touchEvent);
|
dispatcher->dispatchEvent(&touchEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesMove(int num, long ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
long id = 0;
|
int id = 0;
|
||||||
float x = 0.0f;
|
float x = 0.0f;
|
||||||
float y = 0.0f;
|
float y = 0.0f;
|
||||||
EventTouch touchEvent;
|
EventTouch touchEvent;
|
||||||
|
@ -280,7 +280,7 @@ void EGLViewProtocol::handleTouchesMove(int num, long ids[], float xs[], float y
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// It is error, should return.
|
// It is error, should return.
|
||||||
CCLOG("Moving touches with id: %ld error", id);
|
CCLOG("Moving touches with id: %d error", id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,9 +296,9 @@ void EGLViewProtocol::handleTouchesMove(int num, long ids[], float xs[], float y
|
||||||
dispatcher->dispatchEvent(&touchEvent);
|
dispatcher->dispatchEvent(&touchEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, long ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
long id = 0;
|
int id = 0;
|
||||||
float x = 0.0f;
|
float x = 0.0f;
|
||||||
float y = 0.0f;
|
float y = 0.0f;
|
||||||
EventTouch touchEvent;
|
EventTouch touchEvent;
|
||||||
|
@ -333,7 +333,7 @@ void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCLOG("Ending touches with id: %ld error", id);
|
CCLOG("Ending touches with id: %d error", id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,12 +356,12 @@ void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesEnd(int num, long ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesEnd(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
handleTouchesOfEndOrCancel(EventTouch::EventCode::ENDED, num, ids, xs, ys);
|
handleTouchesOfEndOrCancel(EventTouch::EventCode::ENDED, num, ids, xs, ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLViewProtocol::handleTouchesCancel(int num, long ids[], float xs[], float ys[])
|
void EGLViewProtocol::handleTouchesCancel(int num, int ids[], float xs[], float ys[])
|
||||||
{
|
{
|
||||||
handleTouchesOfEndOrCancel(EventTouch::EventCode::CANCELLED, num, ids, xs, ys);
|
handleTouchesOfEndOrCancel(EventTouch::EventCode::CANCELLED, num, ids, xs, ys);
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,10 +135,10 @@ public:
|
||||||
const std::string& getViewName() const;
|
const std::string& getViewName() const;
|
||||||
|
|
||||||
/** Touch events are handled by default; if you want to customize your handlers, please override these functions: */
|
/** Touch events are handled by default; if you want to customize your handlers, please override these functions: */
|
||||||
virtual void handleTouchesBegin(int num, long ids[], float xs[], float ys[]);
|
virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]);
|
||||||
virtual void handleTouchesMove(int num, long ids[], float xs[], float ys[]);
|
virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]);
|
||||||
virtual void handleTouchesEnd(int num, long ids[], float xs[], float ys[]);
|
virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]);
|
||||||
virtual void handleTouchesCancel(int num, long ids[], float xs[], float ys[]);
|
virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the opengl view port rectangle.
|
* Get the opengl view port rectangle.
|
||||||
|
@ -157,7 +157,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, long ids[], float xs[], float ys[]);
|
void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, int ids[], float xs[], float ys[]);
|
||||||
|
|
||||||
EGLTouchDelegate* _delegate;
|
EGLTouchDelegate* _delegate;
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,8 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
|
#include "ccMacros.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCDictionary.h"
|
|
||||||
#include "CCString.h"
|
|
||||||
#include "CCSAXParser.h"
|
#include "CCSAXParser.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
#include "unzip.h"
|
#include "unzip.h"
|
||||||
|
@ -59,26 +58,23 @@ class DictMaker : public SAXDelegator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SAXResult _resultType;
|
SAXResult _resultType;
|
||||||
Array* _rootArray;
|
ValueMap _rootDict;
|
||||||
Dictionary *_rootDict;
|
ValueVector _rootArray;
|
||||||
Dictionary *_curDict;
|
|
||||||
std::stack<Dictionary*> _dictStack;
|
|
||||||
std::string _curKey; ///< parsed key
|
std::string _curKey; ///< parsed key
|
||||||
std::string _curValue; // parsed value
|
std::string _curValue; // parsed value
|
||||||
SAXState _state;
|
SAXState _state;
|
||||||
Array* _array;
|
|
||||||
|
|
||||||
std::stack<Array*> _arrayStack;
|
ValueMap* _curDict;
|
||||||
|
ValueVector* _curArray;
|
||||||
|
|
||||||
|
std::stack<ValueMap*> _dictStack;
|
||||||
|
std::stack<ValueVector*> _arrayStack;
|
||||||
std::stack<SAXState> _stateStack;
|
std::stack<SAXState> _stateStack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DictMaker()
|
DictMaker()
|
||||||
: _resultType(SAX_RESULT_NONE),
|
: _resultType(SAX_RESULT_NONE)
|
||||||
_rootArray(NULL),
|
|
||||||
_rootDict(NULL),
|
|
||||||
_curDict(NULL),
|
|
||||||
_state(SAX_NONE),
|
|
||||||
_array(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,50 +82,42 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary* dictionaryWithContentsOfFile(const char *pFileName)
|
ValueMap dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
{
|
{
|
||||||
_resultType = SAX_RESULT_DICT;
|
_resultType = SAX_RESULT_DICT;
|
||||||
SAXParser parser;
|
SAXParser parser;
|
||||||
|
|
||||||
if (false == parser.init("UTF-8"))
|
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
parser.setDelegator(this);
|
parser.setDelegator(this);
|
||||||
|
|
||||||
parser.parse(pFileName);
|
parser.parse(pFileName);
|
||||||
return _rootDict;
|
return std::move(_rootDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array* arrayWithContentsOfFile(const char* pFileName)
|
ValueVector arrayWithContentsOfFile(const char* pFileName)
|
||||||
{
|
{
|
||||||
_resultType = SAX_RESULT_ARRAY;
|
_resultType = SAX_RESULT_ARRAY;
|
||||||
SAXParser parser;
|
SAXParser parser;
|
||||||
|
|
||||||
if (false == parser.init("UTF-8"))
|
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
parser.setDelegator(this);
|
parser.setDelegator(this);
|
||||||
|
|
||||||
parser.parse(pFileName);
|
parser.parse(pFileName);
|
||||||
return _array;
|
return std::move(_rootArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startElement(void *ctx, const char *name, const char **atts)
|
void startElement(void *ctx, const char *name, const char **atts)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(ctx);
|
CC_UNUSED_PARAM(ctx);
|
||||||
CC_UNUSED_PARAM(atts);
|
CC_UNUSED_PARAM(atts);
|
||||||
std::string sName((char*)name);
|
std::string sName(name);
|
||||||
if( sName == "dict" )
|
if( sName == "dict" )
|
||||||
{
|
{
|
||||||
_curDict = new Dictionary();
|
if(_resultType == SAX_RESULT_DICT && _rootDict.empty())
|
||||||
if(_resultType == SAX_RESULT_DICT && _rootDict == NULL)
|
|
||||||
{
|
{
|
||||||
// Because it will call _curDict->release() later, so retain here.
|
_curDict = &_rootDict;
|
||||||
_rootDict = _curDict;
|
|
||||||
_rootDict->retain();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_state = SAX_DICT;
|
_state = SAX_DICT;
|
||||||
|
|
||||||
SAXState preState = SAX_NONE;
|
SAXState preState = SAX_NONE;
|
||||||
|
@ -140,19 +128,19 @@ public:
|
||||||
|
|
||||||
if (SAX_ARRAY == preState)
|
if (SAX_ARRAY == preState)
|
||||||
{
|
{
|
||||||
// add the dictionary into the array
|
// add a new dictionary into the array
|
||||||
_array->addObject(_curDict);
|
_curArray->push_back(Value(ValueMap()));
|
||||||
|
_curDict = &(_curArray->rbegin())->asValueMap();
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == preState)
|
else if (SAX_DICT == preState)
|
||||||
{
|
{
|
||||||
// add the dictionary into the pre dictionary
|
// add a new dictionary into the pre dictionary
|
||||||
CCASSERT(! _dictStack.empty(), "The state is wrong!");
|
CCASSERT(! _dictStack.empty(), "The state is wrong!");
|
||||||
Dictionary* pPreDict = _dictStack.top();
|
ValueMap* preDict = _dictStack.top();
|
||||||
pPreDict->setObject(_curDict, _curKey.c_str());
|
(*preDict)[_curKey] = Value(ValueMap());
|
||||||
|
_curDict = &(*preDict)[_curKey].asValueMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
_curDict->release();
|
|
||||||
|
|
||||||
// record the dict state
|
// record the dict state
|
||||||
_stateStack.push(_state);
|
_stateStack.push(_state);
|
||||||
_dictStack.push(_curDict);
|
_dictStack.push(_curDict);
|
||||||
|
@ -176,12 +164,10 @@ public:
|
||||||
else if (sName == "array")
|
else if (sName == "array")
|
||||||
{
|
{
|
||||||
_state = SAX_ARRAY;
|
_state = SAX_ARRAY;
|
||||||
_array = new Array();
|
|
||||||
_array->init();
|
if (_resultType == SAX_RESULT_ARRAY && _rootArray.empty())
|
||||||
if (_resultType == SAX_RESULT_ARRAY && _rootArray == NULL)
|
|
||||||
{
|
{
|
||||||
_rootArray = _array;
|
_curArray = &_rootArray;
|
||||||
_rootArray->retain();
|
|
||||||
}
|
}
|
||||||
SAXState preState = SAX_NONE;
|
SAXState preState = SAX_NONE;
|
||||||
if (! _stateStack.empty())
|
if (! _stateStack.empty())
|
||||||
|
@ -191,18 +177,19 @@ public:
|
||||||
|
|
||||||
if (preState == SAX_DICT)
|
if (preState == SAX_DICT)
|
||||||
{
|
{
|
||||||
_curDict->setObject(_array, _curKey.c_str());
|
(*_curDict)[_curKey] = Value(ValueVector());
|
||||||
|
_curArray = &(*_curDict)[_curKey].asValueVector();
|
||||||
}
|
}
|
||||||
else if (preState == SAX_ARRAY)
|
else if (preState == SAX_ARRAY)
|
||||||
{
|
{
|
||||||
CCASSERT(! _arrayStack.empty(), "The state is wrong!");
|
CCASSERT(! _arrayStack.empty(), "The state is wrong!");
|
||||||
Array* pPreArray = _arrayStack.top();
|
ValueVector* preArray = _arrayStack.top();
|
||||||
pPreArray->addObject(_array);
|
preArray->push_back(Value(ValueVector()));
|
||||||
|
_curArray = &(_curArray->rbegin())->asValueVector();
|
||||||
}
|
}
|
||||||
_array->release();
|
|
||||||
// record the array state
|
// record the array state
|
||||||
_stateStack.push(_state);
|
_stateStack.push(_state);
|
||||||
_arrayStack.push(_array);
|
_arrayStack.push(_curArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -230,49 +217,52 @@ public:
|
||||||
_arrayStack.pop();
|
_arrayStack.pop();
|
||||||
if (! _arrayStack.empty())
|
if (! _arrayStack.empty())
|
||||||
{
|
{
|
||||||
_array = _arrayStack.top();
|
_curArray = _arrayStack.top();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sName == "true")
|
else if (sName == "true")
|
||||||
{
|
{
|
||||||
String *str = new String("1");
|
|
||||||
if (SAX_ARRAY == curState)
|
if (SAX_ARRAY == curState)
|
||||||
{
|
{
|
||||||
_array->addObject(str);
|
_curArray->push_back(Value(true));
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
_curDict->setObject(str, _curKey.c_str());
|
(*_curDict)[_curKey] = Value(true);
|
||||||
}
|
}
|
||||||
str->release();
|
|
||||||
}
|
}
|
||||||
else if (sName == "false")
|
else if (sName == "false")
|
||||||
{
|
{
|
||||||
String *str = new String("0");
|
|
||||||
if (SAX_ARRAY == curState)
|
if (SAX_ARRAY == curState)
|
||||||
{
|
{
|
||||||
_array->addObject(str);
|
_curArray->push_back(Value(false));
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
_curDict->setObject(str, _curKey.c_str());
|
(*_curDict)[_curKey] = Value(false);
|
||||||
}
|
}
|
||||||
str->release();
|
|
||||||
}
|
}
|
||||||
else if (sName == "string" || sName == "integer" || sName == "real")
|
else if (sName == "string" || sName == "integer" || sName == "real")
|
||||||
{
|
{
|
||||||
String* pStrValue = new String(_curValue);
|
|
||||||
|
|
||||||
if (SAX_ARRAY == curState)
|
if (SAX_ARRAY == curState)
|
||||||
{
|
{
|
||||||
_array->addObject(pStrValue);
|
if (sName == "string")
|
||||||
|
_curArray->push_back(Value(_curValue));
|
||||||
|
else if (sName == "integer")
|
||||||
|
_curArray->push_back(Value(atoi(_curValue.c_str())));
|
||||||
|
else
|
||||||
|
_curArray->push_back(Value(atof(_curValue.c_str())));
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
_curDict->setObject(pStrValue, _curKey.c_str());
|
if (sName == "string")
|
||||||
|
(*_curDict)[_curKey] = Value(_curValue);
|
||||||
|
else if (sName == "integer")
|
||||||
|
(*_curDict)[_curKey] = Value(atoi(_curValue.c_str()));
|
||||||
|
else
|
||||||
|
(*_curDict)[_curKey] = Value(atof(_curValue.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pStrValue->release();
|
|
||||||
_curValue.clear();
|
_curValue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,12 +278,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
SAXState curState = _stateStack.empty() ? SAX_DICT : _stateStack.top();
|
SAXState curState = _stateStack.empty() ? SAX_DICT : _stateStack.top();
|
||||||
String *pText = new String(std::string((char*)ch,0,len));
|
std::string text = std::string((char*)ch,0,len);
|
||||||
|
|
||||||
switch(_state)
|
switch(_state)
|
||||||
{
|
{
|
||||||
case SAX_KEY:
|
case SAX_KEY:
|
||||||
_curKey = pText->getCString();
|
_curKey = text;
|
||||||
break;
|
break;
|
||||||
case SAX_INT:
|
case SAX_INT:
|
||||||
case SAX_REAL:
|
case SAX_REAL:
|
||||||
|
@ -304,49 +294,48 @@ public:
|
||||||
CCASSERT(!_curKey.empty(), "key not found : <integer/real>");
|
CCASSERT(!_curKey.empty(), "key not found : <integer/real>");
|
||||||
}
|
}
|
||||||
|
|
||||||
_curValue.append(pText->getCString());
|
_curValue.append(text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pText->release();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Dictionary* FileUtils::createDictionaryWithContentsOfFile(const std::string& filename)
|
ValueMap FileUtils::getValueMapFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::string fullPath = fullPathForFilename(filename.c_str());
|
std::string fullPath = fullPathForFilename(filename.c_str());
|
||||||
DictMaker tMaker;
|
DictMaker tMaker;
|
||||||
return tMaker.dictionaryWithContentsOfFile(fullPath.c_str());
|
return std::move(tMaker.dictionaryWithContentsOfFile(fullPath.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Array* FileUtils::createArrayWithContentsOfFile(const std::string& filename)
|
ValueVector FileUtils::getValueVectorFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::string fullPath = fullPathForFilename(filename.c_str());
|
std::string fullPath = fullPathForFilename(filename.c_str());
|
||||||
DictMaker tMaker;
|
DictMaker tMaker;
|
||||||
return tMaker.arrayWithContentsOfFile(fullPath.c_str());
|
return std::move(tMaker.arrayWithContentsOfFile(fullPath.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* forward statement
|
* forward statement
|
||||||
*/
|
*/
|
||||||
static tinyxml2::XMLElement* generateElementForArray(cocos2d::Array *array, tinyxml2::XMLDocument *pDoc);
|
static tinyxml2::XMLElement* generateElementForArray(ValueVector& array, tinyxml2::XMLDocument *pDoc);
|
||||||
static tinyxml2::XMLElement* generateElementForDict(cocos2d::Dictionary *dict, tinyxml2::XMLDocument *pDoc);
|
static tinyxml2::XMLElement* generateElementForDict(ValueMap& dict, tinyxml2::XMLDocument *pDoc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use tinyxml2 to write plist files
|
* Use tinyxml2 to write plist files
|
||||||
*/
|
*/
|
||||||
bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPath)
|
bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath)
|
||||||
{
|
{
|
||||||
//CCLOG("tinyxml2 Dictionary %d writeToFile %s", dict->_ID, fullPath.c_str());
|
//CCLOG("tinyxml2 Dictionary %d writeToFile %s", dict->_ID, fullPath.c_str());
|
||||||
tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument();
|
tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument();
|
||||||
if (NULL == pDoc)
|
if (nullptr == pDoc)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tinyxml2::XMLDeclaration *pDeclaration = pDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\"");
|
tinyxml2::XMLDeclaration *pDeclaration = pDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\"");
|
||||||
if (NULL == pDeclaration)
|
if (nullptr == pDeclaration)
|
||||||
{
|
{
|
||||||
delete pDoc;
|
delete pDoc;
|
||||||
return false;
|
return false;
|
||||||
|
@ -358,7 +347,7 @@ bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPa
|
||||||
|
|
||||||
tinyxml2::XMLElement *pRootEle = pDoc->NewElement("plist");
|
tinyxml2::XMLElement *pRootEle = pDoc->NewElement("plist");
|
||||||
pRootEle->SetAttribute("version", "1.0");
|
pRootEle->SetAttribute("version", "1.0");
|
||||||
if (NULL == pRootEle)
|
if (nullptr == pRootEle)
|
||||||
{
|
{
|
||||||
delete pDoc;
|
delete pDoc;
|
||||||
return false;
|
return false;
|
||||||
|
@ -366,7 +355,7 @@ bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPa
|
||||||
pDoc->LinkEndChild(pRootEle);
|
pDoc->LinkEndChild(pRootEle);
|
||||||
|
|
||||||
tinyxml2::XMLElement *innerDict = generateElementForDict(dict, pDoc);
|
tinyxml2::XMLElement *innerDict = generateElementForDict(dict, pDoc);
|
||||||
if (NULL == innerDict )
|
if (nullptr == innerDict )
|
||||||
{
|
{
|
||||||
delete pDoc;
|
delete pDoc;
|
||||||
return false;
|
return false;
|
||||||
|
@ -382,46 +371,64 @@ bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPa
|
||||||
/*
|
/*
|
||||||
* Generate tinyxml2::XMLElement for Object through a tinyxml2::XMLDocument
|
* Generate tinyxml2::XMLElement for Object through a tinyxml2::XMLDocument
|
||||||
*/
|
*/
|
||||||
static tinyxml2::XMLElement* generateElementForObject(cocos2d::Object *object, tinyxml2::XMLDocument *pDoc)
|
static tinyxml2::XMLElement* generateElementForObject(Value& value, tinyxml2::XMLDocument *pDoc)
|
||||||
{
|
{
|
||||||
// object is String
|
// object is String
|
||||||
if (String *str = dynamic_cast<String *>(object))
|
if (value.getType() == Value::Type::STRING)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* node = pDoc->NewElement("string");
|
tinyxml2::XMLElement* node = pDoc->NewElement("string");
|
||||||
tinyxml2::XMLText* content = pDoc->NewText(str->getCString());
|
tinyxml2::XMLText* content = pDoc->NewText(value.asString().c_str());
|
||||||
node->LinkEndChild(content);
|
node->LinkEndChild(content);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// object is integer
|
||||||
|
if (value.getType() == Value::Type::INTEGER)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLElement* node = pDoc->NewElement("integer");
|
||||||
|
tinyxml2::XMLText* content = pDoc->NewText(value.asString().c_str());
|
||||||
|
node->LinkEndChild(content);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// object is real
|
||||||
|
if (value.getType() == Value::Type::FLOAT || value.getType() == Value::Type::DOUBLE)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLElement* node = pDoc->NewElement("real");
|
||||||
|
tinyxml2::XMLText* content = pDoc->NewText(value.asString().c_str());
|
||||||
|
node->LinkEndChild(content);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME:XXX How to deal with Boolean ??
|
||||||
|
|
||||||
// object is Array
|
// object is Array
|
||||||
if (Array *array = dynamic_cast<Array *>(object))
|
if (value.getType() == Value::Type::VECTOR)
|
||||||
return generateElementForArray(array, pDoc);
|
return generateElementForArray(value.asValueVector(), pDoc);
|
||||||
|
|
||||||
// object is Dictionary
|
// object is Dictionary
|
||||||
if (Dictionary *innerDict = dynamic_cast<Dictionary *>(object))
|
if (value.getType() == Value::Type::MAP)
|
||||||
return generateElementForDict(innerDict, pDoc);
|
return generateElementForDict(value.asValueMap(), pDoc);
|
||||||
|
|
||||||
CCLOG("This type cannot appear in property list");
|
CCLOG("This type cannot appear in property list");
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate tinyxml2::XMLElement for Dictionary through a tinyxml2::XMLDocument
|
* Generate tinyxml2::XMLElement for Dictionary through a tinyxml2::XMLDocument
|
||||||
*/
|
*/
|
||||||
static tinyxml2::XMLElement* generateElementForDict(cocos2d::Dictionary *dict, tinyxml2::XMLDocument *pDoc)
|
static tinyxml2::XMLElement* generateElementForDict(ValueMap& dict, tinyxml2::XMLDocument *pDoc)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* rootNode = pDoc->NewElement("dict");
|
tinyxml2::XMLElement* rootNode = pDoc->NewElement("dict");
|
||||||
|
|
||||||
DictElement *dictElement = NULL;
|
for (auto iter = dict.begin(); iter != dict.end(); ++iter)
|
||||||
CCDICT_FOREACH(dict, dictElement)
|
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* tmpNode = pDoc->NewElement("key");
|
tinyxml2::XMLElement* tmpNode = pDoc->NewElement("key");
|
||||||
rootNode->LinkEndChild(tmpNode);
|
rootNode->LinkEndChild(tmpNode);
|
||||||
tinyxml2::XMLText* content = pDoc->NewText(dictElement->getStrKey());
|
tinyxml2::XMLText* content = pDoc->NewText(iter->first.c_str());
|
||||||
tmpNode->LinkEndChild(content);
|
tmpNode->LinkEndChild(content);
|
||||||
|
|
||||||
Object *object = dictElement->getObject();
|
tinyxml2::XMLElement *element = generateElementForObject(iter->second, pDoc);
|
||||||
tinyxml2::XMLElement *element = generateElementForObject(object, pDoc);
|
|
||||||
if (element)
|
if (element)
|
||||||
rootNode->LinkEndChild(element);
|
rootNode->LinkEndChild(element);
|
||||||
}
|
}
|
||||||
|
@ -431,17 +438,16 @@ static tinyxml2::XMLElement* generateElementForDict(cocos2d::Dictionary *dict, t
|
||||||
/*
|
/*
|
||||||
* Generate tinyxml2::XMLElement for Array through a tinyxml2::XMLDocument
|
* Generate tinyxml2::XMLElement for Array through a tinyxml2::XMLDocument
|
||||||
*/
|
*/
|
||||||
static tinyxml2::XMLElement* generateElementForArray(cocos2d::Array *array, tinyxml2::XMLDocument *pDoc)
|
static tinyxml2::XMLElement* generateElementForArray(ValueVector& array, tinyxml2::XMLDocument *pDoc)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* rootNode = pDoc->NewElement("array");
|
tinyxml2::XMLElement* rootNode = pDoc->NewElement("array");
|
||||||
|
|
||||||
Object *object = NULL;
|
std::for_each(array.begin(), array.end(), [=](Value& value){
|
||||||
CCARRAY_FOREACH(array, object)
|
tinyxml2::XMLElement *element = generateElementForObject(value, pDoc);
|
||||||
{
|
|
||||||
tinyxml2::XMLElement *element = generateElementForObject(object, pDoc);
|
|
||||||
if (element)
|
if (element)
|
||||||
rootNode->LinkEndChild(element);
|
rootNode->LinkEndChild(element);
|
||||||
}
|
|
||||||
|
});
|
||||||
return rootNode;
|
return rootNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,14 +456,14 @@ static tinyxml2::XMLElement* generateElementForArray(cocos2d::Array *array, tiny
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/* The subclass FileUtilsApple should override these two method. */
|
/* The subclass FileUtilsApple should override these two method. */
|
||||||
Dictionary* FileUtils::createDictionaryWithContentsOfFile(const std::string& filename) {return NULL;}
|
ValueMap FileUtils::getValueMapFromFile(const std::string& filename) {return ValueMap();}
|
||||||
bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPath) {return false;}
|
ValueVector FileUtils::getValueVectorFromFile(const std::string& filename) {return ValueVector();}
|
||||||
Array* FileUtils::createArrayWithContentsOfFile(const std::string& filename) {return NULL;}
|
bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath) {return false;}
|
||||||
|
|
||||||
#endif /* (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) */
|
#endif /* (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) */
|
||||||
|
|
||||||
|
|
||||||
FileUtils* FileUtils::s_sharedFileUtils = NULL;
|
FileUtils* FileUtils::s_sharedFileUtils = nullptr;
|
||||||
|
|
||||||
|
|
||||||
void FileUtils::destroyInstance()
|
void FileUtils::destroyInstance()
|
||||||
|
@ -466,13 +472,11 @@ void FileUtils::destroyInstance()
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtils::FileUtils()
|
FileUtils::FileUtils()
|
||||||
: _filenameLookupDict(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtils::~FileUtils()
|
FileUtils::~FileUtils()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_filenameLookupDict);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -488,10 +492,10 @@ void FileUtils::purgeCachedEntries()
|
||||||
_fullPathCache.clear();
|
_fullPathCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* FileUtils::getFileData(const char* filename, const char* mode, long *size)
|
unsigned char* FileUtils::getFileData(const char* filename, const char* mode, ssize_t *size)
|
||||||
{
|
{
|
||||||
unsigned char * buffer = NULL;
|
unsigned char * buffer = nullptr;
|
||||||
CCASSERT(filename != NULL && size != NULL && mode != NULL, "Invalid parameters.");
|
CCASSERT(filename != nullptr && size != nullptr && mode != nullptr, "Invalid parameters.");
|
||||||
*size = 0;
|
*size = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -518,10 +522,10 @@ unsigned char* FileUtils::getFileData(const char* filename, const char* mode, lo
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, long *size)
|
unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, ssize_t *size)
|
||||||
{
|
{
|
||||||
unsigned char * buffer = NULL;
|
unsigned char * buffer = nullptr;
|
||||||
unzFile pFile = NULL;
|
unzFile pFile = nullptr;
|
||||||
*size = 0;
|
*size = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -537,14 +541,14 @@ unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char
|
||||||
|
|
||||||
char szFilePathA[260];
|
char szFilePathA[260];
|
||||||
unz_file_info FileInfo;
|
unz_file_info FileInfo;
|
||||||
nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0);
|
nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), nullptr, 0, nullptr, 0);
|
||||||
CC_BREAK_IF(UNZ_OK != nRet);
|
CC_BREAK_IF(UNZ_OK != nRet);
|
||||||
|
|
||||||
nRet = unzOpenCurrentFile(pFile);
|
nRet = unzOpenCurrentFile(pFile);
|
||||||
CC_BREAK_IF(UNZ_OK != nRet);
|
CC_BREAK_IF(UNZ_OK != nRet);
|
||||||
|
|
||||||
buffer = (unsigned char*)malloc(FileInfo.uncompressed_size);
|
buffer = (unsigned char*)malloc(FileInfo.uncompressed_size);
|
||||||
int CC_UNUSED nSize = unzReadCurrentFile(pFile, buffer, FileInfo.uncompressed_size);
|
int CC_UNUSED nSize = unzReadCurrentFile(pFile, buffer, static_cast<unsigned>(FileInfo.uncompressed_size));
|
||||||
CCASSERT(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong");
|
CCASSERT(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong");
|
||||||
|
|
||||||
*size = FileInfo.uncompressed_size;
|
*size = FileInfo.uncompressed_size;
|
||||||
|
@ -564,12 +568,15 @@ std::string FileUtils::getNewFilename(const std::string &filename)
|
||||||
std::string newFileName;
|
std::string newFileName;
|
||||||
|
|
||||||
// in Lookup Filename dictionary ?
|
// in Lookup Filename dictionary ?
|
||||||
String* fileNameFound = _filenameLookupDict ? (String*)_filenameLookupDict->objectForKey(filename) : NULL;
|
auto iter = _filenameLookupDict.find(filename);
|
||||||
if( NULL == fileNameFound || fileNameFound->length() == 0) {
|
|
||||||
|
if (iter == _filenameLookupDict.end())
|
||||||
|
{
|
||||||
newFileName = filename;
|
newFileName = filename;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
newFileName = fileNameFound->getCString();
|
{
|
||||||
|
newFileName = iter->second.asString();
|
||||||
}
|
}
|
||||||
return newFileName;
|
return newFileName;
|
||||||
}
|
}
|
||||||
|
@ -731,12 +738,10 @@ void FileUtils::addSearchPath(const std::string &searchpath)
|
||||||
_searchPathArray.push_back(path);
|
_searchPathArray.push_back(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileUtils::setFilenameLookupDictionary(Dictionary* pFilenameLookupDict)
|
void FileUtils::setFilenameLookupDictionary(const ValueMap& filenameLookupDict)
|
||||||
{
|
{
|
||||||
_fullPathCache.clear();
|
_fullPathCache.clear();
|
||||||
CC_SAFE_RELEASE(_filenameLookupDict);
|
_filenameLookupDict = filenameLookupDict;
|
||||||
_filenameLookupDict = pFilenameLookupDict;
|
|
||||||
CC_SAFE_RETAIN(_filenameLookupDict);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileUtils::loadFilenameLookupDictionaryFromFile(const std::string &filename)
|
void FileUtils::loadFilenameLookupDictionaryFromFile(const std::string &filename)
|
||||||
|
@ -744,17 +749,17 @@ void FileUtils::loadFilenameLookupDictionaryFromFile(const std::string &filename
|
||||||
std::string fullPath = fullPathForFilename(filename);
|
std::string fullPath = fullPathForFilename(filename);
|
||||||
if (fullPath.length() > 0)
|
if (fullPath.length() > 0)
|
||||||
{
|
{
|
||||||
Dictionary* dict = Dictionary::createWithContentsOfFile(fullPath.c_str());
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||||
if (dict)
|
if (!dict.empty())
|
||||||
{
|
{
|
||||||
Dictionary* metadata = static_cast<Dictionary*>( dict->objectForKey("metadata") );
|
ValueMap& metadata = dict["metadata"].asValueMap();
|
||||||
int version = static_cast<String*>( metadata->objectForKey("version"))->intValue();
|
int version = metadata["version"].asInt();
|
||||||
if (version != 1)
|
if (version != 1)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %s", (long)version, filename.c_str());
|
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %d. Filename: %s", version, filename.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setFilenameLookupDictionary( static_cast<Dictionary*>( dict->objectForKey("filenames")) );
|
setFilenameLookupDictionary( dict["filenames"].asValueMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,10 @@ THE SOFTWARE.
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "CCPlatformMacros.h"
|
#include "CCPlatformMacros.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
|
#include "CCValue.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class Dictionary;
|
|
||||||
class Array;
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup platform
|
* @addtogroup platform
|
||||||
* @{
|
* @{
|
||||||
|
@ -42,10 +41,7 @@ class Array;
|
||||||
//! @brief Helper class to handle file operations
|
//! @brief Helper class to handle file operations
|
||||||
class CC_DLL FileUtils
|
class CC_DLL FileUtils
|
||||||
{
|
{
|
||||||
friend class Array;
|
|
||||||
friend class Dictionary;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the instance of FileUtils.
|
* Gets the instance of FileUtils.
|
||||||
*/
|
*/
|
||||||
|
@ -88,7 +84,7 @@ public:
|
||||||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||||
* @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned.
|
* @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned.
|
||||||
*/
|
*/
|
||||||
virtual unsigned char* getFileData(const char* filename, const char* mode, long *size);
|
virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets resource file data from a zip file.
|
* Gets resource file data from a zip file.
|
||||||
|
@ -98,7 +94,7 @@ public:
|
||||||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||||
* @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned.
|
* @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned.
|
||||||
*/
|
*/
|
||||||
virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, long *size);
|
virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, ssize_t *size);
|
||||||
|
|
||||||
|
|
||||||
/** Returns the fullpath for a given filename.
|
/** Returns the fullpath for a given filename.
|
||||||
|
@ -189,7 +185,7 @@ public:
|
||||||
* @param pFilenameLookupDict The dictionary for replacing filename.
|
* @param pFilenameLookupDict The dictionary for replacing filename.
|
||||||
* @since v2.1
|
* @since v2.1
|
||||||
*/
|
*/
|
||||||
virtual void setFilenameLookupDictionary(Dictionary* filenameLookupDict);
|
virtual void setFilenameLookupDictionary(const ValueMap& filenameLookupDict);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets full path from a file name and the path of the reletive file.
|
* Gets full path from a file name and the path of the reletive file.
|
||||||
|
@ -300,6 +296,24 @@ public:
|
||||||
virtual void setPopupNotify(bool notify);
|
virtual void setPopupNotify(bool notify);
|
||||||
virtual bool isPopupNotify();
|
virtual bool isPopupNotify();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the contents of a file to a ValueMap.
|
||||||
|
* @note This method is used internally.
|
||||||
|
*/
|
||||||
|
virtual ValueMap getValueMapFromFile(const std::string& filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a ValueMap to a plist file.
|
||||||
|
* @note This method is used internally.
|
||||||
|
*/
|
||||||
|
virtual bool writeToFile(ValueMap& dict, const std::string& fullPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the contents of a file to a ValueVector.
|
||||||
|
* @note This method is used internally.
|
||||||
|
*/
|
||||||
|
virtual ValueVector getValueVectorFromFile(const std::string& filename);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* The default constructor.
|
* The default constructor.
|
||||||
|
@ -347,23 +361,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual std::string getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename);
|
virtual std::string getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a dictionary by the contents of a file.
|
|
||||||
* @note This method is used internally.
|
|
||||||
*/
|
|
||||||
virtual Dictionary* createDictionaryWithContentsOfFile(const std::string& filename);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a dictionary to a plist file.
|
|
||||||
* @note This method is used internally.
|
|
||||||
*/
|
|
||||||
virtual bool writeToFile(Dictionary *dict, const std::string& fullPath);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an array by the contents of a file.
|
|
||||||
* @note This method is used internally.
|
|
||||||
*/
|
|
||||||
virtual Array* createArrayWithContentsOfFile(const std::string& filename);
|
|
||||||
|
|
||||||
/** Dictionary used to lookup filenames based on a key.
|
/** Dictionary used to lookup filenames based on a key.
|
||||||
* It is used internally by the following methods:
|
* It is used internally by the following methods:
|
||||||
|
@ -372,7 +369,7 @@ protected:
|
||||||
*
|
*
|
||||||
* @since v2.1
|
* @since v2.1
|
||||||
*/
|
*/
|
||||||
Dictionary* _filenameLookupDict;
|
ValueMap _filenameLookupDict;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The vector contains resolution folders.
|
* The vector contains resolution folders.
|
||||||
|
|
|
@ -121,10 +121,10 @@ public:
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
bool initWithImageData(const unsigned char * data, long dataLen);
|
bool initWithImageData(const unsigned char * data, ssize_t dataLen);
|
||||||
|
|
||||||
// @warning kFmtRawData only support RGBA8888
|
// @warning kFmtRawData only support RGBA8888
|
||||||
bool initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti = false);
|
bool initWithRawData(const unsigned char * data, ssize_t dataLen, int width, int height, int bitsPerComponent, bool preMulti = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Create image with specified string.
|
@brief Create image with specified string.
|
||||||
|
@ -175,7 +175,7 @@ public:
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
inline unsigned char * getData() { return _data; }
|
inline unsigned char * getData() { return _data; }
|
||||||
inline int getDataLen() { return _dataLen; }
|
inline ssize_t getDataLen() { return _dataLen; }
|
||||||
inline Format getFileType() {return _fileType; }
|
inline Format getFileType() {return _fileType; }
|
||||||
inline Texture2D::PixelFormat getRenderFormat() { return _renderFormat; }
|
inline Texture2D::PixelFormat getRenderFormat() { return _renderFormat; }
|
||||||
inline int getWidth() { return _width; }
|
inline int getWidth() { return _width; }
|
||||||
|
@ -198,16 +198,16 @@ public:
|
||||||
bool saveToFile(const std::string &filename, bool isToRGB = true);
|
bool saveToFile(const std::string &filename, bool isToRGB = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool initWithJpgData(const unsigned char * data, int dataLen);
|
bool initWithJpgData(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithPngData(const unsigned char * data, int dataLen);
|
bool initWithPngData(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithTiffData(const unsigned char * data, int dataLen);
|
bool initWithTiffData(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithWebpData(const unsigned char * data, int dataLen);
|
bool initWithWebpData(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithPVRData(const unsigned char * data, int dataLen);
|
bool initWithPVRData(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithPVRv2Data(const unsigned char * data, int dataLen);
|
bool initWithPVRv2Data(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithPVRv3Data(const unsigned char * data, int dataLen);
|
bool initWithPVRv3Data(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithETCData(const unsigned char * data, int dataLen);
|
bool initWithETCData(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithS3TCData(const unsigned char * data, int dataLen);
|
bool initWithS3TCData(const unsigned char * data, ssize_t dataLen);
|
||||||
bool initWithATITCData(const unsigned char *data, int dataLen);
|
bool initWithATITCData(const unsigned char *data, ssize_t dataLen);
|
||||||
typedef struct sImageTGA tImageTGA;
|
typedef struct sImageTGA tImageTGA;
|
||||||
bool initWithTGAData(tImageTGA* tgaData);
|
bool initWithTGAData(tImageTGA* tgaData);
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ private:
|
||||||
*/
|
*/
|
||||||
static const int MIPMAP_MAX = 16;
|
static const int MIPMAP_MAX = 16;
|
||||||
unsigned char *_data;
|
unsigned char *_data;
|
||||||
int _dataLen;
|
ssize_t _dataLen;
|
||||||
int _width;
|
int _width;
|
||||||
int _height;
|
int _height;
|
||||||
Format _fileType;
|
Format _fileType;
|
||||||
|
@ -248,15 +248,15 @@ private:
|
||||||
*/
|
*/
|
||||||
bool initWithImageFileThreadSafe(const char *fullpath);
|
bool initWithImageFileThreadSafe(const char *fullpath);
|
||||||
|
|
||||||
Format detectFormat(const unsigned char * data, int dataLen);
|
Format detectFormat(const unsigned char * data, ssize_t dataLen);
|
||||||
bool isPng(const unsigned char * data, int dataLen);
|
bool isPng(const unsigned char * data, ssize_t dataLen);
|
||||||
bool isJpg(const unsigned char * data, int dataLen);
|
bool isJpg(const unsigned char * data, ssize_t dataLen);
|
||||||
bool isTiff(const unsigned char * data, int dataLen);
|
bool isTiff(const unsigned char * data, ssize_t dataLen);
|
||||||
bool isWebp(const unsigned char * data, int dataLen);
|
bool isWebp(const unsigned char * data, ssize_t dataLen);
|
||||||
bool isPvr(const unsigned char * data, int dataLen);
|
bool isPvr(const unsigned char * data, ssize_t dataLen);
|
||||||
bool isEtc(const unsigned char * data, int dataLen);
|
bool isEtc(const unsigned char * data, ssize_t dataLen);
|
||||||
bool isS3TC(const unsigned char * data,int dataLen);
|
bool isS3TC(const unsigned char * data,ssize_t dataLen);
|
||||||
bool isATITC(const unsigned char *data, int dataLen);
|
bool isATITC(const unsigned char *data, ssize_t dataLen);
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of platform group
|
// end of platform group
|
||||||
|
|
|
@ -349,7 +349,7 @@ namespace
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const unsigned char * data;
|
const unsigned char * data;
|
||||||
int size;
|
ssize_t size;
|
||||||
int offset;
|
int offset;
|
||||||
}tImageSource;
|
}tImageSource;
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ bool Image::initWithImageFile(const char * strPath)
|
||||||
|
|
||||||
SDL_FreeSurface(iSurf);
|
SDL_FreeSurface(iSurf);
|
||||||
#else
|
#else
|
||||||
long bufferLen = 0;
|
ssize_t bufferLen = 0;
|
||||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(_filePath.c_str(), "rb", &bufferLen);
|
unsigned char* buffer = FileUtils::getInstance()->getFileData(_filePath.c_str(), "rb", &bufferLen);
|
||||||
|
|
||||||
if (buffer != nullptr && bufferLen > 0)
|
if (buffer != nullptr && bufferLen > 0)
|
||||||
|
@ -437,7 +437,7 @@ bool Image::initWithImageFile(const char * strPath)
|
||||||
bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
long dataLen = 0;
|
ssize_t dataLen = 0;
|
||||||
_filePath = fullpath;
|
_filePath = fullpath;
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance();
|
FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance();
|
||||||
|
@ -453,7 +453,7 @@ bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
bool Image::initWithImageData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
|
@ -462,7 +462,7 @@ bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
||||||
CC_BREAK_IF(! data || dataLen <= 0);
|
CC_BREAK_IF(! data || dataLen <= 0);
|
||||||
|
|
||||||
unsigned char* unpackedData = nullptr;
|
unsigned char* unpackedData = nullptr;
|
||||||
int unpackedLen = 0;
|
ssize_t unpackedLen = 0;
|
||||||
|
|
||||||
//detecgt and unzip the compress file
|
//detecgt and unzip the compress file
|
||||||
if (ZipUtils::isCCZBuffer(data, dataLen))
|
if (ZipUtils::isCCZBuffer(data, dataLen))
|
||||||
|
@ -535,7 +535,7 @@ bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::isPng(const unsigned char * data, int dataLen)
|
bool Image::isPng(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
if (dataLen <= 8)
|
if (dataLen <= 8)
|
||||||
{
|
{
|
||||||
|
@ -548,13 +548,13 @@ bool Image::isPng(const unsigned char * data, int dataLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Image::isEtc(const unsigned char * data, int dataLen)
|
bool Image::isEtc(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
return etc1_pkm_is_valid((etc1_byte*)data) ? true : false;
|
return etc1_pkm_is_valid((etc1_byte*)data) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Image::isS3TC(const unsigned char * data, int dataLen)
|
bool Image::isS3TC(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
|
|
||||||
S3TCTexHeader *header = (S3TCTexHeader *)data;
|
S3TCTexHeader *header = (S3TCTexHeader *)data;
|
||||||
|
@ -567,7 +567,7 @@ bool Image::isS3TC(const unsigned char * data, int dataLen)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::isATITC(const unsigned char *data, int dataLen)
|
bool Image::isATITC(const unsigned char *data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
ATITCTexHeader *header = (ATITCTexHeader *)data;
|
ATITCTexHeader *header = (ATITCTexHeader *)data;
|
||||||
|
|
||||||
|
@ -579,7 +579,7 @@ bool Image::isATITC(const unsigned char *data, int dataLen)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::isJpg(const unsigned char * data, int dataLen)
|
bool Image::isJpg(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
if (dataLen <= 4)
|
if (dataLen <= 4)
|
||||||
{
|
{
|
||||||
|
@ -591,7 +591,7 @@ bool Image::isJpg(const unsigned char * data, int dataLen)
|
||||||
return memcmp(data, JPG_SOI, 2) == 0;
|
return memcmp(data, JPG_SOI, 2) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::isTiff(const unsigned char * data, int dataLen)
|
bool Image::isTiff(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
if (dataLen <= 4)
|
if (dataLen <= 4)
|
||||||
{
|
{
|
||||||
|
@ -605,7 +605,7 @@ bool Image::isTiff(const unsigned char * data, int dataLen)
|
||||||
(memcmp(data, TIFF_MM, 2) == 0 && *(static_cast<const unsigned char*>(data) + 2) == 0 && *(static_cast<const unsigned char*>(data) + 3) == 42);
|
(memcmp(data, TIFF_MM, 2) == 0 && *(static_cast<const unsigned char*>(data) + 2) == 0 && *(static_cast<const unsigned char*>(data) + 3) == 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::isWebp(const unsigned char * data, int dataLen)
|
bool Image::isWebp(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
if (dataLen <= 12)
|
if (dataLen <= 12)
|
||||||
{
|
{
|
||||||
|
@ -619,7 +619,7 @@ bool Image::isWebp(const unsigned char * data, int dataLen)
|
||||||
&& memcmp(static_cast<const unsigned char*>(data) + 8, WEBP_WEBP, 4) == 0;
|
&& memcmp(static_cast<const unsigned char*>(data) + 8, WEBP_WEBP, 4) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::isPvr(const unsigned char * data, int dataLen)
|
bool Image::isPvr(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
if (static_cast<size_t>(dataLen) < sizeof(PVRv2TexHeader) || static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader))
|
if (static_cast<size_t>(dataLen) < sizeof(PVRv2TexHeader) || static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader))
|
||||||
{
|
{
|
||||||
|
@ -632,7 +632,7 @@ bool Image::isPvr(const unsigned char * data, int dataLen)
|
||||||
return memcmp(&headerv2->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203;
|
return memcmp(&headerv2->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Format Image::detectFormat(const unsigned char * data, int dataLen)
|
Image::Format Image::detectFormat(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
if (isPng(data, dataLen))
|
if (isPng(data, dataLen))
|
||||||
{
|
{
|
||||||
|
@ -744,7 +744,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithJpgData(const unsigned char * data, int dataLen)
|
bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
/* these are standard libjpeg structures for reading(decompression) */
|
/* these are standard libjpeg structures for reading(decompression) */
|
||||||
struct jpeg_decompress_struct cinfo;
|
struct jpeg_decompress_struct cinfo;
|
||||||
|
@ -841,7 +841,7 @@ bool Image::initWithJpgData(const unsigned char * data, int dataLen)
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithPngData(const unsigned char * data, int dataLen)
|
bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
// length of bytes to check if it is a valid png file
|
// length of bytes to check if it is a valid png file
|
||||||
#define PNGSIGSIZE 8
|
#define PNGSIGSIZE 8
|
||||||
|
@ -941,7 +941,7 @@ bool Image::initWithPngData(const unsigned char * data, int dataLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read png data
|
// read png data
|
||||||
png_uint_32 rowbytes;
|
png_size_t rowbytes;
|
||||||
png_bytep* row_pointers = (png_bytep*)malloc( sizeof(png_bytep) * _height );
|
png_bytep* row_pointers = (png_bytep*)malloc( sizeof(png_bytep) * _height );
|
||||||
|
|
||||||
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||||
|
@ -1085,7 +1085,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithTiffData(const unsigned char * data, int dataLen)
|
bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
do
|
do
|
||||||
|
@ -1179,7 +1179,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen)
|
bool Image::initWithPVRv2Data(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
int dataLength = 0, dataOffset = 0, dataSize = 0;
|
int dataLength = 0, dataOffset = 0, dataSize = 0;
|
||||||
int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
|
int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
|
||||||
|
@ -1305,7 +1305,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen)
|
bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
if (static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader))
|
if (static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader))
|
||||||
{
|
{
|
||||||
|
@ -1414,11 +1414,11 @@ bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataSize = widthBlocks * heightBlocks * ((blockSize * it->second.bpp) / 8);
|
dataSize = widthBlocks * heightBlocks * ((blockSize * it->second.bpp) / 8);
|
||||||
int packetLength = _dataLen - dataOffset;
|
auto packetLength = _dataLen - dataOffset;
|
||||||
packetLength = packetLength > dataSize ? dataSize : packetLength;
|
packetLength = packetLength > dataSize ? dataSize : packetLength;
|
||||||
|
|
||||||
_mipmaps[i].address = _data + dataOffset;
|
_mipmaps[i].address = _data + dataOffset;
|
||||||
_mipmaps[i].len = packetLength;
|
_mipmaps[i].len = static_cast<int>(packetLength);
|
||||||
|
|
||||||
dataOffset += packetLength;
|
dataOffset += packetLength;
|
||||||
CCAssert(dataOffset <= _dataLen, "CCTexurePVR: Invalid lenght");
|
CCAssert(dataOffset <= _dataLen, "CCTexurePVR: Invalid lenght");
|
||||||
|
@ -1431,7 +1431,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithETCData(const unsigned char * data, int dataLen)
|
bool Image::initWithETCData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
const etc1_byte* header = static_cast<const etc1_byte*>(data);
|
const etc1_byte* header = static_cast<const etc1_byte*>(data);
|
||||||
|
|
||||||
|
@ -1548,7 +1548,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
|
||||||
const unsigned char tgaSuffix[] = ".tga";
|
const unsigned char tgaSuffix[] = ".tga";
|
||||||
for(int i = 0; i < 4; ++i)
|
for(int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
if (std::tolower(_filePath[_filePath.length() - i - 1]) != tgaSuffix[3 - i])
|
if (tolower(_filePath[_filePath.length() - i - 1]) != tgaSuffix[3 - i])
|
||||||
{
|
{
|
||||||
CCLOG("Image WARNING: the image file suffix is not tga, but parsed as a tga image file. FILE: %s", _filePath.c_str());
|
CCLOG("Image WARNING: the image file suffix is not tga, but parsed as a tga image file. FILE: %s", _filePath.c_str());
|
||||||
break;
|
break;
|
||||||
|
@ -1575,7 +1575,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
|
bool Image::initWithS3TCData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
|
|
||||||
const uint32_t FOURCC_DXT1 = makeFourCC('D', 'X', 'T', '1');
|
const uint32_t FOURCC_DXT1 = makeFourCC('D', 'X', 'T', '1');
|
||||||
|
@ -1697,7 +1697,7 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Image::initWithATITCData(const unsigned char *data, int dataLen)
|
bool Image::initWithATITCData(const unsigned char *data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
/* load the .ktx file */
|
/* load the .ktx file */
|
||||||
ATITCTexHeader *header = (ATITCTexHeader *)data;
|
ATITCTexHeader *header = (ATITCTexHeader *)data;
|
||||||
|
@ -1826,12 +1826,12 @@ bool Image::initWithATITCData(const unsigned char *data, int dataLen)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithPVRData(const unsigned char * data, int dataLen)
|
bool Image::initWithPVRData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
return initWithPVRv2Data(data, dataLen) || initWithPVRv3Data(data, dataLen);
|
return initWithPVRv2Data(data, dataLen) || initWithPVRv3Data(data, dataLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithWebpData(const unsigned char * data, int dataLen)
|
bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
do
|
do
|
||||||
|
@ -1866,7 +1866,7 @@ bool Image::initWithWebpData(const unsigned char * data, int dataLen)
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti)
|
bool Image::initWithRawData(const unsigned char * data, ssize_t dataLen, int width, int height, int bitsPerComponent, bool preMulti)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
do
|
do
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCSAXParser.h"
|
#include "CCSAXParser.h"
|
||||||
#include "CCDictionary.h"
|
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
|
||||||
|
@ -82,7 +81,7 @@ bool XmlSaxHander::VisitExit( const tinyxml2::XMLElement& element )
|
||||||
bool XmlSaxHander::Visit( const tinyxml2::XMLText& text )
|
bool XmlSaxHander::Visit( const tinyxml2::XMLText& text )
|
||||||
{
|
{
|
||||||
//log("Visit %s",text.Value());
|
//log("Visit %s",text.Value());
|
||||||
SAXParser::textHandler(_ccsaxParserImp, (const CC_XML_CHAR *)text.Value(), strlen(text.Value()));
|
SAXParser::textHandler(_ccsaxParserImp, (const CC_XML_CHAR *)text.Value(), static_cast<int>(strlen(text.Value())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +101,7 @@ bool SAXParser::init(const char *pszEncoding)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength)
|
bool SAXParser::parse(const char* pXMLData, size_t uDataLength)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument tinyDoc;
|
tinyxml2::XMLDocument tinyDoc;
|
||||||
tinyDoc.Parse(pXMLData, uDataLength);
|
tinyDoc.Parse(pXMLData, uDataLength);
|
||||||
|
@ -115,7 +114,7 @@ bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength)
|
||||||
bool SAXParser::parse(const char *pszFile)
|
bool SAXParser::parse(const char *pszFile)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
long size = 0;
|
ssize_t size = 0;
|
||||||
char* pBuffer = (char*)FileUtils::getInstance()->getFileData(pszFile, "rt", &size);
|
char* pBuffer = (char*)FileUtils::getInstance()->getFileData(pszFile, "rt", &size);
|
||||||
if (pBuffer != NULL && size > 0)
|
if (pBuffer != NULL && size > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "CCPlatformConfig.h"
|
#include "CCPlatformConfig.h"
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
|
#include "string.h" // for size_t
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ public:
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
bool parse(const char* pXMLData, unsigned int uDataLength);
|
bool parse(const char* pXMLData, size_t uDataLength);
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
* @lua NA
|
* @lua NA
|
||||||
|
|
|
@ -29,10 +29,6 @@ NS_CC_BEGIN
|
||||||
// iOS and Mac already has a Thread.mm
|
// iOS and Mac already has a Thread.mm
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||||
|
|
||||||
std::list<std::function<void(void)>>* ThreadHelper::_callbackList = new std::list<std::function<void(void)>>();
|
|
||||||
std::mutex* ThreadHelper::_mutex = new std::mutex;
|
|
||||||
long ThreadHelper::_callbackNumberPerFrame = 5;
|
|
||||||
|
|
||||||
|
|
||||||
void* ThreadHelper::createAutoreleasePool()
|
void* ThreadHelper::createAutoreleasePool()
|
||||||
{
|
{
|
||||||
|
@ -44,42 +40,6 @@ void ThreadHelper::releaseAutoreleasePool(void* autoreleasePool)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadHelper::runOnGLThread(std::function<void(void)> f)
|
|
||||||
{
|
|
||||||
// Insert call back function
|
|
||||||
_mutex->lock();
|
|
||||||
_callbackList->push_back(f);
|
|
||||||
_mutex->unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadHelper::doCallback()
|
|
||||||
{
|
|
||||||
_mutex->lock();
|
|
||||||
auto iter = _callbackList->begin();
|
|
||||||
long i = 0;
|
|
||||||
while (iter != _callbackList->end())
|
|
||||||
{
|
|
||||||
auto f = *iter;
|
|
||||||
f();
|
|
||||||
|
|
||||||
++i;
|
|
||||||
if (i >= _callbackNumberPerFrame)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iter = _callbackList->erase(iter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_mutex->unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadHelper::setCallbackNumberPerFrame(long callbackNumberPerFrame)
|
|
||||||
{
|
|
||||||
_callbackNumberPerFrame = callbackNumberPerFrame;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -59,29 +59,6 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
static void releaseAutoreleasePool(void *autoreleasePool);
|
static void releaseAutoreleasePool(void *autoreleasePool);
|
||||||
|
|
||||||
/** To run a function in gl thread.
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
@since v3.0
|
|
||||||
*/
|
|
||||||
static void runOnGLThread(std::function<void(void)> f);
|
|
||||||
|
|
||||||
/** Set how many callback functions being invoked per frame. Default value is 5.
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
@since v3.0
|
|
||||||
*/
|
|
||||||
static void setCallbackNumberPerFrame(long callbackNumberPerFrame);
|
|
||||||
|
|
||||||
private:
|
|
||||||
// This function will be call by Director to call some call back function on gl thread
|
|
||||||
static void doCallback();
|
|
||||||
|
|
||||||
static std::list<std::function<void(void)>> *_callbackList;
|
|
||||||
static std::mutex *_mutex;
|
|
||||||
// How many callback functions invoked per frame
|
|
||||||
static long _callbackNumberPerFrame;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of platform group
|
// end of platform group
|
||||||
|
|
|
@ -130,17 +130,17 @@ bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, long * size)
|
unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, ssize_t * size)
|
||||||
{
|
{
|
||||||
return doGetFileData(filename, mode, size, false);
|
return doGetFileData(filename, mode, size, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, long * pSize)
|
unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, ssize_t * pSize)
|
||||||
{
|
{
|
||||||
return doGetFileData(filename, pszMode, pSize, true);
|
return doGetFileData(filename, pszMode, pSize, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* mode, long * size, bool forAsync)
|
unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* mode, ssize_t * size, bool forAsync)
|
||||||
{
|
{
|
||||||
unsigned char * data = 0;
|
unsigned char * data = 0;
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
/* override funtions */
|
/* override funtions */
|
||||||
bool init();
|
bool init();
|
||||||
virtual unsigned char* getFileData(const char* filename, const char* mode, long * size);
|
virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size);
|
||||||
|
|
||||||
virtual std::string getWritablePath() const;
|
virtual std::string getWritablePath() const;
|
||||||
virtual bool isFileExist(const std::string& strFilePath) const;
|
virtual bool isFileExist(const std::string& strFilePath) const;
|
||||||
|
@ -64,10 +64,10 @@ public:
|
||||||
/** This function is android specific. It is used for TextureCache::addImageAsync().
|
/** This function is android specific. It is used for TextureCache::addImageAsync().
|
||||||
Don't use it in your codes.
|
Don't use it in your codes.
|
||||||
*/
|
*/
|
||||||
unsigned char* getFileDataForAsync(const char* filename, const char* mode, long * size);
|
unsigned char* getFileDataForAsync(const char* filename, const char* mode, ssize_t * size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char* doGetFileData(const char* filename, const char* mode, long * size, bool forAsync);
|
unsigned char* doGetFileData(const char* filename, const char* mode, ssize_t * size, bool forAsync);
|
||||||
static AAssetManager* assetmanager;
|
static AAssetManager* assetmanager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue