#New to bevy/ ecs, made SVG drawing application

17 messages · Page 1 of 1 (latest)

cobalt briar
#

Ive been interested in game dev for a while and used unity years back, I looked into bevy and wanted to try it out recently so I made this SVG drawing tool if you can call it that, and would love some feedback/ input on how to program correctly with bevy! https://github.com/nolook1/drawsvg

GitHub

SVG drawing test using bevy. Contribute to nolook1/drawsvg development by creating an account on GitHub.

cobalt briar
#

New to bevy/ ecs, made SVG drawing application

lavish panther
#

I'm newish to bevy, but I noticed this:

fn camera_movement_system(
    keyboard_input: Res<Input<KeyCode>>,
    mut query: Query<(&Camera, &mut Transform)>,
    time: Res<Time>,
    drawingconfig: Res<DrawingConfig>,
) {
    for (_camera, mut transform) in query.iter_mut() {
    ...
}

If you have a query where you want entities that have a component type on them, but you don't need any data in that component, use With<T>. Like so:

fn camera_movement_system(
    keyboard_input: Res<Input<KeyCode>>,
    mut query: Query<&mut Transform, With<Camera>>,
    time: Res<Time>,
    drawingconfig: Res<DrawingConfig>,
) {
    for mut transform in query.iter_mut() {
    ...
}

See this for more details:
https://bevy-cheatbook.github.io/programming/queries.html#query-filters

vital veldt
cobalt briar
#

thank you so much ill look into it, i appreciate it

vital veldt
#

This is all minor feedback btw, just next steps to work on when you're getting started 🙂

cobalt briar
#

also thank you @lavish panther i didnt see your message until now

#

for sure, always looking for improvements no matter how small tbf

vital veldt
#

This is more opinionated and might only apply in larger projects, but I think separate code/systems should always be put into plugins, especially when they are already in separate files.

E.g. fps_counter.rs should export a plugin. If someone opens fps_counter.rs, they'll see a plugin at the top of the file, and by looking at the plugin it tells them everything it is doing and when it runs.

A bonus of this is you can copy-past that file into another project, or even publish it as a crate.

cobalt briar
cobalt briar
vital veldt
# cobalt briar for explicit error handling im not sure what needs it compared to what doesnt ne...

I use something like this rule: The only time you should ignore errors is when it shouldn't ever happen inside your control.

E.g. this is fine: Unwrapping a Query<&Window> because there should always be a Window in your bevy app

But, when you're using something external like the file system, or a third party crate that returns an error, then you should make the error behavior explicit somehow. Even if you manually panic afterwards, or just document the behavior: /// Panics if anything goes wrong

Again, doesn't matter in your example, but I'd test it out early just so you get a "feel" for error handling 🙂

cobalt briar
#

awesome, thanks for explaining it, that makes sense as well. Ive gotten some panic situations with the unwrap but honestly rusts error/ panic debug in the console got me through them, definitly will look into that more

vital veldt
# cobalt briar havent looked into how plugins are made but that makes sense

Plugins are really easy. Add the following to fps_counter.rs:

pub(super) struct FpsCounterPlugin;

impl Plugin for FpsCounterPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins(FrameTimeDiagnosticsPlugin::default())
            .add_systems(Startup, fps_setup)
            .add_systems(Update, (fps_text_update, fps_counter_display));
    }
}

In main.rs:

fn main() {
    App::new()
        .insert_resource(Msaa::Sample4)
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                title: "SVGdraw".to_string(),
                present_mode: PresentMode::AutoVsync,
                ..Default::default()
            }),
            ..Default::default()
        }))
        .add_plugins((bevy_svg::prelude::SvgPlugin, ShapePlugin, FpsCounterPlugin))
        .add_systems(Startup, (draw_setup, main_setup))
        .add_systems(Update, toggle_vsync)
        .add_systems(FixedUpdate, (drawing, draw_lines, camera_movement_system))
        .run();
}

Now, all the FPS stuff is wrapped up in its own plugin.

cobalt briar
#

that is simple damn

#

will do!