mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop
Conflicts: cocos/scripting/javascript/bindings/cocos2d_specifics.cpp
This commit is contained in:
commit
3de7ed93f9
|
@ -2,7 +2,8 @@ language: cpp
|
|||
env:
|
||||
matrix:
|
||||
- GEN_JSB=YES
|
||||
- PLATFORM=linux DEBUG=1
|
||||
- PLATFORM=linux DEBUG=1 CC_COMPILER=gcc CXX_COMPILER=g++
|
||||
- PLATFORM=linux DEBUG=1 CC_COMPILER=clang CXX_COMPILER=clang++
|
||||
# Since switching to C++11 only the ARM version of the nactive client
|
||||
# port currently builds. TODO(sbc): Re-enable all architectures.
|
||||
# Disabled travis-ci build for native client port since it doesn't support std::thread, std::mutex.
|
||||
|
@ -23,6 +24,8 @@ env:
|
|||
9lV+vgJQDRcFe7dKwtC86vk10EU7Ym2bhVmhMxi/AlmJXgavjmPVdizRT7rh
|
||||
X2Ry/Nb6hGRkH3WS0T3D/KG1+e7lP/TMB9bvo6/locLJ2A6Z1YI=
|
||||
script:
|
||||
- export CC=$CC_COMPILER
|
||||
- export CXX=$CXX_COMPILER
|
||||
- tools/travis-scripts/run-script.sh
|
||||
before_install:
|
||||
- tools/travis-scripts/before-install.sh
|
||||
|
|
16
AUTHORS
16
AUTHORS
|
@ -94,6 +94,7 @@ Developers:
|
|||
use tinyxml2 to replace libxml2
|
||||
Added Mingw-crt Support without breaking VS SDK
|
||||
CMake support for windows.
|
||||
Added support for x64 target of windows.
|
||||
|
||||
mchinen
|
||||
fix emulator issue for OpenGL ES 2.0 on Android
|
||||
|
@ -356,6 +357,7 @@ Developers:
|
|||
|
||||
ThePickleMan
|
||||
Adding 'rotationIsDir' property to ParticleSystem.
|
||||
DrawNode supports to draw triangle, quad bezier, cubic bezier.
|
||||
|
||||
Jianghua (jxhgzs)
|
||||
Adding an additional transform for CCNode.
|
||||
|
@ -519,6 +521,7 @@ Developers:
|
|||
Correcting the type detecting order for Lua CCBProxy::getNodeTypeName.
|
||||
Casting variables to their own type, and print warning info if no corresponding lua callback function instead of crash.
|
||||
fix of WebSocket url parse error for 'ws://domain.com/websocket' pattern.
|
||||
Fixed a bug that Websocket doesn't support send/receive data which larger than 4096 bytes.
|
||||
|
||||
musikov
|
||||
Fixing a bug that missing precision when getting strokeColor and fontFillColor
|
||||
|
@ -709,6 +712,19 @@ Developers:
|
|||
v1ctor
|
||||
ControlSlider supports to set selected thumb sprite.
|
||||
ControlButton supports to set scale ratio of touchdown state
|
||||
|
||||
akof1314
|
||||
TestCpp works by using CMake and mingw on Windows.
|
||||
|
||||
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
|
||||
|
|
34
CHANGELOG
34
CHANGELOG
|
@ -1,8 +1,38 @@
|
|||
cocos2d-x-3.0final ?.? ?
|
||||
cocos2d-x-3.0beta2 ?.? ?
|
||||
[All]
|
||||
[FIX] Crash was triggered if there is not `textureFileName`section in particle plist file.
|
||||
[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
|
||||
[NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use.
|
||||
[NEW] Label: Integrates LabelAtlas into new Label.
|
||||
[NEW] Node: Added `setGlobalZOrder()`. Useful to change the Node's render order. Node::setZOrder() -> Node::setLocalZOrder()
|
||||
[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.
|
||||
[FIX] Label: Crash when using unknown characters.
|
||||
[FIX] Console: log(format, va_args) is private to prevent possible resolution errors
|
||||
[FIX] Configuration: dumpInfo() -> getInfo()
|
||||
[FIX] ControlSlider doesn't support to set selected thumb sprite.
|
||||
[FIX] ControlButton doesn't support to set scale ratio of touchdown state.
|
||||
[FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file.
|
||||
[FIX] Renderer: Uses a float as key with only the depth. Viewport, opaque are not needed now
|
||||
[FIX] Renderer Performance Fix: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster
|
||||
[FIX] Renderer Performance Fix: Sprite and SpriteBatchNode (and subclasses) has much better performance
|
||||
[FIX] Renderer Performance Fix: When note using VAO, call glBufferData() instead of glBufferSubData().
|
||||
[FIX] Renderer Performance Fix: Doesn't sort z=0 elements. It also uses sort() instead of stable_sort() for z!=0.
|
||||
[FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well
|
||||
[FIX] Tests: TestCpp works with CMake on Windows.
|
||||
[FIX] Tests: Sprites Performance Test has 4 new tests
|
||||
[FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected
|
||||
[FIX] TextureCache: dumpCachedTextureInfo() -> getCachedTextureInfo()
|
||||
[FIX] Websocket doesn't support send/receive data which larger than 4096 bytes.
|
||||
[FIX] Windows: There will be some compilation errors when using x64 target on Windows.
|
||||
|
||||
cocos2d-x-3.0beta Jan.7 2014
|
||||
[All]
|
||||
[NEW] New label: shadow, outline, glow support
|
||||
|
|
|
@ -38,15 +38,15 @@ option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
|
|||
option(USE_BOX2D "Use box2d for physics library" OFF)
|
||||
option(DEBUG_MODE "Debug or release?" ON)
|
||||
option(BUILD_LIBS_LUA "Build lua libraries" OFF)
|
||||
option(BUILD_GUI "Build GUI library" OFF)
|
||||
option(BUILD_NETWORK "Build network library" OFF)
|
||||
option(BUILD_EXTENSIONS "Build extension library" OFF)
|
||||
option(BUILD_EDITOR_SPINE "Build editor support for spine" OFF)
|
||||
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" OFF)
|
||||
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" OFF)
|
||||
option(BUILD_GUI "Build GUI library" ON)
|
||||
option(BUILD_NETWORK "Build network library" ON)
|
||||
option(BUILD_EXTENSIONS "Build extension library" ON)
|
||||
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
|
||||
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
|
||||
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
|
||||
|
||||
option(BUILD_HelloCpp "Only build HelloCpp sample" ON)
|
||||
option(BUILD_TestCpp "Only build TestCpp sample" OFF)
|
||||
option(BUILD_TestCpp "Only build TestCpp sample" ON)
|
||||
option(BUILD_HelloLua "Only build HelloLua sample" OFF)
|
||||
option(BUILD_TestLua "Only build TestLua sample" OFF)
|
||||
|
||||
|
|
|
@ -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 @@
|
|||
3d6ada05d55194dd8e4c10ed8316add7c0d8705c
|
||||
df164052374ec5c6ec61d99f36a20cc99638b631
|
|
@ -1 +1 @@
|
|||
2efefc01ff97bda1498d1d4a850ea1881f751f7c
|
||||
447e7ba37294e6da0df2e02f5a62f30fb15e3272
|
|
@ -47,10 +47,9 @@ CCEventListenerTouch.cpp \
|
|||
CCEventMouse.cpp \
|
||||
CCEventTouch.cpp \
|
||||
CCFont.cpp \
|
||||
CCFontCharMap.cpp \
|
||||
CCFontAtlas.cpp \
|
||||
CCFontAtlasCache.cpp \
|
||||
CCFontAtlasFactory.cpp \
|
||||
CCFontDefinition.cpp \
|
||||
CCFontFNT.cpp \
|
||||
CCFontFreeType.cpp \
|
||||
ccFPSImages.c \
|
||||
|
@ -90,7 +89,6 @@ CCSpriteBatchNode.cpp \
|
|||
CCSpriteFrame.cpp \
|
||||
CCSpriteFrameCache.cpp \
|
||||
CCTextFieldTTF.cpp \
|
||||
CCTextImage.cpp \
|
||||
CCTexture2D.cpp \
|
||||
CCTextureAtlas.cpp \
|
||||
CCTextureCache.cpp \
|
||||
|
@ -122,6 +120,7 @@ renderer/CCFrustum.cpp \
|
|||
renderer/CCGroupCommand.cpp \
|
||||
renderer/CCMaterialManager.cpp \
|
||||
renderer/CCQuadCommand.cpp \
|
||||
renderer/CCBatchCommand.cpp \
|
||||
renderer/CCRenderCommand.cpp \
|
||||
renderer/CCRenderer.cpp \
|
||||
renderer/CCRenderMaterial.cpp \
|
||||
|
|
|
@ -33,6 +33,12 @@ NS_CC_BEGIN
|
|||
//
|
||||
// CameraAction
|
||||
//
|
||||
ActionCamera::ActionCamera()
|
||||
{
|
||||
kmVec3Fill(&_center, 0, 0, 0);
|
||||
kmVec3Fill(&_eye, 0, 0, FLT_EPSILON);
|
||||
kmVec3Fill(&_up, 0, 1, 0);
|
||||
}
|
||||
void ActionCamera::startWithTarget(Node *target)
|
||||
{
|
||||
ActionInterval::startWithTarget(target);
|
||||
|
@ -54,53 +60,39 @@ ActionCamera * ActionCamera::reverse() const
|
|||
|
||||
void ActionCamera::restore()
|
||||
{
|
||||
_eyeX = _eyeY = 0.0f;
|
||||
_eyeZ = FLT_EPSILON;
|
||||
kmVec3Fill(&_center, 0, 0, 0);
|
||||
kmVec3Fill(&_eye, 0, 0, FLT_EPSILON);
|
||||
kmVec3Fill(&_up, 0, 1, 0);
|
||||
}
|
||||
|
||||
_centerX = _centerY = _centerZ = 0.0f;
|
||||
|
||||
_upX = 0.0f;
|
||||
_upY = 1.0f;
|
||||
_upZ = 0.0f;
|
||||
void ActionCamera::setEye(const kmVec3& eye)
|
||||
{
|
||||
_eye = eye;
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
void ActionCamera::setEye(float x, float y, float z)
|
||||
{
|
||||
_eyeX = x;
|
||||
_eyeY = y;
|
||||
_eyeZ = z;
|
||||
|
||||
kmVec3Fill(&_eye, x, y, z);
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
void ActionCamera::setCenter(float centerX, float centerY, float centerZ)
|
||||
void ActionCamera::setCenter(const kmVec3& center)
|
||||
{
|
||||
_centerX = centerX;
|
||||
_centerY = centerY;
|
||||
_centerZ = centerZ;
|
||||
|
||||
_center = center;
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
void ActionCamera::setUp(float upX, float upY, float upZ)
|
||||
void ActionCamera::setUp(const kmVec3& up)
|
||||
{
|
||||
_upX = upX;
|
||||
_upY = upY;
|
||||
_upZ = upZ;
|
||||
|
||||
_up = up;
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
void ActionCamera::updateTransform()
|
||||
{
|
||||
kmVec3 eye, center, up;
|
||||
|
||||
kmVec3Fill(&eye, _eyeX, _eyeY , _eyeZ);
|
||||
kmVec3Fill(¢er, _centerX, _centerY, _centerZ);
|
||||
kmVec3Fill(&up, _upX, _upY, _upZ);
|
||||
|
||||
kmMat4 lookupMatrix;
|
||||
kmMat4LookAt(&lookupMatrix, &eye, ¢er, &up);
|
||||
kmMat4LookAt(&lookupMatrix, &_eye, &_center, &_up);
|
||||
|
||||
Point anchorPoint = _target->getAnchorPointInPoints();
|
||||
|
||||
|
@ -199,9 +191,9 @@ void OrbitCamera::update(float dt)
|
|||
float za = _radZ + _radDeltaZ * dt;
|
||||
float xa = _radX + _radDeltaX * dt;
|
||||
|
||||
float i = sinf(za) * cosf(xa) * r + _centerX;
|
||||
float j = sinf(za) * sinf(xa) * r + _centerY;
|
||||
float k = cosf(za) * r + _centerZ;
|
||||
float i = sinf(za) * cosf(xa) * r + _center.x;
|
||||
float j = sinf(za) * sinf(xa) * r + _center.y;
|
||||
float k = cosf(za) * r + _center.z;
|
||||
|
||||
setEye(i,j,k);
|
||||
}
|
||||
|
@ -211,9 +203,9 @@ void OrbitCamera::sphericalRadius(float *newRadius, float *zenith, float *azimut
|
|||
float r; // radius
|
||||
float s;
|
||||
|
||||
float x = _eyeX - _centerX;
|
||||
float y = _eyeY - _centerY;
|
||||
float z = _eyeZ - _centerZ;
|
||||
float x = _eye.x - _center.x;
|
||||
float y = _eye.y - _center.y;
|
||||
float z = _eye.z - _center.z;
|
||||
|
||||
r = sqrtf( powf(x,2) + powf(y,2) + powf(z,2));
|
||||
s = sqrtf( powf(x,2) + powf(y,2));
|
||||
|
|
|
@ -50,17 +50,7 @@ public:
|
|||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
ActionCamera()
|
||||
:_centerX(0)
|
||||
,_centerY(0)
|
||||
,_centerZ(0)
|
||||
,_eyeX(0)
|
||||
,_eyeY(0)
|
||||
,_eyeZ(FLT_EPSILON)
|
||||
,_upX(0)
|
||||
,_upY(1)
|
||||
,_upZ(0)
|
||||
{}
|
||||
ActionCamera();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -72,23 +62,28 @@ public:
|
|||
virtual ActionCamera * reverse() const override;
|
||||
virtual ActionCamera *clone() const override;
|
||||
|
||||
/* sets the Eye value of the Camera */
|
||||
void setEye(const kmVec3 &eye);
|
||||
void setEye(float x, float y, float z);
|
||||
/* returns the Eye value of the Camera */
|
||||
const kmVec3& getEye() const { return _eye; }
|
||||
/* sets the Center value of the Camera */
|
||||
void setCenter(const kmVec3 ¢er);
|
||||
/* returns the Center value of the Camera */
|
||||
const kmVec3& getCenter() const { return _center; }
|
||||
/* sets the Up value of the Camera */
|
||||
void setUp(const kmVec3 &up);
|
||||
/* Returns the Up value of the Camera */
|
||||
const kmVec3& getUp() const { return _up; }
|
||||
|
||||
protected:
|
||||
|
||||
void restore();
|
||||
void setEye(float x, float y, float z);
|
||||
void setCenter(float x, float y, float z);
|
||||
void setUp(float x, float y, float z);
|
||||
void updateTransform();
|
||||
|
||||
float _centerX;
|
||||
float _centerY;
|
||||
float _centerZ;
|
||||
float _eyeX;
|
||||
float _eyeY;
|
||||
float _eyeZ;
|
||||
float _upX;
|
||||
float _upY;
|
||||
float _upZ;
|
||||
kmVec3 _center;
|
||||
kmVec3 _eye;
|
||||
kmVec3 _up;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,7 +34,7 @@ THE SOFTWARE.
|
|||
#include "ccGLStateCache.h"
|
||||
#include "CCDirector.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
|
||||
// external
|
||||
|
@ -152,13 +152,13 @@ void AtlasNode::draw(void)
|
|||
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
_quadCommand.init(0,
|
||||
_vertexZ,
|
||||
_quadCommand.init(
|
||||
_globalZOrder,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
_blendFunc,
|
||||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
_quadsToDraw,
|
||||
_modelViewTransform);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
|
|
|
@ -31,9 +31,10 @@
|
|||
#include "CCShaderCache.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCDrawingPrimitives.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCCustomCommand.h"
|
||||
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -209,12 +210,12 @@ void ClippingNode::visit()
|
|||
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
_groupCommand.init(0,_vertexZ);
|
||||
_groupCommand.init(_globalZOrder);
|
||||
renderer->addCommand(&_groupCommand);
|
||||
|
||||
renderer->pushGroup(_groupCommand.getRenderQueueID());
|
||||
|
||||
_beforeVisitCmd.init(0,_vertexZ);
|
||||
_beforeVisitCmd.init(_globalZOrder);
|
||||
_beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
|
||||
renderer->addCommand(&_beforeVisitCmd);
|
||||
if (_alphaThreshold < 1)
|
||||
|
@ -237,7 +238,7 @@ void ClippingNode::visit()
|
|||
}
|
||||
_stencil->visit();
|
||||
|
||||
_afterDrawStencilCmd.init(0,_vertexZ);
|
||||
_afterDrawStencilCmd.init(_globalZOrder);
|
||||
_afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
|
||||
renderer->addCommand(&_afterDrawStencilCmd);
|
||||
|
||||
|
@ -251,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;
|
||||
|
@ -267,7 +268,7 @@ void ClippingNode::visit()
|
|||
this->draw();
|
||||
}
|
||||
|
||||
_afterVisitCmd.init(0,_vertexZ);
|
||||
_afterVisitCmd.init(_globalZOrder);
|
||||
_afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
|
||||
renderer->addCommand(&_afterVisitCmd);
|
||||
|
||||
|
|
|
@ -31,13 +31,13 @@ THE SOFTWARE.
|
|||
#include "CCDictionary.h"
|
||||
#include "CCInteger.h"
|
||||
#include "CCBool.h"
|
||||
#include "cocos2d.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
extern const char* cocos2dVersion();
|
||||
|
||||
Configuration* Configuration::s_sharedConfiguration = nullptr;
|
||||
|
||||
|
@ -88,24 +88,20 @@ Configuration::~Configuration()
|
|||
{
|
||||
}
|
||||
|
||||
void Configuration::dumpInfo() const
|
||||
std::string Configuration::getInfo() const
|
||||
{
|
||||
// Dump
|
||||
Value forDump = Value(_valueDict);
|
||||
CCLOG("%s", forDump.getDescription().c_str());
|
||||
|
||||
// And Dump some warnings as well
|
||||
#if CC_ENABLE_PROFILERS
|
||||
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.h)");
|
||||
printf("\n");
|
||||
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.h)\n");
|
||||
#endif
|
||||
|
||||
#if CC_ENABLE_GL_STATE_CACHE == 0
|
||||
CCLOG("");
|
||||
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it (from ccConfig.h)");
|
||||
printf("\n");
|
||||
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it (from ccConfig.h)\n");
|
||||
#endif
|
||||
|
||||
// Dump
|
||||
Value forDump = Value(_valueDict);
|
||||
return forDump.getDescription();
|
||||
}
|
||||
|
||||
void Configuration::gatherGPUInfo()
|
||||
|
@ -150,7 +146,7 @@ void Configuration::gatherGPUInfo()
|
|||
|
||||
_supportsShareableVAO = checkForGLExtension("vertex_array_object");
|
||||
_valueDict["gl.supports_vertex_array_object"] = Value(_supportsShareableVAO);
|
||||
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
|
|
|
@ -122,8 +122,8 @@ public:
|
|||
/** sets a new key/value pair in the configuration dictionary */
|
||||
void setValue(const std::string& key, const Value& value);
|
||||
|
||||
/** dumps the current configuration on the console */
|
||||
void dumpInfo() const;
|
||||
/** returns the Configuration info */
|
||||
std::string getInfo() const;
|
||||
|
||||
/** gathers OpenGL / GPU information */
|
||||
void gatherGPUInfo();
|
||||
|
|
|
@ -60,8 +60,10 @@ THE SOFTWARE.
|
|||
#include "CCEventDispatcher.h"
|
||||
#include "CCEventCustom.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCFrustum.h"
|
||||
#include "CCConsole.h"
|
||||
|
||||
/**
|
||||
Position of the FPS
|
||||
|
||||
|
@ -116,9 +118,6 @@ bool Director::init(void)
|
|||
|
||||
_scenesStack.reserve(15);
|
||||
|
||||
// projection delegate if "Custom" projection is used
|
||||
_projectionDelegate = nullptr;
|
||||
|
||||
// FPS
|
||||
_accumDt = 0.0f;
|
||||
_frameRate = 0.0f;
|
||||
|
@ -131,16 +130,16 @@ bool Director::init(void)
|
|||
|
||||
// paused ?
|
||||
_paused = false;
|
||||
|
||||
|
||||
// purge ?
|
||||
_purgeDirectorInNextLoop = false;
|
||||
|
||||
_winSizeInPoints = Size::ZERO;
|
||||
_winSizeInPoints = Size::ZERO;
|
||||
|
||||
_openGLView = nullptr;
|
||||
|
||||
|
||||
_cullingFrustum = new Frustum();
|
||||
|
||||
|
||||
_contentScaleFactor = 1.0f;
|
||||
|
||||
// scheduler
|
||||
|
@ -163,15 +162,15 @@ bool Director::init(void)
|
|||
//init TextureCache
|
||||
initTextureCache();
|
||||
|
||||
// Renderer
|
||||
_renderer = new Renderer;
|
||||
_console = new Console;
|
||||
|
||||
// create autorelease pool
|
||||
PoolManager::sharedPoolManager()->push();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Director::~Director(void)
|
||||
{
|
||||
CCLOGINFO("deallocing Director: %p", this);
|
||||
|
@ -179,7 +178,7 @@ Director::~Director(void)
|
|||
CC_SAFE_RELEASE(_FPSLabel);
|
||||
CC_SAFE_RELEASE(_SPFLabel);
|
||||
CC_SAFE_RELEASE(_drawsLabel);
|
||||
|
||||
|
||||
CC_SAFE_RELEASE(_runningScene);
|
||||
CC_SAFE_RELEASE(_notificationNode);
|
||||
CC_SAFE_RELEASE(_scheduler);
|
||||
|
@ -192,6 +191,7 @@ Director::~Director(void)
|
|||
delete _eventProjectionChanged;
|
||||
|
||||
delete _renderer;
|
||||
delete _console;
|
||||
|
||||
// pop the autorelease pool
|
||||
PoolManager::sharedPoolManager()->pop();
|
||||
|
@ -284,17 +284,17 @@ void Director::drawScene()
|
|||
}
|
||||
|
||||
kmGLPushMatrix();
|
||||
|
||||
|
||||
//construct the frustum
|
||||
{
|
||||
kmMat4 view;
|
||||
kmMat4 projection;
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &projection);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &view);
|
||||
|
||||
|
||||
_cullingFrustum->setupFromMatrix(view, projection);
|
||||
}
|
||||
|
||||
|
||||
// draw the scene
|
||||
if (_runningScene)
|
||||
{
|
||||
|
@ -307,7 +307,7 @@ void Director::drawScene()
|
|||
{
|
||||
_notificationNode->visit();
|
||||
}
|
||||
|
||||
|
||||
if (_displayStats)
|
||||
{
|
||||
showStats();
|
||||
|
@ -325,7 +325,7 @@ void Director::drawScene()
|
|||
{
|
||||
_openGLView->swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
if (_displayStats)
|
||||
{
|
||||
calculateMPF();
|
||||
|
@ -378,7 +378,7 @@ void Director::setOpenGLView(EGLView *openGLView)
|
|||
// Configuration. Gather GPU info
|
||||
Configuration *conf = Configuration::getInstance();
|
||||
conf->gatherGPUInfo();
|
||||
conf->dumpInfo();
|
||||
CCLOG("%s\n",conf->getInfo().c_str());
|
||||
|
||||
// EAGLView is not a Object
|
||||
delete _openGLView; // [openGLView_ release]
|
||||
|
@ -386,16 +386,16 @@ void Director::setOpenGLView(EGLView *openGLView)
|
|||
|
||||
// set size
|
||||
_winSizeInPoints = _openGLView->getDesignResolutionSize();
|
||||
|
||||
|
||||
createStatsLabel();
|
||||
|
||||
|
||||
if (_openGLView)
|
||||
{
|
||||
setGLDefaultValues();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_renderer->initGLView();
|
||||
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// _touchDispatcher->setDispatchEvents(true);
|
||||
|
@ -481,13 +481,12 @@ void Director::setProjection(Projection projection)
|
|||
kmGLMultMatrix(&matrixLookup);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case Projection::CUSTOM:
|
||||
if (_projectionDelegate)
|
||||
_projectionDelegate->updateProjection();
|
||||
|
||||
// Projection Delegate is no longer needed
|
||||
// since the event "PROJECTION CHANGED" is emitted
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
CCLOG("cocos2d: Director: unrecognized projection");
|
||||
break;
|
||||
|
@ -549,10 +548,10 @@ static void GLToClipTransform(kmMat4 *transformOut)
|
|||
{
|
||||
kmMat4 projection;
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &projection);
|
||||
|
||||
|
||||
kmMat4 modelview;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &modelview);
|
||||
|
||||
|
||||
kmMat4Multiply(transformOut, &projection, &modelview);
|
||||
}
|
||||
|
||||
|
@ -560,19 +559,19 @@ Point Director::convertToGL(const Point& uiPoint)
|
|||
{
|
||||
kmMat4 transform;
|
||||
GLToClipTransform(&transform);
|
||||
|
||||
|
||||
kmMat4 transformInv;
|
||||
kmMat4Inverse(&transformInv, &transform);
|
||||
|
||||
|
||||
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w
|
||||
kmScalar zClip = transform.mat[14]/transform.mat[15];
|
||||
|
||||
|
||||
Size glSize = _openGLView->getDesignResolutionSize();
|
||||
kmVec3 clipCoord = {2.0f*uiPoint.x/glSize.width - 1.0f, 1.0f - 2.0f*uiPoint.y/glSize.height, zClip};
|
||||
|
||||
|
||||
kmVec3 glCoord;
|
||||
kmVec3TransformCoord(&glCoord, &clipCoord, &transformInv);
|
||||
|
||||
|
||||
return Point(glCoord.x, glCoord.y);
|
||||
}
|
||||
|
||||
|
@ -580,12 +579,12 @@ Point Director::convertToUI(const Point& glPoint)
|
|||
{
|
||||
kmMat4 transform;
|
||||
GLToClipTransform(&transform);
|
||||
|
||||
|
||||
kmVec3 clipCoord;
|
||||
// Need to calculate the zero depth from the transform.
|
||||
kmVec3 glCoord = {glPoint.x, glPoint.y, 0.0};
|
||||
kmVec3TransformCoord(&clipCoord, &glCoord, &transform);
|
||||
|
||||
|
||||
Size glSize = _openGLView->getDesignResolutionSize();
|
||||
return Point(glSize.width*(clipCoord.x*0.5 + 0.5), glSize.height*(-clipCoord.y*0.5 + 0.5));
|
||||
}
|
||||
|
@ -606,7 +605,7 @@ Size Director::getVisibleSize() const
|
|||
{
|
||||
return _openGLView->getVisibleSize();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
return Size::ZERO;
|
||||
}
|
||||
|
@ -618,7 +617,7 @@ Point Director::getVisibleOrigin() const
|
|||
{
|
||||
return _openGLView->getVisibleOrigin();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
return Point::ZERO;
|
||||
}
|
||||
|
@ -948,17 +947,20 @@ void Director::createStatsLabel()
|
|||
*/
|
||||
float factor = EGLView::getInstance()->getDesignResolutionSize().height / 320.0f;
|
||||
|
||||
_FPSLabel = new LabelAtlas;
|
||||
_FPSLabel = LabelAtlas::create();
|
||||
_FPSLabel->retain();
|
||||
_FPSLabel->setIgnoreContentScaleFactor(true);
|
||||
_FPSLabel->initWithString("00.0", texture, 12, 32 , '.');
|
||||
_FPSLabel->setScale(factor);
|
||||
|
||||
_SPFLabel = new LabelAtlas;
|
||||
_SPFLabel = LabelAtlas::create();
|
||||
_SPFLabel->retain();
|
||||
_SPFLabel->setIgnoreContentScaleFactor(true);
|
||||
_SPFLabel->initWithString("0.000", texture, 12, 32, '.');
|
||||
_SPFLabel->setScale(factor);
|
||||
|
||||
_drawsLabel = new LabelAtlas;
|
||||
_drawsLabel = LabelAtlas::create();
|
||||
_drawsLabel->retain();
|
||||
_drawsLabel->setIgnoreContentScaleFactor(true);
|
||||
_drawsLabel->initWithString("000", texture, 12, 32, '.');
|
||||
_drawsLabel->setScale(factor);
|
||||
|
@ -970,11 +972,6 @@ void Director::createStatsLabel()
|
|||
_FPSLabel->setPosition(CC_DIRECTOR_STATS_POSITION);
|
||||
}
|
||||
|
||||
float Director::getContentScaleFactor() const
|
||||
{
|
||||
return _contentScaleFactor;
|
||||
}
|
||||
|
||||
void Director::setContentScaleFactor(float scaleFactor)
|
||||
{
|
||||
if (scaleFactor != _contentScaleFactor)
|
||||
|
@ -984,11 +981,6 @@ void Director::setContentScaleFactor(float scaleFactor)
|
|||
}
|
||||
}
|
||||
|
||||
Node* Director::getNotificationNode()
|
||||
{
|
||||
return _notificationNode;
|
||||
}
|
||||
|
||||
void Director::setNotificationNode(Node *node)
|
||||
{
|
||||
CC_SAFE_RELEASE(_notificationNode);
|
||||
|
@ -996,16 +988,6 @@ void Director::setNotificationNode(Node *node)
|
|||
CC_SAFE_RETAIN(_notificationNode);
|
||||
}
|
||||
|
||||
DirectorDelegate* Director::getDelegate() const
|
||||
{
|
||||
return _projectionDelegate;
|
||||
}
|
||||
|
||||
void Director::setDelegate(DirectorDelegate* delegate)
|
||||
{
|
||||
_projectionDelegate = delegate;
|
||||
}
|
||||
|
||||
void Director::setScheduler(Scheduler* scheduler)
|
||||
{
|
||||
if (_scheduler != scheduler)
|
||||
|
@ -1016,11 +998,6 @@ void Director::setScheduler(Scheduler* scheduler)
|
|||
}
|
||||
}
|
||||
|
||||
Scheduler* Director::getScheduler() const
|
||||
{
|
||||
return _scheduler;
|
||||
}
|
||||
|
||||
void Director::setActionManager(ActionManager* actionManager)
|
||||
{
|
||||
if (_actionManager != actionManager)
|
||||
|
@ -1031,16 +1008,6 @@ void Director::setActionManager(ActionManager* actionManager)
|
|||
}
|
||||
}
|
||||
|
||||
ActionManager* Director::getActionManager() const
|
||||
{
|
||||
return _actionManager;
|
||||
}
|
||||
|
||||
EventDispatcher* Director::getEventDispatcher() const
|
||||
{
|
||||
return _eventDispatcher;
|
||||
}
|
||||
|
||||
void Director::setEventDispatcher(EventDispatcher* dispatcher)
|
||||
{
|
||||
if (_eventDispatcher != dispatcher)
|
||||
|
@ -1051,12 +1018,6 @@ void Director::setEventDispatcher(EventDispatcher* dispatcher)
|
|||
}
|
||||
}
|
||||
|
||||
Renderer* Director::getRenderer() const
|
||||
{
|
||||
return _renderer;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************
|
||||
* implementation of DisplayLinkDirector
|
||||
**************************************************/
|
||||
|
|
|
@ -60,6 +60,7 @@ class EventListenerCustom;
|
|||
class TextureCache;
|
||||
class Frustum;
|
||||
class Renderer;
|
||||
class Console;
|
||||
|
||||
/**
|
||||
@brief Class that creates and handles the main Window and manages how
|
||||
|
@ -186,21 +187,9 @@ public:
|
|||
Useful to hook a notification object, like Notifications (http://github.com/manucorporat/CCNotifications)
|
||||
@since v0.99.5
|
||||
*/
|
||||
Node* getNotificationNode();
|
||||
Node* getNotificationNode() const { return _notificationNode; }
|
||||
void setNotificationNode(Node *node);
|
||||
|
||||
/** Director delegate. It shall implement the DirectorDelegate protocol
|
||||
@since v0.99.5
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
DirectorDelegate* getDelegate() const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void setDelegate(DirectorDelegate* delegate);
|
||||
|
||||
// window size
|
||||
|
||||
/** returns the size of the OpenGL view in points.
|
||||
|
@ -340,7 +329,7 @@ public:
|
|||
@since v0.99.4
|
||||
*/
|
||||
void setContentScaleFactor(float scaleFactor);
|
||||
float getContentScaleFactor() const;
|
||||
float getContentScaleFactor() const { return _contentScaleFactor; }
|
||||
|
||||
/**
|
||||
Get the Culling Frustum
|
||||
|
@ -351,7 +340,7 @@ public:
|
|||
/** Gets the Scheduler associated with this director
|
||||
@since v2.0
|
||||
*/
|
||||
Scheduler* getScheduler() const;
|
||||
Scheduler* getScheduler() const { return _scheduler; }
|
||||
|
||||
/** Sets the Scheduler associated with this director
|
||||
@since v2.0
|
||||
|
@ -361,7 +350,7 @@ public:
|
|||
/** Gets the ActionManager associated with this director
|
||||
@since v2.0
|
||||
*/
|
||||
ActionManager* getActionManager() const;
|
||||
ActionManager* getActionManager() const { return _actionManager; }
|
||||
|
||||
/** Sets the ActionManager associated with this director
|
||||
@since v2.0
|
||||
|
@ -371,7 +360,7 @@ public:
|
|||
/** Gets the EventDispatcher associated with this director
|
||||
@since v3.0
|
||||
*/
|
||||
EventDispatcher* getEventDispatcher() const;
|
||||
EventDispatcher* getEventDispatcher() const { return _eventDispatcher; }
|
||||
|
||||
/** Sets the EventDispatcher associated with this director
|
||||
@since v3.0
|
||||
|
@ -381,7 +370,12 @@ public:
|
|||
/** Returns the Renderer
|
||||
@since v3.0
|
||||
*/
|
||||
Renderer* getRenderer() const;
|
||||
Renderer* getRenderer() const { return _renderer; }
|
||||
|
||||
/** Returns the Console
|
||||
@since v3.0
|
||||
*/
|
||||
Console* getConsole() const { return _console; }
|
||||
|
||||
/* Gets delta time since last tick to main loop */
|
||||
float getDeltaTime() const;
|
||||
|
@ -492,10 +486,11 @@ protected:
|
|||
/* This object will be visited after the scene. Useful to hook a notification node */
|
||||
Node *_notificationNode;
|
||||
|
||||
/* Projection protocol delegate */
|
||||
DirectorDelegate *_projectionDelegate;
|
||||
|
||||
/* Renderer for the Director */
|
||||
Renderer *_renderer;
|
||||
|
||||
/* Console for the director */
|
||||
Console *_console;
|
||||
|
||||
// EGLViewProtocol will recreate stats labels to fit visible rect
|
||||
friend class EGLViewProtocol;
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#include "CCGL.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCEventListenerCustom.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
|
||||
|
@ -241,7 +241,7 @@ void DrawNode::render()
|
|||
|
||||
void DrawNode::draw()
|
||||
{
|
||||
_customCommand.init(0, _vertexZ);
|
||||
_customCommand.init(_globalZOrder);
|
||||
_customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
}
|
||||
|
@ -456,6 +456,86 @@ void DrawNode::drawPolygon(Point *verts, int count, const Color4F &fillColor, fl
|
|||
free(extrude);
|
||||
}
|
||||
|
||||
void DrawNode::drawTriangle(const Point &p1, const Point &p2, const Point &p3, const Color4F &color)
|
||||
{
|
||||
unsigned int vertex_count = 2*3;
|
||||
ensureCapacity(vertex_count);
|
||||
|
||||
Color4B col = Color4B(color);
|
||||
V2F_C4B_T2F a = {Vertex2F(p1.x, p1.y), col, Tex2F(0.0, 0.0) };
|
||||
V2F_C4B_T2F b = {Vertex2F(p2.x, p2.y), col, Tex2F(0.0, 0.0) };
|
||||
V2F_C4B_T2F c = {Vertex2F(p3.x, p3.y), col, Tex2F(0.0, 0.0) };
|
||||
|
||||
V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
|
||||
V2F_C4B_T2F_Triangle triangle = {a, b, c};
|
||||
triangles[0] = triangle;
|
||||
|
||||
_bufferCount += vertex_count;
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
void DrawNode::drawCubicBezier(const Point& from, const Point& control1, const Point& control2, const Point& to, unsigned int segments, const Color4F &color)
|
||||
{
|
||||
unsigned int vertex_count = (segments + 1) * 3;
|
||||
ensureCapacity(vertex_count);
|
||||
|
||||
Tex2F texCoord = Tex2F(0.0, 0.0);
|
||||
Color4B col = Color4B(color);
|
||||
Vertex2F vertex;
|
||||
Vertex2F firstVertex = Vertex2F(from.x, from.y);
|
||||
Vertex2F lastVertex = Vertex2F(to.x, to.y);
|
||||
|
||||
float t = 0;
|
||||
for(unsigned int i = segments + 1; i > 0; i--)
|
||||
{
|
||||
float x = powf(1 - t, 3) * from.x + 3.0f * powf(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * to.x;
|
||||
float y = powf(1 - t, 3) * from.y + 3.0f * powf(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * to.y;
|
||||
vertex = Vertex2F(x, y);
|
||||
|
||||
V2F_C4B_T2F a = {firstVertex, col, texCoord };
|
||||
V2F_C4B_T2F b = {lastVertex, col, texCoord };
|
||||
V2F_C4B_T2F c = {vertex, col, texCoord };
|
||||
V2F_C4B_T2F_Triangle triangle = {a, b, c};
|
||||
((V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount))[0] = triangle;
|
||||
|
||||
lastVertex = vertex;
|
||||
t += 1.0f / segments;
|
||||
_bufferCount += 3;
|
||||
}
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
void DrawNode::drawQuadraticBezier(const Point& from, const Point& control, const Point& to, unsigned int segments, const Color4F &color)
|
||||
{
|
||||
unsigned int vertex_count = (segments + 1) * 3;
|
||||
ensureCapacity(vertex_count);
|
||||
|
||||
Tex2F texCoord = Tex2F(0.0, 0.0);
|
||||
Color4B col = Color4B(color);
|
||||
Vertex2F vertex;
|
||||
Vertex2F firstVertex = Vertex2F(from.x, from.y);
|
||||
Vertex2F lastVertex = Vertex2F(to.x, to.y);
|
||||
|
||||
float t = 0;
|
||||
for(unsigned int i = segments + 1; i > 0; i--)
|
||||
{
|
||||
float x = powf(1 - t, 2) * from.x + 2.0f * (1 - t) * t * control.x + t * t * to.x;
|
||||
float y = powf(1 - t, 2) * from.y + 2.0f * (1 - t) * t * control.y + t * t * to.y;
|
||||
vertex = Vertex2F(x, y);
|
||||
|
||||
V2F_C4B_T2F a = {firstVertex, col, texCoord };
|
||||
V2F_C4B_T2F b = {lastVertex, col, texCoord };
|
||||
V2F_C4B_T2F c = {vertex, col, texCoord };
|
||||
V2F_C4B_T2F_Triangle triangle = {a, b, c};
|
||||
((V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount))[0] = triangle;
|
||||
|
||||
lastVertex = vertex;
|
||||
t += 1.0f / segments;
|
||||
_bufferCount += 3;
|
||||
}
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
void DrawNode::clear()
|
||||
{
|
||||
_bufferCount = 0;
|
||||
|
|
|
@ -63,6 +63,15 @@ public:
|
|||
* @endcode
|
||||
*/
|
||||
void drawPolygon(Point *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
|
||||
|
||||
/** draw a triangle with color */
|
||||
void drawTriangle(const Point &p1, const Point &p2, const Point &p3, const Color4F &color);
|
||||
|
||||
/** draw a cubic bezier curve with color and number of segments */
|
||||
void drawCubicBezier(const Point& from, const Point& control1, const Point& control2, const Point& to, unsigned int segments, const Color4F &color);
|
||||
|
||||
/** draw a quadratic bezier curve with color and number of segments */
|
||||
void drawQuadraticBezier(const Point& from, const Point& control, const Point& to, unsigned int segments, const Color4F &color);
|
||||
|
||||
/** Clear the geometry in the node's buffer. */
|
||||
void 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();
|
||||
|
|
|
@ -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,14 +26,8 @@
|
|||
#include "CCFont.h"
|
||||
#include "ccUTF8.h"
|
||||
|
||||
#include "CCFontFNT.h"
|
||||
#include "CCFontFreeType.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{|}~ ";
|
||||
|
@ -42,7 +36,6 @@ const char * Font::_glyphNEHE = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM
|
|||
Font::Font() :
|
||||
_usedGlyphs(GlyphCollection::ASCII)
|
||||
, _customGlyphs(nullptr)
|
||||
,_distanceFieldEnabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -106,174 +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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -28,29 +28,17 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCLabel.h"
|
||||
|
||||
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 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;
|
||||
|
@ -58,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;
|
||||
|
||||
|
@ -82,7 +70,6 @@ protected:
|
|||
char * _customGlyphs;
|
||||
static const char * _glyphASCII;
|
||||
static const char * _glyphNEHE;
|
||||
bool _distanceFieldEnabled;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "cocos2d.h"
|
||||
|
||||
#include "CCFontAtlas.h"
|
||||
#include "CCFont.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "ccUTF8.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
#define PAGE_WIDTH 1024
|
||||
#define PAGE_HEIGHT 1024
|
||||
|
@ -37,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;
|
||||
|
@ -49,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()
|
||||
|
@ -100,6 +101,7 @@ bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontL
|
|||
}
|
||||
else
|
||||
{
|
||||
outDefinition.validDefinition = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -127,8 +129,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
|
||||
Rect tempRect;
|
||||
|
||||
FontLetterDefinition tempDef;
|
||||
tempDef.offsetX = 0;
|
||||
FontLetterDefinition tempDef;
|
||||
tempDef.anchorX = 0.0f;
|
||||
tempDef.anchorY = 1.0f;
|
||||
|
||||
|
@ -140,7 +141,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
tempDef.width = 0;
|
||||
tempDef.height = 0;
|
||||
tempDef.U = 0;
|
||||
tempDef.V = 0;
|
||||
tempDef.V = 0;
|
||||
tempDef.offsetX = 0;
|
||||
tempDef.offsetY = 0;
|
||||
tempDef.textureID = 0;
|
||||
}
|
||||
|
@ -149,7 +151,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
tempDef.validDefinition = true;
|
||||
tempDef.letteCharUTF16 = utf16String[i];
|
||||
tempDef.width = tempRect.size.width + _letterPadding;
|
||||
tempDef.height = _currentPageLineHeight - 1;
|
||||
tempDef.height = _currentPageLineHeight - 1;
|
||||
tempDef.offsetX = tempRect.origin.x;
|
||||
tempDef.offsetY = tempRect.origin.y;
|
||||
tempDef.commonLineHeight = _currentPageLineHeight;
|
||||
|
||||
|
@ -161,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++)
|
||||
{
|
||||
|
@ -190,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;
|
||||
|
@ -231,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,11 +26,14 @@
|
|||
#define _CCFontAtlas_h_
|
||||
|
||||
#include <unordered_map>
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
//fwd
|
||||
class Font;
|
||||
class Texture2D;
|
||||
|
||||
struct FontLetterDefinition
|
||||
{
|
||||
|
|
|
@ -23,9 +23,13 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCFontAtlasCache.h"
|
||||
#include "CCFontAtlasFactory.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "CCFontAtlasCache.h"
|
||||
|
||||
#include "CCFontFNT.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "CCFontCharMap.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -38,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;
|
||||
}
|
||||
|
||||
|
@ -57,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
|
||||
{
|
||||
|
@ -69,6 +91,92 @@ FontAtlas * FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName)
|
|||
return tempAtlas;
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile)
|
||||
{
|
||||
std::string atlasName = generateFontName(plistFile, 0, GlyphCollection::CUSTOM,false);
|
||||
FontAtlas *tempAtlas = _atlasMap[atlasName];
|
||||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
Font *font = FontCharMap::create(plistFile);
|
||||
|
||||
if(font)
|
||||
{
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tempAtlas->retain();
|
||||
}
|
||||
|
||||
return tempAtlas;
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
char tmp[30];
|
||||
sprintf(tmp,"name:%u_%d_%d_%d",texture->getName(),itemWidth,itemHeight,startCharMap);
|
||||
std::string atlasName = generateFontName(tmp, 0, GlyphCollection::CUSTOM,false);
|
||||
FontAtlas *tempAtlas = _atlasMap[atlasName];
|
||||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
Font *font = FontCharMap::create(texture,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if(font)
|
||||
{
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tempAtlas->retain();
|
||||
}
|
||||
|
||||
return tempAtlas;
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
std::string atlasName = generateFontName(charMapFile, 0, GlyphCollection::CUSTOM,false);
|
||||
FontAtlas *tempAtlas = _atlasMap[atlasName];
|
||||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
Font *font = FontCharMap::create(charMapFile,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if(font)
|
||||
{
|
||||
tempAtlas = font->createFontAtlas();
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tempAtlas->retain();
|
||||
}
|
||||
|
||||
return tempAtlas;
|
||||
}
|
||||
|
||||
std::string FontAtlasCache::generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField)
|
||||
{
|
||||
std::string tempName(fontFileName);
|
||||
|
|
|
@ -29,23 +29,24 @@
|
|||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCFontAtlas.h"
|
||||
#include "CCLabel.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL FontAtlasCache
|
||||
{
|
||||
|
||||
{
|
||||
public:
|
||||
|
||||
static FontAtlas * getFontAtlasTTF(const std::string& fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static FontAtlas * getFontAtlasFNT(const std::string& fontFileName);
|
||||
|
||||
static FontAtlas * getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||
static FontAtlas * getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||
static FontAtlas * getFontAtlasCharMap(const std::string& plistFile);
|
||||
|
||||
static bool releaseFontAtlas(FontAtlas *atlas);
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
static std::string generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField);
|
||||
static std::unordered_map<std::string, FontAtlas *> _atlasMap;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
/****************************************************************************
|
||||
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 "CCFontCharMap.h"
|
||||
#include "CCFontAtlas.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "ccUTF8.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
FontCharMap * FontCharMap::create(const std::string& plistFile)
|
||||
{
|
||||
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(plistFile);
|
||||
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
|
||||
|
||||
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr.c_str());
|
||||
|
||||
CCASSERT(dict["version"].asInt() == 1, "Unsupported version. Upgrade cocos2d version");
|
||||
|
||||
std::string textureFilename = relPathStr + dict["textureFilename"].asString();
|
||||
|
||||
unsigned int width = dict["itemWidth"].asInt() / CC_CONTENT_SCALE_FACTOR();
|
||||
unsigned int height = dict["itemHeight"].asInt() / CC_CONTENT_SCALE_FACTOR();
|
||||
unsigned int startChar = dict["firstChar"].asInt();
|
||||
|
||||
Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(textureFilename);
|
||||
if (!tempTexture)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FontCharMap *tempFont = new FontCharMap(tempTexture,width,height,startChar);
|
||||
|
||||
if (!tempFont)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
tempFont->autorelease();
|
||||
return tempFont;
|
||||
}
|
||||
|
||||
FontCharMap* FontCharMap::create(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(charMapFile);
|
||||
|
||||
if (!tempTexture)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FontCharMap *tempFont = new FontCharMap(tempTexture,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if (!tempFont)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
tempFont->autorelease();
|
||||
return tempFont;
|
||||
}
|
||||
|
||||
FontCharMap* FontCharMap::create(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
FontCharMap *tempFont = new FontCharMap(texture,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if (!tempFont)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
tempFont->autorelease();
|
||||
return tempFont;
|
||||
}
|
||||
|
||||
FontCharMap::~FontCharMap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Size * FontCharMap::getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const
|
||||
{
|
||||
if (!text)
|
||||
return 0;
|
||||
|
||||
outNumLetters = cc_wcslen(text);
|
||||
|
||||
if (!outNumLetters)
|
||||
return 0;
|
||||
|
||||
Size *sizes = new Size[outNumLetters];
|
||||
if (!sizes)
|
||||
return 0;
|
||||
|
||||
int advance = _itemWidth * CC_CONTENT_SCALE_FACTOR();
|
||||
for (int c = 0; c < outNumLetters; ++c)
|
||||
{
|
||||
sizes[c].width = advance;
|
||||
}
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
Rect FontCharMap::getRectForChar(unsigned short theChar) const
|
||||
{
|
||||
return _charRect;
|
||||
}
|
||||
|
||||
FontAtlas * FontCharMap::createFontAtlas()
|
||||
{
|
||||
FontAtlas *tempAtlas = new FontAtlas(*this);
|
||||
if (!tempAtlas)
|
||||
return nullptr;
|
||||
|
||||
Size s = _texture->getContentSize();
|
||||
|
||||
int itemsPerColumn = (int)(s.height / _itemHeight);
|
||||
int itemsPerRow = (int)(s.width / _itemWidth);
|
||||
|
||||
tempAtlas->setCommonLineHeight(_itemHeight);
|
||||
|
||||
FontLetterDefinition tempDefinition;
|
||||
tempDefinition.textureID = 0;
|
||||
tempDefinition.anchorX = 0.5f;
|
||||
tempDefinition.anchorY = 0.5f;
|
||||
tempDefinition.offsetX = 0.0f;
|
||||
tempDefinition.offsetY = 0.0f;
|
||||
tempDefinition.validDefinition = true;
|
||||
tempDefinition.width = _itemWidth;
|
||||
tempDefinition.height = _itemHeight;
|
||||
|
||||
int charId = _mapStartChar;
|
||||
float itemWidthInPixels = _itemWidth * CC_CONTENT_SCALE_FACTOR();
|
||||
float itemHeightInPixels = _itemHeight * CC_CONTENT_SCALE_FACTOR();
|
||||
for (int row = 0; row < itemsPerColumn; ++row)
|
||||
{
|
||||
for (int col = 0; col < itemsPerRow; ++col)
|
||||
{
|
||||
tempDefinition.letteCharUTF16 = charId;
|
||||
|
||||
tempDefinition.U = _itemWidth * col;
|
||||
tempDefinition.V = _itemHeight * row;
|
||||
|
||||
tempAtlas->addLetterDefinition(tempDefinition);
|
||||
charId++;
|
||||
}
|
||||
}
|
||||
|
||||
tempAtlas->addTexture(*_texture,0);
|
||||
|
||||
return tempAtlas;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -23,48 +23,47 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _FontDefinition_h_
|
||||
#define _FontDefinition_h_
|
||||
#ifndef _CCFontCharMap_h_
|
||||
#define _CCFontCharMap_h_
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CCTextImage.h"
|
||||
#include "CCFont.h"
|
||||
#include "CCFontAtlas.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
*/
|
||||
class CC_DLL FontDefinitionTTF : public Object
|
||||
{
|
||||
class FontCharMap : public Font
|
||||
{
|
||||
public:
|
||||
static FontCharMap * create(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||
static FontCharMap * create(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||
static FontCharMap * create(const std::string& plistFile);
|
||||
|
||||
static FontDefinitionTTF* create(Font *font, int textureSize = 0);
|
||||
FontAtlas * createFontAtlas();
|
||||
virtual Size* getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const override;
|
||||
virtual Rect getRectForChar(unsigned short theChar) const override;
|
||||
virtual FontAtlas *createFontAtlas() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
FontDefinitionTTF();
|
||||
protected:
|
||||
FontCharMap(Texture2D* texture,int itemWidth, int itemHeight, int startCharMap)
|
||||
:_texture(texture)
|
||||
,_mapStartChar(startCharMap)
|
||||
,_itemWidth(itemWidth)
|
||||
,_itemHeight(itemHeight)
|
||||
,_charRect(0,0,itemWidth,itemHeight)
|
||||
{}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~FontDefinitionTTF();
|
||||
virtual ~FontCharMap();
|
||||
|
||||
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;
|
||||
private:
|
||||
Texture2D* _texture;
|
||||
int _mapStartChar;
|
||||
int _itemWidth;
|
||||
int _itemHeight;
|
||||
|
||||
static const int DEFAUL_ATLAS_TEXTURE_SIZE;
|
||||
Rect _charRect;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
#endif /* defined(_CCFontCharMap_h_) */
|
|
@ -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 "cocos2d.h"
|
||||
#include "CCFontDefinition.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.offsetX = 0;
|
||||
tempDefinition.anchorX = 0.0f;
|
||||
tempDefinition.anchorY = 1.0f;
|
||||
retAtlas->addLetterDefinition(tempDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
// done here
|
||||
return retAtlas;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -25,6 +25,10 @@
|
|||
|
||||
#include "CCFontFNT.h"
|
||||
#include "CCFontAtlas.h"
|
||||
#include "CCLabelBMFont.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "ccUTF8.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -26,11 +26,12 @@
|
|||
#ifndef _CCFontFNT_h_
|
||||
#define _CCFontFNT_h_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCFont.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCBMFontConfiguration;
|
||||
|
||||
class FontFNT : public Font
|
||||
{
|
||||
|
||||
|
|
|
@ -28,23 +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;
|
||||
|
@ -88,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)
|
||||
|
@ -140,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
|
||||
|
@ -175,7 +159,7 @@ bool FontFreeType::getBBOXFotChar(unsigned short theChar, Rect &outRect) const
|
|||
return false;
|
||||
|
||||
// store result in the passed rectangle
|
||||
outRect.origin.x = 0;
|
||||
outRect.origin.x = _fontRef->glyph->metrics.horiBearingX >> 6;
|
||||
outRect.origin.y = - (_fontRef->glyph->metrics.horiBearingY >> 6);
|
||||
outRect.size.width = (_fontRef->glyph->metrics.width >> 6);
|
||||
outRect.size.height = (_fontRef->glyph->metrics.height >> 6);
|
||||
|
@ -183,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)
|
||||
|
@ -267,7 +186,7 @@ Size * FontFreeType::getAdvancesForTextUTF16(unsigned short *text, int &outNumLe
|
|||
int advance = 0;
|
||||
int kerning = 0;
|
||||
|
||||
advance = getAdvanceForChar(text[c]) - getBearingXForChar(text[c]);
|
||||
advance = getAdvanceForChar(text[c]);
|
||||
|
||||
if (c < (outNumLetters-1))
|
||||
kerning = getHorizontalKerningForChars(text[c], text[c+1]);
|
||||
|
@ -294,7 +213,7 @@ int FontFreeType::getAdvanceForChar(unsigned short theChar) const
|
|||
return 0;
|
||||
|
||||
// get to the advance for this glyph
|
||||
return (static_cast<int>(_fontRef->glyph->advance.x >> 6));
|
||||
return (static_cast<int>(_fontRef->glyph->metrics.horiAdvance >> 6));
|
||||
}
|
||||
|
||||
int FontFreeType::getBearingXForChar(unsigned short theChar) const
|
||||
|
@ -379,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,70 +24,88 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCLabel.h"
|
||||
#include "CCFontDefinition.h"
|
||||
#include "CCFontAtlasCache.h"
|
||||
#include "CCLabelTextFormatter.h"
|
||||
#include "CCSprite.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "ccUTF8.h"
|
||||
#include "CCSpriteFrame.h"
|
||||
#include "CCDirector.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "CCFont.h"
|
||||
|
||||
#define DISTANCEFIELD_ATLAS_FONTSIZE 50
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Label* Label::createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
Label* Label::create()
|
||||
{
|
||||
FontAtlas *tmpAtlas = nullptr;
|
||||
if(useDistanceField)
|
||||
tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), DISTANCEFIELD_ATLAS_FONTSIZE, glyphs, customGlyphs,true);
|
||||
else
|
||||
tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), fontSize, glyphs, customGlyphs,false);
|
||||
Label *ret = new Label();
|
||||
|
||||
if (!tmpAtlas)
|
||||
return nullptr;
|
||||
|
||||
// create the actual label
|
||||
Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize, useDistanceField,true);
|
||||
|
||||
if (templabel)
|
||||
{
|
||||
if(useDistanceField)
|
||||
templabel->setFontSize(fontSize);
|
||||
templabel->setText(label, lineSize, alignment, false);
|
||||
return templabel;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Label* Label::createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment, int lineSize)
|
||||
{
|
||||
|
||||
FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath.c_str());
|
||||
|
||||
if (!tmpAtlas)
|
||||
return 0;
|
||||
|
||||
Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize);
|
||||
|
||||
if (templabel)
|
||||
{
|
||||
templabel->setText(label, lineSize, alignment, false);
|
||||
return templabel;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int lineSize, bool useDistanceField,bool useA8Shader)
|
||||
{
|
||||
Label *ret = new Label(atlas, alignment, useDistanceField,useA8Shader);
|
||||
|
||||
if (!ret)
|
||||
return 0;
|
||||
|
||||
if( ret->init() )
|
||||
return nullptr;
|
||||
|
||||
ret->autorelease();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Label* Label::createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment /* = TextHAlignment::CENTER */, int lineSize /* = 0 */)
|
||||
{
|
||||
Label *ret = new Label();
|
||||
|
||||
if (!ret)
|
||||
return nullptr;
|
||||
|
||||
if (ret->setTTFConfig(ttfConfig))
|
||||
{
|
||||
if(ttfConfig.distanceFieldEnabled)
|
||||
ret->setFontSize(ttfConfig.fontSize);
|
||||
ret->setString(text,alignment,lineSize);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Label* Label::createWithTTF(const std::string& text, const std::string& fontFilePath, int fontSize, int lineSize /* = 0 */, TextHAlignment alignment /* = TextHAlignment::CENTER */, GlyphCollection glyphs /* = GlyphCollection::NEHE */, const char *customGlyphs /* = 0 */, bool useDistanceField /* = false */)
|
||||
{
|
||||
TTFConfig ttfConfig(fontFilePath.c_str(),fontSize,glyphs,customGlyphs,useDistanceField);
|
||||
return createWithTTF(ttfConfig,text,alignment,lineSize);
|
||||
}
|
||||
|
||||
Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment /* = TextHAlignment::CENTER */, int lineSize /* = 0 */)
|
||||
{
|
||||
Label *ret = new Label();
|
||||
|
||||
if (!ret)
|
||||
return nullptr;
|
||||
|
||||
if (ret->setBMFontFilePath(bmfontFilePath))
|
||||
{
|
||||
ret->setString(text,alignment,lineSize);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Label* Label::createWithCharMap(const std::string& plistFile)
|
||||
{
|
||||
Label *ret = new Label();
|
||||
|
||||
if (!ret)
|
||||
return nullptr;
|
||||
|
||||
if (ret->setCharMap(plistFile))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
|
@ -95,21 +113,86 @@ Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int li
|
|||
else
|
||||
{
|
||||
delete ret;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Label* Label::createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
Label *ret = new Label();
|
||||
|
||||
if (!ret)
|
||||
return nullptr;
|
||||
|
||||
if (ret->setCharMap(texture,itemWidth,itemHeight,startCharMap))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Label* Label::createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
Label *ret = new Label();
|
||||
|
||||
if (!ret)
|
||||
return nullptr;
|
||||
|
||||
if (ret->setCharMap(charMapFile,itemWidth,itemHeight,startCharMap))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Label::setCharMap(const std::string& plistFile)
|
||||
{
|
||||
FontAtlas *newAtlas = FontAtlasCache::getFontAtlasCharMap(plistFile);
|
||||
|
||||
if (!newAtlas)
|
||||
return false;
|
||||
|
||||
return initWithFontAtlas(newAtlas);
|
||||
}
|
||||
|
||||
bool Label::setCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
FontAtlas *newAtlas = FontAtlasCache::getFontAtlasCharMap(texture,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if (!newAtlas)
|
||||
return false;
|
||||
|
||||
return initWithFontAtlas(newAtlas);
|
||||
}
|
||||
|
||||
bool Label::setCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
FontAtlas *newAtlas = FontAtlasCache::getFontAtlasCharMap(charMapFile,itemWidth,itemHeight,startCharMap);
|
||||
|
||||
if (!newAtlas)
|
||||
return false;
|
||||
|
||||
return initWithFontAtlas(newAtlas);
|
||||
}
|
||||
|
||||
Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,bool useA8Shader)
|
||||
: _reusedLetter(nullptr)
|
||||
, _multilineEnable(true)
|
||||
, _commonLineHeight(0.0f)
|
||||
, _lineBreakWithoutSpaces(false)
|
||||
, _width(0.0f)
|
||||
, _alignment(alignment)
|
||||
, _currentUTF16String(0)
|
||||
, _originalUTF16String(0)
|
||||
, _currentUTF16String(nullptr)
|
||||
, _originalUTF16String(nullptr)
|
||||
, _advances(nullptr)
|
||||
, _fontAtlas(atlas)
|
||||
, _isOpacityModifyRGB(true)
|
||||
|
@ -118,6 +201,7 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,b
|
|||
, _fontSize(0)
|
||||
, _uniformEffectColor(0)
|
||||
{
|
||||
_cascadeColorEnabled = true;
|
||||
}
|
||||
|
||||
Label::~Label()
|
||||
|
@ -137,10 +221,13 @@ bool Label::init()
|
|||
bool ret = true;
|
||||
if(_fontAtlas)
|
||||
{
|
||||
_reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0));
|
||||
_reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB);
|
||||
ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30);
|
||||
_reusedLetter->retain();
|
||||
if (_reusedLetter == nullptr)
|
||||
{
|
||||
_reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0));
|
||||
_reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB);
|
||||
_reusedLetter->retain();
|
||||
}
|
||||
ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30);
|
||||
}
|
||||
if (_useDistanceField)
|
||||
setLabelEffect(LabelEffect::NORMAL,Color3B::BLACK);
|
||||
|
@ -148,46 +235,94 @@ bool Label::init()
|
|||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR));
|
||||
else
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Label::setString(const std::string &stringToRender)
|
||||
bool Label::initWithFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false */, bool useA8Shader /* = false */)
|
||||
{
|
||||
_multilineEnable = true;
|
||||
setText(stringToRender, _width, TextHAlignment::CENTER, false);
|
||||
FontAtlas *oldAtlas = _fontAtlas;
|
||||
bool oldDistanceFieldEnable = _useDistanceField;
|
||||
bool oldA8ShaderEnabel = _useA8Shader;
|
||||
|
||||
_fontAtlas = atlas;
|
||||
_useDistanceField = distanceFieldEnabled;
|
||||
_useA8Shader = useA8Shader;
|
||||
|
||||
bool ret = Label::init();
|
||||
if (oldAtlas)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
FontAtlasCache::releaseFontAtlas(oldAtlas);
|
||||
}
|
||||
else
|
||||
{
|
||||
_fontAtlas = oldAtlas;
|
||||
_useDistanceField = oldDistanceFieldEnable;
|
||||
_useA8Shader = oldA8ShaderEnabel;
|
||||
Label::init();
|
||||
|
||||
FontAtlasCache::releaseFontAtlas(atlas);
|
||||
}
|
||||
}
|
||||
|
||||
if (_fontAtlas)
|
||||
{
|
||||
_commonLineHeight = _fontAtlas->getCommonLineHeight();
|
||||
if (_currentUTF16String)
|
||||
{
|
||||
alignText();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Label::setString(const std::string &stringToRender,bool multilineEnable)
|
||||
bool Label::setTTFConfig(const TTFConfig& ttfConfig)
|
||||
{
|
||||
_multilineEnable = multilineEnable;
|
||||
setText(stringToRender, _width, TextHAlignment::CENTER, false);
|
||||
FontAtlas *newAtlas = nullptr;
|
||||
if(ttfConfig.distanceFieldEnabled)
|
||||
newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, DISTANCEFIELD_ATLAS_FONTSIZE, ttfConfig.glyphs, ttfConfig.customGlyphs,true);
|
||||
else
|
||||
newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, ttfConfig.fontSize, ttfConfig.glyphs, ttfConfig.customGlyphs,false);
|
||||
|
||||
if (!newAtlas)
|
||||
return false;
|
||||
|
||||
return initWithFontAtlas(newAtlas,ttfConfig.distanceFieldEnabled,true);
|
||||
}
|
||||
|
||||
bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces)
|
||||
bool Label::setBMFontFilePath(const std::string& bmfontFilePath)
|
||||
{
|
||||
if (!_fontAtlas)
|
||||
FontAtlas *newAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath);
|
||||
|
||||
if (!newAtlas)
|
||||
return false;
|
||||
|
||||
return initWithFontAtlas(newAtlas);
|
||||
}
|
||||
|
||||
bool Label::setString(const std::string& text, const TextHAlignment& alignment /* = TextHAlignment::CENTER */, float lineWidth /* = -1 */, bool lineBreakWithoutSpaces /* = false */)
|
||||
{
|
||||
if (!_fontAtlas || _commonLineHeight <= 0)
|
||||
return false;
|
||||
|
||||
// carloX
|
||||
// reset the string
|
||||
resetCurrentString();
|
||||
|
||||
_width = lineWidth;
|
||||
if(lineWidth >= 0)
|
||||
{
|
||||
_width = lineWidth;
|
||||
}
|
||||
_alignment = alignment;
|
||||
_lineBreakWithoutSpaces = lineBreakWithoutSpaces;
|
||||
|
||||
// store locally common line height
|
||||
_commonLineHeight = _fontAtlas->getCommonLineHeight();
|
||||
if (_commonLineHeight <= 0)
|
||||
return false;
|
||||
|
||||
// int numLetter = 0;
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(stringToRender.c_str());
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(text.c_str());
|
||||
if(!utf16String)
|
||||
return false;
|
||||
|
||||
_cascadeColorEnabled = true;
|
||||
|
||||
setCurrentString(utf16String);
|
||||
setOriginalString(utf16String);
|
||||
|
||||
|
@ -299,7 +434,7 @@ void Label::alignText()
|
|||
_textureAtlas->removeAllQuads();
|
||||
_fontAtlas->prepareLetterDefinitions(_currentUTF16String);
|
||||
LabelTextFormatter::createStringSprites(this);
|
||||
if(_multilineEnable && LabelTextFormatter::multilineText(this) )
|
||||
if(_width > 0 && LabelTextFormatter::multilineText(this) )
|
||||
LabelTextFormatter::createStringSprites(this);
|
||||
|
||||
LabelTextFormatter::alignText(this);
|
||||
|
@ -531,7 +666,7 @@ void Label::onDraw()
|
|||
|
||||
void Label::draw()
|
||||
{
|
||||
_customCommand.init(0, _vertexZ);
|
||||
_customCommand.init(_globalZOrder);
|
||||
_customCommand.func = CC_CALLBACK_0(Label::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
}
|
||||
|
|
|
@ -54,23 +54,51 @@ enum class LabelEffect {
|
|||
struct FontLetterDefinition;
|
||||
class FontAtlas;
|
||||
|
||||
typedef struct _ttfConfig
|
||||
{
|
||||
std::string fontFilePath;
|
||||
int fontSize;
|
||||
GlyphCollection glyphs;
|
||||
const char *customGlyphs;
|
||||
bool distanceFieldEnabled;
|
||||
|
||||
_ttfConfig(const char* filePath,int size = 36, const GlyphCollection& glyphCollection = GlyphCollection::NEHE,
|
||||
const char *customGlyphCollection = nullptr,bool useDistanceField = false)
|
||||
:fontFilePath(filePath)
|
||||
,fontSize(size)
|
||||
,glyphs(glyphCollection)
|
||||
,customGlyphs(customGlyphCollection)
|
||||
,distanceFieldEnabled(useDistanceField)
|
||||
{}
|
||||
}TTFConfig;
|
||||
|
||||
class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public LabelTextFormatProtocol
|
||||
class CC_DLL Label : public SpriteBatchNode, public LabelTextFormatProtocol
|
||||
{
|
||||
public:
|
||||
|
||||
// static create
|
||||
static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
|
||||
static Label* createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0);
|
||||
|
||||
bool setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false);
|
||||
static Label* create();
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static Label* createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment = TextHAlignment::CENTER, int lineWidth = 0);
|
||||
|
||||
static Label* createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment = TextHAlignment::CENTER, int lineWidth = 0);
|
||||
|
||||
static Label * createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||
static Label * createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||
static Label * createWithCharMap(const std::string& plistFile);
|
||||
|
||||
bool setTTFConfig(const TTFConfig& ttfConfig);
|
||||
|
||||
bool setBMFontFilePath(const std::string& bmfontFilePath);
|
||||
|
||||
bool setCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||
bool setCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||
bool setCharMap(const std::string& plistFile);
|
||||
|
||||
bool setString(const std::string& text, const TextHAlignment& alignment = TextHAlignment::CENTER, float lineWidth = -1, bool lineBreakWithoutSpaces = false);
|
||||
|
||||
//only support for TTF
|
||||
void setLabelEffect(LabelEffect effect,const Color3B& effectColor);
|
||||
|
||||
virtual void setString(const std::string &stringToRender) override;
|
||||
void setString(const std::string &stringToRender,bool multilineEnable);
|
||||
virtual void setAlignment(TextHAlignment alignment);
|
||||
virtual void setWidth(float width);
|
||||
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
||||
|
@ -116,7 +144,7 @@ public:
|
|||
virtual void setLabelContentSize(const Size &newSize) override;
|
||||
|
||||
// carloX
|
||||
virtual const std::string& getString() const override { static std::string _ret("not implemented"); return _ret; }
|
||||
virtual const std::string& getString() const { static std::string _ret("not implemented"); return _ret; }
|
||||
void addChild(Node * child, int zOrder=0, int tag=0) override;
|
||||
|
||||
virtual std::string getDescription() const override;
|
||||
|
@ -127,14 +155,14 @@ private:
|
|||
/**
|
||||
* @js NA
|
||||
*/
|
||||
Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField = false,bool useA8Shader = false);
|
||||
Label(FontAtlas *atlas = nullptr, TextHAlignment alignment = TextHAlignment::CENTER, bool useDistanceField = false,bool useA8Shader = false);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~Label();
|
||||
|
||||
static Label* createWithAtlas(FontAtlas *atlas, TextHAlignment alignment = TextHAlignment::LEFT, int lineSize = 0, bool useDistanceField = false,bool useA8Shader = false);
|
||||
bool initWithFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled = false, bool useA8Shader = false);
|
||||
|
||||
void setFontSize(int fontSize);
|
||||
|
||||
|
@ -151,32 +179,30 @@ private:
|
|||
|
||||
virtual void updateColor() override;
|
||||
|
||||
|
||||
//! used for optimization
|
||||
Sprite *_reusedLetter;
|
||||
std::vector<LetterInfo> _lettersInfo;
|
||||
|
||||
bool _multilineEnable;
|
||||
float _commonLineHeight;
|
||||
bool _lineBreakWithoutSpaces;
|
||||
float _width;
|
||||
TextHAlignment _alignment;
|
||||
unsigned short int * _currentUTF16String;
|
||||
unsigned short int * _originalUTF16String;
|
||||
Size * _advances;
|
||||
FontAtlas * _fontAtlas;
|
||||
bool _isOpacityModifyRGB;
|
||||
Sprite *_reusedLetter;
|
||||
std::vector<LetterInfo> _lettersInfo;
|
||||
|
||||
bool _useDistanceField;
|
||||
bool _useA8Shader;
|
||||
int _fontSize;
|
||||
float _commonLineHeight;
|
||||
bool _lineBreakWithoutSpaces;
|
||||
float _width;
|
||||
TextHAlignment _alignment;
|
||||
unsigned short int * _currentUTF16String;
|
||||
unsigned short int * _originalUTF16String;
|
||||
Size * _advances;
|
||||
FontAtlas * _fontAtlas;
|
||||
bool _isOpacityModifyRGB;
|
||||
|
||||
LabelEffect _currLabelEffect;
|
||||
Color3B _effectColor;
|
||||
bool _useDistanceField;
|
||||
bool _useA8Shader;
|
||||
int _fontSize;
|
||||
|
||||
GLuint _uniformEffectColor;
|
||||
LabelEffect _currLabelEffect;
|
||||
Color3B _effectColor;
|
||||
|
||||
CustomCommand _customCommand;
|
||||
GLuint _uniformEffectColor;
|
||||
|
||||
CustomCommand _customCommand;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -60,13 +60,13 @@ LabelAtlas* LabelAtlas::create()
|
|||
|
||||
LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||
{
|
||||
LabelAtlas *pRet = new LabelAtlas();
|
||||
if(pRet && pRet->initWithString(string, charMapFile, itemWidth, itemHeight, startCharMap))
|
||||
LabelAtlas* ret = new LabelAtlas();
|
||||
if(ret && ret->initWithString(string, charMapFile, itemWidth, itemHeight, startCharMap))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,21 +52,6 @@ A more flexible class is LabelBMFont. It supports variable width characters and
|
|||
class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
LabelAtlas()
|
||||
:_string("")
|
||||
{}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual ~LabelAtlas()
|
||||
{
|
||||
_string.clear();
|
||||
}
|
||||
|
||||
/** creates an empty LabelAtlas, user need to call initWithString(...) later to make this object work properly **/
|
||||
static LabelAtlas* create();
|
||||
|
||||
|
@ -101,6 +86,15 @@ public:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
LabelAtlas()
|
||||
:_string("")
|
||||
{}
|
||||
|
||||
virtual ~LabelAtlas()
|
||||
{
|
||||
_string.clear();
|
||||
}
|
||||
|
||||
// string to render
|
||||
std::string _string;
|
||||
// the first char in the charmap
|
||||
|
|
|
@ -275,8 +275,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseBinaryConfigFile(unsigned ch
|
|||
|
||||
unsigned long remains = size;
|
||||
|
||||
unsigned char version = pData[3];
|
||||
CCASSERT(version == 3, "Only version 3 is supported");
|
||||
CCASSERT(pData[3] == 3, "Only version 3 is supported");
|
||||
|
||||
pData += 4; remains -= 4;
|
||||
|
||||
|
@ -343,8 +342,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseBinaryConfigFile(unsigned ch
|
|||
*/
|
||||
|
||||
const char *value = (const char *)pData;
|
||||
size_t len = strlen(value);
|
||||
CCASSERT(len < blockSize, "Block size should be less then string");
|
||||
CCASSERT(strlen(value) < blockSize, "Block size should be less then string");
|
||||
|
||||
_atlasName = FileUtils::getInstance()->fullPathFromRelativeFile(value, controlFile);
|
||||
}
|
||||
|
|
|
@ -25,11 +25,16 @@
|
|||
|
||||
#ifndef _CCLabelTextFormatProtocol_h_
|
||||
#define _CCLabelTextFormatProtocol_h_
|
||||
#include "CCFontAtlas.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "CCFontAtlas.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "ccTypes.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Sprite;
|
||||
|
||||
struct LetterInfo
|
||||
{
|
||||
|
@ -46,13 +51,13 @@ public:
|
|||
|
||||
virtual ~LabelTextFormatProtocol() {}
|
||||
|
||||
virtual bool recordLetterInfo(const cocos2d::Point& point,unsigned short int theChar, int spriteIndex) = 0;
|
||||
virtual bool recordLetterInfo(const Point& point,unsigned short int theChar, int spriteIndex) = 0;
|
||||
virtual bool recordPlaceholderInfo(int spriteIndex) = 0;
|
||||
virtual std::vector<LetterInfo> *getLettersInfo() = 0;
|
||||
virtual float getLetterPosXLeft(int index) const = 0;
|
||||
virtual float getLetterPosXRight(int index) const = 0;
|
||||
// sprite related stuff
|
||||
virtual cocos2d::Sprite *getLetter(int ID) = 0;
|
||||
virtual Sprite *getLetter(int ID) = 0;
|
||||
|
||||
// font related stuff
|
||||
virtual int getCommonLineHeight() const = 0;
|
||||
|
@ -60,7 +65,7 @@ public:
|
|||
virtual int getXOffsetForChar(unsigned short c) const = 0;
|
||||
virtual int getYOffsetForChar(unsigned short c) const = 0;
|
||||
virtual int getAdvanceForChar(unsigned short c, int hintPositionInString) const = 0;
|
||||
virtual cocos2d::Rect getRectForChar(unsigned short c) const = 0;
|
||||
virtual Rect getRectForChar(unsigned short c) const = 0;
|
||||
|
||||
// string related stuff
|
||||
virtual int getStringNumLines() const = 0;
|
||||
|
@ -68,7 +73,7 @@ public:
|
|||
virtual unsigned short getCharAtStringPosition(int position) const = 0;
|
||||
virtual unsigned short * getUTF8String() const = 0;
|
||||
virtual void assignNewUTF8String(unsigned short *newString) = 0;
|
||||
virtual TextHAlignment getTextAlignment() const = 0;
|
||||
virtual TextHAlignment getTextAlignment() const = 0;
|
||||
|
||||
// label related stuff
|
||||
virtual float getMaxLineWidth() const = 0;
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "ccUTF8.h"
|
||||
#include "CCLabelTextFormatter.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -63,20 +63,24 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
|
|||
{
|
||||
LetterInfo* info = &leterInfo->at(j+skip);
|
||||
|
||||
unsigned int justSkipped = 0;
|
||||
unsigned int justSkipped = 0;
|
||||
|
||||
while (info->def.validDefinition == false)
|
||||
{
|
||||
justSkipped++;
|
||||
info = &leterInfo->at( j+skip+justSkipped );
|
||||
tIndex = j+skip+justSkipped;
|
||||
if(tIndex < strLen)
|
||||
info = &leterInfo->at( tIndex );
|
||||
else
|
||||
break;
|
||||
}
|
||||
skip += justSkipped;
|
||||
tIndex = j + skip;
|
||||
|
||||
if (i >= stringLength)
|
||||
if (tIndex >= stringLength)
|
||||
break;
|
||||
|
||||
unsigned short character = strWhole[i];
|
||||
unsigned short character = strWhole[tIndex];
|
||||
|
||||
if (!isStartOfWord)
|
||||
{
|
||||
|
@ -241,8 +245,6 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
|||
continue;
|
||||
}
|
||||
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
||||
if(currentChar == 0)
|
||||
index -= 1;
|
||||
if (index < 0) continue;
|
||||
|
||||
LetterInfo* info = &leterInfo->at( index );
|
||||
|
@ -351,7 +353,7 @@ bool LabelTextFormatter::createStringSprites(LabelTextFormatProtocol *theLabel)
|
|||
|
||||
|
||||
Point fontPos = Point((float)nextFontPositionX + charXOffset + charRect.size.width * 0.5f + kerningAmount,
|
||||
(float)nextFontPositionY + yOffset - charRect.size.height * 0.5f);
|
||||
(float)nextFontPositionY + yOffset - charRect.size.height * 0.5f);
|
||||
|
||||
if( theLabel->recordLetterInfo(CC_POINT_PIXELS_TO_POINTS(fontPos),c,i) == false)
|
||||
{
|
||||
|
|
|
@ -44,8 +44,8 @@ THE SOFTWARE.
|
|||
#include "CCEventListenerAcceleration.h"
|
||||
#include "platform/CCDevice.h"
|
||||
#include "CCScene.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -565,20 +565,15 @@ void LayerColor::updateColor()
|
|||
|
||||
void LayerColor::draw()
|
||||
{
|
||||
_customCommand.init(0, _vertexZ);
|
||||
_customCommand.init(_globalZOrder);
|
||||
_customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
|
||||
kmMat4 p, mvp;
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &p);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mvp);
|
||||
kmMat4Multiply(&mvp, &p, &mvp);
|
||||
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
kmVec3 pos;
|
||||
pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _vertexZ;
|
||||
kmVec3TransformCoord(&pos, &pos, &mvp);
|
||||
kmVec3TransformCoord(&pos, &pos, &_modelViewTransform);
|
||||
_noMVPVertices[i] = Vertex3F(pos.x,pos.y,pos.z);
|
||||
}
|
||||
|
||||
|
|
|
@ -348,9 +348,8 @@ bool MenuItemAtlasFont::initWithString(const std::string& value, const std::stri
|
|||
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||
{
|
||||
CCASSERT( value.size() != 0, "value length must be greater than 0");
|
||||
LabelAtlas *label = new LabelAtlas();
|
||||
LabelAtlas *label = LabelAtlas::create();
|
||||
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
|
||||
label->autorelease();
|
||||
if (MenuItemLabel::initWithLabel(label, callback))
|
||||
{
|
||||
// do something ?
|
||||
|
|
|
@ -31,8 +31,8 @@ THE SOFTWARE.
|
|||
#include "ccMacros.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCVertex.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -359,7 +359,7 @@ void MotionStreak::draw()
|
|||
if(_nuPoints <= 1)
|
||||
return;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV);
|
||||
_customCommand.init(0,_vertexZ);
|
||||
_customCommand.init(_globalZOrder);
|
||||
_customCommand.func = CC_CALLBACK_0(MotionStreak::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
|
||||
|
|
|
@ -72,8 +72,8 @@ bool nodeComparisonLess(const RCPtr<Object>& pp1, const RCPtr<Object>& pp2)
|
|||
Node *n1 = static_cast<Node*>(p1);
|
||||
Node *n2 = static_cast<Node*>(p2);
|
||||
|
||||
return( n1->getZOrder() < n2->getZOrder() ||
|
||||
( n1->getZOrder() == n2->getZOrder() && n1->getOrderOfArrival() < n2->getOrderOfArrival() )
|
||||
return( n1->getLocalZOrder() < n2->getLocalZOrder() ||
|
||||
( n1->getLocalZOrder() == n2->getLocalZOrder() && n1->getOrderOfArrival() < n2->getOrderOfArrival() )
|
||||
);
|
||||
}
|
||||
#else
|
||||
|
@ -82,8 +82,8 @@ bool nodeComparisonLess(Object* p1, Object* p2)
|
|||
Node *n1 = static_cast<Node*>(p1);
|
||||
Node *n2 = static_cast<Node*>(p2);
|
||||
|
||||
return( n1->getZOrder() < n2->getZOrder() ||
|
||||
( n1->getZOrder() == n2->getZOrder() && n1->getOrderOfArrival() < n2->getOrderOfArrival() )
|
||||
return( n1->getLocalZOrder() < n2->getLocalZOrder() ||
|
||||
( n1->getLocalZOrder() == n2->getLocalZOrder() && n1->getOrderOfArrival() < n2->getOrderOfArrival() )
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
@ -103,12 +103,13 @@ Node::Node(void)
|
|||
, _anchorPointInPoints(Point::ZERO)
|
||||
, _anchorPoint(Point::ZERO)
|
||||
, _contentSize(Size::ZERO)
|
||||
, _additionalTransformDirty(false)
|
||||
, _useAdditionalTransform(false)
|
||||
, _transformDirty(true)
|
||||
, _inverseDirty(true)
|
||||
// children (lazy allocs)
|
||||
// lazy alloc
|
||||
, _ZOrder(0)
|
||||
, _localZOrder(0)
|
||||
, _globalZOrder(0)
|
||||
, _parent(nullptr)
|
||||
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
|
||||
, _tag(Node::INVALID_TAG)
|
||||
|
@ -212,32 +213,34 @@ void Node::setSkewY(float newSkewY)
|
|||
_transformDirty = _inverseDirty = true;
|
||||
}
|
||||
|
||||
/// zOrder getter
|
||||
int Node::getZOrder() const
|
||||
{
|
||||
return _ZOrder;
|
||||
}
|
||||
|
||||
/// zOrder setter : private method
|
||||
/// used internally to alter the zOrder variable. DON'T call this method manually
|
||||
void Node::_setZOrder(int z)
|
||||
void Node::_setLocalZOrder(int z)
|
||||
{
|
||||
_ZOrder = z;
|
||||
_localZOrder = z;
|
||||
}
|
||||
|
||||
void Node::setZOrder(int z)
|
||||
void Node::setLocalZOrder(int z)
|
||||
{
|
||||
_localZOrder = z;
|
||||
if (_parent)
|
||||
{
|
||||
_parent->reorderChild(this, z);
|
||||
}
|
||||
// should set "_ZOrder" after reorderChild, because the implementation of reorderChild subclass of Node, such as Sprite,
|
||||
// will return when _ZOrder value is not changed
|
||||
_setZOrder(z);
|
||||
|
||||
|
||||
_eventDispatcher->setDirtyForNode(this);
|
||||
}
|
||||
|
||||
void Node::setGlobalZOrder(float zOrder)
|
||||
{
|
||||
if (_globalZOrder != zOrder)
|
||||
{
|
||||
_globalZOrder = zOrder;
|
||||
_eventDispatcher->setDirtyForNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// vertexZ getter
|
||||
float Node::getVertexZ() const
|
||||
{
|
||||
|
@ -246,9 +249,10 @@ float Node::getVertexZ() const
|
|||
|
||||
|
||||
/// vertexZ setter
|
||||
void Node::setVertexZ(float var)
|
||||
void Node::setVertexZ(float zOrder)
|
||||
{
|
||||
_vertexZ = var;
|
||||
_vertexZ = zOrder;
|
||||
setGlobalZOrder(zOrder);
|
||||
}
|
||||
|
||||
|
||||
|
@ -650,7 +654,7 @@ void Node::addChild(Node *child, int zOrder)
|
|||
void Node::addChild(Node *child)
|
||||
{
|
||||
CCASSERT( child != nullptr, "Argument must be non-nil");
|
||||
this->addChild(child, child->_ZOrder, child->_tag);
|
||||
this->addChild(child, child->_localZOrder, child->_tag);
|
||||
}
|
||||
|
||||
void Node::removeFromParent()
|
||||
|
@ -767,7 +771,7 @@ void Node::insertChild(Node* child, int z)
|
|||
{
|
||||
_reorderChildDirty = true;
|
||||
_children.pushBack(child);
|
||||
child->_setZOrder(z);
|
||||
child->_setLocalZOrder(z);
|
||||
}
|
||||
|
||||
void Node::reorderChild(Node *child, int zOrder)
|
||||
|
@ -775,7 +779,7 @@ void Node::reorderChild(Node *child, int zOrder)
|
|||
CCASSERT( child != nullptr, "Child must be non-nil");
|
||||
_reorderChildDirty = true;
|
||||
child->setOrderOfArrival(s_globalOrderOfArrival++);
|
||||
child->_setZOrder(zOrder);
|
||||
child->_setLocalZOrder(zOrder);
|
||||
}
|
||||
|
||||
void Node::sortAllChildren()
|
||||
|
@ -816,7 +820,7 @@ void Node::visit()
|
|||
{
|
||||
auto node = _children.at(i);
|
||||
|
||||
if ( node && node->_ZOrder < 0 )
|
||||
if ( node && node->_localZOrder < 0 )
|
||||
node->visit();
|
||||
else
|
||||
break;
|
||||
|
@ -1189,10 +1193,9 @@ const kmMat4& Node::getNodeToParentTransform() const
|
|||
// vertex Z
|
||||
_transform.mat[14] = _vertexZ;
|
||||
|
||||
if (_additionalTransformDirty)
|
||||
if (_useAdditionalTransform)
|
||||
{
|
||||
kmMat4Multiply(&_transform, &_transform, &_additionalTransform);
|
||||
_additionalTransformDirty = false;
|
||||
}
|
||||
|
||||
_transformDirty = false;
|
||||
|
@ -1211,14 +1214,14 @@ void Node::setAdditionalTransform(const AffineTransform& additionalTransform)
|
|||
{
|
||||
CGAffineToGL(additionalTransform, _additionalTransform.mat);
|
||||
_transformDirty = true;
|
||||
_additionalTransformDirty = true;
|
||||
_useAdditionalTransform = true;
|
||||
}
|
||||
|
||||
void Node::setAdditionalTransform(const kmMat4& additionalTransform)
|
||||
{
|
||||
_additionalTransform = additionalTransform;
|
||||
_transformDirty = true;
|
||||
_additionalTransformDirty = true;
|
||||
_useAdditionalTransform = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -161,43 +161,72 @@ public:
|
|||
/// @name Setters & Getters for Graphic Peroperties
|
||||
|
||||
/**
|
||||
* Sets the Z order which stands for the drawing order, and reorder this node in its parent's children array.
|
||||
*
|
||||
* The Z order of node is relative to its siblings.
|
||||
* It is not related to the OpenGL's z property. This one only affects the draw order of itself and its siblings.
|
||||
* Lower Z order number are drawn before higher numbers.
|
||||
* Please refer to `setVertexZ(float)` for the difference.
|
||||
*
|
||||
* @param zOrder Z order of this node.
|
||||
LocalZOrder is the 'key' used to sort the node relative to its siblings.
|
||||
|
||||
The Node's parent will sort all its children based ont the LocalZOrder value.
|
||||
If two nodes have the same LocalZOrder, then the node that was added first to the children's array will be in front of the other node in the array.
|
||||
|
||||
Also, the Scene Graph is traversed using the "In-Order" tree traversal algorithm ( http://en.wikipedia.org/wiki/Tree_traversal#In-order )
|
||||
And Nodes that have LocalZOder values < 0 are the "left" subtree
|
||||
While Nodes with LocalZOder >=0 are the "right" subtree.
|
||||
|
||||
@see `setGlobalZOrder`
|
||||
@see `setVertexZ`
|
||||
*/
|
||||
virtual void setZOrder(int zOrder);
|
||||
/*
|
||||
* Sets the z order which stands for the drawing order
|
||||
*
|
||||
* This is an internal method. Don't call it outside the framework.
|
||||
* The difference between setZOrder(int) and _setOrder(int) is:
|
||||
* - _setZOrder(int) is a pure setter for _ZOrder memeber variable
|
||||
* - setZOrder(int) firstly changes _ZOrder, then recorder this node in its parent's chilren array.
|
||||
virtual void setLocalZOrder(int zOrder);
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE virtual void setZOrder(int zOrder) { setLocalZOrder(zOrder); }
|
||||
/* Helper function used by `setLocalZOrder`. Don't use it unless you know what you are doing.
|
||||
*/
|
||||
virtual void _setZOrder(int z);
|
||||
virtual void _setLocalZOrder(int z);
|
||||
/**
|
||||
* Gets the Z order of this node.
|
||||
* Gets the local Z order of this node.
|
||||
*
|
||||
* @see `setZOrder(int)`
|
||||
* @see `setLocalZOrder(int)`
|
||||
*
|
||||
* @return The Z order.
|
||||
* @return The local (relative to its siblings) Z order.
|
||||
*/
|
||||
virtual int getZOrder() const;
|
||||
virtual int getLocalZOrder() const { return _localZOrder; }
|
||||
CC_DEPRECATED_ATTRIBUTE virtual int getZOrder() const { return getLocalZOrder(); }
|
||||
|
||||
/**
|
||||
* Sets the real OpenGL Z vertex.
|
||||
Defines the oder in which the nodes are renderer.
|
||||
Nodes that have a Global Z Order lower, are renderer first.
|
||||
|
||||
In case two or more nodes have the same Global Z Order, the oder is not guaranteed.
|
||||
The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used.
|
||||
|
||||
By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes.
|
||||
|
||||
Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order.
|
||||
|
||||
Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their acenstors.
|
||||
And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode.
|
||||
|
||||
@see `setLocalZOrder()`
|
||||
@see `setVertexZ()`
|
||||
|
||||
@since v3.0
|
||||
*/
|
||||
virtual void setGlobalZOrder(float zOrder);
|
||||
/**
|
||||
* Returns the Node's Global Z Order.
|
||||
*
|
||||
* Differences between openGL Z vertex and cocos2d Z order:
|
||||
* - OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children
|
||||
* - OpenGL Z might require to set 2D projection
|
||||
* - cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: `vertexZ = 0`
|
||||
* @see `setGlobalZOrder(int)`
|
||||
*
|
||||
* @warning Use it at your own risk since it might break the cocos2d parent-children z order
|
||||
* @return The node's global Z order
|
||||
*/
|
||||
virtual float getGlobalZOrder() const { return _globalZOrder; }
|
||||
|
||||
/**
|
||||
* Sets the 'z' value in the OpenGL Depth Buffer.
|
||||
*
|
||||
* The OpenGL depth buffer and depth testing are disabled by default. You need to turn them on
|
||||
* in order to use this property correctly.
|
||||
*
|
||||
* `setVertexZ()` also sets the `setGlobalZValue()` with the vertexZ value.
|
||||
*
|
||||
* @see `setGlobalZValue()`
|
||||
*
|
||||
* @param vertexZ OpenGL Z vertex of this node.
|
||||
*/
|
||||
|
@ -1266,7 +1295,9 @@ public:
|
|||
Point convertTouchToNodeSpaceAR(Touch * touch) const;
|
||||
|
||||
/**
|
||||
* Sets the additional transform.
|
||||
* Sets an additional transform matrix to the node.
|
||||
*
|
||||
* In order to remove it, set the Identity Matrix to the additional transform.
|
||||
*
|
||||
* @note The additional transform will be concatenated at the end of getNodeToParentTransform.
|
||||
* It could be used to simulate `parent-child` relationship between two nodes (e.g. one is in BatchNode, another isn't).
|
||||
|
@ -1289,7 +1320,7 @@ public:
|
|||
spriteA->setPosition(Point(200, 200));
|
||||
|
||||
// Gets the spriteA's transform.
|
||||
AffineTransform t = spriteA->getNodeToParentTransform();
|
||||
auto t = spriteA->getNodeToParentTransform();
|
||||
|
||||
// Sets the additional transform to spriteB, spriteB's postion will based on its pseudo parent i.e. spriteA.
|
||||
spriteB->setAdditionalTransform(t);
|
||||
|
@ -1409,7 +1440,6 @@ protected:
|
|||
float _scaleX; ///< scaling factor on x-axis
|
||||
float _scaleY; ///< scaling factor on y-axis
|
||||
|
||||
float _vertexZ; ///< OpenGL real Z vertex
|
||||
|
||||
Point _position; ///< position of the node
|
||||
|
||||
|
@ -1421,17 +1451,22 @@ protected:
|
|||
|
||||
Size _contentSize; ///< untransformed size of the node
|
||||
|
||||
kmMat4 _modelViewTransform; ///< ModelView transform of the Node.
|
||||
|
||||
// "cache" variables are allowed to be mutable
|
||||
mutable kmMat4 _additionalTransform; ///< transform
|
||||
mutable kmMat4 _transform; ///< transform
|
||||
mutable kmMat4 _inverse; ///< inverse transform
|
||||
kmMat4 _modelViewTransform; ///< ModelView transform of the Node.
|
||||
mutable bool _additionalTransformDirty; ///< The flag to check whether the additional transform is dirty
|
||||
bool _useAdditionalTransform; ///< The flag to check whether the additional transform is dirty
|
||||
mutable bool _transformDirty; ///< transform dirty flag
|
||||
mutable bool _inverseDirty; ///< inverse transform dirty flag
|
||||
|
||||
int _ZOrder; ///< z-order value that affects the draw order
|
||||
|
||||
|
||||
int _localZOrder; ///< Local order (relative to its siblings) used to sort the node
|
||||
float _globalZOrder; ///< Global order used to sort the node
|
||||
float _vertexZ; ///< OpenGL real Z vertex
|
||||
|
||||
|
||||
Vector<Node*> _children; ///< array of children nodes
|
||||
Node *_parent; ///< weak reference to parent node
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
#include "CCNodeGrid.h"
|
||||
#include "CCGrid.h"
|
||||
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -92,7 +92,7 @@ void NodeGrid::visit()
|
|||
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
_groupCommand.init(0,_vertexZ);
|
||||
_groupCommand.init(_globalZOrder);
|
||||
renderer->addCommand(&_groupCommand);
|
||||
renderer->pushGroup(_groupCommand.getRenderQueueID());
|
||||
|
||||
|
@ -104,7 +104,7 @@ void NodeGrid::visit()
|
|||
_nodeGrid->set2DProjection();
|
||||
}
|
||||
|
||||
_gridBeginCommand.init(0,_vertexZ);
|
||||
_gridBeginCommand.init(_globalZOrder);
|
||||
_gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
|
||||
renderer->addCommand(&_gridBeginCommand);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -152,7 +152,7 @@ void NodeGrid::visit()
|
|||
director->setProjection(beforeProjectionType);
|
||||
}
|
||||
|
||||
_gridEndCommand.init(0,_vertexZ);
|
||||
_gridEndCommand.init(_globalZOrder);
|
||||
_gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this);
|
||||
renderer->addCommand(&_gridEndCommand);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
#include "kazmath/GL/matrix.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -197,7 +197,7 @@ int ParticleBatchNode::addChildHelper(ParticleSystem* child, int z, int aTag)
|
|||
_children.insert(pos, child);
|
||||
|
||||
child->setTag(aTag);
|
||||
child->_setZOrder(z);
|
||||
child->_setLocalZOrder(z);
|
||||
|
||||
child->setParent(this);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
|
|||
}
|
||||
}
|
||||
|
||||
child->_setZOrder(zOrder);
|
||||
child->_setLocalZOrder(zOrder);
|
||||
}
|
||||
|
||||
void ParticleBatchNode::getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -382,26 +382,14 @@ void ParticleBatchNode::draw(void)
|
|||
return;
|
||||
}
|
||||
|
||||
// CC_NODE_DRAW_SETUP();
|
||||
//
|
||||
// GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
//
|
||||
// _textureAtlas->drawQuads();
|
||||
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
_quadCommand.init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
_blendFunc,
|
||||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
_batchCommand.init(
|
||||
_globalZOrder,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
_shaderProgram,
|
||||
_blendFunc,
|
||||
_textureAtlas,
|
||||
_modelViewTransform);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_batchCommand);
|
||||
CC_PROFILER_STOP("CCParticleBatchNode - draw");
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#include "CCNode.h"
|
||||
#include "CCProtocols.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "renderer/CCBatchCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -146,7 +146,7 @@ private:
|
|||
/** the blend function used for drawing the quads */
|
||||
BlendFunc _blendFunc;
|
||||
// quad command
|
||||
QuadCommand _quadCommand;
|
||||
BatchCommand _batchCommand;
|
||||
};
|
||||
|
||||
// end of particle_nodes group
|
||||
|
|
|
@ -38,9 +38,9 @@ THE SOFTWARE.
|
|||
#include "TransformUtils.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
@ -439,7 +439,7 @@ void ParticleSystemQuad::draw()
|
|||
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
_quadCommand.init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
|
||||
_quadCommand.init(_globalZOrder, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ THE SOFTWARE.
|
|||
#include "CCDirector.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCDrawingPrimitives.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
@ -555,7 +555,7 @@ void ProgressTimer::draw()
|
|||
if( ! _vertexData || ! _sprite)
|
||||
return;
|
||||
|
||||
_customCommand.init(0, _vertexZ);
|
||||
_customCommand.init(_globalZOrder);
|
||||
_customCommand.func = CC_CALLBACK_0(ProgressTimer::onDraw, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ THE SOFTWARE.
|
|||
#include "CCEventType.h"
|
||||
#include "CCGrid.h"
|
||||
|
||||
#include "CCRenderer.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
@ -322,7 +322,7 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep
|
|||
this->begin();
|
||||
|
||||
//clear screen
|
||||
_beginWithClearCommand.init(0, _vertexZ);
|
||||
_beginWithClearCommand.init(_globalZOrder);
|
||||
_beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand);
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ void RenderTexture::clearDepth(float depthValue)
|
|||
|
||||
this->begin();
|
||||
|
||||
_clearDepthCommand.init(0, _vertexZ);
|
||||
_clearDepthCommand.init(_globalZOrder);
|
||||
_clearDepthCommand.func = CC_CALLBACK_0(RenderTexture::onClearDepth, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(&_clearDepthCommand);
|
||||
|
@ -605,7 +605,7 @@ void RenderTexture::draw()
|
|||
begin();
|
||||
|
||||
//clear screen
|
||||
_clearCommand.init(0, _vertexZ);
|
||||
_clearCommand.init(_globalZOrder);
|
||||
_clearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_clearCommand);
|
||||
|
||||
|
@ -648,13 +648,13 @@ void RenderTexture::begin()
|
|||
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
|
||||
kmGLMultMatrix(&orthoMatrix);
|
||||
|
||||
_groupCommand.init(0, _vertexZ);
|
||||
_groupCommand.init(_globalZOrder);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(&_groupCommand);
|
||||
renderer->pushGroup(_groupCommand.getRenderQueueID());
|
||||
|
||||
_beginCommand.init(0, _vertexZ);
|
||||
_beginCommand.init(_globalZOrder);
|
||||
_beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(&_beginCommand);
|
||||
|
@ -662,7 +662,7 @@ void RenderTexture::begin()
|
|||
|
||||
void RenderTexture::end()
|
||||
{
|
||||
_endCommand.init(0, _vertexZ);
|
||||
_endCommand.init(_globalZOrder);
|
||||
_endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
|
|
|
@ -45,9 +45,9 @@ THE SOFTWARE.
|
|||
#include "CCAffineTransform.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "CCFrustum.h"
|
||||
#include "renderer/CCFrustum.h"
|
||||
|
||||
// external
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
@ -242,9 +242,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)
|
|||
|
||||
// zwoptex default values
|
||||
_offsetPosition = Point::ZERO;
|
||||
|
||||
_hasChildren = false;
|
||||
|
||||
|
||||
// clean the Quad
|
||||
memset(&_quad, 0, sizeof(_quad));
|
||||
|
||||
|
@ -672,7 +670,7 @@ void Sprite::updateTransform(void)
|
|||
void Sprite::draw(void)
|
||||
{
|
||||
//TODO implement z order
|
||||
_quadCommand.init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform);
|
||||
_quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform);
|
||||
|
||||
// if(culling())
|
||||
{
|
||||
|
@ -767,18 +765,12 @@ void Sprite::addChild(Node *child, int zOrder, int tag)
|
|||
}
|
||||
//CCNode already sets isReorderChildDirty_ so this needs to be after batchNode check
|
||||
Node::addChild(child, zOrder, tag);
|
||||
_hasChildren = true;
|
||||
}
|
||||
|
||||
void Sprite::reorderChild(Node *child, int zOrder)
|
||||
{
|
||||
CCASSERT(child != nullptr, "");
|
||||
CCASSERT(_children.contains(child), "");
|
||||
|
||||
if (zOrder == child->getZOrder())
|
||||
{
|
||||
return;
|
||||
}
|
||||
CCASSERT(child != nullptr, "child must be non null");
|
||||
CCASSERT(_children.contains(child), "child does not belong to this");
|
||||
|
||||
if( _batchNode && ! _reorderChildDirty)
|
||||
{
|
||||
|
@ -813,8 +805,6 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup)
|
|||
}
|
||||
|
||||
Node::removeAllChildrenWithCleanup(cleanup);
|
||||
|
||||
_hasChildren = false;
|
||||
}
|
||||
|
||||
void Sprite::sortAllChildren()
|
||||
|
@ -832,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 );
|
||||
|
@ -882,27 +872,24 @@ void Sprite::setDirtyRecursively(bool bValue)
|
|||
{
|
||||
_recursiveDirty = bValue;
|
||||
setDirty(bValue);
|
||||
// recursively set dirty
|
||||
if (_hasChildren)
|
||||
{
|
||||
for(const auto &child: _children) {
|
||||
Sprite* sp = dynamic_cast<Sprite*>(child);
|
||||
if (sp)
|
||||
{
|
||||
sp->setDirtyRecursively(true);
|
||||
}
|
||||
|
||||
for(const auto &child: _children) {
|
||||
Sprite* sp = dynamic_cast<Sprite*>(child);
|
||||
if (sp)
|
||||
{
|
||||
sp->setDirtyRecursively(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XXX HACK: optimization
|
||||
#define SET_DIRTY_RECURSIVELY() { \
|
||||
if (! _recursiveDirty) { \
|
||||
_recursiveDirty = true; \
|
||||
setDirty(true); \
|
||||
if ( _hasChildren) \
|
||||
setDirtyRecursively(true); \
|
||||
} \
|
||||
#define SET_DIRTY_RECURSIVELY() { \
|
||||
if (! _recursiveDirty) { \
|
||||
_recursiveDirty = true; \
|
||||
setDirty(true); \
|
||||
if (!_children.empty()) \
|
||||
setDirtyRecursively(true); \
|
||||
} \
|
||||
}
|
||||
|
||||
void Sprite::setPosition(const Point& pos)
|
||||
|
|
|
@ -538,7 +538,6 @@ protected:
|
|||
|
||||
bool _dirty; /// Whether the sprite needs to be updated
|
||||
bool _recursiveDirty; /// Whether all of the sprite's children needs to be updated
|
||||
bool _hasChildren; /// Whether the sprite contains children
|
||||
bool _shouldBeHidden; /// should not be drawn because one of the ancestors is not visible
|
||||
kmMat4 _transformToBatch;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ THE SOFTWARE.
|
|||
#include "CCProfiling.h"
|
||||
#include "CCLayer.h"
|
||||
#include "CCScene.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
// external
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
@ -99,7 +99,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity)
|
|||
|
||||
_descendants.reserve(capacity);
|
||||
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -356,18 +356,14 @@ void SpriteBatchNode::draw()
|
|||
for(const auto &child: _children)
|
||||
child->updateTransform();
|
||||
|
||||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
_quadCommand.init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
_shaderProgram,
|
||||
_blendFunc,
|
||||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
||||
_batchCommand.init(
|
||||
_globalZOrder,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
_shaderProgram,
|
||||
_blendFunc,
|
||||
_textureAtlas,
|
||||
_modelViewTransform);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_batchCommand);
|
||||
}
|
||||
|
||||
void SpriteBatchNode::increaseAtlasCapacity(void)
|
||||
|
@ -396,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);
|
||||
}
|
||||
|
@ -411,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);
|
||||
}
|
||||
|
@ -492,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;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ THE SOFTWARE.
|
|||
#include "CCProtocols.h"
|
||||
#include "CCTextureAtlas.h"
|
||||
#include "ccMacros.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "renderer/CCBatchCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -189,7 +189,7 @@ protected:
|
|||
|
||||
TextureAtlas *_textureAtlas;
|
||||
BlendFunc _blendFunc;
|
||||
QuadCommand _quadCommand; // quad command
|
||||
BatchCommand _batchCommand; // render command
|
||||
|
||||
// all descendants: children, grand children, etc...
|
||||
// There is not need to retain/release these objects, since they are already retained by _children
|
||||
|
|
|
@ -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 "cocos2d.h"
|
||||
#include "CCTextImage.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "CCFont.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::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,211 +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 _TextImage_h_
|
||||
#define _TextImage_h_
|
||||
|
||||
//#include "CCFont.h"
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Font;
|
||||
|
||||
/** @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) { /*do nothing*/ }
|
||||
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() { return _uTF16Letter; }
|
||||
const Rect & getRect() const { return _gliphRect; }
|
||||
void setPadding(float padding) { _padding = padding; }
|
||||
float getPadding() { return _padding; }
|
||||
void setCommonHeight(float commonHeight) { _commonHeight = commonHeight; }
|
||||
float getCommonHeight() { return _commonHeight; }
|
||||
void setValid(bool isValid) { _validGlyph = isValid; }
|
||||
bool isValid() { return _validGlyph; }
|
||||
|
||||
private:
|
||||
|
||||
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]; }
|
||||
|
||||
private:
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
|
||||
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]; }
|
||||
|
||||
private:
|
||||
|
||||
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; }
|
||||
|
||||
private:
|
||||
|
||||
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::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::map<unsigned short int, GlyphDef> _textGlyphs;
|
||||
TextFontPagesDef * _fontPages;
|
||||
Font * _font;
|
||||
};
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif
|
|
@ -624,11 +624,11 @@ void TextureAtlas::drawNumberOfQuads(ssize_t numberOfQuads, ssize_t start)
|
|||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
// option 1: subdata
|
||||
//glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * n , &_quads[start] );
|
||||
|
||||
// glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * n , &_quads[start] );
|
||||
|
||||
// option 2: data
|
||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW);
|
||||
|
||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW);
|
||||
|
||||
// option 3: orphaning + glMapBuffer
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * (numberOfQuads-start), nullptr, GL_DYNAMIC_DRAW);
|
||||
void *buf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
|
|
|
@ -97,7 +97,7 @@ void TextureCache::addImageAsync(const std::string &path, std::function<void(Tex
|
|||
{
|
||||
Texture2D *texture = nullptr;
|
||||
|
||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path.c_str());
|
||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
|
||||
auto it = _textures.find(fullpath);
|
||||
if( it != _textures.end() )
|
||||
|
@ -290,7 +290,7 @@ Texture2D * TextureCache::addImage(const std::string &path)
|
|||
// MUTEX:
|
||||
// Needed since addImageAsync calls this method from a different thread
|
||||
|
||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path.c_str());
|
||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
if (fullpath.size() == 0)
|
||||
{
|
||||
return nullptr;
|
||||
|
@ -307,7 +307,7 @@ Texture2D * TextureCache::addImage(const std::string &path)
|
|||
image = new Image();
|
||||
CC_BREAK_IF(nullptr == image);
|
||||
|
||||
bool bRet = image->initWithImageFile(fullpath.c_str());
|
||||
bool bRet = image->initWithImageFile(fullpath);
|
||||
CC_BREAK_IF(!bRet);
|
||||
|
||||
texture = new Texture2D();
|
||||
|
@ -417,16 +417,30 @@ void TextureCache::removeTexture(Texture2D* texture)
|
|||
|
||||
void TextureCache::removeTextureForKey(const std::string &textureKeyName)
|
||||
{
|
||||
auto it = _textures.find(textureKeyName);
|
||||
std::string key = textureKeyName;
|
||||
auto it = _textures.find(key);
|
||||
|
||||
if( it == _textures.end() ) {
|
||||
key = FileUtils::getInstance()->fullPathForFilename(textureKeyName);
|
||||
it = _textures.find(key);
|
||||
}
|
||||
|
||||
if( it != _textures.end() ) {
|
||||
(it->second)->release();
|
||||
_textures.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
Texture2D* TextureCache::getTextureForKey(const std::string &key) const
|
||||
Texture2D* TextureCache::getTextureForKey(const std::string &textureKeyName) const
|
||||
{
|
||||
std::string key = textureKeyName;
|
||||
auto it = _textures.find(key);
|
||||
|
||||
if( it == _textures.end() ) {
|
||||
key = FileUtils::getInstance()->fullPathForFilename(textureKeyName);
|
||||
it = _textures.find(key);
|
||||
}
|
||||
|
||||
if( it != _textures.end() )
|
||||
return it->second;
|
||||
return nullptr;
|
||||
|
@ -448,20 +462,28 @@ void TextureCache::waitForQuit()
|
|||
if (_loadingThread) _loadingThread->join();
|
||||
}
|
||||
|
||||
void TextureCache::dumpCachedTextureInfo() const
|
||||
std::string TextureCache::getCachedTextureInfo() const
|
||||
{
|
||||
char buffer[16386];
|
||||
char buftmp[4096];
|
||||
|
||||
memset(buffer,0,sizeof(buffer));
|
||||
|
||||
unsigned int count = 0;
|
||||
unsigned int totalBytes = 0;
|
||||
|
||||
for( auto it = _textures.begin(); it != _textures.end(); ++it ) {
|
||||
|
||||
memset(buftmp,0,sizeof(buftmp));
|
||||
|
||||
|
||||
Texture2D* tex = it->second;
|
||||
unsigned int bpp = tex->getBitsPerPixelForFormat();
|
||||
// Each texture takes up width * height * bytesPerPixel bytes.
|
||||
auto bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8;
|
||||
totalBytes += bytes;
|
||||
count++;
|
||||
log("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
||||
snprintf(buftmp,sizeof(buftmp)-1,"\"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB\n",
|
||||
it->first.c_str(),
|
||||
(long)tex->retainCount(),
|
||||
(long)tex->getName(),
|
||||
|
@ -469,9 +491,13 @@ void TextureCache::dumpCachedTextureInfo() const
|
|||
(long)tex->getPixelsHigh(),
|
||||
(long)bpp,
|
||||
(long)bytes / 1024);
|
||||
strcat(buffer, buftmp);
|
||||
}
|
||||
|
||||
log("cocos2d: TextureCache dumpDebugInfo: %ld textures, for %lu KB (%.2f MB)", (long)count, (long)totalBytes / 1024, totalBytes / (1024.0f*1024.0f));
|
||||
snprintf(buftmp, sizeof(buftmp)-1, "TextureCache dumpDebugInfo: %ld textures, for %lu KB (%.2f MB)\n", (long)count, (long)totalBytes / 1024, totalBytes / (1024.0f*1024.0f));
|
||||
strcat(buffer, buftmp);
|
||||
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
|
|
|
@ -163,7 +163,7 @@ public:
|
|||
*
|
||||
* @since v1.0
|
||||
*/
|
||||
void dumpCachedTextureInfo() const;
|
||||
std::string getCachedTextureInfo() const;
|
||||
|
||||
//wait for texture cahe to quit befor destroy instance
|
||||
//called by director, please do not called outside
|
||||
|
|
|
@ -98,23 +98,23 @@ void TransitionPageTurn::draw()
|
|||
|
||||
if( _isInSceneOnTop ) {
|
||||
_outSceneProxy->visit();
|
||||
_enableOffsetCmd.init(0, _vertexZ);
|
||||
_enableOffsetCmd.init(_globalZOrder);
|
||||
_enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd);
|
||||
_inSceneProxy->visit();
|
||||
_disableOffsetCmd.init(0, _vertexZ);
|
||||
_disableOffsetCmd.init(_globalZOrder);
|
||||
_disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd);
|
||||
} else {
|
||||
_inSceneProxy->visit();
|
||||
|
||||
_enableOffsetCmd.init(0, _vertexZ);
|
||||
_enableOffsetCmd.init(_globalZOrder);
|
||||
_enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd);
|
||||
|
||||
_outSceneProxy->visit();
|
||||
|
||||
_disableOffsetCmd.init(0, _vertexZ);
|
||||
_disableOffsetCmd.init(_globalZOrder);
|
||||
_disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd);
|
||||
}
|
||||
|
|
|
@ -67,16 +67,14 @@ set(COCOS2D_SRC
|
|||
CCFont.cpp
|
||||
CCFontAtlas.cpp
|
||||
CCFontAtlasCache.cpp
|
||||
CCFontAtlasFactory.cpp
|
||||
CCFontDefinition.cpp
|
||||
CCFontFNT.cpp
|
||||
CCFontFreeType.cpp
|
||||
CCFontCharMap.cpp
|
||||
CCLabel.cpp
|
||||
CCLabelAtlas.cpp
|
||||
CCLabelBMFont.cpp
|
||||
CCLabelTTF.cpp
|
||||
CCLabelTextFormatter.cpp
|
||||
CCTextImage.cpp
|
||||
CCLayer.cpp
|
||||
CCScene.cpp
|
||||
CCTransition.cpp
|
||||
|
@ -144,6 +142,7 @@ set(COCOS2D_SRC
|
|||
renderer/CCGroupCommand.cpp
|
||||
renderer/CCMaterialManager.cpp
|
||||
renderer/CCQuadCommand.cpp
|
||||
renderer/CCBatchCommand.cpp
|
||||
renderer/CCRenderCommand.cpp
|
||||
renderer/CCRenderer.cpp
|
||||
renderer/CCRenderMaterial.cpp
|
||||
|
|
|
@ -73,7 +73,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra)
|
|||
{
|
||||
while (arr->max < arr->num + extra)
|
||||
{
|
||||
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
|
||||
CCLOGINFO("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
|
||||
static_cast<int>(arr->max),
|
||||
static_cast<int>(arr->max*2));
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ namespace
|
|||
static bool s_vertexAttribColor = false;
|
||||
static bool s_vertexAttribTexCoords = false;
|
||||
|
||||
|
||||
#if CC_ENABLE_GL_STATE_CACHE
|
||||
|
||||
#define kMaxActiveTexture 16
|
||||
|
@ -55,6 +54,8 @@ namespace
|
|||
static GLenum s_blendingDest = -1;
|
||||
static int s_GLServerState = 0;
|
||||
static GLuint s_VAO = 0;
|
||||
static GLenum s_activeTexture = -1;
|
||||
|
||||
#endif // CC_ENABLE_GL_STATE_CACHE
|
||||
}
|
||||
|
||||
|
@ -159,7 +160,7 @@ void bindTexture2DN(GLuint textureUnit, GLuint textureId)
|
|||
if (s_currentBoundTexture[textureUnit] != textureId)
|
||||
{
|
||||
s_currentBoundTexture[textureUnit] = textureId;
|
||||
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
||||
activeTexture(GL_TEXTURE0 + textureUnit);
|
||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
||||
}
|
||||
#else
|
||||
|
@ -186,6 +187,18 @@ void deleteTextureN(GLuint textureUnit, GLuint textureId)
|
|||
glDeleteTextures(1, &textureId);
|
||||
}
|
||||
|
||||
void activeTexture(GLenum texture)
|
||||
{
|
||||
#if CC_ENABLE_GL_STATE_CACHE
|
||||
if(s_activeTexture != texture) {
|
||||
s_activeTexture = texture;
|
||||
glActiveTexture(s_activeTexture);
|
||||
}
|
||||
#else
|
||||
glActiveTexture(texture);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bindVAO(GLuint vaoId)
|
||||
{
|
||||
if (Configuration::getInstance()->supportsShareableVAO())
|
||||
|
|
|
@ -129,6 +129,12 @@ void CC_DLL deleteTexture(GLuint textureId);
|
|||
*/
|
||||
void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId);
|
||||
|
||||
/** Select active texture unit.
|
||||
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.
|
||||
@since v3.0
|
||||
*/
|
||||
void CC_DLL activeTexture(GLenum texture);
|
||||
|
||||
/** If the vertex array is not already bound, it binds it.
|
||||
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.
|
||||
@since v2.0.0
|
||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
|||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
#include "platform/CCCommon.h"
|
||||
#include "CCConsole.h"
|
||||
#include "CCStdC.h"
|
||||
|
||||
#ifndef CCASSERT
|
||||
|
|
|
@ -38,7 +38,7 @@ varying vec2 v_texCoord; \n\
|
|||
\n\
|
||||
void main() \n\
|
||||
{ \n\
|
||||
gl_Position = a_position; \n\
|
||||
gl_Position = CC_PMatrix * a_position; \n\
|
||||
v_fragmentColor = a_color; \n\
|
||||
v_texCoord = a_texCoord; \n\
|
||||
} \n\
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "ccUTF8.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "CCConsole.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -278,9 +279,9 @@ cc_utf8_get_char (const char * p)
|
|||
|
||||
unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1 */, int* rUtf16Size/* = nullptr */)
|
||||
{
|
||||
unsigned short len = cc_utf8_strlen(str_old, length);
|
||||
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];
|
||||
|
|
|
@ -25,7 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -247,8 +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="CCFontDefinition.cpp" />
|
||||
<ClCompile Include="CCFontCharMap.cpp" />
|
||||
<ClCompile Include="CCFontFNT.cpp" />
|
||||
<ClCompile Include="CCFontFreeType.cpp" />
|
||||
<ClCompile Include="ccFPSImages.c" />
|
||||
|
@ -287,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" />
|
||||
|
@ -317,6 +315,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="platform\win32\CCFileUtilsWin32.cpp" />
|
||||
<ClCompile Include="platform\win32\CCImage.cpp" />
|
||||
<ClCompile Include="platform\win32\CCStdC.cpp" />
|
||||
<ClCompile Include="renderer\CCBatchCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCCustomCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCFrustum.cpp" />
|
||||
<ClCompile Include="renderer\CCGroupCommand.cpp" />
|
||||
|
@ -427,8 +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="CCFontDefinition.h" />
|
||||
<ClInclude Include="CCFontCharMap.h" />
|
||||
<ClInclude Include="CCFontFNT.h" />
|
||||
<ClInclude Include="CCFontFreeType.h" />
|
||||
<ClInclude Include="ccFPSImages.h" />
|
||||
|
@ -487,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" />
|
||||
|
@ -521,6 +518,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClInclude Include="platform\win32\CCGL.h" />
|
||||
<ClInclude Include="platform\win32\CCPlatformDefine.h" />
|
||||
<ClInclude Include="platform\win32\CCStdC.h" />
|
||||
<ClInclude Include="renderer\CCBatchCommand.h" />
|
||||
<ClInclude Include="renderer\CCCustomCommand.h" />
|
||||
<ClInclude Include="renderer\CCFrustum.h" />
|
||||
<ClInclude Include="renderer\CCGroupCommand.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>
|
||||
|
@ -598,6 +589,12 @@
|
|||
<ClCompile Include="renderer\CCRenderMaterial.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCBatchCommand.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CCFontCharMap.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
||||
|
@ -828,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>
|
||||
|
@ -858,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>
|
||||
|
@ -1207,5 +1195,11 @@
|
|||
<ClInclude Include="renderer\CCRenderMaterial.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCBatchCommand.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CCFontCharMap.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -35,14 +35,6 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
/// The max length of CCLog message.
|
||||
static const int kMaxLogLen = 16*1024;
|
||||
|
||||
/**
|
||||
@brief Output Debug message.
|
||||
*/
|
||||
void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2);
|
||||
|
||||
/**
|
||||
* lua can not deal with ...
|
||||
*/
|
||||
|
|
|
@ -547,6 +547,8 @@ static Data getData(const std::string& filename, bool forString)
|
|||
std::string FileUtils::getStringFromFile(const std::string& filename)
|
||||
{
|
||||
Data data = getData(filename, true);
|
||||
if (data.isNull())
|
||||
return "";
|
||||
std::string ret((const char*)data.getBytes());
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -326,7 +326,10 @@ public:
|
|||
* @note This method is used internally.
|
||||
*/
|
||||
virtual ValueVector getValueVectorFromFile(const std::string& filename);
|
||||
|
||||
|
||||
/** Returns the full path cache */
|
||||
const std::unordered_map<std::string, std::string>& getFullPathCache() const { return _fullPathCache; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The default constructor.
|
||||
|
|
|
@ -376,7 +376,7 @@ namespace
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Image::Image()
|
||||
: _data(0)
|
||||
: _data(nullptr)
|
||||
, _dataLen(0)
|
||||
, _width(0)
|
||||
, _height(0)
|
||||
|
@ -391,10 +391,7 @@ Image::Image()
|
|||
|
||||
Image::~Image()
|
||||
{
|
||||
if (_data != nullptr)
|
||||
{
|
||||
free(_data);
|
||||
}
|
||||
CC_SAFE_FREE(_data);
|
||||
}
|
||||
|
||||
bool Image::initWithImageFile(const std::string& path)
|
||||
|
@ -1539,7 +1536,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
|
|||
|
||||
}while(false);
|
||||
|
||||
if (!ret)
|
||||
if (ret)
|
||||
{
|
||||
const unsigned char tgaSuffix[] = ".tga";
|
||||
for(int i = 0; i < 4; ++i)
|
||||
|
@ -1556,6 +1553,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
|
|||
if (tgaData->imageData != nullptr)
|
||||
{
|
||||
free(tgaData->imageData);
|
||||
_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,28 +33,6 @@ NS_CC_BEGIN
|
|||
|
||||
#define MAX_LEN (cocos2d::kMaxLogLen + 1)
|
||||
|
||||
// XXX deprecated
|
||||
void CCLog(const char * pszFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pszFormat);
|
||||
__android_log_vprint(ANDROID_LOG_DEBUG, "cocos2d-x debug info", pszFormat, args);
|
||||
va_end(args);
|
||||
|
||||
}
|
||||
|
||||
void log(const char * pszFormat, ...)
|
||||
{
|
||||
char buf[MAX_LEN];
|
||||
|
||||
va_list args;
|
||||
va_start(args, pszFormat);
|
||||
vsnprintf(buf, MAX_LEN, pszFormat, args);
|
||||
va_end(args);
|
||||
|
||||
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf);
|
||||
}
|
||||
|
||||
void MessageBox(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
showDialogJNI(pszMsg, pszTitle);
|
||||
|
|
|
@ -89,38 +89,43 @@ public class Cocos2dxHelper {
|
|||
jobs.add(r);
|
||||
}
|
||||
|
||||
private static boolean sInited = false;
|
||||
public static void init(final Activity activity) {
|
||||
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
||||
|
||||
initListener();
|
||||
|
||||
try {
|
||||
// Get the lib_name from AndroidManifest.xml metadata
|
||||
ActivityInfo ai =
|
||||
activity.getPackageManager().getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA);
|
||||
if (null != ai.metaData) {
|
||||
String lib_name = ai.metaData.getString(META_DATA_LIB_NAME);
|
||||
if (null != lib_name) {
|
||||
System.loadLibrary(lib_name);
|
||||
} else {
|
||||
System.loadLibrary(DEFAULT_LIB_NAME);
|
||||
if (!sInited) {
|
||||
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
||||
|
||||
initListener();
|
||||
|
||||
try {
|
||||
// Get the lib_name from AndroidManifest.xml metadata
|
||||
ActivityInfo ai =
|
||||
activity.getPackageManager().getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA);
|
||||
if (null != ai.metaData) {
|
||||
String lib_name = ai.metaData.getString(META_DATA_LIB_NAME);
|
||||
if (null != lib_name) {
|
||||
System.loadLibrary(lib_name);
|
||||
} else {
|
||||
System.loadLibrary(DEFAULT_LIB_NAME);
|
||||
}
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
throw new RuntimeException("Error getting activity info", e);
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
throw new RuntimeException("Error getting activity info", e);
|
||||
}
|
||||
|
||||
Cocos2dxHelper.sPackageName = applicationInfo.packageName;
|
||||
Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath();
|
||||
//Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);
|
||||
|
||||
Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity);
|
||||
Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity);
|
||||
Cocos2dxHelper.sAssetManager = activity.getAssets();
|
||||
|
||||
//Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
|
||||
Cocos2dxBitmap.setContext(activity);
|
||||
sActivity = activity;
|
||||
|
||||
Cocos2dxHelper.sPackageName = applicationInfo.packageName;
|
||||
Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath();
|
||||
//Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);
|
||||
|
||||
Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity);
|
||||
Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity);
|
||||
Cocos2dxHelper.sAssetManager = activity.getAssets();
|
||||
|
||||
//Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
|
||||
Cocos2dxBitmap.setContext(activity);
|
||||
sActivity = activity;
|
||||
sInited = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void initListener() {
|
||||
|
|
|
@ -29,34 +29,11 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#import <UIKit/UIAlert.h>
|
||||
#include "CCDirector.h"
|
||||
#include "CCConsole.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// XXX deprecated
|
||||
void CCLog(const char * format, ...)
|
||||
{
|
||||
printf("cocos2d: ");
|
||||
char buf[kMaxLogLen+1] = {0};
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, kMaxLogLen, format, ap);
|
||||
va_end(ap);
|
||||
printf("%s", buf);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void log(const char * format, ...)
|
||||
{
|
||||
printf("cocos2d: ");
|
||||
char buf[kMaxLogLen+1] = {0};
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, kMaxLogLen, format, ap);
|
||||
va_end(ap);
|
||||
printf("%s", buf);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// ios no MessageBox, use log instead
|
||||
void MessageBox(const char * msg, const char * title)
|
||||
{
|
||||
|
|
|
@ -24,60 +24,18 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
#include "platform/CCCommon.h"
|
||||
#include "CCStdC.h"
|
||||
#include "CCConsole.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#define MAX_LEN (cocos2d::kMaxLogLen + 1)
|
||||
|
||||
// XXX deprecated
|
||||
void CCLog(const char * pszFormat, ...)
|
||||
void MessageBox(const char * msg, const char * title)
|
||||
{
|
||||
char szBuf[MAX_LEN];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, pszFormat);
|
||||
vsnprintf(szBuf, MAX_LEN, pszFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
// Strip any trailing newlines from log message.
|
||||
size_t len = strlen(szBuf);
|
||||
while (len && szBuf[len-1] == '\n')
|
||||
{
|
||||
szBuf[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
fprintf(stderr, "cocos2d-x debug info [%s]\n", szBuf);
|
||||
log("%s: %s", title, msg);
|
||||
}
|
||||
|
||||
void log(const char * pszFormat, ...)
|
||||
void LuaLog(const char * format)
|
||||
{
|
||||
char szBuf[MAX_LEN];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, pszFormat);
|
||||
vsnprintf(szBuf, MAX_LEN, pszFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
// Strip any trailing newlines from log message.
|
||||
size_t len = strlen(szBuf);
|
||||
while (len && szBuf[len-1] == '\n')
|
||||
{
|
||||
szBuf[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
fprintf(stderr, "cocos2d-x debug info [%s]\n", szBuf);
|
||||
}
|
||||
|
||||
void MessageBox(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
log("%s: %s", pszTitle, pszMsg);
|
||||
}
|
||||
|
||||
void LuaLog(const char * pszFormat)
|
||||
{
|
||||
puts(pszFormat);
|
||||
puts(format);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -274,9 +274,12 @@ void EGLViewEventHandler::OnGLFWMouseScrollCallback(GLFWwindow* window, double x
|
|||
|
||||
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action || GLFW_REPEAT == action);
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->dispatchEvent(&event);
|
||||
if (GLFW_REPEAT != action)
|
||||
{
|
||||
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action);
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->dispatchEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||
|
|
|
@ -459,7 +459,7 @@ bool Image::initWithString(
|
|||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
{
|
||||
CC_BREAK_IF(! pText);
|
||||
|
||||
BitmapDC &dc = sharedBitmapDC();
|
||||
|
|
|
@ -33,36 +33,6 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// XXX deprecated
|
||||
void CCLog(const char * format, ...)
|
||||
{
|
||||
printf("Cocos2d: ");
|
||||
char buf[kMaxLogLen];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, kMaxLogLen, format, ap);
|
||||
va_end(ap);
|
||||
printf("%s", buf);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void log(const char * format, ...)
|
||||
{
|
||||
printf("Cocos2d: ");
|
||||
char buf[kMaxLogLen];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, kMaxLogLen, format, ap);
|
||||
va_end(ap);
|
||||
printf("%s", buf);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
void LuaLog(const char * format)
|
||||
{
|
||||
puts(format);
|
||||
|
|
|
@ -74,6 +74,9 @@ public:
|
|||
|
||||
/** @deprecated Use getInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||
|
||||
inline bool isRetina() { return _isRetina; };
|
||||
|
||||
protected:
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
|
@ -82,8 +85,8 @@ protected:
|
|||
private:
|
||||
bool _captured;
|
||||
bool _supportTouch;
|
||||
bool _isRetina;
|
||||
|
||||
int _frameBufferSize[2];
|
||||
float _frameZoomFactor;
|
||||
static EGLView* s_pEglView;
|
||||
public:
|
||||
|
@ -93,6 +96,7 @@ public:
|
|||
GLFWwindow* getWindow() const { return _mainWindow; }
|
||||
private:
|
||||
GLFWwindow* _mainWindow;
|
||||
friend class EGLViewEventHandler;
|
||||
};
|
||||
|
||||
NS_CC_END // end of namespace cocos2d
|
||||
|
|
|
@ -178,25 +178,26 @@ public:
|
|||
static float s_mouseX;
|
||||
static float s_mouseY;
|
||||
|
||||
static void OnGLFWError(int errorID, const char* errorDesc);
|
||||
static void OnGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify);
|
||||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||
static void OnGLFWMouseScrollCallback(GLFWwindow* window, double x, double y);
|
||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||
static void onGLFWError(int errorID, const char* errorDesc);
|
||||
static void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify);
|
||||
static void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||
static void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y);
|
||||
static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void onGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||
static void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||
static void onGLFWframebuffersize(GLFWwindow* window, int w, int h);
|
||||
};
|
||||
|
||||
bool EGLViewEventHandler::s_captured = false;
|
||||
float EGLViewEventHandler::s_mouseX = 0;
|
||||
float EGLViewEventHandler::s_mouseY = 0;
|
||||
|
||||
void EGLViewEventHandler::OnGLFWError(int errorID, const char* errorDesc)
|
||||
void EGLViewEventHandler::onGLFWError(int errorID, const char* errorDesc)
|
||||
{
|
||||
CCLOGERROR("GLFWError #%d Happen, %s\n", errorID, errorDesc);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
|
||||
void EGLViewEventHandler::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
|
||||
{
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
if(nullptr == eglView) return;
|
||||
|
@ -240,10 +241,16 @@ void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, in
|
|||
}
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
||||
void EGLViewEventHandler::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
if(nullptr == eglView) return;
|
||||
|
||||
if (eglView->isRetina()) {
|
||||
x *= 2;
|
||||
y *= 2;
|
||||
}
|
||||
|
||||
s_mouseX = (float)x;
|
||||
s_mouseY = (float)y;
|
||||
|
||||
|
@ -265,7 +272,7 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
|
|||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
|
||||
void EGLViewEventHandler::onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
if(nullptr == eglView) return;
|
||||
|
@ -277,26 +284,50 @@ void EGLViewEventHandler::OnGLFWMouseScrollCallback(GLFWwindow* window, double x
|
|||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
void EGLViewEventHandler::onGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action || GLFW_REPEAT == action);
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->dispatchEvent(&event);
|
||||
if (GLFW_REPEAT != action)
|
||||
{
|
||||
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action);
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->dispatchEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||
void EGLViewEventHandler::onGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||
{
|
||||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||
void EGLViewEventHandler::onGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||
{
|
||||
if(Director::getInstance())
|
||||
Director::getInstance()->setViewport();
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::onGLFWframebuffersize(GLFWwindow* window, int w, int h)
|
||||
{
|
||||
auto view = EGLView::getInstance();
|
||||
|
||||
float frameSizeW = view->getFrameSize().width;
|
||||
float frameSizeH = view->getFrameSize().height;
|
||||
float factorX = frameSizeW / w * view->getFrameZoomFactor();
|
||||
float factorY = frameSizeH / h * view->getFrameZoomFactor();;
|
||||
|
||||
if (fabs(factorX - 0.5f) < FLT_EPSILON && fabs(factorY - 0.5f) < FLT_EPSILON )
|
||||
{
|
||||
Director::getInstance()->setViewport();
|
||||
view->_isRetina = true;
|
||||
view->setFrameZoomFactor(2.0f * view->getFrameZoomFactor());
|
||||
glfwSetWindowSize(window, static_cast<int>(frameSizeW * 0.5f * view->getFrameZoomFactor()) , static_cast<int>(frameSizeH * 0.5f * view->getFrameZoomFactor()));
|
||||
}
|
||||
else if(fabs(factorX - 2.0f) < FLT_EPSILON && fabs(factorY - 2.0f) < FLT_EPSILON)
|
||||
{
|
||||
view->_isRetina = false;
|
||||
view->setFrameZoomFactor(0.5f * view->getFrameZoomFactor());
|
||||
glfwSetWindowSize(window, static_cast<int>(frameSizeW * view->getFrameZoomFactor()), static_cast<int>(frameSizeH * view->getFrameZoomFactor()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//end EGLViewEventHandler
|
||||
|
||||
|
||||
|
@ -310,12 +341,13 @@ EGLView::EGLView()
|
|||
: _captured(false)
|
||||
, _frameZoomFactor(1.0f)
|
||||
, _supportTouch(false)
|
||||
, _isRetina(false)
|
||||
, _mainWindow(nullptr)
|
||||
{
|
||||
CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n");
|
||||
_viewName = "cocos2dx";
|
||||
s_pEglView = this;
|
||||
glfwSetErrorCallback(EGLViewEventHandler::OnGLFWError);
|
||||
glfwSetErrorCallback(EGLViewEventHandler::onGLFWError);
|
||||
glfwInit();
|
||||
}
|
||||
|
||||
|
@ -338,15 +370,25 @@ bool EGLView::init(const std::string& viewName, float width, float height, float
|
|||
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName.c_str(), nullptr, nullptr);
|
||||
glfwMakeContextCurrent(_mainWindow);
|
||||
|
||||
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||
int w, h;
|
||||
glfwGetWindowSize(_mainWindow, &w, &h);
|
||||
int frameBufferW, frameBufferH;
|
||||
glfwGetFramebufferSize(_mainWindow, &frameBufferW, &frameBufferH);
|
||||
|
||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||
glfwSetScrollCallback(_mainWindow, EGLViewEventHandler::OnGLFWMouseScrollCallback);
|
||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
||||
glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback);
|
||||
if (frameBufferW == 2 * w && frameBufferH == 2 * h)
|
||||
{
|
||||
_isRetina = true;
|
||||
setFrameZoomFactor(frameZoomFactor * 2);
|
||||
glfwSetWindowSize(_mainWindow, width/2 * _frameZoomFactor, height/2 * _frameZoomFactor);
|
||||
}
|
||||
|
||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::onGLFWMouseCallBack);
|
||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::onGLFWMouseMoveCallBack);
|
||||
glfwSetScrollCallback(_mainWindow, EGLViewEventHandler::onGLFWMouseScrollCallback);
|
||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::onGLFWCharCallback);
|
||||
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::onGLFWKeyCallback);
|
||||
glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::onGLFWWindowPosCallback);
|
||||
glfwSetFramebufferSizeCallback(_mainWindow, EGLViewEventHandler::onGLFWframebuffersize);
|
||||
// check OpenGL version at first
|
||||
const GLubyte* glVersion = glGetString(GL_VERSION);
|
||||
|
||||
|
@ -450,22 +492,18 @@ void EGLView::setFrameSize(float width, float height)
|
|||
|
||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
}
|
||||
|
||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
}
|
||||
|
||||
EGLView* EGLView::getInstance()
|
||||
|
|
|
@ -29,43 +29,6 @@ NS_CC_BEGIN
|
|||
|
||||
#define MAX_LEN (cocos2d::kMaxLogLen + 1)
|
||||
|
||||
// XXX deprecated
|
||||
void CCLog(const char * pszFormat, ...)
|
||||
{
|
||||
char szBuf[MAX_LEN];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, pszFormat);
|
||||
vsnprintf_s(szBuf, MAX_LEN, MAX_LEN, pszFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
WCHAR wszBuf[MAX_LEN] = {0};
|
||||
MultiByteToWideChar(CP_UTF8, 0, szBuf, -1, wszBuf, sizeof(wszBuf));
|
||||
OutputDebugStringW(wszBuf);
|
||||
OutputDebugStringA("\n");
|
||||
|
||||
WideCharToMultiByte(CP_ACP, 0, wszBuf, sizeof(wszBuf), szBuf, sizeof(szBuf), NULL, FALSE);
|
||||
printf("%s\n", szBuf);
|
||||
}
|
||||
|
||||
void log(const char * pszFormat, ...)
|
||||
{
|
||||
char szBuf[MAX_LEN];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, pszFormat);
|
||||
vsnprintf_s(szBuf, MAX_LEN, MAX_LEN, pszFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
WCHAR wszBuf[MAX_LEN] = {0};
|
||||
MultiByteToWideChar(CP_UTF8, 0, szBuf, -1, wszBuf, sizeof(wszBuf));
|
||||
OutputDebugStringW(wszBuf);
|
||||
OutputDebugStringA("\n");
|
||||
|
||||
WideCharToMultiByte(CP_ACP, 0, wszBuf, sizeof(wszBuf), szBuf, sizeof(szBuf), NULL, FALSE);
|
||||
printf("%s\n", szBuf);
|
||||
}
|
||||
|
||||
void MessageBox(const char * pszMsg, const char * pszTitle)
|
||||
{
|
||||
MessageBoxA(NULL, pszMsg, pszTitle, MB_OK);
|
||||
|
|
|
@ -374,9 +374,12 @@ void EGLViewEventHandler::OnGLFWMouseScrollCallback(GLFWwindow* window, double x
|
|||
|
||||
void EGLViewEventHandler::OnGLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action || GLFW_REPEAT == action);
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->dispatchEvent(&event);
|
||||
if (GLFW_REPEAT != action)
|
||||
{
|
||||
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action);
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->dispatchEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int character)
|
||||
|
|
|
@ -109,7 +109,22 @@ NS_CC_END
|
|||
|
||||
#else
|
||||
|
||||
#include <winsock.h>
|
||||
#undef _WINSOCKAPI_
|
||||
#include <winsock2.h>
|
||||
|
||||
// Conflicted with math.h isnan
|
||||
#include <cmath>
|
||||
using std::isnan;
|
||||
|
||||
inline int vsnprintf_s(char *buffer, size_t sizeOfBuffer, size_t count,
|
||||
const char *format, va_list argptr) {
|
||||
return vsnprintf(buffer, sizeOfBuffer, format, argptr);
|
||||
}
|
||||
inline errno_t strcpy_s(char *strDestination, size_t numberOfElements,
|
||||
const char *strSource) {
|
||||
strcpy(strDestination, strSource);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // __MINGW32__
|
||||
|
||||
|
@ -133,5 +148,8 @@ NS_CC_END
|
|||
#undef DELETE
|
||||
#endif
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
#endif // __CC_STD_C_H__
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/****************************************************************************
|
||||
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
|
||||
|
@ -23,41 +22,48 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCFontAtlasFactory.h"
|
||||
#include "CCFontFNT.h"
|
||||
|
||||
// carloX this NEEDS to be changed
|
||||
#include "CCLabelBMFont.h"
|
||||
#include "renderer/CCBatchCommand.h"
|
||||
#include "ccGLStateCache.h"
|
||||
#include "CCTextureAtlas.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromTTF(const std::string& fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
BatchCommand::BatchCommand()
|
||||
: _textureID(0)
|
||||
, _blendType(BlendFunc::DISABLE)
|
||||
, _textureAtlas(nullptr)
|
||||
{
|
||||
|
||||
Font *font = Font::createWithTTF(fntFilePath, fontSize, glyphs, customGlyphs);
|
||||
if (font)
|
||||
{
|
||||
font->setDistanceFieldEnabled(useDistanceField);
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
_type = RenderCommand::Type::BATCH_COMMAND;
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromFNT(const std::string& fntFilePath)
|
||||
void BatchCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform)
|
||||
{
|
||||
Font *font = Font::createWithFNT(fntFilePath);
|
||||
|
||||
if(font)
|
||||
{
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
_globalOrder = globalOrder;
|
||||
_textureID = textureID;
|
||||
_blendType = blendType;
|
||||
_shader = shader;
|
||||
|
||||
_textureAtlas = textureAtlas;
|
||||
|
||||
_mv = modelViewTransform;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
BatchCommand::~BatchCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void BatchCommand::execute()
|
||||
{
|
||||
// Set material
|
||||
_shader->use();
|
||||
_shader->setUniformsForBuiltins(_mv);
|
||||
GL::bindTexture2D(_textureID);
|
||||
GL::blendFunc(_blendType.src, _blendType.dst);
|
||||
|
||||
// Draw
|
||||
_textureAtlas->drawQuads();
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,19 +1,18 @@
|
|||
/****************************************************************************
|
||||
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
|
||||
|
@ -23,26 +22,47 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CCFontAtlasFactory_h_
|
||||
#define _CCFontAtlasFactory_h_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCFontAtlas.h"
|
||||
#ifndef _CC_BATCHCOMMAND_H_
|
||||
#define _CC_BATCHCOMMAND_H_
|
||||
|
||||
#include "CCRenderCommand.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "CCRenderCommandPool.h"
|
||||
#include "kazmath/kazmath.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);
|
||||
|
||||
private:
|
||||
};
|
||||
class TextureAtlas;
|
||||
|
||||
#define CC_NO_TEXTURE 0
|
||||
|
||||
class BatchCommand : public RenderCommand
|
||||
{
|
||||
public:
|
||||
|
||||
BatchCommand();
|
||||
~BatchCommand();
|
||||
|
||||
void init(float depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform);
|
||||
|
||||
void execute();
|
||||
|
||||
protected:
|
||||
int32_t _materialID;
|
||||
|
||||
//Maternal
|
||||
GLuint _textureID;
|
||||
|
||||
GLProgram* _shader;
|
||||
// GLuint _shaderID;
|
||||
|
||||
BlendFunc _blendType;
|
||||
|
||||
TextureAtlas *_textureAtlas;
|
||||
|
||||
// ModelView transform
|
||||
kmMat4 _mv;
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(_CCFontAtlasFactory_h_) */
|
||||
#endif //_CC_BATCHCOMMAND_H_
|
|
@ -22,23 +22,19 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCCustomCommand.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CustomCommand::CustomCommand()
|
||||
:RenderCommand()
|
||||
, func(nullptr)
|
||||
, _viewport(0)
|
||||
, _depth(0)
|
||||
: func(nullptr)
|
||||
{
|
||||
_type = RenderCommand::Type::CUSTOM_COMMAND;
|
||||
}
|
||||
|
||||
void CustomCommand::init(int viewport, int32_t depth)
|
||||
void CustomCommand::init(float globalOrder)
|
||||
{
|
||||
_viewport = viewport;
|
||||
_depth = depth;
|
||||
_globalOrder = globalOrder;
|
||||
}
|
||||
|
||||
CustomCommand::~CustomCommand()
|
||||
|
@ -46,17 +42,6 @@ CustomCommand::~CustomCommand()
|
|||
|
||||
}
|
||||
|
||||
int64_t CustomCommand::generateID()
|
||||
{
|
||||
_id = 0;
|
||||
|
||||
_id = (int64_t)_viewport << 61
|
||||
| (int64_t)1 << 60 // translucent
|
||||
| (int64_t)_depth << 36;
|
||||
|
||||
return _id;
|
||||
}
|
||||
|
||||
void CustomCommand::execute()
|
||||
{
|
||||
if(func)
|
||||
|
|
|
@ -39,14 +39,7 @@ public:
|
|||
|
||||
public:
|
||||
|
||||
void init(int viewport, int32_t depth);
|
||||
|
||||
// +----------+----------+-----+-----------------------------------+
|
||||
// | | | | | |
|
||||
// | ViewPort | Transluc | | Depth | |
|
||||
// | 3 bits | 1 bit | | 24 bits | |
|
||||
// +----------+----------+-----+----------------+------------------+
|
||||
virtual int64_t generateID();
|
||||
void init(float depth);
|
||||
|
||||
void execute();
|
||||
|
||||
|
@ -54,8 +47,6 @@ public:
|
|||
std::function<void()> func;
|
||||
|
||||
protected:
|
||||
int _viewport;
|
||||
int32_t _depth;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCFrustum.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "renderer/CCFrustum.h"
|
||||
#include "CCConsole.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -173,7 +173,7 @@ Frustum::~Frustum()
|
|||
{
|
||||
}
|
||||
|
||||
void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, float width, float height, float near, float far)
|
||||
void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, float width, float height, float nearPlane, float farPlane)
|
||||
{
|
||||
kmVec3 cc = view.getPosition();
|
||||
kmVec3 cDir = view.getDirection();
|
||||
|
@ -189,7 +189,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
|
|||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
normal = cDir;
|
||||
kmVec3Scale(&point, &cDir, near);
|
||||
kmVec3Scale(&point, &cDir, nearPlane);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_NEAR], &point, &normal);
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
|
|||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
kmVec3Scale(&normal, &cDir, -1);
|
||||
kmVec3Scale(&point, &cDir, far);
|
||||
kmVec3Scale(&point, &cDir, farPlane);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_FAR], &point, &normal);
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
|
|||
}
|
||||
}
|
||||
|
||||
void Frustum::setupProjectionPerspective(const ViewTransform& view, float left, float right, float top, float bottom, float near, float far)
|
||||
void Frustum::setupProjectionPerspective(const ViewTransform& view, float left, float right, float top, float bottom, float nearPlane, float farPlane)
|
||||
{
|
||||
kmVec3 cc = view.getPosition();
|
||||
kmVec3 cDir = view.getDirection();
|
||||
|
@ -259,10 +259,10 @@ void Frustum::setupProjectionPerspective(const ViewTransform& view, float left,
|
|||
kmVec3 nearCenter;
|
||||
kmVec3 farCenter;
|
||||
|
||||
kmVec3Scale(&nearCenter, &cDir, near);
|
||||
kmVec3Scale(&nearCenter, &cDir, nearPlane);
|
||||
kmVec3Add(&nearCenter, &nearCenter, &cc);
|
||||
|
||||
kmVec3Scale(&farCenter, &cDir, far);
|
||||
kmVec3Scale(&farCenter, &cDir, farPlane);
|
||||
kmVec3Add(&farCenter, &farCenter, &cc);
|
||||
|
||||
//near
|
||||
|
@ -335,11 +335,11 @@ void Frustum::setupProjectionPerspective(const ViewTransform& view, float left,
|
|||
|
||||
}
|
||||
|
||||
void Frustum::setupProjectionPerspectiveFov(const ViewTransform& view, float fov, float ratio, float near, float far)
|
||||
void Frustum::setupProjectionPerspectiveFov(const ViewTransform& view, float fov, float ratio, float nearPlane, float farPlane)
|
||||
{
|
||||
float width = 2 * near * tan(fov * 0.5);
|
||||
float width = 2 * nearPlane * tan(fov * 0.5);
|
||||
float height = width/ratio;
|
||||
setupProjectionPerspective(view, -width/2, width/2, height/2, -height/2, near, far);
|
||||
setupProjectionPerspective(view, -width/2, width/2, height/2, -height/2, nearPlane, farPlane);
|
||||
}
|
||||
|
||||
void Frustum::setupFromMatrix(const kmMat4 &view, const kmMat4 &projection)
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
****************************************************************************/
|
||||
|
||||
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -86,18 +86,14 @@ void GroupCommandManager::releaseGroupID(int groupID)
|
|||
}
|
||||
|
||||
GroupCommand::GroupCommand()
|
||||
:RenderCommand()
|
||||
, _viewport(0)
|
||||
, _depth(0)
|
||||
{
|
||||
_type = RenderCommand::Type::GROUP_COMMAND;
|
||||
_renderQueueID = GroupCommandManager::getInstance()->getGroupID();
|
||||
}
|
||||
|
||||
void GroupCommand::init(int viewport, int32_t depth)
|
||||
void GroupCommand::init(float globalOrder)
|
||||
{
|
||||
_viewport = viewport;
|
||||
_depth = depth;
|
||||
_globalOrder = globalOrder;
|
||||
GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID);
|
||||
_renderQueueID = GroupCommandManager::getInstance()->getGroupID();
|
||||
}
|
||||
|
@ -107,15 +103,4 @@ GroupCommand::~GroupCommand()
|
|||
GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID);
|
||||
}
|
||||
|
||||
int64_t GroupCommand::generateID()
|
||||
{
|
||||
_id = 0;
|
||||
|
||||
_id = (int64_t)_viewport << 61
|
||||
| (int64_t)1 << 60 // translucent
|
||||
| (int64_t)_depth << 36;
|
||||
|
||||
return _id;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -56,23 +56,11 @@ public:
|
|||
GroupCommand();
|
||||
~GroupCommand();
|
||||
|
||||
public:
|
||||
void init(float depth);
|
||||
|
||||
void init(int viewport, int32_t depth);
|
||||
|
||||
// +----------+----------+-----+-----------------------------------+
|
||||
// | | | | | |
|
||||
// | ViewPort | Transluc | | Depth | |
|
||||
// | 3 bits | 1 bit | | 24 bits | |
|
||||
// +----------+----------+-----+----------------+------------------+
|
||||
virtual int64_t generateID() override;
|
||||
|
||||
inline bool isTranslucent() {return true;}
|
||||
inline int getRenderQueueID() {return _renderQueueID;}
|
||||
inline int getRenderQueueID() const {return _renderQueueID;}
|
||||
|
||||
protected:
|
||||
int _viewport;
|
||||
int32_t _depth;
|
||||
int _renderQueueID;
|
||||
};
|
||||
|
||||
|
|
|
@ -29,94 +29,36 @@
|
|||
NS_CC_BEGIN
|
||||
|
||||
QuadCommand::QuadCommand()
|
||||
:RenderCommand()
|
||||
,_viewport(0)
|
||||
,_depth(0)
|
||||
,_textureID(0)
|
||||
:_textureID(0)
|
||||
,_blendType(BlendFunc::DISABLE)
|
||||
,_quadCount(0)
|
||||
,_capacity(0)
|
||||
,_quadsCount(0)
|
||||
{
|
||||
_type = RenderCommand::Type::QUAD_COMMAND;
|
||||
_shader = nullptr;
|
||||
_quad = nullptr;
|
||||
_quads = nullptr;
|
||||
}
|
||||
|
||||
void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv)
|
||||
void QuadCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv)
|
||||
{
|
||||
_viewport = viewport;
|
||||
_depth = depth;
|
||||
_globalOrder = globalOrder;
|
||||
_textureID = textureID;
|
||||
_blendType = blendType;
|
||||
_quadCount = quadCount;
|
||||
_shader = shader;
|
||||
|
||||
if(quadCount > _capacity ) {
|
||||
//TODO find a better way to manage quads, current way will result in memory be wasted
|
||||
// _quad = (V3F_C4B_T2F_Quad*)malloc(sizeof(V3F_C4B_T2F_Quad) * quadCount);
|
||||
_quad = (V3F_C4B_T2F_Quad*) realloc(_quad, sizeof(*quad) * quadCount );
|
||||
_capacity = quadCount;
|
||||
}
|
||||
_quadsCount = quadCount;
|
||||
_quads = quad;
|
||||
|
||||
kmMat4 p, mvp;
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &p);
|
||||
_mv = mv;
|
||||
|
||||
kmMat4Multiply(&mvp, &p, &mv);
|
||||
|
||||
|
||||
_quadCount = quadCount;
|
||||
memcpy(_quad, quad, sizeof(V3F_C4B_T2F_Quad) * quadCount);
|
||||
|
||||
for(int i=0; i<quadCount; ++i) {
|
||||
V3F_C4B_T2F_Quad *q = &_quad[i];
|
||||
|
||||
kmVec3 vec1, out1;
|
||||
vec1.x = q->bl.vertices.x;
|
||||
vec1.y = q->bl.vertices.y;
|
||||
vec1.z = q->bl.vertices.z;
|
||||
kmVec3TransformCoord(&out1, &vec1, &mvp);
|
||||
q->bl.vertices.x = out1.x;
|
||||
q->bl.vertices.y = out1.y;
|
||||
q->bl.vertices.z = out1.z;
|
||||
|
||||
kmVec3 vec2, out2;
|
||||
vec2.x = q->br.vertices.x;
|
||||
vec2.y = q->br.vertices.y;
|
||||
vec2.z = q->br.vertices.z;
|
||||
kmVec3TransformCoord(&out2, &vec2, &mvp);
|
||||
q->br.vertices.x = out2.x;
|
||||
q->br.vertices.y = out2.y;
|
||||
q->br.vertices.z = out2.z;
|
||||
|
||||
kmVec3 vec3, out3;
|
||||
vec3.x = q->tr.vertices.x;
|
||||
vec3.y = q->tr.vertices.y;
|
||||
vec3.z = q->tr.vertices.z;
|
||||
kmVec3TransformCoord(&out3, &vec3, &mvp);
|
||||
q->tr.vertices.x = out3.x;
|
||||
q->tr.vertices.y = out3.y;
|
||||
q->tr.vertices.z = out3.z;
|
||||
|
||||
kmVec3 vec4, out4;
|
||||
vec4.x = q->tl.vertices.x;
|
||||
vec4.y = q->tl.vertices.y;
|
||||
vec4.z = q->tl.vertices.z;
|
||||
kmVec3TransformCoord(&out4, &vec4, &mvp);
|
||||
q->tl.vertices.x = out4.x;
|
||||
q->tl.vertices.y = out4.y;
|
||||
q->tl.vertices.z = out4.z;
|
||||
}
|
||||
generateMaterialID();
|
||||
}
|
||||
|
||||
QuadCommand::~QuadCommand()
|
||||
{
|
||||
free(_quad);
|
||||
}
|
||||
|
||||
int64_t QuadCommand::generateID()
|
||||
void QuadCommand::generateMaterialID()
|
||||
{
|
||||
_id = 0;
|
||||
|
||||
//Generate Material ID
|
||||
//TODO fix shader ID generation
|
||||
CCASSERT(_shader->getProgram() < pow(2,10), "ShaderID is greater than 2^10");
|
||||
|
@ -154,19 +96,12 @@ int64_t QuadCommand::generateID()
|
|||
// | Shader ID (10 bits) | Blend ID (4 bits) | Texture ID (18 bits) |
|
||||
// +---------------------+-------------------+----------------------+
|
||||
|
||||
_materialID = (int32_t)_shader->getProgram() << 22
|
||||
| (int32_t)blendID << 18
|
||||
| (int32_t)_textureID << 0;
|
||||
|
||||
//Generate RenderCommandID
|
||||
_id = (int64_t)_viewport << 61
|
||||
| (int64_t)1 << 60 //translucent
|
||||
| (int64_t)_depth << 36;
|
||||
|
||||
return _id;
|
||||
_materialID = (uint32_t)_shader->getProgram() << 22
|
||||
| (uint32_t)blendID << 18
|
||||
| (uint32_t)_textureID << 0;
|
||||
}
|
||||
|
||||
void QuadCommand::useMaterial()
|
||||
void QuadCommand::useMaterial() const
|
||||
{
|
||||
_shader->use();
|
||||
|
||||
|
|
|
@ -41,41 +41,31 @@ public:
|
|||
QuadCommand();
|
||||
~QuadCommand();
|
||||
|
||||
void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount,
|
||||
void init(float depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quads, ssize_t quadCount,
|
||||
const kmMat4& mv);
|
||||
|
||||
// +----------+----------+-----+-----------------------------------+
|
||||
// | | | | | |
|
||||
// | ViewPort | Transluc | | Depth | Material ID |
|
||||
// | 3 bits | 1 bit | | 24 bits | 24 bit2 |
|
||||
// +----------+----------+-----+----------------+------------------+
|
||||
virtual int64_t generateID();
|
||||
|
||||
void useMaterial();
|
||||
void useMaterial() const;
|
||||
|
||||
//TODO use material to decide if it is translucent
|
||||
inline bool isTranslucent() const { return true; }
|
||||
|
||||
inline int32_t getMaterialID() const { return _materialID; }
|
||||
void generateMaterialID();
|
||||
inline uint32_t getMaterialID() const { return _materialID; }
|
||||
|
||||
inline GLuint getTextureID() const { return _textureID; }
|
||||
|
||||
inline V3F_C4B_T2F_Quad* getQuad() const { return _quad; }
|
||||
inline V3F_C4B_T2F_Quad* getQuads() const { return _quads; }
|
||||
|
||||
inline ssize_t getQuadCount() const { return _quadCount; }
|
||||
inline ssize_t getQuadCount() const { return _quadsCount; }
|
||||
|
||||
inline GLProgram* getShader() const { return _shader; }
|
||||
|
||||
inline BlendFunc getBlendType() const { return _blendType; }
|
||||
|
||||
inline const kmMat4& getModelView() const { return _mv; }
|
||||
|
||||
protected:
|
||||
int32_t _materialID;
|
||||
|
||||
//Key Data
|
||||
int _viewport; /// Which view port it belongs to
|
||||
|
||||
//TODO use material to determine if it's translucent
|
||||
int32_t _depth;
|
||||
uint32_t _materialID;
|
||||
|
||||
//Maternal
|
||||
GLuint _textureID;
|
||||
|
@ -85,9 +75,10 @@ protected:
|
|||
|
||||
BlendFunc _blendType;
|
||||
|
||||
V3F_C4B_T2F_Quad* _quad;
|
||||
ssize_t _quadCount;
|
||||
ssize_t _capacity;
|
||||
V3F_C4B_T2F_Quad* _quads;
|
||||
ssize_t _quadsCount;
|
||||
|
||||
kmMat4 _mv;
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
NS_CC_BEGIN
|
||||
|
||||
RenderCommand::RenderCommand()
|
||||
: _type(RenderCommand::Type::UNKNOWN_COMMAND)
|
||||
, _globalOrder(0)
|
||||
{
|
||||
_id = 0;
|
||||
_type = RenderCommand::Type::UNKNOWN_COMMAND;
|
||||
}
|
||||
|
||||
RenderCommand::~RenderCommand()
|
||||
|
@ -57,9 +57,7 @@ void printBits(ssize_t const size, void const * const ptr)
|
|||
|
||||
void RenderCommand::printID()
|
||||
{
|
||||
printf("CommandID: ");
|
||||
printBits(sizeof(_id), &_id);
|
||||
printf("\n");
|
||||
printf("Command Depth: %f\n", _globalOrder);
|
||||
}
|
||||
|
||||
NS_CC_END
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue