Stan Hebben преди 6 години
родител
ревизия
da051f56ce

+ 13
- 6
Shared/src/main/java/compactio/CompactBytesDataInput.java Целия файл

4
 import java.util.Arrays;
4
 import java.util.Arrays;
5
 
5
 
6
 public final class CompactBytesDataInput implements CompactDataInput, AutoCloseable {
6
 public final class CompactBytesDataInput implements CompactDataInput, AutoCloseable {
7
+    private static final int P6 = 1 << 6;
7
     private static final int P7 = 1 << 7;
8
     private static final int P7 = 1 << 7;
9
+    private static final int P13 = 1 << 13;
8
     private static final int P14 = 1 << 14;
10
     private static final int P14 = 1 << 14;
11
+    private static final int P20 = 1 << 20;
9
     private static final int P21 = 1 << 21;
12
     private static final int P21 = 1 << 21;
13
+    private static final int P27 = 1 << 27;
10
     private static final int P28 = 1 << 28;
14
     private static final int P28 = 1 << 28;
15
+    private static final long P34 = 1L << 34;
11
     private static final long P35 = 1L << 35;
16
     private static final long P35 = 1L << 35;
17
+    private static final long P41 = 1L << 41;
12
     private static final long P42 = 1L << 42;
18
     private static final long P42 = 1L << 42;
19
+    private static final long P48 = 1L << 48;
13
     private static final long P49 = 1L << 49;
20
     private static final long P49 = 1L << 49;
21
+    private static final long P55 = 1L << 55;
14
     private static final long P56 = 1L << 56;
22
     private static final long P56 = 1L << 56;
15
-	
16
     private final byte[] data;
23
     private final byte[] data;
17
     private int offset;
24
     private int offset;
18
     
25
     
86
     @Override
93
     @Override
87
     public int readVarInt() {
94
     public int readVarInt() {
88
         int value = this.readVarUInt();
95
         int value = this.readVarUInt();
89
-        return Integer.compareUnsigned(value & 1, 0) == 0 ? value >>> 1 : -((value >>> 1) + 1);
96
+        return (value & 1) == 0 ? value >>> 1 : -((value >>> 1) + 1);
90
     }
97
     }
91
     
98
     
92
     @Override
99
     @Override
93
     public int readVarUInt() {
100
     public int readVarUInt() {
94
         int value = data[offset++] & 0xFF;
101
         int value = data[offset++] & 0xFF;
95
-        if (Integer.compareUnsigned(value & CompactBytesDataInput.P7, 0) == 0)
102
+        if ((value & CompactBytesDataInput.P7) == 0)
96
             return value;
103
             return value;
97
         value = value & CompactBytesDataInput.P7 - 1 | (data[offset++] & 0xFF) << 7;
104
         value = value & CompactBytesDataInput.P7 - 1 | (data[offset++] & 0xFF) << 7;
98
-        if (Integer.compareUnsigned(value & CompactBytesDataInput.P14, 0) == 0)
105
+        if ((value & CompactBytesDataInput.P14) == 0)
99
             return value;
106
             return value;
100
         value = value & CompactBytesDataInput.P14 - 1 | (data[offset++] & 0xFF) << 14;
107
         value = value & CompactBytesDataInput.P14 - 1 | (data[offset++] & 0xFF) << 14;
101
-        if (Integer.compareUnsigned(value & CompactBytesDataInput.P21, 0) == 0)
108
+        if ((value & CompactBytesDataInput.P21) == 0)
102
             return value;
109
             return value;
103
         value = value & CompactBytesDataInput.P21 - 1 | (data[offset++] & 0xFF) << 21;
110
         value = value & CompactBytesDataInput.P21 - 1 | (data[offset++] & 0xFF) << 21;
104
-        if (Integer.compareUnsigned(value & CompactBytesDataInput.P28, 0) == 0)
111
+        if ((value & CompactBytesDataInput.P28) == 0)
105
             return value;
112
             return value;
106
         return value & CompactBytesDataInput.P28 - 1 | (data[offset++] & 0xFF) << 28;
113
         return value & CompactBytesDataInput.P28 - 1 | (data[offset++] & 0xFF) << 28;
107
     }
114
     }

+ 9
- 0
Shared/src/main/java/live/MutableLiveBool.java Целия файл

1
+package live;
2
+
3
+public interface MutableLiveBool extends LiveBool {
4
+    void setValue(boolean value);
5
+	
6
+	default void toggle() {
7
+		setValue(!getValue());
8
+	}
9
+}

+ 33
- 0
Shared/src/main/java/live/SimpleLiveBool.java Целия файл

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+import listeners.ListenerList;
5
+import zsynthetic.FunctionBoolBoolToVoid;
6
+
7
+public final class SimpleLiveBool implements MutableLiveBool {
8
+    private final ListenerList<FunctionBoolBoolToVoid> listeners = new ListenerList<FunctionBoolBoolToVoid>();
9
+    private boolean value;
10
+    
11
+    public SimpleLiveBool(boolean value) {
12
+        this.value = value;
13
+    }
14
+    
15
+    @Override
16
+    public ListenerHandle<FunctionBoolBoolToVoid> addListener(FunctionBoolBoolToVoid listener) {
17
+        return listeners.add(listener);
18
+    }
19
+    
20
+    @Override
21
+    public void setValue(boolean value) {
22
+        if (value == this.value)
23
+            return;
24
+        boolean oldValue = this.value;
25
+        this.value = value;
26
+        listeners.accept(listener -> 
27
+        listener.invoke(oldValue, this.value));
28
+    }
29
+    
30
+    public boolean getValue() {
31
+        return value;
32
+    }
33
+}

+ 0
- 1
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java Целия файл

6
     public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
6
     public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
7
     public static final CodePosition UNKNOWN = new CodePosition(new VirtualSourceFile("unknown"), 0, 0, 0, 0);
7
     public static final CodePosition UNKNOWN = new CodePosition(new VirtualSourceFile("unknown"), 0, 0, 0, 0);
8
     public static final CodePosition GENERATED = new CodePosition(new VirtualSourceFile("generated"), 0, 0, 0, 0);
8
     public static final CodePosition GENERATED = new CodePosition(new VirtualSourceFile("generated"), 0, 0, 0, 0);
9
-	
10
     public final SourceFile file;
9
     public final SourceFile file;
11
     public final int fromLine;
10
     public final int fromLine;
12
     public final int fromLineOffset;
11
     public final int fromLineOffset;

+ 2
- 3
Shared/src/main/java/org/openzen/zencode/shared/CompileException.java Целия файл

7
     
7
     
8
     public final CodePosition position;
8
     public final CodePosition position;
9
     public final CompileExceptionCode code;
9
     public final CompileExceptionCode code;
10
-	public final String message;
11
-    
10
+    public final String message;
11
+	
12
     public CompileException(CodePosition position, CompileExceptionCode code, String message) {
12
     public CompileException(CodePosition position, CompileExceptionCode code, String message) {
13
         super(position.toString() + ": [" + code.toString() + "] " + message);
13
         super(position.toString() + ": [" + code.toString() + "] " + message);
14
-		
15
         this.position = position;
14
         this.position = position;
16
         this.code = code;
15
         this.code = code;
17
 		this.message = message;
16
 		this.message = message;

+ 0
- 1
Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java Целия файл

23
         throw new AssertionError("Cannot update literal source files");
23
         throw new AssertionError("Cannot update literal source files");
24
     }
24
     }
25
     
25
     
26
-	@Override
27
     public String getFilename() {
26
     public String getFilename() {
28
         return filename;
27
         return filename;
29
     }
28
     }

Loading…
Отказ
Запис