Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upWrite a "Guide for writing idiomatic Piston code" #1048
Comments
bvssvni
added
the
discussion
label
Mar 21, 2016
This comment has been minimized.
This comment has been minimized.
robojeb
commented
Mar 21, 2016
|
Speaking as the person who made that post, thank you. Even looking at this I notice some differences between what I am doing in my code and what appears to be idiomatic for Piston2D. That said I love piston's modularity and if I can I would love to help build such a document. |
This comment has been minimized.
This comment has been minimized.
robojeb
commented
Mar 21, 2016
|
#1013 Is along the same vein as this. But this seems more targeted than just "Improve all the docs" |
This comment has been minimized.
This comment has been minimized.
|
I've started sprinkling bits and pieces of an "Idiomatic Piston" guide throughout the docs I'm writing (see #1068, #1069, and probably more to come as I continue through the code). I'll keep these things in mind while I'm writing. I definitely agree with robojeb's point in that reddit post, where the connection between the name of the crate and the name of the modules it provides are too different. I think we should make an effort to make scopes more explicit. Crates should have a single scope they provide that contain everything that the user needs, and the name of that scope should be very similar to the name of the crate. piston_window should give the user things inside of piston_window::, piston_2d should give things inside of piston_2d::, etc. The user will have to add in one or two more use statements, and everything becomes sooooo much more clear. |
bvssvni commentedMar 21, 2016
See https://www.reddit.com/r/rust_gamedev/comments/4b8s9h/i_love_the_idea_of_piston_but_and_some_questions/
People have a hard time making the transition from writing application code to generic code. This requires knowledge about how to structure the code, which generic parameters to use, and which library to depend on.
The amount of confusion increases because in an application, by depending on generic libraries, you need the backends, and maybe a convenience wrapper like piston_window on top. In generic code this is pretty much the other way around, with a library only depending on a few others. There is a large conceptual gap from how a new user experience doing a few smaller projects to the attempt of extending the ecosystem.
Some points I noticed people are often confused about:
The guide should explain in details, but in a simple way, the following stuff:
Event handling
event<E: GenericEvent>(e: &E)2D Graphics
render<G: Graphics>(c: &Context, g: &mut G)T: ImageSizefor texturesTexture creation
T: Rgba8Texture<F>whereFis the factoryWindow
W: Windowfor simple stuffW: AdvancedWindowfor advanced stuffWhat is all the "cruft"?
Piston uses backend agnostic design to remove the dependency on OS platform or API where it is expected that 90% or more of the total amount of code is reusable. This requires backend libraries that glues together the generic abstraction with the API specific code. On top of that, since several backends often go together to make an application, you might need a convenience wrapper like piston_window.
The result is that an application requires extra libraries just to work, and this makes the dependency graph larger than a platform specific game engine.
On the upside:
These benefits are more enough to pay for the extra dependencies, and we develop tools to help getting this right. However, in periods of design changes it can be quite difficult to keep up, so we try to avoid breaking existing code. If your project works, then that set of dependency versions should work in the future too.