mirror of https://github.com/axmolengine/axmol.git
issue #528, improve CCScriptEngineManager. AppDelegate should hold the whole lifecycle of LuaEngine object.
This commit is contained in:
parent
ec2553d589
commit
f3375f0dbb
|
@ -1,17 +1,18 @@
|
|||
#include "AppDelegate.h"
|
||||
#include "LuaEngine.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
:m_pLuaEngine(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
||||
CC_SAFE_DELETE(m_pLuaEngine);
|
||||
}
|
||||
|
||||
bool AppDelegate::initInstance()
|
||||
|
@ -84,10 +85,10 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// register lua engine
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->registerScriptEngine(new LuaEngine());
|
||||
m_pLuaEngine = new LuaEngine;
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
CCLog("1");
|
||||
unsigned long size;
|
||||
char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
#include "LuaEngine.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
@ -37,6 +38,9 @@ public:
|
|||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
|
||||
private:
|
||||
LuaEngine* m_pLuaEngine;
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
|
@ -65,18 +65,24 @@ public:
|
|||
virtual bool executeSchedule(const char* pszFuncName, ccTime t) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
CCScriptEngineManager is a singleton which holds an object instance of CCScriptEngineProtocl
|
||||
It helps cocos2d-x and the user code to find back LuaEngine object
|
||||
@since v0.99.5-x-0.8.5
|
||||
*/
|
||||
class CC_DLL CCScriptEngineManager
|
||||
{
|
||||
public:
|
||||
CCScriptEngineManager();
|
||||
virtual ~CCScriptEngineManager();
|
||||
|
||||
void registerScriptEngine(CCScriptEngineProtocol *pScriptEngine);
|
||||
static CCScriptEngineManager* sharedScriptEngineManager();
|
||||
|
||||
void setScriptEngine(CCScriptEngineProtocol *pScriptEngine);
|
||||
CCScriptEngineProtocol* getScriptEngine();
|
||||
|
||||
static CCScriptEngineManager* sharedScriptEngineManager();
|
||||
|
||||
void removeScriptEngine();
|
||||
|
||||
private:
|
||||
CCScriptEngineManager();
|
||||
virtual ~CCScriptEngineManager();
|
||||
|
||||
CCScriptEngineProtocol *m_pScriptEngine;
|
||||
};
|
||||
|
||||
|
|
|
@ -25,14 +25,17 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
CCScriptEngineManager::CCScriptEngineManager() : m_pScriptEngine(NULL) {}
|
||||
CCScriptEngineManager::CCScriptEngineManager()
|
||||
:m_pScriptEngine(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CCScriptEngineManager::~CCScriptEngineManager()
|
||||
{
|
||||
CC_SAFE_DELETE(m_pScriptEngine);
|
||||
m_pScriptEngine = NULL;
|
||||
}
|
||||
|
||||
void CCScriptEngineManager::registerScriptEngine(CCScriptEngineProtocol *pScriptEngine)
|
||||
void CCScriptEngineManager::setScriptEngine(CCScriptEngineProtocol *pScriptEngine)
|
||||
{
|
||||
this->m_pScriptEngine = pScriptEngine;
|
||||
}
|
||||
|
@ -42,6 +45,11 @@ CCScriptEngineProtocol* CCScriptEngineManager::getScriptEngine()
|
|||
return m_pScriptEngine;
|
||||
}
|
||||
|
||||
void CCScriptEngineManager::removeScriptEngine()
|
||||
{
|
||||
this->m_pScriptEngine = NULL;
|
||||
}
|
||||
|
||||
CCScriptEngineManager* CCScriptEngineManager::sharedScriptEngineManager()
|
||||
{
|
||||
static CCScriptEngineManager scriptEngineManager;
|
||||
|
|
Loading…
Reference in New Issue