-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add starts_immediately
related methods
#174
base: main
Are you sure you want to change the base?
Conversation
Hi- Thanks for the PR!
How is that different from the |
42ae875
to
9e67d27
Compare
Hey, thanks for getting back to me! I added an example, see it here. I may also be missing something, but as far as I could tell, with the current API in As a direct comparison how it's different to ... and |
9e67d27
to
10dc7ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c981a0e
to
283b1ea
Compare
Remove `with_time` from `Spawner`, and move `set_time` and `get_time` to `EffectSpawner`. Update `burst_over_time_on_command.rs` example. Change how `starts_immediately=false` is handled (with infinity).
@djeedai I made some changes, dropped Also not sure do we really need |
with_time
, set_time
, and get_time
functions to Spawner
starts_immediately
related methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not convinced, sorry 😅
- The added methods for
starts_immediately
are probably fine. - The time ones are... maybe ok
- The fact that the infinite time has a special effect though, that one I'd like to be more convinced that I am now that it's a good thing. See other comment for details.
@@ -442,6 +465,16 @@ impl EffectSpawner { | |||
self.active | |||
} | |||
|
|||
/// Set accumulated time since last spawn. | |||
pub fn set_time(&mut self, time: f32) { | |||
self.time = time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add at least a debug check for robustness, because passing a negative time will likely break everything.
self.time = time; | |
debug_assert!(time >= 0.); | |
self.time = time; |
0. | ||
} else { | ||
f32::INFINITY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is nice (or not; see below) because it works with non-once
spawners too. However this means there's now an implicit API contract which is that set_time(f32::INFINITY)
is equivalent to / duplicates set_starts_immediately(false)
, which is both unexpected and undocumented. I liked the time-based approach better because this makes sense to users, and can be useful for precise control even beyond the current burst use case.
And on the fact it works for non-once
spawners: thinking more about it I think that's a mistake, because this is redundant with the active
state of the spawner itself. The once
spawner is very special because once it emitted a burst it goes to "sleep" yet is still active, but the other spawners (anything with a finite period
) should conceptually emit particles if active, and now with that infinite time trick they don't, and I think that makes things confusing for the user.
Actually, as I was writing, I'm now wondering if any of this is needed. If you want a burst-over-time effect you can simply call new()
with non-zero count
and time
, but leave the period
as infinite to get a non-repeating emission. There's no need to manipulate the time, is there?
It's always good to expose this kind of things, both for testing and for tooling (some future VFX editor), even if not used much at runtime in games/apps, provided it doesn't force any design or behavior that is detrimental to runtime usability/performance. I'd probably keep those. |
I think you can do it in current api using Spawner or add this new function in Spawner implementation pub fn until_timeout(count: Value<f32>, spawn_immediately: bool, timeout: f32) -> Self {
let mut spawner = Self::new(count, 0.0.into(), timeout);
spawner.starts_immediately = spawn_immediately;
spawner
} |
This change makes it possible to create a single burst of particles over a time window, that doesn't fire immediately. My workaround before was to have it inactive at first, but this seemed counter-intuitive, as we have the
once
function.Perhaps an additional function we could add, is something like
burst_once_over_time
, pending for a better name 😅