Debian Codegraph @

modules/navigation_2d/2d/nav_mesh_generator_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* nav_mesh_generator_2d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #ifdef CLIPPER2_ENABLED
34
35 #include "core/object/class_db.h"
36 #include "core/object/worker_thread_pool.h"
37 #include "core/templates/rid_owner.h"
38 #include "servers/navigation_2d/navigation_server_2d.h"
39
40 class Node;
41 class NavigationPolygon;
42 class NavigationMeshSourceGeometryData2D;
43
44 class NavMeshGenerator2D : public Object {
45 GDSOFTCLASS(NavMeshGenerator2D, Object);
46
47 static NavMeshGenerator2D *singleton;
48
49 static Mutex baking_navmesh_mutex;
50 static Mutex generator_task_mutex;
51
52 static RWLock generator_parsers_rwlock;
53 static LocalVector<NavMeshGeometryParser2D *> generator_parsers;
54
55 static bool use_threads;
56 static bool baking_use_multiple_threads;
57 static bool baking_use_high_priority_threads;
58
59 struct NavMeshGeneratorTask2D {
60 enum TaskStatus {
61 BAKING_STARTED,
62 BAKING_FINISHED,
63 BAKING_FAILED,
64 CALLBACK_DISPATCHED,
65 CALLBACK_FAILED,
66 };
67
68 Ref<NavigationPolygon> navigation_mesh;
69 Ref<NavigationMeshSourceGeometryData2D> source_geometry_data;
70 Callable callback;
71 WorkerThreadPool::TaskID thread_task_id = WorkerThreadPool::INVALID_TASK_ID;
72 NavMeshGeneratorTask2D::TaskStatus status = NavMeshGeneratorTask2D::TaskStatus::BAKING_STARTED;
73 };
74
75 static HashMap<WorkerThreadPool::TaskID, NavMeshGeneratorTask2D *> generator_tasks;
76
77 static void generator_thread_bake(void *p_arg);
78
79 static HashSet<Ref<NavigationPolygon>> baking_navmeshes;
80
81 static void generator_parse_geometry_node(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node, bool p_recurse_children);
82 static void generator_parse_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_root_node);
83 static void generator_bake_from_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data);
84
85 static bool generator_emit_callback(const Callable &p_callback);
86
87 public:
88 static NavMeshGenerator2D *get_singleton();
89
90 static void sync();
91 static void cleanup();
92 static void finish();
93
94 static void set_generator_parsers(LocalVector<NavMeshGeometryParser2D *> p_parsers);
95
96 static void parse_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_root_node, const Callable &p_callback = Callable());
97 static void bake_from_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback = Callable());
98 static void bake_from_source_geometry_data_async(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback = Callable());
99 static bool is_baking(Ref<NavigationPolygon> p_navigation_polygon);
100
101 NavMeshGenerator2D();
102 ~NavMeshGenerator2D();
103 };
104
105 #endif // CLIPPER2_ENABLED