Description
Note
Edited by Bromeon to stay up-to-date with progress.
🚧 actionable to be addressed.
✅ completed.
While scouring for null related documentation in the Godot API, i found some inconsistencies betwen godot and gdext API. Some probably idiomatically better in rust, but I still document them here so we don't lose track. This is not exhaustive because I only found them while searching for "null" in the API
AABB
- ✅ add method
intersect_ray()
, returningOption<Vector3>
. - ✅ decide if
intersects_ray()
should stay, and if yes, implemented using the above.
Both implemented in #1001.
Godot : Variant intersects_ray ( Vector3 from, Vector3 dir ) const
Returns the first point where this bounding box and the given ray intersect, as a Vector3. If no intersection occurs, returns null
.
The ray begin at from
, faces dir
and extends towards infinity.
gdext : pub fn intersects_ray(self, from: Vector3, dir: Vector3) -> bool
Returns true
if the given ray intersects with this AABB. Ray length is infinite.
Panics:
If self.size
is negative.
Godot : Variant intersects_segment ( Vector3 from, Vector3 to ) const
gdext : pub fn intersects_segment(self, from: Vector3
Returns the first point where this bounding box and the given segment intersect, as a Vector3. If no intersection occurs, returnsnull
. The segment begins atfrom
and ends atto
.
Array
Godot : Variant get_typed_script() const
Returns the script associated with the typed array. This method returns a Script instance ornull
.
gdext : (missing)
- 🚧 Decide if we need this.
- ✅
pop_at
named asremove
in Rust is intended and doc-aliased; nothing to do.
gdext: pub fn remove(&mut self, index: usize) -> T
pop_at
in GDScript.
On large arrays, this method is much slower than pop()
as it will move all the array’s elements after the removed element. The larger the array, the slower remove()
will be.
Panics
If index
is out of bounds.
Dictionary
🚧 We should add
get_or_add
, maybe check Rust naming.Godot: Variant get_or_add(key: Variant, default: Variant = null)
Gets a value and ensures the key is set. If the
key
exists in the dictionary, this behaves like get. Otherwise, thedefault
value is inserted into the dictionary and returned.
gdext: (missing)
(Iride's note: This apparently is new API in 4.3)
PackedByteArray
(Iride's note: Everything here is missing from gdext)
- ✅ All
PackedByteArray
methods have been implemented in Add encoding, string conversion and compression methods toPackedByteArray
#994.
float decode_double(byte_offset: int) const
Decodes a 64-bit floating-point number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0.0
if a valid number can't be decoded.
float decode_float(byte_offset: int) const
Decodes a 32-bit floating-point number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0.0
if a valid number can't be decoded.
float decode_half(byte_offset: int) const
Decodes a 16-bit floating-point number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0.0
if a valid number can't be decoded.
int decode_s8(byte_offset: int) const
Decodes a 8-bit signed integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
int decode_s16(byte_offset: int) const
Decodes a 16-bit signed integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
int decode_s32(byte_offset: int) const
Decodes a 32-bit signed integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
int decode_s64(byte_offset: int) const
Decodes a 64-bit signed integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
int decode_u8(byte_offset: int) const
Decodes a 8-bit unsigned integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
int decode_u16(byte_offset: int) const
Decodes a 16-bit unsigned integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
int decode_u32(byte_offset: int) const
Decodes a 32-bit unsigned integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
int decode_u64(byte_offset: int) const
Decodes a 64-bit unsigned integer number from the bytes starting at byte_offset
. Fails if the byte count is insufficient. Returns 0
if a valid number can't be decoded.
Variant decode_var(byte_offset: int, allow_objects: bool = false) const
Decodes a Variant from the bytes starting at byte_offset
. Returns null
if a valid variant can't be decoded or the value is Object-derived and allow_objects
is false
.
int decode_var_size(byte_offset: int, allow_objects: bool = false) const
Decodes a size of a Variant from the bytes starting at byte_offset
. Requires at least 4 bytes of data starting at the offset, otherwise fails.
PackedByteArray decompress(buffer_size: int, compression_mode: int = 0) const
Returns a new PackedByteArray with the data decompressed. Set buffer_size
to the size of the uncompressed data. Set the compression mode using one of CompressionMode's constants.
Note: Decompression is not guaranteed to work with data not compressed by Godot, for example if data compressed with the deflate compression mode lacks a checksum or header.
PackedByteArray decompress_dynamic(max_output_size: int, compression_mode: int = 0) const
Returns a new PackedByteArray with the data decompressed. Set the compression mode using one of CompressionMode's constants. This method only accepts brotli, gzip, and deflate compression modes.
This method is potentially slower than decompress, as it may have to re-allocate its output buffer multiple times while decompressing, whereas decompress knows it's output buffer size from the beginning.
GZIP has a maximal compression ratio of 1032:1, meaning it's very possible for a small compressed payload to decompress to a potentially very large output. To guard against this, you may provide a maximum size this function is allowed to allocate in bytes via max_output_size
. Passing -1 will allow for unbounded output. If any positive value is passed, and the decompression exceeds that amount in bytes, then an error will be returned.
Note: Decompression is not guaranteed to work with data not compressed by Godot, for example if data compressed with the deflate compression mode lacks a checksum or header.
void encode_double(byte_offset: int, value: float)
Encodes a 64-bit floating-point number as bytes at the index of byte_offset
bytes. The array must have at least 8 bytes of allocated space, starting at the offset.
void encode_float(byte_offset: int, value: float)
Encodes a 32-bit floating-point number as bytes at the index of byte_offset
bytes. The array must have at least 4 bytes of space, starting at the offset.
void encode_half(byte_offset: int, value: float)
Encodes a 16-bit floating-point number as bytes at the index of byte_offset
bytes. The array must have at least 2 bytes of space, starting at the offset.
void encode_s8(byte_offset: int, value: int)
Encodes a 8-bit signed integer number (signed byte) at the index of byte_offset
bytes. The array must have at least 1 byte of space, starting at the offset.
void encode_s16(byte_offset: int, value: int)
Encodes a 16-bit signed integer number as bytes at the index of byte_offset
bytes. The array must have at least 2 bytes of space, starting at the offset.
void encode_s32(byte_offset: int, value: int)
Encodes a 32-bit signed integer number as bytes at the index of byte_offset
bytes. The array must have at least 4 bytes of space, starting at the offset.
void encode_s64(byte_offset: int, value: int)
Encodes a 64-bit signed integer number as bytes at the index of byte_offset
bytes. The array must have at least 8 bytes of space, starting at the offset.
void encode_u8(byte_offset: int, value: int)
Encodes a 8-bit unsigned integer number (byte) at the index of byte_offset
bytes. The array must have at least 1 byte of space, starting at the offset.
void encode_u16(byte_offset: int, value: int)
Encodes a 16-bit unsigned integer number as bytes at the index of byte_offset
bytes. The array must have at least 2 bytes of space, starting at the offset.
void encode_u32(byte_offset: int, value: int)
Encodes a 32-bit unsigned integer number as bytes at the index of byte_offset
bytes. The array must have at least 4 bytes of space, starting at the offset.
void encode_u64(byte_offset: int, value: int)
Encodes a 64-bit unsigned integer number as bytes at the index of byte_offset
bytes. The array must have at least 8 bytes of space, starting at the offset.
int encode_var(byte_offset: int, value: Variant, allow_objects: bool = false)
Encodes a Variant at the index of byte_offset
bytes. A sufficient space must be allocated, depending on the encoded variant's size. If allow_objects
is false
, Object-derived values are not permitted and will instead be serialized as ID-only.
String get_string_from_ascii() const
Converts ASCII/Latin-1 encoded array to String. Fast alternative to get_string_from_utf8 if the content is ASCII/Latin-1 only. Unlike the UTF-8 function this function maps every byte to a character in the array. Multibyte sequences will not be interpreted correctly. For parsing user input always use get_string_from_utf8. This is the inverse of String.to_ascii_buffer.
String get_string_from_utf8() const
Converts UTF-8 encoded array to String. Slower than get_string_from_ascii but supports UTF-8 encoded data. Use this function if you are unsure about the source of the data. For user input this function should always be preferred. Returns empty string if source array is not valid UTF-8 string. This is the inverse of String.to_utf8_buffer.
String get_string_from_utf16() const
Converts UTF-16 encoded array to String. If the BOM is missing, system endianness is assumed. Returns empty string if source array is not valid UTF-16 string. This is the inverse of String.to_utf16_buffer.
String get_string_from_utf32() const
Converts UTF-32 encoded array to String. System endianness is assumed. Returns empty string if source array is not valid UTF-32 string. This is the inverse of String.to_utf32_buffer.
String get_string_from_wchar() const
Converts wide character (wchar_t
, UTF-16 on Windows, UTF-32 on other platforms) encoded array to String. Returns empty string if source array is not valid wide string. This is the inverse of String.to_wchar_buffer.
bool has_encoded_var(byte_offset: int, allow_objects: bool = false) const
Returns true
if a valid Variant value can be decoded at the byte_offset
. Returns false
otherwise or when the value is Object-derived and allow_objects
is false
.
String hex_encode() const
Returns a hexadecimal representation of this array as a String.
var array = PackedByteArray([11, 46, 255])
print(array.hex_encode()) # Prints: 0b2eff
Plane
✅ Nothing to do; intersection APIs returning Option<Vector3>
are the optimal design. We need to make others (Aabb
, maybe rects) consistent with it.
Godot: Variant intersect_3(b: Plane, c: Plane) const
Returns the intersection point of the three planes b
, c
and this plane. If no intersection is found, null
is returned.
gdext: pub fn intersect_3(self, b: Plane, c: Plane) -> Option<Vector3>
Finds the intersection point of three planes.
If no intersection point is found, None
will be returned.
Godot: Variant intersects_ray(from: Vector3, dir: Vector3) const
Returns the intersection point of a ray consisting of the position from
and the direction normal dir
with this plane. If no intersection is found, null
is returned.
gdext: pub fn intersect_ray(self, from: Vector3, dir: Vector3) -> Option<Vector3>
Finds the intersection point of the plane with a ray.
The ray starts at position from
and has direction vector dir
, i.e. it is unbounded in one direction.
If no intersection is found (the ray is parallel to the plane or points away from it), None
will be returned.
Godot : Variant intersects_segment(from: Vector3, to: Vector3) const
Returns the intersection point of a segment from position from
to position to
with this plane. If no intersection is found, null
is returned.
gdext: pub fn intersect_segment(self, from: Vector3, to: Vector3) -> Option<Vector3>
Finds the intersection point of the plane with a line segment.
The segment starts at position ‘from’ and ends at position ‘to’, i.e. it is bounded at two directions.
If no intersection is found (the segment is parallel to the plane or does not intersect it), None
will be returned.