Path: blob/master/scene/2d/navigation/navigation_obstacle_2d.h
9904 views
/**************************************************************************/1/* navigation_obstacle_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 "scene/2d/node_2d.h"3334class NavigationPolygon;35class NavigationMeshSourceGeometryData2D;3637class NavigationObstacle2D : public Node2D {38GDCLASS(NavigationObstacle2D, Node2D);3940RID obstacle;41RID map_before_pause;42RID map_override;43RID map_current;4445real_t radius = 0.0;4647Vector<Vector2> vertices;48bool vertices_are_clockwise = true;49bool vertices_are_valid = true;5051bool avoidance_enabled = true;52uint32_t avoidance_layers = 1;5354Transform2D previous_transform;5556Vector2 velocity;57Vector2 previous_velocity;58bool velocity_submitted = false;5960bool affect_navigation_mesh = false;61bool carve_navigation_mesh = false;6263#ifdef DEBUG_ENABLED64private:65RID debug_canvas_item;66RID debug_mesh_rid;6768void _update_fake_agent_radius_debug();69void _update_static_obstacle_debug();70#endif // DEBUG_ENABLED7172protected:73static void _bind_methods();74void _notification(int p_what);7576public:77NavigationObstacle2D();78virtual ~NavigationObstacle2D();7980RID get_rid() const { return obstacle; }8182void set_avoidance_enabled(bool p_enabled);83bool get_avoidance_enabled() const;8485void set_navigation_map(RID p_navigation_map);86RID get_navigation_map() const;8788void set_radius(real_t p_radius);89real_t get_radius() const { return radius; }9091void set_vertices(const Vector<Vector2> &p_vertices);92const Vector<Vector2> &get_vertices() const { return vertices; }9394bool are_vertices_clockwise() const { return vertices_are_clockwise; }95bool are_vertices_valid() const { return vertices_are_valid; }9697void set_avoidance_layers(uint32_t p_layers);98uint32_t get_avoidance_layers() const;99100void set_avoidance_mask(uint32_t p_mask);101uint32_t get_avoidance_mask() const;102103void set_avoidance_layer_value(int p_layer_number, bool p_value);104bool get_avoidance_layer_value(int p_layer_number) const;105106void set_velocity(const Vector2 p_velocity);107Vector2 get_velocity() const { return velocity; }108109void _avoidance_done(Vector3 p_new_velocity); // Dummy110111void set_affect_navigation_mesh(bool p_enabled);112bool get_affect_navigation_mesh() const;113114void set_carve_navigation_mesh(bool p_enabled);115bool get_carve_navigation_mesh() const;116117PackedStringArray get_configuration_warnings() const override;118119private:120static Callable _navmesh_source_geometry_parsing_callback;121static RID _navmesh_source_geometry_parser;122123public:124static void navmesh_parse_init();125static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);126127private:128void _update_map(RID p_map);129void _update_position(const Vector2 p_position);130void _update_transform();131};132133134