mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-31 04:46:37 +00:00
缓存清理
This commit is contained in:
@@ -313,6 +313,14 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
this.pendingConfigSections.add(section);
|
||||
}
|
||||
|
||||
public IdAllocator internalIdAllocator() {
|
||||
return internalIdAllocator;
|
||||
}
|
||||
|
||||
public VisualBlockStateAllocator visualBlockStateAllocator() {
|
||||
return visualBlockStateAllocator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcess() {
|
||||
this.internalIdAllocator.processPendingAllocations();
|
||||
@@ -514,7 +522,7 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
}
|
||||
}
|
||||
|
||||
CompletableFutures.allOf(futureVisualStates.values()).whenComplete((v2, t2) -> {
|
||||
CompletableFutures.allOf(futureVisualStates.values()).whenComplete((v2, t2) -> ResourceConfigUtils.runCatching(path, node, () -> {
|
||||
if (t2 != null) {
|
||||
if (t2 instanceof CompletionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
@@ -635,7 +643,7 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
|
||||
// 抛出次要警告
|
||||
exceptionCollector.throwIfPresent();
|
||||
});
|
||||
}, () -> GsonHelper.get().toJson(section)));
|
||||
}, () -> GsonHelper.get().toJson(section)));
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class AbstractFontManager implements FontManager {
|
||||
private final CraftEngine plugin;
|
||||
@@ -511,10 +512,6 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
});
|
||||
}
|
||||
|
||||
public Map<Key, IdAllocator> idAllocators() {
|
||||
return this.idAllocators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseSection(Pack pack, Path path, String node, Key id, Map<String, Object> section) {
|
||||
if (AbstractFontManager.this.images.containsKey(id)) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.momirealms.craftengine.core.pack.allocator;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
@@ -15,6 +17,7 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class VisualBlockStateAllocator {
|
||||
private final Path cacheFilePath;
|
||||
@@ -32,7 +35,9 @@ public class VisualBlockStateAllocator {
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
Arrays.fill(this.pendingAllocationFutures, new ArrayList<>());
|
||||
for (int i = 0; i < this.pendingAllocationFutures.length; i++) {
|
||||
this.pendingAllocationFutures[i] = new ArrayList<>();
|
||||
}
|
||||
this.cachedBlockStates.clear();
|
||||
this.pendingAllocations.clear();
|
||||
}
|
||||
@@ -53,6 +58,19 @@ public class VisualBlockStateAllocator {
|
||||
return future;
|
||||
}
|
||||
|
||||
public List<String> cleanupUnusedIds(Predicate<BlockStateWrapper> shouldRemove) {
|
||||
List<String> idsToRemove = new ArrayList<>();
|
||||
for (Map.Entry<String, BlockStateWrapper> entry : this.cachedBlockStates.entrySet()) {
|
||||
if (shouldRemove.test(entry.getValue())) {
|
||||
idsToRemove.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
for (String id : idsToRemove) {
|
||||
this.cachedBlockStates.remove(id);
|
||||
}
|
||||
return idsToRemove;
|
||||
}
|
||||
|
||||
public void processPendingAllocations() {
|
||||
// 先处理缓存的
|
||||
for (Map.Entry<String, BlockStateWrapper> entry : this.cachedBlockStates.entrySet()) {
|
||||
@@ -64,12 +82,17 @@ public class VisualBlockStateAllocator {
|
||||
if (!candidate.isUsed()) {
|
||||
// 获取当前的安排任务
|
||||
Pair<AutoStateGroup, CompletableFuture<BlockStateWrapper>> pair = this.pendingAllocations.get(entry.getKey());
|
||||
// 如果候选满足组,那么直接允许起飞
|
||||
if (pair != null && pair.left().test(candidate.blockState())) {
|
||||
pair.right().complete(candidate.blockState());
|
||||
if (pair != null) {
|
||||
// 如果候选满足组,那么直接允许起飞
|
||||
if (pair.left().test(candidate.blockState())) {
|
||||
pair.right().complete(candidate.blockState());
|
||||
} else {
|
||||
// 不满足候选组要求,那就等着分配新的吧
|
||||
}
|
||||
} else {
|
||||
// 尽管未被使用,该槽位也应该被占用,以避免被自动分配到
|
||||
candidate.setUsed();
|
||||
}
|
||||
// 尽管未被使用,该槽位也应该被占用,以避免被自动分配到
|
||||
candidate.setUsed();
|
||||
}
|
||||
// 被使用了就随他去
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user