Commit Graph

99 Commits

Author SHA1 Message Date
Piotr Siuszko
23ca435e73 Cleanup, support for Cow<str> 2025-07-05 12:05:33 +02:00
Piotr Siuszko
a58f697363 Add helper trait for registering schema types 2025-07-05 11:43:27 +02:00
Piotr Siuszko
daf03b5b3a Restore a as a f32 field, add separate unsigned field in test struct 2025-07-05 09:46:01 +02:00
Piotr Siuszko
4b8d0064ef Fixes for NonZero types, store typepath for primitive types 2025-07-05 09:07:40 +02:00
Piotr Siuszko
0b375625e0 Basic support for NonZero types with not field 2025-07-05 08:22:40 +02:00
Piotr Siuszko
492ad8be31 Remove id field 2025-07-05 07:53:22 +02:00
Piotr Siuszko
714d56e1ed Use oneOf for Option types, use jsonschema for testing schemas 2025-07-04 17:24:59 +02:00
MevLyshkin
efec7d192f
Merge branch 'main' into proper-json-schema 2025-07-04 09:32:07 +02:00
Piotr Siuszko
15125a3de5 Docs fix 2025-07-04 09:31:26 +02:00
Joe Buehler
d16d216083
Add support for returning all Component and values to query method in the Bevy Remote Protocol (#19857)
# Objective

We should have an API with filtering to allow BRP clients to retrieve
all relevant data from the world state. Currently working on adding
examples - but reviews are appreciated! Still semi-WIP while I get my
head around bevy’s reflection and implementation :)

## Solution

This change adds support to query all entities in the world, and returns
all of their Reflected Components with corresponding values. For custom
`Components` it's important to still implement `Reflect` so that this
endpoint returns these. This will be useful for the
`bevy_entity_inspector` so that we can easily get the current world
state. We have modified the existing query API
so that clients can now pass in an empty `components[]` on the JSON
request.

## Testing

Updated example to showcase how to use the new endpoint to get all data:
```rust
/// Create a query_all request to send to the remote Bevy app.
/// This request will return all entities in the app, their components, and their
/// component values.
fn run_query_all_components_and_entities(url: String) -> Result<(), anyhow::Error> {
    let query_all_req = BrpRequest {
        jsonrpc: String::from("2.0"),
        method: String::from(BRP_QUERY_METHOD),
        id: Some(serde_json::to_value(1)?),
        params: None,
    };
    println!("query_all req: {:#?}", query_all_req);
    let query_all_res = ureq::post(&url)
        .send_json(query_all_req)?
        .body_mut()
        .read_json::<serde_json::Value>()?;
    println!("{query_all_res:#}");
    Ok(())
}
```

---

## Showcase
In the `client.rs` example, we can clearly see (assuming the `server.rs`
is running) a query hit for all entities and components:
```text
query_all req: BrpRequest {
    jsonrpc: "2.0",
    method: "bevy/query",
    id: Some(
        Number(1),
    ),
    params: Some(
        Object {
            "data": Object {
                "components": Array [],
                "has": Array [],
                "option": Array [],
            },
            "filter": Object {
                "with": Array [],
                "without": Array [],
            },
            "strict": Bool(false),
        },
    ),
}
```

And in the massive response:
```text
.....
{
      "components": {
        "bevy_window::monitor::Monitor": {
          "name": "\\\\.\\DISPLAY1",
          "physical_height": 1080,
          "physical_position": [
            -1920,
            0
          ],
          "physical_width": 1920,
          "refresh_rate_millihertz": 240000,
          "scale_factor": 1.25,
          "video_modes": [
            {
              "bit_depth": 32,
              "physical_size": [
                1920,
                1080
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1680,
                1050
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1600,
                900
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1440,
                900
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1400,
                1050
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1366,
                768
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1360,
                768
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1280,
                1024
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1280,
                960
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1280,
                800
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1280,
                768
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1280,
                720
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1280,
                600
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1152,
                864
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                1024,
                768
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                800,
                600
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                640,
                480
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                640,
                400
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                512,
                384
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                400,
                300
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                320,
                240
              ],
              "refresh_rate_millihertz": 240000
            },
            {
              "bit_depth": 32,
              "physical_size": [
                320,
                200
              ],
              "refresh_rate_millihertz": 240000
            }
          ]
        }
      },
      "entity": 4294967267
    },
....
```

What's also really cool about this and `bevy_reflect` is that we also
get custom components returned as well (see below for `"server::Cube":
1.0` as the custom reflected struct specified in `server.rs`:

```text
{
      "components": {
        "bevy_render::primitives::Aabb": {
          "center": [
            0.0,
            0.0,
            0.0
          ],
          "half_extents": [
            0.5,
            0.5,
            0.5
          ]
        },
        "bevy_render::view::visibility::InheritedVisibility": true,
        "bevy_render::view::visibility::ViewVisibility": true,
        "bevy_render::view::visibility::Visibility": "Inherited",
        "bevy_transform::components::global_transform::GlobalTransform": [
          1.0,
          0.0,
          0.0,
          0.0,
          1.0,
          0.0,
          0.0,
          0.0,
          1.0,
          0.0,
          2.4572744369506836,
          0.0
        ],
        "bevy_transform::components::transform::Transform": {
          "rotation": [
            0.0,
            0.0,
            0.0,
            1.0
          ],
          "scale": [
            1.0,
            1.0,
            1.0
          ],
          "translation": [
            0.0,
            2.4572744369506836,
            0.0
          ]
        },
        "bevy_transform::components::transform::TransformTreeChanged": null,
        "server::Cube": 1.0
      },
```

---------

Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
2025-07-03 18:51:32 +00:00
Piotr Siuszko
59cb4b6dc7 Format fix 2025-07-03 17:13:50 +02:00
Piotr Siuszko
9ed0787d41 schema IDs using URN format, further improvements, tests for export
endpoint
2025-07-03 17:08:51 +02:00
MevLyshkin
16c7db42aa
Merge branch 'main' into proper-json-schema 2025-07-03 11:41:33 +02:00
Piotr Siuszko
cd1b933333 Cleanup 2025-07-03 11:41:10 +02:00
Piotr Siuszko
d83f82f045 Schema definitions generate better 2025-07-03 11:40:27 +02:00
Piotr Siuszko
5ea21b4705 Start populating schema definitons field 2025-07-03 09:46:10 +02:00
Piotr Siuszko
27366c9f4f Cleanup and refactor 2025-07-01 21:57:10 +02:00
charlotte 🌸
92e65d5eb1
Upgrade to Rust 1.88 (#19825) 2025-06-26 19:38:19 +00:00
MevLyshkin
a67cccc107
Update crates/bevy_remote/src/lib.rs
Good call

Co-authored-by: Sébastien Job <sebastien.job@gmail.com>
2025-06-24 21:36:59 +02:00
Piotr Siuszko
8cea898f9c values bound fix 2025-06-23 18:22:02 +02:00
Piotr Siuszko
e9ee9462dd Rename reflect_types to reflect_type_data, update field doc 2025-06-23 18:13:11 +02:00
Piotr Siuszko
5dac986c84 Format code 2025-06-23 18:09:18 +02:00
Piotr Siuszko
7530568498 Clippy fixes 2025-06-23 18:06:11 +02:00
Piotr Siuszko
ef2ff40d75 Test without documentation fix, typo fixes 2025-06-23 18:02:32 +02:00
MevLyshkin
16278cb4a3
Merge branch 'main' into proper-json-schema 2025-06-23 17:53:31 +02:00
Piotr Siuszko
e93680baa3 Use Cow instead of String in JSON schema types 2025-06-23 17:20:16 +02:00
github-actions[bot]
a466084167
Bump Version after Release (#19774)
Bump version after release
This PR has been auto-generated

Fixes #19766

---------

Co-authored-by: Bevy Auto Releaser <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: François Mockers <francois.mockers@vleue.com>
Co-authored-by: François Mockers <mockersf@gmail.com>
2025-06-22 23:06:43 +00:00
Piotr Siuszko
16f9c87bdd Add InvalidJsonSchema error and helper impl for TypeRegistration 2025-06-21 21:55:58 +02:00
Piotr Siuszko
f2fd5707f0 Clean up JSON schema test messages 2025-06-21 21:50:23 +02:00
Piotr Siuszko
0a3b70762c Add JSON Schema version identification field 2025-06-21 04:27:02 +02:00
Piotr Siuszko
c221b5ef44 Merge remote-tracking branch 'origin/main' into proper-json-schema
# Conflicts:
#	crates/bevy_remote/Cargo.toml
#	crates/bevy_remote/src/builtin_methods.rs
#	crates/bevy_remote/src/schemas/json_schema.rs
#	crates/bevy_remote/src/schemas/mod.rs
2025-06-21 04:16:24 +02:00
MevLyshkin
84f21f7c8a
Schema types metadata (#19524)
# Objective

- Currently there is predefinied list of supported DataTypes that can be
detected on Bevy JSON Schema generation and mapped as reflect_types
array elements.
- Make it possible to register custom `reflectTypes` mappings for Bevy
JSON Schema.

## Solution

- Create a `SchemaTypesMetadata` Resource that will hold mappings for
`TypeId` of `TypeData`. List is bigger from beggining and it is possible
to expand it without forking package.

## Testing

- I use it for quite a while in my game, I have a fork of bevy_remote
with more changes that later I want to merge to main as well.

---------

Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
2025-06-20 17:07:16 +00:00
Piotr Siuszko
77c9da49d6 ReflectJsonSchema for custom schemas 2025-06-20 14:53:53 +02:00
Piotr Siuszko
8e4809f123 Default values for schemas 2025-06-20 14:31:16 +02:00
François Mockers
4e694aea53
ECS: put strings only used for debug behind a feature (#19558)
# Objective

- Many strings in bevy_ecs are created but only used for debug: system
name, component name, ...
- Those strings make a significant part of the final binary and are no
use in a released game

## Solution

- Use [`strings`](https://linux.die.net/man/1/strings) to find ...
strings in a binary
- Try to find where they come from
- Many are made from `type_name::<T>()` and only used in error / debug
messages
- Add a new structure `DebugName` that holds no value if `debug` feature
is disabled
- Replace `core::any::type_name::<T>()` by `DebugName::type_name::<T>()`

## Testing

Measurements were taken without the new feature being enabled by
default, to help with commands

### File Size

I tried building the `breakout` example with `cargo run --release
--example breakout`

|`debug` enabled|`debug` disabled|
|-|-|
|81621776 B|77735728B|
|77.84MB|74.13MB|

### Compilation time

`hyperfine --min-runs 15 --prepare "cargo clean && sleep 5"
'RUSTC_WRAPPER="" cargo build --release --example breakout'
'RUSTC_WRAPPER="" cargo build --release --example breakout --features
debug'`

```
breakout' 'RUSTC_WRAPPER="" cargo build --release --example breakout --features debug'
Benchmark 1: RUSTC_WRAPPER="" cargo build --release --example breakout
  Time (mean ± σ):     84.856 s ±  3.565 s    [User: 1093.817 s, System: 32.547 s]
  Range (min … max):   78.038 s … 89.214 s    15 runs

Benchmark 2: RUSTC_WRAPPER="" cargo build --release --example breakout --features debug
  Time (mean ± σ):     92.303 s ±  2.466 s    [User: 1193.443 s, System: 33.803 s]
  Range (min … max):   90.619 s … 99.684 s    15 runs

Summary
  RUSTC_WRAPPER="" cargo build --release --example breakout ran
    1.09 ± 0.05 times faster than RUSTC_WRAPPER="" cargo build --release --example breakout --features debug
```
2025-06-18 20:15:25 +00:00
Piotr Siuszko
2b20e8dae8 Reflect info and stuff 2025-06-11 18:22:07 +02:00
MevLyshkin
648bd3d796
Merge branch 'bevyengine:main' into proper-json-schema 2025-06-11 13:14:39 +02:00
Piotr Siuszko
da2336aa45 JSON Schema reforge 2025-06-11 13:05:27 +02:00
Alice Cecile
6ddd0f16a8
Component lifecycle reorganization and documentation (#19543)
# Objective

I set out with one simple goal: clearly document the differences between
each of the component lifecycle events via module docs.

Unfortunately, no such module existed: the various lifecycle code was
scattered to the wind.
Without a unified module, it's very hard to discover the related types,
and there's nowhere good to put my shiny new documentation.

## Solution

1. Unify the assorted types into a single
`bevy_ecs::component_lifecycle` module.
2. Write docs.
3. Write a migration guide.

## Testing

Thanks CI!

## Follow-up

1. The lifecycle event names are pretty confusing, especially
`OnReplace`. We should consider renaming those. No bikeshedding in my PR
though!
2. Observers need real module docs too :(
3. Any additional functional changes should be done elsewhere; this is a
simple docs and re-org PR.

---------

Co-authored-by: theotherphil <phil.j.ellison@gmail.com>
2025-06-10 00:59:16 +00:00
Piotr Siuszko
15b780d96b Format fix for toml file 2025-06-08 10:45:20 +02:00
Piotr Siuszko
93df12ae70 Format fix for toml file 2025-06-08 10:41:58 +02:00
Piotr Siuszko
10dabadd08 Apply feedback 2025-06-08 10:37:27 +02:00
MevLyshkin
b84e878ab2
Update mod.rs
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
2025-06-07 19:37:53 +02:00
MevLyshkin
671c3b6828
Update mod.rs
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
2025-06-07 19:37:45 +02:00
Piotr Siuszko
07dd944085 Extra test for schema 2025-06-07 13:04:19 +02:00
Piotr Siuszko
42ae72256c Cleanup, init resource 2025-06-07 12:38:21 +02:00
Piotr Siuszko
2f082b63e9 Schema Types Metadata 2025-06-07 12:34:04 +02:00
Eagster
8ad7118443
Only get valid component ids (#19510)
# Objective

- #19504 showed a 11x regression in getting component values for
unregistered components. This pr should fix that and improve others a
little too.
- This is some cleanup work from #18173 .

## Solution

- Whenever we expect a component value to exist, we only care about
fully registered components, not queued to be registered components
since, for the value to exist, it must be registered.
- So we can use the faster `get_valid_*` instead of `get_*` in a lot of
places.
- Also found a bug where `valid_*` did not forward to `get_valid_*`
properly. That's fixed.

## Testing

CI
2025-06-06 20:59:57 +00:00
Carter Anderson
7e9d6d852b
bevyengine.org -> bevy.org (#19503)
We have acquired [bevy.org](https://bevy.org) and the migration has
finished! Meaning we can now update all of the references in this repo.
2025-06-05 23:09:28 +00:00
Benjamin Brienen
20057e5ed7
Make sure that serde_json::Map::into_values exists (#19229)
# Objective

cargo update was required to build because into_values was added in a
patch version

## Solution

Depend on the new patch

## Testing

Builds locally now
2025-05-26 19:38:28 +00:00