From 7b9c15176e79c9f4186a936808a60997280361f6 Mon Sep 17 00:00:00 2001 From: ncrothe Date: Sat, 22 Sep 2012 17:45:02 +0300 Subject: [PATCH 01/15] Update extensions/network/HttpRequest.h --- extensions/network/HttpRequest.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/extensions/network/HttpRequest.h b/extensions/network/HttpRequest.h index 89c1a3f812..ef4ca4a3a0 100644 --- a/extensions/network/HttpRequest.h +++ b/extensions/network/HttpRequest.h @@ -175,7 +175,20 @@ public: { return _pSelector; } - + + /** Set any custom headers **/ + inline void setHeaders(std::vector pHeaders) + { + _headers=pHeaders; + } + + /** Get custom headers **/ + inline std::vector getHeaders() + { + return _headers; + } + + protected: // properties HttpRequestType _requestType; /// kHttpRequestGet, kHttpRequestPost or other enums @@ -185,6 +198,7 @@ protected: cocos2d::CCObject* _pTarget; /// callback target of pSelector function cocos2d::SEL_CallFuncND _pSelector; /// callback function, e.g. MyLayer::onHttpResponse(CCObject *sender, void *data) void* _pUserData; /// You can add your customed data here + std::vector _headers; /// custom http headers }; NS_CC_EXT_END From b3f5a04ad426acdf90ec353e73302a1c75bacf14 Mon Sep 17 00:00:00 2001 From: ncrothe Date: Sat, 22 Sep 2012 17:52:04 +0300 Subject: [PATCH 02/15] Update extensions/network/HttpClient.cpp Added custom header capability to http wrapper (using curl features). This allows setting non-default content-type for POSTs. --- extensions/network/HttpClient.cpp | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/extensions/network/HttpClient.cpp b/extensions/network/HttpClient.cpp index 1fa241540c..d40c6d0d41 100644 --- a/extensions/network/HttpClient.cpp +++ b/extensions/network/HttpClient.cpp @@ -246,6 +246,25 @@ int processGetTask(CCHttpRequest *request, write_callback callback, void *stream break; } + /* handle custom header data */ + /* create curl linked list */ + struct curl_slist *cHeaders=NULL; + /* get custom header data (if set) */ + std::vector headers=request->getHeaders(); + if(!headers.empty()) + { + for(std::vector::iterator it=headers.begin();it!=headers.end();it++) + { + /* append custom headers one by one */ + cHeaders=curl_slist_append(cHeaders,it->c_str()); + } + /* set custom headers for curl */ + code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, cHeaders); + if (code != CURLE_OK) { + break; + } + } + code = curl_easy_setopt(curl, CURLOPT_URL, request->getUrl()); if (code != CURLE_OK) { @@ -276,6 +295,9 @@ int processGetTask(CCHttpRequest *request, write_callback callback, void *stream break; } + /* free the linked list for header data */ + curl_slist_free_all(cHeaders); + code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, responseCode); if (code != CURLE_OK || *responseCode != 200) { @@ -301,6 +323,25 @@ int processPostTask(CCHttpRequest *request, write_callback callback, void *strea break; } + /* handle custom header data */ + /* create curl linked list */ + struct curl_slist *cHeaders=NULL; + /* get custom header data (if set) */ + std::vector headers=request->getHeaders(); + if(!headers.empty()) + { + for(std::vector::iterator it=headers.begin();it!=headers.end();it++) + { + /* append custom headers one by one */ + cHeaders=curl_slist_append(cHeaders,it->c_str()); + } + /* set custom headers for curl */ + code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, cHeaders); + if (code != CURLE_OK) { + break; + } + } + code = curl_easy_setopt(curl, CURLOPT_URL, request->getUrl()); if (code != CURLE_OK) { break; @@ -330,6 +371,9 @@ int processPostTask(CCHttpRequest *request, write_callback callback, void *strea break; } + /* free the linked list for header data */ + curl_slist_free_all(cHeaders); + code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, responseCode); if (code != CURLE_OK || *responseCode != 200) { code = CURLE_HTTP_RETURNED_ERROR; From e0fe233752b66d8ba6776719f636029df8836702 Mon Sep 17 00:00:00 2001 From: ncrothe Date: Mon, 24 Sep 2012 12:15:53 +0300 Subject: [PATCH 03/15] Update samples/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp Added test to show use of HttpRequest::setHeaders --- .../NetworkTest/HttpClientTest.cpp | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/samples/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp b/samples/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp index 7a0741db42..abe50a6030 100644 --- a/samples/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp +++ b/samples/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp @@ -101,18 +101,40 @@ void HttpClientTest::onMenuGetTestClicked(cocos2d::CCObject *sender) void HttpClientTest::onMenuPostTestClicked(cocos2d::CCObject *sender) { - CCHttpRequest* request = new CCHttpRequest(); - request->setUrl("http://www.httpbin.org/post"); - request->setRequestType(CCHttpRequest::kHttpPost); - request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted)); + // test 1 + { + CCHttpRequest* request = new CCHttpRequest(); + request->setUrl("http://www.httpbin.org/post"); + request->setRequestType(CCHttpRequest::kHttpPost); + request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted)); + + // write the post data + const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetworkTest"; + request->setRequestData(postData, strlen(postData)); + + request->setTag("POST test1"); + CCHttpClient::getInstance()->send(request); + request->release(); + } - // write the post data - const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetowrkTest"; - request->setRequestData(postData, strlen(postData)); - - request->setTag("POST test"); - CCHttpClient::getInstance()->send(request); - request->release(); + // test 2: set Content-Type + { + CCHttpRequest* request = new CCHttpRequest(); + request->setUrl("http://www.httpbin.org/post"); + request->setRequestType(CCHttpRequest::kHttpPost); + std::vector headers; + headers.push_back("Content-Type: application/json; charset=utf-8"); + request->setHeaders(headers); + request->setResponseCallback(this, callfuncND_selector(HttpClientTest::onHttpRequestCompleted)); + + // write the post data + const char* postData = "visitor=cocos2d&TestSuite=Extensions Test/NetworkTest"; + request->setRequestData(postData, strlen(postData)); + + request->setTag("POST test2"); + CCHttpClient::getInstance()->send(request); + request->release(); + } // waiting m_labelStatusCode->setString("waiting..."); From 2f5613595bf169a2604a68aec71ab2bc818011b6 Mon Sep 17 00:00:00 2001 From: folecr Date: Fri, 27 Jul 2012 17:18:23 -0700 Subject: [PATCH 04/15] Helper script to launch this application via ndk-gdb --- samples/HelloCpp/proj.android/ndkgdb.sh | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 samples/HelloCpp/proj.android/ndkgdb.sh diff --git a/samples/HelloCpp/proj.android/ndkgdb.sh b/samples/HelloCpp/proj.android/ndkgdb.sh new file mode 100755 index 0000000000..27ef46bb1e --- /dev/null +++ b/samples/HelloCpp/proj.android/ndkgdb.sh @@ -0,0 +1,47 @@ +APPNAME="HelloCpp" +APP_ANDROID_NAME="org.cocos2dx.hellocpp" + +if [ -z "${SDK_ROOT+aaa}" ]; then +# ... if SDK_ROOT is not set, use "$HOME/bin/android-sdk" + SDK_ROOT="$HOME/bin/android-sdk" +fi + +if [ -z "${NDK_ROOT+aaa}" ]; then +# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk" + NDK_ROOT="$HOME/bin/android-ndk" +fi + +if [ -z "${COCOS2DX_ROOT+aaa}" ]; then +# ... if COCOS2DX_ROOT is not set +# ... find current working directory + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# ... use paths relative to current directory + COCOS2DX_ROOT="$DIR/../../.." + APP_ROOT="$DIR/.." + APP_ANDROID_ROOT="$DIR" +else + APP_ROOT="$COCOS2DX_ROOT/samples/$APPNAME" + APP_ANDROID_ROOT="$COCOS2DX_ROOT/samples/$APPNAME/proj.android" +fi + +echo "NDK_ROOT = $NDK_ROOT" +echo "SDK_ROOT = $SDK_ROOT" +echo "COCOS2DX_ROOT = $COCOS2DX_ROOT" +echo "APP_ROOT = $APP_ROOT" +echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT" +echo "APP_ANDROID_NAME = $APP_ANDROID_NAME" + +echo +echo "Killing and restarting ${APP_ANDROID_NAME}" +echo + +set -x + +"${SDK_ROOT}"/platform-tools/adb shell am force-stop "${APP_ANDROID_NAME}" + +NDK_MODULE_PATH="${COCOS2DX_ROOT}":"${COCOS2DX_ROOT}"/cocos2dx/platform/third_party/android/prebuilt \ + "${NDK_ROOT}"/ndk-gdb \ + --adb="${SDK_ROOT}"/platform-tools/adb \ + --verbose \ + --start \ + --force From abcb6b33a7669938964c8229648ec770a96b0d91 Mon Sep 17 00:00:00 2001 From: folecr Date: Sun, 30 Sep 2012 10:55:17 -0700 Subject: [PATCH 05/15] set -x in build script so that entire command line is available in the build log --- samples/HelloCpp/proj.android/build_native.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/HelloCpp/proj.android/build_native.sh b/samples/HelloCpp/proj.android/build_native.sh index e14fddce76..63cce90a30 100755 --- a/samples/HelloCpp/proj.android/build_native.sh +++ b/samples/HelloCpp/proj.android/build_native.sh @@ -67,10 +67,12 @@ done if [[ "$buildexternalsfromsource" ]]; then echo "Building external dependencies from source" + set -x "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source" else echo "Using prebuilt externals" + set -x "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt" fi From bc05a650ecbdf28a66632d3b2473d4f34efba6c3 Mon Sep 17 00:00:00 2001 From: folecr Date: Thu, 4 Oct 2012 10:23:07 -0700 Subject: [PATCH 06/15] Add a template for the debugger script that is used when generating a new project --- template/android/copy_files.sh | 7 +++++ template/android/ndkgdb.sh | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 template/android/ndkgdb.sh diff --git a/template/android/copy_files.sh b/template/android/copy_files.sh index d102d0684e..633d8c9336 100644 --- a/template/android/copy_files.sh +++ b/template/android/copy_files.sh @@ -52,6 +52,12 @@ copy_build_native(){ chmod u+x $APP_DIR/proj.android/build_native.sh } +# copy debugger script and replace templated parameters +copy_ndkgdb(){ + sed "s#__projectname__#$APP_NAME#;s#__packagename__#$PACKAGE_PATH#" $COCOS2DX_ROOT/template/android/ndkgdb.sh > $APP_DIR/proj.android/ndkgdb.sh + chmod u+x $APP_DIR/proj.android/ndkgdb.sh +} + # copy .project and .classpath and replace project name modify_project_classpath(){ sed "s/HelloCpp/$APP_NAME/" $COCOS2DX_ROOT/template/android/.project > $APP_DIR/proj.android/.project @@ -92,6 +98,7 @@ copy_cpp_h copy_resouces copy_src_and_jni copy_build_native +copy_ndkgdb modify_project_classpath modify_androidmanifest modify_applicationdemo diff --git a/template/android/ndkgdb.sh b/template/android/ndkgdb.sh new file mode 100644 index 0000000000..5326004ea8 --- /dev/null +++ b/template/android/ndkgdb.sh @@ -0,0 +1,47 @@ +APPNAME="__projectname__" +APP_ANDROID_NAME="__packagename__" + +if [ -z "${SDK_ROOT+aaa}" ]; then +# ... if SDK_ROOT is not set, use "$HOME/bin/android-sdk" + SDK_ROOT="$HOME/bin/android-sdk" +fi + +if [ -z "${NDK_ROOT+aaa}" ]; then +# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk" + NDK_ROOT="$HOME/bin/android-ndk" +fi + +if [ -z "${COCOS2DX_ROOT+aaa}" ]; then +# ... if COCOS2DX_ROOT is not set +# ... find current working directory + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# ... use paths relative to current directory + COCOS2DX_ROOT="$DIR/../.." + APP_ROOT="$DIR/.." + APP_ANDROID_ROOT="$DIR" +else + APP_ROOT="$COCOS2DX_ROOT/$APPNAME" + APP_ANDROID_ROOT="$COCOS2DX_ROOT/$APPNAME/proj.android" +fi + +echo "NDK_ROOT = $NDK_ROOT" +echo "SDK_ROOT = $SDK_ROOT" +echo "COCOS2DX_ROOT = $COCOS2DX_ROOT" +echo "APP_ROOT = $APP_ROOT" +echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT" +echo "APP_ANDROID_NAME = $APP_ANDROID_NAME" + +echo +echo "Killing and restarting ${APP_ANDROID_NAME}" +echo + +set -x + +"${SDK_ROOT}"/platform-tools/adb shell am force-stop "${APP_ANDROID_NAME}" + +NDK_MODULE_PATH="${COCOS2DX_ROOT}":"${COCOS2DX_ROOT}"/cocos2dx/platform/third_party/android/prebuilt \ + "${NDK_ROOT}"/ndk-gdb \ + --adb="${SDK_ROOT}"/platform-tools/adb \ + --verbose \ + --start \ + --force From a9177fed6fb1324e8a27abb53d0d64d7a7c3c70e Mon Sep 17 00:00:00 2001 From: Ed Bartley Date: Fri, 5 Oct 2012 10:24:17 -0400 Subject: [PATCH 07/15] Fix Typo. Make mGLSurfaceView public so that subclasses can may initialize mGLSurfaceView from a custom xml layout. --- .../org/cocos2dx/lib/Cocos2dxActivity.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 247fb78575..e6f34d131a 100644 --- a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -26,7 +26,6 @@ package org.cocos2dx.lib; import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener; import android.app.Activity; -import android.app.AlertDialog; import android.os.Bundle; import android.os.Message; import android.view.ViewGroup; @@ -43,8 +42,8 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // Fields // =========================================================== - private Cocos2dxGLSurfaceView mGLSurefaceView; - private Cocos2dxHandler mHandler; + public Cocos2dxGLSurfaceView mGLSurfaceView; + public Cocos2dxHandler mHandler; // =========================================================== // Constructors @@ -72,7 +71,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe super.onResume(); Cocos2dxHelper.onResume(); - this.mGLSurefaceView.onResume(); + this.mGLSurfaceView.onResume(); } @Override @@ -80,7 +79,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe super.onPause(); Cocos2dxHelper.onPause(); - this.mGLSurefaceView.onPause(); + this.mGLSurfaceView.onPause(); } @Override @@ -101,7 +100,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe @Override public void runOnGLThread(final Runnable pRunnable) { - this.mGLSurefaceView.queueEvent(pRunnable); + this.mGLSurfaceView.queueEvent(pRunnable); } // =========================================================== @@ -130,13 +129,13 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe framelayout.addView(edittext); // Cocos2dxGLSurfaceView - this.mGLSurefaceView = this.onCreateGLSurfaceView(); + this.mGLSurfaceView = this.onCreateGLSurfaceView(); // ...add to FrameLayout - framelayout.addView(mGLSurefaceView); + framelayout.addView(mGLSurfaceView); - mGLSurefaceView.setCocos2dxRenderer(new Cocos2dxRenderer()); - mGLSurefaceView.setCocos2dxEditText(edittext); + mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer()); + mGLSurfaceView.setCocos2dxEditText(edittext); // Set framelayout as the content view setContentView(framelayout); From d8a26a86234afaa1567ff5e0db8c0d2ebaef36bb Mon Sep 17 00:00:00 2001 From: folecr Date: Fri, 5 Oct 2012 12:36:04 -0700 Subject: [PATCH 08/15] Use "-j8" flag to ndk-build when building TestJavaScript * If a "-p" for "parallel build" option is set --- samples/TestJavascript/proj.android/build_native.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/samples/TestJavascript/proj.android/build_native.sh b/samples/TestJavascript/proj.android/build_native.sh index 6ce5e724e4..be80429f39 100755 --- a/samples/TestJavascript/proj.android/build_native.sh +++ b/samples/TestJavascript/proj.android/build_native.sh @@ -3,6 +3,7 @@ APPNAME="TestJavascript" # options buildexternalsfromsource= +PARALLEL_BUILD_FLAG= usage(){ cat << EOF @@ -12,15 +13,19 @@ Build C/C++ code for $APPNAME using Android NDK OPTIONS: -s Build externals from source +-p Run make with -j8 option to take advantage of multiple processors -h this help EOF } -while getopts "sh" OPTION; do +while getopts "sph" OPTION; do case "$OPTION" in s) buildexternalsfromsource=1 ;; +p) +PARALLEL_BUILD_FLAG=\-j8 +;; h) usage exit 0 @@ -90,6 +95,6 @@ echo set -x -"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ +"$NDK_ROOT"/ndk-build $PARALLEL_BUILD_FLAG -C "$APP_ANDROID_ROOT" $* \ "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt" \ NDK_LOG=1 V=1 From 04527f7378cf040f76f8fa337948f3939d338232 Mon Sep 17 00:00:00 2001 From: Ed Bartley Date: Sat, 6 Oct 2012 23:39:47 -0400 Subject: [PATCH 09/15] Added some flexibility to the Cocos2dxActivity. View creation can be overridden by developers that use a custom Layout and custom views. --- .../org/cocos2dx/lib/Cocos2dxActivity.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index e6f34d131a..89bd3fc53b 100644 --- a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -42,8 +42,8 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // Fields // =========================================================== - public Cocos2dxGLSurfaceView mGLSurfaceView; - public Cocos2dxHandler mHandler; + private Cocos2dxGLSurfaceView mGLSurfaceView; + private Cocos2dxHandler mHandler; // =========================================================== // Constructors @@ -53,7 +53,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - this.init(); + this.mHandler = new Cocos2dxHandler(this); + + this.mGLSurfaceView = onCreateView(); Cocos2dxHelper.init(this, this); } @@ -107,9 +109,8 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // Methods // =========================================================== - public void init() { + public Cocos2dxGLSurfaceView onCreateView() { // Init handler - this.mHandler = new Cocos2dxHandler(this); // FrameLayout ViewGroup.LayoutParams framelayout_params = @@ -129,20 +130,18 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe framelayout.addView(edittext); // Cocos2dxGLSurfaceView - this.mGLSurfaceView = this.onCreateGLSurfaceView(); + Cocos2dxGLSurfaceView gLSurfaceView = new Cocos2dxGLSurfaceView(this); // ...add to FrameLayout - framelayout.addView(mGLSurfaceView); + framelayout.addView(gLSurfaceView); - mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer()); - mGLSurfaceView.setCocos2dxEditText(edittext); + gLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer()); + gLSurfaceView.setCocos2dxEditText(edittext); // Set framelayout as the content view setContentView(framelayout); - } - - public Cocos2dxGLSurfaceView onCreateGLSurfaceView() { - return new Cocos2dxGLSurfaceView(this); + + return gLSurfaceView; } // =========================================================== From 54b4c690d15c4bdf4f25469ceac81b56d19afc8d Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 8 Oct 2012 13:41:48 +0800 Subject: [PATCH 10/15] fixed #1494: Missing removing auto-release object from AutoReleasePool if invoking 'autorelease' method more times. --- cocos2dx/cocoa/CCAutoreleasePool.cpp | 4 +--- cocos2dx/cocoa/CCObject.cpp | 11 +++++++---- cocos2dx/cocoa/CCObject.h | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cocos2dx/cocoa/CCAutoreleasePool.cpp b/cocos2dx/cocoa/CCAutoreleasePool.cpp index d6583c296f..1e5143694c 100644 --- a/cocos2dx/cocoa/CCAutoreleasePool.cpp +++ b/cocos2dx/cocoa/CCAutoreleasePool.cpp @@ -41,8 +41,6 @@ CCAutoreleasePool::~CCAutoreleasePool(void) void CCAutoreleasePool::addObject(CCObject* pObject) { - CCAssert(false == pObject->m_bManaged, "this object is already in autorelese pool"); - m_pManagedObjectArray->addObject(pObject); CCAssert(pObject->m_uReference > 1, "reference count should be greater than 1"); @@ -70,7 +68,7 @@ void CCAutoreleasePool::clear() if(!pObj) break; - pObj->m_bManaged = false; + --(pObj->m_uAutoReleaseCount); //(*it)->release(); //delete (*it); #ifdef _DEBUG diff --git a/cocos2dx/cocoa/CCObject.cpp b/cocos2dx/cocoa/CCObject.cpp index 8084c65180..dc807406c7 100644 --- a/cocos2dx/cocoa/CCObject.cpp +++ b/cocos2dx/cocoa/CCObject.cpp @@ -38,7 +38,7 @@ CCObject* CCCopying::copyWithZone(CCZone *pZone) } CCObject::CCObject(void) -:m_bManaged(false) +:m_uAutoReleaseCount(0) ,m_uReference(1) // when the object is created, the reference count of it is 1 ,m_nLuaID(0) { @@ -51,9 +51,12 @@ CCObject::~CCObject(void) { // if the object is managed, we should remove it // from pool manager - if (m_bManaged) + if (m_uAutoReleaseCount > 0) { - CCPoolManager::sharedPoolManager()->removeObject(this); + for (int i = 0; i < m_uAutoReleaseCount; ++i) + { + CCPoolManager::sharedPoolManager()->removeObject(this); + } } // if the object is referenced by Lua engine, remove it @@ -98,7 +101,7 @@ CCObject* CCObject::autorelease(void) { CCPoolManager::sharedPoolManager()->addObject(this); - m_bManaged = true; + ++m_uAutoReleaseCount; return this; } diff --git a/cocos2dx/cocoa/CCObject.h b/cocos2dx/cocoa/CCObject.h index 2aff081ee1..010e55df62 100644 --- a/cocos2dx/cocoa/CCObject.h +++ b/cocos2dx/cocoa/CCObject.h @@ -55,8 +55,8 @@ public: protected: // count of references unsigned int m_uReference; - // is the object autoreleased - bool m_bManaged; + // count of autorelease + unsigned int m_uAutoReleaseCount; public: CCObject(void); virtual ~CCObject(void); From 6d29e632941ca04d5401bd4a2b05d82eaabf698b Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 8 Oct 2012 14:05:03 +0800 Subject: [PATCH 11/15] fixed #1494: Change the value of CCObject::m_uAutoreleaseCount in CCAutoreleasePool class. --- cocos2dx/cocoa/CCAutoreleasePool.cpp | 7 +++++-- cocos2dx/cocoa/CCObject.cpp | 7 +------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cocos2dx/cocoa/CCAutoreleasePool.cpp b/cocos2dx/cocoa/CCAutoreleasePool.cpp index 1e5143694c..791226942a 100644 --- a/cocos2dx/cocoa/CCAutoreleasePool.cpp +++ b/cocos2dx/cocoa/CCAutoreleasePool.cpp @@ -44,13 +44,16 @@ void CCAutoreleasePool::addObject(CCObject* pObject) m_pManagedObjectArray->addObject(pObject); CCAssert(pObject->m_uReference > 1, "reference count should be greater than 1"); - + ++(pObject->m_uAutoReleaseCount); pObject->release(); // no ref count, in this case autorelease pool added. } void CCAutoreleasePool::removeObject(CCObject* pObject) { - m_pManagedObjectArray->removeObject(pObject, false); + for (int i = 0; i < pObject->m_uAutoReleaseCount; ++i) + { + m_pManagedObjectArray->removeObject(pObject, false); + } } void CCAutoreleasePool::clear() diff --git a/cocos2dx/cocoa/CCObject.cpp b/cocos2dx/cocoa/CCObject.cpp index dc807406c7..ff8f6a5eba 100644 --- a/cocos2dx/cocoa/CCObject.cpp +++ b/cocos2dx/cocoa/CCObject.cpp @@ -53,10 +53,7 @@ CCObject::~CCObject(void) // from pool manager if (m_uAutoReleaseCount > 0) { - for (int i = 0; i < m_uAutoReleaseCount; ++i) - { - CCPoolManager::sharedPoolManager()->removeObject(this); - } + CCPoolManager::sharedPoolManager()->removeObject(this); } // if the object is referenced by Lua engine, remove it @@ -100,8 +97,6 @@ void CCObject::retain(void) CCObject* CCObject::autorelease(void) { CCPoolManager::sharedPoolManager()->addObject(this); - - ++m_uAutoReleaseCount; return this; } From cb2f3efc2c79f938d023b145a028bcd91281b190 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 8 Oct 2012 14:12:34 +0800 Subject: [PATCH 12/15] fixed #1495: CCScrollView display area and touch area are wrong if its parent's postion isn't at CCPointZero in world. --- extensions/GUI/CCScrollView/CCScrollView.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index e08da8a74f..30ba0f53c0 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -493,10 +493,10 @@ void CCScrollView::addChild(CCNode * child) */ void CCScrollView::beforeDraw() { - if (m_bClippingToBounds) + if (m_bClippingToBounds) { // TODO: This scrollview should respect parents' positions - CCPoint screenPos = this->convertToWorldSpace(this->getParent()->getPosition()); + CCPoint screenPos = this->getParent()->convertToWorldSpace(this->getPosition()); glEnable(GL_SCISSOR_TEST); float s = this->getScale(); @@ -531,8 +531,6 @@ void CCScrollView::visit() kmGLPushMatrix(); -// glPushMatrix(); - if (m_pGrid && m_pGrid->isActive()) { m_pGrid->beforeDraw(); @@ -584,8 +582,6 @@ void CCScrollView::visit() } kmGLPopMatrix(); - -// glPopMatrix(); } bool CCScrollView::ccTouchBegan(CCTouch* touch, CCEvent* event) @@ -595,7 +591,8 @@ bool CCScrollView::ccTouchBegan(CCTouch* touch, CCEvent* event) return false; } CCRect frame; - frame = CCRectMake(this->getPosition().x, this->getPosition().y, m_tViewSize.width, m_tViewSize.height); + CCPoint frameOriginal = this->getParent()->convertToWorldSpace(this->getPosition()); + frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height); //dispatcher does not know about clipping. reject touches outside visible bounds. if (m_pTouches->count() > 2 || @@ -645,7 +642,9 @@ void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event) float newX, newY; m_bTouchMoved = true; - frame = CCRectMake(this->getPosition().x, this->getPosition().y, m_tViewSize.width, m_tViewSize.height); + CCPoint frameOriginal = this->getParent()->convertToWorldSpace(this->getPosition()); + frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height); + newPoint = this->convertTouchToNodeSpace((CCTouch*)m_pTouches->objectAtIndex(0)); moveDistance = ccpSub(newPoint, m_tTouchPoint); m_tTouchPoint = newPoint; From 719cb7b7a655c0ae126b52de049a8d5bafabc27a Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 8 Oct 2012 14:52:08 +0800 Subject: [PATCH 13/15] fixed #1496: An error of comparing font's face name in CCImage of win32 port. --- cocos2dx/platform/win32/CCImage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/platform/win32/CCImage.cpp b/cocos2dx/platform/win32/CCImage.cpp index 27d0b69468..8eea70c70f 100644 --- a/cocos2dx/platform/win32/CCImage.cpp +++ b/cocos2dx/platform/win32/CCImage.cpp @@ -127,7 +127,7 @@ public: GetObjectA(m_hFont, sizeof(tOldFont), &tOldFont); if (tOldFont.lfHeight == tNewFont.lfHeight - && ! strcpy(tOldFont.lfFaceName, tNewFont.lfFaceName)) + && 0 == strcmp(tOldFont.lfFaceName, tNewFont.lfFaceName)) { // already has the font bRet = true; From f6c34e23e649df18372373f2a5a6b14a3b248dfc Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 8 Oct 2012 14:55:46 +0800 Subject: [PATCH 14/15] Adding some comments for CCDictionary::objectForKey method. --- cocos2dx/cocoa/CCDictionary.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cocos2dx/cocoa/CCDictionary.cpp b/cocos2dx/cocoa/CCDictionary.cpp index 2265d85540..be761a5c0a 100644 --- a/cocos2dx/cocoa/CCDictionary.cpp +++ b/cocos2dx/cocoa/CCDictionary.cpp @@ -91,7 +91,10 @@ CCArray* CCDictionary::allKeysForObject(CCObject* object) CCObject* CCDictionary::objectForKey(const std::string& key) { - if (m_eDictType == kCCDictUnknown && m_eDictType == kCCDictUnknown) return NULL; + // if dictionary wasn't initialized, return NULL directly. + if (m_eDictType == kCCDictUnknown) return NULL; + // CCDictionary only supports one kind of key, string or integer. + // This method uses string as key, therefore we should make sure that the key type of this CCDictionary is string. CCAssert(m_eDictType == kCCDictStr, "this dictionary does not use string as key."); CCObject* pRetObject = NULL; @@ -106,7 +109,10 @@ CCObject* CCDictionary::objectForKey(const std::string& key) CCObject* CCDictionary::objectForKey(int key) { - if (m_eDictType == kCCDictUnknown && m_eDictType == kCCDictUnknown) return NULL; + // if dictionary wasn't initialized, return NULL directly. + if (m_eDictType == kCCDictUnknown) return NULL; + // CCDictionary only supports one kind of key, string or integer. + // This method uses string as key, therefore we should make sure that the key type of this CCDictionary is integer. CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as key."); CCObject* pRetObject = NULL; From be236155e953de53479356372ec67bc7dcd8be93 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 8 Oct 2012 14:58:24 +0800 Subject: [PATCH 15/15] Fix a typo. --- cocos2dx/cocoa/CCDictionary.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/cocoa/CCDictionary.cpp b/cocos2dx/cocoa/CCDictionary.cpp index be761a5c0a..eafd729dba 100644 --- a/cocos2dx/cocoa/CCDictionary.cpp +++ b/cocos2dx/cocoa/CCDictionary.cpp @@ -112,7 +112,7 @@ CCObject* CCDictionary::objectForKey(int key) // if dictionary wasn't initialized, return NULL directly. if (m_eDictType == kCCDictUnknown) return NULL; // CCDictionary only supports one kind of key, string or integer. - // This method uses string as key, therefore we should make sure that the key type of this CCDictionary is integer. + // This method uses integer as key, therefore we should make sure that the key type of this CCDictionary is integer. CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as key."); CCObject* pRetObject = NULL;