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

Make bevy::core::update_frame_count public #10107

Closed
mamekoro opened this issue Oct 13, 2023 · 1 comment · Fixed by #10111
Closed

Make bevy::core::update_frame_count public #10107

mamekoro opened this issue Oct 13, 2023 · 1 comment · Fixed by #10111
Labels
C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@mamekoro
Copy link
Contributor

mamekoro commented Oct 13, 2023

What problem does this solve or what need does it fill?

I tried to create a plugin that can capture events and their corresponding frame count to make game sessions possible to reproduce.

I'd like to get the frame count before it is incremented in the Last schedule, but it is impossible since bevy::core::update_frame_count is not pub.
Here is a simplified code.

pub struct RecorderPlugin;

impl Plugin for RecorderPlugin {
    fn build(&self, app: &mut App) {
        if !app.is_plugin_added::<FrameCountPlugin>() {
            app.add_plugins(FrameCountPlugin);
        }

        app
            // Save events before the frame count is incremented.
            .add_systems(Last, commit.before(bevy::core::update_frame_count))
            // External systems push events via the `Recorder` resource.
            .insert_resource(Recorder::new());
    }
}

pub fn commit(mut recorder: ResMut<Recorder>, frame: Res<FrameCount>) {
    let staged = std::mem::take(&mut recorder.staged);
    let current_frame = frame.0;
    save(staged, current_frame);
}

#[derive(Debug, Resource)]
pub struct Recorder<Event> {
    // Events that occurred in this frame
    staged: Vec<Event>,
}

impl<Event> Recorder<Event> {
    // ...
}

What solution would you like?

bevy::core::update_frame_count as a pub system.

What alternative(s) have you considered?

I cloned and patched the bevy_core crate, but it is painful because I have to manually track upstream updates.

@mamekoro mamekoro added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Oct 13, 2023
@alice-i-cecile alice-i-cecile added A-Core C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy and removed C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Oct 13, 2023
@alice-i-cecile
Copy link
Member

No objections to this: feel free to make a PR.

github-merge-queue bot pushed a commit that referenced this issue Oct 16, 2023
# Objective
Closes #10107

The visibility of `bevy::core::update_frame_count` should be `pub` so it
can be used in third-party code like this:

```rust
impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Last, use_frame_count.before(bevy::core::update_frame_count));
    }
}
```

## Solution
Make `bevy::core::update_frame_count` public.

---

## Changelog

### Added
- Documentation for `bevy::core::update_frame_count`

### Changed
- Visibility of `bevy::core::update_frame_count` is now `pub`
ameknite pushed a commit to ameknite/bevy that referenced this issue Nov 6, 2023
…ngine#10111)

# Objective
Closes bevyengine#10107

The visibility of `bevy::core::update_frame_count` should be `pub` so it
can be used in third-party code like this:

```rust
impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Last, use_frame_count.before(bevy::core::update_frame_count));
    }
}
```

## Solution
Make `bevy::core::update_frame_count` public.

---

## Changelog

### Added
- Documentation for `bevy::core::update_frame_count`

### Changed
- Visibility of `bevy::core::update_frame_count` is now `pub`
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue Jan 9, 2024
…ngine#10111)

# Objective
Closes bevyengine#10107

The visibility of `bevy::core::update_frame_count` should be `pub` so it
can be used in third-party code like this:

```rust
impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Last, use_frame_count.before(bevy::core::update_frame_count));
    }
}
```

## Solution
Make `bevy::core::update_frame_count` public.

---

## Changelog

### Added
- Documentation for `bevy::core::update_frame_count`

### Changed
- Visibility of `bevy::core::update_frame_count` is now `pub`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants