Skip to content

refactor(view): Simplify View angle normalization - #2271

Merged
xezon merged 3 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-view-normangle
Feb 9, 2026
Merged

refactor(view): Simplify View angle normalization#2271
xezon merged 3 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-view-normangle

Conversation

@xezon

@xezon xezon commented Feb 8, 2026

Copy link
Copy Markdown

This change simplifies the View angle normalization. All changes to View::m_angle now go through View::setAngle.

User facing nothing should change.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing labels Feb 8, 2026
@greptile-apps

greptile-apps Bot commented Feb 8, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

Centralized View angle normalization by routing all View::m_angle assignments through View::setAngle(), which now normalizes angles using WWMath::Normalize_Angle(). Key changes:

  • Modified View::setAngle() to normalize input angles to the range [-π, π]
  • Refactored W3DView.cpp to replace 8 direct m_angle assignments with View::setAngle() calls
  • Removed redundant normAngle() calls in W3DView::setAngle() since normalization now happens in base class
  • Added documentation comments clarifying that angle members are expected to be normalized
  • Addressed previous review concern by normalizing oldZRot in the follow-camera rotation logic for consistent smoothing behavior

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean refactoring that improves code maintainability by centralizing angle normalization logic. All direct m_angle assignments in View-related classes now go through View::setAngle(). The developer addressed the previous review concern about oldZRot normalization. No breaking changes to behavior, and the refactoring is systematic and thorough.
  • No files require special attention

Important Files Changed

Filename Overview
Core/GameEngine/Include/GameClient/View.h Added documentation comments clarifying that angle members are expected to be normalized
Core/GameEngine/Source/GameClient/View.cpp Modified setAngle() to normalize input using WWMath::Normalize_Angle(), minor signature formatting in setAngleToDefault()
Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp Refactored all direct m_angle assignments to use View::setAngle(), removed redundant normalization calls, addressed previous review concern about oldZRot normalization

Sequence Diagram

sequenceDiagram
    participant Client as Caller Code
    participant W3DView as W3DView
    participant View as View (Base)
    participant WWMath as WWMath
    
    Note over Client,WWMath: Before: Multiple normalization points
    Client->>W3DView: Direct m_angle assignment
    W3DView->>W3DView: normAngle(m_angle)
    Note over W3DView: Normalization scattered

    Note over Client,WWMath: After: Centralized normalization
    Client->>W3DView: setAngle(radians)
    W3DView->>View: View::setAngle(radians)
    View->>WWMath: Normalize_Angle(radians)
    WWMath-->>View: normalized angle
    View->>View: m_angle = normalized
    Note over View: Single point of normalization
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps

greptile-apps Bot commented Feb 8, 2026

Copy link
Copy Markdown
Additional Comments (1)

Core/GameEngine/Source/GameClient/View.cpp
Angle not normalized

View::setAngle normalizes with while (angle >= ...) angle -= ... / while (angle < ...) angle += .... If angle can ever become non-finite (NaN/Inf) (e.g., from upstream math), those loops won’t terminate (NaN makes both comparisons false; Inf makes them spin forever). Consider guarding setAngle with a finite check (e.g. if (!std::isfinite(angle)) angle = 0;) or otherwise handling this explicitly so one bad input can’t hang the game loop.

Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/GameEngine/Source/GameClient/View.cpp
Line: 1:3

Comment:
**Angle not normalized**

`View::setAngle` normalizes with `while (angle >= ...) angle -= ...` / `while (angle < ...) angle += ...`. If `angle` can ever become non-finite (NaN/Inf) (e.g., from upstream math), those loops won’t terminate (NaN makes both comparisons false; Inf makes them spin forever). Consider guarding `setAngle` with a finite check (e.g. `if (!std::isfinite(angle)) angle = 0;`) or otherwise handling this explicitly so one bad input can’t hang the game loop.

How can I resolve this? If you propose a fix, please make it concise.

@xezon

xezon commented Feb 8, 2026

Copy link
Copy Markdown
Author

@greptileai

Where do you see that loop? This is how the normalize function looks like:

WWINLINE float WWMath::Normalize_Angle(float angle)
{
	return angle - (WWMATH_TWO_PI * Floor((angle + WWMATH_PI) / WWMATH_TWO_PI));
}

@greptile-apps

greptile-apps Bot commented Feb 8, 2026

Copy link
Copy Markdown

You're absolutely right - I apologize for the confusion. Looking at the actual WWMath::Normalize_Angle implementation, there is no loop. The normalization is done with a single mathematical expression using floor division.

The function works by:

  1. Shifting the angle by π (to center the range)
  2. Computing how many full 2π rotations to remove using floor division
  3. Subtracting those full rotations to bring the result into [-π, π]

This is a standard, efficient mathematical normalization - no iterative loop involved. My earlier concern about potential performance issues from repeated calls was misplaced. This approach is actually optimal for angle normalization.

@xezon

xezon commented Feb 8, 2026

Copy link
Copy Markdown
Author

@greptileai

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread Core/GameEngine/Source/GameClient/View.cpp

@Mauller Mauller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

looks good

@xezon
xezon merged commit 3e0a5be into TheSuperHackers:main Feb 9, 2026
@xezon
xezon deleted the xezon/refactor-view-normangle branch February 9, 2026 18:37
@xezon xezon modified the milestones: Backlog, Camera Rework Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants