Skip to content
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

Delete left-over Game Objects when changing LOD levels and when tiles… #2

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

mvriel
Copy link
Contributor

@mvriel mvriel commented Feb 29, 2024

… are destroyed before the Game Object was spawned

… are destroyed before the Game Object was spawned
@mvriel mvriel requested review from sambaas and mvangog February 29, 2024 15:59
else
if (tiles.TryGetValue(tileKey, out tile))
{
if (tile.gameObject) RemoveGameObject(tile.gameObject);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fix #1 where a prior gameobject will be cleaned up, for example when changing the LOD

else
{
// Tile was destroyed in the mean time.. destroy this game object too then.
RemoveGameObject(newGameobject);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fix #2 where we destroy the game object again when the tile cannot be found anymore; we can assume the Tile was removed while the Coroutine was running

@@ -185,6 +182,9 @@ private IEnumerator LoadMetaData(GameObject gameObject, string geometryUrl)

private void ReadMetaDataFile(byte[] results, GameObject gameobject)
{
// The gameobject could be destroyed in the mean time
if (!gameobject) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor fix #3, because of the other changes we now need to take into consideration the GameObject may be 'destroying' in the same frame; using the ! operator will also check the lifecycle of a gameobject and return true if it technically still exists but is in the process of destroying

//activeTiles = new List<Vector2Int>(layer.tiles.Keys);
var neededTiles = tileDistances[tilesizeIndex];

var neededTileKeys = new HashSet<Vector2Int>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance improvement: hashset lookups are O(1) where List lookups (using Contains) are O(n). This code is also simplified and will no longer use class-wide state for its internals

Copy link
Contributor

@TomSimons TomSimons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ziet er goed uit

@mvriel mvriel merged commit d0d0ec6 into main Mar 1, 2024
@mvriel mvriel deleted the fix/overlapping-buildings branch March 1, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants