-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
Add amount_ratio to cpu particles to dynamically change amount emitted
#105251
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
Draft
Ducklett
wants to merge
6
commits into
godotengine:master
Choose a base branch
from
Ducklett:particles-dynamic-amount
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ff592f
Add amount ratio to cpu particles to dynamically change amount emitted
chrisb123 0dd74c5
Merge branch 'master' into revived-particles-pr
chrisb123 bac6849
don't change `emitting` in `set_amount_ratio`
Ducklett 0489fc0
update documentation of `CPUParticles2D` and `CPUParticles3D` to matc…
Ducklett 2ebf6f6
rewrite `amount_ratio` logic to use `active`
Ducklett a2df310
deactivate dead particles when `!active_by_ratio`
Ducklett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,11 @@ void CPUParticles2D::set_amount(int p_amount) { | |
| RS::get_singleton()->multimesh_allocate_data(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_2D, true, true); | ||
|
|
||
| particle_order.resize(p_amount); | ||
| set_amount_ratio(amount_ratio); | ||
| } | ||
|
|
||
| void CPUParticles2D::set_amount_ratio(float p_amount_ratio) { | ||
| amount_ratio = p_amount_ratio; | ||
| } | ||
|
|
||
| void CPUParticles2D::set_lifetime(double p_lifetime) { | ||
|
|
@@ -138,6 +143,10 @@ int CPUParticles2D::get_amount() const { | |
| return particles.size(); | ||
| } | ||
|
|
||
| float CPUParticles2D::get_amount_ratio() const { | ||
| return amount_ratio; | ||
| } | ||
|
|
||
| double CPUParticles2D::get_lifetime() const { | ||
| return lifetime; | ||
| } | ||
|
|
@@ -771,12 +780,22 @@ void CPUParticles2D::_particles_process(double p_delta) { | |
| velocity_xform[2] = Vector2(); | ||
| } | ||
|
|
||
| float amount_ratio_accumulator = 0.0; | ||
| double system_phase = time / lifetime; | ||
|
|
||
| bool should_be_active = false; | ||
| for (int i = 0; i < pcount; i++) { | ||
| Particle &p = parray[i]; | ||
|
|
||
| amount_ratio_accumulator += amount_ratio; | ||
| bool active_by_ratio = false; | ||
| if (amount_ratio_accumulator >= 1.0) { | ||
| active_by_ratio = true; | ||
| amount_ratio_accumulator -= 1.0; | ||
| } else if (!p.active) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same condition is few lines below. |
||
| continue; | ||
| } | ||
|
|
||
| if (!emitting && !p.active) { | ||
| continue; | ||
| } | ||
|
|
@@ -835,6 +854,11 @@ void CPUParticles2D::_particles_process(double p_delta) { | |
| float tv = 0.0; | ||
|
|
||
| if (restart) { | ||
| if (!active_by_ratio) { | ||
| p.active = false; | ||
| continue; | ||
| } | ||
|
|
||
| if (!emitting) { | ||
| p.active = false; | ||
| continue; | ||
|
|
@@ -1415,6 +1439,7 @@ void CPUParticles2D::convert_from_particles(Node *p_particles) { | |
| void CPUParticles2D::_bind_methods() { | ||
| ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles2D::set_emitting); | ||
| ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles2D::set_amount); | ||
| ClassDB::bind_method(D_METHOD("set_amount_ratio", "amount_ratio"), &CPUParticles2D::set_amount_ratio); | ||
| ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles2D::set_lifetime); | ||
| ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles2D::set_one_shot); | ||
| ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles2D::set_pre_process_time); | ||
|
|
@@ -1429,6 +1454,7 @@ void CPUParticles2D::_bind_methods() { | |
|
|
||
| ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles2D::is_emitting); | ||
| ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles2D::get_amount); | ||
| ClassDB::bind_method(D_METHOD("get_amount_ratio"), &CPUParticles2D::get_amount_ratio); | ||
| ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles2D::get_lifetime); | ||
| ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles2D::get_one_shot); | ||
| ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles2D::get_pre_process_time); | ||
|
|
@@ -1456,6 +1482,7 @@ void CPUParticles2D::_bind_methods() { | |
|
|
||
| ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting", PROPERTY_HINT_ONESHOT), "set_emitting", "is_emitting"); | ||
| ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); // FIXME: Evaluate support for `exp` in integer properties, or remove this. | ||
| ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "amount_ratio", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_amount_ratio", "get_amount_ratio"); | ||
| ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); | ||
| ADD_GROUP("Time", ""); | ||
| ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp,suffix:s"), "set_lifetime", "get_lifetime"); | ||
|
|
@@ -1647,6 +1674,7 @@ CPUParticles2D::CPUParticles2D() { | |
|
|
||
| set_emitting(true); | ||
| set_amount(8); | ||
| set_amount_ratio(1); | ||
| set_use_local_coordinates(false); | ||
| set_seed(Math::rand()); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.