Skip to content
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

Undo in the editor can unintentionally revert tweaks to part modules #172

Closed
JonnyOThan opened this issue Dec 14, 2023 · 7 comments
Closed
Labels
kspQoL Quality of life modification
Milestone

Comments

@JonnyOThan
Copy link
Contributor

Repro steps:

  1. Start a new craft in the editor
  2. Place a fuel tank
  3. Change the fuel level in the tank
  4. Attach another part to the tank
  5. hit Ctrl-Z to undo

In addition to the second part being deleted, the fuel level in the first tank will be reverted to the full level. This applies to all tweaks to part modules and resources. It seems like maybe the undo state is captured right after a part is placed (i.e. after step 2 above) instead of just before the second part is placed.

@JonnyOThan JonnyOThan changed the title Undo in the editor can revert tweaks to part modules Undo in the editor can unintentionally revert tweaks to part modules Dec 14, 2023
@gotmachine
Copy link
Contributor

Yeah that's something I noticed.
I think there is a usability / performance rationale :

  • The amount of captured states is limited. If every small tweak was captured, you would often end up hitting undo dozens of times without getting back to significant changes, or even getting to the bottom of the captured undo states without being able to revert as far as needed.
  • Saving the craft induce perceivable stutter with large crafts, this would make interacting with the PAW quite annoying...
  • This is compounded by the fact that it's difficult to capture tweaks in a smart way. Most controls don't really have a "on exit" event meaning it might be necessary to capture every value change (especially bad for sliders like resources), in any case this would need to be implemented for every single PAW control, ensuring the state is captured after all callbacks are called. It's also fundamentally not possible to reliably know if tweaking something is inducing a persisted change or not, although one could argue that the vast majority of editor controls are inducing a persisted change.

@gotmachine gotmachine added the kspQoL Quality of life modification label Dec 14, 2023
@JonnyOThan
Copy link
Contributor Author

Oh absolutely; I don't think every tweak should be saved. But I think adding a save state before attaching a new part (and possibly other actions) would solve the problem. Then undoing the attach won't also undo all the tweaks, and then the next undo will undo all the tweaks since the last state. Or the state that gets saved before attaching could replace the previous one.

@gotmachine
Copy link
Contributor

Overriding the last state before attaching feels like a good solution that wouldn't change the current behavior, every ctrl-z would still result in the last attach action being undone. The main drawback would be that this would double the hiccup lag on attaching, as 2 state save (before and after attaching) are now performed instead of one. Not sure how impactfull this would be in practice.

@JonnyOThan
Copy link
Contributor Author

Right - I also wonder if it would be feasible to then remove the save state from after the attach. We'd probably need to go through and adjust other save state behaviors though.

@gotmachine
Copy link
Contributor

gotmachine commented Jan 6, 2024

Gave a look at this, and TBH, it's a bit of a mess.

I initially tried what we were talking about, but that mean a lot of additional captures and I don't like that.

Then I tried to move around when undo states are captured, as the whole thing is kinda implemented backwards...
Instead of capturing the state before events like picking or attaching a part, it capture the state after, and then doesn't restore the last captured state, but the n-1 state. I guess the logic is to have the "redo" state on hand, but that would be better achieved by simply saving the current state before undoing...

Edit : did a bit more fiddling around, and from the perspective of the undo/redo system, inverting the logic actually would work very well. That is, until I realized that the last serialized ship state created by the undo/redo system is what is used to check the available seats for the editor crew assignment. Yay spaghetti mess.

I might have exhausted my will to work on this...

gotmachine added a commit that referenced this issue Jan 6, 2024
…ork because of VesselCrewManifest side effects

See #172
@JonnyOThan JonnyOThan added this to the 1.34 milestone Jan 27, 2024
@JonnyOThan
Copy link
Contributor Author

JonnyOThan commented Jan 29, 2024

@gotmachine I see you made another commit that addresses the crew manifest issue - is this change ready to go? Perhaps disabled by default?

Edit: Oh I see the PR mentions that change

JonnyOThan added a commit that referenced this issue Jan 29, 2024
* BetterEditorUndoRedo : Exploratory fix for undo/redo state, doesn't work because of VesselCrewManifest side effects
See #172

* BetterEditorUndoRedo : functional, obvious issues fixed, still likely to cause side effects.

* disable BetterEditorUndoRedo by default

---------

Co-authored-by: JonnyOThan <jonnyothan@gmail.com>
@gotmachine
Copy link
Contributor

From my perspective that patch is production ready, and unless I made a mistake somewhere, it shouldn't cause issues.
But as usual, the only way to know for sure is to release it into the wild.

JonnyOThan added a commit that referenced this issue Jan 30, 2024
* New KSP QoL/performance patch : [**LowerMinPhysicsDTPerFrame**](#175) : Allow a min value of 0.02 instead of 0.03 for the "Max Physics Delta-Time Per Frame" main menu setting. This was already possible by manually editing the `settings.cfg` file, but changes would revert when going into the settings screen.

* Add tooltip describing the "Max Physics Delta-Time Per Frame" main menu setting

* merging master to dev (#181)

* zh-cn localization for ManufacturerFixes.cfg (#178)

* Remove ENABLE_PROFILER define that got added recently

---------

Co-authored-by: zhangyuesai <zhangyuesai@live.com>

* Fix #182: ModulePartInventory now accounts for changes to a part's mass or volume
-for example, changing a part's variant (rcs thruster blocks, structural tube) or its resource level could change its mass, but when you store it in inventory the mass would always use the value from the prefab

* oops, revert a couple changes to the csproj that made it into the last commit by accident

* Fix #185: calculate the correct mass for parts when picking them up off the ground in EVA construction

* Fix #104 : set dead kerbals to missing when loading a game and respawning is enabled

* Standardize spaces for indent in .editorconfig and add it to the SLN
(note personally I'd prefer tabs for indents, but all the existing code in here that didn't come from me uses spaces and consistency is more important)

* Change tabs -> spaces in the few files that used it
Whitespace-only change.
(note most of these were originally authored by me, but the project as a whole uses spaces pretty consistently)

* Fix #180: add ZeroCostTechNode patch

* Better editor undo redo (#176)

* BetterEditorUndoRedo : Exploratory fix for undo/redo state, doesn't work because of VesselCrewManifest side effects
See #172

* BetterEditorUndoRedo : functional, obvious issues fixed, still likely to cause side effects.

* disable BetterEditorUndoRedo by default

---------

Co-authored-by: JonnyOThan <jonnyothan@gmail.com>

* PAWGroupMemory is no longer per-window, but rather per-group (#186)

* Fix #50: PAWGroupMemory is no longer per-PAW, but stores the expansion state for all windows and is not cleared on scene changes
-possible future work: persist the collapse state to disk

* collapse or expand PAW groups when the PAW is shown

* Fix #179: ModulePartVariants now applies node position changes in all scenes

* enable BetterEditorUndoRedo by default

* Merge master -> dev (#187)

* zh-cn localization for ManufacturerFixes.cfg (#178)

* Remove ENABLE_PROFILER define that got added recently

---------

Co-authored-by: zhangyuesai <zhangyuesai@live.com>

* update readme with the new fixes

---------

Co-authored-by: gotmachine <24925209+gotmachine@users.noreply.github.com>
Co-authored-by: zhangyuesai <zhangyuesai@live.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kspQoL Quality of life modification
Development

No branches or pull requests

2 participants