bevyengine / bevy_github_ci_template

Apache License 2.0
202 stars 45 forks source link

Show how users can organize their code into plugins #62

Closed janhohenheim closed 3 months ago

janhohenheim commented 3 months ago

This might be a major bikeshed.

Over the years, I've experimented with many styles of organizing Bevy games, and I've landed at the following convention:

// main.rs

mod physics;
mod level;
mod camera;

fn main() {
    App::new().add_plugins((
        DefaultPlugins,
        physics::plugin,
        level::plugin,
        camera::plugin,
}
// camera.rs, level.rs, physics.rs

pub(super) fn plugin(app: &mut App) {
    app.add_systems(...);
}

Any of these plugins can (and probably will) have sub-plugins. I usually have about one plugin per file, which works out pretty well when using this terse plugin-function-syntax above. Please see the conversation here for a writeup I did about why I prefer to organize games this way.

This is the style used in Foxtrot, parts of Blenvy, and the unofficial best practices

This stuff is certainly opinionated, but I think we have to recognize the following things:

This means that we should take care to make the organization presented here conductive to development.