@@ -36,15 +36,11 @@ GodotJSScriptLanguageBase::~GodotJSScriptLanguageBase()
36
36
}
37
37
}
38
38
39
- void GodotJSScriptLanguageBase::init ()
39
+ void GodotJSScriptLanguageBase::create_environment ()
40
40
{
41
- if (once_inited_) return ;
42
-
43
- JSB_BENCHMARK_SCOPE (GodotJSScriptLanguageBase, init);
44
- once_inited_ = true ;
45
- JSB_LOG (Verbose, " Runtime: %s" , JSB_IMPL_VERSION_STRING);
46
- JSB_LOG (VeryVerbose, " jsb lang init" );
47
-
41
+ ++prevent_environment_dispose_;
42
+ if (environment_)
43
+ return ;
48
44
jsb::Environment::CreateParams params;
49
45
params.initial_class_slots = (int ) ClassDB::classes.size () + JSB_MASTER_INITIAL_CLASS_EXTRA_SLOTS;
50
46
params.initial_object_slots = JSB_MASTER_INITIAL_OBJECT_SLOTS;
@@ -53,34 +49,51 @@ void GodotJSScriptLanguageBase::init()
53
49
params.debugger_port = jsb::internal::Settings::get_debugger_port ();
54
50
params.thread_id = Thread::get_caller_id ();
55
51
56
- ++prevent_environment_dispose_;
57
- // Initialize only once
58
- if (!environment_) {
59
- environment_ = std::make_shared<jsb::Environment>(params);
60
- environment_->init ();
52
+ environment_ = std::make_shared<jsb::Environment>(params);
53
+ environment_->init ();
61
54
62
- // load internal scripts (jsb.core, jsb.editor.main, jsb.editor.codegen)
63
- static constexpr char kRuntimeBundleFile [] = " jsb.runtime.bundle.js" ;
64
- jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kRuntimeBundleFile , GodotJSProjectPreset::get_source_rt) == OK,
65
- " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kRuntimeBundleFile );
66
- jsb_ensuref (environment_->load (" jsb.inject" ) == OK, " failed to load jsb.inject" );
55
+ // load internal scripts (jsb.core, jsb.editor.main, jsb.editor.codegen)
56
+ static constexpr char kRuntimeBundleFile [] = " jsb.runtime.bundle.js" ;
57
+ jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kRuntimeBundleFile , GodotJSProjectPreset::get_source_rt) == OK,
58
+ " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kRuntimeBundleFile );
59
+ jsb_ensuref (environment_->load (" jsb.inject" ) == OK, " failed to load jsb.inject" );
67
60
68
61
#ifdef TOOLS_ENABLED
69
- static constexpr char kEditorBundleFile [] = " jsb.editor.bundle.js" ;
70
- jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kEditorBundleFile , GodotJSProjectPreset::get_source_ed) == OK,
71
- " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kEditorBundleFile );
62
+ static constexpr char kEditorBundleFile [] = " jsb.editor.bundle.js" ;
63
+ jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kEditorBundleFile , GodotJSProjectPreset::get_source_ed) == OK,
64
+ " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kEditorBundleFile );
72
65
#endif
73
- }
74
66
}
75
67
76
- void GodotJSScriptLanguageBase::finish ()
68
+ void GodotJSScriptLanguageBase::destroy_environment ()
77
69
{
78
- jsb_check (once_inited_);
79
- once_inited_ = false ;
70
+ if (!environment_)
71
+ return ;
80
72
if (--prevent_environment_dispose_ == 1 ) {
81
73
environment_->dispose ();
82
74
environment_.reset ();
83
75
}
76
+ }
77
+
78
+ void GodotJSScriptLanguageBase::init ()
79
+ {
80
+ if (once_inited_) return ;
81
+
82
+ JSB_BENCHMARK_SCOPE (GodotJSScriptLanguageBase, init);
83
+ once_inited_ = true ;
84
+ JSB_LOG (Verbose, " Runtime: %s" , JSB_IMPL_VERSION_STRING);
85
+ JSB_LOG (VeryVerbose, " jsb lang init" );
86
+
87
+ create_environment ();
88
+
89
+ }
90
+
91
+ void GodotJSScriptLanguageBase::finish ()
92
+ {
93
+ jsb_check (once_inited_);
94
+ once_inited_ = false ;
95
+
96
+ destroy_environment ();
84
97
#if !JSB_WITH_WEB
85
98
jsb::Worker::finish ();
86
99
#endif
0 commit comments