|
1 | 1 | package org.embeddedt.modernfix.world.gen; |
2 | 2 |
|
3 | | -import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; |
4 | 3 | import it.unimi.dsi.fastutil.objects.Reference2ObjectMaps; |
5 | 4 | import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; |
6 | 5 | import net.minecraft.core.Holder; |
@@ -58,32 +57,49 @@ public static SurfaceRules.RuleSource optimizeSequenceRuleSource(SurfaceRules.Se |
58 | 57 | noMatchSources.add(innerSource); |
59 | 58 | } |
60 | 59 | } |
61 | | - return new OptimizedBiomeLookupSequenceRule(perBiomeSources, List.copyOf(noMatchSources)); |
| 60 | + @SuppressWarnings("unchecked") |
| 61 | + ResourceKey<Biome>[] biomeKeys = new ResourceKey[perBiomeSources.size()]; |
| 62 | + SurfaceRules.RuleSource[][] sourcesPerBiome = new SurfaceRules.RuleSource[perBiomeSources.size()][]; |
| 63 | + int i = 0; |
| 64 | + for (var entry : Reference2ObjectMaps.fastIterable(perBiomeSources)) { |
| 65 | + biomeKeys[i] = entry.getKey(); |
| 66 | + sourcesPerBiome[i] = entry.getValue().toArray(new SurfaceRules.RuleSource[0]); |
| 67 | + i++; |
| 68 | + } |
| 69 | + return new OptimizedBiomeLookupSequenceRule(biomeKeys, sourcesPerBiome, noMatchSources.toArray(new SurfaceRules.RuleSource[0])); |
62 | 70 | } |
63 | 71 |
|
64 | 72 | public record OptimizedBiomeLookupSequenceRule( |
65 | | - Reference2ObjectMap<ResourceKey<Biome>, List<SurfaceRules.RuleSource>> sourcesForBiomeMatch, |
66 | | - List<SurfaceRules.RuleSource> sourcesForNoBiomeMatch |
| 73 | + ResourceKey<Biome>[] biomeKeys, |
| 74 | + SurfaceRules.RuleSource[][] sourcesPerBiome, |
| 75 | + SurfaceRules.RuleSource[] sourcesForNoBiomeMatch |
67 | 76 | ) implements SurfaceRules.RuleSource { |
68 | 77 | @Override |
69 | 78 | public SurfaceRules.SurfaceRule apply(SurfaceRules.Context context) { |
70 | | - var sourcesForBiomeMatch = this.sourcesForBiomeMatch; |
| 79 | + var biomeKeys = this.biomeKeys; |
| 80 | + var sourcesPerBiome = this.sourcesPerBiome; |
71 | 81 | Reference2ObjectOpenHashMap<ResourceKey<Biome>, List<SurfaceRules.SurfaceRule>> compiledBiomeMatch = |
72 | | - new Reference2ObjectOpenHashMap<>(sourcesForBiomeMatch.size()); |
73 | | - Reference2ObjectMaps.fastForEach(sourcesForBiomeMatch, entry -> { |
74 | | - SurfaceRules.SurfaceRule[] compiled = new SurfaceRules.SurfaceRule[entry.getValue().size()]; |
75 | | - var uncompiled = entry.getValue(); |
76 | | - for (int i = 0; i < uncompiled.size(); i++) { |
77 | | - compiled[i] = uncompiled.get(i).apply(context); |
| 82 | + new Reference2ObjectOpenHashMap<>(biomeKeys.length); |
| 83 | + for (int i = 0; i < biomeKeys.length; i++) { |
| 84 | + var uncompiled = sourcesPerBiome[i]; |
| 85 | + SurfaceRules.SurfaceRule[] compiled = new SurfaceRules.SurfaceRule[uncompiled.length]; |
| 86 | + for (int j = 0; j < uncompiled.length; j++) { |
| 87 | + compiled[j] = uncompiled[j].apply(context); |
78 | 88 | } |
79 | | - compiledBiomeMatch.put(entry.getKey(), List.of(compiled)); |
80 | | - }); |
| 89 | + compiledBiomeMatch.put(biomeKeys[i], List.of(compiled)); |
| 90 | + } |
81 | 91 | var sourcesForNoBiomeMatch = this.sourcesForNoBiomeMatch; |
82 | | - SurfaceRules.SurfaceRule[] compiledNoMatch = new SurfaceRules.SurfaceRule[sourcesForNoBiomeMatch.size()]; |
83 | | - for (int i = 0; i < sourcesForNoBiomeMatch.size(); i++) { |
84 | | - compiledNoMatch[i] = sourcesForNoBiomeMatch.get(i).apply(context); |
| 92 | + List<SurfaceRules.SurfaceRule> compiledNoMatchList; |
| 93 | + if (sourcesForNoBiomeMatch.length > 0) { |
| 94 | + SurfaceRules.SurfaceRule[] compiledNoMatch = new SurfaceRules.SurfaceRule[sourcesForNoBiomeMatch.length]; |
| 95 | + for (int i = 0; i < sourcesForNoBiomeMatch.length; i++) { |
| 96 | + compiledNoMatch[i] = sourcesForNoBiomeMatch[i].apply(context); |
| 97 | + } |
| 98 | + compiledNoMatchList = List.of(compiledNoMatch); |
| 99 | + } else { |
| 100 | + compiledNoMatchList = List.of(); |
85 | 101 | } |
86 | | - return new CompiledOptimizedBiomeLookupRule(compiledBiomeMatch, List.of(compiledNoMatch), context); |
| 102 | + return new CompiledOptimizedBiomeLookupRule(compiledBiomeMatch, compiledNoMatchList, context); |
87 | 103 | } |
88 | 104 |
|
89 | 105 | @Override |
|
0 commit comments