-
-
Notifications
You must be signed in to change notification settings - Fork 340
Optimize the logic of remove and add entity. #1930
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
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 |
---|---|---|
|
@@ -337,11 +337,11 @@ | |
const oldScene = enti 8000 ty._scene; | ||
if (oldScene !== this) { | ||
if (oldScene && isRoot) { | ||
oldScene._removeFromEntityList(entity); | ||
Entity._removeFormChildren(oldScene._rootEntities, entity); | ||
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. Update method name to match the fix in Entity class. Once the typo in Apply this diff to fix the references: - Entity._removeFormChildren(oldScene._rootEntities, child);
+ Entity._removeFromChildren(oldScene._rootEntities, child); Also applies to: 378-378 🧰 Tools🪛 GitHub Check: codecov/patch[warning] 340-340: packages/core/src/Scene.ts#L340 |
||
} | ||
this._addToRootEntityList(index, entity); | ||
Entity._addToChildren(this._rootEntities, entity, index); | ||
} else if (!isRoot) { | ||
this._addToRootEntityList(index, entity); | ||
Entity._addToChildren(this._rootEntities, entity, index); | ||
} | ||
|
||
// Process entity active/inActive | ||
|
@@ -375,9 +375,8 @@ | |
*/ | ||
removeRootEntity(entity: Entity): void { | ||
if (entity._isRoot && entity._scene == this) { | ||
this._removeFromEntityList(entity); | ||
Entity._removeFormChildren(this._rootEntities, entity); | ||
entity._isRoot = false; | ||
|
||
let inActiveChangeFlag = ActiveChangeFlag.None; | ||
this._isActiveInEngine && entity._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy); | ||
entity._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene); | ||
|
@@ -494,19 +493,6 @@ | |
); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
_removeFromEntityList(entity: Entity): void { | ||
const rootEntities = this._rootEntities; | ||
let index = entity._siblingIndex; | ||
rootEntities.splice(index, 1); | ||
for (let n = rootEntities.length; index < n; index++) { | ||
rootEntities[index]._siblingIndex--; | ||
} | ||
entity._siblingIndex = -1; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
|
@@ -530,24 +516,6 @@ | |
allCreatedScenes.splice(allCreatedScenes.indexOf(this), 1); | ||
} | ||
|
||
private _addToRootEntityList(index: number, rootEntity: Entity): void { | ||
const rootEntities = this._rootEntities; | ||
const rootEntityCount = rootEntities.length; | ||
if (index === undefined) { | ||
rootEntity._siblingIndex = rootEntityCount; | ||
rootEntities.push(rootEntity); | ||
} else { | ||
if (index < 0 || index > rootEntityCount) { | ||
throw `The index ${index} is out of child list bounds ${rootEntityCount}`; | ||
} | ||
rootEntity._siblingIndex = index; | ||
rootEntities.splice(index, 0, rootEntity); | ||
for (let i = index + 1, n = rootEntityCount + 1; i < n; i++) { | ||
rootEntities[i]._siblingIndex++; | ||
} | ||
} | ||
} | ||
|
||
private _computeLinearFogParams(fogStart: number, fogEnd: number): void { | ||
const fogRange = fogEnd - fogStart; | ||
const fogParams = this._fogParams; | ||
|
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.
Fix typo in method name.
The method name has a typo:
_removeFormChildren
should be_removeFromChildren
.Apply this diff to fix the typo:
Note: This change will require updating all references to this method.
📝 Committable suggestion