Update EaglerAdapter
This commit is contained in:
parent
890a2f9afd
commit
58f318e627
299
src/net/PeytonPlayz585/Client.java
Normal file
299
src/net/PeytonPlayz585/Client.java
Normal file
File diff suppressed because one or more lines are too long
81
src/net/PeytonPlayz585/awt/image/BufferedImage.java
Normal file
81
src/net/PeytonPlayz585/awt/image/BufferedImage.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
package net.PeytonPlayz585.awt.image;
|
||||
|
||||
public class BufferedImage {
|
||||
|
||||
private final int[] pixels;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final boolean isAlphaPremultiplied;
|
||||
|
||||
public BufferedImage(int[] pixels, int width, int height, boolean alpha) {
|
||||
if(pixels.length != width*height) {
|
||||
throw new IllegalArgumentException("array size does not equal image size");
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.pixels = pixels;
|
||||
this.isAlphaPremultiplied = alpha;
|
||||
}
|
||||
|
||||
public BufferedImage(int width, int height, int[] pixels, boolean alpha) {
|
||||
if(pixels.length != width*height) {
|
||||
throw new IllegalArgumentException("array size does not equal image size");
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.pixels = pixels;
|
||||
this.isAlphaPremultiplied = alpha;
|
||||
}
|
||||
|
||||
public BufferedImage(int width, int height, boolean alpha) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.pixels = new int[width * height];
|
||||
this.isAlphaPremultiplied = alpha;
|
||||
}
|
||||
|
||||
public BufferedImage(int w, int h, int k) {
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
this.isAlphaPremultiplied = true;
|
||||
this.pixels = new int[w * h];
|
||||
}
|
||||
|
||||
public BufferedImage getSubImage(int x, int y, int pw, int ph) {
|
||||
int[] img = new int[pw * ph];
|
||||
for(int i = 0; i < ph; ++i) {
|
||||
System.arraycopy(pixels, (i + y) * this.width + x, img, i * pw, pw);
|
||||
}
|
||||
return new BufferedImage(pw, ph, img, isAlphaPremultiplied);
|
||||
}
|
||||
|
||||
public void getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {
|
||||
for (int y = 0; y < h; ++y) {
|
||||
System.arraycopy(pixels, offset + (y + startY) * scansize + startX, rgbArray, y * w, w);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {
|
||||
for (int y = 0; y < h; ++y) {
|
||||
System.arraycopy(rgbArray, offset + (y + startY) * scansize + startX, pixels, y * w, w);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAlphaPremultiplied() {
|
||||
return isAlphaPremultiplied;
|
||||
}
|
||||
|
||||
public int[] getData() {
|
||||
return pixels;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
29
src/net/PeytonPlayz585/awt/image/ImageIO.java
Normal file
29
src/net/PeytonPlayz585/awt/image/ImageIO.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package net.PeytonPlayz585.awt.image;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class ImageIO {
|
||||
|
||||
public static BufferedImage read(InputStream var1) {
|
||||
ByteArrayInputStream bais = (ByteArrayInputStream)var1;
|
||||
byte[] data = bais.readAllBytes();
|
||||
|
||||
return GL11.EaglerAdapterImpl2.loadPNG(data);
|
||||
}
|
||||
|
||||
public static BufferedImage read(BufferedImage resource) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static InputStream getResourceAsStream(String var1) {
|
||||
return GL11.EaglerAdapterImpl2.loadResource(var1);
|
||||
}
|
||||
|
||||
public static BufferedImage getResource(String string) {
|
||||
return GL11.EaglerAdapterImpl2.loadPNG(GL11.EaglerAdapterImpl2.loadResourceBytes(string));
|
||||
}
|
||||
|
||||
}
|
112
src/net/PeytonPlayz585/fileutils/File.java
Normal file
112
src/net/PeytonPlayz585/fileutils/File.java
Normal file
|
@ -0,0 +1,112 @@
|
|||
package net.PeytonPlayz585.fileutils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.PeytonPlayz585.Client;
|
||||
import net.PeytonPlayz585.fileutils.IndexedDBFilesystem.OpenState;
|
||||
|
||||
public class File {
|
||||
|
||||
public static final boolean fileExists(String path) {
|
||||
return IndexedDBFilesystem.fileExists(path);
|
||||
}
|
||||
|
||||
public static final boolean directoryExists(String path) {
|
||||
return IndexedDBFilesystem.directoryExists(path);
|
||||
}
|
||||
|
||||
public static final boolean pathExists(String path) {
|
||||
return IndexedDBFilesystem.pathExists(path);
|
||||
}
|
||||
|
||||
public static final boolean exists(String path) {
|
||||
return readFile(path) != null;
|
||||
}
|
||||
|
||||
public static final void mkdir(String path) {
|
||||
String[] parts = path.split("/");
|
||||
String dir = parts[parts.length - 1];
|
||||
|
||||
if(path.endsWith("/")) {
|
||||
String file = "placeholder.txt";
|
||||
path = path.replace(dir + "/", "");
|
||||
if(!path.endsWith("/")) {
|
||||
path = path + "/";
|
||||
}
|
||||
writeFile(path + dir + "/" + file, "UwU".getBytes());
|
||||
} else {
|
||||
String file = "placeholder.txt";
|
||||
path = path.replace(dir, "");
|
||||
if(!path.endsWith("/")) {
|
||||
path = path + "/";
|
||||
}
|
||||
writeFile(path + dir + "/" + file, "UwU".getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
public static final void writeFile(String path, byte[] data) {
|
||||
IndexedDBFilesystem.writeFile(path, data);
|
||||
}
|
||||
|
||||
public static final byte[] readFile(String path) {
|
||||
return IndexedDBFilesystem.readFile(path);
|
||||
}
|
||||
|
||||
public static final long getLastModified(String path) {
|
||||
return IndexedDBFilesystem.getLastModified(path);
|
||||
}
|
||||
|
||||
public static final int getFileSize(String path) {
|
||||
return IndexedDBFilesystem.getFileSize(path);
|
||||
}
|
||||
|
||||
public static final void renameFile(String oldPath, String newPath) {
|
||||
IndexedDBFilesystem.renameFile(oldPath, newPath);
|
||||
}
|
||||
|
||||
public static final void copyFile(String oldPath, String newPath) {
|
||||
IndexedDBFilesystem.copyFile(oldPath, newPath);
|
||||
}
|
||||
|
||||
public static final void deleteFile(String path) {
|
||||
IndexedDBFilesystem.deleteFile(path);
|
||||
}
|
||||
|
||||
public static final Collection<FileEntry> listFiles(String path, boolean listDirs, boolean recursiveDirs) {
|
||||
return IndexedDBFilesystem.listFiles(path, listDirs, recursiveDirs);
|
||||
}
|
||||
|
||||
public static final Collection<FileEntry> listFilesAndDirectories(String path) {
|
||||
return listFiles(path, true, false);
|
||||
}
|
||||
|
||||
public static final Collection<FileEntry> listFilesRecursive(String path) {
|
||||
return listFiles(path, false, true);
|
||||
}
|
||||
|
||||
public static final FileEntry[] listFiles(String path) {
|
||||
Collection<FileEntry> entries = IndexedDBFilesystem.listFiles(path, true, false);
|
||||
FileEntry[] entryArray = new FileEntry[entries.size()];
|
||||
|
||||
int i = 0;
|
||||
for(FileEntry entry : entries) {
|
||||
entryArray[i] = entry;
|
||||
i = i + 1;
|
||||
}
|
||||
return entryArray;
|
||||
}
|
||||
|
||||
public static boolean isCompressed(byte[] b) {
|
||||
if(b == null || b.length < 2) {
|
||||
return false;
|
||||
}
|
||||
return (b[0] == (byte) 0x1F) && (b[1] == (byte) 0x8B);
|
||||
}
|
||||
|
||||
static {
|
||||
if(IndexedDBFilesystem.initialize() != OpenState.OPENED) {
|
||||
Client.showIncompatibleScreen("IndexedDB failed to initialize!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
24
src/net/PeytonPlayz585/fileutils/FileEntry.java
Normal file
24
src/net/PeytonPlayz585/fileutils/FileEntry.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package net.PeytonPlayz585.fileutils;
|
||||
|
||||
public class FileEntry {
|
||||
|
||||
public final String path;
|
||||
public final boolean isDirectory;
|
||||
public final long lastModified;
|
||||
|
||||
public FileEntry(String path, boolean isDirectory, long lastModified) {
|
||||
this.path = path;
|
||||
this.isDirectory = isDirectory;
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
int i = path.indexOf('/');
|
||||
if(i >= 0) {
|
||||
return path.substring(i + 1);
|
||||
}else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
22
src/net/PeytonPlayz585/fileutils/FilesystemUtils.java
Normal file
22
src/net/PeytonPlayz585/fileutils/FilesystemUtils.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package net.PeytonPlayz585.fileutils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class FilesystemUtils {
|
||||
|
||||
public static void recursiveDeleteDirectory(String dir) {
|
||||
Collection<FileEntry> lst = File.listFiles(dir, true, true);
|
||||
for(FileEntry t : lst) {
|
||||
if(!t.isDirectory) {
|
||||
File.deleteFile(t.path);
|
||||
}
|
||||
}
|
||||
for(FileEntry t : lst) {
|
||||
if(t.isDirectory) {
|
||||
File.deleteFile(t.path);
|
||||
}
|
||||
}
|
||||
File.deleteFile(dir);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +1,79 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.core.JSString;
|
||||
import org.teavm.jso.indexeddb.IDBCountRequest;
|
||||
import org.teavm.jso.indexeddb.IDBCursorRequest;
|
||||
import org.teavm.jso.indexeddb.IDBCursorSource;
|
||||
import org.teavm.jso.indexeddb.IDBDatabase;
|
||||
import org.teavm.jso.indexeddb.IDBGetRequest;
|
||||
import org.teavm.jso.indexeddb.IDBIndex;
|
||||
import org.teavm.jso.indexeddb.IDBKeyRange;
|
||||
import org.teavm.jso.indexeddb.IDBObjectStoreParameters;
|
||||
import org.teavm.jso.indexeddb.IDBRequest;
|
||||
import org.teavm.jso.indexeddb.IDBTransaction;
|
||||
|
||||
public abstract class IDBObjectStorePatched implements JSObject, IDBCursorSource {
|
||||
|
||||
@JSBody(params = { "db", "name", "optionalParameters" }, script = "return db.createObjectStore(name, optionalParameters);")
|
||||
public static native IDBObjectStorePatched createObjectStorePatch(IDBDatabase db, String name, IDBObjectStoreParameters optionalParameters);
|
||||
|
||||
@JSBody(params = { "tx", "name" }, script = "return tx.objectStore(name);")
|
||||
public static native IDBObjectStorePatched objectStorePatch(IDBTransaction tx, String name);
|
||||
|
||||
@JSProperty
|
||||
public abstract String getName();
|
||||
|
||||
@JSProperty("keyPath")
|
||||
abstract JSObject getKeyPathImpl();
|
||||
|
||||
public final String[] getKeyPath() {
|
||||
JSObject result = getKeyPathImpl();
|
||||
if (JSString.isInstance(result)) {
|
||||
return new String[] { result.<JSString>cast().stringValue() };
|
||||
} else {
|
||||
return unwrapStringArray(result);
|
||||
}
|
||||
}
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return this;")
|
||||
private static native String[] unwrapStringArray(JSObject obj);
|
||||
|
||||
@JSProperty
|
||||
public abstract String[] getIndexNames();
|
||||
|
||||
@JSProperty
|
||||
public abstract boolean isAutoIncrement();
|
||||
|
||||
public abstract IDBRequest put(JSObject value, JSObject key);
|
||||
|
||||
public abstract IDBRequest put(JSObject value);
|
||||
|
||||
public abstract IDBRequest add(JSObject value, JSObject key);
|
||||
|
||||
public abstract IDBRequest add(JSObject value);
|
||||
|
||||
public abstract IDBRequest delete(JSObject key);
|
||||
|
||||
public abstract IDBGetRequest get(JSObject key);
|
||||
|
||||
public abstract IDBRequest clear();
|
||||
|
||||
public abstract IDBCursorRequest openCursor();
|
||||
|
||||
public abstract IDBCursorRequest openCursor(IDBKeyRange range);
|
||||
|
||||
public abstract IDBIndex createIndex(String name, String key);
|
||||
|
||||
public abstract IDBIndex createIndex(String name, String[] keys);
|
||||
|
||||
public abstract IDBIndex index(String name);
|
||||
|
||||
public abstract void deleteIndex(String name);
|
||||
|
||||
public abstract IDBCountRequest count();
|
||||
|
||||
public abstract IDBCountRequest count(JSObject key);
|
||||
package net.PeytonPlayz585.fileutils;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.core.JSString;
|
||||
import org.teavm.jso.indexeddb.IDBCountRequest;
|
||||
import org.teavm.jso.indexeddb.IDBCursorRequest;
|
||||
import org.teavm.jso.indexeddb.IDBCursorSource;
|
||||
import org.teavm.jso.indexeddb.IDBDatabase;
|
||||
import org.teavm.jso.indexeddb.IDBGetRequest;
|
||||
import org.teavm.jso.indexeddb.IDBIndex;
|
||||
import org.teavm.jso.indexeddb.IDBKeyRange;
|
||||
import org.teavm.jso.indexeddb.IDBObjectStoreParameters;
|
||||
import org.teavm.jso.indexeddb.IDBRequest;
|
||||
import org.teavm.jso.indexeddb.IDBTransaction;
|
||||
|
||||
public abstract class IDBObjectStorePatched implements JSObject, IDBCursorSource {
|
||||
|
||||
@JSBody(params = { "db", "name", "optionalParameters" }, script = "return db.createObjectStore(name, optionalParameters);")
|
||||
public static native IDBObjectStorePatched createObjectStorePatch(IDBDatabase db, String name, IDBObjectStoreParameters optionalParameters);
|
||||
|
||||
@JSBody(params = { "tx", "name" }, script = "return tx.objectStore(name);")
|
||||
public static native IDBObjectStorePatched objectStorePatch(IDBTransaction tx, String name);
|
||||
|
||||
@JSProperty
|
||||
public abstract String getName();
|
||||
|
||||
@JSProperty("keyPath")
|
||||
abstract JSObject getKeyPathImpl();
|
||||
|
||||
public final String[] getKeyPath() {
|
||||
JSObject result = getKeyPathImpl();
|
||||
if (JSString.isInstance(result)) {
|
||||
return new String[] { result.<JSString>cast().stringValue() };
|
||||
} else {
|
||||
return unwrapStringArray(result);
|
||||
}
|
||||
}
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return this;")
|
||||
private static native String[] unwrapStringArray(JSObject obj);
|
||||
|
||||
@JSProperty
|
||||
public abstract String[] getIndexNames();
|
||||
|
||||
@JSProperty
|
||||
public abstract boolean isAutoIncrement();
|
||||
|
||||
public abstract IDBRequest put(JSObject value, JSObject key);
|
||||
|
||||
public abstract IDBRequest put(JSObject value);
|
||||
|
||||
public abstract IDBRequest add(JSObject value, JSObject key);
|
||||
|
||||
public abstract IDBRequest add(JSObject value);
|
||||
|
||||
public abstract IDBRequest delete(JSObject key);
|
||||
|
||||
public abstract IDBGetRequest get(JSObject key);
|
||||
|
||||
public abstract IDBRequest clear();
|
||||
|
||||
public abstract IDBCursorRequest openCursor();
|
||||
|
||||
public abstract IDBCursorRequest openCursor(IDBKeyRange range);
|
||||
|
||||
public abstract IDBIndex createIndex(String name, String key);
|
||||
|
||||
public abstract IDBIndex createIndex(String name, String[] keys);
|
||||
|
||||
public abstract IDBIndex index(String name);
|
||||
|
||||
public abstract void deleteIndex(String name);
|
||||
|
||||
public abstract IDBCountRequest count();
|
||||
|
||||
public abstract IDBCountRequest count(JSObject key);
|
||||
}
|
|
@ -1,414 +1,404 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.teavm.interop.Async;
|
||||
import org.teavm.interop.AsyncCallback;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.dom.events.EventListener;
|
||||
import org.teavm.jso.indexeddb.EventHandler;
|
||||
import org.teavm.jso.indexeddb.IDBCountRequest;
|
||||
import org.teavm.jso.indexeddb.IDBCursor;
|
||||
import org.teavm.jso.indexeddb.IDBCursorRequest;
|
||||
import org.teavm.jso.indexeddb.IDBDatabase;
|
||||
import org.teavm.jso.indexeddb.IDBFactory;
|
||||
import org.teavm.jso.indexeddb.IDBGetRequest;
|
||||
import org.teavm.jso.indexeddb.IDBObjectStoreParameters;
|
||||
import org.teavm.jso.indexeddb.IDBOpenDBRequest;
|
||||
import org.teavm.jso.indexeddb.IDBRequest;
|
||||
import org.teavm.jso.indexeddb.IDBTransaction;
|
||||
import org.teavm.jso.indexeddb.IDBVersionChangeEvent;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Uint8Array;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
|
||||
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2.FileEntry;
|
||||
|
||||
public class IndexedDBFilesystem {
|
||||
|
||||
public static enum OpenState {
|
||||
OPENED, LOCKED, ERROR
|
||||
}
|
||||
|
||||
private static String err = "";
|
||||
private static IDBDatabase db = null;
|
||||
|
||||
public static final OpenState initialize() {
|
||||
DatabaseOpen dbo;
|
||||
if(GL11.dataBaseName != null) {
|
||||
System.out.println("Setting custom database name to " + GL11.dataBaseName);
|
||||
dbo = AsyncHandlers.openDB(GL11.dataBaseName);
|
||||
} else {
|
||||
dbo = AsyncHandlers.openDB("_net_PeytonPlayz585_eaglercraft_beta_IndexedDBFilesystem_1_7_3");
|
||||
}
|
||||
if(dbo == null) {
|
||||
err = "Unknown Error";
|
||||
return OpenState.ERROR;
|
||||
}
|
||||
if(dbo.failedLocked) {
|
||||
return OpenState.LOCKED;
|
||||
}
|
||||
if(dbo.failedInit || dbo.database == null) {
|
||||
err = dbo.failedError == null ? "Initialization Failed" : dbo.failedError;
|
||||
return OpenState.ERROR;
|
||||
}
|
||||
db = dbo.database;
|
||||
return OpenState.OPENED;
|
||||
}
|
||||
|
||||
public static final String errorDetail() {
|
||||
return err;
|
||||
}
|
||||
|
||||
public static final boolean fileExists(String path) {
|
||||
return AsyncHandlers.fileGetType(db, path) == FileExists.FILE;
|
||||
}
|
||||
|
||||
public static final boolean directoryExists(String path) {
|
||||
return AsyncHandlers.fileGetType(db, path) == FileExists.DIRECTORY;
|
||||
}
|
||||
|
||||
public static final boolean pathExists(String path) {
|
||||
return AsyncHandlers.fileExists(db, path).bool;
|
||||
}
|
||||
|
||||
private static final void mkdir(String dir) {
|
||||
if(directoryExists(dir)) {
|
||||
return;
|
||||
}
|
||||
int i = dir.lastIndexOf('/');
|
||||
if(i > 0) {
|
||||
mkdir(dir.substring(0, i));
|
||||
}
|
||||
AsyncHandlers.writeWholeFile(db, dir, true, ArrayBuffer.create(0));
|
||||
}
|
||||
|
||||
public static final void writeFile(String path, byte[] data) {
|
||||
int i = path.lastIndexOf('/');
|
||||
if(i > 0) {
|
||||
mkdir(path.substring(0, i));
|
||||
}
|
||||
Uint8Array arr = Uint8Array.create(data.length);
|
||||
arr.set(data);
|
||||
AsyncHandlers.writeWholeFile(db, path, false, arr.getBuffer());
|
||||
}
|
||||
|
||||
public static final byte[] readFile(String path) {
|
||||
ArrayBuffer arr = AsyncHandlers.readWholeFile(db, path);
|
||||
if(arr == null) {
|
||||
return null;
|
||||
}
|
||||
byte[] data = new byte[arr.getByteLength()];
|
||||
Uint8Array arrr = Uint8Array.create(arr);
|
||||
for(int i = 0; i < data.length; ++i) {
|
||||
data[i] = (byte) arrr.get(i);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static final long getLastModified(String path) {
|
||||
int lm = AsyncHandlers.fileGetLastModified(db, path);
|
||||
return lm == -1 ? -1l : AsyncHandlers.eaglercraftEpoch + lm;
|
||||
}
|
||||
|
||||
public static final int getFileSize(String path) {
|
||||
ArrayBuffer arr = AsyncHandlers.readWholeFile(db, path);
|
||||
if(arr == null) {
|
||||
return -1;
|
||||
}else {
|
||||
return arr.getByteLength();
|
||||
}
|
||||
}
|
||||
|
||||
public static final void renameFile(String oldPath, String newPath) {
|
||||
copyFile(oldPath, newPath);
|
||||
AsyncHandlers.deleteFile(db, oldPath);
|
||||
}
|
||||
|
||||
public static final void copyFile(String oldPath, String newPath) {
|
||||
ArrayBuffer arr = AsyncHandlers.readWholeFile(db, oldPath);
|
||||
int i = newPath.lastIndexOf('/');
|
||||
if(i > 0) {
|
||||
mkdir(newPath.substring(0, i));
|
||||
}
|
||||
AsyncHandlers.writeWholeFile(db, newPath, false, arr);
|
||||
}
|
||||
|
||||
public static final void deleteFile(String path) {
|
||||
AsyncHandlers.deleteFile(db, path);
|
||||
}
|
||||
|
||||
public static final Collection<FileEntry> listFiles(String path, boolean listDirs, boolean recursiveDirs) {
|
||||
LinkedList<FileEntry> lst = new LinkedList<FileEntry>();
|
||||
AsyncHandlers.iterateFiles(db, path, listDirs, recursiveDirs, lst);
|
||||
return lst;
|
||||
}
|
||||
|
||||
protected static class BooleanResult {
|
||||
|
||||
protected static final BooleanResult TRUE = new BooleanResult(true);
|
||||
protected static final BooleanResult FALSE = new BooleanResult(false);
|
||||
|
||||
protected final boolean bool;
|
||||
|
||||
private BooleanResult(boolean b) {
|
||||
bool = b;
|
||||
}
|
||||
|
||||
protected static BooleanResult _new(boolean b) {
|
||||
return b ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class DatabaseOpen {
|
||||
|
||||
protected final boolean failedInit;
|
||||
protected final boolean failedLocked;
|
||||
protected final String failedError;
|
||||
|
||||
protected final IDBDatabase database;
|
||||
|
||||
protected DatabaseOpen(boolean init, boolean locked, String error, IDBDatabase db) {
|
||||
failedInit = init;
|
||||
failedLocked = locked;
|
||||
failedError = error;
|
||||
database = db;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static enum FileExists {
|
||||
FILE, DIRECTORY, FALSE
|
||||
}
|
||||
|
||||
@JSBody(script = "return ((typeof indexedDB) !== 'undefined') ? indexedDB : null;")
|
||||
protected static native IDBFactory createIDBFactory();
|
||||
|
||||
protected static class AsyncHandlers {
|
||||
|
||||
protected static final long eaglercraftEpoch = 1645568542000l;
|
||||
|
||||
@Async
|
||||
protected static native DatabaseOpen openDB(String name);
|
||||
|
||||
private static void openDB(String name, final AsyncCallback<DatabaseOpen> cb) {
|
||||
IDBFactory i = createIDBFactory();
|
||||
if(i == null) {
|
||||
cb.complete(new DatabaseOpen(false, false, "window.indexedDB was null or undefined", null));
|
||||
return;
|
||||
}
|
||||
final IDBOpenDBRequest f = i.open(name, 1);
|
||||
f.setOnBlocked(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(new DatabaseOpen(false, true, null, null));
|
||||
}
|
||||
});
|
||||
f.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(new DatabaseOpen(false, false, null, f.getResult()));
|
||||
}
|
||||
});
|
||||
f.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(new DatabaseOpen(true, false, "open error", null));
|
||||
}
|
||||
});
|
||||
f.setOnUpgradeNeeded(new EventListener<IDBVersionChangeEvent>() {
|
||||
public void handleEvent(IDBVersionChangeEvent evt) {
|
||||
IDBObjectStorePatched.createObjectStorePatch(f.getResult(), "filesystem", IDBObjectStoreParameters.create().keyPath("path"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native BooleanResult deleteFile(IDBDatabase db, String name);
|
||||
|
||||
private static void deleteFile(IDBDatabase db, String name, final AsyncCallback<BooleanResult> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readwrite");
|
||||
final IDBRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").delete(makeTheFuckingKeyWork(name));
|
||||
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(true));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return (typeof obj === 'undefined') ? null : ((typeof obj.data === 'undefined') ? null : obj.data);")
|
||||
protected static native ArrayBuffer readRow(JSObject obj);
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return (typeof obj === 'undefined') ? false : ((typeof obj.directory === 'undefined') ? false : obj.directory);")
|
||||
protected static native boolean isRowDirectory(JSObject obj);
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return (typeof obj === 'undefined') ? -1 : ((typeof obj.lastModified === 'undefined') ? -1 : obj.lastModified);")
|
||||
protected static native int readLastModified(JSObject obj);
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return [obj];")
|
||||
private static native JSObject makeTheFuckingKeyWork(String k);
|
||||
|
||||
@Async
|
||||
protected static native ArrayBuffer readWholeFile(IDBDatabase db, String name);
|
||||
|
||||
private static void readWholeFile(IDBDatabase db, String name, final AsyncCallback<ArrayBuffer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(isRowDirectory(r.getResult()) ? null : readRow(r.getResult()));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(null);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native Integer readLastModified(IDBDatabase db, String name);
|
||||
|
||||
private static void readLastModified(IDBDatabase db, String name, final AsyncCallback<Integer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(readLastModified(r.getResult()));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(-1);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@JSBody(params = { "k" }, script = "return ((typeof k) === \"string\") ? k : (((typeof k) === \"undefined\") ? null : (((typeof k[0]) === \"string\") ? k[0] : null));")
|
||||
private static native String readKey(JSObject k);
|
||||
|
||||
@Async
|
||||
protected static native Integer iterateFiles(IDBDatabase db, final String prefix, final boolean listDirs, final boolean recursiveDirs, final Collection<EaglerAdapterImpl2.FileEntry> lst);
|
||||
|
||||
private static void iterateFiles(IDBDatabase db, final String prefix, final boolean listDirs, final boolean recursiveDirs, final Collection<EaglerAdapterImpl2.FileEntry> lst, final AsyncCallback<Integer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBCursorRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").openCursor();
|
||||
final int[] res = new int[1];
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
IDBCursor c = r.getResult();
|
||||
if(c == null || c.getKey() == null || c.getValue() == null) {
|
||||
cb.complete(res[0]);
|
||||
return;
|
||||
}
|
||||
String k = readKey(c.getKey());
|
||||
if(k != null) {
|
||||
if(k.startsWith(prefix)) {
|
||||
if(recursiveDirs || k.indexOf('/', prefix.length() + 1) == -1) {
|
||||
boolean dir = isRowDirectory(c.getValue());
|
||||
if(dir) {
|
||||
if(listDirs) {
|
||||
lst.add(new EaglerAdapterImpl2.FileEntry(k, true, -1));
|
||||
}
|
||||
}else {
|
||||
lst.add(new EaglerAdapterImpl2.FileEntry(k, false, eaglercraftEpoch + readLastModified(c.getValue())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
c.doContinue();
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(res[0] > 0 ? res[0] : -1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native BooleanResult fileExists(IDBDatabase db, String name);
|
||||
|
||||
private static void fileExists(IDBDatabase db, String name, final AsyncCallback<BooleanResult> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBCountRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").count(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(r.getResult() > 0));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native Integer fileGetLastModified(IDBDatabase db, String name);
|
||||
|
||||
private static void fileGetLastModified(IDBDatabase db, String name, final AsyncCallback<Integer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(readLastModified(r.getResult()));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native FileExists fileGetType(IDBDatabase db, String name);
|
||||
|
||||
private static void fileGetType(IDBDatabase db, String name, final AsyncCallback<FileExists> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(r.getResult() == null ? FileExists.FALSE : (isRowDirectory(r.getResult()) ? FileExists.DIRECTORY : FileExists.FILE));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(FileExists.FALSE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@JSBody(params = { "pat", "dir", "lm", "dat" }, script = "return { path: pat, directory: dir, lastModified: lm, data: dat };")
|
||||
protected static native JSObject writeRow(String name, boolean directory, int lm, ArrayBuffer data);
|
||||
|
||||
@Async
|
||||
protected static native BooleanResult writeWholeFile(IDBDatabase db, String name, boolean directory, ArrayBuffer data);
|
||||
|
||||
private static void writeWholeFile(IDBDatabase db, String name, boolean directory, ArrayBuffer data, final AsyncCallback<BooleanResult> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readwrite");
|
||||
final IDBRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").put(writeRow(name, directory, (int)(System.currentTimeMillis() - eaglercraftEpoch), data));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(true));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
package net.PeytonPlayz585.fileutils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.teavm.interop.Async;
|
||||
import org.teavm.interop.AsyncCallback;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.dom.events.EventListener;
|
||||
import org.teavm.jso.indexeddb.EventHandler;
|
||||
import org.teavm.jso.indexeddb.IDBCountRequest;
|
||||
import org.teavm.jso.indexeddb.IDBCursor;
|
||||
import org.teavm.jso.indexeddb.IDBCursorRequest;
|
||||
import org.teavm.jso.indexeddb.IDBDatabase;
|
||||
import org.teavm.jso.indexeddb.IDBFactory;
|
||||
import org.teavm.jso.indexeddb.IDBGetRequest;
|
||||
import org.teavm.jso.indexeddb.IDBObjectStoreParameters;
|
||||
import org.teavm.jso.indexeddb.IDBOpenDBRequest;
|
||||
import org.teavm.jso.indexeddb.IDBRequest;
|
||||
import org.teavm.jso.indexeddb.IDBTransaction;
|
||||
import org.teavm.jso.indexeddb.IDBVersionChangeEvent;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Uint8Array;
|
||||
|
||||
public class IndexedDBFilesystem {
|
||||
|
||||
public static enum OpenState {
|
||||
OPENED, LOCKED, ERROR
|
||||
}
|
||||
|
||||
private static String err = "";
|
||||
private static IDBDatabase db = null;
|
||||
|
||||
public static final OpenState initialize() {
|
||||
DatabaseOpen dbo = AsyncHandlers.openDB("_net_PeytonPlayz585_eaglercraft_beta_IndexedDBFilesystem_1_7_3");
|
||||
if(dbo == null) {
|
||||
err = "Unknown Error";
|
||||
return OpenState.ERROR;
|
||||
}
|
||||
if(dbo.failedLocked) {
|
||||
return OpenState.LOCKED;
|
||||
}
|
||||
if(dbo.failedInit || dbo.database == null) {
|
||||
err = dbo.failedError == null ? "Initialization Failed" : dbo.failedError;
|
||||
return OpenState.ERROR;
|
||||
}
|
||||
db = dbo.database;
|
||||
return OpenState.OPENED;
|
||||
}
|
||||
|
||||
public static final String errorDetail() {
|
||||
return err;
|
||||
}
|
||||
|
||||
public static final boolean fileExists(String path) {
|
||||
return AsyncHandlers.fileGetType(db, path) == FileExists.FILE;
|
||||
}
|
||||
|
||||
public static final boolean directoryExists(String path) {
|
||||
return AsyncHandlers.fileGetType(db, path) == FileExists.DIRECTORY;
|
||||
}
|
||||
|
||||
public static final boolean pathExists(String path) {
|
||||
return AsyncHandlers.fileExists(db, path).bool;
|
||||
}
|
||||
|
||||
private static final void mkdir(String dir) {
|
||||
if(directoryExists(dir)) {
|
||||
return;
|
||||
}
|
||||
int i = dir.lastIndexOf('/');
|
||||
if(i > 0) {
|
||||
mkdir(dir.substring(0, i));
|
||||
}
|
||||
AsyncHandlers.writeWholeFile(db, dir, true, ArrayBuffer.create(0));
|
||||
}
|
||||
|
||||
public static final void writeFile(String path, byte[] data) {
|
||||
int i = path.lastIndexOf('/');
|
||||
if(i > 0) {
|
||||
mkdir(path.substring(0, i));
|
||||
}
|
||||
Uint8Array arr = Uint8Array.create(data.length);
|
||||
arr.set(data);
|
||||
AsyncHandlers.writeWholeFile(db, path, false, arr.getBuffer());
|
||||
}
|
||||
|
||||
public static final byte[] readFile(String path) {
|
||||
ArrayBuffer arr = AsyncHandlers.readWholeFile(db, path);
|
||||
if(arr == null) {
|
||||
return null;
|
||||
}
|
||||
byte[] data = new byte[arr.getByteLength()];
|
||||
Uint8Array arrr = Uint8Array.create(arr);
|
||||
for(int i = 0; i < data.length; ++i) {
|
||||
data[i] = (byte) arrr.get(i);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static final long getLastModified(String path) {
|
||||
int lm = AsyncHandlers.fileGetLastModified(db, path);
|
||||
return lm == -1 ? -1l : AsyncHandlers.eaglercraftEpoch + lm;
|
||||
}
|
||||
|
||||
public static final int getFileSize(String path) {
|
||||
ArrayBuffer arr = AsyncHandlers.readWholeFile(db, path);
|
||||
if(arr == null) {
|
||||
return -1;
|
||||
}else {
|
||||
return arr.getByteLength();
|
||||
}
|
||||
}
|
||||
|
||||
public static final void renameFile(String oldPath, String newPath) {
|
||||
copyFile(oldPath, newPath);
|
||||
AsyncHandlers.deleteFile(db, oldPath);
|
||||
}
|
||||
|
||||
public static final void copyFile(String oldPath, String newPath) {
|
||||
ArrayBuffer arr = AsyncHandlers.readWholeFile(db, oldPath);
|
||||
int i = newPath.lastIndexOf('/');
|
||||
if(i > 0) {
|
||||
mkdir(newPath.substring(0, i));
|
||||
}
|
||||
AsyncHandlers.writeWholeFile(db, newPath, false, arr);
|
||||
}
|
||||
|
||||
public static final void deleteFile(String path) {
|
||||
AsyncHandlers.deleteFile(db, path);
|
||||
}
|
||||
|
||||
public static final Collection<FileEntry> listFiles(String path, boolean listDirs, boolean recursiveDirs) {
|
||||
LinkedList<FileEntry> lst = new LinkedList<FileEntry>();
|
||||
AsyncHandlers.iterateFiles(db, path, listDirs, recursiveDirs, lst);
|
||||
return lst;
|
||||
}
|
||||
|
||||
protected static class BooleanResult {
|
||||
|
||||
protected static final BooleanResult TRUE = new BooleanResult(true);
|
||||
protected static final BooleanResult FALSE = new BooleanResult(false);
|
||||
|
||||
protected final boolean bool;
|
||||
|
||||
private BooleanResult(boolean b) {
|
||||
bool = b;
|
||||
}
|
||||
|
||||
protected static BooleanResult _new(boolean b) {
|
||||
return b ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class DatabaseOpen {
|
||||
|
||||
protected final boolean failedInit;
|
||||
protected final boolean failedLocked;
|
||||
protected final String failedError;
|
||||
|
||||
protected final IDBDatabase database;
|
||||
|
||||
protected DatabaseOpen(boolean init, boolean locked, String error, IDBDatabase db) {
|
||||
failedInit = init;
|
||||
failedLocked = locked;
|
||||
failedError = error;
|
||||
database = db;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static enum FileExists {
|
||||
FILE, DIRECTORY, FALSE
|
||||
}
|
||||
|
||||
@JSBody(script = "return ((typeof indexedDB) !== 'undefined') ? indexedDB : null;")
|
||||
protected static native IDBFactory createIDBFactory();
|
||||
|
||||
protected static class AsyncHandlers {
|
||||
|
||||
protected static final long eaglercraftEpoch = 1645568542000l;
|
||||
|
||||
@Async
|
||||
protected static native DatabaseOpen openDB(String name);
|
||||
|
||||
private static void openDB(String name, final AsyncCallback<DatabaseOpen> cb) {
|
||||
IDBFactory i = createIDBFactory();
|
||||
if(i == null) {
|
||||
cb.complete(new DatabaseOpen(false, false, "window.indexedDB was null or undefined", null));
|
||||
return;
|
||||
}
|
||||
final IDBOpenDBRequest f = i.open(name, 1);
|
||||
f.setOnBlocked(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(new DatabaseOpen(false, true, null, null));
|
||||
}
|
||||
});
|
||||
f.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(new DatabaseOpen(false, false, null, f.getResult()));
|
||||
}
|
||||
});
|
||||
f.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(new DatabaseOpen(true, false, "open error", null));
|
||||
}
|
||||
});
|
||||
f.setOnUpgradeNeeded(new EventListener<IDBVersionChangeEvent>() {
|
||||
public void handleEvent(IDBVersionChangeEvent evt) {
|
||||
IDBObjectStorePatched.createObjectStorePatch(f.getResult(), "filesystem", IDBObjectStoreParameters.create().keyPath("path"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native BooleanResult deleteFile(IDBDatabase db, String name);
|
||||
|
||||
private static void deleteFile(IDBDatabase db, String name, final AsyncCallback<BooleanResult> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readwrite");
|
||||
final IDBRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").delete(makeTheFuckingKeyWork(name));
|
||||
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(true));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return (typeof obj === 'undefined') ? null : ((typeof obj.data === 'undefined') ? null : obj.data);")
|
||||
protected static native ArrayBuffer readRow(JSObject obj);
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return (typeof obj === 'undefined') ? false : ((typeof obj.directory === 'undefined') ? false : obj.directory);")
|
||||
protected static native boolean isRowDirectory(JSObject obj);
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return (typeof obj === 'undefined') ? -1 : ((typeof obj.lastModified === 'undefined') ? -1 : obj.lastModified);")
|
||||
protected static native int readLastModified(JSObject obj);
|
||||
|
||||
@JSBody(params = { "obj" }, script = "return [obj];")
|
||||
private static native JSObject makeTheFuckingKeyWork(String k);
|
||||
|
||||
@Async
|
||||
protected static native ArrayBuffer readWholeFile(IDBDatabase db, String name);
|
||||
|
||||
private static void readWholeFile(IDBDatabase db, String name, final AsyncCallback<ArrayBuffer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(isRowDirectory(r.getResult()) ? null : readRow(r.getResult()));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(null);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native Integer readLastModified(IDBDatabase db, String name);
|
||||
|
||||
private static void readLastModified(IDBDatabase db, String name, final AsyncCallback<Integer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(readLastModified(r.getResult()));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(-1);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@JSBody(params = { "k" }, script = "return ((typeof k) === \"string\") ? k : (((typeof k) === \"undefined\") ? null : (((typeof k[0]) === \"string\") ? k[0] : null));")
|
||||
private static native String readKey(JSObject k);
|
||||
|
||||
@Async
|
||||
protected static native Integer iterateFiles(IDBDatabase db, final String prefix, final boolean listDirs, final boolean recursiveDirs, final Collection<FileEntry> lst);
|
||||
|
||||
private static void iterateFiles(IDBDatabase db, final String prefix, final boolean listDirs, final boolean recursiveDirs, final Collection<FileEntry> lst, final AsyncCallback<Integer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBCursorRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").openCursor();
|
||||
final int[] res = new int[1];
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
IDBCursor c = r.getResult();
|
||||
if(c == null || c.getKey() == null || c.getValue() == null) {
|
||||
cb.complete(res[0]);
|
||||
return;
|
||||
}
|
||||
String k = readKey(c.getKey());
|
||||
if(k != null) {
|
||||
if(k.startsWith(prefix)) {
|
||||
if(recursiveDirs || k.indexOf('/', prefix.length() + 1) == -1) {
|
||||
boolean dir = isRowDirectory(c.getValue());
|
||||
if(dir) {
|
||||
if(listDirs) {
|
||||
lst.add(new FileEntry(k, true, -1));
|
||||
}
|
||||
}else {
|
||||
lst.add(new FileEntry(k, false, eaglercraftEpoch + readLastModified(c.getValue())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
c.doContinue();
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(res[0] > 0 ? res[0] : -1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native BooleanResult fileExists(IDBDatabase db, String name);
|
||||
|
||||
private static void fileExists(IDBDatabase db, String name, final AsyncCallback<BooleanResult> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBCountRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").count(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(r.getResult() > 0));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native Integer fileGetLastModified(IDBDatabase db, String name);
|
||||
|
||||
private static void fileGetLastModified(IDBDatabase db, String name, final AsyncCallback<Integer> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(readLastModified(r.getResult()));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Async
|
||||
protected static native FileExists fileGetType(IDBDatabase db, String name);
|
||||
|
||||
private static void fileGetType(IDBDatabase db, String name, final AsyncCallback<FileExists> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readonly");
|
||||
final IDBGetRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").get(makeTheFuckingKeyWork(name));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(r.getResult() == null ? FileExists.FALSE : (isRowDirectory(r.getResult()) ? FileExists.DIRECTORY : FileExists.FILE));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(FileExists.FALSE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@JSBody(params = { "pat", "dir", "lm", "dat" }, script = "return { path: pat, directory: dir, lastModified: lm, data: dat };")
|
||||
protected static native JSObject writeRow(String name, boolean directory, int lm, ArrayBuffer data);
|
||||
|
||||
@Async
|
||||
protected static native BooleanResult writeWholeFile(IDBDatabase db, String name, boolean directory, ArrayBuffer data);
|
||||
|
||||
private static void writeWholeFile(IDBDatabase db, String name, boolean directory, ArrayBuffer data, final AsyncCallback<BooleanResult> cb) {
|
||||
IDBTransaction tx = db.transaction("filesystem", "readwrite");
|
||||
final IDBRequest r = IDBObjectStorePatched.objectStorePatch(tx, "filesystem").put(writeRow(name, directory, (int)(System.currentTimeMillis() - eaglercraftEpoch), data));
|
||||
r.setOnSuccess(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(true));
|
||||
}
|
||||
});
|
||||
r.setOnError(new EventHandler() {
|
||||
public void handleEvent() {
|
||||
cb.complete(BooleanResult._new(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,55 +0,0 @@
|
|||
package net.PeytonPlayz585.glemu;
|
||||
|
||||
public class GLObjectMap<T> {
|
||||
private Object[] values;
|
||||
private int size;
|
||||
private int insertIndex;
|
||||
public int allocatedObjects;
|
||||
|
||||
public GLObjectMap(int initialSize) {
|
||||
this.values = new Object[initialSize];
|
||||
this.size = initialSize;
|
||||
this.insertIndex = 0;
|
||||
this.allocatedObjects = 0;
|
||||
}
|
||||
|
||||
public int register(T obj) {
|
||||
int start = insertIndex;
|
||||
do {
|
||||
++insertIndex;
|
||||
if (insertIndex >= size) {
|
||||
insertIndex = 0;
|
||||
}
|
||||
if (insertIndex == start) {
|
||||
resize();
|
||||
return register(obj);
|
||||
}
|
||||
} while (values[insertIndex] != null);
|
||||
values[insertIndex] = obj;
|
||||
++allocatedObjects;
|
||||
return insertIndex;
|
||||
}
|
||||
|
||||
public T free(int obj) {
|
||||
if (obj >= size || obj < 0)
|
||||
return null;
|
||||
Object ret = values[obj];
|
||||
values[obj] = null;
|
||||
--allocatedObjects;
|
||||
return (T) ret;
|
||||
}
|
||||
|
||||
public T get(int obj) {
|
||||
if (obj >= size || obj < 0)
|
||||
return null;
|
||||
return (T) values[obj];
|
||||
}
|
||||
|
||||
private void resize() {
|
||||
int oldSize = size;
|
||||
size += size / 2;
|
||||
Object[] oldValues = values;
|
||||
values = new Object[size];
|
||||
System.arraycopy(oldValues, 0, values, 0, oldSize);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package net.PeytonPlayz585.glemu;
|
||||
|
||||
import static net.PeytonPlayz585.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL11.EaglerAdapterImpl2.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
package net.PeytonPlayz585.glemu;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import net.lax1dude.eaglercraft.GLAllocation;
|
||||
|
||||
/**
|
||||
* Utility class that emulates immediate mode vertex data submission.
|
||||
* Can be used to create VBO data.
|
||||
*/
|
||||
public final class ModeBuffer {
|
||||
|
||||
private FloatBuffer buffer;
|
||||
|
||||
public ModeBuffer(final int startSize) {
|
||||
this.buffer = GLAllocation.createDirectFloatBuffer(startSize);
|
||||
}
|
||||
|
||||
private void checkSize(final int count) {
|
||||
while ( buffer.remaining() < count ) {
|
||||
final FloatBuffer newBuffer = GLAllocation.createDirectFloatBuffer(buffer.capacity() << 1);
|
||||
buffer.flip();
|
||||
newBuffer.put(buffer);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public FloatBuffer getBuffer() {
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public void glVertex2f(final float x, final float y) {
|
||||
checkSize(2);
|
||||
buffer.put(x).put(y);
|
||||
}
|
||||
|
||||
public void glVertex3f(final float x, final float y, final float z) {
|
||||
checkSize(3);
|
||||
buffer.put(x).put(y).put(z);
|
||||
}
|
||||
|
||||
public void glVertex4f(final float x, final float y, final float z, final float w) {
|
||||
checkSize(4);
|
||||
buffer.put(x).put(y).put(z).put(w);
|
||||
}
|
||||
|
||||
public void glNormal3f(final float x, final float y, final float z) {
|
||||
checkSize(3);
|
||||
buffer.put(x).put(y).put(z);
|
||||
}
|
||||
|
||||
public void glTexCoord2f(final float s, final float t) {
|
||||
checkSize(2);
|
||||
buffer.put(s).put(t);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package net.PeytonPlayz585.glemu;
|
||||
|
||||
import static net.PeytonPlayz585.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL11.EaglerAdapterImpl2.*;
|
||||
|
||||
public class StreamBuffer {
|
||||
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for matrices. When a matrix is constructed it will be the identity
|
||||
* matrix unless otherwise stated.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
public abstract class Matrix implements Serializable {
|
||||
|
||||
/**
|
||||
* Constructor for Matrix.
|
||||
*/
|
||||
protected Matrix() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix setIdentity();
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix invert();
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix load(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (mathematical) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix loadTranspose(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix negate();
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column major
|
||||
* (openGL) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix store(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix storeTranspose(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix transpose();
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix setZero();
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public abstract float determinant();
|
||||
|
||||
}
|
|
@ -1,418 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 2x2 matrix
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Matrix2f extends Matrix implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float m00, m01, m10, m11;
|
||||
|
||||
/**
|
||||
* Constructor for Matrix2f. The matrix is initialised to the identity.
|
||||
*/
|
||||
public Matrix2f() {
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Matrix2f(Matrix2f src) {
|
||||
load(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another matrix
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @return this
|
||||
*/
|
||||
public Matrix2f load(Matrix2f src) {
|
||||
return load(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the source matrix to the destination matrix.
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new one should be created.
|
||||
* @return The copied matrix
|
||||
*/
|
||||
public static Matrix2f load(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = src.m00;
|
||||
dest.m01 = src.m01;
|
||||
dest.m10 = src.m10;
|
||||
dest.m11 = src.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (mathematical) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column major
|
||||
* (openGL) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the right matrix from the left and place the result in a third
|
||||
* matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the right matrix by the left and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
float m00 = left.m00 * right.m00 + left.m10 * right.m01;
|
||||
float m01 = left.m01 * right.m00 + left.m11 * right.m01;
|
||||
float m10 = left.m00 * right.m10 + left.m10 * right.m11;
|
||||
float m11 = left.m01 * right.m10 + left.m11 * right.m11;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Vector by a matrix and return the result in a destination vector.
|
||||
*
|
||||
* @param left The left matrix
|
||||
* @param right The right vector
|
||||
* @param dest The destination vector, or null if a new one is to be created
|
||||
* @return the destination vector
|
||||
*/
|
||||
public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector2f();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y;
|
||||
float y = left.m01 * right.x + left.m11 * right.y;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix transpose() {
|
||||
return transpose(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix and place the result in another matrix.
|
||||
*
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public Matrix2f transpose(Matrix2f dest) {
|
||||
return transpose(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose the source matrix and place the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix or null if a new matrix is to be created
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public static Matrix2f transpose(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
float m01 = src.m10;
|
||||
float m10 = src.m01;
|
||||
|
||||
dest.m01 = m01;
|
||||
dest.m10 = m10;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
*
|
||||
* @return this if successful, null otherwise
|
||||
*/
|
||||
public Matrix invert() {
|
||||
return invert(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the source matrix and place the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix to be inverted
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return The inverted matrix, or null if source can't be reverted.
|
||||
*/
|
||||
public static Matrix2f invert(Matrix2f src, Matrix2f dest) {
|
||||
/*
|
||||
* inv(A) = 1/det(A) * adj(A);
|
||||
*/
|
||||
|
||||
float determinant = src.determinant();
|
||||
if (determinant != 0) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
float determinant_inv = 1f / determinant;
|
||||
float t00 = src.m11 * determinant_inv;
|
||||
float t01 = -src.m01 * determinant_inv;
|
||||
float t11 = src.m00 * determinant_inv;
|
||||
float t10 = -src.m10 * determinant_inv;
|
||||
|
||||
dest.m00 = t00;
|
||||
dest.m01 = t01;
|
||||
dest.m10 = t10;
|
||||
dest.m11 = t11;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this matrix
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(m00).append(' ').append(m10).append(' ').append('\n');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append('\n');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and stash the result in another matrix.
|
||||
*
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public Matrix2f negate(Matrix2f dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the source matrix and stash the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix to be negated
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public static Matrix2f negate(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m01;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source matrix to be the identity matrix.
|
||||
*
|
||||
* @param src The matrix to set to the identity.
|
||||
* @return The source matrix
|
||||
*/
|
||||
public static Matrix2f setIdentity(Matrix2f src) {
|
||||
src.m00 = 1.0f;
|
||||
src.m01 = 0.0f;
|
||||
src.m10 = 0.0f;
|
||||
src.m11 = 1.0f;
|
||||
return src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setZero() {
|
||||
return setZero(this);
|
||||
}
|
||||
|
||||
public static Matrix2f setZero(Matrix2f src) {
|
||||
src.m00 = 0.0f;
|
||||
src.m01 = 0.0f;
|
||||
src.m10 = 0.0f;
|
||||
src.m11 = 0.0f;
|
||||
return src;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Matrix#determinant()
|
||||
*/
|
||||
public float determinant() {
|
||||
return m00 * m11 - m01 * m10;
|
||||
}
|
||||
}
|
|
@ -1,529 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 3x3 matrix.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Matrix3f extends Matrix implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float m00, m01, m02, m10, m11, m12, m20, m21, m22;
|
||||
|
||||
/**
|
||||
* Constructor for Matrix3f. Matrix is initialised to the identity.
|
||||
*/
|
||||
public Matrix3f() {
|
||||
super();
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another matrix
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @return this
|
||||
*/
|
||||
public Matrix3f load(Matrix3f src) {
|
||||
return load(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy source matrix to destination matrix
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null of a new matrix is to be created
|
||||
* @return The copied matrix
|
||||
*/
|
||||
public static Matrix3f load(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = src.m00;
|
||||
dest.m10 = src.m10;
|
||||
dest.m20 = src.m20;
|
||||
dest.m01 = src.m01;
|
||||
dest.m11 = src.m11;
|
||||
dest.m21 = src.m21;
|
||||
dest.m02 = src.m02;
|
||||
dest.m12 = src.m12;
|
||||
dest.m22 = src.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m02 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
m12 = buf.get();
|
||||
m20 = buf.get();
|
||||
m21 = buf.get();
|
||||
m22 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major (maths)
|
||||
* order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m20 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
m21 = buf.get();
|
||||
m02 = buf.get();
|
||||
m12 = buf.get();
|
||||
m22 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column major
|
||||
* (openGL) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m02);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
buf.put(m12);
|
||||
buf.put(m20);
|
||||
buf.put(m21);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matrix store(float[] buf) {
|
||||
buf[0] = m00;
|
||||
buf[1] = m01;
|
||||
buf[2] = m02;
|
||||
buf[3] = m10;
|
||||
buf[4] = m11;
|
||||
buf[5] = m12;
|
||||
buf[6] = m20;
|
||||
buf[7] = m21;
|
||||
buf[8] = m22;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m20);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
buf.put(m21);
|
||||
buf.put(m02);
|
||||
buf.put(m12);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f add(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m02 = left.m02 + right.m02;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
dest.m12 = left.m12 + right.m12;
|
||||
dest.m20 = left.m20 + right.m20;
|
||||
dest.m21 = left.m21 + right.m21;
|
||||
dest.m22 = left.m22 + right.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the right matrix from the left and place the result in a third
|
||||
* matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f sub(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m02 = left.m02 - right.m02;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
dest.m12 = left.m12 - right.m12;
|
||||
dest.m20 = left.m20 - right.m20;
|
||||
dest.m21 = left.m21 - right.m21;
|
||||
dest.m22 = left.m22 - right.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the right matrix by the left and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f mul(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02;
|
||||
float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02;
|
||||
float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02;
|
||||
float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12;
|
||||
float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12;
|
||||
float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12;
|
||||
float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22;
|
||||
float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22;
|
||||
float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Vector by a matrix and return the result in a destination vector.
|
||||
*
|
||||
* @param left The left matrix
|
||||
* @param right The right vector
|
||||
* @param dest The destination vector, or null if a new one is to be created
|
||||
* @return the destination vector
|
||||
*/
|
||||
public static Vector3f transform(Matrix3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z;
|
||||
float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z;
|
||||
float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
dest.z = z;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix transpose() {
|
||||
return transpose(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix and place the result in another matrix
|
||||
*
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public Matrix3f transpose(Matrix3f dest) {
|
||||
return transpose(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose the source matrix and place the result into the destination matrix
|
||||
*
|
||||
* @param src The source matrix to be transposed
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public static Matrix3f transpose(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
float m00 = src.m00;
|
||||
float m01 = src.m10;
|
||||
float m02 = src.m20;
|
||||
float m10 = src.m01;
|
||||
float m11 = src.m11;
|
||||
float m12 = src.m21;
|
||||
float m20 = src.m02;
|
||||
float m21 = src.m12;
|
||||
float m22 = src.m22;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public float determinant() {
|
||||
float f = m00 * (m11 * m22 - m12 * m21) + m01 * (m12 * m20 - m10 * m22) + m02 * (m10 * m21 - m11 * m20);
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this matrix
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append('\n');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append('\n');
|
||||
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append('\n');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
*
|
||||
* @return this if successful, null otherwise
|
||||
*/
|
||||
public Matrix invert() {
|
||||
return invert(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the source matrix and put the result into the destination matrix
|
||||
*
|
||||
* @param src The source matrix to be inverted
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return The inverted matrix if successful, null otherwise
|
||||
*/
|
||||
public static Matrix3f invert(Matrix3f src, Matrix3f dest) {
|
||||
float determinant = src.determinant();
|
||||
|
||||
if (determinant != 0) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
/*
|
||||
* do it the ordinary way
|
||||
*
|
||||
* inv(A) = 1/det(A) * adj(T), where adj(T) = transpose(Conjugate Matrix)
|
||||
*
|
||||
* m00 m01 m02 m10 m11 m12 m20 m21 m22
|
||||
*/
|
||||
float determinant_inv = 1f / determinant;
|
||||
|
||||
// get the conjugate matrix
|
||||
float t00 = src.m11 * src.m22 - src.m12 * src.m21;
|
||||
float t01 = -src.m10 * src.m22 + src.m12 * src.m20;
|
||||
float t02 = src.m10 * src.m21 - src.m11 * src.m20;
|
||||
float t10 = -src.m01 * src.m22 + src.m02 * src.m21;
|
||||
float t11 = src.m00 * src.m22 - src.m02 * src.m20;
|
||||
float t12 = -src.m00 * src.m21 + src.m01 * src.m20;
|
||||
float t20 = src.m01 * src.m12 - src.m02 * src.m11;
|
||||
float t21 = -src.m00 * src.m12 + src.m02 * src.m10;
|
||||
float t22 = src.m00 * src.m11 - src.m01 * src.m10;
|
||||
|
||||
dest.m00 = t00 * determinant_inv;
|
||||
dest.m11 = t11 * determinant_inv;
|
||||
dest.m22 = t22 * determinant_inv;
|
||||
dest.m01 = t10 * determinant_inv;
|
||||
dest.m10 = t01 * determinant_inv;
|
||||
dest.m20 = t02 * determinant_inv;
|
||||
dest.m02 = t20 * determinant_inv;
|
||||
dest.m12 = t21 * determinant_inv;
|
||||
dest.m21 = t12 * determinant_inv;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and place the result in a destination matrix.
|
||||
*
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public Matrix3f negate(Matrix3f dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the source matrix and place the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public static Matrix3f negate(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m02;
|
||||
dest.m02 = -src.m01;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m12;
|
||||
dest.m12 = -src.m11;
|
||||
dest.m20 = -src.m20;
|
||||
dest.m21 = -src.m22;
|
||||
dest.m22 = -src.m21;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix to be the identity matrix.
|
||||
*
|
||||
* @param m The matrix to be set to the identity
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix3f setIdentity(Matrix3f m) {
|
||||
m.m00 = 1.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 1.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 1.0f;
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setZero() {
|
||||
return setZero(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix matrix to 0.
|
||||
*
|
||||
* @param m The matrix to be set to 0
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix3f setZero(Matrix3f m) {
|
||||
m.m00 = 0.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 0.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 0.0f;
|
||||
return m;
|
||||
}
|
||||
|
||||
public boolean equals(Object m) {
|
||||
return (m instanceof Matrix3f) && equal(this, (Matrix3f) m);
|
||||
}
|
||||
|
||||
public static boolean equal(Matrix3f a, Matrix3f b) {
|
||||
return a.m00 == b.m00 && a.m01 == b.m01 && a.m02 == b.m02 && a.m10 == b.m10 && a.m11 == b.m11 && a.m12 == b.m12
|
||||
&& a.m20 == b.m20 && a.m21 == b.m21 && a.m22 == b.m22;
|
||||
}
|
||||
}
|
|
@ -1,506 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* Quaternions for LWJGL!
|
||||
*
|
||||
* @author fbi
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class Quaternion extends Vector implements ReadableVector4f {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z, w;
|
||||
|
||||
/**
|
||||
* C'tor. The quaternion will be initialized to the identity.
|
||||
*/
|
||||
public Quaternion() {
|
||||
super();
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*
|
||||
* @param src
|
||||
*/
|
||||
public Quaternion(ReadableVector4f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*
|
||||
*/
|
||||
public Quaternion(float x, float y, float z, float w) {
|
||||
set(x, y, z, w);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector4f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Quaternion set(ReadableVector4f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
w = src.getW();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this quaternion to the multiplication identity.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Quaternion setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given quaternion to the multiplication identity.
|
||||
*
|
||||
* @param q The quaternion
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setIdentity(Quaternion q) {
|
||||
q.x = 0;
|
||||
q.y = 0;
|
||||
q.z = 0;
|
||||
q.w = 1;
|
||||
return q;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the quaternion
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise the source quaternion and place the result in another quaternion.
|
||||
*
|
||||
* @param src The source quaternion
|
||||
* @param dest The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return The normalised quaternion
|
||||
*/
|
||||
public static Quaternion normalise(Quaternion src, Quaternion dest) {
|
||||
float inv_l = 1f / src.length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
|
||||
dest.set(src.x * inv_l, src.y * inv_l, src.z * inv_l, src.w * inv_l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this quaternion and place the result in another quaternion.
|
||||
*
|
||||
* @param dest The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return the normalised quaternion
|
||||
*/
|
||||
public Quaternion normalise(Quaternion dest) {
|
||||
return normalise(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two quaternions
|
||||
*
|
||||
* @param left The LHS quat
|
||||
* @param right The RHS quat
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Quaternion left, Quaternion right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion and put it into the given one
|
||||
*
|
||||
* @param dest The quaternion which should be set to the conjugate of this
|
||||
* quaternion
|
||||
*/
|
||||
public Quaternion negate(Quaternion dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion and put it into the given one
|
||||
*
|
||||
* @param src The source quaternion
|
||||
* @param dest The quaternion which should be set to the conjugate of this
|
||||
* quaternion
|
||||
*/
|
||||
public static Quaternion negate(Quaternion src, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
|
||||
dest.x = -src.x;
|
||||
dest.y = -src.y;
|
||||
dest.z = -src.z;
|
||||
dest.w = src.w;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion
|
||||
*/
|
||||
public Vector negate() {
|
||||
return negate(this, this);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.Vector#load(java.nio.FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
return scale(scale, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale the source quaternion by scale and put the result in the destination
|
||||
*
|
||||
* @param scale The amount to scale by
|
||||
* @param src The source quaternion
|
||||
* @param dest The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return The scaled quaternion
|
||||
*/
|
||||
public static Quaternion scale(float scale, Quaternion src, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.x = src.x * scale;
|
||||
dest.y = src.y * scale;
|
||||
dest.z = src.z * scale;
|
||||
dest.w = src.w * scale;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.ReadableVector#store(java.nio.FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
buf.put(w);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set W
|
||||
*
|
||||
* @param w
|
||||
*/
|
||||
public void setW(float w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getW()
|
||||
*/
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Quaternion: " + x + " " + y + " " + z + " " + w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion to the quaternion product of quaternions
|
||||
* left and right (this = left * right). Note that this is safe for aliasing
|
||||
* (e.g. this can be left or right).
|
||||
*
|
||||
* @param left the first quaternion
|
||||
* @param right the second quaternion
|
||||
*/
|
||||
public static Quaternion mul(Quaternion left, Quaternion right, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.set(left.x * right.w + left.w * right.x + left.y * right.z - left.z * right.y,
|
||||
left.y * right.w + left.w * right.y + left.z * right.x - left.x * right.z,
|
||||
left.z * right.w + left.w * right.z + left.x * right.y - left.y * right.x,
|
||||
left.w * right.w - left.x * right.x - left.y * right.y - left.z * right.z);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Multiplies quaternion left by the inverse of quaternion right and places the
|
||||
* value into this quaternion. The value of both argument quaternions is
|
||||
* preservered (this = left * right^-1).
|
||||
*
|
||||
* @param left the left quaternion
|
||||
* @param right the right quaternion
|
||||
*/
|
||||
public static Quaternion mulInverse(Quaternion left, Quaternion right, Quaternion dest) {
|
||||
float n = right.lengthSquared();
|
||||
// zero-div may occur.
|
||||
n = (n == 0.0 ? n : 1 / n);
|
||||
// store on stack once for aliasing-safty
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.set((left.x * right.w - left.w * right.x - left.y * right.z + left.z * right.y) * n,
|
||||
(left.y * right.w - left.w * right.y - left.z * right.x + left.x * right.z) * n,
|
||||
(left.z * right.w - left.w * right.z - left.x * right.y + left.y * right.x) * n,
|
||||
(left.w * right.w + left.x * right.x + left.y * right.y + left.z * right.z) * n);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion to the equivalent rotation of the
|
||||
* Axis-Angle argument.
|
||||
*
|
||||
* @param a1 the axis-angle: (x,y,z) is the axis and w is the angle
|
||||
*/
|
||||
public final void setFromAxisAngle(Vector4f a1) {
|
||||
x = a1.x;
|
||||
y = a1.y;
|
||||
z = a1.z;
|
||||
float n = (float) Math.sqrt(x * x + y * y + z * z);
|
||||
// zero-div may occur.
|
||||
float s = (float) (Math.sin(0.5 * a1.w) / n);
|
||||
x *= s;
|
||||
y *= s;
|
||||
z *= s;
|
||||
w = (float) Math.cos(0.5 * a1.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The matrix
|
||||
* @return this
|
||||
*/
|
||||
public final Quaternion setFromMatrix(Matrix4f m) {
|
||||
return setFromMatrix(m, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the source quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The source matrix
|
||||
* @param q The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setFromMatrix(Matrix4f m, Quaternion q) {
|
||||
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The source matrix
|
||||
*/
|
||||
public final Quaternion setFromMatrix(Matrix3f m) {
|
||||
return setFromMatrix(m, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the source quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The source matrix
|
||||
* @param q The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setFromMatrix(Matrix3f m, Quaternion q) {
|
||||
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private method to perform the matrix-to-quaternion conversion
|
||||
*/
|
||||
private Quaternion setFromMat(float m00, float m01, float m02, float m10, float m11, float m12, float m20,
|
||||
float m21, float m22) {
|
||||
|
||||
float s;
|
||||
float tr = m00 + m11 + m22;
|
||||
if (tr >= 0.0) {
|
||||
s = (float) Math.sqrt(tr + 1.0);
|
||||
w = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
x = (m21 - m12) * s;
|
||||
y = (m02 - m20) * s;
|
||||
z = (m10 - m01) * s;
|
||||
} else {
|
||||
float max = Math.max(Math.max(m00, m11), m22);
|
||||
if (max == m00) {
|
||||
s = (float) Math.sqrt(m00 - (m11 + m22) + 1.0);
|
||||
x = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
y = (m01 + m10) * s;
|
||||
z = (m20 + m02) * s;
|
||||
w = (m21 - m12) * s;
|
||||
} else if (max == m11) {
|
||||
s = (float) Math.sqrt(m11 - (m22 + m00) + 1.0);
|
||||
y = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
z = (m12 + m21) * s;
|
||||
x = (m01 + m10) * s;
|
||||
w = (m02 - m20) * s;
|
||||
} else {
|
||||
s = (float) Math.sqrt(m22 - (m00 + m11) + 1.0);
|
||||
z = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
x = (m20 + m02) * s;
|
||||
y = (m12 + m21) * s;
|
||||
w = (m10 - m01) * s;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector {
|
||||
/**
|
||||
* @return the length of the vector
|
||||
*/
|
||||
float length();
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
float lengthSquared();
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
Vector store(FloatBuffer buf);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector2f extends ReadableVector {
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
float getY();
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector3f extends ReadableVector2f {
|
||||
/**
|
||||
* @return z
|
||||
*/
|
||||
float getZ();
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector4f extends ReadableVector3f {
|
||||
|
||||
/**
|
||||
* @return w
|
||||
*/
|
||||
float getW();
|
||||
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for vectors.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
public abstract class Vector implements Serializable, ReadableVector {
|
||||
|
||||
/**
|
||||
* Constructor for Vector.
|
||||
*/
|
||||
protected Vector() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length of the vector
|
||||
*/
|
||||
public final float length() {
|
||||
return (float) Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public abstract float lengthSquared();
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector load(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector negate();
|
||||
|
||||
/**
|
||||
* Normalise this vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final Vector normalise() {
|
||||
float len = length();
|
||||
if (len != 0.0f) {
|
||||
float l = 1.0f / len;
|
||||
return scale(l);
|
||||
} else
|
||||
throw new IllegalStateException("Zero length vector");
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector store(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Scale this vector
|
||||
*
|
||||
* @param scale The scale factor
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector scale(float scale);
|
||||
|
||||
}
|
|
@ -1,319 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 2-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y;
|
||||
|
||||
/**
|
||||
* Constructor for Vector2f.
|
||||
*/
|
||||
public Vector2f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Vector2f(ReadableVector2f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Vector2f(float x, float y) {
|
||||
set(x, y);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector2f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f set(ReadableVector2f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
*
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f translate(float x, float y) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
*
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector2f negate(Vector2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector2f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
*
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector2f normalise(Vector2f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector2f(x / l, y / l);
|
||||
else
|
||||
dest.set(x / l, y / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y +
|
||||
* v1.z * v2.z
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector2f left, Vector2f right) {
|
||||
return left.x * right.x + left.y * right.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
*
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector2f a, Vector2f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.acos(dls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x + right.x, left.y + right.y);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x - right.x, left.y - right.y);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
|
||||
sb.append("Vector2f[");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
sb.append(y);
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Vector2f other = (Vector2f) obj;
|
||||
|
||||
if (x == other.x && y == other.y)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,376 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 3-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Vector3f extends Vector implements Serializable, ReadableVector3f, WritableVector3f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z;
|
||||
|
||||
/**
|
||||
* Constructor for Vector3f.
|
||||
*/
|
||||
public Vector3f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector3f(ReadableVector3f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector3f(float x, float y, float z) {
|
||||
set(x, y, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector3f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector3f set(ReadableVector3f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
*
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector3f translate(float x, float y, float z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The cross product of two vectors.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination result, or null if a new vector is to be created
|
||||
* @return left cross right
|
||||
*/
|
||||
public static Vector3f cross(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
|
||||
dest.set(left.y * right.z - left.z * right.y, right.x * left.z - right.z * left.x,
|
||||
left.x * right.y - left.y * right.x);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
*
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector3f negate(Vector3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
dest.z = -z;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
*
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector3f normalise(Vector3f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f(x / l, y / l, z / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y +
|
||||
* v1.z * v2.z
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector3f left, Vector3f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
*
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector3f a, Vector3f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.acos(dls);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
|
||||
sb.append("Vector3f[");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
sb.append(y);
|
||||
sb.append(", ");
|
||||
sb.append(z);
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Vector3f other = (Vector3f) obj;
|
||||
|
||||
if (x == other.x && y == other.y && z == other.z)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,377 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 4-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Vector4f extends Vector implements Serializable, ReadableVector4f, WritableVector4f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z, w;
|
||||
|
||||
/**
|
||||
* Constructor for Vector4f.
|
||||
*/
|
||||
public Vector4f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector4f(ReadableVector4f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector4f(float x, float y, float z, float w) {
|
||||
set(x, y, z, w);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector4f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f set(ReadableVector4f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
w = src.getW();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
*
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f translate(float x, float y, float z, float w) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
this.w += w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
w = -w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
*
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector4f negate(Vector4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector4f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
dest.z = -z;
|
||||
dest.w = -w;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
*
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector4f normalise(Vector4f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector4f(x / l, y / l, z / l, w / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l, w / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y +
|
||||
* v1.z * v2.z + v1.w * v2.w
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector4f left, Vector4f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
*
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector4f a, Vector4f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.acos(dls);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
w *= scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
buf.put(w);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Vector4f: " + x + " " + y + " " + z + " " + w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set W
|
||||
*
|
||||
* @param w
|
||||
*/
|
||||
public void setW(float w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Vector4f other = (Vector4f) obj;
|
||||
|
||||
if (x == other.x && y == other.y && z == other.z && w == other.w)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector2fs
|
||||
*
|
||||
* @author $author$
|
||||
* @version $revision$ $Id$
|
||||
*/
|
||||
public interface WritableVector2f {
|
||||
|
||||
/**
|
||||
* Set the X value
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Set the Y value
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
void setY(float y);
|
||||
|
||||
/**
|
||||
* Set the X,Y values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
void set(float x, float y);
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector3fs
|
||||
*
|
||||
* @author $author$
|
||||
* @version $revision$ $Id$
|
||||
*/
|
||||
public interface WritableVector3f extends WritableVector2f {
|
||||
|
||||
/**
|
||||
* Set the Z value
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
void setZ(float z);
|
||||
|
||||
/**
|
||||
* Set the X,Y,Z values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
void set(float x, float y, float z);
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector4fs
|
||||
*
|
||||
* @author $author$
|
||||
* @version $revision$ $Id$
|
||||
*/
|
||||
public interface WritableVector4f extends WritableVector3f {
|
||||
|
||||
/**
|
||||
* Set the W value
|
||||
*
|
||||
* @param w
|
||||
*/
|
||||
void setW(float w);
|
||||
|
||||
/**
|
||||
* Set the X,Y,Z,W values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param w
|
||||
*/
|
||||
void set(float x, float y, float z, float w);
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package net.PeytonPlayz585.input;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
|
||||
public class Keyboard extends GL11 {
|
||||
|
||||
public static boolean next() {
|
||||
return keysNext();
|
||||
}
|
||||
|
||||
public static char getEventCharacter() {
|
||||
return getEventChar();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package net.PeytonPlayz585.input;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
|
||||
public class Mouse extends GL11 {
|
||||
|
||||
public static int getX() {
|
||||
return mouseGetX();
|
||||
}
|
||||
|
||||
public static int getY() {
|
||||
return mouseGetY();
|
||||
}
|
||||
|
||||
public static boolean next() {
|
||||
return mouseNext();
|
||||
}
|
||||
|
||||
public static boolean getEventButtonState() {
|
||||
return mouseGetEventButtonState();
|
||||
}
|
||||
|
||||
public static int getEventX() {
|
||||
return mouseGetEventX();
|
||||
}
|
||||
|
||||
|
||||
public static int getEventY() {
|
||||
return mouseGetEventY();
|
||||
}
|
||||
|
||||
public static int getEventButton() {
|
||||
return mouseGetEventButton();
|
||||
}
|
||||
|
||||
public static int getDX() {
|
||||
return mouseGetDX();
|
||||
}
|
||||
|
||||
public static int getDY() {
|
||||
return mouseGetDY();
|
||||
}
|
||||
|
||||
public static void setGrabbed(boolean b) {
|
||||
mouseSetGrabbed(b);
|
||||
}
|
||||
|
||||
public static boolean isButtonDown(int i) {
|
||||
return mouseIsButtonDown(i);
|
||||
}
|
||||
|
||||
public static int getEventDWheel() {
|
||||
return mouseGetEventDWheel();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
@ -1713,4 +1713,4 @@ public class JSONArray implements Iterable<Object> {
|
|||
, cause);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
@ -66,4 +66,4 @@ public class JSONException extends RuntimeException {
|
|||
super(cause.getMessage(), cause);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
|
@ -2233,7 +2233,7 @@ public class JSONObject {
|
|||
try {
|
||||
BigDecimal bd = new BigDecimal(val);
|
||||
if(initial == '-' && BigDecimal.ZERO.compareTo(bd)==0) {
|
||||
return Double.valueOf(0D);
|
||||
return Double.valueOf(-0.0);
|
||||
}
|
||||
return bd;
|
||||
} catch (NumberFormatException retryAsDouble) {
|
||||
|
@ -2729,4 +2729,4 @@ public class JSONObject {
|
|||
"JavaBean object contains recursively defined member variable of key " + quote(key)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
|
@ -292,4 +292,4 @@ public class JSONPointer {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
@ -42,4 +42,4 @@ public class JSONPointerException extends JSONException {
|
|||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2018 JSON.org
|
||||
|
@ -40,4 +40,4 @@ import java.lang.annotation.Target;
|
|||
* present at any level in the class hierarchy, then the method will
|
||||
* not be serialized from the bean into the JSONObject.
|
||||
*/
|
||||
public @interface JSONPropertyIgnore { }
|
||||
public @interface JSONPropertyIgnore { }
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2018 JSON.org
|
||||
|
@ -44,4 +44,4 @@ public @interface JSONPropertyName {
|
|||
* @return The name of the property as to be used in the JSON Object.
|
||||
*/
|
||||
String value();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
@ -40,4 +40,4 @@ public interface JSONString {
|
|||
* @return A strictly syntactically correct JSON text.
|
||||
*/
|
||||
public String toJSONString();
|
||||
}
|
||||
}
|
79
src/net/PeytonPlayz585/json/JSONStringer.java
Normal file
79
src/net/PeytonPlayz585/json/JSONStringer.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2006 JSON.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
The Software shall be used for Good, not Evil.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* JSONStringer provides a quick and convenient way of producing JSON text.
|
||||
* The texts produced strictly conform to JSON syntax rules. No whitespace is
|
||||
* added, so the results are ready for transmission or storage. Each instance of
|
||||
* JSONStringer can produce one JSON text.
|
||||
* <p>
|
||||
* A JSONStringer instance provides a <code>value</code> method for appending
|
||||
* values to the
|
||||
* text, and a <code>key</code>
|
||||
* method for adding keys before values in objects. There are <code>array</code>
|
||||
* and <code>endArray</code> methods that make and bound array values, and
|
||||
* <code>object</code> and <code>endObject</code> methods which make and bound
|
||||
* object values. All of these methods return the JSONWriter instance,
|
||||
* permitting cascade style. For example, <pre>
|
||||
* myString = new JSONStringer()
|
||||
* .object()
|
||||
* .key("JSON")
|
||||
* .value("Hello, World!")
|
||||
* .endObject()
|
||||
* .toString();</pre> which produces the string <pre>
|
||||
* {"JSON":"Hello, World!"}</pre>
|
||||
* <p>
|
||||
* The first method called must be <code>array</code> or <code>object</code>.
|
||||
* There are no methods for adding commas or colons. JSONStringer adds them for
|
||||
* you. Objects and arrays can be nested up to 200 levels deep.
|
||||
* <p>
|
||||
* This can sometimes be easier than using a JSONObject to build a string.
|
||||
* @author JSON.org
|
||||
* @version 2015-12-09
|
||||
*/
|
||||
public class JSONStringer extends JSONWriter {
|
||||
/**
|
||||
* Make a fresh JSONStringer. It can be used to build one JSON text.
|
||||
*/
|
||||
public JSONStringer() {
|
||||
super(new StringWriter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JSON text. This method is used to obtain the product of the
|
||||
* JSONStringer instance. It will return <code>null</code> if there was a
|
||||
* problem in the construction of the JSON text (such as the calls to
|
||||
* <code>array</code> were not properly balanced with calls to
|
||||
* <code>endArray</code>).
|
||||
* @return The JSON text.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.mode == 'd' ? this.writer.toString() : null;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
@ -542,4 +542,4 @@ public class JSONTokener {
|
|||
return " at " + this.index + " [character " + this.character + " line " +
|
||||
this.line + "]";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
@ -411,4 +411,4 @@ public class JSONWriter {
|
|||
public JSONWriter value(Object object) throws JSONException {
|
||||
return this.append(valueToString(object));
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +0,0 @@
|
|||
package net.PeytonPlayz585.opengl;
|
||||
|
||||
public class GL11 extends EaglerAdapterGL30 {
|
||||
|
||||
public static void glPixelStorei(int glUnpackAlignment, int i) {
|
||||
_wglPixelStorei(glUnpackAlignment, i);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package net.PeytonPlayz585.opengl;
|
||||
|
||||
public class GL12 extends GL11 {
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,8 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.CompressedStreamTools;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
@ -26,7 +27,7 @@ public class Profile {
|
|||
}
|
||||
|
||||
public static void read() {
|
||||
read(EaglerAdapterImpl2.loadLocalStorage("P"));
|
||||
read(GL11.EaglerAdapterImpl2.loadLocalStorage("P"));
|
||||
}
|
||||
|
||||
public static void read(byte[] profileStorage) {
|
||||
|
@ -67,7 +68,7 @@ public class Profile {
|
|||
public static void save() {
|
||||
byte[] b = write();
|
||||
if(b != null) {
|
||||
EaglerAdapterImpl2.saveLocalStorage("P", b);
|
||||
GL11.EaglerAdapterImpl2.saveLocalStorage("P", b);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,4 +76,4 @@ public class Profile {
|
|||
read();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -2,12 +2,12 @@ package net.PeytonPlayz585.socket;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class Socket {
|
||||
|
||||
public Socket(String hostName, int port) throws IOException {
|
||||
if(!EaglerAdapterImpl2.startConnection(hostName + ":" + port)) {
|
||||
if(!GL11.EaglerAdapterImpl2.startConnection(hostName + ":" + port)) {
|
||||
IOException e = new IOException("Connection failed: " + hostName + ":" + port);
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
|
@ -15,7 +15,7 @@ public class Socket {
|
|||
}
|
||||
|
||||
public Socket(String hostName) throws IOException {
|
||||
if(!EaglerAdapterImpl2.startConnection(hostName)) {
|
||||
if(!GL11.EaglerAdapterImpl2.startConnection(hostName)) {
|
||||
IOException e = new IOException("Connection failed: " + hostName);
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
|
@ -24,13 +24,13 @@ public class Socket {
|
|||
|
||||
public void write(byte[] data) {
|
||||
if(socketOpen()) {
|
||||
EaglerAdapterImpl2.writePacket(data);
|
||||
GL11.EaglerAdapterImpl2.writePacket(data);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] read() {
|
||||
if(socketOpen()) {
|
||||
return EaglerAdapterImpl2.readPacket();
|
||||
return GL11.EaglerAdapterImpl2.readPacket();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ public class Socket {
|
|||
|
||||
public void close() {
|
||||
if(socketOpen()) {
|
||||
EaglerAdapterImpl2.endConnection();
|
||||
GL11.EaglerAdapterImpl2.endConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean socketOpen() {
|
||||
return EaglerAdapterImpl2.connectionOpen();
|
||||
return GL11.EaglerAdapterImpl2.connectionOpen();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package net.PeytonPlayz585.storage;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz595.nbt.NBTBase;
|
||||
import net.PeytonPlayz595.nbt.NBTTagCompound;
|
||||
import net.lax1dude.eaglercraft.Base64;
|
||||
|
||||
public class LocalStorageManager {
|
||||
|
||||
public static NBTTagCompound gameSettingsStorage = null;
|
||||
public static NBTTagCompound levelSettingsStorage = null;
|
||||
|
||||
public static void loadStorage() {
|
||||
byte[] g = GL11.loadLocalStorage("g");
|
||||
byte[] p = GL11.loadLocalStorage("p");
|
||||
|
||||
if(g != null) {
|
||||
try {
|
||||
NBTBase t = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(g)));
|
||||
if(t != null && t instanceof NBTTagCompound) {
|
||||
gameSettingsStorage = (NBTTagCompound)t;
|
||||
}
|
||||
}catch(IOException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if(p != null) {
|
||||
try {
|
||||
NBTBase t = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(p)));
|
||||
if(t != null && t instanceof NBTTagCompound) {
|
||||
levelSettingsStorage = (NBTTagCompound)t;
|
||||
}
|
||||
}catch(IOException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if(gameSettingsStorage == null) gameSettingsStorage = new NBTTagCompound();
|
||||
if(levelSettingsStorage == null) levelSettingsStorage = new NBTTagCompound();
|
||||
|
||||
}
|
||||
|
||||
public static void saveStorageG() {
|
||||
try {
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
NBTBase.writeTag(gameSettingsStorage, new DataOutputStream(s));
|
||||
GL11.saveLocalStorage("g", s.toByteArray());
|
||||
} catch (IOException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveStorageP() {
|
||||
try {
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
NBTBase.writeTag(levelSettingsStorage, new DataOutputStream(s));
|
||||
GL11.saveLocalStorage("p", s.toByteArray());
|
||||
} catch (IOException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public static String dumpConfiguration() {
|
||||
try {
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
NBTBase.writeTag(gameSettingsStorage, new DataOutputStream(s));
|
||||
return Base64.encodeBase64String(s.toByteArray());
|
||||
} catch(Throwable e) {
|
||||
return "<error>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package net.PeytonPlayz585.util.glu;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
|
||||
public class GLU extends GL11 {
|
||||
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTBase {
|
||||
|
||||
public NBTBase() {
|
||||
key = null;
|
||||
}
|
||||
|
||||
abstract void writeTagContents(DataOutput dataoutput) throws IOException;
|
||||
|
||||
abstract void readTagContents(DataInput datainput) throws IOException;
|
||||
|
||||
public abstract byte getType();
|
||||
|
||||
public String getKey() {
|
||||
if (key == null) {
|
||||
return "";
|
||||
} else {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public NBTBase setKey(String s) {
|
||||
key = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static NBTBase readTag(DataInput datainput) throws IOException {
|
||||
byte byte0 = datainput.readByte();
|
||||
if (byte0 == 0) {
|
||||
return new NBTTagEnd();
|
||||
} else {
|
||||
NBTBase nbtbase = createTagOfType(byte0);
|
||||
nbtbase.key = datainput.readUTF();
|
||||
nbtbase.readTagContents(datainput);
|
||||
return nbtbase;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeTag(NBTBase nbtbase, DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeByte(nbtbase.getType());
|
||||
if (nbtbase.getType() == 0) {
|
||||
return;
|
||||
} else {
|
||||
dataoutput.writeUTF(nbtbase.getKey());
|
||||
nbtbase.writeTagContents(dataoutput);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static NBTBase createTagOfType(byte byte0) {
|
||||
switch (byte0) {
|
||||
case 0: // '\0'
|
||||
return new NBTTagEnd();
|
||||
|
||||
case 1: // '\001'
|
||||
return new NBTTagByte();
|
||||
|
||||
case 2: // '\002'
|
||||
return new NBTTagShort();
|
||||
|
||||
case 3: // '\003'
|
||||
return new NBTTagInt();
|
||||
|
||||
case 4: // '\004'
|
||||
return new NBTTagLong();
|
||||
|
||||
case 5: // '\005'
|
||||
return new NBTTagFloat();
|
||||
|
||||
case 6: // '\006'
|
||||
return new NBTTagDouble();
|
||||
|
||||
case 7: // '\007'
|
||||
return new NBTTagByteArray();
|
||||
|
||||
case 8: // '\b'
|
||||
return new NBTTagString();
|
||||
|
||||
case 9: // '\t'
|
||||
return new NBTTagList();
|
||||
|
||||
case 10: // '\n'
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getTagName(byte byte0) {
|
||||
switch (byte0) {
|
||||
case 0: // '\0'
|
||||
return "TAG_End";
|
||||
|
||||
case 1: // '\001'
|
||||
return "TAG_Byte";
|
||||
|
||||
case 2: // '\002'
|
||||
return "TAG_Short";
|
||||
|
||||
case 3: // '\003'
|
||||
return "TAG_Int";
|
||||
|
||||
case 4: // '\004'
|
||||
return "TAG_Long";
|
||||
|
||||
case 5: // '\005'
|
||||
return "TAG_Float";
|
||||
|
||||
case 6: // '\006'
|
||||
return "TAG_Double";
|
||||
|
||||
case 7: // '\007'
|
||||
return "TAG_Byte_Array";
|
||||
|
||||
case 8: // '\b'
|
||||
return "TAG_String";
|
||||
|
||||
case 9: // '\t'
|
||||
return "TAG_List";
|
||||
|
||||
case 10: // '\n'
|
||||
return "TAG_Compound";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
private String key;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagByte extends NBTBase {
|
||||
|
||||
public NBTTagByte() {
|
||||
}
|
||||
|
||||
public NBTTagByte(byte byte0) {
|
||||
byteValue = byte0;
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeByte(byteValue);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
byteValue = datainput.readByte();
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(byteValue).toString();
|
||||
}
|
||||
|
||||
public byte byteValue;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagByteArray extends NBTBase {
|
||||
|
||||
public NBTTagByteArray() {
|
||||
}
|
||||
|
||||
public NBTTagByteArray(byte abyte0[]) {
|
||||
byteArray = abyte0;
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeInt(byteArray.length);
|
||||
dataoutput.write(byteArray);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
int i = datainput.readInt();
|
||||
byteArray = new byte[i];
|
||||
datainput.readFully(byteArray);
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 7;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("[").append(byteArray.length).append(" bytes]").toString();
|
||||
}
|
||||
|
||||
public byte byteArray[];
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class NBTTagCompound extends NBTBase {
|
||||
|
||||
public NBTTagCompound() {
|
||||
tagMap = new HashMap();
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
NBTBase nbtbase;
|
||||
for (Iterator iterator = tagMap.values().iterator(); iterator.hasNext(); NBTBase.writeTag(nbtbase,
|
||||
dataoutput)) {
|
||||
nbtbase = (NBTBase) iterator.next();
|
||||
}
|
||||
|
||||
dataoutput.writeByte(0);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
tagMap.clear();
|
||||
NBTBase nbtbase;
|
||||
for (; (nbtbase = NBTBase.readTag(datainput)).getType() != 0; tagMap.put(nbtbase.getKey(), nbtbase)) {
|
||||
}
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
public void setTag(String s, NBTBase nbtbase) {
|
||||
tagMap.put(s, nbtbase.setKey(s));
|
||||
}
|
||||
|
||||
public void setByte(String s, byte byte0) {
|
||||
tagMap.put(s, (new NBTTagByte(byte0)).setKey(s));
|
||||
}
|
||||
|
||||
public void setShort(String s, short word0) {
|
||||
tagMap.put(s, (new NBTTagShort(word0)).setKey(s));
|
||||
}
|
||||
|
||||
public void setInteger(String s, int i) {
|
||||
tagMap.put(s, (new NBTTagInt(i)).setKey(s));
|
||||
}
|
||||
|
||||
public void setLong(String s, long l) {
|
||||
tagMap.put(s, (new NBTTagLong(l)).setKey(s));
|
||||
}
|
||||
|
||||
public void setFloat(String s, float f) {
|
||||
tagMap.put(s, (new NBTTagFloat(f)).setKey(s));
|
||||
}
|
||||
|
||||
public void setDouble(String s, double d) {
|
||||
tagMap.put(s, (new NBTTagDouble(d)).setKey(s));
|
||||
}
|
||||
|
||||
public void setString(String s, String s1) {
|
||||
tagMap.put(s, (new NBTTagString(s1)).setKey(s));
|
||||
}
|
||||
|
||||
public void setByteArray(String s, byte abyte0[]) {
|
||||
tagMap.put(s, (new NBTTagByteArray(abyte0)).setKey(s));
|
||||
}
|
||||
|
||||
public void setObject(String s, Object obj) {
|
||||
tagMap.put(s, obj);
|
||||
}
|
||||
|
||||
public void setCompoundTag(String s, NBTTagCompound nbttagcompound) {
|
||||
tagMap.put(s, nbttagcompound.setKey(s));
|
||||
}
|
||||
|
||||
public void setBoolean(String s, boolean flag) {
|
||||
setByte(s, ((byte) (flag ? 1 : 0)));
|
||||
}
|
||||
|
||||
public boolean hasKey(String s) {
|
||||
return tagMap.containsKey(s);
|
||||
}
|
||||
|
||||
public byte getByte(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return 0;
|
||||
} else {
|
||||
return ((NBTTagByte) tagMap.get(s)).byteValue;
|
||||
}
|
||||
}
|
||||
|
||||
public short getShort(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return 0;
|
||||
} else {
|
||||
return ((NBTTagShort) tagMap.get(s)).shortValue;
|
||||
}
|
||||
}
|
||||
|
||||
public int getInteger(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return 0;
|
||||
} else {
|
||||
return ((NBTTagInt) tagMap.get(s)).intValue;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLong(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return 0L;
|
||||
} else {
|
||||
return ((NBTTagLong) tagMap.get(s)).longValue;
|
||||
}
|
||||
}
|
||||
|
||||
public float getFloat(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return 0.0F;
|
||||
} else {
|
||||
return ((NBTTagFloat) tagMap.get(s)).floatValue;
|
||||
}
|
||||
}
|
||||
|
||||
public double getDouble(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return 0.0D;
|
||||
} else {
|
||||
return ((NBTTagDouble) tagMap.get(s)).doubleValue;
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return "";
|
||||
} else {
|
||||
return ((NBTTagString) tagMap.get(s)).stringValue;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getByteArray(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return new byte[0];
|
||||
} else {
|
||||
return ((NBTTagByteArray) tagMap.get(s)).byteArray;
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound getCompoundTag(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return new NBTTagCompound();
|
||||
} else {
|
||||
return (NBTTagCompound) tagMap.get(s);
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagList getTagList(String s) {
|
||||
if (!tagMap.containsKey(s)) {
|
||||
return new NBTTagList();
|
||||
} else {
|
||||
return (NBTTagList) tagMap.get(s);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getBoolean(String s) {
|
||||
return getByte(s) != 0;
|
||||
}
|
||||
|
||||
public Object getObject(String s) {
|
||||
if(!tagMap.containsKey(s)) {
|
||||
return null;
|
||||
} else {
|
||||
return tagMap.get(s);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(tagMap.size()).append(" entries").toString();
|
||||
}
|
||||
|
||||
public boolean hasNoTags() {
|
||||
return tagMap.size() == 0;
|
||||
}
|
||||
|
||||
public Map tagMap;
|
||||
|
||||
public NBTBase getTag(String s) {
|
||||
return (NBTBase) tagMap.get(s);
|
||||
}
|
||||
|
||||
public static Map<String,NBTBase> getTagMap(NBTTagCompound nb) {
|
||||
return nb.tagMap;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagDouble extends NBTBase {
|
||||
|
||||
public NBTTagDouble() {
|
||||
}
|
||||
|
||||
public NBTTagDouble(double d) {
|
||||
doubleValue = d;
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeDouble(doubleValue);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
doubleValue = datainput.readDouble();
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(doubleValue).toString();
|
||||
}
|
||||
|
||||
public double doubleValue;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagEnd extends NBTBase {
|
||||
|
||||
public NBTTagEnd() {
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "END";
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagFloat extends NBTBase {
|
||||
|
||||
public NBTTagFloat() {
|
||||
}
|
||||
|
||||
public NBTTagFloat(float f) {
|
||||
floatValue = f;
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeFloat(floatValue);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
floatValue = datainput.readFloat();
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(floatValue).toString();
|
||||
}
|
||||
|
||||
public float floatValue;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagInt extends NBTBase {
|
||||
|
||||
public NBTTagInt() {
|
||||
}
|
||||
|
||||
public NBTTagInt(int i) {
|
||||
intValue = i;
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeInt(intValue);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
intValue = datainput.readInt();
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(intValue).toString();
|
||||
}
|
||||
|
||||
public int intValue;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NBTTagList extends NBTBase {
|
||||
|
||||
public NBTTagList() {
|
||||
tagList = new ArrayList();
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
if (tagList.size() > 0) {
|
||||
tagType = ((NBTBase) tagList.get(0)).getType();
|
||||
} else {
|
||||
tagType = 1;
|
||||
}
|
||||
dataoutput.writeByte(tagType);
|
||||
dataoutput.writeInt(tagList.size());
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
((NBTBase) tagList.get(i)).writeTagContents(dataoutput);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
tagType = datainput.readByte();
|
||||
int i = datainput.readInt();
|
||||
tagList = new ArrayList();
|
||||
for (int j = 0; j < i; j++) {
|
||||
NBTBase nbtbase = NBTBase.createTagOfType(tagType);
|
||||
nbtbase.readTagContents(datainput);
|
||||
tagList.add(nbtbase);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(tagList.size()).append(" entries of type ")
|
||||
.append(NBTBase.getTagName(tagType)).toString();
|
||||
}
|
||||
|
||||
public void setTag(NBTBase nbtbase) {
|
||||
tagType = nbtbase.getType();
|
||||
tagList.add(nbtbase);
|
||||
}
|
||||
|
||||
public NBTBase tagAt(int i) {
|
||||
return (NBTBase) tagList.get(i);
|
||||
}
|
||||
|
||||
public int tagCount() {
|
||||
return tagList.size();
|
||||
}
|
||||
|
||||
private List tagList;
|
||||
private byte tagType;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagLong extends NBTBase {
|
||||
|
||||
public NBTTagLong() {
|
||||
}
|
||||
|
||||
public NBTTagLong(long l) {
|
||||
longValue = l;
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeLong(longValue);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
longValue = datainput.readLong();
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(longValue).toString();
|
||||
}
|
||||
|
||||
public long longValue;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagShort extends NBTBase {
|
||||
|
||||
public NBTTagShort() {
|
||||
}
|
||||
|
||||
public NBTTagShort(short word0) {
|
||||
shortValue = word0;
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeShort(shortValue);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
shortValue = datainput.readShort();
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(shortValue).toString();
|
||||
}
|
||||
|
||||
public short shortValue;
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package net.PeytonPlayz595.nbt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NBTTagString extends NBTBase {
|
||||
|
||||
public NBTTagString() {
|
||||
}
|
||||
|
||||
public NBTTagString(String s) {
|
||||
stringValue = s;
|
||||
if (s == null) {
|
||||
throw new IllegalArgumentException("Empty string not allowed");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void writeTagContents(DataOutput dataoutput) throws IOException {
|
||||
dataoutput.writeUTF(stringValue);
|
||||
}
|
||||
|
||||
void readTagContents(DataInput datainput) throws IOException {
|
||||
stringValue = datainput.readUTF();
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new StringBuilder()).append("").append(stringValue).toString();
|
||||
}
|
||||
|
||||
public String stringValue;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.jcraft.jzlib.InflaterInputStream;
|
||||
|
||||
public class AssetRepository {
|
||||
|
||||
private static final HashMap<String, byte[]> filePool = new HashMap();
|
||||
|
||||
public static final void install(byte[] pkg) throws IOException {
|
||||
ByteArrayInputStream in2 = new ByteArrayInputStream(pkg);
|
||||
DataInputStream in = new DataInputStream(in2);
|
||||
byte[] header = new byte[8];
|
||||
in.read(header);
|
||||
if (!"EAGPKG!!".equals(new String(header, Charset.forName("UTF-8"))))
|
||||
throw new IOException("invalid epk file");
|
||||
in.readUTF();
|
||||
in = new DataInputStream(new InflaterInputStream(in2));
|
||||
String s = null;
|
||||
SHA1Digest dg = new SHA1Digest();
|
||||
while ("<file>".equals(s = in.readUTF())) {
|
||||
String path = in.readUTF();
|
||||
byte[] digest = new byte[20];
|
||||
byte[] digest2 = new byte[20];
|
||||
in.read(digest);
|
||||
int len = in.readInt();
|
||||
byte[] file = new byte[len];
|
||||
in.read(file);
|
||||
if (filePool.containsKey(path))
|
||||
continue;
|
||||
dg.update(file, 0, len);
|
||||
dg.doFinal(digest2, 0);
|
||||
if (!Arrays.equals(digest, digest2))
|
||||
throw new IOException("invalid file hash for " + path);
|
||||
filePool.put(path, file);
|
||||
if (!"</file>".equals(in.readUTF()))
|
||||
throw new IOException("invalid epk file");
|
||||
}
|
||||
if (in.available() > 0 || !" end".equals(s))
|
||||
throw new IOException("invalid epk file");
|
||||
}
|
||||
|
||||
public static final byte[] getResource(String path) {
|
||||
if (path.startsWith("/"))
|
||||
path = path.substring(1);
|
||||
return filePool.get(path);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,857 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Provides Base64 encoding and decoding as defined by
|
||||
* <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>.
|
||||
*
|
||||
* <p>
|
||||
* This class implements section <cite>6.8. Base64
|
||||
* Content-Transfer-Encoding</cite> from RFC 2045 <cite>Multipurpose Internet
|
||||
* Mail Extensions (MIME) Part One: Format of Internet Message Bodies</cite> by
|
||||
* Freed and Borenstein.
|
||||
* </p>
|
||||
* <p>
|
||||
* The class can be parameterized in the following manner with various
|
||||
* constructors:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>URL-safe mode: Default off.</li>
|
||||
* <li>Line length: Default 76. Line length that aren't multiples of 4 will
|
||||
* still essentially end up being multiples of 4 in the encoded data.
|
||||
* <li>Line separator: Default is CRLF ("\r\n")</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The URL-safe parameter is only applied to encode operations. Decoding
|
||||
* seamlessly handles both modes.
|
||||
* </p>
|
||||
* <p>
|
||||
* Since this class operates directly on byte streams, and not character
|
||||
* streams, it is hard-coded to only encode/decode character encodings which are
|
||||
* compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8,
|
||||
* etc).
|
||||
* </p>
|
||||
* <p>
|
||||
* This class is thread-safe.
|
||||
* </p>
|
||||
*
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Base64 extends BaseNCodec {
|
||||
|
||||
/**
|
||||
* BASE32 characters are 6 bits in length. They are formed by taking a block of
|
||||
* 3 octets to form a 24-bit string, which is converted into 4 BASE64
|
||||
* characters.
|
||||
*/
|
||||
private static final int BITS_PER_ENCODED_BYTE = 6;
|
||||
private static final int BYTES_PER_UNENCODED_BLOCK = 3;
|
||||
private static final int BYTES_PER_ENCODED_BLOCK = 4;
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates 6-bit positive integer index
|
||||
* values into their "Base64 Alphabet" equivalents as specified in Table 1 of
|
||||
* RFC 2045.
|
||||
*
|
||||
* Thanks to "commons" project in ws.apache.org for this code.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
*/
|
||||
private static final byte[] STANDARD_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1',
|
||||
'2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
|
||||
|
||||
/**
|
||||
* This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed
|
||||
* to - and _ to make the encoded Base64 results more URL-SAFE. This table is
|
||||
* only used when the Base64's mode is set to URL-SAFE.
|
||||
*/
|
||||
private static final byte[] URL_SAFE_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1',
|
||||
'2', '3', '4', '5', '6', '7', '8', '9', '-', '_' };
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates Unicode characters drawn from
|
||||
* the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit
|
||||
* positive integer equivalents. Characters that are not in the Base64 alphabet
|
||||
* but fall within the bounds of the array are translated to -1.
|
||||
*
|
||||
* Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This
|
||||
* means decoder seamlessly handles both URL_SAFE and STANDARD base64. (The
|
||||
* encoder, on the other hand, needs to know ahead of time what to emit).
|
||||
*
|
||||
* Thanks to "commons" project in ws.apache.org for this code.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
*/
|
||||
private static final byte[] DECODE_TABLE = {
|
||||
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, // 20-2f + - /
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 30-3f 0-9
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 40-4f A-O
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, // 50-5f P-Z _
|
||||
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 60-6f a-o
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 // 70-7a p-z
|
||||
};
|
||||
|
||||
/**
|
||||
* Base64 uses 6-bit fields.
|
||||
*/
|
||||
/** Mask used to extract 6 bits, used when encoding */
|
||||
private static final int MASK_6BITS = 0x3f;
|
||||
/** Mask used to extract 4 bits, used when decoding final trailing character. */
|
||||
private static final int MASK_4BITS = 0xf;
|
||||
/** Mask used to extract 2 bits, used when decoding final trailing character. */
|
||||
private static final int MASK_2BITS = 0x3;
|
||||
|
||||
// The static final fields above are used for the original static byte[] methods
|
||||
// on Base64.
|
||||
// The private member fields below are used with the new streaming approach,
|
||||
// which requires
|
||||
// some state be preserved between calls of encode() and decode().
|
||||
|
||||
/**
|
||||
* Decodes Base64 data into octets.
|
||||
* <p>
|
||||
* <b>Note:</b> this method seamlessly handles data encoded in URL-safe or
|
||||
* normal mode.
|
||||
* </p>
|
||||
*
|
||||
* @param base64Data Byte array containing Base64 data
|
||||
* @return Array containing decoded data.
|
||||
*/
|
||||
public static byte[] decodeBase64(final byte[] base64Data) {
|
||||
return new Base64().decode(base64Data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a Base64 String into octets.
|
||||
* <p>
|
||||
* <b>Note:</b> this method seamlessly handles data encoded in URL-safe or
|
||||
* normal mode.
|
||||
* </p>
|
||||
*
|
||||
* @param base64String String containing Base64 data
|
||||
* @return Array containing decoded data.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] decodeBase64(final String base64String) {
|
||||
return new Base64().decode(base64String);
|
||||
}
|
||||
|
||||
// Implementation of integer encoding used for crypto
|
||||
/**
|
||||
* Decodes a byte64-encoded integer according to crypto standards such as W3C's
|
||||
* XML-Signature.
|
||||
*
|
||||
* @param pArray a byte array containing base64 character data
|
||||
* @return A BigInteger
|
||||
* @since 1.4
|
||||
*/
|
||||
public static BigInteger decodeInteger(final byte[] pArray) {
|
||||
return new BigInteger(1, decodeBase64(pArray));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm but does not chunk the output.
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return byte[] containing Base64 characters in their UTF-8 representation.
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData) {
|
||||
return encodeBase64(binaryData, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm, optionally chunking the
|
||||
* output into 76 character blocks.
|
||||
*
|
||||
* @param binaryData Array containing binary data to encode.
|
||||
* @param isChunked if {@code true} this encoder will chunk the base64 output
|
||||
* into 76 character blocks
|
||||
* @return Base64-encoded data.
|
||||
* @throws IllegalArgumentException Thrown when the input array needs an output
|
||||
* array bigger than {@link Integer#MAX_VALUE}
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked) {
|
||||
return encodeBase64(binaryData, isChunked, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm, optionally chunking the
|
||||
* output into 76 character blocks.
|
||||
*
|
||||
* @param binaryData Array containing binary data to encode.
|
||||
* @param isChunked if {@code true} this encoder will chunk the base64 output
|
||||
* into 76 character blocks
|
||||
* @param urlSafe if {@code true} this encoder will emit - and _ instead of
|
||||
* the usual + and / characters. <b>Note: no padding is added
|
||||
* when encoding using the URL-safe alphabet.</b>
|
||||
* @return Base64-encoded data.
|
||||
* @throws IllegalArgumentException Thrown when the input array needs an output
|
||||
* array bigger than {@link Integer#MAX_VALUE}
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe) {
|
||||
return encodeBase64(binaryData, isChunked, urlSafe, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm, optionally chunking the
|
||||
* output into 76 character blocks.
|
||||
*
|
||||
* @param binaryData Array containing binary data to encode.
|
||||
* @param isChunked if {@code true} this encoder will chunk the base64
|
||||
* output into 76 character blocks
|
||||
* @param urlSafe if {@code true} this encoder will emit - and _ instead
|
||||
* of the usual + and / characters. <b>Note: no padding is
|
||||
* added when encoding using the URL-safe alphabet.</b>
|
||||
* @param maxResultSize The maximum result size to accept.
|
||||
* @return Base64-encoded data.
|
||||
* @throws IllegalArgumentException Thrown when the input array needs an output
|
||||
* array bigger than maxResultSize
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe,
|
||||
final int maxResultSize) {
|
||||
if (binaryData == null || binaryData.length == 0) {
|
||||
return binaryData;
|
||||
}
|
||||
|
||||
// Create this so can use the super-class method
|
||||
// Also ensures that the same roundings are performed by the ctor and the code
|
||||
final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
|
||||
final long len = b64.getEncodedLength(binaryData);
|
||||
if (len > maxResultSize) {
|
||||
throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len
|
||||
+ ") than the specified maximum size of " + maxResultSize);
|
||||
}
|
||||
|
||||
return b64.encode(binaryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm and chunks the encoded output
|
||||
* into 76 character blocks
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return Base64 characters chunked in 76 character blocks
|
||||
*/
|
||||
public static byte[] encodeBase64Chunked(final byte[] binaryData) {
|
||||
return encodeBase64(binaryData, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm but does not chunk the output.
|
||||
*
|
||||
* NOTE: We changed the behavior of this method from multi-line chunking
|
||||
* (commons-codec-1.4) to single-line non-chunking (commons-codec-1.5).
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return String containing Base64 characters.
|
||||
* @since 1.4 (NOTE: 1.4 chunked the output, whereas 1.5 does not).
|
||||
*/
|
||||
public static String encodeBase64String(final byte[] binaryData) {
|
||||
return new String(encodeBase64(binaryData, false), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using a URL-safe variation of the base64 algorithm but
|
||||
* does not chunk the output. The url-safe variation emits - and _ instead of +
|
||||
* and / characters. <b>Note: no padding is added.</b>
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return byte[] containing Base64 characters in their UTF-8 representation.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeBase64URLSafe(final byte[] binaryData) {
|
||||
return encodeBase64(binaryData, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using a URL-safe variation of the base64 algorithm but
|
||||
* does not chunk the output. The url-safe variation emits - and _ instead of +
|
||||
* and / characters. <b>Note: no padding is added.</b>
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return String containing Base64 characters
|
||||
* @since 1.4
|
||||
*/
|
||||
public static String encodeBase64URLSafeString(final byte[] binaryData) {
|
||||
return new String(encodeBase64(binaryData, false, true), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes to a byte64-encoded integer according to crypto standards such as
|
||||
* W3C's XML-Signature.
|
||||
*
|
||||
* @param bigInteger a BigInteger
|
||||
* @return A byte array containing base64 character data
|
||||
* @throws NullPointerException if null is passed in
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeInteger(final BigInteger bigInteger) {
|
||||
return encodeBase64(toIntegerBytes(bigInteger), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains only valid characters within
|
||||
* the Base64 alphabet. Currently the method treats whitespace as valid.
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @return {@code true} if all bytes are valid characters in the Base64 alphabet
|
||||
* or if the byte array is empty; {@code false}, otherwise
|
||||
* @deprecated 1.5 Use {@link #isBase64(byte[])}, will be removed in 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isArrayByteBase64(final byte[] arrayOctet) {
|
||||
return isBase64(arrayOctet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the {@code octet} is in the base 64 alphabet.
|
||||
*
|
||||
* @param octet The value to test
|
||||
* @return {@code true} if the value is defined in the the base 64 alphabet,
|
||||
* {@code false} otherwise.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static boolean isBase64(final byte octet) {
|
||||
return octet == PAD_DEFAULT || (octet >= 0 && octet < DECODE_TABLE.length && DECODE_TABLE[octet] != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains only valid characters within
|
||||
* the Base64 alphabet. Currently the method treats whitespace as valid.
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @return {@code true} if all bytes are valid characters in the Base64 alphabet
|
||||
* or if the byte array is empty; {@code false}, otherwise
|
||||
* @since 1.5
|
||||
*/
|
||||
public static boolean isBase64(final byte[] arrayOctet) {
|
||||
for (int i = 0; i < arrayOctet.length; i++) {
|
||||
if (!isBase64(arrayOctet[i]) && !isWhiteSpace(arrayOctet[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given String to see if it contains only valid characters within the
|
||||
* Base64 alphabet. Currently the method treats whitespace as valid.
|
||||
*
|
||||
* @param base64 String to test
|
||||
* @return {@code true} if all characters in the String are valid characters in
|
||||
* the Base64 alphabet or if the String is empty; {@code false},
|
||||
* otherwise
|
||||
* @since 1.5
|
||||
*/
|
||||
public static boolean isBase64(final String base64) {
|
||||
return isBase64(base64.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a byte-array representation of a {@code BigInteger} without sign bit.
|
||||
*
|
||||
* @param bigInt {@code BigInteger} to be converted
|
||||
* @return a byte array representation of the BigInteger parameter
|
||||
*/
|
||||
static byte[] toIntegerBytes(final BigInteger bigInt) {
|
||||
int bitlen = bigInt.bitLength();
|
||||
// round bitlen
|
||||
bitlen = ((bitlen + 7) >> 3) << 3;
|
||||
final byte[] bigBytes = bigInt.toByteArray();
|
||||
|
||||
if (((bigInt.bitLength() % 8) != 0) && (((bigInt.bitLength() / 8) + 1) == (bitlen / 8))) {
|
||||
return bigBytes;
|
||||
}
|
||||
// set up params for copying everything but sign bit
|
||||
int startSrc = 0;
|
||||
int len = bigBytes.length;
|
||||
|
||||
// if bigInt is exactly byte-aligned, just skip signbit in copy
|
||||
if ((bigInt.bitLength() % 8) == 0) {
|
||||
startSrc = 1;
|
||||
len--;
|
||||
}
|
||||
final int startDst = bitlen / 8 - len; // to pad w/ nulls as per spec
|
||||
final byte[] resizedBytes = new byte[bitlen / 8];
|
||||
System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len);
|
||||
return resizedBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode table to use: either STANDARD or URL_SAFE. Note: the DECODE_TABLE
|
||||
* above remains static because it is able to decode both STANDARD and URL_SAFE
|
||||
* streams, but the encodeTable must be a member variable so we can switch
|
||||
* between the two modes.
|
||||
*/
|
||||
private final byte[] encodeTable;
|
||||
|
||||
// Only one decode table currently; keep for consistency with Base32 code
|
||||
private final byte[] decodeTable = DECODE_TABLE;
|
||||
|
||||
/**
|
||||
* Line separator for encoding. Not used when decoding. Only used if lineLength
|
||||
* > 0.
|
||||
*/
|
||||
private final byte[] lineSeparator;
|
||||
|
||||
/**
|
||||
* Convenience variable to help us determine when our buffer is going to run out
|
||||
* of room and needs resizing. {@code decodeSize = 3 + lineSeparator.length;}
|
||||
*/
|
||||
private final int decodeSize;
|
||||
|
||||
/**
|
||||
* Convenience variable to help us determine when our buffer is going to run out
|
||||
* of room and needs resizing. {@code encodeSize = 4 + lineSeparator.length;}
|
||||
*/
|
||||
private final int encodeSize;
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length is 0 (no chunking), and the encoding table is
|
||||
* STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*/
|
||||
public Base64() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in the
|
||||
* given URL-safe mode.
|
||||
* <p>
|
||||
* When encoding the line length is 76, the line separator is CRLF, and the
|
||||
* encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param urlSafe if {@code true}, URL-safe encoding is used. In most cases this
|
||||
* should be set to {@code false}.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final boolean urlSafe) {
|
||||
this(MIME_CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length is given in the constructor, the line separator
|
||||
* is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final int lineLength) {
|
||||
this(lineLength, CHUNK_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length and line separator are given in the
|
||||
* constructor, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @param lineSeparator Each line of encoded data will end with this sequence of
|
||||
* bytes.
|
||||
* @throws IllegalArgumentException Thrown when the provided lineSeparator
|
||||
* included some base64 characters.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final int lineLength, final byte[] lineSeparator) {
|
||||
this(lineLength, lineSeparator, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length and line separator are given in the
|
||||
* constructor, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @param lineSeparator Each line of encoded data will end with this sequence of
|
||||
* bytes.
|
||||
* @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_'
|
||||
* respectively. urlSafe is only applied to encode
|
||||
* operations. Decoding seamlessly handles both modes.
|
||||
* <b>Note: no padding is added when using the URL-safe
|
||||
* alphabet.</b>
|
||||
* @throws IllegalArgumentException Thrown when the {@code lineSeparator}
|
||||
* contains Base64 characters.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe) {
|
||||
this(lineLength, lineSeparator, urlSafe, CodecPolicy.LENIANT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length and line separator are given in the
|
||||
* constructor, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @param lineSeparator Each line of encoded data will end with this sequence
|
||||
* of bytes.
|
||||
* @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_'
|
||||
* respectively. urlSafe is only applied to encode
|
||||
* operations. Decoding seamlessly handles both modes.
|
||||
* <b>Note: no padding is added when using the URL-safe
|
||||
* alphabet.</b>
|
||||
* @param decodingPolicy The decoding policy.
|
||||
* @throws IllegalArgumentException Thrown when the {@code lineSeparator}
|
||||
* contains Base64 characters.
|
||||
* @since 1.15
|
||||
*/
|
||||
public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe,
|
||||
final CodecPolicy decodingPolicy) {
|
||||
super(BYTES_PER_UNENCODED_BLOCK, BYTES_PER_ENCODED_BLOCK, lineLength,
|
||||
lineSeparator == null ? 0 : lineSeparator.length, PAD_DEFAULT, decodingPolicy);
|
||||
// TODO could be simplified if there is no requirement to reject invalid line
|
||||
// sep when length <=0
|
||||
// @see test case Base64Test.testConstructors()
|
||||
if (lineSeparator != null) {
|
||||
if (containsAlphabetOrPad(lineSeparator)) {
|
||||
final String sep = new String(lineSeparator, Charset.forName("UTF-8"));
|
||||
throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + sep + "]");
|
||||
}
|
||||
if (lineLength > 0) { // null line-sep forces no chunking rather than throwing IAE
|
||||
this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator.length;
|
||||
this.lineSeparator = new byte[lineSeparator.length];
|
||||
System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
|
||||
} else {
|
||||
this.encodeSize = BYTES_PER_ENCODED_BLOCK;
|
||||
this.lineSeparator = null;
|
||||
}
|
||||
} else {
|
||||
this.encodeSize = BYTES_PER_ENCODED_BLOCK;
|
||||
this.lineSeparator = null;
|
||||
}
|
||||
this.decodeSize = this.encodeSize - 1;
|
||||
this.encodeTable = urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE;
|
||||
}
|
||||
|
||||
// Implementation of the Encoder Interface
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Decodes all of the provided data, starting at inPos, for inAvail bytes.
|
||||
* Should be called at least twice: once with the data to decode, and once with
|
||||
* inAvail set to "-1" to alert decoder that EOF has been reached. The "-1" call
|
||||
* is not necessary when decoding, but it doesn't hurt, either.
|
||||
* </p>
|
||||
* <p>
|
||||
* Ignores all non-base64 characters. This is how chunked (e.g. 76 character)
|
||||
* data is handled, since CR and LF are silently ignored, but has implications
|
||||
* for other bytes, too. This method subscribes to the garbage-in, garbage-out
|
||||
* philosophy: it will not check the provided data for validity.
|
||||
* </p>
|
||||
* <p>
|
||||
* Thanks to "commons" project in ws.apache.org for the bitwise operations, and
|
||||
* general approach.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
* </p>
|
||||
*
|
||||
* @param in byte[] array of ascii data to base64 decode.
|
||||
* @param inPos Position to start reading data from.
|
||||
* @param inAvail Amount of bytes available from input for decoding.
|
||||
* @param context the context to be used
|
||||
*/
|
||||
@Override
|
||||
void decode(final byte[] in, int inPos, final int inAvail, final Context context) {
|
||||
if (context.eof) {
|
||||
return;
|
||||
}
|
||||
if (inAvail < 0) {
|
||||
context.eof = true;
|
||||
}
|
||||
for (int i = 0; i < inAvail; i++) {
|
||||
final byte[] buffer = ensureBufferSize(decodeSize, context);
|
||||
final byte b = in[inPos++];
|
||||
if (b == pad) {
|
||||
// We're done.
|
||||
context.eof = true;
|
||||
break;
|
||||
}
|
||||
if (b >= 0 && b < DECODE_TABLE.length) {
|
||||
final int result = DECODE_TABLE[b];
|
||||
if (result >= 0) {
|
||||
context.modulus = (context.modulus + 1) % BYTES_PER_ENCODED_BLOCK;
|
||||
context.ibitWorkArea = (context.ibitWorkArea << BITS_PER_ENCODED_BYTE) + result;
|
||||
if (context.modulus == 0) {
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS);
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
|
||||
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two forms of EOF as far as base64 decoder is concerned: actual
|
||||
// EOF (-1) and first time '=' character is encountered in stream.
|
||||
// This approach makes the '=' padding characters completely optional.
|
||||
if (context.eof && context.modulus != 0) {
|
||||
final byte[] buffer = ensureBufferSize(decodeSize, context);
|
||||
|
||||
// We have some spare bits remaining
|
||||
// Output all whole multiples of 8 bits and ignore the rest
|
||||
switch (context.modulus) {
|
||||
// case 0 : // impossible, as excluded above
|
||||
case 1: // 6 bits - either ignore entirely, or raise an exception
|
||||
validateTrailingCharacter();
|
||||
break;
|
||||
case 2: // 12 bits = 8 + 4
|
||||
validateCharacter(MASK_4BITS, context);
|
||||
context.ibitWorkArea = context.ibitWorkArea >> 4; // dump the extra 4 bits
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
|
||||
break;
|
||||
case 3: // 18 bits = 8 + 8 + 2
|
||||
validateCharacter(MASK_2BITS, context);
|
||||
context.ibitWorkArea = context.ibitWorkArea >> 2; // dump 2 bits
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Impossible modulus " + context.modulus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Encodes all of the provided data, starting at inPos, for inAvail bytes. Must
|
||||
* be called at least twice: once with the data to encode, and once with inAvail
|
||||
* set to "-1" to alert encoder that EOF has been reached, to flush last
|
||||
* remaining bytes (if not multiple of 3).
|
||||
* </p>
|
||||
* <p>
|
||||
* <b>Note: no padding is added when encoding using the URL-safe alphabet.</b>
|
||||
* </p>
|
||||
* <p>
|
||||
* Thanks to "commons" project in ws.apache.org for the bitwise operations, and
|
||||
* general approach.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
* </p>
|
||||
*
|
||||
* @param in byte[] array of binary data to base64 encode.
|
||||
* @param inPos Position to start reading data from.
|
||||
* @param inAvail Amount of bytes available from input for encoding.
|
||||
* @param context the context to be used
|
||||
*/
|
||||
@Override
|
||||
void encode(final byte[] in, int inPos, final int inAvail, final Context context) {
|
||||
if (context.eof) {
|
||||
return;
|
||||
}
|
||||
// inAvail < 0 is how we're informed of EOF in the underlying data we're
|
||||
// encoding.
|
||||
if (inAvail < 0) {
|
||||
context.eof = true;
|
||||
if (0 == context.modulus && lineLength == 0) {
|
||||
return; // no leftovers to process and not using chunking
|
||||
}
|
||||
final byte[] buffer = ensureBufferSize(encodeSize, context);
|
||||
final int savedPos = context.pos;
|
||||
switch (context.modulus) { // 0-2
|
||||
case 0: // nothing to do here
|
||||
break;
|
||||
case 1: // 8 bits = 6 + 2
|
||||
// top 6 bits:
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 2) & MASK_6BITS];
|
||||
// remaining 2:
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 4) & MASK_6BITS];
|
||||
// URL-SAFE skips the padding to further reduce size.
|
||||
if (encodeTable == STANDARD_ENCODE_TABLE) {
|
||||
buffer[context.pos++] = pad;
|
||||
buffer[context.pos++] = pad;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // 16 bits = 6 + 6 + 4
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 10) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 4) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 2) & MASK_6BITS];
|
||||
// URL-SAFE skips the padding to further reduce size.
|
||||
if (encodeTable == STANDARD_ENCODE_TABLE) {
|
||||
buffer[context.pos++] = pad;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Impossible modulus " + context.modulus);
|
||||
}
|
||||
context.currentLinePos += context.pos - savedPos; // keep track of current line position
|
||||
// if currentPos == 0 we are at the start of a line, so don't add CRLF
|
||||
if (lineLength > 0 && context.currentLinePos > 0) {
|
||||
System.arraycopy(lineSeparator, 0, buffer, context.pos, lineSeparator.length);
|
||||
context.pos += lineSeparator.length;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < inAvail; i++) {
|
||||
final byte[] buffer = ensureBufferSize(encodeSize, context);
|
||||
context.modulus = (context.modulus + 1) % BYTES_PER_UNENCODED_BLOCK;
|
||||
int b = in[inPos++];
|
||||
if (b < 0) {
|
||||
b += 256;
|
||||
}
|
||||
context.ibitWorkArea = (context.ibitWorkArea << 8) + b; // BITS_PER_BYTE
|
||||
if (0 == context.modulus) { // 3 bytes = 24 bits = 4 * 6 bits to extract
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 18) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 12) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 6) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[context.ibitWorkArea & MASK_6BITS];
|
||||
context.currentLinePos += BYTES_PER_ENCODED_BLOCK;
|
||||
if (lineLength > 0 && lineLength <= context.currentLinePos) {
|
||||
System.arraycopy(lineSeparator, 0, buffer, context.pos, lineSeparator.length);
|
||||
context.pos += lineSeparator.length;
|
||||
context.currentLinePos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the {@code octet} is in the Base64 alphabet.
|
||||
*
|
||||
* @param octet The value to test
|
||||
* @return {@code true} if the value is defined in the the Base64 alphabet
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
@Override
|
||||
protected boolean isInAlphabet(final byte octet) {
|
||||
return octet >= 0 && octet < decodeTable.length && decodeTable[octet] != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns our current encode mode. True if we're URL-SAFE, false otherwise.
|
||||
*
|
||||
* @return true if we're in URL-SAFE mode, false otherwise.
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isUrlSafe() {
|
||||
return this.encodeTable == URL_SAFE_ENCODE_TABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether decoding the final trailing character is possible in the
|
||||
* context of the set of possible base 64 values.
|
||||
*
|
||||
* <p>
|
||||
* The character is valid if the lower bits within the provided mask are zero.
|
||||
* This is used to test the final trailing base-64 digit is zero in the bits
|
||||
* that will be discarded.
|
||||
*
|
||||
* @param emptyBitsMask The mask of the lower bits that should be empty
|
||||
* @param context the context to be used
|
||||
*
|
||||
* @throws IllegalArgumentException if the bits being checked contain any
|
||||
* non-zero value
|
||||
*/
|
||||
private void validateCharacter(final int emptyBitsMask, final Context context) {
|
||||
if (isStrictDecoding() && (context.ibitWorkArea & emptyBitsMask) != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Strict decoding: Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible encoding. "
|
||||
+ "Expected the discarded bits from the character to be zero.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether decoding allows an entire final trailing character that
|
||||
* cannot be used for a complete byte.
|
||||
*
|
||||
* @throws IllegalArgumentException if strict decoding is enabled
|
||||
*/
|
||||
private void validateTrailingCharacter() {
|
||||
if (isStrictDecoding()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Strict decoding: Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible encoding. "
|
||||
+ "Decoding requires at least two trailing 6-bit characters to create bytes.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,694 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.lax1dude.eaglercraft.BaseNCodec.CodecPolicy;
|
||||
|
||||
public abstract class BaseNCodec {
|
||||
|
||||
static enum CodecPolicy {
|
||||
STRICT, LENIANT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds thread context so classes can be thread-safe.
|
||||
*
|
||||
* This class is not itself thread-safe; each thread must allocate its own copy.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
static class Context {
|
||||
|
||||
/**
|
||||
* Place holder for the bytes we're dealing with for our based logic. Bitwise
|
||||
* operations store and extract the encoding or decoding from this variable.
|
||||
*/
|
||||
int ibitWorkArea;
|
||||
|
||||
/**
|
||||
* Place holder for the bytes we're dealing with for our based logic. Bitwise
|
||||
* operations store and extract the encoding or decoding from this variable.
|
||||
*/
|
||||
long lbitWorkArea;
|
||||
|
||||
/**
|
||||
* Buffer for streaming.
|
||||
*/
|
||||
byte[] buffer;
|
||||
|
||||
/**
|
||||
* Position where next character should be written in the buffer.
|
||||
*/
|
||||
int pos;
|
||||
|
||||
/**
|
||||
* Position where next character should be read from the buffer.
|
||||
*/
|
||||
int readPos;
|
||||
|
||||
/**
|
||||
* Boolean flag to indicate the EOF has been reached. Once EOF has been reached,
|
||||
* this object becomes useless, and must be thrown away.
|
||||
*/
|
||||
boolean eof;
|
||||
|
||||
/**
|
||||
* Variable tracks how many characters have been written to the current line.
|
||||
* Only used when encoding. We use it to make sure each encoded line never goes
|
||||
* beyond lineLength (if lineLength > 0).
|
||||
*/
|
||||
int currentLinePos;
|
||||
|
||||
/**
|
||||
* Writes to the buffer only occur after every 3/5 reads when encoding, and
|
||||
* every 4/8 reads when decoding. This variable helps track that.
|
||||
*/
|
||||
int modulus;
|
||||
|
||||
Context() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String useful for debugging (especially within a debugger.)
|
||||
*
|
||||
* @return a String useful for debugging.
|
||||
*/
|
||||
@SuppressWarnings("boxing") // OK to ignore boxing here
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, "
|
||||
+ "modulus=%s, pos=%s, readPos=%s]",
|
||||
this.getClass().getSimpleName(), Arrays.toString(buffer), currentLinePos, eof, ibitWorkArea,
|
||||
lbitWorkArea, modulus, pos, readPos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EOF
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
static final int EOF = -1;
|
||||
|
||||
/**
|
||||
* MIME chunk size per RFC 2045 section 6.8.
|
||||
*
|
||||
* <p>
|
||||
* The {@value} character limit does not count the trailing CRLF, but counts all
|
||||
* other characters, including any equal signs.
|
||||
* </p>
|
||||
*
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 6.8</a>
|
||||
*/
|
||||
public static final int MIME_CHUNK_SIZE = 76;
|
||||
|
||||
/**
|
||||
* PEM chunk size per RFC 1421 section 4.3.2.4.
|
||||
*
|
||||
* <p>
|
||||
* The {@value} character limit does not count the trailing CRLF, but counts all
|
||||
* other characters, including any equal signs.
|
||||
* </p>
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc1421">RFC 1421 section
|
||||
* 4.3.2.4</a>
|
||||
*/
|
||||
public static final int PEM_CHUNK_SIZE = 64;
|
||||
|
||||
private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2;
|
||||
|
||||
/**
|
||||
* Defines the default buffer size - currently {@value} - must be large enough
|
||||
* for at least one encoded block+separator
|
||||
*/
|
||||
private static final int DEFAULT_BUFFER_SIZE = 8192;
|
||||
|
||||
/**
|
||||
* The maximum size buffer to allocate.
|
||||
*
|
||||
* <p>
|
||||
* This is set to the same size used in the JDK {@code java.util.ArrayList}:
|
||||
* </p>
|
||||
* <blockquote> Some VMs reserve some header words in an array. Attempts to
|
||||
* allocate larger arrays may result in OutOfMemoryError: Requested array size
|
||||
* exceeds VM limit. </blockquote>
|
||||
*/
|
||||
private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8;
|
||||
|
||||
/** Mask used to extract 8 bits, used in decoding bytes */
|
||||
protected static final int MASK_8BITS = 0xff;
|
||||
|
||||
/**
|
||||
* Byte used to pad output.
|
||||
*/
|
||||
protected static final byte PAD_DEFAULT = '='; // Allow static access to default
|
||||
|
||||
/**
|
||||
* Chunk separator per RFC 2045 section 2.1.
|
||||
*
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
|
||||
*/
|
||||
static final byte[] CHUNK_SEPARATOR = { '\r', '\n' };
|
||||
|
||||
/**
|
||||
* Compares two {@code int} values numerically treating the values as unsigned.
|
||||
* Taken from JDK 1.8.
|
||||
*
|
||||
* <p>
|
||||
* TODO: Replace with JDK 1.8 Integer::compareUnsigned(int, int).
|
||||
* </p>
|
||||
*
|
||||
* @param x the first {@code int} to compare
|
||||
* @param y the second {@code int} to compare
|
||||
* @return the value {@code 0} if {@code x == y}; a value less than {@code 0} if
|
||||
* {@code x < y} as unsigned values; and a value greater than {@code 0}
|
||||
* if {@code x > y} as unsigned values
|
||||
*/
|
||||
private static int compareUnsigned(final int xx, final int yy) {
|
||||
int x = xx + Integer.MIN_VALUE;
|
||||
int y = yy + Integer.MIN_VALUE;
|
||||
return (x < y) ? -1 : ((x == y) ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a positive capacity at least as large the minimum required capacity.
|
||||
* If the minimum capacity is negative then this throws an OutOfMemoryError as
|
||||
* no array can be allocated.
|
||||
*
|
||||
* @param minCapacity the minimum capacity
|
||||
* @return the capacity
|
||||
* @throws OutOfMemoryError if the {@code minCapacity} is negative
|
||||
*/
|
||||
private static int createPositiveCapacity(final int minCapacity) {
|
||||
if (minCapacity < 0) {
|
||||
// overflow
|
||||
throw new OutOfMemoryError("Unable to allocate array size: " + (minCapacity & 0xffffffffL));
|
||||
}
|
||||
// This is called when we require buffer expansion to a very big array.
|
||||
// Use the conservative maximum buffer size if possible, otherwise the biggest
|
||||
// required.
|
||||
//
|
||||
// Note: In this situation JDK 1.8 java.util.ArrayList returns
|
||||
// Integer.MAX_VALUE.
|
||||
// This excludes some VMs that can exceed MAX_BUFFER_SIZE but not allocate a
|
||||
// full
|
||||
// Integer.MAX_VALUE length array.
|
||||
// The result is that we may have to allocate an array of this size more than
|
||||
// once if
|
||||
// the capacity must be expanded again.
|
||||
return (minCapacity > MAX_BUFFER_SIZE) ? minCapacity : MAX_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a copy of the chunk separator per RFC 2045 section 2.1.
|
||||
*
|
||||
* @return the chunk separator
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
|
||||
* @since 1.15
|
||||
*/
|
||||
public static byte[] getChunkSeparator() {
|
||||
return CHUNK_SEPARATOR.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a byte value is whitespace or not. Whitespace is taken to mean:
|
||||
* space, tab, CR, LF
|
||||
*
|
||||
* @param byteToCheck the byte to check
|
||||
* @return true if byte is whitespace, false otherwise
|
||||
*/
|
||||
protected static boolean isWhiteSpace(final byte byteToCheck) {
|
||||
switch (byteToCheck) {
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases our buffer by the {@link #DEFAULT_BUFFER_RESIZE_FACTOR}.
|
||||
*
|
||||
* @param context the context to be used
|
||||
* @param minCapacity the minimum required capacity
|
||||
* @return the resized byte[] buffer
|
||||
* @throws OutOfMemoryError if the {@code minCapacity} is negative
|
||||
*/
|
||||
private static byte[] resizeBuffer(final Context context, final int minCapacity) {
|
||||
// Overflow-conscious code treats the min and new capacity as unsigned.
|
||||
final int oldCapacity = context.buffer.length;
|
||||
int newCapacity = oldCapacity * DEFAULT_BUFFER_RESIZE_FACTOR;
|
||||
if (compareUnsigned(newCapacity, minCapacity) < 0) {
|
||||
newCapacity = minCapacity;
|
||||
}
|
||||
if (compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
|
||||
newCapacity = createPositiveCapacity(minCapacity);
|
||||
}
|
||||
|
||||
final byte[] b = new byte[newCapacity];
|
||||
System.arraycopy(context.buffer, 0, b, 0, context.buffer.length);
|
||||
context.buffer = b;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #pad}. Will be removed in 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
protected final byte PAD = PAD_DEFAULT; // instance variable just in case it needs to vary later
|
||||
|
||||
protected final byte pad; // instance variable just in case it needs to vary later
|
||||
|
||||
/**
|
||||
* Number of bytes in each full block of unencoded data, e.g. 4 for Base64 and 5
|
||||
* for Base32
|
||||
*/
|
||||
private final int unencodedBlockSize;
|
||||
|
||||
/**
|
||||
* Number of bytes in each full block of encoded data, e.g. 3 for Base64 and 8
|
||||
* for Base32
|
||||
*/
|
||||
private final int encodedBlockSize;
|
||||
|
||||
/**
|
||||
* Chunksize for encoding. Not used when decoding. A value of zero or less
|
||||
* implies no chunking of the encoded data. Rounded down to nearest multiple of
|
||||
* encodedBlockSize.
|
||||
*/
|
||||
protected final int lineLength;
|
||||
|
||||
/**
|
||||
* Size of chunk separator. Not used unless {@link #lineLength} > 0.
|
||||
*/
|
||||
private final int chunkSeparatorLength;
|
||||
|
||||
/**
|
||||
* Defines the decoding behavior when the input bytes contain leftover trailing
|
||||
* bits that cannot be created by a valid encoding. These can be bits that are
|
||||
* unused from the final character or entire characters. The default mode is
|
||||
* lenient decoding. Set this to {@code true} to enable strict decoding.
|
||||
* <ul>
|
||||
* <li>Lenient: Any trailing bits are composed into 8-bit bytes where possible.
|
||||
* The remainder are discarded.
|
||||
* <li>Strict: The decoding will raise an {@link IllegalArgumentException} if
|
||||
* trailing bits are not part of a valid encoding. Any unused bits from the
|
||||
* final character must be zero. Impossible counts of entire final characters
|
||||
* are not allowed.
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* When strict decoding is enabled it is expected that the decoded bytes will be
|
||||
* re-encoded to a byte array that matches the original, i.e. no changes occur
|
||||
* on the final character. This requires that the input bytes use the same
|
||||
* padding and alphabet as the encoder.
|
||||
*/
|
||||
private final CodecPolicy decodingPolicy;
|
||||
|
||||
/**
|
||||
* Note {@code lineLength} is rounded down to the nearest multiple of the
|
||||
* encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is
|
||||
* disabled.
|
||||
*
|
||||
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3)
|
||||
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
|
||||
* @param lineLength if > 0, use chunking with a length
|
||||
* {@code lineLength}
|
||||
* @param chunkSeparatorLength the chunk separator length, if relevant
|
||||
*/
|
||||
protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength,
|
||||
final int chunkSeparatorLength) {
|
||||
this(unencodedBlockSize, encodedBlockSize, lineLength, chunkSeparatorLength, PAD_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note {@code lineLength} is rounded down to the nearest multiple of the
|
||||
* encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is
|
||||
* disabled.
|
||||
*
|
||||
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3)
|
||||
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
|
||||
* @param lineLength if > 0, use chunking with a length
|
||||
* {@code lineLength}
|
||||
* @param chunkSeparatorLength the chunk separator length, if relevant
|
||||
* @param pad byte used as padding byte.
|
||||
*/
|
||||
protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength,
|
||||
final int chunkSeparatorLength, final byte pad) {
|
||||
this(unencodedBlockSize, encodedBlockSize, lineLength, chunkSeparatorLength, pad, CodecPolicy.LENIANT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note {@code lineLength} is rounded down to the nearest multiple of the
|
||||
* encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is
|
||||
* disabled.
|
||||
*
|
||||
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3)
|
||||
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
|
||||
* @param lineLength if > 0, use chunking with a length
|
||||
* {@code lineLength}
|
||||
* @param chunkSeparatorLength the chunk separator length, if relevant
|
||||
* @param pad byte used as padding byte.
|
||||
* @param decodingPolicy Decoding policy.
|
||||
* @since 1.15
|
||||
*/
|
||||
protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength,
|
||||
final int chunkSeparatorLength, final byte pad, final CodecPolicy decodingPolicy) {
|
||||
this.unencodedBlockSize = unencodedBlockSize;
|
||||
this.encodedBlockSize = encodedBlockSize;
|
||||
final boolean useChunking = lineLength > 0 && chunkSeparatorLength > 0;
|
||||
this.lineLength = useChunking ? (lineLength / encodedBlockSize) * encodedBlockSize : 0;
|
||||
this.chunkSeparatorLength = chunkSeparatorLength;
|
||||
this.pad = pad;
|
||||
this.decodingPolicy = decodingPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of buffered data available for reading.
|
||||
*
|
||||
* @param context the context to be used
|
||||
* @return The amount of buffered data available for reading.
|
||||
*/
|
||||
int available(final Context context) { // package protected for access from I/O streams
|
||||
return context.buffer != null ? context.pos - context.readPos : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains any characters within the
|
||||
* alphabet or PAD.
|
||||
*
|
||||
* Intended for use in checking line-ending arrays
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @return {@code true} if any byte is a valid character in the alphabet or PAD;
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
protected boolean containsAlphabetOrPad(final byte[] arrayOctet) {
|
||||
if (arrayOctet == null) {
|
||||
return false;
|
||||
}
|
||||
for (final byte element : arrayOctet) {
|
||||
if (pad == element || isInAlphabet(element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a byte[] containing characters in the Base-N alphabet.
|
||||
*
|
||||
* @param pArray A byte array containing Base-N character data
|
||||
* @return a byte array containing binary data
|
||||
*/
|
||||
public byte[] decode(final byte[] pArray) {
|
||||
if (pArray == null || pArray.length == 0) {
|
||||
return pArray;
|
||||
}
|
||||
final Context context = new Context();
|
||||
decode(pArray, 0, pArray.length, context);
|
||||
decode(pArray, 0, EOF, context); // Notify decoder of EOF.
|
||||
final byte[] result = new byte[context.pos];
|
||||
readResults(result, 0, result.length, context);
|
||||
return result;
|
||||
}
|
||||
|
||||
// package protected for access from I/O streams
|
||||
abstract void decode(byte[] pArray, int i, int length, Context context);
|
||||
|
||||
/**
|
||||
* Decodes an Object using the Base-N algorithm. This method is provided in
|
||||
* order to satisfy the requirements of the Decoder interface, and will throw a
|
||||
* DecoderException if the supplied object is not of type byte[] or String.
|
||||
*
|
||||
* @param obj Object to decode
|
||||
* @return An object (of type byte[]) containing the binary data which
|
||||
* corresponds to the byte[] or String supplied.
|
||||
* @throws DecoderException if the parameter supplied is not of type byte[]
|
||||
*/
|
||||
public Object decode(final Object obj) {
|
||||
if (obj instanceof byte[]) {
|
||||
return decode((byte[]) obj);
|
||||
} else if (obj instanceof String) {
|
||||
return decode((String) obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a String containing characters in the Base-N alphabet.
|
||||
*
|
||||
* @param pArray A String containing Base-N character data
|
||||
* @return a byte array containing binary data
|
||||
*/
|
||||
public byte[] decode(final String pArray) {
|
||||
return decode(pArray.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a byte[] containing characters
|
||||
* in the alphabet.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @return A byte array containing only the base N alphabetic character data
|
||||
*/
|
||||
public byte[] encode(final byte[] pArray) {
|
||||
if (pArray == null || pArray.length == 0) {
|
||||
return pArray;
|
||||
}
|
||||
return encode(pArray, 0, pArray.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a byte[] containing characters
|
||||
* in the alphabet.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @param offset initial offset of the subarray.
|
||||
* @param length length of the subarray.
|
||||
* @return A byte array containing only the base N alphabetic character data
|
||||
* @since 1.11
|
||||
*/
|
||||
public byte[] encode(final byte[] pArray, final int offset, final int length) {
|
||||
if (pArray == null || pArray.length == 0) {
|
||||
return pArray;
|
||||
}
|
||||
final Context context = new Context();
|
||||
encode(pArray, offset, length, context);
|
||||
encode(pArray, offset, EOF, context); // Notify encoder of EOF.
|
||||
final byte[] buf = new byte[context.pos - context.readPos];
|
||||
readResults(buf, 0, buf.length, context);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// package protected for access from I/O streams
|
||||
abstract void encode(byte[] pArray, int i, int length, Context context);
|
||||
|
||||
/**
|
||||
* Encodes an Object using the Base-N algorithm. This method is provided in
|
||||
* order to satisfy the requirements of the Encoder interface, and will throw an
|
||||
* EncoderException if the supplied object is not of type byte[].
|
||||
*
|
||||
* @param obj Object to encode
|
||||
* @return An object (of type byte[]) containing the Base-N encoded data which
|
||||
* corresponds to the byte[] supplied.
|
||||
* @throws EncoderException if the parameter supplied is not of type byte[]
|
||||
*/
|
||||
public Object encode(final Object obj) {
|
||||
return encode((byte[]) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a String containing characters
|
||||
* in the appropriate alphabet. Uses UTF8 encoding.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @return String containing only character data in the appropriate alphabet.
|
||||
* @since 1.5 This is a duplicate of {@link #encodeToString(byte[])}; it was
|
||||
* merged during refactoring.
|
||||
*/
|
||||
public String encodeAsString(final byte[] pArray) {
|
||||
return new String(encode(pArray), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a String containing characters
|
||||
* in the Base-N alphabet. Uses UTF8 encoding.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @return A String containing only Base-N character data
|
||||
*/
|
||||
public String encodeToString(final byte[] pArray) {
|
||||
return new String(encode(pArray), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the buffer has room for {@code size} bytes
|
||||
*
|
||||
* @param size minimum spare space required
|
||||
* @param context the context to be used
|
||||
* @return the buffer
|
||||
*/
|
||||
protected byte[] ensureBufferSize(final int size, final Context context) {
|
||||
if (context.buffer == null) {
|
||||
context.buffer = new byte[Math.max(size, getDefaultBufferSize())];
|
||||
context.pos = 0;
|
||||
context.readPos = 0;
|
||||
|
||||
// Overflow-conscious:
|
||||
// x + y > z == x + y - z > 0
|
||||
} else if (context.pos + size - context.buffer.length > 0) {
|
||||
return resizeBuffer(context, context.pos + size);
|
||||
}
|
||||
return context.buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the decoding behavior policy.
|
||||
*
|
||||
* <p>
|
||||
* The default is lenient. If the decoding policy is strict, then decoding will
|
||||
* raise an {@link IllegalArgumentException} if trailing bits are not part of a
|
||||
* valid encoding. Decoding will compose trailing bits into 8-bit bytes and
|
||||
* discard the remainder.
|
||||
* </p>
|
||||
*
|
||||
* @return true if using strict decoding
|
||||
* @since 1.15
|
||||
*/
|
||||
public CodecPolicy getCodecPolicy() {
|
||||
return decodingPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default buffer size. Can be overridden.
|
||||
*
|
||||
* @return the default buffer size.
|
||||
*/
|
||||
protected int getDefaultBufferSize() {
|
||||
return DEFAULT_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the amount of space needed to encode the supplied array.
|
||||
*
|
||||
* @param pArray byte[] array which will later be encoded
|
||||
*
|
||||
* @return amount of space needed to encoded the supplied array. Returns a long
|
||||
* since a max-len array will require > Integer.MAX_VALUE
|
||||
*/
|
||||
public long getEncodedLength(final byte[] pArray) {
|
||||
// Calculate non-chunked size - rounded up to allow for padding
|
||||
// cast to long is needed to avoid possibility of overflow
|
||||
long len = ((pArray.length + unencodedBlockSize - 1) / unencodedBlockSize) * (long) encodedBlockSize;
|
||||
if (lineLength > 0) { // We're using chunking
|
||||
// Round up to nearest multiple
|
||||
len += ((len + lineLength - 1) / lineLength) * chunkSeparatorLength;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this object has buffered data for reading.
|
||||
*
|
||||
* @param context the context to be used
|
||||
* @return true if there is data still available for reading.
|
||||
*/
|
||||
boolean hasData(final Context context) { // package protected for access from I/O streams
|
||||
return context.buffer != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the {@code octet} is in the current alphabet. Does not
|
||||
* allow whitespace or pad.
|
||||
*
|
||||
* @param value The value to test
|
||||
*
|
||||
* @return {@code true} if the value is defined in the current alphabet,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
protected abstract boolean isInAlphabet(byte value);
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains only valid characters within
|
||||
* the alphabet. The method optionally treats whitespace and pad as valid.
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @param allowWSPad if {@code true}, then whitespace and PAD are also allowed
|
||||
*
|
||||
* @return {@code true} if all bytes are valid characters in the alphabet or if
|
||||
* the byte array is empty; {@code false}, otherwise
|
||||
*/
|
||||
public boolean isInAlphabet(final byte[] arrayOctet, final boolean allowWSPad) {
|
||||
for (final byte octet : arrayOctet) {
|
||||
if (!isInAlphabet(octet) && (!allowWSPad || (octet != pad) && !isWhiteSpace(octet))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given String to see if it contains only valid characters within the
|
||||
* alphabet. The method treats whitespace and PAD as valid.
|
||||
*
|
||||
* @param basen String to test
|
||||
* @return {@code true} if all characters in the String are valid characters in
|
||||
* the alphabet or if the String is empty; {@code false}, otherwise
|
||||
* @see #isInAlphabet(byte[], boolean)
|
||||
*/
|
||||
public boolean isInAlphabet(final String basen) {
|
||||
return isInAlphabet(basen.getBytes(Charset.forName("UTF-8")), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if decoding behavior is strict. Decoding will raise an
|
||||
* {@link IllegalArgumentException} if trailing bits are not part of a valid
|
||||
* encoding.
|
||||
*
|
||||
* <p>
|
||||
* The default is false for lenient decoding. Decoding will compose trailing
|
||||
* bits into 8-bit bytes and discard the remainder.
|
||||
* </p>
|
||||
*
|
||||
* @return true if using strict decoding
|
||||
* @since 1.15
|
||||
*/
|
||||
public boolean isStrictDecoding() {
|
||||
return decodingPolicy == CodecPolicy.STRICT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts buffered data into the provided byte[] array, starting at position
|
||||
* bPos, up to a maximum of bAvail bytes. Returns how many bytes were actually
|
||||
* extracted.
|
||||
* <p>
|
||||
* Package protected for access from I/O streams.
|
||||
*
|
||||
* @param b byte[] array to extract the buffered data into.
|
||||
* @param bPos position in byte[] array to start extraction at.
|
||||
* @param bAvail amount of bytes we're allowed to extract. We may extract fewer
|
||||
* (if fewer are available).
|
||||
* @param context the context to be used
|
||||
* @return The number of bytes successfully extracted into the provided byte[]
|
||||
* array.
|
||||
*/
|
||||
int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) {
|
||||
if (context.buffer != null) {
|
||||
final int len = Math.min(available(context), bAvail);
|
||||
System.arraycopy(context.buffer, context.readPos, b, bPos, len);
|
||||
context.readPos += len;
|
||||
if (context.readPos >= context.pos) {
|
||||
context.buffer = null; // so hasData() will return false, and this method can return -1
|
||||
}
|
||||
return len;
|
||||
}
|
||||
return context.eof ? EOF : 0;
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
public class BufferedImage {
|
||||
|
||||
private final int[] data;
|
||||
public final int w;
|
||||
public final int h;
|
||||
private final boolean alpha;
|
||||
|
||||
public BufferedImage(int width, int height, int[] pixels, boolean alpha) {
|
||||
this.w = width;
|
||||
this.h = height;
|
||||
this.data = pixels;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public BufferedImage(int width, int height, boolean alpha) {
|
||||
this.w = width;
|
||||
this.h = height;
|
||||
this.data = new int[width * height];
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public BufferedImage(int w, int h, int k) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.alpha = true;
|
||||
this.data = new int[w * h];
|
||||
}
|
||||
|
||||
public BufferedImage getSubImage(int x, int y, int pw, int ph) {
|
||||
int[] img = new int[pw * ph];
|
||||
for(int i = 0; i < ph; ++i) {
|
||||
System.arraycopy(data, (i + y) * this.w + x, img, i * pw, pw);
|
||||
}
|
||||
return new BufferedImage(pw, ph, img, alpha);
|
||||
}
|
||||
|
||||
public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {
|
||||
if (startX < 0 || startY < 0 || w <= 0 || h <= 0 ||
|
||||
startX + w > this.w || startY + h > this.h ||
|
||||
rgbArray.length < offset + w * h) {
|
||||
throw new IllegalArgumentException("Invalid input parameters");
|
||||
}
|
||||
|
||||
for (int y = startY; y < startY + h; y++) {
|
||||
for (int x = startX; x < startX + w; x++) {
|
||||
int imageDataIndex = y * this.w + x;
|
||||
int argb = data[imageDataIndex];
|
||||
int alpha = (argb >> 24) & 0xff;
|
||||
int red = (argb >> 16) & 0xff;
|
||||
int green = (argb >> 8) & 0xff;
|
||||
int blue = argb & 0xff;
|
||||
int rgb = (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
|
||||
rgbArray[offset + (y - startY) * scansize + (x - startX)] = rgb;
|
||||
}
|
||||
}
|
||||
|
||||
return rgbArray;
|
||||
}
|
||||
|
||||
public void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {
|
||||
if (startX < 0 || startY < 0 || w <= 0 || h <= 0 ||
|
||||
startX + w > this.w || startY + h > this.h ||
|
||||
rgbArray.length < offset + w * h) {
|
||||
throw new IllegalArgumentException("Invalid input parameters");
|
||||
}
|
||||
|
||||
for (int y = startY; y < startY + h; y++) {
|
||||
for (int x = startX; x < startX + w; x++) {
|
||||
int imageDataIndex = y * this.w + x;
|
||||
int rgb = rgbArray[offset + (y - startY) * scansize + (x - startX)];
|
||||
int alpha = (rgb >> 24) & 0xff;
|
||||
int red = (rgb >> 16) & 0xff;
|
||||
int green = (rgb >> 8) & 0xff;
|
||||
int blue = rgb & 0xff;
|
||||
int argb = (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
|
||||
data[imageDataIndex] = argb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return h;
|
||||
}
|
||||
|
||||
public int[] getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,60 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.nio.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
|
||||
public class GLAllocation {
|
||||
|
||||
public GLAllocation() {
|
||||
}
|
||||
|
||||
public static synchronized int generateDisplayLists(int i) {
|
||||
int j = GL11.glGenLists(i);
|
||||
displayLists.add(Integer.valueOf(j));
|
||||
displayLists.add(Integer.valueOf(i));
|
||||
return j;
|
||||
}
|
||||
|
||||
public static synchronized void generateTextureNames(IntBuffer intbuffer) {
|
||||
|
||||
for (int i = intbuffer.position(); i < intbuffer.limit(); i++) {
|
||||
int tx = GL11.glGenTextures();
|
||||
intbuffer.put(i, tx);
|
||||
textureNames.add(Integer.valueOf(tx));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static synchronized void deleteTexturesAndDisplayLists() {
|
||||
for (int i = 0; i < displayLists.size(); i += 2) {
|
||||
GL11.glDeleteLists(((Integer) displayLists.get(i)).intValue(),
|
||||
((Integer) displayLists.get(i + 1)).intValue());
|
||||
}
|
||||
|
||||
for (int j = 0; j < textureNames.size(); j++) {
|
||||
GL11.glDeleteTextures(((Integer) textureNames.get(j)).intValue());
|
||||
}
|
||||
|
||||
displayLists.clear();
|
||||
textureNames.clear();
|
||||
}
|
||||
|
||||
public static ByteBuffer createDirectByteBuffer(int par0) {
|
||||
return GL11.isWebGL ? ByteBuffer.wrap(new byte[par0]).order(ByteOrder.nativeOrder()) : ByteBuffer.allocateDirect(par0).order(ByteOrder.nativeOrder());
|
||||
}
|
||||
|
||||
public static IntBuffer createDirectIntBuffer(int par0) {
|
||||
return GL11.isWebGL ? IntBuffer.wrap(new int[par0]) : createDirectByteBuffer(par0 << 2).asIntBuffer();
|
||||
}
|
||||
|
||||
public static FloatBuffer createDirectFloatBuffer(int par0) {
|
||||
return GL11.isWebGL ? FloatBuffer.wrap(new float[par0]) : createDirectByteBuffer(par0 << 2).asFloatBuffer();
|
||||
}
|
||||
|
||||
private static List displayLists = new ArrayList();
|
||||
private static List textureNames = new ArrayList();
|
||||
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
/**
|
||||
* base implementation of MD4 family style digest as outlined in "Handbook of
|
||||
* Applied Cryptography", pages 344 - 347.
|
||||
*/
|
||||
public abstract class GeneralDigest {
|
||||
private byte[] xBuf;
|
||||
private int xBufOff;
|
||||
|
||||
private long byteCount;
|
||||
|
||||
/**
|
||||
* Standard constructor
|
||||
*/
|
||||
protected GeneralDigest() {
|
||||
xBuf = new byte[4];
|
||||
xBufOff = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor. We are using copy constructors in place of the
|
||||
* Object.clone() interface as this interface is not supported by J2ME.
|
||||
*/
|
||||
protected GeneralDigest(GeneralDigest t) {
|
||||
xBuf = new byte[t.xBuf.length];
|
||||
System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length);
|
||||
|
||||
xBufOff = t.xBufOff;
|
||||
byteCount = t.byteCount;
|
||||
}
|
||||
|
||||
public void update(byte in) {
|
||||
xBuf[xBufOff++] = in;
|
||||
|
||||
if (xBufOff == xBuf.length) {
|
||||
processWord(xBuf, 0);
|
||||
xBufOff = 0;
|
||||
}
|
||||
|
||||
byteCount++;
|
||||
}
|
||||
|
||||
public void update(byte[] in, int inOff, int len) {
|
||||
//
|
||||
// fill the current word
|
||||
//
|
||||
while ((xBufOff != 0) && (len > 0)) {
|
||||
update(in[inOff]);
|
||||
|
||||
inOff++;
|
||||
len--;
|
||||
}
|
||||
|
||||
//
|
||||
// process whole words.
|
||||
//
|
||||
while (len > xBuf.length) {
|
||||
processWord(in, inOff);
|
||||
|
||||
inOff += xBuf.length;
|
||||
len -= xBuf.length;
|
||||
byteCount += xBuf.length;
|
||||
}
|
||||
|
||||
//
|
||||
// load in the remainder.
|
||||
//
|
||||
while (len > 0) {
|
||||
update(in[inOff]);
|
||||
|
||||
inOff++;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
long bitLength = (byteCount << 3);
|
||||
|
||||
//
|
||||
// add the pad bytes.
|
||||
//
|
||||
update((byte) 128);
|
||||
|
||||
while (xBufOff != 0) {
|
||||
update((byte) 0);
|
||||
}
|
||||
|
||||
processLength(bitLength);
|
||||
|
||||
processBlock();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
byteCount = 0;
|
||||
|
||||
xBufOff = 0;
|
||||
for (int i = 0; i < xBuf.length; i++) {
|
||||
xBuf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void processWord(byte[] in, int inOff);
|
||||
|
||||
protected abstract void processLength(long bitLength);
|
||||
|
||||
protected abstract void processBlock();
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
|
||||
public class ImageIO {
|
||||
|
||||
public static BufferedImage read(InputStream var1) {
|
||||
ByteArrayInputStream bais = (ByteArrayInputStream)var1;
|
||||
byte[] data = bais.readAllBytes();
|
||||
|
||||
return GL11.loadPNG(data);
|
||||
}
|
||||
|
||||
public static BufferedImage read(BufferedImage resource) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
/**
|
||||
* implementation of SHA-1 as outlined in "Handbook of Applied Cryptography",
|
||||
* pages 346 - 349.
|
||||
*
|
||||
* It is interesting to ponder why the, apart from the extra IV, the other
|
||||
* difference here from MD5 is the "endienness" of the word processing!
|
||||
*/
|
||||
public class SHA1Digest extends GeneralDigest {
|
||||
private static final int DIGEST_LENGTH = 20;
|
||||
|
||||
private int H1, H2, H3, H4, H5;
|
||||
|
||||
private int[] X = new int[80];
|
||||
private int xOff;
|
||||
|
||||
/**
|
||||
* Standard constructor
|
||||
*/
|
||||
public SHA1Digest() {
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor. This will copy the state of the provided message digest.
|
||||
*/
|
||||
public SHA1Digest(SHA1Digest t) {
|
||||
super(t);
|
||||
|
||||
H1 = t.H1;
|
||||
H2 = t.H2;
|
||||
H3 = t.H3;
|
||||
H4 = t.H4;
|
||||
H5 = t.H5;
|
||||
|
||||
System.arraycopy(t.X, 0, X, 0, t.X.length);
|
||||
xOff = t.xOff;
|
||||
}
|
||||
|
||||
public String getAlgorithmName() {
|
||||
return "SHA-1";
|
||||
}
|
||||
|
||||
public int getDigestSize() {
|
||||
return DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
protected void processWord(byte[] in, int inOff) {
|
||||
X[xOff++] = ((in[inOff] & 0xff) << 24) | ((in[inOff + 1] & 0xff) << 16) | ((in[inOff + 2] & 0xff) << 8)
|
||||
| ((in[inOff + 3] & 0xff));
|
||||
|
||||
if (xOff == 16) {
|
||||
processBlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackWord(int word, byte[] out, int outOff) {
|
||||
out[outOff] = (byte) (word >>> 24);
|
||||
out[outOff + 1] = (byte) (word >>> 16);
|
||||
out[outOff + 2] = (byte) (word >>> 8);
|
||||
out[outOff + 3] = (byte) word;
|
||||
}
|
||||
|
||||
protected void processLength(long bitLength) {
|
||||
if (xOff > 14) {
|
||||
processBlock();
|
||||
}
|
||||
|
||||
X[14] = (int) (bitLength >>> 32);
|
||||
X[15] = (int) (bitLength & 0xffffffff);
|
||||
}
|
||||
|
||||
public int doFinal(byte[] out, int outOff) {
|
||||
finish();
|
||||
|
||||
unpackWord(H1, out, outOff);
|
||||
unpackWord(H2, out, outOff + 4);
|
||||
unpackWord(H3, out, outOff + 8);
|
||||
unpackWord(H4, out, outOff + 12);
|
||||
unpackWord(H5, out, outOff + 16);
|
||||
|
||||
reset();
|
||||
|
||||
return DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* reset the chaining variables
|
||||
*/
|
||||
public void reset() {
|
||||
super.reset();
|
||||
|
||||
H1 = 0x67452301;
|
||||
H2 = 0xefcdab89;
|
||||
H3 = 0x98badcfe;
|
||||
H4 = 0x10325476;
|
||||
H5 = 0xc3d2e1f0;
|
||||
|
||||
xOff = 0;
|
||||
for (int i = 0; i != X.length; i++) {
|
||||
X[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Additive constants
|
||||
//
|
||||
private static final int Y1 = 0x5a827999;
|
||||
private static final int Y2 = 0x6ed9eba1;
|
||||
private static final int Y3 = 0x8f1bbcdc;
|
||||
private static final int Y4 = 0xca62c1d6;
|
||||
|
||||
private int f(int u, int v, int w) {
|
||||
return ((u & v) | ((~u) & w));
|
||||
}
|
||||
|
||||
private int h(int u, int v, int w) {
|
||||
return (u ^ v ^ w);
|
||||
}
|
||||
|
||||
private int g(int u, int v, int w) {
|
||||
return ((u & v) | (u & w) | (v & w));
|
||||
}
|
||||
|
||||
private int rotateLeft(int x, int n) {
|
||||
return (x << n) | (x >>> (32 - n));
|
||||
}
|
||||
|
||||
protected void processBlock() {
|
||||
//
|
||||
// expand 16 word block into 80 word block.
|
||||
//
|
||||
for (int i = 16; i <= 79; i++) {
|
||||
X[i] = rotateLeft((X[i - 3] ^ X[i - 8] ^ X[i - 14] ^ X[i - 16]), 1);
|
||||
}
|
||||
|
||||
//
|
||||
// set up working variables.
|
||||
//
|
||||
int A = H1;
|
||||
int B = H2;
|
||||
int C = H3;
|
||||
int D = H4;
|
||||
int E = H5;
|
||||
|
||||
//
|
||||
// round 1
|
||||
//
|
||||
for (int j = 0; j <= 19; j++) {
|
||||
int t = rotateLeft(A, 5) + f(B, C, D) + E + X[j] + Y1;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
//
|
||||
// round 2
|
||||
//
|
||||
for (int j = 20; j <= 39; j++) {
|
||||
int t = rotateLeft(A, 5) + h(B, C, D) + E + X[j] + Y2;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
//
|
||||
// round 3
|
||||
//
|
||||
for (int j = 40; j <= 59; j++) {
|
||||
int t = rotateLeft(A, 5) + g(B, C, D) + E + X[j] + Y3;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
//
|
||||
// round 4
|
||||
//
|
||||
for (int j = 60; j <= 79; j++) {
|
||||
int t = rotateLeft(A, 5) + h(B, C, D) + E + X[j] + Y4;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
H1 += A;
|
||||
H2 += B;
|
||||
H3 += C;
|
||||
H4 += D;
|
||||
H5 += E;
|
||||
|
||||
//
|
||||
// reset the offset and clean out the word buffer.
|
||||
//
|
||||
xOff = 0;
|
||||
for (int i = 0; i != X.length; i++) {
|
||||
X[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,26 +0,0 @@
|
|||
package net.lax1dude.eaglercraft.adapter;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022-2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class FileChooserResult {
|
||||
|
||||
public final String fileName;
|
||||
public final byte[] fileData;
|
||||
|
||||
public FileChooserResult(String fileName, byte[] fileData) {
|
||||
this.fileName = fileName;
|
||||
this.fileData = fileData;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
public class BufferConverter {
|
||||
|
||||
public static final byte[] convertByteBuffer(ByteBuffer b) {
|
||||
byte[] ret = new byte[b.limit() - b.position()];
|
||||
b.get(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static final short[] convertShortBuffer(ShortBuffer b) {
|
||||
short[] ret = new short[b.limit() - b.position()];
|
||||
b.get(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static final int[] convertIntBuffer(IntBuffer b) {
|
||||
int[] ret = new int[b.limit() - b.position()];
|
||||
b.get(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static final float[] convertFloatBuffer(FloatBuffer b) {
|
||||
float[] ret = new float[b.limit() - b.position()];
|
||||
b.get(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.webgl.WebGLRenderingContext;
|
||||
|
||||
public interface WebGL2RenderingContext extends WebGLRenderingContext {
|
||||
|
||||
int TEXTURE_MAX_LEVEL = 0x0000813D;
|
||||
int TEXTURE_MAX_ANISOTROPY_EXT = 0x000084FE;
|
||||
int UNSIGNED_INT_24_8 = 0x000084FA;
|
||||
int ANY_SAMPLES_PASSED = 0x00008D6A;
|
||||
int QUERY_RESULT = 0x00008866;
|
||||
int QUERY_RESULT_AVAILABLE = 0x00008867;
|
||||
int DEPTH24_STENCIL8 = 0x000088F0;
|
||||
int DEPTH_COMPONENT32F = 0x00008CAC;
|
||||
int READ_FRAMEBUFFER = 0x00008CA8;
|
||||
int DRAW_FRAMEBUFFER = 0x00008CA9;
|
||||
int RGB8 = 0x00008051;
|
||||
int RGBA8 = 0x00008058;
|
||||
|
||||
WebGLQuery createQuery();
|
||||
|
||||
void beginQuery(int p1, WebGLQuery obj);
|
||||
|
||||
void endQuery(int p1);
|
||||
|
||||
void deleteQuery(WebGLQuery obj);
|
||||
|
||||
int getQueryParameter(WebGLQuery obj, int p2);
|
||||
|
||||
WebGLVertexArray createVertexArray();
|
||||
|
||||
void deleteVertexArray(WebGLVertexArray obj);
|
||||
|
||||
void bindVertexArray(WebGLVertexArray obj);
|
||||
|
||||
void renderbufferStorageMultisample(int p1, int p2, int p3, int p4, int p5);
|
||||
|
||||
void blitFramebuffer(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10);
|
||||
|
||||
void drawBuffers(int[] p1);
|
||||
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
public interface WebGLQuery extends JSObject {
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
public interface WebGLVertexArray extends JSObject {
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package net.minecraft.client;
|
||||
|
||||
import net.PeytonPlayz585.input.Keyboard;
|
||||
import net.PeytonPlayz585.input.Mouse;
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.src.AchievementList;
|
||||
import net.minecraft.src.AxisAlignedBB;
|
||||
import net.minecraft.src.Block;
|
||||
|
@ -136,9 +138,9 @@ public class Minecraft implements Runnable {
|
|||
|
||||
public Minecraft() {
|
||||
StatList.func_27360_a();
|
||||
this.tempDisplayHeight = GL11.getCanvasHeight();
|
||||
this.displayWidth = GL11.getCanvasWidth();
|
||||
this.displayHeight = GL11.getCanvasHeight();
|
||||
this.tempDisplayHeight = GL11.EaglerAdapterImpl2.getCanvasHeight();
|
||||
this.displayWidth = GL11.EaglerAdapterImpl2.getCanvasWidth();
|
||||
this.displayHeight = GL11.EaglerAdapterImpl2.getCanvasHeight();
|
||||
|
||||
theMinecraft = this;
|
||||
}
|
||||
|
@ -233,7 +235,7 @@ public class Minecraft implements Runnable {
|
|||
|
||||
//Emulate Display.swapBuffers()
|
||||
GL11.glFlush();
|
||||
GL11.updateDisplay();
|
||||
Display.update();
|
||||
GL11.optimize();
|
||||
}
|
||||
|
||||
|
@ -370,7 +372,7 @@ public class Minecraft implements Runnable {
|
|||
this.theWorld.updatingLighting();
|
||||
}
|
||||
|
||||
GL11.updateDisplay();
|
||||
Display.update();
|
||||
|
||||
if(this.thePlayer != null && this.thePlayer.isEntityInsideOpaqueBlock()) {
|
||||
this.gameSettings.thirdPersonView = false;
|
||||
|
@ -393,9 +395,9 @@ public class Minecraft implements Runnable {
|
|||
this.guiAchievement.updateAchievementWindow();
|
||||
Thread.yield();
|
||||
|
||||
if(GL11.getCanvasWidth() != this.displayWidth || GL11.getCanvasHeight() != this.displayHeight) {
|
||||
this.displayWidth = GL11.getCanvasWidth();
|
||||
this.displayHeight = GL11.getCanvasHeight();
|
||||
if(GL11.EaglerAdapterImpl2.getCanvasWidth() != this.displayWidth || GL11.EaglerAdapterImpl2.getCanvasHeight() != this.displayHeight) {
|
||||
this.displayWidth = GL11.EaglerAdapterImpl2.getCanvasWidth();
|
||||
this.displayHeight = GL11.EaglerAdapterImpl2.getCanvasHeight();
|
||||
if(this.displayWidth <= 0) {
|
||||
this.displayWidth = 1;
|
||||
}
|
||||
|
@ -784,19 +786,19 @@ public class Minecraft implements Runnable {
|
|||
this.displayInGameMenu();
|
||||
}
|
||||
|
||||
if(Keyboard.getEventKey() == 33 && GL11.isKeyDown(2)) {
|
||||
if(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(2)) {
|
||||
this.gameSettings.hideGUI = !this.gameSettings.hideGUI;
|
||||
}
|
||||
|
||||
if(Keyboard.getEventKey() == 33 && GL11.isKeyDown(4)) {
|
||||
if(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(4)) {
|
||||
this.gameSettings.showDebugInfo = !this.gameSettings.showDebugInfo;
|
||||
}
|
||||
|
||||
if(Keyboard.getEventKey() == 33 && GL11.isKeyDown(6)) {
|
||||
if(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(6)) {
|
||||
this.gameSettings.thirdPersonView = !this.gameSettings.thirdPersonView;
|
||||
}
|
||||
|
||||
if(Keyboard.getEventKey() == 33 && GL11.isKeyDown(9)) {
|
||||
if(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(9)) {
|
||||
this.gameSettings.smoothCamera = !this.gameSettings.smoothCamera;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
|
||||
public class ChunkLoader implements IChunkLoader {
|
||||
private String saveDir;
|
||||
|
@ -34,7 +34,7 @@ public class ChunkLoader implements IChunkLoader {
|
|||
|
||||
public Chunk loadChunk(World var1, int var2, int var3) throws IOException {
|
||||
String var4 = this.chunkFileForXZ(var2, var3);
|
||||
byte[] chunkData = GL11.readFile(var4);
|
||||
byte[] chunkData = File.readFile(var4);
|
||||
|
||||
if(chunkData != null) {
|
||||
try {
|
||||
|
@ -45,7 +45,7 @@ public class ChunkLoader implements IChunkLoader {
|
|||
int z = var6.getInteger("zPos");
|
||||
if(var2 != x || var3 != z) {
|
||||
String var7 = this.chunkFileForXZ(x, z);
|
||||
GL11.renameFile(var4, var7);
|
||||
File.renameFile(var4, var7);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class ChunkLoader implements IChunkLoader {
|
|||
var7.func_25124_i();
|
||||
return var7;
|
||||
} catch(IOException e) {
|
||||
GL11.deleteFile(var4);
|
||||
File.deleteFile(var4);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
|
@ -66,9 +66,9 @@ public class ChunkLoader implements IChunkLoader {
|
|||
String var3 = this.chunkFileForXZ(var2.xPosition, var2.zPosition);
|
||||
ByteArrayOutputStream var5 = new ByteArrayOutputStream();
|
||||
|
||||
if(GL11.exists(var3)) {
|
||||
if(File.exists(var3)) {
|
||||
WorldInfo var4 = var1.getWorldInfo();
|
||||
var4.setSizeOnDisk(var4.getSizeOnDisk() - GL11.getFileSize(var3));
|
||||
var4.setSizeOnDisk(var4.getSizeOnDisk() - File.getFileSize(var3));
|
||||
}
|
||||
|
||||
NBTTagCompound var6 = new NBTTagCompound();
|
||||
|
@ -84,9 +84,9 @@ public class ChunkLoader implements IChunkLoader {
|
|||
}
|
||||
|
||||
var5.flush();
|
||||
GL11.writeFile(var3, var5.toByteArray());
|
||||
File.writeFile(var3, var5.toByteArray());
|
||||
WorldInfo var8 = var1.getWorldInfo();
|
||||
var8.setSizeOnDisk(var8.getSizeOnDisk() + GL11.getFileSize(var3));
|
||||
var8.setSizeOnDisk(var8.getSizeOnDisk() + File.getFileSize(var3));
|
||||
}
|
||||
|
||||
public static void storeChunkInCompound(Chunk var0, World var1, NBTTagCompound var2) {
|
||||
|
|
|
@ -11,9 +11,8 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
|
||||
import static net.PeytonPlayz585.opengl.GL11.FileEntry;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
import net.PeytonPlayz585.fileutils.FileEntry;
|
||||
|
||||
public class EaglerSaveFormat implements ISaveFormat {
|
||||
|
||||
|
@ -37,7 +36,7 @@ public class EaglerSaveFormat implements ISaveFormat {
|
|||
//Returns a list a worlds
|
||||
public List func_22176_b() {
|
||||
ArrayList<SaveFormatComparator> lst = new ArrayList<>();
|
||||
GL11.listFilesAndDirectories(saveDir).forEach(new Consumer<FileEntry>() {
|
||||
File.listFilesAndDirectories(saveDir).forEach(new Consumer<FileEntry>() {
|
||||
@Override
|
||||
public void accept(FileEntry t) {
|
||||
if(!t.isDirectory) {
|
||||
|
@ -45,7 +44,7 @@ public class EaglerSaveFormat implements ISaveFormat {
|
|||
}
|
||||
String folderName = t.getName();
|
||||
String dir = t.path;
|
||||
byte[] lvl = GL11.readFile(dir + "/level.dat");
|
||||
byte[] lvl = File.readFile(dir + "/level.dat");
|
||||
if(lvl != null) {
|
||||
try {
|
||||
NBTBase nbt = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(lvl)));
|
||||
|
@ -78,7 +77,7 @@ public class EaglerSaveFormat implements ISaveFormat {
|
|||
|
||||
//Returns world info for the world
|
||||
public WorldInfo func_22173_b(String var1) {
|
||||
byte[] lvl = GL11.readFile(saveDir + "/" + var1 + "/level.dat");
|
||||
byte[] lvl = File.readFile(saveDir + "/" + var1 + "/level.dat");
|
||||
if(lvl != null) {
|
||||
try {
|
||||
NBTBase nbt = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(lvl)));
|
||||
|
@ -113,7 +112,7 @@ public class EaglerSaveFormat implements ISaveFormat {
|
|||
if(var2.contains("/saves/saves/")) {
|
||||
var2 = var2.replace("/saves/saves/", "/saves/");
|
||||
}
|
||||
byte[] lvl = GL11.readFile(saveDir + "/" + var1 + "/level.dat");
|
||||
byte[] lvl = File.readFile(saveDir + "/" + var1 + "/level.dat");
|
||||
if(lvl != null) {
|
||||
try {
|
||||
NBTBase nbt = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(lvl)));
|
||||
|
@ -122,7 +121,7 @@ public class EaglerSaveFormat implements ISaveFormat {
|
|||
w.setString("LevelName", var2);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(lvl.length + 16 + var2.length() * 2);
|
||||
NBTBase.writeTag(w, new DataOutputStream(out));
|
||||
GL11.writeFile(saveDir + "/" + var1 + "/level.dat", out.toByteArray());
|
||||
File.writeFile(saveDir + "/" + var1 + "/level.dat", out.toByteArray());
|
||||
}else {
|
||||
throw new IOException("file '" + saveDir + "/" + var1 + "/level.dat' does not contain an NBTTagCompound");
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
|
||||
public class EaglerSaveHandler implements ISaveHandler {
|
||||
|
||||
|
@ -18,7 +18,7 @@ public class EaglerSaveHandler implements ISaveHandler {
|
|||
}
|
||||
|
||||
public WorldInfo loadWorldInfo() {
|
||||
byte[] file = GL11.readFile(saveDir + "/level.dat");
|
||||
byte[] file = File.readFile(saveDir + "/level.dat");
|
||||
if(file != null) {
|
||||
try {
|
||||
NBTBase nbt = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(file)));
|
||||
|
@ -55,7 +55,7 @@ public class EaglerSaveHandler implements ISaveHandler {
|
|||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
GL11.writeFile(saveDir + "/level.dat", out.toByteArray());
|
||||
File.writeFile(saveDir + "/level.dat", out.toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +69,7 @@ public class EaglerSaveHandler implements ISaveHandler {
|
|||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
GL11.writeFile(saveDir + "/level.dat", out.toByteArray());
|
||||
File.writeFile(saveDir + "/level.dat", out.toByteArray());
|
||||
}
|
||||
|
||||
public String func_28113_a(String var1) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import net.PeytonPlayz585.glemu.GameOverlayFramebuffer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
|
||||
|
@ -328,7 +329,7 @@ public class EntityRenderer {
|
|||
}
|
||||
|
||||
public void updateCameraAndRender(float var1) {
|
||||
if(!GL11.isFocused()) {
|
||||
if(!Display.isFocused()) {
|
||||
this.mc.displayInGameMenu();
|
||||
} else {
|
||||
this.prevFrameTime = System.currentTimeMillis();
|
||||
|
|
|
@ -2,23 +2,24 @@ package net.minecraft.src;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
import net.PeytonPlayz585.fileutils.FileEntry;
|
||||
|
||||
public class FilesystemUtils {
|
||||
|
||||
public static void recursiveDeleteDirectory(String dir) {
|
||||
Collection<GL11.FileEntry> lst = GL11.listFiles(dir, true, true);
|
||||
for(GL11.FileEntry t : lst) {
|
||||
Collection<FileEntry> lst = File.listFiles(dir, true, true);
|
||||
for(FileEntry t : lst) {
|
||||
if(!t.isDirectory) {
|
||||
GL11.deleteFile(t.path);
|
||||
File.deleteFile(t.path);
|
||||
}
|
||||
}
|
||||
for(GL11.FileEntry t : lst) {
|
||||
for(FileEntry t : lst) {
|
||||
if(t.isDirectory) {
|
||||
GL11.deleteFile(t.path);
|
||||
File.deleteFile(t.path);
|
||||
}
|
||||
}
|
||||
GL11.deleteFile(dir);
|
||||
File.deleteFile(dir);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import java.util.Map;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.lax1dude.eaglercraft.BufferedImage;
|
||||
import net.lax1dude.eaglercraft.ImageIO;
|
||||
import net.PeytonPlayz585.awt.image.BufferedImage;
|
||||
import net.PeytonPlayz585.awt.image.ImageIO;
|
||||
|
||||
public class FontRenderer {
|
||||
private int[] charWidth = new int[256];
|
||||
|
|
|
@ -49,14 +49,14 @@ public class GLAllocation {
|
|||
}
|
||||
|
||||
public static ByteBuffer createDirectByteBuffer(int par0) {
|
||||
return GL11.isWebGL ? ByteBuffer.wrap(new byte[par0]).order(ByteOrder.nativeOrder()) : ByteBuffer.allocateDirect(par0).order(ByteOrder.nativeOrder());
|
||||
return ByteBuffer.wrap(new byte[par0]).order(ByteOrder.nativeOrder());
|
||||
}
|
||||
|
||||
public static IntBuffer createDirectIntBuffer(int par0) {
|
||||
return GL11.isWebGL ? IntBuffer.wrap(new int[par0]) : createDirectByteBuffer(par0 << 2).asIntBuffer();
|
||||
return IntBuffer.wrap(new int[par0]);
|
||||
}
|
||||
|
||||
public static FloatBuffer createDirectFloatBuffer(int par0) {
|
||||
return GL11.isWebGL ? FloatBuffer.wrap(new float[par0]) : createDirectByteBuffer(par0 << 2).asFloatBuffer();
|
||||
return FloatBuffer.wrap(new float[par0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
@ -177,11 +178,11 @@ public class GameSettings {
|
|||
|
||||
public void loadOptions() {
|
||||
try {
|
||||
if(!GL11.exists(this.optionsFile)) {
|
||||
if(!File.exists(this.optionsFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(GL11.readFile(this.optionsFile));
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(File.readFile(this.optionsFile));
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(byteArrayInputStream, "UTF-8");
|
||||
BufferedReader var1 = new BufferedReader(inputStreamReader);
|
||||
String var2 = "";
|
||||
|
@ -301,7 +302,7 @@ public class GameSettings {
|
|||
|
||||
var1.flush();
|
||||
byte[] data = byteArrayOutputStream.toByteArray();
|
||||
GL11.writeFile(this.optionsFile, data);
|
||||
File.writeFile(this.optionsFile, data);
|
||||
|
||||
var1.close();
|
||||
} catch (Exception var3) {
|
||||
|
|
|
@ -165,9 +165,9 @@ public class GuiIngame extends Gui {
|
|||
var8.drawStringWithShadow(this.mc.func_6262_n(), 2, 22, 16777215);
|
||||
var8.drawStringWithShadow(this.mc.func_6245_o(), 2, 32, 16777215);
|
||||
var8.drawStringWithShadow(this.mc.func_21002_o(), 2, 42, 16777215);
|
||||
long var24 = GL11.maxMemory();
|
||||
long var29 = GL11.totalMemory();
|
||||
long var30 = GL11.freeMemory();
|
||||
long var24 = GL11.EaglerAdapterImpl2.maxMemory();
|
||||
long var29 = GL11.EaglerAdapterImpl2.totalMemory();
|
||||
long var30 = GL11.EaglerAdapterImpl2.freeMemory();
|
||||
long var21 = var29 - var30;
|
||||
var23 = "Used memory: " + var21 * 100L / var24 + "% (" + var21 / 1024L / 1024L + "MB) of " + var24 / 1024L / 1024L + "MB";
|
||||
this.drawString(var8, var23, var6 - var8.getStringWidth(var23) - 2, 2, 14737632);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import net.lax1dude.eaglercraft.BufferedImage;
|
||||
import net.PeytonPlayz585.awt.image.BufferedImage;
|
||||
|
||||
public class IsoImageBuffer {
|
||||
public BufferedImage field_1348_a;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class LoadingScreenRenderer implements IProgressUpdate {
|
||||
|
@ -109,7 +111,7 @@ public class LoadingScreenRenderer implements IProgressUpdate {
|
|||
|
||||
this.mc.fontRenderer.drawStringWithShadow(this.field_1007_c, (var5 - this.mc.fontRenderer.getStringWidth(this.field_1007_c)) / 2, var6 / 2 - 4 - 16, 16777215);
|
||||
this.mc.fontRenderer.drawStringWithShadow(this.field_1004_a, (var5 - this.mc.fontRenderer.getStringWidth(this.field_1004_a)) / 2, var6 / 2 - 4 + 8, 16777215);
|
||||
GL11.updateDisplay();
|
||||
Display.update();
|
||||
|
||||
try {
|
||||
Thread.yield();
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.minecraft.src;
|
|||
import java.util.Iterator;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.lax1dude.eaglercraft.BufferedImage;
|
||||
import net.PeytonPlayz585.awt.image.BufferedImage;
|
||||
|
||||
public class MapItemRenderer {
|
||||
private int[] field_28159_a = new int[16384];
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
|
||||
public class MapStorage {
|
||||
private ISaveHandler field_28191_a;
|
||||
|
@ -31,14 +31,14 @@ public class MapStorage {
|
|||
if(this.field_28191_a != null) {
|
||||
try {
|
||||
String var4 = this.field_28191_a.func_28113_a(var2);
|
||||
if(var4 != null && GL11.exists(var4)) {
|
||||
if(var4 != null && File.exists(var4)) {
|
||||
try {
|
||||
var3 = (MapDataBase)var1.getConstructor(new Class[]{String.class}).newInstance(new Object[]{var2});
|
||||
} catch (Exception var7) {
|
||||
throw new RuntimeException("Failed to instantiate " + var1.toString(), var7);
|
||||
}
|
||||
|
||||
ByteArrayInputStream var5 = new ByteArrayInputStream(GL11.readFile(var4));
|
||||
ByteArrayInputStream var5 = new ByteArrayInputStream(File.readFile(var4));
|
||||
NBTTagCompound var6 = CompressedStreamTools.func_1138_a(var5);
|
||||
var5.close();
|
||||
var3.readFromNBT(var6.getCompoundTag("data"));
|
||||
|
@ -92,7 +92,7 @@ public class MapStorage {
|
|||
var4.setCompoundTag("data", var3);
|
||||
ByteArrayOutputStream var5 = new ByteArrayOutputStream();
|
||||
CompressedStreamTools.writeGzippedCompoundToOutputStream(var4, var5);
|
||||
GL11.writeFile(var2, var5.toByteArray());
|
||||
File.writeFile(var2, var5.toByteArray());
|
||||
var5.close();
|
||||
}
|
||||
} catch (Exception var6) {
|
||||
|
@ -110,8 +110,8 @@ public class MapStorage {
|
|||
}
|
||||
|
||||
String var1 = this.field_28191_a.func_28113_a("idcounts");
|
||||
if(var1 != null && GL11.exists(var1)) {
|
||||
DataInputStream var2 = new DataInputStream(new ByteArrayInputStream(GL11.readFile(var1)));
|
||||
if(var1 != null && File.exists(var1)) {
|
||||
DataInputStream var2 = new DataInputStream(new ByteArrayInputStream(File.readFile(var1)));
|
||||
NBTTagCompound var3 = CompressedStreamTools.func_1141_a(var2);
|
||||
var2.close();
|
||||
Iterator var4 = var3.func_28110_c().iterator();
|
||||
|
@ -159,7 +159,7 @@ public class MapStorage {
|
|||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream var9 = new DataOutputStream(baos);
|
||||
CompressedStreamTools.func_1139_a(var4, var9);
|
||||
GL11.writeFile(var3, baos.toByteArray());
|
||||
File.writeFile(var3, baos.toByteArray());
|
||||
var9.close();
|
||||
}
|
||||
} catch (Exception var8) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import net.PeytonPlayz585.input.Mouse;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
public class MouseHelper {
|
||||
public int deltaX;
|
||||
|
|
|
@ -7,7 +7,8 @@ import java.io.IOException;
|
|||
//import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.PeytonPlayz585.socket.Socket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
|
@ -31,7 +32,7 @@ public class NetClientHandler extends NetHandler {
|
|||
uri = var2.substring(6);
|
||||
}else if(!var2.contains("://")){
|
||||
uri = var2;
|
||||
if(GL11.isSSLPage()) {
|
||||
if(GL11.EaglerAdapterImpl2.isSSLPage()) {
|
||||
var2 = "wss://" + var2;
|
||||
} else {
|
||||
var2 = "ws://" + var2;
|
||||
|
|
|
@ -12,8 +12,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.lax1dude.eaglercraft.BufferedImage;
|
||||
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2.TextureGL;
|
||||
import net.PeytonPlayz585.awt.image.BufferedImage;
|
||||
|
||||
public class RenderEngine {
|
||||
public static boolean useMipmaps = false;
|
||||
|
@ -390,7 +389,7 @@ public class RenderEngine {
|
|||
}
|
||||
|
||||
private BufferedImage readTextureImage(InputStream var1) throws IOException {
|
||||
return GL11.loadPNG(((ByteArrayInputStream)var1).readAllBytes());
|
||||
return GL11.EaglerAdapterImpl2.loadPNG(((ByteArrayInputStream)var1).readAllBytes());
|
||||
}
|
||||
|
||||
public void bindTexture(int var1) {
|
||||
|
|
|
@ -16,6 +16,7 @@ public class RenderHelper {
|
|||
GL11.glEnable(GL11.GL_LIGHT1);
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
|
||||
GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
|
||||
GL11.copyModelToLightMatrix();
|
||||
GL11.copyModelToLightMatrix2();
|
||||
GL11.flipBothLightMatrix();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.minecraft.src;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class SoundManager {
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class SoundManager {
|
|||
|
||||
public void onSoundOptionsChanged() {
|
||||
for(int i = 0; i < sounds.size(); i++) {
|
||||
if(!GL11.isPlaying(sounds.get(i))) {
|
||||
if(!GL11.EaglerAdapterImpl2.isPlaying(sounds.get(i))) {
|
||||
sounds.remove(i);
|
||||
}
|
||||
}
|
||||
|
@ -32,24 +32,24 @@ public class SoundManager {
|
|||
if(loaded) {
|
||||
if(this.options.musicVolume == 0.0F) {
|
||||
if(BgMusic != -1) {
|
||||
GL11.endSound(BgMusic);
|
||||
GL11.EaglerAdapterImpl2.endSound(BgMusic);
|
||||
}
|
||||
} else {
|
||||
if(BgMusic != -1) {
|
||||
GL11.setVolume(BgMusic, this.options.musicVolume);
|
||||
GL11.EaglerAdapterImpl2.setVolume(BgMusic, this.options.musicVolume);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.options.soundVolume == 0.0F) {
|
||||
for(Integer i : sounds) {
|
||||
if(i != -1) {
|
||||
GL11.endSound(i);
|
||||
GL11.EaglerAdapterImpl2.endSound(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Integer i : sounds) {
|
||||
if(i != -1) {
|
||||
GL11.setVolume(i, this.options.soundVolume);
|
||||
GL11.EaglerAdapterImpl2.setVolume(i, this.options.soundVolume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +70,13 @@ public class SoundManager {
|
|||
|
||||
public void playRandomMusicIfReady() {
|
||||
for(int i = 0; i < sounds.size(); i++) {
|
||||
if(!GL11.isPlaying(sounds.get(i))) {
|
||||
if(!GL11.EaglerAdapterImpl2.isPlaying(sounds.get(i))) {
|
||||
sounds.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
if(loaded && this.options.musicVolume != 0.0F) {
|
||||
if(!GL11.isPlaying(BgMusic)) {
|
||||
if(!GL11.EaglerAdapterImpl2.isPlaying(BgMusic)) {
|
||||
try {
|
||||
if(this.ticksBeforeMusic > 0) {
|
||||
--this.ticksBeforeMusic;
|
||||
|
@ -86,7 +86,7 @@ public class SoundManager {
|
|||
//Apparently I DO NOT know how to use random.nextInt
|
||||
int var1 = rand.nextInt(music.length);
|
||||
this.ticksBeforeMusic = this.rand.nextInt(12000) + 12000;
|
||||
BgMusic = GL11.beginPlaybackStatic(music[var1].replace(".", "/").replace("_", "."), this.options.musicVolume, 1.0F);
|
||||
BgMusic = GL11.EaglerAdapterImpl2.beginPlaybackStatic(music[var1].replace(".", "/").replace("_", "."), this.options.musicVolume, 1.0F);
|
||||
} catch(Exception e) {
|
||||
BgMusic = -1;
|
||||
return;
|
||||
|
@ -97,7 +97,7 @@ public class SoundManager {
|
|||
|
||||
public void func_338_a(EntityLiving var1, float var2) {
|
||||
for(int i = 0; i < sounds.size(); i++) {
|
||||
if(!GL11.isPlaying(sounds.get(i))) {
|
||||
if(!GL11.EaglerAdapterImpl2.isPlaying(sounds.get(i))) {
|
||||
sounds.remove(i);
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class SoundManager {
|
|||
double var6 = var1.prevPosY + (var1.posY - var1.prevPosY) * (double)var2;
|
||||
double var8 = var1.prevPosZ + (var1.posZ - var1.prevPosZ) * (double)var2;
|
||||
try {
|
||||
GL11.setListenerPos((float)var4, (float)var6, (float)var8, (float)var1.motionX, (float)var1.motionY, (float)var1.motionZ, (float)var9, (float)var3);
|
||||
GL11.EaglerAdapterImpl2.setListenerPos((float)var4, (float)var6, (float)var8, (float)var1.motionX, (float)var1.motionY, (float)var1.motionZ, (float)var9, (float)var3);
|
||||
} catch(Exception e) {
|
||||
// ???
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public class SoundManager {
|
|||
|
||||
public void playSound(String var1, float var2, float var3, float var4, float var5, float var6, int number) {
|
||||
for(int i = 0; i < sounds.size(); i++) {
|
||||
if(!GL11.isPlaying(sounds.get(i))) {
|
||||
if(!GL11.EaglerAdapterImpl2.isPlaying(sounds.get(i))) {
|
||||
sounds.remove(i);
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class SoundManager {
|
|||
var5 = 1.0F;
|
||||
}
|
||||
|
||||
int i = GL11.beginPlayback(var7.replace("0", ""), var2, var3, var4, var5 * this.options.soundVolume, var6);
|
||||
int i = GL11.EaglerAdapterImpl2.beginPlayback(var7.replace("0", ""), var2, var3, var4, var5 * this.options.soundVolume, var6);
|
||||
if(i != -1) {
|
||||
sounds.add(i);
|
||||
} else {
|
||||
|
@ -161,7 +161,7 @@ public class SoundManager {
|
|||
|
||||
public void playSoundFX(String var1, float var2, float var3, int number) {
|
||||
for(int i = 0; i < sounds.size(); i++) {
|
||||
if(!GL11.isPlaying(sounds.get(i))) {
|
||||
if(!GL11.EaglerAdapterImpl2.isPlaying(sounds.get(i))) {
|
||||
sounds.remove(i);
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public class SoundManager {
|
|||
var2 = 1.0F;
|
||||
}
|
||||
|
||||
int i = GL11.beginPlaybackStatic(var4.replace("0", ""), var2 * this.options.soundVolume, var3);
|
||||
int i = GL11.EaglerAdapterImpl2.beginPlaybackStatic(var4.replace("0", ""), var2 * this.options.soundVolume, var3);
|
||||
if(i != -1) {
|
||||
sounds.add(i);
|
||||
} else {
|
||||
|
|
|
@ -6,7 +6,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
import net.PeytonPlayz585.fileutils.FileEntry;
|
||||
|
||||
public class StatFileWriter {
|
||||
private Map field_25102_a = new HashMap();
|
||||
|
@ -17,16 +18,16 @@ public class StatFileWriter {
|
|||
public StatFileWriter(Session var1, String var2) {
|
||||
String var3 = var2 + "/" + "stats";
|
||||
|
||||
GL11.FileEntry[] var4 = GL11.listFiles(var2);
|
||||
FileEntry[] var4 = File.listFiles(var2);
|
||||
int var5 = var4.length;
|
||||
|
||||
for(int var6 = 0; var6 < var5; ++var6) {
|
||||
GL11.FileEntry var7 = var4[var6];
|
||||
FileEntry var7 = var4[var6];
|
||||
if(var7.getName().startsWith("stats_") && var7.getName().endsWith(".dat")) {
|
||||
String var8 = var3 + "/" + var7.getName();
|
||||
if(!GL11.exists(var8)) {
|
||||
if(!File.exists(var8)) {
|
||||
System.out.println("Relocating " + var7.getName());
|
||||
GL11.renameFile(var7.path, var8);
|
||||
File.renameFile(var7.path, var8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.io.InputStreamReader;
|
|||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import net.PeytonPlayz585.opengl.GL11;
|
||||
import net.PeytonPlayz585.fileutils.File;
|
||||
|
||||
public class StatsSyncher {
|
||||
private volatile boolean field_27438_a = false;
|
||||
|
@ -43,7 +43,7 @@ public class StatsSyncher {
|
|||
|
||||
this.field_27435_d = var2;
|
||||
this.field_27428_k = var1;
|
||||
if(GL11.exists(this.field_27434_e)) {
|
||||
if(File.exists(this.field_27434_e)) {
|
||||
var2.func_27179_a(this.func_27415_a(this.field_27434_e, this.field_27432_g, this.field_27430_i));
|
||||
}
|
||||
|
||||
|
@ -52,18 +52,18 @@ public class StatsSyncher {
|
|||
|
||||
private void func_28214_a(String var1, String var2, String var3) {
|
||||
String var4 = makeFilePath(var1, var2);
|
||||
if(GL11.exists(var4) && !GL11.directoryExists(var4) && !GL11.exists(var3)) {
|
||||
GL11.renameFile(var4, var3);
|
||||
if(File.exists(var4) && !File.directoryExists(var4) && !File.exists(var3)) {
|
||||
File.renameFile(var4, var3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map func_27415_a(String var1, String var2, String var3) {
|
||||
return GL11.exists(var1) ? this.func_27408_a(var1) : (GL11.exists(var3) ? this.func_27408_a(var3) : (GL11.exists(var2) ? this.func_27408_a(var2) : null));
|
||||
return File.exists(var1) ? this.func_27408_a(var1) : (File.exists(var3) ? this.func_27408_a(var3) : (File.exists(var2) ? this.func_27408_a(var2) : null));
|
||||
}
|
||||
|
||||
private Map func_27408_a(String var1) {
|
||||
byte[] bytes = GL11.readFile(var1);
|
||||
byte[] bytes = File.readFile(var1);
|
||||
if (bytes == null || bytes.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -76,20 +76,20 @@ public class StatsSyncher {
|
|||
|
||||
try {
|
||||
var5.print(StatFileWriter.func_27185_a(this.field_27428_k.username, "local", var1));
|
||||
GL11.writeFile(var3, baos.toByteArray());
|
||||
File.writeFile(var3, baos.toByteArray());
|
||||
} finally {
|
||||
var5.close();
|
||||
}
|
||||
|
||||
if(GL11.exists(var4)) {
|
||||
GL11.deleteFile(var4);
|
||||
if(File.exists(var4)) {
|
||||
File.deleteFile(var4);
|
||||
}
|
||||
|
||||
if(GL11.exists(var2)) {
|
||||
GL11.renameFile(var2, var4);
|
||||
if(File.exists(var2)) {
|
||||
File.renameFile(var2, var4);
|
||||
}
|
||||
|
||||
GL11.renameFile(var3, var2);
|
||||
File.renameFile(var3, var2);
|
||||
}
|
||||
|
||||
public void func_27418_a() {
|
||||
|
|
|
@ -4,8 +4,8 @@ import java.util.Arrays;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.lax1dude.eaglercraft.BufferedImage;
|
||||
import net.lax1dude.eaglercraft.ImageIO;
|
||||
import net.PeytonPlayz585.awt.image.BufferedImage;
|
||||
import net.PeytonPlayz585.awt.image.ImageIO;
|
||||
|
||||
public class TerrainTextureManager {
|
||||
private float[] field_1181_a = new float[768];
|
||||
|
|
|
@ -54,7 +54,7 @@ public class Tessellator {
|
|||
}
|
||||
|
||||
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
|
||||
GL11.glDrawArrays(this.drawMode, GL11.GL_POINTS, this.vertexCount, Int32Array.create(intBuffer.getBuffer(), 0, this.vertexCount * 7));
|
||||
GL11.glDrawArrays(this.drawMode, GL11.GL_POINTS, this.vertexCount, Int32Array.create(intBuffer.getBuffer(), 0, this.vertexCount * 8));
|
||||
|
||||
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
|
||||
if(this.hasTexture) {
|
||||
|
@ -189,7 +189,7 @@ public class Tessellator {
|
|||
intBuffer0.set(this.rawBufferIndex + 6, this.normal);
|
||||
}
|
||||
|
||||
this.rawBufferIndex += 7;
|
||||
this.rawBufferIndex += 8;
|
||||
++this.vertexCount;
|
||||
if(this.vertexCount % 4 == 0 && this.rawBufferIndex >= this.bufferSize - 32) {
|
||||
this.draw();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user