MMapper icon indicating copy to clipboard operation
MMapper copied to clipboard

replace thick lines with quads

Open nschimme opened this issue 1 month ago • 2 comments

Summary by Sourcery

Replace line-based rendering of thick connection, infomark, and character path graphics with quad-based rendering for more consistent appearance and control over thickness.

Enhancements:

  • Render connections, infomarks, and character paths using colored quads instead of OpenGL line primitives, adjusting line widths to match the new approach.
  • Improve handling of degenerate and long segments for connections and infomark arrows to maintain visual continuity and fading behavior.
  • Slightly adjust one-way connection endpoint geometry for better visual alignment.

nschimme avatar Nov 24 '25 21:11 nschimme

Reviewer's Guide

Replaces OpenGL line-based rendering of 3D map connections, infomark arrows, and character paths with quad-based geometry built via a new shared LineRendering utility, while adjusting visual constants and projection tolerances for more robust, consistent appearance.

Sequence diagram for quad-based connection line rendering

sequenceDiagram
    participant MapCanvas
    participant ConnectionDrawer
    participant ConnectionFakeGL
    participant OpenGL
    participant mmgl_LineRendering

    MapCanvas->>ConnectionDrawer: buildConnectionGeometry()
    ConnectionDrawer->>ConnectionFakeGL: drawLineStrip(points)

    loop over segments
        ConnectionFakeGL->>ConnectionFakeGL: transform points
        ConnectionFakeGL->>mmgl_LineRendering: isNearZero(segment)
        alt zero-length segment
            mmgl_LineRendering-->>ConnectionFakeGL: true
            ConnectionFakeGL->>mmgl_LineRendering: drawZeroLengthSquare(quadVerts, center, width, color)
        else non-zero segment
            mmgl_LineRendering-->>ConnectionFakeGL: false
            ConnectionFakeGL->>mmgl_LineRendering: getPerpendicularNormal(direction)
            alt segment crosses Z layers
                ConnectionFakeGL->>mmgl_LineRendering: getOrthogonalNormal(direction, perp_normal_1)
                ConnectionFakeGL->>mmgl_LineRendering: generateLineQuad(quadVerts, p1, p2, width, color, perp_normal_1)
                ConnectionFakeGL->>mmgl_LineRendering: generateLineQuad(quadVerts, p1, p2, width, color, perp_normal_2)
            else same Z layer
                ConnectionFakeGL->>mmgl_LineRendering: generateLineQuad(quadVerts, p1, p2, width, color, perp_normal_1)
            end
        end
    end

    ConnectionDrawer->>OpenGL: ConnectionDrawerBuffers.getMeshes()
    OpenGL-->>ConnectionDrawer: ConnectionMeshes(normalQuads, redQuads, tris)

    MapCanvas->>ConnectionMeshes: render(thisLayer, focusedLayer)
    ConnectionMeshes->>OpenGL: normalQuads.render(state)
    ConnectionMeshes->>OpenGL: redQuads.render(state)
    ConnectionMeshes->>OpenGL: normalTris.render(state)
    ConnectionMeshes->>OpenGL: redTris.render(state)

Sequence diagram for quad-based infomark arrow rendering

sequenceDiagram
    participant MapCanvas
    participant InfomarksBatch
    participant OpenGL
    participant mmgl_LineRendering

    MapCanvas->>InfomarksBatch: drawInfomark(batch, ARROW, ...)
    MapCanvas->>InfomarksBatch: drawLine(shaftStart, shaftEnd)

    InfomarksBatch->>mmgl_LineRendering: generateLineQuadsSafe(m_quads, start_v, end_v, width, color)
    mmgl_LineRendering-->>InfomarksBatch: quad vertices appended

    MapCanvas->>InfomarksBatch: drawTriangle(arrowhead vertices)

    MapCanvas->>InfomarksBatch: renderImmediate(state)
    InfomarksBatch->>OpenGL: renderColoredTris(m_tris, state)
    InfomarksBatch->>OpenGL: renderColoredQuads(m_quads, state)
    InfomarksBatch->>OpenGL: renderPoints(m_points, state.withPointSize())
    InfomarksBatch->>OpenGL: font.render3dTextImmediate(text)

Class diagram for quad-based line rendering utilities and consumers

classDiagram

class mmgl_LineRendering {
    +float W_PROJECTION_EPSILON
    +float GEOMETRIC_EPSILON
    +float PROJECTION_EPSILON
    +float ZERO_LENGTH_THRESHOLD_SQ
    +generateLineQuad(verts, p1, p2, width, color, perpendicular_normal)
    +drawZeroLengthSquare(verts, center, width, color)
    +getPerpendicularNormal(direction) glm::vec3
    +getOrthogonalNormal(direction, perp_normal_1) glm::vec3
    +generateLineQuadsSafe(verts, p1, p2, width, color)
    +isDegenerate(vec) bool
    +isNearZero(segment) bool
}

class ConnectionDrawerColorBuffer {
    +std_vector_ColorVert triVerts
    +std_vector_ColorVert quadVerts
    +clear()
    +empty() bool
}

class ConnectionMeshes {
    +UniqueMesh normalTris
    +UniqueMesh redTris
    +UniqueMesh normalQuads
    +UniqueMesh redQuads
    +render(thisLayer, focusedLayer)
}

class InfomarksBatch {
    -OpenGL m_realGL
    -Font3d m_font
    -Color m_color
    -std_vector_ColorVert m_points
    -std_vector_ColorVert m_tris
    -std_vector_ColorVert m_quads
    +drawPoint(a)
    +drawLine(a, b)
    +drawTriangle(a, b, c)
    +renderImmediate(state)
    +getMeshes() InfomarksMeshes
}

class InfomarksMeshes {
    +UniqueMesh points
    +UniqueMesh tris
    +UniqueMesh quads
    +UniqueMesh textMesh
    +bool isValid
    +render()
}

class CharacterBatch_CharFakeGL {
    -std_vector_ColorVert m_charTris
    -std_vector_ColorVert m_charBeaconQuads
    -std_vector_ColorVert m_charLines
    -std_vector_ColoredTexVert m_charRoomQuads
    -std_vector_ColorVert m_pathPoints
    -std_vector_ColorVert m_pathLineQuads
    -std_vector_FontVert3d m_screenSpaceArrows
    +drawPathSegment(p1, p2, color)
    +drawPathPoint(color, pos)
    +reallyDrawPaths(gl)
}

mmgl_LineRendering <.. ConnectionDrawerColorBuffer : uses
mmgl_LineRendering <.. ConnectionMeshes : uses
mmgl_LineRendering <.. InfomarksBatch : uses
mmgl_LineRendering <.. CharacterBatch_CharFakeGL : uses

ConnectionDrawerColorBuffer --> ConnectionMeshes : provides data
InfomarksBatch --> InfomarksMeshes : builds
CharacterBatch_CharFakeGL --> OpenGL : reallyDrawPaths

File-Level Changes

Change Details Files
Introduce shared quad-based line rendering helpers and tolerance constants in a new LineRendering module and wire it into build.
  • Add LineRendering.h/cpp with helpers for generating line quads, handling zero-length segments, and computing perpendicular normals.
  • Define shared geometric/projection epsilons and zero-length thresholds for use in rendering and projection logic.
  • Register LineRendering sources in the CMake build so they are compiled and linked.
src/opengl/LineRendering.cpp
src/opengl/LineRendering.h
src/CMakeLists.txt
Convert connection rendering from line primitives to quad geometry with updated fading, Z-layer handling, and endpoint tweaks.
  • Replace ConnectionDrawer line vertex buffers and meshes with quad-based buffers and meshes, and render them via createColoredQuadBatch/renderColoredQuads instead of line batches.
  • Reimplement ConnectionFakeGL::drawLineStrip to build quads per segment, extending first/last segments, applying long-line fading with alpha, and using a cross-shaped quad when crossing Z-layers.
  • Update paintSelectedConnection to render the selected connection as a quad line via generateLineQuadsSafe instead of renderPlainLines.
  • Add isCrossingZAxis helper using shared GEOMETRIC_EPSILON and slightly adjust one-way connection endpoint coordinates for up/down exits.
  • Change CONNECTION_LINE_WIDTH constant from pixel width to a small world-space value suitable for quad rendering.
src/display/Connections.cpp
src/display/Connections.h
src/display/ConnectionLineBuilder.cpp
Convert infomark arrows from line primitives to quads and adjust arrow drawing to separate shaft and head.
  • Replace InfomarksBatch line storage with quad storage, generating line quads in drawLine via generateLineQuadsSafe.
  • Update InfomarksMeshes and renderImmediate to use colored quads instead of lines, and adjust render order to draw quads before text.
  • Change the ARROW infomark drawing to explicitly draw a single shaft line plus a triangle head instead of a line strip through three points.
  • Switch INFOMARK_ARROW_LINE_WIDTH to a world-space width value and include glm epsilon/norm headers for tolerances.
src/display/Infomarks.cpp
src/display/Infomarks.h
Render character path lines as quad geometry instead of GL lines, and adjust path width.
  • Introduce CharFakeGL::drawPathSegment that generates path line quads via generateLineQuadsSafe, and remove drawPathLineStrip that pushed simple line segments.
  • Change drawPreSpammedPath to iterate over path vertices and call drawPathSegment per segment, leaving point rendering unchanged.
  • Update CharFakeGL::reallyDrawPaths to render m_pathLineQuads as colored quads instead of m_pathLineVerts lines, and rename the internal buffers accordingly.
  • Increase path rendering thickness semantics by changing PATH_LINE_WIDTH to a small world-space width while keeping CHAR_ARROW_LINE_WIDTH unchanged.
src/display/Characters.cpp
src/display/Characters.h
Use shared projection tolerances from LineRendering when projecting/unprojecting map coordinates.
  • Replace hard-coded w==0 and projection clamp epsilons in MapCanvasViewport::project and ::unproject with mmgl::W_PROJECTION_EPSILON and mmgl::PROJECTION_EPSILON.
  • Include LineRendering.h and glm epsilon headers in MapCanvasData.cpp to access the shared constants.
src/display/MapCanvasData.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Nov 24 '25 21:11 sourcery-ai[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 66.37%. Comparing base (26d1a9d) to head (b233e82). :warning: Report is 125 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #412      +/-   ##
==========================================
- Coverage   66.48%   66.37%   -0.12%     
==========================================
  Files          85       86       +1     
  Lines        4186     3937     -249     
  Branches      255      257       +2     
==========================================
- Hits         2783     2613     -170     
+ Misses       1403     1324      -79     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Nov 24 '25 21:11 codecov[bot]

@sourcery-ai review

nschimme avatar Nov 25 '25 18:11 nschimme

https://github.com/sourcery-ai review

nschimme avatar Nov 25 '25 20:11 nschimme

@sourcery-ai review

nschimme avatar Nov 25 '25 20:11 nschimme

@sourcery-ai review

nschimme avatar Nov 25 '25 21:11 nschimme

https://github.com/sourcery-ai review

nschimme avatar Nov 25 '25 21:11 nschimme

@sourcery-ai review

nschimme avatar Nov 25 '25 21:11 nschimme

@sourcery-ai review

nschimme avatar Nov 26 '25 18:11 nschimme

@sourcery-ai review

nschimme avatar Nov 26 '25 19:11 nschimme