Skip to content

Comments

Real-time/undo fix#796

Closed
BentSm wants to merge 2 commits intoincrepare:masterfrom
BentSm:realtime-undo-fix
Closed

Real-time/undo fix#796
BentSm wants to merge 2 commits intoincrepare:masterfrom
BentSm:realtime-undo-fix

Conversation

@BentSm
Copy link

@BentSm BentSm commented Jan 23, 2022

The 'diff' undo mechanism breaks down when real-time ticks are used, since they change level state without generating any undo data for those changes; thus, the diffs get applied to the wrong state. (Diffs are applied to the current state. In the case that the state had changed due to real-time ticks, the current state would not be the same as the state with respect to which the diff was created.)

This corrects that issue by restoring diff-type undos to full undos as needed to prevent such inconsistencies, and adds a test for such issues.

An example where the issue occurs:

title Undo and Real-time
realtime_interval 0.25

OBJECTS

Background .
Black

Player @
Blue

Thing *
Yellow

LEGEND

SOUNDS

COLLISIONLAYERS

Background
Thing
Player

RULES   

[ Thing ] -> [ right Thing ]   

WINCONDITIONS

LEVELS

message Walk around a bit, then undo several times (usually, three is enough).

*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.............@.......................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................
*.....................................................

Ben Small added 2 commits January 23, 2022 14:38
Added diff-to-full undo state conversion on real-time ticks.

(Real-time ticks do not generate new undo states.  This means that undoing a 'diff'-ed state could produce incorrect results if real-time ticks had happened in the intervening interval.  Specifically, diffs are applied to the current state.  In the case that the state had changed due to real-time ticks, the current state would not be the same as the state with respect to which the diff was created.  Applying the diff in such a case could produce an incorrect result.

This commit fixes the issue by converting a diff-type undo on the top of the undo stack to a full undo (using the correct reference state) when handling a real-time tick.)
@increpare
Copy link
Owner

increpare commented Jan 24, 2022

aha, great catch :) I'll review it asap

Thanks!

@increpare increpare closed this in 73f2c4e Jan 27, 2022
@increpare
Copy link
Owner

increpare commented Jan 27, 2022

I accepted this by manually pasting the code and doing some minor code-rearranging. I had completely forgotten that the undo-buffer does all its diffing backwards and was briefly highly confused trying to read the code 🙃 Because of how I did it your change isn't nicely represented as a merge in the diff graph between repos, but I figure it's more important to get the fix in than to figure out how the best flow for github (even if that acknowledges your contribution more actively/neatly).

Thank you for the fix! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants