-
-
Notifications
You must be signed in to change notification settings - Fork 841
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
Associate sounds with instance ID #1445
Conversation
Thanks! I wouldn't want to merge this without the sound instances cleaning up after themselves; currently the instance list would "leak" unless sounds are explicitly stopped. Event sounds from the timeline should be stopped as well. |
I came up with a better solution that doesn't leak the sound instances, so this is not a prototype anymore and ready for CR. |
Using Character ID is troublesome because:
One possibility is to add an unique increasing |
Now sounds are stopped per an instance ID, which is the However, there are some Rust borrowing issues left, which you might assist me to solve. In short, I made if let Ok(child) = context // 1st borrow
.library
library_for_movie_mut(self.movie().unwrap())
instantiate_by_id(id, context) // 2nd borrow, context used to be context.gc_context
{
... The problem is that |
You can't chain methods on context variables that also need the context. This is the same reason why
Rust's borrow checker is a little weird with how it accounts for lifetimes and borrows accrued in temporaries; any borrow that's part of an |
@kmeisthax Thanks for your help, but unfortunately the compiler still complains for the same reason. Can you please try to compile the code yourself and confirm it's working? |
You could do it in |
@Herschel Thanks for your suggestion! Despite I think it's not the ideal way, I did it in One thing that still remained - few methods currently accept an optional |
Previously, Sound.stop stopped only the last played sound. This commit is a prototype and needs some follow-ups: * Remove inactive sound instances from the list. * Fix and uncomment the code in Sound.position, but anyway it wasn't fully functional before.
Instead of maintaining a Vec of active sound instances in each DisplayObject, this commit reuses the already-existing sound tracking mechanism of each backend. This is both much more simple, and doesn't leak the instances list. TODO: Consider to require all sound instances to be associated with a MovieClip. Currently some are not associated with any (i.e. have None in their clip_id). This would allow to convert clip_id to be non-Option.
As a preparation for associating active sounds to an unique instance ID instead of a possibly shared clip ID. The code currently does not compile because of 5 similar errors related to Rust borrowing.
This commit uses the instance IDs added in the previous commit for tracking the active sounds. The code still doesn't compile as the borrowing issues haven't been fixed yet.
It always should be non-negative. Maybe it's worth to define a type alias for it: pub type InstanceId = u32; But I'm not sure where to place it.
For now, we're going to initialize instance_id in post_instantiation alongside set_default_instance_name.
The previous commit removed its initialization because it led to compile errors.
On second thought it's still useful.
Was this request abandoned? Sorry for asking that, but it seems to be no activity for over a month. Maybe I’m just being impatient. (I must confess that I’m extremely interested in an improvement for #340, reported almost a year ago). Many thanks for your excellent work. |
Completely superseded by #2825. |
Fixes #1441
Fixes #1319