diff --git a/cocos2dx/CCCamera.h b/cocos2dx/CCCamera.h index 310031146f..e38f6c478d 100644 --- a/cocos2dx/CCCamera.h +++ b/cocos2dx/CCCamera.h @@ -58,7 +58,7 @@ using the camera. - It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object. -- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate. +- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effects, use the action CCFollow or position/scale/rotate. */ class CC_DLL CCCamera : public CCObject diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index 9eb2ac492a..5b86564aad 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -70,7 +70,7 @@ using namespace std; unsigned int g_uNumberOfDraws = 0; NS_CC_BEGIN -// XXX it shoul be a Director ivar. Move it there once support for multiple directors is added +// XXX it should be a Director ivar. Move it there once support for multiple directors is added // singleton stuff static CCDisplayLinkDirector s_SharedDirector; @@ -136,7 +136,7 @@ bool CCDirector::init(void) m_pobOpenGLView = NULL; - m_fContentScaleFactor = 1; + m_fContentScaleFactor = 1.0f; m_bIsContentScaleSupported = false; // scheduler @@ -200,7 +200,7 @@ void CCDirector::setGLDefaultValues(void) glClearColor(0.0f, 0.0f, 0.0f, 1.0f); } -// Draw the SCene +// Draw the Scene void CCDirector::drawScene(void) { // calculate "global" dt @@ -290,16 +290,13 @@ void CCDirector::calculateDeltaTime(void) *m_pLastUpdate = now; } - -// m_pobOpenGLView - void CCDirector::setOpenGLView(CCEGLView *pobOpenGLView) { CCAssert(pobOpenGLView, "opengl view should not be null"); if (m_pobOpenGLView != pobOpenGLView) { - // because EAGLView is not kind of CCObject + // EAGLView is not a CCObject delete m_pobOpenGLView; // [openGLView_ release] m_pobOpenGLView = pobOpenGLView; @@ -591,6 +588,9 @@ void CCDirector::end() void CCDirector::purgeDirector() { + // cleanup scheduler + getScheduler()->unscheduleAllSelectors(); + // don't release the event handlers // They are needed in case the director is run again m_pTouchDispatcher->removeAllDelegates(); @@ -814,7 +814,7 @@ bool CCDirector::enableRetinaDisplay(bool enabled) return true; } - // Already diabled? + // Already disabled? if (!enabled && m_fContentScaleFactor == 1) { return false; @@ -942,7 +942,7 @@ CCAccelerometer* CCDirector::getAccelerometer() * implementation of DisplayLinkDirector **************************************************/ -// should we afford 4 types of director ?? +// should we implement 4 types of director ?? // I think DisplayLinkDirector is enough // so we now only support DisplayLinkDirector void CCDisplayLinkDirector::startAnimation(void) diff --git a/cocos2dx/CCDirector.h b/cocos2dx/CCDirector.h index 2407729e8a..9cbc06d6b2 100644 --- a/cocos2dx/CCDirector.h +++ b/cocos2dx/CCDirector.h @@ -58,7 +58,7 @@ typedef enum { /// it calls "updateProjection" on the projection delegate. kCCDirectorProjectionCustom, - /// Detault projection is 3D projection + /// Default projection is 3D projection kCCDirectorProjectionDefault = kCCDirectorProjection3D, } ccDirectorProjection; @@ -83,7 +83,7 @@ and when to execute the Scenes. - setting the OpenGL pixel format (default on is RGB565) - setting the OpenGL buffer depth (default one is 0-bit) - setting the projection (default one is 3D) - - setting the orientation (default one is Protrait) + - setting the orientation (default one is Portrait) Since the CCDirector is a singleton, the standard way to use it is by calling: _ CCDirector::sharedDirector()->methodName(); diff --git a/cocos2dx/CCDrawingPrimitives.cpp b/cocos2dx/CCDrawingPrimitives.cpp index 085ba16c1b..0053868c44 100644 --- a/cocos2dx/CCDrawingPrimitives.cpp +++ b/cocos2dx/CCDrawingPrimitives.cpp @@ -54,7 +54,7 @@ static void lazy_init( void ) if( ! s_bInitialized ) { // - // Position and 1 color passed as a uniform (to similate glColor4ub ) + // Position and 1 color passed as a uniform (to simulate glColor4ub ) // s_pShader = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_Position_uColor); @@ -67,7 +67,7 @@ static void lazy_init( void ) } } -// When back to foreground on android, we want to it to inilialize again +// When switching from backround to foreground on android, we want the params to be initialized again void ccDrawInit() { s_bInitialized = false; diff --git a/cocos2dx/CCDrawingPrimitives.h b/cocos2dx/CCDrawingPrimitives.h index ee328e43dc..da8311fce8 100644 --- a/cocos2dx/CCDrawingPrimitives.h +++ b/cocos2dx/CCDrawingPrimitives.h @@ -56,7 +56,7 @@ NS_CC_BEGIN class CCPointArray; -/** initlialize context */ +/** initialize context */ void CC_DLL ccDrawInit(); /** draws a point given x and y coordinate measured in points */ @@ -78,12 +78,12 @@ void CC_DLL ccDrawRect( CCPoint origin, CCPoint destination ); */ void CC_DLL ccDrawSolidRect( CCPoint origin, CCPoint destination, ccColor4F color ); -/** draws a poligon given a pointer to CCPoint coordiantes and the number of vertices measured in points. +/** draws a polygon given a pointer to CCPoint coordinates and the number of vertices measured in points. The polygon can be closed or open */ void CC_DLL ccDrawPoly( const CCPoint *vertices, unsigned int numOfVertices, bool closePolygon ); -/** draws a solid polygon given a pointer to CGPoint coordiantes, the number of vertices measured in points, and a color. +/** draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color. */ void CC_DLL ccDrawSolidPoly( const CCPoint *poli, unsigned int numberOfPoints, ccColor4F color ); diff --git a/cocos2dx/CCScheduler.cpp b/cocos2dx/CCScheduler.cpp index ef0ab4e562..e7ce2c8e23 100644 --- a/cocos2dx/CCScheduler.cpp +++ b/cocos2dx/CCScheduler.cpp @@ -164,7 +164,7 @@ void CCTimer::update(float dt) if (m_nScriptHandler) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed, NULL); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(this, m_fElapsed); } m_fElapsed = 0; } @@ -183,7 +183,7 @@ void CCTimer::update(float dt) if (m_nScriptHandler) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed, NULL); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(this, m_fElapsed); } m_fElapsed = m_fElapsed - m_fDelay; @@ -202,7 +202,7 @@ void CCTimer::update(float dt) if (m_nScriptHandler) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed, NULL); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(this, m_fElapsed); } m_fElapsed = 0; @@ -375,7 +375,7 @@ void CCScheduler::priorityIn(tListEntry **ppList, CCObject *pTarget, int nPriori pListElement->next = pListElement->prev = NULL; pListElement->markedForDeletion = false; - // empey list ? + // empty list ? if (! *ppList) { DL_APPEND(*ppList, pListElement); @@ -610,14 +610,14 @@ void CCScheduler::unscheduleAllSelectorsForTarget(CCObject *pTarget) unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler, float fInterval, bool bPaused) { - CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::entryWithHandler(nHandler, fInterval, bPaused); + CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::create(nHandler, fInterval, bPaused); if (!m_pScriptHandlerEntries) { m_pScriptHandlerEntries = CCArray::createWithCapacity(20); m_pScriptHandlerEntries->retain(); } m_pScriptHandlerEntries->addObject(pEntry); - return pEntry->getEntryID(); + return pEntry->getEntryId(); } void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID) @@ -625,7 +625,7 @@ void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID) for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--) { CCSchedulerScriptHandlerEntry* pEntry = static_cast(m_pScriptHandlerEntries->objectAtIndex(i)); - if (pEntry->getEntryID() == uScheduleScriptEntryID) + if (pEntry->getEntryId() == uScheduleScriptEntryID) { pEntry->markedForDeletion(); break; @@ -763,7 +763,7 @@ void CCScheduler::update(float dt) dt *= m_fTimeScale; } - // Iterate all over the Updates selectors + // Iterate over all the Updates' selectors tListEntry *pEntry, *pTmp; // updates with priority < 0 @@ -783,7 +783,7 @@ void CCScheduler::update(float dt) CCScriptEngineProtocol* pEngine = CCScriptEngineManager::sharedManager()->getScriptEngine(); if (pEngine != NULL && kScriptTypeJavascript == pEngine->getScriptType()) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(1, dt, (CCNode *)pEntry->target); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(NULL, dt, (CCNode *)pEntry->target); } pEntry->target->update(dt); @@ -799,7 +799,7 @@ void CCScheduler::update(float dt) } } - // Interate all over the custom selectors + // Iterate over all the custom selectors for (tHashSelectorEntry *elt = m_pHashForSelectors; elt != NULL; ) { m_pCurrentTarget = elt; @@ -838,7 +838,7 @@ void CCScheduler::update(float dt) } } - // Interate all over the script callbacks + // Iterate over all the script callbacks if (m_pScriptHandlerEntries) { for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--) @@ -855,7 +855,7 @@ void CCScheduler::update(float dt) } } - // delete all updates that are morked for deletion + // delete all updates that are marked for deletion // updates with priority < 0 DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp) { diff --git a/cocos2dx/CCScheduler.h b/cocos2dx/CCScheduler.h index 4be9d01e19..af3ed28958 100644 --- a/cocos2dx/CCScheduler.h +++ b/cocos2dx/CCScheduler.h @@ -47,7 +47,7 @@ class CCSet; // // CCTimer // -/** @brief Light weight timer */ +/** @brief Light-weight timer */ class CC_DLL CCTimer : public CCObject { public: @@ -80,6 +80,8 @@ public: /** Allocates a timer with a script callback function and an interval in seconds. */ static CCTimer* timerWithScriptHandler(int nHandler, float fSeconds); + inline int getScriptHandler() { return m_nScriptHandler; }; + public: SEL_SCHEDULE m_pfnSelector; float m_fInterval; @@ -106,7 +108,7 @@ struct _hashUpdateEntry; class CCArray; -/** @brief Scheduler is responsible of triggering the scheduled callbacks. +/** @brief Scheduler is responsible for triggering the scheduled callbacks. You should not use NSTimer. Instead use this class. There are 2 different types of callbacks (selectors): @@ -140,9 +142,9 @@ public: /** The scheduled method will be called every 'interval' seconds. If paused is YES, then it won't be called until it is resumed. - If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead. + If 'interval' is 0, it will be called every frame, but if so, it's recommended to use 'scheduleUpdateForTarget:' instead. If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again. - repeat let the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continiously + repeat let the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously delay is the amount of time the action will wait before it'll start @since v0.99.3, repeat and delay added in v1.1 diff --git a/cocos2dx/actions/CCAction.h b/cocos2dx/actions/CCAction.h index 1e897146f3..3f9375a1c6 100644 --- a/cocos2dx/actions/CCAction.h +++ b/cocos2dx/actions/CCAction.h @@ -234,7 +234,7 @@ public: public: /** creates the action with a set boundary, It will work with no boundary if @param rect is equal to CCRectZero. - @deprecated: Please use create(CCNode*, const CCRect&) intead. This interface will be deprecated sooner or later. + @deprecated: Please use create(CCNode*, const CCRect&) instead. This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCFollow* actionWithTarget(CCNode *pFollowedNode, const CCRect& rect = CCRectZero); /** creates the action with a set boundary, diff --git a/cocos2dx/actions/CCActionCatmullRom.cpp b/cocos2dx/actions/CCActionCatmullRom.cpp index 632cd160a6..6c06f8be59 100644 --- a/cocos2dx/actions/CCActionCatmullRom.cpp +++ b/cocos2dx/actions/CCActionCatmullRom.cpp @@ -26,7 +26,7 @@ * THE SOFTWARE. * * - * Orignal code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So + * Original code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So * * Adapted to cocos2d-x by Vit Valentin * @@ -96,12 +96,12 @@ CCPointArray::CCPointArray() :m_pControlPoints(NULL){} void CCPointArray::addControlPoint(CCPoint controlPoint) { - // should create a new object of CCPoint - // because developer always use this function like this + // should create a new object: CCPoint + // because developers are accustomed to using // addControlPoint(ccp(x, y)) - // passing controlPoint is a temple object - // and CCArray::addObject() will retain the passing object, so it - // should be an object created in heap + // which assumes controlPoint is a temporary struct + // but CCArray::addObject() will retain the passed object, so temp + // should be an object created in the heap. CCPoint *temp = new CCPoint(controlPoint.x, controlPoint.y); m_pControlPoints->addObject(temp); temp->release(); @@ -109,12 +109,12 @@ void CCPointArray::addControlPoint(CCPoint controlPoint) void CCPointArray::insertControlPoint(CCPoint &controlPoint, unsigned int index) { - // should create a new object of CCPoint - // because developer always use this function like this + // should create a new object: CCPoint + // because developers are accustomed to using // insertControlPoint(ccp(x, y)) - // passing controlPoint is a temple object - // and CCArray::insertObject() will retain the passing object, so it - // should be an object created in heap + // which assumes controlPoint is a temporary struct + // but CCArray::insertObject() will retain the passed object, so temp + // should be an object created in the heap. CCPoint *temp = new CCPoint(controlPoint.x, controlPoint.y); m_pControlPoints->insertObject(temp, index); temp->release(); @@ -130,12 +130,12 @@ CCPoint CCPointArray::getControlPointAtIndex(unsigned int index) void CCPointArray::replaceControlPoint(cocos2d::CCPoint &controlPoint, unsigned int index) { - // should create a new object of CCPoint - // because developer always use this function like this + // should create a new object: CCPoint + // because developers are accustomed to using // replaceControlPoint(ccp(x, y)) - // passing controlPoint is a temple object - // and CCArray::insertObject() will retain the passing object, so it - // should be an object created in heap + // which assumes controlPoint is a temporary struct + // but CCArray::insertObject() will retain the passed object, so temp + // should be an object created in the heap. CCPoint *temp = new CCPoint(controlPoint.x, controlPoint.y); m_pControlPoints->replaceObjectAtIndex(index, temp); temp->release(); diff --git a/cocos2dx/actions/CCActionCatmullRom.h b/cocos2dx/actions/CCActionCatmullRom.h index cd9e12f14e..3fbbc66b46 100644 --- a/cocos2dx/actions/CCActionCatmullRom.h +++ b/cocos2dx/actions/CCActionCatmullRom.h @@ -26,7 +26,7 @@ * THE SOFTWARE. * * - * Orignal code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So + * Original code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So * * Adapted to cocos2d-x by Vit Valentin * diff --git a/cocos2dx/actions/CCActionEase.h b/cocos2dx/actions/CCActionEase.h index 8ee4695ca8..e7e9aeb38b 100644 --- a/cocos2dx/actions/CCActionEase.h +++ b/cocos2dx/actions/CCActionEase.h @@ -320,7 +320,7 @@ protected: /** @brief Ease Elastic In action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ @@ -345,7 +345,7 @@ public: /** @brief Ease Elastic Out action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ @@ -371,7 +371,7 @@ public: /** @brief Ease Elastic InOut action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ @@ -440,7 +440,7 @@ public: /** @brief EaseBounceOut action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ @@ -462,7 +462,7 @@ public: /** @brief CCEaseBounceInOut action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ @@ -484,7 +484,7 @@ public: /** @brief CCEaseBackIn action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ @@ -506,7 +506,7 @@ public: /** @brief CCEaseBackOut action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ @@ -528,7 +528,7 @@ public: /** @brief CCEaseBackInOut action. - @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. @since v0.8.2 @ingroup Actions */ diff --git a/cocos2dx/actions/CCActionInstant.cpp b/cocos2dx/actions/CCActionInstant.cpp index b4466420fa..2e0929a945 100644 --- a/cocos2dx/actions/CCActionInstant.cpp +++ b/cocos2dx/actions/CCActionInstant.cpp @@ -435,7 +435,7 @@ void CCCallFunc::execute() { (m_pSelectorTarget->*m_pCallFunc)(); } if (m_nScriptHandler) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionByHandler(m_nScriptHandler); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeCallFuncActionEvent(this); } } @@ -447,7 +447,7 @@ void CCCallFuncN::execute() { (m_pSelectorTarget->*m_pCallFuncN)(m_pTarget); } if (m_nScriptHandler) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithCCObject(m_nScriptHandler, m_pTarget, "CCNode"); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeCallFuncActionEvent(this, m_pTarget); } } diff --git a/cocos2dx/actions/CCActionInstant.h b/cocos2dx/actions/CCActionInstant.h index 38f0eb13ae..334119446c 100644 --- a/cocos2dx/actions/CCActionInstant.h +++ b/cocos2dx/actions/CCActionInstant.h @@ -263,7 +263,8 @@ public: m_pSelectorTarget = pSel; } } - + + inline int getScriptHandler() { return m_nScriptHandler; }; protected: /** Target that will be called */ CCObject* m_pSelectorTarget; diff --git a/cocos2dx/actions/CCActionInterval.cpp b/cocos2dx/actions/CCActionInterval.cpp index 2b86dcf7c3..194d3f693c 100644 --- a/cocos2dx/actions/CCActionInterval.cpp +++ b/cocos2dx/actions/CCActionInterval.cpp @@ -384,7 +384,7 @@ bool CCRepeat::initWithAction(CCFiniteTimeAction *pAction, unsigned int times) pAction->retain(); m_bActionInstant = dynamic_cast(pAction) ? true : false; - //a instant action needs to be executed one time less in the update method since it uses startWithTarget to execute the action + //an instant action needs to be executed one time less in the update method since it uses startWithTarget to execute the action if (m_bActionInstant) { m_uTimes -=1; @@ -463,7 +463,7 @@ void CCRepeat::update(float dt) m_uTotal++; } - // don't set a instantaction back or update it, it has no use because it has no duration + // don't set an instant action back or update it, it has no use because it has no duration if (!m_bActionInstant) { if (m_uTotal == m_uTimes) diff --git a/cocos2dx/actions/CCActionInterval.h b/cocos2dx/actions/CCActionInterval.h index f138b8fc3d..bdd147e478 100644 --- a/cocos2dx/actions/CCActionInterval.h +++ b/cocos2dx/actions/CCActionInterval.h @@ -116,7 +116,7 @@ public: @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actions(CCFiniteTimeAction *pAction1, ...); - /** helper contructor to create an array of sequenceable actions given an array + /** helper constructor to create an array of sequenceable actions given an array @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actionWithArray(CCArray *arrayOfActions); @@ -127,7 +127,7 @@ public: /** helper constructor to create an array of sequenceable actions */ static CCFiniteTimeAction* create(CCFiniteTimeAction *pAction1, ...); - /** helper contructor to create an array of sequenceable actions given an array */ + /** helper constructor to create an array of sequenceable actions given an array */ static CCFiniteTimeAction* create(CCArray *arrayOfActions); /** creates the action */ static CCSequence* createWithTwoActions(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo); @@ -257,7 +257,7 @@ public: */ CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actions(CCFiniteTimeAction *pAction1, ...); - /** helper contructor to create an array of spawned actions given an array + /** helper constructor to create an array of spawned actions given an array @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actionWithArray(CCArray *arrayOfActions); @@ -270,7 +270,7 @@ public: /** helper constructor to create an array of spawned actions */ static CCFiniteTimeAction* create(CCFiniteTimeAction *pAction1, ...); - /** helper contructor to create an array of spawned actions given an array */ + /** helper constructor to create an array of spawned actions given an array */ static CCFiniteTimeAction* create(CCArray *arrayOfActions); /** creates the Spawn action */ diff --git a/cocos2dx/actions/CCActionPageTurn3D.cpp b/cocos2dx/actions/CCActionPageTurn3D.cpp index 125cd94cbd..8397c454dc 100644 --- a/cocos2dx/actions/CCActionPageTurn3D.cpp +++ b/cocos2dx/actions/CCActionPageTurn3D.cpp @@ -96,7 +96,7 @@ void CCPageTurn3D::update(float time) p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta)); // We scale z here to avoid the animation being - // too much bigger than the screen due to perspectve transform + // too much bigger than the screen due to perspective transform p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7;// "100" didn't work for // Stop z coord from dropping beneath underlying page in a transition diff --git a/cocos2dx/actions/CCActionTween.h b/cocos2dx/actions/CCActionTween.h index f355ccb771..2d9197c501 100644 --- a/cocos2dx/actions/CCActionTween.h +++ b/cocos2dx/actions/CCActionTween.h @@ -50,7 +50,7 @@ public: [target runAction:modifyWidth]; - Another example: CCScaleTo action could be rewriten using CCPropertyAction: + Another example: CCScaleTo action could be rewritten using CCPropertyAction: // scaleA and scaleB are equivalents id scaleA = [CCScaleTo actionWithDuration:2 scale:3]; diff --git a/cocos2dx/base_nodes/CCAtlasNode.cpp b/cocos2dx/base_nodes/CCAtlasNode.cpp index 4c814419a6..db54b2052f 100644 --- a/cocos2dx/base_nodes/CCAtlasNode.cpp +++ b/cocos2dx/base_nodes/CCAtlasNode.cpp @@ -130,7 +130,7 @@ void CCAtlasNode::calculateMaxItems() void CCAtlasNode::updateAtlasValues() { - CCAssert(false, "CCAtlasNode:Abstract updateAtlasValue not overriden"); + CCAssert(false, "CCAtlasNode:Abstract updateAtlasValue not overridden"); } // CCAtlasNode - draw diff --git a/cocos2dx/base_nodes/CCAtlasNode.h b/cocos2dx/base_nodes/CCAtlasNode.h index f14eb04507..50885b3778 100644 --- a/cocos2dx/base_nodes/CCAtlasNode.h +++ b/cocos2dx/base_nodes/CCAtlasNode.h @@ -98,7 +98,7 @@ public: bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender); /** updates the Atlas (indexed vertex array). - * Shall be overriden in subclasses + * Shall be overridden in subclasses */ virtual void updateAtlasValues(); diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index 43d80de089..be9e7c0913 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -171,7 +171,7 @@ void CCNode::setZOrder(int z) } } -/// ertexZ getter +/// vertexZ getter float CCNode::getVertexZ() { return m_fVertexZ; @@ -491,7 +491,7 @@ CCNode* CCNode::getChildByTag(int aTag) } /* "add" logic MUST only be on this method -* If a class want's to extend the 'addChild' behaviour it only needs +* If a class want's to extend the 'addChild' behavior it only needs * to override this method */ void CCNode::addChild(CCNode *child, int zOrder, int tag) @@ -681,7 +681,7 @@ void CCNode::sortAllChildren() { //CCAssert(0); // override me - // Only use- this function to draw your staff. + // Only use- this function to draw your stuff. // DON'T draw your stuff outside this method } @@ -798,11 +798,10 @@ void CCNode::onEnter() m_bIsRunning = true; - if ( (m_eScriptType == kScriptTypeLua && m_nScriptHandler != 0) - || m_eScriptType == kScriptTypeJavascript ) + if (m_eScriptType != kScriptTypeNone) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnEnter, this); - } + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnEnter); + } } void CCNode::onEnterTransitionDidFinish() @@ -811,7 +810,7 @@ void CCNode::onEnterTransitionDidFinish() if (m_eScriptType == kScriptTypeJavascript) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnEnterTransitionDidFinish, this); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnEnterTransitionDidFinish); } } @@ -821,7 +820,7 @@ void CCNode::onExitTransitionDidStart() if (m_eScriptType == kScriptTypeJavascript) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnExitTransitionDidStart, this); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnExitTransitionDidStart); } } @@ -831,10 +830,9 @@ void CCNode::onExit() m_bIsRunning = false; - if ( (m_eScriptType == kScriptTypeLua && m_nScriptHandler != 0) - || m_eScriptType == kScriptTypeJavascript ) + if ( m_eScriptType != kScriptTypeNone) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnExit, this); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnExit); } arrayMakeObjectsPerformSelector(m_pChildren, onExit, CCNode*); @@ -851,7 +849,7 @@ void CCNode::unregisterScriptHandler(void) { if (m_nScriptHandler) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nScriptHandler); + CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nScriptHandler); LUALOG("[LUA] Remove CCNode event handler: %d", m_nScriptHandler); m_nScriptHandler = 0; } diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index 3b2e5d2e52..e9595be0de 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -25,8 +25,8 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __PLATFOMR_CCNODE_H__ -#define __PLATFOMR_CCNODE_H__ +#ifndef __PLATFORM_CCNODE_H__ +#define __PLATFORM_CCNODE_H__ #include "ccMacros.h" #include "cocoa/CCAffineTransform.h" @@ -61,12 +61,11 @@ enum { enum { kCCNodeOnEnter, kCCNodeOnExit, - kCCMenuItemActivated, kCCNodeOnEnterTransitionDidFinish, kCCNodeOnExitTransitionDidStart }; -/** @brief CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode. +/** @brief CCNode is the main element. Anything that gets drawn or contains things that get drawn is a CCNode. The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu. The main features of a CCNode are: @@ -240,7 +239,7 @@ public: /** A weak reference to the parent */ CC_PROPERTY(CCNode *, m_pParent, Parent) - // If ture, the Anchor Point will be (0,0) when you position the CCNode. + // If true, the Anchor Point will be (0,0) when you position the CCNode. // Used by CCLayer and CCScene bool m_bIgnoreAnchorPointForPosition; bool isIgnoreAnchorPointForPosition(); @@ -279,6 +278,8 @@ public: */ CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler); + inline int getScriptHandler() { return m_nScriptHandler; }; + protected: // transform @@ -324,7 +325,7 @@ public: */ static CCNode * create(void); - //scene managment + //scene management /** callback that is called every time the CCNode enters the 'stage'. If the CCNode enters the 'stage' with a transition, this callback is called when the transition starts. @@ -576,7 +577,7 @@ public: */ virtual CCAffineTransform parentToNodeTransform(void); - /** Retrusn the world affine transform matrix. The matrix is in Pixels. + /** Returns the world affine transform matrix. The matrix is in Pixels. @since v0.7.1 */ virtual CCAffineTransform nodeToWorldTransform(void); @@ -610,7 +611,7 @@ public: */ CCPoint convertTouchToNodeSpace(CCTouch * touch); - /** converts a CCTouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative). + /** converts a CCTouch (world coordinates) into a local coordinate. This method is AR (Anchor Relative). @since v0.7.1 */ CCPoint convertTouchToNodeSpaceAR(CCTouch * touch); @@ -621,7 +622,7 @@ public: NS_CC_END -#endif // __PLATFOMR_CCNODE_H__ +#endif // __PLATFORM_CCNODE_H__ diff --git a/cocos2dx/cocoa/CCArray.cpp b/cocos2dx/cocoa/CCArray.cpp index 9cc9d5c5e6..7a6735eba0 100644 --- a/cocos2dx/cocoa/CCArray.cpp +++ b/cocos2dx/cocoa/CCArray.cpp @@ -414,7 +414,7 @@ void CCArray::reverseObjects() { if (data->num > 1) { - //floor it since in case of a oneven number the number of swaps stays the same + // floorf(), since in the case of an even number, the number of swaps stays the same int count = (int) floorf(data->num/2.f); unsigned int maxIndex = data->num - 1; diff --git a/cocos2dx/cocoa/CCArray.h b/cocos2dx/cocoa/CCArray.h index c35e8ce225..827bbda49c 100644 --- a/cocos2dx/cocoa/CCArray.h +++ b/cocos2dx/cocoa/CCArray.h @@ -33,7 +33,7 @@ THE SOFTWARE. */ /** @def CCARRAY_FOREACH -A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface. +A convenience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface. @since v0.99.4 */ @@ -139,7 +139,7 @@ public: @brief Generate a CCArray pointer by file @param pFileName The file name of *.plist file @return The CCArray pointer generated from the file - @deprecated: Please use createWithContentsOfFile(const char*) intead. This interface will be deprecated sooner or later. + @deprecated: Please use createWithContentsOfFile(const char*) instead. This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCArray* arrayWithContentsOfFile(const char* pFileName); diff --git a/cocos2dx/cocoa/CCDictionary.cpp b/cocos2dx/cocoa/CCDictionary.cpp index 990fbac698..2265d85540 100644 --- a/cocos2dx/cocoa/CCDictionary.cpp +++ b/cocos2dx/cocoa/CCDictionary.cpp @@ -264,7 +264,7 @@ void CCDictionary::removeAllObjects() CCObject* CCDictionary::copyWithZone(CCZone* pZone) { - CCAssert(pZone == NULL, "CCDirctionary should not be inherited."); + CCAssert(pZone == NULL, "CCDictionary should not be inherited."); CCDictionary* pNewDict = new CCDictionary(); CCDictElement* pElement = NULL; diff --git a/cocos2dx/cocoa/CCNS.cpp b/cocos2dx/cocoa/CCNS.cpp index 0fda42ce48..96360c10aa 100644 --- a/cocos2dx/cocoa/CCNS.cpp +++ b/cocos2dx/cocoa/CCNS.cpp @@ -50,7 +50,7 @@ static inline void split(std::string src, const char* token, strArray& vect) } // first, judge whether the form of the string like this: {x,y} -// if the form is right,the string will be splited into the parameter strs; +// if the form is right,the string will be split into the parameter strs; // or the parameter strs will be empty. // if the form is right return true,else return false. static bool splitWithForm(const char* pStr, strArray& strs) diff --git a/cocos2dx/cocoa/CCObject.cpp b/cocos2dx/cocoa/CCObject.cpp index 07a9e23b3c..c439c1eda7 100644 --- a/cocos2dx/cocoa/CCObject.cpp +++ b/cocos2dx/cocoa/CCObject.cpp @@ -44,7 +44,7 @@ CCObject::CCObject(void) m_uID = ++uObjectCount; m_nLuaID = 0; - // when the object is created, the refrence count of it is 1 + // when the object is created, the reference count of it is 1 m_uReference = 1; m_bManaged = false; } @@ -61,14 +61,14 @@ CCObject::~CCObject(void) // if the object is referenced by Lua engine, remove it if (m_nLuaID) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->removeCCObjectByID(m_nLuaID); + CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptObjectByCCObject(this); } else { CCScriptEngineProtocol* pEngine = CCScriptEngineManager::sharedManager()->getScriptEngine(); if (pEngine != NULL && pEngine->getScriptType() == kScriptTypeJavascript) { - pEngine->removeJSObjectByCCObject(this); + pEngine->removeScriptObjectByCCObject(this); } } } diff --git a/cocos2dx/cocoa/CCObject.h b/cocos2dx/cocoa/CCObject.h index 1cdf5fef53..2aff081ee1 100644 --- a/cocos2dx/cocoa/CCObject.h +++ b/cocos2dx/cocoa/CCObject.h @@ -53,7 +53,7 @@ public: // Lua reference id int m_nLuaID; protected: - // count of refrence + // count of references unsigned int m_uReference; // is the object autoreleased bool m_bManaged; diff --git a/cocos2dx/cocoa/CCSet.h b/cocos2dx/cocoa/CCSet.h index 6d623ed8c0..e6513c3685 100644 --- a/cocos2dx/cocoa/CCSet.h +++ b/cocos2dx/cocoa/CCSet.h @@ -45,7 +45,7 @@ public: virtual ~CCSet(void); /** - *@brief Return a copy of the CCSet, it will copy all the elelments. + *@brief Return a copy of the CCSet, it will copy all the elements. */ CCSet* copy(); /** @@ -73,7 +73,7 @@ public: */ CCSetIterator begin(); /** - *@brief Return the iterator that points to the poisition after the last element. + *@brief Return the iterator that points to the position after the last element. */ CCSetIterator end(); /** diff --git a/cocos2dx/cocoa/CCString.cpp b/cocos2dx/cocoa/CCString.cpp index f522d11eec..f6ea6d8390 100644 --- a/cocos2dx/cocoa/CCString.cpp +++ b/cocos2dx/cocoa/CCString.cpp @@ -219,7 +219,7 @@ CCString* CCString::createWithFormat(const char* format, ...) CCString* CCString::stringWithContentsOfFile(const char* pszFileName) { - return CCString::create(pszFileName); + return CCString::createWithContentsOfFile(pszFileName); } CCString* CCString::createWithContentsOfFile(const char* pszFileName) diff --git a/cocos2dx/cocoa/CCString.h b/cocos2dx/cocoa/CCString.h index 503a37aa0a..bb8f242528 100644 --- a/cocos2dx/cocoa/CCString.h +++ b/cocos2dx/cocoa/CCString.h @@ -84,7 +84,7 @@ public: virtual CCObject* copyWithZone(CCZone* pZone); virtual bool isEqual(const CCObject* pObject); - /* static funcitons */ + /* static functions */ /** create a string with c string * @return A CCString pointer which is an autorelease object pointer, * it means that you needn't do a release operation unless you retain it. @@ -120,7 +120,7 @@ public: */ CC_DEPRECATED_ATTRIBUTE static CCString* stringWithContentsOfFile(const char* pszFileName); - /** create a string with std string, you can also pass a c string pointer because the default constuctor of std::string can access a c string pointer. + /** create a string with std string, you can also pass a c string pointer because the default constructor of std::string can access a c string pointer. * @return A CCString pointer which is an autorelease object pointer, * it means that you needn't do a release operation unless you retain it. */ diff --git a/cocos2dx/effects/CCGrabber.cpp b/cocos2dx/effects/CCGrabber.cpp index dac9879136..6a408960c9 100644 --- a/cocos2dx/effects/CCGrabber.cpp +++ b/cocos2dx/effects/CCGrabber.cpp @@ -53,7 +53,7 @@ void CCGrabber::grab(CCTexture2D *pTexture) GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - CCAssert(0, "Frame Grabber: could not attach texture to frmaebuffer"); + CCAssert(0, "Frame Grabber: could not attach texture to framebuffer"); } glBindFramebuffer(GL_FRAMEBUFFER, m_oldFBO); diff --git a/cocos2dx/effects/CCGrid.cpp b/cocos2dx/effects/CCGrid.cpp index 7b21ab4a1e..9bd870c036 100644 --- a/cocos2dx/effects/CCGrid.cpp +++ b/cocos2dx/effects/CCGrid.cpp @@ -346,7 +346,7 @@ void CCGrid3D::blit(void) // position glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, m_pVertices); - // texCoods + // texCoords glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoordinates); glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, m_pIndices); @@ -551,7 +551,7 @@ void CCTiledGrid3D::blit(void) // position glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, m_pVertices); - // texCoods + // texCoords glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoordinates); glDrawElements(GL_TRIANGLES, (GLsizei)n*6, GL_UNSIGNED_SHORT, m_pIndices); diff --git a/cocos2dx/effects/CCGrid.h b/cocos2dx/effects/CCGrid.h index df008373e3..e6e49c1a5e 100644 --- a/cocos2dx/effects/CCGrid.h +++ b/cocos2dx/effects/CCGrid.h @@ -51,7 +51,7 @@ class CC_DLL CCGridBase : public CCObject public: virtual ~CCGridBase(void); - /** wheter or not the grid is active */ + /** whether or not the grid is active */ inline bool isActive(void) { return m_bActive; } void setActive(bool bActive); diff --git a/cocos2dx/include/CCProtocols.h b/cocos2dx/include/CCProtocols.h old mode 100755 new mode 100644 index 2dd5c0b87f..6ea1c60664 --- a/cocos2dx/include/CCProtocols.h +++ b/cocos2dx/include/CCProtocols.h @@ -50,7 +50,7 @@ public: virtual GLubyte getOpacity(void) = 0; /** sets the opacity. - @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed. + @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modified. Values goes from 0 to 255, where 255 means fully opaque. */ virtual void setOpacity(GLubyte opacity) = 0; @@ -59,7 +59,7 @@ public: /** sets the premultipliedAlphaOpacity property. If set to NO then opacity will be applied as: glColor(R,G,B,opacity); - If set to YES then oapcity will be applied as: glColor(opacity, opacity, opacity, opacity ); + If set to YES then opacity will be applied as: glColor(opacity, opacity, opacity, opacity ); Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO @since v0.8 */ @@ -72,7 +72,7 @@ public: }; /** - @brief You can specify the blending fuction. + @brief You can specify the blending function. @since v0.99.0 */ class CC_DLL CCBlendProtocol @@ -91,7 +91,7 @@ public: src=GL_ONE dst= GL_ONE_MINUS_SRC_ALPHA else src=GL_SRC_ALPHA dst= GL_ONE_MINUS_SRC_ALPHA - But you can change the blending funtion at any time. + But you can change the blending function at any time. @since v0.8.0 */ class CC_DLL CCTextureProtocol : public CCBlendProtocol @@ -119,7 +119,7 @@ public: class CC_DLL CCDirectorDelegate { public: - /** Called by CCDirector when the porjection is updated, and "custom" projection is used + /** Called by CCDirector when the projection is updated, and "custom" projection is used @since v0.99.5 */ virtual void updateProjection(void) = 0; diff --git a/cocos2dx/include/ccConfig.h b/cocos2dx/include/ccConfig.h old mode 100755 new mode 100644 index 4b3c3ba753..5b3bd9f44b --- a/cocos2dx/include/ccConfig.h +++ b/cocos2dx/include/ccConfig.h @@ -36,14 +36,14 @@ THE SOFTWARE. /** @def CC_ENABLE_GL_STATE_CACHE If enabled, cocos2d will maintain an OpenGL state cache internally to avoid unnecessary switches. - In order to use them, you have to use the following functions, insead of the the GL ones: + In order to use them, you have to use the following functions, instead of the the GL ones: - ccGLUseProgram() instead of glUseProgram() - ccGLDeleteProgram() instead of glDeleteProgram() - ccGLBlendFunc() instead of glBlendFunc() If this functionality is disabled, then ccGLUseProgram(), ccGLDeleteProgram(), ccGLBlendFunc() will call the GL ones, without using the cache. - It is recommened to enable whenever possible to improve speed. + It is recommended to enable whenever possible to improve speed. If you are migrating your code from GL ES 1.1, then keep it disabled. Once all your code works as expected, turn it on. @since v2.0.0 @@ -77,7 +77,7 @@ To enabled set it to 1. Disabled by default. #endif /** @def CC_DIRECTOR_FPS_INTERVAL - Senconds between FPS updates. + Seconds between FPS updates. 0.5 seconds, means that the FPS number will be updated every 0.5 seconds. Having a bigger number means a more reliable FPS @@ -190,7 +190,7 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios. /** @def CC_SPRITE_DEBUG_DRAW If enabled, all subclasses of CCSprite will draw a bounding box - Useful for debugging purposes only. It is recommened to leave it disabled. + Useful for debugging purposes only. It is recommended to leave it disabled. To enable set it to a value different than 0. Disabled by default: 0 -- disabled @@ -206,7 +206,7 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios. /** @def CC_SPRITEBATCHNODE_DEBUG_DRAW If enabled, all subclasses of CCSprite that are rendered using an CCSpriteBatchNode draw a bounding box. -Useful for debugging purposes only. It is recommened to leave it disabled. +Useful for debugging purposes only. It is recommended to leave it disabled. To enable set it to a value different than 0. Disabled by default. */ @@ -216,7 +216,7 @@ To enable set it to a value different than 0. Disabled by default. /** @def CC_LABELBMFONT_DEBUG_DRAW If enabled, all subclasses of CCLabelBMFont will draw a bounding box -Useful for debugging purposes only. It is recommened to leave it disabled. +Useful for debugging purposes only. It is recommended to leave it disabled. To enable set it to a value different than 0. Disabled by default. */ @@ -226,7 +226,7 @@ To enable set it to a value different than 0. Disabled by default. /** @def CC_LABELATLAS_DEBUG_DRAW If enabled, all subclasses of LabeltAtlas will draw a bounding box - Useful for debugging purposes only. It is recommened to leave it disabled. + Useful for debugging purposes only. It is recommended to leave it disabled. To enable set it to a value different than 0. Disabled by default. */ @@ -235,9 +235,9 @@ To enable set it to a value different than 0. Disabled by default. #endif /** @def CC_ENABLE_PROFILERS - If enabled, will activate various profilers withing cocos2d. This statistical data will be output to the console + If enabled, will activate various profilers within cocos2d. This statistical data will be output to the console once per second showing average time (in milliseconds) required to execute the specific routine(s). - Useful for debugging purposes only. It is recommened to leave it disabled. + Useful for debugging purposes only. It is recommended to leave it disabled. To enable set it to a value different than 0. Disabled by default. */ diff --git a/cocos2dx/include/ccMacros.h b/cocos2dx/include/ccMacros.h index 49252d46bb..e3c3dff77c 100644 --- a/cocos2dx/include/ccMacros.h +++ b/cocos2dx/include/ccMacros.h @@ -163,7 +163,7 @@ CCSizeMake( (__size_in_points__).width * CC_CONTENT_SCALE_FACTOR(), (__size_in_p void operator=(const TypeName&) /** -Helper marcos which converts 4-byte little/big endian +Helper macros which converts 4-byte little/big endian integral number to the machine native number representation It should work same as apples CFSwapInt32LittleToHost(..) diff --git a/cocos2dx/include/ccTypes.h b/cocos2dx/include/ccTypes.h old mode 100755 new mode 100644 index efccf070eb..790de5cab1 --- a/cocos2dx/include/ccTypes.h +++ b/cocos2dx/include/ccTypes.h @@ -254,7 +254,7 @@ typedef struct _ccV3F_C4B_T2F // char __padding2__[4]; // tex coords (2F) - ccTex2F texCoords; // 8 byts + ccTex2F texCoords; // 8 bytes } ccV3F_C4B_T2F; //! 4 ccVertex2FTex2FColor4B Quad @@ -305,7 +305,7 @@ typedef struct _ccBlendFunc GLenum dst; } ccBlendFunc; -// XXX: If any of these enums are edited and/or reordered, udpate CCTexture2D.m +// XXX: If any of these enums are edited and/or reordered, update CCTexture2D.m //! Vertical text alignment type typedef enum { @@ -314,7 +314,7 @@ typedef enum kCCVerticalTextAlignmentBottom, } CCVerticalTextAlignment; -// XXX: If any of these enums are edited and/or reordered, udpate CCTexture2D.m +// XXX: If any of these enums are edited and/or reordered, update CCTexture2D.m //! Horizontal text alignment type typedef enum { diff --git a/cocos2dx/kazmath/include/kazmath/aabb.h b/cocos2dx/kazmath/include/kazmath/aabb.h index 6b1860c13b..629889cef1 100644 --- a/cocos2dx/kazmath/include/kazmath/aabb.h +++ b/cocos2dx/kazmath/include/kazmath/aabb.h @@ -35,7 +35,7 @@ extern "C" { #endif /** - * A struture that represents an axis-aligned + * A structure that represents an axis-aligned * bounding box. */ typedef struct kmAABB { diff --git a/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h b/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h index 2223c65857..6e73e64a23 100644 --- a/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h +++ b/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h @@ -32,13 +32,13 @@ #endif #endif // __arm__ -// Matrixes are assumed to be stored in column major format according to OpenGL +// Matrices are assumed to be stored in column major format according to OpenGL // specification. -// Multiplies two 4x4 matrices (a,b) outputing a 4x4 matrix (output) +// Multiplies two 4x4 matrices (a,b) outputting a 4x4 matrix (output) void NEON_Matrix4Mul(const float* a, const float* b, float* output ); -// Multiplies a 4x4 matrix (m) with a vector 4 (v), outputing a vector 4 +// Multiplies a 4x4 matrix (m) with a vector 4 (v), outputting a vector 4 void NEON_Matrix4Vector4Mul(const float* m, const float* v, float* output); diff --git a/cocos2dx/kazmath/include/kazmath/plane.h b/cocos2dx/kazmath/include/kazmath/plane.h index 0a42daf63e..c4e4fe5b7e 100644 --- a/cocos2dx/kazmath/include/kazmath/plane.h +++ b/cocos2dx/kazmath/include/kazmath/plane.h @@ -62,7 +62,7 @@ CC_DLL kmPlane* const kmPlaneFromPoints(kmPlane* pOut, const struct kmVec3* p1, CC_DLL kmVec3* const kmPlaneIntersectLine(struct kmVec3* pOut, const kmPlane* pP, const struct kmVec3* pV1, const struct kmVec3* pV2); CC_DLL kmPlane* const kmPlaneNormalize(kmPlane* pOut, const kmPlane* pP); CC_DLL kmPlane* const kmPlaneScale(kmPlane* pOut, const kmPlane* pP, kmScalar s); -CC_DLL const POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3* pP); /** Classifys a point against a plane */ +CC_DLL const POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3* pP); /** Classifies a point against a plane */ #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/src/GL/matrix.c b/cocos2dx/kazmath/src/GL/matrix.c index f074f86251..dfd8a87259 100644 --- a/cocos2dx/kazmath/src/GL/matrix.c +++ b/cocos2dx/kazmath/src/GL/matrix.c @@ -100,7 +100,7 @@ void kmGLPushMatrix(void) void kmGLPopMatrix(void) { assert(initialized && "Cannot Pop empty matrix stack"); - //No need to lazy initialize, you shouldnt be popping first anyway! + //No need to lazy initialize, you shouldn't be popping first anyway! km_mat4_stack_pop(current_stack, NULL); } diff --git a/cocos2dx/kazmath/src/mat3.c b/cocos2dx/kazmath/src/mat3.c index d5549a7792..6654d0634f 100644 --- a/cocos2dx/kazmath/src/mat3.c +++ b/cocos2dx/kazmath/src/mat3.c @@ -55,7 +55,7 @@ const kmScalar kmMat3Determinant(const kmMat3* pIn) m = | 1 4 7 | 1 4 | | 2 5 8 | 2 5 | now sum up the products of the diagonals going to the right (i.e. 0,4,8) - and substract the products of the other diagonals (i.e. 2,4,6) + and subtract the products of the other diagonals (i.e. 2,4,6) */ output = pIn->mat[0] * pIn->mat[4] * pIn->mat[8] + pIn->mat[1] * pIn->mat[5] * pIn->mat[6] + pIn->mat[2] * pIn->mat[3] * pIn->mat[7]; diff --git a/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h b/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h index fe930880a8..fd47e80523 100644 --- a/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h +++ b/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h @@ -41,7 +41,7 @@ public: // The back key clicked virtual void keyBackClicked() {} - // The menu key clicked. only avialble on wophone & android + // The menu key clicked. only available on wophone & android virtual void keyMenuClicked() {}; }; diff --git a/cocos2dx/label_nodes/CCLabelBMFont.cpp b/cocos2dx/label_nodes/CCLabelBMFont.cpp index 737e801e42..299fd7553d 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.cpp +++ b/cocos2dx/label_nodes/CCLabelBMFont.cpp @@ -931,7 +931,7 @@ void CCLabelBMFont::createFontChars() // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on fontChar->setColor(m_tColor); - // only apply opaccity if it is different than 255 ) + // only apply opacity if it is different than 255 ) // to prevent modifying the color too (issue #610) if( m_cOpacity != 255 ) { diff --git a/cocos2dx/label_nodes/CCLabelBMFont.h b/cocos2dx/label_nodes/CCLabelBMFont.h index eec1a44389..0488b3df3e 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.h +++ b/cocos2dx/label_nodes/CCLabelBMFont.h @@ -93,7 +93,7 @@ typedef struct _BMFontPadding { */ class CC_DLL CCBMFontConfiguration : public CCObject { - // XXX: Creating a public interface so that the bitmapFontArray[] is accesible + // XXX: Creating a public interface so that the bitmapFontArray[] is accessible public://@public // BMFont definitions struct _FontDefHashElement* m_pFontDefDictionary; @@ -142,7 +142,7 @@ Features: - scaled - translated - tinted -- chage the opacity +- change the opacity - It can be used as part of a menu item. - anchorPoint can be used to align the "label" - Supports AngelCode text format @@ -202,11 +202,11 @@ public: @since v0.99.3 */ static void purgeCachedData(); - /** creates a bitmap font altas with an initial string and the FNT file + /** creates a bitmap font atlas with an initial string and the FNT file @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCLabelBMFont * labelWithString(const char *str, const char *fntFile, float width = kCCLabelAutomaticWidth, CCTextAlignment alignment = kCCTextAlignmentLeft, CCPoint imageOffset = CCPointZero); - /** creates a bitmap font altas with an initial string and the FNT file */ + /** creates a bitmap font atlas with an initial string and the FNT file */ static CCLabelBMFont * create(const char *str, const char *fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset); static CCLabelBMFont * create(const char *str, const char *fntFile, float width, CCTextAlignment alignment) { @@ -231,7 +231,7 @@ public: static CCLabelBMFont * create(); bool init(); - /** init a bitmap font altas with an initial string and the FNT file */ + /** init a bitmap font atlas with an initial string and the FNT file */ bool initWithString(const char *str, const char *fntFile, float width = kCCLabelAutomaticWidth, CCTextAlignment alignment = kCCTextAlignmentLeft, CCPoint imageOffset = CCPointZero); /** updates the font chars based on the string to render */ diff --git a/cocos2dx/label_nodes/CCLabelTTF.cpp b/cocos2dx/label_nodes/CCLabelTTF.cpp index 8ed7a89205..1aaa340771 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.cpp +++ b/cocos2dx/label_nodes/CCLabelTTF.cpp @@ -227,7 +227,7 @@ void CCLabelTTF::setDimensions(const CCSize &dim) { m_tDimensions = dim; - // Force udpate + // Force update if (m_string.size() > 0) { this->updateTexture(); diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index cd64003bbd..f0b3347a6e 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -123,7 +123,7 @@ void CCLayer::registerWithTouchDispatcher() void CCLayer::registerScriptTouchHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches) { unregisterScriptTouchHandler(); - m_pScriptHandlerEntry = CCTouchScriptHandlerEntry::entryWithHandler(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches); + m_pScriptHandlerEntry = CCTouchScriptHandlerEntry::create(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches); m_pScriptHandlerEntry->retain(); } @@ -138,22 +138,12 @@ void CCLayer::unregisterScriptTouchHandler(void) int CCLayer::excuteScriptTouchHandler(int nEventType, CCTouch *pTouch) { - return CCScriptEngineManager::sharedManager()->getScriptEngine()->executeTouchEvent(m_pScriptHandlerEntry->getHandler(), nEventType, pTouch); + return CCScriptEngineManager::sharedManager()->getScriptEngine()->executeLayerTouchEvent(this, nEventType, pTouch); } int CCLayer::excuteScriptTouchHandler(int nEventType, CCSet *pTouches) { - int ret = 0; - if (kScriptTypeJavascript == m_eScriptType) - { - ret = CCScriptEngineManager::sharedManager()->getScriptEngine()->executeTouchesEvent(1, nEventType, pTouches, this); - } - else if (kScriptTypeLua == m_eScriptType) - { - ret = CCScriptEngineManager::sharedManager()->getScriptEngine()->executeTouchesEvent(m_pScriptHandlerEntry->getHandler(), nEventType, pTouches, this); - } - - return ret; + return CCScriptEngineManager::sharedManager()->getScriptEngine()->executeLayerTouchesEvent(this, nEventType, pTouches); } /// isTouchEnabled getter @@ -257,7 +247,7 @@ void CCLayer::onEnter() pDirector->getAccelerometer()->setDelegate(this); } - // add this layer to concern the kaypad msg + // add this layer to concern the keypad msg if (m_bIsKeypadEnabled) { pDirector->getKeypadDispatcher()->addDelegate(this); @@ -279,7 +269,7 @@ void CCLayer::onExit() pDirector->getAccelerometer()->setDelegate(NULL); } - // remove this layer from the delegates who concern the kaypad msg + // remove this layer from the delegates who concern the keypad msg if (m_bIsKeypadEnabled) { pDirector->getKeypadDispatcher()->removeDelegate(this); @@ -301,7 +291,7 @@ void CCLayer::onEnterTransitionDidFinish() bool CCLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { return excuteScriptTouchHandler(CCTOUCHBEGAN, pTouch) == 0 ? false : true; } @@ -314,7 +304,7 @@ bool CCLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) void CCLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { excuteScriptTouchHandler(CCTOUCHMOVED, pTouch); return; @@ -326,7 +316,7 @@ void CCLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) void CCLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { excuteScriptTouchHandler(CCTOUCHENDED, pTouch); return; @@ -338,7 +328,7 @@ void CCLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) void CCLayer::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { excuteScriptTouchHandler(CCTOUCHCANCELLED, pTouch); return; @@ -350,7 +340,7 @@ void CCLayer::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) void CCLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { excuteScriptTouchHandler(CCTOUCHBEGAN, pTouches); return; @@ -362,7 +352,7 @@ void CCLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) void CCLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { excuteScriptTouchHandler(CCTOUCHMOVED, pTouches); return; @@ -374,7 +364,7 @@ void CCLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) void CCLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { excuteScriptTouchHandler(CCTOUCHENDED, pTouches); return; @@ -386,7 +376,7 @@ void CCLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) void CCLayer::ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent) { - if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry)) + if (kScriptTypeNone != m_eScriptType) { excuteScriptTouchHandler(CCTOUCHCANCELLED, pTouches); return; diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h index 3037f8186c..ecff165334 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h @@ -119,6 +119,7 @@ public: bool isKeypadEnabled(); void setKeypadEnabled(bool value); + inline CCTouchScriptHandlerEntry* getScriptHandlerEntry() { return m_pScriptHandlerEntry; }; protected: bool m_bIsTouchEnabled; bool m_bIsAccelerometerEnabled; @@ -292,7 +293,7 @@ public: /** * lua script can not init with undetermined number of variables - * so add these functinons to be used with lua. + * so add these functions to be used with lua. @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCLayerMultiplex * layerWithLayer(CCLayer* layer); @@ -302,7 +303,7 @@ public: /** * lua script can not init with undetermined number of variables - * so add these functinons to be used with lua. + * so add these functions to be used with lua. */ static CCLayerMultiplex * createWithLayer(CCLayer* layer); diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.h b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.h index ec821a516e..a146af445a 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.h @@ -130,7 +130,7 @@ public: /** called after the transition finishes */ void finish(void); - /** used by some transitions to hide the outter scene */ + /** used by some transitions to hide the outer scene */ void hideOutShowIn(void); protected: @@ -266,7 +266,7 @@ public: /** initializes the scenes */ virtual void initScenes(void); - /** returns the action that will be performed by the incomming and outgoing scene */ + /** returns the action that will be performed by the incoming and outgoing scene */ virtual CCActionInterval* action(void); virtual void onEnter(); @@ -290,7 +290,7 @@ public: /** initializes the scenes */ virtual void initScenes(void); - /** returns the action that will be performed by the incomming and outgoing scene */ + /** returns the action that will be performed by the incoming and outgoing scene */ virtual CCActionInterval* action(void); TRANSITION_CREATE_FUNC(CCTransitionSlideInR); @@ -310,7 +310,7 @@ public: /** initializes the scenes */ virtual void initScenes(void); - /** returns the action that will be performed by the incomming and outgoing scene */ + /** returns the action that will be performed by the incoming and outgoing scene */ virtual CCActionInterval* action(void); TRANSITION_CREATE_FUNC(CCTransitionSlideInB); @@ -330,7 +330,7 @@ public: /** initializes the scenes */ virtual void initScenes(void); - /** returns the action that will be performed by the incomming and outgoing scene */ + /** returns the action that will be performed by the incoming and outgoing scene */ virtual CCActionInterval* action(void); TRANSITION_CREATE_FUNC(CCTransitionSlideInT); diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCTransitionProgress.h b/cocos2dx/layers_scenes_transitions_nodes/CCTransitionProgress.h index 11b9976899..7ae48686be 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCTransitionProgress.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCTransitionProgress.h @@ -59,7 +59,7 @@ protected: /** CCTransitionRadialCCW transition. - A counter colock-wise radial transition to the next scene + A counter clock-wise radial transition to the next scene */ class CC_DLL CCTransitionProgressRadialCCW : public CCTransitionProgress { @@ -73,7 +73,7 @@ protected: /** CCTransitionRadialCW transition. - A counter colock-wise radial transition to the next scene + A counter clock-wise radial transition to the next scene */ class CC_DLL CCTransitionProgressRadialCW : public CCTransitionProgress { @@ -86,7 +86,7 @@ protected: }; /** CCTransitionProgressHorizontal transition. - A colock-wise radial transition to the next scene + A clock-wise radial transition to the next scene */ class CC_DLL CCTransitionProgressHorizontal : public CCTransitionProgress { diff --git a/cocos2dx/menu_nodes/CCMenu.h b/cocos2dx/menu_nodes/CCMenu.h index d636592c83..8a1453f420 100644 --- a/cocos2dx/menu_nodes/CCMenu.h +++ b/cocos2dx/menu_nodes/CCMenu.h @@ -51,7 +51,7 @@ enum { * * Features and Limitation: * - You can add MenuItem objects in runtime using addChild: -* - But the only accecpted children are MenuItem objects +* - But the only accepted children are MenuItem objects */ class CC_DLL CCMenu : public CCLayer, public CCRGBAProtocol { diff --git a/cocos2dx/menu_nodes/CCMenuItem.cpp b/cocos2dx/menu_nodes/CCMenuItem.cpp index 934af1e43c..50021da77c 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.cpp +++ b/cocos2dx/menu_nodes/CCMenuItem.cpp @@ -80,7 +80,7 @@ bool CCMenuItem::initWithTarget(CCObject *rec, SEL_MenuHandler selector) CCMenuItem::~CCMenuItem() { - unregisterScriptHandler(); + unregisterScriptTapHandler(); } void CCMenuItem::selected() @@ -93,20 +93,20 @@ void CCMenuItem::unselected() m_bIsSelected = false; } -void CCMenuItem::registerScriptHandler(int nHandler) +void CCMenuItem::registerScriptTapHandler(int nHandler) { - unregisterScriptHandler(); - m_nScriptHandler = nHandler; - LUALOG("[LUA] Add CCMenuItem script handler: %d", m_nScriptHandler); + unregisterScriptTapHandler(); + m_nScriptTapHandler = nHandler; + LUALOG("[LUA] Add CCMenuItem script handler: %d", m_nScriptTapHandler); } -void CCMenuItem::unregisterScriptHandler(void) +void CCMenuItem::unregisterScriptTapHandler(void) { - if (m_nScriptHandler) + if (m_nScriptTapHandler) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nScriptHandler); - LUALOG("[LUA] Remove CCMenuItem script handler: %d", m_nScriptHandler); - m_nScriptHandler = 0; + CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nScriptTapHandler); + LUALOG("[LUA] Remove CCMenuItem script handler: %d", m_nScriptTapHandler); + m_nScriptTapHandler = 0; } } @@ -119,13 +119,9 @@ void CCMenuItem::activate() (m_pListener->*m_pfnSelector)(this); } - if (kScriptTypeJavascript == m_eScriptType) + if (kScriptTypeNone != m_eScriptType) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCMenuItemActivated, this); - } - else if( kScriptTypeLua == m_eScriptType && m_nScriptHandler != 0) - { - CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, getTag(), this); + CCScriptEngineManager::sharedManager()->getScriptEngine()->executeMenuItemEvent(this); } } } diff --git a/cocos2dx/menu_nodes/CCMenuItem.h b/cocos2dx/menu_nodes/CCMenuItem.h index c085b27a73..379737c9ba 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.h +++ b/cocos2dx/menu_nodes/CCMenuItem.h @@ -65,7 +65,7 @@ public: , m_bIsEnabled(false) , m_pListener(NULL) , m_pfnSelector(NULL) - , m_nScriptHandler(0) + , m_nScriptTapHandler(0) {} virtual ~CCMenuItem(); /** Creates a CCMenuItem with a target/selector @@ -88,9 +88,10 @@ public: virtual void unselected(); /** Register menu handler script function */ - virtual void registerScriptHandler(int nHandler); - virtual void unregisterScriptHandler(void); - + virtual void registerScriptTapHandler(int nHandler); + virtual void unregisterScriptTapHandler(void); + int getScriptTapHandler() { return m_nScriptTapHandler; }; + virtual bool isEnabled(); //@note: It's 'setIsEnable' in cocos2d-iphone. virtual void setEnabled(bool value); @@ -98,10 +99,11 @@ public: /** set the target/selector of the menu item*/ void setTarget(CCObject *rec, SEL_MenuHandler selector); + protected: CCObject* m_pListener; SEL_MenuHandler m_pfnSelector; - int m_nScriptHandler; + int m_nScriptTapHandler; }; /** @brief An abstract class for "label" CCMenuItemLabel items @@ -127,14 +129,14 @@ public: @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCMenuItemLabel * itemWithLabel(CCNode*label, CCObject* target, SEL_MenuHandler selector); - /** creates a CCMenuItemLabel with a Label. Target and selector will be nill + /** creates a CCMenuItemLabel with a Label. Target and selector will be nil @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCMenuItemLabel* itemWithLabel(CCNode *label); /** creates a CCMenuItemLabel with a Label, target and selector */ static CCMenuItemLabel * create(CCNode*label, CCObject* target, SEL_MenuHandler selector); - /** creates a CCMenuItemLabel with a Label. Target and selector will be nill */ + /** creates a CCMenuItemLabel with a Label. Target and selector will be nil */ static CCMenuItemLabel* create(CCNode *label); /** initializes a CCMenuItemLabel with a Label, target and selector */ @@ -371,7 +373,7 @@ public: /** @brief A CCMenuItemToggle A simple container class that "toggles" it's inner items - The inner itmes can be any MenuItem + The inner items can be any MenuItem */ class CC_DLL CCMenuItemToggle : public CCMenuItem, public CCRGBAProtocol { diff --git a/cocos2dx/misc_nodes/CCMotionStreak.cpp b/cocos2dx/misc_nodes/CCMotionStreak.cpp index 30c13792d3..8d2d85027d 100644 --- a/cocos2dx/misc_nodes/CCMotionStreak.cpp +++ b/cocos2dx/misc_nodes/CCMotionStreak.cpp @@ -299,7 +299,7 @@ void CCMotionStreak::update(float delta) m_pPointVertexes[m_uNuPoints] = m_tPositionR; m_pPointState[m_uNuPoints] = 1.0f; - // Color asignation + // Color assignment const unsigned int offset = m_uNuPoints*8; *((ccColor3B*)(m_pColorPointer + offset)) = m_tColor; *((ccColor3B*)(m_pColorPointer + offset+4)) = m_tColor; diff --git a/cocos2dx/misc_nodes/CCMotionStreak.h b/cocos2dx/misc_nodes/CCMotionStreak.h index c09784cdc1..c93e6936e4 100644 --- a/cocos2dx/misc_nodes/CCMotionStreak.h +++ b/cocos2dx/misc_nodes/CCMotionStreak.h @@ -87,7 +87,7 @@ public: virtual void setOpacityModifyRGB(bool bValue); virtual bool isOpacityModifyRGB(void); - /** When fast mode is enbled, new points are added faster but with lower precision */ + /** When fast mode is enabled, new points are added faster but with lower precision */ inline bool isFastMode() { return m_bFastMode; } inline void setFastMode(bool bFastMode) { m_bFastMode = bFastMode; } diff --git a/cocos2dx/misc_nodes/CCProgressTimer.cpp b/cocos2dx/misc_nodes/CCProgressTimer.cpp index fa98613a04..a348d7175f 100644 --- a/cocos2dx/misc_nodes/CCProgressTimer.cpp +++ b/cocos2dx/misc_nodes/CCProgressTimer.cpp @@ -118,7 +118,7 @@ void CCProgressTimer::setSprite(CCSprite *pSprite) m_pSprite = pSprite; setContentSize(m_pSprite->getContentSize()); - // Everytime we set a new sprite, we free the current vertex data + // Every time we set a new sprite, we free the current vertex data if (m_pVertexData) { CC_SAFE_FREE(m_pVertexData); diff --git a/cocos2dx/misc_nodes/CCProgressTimer.h b/cocos2dx/misc_nodes/CCProgressTimer.h index 475b0bb941..3f3aebbcc7 100644 --- a/cocos2dx/misc_nodes/CCProgressTimer.h +++ b/cocos2dx/misc_nodes/CCProgressTimer.h @@ -45,7 +45,7 @@ typedef enum { } CCProgressTimerType; /** - @brief CCProgresstimer is a subclass of CCNode. + @brief CCProgressTimer is a subclass of CCNode. It renders the inner sprite according to the percentage. The progress can be Radial, Horizontal or vertical. @since v0.99.1 diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index 9839d7e0a7..bed3dae646 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -431,7 +431,7 @@ CCImage* CCRenderTexture::newCCImage() const CCSize& s = m_pTexture->getContentSizeInPixels(); // to get the image size to save - // if the saving image domain exeeds the buffer texture domain, + // if the saving image domain exceeds the buffer texture domain, // it should be cut int nSavedBufferWidth = (int)s.width; int nSavedBufferHeight = (int)s.height; @@ -458,7 +458,7 @@ CCImage* CCRenderTexture::newCCImage() this->end(); // to get the actual texture data - // #640 the image read from rendertexture is upseted + // #640 the image read from rendertexture is dirty for (int i = 0; i < nSavedBufferHeight; ++i) { memcpy(&pBuffer[i * nSavedBufferWidth * 4], diff --git a/cocos2dx/misc_nodes/CCRenderTexture.h b/cocos2dx/misc_nodes/CCRenderTexture.h index 7dc58c8014..22d9ae8c0b 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.h +++ b/cocos2dx/misc_nodes/CCRenderTexture.h @@ -44,7 +44,7 @@ typedef enum eImageFormat /** @brief CCRenderTexture is a generic rendering target. To render things into it, simply construct a render target, call begin on it, call visit on any cocos -scenes or objects to render them, and call end. For convienience, render texture +scenes or objects to render them, and call end. For convenience, render texture adds a sprite as it's display child with the results, so you can simply add the render texture to your scene and treat it like any other CocosNode. There are also functions for saving the render texture to disk in PNG or JPG format. diff --git a/cocos2dx/particle_nodes/CCParticleBatchNode.cpp b/cocos2dx/particle_nodes/CCParticleBatchNode.cpp index 86da441a9b..e6d1721226 100644 --- a/cocos2dx/particle_nodes/CCParticleBatchNode.cpp +++ b/cocos2dx/particle_nodes/CCParticleBatchNode.cpp @@ -135,7 +135,7 @@ void CCParticleBatchNode::visit() // with the exception that it doesn't call visit on it's children // // The alternative is to have a void CCSprite#visit, but - // although this is less mantainable, is faster + // although this is less maintainable, is faster // if (!m_bIsVisible) { @@ -185,7 +185,7 @@ void CCParticleBatchNode::addChild(CCNode * child, int zOrder, int tag) setBlendFunc(pChild->getBlendFunc()); } - CCAssert( m_tBlendFunc.src == pChild->getBlendFunc().src && m_tBlendFunc.dst == pChild->getBlendFunc().dst, "Can't add a PaticleSystem that uses a differnt blending function"); + CCAssert( m_tBlendFunc.src == pChild->getBlendFunc().src && m_tBlendFunc.dst == pChild->getBlendFunc().dst, "Can't add a PaticleSystem that uses a different blending function"); //no lazy sorting, so don't call super addChild, call helper instead unsigned int pos = addChildHelper(pChild,zOrder,tag); @@ -388,7 +388,7 @@ void CCParticleBatchNode::removeChild(CCNode* child, bool cleanup) // after memmove of data, empty the quads at the end of array m_pTextureAtlas->fillWithEmptyQuadsFromIndex(m_pTextureAtlas->getTotalQuads(), pChild->getTotalParticles()); - // paticle could be reused for self rendering + // particle could be reused for self rendering pChild->setBatchNode(NULL); updateAllAtlasIndexes(); @@ -469,7 +469,7 @@ void CCParticleBatchNode::insertChild(CCParticleSystem* pSystem, unsigned int in m_pTextureAtlas->moveQuadsFromIndex(index, index+pSystem->getTotalParticles()); } - // increase totalParticles here for new particles, update method of particlesystem will fill the quads + // increase totalParticles here for new particles, update method of particle-system will fill the quads m_pTextureAtlas->increaseTotalQuadsWith(pSystem->getTotalParticles()); updateAllAtlasIndexes(); diff --git a/cocos2dx/particle_nodes/CCParticleExamples.cpp b/cocos2dx/particle_nodes/CCParticleExamples.cpp index 2aa2cc3379..b931458302 100644 --- a/cocos2dx/particle_nodes/CCParticleExamples.cpp +++ b/cocos2dx/particle_nodes/CCParticleExamples.cpp @@ -263,7 +263,7 @@ bool CCParticleGalaxy::initWithTotalParticles(unsigned int numberOfParticles) modeA.radialAccel = -80; modeA.radialAccelVar = 0; - // Gravity Mode: tagential + // Gravity Mode: tangential modeA.tangentialAccel = 80; modeA.tangentialAccelVar = 0; @@ -337,7 +337,7 @@ bool CCParticleFlower::initWithTotalParticles(unsigned int numberOfParticles) modeA.radialAccel = -60; modeA.radialAccelVar = 0; - // Gravity Mode: tagential + // Gravity Mode: tangential modeA.tangentialAccel = 15; modeA.tangentialAccelVar = 0; @@ -410,7 +410,7 @@ bool CCParticleMeteor::initWithTotalParticles(unsigned int numberOfParticles) modeA.radialAccel = 0; modeA.radialAccelVar = 0; - // Gravity Mode: tagential + // Gravity Mode: tangential modeA.tangentialAccel = 0; modeA.tangentialAccelVar = 0; @@ -484,7 +484,7 @@ bool CCParticleSpiral::initWithTotalParticles(unsigned int numberOfParticles) modeA.radialAccel = -380; modeA.radialAccelVar = 0; - // Gravity Mode: tagential + // Gravity Mode: tangential modeA.tangentialAccel = 45; modeA.tangentialAccelVar = 0; @@ -557,7 +557,7 @@ bool CCParticleExplosion::initWithTotalParticles(unsigned int numberOfParticles) modeA.radialAccel = 0; modeA.radialAccelVar = 0; - // Gravity Mode: tagential + // Gravity Mode: tangential modeA.tangentialAccel = 0; modeA.tangentialAccelVar = 0; @@ -700,7 +700,7 @@ bool CCParticleSnow::initWithTotalParticles(unsigned int numberOfParticles) modeA.radialAccel = 0; modeA.radialAccelVar = 1; - // Gravity mode: tagential + // Gravity mode: tangential modeA.tangentialAccel = 0; modeA.tangentialAccelVar = 1; @@ -768,7 +768,7 @@ bool CCParticleRain::initWithTotalParticles(unsigned int numberOfParticles) modeA.radialAccel = 0; modeA.radialAccelVar = 1; - // Gravity Mode: tagential + // Gravity Mode: tangential modeA.tangentialAccel = 0; modeA.tangentialAccelVar = 1; diff --git a/cocos2dx/particle_nodes/CCParticleSystem.cpp b/cocos2dx/particle_nodes/CCParticleSystem.cpp index 4c79cc21af..ec9f5e0ea6 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystem.cpp @@ -37,7 +37,7 @@ THE SOFTWARE. // http://particledesigner.71squared.com/ // // IMPORTANT: Particle Designer is supported by cocos2d, but -// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d, +// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d, // cocos2d uses a another approach, but the results are almost identical. // @@ -73,7 +73,7 @@ NS_CC_BEGIN // http://particledesigner.71squared.com/ // // IMPORTANT: Particle Designer is supported by cocos2d, but -// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d, +// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d, // cocos2d uses a another approach, but the results are almost identical. // @@ -392,12 +392,12 @@ bool CCParticleSystem::initWithTotalParticles(unsigned int numberOfParticles) m_bIsAutoRemoveOnFinish = false; - // Optimization: compile udpateParticle method + // Optimization: compile updateParticle method //updateParticleSel = @selector(updateQuadWithParticle:newPosition:); //updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel]; //for batchNode m_bTransformSystemDirty = false; - // udpate after action in run! + // update after action in run! this->scheduleUpdateWithPriority(1); return true; @@ -734,12 +734,12 @@ void CCParticleSystem::updateQuadWithParticle(tCCParticle* particle, const CCPoi { CC_UNUSED_PARAM(particle); CC_UNUSED_PARAM(newPosition); - // should be overriden + // should be overridden } void CCParticleSystem::postStep() { - // should be overriden + // should be overridden } // ParticleSystem - CCTexture protocol diff --git a/cocos2dx/particle_nodes/CCParticleSystem.h b/cocos2dx/particle_nodes/CCParticleSystem.h index ca855f5209..e6f7688ba4 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.h +++ b/cocos2dx/particle_nodes/CCParticleSystem.h @@ -131,7 +131,7 @@ class CCTexture2D; /** @brief Particle System base class. Attributes of a Particle System: -- emmision rate of the particles +- emission rate of the particles - Gravity Mode (Mode A): - gravity - direction @@ -155,7 +155,7 @@ Attributes of a Particle System: - texture cocos2d also supports particles generated by Particle Designer (http://particledesigner.71squared.com/). -'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d, +'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d, cocos2d uses a another approach, but the results are almost identical. cocos2d supports all the variables used by Particle Designer plus a bit more: @@ -208,7 +208,7 @@ protected: float endRadius; /** The ending radius variance of the particles. Only available in 'Radius' mode. */ float endRadiusVar; - /** Number of degress to rotate a particle around the source pos per second. Only available in 'Radius' mode. */ + /** Number of degrees to rotate a particle around the source pos per second. Only available in 'Radius' mode. */ float rotatePerSecond; /** Variance in degrees for rotatePerSecond. Only available in 'Radius' mode. */ float rotatePerSecondVar; @@ -245,7 +245,7 @@ protected: bool m_bIsActive; /** Quantity of particles that are being simulated at the moment */ CC_PROPERTY_READONLY(unsigned int, m_uParticleCount, ParticleCount) - /** How many seconds the emitter wil run. -1 means 'forever' */ + /** How many seconds the emitter will run. -1 means 'forever' */ CC_PROPERTY(float, m_fDuration, Duration) /** sourcePosition of the emitter */ CC_PROPERTY_PASS_BY_REF(CCPoint, m_tSourcePosition, SourcePosition) @@ -368,7 +368,7 @@ public: CCParticleSystem(); virtual ~CCParticleSystem(); /** creates an initializes a CCParticleSystem from a plist file. - This plist files can be creted manually or with Particle Designer: + This plist files can be created manually or with Particle Designer: http://particledesigner.71squared.com/ @deprecated: This interface will be deprecated sooner or later. @since v0.99.3 @@ -376,7 +376,7 @@ public: CC_DEPRECATED_ATTRIBUTE static CCParticleSystem * particleWithFile(const char *plistFile); /** creates an initializes a CCParticleSystem from a plist file. - This plist files can be creted manually or with Particle Designer: + This plist files can be created manually or with Particle Designer: http://particledesigner.71squared.com/ @since v2.0 */ @@ -388,7 +388,7 @@ public: /** initializes a CCParticleSystem*/ bool init(); /** initializes a CCParticleSystem from a plist file. - This plist files can be creted manually or with Particle Designer: + This plist files can be created manually or with Particle Designer: http://particledesigner.71squared.com/ @since v0.99.3 */ @@ -412,9 +412,9 @@ public: //! whether or not the system is full bool isFull(); - //! should be overriden by subclasses + //! should be overridden by subclasses virtual void updateQuadWithParticle(tCCParticle* particle, const CCPoint& newPosition); - //! should be overriden by subclasses + //! should be overridden by subclasses virtual void postStep(); virtual void update(float dt); diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp index ebd01eb50f..35fe1f0e02 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp @@ -381,7 +381,7 @@ void CCParticleSystemQuad::draw() void CCParticleSystemQuad::setTotalParticles(unsigned int tp) { - // If we are setting the total numer of particles to a number higher + // If we are setting the total number of particles to a number higher // than what is allocated, we need to allocate new arrays if( tp > m_uAllocatedParticles ) { diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.h b/cocos2dx/particle_nodes/CCParticleSystemQuad.h index fc1e674ecb..10822f4a24 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.h +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.h @@ -67,20 +67,20 @@ public: virtual ~CCParticleSystemQuad(); /** creates an initializes a CCParticleSystemQuad from a plist file. - This plist files can be creted manually or with Particle Designer: + This plist files can be created manually or with Particle Designer: @deprecated: This interface will be deprecated sooner or later. */ CC_DEPRECATED_ATTRIBUTE static CCParticleSystemQuad * particleWithFile(const char *plistFile); /** creates an initializes a CCParticleSystemQuad from a plist file. - This plist files can be creted manually or with Particle Designer: + This plist files can be created manually or with Particle Designer: */ static CCParticleSystemQuad * create(const char *plistFile); - /** initialices the indices for the vertices*/ + /** initializes the indices for the vertices*/ void setupIndices(); - /** initilizes the texture with a rectangle measured Points */ + /** initializes the texture with a rectangle measured Points */ void initTexCoordsWithRect(const CCRect& rect); /** Sets a new CCSpriteFrame as particle. diff --git a/cocos2dx/platform/CCApplicationProtocol.h b/cocos2dx/platform/CCApplicationProtocol.h index 76cadc8e05..6af58621a7 100644 --- a/cocos2dx/platform/CCApplicationProtocol.h +++ b/cocos2dx/platform/CCApplicationProtocol.h @@ -46,7 +46,7 @@ public: /** @brief Callback by CCDirector for limit FPS. - @interval The time, which expressed in second in second, between current frame and next. + @interval The time, expressed in seconds, between current frame and next. */ virtual void setAnimationInterval(double interval) = 0; diff --git a/cocos2dx/platform/CCCommon.h b/cocos2dx/platform/CCCommon.h index b4ac93581f..93a963a32f 100644 --- a/cocos2dx/platform/CCCommon.h +++ b/cocos2dx/platform/CCCommon.h @@ -47,14 +47,13 @@ void CC_DLL CCLog(const char * pszFormat, ...); */ void CC_DLL CCLuaLog(const char * pszFormat); - /** @brief Pop out a message box */ void CC_DLL CCMessageBox(const char * pszMsg, const char * pszTitle); /** -@brief Enum the language type supportted now +@brief Enum the language type supported now */ typedef enum LanguageType { diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index cd6ea0fbe7..a4e6080377 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -91,7 +91,7 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol //setViewPortInPoints(0, 0,m_obScreenSize.width, m_obScreenSize.height); - // reset director's member vaviables to fit visible rect + // reset director's member variables to fit visible rect CCDirector::sharedDirector()->createStatsLabel(); CCDirector::sharedDirector()->m_obWinSizeInPoints = CCDirector::sharedDirector()->m_obWinSizeInPixels = getSize(); CCDirector::sharedDirector()->setGLDefaultValues(); diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index f0db5bf7f5..aa03d423a6 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -36,7 +36,7 @@ public: CCEGLViewProtocol(); virtual ~CCEGLViewProtocol(); - /** Force destorying EGL view, subclass must implement this method. */ + /** Force destroying EGL view, subclass must implement this method. */ virtual void end() = 0; /** Get whether opengl render system is ready, subclass must implement this method. */ @@ -77,14 +77,14 @@ public: virtual CCPoint getVisibleOrigin() const; /** - * Set the design resolutin size. - * You can't use it with enableRetina together. + * Set the design resolution size. + * Behavior undefined when enableRetina == true. * @param width Design resolution width. * @param height Design resolution height. - * @param resolutionPolicy The resolution policy you need, there are: - * [1] kCCResolutionExactFit Fill screen, if the design resolution ratio of width and height is different from the screen resolution ratio, your game view will be stretched. - * [2] kCCResolutionNoBorder Full screen without black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two areas of your game view will be cut. - * [3] kCCResolutionShowAll Full screen with black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two black border will be shown on the screen; + * @param resolutionPolicy The resolution policy desired, you may choose: + * [1] kCCResolutionExactFit Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched. + * [2] kCCResolutionNoBorder Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut. + * [3] kCCResolutionShowAll Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown. */ virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy); @@ -93,7 +93,7 @@ public: /** * Set content scale factor. - * @return If return true, it means the plaform supports retina display. + * @return If the return value is true, the platform supports retina display mode. */ virtual bool setContentScaleFactor(float contentScaleFactor); @@ -113,30 +113,29 @@ public: */ virtual bool enableRetina(); - /** handle touch events by default, if you want to custom your handles, please override these functions */ + /** Touch events are handled by default; if you want to customize your handlers, please override these functions: */ virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]); /** - * Get opengl view port rectangle. + * Get the opengl view port rectangle. */ const CCRect& getViewPortRect() const; /** - * Get the scale factor of horizontal direction. - * + * Get scale factor of the horizontal direction. */ float getScaleX() const; /** - * Get the scale factor of vertical direction. + * Get scale factor of the vertical direction. */ float getScaleY() const; /** - * Get whether the retina mode is enabled. + * Get retina mode status (on if true). */ bool isRetinaEnabled() const; private: @@ -145,9 +144,9 @@ private: protected: EGLTouchDelegate* m_pDelegate; - // real size of screen + // real screen size CCSize m_obScreenSize; - // resolution size, it is the size the app resources designed for + // resolution size, it is the size appropriate for the app resources. CCSize m_obDesignResolutionSize; // the view port size CCRect m_obViewPortRect; diff --git a/cocos2dx/platform/CCFileUtils.h b/cocos2dx/platform/CCFileUtils.h index 100bb1db46..9a310d0f53 100644 --- a/cocos2dx/platform/CCFileUtils.h +++ b/cocos2dx/platform/CCFileUtils.h @@ -45,20 +45,20 @@ public: void purgeCachedEntries(); /** @brief Get resource file data - @param[in] pszFileName The resource file name which contain the path - @param[in] pszMode The read mode of the file - @param[out] pSize If get the file data succeed the it will be the data size,or it will be 0 - @return if success,the pointer of data will be returned,or NULL is returned - @warning If you get the file data succeed,you must delete[] it after used. + @param[in] pszFileName The resource file name which contains the path. + @param[in] pszMode The read mode of the file. + @param[out] pSize If the file read operation succeeds, it will be the data size, otherwise 0. + @return Upon success, a pointer to the data is returned, otherwise NULL. + @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned. */ unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize); /** - @brief Get resource file data from zip file - @param[in] pszFileName The resource file name which contain the relative path of zip file - @param[out] pSize If get the file data succeed the it will be the data size,or it will be 0 - @return if success,the pointer of data will be returned,or NULL is returned - @warning If you get the file data succeed,you must delete[] it after used. + @brief Get resource file data from a zip file. + @param[in] pszFileName The resource file name which contains the relative path of the zip file. + @param[out] pSize If the file read operation succeeds, it will be the data size, otherwise 0. + @return Upon success, a pointer to the data is returned, otherwise NULL. + @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned. */ unsigned char* getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize); @@ -67,8 +67,8 @@ public: @param pszRelativePath The relative path of the file. @return The absolute path of the file. @warning We only add the ResourcePath before the relative path of the file. - If you have not set the ResourcePath,the function add "/NEWPLUS/TDA_DATA/UserData/" as default. - You can set ResourcePath by function void setResourcePath(const char *pszResourcePath); + If you have not set the ResourcePath, the function appends "/NEWPLUS/TDA_DATA/UserData/" by default. + You can set ResourcePath with void setResourcePath(const char *pszResourcePath); */ const char* fullPathFromRelativePath(const char *pszRelativePath); @@ -77,8 +77,8 @@ public: /// @endcond /** - @brief Set the resource directory,we will find resource relative to this directory - @param pszDirectoryName Relative path to root + @brief Set the resource directory; we will find resources relative to this directory. + @param pszDirectoryName Relative path to root. */ void setResourceDirectory(const char *pszDirectoryName); @@ -100,6 +100,10 @@ public: bool isPopupNotify(); protected: + CCFileUtils(void) + { + } + std::string m_obDirectory; }; diff --git a/cocos2dx/platform/CCFileUtilsCommon_cpp.h b/cocos2dx/platform/CCFileUtilsCommon_cpp.h index 63efba2b5e..7e575eabf6 100644 --- a/cocos2dx/platform/CCFileUtilsCommon_cpp.h +++ b/cocos2dx/platform/CCFileUtilsCommon_cpp.h @@ -199,7 +199,7 @@ public: } else if (preState == SAX_ARRAY) { - CCAssert(! m_tArrayStack.empty(), "The state is worng!"); + CCAssert(! m_tArrayStack.empty(), "The state is wrong!"); CCArray* pPreArray = m_tArrayStack.top(); pPreArray->addObject(m_pArray); } @@ -305,7 +305,7 @@ public: { if (curState == SAX_DICT) { - CCAssert(!m_sCurKey.empty(), "not found key : "); + CCAssert(!m_sCurKey.empty(), "key not found : "); } m_sCurValue.append(pText->getCString()); diff --git a/cocos2dx/platform/CCImage.h b/cocos2dx/platform/CCImage.h index bdabd97f66..3deb5bd37e 100644 --- a/cocos2dx/platform/CCImage.h +++ b/cocos2dx/platform/CCImage.h @@ -64,29 +64,29 @@ public: /** @brief Load the image from the specified path. - @param strPath the absolute file path - @param imageType the type of image, now only support tow types. - @return true if load correctly + @param strPath the absolute file path. + @param imageType the type of image, currently only supporting two types. + @return true if loaded correctly. */ bool initWithImageFile(const char * strPath, EImageFormat imageType = kFmtPng); /* - @brief The same meaning as initWithImageFile, but it is thread safe. It is casued by + @brief The same result as with initWithImageFile, but thread safe. It is caused by loadImage() in CCTextureCache.cpp. - @param fullpath full path of the file - @param imageType the type of image, now only support tow types. - @return true if load correctly + @param fullpath full path of the file. + @param imageType the type of image, currently only supporting two types. + @return true if loaded correctly. */ bool initWithImageFileThreadSafe(const char *fullpath, EImageFormat imageType = kFmtPng); /** @brief Load image from stream buffer. - @warning kFmtRawData only support RGBA8888 - @param pBuffer stream buffer that hold the image data - @param nLength the length of data(managed in byte) - @param nWidth, nHeight, nBitsPerComponent are used for kFmtRawData - @return true if load correctly + @warning kFmtRawData only supports RGBA8888. + @param pBuffer stream buffer which holds the image data. + @param nLength data length expressed in (number of) bytes. + @param nWidth, nHeight, nBitsPerComponent are used for kFmtRawData. + @return true if loaded correctly. */ bool initWithImageData(void * pData, int nDataLen, @@ -97,11 +97,11 @@ public: /** @brief Create image with specified string. - @param pText the text which the image show, nil cause init fail - @param nWidth the image width, if 0, the width match the text's width - @param nHeight the image height, if 0, the height match the text's height + @param pText the text the image will show (cannot be nil). + @param nWidth the image width, if 0, the width will match the text's width. + @param nHeight the image height, if 0, the height will match the text's height. @param eAlignMask the test Alignment - @param pFontName the name of the font which use to draw the text. If nil, use the default system font. + @param pFontName the name of the font used to draw the text. If nil, use the default system font. @param nSize the font size, if 0, use the system default size. */ bool initWithString( @@ -119,9 +119,9 @@ public: bool isPremultipliedAlpha() { return m_bPreMulti; } /** - @brief Save the CCImage data to specified file with specified format. - @param pszFilePath the file's absolute path, including file subfix - @param bIsToRGB if the image is saved as RGB format + @brief Save CCImage data to the specified file, with specified format. + @param pszFilePath the file's absolute path, including file suffix. + @param bIsToRGB whether the image is saved as RGB format. */ bool saveToFile(const char *pszFilePath, bool bIsToRGB = true); diff --git a/cocos2dx/platform/CCImageCommon_cpp.h b/cocos2dx/platform/CCImageCommon_cpp.h index f060ce9f9a..5b0a60e93d 100644 --- a/cocos2dx/platform/CCImageCommon_cpp.h +++ b/cocos2dx/platform/CCImageCommon_cpp.h @@ -40,7 +40,7 @@ NS_CC_BEGIN // premultiply alpha, or the effect will wrong when want to use other pixel format in CCTexture2D, // such as RGB888, RGB5A1 -#define CC_RGB_PREMULTIPLY_APLHA(vr, vg, vb, va) \ +#define CC_RGB_PREMULTIPLY_ALPHA(vr, vg, vb, va) \ (unsigned)(((unsigned)((unsigned char)(vr) * ((unsigned char)(va) + 1)) >> 8) | \ ((unsigned)((unsigned char)(vg) * ((unsigned char)(va) + 1) >> 8) << 8) | \ ((unsigned)((unsigned char)(vb) * ((unsigned char)(va) + 1) >> 8) << 16) | \ @@ -71,7 +71,7 @@ static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t leng } ////////////////////////////////////////////////////////////////////////// -// Impliment CCImage +// Implement CCImage ////////////////////////////////////////////////////////////////////////// CCImage::CCImage() @@ -325,7 +325,7 @@ bool CCImage::_initWithPngData(void * pData, int nDatalen) { png_set_palette_to_rgb(png_ptr); } - // low-bit-depth grayscale iamges are to be expanded to 8 bits + // low-bit-depth grayscale images are to be expanded to 8 bits if (color_type == PNG_COLOR_TYPE_GRAY && m_nBitsPerComponent < 8) { png_set_expand_gray_1_2_4_to_8(png_ptr); @@ -376,7 +376,7 @@ bool CCImage::_initWithPngData(void * pData, int nDatalen) { for(unsigned int j = 0; j < rowbytes; j += 4) { - *tmp++ = CC_RGB_PREMULTIPLY_APLHA( row_pointers[i][j], row_pointers[i][j + 1], + *tmp++ = CC_RGB_PREMULTIPLY_ALPHA( row_pointers[i][j], row_pointers[i][j + 1], row_pointers[i][j + 2], row_pointers[i][j + 3] ); } } @@ -553,7 +553,7 @@ bool CCImage::_initWithTiffData(void* pData, int nDataLen) after invoking TIFFReadRGBAImageOriented for(int j = 0; j < m_nWidth * m_nHeight * 4; j += 4) { - *tmp++ = CC_RGB_PREMULTIPLY_APLHA( src[j], src[j + 1], + *tmp++ = CC_RGB_PREMULTIPLY_ALPHA( src[j], src[j + 1], src[j + 2], src[j + 3] ); } */ @@ -585,7 +585,7 @@ bool CCImage::_initWithRawData(void * pData, int nDatalen, int nWidth, int nHeig m_nWidth = (short)nWidth; m_bHasAlpha = true; - // only RGBA8888 surported + // only RGBA8888 supported int nBytesPerComponent = 4; int nSize = nHeight * nWidth * nBytesPerComponent; m_pData = new unsigned char[nSize]; diff --git a/cocos2dx/platform/CCPlatformConfig.h b/cocos2dx/platform/CCPlatformConfig.h index f1f3aaeaa6..43b61e2a3a 100644 --- a/cocos2dx/platform/CCPlatformConfig.h +++ b/cocos2dx/platform/CCPlatformConfig.h @@ -26,10 +26,7 @@ THE SOFTWARE. #define __CC_PLATFORM_CONFIG_H__ /** -Config of cocos2d-x project. - -There are config below: -build for which target platform +Config of cocos2d-x project, per target platform. */ ////////////////////////////////////////////////////////////////////////// @@ -47,7 +44,7 @@ build for which target platform #define CC_PLATFORM_BLACKBERRY 7 #define CC_PLATFORM_MAC 8 -// Determine tartet platform by compile environment macro. +// Determine target platform by compile environment macro. #define CC_TARGET_PLATFORM CC_PLATFORM_UNKNOWN // iphone @@ -106,10 +103,9 @@ build for which target platform // check user set platform #if ! CC_TARGET_PLATFORM - #error "Can not recognize the target platform, compling under a unsupported platform?" + #error "Cannot recognize the target platform; are you targeting an unsupported platform?" #endif -// Check the supportive of platform #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #pragma warning (disable:4127) #endif // CC_PLATFORM_WIN32 diff --git a/cocos2dx/platform/CCSAXParser.cpp b/cocos2dx/platform/CCSAXParser.cpp index cf0897a026..2dc1c8fd41 100644 --- a/cocos2dx/platform/CCSAXParser.cpp +++ b/cocos2dx/platform/CCSAXParser.cpp @@ -49,7 +49,7 @@ bool CCSAXParser::init(const char *pszEncoding) bool CCSAXParser::parse(const char* pXMLData, unsigned int uDataLength) { /* - * this initialize the library and check potential ABI mismatches + * this initializes the library and checks potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ diff --git a/cocos2dx/platform/CCThread.cpp b/cocos2dx/platform/CCThread.cpp index 7271c76ec3..b5342aa7e5 100644 --- a/cocos2dx/platform/CCThread.cpp +++ b/cocos2dx/platform/CCThread.cpp @@ -24,8 +24,8 @@ THE SOFTWARE. #include "CCThread.h" -// iOS already has a CCThread.mm -#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) +// iOS and Mac already has a CCThread.mm +#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_MAC) NS_CC_BEGIN diff --git a/cocos2dx/platform/android/CCApplication.h b/cocos2dx/platform/android/CCApplication.h index 8e42f45b9b..7fead7cdd0 100644 --- a/cocos2dx/platform/android/CCApplication.h +++ b/cocos2dx/platform/android/CCApplication.h @@ -15,8 +15,8 @@ public: virtual ~CCApplication(); /** - @brief Callback by CCDirector for limit FPS. - @interval The time, which expressed in second in second, between current frame and next. + @brief Callback by CCDirector to limit FPS. + @interval The time, expressed in seconds, between current frame and next. */ void setAnimationInterval(double interval); @@ -33,8 +33,8 @@ public: } Orientation; /** - @brief Callback by CCDirector for change device orientation. - @orientation The defination of orientation which CCDirector want change to. + @brief Callback by CCDirector to change device orientation. + @orientation The desired orientation. @return The actual orientation of the application. */ Orientation setOrientation(Orientation orientation); @@ -45,7 +45,7 @@ public: int run(); /** - @brief Get current applicaiton instance. + @brief Get current application instance. @return Current application instance pointer. */ static CCApplication* sharedApplication(); diff --git a/cocos2dx/platform/android/CCGL.h b/cocos2dx/platform/android/CCGL.h index b80308e0ad..aa690cd5cc 100644 --- a/cocos2dx/platform/android/CCGL.h +++ b/cocos2dx/platform/android/CCGL.h @@ -41,7 +41,7 @@ THE SOFTWARE. // normal process #include #include -// gl2.h don't define GLchar on Android +// gl2.h doesn't define GLchar on Android typedef char GLchar; //declare here while define in CCEGLView_android.cpp diff --git a/cocos2dx/platform/android/CCImage.cpp b/cocos2dx/platform/android/CCImage.cpp index 7c585947f7..8518543d2e 100644 --- a/cocos2dx/platform/android/CCImage.cpp +++ b/cocos2dx/platform/android/CCImage.cpp @@ -69,7 +69,7 @@ public: * this method call Cococs2dx.createBitmap()(java code) to create the bitmap, the java code * will call Java_org_cocos2dx_lib_Cocos2dxBitmap_nativeInitBitmapDC() to init the width, height * and data. - * use this appoach to decrease the jni call number + * use this approach to decrease the jni call number */ jstring jstrText = methodInfo.env->NewStringUTF(text); jstring jstrFont = methodInfo.env->NewStringUTF(pFontName); diff --git a/cocos2dx/platform/ios/CCApplication.h b/cocos2dx/platform/ios/CCApplication.h index 8b7e383c8f..74885cf795 100644 --- a/cocos2dx/platform/ios/CCApplication.h +++ b/cocos2dx/platform/ios/CCApplication.h @@ -44,14 +44,14 @@ public: int run(); /** - @brief Get current applicaiton instance. + @brief Get the current application instance. @return Current application instance pointer. */ static CCApplication* sharedApplication(); /** @brief Callback by CCDirector for limit FPS. - @interval The time, which expressed in second in second, between current frame and next. + @interval The time, expressed in seconds, between current frame and next. */ virtual void setAnimationInterval(double interval); diff --git a/cocos2dx/platform/ios/CCApplication.mm b/cocos2dx/platform/ios/CCApplication.mm index ff295f7ab5..9e2f2f4b6f 100644 --- a/cocos2dx/platform/ios/CCApplication.mm +++ b/cocos2dx/platform/ios/CCApplication.mm @@ -110,7 +110,7 @@ ccLanguageType CCApplication::getCurrentLanguage() TargetPlatform CCApplication::getTargetPlatform() { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // idiom for iOS <= 3.2, otherwise: [UIDevice userInterfaceIdiom] is faster. { return kTargetIpad; } diff --git a/cocos2dx/platform/ios/CCDirectorCaller.mm b/cocos2dx/platform/ios/CCDirectorCaller.mm index 0852f8fb0a..b39373449e 100644 --- a/cocos2dx/platform/ios/CCDirectorCaller.mm +++ b/cocos2dx/platform/ios/CCDirectorCaller.mm @@ -66,7 +66,7 @@ static id s_sharedDirectorCaller; -(void) startMainLoop { - // CCDirector::setAnimationInterval() is called, we should invalide it first + // CCDirector::setAnimationInterval() is called, we should invalidate it first [displayLink invalidate]; displayLink = nil; @@ -77,7 +77,7 @@ static id s_sharedDirectorCaller; -(void) setAnimationInterval:(double)intervalNew { - // CCDirector::setAnimationInterval() is called, we should invalide it first + // CCDirector::setAnimationInterval() is called, we should invalidate it first [displayLink invalidate]; displayLink = nil; diff --git a/cocos2dx/platform/ios/CCEGLView.mm b/cocos2dx/platform/ios/CCEGLView.mm index c672ad8ff4..68fb7d15cc 100644 --- a/cocos2dx/platform/ios/CCEGLView.mm +++ b/cocos2dx/platform/ios/CCEGLView.mm @@ -48,8 +48,7 @@ bool CCEGLView::isOpenGLReady() bool CCEGLView::setContentScaleFactor(float contentScaleFactor) { - // can not enable retina because have used resolution policy - assert(m_eResolutionPolicy == kResolutionUnKnown); + assert(m_eResolutionPolicy == kResolutionUnKnown); // cannot enable retina mode if ([[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)]) { diff --git a/cocos2dx/platform/ios/CCFileUtils.mm b/cocos2dx/platform/ios/CCFileUtils.mm index 68a9ad64fd..5f5c62ac2a 100644 --- a/cocos2dx/platform/ios/CCFileUtils.mm +++ b/cocos2dx/platform/ios/CCFileUtils.mm @@ -264,7 +264,7 @@ CCArray* ccFileUtils_arrayWithContentsOfFileThreadSafe(const char* pFileName) unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize) { unsigned char * pBuffer = NULL; - CCAssert(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invaild parameters."); + CCAssert(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invalid parameters."); *pSize = 0; do { diff --git a/cocos2dx/platform/ios/CCImage.mm b/cocos2dx/platform/ios/CCImage.mm index 34cfbc4940..fd80592627 100644 --- a/cocos2dx/platform/ios/CCImage.mm +++ b/cocos2dx/platform/ios/CCImage.mm @@ -437,7 +437,7 @@ bool CCImage::_initWithRawData(void *pData, int nDatalen, int nWidth, int nHeigh m_nWidth = (short)nWidth; m_bHasAlpha = true; - // only RGBA8888 surported + // only RGBA8888 supported int nBytesPerComponent = 4; int nSize = nHeight * nWidth * nBytesPerComponent; m_pData = new unsigned char[nSize]; diff --git a/cocos2dx/platform/ios/EAGLView.mm b/cocos2dx/platform/ios/EAGLView.mm index 04b27fa72e..2f9ba0a360 100755 --- a/cocos2dx/platform/ios/EAGLView.mm +++ b/cocos2dx/platform/ios/EAGLView.mm @@ -577,7 +577,7 @@ static EAGLView *view = 0; /* If text can be selected, it can be marked. Marked text represents provisionally * inserted text that has yet to be confirmed by the user. It requires unique visual * treatment in its display. If there is any marked text, the selection, whether a - * caret or an extended range, always resides witihin. + * caret or an extended range, always resides within. * * Setting marked text either replaces the existing marked text or, if none is present, * inserts it from the current selection. */ diff --git a/cocos2dx/platform/ios/FontLabel/ZAttributedString.m b/cocos2dx/platform/ios/FontLabel/ZAttributedString.m index 20db287c55..485695f078 100644 --- a/cocos2dx/platform/ios/FontLabel/ZAttributedString.m +++ b/cocos2dx/platform/ios/FontLabel/ZAttributedString.m @@ -113,7 +113,7 @@ - (ZAttributedString *)attributedSubstringFromRange:(NSRange)aRange { if (NSMaxRange(aRange) > [_buffer length]) { - @throw [NSException exceptionWithName:NSRangeException reason:@"range was outisde of the attributed string" userInfo:nil]; + @throw [NSException exceptionWithName:NSRangeException reason:@"range was outside of the attributed string" userInfo:nil]; } ZMutableAttributedString *newStr = [self mutableCopy]; if (aRange.location > 0) { diff --git a/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.h b/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.h index 47297c39a1..6a96cfe944 100644 --- a/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.h +++ b/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.h @@ -24,7 +24,7 @@ @end -// override UIAccelerometer behaviour +// override UIAccelerometer behavior @interface UIAccelerometer (Simulation) + (UIAccelerometer *)sharedAccelerometer; @end diff --git a/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.m b/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.m index 2ff94fa02e..ce50529583 100644 --- a/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.m +++ b/cocos2dx/platform/ios/Simulation/AccelerometerSimulation.m @@ -167,7 +167,7 @@ static AccelerometerSimulation *sharedAccelerometer = NULL; accObject = [UIAccelerationSimulation alloc]; isExiting = false; - // couldn't get the CFSocket version to work with UDP and runloop, so used Berkely sockets and a thread instead + // couldn't get the CFSocket version to work with UDP and runloop, so used Berkeley sockets and a thread instead udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); struct sockaddr_in sin; diff --git a/cocos2dx/platform/linux/CCEGLView.cpp b/cocos2dx/platform/linux/CCEGLView.cpp index ac2d390203..c0ba1181bc 100644 --- a/cocos2dx/platform/linux/CCEGLView.cpp +++ b/cocos2dx/platform/linux/CCEGLView.cpp @@ -142,6 +142,11 @@ void mousePosEventHandle(int iPosX,int iPosY) { } } +int closeEventHandle() { + CCDirector::sharedDirector()->end(); + return GL_TRUE; +} + void CCEGLView::setFrameSize(float width, float height) { bool eResult = false; @@ -217,6 +222,8 @@ void CCEGLView::setFrameSize(float width, float height) //register the glfw mouse pos event glfwSetMousePosCallback(mousePosEventHandle); + glfwSetWindowCloseCallback(closeEventHandle); + //Inits extensions eResult = initExtensions(); diff --git a/cocos2dx/platform/mac/CCAccelerometer.h b/cocos2dx/platform/mac/CCAccelerometer.h index 0603a98a1e..23f063b3b8 100755 --- a/cocos2dx/platform/mac/CCAccelerometer.h +++ b/cocos2dx/platform/mac/CCAccelerometer.h @@ -27,7 +27,7 @@ THE SOFTWARE. #include "platform/CCAccelerometerDelegate.h" -namespace cocos2d { +NS_CC_BEGIN class CC_DLL CCAccelerometer { @@ -38,6 +38,6 @@ public: void setDelegate(CCAccelerometerDelegate* pDelegate) { CC_UNUSED_PARAM(pDelegate); } }; -}//namespace cocos2d +NS_CC_END #endif diff --git a/cocos2dx/platform/mac/CCApplication.h b/cocos2dx/platform/mac/CCApplication.h index 5d18795a67..8d48f56319 100755 --- a/cocos2dx/platform/mac/CCApplication.h +++ b/cocos2dx/platform/mac/CCApplication.h @@ -22,14 +22,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#pragma once #ifndef __CC_APPLICATION_MAC_H__ #define __CC_APPLICATION_MAC_H__ #include "platform/CCCommon.h" #include "platform/CCApplicationProtocol.h" +#include -NS_CC_BEGIN; +NS_CC_BEGIN class CC_DLL CCApplication : public CCApplicationProtocol { @@ -69,10 +69,23 @@ public: */ virtual TargetPlatform getTargetPlatform(); + /* set the Resource root path */ + void setResourceRootPath(const std::string& rootResDir); + + /* get the Resource root path */ + const std::string& getResourceRootPath(void); + + void setStartupScriptFilename(const std::string& startupScriptFile); + + const std::string& getStartupScriptFilename(void); + protected: static CCApplication * sm_pSharedApplication; + + std::string m_resourceRootPath; + std::string m_startupScriptFilename; }; -NS_CC_END; +NS_CC_END -#endif // end of __CC_APPLICATION_MAC_H__ +#endif // end of __CC_APPLICATION_MAC_H__; diff --git a/cocos2dx/platform/mac/CCApplication.mm b/cocos2dx/platform/mac/CCApplication.mm index 5ad820bc92..a8b8f650b0 100755 --- a/cocos2dx/platform/mac/CCApplication.mm +++ b/cocos2dx/platform/mac/CCApplication.mm @@ -23,26 +23,26 @@ ****************************************************************************/ #import "CCApplication.h" - #import +#include -#import "CCGeometry.h" +#include "CCGeometry.h" #include "CCDirector.h" #import "CCDirectorCaller.h" -NS_CC_BEGIN; +NS_CC_BEGIN CCApplication* CCApplication::sm_pSharedApplication = 0; CCApplication::CCApplication() { - CC_ASSERT(! sm_pSharedApplication); + CCAssert(! sm_pSharedApplication, "sm_pSharedApplication already exist"); sm_pSharedApplication = this; } CCApplication::~CCApplication() { - CC_ASSERT(this == sm_pSharedApplication); + CCAssert(this == sm_pSharedApplication, "sm_pSharedApplication != this"); sm_pSharedApplication = 0; } @@ -71,7 +71,7 @@ TargetPlatform CCApplication::getTargetPlatform() CCApplication* CCApplication::sharedApplication() { - CC_ASSERT(sm_pSharedApplication); + CCAssert(sm_pSharedApplication, "sm_pSharedApplication not set"); return sm_pSharedApplication; } @@ -99,4 +99,30 @@ ccLanguageType CCApplication::getCurrentLanguage() return ret; } -NS_CC_END; +void CCApplication::setResourceRootPath(const std::string& rootResDir) +{ + m_resourceRootPath = rootResDir; + std::replace(m_resourceRootPath.begin(), m_resourceRootPath.end(), '\\', '/'); + if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/') + { + m_resourceRootPath += '/'; + } +} + +const std::string& CCApplication::getResourceRootPath(void) +{ + return m_resourceRootPath; +} + +void CCApplication::setStartupScriptFilename(const std::string& startupScriptFile) +{ + m_startupScriptFilename = startupScriptFile; + std::replace(m_startupScriptFilename.begin(), m_startupScriptFilename.end(), '\\', '/'); +} + +const std::string& CCApplication::getStartupScriptFilename(void) +{ + return m_startupScriptFilename; +} + +NS_CC_END diff --git a/cocos2dx/platform/mac/CCCommon.mm b/cocos2dx/platform/mac/CCCommon.mm index dc232b6c66..1ab9962628 100755 --- a/cocos2dx/platform/mac/CCCommon.mm +++ b/cocos2dx/platform/mac/CCCommon.mm @@ -30,7 +30,7 @@ #import "EAGLView.h" -NS_CC_BEGIN; +NS_CC_BEGIN void CCLog(const char * pszFormat, ...) { @@ -45,6 +45,11 @@ void CCLog(const char * pszFormat, ...) printf("\n"); } +void CCLuaLog(const char * pszFormat) +{ + CCLog(pszFormat); +} + // ios no MessageBox, use CCLog instead void CCMessageBox(const char * pszMsg, const char * pszTitle) { @@ -64,4 +69,4 @@ void CCMessageBox(const char * pszMsg, const char * pszTitle) contextInfo:nil]; } -NS_CC_END; +NS_CC_END diff --git a/cocos2dx/platform/mac/CCDirectorCaller.h b/cocos2dx/platform/mac/CCDirectorCaller.h index f128d8e32a..4d80b6e8b5 100755 --- a/cocos2dx/platform/mac/CCDirectorCaller.h +++ b/cocos2dx/platform/mac/CCDirectorCaller.h @@ -31,8 +31,9 @@ } @property (readwrite) int interval; -(void) startMainLoop; +-(void) end; -(void) doCaller: (id) sender; -(void) setAnimationInterval:(double)interval; + +(id) sharedDirectorCaller; -+(void) destroy; @end diff --git a/cocos2dx/platform/mac/CCDirectorCaller.mm b/cocos2dx/platform/mac/CCDirectorCaller.mm index f3eacf9a66..b6586544ed 100755 --- a/cocos2dx/platform/mac/CCDirectorCaller.mm +++ b/cocos2dx/platform/mac/CCDirectorCaller.mm @@ -45,30 +45,24 @@ static id s_sharedDirectorCaller; { if (s_sharedDirectorCaller == nil) { - s_sharedDirectorCaller = [CCDirectorCaller new]; + s_sharedDirectorCaller = [[CCDirectorCaller alloc] init]; } return s_sharedDirectorCaller; } -+(void) destroy -{ - [s_sharedDirectorCaller release]; -} - -(void) alloc { - interval = 1; + interval = 1; } -(void) dealloc { + s_sharedDirectorCaller = nil; + NSLog(@"cocos2d: deallocing CCDirectorCaller %@", self); if (displayLink) { CVDisplayLinkRelease(displayLink); } - if (renderTimer) { - [renderTimer release]; - } [super dealloc]; } @@ -77,7 +71,7 @@ static id s_sharedDirectorCaller; #if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD //if( ! runningThread_ ) //runningThread_ = [NSThread currentThread]; - + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; cocos2d::CCDirector::sharedDirector()->drawScene(); @@ -99,84 +93,94 @@ static id s_sharedDirectorCaller; // This is the renderer output callback function static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext) { -// CVReturn result = [(CCDirectorCaller*)displayLinkContext getFrameForTime:outputTime]; -// return result; + // CVReturn result = [(CCDirectorCaller*)displayLinkContext getFrameForTime:outputTime]; + // return result; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; cocos2d::CCDirector::sharedDirector()->mainLoop(); [pool release]; - + return kCVReturnSuccess; } - (void)timerFired:(id)sender { // It is good practice in a Cocoa application to allow the system to send the -drawRect: - // message when it needs to draw, and not to invoke it directly from the timer. + // message when it needs to draw, and not to invoke it directly from the timer. // All we do here is tell the display it needs a refresh NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + // get the opengl view EAGLView *openGLView = [EAGLView sharedEGLView]; [openGLView lockOpenGLContext]; - + // run the main cocos2d loop cocos2d::CCDirector::sharedDirector()->mainLoop(); - + // flush buffer (this line is very important!) - [[openGLView openGLContext] flushBuffer]; + [[openGLView openGLContext] flushBuffer]; [openGLView unlockOpenGLContext]; - + // send any queued events [[CCEventDispatcher sharedDispatcher] dispatchQueuedEvents]; - + [pool release]; } -(void) startMainLoop { - // CCDirector::setAnimationInterval() is called, we should invalide it first -// [displayLink invalidate]; -// displayLink = nil; -// -// displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)]; -// [displayLink setFrameInterval: self.interval]; -// [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + // CCDirector::setAnimationInterval() is called, we should invalide it first + // [displayLink invalidate]; + // displayLink = nil; + // + // displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)]; + // [displayLink setFrameInterval: self.interval]; + // [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; #if ! CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD NSThread* thread = [[NSThread alloc] initWithTarget:self selector:@selector(mainLoop) object:nil]; - [thread start]; + [thread start]; #endif // NSTimer + [renderTimer invalidate]; + renderTimer = nil; + renderTimer = [NSTimer timerWithTimeInterval:self.interval/60.0f //a 1ms time interval - target:self - selector:@selector(timerFired:) - userInfo:nil - repeats:YES]; - - [[NSRunLoop currentRunLoop] addTimer:renderTimer - forMode:NSDefaultRunLoopMode]; - [[NSRunLoop currentRunLoop] addTimer:renderTimer - forMode:NSEventTrackingRunLoopMode]; //Ensure timer fires during resize - -/* - // CVDisplayLink - //cocos2d::CCDirector::sharedDirector()->gettimeofday(); - - // Create a display link capable of being used with all active displays - CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); - - // Set the renderer output callback function - CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, self); - - // Set the display link for the current renderer - EAGLView *openGLView_ = (EAGLView*)[EAGLView sharedEGLView]; - CGLContextObj cglContext = (CGLContextObj)[[openGLView_ openGLContext] CGLContextObj]; - CGLPixelFormatObj cglPixelFormat = (CGLPixelFormatObj)[[openGLView_ pixelFormat] CGLPixelFormatObj]; - CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat); - - // Activate the display link - CVDisplayLinkStart(displayLink); -*/ + target:self + selector:@selector(timerFired:) + userInfo:nil + repeats:YES]; + + [[NSRunLoop currentRunLoop] addTimer:renderTimer + forMode:NSDefaultRunLoopMode]; + [[NSRunLoop currentRunLoop] addTimer:renderTimer + forMode:NSEventTrackingRunLoopMode]; //Ensure timer fires during resize + + /* + // CVDisplayLink + //cocos2d::CCDirector::sharedDirector()->gettimeofday(); + + // Create a display link capable of being used with all active displays + CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); + + // Set the renderer output callback function + CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, self); + + // Set the display link for the current renderer + EAGLView *openGLView_ = (EAGLView*)[EAGLView sharedEGLView]; + CGLContextObj cglContext = (CGLContextObj)[[openGLView_ openGLContext] CGLContextObj]; + CGLPixelFormatObj cglPixelFormat = (CGLPixelFormatObj)[[openGLView_ pixelFormat] CGLPixelFormatObj]; + CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat); + + // Activate the display link + CVDisplayLinkStart(displayLink); + */ +} + +-(void) end +{ + [renderTimer invalidate]; + renderTimer = nil; + [self release]; } -(void) setAnimationInterval:(double)intervalNew @@ -195,7 +199,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime [[NSRunLoop currentRunLoop] addTimer:renderTimer forMode:NSEventTrackingRunLoopMode]; } - + -(void) doCaller: (id) sender { cocos2d::CCDirector::sharedDirector()->mainLoop(); diff --git a/cocos2dx/platform/mac/CCEGLView.h b/cocos2dx/platform/mac/CCEGLView.h index b1a37d6088..10ef42f59d 100755 --- a/cocos2dx/platform/mac/CCEGLView.h +++ b/cocos2dx/platform/mac/CCEGLView.h @@ -1,26 +1,26 @@ /**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ + Copyright (c) 2010 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef __CC_EGLVIEW_MAC_H__ #define __CC_EGLVIEW_MAC_H__ @@ -28,7 +28,8 @@ THE SOFTWARE. #include "platform/CCCommon.h" #include "platform/CCEGLViewProtocol.h" -namespace cocos2d { +NS_CC_BEGIN + class CCSet; class CCTouch; class CCSize; @@ -36,22 +37,24 @@ class CCSize; class CC_DLL CCEGLView : public CCEGLViewProtocol { public: - CCEGLView(); - virtual ~CCEGLView(); - - bool isOpenGLReady(); + static CCEGLView* sharedOpenGLView(void); + + virtual ~CCEGLView(void); + + virtual bool isOpenGLReady(void); virtual bool setContentScaleFactor(float contentScaleFactor); - void end(); - void swapBuffers(); - - void setIMEKeyboardState(bool bOpen); - - void setMultiTouchMask(bool mask); - - static CCEGLView* sharedOpenGLView(); - + virtual void end(); + virtual void swapBuffers(void); + + virtual void setIMEKeyboardState(bool bOpen); + virtual void setMultiTouchMask(bool mask); + +private: + static CCEGLView* s_sharedView; + + CCEGLView(void); }; -} // end of namespace cocos2d +NS_CC_END // end of namespace cocos2d #endif // end of __CC_EGLVIEW_MAC_H__ diff --git a/cocos2dx/platform/mac/CCEGLView.mm b/cocos2dx/platform/mac/CCEGLView.mm index 0d1b96129e..b641fbcd1a 100755 --- a/cocos2dx/platform/mac/CCEGLView.mm +++ b/cocos2dx/platform/mac/CCEGLView.mm @@ -1,26 +1,26 @@ /**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ + Copyright (c) 2010 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #include "CCEGLView.h" #include "EAGLView.h" #include "CCDirectorCaller.h" @@ -28,19 +28,32 @@ THE SOFTWARE. #include "CCTouch.h" #include "CCTouchDispatcher.h" -namespace cocos2d { +NS_CC_BEGIN -CCEGLView::CCEGLView() +CCEGLView* CCEGLView::s_sharedView = NULL; + +CCEGLView* CCEGLView::sharedOpenGLView(void) +{ + if (!s_sharedView) + { + s_sharedView = new CCEGLView(); + } + return s_sharedView; +} + +CCEGLView::CCEGLView(void) { m_obScreenSize.width = m_obDesignResolutionSize.width = [[EAGLView sharedEGLView] getWidth]; m_obScreenSize.height = m_obDesignResolutionSize.height = [[EAGLView sharedEGLView] getHeight]; } -CCEGLView::~CCEGLView() +CCEGLView::~CCEGLView(void) { + CCLOG("cocos2d: deallocing CCEGLView %0x", this); + s_sharedView = NULL; } -bool CCEGLView::isOpenGLReady() +bool CCEGLView::isOpenGLReady(void) { return [EAGLView sharedEGLView] != NULL; } @@ -50,14 +63,14 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor) return false; } -void CCEGLView::end() +void CCEGLView::end(void) { - [CCDirectorCaller destroy]; + [[CCDirectorCaller sharedDirectorCaller] end]; // destroy EAGLView [[EAGLView sharedEGLView] removeFromSuperview]; - - _exit(0); + + delete this; } void CCEGLView::swapBuffers() @@ -83,10 +96,4 @@ void CCEGLView::setMultiTouchMask(bool mask) //glView.multipleTouchEnabled = mask ? YES : NO; } -CCEGLView* CCEGLView::sharedOpenGLView() -{ - static CCEGLView instance; - return &instance; -} - -} // end of namespace cocos2d; +NS_CC_END // end of namespace cocos2d; diff --git a/cocos2dx/platform/mac/CCFileUtils.mm b/cocos2dx/platform/mac/CCFileUtils.mm index cf564fa3dd..248bfbb214 100755 --- a/cocos2dx/platform/mac/CCFileUtils.mm +++ b/cocos2dx/platform/mac/CCFileUtils.mm @@ -1,27 +1,27 @@ /**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org -Copyright (c) 2011 Zynga Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ + Copyright (c) 2010-2011 cocos2d-x.org + Copyright (c) 2011 Zynga Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #import #include @@ -44,7 +44,7 @@ USING_NS_CC; static void static_addValueToCCDict(id key, id value, CCDictionary* pDict); static void static_addItemToCCArray(id item, CCArray* pArray); -static NSFileManager *__localFileManager= [[NSFileManager alloc] init]; +static NSFileManager *__localFileManager= [NSFileManager defaultManager]; static void static_addItemToCCArray(id item, CCArray *pArray) { @@ -56,7 +56,7 @@ static void static_addItemToCCArray(id item, CCArray *pArray) pValue->release(); return; } - + // add number value into array(such as int, float, bool and so on) if ([item isKindOfClass:[NSNumber class]]) { NSString* pStr = [item stringValue]; @@ -97,7 +97,7 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict) // the key must be a string CCAssert([key isKindOfClass:[NSString class]], "The key should be a string!"); std::string pKey = [key UTF8String]; - + // the value is a new dictionary if ([value isKindOfClass:[NSDictionary class]]) { CCDictionary* pSubDict = new CCDictionary(); @@ -109,16 +109,16 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict) pSubDict->release(); return; } - + // the value is a string if ([value isKindOfClass:[NSString class]]) { CCString* pValue = new CCString([value UTF8String]); - + pDict->setObject(pValue, pKey.c_str()); pValue->release(); return; } - + // the value is a number if ([value isKindOfClass:[NSNumber class]]) { NSString* pStr = [value stringValue]; @@ -128,7 +128,7 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict) pValue->release(); return; } - + // the value is a array if ([value isKindOfClass:[NSArray class]]) { CCArray *pArray = new CCArray(); @@ -164,13 +164,13 @@ void CCFileUtils::purgeFileUtils() { s_pFileUtils->purgeCachedEntries(); } - + CC_SAFE_DELETE(s_pFileUtils); } void CCFileUtils::purgeCachedEntries() { - + } void CCFileUtils::setResourceDirectory(const char *pszDirectoryName) @@ -191,7 +191,6 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) // only if it is not an absolute path if( ! [relPath isAbsolutePath] ) { - // pathForResource also searches in .lproj directories. issue #1230 NSString *lastPathComponent = [relPath lastPathComponent]; @@ -199,16 +198,24 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) NSMutableString *imageDirectoryByAppendDirectory = [NSMutableString stringWithUTF8String:m_obDirectory.c_str()]; [imageDirectoryByAppendDirectory appendString:imageDirectory]; - // search path from directory set by setResourceDirectory - fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent - ofType:nil - inDirectory:imageDirectoryByAppendDirectory]; - if (fullpath == nil) + const std::string& resourceRootPath = CCApplication::sharedApplication()->getResourceRootPath(); + if (resourceRootPath.length() == 0) { - // search from root directory + // search path from directory set by setResourceDirectory fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent ofType:nil - inDirectory:imageDirectory]; + inDirectory:imageDirectoryByAppendDirectory]; + if (fullpath == nil) + { + // search from root directory + fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent + ofType:nil + inDirectory:imageDirectory]; + } + } + else + { + fullpath = [NSString stringWithFormat:@"%s%s%@", resourceRootPath.c_str(), m_obDirectory.c_str(), relPath]; } } @@ -257,7 +264,7 @@ CCArray* ccFileUtils_arrayWithContentsOfFileThreadSafe(const char* pFileName) for (id value in pArray) { static_addItemToCCArray(value, pRet); } - + return pRet; } @@ -266,12 +273,12 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz unsigned char * pBuffer = NULL; CCAssert(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invaild parameters."); *pSize = 0; - do + do { // read the file from hardware FILE *fp = fopen(pszFileName, pszMode); CC_BREAK_IF(!fp); - + fseek(fp,0,SEEK_END); *pSize = ftell(fp); fseek(fp,0,SEEK_SET); @@ -279,13 +286,13 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz *pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp); fclose(fp); } while (0); - - if (! pBuffer && isPopupNotify()) + + if (! pBuffer && isPopupNotify()) { std::string title = "Notification"; std::string msg = "Get data from file("; msg.append(pszFileName).append(") failed!"); - + CCMessageBox(msg.c_str(), title.c_str()); } return pBuffer; @@ -316,44 +323,44 @@ std::string CCFileUtils::getWriteablePath() unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize) { - unsigned char * pBuffer = NULL; - unzFile pFile = NULL; - *pSize = 0; + unsigned char * pBuffer = NULL; + unzFile pFile = NULL; + *pSize = 0; - do - { - CC_BREAK_IF(!pszZipFilePath || !pszFileName); - CC_BREAK_IF(strlen(pszZipFilePath) == 0); + do + { + CC_BREAK_IF(!pszZipFilePath || !pszFileName); + CC_BREAK_IF(strlen(pszZipFilePath) == 0); + + pFile = unzOpen(pszZipFilePath); + CC_BREAK_IF(!pFile); + + int nRet = unzLocateFile(pFile, pszFileName, 1); + CC_BREAK_IF(UNZ_OK != nRet); + + char szFilePathA[260]; + unz_file_info FileInfo; + nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0); + CC_BREAK_IF(UNZ_OK != nRet); + + nRet = unzOpenCurrentFile(pFile); + CC_BREAK_IF(UNZ_OK != nRet); + + pBuffer = new unsigned char[FileInfo.uncompressed_size]; + int nSize = 0; + nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size); + CCAssert(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong"); + + *pSize = FileInfo.uncompressed_size; + unzCloseCurrentFile(pFile); + } while (0); - pFile = unzOpen(pszZipFilePath); - CC_BREAK_IF(!pFile); + if (pFile) + { + unzClose(pFile); + } - int nRet = unzLocateFile(pFile, pszFileName, 1); - CC_BREAK_IF(UNZ_OK != nRet); - - char szFilePathA[260]; - unz_file_info FileInfo; - nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0); - CC_BREAK_IF(UNZ_OK != nRet); - - nRet = unzOpenCurrentFile(pFile); - CC_BREAK_IF(UNZ_OK != nRet); - - pBuffer = new unsigned char[FileInfo.uncompressed_size]; - int nSize = 0; - nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size); - CCAssert(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong"); - - *pSize = FileInfo.uncompressed_size; - unzCloseCurrentFile(pFile); - } while (0); - - if (pFile) - { - unzClose(pFile); - } - - return pBuffer; + return pBuffer; } NS_CC_END diff --git a/cocos2dx/platform/mac/CCImage.mm b/cocos2dx/platform/mac/CCImage.mm index 4043bd1f1a..ea2d8afe6e 100755 --- a/cocos2dx/platform/mac/CCImage.mm +++ b/cocos2dx/platform/mac/CCImage.mm @@ -340,8 +340,8 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl { bool bRet = false; - CCAssert( pText, @"Invalid pText"); - CCAssert( pInfo, @"Invalid pInfo"); + CCAssert(pText, "Invalid pText"); + CCAssert(pInfo, "Invalid pInfo"); do { NSString * string = [NSString stringWithUTF8String:pText]; @@ -480,7 +480,7 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl return bRet; } -NS_CC_BEGIN; +NS_CC_BEGIN static bool m_bEnabledScale = true; @@ -876,5 +876,5 @@ bool CCImage::saveToFile(const char *pszFilePath, bool bIsToRGB) -NS_CC_END; +NS_CC_END diff --git a/cocos2dx/platform/mac/CCPlatformDefine.h b/cocos2dx/platform/mac/CCPlatformDefine.h index 789ea77e08..67a7d0ea3d 100644 --- a/cocos2dx/platform/mac/CCPlatformDefine.h +++ b/cocos2dx/platform/mac/CCPlatformDefine.h @@ -5,8 +5,11 @@ #define CC_DLL +#if CC_DISABLE_ASSERT > 0 +#define CC_ASSERT(cond) +#else #define CC_ASSERT(cond) assert(cond) - +#endif #define CC_UNUSED_PARAM(unusedparam) (void)unusedparam diff --git a/cocos2dx/platform/mac/EAGLView.mm b/cocos2dx/platform/mac/EAGLView.mm index fca62ada93..98bb6367e1 100755 --- a/cocos2dx/platform/mac/EAGLView.mm +++ b/cocos2dx/platform/mac/EAGLView.mm @@ -158,8 +158,7 @@ static EAGLView *view; - (void) dealloc { - CCLOGINFO(@"cocos2d: deallocing %@", self); - + CCLOGINFO(@"cocos2d: deallocing EAGLView %@", self); [super dealloc]; } diff --git a/cocos2dx/platform/win32/CCApplication.cpp b/cocos2dx/platform/win32/CCApplication.cpp index d77a93a85b..0507355813 100644 --- a/cocos2dx/platform/win32/CCApplication.cpp +++ b/cocos2dx/platform/win32/CCApplication.cpp @@ -1,6 +1,7 @@ #include "CCApplication.h" #include "CCEGLView.h" #include "CCDirector.h" +#include /** @brief This function change the PVRFrame show/hide setting in register. @@ -142,6 +143,22 @@ TargetPlatform CCApplication::getTargetPlatform() return kTargetWindows; } +void CCApplication::setResourceRootPath(const std::string& rootResDir) +{ + m_resourceRootPath = rootResDir; + std::replace(m_resourceRootPath.begin(), m_resourceRootPath.end(), '\\', '/'); + if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/') + { + m_resourceRootPath += '/'; + } +} + +void CCApplication::setStartupScriptFilename(const std::string& startupScriptFile) +{ + m_startupScriptFilename = startupScriptFile; + std::replace(m_startupScriptFilename.begin(), m_startupScriptFilename.end(), '\\', '/'); +} + NS_CC_END ////////////////////////////////////////////////////////////////////////// diff --git a/cocos2dx/platform/win32/CCApplication.h b/cocos2dx/platform/win32/CCApplication.h index 8e05740002..f10b7231e9 100644 --- a/cocos2dx/platform/win32/CCApplication.h +++ b/cocos2dx/platform/win32/CCApplication.h @@ -4,6 +4,7 @@ #include #include "platform/CCCommon.h" #include "platform/CCApplicationProtocol.h" +#include NS_CC_BEGIN @@ -35,10 +36,28 @@ public: */ virtual TargetPlatform getTargetPlatform(); + /* set the Resource root path */ + void setResourceRootPath(const std::string& rootResDir); + + /* get the Resource root path */ + const std::string& getResourceRootPath(void) + { + return m_resourceRootPath; + } + + void setStartupScriptFilename(const std::string& startupScriptFile); + + const std::string& getStartupScriptFilename(void) + { + return m_startupScriptFilename; + } + protected: HINSTANCE m_hInstance; HACCEL m_hAccelTable; LARGE_INTEGER m_nAnimationInterval; + std::string m_resourceRootPath; + std::string m_startupScriptFilename; static CCApplication * sm_pSharedApplication; }; diff --git a/cocos2dx/platform/win32/CCCommon.cpp b/cocos2dx/platform/win32/CCCommon.cpp index ba7526d26f..6beb9b83c8 100644 --- a/cocos2dx/platform/win32/CCCommon.cpp +++ b/cocos2dx/platform/win32/CCCommon.cpp @@ -42,6 +42,9 @@ void CCLog(const char * pszFormat, ...) MultiByteToWideChar(CP_UTF8, 0, szBuf, -1, wszBuf, sizeof(wszBuf)); OutputDebugStringW(wszBuf); OutputDebugStringA("\n"); + + WideCharToMultiByte(CP_ACP, 0, wszBuf, sizeof(wszBuf), szBuf, sizeof(szBuf), NULL, FALSE); + printf("%s\n", szBuf); } void CCMessageBox(const char * pszMsg, const char * pszTitle) @@ -49,9 +52,18 @@ void CCMessageBox(const char * pszMsg, const char * pszTitle) MessageBoxA(NULL, pszMsg, pszTitle, MB_OK); } -void CCLuaLog(const char * pszFormat) +void CCLuaLog(const char *pszMsg) { - CCLog(pszFormat); + int bufflen = MultiByteToWideChar(CP_UTF8, 0, pszMsg, -1, NULL, 0); + ++bufflen; + WCHAR* buff = new WCHAR[bufflen]; + memset(buff, 0, sizeof(WCHAR) * bufflen); + MultiByteToWideChar(CP_UTF8, 0, pszMsg, -1, buff, bufflen - 1); + + OutputDebugStringW(buff); + OutputDebugStringA("\n"); + + puts(pszMsg); } NS_CC_END diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 9956524675..aead83fd60 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -89,6 +89,12 @@ CCEGLView::CCEGLView() , m_hDC(NULL) , m_hRC(NULL) , m_lpfnAccelerometerKeyHook(NULL) +, m_menu(NULL) +, m_wndproc(NULL) +, m_windowWidth(0) +, m_windowHeight(0) +, m_windowTouchScaleX(1.0f) +, m_windowTouchScaleY(1.0f) { strcpy(m_szViewName, "Cocos2dxWin32"); } @@ -106,6 +112,19 @@ bool CCEGLView::initGL() m_hRC = wglCreateContext(m_hDC); wglMakeCurrent(m_hDC, m_hRC); + // check OpenGL version at first + const GLubyte* glVersion = glGetString(GL_VERSION); + CCLOG("OpenGL version = %s", glVersion); + + if ( atof((const char*)glVersion) < 1.5 ) + { + char strComplain[256] = {0}; + sprintf(strComplain, + "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", + glVersion); + CCMessageBox(strComplain, "OpenGL version tooooooooooold"); + } + GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { @@ -115,20 +134,20 @@ bool CCEGLView::initGL() if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) { - CCLog("Ready for GLSL\n"); + CCLog("Ready for GLSL"); } else { - CCLog("Not totally ready :( \n"); + CCLog("Not totally ready :("); } if (glewIsSupported("GL_VERSION_2_0")) { - CCLog("Ready for OpenGL 2.0\n"); + CCLog("Ready for OpenGL 2.0"); } else { - CCLog("OpenGL 2.0 not supported\n"); + CCLog("OpenGL 2.0 not supported"); } return true; } @@ -162,7 +181,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL - wc.lpszMenuName = NULL; // We Don't Want A Menu + wc.lpszMenuName = m_menu; // wc.lpszClassName = kWindowClassName; // Set The Class Name CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); @@ -204,6 +223,8 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { + BOOL bProcessed = FALSE; + switch (message) { case WM_LBUTTONDOWN: @@ -217,6 +238,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) m_bCaptured = true; SetCapture(m_hWnd); int id = 0; + pt.x *= m_windowTouchScaleX; + pt.y *= m_windowTouchScaleY; handleTouchesBegin(1, &id, &pt.x, &pt.y); } } @@ -228,6 +251,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); int id = 0; + pt.x *= m_windowTouchScaleX; + pt.y *= m_windowTouchScaleY; handleTouchesMove(1, &id, &pt.x, &pt.y); } break; @@ -238,6 +263,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); int id = 0; + pt.x *= m_windowTouchScaleX; + pt.y *= m_windowTouchScaleY; handleTouchesEnd(1, &id, &pt.x, &pt.y); ReleaseCapture(); @@ -292,7 +319,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) else if (VK_ESCAPE == wParam) { // ESC input - CCDirector::sharedDirector()->end(); + //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) @@ -328,8 +355,19 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) break; default: + if (m_wndproc) + { + + m_wndproc(message, wParam, lParam, &bProcessed); + if (bProcessed) break; + } return DefWindowProc(m_hWnd, message, wParam, lParam); } + + if (m_wndproc && !bProcessed) + { + m_wndproc(message, wParam, lParam, &bProcessed); + } return 0; } @@ -376,6 +414,16 @@ bool CCEGLView::enableRetina() return true; } +void CCEGLView::setMenuResource(LPCWSTR menu) +{ + m_menu = menu; +} + +void CCEGLView::setWndProc(CUSTOM_WND_PROC proc) +{ + m_wndproc = proc; +} + HWND CCEGLView::getHWnd() { return m_hWnd; @@ -388,27 +436,48 @@ void CCEGLView::resize(int width, int height) return; } + RECT rcWindow; + GetWindowRect(m_hWnd, &rcWindow); + RECT rcClient; GetClientRect(m_hWnd, &rcClient); - if (rcClient.right - rcClient.left == width && - rcClient.bottom - rcClient.top == height) - { - return; - } + // calculate new window width and height + POINT ptDiff; + ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right; + ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom; rcClient.right = rcClient.left + width; rcClient.bottom = rcClient.top + height; + + m_windowWidth = width; + m_windowHeight = height; + const CCSize& frameSize = getFrameSize(); + if (frameSize.width > 0) + { + m_windowTouchScaleX = frameSize.width / width; + m_windowTouchScaleY = frameSize.height / height; + + TCHAR buff[MAX_PATH + 1]; + memset(buff, 0, sizeof(buff)); + swprintf_s(buff, MAX_PATH, L"%s - %0.0fx%0.0f - %0.2f", + kWindowClassName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX); + SetWindowText(m_hWnd, buff); + } + AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); // change width and height - SetWindowPos(m_hWnd, 0, 0, 0, rcClient.right - rcClient.left, - rcClient.bottom - rcClient.top, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); + SetWindowPos(m_hWnd, 0, 0, 0, width + ptDiff.x, height + ptDiff.y, + SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); } void CCEGLView::setFrameSize(float width, float height) { Create((LPCTSTR)m_szViewName, (int)width, (int)height); CCEGLViewProtocol::setFrameSize(width, height); + + resize(width, height); // adjust window size for menubar + centerWindow(); } void CCEGLView::centerWindow() diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 909a0639e7..2f8877772a 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -32,6 +32,8 @@ THE SOFTWARE. NS_CC_BEGIN +typedef LRESULT (*CUSTOM_WND_PROC)(UINT message, WPARAM wParam, LPARAM lParam, BOOL* pProcessed); + class CCEGL; class CC_DLL CCEGLView : public CCEGLViewProtocol @@ -48,6 +50,10 @@ public: virtual void setFrameSize(float width, float height); virtual void setIMEKeyboardState(bool bOpen); virtual bool enableRetina(); + + void setMenuResource(LPCWSTR menu); + void setWndProc(CUSTOM_WND_PROC proc); + private: virtual bool Create(LPCTSTR pTitle, int w, int h); bool initGL(); @@ -77,6 +83,14 @@ private: HDC m_hDC; HGLRC m_hRC; LPFN_ACCELEROMETER_KEYHOOK m_lpfnAccelerometerKeyHook; + + LPCWSTR m_menu; + CUSTOM_WND_PROC m_wndproc; + + int m_windowWidth; + int m_windowHeight; + float m_windowTouchScaleX; + float m_windowTouchScaleY; }; NS_CC_END diff --git a/cocos2dx/platform/win32/CCFileUtils.cpp b/cocos2dx/platform/win32/CCFileUtils.cpp index 80c4f846cf..c7a25de12f 100644 --- a/cocos2dx/platform/win32/CCFileUtils.cpp +++ b/cocos2dx/platform/win32/CCFileUtils.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "platform/CCFileUtilsCommon_cpp.h" #include #include "CCDirector.h" +#include "CCApplication.h" using namespace std; @@ -78,6 +79,7 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) const char* resDir = m_obDirectory.c_str(); CCString* pRet = CCString::create(""); + const std::string& resourceRootPath = CCApplication::sharedApplication()->getResourceRootPath(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { // path start with "x:", is absolute path @@ -91,6 +93,12 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) pRet->m_sString = szDriver; pRet->m_sString += pszRelativePath; } + else if (resourceRootPath.length() > 0) + { + pRet->m_sString = resourceRootPath.c_str(); + pRet->m_sString += m_obDirectory.c_str(); + pRet->m_sString += pszRelativePath; + } else { pRet->m_sString = s_pszResourcePath; diff --git a/cocos2dx/platform/win32/CCPlatformDefine.h b/cocos2dx/platform/win32/CCPlatformDefine.h index 7cd65d4ec2..febb3bcd9e 100644 --- a/cocos2dx/platform/win32/CCPlatformDefine.h +++ b/cocos2dx/platform/win32/CCPlatformDefine.h @@ -9,7 +9,12 @@ #endif #include + +#if CC_DISABLE_ASSERT > 0 +#define CC_ASSERT(cond) +#else #define CC_ASSERT(cond) assert(cond) +#endif #define CC_UNUSED_PARAM(unusedparam) (void)unusedparam /* Define NULL pointer value */ diff --git a/cocos2dx/proj.mac/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2dx/proj.mac/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id index cc2a2bbb8b..e784f3a3ce 100644 --- a/cocos2dx/proj.mac/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2dx/proj.mac/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -f8238151c244507cf5d5d21019bcc3aeae12ad58 \ No newline at end of file +48a295775479bd5b7fc89114495885a002502849 \ No newline at end of file diff --git a/cocos2dx/script_support/CCScriptSupport.cpp b/cocos2dx/script_support/CCScriptSupport.cpp index a71e24994a..cfe788731f 100644 --- a/cocos2dx/script_support/CCScriptSupport.cpp +++ b/cocos2dx/script_support/CCScriptSupport.cpp @@ -1,97 +1,98 @@ /**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ + Copyright (c) 2010-2011 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #include "CCScriptSupport.h" #include "CCScheduler.h" NS_CC_BEGIN -CCSchedulerScriptHandlerEntry* CCSchedulerScriptHandlerEntry::entryWithHandler(int nHandler, float fInterval, bool bPaused) +// #pragma mark - +// #pragma mark CCScriptHandlerEntry + +CCScriptHandlerEntry* CCScriptHandlerEntry::create(int nHandler) { - CCSchedulerScriptHandlerEntry* pEntry = new CCSchedulerScriptHandlerEntry(); - pEntry->initWithHandler(nHandler, fInterval, bPaused); + CCScriptHandlerEntry* entry = new CCScriptHandlerEntry(nHandler); + entry->autorelease(); + return entry; +} + +CCScriptHandlerEntry::~CCScriptHandlerEntry(void) +{ + CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler); +} + +// #pragma mark - +// #pragma mark CCSchedulerScriptHandlerEntry + +CCSchedulerScriptHandlerEntry* CCSchedulerScriptHandlerEntry::create(int nHandler, float fInterval, bool bPaused) +{ + CCSchedulerScriptHandlerEntry* pEntry = new CCSchedulerScriptHandlerEntry(nHandler); + pEntry->init(fInterval, bPaused); pEntry->autorelease(); return pEntry; } -bool CCSchedulerScriptHandlerEntry::initWithHandler(int nHandler, float fInterval, bool bPaused) +bool CCSchedulerScriptHandlerEntry::init(float fInterval, bool bPaused) { m_pTimer = new CCTimer(); - m_pTimer->initWithScriptHandler(nHandler, fInterval); + m_pTimer->initWithScriptHandler(m_nHandler, fInterval); m_pTimer->autorelease(); m_pTimer->retain(); - m_nHandler = nHandler; m_bPaused = bPaused; - LUALOG("[LUA] ADD script schedule: %d, entryID: %d", m_nHandler, m_nEntryID); + LUALOG("[LUA] ADD script schedule: %d, entryID: %d", m_nHandler, m_nEntryId); return true; } -CCSchedulerScriptHandlerEntry::CCSchedulerScriptHandlerEntry(void) -: m_pTimer(NULL) -, m_nHandler(0) -, m_bPaused(true) -, m_bMarkedForDeletion(false) -{ - static int nEntryCount = 0; - m_nEntryID = ++nEntryCount; -} - CCSchedulerScriptHandlerEntry::~CCSchedulerScriptHandlerEntry(void) { m_pTimer->release(); - CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nHandler); - LUALOG("[LUA] DEL script schedule %d, entryID: %d", m_nHandler, m_nEntryID); + LUALOG("[LUA] DEL script schedule %d, entryID: %d", m_nHandler, m_nEntryId); } -// ---------------------------- +// #pragma mark - +// #pragma mark CCTouchScriptHandlerEntry -CCTouchScriptHandlerEntry* CCTouchScriptHandlerEntry::entryWithHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches) +CCTouchScriptHandlerEntry* CCTouchScriptHandlerEntry::create(int nHandler, + bool bIsMultiTouches, + int nPriority, + bool bSwallowsTouches) { - CCTouchScriptHandlerEntry* pEntry = new CCTouchScriptHandlerEntry(); - pEntry->initWithHandler(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches); + CCTouchScriptHandlerEntry* pEntry = new CCTouchScriptHandlerEntry(nHandler); + pEntry->init(bIsMultiTouches, nPriority, bSwallowsTouches); pEntry->autorelease(); return pEntry; } -CCTouchScriptHandlerEntry::CCTouchScriptHandlerEntry(void) -: m_nHandler(0) -, m_bIsMultiTouches(false) -, m_nPriority(0) -, m_bSwallowsTouches(false) -{ -} - CCTouchScriptHandlerEntry::~CCTouchScriptHandlerEntry(void) { - CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nHandler); + CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler); LUALOG("[LUA] Remove touch event handler: %d", m_nHandler); } -bool CCTouchScriptHandlerEntry::initWithHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches) +bool CCTouchScriptHandlerEntry::init(bool bIsMultiTouches, int nPriority, bool bSwallowsTouches) { - m_nHandler = nHandler; m_bIsMultiTouches = bIsMultiTouches; m_nPriority = nPriority; m_bSwallowsTouches = bSwallowsTouches; @@ -99,8 +100,8 @@ bool CCTouchScriptHandlerEntry::initWithHandler(int nHandler, bool bIsMultiTouch return true; } -// ---------------------------- - +// #pragma mark - +// #pragma mark CCScriptEngineManager static CCScriptEngineManager* s_pSharedScriptEngineManager = NULL; @@ -114,7 +115,6 @@ void CCScriptEngineManager::setScriptEngine(CCScriptEngineProtocol *pScriptEngin { removeScriptEngine(); m_pScriptEngine = pScriptEngine; -// m_pScriptEngine->retain(); } void CCScriptEngineManager::removeScriptEngine(void) @@ -122,7 +122,6 @@ void CCScriptEngineManager::removeScriptEngine(void) if (m_pScriptEngine) { delete m_pScriptEngine; -// m_pScriptEngine->release(); m_pScriptEngine = NULL; } } diff --git a/cocos2dx/script_support/CCScriptSupport.h b/cocos2dx/script_support/CCScriptSupport.h index 0b6232e87c..93856a8c2c 100644 --- a/cocos2dx/script_support/CCScriptSupport.h +++ b/cocos2dx/script_support/CCScriptSupport.h @@ -1,26 +1,26 @@ /**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ + Copyright (c) 2010-2011 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef __SCRIPT_SUPPORT_H__ #define __SCRIPT_SUPPORT_H__ @@ -28,12 +28,19 @@ THE SOFTWARE. #include "platform/CCCommon.h" #include "touch_dispatcher/CCTouch.h" #include "cocoa/CCSet.h" +#include +#include +#include typedef struct lua_State lua_State; NS_CC_BEGIN class CCTimer; +class CCLayer; +class CCMenuItem; +class CCNotificationCenter; +class CCCallFunc; enum ccScriptType { kScriptTypeNone = 0, @@ -41,123 +48,144 @@ enum ccScriptType { kScriptTypeJavascript }; +// #pragma mark - +// #pragma mark CCScriptHandlerEntry + +class CCScriptHandlerEntry : public CCObject +{ +public: + static CCScriptHandlerEntry* create(int nHandler); + ~CCScriptHandlerEntry(void); + + int getHandler(void) { + return m_nHandler; + } + + int getEntryId(void) { + return m_nEntryId; + } + +protected: + CCScriptHandlerEntry(int nHandler) + : m_nHandler(nHandler) + { + static int newEntryId = 0; + newEntryId++; + m_nEntryId = newEntryId; + } + + int m_nHandler; + int m_nEntryId; +}; + /** * @addtogroup script_support * @{ */ -// Lua support for CCScheduler -class CCSchedulerScriptHandlerEntry : public CCObject +// #pragma mark - +// #pragma mark CCSchedulerScriptHandlerEntry + +class CCSchedulerScriptHandlerEntry : public CCScriptHandlerEntry { public: // nHandler return by tolua_ref_function(), called from LuaCocos2d.cpp - static CCSchedulerScriptHandlerEntry* entryWithHandler(int nHandler, float fInterval, bool bPaused); + static CCSchedulerScriptHandlerEntry* create(int nHandler, float fInterval, bool bPaused); ~CCSchedulerScriptHandlerEntry(void); - inline cocos2d::CCTimer* getTimer(void) { + cocos2d::CCTimer* getTimer(void) { return m_pTimer; } - inline bool isPaused(void) { + bool isPaused(void) { return m_bPaused; } - inline int getEntryID(void) { - return m_nEntryID; - } - - inline void markedForDeletion(void) { + void markedForDeletion(void) { m_bMarkedForDeletion = true; } - inline bool isMarkedForDeletion(void) { + bool isMarkedForDeletion(void) { return m_bMarkedForDeletion; } private: - CCSchedulerScriptHandlerEntry(void); - bool initWithHandler(int nHandler, float fInterval, bool bPaused); + CCSchedulerScriptHandlerEntry(int nHandler) + : CCScriptHandlerEntry(nHandler) + , m_pTimer(NULL) + , m_bPaused(false) + , m_bMarkedForDeletion(false) + { + } + bool init(float fInterval, bool bPaused); cocos2d::CCTimer* m_pTimer; bool m_bPaused; bool m_bMarkedForDeletion; - int m_nHandler; - int m_nEntryID; }; -// Lua support for touch events -class CCTouchScriptHandlerEntry : public CCObject +// #pragma mark - +// #pragma mark CCTouchScriptHandlerEntry + +class CCTouchScriptHandlerEntry : public CCScriptHandlerEntry { public: - static CCTouchScriptHandlerEntry* entryWithHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches); + static CCTouchScriptHandlerEntry* create(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches); ~CCTouchScriptHandlerEntry(void); - inline int getHandler(void) { - return m_nHandler; - } - - inline bool isMultiTouches(void) { + bool isMultiTouches(void) { return m_bIsMultiTouches; } - inline int getPriority(void) { + int getPriority(void) { return m_nPriority; } - inline bool getSwallowsTouches(void) { + bool getSwallowsTouches(void) { return m_bSwallowsTouches; } private: - CCTouchScriptHandlerEntry(void); - bool initWithHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches); + CCTouchScriptHandlerEntry(int nHandler) + : CCScriptHandlerEntry(nHandler) + , m_bIsMultiTouches(false) + , m_nPriority(0) + , m_bSwallowsTouches(false) + { + } + bool init(bool bIsMultiTouches, int nPriority, bool bSwallowsTouches); - int m_nHandler; bool m_bIsMultiTouches; int m_nPriority; bool m_bSwallowsTouches; }; +// #pragma mark - +// #pragma mark CCScriptEngineProtocol + // Don't make CCScriptEngineProtocol inherits from CCObject since setScriptEngine is invoked only once in AppDelegate.cpp, // It will affect the lifecycle of ScriptCore instance, the autorelease pool will be destroyed before destructing ScriptCore. // So a crash will appear on Win32 if you click the close button. -class CC_DLL CCScriptEngineProtocol// : public CCObject +class CC_DLL CCScriptEngineProtocol { public: virtual ~CCScriptEngineProtocol() {}; - + + /** Get script type */ virtual ccScriptType getScriptType() { return kScriptTypeNone; }; - /** - @brief Method used to get a pointer to the lua_State that the script module is attached to. - @return A pointer to the lua_State that the script module is attached to. - */ - virtual lua_State* getLuaState(void) = 0; - - /** - @brief Remove CCObject from lua state - @param object to remove - */ - virtual void removeCCObjectByID(int nLuaID) = 0; - virtual void removeJSObjectByCCObject(void * cobj) = 0; + /** Remove script object. */ + virtual void removeScriptObjectByCCObject(CCObject* pObj) = 0; - /** - @brief Remove Lua function handler - */ - virtual void removeLuaHandler(int nHandler) = 0; - - /** - @brief Add a path to find lua files in - @param path to be added to the Lua path - */ - virtual void addSearchPath(const char* path) = 0; + /** Remove script function handler, only CCLuaEngine class need to implement this function. */ + virtual void removeScriptHandler(int nHandler) {}; /** @brief Execute script code contained in the given string. @param codes holding the valid script code that should be executed. - @return 0 if the string is excuted correctly. - @return other if the string is excuted wrongly. + @return 0 if the string is executed correctly. + @return other if the string is executed wrongly. */ virtual int executeString(const char* codes) = 0; @@ -176,29 +204,25 @@ public: virtual int executeGlobalFunction(const char* functionName) = 0; /** - @brief Execute a function by handler - @param The function handler - @param Number of parameters + @brief Execute a node event function + @param pNode which node produce this event + @param nAction kCCNodeOnEnter,kCCNodeOnExit,kCCMenuItemActivated,kCCNodeOnEnterTransitionDidFinish,kCCNodeOnExitTransitionDidStart @return The integer value returned from the script function. */ - virtual int executeFunctionByHandler(int nHandler, int numArgs = 0) = 0; + virtual int executeNodeEvent(CCNode* pNode, int nAction) = 0; - virtual int executeFunctionWithIntegerData(int nHandler, int data, CCNode *self) = 0; - virtual int executeTouchesEvent(int nHandler, int eventType, CCSet *pTouches, CCNode *self) = 0; - virtual int executeFunctionWithFloatData(int nHandler, float data, CCNode *self) = 0; + virtual int executeMenuItemEvent(CCMenuItem* pMenuItem) = 0; + /** Execute a notification event function */ + virtual int executeNotificationEvent(CCNotificationCenter* pNotificationCenter, const char* pszName) = 0; - // execute a schedule function - virtual int executeSchedule(int nHandler, float dt, CCNode *self) = 0; + /** execute a callfun event */ + virtual int executeCallFuncActionEvent(CCCallFunc* pAction, CCObject* pTarget = NULL) = 0; + /** execute a schedule function */ + virtual int executeSchedule(CCTimer* pTimer, float dt, CCNode* pNode = NULL) = 0; - virtual int executeFunctionWithBooleanData(int nHandler, bool data) = 0; - virtual int executeFunctionWithCCObject(int nHandler, CCObject* pObject, const char* typeName) = 0; - virtual int pushIntegerToLuaStack(int data) = 0; - virtual int pushFloatToLuaStack(int data) = 0; - virtual int pushBooleanToLuaStack(int data) = 0; - virtual int pushCCObjectToLuaStack(CCObject* pObject, const char* typeName) = 0; - - // functions for excute touch event - virtual int executeTouchEvent(int nHandler, int eventType, CCTouch *pTouch) = 0; + /** functions for execute touch event */ + virtual int executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches) = 0; + virtual int executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch) = 0; }; /** @@ -216,10 +240,10 @@ public: } void setScriptEngine(CCScriptEngineProtocol *pScriptEngine); void removeScriptEngine(void); - + static CCScriptEngineManager* sharedManager(void); static void purgeSharedManager(void); - + private: CCScriptEngineManager(void) : m_pScriptEngine(NULL) diff --git a/cocos2dx/shaders/CCShaderCache.cpp b/cocos2dx/shaders/CCShaderCache.cpp index c5c61db11b..2ff29d8976 100644 --- a/cocos2dx/shaders/CCShaderCache.cpp +++ b/cocos2dx/shaders/CCShaderCache.cpp @@ -134,7 +134,7 @@ void CCShaderCache::loadDefaultShaders() p->release(); // - // Position and 1 color passed as a uniform (to similate glColor4ub ) + // Position and 1 color passed as a uniform (to simulate glColor4ub ) // p = new CCGLProgram(); loadDefaultShader(p, kCCShaderType_Position_uColor); @@ -186,7 +186,7 @@ void CCShaderCache::reloadDefaultShaders() loadDefaultShader(p, kCCShaderType_PositionTextureA8Color); // - // Position and 1 color passed as a uniform (to similate glColor4ub ) + // Position and 1 color passed as a uniform (to simulate glColor4ub ) // p = programForKey(kCCShader_Position_uColor); p->reset(); diff --git a/cocos2dx/sprite_nodes/CCAnimation.h b/cocos2dx/sprite_nodes/CCAnimation.h index c12852bdb8..9d92817894 100644 --- a/cocos2dx/sprite_nodes/CCAnimation.h +++ b/cocos2dx/sprite_nodes/CCAnimation.h @@ -67,7 +67,7 @@ public: /** how many units of time the frame takes */ CC_SYNTHESIZE(float, m_fDelayUnits, DelayUnits) - /** A CCAnimationFrameDisplayedNotification notification will be broadcasted when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcasted. */ + /** A CCAnimationFrameDisplayedNotification notification will be broadcast when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcast. */ CC_SYNTHESIZE_RETAIN(CCDictionary*, m_pUserInfo, UserInfo) }; diff --git a/cocos2dx/sprite_nodes/CCAnimationCache.h b/cocos2dx/sprite_nodes/CCAnimationCache.h index 570fc2979e..ac86cc5494 100644 --- a/cocos2dx/sprite_nodes/CCAnimationCache.h +++ b/cocos2dx/sprite_nodes/CCAnimationCache.h @@ -52,7 +52,7 @@ class CC_DLL CCAnimationCache : public CCObject public: CCAnimationCache(); ~CCAnimationCache(); - /** Retruns ths shared instance of the Animation cache */ + /** Returns the shared instance of the Animation cache */ static CCAnimationCache* sharedAnimationCache(void); /** Purges the cache. It releases all the CCAnimation objects and the shared instance. diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index ca6a5e8707..f77e140102 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -135,7 +135,7 @@ CCSprite* CCSprite::spriteWithSpriteFrame(CCSpriteFrame *pSpriteFrame) CCSprite* CCSprite::createWithSpriteFrame(CCSpriteFrame *pSpriteFrame) { CCSprite *pobSprite = new CCSprite(); - if (pobSprite && pobSprite->initWithSpriteFrame(pSpriteFrame)) + if (pSpriteFrame && pobSprite && pobSprite->initWithSpriteFrame(pSpriteFrame)) { pobSprite->autorelease(); return pobSprite; @@ -152,10 +152,13 @@ CCSprite* CCSprite::spriteWithSpriteFrameName(const char *pszSpriteFrameName) CCSprite* CCSprite::createWithSpriteFrameName(const char *pszSpriteFrameName) { CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pszSpriteFrameName); - + +#if COCOS2D_DEBUG > 0 char msg[256] = {0}; sprintf(msg, "Invalid spriteFrameName: %s", pszSpriteFrameName); CCAssert(pFrame != NULL, msg); +#endif + return createWithSpriteFrame(pFrame); } @@ -301,7 +304,7 @@ bool CCSprite::initWithSpriteFrameName(const char *pszSpriteFrameName) CCSprite* CCSprite::initWithCGImage(CGImageRef pImage) { // todo - // because it is deprecated, so we do not impelment it + // because it is deprecated, so we do not implement it return NULL; } @@ -479,7 +482,7 @@ void CCSprite::updateTransform(void) { CCAssert(m_pobBatchNode, "updateTransform is only valid when CCSprite is being rendered using an CCSpriteBatchNode"); - // recaculate matrix only if it is dirty + // recalculate matrix only if it is dirty if( isDirty() ) { // If it is not visible, or one of its ancestors is not visible, then do nothing: diff --git a/cocos2dx/sprite_nodes/CCSprite.h b/cocos2dx/sprite_nodes/CCSprite.h index 2a2aa504f0..ed5994b765 100644 --- a/cocos2dx/sprite_nodes/CCSprite.h +++ b/cocos2dx/sprite_nodes/CCSprite.h @@ -50,7 +50,7 @@ struct transformValues_; * @{ */ -#define CCSpriteIndexNotInitialized 0xffffffff /// CCSprite invalid index on the CCSpriteBatchode +#define CCSpriteIndexNotInitialized 0xffffffff /// CCSprite invalid index on the CCSpriteBatchNode /** CCSprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) ) diff --git a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp index ac82b54d03..8683e9120b 100644 --- a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp @@ -139,7 +139,7 @@ void CCSpriteBatchNode::visit(void) // with the exception that it doesn't call visit on it's children // // The alternative is to have a void CCSprite#visit, but - // although this is less mantainable, is faster + // although this is less maintainable, is faster // if (! m_bIsVisible) { @@ -280,7 +280,7 @@ void CCSpriteBatchNode::sortAllChildren() CCObject* pObj = NULL; //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact) - // and at the same time reorder descedants and the quads to the right index + // and at the same time reorder descendants and the quads to the right index CCARRAY_FOREACH(m_pChildren, pObj) { CCSprite* pChild = (CCSprite*)pObj; @@ -424,7 +424,7 @@ void CCSpriteBatchNode::increaseAtlasCapacity(void) { // serious problems CCLOGWARN("cocos2d: WARNING: Not enough memory to resize the atlas"); - CCAssert(false, "Not enough memory to resize the atla"); + CCAssert(false, "Not enough memory to resize the atlas"); } } diff --git a/cocos2dx/sprite_nodes/CCSpriteBatchNode.h b/cocos2dx/sprite_nodes/CCSpriteBatchNode.h index b23882a167..a0c2f98d72 100644 --- a/cocos2dx/sprite_nodes/CCSpriteBatchNode.h +++ b/cocos2dx/sprite_nodes/CCSpriteBatchNode.h @@ -157,12 +157,12 @@ public: virtual void draw(void); protected: - /* IMPORTANT XXX IMPORTNAT: + /* IMPORTANT XXX IMPORTANT: * These 2 methods can't be part of CCTMXLayer since they call [super add...], and CCSpriteSheet#add SHALL not be called */ /* Adds a quad into the texture atlas but it won't be added into the children array. - This method should be called only when you are dealing with very big AtlasSrite and when most of the CCSprite won't be updated. + This method should be called only when you are dealing with very big AtlasSprite and when most of the CCSprite won't be updated. For example: a tile map (CCTMXMap) or a label with lots of characters (BitmapFontAtlas) */ void addQuadFromSprite(CCSprite *sprite, unsigned int index); @@ -180,7 +180,7 @@ protected: CCTextureAtlas *m_pobTextureAtlas; ccBlendFunc m_blendFunc; - // all descendants: chlidren, gran children, etc... + // all descendants: children, gran children, etc... CCArray* m_pobDescendants; }; diff --git a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp index 056ed7f98b..2d9881ca3c 100644 --- a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp @@ -405,7 +405,7 @@ CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName) frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(key->getCString()); if (! frame) { - CCLOG("cocos2d: CCSpriteFrameCahce: Frame '%s' not found", pszName); + CCLOG("cocos2d: CCSpriteFrameCache: Frame '%s' not found", pszName); } } } diff --git a/cocos2dx/sprite_nodes/CCSpriteFrameCache.h b/cocos2dx/sprite_nodes/CCSpriteFrameCache.h index 2fd8462174..8aaa86b728 100644 --- a/cocos2dx/sprite_nodes/CCSpriteFrameCache.h +++ b/cocos2dx/sprite_nodes/CCSpriteFrameCache.h @@ -104,7 +104,7 @@ public: /** Removes multiple Sprite Frames from a plist file. * Sprite Frames stored in this file will be removed. - * It is convinient to call this method when a specific texture needs to be removed. + * It is convenient to call this method when a specific texture needs to be removed. * @since v0.99.5 */ void removeSpriteFramesFromFile(const char* plist); @@ -116,7 +116,7 @@ private: void removeSpriteFramesFromDictionary(CCDictionary* dictionary); public: /** Removes all Sprite Frames associated with the specified textures. - * It is convinient to call this method when a specific texture needs to be removed. + * It is convenient to call this method when a specific texture needs to be removed. * @since v0.995. */ void removeSpriteFramesFromTexture(CCTexture2D* texture); diff --git a/cocos2dx/support/CCNotificationCenter.cpp b/cocos2dx/support/CCNotificationCenter.cpp index a480e01ebb..4ba8e8d0a9 100644 --- a/cocos2dx/support/CCNotificationCenter.cpp +++ b/cocos2dx/support/CCNotificationCenter.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. #include "CCNotificationCenter.h" #include "cocoa/CCArray.h" +#include "script_support/CCScriptSupport.h" #include using namespace std; @@ -33,6 +34,7 @@ NS_CC_BEGIN; static CCNotificationCenter *s_sharedNotifCenter = NULL; CCNotificationCenter::CCNotificationCenter() +: m_scriptHandler(0) { m_observers = CCArray::createWithCapacity(3); m_observers->retain(); @@ -40,6 +42,7 @@ CCNotificationCenter::CCNotificationCenter() CCNotificationCenter::~CCNotificationCenter() { + unregisterScriptObserver(); m_observers->release(); } @@ -111,6 +114,21 @@ void CCNotificationCenter::removeObserver(CCObject *target,const char *name) } } +void CCNotificationCenter::registerScriptObserver(int handler) +{ + unregisterScriptObserver(); + m_scriptHandler = handler; +} + +void CCNotificationCenter::unregisterScriptObserver(void) +{ + if (m_scriptHandler) + { + CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_scriptHandler); + } + m_scriptHandler = 0; +} + void CCNotificationCenter::postNotification(const char *name, CCObject *object) { CCObject* obj = NULL; @@ -123,6 +141,12 @@ void CCNotificationCenter::postNotification(const char *name, CCObject *object) if (!strcmp(name,observer->getName())) observer->performSelector(object); } + + if (m_scriptHandler) + { + CCScriptEngineProtocol* engine = CCScriptEngineManager::sharedManager()->getScriptEngine(); + engine->executeNotificationEvent(this, name); + } } void CCNotificationCenter::postNotification(const char *name) diff --git a/cocos2dx/support/CCNotificationCenter.h b/cocos2dx/support/CCNotificationCenter.h index 70c94a9d4d..0876b5b7a7 100644 --- a/cocos2dx/support/CCNotificationCenter.h +++ b/cocos2dx/support/CCNotificationCenter.h @@ -46,9 +46,13 @@ public: void removeObserver(CCObject *target,const char *name); + void registerScriptObserver(int handler); + void unregisterScriptObserver(void); + void postNotification(const char *name); void postNotification(const char *name, CCObject *object); + inline int getScriptHandler() { return m_scriptHandler; }; private: // // internal functions @@ -59,6 +63,7 @@ private: // variables // CCArray *m_observers; + int m_scriptHandler; }; class CC_DLL CCNotificationObserver : public CCObject diff --git a/cocos2dx/support/CCPointExtension.h b/cocos2dx/support/CCPointExtension.h index caecb9ca7d..d288704af5 100644 --- a/cocos2dx/support/CCPointExtension.h +++ b/cocos2dx/support/CCPointExtension.h @@ -272,7 +272,7 @@ CCPoint CC_DLL ccpLerp(const CCPoint& a, const CCPoint& b, float alpha); bool CC_DLL ccpFuzzyEqual(const CCPoint& a, const CCPoint& b, float variance); -/** Multiplies a nd b components, a.x*b.x, a.y*b.y +/** Multiplies a and b components, a.x*b.x, a.y*b.y @returns a component-wise multiplication @since v0.99.1 */ diff --git a/cocos2dx/support/CCUserDefault.cpp b/cocos2dx/support/CCUserDefault.cpp index 6714b255ab..2c13b2cf51 100644 --- a/cocos2dx/support/CCUserDefault.cpp +++ b/cocos2dx/support/CCUserDefault.cpp @@ -118,7 +118,7 @@ static void setValueForKey(const char* pKey, const char* pValue) if (rootNode) { // the node doesn't exist, add a new one - // libxml in android donesn't support xmlNewTextChild, so use this approach + // libxml in android doesn't support xmlNewTextChild, so use this approach xmlNodePtr tmpNode = xmlNewNode(NULL, BAD_CAST pKey); xmlNodePtr content = xmlNewText(BAD_CAST pValue); xmlAddChild(rootNode, tmpNode); @@ -227,7 +227,7 @@ string CCUserDefault::getStringForKey(const char* pKey, const std::string & defa void CCUserDefault::setBoolForKey(const char* pKey, bool value) { - // save bool value as sring + // save bool value as string if (true == value) { @@ -292,7 +292,7 @@ CCUserDefault* CCUserDefault::sharedUserDefault() initXMLFilePath(); // only create xml file one time - // the file exists after the programe exit + // the file exists after the program exit if ((! isXMLFileExist()) && (! createXMLFile())) { return NULL; diff --git a/cocos2dx/support/CCVertex.h b/cocos2dx/support/CCVertex.h index 7ea150faaa..2ce4446afc 100644 --- a/cocos2dx/support/CCVertex.h +++ b/cocos2dx/support/CCVertex.h @@ -39,7 +39,7 @@ NS_CC_BEGIN /** converts a line to a polygon */ void CC_DLL ccVertexLineToPolygon(CCPoint *points, float stroke, ccVertex2F *vertices, unsigned int offset, unsigned int nuPoints); -/** returns wheter or not the line intersects */ +/** returns whether or not the line intersects */ bool CC_DLL ccVertexLineIntersect(float Ax, float Ay, float Bx, float By, float Cx, float Cy, diff --git a/cocos2dx/support/data_support/ccCArray.cpp b/cocos2dx/support/data_support/ccCArray.cpp index 3255ac7289..cb6df03055 100644 --- a/cocos2dx/support/data_support/ccCArray.cpp +++ b/cocos2dx/support/data_support/ccCArray.cpp @@ -97,7 +97,7 @@ void ccArrayShrink(ccArray *arr) } } -/** Returns index of first occurence of object, CC_INVALID_INDEX if object not found. */ +/** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */ unsigned int ccArrayGetIndexOfObject(ccArray *arr, CCObject* object) { for(unsigned int i = 0; i < arr->num; i++) @@ -114,7 +114,7 @@ bool ccArrayContainsObject(ccArray *arr, CCObject* object) return ccArrayGetIndexOfObject(arr, object) != CC_INVALID_INDEX; } -/** Appends an object. Bahaviour undefined if array doesn't have enough capacity. */ +/** Appends an object. Behavior undefined if array doesn't have enough capacity. */ void ccArrayAppendObject(ccArray *arr, CCObject* object) { CCAssert(object != NULL, "Invalid parameter!"); @@ -130,7 +130,7 @@ void ccArrayAppendObjectWithResize(ccArray *arr, CCObject* object) ccArrayAppendObject(arr, object); } -/** Appends objects from plusArr to arr. Behaviour undefined if arr doesn't have +/** Appends objects from plusArr to arr. Behavior undefined if arr doesn't have enough capacity. */ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr) { @@ -188,7 +188,7 @@ void ccArrayRemoveAllObjects(ccArray *arr) } /** Removes object at specified index and pushes back all subsequent objects. - Behaviour undefined if index outside [0, num-1]. */ + Behavior 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"); @@ -208,7 +208,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseO /** Removes object at specified index and fills the gap with the last object, thereby avoiding the need to push back subsequent objects. - Behaviour undefined if index outside [0, num-1]. */ + Behavior undefined if index outside [0, num-1]. */ void ccArrayFastRemoveObjectAtIndex(ccArray *arr, unsigned int index) { CC_SAFE_RELEASE(arr->arr[index]); @@ -225,7 +225,7 @@ void ccArrayFastRemoveObject(ccArray *arr, CCObject* object) } } -/** Searches for the first occurance of object and removes it. If object is not +/** Searches for the first occurrence of object and removes it. If object is not found the function has no effect. */ void ccArrayRemoveObject(ccArray *arr, CCObject* object, bool bReleaseObj/* = true*/) { @@ -313,7 +313,7 @@ void ccCArrayEnsureExtraCapacity(ccCArray *arr, unsigned int extra) ccArrayEnsureExtraCapacity((ccArray*)arr,extra); } -/** Returns index of first occurence of value, CC_INVALID_INDEX if value not found. */ +/** Returns index of first occurrence of value, CC_INVALID_INDEX if value not found. */ unsigned int ccCArrayGetIndexOfValue(ccCArray *arr, void* value) { unsigned int i; @@ -331,7 +331,7 @@ bool ccCArrayContainsValue(ccCArray *arr, void* value) return ccCArrayGetIndexOfValue(arr, value) != CC_INVALID_INDEX; } -/** Inserts a value at a certain position. Behaviour undefined if aray doesn't have enough capacity */ +/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */ void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, unsigned int index) { CCAssert( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index"); @@ -352,7 +352,7 @@ void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, unsigned int index) arr->arr[index] = value; } -/** Appends an value. Bahaviour undefined if array doesn't have enough capacity. */ +/** Appends an value. Behavior undefined if array doesn't have enough capacity. */ void ccCArrayAppendValue(ccCArray *arr, void* value) { arr->arr[arr->num] = value; @@ -373,7 +373,7 @@ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value) } -/** Appends values from plusArr to arr. Behaviour undefined if arr doesn't have +/** Appends values from plusArr to arr. Behavior undefined if arr doesn't have enough capacity. */ void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr) { @@ -399,7 +399,7 @@ void ccCArrayRemoveAllValues(ccCArray *arr) } /** Removes value at specified index and pushes back all subsequent values. - Behaviour undefined if index outside [0, num-1]. + Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index) @@ -414,7 +414,7 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index) /** Removes value at specified index and fills the gap with the last value, thereby avoiding the need to push back subsequent values. - Behaviour undefined if index outside [0, num-1]. + Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int index) @@ -423,7 +423,7 @@ void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int index) arr->arr[index] = arr->arr[last]; } -/** Searches for the first occurance of value and removes it. If value is not found the function has no effect. +/** Searches for the first occurrence of value and removes it. If value is not found the function has no effect. @since v0.99.4 */ void ccCArrayRemoveValue(ccCArray *arr, void* value) diff --git a/cocos2dx/support/data_support/ccCArray.h b/cocos2dx/support/data_support/ccCArray.h index a6afcbc256..cd6ee42255 100644 --- a/cocos2dx/support/data_support/ccCArray.h +++ b/cocos2dx/support/data_support/ccCArray.h @@ -35,7 +35,7 @@ THE SOFTWARE. - comparisons are done using pointer equality instead of isEqual There are 2 kind of functions: - - ccArray functions that manipulates objective-c objects (retain and release are performanced) + - ccArray functions that manipulates objective-c objects (retain and release are performed) - ccCArray functions that manipulates values like if they were standard C structures (no retain/release is performed) */ @@ -78,20 +78,20 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, unsigned int extra); /** shrinks the array so the memory footprint corresponds with the number of items */ void ccArrayShrink(ccArray *arr); -/** Returns index of first occurence of object, NSNotFound if object not found. */ +/** Returns index of first occurrence of object, NSNotFound if object not found. */ unsigned int ccArrayGetIndexOfObject(ccArray *arr, CCObject* object); /** Returns a Boolean value that indicates whether object is present in array. */ bool ccArrayContainsObject(ccArray *arr, CCObject* object); -/** Appends an object. Bahaviour undefined if array doesn't have enough capacity. */ +/** Appends an object. Behavior undefined if array doesn't have enough capacity. */ void ccArrayAppendObject(ccArray *arr, CCObject* object); /** Appends an object. Capacity of arr is increased if needed. */ void ccArrayAppendObjectWithResize(ccArray *arr, CCObject* object); /** Appends objects from plusArr to arr. - Behaviour undefined if arr doesn't have enough capacity. */ + Behavior undefined if arr doesn't have enough capacity. */ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr); /** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */ @@ -107,17 +107,17 @@ void ccArraySwapObjectsAtIndexes(ccArray *arr, unsigned int index1, unsigned int void ccArrayRemoveAllObjects(ccArray *arr); /** Removes object at specified index and pushes back all subsequent objects. - Behaviour undefined if index outside [0, num-1]. */ + Behavior undefined if index outside [0, num-1]. */ void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj = true); /** Removes object at specified index and fills the gap with the last object, thereby avoiding the need to push back subsequent objects. - Behaviour undefined if index outside [0, num-1]. */ + Behavior undefined if index outside [0, num-1]. */ void ccArrayFastRemoveObjectAtIndex(ccArray *arr, unsigned int index); void ccArrayFastRemoveObject(ccArray *arr, CCObject* object); -/** Searches for the first occurance of object and removes it. If object is not +/** Searches for the first occurrence of object and removes it. If object is not found the function has no effect. */ void ccArrayRemoveObject(ccArray *arr, CCObject* object, bool bReleaseObj = true); @@ -149,22 +149,22 @@ void ccCArrayDoubleCapacity(ccCArray *arr); /** Increases array capacity such that max >= num + extra. */ void ccCArrayEnsureExtraCapacity(ccCArray *arr, unsigned int extra); -/** Returns index of first occurence of value, NSNotFound if value not found. */ +/** Returns index of first occurrence of value, NSNotFound if value not found. */ unsigned int ccCArrayGetIndexOfValue(ccCArray *arr, void* value); /** Returns a Boolean value that indicates whether value is present in the C array. */ bool ccCArrayContainsValue(ccCArray *arr, void* value); -/** Inserts a value at a certain position. Behaviour undefined if aray doesn't have enough capacity */ +/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */ void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, unsigned int index); -/** Appends an value. Bahaviour undefined if array doesn't have enough capacity. */ +/** Appends an value. Behavior undefined if array doesn't have enough capacity. */ void ccCArrayAppendValue(ccCArray *arr, void* value); /** Appends an value. Capacity of arr is increased if needed. */ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value); -/** Appends values from plusArr to arr. Behaviour undefined if arr doesn't have +/** Appends values from plusArr to arr. Behavior undefined if arr doesn't have enough capacity. */ void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr); @@ -175,19 +175,19 @@ void ccCArrayAppendArrayWithResize(ccCArray *arr, ccCArray *plusArr); void ccCArrayRemoveAllValues(ccCArray *arr); /** Removes value at specified index and pushes back all subsequent values. - Behaviour undefined if index outside [0, num-1]. + Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ void ccCArrayRemoveValueAtIndex(ccCArray *arr, unsigned int index); /** Removes value at specified index and fills the gap with the last value, thereby avoiding the need to push back subsequent values. - Behaviour undefined if index outside [0, num-1]. + Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int index); -/** Searches for the first occurance of value and removes it. If value is not found the function has no effect. +/** Searches for the first occurrence of value and removes it. If value is not found the function has no effect. @since v0.99.4 */ void ccCArrayRemoveValue(ccCArray *arr, void* value); diff --git a/cocos2dx/support/data_support/uthash.h b/cocos2dx/support/data_support/uthash.h index f86a82e81b..f2576e9154 100644 --- a/cocos2dx/support/data_support/uthash.h +++ b/cocos2dx/support/data_support/uthash.h @@ -62,7 +62,7 @@ do { } while(0) #endif -/* uint32_t next definded will conflict with other libraries and an "error C2872: 'uint32_t' : ambiguous symbol" will appear. +/* uint32_t next defined will conflict with other libraries and an "error C2872: 'uint32_t' : ambiguous symbol" will appear. so we replace all uint32_t with 'unsigned int'. */ /* a number of the hash function use uint32_t which isn't defined on win32 */ diff --git a/cocos2dx/support/image_support/TGAlib.cpp b/cocos2dx/support/image_support/TGAlib.cpp index 23d9a2bf64..dd98b87fb1 100644 --- a/cocos2dx/support/image_support/TGAlib.cpp +++ b/cocos2dx/support/image_support/TGAlib.cpp @@ -275,14 +275,14 @@ tImageTGA * tgaLoad(const char *pszFilename) return info; } -// converts RGB to greyscale +// converts RGB to grayscale void tgaRGBtogreyscale(tImageTGA *psInfo) { int mode,i,j; unsigned char *newImageData; - // if the image is already greyscale do nothing + // if the image is already grayscale do nothing if (psInfo->pixelDepth == 8) return; @@ -296,7 +296,7 @@ void tgaRGBtogreyscale(tImageTGA *psInfo) { return; } - // convert pixels: greyscale = o.30 * R + 0.59 * G + 0.11 * B + // convert pixels: grayscale = o.30 * R + 0.59 * G + 0.11 * B for (i = 0,j = 0; j < psInfo->width * psInfo->height; i +=mode, j++) newImageData[j] = (unsigned char)(0.30 * psInfo->imageData[i] + @@ -310,7 +310,7 @@ void tgaRGBtogreyscale(tImageTGA *psInfo) { // reassign pixelDepth and type according to the new image type psInfo->pixelDepth = 8; psInfo->type = 3; - // reassing imageData to the new array. + // reassigning imageData to the new array. psInfo->imageData = newImageData; } diff --git a/cocos2dx/support/image_support/TGAlib.h b/cocos2dx/support/image_support/TGAlib.h index 58e66b2e88..141b6a2fff 100644 --- a/cocos2dx/support/image_support/TGAlib.h +++ b/cocos2dx/support/image_support/TGAlib.h @@ -61,7 +61,7 @@ bool tgaLoadImageData(unsigned char *Buffer, unsigned long bufSize, tImageTGA *p /// this is the function to call when we want to load an image tImageTGA * tgaLoad(const char *pszFilename); -// /converts RGB to greyscale +// /converts RGB to grayscale void tgaRGBtogreyscale(tImageTGA *psInfo); /// releases the memory used for the image diff --git a/cocos2dx/support/zip_support/ZipUtils.h b/cocos2dx/support/zip_support/ZipUtils.h index d9cc1ecdd3..564ec230f7 100644 --- a/cocos2dx/support/zip_support/ZipUtils.h +++ b/cocos2dx/support/zip_support/ZipUtils.h @@ -33,7 +33,7 @@ namespace cocos2d unsigned char sig[4]; // signature. Should be 'CCZ!' 4 bytes unsigned short compression_type; // should 0 unsigned short version; // should be 2 (although version type==1 is also supported) - unsigned int reserved; // Reserverd for users. + unsigned int reserved; // Reserved for users. unsigned int len; // size of the uncompressed file }; @@ -51,7 +51,7 @@ namespace cocos2d * Inflates either zlib or gzip deflated memory. The inflated memory is * expected to be freed by the caller. * - * It will allocate 256k for the destination buffer. If it is not enought it will multiply the previous buffer size per 2, until there is enough memory. + * It will allocate 256k for the destination buffer. If it is not enough it will multiply the previous buffer size per 2, until there is enough memory. * @returns the length of the deflated buffer * @since v0.8.1 diff --git a/cocos2dx/support/zip_support/ioapi.h b/cocos2dx/support/zip_support/ioapi.h index 4eeddaadf8..48b65c95b2 100644 --- a/cocos2dx/support/zip_support/ioapi.h +++ b/cocos2dx/support/zip_support/ioapi.h @@ -80,7 +80,7 @@ namespace cocos2d { #include "mz64conf.h" #endif -/* a type choosen by DEFINE */ +/* a type chosen by DEFINE */ #ifdef HAVE_64BIT_INT_CUSTOM typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; #else diff --git a/cocos2dx/support/zip_support/unzip.cpp b/cocos2dx/support/zip_support/unzip.cpp index 29a589eb73..b65caaae89 100644 --- a/cocos2dx/support/zip_support/unzip.cpp +++ b/cocos2dx/support/zip_support/unzip.cpp @@ -53,8 +53,8 @@ Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G should only read the compressed/uncompressed size from the Zip64 format if the size from normal header was 0xFFFFFFFF - Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant - Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) + Oct-2009 - Mathias Svensson - Applied some bug fixes from patches received from Gilles Vollant + Oct-2009 - Mathias Svensson - Applied support to unzip files with compression method BZIP2 (bzip2 lib is required) Patch created by Daniel Borca Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer @@ -142,7 +142,7 @@ typedef struct #endif ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ - uLong stream_initialised; /* flag set if stream structure is initialised*/ + uLong stream_initialised; /* flag set if stream structure is initialized*/ ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ uInt size_local_extrafield;/* size of the local extra field */ @@ -154,7 +154,7 @@ typedef struct ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ + voidpf filestream; /* io structure of the zipfile */ uLong compression_method; /* compression method (0==store) */ ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ int raw; @@ -167,7 +167,7 @@ typedef struct { zlib_filefunc64_32_def z_filefunc; int is64bitOpenFunction; - voidpf filestream; /* io structore of the zipfile */ + voidpf filestream; /* io structure of the zipfile */ unz_global_info64 gi; /* public global information */ ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ ZPOS64_T num_file; /* number of the current file in the zipfile*/ @@ -201,7 +201,7 @@ typedef struct /* =========================================================================== Read a byte from a gz_stream; update next_in and avail_in. Return EOF for end of file. - IN assertion: the stream s has been sucessfully opened for reading. + IN assertion: the stream s has been successfully opened for reading. */ @@ -381,10 +381,10 @@ local int strcmpcasenosensitive_internal (const char* fileName1, const char* fil /* Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + If iCaseSenisivity = 1, comparison is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparison is not case sensitivity (like strcmpi or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + If iCaseSenisivity = 0, case sensitivity is default of your operating system (like 1 on Unix, 2 on Windows) */ @@ -592,9 +592,9 @@ local unzFile unzOpenInternal (const void *path, uLong uL; uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ + spanning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ + for spanning ZIP, unsupported, always 0*/ ZPOS64_T number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ @@ -848,7 +848,7 @@ int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) return UNZ_OK; } /* - Translate date/time from Dos format to tm_unz (readable more easilty) + Translate date/time from Dos format to tm_unz (readable more easily) */ local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) { @@ -1677,7 +1677,7 @@ ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) buf contain buffer where data must be copied len the size of buf. - return the number of byte copied if somes bytes are copied + return the number of byte copied if some bytes are copied return 0 if the end of file was reached return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) diff --git a/cocos2dx/support/zip_support/unzip.h b/cocos2dx/support/zip_support/unzip.h index 4fab73cda3..e30e403d17 100644 --- a/cocos2dx/support/zip_support/unzip.h +++ b/cocos2dx/support/zip_support/unzip.h @@ -153,10 +153,10 @@ int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, int iCaseSensitivity)); /* Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + If iCaseSenisivity = 1, comparison is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparison is not case sensitivity (like strcmpi or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + If iCaseSenisivity = 0, case sensitivity is default of your operating system (like 1 on Unix, 2 on Windows) */ @@ -302,9 +302,9 @@ int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, uLong commentBufferSize)); /* Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about + if pfile_info!=NULL, the *pfile_info structure will contain some info about the current file - if szFileName!=NULL, the filemane string will be copied in szFileName + if szFileName!=NULL, the filename string will be copied in szFileName (fileNameBufferSize is the size of the buffer) if extraField!=NULL, the extra field information will be copied in extraField (extraFieldBufferSize is the size of the buffer). @@ -382,7 +382,7 @@ int ZEXPORT unzReadCurrentFile OF((unzFile file, buf contain buffer where data must be copied len the size of buf. - return the number of byte copied if somes bytes are copied + return the number of byte copied if some bytes are copied return 0 if the end of file was reached return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) diff --git a/cocos2dx/text_input_node/CCIMEDelegate.h b/cocos2dx/text_input_node/CCIMEDelegate.h index bc70383344..07c54ca300 100644 --- a/cocos2dx/text_input_node/CCIMEDelegate.h +++ b/cocos2dx/text_input_node/CCIMEDelegate.h @@ -36,8 +36,8 @@ NS_CC_BEGIN typedef struct { - CCRect begin; // the soft keyboard rectangle when animatin begin - CCRect end; // the soft keyboard rectangle when animatin end + CCRect begin; // the soft keyboard rectangle when animation begins + CCRect end; // the soft keyboard rectangle when animation ends float duration; // the soft keyboard animation duration } CCIMEKeyboardNotificationInfo; @@ -56,38 +56,38 @@ protected: friend class CCIMEDispatcher; /** - @brief Decide the delegate instance is ready for receive ime message or not. + @brief Decide if the delegate instance is ready to receive an IME message. Called by CCIMEDispatcher. */ virtual bool canAttachWithIME() { return false; } /** - @brief When the delegate detach with IME, this method call by CCIMEDispatcher. + @brief When the delegate detaches from the IME, this method is called by CCIMEDispatcher. */ virtual void didAttachWithIME() {} /** - @brief Decide the delegate instance can stop receive ime message or not. + @brief Decide if the delegate instance can stop receiving IME messages. */ virtual bool canDetachWithIME() { return false; } /** - @brief When the delegate detach with IME, this method call by CCIMEDispatcher. + @brief When the delegate detaches from the IME, this method is called by CCIMEDispatcher. */ virtual void didDetachWithIME() {} /** - @brief Called by CCIMEDispatcher when some text input from IME. + @brief Called by CCIMEDispatcher when text input received from the IME. */ virtual void insertText(const char * text, int len) {CC_UNUSED_PARAM(text);CC_UNUSED_PARAM(len);} /** - @brief Called by CCIMEDispatcher when user clicked the backward key. + @brief Called by CCIMEDispatcher after the user clicks the backward key. */ virtual void deleteBackward() {} /** - @brief Called by CCIMEDispatcher for get text which delegate already has. + @brief Called by CCIMEDispatcher for text stored in delegate. */ virtual const char * getContentText() { return 0; } diff --git a/cocos2dx/text_input_node/CCIMEDispatcher.cpp b/cocos2dx/text_input_node/CCIMEDispatcher.cpp index 9fd58584d9..1371557d7e 100644 --- a/cocos2dx/text_input_node/CCIMEDispatcher.cpp +++ b/cocos2dx/text_input_node/CCIMEDispatcher.cpp @@ -160,7 +160,7 @@ bool CCIMEDispatcher::attachDelegateWithIME(CCIMEDelegate * pDelegate) break; } - // havn't delegate attached with IME yet + // delegate hasn't attached to IME yet CC_BREAK_IF(! pDelegate->canAttachWithIME()); m_pImpl->m_DelegateWithIme = *iter; @@ -177,7 +177,7 @@ bool CCIMEDispatcher::detachDelegateWithIME(CCIMEDelegate * pDelegate) { CC_BREAK_IF(! m_pImpl || ! pDelegate); - // if pDelegate is not the current delegate attached with ime, return + // if pDelegate is not the current delegate attached to IME, return CC_BREAK_IF(m_pImpl->m_DelegateWithIme != pDelegate); CC_BREAK_IF(! pDelegate->canDetachWithIME()); @@ -219,7 +219,7 @@ void CCIMEDispatcher::dispatchInsertText(const char * pText, int nLen) { CC_BREAK_IF(! m_pImpl || ! pText || nLen <= 0); - // there is no delegate attach with ime + // there is no delegate attached to IME CC_BREAK_IF(! m_pImpl->m_DelegateWithIme); m_pImpl->m_DelegateWithIme->insertText(pText, nLen); @@ -232,7 +232,7 @@ void CCIMEDispatcher::dispatchDeleteBackward() { CC_BREAK_IF(! m_pImpl); - // there is no delegate attach with ime + // there is no delegate attached to IME CC_BREAK_IF(! m_pImpl->m_DelegateWithIme); m_pImpl->m_DelegateWithIme->deleteBackward(); diff --git a/cocos2dx/text_input_node/CCIMEDispatcher.h b/cocos2dx/text_input_node/CCIMEDispatcher.h index 54fdaeb137..1887e223da 100644 --- a/cocos2dx/text_input_node/CCIMEDispatcher.h +++ b/cocos2dx/text_input_node/CCIMEDispatcher.h @@ -48,22 +48,22 @@ public: static CCIMEDispatcher* sharedDispatcher(); // /** -// @brief Release all CCIMEDelegates from shared dispatcher. +// @brief Releases all CCIMEDelegates from the shared dispatcher. // */ // static void purgeSharedDispatcher(); /** - @brief dispatch the input text from ime + @brief Dispatches the input text from IME. */ void dispatchInsertText(const char * pText, int nLen); /** - @brief dispatch the delete backward operation + @brief Dispatches the delete-backward operation. */ void dispatchDeleteBackward(); /** - @brief get the content text, which current CCIMEDelegate which attached with IME has. + @brief Get the content text from CCIMEDelegate, retrieved previously from IME. */ const char * getContentText(); @@ -79,20 +79,20 @@ protected: friend class CCIMEDelegate; /** - @brief add delegate to concern ime msg + @brief Add delegate to receive IME messages. */ void addDelegate(CCIMEDelegate * pDelegate); /** - @brief attach the pDeleate with ime. - @return If the old delegate can detattach with ime and the new delegate - can attach with ime, return true, otherwise return false. + @brief Attach the pDelegate to the IME. + @return If the old delegate can detach from the IME, and the new delegate + can attach to the IME, return true, otherwise false. */ bool attachDelegateWithIME(CCIMEDelegate * pDelegate); bool detachDelegateWithIME(CCIMEDelegate * pDelegate); /** - @brief remove the delegate from the delegates who concern ime msg + @brief Remove the delegate from the delegates which receive IME messages. */ void removeDelegate(CCIMEDelegate * pDelegate); diff --git a/cocos2dx/text_input_node/CCTextFieldTTF.cpp b/cocos2dx/text_input_node/CCTextFieldTTF.cpp index b0d6d36879..4d689893fa 100644 --- a/cocos2dx/text_input_node/CCTextFieldTTF.cpp +++ b/cocos2dx/text_input_node/CCTextFieldTTF.cpp @@ -184,7 +184,7 @@ void CCTextFieldTTF::insertText(const char * text, int len) { if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len)) { - // delegate doesn't want insert text + // delegate doesn't want to insert text return; } @@ -198,13 +198,13 @@ void CCTextFieldTTF::insertText(const char * text, int len) return; } - // '\n' has inserted, let delegate process first + // '\n' inserted, let delegate process first if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1)) { return; } - // if delegate hasn't process, detach with ime as default + // if delegate hasn't processed, detach from IME by default detachWithIME(); } @@ -227,11 +227,11 @@ void CCTextFieldTTF::deleteBackward() if (m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, m_pInputText->c_str() + nStrLen - nDeleteLen, nDeleteLen)) { - // delegate don't wan't delete backward + // delegate doesn't wan't to delete backwards return; } - // if delete all text, show space holder string + // if all text deleted, show placeholder string if (nStrLen <= nDeleteLen) { CC_SAFE_DELETE(m_pInputText); diff --git a/cocos2dx/text_input_node/CCTextFieldTTF.h b/cocos2dx/text_input_node/CCTextFieldTTF.h index da3d590d94..c59b01555a 100644 --- a/cocos2dx/text_input_node/CCTextFieldTTF.h +++ b/cocos2dx/text_input_node/CCTextFieldTTF.h @@ -42,7 +42,7 @@ class CC_DLL CCTextFieldDelegate { public: /** - @brief If the sender doesn't want to attach with IME, return true; + @brief If the sender doesn't want to attach to the IME, return true; */ virtual bool onTextFieldAttachWithIME(CCTextFieldTTF * sender) { @@ -51,7 +51,7 @@ public: } /** - @brief If the sender doesn't want to detach with IME, return true; + @brief If the sender doesn't want to detach from the IME, return true; */ virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * sender) { @@ -82,7 +82,7 @@ public: } /** - @brief If doesn't want draw sender as default, return true. + @brief If the sender doesn't want to draw, return true. */ virtual bool onDraw(CCTextFieldTTF * sender) { @@ -117,7 +117,7 @@ public: virtual bool attachWithIME(); /** - @brief End text input and close keyboard. + @brief End text input and close keyboard. */ virtual bool detachWithIME(); @@ -166,4 +166,4 @@ private: NS_CC_END -#endif // __CC_TEXT_FIELD_H__ \ No newline at end of file +#endif // __CC_TEXT_FIELD_H__ diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index c34a077b68..637a6f93de 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -163,7 +163,7 @@ void CCTexture2D::releaseData(void *data) void* CCTexture2D::keepData(void *data, unsigned int length) { CC_UNUSED_PARAM(length); - //The texture data mustn't be saved becuase it isn't a mutable texture. + //The texture data mustn't be saved because it isn't a mutable texture. return data; } @@ -600,7 +600,7 @@ void CCTexture2D::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) void CCTexture2D::generateMipmap() { - CCAssert( m_uPixelsWide == ccNextPOT(m_uPixelsWide) && m_uPixelsHigh == ccNextPOT(m_uPixelsHigh), "Mimpap texture only works in POT textures"); + CCAssert( m_uPixelsWide == ccNextPOT(m_uPixelsWide) && m_uPixelsHigh == ccNextPOT(m_uPixelsHigh), "Mipmap texture only works in POT textures"); ccGLBindTexture2D( m_uName ); glGenerateMipmap(GL_TEXTURE_2D); m_bHasMipmaps = true; @@ -703,7 +703,7 @@ const char* CCTexture2D::stringForFormat() return "PVRTC2"; default: - CCAssert(false , "unrecognised pixel format"); + CCAssert(false , "unrecognized pixel format"); CCLOG("stringForFormat: %ld, cannot give useful result", (long)m_ePixelFormat); break; } @@ -766,7 +766,7 @@ unsigned int CCTexture2D::bitsPerPixelForFormat(CCTexture2DPixelFormat format) break; default: ret = -1; - CCAssert(false , "unrecognised pixel format"); + CCAssert(false , "unrecognized pixel format"); CCLOG("bitsPerPixelForFormat: %ld, cannot give useful result", (long)format); break; } diff --git a/cocos2dx/textures/CCTexture2D.h b/cocos2dx/textures/CCTexture2D.h index 9c8370b88f..f4e1928a2f 100644 --- a/cocos2dx/textures/CCTexture2D.h +++ b/cocos2dx/textures/CCTexture2D.h @@ -114,7 +114,7 @@ public: void releaseData(void *data); void* keepData(void *data, unsigned int length); - /** Intializes with a texture2d with data */ + /** Initializes with a texture2d with data */ bool initWithData(const void* data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const CCSize& contentSize); /** @@ -251,7 +251,7 @@ private: CC_PROPERTY_READONLY(CCTexture2DPixelFormat, m_ePixelFormat, PixelFormat) /** width in pixels */ CC_PROPERTY_READONLY(unsigned int, m_uPixelsWide, PixelsWide) - /** hight in pixels */ + /** height in pixels */ CC_PROPERTY_READONLY(unsigned int, m_uPixelsHigh, PixelsHigh) /** texture name */ diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 9dd22e3c56..04532049fb 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -384,7 +384,7 @@ void CCTextureAtlas::insertQuadFromIndex(unsigned int oldIndex, unsigned int new { return; } - // because it is ambigious in iphone, so we implement abs ourself + // because it is ambiguous in iphone, so we implement abs ourselves // unsigned int howMany = abs( oldIndex - newIndex); unsigned int howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex); unsigned int dst = oldIndex; diff --git a/cocos2dx/textures/CCTextureAtlas.h b/cocos2dx/textures/CCTextureAtlas.h index fd8be63e78..ee9376cfcb 100644 --- a/cocos2dx/textures/CCTextureAtlas.h +++ b/cocos2dx/textures/CCTextureAtlas.h @@ -43,8 +43,8 @@ class CCTexture2D; /** @brief A class that implements a Texture Atlas. Supported features: -* The atlas file can be a PVRTC, PNG or any other fomrat supported by Texture2D -* Quads can be udpated in runtime +* The atlas file can be a PVRTC, PNG or any other format supported by Texture2D +* Quads can be updated in runtime * Quads can be added in runtime * Quads can be removed in runtime * Quads can be re-ordered in runtime diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 12551ad858..c150af905b 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -151,7 +151,7 @@ static void* loadImage(void* data) CCImage::EImageFormat imageType = computeImageFormatType(pAsyncStruct->filename); if (imageType == CCImage::kFmtUnKnown) { - CCLOG("unsupportted format %s",filename); + CCLOG("unsupported format %s",filename); delete pAsyncStruct; continue; @@ -437,8 +437,15 @@ CCTexture2D * CCTextureCache::addImage(const char * path) CCImage image; unsigned long nSize = 0; unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), "rb", &nSize); - CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, eImageFormat)); - CC_SAFE_DELETE_ARRAY(pBuffer); + if (! image.initWithImageData((void*)pBuffer, nSize, eImageFormat)) + { + CC_SAFE_DELETE_ARRAY(pBuffer); + break; + } + else + { + CC_SAFE_DELETE_ARRAY(pBuffer); + } texture = new CCTexture2D(); @@ -468,7 +475,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path) #ifdef CC_SUPPORT_PVRTC CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAlpha, int width) { - CCAssert(path != NULL, "TextureCache: fileimage MUST not be nill"); + CCAssert(path != NULL, "TextureCache: fileimage MUST not be nil"); CCAssert( bpp==2 || bpp==4, "TextureCache: bpp must be either 2 or 4"); CCTexture2D * texture; @@ -506,7 +513,7 @@ CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAl CCTexture2D * CCTextureCache::addPVRImage(const char* path) { - CCAssert(path != NULL, "TextureCache: fileimage MUST not be nill"); + CCAssert(path != NULL, "TextureCache: fileimage MUST not be nil"); CCTexture2D* texture = NULL; std::string key(path); @@ -539,7 +546,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path) CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key) { - CCAssert(image != NULL, "TextureCache: image MUST not be nill"); + CCAssert(image != NULL, "TextureCache: image MUST not be nil"); CCTexture2D * texture = NULL; // textureForKey() use full path,so the key should be full path diff --git a/cocos2dx/textures/CCTextureCache.h b/cocos2dx/textures/CCTextureCache.h index d21bf1a663..3f7bb1ef01 100644 --- a/cocos2dx/textures/CCTextureCache.h +++ b/cocos2dx/textures/CCTextureCache.h @@ -72,7 +72,7 @@ public: CCDictionary* snapshotTextures(); - /** Retruns ths shared instance of the cache */ + /** Returns the shared instance of the cache */ static CCTextureCache * sharedTextureCache(); /** purges the cache. It releases the retained instance. @@ -83,7 +83,7 @@ public: /** Returns a Texture2D object given an file image * If the file image was not previously loaded, it will create a new CCTexture2D * object and it will return it. It will use the filename as a key. - * Otherwise it will return a reference of a previosly loaded image. + * Otherwise it will return a reference of a previously loaded image. * Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif */ CCTexture2D* addImage(const char* fileimage); @@ -128,7 +128,7 @@ public: /** Removes unused textures * Textures that have a retain count of 1 will be deleted - * It is convinient to call this method after when starting a new Scene + * It is convenient to call this method after when starting a new Scene * @since v0.8 */ void removeUnusedTextures(); @@ -152,7 +152,7 @@ public: #ifdef CC_SUPPORT_PVRTC /** Returns a Texture2D object given an PVRTC RAW filename * If the file image was not previously loaded, it will create a new CCTexture2D - * object and it will return it. Otherwise it will return a reference of a previosly loaded image + * object and it will return it. Otherwise it will return a reference of a previously loaded image * * It can only load square images: width == height, and it must be a power of 2 (128,256,512...) * bpp can only be 2 or 4. 2 means more compression but lower quality. @@ -163,7 +163,7 @@ public: /** Returns a Texture2D object given an PVR filename * If the file image was not previously loaded, it will create a new CCTexture2D - * object and it will return it. Otherwise it will return a reference of a previosly loaded image + * object and it will return it. Otherwise it will return a reference of a previously loaded image */ CCTexture2D* addPVRImage(const char* filename); diff --git a/cocos2dx/textures/CCTexturePVR.cpp b/cocos2dx/textures/CCTexturePVR.cpp old mode 100755 new mode 100644 index 5e1e10eb78..eb28b96134 --- a/cocos2dx/textures/CCTexturePVR.cpp +++ b/cocos2dx/textures/CCTexturePVR.cpp @@ -47,7 +47,7 @@ enum { kPVRTextureFlagBumpmap = (1<<10), // has normals encoded for a bump map kPVRTextureFlagTiling = (1<<11), // is bordered for tiled pvr kPVRTextureFlagCubemap = (1<<12), // is a cubemap/skybox - kPVRTextureFlagFalseMipCol = (1<<13), // are there false coloured MIP levels + kPVRTextureFlagFalseMipCol = (1<<13), // are there false colored MIP levels kPVRTextureFlagVolume = (1<<14), // is this a volume texture kPVRTextureFlagAlpha = (1<<15), // v2.1 is there transparency info in the texture kPVRTextureFlagVerticalFlip = (1<<16), // v2.1 is the texture vertically flipped @@ -195,7 +195,7 @@ bool CCTexturePVR::unpackPVRData(unsigned char* data, unsigned int len) if (! configuration->supportsNPOT() && (header->width != ccNextPOT(header->width) || header->height != ccNextPOT(header->height))) { - CCLOG("cocos2d: ERROR: Loding an NPOT texture (%dx%d) but is not supported on this device", header->width, header->height); + CCLOG("cocos2d: ERROR: Loading an NPOT texture (%dx%d) but is not supported on this device", header->width, header->height); return false; } @@ -207,7 +207,7 @@ bool CCTexturePVR::unpackPVRData(unsigned char* data, unsigned int len) //Reset num of mipmaps m_uNumberOfMipmaps = 0; - //Get size of maimap + //Get size of mipmap m_uWidth = width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width); m_uHeight = height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height); @@ -270,14 +270,14 @@ bool CCTexturePVR::unpackPVRData(unsigned char* data, unsigned int len) unsigned int packetLength = (dataLength - dataOffset); packetLength = packetLength > dataSize ? dataSize : packetLength; - //Make record to the mipmaps array and increment coutner + //Make record to the mipmaps array and increment counter m_asMipmaps[m_uNumberOfMipmaps].address = bytes + dataOffset; m_asMipmaps[m_uNumberOfMipmaps].len = packetLength; m_uNumberOfMipmaps++; //Check that we didn't overflow CCAssert(m_uNumberOfMipmaps < CC_PVRMIPMAP_MAX, - "TexturePVR: Maximum number of mimpaps reached. Increate the CC_PVRMIPMAP_MAX value"); + "TexturePVR: Maximum number of mipmaps reached. Increase the CC_PVRMIPMAP_MAX value"); dataOffset += packetLength; diff --git a/cocos2dx/textures/CCTexturePVR.h b/cocos2dx/textures/CCTexturePVR.h index 2893cf3c93..6ebb031b0e 100644 --- a/cocos2dx/textures/CCTexturePVR.h +++ b/cocos2dx/textures/CCTexturePVR.h @@ -39,7 +39,7 @@ NS_CC_BEGIN */ /** - @brief Structure which can tell where mimap begins and how long is it + @brief Structure which can tell where mipmap begins and how long is it */ struct CCPVRMipmap { unsigned char *address; @@ -47,7 +47,7 @@ struct CCPVRMipmap { }; /** - @brief Detemine how many mipmaps can we have. + @brief Determine how many mipmaps can we have. Its same as define but it respects namespaces */ enum { diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp index 91cc21bd7b..a45d7a900d 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp @@ -199,7 +199,7 @@ void CCTMXLayer::setupTiles() } CCAssert( m_uMaxGID >= m_pTileSet->m_uFirstGid && - m_uMinGID >= m_pTileSet->m_uFirstGid, "TMX: Only 1 tilset per layer is supported"); + m_uMinGID >= m_pTileSet->m_uFirstGid, "TMX: Only 1 tileset per layer is supported"); } // CCTMXLayer - Properties @@ -306,7 +306,7 @@ CCSprite* CCTMXLayer::reusedTileWithRect(CCRect rect) } else { - // XXX: should not be re-init. Potential memeory leak. Not following best practices + // XXX: should not be re-init. Potential memory leak. Not following best practices // XXX: it shall call directory [setRect:rect] m_pReusedTile->initWithTexture(m_pobTextureAtlas->getTexture(), rect, false); diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h index 018193f690..0ebfc48206 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h @@ -53,12 +53,12 @@ If the layer contains a property named "cc_vertexz" with an integer (in can be p then all the tiles belonging to the layer will use that value as their OpenGL vertex Z for depth. On the other hand, if the "cc_vertexz" property has the "automatic" value, then the tiles will use an automatic vertex Z value. -Also before drawing the tiles, GL_ALPHA_TEST will be enabled, and disabled after drawin them. The used alpha func will be: +Also before drawing the tiles, GL_ALPHA_TEST will be enabled, and disabled after drawing them. The used alpha func will be: glAlphaFunc( GL_GREATER, value ) "value" by default is 0, but you can change it from Tiled by adding the "cc_alpha_func" property to the layer. -The value 0 should work for most cases, but if you have tiles that are semi-transparent, then you might want to use a differnt +The value 0 should work for most cases, but if you have tiles that are semi-transparent, then you might want to use a different value, like 0.5. For further information, please see the programming guide: @@ -75,11 +75,11 @@ class CC_DLL CCTMXLayer : public CCSpriteBatchNode { /** size of the layer in tiles */ CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tLayerSize, LayerSize); - /** size of the map's tile (could be differnt from the tile's size) */ + /** size of the map's tile (could be different from the tile's size) */ CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tMapTileSize, MapTileSize); /** pointer to the map of tiles */ CC_SYNTHESIZE(unsigned int*, m_pTiles, Tiles); - /** Tilset information for the layer */ + /** Tileset information for the layer */ CC_PROPERTY(CCTMXTilesetInfo*, m_pTileSet, TileSet); /** Layer orientation, which is the same as the map orientation */ CC_SYNTHESIZE(unsigned int, m_uLayerOrientation, LayerOrientation); @@ -168,7 +168,7 @@ private: CCPoint calculateLayerOffset(const CCPoint& offset); - /* optimization methos */ + /* optimization methods */ CCSprite* appendTileForGID(unsigned int gid, const CCPoint& pos); CCSprite* insertTileForGID(unsigned int gid, const CCPoint& pos); CCSprite* updateTileForGID(unsigned int gid, const CCPoint& pos); diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXTiledMap.h b/cocos2dx/tilemap_parallax_nodes/CCTMXTiledMap.h index a1013dfd8b..6e672cd625 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXTiledMap.h +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXTiledMap.h @@ -42,7 +42,7 @@ class CCTMXMapInfo; * @{ */ -/** Possible oritentations of the TMX map */ +/** Possible orientations of the TMX map */ enum { /** Orthogonal orientation */ @@ -64,7 +64,7 @@ It also supports object groups, objects, and properties. Features: - Each tile will be treated as an CCSprite - The sprites are created on demand. They will be created only when you call "layer->tileAt(position)" -- Each tile can be rotated / moved / scaled / tinted / "opacitied", since each tile is a CCSprite +- Each tile can be rotated / moved / scaled / tinted / "opaqued", since each tile is a CCSprite - Tiles can be added/removed in runtime - The z-order of the tiles can be modified in runtime - Each tile has an anchorPoint of (0,0) @@ -80,7 +80,7 @@ Features: Limitations: - It only supports one tileset per layer. -- Embeded images are not supported +- Embedded images are not supported - It only supports the XML format (the JSON format is not supported) Technical description: @@ -147,7 +147,7 @@ public: /** return the TMXLayer for the specific layer */ CCTMXLayer* layerNamed(const char *layerName); - /** return the TMXObjectGroup for the secific group */ + /** return the TMXObjectGroup for the specific group */ CCTMXObjectGroup* objectGroupNamed(const char *groupName); /** return the value for the specific property name */ diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp index 41a43e057d..b11d4812d7 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.cpp @@ -43,7 +43,7 @@ using namespace std; #include #include #include -#endf +#endif */ NS_CC_BEGIN @@ -453,7 +453,7 @@ void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts) } else { - tileset->m_sSourceImage = m_sResources + "/" + imagename; + tileset->m_sSourceImage = m_sResources + (m_sResources.size() ? "/" : "") + imagename; } } else if(elementName == "data") @@ -652,7 +652,7 @@ void CCTMXMapInfo::endElement(void *ctx, const char *name) int inflatedLen = ZipUtils::ccInflateMemoryWithHint(buffer, len, &deflated, sizeHint); CCAssert(inflatedLen == sizeHint, ""); - inflatedLen = (size_t)&inflatedLen; // XXX: to avoid warings in compiler + inflatedLen = (size_t)&inflatedLen; // XXX: to avoid warnings in compiler delete [] buffer; buffer = NULL; diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.h b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.h index fddc70fc2a..c1fe4522bf 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.h +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.h @@ -106,7 +106,7 @@ public: /** @brief CCTMXTilesetInfo contains the information about the tilesets like: - Tileset name -- Tilset spacing +- Tileset spacing - Tileset margin - size of the tiles - Image used for the tiles @@ -166,7 +166,7 @@ public: CC_SYNTHESIZE(unsigned int, m_uParentGID, ParentGID); /// layer attribs CC_SYNTHESIZE(int, m_nLayerAttribs, LayerAttribs); - /// is stroing characters? + /// is storing characters? CC_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters); /// properties CC_PROPERTY(CCDictionary*, m_pProperties, Properties); @@ -177,13 +177,13 @@ public: static CCTMXMapInfo * formatWithTMXFile(const char *tmxFile); /** creates a TMX Format with an XML string and a TMX resource path */ static CCTMXMapInfo * formatWithXML(const char* tmxString, const char* resourcePath); - /** initializes a TMX format witha tmx file */ + /** initializes a TMX format with a tmx file */ bool initWithTMXFile(const char *tmxFile); /** initializes a TMX format with an XML string and a TMX resource path */ bool initWithXML(const char* tmxString, const char* resourcePath); - /** initalises parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file */ + /** initializes parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file */ bool parseXMLFile(const char *xmlFilename); - /* initalises parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */ + /* initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */ bool parseXMLString(const char *xmlString); CCDictionary* getTileProperties(); diff --git a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp index 8a1b885aae..0b3f375425 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.cpp @@ -131,7 +131,7 @@ void CCTileMapAtlas::loadTGAfile(const char *file) #if 1 if( m_pTGAInfo->status != TGA_OK ) { - CCAssert(0, "TileMapAtlasLoadTGA : TileMapAtas cannot load TGA file"); + CCAssert(0, "TileMapAtlasLoadTGA : TileMapAtlas cannot load TGA file"); } #endif } @@ -156,7 +156,7 @@ void CCTileMapAtlas::setTile(const ccColor3B& tile, const ccGridSize& position) ptr[position.x + position.y * m_pTGAInfo->width] = tile; // XXX: this method consumes a lot of memory - // XXX: a tree of something like that shall be impolemented + // XXX: a tree of something like that shall be implemented CCInteger *num = (CCInteger*)m_pPosToAtlasIndex->objectForKey(CCString::createWithFormat("%ld,%ld", (long)position.x, (long)position.y)->getCString()); diff --git a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.h b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.h index 822b4b34ef..0994166cd8 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.h +++ b/cocos2dx/tilemap_parallax_nodes/CCTileMapAtlas.h @@ -93,7 +93,7 @@ private: void updateAtlasValues(); protected: - //! x,y to altas dicctionary + //! x,y to atlas dictionary CCDictionary* m_pPosToAtlasIndex; //! numbers of tiles to render int m_nItemsToRender; diff --git a/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h b/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h index 6770d1e421..4565ae52a4 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h +++ b/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h @@ -72,7 +72,7 @@ public: them. You get exactly one UITouch per call. - 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed touches are sent only to the delegate(s) that claimed them. So if you get a move/ - ended/cancelled update you're sure it's your touch. This frees you from doing a + ended/canceled update you're sure it's your touch. This frees you from doing a lot of checks when doing multi-touch. (The name TargetedTouchDelegate relates to updates "targeting" their specific @@ -94,7 +94,7 @@ public: }; /** @brief - This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Cancelled). + This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Canceled). @since v0.8 */ class CC_DLL CCStandardTouchDelegate : public CCTouchDelegate diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp index e37f3d053d..315b1a14d9 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp @@ -136,7 +136,7 @@ void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPri } else { - /* If pHandler is contained in m_pHandlersToRemove, if so remove it from m_pHandlersToRemove and retrun. + /* If pHandler is contained in m_pHandlersToRemove, if so remove it from m_pHandlersToRemove and return. * Refer issue #752(cocos2d-x) */ if (ccCArrayContainsValue(m_pHandlersToRemove, pDelegate)) @@ -159,7 +159,7 @@ void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPri } else { - /* If pHandler is contained in m_pHandlersToRemove, if so remove it from m_pHandlersToRemove and retrun. + /* If pHandler is contained in m_pHandlersToRemove, if so remove it from m_pHandlersToRemove and return. * Refer issue #752(cocos2d-x) */ if (ccCArrayContainsValue(m_pHandlersToRemove, pDelegate)) @@ -216,7 +216,7 @@ void CCTouchDispatcher::removeDelegate(CCTouchDelegate *pDelegate) } else { - /* If pHandler is contained in m_pHandlersToAdd, if so remove it from m_pHandlersToAdd and retrun. + /* If pHandler is contained in m_pHandlersToAdd, if so remove it from m_pHandlersToAdd and return. * Refer issue #752(cocos2d-x) */ CCTouchHandler *pHandler = findHandler(m_pHandlersToAdd, pDelegate); @@ -365,7 +365,7 @@ void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int u } else if (pHandler->getClaimedTouches()->containsObject(pTouch)) { - // moved ended cancelled + // moved ended canceled bClaimed = true; switch (sHelper.m_type) diff --git a/cocos2dx/touch_dispatcher/CCTouchHandler.h b/cocos2dx/touch_dispatcher/CCTouchHandler.h index 89b9d02a2a..1b6eb222c1 100644 --- a/cocos2dx/touch_dispatcher/CCTouchHandler.h +++ b/cocos2dx/touch_dispatcher/CCTouchHandler.h @@ -73,7 +73,7 @@ protected: }; /** CCStandardTouchHandler - It forwardes each event to the delegate. + It forwards each event to the delegate. */ class CC_DLL CCStandardTouchHandler : public CCTouchHandler { @@ -88,7 +88,7 @@ public: /** CCTargetedTouchHandler - Object than contains the claimed touches and if it swallos touches. + Object than contains the claimed touches and if it swallows touches. Used internally by TouchDispatcher */ class CC_DLL CCTargetedTouchHandler : public CCTouchHandler diff --git a/extensions/network/HttpClient.cpp b/extensions/network/HttpClient.cpp index bde526ed21..c35126d856 100644 --- a/extensions/network/HttpClient.cpp +++ b/extensions/network/HttpClient.cpp @@ -74,12 +74,10 @@ size_t writeData(void *ptr, size_t size, size_t nmemb, void *stream) { std::vector *recvBuffer = (std::vector*)stream; size_t sizes = size * nmemb; - - recvBuffer->clear(); - // someone reported a bug of losting data potentially here - // use recvBuffer->insert(recvBuffer->end(), (char*)ptr, (char*)ptr+sizes); can resolve. - recvBuffer->assign((char*)ptr, (char*)ptr + sizes); + // add data to the end of recvBuffer + // write data maybe called more than once in a single request + recvBuffer->insert(recvBuffer->end(), (char*)ptr, (char*)ptr+sizes); return sizes; } diff --git a/extensions/network/HttpClient.h b/extensions/network/HttpClient.h index 67b91ebaf0..c63d32042a 100644 --- a/extensions/network/HttpClient.h +++ b/extensions/network/HttpClient.h @@ -55,6 +55,7 @@ public: /** * Add a get request to task queue * @param request a CCHttpRequest object, which includes url, response callback etc. + please make sure request->_requestData is clear before calling "send" here. * @return NULL */ void send(CCHttpRequest* request); diff --git a/samples/HelloCpp/Classes/HelloWorldScene.h b/samples/HelloCpp/Classes/HelloWorldScene.h index e202b8c2c3..654c107b3e 100644 --- a/samples/HelloCpp/Classes/HelloWorldScene.h +++ b/samples/HelloCpp/Classes/HelloWorldScene.h @@ -9,7 +9,7 @@ public: // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual bool init(); - // there's no 'id' in cpp, so we recommand to return the exactly class pointer + // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d::CCScene* scene(); // a selector callback diff --git a/samples/HelloLua/Classes/AppDelegate.cpp b/samples/HelloLua/Classes/AppDelegate.cpp index 8acf19b0db..21ca3dcefc 100644 --- a/samples/HelloLua/Classes/AppDelegate.cpp +++ b/samples/HelloLua/Classes/AppDelegate.cpp @@ -38,7 +38,7 @@ bool AppDelegate::applicationDidFinishLaunching() pDirector->setAnimationInterval(1.0 / 60); // register lua engine - CCScriptEngineProtocol* pEngine = CCLuaEngine::engine(); + CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) diff --git a/samples/HelloLua/Resources/hello.lua b/samples/HelloLua/Resources/hello.lua index ce3c4df576..4bbd577856 100644 --- a/samples/HelloLua/Resources/hello.lua +++ b/samples/HelloLua/Resources/hello.lua @@ -1,188 +1,200 @@ --- avoid memory leak -collectgarbage("setpause", 100) -collectgarbage("setstepmul", 5000) - -local cclog = function(...) - print(string.format(...)) +-- for CCLuaEngine traceback +function __G__TRACKBACK__(msg) + print("----------------------------------------") + print("LUA ERROR: " .. tostring(msg) .. "\n") + print(debug.traceback()) + print("----------------------------------------") end -require "hello2" -cclog("result is " .. myadd(3, 5)) +local function main() + -- avoid memory leak + collectgarbage("setpause", 100) + collectgarbage("setstepmul", 5000) ---------------- - -local winSize = CCDirector:sharedDirector():getWinSize() - --- add the moving dog -local function creatDog() - local frameWidth = 105 - local frameHeight = 95 - - -- create dog animate - local textureDog = CCTextureCache:sharedTextureCache():addImage("dog.png") - local rect = CCRectMake(0, 0, frameWidth, frameHeight) - local frame0 = CCSpriteFrame:createWithTexture(textureDog, rect) - rect = CCRectMake(frameWidth, 0, frameWidth, frameHeight) - local frame1 = CCSpriteFrame:createWithTexture(textureDog, rect) - - local spriteDog = CCSprite:createWithSpriteFrame(frame0) - spriteDog.isPaused = false - spriteDog:setPosition(0, winSize.height / 4 * 3) - - local animFrames = CCArray:create(2) - - animFrames:addObject(frame0) - animFrames:addObject(frame1) - - local animation = CCAnimation:create(animFrames, 0.5) - local animate = CCAnimate:create(animation); - spriteDog:runAction(CCRepeatForever:create(animate)) - - -- moving dog at every frame - local function tick() - if spriteDog.isPaused then return end - local x, y = spriteDog:getPosition() - if x > winSize.width then - x = 0 - else - x = x + 1 - end - - spriteDog:setPositionX(x) + local cclog = function(...) + print(string.format(...)) end - CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(tick, 0, false) + require "hello2" + cclog("result is " .. myadd(3, 5)) - return spriteDog -end + --------------- --- create farm -local function createLayerFarm() - local layerFarm = CCLayer:create() + local winSize = CCDirector:sharedDirector():getWinSize() - -- add in farm background - local bg = CCSprite:create("farm.jpg") - bg:setPosition(winSize.width / 2 + 80, winSize.height / 2) - layerFarm:addChild(bg) + -- add the moving dog + local function creatDog() + local frameWidth = 105 + local frameHeight = 95 - -- add land sprite - for i = 0, 3 do - for j = 0, 1 do - local spriteLand = CCSprite:create("land.png") - spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2) - layerFarm:addChild(spriteLand) - end - end + -- create dog animate + local textureDog = CCTextureCache:sharedTextureCache():addImage("dog.png") + local rect = CCRectMake(0, 0, frameWidth, frameHeight) + local frame0 = CCSpriteFrame:createWithTexture(textureDog, rect) + rect = CCRectMake(frameWidth, 0, frameWidth, frameHeight) + local frame1 = CCSpriteFrame:createWithTexture(textureDog, rect) - -- add crop - local frameCrop = CCSpriteFrame:create("crop.png", CCRectMake(0, 0, 105, 95)) - for i = 0, 3 do - for j = 0, 1 do - local spriteCrop = CCSprite:createWithSpriteFrame(frameCrop); - spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2) - layerFarm:addChild(spriteCrop) - end - end - - -- add moving dog - local spriteDog = creatDog() - layerFarm:addChild(spriteDog) - - -- handing touch events - local touchBeginPoint = nil - - local function onTouchBegan(x, y) - cclog("onTouchBegan: %0.2f, %0.2f", x, y) - touchBeginPoint = {x = x, y = y} - spriteDog.isPaused = true - -- CCTOUCHBEGAN event must return true - return true - end - - local function onTouchMoved(x, y) - cclog("onTouchMoved: %0.2f, %0.2f", x, y) - if touchBeginPoint then - local cx, cy = layerFarm:getPosition() - layerFarm:setPosition(cx + x - touchBeginPoint.x, - cy + y - touchBeginPoint.y) - touchBeginPoint = {x = x, y = y} - end - end - - local function onTouchEnded(x, y) - cclog("onTouchEnded: %0.2f, %0.2f", x, y) - touchBeginPoint = nil + local spriteDog = CCSprite:createWithSpriteFrame(frame0) spriteDog.isPaused = false - end + spriteDog:setPosition(0, winSize.height / 4 * 3) - local function onTouch(eventType, x, y) - if eventType == CCTOUCHBEGAN then - return onTouchBegan(x, y) - elseif eventType == CCTOUCHMOVED then - return onTouchMoved(x, y) - else - return onTouchEnded(x, y) + local animFrames = CCArray:create() + + animFrames:addObject(frame0) + animFrames:addObject(frame1) + + local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.5) + local animate = CCAnimate:create(animation); + spriteDog:runAction(CCRepeatForever:create(animate)) + + -- moving dog at every frame + local function tick() + if spriteDog.isPaused then return end + local x, y = spriteDog:getPosition() + if x > winSize.width then + x = 0 + else + x = x + 1 + end + + spriteDog:setPositionX(x) end + + CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(tick, 0, false) + + return spriteDog end - layerFarm:registerScriptTouchHandler(onTouch) - layerFarm:setTouchEnabled(true) + -- create farm + local function createLayerFarm() + local layerFarm = CCLayer:create() - return layerFarm -end + -- add in farm background + local bg = CCSprite:create("farm.jpg") + bg:setPosition(winSize.width / 2 + 80, winSize.height / 2) + layerFarm:addChild(bg) + + -- add land sprite + for i = 0, 3 do + for j = 0, 1 do + local spriteLand = CCSprite:create("land.png") + spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2) + layerFarm:addChild(spriteLand) + end + end + + -- add crop + local frameCrop = CCSpriteFrame:create("crop.png", CCRectMake(0, 0, 105, 95)) + for i = 0, 3 do + for j = 0, 1 do + local spriteCrop = CCSprite:createWithSpriteFrame(frameCrop); + spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2) + layerFarm:addChild(spriteCrop) + end + end + + -- add moving dog + local spriteDog = creatDog() + layerFarm:addChild(spriteDog) + + -- handing touch events + local touchBeginPoint = nil + + local function onTouchBegan(x, y) + cclog("onTouchBegan: %0.2f, %0.2f", x, y) + touchBeginPoint = {x = x, y = y} + spriteDog.isPaused = true + -- CCTOUCHBEGAN event must return true + return true + end + + local function onTouchMoved(x, y) + -- cclog("onTouchMoved: %0.2f, %0.2f", x, y) + if touchBeginPoint then + local cx, cy = layerFarm:getPosition() + layerFarm:setPosition(cx + x - touchBeginPoint.x, + cy + y - touchBeginPoint.y) + touchBeginPoint = {x = x, y = y} + end + end + + local function onTouchEnded(x, y) + cclog("onTouchEnded: %0.2f, %0.2f", x, y) + touchBeginPoint = nil + spriteDog.isPaused = false + end + + local function onTouch(eventType, x, y) + if eventType == CCTOUCHBEGAN then + return onTouchBegan(x, y) + elseif eventType == CCTOUCHMOVED then + return onTouchMoved(x, y) + else + return onTouchEnded(x, y) + end + end + + layerFarm:registerScriptTouchHandler(onTouch) + layerFarm:setTouchEnabled(true) + + return layerFarm + end --- create menu -local function createLayerMenu() - local layerMenu = CCLayer:create() + -- create menu + local function createLayerMenu() + local layerMenu = CCLayer:create() - local menuPopup, menuTools, effectID + local menuPopup, menuTools, effectID - local function menuCallbackClosePopup() - -- stop test sound effect - SimpleAudioEngine:sharedEngine():stopEffect(effectID) + local function menuCallbackClosePopup() + -- stop test sound effect + SimpleAudioEngine:sharedEngine():stopEffect(effectID) + menuPopup:setVisible(false) + end + + local function menuCallbackOpenPopup() + -- loop test sound effect + local effectPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("effect1.wav") + effectID = SimpleAudioEngine:sharedEngine():playEffect(effectPath) + menuPopup:setVisible(true) + end + + -- add a popup menu + local menuPopupItem = CCMenuItemImage:create("menu2.png", "menu2.png") + menuPopupItem:setPosition(0, 0) + menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) + menuPopup = CCMenu:createWithItem(menuPopupItem) + menuPopup:setPosition(winSize.width / 2, winSize.height / 2) menuPopup:setVisible(false) + layerMenu:addChild(menuPopup) + + -- add the left-bottom "tools" menu to invoke menuPopup + local menuToolsItem = CCMenuItemImage:create("menu1.png", "menu1.png") + menuToolsItem:setPosition(0, 0) + menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) + menuTools = CCMenu:createWithItem(menuToolsItem) + menuTools:setPosition(30, 40) + layerMenu:addChild(menuTools) + + return layerMenu end - local function menuCallbackOpenPopup() - -- loop test sound effect - local effectPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("effect1.wav") - effectID = SimpleAudioEngine:sharedEngine():playEffect(effectPath) - menuPopup:setVisible(true) - end + -- play background music, preload effect - -- add a popup menu - local menuPopupItem = CCMenuItemImage:create("menu2.png", "menu2.png") - menuPopupItem:setPosition(0, 0) - menuPopupItem:registerScriptHandler(menuCallbackClosePopup) - menuPopup = CCMenu:createWithItem(menuPopupItem) - menuPopup:setPosition(winSize.width / 2, winSize.height / 2) - menuPopup:setVisible(false) - layerMenu:addChild(menuPopup) + -- uncomment below for the BlackBerry version + -- local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("background.ogg") + local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("background.mp3") + SimpleAudioEngine:sharedEngine():playBackgroundMusic(bgMusicPath, true) + local effectPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("effect1.wav") + SimpleAudioEngine:sharedEngine():preloadEffect(effectPath) - -- add the left-bottom "tools" menu to invoke menuPopup - local menuToolsItem = CCMenuItemImage:create("menu1.png", "menu1.png") - menuToolsItem:setPosition(0, 0) - menuToolsItem:registerScriptHandler(menuCallbackOpenPopup) - menuTools = CCMenu:createWithItem(menuToolsItem) - menuTools:setPosition(30, 40) - layerMenu:addChild(menuTools) - - return layerMenu + -- run + local sceneGame = CCScene:create() + sceneGame:addChild(createLayerFarm()) + sceneGame:addChild(createLayerMenu()) + CCDirector:sharedDirector():runWithScene(sceneGame) end --- play background music, preload effect - --- uncomment below for the BlackBerry version --- local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("background.ogg") -local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("background.mp3") -SimpleAudioEngine:sharedEngine():playBackgroundMusic(bgMusicPath, true) -local effectPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("effect1.wav") -SimpleAudioEngine:sharedEngine():preloadEffect(effectPath) - --- run -local sceneGame = CCScene:create() -sceneGame:addChild(createLayerFarm()) -sceneGame:addChild(createLayerMenu()) -CCDirector:sharedDirector():runWithScene(sceneGame) +xpcall(main, __G__TRACKBACK__) diff --git a/samples/TestJavascript/proj.android/ant.properties b/samples/TestJavascript/proj.android/ant.properties index ce44c76b37..f8af38bfb4 100644 --- a/samples/TestJavascript/proj.android/ant.properties +++ b/samples/TestJavascript/proj.android/ant.properties @@ -1 +1 @@ -aapt.ignore.assets="!*.pvr.gz:!*.gz:!Images:!Fonts:!.svn:!.git:.*:_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" +aapt.ignore.assets="!*.pvr.gz:!*.gz:!.svn:!.git:.*:_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" diff --git a/samples/TestJavascript/proj.android/jni/Android.mk b/samples/TestJavascript/proj.android/jni/Android.mk index 6e516fc376..05af70ea6e 100644 --- a/samples/TestJavascript/proj.android/jni/Android.mk +++ b/samples/TestJavascript/proj.android/jni/Android.mk @@ -24,5 +24,5 @@ include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,CocosDenshion/android) $(call import-module,external/chipmunk) -$(call import-module,scripting/javascript/spidermonkey-android/android) +$(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,scripting/javascript/bindings) diff --git a/samples/TestLua/Classes/AppDelegate.cpp b/samples/TestLua/Classes/AppDelegate.cpp index 8eec3fbb9b..e87925fc68 100644 --- a/samples/TestLua/Classes/AppDelegate.cpp +++ b/samples/TestLua/Classes/AppDelegate.cpp @@ -33,7 +33,7 @@ bool AppDelegate::applicationDidFinishLaunching() pDirector->setAnimationInterval(1.0 / 60); // register lua engine - CCScriptEngineProtocol* pEngine = CCLuaEngine::engine(); + CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); std::string dirPath = "luaScript"; diff --git a/samples/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua b/samples/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua index 14d60ea3f0..5abfda267c 100644 --- a/samples/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua +++ b/samples/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua @@ -85,9 +85,9 @@ local function getBaseLayer() local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) local menu = CCMenu:create() menu:addChild(item1) diff --git a/samples/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua b/samples/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua index 3a538ab086..7f9cf8ed7f 100644 --- a/samples/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua +++ b/samples/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua @@ -61,9 +61,9 @@ local function initWithLayer(layer) local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) local menu = CCMenu:create() menu:addChild(item1) diff --git a/samples/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua b/samples/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua index 5836b15b06..4c0f089713 100644 --- a/samples/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua +++ b/samples/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua @@ -79,9 +79,9 @@ local function initWithLayer(layer) local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) item1:setPosition(ccp(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) item2:setPosition(ccp(size.width / 2, item2:getContentSize().height / 2)) item3:setPosition(ccp(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) diff --git a/samples/TestLua/Resources/luaScript/EffectsTest/EffectsTest.lua b/samples/TestLua/Resources/luaScript/EffectsTest/EffectsTest.lua index b995a6b72e..4d742f2a0a 100644 --- a/samples/TestLua/Resources/luaScript/EffectsTest/EffectsTest.lua +++ b/samples/TestLua/Resources/luaScript/EffectsTest/EffectsTest.lua @@ -392,9 +392,9 @@ function CreateEffectsTestLayer() local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) local menu = CCMenu:create() menu:addChild(item1) diff --git a/samples/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua b/samples/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua index 2b520dc11e..1de0f36f10 100644 --- a/samples/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua +++ b/samples/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua @@ -81,9 +81,9 @@ local function getBaseLayer() local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) local menu = CCMenu:create() menu:addChild(item1) @@ -98,7 +98,7 @@ local function getBaseLayer() local itemMode = CCMenuItemToggle:create(CCMenuItemFont:create("Use High Quality Mode")) itemMode:addSubItem(CCMenuItemFont:create("Use Fast Mode")) - itemMode:registerScriptHandler(modeCallback) + itemMode:registerScriptTapHandler(modeCallback) local menuMode = CCMenu:create() menuMode:addChild(itemMode) menuMode:setPosition(ccp(s.width / 2, s.height / 4)) diff --git a/samples/TestLua/Resources/luaScript/NodeTest/NodeTest.lua b/samples/TestLua/Resources/luaScript/NodeTest/NodeTest.lua index fbc5e4048a..5a397e5886 100644 --- a/samples/TestLua/Resources/luaScript/NodeTest/NodeTest.lua +++ b/samples/TestLua/Resources/luaScript/NodeTest/NodeTest.lua @@ -73,9 +73,9 @@ local function getBaseLayer() local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) local menu = CCMenu:create() menu:addChild(item1) diff --git a/samples/TestLua/Resources/luaScript/ParticleTest/ParticleTest.lua b/samples/TestLua/Resources/luaScript/ParticleTest/ParticleTest.lua index 55d2928ed0..ee60d1dcd4 100644 --- a/samples/TestLua/Resources/luaScript/ParticleTest/ParticleTest.lua +++ b/samples/TestLua/Resources/luaScript/ParticleTest/ParticleTest.lua @@ -113,10 +113,10 @@ local function getBaseLayer() local item4 = CCMenuItemToggle:create(CCMenuItemFont:create("Free Movement")) item4:addSubItem(CCMenuItemFont:create("Relative Movement")) item4:addSubItem(CCMenuItemFont:create("Grouped Movement")) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) - item4:registerScriptHandler(toggleCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) + item4:registerScriptTapHandler(toggleCallback) local menu = CCMenu:create() menu:addChild(item1) diff --git a/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceSpriteTest.lua b/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceSpriteTest.lua index 4b064e33d3..3bf61fd67e 100644 --- a/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceSpriteTest.lua +++ b/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceSpriteTest.lua @@ -247,7 +247,7 @@ local function initWithLayer(layer, controlMenuVisible) CCMenuItemFont:setFontName("Arial") CCMenuItemFont:setFontSize(24) local mainItem = CCMenuItemFont:create("Back") - mainItem:registerScriptHandler(toPerformanceMainLayer) + mainItem:registerScriptTapHandler(toPerformanceMainLayer) mainItem:setPosition(s.width - 50, 25) local menu = CCMenu:create() menu:addChild(mainItem) @@ -257,9 +257,9 @@ local function initWithLayer(layer, controlMenuVisible) local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) item1:setPosition(s.width / 2 - 100, 30) item2:setPosition(s.width / 2, 30) item3:setPosition(s.width / 2 + 100, 30) @@ -344,10 +344,10 @@ local function initWithMainTest(scene, asubtest, nNodes) CCMenuItemFont:setFontSize(65) local decrease = CCMenuItemFont:create(" - ") - decrease:registerScriptHandler(onDecrease) + decrease:registerScriptTapHandler(onDecrease) decrease:setColor(ccc3(0, 200, 20)) local increase = CCMenuItemFont:create(" + ") - increase:registerScriptHandler(onIncrease) + increase:registerScriptTapHandler(onIncrease) increase:setColor(ccc3(0, 200, 20)) local menu = CCMenu:create() @@ -370,7 +370,7 @@ local function initWithMainTest(scene, asubtest, nNodes) for i = 1, 9 do local str = i .. " " local itemFont = CCMenuItemFont:create(str) - itemFont:registerScriptHandler(testNCallback) + itemFont:registerScriptTapHandler(testNCallback) --itemFont:setTag(i) subMenu:addChild(itemFont, kBasicZOrder + i, kBasicZOrder + i) diff --git a/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceTest.lua b/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceTest.lua index 6d8ee41fe6..06615710a8 100644 --- a/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceTest.lua +++ b/samples/TestLua/Resources/luaScript/PerformanceTest/PerformanceTest.lua @@ -47,7 +47,7 @@ local function PerformanceMainLayer() CCMenuItemFont:setFontSize(24) for i = 0, MAX_COUNT - 1 do local item = CCMenuItemFont:create(testsName[i]) - item:registerScriptHandler(menuCallback) + item:registerScriptTapHandler(menuCallback) item:setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE) menu:addChild(item, kItemTagBasic + i, kItemTagBasic + i) end diff --git a/samples/TestLua/Resources/luaScript/TransitionsTest/TransitionsTest.lua b/samples/TestLua/Resources/luaScript/TransitionsTest/TransitionsTest.lua index 583b4c8442..c265bf626e 100644 --- a/samples/TestLua/Resources/luaScript/TransitionsTest/TransitionsTest.lua +++ b/samples/TestLua/Resources/luaScript/TransitionsTest/TransitionsTest.lua @@ -76,9 +76,9 @@ local function createLayer1() local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) local menu = CCMenu:create() menu:addChild(item1) @@ -119,9 +119,9 @@ local function createLayer2() local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptHandler(backCallback) - item2:registerScriptHandler(restartCallback) - item3:registerScriptHandler(nextCallback) + item1:registerScriptTapHandler(backCallback) + item2:registerScriptTapHandler(restartCallback) + item3:registerScriptTapHandler(nextCallback) local menu = CCMenu:create() menu:addChild(item1) diff --git a/samples/TestLua/Resources/luaScript/helper.lua b/samples/TestLua/Resources/luaScript/helper.lua index fa8fe0b9e2..e95796e5b9 100644 --- a/samples/TestLua/Resources/luaScript/helper.lua +++ b/samples/TestLua/Resources/luaScript/helper.lua @@ -25,7 +25,7 @@ end function CreateBackMenuItem() local label = CCLabelTTF:create("MainMenu", "Arial", 20) local MenuItem = CCMenuItemLabel:create(label) - MenuItem:registerScriptHandler(MainMenuCallback) + MenuItem:registerScriptTapHandler(MainMenuCallback) local s = CCDirector:sharedDirector():getWinSize() local Menu = CCMenu:create() diff --git a/samples/TestLua/Resources/luaScript/mainMenu.lua b/samples/TestLua/Resources/luaScript/mainMenu.lua index 9f433e6352..022e6a2609 100644 --- a/samples/TestLua/Resources/luaScript/mainMenu.lua +++ b/samples/TestLua/Resources/luaScript/mainMenu.lua @@ -131,6 +131,7 @@ function CreateTestMenu() end local function menuCallback(tag) + print(tag) local Idx = tag - 10000 local testScene = CreateTestScene(Idx) if testScene then @@ -141,7 +142,7 @@ function CreateTestMenu() -- add close menu local s = CCDirector:sharedDirector():getWinSize() local CloseItem = CCMenuItemImage:create(s_pPathClose, s_pPathClose) - CloseItem:registerScriptHandler(closeCallback) + CloseItem:registerScriptTapHandler(closeCallback) CloseItem:setPosition(ccp(s.width - 30, s.height - 30)) local CloseMenu = CCMenu:create() @@ -155,7 +156,7 @@ function CreateTestMenu() local testLabel = CCLabelTTF:create(labelName, "Arial", 24) local testMenuItem = CCMenuItemLabel:create(testLabel) - testMenuItem:registerScriptHandler(menuCallback) + testMenuItem:registerScriptTapHandler(menuCallback) testMenuItem:setPosition(ccp(s.width / 2, (s.height - (index + 1) * LINE_SPACE))) MainMenu:addChild(testMenuItem, index + 10000, index + 10000) end diff --git a/scripting/javascript/bindings/Android.mk b/scripting/javascript/bindings/Android.mk index d29233d8c3..1ecdfb1099 100644 --- a/scripting/javascript/bindings/Android.mk +++ b/scripting/javascript/bindings/Android.mk @@ -31,6 +31,6 @@ LOCAL_LDLIBS += -llog include $(BUILD_STATIC_LIBRARY) -$(call import-module,scripting/javascript/spidermonkey-android/android) +$(call import-module,scripting/javascript/spidermonkey-android) $(call import-module,cocos2dx) $(call import-module,external/chipmunk) diff --git a/scripting/javascript/bindings/ScriptingCore.cpp b/scripting/javascript/bindings/ScriptingCore.cpp index 8ae8ad0984..d516ba38bd 100644 --- a/scripting/javascript/bindings/ScriptingCore.cpp +++ b/scripting/javascript/bindings/ScriptingCore.cpp @@ -51,6 +51,78 @@ static void executeJSFunctionFromReservedSpot(JSContext *cx, JSObject *obj, // } } +static void getTouchesFuncName(int eventType, std::string &funcName) { + switch(eventType) { + case CCTOUCHBEGAN: + funcName = "onTouchesBegan"; + break; + case CCTOUCHENDED: + funcName = "onTouchesEnded"; + break; + case CCTOUCHMOVED: + funcName = "onTouchesMoved"; + break; + case CCTOUCHCANCELLED: + funcName = "onTouchesCancelled"; + break; + } + +} + +static void getTouchFuncName(int eventType, std::string &funcName) { + switch(eventType) { + case CCTOUCHBEGAN: + funcName = "onTouchBegan"; + break; + case CCTOUCHENDED: + funcName = "onTouchEnded"; + break; + case CCTOUCHMOVED: + funcName = "onTouchMoved"; + break; + case CCTOUCHCANCELLED: + funcName = "onTouchCancelled"; + break; + } + +} + +static void rootObject(JSContext *cx, JSObject *obj) { + JS_AddNamedObjectRoot(cx, &obj, "unnamed"); +} + + +static void unRootObject(JSContext *cx, JSObject *obj) { + JS_RemoveObjectRoot(cx, &obj); +} + +static void getJSTouchObject(JSContext *cx, CCTouch *x, jsval &jsret) { + js_type_class_t *classType; + TypeTest t; + uint32_t typeId = t.s_id(); + HASH_FIND_INT(_js_global_type_ht, &typeId, classType); + assert(classType); + JSObject *_tmp = JS_NewObject(cx, classType->jsclass, classType->proto, classType->parentProto); + js_proxy_t *proxy, *nproxy; + JS_NEW_PROXY(proxy, x, _tmp); + void *ptr = x; + JS_GET_PROXY(nproxy, ptr); + JS_AddNamedObjectRoot(cx, &nproxy->obj, "CCTouch"); + jsret = OBJECT_TO_JSVAL(_tmp); +} + +static void removeJSTouchObject(JSContext *cx, CCTouch *x, jsval &jsret) { + js_proxy_t* nproxy; + js_proxy_t* jsproxy; + void *ptr = x; + JS_GET_PROXY(nproxy, ptr); + if (nproxy) { + JS_RemoveObjectRoot(cx, &nproxy->obj); + JS_GET_NATIVE_PROXY(jsproxy, nproxy->obj); + JS_REMOVE_PROXY(nproxy, jsproxy); + } +} + void ScriptingCore::executeJSFunctionWithThisObj(jsval thisObj, jsval callback, jsval data) { jsval retval; @@ -288,11 +360,11 @@ JSBool ScriptingCore::log(JSContext* cx, uint32_t argc, jsval *vp) } -void ScriptingCore::removeJSObjectByCCObject(void* cobj) { - +void ScriptingCore::removeScriptObjectByCCObject(CCObject* pObj) +{ js_proxy_t* nproxy; js_proxy_t* jsproxy; - void *ptr = cobj; + void *ptr = (void*)pObj; JS_GET_PROXY(nproxy, ptr); if (nproxy) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); @@ -370,37 +442,116 @@ JSBool ScriptingCore::removeRootJS(JSContext *cx, uint32_t argc, jsval *vp) return JS_FALSE; } -int ScriptingCore::executeFunctionWithIntegerData(int nHandler, int data, CCNode *self) { +int ScriptingCore::executeNodeEvent(CCNode* pNode, int nAction) +{ js_proxy_t * p; - JS_GET_PROXY(p, self); - + JS_GET_PROXY(p, pNode); + if (!p) return 0; - + jsval retval; jsval dataVal = INT_TO_JSVAL(1); js_proxy_t *proxy; - JS_GET_PROXY(proxy, self); - - std::string funcName = ""; - if(data == kCCNodeOnEnter) { + JS_GET_PROXY(proxy, pNode); + + if(nAction == kCCNodeOnEnter) + { executeJSFunctionWithName(this->cx, p->obj, "onEnter", dataVal, retval); - } else if(data == kCCNodeOnExit) { + } + else if(nAction == kCCNodeOnExit) + { executeJSFunctionWithName(this->cx, p->obj, "onExit", dataVal, retval); - } else if(data == kCCMenuItemActivated) { - dataVal = (proxy ? OBJECT_TO_JSVAL(proxy->obj) : JSVAL_NULL); - executeJSFunctionFromReservedSpot(this->cx, p->obj, dataVal, retval); - } else if(data == kCCNodeOnEnterTransitionDidFinish) { - executeJSFunctionWithName(this->cx, p->obj, "onEnterTransitionDidFinish", dataVal, retval); - } else if(data == kCCNodeOnExitTransitionDidStart) { executeJSFunctionWithName(this->cx, p->obj, "onExitTransitionDidStart", dataVal, retval); } - - - + else if(nAction == kCCNodeOnEnterTransitionDidFinish) + { + executeJSFunctionWithName(this->cx, p->obj, "onEnterTransitionDidFinish", dataVal, retval); + } + else if(nAction == kCCNodeOnExitTransitionDidStart) + { + executeJSFunctionWithName(this->cx, p->obj, "onExitTransitionDidStart", dataVal, retval); + } + return 1; } +int ScriptingCore::executeMenuItemEvent(CCMenuItem* pMenuItem) +{ + js_proxy_t * p; + JS_GET_PROXY(p, pMenuItem); -int ScriptingCore::executeFunctionWithObjectData(int nHandler, const char *name, JSObject *obj, CCNode *self) { + if (!p) return 0; + + jsval retval; + jsval dataVal; + js_proxy_t *proxy; + JS_GET_PROXY(proxy, pMenuItem); + dataVal = (proxy ? OBJECT_TO_JSVAL(proxy->obj) : JSVAL_NULL); + + executeJSFunctionFromReservedSpot(this->cx, p->obj, dataVal, retval); + + return 1; +} + +int ScriptingCore::executeNotificationEvent(CCNotificationCenter* pNotificationCenter, const char* pszName) +{ + return 1; +} + +int ScriptingCore::executeCallFuncActionEvent(CCCallFunc* pAction, CCObject* pTarget/* = NULL*/) +{ + return 1; +} + +int ScriptingCore::executeSchedule(CCTimer* pTimer, float dt, CCNode* pNode/* = NULL*/) +{ + js_proxy_t * p; + JS_GET_PROXY(p, pNode); + + if (!p) return 0; + + jsval retval; + jsval dataVal = DOUBLE_TO_JSVAL(dt); + + executeJSFunctionWithName(this->cx, p->obj, "update", dataVal, retval); + + return 1; +} + +int ScriptingCore::executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches) +{ + std::string funcName = ""; + getTouchesFuncName(eventType, funcName); + + JSObject *jsretArr = JS_NewArrayObject(this->cx, 0, NULL); + + JS_AddNamedObjectRoot(this->cx, &jsretArr, "touchArray"); + int count = 0; + for(CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it, ++count) { + jsval jsret; + getJSTouchObject(this->cx, (CCTouch *) *it, jsret); + if(!JS_SetElement(this->cx, jsretArr, count, &jsret)) { + break; + } + } + + executeFunctionWithObjectData(pLayer, funcName.c_str(), jsretArr); + + JS_RemoveObjectRoot(this->cx, &jsretArr); + + for(CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it, ++count) { + jsval jsret; + removeJSTouchObject(this->cx, (CCTouch *) *it, jsret); + } + + return 1; +} + +int ScriptingCore::executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch) +{ + return 0; +} + +int ScriptingCore::executeFunctionWithObjectData(CCNode *self, const char *name, JSObject *obj) { js_proxy_t * p; JS_GET_PROXY(p, self); @@ -414,136 +565,9 @@ int ScriptingCore::executeFunctionWithObjectData(int nHandler, const char *name, return 1; } - -int ScriptingCore::executeFunctionWithFloatData(int nHandler, float data, CCNode *self) { - - - js_proxy_t * p; - JS_GET_PROXY(p, self); - - if (!p) return 0; - - jsval retval; - jsval dataVal = DOUBLE_TO_JSVAL(data); - - std::string funcName = ""; - - executeJSFunctionWithName(this->cx, p->obj, "update", dataVal, retval); - - return 1; -} - -static void getTouchesFuncName(int eventType, std::string &funcName) { - switch(eventType) { - case CCTOUCHBEGAN: - funcName = "onTouchesBegan"; - break; - case CCTOUCHENDED: - funcName = "onTouchesEnded"; - break; - case CCTOUCHMOVED: - funcName = "onTouchesMoved"; - break; - case CCTOUCHCANCELLED: - funcName = "onTouchesCancelled"; - break; - } - -} - -static void getTouchFuncName(int eventType, std::string &funcName) { - switch(eventType) { - case CCTOUCHBEGAN: - funcName = "onTouchBegan"; - break; - case CCTOUCHENDED: - funcName = "onTouchEnded"; - break; - case CCTOUCHMOVED: - funcName = "onTouchMoved"; - break; - case CCTOUCHCANCELLED: - funcName = "onTouchCancelled"; - break; - } - -} - -static void rootObject(JSContext *cx, JSObject *obj) { - JS_AddNamedObjectRoot(cx, &obj, "unnamed"); -} - - -static void unRootObject(JSContext *cx, JSObject *obj) { - JS_RemoveObjectRoot(cx, &obj); -} - - - - -static void getJSTouchObject(JSContext *cx, CCTouch *x, jsval &jsret) { - js_type_class_t *classType; - TypeTest t; - uint32_t typeId = t.s_id(); - HASH_FIND_INT(_js_global_type_ht, &typeId, classType); - assert(classType); - JSObject *_tmp = JS_NewObject(cx, classType->jsclass, classType->proto, classType->parentProto); - js_proxy_t *proxy, *nproxy; - JS_NEW_PROXY(proxy, x, _tmp); - void *ptr = x; - JS_GET_PROXY(nproxy, ptr); - JS_AddNamedObjectRoot(cx, &nproxy->obj, "CCTouch"); - jsret = OBJECT_TO_JSVAL(_tmp); -} - - -static void removeJSTouchObject(JSContext *cx, CCTouch *x, jsval &jsret) { - js_proxy_t* nproxy; - js_proxy_t* jsproxy; - void *ptr = x; - JS_GET_PROXY(nproxy, ptr); - if (nproxy) { - JS_RemoveObjectRoot(cx, &nproxy->obj); - JS_GET_NATIVE_PROXY(jsproxy, nproxy->obj); - JS_REMOVE_PROXY(nproxy, jsproxy); - } -} - - -int ScriptingCore::executeTouchesEvent(int nHandler, int eventType, - CCSet *pTouches, CCNode *self) { - - std::string funcName = ""; - getTouchesFuncName(eventType, funcName); - - JSObject *jsretArr = JS_NewArrayObject(this->cx, 0, NULL); - - JS_AddNamedObjectRoot(this->cx, &jsretArr, "touchArray"); - int count = 0; - for(CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it, ++count) { - jsval jsret; - getJSTouchObject(this->cx, (CCTouch *) *it, jsret); - if(!JS_SetElement(this->cx, jsretArr, count, &jsret)) { - break; - } - } - - executeFunctionWithObjectData(1, funcName.c_str(), jsretArr, self); - - JS_RemoveObjectRoot(this->cx, &jsretArr); - - for(CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it, ++count) { - jsval jsret; - removeJSTouchObject(this->cx, (CCTouch *) *it, jsret); - } - - return 1; -} - int ScriptingCore::executeCustomTouchesEvent(int eventType, CCSet *pTouches, JSObject *obj) { - jsval retval; std::string funcName; getTouchesFuncName(eventType, funcName); @@ -602,13 +626,6 @@ int ScriptingCore::executeCustomTouchEvent(int eventType, } - -int ScriptingCore::executeSchedule(int nHandler, float dt, CCNode *self) { - - executeFunctionWithFloatData(nHandler, dt, self); - return 1; -} - long long jsval_to_long_long(JSContext *cx, jsval v) { JSObject *tmp = JSVAL_TO_OBJECT(v); if (JS_IsTypedArrayObject(tmp, cx) && JS_GetTypedArrayByteLength(tmp, cx) == 8) { diff --git a/scripting/javascript/bindings/ScriptingCore.h b/scripting/javascript/bindings/ScriptingCore.h index ad362a943b..3597796854 100644 --- a/scripting/javascript/bindings/ScriptingCore.h +++ b/scripting/javascript/bindings/ScriptingCore.h @@ -43,27 +43,13 @@ public: }; virtual ccScriptType getScriptType() { return kScriptTypeJavascript; }; - - lua_State* getLuaState(void) { return NULL; } /** @brief Remove CCObject from lua state @param object to remove */ - virtual void removeCCObjectByID(int n) {} - virtual void removeJSObjectByCCObject(void * cobj); + virtual void removeScriptObjectByCCObject(CCObject* pObj); - /** - @brief Remove Lua function handler - */ - virtual void removeLuaHandler(int nHandler) {} - - /** - @brief Add a path to find lua files in - @param path to be added to the Lua path - */ - virtual void addSearchPath(const char* path) {} - /** @brief Execute script code contained in the given string. @param codes holding the valid script code that should be executed. @@ -85,30 +71,16 @@ public: @return The integer value returned from the script function. */ virtual int executeGlobalFunction(const char* functionName) { return 0; } - - /** - @brief Execute a function by handler - @param The function handler - @param Number of parameters - @return The integer value returned from the script function. - */ - virtual int executeFunctionByHandler(int nHandler, int numArgs = 0) { return 0; } - virtual int executeFunctionWithIntegerData(int nHandler, int data, CCNode *self); - int executeFunctionWithObjectData(int nHandler, const char *name, JSObject *obj, CCNode *self); - virtual int executeFunctionWithFloatData(int nHandler, float data, CCNode *self); - virtual int executeFunctionWithBooleanData(int nHandler, bool data) { return 0; } - virtual int executeFunctionWithCCObject(int nHandler, CCObject* pObject, const char* typeName) { return 0; } - virtual int pushIntegerToLuaStack(int data) { return 0; } - virtual int pushFloatToLuaStack(int data) { return 0; } - virtual int pushBooleanToLuaStack(int data) { return 0; } - virtual int pushCCObjectToLuaStack(CCObject* pObject, const char* typeName) { return 0; } - - // functions for excute touch event - virtual int executeTouchEvent(int nHandler, int eventType, CCTouch *pTouch) { return 0; } - virtual int executeTouchesEvent(int nHandler, int eventType, CCSet *pTouches, CCNode *self); - - // execute a schedule function - virtual int executeSchedule(int nHandler, float dt, CCNode *self); + + virtual int executeNodeEvent(CCNode* pNode, int nAction); + virtual int executeMenuItemEvent(CCMenuItem* pMenuItem); + virtual int executeNotificationEvent(CCNotificationCenter* pNotificationCenter, const char* pszName); + virtual int executeCallFuncActionEvent(CCCallFunc* pAction, CCObject* pTarget = NULL); + virtual int executeSchedule(CCTimer* pTimer, float dt, CCNode* pNode = NULL); + virtual int executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches); + virtual int executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch); + + int executeFunctionWithObjectData(CCNode *self, const char *name, JSObject *obj); void executeJSFunctionWithThisObj(jsval thisObj, jsval callback, jsval data); diff --git a/scripting/javascript/bindings/cocos2dx.cpp.REMOVED.git-id b/scripting/javascript/bindings/cocos2dx.cpp.REMOVED.git-id index e47032916b..3726a6d305 100644 --- a/scripting/javascript/bindings/cocos2dx.cpp.REMOVED.git-id +++ b/scripting/javascript/bindings/cocos2dx.cpp.REMOVED.git-id @@ -1 +1 @@ -1add31bd5868e40261e6fc1706c097108a551e98 \ No newline at end of file +e63ae7e9891ffc117d0773ea208a818c73ceaabb \ No newline at end of file diff --git a/scripting/javascript/spidermonkey-android/android/Android.mk b/scripting/javascript/spidermonkey-android/Android.mk similarity index 70% rename from scripting/javascript/spidermonkey-android/android/Android.mk rename to scripting/javascript/spidermonkey-android/Android.mk index 8a8844d692..26072d8fe4 100644 --- a/scripting/javascript/spidermonkey-android/android/Android.mk +++ b/scripting/javascript/spidermonkey-android/Android.mk @@ -3,8 +3,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := spidermonkey_static LOCAL_MODULE_FILENAME := js_static -LOCAL_SRC_FILES := ../dist/lib/libjs_static.a -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../dist/include +LOCAL_SRC_FILES := ./dist/lib/libjs_static.a +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/dist/include LOCAL_CPPFLAGS := -D__STDC_LIMIT_MACROS=1 LOCAL_EXPORT_CPPFLAGS := -D__STDC_LIMIT_MACROS=1 include $(PREBUILT_STATIC_LIBRARY) diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp index 7be69da127..e31bd5acd4 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp @@ -42,9 +42,165 @@ extern "C" { NS_CC_BEGIN -CCLuaEngine::~CCLuaEngine() +// #pragma mark - +// #pragma mark CCLuaValue + +const CCLuaValue CCLuaValue::intValue(const int intValue) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeInt; + value.m_field.intValue = intValue; + return value; +} + +const CCLuaValue CCLuaValue::floatValue(const float floatValue) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeFloat; + value.m_field.floatValue = floatValue; + return value; +} + +const CCLuaValue CCLuaValue::booleanValue(const bool booleanValue) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeBoolean; + value.m_field.booleanValue = booleanValue; + return value; +} + +const CCLuaValue CCLuaValue::stringValue(const char* stringValue) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeString; + value.m_field.stringValue = new std::string(stringValue); + return value; +} + +const CCLuaValue CCLuaValue::stringValue(const std::string& stringValue) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeString; + value.m_field.stringValue = new std::string(stringValue); + return value; +} + +const CCLuaValue CCLuaValue::dictValue(const CCLuaValueDict& dictValue) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeDict; + value.m_field.dictValue = new CCLuaValueDict(dictValue); + return value; +} + +const CCLuaValue CCLuaValue::arrayValue(const CCLuaValueArray& arrayValue) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeArray; + value.m_field.arrayValue = new CCLuaValueArray(arrayValue); + return value; +} + +const CCLuaValue CCLuaValue::ccobjectValue(CCObject* ccobjectValue, const char* objectTypename) +{ + CCLuaValue value; + value.m_type = CCLuaValueTypeCCObject; + value.m_field.ccobjectValue = ccobjectValue; + ccobjectValue->retain(); + value.m_ccobjectType = new std::string(objectTypename); + return value; +} + +const CCLuaValue CCLuaValue::ccobjectValue(CCObject* ccobjectValue, const std::string& objectTypename) +{ + return CCLuaValue::ccobjectValue(ccobjectValue, objectTypename.c_str()); +} + +CCLuaValue::CCLuaValue(const CCLuaValue& rhs) +{ + copy(rhs); +} + +CCLuaValue& CCLuaValue::operator=(const CCLuaValue& rhs) +{ + if (this != &rhs) copy(rhs); + return *this; +} + +CCLuaValue::~CCLuaValue(void) +{ + if (m_type == CCLuaValueTypeString) + { + delete m_field.stringValue; + } + else if (m_type == CCLuaValueTypeDict) + { + delete m_field.dictValue; + } + else if (m_type == CCLuaValueTypeArray) + { + delete m_field.arrayValue; + } + else if (m_type == CCLuaValueTypeCCObject) + { + m_field.ccobjectValue->release(); + delete m_ccobjectType; + } +} + +void CCLuaValue::copy(const CCLuaValue& rhs) +{ + memcpy(&m_field, &rhs.m_field, sizeof(m_field)); + m_type = rhs.m_type; + if (m_type == CCLuaValueTypeString) + { + m_field.stringValue = new std::string(*rhs.m_field.stringValue); + } + else if (m_type == CCLuaValueTypeDict) + { + m_field.dictValue = new CCLuaValueDict(*rhs.m_field.dictValue); + } + else if (m_type == CCLuaValueTypeArray) + { + m_field.arrayValue = new CCLuaValueArray(*rhs.m_field.arrayValue); + } + else if (m_type == CCLuaValueTypeCCObject) + { + m_field.ccobjectValue = rhs.m_field.ccobjectValue; + m_field.ccobjectValue->retain(); + m_ccobjectType = new std::string(*rhs.m_ccobjectType); + } +} + + +#pragma mark - +#pragma mark CCLuaEngine + +CCLuaEngine* CCLuaEngine::m_defaultEngine = NULL; + +CCLuaEngine* CCLuaEngine::defaultEngine(void) +{ + if (!m_defaultEngine) + { + m_defaultEngine = CCLuaEngine::create(); + } + return m_defaultEngine; +} + +CCLuaEngine* CCLuaEngine::create(void) +{ + CCLuaEngine* pEngine = new CCLuaEngine(); + pEngine->init(); + return pEngine; +} + +CCLuaEngine::~CCLuaEngine(void) { lua_close(m_state); + if (this == m_defaultEngine) + { + m_defaultEngine = NULL; + } } bool CCLuaEngine::init(void) @@ -52,40 +208,32 @@ bool CCLuaEngine::init(void) m_state = lua_open(); luaL_openlibs(m_state); tolua_Cocos2d_open(m_state); - tolua_prepare_ccobject_table(m_state); + toluafix_open(m_state); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) addLuaLoader(loader_Android); #endif return true; } -CCLuaEngine* CCLuaEngine::engine() +void CCLuaEngine::removeScriptObjectByCCObject(CCObject* pObj) { - CCLuaEngine* pEngine = new CCLuaEngine(); - pEngine->init(); -// pEngine->autorelease(); - return pEngine; + toluafix_remove_ccobject_by_refid(m_state, pObj->m_nLuaID); } -void CCLuaEngine::removeCCObjectByID(int nLuaID) +void CCLuaEngine::removeScriptHandler(int nHandler) { - tolua_remove_ccobject_by_refid(m_state, nLuaID); -} - -void CCLuaEngine::removeLuaHandler(int nHandler) -{ - tolua_remove_function_by_refid(m_state, nHandler); + toluafix_remove_function_by_refid(m_state, nHandler); } void CCLuaEngine::addSearchPath(const char* path) { - lua_getglobal(m_state, "package"); /* stack: package */ - lua_getfield(m_state, -1, "path"); /* get package.path, stack: package path */ + lua_getglobal(m_state, "package"); /* stack: package */ + lua_getfield(m_state, -1, "path"); /* get package.path, stack: package path */ const char* cur_path = lua_tostring(m_state, -1); - lua_pop(m_state, 1); /* stack: package */ - lua_pushfstring(m_state, "%s;%s/?.lua", cur_path, path); /* stack: package newpath */ - lua_setfield(m_state, -2, "path"); /* package.path = newpath, stack: package */ - lua_pop(m_state, 1); /* stack: - */ + lua_pop(m_state, 1); /* stack: package */ + lua_pushfstring(m_state, "%s;%s/?.lua", cur_path, path); /* stack: package newpath */ + lua_setfield(m_state, -2, "path"); /* package.path = newpath, stack: package */ + lua_pop(m_state, 1); /* stack: - */ } int CCLuaEngine::executeString(const char *codes) @@ -105,7 +253,7 @@ int CCLuaEngine::executeString(const char *codes) int CCLuaEngine::executeScriptFile(const char* filename) { int nRet = luaL_dofile(m_state, filename); -// lua_gc(m_state, LUA_GCCOLLECT, 0); + // lua_gc(m_state, LUA_GCCOLLECT, 0); if (nRet != 0) { @@ -116,9 +264,9 @@ int CCLuaEngine::executeScriptFile(const char* filename) return 0; } -int CCLuaEngine::executeGlobalFunction(const char* functionName) +int CCLuaEngine::executeGlobalFunction(const char* functionName) { - lua_getglobal(m_state, functionName); /* query function by name, stack: function */ + lua_getglobal(m_state, functionName); /* query function by name, stack: function */ if (!lua_isfunction(m_state, -1)) { CCLOG("[LUA ERROR] name '%s' does not represent a Lua function", functionName); @@ -126,8 +274,8 @@ int CCLuaEngine::executeGlobalFunction(const char* functionName) return 0; } - int error = lua_pcall(m_state, 0, 1, 0); /* call function, stack: ret */ -// lua_gc(m_state, LUA_GCCOLLECT, 0); + int error = lua_pcall(m_state, 0, 1, 0); /* call function, stack: ret */ + // lua_gc(m_state, LUA_GCCOLLECT, 0); if (error) { @@ -144,43 +292,174 @@ int CCLuaEngine::executeGlobalFunction(const char* functionName) } int ret = lua_tointeger(m_state, -1); - lua_pop(m_state, 1); /* stack: - */ + lua_pop(m_state, 1); /* stack: - */ + return ret; +} + +int CCLuaEngine::executeNodeEvent(CCNode* pNode, int nAction) +{ + int ret = 0; + do + { + int nScriptHandler = pNode->getScriptHandler(); + CC_BREAK_IF(0 == nScriptHandler); + CCLuaValueDict dict; + if (nAction == kCCNodeOnEnter) + { + dict["name"] = CCLuaValue::stringValue("enter"); + pushCCLuaValueDict(dict); + ret = executeFunctionByHandler(nScriptHandler, 1); + } + else if (nAction == kCCNodeOnExit) + { + dict["name"] = CCLuaValue::stringValue("exit"); + pushCCLuaValueDict(dict); + ret = executeFunctionByHandler(nScriptHandler, 1); + } + } while (0); + return ret; +} + +int CCLuaEngine::executeMenuItemEvent(CCMenuItem* pMenuItem) +{ + int ret = 0; + do + { + int nScriptHandler = pMenuItem->getScriptTapHandler(); + CC_BREAK_IF(0 == nScriptHandler); + ret = pushInt(pMenuItem->getTag()); + ret = executeFunctionByHandler(nScriptHandler, 1); + } while (0); + return ret; +} + +int CCLuaEngine::executeNotificationEvent(CCNotificationCenter* pNotificationCenter, const char* pszName) +{ + int ret = 0; + do + { + int nScriptHandler = pNotificationCenter->getScriptHandler(); + CC_BREAK_IF(0 == nScriptHandler); + ret = pushString(pszName); + ret = executeFunctionByHandler(nScriptHandler, 1); + } while (0); + return ret; +} + +int CCLuaEngine::executeCallFuncActionEvent(CCCallFunc* pAction, CCObject* pTarget/* = NULL*/) +{ + int ret = 0; + do + { + int nScriptHandler = pAction->getScriptHandler(); + CC_BREAK_IF(0 == nScriptHandler); + if (pTarget != NULL) + { + ret = pushCCObject(pTarget, "CCNode"); + } + ret = executeFunctionByHandler(nScriptHandler, 1); + } while (0); + return ret; +} + +int CCLuaEngine::executeSchedule(CCTimer* pTimer, float dt, CCNode* pNode/* = NULL*/) +{ + int ret = 0; + do + { + int nScriptHandler = pTimer->getScriptHandler(); + CC_BREAK_IF(0 == nScriptHandler); + ret = pushFloat(dt); + ret = executeFunctionByHandler(nScriptHandler, 1); + } while (0); + return ret; +} + +// functions for excute touch event +int CCLuaEngine::executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch) +{ + int ret = 0; + do + { + CCTouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptHandlerEntry(); + CC_BREAK_IF(NULL == pScriptHandlerEntry); + int nScriptHandler = pScriptHandlerEntry->getHandler(); + CC_BREAK_IF(0 == nScriptHandler); + CCPoint pt = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView()); + lua_pushinteger(m_state, eventType); + lua_pushnumber(m_state, pt.x); + lua_pushnumber(m_state, pt.y); + ret = executeFunctionByHandler(nScriptHandler, 3); + } while (0); + return ret; +} + +int CCLuaEngine::executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches) +{ + int ret = 0; + do + { + CCTouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptHandlerEntry(); + CC_BREAK_IF(NULL == pScriptHandlerEntry); + int nScriptHandler = pScriptHandlerEntry->getHandler(); + CC_BREAK_IF(0 == nScriptHandler); + lua_pushinteger(m_state, eventType); + lua_newtable(m_state); + + CCDirector* pDirector = CCDirector::sharedDirector(); + CCSetIterator it = pTouches->begin(); + CCTouch* pTouch; + int n = 1; + while (it != pTouches->end()) + { + pTouch = (CCTouch*)*it; + CCPoint pt = pDirector->convertToGL(pTouch->getLocationInView()); + lua_pushnumber(m_state, pt.x); + lua_rawseti(m_state, -2, n++); + lua_pushnumber(m_state, pt.y); + lua_rawseti(m_state, -2, n++); + ++it; + } + + ret = executeFunctionByHandler(nScriptHandler, 2); + } while (0); + return ret; } int CCLuaEngine::executeFunctionByHandler(int nHandler, int numArgs) { - if (pushFunctionByHandler(nHandler)) + if (pushFunction(nHandler)) /* stack: ... arg1 arg2 ... func */ { if (numArgs > 0) { lua_insert(m_state, -(numArgs + 1)); /* stack: ... func arg1 arg2 ... */ } - + + int traceback = 0; + lua_getglobal(m_state, "__G__TRACKBACK__"); /* stack: ... func arg1 arg2 ... G */ + if (!lua_isfunction(m_state, -1)) + { + lua_pop(m_state, 1); /* stack: ... func arg1 arg2 ... */ + } + else + { + traceback = -(numArgs + 2); + lua_insert(m_state, traceback); /* stack: ... G func arg1 arg2 ... */ + } + int error = 0; - // try - // { - error = lua_pcall(m_state, numArgs, 1, 0); /* stack: ... ret */ - // } - // catch (exception& e) - // { - // CCLOG("[LUA ERROR] lua_pcall(%d) catch C++ exception: %s", nHandler, e.what()); - // lua_settop(m_state, 0); - // return 0; - // } - // catch (...) - // { - // CCLOG("[LUA ERROR] lua_pcall(%d) catch C++ unknown exception.", nHandler); - // lua_settop(m_state, 0); - // return 0; - // } + error = lua_pcall(m_state, numArgs, 1, traceback); /* stack: ... ret */ if (error) { - CCLOG("[LUA ERROR] %s", lua_tostring(m_state, - 1)); - lua_settop(m_state, 0); + if (traceback == 0) + { + CCLOG("[LUA ERROR] %s", lua_tostring(m_state, - 1)); /* stack: ... error */ + lua_pop(m_state, 1); // remove error message from stack + } return 0; } - + // get return value int ret = 0; if (lua_isnumber(m_state, -1)) @@ -191,100 +470,124 @@ int CCLuaEngine::executeFunctionByHandler(int nHandler, int numArgs) { ret = lua_toboolean(m_state, -1); } - - lua_pop(m_state, 1); + + lua_pop(m_state, 1); // remove return value from stack return ret; } else { + lua_pop(m_state, numArgs); // remove args from stack return 0; } } -int CCLuaEngine::executeFunctionWithIntegerData(int nHandler, int data, CCNode *self) -{ - lua_pushinteger(m_state, data); - return executeFunctionByHandler(nHandler, 1); -} - -int CCLuaEngine::executeFunctionWithFloatData(int nHandler, float data, CCNode *self) -{ - lua_pushnumber(m_state, data); - return executeFunctionByHandler(nHandler, 1); -} - -int CCLuaEngine::executeFunctionWithBooleanData(int nHandler, bool data) -{ - lua_pushboolean(m_state, data); - return executeFunctionByHandler(nHandler, 1); -} - -int CCLuaEngine::executeFunctionWithCCObject(int nHandler, CCObject* pObject, const char* typeName) -{ - tolua_pushusertype_ccobject(m_state, pObject->m_uID, &pObject->m_nLuaID, pObject, typeName); - return executeFunctionByHandler(nHandler, 1); -} - -int CCLuaEngine::pushIntegerToLuaStack(int data) +int CCLuaEngine::pushInt(int data) { lua_pushinteger(m_state, data); return lua_gettop(m_state); } -int CCLuaEngine::pushFloatToLuaStack(int data) +int CCLuaEngine::pushFloat(float data) { lua_pushnumber(m_state, data); return lua_gettop(m_state); } -int CCLuaEngine::pushBooleanToLuaStack(int data) +int CCLuaEngine::pushBoolean(bool data) { lua_pushboolean(m_state, data); return lua_gettop(m_state); } -int CCLuaEngine::pushCCObjectToLuaStack(CCObject* pObject, const char* typeName) +int CCLuaEngine::pushString(const char* data) { - tolua_pushusertype_ccobject(m_state, pObject->m_uID, &pObject->m_nLuaID, pObject, typeName); + lua_pushstring(m_state, data); return lua_gettop(m_state); } -// functions for excute touch event -int CCLuaEngine::executeTouchEvent(int nHandler, int eventType, CCTouch *pTouch) +int CCLuaEngine::pushString(const char* data, int length) { - CCPoint pt = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView()); - lua_pushinteger(m_state, eventType); - lua_pushnumber(m_state, pt.x); - lua_pushnumber(m_state, pt.y); - return executeFunctionByHandler(nHandler, 3); + lua_pushlstring(m_state, data, length); + return lua_gettop(m_state); } -int CCLuaEngine::executeTouchesEvent(int nHandler, int eventType, CCSet *pTouches, CCNode *self) +int CCLuaEngine::pushNil(void) { - lua_pushinteger(m_state, eventType); - lua_newtable(m_state); + lua_pushnil(m_state); + return lua_gettop(m_state); +} - CCDirector* pDirector = CCDirector::sharedDirector(); - CCSetIterator it = pTouches->begin(); - CCTouch* pTouch; - int n = 1; - while (it != pTouches->end()) +int CCLuaEngine::pushCCObject(CCObject* pObject, const char* typeName) +{ + toluafix_pushusertype_ccobject(m_state, pObject->m_uID, &pObject->m_nLuaID, pObject, typeName); + return lua_gettop(m_state); +} + +int CCLuaEngine::pushCCLuaValue(const CCLuaValue& value) +{ + const CCLuaValueType type = value.getType(); + if (type == CCLuaValueTypeInt) { - pTouch = (CCTouch*)*it; - CCPoint pt = pDirector->convertToGL(pTouch->getLocationInView()); - lua_pushnumber(m_state, pt.x); - lua_rawseti(m_state, -2, n++); - lua_pushnumber(m_state, pt.y); - lua_rawseti(m_state, -2, n++); - ++it; + return pushInt(value.intValue()); } - - return executeFunctionByHandler(nHandler, 2); + else if (type == CCLuaValueTypeFloat) + { + return pushFloat(value.floatValue()); + } + else if (type == CCLuaValueTypeBoolean) + { + return pushBoolean(value.booleanValue()); + } + else if (type == CCLuaValueTypeString) + { + return pushString(value.stringValue().c_str()); + } + else if (type == CCLuaValueTypeDict) + { + pushCCLuaValueDict(value.dictValue()); + } + else if (type == CCLuaValueTypeArray) + { + pushCCLuaValueArray(value.arrayValue()); + } + else if (type == CCLuaValueTypeCCObject) + { + pushCCObject(value.ccobjectValue(), value.getCCObjectTypename().c_str()); + } + + return lua_gettop(m_state); } -int CCLuaEngine::executeSchedule(int nHandler, float dt, CCNode *self) +int CCLuaEngine::pushCCLuaValueDict(const CCLuaValueDict& dict) { - return executeFunctionWithFloatData(nHandler, dt, self); + lua_newtable(m_state); /* stack: table */ + for (CCLuaValueDictIterator it = dict.begin(); it != dict.end(); ++it) + { + lua_pushstring(m_state, it->first.c_str()); /* stack: table key */ + pushCCLuaValue(it->second); /* stack: table key value */ + lua_rawset(m_state, -3); /* table.key = value, stack: table */ + } + + return lua_gettop(m_state); +} + +int CCLuaEngine::pushCCLuaValueArray(const CCLuaValueArray& array) +{ + lua_newtable(m_state); /* stack: table */ + int index = 1; + for (CCLuaValueArrayIterator it = array.begin(); it != array.end(); ++it) + { + pushCCLuaValue(*it); /* stack: table value */ + lua_rawseti(m_state, -2, index); /* table[index] = value, stack: table */ + ++index; + } + + return lua_gettop(m_state); +} + +void CCLuaEngine::cleanStack(void) +{ + lua_settop(m_state, 0); } void CCLuaEngine::addLuaLoader(lua_CFunction func) @@ -312,7 +615,7 @@ void CCLuaEngine::addLuaLoader(lua_CFunction func) lua_pop(m_state, 1); } -bool CCLuaEngine::pushFunctionByHandler(int nHandler) +bool CCLuaEngine::pushFunction(int nHandler) { lua_rawgeti(m_state, LUA_REGISTRYINDEX, nHandler); /* stack: ... func */ if (!lua_isfunction(m_state, -1)) diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.h b/scripting/lua/cocos2dx_support/CCLuaEngine.h index 3e219df446..fad8936c38 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.h +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.h @@ -38,30 +38,127 @@ extern "C" { NS_CC_BEGIN +typedef int LUA_FUNCTION; +typedef int LUA_TABLE; +typedef int LUA_STRING; + +class CCLuaValue; + +typedef std::map CCLuaValueDict; +typedef CCLuaValueDict::const_iterator CCLuaValueDictIterator; +typedef std::list CCLuaValueArray; +typedef CCLuaValueArray::const_iterator CCLuaValueArrayIterator; + +typedef enum { + CCLuaValueTypeInt, + CCLuaValueTypeFloat, + CCLuaValueTypeBoolean, + CCLuaValueTypeString, + CCLuaValueTypeDict, + CCLuaValueTypeArray, + CCLuaValueTypeCCObject +} CCLuaValueType; + +typedef union { + int intValue; + float floatValue; + bool booleanValue; + std::string* stringValue; + CCLuaValueDict* dictValue; + CCLuaValueArray* arrayValue; + CCObject* ccobjectValue; +} CCLuaValueField; + +class CCLuaValue +{ +public: + static const CCLuaValue intValue(const int intValue); + static const CCLuaValue floatValue(const float floatValue); + static const CCLuaValue booleanValue(const bool booleanValue); + static const CCLuaValue stringValue(const char* stringValue); + static const CCLuaValue stringValue(const std::string& stringValue); + static const CCLuaValue dictValue(const CCLuaValueDict& dictValue); + static const CCLuaValue arrayValue(const CCLuaValueArray& arrayValue); + static const CCLuaValue ccobjectValue(CCObject* ccobjectValue, const char* objectTypename); + static const CCLuaValue ccobjectValue(CCObject* ccobjectValue, const std::string& objectTypename); + + CCLuaValue(void) + : m_type(CCLuaValueTypeInt) + , m_ccobjectType(NULL) + { + memset(&m_field, 0, sizeof(m_field)); + } + CCLuaValue(const CCLuaValue& rhs); + CCLuaValue& operator=(const CCLuaValue& rhs); + ~CCLuaValue(void); + + const CCLuaValueType getType(void) const { + return m_type; + } + + const std::string& getCCObjectTypename(void) const { + return *m_ccobjectType; + } + + int intValue(void) const { + return m_field.intValue; + } + + float floatValue(void) const { + return m_field.floatValue; + } + + bool booleanValue(void) const { + return m_field.booleanValue; + } + + const std::string& stringValue(void) const { + return *m_field.stringValue; + } + + const CCLuaValueDict& dictValue(void) const { + return *m_field.dictValue; + } + + const CCLuaValueArray& arrayValue(void) const { + return *m_field.arrayValue; + } + + CCObject* ccobjectValue(void) const { + return m_field.ccobjectValue; + } + +private: + CCLuaValueField m_field; + CCLuaValueType m_type; + std::string* m_ccobjectType; + + void copy(const CCLuaValue& rhs); +}; + + // Lua support for cocos2d-x class CCLuaEngine : public CCScriptEngineProtocol { public: - ~CCLuaEngine(); - virtual ccScriptType getScriptType() { return kScriptTypeLua; }; - /** - @brief Method used to get a pointer to the lua_State that the script module is attached to. - @return A pointer to the lua_State that the script module is attached to. - */ - virtual lua_State* getLuaState(void) { - return m_state; - } - virtual void removeJSObjectByCCObject(void * cobj) {}; + static CCLuaEngine* defaultEngine(void); + static CCLuaEngine* create(void); + virtual ~CCLuaEngine(void); + + virtual ccScriptType getScriptType() { + return kScriptTypeLua; + }; + /** @brief Remove CCObject from lua state @param object to remove */ - virtual void removeCCObjectByID(int nLuaID); + virtual void removeScriptObjectByCCObject(CCObject* pObj); /** @brief Remove Lua function reference */ - virtual void removeLuaHandler(int nHandler); + virtual void removeScriptHandler(int nHandler); /** @brief Add a path to find lua files in @@ -90,34 +187,38 @@ public: @return The integer value returned from the script function. */ virtual int executeGlobalFunction(const char* functionName); + + virtual int executeNodeEvent(CCNode* pNode, int nAction); + virtual int executeMenuItemEvent(CCMenuItem* pMenuItem); + virtual int executeNotificationEvent(CCNotificationCenter* pNotificationCenter, const char* pszName); + virtual int executeCallFuncActionEvent(CCCallFunc* pAction, CCObject* pTarget = NULL); + virtual int executeSchedule(CCTimer* pTimer, float dt, CCNode* pNode = NULL); + virtual int executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches); + virtual int executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch); /** - @brief Execute a function by ref id - @param The function ref id - @param Number of parameters - @return The integer value returned from the script function. + @brief Method used to get a pointer to the lua_State that the script module is attached to. + @return A pointer to the lua_State that the script module is attached to. */ - virtual int executeFunctionByHandler(int nHandler, int numArgs = 0); - virtual int executeFunctionWithIntegerData(int nHandler, int data, cocos2d::CCNode *self); - virtual int executeFunctionWithFloatData(int nHandler, float data, cocos2d::CCNode *self); - virtual int executeFunctionWithBooleanData(int nHandler, bool data); - virtual int executeFunctionWithCCObject(int nHandler, CCObject* pObject, const char* typeName); - virtual int pushIntegerToLuaStack(int data); - virtual int pushFloatToLuaStack(int data); - virtual int pushBooleanToLuaStack(int data); - virtual int pushCCObjectToLuaStack(CCObject* pObject, const char* typeName); - - // functions for excute touch event - virtual int executeTouchEvent(int nHandler, int eventType, cocos2d::CCTouch *pTouch); - virtual int executeTouchesEvent(int nHandler, int eventType, cocos2d::CCSet *pTouches, cocos2d::CCNode *self); - - // execute a schedule function - virtual int executeSchedule(int nHandler, float dt, cocos2d::CCNode *self); + lua_State* getLuaState(void) { + return m_state; + } + + int pushInt(int data); + int pushFloat(float data); + int pushBoolean(bool data); + int pushString(const char* data); + int pushString(const char* data, int length); + int pushNil(void); + int pushCCObject(CCObject* pObject, const char* typeName); + int pushCCLuaValue(const CCLuaValue& value); + int pushCCLuaValueDict(const CCLuaValueDict& dict); + int pushCCLuaValueArray(const CCLuaValueArray& array); + int executeFunctionByHandler(int nHandler, int numArgs); + void cleanStack(void); // Add lua loader, now it is used on android - virtual void addLuaLoader(lua_CFunction func); - - static CCLuaEngine* engine(); + void addLuaLoader(lua_CFunction func); private: CCLuaEngine(void) @@ -126,11 +227,12 @@ private: } bool init(void); - bool pushFunctionByHandler(int nHandler); + bool pushFunction(int nHandler); lua_State* m_state; + static CCLuaEngine* m_defaultEngine; }; - + NS_CC_END #endif // __CC_LUA_ENGINE_H__ diff --git a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id index a8ccc47482..6bcf2669e2 100644 --- a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id @@ -1 +1 @@ -d5d8be3ed996546bd17110a1ab9b85553b02a7a7 \ No newline at end of file +6f56a41a68d8e682e9bd47bc0d7e6d1960608e8b \ No newline at end of file diff --git a/scripting/lua/cocos2dx_support/LuaCocos2d.h b/scripting/lua/cocos2dx_support/LuaCocos2d.h index 5119bbd918..cd93204279 100644 --- a/scripting/lua/cocos2dx_support/LuaCocos2d.h +++ b/scripting/lua/cocos2dx_support/LuaCocos2d.h @@ -1,44 +1,22 @@ -/**************************************************************************** - Copyright (c) 2011 cocos2d-x.org - Copyright (c) 2011 NetDragon.com - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#ifndef __LUACOCOS2D_H -#define __LUACOCOS2D_H - -#if defined(_WIN32) && defined(_DEBUG) -#pragma warning (disable:4800) -#endif - -#define TOLUA_RELEASE - -#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 -#define TOLUA_RELEASE -#endif +#ifndef __LUACOCOS2D_H_ +#define __LUACOCOS2D_H_ +extern "C" { #include "tolua++.h" +#include "tolua_fix.h" +} -int tolua_Cocos2d_open(lua_State* tolua_S); +#include +#include +#include "tolua_fix.h" +#include "cocos2d.h" +#include "CCLuaEngine.h" +#include "SimpleAudioEngine.h" +using namespace cocos2d; +using namespace CocosDenshion; -#endif // __LUACOCOS2D_H +TOLUA_API int tolua_Cocos2d_open(lua_State* tolua_S); + +#endif // __LUACOCOS2D_H_ diff --git a/scripting/lua/cocos2dx_support/tolua_fix.c b/scripting/lua/cocos2dx_support/tolua_fix.c index 4f9276bc6c..1f98871efa 100644 --- a/scripting/lua/cocos2dx_support/tolua_fix.c +++ b/scripting/lua/cocos2dx_support/tolua_fix.c @@ -2,7 +2,7 @@ #include "tolua_fix.h" #include -TOLUA_API void tolua_prepare_ccobject_table(lua_State* L) +TOLUA_API void toluafix_open(lua_State* L) { lua_pushstring(L, TOLUA_REFID_PTR_MAPPING); lua_newtable(L); @@ -13,11 +13,11 @@ TOLUA_API void tolua_prepare_ccobject_table(lua_State* L) lua_rawset(L, LUA_REGISTRYINDEX); } -TOLUA_API int tolua_pushusertype_ccobject(lua_State* L, - int refid, - int* p_refid, - void* ptr, - const char* type) +TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L, + int refid, + int* p_refid, + void* ptr, + const char* type) { if (ptr == NULL || p_refid == NULL) { @@ -51,9 +51,9 @@ TOLUA_API int tolua_pushusertype_ccobject(lua_State* L, return 0; } -TOLUA_API int tolua_remove_ccobject_by_refid(lua_State* L, int refid) +TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid) { - void* ptr = NULL; + void* ptr = NULL; const char* type = NULL; void** ud = NULL; if (refid == 0) return -1; @@ -144,20 +144,20 @@ TOLUA_API int tolua_remove_ccobject_by_refid(lua_State* L, int refid) return 0; } -TOLUA_API int tolua_ref_function(lua_State* L, int lo, int def) +TOLUA_API int toluafix_ref_function(lua_State* L, int lo, int def) { if (!lua_isfunction(L, lo)) return 0; lua_pushvalue(L, lo); /* stack: ... func */ return luaL_ref(L, LUA_REGISTRYINDEX); } -TOLUA_API void tolua_remove_function_by_refid(lua_State* L, int refid) +TOLUA_API void toluafix_remove_function_by_refid(lua_State* L, int refid) { luaL_unref(L, LUA_REGISTRYINDEX, refid); } // check lua value is funciton -TOLUA_API int tolua_isfunction(lua_State* L, int lo, tolua_Error* err) +TOLUA_API int toluafix_isfunction(lua_State* L, int lo, const char* type, int def, tolua_Error* err) { if (lua_gettop(L) >= abs(lo) && lua_isfunction(L, lo)) { @@ -169,7 +169,17 @@ TOLUA_API int tolua_isfunction(lua_State* L, int lo, tolua_Error* err) return 0; } -TOLUA_API void tolua_stack_dump(lua_State* L, const char* label) +TOLUA_API int toluafix_totable(lua_State* L, int lo, int def) +{ + return lo; +} + +TOLUA_API int toluafix_istable(lua_State* L, int lo, const char* type, int def, tolua_Error* err) +{ + return tolua_istable(L, lo, def, err); +} + +TOLUA_API void toluafix_stack_dump(lua_State* L, const char* label) { int i; int top = lua_gettop(L); diff --git a/scripting/lua/cocos2dx_support/tolua_fix.h b/scripting/lua/cocos2dx_support/tolua_fix.h index 73a6aabe7c..88c3ff4b27 100644 --- a/scripting/lua/cocos2dx_support/tolua_fix.h +++ b/scripting/lua/cocos2dx_support/tolua_fix.h @@ -9,20 +9,22 @@ extern "C" { #endif -#define TOLUA_REFID_PTR_MAPPING "tolua_refid_ptr_mapping" -#define TOLUA_REFID_TYPE_MAPPING "tolua_refid_type_mapping" +#define TOLUA_REFID_PTR_MAPPING "toluafix_refid_ptr_mapping" +#define TOLUA_REFID_TYPE_MAPPING "toluafix_refid_type_mapping" -TOLUA_API void tolua_prepare_ccobject_table(lua_State* L); -TOLUA_API int tolua_pushusertype_ccobject(lua_State* L, - int uid, - int* p_refid, - void* ptr, - const char* type); -TOLUA_API int tolua_remove_ccobject_by_refid(lua_State* L, int refid); -TOLUA_API int tolua_ref_function(lua_State* L, int lo, int def); -TOLUA_API void tolua_remove_function_by_refid(lua_State* L, int refid); -TOLUA_API int tolua_isfunction(lua_State* L, int lo, tolua_Error* err); -TOLUA_API void tolua_stack_dump(lua_State* L, const char* label); +TOLUA_API void toluafix_open(lua_State* L); +TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L, + int uid, + int* p_refid, + void* ptr, + const char* type); +TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid); +TOLUA_API int toluafix_ref_function(lua_State* L, int lo, int def); +TOLUA_API void toluafix_remove_function_by_refid(lua_State* L, int refid); +TOLUA_API int toluafix_isfunction(lua_State* L, int lo, const char* type, int def, tolua_Error* err); +TOLUA_API int toluafix_totable(lua_State* L, int lo, int def); +TOLUA_API int toluafix_istable(lua_State* L, int lo, const char* type, int def, tolua_Error* err); +TOLUA_API void toluafix_stack_dump(lua_State* L, const char* label); #ifdef __cplusplus } // extern "C" diff --git a/scripting/lua/lua/lapi.c b/scripting/lua/lua/lapi.c index b1f51a56ed..5d5145d2eb 100644 --- a/scripting/lua/lua/lapi.c +++ b/scripting/lua/lua/lapi.c @@ -38,9 +38,9 @@ const char lua_ident[] = -#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) -#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) +#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} @@ -771,7 +771,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { #define checkresults(L,na,nr) \ api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) - + LUA_API void lua_call (lua_State *L, int nargs, int nresults) { StkId func; diff --git a/scripting/lua/lua/lauxlib.c b/scripting/lua/lua/lauxlib.c index e9da1fbea8..10f14e2c08 100644 --- a/scripting/lua/lua/lauxlib.c +++ b/scripting/lua/lua/lauxlib.c @@ -25,12 +25,12 @@ #include "lauxlib.h" -#define FREELIST_REF 0 /* free list of references */ +#define FREELIST_REF 0 /* free list of references */ /* convert a stack index to positive */ -#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ - lua_gettop(L) + (i) + 1) +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) /* @@ -389,10 +389,10 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx, */ -#define bufflen(B) ((B)->p - (B)->buffer) -#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) +#define bufflen(B) ((B)->p - (B)->buffer) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) -#define LIMIT (LUA_MINSTACK/2) +#define LIMIT (LUA_MINSTACK/2) static int emptybuffer (luaL_Buffer *B) { diff --git a/scripting/lua/lua/lauxlib.h b/scripting/lua/lua/lauxlib.h index d264d23d70..34258235db 100644 --- a/scripting/lua/lua/lauxlib.h +++ b/scripting/lua/lua/lauxlib.h @@ -24,7 +24,7 @@ LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); #endif #if defined(LUA_COMPAT_OPENLIB) -#define luaI_openlib luaL_openlib +#define luaI_openlib luaL_openlib #endif @@ -97,26 +97,26 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, ** =============================================================== */ -#define luaL_argcheck(L, cond,numarg,extramsg) \ - ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) -#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) -#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) -#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) -#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) -#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) -#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) +#define luaL_argcheck(L, cond,numarg,extramsg) \ + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) -#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) #define luaL_dofile(L, fn) \ - (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) #define luaL_dostring(L, s) \ - (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) -#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) -#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) /* ** {====================================================== @@ -127,7 +127,7 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, typedef struct luaL_Buffer { - char *p; /* current position in buffer */ + char *p; /* current position in buffer */ int lvl; /* number of strings in the stack (level) */ lua_State *L; char buffer[LUAL_BUFFERSIZE]; @@ -138,9 +138,9 @@ typedef struct luaL_Buffer { (*(B)->p++ = (char)(c))) /* compatibility only */ -#define luaL_putchar(B,c) luaL_addchar(B,c) +#define luaL_putchar(B,c) luaL_addchar(B,c) -#define luaL_addsize(B,n) ((B)->p += (n)) +#define luaL_addsize(B,n) ((B)->p += (n)) LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); @@ -167,7 +167,7 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) -#define luaL_reg luaL_Reg +#define luaL_reg luaL_Reg #endif diff --git a/scripting/lua/lua/lbaselib.c b/scripting/lua/lua/lbaselib.c index 8a8d560c35..2ab550bd48 100644 --- a/scripting/lua/lua/lbaselib.c +++ b/scripting/lua/lua/lbaselib.c @@ -479,10 +479,10 @@ static const luaL_Reg base_funcs[] = { ** ======================================================= */ -#define CO_RUN 0 /* running */ -#define CO_SUS 1 /* suspended */ -#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ -#define CO_DEAD 3 +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 static const char *const statnames[] = {"running", "suspended", "normal", "dead"}; @@ -631,7 +631,7 @@ static void base_open (lua_State *L) { luaL_register(L, "_G", base_funcs); lua_pushliteral(L, LUA_VERSION); lua_setglobal(L, "_VERSION"); /* set global _VERSION */ - /* `ipairs' and `pairs' need auxliliary functions as upvalues */ + /* `ipairs' and `pairs' need auxiliary functions as upvalues */ auxopen(L, "ipairs", luaB_ipairs, ipairsaux); auxopen(L, "pairs", luaB_pairs, luaB_next); /* `newproxy' needs a weaktable as upvalue */ diff --git a/scripting/lua/lua/lcode.c b/scripting/lua/lua/lcode.c index 3f2b6cfd5f..679cb9cfd9 100644 --- a/scripting/lua/lua/lcode.c +++ b/scripting/lua/lua/lcode.c @@ -24,7 +24,7 @@ #include "ltable.h" -#define hasjumps(e) ((e)->t != (e)->f) +#define hasjumps(e) ((e)->t != (e)->f) static int isnumeral(expdesc *e) { diff --git a/scripting/lua/lua/lcode.h b/scripting/lua/lua/lcode.h index aaf6f11173..b941c60721 100644 --- a/scripting/lua/lua/lcode.h +++ b/scripting/lua/lua/lcode.h @@ -36,11 +36,11 @@ typedef enum BinOpr { typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; -#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) -#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) +#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) -#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); diff --git a/scripting/lua/lua/ldblib.c b/scripting/lua/lua/ldblib.c index be446687f1..2027eda598 100644 --- a/scripting/lua/lua/ldblib.c +++ b/scripting/lua/lua/ldblib.c @@ -316,8 +316,8 @@ static int db_debug (lua_State *L) { } -#define LEVELS1 12 /* size of the first part of the stack */ -#define LEVELS2 10 /* size of the second part of the stack */ +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ static int db_errorfb (lua_State *L) { int level; diff --git a/scripting/lua/lua/ldebug.c b/scripting/lua/lua/ldebug.c index 609ca9fd86..50ad3d3803 100644 --- a/scripting/lua/lua/ldebug.c +++ b/scripting/lua/lua/ldebug.c @@ -265,11 +265,11 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { ** ======================================================= */ -#define check(x) if (!(x)) return 0; +#define check(x) if (!(x)) return 0; -#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) +#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) -#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) +#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) @@ -285,7 +285,7 @@ static int precheck (const Proto *pt) { } -#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) +#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) int luaG_checkopenop (Instruction i) { switch (GET_OPCODE(i)) { diff --git a/scripting/lua/lua/ldebug.h b/scripting/lua/lua/ldebug.h index bc2376d7b9..ba28a97248 100644 --- a/scripting/lua/lua/ldebug.h +++ b/scripting/lua/lua/ldebug.h @@ -11,11 +11,11 @@ #include "lstate.h" -#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) +#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) -#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) +#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) -#define resethookcount(L) (L->hookcount = L->basehookcount) +#define resethookcount(L) (L->hookcount = L->basehookcount) LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, diff --git a/scripting/lua/lua/ldo.c b/scripting/lua/lua/ldo.c index 8de05f728e..d1bf786cb7 100644 --- a/scripting/lua/lua/ldo.c +++ b/scripting/lua/lua/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ +** $Id: ldo.c,v 2.38.1.4 2012/01/18 02:27:10 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -217,6 +217,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { int nvar = actual - nfixargs; /* number of extra arguments */ lua_assert(p->is_vararg & VARARG_HASARG); luaC_checkGC(L); + luaD_checkstack(L, p->maxstacksize); htab = luaH_new(L, nvar, 1); /* create `arg' table */ for (i=0; itop - nvar + i); diff --git a/scripting/lua/lua/ldo.h b/scripting/lua/lua/ldo.h index c97537ef51..98fddac59f 100644 --- a/scripting/lua/lua/ldo.h +++ b/scripting/lua/lua/ldo.h @@ -13,7 +13,7 @@ #include "lzio.h" -#define luaD_checkstack(L,n) \ +#define luaD_checkstack(L,n) \ if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ luaD_growstack(L, n); \ else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); @@ -21,17 +21,17 @@ #define incr_top(L) {luaD_checkstack(L,1); L->top++;} -#define savestack(L,p) ((char *)(p) - (char *)L->stack) -#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) +#define savestack(L,p) ((char *)(p) - (char *)L->stack) +#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) -#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) -#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) +#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) +#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) /* results from luaD_precall */ -#define PCRLUA 0 /* initiated a call to a Lua function */ -#define PCRC 1 /* did a call to a C function */ -#define PCRYIELD 2 /* C funtion yielded */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ /* type of protected functions, to be ran by `runprotected' */ diff --git a/scripting/lua/lua/ldump.c b/scripting/lua/lua/ldump.c index 678ef4d594..c9d3d4870f 100644 --- a/scripting/lua/lua/ldump.c +++ b/scripting/lua/lua/ldump.c @@ -23,8 +23,8 @@ typedef struct { int status; } DumpState; -#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) -#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) +#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) +#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) static void DumpBlock(const void* b, size_t size, DumpState* D) { @@ -67,13 +67,13 @@ static void DumpString(const TString* s, DumpState* D) } else { - size_t size=s->tsv.len+1; /* include trailing '\0' */ + size_t size=s->tsv.len+1; /* include trailing '\0' */ DumpVar(size,D); DumpBlock(getstr(s),size,D); } } -#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) +#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) static void DumpFunction(const Proto* f, const TString* p, DumpState* D); @@ -88,19 +88,19 @@ static void DumpConstants(const Proto* f, DumpState* D) switch (ttype(o)) { case LUA_TNIL: - break; + break; case LUA_TBOOLEAN: - DumpChar(bvalue(o),D); - break; + DumpChar(bvalue(o),D); + break; case LUA_TNUMBER: - DumpNumber(nvalue(o),D); - break; + DumpNumber(nvalue(o),D); + break; case LUA_TSTRING: - DumpString(rawtsvalue(o),D); - break; + DumpString(rawtsvalue(o),D); + break; default: - lua_assert(0); /* cannot happen */ - break; + lua_assert(0); /* cannot happen */ + break; } } n=f->sizep; diff --git a/scripting/lua/lua/lfunc.h b/scripting/lua/lua/lfunc.h index d936be679a..a68cf5151c 100644 --- a/scripting/lua/lua/lfunc.h +++ b/scripting/lua/lua/lfunc.h @@ -11,10 +11,10 @@ #include "lobject.h" -#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ +#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ cast(int, sizeof(TValue)*((n)-1))) -#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ +#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ cast(int, sizeof(TValue *)*((n)-1))) diff --git a/scripting/lua/lua/lgc.c b/scripting/lua/lua/lgc.c index a782f9898f..e909c79a96 100644 --- a/scripting/lua/lua/lgc.c +++ b/scripting/lua/lua/lgc.c @@ -23,25 +23,25 @@ #include "ltm.h" -#define GCSTEPSIZE 1024u -#define GCSWEEPMAX 40 -#define GCSWEEPCOST 10 -#define GCFINALIZECOST 100 +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 -#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) +#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) -#define makewhite(g,x) \ +#define makewhite(g,x) \ ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) -#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) -#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) +#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) -#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) +#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) -#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) -#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) +#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) +#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) #define KEYWEAK bitmask(KEYWEAKBIT) @@ -53,7 +53,7 @@ if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } #define markobject(g,t) { if (iswhite(obj2gco(t))) \ - reallymarkobject(g, obj2gco(t)); } + reallymarkobject(g, obj2gco(t)); } #define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) @@ -401,7 +401,7 @@ static void freeobj (lua_State *L, GCObject *o) { -#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { diff --git a/scripting/lua/lua/lgc.h b/scripting/lua/lua/lgc.h index 1280a27289..5a8dc605b3 100644 --- a/scripting/lua/lua/lgc.h +++ b/scripting/lua/lua/lgc.h @@ -14,27 +14,27 @@ /* ** Possible states of the Garbage Collector */ -#define GCSpause 0 -#define GCSpropagate 1 -#define GCSsweepstring 2 -#define GCSsweep 3 -#define GCSfinalize 4 +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 /* ** some userful bit tricks */ -#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) -#define setbits(x,m) ((x) |= (m)) -#define testbits(x,m) ((x) & (m)) -#define bitmask(b) (1<<(b)) -#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) -#define l_setbit(x,b) setbits(x, bitmask(b)) -#define resetbit(x,b) resetbits(x, bitmask(b)) -#define testbit(x,b) testbits(x, bitmask(b)) -#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) -#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) -#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) @@ -51,47 +51,47 @@ */ -#define WHITE0BIT 0 -#define WHITE1BIT 1 -#define BLACKBIT 2 -#define FINALIZEDBIT 3 -#define KEYWEAKBIT 3 -#define VALUEWEAKBIT 4 -#define FIXEDBIT 5 -#define SFIXEDBIT 6 -#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) #define isblack(x) testbit((x)->gch.marked, BLACKBIT) -#define isgray(x) (!isblack(x) && !iswhite(x)) +#define isgray(x) (!isblack(x) && !iswhite(x)) -#define otherwhite(g) (g->currentwhite ^ WHITEBITS) -#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) -#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) -#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) -#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) -#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) #define luaC_checkGC(L) { \ condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ if (G(L)->totalbytes >= G(L)->GCthreshold) \ - luaC_step(L); } + luaC_step(L); } #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ - luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ - luaC_barrierback(L,t); } + luaC_barrierback(L,t); } #define luaC_objbarrier(L,p,o) \ - { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ - luaC_barrierf(L,obj2gco(p),obj2gco(o)); } + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } #define luaC_objbarriert(L,t,o) \ { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } diff --git a/scripting/lua/lua/liolib.c b/scripting/lua/lua/liolib.c index e6d475a95a..649f9a5951 100644 --- a/scripting/lua/lua/liolib.c +++ b/scripting/lua/lua/liolib.c @@ -20,8 +20,8 @@ -#define IO_INPUT 1 -#define IO_OUTPUT 2 +#define IO_INPUT 1 +#define IO_OUTPUT 2 static const char *const fnames[] = {"input", "output"}; @@ -51,7 +51,7 @@ static void fileerror (lua_State *L, int arg, const char *filename) { } -#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) +#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) static int io_type (lua_State *L) { diff --git a/scripting/lua/lua/llex.c b/scripting/lua/lua/llex.c index e3d3de1c24..77afcdedc7 100644 --- a/scripting/lua/lua/llex.c +++ b/scripting/lua/lua/llex.c @@ -30,7 +30,7 @@ -#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') /* ORDER RESERVED */ @@ -177,21 +177,16 @@ static void buffreplace (LexState *ls, char from, char to) { static void trydecpoint (LexState *ls, SemInfo *seminfo) { - /* format error: try to update decimal point separator */ -#ifdef ANDROID - char old = ls->decpoint; - ls->decpoint = '.'; -#else - struct lconv *cv = localeconv(); - char old = ls->decpoint; - ls->decpoint = (cv ? cv->decimal_point[0] : '.'); -#endif - buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ - if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { - /* format error with correct decimal point: no more options */ - buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ - luaX_lexerror(ls, "malformed number", TK_NUMBER); - } + /* format error: try to update decimal point separator */ + /* struct lconv *cv = localeconv(); removed for android ndk */ + char old = ls->decpoint; + ls->decpoint = '.'; /* (cv ? cv->decimal_point[0] : '.'); removed for android ndk */ + buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + luaX_lexerror(ls, "malformed number", TK_NUMBER); + } } diff --git a/scripting/lua/lua/llex.h b/scripting/lua/lua/llex.h index 9a93e99114..a9201cee48 100644 --- a/scripting/lua/lua/llex.h +++ b/scripting/lua/lua/llex.h @@ -11,10 +11,10 @@ #include "lzio.h" -#define FIRST_RESERVED 257 +#define FIRST_RESERVED 257 /* maximum length of a reserved word */ -#define TOKEN_LEN (sizeof("function")/sizeof(char)) +#define TOKEN_LEN (sizeof("function")/sizeof(char)) /* @@ -33,7 +33,7 @@ enum RESERVED { }; /* number of reserved words */ -#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) /* array with token `names' */ diff --git a/scripting/lua/lua/llimits.h b/scripting/lua/lua/llimits.h index 899bcb5db4..ca8dcb7224 100644 --- a/scripting/lua/lua/llimits.h +++ b/scripting/lua/lua/llimits.h @@ -27,9 +27,9 @@ typedef LUAI_MEM l_mem; typedef unsigned char lu_byte; -#define MAX_SIZET ((size_t)(~(size_t)0)-2) +#define MAX_SIZET ((size_t)(~(size_t)0)-2) -#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ @@ -54,30 +54,30 @@ typedef LUAI_UACNUMBER l_uacNumber; /* internal assertions for in-house debugging */ #ifdef lua_assert -#define check_exp(c,e) (lua_assert(c), (e)) -#define api_check(l,e) lua_assert(e) +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) #else -#define lua_assert(c) ((void)0) -#define check_exp(c,e) (e) -#define api_check luai_apicheck +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck #endif #ifndef UNUSED -#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ #endif #ifndef cast -#define cast(t, exp) ((t)(exp)) +#define cast(t, exp) ((t)(exp)) #endif -#define cast_byte(i) cast(lu_byte, (i)) -#define cast_num(i) cast(lua_Number, (i)) -#define cast_int(i) cast(int, (i)) +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) @@ -90,19 +90,19 @@ typedef lu_int32 Instruction; /* maximum stack for a Lua function */ -#define MAXSTACK 250 +#define MAXSTACK 250 /* minimum size for the string table (must be power of 2) */ #ifndef MINSTRTABSIZE -#define MINSTRTABSIZE 32 +#define MINSTRTABSIZE 32 #endif /* minimum size for string buffer */ #ifndef LUA_MINBUFFER -#define LUA_MINBUFFER 32 +#define LUA_MINBUFFER 32 #endif @@ -120,9 +120,9 @@ typedef lu_int32 Instruction; ** macro to control inclusion of some hard tests on stack reallocation */ #ifndef HARDSTACKTESTS -#define condhardstacktests(x) ((void)0) +#define condhardstacktests(x) ((void)0) #else -#define condhardstacktests(x) x +#define condhardstacktests(x) x #endif #endif diff --git a/scripting/lua/lua/lmem.c b/scripting/lua/lua/lmem.c index 953b9a6d25..ae7d8c965f 100644 --- a/scripting/lua/lua/lmem.c +++ b/scripting/lua/lua/lmem.c @@ -40,7 +40,7 @@ -#define MINSIZEARRAY 4 +#define MINSIZEARRAY 4 void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, diff --git a/scripting/lua/lua/lmem.h b/scripting/lua/lua/lmem.h index a017f7aecc..7c2dcb3220 100644 --- a/scripting/lua/lua/lmem.h +++ b/scripting/lua/lua/lmem.h @@ -13,22 +13,22 @@ #include "llimits.h" #include "lua.h" -#define MEMERRMSG "not enough memory" +#define MEMERRMSG "not enough memory" #define luaM_reallocv(L,b,on,n,e) \ - ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ - luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ - luaM_toobig(L)) + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) -#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) -#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) -#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) -#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) #define luaM_newvector(L,n,t) \ - cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) #define luaM_growvector(L,v,nelems,size,t,limit,e) \ if ((nelems)+1 > (size)) \ diff --git a/scripting/lua/lua/loadlib.c b/scripting/lua/lua/loadlib.c index 537b40b6f9..6158c5353d 100644 --- a/scripting/lua/lua/loadlib.c +++ b/scripting/lua/lua/loadlib.c @@ -23,23 +23,23 @@ /* prefix for open functions in C libraries */ -#define LUA_POF "luaopen_" +#define LUA_POF "luaopen_" /* separator for open functions in C libraries */ -#define LUA_OFSEP "_" +#define LUA_OFSEP "_" -#define LIBPREFIX "LOADLIB: " +#define LIBPREFIX "LOADLIB: " -#define POF LUA_POF -#define LIB_FAIL "open" +#define POF LUA_POF +#define LIB_FAIL "open" /* error codes for ll_loadfunc */ -#define ERRLIB 1 -#define ERRFUNC 2 +#define ERRLIB 1 +#define ERRFUNC 2 -#define setprogdir(L) ((void)0) +#define setprogdir(L) ((void)0) static void ll_unloadlib (void *lib); @@ -153,7 +153,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { /* Mac appends a `_' before C function names */ #undef POF -#define POF "_" LUA_POF +#define POF "_" LUA_POF static void pusherror (lua_State *L) { @@ -230,10 +230,10 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { */ #undef LIB_FAIL -#define LIB_FAIL "absent" +#define LIB_FAIL "absent" -#define DLMSG "dynamic libraries not enabled; check your Lua installation" +#define DLMSG "dynamic libraries not enabled; check your Lua installation" static void ll_unloadlib (void *lib) { @@ -445,7 +445,7 @@ static int loader_preload (lua_State *L) { static const int sentinel_ = 0; -#define sentinel ((void *)&sentinel_) +#define sentinel ((void *)&sentinel_) static int ll_require (lua_State *L) { @@ -587,7 +587,7 @@ static int ll_seeall (lua_State *L) { /* auxiliary mark (for internal use) */ -#define AUXMARK "\1" +#define AUXMARK "\1" static void setpath (lua_State *L, const char *fieldname, const char *envname, const char *def) { diff --git a/scripting/lua/lua/lobject.h b/scripting/lua/lua/lobject.h index 5235f2e8ae..f1e447ef3b 100644 --- a/scripting/lua/lua/lobject.h +++ b/scripting/lua/lua/lobject.h @@ -17,17 +17,17 @@ /* tags for values visible from Lua */ -#define LAST_TAG LUA_TTHREAD +#define LAST_TAG LUA_TTHREAD -#define NUM_TAGS (LAST_TAG+1) +#define NUM_TAGS (LAST_TAG+1) /* ** Extra tags for non-values */ -#define LUA_TPROTO (LAST_TAG+1) -#define LUA_TUPVAL (LAST_TAG+2) -#define LUA_TDEADKEY (LAST_TAG+3) +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) /* @@ -40,7 +40,7 @@ typedef union GCObject GCObject; ** Common Header for all collectable objects (in macro form, to be ** included in other objects) */ -#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked +#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked /* @@ -68,7 +68,7 @@ typedef union { ** Tagged Values */ -#define TValuefields Value value; int tt +#define TValuefields Value value; int tt typedef struct lua_TValue { TValuefields; @@ -76,31 +76,31 @@ typedef struct lua_TValue { /* Macros to test type */ -#define ttisnil(o) (ttype(o) == LUA_TNIL) -#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) -#define ttisstring(o) (ttype(o) == LUA_TSTRING) -#define ttistable(o) (ttype(o) == LUA_TTABLE) -#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) -#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) -#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) -#define ttisthread(o) (ttype(o) == LUA_TTHREAD) -#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) +#define ttisnil(o) (ttype(o) == LUA_TNIL) +#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) +#define ttisstring(o) (ttype(o) == LUA_TSTRING) +#define ttistable(o) (ttype(o) == LUA_TTABLE) +#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) +#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) +#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) +#define ttisthread(o) (ttype(o) == LUA_TTHREAD) +#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) /* Macros to access values */ -#define ttype(o) ((o)->tt) -#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) -#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) -#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) -#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) -#define tsvalue(o) (&rawtsvalue(o)->tsv) -#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) -#define uvalue(o) (&rawuvalue(o)->uv) -#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) -#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) -#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) -#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) +#define ttype(o) ((o)->tt) +#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) +#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) +#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) +#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) +#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) +#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) +#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) -#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) +#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) /* ** for internal debug only @@ -169,24 +169,24 @@ typedef struct lua_TValue { */ /* from stack to (same) stack */ -#define setobjs2s setobj +#define setobjs2s setobj /* to stack (not from same stack) */ -#define setobj2s setobj -#define setsvalue2s setsvalue -#define sethvalue2s sethvalue -#define setptvalue2s setptvalue +#define setobj2s setobj +#define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue /* from table to same table */ -#define setobjt2t setobj +#define setobjt2t setobj /* to table */ -#define setobj2t setobj +#define setobj2t setobj /* to new object */ -#define setobj2n setobj -#define setsvalue2n setsvalue +#define setobj2n setobj +#define setsvalue2n setsvalue #define setttype(obj, tt) (ttype(obj) = (tt)) -#define iscollectable(o) (ttype(o) >= LUA_TSTRING) +#define iscollectable(o) (ttype(o) >= LUA_TSTRING) @@ -207,7 +207,7 @@ typedef union TString { } TString; -#define getstr(ts) cast(const char *, (ts) + 1) +#define getstr(ts) cast(const char *, (ts) + 1) #define svalue(o) getstr(rawtsvalue(o)) @@ -254,9 +254,9 @@ typedef struct Proto { /* masks for new-style vararg */ -#define VARARG_HASARG 1 -#define VARARG_ISVARARG 2 -#define VARARG_NEEDSARG 4 +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 typedef struct LocVar { @@ -289,8 +289,8 @@ typedef struct UpVal { */ #define ClosureHeader \ - CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ - struct Table *env + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env typedef struct CClosure { ClosureHeader; @@ -312,8 +312,8 @@ typedef union Closure { } Closure; -#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) -#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) +#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) +#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) /* @@ -353,18 +353,18 @@ typedef struct Table { ** `module' operation for hashing (size is always a power of 2) */ #define lmod(s,size) \ - (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))) + (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))) -#define twoto(x) (1<<(x)) -#define sizenode(t) (twoto((t)->lsizenode)) +#define twoto(x) (1<<(x)) +#define sizenode(t) (twoto((t)->lsizenode)) -#define luaO_nilobject (&luaO_nilobject_) +#define luaO_nilobject (&luaO_nilobject_) LUAI_DATA const TValue luaO_nilobject_; -#define ceillog2(x) (luaO_log2((x)-1) + 1) +#define ceillog2(x) (luaO_log2((x)-1) + 1) LUAI_FUNC int luaO_log2 (unsigned int x); LUAI_FUNC int luaO_int2fb (unsigned int x); diff --git a/scripting/lua/lua/lopcodes.c b/scripting/lua/lua/lopcodes.c index f18a05a792..4cc745230b 100644 --- a/scripting/lua/lua/lopcodes.c +++ b/scripting/lua/lua/lopcodes.c @@ -59,44 +59,44 @@ const char *const luaP_opnames[NUM_OPCODES+1] = { #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) const lu_byte luaP_opmodes[NUM_OPCODES] = { -/* T A B C mode opcode */ - opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ - ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ - ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ - ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ - ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ - ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ - ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ - ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ - ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ - ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ - ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ - ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ - ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ - ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ - ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ - ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ - ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ - ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ - ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ - ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ - ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ - ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ - ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ - ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ +/* T A B C mode opcode */ + opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ + ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ + ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ + ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ + ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ + ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ + ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ + ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ }; diff --git a/scripting/lua/lua/lopcodes.h b/scripting/lua/lua/lopcodes.h index 03eb54761e..41224d6ee1 100644 --- a/scripting/lua/lua/lopcodes.h +++ b/scripting/lua/lua/lopcodes.h @@ -14,11 +14,11 @@ We assume that instructions are unsigned numbers. All instructions have an opcode in the first 6 bits. Instructions can have the following fields: - `A' : 8 bits - `B' : 9 bits - `C' : 9 bits - `Bx' : 18 bits (`B' and `C' together) - `sBx' : signed Bx + `A' : 8 bits + `B' : 9 bits + `C' : 9 bits + `Bx' : 18 bits (`B' and `C' together) + `sBx' : signed Bx A signed argument is represented in excess K; that is, the number value is the unsigned value minus K. K is exactly the maximum value @@ -34,18 +34,18 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ /* ** size and position of opcode arguments. */ -#define SIZE_C 9 -#define SIZE_B 9 -#define SIZE_Bx (SIZE_C + SIZE_B) -#define SIZE_A 8 +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 -#define SIZE_OP 6 +#define SIZE_OP 6 -#define POS_OP 0 -#define POS_A (POS_OP + SIZE_OP) -#define POS_C (POS_A + SIZE_A) -#define POS_B (POS_C + SIZE_C) -#define POS_Bx POS_C +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C /* @@ -68,47 +68,47 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ /* creates a mask with `n' 1 bits at position `p' */ -#define MASK1(n,p) ((~((~(Instruction)0)<>POS_OP) & MASK1(SIZE_OP,0))) -#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ - ((cast(Instruction, o)<>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) -#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ - ((cast(Instruction, u)<>POS_A) & MASK1(SIZE_A,0))) +#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ + ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) -#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ - ((cast(Instruction, b)<>POS_B) & MASK1(SIZE_B,0))) +#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ + ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) -#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ - ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) +#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ + ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) -#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ - ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) +#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ + ((cast(Instruction, b)< C) then pc++ */ -OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ +OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ -OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ -OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ -OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ +OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ -OP_FORLOOP,/* A sBx R(A)+=R(A+2); - if R(A) =) R(A)*/ -OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ +OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ -OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ } OpCode; -#define NUM_OPCODES (cast(int, OP_VARARG) + 1) +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) @@ -251,18 +251,18 @@ enum OpArgMask { LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; -#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) -#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) -#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) -#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) -#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ /* number of list items to accumulate before a SETLIST instruction */ -#define LFIELDS_PER_FLUSH 50 +#define LFIELDS_PER_FLUSH 50 #endif diff --git a/scripting/lua/lua/lparser.c b/scripting/lua/lua/lparser.c index 54798e8796..dda7488dca 100644 --- a/scripting/lua/lua/lparser.c +++ b/scripting/lua/lua/lparser.c @@ -27,11 +27,11 @@ -#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) +#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) -#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) +#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) -#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) /* @@ -97,7 +97,7 @@ static void checknext (LexState *ls, int c) { } -#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } +#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } @@ -275,11 +275,11 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { static void enterlevel (LexState *ls) { if (++ls->L->nCcalls > LUAI_MAXCCALLS) - luaX_lexerror(ls, "chunk has too many syntax levels", 0); + luaX_lexerror(ls, "chunk has too many syntax levels", 0); } -#define leavelevel(ls) ((ls)->L->nCcalls--) +#define leavelevel(ls) ((ls)->L->nCcalls--) static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { @@ -818,7 +818,7 @@ static const struct { {2, 2}, {1, 1} /* logical (and/or) */ }; -#define UNARY_PRIORITY 8 /* priority for unary operators */ +#define UNARY_PRIORITY 8 /* priority for unary operators */ /* diff --git a/scripting/lua/lua/lparser.h b/scripting/lua/lua/lparser.h index 82f669eb95..18836afd1c 100644 --- a/scripting/lua/lua/lparser.h +++ b/scripting/lua/lua/lparser.h @@ -17,21 +17,21 @@ */ typedef enum { - VVOID, /* no value */ + VVOID, /* no value */ VNIL, VTRUE, VFALSE, - VK, /* info = index of constant in `k' */ - VKNUM, /* nval = numerical value */ - VLOCAL, /* info = local register */ + VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ + VLOCAL, /* info = local register */ VUPVAL, /* info = index of upvalue in `upvalues' */ - VGLOBAL, /* info = index of table; aux = index of global name in `k' */ - VINDEXED, /* info = table register; aux = index register (or `k') */ - VJMP, /* info = instruction pc */ - VRELOCABLE, /* info = instruction pc */ - VNONRELOC, /* info = result register */ - VCALL, /* info = instruction pc */ - VVARARG /* info = instruction pc */ + VGLOBAL, /* info = index of table; aux = index of global name in `k' */ + VINDEXED, /* info = table register; aux = index register (or `k') */ + VJMP, /* info = instruction pc */ + VRELOCABLE, /* info = instruction pc */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ } expkind; typedef struct expdesc { diff --git a/scripting/lua/lua/lstate.c b/scripting/lua/lua/lstate.c index 2a5cc299a0..4313b83a0c 100644 --- a/scripting/lua/lua/lstate.c +++ b/scripting/lua/lua/lstate.c @@ -24,8 +24,8 @@ #include "ltm.h" -#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) -#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) #define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) diff --git a/scripting/lua/lua/lstate.h b/scripting/lua/lua/lstate.h index 3d9117fb79..3bc575b6bc 100644 --- a/scripting/lua/lua/lstate.h +++ b/scripting/lua/lua/lstate.h @@ -19,10 +19,10 @@ struct lua_longjmp; /* defined in ldo.c */ /* table of globals */ -#define gt(L) (&L->l_gt) +#define gt(L) (&L->l_gt) /* registry */ -#define registry(L) (&G(L)->l_registry) +#define registry(L) (&G(L)->l_registry) /* extra stack space to handle TM calls and some other extras */ @@ -48,7 +48,7 @@ typedef struct stringtable { typedef struct CallInfo { StkId base; /* base for this function */ StkId func; /* function index in the stack */ - StkId top; /* top for this function */ + StkId top; /* top for this function */ const Instruction *savedpc; int nresults; /* expected number of results from this function */ int tailcalls; /* number of tail calls lost under this entry */ @@ -56,10 +56,10 @@ typedef struct CallInfo { -#define curr_func(L) (clvalue(L->ci->func)) -#define ci_func(ci) (clvalue((ci)->func)) -#define f_isLua(ci) (!ci_func(ci)->c.isC) -#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) /* @@ -127,7 +127,7 @@ struct lua_State { }; -#define G(L) (L->l_G) +#define G(L) (L->l_G) /* @@ -146,20 +146,20 @@ union GCObject { /* macros to convert a GCObject into a specific value */ -#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) -#define gco2ts(o) (&rawgco2ts(o)->tsv) -#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) -#define gco2u(o) (&rawgco2u(o)->uv) -#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) -#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) -#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) -#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) #define ngcotouv(o) \ - check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) -#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) /* macro to convert any Lua object into a GCObject */ -#define obj2gco(v) (cast(GCObject *, (v))) +#define obj2gco(v) (cast(GCObject *, (v))) LUAI_FUNC lua_State *luaE_newthread (lua_State *L); diff --git a/scripting/lua/lua/lstring.h b/scripting/lua/lua/lstring.h index d909495d39..73a2ff8b38 100644 --- a/scripting/lua/lua/lstring.h +++ b/scripting/lua/lua/lstring.h @@ -13,15 +13,15 @@ #include "lstate.h" -#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) -#define sizeudata(u) (sizeof(union Udata)+(u)->len) +#define sizeudata(u) (sizeof(union Udata)+(u)->len) -#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) -#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) +#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ (sizeof(s)/sizeof(char))-1)) -#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) LUAI_FUNC void luaS_resize (lua_State *L, int newsize); LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); diff --git a/scripting/lua/lua/lstrlib.c b/scripting/lua/lua/lstrlib.c index a99c7dd631..7a03489beb 100644 --- a/scripting/lua/lua/lstrlib.c +++ b/scripting/lua/lua/lstrlib.c @@ -164,8 +164,8 @@ static int str_dump (lua_State *L) { */ -#define CAP_UNFINISHED (-1) -#define CAP_POSITION (-2) +#define CAP_UNFINISHED (-1) +#define CAP_POSITION (-2) typedef struct MatchState { const char *src_init; /* init of source string */ @@ -179,8 +179,8 @@ typedef struct MatchState { } MatchState; -#define L_ESC '%' -#define SPECIALS "^$*+?.([%-" +#define L_ESC '%' +#define SPECIALS "^$*+?.([%-" static int check_capture (MatchState *ms, int l) { @@ -683,14 +683,14 @@ static int str_gsub (lua_State *L) { /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ -#define MAX_ITEM 512 +#define MAX_ITEM 512 /* valid flags in a format specification */ -#define FLAGS "-+ #0" +#define FLAGS "-+ #0" /* ** maximum size of each format specification (such as '%-099.99d') ** (+10 accounts for %99.99x plus margin of error) */ -#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { diff --git a/scripting/lua/lua/ltable.c b/scripting/lua/lua/ltable.c index cb0730ac2d..ec84f4fabc 100644 --- a/scripting/lua/lua/ltable.c +++ b/scripting/lua/lua/ltable.c @@ -39,12 +39,12 @@ ** max size of array part is 2^MAXBITS */ #if LUAI_BITSINT > 26 -#define MAXBITS 26 +#define MAXBITS 26 #else -#define MAXBITS (LUAI_BITSINT-2) +#define MAXBITS (LUAI_BITSINT-2) #endif -#define MAXASIZE (1 << MAXBITS) +#define MAXASIZE (1 << MAXBITS) #define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) @@ -57,20 +57,20 @@ ** for some types, it is better to avoid modulus by power of 2, as ** they tend to have many 2 factors. */ -#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) +#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) -#define hashpointer(t,p) hashmod(t, IntPoint(p)) +#define hashpointer(t,p) hashmod(t, IntPoint(p)) /* ** number of ints inside a lua_Number */ -#define numints cast_int(sizeof(lua_Number)/sizeof(int)) +#define numints cast_int(sizeof(lua_Number)/sizeof(int)) -#define dummynode (&dummynode_) +#define dummynode (&dummynode_) static const Node dummynode_ = { {{NULL}, LUA_TNIL}, /* value */ diff --git a/scripting/lua/lua/ltable.h b/scripting/lua/lua/ltable.h index c043deb9b8..f5b9d5ead0 100644 --- a/scripting/lua/lua/ltable.h +++ b/scripting/lua/lua/ltable.h @@ -10,12 +10,12 @@ #include "lobject.h" -#define gnode(t,i) (&(t)->node[i]) -#define gkey(n) (&(n)->i_key.nk) -#define gval(n) (&(n)->i_val) -#define gnext(n) ((n)->i_key.nk.next) +#define gnode(t,i) (&(t)->node[i]) +#define gkey(n) (&(n)->i_key.nk) +#define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) -#define key2tval(n) (&(n)->i_key.tvk) +#define key2tval(n) (&(n)->i_key.tvk) LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); diff --git a/scripting/lua/lua/ltablib.c b/scripting/lua/lua/ltablib.c index 19daaece91..b6d9cb4ac7 100644 --- a/scripting/lua/lua/ltablib.c +++ b/scripting/lua/lua/ltablib.c @@ -16,7 +16,7 @@ #include "lualib.h" -#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) +#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) static int foreachi (lua_State *L) { diff --git a/scripting/lua/lua/ltm.h b/scripting/lua/lua/ltm.h index c55b234839..64343b781b 100644 --- a/scripting/lua/lua/ltm.h +++ b/scripting/lua/lua/ltm.h @@ -33,7 +33,7 @@ typedef enum { TM_LE, TM_CONCAT, TM_CALL, - TM_N /* number of elements in the enum */ + TM_N /* number of elements in the enum */ } TMS; @@ -41,7 +41,7 @@ typedef enum { #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) -#define fasttm(l,et,e) gfasttm(G(l), et, e) +#define fasttm(l,et,e) gfasttm(G(l), et, e) LUAI_DATA const char *const luaT_typenames[]; diff --git a/scripting/lua/lua/lua.c b/scripting/lua/lua/lua.c index f05d60db75..3add3ee1c5 100644 --- a/scripting/lua/lua/lua.c +++ b/scripting/lua/lua/lua.c @@ -255,7 +255,7 @@ static int handle_script (lua_State *L, char **argv, int n) { /* check that argument has no extra characters at the end */ -#define notail(x) {if ((x)[2] != '\0') return -1;} +#define notail(x) {if ((x)[2] != '\0') return -1;} static int collectargs (char **argv, int *pi, int *pv, int *pe) { @@ -329,64 +329,10 @@ static int handle_luainit (lua_State *L) { return dostring(L, init, "=" LUA_INIT); } -// -//struct Smain { -// int argc; -// char **argv; -// int status; -//}; -// -// -//static int pmain (lua_State *L) { -// struct Smain *s = (struct Smain *)lua_touserdata(L, 1); -// char **argv = s->argv; -// int script; -// int has_i = 0, has_v = 0, has_e = 0; -// globalL = L; -// if (argv[0] && argv[0][0]) progname = argv[0]; -// lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ -// luaL_openlibs(L); /* open libraries */ -// lua_gc(L, LUA_GCRESTART, 0); -// s->status = handle_luainit(L); -// if (s->status != 0) return 0; -// script = collectargs(argv, &has_i, &has_v, &has_e); -// if (script < 0) { /* invalid args? */ -// print_usage(); -// s->status = 1; -// return 0; -// } -// if (has_v) print_version(); -// s->status = runargs(L, argv, (script > 0) ? script : s->argc); -// if (s->status != 0) return 0; -// if (script) -// s->status = handle_script(L, argv, script); -// if (s->status != 0) return 0; -// if (has_i) -// dotty(L); -// else if (script == 0 && !has_e && !has_v) { -// if (lua_stdin_is_tty()) { -// print_version(); -// dotty(L); -// } -// else dofile(L, NULL); /* executes stdin as a file */ -// } -// return 0; -//} -// -// -//int main (int argc, char **argv) { -// int status; -// struct Smain s; -// lua_State *L = lua_open(); /* create state */ -// if (L == NULL) { -// l_message(argv[0], "cannot create state: not enough memory"); -// return EXIT_FAILURE; -// } -// s.argc = argc; -// s.argv = argv; -// status = lua_cpcall(L, &pmain, &s); -// report(L, status); -// lua_close(L); -// return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; -//} + +struct Smain { + int argc; + char **argv; + int status; +}; diff --git a/scripting/lua/lua/lua.h b/scripting/lua/lua/lua.h index 02109346b1..a4b73e743e 100644 --- a/scripting/lua/lua/lua.h +++ b/scripting/lua/lua/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ +** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $ ** Lua - An Extensible Extension Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -16,35 +16,35 @@ #include "luaconf.h" -#define LUA_VERSION "Lua 5.1" -#define LUA_RELEASE "Lua 5.1.4" -#define LUA_VERSION_NUM 501 -#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" -#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" +#define LUA_VERSION "Lua 5.1" +#define LUA_RELEASE "Lua 5.1.5" +#define LUA_VERSION_NUM 501 +#define LUA_COPYRIGHT "Copyright (C) 1994-2012 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" /* mark for precompiled code (`Lua') */ -#define LUA_SIGNATURE "\033Lua" +#define LUA_SIGNATURE "\033Lua" /* option for multiple returns in `lua_pcall' and `lua_call' */ -#define LUA_MULTRET (-1) +#define LUA_MULTRET (-1) /* ** pseudo-indices */ -#define LUA_REGISTRYINDEX (-10000) -#define LUA_ENVIRONINDEX (-10001) -#define LUA_GLOBALSINDEX (-10002) -#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) +#define LUA_REGISTRYINDEX (-10000) +#define LUA_ENVIRONINDEX (-10001) +#define LUA_GLOBALSINDEX (-10002) +#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) /* thread status; 0 is OK */ -#define LUA_YIELD 1 -#define LUA_ERRRUN 2 -#define LUA_ERRSYNTAX 3 -#define LUA_ERRMEM 4 -#define LUA_ERRERR 5 +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 typedef struct lua_State lua_State; @@ -69,22 +69,22 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); /* ** basic types */ -#define LUA_TNONE (-1) +#define LUA_TNONE (-1) -#define LUA_TNIL 0 -#define LUA_TBOOLEAN 1 -#define LUA_TLIGHTUSERDATA 2 -#define LUA_TNUMBER 3 -#define LUA_TSTRING 4 -#define LUA_TTABLE 5 -#define LUA_TFUNCTION 6 -#define LUA_TUSERDATA 7 -#define LUA_TTHREAD 8 +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 /* minimum Lua stack available to a C function */ -#define LUA_MINSTACK 20 +#define LUA_MINSTACK 20 /* @@ -149,7 +149,7 @@ LUA_API int (lua_toboolean) (lua_State *L, int idx); LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); LUA_API size_t (lua_objlen) (lua_State *L, int idx); LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); -LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); LUA_API const void *(lua_topointer) (lua_State *L, int idx); @@ -218,14 +218,14 @@ LUA_API int (lua_status) (lua_State *L); ** garbage-collection function and options */ -#define LUA_GCSTOP 0 -#define LUA_GCRESTART 1 -#define LUA_GCCOLLECT 2 -#define LUA_GCCOUNT 3 -#define LUA_GCCOUNTB 4 -#define LUA_GCSTEP 5 -#define LUA_GCSETPAUSE 6 -#define LUA_GCSETSTEPMUL 7 +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCSETPAUSE 6 +#define LUA_GCSETSTEPMUL 7 LUA_API int (lua_gc) (lua_State *L, int what, int data); @@ -251,32 +251,32 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); ** =============================================================== */ -#define lua_pop(L,n) lua_settop(L, -(n)-1) +#define lua_pop(L,n) lua_settop(L, -(n)-1) -#define lua_newtable(L) lua_createtable(L, 0, 0) +#define lua_newtable(L) lua_createtable(L, 0, 0) #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) -#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) -#define lua_strlen(L,i) lua_objlen(L, (i)) +#define lua_strlen(L,i) lua_objlen(L, (i)) -#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) -#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) -#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) -#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) -#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) -#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) -#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) -#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) -#define lua_pushliteral(L, s) \ - lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) +#define lua_pushliteral(L, s) \ + lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) -#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) -#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) -#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) @@ -284,18 +284,18 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); ** compatibility macros and functions */ -#define lua_open() luaL_newstate() +#define lua_open() luaL_newstate() -#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) +#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) -#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) +#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) -#define lua_Chunkreader lua_Reader -#define lua_Chunkwriter lua_Writer +#define lua_Chunkreader lua_Reader +#define lua_Chunkwriter lua_Writer /* hack */ -LUA_API void lua_setlevel (lua_State *from, lua_State *to); +LUA_API void lua_setlevel (lua_State *from, lua_State *to); /* @@ -308,20 +308,20 @@ LUA_API void lua_setlevel (lua_State *from, lua_State *to); /* ** Event codes */ -#define LUA_HOOKCALL 0 -#define LUA_HOOKRET 1 -#define LUA_HOOKLINE 2 -#define LUA_HOOKCOUNT 3 +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 #define LUA_HOOKTAILRET 4 /* ** Event masks */ -#define LUA_MASKCALL (1 << LUA_HOOKCALL) -#define LUA_MASKRET (1 << LUA_HOOKRET) -#define LUA_MASKLINE (1 << LUA_HOOKLINE) -#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) typedef struct lua_Debug lua_Debug; /* activation record */ @@ -345,14 +345,14 @@ LUA_API int lua_gethookcount (lua_State *L); struct lua_Debug { int event; - const char *name; /* (n) */ - const char *namewhat; /* (n) `global', `local', `field', `method' */ - const char *what; /* (S) `Lua', `C', `main', `tail' */ - const char *source; /* (S) */ - int currentline; /* (l) */ - int nups; /* (u) number of upvalues */ - int linedefined; /* (S) */ - int lastlinedefined; /* (S) */ + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua', `C', `main', `tail' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ char short_src[LUA_IDSIZE]; /* (S) */ /* private part */ int i_ci; /* active function */ @@ -362,7 +362,7 @@ struct lua_Debug { /****************************************************************************** -* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/scripting/lua/lua/luaconf.h b/scripting/lua/lua/luaconf.h index 60db553873..e2cb26163a 100644 --- a/scripting/lua/lua/luaconf.h +++ b/scripting/lua/lua/luaconf.h @@ -35,13 +35,13 @@ #if defined(LUA_USE_LINUX) #define LUA_USE_POSIX -#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ -#define LUA_USE_READLINE /* needs some extra libraries */ +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#define LUA_USE_READLINE /* needs some extra libraries */ #endif #if defined(LUA_USE_MACOSX) #define LUA_USE_POSIX -#define LUA_DL_DYLD /* does not need extra library */ +#define LUA_DL_DYLD /* does not need extra library */ #endif @@ -68,7 +68,7 @@ */ #define LUA_PATH "LUA_PATH" #define LUA_CPATH "LUA_CPATH" -#define LUA_INIT "LUA_INIT" +#define LUA_INIT "LUA_INIT" /* @@ -85,23 +85,23 @@ ** In Windows, any exclamation mark ('!') in the path is replaced by the ** path of the directory of the executable file of the current process. */ -#define LUA_LDIR "!\\lua\\" -#define LUA_CDIR "!\\" +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" #define LUA_PATH_DEFAULT \ - ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ - LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" + ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" #define LUA_CPATH_DEFAULT \ - ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" #else -#define LUA_ROOT "/usr/local/" -#define LUA_LDIR LUA_ROOT "share/lua/5.1/" -#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/5.1/" +#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" #define LUA_PATH_DEFAULT \ - "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ - LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" + "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" #define LUA_CPATH_DEFAULT \ - "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" + "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" #endif @@ -111,9 +111,9 @@ ** and is not Windows. (On Windows Lua automatically uses "\".) */ #if defined(_WIN32) -#define LUA_DIRSEP "\\" +#define LUA_DIRSEP "\\" #else -#define LUA_DIRSEP "/" +#define LUA_DIRSEP "/" #endif @@ -129,10 +129,10 @@ ** characters. (E.g., if one of those characters is a common character ** in file/directory names.) Probably you do not need to change them. */ -#define LUA_PATHSEP ";" -#define LUA_PATH_MARK "?" -#define LUA_EXECDIR "!" -#define LUA_IGMARK "-" +#define LUA_PATHSEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXECDIR "!" +#define LUA_IGMARK "-" /* @@ -140,7 +140,7 @@ ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most ** machines, ptrdiff_t gives a good choice between int or long.) */ -#define LUA_INTEGER ptrdiff_t +#define LUA_INTEGER ptrdiff_t /* @@ -161,12 +161,12 @@ #else -#define LUA_API extern +#define LUA_API extern #endif /* more often than not the libs go together with the core */ -#define LUALIB_API LUA_API +#define LUALIB_API LUA_API /* @@ -179,17 +179,17 @@ ** when Lua is compiled as a shared library. */ #if defined(luaall_c) -#define LUAI_FUNC static -#define LUAI_DATA /* empty */ +#define LUAI_FUNC static +#define LUAI_DATA /* empty */ #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ defined(__ELF__) -#define LUAI_FUNC __attribute__((visibility("hidden"))) extern -#define LUAI_DATA LUAI_FUNC +#define LUAI_FUNC __attribute__((visibility("hidden"))) extern +#define LUAI_DATA LUAI_FUNC #else -#define LUAI_FUNC extern -#define LUAI_DATA extern +#define LUAI_FUNC extern +#define LUAI_DATA extern #endif @@ -198,8 +198,8 @@ @@ LUA_QL describes how error messages quote program elements. ** CHANGE it if you want a different appearance. */ -#define LUA_QL(x) "'" x "'" -#define LUA_QS LUA_QL("%s") +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") /* @@ -207,7 +207,7 @@ @* of a function in debug information. ** CHANGE it if you want a different size. */ -#define LUA_IDSIZE 60 +#define LUA_IDSIZE 60 /* @@ -226,13 +226,13 @@ */ #if defined(LUA_USE_ISATTY) #include -#define lua_stdin_is_tty() isatty(0) +#define lua_stdin_is_tty() isatty(0) #elif defined(LUA_WIN) #include #include -#define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) #else -#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ +#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ #endif @@ -242,8 +242,8 @@ ** CHANGE them if you want different prompts. (You can also change the ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) */ -#define LUA_PROMPT "> " -#define LUA_PROMPT2 ">> " +#define LUA_PROMPT "> " +#define LUA_PROMPT2 ">> " /* @@ -251,7 +251,7 @@ ** CHANGE it if your stand-alone interpreter has a different name and ** your system is not able to detect that name automatically. */ -#define LUA_PROGNAME "lua" +#define LUA_PROGNAME "lua" /* @@ -259,7 +259,7 @@ @* stand-alone interpreter. ** CHANGE it if you need longer lines. */ -#define LUA_MAXINPUT 512 +#define LUA_MAXINPUT 512 /* @@ -274,17 +274,17 @@ #include #include #include -#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) +#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) #define lua_saveline(L,idx) \ - if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ - add_history(lua_tostring(L, idx)); /* add it to history */ -#define lua_freeline(L,b) ((void)L, free(b)) + if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ + add_history(lua_tostring(L, idx)); /* add it to history */ +#define lua_freeline(L,b) ((void)L, free(b)) #else -#define lua_readline(L,b,p) \ - ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ - fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ -#define lua_saveline(L,idx) { (void)L; (void)idx; } -#define lua_freeline(L,b) { (void)L; (void)b; } +#define lua_readline(L,b,p) \ + ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ + fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ +#define lua_saveline(L,idx) { (void)L; (void)idx; } +#define lua_freeline(L,b) { (void)L; (void)b; } #endif #endif @@ -299,7 +299,7 @@ ** mean larger pauses which mean slower collection.) You can also change ** this value dynamically. */ -#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ +#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ /* @@ -310,7 +310,7 @@ ** infinity, where each step performs a full collection.) You can also ** change this value dynamically. */ -#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ +#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ @@ -348,7 +348,7 @@ ** CHANGE it to 2 if you want the old behaviour, or undefine it to turn ** off the advisory error when nesting [[...]]. */ -#define LUA_COMPAT_LSTR 1 +#define LUA_COMPAT_LSTR 1 /* @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. @@ -376,9 +376,9 @@ */ #if defined(LUA_USE_APICHECK) #include -#define luai_apicheck(L,o) { (void)L; assert(o); } +#define luai_apicheck(L,o) { (void)L; assert(o); } #else -#define luai_apicheck(L,o) { (void)L; } +#define luai_apicheck(L,o) { (void)L; } #endif @@ -389,10 +389,10 @@ */ /* avoid overflows in comparison */ #if INT_MAX-20 < 32760 -#define LUAI_BITSINT 16 +#define LUAI_BITSINT 16 #elif INT_MAX > 2147483640L /* int has at least 32 bits */ -#define LUAI_BITSINT 32 +#define LUAI_BITSINT 32 #else #error "you must define LUA_BITSINT with number of bits in an integer" #endif @@ -411,18 +411,18 @@ ** longs.) Probably you do not need to change this. */ #if LUAI_BITSINT >= 32 -#define LUAI_UINT32 unsigned int -#define LUAI_INT32 int -#define LUAI_MAXINT32 INT_MAX -#define LUAI_UMEM size_t -#define LUAI_MEM ptrdiff_t +#define LUAI_UINT32 unsigned int +#define LUAI_INT32 int +#define LUAI_MAXINT32 INT_MAX +#define LUAI_UMEM size_t +#define LUAI_MEM ptrdiff_t #else /* 16-bit ints */ -#define LUAI_UINT32 unsigned long -#define LUAI_INT32 long -#define LUAI_MAXINT32 LONG_MAX -#define LUAI_UMEM unsigned long -#define LUAI_MEM long +#define LUAI_UINT32 unsigned long +#define LUAI_INT32 long +#define LUAI_MAXINT32 LONG_MAX +#define LUAI_UMEM unsigned long +#define LUAI_MEM long #endif @@ -432,7 +432,7 @@ ** arbitrary; its only purpose is to stop infinite recursion before ** exhausting memory. */ -#define LUAI_MAXCALLS 20000 +#define LUAI_MAXCALLS 20000 /* @@ -443,7 +443,7 @@ ** functions to consume unlimited stack space. (must be smaller than ** -LUA_REGISTRYINDEX) */ -#define LUAI_MAXCSTACK 8000 +#define LUAI_MAXCSTACK 8000 @@ -465,27 +465,27 @@ @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and @* syntactical nested non-terminals in a program. */ -#define LUAI_MAXCCALLS 200 +#define LUAI_MAXCCALLS 200 /* @@ LUAI_MAXVARS is the maximum number of local variables per function @* (must be smaller than 250). */ -#define LUAI_MAXVARS 200 +#define LUAI_MAXVARS 200 /* @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function @* (must be smaller than 250). */ -#define LUAI_MAXUPVALUES 60 +#define LUAI_MAXUPVALUES 60 /* @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. */ -#define LUAL_BUFFERSIZE BUFSIZ +#define LUAL_BUFFERSIZE BUFSIZ /* }================================================================== */ @@ -502,13 +502,13 @@ */ #define LUA_NUMBER_DOUBLE -#define LUA_NUMBER double +#define LUA_NUMBER double /* @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' @* over a number. */ -#define LUAI_UACNUMBER double +#define LUAI_UACNUMBER double /* @@ -518,11 +518,11 @@ @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. @@ lua_str2number converts a string to a number. */ -#define LUA_NUMBER_SCAN "%lf" -#define LUA_NUMBER_FMT "%.14g" -#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) -#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ -#define lua_str2number(s,p) strtod((s), (p)) +#define LUA_NUMBER_SCAN "%lf" +#define LUA_NUMBER_FMT "%.14g" +#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ +#define lua_str2number(s,p) strtod((s), (p)) /* @@ -530,17 +530,17 @@ */ #if defined(LUA_CORE) #include -#define luai_numadd(a,b) ((a)+(b)) -#define luai_numsub(a,b) ((a)-(b)) -#define luai_nummul(a,b) ((a)*(b)) -#define luai_numdiv(a,b) ((a)/(b)) -#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) -#define luai_numpow(a,b) (pow(a,b)) -#define luai_numunm(a) (-(a)) -#define luai_numeq(a,b) ((a)==(b)) -#define luai_numlt(a,b) ((a)<(b)) -#define luai_numle(a,b) ((a)<=(b)) -#define luai_numisnan(a) (!luai_numeq((a), (a))) +#define luai_numadd(a,b) ((a)+(b)) +#define luai_numsub(a,b) ((a)-(b)) +#define luai_nummul(a,b) ((a)*(b)) +#define luai_numdiv(a,b) ((a)/(b)) +#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) +#define luai_numpow(a,b) (pow(a,b)) +#define luai_numunm(a) (-(a)) +#define luai_numeq(a,b) ((a)==(b)) +#define luai_numlt(a,b) ((a)<(b)) +#define luai_numle(a,b) ((a)<=(b)) +#define luai_numisnan(a) (!luai_numeq((a), (a))) #endif @@ -561,7 +561,7 @@ #if defined(_MSC_VER) #define lua_number2int(i,d) __asm fld d __asm fistp i -#define lua_number2integer(i,n) lua_number2int(i, n) +#define lua_number2integer(i,n) lua_number2int(i, n) /* the next trick should work on any Pentium, but sometimes clashes with a DirectX idiosyncrasy */ @@ -570,15 +570,15 @@ union luai_Cast { double l_d; long l_l; }; #define lua_number2int(i,d) \ { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } -#define lua_number2integer(i,n) lua_number2int(i, n) +#define lua_number2integer(i,n) lua_number2int(i, n) #endif /* this option always works, but may be slow */ #else -#define lua_number2int(i,d) ((i)=(int)(d)) -#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) +#define lua_number2int(i,d) ((i)=(int)(d)) +#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) #endif @@ -592,7 +592,7 @@ union luai_Cast { double l_d; long l_l; }; ** aligned in 16-byte boundaries, then you should add long double in the ** union.) Probably you do not need to change this. */ -#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } +#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } /* @@ -605,22 +605,22 @@ union luai_Cast { double l_d; long l_l; }; */ #if defined(__cplusplus) /* C++ exceptions */ -#define LUAI_THROW(L,c) throw(c) -#define LUAI_TRY(L,c,a) try { a } catch(...) \ - { if ((c)->status == 0) (c)->status = -1; } -#define luai_jmpbuf int /* dummy variable */ +#define LUAI_THROW(L,c) throw(c) +#define LUAI_TRY(L,c,a) try { a } catch(...) \ + { if ((c)->status == 0) (c)->status = -1; } +#define luai_jmpbuf int /* dummy variable */ #elif defined(LUA_USE_ULONGJMP) /* in Unix, try _longjmp/_setjmp (more efficient) */ -#define LUAI_THROW(L,c) _longjmp((c)->b, 1) -#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } -#define luai_jmpbuf jmp_buf +#define LUAI_THROW(L,c) _longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf #else /* default handling with long jumps */ -#define LUAI_THROW(L,c) longjmp((c)->b, 1) -#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } -#define luai_jmpbuf jmp_buf +#define LUAI_THROW(L,c) longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf #endif @@ -630,7 +630,7 @@ union luai_Cast { double l_d; long l_l; }; @* can do during pattern-matching. ** CHANGE it if you need more captures. This limit is arbitrary. */ -#define LUA_MAXCAPTURES 32 +#define LUA_MAXCAPTURES 32 /* @@ -645,16 +645,16 @@ union luai_Cast { double l_d; long l_l; }; #if defined(LUA_USE_MKSTEMP) #include -#define LUA_TMPNAMBUFSIZE 32 -#define lua_tmpnam(b,e) { \ - strcpy(b, "/tmp/lua_XXXXXX"); \ - e = mkstemp(b); \ - if (e != -1) close(e); \ - e = (e == -1); } +#define LUA_TMPNAMBUFSIZE 32 +#define lua_tmpnam(b,e) { \ + strcpy(b, "/tmp/lua_XXXXXX"); \ + e = mkstemp(b); \ + if (e != -1) close(e); \ + e = (e == -1); } #else -#define LUA_TMPNAMBUFSIZE L_tmpnam -#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } +#define LUA_TMPNAMBUFSIZE L_tmpnam +#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } #endif #endif @@ -667,19 +667,19 @@ union luai_Cast { double l_d; long l_l; }; */ #if defined(LUA_USE_POPEN) -#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) -#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) +#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) #elif defined(LUA_WIN) -#define lua_popen(L,c,m) ((void)L, _popen(c,m)) -#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) +#define lua_popen(L,c,m) ((void)L, _popen(c,m)) +#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) #else -#define lua_popen(L,c,m) ((void)((void)c, m), \ - luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) -#define lua_pclose(L,file) ((void)((void)L, file), 0) +#define lua_popen(L,c,m) ((void)((void)c, m), \ + luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) +#define lua_pclose(L,file) ((void)((void)L, file), 0) #endif @@ -712,7 +712,7 @@ union luai_Cast { double l_d; long l_l; }; ** CHANGE (define) this if you really need that. This value must be ** a multiple of the maximum alignment required for your machine. */ -#define LUAI_EXTRASPACE 0 +#define LUAI_EXTRASPACE 0 /* @@ -720,12 +720,12 @@ union luai_Cast { double l_d; long l_l; }; ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something ** extra when a thread is created/deleted/resumed/yielded. */ -#define luai_userstateopen(L) ((void)L) -#define luai_userstateclose(L) ((void)L) -#define luai_userstatethread(L,L1) ((void)L) -#define luai_userstatefree(L) ((void)L) -#define luai_userstateresume(L,n) ((void)L) -#define luai_userstateyield(L,n) ((void)L) +#define luai_userstateopen(L) ((void)L) +#define luai_userstateclose(L) ((void)L) +#define luai_userstatethread(L,L1) ((void)L) +#define luai_userstatefree(L) ((void)L) +#define luai_userstateresume(L,n) ((void)L) +#define luai_userstateyield(L,n) ((void)L) /* @@ -738,13 +738,13 @@ union luai_Cast { double l_d; long l_l; }; #if defined(LUA_USELONGLONG) -#define LUA_INTFRMLEN "ll" -#define LUA_INTFRM_T long long +#define LUA_INTFRMLEN "ll" +#define LUA_INTFRM_T long long #else -#define LUA_INTFRMLEN "l" -#define LUA_INTFRM_T long +#define LUA_INTFRMLEN "l" +#define LUA_INTFRM_T long #endif diff --git a/scripting/lua/lua/lualib.h b/scripting/lua/lua/lualib.h index 08d8df3d4d..469417f670 100644 --- a/scripting/lua/lua/lualib.h +++ b/scripting/lua/lua/lualib.h @@ -12,31 +12,31 @@ /* Key to file-handle type */ -#define LUA_FILEHANDLE "FILE*" +#define LUA_FILEHANDLE "FILE*" -#define LUA_COLIBNAME "coroutine" +#define LUA_COLIBNAME "coroutine" LUALIB_API int (luaopen_base) (lua_State *L); -#define LUA_TABLIBNAME "table" +#define LUA_TABLIBNAME "table" LUALIB_API int (luaopen_table) (lua_State *L); -#define LUA_IOLIBNAME "io" +#define LUA_IOLIBNAME "io" LUALIB_API int (luaopen_io) (lua_State *L); -#define LUA_OSLIBNAME "os" +#define LUA_OSLIBNAME "os" LUALIB_API int (luaopen_os) (lua_State *L); -#define LUA_STRLIBNAME "string" +#define LUA_STRLIBNAME "string" LUALIB_API int (luaopen_string) (lua_State *L); -#define LUA_MATHLIBNAME "math" +#define LUA_MATHLIBNAME "math" LUALIB_API int (luaopen_math) (lua_State *L); -#define LUA_DBLIBNAME "debug" +#define LUA_DBLIBNAME "debug" LUALIB_API int (luaopen_debug) (lua_State *L); -#define LUA_LOADLIBNAME "package" +#define LUA_LOADLIBNAME "package" LUALIB_API int (luaopen_package) (lua_State *L); @@ -46,7 +46,7 @@ LUALIB_API void (luaL_openlibs) (lua_State *L); #ifndef lua_assert -#define lua_assert(x) ((void)0) +#define lua_assert(x) ((void)0) #endif diff --git a/scripting/lua/lua/lundump.c b/scripting/lua/lua/lundump.c index 1db09e6b56..8010a45795 100644 --- a/scripting/lua/lua/lundump.c +++ b/scripting/lua/lua/lundump.c @@ -31,7 +31,7 @@ typedef struct { #define IF(c,s) #define error(S,s) #else -#define IF(c,s) if (c) error(S,s) +#define IF(c,s) if (c) error(S,s) static void error(LoadState* S, const char* why) { @@ -40,10 +40,10 @@ static void error(LoadState* S, const char* why) } #endif -#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) -#define LoadByte(S) (lu_byte)LoadChar(S) -#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) -#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) +#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) +#define LoadByte(S) (lu_byte)LoadChar(S) +#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) +#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) static void LoadBlock(LoadState* S, void* b, size_t size) { @@ -83,7 +83,7 @@ static TString* LoadString(LoadState* S) { char* s=luaZ_openspace(S->L,S->b,size); LoadBlock(S,s,size); - return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ + return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ } } @@ -111,20 +111,20 @@ static void LoadConstants(LoadState* S, Proto* f) switch (t) { case LUA_TNIL: - setnilvalue(o); - break; + setnilvalue(o); + break; case LUA_TBOOLEAN: - setbvalue(o,LoadChar(S)!=0); - break; + setbvalue(o,LoadChar(S)!=0); + break; case LUA_TNUMBER: - setnvalue(o,LoadNumber(S)); - break; + setnvalue(o,LoadNumber(S)); + break; case LUA_TSTRING: - setsvalue2n(S->L,o,LoadString(S)); - break; + setsvalue2n(S->L,o,LoadString(S)); + break; default: - error(S,"bad constant"); - break; + error(S,"bad constant"); + break; } } n=LoadInt(S); @@ -218,10 +218,10 @@ void luaU_header (char* h) h+=sizeof(LUA_SIGNATURE)-1; *h++=(char)LUAC_VERSION; *h++=(char)LUAC_FORMAT; - *h++=(char)*(char*)&x; /* endianness */ + *h++=(char)*(char*)&x; /* endianness */ *h++=(char)sizeof(int); *h++=(char)sizeof(size_t); *h++=(char)sizeof(Instruction); *h++=(char)sizeof(lua_Number); - *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ + *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ } diff --git a/scripting/lua/lua/lundump.h b/scripting/lua/lua/lundump.h index 491d691cc0..c80189dbff 100644 --- a/scripting/lua/lua/lundump.h +++ b/scripting/lua/lua/lundump.h @@ -25,12 +25,12 @@ LUAI_FUNC void luaU_print (const Proto* f, int full); #endif /* for header of binary files -- this is Lua 5.1 */ -#define LUAC_VERSION 0x51 +#define LUAC_VERSION 0x51 /* for header of binary files -- this is the official format */ -#define LUAC_FORMAT 0 +#define LUAC_FORMAT 0 /* size of header of binary files */ -#define LUAC_HEADERSIZE 12 +#define LUAC_HEADERSIZE 12 #endif diff --git a/scripting/lua/lua/lvm.c b/scripting/lua/lua/lvm.c index b18e51aa7e..e0a0cd8521 100644 --- a/scripting/lua/lua/lvm.c +++ b/scripting/lua/lua/lvm.c @@ -29,7 +29,7 @@ /* limit for table tag-method chains (to avoid loops) */ -#define MAXTAGLOOP 100 +#define MAXTAGLOOP 100 const TValue *luaV_tonumber (const TValue *obj, TValue *n) { @@ -342,23 +342,23 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, ** some macros for common tasks in `luaV_execute' */ -#define runtime_check(L, c) { if (!(c)) break; } +#define runtime_check(L, c) { if (!(c)) break; } -#define RA(i) (base+GETARG_A(i)) +#define RA(i) (base+GETARG_A(i)) /* to be used after possible stack reallocation */ -#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) -#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) -#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ - ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) -#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ - ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) -#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) +#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) +#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) +#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) +#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) +#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) -#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} -#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } #define arith_op(op,tm) { \ diff --git a/scripting/lua/lua/lvm.h b/scripting/lua/lua/lvm.h index 484121b69b..bfe4f5678d 100644 --- a/scripting/lua/lua/lvm.h +++ b/scripting/lua/lua/lvm.h @@ -15,11 +15,11 @@ #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) -#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ (((o) = luaV_tonumber(o,n)) != NULL)) #define equalobj(L,o1,o2) \ - (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) + (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); diff --git a/scripting/lua/lua/lzio.h b/scripting/lua/lua/lzio.h index 38c60b16bd..51d695d8c1 100644 --- a/scripting/lua/lua/lzio.h +++ b/scripting/lua/lua/lzio.h @@ -13,11 +13,11 @@ #include "lmem.h" -#define EOZ (-1) /* end of stream */ +#define EOZ (-1) /* end of stream */ typedef struct Zio ZIO; -#define char2int(c) cast(int, cast(unsigned char, (c))) +#define char2int(c) cast(int, cast(unsigned char, (c))) #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) @@ -29,24 +29,24 @@ typedef struct Mbuffer { #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) -#define luaZ_buffer(buff) ((buff)->buffer) -#define luaZ_sizebuffer(buff) ((buff)->buffsize) -#define luaZ_bufflen(buff) ((buff)->n) +#define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) #define luaZ_resetbuffer(buff) ((buff)->n = 0) #define luaZ_resizebuffer(L, buff, size) \ - (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ - (buff)->buffsize = size) + (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ + (buff)->buffsize = size) -#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) +#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data); -LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ LUAI_FUNC int luaZ_lookahead (ZIO *z); @@ -54,11 +54,11 @@ LUAI_FUNC int luaZ_lookahead (ZIO *z); /* --------- Private Part ------------------ */ struct Zio { - size_t n; /* bytes still unread */ - const char *p; /* current position in buffer */ + size_t n; /* bytes still unread */ + const char *p; /* current position in buffer */ lua_Reader reader; - void* data; /* additional data */ - lua_State *L; /* Lua state (for reader) */ + void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ }; diff --git a/scripting/lua/lua/print.c b/scripting/lua/lua/print.c index 800706aa4e..e240cfc3c6 100644 --- a/scripting/lua/lua/print.c +++ b/scripting/lua/lua/print.c @@ -15,10 +15,10 @@ #include "lopcodes.h" #include "lundump.h" -#define PrintFunction luaU_print +#define PrintFunction luaU_print -#define Sizeof(x) ((int)sizeof(x)) -#define VOID(p) ((const void*)(p)) +#define Sizeof(x) ((int)sizeof(x)) +#define VOID(p) ((const void*)(p)) static void PrintString(const TString* ts) { @@ -39,10 +39,10 @@ static void PrintString(const TString* ts) case '\r': printf("\\r"); break; case '\t': printf("\\t"); break; case '\v': printf("\\v"); break; - default: if (isprint((unsigned char)c)) - putchar(c); - else - printf("\\%03u",(unsigned char)c); + default: if (isprint((unsigned char)c)) + putchar(c); + else + printf("\\%03u",(unsigned char)c); } } putchar('"'); @@ -54,20 +54,20 @@ static void PrintConstant(const Proto* f, int i) switch (ttype(o)) { case LUA_TNIL: - printf("nil"); - break; + printf("nil"); + break; case LUA_TBOOLEAN: - printf(bvalue(o) ? "true" : "false"); - break; + printf(bvalue(o) ? "true" : "false"); + break; case LUA_TNUMBER: - printf(LUA_NUMBER_FMT,nvalue(o)); - break; + printf(LUA_NUMBER_FMT,nvalue(o)); + break; case LUA_TSTRING: - PrintString(rawtsvalue(o)); - break; - default: /* cannot happen */ - printf("? type=%d",ttype(o)); - break; + PrintString(rawtsvalue(o)); + break; + default: /* cannot happen */ + printf("? type=%d",ttype(o)); + break; } } @@ -155,8 +155,8 @@ static void PrintCode(const Proto* f) } } -#define SS(x) (x==1)?"":"s" -#define S(x) x,SS(x) +#define SS(x) (x==1)?"":"s" +#define S(x) x,SS(x) static void PrintHeader(const Proto* f) { @@ -168,14 +168,14 @@ static void PrintHeader(const Proto* f) else s="(string)"; printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", - (f->linedefined==0)?"main":"function",s, - f->linedefined,f->lastlinedefined, - S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); + (f->linedefined==0)?"main":"function",s, + f->linedefined,f->lastlinedefined, + S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); printf("%d%s param%s, %d slot%s, %d upvalue%s, ", - f->numparams,f->is_vararg?"+":"",SS(f->numparams), - S(f->maxstacksize),S(f->nups)); + f->numparams,f->is_vararg?"+":"",SS(f->numparams), + S(f->maxstacksize),S(f->nups)); printf("%d local%s, %d constant%s, %d function%s\n", - S(f->sizelocvars),S(f->sizek),S(f->sizep)); + S(f->sizelocvars),S(f->sizek),S(f->sizep)); } static void PrintConstants(const Proto* f) diff --git a/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp index 88577cd02c..01eedc43ca 100644 --- a/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp @@ -51,7 +51,7 @@ void AppDelegate::applicationDidEnterBackground() { CCDirector::sharedDirector()->pause(); - // if you use SimpleAudioEngine, it must be pause + // if you use SimpleAudioEngine, it must be paused // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); } diff --git a/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.h b/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.h index d02100efd0..3a7d36517a 100644 --- a/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.h +++ b/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.h @@ -14,7 +14,7 @@ /** @brief The cocos2d Application. -The reason for implement as private inheritance is to hide some interface call by CCDirector. +The reason to implement with private inheritance is to hide some interface details of CCDirector. */ class AppDelegate : private cocos2d::CCApplication { @@ -30,14 +30,14 @@ public: virtual bool applicationDidFinishLaunching(); /** - @brief The function be called when the application enter background - @param the pointer of the application + @brief The function is called when the application enters the background + @param the pointer of the application instance */ virtual void applicationDidEnterBackground(); /** - @brief The function be called when the application enter foreground - @param the pointer of the application + @brief The function is called when the application enters the foreground + @param the pointer of the application instance */ virtual void applicationWillEnterForeground(); }; diff --git a/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.h b/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.h index e202b8c2c3..82416bdc22 100644 --- a/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.h +++ b/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.h @@ -6,16 +6,16 @@ class HelloWorld : public cocos2d::CCLayer { public: - // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone - virtual bool init(); + // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer) + virtual bool init(); - // there's no 'id' in cpp, so we recommand to return the exactly class pointer + // there's no 'id' in cpp, so we recommend to return the class instance pointer static cocos2d::CCScene* scene(); // a selector callback void menuCloseCallback(CCObject* pSender); - // implement the "static node()" method manually + // preprocessor macro for "static create()" constructor ( node() deprecated ) CREATE_FUNC(HelloWorld); }; diff --git a/template/xcode4/cocos2dx.xctemplate/ios/AppController.h b/template/xcode4/cocos2dx.xctemplate/ios/AppController.h index 4bd3952824..4f51fc6229 100644 --- a/template/xcode4/cocos2dx.xctemplate/ios/AppController.h +++ b/template/xcode4/cocos2dx.xctemplate/ios/AppController.h @@ -13,5 +13,8 @@ RootViewController *viewController; } +@property (nonatomic, retain) UIWindow *window; +@property (nonatomic, retain) RootViewController *viewController; + @end diff --git a/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm index 96281719a6..bf7505012c 100644 --- a/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm @@ -15,6 +15,9 @@ @implementation AppController +@synthesize window; +@synthesize viewController; + #pragma mark - #pragma mark Application lifecycle @@ -76,7 +79,7 @@ static AppDelegate s_sharedApplication; - (void)applicationWillEnterForeground:(UIApplication *)application { /* - Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. + Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. */ cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground(); } diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp index 41237a35e9..0a066f1849 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp @@ -51,7 +51,7 @@ void AppDelegate::applicationDidEnterBackground() { CCDirector::sharedDirector()->stopAnimation(); - // if you use SimpleAudioEngine, it must be pause + // if you use SimpleAudioEngine, it must be paused // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); } diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.h b/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.h index 4bd3952824..4f51fc6229 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.h +++ b/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.h @@ -13,5 +13,8 @@ RootViewController *viewController; } +@property (nonatomic, retain) UIWindow *window; +@property (nonatomic, retain) RootViewController *viewController; + @end diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm index 520b117ea2..a9bf46f84a 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm @@ -15,6 +15,9 @@ @implementation AppController +@synthesize window; +@synthesize viewController; + #pragma mark - #pragma mark Application lifecycle diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.h b/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.h index 4bd3952824..4f51fc6229 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.h +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.h @@ -13,5 +13,8 @@ RootViewController *viewController; } +@property (nonatomic, retain) UIWindow *window; +@property (nonatomic, retain) RootViewController *viewController; + @end diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm index 833f59255d..da90ebfae0 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm @@ -15,6 +15,9 @@ @implementation AppController +@synthesize window; +@synthesize viewController; + #pragma mark - #pragma mark Application lifecycle diff --git a/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.h b/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.h index 3d51064ca0..b05d7bf9f7 100644 --- a/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.h +++ b/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.h @@ -29,5 +29,8 @@ RootViewController *viewController; } +@property (nonatomic, retain) UIWindow *window; +@property (nonatomic, retain) RootViewController *viewController; + @end diff --git a/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.mm index 96281719a6..82acce0269 100644 --- a/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx_js.xctemplate/ios/AppController.mm @@ -15,6 +15,9 @@ @implementation AppController +@synthesize window; +@synthesize viewController; + #pragma mark - #pragma mark Application lifecycle diff --git a/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.h b/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.h index 3d51064ca0..b05d7bf9f7 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.h +++ b/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.h @@ -29,5 +29,8 @@ RootViewController *viewController; } +@property (nonatomic, retain) UIWindow *window; +@property (nonatomic, retain) RootViewController *viewController; + @end diff --git a/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm index 6b27e1dcc9..a9cd27a2fe 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm @@ -31,6 +31,9 @@ @implementation AppController +@synthesize window; +@synthesize viewController; + #pragma mark - #pragma mark Application lifecycle diff --git a/tools/JenkinsScript/Monkeyrunner_TestCpp.py b/tools/jenkins_scripts/Monkeyrunner_TestCpp.py similarity index 100% rename from tools/JenkinsScript/Monkeyrunner_TestCpp.py rename to tools/jenkins_scripts/Monkeyrunner_TestCpp.py diff --git a/tools/JenkinsScript/ReportManager.py b/tools/jenkins_scripts/ReportManager.py similarity index 100% rename from tools/JenkinsScript/ReportManager.py rename to tools/jenkins_scripts/ReportManager.py diff --git a/tools/JenkinsScript/ant.properties b/tools/jenkins_scripts/ant.properties similarity index 100% rename from tools/JenkinsScript/ant.properties rename to tools/jenkins_scripts/ant.properties diff --git a/tools/JenkinsScript/build.xml b/tools/jenkins_scripts/build.xml similarity index 100% rename from tools/JenkinsScript/build.xml rename to tools/jenkins_scripts/build.xml diff --git a/tools/JenkinsScript/Mac/android/AndroidCompile-debug2_2-3_2.sh b/tools/jenkins_scripts/mac/android/build-android-2.2-3.2-debug.sh similarity index 79% rename from tools/JenkinsScript/Mac/android/AndroidCompile-debug2_2-3_2.sh rename to tools/jenkins_scripts/mac/android/build-android-2.2-3.2-debug.sh index 3893270da5..e671ed7ad8 100755 --- a/tools/JenkinsScript/Mac/android/AndroidCompile-debug2_2-3_2.sh +++ b/tools/jenkins_scripts/mac/android/build-android-2.2-3.2-debug.sh @@ -88,11 +88,11 @@ ROOT=$(pwd) IsTestCpp=1 #copy configuration files to target. -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/TestCpp/proj.android cd samples/TestCpp/proj.android -sh rootconfig-Mac.sh TestCpp +sh rootconfig-mac.sh TestCpp sh build_native.sh #update android project configuration files @@ -103,22 +103,22 @@ antcompile IsTestCpp=0 -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloCpp/proj.android cd ../../HelloCpp/proj.android -sh rootconfig-Mac.sh HelloCpp +sh rootconfig-mac.sh HelloCpp sh build_native.sh cd .. android update project -p proj.android cd proj.android antcompile -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloLua/proj.android cd ../../HelloLua/proj.android -sh rootconfig-Mac.sh HelloLua +sh rootconfig-mac.sh HelloLua sh build_native.sh cd .. android update project -p proj.android diff --git a/tools/JenkinsScript/Mac/android/AndroidCompile-release2_2-3_2.sh b/tools/jenkins_scripts/mac/android/build-android-2.2-3.2-release.sh similarity index 80% rename from tools/JenkinsScript/Mac/android/AndroidCompile-release2_2-3_2.sh rename to tools/jenkins_scripts/mac/android/build-android-2.2-3.2-release.sh index 8bacaf29f1..f3362a662e 100755 --- a/tools/JenkinsScript/Mac/android/AndroidCompile-release2_2-3_2.sh +++ b/tools/jenkins_scripts/mac/android/build-android-2.2-3.2-release.sh @@ -92,11 +92,11 @@ sed -i '' '14d' $CUR/ant.properties gsed -i "14 i\\key.store=$ANDROID_HOME/debug.keystore" $CUR/ant.properties cp $CUR/../debug.keystore $ANDROID_HOME -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/TestCpp/proj.android cd samples/TestCpp/proj.android -sh rootconfig-Mac.sh TestCpp +sh rootconfig-mac.sh TestCpp sh build_native.sh #update android project configuration files @@ -107,22 +107,22 @@ antcompile IsTestCpp=0 -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloCpp/proj.android cd ../../HelloCpp/proj.android -sh rootconfig-Mac.sh HelloCpp +sh rootconfig-mac.sh HelloCpp sh build_native.sh cd .. android update project -p proj.android cd proj.android antcompile -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloLua/proj.android cd ../../HelloLua/proj.android -sh rootconfig-Mac.sh HelloLua +sh rootconfig-mac.sh HelloLua sh build_native.sh cd .. android update project -p proj.android diff --git a/tools/JenkinsScript/Mac/android/AndroidCompile-debug4_0-4_0_3.sh b/tools/jenkins_scripts/mac/android/build-android-4.x-debug.sh similarity index 69% rename from tools/JenkinsScript/Mac/android/AndroidCompile-debug4_0-4_0_3.sh rename to tools/jenkins_scripts/mac/android/build-android-4.x-debug.sh index 5d5c442af4..525ef60562 100755 --- a/tools/JenkinsScript/Mac/android/AndroidCompile-debug4_0-4_0_3.sh +++ b/tools/jenkins_scripts/mac/android/build-android-4.x-debug.sh @@ -10,7 +10,7 @@ antcompile() sed '/target=/s/=.*$/=android-14/' ant.properties > anttmp.properties cp anttmp.properties ant.properties rm anttmp.properties - ant release + ant debug compileresult=$[$compileresult+$?] if [ $IsTestCpp == 1 ] && [ $? == 0 ] then @@ -23,7 +23,7 @@ antcompile() sed '/target=/s/=.*$/=android-15/' ant.properties > anttmp.properties cp anttmp.properties ant.properties rm anttmp.properties - ant release + ant debug compileresult=$[$compileresult+$?] if [ $IsTestCpp == 1 ] && [ $? == 0 ] then @@ -46,11 +46,11 @@ ROOT=$(pwd) IsTestCpp=1 #copy configuration files to target. -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/TestCpp/proj.android cd samples/TestCpp/proj.android -sh rootconfig-Mac.sh TestCpp +sh rootconfig-mac.sh TestCpp sh build_native.sh #update android project configuration files @@ -61,22 +61,22 @@ antcompile IsTestCpp=0 -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloCpp/proj.android cd ../../HelloCpp/proj.android -sh rootconfig-Mac.sh HelloCpp +sh rootconfig-mac.sh HelloCpp sh build_native.sh cd .. android update project -p proj.android cd proj.android antcompile -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloLua/proj.android cd ../../HelloLua/proj.android -sh rootconfig-Mac.sh HelloLua +sh rootconfig-mac.sh HelloLua sh build_native.sh cd .. android update project -p proj.android @@ -93,4 +93,4 @@ else # git checkout -f # git clean -df -x exit 0 -fi \ No newline at end of file +fi diff --git a/tools/JenkinsScript/Mac/android/AndroidCompile-release4_0-4_0_3.sh b/tools/jenkins_scripts/mac/android/build-android-4.x-release.sh similarity index 71% rename from tools/JenkinsScript/Mac/android/AndroidCompile-release4_0-4_0_3.sh rename to tools/jenkins_scripts/mac/android/build-android-4.x-release.sh index 340b477315..2cac53da27 100755 --- a/tools/JenkinsScript/Mac/android/AndroidCompile-release4_0-4_0_3.sh +++ b/tools/jenkins_scripts/mac/android/build-android-4.x-release.sh @@ -50,11 +50,11 @@ sed -i '' '14d' $CUR/ant.properties gsed -i "14 i\\key.store=$ANDROID_HOME/debug.keystore" $CUR/ant.properties cp $CUR/../debug.keystore $ANDROID_HOME -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/TestCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/TestCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/TestCpp/proj.android cd samples/TestCpp/proj.android -sh rootconfig-Mac.sh TestCpp +sh rootconfig-mac.sh TestCpp sh build_native.sh #update android project configuration files @@ -65,22 +65,22 @@ antcompile IsTestCpp=0 -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloCpp/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloCpp/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloCpp/proj.android cd ../../HelloCpp/proj.android -sh rootconfig-Mac.sh HelloCpp +sh rootconfig-mac.sh HelloCpp sh build_native.sh cd .. android update project -p proj.android cd proj.android antcompile -cp $ROOT/tools/JenkinsScript/ant.properties $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/build.xml $ROOT/samples/HelloLua/proj.android -cp $ROOT/tools/JenkinsScript/Mac/rootconfig-Mac.sh $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/ant.properties $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/build.xml $ROOT/samples/HelloLua/proj.android +cp $ROOT/tools/jenkins_scripts/mac/rootconfig-mac.sh $ROOT/samples/HelloLua/proj.android cd ../../HelloLua/proj.android -sh rootconfig-Mac.sh HelloLua +sh rootconfig-mac.sh HelloLua sh build_native.sh cd .. android update project -p proj.android diff --git a/tools/JenkinsScript/Mac/android/AndroidTest-debug2_2-3_2.sh b/tools/jenkins_scripts/mac/android/test-android-2.2-3.2-debug.sh similarity index 100% rename from tools/JenkinsScript/Mac/android/AndroidTest-debug2_2-3_2.sh rename to tools/jenkins_scripts/mac/android/test-android-2.2-3.2-debug.sh diff --git a/tools/JenkinsScript/Mac/android/AndroidTest-release2_2-3_2.sh b/tools/jenkins_scripts/mac/android/test-android-2.2-3.2-release.sh similarity index 100% rename from tools/JenkinsScript/Mac/android/AndroidTest-release2_2-3_2.sh rename to tools/jenkins_scripts/mac/android/test-android-2.2-3.2-release.sh diff --git a/tools/JenkinsScript/Mac/android/AndroidTest-debug4_0-4_0_3.sh b/tools/jenkins_scripts/mac/android/test-android-4.x-debug.sh similarity index 100% rename from tools/JenkinsScript/Mac/android/AndroidTest-debug4_0-4_0_3.sh rename to tools/jenkins_scripts/mac/android/test-android-4.x-debug.sh diff --git a/tools/JenkinsScript/Mac/android/AndroidTest-release4_0-4_0_3.sh b/tools/jenkins_scripts/mac/android/test-android-4.x-release.sh similarity index 100% rename from tools/JenkinsScript/Mac/android/AndroidTest-release4_0-4_0_3.sh rename to tools/jenkins_scripts/mac/android/test-android-4.x-release.sh diff --git a/tools/JenkinsScript/Mac/debug.keystore b/tools/jenkins_scripts/mac/debug.keystore similarity index 100% rename from tools/JenkinsScript/Mac/debug.keystore rename to tools/jenkins_scripts/mac/debug.keystore diff --git a/tools/JenkinsScript/Mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.html b/tools/jenkins_scripts/mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.html similarity index 100% rename from tools/JenkinsScript/Mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.html rename to tools/jenkins_scripts/mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.html diff --git a/tools/JenkinsScript/Mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.py b/tools/jenkins_scripts/mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.py similarity index 100% rename from tools/JenkinsScript/Mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.py rename to tools/jenkins_scripts/mac/iOS_SikuliTest.sikuli/iOS_SikuliTest.py diff --git a/tools/jenkins_scripts/mac/ios/build-ios-all.sh b/tools/jenkins_scripts/mac/ios/build-ios-all.sh new file mode 100755 index 0000000000..45a22889c2 --- /dev/null +++ b/tools/jenkins_scripts/mac/ios/build-ios-all.sh @@ -0,0 +1,21 @@ +# cpp +xcodebuild clean build -project ../../../../samples/HelloCpp/proj.ios/HelloCpp.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Debug +xcodebuild clean build -project ../../../../samples/HelloCpp/proj.ios/HelloCpp.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Release + +xcodebuild clean build -project ../../../../samples/TestCpp/proj.ios/TestCpp.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Debug +xcodebuild clean build -project ../../../../samples/TestCpp/proj.ios/TestCpp.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Release + +# lua +xcodebuild clean build -project ../../../../samples/HelloLua/proj.ios/HelloLua.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Debug +xcodebuild clean build -project ../../../../samples/HelloLua/proj.ios/HelloLua.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Release + +xcodebuild clean build -project ../../../../samples/TestLua/proj.ios/TestLua.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Debug +xcodebuild clean build -project ../../../../samples/TestLua/proj.ios/TestLua.xcodeproj -alltargets -sdk iphonesimulator5.1-configuration Release + +# javascript +xcodebuild clean build -project ../../../../samples/TestJavascript/proj.ios/TestJavascript.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Debug +xcodebuild clean build -project ../../../../samples/TestJavascript/proj.ios/TestJavascript.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Release + +# other sample games +xcodebuild clean build -project ../../../../samples/SimpleGame/proj.ios/SimpleGame.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Debug +xcodebuild clean build -project ../../../../samples/SimpleGame/proj.ios/SimpleGame.xcodeproj -alltargets -sdk iphonesimulator5.1 -configuration Release diff --git a/tools/JenkinsScript/Mac/ios/iOSCompile-debug.sh b/tools/jenkins_scripts/mac/ios/build-ios-debug.sh similarity index 100% rename from tools/JenkinsScript/Mac/ios/iOSCompile-debug.sh rename to tools/jenkins_scripts/mac/ios/build-ios-debug.sh diff --git a/tools/JenkinsScript/Mac/ios/iOSCompile-release.sh b/tools/jenkins_scripts/mac/ios/build-ios-release.sh similarity index 100% rename from tools/JenkinsScript/Mac/ios/iOSCompile-release.sh rename to tools/jenkins_scripts/mac/ios/build-ios-release.sh diff --git a/tools/JenkinsScript/Mac/ios/iphonesim b/tools/jenkins_scripts/mac/ios/iphonesim similarity index 100% rename from tools/JenkinsScript/Mac/ios/iphonesim rename to tools/jenkins_scripts/mac/ios/iphonesim diff --git a/tools/JenkinsScript/Mac/ios/iOSTest-debug.sh b/tools/jenkins_scripts/mac/ios/test-ios-debug.sh similarity index 100% rename from tools/JenkinsScript/Mac/ios/iOSTest-debug.sh rename to tools/jenkins_scripts/mac/ios/test-ios-debug.sh diff --git a/tools/JenkinsScript/Mac/ios/iOSTest-release.sh b/tools/jenkins_scripts/mac/ios/test-ios-release.sh similarity index 100% rename from tools/JenkinsScript/Mac/ios/iOSTest-release.sh rename to tools/jenkins_scripts/mac/ios/test-ios-release.sh diff --git a/tools/jenkins_scripts/mac/mac/build-mac-all.sh b/tools/jenkins_scripts/mac/mac/build-mac-all.sh new file mode 100755 index 0000000000..3528973183 --- /dev/null +++ b/tools/jenkins_scripts/mac/mac/build-mac-all.sh @@ -0,0 +1,15 @@ +# cpp +xcodebuild clean build -project ../../../../samples/HelloCpp/proj.mac/HelloCpp.xcodeproj -alltargets -configuration Debug +xcodebuild clean build -project ../../../../samples/HelloCpp/proj.mac/HelloCpp.xcodeproj -alltargets -configuration Release + +xcodebuild clean build -project ../../../../samples/TestCpp/proj.mac/TestCpp.xcodeproj -alltargets -configuration Debug +xcodebuild clean build -project ../../../../samples/TestCpp/proj.mac/TestCpp.xcodeproj -alltargets -configuration Release + +# lua +# TBD + +# javascript +# TBD + +# other sample games +# TBD diff --git a/tools/JenkinsScript/Mac/mac/MacCompile-debug.sh b/tools/jenkins_scripts/mac/mac/build-mac-debug.sh similarity index 100% rename from tools/JenkinsScript/Mac/mac/MacCompile-debug.sh rename to tools/jenkins_scripts/mac/mac/build-mac-debug.sh diff --git a/tools/JenkinsScript/Mac/mac/MacCompile-release.sh b/tools/jenkins_scripts/mac/mac/build-mac-release.sh similarity index 100% rename from tools/JenkinsScript/Mac/mac/MacCompile-release.sh rename to tools/jenkins_scripts/mac/mac/build-mac-release.sh diff --git a/tools/JenkinsScript/Mac/mac/MacTest-release.sh b/tools/jenkins_scripts/mac/mac/test-mac-debug.sh similarity index 100% rename from tools/JenkinsScript/Mac/mac/MacTest-release.sh rename to tools/jenkins_scripts/mac/mac/test-mac-debug.sh diff --git a/tools/JenkinsScript/Mac/mac/Mactest-debug.sh b/tools/jenkins_scripts/mac/mac/test-mac-release.sh similarity index 100% rename from tools/JenkinsScript/Mac/mac/Mactest-debug.sh rename to tools/jenkins_scripts/mac/mac/test-mac-release.sh diff --git a/tools/JenkinsScript/Mac/rootconfig-Mac.sh b/tools/jenkins_scripts/mac/rootconfig-mac.sh similarity index 100% rename from tools/JenkinsScript/Mac/rootconfig-Mac.sh rename to tools/jenkins_scripts/mac/rootconfig-mac.sh diff --git a/tools/JenkinsScript/Windows/android/androidtestcommon.bat b/tools/jenkins_scripts/windows/android/androidtestcommon.bat old mode 100644 new mode 100755 similarity index 95% rename from tools/JenkinsScript/Windows/android/androidtestcommon.bat rename to tools/jenkins_scripts/windows/android/androidtestcommon.bat index fab374d236..cd9d49ee85 --- a/tools/JenkinsScript/Windows/android/androidtestcommon.bat +++ b/tools/jenkins_scripts/windows/android/androidtestcommon.bat @@ -9,7 +9,7 @@ set AndroidHome=D:\Windows7\android-sdk-windows rem android version path set AndroidVersion=\platforms\android-8 rem android project path -set AndroidProject=D:\cocos2d-x\tests\proj.android +set AndroidProject=D:\cocos2d-x\samples\TestCpp\proj.android rem unsigned apk name set unsign_apk=Tests.apk rem signed apk name diff --git a/tools/JenkinsScript/Windows/android/AndroidCompile-debug2_2-3_2.bat b/tools/jenkins_scripts/windows/android/build-android-2.2-3.2-debug.bat old mode 100644 new mode 100755 similarity index 94% rename from tools/JenkinsScript/Windows/android/AndroidCompile-debug2_2-3_2.bat rename to tools/jenkins_scripts/windows/android/build-android-2.2-3.2-debug.bat index 1857845a22..373b31d49d --- a/tools/JenkinsScript/Windows/android/AndroidCompile-debug2_2-3_2.bat +++ b/tools/jenkins_scripts/windows/android/build-android-2.2-3.2-debug.bat @@ -4,6 +4,7 @@ ::Here are the environment variables you should set. ::%ANT_HOME% %ANDROID_HOME% %JAVA_HOME% %CYGWIN% %ANDROID_NDK% +echo off if not exist "%CYGWIN%" echo Couldn't find Cygwin at "%CYGWIN%" and you should set it like this "C:\cygwin"& pause & exit 1 if not exist "%ANDROID_HOME%" echo Couldn't find ANDROID_HOME at "%ANDROID_HOME%" and you should set it like this "D:\xx\android-sdk-windows"& pause & exit 2 if not exist "%ANDROID_NDK%" echo Couldn't find Cygwin at "%ANDROID_NDK%" and you should set it like this "D:\xx\android-ndk-r8"& pause & exit 3 @@ -15,9 +16,9 @@ cd ..\..\..\.. :project ::Copy build Configuration files to target directory -copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\Windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android /Y +copy %cd%\tools\jenkins_scripts\build.xml %cd%\samples\%_PROJECTNAME%\proj.android /Y +copy %cd%\tools\jenkins_scripts\windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android /Y ::Modify the configuration files cd samples\%_PROJECTNAME%\proj.android diff --git a/tools/JenkinsScript/Windows/android/AndroidCompile-release2_2-3_2.bat b/tools/jenkins_scripts/windows/android/build-android-2.2-3.2-release.bat old mode 100644 new mode 100755 similarity index 92% rename from tools/JenkinsScript/Windows/android/AndroidCompile-release2_2-3_2.bat rename to tools/jenkins_scripts/windows/android/build-android-2.2-3.2-release.bat index 80e2669623..85aa538401 --- a/tools/JenkinsScript/Windows/android/AndroidCompile-release2_2-3_2.bat +++ b/tools/jenkins_scripts/windows/android/build-android-2.2-3.2-release.bat @@ -15,9 +15,9 @@ cd ..\..\..\.. :project ::Copy build Configuration files to target directory -copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\Windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\build.xml %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android ::Modify the configuration files cd samples\%_PROJECTNAME%\proj.android diff --git a/tools/JenkinsScript/Windows/android/AndroidCompile-debug4_0-4_0_3.bat b/tools/jenkins_scripts/windows/android/build-android-4.x-debug.bat old mode 100644 new mode 100755 similarity index 90% rename from tools/JenkinsScript/Windows/android/AndroidCompile-debug4_0-4_0_3.bat rename to tools/jenkins_scripts/windows/android/build-android-4.x-debug.bat index 988f507bd4..c8efd8a229 --- a/tools/JenkinsScript/Windows/android/AndroidCompile-debug4_0-4_0_3.bat +++ b/tools/jenkins_scripts/windows/android/build-android-4.x-debug.bat @@ -15,9 +15,9 @@ cd ..\..\..\.. :project ::Copy build Configuration files to target directory -copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\Windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\build.xml %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android ::Modify the configuration files cd samples\%_PROJECTNAME%\proj.android diff --git a/tools/JenkinsScript/Windows/android/AndroidCompile-release4_0-4_0_3.bat b/tools/jenkins_scripts/windows/android/build-android-4.x-release.bat old mode 100644 new mode 100755 similarity index 91% rename from tools/JenkinsScript/Windows/android/AndroidCompile-release4_0-4_0_3.bat rename to tools/jenkins_scripts/windows/android/build-android-4.x-release.bat index 4c263ba001..496881c7dc --- a/tools/JenkinsScript/Windows/android/AndroidCompile-release4_0-4_0_3.bat +++ b/tools/jenkins_scripts/windows/android/build-android-4.x-release.bat @@ -15,9 +15,9 @@ cd ..\..\..\.. :project ::Copy build Configuration files to target directory -copy %cd%\tools\JenkinsScript\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\build.xml %cd%\samples\%_PROJECTNAME%\proj.android -copy %cd%\tools\JenkinsScript\Windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\ant.properties %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\build.xml %cd%\samples\%_PROJECTNAME%\proj.android +copy %cd%\tools\jenkins_scripts\windows\android\rootconfig.sh %cd%\samples\%_PROJECTNAME%\proj.android ::Modify the configuration files cd samples\%_PROJECTNAME%\proj.android diff --git a/tools/JenkinsScript/Windows/android/rootconfig.sh b/tools/jenkins_scripts/windows/android/rootconfig.sh old mode 100644 new mode 100755 similarity index 69% rename from tools/JenkinsScript/Windows/android/rootconfig.sh rename to tools/jenkins_scripts/windows/android/rootconfig.sh index 4324a0d198..1eae455170 --- a/tools/JenkinsScript/Windows/android/rootconfig.sh +++ b/tools/jenkins_scripts/windows/android/rootconfig.sh @@ -31,7 +31,16 @@ if [ $1 = TestCpp ]; then elif [ $1 = HelloCpp ]; then sed -i '2d' $CUR/build.xml sed -i '2 i\' $CUR/build.xml -else +else [ $1 = HelloLua ]; then sed -i '2d' $CUR/build.xml sed -i '2 i\' $CUR/build.xml +else [ $1 = TestLua ]; then + sed -i '2d' $CUR/build.xml + sed -i '2 i\' $CUR/build.xml +else [ $1 = TestJavascript ]; then + sed -i '2d' $CUR/build.xml + sed -i '2 i\' $CUR/build.xml +else [ $1 = SimpleGame ]; then + sed -i '2d' $CUR/build.xml + sed -i '2 i\' $CUR/build.xml fi \ No newline at end of file diff --git a/tools/JenkinsScript/Windows/android/AndroidTest-debug2_2-3_2.bat b/tools/jenkins_scripts/windows/android/test-android-2.2-3.2-debug.bat similarity index 100% rename from tools/JenkinsScript/Windows/android/AndroidTest-debug2_2-3_2.bat rename to tools/jenkins_scripts/windows/android/test-android-2.2-3.2-debug.bat diff --git a/tools/JenkinsScript/Windows/android/AndroidTest-release2_2-3_2.bat b/tools/jenkins_scripts/windows/android/test-android-2.2-3.2-release.bat similarity index 100% rename from tools/JenkinsScript/Windows/android/AndroidTest-release2_2-3_2.bat rename to tools/jenkins_scripts/windows/android/test-android-2.2-3.2-release.bat diff --git a/tools/JenkinsScript/Windows/android/AndroidTest-debug4_0-4_0_3.bat b/tools/jenkins_scripts/windows/android/test-android-4.x-debug.bat similarity index 100% rename from tools/JenkinsScript/Windows/android/AndroidTest-debug4_0-4_0_3.bat rename to tools/jenkins_scripts/windows/android/test-android-4.x-debug.bat diff --git a/tools/JenkinsScript/Windows/android/AndroidTest-release4_0-4_0_3.bat b/tools/jenkins_scripts/windows/android/test-android-4.x-release.bat similarity index 100% rename from tools/JenkinsScript/Windows/android/AndroidTest-release4_0-4_0_3.bat rename to tools/jenkins_scripts/windows/android/test-android-4.x-release.bat diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Action0/ObjectRepository.bdb.REMOVED.git-id b/tools/jenkins_scripts/windows/win32/qtp_win32/Action0/ObjectRepository.bdb.REMOVED.git-id similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Action0/ObjectRepository.bdb.REMOVED.git-id rename to tools/jenkins_scripts/windows/win32/qtp_win32/Action0/ObjectRepository.bdb.REMOVED.git-id diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Action0/Resource.mtr b/tools/jenkins_scripts/windows/win32/qtp_win32/Action0/Resource.mtr similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Action0/Resource.mtr rename to tools/jenkins_scripts/windows/win32/qtp_win32/Action0/Resource.mtr diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Action0/Script.mts b/tools/jenkins_scripts/windows/win32/qtp_win32/Action0/Script.mts similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Action0/Script.mts rename to tools/jenkins_scripts/windows/win32/qtp_win32/Action0/Script.mts diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Action1/ObjectRepository.bdb.REMOVED.git-id b/tools/jenkins_scripts/windows/win32/qtp_win32/Action1/ObjectRepository.bdb.REMOVED.git-id similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Action1/ObjectRepository.bdb.REMOVED.git-id rename to tools/jenkins_scripts/windows/win32/qtp_win32/Action1/ObjectRepository.bdb.REMOVED.git-id diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Action1/Resource.mtr b/tools/jenkins_scripts/windows/win32/qtp_win32/Action1/Resource.mtr similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Action1/Resource.mtr rename to tools/jenkins_scripts/windows/win32/qtp_win32/Action1/Resource.mtr diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Action1/Script.mts b/tools/jenkins_scripts/windows/win32/qtp_win32/Action1/Script.mts similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Action1/Script.mts rename to tools/jenkins_scripts/windows/win32/qtp_win32/Action1/Script.mts diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Default.xls b/tools/jenkins_scripts/windows/win32/qtp_win32/Default.xls similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Default.xls rename to tools/jenkins_scripts/windows/win32/qtp_win32/Default.xls diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Error_Sub.vbs b/tools/jenkins_scripts/windows/win32/qtp_win32/Error_Sub.vbs similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Error_Sub.vbs rename to tools/jenkins_scripts/windows/win32/qtp_win32/Error_Sub.vbs diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Error_appcrash.qrs b/tools/jenkins_scripts/windows/win32/qtp_win32/Error_appcrash.qrs similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Error_appcrash.qrs rename to tools/jenkins_scripts/windows/win32/qtp_win32/Error_appcrash.qrs diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Parameters.mtr b/tools/jenkins_scripts/windows/win32/qtp_win32/Parameters.mtr similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Parameters.mtr rename to tools/jenkins_scripts/windows/win32/qtp_win32/Parameters.mtr diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/Test.tsp b/tools/jenkins_scripts/windows/win32/qtp_win32/Test.tsp similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/Test.tsp rename to tools/jenkins_scripts/windows/win32/qtp_win32/Test.tsp diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/TestCpp_Appcrash.tsr.REMOVED.git-id b/tools/jenkins_scripts/windows/win32/qtp_win32/TestCpp_Appcrash.tsr.REMOVED.git-id similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/TestCpp_Appcrash.tsr.REMOVED.git-id rename to tools/jenkins_scripts/windows/win32/qtp_win32/TestCpp_Appcrash.tsr.REMOVED.git-id diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/default.cfg b/tools/jenkins_scripts/windows/win32/qtp_win32/default.cfg similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/default.cfg rename to tools/jenkins_scripts/windows/win32/qtp_win32/default.cfg diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/default.usp b/tools/jenkins_scripts/windows/win32/qtp_win32/default.usp similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/default.usp rename to tools/jenkins_scripts/windows/win32/qtp_win32/default.usp diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/lock.lck b/tools/jenkins_scripts/windows/win32/qtp_win32/lock.lck similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/lock.lck rename to tools/jenkins_scripts/windows/win32/qtp_win32/lock.lck diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/qtp_win32.usr b/tools/jenkins_scripts/windows/win32/qtp_win32/qtp_win32.usr similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/qtp_win32.usr rename to tools/jenkins_scripts/windows/win32/qtp_win32/qtp_win32.usr diff --git a/tools/JenkinsScript/Windows/win32/qtp_win32/qtrunner.vbs b/tools/jenkins_scripts/windows/win32/qtp_win32/qtrunner.vbs similarity index 100% rename from tools/JenkinsScript/Windows/win32/qtp_win32/qtrunner.vbs rename to tools/jenkins_scripts/windows/win32/qtp_win32/qtrunner.vbs diff --git a/tools/JenkinsScript/Windows/win32/vs2008_debugtest.bat b/tools/jenkins_scripts/windows/win32/test-win-vs2008-debug.bat similarity index 100% rename from tools/JenkinsScript/Windows/win32/vs2008_debugtest.bat rename to tools/jenkins_scripts/windows/win32/test-win-vs2008-debug.bat diff --git a/tools/JenkinsScript/Windows/win32/vs2008_releasetest.bat b/tools/jenkins_scripts/windows/win32/test-win-vs2008_release.bat similarity index 100% rename from tools/JenkinsScript/Windows/win32/vs2008_releasetest.bat rename to tools/jenkins_scripts/windows/win32/test-win-vs2008_release.bat diff --git a/tools/JenkinsScript/Windows/win32/vs2010_debugtest.bat b/tools/jenkins_scripts/windows/win32/test-win-vs2010_debug.bat similarity index 100% rename from tools/JenkinsScript/Windows/win32/vs2010_debugtest.bat rename to tools/jenkins_scripts/windows/win32/test-win-vs2010_debug.bat diff --git a/tools/JenkinsScript/Windows/win32/vs2010_releasetest.bat b/tools/jenkins_scripts/windows/win32/test-win-vs2010_release.bat similarity index 100% rename from tools/JenkinsScript/Windows/win32/vs2010_releasetest.bat rename to tools/jenkins_scripts/windows/win32/test-win-vs2010_release.bat diff --git a/tools/tolua++/CCAction.pkg b/tools/tolua++/CCAction.pkg index 4ebed74843..f87973a654 100644 --- a/tools/tolua++/CCAction.pkg +++ b/tools/tolua++/CCAction.pkg @@ -335,7 +335,7 @@ class CCPlace : public CCActionInstant // static CCPlace* create(CCPoint pos); }; -class CCCallFunc : public CCActioninstant +class CCCallFunc : public CCActionInstant { static CCCallFunc* create(LUA_FUNCTION funcID); }; diff --git a/tools/tolua++/CCAffineTransform.pkg b/tools/tolua++/CCAffineTransform.pkg index dece0d7af9..b7a98840c6 100644 --- a/tools/tolua++/CCAffineTransform.pkg +++ b/tools/tolua++/CCAffineTransform.pkg @@ -1,5 +1,5 @@ -struct CCAffineTransform { +class CCAffineTransform { float a, b, c, d; float tx, ty; }; diff --git a/tools/tolua++/CCAnimation.pkg b/tools/tolua++/CCAnimation.pkg index ac8161b33a..7e6088119a 100644 --- a/tools/tolua++/CCAnimation.pkg +++ b/tools/tolua++/CCAnimation.pkg @@ -20,14 +20,10 @@ class CCAnimationFrame : public CCObject class CCAnimation : public CCObject { - CCAnimation(); - ~CCAnimation(void); - CCObject* copyWithZone(CCZone* pZone); - + static CCAnimation* create(CCArray *arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops); static CCAnimation* create(void); static CCAnimation* createWithSpriteFrames(CCArray* arrayOfSpriteFrameNames); static CCAnimation* createWithSpriteFrames(CCArray* arrayOfSpriteFrameNames, float delay); - static CCAnimation* create(CCArray *arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops); void addSpriteFrame(CCSpriteFrame *pFrame); void addSpriteFrameWithFileName(const char *pszFileName); diff --git a/tools/tolua++/CCCommon.pkg b/tools/tolua++/CCCommon.pkg index 126b60b18b..1226c80592 100644 --- a/tools/tolua++/CCCommon.pkg +++ b/tools/tolua++/CCCommon.pkg @@ -1,3 +1,4 @@ + typedef enum LanguageType { kLanguageEnglish = 0, diff --git a/tools/tolua++/CCDirector.pkg b/tools/tolua++/CCDirector.pkg index 9835e344df..4b17648a70 100644 --- a/tools/tolua++/CCDirector.pkg +++ b/tools/tolua++/CCDirector.pkg @@ -18,7 +18,7 @@ class CCDirector : public CCObject bool isPaused(void); unsigned int getTotalFrames(void); - CCEGLView* getOpenGLView(void); + CCEGLViewProtocol* getOpenGLView(void); bool enableRetinaDisplay(bool bEnableRetina); CCSize getWinSize(void); @@ -35,7 +35,7 @@ class CCDirector : public CCObject void pushScene(CCScene *pScene); void popScene(void); void replaceScene(CCScene *pScene); - void end @ endToLua(); + void end @ endToLua (); float getContentScaleFactor(void); diff --git a/tools/tolua++/CCDrawingPrimitives.pkg b/tools/tolua++/CCDrawingPrimitives.pkg index 01779d51be..b894407850 100644 --- a/tools/tolua++/CCDrawingPrimitives.pkg +++ b/tools/tolua++/CCDrawingPrimitives.pkg @@ -16,4 +16,4 @@ void ccDrawColor4F(GLubyte r, GLubyte g, GLubyte b, GLubyte a); void ccPointSize(GLfloat pointSize); // glew.h API: -void glLineWidth(GLfloat width); +// void glLineWidth(GLfloat width); diff --git a/tools/tolua++/CCEGLViewProtocol.pkg b/tools/tolua++/CCEGLViewProtocol.pkg new file mode 100644 index 0000000000..f98ffaab73 --- /dev/null +++ b/tools/tolua++/CCEGLViewProtocol.pkg @@ -0,0 +1,97 @@ + +enum ResolutionPolicy +{ + // The entire application is visible in the specified area without trying to preserve the original aspect ratio. + // Distortion can occur, and the application may appear stretched or compressed. + kResolutionExactFit, + // The entire application fills the specified area, without distortion but possibly with some cropping, + // while maintaining the original aspect ratio of the application. + kResolutionNoBorder, + // The entire application is visible in the specified area without distortion while maintaining the original + // aspect ratio of the application. Borders can appear on two sides of the application. + kResolutionShowAll, + + kResolutionUnKnown, +}; + +class CCEGLViewProtocol +{ + /** + * Get design resolution size. + * If setDesignResolutionSize wasn't invoked, the result of this function return is the same as 'getFrameSize' + */ + const CCSize& getSize() const; + + /** + * Get the frame size of EGL view. + * In general, it returns the screen size since the EGL view is a fullscreen view. + */ + const CCSize& getFrameSize() const; + + /** + * Set the frame size of EGL view. + */ + void setFrameSize(float width, float height); + + /** + * Get the visible area size of opengl viewport. + */ + CCSize getVisibleSize() const; + + /** + * Get the visible origin point of opengl viewport. + */ + CCPoint getVisibleOrigin() const; + + /** + * Set the design resolutin size. + * You can't use it with enableRetina together. + * @param width Design resolution width. + * @param height Design resolution height. + * @param resolutionPolicy The resolution policy you need, there are: + * [1] kCCResolutionExactFit Fill screen, if the design resolution ratio of width and height is different from the screen resolution ratio, your game view will be stretched. + * [2] kCCResolutionNoBorder Full screen without black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two areas of your game view will be cut. + * [3] kCCResolutionShowAll Full screen with black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two black border will be shown on the screen; + */ + void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy); + + /** Set touch delegate */ + void setTouchDelegate(EGLTouchDelegate * pDelegate); + + /** + * Set content scale factor. + * @return If return true, it means the plaform supports retina display. + */ + bool setContentScaleFactor(float contentScaleFactor); + + /** + * Set opengl view port rectangle with points. + */ + void setViewPortInPoints(float x , float y , float w , float h); + + /** + * Set Scissor rectangle with points. + */ + void setScissorInPoints(float x , float y , float w , float h); + + /** + * Get opengl view port rectangle. + */ + const CCRect& getViewPortRect() const; + + /** + * Get the scale factor of horizontal direction. + * + */ + float getScaleX() const; + + /** + * Get the scale factor of vertical direction. + */ + float getScaleY() const; + + /** + * Get whether the retina mode is enabled. + */ + bool isRetinaEnabled() const; +}; diff --git a/tools/tolua++/CCFileUtils.pkg b/tools/tolua++/CCFileUtils.pkg index c6429207c3..bca02e2e72 100644 --- a/tools/tolua++/CCFileUtils.pkg +++ b/tools/tolua++/CCFileUtils.pkg @@ -3,6 +3,7 @@ class CCFileUtils { static CCFileUtils* sharedFileUtils(); std::string getWriteablePath(); + void setResourceDirectory(const char *pszDirectoryName); const char* fullPathFromRelativePath(const char *pszRelativePath); const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile); const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile); diff --git a/tools/tolua++/CCGeometry.pkg b/tools/tolua++/CCGeometry.pkg index c1e232045a..a3a8b45860 100644 --- a/tools/tolua++/CCGeometry.pkg +++ b/tools/tolua++/CCGeometry.pkg @@ -1,7 +1,7 @@ typedef float CGFloat; -class CCPoint +class CCPoint : public CCObject { float x; float y; @@ -11,7 +11,7 @@ class CCPoint bool equals(const CCPoint & target) const ; }; -class CCSize +class CCSize : public CCObject { float width; float height; @@ -21,7 +21,7 @@ class CCSize bool equals(const CCSize & target) const; }; -class CCRect +class CCRect : public CCObject { CCPoint origin; CCSize size; diff --git a/tools/tolua++/CCMenuItem.pkg b/tools/tolua++/CCMenuItem.pkg index 1a5e9b3356..8a1c0eff79 100644 --- a/tools/tolua++/CCMenuItem.pkg +++ b/tools/tolua++/CCMenuItem.pkg @@ -9,8 +9,8 @@ class CCMenuItem : public CCNode bool isEnabled(); bool isSelected(); - void registerScriptHandler(LUA_FUNCTION funcID); - void unregisterScriptHandler(void); + void registerScriptTapHandler(LUA_FUNCTION funcID); + void unregisterScriptTapHandler(void); }; class CCMenuItemLabel : public CCMenuItem diff --git a/tools/tolua++/CCNode.pkg b/tools/tolua++/CCNode.pkg index 7d69b4629a..fc73c99ec3 100644 --- a/tools/tolua++/CCNode.pkg +++ b/tools/tolua++/CCNode.pkg @@ -51,9 +51,9 @@ class CCNode : public CCObject tolua_property__CCPositionY float y; tolua_property__CCSkewX float skewX; tolua_property__CCSkewY float skewY; -// tolua_property__CCIsVisible bool isVisible; + tolua_property__IsVisible bool isVisible; tolua_property__CCAnchorPoint CCPoint anchorPoint; -// tolua_property__CCContentSize CCSize contentSize; + tolua_property__CCContentSize CCSize contentSize; tolua_property__CCTag int tag; CCArray* getChildren(); @@ -87,9 +87,9 @@ class CCNode : public CCObject void setGLServerState(ccGLServerState state); CCScheduler* getScheduler(); void setScheduler(CCScheduler* pScheduler); + void addChild(CCNode * child); + void addChild(CCNode * child, int zOrder); void addChild(CCNode * child, int zOrder, int tag); - void addChild(CCNode * child, int zOrder); - void addChild(CCNode * child); void removeChild(CCNode* child, bool cleanup); void removeAllChildrenWithCleanup(bool cleanup); void reorderChild(CCNode * child, int zOrder); diff --git a/tools/tolua++/CCNotificationCenter.pkg b/tools/tolua++/CCNotificationCenter.pkg new file mode 100644 index 0000000000..5a37aa3aae --- /dev/null +++ b/tools/tolua++/CCNotificationCenter.pkg @@ -0,0 +1,8 @@ + +class CCNotificationCenter : public CCObject +{ + static CCNotificationCenter *sharedNotificationCenter(void); + void registerScriptObserver(LUA_FUNCTION handler); + void unregisterScriptObserver(void); + void postNotification(const char *name); +}; diff --git a/tools/tolua++/CCParallaxNode.pkg b/tools/tolua++/CCParallaxNode.pkg index c4d68d9d07..998fb6d4a1 100644 --- a/tools/tolua++/CCParallaxNode.pkg +++ b/tools/tolua++/CCParallaxNode.pkg @@ -1,10 +1,8 @@ -struct _ccArray; - class CCParallaxNode : public CCNode { - struct _ccArray* getParallaxArray(); - void setParallaxArray(struct _ccArray * pval); + // struct _ccArray* getParallaxArray(); + // void setParallaxArray(struct _ccArray * pval); void addChild(CCNode * child, unsigned int z, CCPoint parallaxRatio, CCPoint positionOffset); void addChild(CCNode * child, unsigned int zOrder, int tag); @@ -14,8 +12,5 @@ class CCParallaxNode : public CCNode void visit(void); - struct _ccArray* getParallaxArray(); - void setParallaxArray(struct _ccArray * val); - static CCParallaxNode* create(); }; diff --git a/tools/tolua++/CCRenderTexture.pkg b/tools/tolua++/CCRenderTexture.pkg index bbdf231073..f998eed95d 100644 --- a/tools/tolua++/CCRenderTexture.pkg +++ b/tools/tolua++/CCRenderTexture.pkg @@ -11,7 +11,7 @@ class CCRenderTexture : public CCNode void setSprite(CCSprite* psprite); void begin(); - void endToLua(); + void end @ endToLua (); void beginWithClear(float r, float g, float b, float a); void beginWithClear(float r, float g, float b, float a, float depthValue); void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue); @@ -19,9 +19,9 @@ class CCRenderTexture : public CCNode void clear(float r, float g, float b, float a); void clearDepth(float depthValue); void clearStencil(int stencilValue); - + CCImage* newCCImage(); - + bool saveToFile(const char *szFilePath); bool saveToFile(const char *name, tCCImageFormat format); diff --git a/tools/tolua++/CCTileMapAtlas.pkg b/tools/tolua++/CCTileMapAtlas.pkg index 6eafdd11bb..48e06a779f 100644 --- a/tools/tolua++/CCTileMapAtlas.pkg +++ b/tools/tolua++/CCTileMapAtlas.pkg @@ -1,11 +1,11 @@ -struct sImageTGA; +// struct sImageTGA; class CCTileMapAtlas : public CCAtlasNode { - struct sImageTGA* getTGAInfo(); - void setTGAInfo(struct sImageTGA* val); + // struct sImageTGA* getTGAInfo(); + // void setTGAInfo(struct sImageTGA* val); void setTile(ccColor3B tile, ccGridSize position); void releaseMap(); diff --git a/tools/tolua++/Cocos2d.pkg b/tools/tolua++/Cocos2d.pkg index 099d6b310b..b7f3442638 100644 --- a/tools/tolua++/Cocos2d.pkg +++ b/tools/tolua++/Cocos2d.pkg @@ -1,66 +1,73 @@ $#include "LuaCocos2d.h" +$pfile "matrix.pkg" +$pfile "ccTypes.pkg" +$pfile "CCObject.pkg" +$pfile "CCCommon.pkg" +$pfile "CCGeometry.pkg" +$pfile "CCArray.pkg" +$pfile "CCDictionary.pkg" +$pfile "CCString.pkg" +$pfile "CCPointExtension.pkg" +$pfile "CCEGLViewProtocol.pkg" + +$pfile "CCFileUtils.pkg" +$pfile "CCDrawingPrimitives.pkg" +$pfile "CCAffineTransform.pkg" +$pfile "CCApplication.pkg" +$pfile "CCDirector.pkg" +$pfile "CCUserDefault.pkg" +$pfile "CCNotificationCenter.pkg" + +$pfile "CCNode.pkg" +$pfile "CCTexture2D.pkg" +$pfile "CCTextureAtlas.pkg" +$pfile "CCTextureCache.pkg" +$pfile "CCRenderTexture.pkg" +$pfile "CCSprite.pkg" +$pfile "CCSpriteBatchNode.pkg" +$pfile "CCSpriteFrame.pkg" +$pfile "CCSpriteFrameCache.pkg" +$pfile "CCLayer.pkg" +$pfile "CCScene.pkg" +$pfile "CCTransition.pkg" +$pfile "CCTransitionProgress.pkg" + +$pfile "CCScheduler.pkg" + $pfile "CCAction.pkg" $pfile "CCActionCamera.pkg" $pfile "CCActionCatmullRom.pkg" $pfile "CCActionEase.pkg" $pfile "CCActionGrid.pkg" $pfile "CCActionGrid3D.pkg" -$pfile "CCActionManager.pkg" $pfile "CCActionPageTurn3D.pkg" $pfile "CCActionProgressTimer.pkg" $pfile "CCActionTiledGrid.pkg" -$pfile "CCAffineTransform.pkg" +$pfile "CCActionManager.pkg" +$pfile "CCMotionStreak.pkg" + $pfile "CCAnimation.pkg" $pfile "CCAnimationCache.pkg" -$pfile "CCApplication.pkg" -$pfile "CCArray.pkg" $pfile "CCAtlasNode.pkg" $pfile "CCCamera.pkg" -$pfile "CCCommon.pkg" -$pfile "CCDirector.pkg" -$pfile "CCDrawingPrimitives.pkg" -$pfile "CCFileUtils.pkg" -$pfile "CCGeometry.pkg" $pfile "CCLabelAtlas.pkg" $pfile "CCLabelBMFont.pkg" $pfile "CCLabelTTF.pkg" -$pfile "CCLayer.pkg" $pfile "CCMenu.pkg" $pfile "CCMenuItem.pkg" -$pfile "CCMotionStreak.pkg" -$pfile "CCDictionary.pkg" -$pfile "CCNode.pkg" -$pfile "CCObject.pkg" $pfile "CCParallaxNode.pkg" $pfile "CCParticleExamples.pkg" $pfile "CCParticleSystem.pkg" $pfile "CCParticleBatchNode.pkg" -$pfile "CCPointExtension.pkg" $pfile "CCProgressTimer.pkg" -$pfile "CCRenderTexture.pkg" -$pfile "CCScene.pkg" -$pfile "CCScheduler.pkg" -$pfile "CCSprite.pkg" -$pfile "CCSpriteBatchNode.pkg" -$pfile "CCSpriteFrame.pkg" -$pfile "CCSpriteFrameCache.pkg" -$pfile "CCString.pkg" $pfile "CCTextFieldTTF.pkg" -$pfile "CCTexture2D.pkg" -$pfile "CCTextureAtlas.pkg" -$pfile "CCTextureCache.pkg" $pfile "CCTileMapAtlas.pkg" $pfile "CCTMXLayer.pkg" $pfile "CCTMXObjectGroup.pkg" $pfile "CCTMXTiledMap.pkg" $pfile "CCTMXXMLParser.pkg" $pfile "CCTouch.pkg" -$pfile "CCTransition.pkg" -$pfile "CCTransitionProgress.pkg" -$pfile "ccTypes.pkg" -$pfile "CCUserDefault.pkg" -$pfile "matrix.pkg" $pfile "SimpleAudioEngine.pkg" diff --git a/tools/tolua++/basic.lua b/tools/tolua++/basic.lua index 110a5f7e15..d7eec9a4e9 100644 --- a/tools/tolua++/basic.lua +++ b/tools/tolua++/basic.lua @@ -193,15 +193,20 @@ local CCObjectTypes = { -- register CCObject types for i = 1, #CCObjectTypes do - _push_functions[CCObjectTypes[i]] = "tolua_pushusertype_ccobject" + _push_functions[CCObjectTypes[i]] = "toluafix_pushusertype_ccobject" end --- register LUA_FUNCTION type -_to_functions["LUA_FUNCTION"] = "tolua_ref_function" -_is_functions["LUA_FUNCTION"] = "tolua_isfunction" +-- register LUA_FUNCTION, LUA_TABLE, LUA_HANDLE type +_to_functions["LUA_FUNCTION"] = "toluafix_ref_function" +_is_functions["LUA_FUNCTION"] = "toluafix_isfunction" +_to_functions["LUA_TABLE"] = "toluafix_totable" +_is_functions["LUA_TABLE"] = "toluafix_istable" function get_property_methods_hook(ptype, name) + if ptype == "IsVisible" then + return "isVisible", "setVisible" + end if string.sub(ptype, 1, 2) == "CC" then ptype = string.sub(ptype, 3) end diff --git a/tools/tolua++/ccTypes.pkg b/tools/tolua++/ccTypes.pkg index 888bc40d97..6f6e5ce0bc 100644 --- a/tools/tolua++/ccTypes.pkg +++ b/tools/tolua++/ccTypes.pkg @@ -1,6 +1,4 @@ -typedef _lua_function LUA_FUNCTION; - typedef unsigned char GLubyte; typedef int GLint; typedef int GLsizei; diff --git a/tools/tolua++/matrix.pkg b/tools/tolua++/matrix.pkg index 736816c381..1bd3c67933 100644 --- a/tools/tolua++/matrix.pkg +++ b/tools/tolua++/matrix.pkg @@ -1,8 +1,9 @@ + typedef unsigned int kmGLEnum; -typedef struct kmMat4 { +class kmMat4 { float mat[16]; -} kmMat4; +}; void kmGLFreeAll(void); void kmGLPushMatrix(void); diff --git a/tools/tolua++/tolua++.Mac.zip.REMOVED.git-id b/tools/tolua++/tolua++.Mac.zip.REMOVED.git-id index 941ba6dc67..52d16d82cb 100644 --- a/tools/tolua++/tolua++.Mac.zip.REMOVED.git-id +++ b/tools/tolua++/tolua++.Mac.zip.REMOVED.git-id @@ -1 +1 @@ -d2ec87961c13d8ae29e5d9bd84aec0a4465c668c \ No newline at end of file +12a58290deb3c79169fcb192e45b92d7229da0b3 \ No newline at end of file