diff options
Diffstat (limited to 'NET/worlds/scape/BackgroundLoaderElement.java')
| -rw-r--r-- | NET/worlds/scape/BackgroundLoaderElement.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/NET/worlds/scape/BackgroundLoaderElement.java b/NET/worlds/scape/BackgroundLoaderElement.java new file mode 100644 index 0000000..aba150a --- /dev/null +++ b/NET/worlds/scape/BackgroundLoaderElement.java @@ -0,0 +1,87 @@ +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; + } +} |