Path: blob/master/modules/navigation_2d/2d/nav_map_iteration_2d.h
10278 views
/**************************************************************************/1/* nav_map_iteration_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#include "../nav_rid_2d.h"33#include "../nav_utils_2d.h"34#include "nav_mesh_queries_2d.h"3536#include "core/math/math_defs.h"37#include "core/os/semaphore.h"3839class NavLinkIteration2D;40class NavRegion2D;41class NavRegionIteration2D;42struct NavMapIteration2D;4344struct NavMapIterationBuild2D {45Vector2 merge_rasterizer_cell_size;46bool use_edge_connections = true;47real_t edge_connection_margin;48real_t link_connection_radius;49Nav2D::PerformanceData performance_data;50int polygon_count = 0;51int free_edge_count = 0;5253HashMap<Nav2D::EdgeKey, Nav2D::EdgeConnectionPair, Nav2D::EdgeKey> iter_connection_pairs_map;54LocalVector<Nav2D::Connection> iter_free_edges;5556NavMapIteration2D *map_iteration = nullptr;5758int navmesh_polygon_count = 0;5960void reset() {61performance_data.reset();6263iter_connection_pairs_map.clear();64iter_free_edges.clear();65polygon_count = 0;66free_edge_count = 0;6768navmesh_polygon_count = 0;69}70};7172struct NavMapIteration2D {73mutable SafeNumeric<uint32_t> users;74RWLock rwlock;7576LocalVector<Ref<NavRegionIteration2D>> region_iterations;77LocalVector<Ref<NavLinkIteration2D>> link_iterations;7879int navmesh_polygon_count = 0;8081// The edge connections that the map builds on top with the edge connection margin.82HashMap<const NavBaseIteration2D *, LocalVector<Nav2D::Connection>> external_region_connections;83HashMap<const NavBaseIteration2D *, LocalVector<LocalVector<Nav2D::Connection>>> navbases_polygons_external_connections;8485LocalVector<Nav2D::Polygon> navlink_polygons;8687HashMap<NavRegion2D *, Ref<NavRegionIteration2D>> region_ptr_to_region_iteration;8889LocalVector<NavMeshQueries2D::PathQuerySlot> path_query_slots;90Mutex path_query_slots_mutex;91Semaphore path_query_slots_semaphore;9293void clear() {94navmesh_polygon_count = 0;9596region_iterations.clear();97link_iterations.clear();98external_region_connections.clear();99navbases_polygons_external_connections.clear();100navlink_polygons.clear();101region_ptr_to_region_iteration.clear();102}103};104105class NavMapIterationRead2D {106const NavMapIteration2D &map_iteration;107108public:109_ALWAYS_INLINE_ NavMapIterationRead2D(const NavMapIteration2D &p_iteration) :110map_iteration(p_iteration) {111map_iteration.rwlock.read_lock();112map_iteration.users.increment();113}114_ALWAYS_INLINE_ ~NavMapIterationRead2D() {115map_iteration.users.decrement();116map_iteration.rwlock.read_unlock();117}118};119120121