Pong Example code distribution analysis

(Joël Lupien) #1

Pong bloat analysis/rant

I’m in a bad mood today, so I figured it would be the perfect time to complain about everything I hate in amethyst.
To do this, I decided to go through the pong example and point out everything that I dislike and that I think should be removed or made differently.

audio.rs

music struct
load_audio_track
should use world.exec https://github.com/amethyst/amethyst/blob/64ed8ab283345dc0f0dbc484fafca167438af564/examples/pong/audio.rs#L27
too complex for what it is https://github.com/amethyst/amethyst/blob/64ed8ab283345dc0f0dbc484fafca167438af564/examples/pong/audio.rs#L33

bundle.rs

ok

main.rs

too many imports
logger not auto started. should autostart and then allow configuration
should add macro for gamedatabuilder declaration
DjSystem
.with_frame_limit should have default methods (ie new_sleep_144)
components and resources should not be in the main file
#derive(Component, new, Serialize, Deserialize, Clone, PartialEq, Default, Debug)
no default render graph
render graph in main
render graph exposes a TON of low level details that are really not needed at all for the pong example

pong.rs

too many imports
Option<Handle> pattern is annoying
StateData '_ spam
load_sprite_sheet should have a method in amethyst_utils for it
need macro to create entities (ie cr_entity!(world; sprite_render.clone(); Paddle{…}; right_transform))
ui transform is bloated

display.ron

use implicit_some and dimensions: (500, 500)

input.ron

ok

input_controller.ron

ok

bounce.rs

imports
should add macro for generating SystemData, sys_data!(WS Ball; RS Paddle; RS Transform; R AssetStorage; RE Sounds; OR Output)
this macro should also generate the run method signature using standardized names (ie https://github.com/amethyst/amethyst/blob/64ed8ab283345dc0f0dbc484fafca167438af564/examples/pong/systems/bounce.rs#L29)
point_in_rect should be in the engine, as a utils to the collider crate (once implemented)

move_balls.rs

ok

paddle.rs

imports

winner.rs

imports
minor code duplication https://github.com/amethyst/amethyst/blob/64ed8ab283345dc0f0dbc484fafca167438af564/examples/pong/systems/winner.rs#L45
audio handled at the same place collisions and ui are handled, these should be handled in 2 separate systems that are triggered by an event https://github.com/amethyst/amethyst/blob/64ed8ab283345dc0f0dbc484fafca167438af564/examples/pong/systems/winner.rs#L77
resource declared in system file https://github.com/amethyst/amethyst/blob/64ed8ab283345dc0f0dbc484fafca167438af564/examples/pong/systems/winner.rs#L88

general

ron should have implicit_some enabled by default
locale not used, we should update and start making nice abstractions for it

summary

Pong is 840 lines long
100 of them are from the render graph (possible cut of 95)
40 are from config files
62 are from imports (possible cut of 30)
53 are from impl System SystemData and run(…) declarations (possible cut of 30)
42 are from building the system graph (possible cut of 10)
14 are from consts
7 lines contain the word Float
95 lines are comments

4 Likes
(Lokathor) #2

Coding in anger is always the best use of time for something that expects to be used by others.

And that sentence sounds sarcastic, but I mean it for real.