mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into TableView
This commit is contained in:
commit
32d056df18
|
@ -35,7 +35,7 @@
|
|||
#define LOG_EVENTS_DEBUG(...)
|
||||
// #define LOG_EVENTS_DEBUG(...) ((void)__android_log_print(ANDROID_LOG_INFO, "cocos2dx/nativeactivity.cpp", __VA_ARGS__))
|
||||
|
||||
void cocos_android_app_init(void);
|
||||
void cocos_android_app_init(struct android_app* app);
|
||||
|
||||
/**
|
||||
* Our saved state data.
|
||||
|
@ -72,19 +72,19 @@ typedef struct cocos_dimensions {
|
|||
int h;
|
||||
} cocos_dimensions;
|
||||
|
||||
static void cocos_init(cocos_dimensions d, AAssetManager* assetmanager) {
|
||||
static void cocos_init(cocos_dimensions d, struct android_app* app) {
|
||||
LOGI("cocos_init(...)");
|
||||
pthread_t thisthread = pthread_self();
|
||||
LOGI("pthread_self() = %X", thisthread);
|
||||
|
||||
cocos2d::FileUtilsAndroid::setassetmanager(assetmanager);
|
||||
cocos2d::FileUtilsAndroid::setassetmanager(app->activity->assetManager);
|
||||
|
||||
if (!cocos2d::Director::getInstance()->getOpenGLView())
|
||||
{
|
||||
cocos2d::EGLView *view = cocos2d::EGLView::getInstance();
|
||||
view->setFrameSize(d.w, d.h);
|
||||
|
||||
cocos_android_app_init();
|
||||
cocos_android_app_init(app);
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
|||
ccxhelperInit.methodID,
|
||||
app->activity->clazz);
|
||||
|
||||
cocos_init(d, app->activity->assetManager);
|
||||
cocos_init(d, app);
|
||||
}
|
||||
engine->animating = 1;
|
||||
engine_draw_frame(engine);
|
||||
|
|
|
@ -94,8 +94,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, int capacity)
|
|||
_children = new Array();
|
||||
_children->initWithCapacity(capacity);
|
||||
|
||||
_descendants = new Array();
|
||||
_descendants->initWithCapacity(capacity);
|
||||
_descendants.reserve(capacity);
|
||||
|
||||
setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
return true;
|
||||
|
@ -119,14 +118,12 @@ bool SpriteBatchNode::initWithFile(const char* fileImage, int capacity)
|
|||
|
||||
SpriteBatchNode::SpriteBatchNode()
|
||||
: _textureAtlas(NULL)
|
||||
, _descendants(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
SpriteBatchNode::~SpriteBatchNode()
|
||||
{
|
||||
CC_SAFE_RELEASE(_textureAtlas);
|
||||
CC_SAFE_RELEASE(_descendants);
|
||||
}
|
||||
|
||||
// override visit
|
||||
|
@ -184,16 +181,6 @@ void SpriteBatchNode::addChild(Node *child, int zOrder, int tag)
|
|||
appendChild(sprite);
|
||||
}
|
||||
|
||||
void SpriteBatchNode::addChild(Node *child)
|
||||
{
|
||||
Node::addChild(child);
|
||||
}
|
||||
|
||||
void SpriteBatchNode::addChild(Node *child, int zOrder)
|
||||
{
|
||||
Node::addChild(child, zOrder);
|
||||
}
|
||||
|
||||
// override reorderChild
|
||||
void SpriteBatchNode::reorderChild(Node *child, int zOrder)
|
||||
{
|
||||
|
@ -238,11 +225,13 @@ void SpriteBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
|||
{
|
||||
// Invalidate atlas index. issue #569
|
||||
// useSelfRender should be performed on all descendants. issue #1216
|
||||
arrayMakeObjectsPerformSelectorWithObject(_descendants, setBatchNode, NULL, Sprite*);
|
||||
std::for_each(_descendants.begin(), _descendants.end(), [](Sprite* sprite) {
|
||||
sprite->setBatchNode(nullptr);
|
||||
});
|
||||
|
||||
Node::removeAllChildrenWithCleanup(doCleanup);
|
||||
|
||||
_descendants->removeAllObjects();
|
||||
_descendants.clear();
|
||||
_textureAtlas->removeAllQuads();
|
||||
}
|
||||
|
||||
|
@ -361,10 +350,10 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
|||
|
||||
if (needNewIndex)
|
||||
{//all children have a zOrder < 0)
|
||||
oldIndex=sprite->getAtlasIndex();
|
||||
oldIndex = sprite->getAtlasIndex();
|
||||
sprite->setAtlasIndex(*curIndex);
|
||||
sprite->setOrderOfArrival(0);
|
||||
if (oldIndex!=*curIndex) {
|
||||
if (oldIndex != *curIndex) {
|
||||
swap(oldIndex, *curIndex);
|
||||
}
|
||||
(*curIndex)++;
|
||||
|
@ -374,15 +363,20 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
|||
|
||||
void SpriteBatchNode::swap(int oldIndex, int newIndex)
|
||||
{
|
||||
CCASSERT(oldIndex>=0 && oldIndex < _descendants->count() && newIndex >=0 && newIndex < _descendants->count(), "Invalid index");
|
||||
CCASSERT(oldIndex>=0 && oldIndex < _descendants.size() && newIndex >=0 && newIndex < _descendants.size(), "Invalid index");
|
||||
|
||||
V3F_C4B_T2F_Quad* quads = _textureAtlas->getQuads();
|
||||
std::swap( quads[oldIndex], quads[newIndex] );
|
||||
|
||||
//update the index of other swapped item
|
||||
static_cast<Sprite*>( _descendants->getObjectAtIndex(newIndex) )->setAtlasIndex(oldIndex);
|
||||
|
||||
std::swap( quads[oldIndex], quads[newIndex] );
|
||||
_descendants->swap( oldIndex, newIndex );
|
||||
auto oldIt = std::next( _descendants.begin(), oldIndex );
|
||||
auto newIt = std::next( _descendants.begin(), newIndex );
|
||||
|
||||
(*newIt)->setAtlasIndex(oldIndex);
|
||||
// (*oldIt)->setAtlasIndex(newIndex);
|
||||
|
||||
std::swap( *oldIt, *newIt );
|
||||
}
|
||||
|
||||
void SpriteBatchNode::reorderBatch(bool reorder)
|
||||
|
@ -560,43 +554,6 @@ int SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// add child helper
|
||||
|
||||
void SpriteBatchNode::insertChild(Sprite *sprite, int index)
|
||||
{
|
||||
sprite->setBatchNode(this);
|
||||
sprite->setAtlasIndex(index);
|
||||
sprite->setDirty(true);
|
||||
|
||||
if(_textureAtlas->getTotalQuads() == _textureAtlas->getCapacity())
|
||||
{
|
||||
increaseAtlasCapacity();
|
||||
}
|
||||
|
||||
V3F_C4B_T2F_Quad quad = sprite->getQuad();
|
||||
_textureAtlas->insertQuad(&quad, index);
|
||||
|
||||
_descendants->insertObject(sprite, index);
|
||||
|
||||
// update indices
|
||||
int i = index+1;
|
||||
|
||||
Sprite* child = nullptr;
|
||||
for(; i < _descendants->count(); i++){
|
||||
child = static_cast<Sprite*>(_descendants->getObjectAtIndex(i));
|
||||
child->setAtlasIndex(child->getAtlasIndex() + 1);
|
||||
}
|
||||
|
||||
// add children recursively
|
||||
Object* obj = nullptr;
|
||||
CCARRAY_FOREACH(sprite->getChildren(), obj)
|
||||
{
|
||||
child = static_cast<Sprite*>(obj);
|
||||
int idx = atlasIndexForChild(child, child->getZOrder());
|
||||
insertChild(child, idx);
|
||||
}
|
||||
}
|
||||
|
||||
// addChild helper, faster than insertChild
|
||||
void SpriteBatchNode::appendChild(Sprite* sprite)
|
||||
{
|
||||
|
@ -608,8 +565,8 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
|
|||
increaseAtlasCapacity();
|
||||
}
|
||||
|
||||
_descendants->addObject(sprite);
|
||||
int index=_descendants->count()-1;
|
||||
_descendants.push_back(sprite);
|
||||
int index = _descendants.size()-1;
|
||||
|
||||
sprite->setAtlasIndex(index);
|
||||
|
||||
|
@ -634,19 +591,16 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
|||
// Cleanup sprite. It might be reused (issue #569)
|
||||
sprite->setBatchNode(NULL);
|
||||
|
||||
int index = _descendants->getIndexOfObject(sprite);
|
||||
if (index != -1)
|
||||
auto it = std::find(_descendants.begin(), _descendants.end(), sprite );
|
||||
if( it != _descendants.end() )
|
||||
{
|
||||
_descendants->removeObjectAtIndex(index);
|
||||
auto next = std::next(it);
|
||||
|
||||
// update all sprites beyond this one
|
||||
int count = _descendants->count();
|
||||
std::for_each(next, _descendants.end(), [](Sprite *sprite) {
|
||||
sprite->setAtlasIndex( sprite->getAtlasIndex() - 1 );
|
||||
});
|
||||
|
||||
for(; index < count; ++index)
|
||||
{
|
||||
Sprite* s = static_cast<Sprite*>(_descendants->getObjectAtIndex(index));
|
||||
s->setAtlasIndex( s->getAtlasIndex() - 1 );
|
||||
}
|
||||
_descendants.erase(it);
|
||||
}
|
||||
|
||||
// remove children recursively
|
||||
|
@ -754,22 +708,17 @@ SpriteBatchNode * SpriteBatchNode::addSpriteWithoutQuad(Sprite*child, int z, int
|
|||
child->setAtlasIndex(z);
|
||||
|
||||
// XXX: optimize with a binary search
|
||||
int i=0;
|
||||
auto it = std::begin(_descendants);
|
||||
std::for_each(_descendants.begin(), _descendants.end(), [&](Sprite *sprite) {
|
||||
if(sprite->getAtlasIndex() >= z)
|
||||
std::next(it);
|
||||
});
|
||||
|
||||
Object* object = NULL;
|
||||
CCARRAY_FOREACH(_descendants, object)
|
||||
{
|
||||
Sprite* child = static_cast<Sprite*>(object);
|
||||
if (child && (child->getAtlasIndex() >= z))
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
_descendants->insertObject(child, i);
|
||||
_descendants.insert(it, child);
|
||||
|
||||
// IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array
|
||||
Node::addChild(child, z, aTag);
|
||||
|
||||
//#issue 1262 don't use lazy sorting, tiles are added as quads not as sprites, so sprites need to be added in order
|
||||
reorderBatch(false);
|
||||
|
||||
|
|
|
@ -28,11 +28,12 @@ THE SOFTWARE.
|
|||
#ifndef __CC_SPRITE_BATCH_NODE_H__
|
||||
#define __CC_SPRITE_BATCH_NODE_H__
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base_nodes/CCNode.h"
|
||||
#include "CCProtocols.h"
|
||||
#include "textures/CCTextureAtlas.h"
|
||||
#include "ccMacros.h"
|
||||
#include "cocoa/CCArray.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -89,10 +90,10 @@ public:
|
|||
bool initWithFile(const char* fileImage, int capacity);
|
||||
bool init();
|
||||
|
||||
// property
|
||||
|
||||
// retain
|
||||
/** returns the TextureAtlas object */
|
||||
inline TextureAtlas* getTextureAtlas(void) { return _textureAtlas; }
|
||||
|
||||
/** sets the TextureAtlas object */
|
||||
inline void setTextureAtlas(TextureAtlas* textureAtlas)
|
||||
{
|
||||
if (textureAtlas != _textureAtlas)
|
||||
|
@ -103,7 +104,9 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
inline Array* getDescendants(void) { return _descendants; }
|
||||
/** returns an array with the descendants (children, gran children, etc.).
|
||||
This is specific to BatchNode. In order to use the children, use getChildren() instead */
|
||||
inline const std::vector<Sprite*>& getDescendants() const { return _descendants; }
|
||||
|
||||
void increaseAtlasCapacity();
|
||||
|
||||
|
@ -112,7 +115,6 @@ public:
|
|||
*/
|
||||
void removeChildAtIndex(int index, bool doCleanup);
|
||||
|
||||
void insertChild(Sprite *child, int index);
|
||||
void appendChild(Sprite* sprite);
|
||||
void removeSpriteFromAtlas(Sprite *sprite);
|
||||
|
||||
|
@ -133,12 +135,11 @@ public:
|
|||
virtual const BlendFunc& getBlendFunc(void) const override;
|
||||
|
||||
virtual void visit(void) override;
|
||||
virtual void addChild(Node * child) override;
|
||||
virtual void addChild(Node * child, int zOrder) override;
|
||||
using Node::addChild;
|
||||
virtual void addChild(Node * child, int zOrder, int tag) override;
|
||||
virtual void reorderChild(Node * child, int zOrder) override;
|
||||
virtual void reorderChild(Node *child, int zOrder) override;
|
||||
|
||||
virtual void removeChild(Node* child, bool cleanup) override;
|
||||
virtual void removeChild(Node *child, bool cleanup) override;
|
||||
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
|
||||
virtual void sortAllChildren() override;
|
||||
virtual void draw(void) override;
|
||||
|
@ -157,19 +158,19 @@ protected:
|
|||
/* This is the opposite of "addQuadFromSprite.
|
||||
It add the sprite to the children and descendants array, but it doesn't update add it to the texture atlas
|
||||
*/
|
||||
SpriteBatchNode * addSpriteWithoutQuad(Sprite*child, int z, int aTag);
|
||||
SpriteBatchNode * addSpriteWithoutQuad(Sprite *child, int z, int aTag);
|
||||
|
||||
private:
|
||||
void updateAtlasIndex(Sprite* sprite, int* curIndex);
|
||||
void swap(int oldIndex, int newIndex);
|
||||
void updateBlendFunc();
|
||||
|
||||
protected:
|
||||
TextureAtlas *_textureAtlas;
|
||||
BlendFunc _blendFunc;
|
||||
|
||||
// all descendants: children, grand children, etc...
|
||||
Array* _descendants;
|
||||
// There is not need to retain/release these objects, since they are already retained by _children
|
||||
// So, using std::vector<Sprite*> is slightly faster than using cocos2d::Array for this particular case
|
||||
std::vector<Sprite*> _descendants;
|
||||
};
|
||||
|
||||
// end of sprite_nodes group
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
7b8ff30c1fc482c4d7485032c73c1145a60168b4
|
||||
71e41ffe1784a179756e14a9745e8b4c6e389d95
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (void) {
|
||||
void cocos_android_app_init (struct android_app* app) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue