From f64c059f265435fd0c1df99c19ba3f9f0f650023 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 8 Feb 2023 09:27:46 -0500 Subject: [PATCH] Color map built after realms loaded. --- src/engine/InterestManagement/RealmMap.java | 9 +++++++-- src/engine/objects/Realm.java | 3 +-- src/engine/server/world/WorldServer.java | 7 +++---- src/engine/util/MapLoader.java | 17 ++++------------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/engine/InterestManagement/RealmMap.java b/src/engine/InterestManagement/RealmMap.java index d9ef12e5..eda74ef8 100644 --- a/src/engine/InterestManagement/RealmMap.java +++ b/src/engine/InterestManagement/RealmMap.java @@ -52,8 +52,7 @@ public enum RealmMap { if (yBuckets < 0 || yBuckets >= MBServerStatics.SPATIAL_HASH_BUCKETSY || xBuckets < 0 || xBuckets >= MBServerStatics.SPATIAL_HASH_BUCKETSX) { - Logger.error("WorldServerRealm.getRealmFromPosition", - "Invalid range; Z: " + yBuckets + ", X: " + xBuckets); + Logger.error("Invalid range; Z: " + yBuckets + ", X: " + xBuckets); return 255; } @@ -110,6 +109,12 @@ public enum RealmMap { public static void loadRealmImageMap() { + // Build color lookup map for realms from database + + for (Realm realm : Realm._realms.values()) { + RealmMap.addToColorMap(realm.mapColor, realm.realmID); + } + RealmMap._realmImageMap = MapLoader.loadMap(); } diff --git a/src/engine/objects/Realm.java b/src/engine/objects/Realm.java index 55133a12..b2f7e22b 100644 --- a/src/engine/objects/Realm.java +++ b/src/engine/objects/Realm.java @@ -65,7 +65,7 @@ public class Realm { private final int stretchY; private final int locX; private final int locY; - private final int realmID; + public final int realmID; private final HashSet cities = new HashSet<>(); private String hash; @@ -204,7 +204,6 @@ public class Realm { public static void configureAllRealms() { for (Realm realm : Realm._realms.values()) { - RealmMap.addToColorMap(realm.mapColor, realm.realmID); realm.configure(); } } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 8e287c10..0e663827 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -326,6 +326,9 @@ public class WorldServer { Logger.info("Loading Realms"); Realm.loadAllRealms(); + Logger.info("Loading RealmMap"); + RealmMap.loadRealmImageMap(); + Logger.info("Loading Kits"); DbManager.KitQueries.GET_ALL_KITS(); @@ -334,10 +337,6 @@ public class WorldServer { Logger.info("Starting InterestManager."); WorldGrid.startLoadJob(); - - - Logger.info("Loading Spaital Hash"); - RealmMap.loadRealmImageMap(); DbManager.MobBaseQueries.SET_AI_DEFAULTS(); diff --git a/src/engine/util/MapLoader.java b/src/engine/util/MapLoader.java index aec069b8..cdc1b503 100644 --- a/src/engine/util/MapLoader.java +++ b/src/engine/util/MapLoader.java @@ -26,8 +26,7 @@ public enum MapLoader { long timeToLoad = System.currentTimeMillis(); long bytesRead = 0; long realmsWritten = 0; - - Integer realmUUID = null; + int realmUUID; // Load image from disk @@ -54,20 +53,14 @@ public enum MapLoader { try { int rgb = image.getRGB(j, i); realmUUID = RealmMap.getRealmIDByRGB(rgb); - - if (realmUUID == null) { - Logger.error("Corrupted png: unknown color " + rgb); - WorldServer.shutdown(); - } - realmMap[j][i] = realmUUID.intValue(); + realmMap[j][i] = realmUUID; bytesRead++; - if (realmUUID.intValue() != 0) + if (realmUUID != 0) realmsWritten++; }catch (Exception e){ - // Logger.error("REALMEDIT ERROR", e.getMessage()); continue; } @@ -76,9 +69,7 @@ public enum MapLoader { } timeToLoad = System.currentTimeMillis() - timeToLoad; - Logger.info( bytesRead + " pixels processed in " + timeToLoad / 1000 + " seconds"); - Logger.info("Realm pixels written : " + realmsWritten); - image = null; + Logger.info( bytesRead + "Realm imageMNap pixels processed in " + timeToLoad / 1000 + " seconds"); return realmMap; }