Performance patch

This commit is contained in:
PeytonPlayz595 2024-10-21 01:08:10 -04:00
parent 059925a075
commit b58c8f1520
77 changed files with 5897 additions and 12006 deletions

View File

@ -25,6 +25,11 @@
</attributes>
</classpathentry>
<classpathentry kind="lib" path="jars/lwjgl_util.jar"/>
<classpathentry kind="lib" path="jars/lwjgl-jemalloc.jar"/>
<classpathentry kind="lib" path="jars/UnsafeMemcpy.jar"/>
<classpathentry kind="lib" path="jars/Java-WebSocket-1.5.1-with-dependencies.jar"/>
<classpathentry kind="lib" path="jars/codecjorbis-20101023.jar"/>
<classpathentry kind="lib" path="jars/codecwav-20101023.jar"/>
<classpathentry kind="lib" path="jars/soundsystem-20120107.jar"/>
<classpathentry kind="output" path="output"/>
</classpath>

View File

@ -8,7 +8,9 @@ repositories {
}
dependencies {
implementation teavm.libs.jsoApis
teavm(teavm.libs.jso)
teavm(teavm.libs.jsoApis)
compileOnly "org.teavm:teavm-core:0.9.2"
}
apply plugin: 'eclipse'

BIN
jars/UnsafeMemcpy.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
jars/codecwav-20101023.jar Normal file

Binary file not shown.

BIN
jars/lwjgl-jemalloc.jar Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,8 +1,3 @@
// copyright (c) 2020-2023 lax1dude
#line 4
precision highp int;
precision highp sampler2D;
precision highp float;
@ -85,10 +80,6 @@ uniform vec3 normalUniform;
#endif
#ifdef CC_fog
uniform vec4 fogColor;
//X = uniform float fogMode;
//Y = uniform float fogStart;
//Z = uniform float fogEnd - fogStart;
//W = uniform float fogDensity;
uniform vec4 fogParam;
#endif
uniform vec4 colorUniform;
@ -96,10 +87,6 @@ uniform vec4 colorUniform;
uniform float alphaTestF;
#endif
#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;
@ -161,24 +148,21 @@ void main(){
#ifdef CC_a_texture0
#ifdef CC_patch_anisotropic
vec2 uv = TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0);
//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);
//uv = ((uv * anisotropic_fix) - fract(uv * anisotropic_fix) + 0.5) / anisotropic_fix;
//vec4 texColor = texture(tex0, uv);
vec2 uv = floor(v_texture0 * anisotropic_fix) + 0.5;
color *= texture(tex0, uv / anisotropic_fix) * texColor.rgba;
#else
vec4 texColor = texture(tex0, TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0));
//vec4 texColor = texture(tex0, TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0));
color *= texture(tex0, v_texture0);
#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;
//vec4 texColor = texture(tex0, TEX_MAT3x2(matrix_t) * vec3(texCoordV0, 1.0));
color *= texture(tex0, texCoordV0);
#endif
#endif
@ -210,9 +194,15 @@ void main(){
#endif
#ifdef CC_fog
float dist = sqrt(dot(v_position, v_position));
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);
vec3 fogPos = v_position.xyz / v_position.w;
float dist = length(fogPos);
float fogDensity = fogParam.y;
float fogStart = fogParam.z;
float fogEnd = fogParam.w;
//float f = fogParam.x == 1.0 ? 1.0 - exp(-fogDensity * dist) :
//(dist - fogStart) / (fogEnd - fogStart);
float f = ((dist * fogDensity) - fogStart) / (fogEnd - fogStart);
color.rgb = mix(color.rgb, fogColor.rgb, clamp(f, 0.0, 1.0) * fogColor.a);
#endif
fragColor = color;

View File

@ -1,14 +1,10 @@
package net.PeytonPlayz585;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.ShortBuffer;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.EaglerLWJGLAllocator;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
import net.lax1dude.eaglercraft.internal.buffer.ShortBuffer;
/**
* Some often-used Buffer code for creating native buffers of the appropriate size.
@ -26,7 +22,8 @@ public final class BufferUtils {
* @return a ByteBuffer
*/
public static ByteBuffer createByteBuffer(int size) {
return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
//return EaglerLWJGLAllocator.allocateDirect(size).order(ByteOrder.nativeOrder());
return EaglerLWJGLAllocator.allocByteBuffer(size);
}
/**
@ -39,16 +36,6 @@ public final class BufferUtils {
return createByteBuffer(size << 1).asShortBuffer();
}
/**
* Construct a direct native-order charbuffer with the specified number
* of elements.
* @param size The size, in chars
* @return an CharBuffer
*/
public static CharBuffer createCharBuffer(int size) {
return createByteBuffer(size << 1).asCharBuffer();
}
/**
* Construct a direct native-order intbuffer with the specified number
* of elements.
@ -59,16 +46,6 @@ public final class BufferUtils {
return createByteBuffer(size << 2).asIntBuffer();
}
/**
* Construct a direct native-order longbuffer with the specified number
* of elements.
* @param size The size, in longs
* @return an LongBuffer
*/
public static LongBuffer createLongBuffer(int size) {
return createByteBuffer(size << 3).asLongBuffer();
}
/**
* Construct a direct native-order floatbuffer with the specified number
* of elements.
@ -78,49 +55,4 @@ public final class BufferUtils {
public static FloatBuffer createFloatBuffer(int size) {
return createByteBuffer(size << 2).asFloatBuffer();
}
/**
* Construct a direct native-order doublebuffer with the specified number
* of elements.
* @param size The size, in floats
* @return a FloatBuffer
*/
public static DoubleBuffer createDoubleBuffer(int size) {
return createByteBuffer(size << 3).asDoubleBuffer();
}
/**
* Construct a PointerBuffer with the specified number
* of elements.
* @param size The size, in memory addresses
* @return a PointerBuffer
*/
public static PointerBuffer createPointerBuffer(int size) {
return (PointerBuffer) PointerBuffer.allocateDirect(size);
}
/**
* @return n, where buffer_element_size=2^n.
*/
public static int getElementSizeExponent(Buffer buf) {
if (buf instanceof ByteBuffer)
return 0;
else if (buf instanceof ShortBuffer || buf instanceof CharBuffer)
return 1;
else if (buf instanceof FloatBuffer || buf instanceof IntBuffer)
return 2;
else if (buf instanceof LongBuffer || buf instanceof DoubleBuffer)
return 3;
else
throw new IllegalStateException("Unsupported buffer type: " + buf);
}
/**
* A helper function which is used to get the byte offset in an arbitrary buffer
* based on its position
* @return the position of the buffer, in BYTES
*/
public static int getOffset(Buffer buffer) {
return buffer.position() << getElementSizeExponent(buffer);
}
}

View File

@ -27,10 +27,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
@ -58,20 +55,27 @@ import org.lwjgl.util.glu.GLU;
import net.PeytonPlayz585.util.vector.Matrix4f;
import net.PeytonPlayz585.util.vector.Vector3f;
import net.PeytonPlayz585.util.vector.Vector4f;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.EaglerLWJGLAllocator;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
import com.jcraft.jzlib.InflaterInputStream;
import de.cuina.fireandfuel.CodecJLayerMP3;
import net.PeytonPlayz585.BufferUtils;
import net.PeytonPlayz585.GameWindowListener;
import net.PeytonPlayz585.awt.image.BufferedImage;
import net.PeytonPlayz585.awt.image.ImageIO;
import net.PeytonPlayz585.fileutils.FileChooserResult;
import net.PeytonPlayz585.glemu.FixedFunctionShader;
import net.PeytonPlayz585.glemu.StreamBuffer.StreamBufferInstance;
import net.PeytonPlayz585.opengl.GL11_1.EaglerAdapterImpl2.TextureGL;
import net.minecraft.src.MathHelper;
import net.minecraft.src.Tessellator;
import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.codecs.CodecJOrbis;
import paulscode.sound.libraries.LibraryLWJGLOpenAL;
import org.lwjgl.opengl.ARBDebugOutput;
@ -87,7 +91,9 @@ import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL21;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL31;
import org.lwjgl.opengl.PixelFormat;
import static net.PeytonPlayz585.opengl.GL11_1.EaglerAdapterImpl2.*;
@ -213,6 +219,8 @@ public class GL11_1 {
public static final int GL_GEQUAL = RealOpenGLEnums.GL_GEQUAL;
public static final int GL_LESS = RealOpenGLEnums.GL_LESS;
public static final int GL_POINTS = RealOpenGLEnums.GL_POINTS;
public static final int GL_RGBA8 = RealOpenGLEnums.GL_RGBA8;
public static final int GL_CLAMP_TO_EDGE = RealOpenGLEnums.GL_CLAMP_TO_EDGE;
static final GLObjectMap<TextureGL> texObjects = new GLObjectMap(256);
@ -310,17 +318,16 @@ public class GL11_1 {
public static float texQ_Z = 0.0f;
public static float texQ_W = 0.0f;
public static int fogColorSerial = 0;
public static float fogColorR = 1.0f;
public static float fogColorG = 1.0f;
public static float fogColorB = 1.0f;
public static float fogColorA = 1.0f;
public static int fogCfgSerial = 0;
public static int fogMode = 1;
static boolean fogEnabled = false;
public static float fogStart = 1.0f;
public static float fogEnd = 1.0f;
public static float fogDensity = 1.0f;
public static boolean stateFog = false;
public static boolean stateFogEXP = false;
public static float stateFogDensity = 1.0f;
public static float stateFogStart = 0.0f;
public static float stateFogEnd = 1.0f;
public static float stateFogColorR = 1.0f;
public static float stateFogColorG = 1.0f;
public static float stateFogColorB = 1.0f;
public static float stateFogColorA = 1.0f;
public static int stateFogSerial = 0;
static int bytesUploaded = 0;
static int vertexDrawn = 0;
@ -441,7 +448,7 @@ public class GL11_1 {
enableAlphaTest = true;
break;
case GL_FOG:
fogEnabled = true;
stateFog = true;
break;
case GL_COLOR_MATERIAL:
enableColorMaterial = true;
@ -626,7 +633,7 @@ public class GL11_1 {
enableAlphaTest = false;
break;
case GL_FOG:
fogEnabled = false;
stateFog = false;
break;
case GL_COLOR_MATERIAL:
enableColorMaterial = false;
@ -683,10 +690,6 @@ public class GL11_1 {
_wglTexImage2D(_wGL_TEXTURE_2D, p2, _wGL_RGBA8, p4, p5, p6, _wGL_RGBA, _wGL_UNSIGNED_BYTE, p9);
}
public static final void glLightModel(int p1, FloatBuffer p2) {
}
public static int lightPos0Serial = 0;
public static int lightPos1Serial = 0;
private static Vector4f lightPos0vec0 = new Vector4f();
@ -697,39 +700,6 @@ public class GL11_1 {
private static float[] light0 = new float[4];
private static float[] light1 = new float[4];
public static final void glLight(int light, int pname, FloatBuffer param) {
if(pname == GL_POSITION) {
switch(light) {
case GL_LIGHT0:
try {
light0[0] = param.get(param.position());
light0[1] = param.get(param.position() + 1);
light0[2] = param.get(param.position() + 2);
light0[3] = param.get(param.position() + 3);
} catch(Exception e) {
System.err.println("Failed to shade model (GL_LIGHT0)");
light0[0] = 0.0F;
light0[1] = 0.0F;
light0[2] = 0.0F;
light0[3] = 0.0F;
}
case GL_LIGHT1:
try {
light1[0] = param.get(param.position());
light1[1] = param.get(param.position() + 1);
light1[2] = param.get(param.position() + 2);
light1[3] = param.get(param.position() + 3);
} catch(Exception e) {
System.err.println("Failed to shade model (GL_LIGHT1)");
light1[0] = 0.0F;
light1[1] = 0.0F;
light1[2] = 0.0F;
light1[3] = 0.0F;
}
}
}
}
public static final void copyModelToLightMatrix() {
++lightPos0Serial;
++lightPos1Serial;
@ -1309,7 +1279,8 @@ public class GL11_1 {
int mode = 0;
mode = (mode | (enableTexGen ? FixedFunctionShader.TEXGEN : 0));
mode = (mode | ((enableColorMaterial && enableLighting) ? FixedFunctionShader.LIGHTING : 0));
mode = (mode | (fogEnabled ? FixedFunctionShader.FOG : 0));
mode = (mode | ((stateFog && stateFogDensity > 0.0f) ? FixedFunctionShader.FOG : 0));
//mode = (mode | (fogEnabled ? FixedFunctionShader.FOG : 0));
mode = (mode | (enableAlphaTest ? FixedFunctionShader.ALPHATEST : 0));
mode = (mode | (enableTexture2D ? FixedFunctionShader.UNIT0 : 0));
mode = (mode | (enableTexture2D_1 ? FixedFunctionShader.UNIT1 : 0));
@ -1328,7 +1299,8 @@ public class GL11_1 {
mode = (mode | (enableTex1Array ? FixedFunctionShader.TEXTURE1 : 0));
mode = (mode | (enableTexGen ? FixedFunctionShader.TEXGEN : 0));
mode = (mode | ((enableColorMaterial && enableLighting) ? FixedFunctionShader.LIGHTING : 0));
mode = (mode | (fogEnabled ? FixedFunctionShader.FOG : 0));
mode = (mode | ((stateFog && stateFogDensity > 0.0f) ? FixedFunctionShader.FOG : 0));
//mode = (mode | (fogEnabled ? FixedFunctionShader.FOG : 0));
mode = (mode | (enableAlphaTest ? FixedFunctionShader.ALPHATEST : 0));
mode = (mode | (enableTexture2D ? FixedFunctionShader.UNIT0 : 0));
mode = (mode | (enableTexture2D_1 ? FixedFunctionShader.UNIT1 : 0));
@ -1434,8 +1406,9 @@ public class GL11_1 {
private static final void _wglDrawQuadArrays(int p2, int p3) {
if (quadsToTrianglesBuffer == null) {
IntBuffer upload = isWebGL ? IntBuffer.wrap(new int[98400 / 2])
: ByteBuffer.allocateDirect(98400 * 2).order(ByteOrder.nativeOrder()).asIntBuffer();
//IntBuffer upload = isWebGL ? IntBuffer.wrap(new int[98400 / 2])
//: ByteBuffer.allocateDirect(98400 * 2).order(ByteOrder.nativeOrder()).asIntBuffer();
IntBuffer upload = BufferUtils.createIntBuffer(98400 * 2);
for (int i = 0; i < 16384; ++i) {
int v1 = i * 4;
int v2 = i * 4 + 1;
@ -1467,8 +1440,9 @@ public class GL11_1 {
occlusion_vao = _wglCreateVertexArray();
occlusion_vbo = _wglCreateBuffer();
IntBuffer upload = (isWebGL ? IntBuffer.wrap(new int[108])
: ByteBuffer.allocateDirect(108 << 2).order(ByteOrder.nativeOrder()).asIntBuffer());
//IntBuffer upload = (isWebGL ? IntBuffer.wrap(new int[108])
//: ByteBuffer.allocateDirect(108 << 2).order(ByteOrder.nativeOrder()).asIntBuffer());
IntBuffer upload = BufferUtils.createIntBuffer(98400 / 2);
float[] verts = new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
@ -1596,6 +1570,10 @@ public class GL11_1 {
return texObjects.register(_wglGenTextures());
}
public static final TextureGL glGetTextures(int tex) {
return texObjects.get(tex);
}
public static final void glGenTextures(IntBuffer buf) {
for(int i = buf.position(); i < buf.limit(); i++) {
buf.put(i, glGenTextures());
@ -1624,45 +1602,48 @@ public class GL11_1 {
if (p1 == GL_FOG_MODE) {
switch (p2) {
default:
case GL_LINEAR:
++fogCfgSerial;
fogMode = 1;
break;
case GL_EXP:
++fogCfgSerial;
fogMode = 2;
stateFogEXP = true;
++stateFogSerial;
break;
}
}
}
public static final void glFogf(int p1, float p2) {
public static final void glFogf(int p1, float param) {
switch (p1) {
case GL_FOG_START:
++fogCfgSerial;
fogStart = p2;
stateFogStart = param;
++stateFogSerial;
break;
case GL_FOG_END:
++fogCfgSerial;
fogEnd = p2;
stateFogEnd = param;
++stateFogSerial;
break;
case GL_FOG_DENSITY:
++fogCfgSerial;
fogDensity = p2;
stateFogDensity = param;
++stateFogSerial;
break;
default:
break;
}
}
public static final void glFog(int p1, FloatBuffer p2) {
if (p1 == GL_FOG_COLOR) {
++fogColorSerial;
fogColorR = p2.get();
fogColorG = p2.get();
fogColorB = p2.get();
fogColorA = p2.get();
public static final void glFog(int param, FloatBuffer valueBuffer) {
int pos = valueBuffer.position();
switch(param) {
case GL_FOG_COLOR:
stateFogColorR = valueBuffer.get();
stateFogColorG = valueBuffer.get();
stateFogColorB = valueBuffer.get();
stateFogColorA = valueBuffer.get();
++stateFogSerial;
break;
default:
throw new UnsupportedOperationException("Only GL_FOG_COLOR is configurable!");
}
valueBuffer.position(pos);
}
public static final void glDeleteLists(int p1, int p2) {
@ -4513,8 +4494,10 @@ public class GL11_1 {
public static final void _wglFlush() {
GL11.glFlush();
}
public static final void _wglTexImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, ByteBuffer p9) {
GL11.glTexImage2D(p1, p2, p3, p4, p5, p6, p7, p8, p9);
public static final void _wglTexImage2D(int target, int level, int internalFormat, int width, int height,
int border, int format, int type, ByteBuffer data) {
GL11.glTexImage2D(target, level, internalFormat, width, height, border, format, type,
data == null ? 0l : EaglerLWJGLAllocator.getAddress(data));
}
public static final void _wglBlendFunc(int p1, int p2) {
GL11.glBlendFunc(p1, p2);
@ -4543,11 +4526,15 @@ public class GL11_1 {
public static final void _wglTexParameterf(int p1, int p2, int p3) {
GL11.glTexParameterf(p1, p2, p3);
}
public static final void _wglTexImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, IntBuffer p9) {
GL11.glTexImage2D(p1, p2, p3, p4, p5, p6, p7, p8, p9);
public static final void _wglTexImage2D(int target, int level, int internalFormat, int width, int height,
int border, int format, int type, IntBuffer data) {
GL11.glTexImage2D(target, level, internalFormat, width, height, border, format, type,
data == null ? 0l : EaglerLWJGLAllocator.getAddress(data));
}
public static final void _wglTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, IntBuffer p9) {
GL11.glTexSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8, p9);
public static final void _wglTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height,
int format, int type, ByteBuffer data) {
GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type,
data == null ? 0l : EaglerLWJGLAllocator.getAddress(data));
}
public static final void _wglDeleteTextures(TextureGL p1) {
GL11.glDeleteTextures(p1.obj);
@ -4561,11 +4548,10 @@ public class GL11_1 {
public static final TextureGL _wglGenTextures() {
return new TextureGL(GL11.glGenTextures());
}
public static final void _wglTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, ByteBuffer p9) {
GL11.glTexSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8, p9);
}
public static final void _wglTexImage3D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, ByteBuffer p10) {
GL12.glTexImage3D(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
public static final void _wglTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height,
int format, int type, IntBuffer data) {
GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type,
data == null ? 0l : EaglerLWJGLAllocator.getAddress(data));
}
public static final void _wglTexParameterf(int p1, int p2, float p3) {
GL11.glTexParameterf(p1, p2, p3);
@ -4634,19 +4620,61 @@ public class GL11_1 {
GL15.glBindBuffer(p1, p2 == null ? 0 : p2.obj);
}
public static final void _wglBufferData(int p1, Object p2, int p3) {
GL15.glBufferData(p1, (IntBuffer)p2, p3);
if(p2 != null) {
IntBuffer buf1 = (IntBuffer)p2;
int size = buf1.remaining() << 2;
java.nio.IntBuffer buf = java.nio.ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asIntBuffer();
while(buf1.hasRemaining()) {
buf.put(buf1.get());
}
GL15.glBufferData(p1, buf, p3);
} else {
GL15.glBufferData(p1, (java.nio.IntBuffer)null, p3);
}
}
public static final void _wglBufferSubData(int p1, int p2, Object p3) {
GL15.glBufferSubData(p1, p2, (IntBuffer)p3);
if(p3 != null) {
IntBuffer buf1 = (IntBuffer)p3;
int size = buf1.remaining() << 2;
java.nio.IntBuffer buf = java.nio.ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asIntBuffer();
while(buf1.hasRemaining()) {
buf.put(buf1.get());
}
GL15.glBufferSubData(p1, p2, buf);
} else {
GL15.glBufferSubData(p1, p2, (java.nio.IntBuffer)null);
}
}
public static final void _wglBufferData0(int p1, IntBuffer p2, int p3) {
GL15.glBufferData(p1, p2, p3);
//GL15.glBufferData(p1, p2, p3);
if(p2 != null) {
IntBuffer buf1 = (IntBuffer)p2;
int size = buf1.remaining() << 2;
java.nio.IntBuffer buf = java.nio.ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asIntBuffer();
while(buf1.hasRemaining()) {
buf.put(buf1.get());
}
GL15.glBufferData(p1, buf, p3);
} else {
GL15.glBufferData(p1, (java.nio.IntBuffer)null, p3);
}
}
public static final void _wglBufferData00(int p1, long len, int p3) {
GL15.glBufferData(p1, len, p3);
}
public static final void _wglBufferSubData0(int p1, int p2, IntBuffer p3) {
GL15.glBufferSubData(p1, p2, p3);
//GL15.glBufferSubData(p1, p2, p3);
if(p3 != null) {
IntBuffer buf1 = (IntBuffer)p3;
int size = buf1.remaining() << 2;
java.nio.IntBuffer buf = java.nio.ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asIntBuffer();
while(buf1.hasRemaining()) {
buf.put(buf1.get());
}
GL15.glBufferSubData(p1, p2, buf);
} else {
GL15.glBufferSubData(p1, p2, (java.nio.IntBuffer)null);
}
}
public static final void _wglBindAttribLocation(int p1, int p2, String p3) {
GL20.glBindAttribLocation(p1, p2, p3);
@ -4688,7 +4716,7 @@ public class GL11_1 {
public static final void _wglUniform4i(UniformGL p1, int p2, int p3, int p4, int p5) {
if(p1 != null) GL20.glUniform4i(p1.obj, p2, p3, p4, p5);
}
private static final FloatBuffer matUpload = ByteBuffer.allocateDirect(16 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
private static final java.nio.FloatBuffer matUpload = java.nio.ByteBuffer.allocateDirect(16 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
public static final void _wglUniformMat2fv(UniformGL p1, float[] mat) {
matUpload.clear();
matUpload.put(mat);
@ -4745,8 +4773,8 @@ public class GL11_1 {
public static final void _wglDeleteFramebuffer(FramebufferGL p1) {
GL30.glDeleteFramebuffers(p1.obj);
}
public static final void _wglFramebufferTexture2D(int p1, TextureGL p2) {
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, p1, GL11.GL_TEXTURE_2D, p2.obj, 0);
public static final void _wglFramebufferTexture2D(int target1, int p1, int target2, TextureGL p2, int target3) {
GL30.glFramebufferTexture2D(target1, p1, target2, p2.obj, target3);
}
public static final void _wglFramebufferTexture2D(int p1, TextureGL p2, int lvl) {
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, p1, GL11.GL_TEXTURE_2D, p2.obj, lvl);
@ -4757,17 +4785,17 @@ public class GL11_1 {
public static final void _wglDeleteRenderbuffer(RenderbufferGL p1) {
GL30.glDeleteRenderbuffers(p1.obj);
}
public static final void _wglBindRenderbuffer(RenderbufferGL p1) {
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, p1 == null ? 0 : p1.obj);
public static final void _wglBindRenderbuffer(int target, RenderbufferGL p1) {
GL30.glBindRenderbuffer(target, p1 == null ? 0 : p1.obj);
}
public static final void _wglRenderbufferStorage(int p1, int p2, int p3) {
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, p1, p2, p3);
public static final void _wglRenderbufferStorage(int target, int p1, int p2, int p3) {
GL30.glRenderbufferStorage(target, p1, p2, p3);
}
public static final void _wglRenderbufferStorageMultisample(int p1, int p2, int p3, int p4) {
GL30.glRenderbufferStorageMultisample(GL30.GL_RENDERBUFFER, p1, p2, p3, p4);
}
public static final void _wglFramebufferRenderbuffer(int p1, RenderbufferGL p2) {
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, p1, GL30.GL_RENDERBUFFER, p2.obj);
public static final void _wglFramebufferRenderbuffer(int target1, int p1, int target2, RenderbufferGL p2) {
GL30.glFramebufferRenderbuffer(target1, p1, target2, p2.obj);
}
public static final QueryGL _wglCreateQuery() {
return new QueryGL(GL15.glGenQueries());
@ -5036,6 +5064,7 @@ public class GL11_1 {
try {
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
SoundSystemConfig.setCodec("ogg", CodecJOrbis.class);
SoundSystemConfig.setCodec("mp3", CodecJLayerMP3.class);
ss = new SoundSystem();
}catch(Throwable t) {
@ -5253,7 +5282,7 @@ public class GL11_1 {
}
@Override
public void onMessage(ByteBuffer arg0) {
public void onMessage(java.nio.ByteBuffer arg0) {
wasAbleToConnect = true;
synchronized(socketSync) {
readPackets.add(arg0.array());
@ -5299,7 +5328,7 @@ public class GL11_1 {
}
public static final void writePacket(byte[] packet) {
if(clientSocket != null && clientSocket.isOpen()) {
clientSocket.send(ByteBuffer.wrap(packet));
clientSocket.send(java.nio.ByteBuffer.wrap(packet));
}
}
public static final byte[] readPacket() {
@ -5495,7 +5524,7 @@ public class GL11_1 {
ss.setVolume(name, volume);
ss.play(name);
}else {
System.err.println("unknown sound event "+fileName);
return -1;
}
return id;
}
@ -5513,7 +5542,7 @@ public class GL11_1 {
ss.setVolume(name, volume);
ss.play(name);
}else {
System.err.println("unknown sound event "+fileName);
return -1;
}
return id;
}
@ -5572,7 +5601,7 @@ public class GL11_1 {
return ((IntBuffer)obj).remaining() * 4;
}
public static final Object _wCreateLowLevelIntBuffer(int len) {
return ByteBuffer.allocateDirect(len*4).order(ByteOrder.nativeOrder()).asIntBuffer();
return BufferUtils.createIntBuffer(len*4);
}
private static final IntBuffer appendbuffer = (IntBuffer) _wCreateLowLevelIntBuffer(525000);

View File

@ -1,9 +1,7 @@
package net.PeytonPlayz585.util.glu;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import net.PeytonPlayz585.opengl.GL11;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
public class GLU {

View File

@ -0,0 +1,164 @@
package net.lax1dude.eaglercraft.internal.buffer;
import org.lwjgl.system.jemalloc.JEmalloc;
/**
* Copyright (c) 2022-2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerLWJGLAllocator {
public static class WrongBufferClassType extends RuntimeException {
public WrongBufferClassType(String msg) {
super(msg);
}
}
public static ByteBuffer allocByteBuffer(int len) {
long ret = JEmalloc.nje_malloc(len);
if(ret == 0l) {
throw new OutOfMemoryError("Native je_malloc call returned null pointer!");
}
return new EaglerLWJGLByteBuffer(ret, len, true);
}
public static ShortBuffer allocShortBuffer(int len) {
long ret = JEmalloc.nje_malloc(len << 1);
if(ret == 0l) {
throw new OutOfMemoryError("Native je_malloc call returned null pointer!");
}
return new EaglerLWJGLShortBuffer(ret, len, true);
}
public static IntBuffer allocIntBuffer(int len) {
long ret = JEmalloc.nje_malloc(len << 2);
if(ret == 0l) {
throw new OutOfMemoryError("Native je_malloc call returned null pointer!");
}
return new EaglerLWJGLIntBuffer(ret, len, true);
}
public static FloatBuffer allocFloatBuffer(int len) {
long ret = JEmalloc.nje_malloc(len << 2);
if(ret == 0l) {
throw new OutOfMemoryError("Native je_malloc call returned null pointer!");
}
return new EaglerLWJGLFloatBuffer(ret, len, true);
}
public static void freeByteBuffer(ByteBuffer buffer) {
if(buffer instanceof EaglerLWJGLByteBuffer) {
EaglerLWJGLByteBuffer buf = (EaglerLWJGLByteBuffer)buffer;
if(buf.original) {
JEmalloc.nje_free(buf.address);
}else {
throwNotOriginal(buffer);
}
}else {
throwNotEagler(buffer);
}
}
public static long getAddress(ByteBuffer buffer) {
if(buffer instanceof EaglerLWJGLByteBuffer) {
EaglerLWJGLByteBuffer b = (EaglerLWJGLByteBuffer)buffer;
return b.address + b.position();
}else {
throw notEagler(buffer);
}
}
public static void freeShortBuffer(ShortBuffer buffer) {
if(buffer instanceof EaglerLWJGLShortBuffer) {
EaglerLWJGLShortBuffer buf = (EaglerLWJGLShortBuffer)buffer;
if(buf.original) {
JEmalloc.nje_free(buf.address);
}else {
throwNotOriginal(buffer);
}
}else {
throwNotEagler(buffer);
}
}
public static long getAddress(ShortBuffer buffer) {
if(buffer instanceof EaglerLWJGLShortBuffer) {
EaglerLWJGLShortBuffer b = (EaglerLWJGLShortBuffer)buffer;
return b.address + (b.position() << 1);
}else {
throw notEagler(buffer);
}
}
public static void freeIntBuffer(IntBuffer buffer) {
if(buffer instanceof EaglerLWJGLIntBuffer) {
EaglerLWJGLIntBuffer buf = (EaglerLWJGLIntBuffer)buffer;
if(buf.original) {
JEmalloc.nje_free(buf.address);
}else {
throwNotOriginal(buffer);
}
}else {
throwNotEagler(buffer);
}
}
public static long getAddress(IntBuffer buffer) {
if(buffer instanceof EaglerLWJGLIntBuffer) {
EaglerLWJGLIntBuffer b = (EaglerLWJGLIntBuffer)buffer;
return b.address + (b.position() << 2);
}else {
throw notEagler(buffer);
}
}
public static void freeFloatBuffer(FloatBuffer buffer) {
if(buffer instanceof EaglerLWJGLFloatBuffer) {
EaglerLWJGLFloatBuffer buf = (EaglerLWJGLFloatBuffer)buffer;
if(buf.original) {
JEmalloc.nje_free(buf.address);
}else {
throwNotOriginal(buffer);
}
}else {
throwNotEagler(buffer);
}
}
public static long getAddress(FloatBuffer buffer) {
if(buffer instanceof EaglerLWJGLFloatBuffer) {
EaglerLWJGLFloatBuffer b = (EaglerLWJGLFloatBuffer)buffer;
return b.address + (b.position() << 2);
}else {
throw notEagler(buffer);
}
}
private static void throwNotOriginal(Object clazz) {
throw notOriginal(clazz);
}
private static WrongBufferClassType notOriginal(Object clazz) {
return new WrongBufferClassType("Tried to pass a " + clazz.getClass().getSimpleName() + " which was not the original buffer");
}
private static void throwNotEagler(Object clazz) {
throw notEagler(clazz);
}
private static WrongBufferClassType notEagler(Object clazz) {
return new WrongBufferClassType("Tried to pass a " + clazz.getClass().getSimpleName() + " which is not a native eagler buffer");
}
}

View File

@ -0,0 +1,378 @@
package net.lax1dude.eaglercraft.internal.buffer;
import net.lax1dude.unsafememcpy.UnsafeMemcpy;
import net.lax1dude.unsafememcpy.UnsafeUtils;
/**
* Copyright (c) 2022-2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerLWJGLByteBuffer implements ByteBuffer {
final long address;
final boolean original;
private final int capacity;
private int position;
private int limit;
private int mark;
EaglerLWJGLByteBuffer(long address, int capacity, boolean original) {
this(address, capacity, 0, capacity, -1, original);
}
EaglerLWJGLByteBuffer(long address, int capacity, int position, int limit, int mark, boolean original) {
this.address = address;
this.capacity = capacity;
this.position = position;
this.limit = limit;
this.mark = mark;
this.original = original;
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return position < limit;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public byte[] array() {
throw new UnsupportedOperationException();
}
@Override
public boolean isDirect() {
return true;
}
@Override
public ByteBuffer duplicate() {
return new EaglerLWJGLByteBuffer(address, capacity, position, limit, mark, false);
}
@Override
public byte get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return UnsafeUtils.getMemByte(address + position++);
}
@Override
public ByteBuffer put(byte b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemByte(address + position++, b);
return this;
}
@Override
public byte get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemByte(address + index);
}
@Override
public ByteBuffer put(int index, byte b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemByte(address + index, b);
return this;
}
@Override
public ByteBuffer get(byte[] dst, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpy(dst, offset, address + position, length);
position += length;
return this;
}
@Override
public ByteBuffer get(byte[] dst) {
if(position + dst.length > limit) throw Buffer.makeIOOBE(position + dst.length - 1);
UnsafeMemcpy.memcpy(dst, 0, address + position, dst.length);
position += dst.length;
return this;
}
@Override
public ByteBuffer put(ByteBuffer src) {
if(src instanceof EaglerLWJGLByteBuffer) {
EaglerLWJGLByteBuffer c = (EaglerLWJGLByteBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
UnsafeMemcpy.memcpy(address + position, c.address + c.position, l);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemByte(address + position + l, src.get());
}
position += l;
}
return this;
}
@Override
public ByteBuffer put(byte[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpy(address + position, src, offset, length);
position += length;
return this;
}
@Override
public ByteBuffer put(byte[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
UnsafeMemcpy.memcpy(address + position, src, 0, src.length);
position += src.length;
return this;
}
@Override
public char getChar() {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
char c = UnsafeUtils.getMemChar(address + position);
position += 2;
return c;
}
@Override
public ByteBuffer putChar(char value) {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemChar(address + position, value);
position += 2;
return this;
}
@Override
public char getChar(int index) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemChar(address + index);
}
@Override
public ByteBuffer putChar(int index, char value) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemChar(address + index, value);
return this;
}
@Override
public short getShort() {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
short s = UnsafeUtils.getMemShort(address + position);
position += 2;
return s;
}
@Override
public ByteBuffer putShort(short value) {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemShort(address + position, value);
position += 2;
return this;
}
@Override
public short getShort(int index) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemShort(address + index);
}
@Override
public ByteBuffer putShort(int index, short value) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemShort(address + index, value);
return this;
}
@Override
public ShortBuffer asShortBuffer() {
return new EaglerLWJGLShortBuffer(address, capacity >> 1, false);
}
@Override
public int getInt() {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
int i = UnsafeUtils.getMemInt(address + position);
position += 4;
return i;
}
@Override
public ByteBuffer putInt(int value) {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemInt(address + position, value);
position += 4;
return this;
}
@Override
public int getInt(int index) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemInt(address + index);
}
@Override
public ByteBuffer putInt(int index, int value) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemInt(address + index, value);
return this;
}
@Override
public IntBuffer asIntBuffer() {
return new EaglerLWJGLIntBuffer(address, capacity >> 2, false);
}
@Override
public long getLong() {
if(position + 8 > limit) throw Buffer.makeIOOBE(position);
long l = UnsafeUtils.getMemLong(address + position);
position += 8;
return l;
}
@Override
public ByteBuffer putLong(long value) {
if(position + 8 > limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemLong(address + position, value);
position += 8;
return this;
}
@Override
public long getLong(int index) {
if(index < 0 || index + 8 > limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemLong(address + index);
}
@Override
public ByteBuffer putLong(int index, long value) {
if(index < 0 || index + 8 > limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemLong(address + index, value);
return this;
}
@Override
public float getFloat() {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
float f = UnsafeUtils.getMemFloat(address + position);
position += 4;
return f;
}
@Override
public ByteBuffer putFloat(float value) {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemFloat(address + position, value);
position += 4;
return this;
}
@Override
public float getFloat(int index) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemFloat(address + index);
}
@Override
public ByteBuffer putFloat(int index, float value) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemFloat(address + index, value);
return this;
}
@Override
public FloatBuffer asFloatBuffer() {
return new EaglerLWJGLFloatBuffer(address, capacity >> 2, false);
}
@Override
public ByteBuffer mark() {
mark = position;
return this;
}
@Override
public ByteBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public ByteBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public ByteBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public ByteBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public ByteBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public ByteBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -0,0 +1,232 @@
package net.lax1dude.eaglercraft.internal.buffer;
import net.lax1dude.unsafememcpy.UnsafeMemcpy;
import net.lax1dude.unsafememcpy.UnsafeUtils;
/**
* Copyright (c) 2022-2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerLWJGLFloatBuffer implements FloatBuffer {
final long address;
final boolean original;
private final int capacity;
private int position;
private int limit;
private int mark;
private static final int SHIFT = 2;
EaglerLWJGLFloatBuffer(long address, int capacity, boolean original) {
this(address, capacity, 0, capacity, -1, original);
}
EaglerLWJGLFloatBuffer(long address, int capacity, int position, int limit, int mark, boolean original) {
this.address = address;
this.capacity = capacity;
this.position = position;
this.limit = limit;
this.mark = mark;
this.original = original;
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return position < limit;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public float[] array() {
throw new UnsupportedOperationException();
}
@Override
public FloatBuffer duplicate() {
return new EaglerLWJGLFloatBuffer(address, capacity, position, limit, mark, false);
}
@Override
public float get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return UnsafeUtils.getMemFloat(address + ((position++) << SHIFT));
}
@Override
public FloatBuffer put(float b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemFloat(address + ((position++) << SHIFT), b);
return this;
}
@Override
public float get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemFloat(address + (index << SHIFT));
}
@Override
public FloatBuffer put(int index, float b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemFloat(address + (index << SHIFT), b);
return this;
}
@Override
public float getElement(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemFloat(address + (index << SHIFT));
}
@Override
public void putElement(int index, float value) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemFloat(address + (index << SHIFT), value);
}
@Override
public FloatBuffer get(float[] dst, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpyAlignDst(dst, offset << SHIFT, address + (position << SHIFT), length);
position += length;
return this;
}
@Override
public FloatBuffer get(float[] dst) {
if(position + dst.length > limit) throw Buffer.makeIOOBE(position + dst.length - 1);
UnsafeMemcpy.memcpyAlignDst(dst, 0, address + (position << SHIFT), dst.length);
position += dst.length;
return this;
}
@Override
public FloatBuffer put(FloatBuffer src) {
if(src instanceof EaglerLWJGLFloatBuffer) {
EaglerLWJGLFloatBuffer c = (EaglerLWJGLFloatBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
UnsafeMemcpy.memcpy(address + (position << SHIFT), c.address + (c.position << SHIFT), l << SHIFT);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemFloat(address + ((position + l) << SHIFT), src.get());
}
position += l;
}
return this;
}
@Override
public FloatBuffer put(float[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpyAlignSrc(address + (position << SHIFT), src, offset << SHIFT, length);
position += length;
return this;
}
@Override
public FloatBuffer put(float[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
UnsafeMemcpy.memcpyAlignSrc(address + (position << SHIFT), src, 0, src.length);
position += src.length;
return this;
}
@Override
public boolean isDirect() {
return true;
}
@Override
public FloatBuffer mark() {
mark = position;
return this;
}
@Override
public FloatBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public FloatBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public FloatBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public FloatBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public FloatBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public FloatBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -0,0 +1,232 @@
package net.lax1dude.eaglercraft.internal.buffer;
import net.lax1dude.unsafememcpy.UnsafeMemcpy;
import net.lax1dude.unsafememcpy.UnsafeUtils;
/**
* Copyright (c) 2022-2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerLWJGLIntBuffer implements IntBuffer {
final long address;
final boolean original;
private final int capacity;
private int position;
private int limit;
private int mark;
private static final int SHIFT = 2;
EaglerLWJGLIntBuffer(long address, int capacity, boolean original) {
this(address, capacity, 0, capacity, -1, original);
}
EaglerLWJGLIntBuffer(long address, int capacity, int position, int limit, int mark, boolean original) {
this.address = address;
this.capacity = capacity;
this.position = position;
this.limit = limit;
this.mark = mark;
this.original = original;
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return position < limit;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public int[] array() {
throw new UnsupportedOperationException();
}
@Override
public IntBuffer duplicate() {
return new EaglerLWJGLIntBuffer(address, capacity, position, limit, mark, false);
}
@Override
public int get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return UnsafeUtils.getMemInt(address + ((position++) << SHIFT));
}
@Override
public IntBuffer put(int b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemInt(address + ((position++) << SHIFT), b);
return this;
}
@Override
public int get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemInt(address + (index << SHIFT));
}
@Override
public IntBuffer put(int index, int b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemInt(address + (index << SHIFT), b);
return this;
}
@Override
public int getElement(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemInt(address + (index << SHIFT));
}
@Override
public void putElement(int index, int value) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemInt(address + (index << SHIFT), value);
}
@Override
public IntBuffer get(int[] dst, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpyAlignDst(dst, offset << SHIFT, address + (position << SHIFT), length);
position += length;
return this;
}
@Override
public IntBuffer get(int[] dst) {
if(position + dst.length > limit) throw Buffer.makeIOOBE(position + dst.length - 1);
UnsafeMemcpy.memcpyAlignDst(dst, 0, address + (position << SHIFT), dst.length);
position += dst.length;
return this;
}
@Override
public IntBuffer put(IntBuffer src) {
if(src instanceof EaglerLWJGLIntBuffer) {
EaglerLWJGLIntBuffer c = (EaglerLWJGLIntBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
UnsafeMemcpy.memcpy(address + (position << SHIFT), c.address + (c.position << SHIFT), l << SHIFT);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemInt(address + ((position + l) << SHIFT), src.get());
}
position += l;
}
return this;
}
@Override
public IntBuffer put(int[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpyAlignSrc(address + (position << SHIFT), src, offset << SHIFT, length);
position += length;
return this;
}
@Override
public IntBuffer put(int[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
UnsafeMemcpy.memcpyAlignSrc(address + (position << SHIFT), src, 0, src.length);
position += src.length;
return this;
}
@Override
public boolean isDirect() {
return true;
}
@Override
public IntBuffer mark() {
mark = position;
return this;
}
@Override
public IntBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public IntBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public IntBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public IntBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public IntBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public IntBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -0,0 +1,232 @@
package net.lax1dude.eaglercraft.internal.buffer;
import net.lax1dude.unsafememcpy.UnsafeMemcpy;
import net.lax1dude.unsafememcpy.UnsafeUtils;
/**
* Copyright (c) 2022-2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerLWJGLShortBuffer implements ShortBuffer {
final long address;
final boolean original;
private final int capacity;
private int position;
private int limit;
private int mark;
private static final int SHIFT = 1;
EaglerLWJGLShortBuffer(long address, int capacity, boolean original) {
this(address, capacity, 0, capacity, -1, original);
}
EaglerLWJGLShortBuffer(long address, int capacity, int position, int limit, int mark, boolean original) {
this.address = address;
this.capacity = capacity;
this.position = position;
this.limit = limit;
this.mark = mark;
this.original = original;
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return position < limit;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public short[] array() {
throw new UnsupportedOperationException();
}
@Override
public ShortBuffer duplicate() {
return new EaglerLWJGLShortBuffer(address, capacity, position, limit, mark, false);
}
@Override
public short get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return UnsafeUtils.getMemShort(address + ((position++) << SHIFT));
}
@Override
public ShortBuffer put(short b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
UnsafeUtils.setMemShort(address + ((position++) << SHIFT), b);
return this;
}
@Override
public short get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemShort(address + (index << SHIFT));
}
@Override
public ShortBuffer put(int index, short b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemShort(address + (index << SHIFT), b);
return this;
}
@Override
public short getElement(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return UnsafeUtils.getMemShort(address + (index << SHIFT));
}
@Override
public void putElement(int index, short value) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
UnsafeUtils.setMemShort(address + (index << SHIFT), value);
}
@Override
public ShortBuffer get(short[] dst, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpyAlignDst(dst, offset << SHIFT, address + (position << SHIFT), length);
position += length;
return this;
}
@Override
public ShortBuffer get(short[] dst) {
if(position + dst.length > limit) throw Buffer.makeIOOBE(position + dst.length - 1);
UnsafeMemcpy.memcpyAlignDst(dst, 0, address + (position << SHIFT), dst.length);
position += dst.length;
return this;
}
@Override
public ShortBuffer put(ShortBuffer src) {
if(src instanceof EaglerLWJGLShortBuffer) {
EaglerLWJGLShortBuffer c = (EaglerLWJGLShortBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
UnsafeMemcpy.memcpy(address + (position << SHIFT), c.address + (c.position << SHIFT), l << SHIFT);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemInt(address + ((position + l) << SHIFT), src.get());
}
position += l;
}
return this;
}
@Override
public ShortBuffer put(short[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
UnsafeMemcpy.memcpyAlignSrc(address + (position << SHIFT), src, offset << SHIFT, length);
position += length;
return this;
}
@Override
public ShortBuffer put(short[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
UnsafeMemcpy.memcpyAlignSrc(address + (position << SHIFT), src, 0, src.length);
position += src.length;
return this;
}
@Override
public boolean isDirect() {
return true;
}
@Override
public ShortBuffer mark() {
mark = position;
return this;
}
@Override
public ShortBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public ShortBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public ShortBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public ShortBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public ShortBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public ShortBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -1,10 +1,10 @@
package net.minecraft.src;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import net.PeytonPlayz585.opengl.GL11;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
public class Tessellator {
private ByteBuffer byteBuffer;

View File

@ -1,270 +0,0 @@
package paulscode.sound;
import java.util.LinkedList;
import javax.sound.sampled.AudioFormat;
/**
* The Channel class is the base class which can be extended for
* library-specific channels. It is also used in the "no-sound" library.
* A channel is a reserved sound-card voice through which sources are played
* back. Channels can be either streaming channels or normal (non-streaming)
* ones. For consistant naming conventions, each sub-class should have the
* name prefix "Channel".
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class Channel
{
/**
* The library class associated with this type of channel.
*/
protected Class libraryType = Library.class;
/**
* Global identifier for the type of channel (normal or streaming). Possible
* values for this varriable can be found in the
* {@link paulscode.sound.SoundSystemConfig SoundSystemConfig} class.
*/
public int channelType;
/**
* Processes status messages, warnings, and error messages.
*/
private SoundSystemLogger logger;
/**
* Whatever source is attached to this channel.
*/
public Source attachedSource = null;
/**
* Cumulative counter of the buffers played then unqued.
*/
public int buffersUnqueued = 0;
/**
* Constructor: Takes channelType identifier as a paramater. Possible values
* for channel type can be found in the
* {@link paulscode.sound.SoundSystemConfig SoundSystemConfig} class.
* @param type Type of channel (normal or streaming).
*/
public Channel( int type )
{
// grab a handle to the message logger:
logger = SoundSystemConfig.getLogger();
channelType = type;
}
/**
* Shuts the channel down and removes references to all instantiated objects.
*/
public void cleanup()
{
logger = null;
}
/**
* Queues up the initial byte[] buffers of data to be streamed.
* @param bufferList List of the first buffers to be played for a streaming source.
* @return False if an error occurred or if end of stream was reached.
*/
public boolean preLoadBuffers( LinkedList<byte[]> bufferList )
{
return true;
}
/**
* Queues up a byte[] buffer of data to be streamed.
* @param buffer The next buffer to be played for a streaming source.
* @return False if an error occurred or if the channel is shutting down.
*/
public boolean queueBuffer( byte[] buffer )
{
return false;
}
/**
* Feeds raw data to the stream.
* @param buffer Buffer containing raw audio data to stream.
* @return Number of prior buffers that have been processed.
*/
public int feedRawAudioData( byte[] buffer )
{
return 1;
}
/**
* Returns the number of queued byte[] buffers that have finished playing.
* @return Number of buffers processed.
*/
public int buffersProcessed()
{
return 0;
}
/**
* Calculates the number of milliseconds since the channel began playing.
* @return Milliseconds, or -1 if unable to calculate.
*/
public float millisecondsPlayed()
{
return -1;
}
/**
* Plays the next queued byte[] buffer. This method is run from the seperate
* {@link paulscode.sound.StreamThread StreamThread}.
* @return False when no more buffers are left to process.
*/
public boolean processBuffer()
{
return false;
}
/**
* Sets the channel up to receive the specified audio format.
*/
public void setAudioFormat( AudioFormat audioFormat )
{}
/**
* Dequeues all previously queued data.
*/
public void flush()
{}
/**
* Stops the channel, dequeues any queued data, and closes the channel.
*/
public void close()
{}
/**
* Plays the currently attached normal source, opens this channel up for
* streaming, or resumes playback if this channel was paused.
*/
public void play()
{}
/**
* Temporarily stops playback for this channel.
*/
public void pause()
{}
/**
* Stops playback for this channel and rewinds the attached source to the
* beginning.
*/
public void stop()
{}
/**
* Rewinds the attached source to the beginning. Stops the source if it was
* paused.
*/
public void rewind()
{}
/**
* Used to determine if a channel is actively playing a source. This method
* will return false if the channel is paused or stopped and when no data is
* queued to be streamed.
* @return True if this channel is playing a source.
*/
public boolean playing()
{
return false;
}
/**
* Returns the name of the class.
* @return "Channel" + library title.
*/
public String getClassName()
{
String libTitle = SoundSystemConfig.getLibraryTitle( libraryType );
if( libTitle.equals( "No Sound" ) )
return "Channel";
else
return "Channel" + libTitle;
}
/**
* Prints a message.
* @param message Message to print.
*/
protected void message( String message )
{
logger.message( message, 0 );
}
/**
* Prints an important message.
* @param message Message to print.
*/
protected void importantMessage( String message )
{
logger.importantMessage( message, 0 );
}
/**
* Prints the specified message if error is true.
* @param error True or False.
* @param message Message to print if error is true.
* @return True if error is true.
*/
protected boolean errorCheck( boolean error, String message )
{
return logger.errorCheck( error, getClassName(), message, 0 );
}
/**
* Prints an error message.
* @param message Message to print.
*/
protected void errorMessage( String message )
{
logger.errorMessage( getClassName(), message, 0 );
}
/**
* Prints an exception's error message followed by the stack trace.
* @param e Exception containing the information to print.
*/
protected void printStackTrace( Exception e )
{
logger.printStackTrace( e, 1 );
}
}

View File

@ -1,603 +0,0 @@
package paulscode.sound;
/**
* The CommandObject class is used to store arguments in the SoundSystem's
* Command Queue. Queued CommandObjects are then processed by the
* {@link paulscode.sound.CommandThread CommandThread}. Commands are queued
* and executed in the background, so it is unlikely that the user will ever
* need to use this class.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class CommandObject
{
/**
* Global identifier for the command to initialize the current sound library.
*/
public static final int INITIALIZE = 1;
/**
* Global identifier for the command to pre-load a sound file.
*/
public static final int LOAD_SOUND = 2;
/**
* Global identifier for the command to pre-load a sound file.
*/
public static final int LOAD_DATA = 3;
/**
* Global identifier for the command to remove a sound file from memory.
*/
public static final int UNLOAD_SOUND = 4;
/**
* Global identifier for the command to queue a sound file.
*/
public static final int QUEUE_SOUND = 5;
/**
* Global identifier for the command to dequeue a sound file.
*/
public static final int DEQUEUE_SOUND = 6;
/**
* Global identifier for the command to fade-out transition a source.
*/
public static final int FADE_OUT = 7;
/**
* Global identifier for the command to fade-out/in transition a source.
*/
public static final int FADE_OUT_IN = 8;
/**
* Global identifier for the command to check volume levels of fading sources.
*/
public static final int CHECK_FADE_VOLUMES = 9;
/**
* Global identifier for the command to create a new source.
*/
public static final int NEW_SOURCE = 10;
/**
* Global identifier for the command to create a new raw data stream.
*/
public static final int RAW_DATA_STREAM = 11;
/**
* Global identifier for the command to create a source and immediately play it.
*/
public static final int QUICK_PLAY = 12;
/**
* Global identifier for the command to set a source's position in 3D space.
*/
public static final int SET_POSITION = 13;
/**
* Global identifier for the command to change a source's volume.
*/
public static final int SET_VOLUME = 14;
/**
* Global identifier for the command to change a source's pitch.
*/
public static final int SET_PITCH = 15;
/**
* Global identifier for the command to change a source's priority.
*/
public static final int SET_PRIORITY = 16;
/**
* Global identifier for the command to tell a source whether or not to loop.
*/
public static final int SET_LOOPING = 17;
/**
* Global identifier for the command to set a source's attenuation model.
*/
public static final int SET_ATTENUATION = 18;
/**
* Global identifier for the command to set a source's fade distance or rolloff
* factor.
*/
public static final int SET_DIST_OR_ROLL = 19;
/**
* Global identifier for the command to change the Doppler factor.
*/
public static final int CHANGE_DOPPLER_FACTOR = 20;
/**
* Global identifier for the command to change the Doppler velocity.
*/
public static final int CHANGE_DOPPLER_VELOCITY = 21;
/**
* Global identifier for the command to set a source's velocity.
*/
public static final int SET_VELOCITY = 22;
/**
* Global identifier for the command to set a source's velocity.
*/
public static final int SET_LISTENER_VELOCITY = 23;
/**
* Global identifier for the command to play a source.
*/
public static final int PLAY = 24;
/**
* Global identifier for the command to play a source.
*/
public static final int FEED_RAW_AUDIO_DATA = 25;
/**
* Global identifier for the command to pause a source.
*/
public static final int PAUSE = 26;
/**
* Global identifier for the command to stop a source.
*/
public static final int STOP = 27;
/**
* Global identifier for the command to rewind a source.
*/
public static final int REWIND = 28;
/**
* Global identifier for the command to flush all queued data.
*/
public static final int FLUSH = 29;
/**
* Global identifier for the command to cull a source.
*/
public static final int CULL = 30;
/**
* Global identifier for the command to activate a source.
*/
public static final int ACTIVATE = 31;
/**
* Global identifier for the command to set a source as permanant or temporary.
*/
public static final int SET_TEMPORARY = 32;
/**
* Global identifier for the command to delete a source.
*/
public static final int REMOVE_SOURCE = 33;
/**
* Global identifier for the command to move the listner.
*/
public static final int MOVE_LISTENER = 34;
/**
* Global identifier for the command to set the listener's position.
*/
public static final int SET_LISTENER_POSITION = 35;
/**
* Global identifier for the command to turn the listener.
*/
public static final int TURN_LISTENER = 36;
/**
* Global identifier for the command to set the listener's turn angle.
*/
public static final int SET_LISTENER_ANGLE = 37;
/**
* Global identifier for the command to change the listener's orientation.
*/
public static final int SET_LISTENER_ORIENTATION = 38;
/**
* Global identifier for the command to change the master volume.
*/
public static final int SET_MASTER_VOLUME = 39;
/**
* Global identifier for the command to create a new library.
*/
public static final int NEW_LIBRARY = 40;
/**
* Any buffer required for a command.
*/
public byte[] buffer;
/**
* Any int arguments required for a command.
*/
public int[] intArgs;
/**
* Any float arguments required for a command.
*/
public float[] floatArgs;
/**
* Any long arguments required for a command.
*/
public long[] longArgs;
/**
* Any boolean arguments required for a command.
*/
public boolean[] boolArgs;
/**
* Any String arguments required for a command.
*/
public String[] stringArgs;
/**
* Any Class arguments required for a command.
*/
public Class[] classArgs;
/**
* Any Object arguments required for a command.
*/
public Object[] objectArgs;
/**
* Which command to execute.
*/
public int Command;
/**
* Constructor used to create a command which doesn't require any arguments.
* @param cmd Which command to execute.
*/
public CommandObject( int cmd )
{
Command = cmd;
}
/**
* Constructor used to create a command which requires one integer argument.
* @param cmd Which command to execute.
* @param i The integer argument needed to execute this command.
*/
public CommandObject( int cmd, int i )
{
Command = cmd;
intArgs = new int[1];
intArgs[0] = i;
}
/**
* Constructor used to create a command which requires one Library Class
* argument.
* @param cmd Which command to execute.
* @param c The Library Class argument needed to execute this command.
*/
public CommandObject( int cmd, Class c )
{
Command = cmd;
classArgs = new Class[1];
classArgs[0] = c;
}
/**
* Constructor used to create a command which requires one float argument.
* @param cmd Which command to execute.
* @param f The float argument needed to execute this command.
*/
public CommandObject( int cmd, float f )
{
Command = cmd;
floatArgs = new float[1];
floatArgs[0] = f;
}
/**
* Constructor used to create a command which requires one String argument.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
*/
public CommandObject( int cmd, String s )
{
Command = cmd;
stringArgs = new String[1];
stringArgs[0] = s;
}
/**
* Constructor used to create a command which requires one Object argument.
* @param cmd Which command to execute.
* @param o The Object argument needed to execute this command.
*/
public CommandObject( int cmd, Object o )
{
Command = cmd;
objectArgs = new Object[1];
objectArgs[0] = o;
}
/**
* Constructor used to create a command which requires one String argument and
* one Object argument.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param o The Object argument needed to execute this command.
*/
public CommandObject( int cmd, String s, Object o )
{
Command = cmd;
stringArgs = new String[1];
stringArgs[0] = s;
objectArgs = new Object[1];
objectArgs[0] = o;
}
/**
* Constructor used to create a command which requires one String argument and
* one byte buffer argument.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param buff The byte buffer argument needed to execute this command.
*/
public CommandObject( int cmd, String s, byte[] buff )
{
Command = cmd;
stringArgs = new String[1];
stringArgs[0] = s;
buffer = buff;
}
/**
* Constructor used to create a command which requires one String argument, one
* Object argument, and one long argument.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param o The Object argument needed to execute this command.
* @param l The long argument needed to execute this command.
*/
public CommandObject( int cmd, String s, Object o, long l )
{
Command = cmd;
stringArgs = new String[1];
stringArgs[0] = s;
objectArgs = new Object[1];
objectArgs[0] = o;
longArgs = new long[1];
longArgs[0] = l;
}
/**
* Constructor used to create a command which requires one String argument, one
* Object argument, and two long arguments.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param o The Object argument needed to execute this command.
* @param l1 The first long argument needed to execute this command.
* @param l2 The second long argument needed to execute this command.
*/
public CommandObject( int cmd, String s, Object o, long l1, long l2 )
{
Command = cmd;
stringArgs = new String[1];
stringArgs[0] = s;
objectArgs = new Object[1];
objectArgs[0] = o;
longArgs = new long[2];
longArgs[0] = l1;
longArgs[1] = l2;
}
/**
* Constructor used to create a command which requires two String arguments.
* @param cmd Which command to execute.
* @param s1 The first String argument needed to execute this command.
* @param s2 The second String argument needed to execute this command.
*/
public CommandObject( int cmd, String s1, String s2 )
{
Command = cmd;
stringArgs = new String[2];
stringArgs[0] = s1;
stringArgs[1] = s2;
}
/**
* Constructor used to create a command which requires a String and an int as
* arguments.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param i The integer argument needed to execute this command.
*/
public CommandObject( int cmd, String s, int i )
{
Command = cmd;
intArgs = new int[1];
stringArgs = new String[1];
intArgs[0] = i;
stringArgs[0] = s;
}
/**
* Constructor used to create a command which requires a String and a float as
* arguments.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param f The float argument needed to execute this command.
*/
public CommandObject( int cmd, String s, float f )
{
Command = cmd;
floatArgs = new float[1];
stringArgs = new String[1];
floatArgs[0] = f;
stringArgs[0] = s;
}
/**
* Constructor used to create a command which requires a String and a boolean
* as arguments.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param b The boolean argument needed to execute this command.
*/
public CommandObject( int cmd, String s, boolean b )
{
Command = cmd;
boolArgs = new boolean[1];
stringArgs = new String[1];
boolArgs[0] = b;
stringArgs[0] = s;
}
/**
* Constructor used to create a command which requires three float arguments.
* @param cmd Which command to execute.
* @param f1 The first float argument needed to execute this command.
* @param f2 The second float argument needed to execute this command.
* @param f3 The third float argument needed to execute this command.
*/
public CommandObject( int cmd, float f1, float f2, float f3 )
{
Command = cmd;
floatArgs = new float[3];
floatArgs[0] = f1;
floatArgs[1] = f2;
floatArgs[2] = f3;
}
/**
* Constructor used to create a command which a String and three float
* arguments.
* @param cmd Which command to execute.
* @param s The String argument needed to execute this command.
* @param f1 The first float argument needed to execute this command.
* @param f2 The second float argument needed to execute this command.
* @param f3 The third float argument needed to execute this command.
*/
public CommandObject( int cmd, String s, float f1, float f2, float f3 )
{
Command = cmd;
floatArgs = new float[3];
stringArgs = new String[1];
floatArgs[0] = f1;
floatArgs[1] = f2;
floatArgs[2] = f3;
stringArgs[0] = s;
}
/**
* Constructor used to create a command which requires six float arguments.
* @param cmd Which command to execute.
* @param f1 The first float argument needed to execute this command.
* @param f2 The second float argument needed to execute this command.
* @param f3 The third float argument needed to execute this command.
* @param f4 The fourth float argument needed to execute this command.
* @param f5 The fifth float argument needed to execute this command.
* @param f6 The sixth float argument needed to execute this command.
*/
public CommandObject( int cmd, float f1, float f2, float f3, float f4,
float f5, float f6 )
{
Command = cmd;
floatArgs = new float[6];
floatArgs[0] = f1;
floatArgs[1] = f2;
floatArgs[2] = f3;
floatArgs[3] = f4;
floatArgs[4] = f5;
floatArgs[5] = f6;
}
/**
* Constructor used to create a command which requires several arguments.
* @param cmd Which command to execute.
* @param b1 The first boolean argument needed to execute this command.
* @param b2 The second boolean argument needed to execute this command.
* @param b3 The third boolean argument needed to execute this command.
* @param s The String argument needed to execute this command.
* @param o The Object argument needed to execute this command.
* @param f1 The first float argument needed to execute this command.
* @param f2 The second float argument needed to execute this command.
* @param f3 The third float argument needed to execute this command.
* @param i The integer argument needed to execute this command.
* @param f4 The fourth float argument needed to execute this command.
*/
public CommandObject( int cmd,
boolean b1, boolean b2, boolean b3,
String s, Object o,
float f1, float f2, float f3,
int i, float f4 )
{
Command = cmd;
intArgs = new int[1];
floatArgs = new float[4];
boolArgs = new boolean[3];
stringArgs = new String[1];
objectArgs = new Object[1];
intArgs[0] = i;
floatArgs[0] = f1;
floatArgs[1] = f2;
floatArgs[2] = f3;
floatArgs[3] = f4;
boolArgs[0] = b1;
boolArgs[1] = b2;
boolArgs[2] = b3;
stringArgs[0] = s;
objectArgs[0] = o;
}
/**
* Constructor used to create a command which requires several arguments.
* @param cmd Which command to execute.
* @param b1 The first boolean argument needed to execute this command.
* @param b2 The second boolean argument needed to execute this command.
* @param b3 The third boolean argument needed to execute this command.
* @param s The String argument needed to execute this command.
* @param o The Object argument needed to execute this command.
* @param f1 The first float argument needed to execute this command.
* @param f2 The second float argument needed to execute this command.
* @param f3 The third float argument needed to execute this command.
* @param i The integer argument needed to execute this command.
* @param f4 The fourth float argument needed to execute this command.
* @param b4 The fourth boolean argument needed to execute this command.
*/
public CommandObject( int cmd,
boolean b1, boolean b2, boolean b3,
String s,
Object o,
float f1, float f2, float f3,
int i, float f4, boolean b4 )
{
Command = cmd;
intArgs = new int[1];
floatArgs = new float[4];
boolArgs = new boolean[4];
stringArgs = new String[1];
objectArgs = new Object[1];
intArgs[0] = i;
floatArgs[0] = f1;
floatArgs[1] = f2;
floatArgs[2] = f3;
floatArgs[3] = f4;
boolArgs[0] = b1;
boolArgs[1] = b2;
boolArgs[2] = b3;
boolArgs[3] = b4;
stringArgs[0] = s;
objectArgs[0] = o;
}
/**
* Constructor used to create a command which requires several arguments.
* @param cmd Which command to execute.
* @param o The Object argument needed to execute this command.
* @param b The first boolean argument needed to execute this command.
* @param s The String argument needed to execute this command.
* @param f1 The first float argument needed to execute this command.
* @param f2 The second float argument needed to execute this command.
* @param f3 The third float argument needed to execute this command.
* @param i The integer argument needed to execute this command.
* @param f4 The fourth float argument needed to execute this command.
*/
public CommandObject( int cmd,
Object o,
boolean b,
String s,
float f1, float f2, float f3,
int i,
float f4 )
{
Command = cmd;
intArgs = new int[1];
floatArgs = new float[4];
boolArgs = new boolean[1];
stringArgs = new String[1];
objectArgs = new Object[1];
intArgs[0] = i;
floatArgs[0] = f1;
floatArgs[1] = f2;
floatArgs[2] = f3;
floatArgs[3] = f4;
boolArgs[0] = b;
stringArgs[0] = s;
objectArgs[0] = o;
}
}

View File

@ -1,176 +0,0 @@
package paulscode.sound;
/**
* The CommandThread class is designed to move all command processing into a
* single thread to be run in the background and avoid conflicts between
* threads. Commands are processed in the order that they were queued. The
* arguements for each command are stored in a
* {@link paulscode.sound.CommandObject CommandObject}. The Command Queue is
* located in the {@link paulscode.sound.SoundSystem SoundSystem} class.
* Calling kill() stops the thread, and this should be immediatly followed
* by a call to interrupt() to wake up the thread so it may end. This class
* also checks for temporary sources that are finished playing, and removes
* them.
*
* NOTE: The command thread is created automatically by the sound system, so it
* is unlikely that the user would ever need to use this class.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class CommandThread extends SimpleThread
{
/**
* Processes status messages, warnings, and error messages.
*/
protected SoundSystemLogger logger;
/**
* Handle to the Sound System. This is where the Command Queue is located.
*/
private SoundSystem soundSystem;
/**
* Name of this class.
*/
protected String className = "CommandThread";
/**
* Constructor: Takes a handle to the SoundSystem object as a parameter.
* @param s Handle to the SoundSystem.
*/
public CommandThread( SoundSystem s )
{
// grab a handle to the message logger:
logger = SoundSystemConfig.getLogger();
soundSystem = s;
}
/**
* Shuts the thread down and removes references to all instantiated objects.
* NOTE: Method alive() will return false when cleanup() has finished.
*/
@Override
protected void cleanup()
{
kill();
logger = null;
soundSystem = null;
super.cleanup(); // Important!
}
/**
* The main loop for processing commands. The Command Thread starts out
* asleep, and it sleeps again after it finishes processing commands, so it
* must be interrupted when commands are queued for processing.
*/
@Override
public void run()
{
long previousTime = System.currentTimeMillis();
long currentTime = previousTime;
if( soundSystem == null )
{
errorMessage( "SoundSystem was null in method run().", 0 );
cleanup();
return;
}
// Start out asleep:
snooze( 3600000 );
while( !dying() )
{
// Perform user-specific source management:
soundSystem.ManageSources();
// Process all queued commands:
soundSystem.CommandQueue( null );
// Remove temporary sources every ten seconds:
currentTime = System.currentTimeMillis();
if( (!dying()) && ((currentTime - previousTime) > 10000) )
{
previousTime = currentTime;
soundSystem.removeTemporarySources();
}
// Wait for more commands:
if( !dying() )
snooze( 3600000 );
}
cleanup(); // Important!
}
/**
* Prints a message.
* @param message Message to print.
*/
protected void message( String message, int indent )
{
logger.message( message, indent );
}
/**
* Prints an important message.
* @param message Message to print.
*/
protected void importantMessage( String message, int indent )
{
logger.importantMessage( message, indent );
}
/**
* Prints the specified message if error is true.
* @param error True or False.
* @param message Message to print if error is true.
* @return True if error is true.
*/
protected boolean errorCheck( boolean error, String message )
{
return logger.errorCheck( error, className, message, 0 );
}
/**
* Prints an error message.
* @param message Message to print.
*/
protected void errorMessage( String message, int indent )
{
logger.errorMessage( className, message, indent );
}
}

View File

@ -1,153 +0,0 @@
package paulscode.sound;
import java.net.URL;
/**
* The FilenameURL class is designed to associate a String filename/identifier
* with a URL. Handles either case where user supplies a String path or user
* supplies a URL instance.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class FilenameURL
{
/**
* Processes status messages, warnings, and error messages.
*/
private SoundSystemLogger logger;
/**
* Filename or identifier for the file.
*/
private String filename = null;
/**
* URL interface to the file.
*/
private URL url = null;
/**
* Constructor: Saves handles to the url and identifier. The identifier should
* look like a filename, and it must have the correct extension so SoundSystem
* knows what format to use for the file referenced by the URL instance.
* @param url URL interface to a file.
* @param identifier Identifier (filename) for the file.
*/
public FilenameURL( URL url, String identifier )
{
// grab a handle to the message logger:
logger = SoundSystemConfig.getLogger();
filename = identifier;
this.url = url;
}
/**
* Constructor: Saves a handle to the filename (used later to generate a URL
* instance). The file may either be located within the
* JAR or at an online location. If the file is online, filename must begin
* with "http://", since that is how SoundSystem recognizes URL names.
* @param filename Name of the file.
*/
public FilenameURL( String filename )
{
// grab a handle to the message logger:
logger = SoundSystemConfig.getLogger();
this.filename = filename;
url = null;
}
/**
* Returns the filename/identifier.
* @return Filename or identifier for the file.
*/
public String getFilename()
{
return filename;
}
/**
* Returns the URL interface to the file. If a URL was not originally specified
* in the constructor, then the first time this method is called it creates a
* URL instance using the previously specified filename.
* @return URL interface to the file.
*/
public URL getURL()
{
if( url == null )
{
// Check if the file is online or inside the JAR:
if( filename.matches( SoundSystemConfig.PREFIX_URL ) )
{
// Online
try
{
url = new URL( filename );
}
catch( Exception e )
{
errorMessage( "Unable to access online URL in " +
"method 'getURL'" );
printStackTrace( e );
return null;
}
}
else
{
// Inside the JAR
url = getClass().getClassLoader().getResource(
SoundSystemConfig.getSoundFilesPackage() + filename );
}
}
return url;
}
/**
* Prints an error message.
* @param message Message to print.
*/
private void errorMessage( String message )
{
logger.errorMessage( "MidiChannel", message, 0 );
}
/**
* Prints an exception's error message followed by the stack trace.
* @param e Exception containing the information to print.
*/
private void printStackTrace( Exception e )
{
logger.printStackTrace( e, 1 );
}
}

View File

@ -1,119 +0,0 @@
package paulscode.sound;
import java.net.URL;
import javax.sound.sampled.AudioFormat;
/**
* The ICodec interface provides a common interface for SoundSystem to use
* for accessing external codec libraries.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public interface ICodec
{
/**
* Should tell derived classes when they may need to reverse the byte order of
* the data before returning it in the read() and readAll() methods. The
* reason for the reversBytOrder method is because some external codec
* libraries produce audio data in a format that some external audio libraries
* require to be reversed. Derivatives of the Library and Source classes for
* audio libraries which require this type of data to be reversed should call
* the reverseByteOrder() method for all instances of ICodec that they use.
* Derivatives of the ICodec interface for codec libraries which which produce
* this type of data should use the reverseByteOrder() method to know when the
* data needs to be reversed before returning it in the read() and readAll()
* methods. If a particular codec library does not produce this type of data,
* its derived ICodec class may disregard any calls to the reverseByteOrder()
* method.
* @param b True if the calling audio library requires byte-reversal by some codec libraries.
*/
public void reverseByteOrder( boolean b );
/**
* Should make any preperations required before reading from the audio stream.
* If another stream is already opened, it should be closed and a new audio
* stream opened in its place. This method is used internally by SoundSystem
* not only to initialize a stream, but also to rewind streams and to switch
* stream sources on the fly.
* @return False if an error occurred or if end of stream was reached.
*/
public boolean initialize( URL url );
/**
* Should return false if the stream is busy initializing. To prevent bad
* data from being returned by this method, derived classes should internally
* synchronize with any elements used by both the initialized() and initialize()
* methods.
* @return True if steam is initialized.
*/
public boolean initialized();
/**
* Should read in one stream buffer worth of audio data. See
* {@link paulscode.sound.SoundSystemConfig SoundSystemConfig} for more
* information about accessing and changing default settings.
* @return The audio data wrapped into a SoundBuffer context.
*/
public SoundBuffer read();
/**
* Should read in all the audio data from the stream (up to the default
* "maximum file size". See
* {@link paulscode.sound.SoundSystemConfig SoundSystemConfig} for more
* information about accessing and changing default settings.
* @return the audio data wrapped into a SoundBuffer context.
*/
public SoundBuffer readAll();
/**
* Should return false if there is still more data available to be read in. To
* prevent bad data from being returned by this method, derived classes should
* internally synchronize with any elements used in both the endOfStream() and
* the read() or readAll() methods.
* @return True if end of stream was reached.
*/
public boolean endOfStream();
/**
* Should close any open streams and remove references to all instantiated
* objects.
*/
public void cleanup();
/**
* Should return the audio format of the data being returned by the read() and
* readAll() methods.
* @return Information wrapped into an AudioFormat context.
*/
public AudioFormat getAudioFormat();
}

View File

@ -1,11 +0,0 @@
package paulscode.sound;
public interface IStreamListener
{
/**
* Notifies implementation that an End Of Stream was reached.
* @param sourcename String identifier of the source which reached the EOS.
* @param queueSize Number of items left the the stream's play queue, or zero if none.
*/
public void endOfStream( String sourcename, int queueSize );
}

File diff suppressed because it is too large Load Diff

View File

@ -1,282 +0,0 @@
package paulscode.sound;
/**
* The listenerData class is used to store information about the
* listener's position and orientation. A ListenerData object can be obtained
* using SoundSystem's getListenerData() method. See
* {@link paulscode.sound.Vector3D Vector3D} for more information about 3D
* coordinates and vectors.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class ListenerData
{
/**
* Listener's position in 3D space
*/
public Vector3D position;
/**
* A normalized vector indicating the direction the listener is facing
*/
public Vector3D lookAt;
/**
* A normalized vector indicating the up direction
*/
public Vector3D up;
/**
* Listener's velocity in world-space
*/
public Vector3D velocity;
/**
* Used for easy rotation along the x/z plane (for use in a first-person
* shooter type of application).
*/
public float angle = 0.0f;
/**
* Constructor: Set this listener data to the origin facing along the z-axis
*/
public ListenerData()
{
position = new Vector3D( 0.0f, 0.0f, 0.0f );
lookAt = new Vector3D( 0.0f, 0.0f, -1.0f );
up = new Vector3D( 0.0f, 1.0f, 0.0f );
velocity = new Vector3D( 0.0f, 0.0f, 0.0f );
angle = 0.0f;
}
/**
* Constructor: Set this listener data to the specified values for position and
* orientation.
* @param pX Listener's X coordinate.
* @param pY Listener's Y coordinate.
* @param pZ Listener's Z coordinate.
* @param lX X element of the look-at direction.
* @param lY Y element of the look-at direction.
* @param lZ Z element of the look-at direction.
* @param uX X element of the up direction.
* @param uY Y element of the up direction.
* @param uZ Z element of the up direction.
* @param a Angle in radians that the listener is turned counterclockwise around the y-axis.
*/
public ListenerData( float pX, float pY, float pZ, float lX, float lY,
float lZ, float uX, float uY, float uZ, float a )
{
position = new Vector3D( pX, pY, pZ );
lookAt = new Vector3D( lX, lY, lZ );
up = new Vector3D( uX, uY, uZ );
velocity = new Vector3D( 0.0f, 0.0f, 0.0f );
angle = a;
}
/**
* Constructor: Set this listener data to the specified values for position and
* orientation.
* @param p Position of the listener in 3D space.
* @param l Normalized vector indicating the direction which the listener is facing.
* @param u Normalized vector indicating the up direction.
* @param a Angle in radians that the listener is turned counterclockwise around the y-axis.
*/
public ListenerData( Vector3D p, Vector3D l, Vector3D u, float a )
{
position = p.clone();
lookAt = l.clone();
up = u.clone();
velocity = new Vector3D( 0.0f, 0.0f, 0.0f );
angle = a;
}
/**
* Change this listener data using the specified coordinates for position and
* orientation.
* @param pX Listener's X coordinate.
* @param pY Listener's Y coordinate.
* @param pZ Listener's Z coordinate.
* @param lX X element of the look-at direction.
* @param lY Y element of the look-at direction.
* @param lZ Z element of the look-at direction.
* @param uX X element of the up direction.
* @param uY Y element of the up direction.
* @param uZ Z element of the up direction.
* @param a Angle in radians that the listener is turned counterclockwise around the y-axis.
*/
public void setData( float pX, float pY, float pZ, float lX, float lY,
float lZ, float uX, float uY, float uZ, float a )
{
position.x = pX;
position.y = pY;
position.z = pZ;
lookAt.x = lX;
lookAt.y = lY;
lookAt.z = lZ;
up.x = uX;
up.y = uY;
up.z = uZ;
angle = a;
}
/**
* Change this listener data using the specified 3D vectors for position and
* orientation.
* @param p Position of the listener in 3D space.
* @param l Normalized vector indicating the direction which the listener is facing.
* @param u Normalized vector indicating the up direction.
* @param a Angle in radians that the listener is turned counterclockwise around the y-axis.
*/
public void setData( Vector3D p, Vector3D l, Vector3D u, float a )
{
position.x = p.x;
position.y = p.y;
position.z = p.z;
lookAt.x = l.x;
lookAt.y = l.y;
lookAt.z = l.z;
up.x = u.x;
up.y = u.y;
up.z = u.z;
angle = a;
}
/**
* Change this listener data to match the specified listener data.
* @param l Listener data to use.
*/
public void setData( ListenerData l )
{
position.x = l.position.x;
position.y = l.position.y;
position.z = l.position.z;
lookAt.x = l.lookAt.x;
lookAt.y = l.lookAt.y;
lookAt.z = l.lookAt.z;
up.x = l.up.x;
up.y = l.up.y;
up.z = l.up.z;
angle = l.angle;
}
/**
* Change this listener's position using the specified coordinates.
* @param x Listener's X coordinate.
* @param y Listener's Y coordinate.
* @param z Listener's Z coordinate.
*/
public void setPosition( float x, float y, float z )
{
position.x = x;
position.y = y;
position.z = z;
}
/**
* Change this listener's position using the specified vector.
* @param p New position.
*/
public void setPosition( Vector3D p )
{
position.x = p.x;
position.y = p.y;
position.z = p.z;
}
/**
* Changes the listeners orientation using the specified coordinates.
* @param lX X element of the look-at direction.
* @param lY Y element of the look-at direction.
* @param lZ Z element of the look-at direction.
* @param uX X element of the up direction.
* @param uY Y element of the up direction.
* @param uZ Z element of the up direction.
*/
public void setOrientation( float lX, float lY, float lZ,
float uX, float uY, float uZ )
{
lookAt.x = lX;
lookAt.y = lY;
lookAt.z = lZ;
up.x = uX;
up.y = uY;
up.z = uZ;
}
/**
* Changes the listeners orientation using the specified vectors.
* @param l Normalized vector representing the look-at direction.
* @param u Normalized vector representing the up direction.
*/
public void setOrientation( Vector3D l, Vector3D u )
{
lookAt.x = l.x;
lookAt.y = l.y;
lookAt.z = l.z;
up.x = u.x;
up.y = u.y;
up.z = u.z;
}
/**
* Change this listener's velocity in world-space.
* @param v New velocity.
*/
public void setVelocity( Vector3D v )
{
velocity.x = v.x;
velocity.y = v.y;
velocity.z = v.z;
}
/**
* Change this listener's velocity in world-space.
* @param x New velocity along world x-axis.
* @param y New velocity along world y-axis.
* @param z New velocity along world z-axis.
*/
public void setVelocity( float x, float y, float z )
{
velocity.x = x;
velocity.y = y;
velocity.z = z;
}
/**
* Sets the listener's angle counterclockwise around the y-axis.
* @param a Angle in radians.
*/
public void setAngle( float a )
{
angle = a;
lookAt.x = -1.0f * (float) Math.sin( angle );
lookAt.z = -1.0f * (float) Math.cos( angle );
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,200 +0,0 @@
package paulscode.sound;
/**
* The SimpleThread class is the template used to create all thread classes
* used by in the SoundSystem library. It provides methods for common actions
* like sleeping, killing, and checking liveness. NOTE: super.cleanup() must
* be called at the bottom of overriden cleanup() methods, and cleanup()
* must be called at the bottom of the run() method for all extended classes.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class SimpleThread extends Thread
{
/**
* Used to return a current value from one of the synchronized
* boolean-interface methods.
*/
private static final boolean GET = false;
/**
* Used to set the value in one of the synchronized boolean-interface methods.
*/
private static final boolean SET = true;
/**
* Used when a parameter for one of the synchronized boolean-interface methods
* is not aplicable.
*/
private static final boolean XXX = false;
/**
* True when thread is running.
*/
private boolean alive = true;
/**
* True when thread should end.
*/
private boolean kill = false;
/**
* Removes all references to instantiated objects, and changes the thread's
* state to "not alive". Method alive() returns false when this method has
* completed. NOTE: super.cleanup() must be called at the bottom of overriden
* cleanup() methods, and cleanup() must be called at the bottom of the run()
* method for all extended classes.
*/
protected void cleanup()
{
kill( SET, true ); // tread needs to shut down
alive( SET, false ); // thread has ended
}
/**
* Executes the thread's main loop. NOTES: Extended classes should check
* method dying() often to know when the user wants the thread to shut down.
* Method cleanup() must be called at the bottom of the run() method for all
* extended classes.
*/
@Override
public void run()
{
/* How the run() method should be set up: */
// Do your stuff here. Remember to check dying() often to know when
// the user wants the thread to shut down.
// MUST call cleanup() at the bottom of Overridden run() method!!!!!
cleanup(); // clears memory and sets status to dead.
}
/**
* Calls the rerun() method on a seperate thread, which calls run() when the
* previous thread finishes.
*/
public void restart()
{
new Thread()
{
@Override
public void run()
{
rerun();
}
}.start();
}
/**
* Kills the previous thread, waits for it to die, then calls run().
*/
private void rerun()
{
kill( SET, true );
while( alive( GET, XXX ) )
{
snooze( 100 );
}
alive( SET, true );
kill( SET, false );
run();
}
/**
* Returns false when the cleanup() method has finished. This method should be
* used to know when the thread has been safely shut down.
* @return True while the thread is alive.
*/
public boolean alive()
{
return alive( GET, XXX );
}
/**
* Causes method dying() to return true, letting the thread know it needs to
* shut down.
*/
public void kill()
{
kill( SET, true );
}
/**
* Returns true when the thread is supposed to shut down.
* @return True if the thread should die.
*/
protected boolean dying()
{
return kill( GET, XXX );
}
/**
* Sets or returns the value of boolean 'alive'.
* @param action GET or SET.
* @param value New value if action == SET, or XXX if action == GET.
* @return True while the thread is alive.
*/
private synchronized boolean alive( boolean action, boolean value )
{
if( action == SET )
alive = value;
return alive;
}
/**
* Sets or returns the value of boolean 'kill'.
* @param action GET or SET.
* @param value New value if action == SET, or XXX if action == GET.
* @return True if the thread should die.
*/
private synchronized boolean kill( boolean action, boolean value )
{
if( action == SET )
kill = value;
return kill;
}
/**
* Sleeps for the specified number of milliseconds.
*/
protected void snooze( long milliseconds )
{
try
{
Thread.sleep( milliseconds );
}
catch( InterruptedException e ){}
}
}

View File

@ -1,91 +0,0 @@
package paulscode.sound;
import javax.sound.sampled.AudioFormat;
/**
* The SoundBuffer class is used to wrap audio data along with the format in
* which the data is stored.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class SoundBuffer
{
/**
* The actual audio data.
*/
public byte[] audioData;
/**
* The audio format in which the data is stored.
*/
public AudioFormat audioFormat;
/**
* Constructor: Wraps the specified data with the specified audio format.
*
* @param audioData The actual audio data.
* @param audioFormat The audio format in which the data is stored.
*/
public SoundBuffer( byte[] audioData, AudioFormat audioFormat )
{
this.audioData = audioData;
this.audioFormat = audioFormat;
}
/**
* Removes handles to all instantiated objects.
*/
public void cleanup()
{
audioData = null;
audioFormat = null;
}
/**
* Trims down the size of the audio data if it is larger than the specified
* maximum length.
*
* @param maxLength Maximum size this buffer may be.
*/
public void trimData( int maxLength )
{
if( audioData == null || maxLength == 0 )
audioData = null;
else if( audioData.length > maxLength )
{
byte[] trimmedArray = new byte[maxLength];
System.arraycopy( audioData, 0, trimmedArray, 0,
maxLength );
audioData = trimmedArray;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,94 +0,0 @@
package paulscode.sound;
/**
* The SoundSystemException class is used to provide information about serious
* errors.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class SoundSystemException extends Exception
{
/**
* Global identifier for no problem.
*/
public static final int ERROR_NONE = 0;
/**
* Global identifier for a generic exception.
*/
public static final int UNKNOWN_ERROR = 1;
/**
* Global identifier for a null parameter.
*/
public static final int NULL_PARAMETER = 2;
/**
* Global identifier for a class type mismatch.
*/
public static final int CLASS_TYPE_MISMATCH = 3;
/**
* Global identifier for the sound library does not exist.
*/
public static final int LIBRARY_NULL = 4;
/**
* Global identifier for the sound library does not exist.
*/
public static final int LIBRARY_TYPE = 5;
/**
* Holds a global identifier indicating the type of exception.
*/
private int myType = UNKNOWN_ERROR;
/**
* Constructor: Generic exception. Specify the error message.
*/
public SoundSystemException( String message )
{
super( message );
}
/**
* Constructor: Specify the error message and type of exception.
* @param message Description of the problem.
* @param type Global identifier for type of exception.
*/
public SoundSystemException( String message, int type )
{
super( message );
myType = type;
}
public int getType()
{
return myType;
}
}

View File

@ -1,173 +0,0 @@
package paulscode.sound;
/**
* The SoundSystemLogger class handles all status messages, warnings, and error
* messages for the SoundSystem library. This class can be extended and
* methods overriden to change how messages are handled. To do this, the
* overridden class should be instantiated, and a call should be made to method
* SoundSystemConfig.setLogger() BEFORE creating the SoundSystem object. If
* the setLogger() method is called after the SoundSystem has been created,
* there will be handles floating around to two different message loggers, and
* the results will be undesirable.
* See {@link paulscode.sound.SoundSystemConfig SoundSystemConfig} for more
* information about changing default settings. If an alternate logger is not
* set by the user, then an instance of this base class will be automatically
* created by default when the SoundSystem class is instantiated.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class SoundSystemLogger
{
/**
* Prints a message.
* @param message Message to print.
* @param indent Number of tabs to indent the message.
*/
public void message( String message, int indent )
{
String messageText;
// Determine how many spaces to indent:
String spacer = "";
for( int x = 0; x < indent; x++ )
{
spacer += " ";
}
// indent the message:
messageText = spacer + message;
// Print the message:
System.out.println( messageText );
}
/**
* Prints an important message.
* @param message Message to print.
* @param indent Number of tabs to indent the message.
*/
public void importantMessage( String message, int indent )
{
String messageText;
// Determine how many spaces to indent:
String spacer = "";
for( int x = 0; x < indent; x++ )
{
spacer += " ";
}
// indent the message:
messageText = spacer + message;
// Print the message:
System.out.println( messageText );
}
/**
* Prints the specified message if error is true.
* @param error True or False.
* @param classname Name of the class checking for an error.
* @param message Message to print if error is true.
* @param indent Number of tabs to indent the message.
* @return True if error is true.
*/
public boolean errorCheck( boolean error, String classname, String message,
int indent )
{
if( error )
errorMessage( classname, message, indent );
return error;
}
/**
* Prints the classname which generated the error, followed by the error
* message.
* @param classname Name of the class which generated the error.
* @param message The actual error message.
* @param indent Number of tabs to indent the message.
*/
public void errorMessage( String classname, String message, int indent )
{
String headerLine, messageText;
// Determine how many spaces to indent:
String spacer = "";
for( int x = 0; x < indent; x++ )
{
spacer += " ";
}
// indent the header:
headerLine = spacer + "Error in class '" + classname + "'";
// indent the message one more than the header:
messageText = " " + spacer + message;
// Print the error message:
System.out.println( headerLine );
System.out.println( messageText );
}
/**
* Prints an exception's error message followed by the stack trace.
* @param e Exception containing the information to print.
* @param indent Number of tabs to indent the message and stack trace.
*/
public void printStackTrace( Exception e, int indent )
{
printExceptionMessage( e, indent );
importantMessage( "STACK TRACE:", indent );
if( e == null )
return;
StackTraceElement[] stack = e.getStackTrace();
if( stack == null )
return;
StackTraceElement line;
for( int x = 0; x < stack.length; x++ )
{
line = stack[x];
if( line != null )
message( line.toString(), indent + 1 );
}
}
/**
* Prints an exception's error message.
* @param e Exception containing the message to print.
* @param indent Number of tabs to indent the message.
*/
public void printExceptionMessage( Exception e, int indent )
{
importantMessage( "ERROR MESSAGE:", indent );
if( e.getMessage() == null )
message( "(none)", indent + 1 );
else
message( e.getMessage(), indent + 1 );
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,303 +0,0 @@
package paulscode.sound;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
/**
* The StreamThread class is used to process all streaming sources. This
* thread starts out asleep, and it sleeps when all streaming sources are
* finished playing, so it is necessary to call interrupt() after adding new
* streaming sources to the list.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*
*/
public class StreamThread extends SimpleThread
{
/**
* Processes status messages, warnings, and error messages.
*/
private SoundSystemLogger logger;
/**
* List of sources that are currently streaming.
*/
private List<Source> streamingSources;
/**
* Used to synchronize access to the streaming sources list.
*/
private final Object listLock = new Object();
/**
* Constructor: Grabs a handle to the message logger and instantiates the
* streaming sources list.
*/
public StreamThread()
{
// grab a handle to the message logger:
logger = SoundSystemConfig.getLogger();
streamingSources = new LinkedList<Source>();
}
/**
* Removes all references to instantiated objects, and changes the thread's
* state to "not alive". Method alive() returns false when the cleanup()
* method has completed.
*/
@Override
protected void cleanup()
{
kill();
super.cleanup(); // Important!!
}
/**
* The main loop for processing commands. The thread sleeps when it finishes
* processing commands, and it must be interrupted to process more.
*/
@Override
public void run()
{
ListIterator<Source> iter;
Source src;
// Start out asleep:
snooze( 3600000 );
while( !dying() )
{
while( !dying() && !streamingSources.isEmpty() )
{
// Make sure noone else is accessing the list of sources:
synchronized( listLock )
{
iter = streamingSources.listIterator();
while( !dying() && iter.hasNext() )
{
src = iter.next();
// If this is a removed source, we cleanup here and then let normal cleanup run - https://github.com/MinecraftForge/MinecraftForge/pull/4765
if (src!=null && src.removed)
{
src.cleanup();
src = null;
}
if( src == null )
{
iter.remove();
}
else if( src.stopped() )
{
if( !src.rawDataStream )
iter.remove();
}
else if( !src.active() )
{
if( src.toLoop || src.rawDataStream )
src.toPlay = true;
iter.remove();
}
else if( !src.paused() )
{
src.checkFadeOut();
if( (!src.stream()) && (!src.rawDataStream) )
{
if( src.channel == null
|| !src.channel.processBuffer() )
{
if( src.nextCodec == null )
{
src.readBuffersFromNextSoundInSequence();
}
/*
if( src.getSoundSequenceQueueSize() > 0 )
{
src.incrementSoundSequence();
}
// check if this is a looping source
else*/ if( src.toLoop )
{
// wait for stream to finish playing
if( !src.playing() )
{
// Generate an EOS event:
SoundSystemConfig.notifyEOS(
src.sourcename,
src.getSoundSequenceQueueSize()
);
// Check if the source is currently
// in the process of fading out.
if( src.checkFadeOut() )
{
// Source is fading out.
// Keep looping until it
// finishes.
src.preLoad = true;
}
else
{
// Source is not fading out.
// If there is another sound in
// the sequence, switch to it
// before replaying.
src.incrementSoundSequence();
src.preLoad = true; // replay
}
}
}
else
{
// wait for stream to finish playing
if( !src.playing() )
{
// Generate an EOS event:
SoundSystemConfig.notifyEOS(
src.sourcename,
src.getSoundSequenceQueueSize()
);
// Check if the source is currently
// in the process of fading out
if( !src.checkFadeOut() )
{
// Source is not fading out.
// Play anything else that is
// in the sound sequence queue.
if(
src.incrementSoundSequence() )
src.preLoad = true;
else
iter.remove(); // finished
}
}
}
}
}
}
}
}
if( !dying() && !streamingSources.isEmpty() )
snooze( 20 ); // sleep a bit so we don't peg the cpu
}
if( !dying() && streamingSources.isEmpty() )
snooze( 3600000 ); // sleep until there is more to do.
}
cleanup(); // Important!!
}
/**
* Adds a new streaming source to the list. If another source in the list is
* already playing on the same channel, it is stopped and removed from the
* list.
* @param source New source to stream.
*/
public void watch( Source source )
{
// make sure the source exists:
if( source == null )
return;
// make sure we aren't already watching this source:
if( streamingSources.contains( source ) )
return;
ListIterator<Source> iter;
Source src;
// Make sure noone else is accessing the list of sources:
synchronized( listLock )
{
// Any currently watched source which is null or playing on the
// same channel as the new source should be stopped and removed
// from the list.
iter = streamingSources.listIterator();
while( iter.hasNext() )
{
src = iter.next();
if( src == null )
{
iter.remove();
}
else if( source.channel == src.channel )
{
src.stop();
iter.remove();
}
}
// Add the new source to the list:
streamingSources.add( source );
}
}
/**
* Prints a message.
* @param message Message to print.
*/
private void message( String message )
{
logger.message( message, 0 );
}
/**
* Prints an important message.
* @param message Message to print.
*/
private void importantMessage( String message )
{
logger.importantMessage( message, 0 );
}
/**
* Prints the specified message if error is true.
* @param error True or False.
* @param message Message to print if error is true.
* @return True if error is true.
*/
private boolean errorCheck( boolean error, String message )
{
return logger.errorCheck( error, "StreamThread", message, 0 );
}
/**
* Prints an error message.
* @param message Message to print.
*/
private void errorMessage( String message )
{
logger.errorMessage( "StreamThread", message, 0 );
}
}

View File

@ -1,210 +0,0 @@
package paulscode.sound;
/**
* The Vector3D class contains methods to simplify common 3D vector functions,
* such as cross and dot product, normalize, etc.
*<br><br>
*<b><i> SoundSystem License:</b></i><br><b><br>
* You are free to use this library for any purpose, commercial or otherwise.
* You may modify this library or source code, and distribute it any way you
* like, provided the following conditions are met:
*<br>
* 1) You may not falsely claim to be the author of this library or any
* unmodified portion of it.
*<br>
* 2) You may not copyright this library or a modified version of it and then
* sue me for copyright infringement.
*<br>
* 3) If you modify the source code, you must clearly document the changes
* made before redistributing the modified source code, so other users know
* it is not the original code.
*<br>
* 4) You are not required to give me credit for this library in any derived
* work, but if you do, you must also mention my website:
* http://www.paulscode.com
*<br>
* 5) I the author will not be responsible for any damages (physical,
* financial, or otherwise) caused by the use if this library or any part
* of it.
*<br>
* 6) I the author do not guarantee, warrant, or make any representations,
* either expressed or implied, regarding the use of this library or any
* part of it.
* <br><br>
* Author: Paul Lamb
* <br>
* http://www.paulscode.com
* </b>
*/
public class Vector3D
{
/**
* The vector's X coordinate.
*/
public float x;
/**
* The vector's Y coordinate.
*/
public float y;
/**
* The vector's Z coordinate.
*/
public float z;
/**
* Constructor: Places the vector at the origin.
*/
public Vector3D()
{
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
/**
* Constructor: Places the vector at the specified 3D coordinates.
* @param nx X coordinate for the new vector.
* @param ny Y coordinate for the new vector.
* @param nz Z coordinate for the new vector.
*/
public Vector3D( float nx, float ny, float nz )
{
x = nx;
y = ny;
z = nz;
}
/**
* Returns a new instance containing the same information as this one.
* @return A new Vector3D.
*/
@Override
public Vector3D clone()
{
return new Vector3D( x, y, z );
}
/**
* Returns a vector containing the cross-product: A cross B.
* @param A First vector in the cross product.
* @param B Second vector in the cross product.
* @return A new Vector3D.
*/
public Vector3D cross( Vector3D A, Vector3D B )
{
return new Vector3D(
A.y * B.z - B.y * A.z,
A.z * B.x - B.z * A.x,
A.x * B.y - B.x * A.y );
}
/**
* Returns a vector containing the cross-product: (this) cross B.
* @param B Second vector in the cross product.
* @return A new Vector3D.
*/
public Vector3D cross( Vector3D B )
{
return new Vector3D(
y * B.z - B.y * z,
z * B.x - B.z * x,
x * B.y - B.x * y );
}
/**
* Returns the dot-product result of: A dot B.
* @param A First vector in the dot product.
* @param B Second vector in the dot product.
* @return Dot product.
*/
public float dot( Vector3D A, Vector3D B )
{
return( (A.x * B.x) + (A.y * B.y) + (A.z * B.z) );
}
/**
* Returns the dot-product result of: (this) dot B.
* @param B Second vector in the dot product.
* @return Dot product.
*/
public float dot( Vector3D B )
{
return( (x * B.x) + (y * B.y) + (z * B.z) );
}
/**
* Returns the vector represented by: A + B.
* @param A First vector.
* @param B Vector to add to A.
* @return A new Vector3D.
*/
public Vector3D add( Vector3D A, Vector3D B )
{
return new Vector3D( A.x + B.x, A.y + B.y, A.z + B.z );
}
/**
* Returns the vector represented by: (this) + B.
* @param B Vector to add to this one.
* @return A new Vector3D.
*/
public Vector3D add( Vector3D B )
{
return new Vector3D( x + B.x, y + B.y, z + B.z );
}
/**
* Returns the vector represented by: A - B.
* @param A First vector.
* @param B Vector to subtract from A.
* @return A new Vector3D.
*/
public Vector3D subtract( Vector3D A, Vector3D B )
{
return new Vector3D( A.x - B.x, A.y - B.y, A.z - B.z );
}
/**
* Returns the vector represented by: (this) - B.
* @param B Vector to subtract from this one.
* @return A new Vector3D.
*/
public Vector3D subtract( Vector3D B )
{
return new Vector3D( x - B.x, y - B.y, z - B.z );
}
/**
* Returns the length of this vector.
* @return Length.
*/
public float length()
{
return (float) Math.sqrt( x * x + y * y + z * z );
}
/**
* Changes the length of this vector to 1.0.
*/
public void normalize()
{
double t = Math.sqrt( x*x + y*y + z*z );
x = (float) (x / t);
y = (float) (y / t);
z = (float) (z / t);
}
/**
* Returns a string depicting this vector.
* @return "Vector3D (x, y, z)".
*/
@Override
public String toString()
{
return "Vector3D (" + x + ", " + y + ", " + z + ")";
}
}

View File

@ -107,7 +107,7 @@ public class FixedFunctionShader {
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 stateEnableFog;
private final boolean enable_alphatest;
private final boolean enable_unit0;
private final boolean enable_unit1;
@ -119,12 +119,17 @@ public class FixedFunctionShader {
private UniformGL u_matrix_p = null;
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_fogParam = null;
private final UniformGL stateFogParamUniform4f;
private boolean stateFogEXP = false;
private float stateFogDensity = -999.0f;
private float stateFogStart = -999.0f;
private float stateFogEnd = -999.0f;
private final UniformGL stateFogColorUniform4f;
private float stateFogColorR = -999.0f;
private float stateFogColorG = -999.0f;
private float stateFogColorB = -999.0f;
private float stateFogColorA = -999.0f;
private int stateFogSerial = -1;
private UniformGL u_colorUniform = null;
private UniformGL u_normalUniform = null;
@ -169,7 +174,7 @@ public class FixedFunctionShader {
enable_texture1 = CC_a_texture1;
enable_TEX_GEN_STRQ = CC_TEX_GEN_STRQ;
enable_lighting = CC_lighting;
enable_fog = CC_fog;
stateEnableFog = CC_fog;
enable_alphatest = CC_alphatest;
enable_unit0 = CC_unit0;
enable_unit1 = CC_unit1;
@ -187,7 +192,7 @@ public class FixedFunctionShader {
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(stateEnableFog) 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";
@ -275,14 +280,21 @@ public class FixedFunctionShader {
u_light1Pos = _wglGetUniformLocation(globject, "light1Pos");
}
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_fogParam = _wglGetUniformLocation(globject, "fogParam");
}
//if(stateEnableFog) {
stateFogParamUniform4f = stateEnableFog ? _wglGetUniformLocation(globject,
"fogParam") : null;
stateFogColorUniform4f = stateEnableFog ? _wglGetUniformLocation(globject,
"fogColor") : null;
//}
// 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_fogParam = _wglGetUniformLocation(globject, "fogParam");
// }
if(enable_alphatest) {
u_alphaTestF = _wglGetUniformLocation(globject, "alphaTestF");
@ -559,33 +571,63 @@ public class FixedFunctionShader {
_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);
// 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);
// }
// }
if(stateEnableFog) {
int serial = GL11.stateFogSerial;
if(stateFogSerial != serial) {
stateFogSerial = serial;
boolean fogEXP = GL11.stateFogEXP;
float fogDensity = GL11.stateFogDensity;
float fogStart = GL11.stateFogStart;
float fogEnd = GL11.stateFogEnd;
if(stateFogEXP != fogEXP || stateFogDensity != fogDensity ||
stateFogStart != fogStart || stateFogEnd != fogEnd) {
stateFogEXP = fogEXP;
stateFogDensity = fogDensity;
stateFogStart = fogStart;
stateFogEnd = fogEnd;
_wglUniform4f(stateFogParamUniform4f, fogEXP ? 1.0f : 0.0f, fogDensity, fogStart, fogEnd);
}
float r = GL11.stateFogColorR;
float g = GL11.stateFogColorG;
float b = GL11.stateFogColorB;
float a = GL11.stateFogColorA;
if(stateFogColorR != r || stateFogColorG != g ||
stateFogColorB != b || stateFogColorA != a) {
stateFogColorR = r;
stateFogColorG = g;
stateFogColorB = b;
stateFogColorA = a;
_wglUniform4f(stateFogColorUniform4f, r, g, b, a);
}
}
}
float limit = GL11.alphaThresh;

View File

@ -3,49 +3,67 @@ package net.PeytonPlayz585.glemu;
import static net.PeytonPlayz585.opengl.GL11.*;
import static net.PeytonPlayz585.opengl.GL11.EaglerAdapterImpl2.*;
import java.nio.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
public class GameOverlayFramebuffer {
private static final int _GL_FRAMEBUFFER = 0x8D40;
private static final int _GL_RENDERBUFFER = 0x8D41;
private static final int _GL_COLOR_ATTACHMENT0 = 0x8CE0;
private static final int _GL_DEPTH_ATTACHMENT = 0x8D00;
private static final int _GL_DEPTH_COMPONENT16 = 0x81A5;
private long age = -1l;
private int currentWidth = -1;
private int currentHeight = -1;
private FramebufferGL framebuffer = null;
private TextureGL framebufferColor = null;
private RenderbufferGL depthBuffer = null;
private int framebufferColor = -1;
private final boolean enableDepth = true;
public GameOverlayFramebuffer() {
}
public void beginRender(int width, int height) {
if(framebuffer == null) {
framebuffer = _wglCreateFramebuffer();
depthBuffer = _wglCreateRenderBuffer();
framebufferColor = _wglGenTextures();
_wglBindFramebuffer(_wGL_FRAMEBUFFER, framebuffer);
glBindTexture(_wGL_TEXTURE_2D, framebufferColor);
depthBuffer = enableDepth ? _wglCreateRenderBuffer() : null;
framebufferColor = glGenTextures();
_wglBindFramebuffer(_GL_FRAMEBUFFER, framebuffer);
glBindTexture(framebufferColor);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
_wglFramebufferTexture2D(_wGL_COLOR_ATTACHMENT0, framebufferColor, 0);
_wglBindRenderbuffer(depthBuffer);
_wglFramebufferRenderbuffer(_wGL_DEPTH_ATTACHMENT, depthBuffer);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
_wglFramebufferTexture2D(_GL_FRAMEBUFFER, _GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glGetTextures(framebufferColor), 0);
if(enableDepth) {
_wglBindRenderbuffer(_GL_RENDERBUFFER, depthBuffer);
_wglFramebufferRenderbuffer(_GL_FRAMEBUFFER, _GL_DEPTH_ATTACHMENT, _GL_RENDERBUFFER, depthBuffer);
}
}
if(currentWidth != width || currentHeight != height) {
boolean resized = currentWidth != width || currentHeight != height;
if(resized) {
currentWidth = width;
currentHeight = height;
glBindTexture(_wGL_TEXTURE_2D, framebufferColor);
_wglTexImage2D(_wGL_TEXTURE_2D, 0, _wGL_RGBA8, width, height, 0, _wGL_RGBA, _wGL_UNSIGNED_BYTE, (ByteBuffer)null);
_wglBindRenderbuffer(depthBuffer);
_wglRenderbufferStorage(0x81A5, width, height);
glBindTexture(framebufferColor);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer)null);
if(enableDepth) {
_wglBindRenderbuffer(_GL_RENDERBUFFER, depthBuffer);
_wglRenderbufferStorage(_GL_RENDERBUFFER, _GL_DEPTH_COMPONENT16, width, height);
}
}
_wglBindFramebuffer(_wGL_FRAMEBUFFER, framebuffer);
_wglBindFramebuffer(_GL_FRAMEBUFFER, framebuffer);
}
public void endRender() {
_wglBindFramebuffer(_wGL_FRAMEBUFFER, null);
_wglBindFramebuffer(_GL_FRAMEBUFFER, null);
age = System.currentTimeMillis();
}
@ -53,20 +71,22 @@ public class GameOverlayFramebuffer {
return age == -1l ? -1l : (System.currentTimeMillis() - age);
}
public void bindTexture() {
glBindTexture(_wGL_TEXTURE_2D, framebufferColor);
public int getTexture() {
return framebufferColor;
}
public void destroy() {
if(framebuffer != null) {
_wglDeleteFramebuffer(framebuffer);
_wglDeleteRenderbuffer(depthBuffer);
_wglDeleteTextures(framebufferColor);
if(enableDepth) {
_wglDeleteRenderbuffer(depthBuffer);
}
glDeleteTextures(framebufferColor);
framebuffer = null;
depthBuffer = null;
framebufferColor = null;
framebufferColor = -1;
age = -1l;
_wglBindFramebuffer(_wGL_FRAMEBUFFER, null);
_wglBindFramebuffer(_GL_FRAMEBUFFER, null);
}
}

View File

@ -61,7 +61,7 @@ public class StreamBuffer {
if(next.vertexBufferSize < requiredMemory) {
int newSize = (requiredMemory & 0xFFFFF000) + 0x2000;
_wglBindBuffer(_wGL_ARRAY_BUFFER, next.vertexBuffer);
_wglBufferData00(_wGL_ARRAY_BUFFER, newSize, _wGL_STREAM_DRAW);
_wglBufferData(_wGL_ARRAY_BUFFER, newSize, _wGL_STREAM_DRAW);
next.vertexBufferSize = newSize;
}
return next;

View File

@ -1,31 +1,134 @@
/*
* 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.util.vector;
import java.io.Serializable;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.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();
}

View File

@ -1,13 +1,54 @@
/*
* 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.util.vector;
import java.io.Serializable;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
/**
* Holds a 4x4 float matrix.
*
* @author foo
*/
public class Matrix4f extends Matrix implements Serializable {
private static final long serialVersionUID = 1L;
public float m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33;
/**
* Construct a new matrix, initialized to the identity.
*/
public Matrix4f() {
super();
setIdentity();
@ -18,6 +59,9 @@ public class Matrix4f extends Matrix implements Serializable {
load(src);
}
/**
* 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(m30).append('\n');
@ -27,10 +71,19 @@ public class Matrix4f extends Matrix implements Serializable {
return buf.toString();
}
/**
* Set this matrix to be the identity matrix.
* @return this
*/
public Matrix setIdentity() {
return setIdentity(this);
}
/**
* Set the given matrix to be the identity matrix.
* @param m The matrix to set to the identity
* @return m
*/
public static Matrix4f setIdentity(Matrix4f m) {
m.m00 = 1.0f;
m.m01 = 0.0f;
@ -52,10 +105,19 @@ public class Matrix4f extends Matrix implements Serializable {
return m;
}
/**
* Set this matrix to 0.
* @return this
*/
public Matrix setZero() {
return setZero(this);
}
/**
* Set the given matrix to 0.
* @param m The matrix to set to 0
* @return m
*/
public static Matrix4f setZero(Matrix4f m) {
m.m00 = 0.0f;
m.m01 = 0.0f;
@ -77,10 +139,21 @@ public class Matrix4f extends Matrix implements Serializable {
return m;
}
/**
* Load from another matrix4f
* @param src The source matrix
* @return this
*/
public Matrix4f load(Matrix4f 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 of a new one is to be created
* @return The copied matrix
*/
public static Matrix4f load(Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -104,6 +177,13 @@ public class Matrix4f extends Matrix implements Serializable {
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();
@ -126,6 +206,42 @@ public class Matrix4f extends Matrix implements Serializable {
return this;
}
/**
* Load from a float buffer. The buffer stores the matrix in column major
* (OpenGL) order.
*
* @param buf A float array to read from
* @return this
*/
public Matrix load(float[] buf) {
m00 = buf[0];
m01 = buf[1];
m02 = buf[2];
m03 = buf[3];
m10 = buf[4];
m11 = buf[5];
m12 = buf[6];
m13 = buf[7];
m20 = buf[8];
m21 = buf[9];
m22 = buf[10];
m23 = buf[11];
m30 = buf[12];
m31 = buf[13];
m32 = buf[14];
m33 = buf[15];
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();
@ -148,6 +264,11 @@ public class Matrix4f extends Matrix implements Serializable {
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);
@ -167,6 +288,29 @@ public class Matrix4f extends Matrix implements Serializable {
buf.put(m33);
return this;
}
/**
* eagler
*/
public Matrix store(ByteBuffer buf) {
buf.putFloat(m00);
buf.putFloat(m01);
buf.putFloat(m02);
buf.putFloat(m03);
buf.putFloat(m10);
buf.putFloat(m11);
buf.putFloat(m12);
buf.putFloat(m13);
buf.putFloat(m20);
buf.putFloat(m21);
buf.putFloat(m22);
buf.putFloat(m23);
buf.putFloat(m30);
buf.putFloat(m31);
buf.putFloat(m32);
buf.putFloat(m33);
return this;
}
public Matrix store(float[] buf) {
buf[0] = m00;
@ -188,6 +332,11 @@ public class Matrix4f extends Matrix implements Serializable {
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);
@ -208,6 +357,11 @@ public class Matrix4f extends Matrix implements Serializable {
return this;
}
/**
* Store the rotation portion of 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 store3f(FloatBuffer buf) {
buf.put(m00);
buf.put(m01);
@ -221,6 +375,13 @@ public class Matrix4f extends Matrix implements Serializable {
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 Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -245,6 +406,13 @@ public class Matrix4f extends Matrix implements Serializable {
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 Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -269,6 +437,13 @@ public class Matrix4f extends Matrix implements Serializable {
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 Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -310,6 +485,14 @@ public class Matrix4f extends Matrix implements Serializable {
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 Vector4f transform(Matrix4f left, Vector4f right, Vector4f dest) {
if (dest == null)
dest = new Vector4f();
@ -327,22 +510,48 @@ public class Matrix4f extends Matrix implements Serializable {
return dest;
}
/**
* Transpose this matrix
* @return this
*/
public Matrix transpose() {
return transpose(this);
}
/**
* Translate this matrix
* @param vec The vector to translate by
* @return this
*/
public Matrix4f translate(Vector2f vec) {
return translate(vec, this);
}
/**
* Translate this matrix
* @param vec The vector to translate by
* @return this
*/
public Matrix4f translate(Vector3f vec) {
return translate(vec, this);
}
/**
* Scales this matrix
* @param vec The vector to scale by
* @return this
*/
public Matrix4f scale(Vector3f vec) {
return scale(vec, this, this);
}
/**
* Scales the source matrix and put the result in the destination matrix
* @param vec The vector to scale by
* @param src The source matrix
* @param dest The destination matrix, or null if a new matrix is to be created
* @return The scaled matrix
*/
public static Matrix4f scale(Vector3f vec, Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -361,14 +570,36 @@ public class Matrix4f extends Matrix implements Serializable {
return dest;
}
/**
* Rotates the matrix around the given axis the specified angle
* @param angle the angle, in radians.
* @param axis The vector representing the rotation axis. Must be normalized.
* @return this
*/
public Matrix4f rotate(float angle, Vector3f axis) {
return rotate(angle, axis, this);
}
/**
* Rotates the matrix around the given axis the specified angle
* @param angle the angle, in radians.
* @param axis The vector representing the rotation axis. Must be normalized.
* @param dest The matrix to put the result, or null if a new matrix is to be created
* @return The rotated matrix
*/
public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) {
return rotate(angle, axis, this, dest);
}
/**
* Rotates the source matrix around the given axis the specified angle and
* put the result in the destination matrix.
* @param angle the angle, in radians.
* @param axis The vector representing the rotation axis. Must be normalized.
* @param src The matrix to rotate
* @param dest The matrix to put the result, or null if a new matrix is to be created
* @return The rotated matrix
*/
public static Matrix4f rotate(float angle, Vector3f axis, Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -385,9 +616,11 @@ public class Matrix4f extends Matrix implements Serializable {
float f00 = axis.x*axis.x*oneminusc+c;
float f01 = xy*oneminusc+zs;
float f02 = xz*oneminusc-ys;
// n[3] not used
float f10 = xy*oneminusc-zs;
float f11 = axis.y*axis.y*oneminusc+c;
float f12 = yz*oneminusc+xs;
// n[7] not used
float f20 = xz*oneminusc+ys;
float f21 = yz*oneminusc-xs;
float f22 = axis.z*axis.z*oneminusc+c;
@ -415,10 +648,23 @@ public class Matrix4f extends Matrix implements Serializable {
return dest;
}
/**
* Translate this matrix and stash the result in another matrix
* @param vec The vector to translate by
* @param dest The destination matrix or null if a new matrix is to be created
* @return the translated matrix
*/
public Matrix4f translate(Vector3f vec, Matrix4f dest) {
return translate(vec, this, dest);
}
/**
* Translate the source matrix and stash the result in the destination matrix
* @param vec The vector to translate by
* @param src The source matrix
* @param dest The destination matrix or null if a new matrix is to be created
* @return The translated matrix
*/
public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -431,10 +677,23 @@ public class Matrix4f extends Matrix implements Serializable {
return dest;
}
/**
* Translate this matrix and stash the result in another matrix
* @param vec The vector to translate by
* @param dest The destination matrix or null if a new matrix is to be created
* @return the translated matrix
*/
public Matrix4f translate(Vector2f vec, Matrix4f dest) {
return translate(vec, this, dest);
}
/**
* Translate the source matrix and stash the result in the destination matrix
* @param vec The vector to translate by
* @param src The source matrix
* @param dest The destination matrix or null if a new matrix is to be created
* @return The translated matrix
*/
public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -447,10 +706,21 @@ public class Matrix4f extends Matrix implements Serializable {
return dest;
}
/**
* 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 Matrix4f transpose(Matrix4f dest) {
return transpose(this, dest);
}
/**
* Transpose 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 transposed matrix
*/
public static Matrix4f transpose(Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -491,6 +761,9 @@ public class Matrix4f extends Matrix implements Serializable {
return dest;
}
/**
* @return the determinant of the matrix
*/
public float determinant() {
float f =
m00
@ -516,6 +789,11 @@ public class Matrix4f extends Matrix implements Serializable {
return f;
}
/**
* Calculate the determinant of a 3x3 matrix
* @return result
*/
private static float determinant3x3(float t00, float t01, float t02,
float t10, float t11, float t12,
float t20, float t21, float t22)
@ -525,34 +803,56 @@ public class Matrix4f extends Matrix implements Serializable {
+ t02 * (t10 * t21 - t11 * t20);
}
/**
* Invert this matrix
* @return this if successful, null otherwise
*/
public Matrix invert() {
return invert(this, this);
}
/**
* Invert the source matrix and put the result in the destination
* @param src The source matrix
* @param dest The destination matrix, or null if a new matrix is to be created
* @return The inverted matrix if successful, null otherwise
*/
public static Matrix4f invert(Matrix4f src, Matrix4f dest) {
float determinant = src.determinant();
if (determinant != 0) {
/*
* m00 m01 m02 m03
* m10 m11 m12 m13
* m20 m21 m22 m23
* m30 m31 m32 m33
*/
if (dest == null)
dest = new Matrix4f();
float determinant_inv = 1f/determinant;
// first row
float t00 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33);
float t01 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33);
float t02 = determinant3x3(src.m10, src.m11, src.m13, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33);
float t03 = -determinant3x3(src.m10, src.m11, src.m12, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32);
// second row
float t10 = -determinant3x3(src.m01, src.m02, src.m03, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33);
float t11 = determinant3x3(src.m00, src.m02, src.m03, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33);
float t12 = -determinant3x3(src.m00, src.m01, src.m03, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33);
float t13 = determinant3x3(src.m00, src.m01, src.m02, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32);
// third row
float t20 = determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m31, src.m32, src.m33);
float t21 = -determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m30, src.m32, src.m33);
float t22 = determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m30, src.m31, src.m33);
float t23 = -determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m30, src.m31, src.m32);
// fourth row
float t30 = -determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m21, src.m22, src.m23);
float t31 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23);
float t32 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, src.m23);
float t33 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22);
// transpose and divide by the determinant
dest.m00 = t00*determinant_inv;
dest.m11 = t11*determinant_inv;
dest.m22 = t22*determinant_inv;
@ -574,14 +874,29 @@ public class Matrix4f extends Matrix implements Serializable {
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 Matrix4f negate(Matrix4f dest) {
return negate(this, dest);
}
/**
* Negate this matrix and place the result in a 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 Matrix4f negate(Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
@ -605,4 +920,27 @@ public class Matrix4f extends Matrix implements Serializable {
return dest;
}
public boolean equals(Object m) {
return (m instanceof Matrix4f) && equal(this, (Matrix4f)m);
}
public static boolean equal(Matrix4f a, Matrix4f b) {
return a.m00 == b.m00 &&
a.m01 == b.m01 &&
a.m02 == b.m02 &&
a.m03 == b.m03 &&
a.m10 == b.m10 &&
a.m11 == b.m11 &&
a.m12 == b.m12 &&
a.m13 == b.m13 &&
a.m20 == b.m20 &&
a.m21 == b.m21 &&
a.m22 == b.m22 &&
a.m23 == b.m23 &&
a.m30 == b.m30 &&
a.m31 == b.m31 &&
a.m32 == b.m32 &&
a.m33 == b.m33;
}
}

View File

@ -1,9 +1,54 @@
/*
* 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.util.vector;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.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);
}

View File

@ -1,24 +1,87 @@
/*
* 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.util.vector;
import java.io.Serializable;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.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) {
@ -28,8 +91,20 @@ public abstract class Vector implements Serializable, ReadableVector {
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);

View File

@ -1,7 +1,47 @@
/*
* 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.util.vector;
import java.io.Serializable;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.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 {
@ -9,45 +49,80 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
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();
@ -56,6 +131,12 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
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();
@ -67,10 +148,25 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
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)
@ -80,6 +176,14 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
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);
@ -89,6 +193,14 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
}
}
/**
* 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);
@ -98,18 +210,31 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
}
}
/**
* 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;
@ -118,6 +243,9 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
return this;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuilder sb = new StringBuilder(64);
@ -129,18 +257,32 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
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;
}

View File

@ -1,7 +1,47 @@
/*
* 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.util.vector;
import java.io.Serializable;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.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 {
@ -9,29 +49,49 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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();
@ -39,10 +99,19 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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;
@ -50,6 +119,14 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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);
@ -59,6 +136,14 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
}
}
/**
* 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);
@ -68,6 +153,14 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
}
}
/**
* 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,
@ -86,6 +179,12 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
return dest;
}
/**
* Negate a vector
* @return this
*/
public Vector negate() {
x = -x;
y = -y;
@ -93,6 +192,11 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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();
@ -102,6 +206,12 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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();
@ -113,10 +223,23 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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)
@ -126,6 +249,9 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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();
@ -133,6 +259,9 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
return this;
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#scale(float)
*/
public Vector scale(float scale) {
x *= scale;
@ -143,6 +272,9 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
*/
public Vector store(FloatBuffer buf) {
buf.put(x);
@ -152,6 +284,9 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
return this;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuilder sb = new StringBuilder(64);
@ -165,26 +300,47 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
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;
}

View File

@ -1,7 +1,47 @@
/*
* 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.util.vector;
import java.io.Serializable;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.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 {
@ -9,29 +49,47 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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;
@ -39,6 +97,11 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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();
@ -47,10 +110,19 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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;
@ -59,6 +131,14 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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);
@ -68,6 +148,14 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
}
}
/**
* 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);
@ -77,6 +165,11 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
}
}
/**
* Negate a vector
* @return this
*/
public Vector negate() {
x = -x;
y = -y;
@ -85,6 +178,11 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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();
@ -95,6 +193,12 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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();
@ -106,10 +210,23 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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)
@ -119,6 +236,9 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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();
@ -127,6 +247,9 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
return this;
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#scale(float)
*/
public Vector scale(float scale) {
x *= scale;
y *= scale;
@ -135,6 +258,9 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
return this;
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
*/
public Vector store(FloatBuffer buf) {
buf.put(x);
@ -149,34 +275,63 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
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;
}

View File

@ -1,11 +1,11 @@
package net.lax1dude.eaglercraft;
import java.nio.IntBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import net.PeytonPlayz585.awt.image.BufferedImage;
import net.PeytonPlayz585.opengl.GL11;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
import net.minecraft.src.GLAllocation;
public class SpriteSheetTexture {

View File

@ -0,0 +1,54 @@
package net.lax1dude.eaglercraft.internal.buffer;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public interface Buffer {
int capacity();
int position();
Buffer position(int newPosition);
int limit();
Buffer limit(int newLimit);
Buffer mark();
Buffer reset();
Buffer clear();
Buffer flip();
Buffer rewind();
int remaining();
boolean hasRemaining();
boolean hasArray();
Object array();
boolean isDirect();
static IndexOutOfBoundsException makeIOOBE(int idx) {
return new IndexOutOfBoundsException("Index out of range: " + idx);
}
}

View File

@ -0,0 +1,103 @@
package net.lax1dude.eaglercraft.internal.buffer;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public interface ByteBuffer extends Buffer {
ByteBuffer duplicate();
byte get();
ByteBuffer put(byte b);
byte get(int index);
ByteBuffer put(int index, byte b);
ByteBuffer get(byte[] dst, int offset, int length);
ByteBuffer get(byte[] dst);
ByteBuffer put(ByteBuffer src);
ByteBuffer put(byte[] src, int offset, int length);
ByteBuffer put(byte[] src);
char getChar();
ByteBuffer putChar(char value);
char getChar(int index);
ByteBuffer putChar(int index, char value);
short getShort();
ByteBuffer putShort(short value);
short getShort(int index);
ByteBuffer putShort(int index, short value);
ShortBuffer asShortBuffer();
int getInt();
ByteBuffer putInt(int value);
int getInt(int index);
ByteBuffer putInt(int index, int value);
IntBuffer asIntBuffer();
long getLong();
ByteBuffer putLong(long value);
long getLong(int index);
ByteBuffer putLong(int index, long value);
float getFloat();
ByteBuffer putFloat(float value);
float getFloat(int index);
ByteBuffer putFloat(int index, float value);
FloatBuffer asFloatBuffer();
ByteBuffer mark();
ByteBuffer reset();
ByteBuffer clear();
ByteBuffer flip();
ByteBuffer rewind();
ByteBuffer limit(int newLimit);
ByteBuffer position(int newPosition);
byte[] array();
}

View File

@ -0,0 +1,62 @@
package net.lax1dude.eaglercraft.internal.buffer;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public interface FloatBuffer extends Buffer {
FloatBuffer duplicate();
float get();
FloatBuffer put(float b);
float get(int index);
FloatBuffer put(int index, float b);
float getElement(int index);
void putElement(int index, float value);
FloatBuffer get(float[] dst, int offset, int length);
FloatBuffer get(float[] dst);
FloatBuffer put(FloatBuffer src);
FloatBuffer put(float[] src, int offset, int length);
FloatBuffer put(float[] src);
boolean isDirect();
FloatBuffer mark();
FloatBuffer reset();
FloatBuffer clear();
FloatBuffer flip();
FloatBuffer rewind();
FloatBuffer limit(int newLimit);
FloatBuffer position(int newPosition);
float[] array();
}

View File

@ -0,0 +1,62 @@
package net.lax1dude.eaglercraft.internal.buffer;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public interface IntBuffer extends Buffer {
IntBuffer duplicate();
int get();
IntBuffer put(int b);
int get(int index);
IntBuffer put(int index, int b);
int getElement(int index);
void putElement(int index, int value);
IntBuffer get(int[] dst, int offset, int length);
IntBuffer get(int[] dst);
IntBuffer put(IntBuffer src);
IntBuffer put(int[] src, int offset, int length);
IntBuffer put(int[] src);
boolean isDirect();
IntBuffer mark();
IntBuffer reset();
IntBuffer clear();
IntBuffer flip();
IntBuffer rewind();
IntBuffer limit(int newLimit);
IntBuffer position(int newPosition);
int[] array();
}

View File

@ -0,0 +1,62 @@
package net.lax1dude.eaglercraft.internal.buffer;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public interface ShortBuffer extends Buffer {
ShortBuffer duplicate();
short get();
ShortBuffer put(short b);
short get(int index);
ShortBuffer put(int index, short b);
short getElement(int index);
void putElement(int index, short value);
ShortBuffer get(short[] dst, int offset, int length);
ShortBuffer get(short[] dst);
ShortBuffer put(ShortBuffer src);
ShortBuffer put(short[] src, int offset, int length);
ShortBuffer put(short[] src);
boolean isDirect();
ShortBuffer mark();
ShortBuffer reset();
ShortBuffer clear();
ShortBuffer flip();
ShortBuffer rewind();
ShortBuffer limit(int newLimit);
ShortBuffer position(int newPosition);
short[] array();
}

View File

@ -399,7 +399,6 @@ public class Minecraft implements Runnable {
}
this.guiAchievement.updateAchievementWindow();
Thread.yield();
if(GL11.EaglerAdapterImpl2.getCanvasWidth() != this.displayWidth || GL11.EaglerAdapterImpl2.getCanvasHeight() != this.displayHeight) {
this.displayWidth = GL11.EaglerAdapterImpl2.getCanvasWidth();

View File

@ -1,8 +1,7 @@
package net.minecraft.src;
import java.nio.FloatBuffer;
import net.PeytonPlayz585.opengl.GL11;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
public class ClippingHelperImpl extends ClippingHelper {
private static ClippingHelperImpl instance = new ClippingHelperImpl();

View File

@ -1,6 +1,5 @@
package net.minecraft.src;
import java.nio.FloatBuffer;
import java.util.List;
import net.PeytonPlayz585.glemu.GameOverlayFramebuffer;
@ -9,6 +8,7 @@ import net.PeytonPlayz585.input.Mouse;
import net.PeytonPlayz585.opengl.Display;
import net.PeytonPlayz585.opengl.GL11;
import net.PeytonPlayz585.util.glu.GLU;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
import net.minecraft.client.Minecraft;
public class EntityRenderer {
@ -434,7 +434,7 @@ public class EntityRenderer {
this.mc.ingameGUI.renderVignette(this.mc.thePlayer.getEntityBrightness(var1), var14, var15);
}
this.mc.ingameGUI.renderCrossHairs(var14, var15);
this.overlayFramebuffer.bindTexture();
GL11.glBindTexture(this.overlayFramebuffer.getTexture());
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_ALPHA_TEST);

View File

@ -1,14 +1,13 @@
package net.minecraft.src;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;
import net.PeytonPlayz585.BufferUtils;
import net.PeytonPlayz585.opengl.GL11;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
public class GLAllocation {
private static List displayLists = new ArrayList();

View File

@ -20,13 +20,13 @@ public class GameSettings {
public float soundVolume = 1.0F;
public float mouseSensitivity = 0.5F;
public boolean invertMouse = false;
public int renderDistance = 0;
public boolean viewBobbing = true;
public int renderDistance = 3;
public boolean viewBobbing = false;
public boolean anaglyph = false;
public boolean advancedOpengl = false;
public int limitFramerate = 1;
public boolean fancyGraphics = true;
public boolean ambientOcclusion = true;
public boolean fancyGraphics = false;
public boolean ambientOcclusion = false;
public boolean particles = true;
public String skin = "Default";
public KeyBinding keyBindForward = new KeyBinding("key.forward", 17);
@ -152,7 +152,6 @@ public class GameSettings {
}
public boolean getOptionOrdinalValue(EnumOptions var1) {
System.out.println(EnumOptionsMappingHelper.enumOptionsMappingHelperArray[var1.ordinal()]);
switch(EnumOptionsMappingHelper.enumOptionsMappingHelperArray[var1.ordinal()]) {
case 1:
return this.invertMouse;

View File

@ -128,12 +128,6 @@ public class LoadingScreenRenderer implements IProgressUpdate {
this.mc.fontRenderer.drawStringWithShadow(this.field_1007_c, (var5 - this.mc.fontRenderer.getStringWidth(this.field_1007_c)) / 2, var6 / 2 - 4 - 16, 16777215);
this.mc.fontRenderer.drawStringWithShadow(this.field_1004_a, (var5 - this.mc.fontRenderer.getStringWidth(this.field_1004_a)) / 2, var6 / 2 - 4 + 8, 16777215);
Display.update();
try {
Thread.yield();
} catch (Exception var14) {
}
}
}
}

View File

@ -16,9 +16,6 @@ import net.PeytonPlayz585.socket.Socket;
import net.PeytonPlayz585.socket.SocketException;
public class NetworkManager {
public static final Object threadSyncObject = new Object();
public static int numReadThreads;
public static int numWriteThreads;
private Object sendQueueLock = new Object();
private Socket networkSocket;
private boolean isRunning = true;

View File

@ -3,8 +3,6 @@ package net.minecraft.src;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -16,6 +14,8 @@ import net.PeytonPlayz585.opengl.GL11;
import net.PeytonPlayz585.profile.Profile;
import net.PeytonPlayz585.textures.TextureLocation;
import net.lax1dude.eaglercraft.SpriteSheetTexture;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
import net.minecraft.client.Minecraft;
public class RenderEngine {
@ -32,7 +32,7 @@ public class RenderEngine {
private TexturePackList texturePack;
private BufferedImage missingTextureImage;
private ByteBuffer imageDataB1 = GLAllocation.createDirectByteBuffer(4194304 * 2);
private int textureWidth;
//private ByteBuffer imageDataB2 = GLAllocation.createDirectByteBuffer(4194304 * 2);
public RenderEngine(TexturePackList var1, GameSettings var2) {
this.options = var2;
@ -42,16 +42,6 @@ public class RenderEngine {
missingTexture[i] = ((i / 16 + (i % 16)) % 2 == 0) ? 0xffff00ff : 0xff000000;
}
this.missingTextureImage = new BufferedImage(16, 16, missingTexture, true);
try {
BufferedImage img = this.readTextureImage(this.texturePack.selectedTexturePack.getResourceAsStream("/terrain.png"));
int width = img.getWidth();
int textureWidth = width / 16;
this.textureWidth = textureWidth;
} catch (IOException e) {
System.err.println("Unable to read terrain.png, using default 16x16 texture animations");
textureWidth = 16;
}
}
public int getTexture(String var1) {
@ -74,7 +64,7 @@ public class RenderEngine {
this.blurTexture = false;
} else {
if(var1.equals("/terrain.png")) {
useMipmaps = true;
//useMipmaps = true;
}
InputStream var7 = var2.getResourceAsStream(var1);
if(var7 == null) {
@ -145,9 +135,8 @@ public class RenderEngine {
}
int var3 = var1.getWidth();
int var4 = var1.getHeight();
int[] var5 = new int[var3 * var4];
int var5[] = var1.getData();
byte[] var6 = new byte[var3 * var4 * 4];
var1.getRGB(0, 0, var3, var4, var5, 0, var3);
int var7;
int var8;
@ -181,48 +170,6 @@ public class RenderEngine {
this.imageDataB1.put(var6);
this.imageDataB1.position(0).limit(var6.length);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, var3, var4, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageDataB1);
if(useMipmaps) {
for(var7 = 1; var7 <= 4; ++var7) {
var8 = var3 >> var7 - 1;
var9 = var3 >> var7;
var10 = var4 >> var7;
for(var11 = 0; var11 < var9; ++var11) {
for(var12 = 0; var12 < var10; ++var12) {
var13 = this.imageDataB1.getInt((var11 * 2 + 0 + (var12 * 2 + 0) * var8) * 4);
var14 = this.imageDataB1.getInt((var11 * 2 + 1 + (var12 * 2 + 0) * var8) * 4);
int var15 = this.imageDataB1.getInt((var11 * 2 + 1 + (var12 * 2 + 1) * var8) * 4);
int var16 = this.imageDataB1.getInt((var11 * 2 + 0 + (var12 * 2 + 1) * var8) * 4);
int var17 = this.averageColor(this.averageColor(var13, var14), this.averageColor(var15, var16));
this.imageDataB1.putInt((var11 + var12 * var9) * 4, var17);
}
}
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, var7, GL11.GL_RGBA, var9, var10, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageDataB1);
}
}
// if (useMipmaps) {
// for (int i1 = 1; i1 <= 4; i1++) {
// int k1 = j >> i1 - 1;
// int i2 = j >> i1;
// int k2 = k >> i1;
// imageDataB1.clear();
// for (int i3 = 0; i3 < i2; i3++) {
// for (int k3 = 0; k3 < k2; k3++) {
// int i4 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 0) * k1) * 4);
// int k4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 0) * k1) * 4);
// int l4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 1) * k1) * 4);
// int i5 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 1) * k1) * 4);
// int j5 = averageColor(averageColor(i4, k4), averageColor(l4, i5));
// imageDataB1.putInt((i3 + k3 * i2) * 4, j5);
// }
//
// }
//
// GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i1, GL11.GL_RGBA, i2, k2, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)imageDataB1);
// }
//
// }
}
public void func_28150_a(int[] var1, int var2, int var3, int var4) {
@ -313,11 +260,7 @@ public class RenderEngine {
}
private int[] func_28148_b(BufferedImage var1) {
int var2 = var1.getWidth();
int var3 = var1.getHeight();
int[] var4 = new int[var2 * var3];
var1.getRGB(0, 0, var2, var3, var4, 0, var2);
return var4;
return var1.getData();
}
public void deleteTexture(int var1) {
@ -347,21 +290,21 @@ public class RenderEngine {
imageDataB1.clear();
imageDataB1.put(texturefx.imageData);
imageDataB1.position(0).limit(tileSize);
GL11.glTexSubImage2D(3553 /* GL_TEXTURE_2D */, 0, (texturefx.iconIndex % this.textureWidth) * 16, (texturefx.iconIndex / this.textureWidth) * 16, 16, 16,
GL11.glTexSubImage2D(3553 /* GL_TEXTURE_2D */, 0, (texturefx.iconIndex % 16) * 16, (texturefx.iconIndex / 16) * 16, 16, 16,
6408 /* GL_RGBA */, 5121 /* GL_UNSIGNED_BYTE */, imageDataB1);
}
TextureFX.terrainTexture.bindTexture();
for(int i = 0, l = textureSpriteList.size(); i < l; ++i) {
SpriteSheetTexture sp = textureSpriteList.get(i);
sp.update();
int w = 16;
for(int j = 0; j < 5; ++j) {
GL11.glTexSubImage2D(3553 /* GL_TEXTURE_2D */, j, (sp.iconIndex % this.textureWidth) * w, (sp.iconIndex / this.textureWidth) * w, w * sp.iconTileSize, w * sp.iconTileSize,
6408 /* GL_RGBA */, 5121 /* GL_UNSIGNED_BYTE */, sp.grabFrame(j));
w /= 2;
}
}
// TextureFX.terrainTexture.bindTexture();
// for(int i = 0, l = textureSpriteList.size(); i < l; ++i) {
// SpriteSheetTexture sp = textureSpriteList.get(i);
// sp.update();
// int w = 16;
// for(int j = 0; j < 5; ++j) {
// GL11.glTexSubImage2D(3553 /* GL_TEXTURE_2D */, j, (sp.iconIndex % this.textureWidth) * w, (sp.iconIndex / this.textureWidth) * w, w * sp.iconTileSize, w * sp.iconTileSize,
// 6408 /* GL_RGBA */, 5121 /* GL_UNSIGNED_BYTE */, sp.grabFrame(j));
// w /= 2;
// }
// }
}
public void registerSpriteSheet(String name, int iconIndex, int iconTileSize) {
@ -371,7 +314,23 @@ public class RenderEngine {
private int averageColor(int var1, int var2) {
int var3 = (var1 & -16777216) >> 24 & 255;
int var4 = (var2 & -16777216) >> 24 & 255;
return (var3 + var4 >> 1 << 24) + ((var1 & 16711422) + (var2 & 16711422) >> 1);
short var5 = 255;
if(var3 + var4 == 0) {
var3 = 1;
var4 = 1;
var5 = 0;
}
int var6 = (var1 >> 16 & 255) * var3;
int var7 = (var1 >> 8 & 255) * var3;
int var8 = (var1 & 255) * var3;
int var9 = (var2 >> 16 & 255) * var4;
int var10 = (var2 >> 8 & 255) * var4;
int var11 = (var2 & 255) * var4;
int var12 = (var6 + var9) / (var3 + var4);
int var13 = (var7 + var10) / (var3 + var4);
int var14 = (var8 + var11) / (var3 + var4);
return var5 << 24 | var12 << 16 | var13 << 8 | var14;
}
public void refreshTextures() {
@ -409,18 +368,7 @@ public class RenderEngine {
for(int j = 0, l = textureSpriteList.size(); j < l; ++j) {
textureSpriteList.get(j).reloadData();
}
try {
BufferedImage img = this.readTextureImage(this.texturePack.selectedTexturePack.getResourceAsStream("/terrain.png"));
int width = img.getWidth();
int textureWidth = width / 16;
this.textureWidth = textureWidth;
} catch (IOException e) {
System.err.println("Unable to read terrain.png, using default 16x16 texture animations");
textureWidth = 16;
}
}
}
private BufferedImage readTextureImage(InputStream var1) throws IOException {

View File

@ -1,8 +1,7 @@
package net.minecraft.src;
import java.nio.IntBuffer;
import net.PeytonPlayz585.opengl.GL11;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
public class RenderList {
private int field_1242_a;

View File

@ -1,16 +1,14 @@
package net.PeytonPlayz585;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.ShortBuffer;
import net.minecraft.src.GLAllocation;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.internal.buffer.EaglerArrayBufferAllocator;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
import net.lax1dude.eaglercraft.internal.buffer.ShortBuffer;
public class BufferUtils {
@ -20,11 +18,13 @@ public class BufferUtils {
*/
public static ByteBuffer createByteBuffer(int size) {
return ByteBuffer.wrap(new byte[size]).order(ByteOrder.nativeOrder());
//return ByteBuffer.wrap(new byte[size]).order(ByteOrder.nativeOrder());
return EaglerArrayBufferAllocator.allocateByteBuffer(size);
}
public static ShortBuffer createShortBuffer(int size) {
return ShortBuffer.wrap(new short[size]);
//return ShortBuffer.wrap(new short[size]);
return EaglerArrayBufferAllocator.allocateByteBuffer(size).asShortBuffer();
}
public static CharBuffer createCharBuffer(int size) {
@ -32,7 +32,8 @@ public class BufferUtils {
}
public static IntBuffer createIntBuffer(int size) {
return IntBuffer.wrap(new int[size]);
//return IntBuffer.wrap(new int[size]);
return EaglerArrayBufferAllocator.allocateIntBuffer(size);
}
public static LongBuffer createLongBuffer(int size) {
@ -40,7 +41,8 @@ public class BufferUtils {
}
public static FloatBuffer createFloatBuffer(int size) {
return FloatBuffer.wrap(new float[size]);
//return FloatBuffer.wrap(new float[size]);
return EaglerArrayBufferAllocator.allocateFloatBuffer(size);
}
public static DoubleBuffer createDoubleBuffer(int size) {
@ -52,110 +54,4 @@ public class BufferUtils {
//I rewrote the PointerBuffer class to use buffer.wrap
return PointerBuffer.allocateDirect(size);
}
public static int getElementSizeExponent(Buffer buf) {
if (buf instanceof ByteBuffer) {
return 0;
} else if (buf instanceof ShortBuffer || buf instanceof CharBuffer) {
return 1;
} else if (buf instanceof FloatBuffer || buf instanceof IntBuffer) {
return 2;
} else if (buf instanceof LongBuffer || buf instanceof DoubleBuffer) {
return 3;
} else {
throw new IllegalStateException("Unsupported buffer type: " + buf);
}
}
public static int getOffset(Buffer buffer) {
return buffer.position() << getElementSizeExponent(buffer);
}
public static void zeroBuffer(ByteBuffer b) {
zeroBuffer0(b, b.position(), b.remaining());
}
public static void zeroBuffer(ShortBuffer b) {
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
}
public static void zeroBuffer(CharBuffer b) {
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
}
public static void zeroBuffer(IntBuffer b) {
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
}
public static void zeroBuffer(FloatBuffer b) {
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
}
public static void zeroBuffer(LongBuffer b) {
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
}
public static void zeroBuffer(DoubleBuffer b) {
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
}
//Wrote my own implementation since JNI isn't supported in TeaVM
private static void zeroBuffer0(Buffer b, long offset, long length) {
for (int i = 0; i < b.remaining(); i++) {
put(b, i, 0);
}
}
private static void put(Buffer b, int i, int i2) {
if(b instanceof ByteBuffer) {
put((ByteBuffer)b, i, i2);
} else if(b instanceof ShortBuffer) {
put((ShortBuffer)b, i, i2);
} else if(b instanceof CharBuffer) {
put((CharBuffer)b, i, i2);
} else if(b instanceof IntBuffer) {
put((IntBuffer)b, i, i2);
} else if(b instanceof FloatBuffer) {
put((FloatBuffer)b, i, i2);
} else if(b instanceof LongBuffer) {
put((LongBuffer)b, i, i2);
} else if(b instanceof DoubleBuffer) {
put((DoubleBuffer)b, i, i2);
} else {
throw new IllegalArgumentException("Unsupported buffer type!");
}
}
private static void put(ByteBuffer b, int i, int i2) {
b.put(i, (byte) i2);
}
private static void put(ShortBuffer b, int i, int i2) {
b.put(i, (short) i2);
}
private static void put(CharBuffer b, int i, int i2) {
b.put(i, (char) i2);
}
private static void put(IntBuffer b, int i, int i2) {
b.put(i, i2);
}
private static void put(FloatBuffer b, int i, int i2) {
b.put(i, i2);
}
private static void put(LongBuffer b, int i, int i2) {
b.put(i, i2);
}
private static void put(DoubleBuffer b, int i, int i2) {
b.put(i, i2);
}
//Not in BufferUtils but thought I would add it anyways
public static int getBufferSizeInBytes(Buffer buffer) {
return buffer.capacity() * getElementSizeExponent(buffer);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
package net.PeytonPlayz585.opengl;
import org.teavm.jso.dom.events.MessageEvent;
public class PlatformWebView {
public static void onWindowMessageRecieved(MessageEvent evt) {
// if(currentIFrame != null && currentMessageHandler != null && sourceEquals(evt, currentIFrame)) {
// currentMessageHandler.accept(evt);
// }
}
}

View File

@ -0,0 +1,88 @@
package net.PeytonPlayz585.opengl;
import org.teavm.jso.webgl.WebGLFramebuffer;
import net.PeytonPlayz585.opengl.GL11.EaglerAdapterImpl2.FramebufferGL;
import net.PeytonPlayz585.opengl.GL11.EaglerAdapterImpl2.RenderbufferGL;
import net.PeytonPlayz585.opengl.GL11.WebGL2RenderingContext;
import static net.PeytonPlayz585.opengl.GL11.*;
import static net.PeytonPlayz585.opengl.GL11.EaglerAdapterImpl2.*;
public class WebGLBackBuffer {
private static WebGL2RenderingContext ctx;
private static WebGLFramebuffer framebuffer;
private static FramebufferGL eagFramebuffer;
private static int width;
private static int height;
// GLES 3.0+
private static RenderbufferGL gles3ColorRenderbuffer;
private static RenderbufferGL gles3DepthRenderbuffer;
private static final int _GL_FRAMEBUFFER = 0x8D40;
private static final int _GL_RENDERBUFFER = 0x8D41;
private static final int _GL_COLOR_ATTACHMENT0 = 0x8CE0;
private static final int _GL_DEPTH_ATTACHMENT = 0x8D00;
private static final int _GL_DEPTH_COMPONENT16 = 0x81A5;
private static final int _GL_DEPTH_COMPONENT32F = 0x8CAC;
private static final int _GL_READ_FRAMEBUFFER = 0x8CA8;
private static final int _GL_DRAW_FRAMEBUFFER = 0x8CA9;
public static void initBackBuffer(WebGL2RenderingContext ctxIn, WebGLFramebuffer fbo, FramebufferGL eagFbo, int sw, int sh) {
ctx = ctxIn;
framebuffer = fbo;
eagFramebuffer = eagFbo;
width = sw;
height = sh;
gles3ColorRenderbuffer = _wglCreateRenderBuffer();
gles3DepthRenderbuffer = _wglCreateRenderBuffer();
_wglBindFramebuffer(_GL_FRAMEBUFFER, eagFbo);
_wglBindRenderbuffer(_GL_RENDERBUFFER, gles3ColorRenderbuffer);
_wglRenderbufferStorage(_GL_RENDERBUFFER, GL11.GL_RGBA8, sw, sh);
_wglFramebufferRenderbuffer(_GL_FRAMEBUFFER, _GL_COLOR_ATTACHMENT0, _GL_RENDERBUFFER, gles3ColorRenderbuffer);
_wglBindRenderbuffer(_GL_RENDERBUFFER, gles3DepthRenderbuffer);
_wglRenderbufferStorage(_GL_RENDERBUFFER, _GL_DEPTH_COMPONENT32F, sw, sh);
_wglFramebufferRenderbuffer(_GL_FRAMEBUFFER, _GL_DEPTH_ATTACHMENT, _GL_RENDERBUFFER, gles3DepthRenderbuffer);
_wglDrawBuffers(_GL_COLOR_ATTACHMENT0);
}
public static void flipBuffer(int windowWidth, int windowHeight) {
ctx.bindFramebuffer(_GL_READ_FRAMEBUFFER, framebuffer);
ctx.bindFramebuffer(_GL_DRAW_FRAMEBUFFER, null);
ctx.blitFramebuffer(0, 0, width, height, 0, 0, windowWidth, windowHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
ctx.bindFramebuffer(_GL_FRAMEBUFFER, framebuffer);
if(windowWidth != width || windowHeight != height) {
width = windowWidth;
height = windowHeight;
_wglBindRenderbuffer(_GL_RENDERBUFFER, gles3ColorRenderbuffer);
_wglRenderbufferStorage(_GL_RENDERBUFFER, GL_RGBA8, windowWidth, windowHeight);
_wglBindRenderbuffer(_GL_RENDERBUFFER, gles3DepthRenderbuffer);
_wglRenderbufferStorage(_GL_RENDERBUFFER, _GL_DEPTH_COMPONENT32F, windowWidth, windowHeight);
}
}
public static void destroy() {
if(eagFramebuffer != null) {
_wglDeleteFramebuffer(eagFramebuffer);
eagFramebuffer = null;
}
if(gles3ColorRenderbuffer != null) {
_wglDeleteRenderbuffer(gles3ColorRenderbuffer);
gles3ColorRenderbuffer = null;
}
if(gles3DepthRenderbuffer != null) {
_wglDeleteRenderbuffer(gles3DepthRenderbuffer);
gles3DepthRenderbuffer = null;
}
framebuffer = null;
width = 0;
height = 0;
}
}

View File

@ -1,9 +1,7 @@
package net.PeytonPlayz585.util.glu;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import net.PeytonPlayz585.opengl.GL11;
import net.lax1dude.eaglercraft.internal.buffer.FloatBuffer;
public class GLU {

View File

@ -0,0 +1,254 @@
package net.lax1dude.eaglercraft;
import net.lax1dude.eaglercraft.crypto.MD5Digest;
import net.minecraft.src.Random;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglercraftUUID implements Comparable<EaglercraftUUID> {
public final long msb;
public final long lsb;
private int hash = 0;
private boolean hasHash;
public EaglercraftUUID(long msb, long lsb) {
this.msb = msb;
this.lsb = lsb;
}
public EaglercraftUUID(byte[] uuid) {
long msb = 0;
long lsb = 0;
for (int i = 0; i < 8; i++)
msb = (msb << 8) | (uuid[i] & 0xff);
for (int i = 8; i < 16; i++)
lsb = (lsb << 8) | (uuid[i] & 0xff);
this.msb = msb;
this.lsb = lsb;
}
public EaglercraftUUID(String uuid) {
String[] components = uuid.split("-");
if (components.length != 5)
throw new IllegalArgumentException("Invalid UUID string: " + uuid);
for (int i = 0; i < 5; i++)
components[i] = "0x" + components[i];
long mostSigBits = Long.decode(components[0]).longValue();
mostSigBits <<= 16;
mostSigBits |= Long.decode(components[1]).longValue();
mostSigBits <<= 16;
mostSigBits |= Long.decode(components[2]).longValue();
long leastSigBits = Long.decode(components[3]).longValue();
leastSigBits <<= 48;
leastSigBits |= Long.decode(components[4]).longValue();
this.msb = mostSigBits;
this.lsb = leastSigBits;
}
private static byte long7(long x) {
return (byte) (x >> 56);
}
private static byte long6(long x) {
return (byte) (x >> 48);
}
private static byte long5(long x) {
return (byte) (x >> 40);
}
private static byte long4(long x) {
return (byte) (x >> 32);
}
private static byte long3(long x) {
return (byte) (x >> 24);
}
private static byte long2(long x) {
return (byte) (x >> 16);
}
private static byte long1(long x) {
return (byte) (x >> 8);
}
private static byte long0(long x) {
return (byte) (x);
}
public byte[] getBytes() {
byte[] ret = new byte[16];
ret[0] = long7(msb);
ret[1] = long6(msb);
ret[2] = long5(msb);
ret[3] = long4(msb);
ret[4] = long3(msb);
ret[5] = long2(msb);
ret[6] = long1(msb);
ret[7] = long0(msb);
ret[8] = long7(lsb);
ret[9] = long6(lsb);
ret[10] = long5(lsb);
ret[11] = long4(lsb);
ret[12] = long3(lsb);
ret[13] = long2(lsb);
ret[14] = long1(lsb);
ret[15] = long0(lsb);
return ret;
}
@Override
public String toString() {
return (digits(msb >> 32, 8) + "-" + digits(msb >> 16, 4) + "-" + digits(msb, 4) + "-" + digits(lsb >> 48, 4)
+ "-" + digits(lsb, 12));
}
private static String digits(long val, int digits) {
long hi = 1L << (digits * 4);
return Long.toHexString(hi | (val & (hi - 1))).substring(1);
}
@Override
public int hashCode() {
if(hash == 0 && !hasHash) {
long hilo = msb ^ lsb;
hash = ((int) (hilo >> 32)) ^ (int) hilo;
hasHash = true;
}
return hash;
}
@Override
public boolean equals(Object o) {
if(!(o instanceof EaglercraftUUID)) return false;
EaglercraftUUID oo = (EaglercraftUUID)o;
return (hasHash && oo.hasHash)
? (hash == oo.hash && msb == oo.msb && lsb == oo.lsb)
: (msb == oo.msb && lsb == oo.lsb);
}
public long getMostSignificantBits() {
return msb;
}
public long getLeastSignificantBits() {
return lsb;
}
private static final String HEX = "0123456789ABCDEF";
private static int nibbleValue(char c) {
int v = HEX.indexOf(Character.toUpperCase(c));
if (v == -1) {
return 0;
} else {
return v;
}
}
private static long parse4Nibbles(String name, int pos) {
int ch1 = nibbleValue(name.charAt(pos));
int ch2 = nibbleValue(name.charAt(pos + 1));
int ch3 = nibbleValue(name.charAt(pos + 2));
int ch4 = nibbleValue(name.charAt(pos + 3));
return (ch1 << 12) | (ch2 << 8) | (ch3 << 4) | ch4;
}
public static EaglercraftUUID fromString(String name) {
if (name.length() == 36) {
char ch1 = name.charAt(8);
char ch2 = name.charAt(13);
char ch3 = name.charAt(18);
char ch4 = name.charAt(23);
if (ch1 == '-' && ch2 == '-' && ch3 == '-' && ch4 == '-') {
long msb1 = parse4Nibbles(name, 0);
long msb2 = parse4Nibbles(name, 4);
long msb3 = parse4Nibbles(name, 9);
long msb4 = parse4Nibbles(name, 14);
long lsb1 = parse4Nibbles(name, 19);
long lsb2 = parse4Nibbles(name, 24);
long lsb3 = parse4Nibbles(name, 28);
long lsb4 = parse4Nibbles(name, 32);
if ((msb1 | msb2 | msb3 | msb4 | lsb1 | lsb2 | lsb3 | lsb4) >= 0) {
return new EaglercraftUUID(msb1 << 48 | msb2 << 32 | msb3 << 16 | msb4,
lsb1 << 48 | lsb2 << 32 | lsb3 << 16 | lsb4);
}
}
}
return fromString1(name);
}
private static EaglercraftUUID fromString1(String name) {
int len = name.length();
if (len > 36) {
throw new IllegalArgumentException("UUID string too large");
}
int dash1 = name.indexOf('-', 0);
int dash2 = name.indexOf('-', dash1 + 1);
int dash3 = name.indexOf('-', dash2 + 1);
int dash4 = name.indexOf('-', dash3 + 1);
int dash5 = name.indexOf('-', dash4 + 1);
if (dash4 < 0 || dash5 >= 0) {
throw new IllegalArgumentException("Invalid UUID string: " + name);
}
long mostSigBits = JDKBackports.parseLong(name, 0, dash1, 16) & 0xffffffffL;
mostSigBits <<= 16;
mostSigBits |= JDKBackports.parseLong(name, dash1 + 1, dash2, 16) & 0xffffL;
mostSigBits <<= 16;
mostSigBits |= JDKBackports.parseLong(name, dash2 + 1, dash3, 16) & 0xffffL;
long leastSigBits = JDKBackports.parseLong(name, dash3 + 1, dash4, 16) & 0xffffL;
leastSigBits <<= 48;
leastSigBits |= JDKBackports.parseLong(name, dash4 + 1, len, 16) & 0xffffffffffffL;
return new EaglercraftUUID(mostSigBits, leastSigBits);
}
public static EaglercraftUUID nameUUIDFromBytes(byte[] bytes) {
MD5Digest dg = new MD5Digest();
dg.update(bytes, 0, bytes.length);
byte[] md5Bytes = new byte[16];
dg.doFinal(md5Bytes, 0);
md5Bytes[6] &= 0x0f;
md5Bytes[6] |= 0x30;
md5Bytes[8] &= 0x3f;
md5Bytes[8] |= 0x80;
return new EaglercraftUUID(md5Bytes);
}
public static EaglercraftUUID randomUUID() {
byte[] randomBytes = new byte[16];
(new Random()).nextBytes(randomBytes);
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */
randomBytes[8] &= 0x3f; /* clear variant */
randomBytes[8] |= 0x80; /* set to IETF variant */
return new EaglercraftUUID(randomBytes);
}
@Override
public int compareTo(EaglercraftUUID val) {
return (this.msb < val.msb ? -1
: (this.msb > val.msb ? 1 : (this.lsb < val.lsb ? -1 : (this.lsb > val.lsb ? 1 : 0))));
}
}

View File

@ -0,0 +1,90 @@
package net.lax1dude.eaglercraft;
import java.util.function.Supplier;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class JDKBackports {
public static long parseLong(CharSequence s, int beginIndex, int endIndex, int radix) throws NumberFormatException {
if (beginIndex < 0 || beginIndex > endIndex || endIndex > s.length()) {
throw new IndexOutOfBoundsException();
}
if (radix < Character.MIN_RADIX) {
throw new NumberFormatException("radix " + radix + " less than Character.MIN_RADIX");
}
if (radix > Character.MAX_RADIX) {
throw new NumberFormatException("radix " + radix + " greater than Character.MAX_RADIX");
}
boolean negative = false;
int i = beginIndex;
long limit = -Long.MAX_VALUE;
if (i < endIndex) {
char firstChar = s.charAt(i);
if (firstChar < '0') { // Possible leading "+" or "-"
if (firstChar == '-') {
negative = true;
limit = Long.MIN_VALUE;
} else if (firstChar != '+') {
throw new NumberFormatException();
}
i++;
}
if (i >= endIndex) { // Cannot have lone "+", "-" or ""
throw new NumberFormatException();
}
long multmin = limit / radix;
long result = 0;
while (i < endIndex) {
// Accumulating negatively avoids surprises near MAX_VALUE
int digit = Character.digit(s.charAt(i), radix);
if (digit < 0 || result < multmin) {
throw new NumberFormatException();
}
result *= radix;
if (result < limit + digit) {
throw new NumberFormatException();
}
i++;
result -= digit;
}
return negative ? result : -result;
} else {
throw new NumberFormatException("");
}
}
public static <T> T javaUtilObject_requireNonNull(T obj, Supplier<String> messageSupplier) {
if (obj == null)
throw new NullPointerException(messageSupplier.get());
return obj;
}
public static <T> T javaUtilObject_requireNonNull(T obj, String message) {
if (obj == null)
throw new NullPointerException(message);
return obj;
}
public static <T> T javaUtilObject_requireNonNull(T obj) {
if (obj == null)
throw new NullPointerException();
return obj;
}
}

View File

@ -0,0 +1,129 @@
/*
* Copyright (c) 2000-2021 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.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 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.
*
*/
package net.lax1dude.eaglercraft.crypto;
/**
* 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();
}

View File

@ -0,0 +1,265 @@
/*
* Copyright (c) 2000-2021 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.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 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.
*
*/
package net.lax1dude.eaglercraft.crypto;
/**
* implementation of MD5 as outlined in "Handbook of Applied Cryptography",
* pages 346 - 347.
*/
public class MD5Digest extends GeneralDigest {
private static final int DIGEST_LENGTH = 16;
private int H1, H2, H3, H4; // IV's
private int[] X = new int[16];
private int xOff;
/**
* Standard constructor
*/
public MD5Digest() {
reset();
}
public String getAlgorithmName() {
return "MD5";
}
public int getDigestSize() {
return DIGEST_LENGTH;
}
protected void processWord(byte[] in, int inOff) {
X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff) << 8) | ((in[inOff + 2] & 0xff) << 16)
| ((in[inOff + 3] & 0xff) << 24);
if (xOff == 16) {
processBlock();
}
}
protected void processLength(long bitLength) {
if (xOff > 14) {
processBlock();
}
X[14] = (int) (bitLength & 0xffffffff);
X[15] = (int) (bitLength >>> 32);
}
private void unpackWord(int word, byte[] out, int outOff) {
out[outOff] = (byte) word;
out[outOff + 1] = (byte) (word >>> 8);
out[outOff + 2] = (byte) (word >>> 16);
out[outOff + 3] = (byte) (word >>> 24);
}
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);
reset();
return DIGEST_LENGTH;
}
/**
* reset the chaining variables to the IV values.
*/
public void reset() {
super.reset();
H1 = 0x67452301;
H2 = 0xefcdab89;
H3 = 0x98badcfe;
H4 = 0x10325476;
xOff = 0;
for (int i = 0; i != X.length; i++) {
X[i] = 0;
}
}
//
// round 1 left rotates
//
private static final int S11 = 7;
private static final int S12 = 12;
private static final int S13 = 17;
private static final int S14 = 22;
//
// round 2 left rotates
//
private static final int S21 = 5;
private static final int S22 = 9;
private static final int S23 = 14;
private static final int S24 = 20;
//
// round 3 left rotates
//
private static final int S31 = 4;
private static final int S32 = 11;
private static final int S33 = 16;
private static final int S34 = 23;
//
// round 4 left rotates
//
private static final int S41 = 6;
private static final int S42 = 10;
private static final int S43 = 15;
private static final int S44 = 21;
/*
* rotate int x left n bits.
*/
private int rotateLeft(int x, int n) {
return (x << n) | (x >>> (32 - n));
}
/*
* F, G, H and I are the basic MD5 functions.
*/
private int F(int u, int v, int w) {
return (u & v) | (~u & w);
}
private int G(int u, int v, int w) {
return (u & w) | (v & ~w);
}
private int H(int u, int v, int w) {
return u ^ v ^ w;
}
private int K(int u, int v, int w) {
return v ^ (u | ~w);
}
protected void processBlock() {
int a = H1;
int b = H2;
int c = H3;
int d = H4;
//
// Round 1 - F cycle, 16 times.
//
a = rotateLeft(a + F(b, c, d) + X[0] + 0xd76aa478, S11) + b;
d = rotateLeft(d + F(a, b, c) + X[1] + 0xe8c7b756, S12) + a;
c = rotateLeft(c + F(d, a, b) + X[2] + 0x242070db, S13) + d;
b = rotateLeft(b + F(c, d, a) + X[3] + 0xc1bdceee, S14) + c;
a = rotateLeft(a + F(b, c, d) + X[4] + 0xf57c0faf, S11) + b;
d = rotateLeft(d + F(a, b, c) + X[5] + 0x4787c62a, S12) + a;
c = rotateLeft(c + F(d, a, b) + X[6] + 0xa8304613, S13) + d;
b = rotateLeft(b + F(c, d, a) + X[7] + 0xfd469501, S14) + c;
a = rotateLeft(a + F(b, c, d) + X[8] + 0x698098d8, S11) + b;
d = rotateLeft(d + F(a, b, c) + X[9] + 0x8b44f7af, S12) + a;
c = rotateLeft(c + F(d, a, b) + X[10] + 0xffff5bb1, S13) + d;
b = rotateLeft(b + F(c, d, a) + X[11] + 0x895cd7be, S14) + c;
a = rotateLeft(a + F(b, c, d) + X[12] + 0x6b901122, S11) + b;
d = rotateLeft(d + F(a, b, c) + X[13] + 0xfd987193, S12) + a;
c = rotateLeft(c + F(d, a, b) + X[14] + 0xa679438e, S13) + d;
b = rotateLeft(b + F(c, d, a) + X[15] + 0x49b40821, S14) + c;
//
// Round 2 - G cycle, 16 times.
//
a = rotateLeft(a + G(b, c, d) + X[1] + 0xf61e2562, S21) + b;
d = rotateLeft(d + G(a, b, c) + X[6] + 0xc040b340, S22) + a;
c = rotateLeft(c + G(d, a, b) + X[11] + 0x265e5a51, S23) + d;
b = rotateLeft(b + G(c, d, a) + X[0] + 0xe9b6c7aa, S24) + c;
a = rotateLeft(a + G(b, c, d) + X[5] + 0xd62f105d, S21) + b;
d = rotateLeft(d + G(a, b, c) + X[10] + 0x02441453, S22) + a;
c = rotateLeft(c + G(d, a, b) + X[15] + 0xd8a1e681, S23) + d;
b = rotateLeft(b + G(c, d, a) + X[4] + 0xe7d3fbc8, S24) + c;
a = rotateLeft(a + G(b, c, d) + X[9] + 0x21e1cde6, S21) + b;
d = rotateLeft(d + G(a, b, c) + X[14] + 0xc33707d6, S22) + a;
c = rotateLeft(c + G(d, a, b) + X[3] + 0xf4d50d87, S23) + d;
b = rotateLeft(b + G(c, d, a) + X[8] + 0x455a14ed, S24) + c;
a = rotateLeft(a + G(b, c, d) + X[13] + 0xa9e3e905, S21) + b;
d = rotateLeft(d + G(a, b, c) + X[2] + 0xfcefa3f8, S22) + a;
c = rotateLeft(c + G(d, a, b) + X[7] + 0x676f02d9, S23) + d;
b = rotateLeft(b + G(c, d, a) + X[12] + 0x8d2a4c8a, S24) + c;
//
// Round 3 - H cycle, 16 times.
//
a = rotateLeft(a + H(b, c, d) + X[5] + 0xfffa3942, S31) + b;
d = rotateLeft(d + H(a, b, c) + X[8] + 0x8771f681, S32) + a;
c = rotateLeft(c + H(d, a, b) + X[11] + 0x6d9d6122, S33) + d;
b = rotateLeft(b + H(c, d, a) + X[14] + 0xfde5380c, S34) + c;
a = rotateLeft(a + H(b, c, d) + X[1] + 0xa4beea44, S31) + b;
d = rotateLeft(d + H(a, b, c) + X[4] + 0x4bdecfa9, S32) + a;
c = rotateLeft(c + H(d, a, b) + X[7] + 0xf6bb4b60, S33) + d;
b = rotateLeft(b + H(c, d, a) + X[10] + 0xbebfbc70, S34) + c;
a = rotateLeft(a + H(b, c, d) + X[13] + 0x289b7ec6, S31) + b;
d = rotateLeft(d + H(a, b, c) + X[0] + 0xeaa127fa, S32) + a;
c = rotateLeft(c + H(d, a, b) + X[3] + 0xd4ef3085, S33) + d;
b = rotateLeft(b + H(c, d, a) + X[6] + 0x04881d05, S34) + c;
a = rotateLeft(a + H(b, c, d) + X[9] + 0xd9d4d039, S31) + b;
d = rotateLeft(d + H(a, b, c) + X[12] + 0xe6db99e5, S32) + a;
c = rotateLeft(c + H(d, a, b) + X[15] + 0x1fa27cf8, S33) + d;
b = rotateLeft(b + H(c, d, a) + X[2] + 0xc4ac5665, S34) + c;
//
// Round 4 - K cycle, 16 times.
//
a = rotateLeft(a + K(b, c, d) + X[0] + 0xf4292244, S41) + b;
d = rotateLeft(d + K(a, b, c) + X[7] + 0x432aff97, S42) + a;
c = rotateLeft(c + K(d, a, b) + X[14] + 0xab9423a7, S43) + d;
b = rotateLeft(b + K(c, d, a) + X[5] + 0xfc93a039, S44) + c;
a = rotateLeft(a + K(b, c, d) + X[12] + 0x655b59c3, S41) + b;
d = rotateLeft(d + K(a, b, c) + X[3] + 0x8f0ccc92, S42) + a;
c = rotateLeft(c + K(d, a, b) + X[10] + 0xffeff47d, S43) + d;
b = rotateLeft(b + K(c, d, a) + X[1] + 0x85845dd1, S44) + c;
a = rotateLeft(a + K(b, c, d) + X[8] + 0x6fa87e4f, S41) + b;
d = rotateLeft(d + K(a, b, c) + X[15] + 0xfe2ce6e0, S42) + a;
c = rotateLeft(c + K(d, a, b) + X[6] + 0xa3014314, S43) + d;
b = rotateLeft(b + K(c, d, a) + X[13] + 0x4e0811a1, S44) + c;
a = rotateLeft(a + K(b, c, d) + X[4] + 0xf7537e82, S41) + b;
d = rotateLeft(d + K(a, b, c) + X[11] + 0xbd3af235, S42) + a;
c = rotateLeft(c + K(d, a, b) + X[2] + 0x2ad7d2bb, S43) + d;
b = rotateLeft(b + K(c, d, a) + X[9] + 0xeb86d391, S44) + c;
H1 += a;
H2 += b;
H3 += c;
H4 += d;
//
// reset the offset and clean out the word buffer.
//
xOff = 0;
for (int i = 0; i != X.length; i++) {
X[i] = 0;
}
}
}

View File

@ -0,0 +1,188 @@
package net.lax1dude.eaglercraft.internal.buffer;
import org.teavm.jso.typedarrays.DataView;
import org.teavm.jso.typedarrays.Float32Array;
import org.teavm.jso.typedarrays.Int32Array;
import org.teavm.jso.typedarrays.Int8Array;
import org.teavm.jso.typedarrays.Uint16Array;
import org.teavm.jso.typedarrays.Uint8Array;
/**
* Copyright (c) 2022-2023 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerArrayBufferAllocator {
public static class WrongBufferClassType extends RuntimeException {
public WrongBufferClassType(String msg) {
super(msg);
}
}
public static ByteBuffer allocateByteBuffer(int size) {
return new EaglerArrayByteBuffer(Int8Array.create(size));
}
public static ByteBuffer wrapByteBufferTeaVM(DataView dv) {
return new EaglerArrayByteBuffer(dv);
}
public static ByteBuffer wrapByteBufferTeaVM(Int8Array typedArray) {
return new EaglerArrayByteBuffer(typedArray);
}
public static IntBuffer allocateIntBuffer(int size) {
return new EaglerArrayIntBuffer(Int32Array.create(size));
}
public static IntBuffer wrapIntBufferTeaVM(Int32Array typedArray) {
return new EaglerArrayIntBuffer(typedArray);
}
public static FloatBuffer allocateFloatBuffer(int size) {
return new EaglerArrayFloatBuffer(Float32Array.create(size));
}
public static FloatBuffer wrapFloatBufferTeaVM(Float32Array typedArray) {
return new EaglerArrayFloatBuffer(typedArray);
}
public static DataView getDataView(ByteBuffer buffer) {
if(buffer instanceof EaglerArrayByteBuffer) {
EaglerArrayByteBuffer b = (EaglerArrayByteBuffer)buffer;
DataView d = b.dataView;
int p = b.position;
int l = b.limit;
if(p == 0 && l == b.capacity) {
return d;
}else {
return DataView.create(d.getBuffer(), d.getByteOffset() + p, l - p);
}
}else {
throw notEagler(buffer);
}
}
public static Int8Array getDataView8(ByteBuffer buffer) {
if(buffer instanceof EaglerArrayByteBuffer) {
EaglerArrayByteBuffer b = (EaglerArrayByteBuffer)buffer;
Int8Array d = b.typedArray;
int p = b.position;
int l = b.limit;
if(p == 0 && l == b.capacity) {
return d;
}else {
int i = d.getByteOffset();
return Int8Array.create(d.getBuffer(), d.getByteOffset() + p, l - p);
}
}else {
throw notEagler(buffer);
}
}
public static Uint8Array getDataView8Unsigned(ByteBuffer buffer) {
if(buffer instanceof EaglerArrayByteBuffer) {
EaglerArrayByteBuffer b = (EaglerArrayByteBuffer)buffer;
Int8Array d = b.typedArray;
int p = b.position;
int i = d.getByteOffset();
return Uint8Array.create(d.getBuffer(), i + p, b.limit - p);
}else {
throw notEagler(buffer);
}
}
public static Uint16Array getDataView16Unsigned(ByteBuffer buffer) {
if(buffer instanceof EaglerArrayByteBuffer) {
EaglerArrayByteBuffer b = (EaglerArrayByteBuffer)buffer;
Int8Array d = b.typedArray;
int p = b.position;
return Uint16Array.create(d.getBuffer(), d.getByteOffset() + p, (b.limit - p) >> 1);
}else {
throw notEagler(buffer);
}
}
public static Float32Array getDataView32F(ByteBuffer buffer) {
if(buffer instanceof EaglerArrayByteBuffer) {
EaglerArrayByteBuffer b = (EaglerArrayByteBuffer)buffer;
Int8Array d = b.typedArray;
int p = b.position;
return Float32Array.create(d.getBuffer(), d.getByteOffset() + p, (b.limit - p) >> 2);
}else {
throw notEagler(buffer);
}
}
public static Int32Array getDataView32(IntBuffer buffer) {
if(buffer instanceof EaglerArrayIntBuffer) {
EaglerArrayIntBuffer b = (EaglerArrayIntBuffer)buffer;
Int32Array d = b.typedArray;
int p = b.position;
int l = b.limit;
if(p == 0 && l == b.capacity) {
return d;
}else {
return Int32Array.create(d.getBuffer(), d.getByteOffset() + (p << 2), l - p);
}
}else {
throw notEagler(buffer);
}
}
public static Uint8Array getDataView8Unsigned(IntBuffer buffer) {
if(buffer instanceof EaglerArrayIntBuffer) {
EaglerArrayIntBuffer b = (EaglerArrayIntBuffer)buffer;
Int32Array d = b.typedArray;
int p = b.position;
int l = b.limit;
return Uint8Array.create(d.getBuffer(), d.getByteOffset() + (p << 2), (l - p) << 2);
}else {
throw notEagler(buffer);
}
}
public static Float32Array getDataView32F(FloatBuffer buffer) {
if(buffer instanceof EaglerArrayFloatBuffer) {
EaglerArrayFloatBuffer b = (EaglerArrayFloatBuffer)buffer;
Float32Array d = b.typedArray;
int p = b.position;
int l = b.limit;
if(p == 0 && l == b.capacity) {
return d;
}else {
return Float32Array.create(d.getBuffer(), d.getByteOffset() + (p << 2), l - p);
}
}else {
throw notEagler(buffer);
}
}
public static Uint8Array getDataView8Unsigned(FloatBuffer buffer) {
if(buffer instanceof EaglerArrayFloatBuffer) {
EaglerArrayFloatBuffer b = (EaglerArrayFloatBuffer)buffer;
Float32Array d = b.typedArray;
int p = b.position;
int l = b.limit;
return Uint8Array.create(d.getBuffer(), d.getByteOffset() + (p << 2), (l - p) << 2);
}else {
throw notEagler(buffer);
}
}
private static WrongBufferClassType notEagler(Object clazz) {
return new WrongBufferClassType("Tried to pass a " + clazz.getClass().getSimpleName() + " which is not a native eagler buffer");
}
}

View File

@ -0,0 +1,411 @@
package net.lax1dude.eaglercraft.internal.buffer;
import org.teavm.jso.typedarrays.DataView;
import org.teavm.jso.typedarrays.Float32Array;
import org.teavm.jso.typedarrays.Int16Array;
import org.teavm.jso.typedarrays.Int32Array;
import org.teavm.jso.typedarrays.Int8Array;
import net.PeytonPlayz585.opengl.GL11;
/**
* Copyright (c) 2022-2023 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerArrayByteBuffer implements ByteBuffer {
final DataView dataView;
final Int8Array typedArray;
final int capacity;
int position;
int limit;
int mark;
EaglerArrayByteBuffer(DataView dataView) {
this.dataView = dataView;
this.typedArray = Int8Array.create(dataView.getBuffer(), dataView.getByteOffset(), dataView.getByteLength());
this.capacity = dataView.getByteLength();
this.position = 0;
this.limit = this.capacity;
this.mark = -1;
}
EaglerArrayByteBuffer(DataView dataView, int position, int limit, int mark) {
this.dataView = dataView;
this.typedArray = Int8Array.create(dataView.getBuffer(), dataView.getByteOffset(), dataView.getByteLength());
this.capacity = dataView.getByteLength();
this.position = position;
this.limit = limit;
this.mark = mark;
}
EaglerArrayByteBuffer(Int8Array typedArray) {
this.typedArray = typedArray;
this.dataView = DataView.create(typedArray.getBuffer(), typedArray.getByteOffset(), typedArray.getByteLength());
this.capacity = typedArray.getByteLength();
this.position = 0;
this.limit = this.capacity;
this.mark = -1;
}
EaglerArrayByteBuffer(Int8Array typedArray, int position, int limit, int mark) {
this.typedArray = typedArray;
this.dataView = DataView.create(typedArray.getBuffer(), typedArray.getByteOffset(), typedArray.getByteLength());
this.capacity = typedArray.getByteLength();
this.position = position;
this.limit = limit;
this.mark = mark;
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return limit > position;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public byte[] array() {
throw new UnsupportedOperationException();
}
@Override
public boolean isDirect() {
return true;
}
@Override
public ByteBuffer duplicate() {
return new EaglerArrayByteBuffer(dataView, position, limit, mark);
}
@Override
public byte get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return typedArray.get(position++);
}
@Override
public ByteBuffer put(byte b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
typedArray.set(position++, b);
return this;
}
@Override
public byte get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return typedArray.get(index);
}
@Override
public ByteBuffer put(int index, byte b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
typedArray.set(index, b);
return this;
}
@Override
public ByteBuffer get(byte[] dst, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
GL11.EaglerAdapterImpl2.TeaVMUtils.unwrapArrayBufferView(dst).set(Int8Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + position, length), offset);
position += length;
return this;
}
@Override
public ByteBuffer get(byte[] dst) {
if(position + dst.length > limit) throw Buffer.makeIOOBE(position + dst.length - 1);
GL11.EaglerAdapterImpl2.TeaVMUtils.unwrapArrayBufferView(dst).set(Int8Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + position, dst.length));
position += dst.length;
return this;
}
@Override
public ByteBuffer put(ByteBuffer src) {
if(src instanceof EaglerArrayByteBuffer) {
EaglerArrayByteBuffer c = (EaglerArrayByteBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
typedArray.set(Int8Array.create(c.typedArray.getBuffer(), c.typedArray.getByteOffset() + c.position, l), position);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
dataView.setInt8(position + l, src.get());
}
position += l;
}
return this;
}
@Override
public ByteBuffer put(byte[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
if(offset == 0 && length == src.length) {
typedArray.set( GL11.EaglerAdapterImpl2.TeaVMUtils.unwrapArrayBufferView(src), position);
}else {
typedArray.set(Int8Array.create(GL11.EaglerAdapterImpl2.TeaVMUtils.unwrapArrayBuffer(src), offset, length), position);
}
position += length;
return this;
}
@Override
public ByteBuffer put(byte[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
typedArray.set(GL11.EaglerAdapterImpl2.TeaVMUtils.unwrapArrayBufferView(src), position);
position += src.length;
return this;
}
@Override
public char getChar() {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
char c = (char)dataView.getUint16(position, true);
position += 2;
return c;
}
@Override
public ByteBuffer putChar(char value) {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
dataView.setUint16(position, (short)value, true);
position += 2;
return this;
}
@Override
public char getChar(int index) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
return (char)dataView.getUint16(index, true);
}
@Override
public ByteBuffer putChar(int index, char value) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
dataView.setUint16(index, value, true);
return this;
}
@Override
public short getShort() {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
short s = dataView.getInt16(position, true);
position += 2;
return s;
}
@Override
public ByteBuffer putShort(short value) {
if(position + 2 > limit) throw Buffer.makeIOOBE(position);
dataView.setInt16(position, value, true);
position += 2;
return this;
}
@Override
public short getShort(int index) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
return dataView.getInt16(index, true);
}
@Override
public ByteBuffer putShort(int index, short value) {
if(index < 0 || index + 2 > limit) throw Buffer.makeIOOBE(index);
dataView.setInt16(index, value, true);
return this;
}
@Override
public ShortBuffer asShortBuffer() {
return new EaglerArrayShortBuffer(Int16Array.create(typedArray.getBuffer(), typedArray.getByteOffset(), typedArray.getLength() >> 1));
}
@Override
public int getInt() {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
int i = dataView.getInt32(position, true);
position += 4;
return i;
}
@Override
public ByteBuffer putInt(int value) {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
dataView.setInt32(position, value, true);
position += 4;
return this;
}
@Override
public int getInt(int index) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
return dataView.getInt32(index, true);
}
@Override
public ByteBuffer putInt(int index, int value) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
dataView.setInt32(index, value, true);
return this;
}
@Override
public IntBuffer asIntBuffer() {
return new EaglerArrayIntBuffer(Int32Array.create(typedArray.getBuffer(), typedArray.getByteOffset(), typedArray.getLength() >> 2));
}
@Override
public long getLong() {
if(position + 8 > limit) throw Buffer.makeIOOBE(position);
long l = (long)dataView.getUint32(position, true) | ((long) dataView.getUint32(position + 4) << 32l);
position += 8;
return l;
}
@Override
public ByteBuffer putLong(long value) {
if(position + 8 > limit) throw Buffer.makeIOOBE(position);
dataView.setUint32(position, (int) (value & 0xFFFFFFFFl), true);
dataView.setUint32(position + 4, (int) (value >>> 32l), true);
position += 8;
return this;
}
@Override
public long getLong(int index) {
if(index < 0 || index + 8 > limit) throw Buffer.makeIOOBE(index);
return (long)dataView.getUint32(index, true) | ((long) dataView.getUint32(index + 4) << 32l);
}
@Override
public ByteBuffer putLong(int index, long value) {
if(index < 0 || index + 8 > limit) throw Buffer.makeIOOBE(index);
dataView.setUint32(index, (int) (value & 0xFFFFFFFFl), true);
dataView.setUint32(index + 4, (int) (value >>> 32l), true);
return this;
}
@Override
public float getFloat() {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
float f = dataView.getFloat32(position, true);
position += 4;
return f;
}
@Override
public ByteBuffer putFloat(float value) {
if(position + 4 > limit) throw Buffer.makeIOOBE(position);
dataView.setFloat32(position, value, true);
position += 4;
return this;
}
@Override
public float getFloat(int index) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
return dataView.getFloat32(index, true);
}
@Override
public ByteBuffer putFloat(int index, float value) {
if(index < 0 || index + 4 > limit) throw Buffer.makeIOOBE(index);
dataView.setFloat32(index, value, true);
return this;
}
@Override
public FloatBuffer asFloatBuffer() {
return new EaglerArrayFloatBuffer(Float32Array.create(typedArray.getBuffer(), typedArray.getByteOffset(), typedArray.getLength() >> 2));
}
@Override
public ByteBuffer mark() {
mark = position;
return this;
}
@Override
public ByteBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public ByteBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public ByteBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public ByteBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public ByteBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public ByteBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -0,0 +1,239 @@
package net.lax1dude.eaglercraft.internal.buffer;
import org.teavm.jso.typedarrays.Float32Array;
import static net.PeytonPlayz585.opengl.GL11.EaglerAdapterImpl2.TeaVMUtils;
/**
* Copyright (c) 2022-2023 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerArrayFloatBuffer implements FloatBuffer {
final Float32Array typedArray;
final int capacity;
int position;
int limit;
int mark;
private static final int SHIFT = 2;
EaglerArrayFloatBuffer(Float32Array typedArray) {
this.typedArray = typedArray;
this.capacity = typedArray.getLength();
this.position = 0;
this.limit = this.capacity;
this.mark = -1;
}
EaglerArrayFloatBuffer(Float32Array typedArray, int position, int limit, int mark) {
this.typedArray = typedArray;
this.capacity = typedArray.getLength();
this.position = position;
this.limit = limit;
this.mark = mark;
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return position < limit;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public float[] array() {
throw new UnsupportedOperationException();
}
@Override
public FloatBuffer duplicate() {
return new EaglerArrayFloatBuffer(typedArray, position, limit, mark);
}
@Override
public float get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return typedArray.get(position++);
}
@Override
public FloatBuffer put(float b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
typedArray.set(position++, b);
return this;
}
@Override
public float get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return typedArray.get(index);
}
@Override
public FloatBuffer put(int index, float b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
typedArray.set(index, b);
return this;
}
@Override
public float getElement(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return typedArray.get(index);
}
@Override
public void putElement(int index, float value) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
typedArray.set(index, value);
}
@Override
public FloatBuffer get(float[] dst, int offset, int length) {
if(position + length > limit) Buffer.makeIOOBE(position + length - 1);
TeaVMUtils.unwrapArrayBufferView(dst).set(Float32Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + (position << SHIFT), length), offset);
position += length;
return this;
}
@Override
public FloatBuffer get(float[] dst) {
if(position + dst.length > limit) Buffer.makeIOOBE(position + dst.length - 1);
TeaVMUtils.unwrapArrayBufferView(dst).set(Float32Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + (position << SHIFT), dst.length));
position += dst.length;
return this;
}
@Override
public FloatBuffer put(FloatBuffer src) {
if(src instanceof EaglerArrayFloatBuffer) {
EaglerArrayFloatBuffer c = (EaglerArrayFloatBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
typedArray.set(Float32Array.create(c.typedArray.getBuffer(), c.typedArray.getByteOffset() + (c.position << SHIFT), l), position);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
typedArray.set(position + l, src.get());
}
position += l;
}
return this;
}
@Override
public FloatBuffer put(float[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
if(offset == 0 && length == src.length) {
typedArray.set(TeaVMUtils.unwrapArrayBufferView(src), position);
}else {
typedArray.set(Float32Array.create(TeaVMUtils.unwrapArrayBuffer(src), offset << SHIFT, length), position);
}
position += length;
return this;
}
@Override
public FloatBuffer put(float[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
typedArray.set(TeaVMUtils.unwrapArrayBufferView(src), position);
position += src.length;
return this;
}
@Override
public boolean isDirect() {
return true;
}
@Override
public FloatBuffer mark() {
mark = position;
return this;
}
@Override
public FloatBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public FloatBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public FloatBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public FloatBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public FloatBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public FloatBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -0,0 +1,246 @@
package net.lax1dude.eaglercraft.internal.buffer;
import org.teavm.jso.typedarrays.Int32Array;
import static net.PeytonPlayz585.opengl.GL11.EaglerAdapterImpl2.TeaVMUtils;
/**
* Copyright (c) 2022-2023 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerArrayIntBuffer implements IntBuffer {
final Int32Array typedArray;
final int capacity;
int position;
int limit;
int mark;
private static final int SHIFT = 2;
EaglerArrayIntBuffer(Int32Array typedArray) {
this.typedArray = typedArray;
this.capacity = typedArray.getLength();
this.position = 0;
this.limit = this.capacity;
this.mark = -1;
}
EaglerArrayIntBuffer(Int32Array typedArray, int position, int limit, int mark) {
this.typedArray = typedArray;
this.capacity = typedArray.getLength();
this.position = position;
this.limit = limit;
this.mark = mark;
}
//!?!?
public static IntBuffer wrap(int[] buffer) {
Int32Array array = Int32Array.create(buffer.length);
array.set(buffer);
return new EaglerArrayIntBuffer(array);
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return position < limit;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public int[] array() {
throw new UnsupportedOperationException();
}
@Override
public IntBuffer duplicate() {
return new EaglerArrayIntBuffer(typedArray, position, limit, mark);
}
@Override
public int get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return typedArray.get(position++);
}
@Override
public IntBuffer put(int b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
typedArray.set(position++, b);
return this;
}
@Override
public int get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return typedArray.get(index);
}
@Override
public IntBuffer put(int index, int b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
typedArray.set(index, b);
return this;
}
@Override
public int getElement(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return typedArray.get(index);
}
@Override
public void putElement(int index, int value) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
typedArray.set(index, value);
}
@Override
public IntBuffer get(int[] dst, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
TeaVMUtils.unwrapArrayBufferView(dst).set(Int32Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + (position << SHIFT), length), offset);
position += length;
return this;
}
@Override
public IntBuffer get(int[] dst) {
if(position + dst.length > limit) throw Buffer.makeIOOBE(position + dst.length - 1);
TeaVMUtils.unwrapArrayBufferView(dst).set(Int32Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + (position << SHIFT), dst.length));
position += dst.length;
return this;
}
@Override
public IntBuffer put(IntBuffer src) {
if(src instanceof EaglerArrayIntBuffer) {
EaglerArrayIntBuffer c = (EaglerArrayIntBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
typedArray.set(Int32Array.create(c.typedArray.getBuffer(), c.typedArray.getByteOffset() + (c.position << SHIFT), l), position);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
typedArray.set(position + l, src.get());
}
position += l;
}
return this;
}
@Override
public IntBuffer put(int[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
if(offset == 0 && length == src.length) {
typedArray.set(TeaVMUtils.unwrapArrayBufferView(src), position);
}else {
typedArray.set(Int32Array.create(TeaVMUtils.unwrapArrayBuffer(src), offset << SHIFT, length), position);
}
position += length;
return this;
}
@Override
public IntBuffer put(int[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
typedArray.set(TeaVMUtils.unwrapArrayBufferView(src), position);
position += src.length;
return this;
}
@Override
public boolean isDirect() {
return true;
}
@Override
public IntBuffer mark() {
mark = position;
return this;
}
@Override
public IntBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public IntBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public IntBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public IntBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public IntBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public IntBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -0,0 +1,238 @@
package net.lax1dude.eaglercraft.internal.buffer;
import org.teavm.jso.typedarrays.Int16Array;
import static net.PeytonPlayz585.opengl.GL11.EaglerAdapterImpl2.TeaVMUtils;
/**
* Copyright (c) 2022-2023 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class EaglerArrayShortBuffer implements ShortBuffer {
final Int16Array typedArray;
final int capacity;
int position;
int limit;
int mark;
private static final int SHIFT = 1;
EaglerArrayShortBuffer(Int16Array typedArray) {
this.typedArray = typedArray;
this.capacity = typedArray.getLength();
this.position = 0;
this.limit = this.capacity;
this.mark = -1;
}
EaglerArrayShortBuffer(Int16Array typedArray, int position, int limit, int mark) {
this.typedArray = typedArray;
this.capacity = typedArray.getLength();
this.position = position;
this.limit = limit;
this.mark = mark;
}
@Override
public int capacity() {
return capacity;
}
@Override
public int position() {
return position;
}
@Override
public int limit() {
return limit;
}
@Override
public int remaining() {
return limit - position;
}
@Override
public boolean hasRemaining() {
return position < limit;
}
@Override
public boolean hasArray() {
return false;
}
@Override
public short[] array() {
throw new UnsupportedOperationException();
}
@Override
public ShortBuffer duplicate() {
return new EaglerArrayShortBuffer(typedArray, position, limit, mark);
}
@Override
public short get() {
if(position >= limit) throw Buffer.makeIOOBE(position);
return typedArray.get(position++);
}
@Override
public ShortBuffer put(short b) {
if(position >= limit) throw Buffer.makeIOOBE(position);
typedArray.set(position++, b);
return this;
}
@Override
public short get(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return typedArray.get(index);
}
@Override
public ShortBuffer put(int index, short b) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
typedArray.set(index, b);
return this;
}
@Override
public short getElement(int index) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
return typedArray.get(index);
}
@Override
public void putElement(int index, short value) {
if(index < 0 || index >= limit) throw Buffer.makeIOOBE(index);
typedArray.set(index, value);
}
@Override
public ShortBuffer get(short[] dst, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
TeaVMUtils.unwrapArrayBufferView(dst).set(Int16Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + (position << SHIFT), length), offset);
position += length;
return this;
}
@Override
public ShortBuffer get(short[] dst) {
if(position + dst.length > limit) throw Buffer.makeIOOBE(position + dst.length - 1);
TeaVMUtils.unwrapArrayBufferView(dst).set(Int16Array.create(typedArray.getBuffer(), typedArray.getByteOffset() + (position << SHIFT), dst.length));
position += dst.length;
return this;
}
@Override
public ShortBuffer put(ShortBuffer src) {
if(src instanceof EaglerArrayShortBuffer) {
EaglerArrayShortBuffer c = (EaglerArrayShortBuffer)src;
int l = c.limit - c.position;
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
typedArray.set(Int16Array.create(c.typedArray.getBuffer(), c.typedArray.getByteOffset() + (c.position << SHIFT), l), position);
position += l;
c.position += l;
}else {
int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) {
typedArray.set(position + l, src.get());
}
position += l;
}
return this;
}
@Override
public ShortBuffer put(short[] src, int offset, int length) {
if(position + length > limit) throw Buffer.makeIOOBE(position + length - 1);
if(offset == 0 && length == src.length) {
typedArray.set(TeaVMUtils.unwrapArrayBufferView(src), position);
}else {
typedArray.set(Int16Array.create(TeaVMUtils.unwrapArrayBuffer(src), offset << SHIFT, length), position);
}
position += length;
return this;
}
@Override
public ShortBuffer put(short[] src) {
if(position + src.length > limit) throw Buffer.makeIOOBE(position + src.length - 1);
typedArray.set(TeaVMUtils.unwrapArrayBufferView(src), position);
position += src.length;
return this;
}
@Override
public boolean isDirect() {
return true;
}
@Override
public ShortBuffer mark() {
mark = position;
return this;
}
@Override
public ShortBuffer reset() {
int m = mark;
if(m < 0) throw new IndexOutOfBoundsException("Invalid mark: " + m);
position = m;
return this;
}
@Override
public ShortBuffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
@Override
public ShortBuffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
@Override
public ShortBuffer rewind() {
position = 0;
mark = -1;
return this;
}
@Override
public ShortBuffer limit(int newLimit) {
if(newLimit < 0 || newLimit > capacity) throw Buffer.makeIOOBE(newLimit);
limit = newLimit;
return this;
}
@Override
public ShortBuffer position(int newPosition) {
if(newPosition < 0 || newPosition > limit) throw Buffer.makeIOOBE(newPosition);
position = newPosition;
return this;
}
}

View File

@ -0,0 +1,26 @@
package net.lax1dude.eaglercraft.internal.teavm;
import org.teavm.jso.JSObject;
/**
* Copyright (c) 2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public interface ImmediateContinue {
public boolean isValidToken(JSObject someObject);
public void execute();
}

View File

@ -0,0 +1,37 @@
package net.lax1dude.eaglercraft.internal.teavm;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
import org.teavm.jso.workers.MessagePort;
/**
* Copyright (c) 2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public abstract class MessageChannel implements JSObject {
@JSBody(params = { }, script = "return (typeof MessageChannel !== \"undefined\");")
public static native boolean supported();
@JSBody(params = { }, script = "return new MessageChannel();")
public static native MessageChannel create();
@JSProperty
public abstract MessagePort getPort1();
@JSProperty
public abstract MessagePort getPort2();
}

View File

@ -0,0 +1,166 @@
package net.lax1dude.eaglercraft.internal.teavm;
import java.io.IOException;
import org.teavm.backend.javascript.codegen.SourceWriter;
import org.teavm.backend.javascript.spi.Generator;
import org.teavm.backend.javascript.spi.GeneratorContext;
import org.teavm.backend.javascript.spi.Injector;
import org.teavm.backend.javascript.spi.InjectorContext;
import org.teavm.model.MethodReference;
/**
* Copyright (c) 2024 lax1dude. All Rights Reserved.
*
* 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 HOLDER 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.
*
*/
public class TeaVMUtilsUnwrapGenerator {
// WARNING: This code uses internal TeaVM APIs that may not have
// been intended for end users of the compiler to program with
public static class UnwrapArrayBuffer implements Injector {
@Override
public void generate(InjectorContext context, MethodReference methodRef) throws IOException {
context.writeExpr(context.getArgument(0));
context.getWriter().append(".data.buffer");
}
}
public static class UnwrapTypedArray implements Injector {
@Override
public void generate(InjectorContext context, MethodReference methodRef) throws IOException {
context.writeExpr(context.getArgument(0));
context.getWriter().append(".data");
}
}
public static class WrapArrayBuffer implements Generator {
@Override
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef)
throws IOException {
String parName = context.getParameterName(1);
switch (methodRef.getName()) {
case "wrapByteArrayBuffer":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_bytecls(),").ws().append("new Int8Array(").append(parName).append("))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapIntArrayBuffer":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_intcls(),").ws().append("new Int32Array(").append(parName).append("))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapFloatArrayBuffer":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_floatcls(),").ws().append("new Float32Array(").append(parName).append("))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapShortArrayBuffer":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_shortcls(),").ws().append("new Int16Array(").append(parName).append("))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
default:
break;
}
}
}
public static class WrapArrayBufferView implements Generator {
@Override
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef)
throws IOException {
String parName = context.getParameterName(1);
switch (methodRef.getName()) {
case "wrapByteArrayBufferView":
case "wrapUnsignedByteArray":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_bytecls(),").ws().append("new Int8Array(").append(parName).append(".buffer))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapIntArrayBufferView":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_intcls(),").ws().append("new Int32Array(").append(parName).append(".buffer))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapFloatArrayBufferView":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_floatcls(),").ws().append("new Float32Array(").append(parName).append(".buffer))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapShortArrayBufferView":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_shortcls(),").ws().append("new Int16Array(").append(parName).append(".buffer))").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
default:
break;
}
}
}
public static class WrapTypedArray implements Generator {
@Override
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef)
throws IOException {
String parName = context.getParameterName(1);
switch (methodRef.getName()) {
case "wrapByteArray":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_bytecls(),").ws().append(parName).append(")").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapIntArray":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_intcls(),").ws().append(parName).append(")").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapFloatArray":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_floatcls(),").ws().append(parName).append(")").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
case "wrapShortArray":
writer.append("return ").append(parName).ws().append('?').ws();
writer.append("$rt_createNumericArray($rt_shortcls(),").ws().append(parName).append(")").ws();
writer.append(':').ws().append("null;").softNewLine();
break;
default:
break;
}
}
}
public static class UnwrapUnsignedTypedArray implements Injector {
@Override
public void generate(InjectorContext context, MethodReference methodRef) throws IOException {
context.getWriter().append("new Uint8Array(");
context.writeExpr(context.getArgument(0));
context.getWriter().append(".data.buffer)");
}
}
}