mirror of https://github.com/axmolengine/axmol.git
Merge pull request #986 from dumganhar/gles20
issue #1310: Synchronize to RC2, HelloWorld works ok on win32.
This commit is contained in:
commit
36e393a5f4
|
@ -370,8 +370,6 @@ CCArray::~CCArray()
|
||||||
ccArrayFree(data);
|
ccArrayFree(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CCObject* CCArray::copyWithZone(CCZone* pZone)
|
CCObject* CCArray::copyWithZone(CCZone* pZone)
|
||||||
{
|
{
|
||||||
CCAssert(pZone == NULL, "CCArray should not be inherited.");
|
CCAssert(pZone == NULL, "CCArray should not be inherited.");
|
||||||
|
@ -386,126 +384,4 @@ CCObject* CCArray::copyWithZone(CCZone* pZone)
|
||||||
return pArray;
|
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
|
NS_CC_END
|
||||||
|
|
|
@ -203,15 +203,6 @@ public:
|
||||||
/* Shrinks the array so the memory footprint corresponds with the number of items */
|
/* Shrinks the array so the memory footprint corresponds with the number of items */
|
||||||
void reduceMemoryFootprint();
|
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 */
|
/* override functions */
|
||||||
virtual CCObject* copyWithZone(CCZone* pZone);
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
|
|
||||||
|
|
|
@ -380,7 +380,7 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
|
||||||
node->setScaleY(floatValFromDict(props, "scaleY"));
|
node->setScaleY(floatValFromDict(props, "scaleY"));
|
||||||
node->setAnchorPoint(pointValFromDict(props, "anchorPoint"));
|
node->setAnchorPoint(pointValFromDict(props, "anchorPoint"));
|
||||||
node->setRotation(floatValFromDict(props, "rotation"));
|
node->setRotation(floatValFromDict(props, "rotation"));
|
||||||
node->setIsRelativeAnchorPoint(boolValFromDict(props, "isRelativeAnchorPoint"));
|
node->setIgnoreAnchorPointForPosition(!boolValFromDict(props, "isRelativeAnchorPoint"));
|
||||||
node->setIsVisible(boolValFromDict(props, "visible"));
|
node->setIsVisible(boolValFromDict(props, "visible"));
|
||||||
|
|
||||||
if (extraProps)
|
if (extraProps)
|
||||||
|
|
|
@ -50,7 +50,7 @@ CCTextureWatcher::CCTextureWatcher()
|
||||||
|
|
||||||
// the menu of disabling touch event
|
// 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);
|
CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label);
|
||||||
menuItem->setAnchorPoint(ccp(0, 0));
|
menuItem->setAnchorPoint(ccp(0, 0));
|
||||||
menuItem->setPosition(ccp(0, 0));
|
menuItem->setPosition(ccp(0, 0));
|
||||||
|
@ -98,7 +98,7 @@ CCTextureWatcher::CCTextureWatcher()
|
||||||
m_pLayer->addChild(menu1);
|
m_pLayer->addChild(menu1);
|
||||||
|
|
||||||
// label page
|
// 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->setAnchorPoint(ccp(0.5, 0));
|
||||||
m_labelPage->setPosition(ccp(size.width/2.0, 0));
|
m_labelPage->setPosition(ccp(size.width/2.0, 0));
|
||||||
m_pLayer->addChild(m_labelPage, 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);
|
string name = key.substr(pos, len - pos);
|
||||||
sprintf(m_pszString, "%s", name.c_str());
|
sprintf(m_pszString, "%s", name.c_str());
|
||||||
CCSize dimensions = CCSizeMake(listItemSize.width * 0.9f, labelSize->getContentSize().height);
|
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;
|
offX = offsetX + listItemSize.width * 0.5f;
|
||||||
offY = offY + labelName->getContentSize().height;
|
offY = offY + labelName->getContentSize().height;
|
||||||
labelName->setPosition(ccp(offX, offY));
|
labelName->setPosition(ccp(offX, offY));
|
||||||
|
|
|
@ -111,6 +111,11 @@ CCRenderTexture * CCRenderTexture::renderTextureWithWidthAndHeight(int w, int h)
|
||||||
return NULL;
|
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)
|
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");
|
CCAssert(m_ePixelFormat != kCCTexture2DPixelFormat_A8, "only RGB and RGBA formats are valid for a render texture");
|
||||||
|
|
|
@ -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()
|
tCCPositionType CCParticleSystem::getPositionType()
|
||||||
{
|
{
|
||||||
return m_ePositionType;
|
return m_ePositionType;
|
||||||
|
|
|
@ -339,6 +339,14 @@
|
||||||
RelativePath="..\actions\CCActionCamera.h"
|
RelativePath="..\actions\CCActionCamera.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\actions\CCActionCatmullRom.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\actions\CCActionCatmullRom.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\actions\CCActionEase.cpp"
|
RelativePath="..\actions\CCActionEase.cpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -29,13 +29,14 @@ THE SOFTWARE.
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/** Allocates and initializes a new array with specified capacity */
|
/** Allocates and initializes a new array with specified capacity */
|
||||||
ccArray* ccArrayNew(unsigned int capacity) {
|
ccArray* ccArrayNew(unsigned int capacity)
|
||||||
|
{
|
||||||
if (capacity == 0)
|
if (capacity == 0)
|
||||||
capacity = 1;
|
capacity = 1;
|
||||||
|
|
||||||
ccArray *arr = (ccArray*)malloc( sizeof(ccArray) );
|
ccArray *arr = (ccArray*)malloc( sizeof(ccArray) );
|
||||||
arr->num = 0;
|
arr->num = 0;
|
||||||
arr->arr = (CCARRAY_ID *)calloc(capacity, sizeof(CCObject*));
|
arr->arr = (CCObject**)calloc(capacity, sizeof(CCObject*));
|
||||||
arr->max = capacity;
|
arr->max = capacity;
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
|
@ -44,8 +45,10 @@ ccArray* ccArrayNew(unsigned int capacity) {
|
||||||
/** Frees array after removing all remaining objects. Silently ignores NULL arr. */
|
/** Frees array after removing all remaining objects. Silently ignores NULL arr. */
|
||||||
void ccArrayFree(ccArray*& arr)
|
void ccArrayFree(ccArray*& arr)
|
||||||
{
|
{
|
||||||
if( arr == NULL) return;
|
if( arr == NULL )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
ccArrayRemoveAllObjects(arr);
|
ccArrayRemoveAllObjects(arr);
|
||||||
|
|
||||||
free(arr->arr);
|
free(arr->arr);
|
||||||
|
@ -57,21 +60,23 @@ void ccArrayFree(ccArray*& arr)
|
||||||
void ccArrayDoubleCapacity(ccArray *arr)
|
void ccArrayDoubleCapacity(ccArray *arr)
|
||||||
{
|
{
|
||||||
arr->max *= 2;
|
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
|
// 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;
|
arr->arr = newArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ccArrayEnsureExtraCapacity(ccArray *arr, unsigned int extra)
|
void ccArrayEnsureExtraCapacity(ccArray *arr, unsigned int extra)
|
||||||
{
|
{
|
||||||
while (arr->max < arr->num + extra)
|
while (arr->max < arr->num + extra)
|
||||||
|
{
|
||||||
ccArrayDoubleCapacity(arr);
|
ccArrayDoubleCapacity(arr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ccArrayShrink(ccArray *arr)
|
void ccArrayShrink(ccArray *arr)
|
||||||
{
|
{
|
||||||
unsigned int newSize;
|
unsigned int newSize = 0;
|
||||||
|
|
||||||
//only resize when necessary
|
//only resize when necessary
|
||||||
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
|
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
|
||||||
|
@ -87,7 +92,7 @@ void ccArrayShrink(ccArray *arr)
|
||||||
arr->max=1;
|
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");
|
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. */
|
/** Returns index of first occurence of object, CC_INVALID_INDEX if object not found. */
|
||||||
unsigned int ccArrayGetIndexOfObject(ccArray *arr, CCObject* object)
|
unsigned int ccArrayGetIndexOfObject(ccArray *arr, CCObject* object)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
for(unsigned int i = 0; i < arr->num; i++)
|
||||||
|
{
|
||||||
for( i = 0; i < arr->num; i++)
|
|
||||||
if( arr->arr[i] == object ) return i;
|
if( arr->arr[i] == object ) return i;
|
||||||
|
}
|
||||||
|
|
||||||
return CC_INVALID_INDEX;
|
return CC_INVALID_INDEX;
|
||||||
}
|
}
|
||||||
|
@ -129,11 +134,11 @@ void ccArrayAppendObjectWithResize(ccArray *arr, CCObject* object)
|
||||||
enough capacity. */
|
enough capacity. */
|
||||||
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
|
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
for(unsigned int i = 0; i < plusArr->num; i++)
|
||||||
|
{
|
||||||
for( i = 0; i < plusArr->num; i++)
|
|
||||||
ccArrayAppendObject(arr, plusArr->arr[i]);
|
ccArrayAppendObject(arr, plusArr->arr[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */
|
/** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */
|
||||||
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
|
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
|
||||||
|
@ -186,6 +191,7 @@ void ccArrayRemoveAllObjects(ccArray *arr)
|
||||||
Behaviour undefined if index outside [0, num-1]. */
|
Behaviour undefined if index outside [0, num-1]. */
|
||||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj/* = true*/)
|
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)
|
if (bReleaseObj)
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(arr->arr[index]);
|
CC_SAFE_RELEASE(arr->arr[index]);
|
||||||
|
@ -214,8 +220,10 @@ void ccArrayFastRemoveObject(ccArray *arr, CCObject* object)
|
||||||
{
|
{
|
||||||
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
||||||
if (index != CC_INVALID_INDEX)
|
if (index != CC_INVALID_INDEX)
|
||||||
|
{
|
||||||
ccArrayFastRemoveObjectAtIndex(arr, index);
|
ccArrayFastRemoveObjectAtIndex(arr, index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Searches for the first occurance of object and removes it. If object is not
|
/** Searches for the first occurance of object and removes it. If object is not
|
||||||
found the function has no effect. */
|
found the function has no effect. */
|
||||||
|
@ -232,26 +240,31 @@ void ccArrayRemoveObject(ccArray *arr, CCObject* object, bool bReleaseObj/* = tr
|
||||||
first matching instance in arr will be removed. */
|
first matching instance in arr will be removed. */
|
||||||
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
for(unsigned int i = 0; i < minusArr->num; i++)
|
||||||
|
{
|
||||||
for( i = 0; i < minusArr->num; i++)
|
|
||||||
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Removes from arr all objects in minusArr. For each object in minusArr, all
|
/** Removes from arr all objects in minusArr. For each object in minusArr, all
|
||||||
matching instances in arr will be removed. */
|
matching instances in arr will be removed. */
|
||||||
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
unsigned int back = 0;
|
unsigned int back = 0;
|
||||||
unsigned int i;
|
unsigned int i = 0;
|
||||||
|
|
||||||
for( i = 0; i < arr->num; i++) {
|
for( i = 0; i < arr->num; i++)
|
||||||
if( ccArrayContainsObject(minusArr, arr->arr[i]) ) {
|
{
|
||||||
|
if( ccArrayContainsObject(minusArr, arr->arr[i]) )
|
||||||
|
{
|
||||||
CC_SAFE_RELEASE(arr->arr[i]);
|
CC_SAFE_RELEASE(arr->arr[i]);
|
||||||
back++;
|
back++;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
arr->arr[i - back] = arr->arr[i];
|
arr->arr[i - back] = arr->arr[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arr->num -= back;
|
arr->num -= back;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +276,9 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
ccCArray* ccCArrayNew(unsigned int capacity)
|
ccCArray* ccCArrayNew(unsigned int capacity)
|
||||||
{
|
{
|
||||||
if (capacity == 0)
|
if (capacity == 0)
|
||||||
|
{
|
||||||
capacity = 1;
|
capacity = 1;
|
||||||
|
}
|
||||||
|
|
||||||
ccCArray *arr = (ccCArray*)malloc( sizeof(ccCArray) );
|
ccCArray *arr = (ccCArray*)malloc( sizeof(ccCArray) );
|
||||||
arr->num = 0;
|
arr->num = 0;
|
||||||
|
@ -276,8 +291,10 @@ ccCArray* ccCArrayNew(unsigned int capacity)
|
||||||
/** Frees C array after removing all remaining values. Silently ignores NULL arr. */
|
/** Frees C array after removing all remaining values. Silently ignores NULL arr. */
|
||||||
void ccCArrayFree(ccCArray *arr)
|
void ccCArrayFree(ccCArray *arr)
|
||||||
{
|
{
|
||||||
if( arr == NULL ) return;
|
if( arr == NULL )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
ccCArrayRemoveAllValues(arr);
|
ccCArrayRemoveAllValues(arr);
|
||||||
|
|
||||||
free(arr->arr);
|
free(arr->arr);
|
||||||
|
@ -287,18 +304,13 @@ void ccCArrayFree(ccCArray *arr)
|
||||||
/** Doubles C array capacity */
|
/** Doubles C array capacity */
|
||||||
void ccCArrayDoubleCapacity(ccCArray *arr)
|
void ccCArrayDoubleCapacity(ccCArray *arr)
|
||||||
{
|
{
|
||||||
arr->max *= 2;
|
ccArrayDoubleCapacity((ccArray*)arr);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Increases array capacity such that max >= num + extra. */
|
/** Increases array capacity such that max >= num + extra. */
|
||||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, unsigned int extra)
|
void ccCArrayEnsureExtraCapacity(ccCArray *arr, unsigned int extra)
|
||||||
{
|
{
|
||||||
while (arr->max < arr->num + extra)
|
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
|
||||||
ccCArrayDoubleCapacity(arr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns index of first occurence of value, CC_INVALID_INDEX if value not found. */
|
/** 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");
|
CCAssert( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
|
||||||
|
|
||||||
unsigned int remaining = arr->num - 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
|
// last Value doesn't need to be moved
|
||||||
if( remaining > 0) {
|
if( remaining > 0) {
|
||||||
// tex coordinates
|
// 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. */
|
/** Appends an value. Bahaviour undefined if array doesn't have enough capacity. */
|
||||||
void ccCArrayAppendValue(ccCArray *arr, void* value)
|
void ccCArrayAppendValue(ccCArray *arr, void* value)
|
||||||
{
|
{
|
||||||
arr->arr[arr->num] = (CCObject*) value;
|
arr->arr[arr->num] = value;
|
||||||
arr->num++;
|
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. */
|
/** Appends an value. Capacity of arr is increased if needed. */
|
||||||
|
@ -385,8 +407,10 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index)
|
||||||
unsigned int last;
|
unsigned int last;
|
||||||
|
|
||||||
for( last = --arr->num; index < last; index++)
|
for( last = --arr->num; index < last; index++)
|
||||||
|
{
|
||||||
arr->arr[index] = arr->arr[index + 1];
|
arr->arr[index] = arr->arr[index + 1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Removes value at specified index and fills the gap with the last value,
|
/** Removes value at specified index and fills the gap with the last value,
|
||||||
thereby avoiding the need to push back subsequent values.
|
thereby avoiding the need to push back subsequent values.
|
||||||
|
@ -406,130 +430,42 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
||||||
{
|
{
|
||||||
unsigned int index = ccCArrayGetIndexOfValue(arr, value);
|
unsigned int index = ccCArrayGetIndexOfValue(arr, value);
|
||||||
if (index != CC_INVALID_INDEX)
|
if (index != CC_INVALID_INDEX)
|
||||||
|
{
|
||||||
ccCArrayRemoveValueAtIndex(arr, 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.
|
/** Removes from arr all values in minusArr. For each Value in minusArr, the first matching instance in arr will be removed.
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
*/
|
*/
|
||||||
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
for(unsigned int i = 0; i < minusArr->num; i++)
|
||||||
|
{
|
||||||
for( i = 0; i < minusArr->num; i++)
|
|
||||||
ccCArrayRemoveValue(arr, minusArr->arr[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.
|
/** Removes from arr all values in minusArr. For each value in minusArr, all matching instances in arr will be removed.
|
||||||
@since v0.99.4
|
@since v0.99.4
|
||||||
*/
|
*/
|
||||||
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
|
||||||
unsigned int back = 0;
|
unsigned int back = 0;
|
||||||
|
|
||||||
for( i = 0; i < arr->num; i++) {
|
for(unsigned int i = 0; i < arr->num; i++)
|
||||||
if( ccCArrayContainsValue(minusArr, arr->arr[i]) ) {
|
{
|
||||||
|
if( ccCArrayContainsValue(minusArr, arr->arr[i]) )
|
||||||
|
{
|
||||||
back++;
|
back++;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
arr->arr[i - back] = arr->arr[i];
|
arr->arr[i - back] = arr->arr[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arr->num -= back;
|
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
|
NS_CC_END
|
||||||
|
|
|
@ -52,34 +52,16 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
#define CC_INVALID_INDEX 0xffffffff
|
#define CC_INVALID_INDEX 0xffffffff
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
// #pragma mark ccArray for Objects
|
|
||||||
|
|
||||||
// Easy integration
|
// Easy integration
|
||||||
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
||||||
__object__=__array__->arr[0]; for(unsigned int i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
|
__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 {
|
typedef struct _ccArray {
|
||||||
unsigned int num, max;
|
unsigned int num, max;
|
||||||
CCARRAY_ID *arr;
|
CCObject** arr;
|
||||||
} ccArray;
|
} 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 */
|
/** Allocates and initializes a new array with specified capacity */
|
||||||
ccArray* ccArrayNew(unsigned int capacity);
|
ccArray* ccArrayNew(unsigned int capacity);
|
||||||
|
|
||||||
|
@ -219,14 +201,6 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr);
|
||||||
*/
|
*/
|
||||||
void ccCArrayFullRemoveArray(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
|
NS_CC_END
|
||||||
|
|
||||||
#endif // CC_ARRAY_H
|
#endif // CC_ARRAY_H
|
||||||
|
|
|
@ -268,7 +268,7 @@ private:
|
||||||
/** whether or not the texture has their Alpha premultiplied */
|
/** whether or not the texture has their Alpha premultiplied */
|
||||||
CC_PROPERTY_READONLY(bool, m_bHasPremultipliedAlpha, HasPremultipliedAlpha);
|
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 */
|
/** shader program used by drawAtPoint and drawInRect */
|
||||||
CC_PROPERTY(CCGLProgram*, m_pShaderProgram, ShaderProgram);
|
CC_PROPERTY(CCGLProgram*, m_pShaderProgram, ShaderProgram);
|
||||||
|
|
|
@ -123,7 +123,7 @@ protected:
|
||||||
How many mipmaps do we have. It must be at least one
|
How many mipmaps do we have. It must be at least one
|
||||||
when proper initialization finishes
|
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
|
Makrs for mipmaps. Each entry contains position in file
|
||||||
|
|
Loading…
Reference in New Issue