mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Fixed the problem that the script callback function could not be registered in game.cpp (#12190)
This commit is contained in:
@@ -54,6 +54,9 @@ int CocosApplication::init() {
|
||||
if (_engine->init()) {
|
||||
return -1;
|
||||
}
|
||||
_engine->on(BaseEngine::ON_START, [this]() {
|
||||
this->onStart();
|
||||
});
|
||||
|
||||
_engine->on(BaseEngine::ON_RESUME, [this]() {
|
||||
this->onResume();
|
||||
@@ -112,6 +115,10 @@ BaseEngine::Ptr CocosApplication::getEngine() const {
|
||||
return _engine;
|
||||
}
|
||||
|
||||
void CocosApplication::onStart() {
|
||||
// TODO(cc): Handling engine start events
|
||||
}
|
||||
|
||||
void CocosApplication::onPause() {
|
||||
// TODO(cc): Handling pause events
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ public:
|
||||
*/
|
||||
BaseEngine::Ptr getEngine() const override;
|
||||
|
||||
/**
|
||||
* @brief Processing engine start events.
|
||||
*/
|
||||
virtual void onStart();
|
||||
/**
|
||||
* @brief Processing pause events..
|
||||
*/
|
||||
|
||||
@@ -96,10 +96,15 @@ bool setCanvasCallback(se::Object * /*global*/) {
|
||||
|
||||
namespace cc {
|
||||
|
||||
Engine::Engine() = default;
|
||||
Engine::Engine() {
|
||||
_scriptEngine = ccnew se::ScriptEngine();
|
||||
}
|
||||
|
||||
Engine::~Engine() {
|
||||
destroy();
|
||||
|
||||
delete _scriptEngine;
|
||||
_scriptEngine = nullptr;
|
||||
}
|
||||
|
||||
int32_t Engine::init() {
|
||||
@@ -118,7 +123,6 @@ int32_t Engine::init() {
|
||||
_profiler = ccnew Profiler();
|
||||
#endif
|
||||
|
||||
_scriptEngine = ccnew se::ScriptEngine();
|
||||
EventDispatcher::init();
|
||||
|
||||
BasePlatform *platform = BasePlatform::getPlatform();
|
||||
@@ -148,7 +152,9 @@ void Engine::destroy() {
|
||||
|
||||
// Should delete it before deleting DeviceManager as ScriptEngine will check gpu resource usage,
|
||||
// and ScriptEngine will hold gfx objects.
|
||||
delete _scriptEngine;
|
||||
// Because the user registration interface needs to be added during initialization.
|
||||
// ScriptEngine cannot be released here.
|
||||
_scriptEngine->cleanup();
|
||||
|
||||
#if CC_USE_PROFILER
|
||||
delete _profiler;
|
||||
@@ -223,8 +229,6 @@ void Engine::close() { // NOLINT
|
||||
_scheduler->removeAllFunctionsToBePerformedInCocosThread();
|
||||
_scheduler->unscheduleAll();
|
||||
BasePlatform::getPlatform()->setHandleEventCallback(nullptr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint Engine::getTotalFrames() const {
|
||||
|
||||
Reference in New Issue
Block a user