mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3
This commit is contained in:
commit
7e8d1bb74c
|
@ -1,4 +1,5 @@
|
||||||
cocos2d-x-3.4rc0 Jan.9 2015
|
cocos2d-x-3.4rc0 Jan.9 2015
|
||||||
|
[FIX] HttpClient: http requests will be lost in immediately mode on iOS
|
||||||
[FIX] WP8: compiling error on ARM architecture
|
[FIX] WP8: compiling error on ARM architecture
|
||||||
|
|
||||||
cocos2d-x-3.4beta0 Dec.31 2014
|
cocos2d-x-3.4beta0 Dec.31 2014
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
using namespace cocos2d::experimental;
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
const int AudioEngine::INVAILD_AUDIO_ID = -1;
|
const int AudioEngine::INVALID_AUDIO_ID = -1;
|
||||||
const float AudioEngine::TIME_UNKNOWN = -1.0f;
|
const float AudioEngine::TIME_UNKNOWN = -1.0f;
|
||||||
|
|
||||||
//audio file path,audio IDs
|
//audio file path,audio IDs
|
||||||
|
@ -85,7 +85,7 @@ bool AudioEngine::lazyInit()
|
||||||
|
|
||||||
int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, const AudioProfile *profile)
|
int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, const AudioProfile *profile)
|
||||||
{
|
{
|
||||||
int ret = AudioEngine::INVAILD_AUDIO_ID;
|
int ret = AudioEngine::INVALID_AUDIO_ID;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if ( !lazyInit() ){
|
if ( !lazyInit() ){
|
||||||
|
@ -130,7 +130,7 @@ int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, co
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _audioEngineImpl->play2d(filePath, loop, volume);
|
ret = _audioEngineImpl->play2d(filePath, loop, volume);
|
||||||
if (ret != INVAILD_AUDIO_ID)
|
if (ret != INVALID_AUDIO_ID)
|
||||||
{
|
{
|
||||||
_audioPathIDMap[filePath].push_back(ret);
|
_audioPathIDMap[filePath].push_back(ret);
|
||||||
auto it = _audioPathIDMap.find(filePath);
|
auto it = _audioPathIDMap.find(filePath);
|
||||||
|
|
|
@ -229,7 +229,7 @@ bool AudioEngineImpl::init()
|
||||||
|
|
||||||
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
||||||
{
|
{
|
||||||
auto audioId = AudioEngine::INVAILD_AUDIO_ID;
|
auto audioId = AudioEngine::INVALID_AUDIO_ID;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
|
@ -187,7 +187,7 @@ bool AudioEngineImpl::init()
|
||||||
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
||||||
{
|
{
|
||||||
if (s_ALDevice == nullptr) {
|
if (s_ALDevice == nullptr) {
|
||||||
return AudioEngine::INVAILD_AUDIO_ID;
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sourceFlag = false;
|
bool sourceFlag = false;
|
||||||
|
@ -201,7 +201,7 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!sourceFlag){
|
if(!sourceFlag){
|
||||||
return AudioEngine::INVAILD_AUDIO_ID;
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioCache* audioCache = nullptr;
|
AudioCache* audioCache = nullptr;
|
||||||
|
|
|
@ -81,7 +81,7 @@ public:
|
||||||
PAUSED
|
PAUSED
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int INVAILD_AUDIO_ID;
|
static const int INVALID_AUDIO_ID;
|
||||||
|
|
||||||
static const float TIME_UNKNOWN;
|
static const float TIME_UNKNOWN;
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!availableSourceExist){
|
if(!availableSourceExist){
|
||||||
return AudioEngine::INVAILD_AUDIO_ID;
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioCache* audioCache = nullptr;
|
AudioCache* audioCache = nullptr;
|
||||||
|
@ -244,7 +244,7 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||||
|
|
||||||
if (eraseCache){
|
if (eraseCache){
|
||||||
_audioCaches.erase(filePath);
|
_audioCaches.erase(filePath);
|
||||||
return AudioEngine::INVAILD_AUDIO_ID;
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||||
|
|
|
@ -43,8 +43,6 @@
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
#define ERROR_SIZE 256
|
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
static std::mutex s_requestQueueMutex;
|
static std::mutex s_requestQueueMutex;
|
||||||
|
@ -55,10 +53,11 @@ static std::condition_variable_any s_SleepCondition;
|
||||||
static Vector<HttpRequest*>* s_requestQueue = nullptr;
|
static Vector<HttpRequest*>* s_requestQueue = nullptr;
|
||||||
static Vector<HttpResponse*>* s_responseQueue = nullptr;
|
static Vector<HttpResponse*>* s_responseQueue = nullptr;
|
||||||
|
|
||||||
static HttpClient *s_pHttpClient = nullptr; // pointer to singleton
|
static HttpClient *s_HttpClient = nullptr; // pointer to singleton
|
||||||
|
|
||||||
static HttpAsynConnection *httpAsynConn = nullptr;
|
|
||||||
static HttpCookie *s_cookie = nullptr;
|
static HttpCookie *s_cookie = nullptr;
|
||||||
|
|
||||||
|
static const int ERROR_SIZE = 256;
|
||||||
|
|
||||||
static char s_errorBuffer[ERROR_SIZE] = {0};
|
static char s_errorBuffer[ERROR_SIZE] = {0};
|
||||||
|
|
||||||
|
@ -106,7 +105,7 @@ void HttpClient::networkThread()
|
||||||
s_responseQueue->pushBack(response);
|
s_responseQueue->pushBack(response);
|
||||||
s_responseQueueMutex.unlock();
|
s_responseQueueMutex.unlock();
|
||||||
|
|
||||||
if (nullptr != s_pHttpClient) {
|
if (nullptr != s_HttpClient) {
|
||||||
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this));
|
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,11 +141,11 @@ void HttpClient::networkThreadAlone(HttpRequest* request)
|
||||||
|
|
||||||
if (callback != nullptr)
|
if (callback != nullptr)
|
||||||
{
|
{
|
||||||
callback(s_pHttpClient, response);
|
callback(s_HttpClient, response);
|
||||||
}
|
}
|
||||||
else if (pTarget && pSelector)
|
else if (pTarget && pSelector)
|
||||||
{
|
{
|
||||||
(pTarget->*pSelector)(s_pHttpClient, response);
|
(pTarget->*pSelector)(s_HttpClient, response);
|
||||||
}
|
}
|
||||||
response->release();
|
response->release();
|
||||||
// do not release in other thread
|
// do not release in other thread
|
||||||
|
@ -218,7 +217,7 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpAsynConn = [HttpAsynConnection new];
|
HttpAsynConnection *httpAsynConn = [HttpAsynConnection new];
|
||||||
httpAsynConn.srcURL = urlstring;
|
httpAsynConn.srcURL = urlstring;
|
||||||
httpAsynConn.sslFile = nil;
|
httpAsynConn.sslFile = nil;
|
||||||
NSString *sslFile = nil;
|
NSString *sslFile = nil;
|
||||||
|
@ -256,7 +255,7 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream
|
||||||
NSString *domain = cookie.domain;
|
NSString *domain = cookie.domain;
|
||||||
//BOOL session = cookie.sessionOnly;
|
//BOOL session = cookie.sessionOnly;
|
||||||
NSString *path = cookie.path;
|
NSString *path = cookie.path;
|
||||||
BOOL secure = cookie.secure;
|
BOOL secure = cookie.isSecure;
|
||||||
NSDate *date = cookie.expiresDate;
|
NSDate *date = cookie.expiresDate;
|
||||||
NSString *name = cookie.name;
|
NSString *name = cookie.name;
|
||||||
NSString *value = cookie.value;
|
NSString *value = cookie.value;
|
||||||
|
@ -356,16 +355,16 @@ static void processResponse(HttpResponse* response, char* errorBuffer)
|
||||||
// HttpClient implementation
|
// HttpClient implementation
|
||||||
HttpClient* HttpClient::getInstance()
|
HttpClient* HttpClient::getInstance()
|
||||||
{
|
{
|
||||||
if (s_pHttpClient == nullptr) {
|
if (s_HttpClient == nullptr) {
|
||||||
s_pHttpClient = new (std::nothrow) HttpClient();
|
s_HttpClient = new (std::nothrow) HttpClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
return s_pHttpClient;
|
return s_HttpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpClient::destroyInstance()
|
void HttpClient::destroyInstance()
|
||||||
{
|
{
|
||||||
CC_SAFE_DELETE(s_pHttpClient);
|
CC_SAFE_DELETE(s_HttpClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpClient::enableCookies(const char* cookieFile) {
|
void HttpClient::enableCookies(const char* cookieFile) {
|
||||||
|
@ -403,7 +402,7 @@ HttpClient::~HttpClient()
|
||||||
s_SleepCondition.notify_one();
|
s_SleepCondition.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
s_pHttpClient = nullptr;
|
s_HttpClient = nullptr;
|
||||||
|
|
||||||
if(!s_cookieFilename.empty())
|
if(!s_cookieFilename.empty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -347,7 +347,7 @@ std::string AudioEngineTestDemo::title() const
|
||||||
bool AudioControlTest::init()
|
bool AudioControlTest::init()
|
||||||
{
|
{
|
||||||
auto ret = AudioEngineTestDemo::init();
|
auto ret = AudioEngineTestDemo::init();
|
||||||
_audioID = AudioEngine::INVAILD_AUDIO_ID;
|
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
||||||
_loopEnabled = false;
|
_loopEnabled = false;
|
||||||
_volume = 1.0f;
|
_volume = 1.0f;
|
||||||
_duration = AudioEngine::TIME_UNKNOWN;
|
_duration = AudioEngine::TIME_UNKNOWN;
|
||||||
|
@ -359,13 +359,13 @@ bool AudioControlTest::init()
|
||||||
auto& layerSize = this->getContentSize();
|
auto& layerSize = this->getContentSize();
|
||||||
|
|
||||||
auto playItem = TextButton::create("play", [&](TextButton* button){
|
auto playItem = TextButton::create("play", [&](TextButton* button){
|
||||||
if (_audioID == AudioEngine::INVAILD_AUDIO_ID) {
|
if (_audioID == AudioEngine::INVALID_AUDIO_ID) {
|
||||||
_audioID = AudioEngine::play2d("background.mp3", _loopEnabled, _volume);
|
_audioID = AudioEngine::play2d("background.mp3", _loopEnabled, _volume);
|
||||||
|
|
||||||
if(_audioID != AudioEngine::INVAILD_AUDIO_ID) {
|
if(_audioID != AudioEngine::INVALID_AUDIO_ID) {
|
||||||
button->setEnabled(false);
|
button->setEnabled(false);
|
||||||
AudioEngine::setFinishCallback(_audioID, [&](int id, const std::string& filePath){
|
AudioEngine::setFinishCallback(_audioID, [&](int id, const std::string& filePath){
|
||||||
_audioID = AudioEngine::INVAILD_AUDIO_ID;
|
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
||||||
((TextButton*)_playItem)->setEnabled(true);
|
((TextButton*)_playItem)->setEnabled(true);
|
||||||
|
|
||||||
_timeRatio = 0.0f;
|
_timeRatio = 0.0f;
|
||||||
|
@ -379,10 +379,10 @@ bool AudioControlTest::init()
|
||||||
addChild(playItem);
|
addChild(playItem);
|
||||||
|
|
||||||
auto stopItem = TextButton::create("stop", [&](TextButton* button){
|
auto stopItem = TextButton::create("stop", [&](TextButton* button){
|
||||||
if (_audioID != AudioEngine::INVAILD_AUDIO_ID ) {
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
|
||||||
AudioEngine::stop(_audioID);
|
AudioEngine::stop(_audioID);
|
||||||
|
|
||||||
_audioID = AudioEngine::INVAILD_AUDIO_ID;
|
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
||||||
((TextButton*)_playItem)->setEnabled(true);
|
((TextButton*)_playItem)->setEnabled(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -390,7 +390,7 @@ bool AudioControlTest::init()
|
||||||
addChild(stopItem);
|
addChild(stopItem);
|
||||||
|
|
||||||
auto pauseItem = TextButton::create("pause", [&](TextButton* button){
|
auto pauseItem = TextButton::create("pause", [&](TextButton* button){
|
||||||
if (_audioID != AudioEngine::INVAILD_AUDIO_ID ) {
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
|
||||||
AudioEngine::pause(_audioID);
|
AudioEngine::pause(_audioID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -398,7 +398,7 @@ bool AudioControlTest::init()
|
||||||
addChild(pauseItem);
|
addChild(pauseItem);
|
||||||
|
|
||||||
auto resumeItem = TextButton::create("resume", [&](TextButton* button){
|
auto resumeItem = TextButton::create("resume", [&](TextButton* button){
|
||||||
if (_audioID != AudioEngine::INVAILD_AUDIO_ID ) {
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
|
||||||
AudioEngine::resume(_audioID);
|
AudioEngine::resume(_audioID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -408,7 +408,7 @@ bool AudioControlTest::init()
|
||||||
auto loopItem = TextButton::create("enable-loop", [&](TextButton* button){
|
auto loopItem = TextButton::create("enable-loop", [&](TextButton* button){
|
||||||
_loopEnabled = !_loopEnabled;
|
_loopEnabled = !_loopEnabled;
|
||||||
|
|
||||||
if (_audioID != AudioEngine::INVAILD_AUDIO_ID ) {
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
|
||||||
AudioEngine::setLoop(_audioID, _loopEnabled);
|
AudioEngine::setLoop(_audioID, _loopEnabled);
|
||||||
}
|
}
|
||||||
if(_loopEnabled){
|
if(_loopEnabled){
|
||||||
|
@ -424,7 +424,7 @@ bool AudioControlTest::init()
|
||||||
auto uncacheItem = TextButton::create("uncache", [&](TextButton* button){
|
auto uncacheItem = TextButton::create("uncache", [&](TextButton* button){
|
||||||
AudioEngine::uncache("background.mp3");
|
AudioEngine::uncache("background.mp3");
|
||||||
|
|
||||||
_audioID = AudioEngine::INVAILD_AUDIO_ID;
|
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
||||||
((TextButton*)_playItem)->setEnabled(true);
|
((TextButton*)_playItem)->setEnabled(true);
|
||||||
});
|
});
|
||||||
uncacheItem->setPosition(layerSize.width * 0.7f,layerSize.height * 0.5f);
|
uncacheItem->setPosition(layerSize.width * 0.7f,layerSize.height * 0.5f);
|
||||||
|
@ -434,7 +434,7 @@ bool AudioControlTest::init()
|
||||||
volumeSlider->setPercent(100);
|
volumeSlider->setPercent(100);
|
||||||
volumeSlider->setCallBack([&](SliderEx* sender,float ratio,SliderEx::TouchEvent event){
|
volumeSlider->setCallBack([&](SliderEx* sender,float ratio,SliderEx::TouchEvent event){
|
||||||
_volume = ratio;
|
_volume = ratio;
|
||||||
if (_audioID != AudioEngine::INVAILD_AUDIO_ID ) {
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
|
||||||
AudioEngine::setVolume(_audioID, _volume);
|
AudioEngine::setVolume(_audioID, _volume);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -449,7 +449,7 @@ bool AudioControlTest::init()
|
||||||
_updateTimeSlider = false;
|
_updateTimeSlider = false;
|
||||||
break;
|
break;
|
||||||
case SliderEx::TouchEvent::UP:
|
case SliderEx::TouchEvent::UP:
|
||||||
if (_audioID != AudioEngine::INVAILD_AUDIO_ID && _duration != AudioEngine::TIME_UNKNOWN) {
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID && _duration != AudioEngine::TIME_UNKNOWN) {
|
||||||
AudioEngine::setCurrentTime(_audioID,_duration * ratio);
|
AudioEngine::setCurrentTime(_audioID,_duration * ratio);
|
||||||
}
|
}
|
||||||
case SliderEx::TouchEvent::CANCEL:
|
case SliderEx::TouchEvent::CANCEL:
|
||||||
|
@ -481,7 +481,7 @@ bool AudioControlTest::init()
|
||||||
|
|
||||||
void AudioControlTest::update(float dt)
|
void AudioControlTest::update(float dt)
|
||||||
{
|
{
|
||||||
if (_audioID != AudioEngine::INVAILD_AUDIO_ID ) {
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
|
||||||
if(_duration == AudioEngine::TIME_UNKNOWN){
|
if(_duration == AudioEngine::TIME_UNKNOWN){
|
||||||
_duration = AudioEngine::getDuration(_audioID);
|
_duration = AudioEngine::getDuration(_audioID);
|
||||||
}
|
}
|
||||||
|
@ -524,7 +524,7 @@ bool PlaySimultaneouslyTest::init()
|
||||||
auto startTime = utils::gettime();
|
auto startTime = utils::gettime();
|
||||||
for(int index = 0; index < TEST_COUNT; ++index){
|
for(int index = 0; index < TEST_COUNT; ++index){
|
||||||
audioId = AudioEngine::play2d(_files[index]);
|
audioId = AudioEngine::play2d(_files[index]);
|
||||||
if(audioId != AudioEngine::INVAILD_AUDIO_ID){
|
if(audioId != AudioEngine::INVALID_AUDIO_ID){
|
||||||
_playingcount += 1;
|
_playingcount += 1;
|
||||||
|
|
||||||
AudioEngine::setFinishCallback(audioId, [&](int id, const std::string& filePath){
|
AudioEngine::setFinishCallback(audioId, [&](int id, const std::string& filePath){
|
||||||
|
@ -584,7 +584,7 @@ bool AudioProfileTest::init()
|
||||||
auto playItem = TextButton::create(text, [&](TextButton* button){
|
auto playItem = TextButton::create(text, [&](TextButton* button){
|
||||||
int index = button->getTag();
|
int index = button->getTag();
|
||||||
auto id = AudioEngine::play2d(_files[index], false, 1.0f, &_audioProfile);
|
auto id = AudioEngine::play2d(_files[index], false, 1.0f, &_audioProfile);
|
||||||
if(id != AudioEngine::INVAILD_AUDIO_ID){
|
if(id != AudioEngine::INVALID_AUDIO_ID){
|
||||||
_time = _minDelay;
|
_time = _minDelay;
|
||||||
_audioCount += 1;
|
_audioCount += 1;
|
||||||
char show[30];
|
char show[30];
|
||||||
|
|
Loading…
Reference in New Issue