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)
|
||||
project (Cocos2dx)
|
||||
|
||||
|
@ -170,12 +195,6 @@ if(WIN32)
|
|||
)
|
||||
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)
|
||||
|
||||
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/CCSet.cpp \
|
||||
../base/CCString.cpp \
|
||||
../base/CCValue.cpp \
|
||||
../base/etc1.cpp \
|
||||
../base/s3tc.cpp \
|
||||
../base/CCConsole.cpp \
|
||||
../math/kazmath/src/aabb.c \
|
||||
../math/kazmath/src/mat3.c \
|
||||
../math/kazmath/src/mat4.c \
|
||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
|||
#include "CCActionInterval.h"
|
||||
#include "CCNode.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCString.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
//
|
||||
|
|
|
@ -43,7 +43,7 @@ NS_CC_BEGIN;
|
|||
* Implementation of PointArray
|
||||
*/
|
||||
|
||||
PointArray* PointArray::create(unsigned int capacity)
|
||||
PointArray* PointArray::create(int capacity)
|
||||
{
|
||||
PointArray* pointArray = new 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*>();
|
||||
|
||||
|
@ -126,19 +126,19 @@ void PointArray::addControlPoint(Point controlPoint)
|
|||
_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);
|
||||
_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));
|
||||
}
|
||||
|
||||
void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, unsigned int index)
|
||||
void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, int index)
|
||||
{
|
||||
|
||||
Point *temp = _controlPoints->at(index);
|
||||
|
@ -146,7 +146,7 @@ void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, unsigned int
|
|||
temp->y = controlPoint.y;
|
||||
}
|
||||
|
||||
void PointArray::removeControlPointAtIndex(unsigned int index)
|
||||
void PointArray::removeControlPointAtIndex(int index)
|
||||
{
|
||||
vector<Point*>::iterator iter = _controlPoints->begin() + index;
|
||||
Point* pRemovedPoint = *iter;
|
||||
|
@ -154,9 +154,9 @@ void PointArray::removeControlPointAtIndex(unsigned int index)
|
|||
delete pRemovedPoint;
|
||||
}
|
||||
|
||||
unsigned int PointArray::count() const
|
||||
int PointArray::count() const
|
||||
{
|
||||
return _controlPoints->size();
|
||||
return static_cast<int>(_controlPoints->size());
|
||||
}
|
||||
|
||||
PointArray* PointArray::reverse() const
|
||||
|
@ -177,11 +177,11 @@ PointArray* PointArray::reverse() const
|
|||
|
||||
void PointArray::reverseInline()
|
||||
{
|
||||
unsigned long l = _controlPoints->size();
|
||||
auto l = _controlPoints->size();
|
||||
Point *p1 = nullptr;
|
||||
Point *p2 = nullptr;
|
||||
int x, y;
|
||||
for (unsigned int i = 0; i < l/2; ++i)
|
||||
for (int i = 0; i < l/2; ++i)
|
||||
{
|
||||
p1 = _controlPoints->at(i);
|
||||
p2 = _controlPoints->at(l-i-1);
|
||||
|
@ -291,7 +291,7 @@ CardinalSplineTo* CardinalSplineTo::clone() const
|
|||
|
||||
void CardinalSplineTo::update(float time)
|
||||
{
|
||||
unsigned int p;
|
||||
int p;
|
||||
float lt;
|
||||
|
||||
// eg.
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
/** creates and initializes a Points array with capacity
|
||||
* @js NA
|
||||
*/
|
||||
static PointArray* create(unsigned int capacity);
|
||||
static PointArray* create(int capacity);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
|
@ -77,7 +77,7 @@ public:
|
|||
/** initializes a Catmull Rom config with a capacity hint
|
||||
* @js NA
|
||||
*/
|
||||
bool initWithCapacity(unsigned int capacity);
|
||||
bool initWithCapacity(int capacity);
|
||||
|
||||
/** appends a control point
|
||||
* @js NA
|
||||
|
@ -87,27 +87,27 @@ public:
|
|||
/** inserts a controlPoint at index
|
||||
* @js NA
|
||||
*/
|
||||
void insertControlPoint(Point &controlPoint, unsigned int index);
|
||||
void insertControlPoint(Point &controlPoint, int index);
|
||||
|
||||
/** replaces an existing controlPoint at index
|
||||
* @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
|
||||
* @js NA
|
||||
*/
|
||||
Point getControlPointAtIndex(unsigned int index);
|
||||
Point getControlPointAtIndex(int index);
|
||||
|
||||
/** deletes a control point at a given index
|
||||
* @js NA
|
||||
*/
|
||||
void removeControlPointAtIndex(unsigned int index);
|
||||
void removeControlPointAtIndex(int index);
|
||||
|
||||
/** returns the number of objects of the control point array
|
||||
* @js NA
|
||||
*/
|
||||
unsigned int count() const;
|
||||
int count() const;
|
||||
|
||||
/** returns a new copy of the array reversed. User is responsible for releasing this copy
|
||||
* @js NA
|
||||
|
|
|
@ -198,21 +198,21 @@ Sequence* Sequence::createWithVariableList(FiniteTimeAction *pAction1, va_list a
|
|||
return ((Sequence*)pPrev);
|
||||
}
|
||||
|
||||
Sequence* Sequence::create(Array* arrayOfActions)
|
||||
Sequence* Sequence::create(const Vector<FiniteTimeAction*>& arrayOfActions)
|
||||
{
|
||||
Sequence* pRet = NULL;
|
||||
do
|
||||
{
|
||||
long count = arrayOfActions->count();
|
||||
auto count = arrayOfActions.size();
|
||||
CC_BREAK_IF(count == 0);
|
||||
|
||||
FiniteTimeAction* prev = static_cast<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(0));
|
||||
auto prev = arrayOfActions.at(0);
|
||||
|
||||
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
|
||||
|
@ -571,19 +571,19 @@ Spawn* Spawn::createWithVariableList(FiniteTimeAction *pAction1, va_list args)
|
|||
return ((Spawn*)pPrev);
|
||||
}
|
||||
|
||||
Spawn* Spawn::create(Array *arrayOfActions)
|
||||
Spawn* Spawn::create(const Vector<FiniteTimeAction*>& arrayOfActions)
|
||||
{
|
||||
Spawn* pRet = NULL;
|
||||
do
|
||||
{
|
||||
long count = arrayOfActions->count();
|
||||
auto count = arrayOfActions.size();
|
||||
CC_BREAK_IF(count == 0);
|
||||
FiniteTimeAction* prev = static_cast<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(0));
|
||||
auto prev = arrayOfActions.at(0);
|
||||
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
|
||||
|
@ -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.
|
||||
prev = createWithTwoActions(prev, ExtraAction::create());
|
||||
}
|
||||
pRet = (Spawn*)prev;
|
||||
pRet = static_cast<Spawn*>(prev);
|
||||
}while (0);
|
||||
|
||||
return pRet;
|
||||
|
@ -2003,31 +2003,28 @@ Animate::~Animate()
|
|||
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;
|
||||
setAnimation(pAnimation);
|
||||
setAnimation(animation);
|
||||
_origFrame = NULL;
|
||||
_executedLoops = 0;
|
||||
|
||||
_splitTimes->reserve(pAnimation->getFrames()->count());
|
||||
_splitTimes->reserve(animation->getFrames().size());
|
||||
|
||||
float accumUnitsOfTime = 0;
|
||||
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
|
||||
float newUnitOfTimeValue = singleDuration / animation->getTotalDelayUnits();
|
||||
|
||||
Array* pFrames = pAnimation->getFrames();
|
||||
CCARRAY_VERIFY_TYPE(pFrames, AnimationFrame*);
|
||||
auto frames = animation->getFrames();
|
||||
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(pFrames, pObj)
|
||||
for (auto& frame : frames)
|
||||
{
|
||||
AnimationFrame* frame = static_cast<AnimationFrame*>(pObj);
|
||||
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
||||
accumUnitsOfTime += frame->getDelayUnits();
|
||||
_splitTimes->push_back(value);
|
||||
|
@ -2099,20 +2096,20 @@ void Animate::update(float t)
|
|||
t = fmodf(t, 1.0f);
|
||||
}
|
||||
|
||||
Array* frames = _animation->getFrames();
|
||||
long numberOfFrames = frames->count();
|
||||
auto frames = _animation->getFrames();
|
||||
auto numberOfFrames = frames.size();
|
||||
SpriteFrame *frameToDisplay = NULL;
|
||||
|
||||
for( int i=_nextFrame; i < numberOfFrames; i++ ) {
|
||||
float splitTime = _splitTimes->at(i);
|
||||
|
||||
if( splitTime <= t ) {
|
||||
AnimationFrame* frame = static_cast<AnimationFrame*>(frames->getObjectAtIndex(i));
|
||||
AnimationFrame* frame = frames.at(i);
|
||||
frameToDisplay = frame->getSpriteFrame();
|
||||
static_cast<Sprite*>(_target)->setDisplayFrame(frameToDisplay);
|
||||
|
||||
Dictionary* dict = frame->getUserInfo();
|
||||
if( dict )
|
||||
const ValueMap& dict = frame->getUserInfo();
|
||||
if ( !dict.empty() )
|
||||
{
|
||||
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:AnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
||||
}
|
||||
|
@ -2127,27 +2124,24 @@ void Animate::update(float t)
|
|||
|
||||
Animate* Animate::reverse() const
|
||||
{
|
||||
Array* pOldArray = _animation->getFrames();
|
||||
Array* pNewArray = Array::createWithCapacity(pOldArray->count());
|
||||
auto oldArray = _animation->getFrames();
|
||||
Vector<AnimationFrame*> newArray(oldArray.size());
|
||||
|
||||
CCARRAY_VERIFY_TYPE(pOldArray, AnimationFrame*);
|
||||
|
||||
if (pOldArray->count() > 0)
|
||||
if (oldArray.size() > 0)
|
||||
{
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH_REVERSE(pOldArray, pObj)
|
||||
for (auto iter = oldArray.crbegin(); iter != oldArray.crend(); ++iter)
|
||||
{
|
||||
AnimationFrame* pElement = static_cast<AnimationFrame*>(pObj);
|
||||
if (! pElement)
|
||||
AnimationFrame* animFrame = *iter;
|
||||
if (!animFrame)
|
||||
{
|
||||
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());
|
||||
return Animate::create(newAnim);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
|||
#include "CCProtocols.h"
|
||||
#include "CCSpriteFrame.h"
|
||||
#include "CCAnimation.h"
|
||||
#include <CCVector.h>
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -99,7 +100,7 @@ public:
|
|||
* in lua :local create(local object1,local object2, ...)
|
||||
* @endcode
|
||||
*/
|
||||
static Sequence* create(Array *arrayOfActions);
|
||||
static Sequence* create(const Vector<FiniteTimeAction*>& arrayOfActions);
|
||||
/** helper constructor to create an array of sequence-able actions */
|
||||
static Sequence* createWithVariableList(FiniteTimeAction *pAction1, va_list args);
|
||||
/** creates the action */
|
||||
|
@ -246,7 +247,7 @@ public:
|
|||
static Spawn* createWithVariableList(FiniteTimeAction *pAction1, va_list args);
|
||||
|
||||
/** 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 */
|
||||
static Spawn* createWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2);
|
||||
|
|
|
@ -40,7 +40,7 @@ NS_CC_BEGIN
|
|||
typedef struct _hashElement
|
||||
{
|
||||
struct _ccArray *actions;
|
||||
Object *target;
|
||||
Node *target;
|
||||
int actionIndex;
|
||||
Action *currentAction;
|
||||
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];
|
||||
|
||||
|
@ -120,7 +120,7 @@ void ActionManager::removeActionAtIndex(long index, tHashElement *element)
|
|||
|
||||
// pause / resume
|
||||
|
||||
void ActionManager::pauseTarget(Object *target)
|
||||
void ActionManager::pauseTarget(Node *target)
|
||||
{
|
||||
tHashElement *element = NULL;
|
||||
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;
|
||||
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();
|
||||
idsWithActions->autorelease();
|
||||
Vector<Node*> idsWithActions;
|
||||
|
||||
for (tHashElement *element=_targets; element != NULL; element = (tHashElement *)element->hh.next)
|
||||
{
|
||||
if (! element->paused)
|
||||
{
|
||||
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;
|
||||
for (iter = targetsToResume->begin(); iter != targetsToResume->end(); ++iter)
|
||||
{
|
||||
resumeTarget(*iter);
|
||||
}
|
||||
targetsToResume.forEach([this](Node* node){
|
||||
this->resumeTarget(node);
|
||||
});
|
||||
}
|
||||
|
||||
// run
|
||||
|
@ -196,17 +193,17 @@ void ActionManager::addAction(Action *action, Node *target, bool paused)
|
|||
|
||||
// remove
|
||||
|
||||
void ActionManager::removeAllActions(void)
|
||||
void ActionManager::removeAllActions()
|
||||
{
|
||||
for (tHashElement *element = _targets; element != NULL; )
|
||||
{
|
||||
Object *target = element->target;
|
||||
auto target = element->target;
|
||||
element = (tHashElement*)element->hh.next;
|
||||
removeAllActionsFromTarget(target);
|
||||
}
|
||||
}
|
||||
|
||||
void ActionManager::removeAllActionsFromTarget(Object *target)
|
||||
void ActionManager::removeAllActionsFromTarget(Node *target)
|
||||
{
|
||||
// explicit null handling
|
||||
if (target == NULL)
|
||||
|
@ -253,7 +250,7 @@ void ActionManager::removeAction(Action *action)
|
|||
HASH_FIND_PTR(_targets, &target, element);
|
||||
if (element)
|
||||
{
|
||||
long i = ccArrayGetIndexOfObject(element->actions, action);
|
||||
auto i = ccArrayGetIndexOfObject(element->actions, action);
|
||||
if (i != CC_INVALID_INDEX)
|
||||
{
|
||||
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(target != NULL, "");
|
||||
|
@ -275,8 +272,8 @@ void ActionManager::removeActionByTag(int tag, Object *target)
|
|||
|
||||
if (element)
|
||||
{
|
||||
long limit = element->actions->num;
|
||||
for (long i = 0; i < limit; ++i)
|
||||
auto limit = element->actions->num;
|
||||
for (int i = 0; i < limit; ++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
|
||||
// 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, "");
|
||||
|
||||
|
@ -304,8 +301,8 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const
|
|||
{
|
||||
if (element->actions != NULL)
|
||||
{
|
||||
long limit = element->actions->num;
|
||||
for (long i = 0; i < limit; ++i)
|
||||
auto limit = element->actions->num;
|
||||
for (int i = 0; i < limit; ++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
|
||||
// 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;
|
||||
HASH_FIND_PTR(_targets, &target, element);
|
||||
|
|
|
@ -29,13 +29,11 @@ THE SOFTWARE.
|
|||
#define __ACTION_CCACTION_MANAGER_H__
|
||||
|
||||
#include "CCAction.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCObject.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Set;
|
||||
|
||||
struct _hashElement;
|
||||
|
||||
/**
|
||||
|
@ -78,55 +76,55 @@ public:
|
|||
|
||||
/** Removes all actions from all the targets.
|
||||
*/
|
||||
void removeAllActions(void);
|
||||
void removeAllActions();
|
||||
|
||||
/** Removes all actions from a certain target.
|
||||
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.
|
||||
*/
|
||||
void removeAction(Action *pAction);
|
||||
|
||||
/** 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
|
||||
@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.
|
||||
* 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 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 */
|
||||
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.
|
||||
*/
|
||||
void pauseTarget(Object *target);
|
||||
void pauseTarget(Node *target);
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
Set* pauseAllRunningActions();
|
||||
Vector<Node*> pauseAllRunningActions();
|
||||
|
||||
/** Resume a set of targets (convenience function to reverse a pauseAllRunningActions call)
|
||||
*/
|
||||
void resumeTargets(Set *targetsToResume);
|
||||
void resumeTargets(const Vector<Node*>& targetsToResume);
|
||||
|
||||
protected:
|
||||
// declared in ActionManager.m
|
||||
|
||||
void removeActionAtIndex(long index, struct _hashElement *pElement);
|
||||
void removeActionAtIndex(int index, struct _hashElement *pElement);
|
||||
void deleteHashElement(struct _hashElement *pElement);
|
||||
void actionAllocWithHashElement(struct _hashElement *pElement);
|
||||
void update(float dt);
|
||||
|
|
|
@ -32,15 +32,28 @@ THE SOFTWARE.
|
|||
|
||||
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()
|
||||
: _spriteFrame(NULL)
|
||||
, _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);
|
||||
setDelayUnits(delayUnits);
|
||||
|
@ -54,7 +67,6 @@ AnimationFrame::~AnimationFrame()
|
|||
CCLOGINFO( "deallocing AnimationFrame: %p", this);
|
||||
|
||||
CC_SAFE_RELEASE(_spriteFrame);
|
||||
CC_SAFE_RELEASE(_userInfo);
|
||||
}
|
||||
|
||||
AnimationFrame* AnimationFrame::clone() const
|
||||
|
@ -63,7 +75,7 @@ AnimationFrame* AnimationFrame::clone() const
|
|||
auto frame = new AnimationFrame();
|
||||
frame->initWithSpriteFrame(_spriteFrame->clone(),
|
||||
_delayUnits,
|
||||
_userInfo != NULL ? _userInfo->clone() : NULL);
|
||||
_userInfo);
|
||||
|
||||
frame->autorelease();
|
||||
return frame;
|
||||
|
@ -80,7 +92,7 @@ Animation* Animation::create(void)
|
|||
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();
|
||||
pAnimation->initWithSpriteFrames(frames, delay);
|
||||
|
@ -89,7 +101,7 @@ Animation* Animation::createWithSpriteFrames(Array *frames, float delay/* = 0.0f
|
|||
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();
|
||||
pAnimation->initWithAnimationFrames(arrayOfAnimationFrameNames, delayPerUnit, loops);
|
||||
|
@ -99,49 +111,36 @@ Animation* Animation::create(Array* arrayOfAnimationFrameNames, float delayPerUn
|
|||
|
||||
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;
|
||||
_delayPerUnit = delay;
|
||||
Array* pTmpFrames = Array::create();
|
||||
setFrames(pTmpFrames);
|
||||
|
||||
if (pFrames != NULL)
|
||||
for (auto& spriteFrame : frames)
|
||||
{
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(pFrames, pObj)
|
||||
{
|
||||
SpriteFrame* frame = static_cast<SpriteFrame*>(pObj);
|
||||
AnimationFrame *animFrame = new AnimationFrame();
|
||||
animFrame->initWithSpriteFrame(frame, 1, NULL);
|
||||
_frames->addObject(animFrame);
|
||||
animFrame->release();
|
||||
|
||||
auto animFrame = AnimationFrame::create(spriteFrame, 1, ValueMap());
|
||||
_frames.pushBack(animFrame);
|
||||
_totalDelayUnits++;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
_loops = loops;
|
||||
|
||||
setFrames(Array::createWithArray(arrayOfAnimationFrames));
|
||||
setFrames(arrayOfAnimationFrames);
|
||||
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(_frames, pObj)
|
||||
for (auto& animFrame : _frames)
|
||||
{
|
||||
AnimationFrame* animFrame = static_cast<AnimationFrame*>(pObj);
|
||||
_totalDelayUnits += animFrame->getDelayUnits();
|
||||
}
|
||||
return true;
|
||||
|
@ -151,7 +150,6 @@ Animation::Animation()
|
|||
: _totalDelayUnits(0.0f)
|
||||
, _delayPerUnit(0.0f)
|
||||
, _duration(0.0f)
|
||||
, _frames(NULL)
|
||||
, _restoreOriginalFrame(false)
|
||||
, _loops(0)
|
||||
{
|
||||
|
@ -161,15 +159,12 @@ Animation::Animation()
|
|||
Animation::~Animation(void)
|
||||
{
|
||||
CCLOGINFO("deallocing Animation: %p", this);
|
||||
CC_SAFE_RELEASE(_frames);
|
||||
}
|
||||
|
||||
void Animation::addSpriteFrame(SpriteFrame *pFrame)
|
||||
void Animation::addSpriteFrame(SpriteFrame* spriteFrame)
|
||||
{
|
||||
AnimationFrame *animFrame = new AnimationFrame();
|
||||
animFrame->initWithSpriteFrame(pFrame, 1.0f, NULL);
|
||||
_frames->addObject(animFrame);
|
||||
animFrame->release();
|
||||
AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, 1.0f, ValueMap());
|
||||
_frames.pushBack(animFrame);
|
||||
|
||||
// update duration
|
||||
_totalDelayUnits++;
|
||||
|
|
|
@ -29,9 +29,11 @@ THE SOFTWARE.
|
|||
#include "CCPlatformConfig.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "CCSpriteFrame.h"
|
||||
#include "CCVector.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -56,17 +58,10 @@ class CC_DLL AnimationFrame : public Object, public Clonable
|
|||
{
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
* Creates the animation frame with a spriteframe, number of delay units and a notification user info
|
||||
* @since 3.0
|
||||
*/
|
||||
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, Dictionary* userInfo);
|
||||
static AnimationFrame* create(SpriteFrame* spriteFrame, float delayUnits, const ValueMap& userInfo);
|
||||
|
||||
SpriteFrame* getSpriteFrame() const { return _spriteFrame; };
|
||||
|
||||
|
@ -86,13 +81,12 @@ public:
|
|||
/** @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.
|
||||
*/
|
||||
Dictionary* getUserInfo() const { return _userInfo; };
|
||||
const ValueMap& getUserInfo() const { return _userInfo; };
|
||||
ValueMap& getUserInfo() { return _userInfo; };
|
||||
|
||||
/** Sets user infomation */
|
||||
void setUserInfo(Dictionary* userInfo)
|
||||
void setUserInfo(const ValueMap& userInfo)
|
||||
{
|
||||
CC_SAFE_RETAIN(userInfo);
|
||||
CC_SAFE_RELEASE(_userInfo);
|
||||
_userInfo = userInfo;
|
||||
}
|
||||
|
||||
|
@ -100,6 +94,20 @@ public:
|
|||
virtual AnimationFrame *clone() const override;
|
||||
|
||||
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 */
|
||||
SpriteFrame* _spriteFrame;
|
||||
|
||||
|
@ -107,7 +115,10 @@ protected:
|
|||
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. */
|
||||
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".
|
||||
@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.
|
||||
@since v2.0
|
||||
* @js NA
|
||||
*/
|
||||
static Animation* create(Array *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);
|
||||
static Animation* create(const Vector<AnimationFrame*>& arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops = 1);
|
||||
|
||||
/** Adds a SpriteFrame to a Animation.
|
||||
The frame will be added with one "delay unit".
|
||||
|
@ -199,13 +189,11 @@ public:
|
|||
float getDuration() const;
|
||||
|
||||
/** Gets the array of AnimationFrames */
|
||||
Array* getFrames() const { return _frames; };
|
||||
const Vector<AnimationFrame*>& getFrames() const { return _frames; };
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
|
@ -225,6 +213,22 @@ public:
|
|||
virtual Animation *clone() const override;
|
||||
|
||||
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. */
|
||||
float _totalDelayUnits;
|
||||
|
||||
|
@ -235,13 +239,16 @@ protected:
|
|||
float _duration;
|
||||
|
||||
/** array of AnimationFrames */
|
||||
Array* _frames;
|
||||
Vector<AnimationFrame*> _frames;
|
||||
|
||||
/** whether or not it shall restore the original frame when the animation finishes */
|
||||
bool _restoreOriginalFrame;
|
||||
|
||||
/** how many times the animation is going to loop. 0 means animation is not animated. 1, animation is executed one time, ... */
|
||||
unsigned int _loops;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(Animation);
|
||||
};
|
||||
|
||||
// end of sprite_nodes group
|
||||
|
|
|
@ -55,25 +55,21 @@ void AnimationCache::destroyInstance()
|
|||
|
||||
bool AnimationCache::init()
|
||||
{
|
||||
_animations = new Dictionary;
|
||||
_animations->init();
|
||||
return true;
|
||||
}
|
||||
|
||||
AnimationCache::AnimationCache()
|
||||
: _animations(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AnimationCache::~AnimationCache()
|
||||
{
|
||||
CCLOGINFO("deallocing AnimationCache: %p", this);
|
||||
CC_SAFE_RELEASE(_animations);
|
||||
}
|
||||
|
||||
void AnimationCache::addAnimation(Animation *animation, const std::string& name)
|
||||
{
|
||||
_animations->setObject(animation, name);
|
||||
_animations.insert(name, animation);
|
||||
}
|
||||
|
||||
void AnimationCache::removeAnimation(const std::string& name)
|
||||
|
@ -81,157 +77,143 @@ void AnimationCache::removeAnimation(const std::string& name)
|
|||
if (name.size()==0)
|
||||
return;
|
||||
|
||||
_animations->removeObjectForKey(name);
|
||||
_animations.remove(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();
|
||||
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(animations, element)
|
||||
for (auto iter = animations.cbegin(); iter != animations.cend(); ++iter)
|
||||
{
|
||||
Dictionary* animationDict = static_cast<Dictionary*>(element->getObject());
|
||||
Array* frameNames = static_cast<Array*>(animationDict->objectForKey("frames"));
|
||||
float delay = animationDict->valueForKey("delay")->floatValue();
|
||||
Animation* animation = NULL;
|
||||
const ValueMap& animationDict = iter->second.asValueMap();
|
||||
const ValueVector& frameNames = animationDict.at("frames").asValueVector();
|
||||
float delay = animationDict.at("delay").asFloat();
|
||||
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;
|
||||
}
|
||||
|
||||
Array* frames = Array::createWithCapacity(frameNames->count());
|
||||
frames->retain();
|
||||
Vector<AnimationFrame*> frames(static_cast<int>(frameNames.size()));
|
||||
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(frameNames, pObj)
|
||||
for (auto& frameName : frameNames)
|
||||
{
|
||||
const std::string& frameName = static_cast<String*>(pObj)->getCString();
|
||||
SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName);
|
||||
SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName.asString());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
AnimationFrame* animFrame = new AnimationFrame();
|
||||
animFrame->initWithSpriteFrame(spriteFrame, 1, NULL);
|
||||
frames->addObject(animFrame);
|
||||
animFrame->release();
|
||||
AnimationFrame* animFrame = AnimationFrame::create(spriteFrame, 1, ValueMap());
|
||||
frames.pushBack(animFrame);
|
||||
}
|
||||
|
||||
if ( frames->count() == 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());
|
||||
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.", iter->first.c_str());
|
||||
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);
|
||||
|
||||
AnimationCache::getInstance()->addAnimation(animation, element->getStrKey());
|
||||
frames->release();
|
||||
AnimationCache::getInstance()->addAnimation(animation, iter->first.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationCache::parseVersion2(Dictionary* animations)
|
||||
void AnimationCache::parseVersion2(const ValueMap& animations)
|
||||
{
|
||||
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
|
||||
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(animations, element)
|
||||
for (auto iter = animations.cbegin(); iter != animations.cend(); ++iter)
|
||||
{
|
||||
const char* name = element->getStrKey();
|
||||
Dictionary* animationDict = static_cast<Dictionary*>(element->getObject());
|
||||
std::string name = iter->first;
|
||||
ValueMap& animationDict = const_cast<ValueMap&>(iter->second.asValueMap());
|
||||
|
||||
const String* loops = animationDict->valueForKey("loops");
|
||||
bool restoreOriginalFrame = animationDict->valueForKey("restoreOriginalFrame")->boolValue();
|
||||
const Value& loops = animationDict["loops"];
|
||||
bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].asBool();
|
||||
|
||||
Array* frameArray = static_cast<Array*>(animationDict->objectForKey("frames"));
|
||||
ValueVector& frameArray = animationDict["frames"].asValueVector();
|
||||
|
||||
if ( frameArray == NULL ) {
|
||||
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name);
|
||||
if ( frameArray.empty() )
|
||||
{
|
||||
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Array of AnimationFrames
|
||||
Array* array = Array::createWithCapacity(frameArray->count());
|
||||
array->retain();
|
||||
Vector<AnimationFrame*> array(static_cast<int>(frameArray.size()));
|
||||
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(frameArray, pObj)
|
||||
for (auto& obj : frameArray)
|
||||
{
|
||||
Dictionary* entry = static_cast<Dictionary*>(pObj);
|
||||
|
||||
const char* spriteFrameName = entry->valueForKey("spriteframe")->getCString();
|
||||
ValueMap& entry = obj.asValueMap();
|
||||
std::string spriteFrameName = entry["spriteframe"].asString();
|
||||
SpriteFrame *spriteFrame = frameCache->getSpriteFrameByName(spriteFrameName);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
float delayUnits = entry->valueForKey("delayUnits")->floatValue();
|
||||
Dictionary* userInfo = (Dictionary*)entry->objectForKey("notification");
|
||||
float delayUnits = entry["delayUnits"].asFloat();
|
||||
Value& userInfo = entry["notification"];
|
||||
|
||||
AnimationFrame *animFrame = new AnimationFrame();
|
||||
animFrame->initWithSpriteFrame(spriteFrame, delayUnits, userInfo);
|
||||
AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, delayUnits, userInfo.asValueMap());
|
||||
|
||||
array->addObject(animFrame);
|
||||
animFrame->release();
|
||||
array.pushBack(animFrame);
|
||||
}
|
||||
|
||||
float delayPerUnit = animationDict->valueForKey("delayPerUnit")->floatValue();
|
||||
Animation *animation = new Animation();
|
||||
animation->initWithAnimationFrames(array, delayPerUnit, 0 != loops->length() ? loops->intValue() : 1);
|
||||
array->release();
|
||||
float delayPerUnit = animationDict["delayPerUnit"].asFloat();
|
||||
Animation *animation = Animation::create(array, delayPerUnit, loops.getType() != Value::Type::NONE ? loops.asInt() : 1);
|
||||
|
||||
animation->setRestoreOriginalFrame(restoreOriginalFrame);
|
||||
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
|
||||
const Value& animations = dictionary.at("animations");
|
||||
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;
|
||||
CCARRAY_FOREACH(spritesheets, pObj)
|
||||
if( dictionary.find("properties") != dictionary.end() )
|
||||
{
|
||||
String* name = static_cast<String*>(pObj);
|
||||
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(name->getCString());
|
||||
}
|
||||
const ValueMap& properties = dictionary.at("properties").asValueMap();
|
||||
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) {
|
||||
case 1:
|
||||
parseVersion1(animations);
|
||||
parseVersion1(animations.asValueMap());
|
||||
break;
|
||||
case 2:
|
||||
parseVersion2(animations);
|
||||
parseVersion2(animations.asValueMap());
|
||||
break;
|
||||
default:
|
||||
CCASSERT(false, "Invalid animation format");
|
||||
|
@ -244,9 +226,9 @@ void AnimationCache::addAnimationsWithFile(const std::string& plist)
|
|||
CCASSERT( plist.size()>0, "Invalid texture file name");
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ THE SOFTWARE.
|
|||
#define __CC_ANIMATION_CACHE_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCDictionary.h"
|
||||
|
||||
#include "CCMap.h"
|
||||
#include "CCValue.h"
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -104,7 +104,7 @@ public:
|
|||
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
||||
@since v1.1
|
||||
*/
|
||||
void addAnimationsWithDictionary(Dictionary* dictionary);
|
||||
void addAnimationsWithDictionary(const ValueMap& dictionary);
|
||||
|
||||
/** Adds an animation from a plist file.
|
||||
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
||||
|
@ -115,11 +115,11 @@ public:
|
|||
void addAnimationsWithFile(const std::string& plist);
|
||||
|
||||
private:
|
||||
void parseVersion1(Dictionary* animations);
|
||||
void parseVersion2(Dictionary* animations);
|
||||
void parseVersion1(const ValueMap& animations);
|
||||
void parseVersion2(const ValueMap& animations);
|
||||
|
||||
private:
|
||||
Dictionary* _animations;
|
||||
Map<std::string, Animation*> _animations;
|
||||
static AnimationCache* s_pSharedAnimationCache;
|
||||
};
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ AtlasNode::~AtlasNode()
|
|||
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();
|
||||
if (pRet->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender))
|
||||
|
@ -73,14 +73,14 @@ AtlasNode * AtlasNode::create(const std::string& tile, long tileWidth, long tile
|
|||
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");
|
||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile);
|
||||
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;
|
||||
_itemHeight = tileHeight;
|
||||
|
@ -245,12 +245,12 @@ TextureAtlas * AtlasNode::getTextureAtlas() const
|
|||
return _textureAtlas;
|
||||
}
|
||||
|
||||
long AtlasNode::getQuadsToDraw() const
|
||||
int AtlasNode::getQuadsToDraw() const
|
||||
{
|
||||
return _quadsToDraw;
|
||||
}
|
||||
|
||||
void AtlasNode::setQuadsToDraw(long uQuadsToDraw)
|
||||
void AtlasNode::setQuadsToDraw(int uQuadsToDraw)
|
||||
{
|
||||
_quadsToDraw = uQuadsToDraw;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol
|
|||
{
|
||||
public:
|
||||
/** 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).
|
||||
* Shall be overridden in subclasses
|
||||
|
@ -62,8 +62,8 @@ public:
|
|||
void setTextureAtlas(TextureAtlas* textureAtlas);
|
||||
TextureAtlas* getTextureAtlas() const;
|
||||
|
||||
void setQuadsToDraw(long quadsToDraw);
|
||||
long getQuadsToDraw() const;
|
||||
void setQuadsToDraw(int quadsToDraw);
|
||||
int getQuadsToDraw() const;
|
||||
|
||||
|
||||
// Overrides
|
||||
|
@ -95,10 +95,10 @@ protected:
|
|||
virtual ~AtlasNode();
|
||||
|
||||
/** 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*/
|
||||
bool initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender);
|
||||
bool initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender);
|
||||
|
||||
void calculateMaxItems();
|
||||
void updateBlendFunc();
|
||||
|
@ -108,14 +108,14 @@ protected:
|
|||
void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor);
|
||||
|
||||
//! chars per row
|
||||
long _itemsPerRow;
|
||||
int _itemsPerRow;
|
||||
//! chars per column
|
||||
long _itemsPerColumn;
|
||||
int _itemsPerColumn;
|
||||
|
||||
//! width of each char
|
||||
long _itemWidth;
|
||||
int _itemWidth;
|
||||
//! height of each char
|
||||
long _itemHeight;
|
||||
int _itemHeight;
|
||||
|
||||
Color3B _colorUnmodified;
|
||||
|
||||
|
@ -125,7 +125,7 @@ protected:
|
|||
BlendFunc _blendFunc;
|
||||
|
||||
// quads to draw
|
||||
long _quadsToDraw;
|
||||
int _quadsToDraw;
|
||||
// color uniform
|
||||
GLint _uniformColor;
|
||||
// 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)
|
||||
{
|
||||
n->setShaderProgram(p);
|
||||
if (!n->getChildren()) return;
|
||||
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(n->getChildren(), pObj)
|
||||
{
|
||||
setProgram(static_cast<Node*>(pObj), p);
|
||||
}
|
||||
n->getChildren().forEach([p](Node* child){
|
||||
setProgram(child, p);
|
||||
});
|
||||
}
|
||||
|
||||
ClippingNode::ClippingNode()
|
||||
|
|
|
@ -540,8 +540,6 @@ CC_DEPRECATED_ATTRIBUTE typedef Bool CCBool;
|
|||
CC_DEPRECATED_ATTRIBUTE typedef Float CCFloat;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Double CCDouble;
|
||||
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 DataVisitor CCDataVisitor;
|
||||
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 Configuration CCConfiguration;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef PointArray CCPointArray;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef SetIterator CCSetIterator;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef RemoveSelf CCRemoveSelf;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef IMEDelegate CCIMEDelegate;
|
||||
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 GLProgram CCGLProgram;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Touch CCTouch;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Set CCSet;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Texture2D CCTexture2D;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Node CCNode;
|
||||
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 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
|
||||
|
||||
|
||||
|
|
|
@ -110,8 +110,7 @@ bool Director::init(void)
|
|||
|
||||
_notificationNode = nullptr;
|
||||
|
||||
_scenesStack = new Array();
|
||||
_scenesStack->initWithCapacity(15);
|
||||
_scenesStack.reserve(15);
|
||||
|
||||
// projection delegate if "Custom" projection is used
|
||||
_projectionDelegate = nullptr;
|
||||
|
@ -164,7 +163,6 @@ Director::~Director(void)
|
|||
|
||||
CC_SAFE_RELEASE(_runningScene);
|
||||
CC_SAFE_RELEASE(_notificationNode);
|
||||
CC_SAFE_RELEASE(_scenesStack);
|
||||
CC_SAFE_RELEASE(_scheduler);
|
||||
CC_SAFE_RELEASE(_actionManager);
|
||||
CC_SAFE_RELEASE(_eventDispatcher);
|
||||
|
@ -597,10 +595,10 @@ void Director::replaceScene(Scene *scene)
|
|||
CCASSERT(_runningScene, "Use runWithScene: instead to start the director");
|
||||
CCASSERT(scene != nullptr, "the scene should not be null");
|
||||
|
||||
unsigned int index = _scenesStack->count();
|
||||
int index = _scenesStack.size();
|
||||
|
||||
_sendCleanupToScene = true;
|
||||
_scenesStack->replaceObjectAtIndex(index - 1, scene);
|
||||
_scenesStack.replace(index - 1, scene);
|
||||
|
||||
_nextScene = scene;
|
||||
}
|
||||
|
@ -611,7 +609,7 @@ void Director::pushScene(Scene *scene)
|
|||
|
||||
_sendCleanupToScene = false;
|
||||
|
||||
_scenesStack->addObject(scene);
|
||||
_scenesStack.pushBack(scene);
|
||||
_nextScene = scene;
|
||||
}
|
||||
|
||||
|
@ -619,8 +617,8 @@ void Director::popScene(void)
|
|||
{
|
||||
CCASSERT(_runningScene != nullptr, "running scene should not null");
|
||||
|
||||
_scenesStack->removeLastObject();
|
||||
unsigned int c = _scenesStack->count();
|
||||
_scenesStack.popBack();
|
||||
int c = _scenesStack.size();
|
||||
|
||||
if (c == 0)
|
||||
{
|
||||
|
@ -629,7 +627,7 @@ void Director::popScene(void)
|
|||
else
|
||||
{
|
||||
_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)
|
||||
{
|
||||
CCASSERT(_runningScene != nullptr, "A running Scene is needed");
|
||||
int c = static_cast<int>(_scenesStack->count());
|
||||
int c = _scenesStack.size();
|
||||
|
||||
// level 0? -> end
|
||||
if (level == 0)
|
||||
|
@ -657,7 +655,7 @@ void Director::popToSceneStackLevel(int level)
|
|||
// pop stack until reaching desired level
|
||||
while (c > level)
|
||||
{
|
||||
Scene *current = (Scene*)_scenesStack->getLastObject();
|
||||
auto current = _scenesStack.back();
|
||||
|
||||
if (current->isRunning())
|
||||
{
|
||||
|
@ -666,11 +664,11 @@ void Director::popToSceneStackLevel(int level)
|
|||
}
|
||||
|
||||
current->cleanup();
|
||||
_scenesStack->removeLastObject();
|
||||
_scenesStack.popBack();
|
||||
--c;
|
||||
}
|
||||
|
||||
_nextScene = (Scene*)_scenesStack->getLastObject();
|
||||
_nextScene = _scenesStack.back();
|
||||
_sendCleanupToScene = false;
|
||||
}
|
||||
|
||||
|
@ -701,7 +699,7 @@ void Director::purgeDirector()
|
|||
|
||||
// remove all objects, but don't release it.
|
||||
// runWithScene might be executed after 'end'.
|
||||
_scenesStack->removeAllObjects();
|
||||
_scenesStack.clear();
|
||||
|
||||
stopAnimation();
|
||||
|
||||
|
@ -857,7 +855,7 @@ void Director::calculateMPF()
|
|||
}
|
||||
|
||||
// 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
|
||||
*datapointer = cc_fps_images_png;
|
||||
|
@ -880,7 +878,7 @@ void Director::createStatsLabel()
|
|||
Texture2D::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat();
|
||||
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
||||
unsigned char *data = nullptr;
|
||||
long dataLength = 0;
|
||||
ssize_t dataLength = 0;
|
||||
getFPSImageData(&data, &dataLength);
|
||||
|
||||
Image* image = new Image();
|
||||
|
@ -1037,9 +1035,6 @@ void DisplayLinkDirector::mainLoop()
|
|||
}
|
||||
else if (! _invalid)
|
||||
{
|
||||
// invoke call back from other thread
|
||||
ThreadHelper::doCallback();
|
||||
|
||||
drawScene();
|
||||
|
||||
// release the objects
|
||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
|||
#include "CCObject.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCGL.h"
|
||||
#include "kazmath/mat4.h"
|
||||
#include "CCLabelAtlas.h"
|
||||
|
@ -379,7 +379,7 @@ protected:
|
|||
void showStats();
|
||||
void createStatsLabel();
|
||||
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 */
|
||||
void calculateDeltaTime();
|
||||
|
@ -446,7 +446,7 @@ protected:
|
|||
bool _sendCleanupToScene;
|
||||
|
||||
/* scheduled scenes */
|
||||
Array* _scenesStack;
|
||||
Vector<Scene*> _scenesStack;
|
||||
|
||||
/* last time the main loop was updated */
|
||||
struct timeval *_lastUpdate;
|
||||
|
|
|
@ -142,7 +142,7 @@ DrawNode* DrawNode::create()
|
|||
return pRet;
|
||||
}
|
||||
|
||||
void DrawNode::ensureCapacity(long count)
|
||||
void DrawNode::ensureCapacity(int count)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
|
@ -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);
|
||||
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 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);
|
||||
|
||||
unsigned int triangle_count = 3*count - 2;
|
||||
unsigned int vertex_count = 3*triangle_count;
|
||||
auto triangle_count = 3*count - 2;
|
||||
auto vertex_count = 3*triangle_count;
|
||||
ensureCapacity(vertex_count);
|
||||
|
||||
V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
|
||||
V2F_C4B_T2F_Triangle *cursor = triangles;
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
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 v1 = __v2f(verts[j]);
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
* In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor)
|
||||
* @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. */
|
||||
void clear();
|
||||
|
@ -92,13 +92,13 @@ protected:
|
|||
virtual ~DrawNode();
|
||||
virtual bool init();
|
||||
|
||||
void ensureCapacity(long count);
|
||||
void ensureCapacity(int count);
|
||||
void render();
|
||||
|
||||
GLuint _vao;
|
||||
GLuint _vbo;
|
||||
|
||||
long _bufferCapacity;
|
||||
int _bufferCapacity;
|
||||
GLsizei _bufferCount;
|
||||
V2F_C4B_T2F *_buffer;
|
||||
|
||||
|
|
|
@ -190,17 +190,17 @@ EventDispatcher::~EventDispatcher()
|
|||
void EventDispatcher::visitTarget(Node* node)
|
||||
{
|
||||
int i = 0;
|
||||
Array* children = node->getChildren();
|
||||
int childrenCount = children ? children->count() : 0;
|
||||
auto& children = node->getChildren();
|
||||
|
||||
auto childrenCount = children.size();
|
||||
|
||||
if(childrenCount > 0)
|
||||
{
|
||||
|
||||
Node* child = nullptr;
|
||||
// visit children zOrder < 0
|
||||
for( ; i < childrenCount; i++ )
|
||||
{
|
||||
child = static_cast<Node*>( children->getObjectAtIndex(i) );
|
||||
child = children.at(i);
|
||||
|
||||
if ( child && child->getZOrder() < 0 )
|
||||
visitTarget(child);
|
||||
|
@ -212,7 +212,7 @@ void EventDispatcher::visitTarget(Node* node)
|
|||
|
||||
for( ; i < childrenCount; i++ )
|
||||
{
|
||||
child = static_cast<Node*>( children->getObjectAtIndex(i) );
|
||||
child = children.at(i);
|
||||
if (child)
|
||||
visitTarget(child);
|
||||
}
|
||||
|
@ -491,7 +491,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
|
|||
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
|
||||
auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners();
|
||||
|
||||
long i = 0;
|
||||
int i = 0;
|
||||
// priority < 0
|
||||
if (fixedPriorityListeners)
|
||||
{
|
||||
|
@ -527,7 +527,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
|
|||
if (!shouldStopPropagation)
|
||||
{
|
||||
// priority > 0
|
||||
for (; i < static_cast<long>(fixedPriorityListeners->size()); ++i)
|
||||
for (; i < fixedPriorityListeners->size(); ++i)
|
||||
{
|
||||
auto l = fixedPriorityListeners->at(i);
|
||||
|
||||
|
@ -976,7 +976,7 @@ void EventDispatcher::sortEventListenersOfFixedPriority(EventListener::ListenerI
|
|||
});
|
||||
|
||||
// FIXME: Should use binary search
|
||||
long index = 0;
|
||||
int index = 0;
|
||||
for (auto& listener : *fixedlisteners)
|
||||
{
|
||||
if (listener->getFixedPriority() >= 0)
|
||||
|
@ -1080,7 +1080,7 @@ void EventDispatcher::removeCustomEventListeners(const std::string& customEventN
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -136,12 +136,12 @@ private:
|
|||
|
||||
inline std::vector<EventListener*>* getFixedPriorityListeners() const { return _fixedListeners; };
|
||||
inline std::vector<EventListener*>* getSceneGraphPriorityListeners() const { return _sceneGraphListeners; };
|
||||
inline long getGt0Index() const { return _gt0Index; };
|
||||
inline void setGt0Index(long index) { _gt0Index = index; };
|
||||
inline int getGt0Index() const { return _gt0Index; };
|
||||
inline void setGt0Index(int index) { _gt0Index = index; };
|
||||
private:
|
||||
std::vector<EventListener*>* _fixedListeners;
|
||||
std::vector<EventListener*>* _sceneGraphListeners;
|
||||
long _gt0Index;
|
||||
int _gt0Index;
|
||||
};
|
||||
|
||||
/** Adds event listener with item */
|
||||
|
|
|
@ -141,7 +141,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
}
|
||||
|
||||
float scaleFactor = CC_CONTENT_SCALE_FACTOR();
|
||||
int newLetterCount = fontDefs.size();
|
||||
size_t newLetterCount = fontDefs.size();
|
||||
float glyphWidth;
|
||||
for (int i = 0; i < newLetterCount; ++i)
|
||||
{
|
||||
|
|
|
@ -149,7 +149,7 @@ FontAtlas * FontFNT::createFontAtlas()
|
|||
if (!_configuration->_fontDefDictionary)
|
||||
return nullptr;
|
||||
|
||||
int numGlyphs = _configuration->_characterSet->size();
|
||||
size_t numGlyphs = _configuration->_characterSet->size();
|
||||
if (!numGlyphs)
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
|||
{
|
||||
FT_Face face;
|
||||
|
||||
long len = 0;
|
||||
ssize_t len = 0;
|
||||
_ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len);
|
||||
if (!_ttfData)
|
||||
return false;
|
||||
|
@ -297,7 +297,7 @@ int FontFreeType::getAdvanceForChar(unsigned short theChar) const
|
|||
return 0;
|
||||
|
||||
// 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
|
||||
|
@ -316,7 +316,7 @@ int FontFreeType::getBearingXForChar(unsigned short theChar) const
|
|||
if (FT_Load_Glyph(_fontRef, glyphIndex, FT_LOAD_DEFAULT))
|
||||
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
|
||||
|
@ -346,12 +346,12 @@ int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsign
|
|||
if (FT_Get_Kerning( _fontRef, glyphIndex1, glyphIndex2, FT_KERNING_DEFAULT, &kerning))
|
||||
return 0;
|
||||
|
||||
return (kerning.x >> 6);
|
||||
return (static_cast<int>(kerning.x >> 6));
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -113,13 +113,13 @@ bool GridBase::initWithSize(const Size& gridSize)
|
|||
Director *pDirector = Director::getInstance();
|
||||
Size s = pDirector->getWinSizeInPixels();
|
||||
|
||||
unsigned long POTWide = ccNextPOT((unsigned int)s.width);
|
||||
unsigned long POTHigh = ccNextPOT((unsigned int)s.height);
|
||||
auto POTWide = ccNextPOT((unsigned int)s.width);
|
||||
auto POTHigh = ccNextPOT((unsigned int)s.height);
|
||||
|
||||
// we only use rgba8888
|
||||
Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888;
|
||||
|
||||
long dataLen = POTWide * POTHigh * 4;
|
||||
auto dataLen = POTWide * POTHigh * 4;
|
||||
void *data = calloc(dataLen, 1);
|
||||
if (! data)
|
||||
{
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
|
||||
protected:
|
||||
bool _active;
|
||||
long _reuseGrid;
|
||||
int _reuseGrid;
|
||||
Size _gridSize;
|
||||
Texture2D *_texture;
|
||||
Point _step;
|
||||
|
|
|
@ -249,19 +249,16 @@ void Label::alignText()
|
|||
LabelTextFormatter::alignText(this);
|
||||
|
||||
int strLen = cc_wcslen(_currentUTF16String);
|
||||
if (_children && _children->count() != 0)
|
||||
|
||||
_children.forEach([this, &strLen](Node* child){
|
||||
if (child)
|
||||
{
|
||||
for (auto child: *_children)
|
||||
{
|
||||
Node* pNode = static_cast<Node*>( child );
|
||||
if (pNode)
|
||||
{
|
||||
int tag = pNode->getTag();
|
||||
int tag = child->getTag();
|
||||
if(tag < 0 || tag >= strLen)
|
||||
SpriteBatchNode::removeChild(pNode, true);
|
||||
}
|
||||
}
|
||||
SpriteBatchNode::removeChild(child, true);
|
||||
}
|
||||
});
|
||||
|
||||
_reusedLetter->setBatchNode(nullptr);
|
||||
|
||||
int vaildIndex = 0;
|
||||
|
@ -376,7 +373,7 @@ Sprite * Label::updateSpriteWithLetterDefinition(Sprite *spriteToUpdate, const F
|
|||
{
|
||||
spriteToUpdate->setBatchNode(this);
|
||||
spriteToUpdate->setTexture(theTexture);
|
||||
spriteToUpdate->setDisplayFrame(frame);
|
||||
spriteToUpdate->setSpriteFrame(frame);
|
||||
spriteToUpdate->setAnchorPoint(Point(theDefinition.anchorX, theDefinition.anchorY));
|
||||
}
|
||||
|
||||
|
@ -594,21 +591,18 @@ bool Label::isOpacityModifyRGB() const
|
|||
void Label::setOpacityModifyRGB(bool isOpacityModifyRGB)
|
||||
{
|
||||
_isOpacityModifyRGB = isOpacityModifyRGB;
|
||||
if (_children && _children->count() != 0)
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
if (child)
|
||||
{
|
||||
for (auto child: *_children)
|
||||
{
|
||||
Node* pNode = static_cast<Node*>( child );
|
||||
if (pNode)
|
||||
{
|
||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(pNode);
|
||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (pRGBAProtocol)
|
||||
{
|
||||
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_reusedLetter->setOpacityModifyRGB(true);
|
||||
}
|
||||
|
||||
|
@ -640,13 +634,13 @@ void Label::updateDisplayedOpacity(GLubyte parentOpacity)
|
|||
{
|
||||
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
||||
|
||||
for (auto child: *_children)
|
||||
{
|
||||
_children.forEach([this](Node* child){
|
||||
Sprite *item = static_cast<Sprite*>( child );
|
||||
item->updateDisplayedOpacity(_displayedOpacity);
|
||||
}
|
||||
});
|
||||
|
||||
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
||||
int count = _textureAtlas->getTotalQuads();
|
||||
auto count = _textureAtlas->getTotalQuads();
|
||||
Color4B color4( _displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity );
|
||||
if (_isOpacityModifyRGB)
|
||||
{
|
||||
|
@ -706,14 +700,13 @@ void Label::updateDisplayedColor(const Color3B& parentColor)
|
|||
_displayedColor.g = _realColor.g * parentColor.g/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 );
|
||||
item->updateDisplayedColor(_displayedColor);
|
||||
}
|
||||
});
|
||||
|
||||
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
||||
int count = _textureAtlas->getTotalQuads();
|
||||
auto count = _textureAtlas->getTotalQuads();
|
||||
Color4B color4( _displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity );
|
||||
|
||||
// special opacity for premultiplied textures
|
||||
|
|
|
@ -42,7 +42,7 @@ NS_CC_BEGIN
|
|||
|
||||
//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();
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
this->setString(string);
|
||||
|
@ -112,7 +112,7 @@ bool LabelAtlas::initWithString(const std::string& theString, const std::string&
|
|||
//CCLabelAtlas - Atlas generation
|
||||
void LabelAtlas::updateAtlasValues()
|
||||
{
|
||||
size_t n = _string.length();
|
||||
auto n = _string.length();
|
||||
|
||||
const unsigned char *s = (unsigned char*)_string.c_str();
|
||||
|
||||
|
@ -127,9 +127,9 @@ void LabelAtlas::updateAtlasValues()
|
|||
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();
|
||||
for(long i = 0; i < static_cast<long>(n); i++) {
|
||||
for(int i = 0; i < n; i++) {
|
||||
|
||||
unsigned char a = s[i] - _mapStartChar;
|
||||
float row = (float) (a % _itemsPerRow);
|
||||
|
@ -177,9 +177,9 @@ void LabelAtlas::updateAtlasValues()
|
|||
}
|
||||
if (n > 0 ){
|
||||
_textureAtlas->setDirty(true);
|
||||
long totalQuads = _textureAtlas->getTotalQuads();
|
||||
if (static_cast<long>(n) > totalQuads) {
|
||||
_textureAtlas->increaseTotalQuadsWith(n - totalQuads);
|
||||
auto totalQuads = _textureAtlas->getTotalQuads();
|
||||
if (n > totalQuads) {
|
||||
_textureAtlas->increaseTotalQuadsWith(static_cast<int>(n - totalQuads));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,10 +187,10 @@ void LabelAtlas::updateAtlasValues()
|
|||
//CCLabelAtlas - LabelProtocol
|
||||
void LabelAtlas::setString(const std::string &label)
|
||||
{
|
||||
size_t len = label.size();
|
||||
if (static_cast<long>(len) > _textureAtlas->getTotalQuads())
|
||||
auto len = label.size();
|
||||
if (len > _textureAtlas->getTotalQuads())
|
||||
{
|
||||
_textureAtlas->resizeCapacity(len);
|
||||
_textureAtlas->resizeCapacity(static_cast<int>(len));
|
||||
}
|
||||
_string.clear();
|
||||
_string = label;
|
||||
|
@ -200,7 +200,7 @@ void LabelAtlas::setString(const std::string &label)
|
|||
|
||||
this->setContentSize(s);
|
||||
|
||||
_quadsToDraw = len;
|
||||
_quadsToDraw = static_cast<int>(len);
|
||||
}
|
||||
|
||||
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 */
|
||||
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
|
||||
@since v2.0
|
||||
|
@ -75,7 +75,7 @@ public:
|
|||
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 */
|
||||
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
|
||||
@since v2.0
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
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 */
|
||||
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
|
||||
virtual void updateAtlasValues();
|
||||
|
@ -99,7 +99,7 @@ protected:
|
|||
// string to render
|
||||
std::string _string;
|
||||
// the first char in the charmap
|
||||
long _mapStartChar;
|
||||
int _mapStartChar;
|
||||
};
|
||||
|
||||
// end of GUI group
|
||||
|
|
|
@ -267,8 +267,8 @@ void CCBMFontConfiguration::parseImageFileName(std::string line, const std::stri
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// page ID. Sanity check
|
||||
long index = line.find('=')+1;
|
||||
long index2 = line.find(' ', index);
|
||||
auto index = line.find('=')+1;
|
||||
auto index2 = line.find(' ', index);
|
||||
std::string value = line.substr(index, index2-index);
|
||||
CCASSERT(atoi(value.c_str()) == 0, "LabelBMFont file could not be found");
|
||||
// file
|
||||
|
@ -288,8 +288,8 @@ void CCBMFontConfiguration::parseInfoArguments(std::string line)
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// padding
|
||||
long index = line.find("padding=");
|
||||
long index2 = line.find(' ', index);
|
||||
auto index = line.find("padding=");
|
||||
auto index2 = line.find(' ', 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);
|
||||
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
|
||||
long index = line.find("lineHeight=");
|
||||
long index2 = line.find(' ', index);
|
||||
auto index = line.find("lineHeight=");
|
||||
auto index2 = line.find(' ', index);
|
||||
std::string value = line.substr(index, index2-index);
|
||||
sscanf(value.c_str(), "lineHeight=%d", &_commonHeight);
|
||||
// scaleW. sanity check
|
||||
|
@ -334,8 +334,8 @@ void CCBMFontConfiguration::parseCharacterDefinition(std::string line, ccBMFontD
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Character ID
|
||||
long index = line.find("id=");
|
||||
long index2 = line.find(' ', index);
|
||||
auto index = line.find("id=");
|
||||
auto index2 = line.find(' ', index);
|
||||
std::string value = line.substr(index, index2-index);
|
||||
sscanf(value.c_str(), "id=%u", &characterDefinition->charID);
|
||||
|
||||
|
@ -385,8 +385,8 @@ void CCBMFontConfiguration::parseKerningEntry(std::string line)
|
|||
|
||||
// first
|
||||
int first;
|
||||
long index = line.find("first=");
|
||||
long index2 = line.find(' ', index);
|
||||
auto index = line.find("first=");
|
||||
auto index2 = line.find(' ', index);
|
||||
std::string value = line.substr(index, index2-index);
|
||||
sscanf(value.c_str(), "first=%d", &first);
|
||||
|
||||
|
@ -494,7 +494,7 @@ bool LabelBMFont::initWithString(const std::string& theString, const std::string
|
|||
texture->autorelease();
|
||||
}
|
||||
|
||||
if (SpriteBatchNode::initWithTexture(texture, theString.size()))
|
||||
if (SpriteBatchNode::initWithTexture(texture, static_cast<int>(theString.size())))
|
||||
{
|
||||
_width = width;
|
||||
_alignment = alignment;
|
||||
|
@ -746,18 +746,10 @@ void LabelBMFont::setString(unsigned short *newString, bool needUpdateLabel)
|
|||
CC_SAFE_DELETE_ARRAY(tmp);
|
||||
}
|
||||
|
||||
if (_children && _children->count() != 0)
|
||||
{
|
||||
Object* child;
|
||||
CCARRAY_FOREACH(_children, child)
|
||||
{
|
||||
Node* pNode = static_cast<Node*>( child );
|
||||
if (pNode)
|
||||
{
|
||||
pNode->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
_children.forEach([](Node* child){
|
||||
child->setVisible(false);
|
||||
});
|
||||
|
||||
this->createFontChars();
|
||||
|
||||
if (needUpdateLabel) {
|
||||
|
@ -830,22 +822,16 @@ void LabelBMFont::setOpacity(GLubyte opacity)
|
|||
void LabelBMFont::setOpacityModifyRGB(bool var)
|
||||
{
|
||||
_isOpacityModifyRGB = var;
|
||||
if (_children && _children->count() != 0)
|
||||
_children.forEach([this](Node* child){
|
||||
if (child)
|
||||
{
|
||||
Object* child;
|
||||
CCARRAY_FOREACH(_children, child)
|
||||
{
|
||||
Node* pNode = static_cast<Node*>( child );
|
||||
if (pNode)
|
||||
{
|
||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(pNode);
|
||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (pRGBAProtocol)
|
||||
{
|
||||
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
bool LabelBMFont::isOpacityModifyRGB() const
|
||||
{
|
||||
|
@ -854,28 +840,24 @@ bool LabelBMFont::isOpacityModifyRGB() const
|
|||
|
||||
void LabelBMFont::updateDisplayedOpacity(GLubyte parentOpacity)
|
||||
{
|
||||
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
||||
_displayedOpacity = _realOpacity * parentOpacity/255.0f;
|
||||
|
||||
Object* pObj;
|
||||
CCARRAY_FOREACH(_children, pObj)
|
||||
{
|
||||
Sprite *item = static_cast<Sprite*>( pObj );
|
||||
_children.forEach([this](Node* child){
|
||||
Sprite *item = static_cast<Sprite*>( child );
|
||||
item->updateDisplayedOpacity(_displayedOpacity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LabelBMFont::updateDisplayedColor(const Color3B& parentColor)
|
||||
{
|
||||
_displayedColor.r = _realColor.r * parentColor.r/255.0;
|
||||
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
||||
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
||||
_displayedColor.r = _realColor.r * parentColor.r/255.0f;
|
||||
_displayedColor.g = _realColor.g * parentColor.g/255.0f;
|
||||
_displayedColor.b = _realColor.b * parentColor.b/255.0f;
|
||||
|
||||
Object* pObj;
|
||||
CCARRAY_FOREACH(_children, pObj)
|
||||
{
|
||||
Sprite *item = static_cast<Sprite*>( pObj );
|
||||
_children.forEach([this](Node* child){
|
||||
Sprite *item = static_cast<Sprite*>( child );
|
||||
item->updateDisplayedColor(_displayedColor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool LabelBMFont::isCascadeColorEnabled() const
|
||||
|
@ -917,7 +899,7 @@ void LabelBMFont::updateLabel()
|
|||
{
|
||||
// Step 1: Make multiline
|
||||
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;
|
||||
multiline_string.reserve( stringLength );
|
||||
vector<unsigned short> last_word;
|
||||
|
@ -928,8 +910,8 @@ void LabelBMFont::updateLabel()
|
|||
float startOfLine = -1, startOfWord = -1;
|
||||
int skip = 0;
|
||||
|
||||
Array* children = getChildren();
|
||||
for (int j = 0; j < children->count(); j++)
|
||||
auto children = getChildren();
|
||||
for (int j = 0; j < children.size(); j++)
|
||||
{
|
||||
Sprite* characterSprite;
|
||||
unsigned int justSkipped = 0;
|
||||
|
@ -1068,7 +1050,7 @@ void LabelBMFont::updateLabel()
|
|||
|
||||
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];
|
||||
|
||||
for (int j = 0; j < size; ++j)
|
||||
|
@ -1096,14 +1078,14 @@ void LabelBMFont::updateLabel()
|
|||
if (_string[ctr] == '\n' || _string[ctr] == 0)
|
||||
{
|
||||
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 (line_length == 0)
|
||||
{
|
||||
lineNumber++;
|
||||
continue;
|
||||
}
|
||||
int index = i + line_length - 1 + lineNumber;
|
||||
int index = static_cast<int>(i + line_length - 1 + lineNumber);
|
||||
if (index < 0) continue;
|
||||
|
||||
Sprite* lastChar = static_cast<Sprite*>( getChildByTag(index) );
|
||||
|
|
|
@ -39,7 +39,7 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
|
|||
{
|
||||
// Step 1: Make multiline
|
||||
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;
|
||||
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());
|
||||
|
||||
int size = multiline_string.size();
|
||||
size_t size = multiline_string.size();
|
||||
unsigned short* strNew = new unsigned short[size + 1];
|
||||
|
||||
for (int j = 0; j < size; ++j)
|
||||
|
@ -231,7 +231,7 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
|||
if (currentChar == '\n' || currentChar == 0)
|
||||
{
|
||||
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 (lineLength == 0)
|
||||
|
@ -239,7 +239,7 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
|||
lineNumber++;
|
||||
continue;
|
||||
}
|
||||
int index = i + lineLength - 1 + lineNumber;
|
||||
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
||||
if (index < 0) continue;
|
||||
|
||||
if(currentChar == 0)
|
||||
|
|
|
@ -499,15 +499,13 @@ void LayerRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
|
|||
|
||||
if (_cascadeOpacityEnabled)
|
||||
{
|
||||
Object *obj = NULL;
|
||||
CCARRAY_FOREACH(_children, obj)
|
||||
{
|
||||
_children.forEach([this](Node* obj){
|
||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
||||
if (item)
|
||||
{
|
||||
item->updateDisplayedOpacity(_displayedOpacity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,15 +517,13 @@ void LayerRGBA::updateDisplayedColor(const Color3B& parentColor)
|
|||
|
||||
if (_cascadeColorEnabled)
|
||||
{
|
||||
Object *obj = NULL;
|
||||
CCARRAY_FOREACH(_children, obj)
|
||||
{
|
||||
_children.forEach([this](Node* obj){
|
||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
||||
if (item)
|
||||
{
|
||||
item->updateDisplayedColor(_displayedColor);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -920,19 +916,14 @@ void LayerGradient::setCompressedInterpolation(bool compress)
|
|||
|
||||
LayerMultiplex::LayerMultiplex()
|
||||
: _enabledLayer(0)
|
||||
, _layers(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
LayerMultiplex::~LayerMultiplex()
|
||||
{
|
||||
if (_layers)
|
||||
{
|
||||
for (auto& item : *_layers)
|
||||
{
|
||||
static_cast<Layer*>(item)->cleanup();
|
||||
}
|
||||
_layers->release();
|
||||
}
|
||||
_layers.forEach([](Layer* layer){
|
||||
layer->cleanup();
|
||||
});
|
||||
}
|
||||
|
||||
LayerMultiplex * LayerMultiplex::create(Layer * layer, ...)
|
||||
|
@ -971,7 +962,7 @@ LayerMultiplex* LayerMultiplex::create()
|
|||
return pRet;
|
||||
}
|
||||
|
||||
LayerMultiplex* LayerMultiplex::createWithArray(Array* arrayOfLayers)
|
||||
LayerMultiplex* LayerMultiplex::createWithArray(const Vector<Layer*>& arrayOfLayers)
|
||||
{
|
||||
LayerMultiplex* pRet = new LayerMultiplex();
|
||||
if (pRet && pRet->initWithArray(arrayOfLayers))
|
||||
|
@ -987,17 +978,13 @@ LayerMultiplex* LayerMultiplex::createWithArray(Array* arrayOfLayers)
|
|||
|
||||
void LayerMultiplex::addLayer(Layer* layer)
|
||||
{
|
||||
CCASSERT(_layers, "");
|
||||
_layers->addObject(layer);
|
||||
_layers.pushBack(layer);
|
||||
}
|
||||
|
||||
bool LayerMultiplex::init()
|
||||
{
|
||||
if (Layer::init())
|
||||
{
|
||||
_layers = Array::create();
|
||||
_layers->retain();
|
||||
|
||||
_enabledLayer = 0;
|
||||
return true;
|
||||
}
|
||||
|
@ -1008,34 +995,32 @@ bool LayerMultiplex::initWithLayers(Layer *layer, va_list params)
|
|||
{
|
||||
if (Layer::init())
|
||||
{
|
||||
_layers = Array::createWithCapacity(5);
|
||||
_layers->retain();
|
||||
_layers->addObject(layer);
|
||||
_layers.reserve(5);
|
||||
_layers.pushBack(layer);
|
||||
|
||||
Layer *l = va_arg(params,Layer*);
|
||||
while( l ) {
|
||||
_layers->addObject(l);
|
||||
_layers.pushBack(l);
|
||||
l = va_arg(params,Layer*);
|
||||
}
|
||||
|
||||
_enabledLayer = 0;
|
||||
this->addChild((Node*)_layers->getObjectAtIndex(_enabledLayer));
|
||||
this->addChild(_layers.at(_enabledLayer));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LayerMultiplex::initWithArray(Array* arrayOfLayers)
|
||||
bool LayerMultiplex::initWithArray(const Vector<Layer*>& arrayOfLayers)
|
||||
{
|
||||
if (Layer::init())
|
||||
{
|
||||
_layers = Array::createWithCapacity(arrayOfLayers->count());
|
||||
_layers->addObjectsFromArray(arrayOfLayers);
|
||||
_layers->retain();
|
||||
_layers.reserve(arrayOfLayers.size());
|
||||
_layers.insert(arrayOfLayers);
|
||||
|
||||
_enabledLayer = 0;
|
||||
this->addChild((Node*)_layers->getObjectAtIndex(_enabledLayer));
|
||||
this->addChild(_layers.at(_enabledLayer));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1043,27 +1028,26 @@ bool LayerMultiplex::initWithArray(Array* arrayOfLayers)
|
|||
|
||||
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;
|
||||
|
||||
this->addChild((Node*)_layers->getObjectAtIndex(n));
|
||||
this->addChild(_layers.at(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->replaceObjectAtIndex(_enabledLayer, NULL);
|
||||
_layers.replace(_enabledLayer, nullptr);
|
||||
|
||||
_enabledLayer = n;
|
||||
|
||||
this->addChild((Node*)_layers->getObjectAtIndex(n));
|
||||
this->addChild(_layers.at(n));
|
||||
}
|
||||
|
||||
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 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 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 ccTouchesCancelled(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 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);}
|
||||
|
||||
/* 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.
|
||||
|
@ -412,7 +412,7 @@ public:
|
|||
@since v2.1
|
||||
* @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.
|
||||
* @code
|
||||
|
@ -430,6 +430,21 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -450,22 +465,13 @@ public:
|
|||
/** initializes a MultiplexLayer with an array of layers
|
||||
@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;
|
||||
Array* _layers;
|
||||
Vector<Layer*> _layers;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(LayerMultiplex);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ THE SOFTWARE.
|
|||
#include "CCInteger.h"
|
||||
#include "CCEventListenerTouch.h"
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
@ -38,18 +37,6 @@ using namespace std;
|
|||
|
||||
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
|
||||
{
|
||||
kDefaultPadding = 5,
|
||||
|
@ -81,36 +68,36 @@ Menu * Menu::create(MenuItem* item, ...)
|
|||
return pRet;
|
||||
}
|
||||
|
||||
Menu* Menu::createWithArray(Array* pArrayOfItems)
|
||||
Menu* Menu::createWithArray(const Vector<MenuItem*>& arrayOfItems)
|
||||
{
|
||||
Menu *pRet = new Menu();
|
||||
if (pRet && pRet->initWithArray(pArrayOfItems))
|
||||
auto ret = new Menu();
|
||||
if (ret && ret->initWithArray(arrayOfItems))
|
||||
{
|
||||
pRet->autorelease();
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Menu* Menu::createWithItems(MenuItem* item, va_list args)
|
||||
{
|
||||
Array* pArray = NULL;
|
||||
Vector<MenuItem*> items;
|
||||
if( item )
|
||||
{
|
||||
pArray = Array::create(item, NULL);
|
||||
items.pushBack(item);
|
||||
MenuItem *i = va_arg(args, MenuItem*);
|
||||
while(i)
|
||||
{
|
||||
pArray->addObject(i);
|
||||
items.pushBack(i);
|
||||
i = va_arg(args, MenuItem*);
|
||||
}
|
||||
}
|
||||
|
||||
return Menu::createWithArray(pArray);
|
||||
return Menu::createWithArray(items);
|
||||
}
|
||||
|
||||
Menu* Menu::createWithItem(MenuItem* item)
|
||||
|
@ -120,10 +107,10 @@ Menu* Menu::createWithItem(MenuItem* item)
|
|||
|
||||
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())
|
||||
{
|
||||
|
@ -137,17 +124,13 @@ bool Menu::initWithArray(Array* pArrayOfItems)
|
|||
|
||||
setPosition(Point(s.width/2, s.height/2));
|
||||
|
||||
if (pArrayOfItems != NULL)
|
||||
{
|
||||
int z=0;
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(pArrayOfItems, pObj)
|
||||
|
||||
for (auto& item : arrayOfItems)
|
||||
{
|
||||
MenuItem* item = static_cast<MenuItem*>(pObj);
|
||||
this->addChild(item, z);
|
||||
z++;
|
||||
}
|
||||
}
|
||||
|
||||
_selectedItem = NULL;
|
||||
_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)
|
||||
{
|
||||
_state = Menu::State::TRACKING_TOUCH;
|
||||
|
@ -282,7 +265,7 @@ void Menu::onTouchCancelled(Touch* touch, Event* event)
|
|||
void Menu::onTouchMoved(Touch* touch, Event* event)
|
||||
{
|
||||
CCASSERT(_state == Menu::State::TRACKING_TOUCH, "[Menu ccTouchMoved] -- invalid state");
|
||||
MenuItem *currentItem = this->itemForTouch(touch);
|
||||
MenuItem *currentItem = this->getItemForTouch(touch);
|
||||
if (currentItem != _selectedItem)
|
||||
{
|
||||
if (_selectedItem)
|
||||
|
@ -306,33 +289,23 @@ void Menu::alignItemsVertically()
|
|||
void Menu::alignItemsVerticallyWithPadding(float padding)
|
||||
{
|
||||
float height = -padding;
|
||||
if (_children && _children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Node* child = dynamic_cast<Node*>(pObject);
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
height += child->getContentSize().height * child->getScaleY() + padding;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
float y = height / 2.0f;
|
||||
if (_children && _children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Node* child = dynamic_cast<Node*>(pObject);
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
child->setPosition(Point(0, y - child->getContentSize().height * child->getScaleY() / 2.0f));
|
||||
y -= child->getContentSize().height * child->getScaleY() + padding;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Menu::alignItemsHorizontally(void)
|
||||
|
@ -342,35 +315,23 @@ void Menu::alignItemsHorizontally(void)
|
|||
|
||||
void Menu::alignItemsHorizontallyWithPadding(float padding)
|
||||
{
|
||||
|
||||
float width = -padding;
|
||||
if (_children && _children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Node* child = dynamic_cast<Node*>(pObject);
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
width += child->getContentSize().width * child->getScaleX() + padding;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
float x = -width / 2.0f;
|
||||
if (_children && _children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Node* child = dynamic_cast<Node*>(pObject);
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
child->setPosition(Point(x + child->getContentSize().width * child->getScaleX() / 2.0f, 0));
|
||||
x += child->getContentSize().width * child->getScaleX() + padding;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Menu::alignItemsInColumns(int columns, ...)
|
||||
|
@ -386,36 +347,29 @@ void Menu::alignItemsInColumns(int columns, ...)
|
|||
void Menu::alignItemsInColumns(int columns, va_list args)
|
||||
{
|
||||
CCASSERT(columns >= 0, "Columns must be >= 0");
|
||||
Array* rows = Array::create();
|
||||
ValueVector rows;
|
||||
while (columns)
|
||||
{
|
||||
rows->addObject(Integer::create(columns));
|
||||
rows.push_back(Value(columns));
|
||||
columns = va_arg(args, int);
|
||||
}
|
||||
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;
|
||||
unsigned int row = 0;
|
||||
unsigned int rowHeight = 0;
|
||||
unsigned int columnsOccupied = 0;
|
||||
unsigned int rowColumns;
|
||||
int row = 0;
|
||||
int rowHeight = 0;
|
||||
int columnsOccupied = 0;
|
||||
int rowColumns = 0;
|
||||
|
||||
if (_children && _children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Node* child = dynamic_cast<Node*>(pObject);
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
CCASSERT(row < rows.size(), "");
|
||||
|
||||
rowColumns = rows[row];
|
||||
rowColumns = rows[row].asInt();
|
||||
// can not have zero columns on a row
|
||||
CCASSERT(rowColumns, "");
|
||||
|
||||
|
@ -432,8 +386,7 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
|||
++row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// check if too many rows/columns for available menu items
|
||||
CCASSERT(! columnsOccupied, "");
|
||||
|
@ -447,17 +400,14 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
|||
float x = 0.0;
|
||||
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 (rowColumns == 0)
|
||||
{
|
||||
rowColumns = rows[row];
|
||||
rowColumns = rows[row].asInt();
|
||||
w = winSize.width / (1 + rowColumns);
|
||||
x = w;
|
||||
}
|
||||
|
@ -482,7 +432,7 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Menu::alignItemsInRows(int rows, ...)
|
||||
|
@ -497,41 +447,34 @@ void Menu::alignItemsInRows(int rows, ...)
|
|||
|
||||
void Menu::alignItemsInRows(int rows, va_list args)
|
||||
{
|
||||
Array* pArray = Array::create();
|
||||
ValueVector array;
|
||||
while (rows)
|
||||
{
|
||||
pArray->addObject(Integer::create(rows));
|
||||
array.push_back(Value(rows));
|
||||
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<unsigned int> columnWidths;
|
||||
vector<unsigned int> columnHeights;
|
||||
vector<int> columnWidths;
|
||||
vector<int> columnHeights;
|
||||
|
||||
int width = -10;
|
||||
int columnHeight = -5;
|
||||
unsigned int column = 0;
|
||||
unsigned int columnWidth = 0;
|
||||
unsigned int rowsOccupied = 0;
|
||||
unsigned int columnRows;
|
||||
int column = 0;
|
||||
int columnWidth = 0;
|
||||
int rowsOccupied = 0;
|
||||
int columnRows;
|
||||
|
||||
if (_children && _children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Node* child = dynamic_cast<Node*>(pObject);
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
// check if too many menu items for the amount of rows/columns
|
||||
CCASSERT(column < columns.size(), "");
|
||||
|
||||
columnRows = columns[column];
|
||||
columnRows = columns[column].asInt();
|
||||
// can't have zero rows on a column
|
||||
CCASSERT(columnRows, "");
|
||||
|
||||
|
@ -554,8 +497,7 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
|||
++column;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// check if too many rows/columns for available menu items.
|
||||
CCASSERT(! rowsOccupied, "");
|
||||
|
@ -568,17 +510,12 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
|||
float x = (float)(-width / 2);
|
||||
float y = 0.0;
|
||||
|
||||
if (_children && _children->count() > 0)
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Node* child = dynamic_cast<Node*>(pObject);
|
||||
_children.forEach([&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
if (columnRows == 0)
|
||||
{
|
||||
columnRows = columns[column];
|
||||
columnRows = columns[column].asInt();
|
||||
y = (float) columnHeights[column];
|
||||
}
|
||||
|
||||
|
@ -601,20 +538,18 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
|
|||
++column;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
MenuItem* Menu::itemForTouch(Touch *touch)
|
||||
MenuItem* Menu::getItemForTouch(Touch *touch)
|
||||
{
|
||||
Point touchLocation = touch->getLocation();
|
||||
|
||||
if (_children && _children->count() > 0)
|
||||
if (!_children.empty())
|
||||
{
|
||||
Object* pObject = NULL;
|
||||
CCARRAY_FOREACH_REVERSE(_children, pObject)
|
||||
for (auto iter = _children.crbegin(); iter != _children.crend(); ++iter)
|
||||
{
|
||||
MenuItem* child = dynamic_cast<MenuItem*>(pObject);
|
||||
MenuItem* child = dynamic_cast<MenuItem*>(*iter);
|
||||
if (child && child->isVisible() && child->isEnabled())
|
||||
{
|
||||
Point local = child->convertToNodeSpace(touchLocation);
|
||||
|
|
|
@ -27,8 +27,9 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCMenuItem.h"
|
||||
#include "CCLayer.h"
|
||||
|
||||
#include "CCVector.h"
|
||||
#include "CCEventTouch.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -63,7 +64,7 @@ public:
|
|||
static Menu* create(MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
|
||||
/** 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
|
||||
* other items. It is used for script, it can't init with undetermined
|
||||
|
@ -91,12 +92,12 @@ public:
|
|||
/** align items in rows of columns */
|
||||
void alignItemsInColumns(int columns, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
void alignItemsInColumns(int columns, va_list args);
|
||||
void alignItemsInColumnsWithArray(Array* rows);
|
||||
void alignItemsInColumnsWithArray(const ValueVector& rows);
|
||||
|
||||
/** align items in columns of rows */
|
||||
void alignItemsInRows(int rows, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
void alignItemsInRows(int rows, va_list args);
|
||||
void alignItemsInRowsWithArray(Array* columns);
|
||||
void alignItemsInRowsWithArray(const ValueVector& columns);
|
||||
|
||||
virtual bool isEnabled() const { return _enabled; }
|
||||
virtual void setEnabled(bool value) { _enabled = value; };
|
||||
|
@ -129,12 +130,12 @@ protected:
|
|||
bool init();
|
||||
|
||||
/** 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 */
|
||||
bool _enabled;
|
||||
|
||||
MenuItem* itemForTouch(Touch * touch);
|
||||
MenuItem* getItemForTouch(Touch * touch);
|
||||
State _state;
|
||||
MenuItem *_selectedItem;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static long _globalFontSize = kItemSize;
|
||||
static int _globalFontSize = kItemSize;
|
||||
static std::string _globalFontName = "Marker Felt";
|
||||
static bool _globalFontNameRelease = false;
|
||||
|
||||
|
@ -310,13 +310,13 @@ void MenuItemLabel::setEnabled(bool enabled)
|
|||
//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);
|
||||
}
|
||||
|
||||
// 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();
|
||||
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
||||
|
@ -324,7 +324,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* cha
|
|||
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();
|
||||
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, callback);
|
||||
|
@ -333,14 +333,14 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st
|
|||
}
|
||||
|
||||
// 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;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
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");
|
||||
LabelAtlas *label = new LabelAtlas();
|
||||
|
@ -357,12 +357,12 @@ bool MenuItemAtlasFont::initWithString(const std::string& value, const std::stri
|
|||
//CCMenuItemFont
|
||||
//
|
||||
|
||||
void MenuItemFont::setFontSize(long s)
|
||||
void MenuItemFont::setFontSize(int s)
|
||||
{
|
||||
_globalFontSize = s;
|
||||
}
|
||||
|
||||
long MenuItemFont::getFontSize()
|
||||
int MenuItemFont::getFontSize()
|
||||
{
|
||||
return _globalFontSize;
|
||||
}
|
||||
|
@ -449,13 +449,13 @@ void MenuItemFont::recreateLabel()
|
|||
this->setLabel(label);
|
||||
}
|
||||
|
||||
void MenuItemFont::setFontSizeObj(long s)
|
||||
void MenuItemFont::setFontSizeObj(int s)
|
||||
{
|
||||
_fontSize = s;
|
||||
recreateLabel();
|
||||
}
|
||||
|
||||
long MenuItemFont::getFontSizeObj() const
|
||||
int MenuItemFont::getFontSizeObj() const
|
||||
{
|
||||
return _fontSize;
|
||||
}
|
||||
|
@ -806,37 +806,21 @@ void MenuItemImage::setDisabledSpriteFrame(SpriteFrame * frame)
|
|||
//
|
||||
|
||||
// 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();
|
||||
ret->MenuItem::initWithTarget(target, selector);
|
||||
ret->_subItems = Array::create();
|
||||
ret->_subItems->retain();
|
||||
|
||||
for (int z=0; z < menuItems->count(); z++)
|
||||
{
|
||||
MenuItem* menuItem = (MenuItem*)menuItems->getObjectAtIndex(z);
|
||||
ret->_subItems->addObject(menuItem);
|
||||
}
|
||||
|
||||
ret->_subItems = menuItems;
|
||||
ret->_selectedIndex = UINT_MAX;
|
||||
ret->setSelectedIndex(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, Array* menuItems)
|
||||
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, const Vector<MenuItem*>& menuItems)
|
||||
{
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->MenuItem::initWithCallback(callback);
|
||||
ret->_subItems = Array::create();
|
||||
ret->_subItems->retain();
|
||||
|
||||
for (int z=0; z < menuItems->count(); z++)
|
||||
{
|
||||
MenuItem* menuItem = (MenuItem*)menuItems->getObjectAtIndex(z);
|
||||
ret->_subItems->addObject(menuItem);
|
||||
}
|
||||
|
||||
ret->_subItems = menuItems;
|
||||
ret->_selectedIndex = UINT_MAX;
|
||||
ret->setSelectedIndex(0);
|
||||
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)
|
||||
{
|
||||
MenuItem::initWithCallback(callback);
|
||||
this->_subItems = Array::create();
|
||||
this->_subItems->retain();
|
||||
|
||||
int z = 0;
|
||||
MenuItem *i = item;
|
||||
while(i)
|
||||
{
|
||||
z++;
|
||||
_subItems->addObject(i);
|
||||
_subItems.pushBack(i);
|
||||
i = va_arg(args, MenuItem*);
|
||||
}
|
||||
_selectedIndex = UINT_MAX;
|
||||
|
@ -910,11 +893,10 @@ MenuItemToggle* MenuItemToggle::create(MenuItem *item)
|
|||
bool MenuItemToggle::initWithItem(MenuItem *item)
|
||||
{
|
||||
MenuItem::initWithCallback((const ccMenuCallback&)nullptr);
|
||||
setSubItems(Array::create());
|
||||
|
||||
if (item)
|
||||
{
|
||||
_subItems->addObject(item);
|
||||
_subItems.pushBack(item);
|
||||
}
|
||||
_selectedIndex = UINT_MAX;
|
||||
this->setSelectedIndex(0);
|
||||
|
@ -927,24 +909,19 @@ bool MenuItemToggle::initWithItem(MenuItem *item)
|
|||
|
||||
void MenuItemToggle::addSubItem(MenuItem *item)
|
||||
{
|
||||
_subItems->addObject(item);
|
||||
_subItems.pushBack(item);
|
||||
}
|
||||
|
||||
MenuItemToggle::~MenuItemToggle()
|
||||
{
|
||||
if (_subItems)
|
||||
{
|
||||
for (auto& item : *_subItems)
|
||||
{
|
||||
static_cast<MenuItem*>(item)->cleanup();
|
||||
}
|
||||
_subItems->release();
|
||||
}
|
||||
_subItems.forEach([](MenuItem* item){
|
||||
item->cleanup();
|
||||
});
|
||||
}
|
||||
|
||||
void MenuItemToggle::setSelectedIndex(unsigned int index)
|
||||
{
|
||||
if( index != _selectedIndex && _subItems->count() > 0 )
|
||||
if( index != _selectedIndex && _subItems.size() > 0 )
|
||||
{
|
||||
_selectedIndex = index;
|
||||
MenuItem *currentItem = (MenuItem*)getChildByTag(kCurrentItem);
|
||||
|
@ -953,7 +930,7 @@ void MenuItemToggle::setSelectedIndex(unsigned int index)
|
|||
currentItem->removeFromParentAndCleanup(false);
|
||||
}
|
||||
|
||||
MenuItem* item = (MenuItem*)_subItems->getObjectAtIndex(_selectedIndex);
|
||||
MenuItem* item = _subItems.at(_selectedIndex);
|
||||
this->addChild(item, 0, kCurrentItem);
|
||||
Size s = item->getContentSize();
|
||||
this->setContentSize(s);
|
||||
|
@ -964,13 +941,13 @@ void MenuItemToggle::setSelectedIndex(unsigned int index)
|
|||
void MenuItemToggle::selected()
|
||||
{
|
||||
MenuItem::selected();
|
||||
static_cast<MenuItem*>(_subItems->getObjectAtIndex(_selectedIndex))->selected();
|
||||
_subItems.at(_selectedIndex)->selected();
|
||||
}
|
||||
|
||||
void MenuItemToggle::unselected()
|
||||
{
|
||||
MenuItem::unselected();
|
||||
static_cast<MenuItem*>(_subItems->getObjectAtIndex(_selectedIndex))->unselected();
|
||||
_subItems.at(_selectedIndex)->unselected();
|
||||
}
|
||||
|
||||
void MenuItemToggle::activate()
|
||||
|
@ -978,7 +955,7 @@ void MenuItemToggle::activate()
|
|||
// update index
|
||||
if( _enabled )
|
||||
{
|
||||
unsigned int newIndex = (_selectedIndex + 1) % _subItems->count();
|
||||
unsigned int newIndex = (_selectedIndex + 1) % _subItems.size();
|
||||
this->setSelectedIndex(newIndex);
|
||||
}
|
||||
MenuItem::activate();
|
||||
|
@ -989,21 +966,15 @@ void MenuItemToggle::setEnabled(bool enabled)
|
|||
{
|
||||
MenuItem::setEnabled(enabled);
|
||||
|
||||
if(_subItems && _subItems->count() > 0)
|
||||
{
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(_subItems, pObj)
|
||||
{
|
||||
MenuItem* pItem = static_cast<MenuItem*>(pObj);
|
||||
pItem->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
_subItems.forEach([&enabled](MenuItem* item){
|
||||
item->setEnabled(enabled);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem* MenuItemToggle::getSelectedItem()
|
||||
{
|
||||
return static_cast<MenuItem*>(_subItems->getObjectAtIndex(_selectedIndex));
|
||||
return _subItems.at(_selectedIndex);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -212,11 +212,11 @@ class CC_DLL MenuItemAtlasFont : public MenuItemLabel
|
|||
{
|
||||
public:
|
||||
/** 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 */
|
||||
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 */
|
||||
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:
|
||||
/**
|
||||
|
@ -230,9 +230,9 @@ protected:
|
|||
virtual ~MenuItemAtlasFont(){}
|
||||
|
||||
/** 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 */
|
||||
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:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(MenuItemAtlasFont);
|
||||
|
@ -253,10 +253,10 @@ public:
|
|||
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
|
||||
|
||||
/** set default font size */
|
||||
static void setFontSize(long size);
|
||||
static void setFontSize(int size);
|
||||
/** get default font size */
|
||||
static long getFontSize();
|
||||
CC_DEPRECATED_ATTRIBUTE static unsigned int fontSize() { return MenuItemFont::getFontSize(); };
|
||||
static int getFontSize();
|
||||
CC_DEPRECATED_ATTRIBUTE static int fontSize() { return MenuItemFont::getFontSize(); };
|
||||
/** set the default font name */
|
||||
static void setFontName(const std::string& name);
|
||||
/** get the default font name */
|
||||
|
@ -268,13 +268,13 @@ public:
|
|||
* so change the name to setFontSizeObj
|
||||
* @js setFontSize
|
||||
*/
|
||||
void setFontSizeObj(long size);
|
||||
void setFontSizeObj(int size);
|
||||
|
||||
/** get font size
|
||||
* @js getFontSize
|
||||
*/
|
||||
long getFontSizeObj() const;
|
||||
CC_DEPRECATED_ATTRIBUTE unsigned int fontSizeObj() const { return getFontSizeObj(); };
|
||||
int getFontSizeObj() const;
|
||||
CC_DEPRECATED_ATTRIBUTE int fontSizeObj() const { return getFontSizeObj(); };
|
||||
|
||||
/** set the font name
|
||||
* c++ can not overload static and non-static member functions with the same parameter types
|
||||
|
@ -309,7 +309,7 @@ protected:
|
|||
|
||||
void recreateLabel();
|
||||
|
||||
long _fontSize;
|
||||
int _fontSize;
|
||||
std::string _fontName;
|
||||
|
||||
private:
|
||||
|
@ -453,8 +453,19 @@ private:
|
|||
class CC_DLL MenuItemToggle : public MenuItem
|
||||
{
|
||||
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 */
|
||||
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 */
|
||||
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
/** creates a menu item with no target/selector and no items */
|
||||
|
@ -481,13 +492,11 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
|
||||
inline Array* getSubItems() const { return _subItems; };
|
||||
inline const Vector<MenuItem*>& getSubItems() const { return _subItems; };
|
||||
inline Vector<MenuItem*>& getSubItems() { return _subItems; };
|
||||
|
||||
/** Sets the array that contains the subitems. */
|
||||
inline void setSubItems(Array* items) {
|
||||
CC_SAFE_RETAIN(items);
|
||||
CC_SAFE_RELEASE(_subItems);
|
||||
inline void setSubItems(const Vector<MenuItem*>& items) {
|
||||
_subItems = items;
|
||||
}
|
||||
|
||||
|
@ -498,22 +507,11 @@ public:
|
|||
virtual void setEnabled(bool var) override;
|
||||
|
||||
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
|
||||
*/
|
||||
MenuItemToggle()
|
||||
: _selectedIndex(0)
|
||||
, _subItems(NULL)
|
||||
{}
|
||||
/**
|
||||
* @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.
|
||||
@since v0.7.2
|
||||
*/
|
||||
Array* _subItems;
|
||||
Vector<MenuItem*> _subItems;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(MenuItemToggle);
|
||||
|
|
|
@ -114,7 +114,6 @@ Node::Node(void)
|
|||
// lazy alloc
|
||||
, _grid(NULL)
|
||||
, _ZOrder(0)
|
||||
, _children(NULL)
|
||||
, _parent(NULL)
|
||||
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
|
||||
, _tag(Node::INVALID_TAG)
|
||||
|
@ -169,21 +168,13 @@ Node::~Node()
|
|||
CC_SAFE_RELEASE(_shaderProgram);
|
||||
CC_SAFE_RELEASE(_userObject);
|
||||
|
||||
if(_children && _children->count() > 0)
|
||||
for (auto& child : _children)
|
||||
{
|
||||
Object* child;
|
||||
CCARRAY_FOREACH(_children, child)
|
||||
if (child)
|
||||
{
|
||||
Node* node = static_cast<Node*>(child);
|
||||
if (node)
|
||||
{
|
||||
node->_parent = NULL;
|
||||
child->_parent = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// children
|
||||
CC_SAFE_RELEASE(_children);
|
||||
|
||||
removeAllComponents();
|
||||
|
||||
|
@ -404,9 +395,9 @@ void Node::setPositionY(float 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
|
||||
|
@ -584,7 +575,9 @@ void Node::cleanup()
|
|||
}
|
||||
|
||||
// timers
|
||||
arrayMakeObjectsPerformSelector(_children, cleanup, Node*);
|
||||
_children.forEach([](Node* child){
|
||||
child->cleanup();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -596,25 +589,19 @@ const char* Node::description() const
|
|||
// lazy allocs
|
||||
void Node::childrenAlloc(void)
|
||||
{
|
||||
_children = Array::createWithCapacity(4);
|
||||
_children->retain();
|
||||
_children.reserve(4);
|
||||
}
|
||||
|
||||
Node* Node::getChildByTag(int aTag)
|
||||
{
|
||||
CCASSERT( aTag != Node::INVALID_TAG, "Invalid tag");
|
||||
|
||||
if(_children && _children->count() > 0)
|
||||
for (auto& child : _children)
|
||||
{
|
||||
Object* child;
|
||||
CCARRAY_FOREACH(_children, child)
|
||||
{
|
||||
Node* pNode = static_cast<Node*>(child);
|
||||
if(pNode && pNode->_tag == aTag)
|
||||
return pNode;
|
||||
if(child && child->_tag == aTag)
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* "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->_parent == NULL, "child already added. It can't be added again");
|
||||
|
||||
if( ! _children )
|
||||
if (_children.empty())
|
||||
{
|
||||
this->childrenAlloc();
|
||||
}
|
||||
|
@ -691,12 +678,12 @@ void Node::removeFromParentAndCleanup(bool cleanup)
|
|||
void Node::removeChild(Node* child, bool cleanup /* = true */)
|
||||
{
|
||||
// explicit nil handling
|
||||
if (_children == NULL)
|
||||
if (_children.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
long index = _children->getIndexOfObject(child);
|
||||
auto index = _children.getIndex(child);
|
||||
if( index != CC_INVALID_INDEX )
|
||||
this->detachChild( child, index, cleanup );
|
||||
}
|
||||
|
@ -725,38 +712,36 @@ void Node::removeAllChildren()
|
|||
void Node::removeAllChildrenWithCleanup(bool cleanup)
|
||||
{
|
||||
// not using detachChild improves speed here
|
||||
if ( _children && _children->count() > 0 )
|
||||
if (!_children.empty())
|
||||
{
|
||||
Object* child;
|
||||
CCARRAY_FOREACH(_children, child)
|
||||
for (auto& child : _children)
|
||||
{
|
||||
Node* pNode = static_cast<Node*>(child);
|
||||
if (pNode)
|
||||
if (child)
|
||||
{
|
||||
// IMPORTANT:
|
||||
// -1st do onExit
|
||||
// -2nd cleanup
|
||||
if(_running)
|
||||
{
|
||||
pNode->onExitTransitionDidStart();
|
||||
pNode->onExit();
|
||||
child->onExitTransitionDidStart();
|
||||
child->onExit();
|
||||
}
|
||||
|
||||
if (cleanup)
|
||||
{
|
||||
pNode->cleanup();
|
||||
child->cleanup();
|
||||
}
|
||||
// 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:
|
||||
// -1st do onExit
|
||||
|
@ -783,9 +768,9 @@ void Node::detachChild(Node *child, long childIndex, bool doCleanup)
|
|||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
_reorderChildDirty = true;
|
||||
_children->addObject(child);
|
||||
_children.pushBack(child);
|
||||
child->_setZOrder(z);
|
||||
}
|
||||
|
||||
|
@ -810,24 +795,24 @@ void Node::sortAllChildren()
|
|||
#if 0
|
||||
if (_reorderChildDirty)
|
||||
{
|
||||
int i,j,length = _children->count();
|
||||
int i,j,length = _children.size();
|
||||
|
||||
// insertion sort
|
||||
for(i=1; i<length; i++)
|
||||
{
|
||||
j = i-1;
|
||||
auto tempI = static_cast<Node*>( _children->getObjectAtIndex(i) );
|
||||
auto tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );
|
||||
auto tempI = static_cast<Node*>( _children.at(i) );
|
||||
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
|
||||
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;
|
||||
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
|
||||
|
@ -836,7 +821,7 @@ void Node::sortAllChildren()
|
|||
}
|
||||
#else
|
||||
if( _reorderChildDirty ) {
|
||||
std::sort( std::begin(*_children), std::end(*_children), nodeComparisonLess );
|
||||
std::sort( std::begin(_children), std::end(_children), nodeComparisonLess );
|
||||
_reorderChildDirty = false;
|
||||
}
|
||||
#endif
|
||||
|
@ -869,13 +854,13 @@ void Node::visit()
|
|||
this->transform();
|
||||
int i = 0;
|
||||
|
||||
if(_children && _children->count() > 0)
|
||||
if(!_children.empty())
|
||||
{
|
||||
sortAllChildren();
|
||||
// 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 )
|
||||
node->visit();
|
||||
|
@ -885,12 +870,10 @@ void Node::visit()
|
|||
// self draw
|
||||
this->draw();
|
||||
|
||||
for( ; i < _children->count(); i++ )
|
||||
{
|
||||
auto node = static_cast<Node*>( _children->getObjectAtIndex(i) );
|
||||
if (node)
|
||||
// Uses std::for_each to improve performance.
|
||||
std::for_each(_children.cbegin()+i, _children.cend(), [](Node* node){
|
||||
node->visit();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -955,7 +938,9 @@ void Node::onEnter()
|
|||
{
|
||||
_isTransitionFinished = false;
|
||||
|
||||
arrayMakeObjectsPerformSelector(_children, onEnter, Node*);
|
||||
_children.forEach([](Node* child){
|
||||
child->onEnter();
|
||||
});
|
||||
|
||||
this->resume();
|
||||
|
||||
|
@ -974,7 +959,9 @@ void Node::onEnterTransitionDidFinish()
|
|||
{
|
||||
_isTransitionFinished = true;
|
||||
|
||||
arrayMakeObjectsPerformSelector(_children, onEnterTransitionDidFinish, Node*);
|
||||
_children.forEach([](Node* child){
|
||||
child->onEnterTransitionDidFinish();
|
||||
});
|
||||
|
||||
if (_scriptType != kScriptTypeNone)
|
||||
{
|
||||
|
@ -987,7 +974,10 @@ void Node::onEnterTransitionDidFinish()
|
|||
|
||||
void Node::onExitTransitionDidStart()
|
||||
{
|
||||
arrayMakeObjectsPerformSelector(_children, onExitTransitionDidStart, Node*);
|
||||
_children.forEach([](Node* child){
|
||||
child->onExitTransitionDidStart();
|
||||
});
|
||||
|
||||
if (_scriptType != kScriptTypeNone)
|
||||
{
|
||||
int action = kNodeOnExitTransitionDidStart;
|
||||
|
@ -1010,7 +1000,9 @@ void Node::onExit()
|
|||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
|
||||
arrayMakeObjectsPerformSelector(_children, onExit, Node*);
|
||||
_children.forEach([](Node* child){
|
||||
child->onExit();
|
||||
});
|
||||
}
|
||||
|
||||
void Node::setEventDispatcher(EventDispatcher* dispatcher)
|
||||
|
@ -1063,7 +1055,7 @@ Action * Node::getActionByTag(int tag)
|
|||
return _actionManager->getActionByTag(tag, this);
|
||||
}
|
||||
|
||||
unsigned int Node::getNumberOfRunningActions() const
|
||||
int Node::getNumberOfRunningActions() const
|
||||
{
|
||||
return _actionManager->getNumberOfRunningActionsInTarget(this);
|
||||
}
|
||||
|
@ -1358,7 +1350,9 @@ bool Node::updatePhysicsTransform()
|
|||
void Node::updateTransform()
|
||||
{
|
||||
// Recursively iterate over children
|
||||
arrayMakeObjectsPerformSelector(_children, updateTransform, Node*);
|
||||
_children.forEach([](Node* child){
|
||||
child->updateTransform();
|
||||
});
|
||||
}
|
||||
|
||||
Component* Node::getComponent(const char *pName)
|
||||
|
@ -1467,15 +1461,13 @@ void NodeRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
|
|||
|
||||
if (_cascadeOpacityEnabled)
|
||||
{
|
||||
Object* pObj;
|
||||
CCARRAY_FOREACH(_children, pObj)
|
||||
{
|
||||
RGBAProtocol* item = dynamic_cast<RGBAProtocol*>(pObj);
|
||||
_children.forEach([this](Node* child){
|
||||
RGBAProtocol* item = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (item)
|
||||
{
|
||||
item->updateDisplayedOpacity(_displayedOpacity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1524,15 +1516,13 @@ void NodeRGBA::updateDisplayedColor(const Color3B& parentColor)
|
|||
|
||||
if (_cascadeColorEnabled)
|
||||
{
|
||||
Object *obj = NULL;
|
||||
CCARRAY_FOREACH(_children, obj)
|
||||
{
|
||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
||||
_children.forEach([this](Node* child){
|
||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (item)
|
||||
{
|
||||
item->updateDisplayedColor(_displayedColor);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@
|
|||
#include "CCScriptSupport.h"
|
||||
#include "CCProtocols.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
|
||||
#include <vector>
|
||||
#include "CCVector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -614,15 +613,15 @@ public:
|
|||
*
|
||||
* @return An array of children
|
||||
*/
|
||||
virtual Array* getChildren() { return _children; }
|
||||
virtual const Array *getChildren() const { return _children; }
|
||||
virtual Vector<Node*>& getChildren() { return _children; }
|
||||
virtual const Vector<Node*>& getChildren() const { return _children; }
|
||||
|
||||
/**
|
||||
* Get the amount of children.
|
||||
*
|
||||
* @return The amount of children.
|
||||
*/
|
||||
long getChildrenCount() const;
|
||||
int getChildrenCount() const;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
unsigned int getNumberOfRunningActions() const;
|
||||
int getNumberOfRunningActions() const;
|
||||
|
||||
/** @deprecated Use getNumberOfRunningActions() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE unsigned int numberOfRunningActions() const { return getNumberOfRunningActions(); };
|
||||
CC_DEPRECATED_ATTRIBUTE int numberOfRunningActions() const { return getNumberOfRunningActions(); };
|
||||
|
||||
/// @} end of Actions
|
||||
|
||||
|
@ -1403,7 +1402,7 @@ protected:
|
|||
void insertChild(Node* child, int z);
|
||||
|
||||
/// 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.
|
||||
Point convertToWindowSpace(const Point& nodePoint) const;
|
||||
|
@ -1441,7 +1440,7 @@ protected:
|
|||
|
||||
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
|
||||
|
||||
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->initWithTexture(tex, capacity);
|
||||
|
||||
// no lazy alloc in this node
|
||||
_children = new Array();
|
||||
_children->initWithCapacity(capacity);
|
||||
_children.reserve(capacity);
|
||||
|
||||
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
||||
|
||||
|
@ -171,7 +169,7 @@ void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag)
|
|||
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
||||
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( _children->count() == 0 )
|
||||
if (_children.empty())
|
||||
{
|
||||
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");
|
||||
|
||||
//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
|
||||
int atlasIndex = 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();
|
||||
|
||||
}
|
||||
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 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
|
||||
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->getParent() == NULL, "child already added. It can't be added again");
|
||||
|
||||
if( ! _children )
|
||||
{
|
||||
_children = new Array();
|
||||
_children->initWithCapacity(4);
|
||||
}
|
||||
_children.reserve(4);
|
||||
|
||||
//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->_setZOrder(z);
|
||||
|
@ -239,7 +232,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
|||
{
|
||||
CCASSERT( aChild != NULL, "Child must be non-NULL");
|
||||
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);
|
||||
|
||||
|
@ -249,9 +242,9 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
||||
|
@ -260,8 +253,8 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
|||
|
||||
// reorder _children->array
|
||||
child->retain();
|
||||
_children->removeObjectAtIndex(oldIndex);
|
||||
_children->insertObject(child, newIndex);
|
||||
_children.remove(oldIndex);
|
||||
_children.insert(newIndex, child);
|
||||
child->release();
|
||||
|
||||
// save old altasIndex
|
||||
|
@ -272,10 +265,10 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
|||
|
||||
// Find new AtlasIndex
|
||||
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);
|
||||
if( pNode == child )
|
||||
ParticleSystem* node = static_cast<ParticleSystem*>(_children.at(i));
|
||||
if( node == child )
|
||||
{
|
||||
newAtlasIndex = child->getAtlasIndex();
|
||||
break;
|
||||
|
@ -292,17 +285,17 @@ void ParticleBatchNode::reorderChild(Node * aChild, int 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 foundNewIdx = false;
|
||||
|
||||
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
|
||||
if( pNode->getZOrder() > z && ! foundNewIdx )
|
||||
|
@ -337,25 +330,25 @@ void ParticleBatchNode::getCurrentIndex(unsigned int* oldIndex, unsigned int* ne
|
|||
|
||||
if( ! foundNewIdx )
|
||||
{
|
||||
*newIndex = count;
|
||||
*newIndex = static_cast<int>(count);
|
||||
}
|
||||
|
||||
*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)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
return static_cast<int>(count);
|
||||
}
|
||||
|
||||
// override removeChild:
|
||||
|
@ -366,7 +359,7 @@ void ParticleBatchNode::removeChild(Node* aChild, bool cleanup)
|
|||
return;
|
||||
|
||||
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);
|
||||
Node::removeChild(child, cleanup);
|
||||
|
@ -383,14 +376,16 @@ void ParticleBatchNode::removeChild(Node* aChild, bool cleanup)
|
|||
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)
|
||||
{
|
||||
arrayMakeObjectsPerformSelectorWithObject(_children, setBatchNode, NULL, ParticleSystem*);
|
||||
_children.forEach([](Node* child){
|
||||
static_cast<ParticleSystem*>(child)->setBatchNode(nullptr);
|
||||
});
|
||||
|
||||
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].",
|
||||
(long)_textureAtlas->getCapacity(),
|
||||
|
@ -431,7 +426,7 @@ void ParticleBatchNode::increaseAtlasCapacityTo(unsigned int quantity)
|
|||
}
|
||||
|
||||
//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]);
|
||||
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
|
||||
void ParticleBatchNode::updateAllAtlasIndexes()
|
||||
{
|
||||
Object *pObj = NULL;
|
||||
unsigned int index = 0;
|
||||
int index = 0;
|
||||
|
||||
CCARRAY_FOREACH(_children,pObj)
|
||||
{
|
||||
ParticleSystem* child = static_cast<ParticleSystem*>(pObj);
|
||||
child->setAtlasIndex(index);
|
||||
index += child->getTotalParticles();
|
||||
}
|
||||
_children.forEach([&index](Node* child){
|
||||
ParticleSystem* partiSys = static_cast<ParticleSystem*>(child);
|
||||
partiSys->setAtlasIndex(index);
|
||||
index += partiSys->getTotalParticles();
|
||||
});
|
||||
}
|
||||
|
||||
// ParticleBatchNode - CocosNodeTexture protocol
|
||||
|
||||
void ParticleBatchNode::updateBlendFunc(void)
|
||||
void ParticleBatchNode::updateBlendFunc()
|
||||
{
|
||||
if( ! _textureAtlas->getTexture()->hasPremultipliedAlpha())
|
||||
_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();
|
||||
}
|
||||
|
@ -507,7 +500,7 @@ void ParticleBatchNode::setBlendFunc(const BlendFunc &blendFunc)
|
|||
_blendFunc = blendFunc;
|
||||
}
|
||||
// returns the blending function used for the texture
|
||||
const BlendFunc& ParticleBatchNode::getBlendFunc(void) const
|
||||
const BlendFunc& ParticleBatchNode::getBlendFunc() const
|
||||
{
|
||||
return _blendFunc;
|
||||
}
|
||||
|
|
|
@ -91,11 +91,11 @@ public:
|
|||
/** Inserts a child into the ParticleBatchNode */
|
||||
void insertChild(ParticleSystem* system, int index);
|
||||
|
||||
void removeChildAtIndex(unsigned int index, bool doCleanup);
|
||||
void removeChildAtIndex(int index, bool doCleanup);
|
||||
void removeAllChildrenWithCleanup(bool doCleanup);
|
||||
|
||||
/** 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 */
|
||||
inline TextureAtlas* getTextureAtlas() const { return _textureAtlas; };
|
||||
|
@ -129,10 +129,10 @@ public:
|
|||
|
||||
private:
|
||||
void updateAllAtlasIndexes();
|
||||
void increaseAtlasCapacityTo(unsigned int quantity);
|
||||
unsigned int searchNewPositionInChildrenForZ(int z);
|
||||
void getCurrentIndex(unsigned int* oldIndex, unsigned int* newIndex, Node* child, int z);
|
||||
unsigned int addChildHelper(ParticleSystem* child, int z, int aTag);
|
||||
void increaseAtlasCapacityTo(int quantity);
|
||||
int searchNewPositionInChildrenForZ(int z);
|
||||
void getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z);
|
||||
int addChildHelper(ParticleSystem* child, int z, int aTag);
|
||||
void updateBlendFunc(void);
|
||||
/** the texture atlas used for drawing the quads */
|
||||
TextureAtlas* _textureAtlas;
|
||||
|
|
|
@ -169,9 +169,9 @@ bool ParticleSystem::initWithFile(const std::string& plistFile)
|
|||
{
|
||||
bool bRet = false;
|
||||
_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
|
||||
string listFilePath = plistFile;
|
||||
|
@ -185,113 +185,110 @@ bool ParticleSystem::initWithFile(const std::string& plistFile)
|
|||
bRet = this->initWithDictionary(dict, "");
|
||||
}
|
||||
|
||||
dict->release();
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool ParticleSystem::initWithDictionary(Dictionary *dictionary)
|
||||
bool ParticleSystem::initWithDictionary(ValueMap& 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;
|
||||
unsigned char *buffer = NULL;
|
||||
unsigned char *deflated = NULL;
|
||||
Image *image = NULL;
|
||||
unsigned char *buffer = nullptr;
|
||||
unsigned char *deflated = nullptr;
|
||||
Image *image = nullptr;
|
||||
do
|
||||
{
|
||||
int maxParticles = dictionary->valueForKey("maxParticles")->intValue();
|
||||
int maxParticles = dictionary["maxParticles"].asInt();
|
||||
// self, not super
|
||||
if(this->initWithTotalParticles(maxParticles))
|
||||
{
|
||||
// Emitter name in particle designer 2.0
|
||||
const String * configNameConstStr = dictionary->valueForKey("configName");
|
||||
_configName = configNameConstStr->getCString();
|
||||
_configName = dictionary["configName"].asString();
|
||||
|
||||
// angle
|
||||
_angle = dictionary->valueForKey("angle")->floatValue();
|
||||
_angleVar = dictionary->valueForKey("angleVariance")->floatValue();
|
||||
_angle = dictionary["angle"].asFloat();
|
||||
_angleVar = dictionary["angleVariance"].asFloat();
|
||||
|
||||
// duration
|
||||
_duration = dictionary->valueForKey("duration")->floatValue();
|
||||
_duration = dictionary["duration"].asFloat();
|
||||
|
||||
// blend function
|
||||
if (_configName.length()>0)
|
||||
{
|
||||
_blendFunc.src = dictionary->valueForKey("blendFuncSource")->floatValue();
|
||||
_blendFunc.src = dictionary["blendFuncSource"].asFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
_blendFunc.src = dictionary->valueForKey("blendFuncSource")->intValue();
|
||||
_blendFunc.src = dictionary["blendFuncSource"].asInt();
|
||||
}
|
||||
_blendFunc.dst = dictionary->valueForKey("blendFuncDestination")->intValue();
|
||||
_blendFunc.dst = dictionary["blendFuncDestination"].asInt();
|
||||
|
||||
// color
|
||||
_startColor.r = dictionary->valueForKey("startColorRed")->floatValue();
|
||||
_startColor.g = dictionary->valueForKey("startColorGreen")->floatValue();
|
||||
_startColor.b = dictionary->valueForKey("startColorBlue")->floatValue();
|
||||
_startColor.a = dictionary->valueForKey("startColorAlpha")->floatValue();
|
||||
_startColor.r = dictionary["startColorRed"].asFloat();
|
||||
_startColor.g = dictionary["startColorGreen"].asFloat();
|
||||
_startColor.b = dictionary["startColorBlue"].asFloat();
|
||||
_startColor.a = dictionary["startColorAlpha"].asFloat();
|
||||
|
||||
_startColorVar.r = dictionary->valueForKey("startColorVarianceRed")->floatValue();
|
||||
_startColorVar.g = dictionary->valueForKey("startColorVarianceGreen")->floatValue();
|
||||
_startColorVar.b = dictionary->valueForKey("startColorVarianceBlue")->floatValue();
|
||||
_startColorVar.a = dictionary->valueForKey("startColorVarianceAlpha")->floatValue();
|
||||
_startColorVar.r = dictionary["startColorVarianceRed"].asFloat();
|
||||
_startColorVar.g = dictionary["startColorVarianceGreen"].asFloat();
|
||||
_startColorVar.b = dictionary["startColorVarianceBlue"].asFloat();
|
||||
_startColorVar.a = dictionary["startColorVarianceAlpha"].asFloat();
|
||||
|
||||
_endColor.r = dictionary->valueForKey("finishColorRed")->floatValue();
|
||||
_endColor.g = dictionary->valueForKey("finishColorGreen")->floatValue();
|
||||
_endColor.b = dictionary->valueForKey("finishColorBlue")->floatValue();
|
||||
_endColor.a = dictionary->valueForKey("finishColorAlpha")->floatValue();
|
||||
_endColor.r = dictionary["finishColorRed"].asFloat();
|
||||
_endColor.g = dictionary["finishColorGreen"].asFloat();
|
||||
_endColor.b = dictionary["finishColorBlue"].asFloat();
|
||||
_endColor.a = dictionary["finishColorAlpha"].asFloat();
|
||||
|
||||
_endColorVar.r = dictionary->valueForKey("finishColorVarianceRed")->floatValue();
|
||||
_endColorVar.g = dictionary->valueForKey("finishColorVarianceGreen")->floatValue();
|
||||
_endColorVar.b = dictionary->valueForKey("finishColorVarianceBlue")->floatValue();
|
||||
_endColorVar.a = dictionary->valueForKey("finishColorVarianceAlpha")->floatValue();
|
||||
_endColorVar.r = dictionary["finishColorVarianceRed"].asFloat();
|
||||
_endColorVar.g = dictionary["finishColorVarianceGreen"].asFloat();
|
||||
_endColorVar.b = dictionary["finishColorVarianceBlue"].asFloat();
|
||||
_endColorVar.a = dictionary["finishColorVarianceAlpha"].asFloat();
|
||||
|
||||
// particle size
|
||||
_startSize = dictionary->valueForKey("startParticleSize")->floatValue();
|
||||
_startSizeVar = dictionary->valueForKey("startParticleSizeVariance")->floatValue();
|
||||
_endSize = dictionary->valueForKey("finishParticleSize")->floatValue();
|
||||
_endSizeVar = dictionary->valueForKey("finishParticleSizeVariance")->floatValue();
|
||||
_startSize = dictionary["startParticleSize"].asFloat();
|
||||
_startSizeVar = dictionary["startParticleSizeVariance"].asFloat();
|
||||
_endSize = dictionary["finishParticleSize"].asFloat();
|
||||
_endSizeVar = dictionary["finishParticleSizeVariance"].asFloat();
|
||||
|
||||
// position
|
||||
float x = dictionary->valueForKey("sourcePositionx")->floatValue();
|
||||
float y = dictionary->valueForKey("sourcePositiony")->floatValue();
|
||||
float x = dictionary["sourcePositionx"].asFloat();
|
||||
float y = dictionary["sourcePositiony"].asFloat();
|
||||
this->setPosition( Point(x,y) );
|
||||
_posVar.x = dictionary->valueForKey("sourcePositionVariancex")->floatValue();
|
||||
_posVar.y = dictionary->valueForKey("sourcePositionVariancey")->floatValue();
|
||||
_posVar.x = dictionary["sourcePositionVariancex"].asFloat();
|
||||
_posVar.y = dictionary["sourcePositionVariancey"].asFloat();
|
||||
|
||||
// Spinning
|
||||
_startSpin = dictionary->valueForKey("rotationStart")->floatValue();
|
||||
_startSpinVar = dictionary->valueForKey("rotationStartVariance")->floatValue();
|
||||
_endSpin= dictionary->valueForKey("rotationEnd")->floatValue();
|
||||
_endSpinVar= dictionary->valueForKey("rotationEndVariance")->floatValue();
|
||||
_startSpin = dictionary["rotationStart"].asFloat();
|
||||
_startSpinVar = dictionary["rotationStartVariance"].asFloat();
|
||||
_endSpin= dictionary["rotationEnd"].asFloat();
|
||||
_endSpinVar= dictionary["rotationEndVariance"].asFloat();
|
||||
|
||||
_emitterMode = (Mode) dictionary->valueForKey("emitterType")->intValue();
|
||||
_emitterMode = (Mode) dictionary["emitterType"].asInt();
|
||||
|
||||
// Mode A: Gravity + tangential accel + radial accel
|
||||
if (_emitterMode == Mode::GRAVITY)
|
||||
{
|
||||
// gravity
|
||||
modeA.gravity.x = dictionary->valueForKey("gravityx")->floatValue();
|
||||
modeA.gravity.y = dictionary->valueForKey("gravityy")->floatValue();
|
||||
modeA.gravity.x = dictionary["gravityx"].asFloat();
|
||||
modeA.gravity.y = dictionary["gravityy"].asFloat();
|
||||
|
||||
// speed
|
||||
modeA.speed = dictionary->valueForKey("speed")->floatValue();
|
||||
modeA.speedVar = dictionary->valueForKey("speedVariance")->floatValue();
|
||||
modeA.speed = dictionary["speed"].asFloat();
|
||||
modeA.speedVar = dictionary["speedVariance"].asFloat();
|
||||
|
||||
// radial acceleration
|
||||
modeA.radialAccel = dictionary->valueForKey("radialAcceleration")->floatValue();
|
||||
modeA.radialAccelVar = dictionary->valueForKey("radialAccelVariance")->floatValue();
|
||||
modeA.radialAccel = dictionary["radialAcceleration"].asFloat();
|
||||
modeA.radialAccelVar = dictionary["radialAccelVariance"].asFloat();
|
||||
|
||||
// tangential acceleration
|
||||
modeA.tangentialAccel = dictionary->valueForKey("tangentialAcceleration")->floatValue();
|
||||
modeA.tangentialAccelVar = dictionary->valueForKey("tangentialAccelVariance")->floatValue();
|
||||
modeA.tangentialAccel = dictionary["tangentialAcceleration"].asFloat();
|
||||
modeA.tangentialAccelVar = dictionary["tangentialAccelVariance"].asFloat();
|
||||
|
||||
// rotation is dir
|
||||
modeA.rotationIsDir = dictionary->valueForKey("rotationIsDir")->boolValue();
|
||||
modeA.rotationIsDir = dictionary["rotationIsDir"].asBool();
|
||||
}
|
||||
|
||||
// or Mode B: radius movement
|
||||
|
@ -299,31 +296,31 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
|||
{
|
||||
if (_configName.length()>0)
|
||||
{
|
||||
modeB.startRadius = dictionary->valueForKey("maxRadius")->intValue();
|
||||
modeB.startRadius = dictionary["maxRadius"].asInt();
|
||||
}
|
||||
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)
|
||||
{
|
||||
modeB.endRadius = dictionary->valueForKey("minRadius")->intValue();
|
||||
modeB.endRadius = dictionary["minRadius"].asInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
modeB.endRadius = dictionary->valueForKey("minRadius")->floatValue();
|
||||
modeB.endRadius = dictionary["minRadius"].asFloat();
|
||||
}
|
||||
modeB.endRadiusVar = 0.0f;
|
||||
if (_configName.length()>0)
|
||||
{
|
||||
modeB.rotatePerSecond = dictionary->valueForKey("rotatePerSecond")->intValue();
|
||||
modeB.rotatePerSecond = dictionary["rotatePerSecond"].asInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
modeB.rotatePerSecond = dictionary->valueForKey("rotatePerSecond")->floatValue();
|
||||
modeB.rotatePerSecond = dictionary["rotatePerSecond"].asFloat();
|
||||
}
|
||||
modeB.rotatePerSecondVar = dictionary->valueForKey("rotatePerSecondVariance")->floatValue();
|
||||
modeB.rotatePerSecondVar = dictionary["rotatePerSecondVariance"].asFloat();
|
||||
|
||||
} else {
|
||||
CCASSERT( false, "Invalid emitterType in config file");
|
||||
|
@ -331,8 +328,8 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
|||
}
|
||||
|
||||
// life span
|
||||
_life = dictionary->valueForKey("particleLifespan")->floatValue();
|
||||
_lifeVar = dictionary->valueForKey("particleLifespanVariance")->floatValue();
|
||||
_life = dictionary["particleLifespan"].asFloat();
|
||||
_lifeVar = dictionary["particleLifespanVariance"].asFloat();
|
||||
|
||||
// emission Rate
|
||||
_emissionRate = _totalParticles / _life;
|
||||
|
@ -345,7 +342,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
|||
|
||||
// texture
|
||||
// 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('/');
|
||||
|
||||
|
@ -385,19 +382,19 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
|
|||
}
|
||||
else
|
||||
{
|
||||
const char *textureData = dictionary->valueForKey("textureImageData")->getCString();
|
||||
CCASSERT(textureData, "");
|
||||
std::string textureData = dictionary["textureImageData"].asString();
|
||||
CCASSERT(!textureData.empty(), "");
|
||||
|
||||
long dataLen = strlen(textureData);
|
||||
auto dataLen = textureData.size();
|
||||
if (dataLen != 0)
|
||||
{
|
||||
// if it fails, try to get it from the base64-gzipped data
|
||||
int decodeLen = base64Decode((unsigned char*)textureData, (unsigned int)dataLen, &buffer);
|
||||
CCASSERT( buffer != NULL, "CCParticleSystem: error decoding textureImageData");
|
||||
int decodeLen = base64Decode((unsigned char*)textureData.c_str(), (unsigned int)dataLen, &buffer);
|
||||
CCASSERT( buffer != nullptr, "CCParticleSystem: error decoding textureImageData");
|
||||
CC_BREAK_IF(!buffer);
|
||||
|
||||
int deflatedLen = ZipUtils::inflateMemory(buffer, decodeLen, &deflated);
|
||||
CCASSERT( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");
|
||||
ssize_t deflatedLen = ZipUtils::inflateMemory(buffer, decodeLen, &deflated);
|
||||
CCASSERT( deflated != nullptr, "CCParticleSystem: error ungzipping textureImageData");
|
||||
CC_BREAK_IF(!deflated);
|
||||
|
||||
// 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)
|
||||
{
|
||||
_yCoordFlipped = dictionary->valueForKey("yCoordFlipped")->intValue();
|
||||
_yCoordFlipped = dictionary["yCoordFlipped"].asInt();
|
||||
}
|
||||
CCASSERT( this->_texture != NULL, "CCParticleSystem: error loading the texture");
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCProtocols.h"
|
||||
#include "CCNode.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCString.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -386,12 +386,12 @@ protected:
|
|||
/** initializes a QuadParticleSystem from a Dictionary.
|
||||
@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
|
||||
@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
|
||||
virtual bool initWithTotalParticles(int numberOfParticles);
|
||||
|
|
|
@ -198,8 +198,8 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat
|
|||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||
|
||||
// textures must be power of two squared
|
||||
long powW = 0;
|
||||
long powH = 0;
|
||||
int powW = 0;
|
||||
int powH = 0;
|
||||
|
||||
if (Configuration::getInstance()->supportsNPOT())
|
||||
{
|
||||
|
@ -212,7 +212,7 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat
|
|||
powH = ccNextPOT(h);
|
||||
}
|
||||
|
||||
long dataLen = (long)(powW * powH * 4);
|
||||
auto dataLen = powW * powH * 4;
|
||||
data = malloc(dataLen);
|
||||
CC_BREAK_IF(! data);
|
||||
|
||||
|
@ -528,16 +528,12 @@ void RenderTexture::draw()
|
|||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
||||
Object *pElement;
|
||||
CCARRAY_FOREACH(_children, pElement)
|
||||
{
|
||||
Node *child = static_cast<Node*>(pElement);
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
if (child != _sprite)
|
||||
{
|
||||
child->visit();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
end();
|
||||
}
|
||||
|
|
|
@ -132,25 +132,17 @@ void Scene::addChildToPhysicsWorld(Node* child)
|
|||
{
|
||||
if (_physicsWorld)
|
||||
{
|
||||
std::function<void(Object*)> addToPhysicsWorldFunc = nullptr;
|
||||
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Object* obj) -> void
|
||||
std::function<void(Node*)> addToPhysicsWorldFunc = nullptr;
|
||||
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Node* node) -> void
|
||||
{
|
||||
|
||||
if (dynamic_cast<Node*>(obj) != nullptr)
|
||||
{
|
||||
Node* node = dynamic_cast<Node*>(obj);
|
||||
|
||||
if (node->getPhysicsBody())
|
||||
{
|
||||
_physicsWorld->addBody(node->getPhysicsBody());
|
||||
}
|
||||
|
||||
Object* subChild = nullptr;
|
||||
CCARRAY_FOREACH(node->getChildren(), subChild)
|
||||
{
|
||||
addToPhysicsWorldFunc(subChild);
|
||||
}
|
||||
}
|
||||
node->getChildren().forEach([addToPhysicsWorldFunc](Node* n){
|
||||
addToPhysicsWorldFunc(n);
|
||||
});
|
||||
};
|
||||
|
||||
addToPhysicsWorldFunc(child);
|
||||
|
|
|
@ -256,15 +256,15 @@ Scheduler::Scheduler(void)
|
|||
, _currentTarget(nullptr)
|
||||
, _currentTargetSalvaged(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)
|
||||
{
|
||||
unscheduleAll();
|
||||
CC_SAFE_RELEASE(_scriptHandlerEntries);
|
||||
}
|
||||
|
||||
void Scheduler::removeHashElement(_hashSelectorEntry *element)
|
||||
|
@ -629,10 +629,7 @@ void Scheduler::unscheduleAllWithMinPriority(int minPriority)
|
|||
}
|
||||
}
|
||||
|
||||
if (_scriptHandlerEntries)
|
||||
{
|
||||
_scriptHandlerEntries->removeAllObjects();
|
||||
}
|
||||
_scriptHandlerEntries.clear();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
SchedulerScriptHandlerEntry* entry = SchedulerScriptHandlerEntry::create(handler, interval, paused);
|
||||
if (!_scriptHandlerEntries)
|
||||
{
|
||||
_scriptHandlerEntries = Array::createWithCapacity(20);
|
||||
_scriptHandlerEntries->retain();
|
||||
}
|
||||
_scriptHandlerEntries->addObject(entry);
|
||||
_scriptHandlerEntries.pushBack(entry);
|
||||
return entry->getEntryId();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
entry->markedForDeletion();
|
||||
|
@ -763,22 +755,21 @@ bool Scheduler::isTargetPaused(Object *target)
|
|||
return false; // should never get here
|
||||
}
|
||||
|
||||
Set* Scheduler::pauseAllTargets()
|
||||
Vector<Object*> Scheduler::pauseAllTargets()
|
||||
{
|
||||
return pauseAllTargetsWithMinPriority(PRIORITY_SYSTEM);
|
||||
}
|
||||
|
||||
Set* Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||
Vector<Object*> Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||
{
|
||||
Set* idsWithSelectors = new Set();// setWithCapacity:50];
|
||||
idsWithSelectors->autorelease();
|
||||
Vector<Object*> idsWithSelectors(50);
|
||||
|
||||
// Custom Selectors
|
||||
for(tHashTimerEntry *element = _hashForTimers; element != nullptr;
|
||||
element = (tHashTimerEntry*)element->hh.next)
|
||||
{
|
||||
element->paused = true;
|
||||
idsWithSelectors->addObject(element->target);
|
||||
idsWithSelectors.pushBack(element->target);
|
||||
}
|
||||
|
||||
// Updates selectors
|
||||
|
@ -790,7 +781,7 @@ Set* Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
|||
if(entry->priority >= minPriority)
|
||||
{
|
||||
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 )
|
||||
{
|
||||
entry->paused = true;
|
||||
idsWithSelectors->addObject(entry->target);
|
||||
idsWithSelectors.pushBack(entry->target);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -809,20 +800,27 @@ Set* Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
|||
if(entry->priority >= minPriority)
|
||||
{
|
||||
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;
|
||||
for (iter = targetsToResume->begin(); iter != targetsToResume->end(); ++iter)
|
||||
{
|
||||
resumeTarget(*iter);
|
||||
targetsToResume.forEach([this](Object* obj){
|
||||
this->resumeTarget(obj);
|
||||
});
|
||||
}
|
||||
|
||||
void Scheduler::performFunctionInCocosThread(const std::function<void ()> &function)
|
||||
{
|
||||
_performMutex.lock();
|
||||
|
||||
_functionsToPerform.push_back(function);
|
||||
|
||||
_performMutex.unlock();
|
||||
}
|
||||
|
||||
// main loop
|
||||
|
@ -835,6 +833,10 @@ void Scheduler::update(float dt)
|
|||
dt *= _timeScale;
|
||||
}
|
||||
|
||||
//
|
||||
// Selector callbacks
|
||||
//
|
||||
|
||||
// Iterate over all the Updates' selectors
|
||||
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
|
||||
// updates with priority < 0
|
||||
DL_FOREACH_SAFE(_updatesNegList, entry, tmp)
|
||||
|
@ -950,8 +935,43 @@ void Scheduler::update(float dt)
|
|||
}
|
||||
|
||||
_updateHashLocked = false;
|
||||
|
||||
_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__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCVector.h"
|
||||
#include "uthash.h"
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
|
@ -37,7 +41,6 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class Set;
|
||||
//
|
||||
// Timer
|
||||
//
|
||||
|
@ -104,8 +107,7 @@ protected:
|
|||
struct _listEntry;
|
||||
struct _hashSelectorEntry;
|
||||
struct _hashUpdateEntry;
|
||||
|
||||
class Array;
|
||||
class SchedulerScriptHandlerEntry;
|
||||
|
||||
/** @brief Scheduler is responsible for triggering the scheduled callbacks.
|
||||
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.
|
||||
@since v2.0.0
|
||||
*/
|
||||
Set* pauseAllTargets();
|
||||
Vector<Object*> pauseAllTargets();
|
||||
|
||||
/** Pause all selectors from all targets with a minimum priority.
|
||||
You should only call this with kPriorityNonSystemMin or higher.
|
||||
@since v2.0.0
|
||||
*/
|
||||
Set* pauseAllTargetsWithMinPriority(int minPriority);
|
||||
Vector<Object*> pauseAllTargetsWithMinPriority(int minPriority);
|
||||
|
||||
/** Resume selectors on a set of targets.
|
||||
This can be useful for undoing a call to pauseAllSelectors.
|
||||
@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 removeUpdateFromHash(struct _listEntry *entry);
|
||||
|
||||
|
@ -266,7 +274,7 @@ private:
|
|||
void priorityIn(struct _listEntry **list, Object *target, int priority, bool paused);
|
||||
void appendIn(struct _listEntry **list, Object *target, bool paused);
|
||||
|
||||
protected:
|
||||
|
||||
float _timeScale;
|
||||
|
||||
//
|
||||
|
@ -283,7 +291,11 @@ protected:
|
|||
bool _currentTargetSalvaged;
|
||||
// If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
||||
bool _updateHashLocked;
|
||||
Array* _scriptHandlerEntries;
|
||||
Vector<SchedulerScriptHandlerEntry*> _scriptHandlerEntries;
|
||||
|
||||
// Used for "perform Function"
|
||||
std::vector<std::function<void()>> _functionsToPerform;
|
||||
std::mutex _performMutex;
|
||||
};
|
||||
|
||||
// end of global group
|
||||
|
|
|
@ -613,7 +613,7 @@ void Sprite::draw(void)
|
|||
long offset = 0;
|
||||
setGLBufferData(&_quad, 4 * kQuadSize, 0);
|
||||
#else
|
||||
long offset = (long)&_quad;
|
||||
size_t offset = (size_t)&_quad;
|
||||
#endif // EMSCRIPTEN
|
||||
|
||||
// vertex
|
||||
|
@ -696,7 +696,7 @@ void Sprite::addChild(Node *child, int zOrder, int tag)
|
|||
void Sprite::reorderChild(Node *child, int zOrder)
|
||||
{
|
||||
CCASSERT(child != NULL, "");
|
||||
CCASSERT(_children->containsObject(child), "");
|
||||
CCASSERT(_children.contains(child), "");
|
||||
|
||||
if (zOrder == child->getZOrder())
|
||||
{
|
||||
|
@ -726,15 +726,13 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup)
|
|||
{
|
||||
if (_batchNode)
|
||||
{
|
||||
Object* object = NULL;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
_children.forEach([this](Node* child){
|
||||
Sprite* sprite = dynamic_cast<Sprite*>(child);
|
||||
if (sprite)
|
||||
{
|
||||
Sprite* child = dynamic_cast<Sprite*>(object);
|
||||
if (child)
|
||||
{
|
||||
_batchNode->removeSpriteFromAtlas(child);
|
||||
}
|
||||
_batchNode->removeSpriteFromAtlas(sprite);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Node::removeAllChildrenWithCleanup(cleanup);
|
||||
|
@ -769,12 +767,14 @@ void Sprite::sortAllChildren()
|
|||
_children->fastSetObject(tempI, j+1);
|
||||
}
|
||||
#else
|
||||
std::sort(std::begin(*_children), std::end(*_children), nodeComparisonLess);
|
||||
std::sort(std::begin(_children), std::end(_children), nodeComparisonLess);
|
||||
#endif
|
||||
|
||||
if ( _batchNode)
|
||||
{
|
||||
arrayMakeObjectsPerformSelector(_children, sortAllChildren, Sprite*);
|
||||
_children.forEach([](Node* child){
|
||||
child->sortAllChildren();
|
||||
});
|
||||
}
|
||||
|
||||
_reorderChildDirty = false;
|
||||
|
@ -809,15 +809,13 @@ void Sprite::setDirtyRecursively(bool bValue)
|
|||
// recursively set dirty
|
||||
if (_hasChildren)
|
||||
{
|
||||
Object* object = NULL;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
_children.forEach([](Node* child){
|
||||
Sprite* sp = dynamic_cast<Sprite*>(child);
|
||||
if (sp)
|
||||
{
|
||||
Sprite* child = dynamic_cast<Sprite*>(object);
|
||||
if (child)
|
||||
{
|
||||
child->setDirtyRecursively(true);
|
||||
}
|
||||
sp->setDirtyRecursively(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1062,7 +1060,7 @@ void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName,
|
|||
|
||||
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");
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity
|
|||
* 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();
|
||||
batchNode->initWithFile(fileImage, capacity);
|
||||
|
@ -76,7 +76,7 @@ SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, long capacity/*
|
|||
/*
|
||||
* init with Texture2D
|
||||
*/
|
||||
bool SpriteBatchNode::initWithTexture(Texture2D *tex, long capacity)
|
||||
bool SpriteBatchNode::initWithTexture(Texture2D *tex, int capacity)
|
||||
{
|
||||
CCASSERT(capacity>=0, "Capacity must be >= 0");
|
||||
|
||||
|
@ -92,9 +92,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, long capacity)
|
|||
|
||||
updateBlendFunc();
|
||||
|
||||
// no lazy alloc in this node
|
||||
_children = new Array();
|
||||
_children->initWithCapacity(capacity);
|
||||
_children.reserve(capacity);
|
||||
|
||||
_descendants.reserve(capacity);
|
||||
|
||||
|
@ -112,7 +110,7 @@ bool SpriteBatchNode::init()
|
|||
/*
|
||||
* 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);
|
||||
return initWithTexture(texture2D, capacity);
|
||||
|
@ -187,7 +185,7 @@ void SpriteBatchNode::addChild(Node *child, int zOrder, int tag)
|
|||
void SpriteBatchNode::reorderChild(Node *child, int zOrder)
|
||||
{
|
||||
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())
|
||||
{
|
||||
|
@ -209,7 +207,7 @@ void SpriteBatchNode::removeChild(Node *child, bool cleanup)
|
|||
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
|
||||
removeSpriteFromAtlas(sprite);
|
||||
|
@ -219,8 +217,8 @@ void SpriteBatchNode::removeChild(Node *child, bool cleanup)
|
|||
|
||||
void SpriteBatchNode::removeChildAtIndex(int index, bool doCleanup)
|
||||
{
|
||||
CCASSERT(index>=0 && index < _children->count(), "Invalid index");
|
||||
removeChild( static_cast<Sprite*>(_children->getObjectAtIndex(index)), doCleanup);
|
||||
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
|
||||
removeChild(_children.at(index), doCleanup);
|
||||
}
|
||||
|
||||
void SpriteBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
||||
|
@ -265,25 +263,25 @@ void SpriteBatchNode::sortAllChildren()
|
|||
_children->fastSetObject(tempI, j+1);
|
||||
}
|
||||
#else
|
||||
std::sort(std::begin(*_children), std::end(*_children), nodeComparisonLess);
|
||||
std::sort(std::begin(_children), std::end(_children), nodeComparisonLess);
|
||||
#endif
|
||||
|
||||
//sorted now check all children
|
||||
if (_children->count() > 0)
|
||||
if (!_children.empty())
|
||||
{
|
||||
//first sort all children recursively based on zOrder
|
||||
arrayMakeObjectsPerformSelector(_children, sortAllChildren, Sprite*);
|
||||
_children.forEach([](Node* child){
|
||||
child->sortAllChildren();
|
||||
});
|
||||
|
||||
int index=0;
|
||||
|
||||
Object* obj = NULL;
|
||||
//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
|
||||
CCARRAY_FOREACH(_children, obj)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
updateAtlasIndex(child, &index);
|
||||
}
|
||||
_children.forEach([this, &index](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
updateAtlasIndex(sp, &index);
|
||||
});
|
||||
}
|
||||
|
||||
_reorderChildDirty=false;
|
||||
|
@ -292,12 +290,8 @@ void SpriteBatchNode::sortAllChildren()
|
|||
|
||||
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
||||
{
|
||||
int count = 0;
|
||||
Array* array = sprite->getChildren();
|
||||
if (array != NULL)
|
||||
{
|
||||
count = array->count();
|
||||
}
|
||||
auto& array = sprite->getChildren();
|
||||
auto count = array.size();
|
||||
|
||||
int oldIndex = 0;
|
||||
|
||||
|
@ -315,7 +309,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
|||
{
|
||||
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
|
||||
oldIndex = sprite->getAtlasIndex();
|
||||
|
@ -330,11 +324,9 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
|||
needNewIndex = false;
|
||||
}
|
||||
|
||||
Object* obj = NULL;
|
||||
CCARRAY_FOREACH(array,obj)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
if (needNewIndex && child->getZOrder() >= 0)
|
||||
array.forEach([&](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (needNewIndex && sp->getZOrder() >= 0)
|
||||
{
|
||||
oldIndex = sprite->getAtlasIndex();
|
||||
sprite->setAtlasIndex(*curIndex);
|
||||
|
@ -344,11 +336,10 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
|||
}
|
||||
(*curIndex)++;
|
||||
needNewIndex = false;
|
||||
|
||||
}
|
||||
|
||||
updateAtlasIndex(child, curIndex);
|
||||
}
|
||||
updateAtlasIndex(sp, curIndex);
|
||||
});
|
||||
|
||||
if (needNewIndex)
|
||||
{//all children have a zOrder < 0)
|
||||
|
@ -399,7 +390,9 @@ void SpriteBatchNode::draw(void)
|
|||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
arrayMakeObjectsPerformSelector(_children, updateTransform, Sprite*);
|
||||
_children.forEach([](Node* child){
|
||||
child->updateTransform();
|
||||
});
|
||||
|
||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
|
||||
|
@ -415,9 +408,9 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
|
|||
// this is likely computationally expensive
|
||||
int quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
|
||||
|
||||
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].",
|
||||
(long)_textureAtlas->getCapacity(),
|
||||
(long)quantity);
|
||||
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%d] to [%d].",
|
||||
_textureAtlas->getCapacity(),
|
||||
quantity);
|
||||
|
||||
if (! _textureAtlas->resizeCapacity(quantity))
|
||||
{
|
||||
|
@ -429,22 +422,17 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
|
|||
|
||||
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;
|
||||
CCARRAY_FOREACH(children, object)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(object);
|
||||
if (child && (child->getZOrder() < 0))
|
||||
{
|
||||
index = rebuildIndexInOrder(child, index);
|
||||
}
|
||||
}
|
||||
index = rebuildIndexInOrder(sp, index);
|
||||
}
|
||||
});
|
||||
|
||||
// ignore self (batch node)
|
||||
if (! parent->isEqual(this))
|
||||
|
@ -453,61 +441,56 @@ int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int 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;
|
||||
CCARRAY_FOREACH(children, object)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(object);
|
||||
if (child && (child->getZOrder() >= 0))
|
||||
{
|
||||
index = rebuildIndexInOrder(child, index);
|
||||
}
|
||||
}
|
||||
index = rebuildIndexInOrder(sp, index);
|
||||
}
|
||||
});
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
return highestAtlasIndexInChild( static_cast<Sprite*>(children->getLastObject()));
|
||||
return highestAtlasIndexInChild( static_cast<Sprite*>(children.back()));
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
return lowestAtlasIndexInChild(static_cast<Sprite*>(children->getObjectAtIndex(0)));
|
||||
return lowestAtlasIndexInChild(static_cast<Sprite*>(children.at(0)));
|
||||
}
|
||||
}
|
||||
|
||||
int SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
|
||||
{
|
||||
Array *siblings = sprite->getParent()->getChildren();
|
||||
int childIndex = siblings->getIndexOfObject(sprite);
|
||||
auto& siblings = sprite->getParent()->getChildren();
|
||||
auto childIndex = siblings.getIndex(sprite);
|
||||
|
||||
// ignore parent Z if parent is spriteSheet
|
||||
bool ignoreParent = (SpriteBatchNode*)(sprite->getParent()) == this;
|
||||
Sprite *prev = NULL;
|
||||
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
|
||||
|
@ -568,7 +551,7 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
|
|||
}
|
||||
|
||||
_descendants.push_back(sprite);
|
||||
int index = _descendants.size()-1;
|
||||
int index = static_cast<int>(_descendants.size()-1);
|
||||
|
||||
sprite->setAtlasIndex(index);
|
||||
|
||||
|
@ -576,13 +559,9 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
|
|||
_textureAtlas->insertQuad(&quad, index);
|
||||
|
||||
// add children recursively
|
||||
|
||||
Object* obj = nullptr;
|
||||
CCARRAY_FOREACH(sprite->getChildren(), obj)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
appendChild(child);
|
||||
}
|
||||
sprite->getChildren().forEach([this](Node* child){
|
||||
appendChild(static_cast<Sprite*>(child));
|
||||
});
|
||||
}
|
||||
|
||||
void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
||||
|
@ -606,19 +585,14 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
|||
}
|
||||
|
||||
// remove children recursively
|
||||
Array *children = sprite->getChildren();
|
||||
if (children && children->count() > 0)
|
||||
{
|
||||
Object* object = NULL;
|
||||
CCARRAY_FOREACH(children, object)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(object);
|
||||
auto& children = sprite->getChildren();
|
||||
children.forEach([this](Node* obj){
|
||||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
if (child)
|
||||
{
|
||||
removeSpriteFromAtlas(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 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
|
||||
*/
|
||||
|
@ -88,14 +88,14 @@ public:
|
|||
/** 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.
|
||||
*/
|
||||
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.
|
||||
The capacity will be increased in 33% in runtime if it run out of space.
|
||||
The file will be loaded using the TextureMgr.
|
||||
* @js init
|
||||
* @lua init
|
||||
*/
|
||||
bool initWithFile(const char* fileImage, long capacity);
|
||||
bool initWithFile(const char* fileImage, int capacity);
|
||||
bool init();
|
||||
|
||||
/** returns the TextureAtlas object */
|
||||
|
|
|
@ -64,22 +64,18 @@ void SpriteFrameCache::destroyInstance()
|
|||
|
||||
bool SpriteFrameCache::init(void)
|
||||
{
|
||||
_spriteFrames= new Dictionary();
|
||||
_spriteFrames->init();
|
||||
_spriteFramesAliases = new Dictionary();
|
||||
_spriteFramesAliases->init();
|
||||
_spriteFrames.reserve(20);
|
||||
_spriteFramesAliases.reserve(20);
|
||||
_loadedFileNames = new std::set<std::string>();
|
||||
return true;
|
||||
}
|
||||
|
||||
SpriteFrameCache::~SpriteFrameCache(void)
|
||||
{
|
||||
CC_SAFE_RELEASE(_spriteFrames);
|
||||
CC_SAFE_RELEASE(_spriteFramesAliases);
|
||||
CC_SAFE_DELETE(_loadedFileNames);
|
||||
}
|
||||
|
||||
void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Texture2D *pobTexture)
|
||||
void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Texture2D* texture)
|
||||
{
|
||||
/*
|
||||
Supported Zwoptex Formats:
|
||||
|
@ -90,25 +86,25 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
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;
|
||||
|
||||
// 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
|
||||
CCASSERT(format >=0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");
|
||||
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(framesDict, element)
|
||||
for (auto iter = framesDict.begin(); iter != framesDict.end(); ++iter)
|
||||
{
|
||||
Dictionary* frameDict = static_cast<Dictionary*>(element->getObject());
|
||||
std::string spriteFrameName = element->getStrKey();
|
||||
SpriteFrame* spriteFrame = static_cast<SpriteFrame*>(_spriteFrames->objectForKey(spriteFrameName));
|
||||
ValueMap& frameDict = iter->second.asValueMap();
|
||||
std::string spriteFrameName = iter->first;
|
||||
SpriteFrame* spriteFrame = _spriteFrames.at(spriteFrameName);
|
||||
if (spriteFrame)
|
||||
{
|
||||
continue;
|
||||
|
@ -116,14 +112,14 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
|
||||
if(format == 0)
|
||||
{
|
||||
float x = frameDict->valueForKey("x")->floatValue();
|
||||
float y = frameDict->valueForKey("y")->floatValue();
|
||||
float w = frameDict->valueForKey("width")->floatValue();
|
||||
float h = frameDict->valueForKey("height")->floatValue();
|
||||
float ox = frameDict->valueForKey("offsetX")->floatValue();
|
||||
float oy = frameDict->valueForKey("offsetY")->floatValue();
|
||||
int ow = frameDict->valueForKey("originalWidth")->intValue();
|
||||
int oh = frameDict->valueForKey("originalHeight")->intValue();
|
||||
float x = frameDict["x"].asFloat();
|
||||
float y = frameDict["y"].asFloat();
|
||||
float w = frameDict["width"].asFloat();
|
||||
float h = frameDict["height"].asFloat();
|
||||
float ox = frameDict["offsetX"].asFloat();
|
||||
float oy = frameDict["offsetY"].asFloat();
|
||||
int ow = frameDict["originalWidth"].asInt();
|
||||
int oh = frameDict["originalHeight"].asInt();
|
||||
// check ow/oh
|
||||
if(!ow || !oh)
|
||||
{
|
||||
|
@ -134,7 +130,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
oh = abs(oh);
|
||||
// create frame
|
||||
spriteFrame = new SpriteFrame();
|
||||
spriteFrame->initWithTexture(pobTexture,
|
||||
spriteFrame->initWithTexture(texture,
|
||||
Rect(x, y, w, h),
|
||||
false,
|
||||
Point(ox, oy),
|
||||
|
@ -143,21 +139,21 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
}
|
||||
else if(format == 1 || format == 2)
|
||||
{
|
||||
Rect frame = RectFromString(frameDict->valueForKey("frame")->getCString());
|
||||
Rect frame = RectFromString(frameDict["frame"].asString());
|
||||
bool rotated = false;
|
||||
|
||||
// rotation
|
||||
if (format == 2)
|
||||
{
|
||||
rotated = frameDict->valueForKey("rotated")->boolValue();
|
||||
rotated = frameDict["rotated"].asBool();
|
||||
}
|
||||
|
||||
Point offset = PointFromString(frameDict->valueForKey("offset")->getCString());
|
||||
Size sourceSize = SizeFromString(frameDict->valueForKey("sourceSize")->getCString());
|
||||
Point offset = PointFromString(frameDict["offset"].asString());
|
||||
Size sourceSize = SizeFromString(frameDict["sourceSize"].asString());
|
||||
|
||||
// create frame
|
||||
spriteFrame = new SpriteFrame();
|
||||
spriteFrame->initWithTexture(pobTexture,
|
||||
spriteFrame->initWithTexture(texture,
|
||||
frame,
|
||||
rotated,
|
||||
offset,
|
||||
|
@ -167,31 +163,28 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
else if (format == 3)
|
||||
{
|
||||
// get values
|
||||
Size spriteSize = SizeFromString(frameDict->valueForKey("spriteSize")->getCString());
|
||||
Point spriteOffset = PointFromString(frameDict->valueForKey("spriteOffset")->getCString());
|
||||
Size spriteSourceSize = SizeFromString(frameDict->valueForKey("spriteSourceSize")->getCString());
|
||||
Rect textureRect = RectFromString(frameDict->valueForKey("textureRect")->getCString());
|
||||
bool textureRotated = frameDict->valueForKey("textureRotated")->boolValue();
|
||||
Size spriteSize = SizeFromString(frameDict["spriteSize"].asString());
|
||||
Point spriteOffset = PointFromString(frameDict["spriteOffset"].asString());
|
||||
Size spriteSourceSize = SizeFromString(frameDict["spriteSourceSize"].asString());
|
||||
Rect textureRect = RectFromString(frameDict["textureRect"].asString());
|
||||
bool textureRotated = frameDict["textureRotated"].asBool();
|
||||
|
||||
// get aliases
|
||||
Array* aliases = (Array*) (frameDict->objectForKey("aliases"));
|
||||
String * frameKey = new String(spriteFrameName);
|
||||
ValueVector& aliases = frameDict["aliases"].asValueVector();
|
||||
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(aliases, pObj)
|
||||
{
|
||||
std::string oneAlias = static_cast<String*>(pObj)->getCString();
|
||||
if (_spriteFramesAliases->objectForKey(oneAlias.c_str()))
|
||||
std::for_each(aliases.cbegin(), aliases.cend(), [this, &spriteFrameName](const Value& value){
|
||||
std::string oneAlias = value.asString();
|
||||
if (_spriteFramesAliases.find(oneAlias) != _spriteFramesAliases.end())
|
||||
{
|
||||
CCLOGWARN("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
||||
}
|
||||
|
||||
_spriteFramesAliases->setObject(frameKey, oneAlias.c_str());
|
||||
}
|
||||
frameKey->release();
|
||||
_spriteFramesAliases[oneAlias] = Value(spriteFrameName);
|
||||
});
|
||||
|
||||
// create frame
|
||||
spriteFrame = new SpriteFrame();
|
||||
spriteFrame->initWithTexture(pobTexture,
|
||||
spriteFrame->initWithTexture(texture,
|
||||
Rect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
|
||||
textureRotated,
|
||||
spriteOffset,
|
||||
|
@ -199,7 +192,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
}
|
||||
|
||||
// add sprite frame
|
||||
_spriteFrames->setObject(spriteFrame, spriteFrameName);
|
||||
_spriteFrames.insert(spriteFrameName, spriteFrame);
|
||||
spriteFrame->release();
|
||||
}
|
||||
}
|
||||
|
@ -207,10 +200,9 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist, Texture2D *pobTexture)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist);
|
||||
Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||
|
||||
addSpriteFramesWithDictionary(dict, pobTexture);
|
||||
dict->release();
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist);
|
||||
Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||
|
||||
string texturePath("");
|
||||
|
||||
Dictionary* metadataDict = static_cast<Dictionary*>( dict->objectForKey("metadata") );
|
||||
if (metadataDict)
|
||||
if (dict.find("metadata") != dict.end())
|
||||
{
|
||||
ValueMap& metadataDict = dict["metadata"].asValueMap();
|
||||
// try to read texture file name from meta data
|
||||
texturePath = metadataDict->valueForKey("textureFileName")->getCString();
|
||||
texturePath = metadataDict["textureFileName"].asString();
|
||||
}
|
||||
|
||||
if (!texturePath.empty())
|
||||
|
@ -277,37 +269,39 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist)
|
|||
{
|
||||
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();
|
||||
_spriteFramesAliases->removeAllObjects();
|
||||
_spriteFrames.clear();
|
||||
_spriteFramesAliases.clear();
|
||||
_loadedFileNames->clear();
|
||||
}
|
||||
|
||||
void SpriteFrameCache::removeUnusedSpriteFrames(void)
|
||||
void SpriteFrameCache::removeUnusedSpriteFrames()
|
||||
{
|
||||
bool bRemoved = false;
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(_spriteFrames, element)
|
||||
std::vector<std::string> toRemoveFrames;
|
||||
|
||||
for (auto iter = _spriteFrames.begin(); iter != _spriteFrames.end(); ++iter)
|
||||
{
|
||||
SpriteFrame* spriteFrame = static_cast<SpriteFrame*>(element->getObject());
|
||||
SpriteFrame* spriteFrame = iter->second;
|
||||
if( spriteFrame->retainCount() == 1 )
|
||||
{
|
||||
CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", element->getStrKey());
|
||||
_spriteFrames->removeObjectForElememt(element);
|
||||
toRemoveFrames.push_back(iter->first);
|
||||
CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", iter->first.c_str());
|
||||
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
|
||||
if( bRemoved )
|
||||
{
|
||||
|
@ -323,16 +317,16 @@ void SpriteFrameCache::removeSpriteFrameByName(const std::string& name)
|
|||
return;
|
||||
|
||||
// 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());
|
||||
_spriteFramesAliases->removeObjectForKey(key->getCString());
|
||||
_spriteFrames.remove(key);
|
||||
_spriteFramesAliases.erase(key);
|
||||
}
|
||||
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
|
||||
|
@ -342,13 +336,13 @@ void SpriteFrameCache::removeSpriteFrameByName(const std::string& name)
|
|||
void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);
|
||||
Dictionary* dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
||||
if (dict == nullptr)
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||
if (dict.empty())
|
||||
{
|
||||
CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFile: create dict by %s fail.",plist.c_str());
|
||||
return;
|
||||
}
|
||||
removeSpriteFramesFromDictionary((Dictionary*)dict);
|
||||
removeSpriteFramesFromDictionary(dict);
|
||||
|
||||
// remove it from the cache
|
||||
set<string>::iterator ret = _loadedFileNames->find(plist);
|
||||
|
@ -356,54 +350,51 @@ void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist)
|
|||
{
|
||||
_loadedFileNames->erase(ret);
|
||||
}
|
||||
dict->release();
|
||||
}
|
||||
|
||||
void SpriteFrameCache::removeSpriteFramesFromDictionary(Dictionary* dictionary)
|
||||
void SpriteFrameCache::removeSpriteFramesFromDictionary(ValueMap& dictionary)
|
||||
{
|
||||
Dictionary* framesDict = static_cast<Dictionary*>(dictionary->objectForKey("frames"));
|
||||
Array* keysToRemove = Array::create();
|
||||
ValueMap framesDict = dictionary["frames"].asValueMap();
|
||||
std::vector<std::string> keysToRemove;
|
||||
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(framesDict, element)
|
||||
for (auto iter = framesDict.cbegin(); iter != framesDict.cend(); ++iter)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Array* keysToRemove = Array::create();
|
||||
std::vector<std::string> keysToRemove;
|
||||
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(_spriteFrames, element)
|
||||
for (auto iter = _spriteFrames.cbegin(); iter != _spriteFrames.cend(); ++iter)
|
||||
{
|
||||
string key = element->getStrKey();
|
||||
SpriteFrame* frame = static_cast<SpriteFrame*>(_spriteFrames->objectForKey(key.c_str()));
|
||||
std::string key = iter->first;
|
||||
SpriteFrame* frame = _spriteFrames.at(key);
|
||||
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* frame = (SpriteFrame*)_spriteFrames->objectForKey(name);
|
||||
SpriteFrame* frame = _spriteFrames.at(name);
|
||||
if (!frame)
|
||||
{
|
||||
// try alias dictionary
|
||||
String *key = (String*)_spriteFramesAliases->objectForKey(name);
|
||||
if (key)
|
||||
std::string key = _spriteFramesAliases[name].asString();
|
||||
if (!key.empty())
|
||||
{
|
||||
frame = (SpriteFrame*)_spriteFrames->objectForKey(key->getCString());
|
||||
frame = _spriteFrames.at(key);
|
||||
if (!frame)
|
||||
{
|
||||
CCLOG("cocos2d: SpriteFrameCache: Frame '%s' not found", name.c_str());
|
||||
|
@ -414,3 +405,4 @@ SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)
|
|||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
|
|
@ -37,13 +37,13 @@ THE SOFTWARE.
|
|||
#include "CCSpriteFrame.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCMap.h"
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Dictionary;
|
||||
class Array;
|
||||
class Sprite;
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
|
||||
protected:
|
||||
// MARMALADE: Made this protected not private, as deriving from this class is pretty useful
|
||||
SpriteFrameCache() : _spriteFrames(NULL), _spriteFramesAliases(NULL){}
|
||||
SpriteFrameCache(){}
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -115,13 +115,13 @@ public:
|
|||
* In the medium term: it will allocate more resources.
|
||||
* In the long term: it will be the same.
|
||||
*/
|
||||
void removeSpriteFrames(void);
|
||||
void removeSpriteFrames();
|
||||
|
||||
/** Removes unused sprite frames.
|
||||
* 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.
|
||||
*/
|
||||
void removeUnusedSpriteFrames(void);
|
||||
void removeUnusedSpriteFrames();
|
||||
|
||||
/** Deletes an sprite frame from the sprite frame cache. */
|
||||
void removeSpriteFrameByName(const std::string& name);
|
||||
|
@ -153,16 +153,16 @@ public:
|
|||
private:
|
||||
/*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.
|
||||
* @since v0.99.5
|
||||
*/
|
||||
void removeSpriteFramesFromDictionary(Dictionary* dictionary);
|
||||
void removeSpriteFramesFromDictionary(ValueMap& dictionary);
|
||||
|
||||
protected:
|
||||
Dictionary* _spriteFrames;
|
||||
Dictionary* _spriteFramesAliases;
|
||||
Map<std::string, SpriteFrame*> _spriteFrames;
|
||||
ValueMap _spriteFramesAliases;
|
||||
std::set<std::string>* _loadedFileNames;
|
||||
};
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
|
|||
_minGID = layerInfo->_minGID;
|
||||
_maxGID = layerInfo->_maxGID;
|
||||
_opacity = layerInfo->_opacity;
|
||||
setProperties(Dictionary::createWithDictionary(layerInfo->getProperties()));
|
||||
setProperties(layerInfo->getProperties());
|
||||
_contentScaleFactor = Director::getInstance()->getContentScaleFactor();
|
||||
|
||||
// tilesetInfo
|
||||
|
@ -112,14 +112,12 @@ TMXLayer::TMXLayer()
|
|||
,_tiles(NULL)
|
||||
,_tileSet(NULL)
|
||||
,_layerOrientation(TMXOrientationOrtho)
|
||||
,_properties(NULL)
|
||||
{}
|
||||
|
||||
TMXLayer::~TMXLayer()
|
||||
{
|
||||
CC_SAFE_RELEASE(_tileSet);
|
||||
CC_SAFE_RELEASE(_reusedTile);
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
|
||||
if (_atlasIndexArray)
|
||||
{
|
||||
|
@ -193,28 +191,28 @@ void TMXLayer::setupTiles()
|
|||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
||||
|
||||
String *vertexz = getProperty("cc_vertexz");
|
||||
if (vertexz)
|
||||
auto vertexz = getProperty("cc_vertexz");
|
||||
if (!vertexz.isNull())
|
||||
{
|
||||
std::string vertexZStr = vertexz.asString();
|
||||
// If "automatic" is on, then parse the "cc_alpha_func" too
|
||||
if (vertexz->_string == "automatic")
|
||||
if (vertexZStr == "automatic")
|
||||
{
|
||||
_useAutomaticVertexZ = true;
|
||||
String *alphaFuncVal = getProperty("cc_alpha_func");
|
||||
float alphaFuncValue = 0.0f;
|
||||
if (alphaFuncVal != NULL)
|
||||
{
|
||||
alphaFuncValue = alphaFuncVal->floatValue();
|
||||
}
|
||||
auto alphaFuncVal = getProperty("cc_alpha_func");
|
||||
float alphaFuncValue = alphaFuncVal.asFloat();
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST));
|
||||
|
||||
GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
||||
|
@ -228,7 +226,7 @@ void TMXLayer::parseInternalProperties()
|
|||
}
|
||||
else
|
||||
{
|
||||
_vertexZvalue = vertexz->intValue();
|
||||
_vertexZvalue = vertexz.asInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +379,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
|||
setupTileSprite(tile, pos, gid);
|
||||
|
||||
// get atlas index
|
||||
unsigned int indexForZ = atlasIndexForNewZ(z);
|
||||
unsigned int indexForZ = atlasIndexForNewZ(static_cast<int>(z));
|
||||
|
||||
// Optimization: add the quad without adding a child
|
||||
this->insertQuadFromSprite(tile, indexForZ);
|
||||
|
@ -390,25 +388,23 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
|||
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
|
||||
|
||||
// update possible children
|
||||
if (_children && _children->count()>0)
|
||||
{
|
||||
Object* pObject = nullptr;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(pObject);
|
||||
|
||||
_children.forEach([&indexForZ](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (child)
|
||||
{
|
||||
unsigned int ai = child->getAtlasIndex();
|
||||
int ai = sp->getAtlasIndex();
|
||||
if ( ai >= indexForZ )
|
||||
{
|
||||
child->setAtlasIndex(ai+1);
|
||||
}
|
||||
}
|
||||
sp->setAtlasIndex(ai+1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_tiles[z] = gid;
|
||||
return tile;
|
||||
}
|
||||
|
||||
Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
|
@ -461,6 +457,7 @@ static inline int compareInts(const void * a, const void * b)
|
|||
{
|
||||
return ((*(int*)a) - (*(int*)b));
|
||||
}
|
||||
|
||||
unsigned int TMXLayer::atlasIndexForExistantZ(unsigned int 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*);
|
||||
return index;
|
||||
}
|
||||
|
||||
unsigned int TMXLayer::atlasIndexForNewZ(int z)
|
||||
{
|
||||
// XXX: This can be improved with a sort of binary search
|
||||
|
@ -558,7 +556,7 @@ void TMXLayer::removeChild(Node* node, bool cleanup)
|
|||
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 zz = (size_t)_atlasIndexArray->arr[atlasIndex];
|
||||
|
@ -596,12 +594,8 @@ void TMXLayer::removeTileAt(const Point& pos)
|
|||
_textureAtlas->removeQuadAtIndex(atlasIndex);
|
||||
|
||||
// update possible children
|
||||
if (_children && _children->count()>0)
|
||||
{
|
||||
Object* pObject = nullptr;
|
||||
CCARRAY_FOREACH(_children, pObject)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(pObject);
|
||||
_children.forEach([&atlasIndex](Node* obj){
|
||||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
if (child)
|
||||
{
|
||||
unsigned int ai = child->getAtlasIndex();
|
||||
|
@ -610,8 +604,7 @@ void TMXLayer::removeTileAt(const Point& pos)
|
|||
child->setAtlasIndex(ai-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,8 +137,8 @@ public:
|
|||
CC_DEPRECATED_ATTRIBUTE Point positionAt(const Point& tileCoordinate) { return getPositionAt(tileCoordinate); };
|
||||
|
||||
/** return the value for the specific property name */
|
||||
String* getProperty(const char *propertyName) const;
|
||||
CC_DEPRECATED_ATTRIBUTE String* propertyNamed(const char *propertyName) const { return getProperty(propertyName); };
|
||||
Value getProperty(const std::string& propertyName) const;
|
||||
CC_DEPRECATED_ATTRIBUTE Value propertyNamed(const std::string& propertyName) const { return getProperty(propertyName); };
|
||||
|
||||
/** Creates the tiles */
|
||||
void setupTiles();
|
||||
|
@ -174,10 +174,9 @@ public:
|
|||
inline void setLayerOrientation(unsigned int orientation) { _layerOrientation = orientation; };
|
||||
|
||||
/** properties from the layer. They can be added using Tiled */
|
||||
inline Dictionary* getProperties() const { return _properties; };
|
||||
inline void setProperties(Dictionary* properties) {
|
||||
CC_SAFE_RETAIN(properties);
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
inline const ValueMap& getProperties() const { return _properties; };
|
||||
inline ValueMap& getProperties() { return _properties; };
|
||||
inline void setProperties(const ValueMap& properties) {
|
||||
_properties = properties;
|
||||
};
|
||||
//
|
||||
|
@ -244,7 +243,7 @@ protected:
|
|||
/** Layer orientation, which is the same as the map orientation */
|
||||
unsigned int _layerOrientation;
|
||||
/** properties from the layer. They can be added using Tiled */
|
||||
Dictionary* _properties;
|
||||
ValueMap _properties;
|
||||
};
|
||||
|
||||
// end of tilemap_parallax_nodes group
|
||||
|
|
|
@ -35,41 +35,38 @@ TMXObjectGroup::TMXObjectGroup()
|
|||
: _groupName("")
|
||||
, _positionOffset(Point::ZERO)
|
||||
{
|
||||
_objects = Array::create();
|
||||
_objects->retain();
|
||||
_properties = new Dictionary();
|
||||
_properties->init();
|
||||
}
|
||||
|
||||
TMXObjectGroup::~TMXObjectGroup()
|
||||
{
|
||||
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;
|
||||
CCARRAY_FOREACH(_objects, pObj)
|
||||
for (const auto& v : _objects)
|
||||
{
|
||||
Dictionary* pDict = static_cast<Dictionary*>(pObj);
|
||||
String *name = static_cast<String*>(pDict->objectForKey("name"));
|
||||
if (name && name->_string == objectName)
|
||||
const ValueMap& dict = v.asValueMap();
|
||||
if (dict.find("name") != dict.end())
|
||||
{
|
||||
return pDict;
|
||||
if (dict.at("name").asString() == objectName)
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
|||
#include "CCGeometry.h"
|
||||
#include "CCString.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -55,20 +55,20 @@ public:
|
|||
*/
|
||||
virtual ~TMXObjectGroup();
|
||||
|
||||
inline const char* getGroupName(){ return _groupName.c_str(); }
|
||||
inline void setGroupName(const char *groupName){ _groupName = groupName; }
|
||||
inline const std::string& getGroupName(){ return _groupName; }
|
||||
inline void setGroupName(const std::string& groupName){ _groupName = groupName; }
|
||||
|
||||
/** 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.
|
||||
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 */
|
||||
inline const Point& getPositionOffset() const { return _positionOffset; };
|
||||
|
@ -77,22 +77,20 @@ public:
|
|||
inline void setPositionOffset(const Point& offset) { _positionOffset = offset; };
|
||||
|
||||
/** 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 */
|
||||
inline void setProperties(Dictionary* properties) {
|
||||
CC_SAFE_RETAIN(properties);
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
inline void setProperties(const ValueMap& properties) {
|
||||
_properties = properties;
|
||||
};
|
||||
|
||||
/** 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 */
|
||||
inline void setObjects(Array* objects) {
|
||||
CC_SAFE_RETAIN(objects);
|
||||
CC_SAFE_RELEASE(_objects);
|
||||
inline void setObjects(const ValueVector& objects) {
|
||||
_objects = objects;
|
||||
};
|
||||
|
||||
|
@ -102,9 +100,9 @@ protected:
|
|||
/** offset position of child objects */
|
||||
Point _positionOffset;
|
||||
/** list of properties stored in a dictionary */
|
||||
Dictionary* _properties;
|
||||
ValueMap _properties;
|
||||
/** array of the objects */
|
||||
Array* _objects;
|
||||
ValueVector _objects;
|
||||
};
|
||||
|
||||
// end of tilemap_parallax_nodes group
|
||||
|
|
|
@ -42,7 +42,7 @@ TMXTiledMap * TMXTiledMap::create(const std::string& tmxFile)
|
|||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
||||
|
@ -69,7 +69,7 @@ bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
|||
{
|
||||
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);
|
||||
|
||||
return true;
|
||||
|
@ -81,7 +81,7 @@ bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& r
|
|||
|
||||
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);
|
||||
|
||||
return true;
|
||||
|
@ -90,16 +90,11 @@ bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& r
|
|||
TMXTiledMap::TMXTiledMap()
|
||||
:_mapSize(Size::ZERO)
|
||||
,_tileSize(Size::ZERO)
|
||||
,_objectGroups(NULL)
|
||||
,_properties(NULL)
|
||||
,_tileProperties(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
TMXTiledMap::~TMXTiledMap()
|
||||
{
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
CC_SAFE_RELEASE(_objectGroups);
|
||||
CC_SAFE_RELEASE(_tileProperties);
|
||||
}
|
||||
|
||||
// private
|
||||
|
@ -118,14 +113,13 @@ TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
|
|||
TMXTilesetInfo * TMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
|
||||
{
|
||||
Size size = layerInfo->_layerSize;
|
||||
Array* tilesets = mapInfo->getTilesets();
|
||||
if (tilesets && tilesets->count()>0)
|
||||
auto& tilesets = mapInfo->getTilesets();
|
||||
if (tilesets.size()>0)
|
||||
{
|
||||
TMXTilesetInfo* tileset = NULL;
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH_REVERSE(tilesets, pObj)
|
||||
TMXTilesetInfo* tileset = nullptr;
|
||||
for (auto iter = tilesets.crbegin(); iter != tilesets.crend(); ++iter)
|
||||
{
|
||||
tileset = static_cast<TMXTilesetInfo*>(pObj);
|
||||
tileset = *iter;
|
||||
if (tileset)
|
||||
{
|
||||
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
|
||||
CCLOG("cocos2d: Warning: TMX Layer '%s' has no tiles", layerInfo->_name.c_str());
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
||||
|
@ -166,28 +160,15 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
_tileSize = mapInfo->getTileSize();
|
||||
_mapOrientation = mapInfo->getOrientation();
|
||||
|
||||
CC_SAFE_RELEASE(_objectGroups);
|
||||
_objectGroups = mapInfo->getObjectGroups();
|
||||
CC_SAFE_RETAIN(_objectGroups);
|
||||
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
_properties = mapInfo->getProperties();
|
||||
CC_SAFE_RETAIN(_properties);
|
||||
|
||||
CC_SAFE_RELEASE(_tileProperties);
|
||||
_tileProperties = mapInfo->getTileProperties();
|
||||
CC_SAFE_RETAIN(_tileProperties);
|
||||
|
||||
int idx=0;
|
||||
|
||||
Array* layers = mapInfo->getLayers();
|
||||
if (layers && layers->count()>0)
|
||||
{
|
||||
TMXLayerInfo* layerInfo = NULL;
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(layers, pObj)
|
||||
{
|
||||
layerInfo = static_cast<TMXLayerInfo*>(pObj);
|
||||
mapInfo->getLayers().forEach([&idx, this, &mapInfo](TMXLayerInfo* layerInfo){
|
||||
if (layerInfo && layerInfo->_visible)
|
||||
{
|
||||
TMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||
|
@ -202,18 +183,17 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// public
|
||||
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
|
||||
{
|
||||
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(layerName.compare( layer->getLayerName()) == 0)
|
||||
|
@ -224,20 +204,19 @@ TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
|
|||
}
|
||||
|
||||
// layer not found
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
|
||||
{
|
||||
CCASSERT(groupName.size() > 0, "Invalid group name!");
|
||||
|
||||
if (_objectGroups && _objectGroups->count()>0)
|
||||
if (_objectGroups.size()>0)
|
||||
{
|
||||
TMXObjectGroup* objectGroup = NULL;
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(_objectGroups, pObj)
|
||||
TMXObjectGroup* objectGroup = nullptr;
|
||||
for (auto iter = _objectGroups.cbegin(); iter != _objectGroups.cend(); ++iter)
|
||||
{
|
||||
objectGroup = static_cast<TMXObjectGroup*>(pObj);
|
||||
objectGroup = *iter;
|
||||
if (objectGroup && objectGroup->getGroupName() == groupName)
|
||||
{
|
||||
return objectGroup;
|
||||
|
@ -246,17 +225,23 @@ TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
|
|||
}
|
||||
|
||||
// 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 "CCTMXObjectGroup.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -132,16 +133,16 @@ public:
|
|||
CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const char *groupName) const { return getObjectGroup(groupName); };
|
||||
|
||||
/** return the value for the specific property name */
|
||||
String *getProperty(const std::string& propertyName) const;
|
||||
Value getProperty(const std::string& propertyName) const;
|
||||
/**
|
||||
* @js 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 */
|
||||
Dictionary* getPropertiesForGID(int GID) const;
|
||||
CC_DEPRECATED_ATTRIBUTE Dictionary* propertiesForGID(int GID) const { return getPropertiesForGID(GID); };
|
||||
Value getPropertiesForGID(int GID) const;
|
||||
CC_DEPRECATED_ATTRIBUTE Value propertiesForGID(int GID) const { return getPropertiesForGID(GID); };
|
||||
|
||||
/** the map's size property measured in tiles */
|
||||
inline const Size& getMapSize() const { return _mapSize; };
|
||||
|
@ -156,18 +157,15 @@ public:
|
|||
inline void setMapOrientation(int mapOrientation) { _mapOrientation = mapOrientation; };
|
||||
|
||||
/** object groups */
|
||||
inline Array* getObjectGroups() const { return _objectGroups; };
|
||||
inline void setObjectGroups(Array* groups) {
|
||||
CC_SAFE_RETAIN(groups);
|
||||
CC_SAFE_RELEASE(_objectGroups);
|
||||
inline const Vector<TMXObjectGroup*>& getObjectGroups() const { return _objectGroups; };
|
||||
inline Vector<TMXObjectGroup*>& getObjectGroups() { return _objectGroups; };
|
||||
inline void setObjectGroups(const Vector<TMXObjectGroup*>& groups) {
|
||||
_objectGroups = groups;
|
||||
};
|
||||
|
||||
/** properties */
|
||||
inline Dictionary* getProperties() const { return _properties; };
|
||||
inline void setProperties(Dictionary* properties) {
|
||||
CC_SAFE_RETAIN(properties);
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
inline ValueMap& getProperties() { return _properties; };
|
||||
inline void setProperties(const ValueMap& properties) {
|
||||
_properties = properties;
|
||||
};
|
||||
|
||||
|
@ -199,12 +197,12 @@ protected:
|
|||
/** map orientation */
|
||||
int _mapOrientation;
|
||||
/** object groups */
|
||||
Array* _objectGroups;
|
||||
Vector<TMXObjectGroup*> _objectGroups;
|
||||
/** properties */
|
||||
Dictionary* _properties;
|
||||
ValueMap _properties;
|
||||
|
||||
//! tile properties
|
||||
Dictionary* _tileProperties;
|
||||
IntValueMap _tileProperties;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(TMXTiledMap);
|
||||
|
|
|
@ -38,47 +38,33 @@ using namespace std;
|
|||
|
||||
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
|
||||
TMXLayerInfo::TMXLayerInfo()
|
||||
: _name("")
|
||||
, _tiles(NULL)
|
||||
, _tiles(nullptr)
|
||||
, _ownTiles(true)
|
||||
, _minGID(100000)
|
||||
, _maxGID(0)
|
||||
, _offset(Point::ZERO)
|
||||
{
|
||||
_properties = new Dictionary();
|
||||
_properties->init();
|
||||
}
|
||||
|
||||
TMXLayerInfo::~TMXLayerInfo()
|
||||
{
|
||||
CCLOGINFO("deallocing TMXLayerInfo: %p", this);
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
if( _ownTiles && _tiles )
|
||||
{
|
||||
free(_tiles);
|
||||
_tiles = NULL;
|
||||
_tiles = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary * TMXLayerInfo::getProperties()
|
||||
ValueMap TMXLayerInfo::getProperties()
|
||||
{
|
||||
return _properties;
|
||||
}
|
||||
void TMXLayerInfo::setProperties(Dictionary* var)
|
||||
void TMXLayerInfo::setProperties(ValueMap var)
|
||||
{
|
||||
CC_SAFE_RETAIN(var);
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
_properties = var;
|
||||
}
|
||||
|
||||
|
@ -121,7 +107,7 @@ TMXMapInfo * TMXMapInfo::create(const std::string& tmxFile)
|
|||
return pRet;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_TMXFileName = FileUtils::getInstance()->fullPathForFilename(tmxFileName);
|
||||
|
@ -154,13 +134,7 @@ void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string&
|
|||
_resources = resourcePath;
|
||||
}
|
||||
|
||||
_objectGroups = Array::createWithCapacity(4);
|
||||
_objectGroups->retain();
|
||||
|
||||
_properties = new Dictionary();
|
||||
_properties->init();
|
||||
_tileProperties = new Dictionary();
|
||||
_tileProperties->init();
|
||||
_objectGroups.reserve(4);
|
||||
|
||||
// tmp vars
|
||||
_currentString = "";
|
||||
|
@ -184,13 +158,8 @@ bool TMXMapInfo::initWithTMXFile(const std::string& tmxFile)
|
|||
TMXMapInfo::TMXMapInfo()
|
||||
: _mapSize(Size::ZERO)
|
||||
, _tileSize(Size::ZERO)
|
||||
, _layers(NULL)
|
||||
, _tilesets(NULL)
|
||||
, _objectGroups(NULL)
|
||||
, _layerAttribs(0)
|
||||
, _storingCharacters(false)
|
||||
, _properties(NULL)
|
||||
, _tileProperties(NULL)
|
||||
, _currentFirstGID(0)
|
||||
{
|
||||
}
|
||||
|
@ -198,16 +167,11 @@ TMXMapInfo::TMXMapInfo()
|
|||
TMXMapInfo::~TMXMapInfo()
|
||||
{
|
||||
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)
|
||||
{
|
||||
int len = xmlString.size();
|
||||
size_t len = xmlString.size();
|
||||
if (len <= 0)
|
||||
return false;
|
||||
|
||||
|
@ -244,24 +208,24 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
CC_UNUSED_PARAM(ctx);
|
||||
TMXMapInfo *pTMXMapInfo = this;
|
||||
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])
|
||||
{
|
||||
for(int i = 0; atts[i]; i += 2)
|
||||
{
|
||||
std::string key = (char*)atts[i];
|
||||
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")
|
||||
{
|
||||
std::string version = valueForKey("version", attributeDict);
|
||||
std::string version = attributeDict["version"].asString();
|
||||
if ( version != "1.0")
|
||||
{
|
||||
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")
|
||||
pTMXMapInfo->setOrientation(TMXOrientationOrtho);
|
||||
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());
|
||||
|
||||
Size s;
|
||||
s.width = (float)atof(valueForKey("width", attributeDict));
|
||||
s.height = (float)atof(valueForKey("height", attributeDict));
|
||||
s.width = attributeDict["width"].asFloat();
|
||||
s.height = attributeDict["height"].asFloat();
|
||||
pTMXMapInfo->setMapSize(s);
|
||||
|
||||
s.width = (float)atof(valueForKey("tilewidth", attributeDict));
|
||||
s.height = (float)atof(valueForKey("tileheight", attributeDict));
|
||||
s.width = attributeDict["tilewidth"].asFloat();
|
||||
s.height = attributeDict["tileheight"].asFloat();
|
||||
pTMXMapInfo->setTileSize(s);
|
||||
|
||||
// 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")
|
||||
{
|
||||
// If this is an external tileset then start parsing that
|
||||
std::string externalTilesetFilename = valueForKey("source", attributeDict);
|
||||
std::string externalTilesetFilename = attributeDict["source"].asString();
|
||||
if (externalTilesetFilename != "")
|
||||
{
|
||||
// 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());
|
||||
|
||||
_currentFirstGID = (unsigned int)atoi(valueForKey("firstgid", attributeDict));
|
||||
_currentFirstGID = (unsigned int)attributeDict["firstgid"].asInt();
|
||||
|
||||
pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
TMXTilesetInfo *tileset = new TMXTilesetInfo();
|
||||
tileset->_name = valueForKey("name", attributeDict);
|
||||
tileset->_name = attributeDict["name"].asString();
|
||||
if (_currentFirstGID == 0)
|
||||
{
|
||||
tileset->_firstGid = (unsigned int)atoi(valueForKey("firstgid", attributeDict));
|
||||
tileset->_firstGid = (unsigned int)attributeDict["firstgid"].asInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
tileset->_firstGid = _currentFirstGID;
|
||||
_currentFirstGID = 0;
|
||||
}
|
||||
tileset->_spacing = (unsigned int)atoi(valueForKey("spacing", attributeDict));
|
||||
tileset->_margin = (unsigned int)atoi(valueForKey("margin", attributeDict));
|
||||
tileset->_spacing = (unsigned int)attributeDict["spacing"].asInt();
|
||||
tileset->_margin = (unsigned int)attributeDict["margin"].asInt();
|
||||
Size s;
|
||||
s.width = (float)atof(valueForKey("tilewidth", attributeDict));
|
||||
s.height = (float)atof(valueForKey("tileheight", attributeDict));
|
||||
s.width = attributeDict["tilewidth"].asFloat();
|
||||
s.height = attributeDict["tileheight"].asFloat();
|
||||
tileset->_tileSize = s;
|
||||
|
||||
pTMXMapInfo->getTilesets()->addObject(tileset);
|
||||
pTMXMapInfo->getTilesets().pushBack(tileset);
|
||||
tileset->release();
|
||||
}
|
||||
}
|
||||
|
@ -333,9 +297,9 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
{
|
||||
if (pTMXMapInfo->getParentElement() == TMXPropertyLayer)
|
||||
{
|
||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
||||
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||
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;
|
||||
|
||||
do
|
||||
|
@ -367,44 +331,41 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
}
|
||||
else
|
||||
{
|
||||
TMXTilesetInfo* info = (TMXTilesetInfo*)pTMXMapInfo->getTilesets()->getLastObject();
|
||||
Dictionary *dict = new Dictionary();
|
||||
dict->init();
|
||||
pTMXMapInfo->setParentGID(info->_firstGid + atoi(valueForKey("id", attributeDict)));
|
||||
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
|
||||
CC_SAFE_RELEASE(dict);
|
||||
|
||||
TMXTilesetInfo* info = pTMXMapInfo->getTilesets().back();
|
||||
pTMXMapInfo->setParentGID(info->_firstGid + attributeDict["id"].asInt());
|
||||
//FIXME:XXX Why insert an empty dict?
|
||||
pTMXMapInfo->getTileProperties()[pTMXMapInfo->getParentGID()] = Value(ValueMap());
|
||||
pTMXMapInfo->setParentElement(TMXPropertyTile);
|
||||
}
|
||||
}
|
||||
else if (elementName == "layer")
|
||||
{
|
||||
TMXLayerInfo *layer = new TMXLayerInfo();
|
||||
layer->_name = valueForKey("name", attributeDict);
|
||||
layer->_name = attributeDict["name"].asString();
|
||||
|
||||
Size s;
|
||||
s.width = (float)atof(valueForKey("width", attributeDict));
|
||||
s.height = (float)atof(valueForKey("height", attributeDict));
|
||||
s.width = attributeDict["width"].asFloat();
|
||||
s.height = attributeDict["height"].asFloat();
|
||||
layer->_layerSize = s;
|
||||
|
||||
std::string visible = valueForKey("visible", attributeDict);
|
||||
layer->_visible = !(visible == "0");
|
||||
layer->_visible = attributeDict["visible"].asBool();
|
||||
|
||||
std::string opacity = valueForKey("opacity", attributeDict);
|
||||
if( opacity != "" )
|
||||
Value& opacityValue = attributeDict["opacity"];
|
||||
|
||||
if( !opacityValue.isNull() )
|
||||
{
|
||||
layer->_opacity = (unsigned char)(255 * atof(opacity.c_str()));
|
||||
layer->_opacity = (unsigned char)(255.0f * opacityValue.asFloat());
|
||||
}
|
||||
else
|
||||
{
|
||||
layer->_opacity = 255;
|
||||
}
|
||||
|
||||
float x = (float)atof(valueForKey("x", attributeDict));
|
||||
float y = (float)atof(valueForKey("y", attributeDict));
|
||||
float x = attributeDict["x"].asFloat();
|
||||
float y = attributeDict["y"].asFloat();
|
||||
layer->_offset = Point(x,y);
|
||||
|
||||
pTMXMapInfo->getLayers()->addObject(layer);
|
||||
pTMXMapInfo->getLayers().pushBack(layer);
|
||||
layer->release();
|
||||
|
||||
// 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")
|
||||
{
|
||||
TMXObjectGroup *objectGroup = new TMXObjectGroup();
|
||||
objectGroup->setGroupName(valueForKey("name", attributeDict));
|
||||
objectGroup->setGroupName(attributeDict["name"].asString());
|
||||
Point positionOffset;
|
||||
positionOffset.x = (float)atof(valueForKey("x", attributeDict)) * pTMXMapInfo->getTileSize().width;
|
||||
positionOffset.y = (float)atof(valueForKey("y", attributeDict)) * pTMXMapInfo->getTileSize().height;
|
||||
positionOffset.x = attributeDict["x"].asFloat() * pTMXMapInfo->getTileSize().width;
|
||||
positionOffset.y = attributeDict["y"].asFloat() * pTMXMapInfo->getTileSize().height;
|
||||
objectGroup->setPositionOffset(positionOffset);
|
||||
|
||||
pTMXMapInfo->getObjectGroups()->addObject(objectGroup);
|
||||
pTMXMapInfo->getObjectGroups().pushBack(objectGroup);
|
||||
objectGroup->release();
|
||||
|
||||
// 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")
|
||||
{
|
||||
TMXTilesetInfo* tileset = (TMXTilesetInfo*)pTMXMapInfo->getTilesets()->getLastObject();
|
||||
TMXTilesetInfo* tileset = pTMXMapInfo->getTilesets().back();
|
||||
|
||||
// build full path
|
||||
std::string imagename = valueForKey("source", attributeDict);
|
||||
std::string imagename = attributeDict["source"].asString();
|
||||
|
||||
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")
|
||||
{
|
||||
std::string encoding = valueForKey("encoding", attributeDict);
|
||||
std::string compression = valueForKey("compression", attributeDict);
|
||||
std::string encoding = attributeDict["encoding"].asString();
|
||||
std::string compression = attributeDict["compression"].asString();
|
||||
|
||||
if (encoding == "")
|
||||
{
|
||||
pTMXMapInfo->setLayerAttribs(pTMXMapInfo->getLayerAttribs() | TMXLayerAttribNone);
|
||||
|
||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
||||
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||
Size layerSize = layer->_layerSize;
|
||||
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")
|
||||
{
|
||||
char buffer[32] = {0};
|
||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject();
|
||||
TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().back();
|
||||
|
||||
// The value for "type" was blank or not a valid class name
|
||||
// Create an instance of TMXObjectInfo to store the object and its properties
|
||||
Dictionary *dict = new Dictionary();
|
||||
dict->init();
|
||||
ValueMap dict;
|
||||
// Parse everything automatically
|
||||
const char* pArray[] = {"name", "type", "width", "height", "gid"};
|
||||
|
||||
for(size_t i = 0; i < sizeof(pArray)/sizeof(pArray[0]); ++i )
|
||||
{
|
||||
const char* key = pArray[i];
|
||||
String* obj = new String(valueForKey(key, attributeDict));
|
||||
if( obj )
|
||||
{
|
||||
obj->autorelease();
|
||||
dict->setObject(obj, key);
|
||||
}
|
||||
Value value = attributeDict[key];
|
||||
dict[key] = value;
|
||||
}
|
||||
|
||||
// But X and Y since they need special treatment
|
||||
// X
|
||||
|
||||
const char* value = valueForKey("x", attributeDict);
|
||||
if (value)
|
||||
{
|
||||
int x = atoi(value) + (int)objectGroup->getPositionOffset().x;
|
||||
sprintf(buffer, "%d", x);
|
||||
String* pStr = new String(buffer);
|
||||
pStr->autorelease();
|
||||
dict->setObject(pStr, "x");
|
||||
}
|
||||
int x = attributeDict["x"].asInt() + (int)objectGroup->getPositionOffset().x;
|
||||
dict["x"] = Value(x);
|
||||
|
||||
// Y
|
||||
value = valueForKey("y", attributeDict);
|
||||
if (value) {
|
||||
int y = atoi(value) + (int)objectGroup->getPositionOffset().y;
|
||||
int y = attributeDict["y"].asInt() + (int)objectGroup->getPositionOffset().y;
|
||||
|
||||
// Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
|
||||
y = (int)(_mapSize.height * _tileSize.height) - y - atoi(valueForKey("height", attributeDict));
|
||||
sprintf(buffer, "%d", y);
|
||||
String* pStr = new String(buffer);
|
||||
pStr->autorelease();
|
||||
dict->setObject(pStr, "y");
|
||||
}
|
||||
y = (int)(_mapSize.height * _tileSize.height) - y - attributeDict["height"].asInt();
|
||||
dict["y"] = Value(y);
|
||||
|
||||
// Add the object to the objectGroup
|
||||
objectGroup->getObjects()->addObject(dict);
|
||||
dict->release();
|
||||
objectGroup->getObjects().push_back(Value(dict));
|
||||
|
||||
// The parent element is now "object"
|
||||
pTMXMapInfo->setParentElement(TMXPropertyObject);
|
||||
|
@ -558,70 +499,61 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
if ( pTMXMapInfo->getParentElement() == TMXPropertyNone )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
// The parent element is the map
|
||||
String *value = new String(valueForKey("value", attributeDict));
|
||||
std::string key = valueForKey("name", attributeDict);
|
||||
pTMXMapInfo->getProperties()->setObject(value, key.c_str());
|
||||
value->release();
|
||||
|
||||
Value value = attributeDict["value"];
|
||||
std::string key = attributeDict["name"].asString();
|
||||
pTMXMapInfo->getProperties().insert(std::make_pair(key, value));
|
||||
}
|
||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
||||
{
|
||||
// The parent element is the last layer
|
||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
||||
String *value = new String(valueForKey("value", attributeDict));
|
||||
std::string key = valueForKey("name", attributeDict);
|
||||
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||
Value value = attributeDict["value"];
|
||||
std::string key = attributeDict["name"].asString();
|
||||
// Add the property to the layer
|
||||
layer->getProperties()->setObject(value, key.c_str());
|
||||
value->release();
|
||||
|
||||
layer->getProperties().insert(std::make_pair(key, value));
|
||||
}
|
||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
||||
{
|
||||
// The parent element is the last object group
|
||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject();
|
||||
String *value = new String(valueForKey("value", attributeDict));
|
||||
const char* key = valueForKey("name", attributeDict);
|
||||
objectGroup->getProperties()->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().back();
|
||||
Value value = attributeDict["value"];
|
||||
std::string key = attributeDict["name"].asString();
|
||||
objectGroup->getProperties().insert(std::make_pair(key, value));
|
||||
}
|
||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
||||
{
|
||||
// The parent element is the last object
|
||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject();
|
||||
Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject();
|
||||
TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().back();
|
||||
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
||||
|
||||
const char* propertyName = valueForKey("name", attributeDict);
|
||||
String *propertyValue = new String(valueForKey("value", attributeDict));
|
||||
dict->setObject(propertyValue, propertyName);
|
||||
propertyValue->release();
|
||||
std::string propertyName = attributeDict["name"].asString();
|
||||
dict[propertyName] = attributeDict["value"];
|
||||
}
|
||||
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);
|
||||
String *propertyValue = new String(valueForKey("value", attributeDict));
|
||||
dict->setObject(propertyValue, propertyName);
|
||||
propertyValue->release();
|
||||
int propertyName = attributeDict["name"].asInt();
|
||||
dict[propertyName] = attributeDict["value"];
|
||||
}
|
||||
}
|
||||
else if (elementName == "polygon")
|
||||
{
|
||||
// find parent object's dict and add polygon-points to it
|
||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->getLastObject();
|
||||
Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject();
|
||||
TMXObjectGroup* objectGroup = _objectGroups.back();
|
||||
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
||||
|
||||
// get points value string
|
||||
const char* value = valueForKey("points", attributeDict);
|
||||
if(value)
|
||||
std::string value = attributeDict["points"].asString();
|
||||
if (!value.empty())
|
||||
{
|
||||
Array* pointsArray = Array::createWithCapacity(10);
|
||||
ValueVector pointsArray;
|
||||
pointsArray.reserve(10);
|
||||
|
||||
// parse points string into a space-separated set of points
|
||||
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
|
||||
stringstream pointStream(pointPair);
|
||||
string xStr,yStr;
|
||||
char buffer[32] = {0};
|
||||
|
||||
Dictionary* pointDict = new Dictionary;
|
||||
pointDict->init();
|
||||
ValueMap pointDict;
|
||||
|
||||
// set x
|
||||
if(std::getline(pointStream, xStr, ','))
|
||||
{
|
||||
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||
sprintf(buffer, "%d", x);
|
||||
String* pStr = new String(buffer);
|
||||
pStr->autorelease();
|
||||
pointDict->setObject(pStr, "x");
|
||||
pointDict["x"] = Value(x);
|
||||
}
|
||||
|
||||
// set y
|
||||
if(std::getline(pointStream, yStr, ','))
|
||||
{
|
||||
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||
sprintf(buffer, "%d", y);
|
||||
String* pStr = new String(buffer);
|
||||
pStr->autorelease();
|
||||
pointDict->setObject(pStr, "y");
|
||||
pointDict["y"] = Value(y);
|
||||
}
|
||||
|
||||
// add to points array
|
||||
pointsArray->addObject(pointDict);
|
||||
pointDict->release();
|
||||
pointsArray.push_back(Value(pointDict));
|
||||
}
|
||||
|
||||
dict->setObject(pointsArray, "points");
|
||||
dict["points"] = Value(pointsArray);
|
||||
}
|
||||
}
|
||||
else if (elementName == "polyline")
|
||||
{
|
||||
// find parent object's dict and add polyline-points to it
|
||||
TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->getLastObject();
|
||||
Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject();
|
||||
TMXObjectGroup* objectGroup = _objectGroups.back();
|
||||
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
||||
|
||||
// get points value string
|
||||
const char* value = valueForKey("points", attributeDict);
|
||||
if(value)
|
||||
std::string value = attributeDict["points"].asString();
|
||||
if (!value.empty())
|
||||
{
|
||||
Array* pointsArray = Array::createWithCapacity(10);
|
||||
ValueVector pointsArray;
|
||||
pointsArray.reserve(10);
|
||||
|
||||
// parse points string into a space-separated set of points
|
||||
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
|
||||
stringstream pointStream(pointPair);
|
||||
string xStr,yStr;
|
||||
char buffer[32] = {0};
|
||||
|
||||
Dictionary* pointDict = new Dictionary;
|
||||
pointDict->init();
|
||||
ValueMap pointDict;
|
||||
|
||||
// set x
|
||||
if(std::getline(pointStream, xStr, ','))
|
||||
{
|
||||
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||
sprintf(buffer, "%d", x);
|
||||
String* pStr = new String(buffer);
|
||||
pStr->autorelease();
|
||||
pointDict->setObject(pStr, "x");
|
||||
pointDict["x"] = Value(x);
|
||||
}
|
||||
|
||||
// set y
|
||||
if(std::getline(pointStream, yStr, ','))
|
||||
{
|
||||
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||
sprintf(buffer, "%d", y);
|
||||
String* pStr = new String(buffer);
|
||||
pStr->autorelease();
|
||||
pointDict->setObject(pStr, "y");
|
||||
pointDict["y"] = Value(y);
|
||||
}
|
||||
|
||||
// add to points array
|
||||
pointsArray->addObject(pointDict);
|
||||
pointDict->release();
|
||||
pointsArray.push_back(Value(pointDict));
|
||||
}
|
||||
|
||||
dict->setObject(pointsArray, "polylinePoints");
|
||||
dict["polylinePoints"] = Value(pointsArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (attributeDict)
|
||||
{
|
||||
attributeDict->clear();
|
||||
delete attributeDict;
|
||||
}
|
||||
}
|
||||
|
||||
void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||
|
@ -739,7 +648,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
{
|
||||
pTMXMapInfo->setStoringCharacters(false);
|
||||
|
||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
||||
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||
|
||||
std::string currentString = pTMXMapInfo->getCurrentString();
|
||||
unsigned char *buffer;
|
||||
|
@ -752,18 +661,16 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
|
||||
if( pTMXMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib) )
|
||||
{
|
||||
unsigned char *deflated;
|
||||
unsigned char *deflated = nullptr;
|
||||
Size s = layer->_layerSize;
|
||||
// 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, "");
|
||||
|
||||
inflatedLen = (size_t)&inflatedLen; // XXX: to avoid warnings in compiler
|
||||
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
buffer = nullptr;
|
||||
|
||||
if( ! deflated )
|
||||
{
|
||||
|
@ -782,7 +689,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
}
|
||||
else if (pTMXMapInfo->getLayerAttribs() & TMXLayerAttribNone)
|
||||
{
|
||||
TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject();
|
||||
TMXLayerInfo* layer = pTMXMapInfo->getLayers().back();
|
||||
Size layerSize = layer->_layerSize;
|
||||
int tilesAmount = layerSize.width * layerSize.height;
|
||||
|
||||
|
|
|
@ -29,15 +29,17 @@ THE SOFTWARE.
|
|||
#define __CC_TM_XML_PARSER__
|
||||
|
||||
#include "CCArray.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "platform/CCSAXParser.h"
|
||||
|
||||
#include "CCVector.h"
|
||||
#include "CCValue.h"
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class TMXLayerInfo;
|
||||
class TMXObjectGroup;
|
||||
class TMXTilesetInfo;
|
||||
|
||||
/** @file
|
||||
* Internal TMX parser
|
||||
|
@ -99,10 +101,10 @@ public:
|
|||
*/
|
||||
virtual ~TMXLayerInfo();
|
||||
|
||||
void setProperties(Dictionary *properties);
|
||||
Dictionary* getProperties();
|
||||
void setProperties(ValueMap properties);
|
||||
ValueMap getProperties();
|
||||
|
||||
Dictionary *_properties;
|
||||
ValueMap _properties;
|
||||
std::string _name;
|
||||
Size _layerSize;
|
||||
unsigned int *_tiles;
|
||||
|
@ -193,10 +195,8 @@ public:
|
|||
/* initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */
|
||||
bool parseXMLString(const std::string& xmlString);
|
||||
|
||||
Dictionary* getTileProperties() { return _tileProperties; };
|
||||
void setTileProperties(Dictionary* tileProperties) {
|
||||
CC_SAFE_RETAIN(tileProperties);
|
||||
CC_SAFE_RELEASE(_tileProperties);
|
||||
IntValueMap& getTileProperties() { return _tileProperties; };
|
||||
void setTileProperties(const IntValueMap& tileProperties) {
|
||||
_tileProperties = tileProperties;
|
||||
};
|
||||
|
||||
|
@ -213,26 +213,23 @@ public:
|
|||
inline void setTileSize(const Size& tileSize) { _tileSize = tileSize; };
|
||||
|
||||
/// Layers
|
||||
inline Array* getLayers() const { return _layers; };
|
||||
inline void setLayers(Array* layers) {
|
||||
CC_SAFE_RETAIN(layers);
|
||||
CC_SAFE_RELEASE(_layers);
|
||||
inline const Vector<TMXLayerInfo*>& getLayers() const { return _layers; };
|
||||
inline Vector<TMXLayerInfo*>& getLayers() { return _layers; };
|
||||
inline void setLayers(const Vector<TMXLayerInfo*>& layers) {
|
||||
_layers = layers;
|
||||
};
|
||||
|
||||
/// tilesets
|
||||
inline Array* getTilesets() const { return _tilesets; };
|
||||
inline void setTilesets(Array* tilesets) {
|
||||
CC_SAFE_RETAIN(tilesets);
|
||||
CC_SAFE_RELEASE(_tilesets);
|
||||
inline const Vector<TMXTilesetInfo*>& getTilesets() const { return _tilesets; };
|
||||
inline Vector<TMXTilesetInfo*>& getTilesets() { return _tilesets; };
|
||||
inline void setTilesets(const Vector<TMXTilesetInfo*>& tilesets) {
|
||||
_tilesets = tilesets;
|
||||
};
|
||||
|
||||
/// ObjectGroups
|
||||
inline Array* getObjectGroups() const { return _objectGroups; };
|
||||
inline void setObjectGroups(Array* groups) {
|
||||
CC_SAFE_RETAIN(groups);
|
||||
CC_SAFE_RELEASE(_objectGroups);
|
||||
inline const Vector<TMXObjectGroup*>& getObjectGroups() const { return _objectGroups; };
|
||||
inline Vector<TMXObjectGroup*>& getObjectGroups() { return _objectGroups; };
|
||||
inline void setObjectGroups(const Vector<TMXObjectGroup*>& groups) {
|
||||
_objectGroups = groups;
|
||||
};
|
||||
|
||||
|
@ -254,10 +251,8 @@ public:
|
|||
inline void setStoringCharacters(bool storingCharacters) { _storingCharacters = storingCharacters; };
|
||||
|
||||
/// properties
|
||||
inline Dictionary* getProperties() const { return _properties; };
|
||||
inline void setProperties(Dictionary* properties) {
|
||||
CC_SAFE_RETAIN(properties);
|
||||
CC_SAFE_RELEASE(_properties);
|
||||
inline ValueMap getProperties() const { return _properties; };
|
||||
inline void setProperties(ValueMap properties) {
|
||||
_properties = properties;
|
||||
};
|
||||
|
||||
|
@ -293,11 +288,11 @@ protected:
|
|||
/// tiles width & height
|
||||
Size _tileSize;
|
||||
/// Layers
|
||||
Array* _layers;
|
||||
Vector<TMXLayerInfo*> _layers;
|
||||
/// tilesets
|
||||
Array* _tilesets;
|
||||
Vector<TMXTilesetInfo*> _tilesets;
|
||||
/// ObjectGroups
|
||||
Array* _objectGroups;
|
||||
Vector<TMXObjectGroup*> _objectGroups;
|
||||
/// parent element
|
||||
int _parentElement;
|
||||
/// parent GID
|
||||
|
@ -307,7 +302,7 @@ protected:
|
|||
/// is storing characters?
|
||||
bool _storingCharacters;
|
||||
/// properties
|
||||
Dictionary* _properties;
|
||||
ValueMap _properties;
|
||||
|
||||
//! tmx filename
|
||||
std::string _TMXFileName;
|
||||
|
@ -316,7 +311,7 @@ protected:
|
|||
//! current string
|
||||
std::string _currentString;
|
||||
//! tile properties
|
||||
Dictionary* _tileProperties;
|
||||
IntValueMap _tileProperties;
|
||||
unsigned int _currentFirstGID;
|
||||
};
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ void TextFieldTTF::insertText(const char * text, int len)
|
|||
std::string sInsert(text, len);
|
||||
|
||||
// insert \n means input end
|
||||
int nPos = sInsert.find('\n');
|
||||
int nPos = static_cast<int>(sInsert.find('\n'));
|
||||
if ((int)sInsert.npos != nPos)
|
||||
{
|
||||
len = nPos;
|
||||
|
@ -201,7 +201,7 @@ void TextFieldTTF::insertText(const char * text, int len)
|
|||
|
||||
void TextFieldTTF::deleteBackward()
|
||||
{
|
||||
int nStrLen = _inputText.length();
|
||||
size_t nStrLen = _inputText.length();
|
||||
if (! nStrLen)
|
||||
{
|
||||
// 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};
|
||||
std::string displayText;
|
||||
int length;
|
||||
size_t length;
|
||||
|
||||
if (text.length()>0)
|
||||
{
|
||||
|
|
|
@ -49,7 +49,7 @@ TextPageDef::TextPageDef(int pageNum, int width, int height): _pageNum(pageNum
|
|||
|
||||
TextPageDef::~TextPageDef()
|
||||
{
|
||||
int numLines = _lines.size();
|
||||
size_t numLines = _lines.size();
|
||||
|
||||
for( int c = 0; c<numLines; ++c )
|
||||
{
|
||||
|
@ -122,8 +122,8 @@ TextFontPagesDef::TextFontPagesDef()
|
|||
|
||||
TextFontPagesDef::~TextFontPagesDef()
|
||||
{
|
||||
int numPages = _pages.size();
|
||||
for( int c = 0; c < numPages; ++c )
|
||||
size_t numPages = _pages.size();
|
||||
for( size_t c = 0; c < numPages; ++c )
|
||||
{
|
||||
if (_pages[c])
|
||||
delete _pages[c];
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
float getHeight() const { return _height; }
|
||||
|
||||
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]; }
|
||||
|
||||
private:
|
||||
|
@ -115,7 +115,7 @@ public:
|
|||
~TextPageDef();
|
||||
|
||||
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]; }
|
||||
int getWidth() const { return _width; }
|
||||
int getHeight() const { return _height; }
|
||||
|
@ -156,7 +156,7 @@ public:
|
|||
~TextFontPagesDef();
|
||||
|
||||
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]; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -119,9 +119,9 @@ static bool _PVRHaveAlphaPremultiplied = false;
|
|||
//conventer function
|
||||
|
||||
// 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]; //G
|
||||
|
@ -130,9 +130,9 @@ void Texture2D::convertI8ToRGB888(const unsigned char* data, long dataLen, unsig
|
|||
}
|
||||
|
||||
// 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]; //G
|
||||
|
@ -141,9 +141,9 @@ void Texture2D::convertAI88ToRGB888(const unsigned char* data, long dataLen, uns
|
|||
}
|
||||
|
||||
// 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]; //G
|
||||
|
@ -153,9 +153,9 @@ void Texture2D::convertI8ToRGBA8888(const unsigned char* data, long dataLen, uns
|
|||
}
|
||||
|
||||
// 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]; //G
|
||||
|
@ -165,7 +165,7 @@ void Texture2D::convertAI88ToRGBA8888(const unsigned char* data, long dataLen, u
|
|||
}
|
||||
|
||||
// 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;
|
||||
for (int i = 0; i < dataLen; ++i)
|
||||
|
@ -177,10 +177,10 @@ void Texture2D::convertI8ToRGB565(const unsigned char* data, long dataLen, unsig
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i] & 0x00FC) << 3 //G
|
||||
|
@ -189,10 +189,10 @@ void Texture2D::convertAI88ToRGB565(const unsigned char* data, long dataLen, uns
|
|||
}
|
||||
|
||||
// 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;
|
||||
for (int i = 0; i < dataLen; ++i)
|
||||
for (ssize_t i = 0; i < dataLen; ++i)
|
||||
{
|
||||
*out16++ = (data[i] & 0x00F0) << 8 //R
|
||||
| (data[i] & 0x00F0) << 4 //G
|
||||
|
@ -202,10 +202,10 @@ void Texture2D::convertI8ToRGBA4444(const unsigned char* data, long dataLen, uns
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i] & 0x00F0) << 4 //G
|
||||
|
@ -215,7 +215,7 @@ void Texture2D::convertAI88ToRGBA4444(const unsigned char* data, long dataLen, u
|
|||
}
|
||||
|
||||
// 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;
|
||||
for (int i = 0; i < dataLen; ++i)
|
||||
|
@ -228,10 +228,10 @@ void Texture2D::convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsig
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i] & 0x00F8) << 3 //G
|
||||
|
@ -241,10 +241,10 @@ void Texture2D::convertAI88ToRGB5A1(const unsigned char* data, long dataLen, uns
|
|||
}
|
||||
|
||||
// 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;
|
||||
for (int i = 0; i < dataLen; ++i)
|
||||
for (ssize_t i = 0; i < dataLen; ++i)
|
||||
{
|
||||
*out16++ = 0xFF00 //A
|
||||
| data[i]; //I
|
||||
|
@ -252,27 +252,27 @@ void Texture2D::convertI8ToAI88(const unsigned char* data, long dataLen, unsigne
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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 + 1]; //G
|
||||
|
@ -282,9 +282,9 @@ void Texture2D::convertRGB888ToRGBA8888(const unsigned char* data, long dataLen,
|
|||
}
|
||||
|
||||
// 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 + 1]; //G
|
||||
|
@ -293,10 +293,10 @@ void Texture2D::convertRGBA8888ToRGB888(const unsigned char* data, long dataLen,
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i + 1] & 0x00FC) << 3 //G
|
||||
|
@ -305,10 +305,10 @@ void Texture2D::convertRGB888ToRGB565(const unsigned char* data, long dataLen, u
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i + 1] & 0x00FC) << 3 //G
|
||||
|
@ -317,36 +317,36 @@ void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, long dataLen,
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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++ = 0xFF;
|
||||
|
@ -355,9 +355,9 @@ void Texture2D::convertRGB888ToAI88(const unsigned char* data, long dataLen, uns
|
|||
|
||||
|
||||
// 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 + 3];
|
||||
|
@ -365,10 +365,10 @@ void Texture2D::convertRGBA8888ToAI88(const unsigned char* data, long dataLen, u
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i + 1] & 0x00F0) << 4 //G
|
||||
|
@ -378,10 +378,10 @@ void Texture2D::convertRGB888ToRGBA4444(const unsigned char* data, long dataLen,
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i + 1] & 0x00F0) << 4 //G
|
||||
|
@ -391,10 +391,10 @@ void Texture2D::convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLe
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i + 1] & 0x00F8) << 3 //G
|
||||
|
@ -404,10 +404,10 @@ void Texture2D::convertRGB888ToRGB5A1(const unsigned char* data, long dataLen, u
|
|||
}
|
||||
|
||||
// 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;
|
||||
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
|
||||
| (data[i + 1] & 0x00F8) << 3 //G
|
||||
|
@ -451,12 +451,12 @@ Texture2D::PixelFormat Texture2D::getPixelFormat() const
|
|||
return _pixelFormat;
|
||||
}
|
||||
|
||||
long Texture2D::getPixelsWide() const
|
||||
int Texture2D::getPixelsWide() const
|
||||
{
|
||||
return _pixelsWide;
|
||||
}
|
||||
|
||||
long Texture2D::getPixelsHigh() const
|
||||
int Texture2D::getPixelsHigh() const
|
||||
{
|
||||
return _pixelsHigh;
|
||||
}
|
||||
|
@ -529,14 +529,14 @@ bool Texture2D::hasPremultipliedAlpha() const
|
|||
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");
|
||||
|
||||
//if data has no mipmaps, we will consider it has only one mipmap
|
||||
MipmapInfo mipmap;
|
||||
mipmap.address = (unsigned char*)data;
|
||||
mipmap.len = dataLen;
|
||||
mipmap.len = static_cast<int>(dataLen);
|
||||
return initWithMipmaps(&mipmap, 1, pixelFormat, pixelsWide, pixelsHigh);
|
||||
|
||||
//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
|
||||
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
|
||||
|
||||
// Specify OpenGL texture image
|
||||
long width = pixelsWide;
|
||||
long height = pixelsHigh;
|
||||
int width = pixelsWide;
|
||||
int height = pixelsHigh;
|
||||
|
||||
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 ))
|
||||
{
|
||||
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();
|
||||
|
@ -742,7 +742,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format)
|
|||
}
|
||||
|
||||
unsigned char* outTempData = NULL;
|
||||
int outTempDataLen = 0;
|
||||
ssize_t outTempDataLen = 0;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -823,7 +823,7 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, l
|
|||
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)
|
||||
{
|
||||
|
@ -878,7 +878,7 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data,
|
|||
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)
|
||||
{
|
||||
|
@ -926,7 +926,7 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat
|
|||
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)
|
||||
|
@ -998,7 +998,7 @@ rgb(2) -> 1235678
|
|||
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)
|
||||
{
|
||||
|
@ -1243,7 +1243,7 @@ void Texture2D::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied)
|
|||
|
||||
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 );
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
_hasMipmaps = true;
|
||||
|
@ -1256,8 +1256,8 @@ bool Texture2D::hasMipmaps() const
|
|||
|
||||
void Texture2D::setTexParameters(const TexParams &texParams)
|
||||
{
|
||||
CCASSERT( (static_cast<unsigned long>(_pixelsWide) == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) &&
|
||||
(static_cast<unsigned long>(_pixelsHigh) == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE),
|
||||
CCASSERT((_pixelsWide == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) &&
|
||||
(_pixelsHigh == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE),
|
||||
"GL_CLAMP_TO_EDGE should be used in NPOT dimensions");
|
||||
|
||||
GL::bindTexture2D( _name );
|
||||
|
|
|
@ -217,10 +217,10 @@ public:
|
|||
* @js 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 */
|
||||
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.
|
||||
|
@ -327,10 +327,10 @@ public:
|
|||
Texture2D::PixelFormat getPixelFormat() const;
|
||||
|
||||
/** Gets the width of the texture in pixels */
|
||||
long getPixelsWide() const;
|
||||
int getPixelsWide() const;
|
||||
|
||||
/** Gets the height of the texture in pixels */
|
||||
long getPixelsHigh() const;
|
||||
int getPixelsHigh() const;
|
||||
|
||||
/** Gets the texture name */
|
||||
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.
|
||||
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 convertAI88ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen);
|
||||
static PixelFormat convertRGB888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen);
|
||||
static PixelFormat convertRGBA8888ToFormat(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, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* 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, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
||||
|
||||
//I8 to XXX
|
||||
static void convertI8ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertI8ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertI8ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertI8ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertI8ToAI88(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, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertI8ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertI8ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertI8ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertI8ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
|
||||
//AI88 to XXX
|
||||
static void convertAI88ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertAI88ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertAI88ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertAI88ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertAI88ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertAI88ToA8(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertAI88ToI8(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, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertAI88ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertAI88ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertAI88ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertAI88ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertAI88ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
|
||||
//RGB888 to XXX
|
||||
static void convertRGB888ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToI8(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToRGB5A1(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, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGB888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
|
||||
//RGBA8888 to XXX
|
||||
static void convertRGBA8888ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToI8(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToA8(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToRGB5A1(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, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
static void convertRGBA8888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
||||
|
||||
protected:
|
||||
/** pixel format of the texture */
|
||||
Texture2D::PixelFormat _pixelFormat;
|
||||
|
||||
/** width in pixels */
|
||||
long _pixelsWide;
|
||||
int _pixelsWide;
|
||||
|
||||
/** height in pixels */
|
||||
long _pixelsHigh;
|
||||
int _pixelsHigh;
|
||||
|
||||
/** texture name */
|
||||
GLuint _name;
|
||||
|
|
|
@ -74,12 +74,12 @@ TextureAtlas::~TextureAtlas()
|
|||
#endif
|
||||
}
|
||||
|
||||
long TextureAtlas::getTotalQuads() const
|
||||
int TextureAtlas::getTotalQuads() const
|
||||
{
|
||||
return _totalQuads;
|
||||
}
|
||||
|
||||
long TextureAtlas::getCapacity() const
|
||||
int TextureAtlas::getCapacity() const
|
||||
{
|
||||
return _capacity;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ void TextureAtlas::setQuads(V3F_C4B_T2F_Quad* quads)
|
|||
|
||||
// TextureAtlas - alloc & init
|
||||
|
||||
TextureAtlas * TextureAtlas::create(const char* file, long capacity)
|
||||
TextureAtlas * TextureAtlas::create(const char* file, int capacity)
|
||||
{
|
||||
TextureAtlas * textureAtlas = new TextureAtlas();
|
||||
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
|
||||
|
@ -122,7 +122,7 @@ TextureAtlas * TextureAtlas::create(const char* file, long capacity)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, long capacity)
|
||||
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, int capacity)
|
||||
{
|
||||
TextureAtlas * textureAtlas = new TextureAtlas();
|
||||
if (textureAtlas && textureAtlas->initWithTexture(texture, capacity))
|
||||
|
@ -134,7 +134,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, long capacity
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool TextureAtlas::initWithFile(const char * file, long capacity)
|
||||
bool TextureAtlas::initWithFile(const char * file, int capacity)
|
||||
{
|
||||
// retained in property
|
||||
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");
|
||||
|
||||
|
@ -224,7 +224,7 @@ void TextureAtlas::listenBackToForeground(Object *obj)
|
|||
|
||||
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
|
||||
|
||||
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");
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -338,7 +338,7 @@ void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, long index)
|
|||
CCASSERT( _totalQuads <= _capacity, "invalid 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
|
||||
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");
|
||||
|
||||
|
@ -363,7 +363,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount)
|
|||
CCASSERT( _totalQuads <= _capacity, "invalid 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
|
||||
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;
|
||||
for (long i = index; i < max ; i++)
|
||||
for (int i = index; i < max ; i++)
|
||||
{
|
||||
_quads[index] = quads[j];
|
||||
index++;
|
||||
|
@ -385,7 +385,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount)
|
|||
_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( 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
|
||||
// unsigned int howMany = abs( oldIndex - newIndex);
|
||||
long howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex);
|
||||
long dst = oldIndex;
|
||||
long src = oldIndex + 1;
|
||||
auto howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex);
|
||||
auto dst = oldIndex;
|
||||
auto src = oldIndex + 1;
|
||||
if( oldIndex > newIndex)
|
||||
{
|
||||
dst = newIndex+1;
|
||||
|
@ -414,11 +414,11 @@ void TextureAtlas::insertQuadFromIndex(long oldIndex, long newIndex)
|
|||
_dirty = true;
|
||||
}
|
||||
|
||||
void TextureAtlas::removeQuadAtIndex(long index)
|
||||
void TextureAtlas::removeQuadAtIndex(int 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
|
||||
if( remaining )
|
||||
|
@ -433,11 +433,11 @@ void TextureAtlas::removeQuadAtIndex(long index)
|
|||
_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");
|
||||
|
||||
long remaining = (_totalQuads) - (index + amount);
|
||||
auto remaining = (_totalQuads) - (index + amount);
|
||||
|
||||
_totalQuads -= amount;
|
||||
|
||||
|
@ -455,14 +455,14 @@ void TextureAtlas::removeAllQuads()
|
|||
}
|
||||
|
||||
// TextureAtlas - Resize
|
||||
bool TextureAtlas::resizeCapacity(long newCapacity)
|
||||
bool TextureAtlas::resizeCapacity(int newCapacity)
|
||||
{
|
||||
CCASSERT(newCapacity>=0, "capacity >= 0");
|
||||
if( newCapacity == _capacity )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
long oldCapactiy = _capacity;
|
||||
auto oldCapactiy = _capacity;
|
||||
// update capacity and totolQuads
|
||||
_totalQuads = MIN(_totalQuads, newCapacity);
|
||||
_capacity = newCapacity;
|
||||
|
@ -529,13 +529,13 @@ bool TextureAtlas::resizeCapacity(long newCapacity)
|
|||
return true;
|
||||
}
|
||||
|
||||
void TextureAtlas::increaseTotalQuadsWith(long amount)
|
||||
void TextureAtlas::increaseTotalQuadsWith(int amount)
|
||||
{
|
||||
CCASSERT(amount>=0, "amount >= 0");
|
||||
_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(newIndex + amount <= _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||
|
@ -567,7 +567,7 @@ void TextureAtlas::moveQuadsFromIndex(long oldIndex, long amount, long newIndex)
|
|||
_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(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]));
|
||||
}
|
||||
|
||||
void TextureAtlas::fillWithEmptyQuadsFromIndex(long index, long amount)
|
||||
void TextureAtlas::fillWithEmptyQuadsFromIndex(int index, int amount)
|
||||
{
|
||||
CCASSERT(index>=0 && amount>=0, "values must be >= 0");
|
||||
V3F_C4B_T2F_Quad quad;
|
||||
memset(&quad, 0, sizeof(quad));
|
||||
|
||||
long to = index + amount;
|
||||
for (long i = index ; i < to ; i++)
|
||||
auto to = index + amount;
|
||||
for (int i = index ; i < to ; i++)
|
||||
{
|
||||
_quads[i] = quad;
|
||||
}
|
||||
|
@ -595,13 +595,13 @@ void TextureAtlas::drawQuads()
|
|||
this->drawNumberOfQuads(_totalQuads, 0);
|
||||
}
|
||||
|
||||
void TextureAtlas::drawNumberOfQuads(long numberOfQuads)
|
||||
void TextureAtlas::drawNumberOfQuads(int numberOfQuads)
|
||||
{
|
||||
CCASSERT(numberOfQuads>=0, "numberOfQuads must be >= 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");
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ public:
|
|||
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
||||
* 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
|
||||
* with an initial capacity for n Quads.
|
||||
* The TextureAtlas capacity can be increased in runtime.
|
||||
*/
|
||||
static TextureAtlas* createWithTexture(Texture2D *texture, long capacity);
|
||||
static TextureAtlas* createWithTexture(Texture2D *texture, int capacity);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
*
|
||||
* 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
|
||||
* with an initial capacity for Quads.
|
||||
|
@ -89,43 +89,43 @@ public:
|
|||
*
|
||||
* 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
|
||||
* index must be between 0 and the atlas capacity - 1
|
||||
@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
|
||||
index must be between 0 and the atlas capacity - 1
|
||||
@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
|
||||
index must be between 0 and the atlas capacity - 1
|
||||
this method doesn't enlarge the array when amount + index > totalQuads
|
||||
@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
|
||||
This operation is faster than removing and inserting in a quad in 2 different steps
|
||||
@since v0.7.2
|
||||
*/
|
||||
void insertQuadFromIndex(long fromIndex, long newIndex);
|
||||
void insertQuadFromIndex(int fromIndex, int newIndex);
|
||||
|
||||
/** 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
|
||||
@since v0.7.2
|
||||
*/
|
||||
void removeQuadAtIndex(long index);
|
||||
void removeQuadAtIndex(int index);
|
||||
|
||||
/** removes a amount of quads starting from index
|
||||
@since 1.1
|
||||
*/
|
||||
void removeQuadsAtIndex(long index, long amount);
|
||||
void removeQuadsAtIndex(int index, int amount);
|
||||
/** removes all Quads.
|
||||
The TextureAtlas capacity remains untouched. No memory is freed.
|
||||
The total number of quads to be drawn will be 0
|
||||
|
@ -138,19 +138,19 @@ public:
|
|||
* 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.
|
||||
*/
|
||||
bool resizeCapacity(long capacity);
|
||||
bool resizeCapacity(int capacity);
|
||||
|
||||
/**
|
||||
Used internally by ParticleBatchNode
|
||||
don't use this unless you know what you're doing
|
||||
@since 1.1
|
||||
*/
|
||||
void increaseTotalQuadsWith(long amount);
|
||||
void increaseTotalQuadsWith(int amount);
|
||||
|
||||
/** Moves an amount of quads from oldIndex at newIndex
|
||||
@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
|
||||
|
@ -158,26 +158,26 @@ public:
|
|||
This method doesn't enlarge the array if newIndex + quads to be moved > capacity
|
||||
@since 1.1
|
||||
*/
|
||||
void moveQuadsFromIndex(long index, long newIndex);
|
||||
void moveQuadsFromIndex(int index, int newIndex);
|
||||
|
||||
/**
|
||||
Ensures that after a realloc quads are still empty
|
||||
Used internally by ParticleBatchNode
|
||||
@since 1.1
|
||||
*/
|
||||
void fillWithEmptyQuadsFromIndex(long index, long amount);
|
||||
void fillWithEmptyQuadsFromIndex(int index, int amount);
|
||||
|
||||
/** draws n quads
|
||||
* 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).
|
||||
n + start can't be greater than the capacity of the atlas
|
||||
|
||||
@since v1.0
|
||||
*/
|
||||
void drawNumberOfQuads(long numberOfQuads, long start);
|
||||
void drawNumberOfQuads(int numberOfQuads, int start);
|
||||
|
||||
/** draws all the Atlas's Quads
|
||||
*/
|
||||
|
@ -197,10 +197,10 @@ public:
|
|||
const char* description() const;
|
||||
|
||||
/** 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 */
|
||||
long getCapacity() const;
|
||||
int getCapacity() const;
|
||||
|
||||
/** Gets the texture of the texture atlas */
|
||||
Texture2D* getTexture() const;
|
||||
|
@ -226,9 +226,9 @@ protected:
|
|||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||
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 */
|
||||
long _totalQuads;
|
||||
int _totalQuads;
|
||||
/** quantity of quads that can be stored with the current texture atlas size */
|
||||
long _capacity;
|
||||
int _capacity;
|
||||
/** Texture of the texture atlas */
|
||||
Texture2D* _texture;
|
||||
/** Quads that are going to be rendered */
|
||||
|
|
|
@ -34,7 +34,6 @@ THE SOFTWARE.
|
|||
#include "ccMacros.h"
|
||||
#include "CCDirector.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "platform/CCThread.h"
|
||||
#include "ccUtils.h"
|
||||
#include "CCScheduler.h"
|
||||
#include "CCString.h"
|
||||
|
@ -93,18 +92,6 @@ const char* TextureCache::description() const
|
|||
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)
|
||||
{
|
||||
Texture2D *texture = NULL;
|
||||
|
@ -446,7 +433,7 @@ void TextureCache::dumpCachedTextureInfo() const
|
|||
Texture2D* tex = it->second;
|
||||
unsigned int bpp = tex->getBitsPerPixelForFormat();
|
||||
// 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;
|
||||
count++;
|
||||
log("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
||||
|
@ -607,7 +594,7 @@ void VolatileTextureMgr::reloadAllTextures()
|
|||
case VolatileTexture::kImageFile:
|
||||
{
|
||||
Image* image = new Image();
|
||||
long size = 0;
|
||||
ssize_t size = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &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();
|
||||
*doc = xmlDoc;
|
||||
//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);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(NULL == pXmlBuffer)
|
||||
|
@ -404,7 +404,7 @@ void UserDefault::setDataForKey(const char* pKey, const Data& value) {
|
|||
|
||||
char *encodedData = 0;
|
||||
|
||||
base64Encode(value.getBytes(), value.getSize(), &encodedData);
|
||||
base64Encode(value.getBytes(), static_cast<unsigned int>(value.getSize()), &encodedData);
|
||||
|
||||
setValueForKey(pKey, encodedData);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
|||
{
|
||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
long size;
|
||||
ssize_t size;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(NULL == pXmlBuffer)
|
||||
|
@ -420,11 +420,11 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
else
|
||||
{
|
||||
unsigned char *bytes = {0};
|
||||
unsigned long size = 0;
|
||||
int size = 0;
|
||||
|
||||
if (data.length > 0) {
|
||||
bytes = (unsigned char*)data.bytes;
|
||||
size = data.length;
|
||||
size = static_cast<int>(data.length);
|
||||
}
|
||||
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();
|
||||
*doc = xmlDoc;
|
||||
long size;
|
||||
ssize_t size;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(NULL == pXmlBuffer)
|
||||
|
@ -470,7 +470,7 @@ void UserDefault::setDataForKey(const char* pKey, const Data& value)
|
|||
|
||||
CCLOG("SET DATA ENCODED: --%s", encodedData);
|
||||
|
||||
return setStringForKeyJNI(pKey, encodedData);
|
||||
setStringForKeyJNI(pKey, encodedData);
|
||||
|
||||
if (encodedData)
|
||||
free(encodedData);
|
||||
|
|
|
@ -39,7 +39,7 @@ bool ZipUtils::s_bEncryptionKeyIsValid = false;
|
|||
|
||||
// --------------------- 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 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;
|
||||
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 ?
|
||||
#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 */
|
||||
int err = Z_OK;
|
||||
|
||||
long bufferSize = outLenghtHint;
|
||||
ssize_t bufferSize = outLenghtHint;
|
||||
*out = (unsigned char*)malloc(bufferSize);
|
||||
|
||||
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.next_in = in;
|
||||
d_stream.avail_in = inLength;
|
||||
d_stream.avail_in = static_cast<unsigned int>(inLength);
|
||||
d_stream.next_out = *out;
|
||||
d_stream.avail_out = bufferSize;
|
||||
d_stream.avail_out = static_cast<unsigned int>(bufferSize);
|
||||
|
||||
/* window size to hold 256k */
|
||||
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.avail_out = bufferSize;
|
||||
d_stream.avail_out = static_cast<unsigned int>(bufferSize);
|
||||
bufferSize *= BUFFER_INC_FACTOR;
|
||||
}
|
||||
}
|
||||
|
@ -192,9 +192,9 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned c
|
|||
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);
|
||||
|
||||
if (err != Z_OK || *out == NULL) {
|
||||
|
@ -225,7 +225,7 @@ int ZipUtils::inflateMemoryWithHint(unsigned char *in, long inLength, unsigned c
|
|||
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
|
||||
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;
|
||||
|
||||
|
@ -407,7 +407,7 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsi
|
|||
|
||||
// decrypt
|
||||
unsigned int* ints = (unsigned int*)(buffer+12);
|
||||
int enclen = (bufferLen-12)/4;
|
||||
ssize_t enclen = (bufferLen-12)/4;
|
||||
|
||||
decodeEncodedPvr(ints, enclen);
|
||||
|
||||
|
@ -439,7 +439,7 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsi
|
|||
}
|
||||
|
||||
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) );
|
||||
|
||||
if( ret != Z_OK )
|
||||
|
@ -591,7 +591,7 @@ bool ZipFile::fileExists(const std::string &fileName) const
|
|||
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;
|
||||
if (size)
|
||||
|
@ -614,7 +614,7 @@ unsigned char *ZipFile::getFileData(const std::string &fileName, long *size)
|
|||
CC_BREAK_IF(UNZ_OK != nRet);
|
||||
|
||||
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");
|
||||
|
||||
if (size)
|
||||
|
|
|
@ -65,8 +65,8 @@ namespace cocos2d
|
|||
*
|
||||
@since v0.8.1
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static int ccInflateMemory(unsigned char *in, long inLength, unsigned char **out) { return inflateMemory(in, inLength, out); }
|
||||
static int inflateMemory(unsigned char *in, long inLength, unsigned char **out);
|
||||
CC_DEPRECATED_ATTRIBUTE static ssize_t ccInflateMemory(unsigned char *in, ssize_t inLength, unsigned char **out) { return inflateMemory(in, inLength, 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
|
||||
|
@ -78,8 +78,8 @@ namespace cocos2d
|
|||
*
|
||||
@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); }
|
||||
static int inflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long 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 ssize_t inflateMemoryWithHint(unsigned char *in, ssize_t inLength, unsigned char **out, ssize_t outLengthHint);
|
||||
|
||||
/** inflates a GZip file into memory
|
||||
*
|
||||
|
@ -105,8 +105,8 @@ namespace cocos2d
|
|||
*
|
||||
* @since v3.0
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static bool ccIsGZipBuffer(const unsigned char *buffer, long len) { return isGZipBuffer(buffer, len); }
|
||||
static bool isGZipBuffer(const unsigned char *buffer, long 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, ssize_t len);
|
||||
|
||||
/** inflates a CCZ file into memory
|
||||
*
|
||||
|
@ -123,8 +123,8 @@ namespace cocos2d
|
|||
*
|
||||
* @since v3.0
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static int ccInflateCCZBuffer(const unsigned char *buffer, long len, unsigned char **out) { return inflateCCZBuffer(buffer, len, out); }
|
||||
static int inflateCCZBuffer(const unsigned char *buffer, long len, unsigned char **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, ssize_t len, unsigned char **out);
|
||||
|
||||
/** test a file is a CCZ format file or not
|
||||
*
|
||||
|
@ -141,8 +141,8 @@ namespace cocos2d
|
|||
*
|
||||
* @since v3.0
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static bool ccIsCCZBuffer(const unsigned char *buffer, long len) { return isCCZBuffer(buffer, len); }
|
||||
static bool isCCZBuffer(const unsigned char *buffer, long 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, ssize_t len);
|
||||
|
||||
/** Sets the pvr.ccz encryption key parts separately for added
|
||||
* security.
|
||||
|
@ -199,9 +199,9 @@ namespace cocos2d
|
|||
static void setPvrEncryptionKey(unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3, unsigned int keyPart4);
|
||||
|
||||
private:
|
||||
static int inflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long *outLength, long outLenghtHint);
|
||||
static inline void decodeEncodedPvr (unsigned int *data, long len);
|
||||
static inline unsigned int checksumPvr(const unsigned int *data, long len);
|
||||
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, ssize_t len);
|
||||
static inline unsigned int checksumPvr(const unsigned int *data, ssize_t len);
|
||||
|
||||
static unsigned int s_uEncryptedPvrKeyParts[4];
|
||||
static unsigned int s_uEncryptionKey[1024];
|
||||
|
@ -264,7 +264,7 @@ namespace cocos2d
|
|||
*
|
||||
* @since v2.0.5
|
||||
*/
|
||||
unsigned char *getFileData(const std::string &fileName, long *size);
|
||||
unsigned char *getFileData(const std::string &fileName, ssize_t *size);
|
||||
|
||||
private:
|
||||
/** Internal data like zip file pointer / file list array and so on */
|
||||
|
|
|
@ -28,10 +28,10 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const long CC_INVALID_INDEX = -1;
|
||||
const int CC_INVALID_INDEX = -1;
|
||||
|
||||
/** Allocates and initializes a new array with specified capacity */
|
||||
ccArray* ccArrayNew(long capacity)
|
||||
ccArray* ccArrayNew(int capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
capacity = 7;
|
||||
|
@ -68,13 +68,13 @@ void ccArrayDoubleCapacity(ccArray *arr)
|
|||
arr->arr = newArr;
|
||||
}
|
||||
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, long extra)
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra)
|
||||
{
|
||||
while (arr->max < arr->num + extra)
|
||||
{
|
||||
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%lu] to [%lu].",
|
||||
(long) arr->max,
|
||||
(long) arr->max*2);
|
||||
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
|
||||
arr->max,
|
||||
arr->max*2);
|
||||
|
||||
ccArrayDoubleCapacity(arr);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, long extra)
|
|||
|
||||
void ccArrayShrink(ccArray *arr)
|
||||
{
|
||||
long newSize = 0;
|
||||
int newSize = 0;
|
||||
|
||||
//only resize when necessary
|
||||
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. */
|
||||
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;
|
||||
for(long i = 0; i < arrNum; ++i, ++ptr)
|
||||
for (int i = 0; i < arrNum; ++i, ++ptr)
|
||||
{
|
||||
if (*ptr == object)
|
||||
return i;
|
||||
|
@ -143,7 +143,7 @@ void ccArrayAppendObjectWithResize(ccArray *arr, Object* object)
|
|||
enough capacity. */
|
||||
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]);
|
||||
}
|
||||
|
@ -157,14 +157,14 @@ void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
|
|||
}
|
||||
|
||||
/** 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(object != NULL, "Invalid parameter!");
|
||||
|
||||
ccArrayEnsureExtraCapacity(arr, 1);
|
||||
|
||||
long remaining = arr->num - index;
|
||||
int remaining = arr->num - index;
|
||||
if (remaining > 0)
|
||||
{
|
||||
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 */
|
||||
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(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.
|
||||
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");
|
||||
if (bReleaseObj)
|
||||
|
@ -208,7 +208,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj/* = t
|
|||
|
||||
arr->num--;
|
||||
|
||||
long remaining = arr->num - index;
|
||||
int remaining = arr->num - index;
|
||||
if(remaining>0)
|
||||
{
|
||||
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,
|
||||
thereby avoiding the need to push back subsequent objects.
|
||||
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]);
|
||||
long last = --arr->num;
|
||||
auto last = --arr->num;
|
||||
arr->arr[index] = arr->arr[last];
|
||||
}
|
||||
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
||||
{
|
||||
long index = ccArrayGetIndexOfObject(arr, object);
|
||||
auto index = ccArrayGetIndexOfObject(arr, object);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
{
|
||||
ccArrayFastRemoveObjectAtIndex(arr, index);
|
||||
|
@ -238,7 +238,7 @@ void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
|||
found the function has no effect. */
|
||||
void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true*/)
|
||||
{
|
||||
long index = ccArrayGetIndexOfObject(arr, object);
|
||||
auto index = ccArrayGetIndexOfObject(arr, object);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
{
|
||||
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. */
|
||||
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]);
|
||||
}
|
||||
|
@ -259,10 +259,9 @@ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
|||
matching instances in arr will be removed. */
|
||||
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||
{
|
||||
long back = 0;
|
||||
long i = 0;
|
||||
int back = 0;
|
||||
|
||||
for( i = 0; i < arr->num; i++)
|
||||
for (int i = 0; i < arr->num; i++)
|
||||
{
|
||||
if (ccArrayContainsObject(minusArr, arr->arr[i]))
|
||||
{
|
||||
|
@ -282,7 +281,7 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
|||
// #pragma mark ccCArray for Values (c structures)
|
||||
|
||||
/** Allocates and initializes a new C array with specified capacity */
|
||||
ccCArray* ccCArrayNew(long capacity)
|
||||
ccCArray* ccCArrayNew(int capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
{
|
||||
|
@ -317,15 +316,15 @@ void ccCArrayDoubleCapacity(ccCArray *arr)
|
|||
}
|
||||
|
||||
/** Increases array capacity such that max >= num + extra. */
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, long extra)
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra)
|
||||
{
|
||||
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
|
||||
}
|
||||
|
||||
/** 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 )
|
||||
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 */
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, long index)
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, int index)
|
||||
{
|
||||
CCASSERT( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
|
||||
|
||||
long remaining = arr->num - index;
|
||||
auto remaining = arr->num - index;
|
||||
// make sure it has enough capacity
|
||||
if (arr->num + 1 == arr->max)
|
||||
{
|
||||
|
@ -385,7 +384,7 @@ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value)
|
|||
enough capacity. */
|
||||
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]);
|
||||
}
|
||||
|
@ -408,9 +407,9 @@ void ccCArrayRemoveAllValues(ccCArray *arr)
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@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];
|
||||
}
|
||||
|
@ -421,9 +420,9 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, long index)
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@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];
|
||||
}
|
||||
|
||||
|
@ -432,7 +431,7 @@ void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, long index)
|
|||
*/
|
||||
void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
||||
{
|
||||
long index = ccCArrayGetIndexOfValue(arr, value);
|
||||
auto index = ccCArrayGetIndexOfValue(arr, value);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
{
|
||||
ccCArrayRemoveValueAtIndex(arr, index);
|
||||
|
@ -444,7 +443,7 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
|||
*/
|
||||
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]);
|
||||
}
|
||||
|
@ -455,9 +454,9 @@ void ccCArrayRemoveArray(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]) )
|
||||
{
|
||||
|
|
|
@ -51,20 +51,20 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
extern const long CC_INVALID_INDEX;
|
||||
extern const int CC_INVALID_INDEX;
|
||||
|
||||
// Easy integration
|
||||
#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 {
|
||||
long num, max;
|
||||
int num, max;
|
||||
Object** arr;
|
||||
} ccArray;
|
||||
|
||||
/** 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. */
|
||||
void ccArrayFree(ccArray*& arr);
|
||||
|
@ -73,13 +73,13 @@ void ccArrayFree(ccArray*& arr);
|
|||
void ccArrayDoubleCapacity(ccArray *arr);
|
||||
|
||||
/** 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 */
|
||||
void ccArrayShrink(ccArray *arr);
|
||||
|
||||
/** 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. */
|
||||
bool ccArrayContainsObject(ccArray *arr, Object* object);
|
||||
|
@ -98,22 +98,22 @@ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr);
|
|||
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr);
|
||||
|
||||
/** Inserts an object at index */
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, long index);
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index);
|
||||
|
||||
/** Swaps two objects */
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, long index1, long index2);
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2);
|
||||
|
||||
/** Removes all objects from arr */
|
||||
void ccArrayRemoveAllObjects(ccArray *arr);
|
||||
|
||||
/** Removes object at specified index and pushes back all subsequent objects.
|
||||
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,
|
||||
thereby avoiding the need to push back subsequent objects.
|
||||
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);
|
||||
|
||||
|
@ -133,12 +133,12 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr);
|
|||
// #pragma mark ccCArray for Values (c structures)
|
||||
|
||||
typedef struct _ccCArray {
|
||||
long num, max;
|
||||
int num, max;
|
||||
void** arr;
|
||||
} ccCArray;
|
||||
|
||||
/** 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. */
|
||||
void ccCArrayFree(ccCArray *arr);
|
||||
|
@ -147,16 +147,16 @@ void ccCArrayFree(ccCArray *arr);
|
|||
void ccCArrayDoubleCapacity(ccCArray *arr);
|
||||
|
||||
/** 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. */
|
||||
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. */
|
||||
bool ccCArrayContainsValue(ccCArray *arr, void* value);
|
||||
|
||||
/** 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. */
|
||||
void ccCArrayAppendValue(ccCArray *arr, void* value);
|
||||
|
@ -178,14 +178,14 @@ void ccCArrayRemoveAllValues(ccCArray *arr);
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@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,
|
||||
thereby avoiding the need to push back subsequent values.
|
||||
Behavior undefined if index outside [0, num-1].
|
||||
@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.
|
||||
@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
|
||||
#endif
|
||||
|
||||
/** Use physics integration API */
|
||||
#ifndef CC_USE_PHYSICS
|
||||
#define CC_USE_PHYSICS
|
||||
#endif
|
||||
|
||||
#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)
|
||||
{
|
||||
int len = str.size();
|
||||
int len = static_cast<int>(str.size());
|
||||
|
||||
int i = len - 1;
|
||||
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)
|
||||
{
|
||||
int size = str->size();
|
||||
int size = static_cast<int>(str->size());
|
||||
if (index >= size || index < 0)
|
||||
return;
|
||||
|
||||
|
@ -171,7 +171,7 @@ bool isspace_unicode(unsigned short ch)
|
|||
|
||||
void cc_utf8_trim_ws(std::vector<unsigned short>* str)
|
||||
{
|
||||
int len = str->size();
|
||||
int len = static_cast<int>(str->size());
|
||||
|
||||
if ( len <= 0 )
|
||||
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 */)
|
||||
{
|
||||
int len = cc_utf8_strlen(str_old, length);
|
||||
unsigned short len = cc_utf8_strlen(str_old, length);
|
||||
if (rUtf16Size != NULL) {
|
||||
*rUtf16Size = len;
|
||||
}
|
||||
|
@ -335,21 +335,23 @@ cc_unichar_to_utf8 (unsigned short c,
|
|||
first = 0xc0;
|
||||
len = 2;
|
||||
}
|
||||
else if (c < 0x10000)
|
||||
{
|
||||
first = 0xe0;
|
||||
len = 3;
|
||||
}
|
||||
else if (c < 0x200000)
|
||||
{
|
||||
first = 0xf0;
|
||||
len = 4;
|
||||
}
|
||||
else if (c < 0x4000000)
|
||||
{
|
||||
first = 0xf8;
|
||||
len = 5;
|
||||
}
|
||||
// XXX FIXME
|
||||
// These conditions are alwasy true.
|
||||
// else if (c < 0x10000)
|
||||
// {
|
||||
// first = 0xe0;
|
||||
// len = 3;
|
||||
// }
|
||||
// else if (c < 0x200000)
|
||||
// {
|
||||
// first = 0xf0;
|
||||
// len = 4;
|
||||
// }
|
||||
// else if (c < 0x4000000)
|
||||
// {
|
||||
// first = 0xf8;
|
||||
// len = 5;
|
||||
// }
|
||||
else
|
||||
{
|
||||
first = 0xfc;
|
||||
|
@ -452,7 +454,7 @@ cc_utf16_to_utf8 (const unsigned short *str,
|
|||
}
|
||||
|
||||
/********** DIFFERENT for UTF8/UCS4 **********/
|
||||
n_bytes += UTF8_LENGTH (wc);
|
||||
n_bytes += UTF8_LENGTH (static_cast<unsigned int>(wc));
|
||||
|
||||
next1:
|
||||
in++;
|
||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||
|
||||
namespace cocos2d {
|
||||
|
||||
unsigned long ccNextPOT(unsigned long x)
|
||||
int ccNextPOT(int x)
|
||||
{
|
||||
x = x - 1;
|
||||
x = x | (x >> 1);
|
||||
|
|
|
@ -43,7 +43,7 @@ Examples:
|
|||
@since v0.99.5
|
||||
*/
|
||||
|
||||
unsigned long ccNextPOT( unsigned long value );
|
||||
int ccNextPOT(int value);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,8 @@ THE SOFTWARE.
|
|||
#include "CCDictionary.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCMap.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "CCSet.h"
|
||||
#include "CCAutoreleasePool.h"
|
||||
|
@ -70,6 +72,7 @@ THE SOFTWARE.
|
|||
#include "CCString.h"
|
||||
#include "CCNS.h"
|
||||
#include "CCData.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
// draw nodes
|
||||
#include "CCDrawingPrimitives.h"
|
||||
|
@ -199,6 +202,7 @@ THE SOFTWARE.
|
|||
#include "ccUTF8.h"
|
||||
#include "CCNotificationCenter.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "CCConsole.h"
|
||||
#include "CCUserDefault.h"
|
||||
#include "CCVertex.h"
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
<ClCompile>
|
||||
<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>
|
||||
<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>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
|
@ -121,7 +121,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
</PreBuildEvent>
|
||||
<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>
|
||||
<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>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
|
@ -169,6 +169,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="..\base\CCAffineTransform.cpp" />
|
||||
<ClCompile Include="..\base\CCArray.cpp" />
|
||||
<ClCompile Include="..\base\CCAutoreleasePool.cpp" />
|
||||
<ClCompile Include="..\base\CCConsole.cpp" />
|
||||
<ClCompile Include="..\base\CCData.cpp" />
|
||||
<ClCompile Include="..\base\CCDataVisitor.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\CCSet.cpp" />
|
||||
<ClCompile Include="..\base\CCString.cpp" />
|
||||
<ClCompile Include="..\base\CCValue.cpp" />
|
||||
<ClCompile Include="..\base\etc1.cpp" />
|
||||
<ClCompile Include="..\base\s3tc.cpp" />
|
||||
<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\CCAutoreleasePool.h" />
|
||||
<ClInclude Include="..\base\CCBool.h" />
|
||||
<ClInclude Include="..\base\CCConsole.h" />
|
||||
<ClInclude Include="..\base\CCData.h" />
|
||||
<ClInclude Include="..\base\CCDataVisitor.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\CCGeometry.h" />
|
||||
<ClInclude Include="..\base\CCInteger.h" />
|
||||
<ClInclude Include="..\base\CCMap.h" />
|
||||
<ClInclude Include="..\base\CCNS.h" />
|
||||
<ClInclude Include="..\base\CCObject.h" />
|
||||
<ClInclude Include="..\base\CCPlatformConfig.h" />
|
||||
<ClInclude Include="..\base\CCPlatformMacros.h" />
|
||||
<ClInclude Include="..\base\CCSet.h" />
|
||||
<ClInclude Include="..\base\CCString.h" />
|
||||
<ClInclude Include="..\base\CCValue.h" />
|
||||
<ClInclude Include="..\base\CCVector.h" />
|
||||
<ClInclude Include="..\base\etc1.h" />
|
||||
<ClInclude Include="..\base\s3tc.h" />
|
||||
<ClInclude Include="..\math\kazmath\include\kazmath\aabb.h" />
|
||||
|
|
|
@ -560,6 +560,12 @@
|
|||
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\CCConsole.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\CCValue.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
||||
|
@ -1125,5 +1131,17 @@
|
|||
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</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>
|
||||
</Project>
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<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>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
</Link>
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace {
|
|||
static Touch* g_touches[EventTouch::MAX_TOUCHES] = { NULL };
|
||||
static unsigned int g_indexBitsUsed = 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()
|
||||
{
|
||||
|
@ -198,9 +198,9 @@ const std::string& EGLViewProtocol::getViewName() const
|
|||
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 y = 0.0f;
|
||||
int nUnusedIndex = 0;
|
||||
|
@ -248,9 +248,9 @@ void EGLViewProtocol::handleTouchesBegin(int num, long ids[], float xs[], float
|
|||
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 y = 0.0f;
|
||||
EventTouch touchEvent;
|
||||
|
@ -280,7 +280,7 @@ void EGLViewProtocol::handleTouchesMove(int num, long ids[], float xs[], float y
|
|||
else
|
||||
{
|
||||
// It is error, should return.
|
||||
CCLOG("Moving touches with id: %ld error", id);
|
||||
CCLOG("Moving touches with id: %d error", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -296,9 +296,9 @@ void EGLViewProtocol::handleTouchesMove(int num, long ids[], float xs[], float y
|
|||
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 y = 0.0f;
|
||||
EventTouch touchEvent;
|
||||
|
@ -333,7 +333,7 @@ void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode
|
|||
}
|
||||
else
|
||||
{
|
||||
CCLOG("Ending touches with id: %ld error", id);
|
||||
CCLOG("Ending touches with id: %d error", id);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -135,10 +135,10 @@ public:
|
|||
const std::string& getViewName() const;
|
||||
|
||||
/** 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 handleTouchesMove(int num, long ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesEnd(int num, long ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesCancel(int num, long ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]);
|
||||
|
||||
/**
|
||||
* Get the opengl view port rectangle.
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -23,9 +23,8 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCFileUtils.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCString.h"
|
||||
#include "CCSAXParser.h"
|
||||
#include "tinyxml2.h"
|
||||
#include "unzip.h"
|
||||
|
@ -59,26 +58,23 @@ class DictMaker : public SAXDelegator
|
|||
{
|
||||
public:
|
||||
SAXResult _resultType;
|
||||
Array* _rootArray;
|
||||
Dictionary *_rootDict;
|
||||
Dictionary *_curDict;
|
||||
std::stack<Dictionary*> _dictStack;
|
||||
ValueMap _rootDict;
|
||||
ValueVector _rootArray;
|
||||
|
||||
std::string _curKey; ///< parsed key
|
||||
std::string _curValue; // parsed value
|
||||
SAXState _state;
|
||||
Array* _array;
|
||||
|
||||
std::stack<Array*> _arrayStack;
|
||||
ValueMap* _curDict;
|
||||
ValueVector* _curArray;
|
||||
|
||||
std::stack<ValueMap*> _dictStack;
|
||||
std::stack<ValueVector*> _arrayStack;
|
||||
std::stack<SAXState> _stateStack;
|
||||
|
||||
public:
|
||||
DictMaker()
|
||||
: _resultType(SAX_RESULT_NONE),
|
||||
_rootArray(NULL),
|
||||
_rootDict(NULL),
|
||||
_curDict(NULL),
|
||||
_state(SAX_NONE),
|
||||
_array(NULL)
|
||||
: _resultType(SAX_RESULT_NONE)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -86,50 +82,42 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
Dictionary* dictionaryWithContentsOfFile(const char *pFileName)
|
||||
ValueMap dictionaryWithContentsOfFile(const char *pFileName)
|
||||
{
|
||||
_resultType = SAX_RESULT_DICT;
|
||||
SAXParser parser;
|
||||
|
||||
if (false == parser.init("UTF-8"))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
|
||||
parser.setDelegator(this);
|
||||
|
||||
parser.parse(pFileName);
|
||||
return _rootDict;
|
||||
return std::move(_rootDict);
|
||||
}
|
||||
|
||||
Array* arrayWithContentsOfFile(const char* pFileName)
|
||||
ValueVector arrayWithContentsOfFile(const char* pFileName)
|
||||
{
|
||||
_resultType = SAX_RESULT_ARRAY;
|
||||
SAXParser parser;
|
||||
|
||||
if (false == parser.init("UTF-8"))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
|
||||
parser.setDelegator(this);
|
||||
|
||||
parser.parse(pFileName);
|
||||
return _array;
|
||||
return std::move(_rootArray);
|
||||
}
|
||||
|
||||
void startElement(void *ctx, const char *name, const char **atts)
|
||||
{
|
||||
CC_UNUSED_PARAM(ctx);
|
||||
CC_UNUSED_PARAM(atts);
|
||||
std::string sName((char*)name);
|
||||
std::string sName(name);
|
||||
if( sName == "dict" )
|
||||
{
|
||||
_curDict = new Dictionary();
|
||||
if(_resultType == SAX_RESULT_DICT && _rootDict == NULL)
|
||||
if(_resultType == SAX_RESULT_DICT && _rootDict.empty())
|
||||
{
|
||||
// Because it will call _curDict->release() later, so retain here.
|
||||
_rootDict = _curDict;
|
||||
_rootDict->retain();
|
||||
_curDict = &_rootDict;
|
||||
}
|
||||
|
||||
_state = SAX_DICT;
|
||||
|
||||
SAXState preState = SAX_NONE;
|
||||
|
@ -140,19 +128,19 @@ public:
|
|||
|
||||
if (SAX_ARRAY == preState)
|
||||
{
|
||||
// add the dictionary into the array
|
||||
_array->addObject(_curDict);
|
||||
// add a new dictionary into the array
|
||||
_curArray->push_back(Value(ValueMap()));
|
||||
_curDict = &(_curArray->rbegin())->asValueMap();
|
||||
}
|
||||
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!");
|
||||
Dictionary* pPreDict = _dictStack.top();
|
||||
pPreDict->setObject(_curDict, _curKey.c_str());
|
||||
ValueMap* preDict = _dictStack.top();
|
||||
(*preDict)[_curKey] = Value(ValueMap());
|
||||
_curDict = &(*preDict)[_curKey].asValueMap();
|
||||
}
|
||||
|
||||
_curDict->release();
|
||||
|
||||
// record the dict state
|
||||
_stateStack.push(_state);
|
||||
_dictStack.push(_curDict);
|
||||
|
@ -176,12 +164,10 @@ public:
|
|||
else if (sName == "array")
|
||||
{
|
||||
_state = SAX_ARRAY;
|
||||
_array = new Array();
|
||||
_array->init();
|
||||
if (_resultType == SAX_RESULT_ARRAY && _rootArray == NULL)
|
||||
|
||||
if (_resultType == SAX_RESULT_ARRAY && _rootArray.empty())
|
||||
{
|
||||
_rootArray = _array;
|
||||
_rootArray->retain();
|
||||
_curArray = &_rootArray;
|
||||
}
|
||||
SAXState preState = SAX_NONE;
|
||||
if (! _stateStack.empty())
|
||||
|
@ -191,18 +177,19 @@ public:
|
|||
|
||||
if (preState == SAX_DICT)
|
||||
{
|
||||
_curDict->setObject(_array, _curKey.c_str());
|
||||
(*_curDict)[_curKey] = Value(ValueVector());
|
||||
_curArray = &(*_curDict)[_curKey].asValueVector();
|
||||
}
|
||||
else if (preState == SAX_ARRAY)
|
||||
{
|
||||
CCASSERT(! _arrayStack.empty(), "The state is wrong!");
|
||||
Array* pPreArray = _arrayStack.top();
|
||||
pPreArray->addObject(_array);
|
||||
ValueVector* preArray = _arrayStack.top();
|
||||
preArray->push_back(Value(ValueVector()));
|
||||
_curArray = &(_curArray->rbegin())->asValueVector();
|
||||
}
|
||||
_array->release();
|
||||
// record the array state
|
||||
_stateStack.push(_state);
|
||||
_arrayStack.push(_array);
|
||||
_arrayStack.push(_curArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -230,49 +217,52 @@ public:
|
|||
_arrayStack.pop();
|
||||
if (! _arrayStack.empty())
|
||||
{
|
||||
_array = _arrayStack.top();
|
||||
_curArray = _arrayStack.top();
|
||||
}
|
||||
}
|
||||
else if (sName == "true")
|
||||
{
|
||||
String *str = new String("1");
|
||||
if (SAX_ARRAY == curState)
|
||||
{
|
||||
_array->addObject(str);
|
||||
_curArray->push_back(Value(true));
|
||||
}
|
||||
else if (SAX_DICT == curState)
|
||||
{
|
||||
_curDict->setObject(str, _curKey.c_str());
|
||||
(*_curDict)[_curKey] = Value(true);
|
||||
}
|
||||
str->release();
|
||||
}
|
||||
else if (sName == "false")
|
||||
{
|
||||
String *str = new String("0");
|
||||
if (SAX_ARRAY == curState)
|
||||
{
|
||||
_array->addObject(str);
|
||||
_curArray->push_back(Value(false));
|
||||
}
|
||||
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")
|
||||
{
|
||||
String* pStrValue = new String(_curValue);
|
||||
|
||||
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)
|
||||
{
|
||||
_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();
|
||||
}
|
||||
|
||||
|
@ -288,12 +278,12 @@ public:
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
case SAX_KEY:
|
||||
_curKey = pText->getCString();
|
||||
_curKey = text;
|
||||
break;
|
||||
case SAX_INT:
|
||||
case SAX_REAL:
|
||||
|
@ -304,49 +294,48 @@ public:
|
|||
CCASSERT(!_curKey.empty(), "key not found : <integer/real>");
|
||||
}
|
||||
|
||||
_curValue.append(pText->getCString());
|
||||
_curValue.append(text);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pText->release();
|
||||
}
|
||||
};
|
||||
|
||||
Dictionary* FileUtils::createDictionaryWithContentsOfFile(const std::string& filename)
|
||||
ValueMap FileUtils::getValueMapFromFile(const std::string& filename)
|
||||
{
|
||||
std::string fullPath = fullPathForFilename(filename.c_str());
|
||||
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());
|
||||
DictMaker tMaker;
|
||||
return tMaker.arrayWithContentsOfFile(fullPath.c_str());
|
||||
return std::move(tMaker.arrayWithContentsOfFile(fullPath.c_str()));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* forward statement
|
||||
*/
|
||||
static tinyxml2::XMLElement* generateElementForArray(cocos2d::Array *array, tinyxml2::XMLDocument *pDoc);
|
||||
static tinyxml2::XMLElement* generateElementForDict(cocos2d::Dictionary *dict, tinyxml2::XMLDocument *pDoc);
|
||||
static tinyxml2::XMLElement* generateElementForArray(ValueVector& array, tinyxml2::XMLDocument *pDoc);
|
||||
static tinyxml2::XMLElement* generateElementForDict(ValueMap& dict, tinyxml2::XMLDocument *pDoc);
|
||||
|
||||
/*
|
||||
* 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());
|
||||
tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument();
|
||||
if (NULL == pDoc)
|
||||
if (nullptr == pDoc)
|
||||
return false;
|
||||
|
||||
tinyxml2::XMLDeclaration *pDeclaration = pDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\"");
|
||||
if (NULL == pDeclaration)
|
||||
if (nullptr == pDeclaration)
|
||||
{
|
||||
delete pDoc;
|
||||
return false;
|
||||
|
@ -358,7 +347,7 @@ bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPa
|
|||
|
||||
tinyxml2::XMLElement *pRootEle = pDoc->NewElement("plist");
|
||||
pRootEle->SetAttribute("version", "1.0");
|
||||
if (NULL == pRootEle)
|
||||
if (nullptr == pRootEle)
|
||||
{
|
||||
delete pDoc;
|
||||
return false;
|
||||
|
@ -366,7 +355,7 @@ bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPa
|
|||
pDoc->LinkEndChild(pRootEle);
|
||||
|
||||
tinyxml2::XMLElement *innerDict = generateElementForDict(dict, pDoc);
|
||||
if (NULL == innerDict )
|
||||
if (nullptr == innerDict )
|
||||
{
|
||||
delete pDoc;
|
||||
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
|
||||
*/
|
||||
static tinyxml2::XMLElement* generateElementForObject(cocos2d::Object *object, tinyxml2::XMLDocument *pDoc)
|
||||
static tinyxml2::XMLElement* generateElementForObject(Value& value, tinyxml2::XMLDocument *pDoc)
|
||||
{
|
||||
// object is String
|
||||
if (String *str = dynamic_cast<String *>(object))
|
||||
if (value.getType() == Value::Type::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);
|
||||
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
|
||||
if (Array *array = dynamic_cast<Array *>(object))
|
||||
return generateElementForArray(array, pDoc);
|
||||
if (value.getType() == Value::Type::VECTOR)
|
||||
return generateElementForArray(value.asValueVector(), pDoc);
|
||||
|
||||
// object is Dictionary
|
||||
if (Dictionary *innerDict = dynamic_cast<Dictionary *>(object))
|
||||
return generateElementForDict(innerDict, pDoc);
|
||||
if (value.getType() == Value::Type::MAP)
|
||||
return generateElementForDict(value.asValueMap(), pDoc);
|
||||
|
||||
CCLOG("This type cannot appear in property list");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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");
|
||||
|
||||
DictElement *dictElement = NULL;
|
||||
CCDICT_FOREACH(dict, dictElement)
|
||||
for (auto iter = dict.begin(); iter != dict.end(); ++iter)
|
||||
{
|
||||
tinyxml2::XMLElement* tmpNode = pDoc->NewElement("key");
|
||||
rootNode->LinkEndChild(tmpNode);
|
||||
tinyxml2::XMLText* content = pDoc->NewText(dictElement->getStrKey());
|
||||
tinyxml2::XMLText* content = pDoc->NewText(iter->first.c_str());
|
||||
tmpNode->LinkEndChild(content);
|
||||
|
||||
Object *object = dictElement->getObject();
|
||||
tinyxml2::XMLElement *element = generateElementForObject(object, pDoc);
|
||||
tinyxml2::XMLElement *element = generateElementForObject(iter->second, pDoc);
|
||||
if (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
|
||||
*/
|
||||
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");
|
||||
|
||||
Object *object = NULL;
|
||||
CCARRAY_FOREACH(array, object)
|
||||
{
|
||||
tinyxml2::XMLElement *element = generateElementForObject(object, pDoc);
|
||||
std::for_each(array.begin(), array.end(), [=](Value& value){
|
||||
tinyxml2::XMLElement *element = generateElementForObject(value, pDoc);
|
||||
if (element)
|
||||
rootNode->LinkEndChild(element);
|
||||
}
|
||||
|
||||
});
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
|
@ -450,14 +456,14 @@ static tinyxml2::XMLElement* generateElementForArray(cocos2d::Array *array, tiny
|
|||
NS_CC_BEGIN
|
||||
|
||||
/* The subclass FileUtilsApple should override these two method. */
|
||||
Dictionary* FileUtils::createDictionaryWithContentsOfFile(const std::string& filename) {return NULL;}
|
||||
bool FileUtils::writeToFile(cocos2d::Dictionary *dict, const std::string &fullPath) {return false;}
|
||||
Array* FileUtils::createArrayWithContentsOfFile(const std::string& filename) {return NULL;}
|
||||
ValueMap FileUtils::getValueMapFromFile(const std::string& filename) {return ValueMap();}
|
||||
ValueVector FileUtils::getValueVectorFromFile(const std::string& filename) {return ValueVector();}
|
||||
bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath) {return false;}
|
||||
|
||||
#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()
|
||||
|
@ -466,13 +472,11 @@ void FileUtils::destroyInstance()
|
|||
}
|
||||
|
||||
FileUtils::FileUtils()
|
||||
: _filenameLookupDict(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
FileUtils::~FileUtils()
|
||||
{
|
||||
CC_SAFE_RELEASE(_filenameLookupDict);
|
||||
}
|
||||
|
||||
|
||||
|
@ -488,10 +492,10 @@ void FileUtils::purgeCachedEntries()
|
|||
_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;
|
||||
CCASSERT(filename != NULL && size != NULL && mode != NULL, "Invalid parameters.");
|
||||
unsigned char * buffer = nullptr;
|
||||
CCASSERT(filename != nullptr && size != nullptr && mode != nullptr, "Invalid parameters.");
|
||||
*size = 0;
|
||||
do
|
||||
{
|
||||
|
@ -518,10 +522,10 @@ unsigned char* FileUtils::getFileData(const char* filename, const char* mode, lo
|
|||
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;
|
||||
unzFile pFile = NULL;
|
||||
unsigned char * buffer = nullptr;
|
||||
unzFile pFile = nullptr;
|
||||
*size = 0;
|
||||
|
||||
do
|
||||
|
@ -537,14 +541,14 @@ unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char
|
|||
|
||||
char szFilePathA[260];
|
||||
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);
|
||||
|
||||
nRet = unzOpenCurrentFile(pFile);
|
||||
CC_BREAK_IF(UNZ_OK != nRet);
|
||||
|
||||
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");
|
||||
|
||||
*size = FileInfo.uncompressed_size;
|
||||
|
@ -564,12 +568,15 @@ std::string FileUtils::getNewFilename(const std::string &filename)
|
|||
std::string newFileName;
|
||||
|
||||
// in Lookup Filename dictionary ?
|
||||
String* fileNameFound = _filenameLookupDict ? (String*)_filenameLookupDict->objectForKey(filename) : NULL;
|
||||
if( NULL == fileNameFound || fileNameFound->length() == 0) {
|
||||
auto iter = _filenameLookupDict.find(filename);
|
||||
|
||||
if (iter == _filenameLookupDict.end())
|
||||
{
|
||||
newFileName = filename;
|
||||
}
|
||||
else {
|
||||
newFileName = fileNameFound->getCString();
|
||||
else
|
||||
{
|
||||
newFileName = iter->second.asString();
|
||||
}
|
||||
return newFileName;
|
||||
}
|
||||
|
@ -731,12 +738,10 @@ void FileUtils::addSearchPath(const std::string &searchpath)
|
|||
_searchPathArray.push_back(path);
|
||||
}
|
||||
|
||||
void FileUtils::setFilenameLookupDictionary(Dictionary* pFilenameLookupDict)
|
||||
void FileUtils::setFilenameLookupDictionary(const ValueMap& filenameLookupDict)
|
||||
{
|
||||
_fullPathCache.clear();
|
||||
CC_SAFE_RELEASE(_filenameLookupDict);
|
||||
_filenameLookupDict = pFilenameLookupDict;
|
||||
CC_SAFE_RETAIN(_filenameLookupDict);
|
||||
_filenameLookupDict = filenameLookupDict;
|
||||
}
|
||||
|
||||
void FileUtils::loadFilenameLookupDictionaryFromFile(const std::string &filename)
|
||||
|
@ -744,17 +749,17 @@ void FileUtils::loadFilenameLookupDictionaryFromFile(const std::string &filename
|
|||
std::string fullPath = fullPathForFilename(filename);
|
||||
if (fullPath.length() > 0)
|
||||
{
|
||||
Dictionary* dict = Dictionary::createWithContentsOfFile(fullPath.c_str());
|
||||
if (dict)
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
|
||||
if (!dict.empty())
|
||||
{
|
||||
Dictionary* metadata = static_cast<Dictionary*>( dict->objectForKey("metadata") );
|
||||
int version = static_cast<String*>( metadata->objectForKey("version"))->intValue();
|
||||
ValueMap& metadata = dict["metadata"].asValueMap();
|
||||
int version = metadata["version"].asInt();
|
||||
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;
|
||||
}
|
||||
setFilenameLookupDictionary( static_cast<Dictionary*>( dict->objectForKey("filenames")) );
|
||||
setFilenameLookupDictionary( dict["filenames"].asValueMap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,11 +29,10 @@ THE SOFTWARE.
|
|||
#include <unordered_map>
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Dictionary;
|
||||
class Array;
|
||||
/**
|
||||
* @addtogroup platform
|
||||
* @{
|
||||
|
@ -42,10 +41,7 @@ class Array;
|
|||
//! @brief Helper class to handle file operations
|
||||
class CC_DLL FileUtils
|
||||
{
|
||||
friend class Array;
|
||||
friend class Dictionary;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Gets the instance of FileUtils.
|
||||
*/
|
||||
|
@ -88,7 +84,7 @@ public:
|
|||
* @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.
|
||||
*/
|
||||
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.
|
||||
|
@ -98,7 +94,7 @@ public:
|
|||
* @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.
|
||||
*/
|
||||
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.
|
||||
|
@ -189,7 +185,7 @@ public:
|
|||
* @param pFilenameLookupDict The dictionary for replacing filename.
|
||||
* @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.
|
||||
|
@ -300,6 +296,24 @@ public:
|
|||
virtual void setPopupNotify(bool notify);
|
||||
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:
|
||||
/**
|
||||
* The default constructor.
|
||||
|
@ -347,23 +361,6 @@ protected:
|
|||
*/
|
||||
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.
|
||||
* It is used internally by the following methods:
|
||||
|
@ -372,7 +369,7 @@ protected:
|
|||
*
|
||||
* @since v2.1
|
||||
*/
|
||||
Dictionary* _filenameLookupDict;
|
||||
ValueMap _filenameLookupDict;
|
||||
|
||||
/**
|
||||
* The vector contains resolution folders.
|
||||
|
|
|
@ -121,10 +121,10 @@ public:
|
|||
* @js 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
|
||||
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.
|
||||
|
@ -175,7 +175,7 @@ public:
|
|||
|
||||
// Getters
|
||||
inline unsigned char * getData() { return _data; }
|
||||
inline int getDataLen() { return _dataLen; }
|
||||
inline ssize_t getDataLen() { return _dataLen; }
|
||||
inline Format getFileType() {return _fileType; }
|
||||
inline Texture2D::PixelFormat getRenderFormat() { return _renderFormat; }
|
||||
inline int getWidth() { return _width; }
|
||||
|
@ -198,16 +198,16 @@ public:
|
|||
bool saveToFile(const std::string &filename, bool isToRGB = true);
|
||||
|
||||
protected:
|
||||
bool initWithJpgData(const unsigned char * data, int dataLen);
|
||||
bool initWithPngData(const unsigned char * data, int dataLen);
|
||||
bool initWithTiffData(const unsigned char * data, int dataLen);
|
||||
bool initWithWebpData(const unsigned char * data, int dataLen);
|
||||
bool initWithPVRData(const unsigned char * data, int dataLen);
|
||||
bool initWithPVRv2Data(const unsigned char * data, int dataLen);
|
||||
bool initWithPVRv3Data(const unsigned char * data, int dataLen);
|
||||
bool initWithETCData(const unsigned char * data, int dataLen);
|
||||
bool initWithS3TCData(const unsigned char * data, int dataLen);
|
||||
bool initWithATITCData(const unsigned char *data, int dataLen);
|
||||
bool initWithJpgData(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithPngData(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithTiffData(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithWebpData(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithPVRData(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithPVRv2Data(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithPVRv3Data(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithETCData(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithS3TCData(const unsigned char * data, ssize_t dataLen);
|
||||
bool initWithATITCData(const unsigned char *data, ssize_t dataLen);
|
||||
typedef struct sImageTGA tImageTGA;
|
||||
bool initWithTGAData(tImageTGA* tgaData);
|
||||
|
||||
|
@ -221,7 +221,7 @@ private:
|
|||
*/
|
||||
static const int MIPMAP_MAX = 16;
|
||||
unsigned char *_data;
|
||||
int _dataLen;
|
||||
ssize_t _dataLen;
|
||||
int _width;
|
||||
int _height;
|
||||
Format _fileType;
|
||||
|
@ -248,15 +248,15 @@ private:
|
|||
*/
|
||||
bool initWithImageFileThreadSafe(const char *fullpath);
|
||||
|
||||
Format detectFormat(const unsigned char * data, int dataLen);
|
||||
bool isPng(const unsigned char * data, int dataLen);
|
||||
bool isJpg(const unsigned char * data, int dataLen);
|
||||
bool isTiff(const unsigned char * data, int dataLen);
|
||||
bool isWebp(const unsigned char * data, int dataLen);
|
||||
bool isPvr(const unsigned char * data, int dataLen);
|
||||
bool isEtc(const unsigned char * data, int dataLen);
|
||||
bool isS3TC(const unsigned char * data,int dataLen);
|
||||
bool isATITC(const unsigned char *data, int dataLen);
|
||||
Format detectFormat(const unsigned char * data, ssize_t dataLen);
|
||||
bool isPng(const unsigned char * data, ssize_t dataLen);
|
||||
bool isJpg(const unsigned char * data, ssize_t dataLen);
|
||||
bool isTiff(const unsigned char * data, ssize_t dataLen);
|
||||
bool isWebp(const unsigned char * data, ssize_t dataLen);
|
||||
bool isPvr(const unsigned char * data, ssize_t dataLen);
|
||||
bool isEtc(const unsigned char * data, ssize_t dataLen);
|
||||
bool isS3TC(const unsigned char * data,ssize_t dataLen);
|
||||
bool isATITC(const unsigned char *data, ssize_t dataLen);
|
||||
};
|
||||
|
||||
// end of platform group
|
||||
|
|
|
@ -349,7 +349,7 @@ namespace
|
|||
typedef struct
|
||||
{
|
||||
const unsigned char * data;
|
||||
int size;
|
||||
ssize_t size;
|
||||
int offset;
|
||||
}tImageSource;
|
||||
|
||||
|
@ -420,7 +420,7 @@ bool Image::initWithImageFile(const char * strPath)
|
|||
|
||||
SDL_FreeSurface(iSurf);
|
||||
#else
|
||||
long bufferLen = 0;
|
||||
ssize_t bufferLen = 0;
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(_filePath.c_str(), "rb", &bufferLen);
|
||||
|
||||
if (buffer != nullptr && bufferLen > 0)
|
||||
|
@ -437,7 +437,7 @@ bool Image::initWithImageFile(const char * strPath)
|
|||
bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
||||
{
|
||||
bool ret = false;
|
||||
long dataLen = 0;
|
||||
ssize_t dataLen = 0;
|
||||
_filePath = fullpath;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance();
|
||||
|
@ -453,7 +453,7 @@ bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
||||
bool Image::initWithImageData(const unsigned char * data, ssize_t dataLen)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
|
@ -462,7 +462,7 @@ bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
|||
CC_BREAK_IF(! data || dataLen <= 0);
|
||||
|
||||
unsigned char* unpackedData = nullptr;
|
||||
int unpackedLen = 0;
|
||||
ssize_t unpackedLen = 0;
|
||||
|
||||
//detecgt and unzip the compress file
|
||||
if (ZipUtils::isCCZBuffer(data, dataLen))
|
||||
|
@ -535,7 +535,7 @@ bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Image::isPng(const unsigned char * data, int dataLen)
|
||||
bool Image::isPng(const unsigned char * data, ssize_t dataLen)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
bool Image::isS3TC(const unsigned char * data, int dataLen)
|
||||
bool Image::isS3TC(const unsigned char * data, ssize_t dataLen)
|
||||
{
|
||||
|
||||
S3TCTexHeader *header = (S3TCTexHeader *)data;
|
||||
|
@ -567,7 +567,7 @@ bool Image::isS3TC(const unsigned char * data, int dataLen)
|
|||
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;
|
||||
|
||||
|
@ -579,7 +579,7 @@ bool Image::isATITC(const unsigned char *data, int dataLen)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Image::isJpg(const unsigned char * data, int dataLen)
|
||||
bool Image::isJpg(const unsigned char * data, ssize_t dataLen)
|
||||
{
|
||||
if (dataLen <= 4)
|
||||
{
|
||||
|
@ -591,7 +591,7 @@ bool Image::isJpg(const unsigned char * data, int dataLen)
|
|||
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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
bool Image::isWebp(const unsigned char * data, int dataLen)
|
||||
bool Image::isWebp(const unsigned char * data, ssize_t dataLen)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -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) */
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
|
@ -841,7 +841,7 @@ bool Image::initWithJpgData(const unsigned char * data, int dataLen)
|
|||
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
|
||||
#define PNGSIGSIZE 8
|
||||
|
@ -941,7 +941,7 @@ bool Image::initWithPngData(const unsigned char * data, int dataLen)
|
|||
}
|
||||
|
||||
// read png data
|
||||
png_uint_32 rowbytes;
|
||||
png_size_t rowbytes;
|
||||
png_bytep* row_pointers = (png_bytep*)malloc( sizeof(png_bytep) * _height );
|
||||
|
||||
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;
|
||||
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 blockSize = 0, widthBlocks = 0, heightBlocks = 0;
|
||||
|
@ -1305,7 +1305,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen)
|
|||
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))
|
||||
{
|
||||
|
@ -1414,11 +1414,11 @@ bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen)
|
|||
}
|
||||
|
||||
dataSize = widthBlocks * heightBlocks * ((blockSize * it->second.bpp) / 8);
|
||||
int packetLength = _dataLen - dataOffset;
|
||||
auto packetLength = _dataLen - dataOffset;
|
||||
packetLength = packetLength > dataSize ? dataSize : packetLength;
|
||||
|
||||
_mipmaps[i].address = _data + dataOffset;
|
||||
_mipmaps[i].len = packetLength;
|
||||
_mipmaps[i].len = static_cast<int>(packetLength);
|
||||
|
||||
dataOffset += packetLength;
|
||||
CCAssert(dataOffset <= _dataLen, "CCTexurePVR: Invalid lenght");
|
||||
|
@ -1431,7 +1431,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen)
|
|||
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);
|
||||
|
||||
|
@ -1548,7 +1548,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
|
|||
const unsigned char tgaSuffix[] = ".tga";
|
||||
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());
|
||||
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');
|
||||
|
@ -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 */
|
||||
ATITCTexHeader *header = (ATITCTexHeader *)data;
|
||||
|
@ -1826,12 +1826,12 @@ bool Image::initWithATITCData(const unsigned char *data, int dataLen)
|
|||
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);
|
||||
}
|
||||
|
||||
bool Image::initWithWebpData(const unsigned char * data, int dataLen)
|
||||
bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
|
@ -1866,7 +1866,7 @@ bool Image::initWithWebpData(const unsigned char * data, int dataLen)
|
|||
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;
|
||||
do
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCSAXParser.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
|
@ -82,7 +81,7 @@ bool XmlSaxHander::VisitExit( const tinyxml2::XMLElement& element )
|
|||
bool XmlSaxHander::Visit( const tinyxml2::XMLText& text )
|
||||
{
|
||||
//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;
|
||||
}
|
||||
|
||||
|
@ -102,7 +101,7 @@ bool SAXParser::init(const char *pszEncoding)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength)
|
||||
bool SAXParser::parse(const char* pXMLData, size_t uDataLength)
|
||||
{
|
||||
tinyxml2::XMLDocument tinyDoc;
|
||||
tinyDoc.Parse(pXMLData, uDataLength);
|
||||
|
@ -115,7 +114,7 @@ bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength)
|
|||
bool SAXParser::parse(const char *pszFile)
|
||||
{
|
||||
bool ret = false;
|
||||
long size = 0;
|
||||
ssize_t size = 0;
|
||||
char* pBuffer = (char*)FileUtils::getInstance()->getFileData(pszFile, "rt", &size);
|
||||
if (pBuffer != NULL && size > 0)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "CCPlatformConfig.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "string.h" // for size_t
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -81,7 +82,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool parse(const char* pXMLData, unsigned int uDataLength);
|
||||
bool parse(const char* pXMLData, size_t uDataLength);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -29,10 +29,6 @@ NS_CC_BEGIN
|
|||
// iOS and Mac already has a Thread.mm
|
||||
#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()
|
||||
{
|
||||
|
@ -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
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -59,29 +59,6 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
/* override funtions */
|
||||
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 bool isFileExist(const std::string& strFilePath) const;
|
||||
|
@ -64,10 +64,10 @@ public:
|
|||
/** This function is android specific. It is used for TextureCache::addImageAsync().
|
||||
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:
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue