package NET.worlds.scape; import NET.worlds.console.Main; import NET.worlds.core.IniFile; import NET.worlds.network.Cache; import NET.worlds.network.CacheFile; import NET.worlds.network.URL; import java.util.Observable; import java.util.Observer; class BackgroundLoaderElement implements Observer { private BGLoaded object; private Object arg; private URL url; private Room room; private boolean inAllRooms; private CacheFile rfile; private static boolean immedLoadLocals = IniFile.gamma().getIniInt("BackgroundLoadLocalFiles", 0) == 0; BackgroundLoaderElement(BGLoaded object, URL url, boolean inAllRooms) { boolean isMain = Main.isMainThread(); this.object = object; this.url = url; if (inAllRooms) { this.inAllRooms = true; } else { this.getRoom(isMain); } this.read(isMain); } @Override public void update(Observable o, Object url) { BackgroundLoader.asyncLoad(this); } private void read(boolean isMain) { this.rfile = this.url != null && this.url.isRemote() ? Cache.getFile(this.url) : null; if ((this.rfile == null || this.rfile.done()) && immedLoadLocals) { this.asyncLoad(); if (!isMain || this.syncLoad()) { BackgroundLoader.syncLoad(this); } } else if (this.rfile == null) { BackgroundLoader.asyncLoad(this); } else { this.rfile.callWhenLoaded(this); } } void asyncLoad() { String name; if (this.rfile == null) { name = this.url.unalias(); } else { name = this.rfile.getLocalName(); } this.arg = this.object.asyncBackgroundLoad(name, this.url); } boolean syncLoad() { if (this.object.syncBackgroundLoad(this.arg, this.url)) { return true; } else { if (this.rfile != null) { this.rfile.finalize(); this.rfile = null; } return false; } } boolean inAllRooms() { return this.inAllRooms; } Room getRoom(boolean isMainThread) { if (this.room == null && !this.inAllRooms && isMainThread) { this.room = this.object.getBackgroundLoadRoom(); } return this.room; } }