diff --git a/src/main/java/toniarts/openkeeper/Main.java b/src/main/java/toniarts/openkeeper/Main.java index 11c7f4ca1..0c31be3b7 100644 --- a/src/main/java/toniarts/openkeeper/Main.java +++ b/src/main/java/toniarts/openkeeper/Main.java @@ -125,6 +125,7 @@ public static void main(String[] args) throws InvocationTargetException, Interru // set a better logging format System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tF %1$tT %4$s %2$s - %5$s%6$s%n"); + suppressMissingAssetWarnings(); // Finally start it if everything went ok if (checkSetup(app)) { @@ -134,6 +135,13 @@ public static void main(String[] args) throws InvocationTargetException, Interru } } + private static void suppressMissingAssetWarnings() { + java.util.logging.Logger assetManagerLogger = java.util.logging.Logger.getLogger(AssetManager.class.getName()); + java.util.logging.Filter existingFilter = assetManagerLogger.getFilter(); + assetManagerLogger.setFilter(record -> !"Cannot locate resource: {0}".equals(record.getMessage()) + && (existingFilter == null || existingFilter.isLoggable(record))); + } + /** * Parse application parameters * diff --git a/src/main/java/toniarts/openkeeper/utils/AssetUtils.java b/src/main/java/toniarts/openkeeper/utils/AssetUtils.java index 83176862c..357ddc86e 100644 --- a/src/main/java/toniarts/openkeeper/utils/AssetUtils.java +++ b/src/main/java/toniarts/openkeeper/utils/AssetUtils.java @@ -48,9 +48,9 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.function.Supplier; import javax.imageio.ImageIO; import toniarts.openkeeper.Main; @@ -75,7 +75,7 @@ public final class AssetUtils { private final static Object ASSET_LOCK = new Object(); private final static AssetCache ASSET_CACHE = new SimpleAssetCache(); private final static AssetCache WEAK_ASSET_CACHE = new WeakRefAssetCache(); - private final static Map TEXTURE_MAP_CACHE = new HashMap<>(); + private final static ConcurrentMap TEXTURE_MAP_CACHE = new ConcurrentHashMap<>(); // Custom model data keys public final static String USER_DATA_KEY_REMOVABLE = "Removable"; @@ -234,21 +234,19 @@ public static void assignMapsToMaterial(AssetManager assetManager, Material mate private static void assignMapToMaterial(AssetManager assetManager, Material material, String paramName, String textureName) { - // Try to locate the texture Boolean found = TEXTURE_MAP_CACHE.get(textureName); if (found == null) { - TextureKey textureKey = new TextureKey(textureName, false); - - // See if it exists - AssetInfo assetInfo = assetManager.locateAsset(textureKey); + AssetInfo assetInfo = assetManager.locateAsset(new TextureKey(textureName, false)); found = (assetInfo != null); - TEXTURE_MAP_CACHE.put(textureName, found); + Boolean cached = TEXTURE_MAP_CACHE.putIfAbsent(textureName, found); + if (cached != null) { + found = cached; + } } // Set it if (found) { - TextureKey textureKey = new TextureKey(textureName, false); - material.setTexture(paramName, assetManager.loadTexture(textureKey)); + material.setTexture(paramName, assetManager.loadTexture(new TextureKey(textureName, false))); } else { material.clearParam(paramName); }