mirror of https://github.com/axmolengine/axmol.git
commit
775c7ff847
|
@ -1 +1 @@
|
||||||
8575c43b860eea3c0f02d9543e58b74073e40e6d
|
f75a8c50e01404209e0c065b8d040d973cfc0fc0
|
|
@ -1 +1 @@
|
||||||
c1cdd4b0d66de5127dc37f73eb9895737ca3e18d
|
f9ca064a5aba796aacdc647bb44c2f8a0658707c
|
|
@ -31,6 +31,7 @@ THE SOFTWARE.
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCMutableDictionary.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
|
#include "selector_protocol.h"
|
||||||
|
|
||||||
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||||
#include "CCImage.h"
|
#include "CCImage.h"
|
||||||
|
@ -38,25 +39,23 @@ THE SOFTWARE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
class CCAsyncObject;
|
|
||||||
class CCLock;
|
class CCLock;
|
||||||
class CCImage;
|
class CCImage;
|
||||||
|
|
||||||
typedef void (*fpAsyncCallback)(CCTexture2D*, void*);
|
|
||||||
|
|
||||||
/** @brief Singleton that handles the loading of textures
|
/** @brief Singleton that handles the loading of textures
|
||||||
* Once the texture is loaded, the next time it will return
|
* Once the texture is loaded, the next time it will return
|
||||||
* a reference of the previously loaded texture reducing GPU & CPU memory
|
* a reference of the previously loaded texture reducing GPU & CPU memory
|
||||||
*/
|
*/
|
||||||
class CC_DLL CCTextureCache : public CCObject
|
class CC_DLL CCTextureCache : public SelectorProtocol, public CCObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CCMutableDictionary<std::string, CCTexture2D*> * m_pTextures;
|
CCMutableDictionary<std::string, CCTexture2D*> * m_pTextures;
|
||||||
CCLock *m_pDictLock;
|
//pthread_mutex_t *m_pDictLock;
|
||||||
CCLock *m_pContextLock;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// @todo void addImageWithAsyncObject(CCAsyncObject* async);
|
// @todo void addImageWithAsyncObject(CCAsyncObject* async);
|
||||||
|
void addImageAsyncCallBack(ccTime dt);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -89,7 +88,7 @@ public:
|
||||||
* @since v0.8
|
* @since v0.8
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @todo void addImageAsync(const char* filename, CCObject*target, fpAsyncCallback func);
|
void addImageAsync(const char *path, SelectorProtocol *target, SEL_CallFuncO selector);
|
||||||
|
|
||||||
/* Returns a Texture2D object given an CGImageRef image
|
/* Returns a Texture2D object given an CGImageRef image
|
||||||
* If the image was not previously loaded, it will create a new CCTexture2D object and it will return it.
|
* If the image was not previously loaded, it will create a new CCTexture2D object and it will return it.
|
||||||
|
|
|
@ -141,11 +141,15 @@ CCParticleSystem * CCParticleSystem::particleWithFile(const char *plistFile)
|
||||||
}
|
}
|
||||||
bool CCParticleSystem::initWithFile(const char *plistFile)
|
bool CCParticleSystem::initWithFile(const char *plistFile)
|
||||||
{
|
{
|
||||||
|
bool bRet = false;
|
||||||
m_sPlistFile = CCFileUtils::fullPathFromRelativePath(plistFile);
|
m_sPlistFile = CCFileUtils::fullPathFromRelativePath(plistFile);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(m_sPlistFile.c_str());
|
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(m_sPlistFile.c_str());
|
||||||
|
|
||||||
CCAssert( dict != NULL, "Particles: file not found");
|
CCAssert( dict != NULL, "Particles: file not found");
|
||||||
return this->initWithDictionary(dict);
|
bRet = this->initWithDictionary(dict);
|
||||||
|
dict->release();
|
||||||
|
|
||||||
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary)
|
bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary)
|
||||||
|
|
|
@ -98,7 +98,9 @@ public:
|
||||||
m_pCurDict = new CCDictionary<std::string, CCObject*>();
|
m_pCurDict = new CCDictionary<std::string, CCObject*>();
|
||||||
if(! m_pRootDict)
|
if(! m_pRootDict)
|
||||||
{
|
{
|
||||||
|
// Because it will call m_pCurDict->release() later, so retain here.
|
||||||
m_pRootDict = m_pCurDict;
|
m_pRootDict = m_pCurDict;
|
||||||
|
m_pRootDict->retain();
|
||||||
}
|
}
|
||||||
m_tState = SAX_DICT;
|
m_tState = SAX_DICT;
|
||||||
|
|
||||||
|
@ -120,7 +122,8 @@ public:
|
||||||
CCDictionary<std::string, CCObject*>* pPreDict = m_tDictStack.top();
|
CCDictionary<std::string, CCObject*>* pPreDict = m_tDictStack.top();
|
||||||
pPreDict->setObject(m_pCurDict, m_sCurKey);
|
pPreDict->setObject(m_pCurDict, m_sCurKey);
|
||||||
}
|
}
|
||||||
m_pCurDict->autorelease();
|
|
||||||
|
m_pCurDict->release();
|
||||||
|
|
||||||
// record the dict state
|
// record the dict state
|
||||||
m_tStateStack.push(m_tState);
|
m_tStateStack.push(m_tState);
|
||||||
|
@ -285,7 +288,15 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCDictMaker tMaker;
|
CCDictionary<std::string, CCObject*> *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
||||||
|
ret->autorelease();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||||
|
{
|
||||||
|
CCDictMaker tMaker;
|
||||||
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,12 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
|
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
|
||||||
|
|
||||||
|
/*
|
||||||
|
@brief The same meaning as dictionaryWithContentsOfFile(), but it doesn't call autorelease, so the
|
||||||
|
invoker should call release().
|
||||||
|
*/
|
||||||
|
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFileThreadSafe(const char *pFileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get the writeable path
|
@brief Get the writeable path
|
||||||
@return The path that can write/read file
|
@return The path that can write/read file
|
||||||
|
|
|
@ -24,18 +24,16 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCThread.h"
|
#include "CCThread.h"
|
||||||
|
|
||||||
#if CC_SUPPORT_MULTITHREAD
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
CCThread::~CCThread()
|
||||||
#include "win32/CCThread_win32.cpp"
|
{
|
||||||
#endif // CC_PLATFORM_WIN32
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
}
|
||||||
#include "wophone/CCThread_wophone.cpp"
|
|
||||||
#endif // CC_PLATFORM_WOPHONE
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
void CCThread::createAutoreleasePool()
|
||||||
#include "android/CCThread_android.cpp"
|
{
|
||||||
#endif // CC_PLATFORM_ANDROID
|
|
||||||
|
|
||||||
#endif // CC_SUPPORT_MULTITHREAD
|
}
|
||||||
|
|
||||||
|
NS_CC_END;
|
|
@ -26,41 +26,24 @@ THE SOFTWARE.
|
||||||
#define __CC_PLATFORM_THREAD_H__
|
#define __CC_PLATFORM_THREAD_H__
|
||||||
|
|
||||||
#include "CCCommon.h"
|
#include "CCCommon.h"
|
||||||
|
#include "CCPlatformMacros.h"
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
#if CC_SUPPORT_MULTITHREAD
|
/* On iOS, should create autorelease pool when create a new thread
|
||||||
/**
|
* and release it when the thread end.
|
||||||
@brief The object for mutual-exclusion synchronization.
|
*/
|
||||||
|
class CC_DLL CCThread
|
||||||
@warning Don't enter a CCLock twice in the same thread.
|
|
||||||
*/
|
|
||||||
class CC_DLL CCLock
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCLock();
|
CCThread() : m_pAutoreasePool(0) {}
|
||||||
~CCLock();
|
~CCThread();
|
||||||
|
|
||||||
void lock();
|
void createAutoreleasePool();
|
||||||
void unlock();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Impl;
|
void *m_pAutoreasePool;
|
||||||
CCLock::Impl * m_pImp;
|
|
||||||
};
|
};
|
||||||
#else // CC_SUPPORT_MULTITHREAD
|
|
||||||
|
|
||||||
class CC_DLL CCLock
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CCLock() {}
|
|
||||||
~CCLock() {}
|
|
||||||
|
|
||||||
void lock() {}
|
|
||||||
void unlock() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CC_SUPPORT_MULTITHREAD
|
|
||||||
|
|
||||||
NS_CC_END;
|
NS_CC_END;
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,16 @@ namespace cocos2d {
|
||||||
pRet->m_sString += pszFilename;
|
pRet->m_sString += pszFilename;
|
||||||
return pRet->m_sString.c_str();
|
return pRet->m_sString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
|
{
|
||||||
|
CCDictionary<std::string, CCObject*> *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
||||||
|
ret->autorelease();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||||
{
|
{
|
||||||
NSString* pPath = [NSString stringWithUTF8String:pFileName];
|
NSString* pPath = [NSString stringWithUTF8String:pFileName];
|
||||||
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
|
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
|
||||||
|
@ -301,9 +310,10 @@ namespace cocos2d {
|
||||||
id value = [pDict objectForKey:key];
|
id value = [pDict objectForKey:key];
|
||||||
static_addValueToCCDict(key, value, pRet);
|
static_addValueToCCDict(key, value, pRet);
|
||||||
}
|
}
|
||||||
pRet->autorelease();
|
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||||
{
|
{
|
||||||
unsigned char * pBuffer = NULL;
|
unsigned char * pBuffer = NULL;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
* Module: sched.h
|
||||||
|
*
|
||||||
|
* Purpose:
|
||||||
|
* Provides an implementation of POSIX realtime extensions
|
||||||
|
* as defined in
|
||||||
|
*
|
||||||
|
* POSIX 1003.1b-1993 (POSIX.1b)
|
||||||
|
*
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Pthreads-win32 - POSIX Threads Library for Win32
|
||||||
|
* Copyright(C) 1998 John E. Bossom
|
||||||
|
* Copyright(C) 1999,2005 Pthreads-win32 contributors
|
||||||
|
*
|
||||||
|
* Contact Email: rpj@callisto.canberra.edu.au
|
||||||
|
*
|
||||||
|
* The current list of contributors is contained
|
||||||
|
* in the file CONTRIBUTORS included with the source
|
||||||
|
* code distribution. The list can also be seen at the
|
||||||
|
* following World Wide Web location:
|
||||||
|
* http://sources.redhat.com/pthreads-win32/contributors.html
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library in the file COPYING.LIB;
|
||||||
|
* if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
#ifndef _SCHED_H
|
||||||
|
#define _SCHED_H
|
||||||
|
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
|
||||||
|
#if defined(_POSIX_SOURCE)
|
||||||
|
#define PTW32_LEVEL 0
|
||||||
|
/* Early POSIX */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
#define PTW32_LEVEL 1
|
||||||
|
/* Include 1b, 1c and 1d */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(INCLUDE_NP)
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
#define PTW32_LEVEL 2
|
||||||
|
/* Include Non-Portable extensions */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PTW32_LEVEL_MAX 3
|
||||||
|
|
||||||
|
#if !defined(PTW32_LEVEL)
|
||||||
|
#define PTW32_LEVEL PTW32_LEVEL_MAX
|
||||||
|
/* Include everything */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if __GNUC__ && ! defined (__declspec)
|
||||||
|
# error Please upgrade your GNU compiler to one that supports __declspec.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When building the DLL code, you should define PTW32_BUILD so that
|
||||||
|
* the variables/functions are exported correctly. When using the DLL,
|
||||||
|
* do NOT define PTW32_BUILD, and then the variables/functions will
|
||||||
|
* be imported correctly.
|
||||||
|
*/
|
||||||
|
#ifndef PTW32_STATIC_LIB
|
||||||
|
# ifdef PTW32_BUILD
|
||||||
|
# define PTW32_DLLPORT __declspec (dllexport)
|
||||||
|
# else
|
||||||
|
# define PTW32_DLLPORT __declspec (dllimport)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define PTW32_DLLPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a duplicate of what is in the autoconf config.h,
|
||||||
|
* which is only used when building the pthread-win32 libraries.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PTW32_CONFIG_H
|
||||||
|
# if defined(WINCE)
|
||||||
|
# define NEED_ERRNO
|
||||||
|
# define NEED_SEM
|
||||||
|
# endif
|
||||||
|
# if defined(_UWIN) || defined(__MINGW32__)
|
||||||
|
# define HAVE_MODE_T
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
|
||||||
|
#ifdef NEED_ERRNO
|
||||||
|
#include "need_errno.h"
|
||||||
|
#else
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) || defined(_UWIN)
|
||||||
|
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
|
||||||
|
/* For pid_t */
|
||||||
|
# include <sys/types.h>
|
||||||
|
/* Required by Unix 98 */
|
||||||
|
# include <time.h>
|
||||||
|
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
|
||||||
|
#else
|
||||||
|
typedef int pid_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Thread scheduling policies */
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SCHED_OTHER = 0,
|
||||||
|
SCHED_FIFO,
|
||||||
|
SCHED_RR,
|
||||||
|
SCHED_MIN = SCHED_OTHER,
|
||||||
|
SCHED_MAX = SCHED_RR
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sched_param {
|
||||||
|
int sched_priority;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sched_yield (void);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that this macro returns ENOTSUP rather than
|
||||||
|
* ENOSYS as might be expected. However, returning ENOSYS
|
||||||
|
* should mean that sched_get_priority_{min,max} are
|
||||||
|
* not implemented as well as sched_rr_get_interval.
|
||||||
|
* This is not the case, since we just don't support
|
||||||
|
* round-robin scheduling. Therefore I have chosen to
|
||||||
|
* return the same value as sched_setscheduler when
|
||||||
|
* SCHED_RR is passed to it.
|
||||||
|
*/
|
||||||
|
#define sched_rr_get_interval(_pid, _interval) \
|
||||||
|
( errno = ENOTSUP, (int) -1 )
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* End of extern "C" */
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
#undef PTW32_LEVEL_MAX
|
||||||
|
|
||||||
|
#endif /* !_SCHED_H */
|
||||||
|
|
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
* Module: semaphore.h
|
||||||
|
*
|
||||||
|
* Purpose:
|
||||||
|
* Semaphores aren't actually part of the PThreads standard.
|
||||||
|
* They are defined by the POSIX Standard:
|
||||||
|
*
|
||||||
|
* POSIX 1003.1b-1993 (POSIX.1b)
|
||||||
|
*
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Pthreads-win32 - POSIX Threads Library for Win32
|
||||||
|
* Copyright(C) 1998 John E. Bossom
|
||||||
|
* Copyright(C) 1999,2005 Pthreads-win32 contributors
|
||||||
|
*
|
||||||
|
* Contact Email: rpj@callisto.canberra.edu.au
|
||||||
|
*
|
||||||
|
* The current list of contributors is contained
|
||||||
|
* in the file CONTRIBUTORS included with the source
|
||||||
|
* code distribution. The list can also be seen at the
|
||||||
|
* following World Wide Web location:
|
||||||
|
* http://sources.redhat.com/pthreads-win32/contributors.html
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library in the file COPYING.LIB;
|
||||||
|
* if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
#if !defined( SEMAPHORE_H )
|
||||||
|
#define SEMAPHORE_H
|
||||||
|
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
|
||||||
|
#if defined(_POSIX_SOURCE)
|
||||||
|
#define PTW32_LEVEL 0
|
||||||
|
/* Early POSIX */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
#define PTW32_LEVEL 1
|
||||||
|
/* Include 1b, 1c and 1d */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(INCLUDE_NP)
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
#define PTW32_LEVEL 2
|
||||||
|
/* Include Non-Portable extensions */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PTW32_LEVEL_MAX 3
|
||||||
|
|
||||||
|
#if !defined(PTW32_LEVEL)
|
||||||
|
#define PTW32_LEVEL PTW32_LEVEL_MAX
|
||||||
|
/* Include everything */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __GNUC__ && ! defined (__declspec)
|
||||||
|
# error Please upgrade your GNU compiler to one that supports __declspec.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When building the DLL code, you should define PTW32_BUILD so that
|
||||||
|
* the variables/functions are exported correctly. When using the DLL,
|
||||||
|
* do NOT define PTW32_BUILD, and then the variables/functions will
|
||||||
|
* be imported correctly.
|
||||||
|
*/
|
||||||
|
#ifndef PTW32_STATIC_LIB
|
||||||
|
# ifdef PTW32_BUILD
|
||||||
|
# define PTW32_DLLPORT __declspec (dllexport)
|
||||||
|
# else
|
||||||
|
# define PTW32_DLLPORT __declspec (dllimport)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define PTW32_DLLPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a duplicate of what is in the autoconf config.h,
|
||||||
|
* which is only used when building the pthread-win32 libraries.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PTW32_CONFIG_H
|
||||||
|
# if defined(WINCE)
|
||||||
|
# define NEED_ERRNO
|
||||||
|
# define NEED_SEM
|
||||||
|
# endif
|
||||||
|
# if defined(_UWIN) || defined(__MINGW32__)
|
||||||
|
# define HAVE_MODE_T
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
|
||||||
|
#ifdef NEED_ERRNO
|
||||||
|
#include "need_errno.h"
|
||||||
|
#else
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
|
||||||
|
|
||||||
|
#define _POSIX_SEMAPHORES
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#ifndef HAVE_MODE_T
|
||||||
|
typedef unsigned int mode_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct sem_t_ * sem_t;
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_init (sem_t * sem,
|
||||||
|
int pshared,
|
||||||
|
unsigned int value);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem,
|
||||||
|
const struct timespec * abstime);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_post (sem_t * sem);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem,
|
||||||
|
int count);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_open (const char * name,
|
||||||
|
int oflag,
|
||||||
|
mode_t mode,
|
||||||
|
unsigned int value);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_close (sem_t * sem);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_unlink (const char * name);
|
||||||
|
|
||||||
|
PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem,
|
||||||
|
int * sval);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* End of extern "C" */
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#undef PTW32_LEVEL
|
||||||
|
#undef PTW32_LEVEL_MAX
|
||||||
|
|
||||||
|
#endif /* !SEMAPHORE_H */
|
|
@ -4,3 +4,4 @@ libpng 1.4.5beta04
|
||||||
libxml2 2.7.7
|
libxml2 2.7.7
|
||||||
OGLES 2.08.28.0634
|
OGLES 2.08.28.0634
|
||||||
zlib 1.2.5
|
zlib 1.2.5
|
||||||
|
pthread 2.8.0
|
||||||
|
|
|
@ -1,70 +1 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if CCX_SUPPORT_MULTITHREAD
|
|
||||||
|
|
||||||
#include "ccxThread.h"
|
|
||||||
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
|
||||||
|
|
||||||
class CCXLock::Impl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Impl() { InitializeCriticalSection(&m_cs); }
|
|
||||||
~Impl() { DeleteCriticalSection(&m_cs); }
|
|
||||||
|
|
||||||
CRITICAL_SECTION m_cs;
|
|
||||||
};
|
|
||||||
|
|
||||||
CCXLock::CCXLock()
|
|
||||||
: m_pImp(new CCXLock::Impl)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CCXLock::~CCXLock()
|
|
||||||
{
|
|
||||||
CC_SAFE_DELETE(m_pImp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCXLock::lock()
|
|
||||||
{
|
|
||||||
if (m_pImp)
|
|
||||||
{
|
|
||||||
EnterCriticalSection(&m_pImp->m_cs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCXLock::unlock()
|
|
||||||
{
|
|
||||||
if (m_pImp)
|
|
||||||
{
|
|
||||||
LeaveCriticalSection(&m_pImp->m_cs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END;
|
|
||||||
|
|
||||||
#endif // CCX_SUPPORT_MULTITHREAD
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories="..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;.."
|
AdditionalIncludeDirectories="..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\pthread;..\platform\third_party\win32\OGLES;..\include;.."
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES"
|
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES"
|
||||||
MinimalRebuild="true"
|
MinimalRebuild="true"
|
||||||
BasicRuntimeChecks="3"
|
BasicRuntimeChecks="3"
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="libEGL.lib libgles_cm.lib libxml2.lib libzlib.lib libpng.lib libjpeg.lib libiconv.lib"
|
AdditionalDependencies="libEGL.lib libgles_cm.lib libxml2.lib libzlib.lib libpng.lib libjpeg.lib libiconv.lib pthreadVCE2.lib"
|
||||||
OutputFile="$(OutDir)\$(ProjectName).dll"
|
OutputFile="$(OutDir)\$(ProjectName).dll"
|
||||||
LinkIncremental="2"
|
LinkIncremental="2"
|
||||||
AdditionalLibraryDirectories=""$(OutDir)""
|
AdditionalLibraryDirectories=""$(OutDir)""
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\pthread;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\pthread;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<MinimalRebuild>true</MinimalRebuild>
|
<MinimalRebuild>true</MinimalRebuild>
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
|
@ -74,7 +74,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
|
||||||
</Command>
|
</Command>
|
||||||
</PreLinkEvent>
|
</PreLinkEvent>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;pthreadVCE2.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
|
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
|
||||||
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||||
|
@ -95,7 +95,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
|
||||||
</Command>
|
</Command>
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\pthread;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
|
@ -110,7 +110,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
|
||||||
</Command>
|
</Command>
|
||||||
</PreLinkEvent>
|
</PreLinkEvent>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
|
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
|
||||||
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<IgnoreSpecificDefaultLibraries> ;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
<IgnoreSpecificDefaultLibraries> ;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
||||||
|
|
|
@ -197,9 +197,11 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
||||||
{
|
{
|
||||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
|
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||||
|
|
||||||
addSpriteFramesWithDictionary(dict, pobTexture);
|
addSpriteFramesWithDictionary(dict, pobTexture);
|
||||||
|
|
||||||
|
dict->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName)
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName)
|
||||||
|
@ -220,7 +222,7 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char*
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||||
{
|
{
|
||||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
|
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||||
|
|
||||||
string texturePath("");
|
string texturePath("");
|
||||||
|
|
||||||
|
@ -261,6 +263,8 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCSpriteFrameCache: Couldn't load texture");
|
CCLOG("cocos2d: CCSpriteFrameCache: Couldn't load texture");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dict->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
||||||
|
@ -316,9 +320,11 @@ void CCSpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
||||||
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
||||||
{
|
{
|
||||||
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
||||||
CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFile(path);
|
CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(path);
|
||||||
|
|
||||||
removeSpriteFramesFromDictionary((CCDictionary<std::string, CCSpriteFrame*>*)dict);
|
removeSpriteFramesFromDictionary((CCDictionary<std::string, CCSpriteFrame*>*)dict);
|
||||||
|
|
||||||
|
dict->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary<std::string, CCSpriteFrame*> *dictionary)
|
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary<std::string, CCSpriteFrame*> *dictionary)
|
||||||
|
|
|
@ -23,6 +23,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#define COCOS2D_DEBUG 1
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -36,24 +37,70 @@ THE SOFTWARE.
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "CCImage.h"
|
#include "CCImage.h"
|
||||||
#include "support/ccUtils.h"
|
#include "support/ccUtils.h"
|
||||||
|
#include "CCScheduler.h"
|
||||||
|
#include "pthread.h"
|
||||||
|
#include "CCThread.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
class CCAsyncObject : CCObject
|
typedef struct _AsyncStruct
|
||||||
{
|
{
|
||||||
public:
|
std::string filename;
|
||||||
fpAsyncCallback m_pfnCallback;
|
SelectorProtocol *target;
|
||||||
CCObject* m_pTarget;
|
SEL_CallFuncO selector;
|
||||||
std::string * m_pData;
|
} AsyncStruct;
|
||||||
public:
|
|
||||||
CCAsyncObject();
|
static cocos2d::CCImage* s_pImageAsync;
|
||||||
~CCAsyncObject()
|
// only allow one loading thread at a time
|
||||||
|
static pthread_mutex_t s_loadingThreadMutex;
|
||||||
|
// condition
|
||||||
|
static pthread_cond_t s_condition;
|
||||||
|
static pthread_mutex_t s_conditionMutex;
|
||||||
|
static AsyncStruct *s_pAsyncObject;
|
||||||
|
|
||||||
|
static void* loadImage(void* data)
|
||||||
|
{
|
||||||
|
// create autorelease pool for iOS
|
||||||
|
CCThread thread;
|
||||||
|
thread.createAutoreleasePool();
|
||||||
|
|
||||||
|
if (! ((AsyncStruct*)data)->filename.c_str())
|
||||||
{
|
{
|
||||||
CCLOGINFO("cocos2d: deallocing CCAsyncObject.");
|
return 0;
|
||||||
CC_SAFE_DELETE(m_pTarget);
|
|
||||||
CC_SAFE_DELETE(m_pData);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
// one loading thread at a time
|
||||||
|
pthread_mutex_lock(&s_loadingThreadMutex);
|
||||||
|
|
||||||
|
s_pAsyncObject = (AsyncStruct*)data;
|
||||||
|
const char *filename = s_pAsyncObject->filename.c_str();
|
||||||
|
|
||||||
|
CCLOG("thread 0x%x is loading image %s", pthread_self(), filename);
|
||||||
|
|
||||||
|
CCImage *tmpImage = new CCImage();
|
||||||
|
tmpImage->initWithImageFile(filename);
|
||||||
|
s_pImageAsync = tmpImage;
|
||||||
|
|
||||||
|
/* Wait for rendering thread to comsume the image.
|
||||||
|
* The implemntation of pthread_cond_wait() of win32 has a bug, it can not
|
||||||
|
* wait the condition at first time.
|
||||||
|
*/
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||||
|
static bool firstRun = true;
|
||||||
|
if (firstRun)
|
||||||
|
{
|
||||||
|
pthread_cond_wait(&s_condition, &s_conditionMutex);
|
||||||
|
firstRun = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
pthread_cond_wait(&s_condition, &s_conditionMutex);
|
||||||
|
|
||||||
|
CCLOG("thread 0x%x has pass the condition, new loading thread is avalable", pthread_self());
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&s_loadingThreadMutex);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// implementation CCTextureCache
|
// implementation CCTextureCache
|
||||||
|
|
||||||
|
@ -73,8 +120,6 @@ CCTextureCache::CCTextureCache()
|
||||||
CCAssert(g_sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
|
CCAssert(g_sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
|
||||||
|
|
||||||
m_pTextures = new CCMutableDictionary<std::string, CCTexture2D*>();
|
m_pTextures = new CCMutableDictionary<std::string, CCTexture2D*>();
|
||||||
m_pDictLock = new CCLock();
|
|
||||||
m_pContextLock = new CCLock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTextureCache::~CCTextureCache()
|
CCTextureCache::~CCTextureCache()
|
||||||
|
@ -82,8 +127,6 @@ CCTextureCache::~CCTextureCache()
|
||||||
CCLOGINFO("cocos2d: deallocing CCTextureCache.");
|
CCLOGINFO("cocos2d: deallocing CCTextureCache.");
|
||||||
|
|
||||||
CC_SAFE_RELEASE(m_pTextures);
|
CC_SAFE_RELEASE(m_pTextures);
|
||||||
CC_SAFE_DELETE(m_pDictLock);
|
|
||||||
CC_SAFE_DELETE(m_pContextLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureCache::purgeSharedTextureCache()
|
void CCTextureCache::purgeSharedTextureCache()
|
||||||
|
@ -99,77 +142,80 @@ char * CCTextureCache::description()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCTextureCache::addImageAsync(const char *path, SelectorProtocol *target, SEL_CallFuncO selector)
|
||||||
// TextureCache - Add Images
|
|
||||||
/* @todo EAGLContext
|
|
||||||
void CCTextureCache::addImageWithAsyncObject(CCAsyncObject* async)
|
|
||||||
{
|
{
|
||||||
|
CCAssert(path != NULL, "TextureCache: fileimage MUST not be NULL");
|
||||||
|
|
||||||
CCAutoreleasePool *autoreleasepool = [[CCAutoreleasePool alloc] init];
|
CCTexture2D *texture = NULL;
|
||||||
|
|
||||||
// textures will be created on the main OpenGL context
|
|
||||||
// it seems that in SDK 2.2.x there can't be 2 threads creating textures at the same time
|
|
||||||
// the lock is used for this purpose: issue #472
|
|
||||||
[contextLock lock];
|
|
||||||
if( auxEAGLcontext == nil ) {
|
|
||||||
auxEAGLcontext = [[EAGLContext alloc]
|
|
||||||
initWithAPI:kEAGLRenderingAPIOpenGLES1
|
|
||||||
sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]];
|
|
||||||
|
|
||||||
if( ! auxEAGLcontext )
|
|
||||||
CCLOG(@"cocos2d: TextureCache: Could not create EAGL context");
|
|
||||||
}
|
|
||||||
|
|
||||||
if( [EAGLContext setCurrentContext:auxEAGLcontext] ) {
|
|
||||||
|
|
||||||
// load / create the texture
|
|
||||||
CCTexture2D *tex = [self addImage:async.data];
|
|
||||||
|
|
||||||
// The callback will be executed on the main thread
|
|
||||||
[async.target performSelectorOnMainThread:async.selector withObject:tex waitUntilDone:NO];
|
|
||||||
|
|
||||||
[EAGLContext setCurrentContext:nil];
|
|
||||||
} else {
|
|
||||||
CCLOG(@"cocos2d: TetureCache: EAGLContext error");
|
|
||||||
}
|
|
||||||
[contextLock unlock];
|
|
||||||
|
|
||||||
[autoreleasepool release];
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/* @todo selector, NSThread
|
|
||||||
void CCTextureCache::addImageAsync(const char* filename, CCObject *target, fpAsyncCallback func)
|
|
||||||
{
|
|
||||||
CCAssert(filename != NULL , "TextureCache: fileimage MUST not be nill");
|
|
||||||
|
|
||||||
// optimization
|
// optimization
|
||||||
|
|
||||||
CCTexture2D * tex;
|
std::string pathKey = path;
|
||||||
|
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
||||||
|
|
||||||
if ( (tex = m_pTextures->objectForKey(filename)) )
|
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
||||||
|
texture = m_pTextures->objectForKey(pathKey);
|
||||||
|
|
||||||
{
|
std::string fullpath = pathKey;
|
||||||
|
if (texture = m_pTextures->objectForKey(pathKey))
|
||||||
|
{
|
||||||
|
(target->*selector)(texture);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
target->
|
// lazy init
|
||||||
|
static bool firstRun = true;
|
||||||
|
if (firstRun)
|
||||||
|
{
|
||||||
|
pthread_mutex_init(&s_loadingThreadMutex, NULL);
|
||||||
|
pthread_mutex_init(&s_conditionMutex, NULL);
|
||||||
|
pthread_cond_init(&s_condition, NULL);
|
||||||
|
s_pImageAsync = NULL;
|
||||||
|
|
||||||
}
|
CCScheduler::sharedScheduler()->scheduleSelector(schedule_selector(CCTextureCache::addImageAsyncCallBack), this, 1.0f, false);
|
||||||
|
|
||||||
|
firstRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
if( (tex=[textures objectForKey: filename] ) ) {
|
AsyncStruct *data = new AsyncStruct();
|
||||||
[target performSelector:selector withObject:tex];
|
data->filename = fullpath.c_str();
|
||||||
return;
|
data->target = target;
|
||||||
}
|
data->selector = selector;
|
||||||
|
|
||||||
// schedule the load
|
// load image in a new thread
|
||||||
|
pthread_t p;
|
||||||
|
pthread_create(&p, NULL, loadImage, (void*)data);
|
||||||
|
}
|
||||||
|
|
||||||
CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init];
|
void CCTextureCache::addImageAsyncCallBack(ccTime dt)
|
||||||
asyncObject.selector = selector;
|
{
|
||||||
asyncObject.target = target;
|
// the image is generated in loading thread
|
||||||
asyncObject.data = filename;
|
if (s_pImageAsync != NULL)
|
||||||
|
{
|
||||||
|
|
||||||
[NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject];
|
SelectorProtocol *target = s_pAsyncObject->target;
|
||||||
[asyncObject release];
|
SEL_CallFuncO selector = s_pAsyncObject->selector;
|
||||||
}*/
|
const char* filename = s_pAsyncObject->filename.c_str();
|
||||||
|
|
||||||
|
// generate texture in render thread
|
||||||
|
CCTexture2D *texture = new CCTexture2D();
|
||||||
|
texture->initWithImage(s_pImageAsync);
|
||||||
|
|
||||||
|
// cache the texture
|
||||||
|
m_pTextures->setObject(texture, filename);
|
||||||
|
texture->autorelease();
|
||||||
|
|
||||||
|
(target->*selector)(texture);
|
||||||
|
|
||||||
|
// the object is newed in addImageAsync() and will be assigned in the loading thread
|
||||||
|
delete s_pAsyncObject;
|
||||||
|
|
||||||
|
delete s_pImageAsync;
|
||||||
|
s_pImageAsync = NULL;
|
||||||
|
|
||||||
|
pthread_cond_signal(&s_condition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CCTexture2D * CCTextureCache::addImage(const char * path)
|
CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
{
|
{
|
||||||
|
@ -180,7 +226,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
// MUTEX:
|
// MUTEX:
|
||||||
// Needed since addImageAsync calls this method from a different thread
|
// Needed since addImageAsync calls this method from a different thread
|
||||||
|
|
||||||
m_pDictLock->lock();
|
//pthread_mutex_lock(m_pDictLock);
|
||||||
|
|
||||||
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
||||||
std::string pathKey = path;
|
std::string pathKey = path;
|
||||||
|
@ -263,7 +309,8 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
|
|
||||||
} while (0);
|
} while (0);
|
||||||
}
|
}
|
||||||
m_pDictLock->unlock();
|
|
||||||
|
//pthread_mutex_unlock(m_pDictLock);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,30 +382,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @todo CGImageRef
|
|
||||||
-(CCTexture2D*) addCGImage: (CGImageRef) imageref forKey: (string & )key
|
|
||||||
{
|
|
||||||
CCAssert(imageref != nil, @"TextureCache: image MUST not be nill");
|
|
||||||
|
|
||||||
CCTexture2D * tex = nil;
|
|
||||||
|
|
||||||
// If key is nil, then create a new texture each time
|
|
||||||
if( key && (tex=[textures objectForKey: key] ) ) {
|
|
||||||
return tex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// prevents overloading the autorelease pool
|
|
||||||
UIImage *image = [[UIImage alloc] initWithCGImage:imageref];
|
|
||||||
tex = [[CCTexture2D alloc] initWithImage: image];
|
|
||||||
[image release];
|
|
||||||
|
|
||||||
if(tex && key)
|
|
||||||
[textures setObject: tex forKey:key];
|
|
||||||
else
|
|
||||||
CCLOG(@"cocos2d: Couldn't add CGImage in CCTextureCache");
|
|
||||||
|
|
||||||
return [tex autorelease];
|
|
||||||
}*/
|
|
||||||
CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
||||||
{
|
{
|
||||||
CCAssert(image != NULL && key != NULL, "TextureCache: image MUST not be nill");
|
CCAssert(image != NULL && key != NULL, "TextureCache: image MUST not be nill");
|
||||||
|
@ -367,7 +391,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
||||||
// textureForKey() use full path,so the key should be full path
|
// textureForKey() use full path,so the key should be full path
|
||||||
std::string forKey = CCFileUtils::fullPathFromRelativePath(key);
|
std::string forKey = CCFileUtils::fullPathFromRelativePath(key);
|
||||||
|
|
||||||
m_pDictLock->lock();
|
//m_pDictLock->lock();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -393,7 +417,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
||||||
|
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
m_pDictLock->unlock();
|
//m_pDictLock->unlock();
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
3aab8d3693dcaba52bbe6cf1d88bd085701c71bb
|
84d1a5cd21bd26c8e2f08241d504b59fe40defc9
|
|
@ -1 +1 @@
|
||||||
2905515c8c42c8a1603230ed28549aa28e4ae3f1
|
36888561783556c80b0635d13bbdcc7e285fa0f3
|
|
@ -1 +1 @@
|
||||||
b59f29f9bd284c46876e7ecc47b74bfaf8a00aa6
|
866c5fd880bbb121951818d47d13a4ee914279ad
|
|
@ -1 +1 @@
|
||||||
60da72586f63e425b1e85a7a0cee1d798e59c843
|
6b542917dfd2180ff6c55bca6cd7b30c64c4a300
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# set params
|
# set params
|
||||||
ANDROID_NDK_ROOT=/home/laschweinski/android/android-ndk-r5/
|
ANDROID_NDK_ROOT=/cygdrive/d/programe/android/ndk/android-ndk-r5
|
||||||
COCOS2DX_ROOT=/home/laschweinski/git/cocos2d-x
|
COCOS2DX_ROOT=/cygdrive/e/cocos2d-x
|
||||||
TESTS_ROOT=$COCOS2DX_ROOT/tests/test.android
|
TESTS_ROOT=$COCOS2DX_ROOT/tests/test.android
|
||||||
|
|
||||||
# make sure assets is exist
|
# make sure assets is exist
|
||||||
|
|
|
@ -76,6 +76,7 @@ LOCAL_SRC_FILES := main.cpp \
|
||||||
../../../tests/SceneTest/SceneTest.cpp \
|
../../../tests/SceneTest/SceneTest.cpp \
|
||||||
../../../tests/SchedulerTest/SchedulerTest.cpp \
|
../../../tests/SchedulerTest/SchedulerTest.cpp \
|
||||||
../../../tests/SpriteTest/SpriteTest.cpp \
|
../../../tests/SpriteTest/SpriteTest.cpp \
|
||||||
|
../../../tests/TextureCacheTest/TextureCacheTest.cpp \
|
||||||
../../../tests/Texture2dTest/Texture2dTest.cpp \
|
../../../tests/Texture2dTest/Texture2dTest.cpp \
|
||||||
../../../tests/TileMapTest/TileMapTest.cpp \
|
../../../tests/TileMapTest/TileMapTest.cpp \
|
||||||
../../../tests/TouchesTest/Ball.cpp \
|
../../../tests/TouchesTest/Ball.cpp \
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
3df87510e48dfe7e5c768dcef3f4fd6eb99a129b
|
0031a29bb750c1b41620d51dbb052daa823edcd4
|
|
@ -89,6 +89,7 @@ OBJECTS = ../tests/AccelerometerTest/AccelerometerTest.o \
|
||||||
../tests/SchedulerTest/SchedulerTest.o \
|
../tests/SchedulerTest/SchedulerTest.o \
|
||||||
../tests/SpriteTest/SpriteTest.o \
|
../tests/SpriteTest/SpriteTest.o \
|
||||||
../tests/TextInputTest/TextInputTest.o \
|
../tests/TextInputTest/TextInputTest.o \
|
||||||
|
../tests/TextureCacheTest/TextureCacheTest.o \
|
||||||
../tests/Texture2dTest/Texture2dTest.o \
|
../tests/Texture2dTest/Texture2dTest.o \
|
||||||
../tests/TileMapTest/TileMapTest.o \
|
../tests/TileMapTest/TileMapTest.o \
|
||||||
../tests/TouchesTest/Ball.o \
|
../tests/TouchesTest/Ball.o \
|
||||||
|
|
|
@ -1107,6 +1107,18 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="TextureCacheTest"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\tests\TextureCacheTest\TextureCacheTest.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\tests\TextureCacheTest\TextureCacheTest.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
|
|
|
@ -124,6 +124,7 @@
|
||||||
<ClCompile Include="..\tests\DirectorTest\DirectorTest.cpp" />
|
<ClCompile Include="..\tests\DirectorTest\DirectorTest.cpp" />
|
||||||
<ClCompile Include="..\tests\FontTest\FontTest.cpp" />
|
<ClCompile Include="..\tests\FontTest\FontTest.cpp" />
|
||||||
<ClCompile Include="..\tests\Texture2dTest\Texture2dTest.cpp" />
|
<ClCompile Include="..\tests\Texture2dTest\Texture2dTest.cpp" />
|
||||||
|
<ClCompile Include="..\tests\TextureCacheTest\TextureCacheTest.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="..\AppDelegate.cpp" />
|
<ClCompile Include="..\AppDelegate.cpp" />
|
||||||
<ClCompile Include="..\tests\controller.cpp" />
|
<ClCompile Include="..\tests\controller.cpp" />
|
||||||
|
@ -210,6 +211,7 @@
|
||||||
<ClInclude Include="..\tests\DirectorTest\DirectorTest.h" />
|
<ClInclude Include="..\tests\DirectorTest\DirectorTest.h" />
|
||||||
<ClInclude Include="..\tests\FontTest\FontTest.h" />
|
<ClInclude Include="..\tests\FontTest\FontTest.h" />
|
||||||
<ClInclude Include="..\tests\Texture2dTest\Texture2dTest.h" />
|
<ClInclude Include="..\tests\Texture2dTest\Texture2dTest.h" />
|
||||||
|
<ClInclude Include="..\tests\TextureCacheTest\TextureCacheTest.h" />
|
||||||
<ClInclude Include="main.h" />
|
<ClInclude Include="main.h" />
|
||||||
<ClInclude Include="..\AppDelegate.h" />
|
<ClInclude Include="..\AppDelegate.h" />
|
||||||
<ClInclude Include="..\tests\controller.h" />
|
<ClInclude Include="..\tests\controller.h" />
|
||||||
|
|
|
@ -136,6 +136,9 @@
|
||||||
<Filter Include="classes\tests\CurrentLanguageTest">
|
<Filter Include="classes\tests\CurrentLanguageTest">
|
||||||
<UniqueIdentifier>{178ed769-203d-47d0-92a4-de8668c4df58}</UniqueIdentifier>
|
<UniqueIdentifier>{178ed769-203d-47d0-92a4-de8668c4df58}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="classes\tests\TextureCacheTest">
|
||||||
|
<UniqueIdentifier>{17b9b23c-1ef6-466e-a2ab-c558f4015698}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
|
@ -390,6 +393,9 @@
|
||||||
<ClCompile Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.cpp">
|
<ClCompile Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.cpp">
|
||||||
<Filter>classes\tests\CurrentLanguageTest</Filter>
|
<Filter>classes\tests\CurrentLanguageTest</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\tests\TextureCacheTest\TextureCacheTest.cpp">
|
||||||
|
<Filter>classes\tests\TextureCacheTest</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="main.h">
|
<ClInclude Include="main.h">
|
||||||
|
@ -704,5 +710,8 @@
|
||||||
<ClInclude Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.h">
|
<ClInclude Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.h">
|
||||||
<Filter>classes\tests\CurrentLanguageTest</Filter>
|
<Filter>classes\tests\CurrentLanguageTest</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\tests\TextureCacheTest\TextureCacheTest.h">
|
||||||
|
<Filter>classes\tests\TextureCacheTest</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -0,0 +1,143 @@
|
||||||
|
// enable log
|
||||||
|
#define COCOS2D_DEBUG 1
|
||||||
|
|
||||||
|
#include "TextureCacheTest.h"
|
||||||
|
|
||||||
|
TextureCacheTest::TextureCacheTest()
|
||||||
|
: m_nNumberOfSprites(24)
|
||||||
|
, m_nNumberOfLoadedSprites(0)
|
||||||
|
{
|
||||||
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
m_pLabelLoading = CCLabelTTF::labelWithString("loading...", "Arial", 15);
|
||||||
|
m_pLabelPercent = CCLabelTTF::labelWithString("%0", "Arial", 15);
|
||||||
|
|
||||||
|
m_pLabelLoading->setPosition(CCPointMake(size.width / 2, size.height / 2 - 20));
|
||||||
|
m_pLabelPercent->setPosition(CCPointMake(size.width / 2, size.height / 2 + 20));
|
||||||
|
|
||||||
|
this->addChild(m_pLabelLoading);
|
||||||
|
this->addChild(m_pLabelPercent);
|
||||||
|
|
||||||
|
// load textrues
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/HelloWorld.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_01.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_02.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_03.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_04.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_05.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_06.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_07.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_08.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_09.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_10.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_11.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_12.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_13.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_14.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background1.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background2.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background3.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background1-hd.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background2-hd.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background3-hd.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/blocks.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/blocks-hd.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureCacheTest::loadingCallBack(CCObject *obj)
|
||||||
|
{
|
||||||
|
++m_nNumberOfLoadedSprites;
|
||||||
|
char tmp[10];
|
||||||
|
sprintf(tmp,"%%%d", (int)(((float)m_nNumberOfLoadedSprites / m_nNumberOfSprites) * 100));
|
||||||
|
m_pLabelPercent->setString(tmp);
|
||||||
|
|
||||||
|
if (m_nNumberOfLoadedSprites == m_nNumberOfSprites)
|
||||||
|
{
|
||||||
|
this->removeChild(m_pLabelLoading, true);
|
||||||
|
this->removeChild(m_pLabelPercent, true);
|
||||||
|
addSprite();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureCacheTest::addSprite()
|
||||||
|
{
|
||||||
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
// create sprites
|
||||||
|
|
||||||
|
CCSprite *bg = CCSprite::spriteWithFile("Images/HelloWorld.png");
|
||||||
|
bg->setPosition(CCPointMake(size.width / 2, size.height / 2));
|
||||||
|
|
||||||
|
CCSprite *s1 = CCSprite::spriteWithFile("Images/grossini.png");
|
||||||
|
CCSprite *s2 = CCSprite::spriteWithFile("Images/grossini_dance_01.png");
|
||||||
|
CCSprite *s3 = CCSprite::spriteWithFile("Images/grossini_dance_02.png");
|
||||||
|
CCSprite *s4 = CCSprite::spriteWithFile("Images/grossini_dance_03.png");
|
||||||
|
CCSprite *s5 = CCSprite::spriteWithFile("Images/grossini_dance_04.png");
|
||||||
|
CCSprite *s6 = CCSprite::spriteWithFile("Images/grossini_dance_05.png");
|
||||||
|
CCSprite *s7 = CCSprite::spriteWithFile("Images/grossini_dance_06.png");
|
||||||
|
CCSprite *s8 = CCSprite::spriteWithFile("Images/grossini_dance_07.png");
|
||||||
|
CCSprite *s9 = CCSprite::spriteWithFile("Images/grossini_dance_08.png");
|
||||||
|
CCSprite *s10 = CCSprite::spriteWithFile("Images/grossini_dance_09.png");
|
||||||
|
CCSprite *s11 = CCSprite::spriteWithFile("Images/grossini_dance_10.png");
|
||||||
|
CCSprite *s12 = CCSprite::spriteWithFile("Images/grossini_dance_11.png");
|
||||||
|
CCSprite *s13 = CCSprite::spriteWithFile("Images/grossini_dance_12.png");
|
||||||
|
CCSprite *s14 = CCSprite::spriteWithFile("Images/grossini_dance_13.png");
|
||||||
|
CCSprite *s15 = CCSprite::spriteWithFile("Images/grossini_dance_14.png");
|
||||||
|
|
||||||
|
// just loading textures to slow down
|
||||||
|
CCSprite *s16 = CCSprite::spriteWithFile("Images/background1.png");
|
||||||
|
CCSprite *s17 = CCSprite::spriteWithFile("Images/background2.png");
|
||||||
|
CCSprite *s18 = CCSprite::spriteWithFile("Images/background3.png");
|
||||||
|
CCSprite *s19 = CCSprite::spriteWithFile("Images/background1-hd.png");
|
||||||
|
CCSprite *s20 = CCSprite::spriteWithFile("Images/background2-hd.png");
|
||||||
|
CCSprite *s21 = CCSprite::spriteWithFile("Images/background3-hd.png");
|
||||||
|
CCSprite *s22 = CCSprite::spriteWithFile("Images/blocks.png");
|
||||||
|
CCSprite *s23 = CCSprite::spriteWithFile("Images/blocks-hd.png");
|
||||||
|
|
||||||
|
s1->setPosition(CCPointMake(50, 50));
|
||||||
|
s2->setPosition(CCPointMake(60, 50));
|
||||||
|
s3->setPosition(CCPointMake(70, 50));
|
||||||
|
s4->setPosition(CCPointMake(80, 50));
|
||||||
|
s5->setPosition(CCPointMake(90, 50));
|
||||||
|
s6->setPosition(CCPointMake(100, 50));
|
||||||
|
|
||||||
|
s7->setPosition(CCPointMake(50, 180));
|
||||||
|
s8->setPosition(CCPointMake(60, 180));
|
||||||
|
s9->setPosition(CCPointMake(70, 180));
|
||||||
|
s10->setPosition(CCPointMake(80, 180));
|
||||||
|
s11->setPosition(CCPointMake(90, 180));
|
||||||
|
s12->setPosition(CCPointMake(100, 180));
|
||||||
|
|
||||||
|
s13->setPosition(CCPointMake(50, 270));
|
||||||
|
s14->setPosition(CCPointMake(60, 270));
|
||||||
|
s15->setPosition(CCPointMake(70, 270));
|
||||||
|
|
||||||
|
this->addChild(bg);
|
||||||
|
|
||||||
|
this->addChild(s1);
|
||||||
|
this->addChild(s2);
|
||||||
|
this->addChild(s3);
|
||||||
|
this->addChild(s4);
|
||||||
|
this->addChild(s5);
|
||||||
|
this->addChild(s6);
|
||||||
|
this->addChild(s7);
|
||||||
|
this->addChild(s8);
|
||||||
|
this->addChild(s9);
|
||||||
|
this->addChild(s10);
|
||||||
|
this->addChild(s11);
|
||||||
|
this->addChild(s12);
|
||||||
|
this->addChild(s13);
|
||||||
|
this->addChild(s14);
|
||||||
|
this->addChild(s15);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TextureCacheTestScene::runThisTest()
|
||||||
|
{
|
||||||
|
CCLayer* pLayer = new TextureCacheTest();
|
||||||
|
addChild(pLayer);
|
||||||
|
|
||||||
|
CCDirector::sharedDirector()->replaceScene(this);
|
||||||
|
pLayer->release();
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef _TEXTURECACHE_TEST_H_
|
||||||
|
#define _TEXTURECACHE_TEST_H_
|
||||||
|
|
||||||
|
#include "cocos2d.h"
|
||||||
|
#include "../testBasic.h"
|
||||||
|
|
||||||
|
class TextureCacheTest : public CCLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextureCacheTest();
|
||||||
|
void addSprite();
|
||||||
|
void loadingCallBack(cocos2d::CCObject *obj);
|
||||||
|
|
||||||
|
private:
|
||||||
|
cocos2d::CCLabelTTF *m_pLabelLoading;
|
||||||
|
cocos2d::CCLabelTTF *m_pLabelPercent;
|
||||||
|
int m_nNumberOfSprites;
|
||||||
|
int m_nNumberOfLoadedSprites;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextureCacheTestScene : public TestScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void runThisTest();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _TEXTURECACHE_TEST_H_
|
|
@ -111,7 +111,7 @@ static TestScene* CreateTestScene(int nIdx)
|
||||||
pScene = new FontTestScene(); break;
|
pScene = new FontTestScene(); break;
|
||||||
case TEST_CURRENT_LANGUAGE:
|
case TEST_CURRENT_LANGUAGE:
|
||||||
pScene = new CurrentLanguageTestScene(); break;
|
pScene = new CurrentLanguageTestScene(); break;
|
||||||
break;
|
case TEST_TEXTURECACHE: pScene = new TextureCacheTestScene(); break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "Texture2dTest/Texture2dTest.h"
|
#include "Texture2dTest/Texture2dTest.h"
|
||||||
#include "FontTest/FontTest.h"
|
#include "FontTest/FontTest.h"
|
||||||
#include "CurrentLanguageTest/CurrentLanguageTest.h"
|
#include "CurrentLanguageTest/CurrentLanguageTest.h"
|
||||||
|
#include "TextureCacheTest/TextureCacheTest.h"
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
|
||||||
#include "ChipmunkTest/cocos2dChipmunkDemo.h"
|
#include "ChipmunkTest/cocos2dChipmunkDemo.h"
|
||||||
|
@ -98,6 +99,7 @@ enum
|
||||||
TEST_BUGS,
|
TEST_BUGS,
|
||||||
TEST_FONTS,
|
TEST_FONTS,
|
||||||
TEST_CURRENT_LANGUAGE,
|
TEST_CURRENT_LANGUAGE,
|
||||||
|
TEST_TEXTURECACHE,
|
||||||
|
|
||||||
TESTS_COUNT,
|
TESTS_COUNT,
|
||||||
};
|
};
|
||||||
|
@ -144,6 +146,7 @@ const std::string g_aTestNames[TESTS_COUNT] = {
|
||||||
"BugsTest",
|
"BugsTest",
|
||||||
"FontTest",
|
"FontTest",
|
||||||
"CurrentLanguageTest",
|
"CurrentLanguageTest",
|
||||||
|
"TextureCacheTest"
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue