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

chore: add configurable tick rate from envar or toml config file #830

Merged
merged 1 commit into from
Feb 7, 2025

Conversation

zulkhair
Copy link
Contributor

@zulkhair zulkhair commented Feb 4, 2025

Closes: PLAT-90

Overview

Based on the user stories, user can configure tick rate from world forge / world cli.
Need capabilities to configure tick rate for world engine from outside the code.
Added CARDINAL_TICK_RATE config that can be put on env variable or using toml config file

Brief Changelog

  • Added CARDINAL_TICK_RATE var on WorldConfig
  • Set world.tickChannel if CARDINAL_TICK_RATE > 0

the value can be overridden by WithTickChannel option if provided.

Testing and Verifying

Manually tested using starter-game-template.

Summary by CodeRabbit

  • New Features
    • Introduced a configuration option to dynamically adjust the simulation tick rate, enabling users to fine-tune the game loop's performance.
    • Added support for specifying the tick rate via environment variables for enhanced configurability.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces a new field, CardinalTickRate, to the WorldConfig struct, allowing configuration of the tick rate via an environment variable. The world initialization logic is updated to set the tick channel based on this tick rate if it is greater than zero. Additionally, the test for loading configuration from the environment is updated to include this new field. These changes enhance the configurability of the tick rate for the game loop without altering existing functionality.

Changes

File(s) Change Summary
cardinal/config.go Added a CardinalTickRate field (uint64, tagged as CARDINAL_TICK_RATE) in WorldConfig with a default value of 0.
cardinal/world.go Updated world initialization to set tickChannel using CardinalTickRate if greater than 0.
cardinal/config_test.go Updated the TestWorldConfig_LoadFromEnv test to initialize CardinalTickRate with a value of 10 and set the environment variable CARDINAL_TICK_RATE.

Sequence Diagram(s)

sequenceDiagram
    participant Config as WorldConfig
    participant World as World
    participant TickTimer as Tick Channel

    Config->>World: Provide configuration with CardinalTickRate
    alt CardinalTickRate > 0
        World->>TickTimer: Calculate tick interval (time.Second / CardinalTickRate) and set tickChannel
    else Default
        World->>TickTimer: Use default tickChannel settings
    end
Loading

📜 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 0c3c648 and 2d429cc.

📒 Files selected for processing (3)
  • cardinal/config.go (2 hunks)
  • cardinal/config_test.go (2 hunks)
  • cardinal/world.go (1 hunks)

🪧 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.

Copy link
Contributor Author

zulkhair commented Feb 4, 2025


How to use the Graphite Merge Queue

Add the label graphite/merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 57.94%. Comparing base (adf2974) to head (2d429cc).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cardinal/world.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #830      +/-   ##
==========================================
+ Coverage   57.83%   57.94%   +0.10%     
==========================================
  Files         145      145              
  Lines        9384     9387       +3     
==========================================
+ Hits         5427     5439      +12     
+ Misses       3506     3501       -5     
+ Partials      451      447       -4     
Files with missing lines Coverage Δ
cardinal/config.go 71.81% <ø> (ø)
cardinal/world.go 75.56% <0.00%> (-0.52%) ⬇️

... and 2 files with indirect coverage changes

@zulkhair zulkhair marked this pull request as ready for review February 4, 2025 12:51
Copy link
Member

@smsunarto smsunarto left a comment

Choose a reason for hiding this comment

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

This needs to be "CARDINAL_TICK_RATE" following the environment variable convention.

There is also a cardinal option WithTickChannel that can be used here (https://world.dev/cardinal/game/world/api-reference#withtickchannel) instead of modifying a private field directly

Copy link
Contributor Author

zulkhair commented Feb 5, 2025

ok, got it will change to CARDINAL_TICK_RATE

I'm modifying it directly because the WithTickChannel option will be used to override everything, it has the highest priority.
so if the user hardcoded tick rate using WithTickChannel on NewWorld func, it will override the value from config.

@zulkhair zulkhair force-pushed the daim/configurable_tick_rate branch from d2a6552 to 0c3c648 Compare February 5, 2025 07:37
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cardinal/config_test.go (1)

39-39: Consider adding test cases for edge values.

The test configuration looks good. Consider adding test cases for edge values (0, max uint64) to ensure proper handling of boundary conditions.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d2a6552 and 0c3c648.

📒 Files selected for processing (3)
  • cardinal/config.go (2 hunks)
  • cardinal/config_test.go (2 hunks)
  • cardinal/world.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • cardinal/world.go
  • cardinal/config.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
cardinal/config_test.go (2)

51-51: LGTM!

The environment variable setup is correct and consistent with the naming convention used for other configuration fields.


58-61: Add validation tests for CardinalTickRate.

Consider adding test cases to validate the tick rate configuration, similar to how other fields are validated. This could include:

  • Test case for valid tick rate (> 0)
  • Test case for invalid tick rate (0 or negative)
  • Test case for interaction with WithTickChannel option (mentioned in PR objectives)

Here's a suggested test structure:

func TestWorldConfig_Validate_TickRate(t *testing.T) {
    testCases := []struct {
        name    string
        cfg     WorldConfig
        wantErr bool
    }{
        {
            name:    "Valid tick rate",
            cfg:     defaultConfigWithOverrides(WorldConfig{CardinalTickRate: 10}),
            wantErr: false,
        },
        {
            name:    "Zero tick rate",
            cfg:     defaultConfigWithOverrides(WorldConfig{CardinalTickRate: 0}),
            wantErr: false, // Assuming 0 is valid as per PR objectives
        },
    }

    for _, tc := range testCases {
        t.Run(tc.name, func(t *testing.T) {
            err := tc.cfg.Validate()
            if tc.wantErr {
                assert.IsError(t, err)
            } else {
                assert.NilError(t, err)
            }
        })
    }
}

@zulkhair zulkhair requested a review from smsunarto February 5, 2025 08:56
Copy link

graphite-app bot commented Feb 7, 2025

Merge activity

Closes: PLAT-90

## Overview

Based on the user stories, user can configure tick rate from world forge / world cli.
Need capabilities to configure tick rate for world engine from outside the code.
Added `CARDINAL_TICK_RATE` config that can be put on env variable or using toml config file

## Brief Changelog

- Added `CARDINAL_TICK_RATE` var on WorldConfig
- Set `world.tickChannel` if `CARDINAL_TICK_RATE > 0`

the value can be overridden by `WithTickChannel` option if provided.

## Testing and Verifying

Manually tested using starter-game-template.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Introduced a configuration option to dynamically adjust the simulation tick rate, enabling users to fine-tune the game loop's performance.
	- Added support for specifying the tick rate via environment variables for enhanced configurability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app bot force-pushed the daim/configurable_tick_rate branch from 0c3c648 to 2d429cc Compare February 7, 2025 09:59
@smsunarto
Copy link
Member

approved -- i'll caveat a small nit that the ordering of the variable declaration does not spark joy (i intentionally grouped them together so its cleaner)

@graphite-app graphite-app bot merged commit 2d429cc into main Feb 7, 2025
9 of 10 checks passed
@graphite-app graphite-app bot deleted the daim/configurable_tick_rate branch February 7, 2025 10:01
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