[−][src]Struct gdnative_bindings::astar_2d::AStar2D
core class AStar2D
inherits Reference
(reference counted).
Official documentation
See the documentation of this class in the Godot engine's official documentation.
Memory management
The lifetime of this object is automatically managed through reference counting.
Class hierarchy
AStar2D inherits methods from:
Safety
All types in the Godot API have "interior mutability" in Rust parlance.
To enforce that the official thread-safety guidelines are
followed, the typestate pattern is used in the Ref
and TRef
smart pointers,
and the Instance
API. The typestate Access
in these types tracks whether the
access is unique, shared, or exclusive to the current thread. For more information,
see the type-level documentation on Ref
.
Implementations
impl AStar2D
[src]
pub fn new() -> Ref<Self, Unique>
[src]
Creates a new instance of this object.
This is a reference-counted type. The returned object is automatically managed
by Ref
.
pub fn add_point(&self, id: i64, position: Vector2, weight_scale: f64)
[src]
Adds a new point at the given position with the given identifier. The algorithm prefers points with lower [code]weight_scale[/code] to form a path. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 1 or larger.
[codeblock]
var astar = AStar2D.new()
astar.add_point(1, Vector2(1, 0), 4) # Adds the point (1, 0) with weight_scale 4 and id 1
[/codeblock]
If there already exists a point for the given [code]id[/code], its position and weight scale are updated to the given values.
Default Arguments
weight_scale
-1.0
pub fn are_points_connected(&self, id: i64, to_id: i64) -> bool
[src]
Returns whether there is a connection/segment between the given points.
pub fn clear(&self)
[src]
Clears all the points and segments.
pub fn connect_points(&self, id: i64, to_id: i64, bidirectional: bool)
[src]
Creates a segment between the given points. If [code]bidirectional[/code] is [code]false[/code], only movement from [code]id[/code] to [code]to_id[/code] is allowed, not the reverse direction.
[codeblock]
var astar = AStar2D.new()
astar.add_point(1, Vector2(1, 1))
astar.add_point(2, Vector2(0, 5))
astar.connect_points(1, 2, false)
[/codeblock]
Default Arguments
bidirectional
-true
pub fn disconnect_points(&self, id: i64, to_id: i64)
[src]
Deletes the segment between the given points.
pub fn get_available_point_id(&self) -> i64
[src]
Returns the next available point ID with no point associated to it.
pub fn get_closest_point(
&self,
to_position: Vector2,
include_disabled: bool
) -> i64
[src]
&self,
to_position: Vector2,
include_disabled: bool
) -> i64
Returns the ID of the closest point to [code]to_position[/code], optionally taking disabled points into account. Returns [code]-1[/code] if there are no points in the points pool.
[b]Note:[/b] If several points are the closest to [code]to_position[/code], the one with the smallest ID will be returned, ensuring a deterministic result.
Default Arguments
include_disabled
-false
pub fn get_closest_position_in_segment(&self, to_position: Vector2) -> Vector2
[src]
Returns the closest position to [code]to_position[/code] that resides inside a segment between two connected points.
[codeblock]
var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 5))
astar.connect_points(1, 2)
var res = astar.get_closest_position_in_segment(Vector2(3, 3)) # Returns (0, 3)
[/codeblock]
The result is in the segment that goes from [code]y = 0[/code] to [code]y = 5[/code]. It's the closest position in the segment to the given point.
pub fn get_id_path(&self, from_id: i64, to_id: i64) -> Int32Array
[src]
Returns an array with the IDs of the points that form the path found by AStar2D between the given points. The array is ordered from the starting point to the ending point of the path.
[codeblock]
var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 1), 1) # Default weight is 1
astar.add_point(3, Vector2(1, 1))
astar.add_point(4, Vector2(2, 0))
astar.connect_points(1, 2, false)
astar.connect_points(2, 3, false)
astar.connect_points(4, 3, false)
astar.connect_points(1, 4, false)
var res = astar.get_id_path(1, 3) # Returns [1, 2, 3]
[/codeblock]
If you change the 2nd point's weight to 3, then the result will be [code][1, 4, 3][/code] instead, because now even though the distance is longer, it's "easier" to get through point 4 than through point 2.
pub fn get_point_capacity(&self) -> i64
[src]
Returns the capacity of the structure backing the points, useful in conjunction with [code]reserve_space[/code].
pub fn get_point_connections(&self, id: i64) -> Int32Array
[src]
Returns an array with the IDs of the points that form the connection with the given point.
[codeblock]
var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 1))
astar.add_point(3, Vector2(1, 1))
astar.add_point(4, Vector2(2, 0))
astar.connect_points(1, 2, true)
astar.connect_points(1, 3, true)
var neighbors = astar.get_point_connections(1) # Returns [2, 3]
[/codeblock]
pub fn get_point_count(&self) -> i64
[src]
Returns the number of points currently in the points pool.
pub fn get_point_path(&self, from_id: i64, to_id: i64) -> Vector2Array
[src]
Returns an array with the points that are in the path found by AStar2D between the given points. The array is ordered from the starting point to the ending point of the path.
pub fn get_point_position(&self, id: i64) -> Vector2
[src]
Returns the position of the point associated with the given [code]id[/code].
pub fn get_point_weight_scale(&self, id: i64) -> f64
[src]
Returns the weight scale of the point associated with the given [code]id[/code].
pub fn get_points(&self) -> VariantArray
[src]
Returns an array of all points.
pub fn has_point(&self, id: i64) -> bool
[src]
Returns whether a point associated with the given [code]id[/code] exists.
pub fn is_point_disabled(&self, id: i64) -> bool
[src]
Returns whether a point is disabled or not for pathfinding. By default, all points are enabled.
pub fn remove_point(&self, id: i64)
[src]
Removes the point associated with the given [code]id[/code] from the points pool.
pub fn reserve_space(&self, num_nodes: i64)
[src]
Reserves space internally for [code]num_nodes[/code] points, useful if you're adding a known large number of points at once, for a grid for instance. New capacity must be greater or equals to old capacity.
pub fn set_point_disabled(&self, id: i64, disabled: bool)
[src]
Disables or enables the specified point for pathfinding. Useful for making a temporary obstacle.
Default Arguments
disabled
-true
pub fn set_point_position(&self, id: i64, position: Vector2)
[src]
Sets the [code]position[/code] for the point with the given [code]id[/code].
pub fn set_point_weight_scale(&self, id: i64, weight_scale: f64)
[src]
Sets the [code]weight_scale[/code] for the point with the given [code]id[/code].
Methods from Deref<Target = Reference>
pub fn init_ref(&self) -> bool
[src]
Initializes the internal reference counter. Use this only if you really know what you are doing.
Returns whether the initialization was successful.
Trait Implementations
impl Debug for AStar2D
[src]
impl Deref for AStar2D
[src]
impl DerefMut for AStar2D
[src]
impl GodotObject for AStar2D
[src]
type RefKind = RefCounted
The memory management kind of this type. This modifies the behavior of the
Ref
smart pointer. See its type-level documentation for more
information. Read more
fn class_name() -> &'static str
[src]
fn null() -> Null<Self>
[src]
fn new() -> Ref<Self, Unique> where
Self: Instanciable,
[src]
Self: Instanciable,
fn cast<T>(&self) -> Option<&T> where
T: GodotObject + SubClass<Self>,
[src]
T: GodotObject + SubClass<Self>,
fn upcast<T>(&self) -> &T where
Self: SubClass<T>,
T: GodotObject,
[src]
Self: SubClass<T>,
T: GodotObject,
unsafe fn assume_shared(&self) -> Ref<Self, Shared>
[src]
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
[src]
Self: GodotObject<RefKind = RefCounted>,
unsafe fn assume_unique(&self) -> Ref<Self, Unique>
[src]
impl Instanciable for AStar2D
[src]
impl Sealed for AStar2D
[src]
impl SubClass<Object> for AStar2D
[src]
impl SubClass<Reference> for AStar2D
[src]
Auto Trait Implementations
impl RefUnwindSafe for AStar2D
impl !Send for AStar2D
impl !Sync for AStar2D
impl Unpin for AStar2D
impl UnwindSafe for AStar2D
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SubClass<T> for T where
T: GodotObject,
[src]
T: GodotObject,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,