Path: blob/master/modules/navigation_2d/2d/nav_mesh_generator_2d.h
11354 views
/**************************************************************************/1/* nav_mesh_generator_2d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#ifdef CLIPPER2_ENABLED3334#include "core/object/class_db.h"35#include "core/object/worker_thread_pool.h"36#include "core/templates/rid_owner.h"37#include "servers/navigation_2d/navigation_server_2d.h"3839class Node;40class NavigationPolygon;41class NavigationMeshSourceGeometryData2D;4243class NavMeshGenerator2D : public Object {44GDSOFTCLASS(NavMeshGenerator2D, Object);4546static NavMeshGenerator2D *singleton;4748static Mutex baking_navmesh_mutex;49static Mutex generator_task_mutex;5051static RWLock generator_parsers_rwlock;52static LocalVector<NavMeshGeometryParser2D *> generator_parsers;5354static bool use_threads;55static bool baking_use_multiple_threads;56static bool baking_use_high_priority_threads;5758struct NavMeshGeneratorTask2D {59enum TaskStatus {60BAKING_STARTED,61BAKING_FINISHED,62BAKING_FAILED,63CALLBACK_DISPATCHED,64CALLBACK_FAILED,65};6667Ref<NavigationPolygon> navigation_mesh;68Ref<NavigationMeshSourceGeometryData2D> source_geometry_data;69Callable callback;70WorkerThreadPool::TaskID thread_task_id = WorkerThreadPool::INVALID_TASK_ID;71NavMeshGeneratorTask2D::TaskStatus status = NavMeshGeneratorTask2D::TaskStatus::BAKING_STARTED;72};7374static HashMap<WorkerThreadPool::TaskID, NavMeshGeneratorTask2D *> generator_tasks;7576static void generator_thread_bake(void *p_arg);7778static HashSet<Ref<NavigationPolygon>> baking_navmeshes;7980static void generator_parse_geometry_node(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node, bool p_recurse_children);81static void generator_parse_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_root_node);82static void generator_bake_from_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data);8384static bool generator_emit_callback(const Callable &p_callback);8586public:87static NavMeshGenerator2D *get_singleton();8889static void sync();90static void cleanup();91static void finish();9293static void set_generator_parsers(LocalVector<NavMeshGeometryParser2D *> p_parsers);9495static 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());96static void bake_from_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback = Callable());97static void bake_from_source_geometry_data_async(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback = Callable());98static bool is_baking(Ref<NavigationPolygon> p_navigation_polygon);99100NavMeshGenerator2D();101~NavMeshGenerator2D();102};103104#endif // CLIPPER2_ENABLED105106107