Skip to content

Commit 297a2e7

Browse files
MrGVSVcart
andauthored
0.11 Section: Better Proxies (#670)
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
1 parent d74fd65 commit 297a2e7

File tree

1 file changed

+36
-0
lines changed
  • content/news/2023-07-07-bevy-0.11

1 file changed

+36
-0
lines changed

content/news/2023-07-07-bevy-0.11/index.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,42 @@ Since our last release a few months ago we've added a _ton_ of new features, bug
2020
flat surfaces a feel of depth through parallaxing the material's textures.
2121
* **Gamepad Rumble API**: an ECS-friendly way of making controllers rumble
2222

23+
## Better Proxies
24+
25+
<div class="release-feature-authors">authors: @MrGVSV</div>
26+
27+
Bevy's reflection API has a handful of structs which are collectively known as "dynamic" types.
28+
These include [`DynamicStruct`], [`DynamicTuple`], and more, and they are used to dynamically construct types
29+
of any shape or form at runtime.
30+
These types are also used to create are commonly referred to as "proxies", which are dynamic types
31+
that are used to represent an actual concrete type.
32+
33+
These proxies are what powers the [`Reflect::clone_value`] method, which generates these proxies under the hood
34+
in order to construct a runtime clone of the data.
35+
36+
Unfortunately, this results in a few [subtle footguns] that could catch users by surprise,
37+
such as the hashes of proxies differing from the hashes of the concrete type they represent,
38+
proxies not being considered equivalent to their concrete counterparts, and more.
39+
40+
While this release does not necessarily fix these issues, it does establish a solid foundation for fixing them in the future.
41+
The way it does this is by changing how a proxy is defined.
42+
43+
Before 0.11, a proxy was only defined by cloning the concrete type's [`Reflect::type_name`] string
44+
and returning it as its own `Reflect::type_name`.
45+
46+
Now in 0.11, a proxy is defined by copying a reference to the static [`TypeInfo`] of the concrete type.
47+
This will allow us to access more of the concrete type's type information dynamically, without requiring the `TypeRegistry`.
48+
In a [future release], we will make use of this to store hashing and comparison strategies in the `TypeInfo` directly
49+
in order to mitigate the proxy issues mentioned above.
50+
51+
[`DynamicStruct`]: https://docs.rs/bevy/0.11.0/bevy/reflect/struct.DynamicStruct.html
52+
[`DynamicTuple`]: https://docs.rs/bevy/0.11.0/bevy/reflect/struct.DynamicTuple.html
53+
[`Reflect::clone_value`]: https://docs.rs/bevy/0.11.0/bevy/reflect/trait.Reflect.html#tymethod.clone_value
54+
[subtle footguns]: https://github.com/bevyengine/bevy/issues/6601
55+
[`Reflect::type_name`]: https://docs.rs/bevy/0.11.0/bevy/reflect/trait.Reflect.html#tymethod.type_name
56+
[`TypeInfo`]: https://docs.rs/bevy/0.11.0/bevy/reflect/enum.TypeInfo.html
57+
[future release]: https://github.com/bevyengine/bevy/pull/8695
58+
2359
## `FromReflect` Ergonomics
2460

2561
<div class="release-feature-authors">authors: @MrGVSV</div>

0 commit comments

Comments
 (0)