Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot API - gdext API differences #887

Open
lmsonic opened this issue Sep 5, 2024 · 0 comments
Open

Godot API - gdext API differences #887

lmsonic opened this issue Sep 5, 2024 · 0 comments
Labels
breaking-change Requires SemVer bump c: core Core components quality-of-life No new functionality, but improves ergonomics/internals

Comments

@lmsonic
Copy link

lmsonic commented Sep 5, 2024

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

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, returns null. The segment begins at from and ends at to.

Array


Godot : Variant get_typed_script() const
Returns the script associated with the typed array. This method returns a Script instance or null.
gdext : (missing)


Godot: Variant pop_at ( int position )
Removes and returns the element of the array at index position. If negative, position is considered relative to the end of the array. Leaves the array unchanged and returns null if the array is empty or if it's accessed out of bounds. An error message is printed when the array is accessed out of bounds, but not when the array is empty.
Note: On large arrays, this method can be slower than pop_back as it will reindex the array's elements that are located after the removed element. The larger the array and the lower the index of the removed element, the slower pop_at will be.

gdext: pub fn remove(&mut self, index: usize) -> T
⚠️ Removes and returns the element at the specified index. Equivalent of 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

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, the default 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)

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

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.

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: core Core components labels Sep 5, 2024
@Bromeon Bromeon added the breaking-change Requires SemVer bump label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Requires SemVer bump c: core Core components quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

No branches or pull requests

2 participants