Ported: Disable threaded NavigationMesh bake on unsupported OS. Automatically disables threaded NavigationMesh bake when OS does not support threads. - smix8

c3b39ca1e9
This commit is contained in:
Relintai 2022-07-27 18:51:18 +02:00
parent 4a5982b9e1
commit ad080c7017
2 changed files with 8 additions and 2 deletions

View File

@ -4,7 +4,7 @@
An instance of a [NavigationMesh].
</brief_description>
<description>
An instance of a [NavigationMesh]. It tells the [Navigation] node what can be navigated and what cannot, based on the [NavigationMesh] resource. This should be a child of a [Navigation] node.
Bakes the [NavigationMesh]. If [code]on_thread[/code] is set to [code]true[/code] (default), the baking is done on a separate thread. Baking on separate thread is useful because navigation baking is not a cheap operation. When it is completed, it automatically sets the new [NavigationMesh]. Please note that baking on separate thread may be very slow if geometry is parsed from meshes as async access to each mesh involves heavy synchronization. Also, please note that baking on a separate thread is automatically disabled on operating systems that cannot use threads (such as HTML5 with threads disabled).
</description>
<tutorials>
</tutorials>

View File

@ -30,6 +30,7 @@
#include "navigation_mesh_instance.h"
#include "core/os/os.h"
#include "mesh_instance.h"
#include "navigation.h"
#include "scene/resources/mesh.h"
@ -179,7 +180,12 @@ void NavigationMeshInstance::bake_navigation_mesh(bool p_on_thread) {
BakeThreadsArgs *args = memnew(BakeThreadsArgs);
args->nav_region = this;
if (p_on_thread) {
if (p_on_thread && !OS::get_singleton()->can_use_threads()) {
WARN_PRINT("NavigationMesh bake 'on_thread' will be disabled as the current OS does not support multiple threads."
"\nAs a fallback the navigation mesh will bake on the main thread which can cause framerate issues.");
}
if (p_on_thread && OS::get_singleton()->can_use_threads()) {
bake_thread.start(_bake_navigation_mesh, args);
} else {
_bake_navigation_mesh(args);