17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust
MIT License
909 stars 63 forks source link

ECS example with Legion #268

Closed rghartmann closed 3 years ago

rghartmann commented 3 years ago

Things to note:

In order for this to compile and work, you'll need to add Legion to Cargo.toml:

legion = { version = "0.4.0", optional = true }

I am new to Rust and thus not very familiar with Cargo yet, so I'm not sure how it handles dependencies for examples. It'd be nicer if the dependency could only be added to the scope of this example, instead of being available to anyone using the library; Even as I made it optional, it could imply a broader support of Tetra for Legion, which is obviously not the intention here.

I based myself off bunnymark.rs, making small changes along the way. I never intended it to be a full conversion of that example to use ECS/Legion. However, if you feel that it's confusing as it is, I can always make it match, or contribute a different ECS example altogether. I'm happy either way!

17cupsofcoffee commented 3 years ago

🎉 🎉 🎉

This looks good at first glance, and the way you've structured the code is in line with how people have used ECS with Tetra in the past (i.e. systems for update, simple queries for draw). Will give it a proper try locally after work!

With regards to the dependency, you can exclude Legion from the main build by putting it in the [dev-dependencies] section of Cargo.toml - that way it will only get compiled for examples/tests. I think there are ways you could make it specifically only get compiled for this single example, but it's probably not worth the trouble unless Legion really slows the builds down. Will check the timings once I get the build working 😄

17cupsofcoffee commented 3 years ago

I made a few code style tweaks and tried to bring the behaviour more in line with the existing Bunnymark example 🙂 Debating maybe moving the spawning into a system too, to give an example of how to handle input, but might save that for a later change.

rghartmann commented 3 years ago

Looks great! And agreed, I can follow up with another PR to have the input/spawning handled by a system.

17cupsofcoffee commented 3 years ago

Let's start with this then 🚀

17cupsofcoffee commented 3 years ago

Thank you for the PR 😄