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
base: development
Are you sure you want to change the base?
Conversation
Delete extra setPen calls
We weren't actually using them for a gain
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
return i.value(); | ||
} | ||
return nullptr; | ||
return rooms.value(id, nullptr); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
There was a problem hiding this 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...
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); | ||
} |
There was a problem hiding this comment.
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...
😕
return i.value(); | ||
} | ||
return nullptr; | ||
return rooms.value(id, nullptr); |
There was a problem hiding this comment.
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 :
return rooms.value(id, nullptr); | |
return rooms.value(id); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
There was a problem hiding this 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 |
There was a problem hiding this comment.
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...
// 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)... |
There was a problem hiding this comment.
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>&); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 inline
d - if the compiler doesn't anyhow - but it might need testing to confim.
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. |
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