-
-
Notifications
You must be signed in to change notification settings - Fork 655
implement persistence for child bodies during reset #1251
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,9 +125,24 @@ export default class World extends Container { | |
| // call the parent method | ||
| super.reset(); | ||
|
|
||
| // save persistent child bodies | ||
| const persistentBodies = []; | ||
| this.bodies.forEach((value) => { | ||
| if (value.ancestor && value.ancestor.isPersistent) { | ||
| persistentBodies.push(value); | ||
| } | ||
| }); | ||
|
|
||
| // empty the list of active physic bodies | ||
| // Note: this should be empty already when calling the parent method | ||
| this.bodies.clear(); | ||
|
|
||
| // insert persistent child bodies into the new state | ||
| if (persistentBodies.length > 0) { | ||
| persistentBodies.forEach((body) => { | ||
| this.bodies.add(body); | ||
| }); | ||
| } | ||
|
Comment on lines
+128
to
+145
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
The persistence filter only keeps bodies whose owning renderable is marked
isPersistent. Bodies belonging to non-persistent renderables inside a persistent container will still remain in the scene aftersuper.reset(), but will be dropped fromthis.bodiesby the subsequentclear()and never re-added, causing those objects to stop being stepped/collided. Consider retaining any body whosebody.ancestoris still attached to this world aftersuper.reset()(e.g., via the renderable’s container chain/root ancestor), or rebuildingthis.bodiesfrom the post-reset scene graph instead of checking onlyisPersistenton the body ancestor.