2012-02-09 14:07:11 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-09-02 00:38:57 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2012-02-09 14:07:11 +08:00
|
|
|
|
|
|
|
#include "CCScriptSupport.h"
|
|
|
|
#include "CCScheduler.h"
|
|
|
|
|
2012-12-29 13:54:46 +08:00
|
|
|
void CC_DLL cc_assert_script_compatible(bool cond, const char *msg)
|
2012-12-26 18:33:55 +08:00
|
|
|
{
|
|
|
|
cocos2d::CCScriptEngineProtocol* pEngine = cocos2d::CCScriptEngineManager::sharedManager()->getScriptEngine();
|
|
|
|
if (!cond && pEngine && pEngine->executeAssert(cond, msg))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CC_ASSERT(cond);
|
|
|
|
}
|
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
|
|
|
// #pragma mark CCScriptHandlerEntry
|
2012-08-28 12:08:15 +08:00
|
|
|
|
|
|
|
CCScriptHandlerEntry* CCScriptHandlerEntry::create(int nHandler)
|
|
|
|
{
|
|
|
|
CCScriptHandlerEntry* entry = new CCScriptHandlerEntry(nHandler);
|
|
|
|
entry->autorelease();
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCScriptHandlerEntry::~CCScriptHandlerEntry(void)
|
|
|
|
{
|
2012-09-11 14:02:33 +08:00
|
|
|
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler);
|
2012-08-28 12:08:15 +08:00
|
|
|
}
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
|
|
|
// #pragma mark CCSchedulerScriptHandlerEntry
|
2012-08-25 15:05:59 +08:00
|
|
|
|
2012-08-28 12:08:15 +08:00
|
|
|
CCSchedulerScriptHandlerEntry* CCSchedulerScriptHandlerEntry::create(int nHandler, float fInterval, bool bPaused)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2012-08-28 12:08:15 +08:00
|
|
|
CCSchedulerScriptHandlerEntry* pEntry = new CCSchedulerScriptHandlerEntry(nHandler);
|
|
|
|
pEntry->init(fInterval, bPaused);
|
2012-02-09 14:07:11 +08:00
|
|
|
pEntry->autorelease();
|
|
|
|
return pEntry;
|
|
|
|
}
|
|
|
|
|
2012-08-28 12:08:15 +08:00
|
|
|
bool CCSchedulerScriptHandlerEntry::init(float fInterval, bool bPaused)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2012-06-12 17:07:54 +08:00
|
|
|
m_pTimer = new CCTimer();
|
2012-08-28 12:08:15 +08:00
|
|
|
m_pTimer->initWithScriptHandler(m_nHandler, fInterval);
|
2012-02-09 14:07:11 +08:00
|
|
|
m_pTimer->autorelease();
|
|
|
|
m_pTimer->retain();
|
|
|
|
m_bPaused = bPaused;
|
2012-08-28 12:08:15 +08:00
|
|
|
LUALOG("[LUA] ADD script schedule: %d, entryID: %d", m_nHandler, m_nEntryId);
|
2012-02-09 14:07:11 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCSchedulerScriptHandlerEntry::~CCSchedulerScriptHandlerEntry(void)
|
|
|
|
{
|
|
|
|
m_pTimer->release();
|
2012-08-28 12:08:15 +08:00
|
|
|
LUALOG("[LUA] DEL script schedule %d, entryID: %d", m_nHandler, m_nEntryId);
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
|
|
|
// #pragma mark CCTouchScriptHandlerEntry
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2012-08-28 12:08:15 +08:00
|
|
|
CCTouchScriptHandlerEntry* CCTouchScriptHandlerEntry::create(int nHandler,
|
|
|
|
bool bIsMultiTouches,
|
|
|
|
int nPriority,
|
|
|
|
bool bSwallowsTouches)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2012-08-28 12:08:15 +08:00
|
|
|
CCTouchScriptHandlerEntry* pEntry = new CCTouchScriptHandlerEntry(nHandler);
|
|
|
|
pEntry->init(bIsMultiTouches, nPriority, bSwallowsTouches);
|
2012-02-09 14:07:11 +08:00
|
|
|
pEntry->autorelease();
|
|
|
|
return pEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTouchScriptHandlerEntry::~CCTouchScriptHandlerEntry(void)
|
|
|
|
{
|
2012-09-11 14:02:33 +08:00
|
|
|
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler);
|
2012-02-09 14:07:11 +08:00
|
|
|
LUALOG("[LUA] Remove touch event handler: %d", m_nHandler);
|
|
|
|
}
|
|
|
|
|
2012-08-28 12:08:15 +08:00
|
|
|
bool CCTouchScriptHandlerEntry::init(bool bIsMultiTouches, int nPriority, bool bSwallowsTouches)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
m_bIsMultiTouches = bIsMultiTouches;
|
|
|
|
m_nPriority = nPriority;
|
|
|
|
m_bSwallowsTouches = bSwallowsTouches;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
|
|
|
// #pragma mark CCScriptEngineManager
|
2012-02-09 14:07:11 +08:00
|
|
|
|
|
|
|
static CCScriptEngineManager* s_pSharedScriptEngineManager = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
CCScriptEngineManager::~CCScriptEngineManager(void)
|
|
|
|
{
|
|
|
|
removeScriptEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCScriptEngineManager::setScriptEngine(CCScriptEngineProtocol *pScriptEngine)
|
|
|
|
{
|
|
|
|
removeScriptEngine();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pScriptEngine = pScriptEngine;
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCScriptEngineManager::removeScriptEngine(void)
|
|
|
|
{
|
|
|
|
if (m_pScriptEngine)
|
|
|
|
{
|
2012-08-29 14:55:55 +08:00
|
|
|
delete m_pScriptEngine;
|
2012-02-09 14:07:11 +08:00
|
|
|
m_pScriptEngine = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCScriptEngineManager* CCScriptEngineManager::sharedManager(void)
|
|
|
|
{
|
|
|
|
if (!s_pSharedScriptEngineManager)
|
|
|
|
{
|
|
|
|
s_pSharedScriptEngineManager = new CCScriptEngineManager();
|
|
|
|
}
|
|
|
|
return s_pSharedScriptEngineManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCScriptEngineManager::purgeSharedManager(void)
|
|
|
|
{
|
2012-02-09 20:07:55 +08:00
|
|
|
if (s_pSharedScriptEngineManager)
|
|
|
|
{
|
|
|
|
delete s_pSharedScriptEngineManager;
|
|
|
|
s_pSharedScriptEngineManager = NULL;
|
|
|
|
}
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 11:46:08 +08:00
|
|
|
NS_CC_END
|