Merge pull request #986 from dumganhar/gles20

issue #1310: Synchronize to RC2, HelloWorld works ok on win32.
This commit is contained in:
James Chen 2012-06-08 02:20:27 -07:00
commit 36e393a5f4
11 changed files with 101 additions and 301 deletions

View File

@ -370,8 +370,6 @@ CCArray::~CCArray()
ccArrayFree(data);
}
CCObject* CCArray::copyWithZone(CCZone* pZone)
{
CCAssert(pZone == NULL, "CCArray should not be inherited.");
@ -386,126 +384,4 @@ CCObject* CCArray::copyWithZone(CCZone* pZone)
return pArray;
}
//#pragma mark CCArray - sorting
/** @since 1.1 */
//#pragma mark -
//#pragma mark CCArray insertionSortUsingCFuncComparator
void CCArray::insertionSortUsingCFuncComparator(cc_comparator comparator)
{
//TODO: cc_insertionSort(data, comparator);
}
//#pragma mark CCArray qsortUsingCFuncComparator
void CCArray::qsortUsingCFuncComparator(cc_comparator comparator)
{
// stable c qsort is used - cost of sorting: best n*log(n), average n*log(n)
// qsort(void *, size_t, size_t, int (*)(const void *arg1, const void *arg2));
qsort(data->arr, data->num, sizeof (CCObject*), comparator);
}
//#pragma mark CCArray mergesortLUsingCFuncComparator
void CCArray::mergesortLUsingCFuncComparator(cc_comparator comparator)
{
//TODO: cc_mergesortL(data, sizeof (CCObject*), comparator);
}
//#pragma mark CCArray insertionSort with (SEL)selector
void CCArray::insertionSort(SEL_Compare selector) // It sorts source array in ascending order
{
int i,j,length = data->num;
CCObject* * x = data->arr;
CCObject* temp;
// insertion sort
for(i=1; i<length; i++)
{
j = i;
// continue moving element downwards while order is descending
while( j>0 && (x[j-1]->*selector)(x[j]) == CCOrderedDescending )
{
temp = x[j];
x[j] = x[j-1];
x[j-1] = temp;
j--;
}
}
}
static inline int selectorCompare(CCObject* object1,CCObject* object2,SEL_Compare selector)
{
return (int) (object1->*selector)(object2);
}
void CCArray::sortUsingSelector(SEL_Compare selector)
{
this->sortUsingFunction(selectorCompare, selector);
}
//#pragma mark CCArray sortUsingFunction
// using a comparison function
void CCArray::sortUsingFunction(int (*compare)(CCObject*, CCObject*, SEL_Compare) , SEL_Compare context)
{
int h, i, j, k, l, m, n = this->count();
CCObject* A, **B = (CCObject**)malloc( (n/2 + 1) * sizeof(CCObject*));
// to prevent retain counts from temporarily hitting zero.
for( i=0;i<n;i++)
{
// [[self objectAtIndex:i] retain]; // prevents compiler warning
data->arr[i]->retain();
}
for (h = 1; h < n; h += h)
{
for (m = n - 1 - h; m >= 0; m -= h + h)
{
l = m - h + 1;
if (l < 0)
{
l = 0;
}
for (i = 0, j = l; j <= m; i++, j++)
{
B[i] = this->objectAtIndex(j);
}
for (i = 0, k = l; k < j && j <= m + h; k++)
{
A = this->objectAtIndex(j);
if (compare(A, B[i], context) == CCOrderedDescending)
{
this->replaceObjectAtIndex(k, B[i++]);
}
else
{
this->replaceObjectAtIndex(k, A);
j++;
}
}
while (k < j)
{
this->replaceObjectAtIndex(k++, B[i++]);
}
}
}
for(i=0;i<n;i++)
{
// [[self objectAtIndex:i] release]; // prevents compiler warning
data->arr[i]->release();
}
free(B);
}
NS_CC_END

View File

@ -202,15 +202,6 @@ public:
void reverseObjects();
/* Shrinks the array so the memory footprint corresponds with the number of items */
void reduceMemoryFootprint();
// Sorting Array
/** all since @1.1 */
void qsortUsingCFuncComparator(cc_comparator comparator); // c qsort is used for sorting
void insertionSortUsingCFuncComparator(cc_comparator comparator); // insertion sort
void mergesortLUsingCFuncComparator(cc_comparator comparator); // mergesort
void insertionSort(SEL_Compare selector); // It sorts source array in ascending order
void sortUsingFunction(int (*compare)(CCObject*, CCObject*, SEL_Compare) , SEL_Compare context);
void sortUsingSelector(SEL_Compare selector);
/* override functions */
virtual CCObject* copyWithZone(CCZone* pZone);

View File

@ -380,7 +380,7 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
node->setScaleY(floatValFromDict(props, "scaleY"));
node->setAnchorPoint(pointValFromDict(props, "anchorPoint"));
node->setRotation(floatValFromDict(props, "rotation"));
node->setIsRelativeAnchorPoint(boolValFromDict(props, "isRelativeAnchorPoint"));
node->setIgnoreAnchorPointForPosition(!boolValFromDict(props, "isRelativeAnchorPoint"));
node->setIsVisible(boolValFromDict(props, "visible"));
if (extraProps)

View File

@ -50,7 +50,7 @@ CCTextureWatcher::CCTextureWatcher()
// the menu of disabling touch event
//*
CCLabelTTF *label = CCLabelTTF::labelWithString(" ", size, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop, "Arial", 12);
CCLabelTTF *label = CCLabelTTF::labelWithString(" ", size, kCCTextAlignmentLeft, "Arial", 12);
CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label);
menuItem->setAnchorPoint(ccp(0, 0));
menuItem->setPosition(ccp(0, 0));
@ -98,7 +98,7 @@ CCTextureWatcher::CCTextureWatcher()
m_pLayer->addChild(menu1);
// label page
m_labelPage = CCLabelTTF::labelWithString(" ", CCSizeMake(size.width * 0.1, labelFresh->getContentSize().height), kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop, "Arial", 16);
m_labelPage = CCLabelTTF::labelWithString(" ", CCSizeMake(size.width * 0.1, labelFresh->getContentSize().height), kCCTextAlignmentCenter, "Arial", 16);
m_labelPage->setAnchorPoint(ccp(0.5, 0));
m_labelPage->setPosition(ccp(size.width/2.0, 0));
m_pLayer->addChild(m_labelPage, 0);
@ -314,7 +314,7 @@ void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewPro
string name = key.substr(pos, len - pos);
sprintf(m_pszString, "%s", name.c_str());
CCSize dimensions = CCSizeMake(listItemSize.width * 0.9f, labelSize->getContentSize().height);
CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop, "Arial", 16);
CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, kCCTextAlignmentCenter, "Arial", 16);
offX = offsetX + listItemSize.width * 0.5f;
offY = offY + labelName->getContentSize().height;
labelName->setPosition(ccp(offX, offY));

View File

@ -111,6 +111,11 @@ CCRenderTexture * CCRenderTexture::renderTextureWithWidthAndHeight(int w, int h)
return NULL;
}
bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
{
return initWithWidthAndHeight(w, h, eFormat, 0);
}
bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat, GLuint uDepthStencilFormat)
{
CCAssert(m_ePixelFormat != kCCTexture2DPixelFormat_A8, "only RGB and RGBA formats are valid for a render texture");

View File

@ -1183,6 +1183,16 @@ void CCParticleSystem::setBlendFunc(ccBlendFunc blendFunc)
}
}
bool CCParticleSystem::getOpacityModifyRGB()
{
return m_bOpacityModifyRGB;
}
void CCParticleSystem::setOpacityModifyRGB(bool bOpacityModifyRGB)
{
m_bOpacityModifyRGB = bOpacityModifyRGB;
}
tCCPositionType CCParticleSystem::getPositionType()
{
return m_ePositionType;

View File

@ -339,6 +339,14 @@
RelativePath="..\actions\CCActionCamera.h"
>
</File>
<File
RelativePath="..\actions\CCActionCatmullRom.cpp"
>
</File>
<File
RelativePath="..\actions\CCActionCatmullRom.h"
>
</File>
<File
RelativePath="..\actions\CCActionEase.cpp"
>

View File

@ -29,13 +29,14 @@ THE SOFTWARE.
NS_CC_BEGIN
/** Allocates and initializes a new array with specified capacity */
ccArray* ccArrayNew(unsigned int capacity) {
ccArray* ccArrayNew(unsigned int capacity)
{
if (capacity == 0)
capacity = 1;
ccArray *arr = (ccArray*)malloc( sizeof(ccArray) );
arr->num = 0;
arr->arr = (CCARRAY_ID *)calloc(capacity, sizeof(CCObject*));
arr->arr = (CCObject**)calloc(capacity, sizeof(CCObject*));
arr->max = capacity;
return arr;
@ -44,8 +45,10 @@ ccArray* ccArrayNew(unsigned int capacity) {
/** Frees array after removing all remaining objects. Silently ignores NULL arr. */
void ccArrayFree(ccArray*& arr)
{
if( arr == NULL) return;
if( arr == NULL )
{
return;
}
ccArrayRemoveAllObjects(arr);
free(arr->arr);
@ -57,21 +60,23 @@ void ccArrayFree(ccArray*& arr)
void ccArrayDoubleCapacity(ccArray *arr)
{
arr->max *= 2;
CCARRAY_ID *newArr = (CCARRAY_ID *)realloc( arr->arr, arr->max * sizeof(CCObject*) );
CCObject** newArr = (CCObject**)realloc( arr->arr, arr->max * sizeof(CCObject*) );
// will fail when there's not enough memory
CCAssert(newArr != NULL, "ccArrayDoubleCapacity failed. Not enough memory");
CCAssert(newArr != 0, "ccArrayDoubleCapacity failed. Not enough memory");
arr->arr = newArr;
}
void ccArrayEnsureExtraCapacity(ccArray *arr, unsigned int extra)
{
while (arr->max < arr->num + extra)
{
ccArrayDoubleCapacity(arr);
}
}
void ccArrayShrink(ccArray *arr)
{
unsigned int newSize;
unsigned int newSize = 0;
//only resize when necessary
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
@ -87,7 +92,7 @@ void ccArrayShrink(ccArray *arr)
arr->max=1;
}
arr->arr = (CCARRAY_ID *) realloc(arr->arr,newSize * sizeof(CCObject*) );
arr->arr = (CCObject**)realloc(arr->arr,newSize * sizeof(CCObject*) );
CCAssert(arr->arr!=NULL,"could not reallocate the memory");
}
}
@ -95,10 +100,10 @@ void ccArrayShrink(ccArray *arr)
/** Returns index of first occurence of object, CC_INVALID_INDEX if object not found. */
unsigned int ccArrayGetIndexOfObject(ccArray *arr, CCObject* object)
{
unsigned int i;
for( i = 0; i < arr->num; i++)
for(unsigned int i = 0; i < arr->num; i++)
{
if( arr->arr[i] == object ) return i;
}
return CC_INVALID_INDEX;
}
@ -129,10 +134,10 @@ void ccArrayAppendObjectWithResize(ccArray *arr, CCObject* object)
enough capacity. */
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
{
unsigned int i;
for( i = 0; i < plusArr->num; i++)
for(unsigned int i = 0; i < plusArr->num; i++)
{
ccArrayAppendObject(arr, plusArr->arr[i]);
}
}
/** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */
@ -186,6 +191,7 @@ void ccArrayRemoveAllObjects(ccArray *arr)
Behaviour undefined if index outside [0, num-1]. */
void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj/* = true*/)
{
CCAssert(arr && arr->num > 0 && index < arr->num, "Invalid index. Out of bounds");
if (bReleaseObj)
{
CC_SAFE_RELEASE(arr->arr[index]);
@ -214,7 +220,9 @@ void ccArrayFastRemoveObject(ccArray *arr, CCObject* object)
{
unsigned int index = ccArrayGetIndexOfObject(arr, object);
if (index != CC_INVALID_INDEX)
{
ccArrayFastRemoveObjectAtIndex(arr, index);
}
}
/** Searches for the first occurance of object and removes it. If object is not
@ -232,10 +240,10 @@ void ccArrayRemoveObject(ccArray *arr, CCObject* object, bool bReleaseObj/* = tr
first matching instance in arr will be removed. */
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
{
unsigned int i;
for( i = 0; i < minusArr->num; i++)
for(unsigned int i = 0; i < minusArr->num; i++)
{
ccArrayRemoveObject(arr, minusArr->arr[i]);
}
}
/** Removes from arr all objects in minusArr. For each object in minusArr, all
@ -243,14 +251,19 @@ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
{
unsigned int back = 0;
unsigned int i;
unsigned int i = 0;
for( i = 0; i < arr->num; i++) {
if( ccArrayContainsObject(minusArr, arr->arr[i]) ) {
for( i = 0; i < arr->num; i++)
{
if( ccArrayContainsObject(minusArr, arr->arr[i]) )
{
CC_SAFE_RELEASE(arr->arr[i]);
back++;
} else
}
else
{
arr->arr[i - back] = arr->arr[i];
}
}
arr->num -= back;
@ -263,8 +276,10 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
ccCArray* ccCArrayNew(unsigned int capacity)
{
if (capacity == 0)
{
capacity = 1;
}
ccCArray *arr = (ccCArray*)malloc( sizeof(ccCArray) );
arr->num = 0;
arr->arr = (void**)malloc( capacity * sizeof(void*) );
@ -276,8 +291,10 @@ ccCArray* ccCArrayNew(unsigned int capacity)
/** Frees C array after removing all remaining values. Silently ignores NULL arr. */
void ccCArrayFree(ccCArray *arr)
{
if( arr == NULL ) return;
if( arr == NULL )
{
return;
}
ccCArrayRemoveAllValues(arr);
free(arr->arr);
@ -287,18 +304,13 @@ void ccCArrayFree(ccCArray *arr)
/** Doubles C array capacity */
void ccCArrayDoubleCapacity(ccCArray *arr)
{
arr->max *= 2;
void** newArr = (void**)realloc( arr->arr, arr->max * sizeof(void*) );
// will fail when there's not enough memory
CCAssert(newArr != NULL, "ccCArrayDoubleCapacity failed. Not enough memory");
arr->arr = newArr;
ccArrayDoubleCapacity((ccArray*)arr);
}
/** Increases array capacity such that max >= num + extra. */
void ccCArrayEnsureExtraCapacity(ccCArray *arr, unsigned int extra)
{
while (arr->max < arr->num + extra)
ccCArrayDoubleCapacity(arr);
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
}
/** Returns index of first occurence of value, CC_INVALID_INDEX if value not found. */
@ -325,7 +337,11 @@ void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, unsigned int index)
CCAssert( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
unsigned int remaining = arr->num - index;
// make sure it has enough capacity
if (arr->num + 1 == arr->max)
{
ccCArrayDoubleCapacity(arr);
}
// last Value doesn't need to be moved
if( remaining > 0) {
// tex coordinates
@ -339,8 +355,14 @@ void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, unsigned int index)
/** Appends an value. Bahaviour undefined if array doesn't have enough capacity. */
void ccCArrayAppendValue(ccCArray *arr, void* value)
{
arr->arr[arr->num] = (CCObject*) value;
arr->arr[arr->num] = value;
arr->num++;
// double the capacity for the next append action
// if the num >= max
if (arr->num >= arr->max)
{
ccCArrayDoubleCapacity(arr);
}
}
/** Appends an value. Capacity of arr is increased if needed. */
@ -385,7 +407,9 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index)
unsigned int last;
for( last = --arr->num; index < last; index++)
{
arr->arr[index] = arr->arr[index + 1];
}
}
/** Removes value at specified index and fills the gap with the last value,
@ -406,7 +430,9 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
{
unsigned int index = ccCArrayGetIndexOfValue(arr, value);
if (index != CC_INVALID_INDEX)
{
ccCArrayRemoveValueAtIndex(arr, index);
}
}
/** Removes from arr all values in minusArr. For each Value in minusArr, the first matching instance in arr will be removed.
@ -414,10 +440,10 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
*/
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
{
unsigned int i;
for( i = 0; i < minusArr->num; i++)
for(unsigned int i = 0; i < minusArr->num; i++)
{
ccCArrayRemoveValue(arr, minusArr->arr[i]);
}
}
/** Removes from arr all values in minusArr. For each value in minusArr, all matching instances in arr will be removed.
@ -425,111 +451,21 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
*/
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
{
unsigned int i;
unsigned int back = 0;
for( i = 0; i < arr->num; i++) {
if( ccCArrayContainsValue(minusArr, arr->arr[i]) ) {
for(unsigned int i = 0; i < arr->num; i++)
{
if( ccCArrayContainsValue(minusArr, arr->arr[i]) )
{
back++;
} else
}
else
{
arr->arr[i - back] = arr->arr[i];
}
}
arr->num -= back;
}
//used by mergesortL
void cc_pointerswap(void* a, void* b, size_t width)
{
void* tmp;
tmp = *(void**)a;
*(void**)a = *(void**)b;
*(void**)b = tmp;
}
// iterative mergesort arrd on
// http://www.inf.fh-flensburg.de/lang/algorithmen/sortieren/merge/mergiter.htm
int cc_mergesortL(ccCArray* array, size_t width, cc_comparator comparator)
{
// void** arr = array->arr;
// int i,j,k,s,m,n= array->num;
//
// void *B = malloc((n/2 + 1) * width);
// for (s = 1; s < n; s += s)
// {
// for (m = n-1-s; m >= 0; m -= s+s)
// {
// int lo = MAX(m-(s+1),0);
// int hi = m+s;
//
// j = lo;
//
// if (m-j > 0)
// {
// //triggers a warning when compiled with ARC, B needs to be strong typed, for compiling for obj-c++
// //memcpy aritmetics aren't allowed on void* types
// //explicitely casting didn't work
// // #pragma clang diagnostic push
// // #if defined(__has_feature) && __has_feature(objc_arc)
// // #pragma clang diagnostic ignored "-Warc-non-pod-memaccess"
// // #endif
//
// memcpy(B, &arr[j], (m-j) * width);
// //#pragma clang diagnostic pop
// }
//
// i = 0;
// j = m;
// k = lo;
//
// while (k<j && j <= hi)
// {
// if (comparator(&B[i],&arr[j]) <= 0)
// {
// cc_pointerswap(&arr[k++],&B[i++], width);
// }
//
// else
// {
// cc_pointerswap(&arr[k++],&arr[j++], width);
// }
// }
//
// while (k<j)
// cc_pointerswap(&arr[k++],&B[i++],width);
// }
// }
// free(B);
return 0;
}
void cc_insertionSort(ccCArray* arr, cc_comparator comparator)
{
// It sorts source array in ascending order
// adaptive - performance adapts to the initial order of elements
// stable - insertion sort retains relative order of the same elements
// in-place - requires constant amount of additional space
// online - new elements can be added during the sort
int i,j,length = arr->num;
void** x = arr->arr;
void* temp;
// insertion sort
for(i=1; i<length; i++)
{
j = i;
//continue moving element downwards while order is descending
while( j>0 && ( comparator( &x[j-1], &x[j] ) == CCOrderedDescending) )
{
temp = x[j];
x[j] = x[j-1];
x[j-1] = temp;
j--;
}
}
}
NS_CC_END

View File

@ -52,34 +52,16 @@ NS_CC_BEGIN
#define CC_INVALID_INDEX 0xffffffff
// #pragma mark -
// #pragma mark ccArray for Objects
// Easy integration
#define CCARRAYDATA_FOREACH(__array__, __object__) \
__object__=__array__->arr[0]; for(unsigned int i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
// #if defined(__has_feature) && __has_feature(objc_arc)
// typedef __strong CCObject* CCARRAY_ID;
// #else
typedef CCObject* CCARRAY_ID;
//#endif
typedef struct _ccArray {
unsigned int num, max;
CCARRAY_ID *arr;
CCObject** arr;
} ccArray;
enum CCComparisonResult
{
CCOrderedDescending = 1,
CCOrderedAscending = -1,
CCOrderedSame = 0
};
typedef int (*cc_comparator)(const void *, const void *);
/** Allocates and initializes a new array with specified capacity */
ccArray* ccArrayNew(unsigned int capacity);
@ -151,7 +133,7 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr);
typedef struct _ccCArray {
unsigned int num, max;
void **arr;
void** arr;
} ccCArray;
/** Allocates and initializes a new C array with specified capacity */
@ -219,14 +201,6 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr);
*/
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr);
// iterative mergesort arrd on
// http://www.inf.fh-flensburg.de/lang/algorithmen/sortieren/merge/mergiter.htm
int cc_mergesortL(ccCArray* array, size_t width, cc_comparator comparator);
void cc_insertionSort(ccCArray* arr, cc_comparator comparator);
void cc_pointerswap(void* a, void* b, size_t width);
NS_CC_END
#endif // CC_ARRAY_H

View File

@ -268,7 +268,7 @@ private:
/** whether or not the texture has their Alpha premultiplied */
CC_PROPERTY_READONLY(bool, m_bHasPremultipliedAlpha, HasPremultipliedAlpha);
CC_PROPERTY_READONLY(bool, m_bHasMipmaps, HasMipmaps);
CC_SYNTHESIZE_READONLY(bool, m_bHasMipmaps, HasMipmaps);
/** shader program used by drawAtPoint and drawInRect */
CC_PROPERTY(CCGLProgram*, m_pShaderProgram, ShaderProgram);

View File

@ -123,7 +123,7 @@ protected:
How many mipmaps do we have. It must be at least one
when proper initialization finishes
*/
CC_PROPERTY_READONLY(unsigned int, m_uNumberOfMipmaps, NumberOfMipmaps);
CC_SYNTHESIZE_READONLY(unsigned int, m_uNumberOfMipmaps, NumberOfMipmaps);
/*
Makrs for mipmaps. Each entry contains position in file