Compare commits
3 Commits
e66bcfa081
...
cf5ff81d18
Author | SHA1 | Date | |
---|---|---|---|
|
cf5ff81d18 | ||
|
58f318e627 | ||
|
890a2f9afd |
|
@ -23,10 +23,14 @@ in vec4 a_color;
|
|||
#ifdef CC_a_normal
|
||||
in vec4 a_normal;
|
||||
#endif
|
||||
|
||||
#ifdef CC_fog
|
||||
out vec4 v_position;
|
||||
#ifdef CC_a_texture1
|
||||
in vec2 a_texture1;
|
||||
#endif
|
||||
|
||||
#ifdef CC_TEX_GEN_STRQ
|
||||
out vec4 v_object_pos;
|
||||
#endif
|
||||
out vec4 v_position;
|
||||
#ifdef CC_a_color
|
||||
out vec4 v_color;
|
||||
#endif
|
||||
|
@ -36,11 +40,20 @@ out vec4 v_normal;
|
|||
#ifdef CC_a_texture0
|
||||
out vec2 v_texture0;
|
||||
#endif
|
||||
#ifdef CC_a_texture1
|
||||
out vec2 v_texture1;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CC_VERT
|
||||
|
||||
void main(){
|
||||
vec4 pos = matrix_m * vec4(a_position, 1.0);
|
||||
#ifdef CC_fog
|
||||
v_position = pos;
|
||||
#ifdef CC_TEX_GEN_STRQ
|
||||
v_object_pos = vec4(a_position, 1.0);
|
||||
#endif
|
||||
#ifdef CC_a_color
|
||||
v_color = a_color;
|
||||
|
@ -50,6 +63,9 @@ void main(){
|
|||
#endif
|
||||
#ifdef CC_a_texture0
|
||||
v_texture0 = a_texture0;
|
||||
#endif
|
||||
#ifdef CC_a_texture1
|
||||
v_texture1 = a_texture1;
|
||||
#endif
|
||||
gl_Position = matrix_p * pos;
|
||||
}
|
||||
|
@ -58,12 +74,10 @@ void main(){
|
|||
|
||||
#ifdef CC_FRAG
|
||||
|
||||
#ifdef CC_unit0
|
||||
uniform sampler2D tex0;
|
||||
#ifndef CC_a_texture0
|
||||
uniform sampler2D tex1;
|
||||
uniform vec2 texCoordV0;
|
||||
#endif
|
||||
#endif
|
||||
uniform vec2 texCoordV1;
|
||||
#ifdef CC_lighting
|
||||
uniform vec3 light0Pos;
|
||||
uniform vec3 light1Pos;
|
||||
|
@ -71,20 +85,35 @@ uniform vec3 normalUniform;
|
|||
#endif
|
||||
#ifdef CC_fog
|
||||
uniform vec4 fogColor;
|
||||
uniform int fogMode;
|
||||
uniform float fogStart;
|
||||
uniform float fogEnd;
|
||||
uniform float fogDensity;
|
||||
uniform float fogPremultiply;
|
||||
//X = uniform float fogMode;
|
||||
//Y = uniform float fogStart;
|
||||
//Z = uniform float fogEnd - fogStart;
|
||||
//W = uniform float fogDensity;
|
||||
uniform vec4 fogParam;
|
||||
#endif
|
||||
uniform vec4 colorUniform;
|
||||
#ifdef CC_alphatest
|
||||
uniform float alphaTestF;
|
||||
#endif
|
||||
|
||||
#ifdef CC_fog
|
||||
in vec4 v_position;
|
||||
#ifdef CC_TEX_GEN_STRQ
|
||||
//uniform int textureGenS_M;
|
||||
//uniform int textureGenT_M;
|
||||
//uniform int textureGenR_M;
|
||||
//uniform int textureGenQ_M;
|
||||
uniform ivec4 textureGen_M;
|
||||
uniform vec4 textureGenS_V;
|
||||
uniform vec4 textureGenT_V;
|
||||
uniform vec4 textureGenR_V;
|
||||
uniform vec4 textureGenQ_V;
|
||||
#endif
|
||||
#ifdef CC_patch_anisotropic
|
||||
uniform vec2 anisotropic_fix;
|
||||
#endif
|
||||
|
||||
#ifdef CC_TEX_GEN_STRQ
|
||||
in vec4 v_object_pos;
|
||||
#endif
|
||||
in vec4 v_position;
|
||||
#ifdef CC_a_color
|
||||
in vec4 v_color;
|
||||
#endif
|
||||
|
@ -94,10 +123,14 @@ in vec4 v_normal;
|
|||
#ifdef CC_a_texture0
|
||||
in vec2 v_texture0;
|
||||
#endif
|
||||
#ifdef CC_a_texture1
|
||||
in vec2 v_texture1;
|
||||
#endif
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
#define TEX_MAT3x2(mat4In) mat3x2(mat4In[0].xy,mat4In[1].xy,mat4In[3].xy)
|
||||
#define TEX_MAT4x3(mat4In) mat4x3(mat4In[0].xyw,mat4In[1].xyw,mat4In[2].xyw,mat4In[3].xyw)
|
||||
|
||||
void main(){
|
||||
#ifdef CC_a_color
|
||||
|
@ -106,12 +139,48 @@ void main(){
|
|||
vec4 color = colorUniform;
|
||||
#endif
|
||||
|
||||
#ifdef CC_TEX_GEN_STRQ
|
||||
vec4 texSrc[2];
|
||||
texSrc[0] = v_object_pos;
|
||||
texSrc[1] = v_position;
|
||||
|
||||
vec4 texPos;
|
||||
texPos.x = dot(texSrc[textureGen_M.x], textureGenS_V);
|
||||
texPos.y = dot(texSrc[textureGen_M.y], textureGenT_V);
|
||||
texPos.z = dot(texSrc[textureGen_M.z], textureGenR_V);
|
||||
texPos.w = dot(texSrc[textureGen_M.w], textureGenQ_V);
|
||||
texPos.xyz = TEX_MAT4x3(matrix_t) * texPos;
|
||||
color *= texture(tex0, texPos.xy / texPos.z).bgra;
|
||||
#ifdef CC_alphatest
|
||||
if(color.a < alphaTestF){
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
#ifdef CC_unit0
|
||||
#ifdef CC_a_texture0
|
||||
color *= texture(tex0, (TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0)).xy).rgba;
|
||||
|
||||
#ifdef CC_patch_anisotropic
|
||||
vec2 uv = TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0);
|
||||
|
||||
/* https://bugs.chromium.org/p/angleproject/issues/detail?id=4994 */
|
||||
uv = ((uv * anisotropic_fix) - fract(uv * anisotropic_fix) + 0.5) / anisotropic_fix;
|
||||
|
||||
vec4 texColor = texture(tex0, uv);
|
||||
#else
|
||||
color *= texture(tex0, (TEX_MAT3x2(matrix_t) * vec3(texCoordV0, 1.0)).xy).rgba;
|
||||
vec4 texColor = texture(tex0, TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0));
|
||||
#endif
|
||||
|
||||
#else
|
||||
vec4 texColor = texture(tex0, TEX_MAT3x2(matrix_t) * vec3(texCoordV0, 1.0));
|
||||
#endif
|
||||
|
||||
#ifdef CC_swap_rb
|
||||
color *= texColor.rgba;
|
||||
#else
|
||||
color *= texColor.bgra;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CC_alphatest
|
||||
|
@ -120,6 +189,15 @@ void main(){
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CC_unit1
|
||||
#ifdef CC_a_texture1
|
||||
color.rgb *= texture(tex1, (v_texture1 + 8.0) * 0.00390625).bgr;
|
||||
#else
|
||||
color.rgb *= texture(tex1, (texCoordV1 + 8.0) * 0.00390625).bgr;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CC_lighting
|
||||
#ifdef CC_a_normal
|
||||
vec3 normal = ((v_normal.xyz - 0.5) * 2.0);
|
||||
|
@ -133,11 +211,12 @@ void main(){
|
|||
|
||||
#ifdef CC_fog
|
||||
float dist = sqrt(dot(v_position, v_position));
|
||||
float i = (fogMode == 1) ? clamp((dist - fogStart) / (fogEnd - fogStart), 0.0, 1.0) : clamp(1.0 - exp(-(fogDensity * dist)), 0.0, 1.0);
|
||||
color.rgb = mix(color.rgb, fogColor.xyz, i * fogColor.a);
|
||||
float i = fogParam.x == 1.0 ? (dist - fogParam.y) / fogParam.z : 1.0 - exp(-fogParam.w * dist);
|
||||
color.rgb = mix(color.rgb, fogColor.xyz, clamp(i, 0.0, 1.0) * fogColor.a);
|
||||
#endif
|
||||
|
||||
fragColor = color;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
BIN
resources/sprite_sheet/clock.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
resources/sprite_sheet/compass.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
resources/sprite_sheet/fire_0.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
resources/sprite_sheet/fire_1.png
Normal file
After Width: | Height: | Size: 14 KiB |
1
resources/sprite_sheet/fire_1.txt
Normal file
|
@ -0,0 +1 @@
|
|||
8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7
|
BIN
resources/sprite_sheet/lava.png
Normal file
After Width: | Height: | Size: 11 KiB |
1
resources/sprite_sheet/lava.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0*2,1*2,2*2,3*2,4*2,5*2,6*2,7*2,8*2,9*2,10*2,11*2,12*2,13*2,14*2,15*2,16*2,17*2,18*2,19*2,18*2,17*2,16*2,15*2,14*2,13*2,12*2,11*2,10*2,9*2,8*2,7*2,6*2,5*2,4*2,3*2,2*2,1*2
|
BIN
resources/sprite_sheet/lava_flow.png
Normal file
After Width: | Height: | Size: 10 KiB |
1
resources/sprite_sheet/lava_flow.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0*3,1*3,2*3,3*3,4*3,5*3,6*3,7*3,8*3,9*3,10*3,11*3,12*3,13*3,14*3,15*3
|
BIN
resources/sprite_sheet/portal.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
resources/sprite_sheet/water.png
Normal file
After Width: | Height: | Size: 14 KiB |
1
resources/sprite_sheet/water.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0*2,1*2,2*2,3*2,4*2,5*2,6*2,7*2,8*2,9*2,10*2,11*2,12*2,13*2,14*2,15*2,16*2,17*2,18*2,19*2,20*2,21*2,22*2,23*2,24*2,25*2,26*2,27*2,28*2,29*2,30*2,31*2
|
BIN
resources/sprite_sheet/water_flow.png
Normal file
After Width: | Height: | Size: 9.9 KiB |
299
src/net/PeytonPlayz585/Client.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
|
@ -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
|
@ -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
|
@ -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
|
@ -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,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
package net.PeytonPlayz585.fileutils;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft.adapter.teavm;
|
||||
package net.PeytonPlayz585.fileutils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
@ -23,10 +23,6 @@ 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 {
|
||||
|
@ -37,13 +33,7 @@ public class IndexedDBFilesystem {
|
|||
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");
|
||||
}
|
||||
DatabaseOpen dbo = AsyncHandlers.openDB("_net_PeytonPlayz585_eaglercraft_beta_IndexedDBFilesystem_1_7_3");
|
||||
if(dbo == null) {
|
||||
err = "Unknown Error";
|
||||
return OpenState.ERROR;
|
||||
|
@ -297,9 +287,9 @@ public class IndexedDBFilesystem {
|
|||
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);
|
||||
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<EaglerAdapterImpl2.FileEntry> lst, final AsyncCallback<Integer> cb) {
|
||||
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];
|
||||
|
@ -317,10 +307,10 @@ public class IndexedDBFilesystem {
|
|||
boolean dir = isRowDirectory(c.getValue());
|
||||
if(dir) {
|
||||
if(listDirs) {
|
||||
lst.add(new EaglerAdapterImpl2.FileEntry(k, true, -1));
|
||||
lst.add(new FileEntry(k, true, -1));
|
||||
}
|
||||
}else {
|
||||
lst.add(new EaglerAdapterImpl2.FileEntry(k, false, eaglercraftEpoch + readLastModified(c.getValue())));
|
||||
lst.add(new FileEntry(k, false, eaglercraftEpoch + readLastModified(c.getValue())));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +1,26 @@
|
|||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.PeytonPlayz585.glemu.vector.*;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL11.EaglerAdapterImpl2.ProgramGL;
|
||||
import org.lwjgl.opengl.GL11.EaglerAdapterImpl2.ShaderGL;
|
||||
import org.lwjgl.opengl.GL11.EaglerAdapterImpl2.UniformGL;
|
||||
import org.lwjgl.util.vector.Vector2f;
|
||||
import org.lwjgl.util.vector.Vector4f;
|
||||
|
||||
public class FixedFunctionShader {
|
||||
|
||||
private static final FixedFunctionShader[] instances = new FixedFunctionShader[128];
|
||||
private static final FixedFunctionShader[] instances = new FixedFunctionShader[4096]; //lol
|
||||
private static final List<FixedFunctionShader> instanceList = new ArrayList();
|
||||
|
||||
public static void refreshCoreGL() {
|
||||
for (int i = 0; i < instances.length; ++i) {
|
||||
if (instances[i] != null) {
|
||||
for(int i = 0; i < instances.length; ++i) {
|
||||
if(instances[i] != null) {
|
||||
_wglDeleteProgram(instances[i].globject);
|
||||
instances[i] = null;
|
||||
}
|
||||
|
@ -26,43 +32,69 @@ public class FixedFunctionShader {
|
|||
public static final int COLOR = 1;
|
||||
public static final int NORMAL = 2;
|
||||
public static final int TEXTURE0 = 4;
|
||||
public static final int LIGHTING = 8;
|
||||
public static final int FOG = 16;
|
||||
public static final int ALPHATEST = 32;
|
||||
public static final int UNIT0 = 64;
|
||||
public static final int TEXTURE1 = 8;
|
||||
public static final int TEXGEN = 16;
|
||||
public static final int LIGHTING = 32;
|
||||
public static final int FOG = 64;
|
||||
public static final int ALPHATEST = 128;
|
||||
public static final int UNIT0 = 256;
|
||||
public static final int UNIT1 = 512;
|
||||
public static final int FIX_ANISOTROPIC = 1024;
|
||||
public static final int SWAP_RB = 2048;
|
||||
|
||||
public static FixedFunctionShader instance(int i) {
|
||||
FixedFunctionShader s = instances[i];
|
||||
if (s == null) {
|
||||
if(s == null) {
|
||||
boolean CC_a_color = false;
|
||||
boolean CC_a_normal = false;
|
||||
boolean CC_a_texture0 = false;
|
||||
boolean CC_a_texture1 = false;
|
||||
boolean CC_TEX_GEN_STRQ = false;
|
||||
boolean CC_lighting = false;
|
||||
boolean CC_fog = false;
|
||||
boolean CC_alphatest = false;
|
||||
boolean CC_unit0 = false;
|
||||
if ((i & COLOR) == COLOR) {
|
||||
boolean CC_unit1 = false;
|
||||
boolean CC_anisotropic = false;
|
||||
boolean CC_swap_rb = false;
|
||||
if((i & COLOR) == COLOR) {
|
||||
CC_a_color = true;
|
||||
}
|
||||
if ((i & NORMAL) == NORMAL) {
|
||||
if((i & NORMAL) == NORMAL) {
|
||||
CC_a_normal = true;
|
||||
}
|
||||
if ((i & TEXTURE0) == TEXTURE0) {
|
||||
if((i & TEXTURE0) == TEXTURE0) {
|
||||
CC_a_texture0 = true;
|
||||
}
|
||||
if ((i & LIGHTING) == LIGHTING) {
|
||||
if((i & TEXTURE1) == TEXTURE1) {
|
||||
CC_a_texture1 = true;
|
||||
}
|
||||
if((i & TEXGEN) == TEXGEN) {
|
||||
CC_TEX_GEN_STRQ = true;
|
||||
}
|
||||
if((i & LIGHTING) == LIGHTING) {
|
||||
CC_lighting = true;
|
||||
}
|
||||
if ((i & FOG) == FOG) {
|
||||
if((i & FOG) == FOG) {
|
||||
CC_fog = true;
|
||||
}
|
||||
if ((i & ALPHATEST) == ALPHATEST) {
|
||||
if((i & ALPHATEST) == ALPHATEST) {
|
||||
CC_alphatest = true;
|
||||
}
|
||||
if ((i & UNIT0) == UNIT0) {
|
||||
if((i & UNIT0) == UNIT0) {
|
||||
CC_unit0 = true;
|
||||
}
|
||||
s = new FixedFunctionShader(i, CC_a_color, CC_a_normal, CC_a_texture0, CC_lighting, CC_fog, CC_alphatest, CC_unit0);
|
||||
if((i & UNIT1) == UNIT1) {
|
||||
CC_unit1 = true;
|
||||
}
|
||||
if((i & FIX_ANISOTROPIC) == FIX_ANISOTROPIC) {
|
||||
CC_anisotropic = true;
|
||||
}
|
||||
if((i & SWAP_RB) == SWAP_RB) {
|
||||
CC_swap_rb = true;
|
||||
}
|
||||
s = new FixedFunctionShader(i, CC_a_color, CC_a_normal, CC_a_texture0, CC_a_texture1, CC_TEX_GEN_STRQ, CC_lighting,
|
||||
CC_fog, CC_alphatest, CC_unit0, CC_unit1, CC_anisotropic, CC_swap_rb);
|
||||
instances[i] = s;
|
||||
instanceList.add(s);
|
||||
}
|
||||
|
@ -74,10 +106,15 @@ public class FixedFunctionShader {
|
|||
private final boolean enable_color;
|
||||
private final boolean enable_normal;
|
||||
private final boolean enable_texture0;
|
||||
private final boolean enable_texture1;
|
||||
private final boolean enable_TEX_GEN_STRQ;
|
||||
private final boolean enable_lighting;
|
||||
private final boolean enable_fog;
|
||||
private final boolean enable_alphatest;
|
||||
private final boolean enable_unit0;
|
||||
private final boolean enable_unit1;
|
||||
private final boolean enable_anisotropic_fix;
|
||||
private final boolean enable_swap_rb;
|
||||
private final ProgramGL globject;
|
||||
|
||||
private UniformGL u_matrix_m = null;
|
||||
|
@ -85,78 +122,96 @@ public class FixedFunctionShader {
|
|||
private UniformGL u_matrix_t = null;
|
||||
|
||||
private UniformGL u_fogColor = null;
|
||||
private UniformGL u_fogMode = null;
|
||||
private UniformGL u_fogStart = null;
|
||||
private UniformGL u_fogEnd = null;
|
||||
private UniformGL u_fogDensity = null;
|
||||
private UniformGL u_fogPremultiply = null;
|
||||
//private UniformGL u_fogMode = null;
|
||||
//private UniformGL u_fogStart = null;
|
||||
//private UniformGL u_fogEnd = null;
|
||||
//private UniformGL u_fogDensity = null;
|
||||
private UniformGL u_fogParam = null;
|
||||
|
||||
private UniformGL u_colorUniform = null;
|
||||
private UniformGL u_normalUniform = null;
|
||||
|
||||
private UniformGL u_alphaTestF = null;
|
||||
|
||||
//private UniformGL u_textureGenS_M = null;
|
||||
//private UniformGL u_textureGenT_M = null;
|
||||
//private UniformGL u_textureGenR_M = null;
|
||||
//private UniformGL u_textureGenQ_M = null;
|
||||
private UniformGL u_textureGen_M = null;
|
||||
private UniformGL u_textureGenS_V = null;
|
||||
private UniformGL u_textureGenT_V = null;
|
||||
private UniformGL u_textureGenR_V = null;
|
||||
private UniformGL u_textureGenQ_V = null;
|
||||
|
||||
private UniformGL u_texCoordV0 = null;
|
||||
private UniformGL u_texCoordV1 = null;
|
||||
|
||||
private UniformGL u_light0Pos = null;
|
||||
private UniformGL u_light1Pos = null;
|
||||
//private UniformGL u_invertNormals = null;
|
||||
|
||||
private UniformGL u_anisotropic_fix = null;
|
||||
|
||||
private final int a_position;
|
||||
private final int a_texture0;
|
||||
private final int a_color;
|
||||
private final int a_normal;
|
||||
private final int a_texture1;
|
||||
|
||||
private final int attributeIndexesToEnable;
|
||||
|
||||
public final StreamBuffer streamBuffer;
|
||||
public boolean bufferIsInitialized = false;
|
||||
|
||||
private FixedFunctionShader(int j, boolean CC_a_color, boolean CC_a_normal, boolean CC_a_texture0,
|
||||
boolean CC_lighting, boolean CC_fog, boolean CC_alphatest, boolean CC_unit0) {
|
||||
private FixedFunctionShader(int j, boolean CC_a_color, boolean CC_a_normal, boolean CC_a_texture0, boolean CC_a_texture1, boolean CC_TEX_GEN_STRQ, boolean CC_lighting,
|
||||
boolean CC_fog, boolean CC_alphatest, boolean CC_unit0, boolean CC_unit1, boolean CC_anisotropic_fix, boolean CC_swap_rb) {
|
||||
enable_color = CC_a_color;
|
||||
enable_normal = CC_a_normal;
|
||||
enable_texture0 = CC_a_texture0;
|
||||
enable_texture1 = CC_a_texture1;
|
||||
enable_TEX_GEN_STRQ = CC_TEX_GEN_STRQ;
|
||||
enable_lighting = CC_lighting;
|
||||
enable_fog = CC_fog;
|
||||
enable_alphatest = CC_alphatest;
|
||||
enable_unit0 = CC_unit0;
|
||||
enable_unit1 = CC_unit1;
|
||||
enable_anisotropic_fix = CC_anisotropic_fix;
|
||||
enable_swap_rb = CC_swap_rb;
|
||||
|
||||
if (shaderSource == null) {
|
||||
if(shaderSource == null) {
|
||||
shaderSource = fileContents("/glsl/core.glsl");
|
||||
}
|
||||
|
||||
String source = "";
|
||||
if (enable_color)
|
||||
source += "\n#define CC_a_color\n";
|
||||
if (enable_normal)
|
||||
source += "#define CC_a_normal\n";
|
||||
if (enable_texture0)
|
||||
source += "#define CC_a_texture0\n";
|
||||
if (enable_lighting)
|
||||
source += "#define CC_lighting\n";
|
||||
if (enable_fog)
|
||||
source += "#define CC_fog\n";
|
||||
if (enable_alphatest)
|
||||
source += "#define CC_alphatest\n";
|
||||
if (enable_unit0)
|
||||
source += "#define CC_unit0\n";
|
||||
if(enable_color) source += "\n#define CC_a_color\n";
|
||||
if(enable_normal) source += "#define CC_a_normal\n";
|
||||
if(enable_texture0) source += "#define CC_a_texture0\n";
|
||||
if(enable_texture1) source += "#define CC_a_texture1\n";
|
||||
if(enable_TEX_GEN_STRQ) source += "#define CC_TEX_GEN_STRQ\n";
|
||||
if(enable_lighting) source += "#define CC_lighting\n";
|
||||
if(enable_fog) source += "#define CC_fog\n";
|
||||
if(enable_alphatest) source += "#define CC_alphatest\n";
|
||||
if(enable_unit0) source += "#define CC_unit0\n";
|
||||
if(enable_unit1) source += "#define CC_unit1\n";
|
||||
if(enable_anisotropic_fix) source += "#define CC_patch_anisotropic\n";
|
||||
if(enable_swap_rb) source += "#define CC_swap_rb\n";
|
||||
source += shaderSource;
|
||||
|
||||
ShaderGL v = _wglCreateShader(_wGL_VERTEX_SHADER);
|
||||
_wglShaderSource(v, _wgetShaderHeader() + "\n#define CC_VERT\n" + source);
|
||||
_wglShaderSource(v, _wgetShaderHeader()+"\n#define CC_VERT\n"+source);
|
||||
_wglCompileShader(v);
|
||||
|
||||
if (!_wglGetShaderCompiled(v)) {
|
||||
System.err.println(("\n\n" + _wglGetShaderInfoLog(v)).replace("\n", "\n[/glsl/core.glsl][CC_VERT] "));
|
||||
if(!_wglGetShaderCompiled(v)) {
|
||||
System.err.println(("\n\n"+_wglGetShaderInfoLog(v)).replace("\n", "\n[/glsl/core.glsl][CC_VERT] "));
|
||||
throw new RuntimeException("broken shader file");
|
||||
}
|
||||
|
||||
ShaderGL f = _wglCreateShader(_wGL_FRAGMENT_SHADER);
|
||||
_wglShaderSource(f, _wgetShaderHeader() + "\n#define CC_FRAG\n" + source);
|
||||
_wglShaderSource(f, _wgetShaderHeader()+"\n#define CC_FRAG\n"+source);
|
||||
_wglCompileShader(f);
|
||||
|
||||
if (!_wglGetShaderCompiled(f)) {
|
||||
System.err.println(("\n\n" + _wglGetShaderInfoLog(f)).replace("\n", "\n[/glsl/core.glsl][CC_FRAG] "));
|
||||
if(!_wglGetShaderCompiled(f)) {
|
||||
System.err.println(("\n\n"+_wglGetShaderInfoLog(f)).replace("\n", "\n[/glsl/core.glsl][CC_FRAG] "));
|
||||
throw new RuntimeException("broken shader file");
|
||||
}
|
||||
|
||||
|
@ -168,24 +223,30 @@ public class FixedFunctionShader {
|
|||
a_position = i++;
|
||||
_wglBindAttributeLocation(globject, a_position, "a_position");
|
||||
|
||||
if (enable_texture0) {
|
||||
if(enable_texture0) {
|
||||
a_texture0 = i++;
|
||||
_wglBindAttributeLocation(globject, a_texture0, "a_texture0");
|
||||
} else {
|
||||
}else {
|
||||
a_texture0 = -1;
|
||||
}
|
||||
if (enable_color) {
|
||||
if(enable_color) {
|
||||
a_color = i++;
|
||||
_wglBindAttributeLocation(globject, a_color, "a_color");
|
||||
} else {
|
||||
}else {
|
||||
a_color = -1;
|
||||
}
|
||||
if (enable_normal) {
|
||||
if(enable_normal) {
|
||||
a_normal = i++;
|
||||
_wglBindAttributeLocation(globject, a_normal, "a_normal");
|
||||
} else {
|
||||
}else {
|
||||
a_normal = -1;
|
||||
}
|
||||
if(enable_texture1) {
|
||||
a_texture1 = i++;
|
||||
_wglBindAttributeLocation(globject, a_texture1, "a_texture1");
|
||||
}else {
|
||||
a_texture1 = -1;
|
||||
}
|
||||
|
||||
attributeIndexesToEnable = i;
|
||||
|
||||
|
@ -196,8 +257,8 @@ public class FixedFunctionShader {
|
|||
_wglDeleteShader(v);
|
||||
_wglDeleteShader(f);
|
||||
|
||||
if (!_wglGetProgramLinked(globject)) {
|
||||
System.err.println(("\n\n" + _wglGetProgramInfoLog(globject)).replace("\n", "\n[LINKER] "));
|
||||
if(!_wglGetProgramLinked(globject)) {
|
||||
System.err.println(("\n\n"+_wglGetProgramInfoLog(globject)).replace("\n", "\n[LINKER] "));
|
||||
throw new RuntimeException("broken shader file");
|
||||
}
|
||||
|
||||
|
@ -209,27 +270,48 @@ public class FixedFunctionShader {
|
|||
|
||||
u_colorUniform = _wglGetUniformLocation(globject, "colorUniform");
|
||||
|
||||
if (enable_lighting) {
|
||||
if(enable_lighting) {
|
||||
u_normalUniform = _wglGetUniformLocation(globject, "normalUniform");
|
||||
//u_invertNormals = _wglGetUniformLocation(globject, "invertNormals");
|
||||
u_light0Pos = _wglGetUniformLocation(globject, "light0Pos");
|
||||
u_light1Pos = _wglGetUniformLocation(globject, "light1Pos");
|
||||
}
|
||||
|
||||
if (enable_fog) {
|
||||
if(enable_fog) {
|
||||
u_fogColor = _wglGetUniformLocation(globject, "fogColor");
|
||||
u_fogMode = _wglGetUniformLocation(globject, "fogMode");
|
||||
u_fogStart = _wglGetUniformLocation(globject, "fogStart");
|
||||
u_fogEnd = _wglGetUniformLocation(globject, "fogEnd");
|
||||
u_fogDensity = _wglGetUniformLocation(globject, "fogDensity");
|
||||
u_fogPremultiply = _wglGetUniformLocation(globject, "fogPremultiply");
|
||||
//u_fogMode = _wglGetUniformLocation(globject, "fogMode");
|
||||
//u_fogStart = _wglGetUniformLocation(globject, "fogStart");
|
||||
//u_fogEnd = _wglGetUniformLocation(globject, "fogEnd");
|
||||
//u_fogDensity = _wglGetUniformLocation(globject, "fogDensity");
|
||||
u_fogParam = _wglGetUniformLocation(globject, "fogParam");
|
||||
}
|
||||
|
||||
if (enable_alphatest) {
|
||||
if(enable_alphatest) {
|
||||
u_alphaTestF = _wglGetUniformLocation(globject, "alphaTestF");
|
||||
}
|
||||
|
||||
if(enable_TEX_GEN_STRQ) {
|
||||
//u_textureGenS_M = _wglGetUniformLocation(globject, "textureGenS_M");
|
||||
//u_textureGenT_M = _wglGetUniformLocation(globject, "textureGenT_M");
|
||||
//u_textureGenR_M = _wglGetUniformLocation(globject, "textureGenR_M");
|
||||
//u_textureGenQ_M = _wglGetUniformLocation(globject, "textureGenQ_M");
|
||||
u_textureGen_M = _wglGetUniformLocation(globject, "textureGen_M");
|
||||
u_textureGenS_V = _wglGetUniformLocation(globject, "textureGenS_V");
|
||||
u_textureGenT_V = _wglGetUniformLocation(globject, "textureGenT_V");
|
||||
u_textureGenR_V = _wglGetUniformLocation(globject, "textureGenR_V");
|
||||
u_textureGenQ_V = _wglGetUniformLocation(globject, "textureGenQ_V");
|
||||
}
|
||||
|
||||
if(enable_anisotropic_fix) {
|
||||
u_anisotropic_fix = _wglGetUniformLocation(globject, "anisotropic_fix");
|
||||
_wglUniform2f(u_anisotropic_fix, 1024.0f * 63.0f / 64.0f, 1024.0f * 63.0f / 64.0f);
|
||||
}
|
||||
|
||||
_wglUniform1i(_wglGetUniformLocation(globject, "tex0"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(globject, "tex1"), 1);
|
||||
|
||||
u_texCoordV0 = _wglGetUniformLocation(globject, "texCoordV0");
|
||||
u_texCoordV1 = _wglGetUniformLocation(globject, "texCoordV1");
|
||||
|
||||
streamBuffer = new StreamBuffer(0x8000, 3, 8, (vertexArray, vertexBuffer) -> {
|
||||
_wglBindVertexArray0(vertexArray);
|
||||
|
@ -241,18 +323,22 @@ public class FixedFunctionShader {
|
|||
|
||||
public void setupArrayForProgram() {
|
||||
_wglEnableVertexAttribArray(a_position);
|
||||
_wglVertexAttribPointer(a_position, 3, _wGL_FLOAT, false, 28, 0);
|
||||
if (enable_texture0) {
|
||||
_wglVertexAttribPointer(a_position, 3, _wGL_FLOAT, false, 32, 0);
|
||||
if(enable_texture0) {
|
||||
_wglEnableVertexAttribArray(a_texture0);
|
||||
_wglVertexAttribPointer(a_texture0, 2, _wGL_FLOAT, false, 28, 12);
|
||||
_wglVertexAttribPointer(a_texture0, 2, _wGL_FLOAT, false, 32, 12);
|
||||
}
|
||||
if (enable_color) {
|
||||
if(enable_color) {
|
||||
_wglEnableVertexAttribArray(a_color);
|
||||
_wglVertexAttribPointer(a_color, 4, _wGL_UNSIGNED_BYTE, true, 28, 20);
|
||||
_wglVertexAttribPointer(a_color, 4, _wGL_UNSIGNED_BYTE, true, 32, 20);
|
||||
}
|
||||
if (enable_normal) {
|
||||
if(enable_normal) {
|
||||
_wglEnableVertexAttribArray(a_normal);
|
||||
_wglVertexAttribPointer(a_normal, 4, _wGL_UNSIGNED_BYTE, true, 28, 24);
|
||||
_wglVertexAttribPointer(a_normal, 4, _wGL_UNSIGNED_BYTE, true, 32, 24);
|
||||
}
|
||||
if(enable_texture1) {
|
||||
_wglEnableVertexAttribArray(a_texture1);
|
||||
_wglVertexAttribPointer(a_texture1, 2, _wGL_SHORT, false, 32, 28);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,137 +357,281 @@ public class FixedFunctionShader {
|
|||
}
|
||||
}
|
||||
|
||||
private float[] modelBuffer = new float[16];
|
||||
private float[] projectionBuffer = new float[16];
|
||||
private float[] textureBuffer = new float[16];
|
||||
private float[] matBuffer = new float[16];
|
||||
|
||||
private Matrix4f modelMatrix = (Matrix4f) new Matrix4f().setZero();
|
||||
private Matrix4f projectionMatrix = (Matrix4f) new Matrix4f().setZero();
|
||||
private Matrix4f textureMatrix = (Matrix4f) new Matrix4f().setZero();
|
||||
private Vector4f light0Pos = new Vector4f();
|
||||
private Vector4f light1Pos = new Vector4f();
|
||||
|
||||
public void setModelMatrix(Matrix4f mat) {
|
||||
if (!mat.equals(modelMatrix)) {
|
||||
modelMatrix.load(mat).store(modelBuffer);
|
||||
_wglUniformMat4fv(u_matrix_m, modelBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void setProjectionMatrix(Matrix4f mat) {
|
||||
if (!mat.equals(projectionMatrix)) {
|
||||
projectionMatrix.load(mat).store(projectionBuffer);
|
||||
_wglUniformMat4fv(u_matrix_p, projectionBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextureMatrix(Matrix4f mat) {
|
||||
if (!mat.equals(textureMatrix)) {
|
||||
textureMatrix.load(mat).store(textureBuffer);
|
||||
_wglUniformMat4fv(u_matrix_t, textureBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLightPositions(Vector4f pos0, Vector4f pos1) {
|
||||
if (!pos0.equals(light0Pos) || !pos1.equals(light1Pos)) {
|
||||
light0Pos.set(pos0);
|
||||
light1Pos.set(pos1);
|
||||
_wglUniform3f(u_light0Pos, light0Pos.x, light0Pos.y, light0Pos.z);
|
||||
_wglUniform3f(u_light1Pos, light1Pos.x, light1Pos.y, light1Pos.z);
|
||||
}
|
||||
}
|
||||
private Vector2f anisotropicFix = new Vector2f(0.0f, 0.0f);
|
||||
|
||||
private int fogMode = 0;
|
||||
|
||||
public void setFogMode(int mode) {
|
||||
if (fogMode != mode) {
|
||||
fogMode = mode;
|
||||
_wglUniform1i(u_fogMode, mode % 2);
|
||||
_wglUniform1f(u_fogPremultiply, mode / 2);
|
||||
}
|
||||
}
|
||||
|
||||
private float fogColorR = 0.0f;
|
||||
private float fogColorG = 0.0f;
|
||||
private float fogColorB = 0.0f;
|
||||
private float fogColorA = 0.0f;
|
||||
|
||||
public void setFogColor(float r, float g, float b, float a) {
|
||||
if (fogColorR != r || fogColorG != g || fogColorB != b || fogColorA != a) {
|
||||
fogColorR = r;
|
||||
fogColorG = g;
|
||||
fogColorB = b;
|
||||
fogColorA = a;
|
||||
_wglUniform4f(u_fogColor, fogColorR, fogColorG, fogColorB, fogColorA);
|
||||
}
|
||||
}
|
||||
|
||||
private float fogStart = 0.0f;
|
||||
private float fogEnd = 0.0f;
|
||||
|
||||
public void setFogStartEnd(float s, float e) {
|
||||
if (fogStart != s || fogEnd != e) {
|
||||
fogStart = s;
|
||||
fogEnd = e;
|
||||
_wglUniform1f(u_fogStart, fogStart);
|
||||
_wglUniform1f(u_fogEnd, fogEnd);
|
||||
}
|
||||
}
|
||||
|
||||
private float fogDensity = 0.0f;
|
||||
|
||||
public void setFogDensity(float d) {
|
||||
if (fogDensity != d) {
|
||||
fogDensity = d;
|
||||
_wglUniform1f(u_fogDensity, fogDensity);
|
||||
}
|
||||
}
|
||||
|
||||
private float alphaTestValue = 0.0f;
|
||||
|
||||
public void setAlphaTest(float limit) {
|
||||
if (alphaTestValue != limit) {
|
||||
alphaTestValue = limit;
|
||||
_wglUniform1f(u_alphaTestF, alphaTestValue);
|
||||
}
|
||||
}
|
||||
|
||||
private float tex0x = 0.0f;
|
||||
private float tex0y = 0.0f;
|
||||
|
||||
public void setTex0Coords(float x, float y) {
|
||||
if (tex0x != x || tex0y != y) {
|
||||
tex0x = x;
|
||||
tex0y = y;
|
||||
_wglUniform2f(u_texCoordV0, tex0x, tex0y);
|
||||
}
|
||||
}
|
||||
private float tex1x = 0.0f;
|
||||
private float tex1y = 0.0f;
|
||||
|
||||
private float colorUniformR = 0.0f;
|
||||
private float colorUniformG = 0.0f;
|
||||
private float colorUniformB = 0.0f;
|
||||
private float colorUniformA = 0.0f;
|
||||
|
||||
public void setColor(float r, float g, float b, float a) {
|
||||
if (colorUniformR != r || colorUniformG != g || colorUniformB != b || colorUniformA != a) {
|
||||
colorUniformR = r;
|
||||
colorUniformG = g;
|
||||
colorUniformB = b;
|
||||
colorUniformA = a;
|
||||
_wglUniform4f(u_colorUniform, colorUniformR, colorUniformG, colorUniformB, colorUniformA);
|
||||
}
|
||||
}
|
||||
|
||||
private float normalUniformX = 0.0f;
|
||||
private float normalUniformY = 0.0f;
|
||||
private float normalUniformZ = 0.0f;
|
||||
|
||||
public void setNormal(float x, float y, float z) {
|
||||
if (normalUniformX != x || normalUniformY != y || normalUniformZ != z) {
|
||||
private int anisotropicFixSerial = -1;
|
||||
private int colorSerial = -1;
|
||||
private int normalSerial = -1;
|
||||
private int tex0Serial = -1;
|
||||
private int tex1Serial = -1;
|
||||
private int texPlaneSerial = -1;
|
||||
private int texSSerial = -1;
|
||||
private int texTSerial = -1;
|
||||
private int texRSerial = -1;
|
||||
private int texQSerial = -1;
|
||||
private int fogColorSerial = -1;
|
||||
private int fogCfgSerial = -1;
|
||||
private int matModelSerialCounter = -1;
|
||||
private int matProjSerialCounter = -1;
|
||||
private int matTexSerialCounter = -1;
|
||||
private int lightPos0Serial = -1;
|
||||
private int lightPos1Serial = -1;
|
||||
|
||||
private int texS_plane = -1;
|
||||
private float texS_X = -999.0f;
|
||||
private float texS_Y = -999.0f;
|
||||
private float texS_Z = -999.0f;
|
||||
private float texS_W = -999.0f;
|
||||
|
||||
private int texT_plane = -1;
|
||||
private float texT_X = -999.0f;
|
||||
private float texT_Y = -999.0f;
|
||||
private float texT_Z = -999.0f;
|
||||
private float texT_W = -999.0f;
|
||||
|
||||
private int texR_plane = -1;
|
||||
private float texR_X = -999.0f;
|
||||
private float texR_Y = -999.0f;
|
||||
private float texR_Z = -999.0f;
|
||||
private float texR_W = -999.0f;
|
||||
|
||||
private int texQ_plane = -1;
|
||||
private float texQ_X = -999.0f;
|
||||
private float texQ_Y = -999.0f;
|
||||
private float texQ_Z = -999.0f;
|
||||
private float texQ_W = -999.0f;
|
||||
|
||||
public void update() {
|
||||
if(anisotropicFixSerial != GL11.anisotropicFixSerial) {
|
||||
float x = GL11.anisotropicFixX;
|
||||
float y = GL11.anisotropicFixY;
|
||||
anisotropicFixSerial = GL11.anisotropicFixSerial;
|
||||
if(anisotropicFix.x != x || anisotropicFix.y != y) {
|
||||
anisotropicFix.x = x;
|
||||
anisotropicFix.y = y;
|
||||
_wglUniform2f(u_anisotropic_fix, x, y);
|
||||
}
|
||||
}
|
||||
if(colorSerial != GL11.colorSerial) {
|
||||
float r = GL11.colorR;
|
||||
float g = GL11.colorG;
|
||||
float b = GL11.colorB;
|
||||
float a = GL11.colorA;
|
||||
colorSerial = GL11.colorSerial;
|
||||
if(colorUniformR != r || colorUniformG != g || colorUniformB != b || colorUniformA != a) {
|
||||
colorUniformR = r;
|
||||
colorUniformG = g;
|
||||
colorUniformB = b;
|
||||
colorUniformA = a;
|
||||
_wglUniform4f(u_colorUniform, r, g, b, a);
|
||||
}
|
||||
}
|
||||
if(normalSerial != GL11.normalSerial) {
|
||||
float x = GL11.normalX;
|
||||
float y = GL11.normalY;
|
||||
float z = GL11.normalZ;
|
||||
normalSerial = GL11.normalSerial;
|
||||
if(normalUniformX != x || normalUniformY != y || normalUniformZ != z) {
|
||||
normalUniformX = x;
|
||||
normalUniformY = y;
|
||||
normalUniformZ = z;
|
||||
_wglUniform3f(u_normalUniform, normalUniformX, normalUniformY, normalUniformZ);
|
||||
_wglUniform3f(u_normalUniform, x, y, z);
|
||||
}
|
||||
}
|
||||
if(tex0Serial != GL11.tex0Serial) {
|
||||
float x = GL11.tex0X;
|
||||
float y = GL11.tex0Y;
|
||||
tex0Serial = GL11.tex0Serial;
|
||||
if(tex0x != x || tex0y != y) {
|
||||
tex0x = x;
|
||||
tex0y = y;
|
||||
_wglUniform2f(u_texCoordV0, x, y);
|
||||
}
|
||||
}
|
||||
if(tex1Serial != GL11.tex1Serial) {
|
||||
float x = GL11.tex1X;
|
||||
float y = GL11.tex1Y;
|
||||
tex1Serial = GL11.tex1Serial;
|
||||
if(tex1x != x || tex1y != y) {
|
||||
tex1x = x;
|
||||
tex1y = y;
|
||||
_wglUniform2f(u_texCoordV1, x, y);
|
||||
}
|
||||
}
|
||||
if(texPlaneSerial != GL11.texPlaneSerial) {
|
||||
int s = GL11.texS_plane;
|
||||
int t = GL11.texT_plane;
|
||||
int r = GL11.texR_plane;
|
||||
int q = GL11.texQ_plane;
|
||||
texPlaneSerial = GL11.texPlaneSerial;
|
||||
if(texS_plane != s || texT_plane != t || texR_plane != r || texQ_plane != q) {
|
||||
texS_plane = s;
|
||||
texT_plane = t;
|
||||
texR_plane = r;
|
||||
texQ_plane = q;
|
||||
_wglUniform4i(u_textureGen_M, s, t, r, q);
|
||||
}
|
||||
}
|
||||
if(texSSerial != GL11.texSSerial) {
|
||||
float x = GL11.texS_X;
|
||||
float y = GL11.texS_Y;
|
||||
float z = GL11.texS_Z;
|
||||
float w = GL11.texS_W;
|
||||
texSSerial = GL11.texSSerial;
|
||||
if(texS_X != x || texS_Y != y || texS_Z != z || texS_W != w) {
|
||||
texS_X = x;
|
||||
texS_Y = y;
|
||||
texS_Z = z;
|
||||
texS_W = w;
|
||||
_wglUniform4f(u_textureGenS_V, x, y, z, w);
|
||||
}
|
||||
}
|
||||
if(texTSerial != GL11.texTSerial) {
|
||||
float x = GL11.texT_X;
|
||||
float y = GL11.texT_Y;
|
||||
float z = GL11.texT_Z;
|
||||
float w = GL11.texT_W;
|
||||
texTSerial = GL11.texTSerial;
|
||||
if(texT_X != x || texT_Y != y || texT_Z != z || texT_W != w) {
|
||||
texT_X = x;
|
||||
texT_Y = y;
|
||||
texT_Z = z;
|
||||
texT_W = w;
|
||||
_wglUniform4f(u_textureGenT_V, x, y, z, w);
|
||||
}
|
||||
}
|
||||
if(texRSerial != GL11.texRSerial) {
|
||||
float x = GL11.texR_X;
|
||||
float y = GL11.texR_Y;
|
||||
float z = GL11.texR_Z;
|
||||
float w = GL11.texR_W;
|
||||
texRSerial = GL11.texRSerial;
|
||||
if(texR_X != x || texR_Y != y || texR_Z != z || texR_W != w) {
|
||||
texR_X = x;
|
||||
texR_Y = y;
|
||||
texR_Z = z;
|
||||
texR_W = w;
|
||||
_wglUniform4f(u_textureGenR_V, x, y, z, w);
|
||||
}
|
||||
}
|
||||
if(texQSerial != GL11.texQSerial) {
|
||||
float x = GL11.texQ_X;
|
||||
float y = GL11.texQ_Y;
|
||||
float z = GL11.texQ_Z;
|
||||
float w = GL11.texQ_W;
|
||||
texQSerial = GL11.texQSerial;
|
||||
if(texQ_X != x || texQ_Y != y || texQ_Z != z || texQ_W != w) {
|
||||
texQ_X = x;
|
||||
texQ_Y = y;
|
||||
texQ_Z = z;
|
||||
texQ_W = w;
|
||||
_wglUniform4f(u_textureGenQ_V, x, y, z, w);
|
||||
}
|
||||
}
|
||||
if(fogColorSerial != GL11.fogColorSerial) {
|
||||
float r = GL11.fogColorR;
|
||||
float g = GL11.fogColorG;
|
||||
float b = GL11.fogColorB;
|
||||
float a = GL11.fogColorA;
|
||||
fogColorSerial = GL11.fogColorSerial;
|
||||
if(fogColorR != r || fogColorG != g || fogColorB != b || fogColorA != a) {
|
||||
fogColorR = r;
|
||||
fogColorG = g;
|
||||
fogColorB = b;
|
||||
fogColorA = a;
|
||||
_wglUniform4f(u_fogColor, r, g, b, a);
|
||||
}
|
||||
}
|
||||
if(fogCfgSerial != GL11.fogCfgSerial) {
|
||||
int fogModex = GL11.fogMode;
|
||||
float fogStarty = GL11.fogStart;
|
||||
float fogEndz = GL11.fogEnd - fogStarty;
|
||||
float fogDensityw = GL11.fogDensity;
|
||||
fogCfgSerial = GL11.fogCfgSerial;
|
||||
if(fogMode != fogModex || fogStart != fogStarty ||
|
||||
fogEnd != fogEndz || fogDensity != fogDensityw) {
|
||||
fogMode = fogModex;
|
||||
fogStart = fogStarty;
|
||||
fogEnd = fogEndz;
|
||||
fogDensity = fogDensityw;
|
||||
_wglUniform4f(u_fogParam, fogModex, fogStarty, fogEndz, fogDensityw);
|
||||
}
|
||||
}
|
||||
float limit = GL11.alphaThresh;
|
||||
if(alphaTestValue != limit) {
|
||||
alphaTestValue = limit;
|
||||
_wglUniform1f(u_alphaTestF, limit);
|
||||
}
|
||||
float[] matCopyBuffer = matBuffer;
|
||||
int i = GL11.matModelPointer;
|
||||
int j = GL11.matModelVSerial[i];
|
||||
if(matModelSerialCounter != j) {
|
||||
matModelSerialCounter = j;
|
||||
GL11.matModelV[i].store(matCopyBuffer);
|
||||
_wglUniformMat4fv(u_matrix_m, matCopyBuffer);
|
||||
}
|
||||
i = GL11.matProjPointer;
|
||||
j = GL11.matProjVSerial[i];
|
||||
if(matProjSerialCounter != j) {
|
||||
matProjSerialCounter = j;
|
||||
GL11.matProjV[i].store(matCopyBuffer);
|
||||
_wglUniformMat4fv(u_matrix_p, matCopyBuffer);
|
||||
}
|
||||
i = GL11.matTexPointer;
|
||||
j = GL11.matTexVSerial[i];
|
||||
if(matTexSerialCounter != j) {
|
||||
matTexSerialCounter = j;
|
||||
GL11.matTexV[i].store(matCopyBuffer);
|
||||
_wglUniformMat4fv(u_matrix_t, matCopyBuffer);
|
||||
}
|
||||
if(lightPos0Serial != GL11.lightPos0Serial) {
|
||||
lightPos0Serial = GL11.lightPos0Serial;
|
||||
Vector4f pos = GL11.lightPos0vec;
|
||||
if(!pos.equals(light0Pos)) {
|
||||
light0Pos.set(pos);
|
||||
_wglUniform3f(u_light0Pos, pos.x, pos.y, pos.z);
|
||||
}
|
||||
}
|
||||
if(lightPos1Serial != GL11.lightPos1Serial) {
|
||||
lightPos1Serial = GL11.lightPos1Serial;
|
||||
Vector4f pos = GL11.lightPos1vec;
|
||||
if(!pos.equals(light1Pos)) {
|
||||
light1Pos.set(pos);
|
||||
_wglUniform3f(u_light1Pos, pos.x, pos.y, pos.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2002 JSON.org
|
|
@ -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) {
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2002 JSON.org
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2018 JSON.org
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2018 JSON.org
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
/*
|
||||
Copyright (c) 2002 JSON.org
|
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;
|
|
@ -1,4 +1,4 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
package net.PeytonPlayz585.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
156
src/net/lax1dude/eaglercraft/SpriteSheetTexture.java
Normal file
|
@ -0,0 +1,156 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.PeytonPlayz585.awt.image.BufferedImage;
|
||||
import net.minecraft.src.GLAllocation;
|
||||
|
||||
public class SpriteSheetTexture {
|
||||
|
||||
public final String name;
|
||||
public final int iconIndex;
|
||||
public final int iconTileSize;
|
||||
private IntBuffer buffer = null;
|
||||
private int dataFrameCount = 0;
|
||||
private int[] frameSet = null;
|
||||
public int ticks = 0;
|
||||
|
||||
private int[] mipmapOffsets = new int[5];
|
||||
|
||||
public SpriteSheetTexture(String name, int iconIndex, int iconTileSize) {
|
||||
this.name = name;
|
||||
this.iconIndex = iconIndex;
|
||||
this.iconTileSize = iconTileSize;
|
||||
reloadData();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
ticks = (ticks + 1) % frameSet.length;
|
||||
}
|
||||
|
||||
public IntBuffer grabFrame(int lvl) {
|
||||
int offWidth = 16 >> lvl;
|
||||
int step = offWidth * offWidth * iconTileSize * iconTileSize;
|
||||
int startIndex = mipmapOffsets[lvl] + step * frameSet[ticks];
|
||||
buffer.limit(startIndex + step);
|
||||
buffer.position(startIndex);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public void reloadData() {
|
||||
ticks = 0;
|
||||
buffer = null;
|
||||
frameSet = null;
|
||||
|
||||
byte[] imgBytes = GL11.EaglerAdapterImpl2.loadResourceBytes("/sprite_sheet/" + name + ".png");
|
||||
if(imgBytes == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int dim = iconTileSize * iconTileSize * 256;
|
||||
BufferedImage img = GL11.EaglerAdapterImpl2.loadPNG(imgBytes);
|
||||
dataFrameCount = img.getData().length / dim;
|
||||
|
||||
ArrayList<Integer> loadedFrameSet = new ArrayList();
|
||||
byte[] metaBytes = GL11.EaglerAdapterImpl2.loadResourceBytes("/sprite_sheet/" + name + ".txt");
|
||||
|
||||
if(metaBytes == null) {
|
||||
for(int i = 0; i < dataFrameCount; ++i) {
|
||||
loadedFrameSet.add(i);
|
||||
}
|
||||
}else {
|
||||
String str = new String(metaBytes, StandardCharsets.UTF_8);
|
||||
String[] splitted = str.split("\\s*,\\s*");
|
||||
for(int i = 0; i < splitted.length; ++i) {
|
||||
String idxStr = splitted[i];
|
||||
int z = idxStr.indexOf('*');
|
||||
if(z != -1) {
|
||||
int idx = Integer.parseInt(idxStr.substring(0, z));
|
||||
int c = Integer.parseInt(idxStr.substring(z + 1));
|
||||
for(int j = 0; j < c; ++j) {
|
||||
loadedFrameSet.add(idx);
|
||||
}
|
||||
}else {
|
||||
loadedFrameSet.add(Integer.parseInt(idxStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameSet = new int[loadedFrameSet.size()];
|
||||
for(int i = 0; i < frameSet.length; ++i) {
|
||||
frameSet[i] = loadedFrameSet.get(i).intValue();
|
||||
}
|
||||
|
||||
buffer = GLAllocation.createDirectIntBuffer(
|
||||
16 * 16 * dataFrameCount * iconTileSize * iconTileSize +
|
||||
8 * 8 * dataFrameCount * iconTileSize * iconTileSize +
|
||||
4 * 4 * dataFrameCount * iconTileSize * iconTileSize +
|
||||
2 * 2 * dataFrameCount * iconTileSize * iconTileSize +
|
||||
dataFrameCount * iconTileSize * iconTileSize
|
||||
);
|
||||
|
||||
int[] texData = swapRB(img.getData());
|
||||
mipmapOffsets[0] = 0;
|
||||
buffer.put(texData);
|
||||
mipmapOffsets[1] = buffer.position();
|
||||
texData = downscale(texData, 16 * iconTileSize, 16 * iconTileSize * dataFrameCount);
|
||||
buffer.put(texData);
|
||||
mipmapOffsets[2] = buffer.position();
|
||||
texData = downscale(texData, 8 * iconTileSize, 8 * iconTileSize * dataFrameCount);
|
||||
buffer.put(texData);
|
||||
mipmapOffsets[3] = buffer.position();
|
||||
texData = downscale(texData, 4 * iconTileSize, 4 * iconTileSize * dataFrameCount);
|
||||
buffer.put(texData);
|
||||
mipmapOffsets[4] = buffer.position();
|
||||
texData = downscale(texData, 2 * iconTileSize, 2 * iconTileSize * dataFrameCount);
|
||||
buffer.put(texData);
|
||||
|
||||
}
|
||||
|
||||
private static int[] downscale(int[] in, int sw, int sh) {
|
||||
int dw = sw / 2;
|
||||
int dh = sh / 2;
|
||||
int[] ret = new int[dw * dh];
|
||||
for(int y = 0; y < dh; ++y) {
|
||||
for(int x = 0; x < dw; ++x) {
|
||||
int a = in[((x * 2) + (y * 2) * sw)];
|
||||
int b = in[((x * 2 + 1) + (y * 2) * sw)];
|
||||
int c = in[((x * 2 + 1) + (y * 2 + 1) * sw)];
|
||||
int d = in[((x * 2) + (y * 2 + 1) * sw)];
|
||||
int b1= (((a >> 26) & 0x3F)) +
|
||||
(((b >> 26) & 0x3F)) +
|
||||
(((c >> 26) & 0x3F)) +
|
||||
(((d >> 26) & 0x3F));
|
||||
int b2= (((a >> 18) & 0x3F)) +
|
||||
(((b >> 18) & 0x3F)) +
|
||||
(((c >> 18) & 0x3F)) +
|
||||
(((d >> 18) & 0x3F));
|
||||
int b3= (((a >> 10) & 0x3F)) +
|
||||
(((b >> 10) & 0x3F)) +
|
||||
(((c >> 10) & 0x3F)) +
|
||||
(((d >> 10) & 0x3F));
|
||||
int b4= (((a >> 2) & 0x3F)) +
|
||||
(((b >> 2) & 0x3F)) +
|
||||
(((c >> 2) & 0x3F)) +
|
||||
(((d >> 2) & 0x3F));
|
||||
ret[y * dw + x] = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static int[] swapRB(int[] in) {
|
||||
int[] out = new int[in.length];
|
||||
for(int i = 0; i < in.length; ++i) {
|
||||
int r = (in[i] >> 16) & 0xFF;
|
||||
int b = in[i] & 0xFF;
|
||||
out[i] = (in[i] & 0xFF00FF00) | (b << 16) | r;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
72
src/net/lax1dude/eaglercraft/TextureNewClockFX.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.TextureFX;
|
||||
|
||||
public class TextureNewClockFX extends TextureFX {
|
||||
|
||||
private final int[] clockSpriteSheet;
|
||||
private final int clockSpriteSheetLength;
|
||||
private float field_94239_h;
|
||||
private float field_94240_i;
|
||||
|
||||
public TextureNewClockFX() {
|
||||
super(Item.pocketSundial.getIconFromDamage(0));
|
||||
tileImage = 1;
|
||||
this.clockSpriteSheet = GL11.EaglerAdapterImpl2.loadPNG(GL11.EaglerAdapterImpl2.loadResourceBytes("/sprite_sheet/clock.png")).getData();
|
||||
this.clockSpriteSheetLength = clockSpriteSheet.length / 256;
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
Minecraft var1 = Minecraft.getMinecraft();
|
||||
double var2 = 0.0D;
|
||||
|
||||
if (var1.theWorld != null && var1.thePlayer != null) {
|
||||
float var4 = var1.theWorld.getCelestialAngle(1.0F);
|
||||
var2 = (double) var4;
|
||||
|
||||
if (var1.theWorld.worldProvider.isNether) {
|
||||
var2 = Math.random();
|
||||
}
|
||||
}
|
||||
|
||||
double var7;
|
||||
|
||||
for (var7 = var2 - this.field_94239_h; var7 < -0.5D; ++var7) {
|
||||
;
|
||||
}
|
||||
|
||||
while (var7 >= 0.5D) {
|
||||
--var7;
|
||||
}
|
||||
|
||||
if (var7 < -1.0D) {
|
||||
var7 = -1.0D;
|
||||
}
|
||||
|
||||
if (var7 > 1.0D) {
|
||||
var7 = 1.0D;
|
||||
}
|
||||
|
||||
this.field_94240_i += var7 * 0.1D;
|
||||
this.field_94240_i *= 0.8D;
|
||||
this.field_94239_h += this.field_94240_i;
|
||||
int var6;
|
||||
|
||||
for (var6 = (int) ((this.field_94239_h + 1.0D) * (double) clockSpriteSheetLength) % clockSpriteSheetLength; var6 < 0; var6 = (var6 + clockSpriteSheetLength) % clockSpriteSheetLength) {
|
||||
;
|
||||
}
|
||||
|
||||
int offset = var6 * 256;
|
||||
for(int i = 0; i < 256; ++i) {
|
||||
this.imageData[i * 4] = (byte)((clockSpriteSheet[offset + i] >> 16) & 0xFF);
|
||||
this.imageData[i * 4 + 1] = (byte)((clockSpriteSheet[offset + i] >> 8) & 0xFF);
|
||||
this.imageData[i * 4 + 2] = (byte)(clockSpriteSheet[offset + i] & 0xFF);
|
||||
this.imageData[i * 4 + 3] = (byte)((clockSpriteSheet[offset + i] >> 24) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
96
src/net/lax1dude/eaglercraft/TextureNewCompassFX.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.ChunkCoordinates;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.TextureFX;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
public class TextureNewCompassFX extends TextureFX {
|
||||
|
||||
private final int[] compassSpriteSheet;
|
||||
private final int compassSpriteSheetLength;
|
||||
private float angleDelta = 0.0f;
|
||||
private float currentAngle = 0.0f;
|
||||
|
||||
public TextureNewCompassFX() {
|
||||
super(Item.compass.getIconFromDamage(0));
|
||||
tileImage = 1;
|
||||
this.compassSpriteSheet = GL11.EaglerAdapterImpl2.loadPNG(GL11.EaglerAdapterImpl2.loadResourceBytes("/sprite_sheet/compass.png")).getData();
|
||||
this.compassSpriteSheetLength = compassSpriteSheet.length / 256;
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
Minecraft var1 = Minecraft.getMinecraft();
|
||||
|
||||
if (var1.theWorld != null && var1.thePlayer != null) {
|
||||
this.updateCompass(var1.theWorld, var1.thePlayer.posX, var1.thePlayer.posZ, (double) var1.thePlayer.rotationYaw, false, false);
|
||||
} else {
|
||||
this.updateCompass((World) null, 0.0D, 0.0D, 0.0D, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCompass(World par1World, double par2, double par4, double par6, boolean par8, boolean par9) {
|
||||
double var10 = 0.0D;
|
||||
|
||||
if (par1World != null && !par8) {
|
||||
ChunkCoordinates var12 = par1World.getSpawnPoint();
|
||||
double var13 = (double) var12.x - par2;
|
||||
double var15 = (double) var12.z - par4;
|
||||
par6 %= 360.0D;
|
||||
var10 = -((par6 - 90.0D) * Math.PI / 180.0D - Math.atan2(var15, var13));
|
||||
|
||||
if (par1World.worldProvider.isNether) {
|
||||
var10 = Math.random() * Math.PI * 2.0D;
|
||||
}
|
||||
}
|
||||
|
||||
if (par9) {
|
||||
this.currentAngle = (float) var10;
|
||||
} else {
|
||||
double var17;
|
||||
|
||||
for (var17 = var10 - this.currentAngle; var17 < -Math.PI; var17 += (Math.PI * 2D)) {
|
||||
;
|
||||
}
|
||||
|
||||
while (var17 >= Math.PI) {
|
||||
var17 -= (Math.PI * 2D);
|
||||
}
|
||||
|
||||
if (var17 < -1.0D) {
|
||||
var17 = -1.0D;
|
||||
}
|
||||
|
||||
if (var17 > 1.0D) {
|
||||
var17 = 1.0D;
|
||||
}
|
||||
|
||||
this.angleDelta += var17 * 0.1D;
|
||||
this.angleDelta *= 0.8D;
|
||||
this.currentAngle += this.angleDelta;
|
||||
}
|
||||
|
||||
int var18;
|
||||
|
||||
for (var18 = (int) ((this.currentAngle / (Math.PI * 2D) + 1.0D) * (double) compassSpriteSheetLength) % compassSpriteSheetLength; var18 < 0; var18 = (var18 + compassSpriteSheetLength) % compassSpriteSheetLength) {
|
||||
;
|
||||
}
|
||||
|
||||
int offset = var18 * 256;
|
||||
for(int i = 0; i < 256; ++i) {
|
||||
this.imageData[i * 4] = (byte)((compassSpriteSheet[offset + i] >> 16) & 0xFF);
|
||||
this.imageData[i * 4 + 1] = (byte)((compassSpriteSheet[offset + i] >> 8) & 0xFF);
|
||||
this.imageData[i * 4 + 2] = (byte)((compassSpriteSheet[offset + i]) & 0xFF);
|
||||
this.imageData[i * 4 + 3] = (byte)((compassSpriteSheet[offset + i] >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
//if (var18 != this.frameCounter) {
|
||||
// this.frameCounter = var18;
|
||||
// this.textureSheet.func_104062_b(this.originX, this.originY, (Texture) this.textureList.get(this.frameCounter));
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
|
@ -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,12 @@
|
|||
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.lax1dude.eaglercraft.TextureNewClockFX;
|
||||
import net.lax1dude.eaglercraft.TextureNewCompassFX;
|
||||
import net.minecraft.src.AchievementList;
|
||||
import net.minecraft.src.AxisAlignedBB;
|
||||
import net.minecraft.src.Block;
|
||||
|
@ -64,14 +68,6 @@ import net.minecraft.src.StatList;
|
|||
import net.minecraft.src.StatStringFormatKeyInv;
|
||||
import net.minecraft.src.Teleporter;
|
||||
import net.minecraft.src.Tessellator;
|
||||
import net.minecraft.src.TextureCompassFX;
|
||||
import net.minecraft.src.TextureFlamesFX;
|
||||
import net.minecraft.src.TextureLavaFX;
|
||||
import net.minecraft.src.TextureLavaFlowFX;
|
||||
import net.minecraft.src.TexturePortalFX;
|
||||
import net.minecraft.src.TextureWatchFX;
|
||||
import net.minecraft.src.TextureWaterFX;
|
||||
import net.minecraft.src.TextureWaterFlowFX;
|
||||
import net.minecraft.src.Timer;
|
||||
import net.minecraft.src.UnexpectedThrowable;
|
||||
import net.minecraft.src.Vec3D;
|
||||
|
@ -119,8 +115,6 @@ public class Minecraft implements Runnable {
|
|||
public StatFileWriter statFileWriter;
|
||||
private String serverName;
|
||||
private int serverPort;
|
||||
private TextureWaterFX textureWaterFX = new TextureWaterFX();
|
||||
private TextureLavaFX textureLavaFX = new TextureLavaFX();
|
||||
private static String minecraftDir = "minecraft";
|
||||
public volatile boolean running = true;
|
||||
public String debug = "";
|
||||
|
@ -136,9 +130,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;
|
||||
}
|
||||
|
@ -181,15 +175,15 @@ public class Minecraft implements Runnable {
|
|||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
this.checkGLError("Startup");
|
||||
this.sndManager.loadSoundSettings(this.gameSettings);
|
||||
this.renderEngine.registerTextureFX(this.textureLavaFX);
|
||||
this.renderEngine.registerTextureFX(this.textureWaterFX);
|
||||
this.renderEngine.registerTextureFX(new TexturePortalFX());
|
||||
this.renderEngine.registerTextureFX(new TextureCompassFX(this));
|
||||
this.renderEngine.registerTextureFX(new TextureWatchFX(this));
|
||||
this.renderEngine.registerTextureFX(new TextureWaterFlowFX());
|
||||
this.renderEngine.registerTextureFX(new TextureLavaFlowFX());
|
||||
this.renderEngine.registerTextureFX(new TextureFlamesFX(0));
|
||||
this.renderEngine.registerTextureFX(new TextureFlamesFX(1));
|
||||
renderEngine.registerTextureFX(new TextureNewCompassFX());
|
||||
renderEngine.registerTextureFX(new TextureNewClockFX());
|
||||
renderEngine.registerSpriteSheet("portal", Block.portal.blockIndexInTexture, 1);
|
||||
renderEngine.registerSpriteSheet("water", Block.waterStill.blockIndexInTexture, 1);
|
||||
renderEngine.registerSpriteSheet("water_flow", Block.waterMoving.blockIndexInTexture + 1, 2);
|
||||
renderEngine.registerSpriteSheet("lava", Block.lavaStill.blockIndexInTexture, 1);
|
||||
renderEngine.registerSpriteSheet("lava_flow", Block.lavaMoving.blockIndexInTexture + 1, 2);
|
||||
renderEngine.registerSpriteSheet("fire_0", Block.fire.blockIndexInTexture, 1);
|
||||
renderEngine.registerSpriteSheet("fire_1", Block.fire.blockIndexInTexture + 16, 1);
|
||||
this.renderGlobal = new RenderGlobal(this, this.renderEngine);
|
||||
GL11.glViewport(0, 0, this.displayWidth, this.displayHeight);
|
||||
this.effectRenderer = new EffectRenderer(this.theWorld, this.renderEngine);
|
||||
|
@ -233,7 +227,7 @@ public class Minecraft implements Runnable {
|
|||
|
||||
//Emulate Display.swapBuffers()
|
||||
GL11.glFlush();
|
||||
GL11.updateDisplay();
|
||||
Display.update();
|
||||
GL11.optimize();
|
||||
}
|
||||
|
||||
|
@ -370,7 +364,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 +387,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;
|
||||
}
|
||||
|
@ -429,13 +423,13 @@ public class Minecraft implements Runnable {
|
|||
}
|
||||
}
|
||||
} catch (MinecraftError var20) {
|
||||
} catch (Throwable var21) {
|
||||
} /*catch (Throwable var21) {
|
||||
this.func_28002_e();
|
||||
var21.printStackTrace();
|
||||
this.onMinecraftCrash(new UnexpectedThrowable("Unexpected error", var21));
|
||||
} finally {
|
||||
this.shutdownMinecraftApplet();
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -784,19 +778,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|