Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/navigation_2d/2d/nav_region_iteration_2d.h
10278 views
1
/**************************************************************************/
2
/* nav_region_iteration_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
#include "../nav_utils_2d.h"
34
#include "nav_base_iteration_2d.h"
35
#include "scene/resources/2d/navigation_polygon.h"
36
37
#include "core/math/rect2.h"
38
39
class NavRegion2D;
40
class NavRegionIteration2D;
41
42
struct NavRegionIterationBuild2D {
43
Nav2D::PerformanceData performance_data;
44
45
NavRegion2D *region = nullptr;
46
47
Vector2 map_cell_size;
48
Transform2D region_transform;
49
50
struct NavMeshData {
51
Vector<Vector2> vertices;
52
Vector<Vector<int>> polygons;
53
54
void clear() {
55
vertices.clear();
56
polygons.clear();
57
}
58
} navmesh_data;
59
60
Ref<NavRegionIteration2D> region_iteration;
61
62
HashMap<Nav2D::EdgeKey, Nav2D::EdgeConnectionPair, Nav2D::EdgeKey> iter_connection_pairs_map;
63
64
void reset() {
65
performance_data.reset();
66
67
navmesh_data.clear();
68
region_iteration = Ref<NavRegionIteration2D>();
69
iter_connection_pairs_map.clear();
70
}
71
};
72
73
class NavRegionIteration2D : public NavBaseIteration2D {
74
GDCLASS(NavRegionIteration2D, NavBaseIteration2D);
75
76
public:
77
Transform2D transform;
78
real_t surface_area = 0.0;
79
Rect2 bounds;
80
LocalVector<Nav2D::ConnectableEdge> external_edges;
81
82
const Transform2D &get_transform() const { return transform; }
83
real_t get_surface_area() const { return surface_area; }
84
Rect2 get_bounds() const { return bounds; }
85
const LocalVector<Nav2D::ConnectableEdge> &get_external_edges() const { return external_edges; }
86
87
virtual ~NavRegionIteration2D() override {
88
external_edges.clear();
89
navmesh_polygons.clear();
90
internal_connections.clear();
91
}
92
};
93
94