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"
|
|
|
|
|
2013-04-15 22:50:07 +08:00
|
|
|
bool CC_DLL cc_assert_script_compatible(const char *msg)
|
2012-12-26 18:33:55 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
cocos2d::ScriptEngineProtocol* pEngine = cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine();
|
2013-04-15 22:50:07 +08:00
|
|
|
if (pEngine && pEngine->handleAssert(msg))
|
2012-12-26 18:33:55 +08:00
|
|
|
{
|
2013-04-15 22:50:07 +08:00
|
|
|
return true;
|
2012-12-26 18:33:55 +08:00
|
|
|
}
|
2013-04-15 22:50:07 +08:00
|
|
|
return false;
|
2012-12-26 18:33:55 +08:00
|
|
|
}
|
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
2013-06-20 14:13:12 +08:00
|
|
|
// #pragma mark ScriptHandlerEntry
|
2012-08-28 12:08:15 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptHandlerEntry* ScriptHandlerEntry::create(int nHandler)
|
2012-08-28 12:08:15 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptHandlerEntry* entry = new ScriptHandlerEntry(nHandler);
|
2012-08-28 12:08:15 +08:00
|
|
|
entry->autorelease();
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptHandlerEntry::~ScriptHandlerEntry(void)
|
2012-08-28 12:08:15 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_handler);
|
2012-08-28 12:08:15 +08:00
|
|
|
}
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
2013-06-20 14:13:12 +08:00
|
|
|
// #pragma mark SchedulerScriptHandlerEntry
|
2012-08-25 15:05:59 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SchedulerScriptHandlerEntry* SchedulerScriptHandlerEntry::create(int nHandler, float fInterval, bool bPaused)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
SchedulerScriptHandlerEntry* pEntry = new SchedulerScriptHandlerEntry(nHandler);
|
2012-08-28 12:08:15 +08:00
|
|
|
pEntry->init(fInterval, bPaused);
|
2012-02-09 14:07:11 +08:00
|
|
|
pEntry->autorelease();
|
|
|
|
return pEntry;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool SchedulerScriptHandlerEntry::init(float fInterval, bool bPaused)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
_timer = new Timer();
|
2013-06-15 14:03:30 +08:00
|
|
|
_timer->initWithScriptHandler(_handler, fInterval);
|
|
|
|
_timer->autorelease();
|
|
|
|
_timer->retain();
|
|
|
|
_paused = bPaused;
|
|
|
|
LUALOG("[LUA] ADD script schedule: %d, entryID: %d", _handler, _entryId);
|
2012-02-09 14:07:11 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SchedulerScriptHandlerEntry::~SchedulerScriptHandlerEntry(void)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_timer->release();
|
|
|
|
LUALOG("[LUA] DEL script schedule %d, entryID: %d", _handler, _entryId);
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
2013-06-20 14:13:12 +08:00
|
|
|
// #pragma mark TouchScriptHandlerEntry
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TouchScriptHandlerEntry* TouchScriptHandlerEntry::create(int nHandler,
|
2012-08-28 12:08:15 +08:00
|
|
|
bool bIsMultiTouches,
|
|
|
|
int nPriority,
|
|
|
|
bool bSwallowsTouches)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TouchScriptHandlerEntry* pEntry = new TouchScriptHandlerEntry(nHandler);
|
2012-08-28 12:08:15 +08:00
|
|
|
pEntry->init(bIsMultiTouches, nPriority, bSwallowsTouches);
|
2012-02-09 14:07:11 +08:00
|
|
|
pEntry->autorelease();
|
|
|
|
return pEntry;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TouchScriptHandlerEntry::~TouchScriptHandlerEntry(void)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_handler);
|
2013-06-15 14:03:30 +08:00
|
|
|
LUALOG("[LUA] Remove touch event handler: %d", _handler);
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TouchScriptHandlerEntry::init(bool bIsMultiTouches, int nPriority, bool bSwallowsTouches)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_isMultiTouches = bIsMultiTouches;
|
|
|
|
_priority = nPriority;
|
|
|
|
_swallowsTouches = bSwallowsTouches;
|
2012-02-09 14:07:11 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-10 18:38:18 +08:00
|
|
|
// #pragma mark -
|
2013-06-20 14:13:12 +08:00
|
|
|
// #pragma mark ScriptEngineManager
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
static ScriptEngineManager* s_pSharedScriptEngineManager = NULL;
|
2012-02-09 14:07:11 +08:00
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptEngineManager::~ScriptEngineManager(void)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
removeScriptEngine();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ScriptEngineManager::setScriptEngine(ScriptEngineProtocol *pScriptEngine)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
removeScriptEngine();
|
2013-06-15 14:03:30 +08:00
|
|
|
_scriptEngine = pScriptEngine;
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ScriptEngineManager::removeScriptEngine(void)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_scriptEngine)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
delete _scriptEngine;
|
|
|
|
_scriptEngine = NULL;
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptEngineManager* ScriptEngineManager::sharedManager(void)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
if (!s_pSharedScriptEngineManager)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
s_pSharedScriptEngineManager = new ScriptEngineManager();
|
2012-02-09 14:07:11 +08:00
|
|
|
}
|
|
|
|
return s_pSharedScriptEngineManager;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ScriptEngineManager::purgeSharedManager(void)
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
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
|