diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/classes/AStar.xml | 28 | ||||
-rw-r--r-- | doc/classes/Control.xml | 13 | ||||
-rw-r--r-- | doc/classes/String.xml | 2 | ||||
-rw-r--r-- | doc/classes/Variant.xml | 33 |
4 files changed, 68 insertions, 8 deletions
diff --git a/doc/classes/AStar.xml b/doc/classes/AStar.xml index e835af01e8..6304bd34f6 100644 --- a/doc/classes/AStar.xml +++ b/doc/classes/AStar.xml @@ -1,11 +1,23 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AStar" inherits="Reference" category="Core" version="3.2"> <brief_description> - AStar class representation that uses 3d-vectors as edges. + An implementation of A* to find shortest paths among connected points in space. </brief_description> <description> - A* (A star) is a computer algorithm that is widely used in pathfinding and graph traversal, the process of plotting an efficiently directed path between multiple points. It enjoys widespread use due to its performance and accuracy. Godot's A* implementation make use of vectors as points. - You must add points manually with [method add_point] and create segments manually with [method connect_points]. So you can test if there is a path between two points with the [method are_points_connected] function, get the list of existing ids in the found path with [method get_id_path], or the points list with [method get_point_path]. + A* (A star) is a computer algorithm that is widely used in pathfinding and graph traversal, the process of plotting short paths among vertices (points), passing through a given set of edges (segments). It enjoys widespread use due to its performance and accuracy. Godot's A* implementation uses points in three-dimensional space and Euclidean distances by default. + You must add points manually with [method add_point] and create segments manually with [method connect_points]. Then you can test if there is a path between two points with the [method are_points_connected] function, get a path containing indices by [method get_id_path], or one containing actual coordinates with [method get_point_path]. + It is also possible to use non-Euclidean distances. To do so, create a class that extends [code]AStar[/code] and override methods [method _compute_cost] and [method _estimate_cost]. Both take two indices and return a length, as is shown in the following example. + [codeblock] + class MyAStar: + extends AStar + + func _compute_cost(u, v): + return abs(u - v) + + func _estimate_cost(u, v): + return min(0, abs(u - v) - 1) + [/codeblock] + [method _estimate_cost] should return a lower bound of the distance, i.e. [code]_estimate_cost(u, v) <= _compute_cost(u, v)[/code]. This serves as a hint to the algorithm because the custom [code]_compute_cost[/code] might be computation-heavy. If this is not the case, make [method _estimate_cost] return the same value as [method _compute_cost] to provide the algorithm with the most accurate information. </description> <tutorials> </tutorials> @@ -19,6 +31,7 @@ </argument> <description> Called when computing the cost between two connected points. + Note that this function is hidden in the default [code]AStar[/code] class. </description> </method> <method name="_estimate_cost" qualifiers="virtual"> @@ -30,6 +43,7 @@ </argument> <description> Called when estimating the cost between a point and the path's ending point. + Note that this function is hidden in the default [code]AStar[/code] class. </description> </method> <method name="add_point"> @@ -57,8 +71,10 @@ </argument> <argument index="1" name="to_id" type="int"> </argument> + <argument index="2" name="bidirectional" type="bool" default="true"> + </argument> <description> - Returns whether there is a connection/segment between the given points. + Returns whether the two given points are directly connected by a segment. If [code]bidirectional[/code] is [code]false[/code], returns whether movement from [code]id[/code] to [code]to_id[/code] is possible through this segment. </description> </method> <method name="clear"> @@ -94,8 +110,10 @@ </argument> <argument index="1" name="to_id" type="int"> </argument> + <argument index="2" name="bidirectional" type="bool" default="true"> + </argument> <description> - Deletes the segment between the given points. + Deletes the 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 prevented, and a unidirectional segment possibly remains. </description> </method> <method name="get_available_point_id" qualifiers="const"> diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index f5a8683a39..75d5a72fb1 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -652,7 +652,18 @@ <argument index="0" name="control" type="Control"> </argument> <description> - Shows the given control at the mouse pointer. A good time to call this method is in [method get_drag_data]. + Shows the given control at the mouse pointer. A good time to call this method is in [method get_drag_data]. The control must not be in the scene tree. + [codeblock] + export (Color, RGBA) var color = Color(1, 0, 0, 1) + + func get_drag_data(position): + # Use a control that is not in the tree + var cpb = ColorPickerButton.new() + cpb.color = color + cpb.rect_size = Vector2(50, 50) + set_drag_preview(cpb) + return color + [/codeblock] </description> </method> <method name="set_end"> diff --git a/doc/classes/String.xml b/doc/classes/String.xml index cf152e716e..e0a4a24299 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -459,7 +459,7 @@ <argument index="1" name="what" type="String"> </argument> <description> - Inserts a substring at a given position. + Returns a copy of the string with the substring [code]what[/code] inserted at the given position. </description> </method> <method name="is_abs_path"> diff --git a/doc/classes/Variant.xml b/doc/classes/Variant.xml index 522e131b45..28c3bc8e85 100644 --- a/doc/classes/Variant.xml +++ b/doc/classes/Variant.xml @@ -4,7 +4,37 @@ The most important data type in Godot. </brief_description> <description> + In computer programming, a Variant class is a class that is designed to store a variety of other types. Dynamic programming languages like PHP, Lua, JavaScript and GDScript like to use them to store variables' data on the backend. With these Variants, properties are able to change value types freely. + [codeblock] + var foo = 2 # foo is dynamically an integer + foo = "Now foo is a string!" + foo = Reference.new() # foo is an Object + var bar: int = 2 # bar is a statically typed integer. + # bar = "Uh oh! I can't make static variables become a different type!" + [/codeblock] + Godot tracks all scripting API variables within Variants. Without even realizing it, you use Variants all the time. When a particular language enforces its own rules for keeping data typed, then that language is applying its own custom logic over the base Variant scripting API. + - GDScript automatically wrap values in them. It keeps all data in plain Variants by default and then optionally enforces custom static typing rules on variable types. + - VisualScript tracks properties inside Variants as well, but it also uses static typing. The GUI interface enforces that properties have a particular type that doesn't change over time. + - C# is statically typed, but uses the Mono [code]object[/code] type in place of Godot's Variant class when it needs to represent a dynamic value. [code]object[/code] is the Mono runtime's equivalent of the same concept. + - The statically-typed language NativeScript C++ does not define a built-in Variant-like class. Godot's GDNative bindings provide their own godot::Variant class for users; Any point at which the C++ code starts interacting with the Godot runtime is a place where you might have to start wrapping data inside Variant objects. + The global [member @GDScript.typeof] function returns the enumerated value of the Variant type stored in the current variable. These correspond to [code]TYPE_*[/code] constants in the [@GlobalScope] docs. + [codeblock] + var foo = 2 + match typeof(foo): + TYPE_NIL: + print("foo is null!") + TYPE_INTEGER: + print("foo is an integer!") + TYPE_OBJECT: + # Note that Objects are their own special category. + # To get the name of the underlying Object type, you need the `get_class()` method. + print("foo is a(n) %s" % foo.get_class()) # inject the class name into a formatted string. + # Note also that there is not yet any way to get a script's `class_name` string easily. + # To fetch that value, you need to dig deeply into a hidden ProjectSettings setting: an Array of Dictionaries called "_global_script_classes". + # Open your project.godot file to see it up close. + [/codeblock] A Variant takes up only 20 bytes and can store almost any engine datatype inside of it. Variants are rarely used to hold information for long periods of time. Instead, they are used mainly for communication, editing, serialization and moving data around. + Godot has specifically invested in making its Variant class as flexible as possible; so much so that it is used for a multitude of operations to facilitate communication between all of Godot's systems. A Variant: - Can store almost any datatype. - Can perform operations between many variants. GDScript uses Variant as its atomic/native datatype. @@ -16,10 +46,11 @@ - Can be serialized to text and use it for printing values and editable settings. - Can work as an exported property, so the editor can edit it universally. - Can be used for dictionaries, arrays, parsers, etc. - [b]Containers ([Array] and [Dictionary]):[/b] Both are implemented using variants. A [Dictionary] can match any datatype used as key to any other datatype. An [Array] just holds an array of Variants. Of course, a Variant can also hold a [Dictionary] and an [Array] inside, making it even more flexible. + [b]Containers (Array and Dictionary):[/b] Both are implemented using variants. A [Dictionary] can match any datatype used as key to any other datatype. An [Array] just holds an array of Variants. Of course, a Variant can also hold a [Dictionary] and an [Array] inside, making it even more flexible. Modifications to a container will modify all references to it. A [Mutex] should be created to lock it if multi-threaded access is desired. </description> <tutorials> + <link>https://docs.godotengine.org/en/latest/development/cpp/variant_class.html</link> </tutorials> <methods> </methods> |