bevyengine / bevy_github_ci_template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show how users can organize their code into plugins

janhohenheim opened this issue · comments

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:

  • The template will be organized somehow
  • Users will generate a lot of nested modules while coding a game
  • Users will implicitly accept the organization presented in the template as a good starting point and try to follow it
  • The organization used for the empty template, which will only contain a few modules, will be stretched to serve users that have dozens upon dozens of modules

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