Merge branch 'develop' into develop_nutty_Mergemasterbranchtodevelopbranch

This commit is contained in:
CaiWenzhi 2013-11-11 17:57:43 +08:00
commit 782c26bc37
104 changed files with 879 additions and 662 deletions

View File

@ -643,6 +643,12 @@ Developers:
Fixed a bug that EventListeners can't be removed sometimes.
Fixed a bug that the data size has to be specified when parsing XML using TinyXML.
Luis Parravicini (luisparravicini)
Fixed typos in create_project.py.
xhcnb
Device::setAccelerometerEnabled needs to be invoked before adding ACC listener.
Retired Core Developers:
WenSheng Yang
Author of windows port, CCTextField,

View File

@ -19,6 +19,7 @@ cocos2d-x-3.0alpha1 @??? 2013
[NEW] Point: Adds ANCHOR_XXX constants like ANCHOR_MIDDLE, ANCHOR_TOP_RIGHT, etc.
[NEW] Sprite: Override setScale(float scaleX, float scaleY)
[NEW] External: added | operator for Control::EventType
[NEW] Android & iOS screen size change support
[Android]
[FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes
[FIX] Fixed application will crash when pause and resume.

View File

@ -97,11 +97,15 @@ $ open samples.xcodeproj
* For Linux
```
$ cd cocos2d-x
$ cmake CMakeLists.txt
$ cd cocos2d-x/build
$ ./install-deps-linux.sh
$ cmake ..
$ make
```
You may meet building errors when building libGLFW.so. It is because libGL.so directs to an error target, you should make it to direct to a correct one.
`install-deps-linux.sh` only has to be run onece.
* For Windows
Open the `cocos2d-x/build/cocos2d-win32.vc2012.sln`

View File

@ -95,7 +95,8 @@ def do_build(cocos_root, ndk_root, app_android_root, ndk_build_param):
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
else:
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ndk_build_param, ndk_module_path)
os.system(command)
if os.system(command) != 0:
raise Exception("Build project [ " + app_android_root + " ] fails!")
def copy_files(src, dst):
@ -205,4 +206,8 @@ if __name__ == '__main__':
if len(args) == 0:
usage()
else:
build_samples(args, opts.ndk_build_param)
try:
build_samples(args, opts.ndk_build_param)
except Exception as e:
print e
sys.exit(1)

View File

@ -123,7 +123,7 @@ void ActionManager::removeActionAtIndex(long index, tHashElement *element)
void ActionManager::pauseTarget(Object *target)
{
tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, element);
HASH_FIND_PTR(_targets, &target, element);
if (element)
{
element->paused = true;
@ -133,7 +133,7 @@ void ActionManager::pauseTarget(Object *target)
void ActionManager::resumeTarget(Object *target)
{
tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, element);
HASH_FIND_PTR(_targets, &target, element);
if (element)
{
element->paused = false;
@ -176,14 +176,14 @@ void ActionManager::addAction(Action *action, Node *target, bool paused)
tHashElement *element = NULL;
// we should convert it to Object*, because we save it as Object*
Object *tmp = target;
HASH_FIND_INT(_targets, &tmp, element);
HASH_FIND_PTR(_targets, &tmp, element);
if (! element)
{
element = (tHashElement*)calloc(sizeof(*element), 1);
element->paused = paused;
target->retain();
element->target = target;
HASH_ADD_INT(_targets, target, element);
HASH_ADD_PTR(_targets, target, element);
}
actionAllocWithHashElement(element);
@ -215,7 +215,7 @@ void ActionManager::removeAllActionsFromTarget(Object *target)
}
tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, element);
HASH_FIND_PTR(_targets, &target, element);
if (element)
{
if (ccArrayContainsObject(element->actions, element->currentAction) && (! element->currentActionSalvaged))
@ -250,7 +250,7 @@ void ActionManager::removeAction(Action *action)
tHashElement *element = NULL;
Object *target = action->getOriginalTarget();
HASH_FIND_INT(_targets, &target, element);
HASH_FIND_PTR(_targets, &target, element);
if (element)
{
long i = ccArrayGetIndexOfObject(element->actions, action);
@ -271,7 +271,7 @@ void ActionManager::removeActionByTag(int tag, Object *target)
CCASSERT(target != NULL, "");
tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, element);
HASH_FIND_PTR(_targets, &target, element);
if (element)
{
@ -298,7 +298,7 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const
CCASSERT(tag != Action::INVALID_TAG, "");
tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, element);
HASH_FIND_PTR(_targets, &target, element);
if (element)
{
@ -330,7 +330,7 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const
unsigned int ActionManager::getNumberOfRunningActionsInTarget(const Object *target) const
{
tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, element);
HASH_FIND_PTR(_targets, &target, element);
if (element)
{
return element->actions ? element->actions->num : 0;

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include "CCTexture2D.h"
#include "ccMacros.h"
#include "CCSpriteFrame.h"
#include "CCDirector.h"
NS_CC_BEGIN
@ -176,7 +177,7 @@ void Animation::addSpriteFrame(SpriteFrame *pFrame)
void Animation::addSpriteFrameWithFile(const char *filename)
{
Texture2D *texture = TextureCache::getInstance()->addImage(filename);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename);
Rect rect = Rect::ZERO;
rect.size = texture->getContentSize();
SpriteFrame *pFrame = SpriteFrame::createWithTexture(texture, rect);

View File

@ -76,7 +76,7 @@ AtlasNode * AtlasNode::create(const std::string& tile, long tileWidth, long tile
bool AtlasNode::initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender)
{
CCASSERT(tile.size() > 0, "file size should not be empty");
Texture2D *texture = TextureCache::getInstance()->addImage(tile);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile);
return initWithTexture(texture, tileWidth, tileHeight, itemsToRender);
}

View File

@ -145,6 +145,8 @@ bool Director::init(void)
_scheduler->scheduleUpdateForTarget(_actionManager, Scheduler::PRIORITY_SYSTEM, false);
_eventDispatcher = new EventDispatcher();
//init TextureCache
initTextureCache();
// create autorelease pool
PoolManager::sharedPoolManager()->push();
@ -359,6 +361,29 @@ void Director::setOpenGLView(EGLView *pobOpenGLView)
}
}
TextureCache* Director::getTextureCache() const
{
return _textureCache;
}
void Director::initTextureCache()
{
#ifdef EMSCRIPTEN
_textureCache = new TextureCacheEmscripten();
#else
_textureCache = new TextureCache();
#endif // EMSCRIPTEN
}
void Director::destroyTextureCache()
{
if (_textureCache)
{
_textureCache->waitForQuit();
CC_SAFE_RELEASE_NULL(_textureCache);
}
}
void Director::setViewport()
{
if (_openGLView)
@ -437,7 +462,7 @@ void Director::purgeCachedData(void)
if (s_SharedDirector->getOpenGLView())
{
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
TextureCache::getInstance()->removeUnusedTextures();
_textureCache->removeUnusedTextures();
}
FileUtils::getInstance()->purgeCachedEntries();
}
@ -693,7 +718,6 @@ void Director::purgeDirector()
DrawPrimitives::free();
AnimationCache::destroyInstance();
SpriteFrameCache::destroyInstance();
TextureCache::destroyInstance();
ShaderCache::destroyInstance();
FileUtils::destroyInstance();
Configuration::destroyInstance();
@ -704,6 +728,8 @@ void Director::purgeDirector()
GL::invalidateStateCache();
destroyTextureCache();
CHECK_GL_ERROR_DEBUG();
// OpenGL view
@ -841,14 +867,13 @@ void Director::getFPSImageData(unsigned char** datapointer, long* length)
void Director::createStatsLabel()
{
Texture2D *texture = nullptr;
TextureCache *textureCache = TextureCache::getInstance();
if (_FPSLabel && _SPFLabel)
{
CC_SAFE_RELEASE_NULL(_FPSLabel);
CC_SAFE_RELEASE_NULL(_SPFLabel);
CC_SAFE_RELEASE_NULL(_drawsLabel);
textureCache->removeTextureForKey("/cc_fps_images");
_textureCache->removeTextureForKey("/cc_fps_images");
FileUtils::getInstance()->purgeCachedEntries();
}
@ -865,7 +890,7 @@ void Director::createStatsLabel()
return;
}
texture = textureCache->addImage(image, "/cc_fps_images");
texture = _textureCache->addImage(image, "/cc_fps_images");
CC_SAFE_RELEASE(image);
/*

View File

@ -54,6 +54,7 @@ class Node;
class Scheduler;
class ActionManager;
class EventDispatcher;
class TextureCache;
/**
@brief Class that creates and handles the main Window and manages how
@ -137,6 +138,8 @@ public:
inline EGLView* getOpenGLView() { return _openGLView; }
void setOpenGLView(EGLView *pobOpenGLView);
TextureCache* getTextureCache() const;
inline bool isNextDeltaTimeZero() { return _nextDeltaTimeZero; }
void setNextDeltaTimeZero(bool nextDeltaTimeZero);
@ -381,6 +384,10 @@ protected:
/** calculates delta time since last time it was called */
void calculateDeltaTime();
//textureCache creation or release
void initTextureCache();
void destroyTextureCache();
protected:
/** Scheduler associated with this director
@since v2.0
@ -403,6 +410,9 @@ protected:
/* The EGLView, where everything is rendered */
EGLView *_openGLView;
//texture cache belongs to this director
TextureCache *_textureCache;
double _animationInterval;
double _oldAnimationInterval;

View File

@ -75,10 +75,9 @@ EventListenerTouchOneByOne* EventListenerTouchOneByOne::create()
bool EventListenerTouchOneByOne::checkAvailable()
{
if (onTouchBegan == nullptr && onTouchMoved == nullptr
&& onTouchEnded == nullptr && onTouchCancelled == nullptr)
if (onTouchBegan == nullptr)
{
CCASSERT(false, "Invalid TouchEventListener.");
CCASSERT(false, "Invalid EventListenerTouchOneByOne!");
return false;
}
@ -150,7 +149,7 @@ bool EventListenerTouchAllAtOnce::checkAvailable()
if (onTouchesBegan == nullptr && onTouchesMoved == nullptr
&& onTouchesEnded == nullptr && onTouchesCancelled == nullptr)
{
CCASSERT(false, "Invalid TouchEventListener.");
CCASSERT(false, "Invalid EventListenerTouchAllAtOnce!");
return false;
}

View File

@ -34,7 +34,7 @@ FontFNT * FontFNT::create(const std::string& fntFilePath)
return nullptr;
// add the texture
Texture2D *tempTexture = TextureCache::getInstance()->addImage(newConf->getAtlasName());
Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(newConf->getAtlasName());
if (!tempTexture)
{
delete newConf;
@ -198,7 +198,7 @@ FontAtlas * FontFNT::createFontAtlas()
// add the texture (only one texture for now)
Texture2D *tempTexture = TextureCache::getInstance()->addImage(_configuration->getAtlasName());
Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(_configuration->getAtlasName());
if (!tempTexture)
return 0;

View File

@ -56,7 +56,7 @@ LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& cha
bool LabelAtlas::initWithString(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap)
{
Texture2D *texture = TextureCache::getInstance()->addImage(charMapFile);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(charMapFile);
return initWithString(string, texture, itemWidth, itemHeight, startCharMap);
}

View File

@ -486,7 +486,7 @@ bool LabelBMFont::initWithString(const std::string& theString, const std::string
_fntFile = fntFile;
texture = TextureCache::getInstance()->addImage(_configuration->getAtlasName());
texture = Director::getInstance()->getTextureCache()->addImage(_configuration->getAtlasName());
}
else
{
@ -1073,9 +1073,9 @@ void LabelBMFont::updateLabel()
int size = multiline_string.size();
unsigned short* str_new = new unsigned short[size + 1];
for (int i = 0; i < size; ++i)
for (int j = 0; j < size; ++j)
{
str_new[i] = multiline_string[i];
str_new[j] = multiline_string[j];
}
str_new[size] = '\0';
@ -1213,7 +1213,7 @@ void LabelBMFont::setFntFile(const char* fntFile)
CC_SAFE_RELEASE(_configuration);
_configuration = newConf;
this->setTexture(TextureCache::getInstance()->addImage(_configuration->getAtlasName()));
this->setTexture(Director::getInstance()->getTextureCache()->addImage(_configuration->getAtlasName()));
this->createFontChars();
}
}

View File

@ -200,9 +200,9 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
int size = multiline_string.size();
unsigned short* strNew = new unsigned short[size + 1];
for (int i = 0; i < size; ++i)
for (int j = 0; j < size; ++j)
{
strNew[i] = multiline_string[i];
strNew[j] = multiline_string[j];
}
strNew[size] = 0;

View File

@ -28,7 +28,7 @@ THE SOFTWARE.
#include "CCGLProgram.h"
#include "CCShaderCache.h"
#include "ccMacros.h"
#include "CCDirector.h"
#include "CCVertex.h"
NS_CC_BEGIN
@ -93,7 +93,7 @@ bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Co
{
CCASSERT(path != NULL, "Invalid filename");
Texture2D *texture = TextureCache::getInstance()->addImage(path);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(path);
return initWithFade(fade, minSeg, stroke, color, texture);
}

View File

@ -111,7 +111,7 @@ bool ParticleBatchNode::initWithTexture(Texture2D *tex, unsigned int capacity)
*/
bool ParticleBatchNode::initWithFile(const char* fileImage, unsigned int capacity)
{
Texture2D *tex = TextureCache::getInstance()->addImage(fileImage);
Texture2D *tex = Director::getInstance()->getTextureCache()->addImage(fileImage);
return initWithTexture(tex, capacity);
}

View File

@ -42,7 +42,7 @@ static Texture2D* getDefaultTexture()
{
bool bRet = false;
const char* key = "/__firePngData";
texture = TextureCache::getInstance()->getTextureForKey(key);
texture = Director::getInstance()->getTextureCache()->getTextureForKey(key);
CC_BREAK_IF(texture != NULL);
pImage = new Image();
@ -50,7 +50,7 @@ static Texture2D* getDefaultTexture()
bRet = pImage->initWithImageData(__firePngData, sizeof(__firePngData));
CC_BREAK_IF(!bRet);
texture = TextureCache::getInstance()->addImage(pImage, key);
texture = Director::getInstance()->getTextureCache()->addImage(pImage, key);
} while (0);
CC_SAFE_RELEASE(pImage);

View File

@ -374,7 +374,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
// set not pop-up message box when load image failed
bool bNotify = FileUtils::getInstance()->isPopupNotify();
FileUtils::getInstance()->setPopupNotify(false);
tex = TextureCache::getInstance()->addImage(textureName.c_str());
tex = Director::getInstance()->getTextureCache()->addImage(textureName.c_str());
// reset the value of UIImage notify
FileUtils::getInstance()->setPopupNotify(bNotify);
}
@ -400,13 +400,13 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin
CCASSERT( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");
CC_BREAK_IF(!deflated);
// For android, we should retain it in VolatileTexture::addImage which invoked in TextureCache::getInstance()->addUIImage()
// For android, we should retain it in VolatileTexture::addImage which invoked in Director::getInstance()->getTextureCache()->addUIImage()
image = new Image();
bool isOK = image->initWithImageData(deflated, deflatedLen);
CCASSERT(isOK, "CCParticleSystem: error init image with Data");
CC_BREAK_IF(!isOK);
setTexture(TextureCache::getInstance()->addImage(image, textureName.c_str()));
setTexture(Director::getInstance()->getTextureCache()->addImage(image, textureName.c_str()));
image->release();
}

View File

@ -166,7 +166,7 @@ void ProfilingEndTimingBlock(const char *timerName)
CCASSERT(timer, "CCProfilingTimer not found");
long duration = chrono::duration_cast<chrono::microseconds>(now - timer->_startTime).count();
long duration = static_cast<long>(chrono::duration_cast<chrono::microseconds>(now - timer->_startTime).count());
timer->totalTime += duration;
timer->_averageTime1 = (timer->_averageTime1 + duration) / 2.0f;

View File

@ -102,11 +102,11 @@ void RenderTexture::listenToBackground(cocos2d::Object *obj)
if (_UITextureImage)
{
const Size& s = _texture->getContentSizeInPixels();
VolatileTexture::addDataTexture(_texture, _UITextureImage->getData(), s.width * s.height * 4, Texture2D::PixelFormat::RGBA8888, s);
VolatileTextureMgr::addDataTexture(_texture, _UITextureImage->getData(), s.width * s.height * 4, Texture2D::PixelFormat::RGBA8888, s);
if ( _textureCopy )
{
VolatileTexture::addDataTexture(_textureCopy, _UITextureImage->getData(), s.width * s.height * 4, Texture2D::PixelFormat::RGBA8888, s);
VolatileTextureMgr::addDataTexture(_textureCopy, _UITextureImage->getData(), s.width * s.height * 4, Texture2D::PixelFormat::RGBA8888, s);
}
}
else

View File

@ -133,12 +133,12 @@ void Scene::addChildToPhysicsWorld(Node* child)
if (_physicsWorld)
{
std::function<void(Object*)> addToPhysicsWorldFunc = nullptr;
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Object* child) -> void
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Object* obj) -> void
{
if (dynamic_cast<Node*>(child) != nullptr)
if (dynamic_cast<Node*>(obj) != nullptr)
{
Node* node = dynamic_cast<Node*>(child);
Node* node = dynamic_cast<Node*>(obj);
if (node->getPhysicsBody())
{

View File

@ -294,7 +294,7 @@ void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Object *target, float in
CCASSERT(target, "Argument target must be non-NULL");
tHashTimerEntry *element = NULL;
HASH_FIND_INT(_hashForTimers, &target, element);
HASH_FIND_PTR(_hashForTimers, &target, element);
if (! element)
{
@ -304,7 +304,7 @@ void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Object *target, float in
{
target->retain();
}
HASH_ADD_INT(_hashForTimers, target, element);
HASH_ADD_PTR(_hashForTimers, target, element);
// Is this the 1st element ? Then set the pause level to all the selectors of this target
element->paused = paused;
@ -352,7 +352,7 @@ void Scheduler::unscheduleSelector(SEL_SCHEDULE selector, Object *target)
//CCASSERT(selector);
tHashTimerEntry *element = NULL;
HASH_FIND_INT(_hashForTimers, &target, element);
HASH_FIND_PTR(_hashForTimers, &target, element);
if (element)
{
@ -448,7 +448,7 @@ void Scheduler::priorityIn(tListEntry **list, Object *target, int priority, bool
target->retain();
pHashElement->list = list;
pHashElement->entry = listElement;
HASH_ADD_INT(_hashForUpdates, target, pHashElement);
HASH_ADD_PTR(_hashForUpdates, target, pHashElement);
}
void Scheduler::appendIn(_listEntry **list, Object *target, bool paused)
@ -467,14 +467,14 @@ void Scheduler::appendIn(_listEntry **list, Object *target, bool paused)
target->retain();
pHashElement->list = list;
pHashElement->entry = listElement;
HASH_ADD_INT(_hashForUpdates, target, pHashElement);
HASH_ADD_PTR(_hashForUpdates, target, pHashElement);
}
void Scheduler::scheduleUpdateForTarget(Object *target, int priority, bool paused)
{
tHashUpdateEntry *pHashElement = NULL;
HASH_FIND_INT(_hashForUpdates, &target, pHashElement);
HASH_FIND_PTR(_hashForUpdates, &target, pHashElement);
if (pHashElement)
{
#if COCOS2D_DEBUG >= 1
@ -509,7 +509,7 @@ bool Scheduler::isScheduledForTarget(SEL_SCHEDULE selector, Object *target)
CCASSERT(target, "Argument target must be non-NULL");
tHashTimerEntry *element = NULL;
HASH_FIND_INT(_hashForTimers, &target, element);
HASH_FIND_PTR(_hashForTimers, &target, element);
if (!element)
{
@ -541,7 +541,7 @@ void Scheduler::removeUpdateFromHash(struct _listEntry *entry)
{
tHashUpdateEntry *element = NULL;
HASH_FIND_INT(_hashForUpdates, &entry->target, element);
HASH_FIND_PTR(_hashForUpdates, &entry->target, element);
if (element)
{
// list entry
@ -567,7 +567,7 @@ void Scheduler::unscheduleUpdateForTarget(const Object *target)
}
tHashUpdateEntry *element = NULL;
HASH_FIND_INT(_hashForUpdates, &target, element);
HASH_FIND_PTR(_hashForUpdates, &target, element);
if (element)
{
if (_updateHashLocked)
@ -601,31 +601,31 @@ void Scheduler::unscheduleAllWithMinPriority(int nMinPriority)
}
// Updates selectors
tListEntry *pEntry, *pTmp;
tListEntry *entry, *tmp;
if(nMinPriority < 0)
{
DL_FOREACH_SAFE(_updatesNegList, pEntry, pTmp)
DL_FOREACH_SAFE(_updatesNegList, entry, tmp)
{
if(pEntry->priority >= nMinPriority)
if(entry->priority >= nMinPriority)
{
unscheduleUpdateForTarget(pEntry->target);
unscheduleUpdateForTarget(entry->target);
}
}
}
if(nMinPriority <= 0)
{
DL_FOREACH_SAFE(_updates0List, pEntry, pTmp)
DL_FOREACH_SAFE(_updates0List, entry, tmp)
{
unscheduleUpdateForTarget(pEntry->target);
unscheduleUpdateForTarget(entry->target);
}
}
DL_FOREACH_SAFE(_updatesPosList, pEntry, pTmp)
DL_FOREACH_SAFE(_updatesPosList, entry, tmp)
{
if(pEntry->priority >= nMinPriority)
if(entry->priority >= nMinPriority)
{
unscheduleUpdateForTarget(pEntry->target);
unscheduleUpdateForTarget(entry->target);
}
}
@ -645,7 +645,7 @@ void Scheduler::unscheduleAllForTarget(Object *target)
// Custom Selectors
tHashTimerEntry *element = NULL;
HASH_FIND_INT(_hashForTimers, &target, element);
HASH_FIND_PTR(_hashForTimers, &target, element);
if (element)
{
@ -702,7 +702,7 @@ void Scheduler::resumeTarget(Object *target)
// custom selectors
tHashTimerEntry *element = NULL;
HASH_FIND_INT(_hashForTimers, &target, element);
HASH_FIND_PTR(_hashForTimers, &target, element);
if (element)
{
element->paused = false;
@ -710,7 +710,7 @@ void Scheduler::resumeTarget(Object *target)
// update selector
tHashUpdateEntry *elementUpdate = NULL;
HASH_FIND_INT(_hashForUpdates, &target, elementUpdate);
HASH_FIND_PTR(_hashForUpdates, &target, elementUpdate);
if (elementUpdate)
{
CCASSERT(elementUpdate->entry != NULL, "");
@ -724,7 +724,7 @@ void Scheduler::pauseTarget(Object *target)
// custom selectors
tHashTimerEntry *element = NULL;
HASH_FIND_INT(_hashForTimers, &target, element);
HASH_FIND_PTR(_hashForTimers, &target, element);
if (element)
{
element->paused = true;
@ -732,7 +732,7 @@ void Scheduler::pauseTarget(Object *target)
// update selector
tHashUpdateEntry *elementUpdate = NULL;
HASH_FIND_INT(_hashForUpdates, &target, elementUpdate);
HASH_FIND_PTR(_hashForUpdates, &target, elementUpdate);
if (elementUpdate)
{
CCASSERT(elementUpdate->entry != NULL, "");
@ -746,7 +746,7 @@ bool Scheduler::isTargetPaused(Object *target)
// Custom selectors
tHashTimerEntry *element = NULL;
HASH_FIND_INT(_hashForTimers, &target, element);
HASH_FIND_PTR(_hashForTimers, &target, element);
if( element )
{
return element->paused;
@ -754,7 +754,7 @@ bool Scheduler::isTargetPaused(Object *target)
// We should check update selectors if target does not have custom selectors
tHashUpdateEntry *elementUpdate = NULL;
HASH_FIND_INT(_hashForUpdates, &target, elementUpdate);
HASH_FIND_PTR(_hashForUpdates, &target, elementUpdate);
if ( elementUpdate )
{
return elementUpdate->entry->paused;
@ -836,32 +836,32 @@ void Scheduler::update(float dt)
}
// Iterate over all the Updates' selectors
tListEntry *pEntry, *pTmp;
tListEntry *entry, *tmp;
// updates with priority < 0
DL_FOREACH_SAFE(_updatesNegList, pEntry, pTmp)
DL_FOREACH_SAFE(_updatesNegList, entry, tmp)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
if ((! entry->paused) && (! entry->markedForDeletion))
{
pEntry->target->update(dt);
entry->target->update(dt);
}
}
// updates with priority == 0
DL_FOREACH_SAFE(_updates0List, pEntry, pTmp)
DL_FOREACH_SAFE(_updates0List, entry, tmp)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
if ((! entry->paused) && (! entry->markedForDeletion))
{
pEntry->target->update(dt);
entry->target->update(dt);
}
}
// updates with priority > 0
DL_FOREACH_SAFE(_updatesPosList, pEntry, pTmp)
DL_FOREACH_SAFE(_updatesPosList, entry, tmp)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
if ((! entry->paused) && (! entry->markedForDeletion))
{
pEntry->target->update(dt);
entry->target->update(dt);
}
}
@ -909,43 +909,43 @@ void Scheduler::update(float dt)
{
for (int i = _scriptHandlerEntries->count() - 1; i >= 0; i--)
{
SchedulerScriptHandlerEntry* pEntry = static_cast<SchedulerScriptHandlerEntry*>(_scriptHandlerEntries->getObjectAtIndex(i));
if (pEntry->isMarkedForDeletion())
SchedulerScriptHandlerEntry* eachEntry = static_cast<SchedulerScriptHandlerEntry*>(_scriptHandlerEntries->getObjectAtIndex(i));
if (eachEntry->isMarkedForDeletion())
{
_scriptHandlerEntries->removeObjectAtIndex(i);
}
else if (!pEntry->isPaused())
else if (!eachEntry->isPaused())
{
pEntry->getTimer()->update(dt);
eachEntry->getTimer()->update(dt);
}
}
}
// delete all updates that are marked for deletion
// updates with priority < 0
DL_FOREACH_SAFE(_updatesNegList, pEntry, pTmp)
DL_FOREACH_SAFE(_updatesNegList, entry, tmp)
{
if (pEntry->markedForDeletion)
if (entry->markedForDeletion)
{
this->removeUpdateFromHash(pEntry);
this->removeUpdateFromHash(entry);
}
}
// updates with priority == 0
DL_FOREACH_SAFE(_updates0List, pEntry, pTmp)
DL_FOREACH_SAFE(_updates0List, entry, tmp)
{
if (pEntry->markedForDeletion)
if (entry->markedForDeletion)
{
this->removeUpdateFromHash(pEntry);
this->removeUpdateFromHash(entry);
}
}
// updates with priority > 0
DL_FOREACH_SAFE(_updatesPosList, pEntry, pTmp)
DL_FOREACH_SAFE(_updatesPosList, entry, tmp)
{
if (pEntry->markedForDeletion)
if (entry->markedForDeletion)
{
this->removeUpdateFromHash(pEntry);
this->removeUpdateFromHash(entry);
}
}

View File

@ -219,7 +219,7 @@ bool Sprite::initWithFile(const std::string& filename)
{
CCASSERT(filename.size()>0, "Invalid filename for sprite");
Texture2D *texture = TextureCache::getInstance()->addImage(filename);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename);
if (texture)
{
Rect rect = Rect::ZERO;
@ -237,7 +237,7 @@ bool Sprite::initWithFile(const std::string &filename, const Rect& rect)
{
CCASSERT(filename.size()>0, "Invalid filename");
Texture2D *texture = TextureCache::getInstance()->addImage(filename);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename);
if (texture)
{
return initWithTexture(texture, rect);
@ -284,7 +284,7 @@ Sprite* Sprite::initWithCGImage(CGImageRef pImage, const char *pszKey)
CCASSERT(pImage != NULL);
// XXX: possible bug. See issue #349. New API should be added
Texture2D *texture = TextureCache::getInstance()->addCGImage(pImage, pszKey);
Texture2D *texture = Director::getInstance()->getTextureCache()->addCGImage(pImage, pszKey);
const Size& size = texture->getContentSize();
Rect rect = Rect(0 ,0, size.width, size.height);
@ -1113,7 +1113,7 @@ void Sprite::setTexture(Texture2D *texture)
if (NULL == texture)
{
// Gets the texture by key firstly.
texture = TextureCache::getInstance()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY);
texture = Director::getInstance()->getTextureCache()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY);
// If texture wasn't in cache, create it from RAW data.
if (NULL == texture)
@ -1122,7 +1122,7 @@ void Sprite::setTexture(Texture2D *texture)
bool isOK = image->initWithRawData(cc_2x2_white_image, sizeof(cc_2x2_white_image), 2, 2, 8);
CCASSERT(isOK, "The 2x2 empty texture was created unsuccessfully.");
texture = TextureCache::getInstance()->addImage(image, CC_2x2_WHITE_IMAGE_KEY);
texture = Director::getInstance()->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY);
CC_SAFE_RELEASE(image);
}
}

View File

@ -24,8 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __SPITE_NODE_CCSPRITE_H__
#define __SPITE_NODE_CCSPRITE_H__
#ifndef __SPRITE_NODE_CCSPRITE_H__
#define __SPRITE_NODE_CCSPRITE_H__
#include "CCNode.h"
#include "CCProtocols.h"
@ -54,7 +54,7 @@ struct transformValues_;
* @{
*/
/**
/**
* Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
*
* Sprite can be created with an image, or with a sub-rectangle of an image.
@ -88,14 +88,14 @@ public:
/// @{
/// @name Creators
/**
* Creates an empty sprite without texture. You can call setTexture method subsequently.
*
* @return An empty sprite object that is marked as autoreleased.
*/
static Sprite* create();
/**
* Creates a sprite with an image filename.
*
@ -106,7 +106,7 @@ public:
* @return A valid sprite object that is marked as autoreleased.
*/
static Sprite* create(const std::string& filename);
/**
* Creates a sprite with an image filename and a rect.
*
@ -115,7 +115,7 @@ public:
* @return A valid sprite object that is marked as autoreleased.
*/
static Sprite* create(const std::string& filename, const Rect& rect);
/**
* Creates a sprite with an exsiting texture contained in a Texture2D object
* After creation, the rect will be the size of the texture, and the offset will be (0,0).
@ -124,7 +124,7 @@ public:
* @return A valid sprite object that is marked as autoreleased.
*/
static Sprite* createWithTexture(Texture2D *texture);
/**
* Creates a sprite with a texture and a rect.
*
@ -136,7 +136,7 @@ public:
* @return A valid sprite object that is marked as autoreleased.
*/
static Sprite* createWithTexture(Texture2D *texture, const Rect& rect);
/**
* Creates a sprite with an sprite frame.
*
@ -144,7 +144,7 @@ public:
* @return A valid sprite object that is marked as autoreleased.
*/
static Sprite* createWithSpriteFrame(SpriteFrame *pSpriteFrame);
/**
* Creates a sprite with an sprite frame name.
*
@ -155,31 +155,31 @@ public:
* @return A valid sprite object that is marked as autoreleased.
*/
static Sprite* createWithSpriteFrameName(const std::string& spriteFrameName);
/// @} end of creators group
/// @{
/// @name Initializers
/**
* Default constructor
* @js ctor
*/
Sprite(void);
/**
* Default destructor
* @js NA
* @lua NA
*/
virtual ~Sprite(void);
/**
* Initializes an empty sprite with nothing init.
*/
virtual bool init(void);
/**
* Initializes a sprite with a texture.
*
@ -190,7 +190,7 @@ public:
* @return true if the sprite is initialized properly, false otherwise.
*/
virtual bool initWithTexture(Texture2D *texture);
/**
* Initializes a sprite with a texture and a rect.
*
@ -202,7 +202,7 @@ public:
* @return true if the sprite is initialized properly, false otherwise.
*/
virtual bool initWithTexture(Texture2D *texture, const Rect& rect);
/**
* Initializes a sprite with a texture and a rect in points, optionally rotated.
*
@ -215,7 +215,7 @@ public:
* @return true if the sprite is initialized properly, false otherwise.
*/
virtual bool initWithTexture(Texture2D *texture, const Rect& rect, bool rotated);
/**
* Initializes a sprite with an SpriteFrame. The texture and rect in SpriteFrame will be applied on this sprite
*
@ -223,7 +223,7 @@ public:
* @return true if the sprite is initialized properly, false otherwise.
*/
virtual bool initWithSpriteFrame(SpriteFrame *pSpriteFrame);
/**
* Initializes a sprite with an sprite frame name.
*
@ -234,7 +234,7 @@ public:
* @return true if the sprite is initialized properly, false otherwise.
*/
virtual bool initWithSpriteFrameName(const std::string& spriteFrameName);
/**
* Initializes a sprite with an image filename.
*
@ -248,7 +248,7 @@ public:
* @lua init
*/
virtual bool initWithFile(const std::string& filename);
/**
* Initializes a sprite with an image filename, and a rect.
*
@ -263,17 +263,17 @@ public:
* @lua init
*/
virtual bool initWithFile(const std::string& filename, const Rect& rect);
/// @} end of initializers
/// @{
/// @name BatchNode methods
/**
* Updates the quad according the rotation, position, scale values.
* Updates the quad according the rotation, position, scale values.
*/
virtual void updateTransform(void);
/**
* Returns the batch node object if this sprite is rendered by SpriteBatchNode
*
@ -292,26 +292,26 @@ public:
* @endcode
*/
virtual void setBatchNode(SpriteBatchNode *spriteBatchNode);
/// @} end of BatchNode methods
/// @{
/// @name Texture methods
/**
* Updates the texture rect of the Sprite in points.
* It will call setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize) with \p rotated = false, and \p utrimmedSize = rect.size.
*/
virtual void setTextureRect(const Rect& rect);
/**
* Sets the texture rect, rectRotated and untrimmed size of the Sprite in points.
* It will update the texture coordinates and the vertex rectangle.
*/
virtual void setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize);
/**
* Sets the vertex rect.
* It will be called internally by setTextureRect.
@ -319,34 +319,34 @@ public:
* Do not call it manually. Use setTextureRect instead.
*/
virtual void setVertexRect(const Rect& rect);
/// @} end of texture methods
/// @} end of texture methods
/// @{
/// @name Frames methods
/**
* Sets a new display frame to the Sprite.
*/
virtual void setDisplayFrame(SpriteFrame *pNewFrame);
/**
* Returns whether or not a SpriteFrame is being displayed
*/
virtual bool isFrameDisplayed(SpriteFrame *pFrame) const;
/** @deprecated Use getDisplayFrame() instead */
CC_DEPRECATED_ATTRIBUTE virtual SpriteFrame* displayFrame() { return getDisplayFrame(); };
/**
* Returns the current displayed frame.
*/
virtual SpriteFrame* getDisplayFrame();
/// @} End of frames methods
/// @{
/// @name Animation methods
@ -356,23 +356,23 @@ public:
*/
virtual void setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex);
/// @}
/// @{
/// @name Sprite Properties' setter/getters
/**
/**
* Whether or not the Sprite needs to be updated in the Atlas.
*
* @return true if the sprite needs to be updated in the Atlas, false otherwise.
*/
virtual bool isDirty(void) const { return _dirty; }
/**
/**
* Makes the Sprite to be updated in the Atlas.
*/
virtual void setDirty(bool bDirty) { _dirty = bDirty; }
/**
* Returns the quad (tex coords, vertex coords and color) information.
* @js NA
@ -380,24 +380,24 @@ public:
*/
inline V3F_C4B_T2F_Quad getQuad(void) const { return _quad; }
/**
/**
* Returns whether or not the texture rectangle is rotated.
*/
inline bool isTextureRectRotated(void) const { return _rectRotated; }
/**
* Returns the index used on the TextureAtlas.
/**
* Returns the index used on the TextureAtlas.
*/
inline int getAtlasIndex(void) const { return _atlasIndex; }
/**
/**
* Sets the index used on the TextureAtlas.
* @warning Don't modify this value unless you know what you are doing
*/
inline void setAtlasIndex(int atlasIndex) { _atlasIndex = atlasIndex; }
/**
* Returns the rect of the Sprite in points
/**
* Returns the rect of the Sprite in points
*/
inline const Rect& getTextureRect(void) { return _rect; }
@ -405,19 +405,19 @@ public:
* Gets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode
*/
inline TextureAtlas* getTextureAtlas(void) { return _textureAtlas; }
/**
* Sets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode
*/
inline void setTextureAtlas(TextureAtlas *pobTextureAtlas) { _textureAtlas = pobTextureAtlas; }
/**
/**
* Gets the offset position of the sprite. Calculated automatically by editors like Zwoptex.
*/
inline const Point& getOffsetPosition(void) const { return _offsetPosition; }
/**
/**
* Returns the flag which indicates whether the sprite is flipped horizontally or not.
*
* It only flips the texture of the sprite, and not the texture of the sprite's children.
@ -425,48 +425,48 @@ public:
* If you want to flip the anchorPoint too, and/or to flip the children too use:
* sprite->setScaleX(sprite->getScaleX() * -1);
*
* @return true if the sprite is flipped horizaontally, false otherwise.
* @return true if the sprite is flipped horizontally, false otherwise.
*/
bool isFlippedX(void) const;
/**
* Sets whether the sprite should be flipped horizontally or not.
*
* @param bFlipX true if the sprite should be flipped horizaontally, false otherwise.
* @param flippedX true if the sprite should be flipped horizontally, false otherwise.
*/
void setFlippedX(bool flippedX);
/** @deprecated Use isFlippedX() instead
/** @deprecated Use isFlippedX() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE bool isFlipX() { return isFlippedX(); };
/** @deprecated Use setFlippedX() instead */
CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flippedX) { setFlippedX(flippedX); };
/**
CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flippedX) { setFlippedX(flippedX); };
/**
* Return the flag which indicates whether the sprite is flipped vertically or not.
*
*
* It only flips the texture of the sprite, and not the texture of the sprite's children.
* Also, flipping the texture doesn't alter the anchorPoint.
* If you want to flip the anchorPoint too, and/or to flip the children too use:
* sprite->setScaleY(sprite->getScaleY() * -1);
*
* @return true if the sprite is flipped vertically, flase otherwise.
*
* @return true if the sprite is flipped vertically, false otherwise.
*/
bool isFlippedY(void) const;
/**
* Sets whether the sprite should be flipped vertically or not.
*
* @param bFlipY true if the sprite should be flipped vertically, flase otherwise.
* @param flippedY true if the sprite should be flipped vertically, false otherwise.
*/
void setFlippedY(bool flippedY);
/// @} End of Sprite properties getter/setters
/** @deprecated Use isFlippedY() instead */
CC_DEPRECATED_ATTRIBUTE bool isFlipY() { return isFlippedY(); };
/** @deprecated Use setFlippedY() instead */
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flippedY) { setFlippedY(flippedY); };
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flippedY) { setFlippedY(flippedY); };
//
// Overrides
@ -543,13 +543,13 @@ protected:
TextureAtlas* _textureAtlas; /// SpriteBatchNode texture atlas (weak reference)
int _atlasIndex; /// Absolute (real) Index on the SpriteSheet
SpriteBatchNode* _batchNode; /// Used batch node (weak reference)
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
AffineTransform _transformToBatch;
//
// Data used when the sprite is self-rendered
//
@ -575,8 +575,8 @@ protected:
bool _opacityModifyRGB;
// image is flipped
bool _flippedX; /// Whether the sprite is flipped horizaontally or not.
bool _flippedY; /// Whether the sprite is flipped vertically or not.
bool _flippedX; /// Whether the sprite is flipped horizontally or not
bool _flippedY; /// Whether the sprite is flipped vertically or not
};
@ -585,4 +585,4 @@ protected:
NS_CC_END
#endif // __SPITE_NODE_CCSPRITE_H__
#endif // __SPRITE_NODE_CCSPRITE_H__

View File

@ -114,7 +114,7 @@ bool SpriteBatchNode::init()
*/
bool SpriteBatchNode::initWithFile(const char* fileImage, long capacity)
{
Texture2D *texture2D = TextureCache::getInstance()->addImage(fileImage);
Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage);
return initWithTexture(texture2D, capacity);
}
@ -598,8 +598,8 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
{
auto next = std::next(it);
std::for_each(next, _descendants.end(), [](Sprite *sprite) {
sprite->setAtlasIndex( sprite->getAtlasIndex() - 1 );
std::for_each(next, _descendants.end(), [](Sprite *spr) {
spr->setAtlasIndex( spr->getAtlasIndex() - 1 );
});
_descendants.erase(it);

View File

@ -180,7 +180,7 @@ Texture2D* SpriteFrame::getTexture(void)
}
if( _textureFilename.length() > 0 ) {
return TextureCache::getInstance()->addImage(_textureFilename.c_str());
return Director::getInstance()->getTextureCache()->addImage(_textureFilename.c_str());
}
// no texture or texture filename
return NULL;

View File

@ -37,6 +37,7 @@ THE SOFTWARE.
#include "CCString.h"
#include "CCArray.h"
#include "CCDictionary.h"
#include "CCDirector.h"
#include <vector>
using namespace std;
@ -215,7 +216,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist, Text
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName)
{
CCASSERT(textureFileName.size()>0, "texture name should not be null");
Texture2D *texture = TextureCache::getInstance()->addImage(textureFileName);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(textureFileName);
if (texture)
{
@ -265,7 +266,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist)
CCLOG("cocos2d: SpriteFrameCache: Trying to use file %s as texture", texturePath.c_str());
}
Texture2D *texture = TextureCache::getInstance()->addImage(texturePath.c_str());
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(texturePath.c_str());
if (texture)
{

View File

@ -58,7 +58,7 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
Texture2D *texture = NULL;
if( tilesetInfo )
{
texture = TextureCache::getInstance()->addImage(tilesetInfo->_sourceImage.c_str());
texture = Director::getInstance()->getTextureCache()->addImage(tilesetInfo->_sourceImage.c_str());
}
if (SpriteBatchNode::initWithTexture(texture, (unsigned int)capacity))

View File

@ -434,7 +434,7 @@ Texture2D::Texture2D()
Texture2D::~Texture2D()
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTexture::removeTexture(this);
VolatileTextureMgr::removeTexture(this);
#endif
CCLOGINFO("deallocing Texture2D: %p - id=%u", this, _name);
@ -1041,7 +1041,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
// cache the texture data
VolatileTexture::addStringTexture(this, text, textDefinition);
VolatileTextureMgr::addStringTexture(this, text, textDefinition);
#endif
bool bRet = false;
@ -1267,7 +1267,7 @@ void Texture2D::setTexParameters(const TexParams &texParams)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams.wrapT );
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTexture::setTexParameters(this, texParams);
VolatileTextureMgr::setTexParameters(this, texParams);
#endif
}
@ -1287,7 +1287,7 @@ void Texture2D::setAliasTexParameters()
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
#if CC_ENABLE_CACHE_TEXTURE_DATA
TexParams texParams = {(GLuint)(_hasMipmaps?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST),GL_NEAREST,GL_NONE,GL_NONE};
VolatileTexture::setTexParameters(this, texParams);
VolatileTextureMgr::setTexParameters(this, texParams);
#endif
}
@ -1307,7 +1307,7 @@ void Texture2D::setAntiAliasTexParameters()
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
#if CC_ENABLE_CACHE_TEXTURE_DATA
TexParams texParams = {(GLuint)(_hasMipmaps?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR),GL_LINEAR,GL_NONE,GL_NONE};
VolatileTexture::setTexParameters(this, texParams);
VolatileTextureMgr::setTexParameters(this, texParams);
#endif
}

View File

@ -32,6 +32,7 @@ THE SOFTWARE.
#include "ccGLStateCache.h"
#include "CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCDirector.h"
#include "CCGL.h"
// support
#include "CCTexture2D.h"
@ -134,7 +135,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, long capacity
bool TextureAtlas::initWithFile(const char * file, long capacity)
{
// retained in property
Texture2D *texture = TextureCache::getInstance()->addImage(file);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file);
if (texture)
{

View File

@ -51,19 +51,9 @@ NS_CC_BEGIN
// implementation TextureCache
TextureCache* TextureCache::_sharedTextureCache = nullptr;
TextureCache * TextureCache::getInstance()
{
if (!_sharedTextureCache)
{
#ifdef EMSCRIPTEN
_sharedTextureCache = new TextureCacheEmscripten();
#else
_sharedTextureCache = new TextureCache();
#endif // EMSCRIPTEN
}
return _sharedTextureCache;
return Director::getInstance()->getTextureCache();
}
TextureCache::TextureCache()
@ -73,7 +63,6 @@ TextureCache::TextureCache()
, _needQuit(false)
, _asyncRefCount(0)
{
CCASSERT(_sharedTextureCache == nullptr, "Attempted to allocate a second instance of a singleton.");
}
TextureCache::~TextureCache()
@ -84,20 +73,19 @@ TextureCache::~TextureCache()
(it->second)->release();
CC_SAFE_DELETE(_loadingThread);
_sharedTextureCache = nullptr;
}
void TextureCache::destroyInstance()
{
if (_sharedTextureCache)
{
// notify sub thread to quick
_sharedTextureCache->_needQuit = true;
_sharedTextureCache->_sleepCondition.notify_one();
if (_sharedTextureCache->_loadingThread) _sharedTextureCache->_loadingThread->join();
CC_SAFE_RELEASE_NULL(_sharedTextureCache);
}
}
TextureCache * TextureCache::sharedTextureCache()
{
return Director::getInstance()->getTextureCache();
}
void TextureCache::purgeSharedTextureCache()
{
}
const char* TextureCache::description() const
@ -260,7 +248,7 @@ void TextureCache::addImageAsyncCallBack(float dt)
#if CC_ENABLE_CACHE_TEXTURE_DATA
// cache the texture file name
VolatileTexture::addImageTexture(texture, filename);
VolatileTextureMgr::addImageTexture(texture, filename);
#endif
// cache the texture. retain it, since it is added in the map
_textures.insert( std::make_pair(filename, texture) );
@ -320,7 +308,7 @@ Texture2D * TextureCache::addImage(const std::string &path)
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
// cache the texture file name
VolatileTexture::addImageTexture(texture, fullpath.c_str());
VolatileTextureMgr::addImageTexture(texture, fullpath.c_str());
#endif
// texture already retained, no need to re-retain it
_textures.insert( std::make_pair(fullpath, texture) );
@ -370,7 +358,7 @@ Texture2D* TextureCache::addImage(Image *image, const std::string &key)
} while (0);
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTexture::addImage(texture, image);
VolatileTextureMgr::addImage(texture, image);
#endif
return texture;
@ -438,9 +426,18 @@ Texture2D* TextureCache::getTextureForKey(const std::string &key) const
void TextureCache::reloadAllTextures()
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTexture::reloadAllTextures();
#endif
//will do nothing
// #if CC_ENABLE_CACHE_TEXTURE_DATA
// VolatileTextureMgr::reloadAllTextures();
// #endif
}
void TextureCache::waitForQuit()
{
// notify sub thread to quick
_needQuit = true;
_sleepCondition.notify_one();
if (_loadingThread) _loadingThread->join();
}
void TextureCache::dumpCachedTextureInfo() const
@ -471,8 +468,8 @@ void TextureCache::dumpCachedTextureInfo() const
#if CC_ENABLE_CACHE_TEXTURE_DATA
std::list<VolatileTexture*> VolatileTexture::_textures;
bool VolatileTexture::_isReloading = false;
std::list<VolatileTexture*> VolatileTextureMgr::_textures;
bool VolatileTextureMgr::_isReloading = false;
VolatileTexture::VolatileTexture(Texture2D *t)
: _texture(t)
@ -487,16 +484,14 @@ VolatileTexture::VolatileTexture(Texture2D *t)
_texParams.magFilter = GL_LINEAR;
_texParams.wrapS = GL_CLAMP_TO_EDGE;
_texParams.wrapT = GL_CLAMP_TO_EDGE;
_textures.push_back(this);
}
VolatileTexture::~VolatileTexture()
{
_textures.remove(this);
CC_SAFE_RELEASE(_uiImage);
}
void VolatileTexture::addImageTexture(Texture2D *tt, const char* imageFileName)
void VolatileTextureMgr::addImageTexture(Texture2D *tt, const char* imageFileName)
{
if (_isReloading)
{
@ -505,20 +500,20 @@ void VolatileTexture::addImageTexture(Texture2D *tt, const char* imageFileName)
VolatileTexture *vt = findVolotileTexture(tt);
vt->_cashedImageType = kImageFile;
vt->_cashedImageType = VolatileTexture::kImageFile;
vt->_fileName = imageFileName;
vt->_pixelFormat = tt->getPixelFormat();
}
void VolatileTexture::addImage(Texture2D *tt, Image *image)
void VolatileTextureMgr::addImage(Texture2D *tt, Image *image)
{
VolatileTexture *vt = findVolotileTexture(tt);
image->retain();
vt->_uiImage = image;
vt->_cashedImageType = kImage;
vt->_cashedImageType = VolatileTexture::kImage;
}
VolatileTexture* VolatileTexture::findVolotileTexture(Texture2D *tt)
VolatileTexture* VolatileTextureMgr::findVolotileTexture(Texture2D *tt)
{
VolatileTexture *vt = 0;
auto i = _textures.begin();
@ -535,12 +530,13 @@ VolatileTexture* VolatileTexture::findVolotileTexture(Texture2D *tt)
if (! vt)
{
vt = new VolatileTexture(tt);
_textures.push_back(vt);
}
return vt;
}
void VolatileTexture::addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize)
void VolatileTextureMgr::addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize)
{
if (_isReloading)
{
@ -549,14 +545,14 @@ void VolatileTexture::addDataTexture(Texture2D *tt, void* data, int dataLen, Tex
VolatileTexture *vt = findVolotileTexture(tt);
vt->_cashedImageType = kImageData;
vt->_cashedImageType = VolatileTexture::kImageData;
vt->_textureData = data;
vt->_dataLen = dataLen;
vt->_pixelFormat = pixelFormat;
vt->_textureSize = contentSize;
}
void VolatileTexture::addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition)
void VolatileTextureMgr::addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition)
{
if (_isReloading)
{
@ -565,12 +561,12 @@ void VolatileTexture::addStringTexture(Texture2D *tt, const char* text, const Fo
VolatileTexture *vt = findVolotileTexture(tt);
vt->_cashedImageType = kString;
vt->_cashedImageType = VolatileTexture::kString;
vt->_text = text;
vt->_fontDefinition = fontDefinition;
}
void VolatileTexture::setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams)
void VolatileTextureMgr::setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams)
{
VolatileTexture *vt = findVolotileTexture(t);
@ -584,7 +580,7 @@ void VolatileTexture::setTexParameters(Texture2D *t, const Texture2D::TexParams
vt->_texParams.wrapT = texParams.wrapT;
}
void VolatileTexture::removeTexture(Texture2D *t)
void VolatileTextureMgr::removeTexture(Texture2D *t)
{
auto i = _textures.begin();
while (i != _textures.end())
@ -592,13 +588,14 @@ void VolatileTexture::removeTexture(Texture2D *t)
VolatileTexture *vt = *i++;
if (vt->_texture == t)
{
_textures.remove(vt);
delete vt;
break;
}
}
}
void VolatileTexture::reloadAllTextures()
void VolatileTextureMgr::reloadAllTextures()
{
_isReloading = true;
@ -611,7 +608,7 @@ void VolatileTexture::reloadAllTextures()
switch (vt->_cashedImageType)
{
case kImageFile:
case VolatileTexture::kImageFile:
{
Image* image = new Image();
long size = 0;
@ -629,7 +626,7 @@ void VolatileTexture::reloadAllTextures()
CC_SAFE_RELEASE(image);
}
break;
case kImageData:
case VolatileTexture::kImageData:
{
vt->_texture->initWithData(vt->_textureData,
vt->_dataLen,
@ -639,12 +636,12 @@ void VolatileTexture::reloadAllTextures()
vt->_textureSize);
}
break;
case kString:
case VolatileTexture::kString:
{
vt->_texture->initWithString(vt->_text.c_str(), vt->_fontDefinition);
}
break;
case kImage:
case VolatileTexture::kImage:
{
vt->_texture->initWithImage(vt->_uiImage);
}

View File

@ -50,6 +50,10 @@ NS_CC_BEGIN
* @addtogroup textures
* @{
*/
/*
* from version 3.0, TextureCache will never to treated as a singleton, it will be owned by director.
* all call by TextureCache::getInstance() should be replaced by Director::getInstance()->getTextureCache()
*/
/** @brief Singleton that handles the loading of textures
* Once the texture is loaded, the next time it will return
@ -59,23 +63,24 @@ class CC_DLL TextureCache : public Object
{
public:
/** Returns the shared instance of the cache */
static TextureCache * getInstance();
CC_DEPRECATED_ATTRIBUTE static TextureCache * getInstance();
/** @deprecated Use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static TextureCache * sharedTextureCache() { return TextureCache::getInstance(); }
CC_DEPRECATED_ATTRIBUTE static TextureCache * sharedTextureCache();
/** purges the cache. It releases the retained instance.
@since v0.99.0
*/
static void destroyInstance();
CC_DEPRECATED_ATTRIBUTE static void destroyInstance();
/** @deprecated Use destroyInstance() instead */
CC_DEPRECATED_ATTRIBUTE static void purgeSharedTextureCache() { return TextureCache::destroyInstance(); }
CC_DEPRECATED_ATTRIBUTE static void purgeSharedTextureCache();
/** Reload all textures
It's only useful when the value of CC_ENABLE_CACHE_TEXTURE_DATA is 1
should not call it, called by frame work
now the function do nothing, use VolatileTextureMgr::reloadAllTextures
*/
static void reloadAllTextures();
CC_DEPRECATED_ATTRIBUTE static void reloadAllTextures();
public:
/**
@ -158,6 +163,10 @@ public:
*/
void dumpCachedTextureInfo() const;
//wait for texture cahe to quit befor destroy instance
//called by director, please do not called outside
void waitForQuit();
private:
void addImageAsyncCallBack(float dt);
void loadImage();
@ -196,8 +205,6 @@ protected:
int _asyncRefCount;
std::unordered_map<std::string, Texture2D*> _textures;
static TextureCache *_sharedTextureCache;
};
#if CC_ENABLE_CACHE_TEXTURE_DATA
@ -212,7 +219,7 @@ class VolatileTexture
kImage,
}ccCachedImageType;
public:
private:
VolatileTexture(Texture2D *t);
/**
* @js NA
@ -220,25 +227,8 @@ public:
*/
~VolatileTexture();
static void addImageTexture(Texture2D *tt, const char* imageFileName);
static void addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition);
static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize);
static void addImage(Texture2D *tt, Image *image);
static void setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams);
static void removeTexture(Texture2D *t);
static void reloadAllTextures();
public:
static std::list<VolatileTexture*> _textures;
static bool _isReloading;
private:
// find VolatileTexture by Texture2D*
// if not found, create a new one
static VolatileTexture* findVolotileTexture(Texture2D *tt);
protected:
friend class VolatileTextureMgr;
Texture2D *_texture;
Image *_uiImage;
@ -257,6 +247,26 @@ protected:
FontDefinition _fontDefinition;
};
class VolatileTextureMgr
{
public:
static void addImageTexture(Texture2D *tt, const char* imageFileName);
static void addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition);
static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize);
static void addImage(Texture2D *tt, Image *image);
static void setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams);
static void removeTexture(Texture2D *t);
static void reloadAllTextures();
public:
static std::list<VolatileTexture*> _textures;
static bool _isReloading;
private:
// find VolatileTexture by Texture2D*
// if not found, create a new one
static VolatileTexture* findVolotileTexture(Texture2D *tt);
};
#endif
// end of textures group

View File

@ -128,4 +128,8 @@ Application::Platform Application::getTargetPlatform()
return Platform::OS_ANDROID;
}
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {
}
NS_CC_END

View File

@ -50,6 +50,13 @@ public:
*/
virtual Platform getTargetPlatform();
/**
@brief This function will be called when the application screen size is changed.
@param new width
@param new height
*/
virtual void applicationScreenSizeChanged(int newWidth, int newHeight);
protected:
static Application * sm_pSharedApplication;
};

View File

View File

@ -12,6 +12,7 @@
#include <android/configuration.h>
#include <pthread.h>
#include <chrono>
#include "CCDirector.h"
#include "CCApplication.h"
@ -69,6 +70,9 @@ struct engine {
struct saved_state state;
};
static bool isContentRectChanged = false;
static std::chrono::steady_clock::time_point timeRectChanged;
static struct engine engine;
static char* editboxText = NULL;
@ -127,7 +131,7 @@ static void cocos_init(cocos_dimensions d, struct android_app* app) {
cocos2d::GL::invalidateStateCache();
cocos2d::ShaderCache::getInstance()->reloadDefaultShaders();
cocos2d::DrawPrimitives::init();
cocos2d::TextureCache::reloadAllTextures();
cocos2d::VolatileTextureMgr::reloadAllTextures();
cocos2d::NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
cocos2d::Director::getInstance()->setGLDefaultValues();
}
@ -558,6 +562,11 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
}
}
static void onContentRectChanged(ANativeActivity* activity, const ARect* rect) {
timeRectChanged = std::chrono::steady_clock::now();
isContentRectChanged = true;
}
/**
* This is the main entry point of a native application that is using
* android_native_app_glue. It runs in its own thread, with its own
@ -586,6 +595,9 @@ void android_main(struct android_app* state) {
engine.state = *(struct saved_state*)state->savedState;
}
// Screen size change support
state->activity->callbacks->onContentRectChanged = onContentRectChanged;
// loop waiting for stuff to do.
while (1) {
@ -673,5 +685,20 @@ void android_main(struct android_app* state) {
} else {
LOG_RENDER_DEBUG("android_main : !engine.animating");
}
// Check if screen size changed
if (isContentRectChanged) {
std::chrono::duration<int, std::milli> duration(
std::chrono::duration_cast<std::chrono::duration<int, std::milli>>(std::chrono::steady_clock::now() - timeRectChanged));
// Wait about 30 ms to get new width and height. Without waiting we can get old values sometime
if (duration.count() > 30) {
isContentRectChanged = false;
int32_t newWidth = ANativeWindow_getWidth(engine.app->window);
int32_t newHeight = ANativeWindow_getHeight(engine.app->window);
cocos2d::Application::getInstance()->applicationScreenSizeChanged(newWidth, newHeight);
}
}
}
}

View File

@ -76,6 +76,13 @@ public:
*/
virtual Platform getTargetPlatform();
/**
@brief This function will be called when the application screen size is changed.
@param new width
@param new height
*/
virtual void applicationScreenSizeChanged(int newWidth, int newHeight);
protected:
static Application * sm_pSharedApplication;
};

View File

@ -146,4 +146,8 @@ Application::Platform Application::getTargetPlatform()
}
}
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {
}
NS_CC_END

0
cocos/2d/platform/ios/EAGLView.h Executable file → Normal file
View File

0
cocos/2d/platform/ios/OpenGL_Internal.h Executable file → Normal file
View File

0
cocos/2d/platform/mac/EAGLView.h Executable file → Normal file
View File

0
cocos/audio/mac/CDXMacOSXSupport.h Executable file → Normal file
View File

0
cocos/audio/mac/CDXMacOSXSupport.mm Executable file → Normal file
View File

0
cocos/audio/proj.linux/.cproject Executable file → Normal file
View File

0
cocos/audio/proj.linux/.project Executable file → Normal file
View File

View File

@ -138,7 +138,7 @@ static void atitc_decode_block(uint8_t **blockData,
{
for (int x = 0; x < 4; ++x)
{
initAlpha = (alpha & 0x0f) << 28;
initAlpha = (static_cast<int>(alpha) & 0x0f) << 28;
initAlpha += initAlpha >> 4;
decodeBlockData[x] = initAlpha + colors[pixelsIndex & 3];
pixelsIndex >>= 2;

View File

@ -126,7 +126,7 @@ static void s3tc_decode_block(uint8_t **blockData,
{
for (int x = 0; x < 4; ++x)
{
initAlpha = (alpha & 0x0f) << 28;
initAlpha = (static_cast<int>(alpha) & 0x0f) << 28;
initAlpha += initAlpha >> 4;
decodeBlockData[x] = initAlpha + colors[pixelsIndex & 3];
pixelsIndex >>= 2;

View File

@ -482,12 +482,12 @@ int CCBReader::readInt(bool pSigned) {
if(pSigned) {
int s = current % 2;
if(s) {
num = (int)(current / 2);
num = static_cast<int>(current / 2);
} else {
num = (int)(-current / 2);
num = static_cast<int>(-current / 2);
}
} else {
num = current - 1;
num = static_cast<int>(current - 1);
}
this->alignBits();
@ -833,7 +833,7 @@ CCBKeyframe* CCBReader::readKeyframe(PropertyType type)
{
spriteFile = _CCBRootPath + spriteFile;
Texture2D *texture = TextureCache::getInstance()->addImage(spriteFile.c_str());
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(spriteFile.c_str());
Rect bounds = Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height);
spriteFrame = SpriteFrame::createWithTexture(texture, bounds);

View File

@ -577,7 +577,7 @@ SpriteFrame * NodeLoader::parsePropTypeSpriteFrame(Node * pNode, Node * pParent,
if (spriteSheet.length() == 0)
{
spriteFile = ccbReader->getCCBRootPath() + spriteFile;
Texture2D * texture = TextureCache::getInstance()->addImage(spriteFile.c_str());
Texture2D * texture = Director::getInstance()->getTextureCache()->addImage(spriteFile.c_str());
if(texture != NULL) {
Rect bounds = Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height);
spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
@ -635,7 +635,7 @@ Texture2D * NodeLoader::parsePropTypeTexture(Node * pNode, Node * pParent, CCBRe
if (spriteFile.length() > 0)
{
return TextureCache::getInstance()->addImage(spriteFile.c_str());
return Director::getInstance()->getTextureCache()->addImage(spriteFile.c_str());
}
else
{

View File

@ -579,8 +579,7 @@ ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML
ArmatureData *armatureData = new ArmatureData();
armatureData->init();
const char *name = armatureXML->Attribute(A_NAME);
armatureData->name = name;
armatureData->name = armatureXML->Attribute(A_NAME);
tinyxml2::XMLElement *boneXML = armatureXML->FirstChildElement(BONE);
@ -888,21 +887,21 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
FrameData **frames = (FrameData **)movBoneData->frameList.data->arr;
for (int i = movBoneData->frameList.count() - 1; i >= 0; i--)
for (int j = movBoneData->frameList.count() - 1; j >= 0; j--)
{
if (i > 0)
if (j > 0)
{
float difSkewX = frames[i]->skewX - frames[i - 1]->skewX;
float difSkewY = frames[i]->skewY - frames[i - 1]->skewY;
float difSkewX = frames[j]->skewX - frames[j - 1]->skewX;
float difSkewY = frames[j]->skewY - frames[j - 1]->skewY;
if (difSkewX < -M_PI || difSkewX > M_PI)
{
frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI;
frames[j - 1]->skewX = difSkewX < 0 ? frames[j - 1]->skewX - 2 * M_PI : frames[j - 1]->skewX + 2 * M_PI;
}
if (difSkewY < -M_PI || difSkewY > M_PI)
{
frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI;
frames[j - 1]->skewY = difSkewY < 0 ? frames[j - 1]->skewY - 2 * M_PI : frames[j - 1]->skewY + 2 * M_PI;
}
}
}

View File

@ -47,6 +47,7 @@ InputDelegate::~InputDelegate(void)
dispatcher->removeEventListener(_touchListener);
dispatcher->removeEventListener(_keyboardListener);
dispatcher->removeEventListener(_accelerometerListener);
Device::setAccelerometerEnabled(false);
}
bool InputDelegate::onTouchBegan(Touch *pTouch, Event *pEvent)
@ -196,6 +197,8 @@ void InputDelegate::setAccelerometerEnabled(bool enabled)
dispatcher->removeEventListener(_accelerometerListener);
_accelerometerListener = nullptr;
Device::setAccelerometerEnabled(enabled);
if (enabled)
{
auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(InputDelegate::onAcceleration, this));

0
cocos/editor-support/cocostudio/CCSGUIReader.cpp Executable file → Normal file
View File

0
cocos/editor-support/cocostudio/CCSGUIReader.h Executable file → Normal file
View File

View File

@ -227,9 +227,9 @@ namespace cocostudio {
const char *name = DICTOOL->getStringValue_json(subData, "name");
childrenCount = DICTOOL->getArrayCount_json(jsonDict, "config_file_path");
for (long i = 0; i < childrenCount; ++i)
for (long j = 0; j < childrenCount; ++j)
{
const char* plist = DICTOOL->getStringValueFromArray_json(jsonDict, "config_file_path", i);
const char* plist = DICTOOL->getStringValueFromArray_json(jsonDict, "config_file_path", j);
std::string plistpath;
plistpath += file_path;
plistpath.append(plist);

View File

@ -248,12 +248,12 @@ void _RotateTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float
bone = skeleton->bones[self->boneIndex];
if (time >= self->frames[self->framesLength - 2]) { /* Time is after last frame. */
float amount = bone->data->rotation + self->frames[self->framesLength - 1] - bone->rotation;
while (amount > 180)
amount -= 360;
while (amount < -180)
amount += 360;
bone->rotation += amount * alpha;
float count = bone->data->rotation + self->frames[self->framesLength - 1] - bone->rotation;
while (count > 180)
count -= 360;
while (count < -180)
count += 360;
bone->rotation += count * alpha;
return;
}

View File

@ -118,7 +118,7 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
skeletonData->animationCount++;
for (i = 0; i < boneCount; ++i) {
int timelineCount;
timelineCount = 0;
Json* boneMap = Json_getItemAt(bones, i);
const char* boneName = boneMap->name;
@ -175,7 +175,7 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
}
for (i = 0; i < slotCount; ++i) {
int timelineCount;
timelineCount = 0;
Json* slotMap = Json_getItemAt(slots, i);
const char* slotName = slotMap->name;

View File

@ -31,7 +31,7 @@ USING_NS_CC;
namespace spine {
void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
Texture2D* texture = TextureCache::getInstance()->addImage(path);
Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(path);
TextureAtlas* textureAtlas = TextureAtlas::createWithTexture(texture, 4);
textureAtlas->retain();
self->rendererObject = textureAtlas;

@ -1 +1 @@
Subproject commit 7199547f2f9ffbac4fdeac20e4bb50328c6d9352
Subproject commit 5788b2500339473ecc19acf1c2e43656a2537a6d

View File

@ -60,14 +60,15 @@ static std::vector<std::string> g_queue;
static std::mutex g_qMutex;
static std::mutex g_rwMutex;
static int clientSocket = -1;
static unsigned long s_nestedLoopLevel = 0;
static uint32_t s_nestedLoopLevel = 0;
// server entry point for the bg thread
static void serverEntryPoint(void);
js_proxy_t *_native_js_global_ht = NULL;
js_proxy_t *_js_native_global_ht = NULL;
js_type_class_t *_js_global_type_ht = NULL;
std::unordered_map<long, js_type_class_t*> _js_global_type_map;
static char *_js_log_buf = NULL;
static std::vector<sc_register_sth> registrationList;
@ -246,7 +247,7 @@ JSBool JSBCore_version(JSContext *cx, uint32_t argc, jsval *vp)
}
char version[256];
snprintf(version, sizeof(version)-1, "%s - %s", cocos2dVersion(), JSB_version);
snprintf(version, sizeof(version)-1, "%s", cocos2dVersion());
JSString * js_version = JS_InternString(cx, version);
jsval ret = STRING_TO_JSVAL(js_version);
@ -377,7 +378,7 @@ void ScriptingCore::string_report(jsval val) {
LOGD("val : return string is NULL");
} else {
JSStringWrapper wrapper(str);
LOGD("val : return string =\n%s\n", (char *)wrapper);
LOGD("val : return string =\n%s\n", wrapper.get());
}
} else if (JSVAL_IS_NUMBER(val)) {
double number;
@ -605,14 +606,13 @@ void ScriptingCore::cleanup()
_js_log_buf = NULL;
}
js_type_class_t* current, *tmp;
HASH_ITER(hh, _js_global_type_ht, current, tmp)
for (auto iter = _js_global_type_map.begin(); iter != _js_global_type_map.end(); ++iter)
{
HASH_DEL(_js_global_type_ht, current);
free(current->jsclass);
free(current);
free(iter->second->jsclass);
free(iter->second);
}
HASH_CLEAR(hh, _js_global_type_ht);
_js_global_type_map.clear();
}
void ScriptingCore::reportError(JSContext *cx, const char *message, JSErrorReport *report)
@ -631,7 +631,7 @@ JSBool ScriptingCore::log(JSContext* cx, uint32_t argc, jsval *vp)
JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string);
if (string) {
JSStringWrapper wrapper(string);
js_log("%s", (char *)wrapper);
js_log("%s", wrapper.get());
}
}
return JS_TRUE;
@ -671,14 +671,14 @@ JSBool ScriptingCore::executeScript(JSContext *cx, uint32_t argc, jsval *vp)
// js::RootedObject* rootedGlobal = globals[name];
JSObject* debugObj = ScriptingCore::getInstance()->getDebugGlobal();
if (debugObj) {
res = ScriptingCore::getInstance()->runScript(path, debugObj);
res = ScriptingCore::getInstance()->runScript(path.get(), debugObj);
} else {
JS_ReportError(cx, "Invalid global object: %s", (char*)name);
JS_ReportError(cx, "Invalid global object: %s", name.get());
return JS_FALSE;
}
} else {
JSObject* glob = JS::CurrentGlobalOrNull(cx);
res = ScriptingCore::getInstance()->runScript(path, glob);
res = ScriptingCore::getInstance()->runScript(path.get(), glob);
}
return res;
}
@ -764,12 +764,7 @@ void ScriptingCore::resumeSchedulesAndActions(js_proxy_t* p)
void ScriptingCore::cleanupSchedulesAndActions(js_proxy_t* p)
{
Array * arr = JSCallFuncWrapper::getTargetForNativeNode((Node*)p->ptr);
if (arr) {
arr->removeAllObjects();
}
arr = JSScheduleWrapper::getTargetForJSObject(p->obj);
Array* arr = JSScheduleWrapper::getTargetForJSObject(p->obj);
if (arr) {
Scheduler* pScheduler = Director::getInstance()->getScheduler();
Object* pObj = NULL;
@ -1297,7 +1292,7 @@ JSBool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, Array** r
else if (JSVAL_IS_STRING(*vp))
{
JSStringWrapper str(JSVAL_TO_STRING(*vp), cx);
pArray->addObject(String::create(str));
pArray->addObject(String::create(str.get()));
}
else
{
@ -2373,9 +2368,11 @@ JSBool jsval_to_FontDefinition( JSContext *cx, jsval vp, FontDefinition *out )
JS_GetProperty(cx, jsobj, "fontName", &jsr);
JS_ValueToString(cx, jsr);
JSStringWrapper wrapper(jsr);
if ( wrapper )
const char* fontName = wrapper.get();
if (fontName && strlen(fontName) > 0)
{
out->_fontName = (char*)wrapper;
out->_fontName = fontName;
}
else
{
@ -2539,3 +2536,59 @@ JSBool jsval_to_FontDefinition( JSContext *cx, jsval vp, FontDefinition *out )
// we are done here
return JS_TRUE;
}
// JSStringWrapper
JSStringWrapper::JSStringWrapper()
: _buffer(nullptr)
{
}
JSStringWrapper::JSStringWrapper(JSString* str, JSContext* cx/* = NULL*/)
: _buffer(nullptr)
{
set(str, cx);
}
JSStringWrapper::JSStringWrapper(jsval val, JSContext* cx/* = NULL*/)
: _buffer(nullptr)
{
set(val, cx);
}
JSStringWrapper::~JSStringWrapper()
{
CC_SAFE_DELETE_ARRAY(_buffer);
}
void JSStringWrapper::set(jsval val, JSContext* cx)
{
if (val.isString())
{
this->set(val.toString(), cx);
}
else
{
CC_SAFE_DELETE_ARRAY(_buffer);
}
}
void JSStringWrapper::set(JSString* str, JSContext* cx)
{
CC_SAFE_DELETE_ARRAY(_buffer);
if (!cx)
{
cx = ScriptingCore::getInstance()->getGlobalContext();
}
// JS_EncodeString isn't supported in SpiderMonkey ff19.0.
//buffer = JS_EncodeString(cx, string);
unsigned short* pStrUTF16 = (unsigned short*)JS_GetStringCharsZ(cx, str);
_buffer = cc_utf16_to_utf8(pStrUTF16, -1, NULL, NULL);
}
const char* JSStringWrapper::get()
{
return _buffer ? _buffer : "";
}

View File

@ -248,54 +248,20 @@ JSObject* NewGlobalObject(JSContext* cx, bool debug = false);
// just a simple utility to avoid mem leaking when using JSString
class JSStringWrapper
{
JSString* string;
const char* buffer;
public:
JSStringWrapper() {
buffer = NULL;
}
JSStringWrapper(JSString* str, JSContext* cx = NULL) {
set(str, cx);
}
JSStringWrapper(jsval val, JSContext* cx = NULL) {
set(val, cx);
}
~JSStringWrapper() {
if (buffer) {
//JS_free(ScriptingCore::getInstance()->getGlobalContext(), (void*)buffer);
delete[] buffer;
}
}
void set(jsval val, JSContext* cx) {
if (val.isString()) {
this->set(val.toString(), cx);
} else {
buffer = NULL;
}
}
void set(JSString* str, JSContext* cx) {
string = str;
if (!cx) {
cx = ScriptingCore::getInstance()->getGlobalContext();
}
// JS_EncodeString isn't supported in SpiderMonkey ff19.0.
//buffer = JS_EncodeString(cx, string);
unsigned short* pStrUTF16 = (unsigned short*)JS_GetStringCharsZ(cx, str);
buffer = cc_utf16_to_utf8(pStrUTF16, -1, NULL, NULL);
}
std::string get() {
return buffer;
}
JSStringWrapper();
JSStringWrapper(JSString* str, JSContext* cx = NULL);
JSStringWrapper(jsval val, JSContext* cx = NULL);
~JSStringWrapper();
void set(jsval val, JSContext* cx);
void set(JSString* str, JSContext* cx);
const char* get();
operator std::string() {
return std::string(buffer);
}
operator char*() {
return (char*)buffer;
}
private:
/* Copy and assignment are not supported. */
const char* _buffer;
/* Copy and assignment are not supported. */
JSStringWrapper(const JSStringWrapper &another);
JSStringWrapper &operator=(const JSStringWrapper &another);
};

View File

@ -42,9 +42,13 @@ static JSBool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
T* cobj = new T();
cobj->autorelease();
js_type_class_t *p;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
assert(p);
long typeId = t.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
p = typeMapIter->second;
CCASSERT(p, "The value is null.");
JSObject *_tmp = JS_NewObject(cx, p->jsclass, p->proto, p->parentProto);
js_proxy_t *pp = jsb_new_proxy(cobj, _tmp);
JS_AddObjectRoot(cx, &pp->obj);
@ -179,10 +183,14 @@ JSBool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_
do {
if (ret) {
TypeTest<PhysicsDebugNode> t;
js_type_class_t *typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
js_type_class_t *typeClass = nullptr;
long typeId = t.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
jsret = OBJECT_TO_JSVAL(obj);
js_proxy_t *p = jsb_new_proxy(ret, obj);
@ -265,24 +273,27 @@ void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JSObject* globalObj, cons
};
TypeTest<cocos2d::DrawNode> t1;
js_type_class_t *typeClass;
uint32_t typeId = t1.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
js_type_class_t *typeClass = nullptr;
long typeId = t1.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSB_CCPhysicsDebugNode_object = JS_InitClass(cx, globalObj, typeClass->proto, JSB_CCPhysicsDebugNode_class, dummy_constructor<PhysicsDebugNode>, 0,properties,funcs,NULL,st_funcs);
TypeTest<PhysicsDebugNode> t;
js_type_class_t *p;
typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
if (!p) {
if (_js_global_type_map.find(typeId) == _js_global_type_map.end())
{
p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
p->type = typeId;
p->jsclass = JSB_CCPhysicsDebugNode_class;
p->proto = JSB_CCPhysicsDebugNode_object;
p->parentProto = typeClass->proto;
HASH_ADD_INT(_js_global_type_ht, type, p);
_js_global_type_map.insert(std::make_pair(typeId, p));
}
}
@ -305,10 +316,13 @@ JSBool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32
do {
if (ret) {
TypeTest<PhysicsSprite> t;
js_type_class_t *typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
js_type_class_t *typeClass = nullptr;
long typeId = t.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
jsret = OBJECT_TO_JSVAL(obj);
js_proxy_t *p = jsb_new_proxy(ret, obj);
@ -331,10 +345,12 @@ JSBool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32
do {
if (ret) {
TypeTest<PhysicsSprite> t;
js_type_class_t *typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
js_type_class_t *typeClass = nullptr;
long typeId = t.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
jsret = OBJECT_TO_JSVAL(obj);
js_proxy_t *p = jsb_new_proxy(ret, obj);
@ -370,10 +386,12 @@ JSBool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrame__static(JSContext *cx, uint
do {
if (ret) {
TypeTest<PhysicsSprite> t;
js_type_class_t *typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
js_type_class_t *typeClass = nullptr;
long typeId = t.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
jsret = OBJECT_TO_JSVAL(obj);
js_proxy_t *p = jsb_new_proxy(ret, obj);
@ -393,29 +411,35 @@ JSBool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx,
JSBool ok = JS_TRUE;
const char* arg0;
std::string arg0_tmp;
if (argc >= 1) {
if (argc == 1) {
ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str();
}
PhysicsSprite* ret = PhysicsSprite::createWithSpriteFrameName(arg0);
jsval jsret;
do {
if (ret) {
TypeTest<PhysicsSprite> t;
js_type_class_t *typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
jsret = OBJECT_TO_JSVAL(obj);
js_proxy_t *p = jsb_new_proxy(ret, obj);
JS_AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite");
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
PhysicsSprite* ret = PhysicsSprite::createWithSpriteFrameName(arg0);
jsval jsret;
do {
if (ret) {
TypeTest<PhysicsSprite> t;
js_type_class_t *typeClass = nullptr;
long typeId = t.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
jsret = OBJECT_TO_JSVAL(obj);
js_proxy_t *p = jsb_new_proxy(ret, obj);
JS_AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite");
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JSObject* globalObj)
@ -450,24 +474,25 @@ void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JSObject* globalObj)
};
TypeTest<cocos2d::Sprite> t1;
js_type_class_t *typeClass;
uint32_t typeId = t1.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
js_type_class_t *typeClass = nullptr;
long typeId = t1.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSPROXY_CCPhysicsSprite_object = JS_InitClass(cx, globalObj, typeClass->proto, JSPROXY_CCPhysicsSprite_class, dummy_constructor<PhysicsSprite>, 0,properties,funcs,NULL,st_funcs);
TypeTest<PhysicsSprite> t;
js_type_class_t *p;
typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
if (!p) {
if (_js_global_type_map.find(typeId) == _js_global_type_map.end())
{
p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
p->type = typeId;
p->jsclass = JSPROXY_CCPhysicsSprite_class;
p->proto = JSPROXY_CCPhysicsSprite_object;
p->parentProto = typeClass->proto;
HASH_ADD_INT(_js_global_type_ht, type, p);
_js_global_type_map.insert(std::make_pair(typeId, p));
}
}

View File

@ -1 +1 @@
927efea93a520eeb9db9f62c8d8eb7a7b93b08dc
36a6cc6177c059364c6ccc3b1151b6475219b396

View File

@ -39,14 +39,23 @@ extern callfuncTarget_proxy_t *_callfuncTarget_native_ht;
*/
template <class T>
inline js_type_class_t *js_get_type_from_native(T* native_obj) {
js_type_class_t *typeProxy;
bool found = false;
long typeId = typeid(*native_obj).hash_code();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy);
if (!typeProxy) {
auto typeProxyIter = _js_global_type_map.find(typeId);
if (typeProxyIter == _js_global_type_map.end())
{
typeId = typeid(T).hash_code();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy);
typeProxyIter = _js_global_type_map.find(typeId);
if (typeProxyIter != _js_global_type_map.end())
{
found = true;
}
}
return typeProxy;
else
{
found = true;
}
return found ? typeProxyIter->second : nullptr;
}
/**
@ -101,19 +110,6 @@ protected:
jsval _extraData;
};
class JSCallFuncWrapper: public JSCallbackWrapper {
public:
JSCallFuncWrapper() {}
virtual ~JSCallFuncWrapper(void) {
return;
}
static void setTargetForNativeNode(Node *pNode, JSCallFuncWrapper *target);
static Array * getTargetForNativeNode(Node *pNode);
void callbackFunc(Node *node);
};
class JSScheduleWrapper: public JSCallbackWrapper {

View File

@ -43,17 +43,6 @@ typedef struct _hashJSObject
static tHashJSObject *hash = NULL;
static tHashJSObject *reverse_hash = NULL;
// Globals
char* JSB_association_proxy_key = NULL;
const char* JSB_version = "0.3-beta";
static void its_finalize(JSFreeOp *fop, JSObject *obj)
{
CCLOGINFO("Finalizing global class");
}
//#pragma mark JSBCore - Helper free functions
static void reportError(JSContext *cx, const char *message, JSErrorReport *report)
{
@ -68,7 +57,7 @@ static void reportError(JSContext *cx, const char *message, JSErrorReport *repor
void* jsb_get_proxy_for_jsobject(JSObject *obj)
{
tHashJSObject *element = NULL;
HASH_FIND_INT(hash, &obj, element);
HASH_FIND_PTR(hash, &obj, element);
if( element )
return element->proxy;
@ -88,13 +77,13 @@ void jsb_set_proxy_for_jsobject(void *proxy, JSObject *obj)
element->proxy = proxy;
element->jsObject = obj;
HASH_ADD_INT( hash, jsObject, element );
HASH_ADD_PTR( hash, jsObject, element );
}
void jsb_del_proxy_for_jsobject(JSObject *obj)
{
tHashJSObject *element = NULL;
HASH_FIND_INT(hash, &obj, element);
HASH_FIND_PTR(hash, &obj, element);
if( element ) {
HASH_DEL(hash, element);
free(element);
@ -107,7 +96,7 @@ void jsb_del_proxy_for_jsobject(JSObject *obj)
JSObject* jsb_get_jsobject_for_proxy(void *proxy)
{
tHashJSObject *element = NULL;
HASH_FIND_INT(reverse_hash, &proxy, element);
HASH_FIND_PTR(reverse_hash, &proxy, element);
if( element )
return element->jsObject;
@ -123,13 +112,13 @@ void jsb_set_jsobject_for_proxy(JSObject *jsobj, void* proxy)
element->proxy = proxy;
element->jsObject = jsobj;
HASH_ADD_INT( reverse_hash, proxy, element );
HASH_ADD_PTR( reverse_hash, proxy, element );
}
void jsb_del_jsobject_for_proxy(void* proxy)
{
tHashJSObject *element = NULL;
HASH_FIND_INT(reverse_hash, &proxy, element);
HASH_FIND_PTR(reverse_hash, &proxy, element);
if( element ) {
HASH_DEL(reverse_hash, element);
free(element);

View File

@ -30,10 +30,6 @@
#include "chipmunk.h"
#include "SimpleAudioEngine.h"
// Globals
// one shared key for associations
extern char * JSB_association_proxy_key;
#ifdef __cplusplus
extern "C" {
#endif
@ -77,7 +73,6 @@ extern "C" {
// needed for callbacks. It does nothing.
JSBool JSB_do_nothing(JSContext *cx, uint32_t argc, jsval *vp);
extern const char* JSB_version;
#ifdef __cplusplus
}
#endif

View File

@ -32,24 +32,27 @@ JSBool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 0) {
GLNode* cobj = new GLNode();
#ifdef COCOS2D_JAVASCRIPT
cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj);
if (_ccobj) {
_ccobj->autorelease();
}
#endif
TypeTest<GLNode> t;
js_type_class_t *typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
js_type_class_t *typeClass = nullptr;
long typeId = t.s_id();
auto typeMapIter = _js_global_type_map.find(typeId);
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
typeClass = typeMapIter->second;
CCASSERT(typeClass, "The value is null.");
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
// link the native object with the javascript object
js_proxy_t *p = jsb_new_proxy(cobj, obj);
#ifdef COCOS2D_JAVASCRIPT
JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode");
#endif
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
@ -131,14 +134,13 @@ void js_register_cocos2dx_GLNode(JSContext *cx, JSObject *global) {
// add the proto and JSClass to the type->js info hash table
TypeTest<GLNode> t;
js_type_class_t *p;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
if (!p) {
long typeId = t.s_id();
if (_js_global_type_map.find(typeId) == _js_global_type_map.end())
{
p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
p->type = typeId;
p->jsclass = js_cocos2dx_GLNode_class;
p->proto = js_cocos2dx_GLNode_prototype;
p->parentProto = jsb_Node_prototype;
HASH_ADD_INT(_js_global_type_ht, type, p);
_js_global_type_map.insert(std::make_pair(typeId, p));
}
}

View File

@ -609,8 +609,8 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, open)
JSStringWrapper w1(jsMethod);
JSStringWrapper w2(jsURL);
method = w1;
urlstr = w2;
method = w1.get();
urlstr = w2.get();
_url = urlstr;
_meth = method;
@ -771,8 +771,8 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, setRequestHeader)
JSStringWrapper w1(jsField);
JSStringWrapper w2(jsValue);
field = w1;
value = w2;
field = w1.get();
value = w2.get();
// Populate the request_header map.
_setRequestHeader(field, value);

View File

@ -3,6 +3,7 @@
#include "jsapi.h"
#include "uthash.h"
#include <unordered_map>
typedef struct js_proxy {
void *ptr;
@ -14,20 +15,18 @@ extern js_proxy_t *_native_js_global_ht;
extern js_proxy_t *_js_native_global_ht;
typedef struct js_type_class {
uint32_t type;
JSClass *jsclass;
JSObject *proto;
JSObject *parentProto;
UT_hash_handle hh;
} js_type_class_t;
extern js_type_class_t *_js_global_type_ht;
extern std::unordered_map<long, js_type_class_t*> _js_global_type_map;
template< typename DERIVED >
class TypeTest
{
public:
static int s_id()
static long s_id()
{
// return id unique for DERIVED
// NOT SURE IT WILL BE REALLY UNIQUE FOR EACH CLASS!!

View File

@ -283,6 +283,30 @@ bool luaval_to_point(lua_State* L,int lo,Point* outValue)
return ok;
}
bool luaval_to_long(lua_State* L,int lo, long* outValue)
{
if (NULL == L || NULL == outValue)
return false;
bool ok = true;
tolua_Error tolua_err;
if (!tolua_isnumber(L,lo,0,&tolua_err))
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err);
#endif
ok = false;
}
if (ok)
{
*outValue = (long)tolua_tonumber(L, lo, 0);
}
return ok;
}
bool luaval_to_size(lua_State* L,int lo,Size* outValue)
{
if (NULL == L || NULL == outValue)

View File

@ -30,6 +30,7 @@ extern bool luaval_to_boolean(lua_State* L,int lo,bool* outValue);
extern bool luaval_to_number(lua_State* L,int lo,double* outValue);
extern bool luaval_to_long_long(lua_State* L,int lo,long long* outValue);
extern bool luaval_to_std_string(lua_State* L, int lo, std::string* outValue);
extern bool luaval_to_long(lua_State* L,int lo, long* outValue);
extern bool luaval_to_point(lua_State* L,int lo,Point* outValue);
extern bool luaval_to_size(lua_State* L,int lo,Size* outValue);

View File

@ -9,7 +9,7 @@ TOLUA_API void toluafix_open(lua_State* L)
lua_pushstring(L, TOLUA_REFID_PTR_MAPPING);
lua_newtable(L);
lua_rawset(L, LUA_REGISTRYINDEX);
lua_pushstring(L, TOLUA_REFID_TYPE_MAPPING);
lua_newtable(L);
lua_rawset(L, LUA_REGISTRYINDEX);
@ -30,29 +30,29 @@ TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L,
lua_pushnil(L);
return -1;
}
if (*p_refid == 0)
{
*p_refid = refid;
lua_pushstring(L, TOLUA_REFID_PTR_MAPPING);
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: refid_ptr */
lua_pushinteger(L, refid); /* stack: refid_ptr refid */
lua_pushlightuserdata(L, ptr); /* stack: refid_ptr refid ptr */
lua_rawset(L, -3); /* refid_ptr[refid] = ptr, stack: refid_ptr */
lua_pop(L, 1); /* stack: - */
lua_pushstring(L, TOLUA_REFID_TYPE_MAPPING);
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: refid_type */
lua_pushinteger(L, refid); /* stack: refid_type refid */
lua_pushstring(L, type); /* stack: refid_type refid type */
lua_rawset(L, -3); /* refid_type[refid] = type, stack: refid_type */
lua_pop(L, 1); /* stack: - */
//printf("[LUA] push CCObject OK - refid: %d, ptr: %x, type: %s\n", *p_refid, (int)ptr, type);
}
tolua_pushusertype(L, ptr, type);
return 0;
}
@ -63,7 +63,7 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid)
const char* type = NULL;
void** ud = NULL;
if (refid == 0) return -1;
// get ptr from tolua_refid_ptr_mapping
lua_pushstring(L, TOLUA_REFID_PTR_MAPPING);
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: refid_ptr */
@ -78,14 +78,14 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid)
// printf("[LUA ERROR] remove CCObject with NULL ptr, refid: %d\n", refid);
return -2;
}
// remove ptr from tolua_refid_ptr_mapping
lua_pushinteger(L, refid); /* stack: refid_ptr refid */
lua_pushnil(L); /* stack: refid_ptr refid nil */
lua_rawset(L, -3); /* delete refid_ptr[refid], stack: refid_ptr */
lua_pop(L, 1); /* stack: - */
// get type from tolua_refid_type_mapping
lua_pushstring(L, TOLUA_REFID_TYPE_MAPPING);
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: refid_type */
@ -97,16 +97,16 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid)
printf("[LUA ERROR] remove CCObject with NULL type, refid: %d, ptr: %p\n", refid, ptr);
return -1;
}
type = lua_tostring(L, -1);
lua_pop(L, 1); /* stack: refid_type */
// remove type from tolua_refid_type_mapping
lua_pushinteger(L, refid); /* stack: refid_type refid */
lua_pushnil(L); /* stack: refid_type refid nil */
lua_rawset(L, -3); /* delete refid_type[refid], stack: refid_type */
lua_pop(L, 1); /* stack: - */
// get ubox
luaL_getmetatable(L, type); /* stack: mt */
lua_pushstring(L, "tolua_ubox"); /* stack: mt key */
@ -118,7 +118,7 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid)
lua_pushstring(L, "tolua_ubox"); /* stack: mt key */
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: mt ubox */
};
lua_pushlightuserdata(L, ptr); /* stack: mt ubox ptr */
lua_rawget(L,-2); /* stack: mt ubox ud */
if (lua_isnil(L, -1))
@ -128,7 +128,11 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid)
lua_pop(L, 3);
return -3;
}
// cleanup peertable
lua_pushvalue(L, LUA_REGISTRYINDEX);
lua_setfenv(L, -2);
ud = (void**)lua_touserdata(L, -1);
lua_pop(L, 1); /* stack: mt ubox */
if (ud == NULL)
@ -137,14 +141,14 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid)
lua_pop(L, 2);
return -1;
}
// clean userdata
*ud = NULL;
lua_pushlightuserdata(L, ptr); /* stack: mt ubox ptr */
lua_pushnil(L); /* stack: mt ubox ptr nil */
lua_rawset(L, -3); /* ubox[ptr] = nil, stack: mt ubox */
lua_pop(L, 2);
//printf("[LUA] remove CCObject, refid: %d, ptr: %x, type: %s\n", refid, (int)ptr, type);
return 0;
@ -154,19 +158,19 @@ TOLUA_API int toluafix_ref_function(lua_State* L, int lo, int def)
{
// function at lo
if (!lua_isfunction(L, lo)) return 0;
s_function_ref_id++;
lua_pushstring(L, TOLUA_REFID_FUNCTION_MAPPING);
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: fun ... refid_fun */
lua_pushinteger(L, s_function_ref_id); /* stack: fun ... refid_fun refid */
lua_pushvalue(L, lo); /* stack: fun ... refid_fun refid fun */
lua_rawset(L, -3); /* refid_fun[refid] = fun, stack: fun ... refid_ptr */
lua_pop(L, 1); /* stack: fun ... */
return s_function_ref_id;
// lua_pushvalue(L, lo); /* stack: ... func */
// return luaL_ref(L, LUA_REGISTRYINDEX);
}

0
cocos/scripting/lua/script/json.lua Executable file → Normal file
View File

View File

@ -1 +1 @@
55fe4bd3605531a58a565c46eec20dee0f81ff97
f86eb12e6d4835f93bd6f59d860970bcd2f74128

View File

@ -33,7 +33,7 @@ class SortedObject : public Object, public SortableObject
{
public:
SortedObject() : objectID(0) {}
virtual void setObjectID(unsigned int objectID) { this->objectID = objectID; }
virtual void setObjectID(unsigned int id) { this->objectID = id; }
virtual unsigned int getObjectID() { return objectID; }
private:
unsigned int objectID;

View File

@ -214,7 +214,7 @@ void AssetsManager::downloadAndUncompress()
_isDownloading = false;
}
void AssetsManager::update()
void AssetsManager::update(float delta)
{
if (_isDownloading) return;
@ -651,8 +651,8 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version
class DelegateProtocolImpl : public AssetsManagerDelegateProtocol
{
public :
DelegateProtocolImpl(ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback)
: errorCallback(errorCallback), progressCallback(progressCallback), successCallback(successCallback)
DelegateProtocolImpl(ErrorCallback aErrorCallback, ProgressCallback aProgressCallback, SuccessCallback aSuccessCallback)
: errorCallback(aErrorCallback), progressCallback(aProgressCallback), successCallback(aSuccessCallback)
{}
virtual void onError(AssetsManager::ErrorCode errorCode) { errorCallback(int(errorCode)); }

View File

@ -98,7 +98,7 @@ public:
/* @brief Download new package if there is a new version, and uncompress downloaded zip file.
* Ofcourse it will set search path that stores downloaded files.
*/
virtual void update();
virtual void update(float delta) override;
/* @brief Gets url of package.
*/

View File

@ -21,6 +21,7 @@ AccelerometerTest::AccelerometerTest(void)
AccelerometerTest::~AccelerometerTest(void)
{
_ball->release();
Device::setAccelerometerEnabled(false);
}
std::string AccelerometerTest::title()
@ -32,6 +33,7 @@ void AccelerometerTest::onEnter()
{
Layer::onEnter();
Device::setAccelerometerEnabled(true);
auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(AccelerometerTest::onAcceleration, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

View File

@ -29,7 +29,7 @@ Box2DTestLayer::Box2DTestLayer()
_spriteTexture = parent->getTexture();
#else
// doesn't use batch node. Slower
_spriteTexture = TextureCache::getInstance()->addImage("Images/blocks.png");
_spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/blocks.png");
auto parent = Node::create();
#endif
addChild(parent, 0, kTagParentNode);

View File

@ -10,6 +10,11 @@
// Bug624Layer
//
////////////////////////////////////////////////////////
Bug624Layer::~Bug624Layer()
{
Device::setAccelerometerEnabled(false);
}
bool Bug624Layer::init()
{
if(BugsTestBaseLayer::init())
@ -20,6 +25,7 @@ bool Bug624Layer::init()
label->setPosition(Point(size.width/2, size.height/2));
addChild(label);
Device::setAccelerometerEnabled(true);
auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(Bug624Layer::onAcceleration, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
@ -50,6 +56,11 @@ void Bug624Layer::onAcceleration(Acceleration* acc, Event* event)
// Bug624Layer2
//
////////////////////////////////////////////////////////
Bug624Layer2::~Bug624Layer2()
{
Device::setAccelerometerEnabled(false);
}
bool Bug624Layer2::init()
{
if(BugsTestBaseLayer::init())
@ -60,6 +71,7 @@ bool Bug624Layer2::init()
label->setPosition(Point(size.width/2, size.height/2));
addChild(label);
Device::setAccelerometerEnabled(true);
auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(Bug624Layer2::onAcceleration, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

View File

@ -6,6 +6,7 @@
class Bug624Layer : public BugsTestBaseLayer
{
public:
virtual ~Bug624Layer();
virtual bool init();
void switchLayer(float dt);
virtual void onAcceleration(Acceleration* acc, Event* event);
@ -16,6 +17,7 @@ public:
class Bug624Layer2 : public BugsTestBaseLayer
{
public:
virtual ~Bug624Layer2();
virtual bool init();
void switchLayer(float dt);
virtual void onAcceleration(Acceleration* acc, Event* event);

View File

@ -26,6 +26,7 @@ ChipmunkTestLayer::ChipmunkTestLayer()
touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTestLayer::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
Device::setAccelerometerEnabled(true);
auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTestLayer::onAcceleration, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(accListener, this);
@ -46,7 +47,7 @@ ChipmunkTestLayer::ChipmunkTestLayer()
_spriteTexture = parent->getTexture();
#else
// doesn't use batch node. Slower
_spriteTexture = TextureCache::getInstance()->addImage("Images/grossini_dance_atlas.png");
_spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png");
auto parent = Node::create();
#endif
addChild(parent, 0, kTagParentNode);
@ -90,6 +91,8 @@ ChipmunkTestLayer::~ChipmunkTestLayer()
}
cpSpaceFree( _space );
Device::setAccelerometerEnabled(false);
}

View File

@ -107,7 +107,7 @@ bool BaseClippingNodeTest::init()
BaseClippingNodeTest::~BaseClippingNodeTest()
{
TextureCache::getInstance()->removeUnusedTextures();
Director::getInstance()->getTextureCache()->removeUnusedTextures();
}
std::string BaseClippingNodeTest::title()

View File

@ -71,7 +71,7 @@ void PrettyPrinterDemo::onEnter()
vistor.clear();
addSprite();
// dict = TextureCache::getInstance()->snapshotTextures();
// dict = Director::getInstance()->getTextureCache()->snapshotTextures();
// dict->acceptVisitor(vistor);
// log("%s", vistor.getResult().c_str());
}

View File

@ -16,7 +16,7 @@ IntervalLayer::IntervalLayer()
auto s = Director::getInstance()->getWinSize();
// sun
auto sun = ParticleSun::create();
sun->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
sun->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
sun->setPosition( Point(VisibleRect::rightTop().x-32,VisibleRect::rightTop().y-32) );
sun->setTotalParticles(130);

View File

@ -359,7 +359,7 @@ void StressTest1::shouldNotCrash(float dt)
// if the node has timers, it crashes
auto explosion = ParticleSun::create();
explosion->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
explosion->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
// if it doesn't, it works Ok.
// auto explosion = [Sprite create:@"grossinis_sister2.png");
@ -409,7 +409,7 @@ StressTest2::StressTest2()
sublayer->addChild(sp1, 1);
auto fire = ParticleFire::create();
fire->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
fire->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
fire->setPosition( Point(80, s.height/2-50) );
auto copy_seq3 = seq3->clone();

View File

@ -22,7 +22,7 @@ void DemoFirework::onEnter()
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_stars1) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
setEmitterPosition();
}
@ -46,7 +46,7 @@ void DemoFire::onEnter()
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );//.pvr");
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );//.pvr");
auto p = _emitter->getPosition();
_emitter->setPosition( Point(p.x, 100) );
@ -71,7 +71,7 @@ void DemoSun::onEnter()
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
setEmitterPosition();
}
@ -94,7 +94,7 @@ void DemoGalaxy::onEnter()
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
setEmitterPosition();
}
@ -116,7 +116,7 @@ void DemoFlower::onEnter()
_emitter = ParticleFlower::create();
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_stars1) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
setEmitterPosition();
}
@ -141,7 +141,7 @@ void DemoBigFlower::onEnter()
_background->addChild(_emitter, 10);
////_emitter->release(); // win32 : use this line or remove this line and use autorelease()
_emitter->setTexture( TextureCache::getInstance()->addImage(s_stars1) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
_emitter->setDuration(-1);
@ -225,7 +225,7 @@ void DemoRotFlower::onEnter()
_background->addChild(_emitter, 10);
////_emitter->release(); // win32 : Remove this line
_emitter->setTexture( TextureCache::getInstance()->addImage(s_stars2) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars2) );
// duration
_emitter->setDuration(-1);
@ -308,7 +308,7 @@ void DemoMeteor::onEnter()
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
setEmitterPosition();
}
@ -331,7 +331,7 @@ void DemoSpiral::onEnter()
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
setEmitterPosition();
}
@ -354,7 +354,7 @@ void DemoExplosion::onEnter()
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_stars1) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
_emitter->setAutoRemoveOnFinish(true);
@ -378,7 +378,7 @@ void DemoSmoke::onEnter()
_emitter = ParticleSmoke::create();
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
auto p = _emitter->getPosition();
_emitter->setPosition( Point( p.x, 100) );
@ -429,7 +429,7 @@ void DemoSnow::onEnter()
_emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife());
_emitter->setTexture( TextureCache::getInstance()->addImage(s_snow) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_snow) );
setEmitterPosition();
}
@ -456,7 +456,7 @@ void DemoRain::onEnter()
_emitter->setPosition( Point( p.x, p.y-100) );
_emitter->setLife(4);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
setEmitterPosition();
}
@ -540,7 +540,7 @@ void DemoModernArt::onEnter()
_emitter->setEndSizeVar(8.0f);
// texture
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
// additive
_emitter->setBlendAdditive(false);
@ -567,7 +567,7 @@ void DemoRing::onEnter()
_background->addChild(_emitter, 10);
_emitter->setTexture( TextureCache::getInstance()->addImage(s_stars1) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
_emitter->setLifeVar(0);
_emitter->setLife(10);
_emitter->setSpeed(100);
@ -605,14 +605,14 @@ void ParallaxParticle::onEnter()
_emitter = ParticleFlower::create();
_emitter->retain();
_emitter->setTexture( TextureCache::getInstance()->addImage(s_fire) );
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
p1->addChild(_emitter, 10);
_emitter->setPosition( Point(250,200) );
auto par = ParticleSun::create();
p2->addChild(par, 10);
par->setTexture( TextureCache::getInstance()->addImage(s_fire) );
par->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
auto move = MoveBy::create(4, Point(300,0));
auto move_back = move->reverse();
@ -641,7 +641,7 @@ void RadiusMode1::onEnter()
_emitter = new ParticleSystemQuad();
_emitter->initWithTotalParticles(200);
addChild(_emitter, 10);
_emitter->setTexture(TextureCache::getInstance()->addImage("Images/stars-grayscale.png"));
_emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars-grayscale.png"));
// duration
_emitter->setDuration(ParticleSystem::DURATION_INFINITY);
@ -725,7 +725,7 @@ void RadiusMode2::onEnter()
_emitter = new ParticleSystemQuad();
_emitter->initWithTotalParticles(200);
addChild(_emitter, 10);
_emitter->setTexture(TextureCache::getInstance()->addImage("Images/stars-grayscale.png"));
_emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars-grayscale.png"));
// duration
_emitter->setDuration(ParticleSystem::DURATION_INFINITY);
@ -809,7 +809,7 @@ void Issue704::onEnter()
_emitter = new ParticleSystemQuad();
_emitter->initWithTotalParticles(100);
addChild(_emitter, 10);
_emitter->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
_emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
// duration
_emitter->setDuration(ParticleSystem::DURATION_INFINITY);
@ -900,7 +900,7 @@ void Issue870::onEnter()
auto system = new ParticleSystemQuad();
system->initWithFile("Particles/SpinningPeas.plist");
system->setTextureWithRect(TextureCache::getInstance()->addImage("Images/particles.png"), Rect(0,0,32,32));
system->setTextureWithRect(Director::getInstance()->getTextureCache()->addImage("Images/particles.png"), Rect(0,0,32,32));
addChild(system, 10);
_emitter = system;
@ -1452,7 +1452,7 @@ bool RainbowEffect::initWithTotalParticles(unsigned int numberOfParticles)
_endColorVar.b = 0.0f;
_endColorVar.a = 0.0f;
setTexture(TextureCache::getInstance()->addImage("Images/particles.png"));
setTexture(Director::getInstance()->getTextureCache()->addImage("Images/particles.png"));
return true;
}
@ -1504,7 +1504,7 @@ void MultipleParticleSystems::onEnter()
removeChild(_background, true);
_background = NULL;
TextureCache::getInstance()->addImage("Images/particles.png");
Director::getInstance()->getTextureCache()->addImage("Images/particles.png");
for (int i = 0; i<5; i++) {
auto particleSystem = ParticleSystemQuad::create("Particles/SpinningPeas.plist");

View File

@ -187,8 +187,8 @@ void ParticleMainScene::createParticleSystem()
removeChildByTag(kTagParticleSystem, true);
// remove the "fire.png" from the TextureCache cache.
auto texture = TextureCache::getInstance()->addImage("Images/fire.png");
TextureCache::getInstance()->removeTexture(texture);
auto texture = Director::getInstance()->getTextureCache()->addImage("Images/fire.png");
Director::getInstance()->getTextureCache()->removeTexture(texture);
//TODO: if (subtestNumber <= 3)
// {
@ -204,42 +204,42 @@ void ParticleMainScene::createParticleSystem()
case 1:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
particleSystem->initWithTotalParticles(quantityParticles);
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
break;
case 2:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
particleSystem->initWithTotalParticles(quantityParticles);
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
break;
case 3:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8);
particleSystem->initWithTotalParticles(quantityParticles);
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
break;
// case 4:
// particleSystem->initWithTotalParticles(quantityParticles);
// ////---- particleSystem.texture = [[TextureCache sharedTextureCache] addImage:@"fire.pvr"];
// particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
// particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
// break;
case 4:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
particleSystem->initWithTotalParticles(quantityParticles);
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
break;
case 5:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
particleSystem->initWithTotalParticles(quantityParticles);
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
break;
case 6:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8);
particleSystem->initWithTotalParticles(quantityParticles);
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
break;
// case 8:
// particleSystem->initWithTotalParticles(quantityParticles);
// ////---- particleSystem.texture = [[TextureCache sharedTextureCache] addImage:@"fire.pvr"];
// particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
// particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
// break;
default:
particleSystem = NULL;

View File

@ -52,7 +52,7 @@ void SubTest::initWithSubTest(int nSubTest, Node* p)
*/
// purge textures
auto mgr = TextureCache::getInstance();
auto mgr = Director::getInstance()->getTextureCache();
// [mgr removeAllTextures];
mgr->removeTexture(mgr->addImage("Images/grossinis_sister1.png"));
mgr->removeTexture(mgr->addImage("Images/grossini_dance_atlas.png"));

View File

@ -84,7 +84,7 @@ void TextureTest::performTestsPNG(const char* filename)
{
struct timeval now;
Texture2D *texture;
auto cache = TextureCache::getInstance();
auto cache = Director::getInstance()->getTextureCache();
log("RGBA 8888");
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
@ -131,7 +131,7 @@ void TextureTest::performTests()
{
// Texture2D *texture;
// struct timeval now;
// auto cache = TextureCache::getInstance();
// auto cache = Director::getInstance()->getTextureCache();
log("--------");

View File

@ -199,6 +199,11 @@ void PhysicsDemo::toggleDebugCallback(Object* sender)
#endif
}
PhysicsDemoClickAdd::~PhysicsDemoClickAdd()
{
Device::setAccelerometerEnabled(false);
}
void PhysicsDemoClickAdd::onEnter()
{
PhysicsDemo::onEnter();
@ -209,6 +214,7 @@ void PhysicsDemoClickAdd::onEnter()
touchListener->onTouchesEnded = CC_CALLBACK_2(PhysicsDemoClickAdd::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
Device::setAccelerometerEnabled(true);
auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(PhysicsDemoClickAdd::onAcceleration, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(accListener, this);

View File

@ -56,6 +56,7 @@ protected:
class PhysicsDemoClickAdd : public PhysicsDemo
{
public:
virtual ~PhysicsDemoClickAdd();
void onEnter() override;
std::string subtitle() override;

View File

@ -156,7 +156,7 @@ void RenderTextureSave::saveImage(cocos2d::Object *sender)
auto image = _target->newImage();
auto tex = TextureCache::getInstance()->addImage(image, png);
auto tex = Director::getInstance()->getTextureCache()->addImage(image, png);
CC_SAFE_DELETE(image);
@ -176,7 +176,7 @@ RenderTextureSave::~RenderTextureSave()
{
_brush->release();
_target->release();
TextureCache::getInstance()->removeUnusedTextures();
Director::getInstance()->getTextureCache()->removeUnusedTextures();
}
void RenderTextureSave::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)

View File

@ -924,7 +924,7 @@ void SchedulerTimeScale::onEnter()
kathia->runAction(Speed::create(action3, 1.0f));
auto emitter = ParticleFireworks::create();
emitter->setTexture( TextureCache::getInstance()->addImage(s_stars1) );
emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
addChild(emitter);
_sliderCtl = sliderCtl();

View File

@ -1 +1 @@
dd564ef17f9cc0281964247923ec24957cad7bd0
c37b913119295ed7f6bcbb7e04cce322722ea1a5

View File

@ -129,18 +129,18 @@ void TextureDemo::onEnter()
{
BaseTest::onEnter();
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
auto col = LayerColor::create(Color4B(128,128,128,255));
addChild(col, -10);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
TextureDemo::~TextureDemo()
{
TextureCache::getInstance()->removeUnusedTextures();
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->removeUnusedTextures();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
void TextureDemo::restartCallback(Object* sender)
@ -191,7 +191,7 @@ void TextureTIFF::onEnter()
auto img = Sprite::create("Images/test_image.tiff");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
this->addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureTIFF::title()
@ -213,7 +213,7 @@ void TexturePNG::onEnter()
auto img = Sprite::create("Images/test_image.png");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePNG::title()
@ -234,7 +234,7 @@ void TextureJPEG::onEnter()
auto img = Sprite::create("Images/test_image.jpeg");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureJPEG::title()
@ -255,7 +255,7 @@ void TextureWEBP::onEnter()
auto img = Sprite::create("Images/test_image.webp");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureWEBP::title()
@ -273,12 +273,12 @@ void TextureMipMap::onEnter()
TextureDemo::onEnter();
auto s = Director::getInstance()->getWinSize();
auto texture0 = TextureCache::getInstance()->addImage("Images/grossini_dance_atlas.png");
auto texture0 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png");
texture0->generateMipmap();
Texture2D::TexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
texture0->setTexParameters(texParams);
auto texture1 = TextureCache::getInstance()->addImage("Images/grossini_dance_atlas_nomipmap.png");
auto texture1 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas_nomipmap.png");
auto img0 = Sprite::createWithTexture(texture0);
img0->setTextureRect(Rect(85, 121, 85, 121));
@ -299,7 +299,7 @@ void TextureMipMap::onEnter()
img0->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL)));
img1->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL)));
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureMipMap::title()
@ -350,7 +350,7 @@ void TexturePVRMipMap::onEnter()
imgMipMap->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL)));
img->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL)));
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRMipMap::title()
@ -392,7 +392,7 @@ void TexturePVRMipMap2::onEnter()
imgMipMap->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL)));
img->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL)));
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRMipMap2::title()
@ -424,7 +424,7 @@ void TexturePVR2BPP::onEnter()
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVR2BPP::title()
@ -455,7 +455,7 @@ void TexturePVRTest::onEnter()
{
log("This test is not supported.");
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
@ -487,7 +487,7 @@ void TexturePVR4BPP::onEnter()
{
log("This test is not supported in cocos2d-mac");
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVR4BPP::title()
@ -510,7 +510,7 @@ void TexturePVRRGBA8888::onEnter()
auto img = Sprite::create("Images/test_image_rgba8888.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRRGBA8888::title()
@ -540,7 +540,7 @@ void TexturePVRBGRA8888::onEnter()
{
log("BGRA8888 images are not supported");
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRBGRA8888::title()
@ -563,7 +563,7 @@ void TexturePVRRGBA5551::onEnter()
auto img = Sprite::create("Images/test_image_rgba5551.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRRGBA5551::title()
@ -586,7 +586,7 @@ void TexturePVRRGBA4444::onEnter()
auto img = Sprite::create("Images/test_image_rgba4444.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRRGBA4444::title()
@ -614,7 +614,7 @@ void TexturePVRRGBA4444GZ::onEnter()
#endif
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRRGBA4444GZ::title()
@ -642,7 +642,7 @@ void TexturePVRRGBA4444CCZ::onEnter()
auto img = Sprite::create("Images/test_image_rgba4444.pvr.ccz");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRRGBA4444CCZ::title()
@ -670,7 +670,7 @@ void TexturePVRRGB565::onEnter()
auto img = Sprite::create("Images/test_image_rgb565.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRRGB565::title()
@ -693,7 +693,7 @@ void TexturePVRRGB888::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRRGB888::title()
@ -716,7 +716,7 @@ void TexturePVRA8::onEnter()
auto img = Sprite::create("Images/test_image_a8.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
@ -740,7 +740,7 @@ void TexturePVRI8::onEnter()
auto img = Sprite::create("Images/test_image_i8.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRI8::title()
@ -763,7 +763,7 @@ void TexturePVRAI88::onEnter()
auto img = Sprite::create("Images/test_image_ai88.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRAI88::title()
@ -785,7 +785,7 @@ void TexturePVR2BPPv3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVR2BPPv3::title()
@ -812,7 +812,7 @@ void TexturePVRII2BPPv3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRII2BPPv3::title()
@ -843,7 +843,7 @@ void TexturePVR4BPPv3::onEnter()
log("This test is not supported");
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVR4BPPv3::title()
@ -878,7 +878,7 @@ void TexturePVRII4BPPv3::onEnter()
log("This test is not supported");
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRII4BPPv3::title()
@ -905,7 +905,7 @@ void TexturePVRRGBA8888v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRRGBA8888v3::title()
@ -936,7 +936,7 @@ void TexturePVRBGRA8888v3::onEnter()
log("BGRA images are not supported");
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRBGRA8888v3::title()
@ -963,7 +963,7 @@ void TexturePVRRGBA5551v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRRGBA5551v3::title()
@ -990,7 +990,7 @@ void TexturePVRRGBA4444v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRRGBA4444v3::title()
@ -1017,7 +1017,7 @@ void TexturePVRRGB565v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRRGB565v3::title()
@ -1044,7 +1044,7 @@ void TexturePVRRGB888v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRRGB888v3::title()
@ -1071,7 +1071,7 @@ void TexturePVRA8v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRA8v3::title()
@ -1098,7 +1098,7 @@ void TexturePVRI8v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRI8v3::title()
@ -1125,7 +1125,7 @@ void TexturePVRAI88v3::onEnter()
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
string TexturePVRAI88v3::title()
@ -1181,7 +1181,7 @@ void TexturePVRNonSquare::onEnter()
auto img = Sprite::create("Images/grossini_128x256_mipmap.pvr");
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRNonSquare::title()
@ -1210,7 +1210,7 @@ void TexturePVRNPOT4444::onEnter()
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRNPOT4444::title()
@ -1239,7 +1239,7 @@ void TexturePVRNPOT8888::onEnter()
img->setPosition(Point( s.width/2.0f, s.height/2.0f));
addChild(img);
}
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePVRNPOT8888::title()
@ -1293,7 +1293,7 @@ void TextureAlias::onEnter()
sprite2->runAction(scaleforever);
sprite->runAction(scaleToo);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureAlias::title()
@ -1334,7 +1334,7 @@ void TexturePixelFormat::onEnter()
addChild(sprite1, 0);
// remove texture from texture manager
TextureCache::getInstance()->removeTexture(sprite1->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite1->getTexture());
// RGBA 4444 image (16-bit)
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
@ -1343,7 +1343,7 @@ void TexturePixelFormat::onEnter()
addChild(sprite2, 0);
// remove texture from texture manager
TextureCache::getInstance()->removeTexture(sprite2->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite2->getTexture());
// RGB5A1 image (16-bit)
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1);
@ -1352,7 +1352,7 @@ void TexturePixelFormat::onEnter()
addChild(sprite3, 0);
// remove texture from texture manager
TextureCache::getInstance()->removeTexture(sprite3->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite3->getTexture());
// RGB888 image
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB888);
@ -1361,7 +1361,7 @@ void TexturePixelFormat::onEnter()
addChild(sprite4, 0);
// remove texture from texture manager
TextureCache::getInstance()->removeTexture(sprite4->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite4->getTexture());
// RGB565 image (16-bit)
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB565);
@ -1370,7 +1370,7 @@ void TexturePixelFormat::onEnter()
addChild(sprite5, 0);
// remove texture from texture manager
TextureCache::getInstance()->removeTexture(sprite5->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite5->getTexture());
// A8 image (8-bit)
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8);
@ -1379,7 +1379,7 @@ void TexturePixelFormat::onEnter()
addChild(sprite6, 0);
// remove texture from texture manager
TextureCache::getInstance()->removeTexture(sprite6->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite6->getTexture());
auto fadeout = FadeOut::create(2);
auto fadein = FadeIn::create(2);
@ -1398,7 +1398,7 @@ void TexturePixelFormat::onEnter()
// restore default
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TexturePixelFormat::title()
@ -1486,7 +1486,7 @@ void TextureAsync::onEnter()
TextureAsync::~TextureAsync()
{
TextureCache::getInstance()->removeAllTextures();
Director::getInstance()->getTextureCache()->removeAllTextures();
}
void TextureAsync::loadImages(float dt)
@ -1495,15 +1495,15 @@ void TextureAsync::loadImages(float dt)
for( int j=0;j < 8; j++) {
char szSpriteName[100] = {0};
sprintf(szSpriteName, "Images/sprites_test/sprite-%d-%d.png", i, j);
TextureCache::getInstance()->addImageAsync(szSpriteName,this, callfuncO_selector(TextureAsync::imageLoaded));
Director::getInstance()->getTextureCache()->addImageAsync(szSpriteName,this, callfuncO_selector(TextureAsync::imageLoaded));
}
}
TextureCache::getInstance()->addImageAsync("Images/background1.jpg",this, callfuncO_selector(TextureAsync::imageLoaded));
TextureCache::getInstance()->addImageAsync("Images/background2.jpg",this, callfuncO_selector(TextureAsync::imageLoaded));
TextureCache::getInstance()->addImageAsync("Images/background.png",this, callfuncO_selector(TextureAsync::imageLoaded));
TextureCache::getInstance()->addImageAsync("Images/atlastest.png",this, callfuncO_selector(TextureAsync::imageLoaded));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_atlas.png",this, callfuncO_selector(TextureAsync::imageLoaded));
Director::getInstance()->getTextureCache()->addImageAsync("Images/background1.jpg",this, callfuncO_selector(TextureAsync::imageLoaded));
Director::getInstance()->getTextureCache()->addImageAsync("Images/background2.jpg",this, callfuncO_selector(TextureAsync::imageLoaded));
Director::getInstance()->getTextureCache()->addImageAsync("Images/background.png",this, callfuncO_selector(TextureAsync::imageLoaded));
Director::getInstance()->getTextureCache()->addImageAsync("Images/atlastest.png",this, callfuncO_selector(TextureAsync::imageLoaded));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_atlas.png",this, callfuncO_selector(TextureAsync::imageLoaded));
}
@ -1576,7 +1576,7 @@ std::string TextureGlClamp::title()
TextureGlClamp::~TextureGlClamp()
{
TextureCache::getInstance()->removeUnusedTextures();
Director::getInstance()->getTextureCache()->removeUnusedTextures();
}
//------------------------------------------------------------------
@ -1613,7 +1613,7 @@ std::string TextureGlRepeat::title()
TextureGlRepeat::~TextureGlRepeat()
{
TextureCache::getInstance()->removeUnusedTextures();
Director::getInstance()->getTextureCache()->removeUnusedTextures();
}
//------------------------------------------------------------------
@ -1684,7 +1684,7 @@ void TextureCache1::onEnter()
sprite->setScale(2);
addChild(sprite);
TextureCache::getInstance()->removeTexture(sprite->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite->getTexture());
sprite = Sprite::create("Images/grossinis_sister1.png");
sprite->setPosition(Point(s.width/5*2, s.height/2));
@ -1700,7 +1700,7 @@ void TextureCache1::onEnter()
sprite->setScale(2);
addChild(sprite);
TextureCache::getInstance()->removeTextureForKey("Images/grossinis_sister2.png");
Director::getInstance()->getTextureCache()->removeTextureForKey("Images/grossinis_sister2.png");
sprite = Sprite::create("Images/grossinis_sister2.png");
sprite->setPosition(Point(s.width/5*4, s.height/2));
@ -1724,8 +1724,8 @@ void TextureDrawAtPoint::onEnter()
{
TextureDemo::onEnter();
_tex1 = TextureCache::getInstance()->addImage("Images/grossinis_sister1.png");
_Tex2F = TextureCache::getInstance()->addImage("Images/grossinis_sister2.png");
_tex1 = Director::getInstance()->getTextureCache()->addImage("Images/grossinis_sister1.png");
_Tex2F = Director::getInstance()->getTextureCache()->addImage("Images/grossinis_sister2.png");
_tex1->retain();
_Tex2F->retain();
@ -1763,8 +1763,8 @@ void TextureDrawAtPoint::draw()
void TextureDrawInRect::onEnter()
{
TextureDemo::onEnter();
_tex1 = TextureCache::getInstance()->addImage("Images/grossinis_sister1.png");
_Tex2F = TextureCache::getInstance()->addImage("Images/grossinis_sister2.png");
_tex1 = Director::getInstance()->getTextureCache()->addImage("Images/grossinis_sister1.png");
_Tex2F = Director::getInstance()->getTextureCache()->addImage("Images/grossinis_sister2.png");
_tex1->retain();
_Tex2F->retain();
@ -1871,7 +1871,7 @@ void TextureMemoryAlloc::updateImage(cocos2d::Object *sender)
_background->removeFromParentAndCleanup(true);
}
TextureCache::getInstance()->removeUnusedTextures();
Director::getInstance()->getTextureCache()->removeUnusedTextures();
int tag = ((Node*)sender)->getTag();
string file;
@ -1952,7 +1952,7 @@ TexturePVRv3Premult::TexturePVRv3Premult()
// PNG
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
TextureCache::getInstance()->removeTextureForKey("Images/grossinis_sister1-testalpha.png");
Director::getInstance()->getTextureCache()->removeTextureForKey("Images/grossinis_sister1-testalpha.png");
auto png = Sprite::create("Images/grossinis_sister1-testalpha.png");
addChild(png, 0);
png->setPosition(Point(size.width/4*3, size.height/2));
@ -2132,7 +2132,7 @@ static void addImageToDemo(TextureDemo& demo, float x, float y, const char* path
demo.addChild(sprite, 0);
//remove texture from texture manager
TextureCache::getInstance()->removeTexture(sprite->getTexture());
Director::getInstance()->getTextureCache()->removeTexture(sprite->getTexture());
}
//TextureConvertRGB888
@ -2157,7 +2157,7 @@ void TextureConvertRGB888::onEnter()
// restore default
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureConvertRGB888::title()
@ -2191,7 +2191,7 @@ void TextureConvertRGBA8888::onEnter()
// restore default
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureConvertRGBA8888::title()
@ -2225,7 +2225,7 @@ void TextureConvertI8::onEnter()
// restore default
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureConvertI8::title()
@ -2259,7 +2259,7 @@ void TextureConvertAI88::onEnter()
// restore default
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT);
TextureCache::getInstance()->dumpCachedTextureInfo();
Director::getInstance()->getTextureCache()->dumpCachedTextureInfo();
}
std::string TextureConvertAI88::title()

View File

@ -21,26 +21,26 @@ TextureCacheTest::TextureCacheTest()
this->addChild(_labelPercent);
// load textrues
TextureCache::getInstance()->addImageAsync("Images/HelloWorld.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_01.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_02.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_03.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_04.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_05.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_06.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_07.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_08.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_09.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_10.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_11.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_12.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_13.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/grossini_dance_14.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/background1.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/background2.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/background3.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
TextureCache::getInstance()->addImageAsync("Images/blocks.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/HelloWorld.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_01.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_02.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_03.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_04.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_05.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_06.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_07.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_08.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_09.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_10.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_11.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_12.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_13.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/grossini_dance_14.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/background1.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/background2.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/background3.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
Director::getInstance()->getTextureCache()->addImageAsync("Images/blocks.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
}
void TextureCacheTest::loadingCallBack(Object *obj)

View File

@ -39,13 +39,13 @@ PongLayer::PongLayer()
{
_ballStartingVelocity = Point(20.0f, -100.0f);
_ball = Ball::ballWithTexture( TextureCache::getInstance()->addImage(s_Ball) );
_ball = Ball::ballWithTexture( Director::getInstance()->getTextureCache()->addImage(s_Ball) );
_ball->setPosition( VisibleRect::center() );
_ball->setVelocity( _ballStartingVelocity );
addChild( _ball );
_ball->retain();
auto paddleTexture = TextureCache::getInstance()->addImage(s_Paddle);
auto paddleTexture = Director::getInstance()->getTextureCache()->addImage(s_Paddle);
auto paddlesM = Array::createWithCapacity(4);

View File

@ -1,5 +1,6 @@
#import "RootViewController.h"
#import "cocos2d.h"
#import "EAGLView.h"
@implementation RootViewController
@ -43,6 +44,14 @@
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
CGSize s = CGSizeMake([[CCEAGLView sharedEGLView] getWidth], [[CCEAGLView sharedEGLView] getHeight]);
cocos2d::Application::getInstance()->applicationScreenSizeChanged((int) s.width, (int) s.height);
}
//fix not hide status on ios7
- (BOOL)prefersStatusBarHidden
{

Some files were not shown because too many files have changed in this diff Show More