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

Utilities to work with the node tree #9

Closed
4 tasks done
Bromeon opened this issue Oct 3, 2022 · 4 comments
Closed
4 tasks done

Utilities to work with the node tree #9

Bromeon opened this issue Oct 3, 2022 · 4 comments
Labels
c: engine Godot classes (nodes, resources, ...) feature Adds functionality to the library good first issue Good for newcomers

Comments

@Bromeon
Copy link
Member

Bromeon commented Oct 3, 2022

Similar to the old NodeResolveExt, utility methods would allow more idiomatic access to the scene tree.
Those could be provided as an extension trait or in a dedicated module/struct.

Examples:

  • get_node<T>
  • find_node<T> (optional) -- implemented as try_get_node
  • load<T>
  • PackedScene::instance<T>
@Bromeon Bromeon added feature Adds functionality to the library c: engine Godot classes (nodes, resources, ...) labels Oct 3, 2022
@Bromeon Bromeon added the good first issue Good for newcomers label Mar 21, 2023
@HenryWConklin
Copy link
Contributor

Seems like get_node and load are implemented.

fn get_node_as<T>(&self, path: impl Into<NodePath>) -> Gd<T>
where
T: GodotClass + Inherits<Node>,
{
let path = path.into();
let copy = path.clone(); // TODO avoid copy
self.try_get_node_as(path).unwrap_or_else(|| {
panic!(
"There is no node of type {ty} path `{copy}`",
ty = T::CLASS_NAME
)
})
}
/// Retrieves the node at path `path` (fallible).
///
/// If the node is not found, or if it does not have type `T` or inherited,
/// `None` will be returned.
fn try_get_node_as<T>(&self, path: impl Into<NodePath>) -> Option<Gd<T>>
where
T: GodotClass + Inherits<Node>;

Is PackedScene::instance<T> the only item left on this?

@Bromeon
Copy link
Member Author

Bromeon commented Apr 1, 2023

There might be other similar methods 🙂

hapenia pushed a commit to hapenia/gdextension that referenced this issue May 26, 2023
# This is the 1st commit message:

Parse gdextension_interface.h declarations using regex

# This is the commit message #2:

AsUninit trait to convert FFI pointers to their uninitialized versions

# This is the commit message godot-rust#3:

GodotFfi::from_sys_init() now uses uninitialized pointer types

# This is the commit message godot-rust#4:

Introduce GDExtensionUninitialized*Ptr, without changing semantics

# This is the commit message godot-rust#5:

Adjust init code to new get_proc_address mechanism

# This is the commit message godot-rust#6:

Make `trace` feature available in godot-ffi, fix interface access before initialization

# This is the commit message godot-rust#7:

Compatibility layer between Godot 4.0 and 4.1 (different GDExtension APIs)

# This is the commit message godot-rust#8:

Add GdextBuild to access build/runtime metadata

# This is the commit message godot-rust#9:

Detect 4.0 <-> 4.1 mismatches in both directions + missing `compatibility_minimum = 4.1`

# This is the commit message godot-rust#10:

Detect legacy/modern version of C header (also without `custom-godot` feature)

# This is the commit message godot-rust#11:

CI: add jobs that use patched 4.0.x versions

# This is the commit message godot-rust#12:

Remove several memory leaks by constructing into uninitialized pointers

# This is the commit message godot-rust#13:

CI: memcheck jobs for both 4.0.3 and nightly

# This is the commit message godot-rust#14:

Remove ToVariant, FromVariant, and VariantMetadata impls for pointers

This commit splits SignatureTuple into two separate traits:
PtrcallSignatureTuple and VarcallSignatureTuple. The latter is a child
of the former. PtrcallSignatureTuple is used for ptrcall and only
demands GodotFuncMarshall of its arguments. VarcallSignatureTuple is
used for varcall and additionally demands ToVariant, FromVariant, and
VariantMetadata of its arguments, so pointers cannot benefit from the
optimizations provided by varcall over ptrcall.

# This is the commit message godot-rust#15:

Adds FromVariant and ToVariant proc macros

# This is the commit message godot-rust#16:

godot-core: builtin: reimplement Plane functions/methods

# This is the commit message godot-rust#17:

impl GodotFfi for Option<T> when T is pointer sized and nullable godot-rust#240

Additionally FromVariant and ToVariant are also implemented for Option<Gd<T>>
to satisfy all the requirements for ffi and godot_api.

# This is the commit message godot-rust#18:

Fix UB in virtual method calls that take objects
Fix incorrect incrementing of refcount when calling in to godot
Fix refcount not being incremented when we receive a refcounted object in virtual methods

# This is the commit message godot-rust#19:

fix UB caused by preload weirdness

# This is the commit message godot-rust#20:

Implements swizzle and converts from/to tuples
@Cankyre
Copy link
Contributor

Cankyre commented Jun 13, 2023

Hoi, is this up-to-date? I can work on some of the features.

@Bromeon
Copy link
Member Author

Bromeon commented Jun 13, 2023

#299 implemented instantiate_as, so it's complete.

I'll close this, if you have other good examples, let me know. But don't find some just for the sake of it, it should be common operations 😉

@Bromeon Bromeon closed this as completed Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: engine Godot classes (nodes, resources, ...) feature Adds functionality to the library good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants