sf::Sprite as temporary view over geometry + texture#3080
sf::Sprite as temporary view over geometry + texture#3080vittorioromeo wants to merge 6 commits intoSFML:masterfrom
sf::Sprite as temporary view over geometry + texture#3080Conversation
|
Maybe I misunderstand something, but with this design, wouldn't users be tempted to store We can of course discourage/document that, but using the same name would likely be irritating. Also, people may wonder why this is a class in the first place (as opposed to e.g. a function taking 2 parameters) 🤔 In general, I feel the current |
This design encourages the creation of struct TotallyInnocent
{
sf::SpriteGeometry g;
sf::Texture t;
sf::Sprite s;
TotallyInnocent(sf::SpriteGeometry&& xg, sf::Texture&& xt)
: g{std::move(xg)}, t{std::move(xt)}, s{g, t}
{
}
void draw(sf::RenderTarget& rt)
{
rt.draw(s); // DOES NOT COMPILE
}
};It is true that the user can circumvent the compile-time error by using
I agree with you that a function would be the best choice here. In fact, I think that Unfortunately, that's pretty much what I proposed in #3072, but pretty much everyone on GitHub hated it. (People on Twitter seemed to like the change though, so I'm at least a little bit vindicated...)
I don't disagree with you. What I genuinely believe is that a small and reasonable impact on ergonomics is very much worth it to prevent subtle lifetime issue scenarios.
I have considered all of these. I'm not sure what you exactly mean with "validity checks", but it is generally not possible to check if an object has changed address if I just have a raw pointer. A centralized texture map or the use of handles instead of pointers would mean that now SFML imposes a resource management strategy on the user. I really like the fact that SFML gives the user the freedom to manage their own resources the way they like, and I think it's a great design choice that I'd like to keep. Finally, having debug-only checks was one of my initial ideas. It would solve common lifetime bugs not only for sprites, but also for text, sounds, music, shapes and so on. I posted my experimental branch here #2385 (comment) and I remember discussing it on GitHub, but again no one really liked it. I also want to reiterate that solving the lifetime issue is not the only problem I'm trying to solve with the new proposed |
|
No consensus. |
(Based on #3067.)
Alternative design to #3072 that:
sf::Spriteas a "drawable texture"The new design is as follows:
sf::SpriteGeometryhas been extracted fromsf::Spritesf::SpriteGeometrycalculates and owns the vertices required to draw a textured quadsf::Spriteis now a lightweight view over the combination of asf::SpriteGeometryand asf::Texturesf::Spriteis still drawable, but not transformablesf::Spritecan be drawn on asf::RenderTarget, preventing lifetime bugsHere is the simplest example of using this new API:
sf::SpriteGeometryis safe to be precalculated, stored in classes, copied, and moved around. This cleanly solves the lifetime issues encountered in #3062, in fact this PR restores part of the original design where the sprite geometry is a data member of the shader effects.If you feel like the new syntax is too verbose, there is a lot of room to add "convenience" functions, e.g.,
This API is also very suitable for a future batching extension: