Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into gles20

Conflicts:
	cocos2dx/cocoa/CCDictionary.cpp
	cocos2dx/platform/win32/CCImage.cpp
This commit is contained in:
walzer 2012-10-09 14:40:25 +08:00
commit 394af672d8
15 changed files with 245 additions and 63 deletions

View File

@ -41,18 +41,19 @@ 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");
++(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()
@ -70,7 +71,7 @@ void CCAutoreleasePool::clear()
if(!pObj)
break;
pObj->m_bManaged = false;
--(pObj->m_uAutoReleaseCount);
//(*it)->release();
//delete (*it);
#ifdef _DEBUG

View File

@ -91,13 +91,12 @@ CCArray* CCDictionary::allKeysForObject(CCObject* object)
CCObject* CCDictionary::objectForKey(const std::string& key)
{
if (m_eDictType != kCCDictStr)
{
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;
CCDictElement *pElement = NULL;
HASH_FIND_STR(m_pElements, key.c_str(), pElement);
@ -110,13 +109,12 @@ CCObject* CCDictionary::objectForKey(const std::string& key)
CCObject* CCDictionary::objectForKey(int key)
{
if (m_eDictType != kCCDictInt)
{
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 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;
CCDictElement *pElement = NULL;
HASH_FIND_INT(m_pElements, &key, pElement);

View File

@ -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,7 +51,7 @@ 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);
}
@ -97,8 +97,6 @@ void CCObject::retain(void)
CCObject* CCObject::autorelease(void)
{
CCPoolManager::sharedPoolManager()->addObject(this);
m_bManaged = true;
return this;
}

View File

@ -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);

View File

@ -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,7 +42,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
// Fields
// ===========================================================
private Cocos2dxGLSurfaceView mGLSurefaceView;
private Cocos2dxGLSurfaceView mGLSurfaceView;
private Cocos2dxHandler mHandler;
// ===========================================================
@ -54,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);
}
@ -72,7 +73,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
super.onResume();
Cocos2dxHelper.onResume();
this.mGLSurefaceView.onResume();
this.mGLSurfaceView.onResume();
}
@Override
@ -80,7 +81,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
super.onPause();
Cocos2dxHelper.onPause();
this.mGLSurefaceView.onPause();
this.mGLSurfaceView.onPause();
}
@Override
@ -101,16 +102,15 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
@Override
public void runOnGLThread(final Runnable pRunnable) {
this.mGLSurefaceView.queueEvent(pRunnable);
this.mGLSurfaceView.queueEvent(pRunnable);
}
// ===========================================================
// Methods
// ===========================================================
public void init() {
public Cocos2dxGLSurfaceView onCreateView() {
// Init handler
this.mHandler = new Cocos2dxHandler(this);
// FrameLayout
ViewGroup.LayoutParams framelayout_params =
@ -130,20 +130,18 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
framelayout.addView(edittext);
// Cocos2dxGLSurfaceView
this.mGLSurefaceView = this.onCreateGLSurfaceView();
Cocos2dxGLSurfaceView gLSurfaceView = new Cocos2dxGLSurfaceView(this);
// ...add to FrameLayout
framelayout.addView(mGLSurefaceView);
framelayout.addView(gLSurfaceView);
mGLSurefaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
mGLSurefaceView.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;
}
// ===========================================================

View File

@ -126,8 +126,8 @@ public:
}
GetObjectA(m_hFont, sizeof(tOldFont), &tOldFont);
if (tOldFont.lfHeight == tNewFont.lfHeight &&
!strcmp(tOldFont.lfFaceName, tNewFont.lfFaceName))
if (tOldFont.lfHeight == tNewFont.lfHeight
&& 0 == strcmp(tOldFont.lfFaceName, tNewFont.lfFaceName))
{
// already has the font
bRet = true;

View File

@ -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;

View File

@ -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<std::string> headers=request->getHeaders();
if(!headers.empty())
{
for(std::vector<std::string>::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<std::string> headers=request->getHeaders();
if(!headers.empty())
{
for(std::vector<std::string>::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;

View File

@ -175,7 +175,20 @@ public:
{
return _pSelector;
}
/** Set any custom headers **/
inline void setHeaders(std::vector<std::string> pHeaders)
{
_headers=pHeaders;
}
/** Get custom headers **/
inline std::vector<std::string> getHeaders()
{
return _headers;
}
protected:
// properties
HttpRequestType _requestType; /// kHttpRequestGet, kHttpRequestPost or other enums
@ -185,6 +198,7 @@ protected:
CCObject* _pTarget; /// callback target of pSelector function
SEL_CallFuncND _pSelector; /// callback function, e.g. MyLayer::onHttpResponse(CCObject *sender, void *data)
void* _pUserData; /// You can add your customed data here
std::vector<std::string> _headers; /// custom http headers
};
NS_CC_EXT_END

View File

@ -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

View File

@ -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

View File

@ -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<std::string> 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...");

View File

@ -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

View File

@ -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

View File

@ -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