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

Add: map autosaves #6056

Merged
merged 10 commits into from
Apr 18, 2022
Merged

Add: map autosaves #6056

merged 10 commits into from
Apr 18, 2022

Conversation

vadi2
Copy link
Member

@vadi2 vadi2 commented Apr 10, 2022

Brief overview of PR changes/additions

Add a map autosave feature to prevent large losses of work when Mudlet/computer shut down unexpectedly.

Motivation for adding to Mudlet

Better player experience.

Other info (issues closed, discussion etc)

Closes #2121.

Works just like profile autosave which has been very successful since its introduction - autosaves the map every 2min if any changes have been done to it. Hopefully this won't be an issue for enormous maps - if it is, we'll need to look into making the save process hog the main thread less.

Adding this revealed that the internal mapper API is messy - ideally the 'mDirtyMap' flag should never be set within TLuaInterpreter.cpp!

@vadi2 vadi2 requested review from a team as code owners April 10, 2022 08:42
@add-deployment-links
Copy link

add-deployment-links bot commented Apr 10, 2022

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@mudlet-machine-account mudlet-machine-account added this to the 4.16.0 milestone Apr 10, 2022
src/TRoom.cpp Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Apr 10, 2022

Messages
✔️

PR type: Addition

Generated by 🚫 dangerJS against aeb0079

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Member

@demonnic demonnic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this feature, but we may want to keep an eye out and see if we need to add automatic cleanup to older maps as an option as well, as this could start to get pretty hefty in terms of disk space.

@vadi2
Copy link
Member Author

vadi2 commented Apr 10, 2022

Yep, fair concern - like profile autosaves, I made it write to one file ever only, so old autosaves are automatically replaced. It won't interfere with manual saves either.

@demonnic
Copy link
Member

oh right, derp. I'm gonna have to drink more coffee.

@vadi2
Copy link
Member Author

vadi2 commented Apr 10, 2022

We do still need to add running delete old maps automatically, right now it's manual only... so there's room for improvement 😬

Copy link
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to check having the map being flagged as dirty in the T2DMap mouse event handlers as somewhere in there represents where map label and room movements (at least) are concluded/committed - in further review I think I have seen some of this being done but I have not worked out if every case is being covered.

TBH The fact that various map and not map classes can dip into each others contents directly rather than going through a uniform interface (perhaps the TMap class) does make this harder than it might otherwise be - but then that is why I raised #4569 in the first place.

src/T2DMap.cpp Outdated Show resolved Hide resolved
src/T2DMap.cpp Outdated Show resolved Hide resolved
src/T2DMap.cpp Outdated Show resolved Hide resolved
src/T2DMap.cpp Outdated Show resolved Hide resolved
src/T2DMap.cpp Outdated Show resolved Hide resolved
src/T2DMap.cpp Show resolved Hide resolved
src/TRoom.cpp Show resolved Hide resolved
src/TRoom.cpp Outdated
}
mpRoomDB->mpMap->mUnsavedMap = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be moved up into each of the if () and else if () { code blocks. So setting/removing an exit weight for a non-existent exit does not dirty the map. OTOH the validity for setting an exit weight is not having the given exit being checked here... 😟

@@ -325,8 +325,8 @@ class mudlet : public QMainWindow, public Ui::main_window
const QMap<QByteArray, QString>& getEncodingNamesMap() const { return mEncodingNameMap; }
void refreshTabBar();
void updateDiscordNamedIcon();
// Has to be public as it needs to be called from dlgConnectionProfiles class:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it is helpful to remove this comment - it gives advice about something that might not be obvious. IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick investigation will fix it.

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@@ -495,6 +496,8 @@ Host::Host(int port, const QString& hostname, const QString& login, const QStrin
auto entry = i.next();
profileShortcuts.insert(entry, new QKeySequence(*mudlet::self()->mShortcutsManager->getSequence(entry)));
}

startMapAutosave();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the most appropriate point to initiate autosaving the map?

For a new profile (not a copy of an existing one) there won't necessarily be a map yet and for an existing one IIRC a map may not get loaded until the "Map" toolbar button is clicked for the first time if a mapper is not instantiated by a script/package...

Looking at the calls to new dlgMapper(...) they happen in:

  • TMainConsole::createMapper(...): 2 alternatives one for the Main console and one for when it is in a sub-console)
  • Host::createMapper(...)

Oh! That is messy/confusing - there are MORE calls to TMap::restore(...) than that - ah, that might explain why the map is sometimes loaded multiple times on start-up - something to investigate and fix I suppose.

Also, in some extreme, pathological, cases it can take a long time to load and audit a map on a slow machine with a big map (I was testing something on a Windows machine with a debug build {so automatically slower} with that humongous >2M room map recently and that took nearly an hour to finish the loading!) Might it not be better to make startMapAutosave() idempotent and to call it after each call to TMap::audit()` - so it only starts once a map has been successfully loaded and audited - ah, that won't include the case where the user is starting from scratch.

Okay, how about changing the lines that do mpMap->mUnsavedMap = true to call a method that both sets the flag AND starts the autosave timer if it hasn't been started before?

What about the cases after TMap::mapClear() gets called - should that stop the timer (and also run the timer code) so that the (to be/just) deleted map is saved in the automatic backup until a new map overwrites it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SlySven it's important to focus on keeping things as simple as possible instead of complicated! If you find any practical issues with autosaves, I'm happy to fix them, we can't afford to spend time and energy thinking of theoretical problems and then solving those theoretical problems.

@vadi2 vadi2 merged commit 9d4d316 into development Apr 18, 2022
@vadi2 vadi2 deleted the add-map-autosave branch April 18, 2022 08:38
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.

Feature request: Map autosave
4 participants