Skip to content

Commit

Permalink
Merge pull request #1787 from petchema/throttled-unloadunusedassets
Browse files Browse the repository at this point in the history
Do not call Resources.UnloadUnusedAssets() more than once every 3 mins
  • Loading branch information
Interkarma committed Apr 20, 2020
2 parents d25190e + 8e9d499 commit 4e23d6e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Game/UserInterface/UserInterfaceWindow.cs
Expand Up @@ -128,7 +128,7 @@ public void CloseWindow()
{
uiManager.PopWindow();
RaiseOnCloseHandler();
Resources.UnloadUnusedAssets();
DaggerfallGC.ThrottledUnloadUnusedAssets();
}

public void PopWindow()
Expand Down
36 changes: 36 additions & 0 deletions Assets/Scripts/Internal/DaggerfallGC.cs
@@ -0,0 +1,36 @@
// Project: Daggerfall Tools For Unity
// Copyright: Copyright (C) 2009-2020 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Source Code: https://github.com/Interkarma/daggerfall-unity
// Original Author: Pango (petchema@concept-micro.com)
// Contributors:
//
// Notes:
//

using System;
using UnityEngine;

namespace DaggerfallWorkshop
{
public static class DaggerfallGC
{
// Min time between two unused assets collections
private const float uuaThrottleDelay = 180f;

private static float uuaTimer = Time.realtimeSinceStartup;

public static void ThrottledUnloadUnusedAssets()
{
if (Time.realtimeSinceStartup >= uuaTimer)
ForcedUnloadUnusedAssets();
}

public static void ForcedUnloadUnusedAssets()
{
Resources.UnloadUnusedAssets();
uuaTimer = Time.realtimeSinceStartup + uuaThrottleDelay;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Internal/DaggerfallGC.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Scripts/Terrain/StreamingWorld.cs
Expand Up @@ -659,7 +659,7 @@ private IEnumerator UpdateTerrains()
if (init)
{
DaggerfallUnity.Instance.MaterialReader.PruneCache();
Resources.UnloadUnusedAssets();
DaggerfallGC.ThrottledUnloadUnusedAssets();
}

// Set terrain neighbours
Expand Down

0 comments on commit 4e23d6e

Please sign in to comment.