Skip to content

Commit

Permalink
Improve backward compabilty
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Jun 28, 2017
1 parent 0ed7515 commit ce98f48
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cocos2dx/CCDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class CC_DLL Director : public Object, public TypeInfo
/** returns the size of the OpenGL view in points.
*/
const Size& getWinSize(void) const;
const Size& getVirtualViewSize(void) const {
return getWinSize();
}

/** returns the size of the OpenGL view in pixels.
*/
Expand Down Expand Up @@ -384,6 +387,8 @@ class CC_DLL Director : public Object, public TypeInfo
/* Gets delta time since last tick to main loop */
float getDeltaTime() const;

Scene* getNextScene() { return _nextScene; }

protected:
void purgeDirector();
bool _purgeDirecotorInNextLoop; // this flag will be set to true in end()
Expand Down
8 changes: 8 additions & 0 deletions cocos2dx/base_nodes/CCNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,14 @@ class CC_DLL Node : public Object
virtual void removeAllComponents();
/// @} end of component functions

bool isTransformDirty() const {
return _transformDirty;
}

const AffineTransform& getTransformStored() const {
return _transform;
}

private:
/// lazy allocs
void childrenAlloc(void);
Expand Down
3 changes: 3 additions & 0 deletions cocos2dx/cocoa/CCString.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ class CC_DLL String : public Object, public Clonable
* it means that you needn't do a release operation unless you retain it.
*/
static String* createWithContentsOfFile(const char* filename);
static String* createWithContentsOfFile(const std::string &filename) {
return createWithContentsOfFile(filename.c_str());
}

virtual void acceptVisitor(DataVisitor &visitor);
virtual String* clone() const;
Expand Down
65 changes: 64 additions & 1 deletion cocos2dx/include/CCDeprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,58 @@
#define __COCOS2D_CCDEPRECATED_H__

#include <math.h>
#include <actions/CCActionCamera.h>
#include <actions/CCActionCatmullRom.h>
#include <actions/CCActionEase.h>
#include <actions/CCActionGrid.h>
#include <actions/CCActionGrid3D.h>
#include <actions/CCActionInstant.h>
#include <actions/CCActionPageTurn3D.h>
#include <actions/CCActionProgressTimer.h>
#include <actions/CCActionTiledGrid.h>
#include <actions/CCActionTween.h>
#include <text_input_node/CCIMEDelegate.h>
#include <text_input_node/CCTextFieldTTF.h>
#include <support/user_default/CCUserDefault.h>
#include <ccTypes.h>
#include <CCAffineTransform.h>
#include <CCAccelerometerDelegate.h>
#include <textures/CCTextureAtlas.h>
#include <textures/CCTextureCache.h>
#include <CCApplication.h>
#include <CCConfiguration.h>
#include <CCFileUtils.h>
#include <draw_nodes/CCDrawNode.h>
#include <base_nodes/CCAtlasNode.h>
#include <label_nodes/CCLabelAtlas.h>
#include <label_nodes/CCLabelBMFont.h>
#include <effects/CCGrid.h>
#include <keypad_dispatcher/CCKeypadDelegate.h>
#include <layers_scenes_transitions_nodes/CCLayer.h>
#include <layers_scenes_transitions_nodes/CCTransition.h>
#include <layers_scenes_transitions_nodes/CCTransitionPageTurn.h>
#include <layers_scenes_transitions_nodes/CCTransitionProgress.h>
#include <menu_nodes/CCMenu.h>
#include <menu_nodes/CCMenuItem.h>
#include <misc_nodes/CCClippingNode.h>
#include <misc_nodes/CCMotionStreak.h>
#include <particle_nodes/CCParticleBatchNode.h>
#include <particle_nodes/CCParticleExamples.h>
#include <particle_nodes/CCParticleSystemQuad.h>
#include <shaders/CCShaderCache.h>
#include <sprite_nodes/CCAnimationCache.h>
#include <sprite_nodes/CCSpriteFrameCache.h>
#include <tilemap_parallax_nodes/CCParallaxNode.h>
#include <tilemap_parallax_nodes/CCTMXLayer.h>
#include <tilemap_parallax_nodes/CCTMXObjectGroup.h>
#include <tilemap_parallax_nodes/CCTMXTiledMap.h>
#include <tilemap_parallax_nodes/CCTMXXMLParser.h>
#include <tilemap_parallax_nodes/CCTileMapAtlas.h>
#include <misc_nodes/CCProgressTimer.h>
#include <CCScheduler.h>
#include <platform/CCEGLViewProtocol.h>
#include "cocoa/CCGeometry.h"
#include "ccTypes.h"


NS_CC_BEGIN

Expand Down Expand Up @@ -408,6 +458,7 @@ CC_DEPRECATED_ATTRIBUTE extern const Color3B ccMAGENTA;
CC_DEPRECATED_ATTRIBUTE extern const Color3B ccBLACK;
CC_DEPRECATED_ATTRIBUTE extern const Color3B ccORANGE;
CC_DEPRECATED_ATTRIBUTE extern const Color3B ccGRAY;
static const Color3B ccDARKGRAY = {88,88,88};

CC_DEPRECATED_ATTRIBUTE extern const BlendFunc kCCBlendFuncDisable;

Expand Down Expand Up @@ -448,6 +499,18 @@ CC_DEPRECATED_ATTRIBUTE static inline Color4B ccc4BFromccc4F(Color4F c)
return Color4B((GLubyte)(c.r*255), (GLubyte)(c.g*255), (GLubyte)(c.b*255), (GLubyte)(c.a*255));
}

CC_DEPRECATED_ATTRIBUTE static inline Color4B ccc4BFromccc3B(Color3B c)
{
Color4B ret = {c.r, c.g, c.b, 255};
return ret;
}

CC_DEPRECATED_ATTRIBUTE static inline Color4B ccc4BFromccc3B(Color3B c, GLubyte alpha)
{
Color4B ret = {c.r, c.g, c.b, alpha};
return ret;
}

CC_DEPRECATED_ATTRIBUTE static inline bool ccc4FEqual(Color4F a, Color4F b)
{
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
Expand Down
20 changes: 20 additions & 0 deletions cocos2dx/include/ccTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ struct Quad3 {
Vertex3F tr;
};

//! a Point with a vertex point and a color 4B
typedef struct _ccV2F_C4B
{
//! vertices (2F)
Vertex2F vertices;
//! colors (4B)
Color4B colors;
} ccV2F_C4B;

//! A Triangle of ccV2F_C4B_T2F
typedef struct _ccV2F_C4B_Triangle
{
//! Point A
ccV2F_C4B a;
//! Point B
ccV2F_C4B b;
//! Point B
ccV2F_C4B c;
} ccV2F_C4B_Triangle;

//! a Point with a vertex point, a tex coord point and a color 4B
struct V2F_C4B_T2F
{
Expand Down
22 changes: 22 additions & 0 deletions cocos2dx/label_nodes/CCLabelBMFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,29 @@ class CC_DLL LabelBMFont : public SpriteBatchNode, public LabelProtocol, public

/** creates a bitmap font atlas with an initial string and the FNT file */
static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment, Point imageOffset);

static LabelBMFont * create(const std::string &str, const std::string &fntFile, float width, TextHAlignment alignment, Point imageOffset) {
return create(str.c_str(), fntFile.c_str(), width, alignment, imageOffset);
}

static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment);

static LabelBMFont * create(const std::string &str, const std::string &fntFile, float width, TextHAlignment alignment) {
return create(str.c_str(), fntFile.c_str(), width, alignment);
}

static LabelBMFont * create(const char *str, const char *fntFile, float width);

static LabelBMFont * create(const std::string &str, const std::string &fntFile, float width) {
return create(str.c_str(), fntFile.c_str(), width);
}

static LabelBMFont * create(const char *str, const char *fntFile);

static LabelBMFont * create(const std::string &str, const std::string &fntFile) {
return create(str.c_str(), fntFile.c_str());
}

/** Creates an label.
*/
static LabelBMFont * create();
Expand All @@ -213,6 +229,12 @@ class CC_DLL LabelBMFont : public SpriteBatchNode, public LabelProtocol, public
// super method
virtual void setString(const char *newString);
virtual void setString(const char *newString, bool needUpdateLabel);
virtual void setString(const std::string &newString) {
setString(newString.c_str());
}
virtual void setString(const std::string &newString, bool needUpdateLabel) {
setString(newString.c_str(), needUpdateLabel);
}

virtual const char* getString(void) const;
virtual void setCString(const char *label);
Expand Down
13 changes: 13 additions & 0 deletions cocos2dx/menu_nodes/CCMenuItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ class CC_DLL MenuItem : public NodeRGBA
/** set the target/selector of the menu item*/
CC_DEPRECATED_ATTRIBUTE void setTarget(Object *rec, SEL_MenuHandler selector);

virtual void extendTouchArea(float extensionPercent) {
//@caiiiycuk
printf("need to implement\n");
}

void extendTouchAreaY(float extensionPercent) {
//@caiiiycuk
printf("need to implement\n");
}

protected:
bool _selected;
bool _enabled;
Expand Down Expand Up @@ -141,6 +151,9 @@ class CC_DLL MenuItemLabel : public MenuItem

/** sets a new string to the inner label */
void setString(const char * label);
void setString(const std::string& label) {
setString(label.c_str());
}

/** Gets the color that will be used to disable the item */
inline const Color3B& getDisabledColor() const { return _disabledColor; };
Expand Down
3 changes: 3 additions & 0 deletions cocos2dx/particle_nodes/CCParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ ParticleSystem::ParticleSystem()
, _blendFunc(BlendFunc::ALPHA_PREMULTIPLIED)
, _opacityModifyRGB(false)
, _positionType(PositionType::FREE)
, _spawnedParticle(false)
{
modeA.gravity = Point::ZERO;
modeA.speed = 0;
Expand Down Expand Up @@ -450,6 +451,8 @@ ParticleSystem::~ParticleSystem()

bool ParticleSystem::addParticle()
{
_spawnedParticle = true;

if (this->isFull())
{
return false;
Expand Down
5 changes: 5 additions & 0 deletions cocos2dx/particle_nodes/CCParticleSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ class CC_DLL ParticleSystem : public Node, public TextureProtocol
virtual void setTexture(Texture2D *texture) override;
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
virtual const BlendFunc &getBlendFunc() const override;

int getAllocatedParticles() { return _allocatedParticles; }
float hasSpawnedParticle() { return _spawnedParticle; }
protected:
virtual void updateBlendFunc();

Expand Down Expand Up @@ -528,6 +531,8 @@ class CC_DLL ParticleSystem : public Node, public TextureProtocol
@since v0.8
*/
PositionType _positionType;

bool _spawnedParticle;
};

// end of particle_nodes group
Expand Down
11 changes: 11 additions & 0 deletions cocos2dx/particle_nodes/CCParticleSystemQuad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ THE SOFTWARE.

NS_CC_BEGIN

bool ParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles, ParticleBatchNode* batchNode, Rect rect) {
//@caiiiycuk
_batchNode = batchNode;
if (ParticleSystem::initWithTotalParticles(numberOfParticles)) {
setBatchNode(_batchNode);
initTexCoordsWithRect(rect);
return true;
}
return false;
}

//implementation ParticleSystemQuad
// overriding the init method
bool ParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles)
Expand Down
1 change: 1 addition & 0 deletions cocos2dx/particle_nodes/CCParticleSystemQuad.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class CC_DLL ParticleSystemQuad : public ParticleSystem

// Overrides
virtual bool initWithTotalParticles(unsigned int numberOfParticles) override;
virtual bool initWithTotalParticles(unsigned int numberOfParticles, ParticleBatchNode* batchNode, Rect rect);
virtual void setTexture(Texture2D* texture) override;
virtual void updateQuadWithParticle(tParticle* particle, const Point& newPosition) override;
virtual void postStep() override;
Expand Down
5 changes: 4 additions & 1 deletion cocos2dx/sprite_nodes/CCSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class CC_DLL Sprite : public NodeRGBA, public TextureProtocol
*/
static Sprite* createWithSpriteFrameName(const char *spriteFrameName);

static Sprite* createWithSpriteFrameName(std::string& spriteFrameName) {
static Sprite* createWithSpriteFrameName(const std::string& spriteFrameName) {
return createWithSpriteFrameName(spriteFrameName.c_str());
}

Expand Down Expand Up @@ -238,6 +238,9 @@ class CC_DLL Sprite : public NodeRGBA, public TextureProtocol
* @return true if the sprite is initialized properly, false otherwise.
*/
virtual bool initWithSpriteFrameName(const char *spriteFrameName);
virtual bool initWithSpriteFrameName(const std::string &spriteFrameName) {
return initWithSpriteFrameName(spriteFrameName.c_str());
}

/**
* Initializes a sprite with an image filename.
Expand Down
9 changes: 9 additions & 0 deletions cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,15 @@ SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const char *pszName)
}
}
}

if (!frame) {
const char* subpath = strstr(pszName, "/") + 1;
if (subpath) {
return getSpriteFrameByName(subpath);
}
abort();
}

return frame;
}

Expand Down
7 changes: 7 additions & 0 deletions cocos2dx/sprite_nodes/CCSpriteFrameCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class CC_DLL SpriteFrameCache : public Object
* If you want to use another texture, you should use the addSpriteFramesWithFile(const char *plist, const char *textureFileName) method.
*/
void addSpriteFramesWithFile(const char *plist);
void addSpriteFramesWithFile(const std::string &plist) {
addSpriteFramesWithFile(plist.c_str());
}

/** Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames.
@since v0.99.5
Expand Down Expand Up @@ -121,6 +124,9 @@ class CC_DLL SpriteFrameCache : public Object
* @since v0.99.5
*/
void removeSpriteFramesFromFile(const char* plist);
void removeSpriteFramesFromFile(const std::string &plist) {
removeSpriteFramesFromFile(plist.c_str());
}

/** Removes all Sprite Frames associated with the specified textures.
* It is convenient to call this method when a specific texture needs to be removed.
Expand All @@ -139,6 +145,7 @@ class CC_DLL SpriteFrameCache : public Object

/** @deprecated use getSpriteFrameByName() instead */
CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const char *name) { return getSpriteFrameByName(name); }
CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const std::string &name) { return getSpriteFrameByName(name.c_str()); }

private:
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
Expand Down
9 changes: 9 additions & 0 deletions cocos2dx/textures/CCTextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class CC_DLL TextureCache : public Object
* Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
*/
Texture2D* addImage(const char* fileimage);
Texture2D* addImage(const std::string& fileimage) {
return addImage(fileimage.c_str());
}

/* Returns a Texture2D object given a file image
* If the file image was not previously loaded, it will create a new Texture2D object and it will return it.
Expand All @@ -114,6 +117,9 @@ class CC_DLL TextureCache : public Object
@since v0.99.5
*/
Texture2D* textureForKey(const char* key);
Texture2D* textureForKey(const std::string &key) {
return textureForKey(key.c_str());
}

/** Purges the dictionary of loaded textures.
* Call this method if you receive the "Memory Warning"
Expand All @@ -138,6 +144,9 @@ class CC_DLL TextureCache : public Object
@since v0.99.4
*/
void removeTextureForKey(const char *textureKeyName);
void removeTextureForKey(const std::string &textureKeyName) {
removeTextureForKey(textureKeyName.c_str());
}

/** Output to CCLOG the current contents of this TextureCache
* This will attempt to calculate the size of each texture, and the total texture memory in use
Expand Down
Loading

0 comments on commit ce98f48

Please sign in to comment.