Added init and finish methods to the NavigationMeshGenerator. Also small tweaks in initialization.

This commit is contained in:
Relintai 2023-09-03 11:51:09 +02:00
parent 9ae3aa65b7
commit e81f25ac7b
3 changed files with 17 additions and 0 deletions

View File

@ -226,6 +226,8 @@ void finalize_physics() {
}
void initialize_navigation_mesh_generator() {
ERR_FAIL_COND(navigation_mesh_generator != NULL);
// Init chosen NavigationMeshGenerator
const String &server_name = GLOBAL_GET(NavigationMeshGeneratorManager::setting_property_name);
navigation_mesh_generator = NavigationMeshGeneratorManager::get_singleton()->new_server(server_name);
@ -243,6 +245,8 @@ void initialize_navigation_mesh_generator() {
}
if (navigation_mesh_generator) {
navigation_mesh_generator->init();
// need to register singleton earlier so modules / extensions / addons can use it on SCENE / SERVER init level
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationMeshGenerator", NavigationMeshGenerator::get_singleton()));
}
@ -251,6 +255,10 @@ void initialize_navigation_mesh_generator() {
}
void finalize_navigation_mesh_generator() {
ERR_FAIL_COND(!navigation_mesh_generator);
navigation_mesh_generator->finish();
memdelete(navigation_mesh_generator);
navigation_mesh_generator = nullptr;
}

View File

@ -71,6 +71,12 @@ NavigationMeshGenerator *NavigationMeshGenerator::get_singleton() {
return singleton;
}
void NavigationMeshGenerator::init() {
}
void NavigationMeshGenerator::finish() {
}
NavigationMeshGenerator::NavigationMeshGenerator() {
ERR_FAIL_COND(singleton != nullptr);
singleton = this;

View File

@ -85,6 +85,9 @@ public:
virtual bool is_navigation_mesh_baking(Ref<NavigationMesh> p_navigation_mesh) const = 0;
#endif // _3D_DISABLED
virtual void init();
virtual void finish();
NavigationMeshGenerator();
~NavigationMeshGenerator();
};