mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-11-28 00:45:03 +00:00
perf: replace biome tag checks with bitset columns
This commit is contained in:
1 parent
6ddf039e49
commit
8a940f7e1f
45 files changed
+938
-314
No files matched your search
+34
@@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
||||
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.tag.BiomeTag;
|
||||
import com.dfsek.terra.api.world.biome.tag.BiomeTagIndex;
|
||||
|
||||
|
||||
public class BiomeTagLoader implements TypeLoader<BiomeTag> {
|
||||
private final BiomeTagIndex index;
|
||||
|
||||
public BiomeTagLoader(BiomeTagIndex index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeTag load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader, DepthTracker depthTracker)
|
||||
throws LoadException {
|
||||
if(!(c instanceof String name)) {
|
||||
throw new LoadException("expected a tag name, got " + describe(c), depthTracker);
|
||||
}
|
||||
return index.tag(name);
|
||||
}
|
||||
|
||||
private static String describe(Object value) {
|
||||
return value == null ? "null" : "type " + value.getClass().getCanonicalName();
|
||||
}
|
||||
}
|
||||
+14
@@ -73,8 +73,11 @@ import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.biome.tag.BiomeTag;
|
||||
import com.dfsek.terra.api.world.biome.tag.BiomeTagIndex;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.provider.ChunkGeneratorProvider;
|
||||
import com.dfsek.terra.config.loaders.BiomeTagLoader;
|
||||
import com.dfsek.terra.config.loaders.GenericTemplateSupplierLoader;
|
||||
import com.dfsek.terra.config.preprocessor.MetaListLikePreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaMapPreprocessor;
|
||||
@@ -106,6 +109,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
private final BiomeProvider seededBiomeProvider;
|
||||
|
||||
private final BiomeTagIndex biomeTagIndex = new BiomeTagIndex();
|
||||
|
||||
private final Map<Type, CheckedRegistryImpl<?>> registryMap = new HashMap<>();
|
||||
private final Map<Type, ShortcutHolder<?>> shortcuts = new HashMap<>();
|
||||
|
||||
@@ -148,6 +153,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
register(abstractConfigLoader);
|
||||
platform.register(abstractConfigLoader);
|
||||
|
||||
applyLoader(BiomeTag.class, new BiomeTagLoader(biomeTagIndex));
|
||||
|
||||
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
||||
selfLoader.load(addonsTemplate, packManifest);
|
||||
this.addons = addonsTemplate.getAddons();
|
||||
@@ -222,6 +229,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.load(packPostTemplate, packManifest);
|
||||
seededBiomeProvider =
|
||||
template.getBiomeCache() ? packPostTemplate.getProviderBuilder().caching(platform) : packPostTemplate.getProviderBuilder();
|
||||
// Must stay inside the constructor: generation threads read tag bitsets without volatile reads.
|
||||
biomeTagIndex.seal();
|
||||
checkDeadEntries();
|
||||
}
|
||||
|
||||
@@ -297,6 +306,11 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
return seededBiomeProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeTagIndex getBiomeTagIndex() {
|
||||
return biomeTagIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CheckedRegistry<T> getOrCreateRegistry(TypeKey<T> typeKey) {
|
||||
return (CheckedRegistry<T>) registryMap.computeIfAbsent(typeKey.getType(), c -> {
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.impl.MapConfiguration;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.tag.BiomeTagIndex;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
class BiomeTagLoaderTest {
|
||||
private final BiomeTagIndex index = new BiomeTagIndex();
|
||||
private final BiomeTagLoader loader = new BiomeTagLoader(index);
|
||||
|
||||
private static DepthTracker tracker() {
|
||||
return new DepthTracker(List.of(), new MapConfiguration(Map.of(), "biome.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonString() {
|
||||
LoadException e = assertThrows(LoadException.class, () -> loader.load((AnnotatedType) null, 42, null, tracker()));
|
||||
assertTrue(e.getMessage().contains("expected a tag name"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("type java.lang.Integer"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringInterns() throws LoadException {
|
||||
Object first = loader.load((AnnotatedType) null, "FOO", null, tracker());
|
||||
assertSame(first, loader.load((AnnotatedType) null, "FOO", null, tracker()));
|
||||
assertSame(index.tag("FOO"), first);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user