mirror of https://github.com/axmolengine/axmol.git
* rename LuaEngine to CCLuaEngine
* add #if LUA_ENGINE * format source files
This commit is contained in:
parent
e9fa8116e9
commit
0739c1f262
|
@ -30,8 +30,10 @@
|
|||
#include "support/data_support/utlist.h"
|
||||
#include "support/data_support/uthash.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCLuaSupport.h"
|
||||
#include "LuaEngine.h"
|
||||
|
||||
#if LUA_ENGINE
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -92,7 +94,7 @@ CCScheduler::CCScheduler(void)
|
|||
CCScheduler::~CCScheduler(void)
|
||||
{
|
||||
unscheduleAllSelectors();
|
||||
unscheduleScriptFunctions();
|
||||
unscheduleAllScriptFunctions();
|
||||
pSharedScheduler = NULL;
|
||||
m_scriptFunctions->release();
|
||||
}
|
||||
|
@ -195,32 +197,6 @@ void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *p
|
|||
pTimer->release();
|
||||
}
|
||||
|
||||
int CCScheduler::scheduleScriptFunc(int refID, ccTime fInterval, bool bPaused)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = CCSchedulerFuncEntry::entryWithRefID(refID, fInterval, bPaused);
|
||||
m_scriptFunctions->addObject(entry);
|
||||
|
||||
// CCLOG("CCScheduler::scheduleScriptFunc() - add script entry, handle: %d, refid: %d", entry->getHandle(), refID);
|
||||
return entry->getHandle();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleScriptFunc(int handle)
|
||||
{
|
||||
for (int i = m_scriptFunctions->count() - 1; i >= 0; i--)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = (CCSchedulerFuncEntry*)m_scriptFunctions->objectAtIndex(i);
|
||||
if (entry->getHandle() == handle)
|
||||
{
|
||||
entry->markDeleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleScriptFunctions()
|
||||
{
|
||||
m_scriptFunctions->removeAllObjects();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget)
|
||||
{
|
||||
// explicity handle nil arguments when removing an object
|
||||
|
@ -452,7 +428,7 @@ void CCScheduler::unscheduleAllSelectors(void)
|
|||
unscheduleUpdateForTarget(pEntry->target);
|
||||
}
|
||||
|
||||
unscheduleScriptFunctions();
|
||||
unscheduleAllScriptFunctions();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleAllSelectorsForTarget(SelectorProtocol *pTarget)
|
||||
|
@ -660,6 +636,7 @@ void CCScheduler::tick(ccTime dt)
|
|||
|
||||
m_pCurrentTarget = NULL;
|
||||
|
||||
#if LUA_ENGINE
|
||||
// Interate all script functions
|
||||
for (int i = m_scriptFunctions->count() - 1; i >= 0; i--)
|
||||
{
|
||||
|
@ -675,6 +652,7 @@ void CCScheduler::tick(ccTime dt)
|
|||
CCSchedulerFuncEntry* entry = (CCSchedulerFuncEntry*)m_scriptFunctions->objectAtIndex(i);
|
||||
if (entry->isMarkDeleted()) m_scriptFunctions->removeObjectAtIndex(i);
|
||||
}
|
||||
#endif // LUA_ENGINE
|
||||
}
|
||||
|
||||
void CCScheduler::purgeSharedScheduler(void)
|
||||
|
@ -683,4 +661,34 @@ void CCScheduler::purgeSharedScheduler(void)
|
|||
pSharedScheduler = NULL;
|
||||
}
|
||||
|
||||
|
||||
#if LUA_ENGINE
|
||||
int CCScheduler::scheduleScriptFunc(int functionRefID, ccTime fInterval, bool bPaused)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = CCSchedulerFuncEntry::entryWithFunctionRefID(functionRefID, fInterval, bPaused);
|
||||
m_scriptFunctions->addObject(entry);
|
||||
return entry->getEntryID();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleScriptFunc(int scheduleEntryID)
|
||||
{
|
||||
for (int i = m_scriptFunctions->count() - 1; i >= 0; i--)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = (CCSchedulerFuncEntry*)m_scriptFunctions->objectAtIndex(i);
|
||||
if (entry->getEntryID() == scheduleEntryID)
|
||||
{
|
||||
entry->markDeleted();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleAllScriptFunctions()
|
||||
{
|
||||
m_scriptFunctions->removeAllObjects();
|
||||
}
|
||||
|
||||
#endif // LUA_ENGINE
|
||||
|
||||
} // namespace cocos2d
|
||||
|
||||
|
|
|
@ -25,14 +25,16 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCTimer.h"
|
||||
#include "LuaEngine.h"
|
||||
#if LUA_ENGINE
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
|
||||
CCTimer::CCTimer()
|
||||
: m_pTarget(NULL)
|
||||
, m_refID(0)
|
||||
, m_functionRefID(0)
|
||||
, m_fInterval(0.0f)
|
||||
, m_fElapsed(0.0f)
|
||||
, m_pfnSelector(NULL)
|
||||
|
@ -41,10 +43,12 @@ CCTimer::CCTimer()
|
|||
|
||||
CCTimer::~CCTimer()
|
||||
{
|
||||
if (m_refID)
|
||||
#if LUA_ENGINE
|
||||
if (m_functionRefID)
|
||||
{
|
||||
LuaEngine::sharedEngine()->releaseRefID(m_refID);
|
||||
CCLuaEngine::sharedEngine()->removeLuaFunctionRef(m_functionRefID);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CCTimer* CCTimer::timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector)
|
||||
|
@ -77,19 +81,19 @@ CCTimer* CCTimer::timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSel
|
|||
return pTimer;
|
||||
}
|
||||
|
||||
bool CCTimer::initWithScriptFunc(int newRefID, ccTime fSeconds)
|
||||
#if LUA_ENGINE
|
||||
bool CCTimer::initWithScriptFunc(int functionRefID, ccTime fSeconds)
|
||||
{
|
||||
LuaEngine::sharedEngine()->retainRefID(newRefID);
|
||||
if (m_refID)
|
||||
if (m_functionRefID)
|
||||
{
|
||||
LuaEngine::sharedEngine()->releaseRefID(m_refID);
|
||||
CCLuaEngine::sharedEngine()->removeLuaFunctionRef(m_functionRefID);
|
||||
}
|
||||
m_refID = newRefID;
|
||||
m_functionRefID = functionRefID;
|
||||
m_fInterval = fSeconds;
|
||||
m_fElapsed = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool CCTimer::initWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector)
|
||||
{
|
||||
|
@ -123,14 +127,15 @@ void CCTimer::update(ccTime dt)
|
|||
(m_pTarget->*m_pfnSelector)(m_fElapsed);
|
||||
m_fElapsed = 0;
|
||||
}
|
||||
if (m_refID)
|
||||
#if LUA_ENGINE
|
||||
if (m_functionRefID)
|
||||
{
|
||||
LuaEngine::sharedEngine()->executeSchedule(m_refID, m_fElapsed);
|
||||
CCLuaEngine::sharedEngine()->executeSchedule(m_functionRefID, m_fElapsed);
|
||||
m_fElapsed = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace cocos2d
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <assert.h>
|
||||
|
||||
#ifdef LUA_ENGINE
|
||||
#include "LuaEngine.h"
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d {
|
||||
|
@ -63,7 +63,7 @@ CCObject::~CCObject(void)
|
|||
#ifdef LUA_ENGINE
|
||||
if (m_refID != 0)
|
||||
{
|
||||
LuaEngine::sharedEngine()->removeCCObject(this);
|
||||
CCLuaEngine::sharedEngine()->removeCCObject(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -56,8 +56,9 @@ public:
|
|||
, m_bIsEnabled(false)
|
||||
, m_pListener(NULL)
|
||||
, m_pfnSelector(NULL)
|
||||
, m_functionRefID(0)
|
||||
{}
|
||||
virtual ~CCMenuItem() {}
|
||||
virtual ~CCMenuItem();
|
||||
/** Creates a CCMenuItem with a target/selector */
|
||||
static CCMenuItem * itemWithTarget(SelectorProtocol *rec, SEL_MenuHandler selector);
|
||||
/** Initializes a CCMenuItem with a target/selector */
|
||||
|
@ -70,17 +71,22 @@ public:
|
|||
virtual void selected();
|
||||
/** The item was unselected */
|
||||
virtual void unselected();
|
||||
|
||||
#if LUA_ENGINE
|
||||
/** Register a script function, the function is called in activete
|
||||
* If pszFunctionName is NULL, then unregister it.
|
||||
*/
|
||||
virtual void registerScriptHandler(const char* pszFunctionName);
|
||||
virtual void registerScriptHandler(int functionRefID);
|
||||
virtual void unregisterScriptHandler(void);
|
||||
#endif
|
||||
|
||||
/** set the target/selector of the menu item*/
|
||||
void setTarget(SelectorProtocol *rec, SEL_MenuHandler selector);
|
||||
protected:
|
||||
SelectorProtocol* m_pListener;
|
||||
SEL_MenuHandler m_pfnSelector;
|
||||
std::string m_functionName;
|
||||
#if LUA_ENGINE
|
||||
int m_functionRefID;
|
||||
#endif
|
||||
};
|
||||
|
||||
/** @brief An abstract class for "label" CCMenuItemLabel items
|
||||
|
@ -217,7 +223,7 @@ public:
|
|||
,m_pDisabledImage(NULL)
|
||||
{}
|
||||
/** creates a menu item with a normal and selected image*/
|
||||
static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite);
|
||||
static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite = NULL);
|
||||
/** creates a menu item with a normal and selected image with target/selector */
|
||||
static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, SelectorProtocol* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal,selected and disabled image with target/selector */
|
||||
|
|
|
@ -86,14 +86,16 @@ public:
|
|||
@since v0.99.3
|
||||
*/
|
||||
|
||||
/** Schedule the script function
|
||||
#if LUA_ENGINE
|
||||
/** Schedule the script function, return schedule entry id
|
||||
*/
|
||||
int scheduleScriptFunc(int refid, ccTime fInterval, bool bPaused);
|
||||
|
||||
/** Unschedule the script function
|
||||
/** Unschedule the script function by schedule entry id
|
||||
*/
|
||||
void unscheduleScriptFunc(int handle);
|
||||
void unscheduleScriptFunctions();
|
||||
void unscheduleScriptFunc(int scheduleEntryID);
|
||||
void unscheduleAllScriptFunctions();
|
||||
#endif
|
||||
|
||||
void scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget, ccTime fInterval, bool bPaused);
|
||||
|
||||
|
|
|
@ -57,7 +57,9 @@ namespace cocos2d
|
|||
/** Initializes a timer with a target, a selector and an interval in seconds. */
|
||||
bool initWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector, ccTime fSeconds);
|
||||
|
||||
bool initWithScriptFunc(int refid, ccTime fSeconds);
|
||||
#if LUA_ENGINE
|
||||
bool initWithScriptFunc(int functionRefID, ccTime fSeconds);
|
||||
#endif
|
||||
|
||||
/** triggers the timer */
|
||||
void update(ccTime dt);
|
||||
|
@ -75,7 +77,10 @@ namespace cocos2d
|
|||
public:
|
||||
SEL_SCHEDULE m_pfnSelector;
|
||||
ccTime m_fInterval;
|
||||
int m_refID;
|
||||
|
||||
#if LUA_ENGINE
|
||||
int m_functionRefID;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
SelectorProtocol *m_pTarget;
|
||||
|
|
|
@ -124,10 +124,6 @@ THE SOFTWARE.
|
|||
#include "ccTypes.h"
|
||||
#include "ccMacros.h"
|
||||
|
||||
#ifdef LUA_ENGINE
|
||||
#include "LuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
const char* cocos2dVersion();
|
||||
|
|
|
@ -33,6 +33,10 @@ THE SOFTWARE.
|
|||
|
||||
#include <stdarg.h>
|
||||
|
||||
#if LUA_ENGINE
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
static unsigned int _fontSize = kCCItemSize;
|
||||
|
@ -62,6 +66,13 @@ bool CCMenuItem::initWithTarget(SelectorProtocol *rec, SEL_MenuHandler selector)
|
|||
return true;
|
||||
}
|
||||
|
||||
CCMenuItem::~CCMenuItem()
|
||||
{
|
||||
#if LUA_ENGINE
|
||||
unregisterScriptHandler();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CCMenuItem::selected()
|
||||
{
|
||||
m_bIsSelected = true;
|
||||
|
@ -72,17 +83,24 @@ void CCMenuItem::unselected()
|
|||
m_bIsSelected = false;
|
||||
}
|
||||
|
||||
void CCMenuItem::registerScriptHandler(const char* pszFunctionName)
|
||||
#if LUA_ENGINE
|
||||
void CCMenuItem::registerScriptHandler(int functionRefID)
|
||||
{
|
||||
if (pszFunctionName)
|
||||
unregisterScriptHandler();
|
||||
m_functionRefID = functionRefID;
|
||||
CCLOG("[LUA] ADD function refID: %04d, add CCMenuItem script handler", m_functionRefID);
|
||||
}
|
||||
|
||||
void CCMenuItem::unregisterScriptHandler(void)
|
||||
{
|
||||
this->m_functionName = string(pszFunctionName);
|
||||
}
|
||||
else
|
||||
if (m_functionRefID)
|
||||
{
|
||||
this->m_functionName.clear();
|
||||
CCLuaEngine::sharedEngine()->removeLuaFunctionRef(m_functionRefID);
|
||||
CCLOG("[LUA] DEL function refID: %04d, remove CCMenuItem script handler", m_functionRefID);
|
||||
}
|
||||
m_functionRefID = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CCMenuItem::activate()
|
||||
{
|
||||
|
@ -93,10 +111,12 @@ void CCMenuItem::activate()
|
|||
(m_pListener->*m_pfnSelector)(this);
|
||||
}
|
||||
|
||||
// if (m_functionName.size() && CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine())
|
||||
// {
|
||||
// CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncN(m_functionName.c_str(), this);
|
||||
// }
|
||||
#if LUA_ENGINE
|
||||
if (m_functionRefID)
|
||||
{
|
||||
CCLuaEngine::sharedEngine()->executeFunctionByRefID(m_functionRefID, m_uID);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,9 +497,9 @@ const ccColor3B& CCMenuItemSprite::getColor()
|
|||
{
|
||||
return m_pNormalImage->convertToRGBAProtocol()->getColor();
|
||||
}
|
||||
CCMenuItemSprite * CCMenuItemSprite::itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite)
|
||||
CCMenuItemSprite * CCMenuItemSprite::itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite)
|
||||
{
|
||||
return CCMenuItemSprite::itemFromNormalSprite(normalSprite, selectedSprite, NULL, NULL, NULL);
|
||||
return CCMenuItemSprite::itemFromNormalSprite(normalSprite, selectedSprite, disabledSprite, NULL, NULL);
|
||||
}
|
||||
CCMenuItemSprite * CCMenuItemSprite::itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, SelectorProtocol* target, SEL_MenuHandler selector)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue