TeaVM OpenGL Emulator
Made a OpenGL Emulator for WebGL using TeaVM
This commit is contained in:
parent
2d2d087441
commit
47b06dbdbd
17
.classpath
Normal file
17
.classpath
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test,teavm"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
6
.gitattributes
vendored
Normal file
6
.gitattributes
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
33
.project
Normal file
33
.project
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Minecraft-Classic-Browser</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
13
.settings/org.eclipse.buildship.core.prefs
Normal file
13
.settings/org.eclipse.buildship.core.prefs
Normal file
|
@ -0,0 +1,13 @@
|
|||
arguments=
|
||||
auto.sync=false
|
||||
build.scans.enabled=false
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=
|
||||
eclipse.preferences.version=1
|
||||
gradle.user.home=
|
||||
java.home=
|
||||
jvm.arguments=
|
||||
offline.mode=false
|
||||
override.workspace.settings=false
|
||||
show.console.view=false
|
||||
show.executions.view=false
|
BIN
bin/main/net/PeytonPlayz585/glemu/FixedFunctionShader.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/FixedFunctionShader.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/GLObjectMap.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/GLObjectMap.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix2f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix2f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix3f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix3f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix4f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Matrix4f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Quaternion.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Quaternion.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector2f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector2f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector3f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector3f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector4f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector4f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector2f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector2f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector3f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector3f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector4f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/Vector4f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/WritableVector2f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/WritableVector2f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/WritableVector3f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/WritableVector3f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/glemu/vector/WritableVector4f.class
Normal file
BIN
bin/main/net/PeytonPlayz585/glemu/vector/WritableVector4f.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferArrayGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferArrayGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$FramebufferGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$FramebufferGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ProgramGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ProgramGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$QueryGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$QueryGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$RenderbufferGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$RenderbufferGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ShaderGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ShaderGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$TextureGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$TextureGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$UniformGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL$UniformGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGL.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$1.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$1.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$2.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$2.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.class
Normal file
BIN
bin/main/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/main/MinecraftMain$1.class
Normal file
BIN
bin/main/net/PeytonPlayz585/main/MinecraftMain$1.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/main/MinecraftMain.class
Normal file
BIN
bin/main/net/PeytonPlayz585/main/MinecraftMain.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/Base64.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/Base64.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$Context.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$Context.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/BaseNCodec.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/BaseNCodec.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/GLAllocation.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/GLAllocation.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/GeneralDigest.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/GeneralDigest.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/GlStateManager.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/GlStateManager.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/MinecraftClient.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/MinecraftClient.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/MinecraftImage.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/MinecraftImage.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/minecraft/SHA1Digest.class
Normal file
BIN
bin/main/net/PeytonPlayz585/minecraft/SHA1Digest.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/teavm/WebGL2RenderingContext.class
Normal file
BIN
bin/main/net/PeytonPlayz585/teavm/WebGL2RenderingContext.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/teavm/WebGLQuery.class
Normal file
BIN
bin/main/net/PeytonPlayz585/teavm/WebGLQuery.class
Normal file
Binary file not shown.
BIN
bin/main/net/PeytonPlayz585/teavm/WebGLVertexArray.class
Normal file
BIN
bin/main/net/PeytonPlayz585/teavm/WebGLVertexArray.class
Normal file
Binary file not shown.
BIN
bin/main/org/lwjgl/opengl/GL11.class
Normal file
BIN
bin/main/org/lwjgl/opengl/GL11.class
Normal file
Binary file not shown.
84
build.gradle
Normal file
84
build.gradle
Normal file
|
@ -0,0 +1,84 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'io.github.zebalu:teavm-gradle-plugin:1.0.0'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'io.github.zebalu.teavm-gradle-plugin'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDir 'src/main/java'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
/** we use 0.6.1 due to performance issues on 7.0.0 */
|
||||
implementation 'org.teavm:teavm-platform:0.6.1'
|
||||
implementation('org.teavm:teavm-classlib:0.6.1') {
|
||||
exclude group: 'com.google.code.gson', module: 'gson'
|
||||
}
|
||||
}
|
||||
|
||||
teavm {
|
||||
|
||||
compileScopes = null;
|
||||
minifying = true;
|
||||
maxTopLevelNames = 10000;
|
||||
properties = null;
|
||||
debugInformationGenerated = false;
|
||||
sourceMapsGenerated = true;
|
||||
sourceFilesCopied = false;
|
||||
incremental = false;
|
||||
transformers = null;
|
||||
|
||||
/** Where to save the result */
|
||||
targetDirectory = file("js");
|
||||
|
||||
/** The directory to monitor to decide if compile is up-to-date or not */
|
||||
sourceDirectory = file("src");
|
||||
|
||||
/** How to name the result file. */
|
||||
targetFileName = "app.js";
|
||||
|
||||
/** Which class holds your public static void main(Strin[] args) method */
|
||||
mainClass = 'net.PeytonPlayz585.main.MinecraftMain';
|
||||
|
||||
/** This will be the name of your main method after compilation. */
|
||||
entryPointName = 'main';
|
||||
|
||||
classesToPreserve = null;
|
||||
stopOnErrors = false;
|
||||
optimizationLevel = "ADVANCED"; //org.teavm.vm.TeaVMOptimizationLevel.SIMPLE;
|
||||
fastGlobalAnalysis = false;
|
||||
targetType = "JAVASCRIPT"; //org.teavm.tooling.TeaVMTargetType.JAVASCRIPT;
|
||||
cacheDirectory = null;
|
||||
wasmVersion = "V_0x1"; //org.teavm.backend.wasm.render.WasmBinaryVersion.V_0x1;
|
||||
minHeapSize = 4;
|
||||
maxHeapSize = 128;
|
||||
outOfProcess = false;
|
||||
processMemory = 512;
|
||||
longjmpSupported = true;
|
||||
heapDump = false;
|
||||
|
||||
/** Add name of configurations here where to look for jarfiles. */
|
||||
includeJarsFrom = [];
|
||||
|
||||
/** By default teavmc taskd epends on javaCompile task, unless this varaibale is true. */
|
||||
skipJavaCompile = false;
|
||||
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
234
gradlew
vendored
Executable file
234
gradlew
vendored
Executable file
|
@ -0,0 +1,234 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
624
js/app.js
Normal file
624
js/app.js
Normal file
|
@ -0,0 +1,624 @@
|
|||
"use strict";
|
||||
var main;(function(){
|
||||
var $rt_seed=2463534242;function $rt_nextId(){var x=$rt_seed;x^=x<<13;x^=x>>17;x^=x<<5;$rt_seed=x;return x;}function $rt_compare(a,b){return a>b?1:a<b? -1:a===b?0:1;}function $rt_isInstance(obj,cls){return obj!==null&&!!obj.constructor.$meta&&$rt_isAssignable(obj.constructor,cls);}function $rt_isAssignable(from,to){if(from===to){return true;}if(to.$meta.item!==null){return from.$meta.item!==null&&$rt_isAssignable(from.$meta.item,to.$meta.item);}var supertypes=from.$meta.supertypes;for(var i=0;i<supertypes.length;i
|
||||
=i+1|0){if($rt_isAssignable(supertypes[i],to)){return true;}}return false;}function $rt_createArray(cls,sz){var data=new Array(sz);var arr=new $rt_array(cls,data);if(sz>0){var i=0;do {data[i]=null;i=i+1|0;}while(i<sz);}return arr;}function $rt_wrapArray(cls,data){return new $rt_array(cls,data);}function $rt_createUnfilledArray(cls,sz){return new $rt_array(cls,new Array(sz));}function $rt_createLongArray(sz){var data=new Array(sz);var arr=new $rt_array($rt_longcls(),data);for(var i=0;i<sz;i=i+1|0){data[i]=Long_ZERO;}return arr;}function $rt_createNumericArray(cls,
|
||||
nativeArray){return new $rt_array(cls,nativeArray);}function $rt_createCharArray(sz){return $rt_createNumericArray($rt_charcls(),new Uint16Array(sz));}function $rt_createByteArray(sz){return $rt_createNumericArray($rt_bytecls(),new Int8Array(sz));}function $rt_createShortArray(sz){return $rt_createNumericArray($rt_shortcls(),new Int16Array(sz));}function $rt_createIntArray(sz){return $rt_createNumericArray($rt_intcls(),new Int32Array(sz));}function $rt_createBooleanArray(sz){return $rt_createNumericArray($rt_booleancls(),
|
||||
new Int8Array(sz));}function $rt_createFloatArray(sz){return $rt_createNumericArray($rt_floatcls(),new Float32Array(sz));}function $rt_createDoubleArray(sz){return $rt_createNumericArray($rt_doublecls(),new Float64Array(sz));}function $rt_arraycls(cls){var result=cls.$array;if(result===null){var arraycls={};var name="["+cls.$meta.binaryName;arraycls.$meta={item:cls,supertypes:[$rt_objcls()],primitive:false,superclass:$rt_objcls(),name:name,binaryName:name,enum:false};arraycls.classObject=null;arraycls.$array
|
||||
=null;result=arraycls;cls.$array=arraycls;}return result;}function $rt_createcls(){return {$array:null,classObject:null,$meta:{supertypes:[],superclass:null}};}function $rt_createPrimitiveCls(name,binaryName){var cls=$rt_createcls();cls.$meta.primitive=true;cls.$meta.name=name;cls.$meta.binaryName=binaryName;cls.$meta.enum=false;cls.$meta.item=null;return cls;}var $rt_booleanclsCache=null;function $rt_booleancls(){if($rt_booleanclsCache===null){$rt_booleanclsCache=$rt_createPrimitiveCls("boolean","Z");}return $rt_booleanclsCache;}var $rt_charclsCache
|
||||
=null;function $rt_charcls(){if($rt_charclsCache===null){$rt_charclsCache=$rt_createPrimitiveCls("char","C");}return $rt_charclsCache;}var $rt_byteclsCache=null;function $rt_bytecls(){if($rt_byteclsCache===null){$rt_byteclsCache=$rt_createPrimitiveCls("byte","B");}return $rt_byteclsCache;}var $rt_shortclsCache=null;function $rt_shortcls(){if($rt_shortclsCache===null){$rt_shortclsCache=$rt_createPrimitiveCls("short","S");}return $rt_shortclsCache;}var $rt_intclsCache=null;function $rt_intcls(){if($rt_intclsCache
|
||||
===null){$rt_intclsCache=$rt_createPrimitiveCls("int","I");}return $rt_intclsCache;}var $rt_longclsCache=null;function $rt_longcls(){if($rt_longclsCache===null){$rt_longclsCache=$rt_createPrimitiveCls("long","J");}return $rt_longclsCache;}var $rt_floatclsCache=null;function $rt_floatcls(){if($rt_floatclsCache===null){$rt_floatclsCache=$rt_createPrimitiveCls("float","F");}return $rt_floatclsCache;}var $rt_doubleclsCache=null;function $rt_doublecls(){if($rt_doubleclsCache===null){$rt_doubleclsCache=$rt_createPrimitiveCls("double",
|
||||
"D");}return $rt_doubleclsCache;}var $rt_voidclsCache=null;function $rt_voidcls(){if($rt_voidclsCache===null){$rt_voidclsCache=$rt_createPrimitiveCls("void","V");}return $rt_voidclsCache;}function $rt_throw(ex){throw $rt_exception(ex);}function $rt_exception(ex){var err=ex.$jsException;if(!err){err=new Error("Java exception thrown");if(typeof Error.captureStackTrace==="function"){Error.captureStackTrace(err);}err.$javaException=ex;ex.$jsException=err;$rt_fillStack(err,ex);}return err;}function $rt_fillStack(err,
|
||||
ex){if(typeof $rt_decodeStack==="function"&&err.stack){var stack=$rt_decodeStack(err.stack);var javaStack=$rt_createArray($rt_objcls(),stack.length);var elem;var noStack=false;for(var i=0;i<stack.length;++i){var element=stack[i];elem=$rt_createStackElement($rt_str(element.className),$rt_str(element.methodName),$rt_str(element.fileName),element.lineNumber);if(elem==null){noStack=true;break;}javaStack.data[i]=elem;}if(!noStack){$rt_setStack(ex,javaStack);}}}function $rt_createMultiArray(cls,dimensions){var first
|
||||
=0;for(var i=dimensions.length -1;i>=0;i=i -1|0){if(dimensions[i]===0){first=i;break;}}if(first>0){for(i=0;i<first;i=i+1|0){cls=$rt_arraycls(cls);}if(first===dimensions.length -1){return $rt_createArray(cls,dimensions[first]);}}var arrays=new Array($rt_primitiveArrayCount(dimensions,first));var firstDim=dimensions[first]|0;for(i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createArray(cls,firstDim);}return $rt_createMultiArrayImpl(cls,arrays,dimensions,first);}function $rt_createByteMultiArray(dimensions){var arrays
|
||||
=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_bytecls(),dimensions);}var firstDim=dimensions[0]|0;for(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createByteArray(firstDim);}return $rt_createMultiArrayImpl($rt_bytecls(),arrays,dimensions);}function $rt_createCharMultiArray(dimensions){var arrays=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_charcls(),dimensions);}var firstDim=dimensions[0]|0;for
|
||||
(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createCharArray(firstDim);}return $rt_createMultiArrayImpl($rt_charcls(),arrays,dimensions,0);}function $rt_createBooleanMultiArray(dimensions){var arrays=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_booleancls(),dimensions);}var firstDim=dimensions[0]|0;for(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createBooleanArray(firstDim);}return $rt_createMultiArrayImpl($rt_booleancls(),arrays,dimensions,0);}function $rt_createShortMultiArray(dimensions)
|
||||
{var arrays=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_shortcls(),dimensions);}var firstDim=dimensions[0]|0;for(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createShortArray(firstDim);}return $rt_createMultiArrayImpl($rt_shortcls(),arrays,dimensions,0);}function $rt_createIntMultiArray(dimensions){var arrays=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_intcls(),dimensions);}var firstDim=dimensions[0]
|
||||
|0;for(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createIntArray(firstDim);}return $rt_createMultiArrayImpl($rt_intcls(),arrays,dimensions,0);}function $rt_createLongMultiArray(dimensions){var arrays=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_longcls(),dimensions);}var firstDim=dimensions[0]|0;for(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createLongArray(firstDim);}return $rt_createMultiArrayImpl($rt_longcls(),arrays,dimensions,0);}function $rt_createFloatMultiArray(dimensions)
|
||||
{var arrays=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_floatcls(),dimensions);}var firstDim=dimensions[0]|0;for(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createFloatArray(firstDim);}return $rt_createMultiArrayImpl($rt_floatcls(),arrays,dimensions,0);}function $rt_createDoubleMultiArray(dimensions){var arrays=new Array($rt_primitiveArrayCount(dimensions,0));if(arrays.length===0){return $rt_createMultiArray($rt_doublecls(),dimensions);}var firstDim
|
||||
=dimensions[0]|0;for(var i=0;i<arrays.length;i=i+1|0){arrays[i]=$rt_createDoubleArray(firstDim);}return $rt_createMultiArrayImpl($rt_doublecls(),arrays,dimensions,0);}function $rt_primitiveArrayCount(dimensions,start){var val=dimensions[start+1]|0;for(var i=start+2;i<dimensions.length;i=i+1|0){val=val*(dimensions[i]|0)|0;if(val===0){break;}}return val;}function $rt_createMultiArrayImpl(cls,arrays,dimensions,start){var limit=arrays.length;for(var i=start+1|0;i<dimensions.length;i=i+1|0){cls=$rt_arraycls(cls);var dim
|
||||
=dimensions[i];var index=0;var packedIndex=0;while(index<limit){var arr=$rt_createUnfilledArray(cls,dim);for(var j=0;j<dim;j=j+1|0){arr.data[j]=arrays[index];index=index+1|0;}arrays[packedIndex]=arr;packedIndex=packedIndex+1|0;}limit=packedIndex;}return arrays[0];}function $rt_assertNotNaN(value){if(typeof value==='number'&&isNaN(value)){throw "NaN";}return value;}var $rt_stdoutBuffer="";var $rt_putStdout=typeof $rt_putStdoutCustom==="function"?$rt_putStdoutCustom:function(ch){if(ch===0xA){if(console){console.info($rt_stdoutBuffer);}$rt_stdoutBuffer
|
||||
="";}else {$rt_stdoutBuffer+=String.fromCharCode(ch);}};var $rt_stderrBuffer="";var $rt_putStderr=typeof $rt_putStderrCustom==="function"?$rt_putStderrCustom:function(ch){if(ch===0xA){if(console){console.error($rt_stderrBuffer);}$rt_stderrBuffer="";}else {$rt_stderrBuffer+=String.fromCharCode(ch);}};var $rt_packageData=null;function $rt_packages(data){var i=0;var packages=new Array(data.length);for(var j=0;j<data.length;++j){var prefixIndex=data[i++];var prefix=prefixIndex>=0?packages[prefixIndex]:"";packages[j]
|
||||
=prefix+data[i++]+".";}$rt_packageData=packages;}function $rt_metadata(data){var packages=$rt_packageData;var i=0;while(i<data.length){var cls=data[i++];cls.$meta={};var m=cls.$meta;var className=data[i++];m.name=className!==0?className:null;if(m.name!==null){var packageIndex=data[i++];if(packageIndex>=0){m.name=packages[packageIndex]+m.name;}}m.binaryName="L"+m.name+";";var superclass=data[i++];m.superclass=superclass!==0?superclass:null;m.supertypes=data[i++];if(m.superclass){m.supertypes.push(m.superclass);cls.prototype
|
||||
=Object.create(m.superclass.prototype);}else {cls.prototype={};}var flags=data[i++];m.enum=(flags&8)!==0;m.flags=flags;m.primitive=false;m.item=null;cls.prototype.constructor=cls;cls.classObject=null;m.accessLevel=data[i++];var clinit=data[i++];cls.$clinit=clinit!==0?clinit:function(){};var virtualMethods=data[i++];if(virtualMethods!==0){for(var j=0;j<virtualMethods.length;j+=2){var name=virtualMethods[j];var func=virtualMethods[j+1];if(typeof name==='string'){name=[name];}for(var k=0;k<name.length;++k){cls.prototype[name[k]]
|
||||
=func;}}}cls.$array=null;}}function $rt_threadStarter(f){return function(){var args=Array.prototype.slice.apply(arguments);$rt_startThread(function(){f.apply(this,args);});};}function $rt_mainStarter(f){return function(args,callback){if(!args){args=[];}var javaArgs=$rt_createArray($rt_objcls(),args.length);for(var i=0;i<args.length;++i){javaArgs.data[i]=$rt_str(args[i]);}$rt_startThread(function(){f.call(null,javaArgs);},callback);};}var $rt_stringPool_instance;function $rt_stringPool(strings){$rt_stringPool_instance
|
||||
=new Array(strings.length);for(var i=0;i<strings.length;++i){$rt_stringPool_instance[i]=$rt_intern($rt_str(strings[i]));}}function $rt_s(index){return $rt_stringPool_instance[index];}function $rt_eraseClinit(target){return target.$clinit=function(){};}var $rt_numberConversionView=new DataView(new ArrayBuffer(8));function $rt_doubleToLongBits(n){$rt_numberConversionView.setFloat64(0,n,true);return new Long($rt_numberConversionView.getInt32(0,true),$rt_numberConversionView.getInt32(4,true));}function $rt_longBitsToDouble(n)
|
||||
{$rt_numberConversionView.setInt32(0,n.lo,true);$rt_numberConversionView.setInt32(4,n.hi,true);return $rt_numberConversionView.getFloat64(0,true);}function $rt_floatToIntBits(n){$rt_numberConversionView.setFloat32(0,n);return $rt_numberConversionView.getInt32(0);}function $rt_intBitsToFloat(n){$rt_numberConversionView.setInt32(0,n);return $rt_numberConversionView.getFloat32(0);}function $rt_javaException(e){return e instanceof Error&&typeof e.$javaException==='object'?e.$javaException:null;}function $rt_jsException(e)
|
||||
{return typeof e.$jsException==='object'?e.$jsException:null;}function $rt_wrapException(err){var ex=err.$javaException;if(!ex){ex=$rt_createException($rt_str("(JavaScript) "+err.toString()));err.$javaException=ex;ex.$jsException=err;$rt_fillStack(err,ex);}return ex;}function $dbg_class(obj){var cls=obj.constructor;var arrayDegree=0;while(cls.$meta&&cls.$meta.item){++arrayDegree;cls=cls.$meta.item;}var clsName="";if(cls===$rt_booleancls()){clsName="boolean";}else if(cls===$rt_bytecls()){clsName="byte";}else if
|
||||
(cls===$rt_shortcls()){clsName="short";}else if(cls===$rt_charcls()){clsName="char";}else if(cls===$rt_intcls()){clsName="int";}else if(cls===$rt_longcls()){clsName="long";}else if(cls===$rt_floatcls()){clsName="float";}else if(cls===$rt_doublecls()){clsName="double";}else {clsName=cls.$meta?cls.$meta.name||"a/"+cls.name:"@"+cls.name;}while(arrayDegree-->0){clsName+="[]";}return clsName;}function Long(lo,hi){this.lo=lo|0;this.hi=hi|0;}Long.prototype.__teavm_class__=function(){return "long";};Long.prototype.toString
|
||||
=function(){var result=[];var n=this;var positive=Long_isPositive(n);if(!positive){n=Long_neg(n);}var radix=new Long(10,0);do {var divRem=Long_divRem(n,radix);result.push(String.fromCharCode(48+divRem[1].lo));n=divRem[0];}while(n.lo!==0||n.hi!==0);result=(result.reverse()).join('');return positive?result:"-"+result;};Long.prototype.valueOf=function(){return Long_toNumber(this);};var Long_ZERO=new Long(0,0);var Long_MAX_NORMAL=1<<18;function Long_fromInt(val){return val>=0?new Long(val,0):new Long(val, -1);}function Long_fromNumber(val)
|
||||
{if(val>=0){return new Long(val|0,val/0x100000000|0);}else {return Long_neg(new Long( -val|0, -val/0x100000000|0));}}function Long_toNumber(val){var lo=val.lo;var hi=val.hi;if(lo<0){lo+=0x100000000;}return 0x100000000*hi+lo;}var $rt_imul=Math.imul||function(a,b){var ah=a>>>16&0xFFFF;var al=a&0xFFFF;var bh=b>>>16&0xFFFF;var bl=b&0xFFFF;return al*bl+(ah*bl+al*bh<<16>>>0)|0;};var $rt_udiv=function(a,b){if(a<0){a+=0x100000000;}if(b<0){b+=0x100000000;}return a/b|0;};var $rt_umod=function(a,b){if(a<0){a+=0x100000000;}if
|
||||
(b<0){b+=0x100000000;}return a%b|0;};function $rt_setCloneMethod(target, f){target.dE=f;}
|
||||
function $rt_cls(cls){return Fi(cls);}
|
||||
function $rt_str(str) {if (str === null) {return null;}var characters = $rt_createCharArray(str.length);var charsBuffer = characters.data;for (var i = 0; i < str.length; i = (i + 1) | 0) {charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;}return H5(characters);}
|
||||
function $rt_ustr(str) {if (str === null) {return null;}var data = str.t.data;var result = "";for (var i = 0; i < data.length; i = (i + 1) | 0) {result += String.fromCharCode(data[i]);}return result;}
|
||||
function $rt_objcls() { return C; }
|
||||
function $rt_nullCheck(val) {if (val === null) {$rt_throw(Ir());}return val;}
|
||||
function $rt_intern(str) {return str;}function $rt_getThread(){return null;}
|
||||
function $rt_setThread(t){}
|
||||
function $rt_createException(message){return Is(message);}
|
||||
function $rt_createStackElement(className,methodName,fileName,lineNumber){return null;}
|
||||
function $rt_setStack(e,stack){}
|
||||
var A=Object.create(null);
|
||||
var D=$rt_throw;var C6=$rt_compare;var It=$rt_nullCheck;var Bt=$rt_cls;var Bu=$rt_createArray;var H$=$rt_isInstance;var GH=$rt_nativeThread;var G7=$rt_suspending;var If=$rt_resuming;var H8=$rt_invalidPointer;var B=$rt_s;var S=$rt_eraseClinit;var Dm=$rt_imul;var U=$rt_wrapException;
|
||||
function C(){this.$id$=0;}
|
||||
function B1(a){return Fi(a.constructor);}
|
||||
function HF(a){var b,c,d,e,f,g,h,i;b=F(F(N(),D6(B1(a))),B(0));c=EB(a);if(!c)d=B(1);else{if(!c)e=32;else{f=0;e=c>>>16;if(e)f=16;else e=c;g=e>>>8;if(!g)g=e;else f=f|8;e=g>>>4;if(!e)e=g;else f=f|4;g=e>>>2;if(!g)g=e;else f=f|2;if(g>>>1)f=f|1;e=(32-f|0)-1|0;}g=(((32-e|0)+4|0)-1|0)/4|0;h=$rt_createCharArray(g);i=h.data;e=(g-1|0)*4|0;g=0;while(e>=0){f=g+1|0;i[g]=CL(c>>>e&15,16);e=e-4|0;g=f;}d=H5(h);}return M(F(b,d));}
|
||||
function EB(a){var b,c;b=a;if(!b.$id$){c=$rt_nextId();b.$id$=c;}return a.$id$;}
|
||||
function HT(a){var b,c,d;if(!H$(a,BT)&&a.constructor.$meta.item===null){b=new CV;H(b);D(b);}b=GX(a);c=b;d=$rt_nextId();c.$id$=d;return b;}
|
||||
function V(){C.call(this);}
|
||||
var Iu=null;var Iv=null;var Iw=null;var Ix=null;var Iy=null;var Iz=null;var IA=null;var IB=null;var IC=null;var ID=null;var IE=null;var IF=0;var IG=0;function Ft(b){var c,d,e,f,g,$p,$z;$p=0;if(If()){var $T=GH();$p=$T.l();g=$T.l();f=$T.l();e=$T.l();d=$T.l();c=$T.l();b=$T.l();}_:while(true){switch($p){case 0:FQ();Fj();EF();Eu();E$();En();Gp();Fk();Eo();E7();FI();EC();EA();Ey();FT();F2();ER();c=window.classicConfig;if(c===null)d=null;else{d=Bu(Br,c.length);b=d.data;e=0;f=b.length;while(e<f){b[e]=$rt_str(c[e]);e
|
||||
=e+1|0;}}b=d.data;c=window.document;g=b[0];c=c.getElementById($rt_ustr(g));Iw=c;g=b[1];$p=1;case 1:EQ(c,g);if(G7()){break _;}return;default:H8();}}GH().s(b,c,d,e,f,g,$p);}
|
||||
function EQ(b,c){var d,e,f,$$je,$p,$z;$p=0;if(If()){var $T=GH();$p=$T.l();f=$T.l();e=$T.l();d=$T.l();c=$T.l();b=$T.l();}_:while(true){switch($p){case 0:Iy=b;d=$rt_str(Iy.getAttribute("style"));e=Iy;f=N();if(d===null)d=B(2);f=M(F(F(f,d),B(3)));e.setAttribute("style",$rt_ustr(f));Iu=window;Iz=Iu.document;Iv=Iz.createElement("canvas");IF=b.clientWidth;IG=b.clientHeight;f=Iv;e=IF;f.width=e;f=Iv;e=IG;f.height=e;IA=Iv.getContext("2d");Iv.setAttribute("id","minecraftClassicBrowser");f=Iv;b.appendChild(f);IB=Iz.createElement("canvas");b
|
||||
=IB;f=IF;b.width=f;b=IB;f=IG;b.height=f;Ix=IB.getContext("webgl2");if(Ix===null){b=new P;G(b,B(4));D(b);}EJ(Ix);b=Ix;H_();IH=b;Ix.getExtension("EXT_texture_filter_anisotropic");$p=1;case 1:GA(c);if(G7()){break _;}a:{try{Gd(IE);break a;}catch($$e){$$je=U($$e);if($$je instanceof Q){f=$$je;}else{throw $$e;}}Fy(f);}return;default:H8();}}GH().s(b,c,d,e,f,$p);}
|
||||
function GA(b){var thread=$rt_nativeThread();var javaThread=$rt_getThread();if(thread.isResuming()){thread.status=0;var result=thread.attribute;if(result instanceof Error){throw result;}return result;}var callback=function(){};callback.d0=function(val){thread.attribute=val;$rt_setThread(javaThread);thread.resume();};callback.em=function(e){thread.attribute=$rt_exception(e);$rt_setThread(javaThread);thread.resume();};callback=Iq(callback);return thread.suspend(function(){try{GM(b,callback);}catch($e){callback.em($rt_exception($e));}});}
|
||||
function GM(b,c){var d,e;d=new XMLHttpRequest();e="arraybuffer";d.responseType=e;d.open("GET",$rt_ustr(b),!!1);b=new CY;b.c3=d;b.dg=c;b=GV(b,"stateChanged");d.onreadystatechange=b;d.send();}
|
||||
function FQ(){Iu=null;Iv=null;Iw=null;Ix=null;Iy=null;Iz=null;IA=null;IB=null;IC=null;ID=null;IE=null;IF=0;IG=0;}
|
||||
function EJ(b){window.currentContext=b;}
|
||||
function Db(){}
|
||||
function De(){var a=this;C.call(a);a.ct=null;a.bH=null;}
|
||||
function Fi(b){var c,d;if(b===null)return null;c=b.classObject;if(c===null){c=new De;c.bH=b;d=c;b.classObject=d;}return c;}
|
||||
function Ep(a,b){var c;b=b;c=a.bH;return b!==null&&!(typeof b.constructor.$meta==='undefined'?1:0)&&Fl(b.constructor,c)?1:0;}
|
||||
function D6(a){if(a.ct===null)a.ct=$rt_str(a.bH.$meta.name);return a.ct;}
|
||||
function BY(a){return a.bH.$meta.primitive?1:0;}
|
||||
function CZ(a){return Fi(a.bH.$meta.item);}
|
||||
function Gi(){C.call(this);}
|
||||
function GV(b,c){var name='jso$functor$'+c;if(!b[name]){var fn=function(){return b[c].apply(b,arguments);};b[name]=function(){return fn;};}return b[name]();}
|
||||
function Cw(b,c){if(typeof b!=="function")return b;var result={};result[c]=b;return result;}
|
||||
function F1(){C.call(this);}
|
||||
function GX(b){var copy=new b.constructor();for(var field in b){if(!b.hasOwnProperty(field)){continue;}copy[field]=b[field];}return copy;}
|
||||
function Fl(b,c){var d,e;if(b===c)return 1;d=b.$meta.supertypes;e=0;while(e<d.length){if(Fl(d[e],c))return 1;e=e+1|0;}return 0;}
|
||||
function BG(){}
|
||||
function Bk(){}
|
||||
function B3(){}
|
||||
function Br(){var a=this;C.call(a);a.t=null;a.b7=0;}
|
||||
var II=null;function H5(a){var b=new Br();E3(b,a);return b;}
|
||||
function HN(a,b,c){var d=new Br();GB(d,a,b,c);return d;}
|
||||
function E3(a,b){var c,d;b=b.data;c=b.length;a.t=$rt_createCharArray(c);d=0;while(d<c){a.t.data[d]=b[d];d=d+1|0;}}
|
||||
function GB(a,b,c,d){var e,f;a.t=$rt_createCharArray(d);e=0;while(e<d){f=b.data;a.t.data[e]=f[e+c|0];e=e+1|0;}}
|
||||
function By(a,b){var c;if(b>=0&&b<a.t.data.length)return a.t.data[b];c=new CD;H(c);D(c);}
|
||||
function R(a){return a.t.data.length;}
|
||||
function CF(a){return a.t.data.length?0:1;}
|
||||
function Bo(a,b){var c,d;if(a===b)return 1;if(!(b instanceof Br))return 0;c=b;if(R(c)!=R(a))return 0;d=0;while(d<R(c)){if(By(a,d)!=By(c,d))return 0;d=d+1|0;}return 1;}
|
||||
function Dt(a){var b,c,d,e;a:{if(!a.b7){b=a.t.data;c=b.length;d=0;while(true){if(d>=c)break a;e=b[d];a.b7=(31*a.b7|0)+e|0;d=d+1|0;}}}return a.b7;}
|
||||
function E0(a){var b,c,d,e,f,g,h,i,j,k;if(CF(a))return a;b=$rt_createIntArray(a.t.data.length).data;c=0;d=0;while(d<a.t.data.length){a:{if(d!=(a.t.data.length-1|0)&&Cs(a.t.data[d])){e=a.t.data;f=d+1|0;if(Co(e[f])){g=c+1|0;b[c]=Ef(Ds(a.t.data[d],a.t.data[f]));d=f;break a;}}g=c+1|0;b[c]=Ef(a.t.data[d])&65535;}d=d+1|0;c=g;}h=new Br;d=0;h.t=$rt_createCharArray(c*2|0);g=0;f=0;while(f<c){i=d+1|0;d=b[d];if(d<65536){e=h.t.data;j=g+1|0;e[g]=d&65535;}else{e=h.t.data;k=g+1|0;e[g]=Ee(d);e=h.t.data;j=k+1|0;e[k]=Do(d);}f
|
||||
=f+1|0;d=i;g=j;}if(g<h.t.data.length)h.t=Dr(h.t,g);return h;}
|
||||
function Fj(){II=new DA;}
|
||||
function BP(){var a=this;C.call(a);a.c1=null;a.bY=null;a.cf=0;a.co=0;a.dH=null;}
|
||||
function IJ(a){var b=new BP();G(b,a);return b;}
|
||||
function G(a,b){a.cf=1;a.co=1;a.c1=b;}
|
||||
function G3(a){return a;}
|
||||
function H1(a){return a.c1;}
|
||||
function Hc(a){return a.b8();}
|
||||
function Fy(a){var b;if(IK===null){b=new Df;b.c6=new Ea;b.Y=N();b.b1=$rt_createCharArray(32);b.ep=0;b.dD=Hv();IK=b;}D5(a,IK);}
|
||||
function D5(a,b){var c,d,e,f,g;B5(b,D6(B1(a)));c=a.b8();if(c!==null)B5(b,M(F(F(N(),B(5)),c)));a:{Gf(b);if(a.dH!==null){d=a.dH.data;e=d.length;f=0;while(true){if(f>=e)break a;g=d[f];B5(b,B(6));Ga(b,g);f=f+1|0;}}}if(a.bY!==null&&a.bY!==a){B5(b,B(7));D5(a.bY,b);}}
|
||||
function Bq(){BP.call(this);}
|
||||
function BS(){Bq.call(this);}
|
||||
function FF(){BS.call(this);}
|
||||
function Ct(){var a=this;C.call(a);a.j=null;a.z=0;}
|
||||
function Fd(a,b,c){return FV(a,a.z,b,c);}
|
||||
function FV(a,b,c,d){var e,f,g,h,i,j,k;e=1;if(c<0){e=0;c= -c;}a:{if(c<d){if(e)Bd(a,b,b+1|0);else{Bd(a,b,b+2|0);f=a.j.data;g=b+1|0;f[b]=45;b=g;}a.j.data[b]=CL(c,d);}else{h=1;i=1;j=2147483647/d|0;b:{while(true){k=Dm(h,d);if(k>c){k=h;break b;}i=i+1|0;if(k>j)break;h=k;}}if(!e)i=i+1|0;Bd(a,b,b+i|0);if(e)e=b;else{f=a.j.data;e=b+1|0;f[b]=45;}while(true){if(k<=0)break a;f=a.j.data;b=e+1|0;f[e]=CL(c/k|0,d);c=c%k|0;k=k/d|0;e=b;}}}return a;}
|
||||
function E8(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o;d=C6(c,0.0);if(!d){Bd(a,b,b+3|0);e=a.j.data;d=b+1|0;e[b]=48;e=a.j.data;b=d+1|0;e[d]=46;a.j.data[b]=48;return a;}if(!d){Bd(a,b,b+4|0);e=a.j.data;d=b+1|0;e[b]=45;e=a.j.data;b=d+1|0;e[d]=48;e=a.j.data;d=b+1|0;e[b]=46;a.j.data[d]=48;return a;}if(isNaN(c)?1:0){Bd(a,b,b+3|0);e=a.j.data;d=b+1|0;e[b]=78;e=a.j.data;b=d+1|0;e[d]=97;a.j.data[b]=78;return a;}if(!isFinite(c)?1:0){if(d>0){Bd(a,b,b+8|0);d=b;}else{Bd(a,b,b+9|0);e=a.j.data;d=b+1|0;e[b]=45;}e=a.j.data;b=d+1|0;e[d]
|
||||
=73;e=a.j.data;d=b+1|0;e[b]=110;e=a.j.data;b=d+1|0;e[d]=102;e=a.j.data;d=b+1|0;e[b]=105;e=a.j.data;b=d+1|0;e[d]=110;e=a.j.data;d=b+1|0;e[b]=105;e=a.j.data;b=d+1|0;e[d]=116;a.j.data[b]=121;return a;}f=IL;EW(c,f);d=f.cF;g=f.c7;h=f.du;i=1;j=1;if(h){h=1;j=2;}k=9;l=G5(d);if(l>0)k=k-l|0;if(g<7&&g>=(-3)){if(g>=0){i=g+1|0;k=BA(k,i+1|0);g=0;}else if(g<0){d=d/IM.data[ -g]|0;k=k-g|0;g=0;}}if(g){j=j+2|0;if(!(g>(-10)&&g<10))j=j+1|0;if(g<0)j=j+1|0;}if(g&&k==i)k=k+1|0;Bd(a,b,b+(j+k|0)|0);if(!h)h=b;else{e=a.j.data;h=b+1|0;e[b]
|
||||
=45;}m=100000000;n=0;while(n<k){if(m<=0)o=0;else{o=d/m|0;d=d%m|0;}e=a.j.data;b=h+1|0;e[h]=(48+o|0)&65535;i=i+(-1)|0;if(i)h=b;else{e=a.j.data;h=b+1|0;e[b]=46;}m=m/10|0;n=n+1|0;}if(g){e=a.j.data;b=h+1|0;e[h]=69;if(g>=0)d=b;else{g= -g;e=a.j.data;d=b+1|0;e[b]=45;}if(g<10)l=d;else{e=a.j.data;l=d+1|0;e[d]=(48+(g/10|0)|0)&65535;}a.j.data[l]=(48+(g%10|0)|0)&65535;}return a;}
|
||||
function G5(b){var c,d,e;if(!(b%1000000000|0))return 9;c=0;d=1;if(!(b%100000000|0)){c=8;d=100000000;}e=d*10000|0;if(b%e|0)e=d;else c=c|4;d=e*100|0;if(b%d|0)d=e;else c=c|2;if(!(b%(d*10|0)|0))c=c|1;return c;}
|
||||
function Bd(a,b,c){var d,e;d=a.z-b|0;D$(a,(a.z+c|0)-b|0);e=d-1|0;while(e>=0){a.j.data[c+e|0]=a.j.data[b+e|0];e=e+(-1)|0;}a.z=a.z+(c-b|0)|0;}
|
||||
function Cy(){}
|
||||
function EE(){Ct.call(this);}
|
||||
function N(){var a=new EE();HE(a);return a;}
|
||||
function HE(a){a.j=$rt_createCharArray(16);}
|
||||
function F(a,b){CM(a,a.z,b);return a;}
|
||||
function J(a,b){Fd(a,b,10);return a;}
|
||||
function Hn(a,b){C5(a,a.z,b);return a;}
|
||||
function EG(a,b){Dq(a,a.z,b);return a;}
|
||||
function ES(a,b){DY(a,a.z,b);return a;}
|
||||
function C5(a,b,c){E8(a,b,c);return a;}
|
||||
function DY(a,b,c){CM(a,b,c===null?B(8):c.dq());return a;}
|
||||
function Dq(a,b,c){Bd(a,b,b+1|0);a.j.data[b]=c;return a;}
|
||||
function CM(a,b,c){var d,e,f;if(b>=0&&b<=a.z){a:{if(c===null)c=B(8);else if(CF(c))break a;D$(a,a.z+R(c)|0);d=a.z-1|0;while(d>=b){a.j.data[d+R(c)|0]=a.j.data[d];d=d+(-1)|0;}a.z=a.z+R(c)|0;d=0;while(d<R(c)){e=a.j.data;f=b+1|0;e[b]=By(c,d);d=d+1|0;b=f;}}return a;}c=new CD;H(c);D(c);}
|
||||
function Gk(a,b){a.z=b;}
|
||||
function ED(a,b,c,d,e){var f,g,h,i,j;if(b>c){f=new O;G(f,B(9));D(f);}while(b<c){g=d.data;h=e+1|0;i=a.j.data;j=b+1|0;g[e]=i[b];e=h;b=j;}}
|
||||
function B2(a){return a.z;}
|
||||
function M(a){return HN(a.j,0,a.z);}
|
||||
function D$(a,b){if(a.j.data.length<b){b=a.j.data.length>=1073741823?2147483647:BA(b,BA(a.j.data.length*2|0,5));a.j=Dr(a.j,b);}}
|
||||
function G1(a,b,c){return DY(a,b,c);}
|
||||
function GI(a,b,c){return Dq(a,b,c);}
|
||||
function Ho(a,b,c){return C5(a,b,c);}
|
||||
function HX(a,b,c){return CM(a,b,c);}
|
||||
function BR(){C.call(this);}
|
||||
function C0(){BR.call(this);}
|
||||
var IN=null;function EF(){IN=Bt($rt_intcls());}
|
||||
function BI(){BS.call(this);}
|
||||
function IO(a){var b=new BI();Dp(b,a);return b;}
|
||||
function Dp(a,b){G(a,b);}
|
||||
function Fs(){BI.call(this);}
|
||||
function IP(a){var b=new Fs();HH(b,a);return b;}
|
||||
function HH(a,b){Dp(a,b);}
|
||||
function Fa(){BI.call(this);}
|
||||
function IQ(a){var b=new Fa();HQ(b,a);return b;}
|
||||
function HQ(a,b){Dp(a,b);}
|
||||
function Bc(){BP.call(this);}
|
||||
function IR(){var a=new Bc();H(a);return a;}
|
||||
function H(a){a.cf=1;a.co=1;}
|
||||
function P(){Bc.call(this);}
|
||||
function Is(a){var b=new P();Hx(b,a);return b;}
|
||||
function Hx(a,b){G(a,b);}
|
||||
function Be(){}
|
||||
function Bv(){}
|
||||
function Ed(){}
|
||||
function DO(){}
|
||||
function DG(){}
|
||||
function Dl(){}
|
||||
function DU(){}
|
||||
function DR(){}
|
||||
function DX(){}
|
||||
function Fc(){C.call(this);}
|
||||
function GF(a,b,c){a.fz($rt_str(b),Cw(c,"handleEvent"));}
|
||||
function GR(a,b,c){a.fc($rt_str(b),Cw(c,"handleEvent"));}
|
||||
function Hl(a,b){return a.gQ(b);}
|
||||
function Hs(a,b,c,d){a.fN($rt_str(b),Cw(c,"handleEvent"),d?1:0);}
|
||||
function Hu(a,b){return !!a.fK(b);}
|
||||
function HM(a){return a.gH();}
|
||||
function GU(a,b,c,d){a.g6($rt_str(b),Cw(c,"handleEvent"),d?1:0);}
|
||||
function Gy(){C.call(this);}
|
||||
function EO(){C.call(this);}
|
||||
function W(){C.call(this);}
|
||||
var IH=null;var IS=0;var IT=null;var IU=null;var IV=null;var IW=null;var IX=null;var IY=0;var IZ=0;var I0=null;function H_(){H_=S(W);HB();}
|
||||
function HB(){IH=null;IS=0;IT=$rt_createIntArray(4);IU=new Uint8Array(new ArrayBuffer(4194304));IV=new Float32Array(4);IW=new Float32Array(9);IX=new Float32Array(16);IY=(-1);IZ=0;I0=new Int32Array(new ArrayBuffer(2100000));}
|
||||
function CI(){W.call(this);}
|
||||
function Gg(){CI.call(this);}
|
||||
function D3(){C.call(this);}
|
||||
var I1=null;function Gd(b){var c,d,e,f,g,h,i,j,k,l,m,n;c=b.data;d=new CX;e=c.length;d.de=b;d.bU=0;d.ex=0;d.c2=0+e|0;f=Ia(d);c=$rt_createByteArray(8);Cq(f,c);g=new Br;Eb(B(10));h=Fn(I2,E0(B(10)));if(h===null){d=new DK;H(d);d.eD=B(10);D(d);}i=EL(h,FZ(c,0,c.data.length));if(F0(i)&&!i.p&&i.N==i.cc)g.t=F5(i);else{g.t=$rt_createCharArray(L(i));Gb(i,g.t);}if(!Bo(B(11),g)){d=new Q;G(d,B(12));D(d);}B9(f);i=new C7;f=new Di;j=new D7;j.K=GP();j.cs=0;k=Gw(j,15,0);if(k){d=new C_;G(d,M(F(F(J(N(),k),B(5)),j.o)));D(d);}Ei(f,
|
||||
d);f.cn=0;f.bK=0;f.di=1;f.dA=0;f.d9=$rt_createByteArray(1);f.d_=$rt_createByteArray(512);f.M=j;f.bG=$rt_createByteArray(512);f.di=1;f.dA=1;EV(i,f);j=new C$;j.V=$rt_createByteArray(4);j.bc=0;j.y=$rt_createIntArray(80);C3(j);while(true){f=B9(i);if(!Bo(B(13),f)){if(Em(i)<=0&&Bo(B(14),f))return;d=new Q;G(d,B(12));D(d);}g=B9(i);l=$rt_createByteArray(20);m=$rt_createByteArray(20);Cq(i,l);k=El(i);n=$rt_createByteArray(k);Cq(i,n);if(Fu(I1,g))continue;a:{Fq(j,n,0,k);Fw(j,m,0);if(l===m)k=1;else{if(l!==null&&m!==null)
|
||||
{b=l.data;c=m.data;k=b.length;if(k==c.length){e=0;while(e<k){if(b[e]!=c[e]){k=0;break a;}e=e+1|0;}k=1;break a;}}k=0;}}if(!k){d=new Q;G(d,M(F(F(N(),B(15)),g)));D(d);}Cr(I1,g,n);if(!Bo(B(16),B9(i)))break;}d=new Q;G(d,B(12));D(d);}
|
||||
function Eu(){I1=H0();}
|
||||
function Q(){Bc.call(this);}
|
||||
function DQ(){}
|
||||
function DA(){C.call(this);}
|
||||
function B6(){C.call(this);}
|
||||
var I3=null;var I4=null;function Cs(b){return (b&64512)!=55296?0:1;}
|
||||
function Co(b){return (b&64512)!=56320?0:1;}
|
||||
function DJ(b){return !Cs(b)&&!Co(b)?0:1;}
|
||||
function Ds(b,c){return ((b&1023)<<10|c&1023)+65536|0;}
|
||||
function Ee(b){return (55296|(b-65536|0)>>10&1023)&65535;}
|
||||
function Do(b){return (56320|b&1023)&65535;}
|
||||
function Ef(b){return (String.fromCharCode(b)).toUpperCase().charCodeAt(0);}
|
||||
function CL(b,c){if(c>=2&&c<=36&&b<c)return b<10?(48+b|0)&65535:((97+b|0)-10|0)&65535;return 0;}
|
||||
function E$(){I3=Bt($rt_charcls());I4=Bu(B6,128);}
|
||||
function DP(){}
|
||||
function DB(){C.call(this);this.c0=null;}
|
||||
function Iq(b){var c;c=new DB;c.c0=b;return c;}
|
||||
function Ge(a,b){a.c0.d0(b);}
|
||||
function HK(a,b){a.c0.em(b);}
|
||||
function E1(){C.call(this);}
|
||||
function D2(){}
|
||||
function CY(){var a=this;C.call(a);a.c3=null;a.dg=null;}
|
||||
function Gv(a){var b,c;if(a.c3.readyState==4){b=new Uint8Array(a.c3.response);IE=$rt_createByteArray(b.byteLength);c=0;while(c<IE.data.length){IE.data[c]=b[c]<<24>>24;c=c+1|0;}Ge(a.dg,B(17));}}
|
||||
function G2(a){Gv(a);}
|
||||
function D0(){}
|
||||
function Cn(){}
|
||||
function BN(){C.call(this);}
|
||||
function CX(){var a=this;BN.call(a);a.de=null;a.bU=0;a.ex=0;a.c2=0;}
|
||||
function HI(a,b,c,d){var e,f,g,h,i;e=Ba(d,a.c2-a.bU|0);f=0;while(f<e){g=b.data;d=c+1|0;h=a.de.data;i=a.bU;a.bU=i+1|0;g[c]=h[i];f=f+1|0;c=d;}if(e<=0)e=(-1);return e;}
|
||||
function GT(a){return a.c2-a.bU|0;}
|
||||
function BL(){BN.call(this);this.bj=null;}
|
||||
function I5(a){var b=new BL();Ei(b,a);return b;}
|
||||
function Ei(a,b){a.bj=b;}
|
||||
function Em(a){return a.bj.c5();}
|
||||
function DM(){}
|
||||
function C7(){BL.call(this);this.ba=null;}
|
||||
function Ia(a){var b=new C7();EV(b,a);return b;}
|
||||
function EV(a,b){Ei(a,b);a.ba=$rt_createByteArray(8);}
|
||||
function Cq(a,b){var c;c=b.data;return a.bj.bX(b,0,c.length);}
|
||||
function Dg(a,b){var c,d;c=0;while(c<b){d=a.bj.bX(a.ba,c,b-c|0);if(d==(-1))return d;c=c+d|0;}return c;}
|
||||
function Gt(a,b,c,d){var e,f;if(d<0){e=new O;H(e);D(e);}if(!d)return;if(a.bj===null){e=new BD;H(e);D(e);}if(b===null){e=new BD;H(e);D(e);}if(c>=0&&c<=(b.data.length-d|0)){while(d>0){f=a.bj.bX(b,c,d);if(f<0){e=new BM;H(e);D(e);}c=c+f|0;d=d-f|0;}return;}e=new O;H(e);D(e);}
|
||||
function El(a){var b;if(Dg(a,4)<0){b=new BM;H(b);D(b);}return (a.ba.data[0]&255)<<24|(a.ba.data[1]&255)<<16|(a.ba.data[2]&255)<<8|a.ba.data[3]&255;}
|
||||
function Gh(a){var b;if(Dg(a,2)<0){b=new BM;H(b);D(b);}return ((a.ba.data[0]&255)<<8|a.ba.data[1]&255)&65535;}
|
||||
function B9(a){return E9(a,Gh(a));}
|
||||
function E9(a,b){var c,d;c=$rt_createByteArray(b);d=$rt_createCharArray(b);Gt(a,c,0,b);return HD(c,d,0,b);}
|
||||
function HD(b,c,d,e){var f,g,h,i,j,k,l,m,n,o;f=0;g=0;a:{while(f<e){h=b.data;i=c.data;j=f+1|0;k=h[d+f|0]&65535;i[g]=k;l=i[g];if(k<128)g=g+1|0;else if((l&224)==192){if(j>=e){m=new BC;G(m,B(18));D(m);}k=j+1|0;j=h[d+j|0];if((j&192)!=128){m=new BC;G(m,B(19));D(m);}n=g+1|0;i[g]=((l&31)<<6|j&63)&65535;g=n;j=k;}else{if((l&240)!=224){m=new BC;G(m,B(19));D(m);}f=j+1|0;if(f>=e){m=new BC;G(m,B(19));D(m);}n=h[d+j|0];j=f+1|0;o=h[d+f|0];if((n&192)!=128)break a;if((o&192)!=128)break a;f=g+1|0;i[g]=((l&15)<<12|(n&63)<<6|o&63)
|
||||
&65535;g=f;}f=j;}return HN(c,0,g);}m=new BC;G(m,B(19));D(m);}
|
||||
function Ck(){var a=this;C.call(a);a.dP=null;a.d7=null;}
|
||||
function Eb(b){var c,d;if(CF(b))D(E4(b));if(!Gu(By(b,0)))D(E4(b));c=1;while(c<R(b)){a:{d=By(b,c);switch(d){case 43:case 45:case 46:case 58:case 95:break;default:if(Gu(d))break a;else D(E4(b));}}c=c+1|0;}}
|
||||
function Gu(b){return !(b>=48&&b<=57)&&!(b>=97&&b<=122)&&b<65&&b>90?0:1;}
|
||||
function EL(a,b){var c,d,$$je;a:{try{b=F8(Ff(Fe(Ev(a),I6),I6),b);}catch($$e){$$je=U($$e);if($$je instanceof BB){c=$$je;break a;}else{throw $$e;}}return b;}d=new DD;d.cf=1;d.co=1;d.c1=B(20);d.bY=c;D(d);}
|
||||
function Di(){var a=this;BL.call(a);a.M=null;a.bG=null;a.cn=0;a.bK=0;a.di=0;a.dA=0;a.d9=null;a.d_=null;}
|
||||
function Hj(a,b,c,d){var e,f,g;if(a.cn){e=new Q;G(e,B(21));D(e);}if(b===null){e=new BD;H(e);D(e);}if(c>=0&&d>=0&&d<=(b.data.length-c|0)){if(!d)return 0;if(a.bK)return (-1);f=0;EP(a.M,b,c,d);a:{while(!a.bK){if(!a.M.f)Fm(a);b:{g=E2(a.M,0);f=f+(a.M.b2-c|0)|0;c=a.M.b2;switch(g){case -3:e=new Q;G(e,a.M.o);D(e);case 1:case 2:break;default:break b;}a.bK=1;if(g==2)return (-1);}if(!a.M.R)break a;}}return f;}e=new O;H(e);D(e);}
|
||||
function H2(a){var b;if(!a.cn){if(!a.bK)return 1;return 0;}b=new Q;G(b,B(21));D(b);}
|
||||
function Fm(a){var b,c;if(a.cn){b=new Q;G(b,B(21));D(b);}a:{c=a.bj.bX(a.bG,0,a.bG.data.length);if(c==(-1)){if(a.M.Z.x)break a;if(EZ(a.M))break a;a.bG.data[0]=0;c=1;}Gl(a.M,a.bG,0,c,1);return;}if(Long_ne(a.M.Z.b4,Long_fromInt(-1))){b=new Q;G(b,B(22));D(b);}b=new BM;G(b,B(23));D(b);}
|
||||
function CP(){var a=this;C.call(a);a.V=null;a.bc=0;a.bt=Long_ZERO;}
|
||||
function B7(a,b){var c,d;c=a.V.data;d=a.bc;a.bc=d+1|0;c[d]=b;if(a.bc==a.V.data.length){CT(a,a.V,0);a.bc=0;}a.bt=Long_add(a.bt,Long_fromInt(1));}
|
||||
function Fq(a,b,c,d){a:{while(a.bc){if(d<=0)break a;B7(a,b.data[c]);c=c+1|0;d=d+(-1)|0;}}while(d>a.V.data.length){CT(a,b,c);c=c+a.V.data.length|0;d=d-a.V.data.length|0;a.bt=Long_add(a.bt,Long_fromInt(a.V.data.length));}while(d>0){B7(a,b.data[c]);c=c+1|0;d=d+(-1)|0;}}
|
||||
function F4(a){var b;b=Long_shl(a.bt,3);B7(a,(-128));while(a.bc){B7(a,0);}EK(a,b);CN(a);}
|
||||
function C$(){var a=this;CP.call(a);a.bO=0;a.bP=0;a.bQ=0;a.bR=0;a.bS=0;a.y=null;a.bx=0;}
|
||||
function CT(a,b,c){var d,e;d=b.data;b=a.y.data;e=a.bx;a.bx=e+1|0;b[e]=(d[c]&255)<<24|(d[c+1|0]&255)<<16|(d[c+2|0]&255)<<8|d[c+3|0]&255;if(a.bx==16)CN(a);}
|
||||
function BH(a,b,c,d){c=c.data;c[d]=b>>>24<<24>>24;c[d+1|0]=b>>>16<<24>>24;c[d+2|0]=b>>>8<<24>>24;c[d+3|0]=b<<24>>24;}
|
||||
function EK(a,b){if(a.bx>14)CN(a);a.y.data[14]=b.hi;a.y.data[15]=Long_and(b,Long_fromInt(-1)).lo;}
|
||||
function Fw(a,b,c){F4(a);BH(a,a.bO,b,c);BH(a,a.bP,b,c+4|0);BH(a,a.bQ,b,c+8|0);BH(a,a.bR,b,c+12|0);BH(a,a.bS,b,c+16|0);C3(a);return 20;}
|
||||
function C3(a){var b;a.bt=Long_ZERO;a.bc=0;b=0;while(b<a.V.data.length){a.V.data[b]=0;b=b+1|0;}a.bO=1732584193;a.bP=(-271733879);a.bQ=(-1732584194);a.bR=271733878;a.bS=(-1009589776);a.bx=0;b=0;while(b!=a.y.data.length){a.y.data[b]=0;b=b+1|0;}}
|
||||
function DL(a,b,c,d){return b^c^d;}
|
||||
function Bi(a,b,c){return b<<c|b>>>(32-c|0);}
|
||||
function CN(a){var b,c,d,e,f,g,h,i,j;b=16;while(b<=79){a.y.data[b]=Bi(a,a.y.data[b-3|0]^a.y.data[b-8|0]^a.y.data[b-14|0]^a.y.data[b-16|0],1);b=b+1|0;}c=a.bO;d=a.bP;e=a.bQ;f=a.bR;g=a.bS;h=0;while(h<=19){i=(((Bi(a,c,5)+(d&e|(d^(-1))&f)|0)+g|0)+a.y.data[h]|0)+1518500249|0;b=Bi(a,d,30);h=h+1|0;g=f;f=e;e=b;d=c;c=i;}j=20;while(j<=39){i=(((Bi(a,c,5)+DL(a,d,e,f)|0)+g|0)+a.y.data[j]|0)+1859775393|0;b=Bi(a,d,30);j=j+1|0;g=f;f=e;e=b;d=c;c=i;}h=40;while(h<=59){i=(((Bi(a,c,5)+(d&e|d&f|e&f)|0)+g|0)+a.y.data[h]|0)+(-1894007588)
|
||||
|0;b=Bi(a,d,30);h=h+1|0;g=f;f=e;e=b;d=c;c=i;}j=60;while(j<=79){i=(((Bi(a,c,5)+DL(a,d,e,f)|0)+g|0)+a.y.data[j]|0)+(-899497514)|0;b=Bi(a,d,30);j=j+1|0;g=f;f=e;e=b;d=c;c=i;}a.bO=a.bO+c|0;a.bP=a.bP+d|0;a.bQ=a.bQ+e|0;a.bR=a.bR+f|0;a.bS=a.bS+g|0;a.bx=0;b=0;while(b!=a.y.data.length){a.y.data[b]=0;b=b+1|0;}}
|
||||
function Fv(){C.call(this);}
|
||||
function Dr(b,c){var d,e,f,g;b=b.data;d=$rt_createCharArray(c);e=d.data;f=Ba(c,b.length);g=0;while(g<f){e[g]=b[g];g=g+1|0;}return d;}
|
||||
function Fr(b,c){var d,e,f,g;b=b.data;d=$rt_createByteArray(c);e=d.data;f=Ba(c,b.length);g=0;while(g<f){e[g]=b[g];g=g+1|0;}return d;}
|
||||
function C1(){}
|
||||
function CH(){C.call(this);}
|
||||
function BT(){}
|
||||
function F7(){var a=this;CH.call(a);a.bM=0;a.J=null;a.ck=0;a.dF=0.0;a.cQ=0;}
|
||||
function H0(){var a=new F7();GG(a);return a;}
|
||||
function Hh(a,b){return Bu(BE,b);}
|
||||
function GG(a){var b;b=FM(16);a.bM=0;a.J=Bu(BE,b);a.dF=0.75;DV(a);}
|
||||
function FM(b){var c;if(b>=1073741824)return 1073741824;if(!b)return 16;c=b-1|0;b=c|c>>1;b=b|b>>2;b=b|b>>4;b=b|b>>8;return (b|b>>16)+1|0;}
|
||||
function DV(a){a.cQ=a.J.data.length*a.dF|0;}
|
||||
function Fu(a,b){return Dc(a,b)===null?0:1;}
|
||||
function Fn(a,b){var c;c=Dc(a,b);if(c===null)return null;return c.b9;}
|
||||
function Dc(a,b){var c,d;if(b===null)c=Ec(a);else{d=Dt(b);c=Dd(a,b,d&(a.J.data.length-1|0),d);}return c;}
|
||||
function Dd(a,b,c,d){var e,f;e=a.J.data[c];while(e!==null){if(e.cC==d){f=e.c4;if(b!==f&&!Bo(b,f)?0:1)break;}e=e.bZ;}return e;}
|
||||
function Ec(a){var b;b=a.J.data[0];while(b!==null&&b.c4!==null){b=b.bZ;}return b;}
|
||||
function G$(a,b,c){return Cr(a,b,c);}
|
||||
function Cr(a,b,c){var d,e,f,g;if(b===null){d=Ec(a);if(d===null){a.ck=a.ck+1|0;d=DS(a,null,0,0);e=a.bM+1|0;a.bM=e;if(e>a.cQ)D4(a);}}else{e=Dt(b);f=e&(a.J.data.length-1|0);d=Dd(a,b,f,e);if(d===null){a.ck=a.ck+1|0;d=DS(a,b,f,e);e=a.bM+1|0;a.bM=e;if(e>a.cQ)D4(a);}}g=d.b9;d.b9=c;return g;}
|
||||
function DS(a,b,c,d){var e,f;e=new BE;f=null;e.c4=b;e.b9=f;e.cC=d;e.bZ=a.J.data[c];a.J.data[c]=e;return e;}
|
||||
function E_(a,b){var c,d,e,f,g,h,i;c=FM(!b?1:b<<1);d=Bu(BE,c);e=d.data;f=0;c=c-1|0;while(f<a.J.data.length){g=a.J.data[f];a.J.data[f]=null;while(g!==null){h=g.cC&c;i=g.bZ;g.bZ=e[h];e[h]=g;g=i;}f=f+1|0;}a.J=d;DV(a);}
|
||||
function D4(a){E_(a,a.J.data.length);}
|
||||
function Dy(){C.call(this);}
|
||||
var I2=null;function En(){I2=H0();Cr(I2,B(10),Hv());}
|
||||
function X(){P.call(this);}
|
||||
function DK(){X.call(this);this.eD=null;}
|
||||
function EU(){C.call(this);}
|
||||
function Bn(){C.call(this);}
|
||||
function FG(){Bn.call(this);}
|
||||
function Et(){Bn.call(this);}
|
||||
function Go(){Bn.call(this);}
|
||||
function Gx(){X.call(this);this.el=null;}
|
||||
function E4(a){var b=new Gx();G8(b,a);return b;}
|
||||
function G8(a,b){H(a);a.el=b;}
|
||||
function Cj(){var a=this;C.call(a);a.q=null;a.b=0;a.f=0;a.e=Long_ZERO;a.cr=null;a.b2=0;a.R=0;a.bD=Long_ZERO;a.o=null;a.Z=null;a.K=null;}
|
||||
function EP(a,b,c,d){a.cr=b;a.b2=c;a.R=d;}
|
||||
function Gl(a,b,c,d,e){var f;if(d<=0&&e&&a.q!==null)return;if(a.f>0&&e){f=$rt_createByteArray(a.f+d|0);Z(a.q,a.b,f,0,a.f);Z(b,c,f,a.f,d);a.q=f;a.b=0;a.f=a.f+d|0;}else{a.q=b;a.b=c;a.f=d;}}
|
||||
function D7(){Cj.call(this);this.cs=0;}
|
||||
function Gw(a,b,c){var d;a.cs=0;d=new CE;d.b4=Long_fromInt(-1);d.X=(-1);d.cz=$rt_createByteArray(4);d.r=null;d.I=null;d.d=a;a.Z=d;d=a.Z;if(c)b= -b;return Er(d,b);}
|
||||
function E2(a,b){var c;if(a.Z===null)return (-2);c=FC(a.Z,b);if(c==1)a.cs=1;return c;}
|
||||
function EZ(a){return a.Z.m!=12?0:1;}
|
||||
function Gn(){Ck.call(this);}
|
||||
function Hv(){var a=new Gn();HA(a);return a;}
|
||||
function HA(a){var b,c,d,e;b=Bu(Br,0);c=b.data;Eb(B(10));d=c.length;e=0;while(e<d){Eb(c[e]);e=e+1|0;}a.dP=B(10);a.d7=b.dE();}
|
||||
function Ev(a){var b;b=new Dj;b.bp=B(24);b.by=I7;b.b3=I7;b.dU=a;b.c$=0.3333333432674408;b.es=0.5;return b;}
|
||||
function FU(a){var b,c,d,e,f;b=new Eh;c=$rt_createByteArray(1);d=c.data;d[0]=63;b.cU=I7;b.cX=I7;e=d.length;if(e&&e>=b.c9){b.eb=a;b.cK=c.dE();b.ef=2.0;b.c9=4.0;return b;}f=new X;G(f,B(25));D(f);}
|
||||
function BJ(){var a=this;C.call(a);a.cc=0;a.p=0;a.N=0;a.bN=0;}
|
||||
function I8(a){var b=new BJ();C4(b,a);return b;}
|
||||
function C4(a,b){a.bN=(-1);a.cc=b;a.N=b;}
|
||||
function GJ(a){return a.cc;}
|
||||
function Hp(a){return a.p;}
|
||||
function Bf(a,b){var c;if(b>=0&&b<=a.N){a.p=b;if(b<a.bN)a.bN=0;return a;}c=new X;G(c,M(F(J(F(J(F(N(),B(26)),b),B(27)),a.N),B(28))));D(c);}
|
||||
function G9(a){return a.N;}
|
||||
function L(a){return a.N-a.p|0;}
|
||||
function Bg(a){return a.p>=a.N?0:1;}
|
||||
function CJ(){var a=this;BJ.call(a);a.cR=0;a.cL=null;a.eF=null;}
|
||||
function FZ(b,c,d){var e,f,g;e=b.data;f=new Dx;g=e.length;d=c+d|0;C4(f,g);f.eF=I9;f.cR=0;f.cL=b;f.p=c;f.N=d;f.dS=0;f.cE=0;return f;}
|
||||
function Gq(a,b,c,d){var e,f,g,h,i,j,k;if(c>=0){e=b.data;f=e.length;if(c<f){g=c+d|0;if(g>f){h=new O;G(h,M(J(F(J(F(N(),B(29)),g),B(30)),f)));D(h);}if(L(a)<d){i=new Cm;H(i);D(i);}if(d<0){i=new O;G(i,M(F(J(F(N(),B(31)),d),B(32))));D(i);}g=a.p+a.cR|0;j=0;while(j<d){k=c+1|0;b=a.cL.data;f=g+1|0;e[c]=b[g];j=j+1|0;c=k;g=f;}a.p=a.p+d|0;return a;}}b=b.data;h=new O;G(h,M(F(J(F(J(F(N(),B(33)),c),B(27)),b.length),B(34))));D(h);}
|
||||
function Dz(a,b,c,d){var e,f,g,h,i,j,k;if(!d)return a;if(a.cE){e=new B$;H(e);D(e);}if(L(a)<d){e=new B0;H(e);D(e);}if(c>=0){f=b.data;g=f.length;if(c<g){h=c+d|0;if(h>g){e=new O;G(e,M(J(F(J(F(N(),B(35)),h),B(30)),g)));D(e);}if(d<0){e=new O;G(e,M(F(J(F(N(),B(31)),d),B(32))));D(e);}h=a.p+a.cR|0;i=0;while(i<d){b=a.cL.data;j=h+1|0;g=c+1|0;b[h]=f[c];i=i+1|0;h=j;c=g;}a.p=a.p+d|0;return a;}}b=b.data;k=new O;G(k,M(F(J(F(J(F(N(),B(33)),c),B(27)),b.length),B(34))));D(k);}
|
||||
function E6(a,b){return Dz(a,b,0,b.data.length);}
|
||||
function DC(a){a.p=0;a.N=a.cc;a.bN=(-1);return a;}
|
||||
function G4(a,b){Bf(a,b);return a;}
|
||||
function Dx(){var a=this;CJ.call(a);a.dS=0;a.cE=0;}
|
||||
function Hk(a){return a.cE;}
|
||||
function Eg(){}
|
||||
function Ci(){BJ.call(this);}
|
||||
function F6(b){var c;if(b>=0)return HG(0,b,$rt_createCharArray(b),0,b,0);c=new X;G(c,M(J(F(N(),B(36)),b)));D(c);}
|
||||
function Gc(b,c,d){return HG(0,b.data.length,b,c,c+d|0,0);}
|
||||
function Dh(a,b,c,d){var e,f,g,h,i,j,k;if(c>=0){e=b.data;f=e.length;if(c<f){g=c+d|0;if(g>f){h=new O;G(h,M(J(F(J(F(N(),B(37)),g),B(30)),f)));D(h);}if(L(a)<d){h=new Cm;H(h);D(h);}if(d<0){h=new O;G(h,M(F(J(F(N(),B(31)),d),B(32))));D(h);}g=a.p;i=0;while(i<d){j=c+1|0;f=g+1|0;e[c]=Fp(a,g);i=i+1|0;c=j;g=f;}a.p=a.p+d|0;return a;}}b=b.data;k=new O;G(k,M(F(J(F(J(F(N(),B(33)),c),B(27)),b.length),B(34))));D(k);}
|
||||
function Gb(a,b){return Dh(a,b,0,b.data.length);}
|
||||
function Gs(a,b,c,d){var e,f,g,h,i,j,k;if(DZ(a)){e=new B$;H(e);D(e);}if(L(a)<d){e=new B0;H(e);D(e);}if(c>=0){f=b.data;g=f.length;if(c<g){h=c+d|0;if(h>g){e=new O;G(e,M(J(F(J(F(N(),B(38)),h),B(30)),g)));D(e);}if(d<0){e=new O;G(e,M(F(J(F(N(),B(31)),d),B(32))));D(e);}h=a.p;i=0;while(i<d){j=h+1|0;g=c+1|0;CS(a,h,f[c]);i=i+1|0;h=j;c=g;}a.p=a.p+d|0;return a;}}b=b.data;k=new O;G(k,M(F(J(F(J(F(N(),B(33)),c),B(27)),b.length),B(34))));D(k);}
|
||||
function FA(a,b,c,d){var e,f,g,h,i,j;if(DZ(a)){b=new B$;H(b);D(b);}e=d-c|0;if(L(a)<e){b=new B0;H(b);D(b);}if(c>=0&&c<R(b)){if(d>R(b)){f=new O;G(f,M(J(F(J(F(N(),B(38)),d),B(39)),R(b))));D(f);}if(c>d){b=new O;G(b,M(J(F(J(F(N(),B(40)),c),B(41)),d)));D(b);}g=a.p;while(c<d){h=g+1|0;i=c+1|0;CS(a,g,By(b,c));g=h;c=i;}a.p=a.p+e|0;return a;}j=new O;G(j,M(F(J(F(J(F(N(),B(40)),c),B(27)),R(b)),B(34))));D(j);}
|
||||
function Ce(a,b){return FA(a,b,0,R(b));}
|
||||
function F0(a){return 1;}
|
||||
function F5(a){return a.bz;}
|
||||
function ET(a){a.N=a.p;a.p=0;a.bN=(-1);return a;}
|
||||
function GD(a,b){Bf(a,b);return a;}
|
||||
function C_(){Q.call(this);}
|
||||
function CK(){}
|
||||
function Fg(){var a=this;C.call(a);a.w=Long_ZERO;a.B=Long_ZERO;}
|
||||
function GP(){var a=new Fg();HU(a);return a;}
|
||||
function HU(a){a.w=Long_fromInt(1);a.B=Long_ZERO;}
|
||||
function GN(a,b){a.w=Long_and(b,Long_fromInt(65535));a.B=Long_and(Long_shr(b,16),Long_fromInt(65535));}
|
||||
function Hz(a){a.w=Long_fromInt(1);a.B=Long_ZERO;}
|
||||
function Hy(a){return Long_or(Long_shl(a.B,16),a.w);}
|
||||
function He(a,b,c,d){var e,f,g,h,i,j;if(d==1){b=b.data;a.w=Long_add(a.w,Long_fromInt(b[c]&255));a.B=Long_add(a.B,a.w);a.w=Long_rem(a.w,Long_fromInt(65521));a.B=Long_rem(a.B,Long_fromInt(65521));return;}e=d/5552|0;f=d%5552|0;while(true){g=e+(-1)|0;if(e<=0)break;h=5552;while(true){e=h+(-1)|0;if(h<=0)break;i=b.data;j=a.w;d=c+1|0;a.w=Long_add(j,Long_fromInt(i[c]&255));a.B=Long_add(a.B,a.w);h=e;c=d;}a.w=Long_rem(a.w,Long_fromInt(65521));a.B=Long_rem(a.B,Long_fromInt(65521));e=g;}while(true){d=f+(-1)|0;if(f<=0)break;i
|
||||
=b.data;j=a.w;e=c+1|0;a.w=Long_add(j,Long_fromInt(i[c]&255));a.B=Long_add(a.B,a.w);f=d;c=e;}a.w=Long_rem(a.w,Long_fromInt(65521));a.B=Long_rem(a.B,Long_fromInt(65521));}
|
||||
function BD(){P.call(this);}
|
||||
function CV(){Bc.call(this);}
|
||||
function Cz(){C.call(this);this.en=null;}
|
||||
var I9=null;var I$=null;function GK(a){var b=new Cz();Es(b,a);return b;}
|
||||
function Es(a,b){a.en=b;}
|
||||
function Gp(){I9=GK(B(42));I$=GK(B(43));}
|
||||
function CU(){}
|
||||
function CG(){var a=this;C.call(a);a.c4=null;a.b9=null;}
|
||||
function BE(){var a=this;CG.call(a);a.cC=0;a.bZ=null;}
|
||||
function O(){P.call(this);}
|
||||
function CD(){O.call(this);}
|
||||
function DH(){C.call(this);}
|
||||
var IK=null;function Z(b,c,d,e,f){var g,h,i,j,k,l,m;if(b!==null&&d!==null){if(c>=0&&e>=0&&f>=0&&(c+f|0)<=F3(b)&&(e+f|0)<=F3(d)){a:{b:{if(b!==d){g=CZ(B1(b));h=CZ(B1(d));if(g!==null&&h!==null){if(g===h)break b;if(!BY(g)&&!BY(h)){i=b;j=0;k=c;while(j<f){l=i.data;m=k+1|0;if(!Ep(h,l[k])){DW(b,c,d,e,j);b=new BZ;H(b);D(b);}j=j+1|0;k=m;}DW(b,c,d,e,f);return;}if(!BY(g))break a;if(BY(h))break b;else break a;}b=new BZ;H(b);D(b);}}DW(b,c,d,e,f);return;}b=new BZ;H(b);D(b);}b=new O;H(b);D(b);}d=new BD;G(d,B(44));D(d);}
|
||||
function DW(b,c,d,e,f){if (b !== d || e < c) {
|
||||
for (var i = 0; i < f; i = (i + 1) | 0) {d.data[e++] = b.data[c++];}} else {c = (c + f) | 0;e = (e + f) | 0;for (var i = 0; i < f; i = (i + 1) | 0) {d.data[--e] = b.data[--c];}}}
|
||||
function BM(){Q.call(this);}
|
||||
function CE(){var a=this;C.call(a);a.m=0;a.bW=0;a.b4=Long_ZERO;a.i=Long_ZERO;a.bI=0;a.x=0;a.cV=0;a.S=null;a.d=null;a.A=0;a.X=0;a.cz=null;a.r=null;a.I=null;}
|
||||
var I_=null;function EH(a){var b;if(a.d===null)return (-2);b=a.d;a.d.bD=Long_ZERO;b.e=Long_ZERO;a.d.o=null;a.m=14;a.X=(-1);B4(a.S);return 0;}
|
||||
function EN(a){if(a.S!==null)D1(a.S);return 0;}
|
||||
function Er(a,b){var c,d,e,f;a.d.o=null;a.S=null;a.x=0;if(b<0)b= -b;else if(b&1073741824){a.x=4;b=b&(-1073741825);if(b<48)b=b&15;}else if(b&(-32)){a.x=4;b=b&15;}else{a.x=(b>>4)+1|0;if(b<48)b=b&15;}if(b>=8&&b<=15){if(a.S!==null&&a.cV!=b){D1(a.S);a.S=null;}a.cV=b;c=new BX;d=a.d;b=1<<b;c.cp=$rt_createIntArray(1);c.bF=$rt_createIntArray(1);c.bC=$rt_createIntArray(1);c.bB=$rt_createIntArray(1);c.cx=Bu($rt_arraycls($rt_intcls()),1);c.cy=Bu($rt_arraycls($rt_intcls()),1);c.cG=$rt_createIntArray(1);c.cJ=$rt_createIntArray(1);e
|
||||
=new Bj;e.bf=null;e.be=null;e.C=null;e.H=null;e.bl=null;e.T=null;c.cv=e;c.a=d;e=new Cu;f=c.a;e.bm=0;e.g=f;e.c=c;c.bT=e;c.bb=$rt_createIntArray(4320);c.u=$rt_createByteArray(b);c.s=b;c.ca=d.Z.x?1:0;c.v=0;B4(c);a.S=c;EH(a);return 0;}EN(a);return (-2);}
|
||||
function FC(a,b){var c,d,e,f,g,h,i,$$je;if(a.d!==null&&a.d.q!==null){c=b!=4?0:(-5);d=(-5);a:{b:{c:{d:{e:{f:{g:{h:{i:while(true){j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{switch(a.m){case 6:a.m=13;a.d.o=B(45);a.bI=0;return (-2);case 7:d=FX(a.S,d);if(d==(-3)){a.m=13;a.bI=0;continue i;}if(!d)d=c;if(d!=1)break i;a.b4=a.d.K.cY();B4(a.S);if(!a.x){a.m=12;d=c;continue i;}a.m=8;d=c;break w;case 12:break e;case 13:return (-3);case 14:break r;case 23:try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}
|
||||
else{throw $$e;}}a.A=a.i.lo&65535;if((a.A&255)!=8){a.d.o=B(46);a.m=13;continue i;}if(a.A&57344){a.d.o=B(47);a.m=13;continue i;}if(a.A&512)BQ(a,2,a.i);a.m=16;break p;case 2:break d;case 3:break c;case 4:break b;case 5:c=d;break a;case 8:break w;case 9:break v;case 10:break u;case 11:break t;case 15:break s;case 16:break p;case 17:break o;case 18:break n;case 19:break q;case 20:break l;case 21:break k;case 22:break;default:return (-2);}break j;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));f
|
||||
=a.d.q.data;e=a.d;b=e.b;e.b=b+1|0;a.i=Long_and(Long_fromInt((f[b]&255)<<24),new Long(4278190080, 0));a.m=9;d=c;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=a.d;b=e.b;e.b=b+1|0;a.i=Long_add(g,Long_and(Long_fromInt((f[b]&255)<<16),Long_fromInt(16711680)));a.m=10;d=c;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=a.d;b=e.b;e.b=b+1|0;a.i=Long_add(g,Long_and(Long_fromInt((f[b]&255)<<8),Long_fromInt(65280)));a.m
|
||||
=11;d=c;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=a.d;b=e.b;e.b=b+1|0;a.i=Long_add(g,Long_and(Long_fromInt(f[b]),Long_fromInt(255)));if(a.A)a.i=Long_and(Long_or(Long_or(Long_or(Long_shr(Long_and(a.i,Long_fromInt(-16777216)),24),Long_shr(Long_and(a.i,Long_fromInt(16711680)),8)),Long_shl(Long_and(a.i,Long_fromInt(65280)),8)),Long_shl(Long_and(a.i,Long_fromInt(65535)),24)),new Long(4294967295, 0));if(a.b4.lo!=a.i.lo)a.d.o=B(48);else if(a.A&&a.r!==null)a.r.ec
|
||||
=a.i;a.m=15;d=c;}if(!(a.x&&a.A)){if(a.d.o===null)break f;if(!Bo(a.d.o,B(48)))break f;a.m=13;a.bI=5;continue i;}try{d=Bl(a,4,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(a.d.o!==null&&Bo(a.d.o,B(48))){a.m=13;a.bI=5;continue i;}if(Long_eq(a.i,Long_and(a.d.bD,new Long(4294967295, 0)))){a.d.o=null;break f;}a.d.o=B(49);a.m=13;continue i;}if(!a.x){a.m=7;continue i;}try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(!(a.x
|
||||
!=4&&!(a.x&2))&&Long_eq(a.i,Long_fromInt(35615))){if(a.x==4)a.x=2;a.d.K=Hb();BQ(a,2,a.i);if(a.r===null)a.r=Ii();a.m=23;continue i;}if(a.x&2){a.m=13;a.d.o=B(50);continue i;}a.A=0;a.bW=a.i.lo&255;h=Long_shr(a.i,8).lo&255;if(!(a.x&1&&!(((a.bW<<8)+h|0)%31|0))&&(a.bW&15)!=8){if(a.x!=4){a.m=13;a.d.o=B(50);continue i;}e=a.d;e.b=e.b-2|0;e=a.d;e.f=e.f+2|0;e=a.d;e.e=Long_sub(e.e,Long_fromInt(2));a.x=0;a.m=7;continue i;}if((a.bW&15)!=8){a.m=13;a.d.o=B(46);continue i;}if(a.x==4)a.x=1;if(((a.bW>>4)+8|0)>a.cV){a.m=13;a.d.o
|
||||
=B(51);continue i;}a.d.K=GP();if(h&32){a.m=2;break d;}a.m=7;continue i;}break m;}try{d=Bl(a,4,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(a.r!==null)a.r.dN=a.i;if(a.A&512)BQ(a,4,a.i);a.m=17;}try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(a.r!==null){a.r.er=a.i.lo&255;a.r.dl=a.i.lo>>8&255;}if(a.A&512)BQ(a,2,a.i);a.m=18;}if(a.A&1024){try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}
|
||||
else{throw $$e;}}if(a.r!==null)a.r.bL=$rt_createByteArray(a.i.lo&65535);if(a.A&512)BQ(a,2,a.i);}else if(a.r!==null)a.r.bL=null;a.m=19;}if(a.A&1024)x:{try{d=Ex(a,d,c);if(a.r===null)break x;f=Cg(a.I);i=f.data;a.I=null;b=i.length;if(b!=a.r.bL.data.length){a.d.o=B(52);a.m=13;continue i;}Z(f,0,a.r.bL,0,b);break x;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}}else if(a.r!==null)a.r.bL=null;a.m=20;}y:{if(a.A&2048){z:{try{d=D9(a,d,c);if(a.r===null)break z;a.r.dd=Cg(a.I);break z;}
|
||||
catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break h;}else{throw $$e;}}}try{a.I=null;break y;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break h;}else{throw $$e;}}}else if(a.r!==null)a.r.dd=null;}a.m=21;}ba:{if(a.A&4096){bb:{try{d=D9(a,d,c);if(a.r===null)break bb;a.r.dm=Cg(a.I);break bb;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break g;}else{throw $$e;}}}try{a.I=null;break ba;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break g;}else{throw $$e;}}}else if(a.r!==null)a.r.dm=
|
||||
null;}a.m=22;}if(a.A&512){try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(a.r!==null)a.r.eG=Long_and(a.i,Long_fromInt(65535)).lo;if(Long_ne(a.i,Long_and(a.d.K.cY(),Long_fromInt(65535)))){a.m=13;a.d.o=B(53);a.bI=5;continue;}}a.d.K=Hb();a.m=7;}return d;}return e.P;}return e.P;}a.m=12;}return 1;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));f=a.d.q.data;e=a.d;d=e.b;e.b=d+1|0;a.i=Long_and(Long_fromInt((f[d]&255)<<24),new Long(4278190080, 0));a.m
|
||||
=3;d=c;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=a.d;d=e.b;e.b=d+1|0;a.i=Long_add(g,Long_and(Long_fromInt((f[d]&255)<<16),Long_fromInt(16711680)));a.m=4;d=c;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=a.d;b=e.b;e.b=b+1|0;a.i=Long_add(g,Long_and(Long_fromInt((f[b]&255)<<8),Long_fromInt(65280)));a.m=5;}if(!a.d.f)return c;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=
|
||||
a.d;b=e.b;e.b=b+1|0;a.i=Long_add(g,Long_and(Long_fromInt(f[b]),Long_fromInt(255)));a.d.K.dy(a.i);a.m=6;return 2;}if(b==4&&a.m==14)return 0;return (-2);}
|
||||
function Bl(a,b,c,d){var e,f,g,h;if(a.X==(-1)){a.X=b;a.i=Long_ZERO;}while(true){if(a.X<=0){if(b==2)a.i=Long_and(a.i,Long_fromInt(65535));else if(b==4)a.i=Long_and(a.i,new Long(4294967295, 0));a.X=(-1);return c;}if(!a.d.f)break;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));f=a.i;g=a.d.q.data;e=a.d;h=e.b;e.b=h+1|0;a.i=Long_or(f,Long_fromInt((g[h]&255)<<((b-a.X|0)*8|0)));a.X=a.X-1|0;c=d;}D(FY(a,c));}
|
||||
function D9(a,b,c){var d,e;if(a.I===null)a.I=GY();while(true){if(!a.d.f)D(FY(a,b));d=a.d;d.f=d.f-1|0;d=a.d;d.e=Long_add(d.e,Long_fromInt(1));e=a.d.q.data[a.d.b];if(e)Dv(a.I,a.d.q,a.d.b,1);a.d.K.bn(a.d.q,a.d.b,1);d=a.d;d.b=d.b+1|0;if(!e)break;b=c;}return c;}
|
||||
function Ex(a,b,c){var d;if(a.I===null)a.I=GY();while(Long_gt(a.i,Long_ZERO)){if(!a.d.f)D(FY(a,b));d=a.d;d.f=d.f-1|0;d=a.d;d.e=Long_add(d.e,Long_fromInt(1));Dv(a.I,a.d.q,a.d.b,1);a.d.K.bn(a.d.q,a.d.b,1);d=a.d;d.b=d.b+1|0;a.i=Long_sub(a.i,Long_fromInt(1));b=c;}return b;}
|
||||
function BQ(a,b,c){var d;d=0;while(d<b){a.cz.data[d]=Long_and(c,Long_fromInt(255)).lo<<24>>24;c=Long_shr(c,8);d=d+1|0;}a.d.K.bn(a.cz,0,b);}
|
||||
function Fk(){var b,c;b=$rt_createByteArray(4);c=b.data;c[0]=0;c[1]=0;c[2]=(-1);c[3]=(-1);I_=b;}
|
||||
function DT(){}
|
||||
function Bp(){C.call(this);}
|
||||
function EY(a,b,c,d){var e,f,g;e=0;while(e<d){f=b.data;g=c+1|0;Fo(a,f[c]);e=e+1|0;c=g;}}
|
||||
function Cp(){Bp.call(this);this.c6=null;}
|
||||
function Df(){var a=this;Cp.call(a);a.ep=0;a.cS=0;a.Y=null;a.b1=null;a.dD=null;}
|
||||
function Dk(a,b,c,d){var $$je;if(a.c6===null)a.cS=1;if(!(a.cS?0:1))return;a:{try{EY(a.c6,b,c,d);break a;}catch($$e){$$je=U($$e);if($$je instanceof Q){}else{throw $$e;}}a.cS=1;}}
|
||||
function DF(a,b,c,d){var e,f,g,h,i;e=b.data;f=Gc(b,c,d-c|0);e=$rt_createByteArray(BA(16,Ba(e.length,1024)));g=FZ(e,0,e.data.length);h=FK(Ek(FU(a.dD),I6),I6);while(true){i=BK(Fz(h,f,g,1));Dk(a,e,0,g.p);DC(g);if(!i)break;}while(true){i=BK(EM(h,g));Dk(a,e,0,g.p);DC(g);if(!i)break;}}
|
||||
function Eq(a,b){a.b1.data[0]=b;DF(a,a.b1,0,1);}
|
||||
function B5(a,b){F(a.Y,b);Dn(a);}
|
||||
function Ga(a,b){EG(ES(a.Y,b),10);Dn(a);}
|
||||
function Gf(a){Eq(a,10);}
|
||||
function Dn(a){var b;b=B2(a.Y)<=a.b1.data.length?a.b1:$rt_createCharArray(B2(a.Y));ED(a.Y,0,B2(a.Y),b,0);DF(a,b,0,B2(a.Y));Gk(a.Y,0);}
|
||||
function Ea(){Bp.call(this);}
|
||||
function Fo(a,b){$rt_putStderr(b);}
|
||||
function FL(){C.call(this);}
|
||||
function Ba(b,c){if(b<c)c=b;return c;}
|
||||
function BA(b,c){if(b>c)c=b;return c;}
|
||||
function BX(){var a=this;C.call(a);a.v=0;a.bV=0;a.bJ=0;a.L=0;a.G=null;a.cp=null;a.bF=null;a.bC=null;a.bB=null;a.cx=null;a.cy=null;a.cG=null;a.cJ=null;a.bT=null;a.b$=0;a.l=0;a.k=0;a.bb=null;a.u=null;a.s=0;a.n=0;a.h=0;a.ca=0;a.cv=null;a.a=null;}
|
||||
var Ja=null;var Jb=null;function B4(a){a.v=0;a.l=0;a.k=0;a.h=0;a.n=0;if(a.ca)a.a.K.cl();}
|
||||
function FX(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;c=a.a.b;d=a.a.f;e=a.k;f=a.l;g=a.h;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;a:{b:{c:{d:{e:while(true){f:{g:{h:{i:{j:{switch(a.v){case 2:break f;case 9:a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));case 0:break j;case 1:break;case 3:while(f<14){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<<f;f=f+8|0;c=k;}k=e&
|
||||
16383;a.bJ=k;l=k&31;if(l>29)break d;k=k>>5&31;if(k>29)break d;k:{k=(258+l|0)+k|0;if(!(a.G!==null&&a.G.data.length>=k))a.G=$rt_createIntArray(k);else{l=0;while(true){if(l>=k)break k;a.G.data[l]=0;l=l+1|0;}}}e=e>>>14;f=f+(-14)|0;a.L=0;a.v=4;break i;case 4:break i;case 5:break h;case 6:break g;case 7:break b;case 8:break a;default:a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-2));}while(f<32){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b
|
||||
|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<<f;f=f+8|0;c=k;}k=(e^(-1))>>>16&65535;l=e&65535;if(k!=l){a.v=9;a.a.o=B(54);a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));}a.bV=l;f=0;a.v=a.bV?2:!a.b$?0:7;e=f;continue e;}while(f<3){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<<f;f=f+8|0;c=k;}l:{m=e&7;a.b$=m&1;switch
|
||||
(m>>>1){case 0:k=e>>>3;l=f+(-3)|0;n=l&7;e=k>>>n;f=l-n|0;a.v=1;break l;case 1:FR(a.bC,a.bB,a.cx,a.cy,a.a);DN(a.bT,a.bC.data[0],a.bB.data[0],a.cx.data[0],0,a.cy.data[0],0);e=e>>>3;f=f+(-3)|0;a.v=6;break l;case 2:e=e>>>3;f=f+(-3)|0;a.v=3;break l;case 3:b=e>>>3;k=f+(-3)|0;a.v=9;a.a.o=B(55);a.k=b;a.l=k;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));default:}}continue e;}while(a.L<(4+(a.bJ>>>10)|0)){while(f<3){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c
|
||||
-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<<f;f=f+8|0;c=k;}o=a.G.data;j=Jb.data;k=a.L;a.L=k+1|0;o[j[k]]=e&7;e=e>>>3;f=f+(-3)|0;}while(a.L<19){o=a.G.data;j=Jb.data;k=a.L;a.L=k+1|0;o[j[k]]=0;}a.cp.data[0]=7;k=GC(a.cv,a.G,a.cp,a.bF,a.bb,a.a);if(k){if(k==(-3)){a.G=null;a.v=9;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,k);}a.L=0;a.v=5;}while(true){k=a.bJ;if(a.L>=((258+(k&31)|0)+(k>>5&31)|0))break;k=a.cp.data[0];while
|
||||
(f<k){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;l=c+1|0;e=e|(j[c]&255)<<f;f=f+8|0;c=l;}k=a.bb.data[((a.bF.data[0]+(e&Ja.data[k])|0)*3|0)+1|0];n=a.bb.data[((a.bF.data[0]+(e&Ja.data[k])|0)*3|0)+2|0];l=C6(n,16);if(l<0){e=e>>>k;f=f-k|0;j=a.G.data;k=a.L;a.L=k+1|0;j[k]=n;}else{p=C6(n,18);q=!p?7:n-14|0;p=p?3:11;while(f<(k+q|0)){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,
|
||||
b);}b=0;d=d+(-1)|0;j=a.a.q.data;n=c+1|0;e=e|(j[c]&255)<<f;f=f+8|0;c=n;}n=e>>>k;k=f-k|0;p=p+(n&Ja.data[q])|0;e=n>>>q;f=k-q|0;h=a.L;q=a.bJ;if((h+p|0)>((258+(q&31)|0)+(q>>5&31)|0))break c;if(!l&&h<1)break c;k=l?0:a.G.data[h-1|0];while(true){j=a.G.data;l=h+1|0;j[h]=k;p=p+(-1)|0;if(!p)break;h=l;}a.L=l;}}a.bF.data[0]=(-1);a.bC.data[0]=9;a.bB.data[0]=6;k=a.bJ;k=Fb(a.cv,257+(k&31)|0,1+(k>>5&31)|0,a.G,a.bC,a.bB,a.cG,a.cJ,a.bb,a.a);if(k){if(k==(-3)){a.G=null;a.v=9;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c
|
||||
-a.a.b|0));a.a.b=c;a.h=g;return I(a,k);}DN(a.bT,a.bC.data[0],a.bB.data[0],a.bb,a.cG.data[0],a.bb,a.cJ.data[0]);a.v=6;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;b=FE(a.bT,b);if(b!=1)break e;b=0;EX(a.bT,a.a);c=a.a.b;d=a.a.f;e=a.k;f=a.l;g=a.h;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;if(a.b$){a.v=7;break b;}a.v=0;continue e;}if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}if(!h){if(g==a.s&&a.n){g=0;h=g>=a.n?a.s-g|0:(a.n-g|0)-1
|
||||
|0;}if(!h){a.h=g;b=I(a,b);g=a.h;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;if(g==a.s&&a.n){g=0;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;}if(!h){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}}}b=0;k=a.bV;if(k>d)k=d;if(k>h)k=h;Z(a.a.q,c,a.u,g,k);c=c+k|0;d=d-k|0;g=g+k|0;h=h-k|0;k=a.bV-k|0;a.bV=k;if(k)continue;a.v=!a.b$?0:7;}return I(a,b);}a.v=9;a.a.o=B(56);a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));}a.G=null;a.v=9;a.a.o=B(57);a.k
|
||||
=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));}a.h=g;b=I(a,b);g=a.h;if(a.n!=a.h){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}a.v=8;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,1);}
|
||||
function D1(a){B4(a);a.u=null;a.bb=null;}
|
||||
function I(a,b){var c,d,e,f,g;c=a.a.b2;d=a.n;e=(d>a.h?a.s:a.h)-d|0;if(e>a.a.R)e=a.a.R;if(e&&b==(-5))b=0;f=a.a;f.R=f.R-e|0;f=a.a;f.bD=Long_add(f.bD,Long_fromInt(e));if(a.ca&&e>0)a.a.K.bn(a.u,d,e);Z(a.u,d,a.a.cr,c,e);c=c+e|0;g=d+e|0;if(g==a.s){if(a.h==a.s)a.h=0;d=a.h-0|0;if(d>a.a.R)d=a.a.R;if(d&&b==(-5))b=0;f=a.a;f.R=f.R-d|0;f=a.a;f.bD=Long_add(f.bD,Long_fromInt(d));if(a.ca&&d>0)a.a.K.bn(a.u,0,d);Z(a.u,0,a.a.cr,c,d);c=c+d|0;g=0+d|0;}a.a.b2=c;a.n=g;return b;}
|
||||
function Eo(){var b,c;b=$rt_createIntArray(17);c=b.data;c[0]=0;c[1]=1;c[2]=3;c[3]=7;c[4]=15;c[5]=31;c[6]=63;c[7]=127;c[8]=255;c[9]=511;c[10]=1023;c[11]=2047;c[12]=4095;c[13]=8191;c[14]=16383;c[15]=32767;c[16]=65535;Ja=b;b=$rt_createIntArray(19);c=b.data;c[0]=16;c[1]=17;c[2]=18;c[3]=0;c[4]=8;c[5]=7;c[6]=9;c[7]=6;c[8]=10;c[9]=5;c[10]=11;c[11]=4;c[12]=12;c[13]=3;c[14]=13;c[15]=2;c[16]=14;c[17]=1;c[18]=15;Jb=b;}
|
||||
function Bj(){var a=this;C.call(a);a.bf=null;a.be=null;a.C=null;a.H=null;a.bl=null;a.T=null;}
|
||||
var Jc=null;var Jd=null;var Je=null;var Jf=null;var Jg=null;var Jh=null;function Ca(a,b,c,d,e,f,g,h,i,j,k,l){var m,n,o,p,q,r,s,t,u,v,w,x,y,z,ba,bb,bc,bd,be;m=0;n=d;while(true){o=b.data;p=a.C.data;q=o[c+m|0];p[q]=p[q]+1|0;m=m+1|0;n=n+(-1)|0;if(!n)break;}if(a.C.data[0]==d){b=h.data;f=i.data;b[0]=(-1);f[0]=0;return 0;}i=i.data;r=i[0];s=1;a:{while(true){if(s>15)break a;if(a.C.data[s])break;s=s+1|0;}}if(r<s)r=s;t=15;b:{while(true){if(!t)break b;if(a.C.data[t])break;t=t+(-1)|0;}}if(r>t)r=t;i[0]=r;u=1<<s;m=s;while
|
||||
(true){if(m>=t){v=u-a.C.data[t]|0;if(v<0)return (-3);b=a.C.data;b[t]=b[t]+v|0;b=a.T.data;u=0;b[1]=u;m=1;w=2;x=t;while(true){x=x+(-1)|0;if(!x)break;i=a.T.data;u=u+a.C.data[m]|0;i[w]=u;w=w+1|0;m=m+1|0;}m=0;w=0;while(true){x=o[c+w|0];if(x){i=l.data;b=a.T.data;q=b[x];b[x]=q+1|0;i[q]=m;}w=w+1|0;m=m+1|0;if(m>=d)break;}u=a.T.data[t];b=a.T.data;m=0;b[0]=m;w=0;y=(-1);z= -r;a.bl.data[0]=0;ba=0;bb=0;c:while(true){if(s>t)return v&&t!=1?(-5):0;bc=a.C.data[s];while(true){bd=bc+(-1)|0;if(!bc)break;n=bd+1|0;while(true){be=
|
||||
z+r|0;if(s<=be)break;y=y+1|0;x=t-be|0;if(x>r)x=r;d:{bc=s-be|0;c=1<<bc;if(c>n){q=c-n|0;if(bc<x){c=s;while(true){bc=bc+1|0;if(bc>=x)break;d=q<<1;b=a.C.data;c=c+1|0;if(d<=b[c])break d;q=d-a.C.data[c]|0;}}}}b=k.data;bb=1<<bc;if((b[0]+bb|0)>1440)break c;i=a.bl.data;ba=b[0];i[y]=ba;b[0]=b[0]+bb|0;if(!y){h.data[0]=ba;z=be;continue;}a.T.data[y]=m;a.H.data[0]=bc<<24>>24;a.H.data[1]=r<<24>>24;c=m>>>(be-r|0);i=a.H.data;b=a.bl.data;q=y-1|0;i[2]=(ba-b[q]|0)-c|0;Z(a.H,0,j,(a.bl.data[q]+c|0)*3|0,3);z=be;}b=a.H.data;x=s-z|
|
||||
0;b[1]=x<<24>>24;if(w>=u)a.H.data[0]=192;else{p=l.data;if(p[w]>=e){i=g.data;o=f.data;a.H.data[0]=((i[p[w]-e|0]+16|0)+64|0)<<24>>24;b=a.H.data;d=w+1|0;b[2]=o[p[w]-e|0];w=d;}else{b=a.H;b.data[0]=(p[w]>=256?96:0)<<24>>24;b=a.H.data;d=w+1|0;b[2]=p[w];w=d;}}q=1<<x;c=m>>>z;while(c<bb){Z(a.H,0,j,(ba+c|0)*3|0,3);c=c+q|0;}c=1<<(s-1|0);while(m&c){m=m^c;c=c>>>1;}m=m^c;x=(1<<z)-1|0;while((m&x)!=a.T.data[y]){y=y+(-1)|0;z=z-r|0;x=(1<<z)-1|0;}bc=bd;}s=s+1|0;}return (-3);}q=u-a.C.data[m]|0;if(q<0)break;m=m+1|0;u=q<<1;}return (-3);}
|
||||
function GC(a,b,c,d,e,f){var g;CB(a,19);a.bf.data[0]=0;g=Ca(a,b,0,19,19,null,null,d,c,e,a.bf,a.be);if(g==(-3))f.o=B(58);else if(!(g!=(-5)&&c.data[0])){f.o=B(59);g=(-3);}return g;}
|
||||
function Fb(a,b,c,d,e,f,g,h,i,j){var k;CB(a,288);a.bf.data[0]=0;k=Ca(a,d,0,b,257,Je,Jf,g,e,i,a.bf,a.be);if(!k&&e.data[0]){CB(a,288);c=Ca(a,d,b,c,0,Jg,Jh,h,f,i,a.bf,a.be);if(!c&&!(!f.data[0]&&b>257))return 0;if(c==(-3))j.o=B(60);else if(c==(-5)){j.o=B(61);c=(-3);}else if(c!=(-4)){j.o=B(62);c=(-3);}return c;}if(k==(-3))j.o=B(63);else if(k!=(-4)){j.o=B(64);k=(-3);}return k;}
|
||||
function FR(b,c,d,e,f){e=e.data;d=d.data;c=c.data;b.data[0]=9;c[0]=5;d[0]=Jc;e[0]=Jd;return 0;}
|
||||
function CB(a,b){var c;if(a.bf===null){a.bf=$rt_createIntArray(1);a.be=$rt_createIntArray(b);a.C=$rt_createIntArray(16);a.H=$rt_createIntArray(3);a.bl=$rt_createIntArray(15);a.T=$rt_createIntArray(16);}if(a.be.data.length<b)a.be=$rt_createIntArray(b);c=0;while(c<b){a.be.data[c]=0;c=c+1|0;}c=0;while(c<16){a.C.data[c]=0;c=c+1|0;}c=0;while(c<3){a.H.data[c]=0;c=c+1|0;}Z(a.C,0,a.bl,0,15);Z(a.C,0,a.T,0,16);}
|
||||
function E7(){var b,c;b=$rt_createIntArray(1536);c=b.data;c[0]=96;c[1]=7;c[2]=256;c[3]=0;c[4]=8;c[5]=80;c[6]=0;c[7]=8;c[8]=16;c[9]=84;c[10]=8;c[11]=115;c[12]=82;c[13]=7;c[14]=31;c[15]=0;c[16]=8;c[17]=112;c[18]=0;c[19]=8;c[20]=48;c[21]=0;c[22]=9;c[23]=192;c[24]=80;c[25]=7;c[26]=10;c[27]=0;c[28]=8;c[29]=96;c[30]=0;c[31]=8;c[32]=32;c[33]=0;c[34]=9;c[35]=160;c[36]=0;c[37]=8;c[38]=0;c[39]=0;c[40]=8;c[41]=128;c[42]=0;c[43]=8;c[44]=64;c[45]=0;c[46]=9;c[47]=224;c[48]=80;c[49]=7;c[50]=6;c[51]=0;c[52]=8;c[53]=88;c[54]
|
||||
=0;c[55]=8;c[56]=24;c[57]=0;c[58]=9;c[59]=144;c[60]=83;c[61]=7;c[62]=59;c[63]=0;c[64]=8;c[65]=120;c[66]=0;c[67]=8;c[68]=56;c[69]=0;c[70]=9;c[71]=208;c[72]=81;c[73]=7;c[74]=17;c[75]=0;c[76]=8;c[77]=104;c[78]=0;c[79]=8;c[80]=40;c[81]=0;c[82]=9;c[83]=176;c[84]=0;c[85]=8;c[86]=8;c[87]=0;c[88]=8;c[89]=136;c[90]=0;c[91]=8;c[92]=72;c[93]=0;c[94]=9;c[95]=240;c[96]=80;c[97]=7;c[98]=4;c[99]=0;c[100]=8;c[101]=84;c[102]=0;c[103]=8;c[104]=20;c[105]=85;c[106]=8;c[107]=227;c[108]=83;c[109]=7;c[110]=43;c[111]=0;c[112]=8;c[113]
|
||||
=116;c[114]=0;c[115]=8;c[116]=52;c[117]=0;c[118]=9;c[119]=200;c[120]=81;c[121]=7;c[122]=13;c[123]=0;c[124]=8;c[125]=100;c[126]=0;c[127]=8;c[128]=36;c[129]=0;c[130]=9;c[131]=168;c[132]=0;c[133]=8;c[134]=4;c[135]=0;c[136]=8;c[137]=132;c[138]=0;c[139]=8;c[140]=68;c[141]=0;c[142]=9;c[143]=232;c[144]=80;c[145]=7;c[146]=8;c[147]=0;c[148]=8;c[149]=92;c[150]=0;c[151]=8;c[152]=28;c[153]=0;c[154]=9;c[155]=152;c[156]=84;c[157]=7;c[158]=83;c[159]=0;c[160]=8;c[161]=124;c[162]=0;c[163]=8;c[164]=60;c[165]=0;c[166]=9;c[167]
|
||||
=216;c[168]=82;c[169]=7;c[170]=23;c[171]=0;c[172]=8;c[173]=108;c[174]=0;c[175]=8;c[176]=44;c[177]=0;c[178]=9;c[179]=184;c[180]=0;c[181]=8;c[182]=12;c[183]=0;c[184]=8;c[185]=140;c[186]=0;c[187]=8;c[188]=76;c[189]=0;c[190]=9;c[191]=248;c[192]=80;c[193]=7;c[194]=3;c[195]=0;c[196]=8;c[197]=82;c[198]=0;c[199]=8;c[200]=18;c[201]=85;c[202]=8;c[203]=163;c[204]=83;c[205]=7;c[206]=35;c[207]=0;c[208]=8;c[209]=114;c[210]=0;c[211]=8;c[212]=50;c[213]=0;c[214]=9;c[215]=196;c[216]=81;c[217]=7;c[218]=11;c[219]=0;c[220]=8;c[221]
|
||||
=98;c[222]=0;c[223]=8;c[224]=34;c[225]=0;c[226]=9;c[227]=164;c[228]=0;c[229]=8;c[230]=2;c[231]=0;c[232]=8;c[233]=130;c[234]=0;c[235]=8;c[236]=66;c[237]=0;c[238]=9;c[239]=228;c[240]=80;c[241]=7;c[242]=7;c[243]=0;c[244]=8;c[245]=90;c[246]=0;c[247]=8;c[248]=26;c[249]=0;c[250]=9;c[251]=148;c[252]=84;c[253]=7;c[254]=67;c[255]=0;c[256]=8;c[257]=122;c[258]=0;c[259]=8;c[260]=58;c[261]=0;c[262]=9;c[263]=212;c[264]=82;c[265]=7;c[266]=19;c[267]=0;c[268]=8;c[269]=106;c[270]=0;c[271]=8;c[272]=42;c[273]=0;c[274]=9;c[275]
|
||||
=180;c[276]=0;c[277]=8;c[278]=10;c[279]=0;c[280]=8;c[281]=138;c[282]=0;c[283]=8;c[284]=74;c[285]=0;c[286]=9;c[287]=244;c[288]=80;c[289]=7;c[290]=5;c[291]=0;c[292]=8;c[293]=86;c[294]=0;c[295]=8;c[296]=22;c[297]=192;c[298]=8;c[299]=0;c[300]=83;c[301]=7;c[302]=51;c[303]=0;c[304]=8;c[305]=118;c[306]=0;c[307]=8;c[308]=54;c[309]=0;c[310]=9;c[311]=204;c[312]=81;c[313]=7;c[314]=15;c[315]=0;c[316]=8;c[317]=102;c[318]=0;c[319]=8;c[320]=38;c[321]=0;c[322]=9;c[323]=172;c[324]=0;c[325]=8;c[326]=6;c[327]=0;c[328]=8;c[329]
|
||||
=134;c[330]=0;c[331]=8;c[332]=70;c[333]=0;c[334]=9;c[335]=236;c[336]=80;c[337]=7;c[338]=9;c[339]=0;c[340]=8;c[341]=94;c[342]=0;c[343]=8;c[344]=30;c[345]=0;c[346]=9;c[347]=156;c[348]=84;c[349]=7;c[350]=99;c[351]=0;c[352]=8;c[353]=126;c[354]=0;c[355]=8;c[356]=62;c[357]=0;c[358]=9;c[359]=220;c[360]=82;c[361]=7;c[362]=27;c[363]=0;c[364]=8;c[365]=110;c[366]=0;c[367]=8;c[368]=46;c[369]=0;c[370]=9;c[371]=188;c[372]=0;c[373]=8;c[374]=14;c[375]=0;c[376]=8;c[377]=142;c[378]=0;c[379]=8;c[380]=78;c[381]=0;c[382]=9;c[383]
|
||||
=252;c[384]=96;c[385]=7;c[386]=256;c[387]=0;c[388]=8;c[389]=81;c[390]=0;c[391]=8;c[392]=17;c[393]=85;c[394]=8;c[395]=131;c[396]=82;c[397]=7;c[398]=31;c[399]=0;c[400]=8;c[401]=113;c[402]=0;c[403]=8;c[404]=49;c[405]=0;c[406]=9;c[407]=194;c[408]=80;c[409]=7;c[410]=10;c[411]=0;c[412]=8;c[413]=97;c[414]=0;c[415]=8;c[416]=33;c[417]=0;c[418]=9;c[419]=162;c[420]=0;c[421]=8;c[422]=1;c[423]=0;c[424]=8;c[425]=129;c[426]=0;c[427]=8;c[428]=65;c[429]=0;c[430]=9;c[431]=226;c[432]=80;c[433]=7;c[434]=6;c[435]=0;c[436]=8;c[437]
|
||||
=89;c[438]=0;c[439]=8;c[440]=25;c[441]=0;c[442]=9;c[443]=146;c[444]=83;c[445]=7;c[446]=59;c[447]=0;c[448]=8;c[449]=121;c[450]=0;c[451]=8;c[452]=57;c[453]=0;c[454]=9;c[455]=210;c[456]=81;c[457]=7;c[458]=17;c[459]=0;c[460]=8;c[461]=105;c[462]=0;c[463]=8;c[464]=41;c[465]=0;c[466]=9;c[467]=178;c[468]=0;c[469]=8;c[470]=9;c[471]=0;c[472]=8;c[473]=137;c[474]=0;c[475]=8;c[476]=73;c[477]=0;c[478]=9;c[479]=242;c[480]=80;c[481]=7;c[482]=4;c[483]=0;c[484]=8;c[485]=85;c[486]=0;c[487]=8;c[488]=21;c[489]=80;c[490]=8;c[491]
|
||||
=258;c[492]=83;c[493]=7;c[494]=43;c[495]=0;c[496]=8;c[497]=117;c[498]=0;c[499]=8;c[500]=53;c[501]=0;c[502]=9;c[503]=202;c[504]=81;c[505]=7;c[506]=13;c[507]=0;c[508]=8;c[509]=101;c[510]=0;c[511]=8;c[512]=37;c[513]=0;c[514]=9;c[515]=170;c[516]=0;c[517]=8;c[518]=5;c[519]=0;c[520]=8;c[521]=133;c[522]=0;c[523]=8;c[524]=69;c[525]=0;c[526]=9;c[527]=234;c[528]=80;c[529]=7;c[530]=8;c[531]=0;c[532]=8;c[533]=93;c[534]=0;c[535]=8;c[536]=29;c[537]=0;c[538]=9;c[539]=154;c[540]=84;c[541]=7;c[542]=83;c[543]=0;c[544]=8;c[545]
|
||||
=125;c[546]=0;c[547]=8;c[548]=61;c[549]=0;c[550]=9;c[551]=218;c[552]=82;c[553]=7;c[554]=23;c[555]=0;c[556]=8;c[557]=109;c[558]=0;c[559]=8;c[560]=45;c[561]=0;c[562]=9;c[563]=186;c[564]=0;c[565]=8;c[566]=13;c[567]=0;c[568]=8;c[569]=141;c[570]=0;c[571]=8;c[572]=77;c[573]=0;c[574]=9;c[575]=250;c[576]=80;c[577]=7;c[578]=3;c[579]=0;c[580]=8;c[581]=83;c[582]=0;c[583]=8;c[584]=19;c[585]=85;c[586]=8;c[587]=195;c[588]=83;c[589]=7;c[590]=35;c[591]=0;c[592]=8;c[593]=115;c[594]=0;c[595]=8;c[596]=51;c[597]=0;c[598]=9;c[599]
|
||||
=198;c[600]=81;c[601]=7;c[602]=11;c[603]=0;c[604]=8;c[605]=99;c[606]=0;c[607]=8;c[608]=35;c[609]=0;c[610]=9;c[611]=166;c[612]=0;c[613]=8;c[614]=3;c[615]=0;c[616]=8;c[617]=131;c[618]=0;c[619]=8;c[620]=67;c[621]=0;c[622]=9;c[623]=230;c[624]=80;c[625]=7;c[626]=7;c[627]=0;c[628]=8;c[629]=91;c[630]=0;c[631]=8;c[632]=27;c[633]=0;c[634]=9;c[635]=150;c[636]=84;c[637]=7;c[638]=67;c[639]=0;c[640]=8;c[641]=123;c[642]=0;c[643]=8;c[644]=59;c[645]=0;c[646]=9;c[647]=214;c[648]=82;c[649]=7;c[650]=19;c[651]=0;c[652]=8;c[653]
|
||||
=107;c[654]=0;c[655]=8;c[656]=43;c[657]=0;c[658]=9;c[659]=182;c[660]=0;c[661]=8;c[662]=11;c[663]=0;c[664]=8;c[665]=139;c[666]=0;c[667]=8;c[668]=75;c[669]=0;c[670]=9;c[671]=246;c[672]=80;c[673]=7;c[674]=5;c[675]=0;c[676]=8;c[677]=87;c[678]=0;c[679]=8;c[680]=23;c[681]=192;c[682]=8;c[683]=0;c[684]=83;c[685]=7;c[686]=51;c[687]=0;c[688]=8;c[689]=119;c[690]=0;c[691]=8;c[692]=55;c[693]=0;c[694]=9;c[695]=206;c[696]=81;c[697]=7;c[698]=15;c[699]=0;c[700]=8;c[701]=103;c[702]=0;c[703]=8;c[704]=39;c[705]=0;c[706]=9;c[707]
|
||||
=174;c[708]=0;c[709]=8;c[710]=7;c[711]=0;c[712]=8;c[713]=135;c[714]=0;c[715]=8;c[716]=71;c[717]=0;c[718]=9;c[719]=238;c[720]=80;c[721]=7;c[722]=9;c[723]=0;c[724]=8;c[725]=95;c[726]=0;c[727]=8;c[728]=31;c[729]=0;c[730]=9;c[731]=158;c[732]=84;c[733]=7;c[734]=99;c[735]=0;c[736]=8;c[737]=127;c[738]=0;c[739]=8;c[740]=63;c[741]=0;c[742]=9;c[743]=222;c[744]=82;c[745]=7;c[746]=27;c[747]=0;c[748]=8;c[749]=111;c[750]=0;c[751]=8;c[752]=47;c[753]=0;c[754]=9;c[755]=190;c[756]=0;c[757]=8;c[758]=15;c[759]=0;c[760]=8;c[761]
|
||||
=143;c[762]=0;c[763]=8;c[764]=79;c[765]=0;c[766]=9;c[767]=254;c[768]=96;c[769]=7;c[770]=256;c[771]=0;c[772]=8;c[773]=80;c[774]=0;c[775]=8;c[776]=16;c[777]=84;c[778]=8;c[779]=115;c[780]=82;c[781]=7;c[782]=31;c[783]=0;c[784]=8;c[785]=112;c[786]=0;c[787]=8;c[788]=48;c[789]=0;c[790]=9;c[791]=193;c[792]=80;c[793]=7;c[794]=10;c[795]=0;c[796]=8;c[797]=96;c[798]=0;c[799]=8;c[800]=32;c[801]=0;c[802]=9;c[803]=161;c[804]=0;c[805]=8;c[806]=0;c[807]=0;c[808]=8;c[809]=128;c[810]=0;c[811]=8;c[812]=64;c[813]=0;c[814]=9;c[815]
|
||||
=225;c[816]=80;c[817]=7;c[818]=6;c[819]=0;c[820]=8;c[821]=88;c[822]=0;c[823]=8;c[824]=24;c[825]=0;c[826]=9;c[827]=145;c[828]=83;c[829]=7;c[830]=59;c[831]=0;c[832]=8;c[833]=120;c[834]=0;c[835]=8;c[836]=56;c[837]=0;c[838]=9;c[839]=209;c[840]=81;c[841]=7;c[842]=17;c[843]=0;c[844]=8;c[845]=104;c[846]=0;c[847]=8;c[848]=40;c[849]=0;c[850]=9;c[851]=177;c[852]=0;c[853]=8;c[854]=8;c[855]=0;c[856]=8;c[857]=136;c[858]=0;c[859]=8;c[860]=72;c[861]=0;c[862]=9;c[863]=241;c[864]=80;c[865]=7;c[866]=4;c[867]=0;c[868]=8;c[869]
|
||||
=84;c[870]=0;c[871]=8;c[872]=20;c[873]=85;c[874]=8;c[875]=227;c[876]=83;c[877]=7;c[878]=43;c[879]=0;c[880]=8;c[881]=116;c[882]=0;c[883]=8;c[884]=52;c[885]=0;c[886]=9;c[887]=201;c[888]=81;c[889]=7;c[890]=13;c[891]=0;c[892]=8;c[893]=100;c[894]=0;c[895]=8;c[896]=36;c[897]=0;c[898]=9;c[899]=169;c[900]=0;c[901]=8;c[902]=4;c[903]=0;c[904]=8;c[905]=132;c[906]=0;c[907]=8;c[908]=68;c[909]=0;c[910]=9;c[911]=233;c[912]=80;c[913]=7;c[914]=8;c[915]=0;c[916]=8;c[917]=92;c[918]=0;c[919]=8;c[920]=28;c[921]=0;c[922]=9;c[923]
|
||||
=153;c[924]=84;c[925]=7;c[926]=83;c[927]=0;c[928]=8;c[929]=124;c[930]=0;c[931]=8;c[932]=60;c[933]=0;c[934]=9;c[935]=217;c[936]=82;c[937]=7;c[938]=23;c[939]=0;c[940]=8;c[941]=108;c[942]=0;c[943]=8;c[944]=44;c[945]=0;c[946]=9;c[947]=185;c[948]=0;c[949]=8;c[950]=12;c[951]=0;c[952]=8;c[953]=140;c[954]=0;c[955]=8;c[956]=76;c[957]=0;c[958]=9;c[959]=249;c[960]=80;c[961]=7;c[962]=3;c[963]=0;c[964]=8;c[965]=82;c[966]=0;c[967]=8;c[968]=18;c[969]=85;c[970]=8;c[971]=163;c[972]=83;c[973]=7;c[974]=35;c[975]=0;c[976]=8;c[977]
|
||||
=114;c[978]=0;c[979]=8;c[980]=50;c[981]=0;c[982]=9;c[983]=197;c[984]=81;c[985]=7;c[986]=11;c[987]=0;c[988]=8;c[989]=98;c[990]=0;c[991]=8;c[992]=34;c[993]=0;c[994]=9;c[995]=165;c[996]=0;c[997]=8;c[998]=2;c[999]=0;c[1000]=8;c[1001]=130;c[1002]=0;c[1003]=8;c[1004]=66;c[1005]=0;c[1006]=9;c[1007]=229;c[1008]=80;c[1009]=7;c[1010]=7;c[1011]=0;c[1012]=8;c[1013]=90;c[1014]=0;c[1015]=8;c[1016]=26;c[1017]=0;c[1018]=9;c[1019]=149;c[1020]=84;c[1021]=7;c[1022]=67;c[1023]=0;c[1024]=8;c[1025]=122;c[1026]=0;c[1027]=8;c[1028]
|
||||
=58;c[1029]=0;c[1030]=9;c[1031]=213;c[1032]=82;c[1033]=7;c[1034]=19;c[1035]=0;c[1036]=8;c[1037]=106;c[1038]=0;c[1039]=8;c[1040]=42;c[1041]=0;c[1042]=9;c[1043]=181;c[1044]=0;c[1045]=8;c[1046]=10;c[1047]=0;c[1048]=8;c[1049]=138;c[1050]=0;c[1051]=8;c[1052]=74;c[1053]=0;c[1054]=9;c[1055]=245;c[1056]=80;c[1057]=7;c[1058]=5;c[1059]=0;c[1060]=8;c[1061]=86;c[1062]=0;c[1063]=8;c[1064]=22;c[1065]=192;c[1066]=8;c[1067]=0;c[1068]=83;c[1069]=7;c[1070]=51;c[1071]=0;c[1072]=8;c[1073]=118;c[1074]=0;c[1075]=8;c[1076]=54;c[1077]
|
||||
=0;c[1078]=9;c[1079]=205;c[1080]=81;c[1081]=7;c[1082]=15;c[1083]=0;c[1084]=8;c[1085]=102;c[1086]=0;c[1087]=8;c[1088]=38;c[1089]=0;c[1090]=9;c[1091]=173;c[1092]=0;c[1093]=8;c[1094]=6;c[1095]=0;c[1096]=8;c[1097]=134;c[1098]=0;c[1099]=8;c[1100]=70;c[1101]=0;c[1102]=9;c[1103]=237;c[1104]=80;c[1105]=7;c[1106]=9;c[1107]=0;c[1108]=8;c[1109]=94;c[1110]=0;c[1111]=8;c[1112]=30;c[1113]=0;c[1114]=9;c[1115]=157;c[1116]=84;c[1117]=7;c[1118]=99;c[1119]=0;c[1120]=8;c[1121]=126;c[1122]=0;c[1123]=8;c[1124]=62;c[1125]=0;c[1126]
|
||||
=9;c[1127]=221;c[1128]=82;c[1129]=7;c[1130]=27;c[1131]=0;c[1132]=8;c[1133]=110;c[1134]=0;c[1135]=8;c[1136]=46;c[1137]=0;c[1138]=9;c[1139]=189;c[1140]=0;c[1141]=8;c[1142]=14;c[1143]=0;c[1144]=8;c[1145]=142;c[1146]=0;c[1147]=8;c[1148]=78;c[1149]=0;c[1150]=9;c[1151]=253;c[1152]=96;c[1153]=7;c[1154]=256;c[1155]=0;c[1156]=8;c[1157]=81;c[1158]=0;c[1159]=8;c[1160]=17;c[1161]=85;c[1162]=8;c[1163]=131;c[1164]=82;c[1165]=7;c[1166]=31;c[1167]=0;c[1168]=8;c[1169]=113;c[1170]=0;c[1171]=8;c[1172]=49;c[1173]=0;c[1174]=9;c[1175]
|
||||
=195;c[1176]=80;c[1177]=7;c[1178]=10;c[1179]=0;c[1180]=8;c[1181]=97;c[1182]=0;c[1183]=8;c[1184]=33;c[1185]=0;c[1186]=9;c[1187]=163;c[1188]=0;c[1189]=8;c[1190]=1;c[1191]=0;c[1192]=8;c[1193]=129;c[1194]=0;c[1195]=8;c[1196]=65;c[1197]=0;c[1198]=9;c[1199]=227;c[1200]=80;c[1201]=7;c[1202]=6;c[1203]=0;c[1204]=8;c[1205]=89;c[1206]=0;c[1207]=8;c[1208]=25;c[1209]=0;c[1210]=9;c[1211]=147;c[1212]=83;c[1213]=7;c[1214]=59;c[1215]=0;c[1216]=8;c[1217]=121;c[1218]=0;c[1219]=8;c[1220]=57;c[1221]=0;c[1222]=9;c[1223]=211;c[1224]
|
||||
=81;c[1225]=7;c[1226]=17;c[1227]=0;c[1228]=8;c[1229]=105;c[1230]=0;c[1231]=8;c[1232]=41;c[1233]=0;c[1234]=9;c[1235]=179;c[1236]=0;c[1237]=8;c[1238]=9;c[1239]=0;c[1240]=8;c[1241]=137;c[1242]=0;c[1243]=8;c[1244]=73;c[1245]=0;c[1246]=9;c[1247]=243;c[1248]=80;c[1249]=7;c[1250]=4;c[1251]=0;c[1252]=8;c[1253]=85;c[1254]=0;c[1255]=8;c[1256]=21;c[1257]=80;c[1258]=8;c[1259]=258;c[1260]=83;c[1261]=7;c[1262]=43;c[1263]=0;c[1264]=8;c[1265]=117;c[1266]=0;c[1267]=8;c[1268]=53;c[1269]=0;c[1270]=9;c[1271]=203;c[1272]=81;c[1273]
|
||||
=7;c[1274]=13;c[1275]=0;c[1276]=8;c[1277]=101;c[1278]=0;c[1279]=8;c[1280]=37;c[1281]=0;c[1282]=9;c[1283]=171;c[1284]=0;c[1285]=8;c[1286]=5;c[1287]=0;c[1288]=8;c[1289]=133;c[1290]=0;c[1291]=8;c[1292]=69;c[1293]=0;c[1294]=9;c[1295]=235;c[1296]=80;c[1297]=7;c[1298]=8;c[1299]=0;c[1300]=8;c[1301]=93;c[1302]=0;c[1303]=8;c[1304]=29;c[1305]=0;c[1306]=9;c[1307]=155;c[1308]=84;c[1309]=7;c[1310]=83;c[1311]=0;c[1312]=8;c[1313]=125;c[1314]=0;c[1315]=8;c[1316]=61;c[1317]=0;c[1318]=9;c[1319]=219;c[1320]=82;c[1321]=7;c[1322]
|
||||
=23;c[1323]=0;c[1324]=8;c[1325]=109;c[1326]=0;c[1327]=8;c[1328]=45;c[1329]=0;c[1330]=9;c[1331]=187;c[1332]=0;c[1333]=8;c[1334]=13;c[1335]=0;c[1336]=8;c[1337]=141;c[1338]=0;c[1339]=8;c[1340]=77;c[1341]=0;c[1342]=9;c[1343]=251;c[1344]=80;c[1345]=7;c[1346]=3;c[1347]=0;c[1348]=8;c[1349]=83;c[1350]=0;c[1351]=8;c[1352]=19;c[1353]=85;c[1354]=8;c[1355]=195;c[1356]=83;c[1357]=7;c[1358]=35;c[1359]=0;c[1360]=8;c[1361]=115;c[1362]=0;c[1363]=8;c[1364]=51;c[1365]=0;c[1366]=9;c[1367]=199;c[1368]=81;c[1369]=7;c[1370]=11;c[1371]
|
||||
=0;c[1372]=8;c[1373]=99;c[1374]=0;c[1375]=8;c[1376]=35;c[1377]=0;c[1378]=9;c[1379]=167;c[1380]=0;c[1381]=8;c[1382]=3;c[1383]=0;c[1384]=8;c[1385]=131;c[1386]=0;c[1387]=8;c[1388]=67;c[1389]=0;c[1390]=9;c[1391]=231;c[1392]=80;c[1393]=7;c[1394]=7;c[1395]=0;c[1396]=8;c[1397]=91;c[1398]=0;c[1399]=8;c[1400]=27;c[1401]=0;c[1402]=9;c[1403]=151;c[1404]=84;c[1405]=7;c[1406]=67;c[1407]=0;c[1408]=8;c[1409]=123;c[1410]=0;c[1411]=8;c[1412]=59;c[1413]=0;c[1414]=9;c[1415]=215;c[1416]=82;c[1417]=7;c[1418]=19;c[1419]=0;c[1420]
|
||||
=8;c[1421]=107;c[1422]=0;c[1423]=8;c[1424]=43;c[1425]=0;c[1426]=9;c[1427]=183;c[1428]=0;c[1429]=8;c[1430]=11;c[1431]=0;c[1432]=8;c[1433]=139;c[1434]=0;c[1435]=8;c[1436]=75;c[1437]=0;c[1438]=9;c[1439]=247;c[1440]=80;c[1441]=7;c[1442]=5;c[1443]=0;c[1444]=8;c[1445]=87;c[1446]=0;c[1447]=8;c[1448]=23;c[1449]=192;c[1450]=8;c[1451]=0;c[1452]=83;c[1453]=7;c[1454]=51;c[1455]=0;c[1456]=8;c[1457]=119;c[1458]=0;c[1459]=8;c[1460]=55;c[1461]=0;c[1462]=9;c[1463]=207;c[1464]=81;c[1465]=7;c[1466]=15;c[1467]=0;c[1468]=8;c[1469]
|
||||
=103;c[1470]=0;c[1471]=8;c[1472]=39;c[1473]=0;c[1474]=9;c[1475]=175;c[1476]=0;c[1477]=8;c[1478]=7;c[1479]=0;c[1480]=8;c[1481]=135;c[1482]=0;c[1483]=8;c[1484]=71;c[1485]=0;c[1486]=9;c[1487]=239;c[1488]=80;c[1489]=7;c[1490]=9;c[1491]=0;c[1492]=8;c[1493]=95;c[1494]=0;c[1495]=8;c[1496]=31;c[1497]=0;c[1498]=9;c[1499]=159;c[1500]=84;c[1501]=7;c[1502]=99;c[1503]=0;c[1504]=8;c[1505]=127;c[1506]=0;c[1507]=8;c[1508]=63;c[1509]=0;c[1510]=9;c[1511]=223;c[1512]=82;c[1513]=7;c[1514]=27;c[1515]=0;c[1516]=8;c[1517]=111;c[1518]
|
||||
=0;c[1519]=8;c[1520]=47;c[1521]=0;c[1522]=9;c[1523]=191;c[1524]=0;c[1525]=8;c[1526]=15;c[1527]=0;c[1528]=8;c[1529]=143;c[1530]=0;c[1531]=8;c[1532]=79;c[1533]=0;c[1534]=9;c[1535]=255;Jc=b;b=$rt_createIntArray(96);c=b.data;c[0]=80;c[1]=5;c[2]=1;c[3]=87;c[4]=5;c[5]=257;c[6]=83;c[7]=5;c[8]=17;c[9]=91;c[10]=5;c[11]=4097;c[12]=81;c[13]=5;c[14]=5;c[15]=89;c[16]=5;c[17]=1025;c[18]=85;c[19]=5;c[20]=65;c[21]=93;c[22]=5;c[23]=16385;c[24]=80;c[25]=5;c[26]=3;c[27]=88;c[28]=5;c[29]=513;c[30]=84;c[31]=5;c[32]=33;c[33]=92;c[34]
|
||||
=5;c[35]=8193;c[36]=82;c[37]=5;c[38]=9;c[39]=90;c[40]=5;c[41]=2049;c[42]=86;c[43]=5;c[44]=129;c[45]=192;c[46]=5;c[47]=24577;c[48]=80;c[49]=5;c[50]=2;c[51]=87;c[52]=5;c[53]=385;c[54]=83;c[55]=5;c[56]=25;c[57]=91;c[58]=5;c[59]=6145;c[60]=81;c[61]=5;c[62]=7;c[63]=89;c[64]=5;c[65]=1537;c[66]=85;c[67]=5;c[68]=97;c[69]=93;c[70]=5;c[71]=24577;c[72]=80;c[73]=5;c[74]=4;c[75]=88;c[76]=5;c[77]=769;c[78]=84;c[79]=5;c[80]=49;c[81]=92;c[82]=5;c[83]=12289;c[84]=82;c[85]=5;c[86]=13;c[87]=90;c[88]=5;c[89]=3073;c[90]=86;c[91]
|
||||
=5;c[92]=193;c[93]=192;c[94]=5;c[95]=24577;Jd=b;b=$rt_createIntArray(31);c=b.data;c[0]=3;c[1]=4;c[2]=5;c[3]=6;c[4]=7;c[5]=8;c[6]=9;c[7]=10;c[8]=11;c[9]=13;c[10]=15;c[11]=17;c[12]=19;c[13]=23;c[14]=27;c[15]=31;c[16]=35;c[17]=43;c[18]=51;c[19]=59;c[20]=67;c[21]=83;c[22]=99;c[23]=115;c[24]=131;c[25]=163;c[26]=195;c[27]=227;c[28]=258;c[29]=0;c[30]=0;Je=b;b=$rt_createIntArray(31);c=b.data;c[0]=0;c[1]=0;c[2]=0;c[3]=0;c[4]=0;c[5]=0;c[6]=0;c[7]=0;c[8]=1;c[9]=1;c[10]=1;c[11]=1;c[12]=2;c[13]=2;c[14]=2;c[15]=2;c[16]=3;c[17]
|
||||
=3;c[18]=3;c[19]=3;c[20]=4;c[21]=4;c[22]=4;c[23]=4;c[24]=5;c[25]=5;c[26]=5;c[27]=5;c[28]=0;c[29]=112;c[30]=112;Jf=b;b=$rt_createIntArray(30);c=b.data;c[0]=1;c[1]=2;c[2]=3;c[3]=4;c[4]=5;c[5]=7;c[6]=9;c[7]=13;c[8]=17;c[9]=25;c[10]=33;c[11]=49;c[12]=65;c[13]=97;c[14]=129;c[15]=193;c[16]=257;c[17]=385;c[18]=513;c[19]=769;c[20]=1025;c[21]=1537;c[22]=2049;c[23]=3073;c[24]=4097;c[25]=6145;c[26]=8193;c[27]=12289;c[28]=16385;c[29]=24577;Jg=b;b=$rt_createIntArray(30);c=b.data;c[0]=0;c[1]=0;c[2]=0;c[3]=0;c[4]=1;c[5]=1;c[6]
|
||||
=2;c[7]=2;c[8]=3;c[9]=3;c[10]=4;c[11]=4;c[12]=5;c[13]=5;c[14]=6;c[15]=6;c[16]=7;c[17]=7;c[18]=8;c[19]=8;c[20]=9;c[21]=9;c[22]=10;c[23]=10;c[24]=11;c[25]=11;c[26]=12;c[27]=12;c[28]=13;c[29]=13;Jh=b;}
|
||||
function Cu(){var a=this;C.call(a);a.D=0;a.bs=0;a.E=null;a.bm=0;a.bw=0;a.dp=0;a.cj=0;a.b_=0;a.cZ=0;a.cH=0;a.c8=null;a.cI=0;a.cD=null;a.cO=0;a.g=null;a.c=null;}
|
||||
var Ji=null;function DN(a,b,c,d,e,f,g){a.D=0;a.cZ=b<<24>>24;a.cH=c<<24>>24;a.c8=d;a.cI=e;a.cD=f;a.cO=g;a.E=null;}
|
||||
function FE(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o;c=a.g.b;d=a.g.f;e=a.c.k;f=a.c.l;g=a.c.h;h=g>=a.c.n?a.c.s-g|0:(a.c.n-g|0)-1|0;a:{b:while(true){c:{d:{e:{f:{g:{switch(a.D){case 0:break f;case 2:i=a.cj;while(f<i){if(!d){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,b);}b=0;d=d+(-1)|0;k=a.g.q.data;l=c+1|0;e=e|(k[c]&255)<<f;f=f+8|0;c=l;}a.bs=a.bs+(e&Ji.data[i])|0;e=e>>i;f=f-i|0;a.bw=a.cH;a.E=a.cD;a.bm=a.cO;a.D=3;break g;case 4:i=a.cj;while(f<i){if(!d){a.c.k=e;a.c.l
|
||||
=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,b);}b=0;d=d+(-1)|0;k=a.g.q.data;l=c+1|0;e=e|(k[c]&255)<<f;f=f+8|0;c=l;}a.b_=a.b_+(e&Ji.data[i])|0;e=e>>i;f=f-i|0;a.D=5;break c;case 6:break d;case 7:if(f>7){f=f+(-8)|0;d=d+1|0;c=c+(-1)|0;}a.c.h=g;b=I(a.c,b);g=a.c.h;if(a.c.n!=a.c.h){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,b);}a.D=8;break a;case 9:a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b
|
||||
|0));a.g.b=c;a.c.h=g;return I(a.c,(-3));case 1:break e;case 3:break;case 5:break c;case 8:break a;default:a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,(-2));}}l=a.bw;while(f<l){if(!d){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,b);}b=0;d=d+(-1)|0;k=a.g.q.data;i=c+1|0;e=e|(k[c]&255)<<f;f=f+8|0;c=i;}m=(a.bm+(e&Ji.data[l])|0)*3|0;k=a.E.data;i=m+1|0;e=e>>k[i];f=f-a.E.data[i]|0;l=a.E.data[m];if(l&16){a.cj
|
||||
=l&15;a.b_=a.E.data[m+2|0];a.D=4;continue b;}if(l&64){a.D=9;a.g.o=B(65);a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,(-3));}a.bw=l;a.bm=(m/3|0)+a.E.data[m+2|0]|0;continue b;}if(h>=258&&d>=10){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;b=F$(a,a.cZ,a.cH,a.c8,a.cI,a.cD,a.cO,a.c,a.g);c=a.g.b;d=a.g.f;e=a.c.k;f=a.c.l;g=a.c.h;h=g>=a.c.n?a.c.s-g|0:(a.c.n-g|0)-1|0;if(b){a.D=b!=1?9:7;continue b;}}a.bw=a.cZ;a.E=a.c8;a.bm
|
||||
=a.cI;a.D=1;}l=a.bw;while(f<l){if(!d)break b;b=0;d=d+(-1)|0;k=a.g.q.data;i=c+1|0;e=e|(k[c]&255)<<f;f=f+8|0;c=i;}m=(a.bm+(e&Ji.data[l])|0)*3|0;k=a.E.data;i=m+1|0;e=e>>>k[i];f=f-a.E.data[i]|0;n=a.E.data[m];if(!n){a.dp=a.E.data[m+2|0];a.D=6;continue b;}if(n&16){a.cj=n&15;a.bs=a.E.data[m+2|0];a.D=2;continue b;}if(!(n&64)){a.bw=n;a.bm=(m/3|0)+a.E.data[m+2|0]|0;continue b;}if(!(n&32)){a.D=9;a.g.o=B(66);a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,(-3));}a.D=
|
||||
7;continue b;}if(h)i=g;else{if(g!=a.c.s)i=g;else if(!a.c.n)i=g;else{i=0;h=i>=a.c.n?a.c.s-i|0:(a.c.n-i|0)-1|0;}if(!h){a.c.h=i;b=I(a.c,b);i=a.c.h;h=i>=a.c.n?a.c.s-i|0:(a.c.n-i|0)-1|0;if(i==a.c.s&&a.c.n){i=0;h=i>=a.c.n?a.c.s-i|0:(a.c.n-i|0)-1|0;}if(!h){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=i;return I(a.c,b);}}}b=0;k=a.c.u.data;g=i+1|0;k[i]=a.dp<<24>>24;h=h+(-1)|0;a.D=0;continue b;}i=g-a.b_|0;while(i<0){i=i+a.c.s|0;}while(a.bs){if(h)l=g;else{if(g!=a.c.s)l=g;else if
|
||||
(!a.c.n)l=g;else{l=0;h=l>=a.c.n?a.c.s-l|0:(a.c.n-l|0)-1|0;}if(!h){a.c.h=l;b=I(a.c,b);l=a.c.h;h=l>=a.c.n?a.c.s-l|0:(a.c.n-l|0)-1|0;if(l==a.c.s&&a.c.n){l=0;h=l>=a.c.n?a.c.s-l|0:(a.c.n-l|0)-1|0;}if(!h){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=l;return I(a.c,b);}}}o=a.c.u.data;g=l+1|0;k=a.c.u.data;m=i+1|0;o[l]=k[i];h=h+(-1)|0;i=m==a.c.s?0:m;a.bs=a.bs-1|0;}a.D=0;}a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,b);}a.c.k
|
||||
=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,1);}
|
||||
function EX(a,b){return;}
|
||||
function F$(a,b,c,d,e,f,g,h,i){var j,k,l,m,n,o,p,q,r,s,t,u,v,w,x;j=i.b;k=i.f;l=h.k;m=h.l;n=h.h;o=n>=h.n?h.s-n|0:(h.n-n|0)-1|0;p=Ji.data[b];q=Ji.data[c];while(true){if(m<20){k=k+(-1)|0;r=i.q.data;b=j+1|0;l=l|(r[j]&255)<<m;m=m+8|0;j=b;continue;}a:{s=d.data;t=l&p;u=(e+t|0)*3|0;c=s[u];if(!c){b=u+1|0;l=l>>s[b];m=m-s[b]|0;r=h.u.data;c=n+1|0;r[n]=s[u+2|0]<<24>>24;o=o+(-1)|0;}else{while(true){b=u+1|0;l=l>>s[b];m=m-s[b]|0;if(c&16){b=c&15;v=s[u+2|0]+(l&Ji.data[b])|0;w=l>>b;m=m-b|0;while(m<15){k=k+(-1)|0;r=i.q.data;b=
|
||||
j+1|0;w=w|(r[j]&255)<<m;m=m+8|0;j=b;}r=f.data;b=w&q;x=(g+b|0)*3|0;c=r[x];while(true){l=x+1|0;w=w>>r[l];m=m-r[l]|0;if(c&16)break;if(c&64){i.o=B(65);b=i.f-k|0;c=m>>3;if(c<b)b=c;c=k+b|0;e=j-b|0;b=m-(b<<3)|0;h.k=w;h.l=b;i.f=c;i.e=Long_add(i.e,Long_fromInt(e-i.b|0));i.b=e;h.h=n;return (-3);}b=(b+r[x+2|0]|0)+(w&Ji.data[c])|0;x=(g+b|0)*3|0;c=r[x];}b=c&15;while(m<b){k=k+(-1)|0;s=i.q.data;c=j+1|0;w=w|(s[j]&255)<<m;m=m+8|0;j=c;}x=r[x+2|0]+(w&Ji.data[b])|0;l=w>>b;m=m-b|0;o=o-v|0;if(n>=x){w=n-x|0;b=n-w|0;if(b>0&&2>b){s
|
||||
=h.u.data;b=n+1|0;r=h.u.data;c=w+1|0;s[n]=r[w];s=h.u.data;n=b+1|0;r=h.u.data;w=c+1|0;s[b]=r[c];v=v+(-2)|0;}else{Z(h.u,w,h.u,n,2);n=n+2|0;w=w+2|0;v=v+(-2)|0;}}else{w=n-x|0;while(true){w=w+h.s|0;if(w>=0)break;}b=h.s-w|0;if(v>b){v=v-b|0;c=n-w|0;if(c>0&&b>c){c=n;while(true){s=h.u.data;n=c+1|0;r=h.u.data;x=w+1|0;s[c]=r[w];b=b+(-1)|0;if(!b)break;c=n;w=x;}}else{Z(h.u,w,h.u,n,b);n=n+b|0;}w=0;}}b=n-w|0;if(b>0&&v>b){while(true){s=h.u.data;c=n+1|0;r=h.u.data;b=w+1|0;s[n]=r[w];v=v+(-1)|0;if(!v)break;n=c;w=b;}break a;}Z(h.u,
|
||||
w,h.u,n,v);c=n+v|0;break a;}if(c&64){if(c&32){v=i.f-k|0;b=m>>3;if(b<v)v=b;b=k+v|0;c=j-v|0;e=m-(v<<3)|0;h.k=l;h.l=e;i.f=b;i.e=Long_add(i.e,Long_fromInt(c-i.b|0));i.b=c;h.h=n;return 1;}i.o=B(66);v=i.f-k|0;b=m>>3;if(b<v)v=b;e=k+v|0;b=j-v|0;c=m-(v<<3)|0;h.k=l;h.l=c;i.f=e;i.e=Long_add(i.e,Long_fromInt(b-i.b|0));i.b=b;h.h=n;return (-3);}t=(t+s[u+2|0]|0)+(l&Ji.data[c])|0;u=(e+t|0)*3|0;c=s[u];if(!c)break;}b=u+1|0;l=l>>s[b];m=m-s[b]|0;r=h.u.data;c=n+1|0;r[n]=s[u+2|0]<<24>>24;o=o+(-1)|0;}}if(o<258)break;if(k<10)break;n
|
||||
=c;}v=i.f-k|0;b=m>>3;if(b<v)v=b;b=k+v|0;e=j-v|0;g=m-(v<<3)|0;h.k=l;h.l=g;i.f=b;i.e=Long_add(i.e,Long_fromInt(e-i.b|0));i.b=e;h.h=c;return 0;}
|
||||
function FI(){var b,c;b=$rt_createIntArray(17);c=b.data;c[0]=0;c[1]=1;c[2]=3;c[3]=7;c[4]=15;c[5]=31;c[6]=63;c[7]=127;c[8]=255;c[9]=511;c[10]=1023;c[11]=2047;c[12]=4095;c[13]=8191;c[14]=16383;c[15]=32767;c[16]=65535;Ji=b;}
|
||||
function BC(){Q.call(this);}
|
||||
function BU(){C.call(this);this.d5=null;}
|
||||
var Jj=null;var I6=null;var I7=null;function FJ(a){var b=new BU();Gm(b,a);return b;}
|
||||
function Gm(a,b){a.d5=b;}
|
||||
function EC(){Jj=FJ(B(67));I6=FJ(B(68));I7=FJ(B(69));}
|
||||
function BB(){Q.call(this);}
|
||||
function DD(){Bq.call(this);}
|
||||
function Cx(){var a=this;C.call(a);a.dU=null;a.c$=0.0;a.es=0.0;a.bp=null;a.by=null;a.b3=null;a.U=0;}
|
||||
function Fe(a,b){var c;if(b!==null){a.by=b;return a;}c=new X;G(c,B(70));D(c);}
|
||||
function Hi(a,b){return;}
|
||||
function Ff(a,b){var c;if(b!==null){a.b3=b;return a;}c=new X;G(c,B(70));D(c);}
|
||||
function Hr(a,b){return;}
|
||||
function C8(a,b,c,d){var e,f,$$je;if(!(a.U==2&&!d)&&a.U!=3){a.U=d?2:1;while(true){try{e=Fh(a,b,c);}catch($$e){$$je=U($$e);if($$je instanceof P){f=$$je;D(HY(f));}else{throw $$e;}}if(BK(e))return e;if(BV(e)){if(d&&Bg(b)){if(a.by===I7)return Bh(L(b));if(L(c)<=R(a.bp))return Jk;Bf(b,b.p+L(b)|0);if(a.by===I6)Ce(c,a.bp);}return e;}if(Dw(e)){if(a.by===I7)return e;if(a.by===I6){if(L(c)<R(a.bp))return Jk;Ce(c,a.bp);}Bf(b,b.p+Ch(e)|0);}else if(Cv(e)){if(a.b3===I7)break;if(a.b3===I6){if(L(c)<R(a.bp))return Jk;Ce(c,a.bp);}Bf(b,
|
||||
b.p+Ch(e)|0);}}return e;}b=new Bx;H(b);D(b);}
|
||||
function F9(a,b){if(a.U!=3&&a.U!=2){b=new Bx;H(b);D(b);}a.U=3;return Jl;}
|
||||
function FB(a){a.U=0;return a;}
|
||||
function F8(a,b){var c,d;if(a.U&&a.U!=3){b=new Bx;H(b);D(b);}if(!L(b))return F6(0);if(a.U)FB(a);c=F6(BA(8,L(b)*a.c$|0));while(true){d=C8(a,b,c,0);if(BV(d))break;if(BK(d))c=CW(a,c);if(!CO(d))continue;Ej(d);}b=C8(a,b,c,1);if(CO(b))Ej(b);while(!BV(F9(a,c))){c=CW(a,c);}ET(c);return c;}
|
||||
function CW(a,b){var c,d,e;c=b.bz;d=Dr(c,BA(8,c.data.length*2|0));e=Gc(d,0,d.data.length);Bf(e,b.p);return e;}
|
||||
function G6(a,b){return Jl;}
|
||||
function GL(a){return;}
|
||||
function Cb(){Ci.call(this);}
|
||||
function DZ(a){return a.cW;}
|
||||
function FN(){var a=this;Cb.call(a);a.cW=0;a.cB=0;a.bz=null;}
|
||||
function HG(a,b,c,d,e,f){var g=new FN();HW(g,a,b,c,d,e,f);return g;}
|
||||
function HW(a,b,c,d,e,f,g){C4(a,c);a.p=e;a.N=f;a.cB=b;a.cW=g;a.bz=d;}
|
||||
function Fp(a,b){return a.bz.data[b+a.cB|0];}
|
||||
function CS(a,b,c){a.bz.data[b+a.cB|0]=c;}
|
||||
function Hm(a){return 1;}
|
||||
function Ha(a){return a.bz;}
|
||||
function HJ(a){return a.cW;}
|
||||
function B_(){var a=this;C.call(a);a.eb=null;a.cK=null;a.ef=0.0;a.c9=0.0;a.cU=null;a.cX=null;a.bu=0;}
|
||||
function Ek(a,b){var c;if(b!==null){a.cU=b;return a;}c=new X;G(c,B(71));D(c);}
|
||||
function HL(a,b){return;}
|
||||
function FK(a,b){var c;if(b!==null){a.cX=b;return a;}c=new X;G(c,B(71));D(c);}
|
||||
function HC(a,b){return;}
|
||||
function Fz(a,b,c,d){var e,f,g,h,$$je;a:{if(a.bu!=3){if(d)break a;if(a.bu!=2)break a;}b=new Bx;H(b);D(b);}a.bu=!d?1:2;while(true){try{e=Fx(a,b,c);}catch($$e){$$je=U($$e);if($$je instanceof P){f=$$je;D(HY(f));}else{throw $$e;}}if(BV(e)){if(!d)return e;g=L(b);if(g<=0)return e;e=Bh(g);}else if(BK(e))break;h=!Cv(e)?a.cU:a.cX;b:{if(h!==I6){if(h===Jj)break b;else return e;}if(L(c)<a.cK.data.length)return Jk;E6(c,a.cK);}Bf(b,b.p+Ch(e)|0);}return e;}
|
||||
function EM(a,b){var c;if(a.bu!=2&&a.bu!=4){b=new Bx;H(b);D(b);}c=Jl;if(c===Jl)a.bu=3;return c;}
|
||||
function GO(a,b){return Jl;}
|
||||
function Cf(){var a=this;C.call(a);a.br=0;a.cg=0;}
|
||||
var Jl=null;var Jk=null;function FP(a,b){var c=new Cf();Gr(c,a,b);return c;}
|
||||
function Gr(a,b,c){a.br=b;a.cg=c;}
|
||||
function BV(a){return a.br?0:1;}
|
||||
function BK(a){return a.br!=1?0:1;}
|
||||
function CO(a){return !Dw(a)&&!Cv(a)?0:1;}
|
||||
function Dw(a){return a.br!=2?0:1;}
|
||||
function Cv(a){return a.br!=3?0:1;}
|
||||
function Ch(a){var b;if(CO(a))return a.cg;b=new BW;H(b);D(b);}
|
||||
function Bh(b){return FP(2,b);}
|
||||
function Ej(a){var b,c;switch(a.br){case 0:b=new C9;H(b);D(b);case 1:b=new DI;H(b);D(b);case 2:b=new D_;c=a.cg;H(b);b.dw=c;D(b);case 3:b=new C2;c=a.cg;H(b);b.ds=c;D(b);default:}}
|
||||
function EA(){Jl=FP(0,0);Jk=FP(1,0);}
|
||||
function CA(){Cx.call(this);}
|
||||
function Fh(a,b,c){var d,e,f,g,h,i,j,k,l,m;d=$rt_createByteArray(Ba(L(b),512));e=d.data;f=0;g=0;h=$rt_createCharArray(Ba(L(c),512));i=h.data;a:{while(true){if((f+32|0)>g&&Bg(b)){j=f;while(j<g){e[j-f|0]=e[j];j=j+1|0;}k=g-f|0;g=Ba(L(b)+k|0,e.length);Gq(b,d,k,g-k|0);f=0;}if(!Bg(c)){l=!Bg(b)&&f>=g?Jl:Jk;break a;}k=Ba(L(c),i.length);m=new D8;m.c_=b;m.dc=c;l=FS(a,d,f,g,h,0,k,m);f=m.cT;if(l===null&&0==m.ch)l=Jl;Gs(c,h,0,m.ch);if(l!==null)break;}}Bf(b,b.p-(g-f|0)|0);return l;}
|
||||
function Dj(){CA.call(this);}
|
||||
function FS(a,b,c,d,e,f,g,h){var i,j,k,l,m,n,o,p,q;i=null;a:{b:{c:{while(c<d){if(f>=g)break a;j=b.data;k=c+1|0;l=j[c]&255;if(!(l&128)){j=e.data;m=f+1|0;j[f]=l&65535;}else if((l&224)==192){if(k>=d){c=k+(-1)|0;if(Cl(h))break a;i=Jl;break a;}n=k+1|0;k=j[k];if(!Bw(a,k)){c=n+(-2)|0;i=Bh(1);break a;}j=e.data;m=f+1|0;j[f]=((l&31)<<6|k&63)&65535;k=n;}else if((l&240)==224){if((k+2|0)>d){c=k+(-1)|0;if(Cl(h))break a;i=Jl;break a;}c=k+1|0;m=j[k];k=c+1|0;o=j[c];if(!Bw(a,m))break b;if(!Bw(a,o))break b;p=((l&15)<<12|(m&63)
|
||||
<<6|o&63)&65535;if(DJ(p)){c=k+(-3)|0;i=Bh(3);break a;}j=e.data;m=f+1|0;j[f]=p;}else{if((l&248)!=240){c=k+(-1)|0;i=Bh(1);break a;}if((k+3|0)>d){c=k+(-1)|0;if(Cl(h))break a;i=Jl;break a;}if((f+2|0)>g){c=k+(-1)|0;if(FO(h,2))break a;i=Jk;break a;}c=k+1|0;m=j[k];n=c+1|0;o=j[c];k=n+1|0;n=j[n];if(!Bw(a,m))break c;if(!Bw(a,o))break c;if(!Bw(a,n))break c;j=e.data;q=(l&7)<<18|(m&63)<<12|(o&63)<<6|n&63;c=f+1|0;j[f]=Ee(q);m=c+1|0;j[c]=Do(q);}c=k;f=m;}break a;}c=k+(-3)|0;i=Bh(1);break a;}c=k+(-3)|0;i=Bh(1);}h.cT=c;h.ch=
|
||||
f;return i;}
|
||||
function Bw(a,b){return (b&192)!=128?0:1;}
|
||||
function Y(){var a=this;Bc.call(a);a.P=0;a.ea=null;}
|
||||
function FY(a,b){var c=new Y();HZ(c,a,b);return c;}
|
||||
function HZ(a,b,c){a.ea=b;H(a);a.P=c;}
|
||||
function Gz(){var a=this;C.call(a);a.d$=0;a.dK=0;a.dN=Long_ZERO;a.er=0;a.dl=0;a.bL=null;a.dd=null;a.dm=null;a.eG=0;a.ec=Long_ZERO;a.dQ=0;a.ee=Long_ZERO;}
|
||||
function Ii(){var a=new Gz();Ht(a);return a;}
|
||||
function Ht(a){a.d$=0;a.dK=0;a.dl=255;a.dQ=0;a.ee=Long_ZERO;}
|
||||
function Da(){C.call(this);this.bA=0;}
|
||||
var Jm=null;function Hb(){var a=new Da();FH(a);return a;}
|
||||
function FH(a){a.bA=0;}
|
||||
function HV(a,b,c,d){var e,f,g,h;e=a.bA^(-1);while(true){d=d+(-1)|0;if(d<0)break;f=b.data;g=Jm.data;h=c+1|0;e=g[(e^f[c])&255]^e>>>8;c=h;}a.bA=e^(-1);}
|
||||
function Hw(a){a.bA=0;}
|
||||
function GQ(a,b){a.bA=Long_and(b,new Long(4294967295, 0)).lo;}
|
||||
function GS(a){return Long_and(Long_fromInt(a.bA),new Long(4294967295, 0));}
|
||||
function Ey(){var b,c,d;Jm=null;Jm=$rt_createIntArray(256);b=0;while(b<256){c=8;d=b;while(true){c=c+(-1)|0;if(c<0)break;if(!(d&1)){d=d>>>1;continue;}d=(-306674912)^d>>>1;}Jm.data[b]=d;b=b+1|0;}}
|
||||
function CQ(){B_.call(this);}
|
||||
function Fx(a,b,c){var d,e,f,g,h,i,j,k,l,m;d=$rt_createCharArray(Ba(L(b),512));e=d.data;f=0;g=0;h=$rt_createByteArray(Ba(L(c),512));i=h.data;a:{while(true){if((f+32|0)>g&&Bg(b)){j=f;while(j<g){e[j-f|0]=e[j];j=j+1|0;}k=g-f|0;g=Ba(L(b)+k|0,e.length);Dh(b,d,k,g-k|0);f=0;}if(!Bg(c)){l=!Bg(b)&&f>=g?Jl:Jk;break a;}k=Ba(L(c),i.length);m=new Du;m.df=b;m.dv=c;l=Gj(a,d,f,g,h,0,k,m);f=m.cu;if(l===null&&0==m.ce)l=Jl;Dz(c,h,0,m.ce);if(l!==null)break;}}Bf(b,b.p-(g-f|0)|0);return l;}
|
||||
function Eh(){CQ.call(this);}
|
||||
function Gj(a,b,c,d,e,f,g,h){var i,j,k,l,m,n;i=null;a:{while(c<d){if(f>=g){j=c;break a;}k=b.data;j=c+1|0;l=k[c];if(l<128){k=e.data;m=f+1|0;k[f]=l<<24>>24;}else if(l<2048){if((f+2|0)>g){j=j+(-1)|0;if(Cd(h,2))break a;i=Jk;break a;}k=e.data;c=f+1|0;k[f]=(192|l>>6)<<24>>24;m=c+1|0;k[c]=(128|l&63)<<24>>24;}else if(!DJ(l)){if((f+3|0)>g){j=j+(-1)|0;if(Cd(h,3))break a;i=Jk;break a;}k=e.data;n=f+1|0;k[f]=(224|l>>12)<<24>>24;c=n+1|0;k[n]=(128|l>>6&63)<<24>>24;m=c+1|0;k[c]=(128|l&63)<<24>>24;}else{if(!Cs(l)){i=Bh(1);break a;}if
|
||||
(j>=d){if(Ez(h))break a;i=Jl;break a;}c=j+1|0;j=k[j];if(!Co(j)){j=c+(-2)|0;i=Bh(1);break a;}if((f+4|0)>g){j=c+(-2)|0;if(Cd(h,4))break a;i=Jk;break a;}k=e.data;n=Ds(l,j);j=f+1|0;k[f]=(240|n>>18)<<24>>24;f=j+1|0;k[j]=(128|n>>12&63)<<24>>24;j=f+1|0;k[f]=(128|n>>6&63)<<24>>24;m=j+1|0;k[j]=(128|n&63)<<24>>24;j=c;}c=j;f=m;}j=c;}h.cu=j;h.ce=f;return i;}
|
||||
function F_(){var a=this;Bp.call(a);a.bh=null;a.ci=0;}
|
||||
function GY(){var a=new F_();HS(a);return a;}
|
||||
function HS(a){a.bh=$rt_createByteArray(32);}
|
||||
function Dv(a,b,c,d){var e,f,g,h,i;e=a.ci+d|0;if(a.bh.data.length<e){f=BA(e,(a.bh.data.length*3|0)/2|0);a.bh=Fr(a.bh,f);}e=0;while(e<d){g=b.data;h=a.bh.data;f=a.ci;a.ci=f+1|0;i=c+1|0;h[f]=g[c];e=e+1|0;c=i;}}
|
||||
function Cg(a){return Fr(a.bh,a.ci);}
|
||||
function E5(){C.call(this);}
|
||||
function F3(b){if (b === null || b.constructor.$meta.item === undefined) {$rt_throw(Jn());}return b.data.length;}
|
||||
function BZ(){P.call(this);}
|
||||
function Bx(){Bc.call(this);}
|
||||
function FD(){Bq.call(this);}
|
||||
function HY(a){var b=new FD();G0(b,a);return b;}
|
||||
function G0(a,b){a.cf=1;a.co=1;a.bY=b;}
|
||||
function CC(){BR.call(this);}
|
||||
var Jo=0.0;var Jp=null;function FT(){Jo=NaN;Jp=Bt($rt_floatcls());}
|
||||
function Bz(){C.call(this);}
|
||||
var IM=null;var Jq=null;var Jr=null;var Js=null;var IL=null;function F2(){var b,c;b=$rt_createIntArray(10);c=b.data;c[0]=1;c[1]=10;c[2]=100;c[3]=1000;c[4]=10000;c[5]=100000;c[6]=1000000;c[7]=10000000;c[8]=100000000;c[9]=1000000000;IM=b;b=$rt_createLongArray(19);c=b.data;c[0]=Long_fromInt(1);c[1]=Long_fromInt(10);c[2]=Long_fromInt(100);c[3]=Long_fromInt(1000);c[4]=Long_fromInt(10000);c[5]=Long_fromInt(100000);c[6]=Long_fromInt(1000000);c[7]=Long_fromInt(10000000);c[8]=Long_fromInt(100000000);c[9]=Long_fromInt(1000000000);c[10]
|
||||
=new Long(1410065408, 2);c[11]=new Long(1215752192, 23);c[12]=new Long(3567587328, 232);c[13]=new Long(1316134912, 2328);c[14]=new Long(276447232, 23283);c[15]=new Long(2764472320, 232830);c[16]=new Long(1874919424, 2328306);c[17]=new Long(1569325056, 23283064);c[18]=new Long(2808348672, 232830643);Jq=b;b=$rt_createLongArray(6);c=b.data;c[0]=Long_fromInt(1);c[1]=Long_fromInt(10);c[2]=Long_fromInt(100);c[3]=Long_fromInt(10000);c[4]=Long_fromInt(100000000);c[5]=new Long(1874919424, 2328306);Jr=b;Js=new DE;IL=
|
||||
new CR;}
|
||||
function Cc(){C.call(this);}
|
||||
var Jt=null;var Ju=null;function EW(b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q;d=$rt_floatToIntBits(b);c.du=!(d&(-2147483648))?0:1;e=d&8388607;f=d>>23&255;if(!e&&!f){c.cF=0;c.c7=0;return;}g=0;if(f)e=e|8388608;else{e=e<<1;while(Long_eq(Long_and(Long_fromInt(e),Long_fromInt(8388608)),Long_ZERO)){e=e<<1;f=f+(-1)|0;g=g+1|0;}}h=Ju.data;i=0;j=h.length;if(i>j){c=new X;H(c);D(c);}j=j-1|0;a:{while(true){k=(i+j|0)/2|0;l=h[k];if(l==f)break;if(f>=l){i=k+1|0;if(i>j){k= -k-2|0;break a;}}else{j=k-1|0;if(j<i){k= -k-1|0;break a;}}}}if
|
||||
(k<0)k= -k-2|0;m=9+(f-Ju.data[k]|0)|0;n=Long_fromInt(e);i=Long_shru(Long_mul(n,Long_fromInt(Jt.data[k])),32-m|0).lo;if(i>=1000000000){k=k+1|0;m=9+(f-Ju.data[k]|0)|0;i=Long_shru(Long_mul(n,Long_fromInt(Jt.data[k])),32-m|0).lo;}f=(31-m|0)-g|0;j=f>=0?Jt.data[k]>>>f:Jt.data[k]<< -f;l=(j+1|0)>>1;o=j>>1;if(e==4194304)o=o>>2;p=10;while(p<=o){p=p*10|0;}if((i%p|0)>=(o/2|0))p=p/10|0;q=10;while(q<=l){q=q*10|0;}if((q-(i%q|0)|0)>(l/2|0))q=q/10|0;e=C6(p,q);e=e>0?Dm(i/p|0,p):e<0?Dm(i/q|0,q)+q|0:Dm((i+(q/2|0)|0)/q|0,q);if(e
|
||||
>=1000000000){k=k+1|0;e=e/10|0;}else if(e<100000000){k=k+(-1)|0;e=e*10|0;}c.cF=e;c.c7=k-50|0;}
|
||||
function ER(){var b,c,d,e,f,g,h,i;Jt=$rt_createIntArray(100);Ju=$rt_createIntArray(100);b=2000000000;c=127;d=0;e=b;while(d<50){f=Jt.data;g=d+50|0;f[g]=$rt_udiv(e,20);Ju.data[g]=c;g=$rt_udiv(e,10);h=$rt_umod(g,10);while(g<=b&&!(g&(-2147483648))){g=g<<1;c=c+1|0;h=h<<1;}e=g+(h/10|0)|0;d=d+1|0;}c=127;d=0;while(d<50){i=0;h=b;while(h>214748364){h=h>>1;i=i+1|0;c=c+(-1)|0;}h=h*10|0;b=i<=0?h:Long_add(Long_fromInt(h),Long_shr(Long_mul(Long_fromInt(b&((1<<i)-1|0)),Long_fromInt(10)),i)).lo;f=Jt.data;i=(50-d|0)-1|0;f[i]
|
||||
=$rt_udiv(b,20);Ju.data[i]=c;d=d+1|0;}}
|
||||
function CR(){var a=this;C.call(a);a.cF=0;a.c7=0;a.du=0;}
|
||||
function DE(){C.call(this);}
|
||||
function BW(){P.call(this);}
|
||||
function Du(){var a=this;C.call(a);a.df=null;a.dv=null;a.cu=0;a.ce=0;}
|
||||
function Ez(a){return Bg(a.df);}
|
||||
function Cd(a,b){return L(a.dv)<b?0:1;}
|
||||
function G_(a,b){a.cu=b;}
|
||||
function H4(a,b){a.ce=b;}
|
||||
function C9(){P.call(this);}
|
||||
function DI(){P.call(this);}
|
||||
function D_(){BB.call(this);this.dw=0;}
|
||||
function GZ(a){return M(J(F(N(),B(72)),a.dw));}
|
||||
function C2(){BB.call(this);this.ds=0;}
|
||||
function H3(a){return M(J(F(N(),B(73)),a.ds));}
|
||||
function Cm(){P.call(this);}
|
||||
function D8(){var a=this;C.call(a);a.c_=null;a.dc=null;a.cT=0;a.ch=0;}
|
||||
function Cl(a){return Bg(a.c_);}
|
||||
function FO(a,b){return L(a.dc)<b?0:1;}
|
||||
function Hg(a,b){a.cT=b;}
|
||||
function HR(a,b){a.ch=b;}
|
||||
function B$(){BW.call(this);}
|
||||
function B0(){P.call(this);}
|
||||
$rt_packages([-1,"com",0,"jcraft",1,"jzlib",-1,"java",3,"nio",4,"charset",3,"io",3,"lang"]);
|
||||
$rt_metadata([C,"Object",7,0,[],0,3,0,0,V,0,C,[],0,3,0,0,Db,0,C,[],3,3,0,0,De,0,C,[Db],0,3,0,0,Gi,0,C,[],4,0,0,0,F1,0,C,[],4,3,0,0,BG,0,C,[],3,3,0,0,Bk,0,C,[],3,3,0,0,B3,0,C,[],3,3,0,0,Br,0,C,[BG,Bk,B3],0,3,0,0,BP,0,C,[],0,3,0,["b8",function(){return H1(this);}],Bq,0,BP,[],0,3,0,0,BS,0,Bq,[],0,3,0,0,FF,0,BS,[],0,3,0,0,Ct,0,C,[BG,B3],0,0,0,0,Cy,0,C,[],3,3,0,0,EE,0,Ct,[Cy],0,3,0,0,BR,0,C,[BG],1,3,0,0,C0,0,BR,[Bk],0,3,0,0,BI,0,BS,[],0,3,0,0,Fs,0,BI,[],0,3,0,0,Fa,0,BI,[],0,3,0,0,Bc,0,BP,[],0,3,0,0,P,0,Bc,[],0,3,
|
||||
0,0,Be,0,C,[],3,3,0,0,Bv,0,C,[Be],3,3,0,0,Ed,0,C,[Bv],3,3,0,0,DO,0,C,[Bv],3,3,0,0,DG,0,C,[Bv],3,3,0,0,Dl,0,C,[Bv],3,3,0,0,DU,0,C,[Bv,Ed,DO,DG,Dl],3,3,0,0,DR,0,C,[],3,3,0,0,DX,0,C,[Be],3,3,0,0,Fc,0,C,[Be,DU,DR,DX],1,3,0,["gw",function(b,c){return GF(this,b,c);},"gb",function(b,c){return GR(this,b,c);},"eW",function(b){return Hl(this,b);},"e4",function(b,c,d){return Hs(this,b,c,d);},"fI",function(b){return Hu(this,b);},"fU",function(){return HM(this);},"gz",function(b,c,d){return GU(this,b,c,d);}],Gy,0,C,[],4,
|
||||
3,0,0,EO,0,C,[Be],1,3,0,0,W,0,C,[],0,3,H_,0,CI,0,W,[],0,3,0,0,Gg,0,CI,[],0,3,0,0,D3,0,C,[],0,3,0,0,Q,"IOException",6,Bc,[],0,3,0,0,DQ,0,C,[],3,3,0,0,DA,0,C,[DQ],0,3,0,0,B6,0,C,[Bk],0,3,0,0,DP,0,C,[],3,3,0,0,DB,0,C,[DP],0,0,0,["d0",function(b){Ge(this,b);},"em",function(b){HK(this,b);}],E1,0,C,[Be],1,3,0,0,D2,0,C,[Be],3,3,0,0,CY,0,C,[D2],4,0,0,["gY",function(){return G2(this);}],D0,0,C,[],3,3,0,0]);
|
||||
$rt_metadata([Cn,0,C,[D0],3,3,0,0,BN,0,C,[Cn],1,3,0,0,CX,0,BN,[],0,3,0,["bX",function(b,c,d){return HI(this,b,c,d);},"c5",function(){return GT(this);}],BL,0,BN,[],0,3,0,0,DM,0,C,[],3,3,0,0,C7,0,BL,[DM],0,3,0,0,Ck,0,C,[Bk],1,3,0,0,Di,0,BL,[],0,3,0,["bX",function(b,c,d){return Hj(this,b,c,d);},"c5",function(){return H2(this);}],CP,0,C,[],1,3,0,0,C$,0,CP,[],0,3,0,0,Fv,0,C,[],0,3,0,0,C1,0,C,[],3,3,0,0,CH,0,C,[C1],1,3,0,0,BT,0,C,[],3,3,0,0,F7,0,CH,[BT,BG],0,3,0,0,Dy,0,C,[],0,0,0,0,X,"IllegalArgumentException",7,
|
||||
P,[],0,3,0,0,DK,0,X,[],0,3,0,0,EU,0,C,[Be],1,3,0,0,Bn,0,C,[Be],1,3,0,0,FG,0,Bn,[],1,3,0,0,Et,0,Bn,[],1,3,0,0,Go,0,Bn,[],1,3,0,0,Gx,0,X,[],0,3,0,0,Cj,0,C,[],128,3,0,0,D7,0,Cj,[],4,3,0,0,Gn,0,Ck,[],0,3,0,0,BJ,0,C,[],1,3,0,0,CJ,0,BJ,[Bk],1,3,0,0,Dx,0,CJ,[],0,0,0,0,Eg,0,C,[],3,3,0,0,Ci,0,BJ,[Bk,Cy,B3,Eg],1,3,0,0,C_,"GZIPException",2,Q,[],0,3,0,0,CK,0,C,[],3,0,0,0,Fg,0,C,[CK],4,3,0,["dy",function(b){GN(this,b);},"cl",function(){Hz(this);},"cY",function(){return Hy(this);},"bn",function(b,c,d){He(this,b,c,d);}],BD,
|
||||
0,P,[],0,3,0,0,CV,0,Bc,[],0,3,0,0,Cz,0,C,[],4,3,0,0,CU,0,C,[],3,3,0,0,CG,0,C,[CU,BT],0,0,0,0,BE,0,CG,[],0,0,0,0,O,"IndexOutOfBoundsException",7,P,[],0,3,0,0,CD,"StringIndexOutOfBoundsException",7,O,[],0,3,0,0,DH,0,C,[],4,3,0,0,BM,"EOFException",6,Q,[],0,3,0,0,CE,0,C,[],4,0,0,0,DT,0,C,[],3,3,0,0,Bp,0,C,[Cn,DT],1,3,0,0,Cp,0,Bp,[],0,3,0,0,Df,0,Cp,[],0,3,0,0]);
|
||||
$rt_metadata([Ea,0,Bp,[],0,0,0,0,FL,0,C,[],4,3,0,0,BX,0,C,[],4,0,0,0,Bj,0,C,[],4,0,0,0,Cu,0,C,[],4,0,0,0,BC,"UTFDataFormatException",6,Q,[],0,3,0,0,BU,0,C,[],0,3,0,0,BB,0,Q,[],0,3,0,0,DD,0,Bq,[],0,3,0,0,Cx,0,C,[],1,3,0,0,Cb,0,Ci,[],1,0,0,0,FN,0,Cb,[],0,0,0,0,B_,0,C,[],1,3,0,0,Cf,0,C,[],0,3,0,0,CA,0,Cx,[],1,3,0,0,Dj,0,CA,[],0,3,0,0,Y,0,Bc,[],0,0,0,0,Gz,0,C,[BT],0,3,0,0,Da,0,C,[CK],4,3,0,["bn",function(b,c,d){HV(this,b,c,d);},"cl",function(){Hw(this);},"dy",function(b){GQ(this,b);},"cY",function(){return GS(this);
|
||||
}],CQ,0,B_,[],1,3,0,0,Eh,0,CQ,[],0,3,0,0,F_,0,Bp,[],0,3,0,0,E5,0,C,[],4,3,0,0,BZ,0,P,[],0,3,0,0,Bx,0,Bc,[],0,3,0,0,FD,0,Bq,[],0,3,0,0,CC,0,BR,[Bk],0,3,0,0,Bz,0,C,[],0,0,0,0,Cc,0,C,[],4,3,0,0,CR,0,C,[],0,3,0,0,DE,0,C,[],0,3,0,0,BW,0,P,[],0,3,0,0,Du,0,C,[],0,3,0,0,C9,0,P,[],0,3,0,0,DI,0,P,[],0,3,0,0,D_,"MalformedInputException",5,BB,[],0,3,0,["b8",function(){return GZ(this);}],C2,"UnmappableCharacterException",5,BB,[],0,3,0,["b8",function(){return H3(this);}],Cm,"BufferUnderflowException",4,P,[],0,3,0,0,D8,0,
|
||||
C,[],0,3,0,0,B$,"ReadOnlyBufferException",4,BW,[],0,3,0,0,B0,"BufferOverflowException",4,P,[],0,3,0,0]);
|
||||
function $rt_array(cls,data){this.hP=null;this.$id$=0;this.type=cls;this.data=data;this.constructor=$rt_arraycls(cls);}$rt_array.prototype=Object.create(($rt_objcls()).prototype);$rt_array.prototype.toString=function(){var str="[";for(var i=0;i<this.data.length;++i){if(i>0){str+=", ";}str+=this.data[i].toString();}str+="]";return str;};$rt_setCloneMethod($rt_array.prototype,function(){var dataCopy;if('slice' in this.data){dataCopy=this.data.slice();}else {dataCopy=new this.data.constructor(this.data.length);for
|
||||
(var i=0;i<dataCopy.length;++i){dataCopy[i]=this.data[i];}}return new $rt_array(this.type,dataCopy);});$rt_stringPool(["@","0","","overflow-x:hidden;overflow-y:hidden;","WebGL 2.0 is not supported in your browser, please get a new one!",": "," at ","Caused by: ","null","Index out of bounds","UTF-8","EAGPKG!!","invalid epk file","<file>"," end","invalid file hash for ","</file>","yee","End of stream reached","Malformed UTF-8 sequence","Should never been thrown","Stream closed","footer is not found","Unexpected end of ZLIB input stream",
|
||||
"<22>","Replacement preconditions do not hold","New position "," is outside of range [0;","]","The last byte in dst "," is outside of array of size ","Length "," must be non-negative","Offset ",")","The last byte in src ","Capacity is negative: ","The last char in dst ","The last char in src "," is outside of string of size ","Start "," must be before end ","BIG_ENDIAN","LITTLE_ENDIAN","Either src or dest is null","need dictionary","unknown compression method","unknown header flags set","incorrect data check",
|
||||
"incorrect length check","incorrect header check","invalid window size","bad extra field length","header crc mismatch","invalid stored block lengths","invalid block type","too many length or distance symbols","invalid bit length repeat","oversubscribed dynamic bit lengths tree","incomplete dynamic bit lengths tree","oversubscribed distance tree","incomplete distance tree","empty distance tree with lengths","oversubscribed literal/length tree","incomplete literal/length tree","invalid distance code","invalid literal/length code",
|
||||
"IGNORE","REPLACE","REPORT","newAction must be non-null","Action must be non-null","Malformed input of length ","Unmappable characters of length "]);
|
||||
Br.prototype.toString=function(){return $rt_ustr(this);};
|
||||
Br.prototype.valueOf=Br.prototype.toString;C.prototype.toString=function(){return $rt_ustr(HF(this));};
|
||||
C.prototype.__teavm_class__=function(){return $dbg_class(this);};
|
||||
function Long_eq(a,b){return a.hi===b.hi&&a.lo===b.lo;}function Long_ne(a,b){return a.hi!==b.hi||a.lo!==b.lo;}function Long_gt(a,b){if(a.hi<b.hi){return false;}if(a.hi>b.hi){return true;}var x=a.lo>>>1;var y=b.lo>>>1;if(x!==y){return x>y;}return (a.lo&1)>(b.lo&1);}function Long_ge(a,b){if(a.hi<b.hi){return false;}if(a.hi>b.hi){return true;}var x=a.lo>>>1;var y=b.lo>>>1;if(x!==y){return x>=y;}return (a.lo&1)>=(b.lo&1);}function Long_lt(a,b){if(a.hi>b.hi){return false;}if(a.hi<b.hi){return true;}var x=a.lo>>>
|
||||
1;var y=b.lo>>>1;if(x!==y){return x<y;}return (a.lo&1)<(b.lo&1);}function Long_le(a,b){if(a.hi>b.hi){return false;}if(a.hi<b.hi){return true;}var x=a.lo>>>1;var y=b.lo>>>1;if(x!==y){return x<=y;}return (a.lo&1)<=(b.lo&1);}function Long_add(a,b){if(a.hi===a.lo>>31&&b.hi===b.lo>>31){return Long_fromNumber(a.lo+b.lo);}else if(Math.abs(a.hi)<Long_MAX_NORMAL&&Math.abs(b.hi)<Long_MAX_NORMAL){return Long_fromNumber(Long_toNumber(a)+Long_toNumber(b));}var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi
|
||||
=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;var lolo=a_lolo+b_lolo|0;var lohi=a_lohi+b_lohi+(lolo>>16)|0;var hilo=a_hilo+b_hilo+(lohi>>16)|0;var hihi=a_hihi+b_hihi+(hilo>>16)|0;return new Long(lolo&0xFFFF|(lohi&0xFFFF)<<16,hilo&0xFFFF|(hihi&0xFFFF)<<16);}function Long_inc(a){var lo=a.lo+1|0;var hi=a.hi;if(lo===0){hi=hi+1|0;}return new Long(lo,hi);}function Long_dec(a){var lo=a.lo -1|0;var hi=a.hi;if(lo=== -1){hi=hi -1|0;}return new Long(lo,hi);}function Long_neg(a)
|
||||
{return Long_inc(new Long(a.lo^0xFFFFFFFF,a.hi^0xFFFFFFFF));}function Long_sub(a,b){if(a.hi===a.lo>>31&&b.hi===b.lo>>31){return Long_fromNumber(a.lo -b.lo);}var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;var lolo=a_lolo -b_lolo|0;var lohi=a_lohi -b_lohi+(lolo>>16)|0;var hilo=a_hilo -b_hilo+(lohi>>16)|0;var hihi=a_hihi -b_hihi+(hilo>>16)|0;return new Long(lolo&0xFFFF|(lohi&0xFFFF)<<
|
||||
16,hilo&0xFFFF|(hihi&0xFFFF)<<16);}function Long_compare(a,b){var r=a.hi -b.hi;if(r!==0){return r;}r=(a.lo>>>1) -(b.lo>>>1);if(r!==0){return r;}return (a.lo&1) -(b.lo&1);}function Long_isPositive(a){return (a.hi&0x80000000)===0;}function Long_isNegative(a){return (a.hi&0x80000000)!==0;}function Long_mul(a,b){var positive=Long_isNegative(a)===Long_isNegative(b);if(Long_isNegative(a)){a=Long_neg(a);}if(Long_isNegative(b)){b=Long_neg(b);}var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi
|
||||
=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;var lolo=0;var lohi=0;var hilo=0;var hihi=0;lolo=a_lolo*b_lolo|0;lohi=lolo>>>16;lohi=(lohi&0xFFFF)+a_lohi*b_lolo|0;hilo=hilo+(lohi>>>16)|0;lohi=(lohi&0xFFFF)+a_lolo*b_lohi|0;hilo=hilo+(lohi>>>16)|0;hihi=hilo>>>16;hilo=(hilo&0xFFFF)+a_hilo*b_lolo|0;hihi=hihi+(hilo>>>16)|0;hilo=(hilo&0xFFFF)+a_lohi*b_lohi|0;hihi=hihi+(hilo>>>16)|0;hilo=(hilo&0xFFFF)+a_lolo*b_hilo|0;hihi=hihi+(hilo>>>16)|0;hihi=hihi+a_hihi*b_lolo
|
||||
+a_hilo*b_lohi+a_lohi*b_hilo+a_lolo*b_hihi|0;var result=new Long(lolo&0xFFFF|lohi<<16,hilo&0xFFFF|hihi<<16);return positive?result:Long_neg(result);}function Long_div(a,b){if(Math.abs(a.hi)<Long_MAX_NORMAL&&Math.abs(b.hi)<Long_MAX_NORMAL){return Long_fromNumber(Long_toNumber(a)/Long_toNumber(b));}return (Long_divRem(a,b))[0];}function Long_udiv(a,b){if(a.hi>=0&&a.hi<Long_MAX_NORMAL&&b.hi>=0&&b.hi<Long_MAX_NORMAL){return Long_fromNumber(Long_toNumber(a)/Long_toNumber(b));}return (Long_udivRem(a,b))[0];}function Long_rem(a,
|
||||
b){if(Math.abs(a.hi)<Long_MAX_NORMAL&&Math.abs(b.hi)<Long_MAX_NORMAL){return Long_fromNumber(Long_toNumber(a)%Long_toNumber(b));}return (Long_divRem(a,b))[1];}function Long_urem(a,b){if(a.hi>=0&&a.hi<Long_MAX_NORMAL&&b.hi>=0&&b.hi<Long_MAX_NORMAL){return Long_fromNumber(Long_toNumber(a)/Long_toNumber(b));}return (Long_udivRem(a,b))[1];}function Long_divRem(a,b){if(b.lo===0&&b.hi===0){throw new Error("Division by zero");}var positive=Long_isNegative(a)===Long_isNegative(b);if(Long_isNegative(a)){a=Long_neg(a);}if
|
||||
(Long_isNegative(b)){b=Long_neg(b);}a=new LongInt(a.lo,a.hi,0);b=new LongInt(b.lo,b.hi,0);var q=LongInt_div(a,b);a=new Long(a.lo,a.hi);q=new Long(q.lo,q.hi);return positive?[q,a]:[Long_neg(q),Long_neg(a)];}function Long_udivRem(a,b){if(b.lo===0&&b.hi===0){throw new Error("Division by zero");}a=new LongInt(a.lo,a.hi,0);b=new LongInt(b.lo,b.hi,0);var q=LongInt_div(a,b);a=new Long(a.lo,a.hi);q=new Long(q.lo,q.hi);return [q,a];}function Long_shiftLeft16(a){return new Long(a.lo<<16,a.lo>>>16|a.hi<<16);}function Long_shiftRight16(a)
|
||||
{return new Long(a.lo>>>16|a.hi<<16,a.hi>>>16);}function Long_and(a,b){return new Long(a.lo&b.lo,a.hi&b.hi);}function Long_or(a,b){return new Long(a.lo|b.lo,a.hi|b.hi);}function Long_xor(a,b){return new Long(a.lo^b.lo,a.hi^b.hi);}function Long_shl(a,b){b&=63;if(b===0){return a;}else if(b<32){return new Long(a.lo<<b,a.lo>>>32 -b|a.hi<<b);}else if(b===32){return new Long(0,a.lo);}else {return new Long(0,a.lo<<b -32);}}function Long_shr(a,b){b&=63;if(b===0){return a;}else if(b<32){return new Long(a.lo>>>b|a.hi
|
||||
<<32 -b,a.hi>>b);}else if(b===32){return new Long(a.hi,a.hi>>31);}else {return new Long(a.hi>>b -32,a.hi>>31);}}function Long_shru(a,b){b&=63;if(b===0){return a;}else if(b<32){return new Long(a.lo>>>b|a.hi<<32 -b,a.hi>>>b);}else if(b===32){return new Long(a.hi,0);}else {return new Long(a.hi>>>b -32,0);}}function LongInt(lo,hi,sup){this.lo=lo;this.hi=hi;this.sup=sup;}function LongInt_mul(a,b){var a_lolo=(a.lo&0xFFFF)*b|0;var a_lohi=(a.lo>>>16)*b|0;var a_hilo=(a.hi&0xFFFF)*b|0;var a_hihi=(a.hi>>>16)*b|0;var sup
|
||||
=a.sup*b|0;a_lohi=a_lohi+(a_lolo>>>16)|0;a_hilo=a_hilo+(a_lohi>>>16)|0;a_hihi=a_hihi+(a_hilo>>>16)|0;sup=sup+(a_hihi>>>16)|0;a.lo=a_lolo&0xFFFF|a_lohi<<16;a.hi=a_hilo&0xFFFF|a_hihi<<16;a.sup=sup&0xFFFF;}function LongInt_sub(a,b){var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;a_lolo=a_lolo -b_lolo|0;a_lohi=a_lohi -b_lohi+(a_lolo>>16)|0;a_hilo=a_hilo -b_hilo+(a_lohi>>16)|0;a_hihi=a_hihi -
|
||||
b_hihi+(a_hilo>>16)|0;var sup=a.sup -b.sup+(a_hihi>>16)|0;a.lo=a_lolo&0xFFFF|a_lohi<<16;a.hi=a_hilo&0xFFFF|a_hihi<<16;a.sup=sup;}function LongInt_add(a,b){var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;a_lolo=a_lolo+b_lolo|0;a_lohi=a_lohi+b_lohi+(a_lolo>>16)|0;a_hilo=a_hilo+b_hilo+(a_lohi>>16)|0;a_hihi=a_hihi+b_hihi+(a_hilo>>16)|0;var sup=a.sup+b.sup+(a_hihi>>16)|0;a.lo=a_lolo&0xFFFF
|
||||
|a_lohi<<16;a.hi=a_hilo&0xFFFF|a_hihi<<16;a.sup=sup;}function LongInt_inc(a){a.lo=a.lo+1|0;if(a.lo===0){a.hi=a.hi+1|0;if(a.hi===0){a.sup=a.sup+1&0xFFFF;}}}function LongInt_dec(a){a.lo=a.lo -1|0;if(a.lo=== -1){a.hi=a.hi -1|0;if(a.hi=== -1){a.sup=a.sup -1&0xFFFF;}}}function LongInt_ucompare(a,b){var r=a.sup -b.sup;if(r!==0){return r;}r=(a.hi>>>1) -(b.hi>>>1);if(r!==0){return r;}r=(a.hi&1) -(b.hi&1);if(r!==0){return r;}r=(a.lo>>>1) -(b.lo>>>1);if(r!==0){return r;}return (a.lo&1) -(b.lo&1);}function LongInt_numOfLeadingZeroBits(a)
|
||||
{var n=0;var d=16;while(d>0){if(a>>>d!==0){a>>>=d;n=n+d|0;}d=d/2|0;}return 31 -n;}function LongInt_shl(a,b){if(b===0){return;}if(b<32){a.sup=(a.hi>>>32 -b|a.sup<<b)&0xFFFF;a.hi=a.lo>>>32 -b|a.hi<<b;a.lo<<=b;}else if(b===32){a.sup=a.hi&0xFFFF;a.hi=a.lo;a.lo=0;}else if(b<64){a.sup=(a.lo>>>64 -b|a.hi<<b -32)&0xFFFF;a.hi=a.lo<<b;a.lo=0;}else if(b===64){a.sup=a.lo&0xFFFF;a.hi=0;a.lo=0;}else {a.sup=a.lo<<b -64&0xFFFF;a.hi=0;a.lo=0;}}function LongInt_shr(a,b){if(b===0){return;}if(b===32){a.lo=a.hi;a.hi=a.sup;a.sup
|
||||
=0;}else if(b<32){a.lo=a.lo>>>b|a.hi<<32 -b;a.hi=a.hi>>>b|a.sup<<32 -b;a.sup>>>=b;}else if(b===64){a.lo=a.sup;a.hi=0;a.sup=0;}else if(b<64){a.lo=a.hi>>>b -32|a.sup<<64 -b;a.hi=a.sup>>>b -32;a.sup=0;}else {a.lo=a.sup>>>b -64;a.hi=0;a.sup=0;}}function LongInt_copy(a){return new LongInt(a.lo,a.hi,a.sup);}function LongInt_div(a,b){var bits=b.hi!==0?LongInt_numOfLeadingZeroBits(b.hi):LongInt_numOfLeadingZeroBits(b.lo)+32;var sz=1+(bits/16|0);var dividentBits=bits%16;LongInt_shl(b,bits);LongInt_shl(a,dividentBits);var q
|
||||
=new LongInt(0,0,0);while(sz-->0){LongInt_shl(q,16);var digitA=(a.hi>>>16)+0x10000*a.sup;var digitB=b.hi>>>16;var digit=digitA/digitB|0;var t=LongInt_copy(b);LongInt_mul(t,digit);if(LongInt_ucompare(t,a)>=0){while(LongInt_ucompare(t,a)>0){LongInt_sub(t,b); --digit;}}else {while(true){var nextT=LongInt_copy(t);LongInt_add(nextT,b);if(LongInt_ucompare(nextT,a)>0){break;}t=nextT;++digit;}}LongInt_sub(a,t);q.lo|=digit;LongInt_shl(a,16);}LongInt_shr(a,bits+16);return q;}function TeaVMThread(runner){this.status=3;this.stack
|
||||
=[];this.suspendCallback=null;this.runner=runner;this.attribute=null;this.completeCallback=null;}TeaVMThread.prototype.push=function(){for(var i=0;i<arguments.length;++i){this.stack.push(arguments[i]);}return this;};TeaVMThread.prototype.s=TeaVMThread.prototype.push;TeaVMThread.prototype.pop=function(){return this.stack.pop();};TeaVMThread.prototype.l=TeaVMThread.prototype.pop;TeaVMThread.prototype.isResuming=function(){return this.status===2;};TeaVMThread.prototype.isSuspending=function(){return this.status
|
||||
===1;};TeaVMThread.prototype.suspend=function(callback){this.suspendCallback=callback;this.status=1;};TeaVMThread.prototype.start=function(callback){if(this.status!==3){throw new Error("Thread already started");}if($rt_currentNativeThread!==null){throw new Error("Another thread is running");}this.status=0;this.completeCallback=callback?callback:function(result){if(result instanceof Error){throw result;}};this.run();};TeaVMThread.prototype.resume=function(){if($rt_currentNativeThread!==null){throw new Error("Another thread is running");}this.status
|
||||
=2;this.run();};TeaVMThread.prototype.run=function(){$rt_currentNativeThread=this;var result;try {result=this.runner();}catch(e){result=e;}finally {$rt_currentNativeThread=null;}if(this.suspendCallback!==null){var self=this;var callback=this.suspendCallback;this.suspendCallback=null;callback(function(){self.resume();});}else if(this.status===0){this.completeCallback(result);}};function $rt_suspending(){var thread=$rt_nativeThread();return thread!=null&&thread.isSuspending();}function $rt_resuming(){var thread
|
||||
=$rt_nativeThread();return thread!=null&&thread.isResuming();}function $rt_suspend(callback){var nativeThread=$rt_nativeThread();if(nativeThread===null){throw new Error("Suspension point reached from non-threading context (perhaps, from native JS method).");}return nativeThread.suspend(callback);}function $rt_startThread(runner,callback){(new TeaVMThread(runner)).start(callback);}var $rt_currentNativeThread=null;function $rt_nativeThread(){return $rt_currentNativeThread;}function $rt_invalidPointer(){throw new Error("Invalid recorded state");}main
|
||||
=$rt_mainStarter(Ft);
|
||||
(function(){var c;c=Fc.prototype;c.dispatchEvent=c.fI;c.addEventListener=c.gw;c.removeEventListener=c.gb;c.getLength=c.fU;c.get=c.eW;c.addEventListener=c.gz;c.removeEventListener=c.e4;c=CY.prototype;c.stateChanged=c.gY;})();
|
||||
})();
|
||||
|
||||
//# sourceMappingURL=app.js.map
|
1
js/app.js.map
Normal file
1
js/app.js.map
Normal file
File diff suppressed because one or more lines are too long
BIN
js/background.jpg
Normal file
BIN
js/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 143 KiB |
20
js/index.html
Normal file
20
js/index.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Main page</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
<script type="text/javascript" charset="utf-8" src="app.js"></script>
|
||||
<script type = text/javascript>
|
||||
if(document.location.href.startsWith("file:")) {
|
||||
alert("Offline Download is not yet supported, please upload all the game files to a HTTP(s) server");
|
||||
} else {
|
||||
window.addEventListener("load", function() {
|
||||
window.classicConfig = ["game_frame","resources.epk"];
|
||||
main();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body style="margin:0px;width:100vw;height:100vh;" id="game_frame">
|
||||
</body>
|
||||
</html>
|
10
settings.gradle
Normal file
10
settings.gradle
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/7.4.2/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = 'Minecraft-Classic-Browser'
|
397
src/main/java/net/PeytonPlayz585/glemu/FixedFunctionShader.java
Normal file
397
src/main/java/net/PeytonPlayz585/glemu/FixedFunctionShader.java
Normal file
|
@ -0,0 +1,397 @@
|
|||
package net.PeytonPlayz585.glemu;
|
||||
|
||||
import static net.PeytonPlayz585.minecraft.GlStateManager.*;
|
||||
|
||||
import net.PeytonPlayz585.glemu.vector.*;
|
||||
|
||||
public class FixedFunctionShader {
|
||||
|
||||
private static final FixedFunctionShader[] instances = new FixedFunctionShader[128];
|
||||
|
||||
public static void refreshCoreGL() {
|
||||
for (int i = 0; i < instances.length; ++i) {
|
||||
if (instances[i] != null) {
|
||||
_wglDeleteProgram(instances[i].globject);
|
||||
instances[i] = null;
|
||||
}
|
||||
}
|
||||
shaderSource = null;
|
||||
}
|
||||
|
||||
public static final int COLOR = 1;
|
||||
public static final int NORMAL = 2;
|
||||
public static final int TEXTURE0 = 4;
|
||||
public static final int LIGHTING = 8;
|
||||
public static final int FOG = 16;
|
||||
public static final int ALPHATEST = 32;
|
||||
public static final int UNIT0 = 64;
|
||||
|
||||
public static FixedFunctionShader instance(int i) {
|
||||
FixedFunctionShader s = instances[i];
|
||||
if (s == null) {
|
||||
boolean CC_a_color = false;
|
||||
boolean CC_a_normal = false;
|
||||
boolean CC_a_texture0 = false;
|
||||
boolean CC_lighting = false;
|
||||
boolean CC_fog = false;
|
||||
boolean CC_alphatest = false;
|
||||
boolean CC_unit0 = false;
|
||||
if ((i & COLOR) == COLOR) {
|
||||
CC_a_color = true;
|
||||
}
|
||||
if ((i & NORMAL) == NORMAL) {
|
||||
CC_a_normal = true;
|
||||
}
|
||||
if ((i & TEXTURE0) == TEXTURE0) {
|
||||
CC_a_texture0 = true;
|
||||
}
|
||||
if ((i & LIGHTING) == LIGHTING) {
|
||||
CC_lighting = true;
|
||||
}
|
||||
if ((i & FOG) == FOG) {
|
||||
CC_fog = true;
|
||||
}
|
||||
if ((i & ALPHATEST) == ALPHATEST) {
|
||||
CC_alphatest = true;
|
||||
}
|
||||
if ((i & UNIT0) == UNIT0) {
|
||||
CC_unit0 = true;
|
||||
}
|
||||
s = new FixedFunctionShader(i, CC_a_color, CC_a_normal, CC_a_texture0, CC_lighting, CC_fog, CC_alphatest, CC_unit0);
|
||||
instances[i] = s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static String shaderSource = null;
|
||||
|
||||
private final boolean enable_color;
|
||||
private final boolean enable_normal;
|
||||
private final boolean enable_texture0;
|
||||
private final boolean enable_lighting;
|
||||
private final boolean enable_fog;
|
||||
private final boolean enable_alphatest;
|
||||
private final boolean enable_unit0;
|
||||
private final ProgramGL globject;
|
||||
|
||||
private UniformGL u_matrix_m = null;
|
||||
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_fogPremultiply = null;
|
||||
|
||||
private UniformGL u_colorUniform = null;
|
||||
private UniformGL u_normalUniform = null;
|
||||
|
||||
private UniformGL u_alphaTestF = null;
|
||||
|
||||
private UniformGL u_texCoordV0 = null;
|
||||
|
||||
private UniformGL u_light0Pos = null;
|
||||
private UniformGL u_light1Pos = null;
|
||||
|
||||
private final int a_position;
|
||||
private final int a_texture0;
|
||||
private final int a_color;
|
||||
private final int a_normal;
|
||||
|
||||
private final int attributeIndexesToEnable;
|
||||
|
||||
public final BufferArrayGL genericArray;
|
||||
public final BufferGL genericBuffer;
|
||||
public boolean bufferIsInitialized = false;
|
||||
|
||||
private FixedFunctionShader(int j, boolean CC_a_color, boolean CC_a_normal, boolean CC_a_texture0,
|
||||
boolean CC_lighting, boolean CC_fog, boolean CC_alphatest, boolean CC_unit0) {
|
||||
enable_color = CC_a_color;
|
||||
enable_normal = CC_a_normal;
|
||||
enable_texture0 = CC_a_texture0;
|
||||
enable_lighting = CC_lighting;
|
||||
enable_fog = CC_fog;
|
||||
enable_alphatest = CC_alphatest;
|
||||
enable_unit0 = CC_unit0;
|
||||
|
||||
if (shaderSource == null) {
|
||||
shaderSource = fileContents("/glsl/core.glsl");
|
||||
}
|
||||
|
||||
String source = "";
|
||||
if (enable_color)
|
||||
source += "\n#define CC_a_color\n";
|
||||
if (enable_normal)
|
||||
source += "#define CC_a_normal\n";
|
||||
if (enable_texture0)
|
||||
source += "#define CC_a_texture0\n";
|
||||
if (enable_lighting)
|
||||
source += "#define CC_lighting\n";
|
||||
if (enable_fog)
|
||||
source += "#define CC_fog\n";
|
||||
if (enable_alphatest)
|
||||
source += "#define CC_alphatest\n";
|
||||
if (enable_unit0)
|
||||
source += "#define CC_unit0\n";
|
||||
source += shaderSource;
|
||||
|
||||
ShaderGL v = _wglCreateShader(_wGL_VERTEX_SHADER);
|
||||
_wglShaderSource(v, _wgetShaderHeader() + "\n#define CC_VERT\n" + source);
|
||||
_wglCompileShader(v);
|
||||
|
||||
if (!_wglGetShaderCompiled(v)) {
|
||||
System.err.println(("\n\n" + _wglGetShaderInfoLog(v)).replace("\n", "\n[/glsl/core.glsl][CC_VERT] "));
|
||||
throw new RuntimeException("broken shader file");
|
||||
}
|
||||
|
||||
ShaderGL f = _wglCreateShader(_wGL_FRAGMENT_SHADER);
|
||||
_wglShaderSource(f, _wgetShaderHeader() + "\n#define CC_FRAG\n" + source);
|
||||
_wglCompileShader(f);
|
||||
|
||||
if (!_wglGetShaderCompiled(f)) {
|
||||
System.err.println(("\n\n" + _wglGetShaderInfoLog(f)).replace("\n", "\n[/glsl/core.glsl][CC_FRAG] "));
|
||||
throw new RuntimeException("broken shader file");
|
||||
}
|
||||
|
||||
globject = _wglCreateProgram();
|
||||
_wglAttachShader(globject, v);
|
||||
_wglAttachShader(globject, f);
|
||||
|
||||
int i = 0;
|
||||
a_position = i++;
|
||||
_wglBindAttributeLocation(globject, a_position, "a_position");
|
||||
|
||||
if (enable_texture0) {
|
||||
a_texture0 = i++;
|
||||
_wglBindAttributeLocation(globject, a_texture0, "a_texture0");
|
||||
} else {
|
||||
a_texture0 = -1;
|
||||
}
|
||||
if (enable_color) {
|
||||
a_color = i++;
|
||||
_wglBindAttributeLocation(globject, a_color, "a_color");
|
||||
} else {
|
||||
a_color = -1;
|
||||
}
|
||||
if (enable_normal) {
|
||||
a_normal = i++;
|
||||
_wglBindAttributeLocation(globject, a_normal, "a_normal");
|
||||
} else {
|
||||
a_normal = -1;
|
||||
}
|
||||
|
||||
attributeIndexesToEnable = i;
|
||||
|
||||
_wglLinkProgram(globject);
|
||||
|
||||
_wglDetachShader(globject, v);
|
||||
_wglDetachShader(globject, f);
|
||||
_wglDeleteShader(v);
|
||||
_wglDeleteShader(f);
|
||||
|
||||
if (!_wglGetProgramLinked(globject)) {
|
||||
System.err.println(("\n\n" + _wglGetProgramInfoLog(globject)).replace("\n", "\n[LINKER] "));
|
||||
throw new RuntimeException("broken shader file");
|
||||
}
|
||||
|
||||
_wglUseProgram(globject);
|
||||
|
||||
u_matrix_m = _wglGetUniformLocation(globject, "matrix_m");
|
||||
u_matrix_p = _wglGetUniformLocation(globject, "matrix_p");
|
||||
u_matrix_t = _wglGetUniformLocation(globject, "matrix_t");
|
||||
|
||||
u_colorUniform = _wglGetUniformLocation(globject, "colorUniform");
|
||||
|
||||
if (enable_lighting) {
|
||||
u_normalUniform = _wglGetUniformLocation(globject, "normalUniform");
|
||||
// u_invertNormals = _wglGetUniformLocation(globject, "invertNormals");
|
||||
u_light0Pos = _wglGetUniformLocation(globject, "light0Pos");
|
||||
u_light1Pos = _wglGetUniformLocation(globject, "light1Pos");
|
||||
}
|
||||
|
||||
if (enable_fog) {
|
||||
u_fogColor = _wglGetUniformLocation(globject, "fogColor");
|
||||
u_fogMode = _wglGetUniformLocation(globject, "fogMode");
|
||||
u_fogStart = _wglGetUniformLocation(globject, "fogStart");
|
||||
u_fogEnd = _wglGetUniformLocation(globject, "fogEnd");
|
||||
u_fogDensity = _wglGetUniformLocation(globject, "fogDensity");
|
||||
u_fogPremultiply = _wglGetUniformLocation(globject, "fogPremultiply");
|
||||
}
|
||||
|
||||
if (enable_alphatest) {
|
||||
u_alphaTestF = _wglGetUniformLocation(globject, "alphaTestF");
|
||||
}
|
||||
|
||||
_wglUniform1i(_wglGetUniformLocation(globject, "tex0"), 0);
|
||||
u_texCoordV0 = _wglGetUniformLocation(globject, "texCoordV0");
|
||||
|
||||
genericArray = _wglCreateVertexArray();
|
||||
genericBuffer = _wglCreateBuffer();
|
||||
_wglBindVertexArray(genericArray);
|
||||
_wglBindBuffer(_wGL_ARRAY_BUFFER, genericBuffer);
|
||||
setupArrayForProgram();
|
||||
|
||||
}
|
||||
|
||||
public void setupArrayForProgram() {
|
||||
_wglEnableVertexAttribArray(a_position);
|
||||
_wglVertexAttribPointer(a_position, 3, _wGL_FLOAT, false, 28, 0);
|
||||
if (enable_texture0) {
|
||||
_wglEnableVertexAttribArray(a_texture0);
|
||||
_wglVertexAttribPointer(a_texture0, 2, _wGL_FLOAT, false, 28, 12);
|
||||
}
|
||||
if (enable_color) {
|
||||
_wglEnableVertexAttribArray(a_color);
|
||||
_wglVertexAttribPointer(a_color, 4, _wGL_UNSIGNED_BYTE, true, 28, 20);
|
||||
}
|
||||
if (enable_normal) {
|
||||
_wglEnableVertexAttribArray(a_normal);
|
||||
_wglVertexAttribPointer(a_normal, 4, _wGL_UNSIGNED_BYTE, true, 28, 24);
|
||||
}
|
||||
}
|
||||
|
||||
public void useProgram() {
|
||||
_wglUseProgram(globject);
|
||||
}
|
||||
|
||||
public void unuseProgram() {
|
||||
|
||||
}
|
||||
|
||||
private float[] modelBuffer = new float[16];
|
||||
private float[] projectionBuffer = new float[16];
|
||||
private float[] textureBuffer = new float[16];
|
||||
|
||||
private Matrix4f modelMatrix = (Matrix4f) new Matrix4f().setZero();
|
||||
private Matrix4f projectionMatrix = (Matrix4f) new Matrix4f().setZero();
|
||||
private Matrix4f textureMatrix = (Matrix4f) new Matrix4f().setZero();
|
||||
private Vector4f light0Pos = new Vector4f();
|
||||
private Vector4f light1Pos = new Vector4f();
|
||||
|
||||
public void setModelMatrix(Matrix4f mat) {
|
||||
if (!mat.equals(modelMatrix)) {
|
||||
modelMatrix.load(mat).store(modelBuffer);
|
||||
_wglUniformMat4fv(u_matrix_m, modelBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void setProjectionMatrix(Matrix4f mat) {
|
||||
if (!mat.equals(projectionMatrix)) {
|
||||
projectionMatrix.load(mat).store(projectionBuffer);
|
||||
_wglUniformMat4fv(u_matrix_p, projectionBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextureMatrix(Matrix4f mat) {
|
||||
if (!mat.equals(textureMatrix)) {
|
||||
textureMatrix.load(mat).store(textureBuffer);
|
||||
_wglUniformMat4fv(u_matrix_t, textureBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLightPositions(Vector4f pos0, Vector4f pos1) {
|
||||
if (!pos0.equals(light0Pos) || !pos1.equals(light1Pos)) {
|
||||
light0Pos.set(pos0);
|
||||
light1Pos.set(pos1);
|
||||
_wglUniform3f(u_light0Pos, light0Pos.x, light0Pos.y, light0Pos.z);
|
||||
_wglUniform3f(u_light1Pos, light1Pos.x, light1Pos.y, light1Pos.z);
|
||||
}
|
||||
}
|
||||
|
||||
private int fogMode = 0;
|
||||
|
||||
public void setFogMode(int mode) {
|
||||
if (fogMode != mode) {
|
||||
fogMode = mode;
|
||||
_wglUniform1i(u_fogMode, mode % 2);
|
||||
_wglUniform1f(u_fogPremultiply, mode / 2);
|
||||
}
|
||||
}
|
||||
|
||||
private float fogColorR = 0.0f;
|
||||
private float fogColorG = 0.0f;
|
||||
private float fogColorB = 0.0f;
|
||||
private float fogColorA = 0.0f;
|
||||
|
||||
public void setFogColor(float r, float g, float b, float a) {
|
||||
if (fogColorR != r || fogColorG != g || fogColorB != b || fogColorA != a) {
|
||||
fogColorR = r;
|
||||
fogColorG = g;
|
||||
fogColorB = b;
|
||||
fogColorA = a;
|
||||
_wglUniform4f(u_fogColor, fogColorR, fogColorG, fogColorB, fogColorA);
|
||||
}
|
||||
}
|
||||
|
||||
private float fogStart = 0.0f;
|
||||
private float fogEnd = 0.0f;
|
||||
|
||||
public void setFogStartEnd(float s, float e) {
|
||||
if (fogStart != s || fogEnd != e) {
|
||||
fogStart = s;
|
||||
fogEnd = e;
|
||||
_wglUniform1f(u_fogStart, fogStart);
|
||||
_wglUniform1f(u_fogEnd, fogEnd);
|
||||
}
|
||||
}
|
||||
|
||||
private float fogDensity = 0.0f;
|
||||
|
||||
public void setFogDensity(float d) {
|
||||
if (fogDensity != d) {
|
||||
fogDensity = d;
|
||||
_wglUniform1f(u_fogDensity, fogDensity);
|
||||
}
|
||||
}
|
||||
|
||||
private float alphaTestValue = 0.0f;
|
||||
|
||||
public void setAlphaTest(float limit) {
|
||||
if (alphaTestValue != limit) {
|
||||
alphaTestValue = limit;
|
||||
_wglUniform1f(u_alphaTestF, alphaTestValue);
|
||||
}
|
||||
}
|
||||
|
||||
private float tex0x = 0.0f;
|
||||
private float tex0y = 0.0f;
|
||||
|
||||
public void setTex0Coords(float x, float y) {
|
||||
if (tex0x != x || tex0y != y) {
|
||||
tex0x = x;
|
||||
tex0y = y;
|
||||
_wglUniform2f(u_texCoordV0, tex0x, tex0y);
|
||||
}
|
||||
}
|
||||
|
||||
private float colorUniformR = 0.0f;
|
||||
private float colorUniformG = 0.0f;
|
||||
private float colorUniformB = 0.0f;
|
||||
private float colorUniformA = 0.0f;
|
||||
|
||||
public void setColor(float r, float g, float b, float a) {
|
||||
if (colorUniformR != r || colorUniformG != g || colorUniformB != b || colorUniformA != a) {
|
||||
colorUniformR = r;
|
||||
colorUniformG = g;
|
||||
colorUniformB = b;
|
||||
colorUniformA = a;
|
||||
_wglUniform4f(u_colorUniform, colorUniformR, colorUniformG, colorUniformB, colorUniformA);
|
||||
}
|
||||
}
|
||||
|
||||
private float normalUniformX = 0.0f;
|
||||
private float normalUniformY = 0.0f;
|
||||
private float normalUniformZ = 0.0f;
|
||||
|
||||
public void setNormal(float x, float y, float z) {
|
||||
if (normalUniformX != x || normalUniformY != y || normalUniformZ != z) {
|
||||
normalUniformX = x;
|
||||
normalUniformY = y;
|
||||
normalUniformZ = z;
|
||||
_wglUniform3f(u_normalUniform, normalUniformX, normalUniformY, normalUniformZ);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
55
src/main/java/net/PeytonPlayz585/glemu/GLObjectMap.java
Normal file
55
src/main/java/net/PeytonPlayz585/glemu/GLObjectMap.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package net.PeytonPlayz585.glemu;
|
||||
|
||||
public class GLObjectMap<T> {
|
||||
private Object[] values;
|
||||
private int size;
|
||||
private int insertIndex;
|
||||
public int allocatedObjects;
|
||||
|
||||
public GLObjectMap(int initialSize) {
|
||||
this.values = new Object[initialSize];
|
||||
this.size = initialSize;
|
||||
this.insertIndex = 0;
|
||||
this.allocatedObjects = 0;
|
||||
}
|
||||
|
||||
public int register(T obj) {
|
||||
int start = insertIndex;
|
||||
do {
|
||||
++insertIndex;
|
||||
if (insertIndex >= size) {
|
||||
insertIndex = 0;
|
||||
}
|
||||
if (insertIndex == start) {
|
||||
resize();
|
||||
return register(obj);
|
||||
}
|
||||
} while (values[insertIndex] != null);
|
||||
values[insertIndex] = obj;
|
||||
++allocatedObjects;
|
||||
return insertIndex;
|
||||
}
|
||||
|
||||
public T free(int obj) {
|
||||
if (obj >= size || obj < 0)
|
||||
return null;
|
||||
Object ret = values[obj];
|
||||
values[obj] = null;
|
||||
--allocatedObjects;
|
||||
return (T) ret;
|
||||
}
|
||||
|
||||
public T get(int obj) {
|
||||
if (obj >= size || obj < 0)
|
||||
return null;
|
||||
return (T) values[obj];
|
||||
}
|
||||
|
||||
private void resize() {
|
||||
int oldSize = size;
|
||||
size += size / 2;
|
||||
Object[] oldValues = values;
|
||||
values = new Object[size];
|
||||
System.arraycopy(oldValues, 0, values, 0, oldSize);
|
||||
}
|
||||
}
|
130
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix.java
Normal file
130
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix.java
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for matrices. When a matrix is constructed it will be the identity
|
||||
* matrix unless otherwise stated.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
public abstract class Matrix implements Serializable {
|
||||
|
||||
/**
|
||||
* Constructor for Matrix.
|
||||
*/
|
||||
protected Matrix() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix setIdentity();
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix invert();
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix load(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (mathematical) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix loadTranspose(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix negate();
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column major
|
||||
* (openGL) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix store(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix storeTranspose(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix transpose();
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix setZero();
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public abstract float determinant();
|
||||
|
||||
}
|
418
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix2f.java
Normal file
418
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix2f.java
Normal file
|
@ -0,0 +1,418 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 2x2 matrix
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Matrix2f extends Matrix implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float m00, m01, m10, m11;
|
||||
|
||||
/**
|
||||
* Constructor for Matrix2f. The matrix is initialised to the identity.
|
||||
*/
|
||||
public Matrix2f() {
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Matrix2f(Matrix2f src) {
|
||||
load(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another matrix
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @return this
|
||||
*/
|
||||
public Matrix2f load(Matrix2f src) {
|
||||
return load(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the source matrix to the destination matrix.
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new one should be created.
|
||||
* @return The copied matrix
|
||||
*/
|
||||
public static Matrix2f load(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = src.m00;
|
||||
dest.m01 = src.m01;
|
||||
dest.m10 = src.m10;
|
||||
dest.m11 = src.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (mathematical) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column major
|
||||
* (openGL) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the right matrix from the left and place the result in a third
|
||||
* matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the right matrix by the left and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
float m00 = left.m00 * right.m00 + left.m10 * right.m01;
|
||||
float m01 = left.m01 * right.m00 + left.m11 * right.m01;
|
||||
float m10 = left.m00 * right.m10 + left.m10 * right.m11;
|
||||
float m11 = left.m01 * right.m10 + left.m11 * right.m11;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Vector by a matrix and return the result in a destination vector.
|
||||
*
|
||||
* @param left The left matrix
|
||||
* @param right The right vector
|
||||
* @param dest The destination vector, or null if a new one is to be created
|
||||
* @return the destination vector
|
||||
*/
|
||||
public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector2f();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y;
|
||||
float y = left.m01 * right.x + left.m11 * right.y;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix transpose() {
|
||||
return transpose(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix and place the result in another matrix.
|
||||
*
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public Matrix2f transpose(Matrix2f dest) {
|
||||
return transpose(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose the source matrix and place the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix or null if a new matrix is to be created
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public static Matrix2f transpose(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
float m01 = src.m10;
|
||||
float m10 = src.m01;
|
||||
|
||||
dest.m01 = m01;
|
||||
dest.m10 = m10;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
*
|
||||
* @return this if successful, null otherwise
|
||||
*/
|
||||
public Matrix invert() {
|
||||
return invert(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the source matrix and place the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix to be inverted
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return The inverted matrix, or null if source can't be reverted.
|
||||
*/
|
||||
public static Matrix2f invert(Matrix2f src, Matrix2f dest) {
|
||||
/*
|
||||
* inv(A) = 1/det(A) * adj(A);
|
||||
*/
|
||||
|
||||
float determinant = src.determinant();
|
||||
if (determinant != 0) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
float determinant_inv = 1f / determinant;
|
||||
float t00 = src.m11 * determinant_inv;
|
||||
float t01 = -src.m01 * determinant_inv;
|
||||
float t11 = src.m00 * determinant_inv;
|
||||
float t10 = -src.m10 * determinant_inv;
|
||||
|
||||
dest.m00 = t00;
|
||||
dest.m01 = t01;
|
||||
dest.m10 = t10;
|
||||
dest.m11 = t11;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this matrix
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(m00).append(' ').append(m10).append(' ').append('\n');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append('\n');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and stash the result in another matrix.
|
||||
*
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public Matrix2f negate(Matrix2f dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the source matrix and stash the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix to be negated
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public static Matrix2f negate(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m01;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source matrix to be the identity matrix.
|
||||
*
|
||||
* @param src The matrix to set to the identity.
|
||||
* @return The source matrix
|
||||
*/
|
||||
public static Matrix2f setIdentity(Matrix2f src) {
|
||||
src.m00 = 1.0f;
|
||||
src.m01 = 0.0f;
|
||||
src.m10 = 0.0f;
|
||||
src.m11 = 1.0f;
|
||||
return src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setZero() {
|
||||
return setZero(this);
|
||||
}
|
||||
|
||||
public static Matrix2f setZero(Matrix2f src) {
|
||||
src.m00 = 0.0f;
|
||||
src.m01 = 0.0f;
|
||||
src.m10 = 0.0f;
|
||||
src.m11 = 0.0f;
|
||||
return src;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Matrix#determinant()
|
||||
*/
|
||||
public float determinant() {
|
||||
return m00 * m11 - m01 * m10;
|
||||
}
|
||||
}
|
529
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix3f.java
Normal file
529
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix3f.java
Normal file
|
@ -0,0 +1,529 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 3x3 matrix.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Matrix3f extends Matrix implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float m00, m01, m02, m10, m11, m12, m20, m21, m22;
|
||||
|
||||
/**
|
||||
* Constructor for Matrix3f. Matrix is initialised to the identity.
|
||||
*/
|
||||
public Matrix3f() {
|
||||
super();
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another matrix
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @return this
|
||||
*/
|
||||
public Matrix3f load(Matrix3f src) {
|
||||
return load(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy source matrix to destination matrix
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null of a new matrix is to be created
|
||||
* @return The copied matrix
|
||||
*/
|
||||
public static Matrix3f load(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = src.m00;
|
||||
dest.m10 = src.m10;
|
||||
dest.m20 = src.m20;
|
||||
dest.m01 = src.m01;
|
||||
dest.m11 = src.m11;
|
||||
dest.m21 = src.m21;
|
||||
dest.m02 = src.m02;
|
||||
dest.m12 = src.m12;
|
||||
dest.m22 = src.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m02 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
m12 = buf.get();
|
||||
m20 = buf.get();
|
||||
m21 = buf.get();
|
||||
m22 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major (maths)
|
||||
* order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m20 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
m21 = buf.get();
|
||||
m02 = buf.get();
|
||||
m12 = buf.get();
|
||||
m22 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column major
|
||||
* (openGL) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m02);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
buf.put(m12);
|
||||
buf.put(m20);
|
||||
buf.put(m21);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matrix store(float[] buf) {
|
||||
buf[0] = m00;
|
||||
buf[1] = m01;
|
||||
buf[2] = m02;
|
||||
buf[3] = m10;
|
||||
buf[4] = m11;
|
||||
buf[5] = m12;
|
||||
buf[6] = m20;
|
||||
buf[7] = m21;
|
||||
buf[8] = m22;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m20);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
buf.put(m21);
|
||||
buf.put(m02);
|
||||
buf.put(m12);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f add(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m02 = left.m02 + right.m02;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
dest.m12 = left.m12 + right.m12;
|
||||
dest.m20 = left.m20 + right.m20;
|
||||
dest.m21 = left.m21 + right.m21;
|
||||
dest.m22 = left.m22 + right.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the right matrix from the left and place the result in a third
|
||||
* matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f sub(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m02 = left.m02 - right.m02;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
dest.m12 = left.m12 - right.m12;
|
||||
dest.m20 = left.m20 - right.m20;
|
||||
dest.m21 = left.m21 - right.m21;
|
||||
dest.m22 = left.m22 - right.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the right matrix by the left and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f mul(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02;
|
||||
float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02;
|
||||
float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02;
|
||||
float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12;
|
||||
float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12;
|
||||
float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12;
|
||||
float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22;
|
||||
float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22;
|
||||
float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Vector by a matrix and return the result in a destination vector.
|
||||
*
|
||||
* @param left The left matrix
|
||||
* @param right The right vector
|
||||
* @param dest The destination vector, or null if a new one is to be created
|
||||
* @return the destination vector
|
||||
*/
|
||||
public static Vector3f transform(Matrix3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z;
|
||||
float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z;
|
||||
float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
dest.z = z;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix transpose() {
|
||||
return transpose(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix and place the result in another matrix
|
||||
*
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public Matrix3f transpose(Matrix3f dest) {
|
||||
return transpose(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose the source matrix and place the result into the destination matrix
|
||||
*
|
||||
* @param src The source matrix to be transposed
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public static Matrix3f transpose(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
float m00 = src.m00;
|
||||
float m01 = src.m10;
|
||||
float m02 = src.m20;
|
||||
float m10 = src.m01;
|
||||
float m11 = src.m11;
|
||||
float m12 = src.m21;
|
||||
float m20 = src.m02;
|
||||
float m21 = src.m12;
|
||||
float m22 = src.m22;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public float determinant() {
|
||||
float f = m00 * (m11 * m22 - m12 * m21) + m01 * (m12 * m20 - m10 * m22) + m02 * (m10 * m21 - m11 * m20);
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this matrix
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append('\n');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append('\n');
|
||||
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append('\n');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
*
|
||||
* @return this if successful, null otherwise
|
||||
*/
|
||||
public Matrix invert() {
|
||||
return invert(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the source matrix and put the result into the destination matrix
|
||||
*
|
||||
* @param src The source matrix to be inverted
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return The inverted matrix if successful, null otherwise
|
||||
*/
|
||||
public static Matrix3f invert(Matrix3f src, Matrix3f dest) {
|
||||
float determinant = src.determinant();
|
||||
|
||||
if (determinant != 0) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
/*
|
||||
* do it the ordinary way
|
||||
*
|
||||
* inv(A) = 1/det(A) * adj(T), where adj(T) = transpose(Conjugate Matrix)
|
||||
*
|
||||
* m00 m01 m02 m10 m11 m12 m20 m21 m22
|
||||
*/
|
||||
float determinant_inv = 1f / determinant;
|
||||
|
||||
// get the conjugate matrix
|
||||
float t00 = src.m11 * src.m22 - src.m12 * src.m21;
|
||||
float t01 = -src.m10 * src.m22 + src.m12 * src.m20;
|
||||
float t02 = src.m10 * src.m21 - src.m11 * src.m20;
|
||||
float t10 = -src.m01 * src.m22 + src.m02 * src.m21;
|
||||
float t11 = src.m00 * src.m22 - src.m02 * src.m20;
|
||||
float t12 = -src.m00 * src.m21 + src.m01 * src.m20;
|
||||
float t20 = src.m01 * src.m12 - src.m02 * src.m11;
|
||||
float t21 = -src.m00 * src.m12 + src.m02 * src.m10;
|
||||
float t22 = src.m00 * src.m11 - src.m01 * src.m10;
|
||||
|
||||
dest.m00 = t00 * determinant_inv;
|
||||
dest.m11 = t11 * determinant_inv;
|
||||
dest.m22 = t22 * determinant_inv;
|
||||
dest.m01 = t10 * determinant_inv;
|
||||
dest.m10 = t01 * determinant_inv;
|
||||
dest.m20 = t02 * determinant_inv;
|
||||
dest.m02 = t20 * determinant_inv;
|
||||
dest.m12 = t21 * determinant_inv;
|
||||
dest.m21 = t12 * determinant_inv;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and place the result in a destination matrix.
|
||||
*
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public Matrix3f negate(Matrix3f dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the source matrix and place the result in the destination matrix.
|
||||
*
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public static Matrix3f negate(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m02;
|
||||
dest.m02 = -src.m01;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m12;
|
||||
dest.m12 = -src.m11;
|
||||
dest.m20 = -src.m20;
|
||||
dest.m21 = -src.m22;
|
||||
dest.m22 = -src.m21;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix to be the identity matrix.
|
||||
*
|
||||
* @param m The matrix to be set to the identity
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix3f setIdentity(Matrix3f m) {
|
||||
m.m00 = 1.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 1.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 1.0f;
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix setZero() {
|
||||
return setZero(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix matrix to 0.
|
||||
*
|
||||
* @param m The matrix to be set to 0
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix3f setZero(Matrix3f m) {
|
||||
m.m00 = 0.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 0.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 0.0f;
|
||||
return m;
|
||||
}
|
||||
|
||||
public boolean equals(Object m) {
|
||||
return (m instanceof Matrix3f) && equal(this, (Matrix3f) m);
|
||||
}
|
||||
|
||||
public static boolean equal(Matrix3f a, Matrix3f b) {
|
||||
return a.m00 == b.m00 && a.m01 == b.m01 && a.m02 == b.m02 && a.m10 == b.m10 && a.m11 == b.m11 && a.m12 == b.m12
|
||||
&& a.m20 == b.m20 && a.m21 == b.m21 && a.m22 == b.m22;
|
||||
}
|
||||
}
|
902
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix4f.java
Normal file
902
src/main/java/net/PeytonPlayz585/glemu/vector/Matrix4f.java
Normal file
|
@ -0,0 +1,902 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
* Holds a 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();
|
||||
}
|
||||
|
||||
public Matrix4f(final Matrix4f src) {
|
||||
super();
|
||||
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');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append(m31).append('\n');
|
||||
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append(m32).append('\n');
|
||||
buf.append(m03).append(' ').append(m13).append(' ').append(m23).append(' ').append(m33).append('\n');
|
||||
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;
|
||||
m.m02 = 0.0f;
|
||||
m.m03 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 1.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m13 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 1.0f;
|
||||
m.m23 = 0.0f;
|
||||
m.m30 = 0.0f;
|
||||
m.m31 = 0.0f;
|
||||
m.m32 = 0.0f;
|
||||
m.m33 = 1.0f;
|
||||
|
||||
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;
|
||||
m.m02 = 0.0f;
|
||||
m.m03 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 0.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m13 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 0.0f;
|
||||
m.m23 = 0.0f;
|
||||
m.m30 = 0.0f;
|
||||
m.m31 = 0.0f;
|
||||
m.m32 = 0.0f;
|
||||
m.m33 = 0.0f;
|
||||
|
||||
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();
|
||||
dest.m00 = src.m00;
|
||||
dest.m01 = src.m01;
|
||||
dest.m02 = src.m02;
|
||||
dest.m03 = src.m03;
|
||||
dest.m10 = src.m10;
|
||||
dest.m11 = src.m11;
|
||||
dest.m12 = src.m12;
|
||||
dest.m13 = src.m13;
|
||||
dest.m20 = src.m20;
|
||||
dest.m21 = src.m21;
|
||||
dest.m22 = src.m22;
|
||||
dest.m23 = src.m23;
|
||||
dest.m30 = src.m30;
|
||||
dest.m31 = src.m31;
|
||||
dest.m32 = src.m32;
|
||||
dest.m33 = src.m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m02 = buf.get();
|
||||
m03 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
m12 = buf.get();
|
||||
m13 = buf.get();
|
||||
m20 = buf.get();
|
||||
m21 = buf.get();
|
||||
m22 = buf.get();
|
||||
m23 = buf.get();
|
||||
m30 = buf.get();
|
||||
m31 = buf.get();
|
||||
m32 = buf.get();
|
||||
m33 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major (maths)
|
||||
* order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m20 = buf.get();
|
||||
m30 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
m21 = buf.get();
|
||||
m31 = buf.get();
|
||||
m02 = buf.get();
|
||||
m12 = buf.get();
|
||||
m22 = buf.get();
|
||||
m32 = buf.get();
|
||||
m03 = buf.get();
|
||||
m13 = buf.get();
|
||||
m23 = buf.get();
|
||||
m33 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column major
|
||||
* (openGL) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m02);
|
||||
buf.put(m03);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
buf.put(m12);
|
||||
buf.put(m13);
|
||||
buf.put(m20);
|
||||
buf.put(m21);
|
||||
buf.put(m22);
|
||||
buf.put(m23);
|
||||
buf.put(m30);
|
||||
buf.put(m31);
|
||||
buf.put(m32);
|
||||
buf.put(m33);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matrix store(float[] buf) {
|
||||
buf[0] = m00;
|
||||
buf[1] = m01;
|
||||
buf[2] = m02;
|
||||
buf[3] = m03;
|
||||
buf[4] = m10;
|
||||
buf[5] = m11;
|
||||
buf[6] = m12;
|
||||
buf[7] = m13;
|
||||
buf[8] = m20;
|
||||
buf[9] = m21;
|
||||
buf[10] = m22;
|
||||
buf[11] = m23;
|
||||
buf[12] = m30;
|
||||
buf[13] = m31;
|
||||
buf[14] = m32;
|
||||
buf[15] = m33;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m20);
|
||||
buf.put(m30);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
buf.put(m21);
|
||||
buf.put(m31);
|
||||
buf.put(m02);
|
||||
buf.put(m12);
|
||||
buf.put(m22);
|
||||
buf.put(m32);
|
||||
buf.put(m03);
|
||||
buf.put(m13);
|
||||
buf.put(m23);
|
||||
buf.put(m33);
|
||||
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);
|
||||
buf.put(m02);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
buf.put(m12);
|
||||
buf.put(m20);
|
||||
buf.put(m21);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
*
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m02 = left.m02 + right.m02;
|
||||
dest.m03 = left.m03 + right.m03;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
dest.m12 = left.m12 + right.m12;
|
||||
dest.m13 = left.m13 + right.m13;
|
||||
dest.m20 = left.m20 + right.m20;
|
||||
dest.m21 = left.m21 + right.m21;
|
||||
dest.m22 = left.m22 + right.m22;
|
||||
dest.m23 = left.m23 + right.m23;
|
||||
dest.m30 = left.m30 + right.m30;
|
||||
dest.m31 = left.m31 + right.m31;
|
||||
dest.m32 = left.m32 + right.m32;
|
||||
dest.m33 = left.m33 + right.m33;
|
||||
|
||||
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();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m02 = left.m02 - right.m02;
|
||||
dest.m03 = left.m03 - right.m03;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
dest.m12 = left.m12 - right.m12;
|
||||
dest.m13 = left.m13 - right.m13;
|
||||
dest.m20 = left.m20 - right.m20;
|
||||
dest.m21 = left.m21 - right.m21;
|
||||
dest.m22 = left.m22 - right.m22;
|
||||
dest.m23 = left.m23 - right.m23;
|
||||
dest.m30 = left.m30 - right.m30;
|
||||
dest.m31 = left.m31 - right.m31;
|
||||
dest.m32 = left.m32 - right.m32;
|
||||
dest.m33 = left.m33 - right.m33;
|
||||
|
||||
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();
|
||||
|
||||
float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02 + left.m30 * right.m03;
|
||||
float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02 + left.m31 * right.m03;
|
||||
float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02 + left.m32 * right.m03;
|
||||
float m03 = left.m03 * right.m00 + left.m13 * right.m01 + left.m23 * right.m02 + left.m33 * right.m03;
|
||||
float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12 + left.m30 * right.m13;
|
||||
float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12 + left.m31 * right.m13;
|
||||
float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12 + left.m32 * right.m13;
|
||||
float m13 = left.m03 * right.m10 + left.m13 * right.m11 + left.m23 * right.m12 + left.m33 * right.m13;
|
||||
float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22 + left.m30 * right.m23;
|
||||
float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22 + left.m31 * right.m23;
|
||||
float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22 + left.m32 * right.m23;
|
||||
float m23 = left.m03 * right.m20 + left.m13 * right.m21 + left.m23 * right.m22 + left.m33 * right.m23;
|
||||
float m30 = left.m00 * right.m30 + left.m10 * right.m31 + left.m20 * right.m32 + left.m30 * right.m33;
|
||||
float m31 = left.m01 * right.m30 + left.m11 * right.m31 + left.m21 * right.m32 + left.m31 * right.m33;
|
||||
float m32 = left.m02 * right.m30 + left.m12 * right.m31 + left.m22 * right.m32 + left.m32 * right.m33;
|
||||
float m33 = left.m03 * right.m30 + left.m13 * right.m31 + left.m23 * right.m32 + left.m33 * right.m33;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m03 = m03;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m13 = m13;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
dest.m23 = m23;
|
||||
dest.m30 = m30;
|
||||
dest.m31 = m31;
|
||||
dest.m32 = m32;
|
||||
dest.m33 = m33;
|
||||
|
||||
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();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z + left.m30 * right.w;
|
||||
float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z + left.m31 * right.w;
|
||||
float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z + left.m32 * right.w;
|
||||
float w = left.m03 * right.x + left.m13 * right.y + left.m23 * right.z + left.m33 * right.w;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
dest.z = z;
|
||||
dest.w = w;
|
||||
|
||||
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();
|
||||
dest.m00 = src.m00 * vec.x;
|
||||
dest.m01 = src.m01 * vec.x;
|
||||
dest.m02 = src.m02 * vec.x;
|
||||
dest.m03 = src.m03 * vec.x;
|
||||
dest.m10 = src.m10 * vec.y;
|
||||
dest.m11 = src.m11 * vec.y;
|
||||
dest.m12 = src.m12 * vec.y;
|
||||
dest.m13 = src.m13 * vec.y;
|
||||
dest.m20 = src.m20 * vec.z;
|
||||
dest.m21 = src.m21 * vec.z;
|
||||
dest.m22 = src.m22 * vec.z;
|
||||
dest.m23 = src.m23 * vec.z;
|
||||
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();
|
||||
float c = (float) Math.cos(angle);
|
||||
float s = (float) Math.sin(angle);
|
||||
float oneminusc = 1.0f - c;
|
||||
float xy = axis.x * axis.y;
|
||||
float yz = axis.y * axis.z;
|
||||
float xz = axis.x * axis.z;
|
||||
float xs = axis.x * s;
|
||||
float ys = axis.y * s;
|
||||
float zs = axis.z * s;
|
||||
|
||||
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;
|
||||
|
||||
float t00 = src.m00 * f00 + src.m10 * f01 + src.m20 * f02;
|
||||
float t01 = src.m01 * f00 + src.m11 * f01 + src.m21 * f02;
|
||||
float t02 = src.m02 * f00 + src.m12 * f01 + src.m22 * f02;
|
||||
float t03 = src.m03 * f00 + src.m13 * f01 + src.m23 * f02;
|
||||
float t10 = src.m00 * f10 + src.m10 * f11 + src.m20 * f12;
|
||||
float t11 = src.m01 * f10 + src.m11 * f11 + src.m21 * f12;
|
||||
float t12 = src.m02 * f10 + src.m12 * f11 + src.m22 * f12;
|
||||
float t13 = src.m03 * f10 + src.m13 * f11 + src.m23 * f12;
|
||||
dest.m20 = src.m00 * f20 + src.m10 * f21 + src.m20 * f22;
|
||||
dest.m21 = src.m01 * f20 + src.m11 * f21 + src.m21 * f22;
|
||||
dest.m22 = src.m02 * f20 + src.m12 * f21 + src.m22 * f22;
|
||||
dest.m23 = src.m03 * f20 + src.m13 * f21 + src.m23 * f22;
|
||||
dest.m00 = t00;
|
||||
dest.m01 = t01;
|
||||
dest.m02 = t02;
|
||||
dest.m03 = t03;
|
||||
dest.m10 = t10;
|
||||
dest.m11 = t11;
|
||||
dest.m12 = t12;
|
||||
dest.m13 = t13;
|
||||
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();
|
||||
|
||||
dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z;
|
||||
dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z;
|
||||
dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z;
|
||||
dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z;
|
||||
|
||||
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();
|
||||
|
||||
dest.m30 += src.m00 * vec.x + src.m10 * vec.y;
|
||||
dest.m31 += src.m01 * vec.x + src.m11 * vec.y;
|
||||
dest.m32 += src.m02 * vec.x + src.m12 * vec.y;
|
||||
dest.m33 += src.m03 * vec.x + src.m13 * vec.y;
|
||||
|
||||
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();
|
||||
float m00 = src.m00;
|
||||
float m01 = src.m10;
|
||||
float m02 = src.m20;
|
||||
float m03 = src.m30;
|
||||
float m10 = src.m01;
|
||||
float m11 = src.m11;
|
||||
float m12 = src.m21;
|
||||
float m13 = src.m31;
|
||||
float m20 = src.m02;
|
||||
float m21 = src.m12;
|
||||
float m22 = src.m22;
|
||||
float m23 = src.m32;
|
||||
float m30 = src.m03;
|
||||
float m31 = src.m13;
|
||||
float m32 = src.m23;
|
||||
float m33 = src.m33;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m03 = m03;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m13 = m13;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
dest.m23 = m23;
|
||||
dest.m30 = m30;
|
||||
dest.m31 = m31;
|
||||
dest.m32 = m32;
|
||||
dest.m33 = m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public float determinant() {
|
||||
float f = m00 * ((m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32) - m13 * m22 * m31 - m11 * m23 * m32
|
||||
- m12 * m21 * m33);
|
||||
f -= m01 * ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32) - m13 * m22 * m30 - m10 * m23 * m32
|
||||
- m12 * m20 * m33);
|
||||
f += m02 * ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31) - m13 * m21 * m30 - m10 * m23 * m31
|
||||
- m11 * m20 * m33);
|
||||
f -= m03 * ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31) - m12 * m21 * m30 - m10 * m22 * m31
|
||||
- m11 * m20 * m32);
|
||||
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) {
|
||||
return t00 * (t11 * t22 - t12 * t21) + t01 * (t12 * t20 - t10 * t22) + 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;
|
||||
dest.m33 = t33 * determinant_inv;
|
||||
dest.m01 = t10 * determinant_inv;
|
||||
dest.m10 = t01 * determinant_inv;
|
||||
dest.m20 = t02 * determinant_inv;
|
||||
dest.m02 = t20 * determinant_inv;
|
||||
dest.m12 = t21 * determinant_inv;
|
||||
dest.m21 = t12 * determinant_inv;
|
||||
dest.m03 = t30 * determinant_inv;
|
||||
dest.m30 = t03 * determinant_inv;
|
||||
dest.m13 = t31 * determinant_inv;
|
||||
dest.m31 = t13 * determinant_inv;
|
||||
dest.m32 = t23 * determinant_inv;
|
||||
dest.m23 = t32 * determinant_inv;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and place the result in a destination matrix.
|
||||
*
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public 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();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m01;
|
||||
dest.m02 = -src.m02;
|
||||
dest.m03 = -src.m03;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m11;
|
||||
dest.m12 = -src.m12;
|
||||
dest.m13 = -src.m13;
|
||||
dest.m20 = -src.m20;
|
||||
dest.m21 = -src.m21;
|
||||
dest.m22 = -src.m22;
|
||||
dest.m23 = -src.m23;
|
||||
dest.m30 = -src.m30;
|
||||
dest.m31 = -src.m31;
|
||||
dest.m32 = -src.m32;
|
||||
dest.m33 = -src.m33;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
506
src/main/java/net/PeytonPlayz585/glemu/vector/Quaternion.java
Normal file
506
src/main/java/net/PeytonPlayz585/glemu/vector/Quaternion.java
Normal file
|
@ -0,0 +1,506 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* Quaternions for LWJGL!
|
||||
*
|
||||
* @author fbi
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class Quaternion extends Vector implements ReadableVector4f {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z, w;
|
||||
|
||||
/**
|
||||
* C'tor. The quaternion will be initialized to the identity.
|
||||
*/
|
||||
public Quaternion() {
|
||||
super();
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*
|
||||
* @param src
|
||||
*/
|
||||
public Quaternion(ReadableVector4f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*
|
||||
*/
|
||||
public Quaternion(float x, float y, float z, float w) {
|
||||
set(x, y, z, w);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector4f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Quaternion set(ReadableVector4f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
w = src.getW();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this quaternion to the multiplication identity.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Quaternion setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given quaternion to the multiplication identity.
|
||||
*
|
||||
* @param q The quaternion
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setIdentity(Quaternion q) {
|
||||
q.x = 0;
|
||||
q.y = 0;
|
||||
q.z = 0;
|
||||
q.w = 1;
|
||||
return q;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the quaternion
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise the source quaternion and place the result in another quaternion.
|
||||
*
|
||||
* @param src The source quaternion
|
||||
* @param dest The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return The normalised quaternion
|
||||
*/
|
||||
public static Quaternion normalise(Quaternion src, Quaternion dest) {
|
||||
float inv_l = 1f / src.length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
|
||||
dest.set(src.x * inv_l, src.y * inv_l, src.z * inv_l, src.w * inv_l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this quaternion and place the result in another quaternion.
|
||||
*
|
||||
* @param dest The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return the normalised quaternion
|
||||
*/
|
||||
public Quaternion normalise(Quaternion dest) {
|
||||
return normalise(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two quaternions
|
||||
*
|
||||
* @param left The LHS quat
|
||||
* @param right The RHS quat
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Quaternion left, Quaternion right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion and put it into the given one
|
||||
*
|
||||
* @param dest The quaternion which should be set to the conjugate of this
|
||||
* quaternion
|
||||
*/
|
||||
public Quaternion negate(Quaternion dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion and put it into the given one
|
||||
*
|
||||
* @param src The source quaternion
|
||||
* @param dest The quaternion which should be set to the conjugate of this
|
||||
* quaternion
|
||||
*/
|
||||
public static Quaternion negate(Quaternion src, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
|
||||
dest.x = -src.x;
|
||||
dest.y = -src.y;
|
||||
dest.z = -src.z;
|
||||
dest.w = src.w;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion
|
||||
*/
|
||||
public Vector negate() {
|
||||
return negate(this, this);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.Vector#load(java.nio.FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
return scale(scale, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale the source quaternion by scale and put the result in the destination
|
||||
*
|
||||
* @param scale The amount to scale by
|
||||
* @param src The source quaternion
|
||||
* @param dest The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return The scaled quaternion
|
||||
*/
|
||||
public static Quaternion scale(float scale, Quaternion src, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.x = src.x * scale;
|
||||
dest.y = src.y * scale;
|
||||
dest.z = src.z * scale;
|
||||
dest.w = src.w * scale;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.ReadableVector#store(java.nio.FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
buf.put(w);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set W
|
||||
*
|
||||
* @param w
|
||||
*/
|
||||
public void setW(float w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getW()
|
||||
*/
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Quaternion: " + x + " " + y + " " + z + " " + w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion to the quaternion product of quaternions
|
||||
* left and right (this = left * right). Note that this is safe for aliasing
|
||||
* (e.g. this can be left or right).
|
||||
*
|
||||
* @param left the first quaternion
|
||||
* @param right the second quaternion
|
||||
*/
|
||||
public static Quaternion mul(Quaternion left, Quaternion right, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.set(left.x * right.w + left.w * right.x + left.y * right.z - left.z * right.y,
|
||||
left.y * right.w + left.w * right.y + left.z * right.x - left.x * right.z,
|
||||
left.z * right.w + left.w * right.z + left.x * right.y - left.y * right.x,
|
||||
left.w * right.w - left.x * right.x - left.y * right.y - left.z * right.z);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Multiplies quaternion left by the inverse of quaternion right and places the
|
||||
* value into this quaternion. The value of both argument quaternions is
|
||||
* preservered (this = left * right^-1).
|
||||
*
|
||||
* @param left the left quaternion
|
||||
* @param right the right quaternion
|
||||
*/
|
||||
public static Quaternion mulInverse(Quaternion left, Quaternion right, Quaternion dest) {
|
||||
float n = right.lengthSquared();
|
||||
// zero-div may occur.
|
||||
n = (n == 0.0 ? n : 1 / n);
|
||||
// store on stack once for aliasing-safty
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.set((left.x * right.w - left.w * right.x - left.y * right.z + left.z * right.y) * n,
|
||||
(left.y * right.w - left.w * right.y - left.z * right.x + left.x * right.z) * n,
|
||||
(left.z * right.w - left.w * right.z - left.x * right.y + left.y * right.x) * n,
|
||||
(left.w * right.w + left.x * right.x + left.y * right.y + left.z * right.z) * n);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion to the equivalent rotation of the
|
||||
* Axis-Angle argument.
|
||||
*
|
||||
* @param a1 the axis-angle: (x,y,z) is the axis and w is the angle
|
||||
*/
|
||||
public final void setFromAxisAngle(Vector4f a1) {
|
||||
x = a1.x;
|
||||
y = a1.y;
|
||||
z = a1.z;
|
||||
float n = (float) Math.sqrt(x * x + y * y + z * z);
|
||||
// zero-div may occur.
|
||||
float s = (float) (Math.sin(0.5 * a1.w) / n);
|
||||
x *= s;
|
||||
y *= s;
|
||||
z *= s;
|
||||
w = (float) Math.cos(0.5 * a1.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The matrix
|
||||
* @return this
|
||||
*/
|
||||
public final Quaternion setFromMatrix(Matrix4f m) {
|
||||
return setFromMatrix(m, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the source quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The source matrix
|
||||
* @param q The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setFromMatrix(Matrix4f m, Quaternion q) {
|
||||
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The source matrix
|
||||
*/
|
||||
public final Quaternion setFromMatrix(Matrix3f m) {
|
||||
return setFromMatrix(m, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the source quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m The source matrix
|
||||
* @param q The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setFromMatrix(Matrix3f m, Quaternion q) {
|
||||
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private method to perform the matrix-to-quaternion conversion
|
||||
*/
|
||||
private Quaternion setFromMat(float m00, float m01, float m02, float m10, float m11, float m12, float m20,
|
||||
float m21, float m22) {
|
||||
|
||||
float s;
|
||||
float tr = m00 + m11 + m22;
|
||||
if (tr >= 0.0) {
|
||||
s = (float) Math.sqrt(tr + 1.0);
|
||||
w = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
x = (m21 - m12) * s;
|
||||
y = (m02 - m20) * s;
|
||||
z = (m10 - m01) * s;
|
||||
} else {
|
||||
float max = Math.max(Math.max(m00, m11), m22);
|
||||
if (max == m00) {
|
||||
s = (float) Math.sqrt(m00 - (m11 + m22) + 1.0);
|
||||
x = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
y = (m01 + m10) * s;
|
||||
z = (m20 + m02) * s;
|
||||
w = (m21 - m12) * s;
|
||||
} else if (max == m11) {
|
||||
s = (float) Math.sqrt(m11 - (m22 + m00) + 1.0);
|
||||
y = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
z = (m12 + m21) * s;
|
||||
x = (m01 + m10) * s;
|
||||
w = (m02 - m20) * s;
|
||||
} else {
|
||||
s = (float) Math.sqrt(m22 - (m00 + m11) + 1.0);
|
||||
z = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
x = (m20 + m02) * s;
|
||||
y = (m12 + m21) * s;
|
||||
w = (m10 - m01) * s;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector {
|
||||
/**
|
||||
* @return the length of the vector
|
||||
*/
|
||||
float length();
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
float lengthSquared();
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
Vector store(FloatBuffer buf);
|
||||
}
|
|
@ -0,0 +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.glemu.vector;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector2f extends ReadableVector {
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
float getY();
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector3f extends ReadableVector2f {
|
||||
/**
|
||||
* @return z
|
||||
*/
|
||||
float getZ();
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector4f extends ReadableVector3f {
|
||||
|
||||
/**
|
||||
* @return w
|
||||
*/
|
||||
float getW();
|
||||
|
||||
}
|
110
src/main/java/net/PeytonPlayz585/glemu/vector/Vector.java
Normal file
110
src/main/java/net/PeytonPlayz585/glemu/vector/Vector.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for vectors.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
public abstract class Vector implements Serializable, ReadableVector {
|
||||
|
||||
/**
|
||||
* Constructor for Vector.
|
||||
*/
|
||||
protected Vector() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length of the vector
|
||||
*/
|
||||
public final float length() {
|
||||
return (float) Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public abstract float lengthSquared();
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector load(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector negate();
|
||||
|
||||
/**
|
||||
* Normalise this vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final Vector normalise() {
|
||||
float len = length();
|
||||
if (len != 0.0f) {
|
||||
float l = 1.0f / len;
|
||||
return scale(l);
|
||||
} else
|
||||
throw new IllegalStateException("Zero length vector");
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector store(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Scale this vector
|
||||
*
|
||||
* @param scale The scale factor
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector scale(float scale);
|
||||
|
||||
}
|
319
src/main/java/net/PeytonPlayz585/glemu/vector/Vector2f.java
Normal file
319
src/main/java/net/PeytonPlayz585/glemu/vector/Vector2f.java
Normal file
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 2-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y;
|
||||
|
||||
/**
|
||||
* Constructor for Vector2f.
|
||||
*/
|
||||
public Vector2f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Vector2f(ReadableVector2f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Vector2f(float x, float y) {
|
||||
set(x, y);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector2f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f set(ReadableVector2f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
*
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f translate(float x, float y) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
*
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector2f negate(Vector2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector2f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
*
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector2f normalise(Vector2f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector2f(x / l, y / l);
|
||||
else
|
||||
dest.set(x / l, y / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y +
|
||||
* v1.z * v2.z
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector2f left, Vector2f right) {
|
||||
return left.x * right.x + left.y * right.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
*
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector2f a, Vector2f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.acos(dls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x + right.x, left.y + right.y);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x - right.x, left.y - right.y);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
*
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
|
||||
sb.append("Vector2f[");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
sb.append(y);
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Vector2f other = (Vector2f) obj;
|
||||
|
||||
if (x == other.x && y == other.y)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
376
src/main/java/net/PeytonPlayz585/glemu/vector/Vector3f.java
Normal file
376
src/main/java/net/PeytonPlayz585/glemu/vector/Vector3f.java
Normal file
|
@ -0,0 +1,376 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 3-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Vector3f extends Vector implements Serializable, ReadableVector3f, WritableVector3f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z;
|
||||
|
||||
/**
|
||||
* Constructor for Vector3f.
|
||||
*/
|
||||
public Vector3f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector3f(ReadableVector3f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector3f(float x, float y, float z) {
|
||||
set(x, y, z);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector3f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector3f set(ReadableVector3f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
*
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector3f translate(float x, float y, float z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The cross product of two vectors.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination result, or null if a new vector is to be created
|
||||
* @return left cross right
|
||||
*/
|
||||
public static Vector3f cross(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
|
||||
dest.set(left.y * right.z - left.z * right.y, right.x * left.z - right.z * left.x,
|
||||
left.x * right.y - left.y * right.x);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
*
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector3f negate(Vector3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
dest.z = -z;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
*
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector3f normalise(Vector3f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f(x / l, y / l, z / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y +
|
||||
* v1.z * v2.z
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector3f left, Vector3f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
*
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector3f a, Vector3f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.acos(dls);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
|
||||
sb.append("Vector3f[");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
sb.append(y);
|
||||
sb.append(", ");
|
||||
sb.append(z);
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Vector3f other = (Vector3f) obj;
|
||||
|
||||
if (x == other.x && y == other.y && z == other.z)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
377
src/main/java/net/PeytonPlayz585/glemu/vector/Vector4f.java
Normal file
377
src/main/java/net/PeytonPlayz585/glemu/vector/Vector4f.java
Normal file
|
@ -0,0 +1,377 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 4-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
|
||||
public class Vector4f extends Vector implements Serializable, ReadableVector4f, WritableVector4f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z, w;
|
||||
|
||||
/**
|
||||
* Constructor for Vector4f.
|
||||
*/
|
||||
public Vector4f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector4f(ReadableVector4f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector4f(float x, float y, float z, float w) {
|
||||
set(x, y, z, w);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector4f
|
||||
*
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f set(ReadableVector4f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
w = src.getW();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
*
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f translate(float x, float y, float z, float w) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
this.w += w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
w = -w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
*
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector4f negate(Vector4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector4f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
dest.z = -z;
|
||||
dest.w = -w;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
*
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector4f normalise(Vector4f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector4f(x / l, y / l, z / l, w / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l, w / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y +
|
||||
* v1.z * v2.z + v1.w * v2.w
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector4f left, Vector4f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
*
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector4f a, Vector4f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.acos(dls);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
w *= scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
buf.put(w);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Vector4f: " + x + " " + y + " " + z + " " + w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set W
|
||||
*
|
||||
* @param w
|
||||
*/
|
||||
public void setW(float w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Vector4f other = (Vector4f) obj;
|
||||
|
||||
if (x == other.x && y == other.y && z == other.z && w == other.w)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector2fs
|
||||
*
|
||||
* @author $author$
|
||||
* @version $revision$ $Id$
|
||||
*/
|
||||
public interface WritableVector2f {
|
||||
|
||||
/**
|
||||
* Set the X value
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Set the Y value
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
void setY(float y);
|
||||
|
||||
/**
|
||||
* Set the X,Y values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
void set(float x, float y);
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector3fs
|
||||
*
|
||||
* @author $author$
|
||||
* @version $revision$ $Id$
|
||||
*/
|
||||
public interface WritableVector3f extends WritableVector2f {
|
||||
|
||||
/**
|
||||
* Set the Z value
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
void setZ(float z);
|
||||
|
||||
/**
|
||||
* Set the X,Y,Z values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
void set(float x, float y, float z);
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.PeytonPlayz585.glemu.vector;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector4fs
|
||||
*
|
||||
* @author $author$
|
||||
* @version $revision$ $Id$
|
||||
*/
|
||||
public interface WritableVector4f extends WritableVector3f {
|
||||
|
||||
/**
|
||||
* Set the W value
|
||||
*
|
||||
* @param w
|
||||
*/
|
||||
void setW(float w);
|
||||
|
||||
/**
|
||||
* Set the X,Y,Z,W values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param w
|
||||
*/
|
||||
void set(float x, float y, float z, float w);
|
||||
|
||||
}
|
586
src/main/java/net/PeytonPlayz585/lwjgl/LWJGL.java
Normal file
586
src/main/java/net/PeytonPlayz585/lwjgl/LWJGL.java
Normal file
|
@ -0,0 +1,586 @@
|
|||
package net.PeytonPlayz585.lwjgl;
|
||||
|
||||
import static net.PeytonPlayz585.teavm.WebGL2RenderingContext.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Float32Array;
|
||||
import org.teavm.jso.typedarrays.Int32Array;
|
||||
import org.teavm.jso.typedarrays.Uint8Array;
|
||||
import org.teavm.jso.webgl.WebGLBuffer;
|
||||
import org.teavm.jso.webgl.WebGLFramebuffer;
|
||||
import org.teavm.jso.webgl.WebGLProgram;
|
||||
import org.teavm.jso.webgl.WebGLRenderbuffer;
|
||||
import org.teavm.jso.webgl.WebGLShader;
|
||||
import org.teavm.jso.webgl.WebGLTexture;
|
||||
import org.teavm.jso.webgl.WebGLUniformLocation;
|
||||
|
||||
import net.PeytonPlayz585.main.MinecraftMain;
|
||||
import net.PeytonPlayz585.minecraft.GlStateManager;
|
||||
import net.PeytonPlayz585.minecraft.MinecraftClient;
|
||||
import net.PeytonPlayz585.teavm.WebGL2RenderingContext;
|
||||
import net.PeytonPlayz585.teavm.WebGLQuery;
|
||||
import net.PeytonPlayz585.teavm.WebGLVertexArray;
|
||||
|
||||
public class LWJGL {
|
||||
static WebGL2RenderingContext webgl = null;
|
||||
|
||||
public static final void initWebGL(WebGL2RenderingContext wgl2rc) {
|
||||
webgl = wgl2rc;
|
||||
}
|
||||
|
||||
public static final String _wgetShaderHeader() {
|
||||
return "#version 300 es";
|
||||
}
|
||||
|
||||
public static final class TextureGL {
|
||||
protected final WebGLTexture obj;
|
||||
public int w = -1;
|
||||
public int h = -1;
|
||||
public boolean nearest = true;
|
||||
public boolean anisotropic = false;
|
||||
protected TextureGL(WebGLTexture obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
public static final class BufferGL {
|
||||
protected final WebGLBuffer obj;
|
||||
protected BufferGL(WebGLBuffer obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
public static final class ShaderGL {
|
||||
protected final WebGLShader obj;
|
||||
protected ShaderGL(WebGLShader obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
private static int progId = 0;
|
||||
public static final class ProgramGL {
|
||||
protected final WebGLProgram obj;
|
||||
protected final int hashcode;
|
||||
protected ProgramGL(WebGLProgram obj) {
|
||||
this.obj = obj;
|
||||
this.hashcode = ++progId;
|
||||
}
|
||||
}
|
||||
public static final class UniformGL {
|
||||
protected final WebGLUniformLocation obj;
|
||||
protected UniformGL(WebGLUniformLocation obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
public static final class BufferArrayGL {
|
||||
protected final WebGLVertexArray obj;
|
||||
public boolean isQuadBufferBound;
|
||||
protected BufferArrayGL(WebGLVertexArray obj) {
|
||||
this.obj = obj;
|
||||
this.isQuadBufferBound = false;
|
||||
}
|
||||
}
|
||||
public static final class FramebufferGL {
|
||||
protected final WebGLFramebuffer obj;
|
||||
protected FramebufferGL(WebGLFramebuffer obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
public static final class RenderbufferGL {
|
||||
protected final WebGLRenderbuffer obj;
|
||||
protected RenderbufferGL(WebGLRenderbuffer obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
public static final class QueryGL {
|
||||
protected final WebGLQuery obj;
|
||||
protected QueryGL(WebGLQuery obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void _wglEnable(int p1) {
|
||||
webgl.enable(p1);
|
||||
}
|
||||
public static final void _wglClearDepth(float p1) {
|
||||
webgl.clearDepth(p1);
|
||||
}
|
||||
public static final void _wglDepthFunc(int p1) {
|
||||
webgl.depthFunc(p1);
|
||||
}
|
||||
public static final void _wglCullFace(int p1) {
|
||||
webgl.cullFace(p1);
|
||||
}
|
||||
private static int[] viewportCache = new int[4];
|
||||
public static final void _wglViewport(int p1, int p2, int p3, int p4) {
|
||||
viewportCache[0] = p1; viewportCache[1] = p2;
|
||||
viewportCache[2] = p3; viewportCache[3] = p4;
|
||||
webgl.viewport(p1, p2, p3, p4);
|
||||
}
|
||||
public static final void _wglClear(int p1) {
|
||||
webgl.clear(p1);
|
||||
}
|
||||
public static final void _wglClearColor(float p1, float p2, float p3, float p4) {
|
||||
webgl.clearColor(p1, p2, p3, p4);
|
||||
}
|
||||
public static final void _wglDisable(int p1) {
|
||||
webgl.disable(p1);
|
||||
}
|
||||
public static final int _wglGetError() {
|
||||
return webgl.getError();
|
||||
}
|
||||
public static final void _wglFlush() {
|
||||
//webgl.flush();
|
||||
}
|
||||
private static Uint8Array uploadBuffer = Uint8Array.create(ArrayBuffer.create(4 * 1024 * 1024));
|
||||
public static final void _wglTexImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, ByteBuffer p9) {
|
||||
if(p9 == null) {
|
||||
webgl.texImage2D(p1, p2, p3, p4, p5, p6, p7, p8, null);
|
||||
}else {
|
||||
int len = p9.remaining();
|
||||
Uint8Array uploadBuffer1 = uploadBuffer;
|
||||
for(int i = 0; i < len; ++i) {
|
||||
uploadBuffer1.set(i, (short) ((int)p9.get() & 0xff));
|
||||
}
|
||||
Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len);
|
||||
webgl.texImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data);
|
||||
}
|
||||
}
|
||||
public static final void _wglBlendFunc(int p1, int p2) {
|
||||
webgl.blendFunc(p1, p2);
|
||||
}
|
||||
public static final void _wglDepthMask(boolean p1) {
|
||||
webgl.depthMask(p1);
|
||||
}
|
||||
public static final void _wglColorMask(boolean p1, boolean p2, boolean p3, boolean p4) {
|
||||
webgl.colorMask(p1, p2, p3, p4);
|
||||
}
|
||||
public static final void _wglBindTexture(int p1, TextureGL p2) {
|
||||
webgl.bindTexture(p1, p2 == null ? null : p2.obj);
|
||||
}
|
||||
public static final void _wglCopyTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) {
|
||||
webgl.copyTexSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8);
|
||||
}
|
||||
public static final void _wglTexParameteri(int p1, int p2, int p3) {
|
||||
webgl.texParameteri(p1, p2, p3);
|
||||
}
|
||||
public static final void _wglTexParameterf(int p1, int p2, float p3) {
|
||||
webgl.texParameterf(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) {
|
||||
int len = p9.remaining();
|
||||
Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer());
|
||||
for(int i = 0; i < len; ++i) {
|
||||
deevis.set(i, p9.get());
|
||||
}
|
||||
Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4);
|
||||
webgl.texImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data);
|
||||
}
|
||||
public static final void _wglTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, IntBuffer p9) {
|
||||
int len = p9.remaining();
|
||||
Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer());
|
||||
for(int i = 0; i < len; ++i) {
|
||||
deevis.set(i, p9.get());
|
||||
}
|
||||
Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4);
|
||||
webgl.texSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data);
|
||||
}
|
||||
public static final void _wglDeleteTextures(TextureGL p1) {
|
||||
webgl.deleteTexture(p1.obj);
|
||||
}
|
||||
public static final void _wglDrawArrays(int p1, int p2, int p3) {
|
||||
webgl.drawArrays(p1, p2, p3);
|
||||
}
|
||||
public static final void _wglDrawElements(int p1, int p2, int p3, int p4) {
|
||||
webgl.drawElements(p1, p2, p3, p4);
|
||||
}
|
||||
public static final TextureGL _wglGenTextures() {
|
||||
return new TextureGL(webgl.createTexture());
|
||||
}
|
||||
public static final void _wglTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, ByteBuffer p9) {
|
||||
int len = p9.remaining();
|
||||
for(int i = 0; i < len; ++i) {
|
||||
uploadBuffer.set(i, (short) ((int)p9.get() & 0xff));
|
||||
}
|
||||
Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len);
|
||||
webgl.texSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data);
|
||||
}
|
||||
public static final void _wglActiveTexture(int p1) {
|
||||
webgl.activeTexture(p1);
|
||||
}
|
||||
public static final ProgramGL _wglCreateProgram() {
|
||||
return new ProgramGL(webgl.createProgram());
|
||||
}
|
||||
public static final ShaderGL _wglCreateShader(int p1) {
|
||||
return new ShaderGL(webgl.createShader(p1));
|
||||
}
|
||||
public static final void _wglAttachShader(ProgramGL p1, ShaderGL p2) {
|
||||
webgl.attachShader(p1.obj, p2.obj);
|
||||
}
|
||||
public static final void _wglDetachShader(ProgramGL p1, ShaderGL p2) {
|
||||
webgl.detachShader(p1.obj, p2.obj);
|
||||
}
|
||||
public static final void _wglCompileShader(ShaderGL p1) {
|
||||
webgl.compileShader(p1.obj);
|
||||
}
|
||||
public static final void _wglLinkProgram(ProgramGL p1) {
|
||||
webgl.linkProgram(p1.obj);
|
||||
}
|
||||
public static final void _wglShaderSource(ShaderGL p1, String p2) {
|
||||
webgl.shaderSource(p1.obj, p2);
|
||||
}
|
||||
public static final String _wglGetShaderInfoLog(ShaderGL p1) {
|
||||
return webgl.getShaderInfoLog(p1.obj);
|
||||
}
|
||||
public static final String _wglGetProgramInfoLog(ProgramGL p1) {
|
||||
return webgl.getProgramInfoLog(p1.obj);
|
||||
}
|
||||
public static final boolean _wglGetShaderCompiled(ShaderGL p1) {
|
||||
return webgl.getShaderParameteri(p1.obj, COMPILE_STATUS) == 1;
|
||||
}
|
||||
public static final boolean _wglGetProgramLinked(ProgramGL p1) {
|
||||
return webgl.getProgramParameteri(p1.obj, LINK_STATUS) == 1;
|
||||
}
|
||||
public static final void _wglDeleteShader(ShaderGL p1) {
|
||||
webgl.deleteShader(p1.obj);
|
||||
}
|
||||
public static final void _wglDeleteProgram(ProgramGL p1) {
|
||||
webgl.deleteProgram(p1.obj);
|
||||
}
|
||||
public static final BufferGL _wglCreateBuffer() {
|
||||
return new BufferGL(webgl.createBuffer());
|
||||
}
|
||||
public static final void _wglDeleteBuffer(BufferGL p1) {
|
||||
webgl.deleteBuffer(p1.obj);
|
||||
}
|
||||
public static final void _wglBindBuffer(int p1, BufferGL p2) {
|
||||
webgl.bindBuffer(p1, p2 == null ? null : p2.obj);
|
||||
}
|
||||
public static final void _wglBufferData0(int p1, IntBuffer p2, int p3) {
|
||||
int len = p2.remaining();
|
||||
Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer());
|
||||
for(int i = 0; i < len; ++i) {
|
||||
deevis.set(i, p2.get());
|
||||
}
|
||||
Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4);
|
||||
webgl.bufferData(p1, data, p3);
|
||||
}
|
||||
public static final void _wglBufferSubData0(int p1, int p2, IntBuffer p3) {
|
||||
int len = p3.remaining();
|
||||
Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer());
|
||||
for(int i = 0; i < len; ++i) {
|
||||
deevis.set(i, p3.get());
|
||||
}
|
||||
Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4);
|
||||
webgl.bufferSubData(p1, p2, data);
|
||||
}
|
||||
public static final void _wglBufferData(int p1, Object p2, int p3) {
|
||||
webgl.bufferData(p1, (Int32Array)p2, p3);
|
||||
}
|
||||
public static final void _wglBufferSubData(int p1, int p2, Object p3) {
|
||||
webgl.bufferSubData(p1, p2, (Int32Array)p3);
|
||||
}
|
||||
public static final void _wglBindAttribLocation(ProgramGL p1, int p2, String p3) {
|
||||
webgl.bindAttribLocation(p1.obj, p2, p3);
|
||||
}
|
||||
public static final void _wglEnableVertexAttribArray(int p1) {
|
||||
webgl.enableVertexAttribArray(p1);
|
||||
}
|
||||
public static final void _wglDisableVertexAttribArray(int p1) {
|
||||
webgl.disableVertexAttribArray(p1);
|
||||
}
|
||||
public static final UniformGL _wglGetUniformLocation(ProgramGL p1, String p2) {
|
||||
WebGLUniformLocation u = webgl.getUniformLocation(p1.obj, p2);
|
||||
return u == null ? null : new UniformGL(u);
|
||||
}
|
||||
public static final void _wglBindAttributeLocation(ProgramGL p1, int p2, String p3) {
|
||||
webgl.bindAttribLocation(p1.obj, p2, p3);
|
||||
}
|
||||
public static final void _wglUniform1f(UniformGL p1, float p2) {
|
||||
if(p1 != null) webgl.uniform1f(p1.obj, p2);
|
||||
}
|
||||
public static final void _wglUniform2f(UniformGL p1, float p2, float p3) {
|
||||
if(p1 != null) webgl.uniform2f(p1.obj, p2, p3);
|
||||
}
|
||||
public static final void _wglUniform3f(UniformGL p1, float p2, float p3, float p4) {
|
||||
if(p1 != null) webgl.uniform3f(p1.obj, p2, p3, p4);
|
||||
}
|
||||
public static final void _wglUniform4f(UniformGL p1, float p2, float p3, float p4, float p5) {
|
||||
if(p1 != null) webgl.uniform4f(p1.obj, p2, p3, p4, p5);
|
||||
}
|
||||
public static final void _wglUniform1i(UniformGL p1, int p2) {
|
||||
if(p1 != null) webgl.uniform1i(p1.obj, p2);
|
||||
}
|
||||
public static final void _wglUniform2i(UniformGL p1, int p2, int p3) {
|
||||
if(p1 != null) webgl.uniform2i(p1.obj, p2, p3);
|
||||
}
|
||||
public static final void _wglUniform3i(UniformGL p1, int p2, int p3, int p4) {
|
||||
if(p1 != null) webgl.uniform3i(p1.obj, p2, p3, p4);
|
||||
}
|
||||
public static final void _wglUniform4i(UniformGL p1, int p2, int p3, int p4, int p5) {
|
||||
if(p1 != null) webgl.uniform4i(p1.obj, p2, p3, p4, p5);
|
||||
}
|
||||
private static Float32Array mat2 = Float32Array.create(4);
|
||||
private static Float32Array mat3 = Float32Array.create(9);
|
||||
private static Float32Array mat4 = Float32Array.create(16);
|
||||
public static final void _wglUniformMat2fv(UniformGL p1, float[] mat) {
|
||||
mat2.set(mat);
|
||||
if(p1 != null) webgl.uniformMatrix2fv(p1.obj, false, mat2);
|
||||
}
|
||||
public static final void _wglUniformMat3fv(UniformGL p1, float[] mat) {
|
||||
mat3.set(mat);
|
||||
if(p1 != null) webgl.uniformMatrix3fv(p1.obj, false, mat3);
|
||||
}
|
||||
public static final void _wglUniformMat4fv(UniformGL p1, float[] mat) {
|
||||
mat4.set(mat);
|
||||
if(p1 != null) webgl.uniformMatrix4fv(p1.obj, false, mat4);
|
||||
}
|
||||
private static int currentProgram = -1;
|
||||
public static final void _wglUseProgram(ProgramGL p1) {
|
||||
if(p1 != null && currentProgram != p1.hashcode) {
|
||||
currentProgram = p1.hashcode;
|
||||
webgl.useProgram(p1.obj);
|
||||
}
|
||||
}
|
||||
public static final void _wglGetParameter(int p1, int size, int[] ret) {
|
||||
if(p1 == _wGL_VIEWPORT) {
|
||||
ret[0] = viewportCache[0];
|
||||
ret[1] = viewportCache[1];
|
||||
ret[2] = viewportCache[2];
|
||||
ret[3] = viewportCache[3];
|
||||
}
|
||||
}
|
||||
public static final void _wglPolygonOffset(float p1, float p2) {
|
||||
webgl.polygonOffset(p1, p2);
|
||||
}
|
||||
public static final void _wglVertexAttribPointer(int p1, int p2, int p3, boolean p4, int p5, int p6) {
|
||||
webgl.vertexAttribPointer(p1, p2, p3, p4, p5, p6);
|
||||
}
|
||||
public static final void _wglBindFramebuffer(int p1, FramebufferGL p2) {
|
||||
webgl.bindFramebuffer(p1, p2 == null ? null : p2.obj);
|
||||
}
|
||||
public static final FramebufferGL _wglCreateFramebuffer() {
|
||||
return new FramebufferGL(webgl.createFramebuffer());
|
||||
}
|
||||
public static final void _wglDeleteFramebuffer(FramebufferGL p1) {
|
||||
webgl.deleteFramebuffer(p1.obj);
|
||||
}
|
||||
public static final void _wglFramebufferTexture2D(int p1, TextureGL p2) {
|
||||
webgl.framebufferTexture2D(FRAMEBUFFER, p1, TEXTURE_2D, p2 == null ? null : p2.obj, 0);
|
||||
}
|
||||
public static final QueryGL _wglCreateQuery() {
|
||||
return new QueryGL(webgl.createQuery());
|
||||
}
|
||||
public static final void _wglBeginQuery(int p1, QueryGL p2) {
|
||||
webgl.beginQuery(p1, p2.obj);
|
||||
}
|
||||
public static final void _wglEndQuery(int p1) {
|
||||
webgl.endQuery(p1);
|
||||
}
|
||||
public static final void _wglDeleteQuery(QueryGL p1) {
|
||||
webgl.deleteQuery(p1.obj);
|
||||
}
|
||||
public static final int _wglGetQueryObjecti(QueryGL p1, int p2) {
|
||||
return webgl.getQueryParameter(p1.obj, p2);
|
||||
}
|
||||
public static final BufferArrayGL _wglCreateVertexArray() {
|
||||
return new BufferArrayGL(webgl.createVertexArray());
|
||||
}
|
||||
public static final void _wglDeleteVertexArray(BufferArrayGL p1) {
|
||||
webgl.deleteVertexArray(p1.obj);
|
||||
}
|
||||
public static final void _wglBindVertexArray(BufferArrayGL p1) {
|
||||
webgl.bindVertexArray(p1 == null ? null : p1.obj);
|
||||
}
|
||||
public static final void _wglDrawBuffer(int p1) {
|
||||
webgl.drawBuffers(new int[] { p1 });
|
||||
}
|
||||
public static final RenderbufferGL _wglCreateRenderBuffer() {
|
||||
return new RenderbufferGL(webgl.createRenderbuffer());
|
||||
}
|
||||
public static final void _wglBindRenderbuffer(RenderbufferGL p1) {
|
||||
webgl.bindRenderbuffer(RENDERBUFFER, p1 == null ? null : p1.obj);
|
||||
}
|
||||
public static final void _wglRenderbufferStorage(int p1, int p2, int p3) {
|
||||
webgl.renderbufferStorage(RENDERBUFFER, p1, p2, p3);
|
||||
}
|
||||
public static final void _wglFramebufferRenderbuffer(int p1, RenderbufferGL p2) {
|
||||
webgl.framebufferRenderbuffer(FRAMEBUFFER, p1, RENDERBUFFER, p2 == null ? null : p2.obj);
|
||||
}
|
||||
public static final void _wglDeleteRenderbuffer(RenderbufferGL p1) {
|
||||
webgl.deleteRenderbuffer(p1.obj);
|
||||
}
|
||||
public static final void _wglRenderbufferStorageMultisample(int p1, int p2, int p3, int p4) {
|
||||
webgl.renderbufferStorageMultisample(RENDERBUFFER, p1, p2, p3, p4);
|
||||
}
|
||||
public static final void _wglBlitFramebuffer(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10) {
|
||||
webgl.blitFramebuffer(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||
}
|
||||
public static final int _wglGetAttribLocation(ProgramGL p1, String p2) {
|
||||
return webgl.getAttribLocation(p1.obj, p2);
|
||||
}
|
||||
|
||||
@JSBody(params = { "ctx", "p" }, script = "return ctx.getTexParameter(0x0DE1, p) | 0;")
|
||||
private static final native int __wglGetTexParameteri(WebGL2RenderingContext ctx, int p);
|
||||
public static final int _wglGetTexParameteri(int p1) {
|
||||
return __wglGetTexParameteri(webgl, p1);
|
||||
}
|
||||
@JSBody(params = { "ctx", "p" }, script = "return (0.0 + ctx.getTexParameter(0x0DE1, p));")
|
||||
private static final native float __wglGetTexParameterf(WebGL2RenderingContext ctx, int p);
|
||||
public static final float _wglGetTexParameterf(int p1) {
|
||||
return __wglGetTexParameterf(webgl, p1);
|
||||
}
|
||||
|
||||
public static final int _wArrayByteLength(Object obj) {
|
||||
return ((Int32Array)obj).getByteLength();
|
||||
}
|
||||
|
||||
public static final Object _wCreateLowLevelIntBuffer(int len) {
|
||||
return Int32Array.create(len);
|
||||
}
|
||||
|
||||
private static int appendbufferindex = 0;
|
||||
private static Int32Array appendbuffer = Int32Array.create(ArrayBuffer.create(525000*4));
|
||||
|
||||
public static final void _wAppendLowLevelBuffer(Object arr) {
|
||||
Int32Array a = ((Int32Array)arr);
|
||||
if(appendbufferindex + a.getLength() < appendbuffer.getLength()) {
|
||||
appendbuffer.set(a, appendbufferindex);
|
||||
appendbufferindex += a.getLength();
|
||||
}
|
||||
}
|
||||
|
||||
public static final Object _wGetLowLevelBuffersAppended() {
|
||||
Int32Array ret = Int32Array.create(appendbuffer.getBuffer(), 0, appendbufferindex);
|
||||
appendbufferindex = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@JSBody(params = { "obj" }, script = "if(obj.commit) obj.commit();")
|
||||
private static native int commitContext(JSObject obj);
|
||||
|
||||
public static final void updateDisplay() {
|
||||
commitContext(webgl);
|
||||
MinecraftMain.canvasContext.drawImage(MinecraftMain.canvasBack, 0d, 0d, MinecraftMain.canvas.getWidth(), MinecraftMain.canvas.getHeight());
|
||||
|
||||
int ww = MinecraftMain.canvas.getClientWidth();
|
||||
int hh = MinecraftMain.canvas.getClientHeight();
|
||||
if(ww != MinecraftMain.width || hh != MinecraftMain.height) {
|
||||
MinecraftMain.width = ww;
|
||||
MinecraftMain.height = hh;
|
||||
MinecraftMain.canvasBack.setWidth(ww);
|
||||
MinecraftMain.canvasBack.setHeight(hh);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1l);
|
||||
} catch (InterruptedException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public static final byte[] loadResourceBytes(String path) {
|
||||
return MinecraftClient.getResource(path);
|
||||
}
|
||||
|
||||
public static final String fileContents(String path) {
|
||||
byte[] contents = loadResourceBytes(path);
|
||||
if(contents == null) {
|
||||
return null;
|
||||
}else {
|
||||
return new String(contents, Charset.forName("UTF-8"));
|
||||
}
|
||||
}
|
||||
|
||||
public static final int _wGL_TEXTURE_2D = TEXTURE_2D;
|
||||
public static final int _wGL_DEPTH_TEST = DEPTH_TEST;
|
||||
public static final int _wGL_LEQUAL = LEQUAL;
|
||||
public static final int _wGL_GEQUAL = GEQUAL;
|
||||
public static final int _wGL_GREATER = GREATER;
|
||||
public static final int _wGL_LESS = LESS;
|
||||
public static final int _wGL_BACK = BACK;
|
||||
public static final int _wGL_FRONT = FRONT;
|
||||
public static final int _wGL_FRONT_AND_BACK = FRONT_AND_BACK;
|
||||
public static final int _wGL_COLOR_BUFFER_BIT = COLOR_BUFFER_BIT;
|
||||
public static final int _wGL_DEPTH_BUFFER_BIT = DEPTH_BUFFER_BIT;
|
||||
public static final int _wGL_BLEND = BLEND;
|
||||
public static final int _wGL_RGBA = RGBA;
|
||||
public static final int _wGL_RGB = RGB;
|
||||
public static final int _wGL_RGB8 = RGB8;
|
||||
public static final int _wGL_RGBA8 = RGBA8;
|
||||
public static final int _wGL_UNSIGNED_BYTE = UNSIGNED_BYTE;
|
||||
public static final int _wGL_UNSIGNED_SHORT = UNSIGNED_SHORT;
|
||||
public static final int _wGL_SRC_ALPHA = SRC_ALPHA;
|
||||
public static final int _wGL_ONE_MINUS_SRC_ALPHA = ONE_MINUS_SRC_ALPHA;
|
||||
public static final int _wGL_ONE_MINUS_DST_COLOR = ONE_MINUS_DST_COLOR;
|
||||
public static final int _wGL_ONE_MINUS_SRC_COLOR = ONE_MINUS_SRC_COLOR;
|
||||
public static final int _wGL_ZERO = ZERO;
|
||||
public static final int _wGL_CULL_FACE = CULL_FACE;
|
||||
public static final int _wGL_TEXTURE_MIN_FILTER = TEXTURE_MIN_FILTER;
|
||||
public static final int _wGL_TEXTURE_MAG_FILTER = TEXTURE_MAG_FILTER;
|
||||
public static final int _wGL_LINEAR = LINEAR;
|
||||
public static final int _wGL_EQUAL = EQUAL;
|
||||
public static final int _wGL_SRC_COLOR = SRC_COLOR;
|
||||
public static final int _wGL_ONE = ONE;
|
||||
public static final int _wGL_NEAREST = NEAREST;
|
||||
public static final int _wGL_CLAMP = CLAMP_TO_EDGE;
|
||||
public static final int _wGL_TEXTURE_WRAP_S = TEXTURE_WRAP_S;
|
||||
public static final int _wGL_TEXTURE_WRAP_T = TEXTURE_WRAP_T;
|
||||
public static final int _wGL_REPEAT = REPEAT;
|
||||
public static final int _wGL_DST_COLOR = DST_COLOR;
|
||||
public static final int _wGL_DST_ALPHA = DST_ALPHA;
|
||||
public static final int _wGL_FLOAT = FLOAT;
|
||||
public static final int _wGL_SHORT = SHORT;
|
||||
public static final int _wGL_TRIANGLES = TRIANGLES;
|
||||
public static final int _wGL_TRIANGLE_STRIP = TRIANGLE_STRIP;
|
||||
public static final int _wGL_TRIANGLE_FAN = TRIANGLE_FAN;
|
||||
public static final int _wGL_LINE_STRIP = LINE_STRIP;
|
||||
public static final int _wGL_LINES = LINES;
|
||||
public static final int _wGL_PACK_ALIGNMENT = PACK_ALIGNMENT;
|
||||
public static final int _wGL_UNPACK_ALIGNMENT = UNPACK_ALIGNMENT;
|
||||
public static final int _wGL_TEXTURE0 = TEXTURE0;
|
||||
public static final int _wGL_TEXTURE1 = TEXTURE1;
|
||||
public static final int _wGL_TEXTURE2 = TEXTURE2;
|
||||
public static final int _wGL_TEXTURE3 = TEXTURE3;
|
||||
public static final int _wGL_VIEWPORT = VIEWPORT;
|
||||
public static final int _wGL_VERTEX_SHADER = VERTEX_SHADER;
|
||||
public static final int _wGL_FRAGMENT_SHADER = FRAGMENT_SHADER;
|
||||
public static final int _wGL_ARRAY_BUFFER = ARRAY_BUFFER;
|
||||
public static final int _wGL_ELEMENT_ARRAY_BUFFER = ELEMENT_ARRAY_BUFFER;
|
||||
public static final int _wGL_STATIC_DRAW = STATIC_DRAW;
|
||||
public static final int _wGL_DYNAMIC_DRAW = DYNAMIC_DRAW;
|
||||
public static final int _wGL_INVALID_ENUM = INVALID_ENUM;
|
||||
public static final int _wGL_INVALID_VALUE= INVALID_VALUE;
|
||||
public static final int _wGL_INVALID_OPERATION = INVALID_OPERATION;
|
||||
public static final int _wGL_OUT_OF_MEMORY = OUT_OF_MEMORY;
|
||||
public static final int _wGL_CONTEXT_LOST_WEBGL = CONTEXT_LOST_WEBGL;
|
||||
public static final int _wGL_FRAMEBUFFER_COMPLETE = FRAMEBUFFER_COMPLETE;
|
||||
public static final int _wGL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
||||
public static final int _wGL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
||||
public static final int _wGL_COLOR_ATTACHMENT0 = COLOR_ATTACHMENT0;
|
||||
public static final int _wGL_DEPTH_STENCIL_ATTACHMENT = DEPTH_STENCIL_ATTACHMENT;
|
||||
public static final int _wGL_DEPTH_STENCIL = DEPTH_STENCIL;
|
||||
public static final int _wGL_NEAREST_MIPMAP_LINEAR = NEAREST_MIPMAP_LINEAR;
|
||||
public static final int _wGL_LINEAR_MIPMAP_LINEAR = LINEAR_MIPMAP_LINEAR;
|
||||
public static final int _wGL_LINEAR_MIPMAP_NEAREST = LINEAR_MIPMAP_NEAREST;
|
||||
public static final int _wGL_NEAREST_MIPMAP_NEAREST = NEAREST_MIPMAP_NEAREST;
|
||||
public static final int _wGL_TEXTURE_MAX_LEVEL = TEXTURE_MAX_LEVEL;
|
||||
public static final int _wGL_UNSIGNED_INT_24_8 = UNSIGNED_INT_24_8;
|
||||
public static final int _wGL_UNSIGNED_INT = UNSIGNED_INT;
|
||||
public static final int _wGL_ANY_SAMPLES_PASSED = ANY_SAMPLES_PASSED;
|
||||
public static final int _wGL_QUERY_RESULT = QUERY_RESULT;
|
||||
public static final int _wGL_QUERY_RESULT_AVAILABLE = QUERY_RESULT_AVAILABLE;
|
||||
public static final int _wGL_TEXTURE_MAX_ANISOTROPY = TEXTURE_MAX_ANISOTROPY_EXT;
|
||||
public static final int _wGL_DEPTH24_STENCIL8 = DEPTH24_STENCIL8;
|
||||
public static final int _wGL_DEPTH_COMPONENT32F = DEPTH_COMPONENT32F;
|
||||
public static final int _wGL_DEPTH_ATTACHMENT = DEPTH_ATTACHMENT;
|
||||
public static final int _wGL_MULTISAMPLE = -1;
|
||||
public static final int _wGL_LINE_SMOOTH = -1;
|
||||
public static final int _wGL_READ_FRAMEBUFFER = READ_FRAMEBUFFER;
|
||||
public static final int _wGL_DRAW_FRAMEBUFFER = DRAW_FRAMEBUFFER;
|
||||
public static final int _wGL_FRAMEBUFFER = FRAMEBUFFER;
|
||||
public static final int _wGL_POLYGON_OFFSET_FILL = POLYGON_OFFSET_FILL;
|
||||
}
|
82
src/main/java/net/PeytonPlayz585/lwjgl/LWJGLUtils.java
Normal file
82
src/main/java/net/PeytonPlayz585/lwjgl/LWJGLUtils.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package net.PeytonPlayz585.lwjgl;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.teavm.interop.Async;
|
||||
import org.teavm.interop.AsyncCallback;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.canvas.ImageData;
|
||||
import org.teavm.jso.dom.events.Event;
|
||||
import org.teavm.jso.dom.events.EventListener;
|
||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||
import org.teavm.jso.dom.html.HTMLImageElement;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Uint8Array;
|
||||
import org.teavm.jso.typedarrays.Uint8ClampedArray;
|
||||
|
||||
import net.PeytonPlayz585.main.MinecraftMain;
|
||||
import net.PeytonPlayz585.minecraft.MinecraftImage;
|
||||
|
||||
public class LWJGLUtils extends GL11 {
|
||||
|
||||
public LWJGLUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static final MinecraftImage loadPNG(byte[] data) {
|
||||
ArrayBuffer arr = ArrayBuffer.create(data.length);
|
||||
Uint8Array.create(arr).set(data);
|
||||
return loadPNG0(arr);
|
||||
}
|
||||
|
||||
@Async
|
||||
private static native MinecraftImage loadPNG0(ArrayBuffer data);
|
||||
|
||||
private static void loadPNG0(ArrayBuffer data, final AsyncCallback<MinecraftImage> ret) {
|
||||
final HTMLImageElement toLoad = (HTMLImageElement) MinecraftMain.doc.createElement("img");
|
||||
toLoad.addEventListener("load", new EventListener<Event>() {
|
||||
@Override
|
||||
public void handleEvent(Event evt) {
|
||||
if(MinecraftMain.imageLoadCanvas == null) {
|
||||
MinecraftMain.imageLoadCanvas = (HTMLCanvasElement) MinecraftMain.doc.createElement("canvas");
|
||||
}
|
||||
if(MinecraftMain.imageLoadCanvas.getWidth() < toLoad.getWidth()) {
|
||||
MinecraftMain.imageLoadCanvas.setWidth(toLoad.getWidth());
|
||||
}
|
||||
if(MinecraftMain.imageLoadCanvas.getHeight() < toLoad.getHeight()) {
|
||||
MinecraftMain.imageLoadCanvas.setHeight(toLoad.getHeight());
|
||||
}
|
||||
if(MinecraftMain.imageLoadContext == null) {
|
||||
MinecraftMain.imageLoadContext = (CanvasRenderingContext2D) MinecraftMain.imageLoadCanvas.getContext("2d");
|
||||
}
|
||||
MinecraftMain.imageLoadContext.clearRect(0, 0, toLoad.getWidth(), toLoad.getHeight());
|
||||
MinecraftMain.imageLoadContext.drawImage(toLoad, 0, 0, toLoad.getWidth(), toLoad.getHeight());
|
||||
ImageData pxlsDat = MinecraftMain.imageLoadContext.getImageData(0, 0, toLoad.getWidth(), toLoad.getHeight());
|
||||
Uint8ClampedArray pxls = pxlsDat.getData();
|
||||
int totalPixels = pxlsDat.getWidth() * pxlsDat.getHeight();
|
||||
MinecraftMain.freeDataURL(toLoad.getSrc());
|
||||
if(pxls.getByteLength() < totalPixels * 4) {
|
||||
ret.complete(null);
|
||||
return;
|
||||
}
|
||||
int[] pixels = new int[totalPixels];
|
||||
for(int i = 0; i < pixels.length; ++i) {
|
||||
pixels[i] = (pxls.get(i * 4) << 16) | (pxls.get(i * 4 + 1) << 8) | pxls.get(i * 4 + 2) | (pxls.get(i * 4 + 3) << 24);
|
||||
}
|
||||
ret.complete(new MinecraftImage(pixels, pxlsDat.getWidth(), pxlsDat.getHeight(), true));
|
||||
}
|
||||
});
|
||||
toLoad.addEventListener("error", new EventListener<Event>() {
|
||||
@Override
|
||||
public void handleEvent(Event evt) {
|
||||
MinecraftMain.freeDataURL(toLoad.getSrc());
|
||||
ret.complete(null);
|
||||
}
|
||||
});
|
||||
String src = MinecraftMain.getDataURL(data, "image/png");
|
||||
if(src == null) {
|
||||
ret.complete(null);
|
||||
}else {
|
||||
toLoad.setSrc(src);
|
||||
}
|
||||
}
|
||||
}
|
2417
src/main/java/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.java
Normal file
2417
src/main/java/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.java
Normal file
File diff suppressed because it is too large
Load Diff
140
src/main/java/net/PeytonPlayz585/main/MinecraftMain.java
Normal file
140
src/main/java/net/PeytonPlayz585/main/MinecraftMain.java
Normal file
|
@ -0,0 +1,140 @@
|
|||
package net.PeytonPlayz585.main;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.teavm.interop.Async;
|
||||
import org.teavm.interop.AsyncCallback;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.ajax.ReadyStateChangeHandler;
|
||||
import org.teavm.jso.ajax.XMLHttpRequest;
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||
import org.teavm.jso.dom.html.HTMLDocument;
|
||||
import org.teavm.jso.dom.html.HTMLElement;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.Uint8Array;
|
||||
import org.teavm.jso.webgl.WebGLRenderingContext;
|
||||
|
||||
import net.PeytonPlayz585.minecraft.MinecraftClient;
|
||||
import net.PeytonPlayz585.teavm.WebGL2RenderingContext;
|
||||
|
||||
public class MinecraftMain {
|
||||
|
||||
public static Window win = null;
|
||||
public static HTMLCanvasElement canvas = null;
|
||||
public static HTMLElement rootElement = null;
|
||||
public static WebGL2RenderingContext webgl = null;
|
||||
public static HTMLElement parent = null;
|
||||
public static HTMLDocument doc = null;
|
||||
public static CanvasRenderingContext2D canvasContext = null;
|
||||
public static HTMLCanvasElement canvasBack = null;
|
||||
public static HTMLCanvasElement imageLoadCanvas = null;
|
||||
public static CanvasRenderingContext2D imageLoadContext = null;
|
||||
private static byte[] loadedPackage = null;
|
||||
|
||||
public static int width = 0;
|
||||
public static int height = 0;
|
||||
|
||||
public static void main(String args[]) {
|
||||
String[] element = getClassicConfig();
|
||||
initContext(rootElement = Window.current().getDocument().getElementById(element[0]), element[1]);
|
||||
}
|
||||
|
||||
public final static void initContext(HTMLElement rootElement, String assetsURI) {
|
||||
parent = rootElement;
|
||||
String s = parent.getAttribute("style");
|
||||
parent.setAttribute("style", (s == null ? "" : s)+"overflow-x:hidden;overflow-y:hidden;");
|
||||
win = Window.current();
|
||||
doc = win.getDocument();
|
||||
canvas = (HTMLCanvasElement)doc.createElement("canvas");
|
||||
width = rootElement.getClientWidth();
|
||||
height = rootElement.getClientHeight();
|
||||
canvas.setWidth(width);
|
||||
canvas.setHeight(height);
|
||||
canvasContext = (CanvasRenderingContext2D) canvas.getContext("2d");
|
||||
canvas.setAttribute("id", "minecraftClassicBrowser");
|
||||
rootElement.appendChild(canvas);
|
||||
canvasBack = (HTMLCanvasElement)doc.createElement("canvas");
|
||||
canvasBack.setWidth(width);
|
||||
canvasBack.setHeight(height);
|
||||
webgl = (WebGL2RenderingContext) canvasBack.getContext("webgl2");
|
||||
if(webgl == null) {
|
||||
throw new RuntimeException("WebGL 2.0 is not supported in your browser, please get a new one!");
|
||||
}
|
||||
setCurrentContext(webgl);
|
||||
GL11.initWebGL(webgl);
|
||||
|
||||
webgl.getExtension("EXT_texture_filter_anisotropic");
|
||||
|
||||
downloadAssetPack(assetsURI);
|
||||
|
||||
try {
|
||||
MinecraftClient.install(loadedPackage);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Start Game Function
|
||||
|
||||
}
|
||||
|
||||
@Async
|
||||
public static native String downloadAssetPack(String assetPackageURI);
|
||||
|
||||
private static void downloadAssetPack(String assetPackageURI, final AsyncCallback<String> cb) {
|
||||
final XMLHttpRequest request = XMLHttpRequest.create();
|
||||
request.setResponseType("arraybuffer");
|
||||
request.open("GET", assetPackageURI, true);
|
||||
request.setOnReadyStateChange(new ReadyStateChangeHandler() {
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
if(request.getReadyState() == XMLHttpRequest.DONE) {
|
||||
Uint8Array bl = Uint8Array.create((ArrayBuffer)request.getResponse());
|
||||
loadedPackage = new byte[bl.getByteLength()];
|
||||
for(int i = 0; i < loadedPackage.length; ++i) {
|
||||
loadedPackage[i] = (byte) bl.get(i);
|
||||
}
|
||||
cb.complete("yee");
|
||||
}
|
||||
}
|
||||
});
|
||||
request.send();
|
||||
}
|
||||
|
||||
public static final int getCanvasWidth() {
|
||||
int w = parent.getClientWidth();
|
||||
if(w != width) {
|
||||
canvas.setWidth(w);
|
||||
canvasBack.setWidth(w);
|
||||
width = w;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
public static final int getCanvasHeight() {
|
||||
int h = parent.getClientHeight();
|
||||
if(h != height) {
|
||||
canvas.setHeight(h);
|
||||
canvasBack.setHeight(h);
|
||||
height = h;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
@JSBody(params = { "obj" }, script = "window.currentContext = obj;")
|
||||
private static native int setCurrentContext(JSObject obj);
|
||||
|
||||
@JSBody(params = { }, script = "return window.classicConfig;")
|
||||
public static native String[] getClassicConfig();
|
||||
|
||||
@JSBody(params = { "obj" }, script = "if(obj.commit) obj.commit();")
|
||||
public static native int commitContext(JSObject obj);
|
||||
|
||||
@JSBody(params = { "url" }, script = "URL.revokeObjectURL(url);")
|
||||
public static native void freeDataURL(String url);
|
||||
|
||||
@JSBody(params = { "buf", "mime" }, script = "return URL.createObjectURL(new Blob([buf], {type: mime}));")
|
||||
public static native String getDataURL(ArrayBuffer buf, String mime);
|
||||
}
|
857
src/main/java/net/PeytonPlayz585/minecraft/Base64.java
Normal file
857
src/main/java/net/PeytonPlayz585/minecraft/Base64.java
Normal file
|
@ -0,0 +1,857 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.PeytonPlayz585.minecraft;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Provides Base64 encoding and decoding as defined by
|
||||
* <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>.
|
||||
*
|
||||
* <p>
|
||||
* This class implements section <cite>6.8. Base64
|
||||
* Content-Transfer-Encoding</cite> from RFC 2045 <cite>Multipurpose Internet
|
||||
* Mail Extensions (MIME) Part One: Format of Internet Message Bodies</cite> by
|
||||
* Freed and Borenstein.
|
||||
* </p>
|
||||
* <p>
|
||||
* The class can be parameterized in the following manner with various
|
||||
* constructors:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>URL-safe mode: Default off.</li>
|
||||
* <li>Line length: Default 76. Line length that aren't multiples of 4 will
|
||||
* still essentially end up being multiples of 4 in the encoded data.
|
||||
* <li>Line separator: Default is CRLF ("\r\n")</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The URL-safe parameter is only applied to encode operations. Decoding
|
||||
* seamlessly handles both modes.
|
||||
* </p>
|
||||
* <p>
|
||||
* Since this class operates directly on byte streams, and not character
|
||||
* streams, it is hard-coded to only encode/decode character encodings which are
|
||||
* compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8,
|
||||
* etc).
|
||||
* </p>
|
||||
* <p>
|
||||
* This class is thread-safe.
|
||||
* </p>
|
||||
*
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Base64 extends BaseNCodec {
|
||||
|
||||
/**
|
||||
* BASE32 characters are 6 bits in length. They are formed by taking a block of
|
||||
* 3 octets to form a 24-bit string, which is converted into 4 BASE64
|
||||
* characters.
|
||||
*/
|
||||
private static final int BITS_PER_ENCODED_BYTE = 6;
|
||||
private static final int BYTES_PER_UNENCODED_BLOCK = 3;
|
||||
private static final int BYTES_PER_ENCODED_BLOCK = 4;
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates 6-bit positive integer index
|
||||
* values into their "Base64 Alphabet" equivalents as specified in Table 1 of
|
||||
* RFC 2045.
|
||||
*
|
||||
* Thanks to "commons" project in ws.apache.org for this code.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
*/
|
||||
private static final byte[] STANDARD_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1',
|
||||
'2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
|
||||
|
||||
/**
|
||||
* This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed
|
||||
* to - and _ to make the encoded Base64 results more URL-SAFE. This table is
|
||||
* only used when the Base64's mode is set to URL-SAFE.
|
||||
*/
|
||||
private static final byte[] URL_SAFE_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1',
|
||||
'2', '3', '4', '5', '6', '7', '8', '9', '-', '_' };
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates Unicode characters drawn from
|
||||
* the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit
|
||||
* positive integer equivalents. Characters that are not in the Base64 alphabet
|
||||
* but fall within the bounds of the array are translated to -1.
|
||||
*
|
||||
* Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This
|
||||
* means decoder seamlessly handles both URL_SAFE and STANDARD base64. (The
|
||||
* encoder, on the other hand, needs to know ahead of time what to emit).
|
||||
*
|
||||
* Thanks to "commons" project in ws.apache.org for this code.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
*/
|
||||
private static final byte[] DECODE_TABLE = {
|
||||
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, // 20-2f + - /
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 30-3f 0-9
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 40-4f A-O
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, // 50-5f P-Z _
|
||||
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 60-6f a-o
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 // 70-7a p-z
|
||||
};
|
||||
|
||||
/**
|
||||
* Base64 uses 6-bit fields.
|
||||
*/
|
||||
/** Mask used to extract 6 bits, used when encoding */
|
||||
private static final int MASK_6BITS = 0x3f;
|
||||
/** Mask used to extract 4 bits, used when decoding final trailing character. */
|
||||
private static final int MASK_4BITS = 0xf;
|
||||
/** Mask used to extract 2 bits, used when decoding final trailing character. */
|
||||
private static final int MASK_2BITS = 0x3;
|
||||
|
||||
// The static final fields above are used for the original static byte[] methods
|
||||
// on Base64.
|
||||
// The private member fields below are used with the new streaming approach,
|
||||
// which requires
|
||||
// some state be preserved between calls of encode() and decode().
|
||||
|
||||
/**
|
||||
* Decodes Base64 data into octets.
|
||||
* <p>
|
||||
* <b>Note:</b> this method seamlessly handles data encoded in URL-safe or
|
||||
* normal mode.
|
||||
* </p>
|
||||
*
|
||||
* @param base64Data Byte array containing Base64 data
|
||||
* @return Array containing decoded data.
|
||||
*/
|
||||
public static byte[] decodeBase64(final byte[] base64Data) {
|
||||
return new Base64().decode(base64Data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a Base64 String into octets.
|
||||
* <p>
|
||||
* <b>Note:</b> this method seamlessly handles data encoded in URL-safe or
|
||||
* normal mode.
|
||||
* </p>
|
||||
*
|
||||
* @param base64String String containing Base64 data
|
||||
* @return Array containing decoded data.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] decodeBase64(final String base64String) {
|
||||
return new Base64().decode(base64String);
|
||||
}
|
||||
|
||||
// Implementation of integer encoding used for crypto
|
||||
/**
|
||||
* Decodes a byte64-encoded integer according to crypto standards such as W3C's
|
||||
* XML-Signature.
|
||||
*
|
||||
* @param pArray a byte array containing base64 character data
|
||||
* @return A BigInteger
|
||||
* @since 1.4
|
||||
*/
|
||||
public static BigInteger decodeInteger(final byte[] pArray) {
|
||||
return new BigInteger(1, decodeBase64(pArray));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm but does not chunk the output.
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return byte[] containing Base64 characters in their UTF-8 representation.
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData) {
|
||||
return encodeBase64(binaryData, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm, optionally chunking the
|
||||
* output into 76 character blocks.
|
||||
*
|
||||
* @param binaryData Array containing binary data to encode.
|
||||
* @param isChunked if {@code true} this encoder will chunk the base64 output
|
||||
* into 76 character blocks
|
||||
* @return Base64-encoded data.
|
||||
* @throws IllegalArgumentException Thrown when the input array needs an output
|
||||
* array bigger than {@link Integer#MAX_VALUE}
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked) {
|
||||
return encodeBase64(binaryData, isChunked, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm, optionally chunking the
|
||||
* output into 76 character blocks.
|
||||
*
|
||||
* @param binaryData Array containing binary data to encode.
|
||||
* @param isChunked if {@code true} this encoder will chunk the base64 output
|
||||
* into 76 character blocks
|
||||
* @param urlSafe if {@code true} this encoder will emit - and _ instead of
|
||||
* the usual + and / characters. <b>Note: no padding is added
|
||||
* when encoding using the URL-safe alphabet.</b>
|
||||
* @return Base64-encoded data.
|
||||
* @throws IllegalArgumentException Thrown when the input array needs an output
|
||||
* array bigger than {@link Integer#MAX_VALUE}
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe) {
|
||||
return encodeBase64(binaryData, isChunked, urlSafe, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm, optionally chunking the
|
||||
* output into 76 character blocks.
|
||||
*
|
||||
* @param binaryData Array containing binary data to encode.
|
||||
* @param isChunked if {@code true} this encoder will chunk the base64
|
||||
* output into 76 character blocks
|
||||
* @param urlSafe if {@code true} this encoder will emit - and _ instead
|
||||
* of the usual + and / characters. <b>Note: no padding is
|
||||
* added when encoding using the URL-safe alphabet.</b>
|
||||
* @param maxResultSize The maximum result size to accept.
|
||||
* @return Base64-encoded data.
|
||||
* @throws IllegalArgumentException Thrown when the input array needs an output
|
||||
* array bigger than maxResultSize
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe,
|
||||
final int maxResultSize) {
|
||||
if (binaryData == null || binaryData.length == 0) {
|
||||
return binaryData;
|
||||
}
|
||||
|
||||
// Create this so can use the super-class method
|
||||
// Also ensures that the same roundings are performed by the ctor and the code
|
||||
final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
|
||||
final long len = b64.getEncodedLength(binaryData);
|
||||
if (len > maxResultSize) {
|
||||
throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len
|
||||
+ ") than the specified maximum size of " + maxResultSize);
|
||||
}
|
||||
|
||||
return b64.encode(binaryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm and chunks the encoded output
|
||||
* into 76 character blocks
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return Base64 characters chunked in 76 character blocks
|
||||
*/
|
||||
public static byte[] encodeBase64Chunked(final byte[] binaryData) {
|
||||
return encodeBase64(binaryData, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using the base64 algorithm but does not chunk the output.
|
||||
*
|
||||
* NOTE: We changed the behavior of this method from multi-line chunking
|
||||
* (commons-codec-1.4) to single-line non-chunking (commons-codec-1.5).
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return String containing Base64 characters.
|
||||
* @since 1.4 (NOTE: 1.4 chunked the output, whereas 1.5 does not).
|
||||
*/
|
||||
public static String encodeBase64String(final byte[] binaryData) {
|
||||
return new String(encodeBase64(binaryData, false), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using a URL-safe variation of the base64 algorithm but
|
||||
* does not chunk the output. The url-safe variation emits - and _ instead of +
|
||||
* and / characters. <b>Note: no padding is added.</b>
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return byte[] containing Base64 characters in their UTF-8 representation.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeBase64URLSafe(final byte[] binaryData) {
|
||||
return encodeBase64(binaryData, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes binary data using a URL-safe variation of the base64 algorithm but
|
||||
* does not chunk the output. The url-safe variation emits - and _ instead of +
|
||||
* and / characters. <b>Note: no padding is added.</b>
|
||||
*
|
||||
* @param binaryData binary data to encode
|
||||
* @return String containing Base64 characters
|
||||
* @since 1.4
|
||||
*/
|
||||
public static String encodeBase64URLSafeString(final byte[] binaryData) {
|
||||
return new String(encodeBase64(binaryData, false, true), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes to a byte64-encoded integer according to crypto standards such as
|
||||
* W3C's XML-Signature.
|
||||
*
|
||||
* @param bigInteger a BigInteger
|
||||
* @return A byte array containing base64 character data
|
||||
* @throws NullPointerException if null is passed in
|
||||
* @since 1.4
|
||||
*/
|
||||
public static byte[] encodeInteger(final BigInteger bigInteger) {
|
||||
return encodeBase64(toIntegerBytes(bigInteger), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains only valid characters within
|
||||
* the Base64 alphabet. Currently the method treats whitespace as valid.
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @return {@code true} if all bytes are valid characters in the Base64 alphabet
|
||||
* or if the byte array is empty; {@code false}, otherwise
|
||||
* @deprecated 1.5 Use {@link #isBase64(byte[])}, will be removed in 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isArrayByteBase64(final byte[] arrayOctet) {
|
||||
return isBase64(arrayOctet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the {@code octet} is in the base 64 alphabet.
|
||||
*
|
||||
* @param octet The value to test
|
||||
* @return {@code true} if the value is defined in the the base 64 alphabet,
|
||||
* {@code false} otherwise.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static boolean isBase64(final byte octet) {
|
||||
return octet == PAD_DEFAULT || (octet >= 0 && octet < DECODE_TABLE.length && DECODE_TABLE[octet] != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains only valid characters within
|
||||
* the Base64 alphabet. Currently the method treats whitespace as valid.
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @return {@code true} if all bytes are valid characters in the Base64 alphabet
|
||||
* or if the byte array is empty; {@code false}, otherwise
|
||||
* @since 1.5
|
||||
*/
|
||||
public static boolean isBase64(final byte[] arrayOctet) {
|
||||
for (int i = 0; i < arrayOctet.length; i++) {
|
||||
if (!isBase64(arrayOctet[i]) && !isWhiteSpace(arrayOctet[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given String to see if it contains only valid characters within the
|
||||
* Base64 alphabet. Currently the method treats whitespace as valid.
|
||||
*
|
||||
* @param base64 String to test
|
||||
* @return {@code true} if all characters in the String are valid characters in
|
||||
* the Base64 alphabet or if the String is empty; {@code false},
|
||||
* otherwise
|
||||
* @since 1.5
|
||||
*/
|
||||
public static boolean isBase64(final String base64) {
|
||||
return isBase64(base64.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a byte-array representation of a {@code BigInteger} without sign bit.
|
||||
*
|
||||
* @param bigInt {@code BigInteger} to be converted
|
||||
* @return a byte array representation of the BigInteger parameter
|
||||
*/
|
||||
static byte[] toIntegerBytes(final BigInteger bigInt) {
|
||||
int bitlen = bigInt.bitLength();
|
||||
// round bitlen
|
||||
bitlen = ((bitlen + 7) >> 3) << 3;
|
||||
final byte[] bigBytes = bigInt.toByteArray();
|
||||
|
||||
if (((bigInt.bitLength() % 8) != 0) && (((bigInt.bitLength() / 8) + 1) == (bitlen / 8))) {
|
||||
return bigBytes;
|
||||
}
|
||||
// set up params for copying everything but sign bit
|
||||
int startSrc = 0;
|
||||
int len = bigBytes.length;
|
||||
|
||||
// if bigInt is exactly byte-aligned, just skip signbit in copy
|
||||
if ((bigInt.bitLength() % 8) == 0) {
|
||||
startSrc = 1;
|
||||
len--;
|
||||
}
|
||||
final int startDst = bitlen / 8 - len; // to pad w/ nulls as per spec
|
||||
final byte[] resizedBytes = new byte[bitlen / 8];
|
||||
System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len);
|
||||
return resizedBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode table to use: either STANDARD or URL_SAFE. Note: the DECODE_TABLE
|
||||
* above remains static because it is able to decode both STANDARD and URL_SAFE
|
||||
* streams, but the encodeTable must be a member variable so we can switch
|
||||
* between the two modes.
|
||||
*/
|
||||
private final byte[] encodeTable;
|
||||
|
||||
// Only one decode table currently; keep for consistency with Base32 code
|
||||
private final byte[] decodeTable = DECODE_TABLE;
|
||||
|
||||
/**
|
||||
* Line separator for encoding. Not used when decoding. Only used if lineLength
|
||||
* > 0.
|
||||
*/
|
||||
private final byte[] lineSeparator;
|
||||
|
||||
/**
|
||||
* Convenience variable to help us determine when our buffer is going to run out
|
||||
* of room and needs resizing. {@code decodeSize = 3 + lineSeparator.length;}
|
||||
*/
|
||||
private final int decodeSize;
|
||||
|
||||
/**
|
||||
* Convenience variable to help us determine when our buffer is going to run out
|
||||
* of room and needs resizing. {@code encodeSize = 4 + lineSeparator.length;}
|
||||
*/
|
||||
private final int encodeSize;
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length is 0 (no chunking), and the encoding table is
|
||||
* STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*/
|
||||
public Base64() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in the
|
||||
* given URL-safe mode.
|
||||
* <p>
|
||||
* When encoding the line length is 76, the line separator is CRLF, and the
|
||||
* encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param urlSafe if {@code true}, URL-safe encoding is used. In most cases this
|
||||
* should be set to {@code false}.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final boolean urlSafe) {
|
||||
this(MIME_CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length is given in the constructor, the line separator
|
||||
* is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final int lineLength) {
|
||||
this(lineLength, CHUNK_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length and line separator are given in the
|
||||
* constructor, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @param lineSeparator Each line of encoded data will end with this sequence of
|
||||
* bytes.
|
||||
* @throws IllegalArgumentException Thrown when the provided lineSeparator
|
||||
* included some base64 characters.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final int lineLength, final byte[] lineSeparator) {
|
||||
this(lineLength, lineSeparator, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length and line separator are given in the
|
||||
* constructor, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @param lineSeparator Each line of encoded data will end with this sequence of
|
||||
* bytes.
|
||||
* @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_'
|
||||
* respectively. urlSafe is only applied to encode
|
||||
* operations. Decoding seamlessly handles both modes.
|
||||
* <b>Note: no padding is added when using the URL-safe
|
||||
* alphabet.</b>
|
||||
* @throws IllegalArgumentException Thrown when the {@code lineSeparator}
|
||||
* contains Base64 characters.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe) {
|
||||
this(lineLength, lineSeparator, urlSafe, CodecPolicy.LENIANT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Base64 codec used for decoding (all modes) and encoding in
|
||||
* URL-unsafe mode.
|
||||
* <p>
|
||||
* When encoding the line length and line separator are given in the
|
||||
* constructor, and the encoding table is STANDARD_ENCODE_TABLE.
|
||||
* </p>
|
||||
* <p>
|
||||
* Line lengths that aren't multiples of 4 will still essentially end up being
|
||||
* multiples of 4 in the encoded data.
|
||||
* </p>
|
||||
* <p>
|
||||
* When decoding all variants are supported.
|
||||
* </p>
|
||||
*
|
||||
* @param lineLength Each line of encoded data will be at most of the given
|
||||
* length (rounded down to nearest multiple of 4). If
|
||||
* lineLength <= 0, then the output will not be divided
|
||||
* into lines (chunks). Ignored when decoding.
|
||||
* @param lineSeparator Each line of encoded data will end with this sequence
|
||||
* of bytes.
|
||||
* @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_'
|
||||
* respectively. urlSafe is only applied to encode
|
||||
* operations. Decoding seamlessly handles both modes.
|
||||
* <b>Note: no padding is added when using the URL-safe
|
||||
* alphabet.</b>
|
||||
* @param decodingPolicy The decoding policy.
|
||||
* @throws IllegalArgumentException Thrown when the {@code lineSeparator}
|
||||
* contains Base64 characters.
|
||||
* @since 1.15
|
||||
*/
|
||||
public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe,
|
||||
final CodecPolicy decodingPolicy) {
|
||||
super(BYTES_PER_UNENCODED_BLOCK, BYTES_PER_ENCODED_BLOCK, lineLength,
|
||||
lineSeparator == null ? 0 : lineSeparator.length, PAD_DEFAULT, decodingPolicy);
|
||||
// TODO could be simplified if there is no requirement to reject invalid line
|
||||
// sep when length <=0
|
||||
// @see test case Base64Test.testConstructors()
|
||||
if (lineSeparator != null) {
|
||||
if (containsAlphabetOrPad(lineSeparator)) {
|
||||
final String sep = new String(lineSeparator, Charset.forName("UTF-8"));
|
||||
throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + sep + "]");
|
||||
}
|
||||
if (lineLength > 0) { // null line-sep forces no chunking rather than throwing IAE
|
||||
this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator.length;
|
||||
this.lineSeparator = new byte[lineSeparator.length];
|
||||
System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
|
||||
} else {
|
||||
this.encodeSize = BYTES_PER_ENCODED_BLOCK;
|
||||
this.lineSeparator = null;
|
||||
}
|
||||
} else {
|
||||
this.encodeSize = BYTES_PER_ENCODED_BLOCK;
|
||||
this.lineSeparator = null;
|
||||
}
|
||||
this.decodeSize = this.encodeSize - 1;
|
||||
this.encodeTable = urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE;
|
||||
}
|
||||
|
||||
// Implementation of the Encoder Interface
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Decodes all of the provided data, starting at inPos, for inAvail bytes.
|
||||
* Should be called at least twice: once with the data to decode, and once with
|
||||
* inAvail set to "-1" to alert decoder that EOF has been reached. The "-1" call
|
||||
* is not necessary when decoding, but it doesn't hurt, either.
|
||||
* </p>
|
||||
* <p>
|
||||
* Ignores all non-base64 characters. This is how chunked (e.g. 76 character)
|
||||
* data is handled, since CR and LF are silently ignored, but has implications
|
||||
* for other bytes, too. This method subscribes to the garbage-in, garbage-out
|
||||
* philosophy: it will not check the provided data for validity.
|
||||
* </p>
|
||||
* <p>
|
||||
* Thanks to "commons" project in ws.apache.org for the bitwise operations, and
|
||||
* general approach.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
* </p>
|
||||
*
|
||||
* @param in byte[] array of ascii data to base64 decode.
|
||||
* @param inPos Position to start reading data from.
|
||||
* @param inAvail Amount of bytes available from input for decoding.
|
||||
* @param context the context to be used
|
||||
*/
|
||||
@Override
|
||||
void decode(final byte[] in, int inPos, final int inAvail, final Context context) {
|
||||
if (context.eof) {
|
||||
return;
|
||||
}
|
||||
if (inAvail < 0) {
|
||||
context.eof = true;
|
||||
}
|
||||
for (int i = 0; i < inAvail; i++) {
|
||||
final byte[] buffer = ensureBufferSize(decodeSize, context);
|
||||
final byte b = in[inPos++];
|
||||
if (b == pad) {
|
||||
// We're done.
|
||||
context.eof = true;
|
||||
break;
|
||||
}
|
||||
if (b >= 0 && b < DECODE_TABLE.length) {
|
||||
final int result = DECODE_TABLE[b];
|
||||
if (result >= 0) {
|
||||
context.modulus = (context.modulus + 1) % BYTES_PER_ENCODED_BLOCK;
|
||||
context.ibitWorkArea = (context.ibitWorkArea << BITS_PER_ENCODED_BYTE) + result;
|
||||
if (context.modulus == 0) {
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS);
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
|
||||
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two forms of EOF as far as base64 decoder is concerned: actual
|
||||
// EOF (-1) and first time '=' character is encountered in stream.
|
||||
// This approach makes the '=' padding characters completely optional.
|
||||
if (context.eof && context.modulus != 0) {
|
||||
final byte[] buffer = ensureBufferSize(decodeSize, context);
|
||||
|
||||
// We have some spare bits remaining
|
||||
// Output all whole multiples of 8 bits and ignore the rest
|
||||
switch (context.modulus) {
|
||||
// case 0 : // impossible, as excluded above
|
||||
case 1: // 6 bits - either ignore entirely, or raise an exception
|
||||
validateTrailingCharacter();
|
||||
break;
|
||||
case 2: // 12 bits = 8 + 4
|
||||
validateCharacter(MASK_4BITS, context);
|
||||
context.ibitWorkArea = context.ibitWorkArea >> 4; // dump the extra 4 bits
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
|
||||
break;
|
||||
case 3: // 18 bits = 8 + 8 + 2
|
||||
validateCharacter(MASK_2BITS, context);
|
||||
context.ibitWorkArea = context.ibitWorkArea >> 2; // dump 2 bits
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
|
||||
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Impossible modulus " + context.modulus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Encodes all of the provided data, starting at inPos, for inAvail bytes. Must
|
||||
* be called at least twice: once with the data to encode, and once with inAvail
|
||||
* set to "-1" to alert encoder that EOF has been reached, to flush last
|
||||
* remaining bytes (if not multiple of 3).
|
||||
* </p>
|
||||
* <p>
|
||||
* <b>Note: no padding is added when encoding using the URL-safe alphabet.</b>
|
||||
* </p>
|
||||
* <p>
|
||||
* Thanks to "commons" project in ws.apache.org for the bitwise operations, and
|
||||
* general approach.
|
||||
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
|
||||
* </p>
|
||||
*
|
||||
* @param in byte[] array of binary data to base64 encode.
|
||||
* @param inPos Position to start reading data from.
|
||||
* @param inAvail Amount of bytes available from input for encoding.
|
||||
* @param context the context to be used
|
||||
*/
|
||||
@Override
|
||||
void encode(final byte[] in, int inPos, final int inAvail, final Context context) {
|
||||
if (context.eof) {
|
||||
return;
|
||||
}
|
||||
// inAvail < 0 is how we're informed of EOF in the underlying data we're
|
||||
// encoding.
|
||||
if (inAvail < 0) {
|
||||
context.eof = true;
|
||||
if (0 == context.modulus && lineLength == 0) {
|
||||
return; // no leftovers to process and not using chunking
|
||||
}
|
||||
final byte[] buffer = ensureBufferSize(encodeSize, context);
|
||||
final int savedPos = context.pos;
|
||||
switch (context.modulus) { // 0-2
|
||||
case 0: // nothing to do here
|
||||
break;
|
||||
case 1: // 8 bits = 6 + 2
|
||||
// top 6 bits:
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 2) & MASK_6BITS];
|
||||
// remaining 2:
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 4) & MASK_6BITS];
|
||||
// URL-SAFE skips the padding to further reduce size.
|
||||
if (encodeTable == STANDARD_ENCODE_TABLE) {
|
||||
buffer[context.pos++] = pad;
|
||||
buffer[context.pos++] = pad;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // 16 bits = 6 + 6 + 4
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 10) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 4) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 2) & MASK_6BITS];
|
||||
// URL-SAFE skips the padding to further reduce size.
|
||||
if (encodeTable == STANDARD_ENCODE_TABLE) {
|
||||
buffer[context.pos++] = pad;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Impossible modulus " + context.modulus);
|
||||
}
|
||||
context.currentLinePos += context.pos - savedPos; // keep track of current line position
|
||||
// if currentPos == 0 we are at the start of a line, so don't add CRLF
|
||||
if (lineLength > 0 && context.currentLinePos > 0) {
|
||||
System.arraycopy(lineSeparator, 0, buffer, context.pos, lineSeparator.length);
|
||||
context.pos += lineSeparator.length;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < inAvail; i++) {
|
||||
final byte[] buffer = ensureBufferSize(encodeSize, context);
|
||||
context.modulus = (context.modulus + 1) % BYTES_PER_UNENCODED_BLOCK;
|
||||
int b = in[inPos++];
|
||||
if (b < 0) {
|
||||
b += 256;
|
||||
}
|
||||
context.ibitWorkArea = (context.ibitWorkArea << 8) + b; // BITS_PER_BYTE
|
||||
if (0 == context.modulus) { // 3 bytes = 24 bits = 4 * 6 bits to extract
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 18) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 12) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 6) & MASK_6BITS];
|
||||
buffer[context.pos++] = encodeTable[context.ibitWorkArea & MASK_6BITS];
|
||||
context.currentLinePos += BYTES_PER_ENCODED_BLOCK;
|
||||
if (lineLength > 0 && lineLength <= context.currentLinePos) {
|
||||
System.arraycopy(lineSeparator, 0, buffer, context.pos, lineSeparator.length);
|
||||
context.pos += lineSeparator.length;
|
||||
context.currentLinePos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the {@code octet} is in the Base64 alphabet.
|
||||
*
|
||||
* @param octet The value to test
|
||||
* @return {@code true} if the value is defined in the the Base64 alphabet
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
@Override
|
||||
protected boolean isInAlphabet(final byte octet) {
|
||||
return octet >= 0 && octet < decodeTable.length && decodeTable[octet] != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns our current encode mode. True if we're URL-SAFE, false otherwise.
|
||||
*
|
||||
* @return true if we're in URL-SAFE mode, false otherwise.
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isUrlSafe() {
|
||||
return this.encodeTable == URL_SAFE_ENCODE_TABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether decoding the final trailing character is possible in the
|
||||
* context of the set of possible base 64 values.
|
||||
*
|
||||
* <p>
|
||||
* The character is valid if the lower bits within the provided mask are zero.
|
||||
* This is used to test the final trailing base-64 digit is zero in the bits
|
||||
* that will be discarded.
|
||||
*
|
||||
* @param emptyBitsMask The mask of the lower bits that should be empty
|
||||
* @param context the context to be used
|
||||
*
|
||||
* @throws IllegalArgumentException if the bits being checked contain any
|
||||
* non-zero value
|
||||
*/
|
||||
private void validateCharacter(final int emptyBitsMask, final Context context) {
|
||||
if (isStrictDecoding() && (context.ibitWorkArea & emptyBitsMask) != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Strict decoding: Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible encoding. "
|
||||
+ "Expected the discarded bits from the character to be zero.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether decoding allows an entire final trailing character that
|
||||
* cannot be used for a complete byte.
|
||||
*
|
||||
* @throws IllegalArgumentException if strict decoding is enabled
|
||||
*/
|
||||
private void validateTrailingCharacter() {
|
||||
if (isStrictDecoding()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Strict decoding: Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible encoding. "
|
||||
+ "Decoding requires at least two trailing 6-bit characters to create bytes.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
692
src/main/java/net/PeytonPlayz585/minecraft/BaseNCodec.java
Normal file
692
src/main/java/net/PeytonPlayz585/minecraft/BaseNCodec.java
Normal file
|
@ -0,0 +1,692 @@
|
|||
package net.PeytonPlayz585.minecraft;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class BaseNCodec {
|
||||
|
||||
static enum CodecPolicy {
|
||||
STRICT, LENIANT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds thread context so classes can be thread-safe.
|
||||
*
|
||||
* This class is not itself thread-safe; each thread must allocate its own copy.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
static class Context {
|
||||
|
||||
/**
|
||||
* Place holder for the bytes we're dealing with for our based logic. Bitwise
|
||||
* operations store and extract the encoding or decoding from this variable.
|
||||
*/
|
||||
int ibitWorkArea;
|
||||
|
||||
/**
|
||||
* Place holder for the bytes we're dealing with for our based logic. Bitwise
|
||||
* operations store and extract the encoding or decoding from this variable.
|
||||
*/
|
||||
long lbitWorkArea;
|
||||
|
||||
/**
|
||||
* Buffer for streaming.
|
||||
*/
|
||||
byte[] buffer;
|
||||
|
||||
/**
|
||||
* Position where next character should be written in the buffer.
|
||||
*/
|
||||
int pos;
|
||||
|
||||
/**
|
||||
* Position where next character should be read from the buffer.
|
||||
*/
|
||||
int readPos;
|
||||
|
||||
/**
|
||||
* Boolean flag to indicate the EOF has been reached. Once EOF has been reached,
|
||||
* this object becomes useless, and must be thrown away.
|
||||
*/
|
||||
boolean eof;
|
||||
|
||||
/**
|
||||
* Variable tracks how many characters have been written to the current line.
|
||||
* Only used when encoding. We use it to make sure each encoded line never goes
|
||||
* beyond lineLength (if lineLength > 0).
|
||||
*/
|
||||
int currentLinePos;
|
||||
|
||||
/**
|
||||
* Writes to the buffer only occur after every 3/5 reads when encoding, and
|
||||
* every 4/8 reads when decoding. This variable helps track that.
|
||||
*/
|
||||
int modulus;
|
||||
|
||||
Context() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String useful for debugging (especially within a debugger.)
|
||||
*
|
||||
* @return a String useful for debugging.
|
||||
*/
|
||||
@SuppressWarnings("boxing") // OK to ignore boxing here
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, "
|
||||
+ "modulus=%s, pos=%s, readPos=%s]",
|
||||
this.getClass().getSimpleName(), Arrays.toString(buffer), currentLinePos, eof, ibitWorkArea,
|
||||
lbitWorkArea, modulus, pos, readPos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EOF
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
static final int EOF = -1;
|
||||
|
||||
/**
|
||||
* MIME chunk size per RFC 2045 section 6.8.
|
||||
*
|
||||
* <p>
|
||||
* The {@value} character limit does not count the trailing CRLF, but counts all
|
||||
* other characters, including any equal signs.
|
||||
* </p>
|
||||
*
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 6.8</a>
|
||||
*/
|
||||
public static final int MIME_CHUNK_SIZE = 76;
|
||||
|
||||
/**
|
||||
* PEM chunk size per RFC 1421 section 4.3.2.4.
|
||||
*
|
||||
* <p>
|
||||
* The {@value} character limit does not count the trailing CRLF, but counts all
|
||||
* other characters, including any equal signs.
|
||||
* </p>
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc1421">RFC 1421 section
|
||||
* 4.3.2.4</a>
|
||||
*/
|
||||
public static final int PEM_CHUNK_SIZE = 64;
|
||||
|
||||
private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2;
|
||||
|
||||
/**
|
||||
* Defines the default buffer size - currently {@value} - must be large enough
|
||||
* for at least one encoded block+separator
|
||||
*/
|
||||
private static final int DEFAULT_BUFFER_SIZE = 8192;
|
||||
|
||||
/**
|
||||
* The maximum size buffer to allocate.
|
||||
*
|
||||
* <p>
|
||||
* This is set to the same size used in the JDK {@code java.util.ArrayList}:
|
||||
* </p>
|
||||
* <blockquote> Some VMs reserve some header words in an array. Attempts to
|
||||
* allocate larger arrays may result in OutOfMemoryError: Requested array size
|
||||
* exceeds VM limit. </blockquote>
|
||||
*/
|
||||
private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8;
|
||||
|
||||
/** Mask used to extract 8 bits, used in decoding bytes */
|
||||
protected static final int MASK_8BITS = 0xff;
|
||||
|
||||
/**
|
||||
* Byte used to pad output.
|
||||
*/
|
||||
protected static final byte PAD_DEFAULT = '='; // Allow static access to default
|
||||
|
||||
/**
|
||||
* Chunk separator per RFC 2045 section 2.1.
|
||||
*
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
|
||||
*/
|
||||
static final byte[] CHUNK_SEPARATOR = { '\r', '\n' };
|
||||
|
||||
/**
|
||||
* Compares two {@code int} values numerically treating the values as unsigned.
|
||||
* Taken from JDK 1.8.
|
||||
*
|
||||
* <p>
|
||||
* TODO: Replace with JDK 1.8 Integer::compareUnsigned(int, int).
|
||||
* </p>
|
||||
*
|
||||
* @param x the first {@code int} to compare
|
||||
* @param y the second {@code int} to compare
|
||||
* @return the value {@code 0} if {@code x == y}; a value less than {@code 0} if
|
||||
* {@code x < y} as unsigned values; and a value greater than {@code 0}
|
||||
* if {@code x > y} as unsigned values
|
||||
*/
|
||||
private static int compareUnsigned(final int xx, final int yy) {
|
||||
int x = xx + Integer.MIN_VALUE;
|
||||
int y = yy + Integer.MIN_VALUE;
|
||||
return (x < y) ? -1 : ((x == y) ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a positive capacity at least as large the minimum required capacity.
|
||||
* If the minimum capacity is negative then this throws an OutOfMemoryError as
|
||||
* no array can be allocated.
|
||||
*
|
||||
* @param minCapacity the minimum capacity
|
||||
* @return the capacity
|
||||
* @throws OutOfMemoryError if the {@code minCapacity} is negative
|
||||
*/
|
||||
private static int createPositiveCapacity(final int minCapacity) {
|
||||
if (minCapacity < 0) {
|
||||
// overflow
|
||||
throw new OutOfMemoryError("Unable to allocate array size: " + (minCapacity & 0xffffffffL));
|
||||
}
|
||||
// This is called when we require buffer expansion to a very big array.
|
||||
// Use the conservative maximum buffer size if possible, otherwise the biggest
|
||||
// required.
|
||||
//
|
||||
// Note: In this situation JDK 1.8 java.util.ArrayList returns
|
||||
// Integer.MAX_VALUE.
|
||||
// This excludes some VMs that can exceed MAX_BUFFER_SIZE but not allocate a
|
||||
// full
|
||||
// Integer.MAX_VALUE length array.
|
||||
// The result is that we may have to allocate an array of this size more than
|
||||
// once if
|
||||
// the capacity must be expanded again.
|
||||
return (minCapacity > MAX_BUFFER_SIZE) ? minCapacity : MAX_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a copy of the chunk separator per RFC 2045 section 2.1.
|
||||
*
|
||||
* @return the chunk separator
|
||||
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
|
||||
* @since 1.15
|
||||
*/
|
||||
public static byte[] getChunkSeparator() {
|
||||
return CHUNK_SEPARATOR.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a byte value is whitespace or not. Whitespace is taken to mean:
|
||||
* space, tab, CR, LF
|
||||
*
|
||||
* @param byteToCheck the byte to check
|
||||
* @return true if byte is whitespace, false otherwise
|
||||
*/
|
||||
protected static boolean isWhiteSpace(final byte byteToCheck) {
|
||||
switch (byteToCheck) {
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases our buffer by the {@link #DEFAULT_BUFFER_RESIZE_FACTOR}.
|
||||
*
|
||||
* @param context the context to be used
|
||||
* @param minCapacity the minimum required capacity
|
||||
* @return the resized byte[] buffer
|
||||
* @throws OutOfMemoryError if the {@code minCapacity} is negative
|
||||
*/
|
||||
private static byte[] resizeBuffer(final Context context, final int minCapacity) {
|
||||
// Overflow-conscious code treats the min and new capacity as unsigned.
|
||||
final int oldCapacity = context.buffer.length;
|
||||
int newCapacity = oldCapacity * DEFAULT_BUFFER_RESIZE_FACTOR;
|
||||
if (compareUnsigned(newCapacity, minCapacity) < 0) {
|
||||
newCapacity = minCapacity;
|
||||
}
|
||||
if (compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
|
||||
newCapacity = createPositiveCapacity(minCapacity);
|
||||
}
|
||||
|
||||
final byte[] b = new byte[newCapacity];
|
||||
System.arraycopy(context.buffer, 0, b, 0, context.buffer.length);
|
||||
context.buffer = b;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #pad}. Will be removed in 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
protected final byte PAD = PAD_DEFAULT; // instance variable just in case it needs to vary later
|
||||
|
||||
protected final byte pad; // instance variable just in case it needs to vary later
|
||||
|
||||
/**
|
||||
* Number of bytes in each full block of unencoded data, e.g. 4 for Base64 and 5
|
||||
* for Base32
|
||||
*/
|
||||
private final int unencodedBlockSize;
|
||||
|
||||
/**
|
||||
* Number of bytes in each full block of encoded data, e.g. 3 for Base64 and 8
|
||||
* for Base32
|
||||
*/
|
||||
private final int encodedBlockSize;
|
||||
|
||||
/**
|
||||
* Chunksize for encoding. Not used when decoding. A value of zero or less
|
||||
* implies no chunking of the encoded data. Rounded down to nearest multiple of
|
||||
* encodedBlockSize.
|
||||
*/
|
||||
protected final int lineLength;
|
||||
|
||||
/**
|
||||
* Size of chunk separator. Not used unless {@link #lineLength} > 0.
|
||||
*/
|
||||
private final int chunkSeparatorLength;
|
||||
|
||||
/**
|
||||
* Defines the decoding behavior when the input bytes contain leftover trailing
|
||||
* bits that cannot be created by a valid encoding. These can be bits that are
|
||||
* unused from the final character or entire characters. The default mode is
|
||||
* lenient decoding. Set this to {@code true} to enable strict decoding.
|
||||
* <ul>
|
||||
* <li>Lenient: Any trailing bits are composed into 8-bit bytes where possible.
|
||||
* The remainder are discarded.
|
||||
* <li>Strict: The decoding will raise an {@link IllegalArgumentException} if
|
||||
* trailing bits are not part of a valid encoding. Any unused bits from the
|
||||
* final character must be zero. Impossible counts of entire final characters
|
||||
* are not allowed.
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* When strict decoding is enabled it is expected that the decoded bytes will be
|
||||
* re-encoded to a byte array that matches the original, i.e. no changes occur
|
||||
* on the final character. This requires that the input bytes use the same
|
||||
* padding and alphabet as the encoder.
|
||||
*/
|
||||
private final CodecPolicy decodingPolicy;
|
||||
|
||||
/**
|
||||
* Note {@code lineLength} is rounded down to the nearest multiple of the
|
||||
* encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is
|
||||
* disabled.
|
||||
*
|
||||
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3)
|
||||
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
|
||||
* @param lineLength if > 0, use chunking with a length
|
||||
* {@code lineLength}
|
||||
* @param chunkSeparatorLength the chunk separator length, if relevant
|
||||
*/
|
||||
protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength,
|
||||
final int chunkSeparatorLength) {
|
||||
this(unencodedBlockSize, encodedBlockSize, lineLength, chunkSeparatorLength, PAD_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note {@code lineLength} is rounded down to the nearest multiple of the
|
||||
* encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is
|
||||
* disabled.
|
||||
*
|
||||
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3)
|
||||
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
|
||||
* @param lineLength if > 0, use chunking with a length
|
||||
* {@code lineLength}
|
||||
* @param chunkSeparatorLength the chunk separator length, if relevant
|
||||
* @param pad byte used as padding byte.
|
||||
*/
|
||||
protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength,
|
||||
final int chunkSeparatorLength, final byte pad) {
|
||||
this(unencodedBlockSize, encodedBlockSize, lineLength, chunkSeparatorLength, pad, CodecPolicy.LENIANT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note {@code lineLength} is rounded down to the nearest multiple of the
|
||||
* encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is
|
||||
* disabled.
|
||||
*
|
||||
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3)
|
||||
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
|
||||
* @param lineLength if > 0, use chunking with a length
|
||||
* {@code lineLength}
|
||||
* @param chunkSeparatorLength the chunk separator length, if relevant
|
||||
* @param pad byte used as padding byte.
|
||||
* @param decodingPolicy Decoding policy.
|
||||
* @since 1.15
|
||||
*/
|
||||
protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength,
|
||||
final int chunkSeparatorLength, final byte pad, final CodecPolicy decodingPolicy) {
|
||||
this.unencodedBlockSize = unencodedBlockSize;
|
||||
this.encodedBlockSize = encodedBlockSize;
|
||||
final boolean useChunking = lineLength > 0 && chunkSeparatorLength > 0;
|
||||
this.lineLength = useChunking ? (lineLength / encodedBlockSize) * encodedBlockSize : 0;
|
||||
this.chunkSeparatorLength = chunkSeparatorLength;
|
||||
this.pad = pad;
|
||||
this.decodingPolicy = decodingPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of buffered data available for reading.
|
||||
*
|
||||
* @param context the context to be used
|
||||
* @return The amount of buffered data available for reading.
|
||||
*/
|
||||
int available(final Context context) { // package protected for access from I/O streams
|
||||
return context.buffer != null ? context.pos - context.readPos : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains any characters within the
|
||||
* alphabet or PAD.
|
||||
*
|
||||
* Intended for use in checking line-ending arrays
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @return {@code true} if any byte is a valid character in the alphabet or PAD;
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
protected boolean containsAlphabetOrPad(final byte[] arrayOctet) {
|
||||
if (arrayOctet == null) {
|
||||
return false;
|
||||
}
|
||||
for (final byte element : arrayOctet) {
|
||||
if (pad == element || isInAlphabet(element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a byte[] containing characters in the Base-N alphabet.
|
||||
*
|
||||
* @param pArray A byte array containing Base-N character data
|
||||
* @return a byte array containing binary data
|
||||
*/
|
||||
public byte[] decode(final byte[] pArray) {
|
||||
if (pArray == null || pArray.length == 0) {
|
||||
return pArray;
|
||||
}
|
||||
final Context context = new Context();
|
||||
decode(pArray, 0, pArray.length, context);
|
||||
decode(pArray, 0, EOF, context); // Notify decoder of EOF.
|
||||
final byte[] result = new byte[context.pos];
|
||||
readResults(result, 0, result.length, context);
|
||||
return result;
|
||||
}
|
||||
|
||||
// package protected for access from I/O streams
|
||||
abstract void decode(byte[] pArray, int i, int length, Context context);
|
||||
|
||||
/**
|
||||
* Decodes an Object using the Base-N algorithm. This method is provided in
|
||||
* order to satisfy the requirements of the Decoder interface, and will throw a
|
||||
* DecoderException if the supplied object is not of type byte[] or String.
|
||||
*
|
||||
* @param obj Object to decode
|
||||
* @return An object (of type byte[]) containing the binary data which
|
||||
* corresponds to the byte[] or String supplied.
|
||||
* @throws DecoderException if the parameter supplied is not of type byte[]
|
||||
*/
|
||||
public Object decode(final Object obj) {
|
||||
if (obj instanceof byte[]) {
|
||||
return decode((byte[]) obj);
|
||||
} else if (obj instanceof String) {
|
||||
return decode((String) obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a String containing characters in the Base-N alphabet.
|
||||
*
|
||||
* @param pArray A String containing Base-N character data
|
||||
* @return a byte array containing binary data
|
||||
*/
|
||||
public byte[] decode(final String pArray) {
|
||||
return decode(pArray.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a byte[] containing characters
|
||||
* in the alphabet.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @return A byte array containing only the base N alphabetic character data
|
||||
*/
|
||||
public byte[] encode(final byte[] pArray) {
|
||||
if (pArray == null || pArray.length == 0) {
|
||||
return pArray;
|
||||
}
|
||||
return encode(pArray, 0, pArray.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a byte[] containing characters
|
||||
* in the alphabet.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @param offset initial offset of the subarray.
|
||||
* @param length length of the subarray.
|
||||
* @return A byte array containing only the base N alphabetic character data
|
||||
* @since 1.11
|
||||
*/
|
||||
public byte[] encode(final byte[] pArray, final int offset, final int length) {
|
||||
if (pArray == null || pArray.length == 0) {
|
||||
return pArray;
|
||||
}
|
||||
final Context context = new Context();
|
||||
encode(pArray, offset, length, context);
|
||||
encode(pArray, offset, EOF, context); // Notify encoder of EOF.
|
||||
final byte[] buf = new byte[context.pos - context.readPos];
|
||||
readResults(buf, 0, buf.length, context);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// package protected for access from I/O streams
|
||||
abstract void encode(byte[] pArray, int i, int length, Context context);
|
||||
|
||||
/**
|
||||
* Encodes an Object using the Base-N algorithm. This method is provided in
|
||||
* order to satisfy the requirements of the Encoder interface, and will throw an
|
||||
* EncoderException if the supplied object is not of type byte[].
|
||||
*
|
||||
* @param obj Object to encode
|
||||
* @return An object (of type byte[]) containing the Base-N encoded data which
|
||||
* corresponds to the byte[] supplied.
|
||||
* @throws EncoderException if the parameter supplied is not of type byte[]
|
||||
*/
|
||||
public Object encode(final Object obj) {
|
||||
return encode((byte[]) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a String containing characters
|
||||
* in the appropriate alphabet. Uses UTF8 encoding.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @return String containing only character data in the appropriate alphabet.
|
||||
* @since 1.5 This is a duplicate of {@link #encodeToString(byte[])}; it was
|
||||
* merged during refactoring.
|
||||
*/
|
||||
public String encodeAsString(final byte[] pArray) {
|
||||
return new String(encode(pArray), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a byte[] containing binary data, into a String containing characters
|
||||
* in the Base-N alphabet. Uses UTF8 encoding.
|
||||
*
|
||||
* @param pArray a byte array containing binary data
|
||||
* @return A String containing only Base-N character data
|
||||
*/
|
||||
public String encodeToString(final byte[] pArray) {
|
||||
return new String(encode(pArray), Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the buffer has room for {@code size} bytes
|
||||
*
|
||||
* @param size minimum spare space required
|
||||
* @param context the context to be used
|
||||
* @return the buffer
|
||||
*/
|
||||
protected byte[] ensureBufferSize(final int size, final Context context) {
|
||||
if (context.buffer == null) {
|
||||
context.buffer = new byte[Math.max(size, getDefaultBufferSize())];
|
||||
context.pos = 0;
|
||||
context.readPos = 0;
|
||||
|
||||
// Overflow-conscious:
|
||||
// x + y > z == x + y - z > 0
|
||||
} else if (context.pos + size - context.buffer.length > 0) {
|
||||
return resizeBuffer(context, context.pos + size);
|
||||
}
|
||||
return context.buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the decoding behavior policy.
|
||||
*
|
||||
* <p>
|
||||
* The default is lenient. If the decoding policy is strict, then decoding will
|
||||
* raise an {@link IllegalArgumentException} if trailing bits are not part of a
|
||||
* valid encoding. Decoding will compose trailing bits into 8-bit bytes and
|
||||
* discard the remainder.
|
||||
* </p>
|
||||
*
|
||||
* @return true if using strict decoding
|
||||
* @since 1.15
|
||||
*/
|
||||
public CodecPolicy getCodecPolicy() {
|
||||
return decodingPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default buffer size. Can be overridden.
|
||||
*
|
||||
* @return the default buffer size.
|
||||
*/
|
||||
protected int getDefaultBufferSize() {
|
||||
return DEFAULT_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the amount of space needed to encode the supplied array.
|
||||
*
|
||||
* @param pArray byte[] array which will later be encoded
|
||||
*
|
||||
* @return amount of space needed to encoded the supplied array. Returns a long
|
||||
* since a max-len array will require > Integer.MAX_VALUE
|
||||
*/
|
||||
public long getEncodedLength(final byte[] pArray) {
|
||||
// Calculate non-chunked size - rounded up to allow for padding
|
||||
// cast to long is needed to avoid possibility of overflow
|
||||
long len = ((pArray.length + unencodedBlockSize - 1) / unencodedBlockSize) * (long) encodedBlockSize;
|
||||
if (lineLength > 0) { // We're using chunking
|
||||
// Round up to nearest multiple
|
||||
len += ((len + lineLength - 1) / lineLength) * chunkSeparatorLength;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this object has buffered data for reading.
|
||||
*
|
||||
* @param context the context to be used
|
||||
* @return true if there is data still available for reading.
|
||||
*/
|
||||
boolean hasData(final Context context) { // package protected for access from I/O streams
|
||||
return context.buffer != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the {@code octet} is in the current alphabet. Does not
|
||||
* allow whitespace or pad.
|
||||
*
|
||||
* @param value The value to test
|
||||
*
|
||||
* @return {@code true} if the value is defined in the current alphabet,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
protected abstract boolean isInAlphabet(byte value);
|
||||
|
||||
/**
|
||||
* Tests a given byte array to see if it contains only valid characters within
|
||||
* the alphabet. The method optionally treats whitespace and pad as valid.
|
||||
*
|
||||
* @param arrayOctet byte array to test
|
||||
* @param allowWSPad if {@code true}, then whitespace and PAD are also allowed
|
||||
*
|
||||
* @return {@code true} if all bytes are valid characters in the alphabet or if
|
||||
* the byte array is empty; {@code false}, otherwise
|
||||
*/
|
||||
public boolean isInAlphabet(final byte[] arrayOctet, final boolean allowWSPad) {
|
||||
for (final byte octet : arrayOctet) {
|
||||
if (!isInAlphabet(octet) && (!allowWSPad || (octet != pad) && !isWhiteSpace(octet))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a given String to see if it contains only valid characters within the
|
||||
* alphabet. The method treats whitespace and PAD as valid.
|
||||
*
|
||||
* @param basen String to test
|
||||
* @return {@code true} if all characters in the String are valid characters in
|
||||
* the alphabet or if the String is empty; {@code false}, otherwise
|
||||
* @see #isInAlphabet(byte[], boolean)
|
||||
*/
|
||||
public boolean isInAlphabet(final String basen) {
|
||||
return isInAlphabet(basen.getBytes(Charset.forName("UTF-8")), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if decoding behavior is strict. Decoding will raise an
|
||||
* {@link IllegalArgumentException} if trailing bits are not part of a valid
|
||||
* encoding.
|
||||
*
|
||||
* <p>
|
||||
* The default is false for lenient decoding. Decoding will compose trailing
|
||||
* bits into 8-bit bytes and discard the remainder.
|
||||
* </p>
|
||||
*
|
||||
* @return true if using strict decoding
|
||||
* @since 1.15
|
||||
*/
|
||||
public boolean isStrictDecoding() {
|
||||
return decodingPolicy == CodecPolicy.STRICT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts buffered data into the provided byte[] array, starting at position
|
||||
* bPos, up to a maximum of bAvail bytes. Returns how many bytes were actually
|
||||
* extracted.
|
||||
* <p>
|
||||
* Package protected for access from I/O streams.
|
||||
*
|
||||
* @param b byte[] array to extract the buffered data into.
|
||||
* @param bPos position in byte[] array to start extraction at.
|
||||
* @param bAvail amount of bytes we're allowed to extract. We may extract fewer
|
||||
* (if fewer are available).
|
||||
* @param context the context to be used
|
||||
* @return The number of bytes successfully extracted into the provided byte[]
|
||||
* array.
|
||||
*/
|
||||
int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) {
|
||||
if (context.buffer != null) {
|
||||
final int len = Math.min(available(context), bAvail);
|
||||
System.arraycopy(context.buffer, context.readPos, b, bPos, len);
|
||||
context.readPos += len;
|
||||
if (context.readPos >= context.pos) {
|
||||
context.buffer = null; // so hasData() will return false, and this method can return -1
|
||||
}
|
||||
return len;
|
||||
}
|
||||
return context.eof ? EOF : 0;
|
||||
}
|
||||
}
|
58
src/main/java/net/PeytonPlayz585/minecraft/GLAllocation.java
Normal file
58
src/main/java/net/PeytonPlayz585/minecraft/GLAllocation.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package net.PeytonPlayz585.minecraft;
|
||||
|
||||
import java.nio.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GLAllocation {
|
||||
|
||||
public GLAllocation() {
|
||||
}
|
||||
|
||||
public static synchronized int generateDisplayLists(int i) {
|
||||
int j = GlStateManager.glGenLists(i);
|
||||
displayLists.add(Integer.valueOf(j));
|
||||
displayLists.add(Integer.valueOf(i));
|
||||
return j;
|
||||
}
|
||||
|
||||
public static synchronized void generateTextureNames(IntBuffer intbuffer) {
|
||||
|
||||
for (int i = intbuffer.position(); i < intbuffer.limit(); i++) {
|
||||
int tx = GlStateManager.glGenTextures();
|
||||
intbuffer.put(i, tx);
|
||||
textureNames.add(Integer.valueOf(tx));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static synchronized void deleteTexturesAndDisplayLists() {
|
||||
for (int i = 0; i < displayLists.size(); i += 2) {
|
||||
GlStateManager.glDeleteLists(((Integer) displayLists.get(i)).intValue(),
|
||||
((Integer) displayLists.get(i + 1)).intValue());
|
||||
}
|
||||
|
||||
for (int j = 0; j < textureNames.size(); j++) {
|
||||
GlStateManager.glDeleteTextures(((Integer) textureNames.get(j)).intValue());
|
||||
}
|
||||
|
||||
displayLists.clear();
|
||||
textureNames.clear();
|
||||
}
|
||||
|
||||
public static ByteBuffer createDirectByteBuffer(int par0) {
|
||||
return ByteBuffer.wrap(new byte[par0]).order(ByteOrder.nativeOrder());
|
||||
}
|
||||
|
||||
public static IntBuffer createDirectIntBuffer(int par0) {
|
||||
return IntBuffer.wrap(new int[par0]);
|
||||
}
|
||||
|
||||
public static FloatBuffer createDirectFloatBuffer(int par0) {
|
||||
return FloatBuffer.wrap(new float[par0]);
|
||||
}
|
||||
|
||||
private static List displayLists = new ArrayList();
|
||||
private static List textureNames = new ArrayList();
|
||||
|
||||
}
|
108
src/main/java/net/PeytonPlayz585/minecraft/GeneralDigest.java
Normal file
108
src/main/java/net/PeytonPlayz585/minecraft/GeneralDigest.java
Normal file
|
@ -0,0 +1,108 @@
|
|||
package net.PeytonPlayz585.minecraft;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
1220
src/main/java/net/PeytonPlayz585/minecraft/GlStateManager.java
Normal file
1220
src/main/java/net/PeytonPlayz585/minecraft/GlStateManager.java
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,54 @@
|
|||
package net.PeytonPlayz585.minecraft;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.jcraft.jzlib.InflaterInputStream;
|
||||
|
||||
public class MinecraftClient {
|
||||
private static final HashMap<String, byte[]> filePool = new HashMap();
|
||||
|
||||
public static final void install(byte[] pkg) throws IOException {
|
||||
ByteArrayInputStream in2 = new ByteArrayInputStream(pkg);
|
||||
DataInputStream in = new DataInputStream(in2);
|
||||
byte[] header = new byte[8];
|
||||
in.read(header);
|
||||
if (!"EAGPKG!!".equals(new String(header, Charset.forName("UTF-8"))))
|
||||
throw new IOException("invalid epk file");
|
||||
in.readUTF();
|
||||
in = new DataInputStream(new InflaterInputStream(in2));
|
||||
String s = null;
|
||||
SHA1Digest dg = new SHA1Digest();
|
||||
while ("<file>".equals(s = in.readUTF())) {
|
||||
String path = in.readUTF();
|
||||
byte[] digest = new byte[20];
|
||||
byte[] digest2 = new byte[20];
|
||||
in.read(digest);
|
||||
int len = in.readInt();
|
||||
byte[] file = new byte[len];
|
||||
in.read(file);
|
||||
if (filePool.containsKey(path))
|
||||
continue;
|
||||
dg.update(file, 0, len);
|
||||
dg.doFinal(digest2, 0);
|
||||
if (!Arrays.equals(digest, digest2))
|
||||
throw new IOException("invalid file hash for " + path);
|
||||
filePool.put(path, file);
|
||||
if (!"</file>".equals(in.readUTF()))
|
||||
throw new IOException("invalid epk file");
|
||||
}
|
||||
if (in.available() > 0 || !" end".equals(s))
|
||||
throw new IOException("invalid epk file");
|
||||
}
|
||||
|
||||
public static final byte[] getResource(String path) {
|
||||
if (path.startsWith("/"))
|
||||
path = path.substring(1);
|
||||
return filePool.get(path);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package net.PeytonPlayz585.minecraft;
|
||||
|
||||
public class MinecraftImage {
|
||||
|
||||
public final int[] data;
|
||||
public final int w;
|
||||
public final int h;
|
||||
public final boolean alpha;
|
||||
|
||||
public MinecraftImage(int pw, int ph, boolean palpha) {
|
||||
this.w = pw;
|
||||
this.h = ph;
|
||||
this.alpha = palpha;
|
||||
this.data = new int[pw * ph];
|
||||
}
|
||||
|
||||
public MinecraftImage(int[] pdata, int pw, int ph, boolean palpha) {
|
||||
if (pdata.length != pw * ph) {
|
||||
throw new IllegalArgumentException("array size does not equal image size");
|
||||
}
|
||||
this.w = pw;
|
||||
this.h = ph;
|
||||
this.alpha = palpha;
|
||||
if (!palpha) {
|
||||
for (int i = 0; i < pdata.length; ++i) {
|
||||
pdata[i] = pdata[i] | 0xFF000000;
|
||||
}
|
||||
}
|
||||
this.data = pdata;
|
||||
}
|
||||
|
||||
public MinecraftImage getSubImage(int x, int y, int pw, int ph) {
|
||||
int[] img = new int[pw * ph];
|
||||
for (int i = 0; i < ph; ++i) {
|
||||
System.arraycopy(data, (i + y) * this.w + x, img, i * pw, pw);
|
||||
}
|
||||
return new MinecraftImage(img, pw, ph, alpha);
|
||||
}
|
||||
|
||||
}
|
213
src/main/java/net/PeytonPlayz585/minecraft/SHA1Digest.java
Normal file
213
src/main/java/net/PeytonPlayz585/minecraft/SHA1Digest.java
Normal file
|
@ -0,0 +1,213 @@
|
|||
package net.PeytonPlayz585.minecraft;
|
||||
|
||||
/**
|
||||
* implementation of SHA-1 as outlined in "Handbook of Applied Cryptography",
|
||||
* pages 346 - 349.
|
||||
*
|
||||
* It is interesting to ponder why the, apart from the extra IV, the other
|
||||
* difference here from MD5 is the "endienness" of the word processing!
|
||||
*/
|
||||
public class SHA1Digest extends GeneralDigest {
|
||||
private static final int DIGEST_LENGTH = 20;
|
||||
|
||||
private int H1, H2, H3, H4, H5;
|
||||
|
||||
private int[] X = new int[80];
|
||||
private int xOff;
|
||||
|
||||
/**
|
||||
* Standard constructor
|
||||
*/
|
||||
public SHA1Digest() {
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor. This will copy the state of the provided message digest.
|
||||
*/
|
||||
public SHA1Digest(SHA1Digest t) {
|
||||
super(t);
|
||||
|
||||
H1 = t.H1;
|
||||
H2 = t.H2;
|
||||
H3 = t.H3;
|
||||
H4 = t.H4;
|
||||
H5 = t.H5;
|
||||
|
||||
System.arraycopy(t.X, 0, X, 0, t.X.length);
|
||||
xOff = t.xOff;
|
||||
}
|
||||
|
||||
public String getAlgorithmName() {
|
||||
return "SHA-1";
|
||||
}
|
||||
|
||||
public int getDigestSize() {
|
||||
return DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
protected void processWord(byte[] in, int inOff) {
|
||||
X[xOff++] = ((in[inOff] & 0xff) << 24) | ((in[inOff + 1] & 0xff) << 16) | ((in[inOff + 2] & 0xff) << 8)
|
||||
| ((in[inOff + 3] & 0xff));
|
||||
|
||||
if (xOff == 16) {
|
||||
processBlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackWord(int word, byte[] out, int outOff) {
|
||||
out[outOff] = (byte) (word >>> 24);
|
||||
out[outOff + 1] = (byte) (word >>> 16);
|
||||
out[outOff + 2] = (byte) (word >>> 8);
|
||||
out[outOff + 3] = (byte) word;
|
||||
}
|
||||
|
||||
protected void processLength(long bitLength) {
|
||||
if (xOff > 14) {
|
||||
processBlock();
|
||||
}
|
||||
|
||||
X[14] = (int) (bitLength >>> 32);
|
||||
X[15] = (int) (bitLength & 0xffffffff);
|
||||
}
|
||||
|
||||
public int doFinal(byte[] out, int outOff) {
|
||||
finish();
|
||||
|
||||
unpackWord(H1, out, outOff);
|
||||
unpackWord(H2, out, outOff + 4);
|
||||
unpackWord(H3, out, outOff + 8);
|
||||
unpackWord(H4, out, outOff + 12);
|
||||
unpackWord(H5, out, outOff + 16);
|
||||
|
||||
reset();
|
||||
|
||||
return DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* reset the chaining variables
|
||||
*/
|
||||
public void reset() {
|
||||
super.reset();
|
||||
|
||||
H1 = 0x67452301;
|
||||
H2 = 0xefcdab89;
|
||||
H3 = 0x98badcfe;
|
||||
H4 = 0x10325476;
|
||||
H5 = 0xc3d2e1f0;
|
||||
|
||||
xOff = 0;
|
||||
for (int i = 0; i != X.length; i++) {
|
||||
X[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Additive constants
|
||||
//
|
||||
private static final int Y1 = 0x5a827999;
|
||||
private static final int Y2 = 0x6ed9eba1;
|
||||
private static final int Y3 = 0x8f1bbcdc;
|
||||
private static final int Y4 = 0xca62c1d6;
|
||||
|
||||
private int f(int u, int v, int w) {
|
||||
return ((u & v) | ((~u) & w));
|
||||
}
|
||||
|
||||
private int h(int u, int v, int w) {
|
||||
return (u ^ v ^ w);
|
||||
}
|
||||
|
||||
private int g(int u, int v, int w) {
|
||||
return ((u & v) | (u & w) | (v & w));
|
||||
}
|
||||
|
||||
private int rotateLeft(int x, int n) {
|
||||
return (x << n) | (x >>> (32 - n));
|
||||
}
|
||||
|
||||
protected void processBlock() {
|
||||
//
|
||||
// expand 16 word block into 80 word block.
|
||||
//
|
||||
for (int i = 16; i <= 79; i++) {
|
||||
X[i] = rotateLeft((X[i - 3] ^ X[i - 8] ^ X[i - 14] ^ X[i - 16]), 1);
|
||||
}
|
||||
|
||||
//
|
||||
// set up working variables.
|
||||
//
|
||||
int A = H1;
|
||||
int B = H2;
|
||||
int C = H3;
|
||||
int D = H4;
|
||||
int E = H5;
|
||||
|
||||
//
|
||||
// round 1
|
||||
//
|
||||
for (int j = 0; j <= 19; j++) {
|
||||
int t = rotateLeft(A, 5) + f(B, C, D) + E + X[j] + Y1;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
//
|
||||
// round 2
|
||||
//
|
||||
for (int j = 20; j <= 39; j++) {
|
||||
int t = rotateLeft(A, 5) + h(B, C, D) + E + X[j] + Y2;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
//
|
||||
// round 3
|
||||
//
|
||||
for (int j = 40; j <= 59; j++) {
|
||||
int t = rotateLeft(A, 5) + g(B, C, D) + E + X[j] + Y3;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
//
|
||||
// round 4
|
||||
//
|
||||
for (int j = 60; j <= 79; j++) {
|
||||
int t = rotateLeft(A, 5) + h(B, C, D) + E + X[j] + Y4;
|
||||
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotateLeft(B, 30);
|
||||
B = A;
|
||||
A = t;
|
||||
}
|
||||
|
||||
H1 += A;
|
||||
H2 += B;
|
||||
H3 += C;
|
||||
H4 += D;
|
||||
H5 += E;
|
||||
|
||||
//
|
||||
// reset the offset and clean out the word buffer.
|
||||
//
|
||||
xOff = 0;
|
||||
for (int i = 0; i != X.length; i++) {
|
||||
X[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package net.PeytonPlayz585.teavm;
|
||||
|
||||
import org.teavm.jso.webgl.WebGLRenderingContext;
|
||||
|
||||
public interface WebGL2RenderingContext extends WebGLRenderingContext {
|
||||
|
||||
int TEXTURE_MAX_LEVEL = 0x0000813D;
|
||||
int TEXTURE_MAX_ANISOTROPY_EXT = 0x000084FE;
|
||||
int UNSIGNED_INT_24_8 = 0x000084FA;
|
||||
int ANY_SAMPLES_PASSED = 0x00008D6A;
|
||||
int QUERY_RESULT = 0x00008866;
|
||||
int QUERY_RESULT_AVAILABLE = 0x00008867;
|
||||
int DEPTH24_STENCIL8 = 0x000088F0;
|
||||
int DEPTH_COMPONENT32F = 0x00008CAC;
|
||||
int READ_FRAMEBUFFER = 0x00008CA8;
|
||||
int DRAW_FRAMEBUFFER = 0x00008CA9;
|
||||
int RGB8 = 0x00008051;
|
||||
int RGBA8 = 0x00008058;
|
||||
|
||||
WebGLQuery createQuery();
|
||||
|
||||
void beginQuery(int p1, WebGLQuery obj);
|
||||
|
||||
void endQuery(int p1);
|
||||
|
||||
void deleteQuery(WebGLQuery obj);
|
||||
|
||||
int getQueryParameter(WebGLQuery obj, int p2);
|
||||
|
||||
WebGLVertexArray createVertexArray();
|
||||
|
||||
void deleteVertexArray(WebGLVertexArray obj);
|
||||
|
||||
void bindVertexArray(WebGLVertexArray obj);
|
||||
|
||||
void renderbufferStorageMultisample(int p1, int p2, int p3, int p4, int p5);
|
||||
|
||||
void blitFramebuffer(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10);
|
||||
|
||||
void drawBuffers(int[] p1);
|
||||
|
||||
}
|
6
src/main/java/net/PeytonPlayz585/teavm/WebGLQuery.java
Normal file
6
src/main/java/net/PeytonPlayz585/teavm/WebGLQuery.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package net.PeytonPlayz585.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
public interface WebGLQuery extends JSObject {
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package net.PeytonPlayz585.teavm;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
public interface WebGLVertexArray extends JSObject {
|
||||
}
|
7
src/main/java/org/lwjgl/opengl/GL11.java
Normal file
7
src/main/java/org/lwjgl/opengl/GL11.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package org.lwjgl.opengl;
|
||||
|
||||
import net.PeytonPlayz585.minecraft.GlStateManager;
|
||||
|
||||
public class GL11 extends GlStateManager {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user