mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 17:57:38 +00:00
Added a megabuf function to the expression parser, which works like gmegabuf, except that there is one buffer per Expression instance.
This commit is contained in:
parent
c6518a9243
commit
9cdac001e3
@ -63,6 +63,7 @@ public class Expression {
|
||||
private final Map<String, RValue> variables = new HashMap<String, RValue>();
|
||||
private final String[] variableNames;
|
||||
private RValue root;
|
||||
private final Map<Integer, double[]> megabuf = new HashMap<Integer, double[]>();
|
||||
|
||||
public static Expression compile(String expression, String... variableNames) throws ExpressionException {
|
||||
return new Expression(expression, variableNames);
|
||||
@ -151,4 +152,8 @@ public class Expression {
|
||||
instance.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, double[]> getMegabuf() {
|
||||
return megabuf;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.sk89q.worldedit.expression.Expression;
|
||||
import com.sk89q.worldedit.expression.runtime.Function.Dynamic;
|
||||
|
||||
/**
|
||||
@ -272,10 +273,10 @@ public final class Functions {
|
||||
|
||||
private static final Map<Integer, double[]> gmegabuf = new HashMap<Integer, double[]>();
|
||||
|
||||
private static double[] getSubBuffer(Integer key) {
|
||||
double[] ret = gmegabuf.get(key);
|
||||
private static double[] getSubBuffer(Map<Integer, double[]> megabuf, Integer key) {
|
||||
double[] ret = megabuf.get(key);
|
||||
if (ret == null) {
|
||||
gmegabuf.put(key, ret = new double[1024]);
|
||||
megabuf.put(key, ret = new double[1024]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -283,13 +284,25 @@ public final class Functions {
|
||||
@Dynamic
|
||||
public static final double gmegabuf(RValue index) throws EvaluationException {
|
||||
final int intIndex = (int) index.getValue();
|
||||
return getSubBuffer(intIndex & ~1023)[intIndex & 1023];
|
||||
return getSubBuffer(gmegabuf, intIndex & ~1023)[intIndex & 1023];
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
public static final double gmegabuf(RValue index, double value) throws EvaluationException {
|
||||
final int intIndex = (int) index.getValue();
|
||||
return getSubBuffer(intIndex & ~1023)[intIndex & 1023] = value;
|
||||
return getSubBuffer(gmegabuf, intIndex & ~1023)[intIndex & 1023] = value;
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
public static final double megabuf(RValue index) throws EvaluationException {
|
||||
final int intIndex = (int) index.getValue();
|
||||
return getSubBuffer(Expression.getInstance().getMegabuf(), intIndex & ~1023)[intIndex & 1023];
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
public static final double megabuf(RValue index, double value) throws EvaluationException {
|
||||
final int intIndex = (int) index.getValue();
|
||||
return getSubBuffer(Expression.getInstance().getMegabuf(), intIndex & ~1023)[intIndex & 1023] = value;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user