1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Implement animation slice drawing in CanvasItem

* Added a function to ignore subsequent commands if they don't fall within the slice.
* This will be used by the new TileMap to properly provide animated tiles.
This commit is contained in:
reduz
2021-06-17 11:30:20 -03:00
parent 085e1d3c03
commit 94d31ac327
9 changed files with 81 additions and 0 deletions

View File

@@ -464,8 +464,15 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
RID last_texture;
Size2 texpixel_size;
bool skipping = false;
const Item::Command *c = p_item->commands;
while (c) {
if (skipping && c->type != Item::Command::TYPE_ANIMATION_SLICE) {
c = c->next;
continue;
}
push_constant.flags = base_flags | (push_constant.flags & (FLAGS_DEFAULT_NORMAL_MAP_USED | FLAGS_DEFAULT_SPECULAR_MAP_USED)); //reset on each command for sanity, keep canvastexture binding config
switch (c->type) {
@@ -879,6 +886,14 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
}
} break;
case Item::Command::TYPE_ANIMATION_SLICE: {
const Item::CommandAnimationSlice *as = static_cast<const Item::CommandAnimationSlice *>(c);
double current_time = RendererCompositorRD::singleton->get_total_time();
double local_time = Math::fposmod(current_time - as->offset, as->animation_length);
skipping = !(local_time >= as->slice_begin && local_time < as->slice_end);
RenderingServerDefault::redraw_request(); // animation visible means redraw request
} break;
}
c = c->next;