From 0376602894fdf60e5176e166237f029d2cb43af6 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 23 Mar 2016 14:00:48 +0000 Subject: [PATCH] Update TODO list, add pipeline cache --- README.md | 12 ++---------- pom.xml | 2 +- .../api/protocol/ProtocolRegistry.java | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7f9eecb66..294d58ab0 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,8 @@ This is an experimental branch, but soon to be live. - -The things which stop this from going live: - -Need to implement debug mode using deprecated PacketType for english - -and then javadocs. - - -It would be nice to have a Pipeline cache so it doesn't have to figure it out all the time. -(and to ensure it uses the shortest pipeline) +(The only issues would be really really complex protocol pipelines...) +(But I don't see them happening any time soon) License: -------- diff --git a/pom.xml b/pom.xml index 2be236da3..cda788d3a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion - 0.6.8-SNAPSHOT + 0.7.0-ALPHA jar ViaVersion diff --git a/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 1cac43b46..e6b459958 100644 --- a/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -10,6 +10,7 @@ public class ProtocolRegistry { public static int SERVER_PROTOCOL = -1; // Input Version -> Output Version & Protocol (Allows fast lookup) private static Map> registryMap = new HashMap<>(); + private static Map, List>> pathCache = new HashMap<>(); static { // Register built in protocols @@ -25,6 +26,10 @@ public class ProtocolRegistry { * @param output The output server version it converts to. */ public static void registerProtocol(Protocol protocol, List supported, Integer output) { + // Clear cache as this may make new routes. + if (pathCache.size() > 0) + pathCache.clear(); + for (Integer version : supported) { if (!registryMap.containsKey(version)) { registryMap.put(version, new HashMap()); @@ -97,7 +102,17 @@ public class ProtocolRegistry { * @return The path it generated, null if it failed. */ public static List> getProtocolPath(int clientVersion, int serverVersion) { - // TODO: Cache - return getProtocolPath(new ArrayList>(), clientVersion, serverVersion); + Pair protocolKey = new Pair<>(clientVersion, serverVersion); + // Check cache + if (pathCache.containsKey(protocolKey)) { + return pathCache.get(protocolKey); + } + // Generate path + List> outputPath = getProtocolPath(new ArrayList>(), clientVersion, serverVersion); + // If it found a path, cache it. + if (outputPath != null) { + pathCache.put(protocolKey, outputPath); + } + return outputPath; } }