Skip to content

fix(weather-editor): type usage and conversions#2200

Merged
alandtse merged 4 commits into
community-shaders:devfrom
SkrubbySkrubInAShrub:WE-WW-Lightning-colour
Apr 25, 2026
Merged

fix(weather-editor): type usage and conversions#2200
alandtse merged 4 commits into
community-shaders:devfrom
SkrubbySkrubInAShrub:WE-WW-Lightning-colour

Conversation

@SkrubbySkrubInAShrub
Copy link
Copy Markdown
Collaborator

@SkrubbySkrubInAShrub SkrubbySkrubInAShrub commented Apr 24, 2026

fixing some issues that were accidentally truncating values.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected wind direction and range editing/saving so values behave and persist correctly.
    • Fixed thunder/lightning frequency serialization to preserve intended values.
    • Improved color conversion for weather data to ensure accurate color representation.
    • Stabilized precipitation handling to reduce particle and visual anomalies.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3810b07c-223b-4daa-92bd-3932a82dd7e3

📥 Commits

Reviewing files that changed from the base of the PR and between c7a23f4 and 60745ff.

📒 Files selected for processing (1)
  • src/Features/WeatherEditor.cpp

📝 Walkthrough

Walkthrough

This PR switches several weather-related 8-bit fields from signed to unsigned representations, updates UI sliders and interpolation for wind fields, replaces C-style casts with static_cast, changes thunder/lightning serialization casts, and alters color byte encoding/decoding from int8-based to uint8-based.

Changes

Cohort / File(s) Summary
Weather widget — wind & thunder
src/WeatherEditor/Weather/WeatherWidget.cpp
Switched “Wind Direction” and “Wind Direction Range” controls from INT8_SLIDER to UINT8_SLIDER. Replaced C-style casts with static_cast; assignments and serialization for windDirection, windDirectionRange, and thunderLightningFrequency now use uint8_t/explicit casts.
Weather interpolation
src/Features/WeatherEditor.cpp
Changed interpolation for wind fields to use LerpUint8_t instead of LerpInt8_t, altering lerp/clamping behavior for windDirection and windDirectionRange.
Color conversion helpers
src/WeatherEditor/WeatherUtils.cpp
Swapped color byte encoding/decoding: Float3ToColor now uses FloatToUint8 and ColorToFloat3 uses Uint8ToFloat (replaces int8-based conversions).
Precipitation runtime indexing
src/WeatherEditor/Weather/PrecipitationWidget.cpp
Replaced C-style (uint32_t) casts with static_cast<uint32_t> when indexing runtime.data using RE::BGSShaderParticleGeometryData::DataID values; numeric assignments unchanged.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • alandtse
  • davo0411

Poem

🐇 Bits hop light on breezy code,

Unsigned winds along the road,
Colors trade their signed disguise,
Sliders hum beneath spring skies,
The rabbit taps "commit" with a joyful nod.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(weather-editor): type usage and conversions' is directly related to the main changes, which involve correcting type usage (unsigned vs signed) and conversions throughout the weather editor code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

No actionable suggestions for changed features.

Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/WeatherEditor/WeatherUtils.cpp (1)

163-182: ⚠️ Potential issue | 🔴 Critical

Revert Color3 encoding to signed conversion.

The Color3::red/green/blue fields in CommonLibSSE-NG are std::int8_t (signed), not unsigned. Using FloatToUint8() writes unsigned values (0–255) into signed fields, causing sign-extension corruption. For example, FloatToUint8(0.8f) produces 204, which reinterprets in a signed field as –52. Revert Float3ToColor() and its related overload to use FloatToInt8() and Uint8ToFloat() for proper round-tripping.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/WeatherEditor/WeatherUtils.cpp` around lines 163 - 182, Float3ToColor and
the Color3 overload of ColorToFloat3 are using unsigned conversions which
corrupt signed Color3 fields; change FloatToUint8(...) to FloatToInt8(...) in
Float3ToColor and change Uint8ToFloat(...) to Int8ToFloat(...) in the
ColorToFloat3 overload that accepts RE::TESWeather::Data::Color3 so the signed
std::int8_t Color3.red/green/blue round-trip correctly.
src/WeatherEditor/Weather/WeatherWidget.cpp (1)

756-759: ⚠️ Potential issue | 🔴 Critical

Missing uint8_t cast on wind save — same bug thunderLightningFrequency was fixed for.

Line 749 casts data.thunderLightningFrequency (an int8_t) to uint8_t before storing in weatherProps. Lines 758-759 neglect to do the same for data.windDirection and data.windDirectionRange (also int8_t per LerpInt8_t usage in src/Features/WeatherEditor.cpp lines 155-156).

When an int8_t field storing a 0-255 bit pattern (e.g., 200) is stored directly without casting, it encodes as a negative int (-56). The UI slider (which now uses UINT8_SLIDER, 0-255 range) will clamp this to 0 on next user interaction, permanently corrupting the vanilla heading value.

Proposed fix
 	// Wind
 	weatherProps["Wind Speed"] = data.windSpeed;
-	weatherProps["Wind Direction"] = data.windDirection;
-	weatherProps["Wind Direction Range"] = data.windDirectionRange;
+	weatherProps["Wind Direction"] = static_cast<uint8_t>(data.windDirection);
+	weatherProps["Wind Direction Range"] = static_cast<uint8_t>(data.windDirectionRange);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/WeatherEditor/Weather/WeatherWidget.cpp` around lines 756 - 759, The
weatherProps assignments for wind store int8_t fields without casting and must
mirror the thunderLightningFrequency fix: when assigning data.windDirection and
data.windDirectionRange into weatherProps, explicitly cast them to uint8_t so
the stored values represent 0–255 rather than negative signed ints; update the
assignments that reference data.windDirection and data.windDirectionRange in
WeatherWidget.cpp to cast to (uint8_t) before inserting into weatherProps.
🧹 Nitpick comments (1)
src/WeatherEditor/Weather/WeatherWidget.cpp (1)

574-584: Minor: unify cast style for int8_t fields on save.

Line 574 goes through static_cast<int8_t>(static_cast<uint8_t>(...)) to make the unsigned-bit-pattern → signed-field reinterpret explicit, while lines 583-584 rely on the implicit narrowing from (uint8_t) into the int8_t field. Consider matching the explicit double-cast on the wind assignments (or dropping the double-cast on the thunder assignment) so the intent is consistent across fields with the same underlying type.

♻️ Suggested unification (optional)
-	data.thunderLightningFrequency = static_cast<int8_t>(static_cast<uint8_t>(weatherProps["Thunder Lightning Frequency"]));
+	data.thunderLightningFrequency = static_cast<int8_t>(static_cast<uint8_t>(weatherProps["Thunder Lightning Frequency"]));
 	...
-	data.windDirection = (uint8_t)weatherProps["Wind Direction"];
-	data.windDirectionRange = (uint8_t)weatherProps["Wind Direction Range"];
+	data.windDirection = static_cast<int8_t>(static_cast<uint8_t>(weatherProps["Wind Direction"]));
+	data.windDirectionRange = static_cast<int8_t>(static_cast<uint8_t>(weatherProps["Wind Direction Range"]));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/WeatherEditor/Weather/WeatherWidget.cpp` around lines 574 - 584, Unify
the cast style so fields with an int8_t storage use the same explicit
conversion: replace the C-style casts on data.windSpeed, data.windDirection, and
data.windDirectionRange with the explicit two-step static_cast pattern used for
data.thunderLightningFrequency (i.e.,
static_cast<int8_t>(static_cast<uint8_t>(...))) so the unsigned-bit-pattern →
signed-field reinterpret is explicit and consistent across these members.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/WeatherEditor/Weather/WeatherWidget.cpp`:
- Around line 756-759: The weatherProps assignments for wind store int8_t fields
without casting and must mirror the thunderLightningFrequency fix: when
assigning data.windDirection and data.windDirectionRange into weatherProps,
explicitly cast them to uint8_t so the stored values represent 0–255 rather than
negative signed ints; update the assignments that reference data.windDirection
and data.windDirectionRange in WeatherWidget.cpp to cast to (uint8_t) before
inserting into weatherProps.

In `@src/WeatherEditor/WeatherUtils.cpp`:
- Around line 163-182: Float3ToColor and the Color3 overload of ColorToFloat3
are using unsigned conversions which corrupt signed Color3 fields; change
FloatToUint8(...) to FloatToInt8(...) in Float3ToColor and change
Uint8ToFloat(...) to Int8ToFloat(...) in the ColorToFloat3 overload that accepts
RE::TESWeather::Data::Color3 so the signed std::int8_t Color3.red/green/blue
round-trip correctly.

---

Nitpick comments:
In `@src/WeatherEditor/Weather/WeatherWidget.cpp`:
- Around line 574-584: Unify the cast style so fields with an int8_t storage use
the same explicit conversion: replace the C-style casts on data.windSpeed,
data.windDirection, and data.windDirectionRange with the explicit two-step
static_cast pattern used for data.thunderLightningFrequency (i.e.,
static_cast<int8_t>(static_cast<uint8_t>(...))) so the unsigned-bit-pattern →
signed-field reinterpret is explicit and consistent across these members.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2a3e67d1-69bc-473a-aebb-b7c263c861c2

📥 Commits

Reviewing files that changed from the base of the PR and between 8561116 and 85a561a.

📒 Files selected for processing (2)
  • src/WeatherEditor/Weather/WeatherWidget.cpp
  • src/WeatherEditor/WeatherUtils.cpp

@SkrubbySkrubInAShrub
Copy link
Copy Markdown
Collaborator Author

All three review comments are based on the same incorrect premise: that the wind and Color3 fields are signed int8_t

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

✅ A pre-release build is available for this PR:
Download

Comment thread src/WeatherEditor/Weather/WeatherWidget.cpp Outdated
@alandtse alandtse changed the title fix(weather-Editor): improper type usage and conversions fix(weather-editor): type usage and conversions Apr 25, 2026
Copy link
Copy Markdown
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/WeatherEditor/Weather/WeatherWidget.cpp`:
- Around line 574-584: The load path for windDirection and windDirectionRange
must apply the same unsigned-to-signed cast used for thunderLightningFrequency
to preserve values >=128; update the assignments that read from
weatherProps["Wind Direction"] and weatherProps["Wind Direction Range"] so they
wrap the property in static_cast<uint8_t>(...) and then static_cast<int8_t>(...)
before assigning to data.windDirection and data.windDirectionRange, mirroring
the pattern used for data.thunderLightningFrequency.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5bbdce35-3564-488b-a7a8-34b5d7a21929

📥 Commits

Reviewing files that changed from the base of the PR and between 85a561a and c7a23f4.

📒 Files selected for processing (2)
  • src/WeatherEditor/Weather/PrecipitationWidget.cpp
  • src/WeatherEditor/Weather/WeatherWidget.cpp
✅ Files skipped from review due to trivial changes (1)
  • src/WeatherEditor/Weather/PrecipitationWidget.cpp

Comment thread src/WeatherEditor/Weather/WeatherWidget.cpp
@alandtse alandtse merged commit 022631b into community-shaders:dev Apr 25, 2026
13 checks passed
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 2, 2026
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.

2 participants