Well, anyway I'm going to implement a texture-based animation system. Hence I'll use
sf::Sprite and seperate animation handling from the rendering system.
Assuming, the animation system handles changing frame animation's frames over time, it will set a dirty flag if the frame was changed. Finally, I want to decouple those systems (animation and rendering) so the animation system does not access the render system's component. Hence it does not know whether the render system is using
sf::Sprite or another structure. If even doesn't know whether the render system is using OpenGL directly or not. Hence a dirty flag is necessary to make the render system detect that the animation frame has changed.
Also assuming that a sprite is always using one texture (else it would be a bit more complex, but that's not necessary to explain my idea, anyway) "forever". So updating and drawing (at the rendering system) might be the following (as pseudo-code):
Update: (per given view)
for each visible tile (depending on given view):
for each object at this tile:
if physics component has a set dirty flag:
calculate sprite's rendering position
apply position to sprite
reset dirty flag
if animation component has a set dirty flag:
determine texture rectangle
apply rectangle to sprite
reset dirty flag
Drawing: (per given view)
create vertex array
create array of Sprite pointers
for each visible tile (depending on given view):
add tile's vertices to vertex array
for each object at this tile:
add pointer to the object's sprite to the array
draw vertex array
for each sprite pointer in array:
draw sprite
What do you think about that solution? Might it be worth implementing - or do you see possible issues / things that should be changed? Maybe both loops could be united, so the sprite update is done while collecting all visible sprites.
btw using sprite pointers while drawing might be necessary, because
std::vector cannot contain lreferences.
btw2: both (vertex array and sprite array) might be resized before the loop by heuristical estimations to avoid multiple reallocations. So e.g. the vertex array could be resized to 4*(Number of visible Tiles) (if using
sf::Quads), and the sprite array might be resized to 5*(Number of visible Tiles), assuming a tile is holding not more than 5 objects in most cases.