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

Fix cpuparticles randomness regression #101872

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

QbieShay
Copy link
Contributor

@QbieShay QbieShay commented Jan 21, 2025

@QbieShay QbieShay added this to the 4.4 milestone Jan 21, 2025
@QbieShay QbieShay requested review from a team as code owners January 21, 2025 11:01
@QbieShay QbieShay requested a review from KoBeWi January 21, 2025 11:01
@AThousandShips AThousandShips changed the title Fixed cpuparticles randomness regression caused by #92089 Fixed cpuparticles randomness regression Jan 21, 2025
@@ -179,6 +180,8 @@ class CPUParticles2D : public Node2D {

Vector2 gravity = Vector2(0, 980);

Ref<RandomNumberGenerator> _rng;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Ref<RandomNumberGenerator> _rng;
Ref<RandomNumberGenerator> rng;

We don't underscore private variables.

@@ -31,6 +31,7 @@
#ifndef CPU_PARTICLES_2D_H
#define CPU_PARTICLES_2D_H

#include "core/math/random_number_generator.h"
Copy link
Member

Choose a reason for hiding this comment

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

Use forward declaration instead of include.

Vector2 rot = Vector2(Math::cos(angle1_rad), Math::sin(angle1_rad));
p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], (real_t)rand_from_seed(_seed));
p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], (real_t)_rng->randf());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], (real_t)_rng->randf());
p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], _rng->randf());

randf() already returns real_t, so not sure what the cast was for.

@AThousandShips AThousandShips changed the title Fixed cpuparticles randomness regression Fix cpuparticles randomness regression Jan 21, 2025
@QbieShay QbieShay force-pushed the qbe/fix-particle-random branch from b93216c to c8b0509 Compare January 21, 2025 12:24
@Repiteo Repiteo merged commit ebea7b1 into godotengine:master Jan 21, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 21, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CPUParticles2D are not random anymore
4 participants