Path: blob/master/modules/navigation_3d/3d/nav_map_iteration_3d.h
10278 views
/**************************************************************************/1/* nav_map_iteration_3d.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_3d.h"33#include "../nav_utils_3d.h"34#include "nav_mesh_queries_3d.h"3536#include "core/math/math_defs.h"37#include "core/os/semaphore.h"3839class NavLinkIteration3D;40class NavRegion3D;41class NavRegionIteration3D;42struct NavMapIteration3D;4344struct NavMapIterationBuild3D {45Vector3 merge_rasterizer_cell_size;46bool use_edge_connections = true;47real_t edge_connection_margin;48real_t link_connection_radius;49Nav3D::PerformanceData performance_data;50int polygon_count = 0;51int free_edge_count = 0;5253HashMap<Nav3D::EdgeKey, Nav3D::EdgeConnectionPair, Nav3D::EdgeKey> iter_connection_pairs_map;54LocalVector<Nav3D::Connection> iter_free_edges;5556NavMapIteration3D *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 NavMapIteration3D {73mutable SafeNumeric<uint32_t> users;74RWLock rwlock;7576Vector3 map_up;7778LocalVector<Ref<NavRegionIteration3D>> region_iterations;79LocalVector<Ref<NavLinkIteration3D>> link_iterations;8081int navmesh_polygon_count = 0;8283// The edge connections that the map builds on top with the edge connection margin.84HashMap<const NavBaseIteration3D *, LocalVector<Nav3D::Connection>> external_region_connections;85HashMap<const NavBaseIteration3D *, LocalVector<LocalVector<Nav3D::Connection>>> navbases_polygons_external_connections;8687LocalVector<Nav3D::Polygon> navlink_polygons;8889HashMap<NavRegion3D *, Ref<NavRegionIteration3D>> region_ptr_to_region_iteration;9091LocalVector<NavMeshQueries3D::PathQuerySlot> path_query_slots;92Mutex path_query_slots_mutex;93Semaphore path_query_slots_semaphore;9495void clear() {96map_up = Vector3();97navmesh_polygon_count = 0;9899region_iterations.clear();100link_iterations.clear();101external_region_connections.clear();102navbases_polygons_external_connections.clear();103navlink_polygons.clear();104region_ptr_to_region_iteration.clear();105}106};107108class NavMapIterationRead3D {109const NavMapIteration3D &map_iteration;110111public:112_ALWAYS_INLINE_ NavMapIterationRead3D(const NavMapIteration3D &p_iteration) :113map_iteration(p_iteration) {114map_iteration.rwlock.read_lock();115map_iteration.users.increment();116}117_ALWAYS_INLINE_ ~NavMapIterationRead3D() {118map_iteration.users.decrement();119map_iteration.rwlock.read_unlock();120}121};122123124