Skip to content

Commit 78645c3

Browse files
committed
- Fix NPE in CachedRGBFontRenderer#L55.
- ResourceExistStateCache now no longer works on all states. - StitcherCache now cleans up its own memory when it finishes loading. - Improved keySet() performance of BlockPos2ValueMap.
1 parent 98d5d6c commit 78645c3

25 files changed

+376
-259
lines changed

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212

1313
// Project properties
1414
group = "github.kasuminova.stellarcore"
15-
version = "1.2.1"
15+
version = "1.3.0"
1616

1717
// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
1818
java {
@@ -278,6 +278,8 @@ dependencies {
278278
compileOnly(rfg.deobf("curse.maven:random-psideas-302313:3215550"))
279279
compileOnly(rfg.deobf("curse.maven:journeymap-32274:5172461"))
280280
compileOnly(rfg.deobf("curse.maven:abyssalcraft-53686:5330323"))
281+
compileOnly(rfg.deobf("curse.maven:vintagefix-871198:5536276"))
282+
compileOnly(rfg.deobf("curse.maven:lolasm-460609:5257348"))
281283
}
282284

283285
// IDE Settings

src/main/java/github/kasuminova/stellarcore/client/gui/font/CachedRGBFontRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static List<String> mapListedString(List<String> listed, LinkedList<Strin
5252
final char ch = charArray[j];
5353
mapping.append(ch);
5454

55-
String strFirst = strList.getFirst();
55+
String strFirst = strList.peekFirst();
5656
if (strFirst == null || colors.getFirst() == null) {
5757
sb.append(ch);
5858
continue;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package github.kasuminova.stellarcore.client.model;
2+
3+
import github.kasuminova.stellarcore.mixin.util.ConcurrentModelLoaderRegistry;
4+
5+
public class ModelLoaderRegistryRef {
6+
7+
public static ConcurrentModelLoaderRegistry instance = null;
8+
9+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package github.kasuminova.stellarcore.client.resource;
2+
3+
import github.kasuminova.stellarcore.mixin.util.StellarCoreResourcePack;
4+
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
5+
6+
import java.util.Set;
7+
8+
public class ResourceExistingCache {
9+
10+
private static final Set<StellarCoreResourcePack> RESOURCE_PACKS = new ReferenceOpenHashSet<>();
11+
12+
public static void addResourcePack(StellarCoreResourcePack resourcePack) {
13+
RESOURCE_PACKS.add(resourcePack);
14+
resourcePack.stellar_core$onReload();
15+
}
16+
17+
public static void clear() {
18+
RESOURCE_PACKS.forEach(StellarCoreResourcePack::stellar_core$disableCache);
19+
RESOURCE_PACKS.clear();
20+
}
21+
22+
public static void enableCache() {
23+
RESOURCE_PACKS.forEach(StellarCoreResourcePack::stellar_core$enableCache);
24+
}
25+
26+
public static void disableCache() {
27+
RESOURCE_PACKS.forEach(StellarCoreResourcePack::stellar_core$disableCache);
28+
}
29+
30+
}

src/main/java/github/kasuminova/stellarcore/client/texture/StitcherCache.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ public void cache(Set<Stitcher.Holder> holders, List<Stitcher.Slot> slots, int w
181181
this.height = height;
182182
this.cacheState = State.AVAILABLE;
183183
}
184+
185+
public void clear() {
186+
this.holders.clear();
187+
this.slots.clear();
188+
this.readTag = null;
189+
this.width = 0;
190+
this.height = 0;
191+
this.cacheState = State.UNKNOWN;
192+
}
184193

185194
public String getName() {
186195
return name;

src/main/java/github/kasuminova/stellarcore/common/config/StellarCoreConfig.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,16 @@ public static class Vanilla {
598598
@Config.Name("ParallelModelLoader")
599599
public boolean parallelModelLoader = true;
600600

601+
@Config.Comment({
602+
"(Client Performance) Clearing the cache after loading a model, significantly reduce memory usage.",
603+
"But it may cause some mod's models to be messed up after reloading ResourcePacks,",
604+
"Turning this option off will use more memory.",
605+
"If you installed FoamFix, FoamFix does the same thing but StellarCore is faster, you may need to turn off the `wipeModelCache` option in foamfix.cfg."
606+
})
607+
@Config.RequiresMcRestart
608+
@Config.Name("WipeModelCache")
609+
public boolean wipeModelCache = true;
610+
601611
@Config.Comment({
602612
"Defining which ModelLoader cannot be safely asynchronized to allow StellarCore to load models",
603613
"using a synchronous approach, usually requires no modification to it."
@@ -664,14 +674,11 @@ public static class Vanilla {
664674

665675
@Config.Comment({
666676
"(Client Performance) Caches the state of existence of each resource file in the ResourcePack,",
667-
"avoiding the use of the resourceExists method with its excessive overhead to improve game loading performance.",
668-
"Effective in large ModPacks and optimises the impact on startup time when installing with Optifine, with good compatibility.",
669-
"If you encounter some resources that don't load properly (which they usually don't), reload the resource packs, this will reset the cache.",
670-
"Incompatible with GroovyScript, and I don't know why."
677+
"improve the speed of model loading, if you encounter the game can not be loaded or display anomaly, turn off this option."
671678
})
672679
@Config.RequiresMcRestart
673680
@Config.Name("ResourceExistStateCache")
674-
public boolean resourceExistStateCache = false;
681+
public boolean resourceExistStateCache = true;
675682

676683
}
677684

src/main/java/github/kasuminova/stellarcore/common/util/BlockPos2ValueMap.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import javax.annotation.Nonnull;
99
import java.util.*;
10-
import java.util.stream.Collectors;
1110

1211
public class BlockPos2ValueMap<V> implements Map<BlockPos, V> {
1312

1413
protected final Long2ObjectMap<V> internal = new Long2ObjectLinkedOpenHashMap<>();
1514
protected EntrySet entrySet = null;
15+
protected KeySet keySet = null;
1616

1717
@Override
1818
public int size() {
@@ -71,7 +71,7 @@ public void clear() {
7171
@Nonnull
7272
@Override
7373
public Set<BlockPos> keySet() {
74-
return internal.keySet().stream().map(BlockPos::fromLong).collect(Collectors.toSet());
74+
return keySet == null ? keySet = new KeySet() : keySet;
7575
}
7676

7777
@Nonnull
@@ -117,6 +117,21 @@ public Iterator<Map.Entry<BlockPos, V>> iterator() {
117117
}
118118
}
119119

120+
public class KeySet extends AbstractSet<BlockPos> {
121+
122+
@Nonnull
123+
@Override
124+
public Iterator<BlockPos> iterator() {
125+
return Iterators.transform(entrySet().iterator(), Map.Entry::getKey);
126+
}
127+
128+
@Override
129+
public int size() {
130+
return internal.size();
131+
}
132+
133+
}
134+
120135
public static class Entry<V> implements Map.Entry<BlockPos, V> {
121136
private final Long2ObjectMap.Entry<V> parent;
122137

src/main/java/github/kasuminova/stellarcore/mixin/minecraft/forge/parallelmodelloader/AccessorForgeBlockStateV1.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/github/kasuminova/stellarcore/mixin/minecraft/forge/parallelmodelloader/AccessorForgeBlockStateV1Variant.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/github/kasuminova/stellarcore/mixin/minecraft/forge/parallelmodelloader/MixinBlockStateLoader.java

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)