summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/BackgroundLoaderElement.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/BackgroundLoaderElement.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/BackgroundLoaderElement.java')
-rw-r--r--NET/worlds/scape/BackgroundLoaderElement.java87
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;
+ }
+}