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

Feat/graphics settings #2534

Merged
merged 18 commits into from
Dec 16, 2024
Merged

Feat/graphics settings #2534

merged 18 commits into from
Dec 16, 2024

Conversation

ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented Dec 16, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a structured graphics settings management system with options for LOW, MID, and HIGH settings.
    • Enhanced rendering logic to adapt based on selected graphics quality, improving performance and user experience.
  • Bug Fixes

    • Fixed control flow issues in animation updates based on graphics settings, preventing unnecessary updates in low graphics mode.
  • Documentation

    • Updated documentation to reflect changes in graphics settings handling and usage.
  • Chores

    • Refactored code for improved clarity and maintainability related to graphics settings management.

Copy link

vercel bot commented Dec 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 16, 2024 5:24am
eternum-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 16, 2024 5:24am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Dec 16, 2024 5:24am

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a comprehensive overhaul of graphics settings management across multiple client-side components. The primary change is the replacement of a simple boolean isLowGraphicsMode with a more nuanced GraphicsSettings enum (LOW, MID, HIGH). The modifications span several files, including GameRenderer, ArmyModel, BattleModel, and configuration files, creating a more flexible system for dynamically adjusting rendering performance based on device capabilities.

Changes

File Change Summary
client/src/three/GameRenderer.ts Replaced boolean graphics mode with GraphicsSettings, added conditional rendering logic based on graphics quality
client/src/three/components/ArmyModel.ts Updated animation update logic to respect graphics settings, skipping animations in low graphics mode
client/src/three/components/BattleModel.tsx Added graphics settings check to control animation updates
client/src/three/components/InstancedBiome.tsx Implemented graphics settings-based animation update control
client/src/ui/config.tsx Introduced GraphicsSettings enum, created new device detection and settings migration logic
client/src/ui/modules/settings/Settings.tsx Updated graphics settings UI and management

Sequence Diagram

sequenceDiagram
    participant User
    participant DeviceDetector
    participant GraphicsSettings
    participant Renderer

    User->>DeviceDetector: Select/Detect Device
    DeviceDetector->>GraphicsSettings: Determine Graphics Level
    GraphicsSettings->>Renderer: Apply Rendering Strategy
    alt Low Graphics
        Renderer->>Renderer: Reduce Animations
        Renderer->>Renderer: Limit Frame Rate
    else Mid Graphics
        Renderer->>Renderer: Partial Animations
        Renderer->>Renderer: Moderate Performance
    else High Graphics
        Renderer->>Renderer: Full Animations
        Renderer->>Renderer: Maximum Performance
    end
Loading

Possibly related PRs

Suggested Reviewers

  • aymericdelab
  • edisontim

Poem

🐰 Rendering Rabbit's Ode to Graphics Grace

In pixels low and frames so light,
Our rabbit leaps with rendering might!
From high to low, we dance and play,
Optimizing graphics day by day! 🎮✨
Performance magic, smooth and bright!

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0edd382 and e096993.

📒 Files selected for processing (7)
  • client/src/three/GameRenderer.ts (6 hunks)
  • client/src/three/components/ArmyModel.ts (3 hunks)
  • client/src/three/components/BattleModel.tsx (2 hunks)
  • client/src/three/components/InstancedBiome.tsx (3 hunks)
  • client/src/three/components/InstancedModel.tsx (3 hunks)
  • client/src/ui/config.tsx (1 hunks)
  • client/src/ui/modules/settings/Settings.tsx (4 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ponderingdemocritus ponderingdemocritus merged commit 6fc4307 into next Dec 16, 2024
6 of 9 checks passed
@ponderingdemocritus ponderingdemocritus deleted the feat/graphics-settings branch December 16, 2024 05:25
Copy link

Failed to generate code suggestions for PR

Copy link
Contributor

@mentatbot mentatbot bot left a comment

Choose a reason for hiding this comment

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

The PR adds a new graphics settings system with LOW/MID/HIGH tiers, replacing the previous binary low/high graphics flag. The implementation looks solid with good performance optimizations like frame rate limiting for lower settings. A few suggestions:

  1. Add documentation for what each graphics tier provides
  2. Extract some repeated code into utility functions
  3. Improve type safety around localStorage usage
  4. Consider adding performance metrics/telemetry
  5. Add visual indicators in settings UI for recommended graphics level based on device capabilities

Thanks for using MentatBot. Give comments a 👍 or 👎 to help me improve!

@@ -3,29 +3,47 @@ import { BuildingType, FELT_CENTER } from "@bibliothecadao/eternum";

export { FELT_CENTER };

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding JSDoc comments to document what features/performance characteristics each graphics setting level provides

Suggested change
/**
* Graphics quality settings
* LOW - Reduced shadows, animations, and effects. 30 FPS cap. Best for low-end devices
* MID - Balanced settings with some effects enabled. 30 FPS cap
* HIGH - Full graphics quality with all effects enabled. Uncapped FPS
*/

Comment on lines +401 to +402
const frameTime = 1000 / 30; // 33.33ms for 30 FPS
if (currentTime - this.lastTime < frameTime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting the frame rate limiting logic into a reusable utility function since it's used in multiple places

Suggested change
const frameTime = 1000 / 30; // 33.33ms for 30 FPS
if (currentTime - this.lastTime < frameTime) {
if (isFrameSkipped(currentTime, this.lastTime, 30)) {

Comment on lines +12 to +18
const checkGraphicsSettings = async () => {
// Handle migration from old LOW_GRAPHICS_FLAG
const oldLowGraphicsFlag = localStorage.getItem("LOW_GRAPHICS_FLAG");
if (oldLowGraphicsFlag !== null) {
// Migrate old setting to new format
const newSetting = oldLowGraphicsFlag === "true" ? GraphicsSettings.LOW : GraphicsSettings.HIGH;
localStorage.setItem("GRAPHICS_SETTING", newSetting);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using TypeScript const assertions for the localStorage keys to prevent typos and improve type safety

Suggested change
const checkGraphicsSettings = async () => {
// Handle migration from old LOW_GRAPHICS_FLAG
const oldLowGraphicsFlag = localStorage.getItem("LOW_GRAPHICS_FLAG");
if (oldLowGraphicsFlag !== null) {
// Migrate old setting to new format
const newSetting = oldLowGraphicsFlag === "true" ? GraphicsSettings.LOW : GraphicsSettings.HIGH;
localStorage.setItem("GRAPHICS_SETTING", newSetting);
const STORAGE_KEYS = {
GRAPHICS_SETTING: 'GRAPHICS_SETTING',
LOW_GRAPHICS_FLAG: 'LOW_GRAPHICS_FLAG',
INITIAL_LAPTOP_CHECK: 'INITIAL_LAPTOP_CHECK'
} as const;
const checkGraphicsSettings = async () => {
// Handle migration from old LOW_GRAPHICS_FLAG
const oldLowGraphicsFlag = localStorage.getItem(STORAGE_KEYS.LOW_GRAPHICS_FLAG);
if (oldLowGraphicsFlag !== null) {
// Migrate old setting to new format
const newSetting = oldLowGraphicsFlag === "true" ? GraphicsSettings.LOW : GraphicsSettings.HIGH;
localStorage.setItem(STORAGE_KEYS.GRAPHICS_SETTING, newSetting);

@@ -168,6 +169,10 @@ export default class InstancedModel {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove console.log statement in removeInstance method

Suggested change
}

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.

3 participants