summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/BackgroundLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/scape/BackgroundLoader.java')
-rw-r--r--NET/worlds/scape/BackgroundLoader.java239
1 files changed, 239 insertions, 0 deletions
diff --git a/NET/worlds/scape/BackgroundLoader.java b/NET/worlds/scape/BackgroundLoader.java
new file mode 100644
index 0000000..0f79ce1
--- /dev/null
+++ b/NET/worlds/scape/BackgroundLoader.java
@@ -0,0 +1,239 @@
+/* */ package NET.worlds.scape;
+/* */
+/* */ import NET.worlds.console.Main;
+/* */ import NET.worlds.console.MainCallback;
+/* */ import NET.worlds.network.URL;
+/* */ import java.util.Vector;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class BackgroundLoader
+/* */ implements MainCallback, Runnable
+/* */ {
+/* 90 */ private static BackgroundLoader bg = new BackgroundLoader();
+/* */
+/* */
+/* */
+/* 94 */ private BackgroundLoaderQueue asyncLoadQueue = new BackgroundLoaderQueue();
+/* */
+/* */
+/* 97 */ private Vector<BackgroundLoaderElement> syncLoadQueue = new Vector();
+/* */
+/* */
+/* */
+/* */
+/* */ private Thread asyncLoaderThread;
+/* */
+/* */
+/* */
+/* */
+/* */ public static void get(BGLoaded loader, String remoteName)
+/* */ {
+/* 109 */ get(loader, URL.make(remoteName), false);
+/* */ }
+/* */
+/* 112 */ public static void get(BGLoaded loader, URL remoteName) { get(loader, remoteName, false); }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public static void get(BGLoaded loader, URL remoteName, boolean highPri)
+/* */ {
+/* 122 */ new BackgroundLoaderElement(loader, remoteName, highPri);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ static void activeRoomChanged(Room room)
+/* */ {
+/* 133 */ bg.asyncLoadQueue.activeRoomChanged(room);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ static void asyncLoad(BackgroundLoaderElement ele)
+/* */ {
+/* 142 */ bg.asyncLoadQueue.add(ele);
+/* */ }
+/* */
+/* */ static void syncLoad(BackgroundLoaderElement ele) {
+/* 146 */ bg.syncLoadQueue.addElement(ele);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ private BackgroundLoader()
+/* */ {
+/* 154 */ this.asyncLoaderThread = new Thread(this);
+/* 155 */ this.asyncLoaderThread.setDaemon(true);
+/* 156 */ this.asyncLoaderThread.start();
+/* */
+/* 158 */ Main.register(this);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public void run()
+/* */ {
+/* 168 */ assert (Thread.currentThread() == this.asyncLoaderThread);
+/* */
+/* */
+/* */
+/* */
+/* */ for (;;)
+/* */ {
+/* 175 */ BackgroundLoaderElement ele = this.asyncLoadQueue.getItem();
+/* */
+/* */
+/* 178 */ ele.asyncLoad();
+/* */
+/* 180 */ synchronized (this)
+/* */ {
+/* */
+/* */
+/* */
+/* 185 */ this.syncLoadQueue.addElement(ele);
+/* 186 */ while (this.syncLoadQueue.size() > 0)
+/* */ {
+/* */ try {
+/* 189 */ wait();
+/* */ }
+/* */ catch (InterruptedException localInterruptedException) {}
+/* 192 */ if (this.asyncLoadQueue.hasHighPriorityItems())
+/* */ break;
+/* */ }
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* 199 */ int nextSync = 0;
+/* */
+/* */
+/* */
+/* */
+/* */ public synchronized void mainCallback()
+/* */ {
+/* 206 */ if (this.syncLoadQueue.size() == 0) {
+/* 207 */ return;
+/* */ }
+/* 209 */ if (this.nextSync >= this.syncLoadQueue.size()) {
+/* 210 */ this.nextSync = 0;
+/* */ }
+/* 212 */ BackgroundLoaderElement ele =
+/* 213 */ (BackgroundLoaderElement)this.syncLoadQueue.elementAt(this.nextSync);
+/* */
+/* */
+/* 216 */ if (!ele.syncLoad())
+/* */ {
+/* */
+/* 219 */ this.syncLoadQueue.removeElementAt(this.nextSync);
+/* */
+/* 221 */ if (this.syncLoadQueue.size() == 0) {
+/* 222 */ notify();
+/* */ }
+/* */ }
+/* */ else
+/* */ {
+/* 227 */ if (this.asyncLoadQueue.hasHighPriorityItems()) {
+/* 228 */ notify();
+/* */ }
+/* 230 */ this.nextSync += 1;
+/* */ }
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\BackgroundLoader.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file