-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistent "render data" for each drawable object in game #969
Comments
A while after writing the original ticket, it's yet not clear for me whether it's a good idea to make a persistent list passable into the graphics renderer directly, with persistent sprite batches (nodes), and so on. But I'm certain in regards of having a separate and persistent "drawable object" for the drawn game elements. Having such data struct would solve two problems:
This list of "drawable objects" could be a simple std::vector, extended as necessary. The game classes would only have a trivial reference to the list's element, preferrably just an index. When the game object is about to be displayed it is assigned a drawable's list element. This vector's elements are not erased, but marked as "unused", so to keep all the indexes intact. The next game object will be assigned a first found free "drawable object". [ Game Object 1 ] [ Game Object 2 ] [ * drawable ID ] -------- -----[ * drawable ID ] | | [ list of drawables ] V V [ ][ ][ ][ ][ ][ ][x ][ ][y ][ ][ ][ ][ ][ ][ ][ ] [ list of drawables ] ===> [ z-sorted list of textures ] ===> [ graphic renderer ] |
Closed in favor of #2628 |
Right now engine gathers drawing lists on each render pass.
See: prepare_room_sprites, add_to_sprite_list, add_thing_to_draw, put_sprite_list_on_screen, and so on.
As you may notice, there are actually two or three separate lists, and data is passed between them before finally sent into GraphicsDriver using virtual DrawSprite call per each item.
This is relatively not slow, but still extra work done each frame, which is often redundant, because it will likely have to draw same sprites again next frame.
The only benefit of this seems to be that it's guaranteed to be always up-to-date if any of the sprite property changes.
Similar thing is done to "sprite batches": they are reinitialized each frame from scratch.
I propose to consider instead have a uniform "render data" struct per each drawable object that would contain:
Such struct may be either a part of game object struct, or a separate data, whichever is more convenient. But it has to be persistent, and put into the persistent render list.
Sprite Batch configuration may also be made persistent. As batches correspond to the render layer, such as room viewport, ui layer, etc, such layers may have linked render data structs, and treated as "drawable objects" as well.
If #967 is implemented, this is going to be not a list, but a tree, or array of arrays. (Actually, it may be array of arrays anyway, because of the sprite batches)
IMPORTANT: as this data is assumed to be persistent, engine has to correctly update it when game object's image changes.
The text was updated successfully, but these errors were encountered: