Path: blob/master/modules/navigation_2d/2d/nav_mesh_generator_2d.h
10278 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_server_2d.h"3839class Node;40class NavigationPolygon;41class NavigationMeshSourceGeometryData2D;4243class NavMeshGenerator2D : public Object {44static NavMeshGenerator2D *singleton;4546static Mutex baking_navmesh_mutex;47static Mutex generator_task_mutex;4849static RWLock generator_parsers_rwlock;50static LocalVector<NavMeshGeometryParser2D *> generator_parsers;5152static bool use_threads;53static bool baking_use_multiple_threads;54static bool baking_use_high_priority_threads;5556struct NavMeshGeneratorTask2D {57enum TaskStatus {58BAKING_STARTED,59BAKING_FINISHED,60BAKING_FAILED,61CALLBACK_DISPATCHED,62CALLBACK_FAILED,63};6465Ref<NavigationPolygon> navigation_mesh;66Ref<NavigationMeshSourceGeometryData2D> source_geometry_data;67Callable callback;68WorkerThreadPool::TaskID thread_task_id = WorkerThreadPool::INVALID_TASK_ID;69NavMeshGeneratorTask2D::TaskStatus status = NavMeshGeneratorTask2D::TaskStatus::BAKING_STARTED;70};7172static HashMap<WorkerThreadPool::TaskID, NavMeshGeneratorTask2D *> generator_tasks;7374static void generator_thread_bake(void *p_arg);7576static HashSet<Ref<NavigationPolygon>> baking_navmeshes;7778static void generator_parse_geometry_node(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node, bool p_recurse_children);79static void generator_parse_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_root_node);80static void generator_bake_from_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data);8182static bool generator_emit_callback(const Callable &p_callback);8384public:85static NavMeshGenerator2D *get_singleton();8687static void sync();88static void cleanup();89static void finish();9091static void set_generator_parsers(LocalVector<NavMeshGeometryParser2D *> p_parsers);9293static 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());94static void bake_from_source_geometry_data(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback = Callable());95static void bake_from_source_geometry_data_async(Ref<NavigationPolygon> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, const Callable &p_callback = Callable());96static bool is_baking(Ref<NavigationPolygon> p_navigation_polygon);9798NavMeshGenerator2D();99~NavMeshGenerator2D();100};101102#endif // CLIPPER2_ENABLED103104105