@@ -253,14 +253,14 @@ void MapCanvas::initializeGL()
253253
254254 setConfig ().canvas .showUnsavedChanges .registerChangeCallback (m_lifetime, [this ]() {
255255 if (getConfig ().canvas .showUnsavedChanges .get () && m_diff.highlight .has_value ()
256- && m_diff.highlight ->modified .empty ()) {
256+ && m_diff.highlight ->highlights .empty ()) {
257257 this ->forceUpdateMeshes ();
258258 }
259259 });
260260
261261 setConfig ().canvas .showMissingMapId .registerChangeCallback (m_lifetime, [this ]() {
262262 if (getConfig ().canvas .showMissingMapId .get () && m_diff.highlight .has_value ()
263- && m_diff.highlight ->needsUpdate .empty ()) {
263+ && m_diff.highlight ->highlights .empty ()) {
264264 this ->forceUpdateMeshes ();
265265 }
266266 });
@@ -465,7 +465,7 @@ void MapCanvas::setViewportAndMvp(int width, int height)
465465
466466void MapCanvas::resizeGL (int width, int height)
467467{
468- if (m_textures.room_modified == nullptr ) {
468+ if (m_textures.room_highlight == nullptr ) {
469469 // resizeGL called but initializeGL was not called yet
470470 return ;
471471 }
@@ -670,13 +670,20 @@ void MapCanvas::Diff::maybeAsyncUpdate(const Map &saved, const Map ¤t)
670670 return ;
671671 }
672672
673- const bool showNeedsServerId = getConfig ().canvas .showMissingMapId .get ();
674- const bool showChanged = getConfig ().canvas .showUnsavedChanges .get ();
673+ const auto &config = getConfig ();
674+ const auto &canvas = config.canvas ;
675+ const bool showNeedsServerId = canvas.showMissingMapId .get ();
676+ const bool showChanged = canvas.showUnsavedChanges .get ();
677+ const auto colorSettings = config.colorSettings .clone ();
675678
676679 diff.futureHighlight = std::async (
677680 std::launch::async,
678- [saved, current, showNeedsServerId, showChanged]() -> Diff::HighlightDiff {
679- DECL_TIMER (t2, " [async] actuallyPaintGL: highlight differences and needs update" );
681+ [saved, current, showNeedsServerId, showChanged, colorSettings]() -> Diff::HighlightDiff {
682+ DECL_TIMER (t2,
683+ " [async] actuallyPaintGL: highlight changes, temporary, and needs update" );
684+
685+ const auto &colors = deref (colorSettings);
686+
680687 // 3-2
681688 // |/|
682689 // 0-1
@@ -687,56 +694,49 @@ void MapCanvas::Diff::maybeAsyncUpdate(const Map &saved, const Map ¤t)
687694 glm::vec3{0 , 1 , 0 },
688695 };
689696
690- // REVISIT: Just send the position and convert from point to quad in a shader?
691- auto getChanged = [&saved, ¤t, showChanged]() -> Diff::MaybeDataOrMesh {
692- if (!showChanged) {
697+ auto getHighlights = [&saved, ¤t, showChanged, showNeedsServerId, &colors]()
698+ -> Diff::MaybeDataOrMesh {
699+ if (!showChanged && !showNeedsServerId ) {
693700 return Diff::MaybeDataOrMesh{};
694701 }
695- DECL_TIMER (t3, " [async] actuallyPaintGL: compute differences" );
696- TexVertVector changed;
697- auto drawQuad = [&changed](const RawRoom &room) {
702+
703+ DECL_TIMER (t3, " [async] actuallyPaintGL: compute highlights" );
704+ ColoredTexVertVector highlights;
705+ auto drawQuad = [&highlights](const RawRoom &room, const XNamedColor &color) {
698706 const auto &pos = room.getPosition ().to_vec3 ();
699707 for (auto &corner : corners) {
700- changed .emplace_back (corner, pos + corner);
708+ highlights .emplace_back (color. getColor (), corner, pos + corner);
701709 }
702710 };
703711
704- ProgressCounter dummyPc;
705- Map::foreachChangedRoom (dummyPc, saved, current, drawQuad);
706- if (changed.empty ()) {
707- return Diff::MaybeDataOrMesh{};
712+ // Handle rooms needing a server ID or that are temporary
713+ if (showNeedsServerId) {
714+ current.getRooms ().for_each ([&](auto id) {
715+ if (auto h = current.getRoomHandle (id)) {
716+ if (h.isTemporary ()) {
717+ drawQuad (h.getRaw (), colors.HIGHLIGHT_TEMPORARY );
718+ } else if (h.getServerId () == INVALID_SERVER_ROOMID) {
719+ drawQuad (h.getRaw (), colors.HIGHLIGHT_NEEDS_SERVER_ID );
720+ }
721+ }
722+ });
708723 }
709724
710- return Diff::MaybeDataOrMesh{ std::move ( changed)};
711- };
712-
713- auto getNeedsUpdate = [& current, showNeedsServerId]() -> Diff::MaybeDataOrMesh {
714- if (!showNeedsServerId) {
715- return MapCanvas::Diff::MaybeDataOrMesh{} ;
725+ // Handle changed rooms
726+ if (showChanged) {
727+ ProgressCounter dummyPc;
728+ Map::foreachChangedRoom (dummyPc, saved, current, [&]( const RawRoom &room) {
729+ drawQuad (room, colors. HIGHLIGHT_UNSAVED );
730+ }) ;
716731 }
717- DECL_TIMER (t3, " [async] actuallyPaintGL: compute needs update" );
718732
719- TexVertVector needsUpdate;
720- auto drawQuad = [&needsUpdate](const RoomHandle &h) {
721- const auto &pos = h.getPosition ().to_vec3 ();
722- for (auto &corner : corners) {
723- needsUpdate.emplace_back (corner, pos + corner);
724- }
725- };
726- current.getRooms ().for_each ([¤t, &drawQuad](auto id) {
727- if (auto h = current.getRoomHandle (id)) {
728- if (h.getServerId () == INVALID_SERVER_ROOMID) {
729- drawQuad (h);
730- }
731- }
732- });
733- if (needsUpdate.empty ()) {
733+ if (highlights.empty ()) {
734734 return Diff::MaybeDataOrMesh{};
735735 }
736- return Diff::MaybeDataOrMesh{std::move (needsUpdate )};
736+ return Diff::MaybeDataOrMesh{std::move (highlights )};
737737 };
738738
739- return Diff::HighlightDiff{saved, current, getNeedsUpdate (), getChanged ()};
739+ return Diff::HighlightDiff{saved, current, getHighlights ()};
740740 });
741741}
742742
@@ -754,13 +754,8 @@ void MapCanvas::paintDifferences()
754754 auto &highlight = deref (diff.highlight );
755755 auto &gl = getOpenGL ();
756756
757- if (getConfig ().canvas .showMissingMapId .get ()) {
758- if (auto &needsUpdate = highlight.needsUpdate ; !needsUpdate.empty ()) {
759- needsUpdate.render (gl, m_textures.room_needs_update ->getId ());
760- }
761- }
762- if (auto &modified = highlight.modified ; !modified.empty ()) {
763- modified.render (gl, m_textures.room_modified ->getId ());
757+ if (auto &highlights = highlight.highlights ; !highlights.empty ()) {
758+ highlights.render (gl, m_textures.room_highlight ->getId ());
764759 }
765760}
766761
0 commit comments