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

Improve: speedup viewing the 2D map #7189

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Open

Conversation

vadi2
Copy link
Member

@vadi2 vadi2 commented Mar 17, 2024

Brief overview of PR changes/additions

Speedup viewing/panning the map - depending on the map zoom level, from 15% to 150% speedup improvement

Motivation for adding to Mudlet

A million rooms makes the 2D mapper somewhat slow

Other info (issues closed, discussion etc)

https://discord.com/channels/283581582550237184/1218643821311823983/1218813662534303754

@add-deployment-links
Copy link

add-deployment-links bot commented Mar 17, 2024

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.

@vadi2 vadi2 marked this pull request as ready for review March 29, 2024 13:48
@vadi2 vadi2 requested a review from a team as a code owner March 29, 2024 13:48
@vadi2 vadi2 requested review from a team as code owners March 29, 2024 13:48
@vadi2 vadi2 marked this pull request as draft March 29, 2024 13:54
src/T2DMap.cpp Show resolved Hide resolved
src/T2DMap.cpp Show resolved Hide resolved
return i.value();
}
return nullptr;
return rooms.value(id, nullptr);
Copy link
Member Author

Choose a reason for hiding this comment

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

Qt's own implementation was quicker.

@vadi2 vadi2 requested a review from SlySven March 29, 2024 14:06
@vadi2 vadi2 marked this pull request as ready for review March 29, 2024 14:07
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.

looks good to me and functional testing bears out

src/CMakeLists.txt Outdated Show resolved Hide resolved
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.

I haven't finished reviewing this - I'm just going out and will be changing PCs...

Comment on lines 692 to 706
if (shouldDrawBorder && mRoomWidth >= 12) {
roomPen.setColor(mpHost->mRoomBorderColor);
pen.setColor(mpHost->mRoomBorderColor);
} else if (shouldDrawBorder) {
auto fadingColor = QColor(mpHost->mRoomBorderColor);
fadingColor.setAlpha(255 * (mRoomWidth / 12));
roomPen.setColor(fadingColor);
}

if (isRoomSelected) {
pen.setColor(fadingColor);
} else if (roomSelected) {
QLinearGradient selectionBg(roomRectangle.topLeft(), roomRectangle.bottomRight());
selectionBg.setColorAt(0.2, roomColor);
selectionBg.setColorAt(1, Qt::blue);
roomPen.setColor(QColor(255, 50, 50));
pen.setColor(QColor(255, 50, 50));
painter.setBrush(selectionBg);
} else {
pen.setColor(Qt::transparent);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure the logic has stayed the same here - it looks as though you are combining the boarder drawing with the room selection drawing - and I'm not entirely sure that is the case. OTOH I didn't do the room borders so I might be missing something...

😕

src/T2DMap.cpp Show resolved Hide resolved
src/T2DMap.cpp Show resolved Hide resolved
return i.value();
}
return nullptr;
return rooms.value(id, nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

The second argument is unneeded in this usage - https://doc.qt.io/qt-5/qhash.html#value :

Suggested change
return rooms.value(id, nullptr);
return rooms.value(id);

Copy link
Member Author

Choose a reason for hiding this comment

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

I've seen that link and I am unsure why you think this. The default is not a null pointer but a default-constructed value.

Copy link
Member

@SlySven SlySven Apr 6, 2024

Choose a reason for hiding this comment

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

A default constructed value in this case is a nullptr! Remember that the (QHash<K,V>) rooms has a <int, TRoom*> type...

Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
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.

Okay, I've looked through the code but I haven't tested it yet - I want to be sure the room drawing code refactoring produces the same output (uses the right pen for each thing) - but I'll need to get back onto my main PC to check it later on (I'm out of home at the moment).

@@ -544,7 +544,7 @@ target_link_libraries(
ZIP::ZIP
ZLIB::ZLIB
# PLACEMARKER: sample benchmarking code
# nanobench
# nanobench
Copy link
Member

Choose a reason for hiding this comment

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

Dammit! The spacing looks to have been off in my suggestion...

Comment on lines -586 to -591
// This has been refactored to a separate function out of the paintEven() code
// because we need to use it in two places - one for every room that is not the
// player's room and then, AFTER all those have been drawn, once for the
// player's room if it is visible. This is so it is drawn LAST (and any effects,
// or extra markings for it do not get overwritten by the drawing of the other
// rooms)...
Copy link
Member

Choose a reason for hiding this comment

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

@vadi2 You think this is unhelpful then?

@@ -254,12 +254,12 @@ public slots:
std::pair<int, int> getMousePosition();
bool checkButtonIsForGivenDirection(const QPushButton*, const QString&, const int&);
bool sizeFontToFitTextInRect(QFont&, const QRectF&, const QString&, const quint8 percentageMargin = 10, const qreal minFontSize = 7.0);
void drawRoom(QPainter&, QFont&, QFont&, QPen&, TRoom*, const bool isGridMode, const bool areRoomIdsLegible, const bool showRoomNames, const int, const float, const float, const QMap<int, QPointF>&);
void drawRoom(QPainter&, QFont&, QFont&, QPen&, QPen&, QPen&, QBrush&, QBrush&, TRoom*, const bool isGridMode, const bool areRoomIdsLegible, const bool showRoomNames, const int, const float, const float, const QMap<int, QPointF>&);
Copy link
Member

Choose a reason for hiding this comment

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

💡 Can you nano bench this to see if an inline (effectively cutting out one method call in the room interation) improves things at all?

void paintMapInfo(const QElapsedTimer& renderTimer, QPainter& painter, const int displayAreaId, QColor& infoColor);
int paintMapInfoContributor(QPainter&, int xOffset, int yOffset, const MapInfoProperties& properties);
void paintRoomExits(QPainter&, QPen&, QList<int>& exitList, QList<int>& oneWayExits, const TArea*, int, float, QMap<int, QPointF>&);
void paintRoomExits(QPainter&, QPen&, QList<int>& exitList, QList<int>& oneWayExits, const TArea*, int, float, QMap<int, QPointF>&) const;
Copy link
Member

Choose a reason for hiding this comment

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

💡 Like drawRoom(...) (and drawDoor(...) this might produce an improvement if it were inlined - if the compiler doesn't anyhow - but it might need testing to confim.

@SlySven
Copy link
Member

SlySven commented Apr 7, 2024

Um, the refactoring has messed up some things - these are some screenshots at maximum size (zoomed in as much as possible) on a room with two-way exits north and south, a two-way east exit with an open door, a west stub exit, an up exit with an "open" door and a down exit with a "closed" door and an in stub exit with a "locked" door:

Original plain room:
original_room

After this PR plain room:
Speed_up_panning_room

So it looks as though the "oversized" black (IIRC it'll be white on a dark room colour) background under the door line is being missed off of the first door being drawn (the order of drawing is up, down, in and then out) - and it starts to be done at line 914 in T2DMap.cpp now.

Original selected room (no boarders)
original_room_selected

After this PR selected room (no boarders):
Speed_up_panning_room_selected

Notice how the oversized line under the up exit marking triangle is now in the "selected" orange colour instead of being black (or white) here.

Original room (with borders):
original_room_with_borders

After this PR room (with borders):
Speed_up_panning_room_with_borders

Same problem - and it'll be probably fixed by the same change!

Original room selected (with borders):
original_room_with_boarders_and_selected

After this PR room selected (with borders):
Speed_up_panning_room_with_borders_and_selected

Not only is the boarder not in the orange "selected" colour, the gradient on the room colour has gone!

Original room with highlight (with borders):
original_room_with_borders_and_highlighted

After this PR room with highlight (with borders):
Speed_up_panning_room_with_borders_and_highlighted

There is a circular border on the highlight now - there should not be!

Original rooms showing room numbers:
original_room_room_number

After this PR rooms showing room numbers:
Speed_up_panning_room_number

It looks as though the (contrasting black or white depending on room colour) colour for the room number is no longer being used.

I did not spot any addition discrepancies with the drawing of the room symbol
Original showing room symbol AB:
original_room_symbol

After this PR showing room symbol AB:
Speed_up_panning_room_symbol

@SlySven
Copy link
Member

SlySven commented Apr 7, 2024

(QPen) roomBorderPen is defined and passed to T2DMap::drawRoom(...) but is not used also const int borderWidth is calculated therein but is not currently being used (it is also calculated - and used - in the main T2DMap::paintEvent(...)).

BTW IMHO It is not necessarily a good idea to use the same variable names inside a method as the values that passed in from the caller - although in this case it made it easy to tell this one is not used (which is probably a problem) and the Qt "refactor" to function "helper" does it like that - it makes it harder to tell that a variable is not a member if those are NOT being marked as we have been, but not invariably, in some way.

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.

None yet

3 participants