Skip to content

Commit e43f745

Browse files
committed
Fix existsSpecific cache with source
1 parent 6fd77dc commit e43f745

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

source/funkin/backend/assets/AssetsLibraryList.hx

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ class AssetsLibraryList extends AssetLibrary {
3232
public var transLib:TranslatedAssetLibrary;
3333
#end
3434

35-
private var cacheLibraryTypePaths:Map<Null<String>, Map<String, AssetLibrary>> = [];
36-
private var cacheTimeTypePaths:Map<Null<String>, Map<String, Float>> = [];
37-
3835
public function removeLibrary(lib:AssetLibrary) {
3936
if (lib != null) {
4037
libraries.remove(lib);
@@ -56,44 +53,51 @@ class AssetsLibraryList extends AssetLibrary {
5653
return lib;
5754
}
5855

56+
var existsSpecificCacheLibrary:Map<AssetSource, Map<Null<String>, Map<String, AssetLibrary>>> = [];
57+
var existsSpecificCacheTime:Map<AssetSource, Map<Null<String>, Map<String, Float>>> = [];
58+
5959
public function existsSpecific(id:String, type:String, source:AssetSource = BOTH) {
6060
if (!id.startsWith("assets/") && existsSpecific('assets/$id', type, source))
6161
return true;
6262

63-
// Prevent massive lags on repetitive usage
64-
final sec = haxe.Timer.stamp();
63+
// Prevent massive lags on repetitive usage, primarily with getting note sprite sheets in mania charts (usually 2k+ notes)
64+
final time = haxe.Timer.stamp();
65+
66+
var cacheLibraryTypes = existsSpecificCacheLibrary.get(source), cacheTimeTypes = existsSpecificCacheTime.get(source);
67+
if (cacheLibraryTypes == null) {
68+
existsSpecificCacheLibrary.set(source, cacheLibraryTypes = []);
69+
existsSpecificCacheTime.set(source, cacheTimeTypes = []);
70+
}
6571

66-
var cacheLibraryPaths:Map<String, AssetLibrary> = cacheLibraryTypePaths.get(type);
67-
var cacheTimePaths:Map<String, Float> = cacheTimeTypePaths.get(type);
72+
var cacheLibraryPaths = cacheLibraryTypes.get(type), cacheTimePaths = cacheTimeTypes.get(type);
6873
if (cacheLibraryPaths == null) {
69-
cacheLibraryTypePaths.set(type, cacheLibraryPaths = []);
70-
cacheTimeTypePaths.set(type, cacheTimePaths = []);
74+
cacheLibraryTypes.set(type, cacheLibraryPaths = []);
75+
cacheTimeTypes.set(type, cacheTimePaths = []);
7176
}
7277

7378
if (cacheTimePaths.exists(id)) {
74-
final cacheSafetime = cacheTimePaths.get(id) + 6;
75-
if (cacheLibraryPaths.exists(id)) {
76-
if (sec < cacheSafetime) return true;
77-
else if (cacheLibraryPaths.get(id).exists(id, type)) {
78-
cacheTimePaths.set(id, sec);
79+
final cacheSafeTime = cacheTimePaths.get(id) + 6, library = cacheLibraryPaths.get(id);
80+
if (library != null) {
81+
if (time < cacheSafeTime) return true;
82+
else if (shouldSkipLib(library, source)) {/*do nothing*/}
83+
else if (library.exists(id, type)) {
84+
cacheTimePaths.set(id, time);
7985
return true;
8086
}
8187

8288
cacheLibraryPaths.remove(id);
8389
}
84-
else if (sec < cacheSafetime) {
90+
else if (time < cacheSafeTime) {
8591
return false;
8692
}
87-
88-
//cacheTimePaths.remove(id);
8993
}
9094

91-
cacheTimePaths.set(id, sec);
95+
cacheTimePaths.set(id, time);
9296

93-
for (k=>l in libraries) {
94-
if (shouldSkipLib(l, source)) continue;
95-
if (l.exists(id, type)) {
96-
cacheLibraryPaths.set(id, l);
97+
for (library in libraries) {
98+
if (shouldSkipLib(library, source)) continue;
99+
if (library.exists(id, type)) {
100+
cacheLibraryPaths.set(id, library);
97101
return true;
98102
}
99103
}

0 commit comments

Comments
 (0)