mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' into local_z_Order_fixes
Conflicts: cocos/2d/CCNode.cpp cocos/2d/CCNode.h
This commit is contained in:
commit
7a8707cb08
4
AUTHORS
4
AUTHORS
|
@ -718,9 +718,13 @@ Developers:
|
|||
|
||||
Pisces000221
|
||||
Corrected a few mistakes in the README file of project-creator.
|
||||
Corrected a mistake in README.
|
||||
|
||||
hbbalfred
|
||||
Fixed a bug that crash if file doesn't exist when using FileUtils::getStringFromFile.
|
||||
|
||||
liang8305
|
||||
Use multiple processes according the number of cores to build android project
|
||||
|
||||
Retired Core Developers:
|
||||
WenSheng Yang
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
cocos2d-x-3.0beta2 ?.? ?
|
||||
[All]
|
||||
[NEW] Adds performance test for Containers(Vector<>, Array, Map<K,V>, Dictionary).
|
||||
[NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier.
|
||||
[NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands
|
||||
[NEW] GLCache: glActiveTexture() is cached with GL::activeTexture(). All code MUST call the cached version in order to work correctly
|
||||
|
@ -9,6 +10,7 @@ cocos2d-x-3.0beta2 ?.? ?
|
|||
[NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10%
|
||||
[NEW] LuaBindings: Bindings-generator supports to bind namespace for lua.
|
||||
|
||||
[FIX] Wrong arithmetic of child's position in ParallaxNode::addChild()
|
||||
[FIX] CocoStudio: TestColliderDetector in ArmatureTest can't work.
|
||||
[FIX] Crash if file doesn't exist when using FileUtils::getStringFromFile.
|
||||
[FIX] If setting a shorter string than before while using LabelAtlas, the effect will be wrong.
|
||||
|
|
|
@ -24,12 +24,12 @@ How to start a new game
|
|||
|
||||
1. Download the code from [cocos2d download site][4]
|
||||
2. Enter `tools/project-creator`
|
||||
3. Run the `create-projects.py` script
|
||||
3. Run the `create_project.py` script
|
||||
|
||||
Example:
|
||||
|
||||
$ cd cocos2d-x/tools/project-creator
|
||||
$ ./project-creator.py -n mygame -k com.your_company.mygame -l cpp -p /home/mygame
|
||||
$ ./create_project.py -n mygame -k com.your_company.mygame -l cpp -p /home/mygame
|
||||
$ cd /home/mygame
|
||||
|
||||
### Build new project for android ###
|
||||
|
|
|
@ -12,6 +12,16 @@ LUA_SAMPLES = ['hellolua', 'testlua']
|
|||
JSB_SAMPLES = ['cocosdragon', 'crystalcraze', 'moonwarriors', 'testjavascript', 'watermelonwithme']
|
||||
ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES + JSB_SAMPLES
|
||||
|
||||
def get_num_of_cpu():
|
||||
''' The build process can be accelerated by running multiple concurrent job processes using the -j-option.
|
||||
'''
|
||||
try:
|
||||
from numpy.distutils import cpuinfo
|
||||
return cpuinfo.cpu._getNCPUs()
|
||||
except Exception:
|
||||
print "Can't know cpuinfo, use default 1 cpu"
|
||||
return 1
|
||||
|
||||
def check_environment_variables():
|
||||
''' Checking the environment NDK_ROOT, which will be used for building
|
||||
'''
|
||||
|
@ -94,10 +104,12 @@ def do_build(cocos_root, ndk_root, app_android_root, ndk_build_param,sdk_root,an
|
|||
else:
|
||||
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
|
||||
|
||||
num_of_cpu = get_num_of_cpu()
|
||||
if ndk_build_param == None:
|
||||
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
|
||||
command = '%s -j%d -C %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_module_path)
|
||||
else:
|
||||
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ndk_build_param, ndk_module_path)
|
||||
command = '%s -j%d -C %s %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_build_param, ndk_module_path)
|
||||
print command
|
||||
if os.system(command) != 0:
|
||||
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
|
||||
elif android_platform is not None:
|
||||
|
|
|
@ -1 +1 @@
|
|||
63e6598ea5798bf42bbd22c2295e65f7c739695a
|
||||
df164052374ec5c6ec61d99f36a20cc99638b631
|
|
@ -1 +1 @@
|
|||
447e7ba37294e6da0df2e02f5a62f30fb15e3272
|
||||
986d41d9721f8079f005999caa9fb0053ea11321
|
|
@ -50,8 +50,6 @@ CCFont.cpp \
|
|||
CCFontCharMap.cpp \
|
||||
CCFontAtlas.cpp \
|
||||
CCFontAtlasCache.cpp \
|
||||
CCFontAtlasFactory.cpp \
|
||||
CCFontDefinition.cpp \
|
||||
CCFontFNT.cpp \
|
||||
CCFontFreeType.cpp \
|
||||
ccFPSImages.c \
|
||||
|
@ -91,7 +89,6 @@ CCSpriteBatchNode.cpp \
|
|||
CCSpriteFrame.cpp \
|
||||
CCSpriteFrameCache.cpp \
|
||||
CCTextFieldTTF.cpp \
|
||||
CCTextImage.cpp \
|
||||
CCTexture2D.cpp \
|
||||
CCTextureAtlas.cpp \
|
||||
CCTextureCache.cpp \
|
||||
|
|
|
@ -252,7 +252,7 @@ void ClippingNode::visit()
|
|||
{
|
||||
auto node = _children.at(i);
|
||||
|
||||
if ( node && node->getZOrder() < 0 )
|
||||
if ( node && node->getLocalZOrder() < 0 )
|
||||
node->visit();
|
||||
else
|
||||
break;
|
||||
|
|
|
@ -165,9 +165,6 @@ bool Director::init(void)
|
|||
_renderer = new Renderer;
|
||||
_console = new Console;
|
||||
|
||||
// create autorelease pool
|
||||
PoolManager::sharedPoolManager()->push();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -193,9 +190,8 @@ Director::~Director(void)
|
|||
delete _renderer;
|
||||
delete _console;
|
||||
|
||||
// pop the autorelease pool
|
||||
PoolManager::sharedPoolManager()->pop();
|
||||
PoolManager::purgePoolManager();
|
||||
// clean auto release pool
|
||||
PoolManager::destroyInstance();
|
||||
|
||||
// delete _lastUpdate
|
||||
CC_SAFE_DELETE(_lastUpdate);
|
||||
|
@ -1049,7 +1045,7 @@ void DisplayLinkDirector::mainLoop()
|
|||
drawScene();
|
||||
|
||||
// release the objects
|
||||
PoolManager::sharedPoolManager()->pop();
|
||||
PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ EventDispatcher::~EventDispatcher()
|
|||
removeAllEventListeners();
|
||||
}
|
||||
|
||||
void EventDispatcher::visitTarget(Node* node)
|
||||
void EventDispatcher::visitTarget(Node* node, bool isRootNode)
|
||||
{
|
||||
int i = 0;
|
||||
auto& children = node->getChildren();
|
||||
|
@ -206,24 +206,55 @@ void EventDispatcher::visitTarget(Node* node)
|
|||
{
|
||||
child = children.at(i);
|
||||
|
||||
if ( child && child->getZOrder() < 0 )
|
||||
visitTarget(child);
|
||||
if ( child && child->getLocalZOrder() < 0 )
|
||||
visitTarget(child, false);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
_nodePriorityMap.insert(std::make_pair(node, ++_nodePriorityIndex));
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].push_back(node);
|
||||
}
|
||||
|
||||
for( ; i < childrenCount; i++ )
|
||||
{
|
||||
child = children.at(i);
|
||||
if (child)
|
||||
visitTarget(child);
|
||||
visitTarget(child, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_nodePriorityMap.insert(std::make_pair(node, ++_nodePriorityIndex));
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
if (isRootNode)
|
||||
{
|
||||
std::vector<int> globalZOrders;
|
||||
globalZOrders.reserve(_globalZOrderNodeMap.size());
|
||||
|
||||
for (const auto& e : _globalZOrderNodeMap)
|
||||
{
|
||||
globalZOrders.push_back(e.first);
|
||||
}
|
||||
|
||||
std::sort(globalZOrders.begin(), globalZOrders.end(), [](const int a, const int b){
|
||||
return a < b;
|
||||
});
|
||||
|
||||
for (const auto& globalZ : globalZOrders)
|
||||
{
|
||||
for (const auto& n : _globalZOrderNodeMap[globalZ])
|
||||
{
|
||||
_nodePriorityMap[n] = ++_nodePriorityIndex;
|
||||
}
|
||||
}
|
||||
|
||||
_globalZOrderNodeMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,7 +385,7 @@ void EventDispatcher::forceAddEventListener(EventListener* listener)
|
|||
}
|
||||
else
|
||||
{
|
||||
setDirty(listenerID, DirtyFlag::FIXED_PRITORY);
|
||||
setDirty(listenerID, DirtyFlag::FIXED_PRIORITY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -496,7 +527,7 @@ void EventDispatcher::setPriority(EventListener* listener, int fixedPriority)
|
|||
if (listener->getFixedPriority() != fixedPriority)
|
||||
{
|
||||
listener->setFixedPriority(fixedPriority);
|
||||
setDirty(listener->getListenerID(), DirtyFlag::FIXED_PRITORY);
|
||||
setDirty(listener->getListenerID(), DirtyFlag::FIXED_PRIORITY);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -921,7 +952,7 @@ void EventDispatcher::sortEventListeners(const EventListener::ListenerID& listen
|
|||
|
||||
if (dirtyFlag != DirtyFlag::NONE)
|
||||
{
|
||||
if ((int)dirtyFlag & (int)DirtyFlag::FIXED_PRITORY)
|
||||
if ((int)dirtyFlag & (int)DirtyFlag::FIXED_PRIORITY)
|
||||
{
|
||||
sortEventListenersOfFixedPriority(listenerID);
|
||||
}
|
||||
|
@ -947,7 +978,7 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener
|
|||
_nodePriorityIndex = 0;
|
||||
_nodePriorityMap.clear();
|
||||
|
||||
visitTarget(rootNode);
|
||||
visitTarget(rootNode, true);
|
||||
|
||||
// After sort: priority < 0, > 0
|
||||
auto sceneGraphlisteners = listeners->getSceneGraphPriorityListeners();
|
||||
|
@ -1135,7 +1166,7 @@ bool EventDispatcher::isEnabled() const
|
|||
|
||||
void EventDispatcher::setDirtyForNode(Node* node)
|
||||
{
|
||||
// Mark the node dirty only when there was an eventlistener associates with it.
|
||||
// Mark the node dirty only when there is an eventlistener associated with it.
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_dirtyNodes.insert(node);
|
||||
|
|
|
@ -207,16 +207,16 @@ protected:
|
|||
enum class DirtyFlag
|
||||
{
|
||||
NONE = 0,
|
||||
FIXED_PRITORY = 1 << 0,
|
||||
FIXED_PRIORITY = 1 << 0,
|
||||
SCENE_GRAPH_PRIORITY = 1 << 1,
|
||||
ALL = FIXED_PRITORY | SCENE_GRAPH_PRIORITY
|
||||
ALL = FIXED_PRIORITY | SCENE_GRAPH_PRIORITY
|
||||
};
|
||||
|
||||
/** Sets the dirty flag for a specified listener ID */
|
||||
void setDirty(const EventListener::ListenerID& listenerID, DirtyFlag flag);
|
||||
|
||||
/** Walks though scene graph to get the draw order for each node, it's called before sorting event listener with scene graph priority */
|
||||
void visitTarget(Node* node);
|
||||
void visitTarget(Node* node, bool isRootNode);
|
||||
|
||||
/** Listeners map */
|
||||
std::unordered_map<EventListener::ListenerID, EventListenerVector*> _listeners;
|
||||
|
@ -230,6 +230,9 @@ protected:
|
|||
/** The map of node and its event priority */
|
||||
std::unordered_map<Node*, int> _nodePriorityMap;
|
||||
|
||||
/** key: Global Z Order, value: Sorted Nodes */
|
||||
std::unordered_map<int, std::vector<Node*>> _globalZOrderNodeMap;
|
||||
|
||||
/** The listeners to be added after dispatching event */
|
||||
std::vector<EventListener*> _toAddedListeners;
|
||||
|
||||
|
|
|
@ -26,15 +26,8 @@
|
|||
#include "CCFont.h"
|
||||
#include "ccUTF8.h"
|
||||
|
||||
#include "CCFontFNT.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "CCFontCharMap.h"
|
||||
#include "edtaa3func.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const int Font::DistanceMapSpread = 3;
|
||||
|
||||
const char * Font::_glyphASCII = "\"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ ";
|
||||
|
||||
const char * Font::_glyphNEHE = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ";
|
||||
|
@ -43,7 +36,6 @@ const char * Font::_glyphNEHE = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM
|
|||
Font::Font() :
|
||||
_usedGlyphs(GlyphCollection::ASCII)
|
||||
, _customGlyphs(nullptr)
|
||||
,_distanceFieldEnabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -107,189 +99,6 @@ const char * Font::getCurrentGlyphCollection() const
|
|||
}
|
||||
}
|
||||
|
||||
Font* Font::createWithTTF(const std::string& fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs)
|
||||
{
|
||||
return FontFreeType::create(fntName, fontSize, glyphs, customGlyphs);
|
||||
}
|
||||
|
||||
Font* Font::createWithFNT(const std::string& fntFilePath)
|
||||
{
|
||||
return FontFNT::create(fntFilePath);
|
||||
}
|
||||
|
||||
Font* Font::createWithCharMap(const std::string& plistFile)
|
||||
{
|
||||
return FontCharMap::create(plistFile);
|
||||
}
|
||||
|
||||
Font* Font::createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
return FontCharMap::create(texture,itemWidth,itemHeight,startCharMap);
|
||||
}
|
||||
|
||||
Font* Font::createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
return FontCharMap::create(charMapFile,itemWidth,itemHeight,startCharMap);
|
||||
}
|
||||
|
||||
unsigned char * Font::makeDistanceMap( unsigned char *img, unsigned int width, unsigned int height)
|
||||
{
|
||||
unsigned int pixelAmount = (width + 2 * DistanceMapSpread) * (height + 2 * DistanceMapSpread);
|
||||
|
||||
short * xdist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
short * ydist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
double * gx = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * gy = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * data = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * outside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * inside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
unsigned int i,j;
|
||||
|
||||
// Convert img into double (data) rescale image levels between 0 and 1
|
||||
unsigned int outWidth = width + 2 * DistanceMapSpread;
|
||||
for (i = 0; i < width; ++i)
|
||||
{
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
data[j * outWidth + DistanceMapSpread + i] = img[j * width + i] / 255.0;
|
||||
}
|
||||
}
|
||||
|
||||
width += 2 * DistanceMapSpread;
|
||||
height += 2 * DistanceMapSpread;
|
||||
|
||||
// Transform background (outside contour, in areas of 0's)
|
||||
computegradient( data, width, height, gx, gy);
|
||||
edtaa3(data, gx, gy, width, height, xdist, ydist, outside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( outside[i] < 0.0 )
|
||||
outside[i] = 0.0;
|
||||
|
||||
// Transform foreground (inside contour, in areas of 1's)
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
data[i] = 1 - data[i];
|
||||
computegradient( data, width, height, gx, gy);
|
||||
edtaa3(data, gx, gy, width, height, xdist, ydist, inside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( inside[i] < 0.0 )
|
||||
inside[i] = 0.0;
|
||||
|
||||
// The bipolar distance field is now outside-inside
|
||||
double dist;
|
||||
/* Single channel 8-bit output (bad precision and range, but simple) */
|
||||
unsigned char *out = (unsigned char *) malloc( pixelAmount * sizeof(unsigned char) );
|
||||
for( i=0; i < pixelAmount; i++)
|
||||
{
|
||||
dist = outside[i] - inside[i];
|
||||
dist = 128.0 - dist*16;
|
||||
if( dist < 0 ) dist = 0;
|
||||
if( dist > 255 ) dist = 255;
|
||||
out[i] = (unsigned char) dist;
|
||||
}
|
||||
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
||||
/*unsigned char *out = (unsigned char *) malloc( pixelAmount * 3 * sizeof(unsigned char) );
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
{
|
||||
dist = outside[i] - inside[i];
|
||||
dist = 128.0 - dist*16;
|
||||
if( dist < 0.0 ) dist = 0.0;
|
||||
if( dist >= 256.0 ) dist = 255.999;
|
||||
// R channel is a copy of the original grayscale image
|
||||
out[3*i] = img[i];
|
||||
// G channel is fraction
|
||||
out[3*i + 1] = (unsigned char) ( 256 - (dist - floor(dist)* 256.0 ));
|
||||
// B channel is truncated integer part
|
||||
out[3*i + 2] = (unsigned char)dist;
|
||||
}*/
|
||||
|
||||
free( xdist );
|
||||
free( ydist );
|
||||
free( gx );
|
||||
free( gy );
|
||||
free( data );
|
||||
free( outside );
|
||||
free( inside );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void Font::setDistanceFieldEnabled(bool distanceFieldEnabled)
|
||||
{
|
||||
_distanceFieldEnabled = distanceFieldEnabled;
|
||||
}
|
||||
|
||||
bool Font::renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize)
|
||||
{
|
||||
unsigned char *sourceBitmap = 0;
|
||||
int sourceWidth = 0;
|
||||
int sourceHeight = 0;
|
||||
|
||||
sourceBitmap = getGlyphBitmap(charToRender, sourceWidth, sourceHeight);
|
||||
|
||||
if (!sourceBitmap)
|
||||
return false;
|
||||
|
||||
if (_distanceFieldEnabled)
|
||||
{
|
||||
unsigned char * out = makeDistanceMap(sourceBitmap,sourceWidth,sourceHeight);
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
sourceWidth += 2 * DistanceMapSpread;
|
||||
sourceHeight += 2 * DistanceMapSpread;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
||||
/*int index = (iX + ( iY * destSize )) * 3;
|
||||
int index2 = (bitmap_y + x)*3;
|
||||
destMemory[index] = out[index2];
|
||||
destMemory[index + 1] = out[index2 + 1];
|
||||
destMemory[index + 2] = out[index2 + 2];*/
|
||||
|
||||
//Single channel 8-bit output
|
||||
destMemory[iX + ( iY * destSize )] = out[bitmap_y + x];
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
free(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
unsigned char cTemp = sourceBitmap[bitmap_y + x];
|
||||
|
||||
// the final pixel
|
||||
destMemory[(iX + ( iY * destSize ) )] = cTemp;
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
|
||||
//everything good
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned short int * Font::getUTF16Text(const char *text, int &outNumLetters) const
|
||||
{
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(text);
|
||||
|
|
|
@ -33,27 +33,12 @@
|
|||
NS_CC_BEGIN
|
||||
|
||||
// fwd
|
||||
class GlyphDef;
|
||||
class FontAtlas;
|
||||
|
||||
|
||||
class CC_DLL Font : public Object
|
||||
{
|
||||
public:
|
||||
static const int DistanceMapSpread;
|
||||
// create the font
|
||||
static Font* createWithTTF(const std::string& fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs);
|
||||
static Font* createWithFNT(const std::string& fntFilePath);
|
||||
|
||||
static Font * createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||
static Font * createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||
static Font * createWithCharMap(const std::string& plistFile);
|
||||
|
||||
static unsigned char * makeDistanceMap(unsigned char *img, unsigned int width, unsigned int height);
|
||||
void setDistanceFieldEnabled(bool distanceFieldEnabled);
|
||||
bool isDistanceFieldEnabled() const { return _distanceFieldEnabled;}
|
||||
bool renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize);
|
||||
|
||||
virtual FontAtlas *createFontAtlas() = 0;
|
||||
|
||||
virtual Size* getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const = 0;
|
||||
|
@ -61,7 +46,7 @@ public:
|
|||
|
||||
virtual int getLetterPadding() const { return 0; }
|
||||
virtual unsigned char * getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const { return 0; }
|
||||
virtual GlyphDef* getGlyphDefintionsForText(const char *text, int &outNumGlyphs, bool UTF16text = false) const { return 0; }
|
||||
|
||||
virtual int getFontMaxHeight() const { return 0; }
|
||||
virtual Rect getRectForChar(unsigned short theChar) const;
|
||||
|
||||
|
@ -85,7 +70,6 @@ protected:
|
|||
char * _customGlyphs;
|
||||
static const char * _glyphASCII;
|
||||
static const char * _glyphNEHE;
|
||||
bool _distanceFieldEnabled;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCFontAtlas.h"
|
||||
#include "CCFont.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "ccUTF8.h"
|
||||
#include "CCDirector.h"
|
||||
|
@ -39,10 +38,9 @@ _font(&theFont),
|
|||
_currentPageData(nullptr)
|
||||
{
|
||||
_font->retain();
|
||||
_makeDistanceMap = _font->isDistanceFieldEnabled();
|
||||
|
||||
FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
|
||||
if (fontTTf && fontTTf->isDynamicGlyphCollection())
|
||||
if (fontTTf)
|
||||
{
|
||||
_currentPageLineHeight = _font->getFontMaxHeight();
|
||||
_commonLineHeight = _currentPageLineHeight * 0.8f;
|
||||
|
@ -51,23 +49,24 @@ _currentPageData(nullptr)
|
|||
_currentPageOrigX = 0;
|
||||
_currentPageOrigY = 0;
|
||||
_letterPadding = 5;
|
||||
|
||||
|
||||
_makeDistanceMap = fontTTf->isDistanceFieldEnabled();
|
||||
if(_makeDistanceMap)
|
||||
{
|
||||
_commonLineHeight += 2 * Font::DistanceMapSpread;
|
||||
_letterPadding += 2 * Font::DistanceMapSpread;
|
||||
_currentPageDataSize = (PAGE_WIDTH * PAGE_HEIGHT * 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentPageDataSize = (PAGE_WIDTH * PAGE_HEIGHT * 1);
|
||||
_commonLineHeight += 2 * FontFreeType::DistanceMapSpread;
|
||||
_letterPadding += 2 * FontFreeType::DistanceMapSpread;
|
||||
}
|
||||
_currentPageDataSize = (PAGE_WIDTH * PAGE_HEIGHT * 1);
|
||||
|
||||
_currentPageData = new unsigned char[_currentPageDataSize];
|
||||
memset(_currentPageData, 0, _currentPageDataSize);
|
||||
addTexture(*tex,0);
|
||||
tex->release();
|
||||
}
|
||||
else
|
||||
{
|
||||
_makeDistanceMap = false;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas::~FontAtlas()
|
||||
|
@ -165,7 +164,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
Size _pageContentSize = Size(PAGE_WIDTH,PAGE_HEIGHT);
|
||||
float scaleFactor = CC_CONTENT_SCALE_FACTOR();
|
||||
float glyphWidth;
|
||||
Texture2D::PixelFormat pixelFormat = _makeDistanceMap ? Texture2D::PixelFormat::A8 : Texture2D::PixelFormat::A8;
|
||||
Texture2D::PixelFormat pixelFormat = Texture2D::PixelFormat::A8;
|
||||
|
||||
|
||||
for(auto it = fontDefs.begin(); it != fontDefs.end(); it++)
|
||||
{
|
||||
|
@ -194,7 +194,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
tex->release();
|
||||
}
|
||||
}
|
||||
_font->renderCharAt(it->second.letteCharUTF16,_currentPageOrigX,_currentPageOrigY,_currentPageData,PAGE_WIDTH);
|
||||
fontTTf->renderCharAt(it->second.letteCharUTF16,_currentPageOrigX,_currentPageOrigY,_currentPageData,PAGE_WIDTH);
|
||||
|
||||
it->second.U = _currentPageOrigX - 1;
|
||||
it->second.V = _currentPageOrigY;
|
||||
|
@ -235,7 +235,7 @@ float FontAtlas::getCommonLineHeight() const
|
|||
void FontAtlas::setCommonLineHeight(float newHeight)
|
||||
{
|
||||
if(_makeDistanceMap)
|
||||
newHeight += 2 * Font::DistanceMapSpread;
|
||||
newHeight += 2 * FontFreeType::DistanceMapSpread;
|
||||
_commonLineHeight = newHeight;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,10 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "CCFontAtlasCache.h"
|
||||
#include "CCFontAtlasFactory.h"
|
||||
|
||||
#include "CCFontFNT.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "CCFontCharMap.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -40,15 +42,24 @@ FontAtlas * FontAtlasCache::getFontAtlasTTF(const std::string& fontFileName, int
|
|||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
tempAtlas = FontAtlasFactory::createAtlasFromTTF(fontFileName, size, glyphs, customGlyphs, useDistanceField);
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
FontFreeType *font = FontFreeType::create(fontFileName, size, glyphs, customGlyphs);
|
||||
if (font)
|
||||
{
|
||||
font->setDistanceFieldEnabled(useDistanceField);
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tempAtlas->retain();
|
||||
}
|
||||
|
||||
|
||||
return tempAtlas;
|
||||
}
|
||||
|
||||
|
@ -59,9 +70,18 @@ FontAtlas * FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName)
|
|||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
tempAtlas = FontAtlasFactory::createAtlasFromFNT(fontFileName);
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
Font *font = FontFNT::create(fontFileName);
|
||||
|
||||
if(font)
|
||||
{
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -78,9 +98,18 @@ FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile)
|
|||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
tempAtlas = FontAtlasFactory::createAtlasFromCharMap(plistFile);
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
Font *font = FontCharMap::create(plistFile);
|
||||
|
||||
if(font)
|
||||
{
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -99,9 +128,18 @@ FontAtlas * FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidt
|
|||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
tempAtlas = FontAtlasFactory::createAtlasFromCharMap(texture,itemWidth,itemHeight,startCharMap);
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
Font *font = FontCharMap::create(texture,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if(font)
|
||||
{
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -118,9 +156,18 @@ FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile,
|
|||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
tempAtlas = FontAtlasFactory::createAtlasFromCharMap(charMapFile,itemWidth,itemHeight,startCharMap);
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
Font *font = FontCharMap::create(charMapFile,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if(font)
|
||||
{
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCFontAtlasFactory.h"
|
||||
#include "CCFontFNT.h"
|
||||
|
||||
// carloX this NEEDS to be changed
|
||||
#include "CCLabelBMFont.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromTTF(const std::string& fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
{
|
||||
|
||||
Font *font = Font::createWithTTF(fntFilePath, fontSize, glyphs, customGlyphs);
|
||||
if (font)
|
||||
{
|
||||
font->setDistanceFieldEnabled(useDistanceField);
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromFNT(const std::string& fntFilePath)
|
||||
{
|
||||
Font *font = Font::createWithFNT(fntFilePath);
|
||||
|
||||
if(font)
|
||||
{
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromCharMap(const std::string& plistFile)
|
||||
{
|
||||
Font *font = Font::createWithCharMap(plistFile);
|
||||
|
||||
if(font)
|
||||
{
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
Font *font = Font::createWithCharMap(texture,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if(font)
|
||||
{
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
Font *font = Font::createWithCharMap(charMapFile,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if(font)
|
||||
{
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,52 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CCFontAtlasFactory_h_
|
||||
#define _CCFontAtlasFactory_h_
|
||||
|
||||
#include "CCFontAtlas.h"
|
||||
#include "CCLabel.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL FontAtlasFactory
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
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);
|
||||
|
||||
static FontAtlas * createAtlasFromCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||
static FontAtlas * createAtlasFromCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||
static FontAtlas * createAtlasFromCharMap(const std::string& plistFile);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(_CCFontAtlasFactory_h_) */
|
|
@ -25,6 +25,10 @@
|
|||
|
||||
#include "CCFontCharMap.h"
|
||||
#include "CCFontAtlas.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "ccUTF8.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#ifndef _CCFontCharMap_h_
|
||||
#define _CCFontCharMap_h_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCFont.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
|
|
@ -1,235 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "CCFontDefinition.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const int FontDefinitionTTF::DEFAUL_ATLAS_TEXTURE_SIZE = 1024;
|
||||
|
||||
FontDefinitionTTF::FontDefinitionTTF():_textImages(0), _commonLineHeight(0)
|
||||
{
|
||||
}
|
||||
|
||||
FontDefinitionTTF* FontDefinitionTTF::create(Font *font, int textureSize)
|
||||
{
|
||||
if (textureSize == 0)
|
||||
textureSize = DEFAUL_ATLAS_TEXTURE_SIZE;
|
||||
|
||||
FontDefinitionTTF *ret = new FontDefinitionTTF;
|
||||
|
||||
if (!ret)
|
||||
return 0;
|
||||
|
||||
const char *glyph = font->getCurrentGlyphCollection();
|
||||
if (!glyph)
|
||||
return nullptr;
|
||||
|
||||
if (ret->initDefinition(font, glyph, textureSize))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete ret;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
FontDefinitionTTF::~FontDefinitionTTF()
|
||||
{
|
||||
if (_textImages)
|
||||
{
|
||||
delete _textImages;
|
||||
}
|
||||
}
|
||||
|
||||
bool FontDefinitionTTF::prepareLetterDefinitions(TextFontPagesDef *pageDefs)
|
||||
{
|
||||
// get all the pages
|
||||
TextFontPagesDef *pages = pageDefs;
|
||||
if (!pages)
|
||||
return (false);
|
||||
|
||||
float maxLineHeight = -1;
|
||||
|
||||
// loops all the pages
|
||||
for (int cPages = 0; cPages < pages->getNumPages(); ++cPages)
|
||||
{
|
||||
// loops all the lines in this page
|
||||
for (int cLines = 0; cLines<pages->getPageAt(cPages)->getNumLines(); ++cLines)
|
||||
{
|
||||
float posXUV = 0.0;
|
||||
float posYUV = pages->getPageAt(cPages)->getLineAt(cLines)->getY();
|
||||
|
||||
int charsCounter = 0;
|
||||
|
||||
for (int c = 0; c < pages->getPageAt(cPages)->getLineAt(cLines)->getNumGlyph(); ++c)
|
||||
{
|
||||
// the current glyph
|
||||
GlyphDef currentGlyph = pages->getPageAt(cPages)->getLineAt(cLines)->getGlyphAt(c);
|
||||
|
||||
// letter width
|
||||
float letterWidth = currentGlyph.getRect().size.width;
|
||||
|
||||
// letter height
|
||||
float letterHeight = pages->getPageAt(cPages)->getLineAt(cLines)->getHeight();
|
||||
|
||||
// add this letter definition
|
||||
FontLetterDefinition tempDef;
|
||||
|
||||
|
||||
// carloX little hack (this should be done outside the loop)
|
||||
if (posXUV == 0.0)
|
||||
posXUV = currentGlyph.getPadding();
|
||||
|
||||
tempDef.validDefinition = currentGlyph.isValid();
|
||||
|
||||
if (tempDef.validDefinition)
|
||||
{
|
||||
tempDef.letteCharUTF16 = currentGlyph.getUTF8Letter();
|
||||
tempDef.width = letterWidth + currentGlyph.getPadding();
|
||||
tempDef.height = (letterHeight - 1);
|
||||
tempDef.U = (posXUV - 1);
|
||||
tempDef.V = posYUV;
|
||||
tempDef.offsetX = currentGlyph.getRect().origin.x;
|
||||
tempDef.offsetY = currentGlyph.getRect().origin.y;
|
||||
tempDef.textureID = cPages;
|
||||
tempDef.commonLineHeight = currentGlyph.getCommonHeight();
|
||||
|
||||
// take from pixels to points
|
||||
tempDef.width = tempDef.width / CC_CONTENT_SCALE_FACTOR();
|
||||
tempDef.height = tempDef.height / CC_CONTENT_SCALE_FACTOR();
|
||||
tempDef.U = tempDef.U / CC_CONTENT_SCALE_FACTOR();
|
||||
tempDef.V = tempDef.V / CC_CONTENT_SCALE_FACTOR();
|
||||
|
||||
if (tempDef.commonLineHeight>maxLineHeight)
|
||||
maxLineHeight = tempDef.commonLineHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempDef.letteCharUTF16 = currentGlyph.getUTF8Letter();
|
||||
tempDef.commonLineHeight = 0;
|
||||
tempDef.width = 0;
|
||||
tempDef.height = 0;
|
||||
tempDef.U = 0;
|
||||
tempDef.V = 0;
|
||||
tempDef.offsetX = 0;
|
||||
tempDef.offsetY = 0;
|
||||
tempDef.textureID = 0;
|
||||
}
|
||||
|
||||
|
||||
// add this definition
|
||||
addLetterDefinition(tempDef);
|
||||
|
||||
// move bounding box to the next letter
|
||||
posXUV += letterWidth + currentGlyph.getPadding();
|
||||
|
||||
// next char in the string
|
||||
++charsCounter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// store the common line height
|
||||
_commonLineHeight = maxLineHeight;
|
||||
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FontDefinitionTTF::initDefinition(cocos2d::Font *font, const char *letters, int textureSize)
|
||||
{
|
||||
// preare texture/image stuff
|
||||
_textImages = new TextImage();
|
||||
if (!_textImages)
|
||||
return false;
|
||||
|
||||
if (!_textImages->initWithString(letters, textureSize, textureSize, font, true))
|
||||
{
|
||||
delete _textImages;
|
||||
_textImages = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// prepare the new letter definition
|
||||
return prepareLetterDefinitions(_textImages->getPages());
|
||||
}
|
||||
|
||||
void FontDefinitionTTF::addLetterDefinition(const FontLetterDefinition &defToAdd)
|
||||
{
|
||||
if (_fontLettersDefinitionUTF16.find(defToAdd.letteCharUTF16) == _fontLettersDefinitionUTF16.end())
|
||||
{
|
||||
_fontLettersDefinitionUTF16[defToAdd.letteCharUTF16] = defToAdd;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontDefinitionTTF::createFontAtlas()
|
||||
{
|
||||
int numTextures = 0;
|
||||
TextFontPagesDef *pages = _textImages->getPages();
|
||||
|
||||
if (pages)
|
||||
numTextures = pages->getNumPages();
|
||||
else
|
||||
return nullptr;
|
||||
|
||||
if (!numTextures)
|
||||
return nullptr;
|
||||
|
||||
FontAtlas *retAtlas = new FontAtlas(*_textImages->getFont());
|
||||
|
||||
if (!retAtlas)
|
||||
return 0;
|
||||
|
||||
for (int c = 0; c < numTextures; ++c)
|
||||
{
|
||||
TextFontPagesDef *pPages = _textImages->getPages();
|
||||
retAtlas->addTexture(*(pPages->getPageAt(c)->getPageTexture()), c);
|
||||
}
|
||||
|
||||
// set the common line height
|
||||
retAtlas->setCommonLineHeight(_commonLineHeight * 0.8);
|
||||
|
||||
for( auto &item: _fontLettersDefinitionUTF16 )
|
||||
{
|
||||
if ( item.second.validDefinition )
|
||||
{
|
||||
FontLetterDefinition tempDefinition = item.second;
|
||||
tempDefinition.anchorX = 0.0f;
|
||||
tempDefinition.anchorY = 1.0f;
|
||||
retAtlas->addLetterDefinition(tempDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
// done here
|
||||
return retAtlas;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,70 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _FontDefinition_h_
|
||||
#define _FontDefinition_h_
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CCTextImage.h"
|
||||
#include "CCFont.h"
|
||||
#include "CCFontAtlas.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
*/
|
||||
class CC_DLL FontDefinitionTTF : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
static FontDefinitionTTF* create(Font *font, int textureSize = 0);
|
||||
FontAtlas * createFontAtlas();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
FontDefinitionTTF();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~FontDefinitionTTF();
|
||||
|
||||
bool initDefinition(Font *font, const char *letters, int textureSize);
|
||||
bool prepareLetterDefinitions(TextFontPagesDef *pageDefs);
|
||||
void addLetterDefinition(const FontLetterDefinition &defToAdd);
|
||||
|
||||
TextImage * _textImages;
|
||||
std::unordered_map<unsigned short, FontLetterDefinition> _fontLettersDefinitionUTF16;
|
||||
float _commonLineHeight;
|
||||
|
||||
static const int DEFAUL_ATLAS_TEXTURE_SIZE;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
|
@ -28,24 +28,19 @@ THE SOFTWARE.
|
|||
|
||||
#include "ccUTF8.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "CCTextImage.h"
|
||||
#include "CCFont.h"
|
||||
#include "CCFontDefinition.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "edtaa3func.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
FT_Library FontFreeType::_FTlibrary;
|
||||
bool FontFreeType::_FTInitialized = false;
|
||||
const int FontFreeType::DistanceMapSpread = 3;
|
||||
|
||||
FontFreeType * FontFreeType::create(const std::string &fontName, int fontSize, GlyphCollection glyphs, const char *customGlyphs)
|
||||
{
|
||||
bool dynamicGlyphCollection = false;
|
||||
if(glyphs == GlyphCollection::DYNAMIC)
|
||||
dynamicGlyphCollection = true;
|
||||
|
||||
FontFreeType *tempFont = new FontFreeType(dynamicGlyphCollection);
|
||||
FontFreeType *tempFont = new FontFreeType();
|
||||
|
||||
if (!tempFont)
|
||||
return nullptr;
|
||||
|
@ -89,13 +84,11 @@ FT_Library FontFreeType::getFTLibrary()
|
|||
return _FTlibrary;
|
||||
}
|
||||
|
||||
FontFreeType::FontFreeType(bool dynamicGlyphCollection)
|
||||
FontFreeType::FontFreeType()
|
||||
: _fontRef(nullptr),
|
||||
_letterPadding(5),
|
||||
_dynamicGlyphCollection(dynamicGlyphCollection)
|
||||
_letterPadding(5)
|
||||
,_distanceFieldEnabled(false)
|
||||
{
|
||||
if(_distanceFieldEnabled)
|
||||
_letterPadding += 2 * DistanceMapSpread;
|
||||
}
|
||||
|
||||
bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
||||
|
@ -141,23 +134,13 @@ FontFreeType::~FontFreeType()
|
|||
|
||||
FontAtlas * FontFreeType::createFontAtlas()
|
||||
{
|
||||
if (_dynamicGlyphCollection)
|
||||
FontAtlas *atlas = new FontAtlas(*this);
|
||||
if (_usedGlyphs != GlyphCollection::DYNAMIC)
|
||||
{
|
||||
FontAtlas *atlas = new FontAtlas(*this);
|
||||
this->release();
|
||||
return atlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
FontDefinitionTTF *def = FontDefinitionTTF::create(this);
|
||||
|
||||
if (!def)
|
||||
return nullptr;
|
||||
|
||||
FontAtlas *atlas = def->createFontAtlas();
|
||||
|
||||
return atlas;
|
||||
}
|
||||
atlas->prepareLetterDefinitions(cc_utf8_to_utf16(getCurrentGlyphCollection()));
|
||||
}
|
||||
this->release();
|
||||
return atlas;
|
||||
}
|
||||
|
||||
bool FontFreeType::getBBOXFotChar(unsigned short theChar, Rect &outRect) const
|
||||
|
@ -184,71 +167,6 @@ bool FontFreeType::getBBOXFotChar(unsigned short theChar, Rect &outRect) const
|
|||
return true;
|
||||
}
|
||||
|
||||
GlyphDef * FontFreeType::getGlyphDefintionsForText(const char *text, int &outNumGlyphs, bool UTF16text) const
|
||||
{
|
||||
unsigned short* utf16String = 0;
|
||||
|
||||
if (UTF16text)
|
||||
{
|
||||
utf16String = (unsigned short*) text;
|
||||
}
|
||||
else
|
||||
{
|
||||
utf16String = cc_utf8_to_utf16(text);
|
||||
}
|
||||
|
||||
//
|
||||
if (!utf16String)
|
||||
return 0;
|
||||
|
||||
int numChar = cc_wcslen(utf16String);
|
||||
if (!numChar)
|
||||
return 0;
|
||||
|
||||
// allocate the needed Glyphs
|
||||
GlyphDef *glyphs = new GlyphDef[numChar];
|
||||
assert(glyphs != nullptr);
|
||||
if (!glyphs)
|
||||
return 0;
|
||||
|
||||
// sore result as CCRect
|
||||
for (int c = 0; c < numChar; ++c)
|
||||
{
|
||||
Rect tempRect;
|
||||
|
||||
if (!getBBOXFotChar(utf16String[c], tempRect))
|
||||
{
|
||||
log("Warning: Cannot find definition for glyph: %c in font:%s", utf16String[c], _fontName.c_str());
|
||||
|
||||
tempRect.origin.x = 0;
|
||||
tempRect.origin.y = 0;
|
||||
tempRect.size.width = 0;
|
||||
tempRect.size.height = 0;
|
||||
|
||||
glyphs[c].setRect(tempRect);
|
||||
glyphs[c].setUTF16Letter(utf16String[c]);
|
||||
glyphs[c].setValid(false);
|
||||
glyphs[c].setPadding(_letterPadding);
|
||||
}
|
||||
else
|
||||
{
|
||||
glyphs[c].setRect(tempRect);
|
||||
glyphs[c].setUTF16Letter(utf16String[c]);
|
||||
glyphs[c].setPadding(_letterPadding);
|
||||
glyphs[c].setValid(true);
|
||||
}
|
||||
}
|
||||
|
||||
outNumGlyphs = numChar;
|
||||
|
||||
// free memory
|
||||
if (!UTF16text)
|
||||
delete [] utf16String;
|
||||
|
||||
// done
|
||||
return glyphs;
|
||||
}
|
||||
|
||||
Size * FontFreeType::getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const
|
||||
{
|
||||
if (!text)
|
||||
|
@ -380,4 +298,164 @@ int FontFreeType::getLetterPadding() const
|
|||
return _letterPadding;
|
||||
}
|
||||
|
||||
unsigned char * makeDistanceMap( unsigned char *img, unsigned int width, unsigned int height)
|
||||
{
|
||||
unsigned int pixelAmount = (width + 2 * FontFreeType::DistanceMapSpread) * (height + 2 * FontFreeType::DistanceMapSpread);
|
||||
|
||||
short * xdist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
short * ydist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
double * gx = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * gy = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * data = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * outside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * inside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
unsigned int i,j;
|
||||
|
||||
// Convert img into double (data) rescale image levels between 0 and 1
|
||||
unsigned int outWidth = width + 2 * FontFreeType::DistanceMapSpread;
|
||||
for (i = 0; i < width; ++i)
|
||||
{
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
data[j * outWidth + FontFreeType::DistanceMapSpread + i] = img[j * width + i] / 255.0;
|
||||
}
|
||||
}
|
||||
|
||||
width += 2 * FontFreeType::DistanceMapSpread;
|
||||
height += 2 * FontFreeType::DistanceMapSpread;
|
||||
|
||||
// Transform background (outside contour, in areas of 0's)
|
||||
computegradient( data, width, height, gx, gy);
|
||||
edtaa3(data, gx, gy, width, height, xdist, ydist, outside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( outside[i] < 0.0 )
|
||||
outside[i] = 0.0;
|
||||
|
||||
// Transform foreground (inside contour, in areas of 1's)
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
data[i] = 1 - data[i];
|
||||
computegradient( data, width, height, gx, gy);
|
||||
edtaa3(data, gx, gy, width, height, xdist, ydist, inside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( inside[i] < 0.0 )
|
||||
inside[i] = 0.0;
|
||||
|
||||
// The bipolar distance field is now outside-inside
|
||||
double dist;
|
||||
/* Single channel 8-bit output (bad precision and range, but simple) */
|
||||
unsigned char *out = (unsigned char *) malloc( pixelAmount * sizeof(unsigned char) );
|
||||
for( i=0; i < pixelAmount; i++)
|
||||
{
|
||||
dist = outside[i] - inside[i];
|
||||
dist = 128.0 - dist*16;
|
||||
if( dist < 0 ) dist = 0;
|
||||
if( dist > 255 ) dist = 255;
|
||||
out[i] = (unsigned char) dist;
|
||||
}
|
||||
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
||||
/*unsigned char *out = (unsigned char *) malloc( pixelAmount * 3 * sizeof(unsigned char) );
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
{
|
||||
dist = outside[i] - inside[i];
|
||||
dist = 128.0 - dist*16;
|
||||
if( dist < 0.0 ) dist = 0.0;
|
||||
if( dist >= 256.0 ) dist = 255.999;
|
||||
// R channel is a copy of the original grayscale image
|
||||
out[3*i] = img[i];
|
||||
// G channel is fraction
|
||||
out[3*i + 1] = (unsigned char) ( 256 - (dist - floor(dist)* 256.0 ));
|
||||
// B channel is truncated integer part
|
||||
out[3*i + 2] = (unsigned char)dist;
|
||||
}*/
|
||||
|
||||
free( xdist );
|
||||
free( ydist );
|
||||
free( gx );
|
||||
free( gy );
|
||||
free( data );
|
||||
free( outside );
|
||||
free( inside );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void FontFreeType::setDistanceFieldEnabled(bool distanceFieldEnabled)
|
||||
{
|
||||
if(distanceFieldEnabled)
|
||||
_letterPadding += 2 * DistanceMapSpread;
|
||||
_distanceFieldEnabled = distanceFieldEnabled;
|
||||
}
|
||||
|
||||
bool FontFreeType::renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize)
|
||||
{
|
||||
unsigned char *sourceBitmap = 0;
|
||||
int sourceWidth = 0;
|
||||
int sourceHeight = 0;
|
||||
|
||||
sourceBitmap = getGlyphBitmap(charToRender, sourceWidth, sourceHeight);
|
||||
|
||||
if (!sourceBitmap)
|
||||
return false;
|
||||
|
||||
if (_distanceFieldEnabled)
|
||||
{
|
||||
unsigned char * out = makeDistanceMap(sourceBitmap,sourceWidth,sourceHeight);
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
sourceWidth += 2 * DistanceMapSpread;
|
||||
sourceHeight += 2 * DistanceMapSpread;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
||||
/*int index = (iX + ( iY * destSize )) * 3;
|
||||
int index2 = (bitmap_y + x)*3;
|
||||
destMemory[index] = out[index2];
|
||||
destMemory[index + 1] = out[index2 + 1];
|
||||
destMemory[index + 2] = out[index2 + 2];*/
|
||||
|
||||
//Single channel 8-bit output
|
||||
destMemory[iX + ( iY * destSize )] = out[bitmap_y + x];
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
free(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
unsigned char cTemp = sourceBitmap[bitmap_y + x];
|
||||
|
||||
// the final pixel
|
||||
destMemory[(iX + ( iY * destSize ) )] = cTemp;
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
|
||||
//everything good
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -39,25 +39,28 @@ NS_CC_BEGIN
|
|||
class CC_DLL FontFreeType : public Font
|
||||
{
|
||||
public:
|
||||
|
||||
static const int DistanceMapSpread;
|
||||
|
||||
static FontFreeType * create(const std::string &fontName, int fontSize, GlyphCollection glyphs, const char *customGlyphs);
|
||||
|
||||
static void shutdownFreeType();
|
||||
|
||||
void setDistanceFieldEnabled(bool distanceFieldEnabled);
|
||||
bool isDistanceFieldEnabled() const { return _distanceFieldEnabled;}
|
||||
bool renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize);
|
||||
|
||||
virtual FontAtlas * createFontAtlas() override;
|
||||
virtual Size * getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const override;
|
||||
virtual GlyphDef * getGlyphDefintionsForText(const char *text, int &outNumGlyphs, bool UTF16text = false) const override;
|
||||
|
||||
unsigned char * getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const override;
|
||||
virtual int getFontMaxHeight() const override;
|
||||
virtual int getLetterPadding() const override;
|
||||
|
||||
bool getBBOXFotChar(unsigned short theChar, Rect &outRect) const;
|
||||
|
||||
inline bool isDynamicGlyphCollection() { return _dynamicGlyphCollection;}
|
||||
bool getBBOXFotChar(unsigned short theChar, Rect &outRect) const;
|
||||
|
||||
protected:
|
||||
|
||||
FontFreeType(bool dynamicGlyphCollection = false);
|
||||
FontFreeType();
|
||||
virtual ~FontFreeType();
|
||||
bool createFontObject(const std::string &fontName, int fontSize);
|
||||
|
||||
|
@ -76,7 +79,7 @@ private:
|
|||
int _letterPadding;
|
||||
std::string _fontName;
|
||||
Data _ttfData;
|
||||
bool _dynamicGlyphCollection;
|
||||
bool _distanceFieldEnabled;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCLabel.h"
|
||||
#include "CCFontDefinition.h"
|
||||
#include "CCFontAtlasCache.h"
|
||||
#include "CCLabelTextFormatter.h"
|
||||
#include "CCSprite.h"
|
||||
|
@ -33,6 +32,7 @@
|
|||
#include "CCSpriteFrame.h"
|
||||
#include "CCDirector.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "CCFont.h"
|
||||
|
||||
#define DISTANCEFIELD_ATLAS_FONTSIZE 50
|
||||
|
||||
|
|
|
@ -215,6 +215,15 @@ void Node::setLocalZOrder(int z)
|
|||
_eventDispatcher->setDirtyForNode(this);
|
||||
}
|
||||
|
||||
void Node::setGlobalZOrder(float globalZOrder)
|
||||
{
|
||||
if (_globalZOrder != globalZOrder)
|
||||
{
|
||||
_globalZOrder = globalZOrder;
|
||||
_eventDispatcher->setDirtyForNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// vertexZ getter
|
||||
float Node::getVertexZ() const
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2009 Valentin Milea
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2009 Valentin Milea
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -204,7 +204,7 @@ public:
|
|||
|
||||
@since v3.0
|
||||
*/
|
||||
virtual void setGlobalZOrder(float globalZOrder) { _globalZOrder = globalZOrder; }
|
||||
virtual void setGlobalZOrder(float globalZOrder);
|
||||
/**
|
||||
* Returns the Node's Global Z Order.
|
||||
*
|
||||
|
|
|
@ -125,7 +125,7 @@ void NodeGrid::visit()
|
|||
{
|
||||
auto node = _children.at(i);
|
||||
|
||||
if ( node && node->getZOrder() < 0 )
|
||||
if ( node && node->getLocalZOrder() < 0 )
|
||||
node->visit();
|
||||
else
|
||||
break;
|
||||
|
|
|
@ -101,8 +101,8 @@ void ParallaxNode::addChild(Node *child, int z, const Point& ratio, const Point&
|
|||
ccArrayAppendObjectWithResize(_parallaxArray, (Object*)obj);
|
||||
|
||||
Point pos = _position;
|
||||
pos.x = pos.x * ratio.x + offset.x;
|
||||
pos.y = pos.y * ratio.y + offset.y;
|
||||
pos.x = -pos.x + pos.x * ratio.x + offset.x;
|
||||
pos.y = -pos.y + pos.y * ratio.y + offset.y;
|
||||
child->setPosition(pos);
|
||||
|
||||
Node::addChild(child, z, child->getTag());
|
||||
|
|
|
@ -218,7 +218,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
|||
|
||||
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
|
||||
|
||||
if( zOrder == child->getZOrder() )
|
||||
if( zOrder == child->getLocalZOrder() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ void ParticleBatchNode::getCurrentIndex(int* oldIndex, int* newIndex, Node* chil
|
|||
Node* pNode = _children.at(i);
|
||||
|
||||
// new index
|
||||
if( pNode->getZOrder() > z && ! foundNewIdx )
|
||||
if( pNode->getLocalZOrder() > z && ! foundNewIdx )
|
||||
{
|
||||
*newIndex = i;
|
||||
foundNewIdx = true;
|
||||
|
@ -325,7 +325,7 @@ int ParticleBatchNode::searchNewPositionInChildrenForZ(int z)
|
|||
for( int i=0; i < count; i++ )
|
||||
{
|
||||
Node *child = _children.at(i);
|
||||
if (child->getZOrder() > z)
|
||||
if (child->getLocalZOrder() > z)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -822,8 +822,8 @@ void Sprite::sortAllChildren()
|
|||
auto tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );
|
||||
|
||||
//continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
|
||||
while(j>=0 && ( tempI->getZOrder() < tempJ->getZOrder() ||
|
||||
( tempI->getZOrder() == tempJ->getZOrder() &&
|
||||
while(j>=0 && ( tempI->getLocalZOrder() < tempJ->getLocalZOrder() ||
|
||||
( tempI->getLocalZOrder() == tempJ->getLocalZOrder() &&
|
||||
tempI->getOrderOfArrival() < tempJ->getOrderOfArrival() ) ) )
|
||||
{
|
||||
_children->fastSetObject( tempJ, j+1 );
|
||||
|
|
|
@ -179,7 +179,7 @@ void SpriteBatchNode::reorderChild(Node *child, int zOrder)
|
|||
CCASSERT(child != nullptr, "the child should not be null");
|
||||
CCASSERT(_children.contains(child), "Child doesn't belong to Sprite");
|
||||
|
||||
if (zOrder == child->getZOrder())
|
||||
if (zOrder == child->getLocalZOrder())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, ssize_t* curIndex)
|
|||
{
|
||||
bool needNewIndex=true;
|
||||
|
||||
if (array.at(0)->getZOrder() >= 0)
|
||||
if (array.at(0)->getLocalZOrder() >= 0)
|
||||
{
|
||||
//all children are in front of the parent
|
||||
oldIndex = sprite->getAtlasIndex();
|
||||
|
@ -294,7 +294,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, ssize_t* curIndex)
|
|||
|
||||
for(const auto &child: array) {
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (needNewIndex && sp->getZOrder() >= 0)
|
||||
if (needNewIndex && sp->getLocalZOrder() >= 0)
|
||||
{
|
||||
oldIndex = sprite->getAtlasIndex();
|
||||
sprite->setAtlasIndex(*curIndex);
|
||||
|
@ -392,7 +392,7 @@ ssize_t SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, ssize_t index)
|
|||
auto& children = parent->getChildren();
|
||||
for(const auto &child: children) {
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (sp && (sp->getZOrder() < 0))
|
||||
if (sp && (sp->getLocalZOrder() < 0))
|
||||
{
|
||||
index = rebuildIndexInOrder(sp, index);
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ ssize_t SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, ssize_t index)
|
|||
|
||||
for(const auto &child: children) {
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (sp && (sp->getZOrder() >= 0))
|
||||
if (sp && (sp->getLocalZOrder() >= 0))
|
||||
{
|
||||
index = rebuildIndexInOrder(sp, index);
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ ssize_t SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
|
|||
else
|
||||
{
|
||||
// previous & sprite belong to the same branch
|
||||
if ((prev->getZOrder() < 0 && nZ < 0) || (prev->getZOrder() >= 0 && nZ >= 0))
|
||||
if ((prev->getLocalZOrder() < 0 && nZ < 0) || (prev->getLocalZOrder() >= 0 && nZ >= 0))
|
||||
{
|
||||
return highestAtlasIndexInChild(prev) + 1;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
if (layerInfo->_visible)
|
||||
{
|
||||
TMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||
addChild((Node*)child, idx, idx);
|
||||
addChild(child, idx, idx);
|
||||
|
||||
// update content size with the max size
|
||||
const Size& childSize = child->getContentSize();
|
||||
|
|
|
@ -1,478 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "CCTextImage.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "CCFont.h"
|
||||
#include "ccUTF8.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
TextLineDef::TextLineDef(float x, float y, float width, float height) :_x(x), _y(y), _width(width), _height(height)
|
||||
{
|
||||
}
|
||||
|
||||
TextPageDef::TextPageDef(int pageNum, int width, int height): _pageNum(pageNum),
|
||||
_width(width),
|
||||
_height(height),
|
||||
_pageData(0),
|
||||
_pageTexture(0)
|
||||
{
|
||||
}
|
||||
|
||||
TextPageDef::~TextPageDef()
|
||||
{
|
||||
size_t numLines = _lines.size();
|
||||
|
||||
for( size_t c = 0; c<numLines; ++c )
|
||||
{
|
||||
delete _lines[c];
|
||||
}
|
||||
|
||||
_lines.clear();
|
||||
|
||||
if (_pageData)
|
||||
{
|
||||
delete [] _pageData;
|
||||
}
|
||||
|
||||
if (_pageTexture)
|
||||
{
|
||||
_pageTexture->release();
|
||||
}
|
||||
}
|
||||
|
||||
bool TextPageDef::generatePageTexture(bool releasePageData)
|
||||
{
|
||||
if (!_pageData)
|
||||
return false;
|
||||
|
||||
if (_pageTexture)
|
||||
{
|
||||
_pageTexture->release();
|
||||
_pageTexture = 0;
|
||||
}
|
||||
|
||||
Size imageSize = Size((float)(_width), (float)(_height));
|
||||
if((imageSize.width <= 0) || (imageSize.height <= 0))
|
||||
return false;
|
||||
|
||||
_pageTexture = new Texture2D();
|
||||
if (!_pageTexture)
|
||||
return false;
|
||||
|
||||
int dataLenght = (_width * _height * 1);
|
||||
bool textureCreated = _pageTexture->initWithData(_pageData, dataLenght, Texture2D::PixelFormat::A8, _width, _height, imageSize);
|
||||
|
||||
// release the page data if requested
|
||||
if (releasePageData && textureCreated)
|
||||
{
|
||||
delete [] _pageData;
|
||||
_pageData = 0;
|
||||
}
|
||||
|
||||
return textureCreated;
|
||||
}
|
||||
|
||||
void TextPageDef::preparePageTexture(bool releaseRAWData)
|
||||
{
|
||||
generatePageTexture(releaseRAWData);
|
||||
}
|
||||
|
||||
Texture2D *TextPageDef::getPageTexture()
|
||||
{
|
||||
if (!_pageTexture)
|
||||
{
|
||||
generatePageTexture();
|
||||
}
|
||||
|
||||
return _pageTexture;
|
||||
}
|
||||
|
||||
TextFontPagesDef::TextFontPagesDef()
|
||||
{
|
||||
}
|
||||
|
||||
TextFontPagesDef::~TextFontPagesDef()
|
||||
{
|
||||
size_t numPages = _pages.size();
|
||||
for( size_t c = 0; c < numPages; ++c )
|
||||
{
|
||||
if (_pages[c])
|
||||
delete _pages[c];
|
||||
}
|
||||
}
|
||||
|
||||
TextImage::TextImage(): _fontPages(0), _font(0)
|
||||
{
|
||||
}
|
||||
|
||||
TextImage::~TextImage()
|
||||
{
|
||||
if (_fontPages)
|
||||
delete _fontPages;
|
||||
|
||||
if (_font)
|
||||
_font->release();
|
||||
}
|
||||
|
||||
bool TextImage::initWithString(const char *text, int width, int height, cocos2d::Font* font, bool releaseRAWData)
|
||||
{
|
||||
bool textIsUTF16 = false;
|
||||
|
||||
if (_font)
|
||||
{
|
||||
_font->release();
|
||||
_font = 0;
|
||||
}
|
||||
|
||||
// carloX
|
||||
_font = font;
|
||||
|
||||
// generate the glyphs for the requested text (glyphs are latter's bounding boxes)
|
||||
if (!generateTextGlyphs(text))
|
||||
return false;
|
||||
|
||||
Size constrainSize;
|
||||
unsigned short int *strUTF16 = 0;
|
||||
|
||||
int stringNumChars;
|
||||
if (textIsUTF16)
|
||||
{
|
||||
strUTF16 = (unsigned short int *)text;
|
||||
stringNumChars = cc_wcslen(strUTF16);
|
||||
}
|
||||
else
|
||||
{
|
||||
// string needs to go to unicode
|
||||
strUTF16 = _font->getUTF16Text(text, stringNumChars);
|
||||
}
|
||||
|
||||
if (!strUTF16 || !stringNumChars)
|
||||
return false;
|
||||
|
||||
// create all the needed pages
|
||||
if (!createPageDefinitions(strUTF16, width, height, _font->getFontMaxHeight()))
|
||||
return false;
|
||||
|
||||
// release the original string if needed
|
||||
if (!textIsUTF16)
|
||||
delete [] strUTF16;
|
||||
|
||||
// actually create the needed images
|
||||
return createImageDataFromPages(_fontPages, releaseRAWData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextImage::createPageDefinitions(unsigned short int *inText, int imageWidth, int imageHeight, int lineHeight)
|
||||
{
|
||||
bool needToReleaseText = false;
|
||||
int delta = 0;
|
||||
int currentPage = 0;
|
||||
float currentY = 0.0;
|
||||
|
||||
//
|
||||
unsigned short int *strUTF16 = inText;
|
||||
|
||||
if (_fontPages)
|
||||
delete _fontPages;
|
||||
|
||||
// create pages for the font
|
||||
_fontPages = new TextFontPagesDef();
|
||||
if (!_fontPages)
|
||||
return false;
|
||||
|
||||
// create the first page (ther is going to be at least one page)
|
||||
TextPageDef *currentPageDef = new TextPageDef(currentPage, imageWidth, imageHeight);
|
||||
if (!currentPageDef)
|
||||
return false;
|
||||
|
||||
// add the current page
|
||||
_fontPages->addPage(currentPageDef);
|
||||
|
||||
// work out creating pages
|
||||
|
||||
do {
|
||||
|
||||
// choose texture page
|
||||
if ((currentY + lineHeight) > imageHeight)
|
||||
{
|
||||
currentY = 0;
|
||||
currentPage += 1;
|
||||
|
||||
// create a new page and add
|
||||
currentPageDef = new TextPageDef(currentPage, imageWidth, imageHeight);
|
||||
if (!currentPageDef)
|
||||
return false;
|
||||
|
||||
_fontPages->addPage(currentPageDef);
|
||||
}
|
||||
|
||||
// get the new fitting string
|
||||
Size tempSize;
|
||||
tempSize.width = imageWidth;
|
||||
tempSize.height = imageHeight;
|
||||
|
||||
// figure out how many glyphs fit in this line
|
||||
int newLineSize = 0;
|
||||
int numFittingChar = getNumGlyphsFittingInSize(_textGlyphs, strUTF16, _font, &tempSize, newLineSize);
|
||||
|
||||
// crete the temporary new string
|
||||
unsigned short int *pTempString = 0;
|
||||
pTempString = _font->trimUTF16Text(strUTF16, 0, (numFittingChar - 1));
|
||||
|
||||
// create the new line and add to the current page
|
||||
TextLineDef *newLine = new TextLineDef(0.0, currentY, newLineSize, lineHeight);
|
||||
if (!newLine)
|
||||
return false;
|
||||
|
||||
// add all the glyphs to this line
|
||||
addGlyphsToLine(newLine, (const char *)pTempString, true);
|
||||
|
||||
// add the line the to current page
|
||||
currentPageDef->addLine(newLine);
|
||||
|
||||
// can now release the string
|
||||
delete [] pTempString;
|
||||
|
||||
// create the new string
|
||||
int stringLenght = _font->getUTF16TextLenght(strUTF16);
|
||||
delta = (stringLenght - numFittingChar);
|
||||
|
||||
// there is still some leftover, need to work on it
|
||||
if (delta)
|
||||
{
|
||||
// create the new string
|
||||
unsigned short int *tempS = _font->trimUTF16Text(strUTF16, numFittingChar, (stringLenght - 1));
|
||||
|
||||
if (needToReleaseText)
|
||||
delete [] strUTF16;
|
||||
|
||||
// a copy of the string has been created, so next time I'll need to release it
|
||||
needToReleaseText = true;
|
||||
|
||||
// assign pointer
|
||||
strUTF16 = tempS;
|
||||
}
|
||||
|
||||
// go to next line
|
||||
currentY += lineHeight;
|
||||
|
||||
} while(delta);
|
||||
|
||||
if (needToReleaseText)
|
||||
delete [] strUTF16;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int TextImage::getNumGlyphsFittingInSize(std::unordered_map<unsigned short int, GlyphDef> &glyphDefs, unsigned short int *strUTF8, Font *font, Size *constrainSize, int &outNewSize)
|
||||
{
|
||||
if (!strUTF8)
|
||||
return 0;
|
||||
|
||||
float widthWithBBX = 0.0f;
|
||||
float lastWidth = 0.0f;
|
||||
|
||||
// get the string to UTF8
|
||||
int numChar = cc_wcslen(strUTF8);
|
||||
|
||||
for (int c = 0; c < numChar; ++c)
|
||||
{
|
||||
widthWithBBX += (glyphDefs[strUTF8[c]].getRect().size.width + glyphDefs[strUTF8[c]].getPadding());
|
||||
|
||||
if (widthWithBBX >= constrainSize->width)
|
||||
{
|
||||
outNewSize = lastWidth;
|
||||
return c;
|
||||
}
|
||||
|
||||
lastWidth = widthWithBBX;
|
||||
}
|
||||
|
||||
outNewSize = constrainSize->width;
|
||||
return numChar;
|
||||
}
|
||||
|
||||
bool TextImage::addGlyphsToLine(TextLineDef *line, const char *lineText, bool textIsUTF16)
|
||||
{
|
||||
if (!_font)
|
||||
return false;
|
||||
|
||||
int numLetters = 0;
|
||||
unsigned short int *UTF16string = 0;
|
||||
|
||||
if (textIsUTF16)
|
||||
{
|
||||
UTF16string = (unsigned short int *)lineText;
|
||||
numLetters = cc_wcslen(UTF16string);
|
||||
}
|
||||
else
|
||||
{
|
||||
UTF16string = _font->getUTF16Text(lineText, numLetters);
|
||||
}
|
||||
|
||||
for (int c = 0; c < numLetters; ++c)
|
||||
{
|
||||
_textGlyphs[UTF16string[c]].setCommonHeight(line->getHeight());
|
||||
line->addGlyph(_textGlyphs[UTF16string[c]] );
|
||||
}
|
||||
|
||||
if(!textIsUTF16)
|
||||
delete [] UTF16string;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextImage::generateTextGlyphs(const char * text)
|
||||
{
|
||||
if (!_font)
|
||||
return false;
|
||||
|
||||
int numGlyphs = 0;
|
||||
GlyphDef *newGlyphs = _font->getGlyphDefintionsForText(text, numGlyphs);
|
||||
|
||||
if (!newGlyphs)
|
||||
return false;
|
||||
|
||||
if (!_textGlyphs.empty())
|
||||
_textGlyphs.clear();
|
||||
|
||||
for (int c = 0; c < numGlyphs; ++c)
|
||||
_textGlyphs[newGlyphs[c].getUTF8Letter()] = newGlyphs[c];
|
||||
|
||||
delete [] newGlyphs;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextImage::createImageDataFromPages(TextFontPagesDef *thePages, bool releaseRAWData)
|
||||
{
|
||||
int numPages = thePages->getNumPages();
|
||||
if (!numPages)
|
||||
return false;
|
||||
|
||||
for (int c = 0; c < numPages; ++c)
|
||||
{
|
||||
unsigned char *pageData = 0;
|
||||
pageData = preparePageGlyphData(thePages->getPageAt(c));
|
||||
|
||||
if (pageData)
|
||||
{
|
||||
// set the page data
|
||||
thePages->getPageAt(c)->setPageData(pageData);
|
||||
|
||||
// crete page texture and relase RAW data
|
||||
thePages->getPageAt(c)->preparePageTexture(releaseRAWData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned char * TextImage::preparePageGlyphData(TextPageDef *thePage)
|
||||
{
|
||||
return renderGlyphData(thePage);
|
||||
}
|
||||
|
||||
unsigned char * TextImage::renderGlyphData(TextPageDef *thePage)
|
||||
{
|
||||
if (!thePage)
|
||||
return 0;
|
||||
|
||||
if (!_font)
|
||||
return 0;
|
||||
|
||||
if (thePage->getNumLines() == 0)
|
||||
return nullptr;
|
||||
|
||||
int pageWidth = thePage->getWidth();
|
||||
int pageHeight = thePage->getHeight();
|
||||
|
||||
// prepare memory and clean to 0
|
||||
int sizeInBytes = (pageWidth * pageHeight * 1);
|
||||
unsigned char* data = new unsigned char[sizeInBytes];
|
||||
|
||||
if (!data)
|
||||
return 0;
|
||||
|
||||
memset(data, 0, sizeInBytes);
|
||||
|
||||
int numLines = thePage->getNumLines();
|
||||
|
||||
for (int c = 0; c < numLines; ++c)
|
||||
{
|
||||
TextLineDef *currentLine = thePage->getLineAt(c);
|
||||
|
||||
float origX = _font->getLetterPadding();
|
||||
float origY = currentLine->getY();
|
||||
|
||||
int numGlyphToRender = currentLine->getNumGlyph();
|
||||
|
||||
for (int cglyph = 0; cglyph < numGlyphToRender; ++cglyph)
|
||||
{
|
||||
GlyphDef currGlyph = currentLine->getGlyphAt(cglyph);
|
||||
_font->renderCharAt(currGlyph.getUTF8Letter(), origX, origY, data, pageWidth);
|
||||
origX += (currGlyph.getRect().size.width + _font->getLetterPadding());
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG_FONTS_
|
||||
static int counter = 0;
|
||||
char outFilename[512];
|
||||
sprintf(outFilename,"testIMG%d", counter);
|
||||
++counter;
|
||||
Image *image = new Image;
|
||||
image->initWithRawData(data, (pageWidth * pageWidth * 4), 1024, 1024, 8, false);
|
||||
image->saveToFile(outFilename);
|
||||
#endif
|
||||
|
||||
// we are done here
|
||||
return data;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CCTextImage_h_
|
||||
#define _CCTextImage_h_
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Font;
|
||||
class Texture2D;
|
||||
|
||||
/** @brief GlyphDef defines one single glyph (character) in a text image
|
||||
*
|
||||
* it defines the bounding box for the glyph in the texture page, the character the padding (spacing) between characters
|
||||
*
|
||||
*/
|
||||
|
||||
class CC_DLL GlyphDef
|
||||
{
|
||||
public:
|
||||
|
||||
GlyphDef() : _validGlyph(false) {}
|
||||
GlyphDef(unsigned short int letterUTF8, const Rect &rect) {
|
||||
_gliphRect = rect;
|
||||
_uTF16Letter = letterUTF8;
|
||||
}
|
||||
|
||||
void setUTF16Letter(unsigned short int letterUTF8) { _uTF16Letter = letterUTF8; }
|
||||
void setRect(const Rect & theRect) { _gliphRect = theRect; }
|
||||
|
||||
unsigned short int getUTF8Letter() const { return _uTF16Letter; }
|
||||
const Rect& getRect() const { return _gliphRect; }
|
||||
|
||||
void setPadding(float padding) { _padding = padding; }
|
||||
float getPadding() const { return _padding; }
|
||||
|
||||
void setCommonHeight(float commonHeight) { _commonHeight = commonHeight; }
|
||||
float getCommonHeight() const { return _commonHeight; }
|
||||
|
||||
void setValid(bool isValid) { _validGlyph = isValid; }
|
||||
bool isValid() const { return _validGlyph; }
|
||||
|
||||
protected:
|
||||
Rect _gliphRect;
|
||||
unsigned short int _uTF16Letter;
|
||||
float _padding;
|
||||
float _commonHeight;
|
||||
bool _validGlyph;
|
||||
|
||||
};
|
||||
|
||||
/** @brief TextLineDef define a line of text in a text image texture page
|
||||
*
|
||||
* conllects all the GlyphDef for a text line plus line size and line position in text image space
|
||||
*
|
||||
*/
|
||||
class CC_DLL TextLineDef
|
||||
{
|
||||
public:
|
||||
|
||||
TextLineDef(float x, float y, float width, float height);
|
||||
|
||||
float getX() const { return _x; }
|
||||
float getY() const { return _y; }
|
||||
float getWidth() const { return _width; }
|
||||
float getHeight() const { return _height; }
|
||||
|
||||
void addGlyph(GlyphDef theGlyph) { _glyphs.push_back(theGlyph); }
|
||||
int getNumGlyph() const { return static_cast<int>(_glyphs.size()); }
|
||||
const GlyphDef & getGlyphAt(int index) const { return _glyphs[index]; }
|
||||
|
||||
protected:
|
||||
float _x;
|
||||
float _y;
|
||||
float _width;
|
||||
float _height;
|
||||
std::vector<GlyphDef> _glyphs;
|
||||
};
|
||||
|
||||
/** @brief TextPageDef defines one text image page (a TextImage can have/use more than one page)
|
||||
*
|
||||
* collects all the TextLineDef for one page, the witdh and height of the page and the graphics (texture) for the page
|
||||
*
|
||||
*/
|
||||
class CC_DLL TextPageDef
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js NA
|
||||
*/
|
||||
TextPageDef(int pageNum, int width, int height);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~TextPageDef();
|
||||
|
||||
void addLine(TextLineDef *theLine) { _lines.push_back(theLine); }
|
||||
int getNumLines() const { return static_cast<int>(_lines.size()); }
|
||||
TextLineDef * getLineAt(int index) const { return _lines[index]; }
|
||||
int getWidth() const { return _width; }
|
||||
int getHeight() const { return _height; }
|
||||
int getPageNumber() const { return _pageNum; }
|
||||
void setPageData(unsigned char *data) { _pageData = data; }
|
||||
const unsigned char * getPageData() const { return _pageData; }
|
||||
Texture2D *getPageTexture();
|
||||
void preparePageTexture(bool releaseRAWData = true);
|
||||
|
||||
protected:
|
||||
bool generatePageTexture(bool releasePageData = false);
|
||||
|
||||
int _pageNum;
|
||||
int _width;
|
||||
int _height;
|
||||
unsigned char * _pageData;
|
||||
Texture2D* _pageTexture;
|
||||
std::vector<TextLineDef*> _lines;
|
||||
};
|
||||
|
||||
/** @brief CCTextFontPages collection of pages (TextPageDef)
|
||||
*
|
||||
* A TextImage is composed by one or more text pages. This calss collects all of those pages
|
||||
*/
|
||||
class CC_DLL TextFontPagesDef
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
TextFontPagesDef();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~TextFontPagesDef();
|
||||
|
||||
void addPage(TextPageDef *newPage) { _pages.push_back(newPage); }
|
||||
int getNumPages() const { return static_cast<int>(_pages.size()); }
|
||||
TextPageDef* getPageAt(int index) const { return _pages[index]; }
|
||||
|
||||
protected:
|
||||
std::vector<TextPageDef*> _pages;
|
||||
|
||||
};
|
||||
|
||||
/** @brief TextImage
|
||||
*
|
||||
*/
|
||||
class CC_DLL TextImage
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
TextImage();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~TextImage();
|
||||
|
||||
bool initWithString(const char *text, int width, int height, Font* font, bool releaseRAWData = true);
|
||||
|
||||
TextFontPagesDef* getPages() const { return _fontPages; }
|
||||
Font* getFont() const { return _font; }
|
||||
|
||||
protected:
|
||||
bool createImageDataFromPages(TextFontPagesDef *thePages, bool releaseRAWData = true);
|
||||
bool addGlyphsToLine(TextLineDef *line, const char *lineText, bool textIsUTF16 = false);
|
||||
bool generateTextGlyphs(const char * text);
|
||||
int getNumGlyphsFittingInSize(std::unordered_map<unsigned short int, GlyphDef> &glyphDefs, unsigned short int *strUTF8, Font *font, Size *constrainSize, int &outNewSize);
|
||||
bool createPageDefinitions(unsigned short int *inText, int imageWidth, int imageHeight, int lineHeight);
|
||||
unsigned char * preparePageGlyphData(TextPageDef *thePage);
|
||||
|
||||
// glyph rendering
|
||||
unsigned char * renderGlyphData(TextPageDef *thePage);
|
||||
|
||||
std::unordered_map<unsigned short int, GlyphDef> _textGlyphs;
|
||||
TextFontPagesDef* _fontPages;
|
||||
Font* _font;
|
||||
};
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif // _CCTextImage_h_
|
|
@ -67,8 +67,6 @@ set(COCOS2D_SRC
|
|||
CCFont.cpp
|
||||
CCFontAtlas.cpp
|
||||
CCFontAtlasCache.cpp
|
||||
CCFontAtlasFactory.cpp
|
||||
CCFontDefinition.cpp
|
||||
CCFontFNT.cpp
|
||||
CCFontFreeType.cpp
|
||||
CCFontCharMap.cpp
|
||||
|
@ -77,7 +75,6 @@ set(COCOS2D_SRC
|
|||
CCLabelBMFont.cpp
|
||||
CCLabelTTF.cpp
|
||||
CCLabelTextFormatter.cpp
|
||||
CCTextImage.cpp
|
||||
CCLayer.cpp
|
||||
CCScene.cpp
|
||||
CCTransition.cpp
|
||||
|
|
|
@ -281,7 +281,7 @@ unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1 */, int*
|
|||
{
|
||||
long len = cc_utf8_strlen(str_old, length);
|
||||
if (rUtf16Size != nullptr) {
|
||||
*rUtf16Size = len;
|
||||
*rUtf16Size = static_cast<int>(len);
|
||||
}
|
||||
|
||||
unsigned short* str_new = new unsigned short[len + 1];
|
||||
|
|
|
@ -247,9 +247,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="CCFont.cpp" />
|
||||
<ClCompile Include="CCFontAtlas.cpp" />
|
||||
<ClCompile Include="CCFontAtlasCache.cpp" />
|
||||
<ClCompile Include="CCFontAtlasFactory.cpp" />
|
||||
<ClCompile Include="CCFontCharMap.cpp" />
|
||||
<ClCompile Include="CCFontDefinition.cpp" />
|
||||
<ClCompile Include="CCFontFNT.cpp" />
|
||||
<ClCompile Include="CCFontFreeType.cpp" />
|
||||
<ClCompile Include="ccFPSImages.c" />
|
||||
|
@ -288,7 +286,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="CCSpriteFrame.cpp" />
|
||||
<ClCompile Include="CCSpriteFrameCache.cpp" />
|
||||
<ClCompile Include="CCTextFieldTTF.cpp" />
|
||||
<ClCompile Include="CCTextImage.cpp" />
|
||||
<ClCompile Include="CCTexture2D.cpp" />
|
||||
<ClCompile Include="CCTextureAtlas.cpp" />
|
||||
<ClCompile Include="CCTextureCache.cpp" />
|
||||
|
@ -429,9 +426,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClInclude Include="CCFont.h" />
|
||||
<ClInclude Include="CCFontAtlas.h" />
|
||||
<ClInclude Include="CCFontAtlasCache.h" />
|
||||
<ClInclude Include="CCFontAtlasFactory.h" />
|
||||
<ClInclude Include="CCFontCharMap.h" />
|
||||
<ClInclude Include="CCFontDefinition.h" />
|
||||
<ClInclude Include="CCFontFNT.h" />
|
||||
<ClInclude Include="CCFontFreeType.h" />
|
||||
<ClInclude Include="ccFPSImages.h" />
|
||||
|
@ -490,7 +485,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClInclude Include="CCSpriteFrame.h" />
|
||||
<ClInclude Include="CCSpriteFrameCache.h" />
|
||||
<ClInclude Include="CCTextFieldTTF.h" />
|
||||
<ClInclude Include="CCTextImage.h" />
|
||||
<ClInclude Include="CCTexture2D.h" />
|
||||
<ClInclude Include="CCTextureAtlas.h" />
|
||||
<ClInclude Include="CCTextureCache.h" />
|
||||
|
|
|
@ -318,12 +318,6 @@
|
|||
<ClCompile Include="CCFontAtlasCache.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CCFontAtlasFactory.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CCFontDefinition.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CCFontFNT.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
|
@ -345,9 +339,6 @@
|
|||
<ClCompile Include="CCLabelTTF.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CCTextImage.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\etc1.cpp">
|
||||
<Filter>platform\etc</Filter>
|
||||
</ClCompile>
|
||||
|
@ -834,12 +825,6 @@
|
|||
<ClInclude Include="CCFontAtlasCache.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CCFontAtlasFactory.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CCFontDefinition.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CCFontFNT.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
|
@ -864,9 +849,6 @@
|
|||
<ClInclude Include="CCLabelTTF.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CCTextImage.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\base\etc1.h">
|
||||
<Filter>platform\etc</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -81,7 +81,7 @@ static id s_sharedDirectorCaller;
|
|||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
cocos2d::Director::getInstance()->drawScene();
|
||||
cocos2d::PoolManager::sharedPoolManager()->pop();
|
||||
cocos2d::PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
[[CCEventDispatcher sharedDispatcher] dispatchQueuedEvents];
|
||||
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:nil];
|
||||
|
|
|
@ -27,16 +27,26 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static PoolManager* s_pPoolManager = NULL;
|
||||
|
||||
AutoreleasePool::AutoreleasePool()
|
||||
:_name("")
|
||||
{
|
||||
_managedObjectArray.reserve(150);
|
||||
PoolManager::getInstance()->push(this);
|
||||
}
|
||||
|
||||
AutoreleasePool::AutoreleasePool(const std::string &name)
|
||||
:_name(name)
|
||||
{
|
||||
_managedObjectArray.reserve(150);
|
||||
PoolManager::getInstance()->push(this);
|
||||
}
|
||||
|
||||
AutoreleasePool::~AutoreleasePool()
|
||||
{
|
||||
CCLOGINFO("deallocing AutoreleasePool: %p", this);
|
||||
_managedObjectArray.clear();
|
||||
|
||||
PoolManager::getInstance()->pop();
|
||||
}
|
||||
|
||||
void AutoreleasePool::addObject(Object* object)
|
||||
|
@ -44,40 +54,26 @@ void AutoreleasePool::addObject(Object* object)
|
|||
_managedObjectArray.pushBack(object);
|
||||
|
||||
CCASSERT(object->_reference > 1, "reference count should be greater than 1");
|
||||
++(object->_autoReleaseCount);
|
||||
object->release(); // no ref count, in this case autorelease pool added.
|
||||
}
|
||||
|
||||
void AutoreleasePool::removeObject(Object* object)
|
||||
{
|
||||
for (unsigned int i = 0; i < object->_autoReleaseCount; ++i)
|
||||
{
|
||||
_managedObjectArray.eraseObject(object, false);
|
||||
}
|
||||
}
|
||||
|
||||
void AutoreleasePool::clear()
|
||||
{
|
||||
if (!_managedObjectArray.empty())
|
||||
{
|
||||
//CCAutoreleasePool* pReleasePool;
|
||||
#ifdef _DEBUG
|
||||
int nIndex = _managedObjectArray.size() - 1;
|
||||
#endif
|
||||
|
||||
for(const auto &obj : _managedObjectArray) {
|
||||
--(obj->_autoReleaseCount);
|
||||
//(*it)->release();
|
||||
//delete (*it);
|
||||
#ifdef _DEBUG
|
||||
nIndex--;
|
||||
#endif
|
||||
}
|
||||
|
||||
_managedObjectArray.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void AutoreleasePool::dump()
|
||||
{
|
||||
CCLOG("autorelease pool: %s, number of managed object %d\n", _name.c_str(), static_cast<int>(_managedObjectArray.size()));
|
||||
CCLOG("%20s%20s%20s", "Object pointer", "Object id", "reference count");
|
||||
for (const auto &obj : _managedObjectArray)
|
||||
{
|
||||
CCLOG("%20p%20u%20u\n", obj, obj->_ID, obj->retainCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
|
@ -85,105 +81,67 @@ void AutoreleasePool::clear()
|
|||
//
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
PoolManager* PoolManager::sharedPoolManager()
|
||||
PoolManager* PoolManager::s_singleInstance = nullptr;
|
||||
|
||||
PoolManager* PoolManager::getInstance()
|
||||
{
|
||||
if (s_pPoolManager == NULL)
|
||||
if (s_singleInstance == nullptr)
|
||||
{
|
||||
s_pPoolManager = new PoolManager();
|
||||
s_singleInstance = new PoolManager();
|
||||
// Add the first auto release pool
|
||||
s_singleInstance->_curReleasePool = new AutoreleasePool("cocos2d autorelease pool");
|
||||
s_singleInstance->_releasePoolStack.push(s_singleInstance->_curReleasePool);
|
||||
}
|
||||
return s_pPoolManager;
|
||||
return s_singleInstance;
|
||||
}
|
||||
|
||||
void PoolManager::purgePoolManager()
|
||||
void PoolManager::destroyInstance()
|
||||
{
|
||||
CC_SAFE_DELETE(s_pPoolManager);
|
||||
delete s_singleInstance;
|
||||
s_singleInstance = nullptr;
|
||||
}
|
||||
|
||||
PoolManager::PoolManager()
|
||||
{
|
||||
_releasePoolStack.reserve(150);
|
||||
_curReleasePool = 0;
|
||||
}
|
||||
|
||||
PoolManager::~PoolManager()
|
||||
{
|
||||
CCLOGINFO("deallocing PoolManager: %p", this);
|
||||
finalize();
|
||||
|
||||
// we only release the last autorelease pool here
|
||||
_curReleasePool = 0;
|
||||
_releasePoolStack.erase(0);
|
||||
}
|
||||
|
||||
void PoolManager::finalize()
|
||||
{
|
||||
if (!_releasePoolStack.empty())
|
||||
|
||||
while (!_releasePoolStack.empty())
|
||||
{
|
||||
for(const auto &pool : _releasePoolStack) {
|
||||
pool->clear();
|
||||
}
|
||||
AutoreleasePool* pool = _releasePoolStack.top();
|
||||
_releasePoolStack.pop();
|
||||
|
||||
delete pool;
|
||||
}
|
||||
}
|
||||
|
||||
void PoolManager::push()
|
||||
|
||||
AutoreleasePool* PoolManager::getCurrentPool() const
|
||||
{
|
||||
AutoreleasePool* pool = new AutoreleasePool(); //ref = 1
|
||||
return _curReleasePool;
|
||||
}
|
||||
|
||||
void PoolManager::push(AutoreleasePool *pool)
|
||||
{
|
||||
_releasePoolStack.push(pool);
|
||||
_curReleasePool = pool;
|
||||
|
||||
_releasePoolStack.pushBack(pool); //ref = 2
|
||||
|
||||
pool->release(); //ref = 1
|
||||
}
|
||||
|
||||
void PoolManager::pop()
|
||||
{
|
||||
if (! _curReleasePool)
|
||||
// Can not pop the pool that created by engine
|
||||
CC_ASSERT(_releasePoolStack.size() >= 1);
|
||||
|
||||
_releasePoolStack.pop();
|
||||
|
||||
// Should update _curReleasePool if a temple pool is released
|
||||
if (_releasePoolStack.size() > 1)
|
||||
{
|
||||
return;
|
||||
_curReleasePool = _releasePoolStack.top();
|
||||
}
|
||||
|
||||
ssize_t count = _releasePoolStack.size();
|
||||
|
||||
_curReleasePool->clear();
|
||||
|
||||
if (count > 1)
|
||||
{
|
||||
_releasePoolStack.erase(count-1);
|
||||
|
||||
// if(nCount > 1)
|
||||
// {
|
||||
// _curReleasePool = _releasePoolStack.at(count - 2);
|
||||
// return;
|
||||
// }
|
||||
_curReleasePool = _releasePoolStack.at(count - 2);
|
||||
}
|
||||
|
||||
/*_curReleasePool = NULL;*/
|
||||
}
|
||||
|
||||
void PoolManager::removeObject(Object* object)
|
||||
{
|
||||
CCASSERT(_curReleasePool, "current auto release pool should not be null");
|
||||
|
||||
_curReleasePool->removeObject(object);
|
||||
}
|
||||
|
||||
void PoolManager::addObject(Object* object)
|
||||
{
|
||||
getCurReleasePool()->addObject(object);
|
||||
}
|
||||
|
||||
|
||||
AutoreleasePool* PoolManager::getCurReleasePool()
|
||||
{
|
||||
if(!_curReleasePool)
|
||||
{
|
||||
push();
|
||||
}
|
||||
|
||||
CCASSERT(_curReleasePool, "current auto release pool should not be null");
|
||||
|
||||
return _curReleasePool;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -25,6 +25,8 @@ THE SOFTWARE.
|
|||
#ifndef __AUTORELEASEPOOL_H__
|
||||
#define __AUTORELEASEPOOL_H__
|
||||
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include "CCObject.h"
|
||||
#include "CCVector.h"
|
||||
|
||||
|
@ -35,24 +37,21 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CC_DLL AutoreleasePool : public Object
|
||||
class CC_DLL AutoreleasePool
|
||||
{
|
||||
/**
|
||||
* The underlying array of object managed by the pool.
|
||||
*
|
||||
* Although Array retains the object once when an object is added, proper
|
||||
* Object::release() is called outside the array to make sure that the pool
|
||||
* does not affect the managed object's reference count. So an object can
|
||||
* be destructed properly by calling Object::release() even if the object
|
||||
* is in the pool.
|
||||
*/
|
||||
Vector<Object*> _managedObjectArray;
|
||||
public:
|
||||
/**
|
||||
* @warn Don't create an auto release pool in heap, create it in stack.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
AutoreleasePool();
|
||||
|
||||
/**
|
||||
* Create an autorelease pool with specific name. This name is useful for debugging.
|
||||
*/
|
||||
AutoreleasePool(const std::string &name);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -72,15 +71,6 @@ public:
|
|||
*/
|
||||
void addObject(Object *object);
|
||||
|
||||
/**
|
||||
* Remove a given object from this pool.
|
||||
*
|
||||
* @param object The object to be removed from the pool.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void removeObject(Object *object);
|
||||
|
||||
/**
|
||||
* Clear the autorelease pool.
|
||||
*
|
||||
|
@ -90,88 +80,70 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Dump the objects that are put into autorelease pool. It is used for debugging.
|
||||
*
|
||||
* The result will look like:
|
||||
* Object pointer address object id reference count
|
||||
*
|
||||
*/
|
||||
void dump();
|
||||
|
||||
private:
|
||||
/**
|
||||
* The underlying array of object managed by the pool.
|
||||
*
|
||||
* Although Array retains the object once when an object is added, proper
|
||||
* Object::release() is called outside the array to make sure that the pool
|
||||
* does not affect the managed object's reference count. So an object can
|
||||
* be destructed properly by calling Object::release() even if the object
|
||||
* is in the pool.
|
||||
*/
|
||||
Vector<Object*> _managedObjectArray;
|
||||
std::string _name;
|
||||
};
|
||||
|
||||
class CC_DLL PoolManager
|
||||
{
|
||||
Vector<AutoreleasePool*> _releasePoolStack;
|
||||
AutoreleasePool *_curReleasePool;
|
||||
|
||||
AutoreleasePool *getCurReleasePool();
|
||||
public:
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static PoolManager* sharedPoolManager();
|
||||
CC_DEPRECATED_ATTRIBUTE static PoolManager* sharedPoolManager() { return getInstance(); }
|
||||
static PoolManager* getInstance();
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static void purgePoolManager();
|
||||
CC_DEPRECATED_ATTRIBUTE static void purgePoolManager() { destroyInstance(); }
|
||||
static void destroyInstance();
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Get current auto release pool, there is at least one auto release pool that created by engine.
|
||||
* You can create your own auto release pool at demand, which will be put into auto releae pool stack.
|
||||
*/
|
||||
PoolManager();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~PoolManager();
|
||||
AutoreleasePool *getCurrentPool() const;
|
||||
|
||||
/**
|
||||
* Clear all the AutoreleasePool on the pool stack.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void finalize();
|
||||
|
||||
/**
|
||||
* Push a new AutoreleasePool to the pool stack.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void push();
|
||||
|
||||
/**
|
||||
* Pop one AutoreleasePool from the pool stack.
|
||||
*
|
||||
* This method will ensure that there is at least one AutoreleasePool on
|
||||
* the stack.
|
||||
*
|
||||
* The AutoreleasePool being poped is destructed.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void pop();
|
||||
|
||||
/**
|
||||
* Remove a given object from the current autorelease pool.
|
||||
*
|
||||
* @param object The object to be removed.
|
||||
*
|
||||
* @see AutoreleasePool::removeObject
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void removeObject(Object *object);
|
||||
|
||||
/**
|
||||
* Add a given object to the current autorelease pool.
|
||||
*
|
||||
* @param object The object to add.
|
||||
*
|
||||
* @see AutoreleasePool::addObject
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void addObject(Object *object);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
friend class AutoreleasePool;
|
||||
|
||||
private:
|
||||
PoolManager();
|
||||
~PoolManager();
|
||||
|
||||
void push(AutoreleasePool *pool);
|
||||
void pop();
|
||||
|
||||
static PoolManager* s_singleInstance;
|
||||
|
||||
std::stack<AutoreleasePool*> _releasePoolStack;
|
||||
AutoreleasePool *_curReleasePool;
|
||||
};
|
||||
|
||||
// end of base_nodes group
|
||||
|
|
|
@ -25,10 +25,17 @@
|
|||
#ifndef __CCMAP_H__
|
||||
#define __CCMAP_H__
|
||||
|
||||
#define USE_STD_UNORDERED_MAP 1
|
||||
|
||||
#include "ccMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include <vector>
|
||||
|
||||
#if USE_STD_UNORDERED_MAP
|
||||
#include <unordered_map>
|
||||
#else
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -44,7 +51,11 @@ public:
|
|||
// ------------------------------------------
|
||||
// Iterators
|
||||
// ------------------------------------------
|
||||
#if USE_STD_UNORDERED_MAP
|
||||
typedef std::unordered_map<K, V> RefMap;
|
||||
#else
|
||||
typedef std::map<K, V> RefMap;
|
||||
#endif
|
||||
|
||||
typedef typename RefMap::iterator iterator;
|
||||
typedef typename RefMap::const_iterator const_iterator;
|
||||
|
@ -104,25 +115,39 @@ public:
|
|||
/** Sets capacity of the map */
|
||||
void reserve(ssize_t capacity)
|
||||
{
|
||||
#if USE_STD_UNORDERED_MAP
|
||||
_data.reserve(capacity);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Returns the number of buckets in the Map container. */
|
||||
ssize_t bucketCount() const
|
||||
{
|
||||
#if USE_STD_UNORDERED_MAP
|
||||
return _data.bucket_count();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Returns the number of elements in bucket n. */
|
||||
ssize_t bucketSize(ssize_t n) const
|
||||
{
|
||||
#if USE_STD_UNORDERED_MAP
|
||||
return _data.bucket_size(n);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Returns the bucket number where the element with key k is located. */
|
||||
ssize_t bucket(const K& k) const
|
||||
{
|
||||
#if USE_STD_UNORDERED_MAP
|
||||
return _data.bucket(k);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** The number of elements in the map. */
|
||||
|
@ -144,9 +169,11 @@ public:
|
|||
std::vector<K> keys() const
|
||||
{
|
||||
std::vector<K> keys;
|
||||
|
||||
|
||||
if (!_data.empty())
|
||||
{
|
||||
keys.reserve(_data.size());
|
||||
|
||||
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter)
|
||||
{
|
||||
keys.push_back(iter->first);
|
||||
|
@ -160,14 +187,21 @@ public:
|
|||
{
|
||||
std::vector<K> keys;
|
||||
|
||||
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter)
|
||||
if (!_data.empty())
|
||||
{
|
||||
if (iter->second == object)
|
||||
keys.reserve(_data.size() / 10);
|
||||
|
||||
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter)
|
||||
{
|
||||
keys.push_back(iter->first);
|
||||
if (iter->second == object)
|
||||
{
|
||||
keys.push_back(iter->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
keys.shrink_to_fit();
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ NS_CC_BEGIN
|
|||
Object::Object()
|
||||
: _luaID(0)
|
||||
, _reference(1) // when the object is created, the reference count of it is 1
|
||||
, _autoReleaseCount(0)
|
||||
{
|
||||
static unsigned int uObjectCount = 0;
|
||||
|
||||
|
@ -43,13 +42,6 @@ Object::Object()
|
|||
|
||||
Object::~Object()
|
||||
{
|
||||
// if the object is managed, we should remove it
|
||||
// from pool manager
|
||||
if (_autoReleaseCount > 0)
|
||||
{
|
||||
PoolManager::sharedPoolManager()->removeObject(this);
|
||||
}
|
||||
|
||||
// if the object is referenced by Lua engine, remove it
|
||||
if (_luaID)
|
||||
{
|
||||
|
@ -67,7 +59,7 @@ Object::~Object()
|
|||
|
||||
Object* Object::autorelease()
|
||||
{
|
||||
PoolManager::sharedPoolManager()->addObject(this);
|
||||
PoolManager::getInstance()->getCurrentPool()->addObject(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,14 +71,12 @@ class CC_DLL Object
|
|||
{
|
||||
public:
|
||||
/// object id, ScriptSupport need public _ID
|
||||
unsigned int _ID;
|
||||
unsigned int _ID;
|
||||
/// Lua reference id
|
||||
int _luaID;
|
||||
int _luaID;
|
||||
protected:
|
||||
/// count of references
|
||||
unsigned int _reference;
|
||||
/// count of autorelease
|
||||
unsigned int _autoReleaseCount;
|
||||
unsigned int _reference;
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
|
|
|
@ -142,7 +142,7 @@ static int readTuple (const char* end, Str tuple[]) {
|
|||
}
|
||||
|
||||
static char* mallocString (Str* str) {
|
||||
int length = str->end - str->begin;
|
||||
long length = str->end - str->begin;
|
||||
char* string = MALLOC(char, length + 1);
|
||||
memcpy(string, str->begin, length);
|
||||
string[length] = '\0';
|
||||
|
@ -150,7 +150,7 @@ static char* mallocString (Str* str) {
|
|||
}
|
||||
|
||||
static int indexOf (const char** array, int count, Str* str) {
|
||||
int length = str->end - str->begin;
|
||||
long length = str->end - str->begin;
|
||||
int i;
|
||||
for (i = count - 1; i >= 0; i--)
|
||||
if (strncmp(array[i], str->begin, length) == 0) return i;
|
||||
|
@ -162,7 +162,7 @@ static int equals (Str* str, const char* other) {
|
|||
}
|
||||
|
||||
static int toInt (Str* str) {
|
||||
return strtol(str->begin, (char**)&str->end, 10);
|
||||
return static_cast<int>(strtol(str->begin, (char**)&str->end, 10));
|
||||
}
|
||||
|
||||
static spAtlas* abortAtlas (spAtlas* self) {
|
||||
|
@ -177,7 +177,7 @@ static const char* textureFilterNames[] = {"Nearest", "Linear", "MipMap", "MipMa
|
|||
spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
|
||||
int count;
|
||||
const char* end = begin + length;
|
||||
int dirLength = strlen(dir);
|
||||
size_t dirLength = strlen(dir);
|
||||
int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\';
|
||||
|
||||
spAtlas* self = NEW(spAtlas);
|
||||
|
@ -289,7 +289,7 @@ spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
|
|||
}
|
||||
|
||||
spAtlas* spAtlas_readAtlasFile (const char* path) {
|
||||
int dirLength;
|
||||
long dirLength;
|
||||
char *dir;
|
||||
int length;
|
||||
const char* data;
|
||||
|
|
|
@ -235,7 +235,7 @@ void Layout::stencilClippingVisit()
|
|||
{
|
||||
auto node = _children.at(i);
|
||||
|
||||
if ( node && node->getZOrder() < 0 )
|
||||
if ( node && node->getLocalZOrder() < 0 )
|
||||
node->visit();
|
||||
else
|
||||
break;
|
||||
|
|
|
@ -255,7 +255,7 @@ Widget* Widget::getChildByName(const char *name)
|
|||
|
||||
void Widget::addNode(Node* node)
|
||||
{
|
||||
addNode(node, node->getZOrder(), node->getTag());
|
||||
addNode(node, node->getLocalZOrder(), node->getTag());
|
||||
}
|
||||
|
||||
void Widget::addNode(Node * node, int zOrder)
|
||||
|
|
|
@ -28,9 +28,12 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "SocketIO.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCScheduler.h"
|
||||
#include "WebSocket.h"
|
||||
#include "HttpClient.h"
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -59,7 +59,10 @@ in the onClose method the pointer should be set to NULL or used to connect to a
|
|||
#ifndef __CC_SOCKETIO_H__
|
||||
#define __CC_SOCKETIO_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCMap.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "WebSocket.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCScheduler.h"
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
@ -521,7 +523,7 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx,
|
|||
|
||||
size_t remaining = data->len - data->issued;
|
||||
size_t n = std::min(remaining, c_bufferSize );
|
||||
CCLOG("[websocket:send] total: %d, sent: %d, remaining: %d, buffer size: %d", data->len, data->issued, remaining, n);
|
||||
CCLOG("[websocket:send] total: %d, sent: %d, remaining: %d, buffer size: %d", static_cast<int>(data->len), static_cast<int>(data->issued), static_cast<int>(remaining), static_cast<int>(n));
|
||||
|
||||
unsigned char* buf = new unsigned char[LWS_SEND_BUFFER_PRE_PADDING + n + LWS_SEND_BUFFER_POST_PADDING];
|
||||
|
||||
|
|
|
@ -30,8 +30,11 @@
|
|||
#ifndef __CC_WEBSOCKET_H__
|
||||
#define __CC_WEBSOCKET_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCStdC.h"
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct libwebsocket;
|
||||
struct libwebsocket_context;
|
||||
|
@ -153,8 +156,8 @@ private:
|
|||
unsigned int _port;
|
||||
std::string _path;
|
||||
|
||||
size_t _pendingFrameDataLen;
|
||||
unsigned int _currentDataLen;
|
||||
ssize_t _pendingFrameDataLen;
|
||||
ssize_t _currentDataLen;
|
||||
char *_currentData;
|
||||
|
||||
friend class WsThreadHelper;
|
||||
|
|
|
@ -1 +1 @@
|
|||
f92acd30f26c52238e94d2ef1f5b11e760980a67
|
||||
46ff200bdf412bcf4cfe2d6ceebadf60657fc4eb
|
|
@ -24,15 +24,15 @@ JSBool JSB_localStorageGetItem(JSContext *cx, uint32_t argc, jsval *vp) {
|
|||
JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" );
|
||||
jsval *argvp = JS_ARGV(cx,vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
const char* arg0;
|
||||
std::string arg0;
|
||||
|
||||
ok &= jsval_to_charptr( cx, *argvp++, &arg0 );
|
||||
ok &= jsval_to_std_string( cx, *argvp++, &arg0 );
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
const char* ret_val;
|
||||
std::string ret_val;
|
||||
|
||||
ret_val = localStorageGetItem((char*)arg0 );
|
||||
ret_val = localStorageGetItem(arg0);
|
||||
|
||||
jsval ret_jsval = c_string_to_jsval(cx, ret_val ? ret_val : "");
|
||||
jsval ret_jsval = std_string_to_jsval(cx, ret_val);
|
||||
JS_SET_RVAL(cx, vp, ret_jsval );
|
||||
|
||||
return JS_TRUE;
|
||||
|
@ -44,12 +44,12 @@ JSBool JSB_localStorageRemoveItem(JSContext *cx, uint32_t argc, jsval *vp) {
|
|||
JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" );
|
||||
jsval *argvp = JS_ARGV(cx,vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
const char* arg0;
|
||||
std::string arg0;
|
||||
|
||||
ok &= jsval_to_charptr( cx, *argvp++, &arg0 );
|
||||
ok &= jsval_to_std_string( cx, *argvp++, &arg0 );
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
|
||||
localStorageRemoveItem((char*)arg0 );
|
||||
localStorageRemoveItem(arg0);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -60,13 +60,13 @@ JSBool JSB_localStorageSetItem(JSContext *cx, uint32_t argc, jsval *vp) {
|
|||
JSB_PRECONDITION2( argc == 2, cx, JS_FALSE, "Invalid number of arguments" );
|
||||
jsval *argvp = JS_ARGV(cx,vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
const char* arg0; const char* arg1;
|
||||
std::string arg0; std::string arg1;
|
||||
|
||||
ok &= jsval_to_charptr( cx, *argvp++, &arg0 );
|
||||
ok &= jsval_to_charptr( cx, *argvp++, &arg1 );
|
||||
ok &= jsval_to_std_string( cx, *argvp++, &arg0 );
|
||||
ok &= jsval_to_std_string( cx, *argvp++, &arg1 );
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
|
||||
localStorageSetItem((char*)arg0 , (char*)arg1 );
|
||||
localStorageSetItem(arg0 , arg1);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
9d9d07e19dba691a22e4d184f0ec0e6ae6207a9b
|
||||
85c7400aec0f87b3851772fbdbc01bf59f5402d8
|
|
@ -359,3 +359,11 @@ cc.GLYPHCOLLECTION_NEHE = 1
|
|||
cc.GLYPHCOLLECTION_ASCII = 2
|
||||
cc.GLYPHCOLLECTION_CUSTOM = 3
|
||||
|
||||
cc.LabelEffect =
|
||||
{
|
||||
NORMAL = 0,
|
||||
OUTLINE = 1,
|
||||
SHADOW = 2,
|
||||
GLOW = 3,
|
||||
}
|
||||
|
||||
|
|
|
@ -1112,3 +1112,19 @@ end
|
|||
rawset(CCEGLView,"sharedOpenGLView",CCEGLViewDeprecated.sharedOpenGLView)
|
||||
--functions of CCEGLView will be deprecated end
|
||||
|
||||
--functions of cc.Node will be deprecated begin
|
||||
local NodeDeprecated = { }
|
||||
function NodeDeprecated.setZOrder(self,zOrder)
|
||||
deprecatedTip("cc.Node:setZOrder","cc.Node:setLocalZOrder")
|
||||
return self:setLocalZOrder(zOrder)
|
||||
end
|
||||
rawset(cc.Node,"setZOrder",NodeDeprecated.setZOrder)
|
||||
|
||||
function NodeDeprecated.getZOrder(self)
|
||||
deprecatedTip("cc.Node:getZOrder","cc.Node:getLocalZOrder")
|
||||
return self:getLocalZOrder()
|
||||
end
|
||||
rawset(cc.Node,"getZOrder",NodeDeprecated.getZOrder)
|
||||
--functions of cc.Node will be deprecated end
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
Works on cocos2d-iphone and cocos2d-x.
|
||||
*/
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "LocalStorage.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
|
||||
|
||||
|
@ -55,16 +56,16 @@ static void localStorageCreateTable()
|
|||
printf("Error in CREATE TABLE\n");
|
||||
}
|
||||
|
||||
void localStorageInit( const char *fullpath)
|
||||
void localStorageInit( const std::string& fullpath/* = "" */)
|
||||
{
|
||||
if( ! _initialized ) {
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (!fullpath)
|
||||
if (fullpath.empty())
|
||||
ret = sqlite3_open(":memory:",&_db);
|
||||
else
|
||||
ret = sqlite3_open(fullpath, &_db);
|
||||
ret = sqlite3_open(fullpath.c_str(), &_db);
|
||||
|
||||
localStorageCreateTable();
|
||||
|
||||
|
@ -103,12 +104,12 @@ void localStorageFree()
|
|||
}
|
||||
|
||||
/** sets an item in the LS */
|
||||
void localStorageSetItem( const char *key, const char *value)
|
||||
void localStorageSetItem( const std::string& key, const std::string& value)
|
||||
{
|
||||
assert( _initialized );
|
||||
|
||||
int ok = sqlite3_bind_text(_stmt_update, 1, key, -1, SQLITE_TRANSIENT);
|
||||
ok |= sqlite3_bind_text(_stmt_update, 2, value, -1, SQLITE_TRANSIENT);
|
||||
int ok = sqlite3_bind_text(_stmt_update, 1, key.c_str(), -1, SQLITE_TRANSIENT);
|
||||
ok |= sqlite3_bind_text(_stmt_update, 2, value.c_str(), -1, SQLITE_TRANSIENT);
|
||||
|
||||
ok |= sqlite3_step(_stmt_update);
|
||||
|
||||
|
@ -119,13 +120,13 @@ void localStorageSetItem( const char *key, const char *value)
|
|||
}
|
||||
|
||||
/** gets an item from the LS */
|
||||
const char* localStorageGetItem( const char *key )
|
||||
std::string localStorageGetItem( const std::string& key )
|
||||
{
|
||||
assert( _initialized );
|
||||
|
||||
int ok = sqlite3_reset(_stmt_select);
|
||||
|
||||
ok |= sqlite3_bind_text(_stmt_select, 1, key, -1, SQLITE_TRANSIENT);
|
||||
ok |= sqlite3_bind_text(_stmt_select, 1, key.c_str(), -1, SQLITE_TRANSIENT);
|
||||
ok |= sqlite3_step(_stmt_select);
|
||||
const unsigned char *ret = sqlite3_column_text(_stmt_select, 0);
|
||||
|
||||
|
@ -137,11 +138,11 @@ const char* localStorageGetItem( const char *key )
|
|||
}
|
||||
|
||||
/** removes an item from the LS */
|
||||
void localStorageRemoveItem( const char *key )
|
||||
void localStorageRemoveItem( const std::string& key )
|
||||
{
|
||||
assert( _initialized );
|
||||
|
||||
int ok = sqlite3_bind_text(_stmt_remove, 1, key, -1, SQLITE_TRANSIENT);
|
||||
int ok = sqlite3_bind_text(_stmt_remove, 1, key.c_str(), -1, SQLITE_TRANSIENT);
|
||||
|
||||
ok |= sqlite3_step(_stmt_remove);
|
||||
|
||||
|
|
|
@ -30,22 +30,21 @@ THE SOFTWARE.
|
|||
#ifndef __JSB_LOCALSTORAGE_H
|
||||
#define __JSB_LOCALSTORAGE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
/** Initializes the database. If path is null, it will create an in-memory DB */
|
||||
void localStorageInit( const char *fullpath);
|
||||
void localStorageInit( const std::string& fullpath = "");
|
||||
|
||||
/** Frees the allocated resources */
|
||||
void localStorageFree();
|
||||
|
||||
/** sets an item in the LS */
|
||||
void localStorageSetItem( const char *key, const char *value);
|
||||
void localStorageSetItem( const std::string& key, const std::string& value);
|
||||
|
||||
/** gets an item from the LS */
|
||||
const char* localStorageGetItem( const char *key );
|
||||
std::string localStorageGetItem( const std::string& key );
|
||||
|
||||
/** removes an item from the LS */
|
||||
void localStorageRemoveItem( const char *key );
|
||||
void localStorageRemoveItem( const std::string& key );
|
||||
|
||||
#endif // __JSB_LOCALSTORAGE_H
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
Works on cocos2d-iphone and cocos2d-x.
|
||||
*/
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "LocalStorage.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include "jni.h"
|
||||
#include "jni/JniHelper.h"
|
||||
|
||||
|
@ -52,27 +52,28 @@ static void splitFilename (std::string& str)
|
|||
}
|
||||
}
|
||||
|
||||
void localStorageInit( const char *fullpath)
|
||||
void localStorageInit( const std::string& fullpath)
|
||||
{
|
||||
if (fullpath == NULL || strlen(fullpath) == 0) return;
|
||||
if (fullpath.empty())
|
||||
return;
|
||||
|
||||
if( ! _initialized ) {
|
||||
JniMethodInfo t;
|
||||
if( ! _initialized )
|
||||
{
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "init", "(Ljava/lang/String;Ljava/lang/String;)Z")) {
|
||||
std::string strDBFilename = fullpath;
|
||||
splitFilename(strDBFilename);
|
||||
jstring jdbName = t.env->NewStringUTF(strDBFilename.c_str());
|
||||
jstring jtableName = t.env->NewStringUTF("data");
|
||||
jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, jdbName, jtableName);
|
||||
t.env->DeleteLocalRef(jdbName);
|
||||
t.env->DeleteLocalRef(jtableName);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
if (ret) {
|
||||
_initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "init", "(Ljava/lang/String;Ljava/lang/String;)Z")) {
|
||||
std::string strDBFilename = fullpath;
|
||||
splitFilename(strDBFilename);
|
||||
jstring jdbName = t.env->NewStringUTF(strDBFilename.c_str());
|
||||
jstring jtableName = t.env->NewStringUTF("data");
|
||||
jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, jdbName, jtableName);
|
||||
t.env->DeleteLocalRef(jdbName);
|
||||
t.env->DeleteLocalRef(jtableName);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
if (ret) {
|
||||
_initialized = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,15 +94,15 @@ void localStorageFree()
|
|||
}
|
||||
|
||||
/** sets an item in the LS */
|
||||
void localStorageSetItem( const char *key, const char *value)
|
||||
void localStorageSetItem( const std::string& key, const std::string& value)
|
||||
{
|
||||
assert( _initialized );
|
||||
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "setItem", "(Ljava/lang/String;Ljava/lang/String;)V")) {
|
||||
jstring jkey = t.env->NewStringUTF(key);
|
||||
jstring jvalue = t.env->NewStringUTF(value);
|
||||
jstring jkey = t.env->NewStringUTF(key.c_str());
|
||||
jstring jvalue = t.env->NewStringUTF(value.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, jkey, jvalue);
|
||||
t.env->DeleteLocalRef(jkey);
|
||||
t.env->DeleteLocalRef(jvalue);
|
||||
|
@ -110,30 +111,31 @@ void localStorageSetItem( const char *key, const char *value)
|
|||
}
|
||||
|
||||
/** gets an item from the LS */
|
||||
const char* localStorageGetItem( const char *key )
|
||||
std::string localStorageGetItem( const std::string& key )
|
||||
{
|
||||
assert( _initialized );
|
||||
JniMethodInfo t;
|
||||
String* pStr = NULL;
|
||||
|
||||
std::string ret;
|
||||
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "getItem", "(Ljava/lang/String;)Ljava/lang/String;")) {
|
||||
jstring jkey = t.env->NewStringUTF(key);
|
||||
jstring ret = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, jkey);
|
||||
pStr = String::create(JniHelper::jstring2string(ret));
|
||||
t.env->DeleteLocalRef(ret);
|
||||
jstring jkey = t.env->NewStringUTF(key.c_str());
|
||||
jstring jret = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, jkey);
|
||||
ret = JniHelper::jstring2string(jret);
|
||||
t.env->DeleteLocalRef(jret);
|
||||
t.env->DeleteLocalRef(jkey);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
return pStr ? pStr->getCString() : NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** removes an item from the LS */
|
||||
void localStorageRemoveItem( const char *key )
|
||||
void localStorageRemoveItem( const std::string& key )
|
||||
{
|
||||
assert( _initialized );
|
||||
JniMethodInfo t;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "removeItem", "(Ljava/lang/String;)V")) {
|
||||
jstring jkey = t.env->NewStringUTF(key);
|
||||
jstring jkey = t.env->NewStringUTF(key.c_str());
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, jkey);
|
||||
t.env->DeleteLocalRef(jkey);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
|
|
|
@ -572,7 +572,7 @@ void ScrollView::visit()
|
|||
for( ; i < _children.size(); i++ )
|
||||
{
|
||||
Node *child = _children.at(i);
|
||||
if ( child->getZOrder() < 0 )
|
||||
if ( child->getLocalZOrder() < 0 )
|
||||
{
|
||||
child->visit();
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ Classes/PerformanceTest/PerformanceLabelTest.cpp \
|
|||
Classes/PerformanceTest/PerformanceRendererTest.cpp \
|
||||
Classes/PerformanceTest/PerformanceContainerTest.cpp \
|
||||
Classes/PhysicsTest/PhysicsTest.cpp \
|
||||
Classes/ReleasePoolTest/ReleasePoolTest.cpp \
|
||||
Classes/RenderTextureTest/RenderTextureTest.cpp \
|
||||
Classes/RotateWorldTest/RotateWorldTest.cpp \
|
||||
Classes/SceneTest/SceneTest.cpp \
|
||||
|
|
|
@ -119,6 +119,7 @@ set(SAMPLE_SRC
|
|||
Classes/PerformanceTest/PerformanceRendererTest.cpp
|
||||
Classes/PerformanceTest/PerformanceContainerTest.cpp
|
||||
Classes/PhysicsTest/PhysicsTest.cpp
|
||||
Classes/ReleasePoolTest/ReleasePoolTest.cpp
|
||||
Classes/RenderTextureTest/RenderTextureTest.cpp
|
||||
Classes/RotateWorldTest/RotateWorldTest.cpp
|
||||
Classes/SceneTest/SceneTest.cpp
|
||||
|
|
|
@ -22,6 +22,7 @@ std::function<Layer*()> createFunctions[] =
|
|||
CL(RemoveAndRetainNodeTest),
|
||||
CL(RemoveListenerAfterAddingTest),
|
||||
CL(DirectorEventTest),
|
||||
CL(GlobalZTouchTest),
|
||||
};
|
||||
|
||||
unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
|
||||
|
@ -859,4 +860,88 @@ std::string DirectorEventTest::subtitle() const
|
|||
return "after visit, after draw, after update, projection changed";
|
||||
}
|
||||
|
||||
// GlobalZTouchTest
|
||||
GlobalZTouchTest::GlobalZTouchTest()
|
||||
: _sprite(nullptr)
|
||||
, _accum(0)
|
||||
{
|
||||
|
||||
auto listener1 = EventListenerTouchOneByOne::create();
|
||||
listener1->setSwallowTouches(true);
|
||||
|
||||
listener1->onTouchBegan = [](Touch* touch, Event* event){
|
||||
auto target = static_cast<Sprite*>(event->getCurrentTarget());
|
||||
|
||||
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
|
||||
Size s = target->getContentSize();
|
||||
Rect rect = Rect(0, 0, s.width, s.height);
|
||||
|
||||
if (rect.containsPoint(locationInNode))
|
||||
{
|
||||
log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y);
|
||||
target->setOpacity(180);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
listener1->onTouchMoved = [](Touch* touch, Event* event){
|
||||
auto target = static_cast<Sprite*>(event->getCurrentTarget());
|
||||
target->setPosition(target->getPosition() + touch->getDelta());
|
||||
};
|
||||
|
||||
listener1->onTouchEnded = [=](Touch* touch, Event* event){
|
||||
auto target = static_cast<Sprite*>(event->getCurrentTarget());
|
||||
log("sprite onTouchesEnded.. ");
|
||||
target->setOpacity(255);
|
||||
};
|
||||
|
||||
const int SPRITE_COUNT = 8;
|
||||
|
||||
for (int i = 0; i < SPRITE_COUNT; i++)
|
||||
{
|
||||
Sprite *sprite;
|
||||
auto parent = Node::create();
|
||||
if(i==4)
|
||||
{
|
||||
sprite = Sprite::create("Images/CyanSquare.png");
|
||||
_sprite = sprite;
|
||||
_sprite->setGlobalZOrder(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite = Sprite::create("Images/YellowSquare.png");
|
||||
}
|
||||
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1->clone(), sprite);
|
||||
|
||||
parent->addChild(sprite);
|
||||
this->addChild(parent);
|
||||
|
||||
Size visibleSize = Director::getInstance()->getVisibleSize();
|
||||
sprite->setPosition(VisibleRect::left().x + visibleSize.width / (SPRITE_COUNT - 1) * i, VisibleRect::center().y);
|
||||
}
|
||||
|
||||
this->scheduleUpdate();
|
||||
}
|
||||
|
||||
void GlobalZTouchTest::update(float dt)
|
||||
{
|
||||
_accum += dt;
|
||||
if( _accum > 2.0f) {
|
||||
float z = _sprite->getGlobalZOrder();
|
||||
_sprite->setGlobalZOrder(-z);
|
||||
_accum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string GlobalZTouchTest::title() const
|
||||
{
|
||||
return "Global Z Value, Try touch blue sprite";
|
||||
}
|
||||
|
||||
std::string GlobalZTouchTest::subtitle() const
|
||||
{
|
||||
return "Blue Sprite should change go from foreground to background";
|
||||
}
|
||||
|
||||
|
|
|
@ -135,4 +135,20 @@ protected:
|
|||
EventListenerCustom *_event1, *_event2, *_event3, *_event4;
|
||||
};
|
||||
|
||||
class GlobalZTouchTest : public EventDispatcherTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(GlobalZTouchTest);
|
||||
GlobalZTouchTest();
|
||||
|
||||
virtual void update(float dt) override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
protected:
|
||||
Sprite* _sprite;
|
||||
float _accum;
|
||||
};
|
||||
|
||||
#endif /* defined(__samples__NewEventDispatcherTest__) */
|
||||
|
|
|
@ -1790,7 +1790,7 @@ void ReorderParticleSystems::onEnter()
|
|||
void ReorderParticleSystems::reorderSystem(float time)
|
||||
{
|
||||
auto system = static_cast<ParticleSystem*>(_batchNode->getChildren().at(1));
|
||||
_batchNode->reorderChild(system, system->getZOrder() - 1);
|
||||
_batchNode->reorderChild(system, system->getLocalZOrder() - 1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,11 @@
|
|||
static std::function<PerformanceContainerScene*()> createFunctions[] =
|
||||
{
|
||||
CL(TemplateVectorPerfTest),
|
||||
CL(ArrayPerfTest)
|
||||
CL(ArrayPerfTest),
|
||||
CL(TemplateMapStringKeyPerfTest),
|
||||
CL(DictionaryStringKeyPerfTest),
|
||||
CL(TemplateMapIntKeyPerfTest),
|
||||
CL(DictionaryIntKeyPerfTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
@ -264,27 +268,6 @@ void PerformanceContainerScene::updateProfilerName()
|
|||
snprintf(_profilerName, sizeof(_profilerName)-1, "%s(%d)", testName(), quantityOfNodes);
|
||||
}
|
||||
|
||||
void PerformanceContainerScene::onExitTransitionDidStart()
|
||||
{
|
||||
Scene::onExitTransitionDidStart();
|
||||
|
||||
auto director = Director::getInstance();
|
||||
auto sched = director->getScheduler();
|
||||
|
||||
sched->unscheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this);
|
||||
}
|
||||
|
||||
void PerformanceContainerScene::onEnterTransitionDidFinish()
|
||||
{
|
||||
Scene::onEnterTransitionDidFinish();
|
||||
|
||||
auto director = Director::getInstance();
|
||||
auto sched = director->getScheduler();
|
||||
|
||||
CC_PROFILER_PURGE_ALL();
|
||||
sched->scheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false);
|
||||
}
|
||||
|
||||
void PerformanceContainerScene::dumpProfilerInfo(float dt)
|
||||
{
|
||||
CC_PROFILER_DISPLAY_TIMERS();
|
||||
|
@ -507,8 +490,6 @@ void TemplateVectorPerfTest::generateTestFunctions()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string TemplateVectorPerfTest::title() const
|
||||
{
|
||||
return "Vector<T> Perf test";
|
||||
|
@ -519,8 +500,6 @@ std::string TemplateVectorPerfTest::subtitle() const
|
|||
return "Test 'pushBack', See console";
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ArrayPerfTest
|
||||
|
@ -701,6 +680,685 @@ void ArrayPerfTest::generateTestFunctions()
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// TemplateMapStringKeyPerfTest
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void TemplateMapStringKeyPerfTest::generateTestFunctions()
|
||||
{
|
||||
auto createMap = [this](){
|
||||
Map<std::string, Node*> ret;
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
ret.insert(StringUtils::format("key_%d", i), node);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
TestFunction testFunctions[] = {
|
||||
{ "insert", [=](){
|
||||
Map<std::string, Node*> map;
|
||||
|
||||
std::string* keys = new std::string[quantityOfNodes];
|
||||
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
keys[i] = StringUtils::format("key_%d", i);
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
map.insert(keys[i], Node::create());
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(keys);
|
||||
} } ,
|
||||
|
||||
{ "at", [=](){
|
||||
Map<std::string, Node*> map = createMap();
|
||||
|
||||
std::string* keys = new std::string[quantityOfNodes];
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
keys[i] = StringUtils::format("key_%d", i);
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
nodes[i] = map.at(keys[i]);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(keys);
|
||||
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
nodes[i]->setTag(100);
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "erase", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
std::string* keys = new std::string[quantityOfNodes];
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
keys[i] = StringUtils::format("key_%d", i);
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
map.erase(keys[i]);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(keys);
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "clear", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
map.clear();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "size", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
ssize_t size = 0;
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
size = map.size();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "keys(all)", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = map.keys();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
std::string allKeysString;
|
||||
for (const auto& key : keys)
|
||||
{
|
||||
allKeysString += "_" + key;
|
||||
}
|
||||
} } ,
|
||||
|
||||
{ "keys(object)", [=](){
|
||||
Map<std::string, Node*> map;
|
||||
|
||||
Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes);
|
||||
Node* sameNode = Node::create();
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
if (quantityOfNodes % 100 == 0)
|
||||
{
|
||||
map.insert(StringUtils::format("key_%d", i), sameNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
map.insert(StringUtils::format("key_%d", i), node);
|
||||
}
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = map.keys(sameNode);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
std::string allKeysString;
|
||||
for (const auto& key : keys)
|
||||
{
|
||||
allKeysString += "_" + key;
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "c++11 range loop", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
|
||||
for (const auto& e : map)
|
||||
{
|
||||
e.second->setTag(100);
|
||||
}
|
||||
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
};
|
||||
|
||||
for (const auto& func : testFunctions)
|
||||
{
|
||||
_testFunctions.push_back(func);
|
||||
}
|
||||
}
|
||||
|
||||
std::string TemplateMapStringKeyPerfTest::title() const
|
||||
{
|
||||
return "Map<T> String Key Perf test";
|
||||
}
|
||||
|
||||
std::string TemplateMapStringKeyPerfTest::subtitle() const
|
||||
{
|
||||
return "Test 'insert', See console";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// DictionaryStringKeyPerfTest
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void DictionaryStringKeyPerfTest::generateTestFunctions()
|
||||
{
|
||||
auto createDict = [this](){
|
||||
Dictionary* ret = Dictionary::create();
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
ret->setObject(node, StringUtils::format("key_%d", i));
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
TestFunction testFunctions[] = {
|
||||
{ "setObject", [=](){
|
||||
Dictionary* dict = Dictionary::create();
|
||||
|
||||
std::string* keys = new std::string[quantityOfNodes];
|
||||
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
keys[i] = StringUtils::format("key_%d", i);
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
dict->setObject(Node::create(), keys[i]);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(keys);
|
||||
} } ,
|
||||
|
||||
{ "objectForKey", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
std::string* keys = new std::string[quantityOfNodes];
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
keys[i] = StringUtils::format("key_%d", i);
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
nodes[i] = static_cast<Node*>(dict->objectForKey(keys[i]));
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(keys);
|
||||
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
nodes[i]->setTag(100);
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "removeObjectForKey", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
std::string* keys = new std::string[quantityOfNodes];
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
keys[i] = StringUtils::format("key_%d", i);
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
dict->removeObjectForKey(keys[i]);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(keys);
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "removeAllObjects", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
dict->removeAllObjects();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "count", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
ssize_t size = 0;
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
size = dict->count();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "allKeys", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = dict->allKeys();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
std::string allKeysString;
|
||||
Object* obj;
|
||||
CCARRAY_FOREACH(keys, obj)
|
||||
{
|
||||
auto key = static_cast<String*>(obj);
|
||||
allKeysString += (std::string("_") + key->getCString());
|
||||
}
|
||||
} } ,
|
||||
|
||||
{ "allKeysForObject", [=](){
|
||||
Dictionary* dict = Dictionary::create();
|
||||
|
||||
Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes);
|
||||
Node* sameNode = Node::create();
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
if (quantityOfNodes % 100 == 0)
|
||||
{
|
||||
dict->setObject(sameNode, StringUtils::format("key_%d", i));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
dict->setObject(node, StringUtils::format("key_%d", i));
|
||||
}
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = dict->allKeysForObject(sameNode);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
std::string allKeysString;
|
||||
Object* obj;
|
||||
CCARRAY_FOREACH(keys, obj)
|
||||
{
|
||||
auto key = static_cast<String*>(obj);
|
||||
allKeysString += (std::string("_") + key->getCString());
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "CCDICT_FOREACH", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
|
||||
DictElement* e = nullptr;
|
||||
CCDICT_FOREACH(dict, e)
|
||||
{
|
||||
static_cast<Node*>(e->getObject())->setTag(100);
|
||||
}
|
||||
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
};
|
||||
|
||||
for (const auto& func : testFunctions)
|
||||
{
|
||||
_testFunctions.push_back(func);
|
||||
}
|
||||
}
|
||||
|
||||
std::string DictionaryStringKeyPerfTest::title() const
|
||||
{
|
||||
return "Dictionary String Key Perf test";
|
||||
}
|
||||
|
||||
std::string DictionaryStringKeyPerfTest::subtitle() const
|
||||
{
|
||||
return "Test `setObject`, See console";
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// TemplateMapIntKeyPerfTest
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void TemplateMapIntKeyPerfTest::generateTestFunctions()
|
||||
{
|
||||
auto createMap = [this](){
|
||||
Map<int, Node*> ret;
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
ret.insert(100+i, node);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
TestFunction testFunctions[] = {
|
||||
{ "insert", [=](){
|
||||
Map<int, Node*> map;
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
map.insert(100 + i, Node::create());
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "at", [=](){
|
||||
auto map = createMap();
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
nodes[i] = map.at(100 + i);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
nodes[i]->setTag(100);
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "erase", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
map.erase(100 + i);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "clear", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
map.clear();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "size", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
ssize_t size = 0;
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
size = map.size();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "keys(all)", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = map.keys();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
int allKeysInt = 0;
|
||||
for (const auto& key : keys)
|
||||
{
|
||||
allKeysInt += key;
|
||||
}
|
||||
} } ,
|
||||
|
||||
{ "keys(object)", [=](){
|
||||
Map<int, Node*> map;
|
||||
|
||||
Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes);
|
||||
Node* sameNode = Node::create();
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
if (quantityOfNodes % 100 == 0)
|
||||
{
|
||||
map.insert(100 + i, sameNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
map.insert(100 + i, node);
|
||||
}
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = map.keys(sameNode);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
int allKeysInt = 0;
|
||||
for (const auto& key : keys)
|
||||
{
|
||||
allKeysInt += key;
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "c++11 range loop", [=](){
|
||||
auto map = createMap();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
|
||||
for (const auto& e : map)
|
||||
{
|
||||
e.second->setTag(100);
|
||||
}
|
||||
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
};
|
||||
|
||||
for (const auto& func : testFunctions)
|
||||
{
|
||||
_testFunctions.push_back(func);
|
||||
}
|
||||
}
|
||||
|
||||
std::string TemplateMapIntKeyPerfTest::title() const
|
||||
{
|
||||
return "Map<T> Integer Key Perf test";
|
||||
}
|
||||
|
||||
std::string TemplateMapIntKeyPerfTest::subtitle() const
|
||||
{
|
||||
return "Test 'insert', See console";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// DictionaryIntKeyPerfTest
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void DictionaryIntKeyPerfTest::generateTestFunctions()
|
||||
{
|
||||
auto createDict = [this](){
|
||||
Dictionary* ret = Dictionary::create();
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
ret->setObject(node, 100 + i);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
TestFunction testFunctions[] = {
|
||||
{ "setObject", [=](){
|
||||
Dictionary* dict = Dictionary::create();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
dict->setObject(Node::create(), 100 + i);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "objectForKey", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
nodes[i] = static_cast<Node*>(dict->objectForKey(100 + i));
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
for (int i = 0; i < quantityOfNodes; ++i)
|
||||
{
|
||||
nodes[i]->setTag(100);
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "removeObjectForKey", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
dict->removeObjectForKey(100 + i);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "removeAllObjects", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
dict->removeAllObjects();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "count", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
unsigned int size = 0;
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
size = dict->count();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
|
||||
{ "allKeys", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = dict->allKeys();
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
int allKeysInt = 0;
|
||||
Object* obj;
|
||||
CCARRAY_FOREACH(keys, obj)
|
||||
{
|
||||
auto key = static_cast<Integer*>(obj);
|
||||
allKeysInt += key->getValue();
|
||||
}
|
||||
} } ,
|
||||
|
||||
{ "allKeysForObject", [=](){
|
||||
Dictionary* dict = Dictionary::create();
|
||||
|
||||
Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes);
|
||||
Node* sameNode = Node::create();
|
||||
|
||||
for( int i=0; i<quantityOfNodes; ++i)
|
||||
{
|
||||
if (quantityOfNodes % 100 == 0)
|
||||
{
|
||||
dict->setObject(sameNode, 100 + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto node = Node::create();
|
||||
node->setTag(i);
|
||||
dict->setObject(node, 100 + i);
|
||||
}
|
||||
}
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
auto keys = dict->allKeysForObject(sameNode);
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
|
||||
int allKeysInt = 0;
|
||||
Object* obj;
|
||||
CCARRAY_FOREACH(keys, obj)
|
||||
{
|
||||
auto key = static_cast<Integer*>(obj);
|
||||
allKeysInt += key->getValue();
|
||||
}
|
||||
|
||||
CC_SAFE_FREE(nodes);
|
||||
} } ,
|
||||
|
||||
{ "CCDICT_FOREACH", [=](){
|
||||
auto dict = createDict();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
|
||||
DictElement* e = nullptr;
|
||||
CCDICT_FOREACH(dict, e)
|
||||
{
|
||||
static_cast<Node*>(e->getObject())->setTag(100);
|
||||
}
|
||||
|
||||
CC_PROFILER_STOP(this->profilerName());
|
||||
} } ,
|
||||
};
|
||||
|
||||
for (const auto& func : testFunctions)
|
||||
{
|
||||
_testFunctions.push_back(func);
|
||||
}
|
||||
}
|
||||
|
||||
std::string DictionaryIntKeyPerfTest::title() const
|
||||
{
|
||||
return "Dictionary Integer Key Perf test";
|
||||
}
|
||||
|
||||
std::string DictionaryIntKeyPerfTest::subtitle() const
|
||||
{
|
||||
return "Test `setObject`, See console";
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------
|
||||
void runContainerPerformanceTest()
|
||||
{
|
||||
|
|
|
@ -44,8 +44,6 @@ public:
|
|||
void dumpProfilerInfo(float dt);
|
||||
|
||||
// overrides
|
||||
virtual void onExitTransitionDidStart() override;
|
||||
virtual void onEnterTransitionDidFinish() override;
|
||||
virtual void update(float dt) override;
|
||||
|
||||
protected:
|
||||
|
@ -85,6 +83,49 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class TemplateMapStringKeyPerfTest : public PerformanceContainerScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TemplateMapStringKeyPerfTest);
|
||||
|
||||
virtual void generateTestFunctions() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class DictionaryStringKeyPerfTest : public PerformanceContainerScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(DictionaryStringKeyPerfTest);
|
||||
|
||||
virtual void generateTestFunctions() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class TemplateMapIntKeyPerfTest : public PerformanceContainerScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TemplateMapIntKeyPerfTest);
|
||||
|
||||
virtual void generateTestFunctions() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class DictionaryIntKeyPerfTest : public PerformanceContainerScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(DictionaryIntKeyPerfTest);
|
||||
|
||||
virtual void generateTestFunctions() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
void runContainerPerformanceTest();
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
#include "ReleasePoolTest.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
class TestObject : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
void ReleasePoolTestScene::runThisTest()
|
||||
{
|
||||
// title
|
||||
auto label = LabelTTF::create("AutoreasePool Test", "Arial", 32);
|
||||
addChild(label, 9999);
|
||||
label->setPosition(Point(VisibleRect::center().x, VisibleRect::top().y - 30));
|
||||
|
||||
// reference count should be added when added into auto release pool
|
||||
|
||||
TestObject *obj = new TestObject();
|
||||
obj->autorelease();
|
||||
assert(obj->retainCount() == 2);
|
||||
|
||||
// can invoke autorelease more than once
|
||||
obj->autorelease();
|
||||
assert(obj->retainCount() == 3);
|
||||
|
||||
// create an autorelease pool in stack
|
||||
|
||||
{
|
||||
AutoreleasePool pool1;
|
||||
|
||||
obj->autorelease();
|
||||
assert(obj->retainCount() == 4);
|
||||
|
||||
// retain, release can work together with autorelease pool
|
||||
obj->retain();
|
||||
assert(obj->retainCount() == 5);
|
||||
obj->release();
|
||||
assert(obj->retainCount() == 4);
|
||||
|
||||
|
||||
AutoreleasePool pool2;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
TestObject *tmpObj = new TestObject();
|
||||
tmpObj->autorelease();
|
||||
}
|
||||
pool2.dump();
|
||||
}
|
||||
|
||||
// pool is destroyed, so the release count is minused by one
|
||||
assert(obj->retainCount() == 3);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
*
|
||||
*/
|
||||
#ifndef __RELEASE_POOL_TEST_H__
|
||||
#define __RELEASE_POOL_TEST_H__
|
||||
|
||||
#include "../testBasic.h"
|
||||
|
||||
class ReleasePoolTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // __RELEASE_POOL_TEST_H__
|
|
@ -1 +1 @@
|
|||
689b357d7acda141d13a3dfc4cb52aabb274f6cd
|
||||
c098eac3962854bc7d1981ec16aad7d2907c0e33
|
|
@ -73,6 +73,7 @@ struct {
|
|||
{ "ParticleTest", [](){return new ParticleTestScene(); } },
|
||||
{ "PerformanceTest", []() { return new PerformanceTestScene(); } },
|
||||
{ "PhysicsTest", []() { return new PhysicsTestScene(); } },
|
||||
{ "ReleasePoolTest", [](){ return new ReleasePoolTestScene(); } },
|
||||
{ "RenderTextureTest", [](){return new RenderTextureScene(); } },
|
||||
{ "RotateWorldTest", [](){return new RotateWorldTestScene(); } },
|
||||
{ "SceneTest", [](){return new SceneTestScene();} },
|
||||
|
@ -155,7 +156,7 @@ void TestController::menuCallback(Object * sender)
|
|||
|
||||
// get the userdata, it's the index of the menu item clicked
|
||||
auto menuItem = static_cast<MenuItem *>(sender);
|
||||
int idx = menuItem->getZOrder() - 10000;
|
||||
int idx = menuItem->getLocalZOrder() - 10000;
|
||||
|
||||
// create the test scene and run it
|
||||
auto scene = g_aTestNames[idx].callback();
|
||||
|
|
|
@ -68,5 +68,6 @@
|
|||
#include "DataVisitorTest/DataVisitorTest.h"
|
||||
#include "ConfigurationTest/ConfigurationTest.h"
|
||||
#include "PhysicsTest/PhysicsTest.h"
|
||||
#include "ReleasePoolTest/ReleasePoolTest.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -190,6 +190,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$
|
|||
<ClCompile Include="..\Classes\PerformanceTest\PerformanceLabelTest.cpp" />
|
||||
<ClCompile Include="..\Classes\PerformanceTest\PerformanceRendererTest.cpp" />
|
||||
<ClCompile Include="..\Classes\PhysicsTest\PhysicsTest.cpp" />
|
||||
<ClCompile Include="..\Classes\ReleasePoolTest\ReleasePoolTest.cpp" />
|
||||
<ClCompile Include="..\Classes\ShaderTest\ShaderTest2.cpp" />
|
||||
<ClCompile Include="..\Classes\SpineTest\SpineTest.cpp" />
|
||||
<ClCompile Include="..\Classes\TexturePackerEncryptionTest\TextureAtlasEncryptionTest.cpp" />
|
||||
|
@ -338,6 +339,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$
|
|||
<ClInclude Include="..\Classes\PerformanceTest\PerformanceLabelTest.h" />
|
||||
<ClInclude Include="..\Classes\PerformanceTest\PerformanceRendererTest.h" />
|
||||
<ClInclude Include="..\Classes\PhysicsTest\PhysicsTest.h" />
|
||||
<ClInclude Include="..\Classes\ReleasePoolTest\ReleasePoolTest.h" />
|
||||
<ClInclude Include="..\Classes\ShaderTest\ShaderTest2.h" />
|
||||
<ClInclude Include="..\Classes\SpineTest\SpineTest.h" />
|
||||
<ClInclude Include="..\Classes\TexturePackerEncryptionTest\TextureAtlasEncryptionTest.h" />
|
||||
|
|
|
@ -307,6 +307,9 @@
|
|||
<Filter Include="Classes\ExtensionsTest\CocoStudioSceneTest\TriggerCode">
|
||||
<UniqueIdentifier>{5ff3af4e-0610-480b-b297-8f407e12f369}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\ReleasePoolTest">
|
||||
<UniqueIdentifier>{f71fab28-32be-45c9-a941-9a22b5a59e51}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
|
@ -721,6 +724,9 @@
|
|||
<ClCompile Include="..\Classes\PerformanceTest\PerformanceContainerTest.cpp">
|
||||
<Filter>Classes\PerformanceTest</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\ReleasePoolTest\ReleasePoolTest.cpp">
|
||||
<Filter>Classes\ReleasePoolTest</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="main.h">
|
||||
|
@ -1333,5 +1339,8 @@
|
|||
<ClInclude Include="..\Classes\PerformanceTest\PerformanceContainerTest.h">
|
||||
<Filter>Classes\PerformanceTest</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\ReleasePoolTest\ReleasePoolTest.h">
|
||||
<Filter>Classes\ReleasePoolTest</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -145,26 +145,6 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
return true;
|
||||
}
|
||||
|
||||
void handle_signal(int signal) {
|
||||
static int internal_state = 0;
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
// should start everything back
|
||||
auto director = Director::getInstance();
|
||||
if (director->getRunningScene()) {
|
||||
director->popToRootScene();
|
||||
} else {
|
||||
PoolManager::sharedPoolManager()->finalize();
|
||||
if (internal_state == 0) {
|
||||
//sc->dumpRoot(NULL, 0, NULL);
|
||||
sc->start();
|
||||
internal_state = 1;
|
||||
} else {
|
||||
sc->runScript("hello.js");
|
||||
internal_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
|
|
|
@ -126,26 +126,6 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
return true;
|
||||
}
|
||||
|
||||
void handle_signal(int signal) {
|
||||
static int internal_state = 0;
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
// should start everything back
|
||||
auto director = Director::getInstance();
|
||||
if (director->getRunningScene()) {
|
||||
director->popToRootScene();
|
||||
} else {
|
||||
PoolManager::sharedPoolManager()->finalize();
|
||||
if (internal_state == 0) {
|
||||
//sc->dumpRoot(NULL, 0, NULL);
|
||||
sc->start();
|
||||
internal_state = 1;
|
||||
} else {
|
||||
sc->runScript("hello.js");
|
||||
internal_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
|
|
|
@ -68,26 +68,6 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
return true;
|
||||
}
|
||||
|
||||
void handle_signal(int signal) {
|
||||
static int internal_state = 0;
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
// should start everything back
|
||||
auto director = Director::getInstance();
|
||||
if (director->getRunningScene()) {
|
||||
director->popToRootScene();
|
||||
} else {
|
||||
PoolManager::sharedPoolManager()->finalize();
|
||||
if (internal_state == 0) {
|
||||
//sc->dumpRoot(NULL, 0, NULL);
|
||||
sc->start();
|
||||
internal_state = 1;
|
||||
} else {
|
||||
sc->runScript("hello.js");
|
||||
internal_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
|
|
|
@ -121,26 +121,6 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
return true;
|
||||
}
|
||||
|
||||
void handle_signal(int signal) {
|
||||
static int internal_state = 0;
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
// should start everything back
|
||||
auto director = Director::getInstance();
|
||||
if (director->getRunningScene()) {
|
||||
director->popToRootScene();
|
||||
} else {
|
||||
PoolManager::sharedPoolManager()->finalize();
|
||||
if (internal_state == 0) {
|
||||
//sc->dumpRoot(NULL, 0, NULL);
|
||||
sc->start();
|
||||
internal_state = 1;
|
||||
} else {
|
||||
sc->runScript("hello.js");
|
||||
internal_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
|
|
|
@ -65,26 +65,6 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
return true;
|
||||
}
|
||||
|
||||
void handle_signal(int signal) {
|
||||
static int internal_state = 0;
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
// should start everything back
|
||||
auto director = Director::getInstance();
|
||||
if (director->getRunningScene()) {
|
||||
director->popToRootScene();
|
||||
} else {
|
||||
PoolManager::sharedPoolManager()->finalize();
|
||||
if (internal_state == 0) {
|
||||
//sc->dumpRoot(NULL, 0, NULL);
|
||||
sc->start();
|
||||
internal_state = 1;
|
||||
} else {
|
||||
sc->runScript("hello.js");
|
||||
internal_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
|
|
|
@ -116,7 +116,7 @@ local function updateLayer()
|
|||
|
||||
local function menuCallback(tag, menuItem)
|
||||
local scene = nil
|
||||
local nIdx = menuItem:getZOrder() - itemTagBasic
|
||||
local nIdx = menuItem:getLocalZOrder() - itemTagBasic
|
||||
local ExtensionsTestScene = CreateExtensionsTestScene(nIdx)
|
||||
if nil ~= ExtensionsTestScene then
|
||||
cc.Director:getInstance():replaceScene(ExtensionsTestScene)
|
||||
|
|
|
@ -583,7 +583,7 @@ local function BugsTestMainLayer()
|
|||
|
||||
--menu callback
|
||||
local function menuCallback(tag, pMenuItem)
|
||||
local nIdx = pMenuItem:getZOrder() - kItemTagBasic
|
||||
local nIdx = pMenuItem:getLocalZOrder() - kItemTagBasic
|
||||
local BugTestScene = CreateBugsTestScene(nIdx)
|
||||
if nil ~= testScene then
|
||||
cc.Director:getInstance():replaceScene(testScene)
|
||||
|
|
|
@ -633,7 +633,7 @@ function TestChangeZorder:onEnter()
|
|||
|
||||
local function changeZorder(dt)
|
||||
local node = self:getChildByTag(self.currentTag)
|
||||
node:setZOrder(math.random(0,1) * 3)
|
||||
node:setLocalZOrder(math.random(0,1) * 3)
|
||||
self.currentTag = (self.currentTag + 1) % 3
|
||||
end
|
||||
|
||||
|
@ -828,7 +828,7 @@ function TestParticleDisplay:onEnter()
|
|||
bone:addDisplay(p1, 0)
|
||||
bone:changeDisplayWithIndex(0, true)
|
||||
bone:setIgnoreMovementBoneData(true)
|
||||
bone:setZOrder(100)
|
||||
bone:setLocalZOrder(100)
|
||||
bone:setScale(1.2)
|
||||
self.armature:addBone(bone, "bady-a3")
|
||||
|
||||
|
@ -836,7 +836,7 @@ function TestParticleDisplay:onEnter()
|
|||
bone:addDisplay(p2, 0)
|
||||
bone:changeDisplayWithIndex(0, true)
|
||||
bone:setIgnoreMovementBoneData(true)
|
||||
bone:setZOrder(100)
|
||||
bone:setLocalZOrder(100)
|
||||
bone:setScale(1.2)
|
||||
self.armature:addBone(bone, "bady-a30")
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ function SceneEditorTestLayer:createGameScene()
|
|||
itemBack:registerScriptTapHandler(menuCloseCallback)
|
||||
local menuBack = cc.Menu:create()
|
||||
menuBack:setPosition(cc.p(0.0, 0.0))
|
||||
menuBack:setZOrder(4)
|
||||
menuBack:setLocalZOrder(4)
|
||||
menuBack:addChild(itemBack)
|
||||
|
||||
node:addChild(menuBack)
|
||||
|
|
|
@ -67,7 +67,7 @@ function CocoStudioTestLayer.extend(target)
|
|||
end
|
||||
|
||||
function CocoStudioTestLayer.onMenuCallback(tag,sender)
|
||||
local index = sender:getZOrder() - ITEM_TAG_BASIC
|
||||
local index = sender:getLocalZOrder() - ITEM_TAG_BASIC
|
||||
cocoStudioTestItemNames[index].testScene()
|
||||
end
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ local function CocosDenshionTest()
|
|||
}
|
||||
|
||||
local function menuCallback(tag, pMenuItem)
|
||||
local nIdx = pMenuItem:getZOrder() - 10000
|
||||
local nIdx = pMenuItem:getLocalZOrder() - 10000
|
||||
-- play background music
|
||||
if nIdx == 0 then
|
||||
AudioEngine.playMusic(MUSIC_FILE, true)
|
||||
|
|
|
@ -1201,7 +1201,7 @@ local function ExtensionsMainLayer()
|
|||
|
||||
local function menuCallback(tag, pMenuItem)
|
||||
local scene = nil
|
||||
local nIdx = pMenuItem:getZOrder() - kItemTagBasic
|
||||
local nIdx = pMenuItem:getLocalZOrder() - kItemTagBasic
|
||||
local ExtensionsTestScene = CreateExtensionsTestScene(nIdx)
|
||||
if nil ~= ExtensionsTestScene then
|
||||
cc.Director:getInstance():replaceScene(ExtensionsTestScene)
|
||||
|
|
|
@ -42,7 +42,7 @@ function LabelFNTColorAndOpacity.create()
|
|||
local col = cc.LayerColor:create( cc.c4b(128,128,128,255) )
|
||||
layer:addChild(col, -10)
|
||||
|
||||
local label1 = cc.Label:createWithBMFont("Test", "fonts/bitmapFontTest2.fnt")
|
||||
local label1 = cc.Label:createWithBMFont("fonts/bitmapFontTest2.fnt", "Test")
|
||||
|
||||
-- testing anchors
|
||||
label1:setAnchorPoint( cc.p(0,0) )
|
||||
|
@ -55,15 +55,15 @@ function LabelFNTColorAndOpacity.create()
|
|||
local repeatAction = cc.RepeatForever:create(seq)
|
||||
label1:runAction(repeatAction)
|
||||
|
||||
local label2 = cc.Label:createWithBMFont("Test", "fonts/bitmapFontTest2.fnt")
|
||||
local label2 = cc.Label:createWithBMFont("fonts/bitmapFontTest2.fnt", "Test")
|
||||
-- testing anchors
|
||||
label2:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
label2:setColor(cc.c3b(255, 0, 0 ))
|
||||
layer:addChild(label2, 0, kTagBitmapAtlas2)
|
||||
|
||||
label2:runAction( tolua.cast(repeatAction:clone(), "Action") )
|
||||
label2:runAction( tolua.cast(repeatAction:clone(), "cc.Action") )
|
||||
|
||||
local label3 = cc.Label:createWithBMFont("Test", "fonts/bitmapFontTest2.fnt")
|
||||
local label3 = cc.Label:createWithBMFont("fonts/bitmapFontTest2.fnt", "Test")
|
||||
-- testing anchors
|
||||
label3:setAnchorPoint( cc.p(1,1) )
|
||||
layer:addChild(label3, 0, kTagBitmapAtlas3)
|
||||
|
@ -85,13 +85,13 @@ function LabelFNTColorAndOpacity.step(dt)
|
|||
m_time = m_time + dt
|
||||
local string = string.format("%2.2f Test j", m_time)
|
||||
|
||||
local label1 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas1), "Label")
|
||||
local label1 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas1), "cc.Label")
|
||||
label1:setString(string)
|
||||
|
||||
local label2 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas2), "Label")
|
||||
local label2 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas2), "cc.Label")
|
||||
label2:setString(string)
|
||||
|
||||
local label3 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas3), "Label")
|
||||
local label3 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas3), "cc.Label")
|
||||
label3:setString(string)
|
||||
end
|
||||
|
||||
|
@ -121,7 +121,7 @@ function LabelFNTSpriteActions.create()
|
|||
LabelFNTSpriteActions.layer = layer
|
||||
|
||||
-- Upper Label
|
||||
local label = cc.Label:createWithBMFont("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt")
|
||||
local label = cc.Label:createWithBMFont("fonts/bitmapFontTest.fnt", "Bitmap Font Atlas")
|
||||
layer:addChild(label)
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
@ -160,12 +160,12 @@ function LabelFNTSpriteActions.create()
|
|||
|
||||
|
||||
-- Bottom Label
|
||||
local label2 = cc.Label:createWithBMFont("00.0", "fonts/bitmapFontTest.fnt")
|
||||
local label2 = cc.Label:createWithBMFont("fonts/bitmapFontTest.fnt", "00.0")
|
||||
layer:addChild(label2, 0, kTagBitmapAtlas2)
|
||||
label2:setPosition( cc.p(s.width/2.0, 80) )
|
||||
|
||||
local lastChar = label2:getLetter(3)
|
||||
lastChar:runAction(tolua.cast( rot_4ever:clone(), "Action" ))
|
||||
lastChar:runAction(tolua.cast( rot_4ever:clone(), "cc.Action" ))
|
||||
|
||||
layer:registerScriptHandler(LabelFNTSpriteActions.onNodeEvent)
|
||||
|
||||
|
@ -203,7 +203,7 @@ function LabelFNTPadding:create()
|
|||
Helper.initWithLayer(layer)
|
||||
LabelFNTPadding.layer = layer
|
||||
|
||||
local label = cc.Label:createWithBMFont("abcdefg", "fonts/bitmapFontTest4.fnt")
|
||||
local label = cc.Label:createWithBMFont("fonts/bitmapFontTest4.fnt", "abcdefg")
|
||||
layer:addChild(label)
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
@ -231,17 +231,17 @@ function LabelFNTOffset:create()
|
|||
LabelFNTOffset.layer = layer
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local label = cc.Label:createWithBMFont("FaFeFiFoFu", "fonts/bitmapFontTest5.fnt")
|
||||
local label = cc.Label:createWithBMFont("fonts/bitmapFontTest5.fnt", "FaFeFiFoFu")
|
||||
layer:addChild(label)
|
||||
label:setPosition( cc.p(s.width/2, s.height/2+50) )
|
||||
label:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
|
||||
label = cc.Label:createWithBMFont("fafefifofu", "fonts/bitmapFontTest5.fnt")
|
||||
label = cc.Label:createWithBMFont("fonts/bitmapFontTest5.fnt", "fafefifofu")
|
||||
layer:addChild(label)
|
||||
label:setPosition( cc.p(s.width/2, s.height/2) )
|
||||
label:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
|
||||
label = cc.Label:createWithBMFont("aeiou", "fonts/bitmapFontTest5.fnt")
|
||||
label = cc.Label:createWithBMFont("fonts/bitmapFontTest5.fnt", "aeiou")
|
||||
layer:addChild(label)
|
||||
label:setPosition( cc.p(s.width/2, s.height/2-50) )
|
||||
label:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
|
@ -264,19 +264,19 @@ function LabelFNTColor:create()
|
|||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local label = cc.Label:createWithBMFont("Blue", "fonts/bitmapFontTest5.fnt")
|
||||
local label = cc.Label:createWithBMFont("fonts/bitmapFontTest5.fnt", "Blue")
|
||||
label:setColor( cc.c3b(0, 0, 255 ))
|
||||
layer:addChild(label)
|
||||
label:setPosition( cc.p(s.width/2, s.height/4) )
|
||||
label:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
|
||||
label = cc.Label:createWithBMFont("Red", "fonts/bitmapFontTest5.fnt")
|
||||
label = cc.Label:createWithBMFont("fonts/bitmapFontTest5.fnt", "Red")
|
||||
layer:addChild(label)
|
||||
label:setPosition( cc.p(s.width/2, 2*s.height/4) )
|
||||
label:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
label:setColor( cc.c3b(255, 0, 0) )
|
||||
|
||||
label = cc.Label:createWithBMFont("G", "fonts/bitmapFontTest5.fnt")
|
||||
label = cc.Label:createWithBMFont("fonts/bitmapFontTest5.fnt", "Green")
|
||||
layer:addChild(label)
|
||||
label:setPosition( cc.p(s.width/2, 3*s.height/4) )
|
||||
label:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
|
@ -301,20 +301,23 @@ function LabelTTFColor:create()
|
|||
Helper.initWithLayer(layer)
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath="fonts/arial.ttf"
|
||||
ttfConfig.fontSize=35
|
||||
|
||||
local label1 = cc.Label:createWithTTF("Green", "fonts/arial.ttf", 35, s.width, cc.VERTICAL_TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_NEHE)
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig,"Green", cc.VERTICAL_TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label1:setColor( cc.c3b(0, 255, 0 ))
|
||||
layer:addChild(label1)
|
||||
label1:setPosition( cc.p(s.width/2, s.height/5 * 1.5) )
|
||||
label1:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
|
||||
local label2 = cc.Label:createWithTTF("Red", "fonts/arial.ttf", 35, s.width, cc.VERTICAL_TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_NEHE)
|
||||
local label2 = cc.Label:createWithTTF(ttfConfig, "Red", cc.VERTICAL_TEXT_ALIGNMENT_CENTER, s.width)
|
||||
layer:addChild(label2)
|
||||
label2:setPosition( cc.p(s.width/2, s.height/5 * 2.0) )
|
||||
label2:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
label2:setColor( cc.c3b(255, 0, 0) )
|
||||
|
||||
local label3 = cc.Label:createWithTTF("Blue", "fonts/arial.ttf", 35, s.width, cc.VERTICAL_TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_NEHE)
|
||||
local label3 = cc.Label:createWithTTF(ttfConfig, "Blue", cc.VERTICAL_TEXT_ALIGNMENT_CENTER, s.width)
|
||||
layer:addChild(label3)
|
||||
label3:setPosition( cc.p(s.width/2, s.height/5 * 2.5) )
|
||||
label3:setAnchorPoint( cc.p(0.5, 0.5) )
|
||||
|
@ -342,7 +345,7 @@ function LabelFNTHundredLabels:create()
|
|||
local i = 0
|
||||
for i = 0, 100, 1 do
|
||||
local str = string.format("-%d-", i)
|
||||
local label = cc.Label:createWithBMFont(str, "fonts/bitmapFontTest.fnt")
|
||||
local label = cc.Label:createWithBMFont("fonts/bitmapFontTest.fnt", str)
|
||||
layer:addChild(label)
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
@ -353,7 +356,7 @@ function LabelFNTHundredLabels:create()
|
|||
end
|
||||
|
||||
Helper.titleLabel:setString("New Label + .FNT file")
|
||||
Helper.subtitleLabel:setString("Creating several Labels using the same FNT file; should be fast")
|
||||
Helper.subtitleLabel:setString("Creating several Labels using the same FNT file should be fast")
|
||||
return layer
|
||||
end
|
||||
|
||||
|
@ -371,7 +374,7 @@ function LabelFNTMultiLine:create()
|
|||
local s = nil
|
||||
|
||||
-- Left
|
||||
local label1 = cc.Label:createWithBMFont(" Multi line\nLeft", "fonts/bitmapFontTest3.fnt")
|
||||
local label1 = cc.Label:createWithBMFont("fonts/bitmapFontTest3.fnt", " Multi line\nLeft")
|
||||
label1:setAnchorPoint(cc.p(0,0))
|
||||
layer:addChild(label1, 0, kTagBitmapAtlas1)
|
||||
|
||||
|
@ -380,7 +383,7 @@ function LabelFNTMultiLine:create()
|
|||
|
||||
|
||||
-- Center
|
||||
local label2 = cc.Label:createWithBMFont("Multi line\nCenter", "fonts/bitmapFontTest3.fnt")
|
||||
local label2 = cc.Label:createWithBMFont("fonts/bitmapFontTest3.fnt", "Multi line\nCenter")
|
||||
label2:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
layer:addChild(label2, 0, kTagBitmapAtlas2)
|
||||
|
||||
|
@ -388,7 +391,7 @@ function LabelFNTMultiLine:create()
|
|||
cclog("content size: %.2fx%.2f", s.width, s.height)
|
||||
|
||||
-- right
|
||||
local label3 = cc.Label:createWithBMFont("Multi line\nRight\nThree lines Three", "fonts/bitmapFontTest3.fnt")
|
||||
local label3 = cc.Label:createWithBMFont("fonts/bitmapFontTest3.fnt", "Multi line\nRight\nThree lines Three")
|
||||
label3:setAnchorPoint(cc.p(1, 1))
|
||||
layer:addChild(label3, 0, kTagBitmapAtlas3)
|
||||
|
||||
|
@ -433,13 +436,17 @@ function LabelFNTandTTFEmpty.create()
|
|||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
-- cc.LabelBMFont
|
||||
local label1 = cc.Label:createWithBMFont("", "fonts/bitmapFontTest3.fnt",cc.TEXT_ALIGNMENT_CENTER,s.width)
|
||||
local label1 = cc.Label:createWithBMFont("fonts/bitmapFontTest3.fnt", "", cc.TEXT_ALIGNMENT_CENTER,s.width)
|
||||
layer:addChild(label1, 0, kTagBitmapAtlas1)
|
||||
label1:setPosition(cc.p(s.width/2, s.height-100))
|
||||
|
||||
-- cc.LabelTTF
|
||||
local label2 = cc.Label:createWithTTF("", "fonts/arial.ttf", 48, s.width, cc.TEXT_ALIGNMENT_CENTER,cc.GLYPHCOLLECTION_NEHE)
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = "fonts/arial.ttf"
|
||||
ttfConfig.fontSize = 48
|
||||
local label2 = cc.Label:createWithTTF(ttfConfig, "", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
layer:addChild(label2, 0, kTagBitmapAtlas2)
|
||||
label2:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
label2:setPosition(cc.p(s.width/2, s.height/2))
|
||||
|
||||
layer:registerScriptHandler(LabelFNTandTTFEmpty.onNodeEvent)
|
||||
|
@ -481,7 +488,7 @@ function LabelFNTRetina.create()
|
|||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
-- cc.LabelBMFont
|
||||
local label1 = cc.Label:createWithBMFont("TESTING RETINA DISPLAY", "fonts/konqa32.fnt")
|
||||
local label1 = cc.Label:createWithBMFont("fonts/konqa32.fnt", "TESTING RETINA DISPLAY")
|
||||
label1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(label1)
|
||||
label1:setPosition(cc.p(s.width/2, s.height/2))
|
||||
|
@ -503,7 +510,7 @@ function LabelFNTGlyphDesigner.create()
|
|||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local label1 = cc.Label:createWithBMFont("TESTING RETINA DISPLAY", "fonts/futura-48.fnt")
|
||||
local label1 = cc.Label:createWithBMFont("fonts/futura-48.fnt", "TESTING RETINA DISPLAY")
|
||||
label1:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
|
||||
layer:addChild(label1)
|
||||
|
@ -523,8 +530,13 @@ function LabelTTFUnicodeChinese.create()
|
|||
Helper.subtitleLabel:setString("Testing new Label + TTF with Chinese character")
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local label1 = cc.Label:createWithTTF("美好的一天啊", "fonts/wt021.ttf", 55, s.width, cc.TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_CUSTOM, "美好的一天啊")
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath="fonts/wt021.ttf"
|
||||
ttfConfig.fontSize=55
|
||||
ttfConfig.glyphs=cc.GLYPHCOLLECTION_CUSTOM
|
||||
ttfConfig.customGlyphs="美好的一天啊"
|
||||
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig,"美好的一天啊", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(label1)
|
||||
label1:setPosition(cc.p(s.width/2, s.height/2))
|
||||
|
@ -542,7 +554,7 @@ function LabelFNTUnicodeChinese.create()
|
|||
Helper.initWithLayer(layer)
|
||||
|
||||
local size = cc.Director:getInstance():getWinSize()
|
||||
local lable = cc.Label:createWithBMFont("中国", "fonts/bitmapFontChinese.fnt")
|
||||
local lable = cc.Label:createWithBMFont("fonts/bitmapFontChinese.fnt", "中国")
|
||||
lable:setAnchorPoint(cc.p(0.5,0.5))
|
||||
lable:setPosition(cc.p(size.width / 2, size.height /2))
|
||||
layer:addChild(lable)
|
||||
|
@ -591,7 +603,7 @@ function LabelFNTMultiLineAlignment.create()
|
|||
local size = cc.Director:getInstance():getWinSize()
|
||||
|
||||
-- create and initialize a Label
|
||||
LabelFNTMultiLineAlignment._pLabelShouldRetain = cc.Label:createWithBMFont(LongSentencesExample, "fonts/markerFelt.fnt", cc.TEXT_ALIGNMENT_CENTER, size.width/1.5)
|
||||
LabelFNTMultiLineAlignment._pLabelShouldRetain = cc.Label:createWithBMFont("fonts/markerFelt.fnt", LongSentencesExample, cc.TEXT_ALIGNMENT_CENTER, size.width/1.5)
|
||||
LabelFNTMultiLineAlignment._pLabelShouldRetain:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
LabelFNTMultiLineAlignment._pLabelShouldRetain:retain()
|
||||
|
||||
|
@ -677,7 +689,7 @@ end
|
|||
|
||||
|
||||
function LabelFNTMultiLineAlignment.stringChanged(tag, sender)
|
||||
local item = tolua.cast(sender, "MenuItemFont")
|
||||
local item = tolua.cast(sender, "cc.MenuItemFont")
|
||||
item:setColor(cc.c3b(255, 0, 0))
|
||||
LabelFNTMultiLineAlignment._pLastAlignmentItem:setColor(cc.c3b(255, 255, 255))
|
||||
LabelFNTMultiLineAlignment._pLastAlignmentItem = item
|
||||
|
@ -695,7 +707,7 @@ end
|
|||
|
||||
function LabelFNTMultiLineAlignment.alignmentChanged(tag, sender)
|
||||
-- cclog("LabelFNTMultiLineAlignment.alignmentChanged, tag:"..tag)
|
||||
local item = tolua.cast(sender, "MenuItemFont")
|
||||
local item = tolua.cast(sender, "cc.MenuItemFont")
|
||||
item:setColor(cc.c3b(255, 0, 0))
|
||||
LabelFNTMultiLineAlignment._pLastAlignmentItem:setColor(cc.c3b(255, 255, 255))
|
||||
LabelFNTMultiLineAlignment._pLastAlignmentItem = item
|
||||
|
@ -759,17 +771,17 @@ function LabelFNTUNICODELanguages.create()
|
|||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local label1 = cc.Label:createWithBMFont("Buen día", "fonts/arial-unicode-26.fnt", 200, cc.TEXT_ALIGNMENT_LEFT)
|
||||
local label1 = cc.Label:createWithBMFont("fonts/arial-unicode-26.fnt", "Buen día", cc.TEXT_ALIGNMENT_CENTER, 200)
|
||||
label1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(label1)
|
||||
label1:setPosition(cc.p(s.width/2, s.height/4*3))
|
||||
|
||||
local label2 = cc.Label:createWithBMFont("美好的一天", "fonts/arial-unicode-26.fnt")
|
||||
local label2 = cc.Label:createWithBMFont("fonts/arial-unicode-26.fnt", "美好的一天")
|
||||
label2:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(label2)
|
||||
label2:setPosition(cc.p(s.width/2, s.height/4*2))
|
||||
|
||||
local label3 = cc.Label:createWithBMFont("良い一日を", "fonts/arial-unicode-26.fnt")
|
||||
local label3 = cc.Label:createWithBMFont("fonts/arial-unicode-26.fnt", "良い一日を")
|
||||
label3:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(label3)
|
||||
label3:setPosition(cc.p(s.width/2, s.height/4*1))
|
||||
|
@ -788,21 +800,20 @@ function LabelTTFAlignmentNew.create()
|
|||
Helper.subtitleLabel:setString("Tests alignment values")
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local ttf0 = cc.Label:createWithTTF("Alignment 0\nnew line", "fonts/tahoma.ttf", 32)
|
||||
ttf0:setAlignment(cc.TEXT_ALIGNMENT_LEFT)
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath="fonts/tahoma.ttf"
|
||||
ttfConfig.fontSize=32
|
||||
local ttf0 = cc.Label:createWithTTF(ttfConfig, "Alignment 0\nnew line", cc.TEXT_ALIGNMENT_LEFT)
|
||||
ttf0:setPosition(cc.p(s.width/2,(s.height/6)*2 - 30))
|
||||
ttf0:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(ttf0)
|
||||
|
||||
local ttf1 = cc.Label:createWithTTF("Alignment 1\nnew line", "fonts/tahoma.ttf", 32)
|
||||
ttf1:setAlignment(cc.TEXT_ALIGNMENT_CENTER)
|
||||
local ttf1 = cc.Label:createWithTTF(ttfConfig, "Alignment 1\nnew line", cc.TEXT_ALIGNMENT_CENTER)
|
||||
ttf1:setPosition(cc.p(s.width/2,(s.height/6)*3 - 30))
|
||||
ttf1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(ttf1)
|
||||
|
||||
local ttf2 = cc.Label:createWithTTF("Alignment 2\nnew line", "fonts/tahoma.ttf", 32)
|
||||
ttf2:setAlignment(cc.TEXT_ALIGNMENT_RIGHT)
|
||||
local ttf2 = cc.Label:createWithTTF(ttfConfig, "Alignment 2\nnew line", cc.TEXT_ALIGNMENT_RIGHT)
|
||||
ttf2:setPosition(cc.p(s.width/2,(s.height/6)*4 - 30))
|
||||
ttf2:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(ttf2)
|
||||
|
@ -824,18 +835,26 @@ function LabelTTFUnicodeNew.create()
|
|||
local s = cc.Director:getInstance():getWinSize()
|
||||
local vStep = s.height/9
|
||||
local vSize = s.height
|
||||
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath="fonts/arial.ttf"
|
||||
ttfConfig.fontSize=45
|
||||
ttfConfig.glyphs=cc.GLYPHCOLLECTION_ASCII
|
||||
|
||||
local label1 = cc.Label:createWithTTF("Buen día, ¿cómo te llamas?", "fonts/arial.ttf", 45, s.width, cc.TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_ASCII)
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig,"Buen día, ¿cómo te llamas?", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
label1:setPosition(cc.p(s.width/2, vSize - vStep * 4.5))
|
||||
layer:addChild(label1)
|
||||
|
||||
local label2 = cc.Label:createWithTTF("In welcher Straße haben Sie gelebt?", "fonts/arial.ttf", 45, s.width, cc.TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_ASCII)
|
||||
local label2 = cc.Label:createWithTTF(ttfConfig, "In welcher Straße haben Sie gelebt?", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label2:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(label2)
|
||||
label2:setPosition(cc.p(s.width/2, vSize - vStep * 5.5))
|
||||
|
||||
local label3 = cc.Label:createWithTTF("美好的一天", "fonts/wt021.ttf", 45, s.width, cc.TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_CUSTOM, "美好的一天")
|
||||
ttfConfig.fontFilePath = "fonts/wt021.ttf"
|
||||
ttfConfig.glyphs = cc.GLYPHCOLLECTION_CUSTOM
|
||||
ttfConfig.customGlyphs = "美好的一天"
|
||||
local label3 = cc.Label:createWithTTF(ttfConfig, "美好的一天", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label3:setAnchorPoint(cc.p(0.5,0.5))
|
||||
layer:addChild(label3)
|
||||
label3:setPosition(cc.p(s.width/2, vSize - vStep * 6.5))
|
||||
|
@ -862,7 +881,7 @@ function LabelFNTBounds.create()
|
|||
layer:addChild(colorlayer, -10)
|
||||
|
||||
-- cc.LabelBMFont
|
||||
local label1 = cc.Label:createWithBMFont("Testing Glyph Designer", "fonts/boundsTestFont.fnt", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
local label1 = cc.Label:createWithBMFont("fonts/boundsTestFont.fnt", "Testing Glyph Designer", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label1:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
|
||||
layer:addChild(label1)
|
||||
|
@ -899,8 +918,10 @@ function LabelTTFLongLineWrapping.create()
|
|||
Helper.subtitleLabel:setString("Uses the new Label with TTF. Testing auto-wrapping")
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local label1 = cc.Label:createWithTTF(LongSentencesExample, "fonts/arial.ttf", 28, s.width,cc.TEXT_ALIGNMENT_LEFT, cc.GLYPHCOLLECTION_NEHE)
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = "fonts/arial.ttf"
|
||||
ttfConfig.fontSize = 28
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig, LongSentencesExample, cc.TEXT_ALIGNMENT_LEFT, s.width)
|
||||
label1:setAnchorPoint(cc.p(0.5,1.0))
|
||||
label1:setPosition(cc.p(s.width/2, s.height/2))
|
||||
layer:addChild(label1)
|
||||
|
@ -927,8 +948,10 @@ function LabelTTFDynamicAlignment.create()
|
|||
LabelTTFDynamicAlignment._eHorizAlign = cc.TEXT_ALIGNMENT_LEFT
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
LabelTTFDynamicAlignment._label = cc.Label:createWithTTF(LongSentencesExample, "fonts/arial.ttf", 45, s.width, cc.TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_NEHE)
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = "fonts/arial.ttf"
|
||||
ttfConfig.fontSize = 45
|
||||
LabelTTFDynamicAlignment._label = cc.Label:createWithTTF(ttfConfig, LongSentencesExample, cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
LabelTTFDynamicAlignment._label:setPosition( cc.p(s.width/2, s.height/2) )
|
||||
LabelTTFDynamicAlignment._label:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
layer:addChild(LabelTTFDynamicAlignment._label)
|
||||
|
@ -1000,9 +1023,12 @@ function LabelTTFFontsTestNew.create()
|
|||
"fonts/Schwarzwald Regular.ttf",
|
||||
"fonts/Scissor Cuts.ttf",
|
||||
}
|
||||
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = ttfPaths[0]
|
||||
ttfConfig.fontSize = 40
|
||||
for i=1, table.getn(ttfPaths) do
|
||||
local label = cc.Label:createWithTTF( ttfPaths[i], ttfPaths[i], 40, 0, cc.TEXT_ALIGNMENT_CENTER, cc.GLYPHCOLLECTION_NEHE)
|
||||
ttfConfig.fontFilePath = ttfPaths[i]
|
||||
local label = cc.Label:createWithTTF( ttfConfig, ttfPaths[i], cc.TEXT_ALIGNMENT_CENTER, 0)
|
||||
if nil ~= label then
|
||||
label:setPosition( cc.p(s.width/2, ((s.height * 0.6)/table.getn(ttfPaths) * (i -1)) + (s.height/5)))
|
||||
layer:addChild(label)
|
||||
|
@ -1029,13 +1055,180 @@ function LabelBMFontTestNew.create()
|
|||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local label1 = cc.Label:createWithBMFont("Hello World, this is testing the new Label using fnt file", "fonts/bitmapFontTest2.fnt", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
local label1 = cc.Label:createWithBMFont("fonts/bitmapFontTest2.fnt", "Hello World, this is testing the new Label using fnt file", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
label1:setPosition(cc.p(s.width/2, s.height/2))
|
||||
layer:addChild(label1)
|
||||
return layer
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------
|
||||
----- LabelTTFDistanceField
|
||||
--------------------------------------------------------
|
||||
local LabelTTFDistanceField = {}
|
||||
function LabelTTFDistanceField.create()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
Helper.titleLabel:setString("New Label + .TTF")
|
||||
Helper.subtitleLabel:setString("Testing rendering base on DistanceField")
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = "fonts/arial.ttf"
|
||||
ttfConfig.fontSize = 80
|
||||
ttfConfig.glyphs = cc.GLYPHCOLLECTION_DYNAMIC
|
||||
ttfConfig.customGlyphs = nil
|
||||
ttfConfig.distanceFieldEnabled = true
|
||||
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig,"Distance Field",cc.TEXT_ALIGNMENT_CENTER,s.width)
|
||||
label1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
label1:setPosition(cc.p(s.width/2, s.height/2))
|
||||
label1:setColor( cc.c3b(0, 255, 0) )
|
||||
local action = cc.Sequence:create(cc.DelayTime:create(1.0),
|
||||
cc.ScaleTo:create(6.0,5.0,5.0),
|
||||
cc.ScaleTo:create(6.0,1.0,1.0))
|
||||
label1:runAction(cc.RepeatForever:create(action))
|
||||
layer:addChild(label1)
|
||||
|
||||
local label2 = cc.Label:createWithTTF(ttfConfig,"Distance Field",cc.TEXT_ALIGNMENT_CENTER,s.width)
|
||||
label2:setPosition( cc.p(s.width/2, s.height/5) )
|
||||
label2:setColor( cc.c3b(255, 0, 0))
|
||||
label2:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
layer:addChild(label2)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
--------------------------------------------------------
|
||||
----- LabelTTFDistanceFieldEffect
|
||||
--------------------------------------------------------
|
||||
local LabelTTFDistanceFieldEffect = {}
|
||||
function LabelTTFDistanceFieldEffect.create()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
Helper.titleLabel:setString("New Label + .TTF")
|
||||
Helper.subtitleLabel:setString("Testing effect base on DistanceField")
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local col = cc.LayerColor:create( cc.c4b(200, 191, 231, 255))
|
||||
layer:addChild(col)
|
||||
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = "fonts/arial.ttf"
|
||||
ttfConfig.fontSize = 80
|
||||
ttfConfig.glyphs = cc.GLYPHCOLLECTION_DYNAMIC
|
||||
ttfConfig.customGlyphs = nil
|
||||
ttfConfig.distanceFieldEnabled = true
|
||||
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig,"Glow",cc.TEXT_ALIGNMENT_CENTER,s.width)
|
||||
label1:setAnchorPoint(cc.p(0.5,0.5))
|
||||
label1:setPosition(cc.p(s.width/2, s.height/2))
|
||||
label1:setColor( cc.c3b(0, 255, 0) )
|
||||
label1:setLabelEffect(cc.LabelEffect.GLOW, cc.c3b(255, 255, 0))
|
||||
layer:addChild(label1)
|
||||
|
||||
local label2 = cc.Label:createWithTTF(ttfConfig,"Outline",cc.TEXT_ALIGNMENT_CENTER,s.width)
|
||||
label2:setPosition( cc.p(s.width/2, s.height * 0.375))
|
||||
label2:setColor( cc.c3b(255, 0, 0))
|
||||
label2:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
label2:setLabelEffect(cc.LabelEffect.OUTLINE, cc.c3b(0, 0, 255))
|
||||
layer:addChild(label2)
|
||||
|
||||
local label3 = cc.Label:createWithTTF(ttfConfig,"Shadow",cc.TEXT_ALIGNMENT_CENTER,s.width)
|
||||
label3:setPosition( cc.p(s.width/2, s.height * 0.25))
|
||||
label3:setColor( cc.c3b(255, 0, 0))
|
||||
label3:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
label3:setLabelEffect(cc.LabelEffect.SHADOW, cc.c3b(0, 0, 0))
|
||||
layer:addChild(label3)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------
|
||||
--
|
||||
-- LabelCharMapTest
|
||||
--
|
||||
--------------------------------------------------------------------
|
||||
local LabelCharMapTest = {}
|
||||
|
||||
function LabelCharMapTest.create()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
Helper.titleLabel:setString("New Label + char map file")
|
||||
Helper.subtitleLabel:setString("Updating label should be fast.")
|
||||
|
||||
time = 0
|
||||
|
||||
local label1 = cc.Label:createWithCharMap("fonts/tuffy_bold_italic-charmap.plist")
|
||||
layer:addChild(label1, 0, kTagSprite1)
|
||||
label1:setPosition( cc.p(10,100) )
|
||||
label1:setOpacity( 200 )
|
||||
|
||||
local label2 = cc.Label:createWithCharMap("fonts/tuffy_bold_italic-charmap.plist")
|
||||
layer:addChild(label2, 0, kTagSprite2)
|
||||
label2:setPosition( cc.p(10,160) )
|
||||
label2:setOpacity( 32 )
|
||||
|
||||
local label3 = cc.Label:createWithCharMap("fonts/tuffy_bold_italic-charmap.png", 48, 64, 32)--32 means Space key
|
||||
label3:setString("123 Test")
|
||||
layer:addChild(label3, 0, kTagSprite3)
|
||||
label3:setPosition(cc.p(10,220))
|
||||
|
||||
local function step(dt)
|
||||
time = time + dt
|
||||
local info = string.format("%2.2f Test", time)
|
||||
|
||||
local label1 = layer:getChildByTag(kTagSprite1)
|
||||
label1:setString(info)
|
||||
|
||||
local label2 = layer:getChildByTag(kTagSprite2)
|
||||
info = string.format("%d",time)
|
||||
label2:setString(info)
|
||||
end
|
||||
|
||||
layer:scheduleUpdateWithPriorityLua(step, 0)
|
||||
|
||||
function onNodeEvent(tag)
|
||||
if tag == "exit" then
|
||||
layer:unscheduleUpdate()
|
||||
end
|
||||
end
|
||||
|
||||
layer:registerScriptHandler(onNodeEvent)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------
|
||||
----- LabelCrashTest
|
||||
--------------------------------------------------------
|
||||
local LabelCrashTest = {}
|
||||
function LabelCrashTest.create()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
Helper.titleLabel:setString("New Label + .TTF")
|
||||
Helper.subtitleLabel:setString("Testing rendering base on DistanceField")
|
||||
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = "fonts/arial.ttf"
|
||||
ttfConfig.fontSize = 80
|
||||
ttfConfig.glyphs = cc.GLYPHCOLLECTION_DYNAMIC
|
||||
ttfConfig.customGlyphs = nil
|
||||
ttfConfig.distanceFieldEnabled = true
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig,"Test崩溃123", cc.TEXT_ALIGNMENT_CENTER, s.width)
|
||||
label1:setPosition( cc.p(s.width/2, s.height/2) )
|
||||
label1:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
layer:addChild(label1)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
------------
|
||||
function LabelTestNew()
|
||||
cclog("LabelTestNew")
|
||||
m_time = 0
|
||||
|
@ -1064,6 +1257,10 @@ function LabelTestNew()
|
|||
LabelTTFDynamicAlignment.create,
|
||||
LabelTTFFontsTestNew.create,
|
||||
LabelBMFontTestNew.create,
|
||||
LabelTTFDistanceField.create,
|
||||
LabelTTFDistanceFieldEffect.create,
|
||||
LabelCharMapTest.create,
|
||||
LabelCrashTest.create,
|
||||
}
|
||||
scene:addChild(LabelFNTColorAndOpacity.create())
|
||||
scene:addChild(CreateBackMenuItem())
|
||||
|
|
|
@ -127,7 +127,7 @@ local function LuaBridgeLayer()
|
|||
|
||||
local function menuCallback(tag, pMenuItem)
|
||||
local scene = nil
|
||||
local nIdx = pMenuItem:getZOrder() - itemTagBasic
|
||||
local nIdx = pMenuItem:getLocalZOrder() - itemTagBasic
|
||||
local newScene = newLuaBridgeScene(nIdx)
|
||||
if nil ~= newScene then
|
||||
newScene:addChild(createMenuToBridgeScene(),10)
|
||||
|
|
|
@ -210,9 +210,9 @@ function TouchableSpriteTest:onEnter()
|
|||
print("sprite onTouchesEnded..")
|
||||
target:setOpacity(255)
|
||||
if target == sprite2 then
|
||||
sprite1:setZOrder(100)
|
||||
sprite1:setLocalZOrder(100)
|
||||
elseif target == sprite1 then
|
||||
sprite1:setZOrder(0)
|
||||
sprite1:setLocalZOrder(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1278,8 +1278,8 @@ local function reorderSystem(dt)
|
|||
local childArray = ReorderParticleSystems_batchNode:getChildren()
|
||||
local random = math.random(1,table.getn(childArray))
|
||||
local child = childArray[random]
|
||||
-- problem: there's no getZOrder() for cc.Object
|
||||
-- ReorderParticleSystems_batchNode:reorderChild(child, child:getZOrder() - 1)
|
||||
-- problem: there's no getLocalZOrder() for cc.Object
|
||||
-- ReorderParticleSystems_batchNode:reorderChild(child, child:getLocalZOrder() - 1)
|
||||
ReorderParticleSystems_batchNode:reorderChild(child, math.random(0, 99999))
|
||||
end
|
||||
|
||||
|
|
|
@ -501,7 +501,7 @@ local function runParticleTest()
|
|||
end
|
||||
|
||||
local function TestNCallback(tag,pMenuItem)
|
||||
local nIndex = pMenuItem:getZOrder() - ParticleTestParam.kSubMenuBasicZOrder
|
||||
local nIndex = pMenuItem:getLocalZOrder() - ParticleTestParam.kSubMenuBasicZOrder
|
||||
nSubtestNumber = nIndex
|
||||
ShowCurrentTest()
|
||||
end
|
||||
|
@ -1178,7 +1178,7 @@ local function runSpriteTest()
|
|||
end
|
||||
|
||||
local function TestNCallback(tag,pMenuItem)
|
||||
local nIndex = pMenuItem:getZOrder() - SpriteTestParam.kSubMenuBasicZOrder
|
||||
local nIndex = pMenuItem:getLocalZOrder() - SpriteTestParam.kSubMenuBasicZOrder
|
||||
nSubtestNumber = nIndex
|
||||
ShowCurrentTest()
|
||||
end
|
||||
|
@ -1661,7 +1661,7 @@ local function CreatePerformancesTestScene(nPerformanceNo)
|
|||
end
|
||||
local function menuCallback(tag, pMenuItem)
|
||||
local scene = nil
|
||||
local nIdx = pMenuItem:getZOrder() - kItemTagBasic
|
||||
local nIdx = pMenuItem:getLocalZOrder() - kItemTagBasic
|
||||
local PerformanceTestScene = CreatePerformancesTestScene(nIdx)
|
||||
if nil ~= PerformanceTestScene then
|
||||
cc.Director:getInstance():replaceScene(PerformanceTestScene)
|
||||
|
|
|
@ -8,6 +8,16 @@ import os, os.path
|
|||
import shutil
|
||||
from optparse import OptionParser
|
||||
|
||||
def get_num_of_cpu():
|
||||
''' The build process can be accelerated by running multiple concurrent job processes using the -j-option.
|
||||
'''
|
||||
try:
|
||||
from numpy.distutils import cpuinfo
|
||||
return cpuinfo.cpu._getNCPUs()
|
||||
except Exception:
|
||||
print "Can't know cpuinfo, use default 1 cpu"
|
||||
return 1
|
||||
|
||||
def check_environment_variables_sdk():
|
||||
''' Checking the environment ANDROID_SDK_ROOT, which will be used for building
|
||||
'''
|
||||
|
@ -61,11 +71,13 @@ def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,and
|
|||
ndk_module_path = 'NDK_MODULE_PATH=%s;%s/external;%s/cocos' % (cocos_root, cocos_root, cocos_root)
|
||||
else:
|
||||
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
|
||||
|
||||
|
||||
num_of_cpu = get_num_of_cpu()
|
||||
|
||||
if ndk_build_param == None:
|
||||
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
|
||||
command = '%s -j%d -C %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_module_path)
|
||||
else:
|
||||
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
|
||||
command = '%s -j%d -C %s %s %s' % (ndk_path, num_of_cpu, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
|
||||
if os.system(command) != 0:
|
||||
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
|
||||
elif android_platform is not None:
|
||||
|
|
|
@ -8,6 +8,16 @@ import os, os.path
|
|||
import shutil
|
||||
from optparse import OptionParser
|
||||
|
||||
def get_num_of_cpu():
|
||||
''' The build process can be accelerated by running multiple concurrent job processes using the -j-option.
|
||||
'''
|
||||
try:
|
||||
from numpy.distutils import cpuinfo
|
||||
return cpuinfo.cpu._getNCPUs()
|
||||
except Exception:
|
||||
print "Can't know cpuinfo, use default 1 cpu"
|
||||
return 1
|
||||
|
||||
def check_environment_variables_sdk():
|
||||
''' Checking the environment ANDROID_SDK_ROOT, which will be used for building
|
||||
'''
|
||||
|
@ -62,10 +72,12 @@ def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,and
|
|||
else:
|
||||
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
|
||||
|
||||
num_of_cpu = get_num_of_cpu()
|
||||
|
||||
if ndk_build_param == None:
|
||||
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
|
||||
command = '%s -j%d -C %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_module_path)
|
||||
else:
|
||||
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
|
||||
command = '%s -j%d -C %s %s %s' % (ndk_path, num_of_cpu, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
|
||||
if os.system(command) != 0:
|
||||
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
|
||||
elif android_platform is not None:
|
||||
|
|
|
@ -8,6 +8,16 @@ import os, os.path
|
|||
import shutil
|
||||
from optparse import OptionParser
|
||||
|
||||
def get_num_of_cpu():
|
||||
''' The build process can be accelerated by running multiple concurrent job processes using the -j-option.
|
||||
'''
|
||||
try:
|
||||
from numpy.distutils import cpuinfo
|
||||
return cpuinfo.cpu._getNCPUs()
|
||||
except Exception:
|
||||
print "Can't know cpuinfo, use default 1 cpu"
|
||||
return 1
|
||||
|
||||
def check_environment_variables_sdk():
|
||||
''' Checking the environment ANDROID_SDK_ROOT, which will be used for building
|
||||
'''
|
||||
|
@ -62,10 +72,12 @@ def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,and
|
|||
else:
|
||||
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
|
||||
|
||||
num_of_cpu = get_num_of_cpu()
|
||||
|
||||
if ndk_build_param == None:
|
||||
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
|
||||
command = '%s -j%d -C %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_module_path)
|
||||
else:
|
||||
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
|
||||
command = '%s -j%d -C %s %s %s' % (ndk_path, num_of_cpu, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
|
||||
if os.system(command) != 0:
|
||||
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
|
||||
elif android_platform is not None:
|
||||
|
|
Loading…
Reference in New Issue