Skip to content

feat: ✨ Parallelizable Script Systems with Res and Query parameters & Schedule debugging utilities #361

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

Merged
merged 31 commits into from
Mar 12, 2025

Conversation

makspll
Copy link
Owner

@makspll makspll commented Mar 10, 2025

Summary

Major step towards #244

  • Adds a bevy_system_reflection crate to organize all the things that would be nice to upstream to bevy eventually and aren't really core logic
  • Moves ReflectSchedule etc into that crate
  • Adds a few more things to the reflected sets, schedules and systems
  • Adds DynamicSystemParam enum which we use to store config for script systems
  • Adds ScriptSystem which can be converted into a system using the IntoSystem trait via ScriptSystemBuilder
  • The custom script system allows us to use default_system_sets predictably for script systems, which previously all lived under the same SystemTypeSet which didn't let us do ordering between them
  • Adds utilities for script writers for printing dot graphs of system schedules
  • Splits WorldGuard::new into new_exclusive and new_non_exclusive

Example

this allows you to parameterize systems like:

    world.add_system(
        post_update_schedule,
        system_builder("my_parameterised_system", script_id)
            :resource(ResourceTypeA)
            :query(world.query():component(ComponentA):component(ComponentB))
            :resource(ResourceTypeB)
    )

and then have the callback run with those parameters passed in:

function my_parameterised_system(resourceA,query,resourceB)
    print("my_parameterised_system")
    runs[#runs + 1] = "my_non_exclusive_system"

    assert(resourceA ~= nil, "Expected to get resource but got nil")
    assert(query ~= nil, "Expected to get query but got nil")
    assert(resourceB ~= nil, "Expected to get resource but got nil")

    assert(#resourceA.bytes == 6, "Expected 6 bytes, got: " .. #resourceA.bytes)
    assert(resourceB.string == "Initial Value", "Expected 'Initial Value', got: " .. resourceB.string)
    assert(#query == 2, "Expected 3 results, got: " .. #query)
    for i,result in pairs(query) do
        components = result:components()
        assert(#components == 2, "Expected 2 components, got " .. #components)
        local componentA = components[1]
        local componentB = components[2]
        assert(componentA._1 == "Default", "Expected 'Default', got: " .. componentA._1)
        assert(componentB._1 == "Default", "Expected 'Default', got: " .. componentA._1)
    end
end

The system will setup a specially sandboxed world guard for the system which only allows access to those set components and resources, this combined with the archetype component access setup in the new system type, allows us to parallelize against any other bevy system where there are no overlaps in access!.

One can also create exclusive systems via :exclusive allowing a normal uninhibiting world guard

Tests
- [x] ordering between script systems
- [x] exclusive & non exclusive systems
- [x] check these run in parallel as expected
- [x] test scripts can only access resources and queries as expected

@makspll makspll changed the title feat: ✨ Non-Exclusive script systems with configurable Res and Query accesses feat: ✨ Parallelizable & Parametrised Script Systems with Res and Query parameters Mar 11, 2025
@makspll makspll changed the title feat: ✨ Parallelizable & Parametrised Script Systems with Res and Query parameters feat: ✨ Parallelizable Script Systems with Res and Query parameters & Schedule debugging utilities Mar 11, 2025
@makspll makspll force-pushed the feat/script-systems branch from eb644ca to d3dd82b Compare March 11, 2025 22:56
@makspll makspll enabled auto-merge (squash) March 11, 2025 22:56
@makspll makspll mentioned this pull request Mar 11, 2025
8 tasks
@makspll makspll added the needs documentation For features or changes which still need changes in the book label Mar 11, 2025
@makspll makspll force-pushed the feat/script-systems branch from d3dd82b to 7d9df09 Compare March 11, 2025 23:02
@makspll makspll disabled auto-merge March 11, 2025 23:58
@makspll makspll enabled auto-merge (squash) March 12, 2025 00:00
@makspll makspll disabled auto-merge March 12, 2025 08:54
@makspll makspll merged commit 70958b3 into main Mar 12, 2025
4 checks passed
@makspll makspll deleted the feat/script-systems branch March 12, 2025 08:54
This was referenced Mar 12, 2025
@makspll makspll removed the needs documentation For features or changes which still need changes in the book label Mar 15, 2025
makspll added a commit that referenced this pull request Mar 16, 2025
## 🤖 New release

* `bevy_mod_scripting_derive`: 0.9.11 -> 0.10.0
* `bevy_mod_scripting_core`: 0.9.11 -> 0.10.0 (✓ API compatible changes)
* `bevy_mod_scripting_lua`: 0.9.11 -> 0.10.0 (✓ API compatible changes)
* `bevy_mod_scripting_rhai`: 0.9.11 -> 0.10.0 (✓ API compatible changes)
* `bevy_mod_scripting_functions`: 0.9.11 -> 0.10.0 (✓ API compatible
changes)
* `ladfile`: 0.3.1 -> 0.4.0 (⚠ API breaking changes)
* `mdbook_lad_preprocessor`: 0.1.3 -> 0.1.4 (✓ API compatible changes)
* `ladfile_builder`: 0.2.5 -> 0.2.6 (✓ API compatible changes)
* `bevy_mod_scripting`: 0.9.11 -> 0.10.0 (✓ API compatible changes)

### ⚠ `ladfile` breaking changes

```text
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field LadInstance.type_kind in /tmp/.tmpHaT0UL/bevy_mod_scripting/crates/ladfile/src/lib.rs:97

--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/enum_missing.ron

Failed in:
  enum ladfile::LadArgumentKind, previously in file /tmp/.tmpAHPNdG/ladfile/src/lib.rs:171

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/struct_pub_field_missing.ron

Failed in:
  field type_id of struct LadInstance, previously in file /tmp/.tmpAHPNdG/ladfile/src/lib.rs:97
```

<details><summary><i><b>Changelog</b></i></summary><p>

## `bevy_mod_scripting_derive`

<blockquote>

##
[0.10.0](bevy_mod_scripting_derive-v0.9.11...bevy_mod_scripting_derive-v0.10.0)
- 2025-03-16

### Added

- [**breaking**] re-design `GetTypeDependencies` trait & add
`GetTypeDependencies` derive macro
([#369](#369))
</blockquote>

## `bevy_mod_scripting_core`

<blockquote>

##
[0.10.0](bevy_mod_scripting_core-v0.9.11...bevy_mod_scripting_core-v0.10.0)
- 2025-03-16

### Added

- *(ladfile)* improve globals in LAD format
([#372](#372))
- add global `types` cache making `get_type_by_name` redundant
([#370](#370))
- [**breaking**] re-design `GetTypeDependencies` trait & add
`GetTypeDependencies` derive macro
([#369](#369))
- shorten import paths
([#367](#367))
- Add missing `luau` extension, improve extension configuration options
([#366](#366))
- allow lua scripts to insert `ScriptComponent`'s
([#359](#359))
- ✨ Parallelizable Script Systems with `Res` and `Query`
parameters & Schedule debugging utilities
([#361](#361))

### Fixed

- supported extensions not including default extensions [SKIP_CHANGELOG]
([#373](#373))
- unit enum variants other than `Option::None` being converted into
`ScriptValue::Unit`
([#360](#360))

### Other

- [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove
`Sync` bound from Contexts
([#350](#350))
</blockquote>

## `bevy_mod_scripting_lua`

<blockquote>

##
[0.10.0](bevy_mod_scripting_lua-v0.9.11...bevy_mod_scripting_lua-v0.10.0)
- 2025-03-16

### Added

- Add missing `luau` extension, improve extension configuration options
([#366](#366))

### Fixed

- [**breaking**] script contexts being completely overwritten on a
re-load ([#345](#345))

### Other

- [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove
`Sync` bound from Contexts
([#350](#350))
</blockquote>

## `bevy_mod_scripting_rhai`

<blockquote>

##
[0.10.0](bevy_mod_scripting_rhai-v0.9.11...bevy_mod_scripting_rhai-v0.10.0)
- 2025-03-16

### Added

- Add missing `luau` extension, improve extension configuration options
([#366](#366))
- ✨ Parallelizable Script Systems with `Res` and `Query`
parameters & Schedule debugging utilities
([#361](#361))

### Fixed

- rhai reloading behavior regression from #345 [SKIP_CHANGELOG]
([#351](#351))
- [**breaking**] script contexts being completely overwritten on a
re-load ([#345](#345))

### Other

- [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove
`Sync` bound from Contexts
([#350](#350))
</blockquote>

## `bevy_mod_scripting_functions`

<blockquote>

##
[0.10.0](bevy_mod_scripting_functions-v0.9.11...bevy_mod_scripting_functions-v0.10.0)
- 2025-03-16

### Added

- add global `types` cache making `get_type_by_name` redundant
([#370](#370))
- ✨ Parallelizable Script Systems with `Res` and `Query`
parameters & Schedule debugging utilities
([#361](#361))
</blockquote>

## `ladfile`

<blockquote>

##
[0.4.0](v0.3.1-ladfile...v0.4.0-ladfile)
- 2025-03-16

### Added

- *(ladfile)* improve globals in LAD format
([#372](#372))
</blockquote>

## `mdbook_lad_preprocessor`

<blockquote>

##
[0.1.4](v0.1.3-mdbook_lad_preprocessor...v0.1.4-mdbook_lad_preprocessor)
- 2025-03-16

### Added

- *(ladfile)* improve globals in LAD format
([#372](#372))
</blockquote>

## `ladfile_builder`

<blockquote>

##
[0.2.6](v0.2.5-ladfile_builder...v0.2.6-ladfile_builder)
- 2025-03-16

### Added

- *(ladfile)* improve globals in LAD format
([#372](#372))
</blockquote>

## `bevy_mod_scripting`

<blockquote>

##
[0.10.0](v0.9.11...v0.10.0)
- 2025-03-16

### Added

- add global `types` cache making `get_type_by_name` redundant
([#370](#370))
- ✨ Parallelizable Script Systems with `Res` and `Query`
parameters & Schedule debugging utilities
([#361](#361))
- Add missing `luau` extension, improve extension configuration options
([#366](#366))
- *(ladfile)* improve globals in LAD format
([#372](#372))
- [**breaking**] re-design `GetTypeDependencies` trait & add
`GetTypeDependencies` derive macro
([#369](#369))
- shorten import paths
([#367](#367))
- allow lua scripts to insert `ScriptComponent`'s
([#359](#359))

### Fixed

- rhai reloading behavior regression from #345 [SKIP_CHANGELOG]
([#351](#351))
- [**breaking**] script contexts being completely overwritten on a
re-load ([#345](#345))
- supported extensions not including default extensions [SKIP_CHANGELOG]
([#373](#373))
- unit enum variants other than `Option::None` being converted into
`ScriptValue::Unit`
([#360](#360))

### Other

- [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove
`Sync` bound from Contexts
([#350](#350))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Maksymilian Mozolewski <[email protected]>
This was referenced Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant