mirror of https://github.com/axmolengine/axmol.git
merge from develop branch
This commit is contained in:
commit
ef76edbd1c
17
AUTHORS
17
AUTHORS
|
@ -668,6 +668,7 @@ Developers:
|
|||
|
||||
zhiqiangxu
|
||||
Fixed a logic error in ControlUtils::RectUnion.
|
||||
Fixed an issue that there is an useless conversion in ScrollView::onTouchBegan.
|
||||
|
||||
yinkaile (2youyouo2)
|
||||
Maintainer of Armature Bone Animation.
|
||||
|
@ -677,6 +678,22 @@ Developers:
|
|||
|
||||
seobyeongky
|
||||
Updates spine runtime.
|
||||
Fixed a potential bug in Data's copy constructor.
|
||||
|
||||
luocker
|
||||
Fix a bug that string itself is also modified in `String::componentsSeparatedByString`.
|
||||
|
||||
omersaeed
|
||||
Fix a bug that game will crash if connection breaks during download using AssetManager.
|
||||
|
||||
SBKarr
|
||||
AngelCode binary file format support for LabelBMFont.
|
||||
|
||||
zarelaky
|
||||
OpenAL context isn't destroyed correctly on mac and ios.
|
||||
|
||||
kicktheken (Kenneth Chan)
|
||||
Fixed a bug that the setBlendFunc method of some classes wasn't exposed to LUA.
|
||||
|
||||
Retired Core Developers:
|
||||
WenSheng Yang
|
||||
|
|
11
CHANGELOG
11
CHANGELOG
|
@ -12,6 +12,15 @@ cocos2d-x-3.0beta0 ?? 2013
|
|||
[FIX] Potential hash collision fix.
|
||||
[FIX] Updates spine runtime to the latest version.
|
||||
[FIX] Uses `const std::string&` instead of `const char*`.
|
||||
[FIX] LabelBMFont string can't be shown integrally.
|
||||
[FIX] Deprecates FileUtils::getFileData, adds FileUtils::getStringFromFile/getDataFromFile.
|
||||
[FIX] GUI refactoring: Removes UI prefix, Widget is inherited from Node, uses new containers(Vector<T>, Map<K,V>).
|
||||
[FIX] String itself is also modified in `String::componentsSeparatedByString`.
|
||||
[FIX] Sprites with PhysicsBody move to a wrong position when game resume from background.
|
||||
[FIX] Crash if connection breaks during download using AssetManager.
|
||||
[NEW] AngelCode binary file format support for LabelBMFont.
|
||||
[FIX] OpenAL context isn't destroyed correctly on mac and ios.
|
||||
[FIX] Useless conversion in ScrollView::onTouchBegan.
|
||||
[Android]
|
||||
[NEW] build/android-build.sh: add supporting to generate .apk file
|
||||
[FIX] XMLHttpRequest receives wrong binary array.
|
||||
|
@ -23,6 +32,8 @@ cocos2d-x-3.0beta0 ?? 2013
|
|||
[Bindings]
|
||||
[FIX] Don't bind override functions for JSB and LuaBining since they aren't needed at all.
|
||||
[NEW] Adds spine JS binding support.
|
||||
[FIX] The order of onEnter and onExit is wrong.
|
||||
[FIX] The setBlendFunc method of some classes wasn't exposed to LUA.
|
||||
|
||||
cocos2d-x-3.0alpha1 Nov.19 2013
|
||||
[all platforms]
|
||||
|
|
|
@ -269,8 +269,6 @@ endif(BUILD_EDITOR_COCOSBUILDER)
|
|||
if(BUILD_EDITOR_COCOSTUDIO)
|
||||
# cocostudio
|
||||
add_subdirectory(cocos/editor-support/cocostudio)
|
||||
# jsoncpp library, cocostuido depends on jsoncpp
|
||||
add_subdirectory(external/json)
|
||||
endif(BUILD_EDITOR_COCOSTUDIO)
|
||||
|
||||
if(BUILD_LIBS_LUA)
|
||||
|
@ -286,4 +284,19 @@ add_subdirectory(cocos/scripting)
|
|||
endif(BUILD_LIBS_LUA)
|
||||
|
||||
# build samples
|
||||
add_subdirectory(samples)
|
||||
if(BUILD_HelloCpp)
|
||||
add_subdirectory(samples/Cpp/HelloCpp)
|
||||
endif(BUILD_HelloCpp)
|
||||
|
||||
if(BUILD_TestCpp)
|
||||
add_subdirectory(samples/Cpp/TestCpp)
|
||||
endif(BUILD_TestCpp)
|
||||
|
||||
if(BUILD_HelloLua)
|
||||
add_subdirectory(samples/Lua/HelloLua)
|
||||
endif(BUILD_HelloLua)
|
||||
|
||||
if(BUILD_TestLua)
|
||||
add_subdirectory(samples/Lua/TestLua)
|
||||
endif(BUILD_TestLua)
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ How to start a new game
|
|||
Example:
|
||||
|
||||
$ cd cocos2d-x/tools/project-creator
|
||||
$ ./create-multi-platform-projects.py -p mygame -k com.your_company.mygame -l cpp
|
||||
$ cd ../../projects/mygame
|
||||
$ ./project-creator.pyw -n mygame -k com.your_company.mygame -l cpp -p /home/mygame
|
||||
$ cd /home/mygame
|
||||
|
||||
|
||||
Main features
|
||||
|
|
|
@ -1 +1 @@
|
|||
fc76c8739d4c7baa28d56f632e8d4c98c5eaf85e
|
||||
4b92c964454c54c1b5df9576f11365c53e253724
|
|
@ -1 +1 @@
|
|||
f36b451a97f9a0c93a4e23c417d7333f1e293993
|
||||
7cc2be4e284d9095dd8fa56a092a98562f132776
|
|
@ -43,7 +43,7 @@ NS_CC_BEGIN;
|
|||
* Implementation of PointArray
|
||||
*/
|
||||
|
||||
PointArray* PointArray::create(int capacity)
|
||||
PointArray* PointArray::create(ssize_t capacity)
|
||||
{
|
||||
PointArray* pointArray = new PointArray();
|
||||
if (pointArray)
|
||||
|
@ -63,7 +63,7 @@ PointArray* PointArray::create(int capacity)
|
|||
}
|
||||
|
||||
|
||||
bool PointArray::initWithCapacity(int capacity)
|
||||
bool PointArray::initWithCapacity(ssize_t 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, int index)
|
||||
void PointArray::insertControlPoint(Point &controlPoint, ssize_t index)
|
||||
{
|
||||
Point *temp = new Point(controlPoint.x, controlPoint.y);
|
||||
_controlPoints->insert(_controlPoints->begin() + index, temp);
|
||||
}
|
||||
|
||||
Point PointArray::getControlPointAtIndex(int index)
|
||||
Point PointArray::getControlPointAtIndex(ssize_t index)
|
||||
{
|
||||
index = static_cast<int>(MIN(_controlPoints->size()-1, MAX(index, 0)));
|
||||
return *(_controlPoints->at(index));
|
||||
}
|
||||
|
||||
void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, int index)
|
||||
void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, ssize_t index)
|
||||
{
|
||||
|
||||
Point *temp = _controlPoints->at(index);
|
||||
|
@ -146,7 +146,7 @@ void PointArray::replaceControlPoint(cocos2d::Point &controlPoint, int index)
|
|||
temp->y = controlPoint.y;
|
||||
}
|
||||
|
||||
void PointArray::removeControlPointAtIndex(int index)
|
||||
void PointArray::removeControlPointAtIndex(ssize_t index)
|
||||
{
|
||||
vector<Point*>::iterator iter = _controlPoints->begin() + index;
|
||||
Point* removedPoint = *iter;
|
||||
|
@ -154,9 +154,9 @@ void PointArray::removeControlPointAtIndex(int index)
|
|||
delete removedPoint;
|
||||
}
|
||||
|
||||
int PointArray::count() const
|
||||
ssize_t PointArray::count() const
|
||||
{
|
||||
return static_cast<int>(_controlPoints->size());
|
||||
return _controlPoints->size();
|
||||
}
|
||||
|
||||
PointArray* PointArray::reverse() const
|
||||
|
@ -177,11 +177,11 @@ PointArray* PointArray::reverse() const
|
|||
|
||||
void PointArray::reverseInline()
|
||||
{
|
||||
auto l = _controlPoints->size();
|
||||
size_t l = _controlPoints->size();
|
||||
Point *p1 = nullptr;
|
||||
Point *p2 = nullptr;
|
||||
int x, y;
|
||||
for (int i = 0; i < l/2; ++i)
|
||||
float x, y;
|
||||
for (size_t 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)
|
||||
{
|
||||
int p;
|
||||
ssize_t p;
|
||||
float lt;
|
||||
|
||||
// eg.
|
||||
|
@ -383,7 +383,7 @@ CardinalSplineBy* CardinalSplineBy::reverse() const
|
|||
// convert "absolutes" to "diffs"
|
||||
//
|
||||
Point p = copyConfig->getControlPointAtIndex(0);
|
||||
for (unsigned int i = 1; i < copyConfig->count(); ++i)
|
||||
for (ssize_t i = 1; i < copyConfig->count(); ++i)
|
||||
{
|
||||
Point current = copyConfig->getControlPointAtIndex(i);
|
||||
Point diff = current - p;
|
||||
|
@ -405,7 +405,7 @@ CardinalSplineBy* CardinalSplineBy::reverse() const
|
|||
p = -p;
|
||||
pReverse->insertControlPoint(p, 0);
|
||||
|
||||
for (unsigned int i = 1; i < pReverse->count(); ++i)
|
||||
for (ssize_t i = 1; i < pReverse->count(); ++i)
|
||||
{
|
||||
Point current = pReverse->getControlPointAtIndex(i);
|
||||
current = -current;
|
||||
|
@ -528,7 +528,7 @@ CatmullRomBy* CatmullRomBy::reverse() const
|
|||
// convert "absolutes" to "diffs"
|
||||
//
|
||||
Point p = copyConfig->getControlPointAtIndex(0);
|
||||
for (unsigned int i = 1; i < copyConfig->count(); ++i)
|
||||
for (ssize_t i = 1; i < copyConfig->count(); ++i)
|
||||
{
|
||||
Point current = copyConfig->getControlPointAtIndex(i);
|
||||
Point diff = current - p;
|
||||
|
@ -550,7 +550,7 @@ CatmullRomBy* CatmullRomBy::reverse() const
|
|||
p = -p;
|
||||
reverse->insertControlPoint(p, 0);
|
||||
|
||||
for (unsigned int i = 1; i < reverse->count(); ++i)
|
||||
for (ssize_t i = 1; i < reverse->count(); ++i)
|
||||
{
|
||||
Point current = reverse->getControlPointAtIndex(i);
|
||||
current = -current;
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
/** creates and initializes a Points array with capacity
|
||||
* @js NA
|
||||
*/
|
||||
static PointArray* create(int capacity);
|
||||
static PointArray* create(ssize_t capacity);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
|
@ -77,7 +77,7 @@ public:
|
|||
/** initializes a Catmull Rom config with a capacity hint
|
||||
* @js NA
|
||||
*/
|
||||
bool initWithCapacity(int capacity);
|
||||
bool initWithCapacity(ssize_t capacity);
|
||||
|
||||
/** appends a control point
|
||||
* @js NA
|
||||
|
@ -87,27 +87,27 @@ public:
|
|||
/** inserts a controlPoint at index
|
||||
* @js NA
|
||||
*/
|
||||
void insertControlPoint(Point &controlPoint, int index);
|
||||
void insertControlPoint(Point &controlPoint, ssize_t index);
|
||||
|
||||
/** replaces an existing controlPoint at index
|
||||
* @js NA
|
||||
*/
|
||||
void replaceControlPoint(Point &controlPoint, int index);
|
||||
void replaceControlPoint(Point &controlPoint, ssize_t index);
|
||||
|
||||
/** get the value of a controlPoint at a given index
|
||||
* @js NA
|
||||
*/
|
||||
Point getControlPointAtIndex(int index);
|
||||
Point getControlPointAtIndex(ssize_t index);
|
||||
|
||||
/** deletes a control point at a given index
|
||||
* @js NA
|
||||
*/
|
||||
void removeControlPointAtIndex(int index);
|
||||
void removeControlPointAtIndex(ssize_t index);
|
||||
|
||||
/** returns the number of objects of the control point array
|
||||
* @js NA
|
||||
*/
|
||||
int count() const;
|
||||
ssize_t count() const;
|
||||
|
||||
/** returns a new copy of the array reversed. User is responsible for releasing this copy
|
||||
* @js NA
|
||||
|
|
|
@ -2053,7 +2053,7 @@ void Animate::startWithTarget(Node *target)
|
|||
|
||||
if (_animation->getRestoreOriginalFrame())
|
||||
{
|
||||
_origFrame = sprite->getDisplayFrame();
|
||||
_origFrame = sprite->getSpriteFrame();
|
||||
_origFrame->retain();
|
||||
}
|
||||
_nextFrame = 0;
|
||||
|
@ -2064,7 +2064,7 @@ void Animate::stop(void)
|
|||
{
|
||||
if (_animation->getRestoreOriginalFrame() && _target)
|
||||
{
|
||||
static_cast<Sprite*>(_target)->setDisplayFrame(_origFrame);
|
||||
static_cast<Sprite*>(_target)->setSpriteFrame(_origFrame);
|
||||
}
|
||||
|
||||
ActionInterval::stop();
|
||||
|
@ -2097,7 +2097,7 @@ void Animate::update(float t)
|
|||
if( splitTime <= t ) {
|
||||
AnimationFrame* frame = frames.at(i);
|
||||
frameToDisplay = frame->getSpriteFrame();
|
||||
static_cast<Sprite*>(_target)->setDisplayFrame(frameToDisplay);
|
||||
static_cast<Sprite*>(_target)->setSpriteFrame(frameToDisplay);
|
||||
|
||||
const ValueMap& dict = frame->getUserInfo();
|
||||
if ( !dict.empty() )
|
||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
|||
#include "CCProtocols.h"
|
||||
#include "CCSpriteFrame.h"
|
||||
#include "CCAnimation.h"
|
||||
#include <CCVector.h>
|
||||
#include "CCVector.h"
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
|
|
@ -102,7 +102,8 @@ void AnimationCache::parseVersion1(const ValueMap& animations)
|
|||
continue;
|
||||
}
|
||||
|
||||
Vector<AnimationFrame*> frames(static_cast<int>(frameNames.size()));
|
||||
ssize_t frameNameSize = frameNames.size();
|
||||
Vector<AnimationFrame*> frames(frameNameSize);
|
||||
|
||||
for (auto& frameName : frameNames)
|
||||
{
|
||||
|
@ -118,12 +119,12 @@ void AnimationCache::parseVersion1(const ValueMap& animations)
|
|||
frames.pushBack(animFrame);
|
||||
}
|
||||
|
||||
if ( frames.size() == 0 )
|
||||
if ( frames.empty() )
|
||||
{
|
||||
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.size() != frameNames.size() )
|
||||
else if ( frames.size() != frameNameSize )
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ THE SOFTWARE.
|
|||
#include "CCDirector.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
|
||||
// external
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
@ -151,8 +151,7 @@ void AtlasNode::draw(void)
|
|||
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,
|
||||
_quadCommand.init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
|
@ -161,7 +160,7 @@ void AtlasNode::draw(void)
|
|||
_textureAtlas->getTotalQuads(),
|
||||
_modelViewTransform);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
|
||||
}
|
||||
|
||||
|
@ -263,12 +262,12 @@ TextureAtlas * AtlasNode::getTextureAtlas() const
|
|||
return _textureAtlas;
|
||||
}
|
||||
|
||||
int AtlasNode::getQuadsToDraw() const
|
||||
ssize_t AtlasNode::getQuadsToDraw() const
|
||||
{
|
||||
return _quadsToDraw;
|
||||
}
|
||||
|
||||
void AtlasNode::setQuadsToDraw(int quadsToDraw)
|
||||
void AtlasNode::setQuadsToDraw(ssize_t quadsToDraw)
|
||||
{
|
||||
_quadsToDraw = quadsToDraw;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ THE SOFTWARE.
|
|||
#include "CCNode.h"
|
||||
#include "CCProtocols.h"
|
||||
#include "ccTypes.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -62,8 +63,8 @@ public:
|
|||
void setTextureAtlas(TextureAtlas* textureAtlas);
|
||||
TextureAtlas* getTextureAtlas() const;
|
||||
|
||||
void setQuadsToDraw(int quadsToDraw);
|
||||
int getQuadsToDraw() const;
|
||||
void setQuadsToDraw(ssize_t quadsToDraw);
|
||||
ssize_t getQuadsToDraw() const;
|
||||
|
||||
|
||||
// Overrides
|
||||
|
@ -125,11 +126,13 @@ protected:
|
|||
BlendFunc _blendFunc;
|
||||
|
||||
// quads to draw
|
||||
int _quadsToDraw;
|
||||
ssize_t _quadsToDraw;
|
||||
// color uniform
|
||||
GLint _uniformColor;
|
||||
// This varible is only used for LabelAtlas FPS display. So plz don't modify its value.
|
||||
bool _ignoreContentScaleFactor;
|
||||
// quad command
|
||||
QuadCommand _quadCommand;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(AtlasNode);
|
||||
|
|
|
@ -200,36 +200,63 @@ void ClippingNode::drawFullScreenQuadClearStencil()
|
|||
|
||||
void ClippingNode::visit()
|
||||
{
|
||||
if(!_visible)
|
||||
return;
|
||||
|
||||
kmGLPushMatrix();
|
||||
transform();
|
||||
//Add group command
|
||||
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
renderer->addCommand(groupCommand);
|
||||
_groupCommand.init(0,_vertexZ);
|
||||
renderer->addCommand(&_groupCommand);
|
||||
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
renderer->pushGroup(_groupCommand.getRenderQueueID());
|
||||
|
||||
CustomCommand* beforeVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beforeVisitCmd->init(0,_vertexZ);
|
||||
beforeVisitCmd->func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
|
||||
renderer->addCommand(beforeVisitCmd);
|
||||
_beforeVisitCmd.init(0,_vertexZ);
|
||||
_beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
|
||||
renderer->addCommand(&_beforeVisitCmd);
|
||||
|
||||
_stencil->visit();
|
||||
|
||||
CustomCommand* afterDrawStencilCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterDrawStencilCmd->init(0,_vertexZ);
|
||||
afterDrawStencilCmd->func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
|
||||
renderer->addCommand(afterDrawStencilCmd);
|
||||
_afterDrawStencilCmd.init(0,_vertexZ);
|
||||
_afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
|
||||
renderer->addCommand(&_afterDrawStencilCmd);
|
||||
|
||||
Node::visit();
|
||||
int i = 0;
|
||||
|
||||
if(!_children.empty())
|
||||
{
|
||||
sortAllChildren();
|
||||
// draw children zOrder < 0
|
||||
for( ; i < _children.size(); i++ )
|
||||
{
|
||||
auto node = _children.at(i);
|
||||
|
||||
if ( node && node->getZOrder() < 0 )
|
||||
node->visit();
|
||||
else
|
||||
break;
|
||||
}
|
||||
// self draw
|
||||
this->draw();
|
||||
|
||||
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
|
||||
(*it)->visit();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->draw();
|
||||
}
|
||||
|
||||
CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterVisitCmd->init(0,_vertexZ);
|
||||
afterVisitCmd->func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
|
||||
renderer->addCommand(afterVisitCmd);
|
||||
_afterVisitCmd.init(0,_vertexZ);
|
||||
_afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
|
||||
renderer->addCommand(&_afterVisitCmd);
|
||||
|
||||
renderer->popGroup();
|
||||
|
||||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
Node* ClippingNode::getStencil() const
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include "CCNode.h"
|
||||
#include "CCGL.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -141,6 +143,11 @@ protected:
|
|||
GLclampf _currentAlphaTestRef;
|
||||
|
||||
GLint _mask_layer_le;
|
||||
|
||||
GroupCommand _groupCommand;
|
||||
CustomCommand _beforeVisitCmd;
|
||||
CustomCommand _afterDrawStencilCmd;
|
||||
CustomCommand _afterVisitCmd;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(ClippingNode);
|
||||
|
|
|
@ -72,14 +72,14 @@ Component* Component::create(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
const char* Component::getName() const
|
||||
const std::string& Component::getName() const
|
||||
{
|
||||
return _name.c_str();
|
||||
return _name;
|
||||
}
|
||||
|
||||
void Component::setName(const char *name)
|
||||
void Component::setName(const std::string& name)
|
||||
{
|
||||
_name.assign(name);
|
||||
_name = name;
|
||||
}
|
||||
|
||||
Node* Component::getOwner() const
|
||||
|
|
|
@ -60,8 +60,8 @@ public:
|
|||
virtual void setEnabled(bool b);
|
||||
static Component* create(void);
|
||||
|
||||
const char* getName() const;
|
||||
void setName(const char *name);
|
||||
const std::string& getName() const;
|
||||
void setName(const std::string& name);
|
||||
|
||||
void setOwner(Node *pOwner);
|
||||
Node* getOwner() const;
|
||||
|
|
|
@ -40,12 +40,10 @@ ComponentContainer::~ComponentContainer(void)
|
|||
CC_SAFE_DELETE(_components);
|
||||
}
|
||||
|
||||
Component* ComponentContainer::get(const char *name) const
|
||||
Component* ComponentContainer::get(const std::string& name) const
|
||||
{
|
||||
Component* ret = nullptr;
|
||||
CCASSERT(name != nullptr, "Argument must be non-nil");
|
||||
do {
|
||||
CC_BREAK_IF(nullptr == name);
|
||||
CC_BREAK_IF(nullptr == _components);
|
||||
ret = _components->at(name);
|
||||
|
||||
|
@ -77,10 +75,9 @@ bool ComponentContainer::add(Component *com)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool ComponentContainer::remove(const char *name)
|
||||
bool ComponentContainer::remove(const std::string& name)
|
||||
{
|
||||
bool ret = false;
|
||||
CCASSERT(name != nullptr, "Argument must be non-nil");
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!_components);
|
||||
|
|
|
@ -47,9 +47,9 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual ~ComponentContainer(void);
|
||||
virtual Component* get(const char *name) const;
|
||||
virtual Component* get(const std::string& name) const;
|
||||
virtual bool add(Component *com);
|
||||
virtual bool remove(const char *name);
|
||||
virtual bool remove(const std::string& name);
|
||||
virtual void removeAll();
|
||||
virtual void visit(float delta);
|
||||
public:
|
||||
|
|
|
@ -284,7 +284,7 @@ void Configuration::setValue(const std::string& key, const Value& value)
|
|||
//
|
||||
// load file
|
||||
//
|
||||
void Configuration::loadConfigFile(const char *filename)
|
||||
void Configuration::loadConfigFile(const std::string& filename)
|
||||
{
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(filename);
|
||||
CCASSERT(!dict.empty(), "cannot create dictionary");
|
||||
|
@ -312,14 +312,14 @@ void Configuration::loadConfigFile(const char *filename)
|
|||
|
||||
if (! validMetadata)
|
||||
{
|
||||
CCLOG("Invalid config format for file: %s", filename);
|
||||
CCLOG("Invalid config format for file: %s", filename.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto dataIter = dict.find("data");
|
||||
if (dataIter == dict.end() || dataIter->second.getType() != Value::Type::MAP)
|
||||
{
|
||||
CCLOG("Expected 'data' dict, but not found. Config file: %s", filename);
|
||||
CCLOG("Expected 'data' dict, but not found. Config file: %s", filename.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ public:
|
|||
void gatherGPUInfo();
|
||||
|
||||
/** Loads a config file. If the keys are already present, then they are going to be replaced. Otherwise the new keys are added. */
|
||||
void loadConfigFile(const char *filename);
|
||||
void loadConfigFile(const std::string& filename);
|
||||
|
||||
private:
|
||||
Configuration(void);
|
||||
|
|
|
@ -545,7 +545,8 @@ CC_DEPRECATED_ATTRIBUTE typedef IMEDelegate CCIMEDelegate;
|
|||
CC_DEPRECATED_ATTRIBUTE typedef IMEKeyboardNotificationInfo CCIMEKeyboardNotificationInfo;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef TextFieldDelegate CCTextFieldDelegate;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef TextFieldTTF CCTextFieldTTF;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef NotificationCenter CCNotificationCenter;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __NotificationCenter CCNotificationCenter;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __NotificationCenter NotificationCenter;
|
||||
//CC_DEPRECATED_ATTRIBUTE typedef TargetedTouchDelegate CCTargetedTouchDelegate;
|
||||
//CC_DEPRECATED_ATTRIBUTE typedef StandardTouchDelegate CCStandardTouchDelegate;
|
||||
//CC_DEPRECATED_ATTRIBUTE typedef TouchDelegate CCTouchDelegate;
|
||||
|
@ -1038,7 +1039,7 @@ CC_DEPRECATED_ATTRIBUTE typedef __Integer CCInteger;
|
|||
CC_DEPRECATED_ATTRIBUTE typedef __Bool Bool;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __Bool CCBool;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __String CCString;
|
||||
//CC_DEPRECATED_ATTRIBUTE typedef __String String;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __String String;
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __RGBAProtocol RGBAProtocol;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef __NodeRGBA NodeRGBA;
|
||||
|
|
|
@ -37,7 +37,6 @@ THE SOFTWARE.
|
|||
#include "CCArray.h"
|
||||
#include "CCScheduler.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CCNotificationCenter.h"
|
||||
#include "CCTransition.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "CCSpriteFrameCache.h"
|
||||
|
@ -768,7 +767,6 @@ void Director::purgeDirector()
|
|||
|
||||
// cocos2d-x specific data structures
|
||||
UserDefault::destroyInstance();
|
||||
NotificationCenter::destroyInstance();
|
||||
|
||||
GL::invalidateStateCache();
|
||||
|
||||
|
@ -847,13 +845,10 @@ void Director::resume()
|
|||
|
||||
setAnimationInterval(_oldAnimationInterval);
|
||||
|
||||
if (gettimeofday(_lastUpdate, nullptr) != 0)
|
||||
{
|
||||
CCLOG("cocos2d: Director: Error in gettimeofday");
|
||||
}
|
||||
|
||||
_paused = false;
|
||||
_deltaTime = 0;
|
||||
// fix issue #3509, skip one fps to avoid incorrect time calculation.
|
||||
setNextDeltaTimeZero(true);
|
||||
}
|
||||
|
||||
// display the FPS using a LabelAtlas
|
||||
|
@ -1076,6 +1071,8 @@ void DisplayLinkDirector::startAnimation()
|
|||
}
|
||||
|
||||
_invalid = false;
|
||||
|
||||
Application::getInstance()->setAnimationInterval(_animationInterval);
|
||||
}
|
||||
|
||||
void DisplayLinkDirector::mainLoop()
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
#include "CCDrawNode.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCGL.h"
|
||||
#include "CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCEventListenerCustom.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -124,10 +125,6 @@ DrawNode::~DrawNode()
|
|||
GL::bindVAO(0);
|
||||
_vao = 0;
|
||||
}
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
#endif
|
||||
}
|
||||
|
||||
DrawNode* DrawNode::create()
|
||||
|
@ -196,10 +193,12 @@ bool DrawNode::init()
|
|||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// Need to listen the event only when not use batchnode, because it will use VBO
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(DrawNode::listenBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
nullptr);
|
||||
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
|
||||
/** listen the event that coming to foreground on Android */
|
||||
this->init();
|
||||
});
|
||||
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
@ -241,10 +240,9 @@ void DrawNode::render()
|
|||
|
||||
void DrawNode::draw()
|
||||
{
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(DrawNode::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
_customCommand.init(0, _vertexZ);
|
||||
_customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
}
|
||||
|
||||
void DrawNode::onDraw()
|
||||
|
@ -473,11 +471,4 @@ void DrawNode::setBlendFunc(const BlendFunc &blendFunc)
|
|||
_blendFunc = blendFunc;
|
||||
}
|
||||
|
||||
/** listen the event that coming to foreground on Android
|
||||
*/
|
||||
void DrawNode::listenBackToForeground(Object *obj)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "CCNode.h"
|
||||
#include "ccTypes.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -77,12 +78,6 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
void setBlendFunc(const BlendFunc &blendFunc);
|
||||
|
||||
/** listen the event that coming to foreground on Android
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void listenBackToForeground(Object *obj);
|
||||
|
||||
void onDraw();
|
||||
|
||||
|
@ -105,6 +100,7 @@ protected:
|
|||
V2F_C4B_T2F *_buffer;
|
||||
|
||||
BlendFunc _blendFunc;
|
||||
CustomCommand _customCommand;
|
||||
|
||||
bool _dirty;
|
||||
|
||||
|
|
|
@ -475,7 +475,7 @@ void drawCardinalSpline( PointArray *config, float tension, unsigned int segmen
|
|||
|
||||
Vertex2F* vertices = new Vertex2F[segments + 1];
|
||||
|
||||
unsigned int p;
|
||||
ssize_t p;
|
||||
float lt;
|
||||
float deltaT = 1.0f / config->count();
|
||||
|
||||
|
|
|
@ -97,10 +97,10 @@ static EventListener::ListenerID __getListenerID(Event* event)
|
|||
return ret;
|
||||
}
|
||||
|
||||
EventDispatcher::EventListenerVector::EventListenerVector()
|
||||
: _sceneGraphListeners(nullptr)
|
||||
, _fixedListeners(nullptr)
|
||||
, _gt0Index(0)
|
||||
EventDispatcher::EventListenerVector::EventListenerVector() :
|
||||
_fixedListeners(nullptr),
|
||||
_sceneGraphListeners(nullptr),
|
||||
_gt0Index(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -501,11 +501,12 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
|
|||
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
|
||||
auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners();
|
||||
|
||||
int i = 0;
|
||||
ssize_t i = 0;
|
||||
// priority < 0
|
||||
if (fixedPriorityListeners)
|
||||
{
|
||||
for (; !fixedPriorityListeners->empty() && i < listeners->getGt0Index(); ++i)
|
||||
bool isEmpty = fixedPriorityListeners->empty();
|
||||
for (; !isEmpty && i < listeners->getGt0Index(); ++i)
|
||||
{
|
||||
auto l = fixedPriorityListeners->at(i);
|
||||
if (!l->isPaused() && l->isRegistered() && onEvent(l))
|
||||
|
@ -537,7 +538,8 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
|
|||
if (!shouldStopPropagation)
|
||||
{
|
||||
// priority > 0
|
||||
for (; i < fixedPriorityListeners->size(); ++i)
|
||||
ssize_t size = fixedPriorityListeners->size();
|
||||
for (; i < size; ++i)
|
||||
{
|
||||
auto l = fixedPriorityListeners->at(i);
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ EventListenerMouse* EventListenerMouse::clone()
|
|||
}
|
||||
|
||||
EventListenerMouse::EventListenerMouse()
|
||||
: onMouseUp(nullptr)
|
||||
, onMouseDown(nullptr)
|
||||
: onMouseDown(nullptr)
|
||||
, onMouseUp(nullptr)
|
||||
, onMouseMove(nullptr)
|
||||
, onMouseScroll(nullptr)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// The application will come to foreground.
|
||||
// This message is used for reloading resources before come to foreground on Android.
|
||||
// This message is posted in main.cpp.
|
||||
#define EVNET_COME_TO_FOREGROUND "event_come_to_foreground"
|
||||
#define EVENT_COME_TO_FOREGROUND "event_come_to_foreground"
|
||||
|
||||
// The application will come to background.
|
||||
// This message is used for doing something before coming to background, such as save RenderTexture.
|
||||
|
|
|
@ -30,7 +30,7 @@ NS_CC_BEGIN
|
|||
|
||||
std::unordered_map<std::string, FontAtlas *> FontAtlasCache::_atlasMap;
|
||||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
FontAtlas * FontAtlasCache::getFontAtlasTTF(const std::string& fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
{
|
||||
std::string atlasName = generateFontName(fontFileName, size, glyphs, useDistanceField);
|
||||
FontAtlas *tempAtlas = _atlasMap[atlasName];
|
||||
|
@ -49,7 +49,7 @@ FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size,
|
|||
return tempAtlas;
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasFNT(const char *fontFileName)
|
||||
FontAtlas * FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName)
|
||||
{
|
||||
std::string atlasName = generateFontName(fontFileName, 0, GlyphCollection::CUSTOM,false);
|
||||
FontAtlas *tempAtlas = _atlasMap[atlasName];
|
||||
|
@ -68,7 +68,7 @@ FontAtlas * FontAtlasCache::getFontAtlasFNT(const char *fontFileName)
|
|||
return tempAtlas;
|
||||
}
|
||||
|
||||
std::string FontAtlasCache::generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField)
|
||||
std::string FontAtlasCache::generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField)
|
||||
{
|
||||
std::string tempName(fontFileName);
|
||||
|
||||
|
|
|
@ -38,14 +38,14 @@ class CC_DLL FontAtlasCache
|
|||
|
||||
public:
|
||||
|
||||
static FontAtlas * getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static FontAtlas * getFontAtlasFNT(const char *fontFileName);
|
||||
static FontAtlas * getFontAtlasTTF(const std::string& fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static FontAtlas * getFontAtlasFNT(const std::string& fontFileName);
|
||||
|
||||
static bool releaseFontAtlas(FontAtlas *atlas);
|
||||
|
||||
private:
|
||||
|
||||
static std::string generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField);
|
||||
static std::string generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField);
|
||||
static std::unordered_map<std::string, FontAtlas *> _atlasMap;
|
||||
};
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromTTF(const std::string& fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
{
|
||||
|
||||
Font *font = Font::createWithTTF(fntFilePath, fontSize, glyphs, customGlyphs);
|
||||
|
@ -45,7 +45,7 @@ FontAtlas * FontAtlasFactory::createAtlasFromTTF(const char* fntFilePath, int fo
|
|||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromFNT(const char* fntFilePath)
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromFNT(const std::string& fntFilePath)
|
||||
{
|
||||
Font *font = Font::createWithFNT(fntFilePath);
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ class CC_DLL FontAtlasFactory
|
|||
|
||||
public:
|
||||
|
||||
static FontAtlas * createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static FontAtlas * createAtlasFromFNT(const char* fntFilePath);
|
||||
static FontAtlas * createAtlasFromTTF(const std::string& fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static FontAtlas * createAtlasFromFNT(const std::string& fntFilePath);
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -90,7 +90,6 @@ FT_Library FontFreeType::getFTLibrary()
|
|||
FontFreeType::FontFreeType(bool dynamicGlyphCollection)
|
||||
: _fontRef(nullptr),
|
||||
_letterPadding(5),
|
||||
_ttfData(nullptr),
|
||||
_dynamicGlyphCollection(dynamicGlyphCollection)
|
||||
{
|
||||
if(_distanceFieldEnabled)
|
||||
|
@ -101,13 +100,13 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
|||
{
|
||||
FT_Face face;
|
||||
|
||||
ssize_t len = 0;
|
||||
_ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len);
|
||||
if (!_ttfData)
|
||||
_ttfData = FileUtils::getInstance()->getDataFromFile(fontName);
|
||||
|
||||
if (_ttfData.isNull())
|
||||
return false;
|
||||
|
||||
// create the face from the data
|
||||
if (FT_New_Memory_Face(getFTLibrary(), _ttfData, len, 0, &face ))
|
||||
if (FT_New_Memory_Face(getFTLibrary(), _ttfData.getBytes(), _ttfData.getSize(), 0, &face ))
|
||||
return false;
|
||||
|
||||
//we want to use unicode
|
||||
|
@ -136,11 +135,6 @@ FontFreeType::~FontFreeType()
|
|||
{
|
||||
FT_Done_Face(_fontRef);
|
||||
}
|
||||
if (_ttfData)
|
||||
{
|
||||
free(_ttfData);
|
||||
_ttfData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontFreeType::createFontAtlas()
|
||||
|
|
|
@ -25,11 +25,12 @@
|
|||
#ifndef _FontFreetype_h_
|
||||
#define _FontFreetype_h_
|
||||
|
||||
#include "CCFont.h"
|
||||
#include "CCData.h"
|
||||
|
||||
#include <string>
|
||||
#include <ft2build.h>
|
||||
|
||||
#include "CCFont.h"
|
||||
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -73,7 +74,7 @@ private:
|
|||
FT_Face _fontRef;
|
||||
int _letterPadding;
|
||||
std::string _fontName;
|
||||
unsigned char* _ttfData;
|
||||
Data _ttfData;
|
||||
bool _dynamicGlyphCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -154,18 +154,18 @@ bool GLProgram::initWithVertexShaderByteArray(const GLchar* vShaderByteArray, co
|
|||
|
||||
bool GLProgram::initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename)
|
||||
{
|
||||
const GLchar * vertexSource = (GLchar*) String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(vShaderFilename).c_str())->getCString();
|
||||
const GLchar * fragmentSource = (GLchar*) String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(fShaderFilename).c_str())->getCString();
|
||||
std::string vertexSource = FileUtils::getInstance()->getStringFromFile(FileUtils::getInstance()->fullPathForFilename(vShaderFilename).c_str());
|
||||
std::string fragmentSource = FileUtils::getInstance()->getStringFromFile(FileUtils::getInstance()->fullPathForFilename(fShaderFilename).c_str());
|
||||
|
||||
return initWithVertexShaderByteArray(vertexSource, fragmentSource);
|
||||
return initWithVertexShaderByteArray(vertexSource.c_str(), fragmentSource.c_str());
|
||||
}
|
||||
|
||||
std::string GLProgram::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<GLProgram = "
|
||||
return StringUtils::format("<GLProgram = "
|
||||
CC_FORMAT_PRINTF_SIZE_T
|
||||
" | Program = %i, VertexShader = %i, FragmentShader = %i>",
|
||||
(size_t)this, _program, _vertShader, _fragShader)->getCString();
|
||||
(size_t)this, _program, _vertShader, _fragShader);
|
||||
}
|
||||
|
||||
bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source)
|
||||
|
|
|
@ -25,9 +25,11 @@ THE SOFTWARE.
|
|||
#ifndef __CC_IME_DELEGATE_H__
|
||||
#define __CC_IME_DELEGATE_H__
|
||||
|
||||
#include <string>
|
||||
#include "CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
extern const std::string STD_STRING_EMPTY;
|
||||
|
||||
/**
|
||||
* @addtogroup input
|
||||
|
@ -114,7 +116,7 @@ protected:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual const char * getContentText() { return 0; }
|
||||
virtual const std::string& getContentText() { return STD_STRING_EMPTY; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// keyboard show/hide notification
|
||||
|
|
|
@ -239,14 +239,13 @@ void IMEDispatcher::dispatchDeleteBackward()
|
|||
} while (0);
|
||||
}
|
||||
|
||||
const char * IMEDispatcher::getContentText()
|
||||
const std::string& IMEDispatcher::getContentText()
|
||||
{
|
||||
const char * contentText = 0;
|
||||
if (_impl && _impl->_delegateWithIme)
|
||||
{
|
||||
contentText = _impl->_delegateWithIme->getContentText();
|
||||
return _impl->_delegateWithIme->getContentText();
|
||||
}
|
||||
return (contentText) ? contentText : "";
|
||||
return STD_STRING_EMPTY;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
const char * getContentText();
|
||||
const std::string& getContentText();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// dispatch keyboard notification
|
||||
|
|
|
@ -102,16 +102,20 @@ Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int li
|
|||
|
||||
Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,bool useA8Shader)
|
||||
: _reusedLetter(nullptr)
|
||||
, _multilineEnable(true)
|
||||
, _commonLineHeight(0.0f)
|
||||
, _lineBreakWithoutSpaces(false)
|
||||
,_multilineEnable(true)
|
||||
, _width(0.0f)
|
||||
, _alignment(alignment)
|
||||
, _currentUTF16String(0)
|
||||
, _originalUTF16String(0)
|
||||
, _advances(0)
|
||||
, _advances(nullptr)
|
||||
, _fontAtlas(atlas)
|
||||
, _isOpacityModifyRGB(true)
|
||||
,_useDistanceField(useDistanceField)
|
||||
,_useA8Shader(useA8Shader)
|
||||
, _useDistanceField(useDistanceField)
|
||||
, _useA8Shader(useA8Shader)
|
||||
, _fontSize(0)
|
||||
, _uniformEffectColor(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ bool LabelAtlas::initWithString(const std::string& theString, const std::string&
|
|||
//CCLabelAtlas - Atlas generation
|
||||
void LabelAtlas::updateAtlasValues()
|
||||
{
|
||||
auto n = _string.length();
|
||||
ssize_t n = _string.length();
|
||||
|
||||
const unsigned char *s = (unsigned char*)_string.c_str();
|
||||
|
||||
|
@ -130,7 +130,7 @@ void LabelAtlas::updateAtlasValues()
|
|||
|
||||
CCASSERT(n <= _textureAtlas->getCapacity(), "updateAtlasValues: Invalid String length");
|
||||
V3F_C4B_T2F_Quad* quads = _textureAtlas->getQuads();
|
||||
for(int i = 0; i < n; i++) {
|
||||
for(ssize_t i = 0; i < n; i++) {
|
||||
|
||||
unsigned char a = s[i] - _mapStartChar;
|
||||
float row = (float) (a % _itemsPerRow);
|
||||
|
@ -178,7 +178,7 @@ void LabelAtlas::updateAtlasValues()
|
|||
}
|
||||
if (n > 0 ){
|
||||
_textureAtlas->setDirty(true);
|
||||
auto totalQuads = _textureAtlas->getTotalQuads();
|
||||
ssize_t totalQuads = _textureAtlas->getTotalQuads();
|
||||
if (n > totalQuads) {
|
||||
_textureAtlas->increaseTotalQuadsWith(static_cast<int>(n - totalQuads));
|
||||
}
|
||||
|
@ -188,10 +188,10 @@ void LabelAtlas::updateAtlasValues()
|
|||
//CCLabelAtlas - LabelProtocol
|
||||
void LabelAtlas::setString(const std::string &label)
|
||||
{
|
||||
auto len = label.size();
|
||||
ssize_t len = label.size();
|
||||
if (len > _textureAtlas->getTotalQuads())
|
||||
{
|
||||
_textureAtlas->resizeCapacity(static_cast<int>(len));
|
||||
_textureAtlas->resizeCapacity(len);
|
||||
}
|
||||
_string.clear();
|
||||
_string = label;
|
||||
|
@ -201,7 +201,7 @@ void LabelAtlas::setString(const std::string &label)
|
|||
|
||||
this->setContentSize(s);
|
||||
|
||||
_quadsToDraw = static_cast<int>(len);
|
||||
_quadsToDraw = len;
|
||||
}
|
||||
|
||||
const std::string& LabelAtlas::getString(void) const
|
||||
|
|
|
@ -183,14 +183,20 @@ void CCBMFontConfiguration::purgeFontDefDictionary()
|
|||
std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const std::string& controlFile)
|
||||
{
|
||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(controlFile);
|
||||
|
||||
String *contents = String::createWithContentsOfFile(fullpath.c_str());
|
||||
|
||||
CCASSERT(contents, "CCBMFontConfiguration::parseConfigFile | Open file error.");
|
||||
|
||||
set<unsigned int> *validCharsString = new set<unsigned int>();
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(fullpath);
|
||||
CCASSERT((!data.isNull() && data.getSize() > 0), "CCBMFontConfiguration::parseConfigFile | Open file error.");
|
||||
|
||||
if (!contents)
|
||||
if (memcmp("BMF", data.getBytes(), 3) == 0) {
|
||||
std::set<unsigned int>* ret = parseBinaryConfigFile(data.getBytes(), data.getSize(), controlFile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string contents((const char*)data.getBytes(), data.getSize());
|
||||
|
||||
std::set<unsigned int> *validCharsString = new std::set<unsigned int>();
|
||||
|
||||
if (contents.empty())
|
||||
{
|
||||
CCLOG("cocos2d: Error parsing FNTfile %s", controlFile.c_str());
|
||||
return nullptr;
|
||||
|
@ -198,7 +204,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const std::string
|
|||
|
||||
// parse spacing / padding
|
||||
std::string line;
|
||||
std::string strLeft = contents->getCString();
|
||||
std::string strLeft(contents);
|
||||
while (strLeft.length() > 0)
|
||||
{
|
||||
size_t pos = strLeft.find('\n');
|
||||
|
@ -260,6 +266,167 @@ std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const std::string
|
|||
return validCharsString;
|
||||
}
|
||||
|
||||
std::set<unsigned int>* CCBMFontConfiguration::parseBinaryConfigFile(unsigned char* pData, unsigned long size, const std::string& controlFile)
|
||||
{
|
||||
/* based on http://www.angelcode.com/products/bmfont/doc/file_format.html file format */
|
||||
|
||||
set<unsigned int> *validCharsString = new set<unsigned int>();
|
||||
|
||||
unsigned long remains = size;
|
||||
|
||||
unsigned char version = pData[3];
|
||||
CCASSERT(version == 3, "Only version 3 is supported");
|
||||
|
||||
pData += 4; remains -= 4;
|
||||
|
||||
while (remains > 0)
|
||||
{
|
||||
unsigned char blockId = pData[0]; pData += 1; remains -= 1;
|
||||
uint32_t blockSize = 0; memcpy(&blockSize, pData, 4);
|
||||
|
||||
pData += 4; remains -= 4;
|
||||
|
||||
if (blockId == 1)
|
||||
{
|
||||
/*
|
||||
fontSize 2 int 0
|
||||
bitField 1 bits 2 bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeigth, bits 5-7: reserved
|
||||
charSet 1 uint 3
|
||||
stretchH 2 uint 4
|
||||
aa 1 uint 6
|
||||
paddingUp 1 uint 7
|
||||
paddingRight 1 uint 8
|
||||
paddingDown 1 uint 9
|
||||
paddingLeft 1 uint 10
|
||||
spacingHoriz 1 uint 11
|
||||
spacingVert 1 uint 12
|
||||
outline 1 uint 13 added with version 2
|
||||
fontName n+1 string 14 null terminated string with length n
|
||||
*/
|
||||
|
||||
_padding.top = (unsigned char)pData[7];
|
||||
_padding.right = (unsigned char)pData[8];
|
||||
_padding.bottom = (unsigned char)pData[9];
|
||||
_padding.left = (unsigned char)pData[10];
|
||||
}
|
||||
else if (blockId == 2)
|
||||
{
|
||||
/*
|
||||
lineHeight 2 uint 0
|
||||
base 2 uint 2
|
||||
scaleW 2 uint 4
|
||||
scaleH 2 uint 6
|
||||
pages 2 uint 8
|
||||
bitField 1 bits 10 bits 0-6: reserved, bit 7: packed
|
||||
alphaChnl 1 uint 11
|
||||
redChnl 1 uint 12
|
||||
greenChnl 1 uint 13
|
||||
blueChnl 1 uint 14
|
||||
*/
|
||||
|
||||
uint16_t lineHeight = 0; memcpy(&lineHeight, pData, 2);
|
||||
_commonHeight = lineHeight;
|
||||
|
||||
uint16_t scaleW = 0; memcpy(&scaleW, pData + 4, 2);
|
||||
uint16_t scaleH = 0; memcpy(&scaleH, pData + 6, 2);
|
||||
|
||||
CCASSERT(scaleW <= Configuration::getInstance()->getMaxTextureSize() && scaleH <= Configuration::getInstance()->getMaxTextureSize(), "CCLabelBMFont: page can't be larger than supported");
|
||||
|
||||
uint16_t pages = 0; memcpy(&pages, pData + 8, 2);
|
||||
CCASSERT(pages == 1, "CCBitfontAtlas: only supports 1 page");
|
||||
}
|
||||
else if (blockId == 3)
|
||||
{
|
||||
/*
|
||||
pageNames p*(n+1) strings 0 p null terminated strings, each with length n
|
||||
*/
|
||||
|
||||
const char *value = (const char *)pData;
|
||||
size_t len = strlen(value);
|
||||
CCASSERT(len < blockSize, "Block size should be less then string");
|
||||
|
||||
_atlasName = FileUtils::getInstance()->fullPathFromRelativeFile(value, controlFile);
|
||||
}
|
||||
else if (blockId == 4)
|
||||
{
|
||||
/*
|
||||
id 4 uint 0+c*20 These fields are repeated until all characters have been described
|
||||
x 2 uint 4+c*20
|
||||
y 2 uint 6+c*20
|
||||
width 2 uint 8+c*20
|
||||
height 2 uint 10+c*20
|
||||
xoffset 2 int 12+c*20
|
||||
yoffset 2 int 14+c*20
|
||||
xadvance 2 int 16+c*20
|
||||
page 1 uint 18+c*20
|
||||
chnl 1 uint 19+c*20
|
||||
*/
|
||||
|
||||
unsigned long count = blockSize / 20;
|
||||
|
||||
for (unsigned long i = 0; i < count; i++)
|
||||
{
|
||||
tFontDefHashElement* element = (tFontDefHashElement*)malloc( sizeof(*element) );
|
||||
|
||||
uint32_t charId = 0; memcpy(&charId, pData + (i * 20), 4);
|
||||
element->fontDef.charID = charId;
|
||||
|
||||
uint16_t charX = 0; memcpy(&charX, pData + (i * 20) + 4, 2);
|
||||
element->fontDef.rect.origin.x = charX;
|
||||
|
||||
uint16_t charY = 0; memcpy(&charY, pData + (i * 20) + 6, 2);
|
||||
element->fontDef.rect.origin.y = charY;
|
||||
|
||||
uint16_t charWidth = 0; memcpy(&charWidth, pData + (i * 20) + 8, 2);
|
||||
element->fontDef.rect.size.width = charWidth;
|
||||
|
||||
uint16_t charHeight = 0; memcpy(&charHeight, pData + (i * 20) + 10, 2);
|
||||
element->fontDef.rect.size.height = charHeight;
|
||||
|
||||
int16_t xoffset = 0; memcpy(&xoffset, pData + (i * 20) + 12, 2);
|
||||
element->fontDef.xOffset = xoffset;
|
||||
|
||||
int16_t yoffset = 0; memcpy(&yoffset, pData + (i * 20) + 14, 2);
|
||||
element->fontDef.yOffset = yoffset;
|
||||
|
||||
int16_t xadvance = 0; memcpy(&xadvance, pData + (i * 20) + 16, 2);
|
||||
element->fontDef.xAdvance = xadvance;
|
||||
|
||||
element->key = element->fontDef.charID;
|
||||
HASH_ADD_INT(_fontDefDictionary, key, element);
|
||||
|
||||
validCharsString->insert(element->fontDef.charID);
|
||||
}
|
||||
}
|
||||
else if (blockId == 5) {
|
||||
/*
|
||||
first 4 uint 0+c*10 These fields are repeated until all kerning pairs have been described
|
||||
second 4 uint 4+c*10
|
||||
amount 2 int 8+c*10
|
||||
*/
|
||||
|
||||
unsigned long count = blockSize / 20;
|
||||
|
||||
for (unsigned long i = 0; i < count; i++)
|
||||
{
|
||||
|
||||
uint32_t first = 0; memcpy(&first, pData + (i * 10), 4);
|
||||
uint32_t second = 0; memcpy(&second, pData + (i * 10) + 4, 4);
|
||||
int16_t amount = 0; memcpy(&amount, pData + (i * 10) + 8, 2);
|
||||
|
||||
tKerningHashElement *element = (tKerningHashElement *)calloc( sizeof( *element ), 1 );
|
||||
element->amount = amount;
|
||||
element->key = (first<<16) | (second&0xffff);
|
||||
HASH_ADD_INT(_kerningDictionary,key, element);
|
||||
}
|
||||
}
|
||||
|
||||
pData += blockSize; remains -= blockSize;
|
||||
}
|
||||
|
||||
return validCharsString;
|
||||
}
|
||||
|
||||
void CCBMFontConfiguration::parseImageFileName(std::string line, const std::string& fntFile)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -817,9 +984,6 @@ void LabelBMFont::updateLabel()
|
|||
}
|
||||
|
||||
skip += justSkipped;
|
||||
|
||||
if (!characterSprite->isVisible())
|
||||
continue;
|
||||
|
||||
if (i >= stringLength)
|
||||
break;
|
||||
|
@ -950,7 +1114,7 @@ void LabelBMFont::updateLabel()
|
|||
size_t size = multiline_string.size();
|
||||
unsigned short* str_new = new unsigned short[size + 1];
|
||||
|
||||
for (int j = 0; j < size; ++j)
|
||||
for (size_t j = 0; j < size; ++j)
|
||||
{
|
||||
str_new[j] = multiline_string[j];
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ public:
|
|||
std::set<unsigned int>* getCharacterSet() const;
|
||||
private:
|
||||
std::set<unsigned int>* parseConfigFile(const std::string& controlFile);
|
||||
std::set<unsigned int>* parseBinaryConfigFile(unsigned char* pData, unsigned long size, const std::string& controlFile);
|
||||
void parseCharacterDefinition(std::string line, ccBMFontDef *characterDefinition);
|
||||
void parseInfoArguments(std::string line);
|
||||
void parseCommonArguments(std::string line);
|
||||
|
|
|
@ -200,7 +200,7 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
|
|||
size_t size = multiline_string.size();
|
||||
unsigned short* strNew = new unsigned short[size + 1];
|
||||
|
||||
for (int j = 0; j < size; ++j)
|
||||
for (size_t j = 0; j < size; ++j)
|
||||
{
|
||||
strNew[j] = multiline_string[j];
|
||||
}
|
||||
|
@ -240,10 +240,10 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
|||
continue;
|
||||
}
|
||||
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
||||
if(currentChar == 0)
|
||||
index -= 1;
|
||||
if (index < 0) continue;
|
||||
|
||||
if(currentChar == 0)
|
||||
continue;
|
||||
LetterInfo* info = &leterInfo->at( index );
|
||||
if(info->def.validDefinition == false)
|
||||
continue;
|
||||
|
|
|
@ -53,11 +53,11 @@ Layer::Layer()
|
|||
: _touchEnabled(false)
|
||||
, _accelerometerEnabled(false)
|
||||
, _keyboardEnabled(false)
|
||||
, _touchMode(Touch::DispatchMode::ALL_AT_ONCE)
|
||||
, _swallowsTouches(true)
|
||||
, _touchListener(nullptr)
|
||||
, _keyboardListener(nullptr)
|
||||
, _accelerationListener(nullptr)
|
||||
, _touchMode(Touch::DispatchMode::ALL_AT_ONCE)
|
||||
, _swallowsTouches(true)
|
||||
{
|
||||
_ignoreAnchorPointForPosition = true;
|
||||
setAnchorPoint(Point(0.5f, 0.5f));
|
||||
|
@ -564,10 +564,9 @@ void LayerColor::updateColor()
|
|||
|
||||
void LayerColor::draw()
|
||||
{
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
_customCommand.init(0, _vertexZ);
|
||||
_customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
}
|
||||
|
||||
void LayerColor::onDraw()
|
||||
|
|
|
@ -35,6 +35,7 @@ THE SOFTWARE.
|
|||
#endif // EMSCRIPTEN
|
||||
|
||||
#include "CCEventKeyboard.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -296,6 +297,7 @@ protected:
|
|||
BlendFunc _blendFunc;
|
||||
Vertex2F _squareVertices[4];
|
||||
Color4F _squareColors[4];
|
||||
CustomCommand _customCommand;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(LayerColor);
|
||||
|
|
|
@ -346,7 +346,7 @@ void Menu::alignItemsInColumns(int columns, va_list args)
|
|||
void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
|
||||
{
|
||||
int height = -5;
|
||||
int row = 0;
|
||||
size_t row = 0;
|
||||
int rowHeight = 0;
|
||||
int columnsOccupied = 0;
|
||||
int rowColumns = 0;
|
||||
|
@ -441,7 +441,7 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
|
|||
|
||||
int width = -10;
|
||||
int columnHeight = -5;
|
||||
int column = 0;
|
||||
size_t column = 0;
|
||||
int columnWidth = 0;
|
||||
int rowsOccupied = 0;
|
||||
int columnRows;
|
||||
|
|
|
@ -320,7 +320,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& 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);
|
||||
|
@ -337,7 +337,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemAtlasFont::initWithString(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
@ -387,7 +387,7 @@ const std::string& MenuItemFont::getFontName()
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemFont * MenuItemFont::create(const char *value, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemFont * MenuItemFont::create(const std::string& value, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemFont *ret = new MenuItemFont();
|
||||
ret->initWithString(value, target, selector);
|
||||
|
@ -422,9 +422,9 @@ MenuItemFont::~MenuItemFont()
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemFont::initWithString(const char *value, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemFont::initWithString(const std::string& value, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
CCASSERT( value != nullptr && strlen(value) != 0, "Value length must be greater than 0");
|
||||
CCASSERT( !value.empty(), "Value length must be greater than 0");
|
||||
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(target);
|
||||
|
@ -433,7 +433,7 @@ bool MenuItemFont::initWithString(const char *value, Object* target, SEL_MenuHan
|
|||
|
||||
bool MenuItemFont::initWithString(const std::string& value, const ccMenuCallback& callback)
|
||||
{
|
||||
CCASSERT( value.size() >= 0, "Value length must be greater than 0");
|
||||
CCASSERT( !value.empty(), "Value length must be greater than 0");
|
||||
|
||||
_fontName = _globalFontName;
|
||||
_fontSize = _globalFontSize;
|
||||
|
@ -710,7 +710,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std:
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
return MenuItemImage::create(normalImage, selectedImage, "", target, selector);
|
||||
}
|
||||
|
@ -721,7 +721,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std:
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemImage *ret = new MenuItemImage();
|
||||
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
|
||||
|
@ -758,7 +758,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std:
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemImage::initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
|
|
@ -217,7 +217,7 @@ 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, 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, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const std::string& value, const std::string& 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, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -233,7 +233,7 @@ 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, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, const std::string& 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, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -251,7 +251,7 @@ public:
|
|||
/** creates a menu item from a string without target/selector. To be used with MenuItemToggle */
|
||||
static MenuItemFont * create(const std::string& value = "");
|
||||
/** creates a menu item from a string with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const char *value, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const std::string& value, Object* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item from a string with a target/selector */
|
||||
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -306,7 +306,7 @@ protected:
|
|||
virtual ~MenuItemFont();
|
||||
|
||||
/** initializes a menu item from a string with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, Object* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item from a string with a target/selector */
|
||||
bool initWithString(const std::string& value, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -411,12 +411,12 @@ public:
|
|||
/** creates a menu item with a normal,selected and disabled image*/
|
||||
static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage);
|
||||
/** creates a menu item with a normal and selected image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const char *normalImage, const char *selectedImage, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, Object* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal and selected image with a callable object */
|
||||
static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const ccMenuCallback& callback);
|
||||
|
||||
/** creates a menu item with a normal,selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal,selected and disabled image with a callable object */
|
||||
static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const std::string&disabledImage, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -440,7 +440,7 @@ protected:
|
|||
|
||||
bool init();
|
||||
/** initializes a menu item with a normal, selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item with a normal, selected and disabled image with a callable object */
|
||||
bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback);
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ MotionStreak::~MotionStreak()
|
|||
CC_SAFE_FREE(_texCoords);
|
||||
}
|
||||
|
||||
MotionStreak* MotionStreak::create(float fade, float minSeg, float stroke, const Color3B& color, const char* path)
|
||||
MotionStreak* MotionStreak::create(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path)
|
||||
{
|
||||
MotionStreak *ret = new MotionStreak();
|
||||
if (ret && ret->initWithFade(fade, minSeg, stroke, color, path))
|
||||
|
@ -91,9 +91,9 @@ MotionStreak* MotionStreak::create(float fade, float minSeg, float stroke, const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const char* path)
|
||||
bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path)
|
||||
{
|
||||
CCASSERT(path != nullptr, "Invalid filename");
|
||||
CCASSERT(!path.empty(), "Invalid filename");
|
||||
|
||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(path);
|
||||
return initWithFade(fade, minSeg, stroke, color, texture);
|
||||
|
@ -358,10 +358,9 @@ void MotionStreak::draw()
|
|||
if(_nuPoints <= 1)
|
||||
return;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV);
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,_vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(MotionStreak::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
_customCommand.init(0,_vertexZ);
|
||||
_customCommand.func = CC_CALLBACK_0(MotionStreak::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ THE SOFTWARE.
|
|||
#include "CCTexture2D.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCNode.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#ifdef EMSCRIPTEN
|
||||
#include "CCGLBufferedNode.h"
|
||||
#endif // EMSCRIPTEN
|
||||
|
@ -50,7 +51,7 @@ class CC_DLL MotionStreak : public Node, public TextureProtocol
|
|||
{
|
||||
public:
|
||||
/** creates and initializes a motion streak with fade in seconds, minimum segments, stroke's width, color, texture filename */
|
||||
static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, const char* path);
|
||||
static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path);
|
||||
/** creates and initializes a motion streak with fade in seconds, minimum segments, stroke's width, color, texture */
|
||||
static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, Texture2D* texture);
|
||||
|
||||
|
@ -116,7 +117,7 @@ protected:
|
|||
virtual ~MotionStreak();
|
||||
|
||||
/** initializes a motion streak with fade in seconds, minimum segments, stroke's width, color and texture filename */
|
||||
bool initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const char* path);
|
||||
bool initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path);
|
||||
/** initializes a motion streak with fade in seconds, minimum segments, stroke's width, color and texture */
|
||||
bool initWithFade(float fade, float minSeg, float stroke, const Color3B& color, Texture2D* texture);
|
||||
|
||||
|
@ -144,6 +145,8 @@ protected:
|
|||
Vertex2F* _vertices;
|
||||
GLubyte* _colorPointer;
|
||||
Tex2F* _texCoords;
|
||||
|
||||
CustomCommand _customCommand;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(MotionStreak);
|
||||
|
|
|
@ -44,7 +44,7 @@ THE SOFTWARE.
|
|||
#include "CCEventTouch.h"
|
||||
#include "CCScene.h"
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
#include "CCPhysicsBody.h"
|
||||
#endif
|
||||
|
||||
|
@ -123,7 +123,7 @@ Node::Node(void)
|
|||
, _isTransitionFinished(false)
|
||||
, _updateScriptHandler(0)
|
||||
, _componentContainer(nullptr)
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
, _physicsBody(nullptr)
|
||||
#endif
|
||||
, _displayedOpacity(255)
|
||||
|
@ -178,7 +178,7 @@ Node::~Node()
|
|||
|
||||
CC_SAFE_DELETE(_componentContainer);
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
CC_SAFE_RELEASE(_physicsBody);
|
||||
#endif
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void Node::setRotation(float newRotation)
|
|||
_rotationX = _rotationY = newRotation;
|
||||
_transformDirty = _inverseDirty = true;
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
if (_physicsBody)
|
||||
{
|
||||
_physicsBody->setRotation(newRotation);
|
||||
|
@ -354,7 +354,7 @@ void Node::setPosition(const Point& newPosition)
|
|||
_position = newPosition;
|
||||
_transformDirty = _inverseDirty = true;
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
if (_physicsBody)
|
||||
{
|
||||
_physicsBody->setPosition(newPosition);
|
||||
|
@ -604,7 +604,7 @@ void Node::addChild(Node *child, int zOrder, int tag)
|
|||
|
||||
this->insertChild(child, zOrder);
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
for (Node* node = this->getParent(); node != nullptr; node = node->getParent())
|
||||
{
|
||||
if (dynamic_cast<Scene*>(node) != nullptr)
|
||||
|
@ -739,7 +739,7 @@ void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup)
|
|||
child->onExit();
|
||||
}
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
if (child->_physicsBody != nullptr)
|
||||
{
|
||||
child->_physicsBody->removeFromWorld();
|
||||
|
@ -848,7 +848,7 @@ void Node::transformAncestors()
|
|||
|
||||
void Node::transform()
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
updatePhysicsTransform();
|
||||
#endif
|
||||
|
||||
|
@ -867,13 +867,6 @@ void Node::onEnter()
|
|||
{
|
||||
_isTransitionFinished = false;
|
||||
|
||||
for( const auto &child: _children)
|
||||
child->onEnter();
|
||||
|
||||
this->resume();
|
||||
|
||||
_running = true;
|
||||
|
||||
if (_scriptType != kScriptTypeNone)
|
||||
{
|
||||
int action = kNodeOnEnter;
|
||||
|
@ -881,15 +874,19 @@ void Node::onEnter()
|
|||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
|
||||
for( const auto &child: _children)
|
||||
child->onEnter();
|
||||
|
||||
this->resume();
|
||||
|
||||
_running = true;
|
||||
}
|
||||
|
||||
void Node::onEnterTransitionDidFinish()
|
||||
{
|
||||
_isTransitionFinished = true;
|
||||
|
||||
for( const auto &child: _children)
|
||||
child->onEnterTransitionDidFinish();
|
||||
|
||||
if (_scriptType != kScriptTypeNone)
|
||||
{
|
||||
int action = kNodeOnEnterTransitionDidFinish;
|
||||
|
@ -897,6 +894,9 @@ void Node::onEnterTransitionDidFinish()
|
|||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
|
||||
for( const auto &child: _children)
|
||||
child->onEnterTransitionDidFinish();
|
||||
}
|
||||
|
||||
void Node::onExitTransitionDidStart()
|
||||
|
@ -918,6 +918,10 @@ void Node::onExit()
|
|||
this->pause();
|
||||
|
||||
_running = false;
|
||||
|
||||
for( const auto &child: _children)
|
||||
child->onExit();
|
||||
|
||||
if (_scriptType != kScriptTypeNone)
|
||||
{
|
||||
int action = kNodeOnExit;
|
||||
|
@ -925,9 +929,6 @@ void Node::onExit()
|
|||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
|
||||
for( const auto &child: _children)
|
||||
child->onExit();
|
||||
}
|
||||
|
||||
void Node::setEventDispatcher(EventDispatcher* dispatcher)
|
||||
|
@ -1170,8 +1171,8 @@ const kmMat4& Node::getNodeToParentTransform() const
|
|||
// If skew is needed, apply skew and then anchor point
|
||||
if (needsSkewMatrix)
|
||||
{
|
||||
kmMat4 skewMatrix = { 1, tanf(CC_DEGREES_TO_RADIANS(_skewY)), 0, 0,
|
||||
tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1, 0, 0,
|
||||
kmMat4 skewMatrix = { 1, (float)tanf(CC_DEGREES_TO_RADIANS(_skewY)), 0, 0,
|
||||
(float)tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1};
|
||||
|
||||
|
@ -1324,7 +1325,7 @@ Point Node::convertTouchToNodeSpaceAR(Touch *touch) const
|
|||
return this->convertToNodeSpaceAR(point);
|
||||
}
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
bool Node::updatePhysicsTransform()
|
||||
{
|
||||
if (_physicsBody != nullptr && _physicsBody->getWorld() != nullptr && !_physicsBody->isResting())
|
||||
|
@ -1346,7 +1347,7 @@ void Node::updateTransform()
|
|||
child->updateTransform();
|
||||
}
|
||||
|
||||
Component* Node::getComponent(const char *pName)
|
||||
Component* Node::getComponent(const std::string& pName)
|
||||
{
|
||||
if( _componentContainer )
|
||||
return _componentContainer->get(pName);
|
||||
|
@ -1361,7 +1362,7 @@ bool Node::addComponent(Component *pComponent)
|
|||
return _componentContainer->add(pComponent);
|
||||
}
|
||||
|
||||
bool Node::removeComponent(const char *pName)
|
||||
bool Node::removeComponent(const std::string& pName)
|
||||
{
|
||||
if( _componentContainer )
|
||||
return _componentContainer->remove(pName);
|
||||
|
@ -1374,7 +1375,7 @@ void Node::removeAllComponents()
|
|||
_componentContainer->removeAll();
|
||||
}
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
void Node::setPhysicsBody(PhysicsBody* body)
|
||||
{
|
||||
if (_physicsBody != nullptr)
|
||||
|
|
|
@ -54,7 +54,7 @@ class Component;
|
|||
class ComponentContainer;
|
||||
class EventDispatcher;
|
||||
class Scene;
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
class PhysicsBody;
|
||||
#endif
|
||||
|
||||
|
@ -590,7 +590,7 @@ public:
|
|||
*
|
||||
* @return a Node object whose tag equals to the input parameter
|
||||
*/
|
||||
Node * getChildByTag(int tag);
|
||||
virtual Node * getChildByTag(int tag);
|
||||
/**
|
||||
* Return an array of children
|
||||
*
|
||||
|
@ -615,7 +615,7 @@ public:
|
|||
*
|
||||
* @return The amount of children.
|
||||
*/
|
||||
ssize_t getChildrenCount() const;
|
||||
virtual ssize_t getChildrenCount() const;
|
||||
|
||||
/**
|
||||
* Sets the parent node
|
||||
|
@ -1322,7 +1322,7 @@ public:
|
|||
/**
|
||||
* gets a component by its name
|
||||
*/
|
||||
Component* getComponent(const char *pName);
|
||||
Component* getComponent(const std::string& pName);
|
||||
|
||||
/**
|
||||
* adds a component
|
||||
|
@ -1332,7 +1332,7 @@ public:
|
|||
/**
|
||||
* removes a component by its name
|
||||
*/
|
||||
virtual bool removeComponent(const char *pName);
|
||||
virtual bool removeComponent(const std::string& pName);
|
||||
|
||||
/**
|
||||
* removes all components
|
||||
|
@ -1341,7 +1341,7 @@ public:
|
|||
/// @} end of component functions
|
||||
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
/**
|
||||
* set the PhysicsBody that let the sprite effect with physics
|
||||
*/
|
||||
|
@ -1465,7 +1465,7 @@ protected:
|
|||
|
||||
ComponentContainer *_componentContainer; ///< Dictionary of components
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
PhysicsBody* _physicsBody; ///< the physicsBody the node have
|
||||
#endif
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ NodeGrid* NodeGrid::create()
|
|||
}
|
||||
|
||||
NodeGrid::NodeGrid()
|
||||
: _nodeGrid(nullptr)
|
||||
, _gridTarget(nullptr)
|
||||
: _gridTarget(nullptr)
|
||||
, _nodeGrid(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -92,10 +92,9 @@ void NodeGrid::visit()
|
|||
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
renderer->addCommand(groupCommand);
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
_groupCommand.init(0,_vertexZ);
|
||||
renderer->addCommand(&_groupCommand);
|
||||
renderer->pushGroup(_groupCommand.getRenderQueueID());
|
||||
|
||||
kmGLPushMatrix();
|
||||
Director::Projection beforeProjectionType;
|
||||
|
@ -105,10 +104,9 @@ void NodeGrid::visit()
|
|||
_nodeGrid->set2DProjection();
|
||||
}
|
||||
|
||||
CustomCommand* gridBeginCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
gridBeginCmd->init(0,_vertexZ);
|
||||
gridBeginCmd->func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
|
||||
renderer->addCommand(gridBeginCmd);
|
||||
_gridBeginCommand.init(0,_vertexZ);
|
||||
_gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
|
||||
renderer->addCommand(&_gridBeginCommand);
|
||||
|
||||
this->transform();
|
||||
|
||||
|
@ -154,10 +152,9 @@ void NodeGrid::visit()
|
|||
director->setProjection(beforeProjectionType);
|
||||
}
|
||||
|
||||
CustomCommand* gridEndCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
gridEndCmd->init(0,_vertexZ);
|
||||
gridEndCmd->func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this);
|
||||
renderer->addCommand(gridEndCmd);
|
||||
_gridEndCommand.init(0,_vertexZ);
|
||||
_gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this);
|
||||
renderer->addCommand(&_gridEndCommand);
|
||||
|
||||
renderer->popGroup();
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "CCNode.h"
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -64,6 +66,9 @@ protected:
|
|||
|
||||
Node* _gridTarget;
|
||||
GridBase* _nodeGrid;
|
||||
GroupCommand _groupCommand;
|
||||
CustomCommand _gridBeginCommand;
|
||||
CustomCommand _gridEndCommand;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(NodeGrid);
|
||||
|
|
|
@ -31,50 +31,50 @@ using namespace std;
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static NotificationCenter *s_sharedNotifCenter = nullptr;
|
||||
static __NotificationCenter *s_sharedNotifCenter = nullptr;
|
||||
|
||||
NotificationCenter::NotificationCenter()
|
||||
__NotificationCenter::__NotificationCenter()
|
||||
: _scriptHandler(0)
|
||||
{
|
||||
_observers = __Array::createWithCapacity(3);
|
||||
_observers->retain();
|
||||
}
|
||||
|
||||
NotificationCenter::~NotificationCenter()
|
||||
__NotificationCenter::~__NotificationCenter()
|
||||
{
|
||||
_observers->release();
|
||||
}
|
||||
|
||||
NotificationCenter *NotificationCenter::getInstance()
|
||||
__NotificationCenter *__NotificationCenter::getInstance()
|
||||
{
|
||||
if (!s_sharedNotifCenter)
|
||||
{
|
||||
s_sharedNotifCenter = new NotificationCenter;
|
||||
s_sharedNotifCenter = new __NotificationCenter;
|
||||
}
|
||||
return s_sharedNotifCenter;
|
||||
}
|
||||
|
||||
void NotificationCenter::destroyInstance()
|
||||
void __NotificationCenter::destroyInstance()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(s_sharedNotifCenter);
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
NotificationCenter *NotificationCenter::sharedNotificationCenter(void)
|
||||
__NotificationCenter *__NotificationCenter::sharedNotificationCenter(void)
|
||||
{
|
||||
return NotificationCenter::getInstance();
|
||||
return __NotificationCenter::getInstance();
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
void NotificationCenter::purgeNotificationCenter(void)
|
||||
void __NotificationCenter::purgeNotificationCenter(void)
|
||||
{
|
||||
NotificationCenter::destroyInstance();
|
||||
__NotificationCenter::destroyInstance();
|
||||
}
|
||||
|
||||
//
|
||||
// internal functions
|
||||
//
|
||||
bool NotificationCenter::observerExisted(Object *target,const char *name, Object *sender)
|
||||
bool __NotificationCenter::observerExisted(Object *target, const std::string& name, Object *sender)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
|
@ -83,7 +83,7 @@ bool NotificationCenter::observerExisted(Object *target,const char *name, Object
|
|||
if (!observer)
|
||||
continue;
|
||||
|
||||
if (!strcmp(observer->getName(),name) && observer->getTarget() == target && observer->getSender() == sender)
|
||||
if (observer->getName() == name && observer->getTarget() == target && observer->getSender() == sender)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -92,9 +92,9 @@ bool NotificationCenter::observerExisted(Object *target,const char *name, Object
|
|||
//
|
||||
// observer functions
|
||||
//
|
||||
void NotificationCenter::addObserver(Object *target,
|
||||
void __NotificationCenter::addObserver(Object *target,
|
||||
SEL_CallFuncO selector,
|
||||
const char *name,
|
||||
const std::string& name,
|
||||
Object *sender)
|
||||
{
|
||||
if (this->observerExisted(target, name, sender))
|
||||
|
@ -108,7 +108,7 @@ void NotificationCenter::addObserver(Object *target,
|
|||
_observers->addObject(observer);
|
||||
}
|
||||
|
||||
void NotificationCenter::removeObserver(Object *target,const char *name)
|
||||
void __NotificationCenter::removeObserver(Object *target, const std::string& name)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
|
@ -117,7 +117,7 @@ void NotificationCenter::removeObserver(Object *target,const char *name)
|
|||
if (!observer)
|
||||
continue;
|
||||
|
||||
if (!strcmp(observer->getName(),name) && observer->getTarget() == target)
|
||||
if (observer->getName() == name && observer->getTarget() == target)
|
||||
{
|
||||
_observers->removeObject(observer);
|
||||
return;
|
||||
|
@ -125,7 +125,7 @@ void NotificationCenter::removeObserver(Object *target,const char *name)
|
|||
}
|
||||
}
|
||||
|
||||
int NotificationCenter::removeAllObservers(Object *target)
|
||||
int __NotificationCenter::removeAllObservers(Object *target)
|
||||
{
|
||||
Object *obj = nullptr;
|
||||
__Array *toRemove = __Array::create();
|
||||
|
@ -146,7 +146,7 @@ int NotificationCenter::removeAllObservers(Object *target)
|
|||
return static_cast<int>(toRemove->count());
|
||||
}
|
||||
|
||||
void NotificationCenter::registerScriptObserver( Object *target, int handler,const char* name)
|
||||
void __NotificationCenter::registerScriptObserver( Object *target, int handler,const std::string& name)
|
||||
{
|
||||
|
||||
if (this->observerExisted(target, name, nullptr))
|
||||
|
@ -161,7 +161,7 @@ void NotificationCenter::registerScriptObserver( Object *target, int handler,con
|
|||
_observers->addObject(observer);
|
||||
}
|
||||
|
||||
void NotificationCenter::unregisterScriptObserver(Object *target,const char* name)
|
||||
void __NotificationCenter::unregisterScriptObserver(Object *target,const std::string& name)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
|
@ -170,14 +170,14 @@ void NotificationCenter::unregisterScriptObserver(Object *target,const char* nam
|
|||
if (!observer)
|
||||
continue;
|
||||
|
||||
if ( !strcmp(observer->getName(),name) && observer->getTarget() == target)
|
||||
if ( observer->getName() == name && observer->getTarget() == target)
|
||||
{
|
||||
_observers->removeObject(observer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationCenter::postNotification(const char *name, Object *sender)
|
||||
void __NotificationCenter::postNotification(const std::string& name, Object *sender)
|
||||
{
|
||||
__Array* ObserversCopy = __Array::createWithCapacity(_observers->count());
|
||||
ObserversCopy->addObjectsFromArray(_observers);
|
||||
|
@ -188,15 +188,9 @@ void NotificationCenter::postNotification(const char *name, Object *sender)
|
|||
if (!observer)
|
||||
continue;
|
||||
|
||||
if (!strcmp(name,observer->getName()) && (observer->getSender() == sender || observer->getSender() == nullptr || sender == nullptr))
|
||||
if (observer->getName() == name && (observer->getSender() == sender || observer->getSender() == nullptr || sender == nullptr))
|
||||
{
|
||||
if (0 != observer->getHandler())
|
||||
{
|
||||
BasicScriptData data(this, (void*)name);
|
||||
ScriptEvent scriptEvent(kNotificationEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
else
|
||||
if (0 == observer->getHandler())
|
||||
{
|
||||
observer->performSelector(sender);
|
||||
}
|
||||
|
@ -204,14 +198,14 @@ void NotificationCenter::postNotification(const char *name, Object *sender)
|
|||
}
|
||||
}
|
||||
|
||||
void NotificationCenter::postNotification(const char *name)
|
||||
void __NotificationCenter::postNotification(const std::string& name)
|
||||
{
|
||||
this->postNotification(name,nullptr);
|
||||
}
|
||||
|
||||
int NotificationCenter::getObserverHandlerByName(const char* name)
|
||||
int __NotificationCenter::getObserverHandlerByName(const std::string& name)
|
||||
{
|
||||
if (nullptr == name || strlen(name) == 0)
|
||||
if (name.empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -223,7 +217,7 @@ int NotificationCenter::getObserverHandlerByName(const char* name)
|
|||
if (nullptr == observer)
|
||||
continue;
|
||||
|
||||
if ( 0 == strcmp(observer->getName(),name) )
|
||||
if ( observer->getName() == name )
|
||||
{
|
||||
return observer->getHandler();
|
||||
break;
|
||||
|
@ -240,7 +234,7 @@ int NotificationCenter::getObserverHandlerByName(const char* name)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
NotificationObserver::NotificationObserver(Object *target,
|
||||
SEL_CallFuncO selector,
|
||||
const char *name,
|
||||
const std::string& name,
|
||||
Object *sender)
|
||||
{
|
||||
_target = target;
|
||||
|
@ -278,9 +272,9 @@ SEL_CallFuncO NotificationObserver::getSelector() const
|
|||
return _selector;
|
||||
}
|
||||
|
||||
const char* NotificationObserver::getName() const
|
||||
const std::string& NotificationObserver::getName() const
|
||||
{
|
||||
return _name.c_str();
|
||||
return _name;
|
||||
}
|
||||
|
||||
Object* NotificationObserver::getSender() const
|
||||
|
|
|
@ -31,29 +31,29 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
class ScriptHandlerMgr;
|
||||
class CC_DLL NotificationCenter : public Object
|
||||
class CC_DLL __NotificationCenter : public Object
|
||||
{
|
||||
friend class ScriptHandlerMgr;
|
||||
public:
|
||||
/** NotificationCenter constructor
|
||||
/** __NotificationCenter constructor
|
||||
* @js ctor
|
||||
*/
|
||||
NotificationCenter();
|
||||
__NotificationCenter();
|
||||
|
||||
/** NotificationCenter destructor
|
||||
/** __NotificationCenter destructor
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~NotificationCenter();
|
||||
~__NotificationCenter();
|
||||
|
||||
/** Gets the single instance of NotificationCenter. */
|
||||
static NotificationCenter *getInstance();
|
||||
/** Gets the single instance of __NotificationCenter. */
|
||||
static __NotificationCenter *getInstance();
|
||||
|
||||
/** Destroys the single instance of NotificationCenter. */
|
||||
/** Destroys the single instance of __NotificationCenter. */
|
||||
static void destroyInstance();
|
||||
|
||||
/** @deprecated use getInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static NotificationCenter *sharedNotificationCenter(void);
|
||||
CC_DEPRECATED_ATTRIBUTE static __NotificationCenter *sharedNotificationCenter(void);
|
||||
|
||||
/** @deprecated use destroyInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static void purgeNotificationCenter(void);
|
||||
|
@ -67,14 +67,14 @@ public:
|
|||
*/
|
||||
void addObserver(Object *target,
|
||||
SEL_CallFuncO selector,
|
||||
const char *name,
|
||||
const std::string& name,
|
||||
Object *sender);
|
||||
|
||||
/** @brief Removes the observer by the specified target and name.
|
||||
* @param target The target of this notification.
|
||||
* @param name The name of this notification.
|
||||
*/
|
||||
void removeObserver(Object *target,const char *name);
|
||||
void removeObserver(Object *target,const std::string& name);
|
||||
|
||||
/** @brief Removes all notifications registered by this target
|
||||
* @param target The target of this notification.
|
||||
|
@ -86,21 +86,21 @@ public:
|
|||
* @note Only supports Lua Binding now.
|
||||
* @param handler The lua handler.
|
||||
*/
|
||||
void registerScriptObserver(Object *target,int handler,const char* name);
|
||||
void registerScriptObserver(Object *target,int handler,const std::string& name);
|
||||
|
||||
/** Unregisters script observer */
|
||||
void unregisterScriptObserver(Object *target,const char* name);
|
||||
void unregisterScriptObserver(Object *target,const std::string& name);
|
||||
|
||||
/** @brief Posts one notification event by name.
|
||||
* @param name The name of this notification.
|
||||
*/
|
||||
void postNotification(const char *name);
|
||||
void postNotification(const std::string& name);
|
||||
|
||||
/** @brief Posts one notification event by name.
|
||||
* @param name The name of this notification.
|
||||
* @param sender The object posting the notification. Can be nullptr
|
||||
*/
|
||||
void postNotification(const char *name, Object *sender);
|
||||
void postNotification(const std::string& name, Object *sender);
|
||||
|
||||
/** @brief Gets script handler.
|
||||
* @note Only supports Lua Binding now.
|
||||
|
@ -112,12 +112,12 @@ public:
|
|||
* @param name The name of this notification.
|
||||
* @return The observer script handle.
|
||||
*/
|
||||
int getObserverHandlerByName(const char* name);
|
||||
int getObserverHandlerByName(const std::string& name);
|
||||
private:
|
||||
// internal functions
|
||||
|
||||
// Check whether the observer exists by the specified target and name.
|
||||
bool observerExisted(Object *target,const char *name, Object *sender);
|
||||
bool observerExisted(Object *target,const std::string& name, Object *sender);
|
||||
|
||||
// variables
|
||||
//
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
*/
|
||||
NotificationObserver(Object *target,
|
||||
SEL_CallFuncO selector,
|
||||
const char *name,
|
||||
const std::string& name,
|
||||
Object *sender);
|
||||
|
||||
/** NotificationObserver destructor function
|
||||
|
@ -168,7 +168,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
const char* getName() const;
|
||||
const std::string& getName() const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "platform/CCFileUtils.h"
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -392,8 +392,7 @@ void ParticleBatchNode::draw(void)
|
|||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,
|
||||
_quadCommand.init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
|
@ -401,7 +400,7 @@ void ParticleBatchNode::draw(void)
|
|||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
CC_PROFILER_STOP("CCParticleBatchNode - draw");
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "CCNode.h"
|
||||
#include "CCProtocols.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -140,6 +141,8 @@ private:
|
|||
private:
|
||||
/** the blend function used for drawing the quads */
|
||||
BlendFunc _blendFunc;
|
||||
// quad command
|
||||
QuadCommand _quadCommand;
|
||||
};
|
||||
|
||||
// end of particle_nodes group
|
||||
|
|
|
@ -41,7 +41,7 @@ static Texture2D* getDefaultTexture()
|
|||
do
|
||||
{
|
||||
bool ret = false;
|
||||
const char* key = "/__firePngData";
|
||||
const std::string key = "/__firePngData";
|
||||
texture = Director::getInstance()->getTextureCache()->getTextureForKey(key);
|
||||
CC_BREAK_IF(texture != nullptr);
|
||||
|
||||
|
|
|
@ -35,15 +35,16 @@ THE SOFTWARE.
|
|||
#include "ccGLStateCache.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "CCCustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "CCEventListenerCustom.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -74,10 +75,8 @@ bool ParticleSystemQuad::initWithTotalParticles(int numberOfParticles)
|
|||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// Need to listen the event only when not use batchnode, because it will use VBO
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(ParticleSystemQuad::listenBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
nullptr);
|
||||
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(ParticleSystemQuad::listenBackToForeground, this));
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
@ -106,10 +105,6 @@ ParticleSystemQuad::~ParticleSystemQuad()
|
|||
GL::bindVAO(0);
|
||||
}
|
||||
}
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
#endif
|
||||
}
|
||||
|
||||
// implementation ParticleSystemQuad
|
||||
|
@ -443,9 +438,8 @@ void ParticleSystemQuad::draw()
|
|||
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
_quadCommand.init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -577,7 +571,7 @@ void ParticleSystemQuad::setupVBO()
|
|||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
void ParticleSystemQuad::listenBackToForeground(Object *obj)
|
||||
void ParticleSystemQuad::listenBackToForeground(EventCustom* event)
|
||||
{
|
||||
if (Configuration::getInstance()->supportsShareableVAO())
|
||||
{
|
||||
|
|
|
@ -28,10 +28,12 @@ THE SOFTWARE.
|
|||
#define __CC_PARTICLE_SYSTEM_QUAD_H__
|
||||
|
||||
#include "CCParticleSystem.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class SpriteFrame;
|
||||
class EventCustom;
|
||||
|
||||
/**
|
||||
* @addtogroup particle_nodes
|
||||
|
@ -80,7 +82,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void listenBackToForeground(Object *obj);
|
||||
void listenBackToForeground(EventCustom* event);
|
||||
|
||||
// Overrides
|
||||
/**
|
||||
|
@ -151,6 +153,8 @@ protected:
|
|||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||
|
||||
kmMat4 _transformMatrix;
|
||||
|
||||
QuadCommand _quadCommand; // quad command
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad);
|
||||
};
|
||||
|
|
|
@ -532,10 +532,9 @@ void ProgressTimer::draw()
|
|||
if( ! _vertexData || ! _sprite)
|
||||
return;
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ProgressTimer::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
_customCommand.init(0, _vertexZ);
|
||||
_customCommand.func = CC_CALLBACK_0(ProgressTimer::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
|||
#define __MISC_NODE_CCPROGRESS_TIMER_H__
|
||||
|
||||
#include "CCSprite.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#ifdef EMSCRIPTEN
|
||||
#include "CCGLBufferedNode.h"
|
||||
#endif // EMSCRIPTEN
|
||||
|
@ -143,6 +144,8 @@ protected:
|
|||
Sprite *_sprite;
|
||||
int _vertexDataCount;
|
||||
V2F_C4B_T2F *_vertexData;
|
||||
|
||||
CustomCommand _customCommand;
|
||||
|
||||
bool _reverseDirection;
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ THE SOFTWARE.
|
|||
#include "CCTextureCache.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "CCGL.h"
|
||||
#include "CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCGrid.h"
|
||||
|
||||
|
@ -44,6 +43,8 @@ THE SOFTWARE.
|
|||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "CCEventListenerCustom.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -66,15 +67,11 @@ RenderTexture::RenderTexture()
|
|||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// Listen this event to save render texture before come to background.
|
||||
// Then it can be restored after coming to foreground on Android.
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(RenderTexture::listenToBackground),
|
||||
EVENT_COME_TO_BACKGROUND,
|
||||
nullptr);
|
||||
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(RenderTexture::listenToForeground),
|
||||
EVNET_COME_TO_FOREGROUND, // this is misspelt
|
||||
nullptr);
|
||||
auto toBackgroundListener = EventListenerCustom::create(EVENT_COME_TO_BACKGROUND, CC_CALLBACK_1(RenderTexture::listenToBackground, this));
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(toBackgroundListener, this);
|
||||
|
||||
auto toForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(RenderTexture::listenToForeground, this));
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(toForegroundListener, this);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -89,14 +86,9 @@ RenderTexture::~RenderTexture()
|
|||
glDeleteRenderbuffers(1, &_depthRenderBufffer);
|
||||
}
|
||||
CC_SAFE_DELETE(_UITextureImage);
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
NotificationCenter::getInstance()->removeObserver(this, EVENT_COME_TO_BACKGROUND);
|
||||
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RenderTexture::listenToBackground(cocos2d::Object *obj)
|
||||
void RenderTexture::listenToBackground(EventCustom *event)
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
CC_SAFE_DELETE(_UITextureImage);
|
||||
|
@ -124,7 +116,7 @@ void RenderTexture::listenToBackground(cocos2d::Object *obj)
|
|||
#endif
|
||||
}
|
||||
|
||||
void RenderTexture::listenToForeground(cocos2d::Object *obj)
|
||||
void RenderTexture::listenToForeground(EventCustom *event)
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// -- regenerate frame buffer object and attach the texture
|
||||
|
@ -329,10 +321,9 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep
|
|||
this->begin();
|
||||
|
||||
//clear screen
|
||||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
_beginWithClearCommand.init(0, _vertexZ);
|
||||
_beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand);
|
||||
}
|
||||
|
||||
//TODO find a better way to clear the screen, there is no need to rebind render buffer there.
|
||||
|
@ -348,11 +339,10 @@ void RenderTexture::clearDepth(float depthValue)
|
|||
|
||||
this->begin();
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(RenderTexture::onClearDepth, this);
|
||||
_clearDepthCommand.init(0, _vertexZ);
|
||||
_clearDepthCommand.func = CC_CALLBACK_0(RenderTexture::onClearDepth, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_clearDepthCommand);
|
||||
|
||||
this->end();
|
||||
}
|
||||
|
@ -508,7 +498,7 @@ void RenderTexture::onBegin()
|
|||
float heightRatio = size.height / texSize.height;
|
||||
|
||||
// Adjust the orthographic projection and viewport
|
||||
glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);
|
||||
glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height);
|
||||
|
||||
|
||||
kmMat4 orthoMatrix;
|
||||
|
@ -614,10 +604,9 @@ void RenderTexture::draw()
|
|||
begin();
|
||||
|
||||
//clear screen
|
||||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
_clearCommand.init(0, _vertexZ);
|
||||
_clearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_clearCommand);
|
||||
|
||||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
@ -642,30 +631,48 @@ void RenderTexture::begin()
|
|||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
|
||||
|
||||
Director *director = Director::getInstance();
|
||||
director->setProjection(director->getProjection());
|
||||
|
||||
const Size& texSize = _texture->getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
Size size = director->getWinSizeInPixels();
|
||||
float widthRatio = size.width / texSize.width;
|
||||
float heightRatio = size.height / texSize.height;
|
||||
|
||||
kmMat4 orthoMatrix;
|
||||
kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio,
|
||||
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
|
||||
kmGLMultMatrix(&orthoMatrix);
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0, _vertexZ);
|
||||
_groupCommand.init(0, _vertexZ);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(groupCommand);
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
renderer->addCommand(&_groupCommand);
|
||||
renderer->pushGroup(_groupCommand.getRenderQueueID());
|
||||
|
||||
CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beginCmd->init(0, _vertexZ);
|
||||
beginCmd->func = CC_CALLBACK_0(RenderTexture::onBegin, this);
|
||||
_beginCommand.init(0, _vertexZ);
|
||||
_beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(beginCmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_beginCommand);
|
||||
}
|
||||
|
||||
void RenderTexture::end()
|
||||
{
|
||||
CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
endCmd->init(0, _vertexZ);
|
||||
endCmd->func = CC_CALLBACK_0(RenderTexture::onEnd, this);
|
||||
_endCommand.init(0, _vertexZ);
|
||||
_endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(endCmd);
|
||||
renderer->addCommand(&_endCommand);
|
||||
renderer->popGroup();
|
||||
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLPopMatrix();
|
||||
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -29,9 +29,13 @@ THE SOFTWARE.
|
|||
#include "CCSprite.h"
|
||||
#include "kazmath/mat4.h"
|
||||
#include "platform/CCImage.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class EventCustom;
|
||||
|
||||
/**
|
||||
* @addtogroup textures
|
||||
* @{
|
||||
|
@ -109,12 +113,12 @@ public:
|
|||
/** Listen "come to background" message, and save render texture.
|
||||
It only has effect on Android.
|
||||
*/
|
||||
void listenToBackground(Object *obj);
|
||||
void listenToBackground(EventCustom *event);
|
||||
|
||||
/** Listen "come to foreground" message and restore the frame buffer object
|
||||
It only has effect on Android.
|
||||
*/
|
||||
void listenToForeground(Object *obj);
|
||||
void listenToForeground(EventCustom *event);
|
||||
|
||||
/** Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT. They can be OR'ed. Valid when "autoDraw" is true. */
|
||||
inline unsigned int getClearFlags() const { return _clearFlags; };
|
||||
|
@ -187,6 +191,13 @@ protected:
|
|||
- [[renderTexture sprite] setBlendFunc:(BlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
||||
*/
|
||||
Sprite* _sprite;
|
||||
|
||||
GroupCommand _groupCommand;
|
||||
CustomCommand _beginWithClearCommand;
|
||||
CustomCommand _clearDepthCommand;
|
||||
CustomCommand _clearCommand;
|
||||
CustomCommand _beginCommand;
|
||||
CustomCommand _endCommand;
|
||||
protected:
|
||||
//renderer caches and callbacks
|
||||
void onBegin();
|
||||
|
|
|
@ -34,7 +34,7 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
Scene::Scene()
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
: _physicsWorld(nullptr)
|
||||
#endif
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ Scene::Scene()
|
|||
|
||||
Scene::~Scene()
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
CC_SAFE_DELETE(_physicsWorld);
|
||||
#endif
|
||||
}
|
||||
|
@ -88,7 +88,22 @@ Scene* Scene::getScene()
|
|||
return this;
|
||||
}
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
void Scene::addChild(Node* child, int zOrder, int tag)
|
||||
{
|
||||
Node::addChild(child, zOrder, tag);
|
||||
addChildToPhysicsWorld(child);
|
||||
}
|
||||
|
||||
void Scene::update(float delta)
|
||||
{
|
||||
Node::update(delta);
|
||||
if (nullptr != _physicsWorld)
|
||||
{
|
||||
_physicsWorld->update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
Scene *Scene::createWithPhysics()
|
||||
{
|
||||
Scene *ret = new Scene();
|
||||
|
@ -121,13 +136,6 @@ bool Scene::initWithPhysics()
|
|||
return ret;
|
||||
}
|
||||
|
||||
void Scene::addChild(Node* child, int zOrder, int tag)
|
||||
{
|
||||
Node::addChild(child, zOrder, tag);
|
||||
|
||||
addChildToPhysicsWorld(child);
|
||||
}
|
||||
|
||||
void Scene::addChildToPhysicsWorld(Node* child)
|
||||
{
|
||||
if (_physicsWorld)
|
||||
|
@ -149,18 +157,6 @@ void Scene::addChildToPhysicsWorld(Node* child)
|
|||
addToPhysicsWorldFunc(child);
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::update(float delta)
|
||||
{
|
||||
Node::update(delta);
|
||||
|
||||
if (nullptr != _physicsWorld)
|
||||
{
|
||||
_physicsWorld->update(delta);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -52,42 +52,36 @@ class CC_DLL Scene : public Node
|
|||
public:
|
||||
/** creates a new Scene object */
|
||||
static Scene *create();
|
||||
#ifdef CC_USE_PHYSICS
|
||||
static Scene *createWithPhysics();
|
||||
#endif
|
||||
|
||||
// Overrides
|
||||
virtual Scene *getScene() override;
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
public:
|
||||
|
||||
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
|
||||
|
||||
using Node::addChild;
|
||||
virtual void addChild(Node* child, int zOrder, int tag) override;
|
||||
virtual void update(float delta) override;
|
||||
virtual std::string getDescription() const override;
|
||||
|
||||
protected:
|
||||
Scene();
|
||||
virtual ~Scene();
|
||||
bool init();
|
||||
|
||||
friend class Node;
|
||||
friend class SpriteBatchNode;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(Scene);
|
||||
|
||||
#if CC_USE_PHYSICS
|
||||
public:
|
||||
virtual void addChild(Node* child, int zOrder, int tag) override;
|
||||
virtual void update(float delta) override;
|
||||
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
|
||||
static Scene *createWithPhysics();
|
||||
protected:
|
||||
bool initWithPhysics();
|
||||
void addChildToPhysicsWorld(Node* child);
|
||||
|
||||
PhysicsWorld* _physicsWorld;
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
Scene();
|
||||
virtual ~Scene();
|
||||
bool init();
|
||||
|
||||
friend class Node;
|
||||
friend class SpriteBatchNode;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(Scene);
|
||||
};
|
||||
|
||||
// end of scene group
|
||||
|
|
|
@ -41,7 +41,6 @@ NS_CC_BEGIN
|
|||
class Timer;
|
||||
class Layer;
|
||||
class MenuItem;
|
||||
class NotificationCenter;
|
||||
class CallFunc;
|
||||
class Acceleration;
|
||||
|
||||
|
@ -201,7 +200,6 @@ enum ScriptEventType
|
|||
{
|
||||
kNodeEvent = 0,
|
||||
kMenuClickedEvent,
|
||||
kNotificationEvent,
|
||||
kCallFuncEvent,
|
||||
kScheduleEvent,
|
||||
kTouchEvent,
|
||||
|
@ -210,16 +208,6 @@ enum ScriptEventType
|
|||
kAccelerometerEvent,
|
||||
kControlEvent,
|
||||
kCommonEvent,
|
||||
kTableViewEvent,//Now it's only used in LuaBinding
|
||||
kAssetsManagerEvent,//Now it's only used in Lua Binding
|
||||
kCocoStudioEventListener,//Now it's only used in Lua Binding
|
||||
kArmatureWrapper,//Now it's only used in Lua Binding
|
||||
kEventListenerAcc,//Now it's only used in Lua Binding
|
||||
kEventListenerKeyboard,//Now it's only used in Lua Binding
|
||||
kEventListenerTouch,//Now it's only used in Lua Binding
|
||||
kEventListenerTouches,//Now it's only used in Lua Binding
|
||||
kEventListenerMouse,//Now it's only used in Lua Binding
|
||||
kEventListenerCustom,////Now it's only used in Lua Binding
|
||||
};
|
||||
|
||||
struct BasicScriptData
|
||||
|
@ -438,6 +426,14 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual bool handleAssert(const char *msg) = 0;
|
||||
|
||||
enum class ConfigType
|
||||
{
|
||||
NONE,
|
||||
COCOSTUDIO
|
||||
};
|
||||
/** Parse configuration file */
|
||||
virtual bool parseConfig(ConfigType type, const std::string& str) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -185,6 +185,11 @@ void ShaderCache::reloadDefaultShaders()
|
|||
p->reset();
|
||||
loadDefaultShader(p, kShaderType_PositionTextureColor);
|
||||
|
||||
// Position Texture Color without MVP shader
|
||||
p = getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
p->reset();
|
||||
loadDefaultShader(p, kShaderType_PositionTextureColor_noMVP);
|
||||
|
||||
// Position Texture Color alpha test
|
||||
p = getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
|
||||
p->reset();
|
||||
|
|
|
@ -45,7 +45,7 @@ THE SOFTWARE.
|
|||
#include "TransformUtils.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "CCFrustum.h"
|
||||
|
||||
// external
|
||||
|
@ -502,7 +502,7 @@ void Sprite::updateTransform(void)
|
|||
{
|
||||
CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode");
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
if (updatePhysicsTransform())
|
||||
{
|
||||
setDirty(true);
|
||||
|
@ -671,16 +671,11 @@ void Sprite::updateTransform(void)
|
|||
void Sprite::draw(void)
|
||||
{
|
||||
//TODO implement z order
|
||||
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
|
||||
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform);
|
||||
_quadCommand.init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform);
|
||||
|
||||
// if(!culling())
|
||||
// {
|
||||
// renderCommand->releaseToCommandPool();
|
||||
// }
|
||||
// else
|
||||
// if(culling())
|
||||
{
|
||||
Director::getInstance()->getRenderer()->addCommand(renderCommand);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -711,7 +706,7 @@ bool Sprite::culling() const
|
|||
|
||||
void Sprite::updateQuadVertices()
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#if CC_USE_PHYSICS
|
||||
updatePhysicsTransform();
|
||||
setDirty(true);
|
||||
#endif
|
||||
|
|
|
@ -37,6 +37,7 @@ THE SOFTWARE.
|
|||
#include "CCGLBufferedNode.h"
|
||||
#endif // EMSCRIPTEN
|
||||
#include "CCPhysicsBody.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -545,6 +546,7 @@ protected:
|
|||
//
|
||||
BlendFunc _blendFunc; /// It's required for TextureProtocol inheritance
|
||||
Texture2D* _texture; /// Texture2D object that is used to render the sprite
|
||||
QuadCommand _quadCommand; /// quad command
|
||||
|
||||
//
|
||||
// Shared data
|
||||
|
|
|
@ -43,7 +43,7 @@ THE SOFTWARE.
|
|||
#include "CCLayer.h"
|
||||
#include "CCScene.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
// external
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
|
@ -66,7 +66,7 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, ssize_t capa
|
|||
* creation with File Image
|
||||
*/
|
||||
|
||||
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/)
|
||||
SpriteBatchNode* SpriteBatchNode::create(const std::string& fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/)
|
||||
{
|
||||
SpriteBatchNode *batchNode = new SpriteBatchNode();
|
||||
batchNode->initWithFile(fileImage, capacity);
|
||||
|
@ -112,7 +112,7 @@ bool SpriteBatchNode::init()
|
|||
/*
|
||||
* init with FileImage
|
||||
*/
|
||||
bool SpriteBatchNode::initWithFile(const char* fileImage, ssize_t capacity)
|
||||
bool SpriteBatchNode::initWithFile(const std::string& fileImage, ssize_t capacity)
|
||||
{
|
||||
Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage);
|
||||
return initWithTexture(texture2D, capacity);
|
||||
|
@ -360,8 +360,7 @@ void SpriteBatchNode::draw()
|
|||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,
|
||||
_quadCommand.init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
|
@ -369,7 +368,7 @@ void SpriteBatchNode::draw()
|
|||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
}
|
||||
|
||||
void SpriteBatchNode::increaseAtlasCapacity(void)
|
||||
|
@ -379,8 +378,8 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
|
|||
// this is likely computationally expensive
|
||||
ssize_t quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
|
||||
|
||||
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%zd] to [%zd].",
|
||||
_textureAtlas->getCapacity(),
|
||||
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%d] to [%d].",
|
||||
static_cast<int>(_textureAtlas->getCapacity()),
|
||||
quantity);
|
||||
|
||||
if (! _textureAtlas->resizeCapacity(quantity))
|
||||
|
|
|
@ -34,6 +34,7 @@ THE SOFTWARE.
|
|||
#include "CCProtocols.h"
|
||||
#include "CCTextureAtlas.h"
|
||||
#include "ccMacros.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -74,7 +75,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, ssize_t capacity = DEFAULT_CAPACITY);
|
||||
static SpriteBatchNode* create(const std::string& fileImage, ssize_t capacity = DEFAULT_CAPACITY);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -95,7 +96,7 @@ public:
|
|||
* @js init
|
||||
* @lua init
|
||||
*/
|
||||
bool initWithFile(const char* fileImage, ssize_t capacity);
|
||||
bool initWithFile(const std::string& fileImage, ssize_t capacity);
|
||||
bool init();
|
||||
|
||||
/** returns the TextureAtlas object */
|
||||
|
@ -187,6 +188,7 @@ protected:
|
|||
|
||||
TextureAtlas *_textureAtlas;
|
||||
BlendFunc _blendFunc;
|
||||
QuadCommand _quadCommand; // quad command
|
||||
|
||||
// all descendants: children, grand children, etc...
|
||||
// There is not need to retain/release these objects, since they are already retained by _children
|
||||
|
|
|
@ -61,14 +61,12 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
|
|||
texture = Director::getInstance()->getTextureCache()->addImage(tilesetInfo->_sourceImage.c_str());
|
||||
}
|
||||
|
||||
if (SpriteBatchNode::initWithTexture(texture, (unsigned int)capacity))
|
||||
if (SpriteBatchNode::initWithTexture(texture, static_cast<ssize_t>(capacity)))
|
||||
{
|
||||
// layerInfo
|
||||
_layerName = layerInfo->_name;
|
||||
_layerSize = size;
|
||||
_tiles = layerInfo->_tiles;
|
||||
_minGID = layerInfo->_minGID;
|
||||
_maxGID = layerInfo->_maxGID;
|
||||
_opacity = layerInfo->_opacity;
|
||||
setProperties(layerInfo->getProperties());
|
||||
_contentScaleFactor = Director::getInstance()->getContentScaleFactor();
|
||||
|
@ -85,7 +83,7 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
|
|||
Point offset = this->calculateLayerOffset(layerInfo->_offset);
|
||||
this->setPosition(CC_POINT_PIXELS_TO_POINTS(offset));
|
||||
|
||||
_atlasIndexArray = ccCArrayNew((unsigned int)totalNumberOfTiles);
|
||||
_atlasIndexArray = ccCArrayNew(totalNumberOfTiles);
|
||||
|
||||
this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(Size(_layerSize.width * _mapTileSize.width, _layerSize.height * _mapTileSize.height)));
|
||||
|
||||
|
@ -100,8 +98,6 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
|
|||
TMXLayer::TMXLayer()
|
||||
:_layerName("")
|
||||
,_opacity(0)
|
||||
,_minGID(0)
|
||||
,_maxGID(0)
|
||||
,_vertexZvalue(0)
|
||||
,_useAutomaticVertexZ(false)
|
||||
,_reusedTile(nullptr)
|
||||
|
@ -161,12 +157,12 @@ void TMXLayer::setupTiles()
|
|||
// Parse cocos2d properties
|
||||
this->parseInternalProperties();
|
||||
|
||||
for (unsigned int y=0; y < _layerSize.height; y++)
|
||||
for (int y=0; y < _layerSize.height; y++)
|
||||
{
|
||||
for (unsigned int x=0; x < _layerSize.width; x++)
|
||||
for (int x=0; x < _layerSize.width; x++)
|
||||
{
|
||||
unsigned int pos = (unsigned int)(x + _layerSize.width * y);
|
||||
unsigned int gid = _tiles[ pos ];
|
||||
int pos = static_cast<int>(x + _layerSize.width * y);
|
||||
int gid = _tiles[ pos ];
|
||||
|
||||
// gid are stored in little endian.
|
||||
// if host is big endian, then swap
|
||||
|
@ -178,16 +174,9 @@ void TMXLayer::setupTiles()
|
|||
if (gid != 0)
|
||||
{
|
||||
this->appendTileForGID(gid, Point(x, y));
|
||||
|
||||
// Optimization: update min and max GID rendered by the layer
|
||||
_minGID = MIN(gid, _minGID);
|
||||
_maxGID = MAX(gid, _maxGID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CCASSERT( _maxGID >= _tileSet->_firstGid &&
|
||||
_minGID >= _tileSet->_firstGid, "TMX: Only 1 tileset per layer is supported");
|
||||
}
|
||||
|
||||
// TMXLayer - Properties
|
||||
|
@ -231,7 +220,7 @@ void TMXLayer::parseInternalProperties()
|
|||
}
|
||||
}
|
||||
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, Point pos, unsigned int gid)
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, Point pos, int gid)
|
||||
{
|
||||
sprite->setPosition(getPositionAt(pos));
|
||||
sprite->setVertexZ((float)getVertexZForPos(pos));
|
||||
|
@ -252,7 +241,7 @@ void TMXLayer::setupTileSprite(Sprite* sprite, Point pos, unsigned int gid)
|
|||
sprite->setPosition(Point(getPositionAt(pos).x + sprite->getContentSize().height/2,
|
||||
getPositionAt(pos).y + sprite->getContentSize().width/2 ) );
|
||||
|
||||
unsigned int flag = gid & (kTMXTileHorizontalFlag | kTMXTileVerticalFlag );
|
||||
int flag = gid & (kTMXTileHorizontalFlag | kTMXTileVerticalFlag );
|
||||
|
||||
// handle the 4 diagonally flipped states.
|
||||
if (flag == kTMXTileHorizontalFlag)
|
||||
|
@ -319,7 +308,7 @@ Sprite * TMXLayer::getTileAt(const Point& pos)
|
|||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
|
||||
Sprite *tile = nullptr;
|
||||
unsigned int gid = this->getTileGIDAt(pos);
|
||||
int gid = this->getTileGIDAt(pos);
|
||||
|
||||
// if GID == 0, then no tile is present
|
||||
if (gid)
|
||||
|
@ -348,14 +337,14 @@ Sprite * TMXLayer::getTileAt(const Point& pos)
|
|||
return tile;
|
||||
}
|
||||
|
||||
unsigned int TMXLayer::getTileGIDAt(const Point& pos, ccTMXTileFlags* flags/* = nullptr*/)
|
||||
int TMXLayer::getTileGIDAt(const Point& pos, ccTMXTileFlags* flags/* = nullptr*/)
|
||||
{
|
||||
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
|
||||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
|
||||
int idx = (int)(pos.x + pos.y * _layerSize.width);
|
||||
int idx = static_cast<int>((pos.x + pos.y * _layerSize.width));
|
||||
// Bits on the far end of the 32-bit global tile ID are used for tile flags
|
||||
unsigned int tile = _tiles[idx];
|
||||
int tile = _tiles[idx];
|
||||
|
||||
// issue1264, flipped tiles can be changed dynamically
|
||||
if (flags)
|
||||
|
@ -367,42 +356,47 @@ unsigned int TMXLayer::getTileGIDAt(const Point& pos, ccTMXTileFlags* flags/* =
|
|||
}
|
||||
|
||||
// TMXLayer - adding helper methods
|
||||
Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
||||
Sprite * TMXLayer::insertTileForGID(int gid, const Point& pos)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = CC_RECT_PIXELS_TO_POINTS(rect);
|
||||
|
||||
intptr_t z = (intptr_t)(pos.x + pos.y * _layerSize.width);
|
||||
|
||||
Sprite *tile = reusedTileWithRect(rect);
|
||||
|
||||
setupTileSprite(tile, pos, gid);
|
||||
|
||||
// get atlas index
|
||||
ssize_t indexForZ = atlasIndexForNewZ(static_cast<int>(z));
|
||||
|
||||
// Optimization: add the quad without adding a child
|
||||
this->insertQuadFromSprite(tile, indexForZ);
|
||||
|
||||
// insert it into the local atlasindex array
|
||||
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
|
||||
|
||||
// update possible children
|
||||
|
||||
for(const auto &child : _children) {
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
ssize_t ai = sp->getAtlasIndex();
|
||||
if ( ai >= indexForZ )
|
||||
{
|
||||
sp->setAtlasIndex(ai+1);
|
||||
if (gid != 0 && (static_cast<int>((gid & kFlippedMask)) - _tileSet->_firstGid) >= 0)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = CC_RECT_PIXELS_TO_POINTS(rect);
|
||||
|
||||
intptr_t z = (intptr_t)(pos.x + pos.y * _layerSize.width);
|
||||
|
||||
Sprite *tile = reusedTileWithRect(rect);
|
||||
|
||||
setupTileSprite(tile, pos, gid);
|
||||
|
||||
// get atlas index
|
||||
ssize_t indexForZ = atlasIndexForNewZ(static_cast<int>(z));
|
||||
|
||||
// Optimization: add the quad without adding a child
|
||||
this->insertQuadFromSprite(tile, indexForZ);
|
||||
|
||||
// insert it into the local atlasindex array
|
||||
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
|
||||
|
||||
// update possible children
|
||||
|
||||
for(const auto &child : _children) {
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
ssize_t ai = sp->getAtlasIndex();
|
||||
if ( ai >= indexForZ )
|
||||
{
|
||||
sp->setAtlasIndex(ai+1);
|
||||
}
|
||||
}
|
||||
|
||||
_tiles[z] = gid;
|
||||
return tile;
|
||||
}
|
||||
|
||||
_tiles[z] = gid;
|
||||
return tile;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
||||
Sprite * TMXLayer::updateTileForGID(int gid, const Point& pos)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = Rect(rect.origin.x / _contentScaleFactor, rect.origin.y / _contentScaleFactor, rect.size.width/ _contentScaleFactor, rect.size.height/ _contentScaleFactor);
|
||||
|
@ -424,29 +418,34 @@ Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
|||
|
||||
// used only when parsing the map. useless after the map was parsed
|
||||
// since lot's of assumptions are no longer true
|
||||
Sprite * TMXLayer::appendTileForGID(unsigned int gid, const Point& pos)
|
||||
Sprite * TMXLayer::appendTileForGID(int gid, const Point& pos)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = CC_RECT_PIXELS_TO_POINTS(rect);
|
||||
|
||||
intptr_t z = (intptr_t)(pos.x + pos.y * _layerSize.width);
|
||||
|
||||
Sprite *tile = reusedTileWithRect(rect);
|
||||
|
||||
setupTileSprite(tile ,pos ,gid);
|
||||
|
||||
// optimization:
|
||||
// The difference between appendTileForGID and insertTileforGID is that append is faster, since
|
||||
// it appends the tile at the end of the texture atlas
|
||||
ssize_t indexForZ = _atlasIndexArray->num;
|
||||
|
||||
// don't add it using the "standard" way.
|
||||
insertQuadFromSprite(tile, indexForZ);
|
||||
|
||||
// append should be after addQuadFromSprite since it modifies the quantity values
|
||||
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
|
||||
|
||||
return tile;
|
||||
if (gid != 0 && (static_cast<int>((gid & kFlippedMask)) - _tileSet->_firstGid) >= 0)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = CC_RECT_PIXELS_TO_POINTS(rect);
|
||||
|
||||
intptr_t z = (intptr_t)(pos.x + pos.y * _layerSize.width);
|
||||
|
||||
Sprite *tile = reusedTileWithRect(rect);
|
||||
|
||||
setupTileSprite(tile ,pos ,gid);
|
||||
|
||||
// optimization:
|
||||
// The difference between appendTileForGID and insertTileforGID is that append is faster, since
|
||||
// it appends the tile at the end of the texture atlas
|
||||
ssize_t indexForZ = _atlasIndexArray->num;
|
||||
|
||||
// don't add it using the "standard" way.
|
||||
insertQuadFromSprite(tile, indexForZ);
|
||||
|
||||
// append should be after addQuadFromSprite since it modifies the quantity values
|
||||
ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TMXLayer - atlasIndex and Z
|
||||
|
@ -455,7 +454,7 @@ static inline int compareInts(const void * a, const void * b)
|
|||
return ((*(int*)a) - (*(int*)b));
|
||||
}
|
||||
|
||||
ssize_t TMXLayer::atlasIndexForExistantZ(unsigned int z)
|
||||
ssize_t TMXLayer::atlasIndexForExistantZ(int z)
|
||||
{
|
||||
int key=z;
|
||||
int *item = (int*)bsearch((void*)&key, (void*)&_atlasIndexArray->arr[0], _atlasIndexArray->num, sizeof(void*), compareInts);
|
||||
|
@ -483,23 +482,23 @@ ssize_t TMXLayer::atlasIndexForNewZ(int z)
|
|||
}
|
||||
|
||||
// TMXLayer - adding / remove tiles
|
||||
void TMXLayer::setTileGID(unsigned int gid, const Point& pos)
|
||||
void TMXLayer::setTileGID(int gid, const Point& pos)
|
||||
{
|
||||
setTileGID(gid, pos, (ccTMXTileFlags)0);
|
||||
}
|
||||
|
||||
void TMXLayer::setTileGID(unsigned int gid, const Point& pos, ccTMXTileFlags flags)
|
||||
void TMXLayer::setTileGID(int gid, const Point& pos, ccTMXTileFlags flags)
|
||||
{
|
||||
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
|
||||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
CCASSERT(gid == 0 || gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" );
|
||||
|
||||
ccTMXTileFlags currentFlags;
|
||||
unsigned int currentGID = getTileGIDAt(pos, ¤tFlags);
|
||||
int currentGID = getTileGIDAt(pos, ¤tFlags);
|
||||
|
||||
if (currentGID != gid || currentFlags != flags)
|
||||
{
|
||||
unsigned gidAndFlags = gid | flags;
|
||||
int gidAndFlags = gid | flags;
|
||||
|
||||
// setting gid=0 is equal to remove the tile
|
||||
if (gid == 0)
|
||||
|
@ -514,7 +513,7 @@ void TMXLayer::setTileGID(unsigned int gid, const Point& pos, ccTMXTileFlags fla
|
|||
// modifying an existing tile with a non-empty tile
|
||||
else
|
||||
{
|
||||
unsigned int z = (unsigned int)(pos.x + pos.y * _layerSize.width);
|
||||
int z = pos.x + pos.y * _layerSize.width;
|
||||
Sprite *sprite = static_cast<Sprite*>(getChildByTag(z));
|
||||
if (sprite)
|
||||
{
|
||||
|
@ -567,11 +566,11 @@ void TMXLayer::removeTileAt(const Point& pos)
|
|||
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
|
||||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
|
||||
unsigned int gid = getTileGIDAt(pos);
|
||||
int gid = getTileGIDAt(pos);
|
||||
|
||||
if (gid)
|
||||
{
|
||||
unsigned int z = (unsigned int)(pos.x + pos.y * _layerSize.width);
|
||||
int z = pos.x + pos.y * _layerSize.width;
|
||||
ssize_t atlasIndex = atlasIndexForExistantZ(z);
|
||||
|
||||
// remove tile from GID map
|
||||
|
@ -670,17 +669,17 @@ Point TMXLayer::getPositionForHexAt(const Point& pos)
|
|||
int TMXLayer::getVertexZForPos(const Point& pos)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int maxVal = 0;
|
||||
int maxVal = 0;
|
||||
if (_useAutomaticVertexZ)
|
||||
{
|
||||
switch (_layerOrientation)
|
||||
{
|
||||
case TMXOrientationIso:
|
||||
maxVal = (unsigned int)(_layerSize.width + _layerSize.height);
|
||||
ret = (int)(-(maxVal - (pos.x + pos.y)));
|
||||
maxVal = static_cast<int>(_layerSize.width + _layerSize.height);
|
||||
ret = static_cast<int>(-(maxVal - (pos.x + pos.y)));
|
||||
break;
|
||||
case TMXOrientationOrtho:
|
||||
ret = (int)(-(_layerSize.height-pos.y));
|
||||
ret = static_cast<int>(-(_layerSize.height-pos.y));
|
||||
break;
|
||||
case TMXOrientationHex:
|
||||
CCASSERT(0, "TMX Hexa zOrder not supported");
|
||||
|
|
|
@ -109,8 +109,8 @@ public:
|
|||
/** returns the tile gid at a given tile coordinate. It also returns the tile flags.
|
||||
This method requires the the tile map has not been previously released (eg. don't call [layer releaseMap])
|
||||
*/
|
||||
unsigned int getTileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr);
|
||||
CC_DEPRECATED_ATTRIBUTE unsigned int tileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr){
|
||||
int getTileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr);
|
||||
CC_DEPRECATED_ATTRIBUTE int tileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr){
|
||||
return getTileGIDAt(tileCoordinate, flags);
|
||||
};
|
||||
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1.
|
||||
If a tile is already placed at that position, then it will be removed.
|
||||
*/
|
||||
void setTileGID(unsigned int gid, const Point& tileCoordinate);
|
||||
void setTileGID(int gid, const Point& tileCoordinate);
|
||||
|
||||
/** sets the tile gid (gid = tile global id) at a given tile coordinate.
|
||||
The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1.
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
Use withFlags if the tile flags need to be changed as well
|
||||
*/
|
||||
|
||||
void setTileGID(unsigned int gid, const Point& tileCoordinate, ccTMXTileFlags flags);
|
||||
void setTileGID(int gid, const Point& tileCoordinate, ccTMXTileFlags flags);
|
||||
|
||||
/** removes a tile at given tile coordinate */
|
||||
void removeTileAt(const Point& tileCoordinate);
|
||||
|
@ -143,8 +143,8 @@ public:
|
|||
/** Creates the tiles */
|
||||
void setupTiles();
|
||||
|
||||
inline const char* getLayerName(){ return _layerName.c_str(); }
|
||||
inline void setLayerName(const char *layerName){ _layerName = layerName; }
|
||||
inline const std::string& getLayerName(){ return _layerName; }
|
||||
inline void setLayerName(const std::string& layerName){ _layerName = layerName; }
|
||||
|
||||
/** size of the layer in tiles */
|
||||
inline const Size& getLayerSize() const { return _layerSize; };
|
||||
|
@ -158,8 +158,8 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
inline unsigned int* getTiles() const { return _tiles; };
|
||||
inline void setTiles(unsigned int* tiles) { _tiles = tiles; };
|
||||
inline int* getTiles() const { return _tiles; };
|
||||
inline void setTiles(int* tiles) { _tiles = tiles; };
|
||||
|
||||
/** Tileset information for the layer */
|
||||
inline TMXTilesetInfo* getTileSet() const { return _tileSet; };
|
||||
|
@ -170,8 +170,8 @@ public:
|
|||
};
|
||||
|
||||
/** Layer orientation, which is the same as the map orientation */
|
||||
inline unsigned int getLayerOrientation() const { return _layerOrientation; };
|
||||
inline void setLayerOrientation(unsigned int orientation) { _layerOrientation = orientation; };
|
||||
inline int getLayerOrientation() const { return _layerOrientation; };
|
||||
inline void setLayerOrientation(int orientation) { _layerOrientation = orientation; };
|
||||
|
||||
/** properties from the layer. They can be added using Tiled */
|
||||
inline const ValueMap& getProperties() const { return _properties; };
|
||||
|
@ -199,18 +199,18 @@ private:
|
|||
Point calculateLayerOffset(const Point& offset);
|
||||
|
||||
/* optimization methods */
|
||||
Sprite* appendTileForGID(unsigned int gid, const Point& pos);
|
||||
Sprite* insertTileForGID(unsigned int gid, const Point& pos);
|
||||
Sprite* updateTileForGID(unsigned int gid, const Point& pos);
|
||||
Sprite* appendTileForGID(int gid, const Point& pos);
|
||||
Sprite* insertTileForGID(int gid, const Point& pos);
|
||||
Sprite* updateTileForGID(int gid, const Point& pos);
|
||||
|
||||
/* The layer recognizes some special properties, like cc_vertez */
|
||||
void parseInternalProperties();
|
||||
void setupTileSprite(Sprite* sprite, Point pos, unsigned int gid);
|
||||
void setupTileSprite(Sprite* sprite, Point pos, int gid);
|
||||
Sprite* reusedTileWithRect(Rect rect);
|
||||
int getVertexZForPos(const Point& pos);
|
||||
|
||||
// index
|
||||
ssize_t atlasIndexForExistantZ(unsigned int z);
|
||||
ssize_t atlasIndexForExistantZ(int z);
|
||||
ssize_t atlasIndexForNewZ(int z);
|
||||
|
||||
protected:
|
||||
|
@ -218,10 +218,7 @@ protected:
|
|||
std::string _layerName;
|
||||
//! TMX Layer supports opacity
|
||||
unsigned char _opacity;
|
||||
|
||||
unsigned int _minGID;
|
||||
unsigned int _maxGID;
|
||||
|
||||
|
||||
//! Only used when vertexZ is used
|
||||
int _vertexZvalue;
|
||||
bool _useAutomaticVertexZ;
|
||||
|
@ -238,11 +235,11 @@ protected:
|
|||
/** size of the map's tile (could be different from the tile's size) */
|
||||
Size _mapTileSize;
|
||||
/** pointer to the map of tiles */
|
||||
unsigned int* _tiles;
|
||||
int* _tiles;
|
||||
/** Tileset information for the layer */
|
||||
TMXTilesetInfo* _tileSet;
|
||||
/** Layer orientation, which is the same as the map orientation */
|
||||
unsigned int _layerOrientation;
|
||||
int _layerOrientation;
|
||||
/** properties from the layer. They can be added using Tiled */
|
||||
ValueMap _properties;
|
||||
};
|
||||
|
|
|
@ -122,12 +122,12 @@ TMXTilesetInfo * TMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInf
|
|||
tileset = *iter;
|
||||
if (tileset)
|
||||
{
|
||||
for( unsigned int y=0; y < size.height; y++ )
|
||||
for( int y=0; y < size.height; y++ )
|
||||
{
|
||||
for( unsigned int x=0; x < size.width; x++ )
|
||||
for( int x=0; x < size.width; x++ )
|
||||
{
|
||||
unsigned int pos = (unsigned int)(x + size.width * y);
|
||||
unsigned int gid = layerInfo->_tiles[ pos ];
|
||||
int pos = static_cast<int>(x + size.width * y);
|
||||
int gid = layerInfo->_tiles[ pos ];
|
||||
|
||||
// gid are stored in little endian.
|
||||
// if host is big endian, then swap
|
||||
|
|
|
@ -122,7 +122,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE TMXLayer* layerNamed(const char *layerName) const { return getLayer(layerName); };
|
||||
CC_DEPRECATED_ATTRIBUTE TMXLayer* layerNamed(const std::string& layerName) const { return getLayer(layerName); };
|
||||
|
||||
/** return the TMXObjectGroup for the specific group */
|
||||
TMXObjectGroup* getObjectGroup(const std::string& groupName) const;
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const char *groupName) const { return getObjectGroup(groupName); };
|
||||
CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const std::string& groupName) const { return getObjectGroup(groupName); };
|
||||
|
||||
/** return the value for the specific property name */
|
||||
Value getProperty(const std::string& propertyName) const;
|
||||
|
@ -204,7 +204,7 @@ protected:
|
|||
ValueMap _properties;
|
||||
|
||||
//! tile properties
|
||||
IntValueMap _tileProperties;
|
||||
ValueMapIntKey _tileProperties;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(TMXTiledMap);
|
||||
|
|
|
@ -43,8 +43,6 @@ TMXLayerInfo::TMXLayerInfo()
|
|||
: _name("")
|
||||
, _tiles(nullptr)
|
||||
, _ownTiles(true)
|
||||
, _minGID(100000)
|
||||
, _maxGID(0)
|
||||
, _offset(Point::ZERO)
|
||||
{
|
||||
}
|
||||
|
@ -83,7 +81,7 @@ TMXTilesetInfo::~TMXTilesetInfo()
|
|||
CCLOGINFO("deallocing TMXTilesetInfo: %p", this);
|
||||
}
|
||||
|
||||
Rect TMXTilesetInfo::rectForGID(unsigned int gid)
|
||||
Rect TMXTilesetInfo::rectForGID(int gid)
|
||||
{
|
||||
Rect rect;
|
||||
rect.size = _tileSize;
|
||||
|
@ -141,7 +139,7 @@ void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string&
|
|||
_storingCharacters = false;
|
||||
_layerAttribs = TMXLayerAttribNone;
|
||||
_parentElement = TMXPropertyNone;
|
||||
_currentFirstGID = 0;
|
||||
_currentFirstGID = -1;
|
||||
}
|
||||
bool TMXMapInfo::initWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||
{
|
||||
|
@ -160,7 +158,8 @@ TMXMapInfo::TMXMapInfo()
|
|||
, _tileSize(Size::ZERO)
|
||||
, _layerAttribs(0)
|
||||
, _storingCharacters(false)
|
||||
, _currentFirstGID(0)
|
||||
, _currentFirstGID(-1)
|
||||
, _recordFirstGID(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -265,7 +264,12 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
}
|
||||
externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename.c_str());
|
||||
|
||||
_currentFirstGID = (unsigned int)attributeDict["firstgid"].asInt();
|
||||
_currentFirstGID = attributeDict["firstgid"].asInt();
|
||||
if (_currentFirstGID < 0)
|
||||
{
|
||||
_currentFirstGID = 0;
|
||||
}
|
||||
_recordFirstGID = false;
|
||||
|
||||
tmxMapInfo->parseXMLFile(externalTilesetFilename.c_str());
|
||||
}
|
||||
|
@ -273,17 +277,25 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
{
|
||||
TMXTilesetInfo *tileset = new TMXTilesetInfo();
|
||||
tileset->_name = attributeDict["name"].asString();
|
||||
if (_currentFirstGID == 0)
|
||||
|
||||
if (_recordFirstGID)
|
||||
{
|
||||
tileset->_firstGid = (unsigned int)attributeDict["firstgid"].asInt();
|
||||
// unset before, so this is tmx file.
|
||||
tileset->_firstGid = attributeDict["firstgid"].asInt();
|
||||
|
||||
if (tileset->_firstGid < 0)
|
||||
{
|
||||
tileset->_firstGid = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tileset->_firstGid = _currentFirstGID;
|
||||
_currentFirstGID = 0;
|
||||
}
|
||||
tileset->_spacing = (unsigned int)attributeDict["spacing"].asInt();
|
||||
tileset->_margin = (unsigned int)attributeDict["margin"].asInt();
|
||||
|
||||
tileset->_spacing = attributeDict["spacing"].asInt();
|
||||
tileset->_margin = attributeDict["margin"].asInt();
|
||||
Size s;
|
||||
s.width = attributeDict["tilewidth"].asFloat();
|
||||
s.height = attributeDict["tileheight"].asFloat();
|
||||
|
@ -299,20 +311,17 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
{
|
||||
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
||||
Size layerSize = layer->_layerSize;
|
||||
unsigned int gid = (unsigned int)attributeDict["gid"].asInt();
|
||||
int gid = attributeDict["gid"].asInt();
|
||||
int tilesAmount = layerSize.width*layerSize.height;
|
||||
|
||||
do
|
||||
{
|
||||
// Check the gid is legal or not
|
||||
CC_BREAK_IF(gid == 0);
|
||||
|
||||
if (tilesAmount > 1)
|
||||
{
|
||||
// Check the value is all set or not
|
||||
CC_BREAK_IF(layer->_tiles[tilesAmount - 2] != 0 && layer->_tiles[tilesAmount - 1] != 0);
|
||||
CC_BREAK_IF(layer->_tiles[tilesAmount - 2] != -1 && layer->_tiles[tilesAmount - 1] != -1);
|
||||
|
||||
int currentTileIndex = tilesAmount - layer->_tiles[tilesAmount - 1] - 1;
|
||||
int currentTileIndex = tilesAmount - layer->_tiles[tilesAmount - 1] - 2;
|
||||
layer->_tiles[currentTileIndex] = gid;
|
||||
|
||||
if (currentTileIndex != tilesAmount - 1)
|
||||
|
@ -322,7 +331,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
}
|
||||
else if(tilesAmount == 1)
|
||||
{
|
||||
if (layer->_tiles[0] == 0)
|
||||
if (layer->_tiles[0] == -1)
|
||||
{
|
||||
layer->_tiles[0] = gid;
|
||||
}
|
||||
|
@ -333,7 +342,6 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
{
|
||||
TMXTilesetInfo* info = tmxMapInfo->getTilesets().back();
|
||||
tmxMapInfo->setParentGID(info->_firstGid + attributeDict["id"].asInt());
|
||||
//FIXME:XXX Why insert an empty dict?
|
||||
tmxMapInfo->getTileProperties()[tmxMapInfo->getParentGID()] = Value(ValueMap());
|
||||
tmxMapInfo->setParentElement(TMXPropertyTile);
|
||||
}
|
||||
|
@ -419,10 +427,8 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
int tilesAmount = layerSize.width*layerSize.height;
|
||||
|
||||
int *tiles = (int *) malloc(tilesAmount*sizeof(int));
|
||||
for (int i = 0; i < tilesAmount; i++)
|
||||
{
|
||||
tiles[i] = 0;
|
||||
}
|
||||
// set all value to -1
|
||||
memset(tiles, 0xFF, tilesAmount*sizeof(int));
|
||||
|
||||
/* Save the special index in tiles[tilesAmount - 1];
|
||||
* When we load tiles, we can do this:
|
||||
|
@ -432,10 +438,10 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
*/
|
||||
if (tilesAmount > 1)
|
||||
{
|
||||
tiles[tilesAmount - 1] = tilesAmount - 1;
|
||||
tiles[tilesAmount - 1] = tilesAmount - 2;
|
||||
}
|
||||
|
||||
layer->_tiles = (unsigned int*) tiles;
|
||||
layer->_tiles = tiles;
|
||||
}
|
||||
else if (encoding == "base64")
|
||||
{
|
||||
|
@ -536,9 +542,9 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
}
|
||||
else if ( tmxMapInfo->getParentElement() == TMXPropertyTile )
|
||||
{
|
||||
IntValueMap& dict = tmxMapInfo->getTileProperties().at(tmxMapInfo->getParentGID()).asIntKeyMap();
|
||||
ValueMap& dict = tmxMapInfo->getTileProperties().at(tmxMapInfo->getParentGID()).asValueMap();
|
||||
|
||||
int propertyName = attributeDict["name"].asInt();
|
||||
std::string propertyName = attributeDict["name"].asString();
|
||||
dict[propertyName] = attributeDict["value"];
|
||||
}
|
||||
}
|
||||
|
@ -678,11 +684,11 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
return;
|
||||
}
|
||||
|
||||
layer->_tiles = (unsigned int*) deflated;
|
||||
layer->_tiles = reinterpret_cast<int*>(deflated);
|
||||
}
|
||||
else
|
||||
{
|
||||
layer->_tiles = (unsigned int*) buffer;
|
||||
layer->_tiles = reinterpret_cast<int*>(buffer);
|
||||
}
|
||||
|
||||
tmxMapInfo->setCurrentString("");
|
||||
|
@ -693,11 +699,19 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
Size layerSize = layer->_layerSize;
|
||||
int tilesAmount = layerSize.width * layerSize.height;
|
||||
|
||||
//reset the layer->_tiles[tilesAmount - 1]
|
||||
if (tilesAmount > 1 && layer->_tiles[tilesAmount - 2] == 0)
|
||||
//set all the tiles unseted to 0
|
||||
if (tilesAmount > 1 && layer->_tiles[tilesAmount - 2] == -1)
|
||||
{
|
||||
for (int i = tilesAmount - layer->_tiles[tilesAmount - 1] - 2; i < tilesAmount; ++i)
|
||||
{
|
||||
layer->_tiles[i] = 0;
|
||||
}
|
||||
}
|
||||
else if (layer->_tiles[tilesAmount - 1] == -1)
|
||||
{
|
||||
layer->_tiles[tilesAmount - 1] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -721,6 +735,10 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
// The object element has ended
|
||||
tmxMapInfo->setParentElement(TMXPropertyNone);
|
||||
}
|
||||
else if (elementName == "tileset")
|
||||
{
|
||||
_recordFirstGID = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TMXMapInfo::textHandler(void *ctx, const char *ch, int len)
|
||||
|
|
|
@ -107,12 +107,10 @@ public:
|
|||
ValueMap _properties;
|
||||
std::string _name;
|
||||
Size _layerSize;
|
||||
unsigned int *_tiles;
|
||||
int *_tiles;
|
||||
bool _visible;
|
||||
unsigned char _opacity;
|
||||
bool _ownTiles;
|
||||
unsigned int _minGID;
|
||||
unsigned int _maxGID;
|
||||
Point _offset;
|
||||
};
|
||||
|
||||
|
@ -130,14 +128,14 @@ class CC_DLL TMXTilesetInfo : public Object
|
|||
{
|
||||
public:
|
||||
std::string _name;
|
||||
unsigned int _firstGid;
|
||||
Size _tileSize;
|
||||
unsigned int _spacing;
|
||||
unsigned int _margin;
|
||||
int _firstGid;
|
||||
Size _tileSize;
|
||||
int _spacing;
|
||||
int _margin;
|
||||
//! filename containing the tiles (should be spritesheet / texture atlas)
|
||||
std::string _sourceImage;
|
||||
//! size in pixels of the image
|
||||
Size _imageSize;
|
||||
Size _imageSize;
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
|
@ -148,7 +146,7 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual ~TMXTilesetInfo();
|
||||
Rect rectForGID(unsigned int gid);
|
||||
Rect rectForGID(int gid);
|
||||
};
|
||||
|
||||
/** @brief TMXMapInfo contains the information about the map like:
|
||||
|
@ -195,8 +193,8 @@ public:
|
|||
/* initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */
|
||||
bool parseXMLString(const std::string& xmlString);
|
||||
|
||||
IntValueMap& getTileProperties() { return _tileProperties; };
|
||||
void setTileProperties(const IntValueMap& tileProperties) {
|
||||
ValueMapIntKey& getTileProperties() { return _tileProperties; };
|
||||
void setTileProperties(const ValueMapIntKey& tileProperties) {
|
||||
_tileProperties = tileProperties;
|
||||
};
|
||||
|
||||
|
@ -238,8 +236,8 @@ public:
|
|||
inline void setParentElement(int element) { _parentElement = element; };
|
||||
|
||||
/// parent GID
|
||||
inline unsigned int getParentGID() const { return _parentGID; };
|
||||
inline void setParentGID(unsigned int gid) { _parentGID = gid; };
|
||||
inline int getParentGID() const { return _parentGID; };
|
||||
inline void setParentGID(int gid) { _parentGID = gid; };
|
||||
|
||||
/// layer attribs
|
||||
inline int getLayerAttribs() const { return _layerAttribs; };
|
||||
|
@ -296,7 +294,7 @@ protected:
|
|||
/// parent element
|
||||
int _parentElement;
|
||||
/// parent GID
|
||||
unsigned int _parentGID;
|
||||
int _parentGID;
|
||||
/// layer attribs
|
||||
int _layerAttribs;
|
||||
/// is storing characters?
|
||||
|
@ -311,8 +309,9 @@ protected:
|
|||
//! current string
|
||||
std::string _currentString;
|
||||
//! tile properties
|
||||
IntValueMap _tileProperties;
|
||||
unsigned int _currentFirstGID;
|
||||
ValueMapIntKey _tileProperties;
|
||||
int _currentFirstGID;
|
||||
bool _recordFirstGID;
|
||||
};
|
||||
|
||||
// end of tilemap_parallax_nodes group
|
||||
|
|
|
@ -209,7 +209,7 @@ void TextFieldTTF::deleteBackward()
|
|||
}
|
||||
|
||||
// get the delete byte number
|
||||
int deleteLen = 1; // default, erase 1 byte
|
||||
size_t deleteLen = 1; // default, erase 1 byte
|
||||
|
||||
while(0x80 == (0xC0 & _inputText.at(len - deleteLen)))
|
||||
{
|
||||
|
@ -236,9 +236,9 @@ void TextFieldTTF::deleteBackward()
|
|||
setString(text);
|
||||
}
|
||||
|
||||
const char * TextFieldTTF::getContentText()
|
||||
const std::string& TextFieldTTF::getContentText()
|
||||
{
|
||||
return _inputText.c_str();
|
||||
return _inputText;
|
||||
}
|
||||
|
||||
void TextFieldTTF::draw()
|
||||
|
|
|
@ -182,7 +182,7 @@ protected:
|
|||
virtual bool canDetachWithIME() override;
|
||||
virtual void insertText(const char * text, int len) override;
|
||||
virtual void deleteBackward() override;
|
||||
virtual const char * getContentText() override;
|
||||
virtual const std::string& getContentText() override;
|
||||
private:
|
||||
class LengthStack;
|
||||
LengthStack * _lens;
|
||||
|
|
|
@ -51,7 +51,7 @@ TextPageDef::~TextPageDef()
|
|||
{
|
||||
size_t numLines = _lines.size();
|
||||
|
||||
for( int c = 0; c<numLines; ++c )
|
||||
for( size_t c = 0; c<numLines; ++c )
|
||||
{
|
||||
delete _lines[c];
|
||||
}
|
||||
|
|
|
@ -673,7 +673,7 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat
|
|||
|
||||
std::string Texture2D::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<Texture2D | Name = %u | Dimensions = %ld x %ld | Coordinates = (%.2f, %.2f)>", _name, (long)_pixelsWide, (long)_pixelsHigh, _maxS, _maxT)->getCString();
|
||||
return StringUtils::format("<Texture2D | Name = %u | Dimensions = %ld x %ld | Coordinates = (%.2f, %.2f)>", _name, (long)_pixelsWide, (long)_pixelsHigh, _maxS, _maxT);
|
||||
}
|
||||
|
||||
// implementation Texture2D (Image)
|
||||
|
|
|
@ -30,7 +30,6 @@ THE SOFTWARE.
|
|||
#include "ccMacros.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "ccGLStateCache.h"
|
||||
#include "CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCGL.h"
|
||||
|
@ -39,6 +38,8 @@ THE SOFTWARE.
|
|||
#include "CCTexture2D.h"
|
||||
#include "CCString.h"
|
||||
#include <stdlib.h>
|
||||
#include "CCEventDispatcher.h"
|
||||
#include "CCEventListenerCustom.h"
|
||||
|
||||
//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong
|
||||
|
||||
|
@ -51,6 +52,9 @@ TextureAtlas::TextureAtlas()
|
|||
,_dirty(false)
|
||||
,_texture(nullptr)
|
||||
,_quads(nullptr)
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
,_backToForegroundlistener(nullptr)
|
||||
#endif
|
||||
{}
|
||||
|
||||
TextureAtlas::~TextureAtlas()
|
||||
|
@ -70,7 +74,7 @@ TextureAtlas::~TextureAtlas()
|
|||
CC_SAFE_RELEASE(_texture);
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundlistener);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -110,7 +114,7 @@ void TextureAtlas::setQuads(V3F_C4B_T2F_Quad* quads)
|
|||
|
||||
// TextureAtlas - alloc & init
|
||||
|
||||
TextureAtlas * TextureAtlas::create(const char* file, ssize_t capacity)
|
||||
TextureAtlas * TextureAtlas::create(const std::string& file, ssize_t capacity)
|
||||
{
|
||||
TextureAtlas * textureAtlas = new TextureAtlas();
|
||||
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
|
||||
|
@ -134,7 +138,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, ssize_t capac
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool TextureAtlas::initWithFile(const char * file, ssize_t capacity)
|
||||
bool TextureAtlas::initWithFile(const std::string& file, ssize_t capacity)
|
||||
{
|
||||
// retained in property
|
||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file);
|
||||
|
@ -145,7 +149,7 @@ bool TextureAtlas::initWithFile(const char * file, ssize_t capacity)
|
|||
}
|
||||
else
|
||||
{
|
||||
CCLOG("cocos2d: Could not open file: %s", file);
|
||||
CCLOG("cocos2d: Could not open file: %s", file.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -185,10 +189,8 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, ssize_t capacity)
|
|||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// listen the event when app go to background
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(TextureAtlas::listenBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
nullptr);
|
||||
_backToForegroundlistener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(TextureAtlas::listenBackToForeground, this));
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundlistener, -1);
|
||||
#endif
|
||||
|
||||
this->setupIndices();
|
||||
|
@ -207,7 +209,7 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, ssize_t capacity)
|
|||
return true;
|
||||
}
|
||||
|
||||
void TextureAtlas::listenBackToForeground(Object *obj)
|
||||
void TextureAtlas::listenBackToForeground(EventCustom* event)
|
||||
{
|
||||
if (Configuration::getInstance()->supportsShareableVAO())
|
||||
{
|
||||
|
@ -224,7 +226,7 @@ void TextureAtlas::listenBackToForeground(Object *obj)
|
|||
|
||||
std::string TextureAtlas::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<TextureAtlas | totalQuads = %zd>", _totalQuads)->getCString();
|
||||
return StringUtils::format("<TextureAtlas | totalQuads = %zd>", _totalQuads);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
class Texture2D;
|
||||
class EventCustom;
|
||||
class EventListenerCustom;
|
||||
|
||||
/**
|
||||
* @addtogroup textures
|
||||
|
@ -59,7 +61,7 @@ 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 , ssize_t capacity);
|
||||
static TextureAtlas* create(const std::string& file , ssize_t capacity);
|
||||
|
||||
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
||||
* with an initial capacity for n Quads.
|
||||
|
@ -81,7 +83,7 @@ public:
|
|||
*
|
||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||
*/
|
||||
bool initWithFile(const char* file, ssize_t capacity);
|
||||
bool initWithFile(const std::string& file, ssize_t capacity);
|
||||
|
||||
/** initializes a TextureAtlas with a previously initialized Texture2D object, and
|
||||
* with an initial capacity for Quads.
|
||||
|
@ -184,7 +186,7 @@ public:
|
|||
void drawQuads();
|
||||
/** listen the event that coming to foreground on Android
|
||||
*/
|
||||
void listenBackToForeground(Object *obj);
|
||||
void listenBackToForeground(EventCustom* event);
|
||||
|
||||
/** whether or not the array buffer of the VBO needs to be updated*/
|
||||
inline bool isDirty(void) { return _dirty; }
|
||||
|
@ -235,6 +237,10 @@ protected:
|
|||
Texture2D* _texture;
|
||||
/** Quads that are going to be rendered */
|
||||
V3F_C4B_T2F_Quad* _quads;
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
EventListenerCustom* _backToForegroundlistener;
|
||||
#endif
|
||||
};
|
||||
|
||||
// end of textures group
|
||||
|
|
|
@ -89,7 +89,7 @@ void TextureCache::purgeSharedTextureCache()
|
|||
|
||||
std::string TextureCache::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<TextureCache | Number of textures = %lu>", _textures.size() )->getCString();
|
||||
return StringUtils::format("<TextureCache | Number of textures = %zd>", _textures.size());
|
||||
}
|
||||
|
||||
void TextureCache::addImageAsync(const std::string &path, Object *target, SEL_CallFuncO selector)
|
||||
|
@ -193,13 +193,13 @@ void TextureCache::loadImage()
|
|||
|
||||
if (generateImage)
|
||||
{
|
||||
const char *filename = asyncStruct->filename.c_str();
|
||||
const std::string& filename = asyncStruct->filename;
|
||||
// generate image
|
||||
image = new Image();
|
||||
if (image && !image->initWithImageFileThreadSafe(filename))
|
||||
{
|
||||
CC_SAFE_RELEASE(image);
|
||||
CCLOG("can not load %s", filename);
|
||||
CCLOG("can not load %s", filename.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ void TextureCache::addImageAsyncCallBack(float dt)
|
|||
|
||||
Object *target = asyncStruct->target;
|
||||
SEL_CallFuncO selector = asyncStruct->selector;
|
||||
const char* filename = asyncStruct->filename.c_str();
|
||||
const std::string& filename = asyncStruct->filename;
|
||||
|
||||
Texture2D *texture = nullptr;
|
||||
if (image)
|
||||
|
@ -326,7 +326,7 @@ Texture2D * TextureCache::addImage(const std::string &path)
|
|||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// cache the texture file name
|
||||
VolatileTextureMgr::addImageTexture(texture, fullpath.c_str());
|
||||
VolatileTextureMgr::addImageTexture(texture, fullpath);
|
||||
#endif
|
||||
// texture already retained, no need to re-retain it
|
||||
_textures.insert( std::make_pair(fullpath, texture) );
|
||||
|
@ -509,7 +509,7 @@ VolatileTexture::~VolatileTexture()
|
|||
CC_SAFE_RELEASE(_uiImage);
|
||||
}
|
||||
|
||||
void VolatileTextureMgr::addImageTexture(Texture2D *tt, const char* imageFileName)
|
||||
void VolatileTextureMgr::addImageTexture(Texture2D *tt, const std::string& imageFileName)
|
||||
{
|
||||
if (_isReloading)
|
||||
{
|
||||
|
@ -629,10 +629,10 @@ void VolatileTextureMgr::reloadAllTextures()
|
|||
case VolatileTexture::kImageFile:
|
||||
{
|
||||
Image* image = new Image();
|
||||
ssize_t size = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size);
|
||||
|
||||
if (image && image->initWithImageData(pBuffer, size))
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(vt->_fileName);
|
||||
|
||||
if (image && image->initWithImageData(data.getBytes(), data.getSize()))
|
||||
{
|
||||
Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat();
|
||||
Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat);
|
||||
|
@ -640,7 +640,6 @@ void VolatileTextureMgr::reloadAllTextures()
|
|||
Texture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
|
||||
}
|
||||
|
||||
free(pBuffer);
|
||||
CC_SAFE_RELEASE(image);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -124,13 +124,13 @@ public:
|
|||
* If "key" is nil, then a new texture will be created each time.
|
||||
*/
|
||||
Texture2D* addImage(Image *image, const std::string &key);
|
||||
CC_DEPRECATED_ATTRIBUTE Texture2D* addUIImage(Image *image, const char *key) { return addImage(image,key); }
|
||||
CC_DEPRECATED_ATTRIBUTE Texture2D* addUIImage(Image *image, const std::string& key) { return addImage(image,key); }
|
||||
|
||||
/** Returns an already created texture. Returns nil if the texture doesn't exist.
|
||||
@since v0.99.5
|
||||
*/
|
||||
Texture2D* getTextureForKey(const std::string& key) const;
|
||||
CC_DEPRECATED_ATTRIBUTE Texture2D* textureForKey(const char* key) const { return getTextureForKey(key); }
|
||||
CC_DEPRECATED_ATTRIBUTE Texture2D* textureForKey(const std::string& key) const { return getTextureForKey(key); }
|
||||
|
||||
/** Purges the dictionary of loaded textures.
|
||||
* Call this method if you receive the "Memory Warning"
|
||||
|
@ -250,7 +250,7 @@ protected:
|
|||
class VolatileTextureMgr
|
||||
{
|
||||
public:
|
||||
static void addImageTexture(Texture2D *tt, const char* imageFileName);
|
||||
static void addImageTexture(Texture2D *tt, const std::string& imageFileName);
|
||||
static void addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition);
|
||||
static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize);
|
||||
static void addImage(Texture2D *tt, Image *image);
|
||||
|
|
|
@ -30,6 +30,7 @@ THE SOFTWARE.
|
|||
#include "CCActionGrid.h"
|
||||
#include "CCActionPageTurn3D.h"
|
||||
#include "CCNodeGrid.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -78,24 +79,43 @@ void TransitionPageTurn::sceneOrder()
|
|||
_isInSceneOnTop = _back;
|
||||
}
|
||||
|
||||
void TransitionPageTurn::onEnablePolygonOffset()
|
||||
{
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_UNITS);
|
||||
}
|
||||
|
||||
void TransitionPageTurn::onDisablePolygonOffset()
|
||||
{
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0, 0);
|
||||
}
|
||||
|
||||
void TransitionPageTurn::draw()
|
||||
{
|
||||
Scene::draw();
|
||||
|
||||
if( _isInSceneOnTop ) {
|
||||
_outSceneProxy->visit();
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_UNITS);
|
||||
_enableOffsetCmd.init(0, _vertexZ);
|
||||
_enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd);
|
||||
_inSceneProxy->visit();
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0, 0);
|
||||
_disableOffsetCmd.init(0, _vertexZ);
|
||||
_disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd);
|
||||
} else {
|
||||
_inSceneProxy->visit();
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_UNITS);
|
||||
|
||||
_enableOffsetCmd.init(0, _vertexZ);
|
||||
_enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd);
|
||||
|
||||
_outSceneProxy->visit();
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0, 0);
|
||||
|
||||
_disableOffsetCmd.init(0, _vertexZ);
|
||||
_disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
|||
#define __CCPAGE_TURN_TRANSITION_H__
|
||||
|
||||
#include "CCTransition.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -96,6 +97,12 @@ protected:
|
|||
bool _back;
|
||||
static float POLYGON_OFFSET_FACTOR;
|
||||
static float POLYGON_OFFSET_UNITS;
|
||||
|
||||
protected:
|
||||
CustomCommand _enableOffsetCmd;
|
||||
CustomCommand _disableOffsetCmd;
|
||||
void onEnablePolygonOffset();
|
||||
void onDisablePolygonOffset();
|
||||
};
|
||||
|
||||
// end of transition group
|
||||
|
|
|
@ -57,17 +57,16 @@ 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");
|
||||
ssize_t nSize;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(nullptr == pXmlBuffer)
|
||||
|
||||
std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath());
|
||||
|
||||
if (xmlBuffer.empty())
|
||||
{
|
||||
CCLOG("can not read xml file");
|
||||
break;
|
||||
}
|
||||
xmlDoc->Parse(pXmlBuffer, nSize);
|
||||
free(pXmlBuffer);
|
||||
xmlDoc->Parse(xmlBuffer.c_str(), xmlBuffer.size());
|
||||
|
||||
// get root node
|
||||
*rootNode = xmlDoc->RootElement();
|
||||
if (nullptr == *rootNode)
|
||||
|
@ -288,12 +287,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul
|
|||
return ret;
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey)
|
||||
Data UserDefault::getDataForKey(const char* pKey)
|
||||
{
|
||||
return getDataForKey(pKey, nullptr);
|
||||
return getDataForKey(pKey, Data::Null);
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
||||
Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||
{
|
||||
const char* encodedData = nullptr;
|
||||
tinyxml2::XMLElement* rootNode;
|
||||
|
@ -306,7 +305,7 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
encodedData = (const char*)(node->FirstChild()->Value());
|
||||
}
|
||||
|
||||
Data* ret = defaultValue;
|
||||
Data ret = defaultValue;
|
||||
|
||||
if (encodedData)
|
||||
{
|
||||
|
@ -314,9 +313,7 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData);
|
||||
|
||||
if (decodedData) {
|
||||
ret = Data::create(decodedData, decodedDataLen);
|
||||
|
||||
free(decodedData);
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,12 +104,12 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Data* getDataForKey(const char* pKey);
|
||||
Data getDataForKey(const char* pKey);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Data* getDataForKey(const char* pKey, Data* defaultValue);
|
||||
Data getDataForKey(const char* pKey, const Data& defaultValue);
|
||||
|
||||
// set value methods
|
||||
|
||||
|
|
|
@ -73,16 +73,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
|||
{
|
||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
ssize_t size;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(nullptr == pXmlBuffer)
|
||||
|
||||
std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath());
|
||||
|
||||
if (xmlBuffer.empty())
|
||||
{
|
||||
NSLog(@"can not read xml file");
|
||||
break;
|
||||
}
|
||||
xmlDoc->Parse(pXmlBuffer);
|
||||
free(pXmlBuffer);
|
||||
xmlDoc->Parse(xmlBuffer.c_str(), xmlBuffer.size());
|
||||
|
||||
// get root node
|
||||
rootNode = xmlDoc->RootElement();
|
||||
if (nullptr == rootNode)
|
||||
|
@ -363,12 +363,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul
|
|||
}
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey)
|
||||
Data UserDefault::getDataForKey(const char* pKey)
|
||||
{
|
||||
return getDataForKey(pKey, nullptr);
|
||||
return getDataForKey(pKey, Data::Null);
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
||||
Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||
{
|
||||
#ifdef KEEP_COMPATABILITY
|
||||
tinyxml2::XMLDocument* doc = nullptr;
|
||||
|
@ -382,13 +382,12 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData);
|
||||
|
||||
if (decodedData) {
|
||||
Data *ret = Data::create(decodedData, decodedDataLen);
|
||||
Data ret;
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
|
||||
// set value in NSUserDefaults
|
||||
setDataForKey(pKey, ret);
|
||||
|
||||
free(decodedData);
|
||||
|
||||
flush();
|
||||
|
||||
// delete xmle node
|
||||
|
@ -412,17 +411,8 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
}
|
||||
else
|
||||
{
|
||||
unsigned char *bytes = {0};
|
||||
int size = 0;
|
||||
|
||||
if (data.length > 0) {
|
||||
bytes = (unsigned char*)data.bytes;
|
||||
size = static_cast<int>(data.length);
|
||||
}
|
||||
Data *ret = new Data(bytes, size);
|
||||
|
||||
ret->autorelease();
|
||||
|
||||
Data ret;
|
||||
ret.copy((unsigned char*)data.bytes, data.length);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,15 +75,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
|||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
ssize_t size;
|
||||
char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(nullptr == pXmlBuffer)
|
||||
|
||||
std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath().c_str());
|
||||
|
||||
if (xmlBuffer.empty())
|
||||
{
|
||||
CCLOG("can not read xml file");
|
||||
break;
|
||||
}
|
||||
xmlDoc->Parse(pXmlBuffer);
|
||||
free(pXmlBuffer);
|
||||
xmlDoc->Parse(xmlBuffer.c_str());
|
||||
|
||||
// get root node
|
||||
rootNode = xmlDoc->RootElement();
|
||||
if (nullptr == rootNode)
|
||||
|
@ -335,12 +336,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul
|
|||
return getStringForKeyJNI(pKey, defaultValue.c_str());
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey)
|
||||
Data UserDefault::getDataForKey(const char* pKey)
|
||||
{
|
||||
return getDataForKey(pKey, nullptr);
|
||||
return getDataForKey(pKey, Data::Null);
|
||||
}
|
||||
|
||||
Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
||||
Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||
{
|
||||
#ifdef KEEP_COMPATABILITY
|
||||
tinyxml2::XMLDocument* doc = nullptr;
|
||||
|
@ -355,12 +356,12 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData);
|
||||
|
||||
if (decodedData) {
|
||||
Data *ret = Data::create(decodedData, decodedDataLen);
|
||||
Data ret;
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
|
||||
// set value in NSUserDefaults
|
||||
setDataForKey(pKey, ret);
|
||||
|
||||
free(decodedData);
|
||||
flush();
|
||||
|
||||
// delete xmle node
|
||||
|
@ -377,8 +378,8 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
}
|
||||
#endif
|
||||
|
||||
char * encodedDefaultData = nullptr;
|
||||
unsigned int encodedDefaultDataLen = defaultValue ? base64Encode(defaultValue->getBytes(), defaultValue->getSize(), &encodedDefaultData) : 0;
|
||||
char * encodedDefaultData = NULL;
|
||||
unsigned int encodedDefaultDataLen = !defaultValue.isNull() ? base64Encode(defaultValue.getBytes(), defaultValue.getSize(), &encodedDefaultData) : 0;
|
||||
|
||||
string encodedStr = getStringForKeyJNI(pKey, encodedDefaultData);
|
||||
|
||||
|
@ -386,23 +387,19 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue)
|
|||
free(encodedDefaultData);
|
||||
|
||||
CCLOG("ENCODED STRING: --%s--%d", encodedStr.c_str(), encodedStr.length());
|
||||
|
||||
Data *ret = defaultValue;
|
||||
|
||||
unsigned char * decodedData = nullptr;
|
||||
|
||||
unsigned char * decodedData = NULL;
|
||||
int decodedDataLen = base64Decode((unsigned char*)encodedStr.c_str(), (unsigned int)encodedStr.length(), &decodedData);
|
||||
|
||||
CCLOG("AFTER DECoDE. ret %p defaultValue %p", ret, defaultValue);
|
||||
CCLOG("DECoDED DATA: %s %d", decodedData, decodedDataLen);
|
||||
CCLOG("DECODED DATA: %s %d", decodedData, decodedDataLen);
|
||||
|
||||
if (decodedData && decodedDataLen) {
|
||||
ret = Data::create(decodedData, decodedDataLen);
|
||||
free(decodedData);
|
||||
Data ret;
|
||||
ret.fastSet(decodedData, decodedDataLen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCLOG("RETURNED %p!", ret);
|
||||
|
||||
return ret;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "TGAlib.h"
|
||||
#include "CCData.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -272,15 +273,11 @@ tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size)
|
|||
// this is the function to call when we want to load an image
|
||||
tImageTGA * tgaLoad(const char *filename)
|
||||
{
|
||||
ssize_t size = 0;
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(filename);
|
||||
|
||||
if (buffer != nullptr)
|
||||
if (!data.isNull())
|
||||
{
|
||||
tImageTGA* data = tgaLoadBuffer(buffer, size);
|
||||
free(buffer);
|
||||
|
||||
return data;
|
||||
return tgaLoadBuffer(data.getBytes(), data.getSize());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "ZipUtils.h"
|
||||
#include "CCData.h"
|
||||
#include "ccMacros.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "unzip.h"
|
||||
|
@ -304,21 +305,15 @@ int ZipUtils::inflateGZipFile(const char *path, unsigned char **out)
|
|||
bool ZipUtils::isCCZFile(const char *path)
|
||||
{
|
||||
// load file into memory
|
||||
unsigned char* compressed = nullptr;
|
||||
Data compressedData = FileUtils::getInstance()->getDataFromFile(path);
|
||||
|
||||
ssize_t fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(compressed == nullptr || fileLen == 0)
|
||||
if (compressedData.isNull())
|
||||
{
|
||||
CCLOG("cocos2d: ZipUtils: loading file failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = isCCZBuffer(compressed, fileLen);
|
||||
free(compressed);
|
||||
|
||||
return ret;
|
||||
return isCCZBuffer(compressedData.getBytes(), compressedData.getSize());
|
||||
}
|
||||
|
||||
bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len)
|
||||
|
@ -336,20 +331,15 @@ bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len)
|
|||
bool ZipUtils::isGZipFile(const char *path)
|
||||
{
|
||||
// load file into memory
|
||||
unsigned char* compressed = nullptr;
|
||||
Data compressedData = FileUtils::getInstance()->getDataFromFile(path);
|
||||
|
||||
ssize_t fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(nullptr == compressed || 0 == fileLen)
|
||||
if (compressedData.isNull())
|
||||
{
|
||||
CCLOG("cocos2d: ZipUtils: loading file failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = isGZipBuffer(compressed, fileLen);
|
||||
free(compressed);
|
||||
return ret;
|
||||
return isGZipBuffer(compressedData.getBytes(), compressedData.getSize());
|
||||
}
|
||||
|
||||
bool ZipUtils::isGZipBuffer(const unsigned char *buffer, ssize_t len)
|
||||
|
@ -455,24 +445,18 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, ssize_t bufferLen, u
|
|||
|
||||
int ZipUtils::inflateCCZFile(const char *path, unsigned char **out)
|
||||
{
|
||||
CCAssert(out, "");
|
||||
CCAssert(&*out, "");
|
||||
CCASSERT(out, "Invalid pointer for buffer!");
|
||||
|
||||
// load file into memory
|
||||
unsigned char* compressed = nullptr;
|
||||
Data compressedData = FileUtils::getInstance()->getDataFromFile(path);
|
||||
|
||||
ssize_t fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(nullptr == compressed || 0 == fileLen)
|
||||
if (compressedData.isNull())
|
||||
{
|
||||
CCLOG("cocos2d: Error loading CCZ compressed file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = inflateCCZBuffer(compressed, fileLen, out);
|
||||
free(compressed);
|
||||
return ret;
|
||||
return inflateCCZBuffer(compressedData.getBytes(), compressedData.getSize(), out);
|
||||
}
|
||||
|
||||
void ZipUtils::setPvrEncryptionKeyPart(int index, unsigned int value)
|
||||
|
|
|
@ -268,7 +268,7 @@ To enable set it to a value different than 0. Disabled by default.
|
|||
|
||||
/** Use physics integration API */
|
||||
#ifndef CC_USE_PHYSICS
|
||||
#define CC_USE_PHYSICS
|
||||
#define CC_USE_PHYSICS 1
|
||||
#endif
|
||||
|
||||
#endif // __CCCONFIG_H__
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "ccTypes.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
const std::string STD_STRING_EMPTY("");
|
||||
|
||||
/**
|
||||
* Color3B
|
||||
|
|
|
@ -471,6 +471,8 @@ public:
|
|||
Acceleration(): x(0), y(0), z(0), timestamp(0) {}
|
||||
};
|
||||
|
||||
extern const std::string STD_STRING_EMPTY;
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCTYPES_H__
|
||||
|
|
|
@ -30,7 +30,7 @@ NS_CC_BEGIN
|
|||
|
||||
const char* cocos2dVersion()
|
||||
{
|
||||
return "3.0-beta0-pre";
|
||||
return "3.0-beta";
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue