summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Texture.java
blob: 9850a380edd5d1e033f0d81cf8e6af31ae8c7559 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package NET.worlds.scape;

import NET.worlds.network.URL;
import java.io.IOException;
import java.net.MalformedURLException;

public abstract class Texture implements Persister {
   protected int textureID = 0;
   int refs = 1;
   private static Object classCookie = new Object();

   static {
      nativeInit();
   }

   protected Texture() {
   }

   public static native void nativeInit();

   private static native int nativeGetW(int var0);

   public int getW() {
      return nativeGetW(this.textureID);
   }

   private static native int nativeGetH(int var0);

   public int getH() {
      return nativeGetH(this.textureID);
   }

   public URL getURL() {
      URL u = null;
      String s = this.getName();
      if (s != null) {
         try {
            u = new URL(URL.getCurDir(), s);
         } catch (MalformedURLException var4) {
         }
      }

      return u;
   }

   public void incRef() {
      assert this.refs > 0;

      if (this.textureID != 0) {
         this.refs++;
      }
   }

   public void copyFrom(int dc, int x1, int x2, int y1, int y2) {
      assert this.textureID != 0;

      nativeCopyFrom(this.textureID, dc, x1, x2, y1, y2);
   }

   private static native void nativeCopyFrom(int var0, int var1, int var2, int var3, int var4, int var5);

   private static native void nativeRelease(int var0);

   public synchronized void decRef() {
      if (--this.refs <= 0 && this.textureID != 0) {
         nativeRelease(this.textureID);
         this.textureID = 0;
      }
   }

   @Override
   protected void finalize() {
      if (this.refs > 0) {
         this.refs = 1;
         this.decRef();
         this.refs = 1000000;
      }
   }

   protected String getName() {
      return null;
   }

   @Override
   public void saveState(Saver s) throws IOException {
      s.saveVersion(0, classCookie);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      switch (r.restoreVersion(classCookie)) {
         case 0:
            return;
         default:
            throw new TooNewException();
      }
   }

   @Override
   public void postRestore(int version) {
   }
}