From e44cc402792d1e2cac15a10f758f34ad3072c4e3 Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Fri, 30 Aug 2024 23:04:41 +0200 Subject: [PATCH] Assume soft reset when getting stream state Because the server always does this before asking us to start a streamed reset, so we now rely on that assumption to avoid rolling back the local fork twice. --- .../libengine/dpengine/canvas_history.c | 22 +++++++------------ .../libengine/dpengine/canvas_history.h | 4 ++-- .../libengine/dpengine/paint_engine.c | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/drawdance/libengine/dpengine/canvas_history.c b/src/drawdance/libengine/dpengine/canvas_history.c index a4983753e1..ecfdd69727 100644 --- a/src/drawdance/libengine/dpengine/canvas_history.c +++ b/src/drawdance/libengine/dpengine/canvas_history.c @@ -896,23 +896,17 @@ void DP_canvas_history_soft_reset(DP_CanvasHistory *ch, DP_DrawContext *dc, } } -DP_CanvasState *DP_canvas_history_stream_start_state_inc(DP_CanvasHistory *ch, - DP_DrawContext *dc) +DP_CanvasState *DP_canvas_history_stream_start_state_inc(DP_CanvasHistory *ch) { DP_ASSERT(ch); - bool have_fork = have_local_fork(ch); - if (have_fork) { - search_and_replay_from(ch, dc, ch->fork.start - ch->offset, false); - } - - DP_CanvasState *cs = DP_canvas_state_incref(ch->current_state); - - if (have_fork) { - finish_replay(ch, replay_fork_dec(ch, DP_canvas_state_incref(cs), dc), - dc); + int used = ch->used; + for (int i = 0; i < used; ++i) { + DP_CanvasState *cs = ch->entries->state; + if (cs) { + return DP_canvas_state_incref(cs); + } } - - return cs; + DP_UNREACHABLE(); } int DP_canvas_history_undo_depth_limit(DP_CanvasHistory *ch) diff --git a/src/drawdance/libengine/dpengine/canvas_history.h b/src/drawdance/libengine/dpengine/canvas_history.h index 26b70e3a54..261a955571 100644 --- a/src/drawdance/libengine/dpengine/canvas_history.h +++ b/src/drawdance/libengine/dpengine/canvas_history.h @@ -113,8 +113,8 @@ void DP_canvas_history_soft_reset(DP_CanvasHistory *ch, DP_DrawContext *dc, unsigned int context_id, DP_CanvasHistorySoftResetFn fn, void *user); -DP_CanvasState *DP_canvas_history_stream_start_state_inc(DP_CanvasHistory *ch, - DP_DrawContext *dc); +// This must have had a soft reset right before it to return the correct state. +DP_CanvasState *DP_canvas_history_stream_start_state_inc(DP_CanvasHistory *ch); int DP_canvas_history_undo_depth_limit(DP_CanvasHistory *ch); diff --git a/src/drawdance/libengine/dpengine/paint_engine.c b/src/drawdance/libengine/dpengine/paint_engine.c index 76ff0e39e5..6cabe1da0f 100644 --- a/src/drawdance/libengine/dpengine/paint_engine.c +++ b/src/drawdance/libengine/dpengine/paint_engine.c @@ -353,7 +353,7 @@ static void handle_internal(DP_PaintEngine *pe, DP_DrawContext *dc, mi, &correlator_length); stream_reset_start_fn( pe->stream_reset.user, - DP_canvas_history_stream_start_state_inc(pe->ch, dc), + DP_canvas_history_stream_start_state_inc(pe->ch), correlator_length, correlator); } else {