diff --git a/.classpath b/.classpath
deleted file mode 100644
index 85d2273f..00000000
--- a/.classpath
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 00000000..dd84ea78
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,38 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Desktop (please complete the following information):**
+ - OS: [e.g. iOS]
+ - Browser [e.g. chrome, safari]
+ - Version [e.g. 22]
+
+**Smartphone (please complete the following information):**
+ - Device: [e.g. iPhone6]
+ - OS: [e.g. iOS8.1]
+ - Browser [e.g. stock browser, safari]
+ - Version [e.g. 22]
+
+**Additional context**
+Add any other context about the problem here.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 00000000..bbcbbe7d
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,20 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 00000000..0fd12408
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,49 @@
+name: "CodeQL"
+
+on:
+ schedule:
+ - cron: '33 23 * * 0-6'
+
+jobs:
+ analyse:
+ name: Analyse
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ with:
+ # We must fetch at least the immediate parents so that if this is
+ # a pull request then we can checkout the head.
+ fetch-depth: 2
+
+ # If this run was triggered by a pull request event, then checkout
+ # the head of the pull request instead of the merge commit.
+ - run: git checkout HEAD^2
+ if: ${{ github.event_name == 'pull_request' }}
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v1
+ # Override language selection by uncommenting this and choosing your languages
+ # with:
+ # languages: go, javascript, csharp, python, cpp, java
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v1
+
+ # âšī¸ Command-line programs to run using the OS shell.
+ # đ https://git.io/JvXDl
+
+ # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v1
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
new file mode 100644
index 00000000..a1a9cd1f
--- /dev/null
+++ b/.github/workflows/gradle.yml
@@ -0,0 +1,30 @@
+# This workflow will build a Java project with Gradle
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
+
+name: Java CI with Gradle
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK 17
+ uses: actions/setup-java@v1
+ with:
+ java-version: 17
+ - name: Grant execute permission for gradlew
+ run: chmod +x gradlew
+ - name: Build with Gradle
+ run: ./gradlew build
+ - uses: actions/upload-artifact@v2
+ with:
+ name: CraftGame
+ path: build/libs/CraftGame.jar
diff --git a/.gitignore b/.gitignore
index c75f3c2c..4e39946d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,22 @@
# Ignore Gradle build output directory
build
+
+bin
+
+# Ignore working directory and debug output
+output
+log
+
+.idea
+
+.vscode
+.VSCodeCounter
+
+.settings
+.classpath
+.project
+
+# Ignore my temporary directory and game working directory
+.craftgame
+EasingsAnim
diff --git a/.project b/.project
deleted file mode 100644
index e9063b21..00000000
--- a/.project
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- CraftGame
-
-
-
- org.eclipse.jdt.core.javanature
- org.eclipse.buildship.core.gradleprojectnature
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
- org.eclipse.buildship.core.gradleprojectbuilder
-
-
-
-
-
-
diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs
deleted file mode 100644
index 408b507c..00000000
--- a/.settings/org.eclipse.buildship.core.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-connection.project.dir=
-eclipse.preferences.version=1
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index 1f887b61..00000000
--- a/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-eclipse.preferences.version=1
-encoding//src/main/java=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index c95baf6d..00000000
--- a/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,13 +0,0 @@
-#
-#Sat Mar 07 16:18:37 CST 2020
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.source=1.8
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..0ad25db4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,661 @@
+ GNU AFFERO GENERAL PUBLIC LICENSE
+ Version 3, 19 November 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+ A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate. Many developers of free software are heartened and
+encouraged by the resulting cooperation. However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+ The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community. It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server. Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+ An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals. This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU Affero General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Remote Network Interaction; Use with the GNU General Public License.
+
+ Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software. This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source. For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code. There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+.
diff --git a/README.md b/README.md
index 52f7204d..bfa612fd 100644
--- a/README.md
+++ b/README.md
@@ -1,28 +1,47 @@
-# CraftGame
-a minecraft-like game programmed in Java with LWJGL 2.
-The game is in beta now. So if you have some suggestion, just leave in the comment.
-****
-
-#### How to build and run
-
-* Windows
-
-To build, just type
-> gradlew.bat build
-
-then
-> gradlew.bat run
-
-There you go!
-
-* Linux && MacOS
-
-Pretty easy too! Just type
-> ./gradlew build
-
-and then
-> ./gradlew run
-
-There you go!
-
-# Have fun!
+
+
+This is a fork of LovelyZeeiam/CraftGame, however, (s)he'd deleted it before I detached this fork with its maintenance changed temporarily :-(. And this fork is detached now, but can be attached to LovelyZeeiam's upstream again if (s)he wants(and I'll undo the maintenance change).
+
+# Minecraft-Classic-Remake
+
+The goal is to make a "Minecraft PE 0.10.5 Remake" programmed in Java 17 with LWJGL 3. Currently, the game is being refactored and cannot be played. But when the game is done, there will be a skeleton summary of this project.
+
+## Current Job
+
+* Implement the terrain generation of Minecraft PE 0.1.0.
+
+## The goal
+
+- [ ] All blocks that are in Minecraft PE 0.10.5
+- [ ] Implement a simple world using terrain generation including default world and simple biomes like Minecraft.
+- [ ] Implement Survival Mode as default.
+- [ ] Day-night Circle.
+- [ ] Animals and monsters.
+
+## How to Test the Game
+
+First install Java 17, and...
+
+#### Windows
+
+> gradlew.bat run
+
+
+#### Linux && MacOS
+
+I have no computer running MacOS, but I got a dual system, Windows and Ubuntu.
+I'm convinced that it is able to run by typing the following 3 commands.
+
+> chmod +x gradlew
+>
+> ./gradlew build
+>
+> ./gradlew run
+
+#### GraalVM Native Image
+
+The programmer has tried build native image for the game but it failed.
+
+# Have fun!
+
+
diff --git a/bin/.gitignore b/bin/.gitignore
deleted file mode 100644
index 827c9503..00000000
--- a/bin/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/xueLi/
-/default/
-/main/
diff --git a/build.gradle b/build.gradle
index cf392544..55ade669 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,37 +5,167 @@
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.0/userguide/tutorial_java_projects.html
*/
-
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application.
id 'application'
+
+ // id 'org.lwjgl.plugin' version '0.0.34'
+ id 'com.google.osdetector' version '1.7.1'
+ // id 'org.graalvm.buildtools.native' version '0.9.12'
+
+}
+
+application {
+ // Define the main class for the application.
+ mainClassName = 'xueli.mcremake.client.CraftGameMain'
+
+ // For building Swing application
+ // mainClassName = 'xueli.clock.ClockFrame'
+ // applicationDefaultJvmArgs = [
+ // '-agentlib:native-image-agent=config-merge-dir=build/agent-info/'
+ // ]
+
+}
+
+compileJava {
+ options.release = 17
+ options.encoding = "UTF-8"
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
- jcenter()
+
+ maven { url "https://maven.aliyun.com/repository/central" }
+ maven { url "https://maven.aliyun.com/repository/jcenter" }
+
+ mavenCentral()
+
+ maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
+ maven { url "https://oss.sonatype.org/content/repositories/releases/" }
+
+}
+
+ext {
+ currentPlatform = getCurrentPlatform()
+ lwjgl_version = '3.3.1'
+ nativeImageDirName = "native-image-$currentPlatform"
}
dependencies {
- compile fileTree(dir:'libs/lwjgl',include:['*.jar'])
+ testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
+
+ implementation 'com.google.code.gson:gson:2.8.6'
+
+ implementation 'org.fusesource.jansi:jansi:2.3.4'
+
+ implementation group: 'org.lwjgl', name: 'lwjgl', version: lwjgl_version, changing: true
+ implementation group: 'org.lwjgl', name: 'lwjgl', version: lwjgl_version, changing: true, classifier: 'natives-windows'
+ implementation group: 'org.lwjgl', name: 'lwjgl', version: lwjgl_version, changing: true, classifier: 'natives-linux'
+ implementation group: 'org.lwjgl', name: 'lwjgl', version: lwjgl_version, changing: true, classifier: 'natives-macos'
+
+ implementation group: 'org.lwjgl', name: 'lwjgl-glfw', version: lwjgl_version, changing: true
+ implementation group: 'org.lwjgl', name: 'lwjgl-glfw', version: lwjgl_version, changing: true, classifier: 'natives-windows'
+ implementation group: 'org.lwjgl', name: 'lwjgl-glfw', version: lwjgl_version, changing: true, classifier: 'natives-linux'
+ implementation group: 'org.lwjgl', name: 'lwjgl-glfw', version: lwjgl_version, changing: true, classifier: 'natives-macos'
+
+ implementation group: 'org.lwjgl', name: 'lwjgl-opengl', version: lwjgl_version, changing: true
+ implementation group: 'org.lwjgl', name: 'lwjgl-opengl', version: lwjgl_version, changing: true, classifier: 'natives-windows'
+ implementation group: 'org.lwjgl', name: 'lwjgl-opengl', version: lwjgl_version, changing: true, classifier: 'natives-linux'
+ implementation group: 'org.lwjgl', name: 'lwjgl-opengl', version: lwjgl_version, changing: true, classifier: 'natives-macos'
+
+ implementation group: 'org.lwjgl', name: 'lwjgl-openal', version: lwjgl_version, changing: true
+ implementation group: 'org.lwjgl', name: 'lwjgl-openal', version: lwjgl_version, changing: true, classifier: 'natives-windows'
+ implementation group: 'org.lwjgl', name: 'lwjgl-openal', version: lwjgl_version, changing: true, classifier: 'natives-macos'
+ implementation group: 'org.lwjgl', name: 'lwjgl-openal', version: lwjgl_version, changing: true, classifier: 'natives-linux'
+
+ implementation group: 'org.lwjgl', name: 'lwjgl-nanovg', version: lwjgl_version, changing: true
+ implementation group: 'org.lwjgl', name: 'lwjgl-nanovg', version: lwjgl_version, changing: true, classifier: 'natives-windows'
+ implementation group: 'org.lwjgl', name: 'lwjgl-nanovg', version: lwjgl_version, changing: true, classifier: 'natives-linux'
+ implementation group: 'org.lwjgl', name: 'lwjgl-nanovg', version: lwjgl_version, changing: true, classifier: 'natives-macos'
+
+ // implementation group: 'org.lwjgl', name: 'lwjgl-stb', version: lwjgl_version, changing: true
+ // implementation group: 'org.lwjgl', name: 'lwjgl-stb', version: lwjgl_version, changing: true, classifier: 'natives-windows'
+ // implementation group: 'org.lwjgl', name: 'lwjgl-stb', version: lwjgl_version, changing: true, classifier: 'natives-linux'
+ // implementation group: 'org.lwjgl', name: 'lwjgl-stb', version: lwjgl_version, changing: true, classifier: 'natives-macos'
+
+ implementation group: 'org.iq80.leveldb', name: 'leveldb', version: '0.12'
+ implementation group: 'org.iq80.snappy', name: 'snappy', version: '0.4'
+ implementation 'com.flowpowered:flow-nbt:1.0.0'
+
+ implementation 'io.netty:netty-all:4.1.82.Final'
+
+ implementation 'com.formdev:flatlaf:1.5'
+ // implementation group: 'com.github.oshi', name: 'oshi-core', version: '6.4.0'
+
+ // implementation 'org.jsoup:jsoup:1.16.1'
+
+// implementation group: 'net.java.dev.jna', name: 'jna', version: '5.13.0'
+// implementation group: 'net.java.dev.jna', name: 'jna-platform', version: '5.13.0'
- // This dependency is used by the application.
- implementation 'com.google.guava:guava:28.0-jre'
- implementation 'com.google.code.gson:gson:2.6.2'
- // Use JUnit test framework
- testImplementation 'junit:junit:4.12'
}
-application {
- // Define the main class for the application.
- apply plugin: 'application'
- mainClassName = 'xueLi.craftGame.Main'
- applicationDefaultJvmArgs = [
- '-Djava.library.path="libs/lwjgl/natives"']
+jar {
+ manifest {
+ attributes 'Implementation-Title': 'CraftGame',
+ 'Implementation-Version': "WorldAlpha-${releaseTime()}"
+ }
+
+}
+
+// graalvmNative {
+// binaries.all {
+// resources.autodetect()
+// buildArgs.add('--initialize-at-build-time=org.slf4j.LoggerFactory')
+ // buildArgs.add('--initialize-at-run-time=org.lwjgl')
+ // buildArgs.add('--initialize-at-build-time=sun.awt.Toolkit')
+ // buildArgs.add('--initialize-at-build-time=java.awt.Toolkit')
+
+ // buildArgs.add('--no-fallback')
+ // buildArgs.add('--allow-incomplete-classpath')
+ // buildArgs.add('-H:+AddAllCharsets')
+ // buildArgs.add('-H:+ReportExceptionStackTraces')
+ // buildArgs.add('-H:ConfigurationFileDirectories=build/agent-info')
+
+ // buildArgs.add('--native-image-info')
+ // buildArgs.add('--verbose')
+
+// }
+// toolchainDetection = false
+// }
+
+// === Functions and Tasks ===
+def releaseTime() {
+ return new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08:00"))
}
+
+def getCurrentPlatform() {
+ def os = osdetector.os
+ def lwjglOS = os == 'linux' ? 'linux' :
+ os == 'osx' ? 'macos' :
+ os == 'windows' ? 'windows' :
+ 'unknown'
+ if (lwjglOS == 'unknown')
+ throw new GradleException('Unsupported OS: ' + os)
+
+ def arch = osdetector.arch
+ //consider 64-bit architectures only
+ def lwjglArch = arch == 'x86_64' ? '' :
+ arch == 'aarch_64' ? 'arm64' :
+ 'unknown'
+ if (lwjglArch == 'unknown')
+ throw new GradleException('Unsupported Architecture: ' + arch)
+
+ return (lwjglArch == '' ? lwjglOS : (lwjglOS + '-' + lwjglArch))
+}
+
+test {
+ useJUnitPlatform()
+}
+
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 6ce793f2..6b4de624 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,6 @@
+#Thu Apr 20 18:43:05 CST 2023
distributionBase=GRADLE_USER_HOME
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
-zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
diff --git a/gradlew b/gradlew
old mode 100644
new mode 100755
diff --git a/libs/lwjgl/ibxm.jar b/libs/lwjgl/ibxm.jar
deleted file mode 100644
index 619d26e1..00000000
Binary files a/libs/lwjgl/ibxm.jar and /dev/null differ
diff --git a/libs/lwjgl/jogg-0.0.7.jar b/libs/lwjgl/jogg-0.0.7.jar
deleted file mode 100644
index ecb02603..00000000
Binary files a/libs/lwjgl/jogg-0.0.7.jar and /dev/null differ
diff --git a/libs/lwjgl/jorbis-0.0.15.jar b/libs/lwjgl/jorbis-0.0.15.jar
deleted file mode 100644
index 4cf51f90..00000000
Binary files a/libs/lwjgl/jorbis-0.0.15.jar and /dev/null differ
diff --git a/libs/lwjgl/lwjgl.jar b/libs/lwjgl/lwjgl.jar
deleted file mode 100644
index 5da88d33..00000000
Binary files a/libs/lwjgl/lwjgl.jar and /dev/null differ
diff --git a/libs/lwjgl/lwjgl_util.jar b/libs/lwjgl/lwjgl_util.jar
deleted file mode 100644
index d377c51a..00000000
Binary files a/libs/lwjgl/lwjgl_util.jar and /dev/null differ
diff --git a/libs/lwjgl/lwjgl_util_applet.jar b/libs/lwjgl/lwjgl_util_applet.jar
deleted file mode 100644
index 99a6ccbe..00000000
Binary files a/libs/lwjgl/lwjgl_util_applet.jar and /dev/null differ
diff --git a/libs/lwjgl/natives-linux.jar b/libs/lwjgl/natives-linux.jar
deleted file mode 100644
index a543ee02..00000000
Binary files a/libs/lwjgl/natives-linux.jar and /dev/null differ
diff --git a/libs/lwjgl/natives-mac.jar b/libs/lwjgl/natives-mac.jar
deleted file mode 100644
index 220012ba..00000000
Binary files a/libs/lwjgl/natives-mac.jar and /dev/null differ
diff --git a/libs/lwjgl/natives-windows.jar b/libs/lwjgl/natives-windows.jar
deleted file mode 100644
index 2fb036fb..00000000
Binary files a/libs/lwjgl/natives-windows.jar and /dev/null differ
diff --git a/libs/lwjgl/natives/linux/libjinput-linux.so b/libs/lwjgl/natives/linux/libjinput-linux.so
deleted file mode 100644
index 3cdc4397..00000000
Binary files a/libs/lwjgl/natives/linux/libjinput-linux.so and /dev/null differ
diff --git a/libs/lwjgl/natives/linux/libjinput-linux64.so b/libs/lwjgl/natives/linux/libjinput-linux64.so
deleted file mode 100644
index de1ee5f3..00000000
Binary files a/libs/lwjgl/natives/linux/libjinput-linux64.so and /dev/null differ
diff --git a/libs/lwjgl/natives/linux/liblwjgl.so b/libs/lwjgl/natives/linux/liblwjgl.so
deleted file mode 100644
index 3fe6b16c..00000000
Binary files a/libs/lwjgl/natives/linux/liblwjgl.so and /dev/null differ
diff --git a/libs/lwjgl/natives/linux/liblwjgl64.so b/libs/lwjgl/natives/linux/liblwjgl64.so
deleted file mode 100644
index 690f6354..00000000
Binary files a/libs/lwjgl/natives/linux/liblwjgl64.so and /dev/null differ
diff --git a/libs/lwjgl/natives/linux/libopenal.so b/libs/lwjgl/natives/linux/libopenal.so
deleted file mode 100644
index 0a3a619b..00000000
Binary files a/libs/lwjgl/natives/linux/libopenal.so and /dev/null differ
diff --git a/libs/lwjgl/natives/linux/libopenal64.so b/libs/lwjgl/natives/linux/libopenal64.so
deleted file mode 100644
index e0693c01..00000000
Binary files a/libs/lwjgl/natives/linux/libopenal64.so and /dev/null differ
diff --git a/libs/lwjgl/natives/mac/libjinput-osx.dylib b/libs/lwjgl/natives/mac/libjinput-osx.dylib
deleted file mode 100644
index 59a3eab5..00000000
Binary files a/libs/lwjgl/natives/mac/libjinput-osx.dylib and /dev/null differ
diff --git a/libs/lwjgl/natives/mac/liblwjgl.dylib b/libs/lwjgl/natives/mac/liblwjgl.dylib
deleted file mode 100644
index a6083b95..00000000
Binary files a/libs/lwjgl/natives/mac/liblwjgl.dylib and /dev/null differ
diff --git a/libs/lwjgl/natives/mac/openal.dylib b/libs/lwjgl/natives/mac/openal.dylib
deleted file mode 100644
index 3c6d0f7f..00000000
Binary files a/libs/lwjgl/natives/mac/openal.dylib and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/OpenAL32.dll b/libs/lwjgl/natives/windows/OpenAL32.dll
deleted file mode 100644
index 1f69e945..00000000
Binary files a/libs/lwjgl/natives/windows/OpenAL32.dll and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/OpenAL64.dll b/libs/lwjgl/natives/windows/OpenAL64.dll
deleted file mode 100644
index 6f2a2fe1..00000000
Binary files a/libs/lwjgl/natives/windows/OpenAL64.dll and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/jinput-dx8.dll b/libs/lwjgl/natives/windows/jinput-dx8.dll
deleted file mode 100644
index 6d27ad5e..00000000
Binary files a/libs/lwjgl/natives/windows/jinput-dx8.dll and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/jinput-dx8_64.dll b/libs/lwjgl/natives/windows/jinput-dx8_64.dll
deleted file mode 100644
index 67305896..00000000
Binary files a/libs/lwjgl/natives/windows/jinput-dx8_64.dll and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/jinput-raw.dll b/libs/lwjgl/natives/windows/jinput-raw.dll
deleted file mode 100644
index ce1d1620..00000000
Binary files a/libs/lwjgl/natives/windows/jinput-raw.dll and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/jinput-raw_64.dll b/libs/lwjgl/natives/windows/jinput-raw_64.dll
deleted file mode 100644
index 3d2b3ada..00000000
Binary files a/libs/lwjgl/natives/windows/jinput-raw_64.dll and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/lwjgl.dll b/libs/lwjgl/natives/windows/lwjgl.dll
deleted file mode 100644
index 7cca39f8..00000000
Binary files a/libs/lwjgl/natives/windows/lwjgl.dll and /dev/null differ
diff --git a/libs/lwjgl/natives/windows/lwjgl64.dll b/libs/lwjgl/natives/windows/lwjgl64.dll
deleted file mode 100644
index 99cbd988..00000000
Binary files a/libs/lwjgl/natives/windows/lwjgl64.dll and /dev/null differ
diff --git a/libs/lwjgl/slick-util.jar b/libs/lwjgl/slick-util.jar
deleted file mode 100644
index 10b552a9..00000000
Binary files a/libs/lwjgl/slick-util.jar and /dev/null differ
diff --git a/res/fonts/minecraft-ten.ttf b/res/fonts/minecraft-ten.ttf
new file mode 100644
index 00000000..a8110223
Binary files /dev/null and b/res/fonts/minecraft-ten.ttf differ
diff --git a/res/gui/CraftGame.png b/res/gui/CraftGame.png
new file mode 100644
index 00000000..5fb599da
Binary files /dev/null and b/res/gui/CraftGame.png differ
diff --git a/res/gui/main_menu/multi_player.png b/res/gui/main_menu/multi_player.png
new file mode 100644
index 00000000..60d20c2d
Binary files /dev/null and b/res/gui/main_menu/multi_player.png differ
diff --git a/res/gui/main_menu/settings.png b/res/gui/main_menu/settings.png
new file mode 100644
index 00000000..39a85fb6
Binary files /dev/null and b/res/gui/main_menu/settings.png differ
diff --git a/res/gui/main_menu/single_player.png b/res/gui/main_menu/single_player.png
new file mode 100644
index 00000000..b2058c89
Binary files /dev/null and b/res/gui/main_menu/single_player.png differ
diff --git a/res/gui/options_background.png b/res/gui/options_background.png
new file mode 100644
index 00000000..ccd17786
Binary files /dev/null and b/res/gui/options_background.png differ
diff --git a/res/gui/player_icon.jpg b/res/gui/player_icon.jpg
new file mode 100644
index 00000000..d62d9e8e
Binary files /dev/null and b/res/gui/player_icon.jpg differ
diff --git a/res/gui/server_select/server_dialog.png b/res/gui/server_select/server_dialog.png
new file mode 100644
index 00000000..7cc73c5d
Binary files /dev/null and b/res/gui/server_select/server_dialog.png differ
diff --git a/res/gui/splash.jpg b/res/gui/splash.jpg
new file mode 100644
index 00000000..3e60db7d
Binary files /dev/null and b/res/gui/splash.jpg differ
diff --git a/res/gui/toast/toast_1.png b/res/gui/toast/toast_1.png
new file mode 100644
index 00000000..7faa633e
Binary files /dev/null and b/res/gui/toast/toast_1.png differ
diff --git a/res/gui/toast/toast_2.png b/res/gui/toast/toast_2.png
new file mode 100644
index 00000000..33cd79f4
Binary files /dev/null and b/res/gui/toast/toast_2.png differ
diff --git a/res/gui/toast/toast_3.png b/res/gui/toast/toast_3.png
new file mode 100644
index 00000000..62ec2b43
Binary files /dev/null and b/res/gui/toast/toast_3.png differ
diff --git a/res/gui/toast/toast_4.png b/res/gui/toast/toast_4.png
new file mode 100644
index 00000000..53998f45
Binary files /dev/null and b/res/gui/toast/toast_4.png differ
diff --git a/res/gui/toast/toast_confusion.png b/res/gui/toast/toast_confusion.png
new file mode 100644
index 00000000..ab1a2ba8
Binary files /dev/null and b/res/gui/toast/toast_confusion.png differ
diff --git a/res/gui/toast/toast_error.png b/res/gui/toast/toast_error.png
new file mode 100644
index 00000000..de28343c
Binary files /dev/null and b/res/gui/toast/toast_error.png differ
diff --git a/res/gui/toast/toast_exception.png b/res/gui/toast/toast_exception.png
new file mode 100644
index 00000000..c397dc2c
Binary files /dev/null and b/res/gui/toast/toast_exception.png differ
diff --git a/res/gui/toast/toast_fine.png b/res/gui/toast/toast_fine.png
new file mode 100644
index 00000000..148ed3db
Binary files /dev/null and b/res/gui/toast/toast_fine.png differ
diff --git a/res/gui/widgets/chosen_close.png b/res/gui/widgets/chosen_close.png
new file mode 100644
index 00000000..31aeadd4
Binary files /dev/null and b/res/gui/widgets/chosen_close.png differ
diff --git a/res/gui/widgets/close.png b/res/gui/widgets/close.png
new file mode 100644
index 00000000..7e563756
Binary files /dev/null and b/res/gui/widgets/close.png differ
diff --git a/res/icon.png b/res/icon.png
new file mode 100644
index 00000000..25a097c5
Binary files /dev/null and b/res/icon.png differ
diff --git a/res/lang/zh-ch.lang b/res/lang/zh-ch.lang
new file mode 100644
index 00000000..187b7e0b
--- /dev/null
+++ b/res/lang/zh-ch.lang
@@ -0,0 +1,43 @@
+# Game Start
+game.version=alpha
+game.copyright=Licensed under AGPL 3.0
+
+# Main Menu
+main_menu.single_player=Single Player
+main_menu.multi_player=Multiplayer
+main_menu.setting=Setting
+esc_menu.back_to_game=Back To Game
+esc_menu.quit=Save And Quit
+
+# Select World Menu
+world_select_menu.text=Select World
+world_select_menu.play=Play
+world_select_menu.edit=Edit
+world_select_menu.delete=Delete
+world_select_menu.cancel=Cancel
+world_select_menu.create=Create
+
+# Select Server Menu
+server_select_menu.text=Select Server
+server_select_menu.join=Join Server
+server_select_menu.direct=Direct Connect
+server_select_menu.add=Add Server
+server_select_menu.edit=Edit
+server_select_menu.delete=Delete
+server_select_menu.refresh=Refresh
+server_select_menu.cancel=Cancel
+server_select_edit_dialog.title=Sorry but currently the view doesn't work!
+server_select_edit_dialog.name=Server Name
+server_select_edit_dialog.name.hint=Please enter server name
+server_select_edit_dialog.addr=Server Address
+server_select_edit_dialog.addr.hint=Please enter IP or Address
+server_select_edit_dialog.port=Port
+server_select_edit_dialog.remove=Remove
+server_select_edit_dialog.save=Save
+
+# World Loading
+world_loading.text=Loading Level...
+
+# World Saving
+world_saving.text=Saving Level...
+
diff --git a/res/logging.properties b/res/logging.properties
new file mode 100644
index 00000000..f2c9fd21
--- /dev/null
+++ b/res/logging.properties
@@ -0,0 +1,65 @@
+############################################################
+# Default Logging Configuration File
+#
+# You can use a different file by specifying a filename
+# with the java.util.logging.config.file system property.
+# For example java -Djava.util.logging.config.file=myfile
+############################################################
+
+############################################################
+# Global properties
+############################################################
+
+# "handlers" specifies a comma separated list of log Handler
+# classes. These handlers will be installed during VM startup.
+# Note that these classes must be on the system classpath.
+# By default we only configure a ConsoleHandler, which will only
+# show messages at the INFO and above levels.
+#handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default global logging level.
+# This specifies which kinds of events are logged across
+# all loggers. For any given facility this global level
+# can be overriden by a facility specific level
+# Note that the ConsoleHandler also has a separate level
+# setting to limit messages printed to the console.
+.level= ALL
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# default file output is in user's home directory.
+java.util.logging.FileHandler.pattern = log/java%u.csv
+java.util.logging.FileHandler.limit = 999999
+java.util.logging.FileHandler.count = 1
+# Default number of locks FileHandler can obtain synchronously.
+# This specifies maximum number of attempts to obtain lock file by FileHandler
+# implemented by incrementing the unique field %u as per FileHandler API documentation.
+java.util.logging.FileHandler.maxLocks = 100
+java.util.logging.FileHandler.formatter = xueli.utils.formatter.MyFormatter
+
+# Limit the message that are printed on the console to INFO and above.
+java.util.logging.ConsoleHandler.level = ALL
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+java.util.logging.SimpleFormatter.format=%1$tF %1$tH:%1$tM:%1$tS %2$s%n%4$s: %5$s%6$s%n
+
+# Example to customize the SimpleFormatter output format
+# to print one-line log message like this:
+# : []
+#
+# java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n
+
+############################################################
+# Facility specific properties.
+# Provides extra control for each logger.
+############################################################
+
+# For example, set the com.xyz.foo logger to only log SEVERE
+# messages:
+# com.xyz.foo.level = SEVERE
diff --git a/res/music/BV1HD4y1x7Gy.nbs b/res/music/BV1HD4y1x7Gy.nbs
new file mode 100644
index 00000000..b9773fd4
Binary files /dev/null and b/res/music/BV1HD4y1x7Gy.nbs differ
diff --git a/res/music/BowOfMoon.nbs b/res/music/BowOfMoon.nbs
new file mode 100644
index 00000000..e94d2c35
Binary files /dev/null and b/res/music/BowOfMoon.nbs differ
diff --git a/res/music/Ninelie.nbs b/res/music/Ninelie.nbs
new file mode 100644
index 00000000..b5f93663
Binary files /dev/null and b/res/music/Ninelie.nbs differ
diff --git a/res/music/One Summer Day.nbs b/res/music/One Summer Day.nbs
new file mode 100644
index 00000000..558464a6
Binary files /dev/null and b/res/music/One Summer Day.nbs differ
diff --git a/res/music/Together Forever-RickAstley.nbs b/res/music/Together Forever-RickAstley.nbs
new file mode 100644
index 00000000..7cc8273a
Binary files /dev/null and b/res/music/Together Forever-RickAstley.nbs differ
diff --git a/res/music/Together Forever-RickAstley_piano.nbs b/res/music/Together Forever-RickAstley_piano.nbs
new file mode 100644
index 00000000..f6b66749
Binary files /dev/null and b/res/music/Together Forever-RickAstley_piano.nbs differ
diff --git a/res/music/always.nbs b/res/music/always.nbs
new file mode 100644
index 00000000..0fdd5a0a
Binary files /dev/null and b/res/music/always.nbs differ
diff --git a/res/music/aurora.nbs b/res/music/aurora.nbs
new file mode 100644
index 00000000..87053bc0
Binary files /dev/null and b/res/music/aurora.nbs differ
diff --git a/res/music/beings.nbs b/res/music/beings.nbs
new file mode 100644
index 00000000..04c8fa38
Binary files /dev/null and b/res/music/beings.nbs differ
diff --git a/res/music/departures.nbs b/res/music/departures.nbs
new file mode 100644
index 00000000..1384d96c
Binary files /dev/null and b/res/music/departures.nbs differ
diff --git a/res/music/dong_feng_po.nbs b/res/music/dong_feng_po.nbs
new file mode 100644
index 00000000..a4199df4
Binary files /dev/null and b/res/music/dong_feng_po.nbs differ
diff --git a/res/music/easteregg.nbs b/res/music/easteregg.nbs
new file mode 100644
index 00000000..58ccbc0b
Binary files /dev/null and b/res/music/easteregg.nbs differ
diff --git a/res/music/everything goes on.nbs b/res/music/everything goes on.nbs
new file mode 100644
index 00000000..cf128a1e
Binary files /dev/null and b/res/music/everything goes on.nbs differ
diff --git a/res/music/flower-yuezhengling.nbs b/res/music/flower-yuezhengling.nbs
new file mode 100644
index 00000000..5769f6d3
Binary files /dev/null and b/res/music/flower-yuezhengling.nbs differ
diff --git a/res/music/lucky_star.nbs b/res/music/lucky_star.nbs
new file mode 100644
index 00000000..9155c088
Binary files /dev/null and b/res/music/lucky_star.nbs differ
diff --git a/res/music/luhan-oncall.nbs b/res/music/luhan-oncall.nbs
new file mode 100644
index 00000000..bcf9749f
Binary files /dev/null and b/res/music/luhan-oncall.nbs differ
diff --git a/res/music/nali_doushini_duizhang.nbs b/res/music/nali_doushini_duizhang.nbs
new file mode 100644
index 00000000..a2e93549
Binary files /dev/null and b/res/music/nali_doushini_duizhang.nbs differ
diff --git a/res/music/ni_ting_de_dao.nbs b/res/music/ni_ting_de_dao.nbs
new file mode 100644
index 00000000..27777959
Binary files /dev/null and b/res/music/ni_ting_de_dao.nbs differ
diff --git a/res/music/ok x lionhearted.nbs b/res/music/ok x lionhearted.nbs
new file mode 100644
index 00000000..fcea4cfc
Binary files /dev/null and b/res/music/ok x lionhearted.nbs differ
diff --git a/res/music/pay no mind x easy.nbs b/res/music/pay no mind x easy.nbs
new file mode 100644
index 00000000..346d743b
Binary files /dev/null and b/res/music/pay no mind x easy.nbs differ
diff --git a/res/music/school lofi (original.nbs b/res/music/school lofi (original.nbs
new file mode 100644
index 00000000..c7f761a0
Binary files /dev/null and b/res/music/school lofi (original.nbs differ
diff --git a/res/music/something comforing.nbs b/res/music/something comforing.nbs
new file mode 100644
index 00000000..144f9197
Binary files /dev/null and b/res/music/something comforing.nbs differ
diff --git a/res/music/thief.nbs b/res/music/thief.nbs
new file mode 100644
index 00000000..d0a76807
Binary files /dev/null and b/res/music/thief.nbs differ
diff --git a/res/music/woheni.nbs b/res/music/woheni.nbs
new file mode 100644
index 00000000..6149d576
Binary files /dev/null and b/res/music/woheni.nbs differ
diff --git a/res/music/yanhua_yileng.nbs b/res/music/yanhua_yileng.nbs
new file mode 100644
index 00000000..72ddc820
Binary files /dev/null and b/res/music/yanhua_yileng.nbs differ
diff --git a/res/music/zuiweidadezuopin.nbs b/res/music/zuiweidadezuopin.nbs
new file mode 100644
index 00000000..5eb41a24
Binary files /dev/null and b/res/music/zuiweidadezuopin.nbs differ
diff --git a/res/shaders/block_view/frag.txt b/res/shaders/block_view/frag.txt
new file mode 100644
index 00000000..4d27793a
--- /dev/null
+++ b/res/shaders/block_view/frag.txt
@@ -0,0 +1,20 @@
+#version 330
+
+in vec2 otexPos;
+in vec3 opos;
+
+uniform sampler2D texSampler;
+
+out vec4 out_color;
+
+float random() {
+ return clamp((opos.x + opos.y + opos.z) / 6.0, 0.0, 1.0);
+}
+
+void main(){
+ vec4 ambient = texture(texSampler, otexPos);
+ if(ambient.w == 0) discard;
+ out_color = vec4(ambient.xyz * vec3(mix(0.7,1.0,1 - random())), ambient.w);
+
+
+}
\ No newline at end of file
diff --git a/res/shaders/block_view/vert.txt b/res/shaders/block_view/vert.txt
new file mode 100644
index 00000000..813674b7
--- /dev/null
+++ b/res/shaders/block_view/vert.txt
@@ -0,0 +1,19 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec2 texPos;
+layout (location = 4) in vec3 normal;
+
+uniform mat4 projMatrix;
+uniform mat4 viewMatrix;
+
+out vec2 otexPos;
+out vec3 opos;
+
+void main() {
+ gl_Position = projMatrix * viewMatrix * vec4(pos, 1.0);
+ otexPos = texPos;
+ opos = pos;
+
+}
+
diff --git a/res/shaders/entity/frag.txt b/res/shaders/entity/frag.txt
new file mode 100644
index 00000000..482718ba
--- /dev/null
+++ b/res/shaders/entity/frag.txt
@@ -0,0 +1,12 @@
+#version 330
+
+in vec2 otexPos;
+
+uniform sampler2D texSampler;
+
+out vec4 out_color;
+
+void main(){
+ out_color = texture(texSampler, otexPos);
+
+}
\ No newline at end of file
diff --git a/res/shaders/entity/vert.txt b/res/shaders/entity/vert.txt
new file mode 100644
index 00000000..75df8cfc
--- /dev/null
+++ b/res/shaders/entity/vert.txt
@@ -0,0 +1,18 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec2 texPos;
+
+uniform mat4 projMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 transMatrix;
+uniform mat4 boneMatrix;
+
+out vec2 otexPos;
+
+void main(){
+ gl_Position = projMatrix * viewMatrix * transMatrix * boneMatrix * vec4(pos, 1.0);
+ otexPos = texPos;
+
+}
+
diff --git a/res/shaders/g_buffer/frag.txt b/res/shaders/g_buffer/frag.txt
new file mode 100644
index 00000000..2316fe23
--- /dev/null
+++ b/res/shaders/g_buffer/frag.txt
@@ -0,0 +1,19 @@
+#version 330
+
+in vec3 fragPos;
+in vec2 otexPos;
+in vec3 ocolor;
+in vec3 onormal;
+
+uniform sampler2D texSampler;
+
+layout (location = 0) out vec3 gPosition;
+layout (location = 1) out vec3 gNormal;
+layout (location = 2) out vec4 gTex;
+
+void main(){
+ gPosition = fragPos;
+ gNormal = onormal;
+ gTex = texture(texSampler, otexPos) * vec4(ocolor, 1.0);
+
+}
\ No newline at end of file
diff --git a/res/shaders/g_buffer/vert.txt b/res/shaders/g_buffer/vert.txt
new file mode 100644
index 00000000..f7402b5e
--- /dev/null
+++ b/res/shaders/g_buffer/vert.txt
@@ -0,0 +1,36 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec2 texPos;
+layout (location = 2) in vec3 color;
+layout (location = 3) in float sunLight;
+layout (location = 4) in vec3 normal;
+
+uniform mat4 projMatrix;
+uniform mat4 viewMatrix;
+
+out vec3 fragPos;
+out vec2 otexPos;
+out vec3 ocolor;
+out float osunLight;
+out vec3 onormal;
+
+const float density = 0.05;
+const float gradient = 4;
+out float visibility;
+
+void main(){
+ vec4 posCam = viewMatrix * vec4(pos ,1.0);
+ gl_Position = projMatrix * posCam;
+ otexPos = texPos;
+ ocolor = color;
+ osunLight = sunLight;
+ fragPos = pos;
+ onormal = normal;
+
+ float distance = length(posCam.xyz);
+ visibility = exp(-pow(distance * density, gradient));
+ visibility = clamp(visibility, 0.0, 1.0);
+
+}
+
diff --git a/res/shaders/screen_quad/frag.txt b/res/shaders/screen_quad/frag.txt
new file mode 100644
index 00000000..b36eb4be
--- /dev/null
+++ b/res/shaders/screen_quad/frag.txt
@@ -0,0 +1,13 @@
+#version 330
+
+in vec2 otexPos;
+
+uniform sampler2D tex;
+uniform sampler2D depth;
+
+out vec4 out_color;
+
+void main(){
+ out_color = texture(tex, otexPos);
+
+}
\ No newline at end of file
diff --git a/res/shaders/screen_quad/vert.txt b/res/shaders/screen_quad/vert.txt
new file mode 100644
index 00000000..cb523df2
--- /dev/null
+++ b/res/shaders/screen_quad/vert.txt
@@ -0,0 +1,13 @@
+#version 330
+
+layout (location = 0) in vec2 pos;
+layout (location = 1) in vec2 texPos;
+
+out vec2 otexPos;
+
+void main(){
+ gl_Position = vec4(pos, 0.0, 1.0);
+ otexPos = texPos;
+
+}
+
diff --git a/res/shaders/screen_quad_ssao/frag.txt b/res/shaders/screen_quad_ssao/frag.txt
new file mode 100644
index 00000000..ccb9f0f8
--- /dev/null
+++ b/res/shaders/screen_quad_ssao/frag.txt
@@ -0,0 +1,51 @@
+#version 330
+
+const float shadowSize = 0.01f;
+const vec2 noiseScale = vec2(800.0f/4.0f, 600.0f/4.0f);
+
+in vec2 otexPos;
+
+uniform sampler2D tex;
+uniform sampler2D noise;
+uniform sampler2D ssaoColor;
+uniform sampler2D normal;
+uniform sampler2D frag;
+uniform vec3 samplers[64];
+uniform mat4 projection;
+
+out vec4 out_color;
+
+float calculateSSAO() {
+ vec3 normal = texture(normal, otexPos).rgb;
+ vec3 randomVec = texture(noise, otexPos * noiseScale).xyz;
+ vec3 fragPos = texture(frag, otexPos).xyz;
+
+ vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
+ vec3 bitangent = cross(normal, tangent);
+ mat3 TBN = mat3(tangent, bitangent, normal);
+
+ float occlusion = 0.0;
+ for(int i = 0; i < 64; ++i)
+ {
+ vec3 sample = TBN * samplers[i];
+ sample = fragPos + sample * 1;
+
+ vec4 offset = vec4(sample, 1.0);
+ offset = projection * offset;
+ offset.xyz /= offset.w;
+ offset.xyz = offset.xyz * 0.5 + 0.5;
+
+ float sampleDepth = -texture(ssaoColor, offset.xy).w;
+ occlusion += (sampleDepth >= sample.z ? 1.0 : 0.0);
+
+ }
+
+ return 1.0 - (occlusion / 64);
+}
+
+void main() {
+ float occlusion = calculateSSAO();
+ out_color = vec4(occlusion,occlusion,occlusion,1.0);
+
+
+}
\ No newline at end of file
diff --git a/res/shaders/screen_quad_ssao/vert.txt b/res/shaders/screen_quad_ssao/vert.txt
new file mode 100644
index 00000000..cb523df2
--- /dev/null
+++ b/res/shaders/screen_quad_ssao/vert.txt
@@ -0,0 +1,13 @@
+#version 330
+
+layout (location = 0) in vec2 pos;
+layout (location = 1) in vec2 texPos;
+
+out vec2 otexPos;
+
+void main(){
+ gl_Position = vec4(pos, 0.0, 1.0);
+ otexPos = texPos;
+
+}
+
diff --git a/res/shaders/test_shadow_mapping/frag.txt b/res/shaders/test_shadow_mapping/frag.txt
new file mode 100644
index 00000000..33275529
--- /dev/null
+++ b/res/shaders/test_shadow_mapping/frag.txt
@@ -0,0 +1,46 @@
+#version 330
+
+in vec3 ocolor;
+
+in vec3 FragPos;
+in vec4 FragPosLightSpace;
+uniform sampler2D shadowMap;
+uniform vec3 lightPos;
+
+out vec4 out_color;
+
+float ShadowCalculation(vec4 fragPosLightSpace) {
+ vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
+ projCoords = projCoords * 0.5 + 0.5;
+ float closestDepth = texture(shadowMap, projCoords.xy).r;
+ float currentDepth = projCoords.z;
+
+ float shadow = 0.0;
+ vec2 texelSize = 1.0 / textureSize(shadowMap, 0);
+ for(int x = -1; x <= 1; ++x)
+ {
+ for(int y = -1; y <= 1; ++y)
+ {
+ float pcfDepth = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
+ shadow += currentDepth > pcfDepth ? 1.0 : 0.0;
+ }
+ }
+ shadow /= 9.0;
+
+ if(projCoords.z > 1.0)
+ shadow = 0.0;
+
+ return shadow;
+
+}
+
+void main(){
+ float shadow = ShadowCalculation(FragPosLightSpace);
+ shadow = 1 - clamp(shadow, 0, 0.6);
+
+ vec4 color = shadow * vec4(ocolor, 1.0);
+ if(color.w == 0) discard;
+ out_color = color;
+
+
+}
\ No newline at end of file
diff --git a/res/shaders/test_shadow_mapping/vert.txt b/res/shaders/test_shadow_mapping/vert.txt
new file mode 100644
index 00000000..0a4de616
--- /dev/null
+++ b/res/shaders/test_shadow_mapping/vert.txt
@@ -0,0 +1,25 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 2) in vec3 color;
+
+uniform mat4 projMatrix;
+uniform mat4 viewMatrix;
+
+out vec3 ocolor;
+
+uniform mat4 lightSpaceMatrix;
+out vec4 FragPosLightSpace;
+
+out vec3 FragPos;
+
+void main(){
+ vec4 posCam = viewMatrix * vec4(pos ,1.0);
+ gl_Position = projMatrix * posCam;
+ ocolor = color;
+ FragPos = pos;
+
+ FragPosLightSpace = lightSpaceMatrix * vec4(pos, 1.0);
+
+}
+
diff --git a/res/shaders/test_shadow_mapping_depth/frag.txt b/res/shaders/test_shadow_mapping_depth/frag.txt
new file mode 100644
index 00000000..2a584a91
--- /dev/null
+++ b/res/shaders/test_shadow_mapping_depth/frag.txt
@@ -0,0 +1,10 @@
+#version 330
+
+in vec3 ocolor;
+
+out vec4 outColor;
+
+void main(){
+ outColor = vec4(ocolor, 1.0);
+
+}
\ No newline at end of file
diff --git a/res/shaders/test_shadow_mapping_depth/vert.txt b/res/shaders/test_shadow_mapping_depth/vert.txt
new file mode 100644
index 00000000..66cf55b0
--- /dev/null
+++ b/res/shaders/test_shadow_mapping_depth/vert.txt
@@ -0,0 +1,18 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 2) in vec3 color;
+
+uniform mat4 projMatrix;
+uniform mat4 viewMatrix;
+
+out vec3 ocolor;
+
+void main(){
+ vec4 posCam = viewMatrix * vec4(pos ,1.0);
+ gl_Position = projMatrix * posCam;
+
+ ocolor = color;
+
+}
+
diff --git a/res/shaders/test_shadow_mapping_depth_show/frag.txt b/res/shaders/test_shadow_mapping_depth_show/frag.txt
new file mode 100644
index 00000000..882fed6a
--- /dev/null
+++ b/res/shaders/test_shadow_mapping_depth_show/frag.txt
@@ -0,0 +1,14 @@
+#version 330
+
+uniform sampler2D depthMap;
+uniform sampler2D viewTexture;
+
+in vec2 otexpos;
+
+out vec4 outcolor;
+
+void main(){
+ float depthValue = texture(depthMap, otexpos).r;
+ outcolor = texture(depthMap, otexpos) * vec4(vec3(1 - depthValue * 0.4), 1.0);
+
+}
\ No newline at end of file
diff --git a/res/shaders/test_shadow_mapping_depth_show/vert.txt b/res/shaders/test_shadow_mapping_depth_show/vert.txt
new file mode 100644
index 00000000..cf684424
--- /dev/null
+++ b/res/shaders/test_shadow_mapping_depth_show/vert.txt
@@ -0,0 +1,13 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec2 texPos;
+
+out vec2 otexpos;
+
+void main(){
+ gl_Position = vec4(pos, 1.0);
+ otexpos = texPos;
+
+}
+
diff --git a/res/shaders/world/world.frag b/res/shaders/world/world.frag
new file mode 100644
index 00000000..4faa86e1
--- /dev/null
+++ b/res/shaders/world/world.frag
@@ -0,0 +1,22 @@
+#version 330
+
+in float visibility;
+
+in vec3 fragPos;
+in vec2 otexPos;
+in vec4 ocolor;
+
+uniform vec3 skyColor;
+uniform vec3 sunDirection;
+uniform sampler2D texSampler;
+
+out vec4 out_color;
+
+void main(){
+ vec4 ambient = texture(texSampler, otexPos);
+ if(ambient.w == 0) discard;
+
+ out_color = mix(vec4(skyColor, 1.0), ambient * ocolor, visibility);
+
+
+}
diff --git a/res/shaders/world/world.vert b/res/shaders/world/world.vert
new file mode 100644
index 00000000..826061bf
--- /dev/null
+++ b/res/shaders/world/world.vert
@@ -0,0 +1,30 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec2 texPos;
+layout (location = 2) in vec4 color;
+
+uniform mat4 projMatrix;
+uniform mat4 viewMatrix;
+
+out vec3 fragPos;
+out vec2 otexPos;
+out vec4 ocolor;
+
+const float density = 0.004;
+const float gradient = 6.0;
+out float visibility;
+
+void main(){
+ vec4 posCam = viewMatrix * vec4(pos ,1.0);
+ gl_Position = projMatrix * posCam;
+ otexPos = texPos;
+ fragPos = pos;
+ ocolor = color;
+
+ float distance = length(posCam.xyz);
+ visibility = exp(-pow(distance * density, gradient));
+ visibility = clamp(visibility, 0.0, 1.0);
+
+}
+
diff --git a/res/shaders/world_ssao/frag.txt b/res/shaders/world_ssao/frag.txt
new file mode 100644
index 00000000..4a1352f1
--- /dev/null
+++ b/res/shaders/world_ssao/frag.txt
@@ -0,0 +1,40 @@
+#version 330
+
+const vec3 sunColor = vec3(1.0, 1.0, 1.0);
+
+in vec3 fragPos;
+in vec2 otexPos;
+in vec3 ocolor;
+in float osunLight;
+in float visibility;
+in vec3 onormal;
+
+uniform vec3 skyColor;
+uniform vec3 sunDirection;
+uniform sampler2D texSampler;
+
+layout (location = 0) out vec4 out_color;
+layout (location = 1) out vec3 out_gNormal;
+layout (location = 2) out vec3 out_gFragPos;
+
+float diff() {
+ vec3 norm = normalize(onormal);
+ vec3 lightDir = normalize(sunDirection);
+
+ return -max(dot(norm, lightDir), 0.0);
+}
+
+void main(){
+ vec3 sunLightColor = sunColor * osunLight;
+ vec3 real_sun_color = mix(ocolor, sunLightColor, 1.0);
+
+ vec4 ambient = texture(texSampler, otexPos);
+ if(ambient.w == 0) discard;
+
+ vec3 color = ambient.xyz * vec3(mix(0.8,2.0,diff()));
+
+ out_color = mix(vec4(skyColor, 1.0), vec4(color, 1.0), visibility);
+ out_gNormal = onormal;
+ out_gFragPos = fragPos;
+
+}
\ No newline at end of file
diff --git a/res/shaders/world_ssao/vert.txt b/res/shaders/world_ssao/vert.txt
new file mode 100644
index 00000000..cfc268f5
--- /dev/null
+++ b/res/shaders/world_ssao/vert.txt
@@ -0,0 +1,36 @@
+#version 330
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec2 texPos;
+layout (location = 2) in vec3 color;
+layout (location = 3) in float sunLight;
+layout (location = 4) in vec3 normal;
+
+uniform mat4 projMatrix;
+uniform mat4 viewMatrix;
+
+out vec3 fragPos;
+out vec2 otexPos;
+out vec3 ocolor;
+out float osunLight;
+out vec3 onormal;
+
+const float density = 0.004;
+const float gradient = 6.0;
+out float visibility;
+
+void main(){
+ vec4 posCam = viewMatrix * vec4(pos ,1.0);
+ gl_Position = projMatrix * posCam;
+ otexPos = texPos;
+ ocolor = color;
+ osunLight = sunLight;
+ fragPos = pos;
+ onormal = normal;
+
+ float distance = length(posCam.xyz);
+ visibility = exp(-pow(distance * density, gradient));
+ visibility = clamp(visibility, 0.0, 1.0);
+
+}
+
diff --git a/res/text/splash.txt b/res/text/splash.txt
new file mode 100644
index 00000000..372a1fac
--- /dev/null
+++ b/res/text/splash.txt
@@ -0,0 +1,15 @@
+īģŋå¤å¤å¤
+æŖåŊ夊æä¸čŦįææåŧäēå°åą
+æåžå¯įą 蝎įģæéą
+čīŧ䏿Ĩåč¯īŧ
+æĨčĒåæŦĄå įæĨčĒåæŦĄå įéĒčåä¸åļäŊįæĨčĒåæŦĄå ῏¸æ
+J A V A H E R O B R I N E
+åŧåå ååååååååååååååååååååååå
+Nobody knows CraftGame better than me!
+Xueli, the fake fake programmer~
+awa
+įŠŋįåĨŗčŖ åäģŖį
+Ah, fine. I guess u r my little pogchamp. Come here~
+Never gonna give u up, never gonna let u down
+čŋä¸ĒåĨŊčļ~ ãŊ(âŋīžâŊīž)ã
+awaæ¯å¤§åŽļį
\ No newline at end of file
diff --git a/res/text/xuanxue1.txt b/res/text/xuanxue1.txt
new file mode 100644
index 00000000..70a836f7
--- /dev/null
+++ b/res/text/xuanxue1.txt
@@ -0,0 +1,22 @@
+Q: ä¸įä¸äŧä¸äŧæä¸į§åˇĨå ˇæ¯æįģ常čĸĢäŊŋį¨įåĸ?åĻææ,ä¸ēäģäšäŧčĸĢæįģ常äŊŋį¨.
+A: åŧĻææå¤¸å åįĩåįåēæŦį˛å
+夸å įåēæŦį˛åææč´¨ååä¸å
+č´¨åä¸åįĩåææåå
+ååææåå
+ååææåį§įŠč´¨
+åį§įŠč´¨ææåˇĨå ˇ
+åŧĻææææä¸čĨŋīŧå æŦåˇĨå ˇ
+äŊ å¯čŊäŧéŽ
+æįåˇĨå ˇæ˛ĄæåŽäŊåŊĸåŧ
+äŊæ¯čŋäēåˇĨå ˇįåå¨éčĻäžéäēå ļäģåˇĨå ˇ
+æ¯åĻ䏿åŧååŽåž
+æ˛ĄæįŠč´¨īŧčŋįŠæåŋäšæ˛ĄæäģģäŊæäš
+åįįæ°åĻå Ŧåŧ
+æ¯åĻ
+e^(i*pi)+1=0
+æäģŦåį°åŽäšæ¯åēäēįŠč´¨
+æäģĨæ˛ĄæįŠč´¨å°ąåį°ä¸äēåŽ
+åį°ä¸äēįäēįŠæ¯æ˛Ąææäšį
+æ¯åĻå éĨäšå¤æäģäščŋäēä¸čĨŋ
+éŊæ¯æ æäšį
+åˇŽä¸å¤å°ąæ¯čŋäē
\ No newline at end of file
diff --git a/res/text/xuanxue2.txt b/res/text/xuanxue2.txt
new file mode 100644
index 00000000..033c53e4
--- /dev/null
+++ b/res/text/xuanxue2.txt
@@ -0,0 +1,9 @@
+įčŋä¸ĒåŋĢéæåēįäģŖį īŧ
+äģå¯äģĨååŠįæŗæžå°į´ æ°īŧ
+æäģŦåį°į´ æ°éĩåžĒįä¸ä¸Ēč§åžīŧ
+ä¸éĩåžĒčŋä¸Ēč§åžįæ°å°ąä¸æ¯į´ æ°īŧ
+䏿¯į´ æ°įæ°ä𿝿æäšįīŧ
+æ¯åĻ蝴4īŧ
+č䏿¯į´ æ°įæ°å¯äģĨåč§Ŗč´¨å æ°īŧ
+åžå°tan(x+y)=(tanx+tany)/(1-tanxtany)īŧ
+æäģŦåæčŋįģæ°æŽäģŖå Ĩīŧå¯äģĨåžå°ä쿝tree
diff --git a/res/textures.png b/res/textures.png
deleted file mode 100644
index d36112f4..00000000
Binary files a/res/textures.png and /dev/null differ
diff --git a/res/textures/hud/cross.png b/res/textures/hud/cross.png
new file mode 100644
index 00000000..89369bd6
Binary files /dev/null and b/res/textures/hud/cross.png differ
diff --git a/res/textures/hud/inventory.png b/res/textures/hud/inventory.png
new file mode 100644
index 00000000..b56a8950
Binary files /dev/null and b/res/textures/hud/inventory.png differ
diff --git a/res/textures/hud/inventory_chosen.png b/res/textures/hud/inventory_chosen.png
new file mode 100644
index 00000000..b088e7f3
Binary files /dev/null and b/res/textures/hud/inventory_chosen.png differ
diff --git a/save.dat b/save.dat
deleted file mode 100644
index adedd395..00000000
Binary files a/save.dat and /dev/null differ
diff --git a/settings.gradle b/settings.gradle
index 21e54987..04e5c6f4 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -7,4 +7,5 @@
* in the user manual at https://docs.gradle.org/6.0/userguide/multi_project_builds.html
*/
-rootProject.name = 'CraftGame'
+rootProject.name = 'RealCraftGame'
+
diff --git a/splash/splash.pdn b/splash/splash.pdn
new file mode 100644
index 00000000..dce5bfef
Binary files /dev/null and b/splash/splash.pdn differ
diff --git a/splash/splash.png b/splash/splash.png
new file mode 100644
index 00000000..5a008e29
Binary files /dev/null and b/splash/splash.png differ
diff --git a/src/main/java/ch/project/inter/SimplexNoise.java b/src/main/java/ch/project/inter/SimplexNoise.java
new file mode 100644
index 00000000..cf701972
--- /dev/null
+++ b/src/main/java/ch/project/inter/SimplexNoise.java
@@ -0,0 +1,457 @@
+package ch.project.inter;
+
+/**
+ * Simplex Noise in 2D, 3D and 4D
+ */
+public class SimplexNoise {
+
+ private static int grad3[][] = { { 1, 1, 0 }, { -1, 1, 0 }, { 1, -1, 0 }, { -1, -1, 0 }, { 1, 0, 1 }, { -1, 0, 1 },
+ { 1, 0, -1 }, { -1, 0, -1 }, { 0, 1, 1 }, { 0, -1, 1 }, { 0, 1, -1 }, { 0, -1, -1 } };
+
+ private static int grad4[][] = { { 0, 1, 1, 1 }, { 0, 1, 1, -1 }, { 0, 1, -1, 1 }, { 0, 1, -1, -1 },
+ { 0, -1, 1, 1 }, { 0, -1, 1, -1 }, { 0, -1, -1, 1 }, { 0, -1, -1, -1 }, { 1, 0, 1, 1 }, { 1, 0, 1, -1 },
+ { 1, 0, -1, 1 }, { 1, 0, -1, -1 }, { -1, 0, 1, 1 }, { -1, 0, 1, -1 }, { -1, 0, -1, 1 }, { -1, 0, -1, -1 },
+ { 1, 1, 0, 1 }, { 1, 1, 0, -1 }, { 1, -1, 0, 1 }, { 1, -1, 0, -1 }, { -1, 1, 0, 1 }, { -1, 1, 0, -1 },
+ { -1, -1, 0, 1 }, { -1, -1, 0, -1 }, { 1, 1, 1, 0 }, { 1, 1, -1, 0 }, { 1, -1, 1, 0 }, { 1, -1, -1, 0 },
+ { -1, 1, 1, 0 }, { -1, 1, -1, 0 }, { -1, -1, 1, 0 }, { -1, -1, -1, 0 } };
+
+ private static int p[] = { 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30,
+ 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117,
+ 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139,
+ 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40,
+ 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130,
+ 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118,
+ 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248,
+ 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113,
+ 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241,
+ 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50,
+ 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156,
+ 180 };
+
+ // To remove the need for index wrapping, double the permutation table length
+ private static int perm[] = new int[512];
+
+ static {
+ for (int i = 0; i < 512; i++)
+ perm[i] = p[i & 255];
+ }
+
+ // A lookup table to traverse the simplex around a given point in 4D.
+ // Details can be found where this table is used, in the 4D noise method.
+ private static int simplex[][] = { { 0, 1, 2, 3 }, { 0, 1, 3, 2 }, { 0, 0, 0, 0 }, { 0, 2, 3, 1 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 2, 3, 0 }, { 0, 2, 1, 3 }, { 0, 0, 0, 0 }, { 0, 3, 1, 2 },
+ { 0, 3, 2, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 3, 2, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 1, 2, 0, 3 }, { 0, 0, 0, 0 }, { 1, 3, 0, 2 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 2, 3, 0, 1 }, { 2, 3, 1, 0 }, { 1, 0, 2, 3 }, { 1, 0, 3, 2 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 2, 0, 3, 1 }, { 0, 0, 0, 0 }, { 2, 1, 3, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 2, 0, 1, 3 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 3, 0, 1, 2 },
+ { 3, 0, 2, 1 }, { 0, 0, 0, 0 }, { 3, 1, 2, 0 }, { 2, 1, 0, 3 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 }, { 3, 1, 0, 2 }, { 0, 0, 0, 0 }, { 3, 2, 0, 1 }, { 3, 2, 1, 0 } };
+
+ // This method is a *lot* faster than using (int)Math.floor(x)
+ private static int fastfloor(double x) {
+ return x > 0 ? (int) x : (int) x - 1;
+ }
+
+ private static double dot(int g[], double x, double y) {
+ return g[0] * x + g[1] * y;
+ }
+
+ private static double dot(int g[], double x, double y, double z) {
+ return g[0] * x + g[1] * y + g[2] * z;
+ }
+
+ private static double dot(int g[], double x, double y, double z, double w) {
+ return g[0] * x + g[1] * y + g[2] * z + g[3] * w;
+ }
+
+ /**
+ * Simplex Noise.
+ */
+ public static double noise(double xin, double yin, double frequencyX, double frequencyY, double persistance,
+ int octaves) {
+ double resultNoise = 0.0;
+ double amplitude = 1.0;
+ double maxValue = 0.0;
+ for (int i = 0; i < octaves; i++) {
+ resultNoise += noise(xin * frequencyX, yin * frequencyY) * amplitude;
+ frequencyX *= 2;
+ frequencyY *= 2;
+ maxValue += amplitude;
+ amplitude *= persistance;
+ }
+ return resultNoise / maxValue;
+ }
+
+ /**
+ * 2D Simplex Noise.
+ */
+ public static double noise(double xin, double yin) {
+ double n0, n1, n2;
+ // Noise contributions from the three corners
+ // Skew the input space to determine which simplex cell we're in
+ final double F2 = 0.5 * (Math.sqrt(3.0) - 1.0);
+ double s = (xin + yin) * F2;
+ // Hairy factor for 2D
+ int i = fastfloor(xin + s);
+ int j = fastfloor(yin + s);
+ final double G2 = (3.0 - Math.sqrt(3.0)) / 6.0;
+ double t = (i + j) * G2;
+ double X0 = i - t;
+ // Unskew the cell origin back to (x,y) space
+ double Y0 = j - t;
+ double x0 = xin - X0;
+ // The x,y distances from the cell origin
+ double y0 = yin - Y0;
+ // For the 2D case, the simplex shape is an equilateral triangle.
+ // Determine which simplex we are in.
+ int i1, j1;
+ // Offsets for second (middle) corner of simplex in (i,j) coords
+ if (x0 > y0) {
+ i1 = 1;
+ j1 = 0;
+ }
+ // lower triangle, XY order: (0,0)->(1,0)->(1,1)
+ else {
+ i1 = 0;
+ j1 = 1;
+ }
+ // upper triangle, YX order: (0,0)->(0,1)->(1,1)
+ // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
+ // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
+ // c = (3-sqrt(3))/6
+ double x1 = x0 - i1 + G2;
+ // Offsets for middle corner in (x,y) unskewed coords
+ double y1 = y0 - j1 + G2;
+ double x2 = x0 - 1.0 + 2.0 * G2;
+ // Offsets for last corner in (x,y) unskewed coords
+ double y2 = y0 - 1.0 + 2.0 * G2;
+ // Work out the hashed gradient indices of the three simplex corners
+ int ii = i & 255;
+ int jj = j & 255;
+ int gi0 = perm[ii + perm[jj]] % 12;
+ int gi1 = perm[ii + i1 + perm[jj + j1]] % 12;
+ int gi2 = perm[ii + 1 + perm[jj + 1]] % 12;
+ // Calculate the contribution from the three corners
+ double t0 = 0.5 - x0 * x0 - y0 * y0;
+ if (t0 < 0)
+ n0 = 0.0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * dot(grad3[gi0], x0, y0);
+ // (x,y) of grad3 used for 2D gradient
+ }
+ double t1 = 0.5 - x1 * x1 - y1 * y1;
+ if (t1 < 0)
+ n1 = 0.0;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
+ }
+ double t2 = 0.5 - x2 * x2 - y2 * y2;
+ if (t2 < 0)
+ n2 = 0.0;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
+ }
+ // Add contributions from each corner to get the final noise value.
+ // The result is scaled to return values in the interval [-1,1].
+ return 70.0 * (n0 + n1 + n2);
+ }
+
+ /**
+ * 3D Simplex Noise.
+ */
+ public static double noise(double xin, double yin, double zin) {
+ double n0, n1, n2, n3;
+ // Noise contributions from the four corners
+ // Skew the input space to determine which simplex cell we're in
+ final double F3 = 1.0 / 3.0;
+ double s = (xin + yin + zin) * F3;
+ // Very nice and simple skew factor for 3D
+ int i = fastfloor(xin + s);
+ int j = fastfloor(yin + s);
+ int k = fastfloor(zin + s);
+ final double G3 = 1.0 / 6.0;
+ // Very nice and simple unskew factor, too
+ double t = (i + j + k) * G3;
+ double X0 = i - t;
+ // Unskew the cell origin back to (x,y,z) space
+ double Y0 = j - t;
+ double Z0 = k - t;
+ double x0 = xin - X0;
+ // The x,y,z distances from the cell origin
+ double y0 = yin - Y0;
+ double z0 = zin - Z0;
+ // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
+ // Determine which simplex we are in.
+ int i1, j1, k1;
+ // Offsets for second corner of simplex in (i,j,k) coords
+ int i2, j2, k2;
+ // Offsets for third corner of simplex in (i,j,k) coords
+ if (x0 >= y0) {
+ if (y0 >= z0) {
+ i1 = 1;
+ j1 = 0;
+ k1 = 0;
+ i2 = 1;
+ j2 = 1;
+ k2 = 0;
+ }
+ // X Y Z order
+ else if (x0 >= z0) {
+ i1 = 1;
+ j1 = 0;
+ k1 = 0;
+ i2 = 1;
+ j2 = 0;
+ k2 = 1;
+ }
+ // X Z Y order
+ else {
+ i1 = 0;
+ j1 = 0;
+ k1 = 1;
+ i2 = 1;
+ j2 = 0;
+ k2 = 1;
+ }
+ // Z X Y order
+ } else {
+ // x0 y0) ? 32 : 0;
+ int c2 = (x0 > z0) ? 16 : 0;
+ int c3 = (y0 > z0) ? 8 : 0;
+ int c4 = (x0 > w0) ? 4 : 0;
+ int c5 = (y0 > w0) ? 2 : 0;
+ int c6 = (z0 > w0) ? 1 : 0;
+ int c = c1 + c2 + c3 + c4 + c5 + c6;
+ int i1, j1, k1, l1;
+ // The integer offsets for the second simplex corner
+ int i2, j2, k2, l2;
+ // The integer offsets for the third simplex corner
+ int i3, j3, k3, l3;
+ // The integer offsets for the fourth simplex corner
+ // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order.
+ // Many values of c will never occur, since e.g. x>y>z>w makes x= 3 ? 1 : 0;
+ j1 = simplex[c][1] >= 3 ? 1 : 0;
+ k1 = simplex[c][2] >= 3 ? 1 : 0;
+ l1 = simplex[c][3] >= 3 ? 1 : 0;
+ // The number 2 in the "simplex" array is at the second largest coordinate.
+ i2 = simplex[c][0] >= 2 ? 1 : 0;
+ j2 = simplex[c][1] >= 2 ? 1 : 0;
+ k2 = simplex[c][2] >= 2 ? 1 : 0;
+ l2 = simplex[c][3] >= 2 ? 1 : 0;
+ // The number 1 in the "simplex" array is at the second smallest coordinate.
+ i3 = simplex[c][0] >= 1 ? 1 : 0;
+ j3 = simplex[c][1] >= 1 ? 1 : 0;
+ k3 = simplex[c][2] >= 1 ? 1 : 0;
+ l3 = simplex[c][3] >= 1 ? 1 : 0;
+ // The fifth corner has all coordinate offsets = 1, so no need to look that up.
+ double x1 = x0 - i1 + G4;
+ // Offsets for second corner in (x,y,z,w) coords
+ double y1 = y0 - j1 + G4;
+ double z1 = z0 - k1 + G4;
+ double w1 = w0 - l1 + G4;
+ double x2 = x0 - i2 + 2.0 * G4;
+ // Offsets for third corner in (x,y,z,w) coords
+ double y2 = y0 - j2 + 2.0 * G4;
+ double z2 = z0 - k2 + 2.0 * G4;
+ double w2 = w0 - l2 + 2.0 * G4;
+ double x3 = x0 - i3 + 3.0 * G4;
+ // Offsets for fourth corner in (x,y,z,w) coords
+ double y3 = y0 - j3 + 3.0 * G4;
+ double z3 = z0 - k3 + 3.0 * G4;
+ double w3 = w0 - l3 + 3.0 * G4;
+ double x4 = x0 - 1.0 + 4.0 * G4;
+ // Offsets for last corner in (x,y,z,w) coords
+ double y4 = y0 - 1.0 + 4.0 * G4;
+ double z4 = z0 - 1.0 + 4.0 * G4;
+ double w4 = w0 - 1.0 + 4.0 * G4;
+ // Work out the hashed gradient indices of the five simplex corners
+ int ii = i & 255;
+ int jj = j & 255;
+ int kk = k & 255;
+ int ll = l & 255;
+ int gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32;
+ int gi1 = perm[ii + i1 + perm[jj + j1 + perm[kk + k1 + perm[ll + l1]]]] % 32;
+ int gi2 = perm[ii + i2 + perm[jj + j2 + perm[kk + k2 + perm[ll + l2]]]] % 32;
+ int gi3 = perm[ii + i3 + perm[jj + j3 + perm[kk + k3 + perm[ll + l3]]]] % 32;
+ int gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
+ // Calculate the contribution from the five corners
+ double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
+ if (t0 < 0)
+ n0 = 0.0;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
+ }
+ double t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
+ if (t1 < 0)
+ n1 = 0.0;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
+ }
+ double t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
+ if (t2 < 0)
+ n2 = 0.0;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
+ }
+ double t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
+ if (t3 < 0)
+ n3 = 0.0;
+ else {
+ t3 *= t3;
+ n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
+ }
+ double t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
+ if (t4 < 0)
+ n4 = 0.0;
+ else {
+ t4 *= t4;
+ n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
+ }
+ // Sum up and scale the result to cover the range [-1,1]
+ return 27.0 * (n0 + n1 + n2 + n3 + n4);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/javaherobrine/GameUtils.java b/src/main/java/io/github/javaherobrine/GameUtils.java
new file mode 100644
index 00000000..d0cdba65
--- /dev/null
+++ b/src/main/java/io/github/javaherobrine/GameUtils.java
@@ -0,0 +1,15 @@
+package io.github.javaherobrine;
+import org.lwjgl.system.NativeType;
+/**
+ * Code from Java_Herobrine, but only memory-related functions are provided
+ */
+public final class GameUtils {
+ static {
+ System.load("/home/javaherobrine/libJNI.so");
+ }
+ public static native long address(byte[] b);
+ /**
+ * Tell JVM that the memory can be freed
+ */
+ public static native void allowGC(@NativeType("void*") long addr,byte[] b);
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Matrix.java b/src/main/java/org/lwjgl/utils/vector/Matrix.java
new file mode 100644
index 00000000..d3ffa375
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Matrix.java
@@ -0,0 +1,131 @@
+/*
+ * 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 org.lwjgl.utils.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
+ * @version $Revision$ $Id$
+ */
+public abstract class Matrix implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 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();
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/Matrix2f.java b/src/main/java/org/lwjgl/utils/vector/Matrix2f.java
new file mode 100644
index 00000000..71ff27fa
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Matrix2f.java
@@ -0,0 +1,416 @@
+/*
+ * 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 org.lwjgl.utils.vector;
+
+import java.nio.FloatBuffer;
+
+/**
+ * Holds a 2x2 matrix
+ *
+ * @author cix_foo
+ * @version $Revision$ $Id$
+ */
+
+public class Matrix2f extends Matrix {
+
+ 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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 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 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;
+ }
+
+ /**
+ * 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 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;
+ }
+
+ public static Matrix2f setZero(Matrix2f src) {
+ src.m00 = 0.0f;
+ src.m01 = 0.0f;
+ src.m10 = 0.0f;
+ src.m11 = 0.0f;
+ return src;
+ }
+
+ /**
+ * Load from another matrix
+ *
+ * @param src The source matrix
+ * @return this
+ */
+ public Matrix2f load(Matrix2f src) {
+ return load(src, this);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Invert this matrix
+ *
+ * @return this if successful, null otherwise
+ */
+ public Matrix invert() {
+ return invert(this, this);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Set this matrix to be the identity matrix.
+ *
+ * @return this
+ */
+ public Matrix setIdentity() {
+ return setIdentity(this);
+ }
+
+ /**
+ * Set this matrix to 0.
+ *
+ * @return this
+ */
+ public Matrix setZero() {
+ return setZero(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.lwjgl.vector.Matrix#determinant()
+ */
+ public float determinant() {
+ return m00 * m11 - m01 * m10;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/Matrix3f.java b/src/main/java/org/lwjgl/utils/vector/Matrix3f.java
new file mode 100644
index 00000000..14105f35
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Matrix3f.java
@@ -0,0 +1,481 @@
+package org.lwjgl.utils.vector;
+
+import java.nio.FloatBuffer;
+
+public class Matrix3f extends Matrix {
+
+ 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;
+ }
+
+ /**
+ * 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 static Matrix3f translate(Vector2f vec, Matrix3f src, Matrix3f dest) {
+ if (dest == null)
+ dest = new Matrix3f();
+
+ dest.m20 += src.m00 * vec.x + src.m10 * vec.y;
+ dest.m21 += src.m01 * vec.x + src.m11 * vec.y;
+ dest.m22 += src.m02 * vec.x + src.m12 * vec.y;
+
+ return dest;
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Matrix4f.java b/src/main/java/org/lwjgl/utils/vector/Matrix4f.java
new file mode 100644
index 00000000..16d576ec
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Matrix4f.java
@@ -0,0 +1,871 @@
+/*
+ * 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 org.lwjgl.utils.vector;
+
+import java.nio.FloatBuffer;
+
+/**
+ * Holds a 4x4 float matrix.
+ *
+ * @author foo
+ */
+public class Matrix4f extends Matrix {
+ 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);
+ }
+
+ /**
+ * 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 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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 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 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 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 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;
+ }
+
+ /**
+ * 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 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 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;
+ }
+
+ /**
+ * 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 this matrix to 0.
+ *
+ * @return this
+ */
+ public Matrix setZero() {
+ return setZero(this);
+ }
+
+ /**
+ * Load from another matrix4f
+ *
+ * @param src The source matrix
+ * @return this
+ */
+ public Matrix4f load(Matrix4f src) {
+ return load(src, this);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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 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);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * @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;
+ }
+
+ /**
+ * Invert this matrix
+ *
+ * @return this if successful, null otherwise
+ */
+ public Matrix invert() {
+ return invert(this, this);
+ }
+
+ /**
+ * 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);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/ReadableVector.java b/src/main/java/org/lwjgl/utils/vector/ReadableVector.java
new file mode 100644
index 00000000..adef6d23
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/ReadableVector.java
@@ -0,0 +1,56 @@
+/*
+ * 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 org.lwjgl.utils.vector;
+
+import xueli.utils.buffer.LotsOfByteBuffer;
+
+/**
+ * @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
+ */
+ void store(LotsOfByteBuffer buf);
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/ReadableVector2f.java b/src/main/java/org/lwjgl/utils/vector/ReadableVector2f.java
new file mode 100644
index 00000000..72648a2b
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/ReadableVector2f.java
@@ -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 org.lwjgl.utils.vector;
+
+/**
+ * @author foo
+ */
+public interface ReadableVector2f extends ReadableVector {
+ /**
+ * @return x
+ */
+ float getX();
+
+ /**
+ * @return y
+ */
+ float getY();
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/ReadableVector3f.java b/src/main/java/org/lwjgl/utils/vector/ReadableVector3f.java
new file mode 100644
index 00000000..bd1c8342
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/ReadableVector3f.java
@@ -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 org.lwjgl.utils.vector;
+
+/**
+ * @author foo
+ */
+public interface ReadableVector3f extends ReadableVector2f {
+ /**
+ * @return z
+ */
+ float getZ();
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/ReadableVector4f.java b/src/main/java/org/lwjgl/utils/vector/ReadableVector4f.java
new file mode 100644
index 00000000..08ca34cd
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/ReadableVector4f.java
@@ -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 org.lwjgl.utils.vector;
+
+/**
+ * @author foo
+ */
+public interface ReadableVector4f extends ReadableVector3f {
+
+ /**
+ * @return w
+ */
+ float getW();
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector.java b/src/main/java/org/lwjgl/utils/vector/Vector.java
new file mode 100644
index 00000000..5b32c4c8
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector.java
@@ -0,0 +1,107 @@
+/*
+ * 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 org.lwjgl.utils.vector;
+
+import java.io.Serializable;
+import java.nio.FloatBuffer;
+
+import xueli.game2.renderer.legacy.buffer.BufferStorable;
+
+/**
+ * Base class for vectors.
+ *
+ * @author cix_foo
+ * @version $Revision$ $Id$
+ */
+public abstract class Vector implements Serializable, ReadableVector, BufferStorable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 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");
+ }
+
+ /**
+ * Scale this vector
+ *
+ * @param scale The scale factor
+ * @return this
+ */
+ public abstract Vector scale(float scale);
+
+ public abstract int getSize();
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector2d.java b/src/main/java/org/lwjgl/utils/vector/Vector2d.java
new file mode 100644
index 00000000..05aba892
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector2d.java
@@ -0,0 +1,42 @@
+package org.lwjgl.utils.vector;
+
+import java.util.Objects;
+
+public class Vector2d {
+
+ public double x, y;
+
+ public Vector2d() {
+ this.x = this.y = 0;
+ }
+
+ public Vector2d(double x, double y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Vector2d vector2d = (Vector2d) o;
+ return Double.compare(vector2d.x, x) == 0 && Double.compare(vector2d.y, y) == 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(x, y);
+ }
+
+ @Override
+ public String toString() {
+ return "Vector2d{" + "x=" + x + ", y=" + y + '}';
+ }
+
+ public static Vector2d add(Vector2d v1, Vector2d v2) {
+ return new Vector2d(v1.x + v2.x, v1.y + v2.y);
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector2f.java b/src/main/java/org/lwjgl/utils/vector/Vector2f.java
new file mode 100644
index 00000000..ba4c4b76
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector2f.java
@@ -0,0 +1,321 @@
+/*
+ * 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 org.lwjgl.utils.vector;
+
+import java.nio.FloatBuffer;
+
+import xueli.utils.buffer.LotsOfByteBuffer;
+
+/**
+ * Holds a 2-tuple vector.
+ *
+ * @author cix_foo
+ * @version $Revision$ $Id$
+ */
+
+public class Vector2f extends Vector implements 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);
+ }
+
+ /**
+ * 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;
+ }
+ }
+
+ /*
+ * (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;
+ }
+
+ /**
+ * Store this vector in a FloatBuffer
+ *
+ * @param buf The buffer to store it in, at the current position
+ */
+ public void store(LotsOfByteBuffer buf) {
+ buf.putFloat(x);
+ buf.putFloat(y);
+ }
+
+ /**
+ * 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;
+ }
+
+ @Override
+ public int getSize() {
+ return 2 * Float.BYTES;
+ }
+
+ /*
+ * (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;
+ }
+
+ /**
+ * Set X
+ *
+ * @param x
+ */
+ public final void setX(float x) {
+ this.x = x;
+ }
+
+ /**
+ * @return y
+ */
+ public final float getY() {
+ return y;
+ }
+
+ /**
+ * 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;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector2i.java b/src/main/java/org/lwjgl/utils/vector/Vector2i.java
new file mode 100644
index 00000000..de070576
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector2i.java
@@ -0,0 +1,45 @@
+package org.lwjgl.utils.vector;
+
+import java.util.Objects;
+
+public class Vector2i implements Comparable {
+
+ public int x, y;
+
+ public Vector2i() {
+ this.x = this.y = 0;
+ }
+
+ public Vector2i(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ @Override
+ public String toString() {
+ return "Vector2i{" + "x=" + x + ", y=" + y + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Vector2i vector2i = (Vector2i) o;
+ return x == vector2i.x && y == vector2i.y;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(x, y);
+ }
+
+ @Override
+ public int compareTo(Vector2i o) {
+ if (o == null)
+ return this.hashCode();
+ return this.hashCode() - o.hashCode();
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector2s.java b/src/main/java/org/lwjgl/utils/vector/Vector2s.java
new file mode 100644
index 00000000..744dfa0d
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector2s.java
@@ -0,0 +1,16 @@
+package org.lwjgl.utils.vector;
+
+import java.io.Serializable;
+
+public class Vector2s implements Serializable {
+
+ private static final long serialVersionUID = 5420508255322410063L;
+
+ public short x, y;
+
+ public Vector2s(short x, short y) {
+ this.x = x;
+ this.y = y;
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector3b.java b/src/main/java/org/lwjgl/utils/vector/Vector3b.java
new file mode 100644
index 00000000..a5d0a4f9
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector3b.java
@@ -0,0 +1,61 @@
+package org.lwjgl.utils.vector;
+
+import java.util.Objects;
+
+public class Vector3b {
+
+ public byte x, y, z;
+
+ public Vector3b(byte x, byte y, byte z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public byte getX() {
+ return x;
+ }
+
+ public void setX(byte x) {
+ this.x = x;
+ }
+
+ public byte getY() {
+ return y;
+ }
+
+ public void setY(byte y) {
+ this.y = y;
+ }
+
+ public byte getZ() {
+ return z;
+ }
+
+ public void setZ(byte z) {
+ this.z = z;
+ }
+
+ @Override
+ public String toString() {
+ return "Vector3b [x=" + x + ", y=" + y + ", z=" + z + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(x, y, z);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Vector3b other = (Vector3b) obj;
+ return x == other.x && y == other.y && z == other.z;
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector3d.java b/src/main/java/org/lwjgl/utils/vector/Vector3d.java
new file mode 100644
index 00000000..f0fb097c
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector3d.java
@@ -0,0 +1,51 @@
+package org.lwjgl.utils.vector;
+
+import java.util.Objects;
+
+public class Vector3d {
+
+ public double x, y, z;
+
+ public Vector3d() {
+ this.x = this.y = this.z = 0;
+ }
+
+ public Vector3d(double x, double y, double z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public void normalize() {
+ double length = Math.sqrt(x * x + y * y + z * z);
+ this.x /= length;
+ this.y /= length;
+ this.z /= length;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Vector3d vector3d = (Vector3d) o;
+ return Double.compare(vector3d.x, x) == 0 && Double.compare(vector3d.y, y) == 0
+ && Double.compare(vector3d.z, z) == 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(x, y, z);
+ }
+
+ @Override
+ public String toString() {
+ return "Vector3d{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
+ }
+
+ public static Vector3d add(Vector3d v1, Vector3d v2) {
+ return new Vector3d(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector3f.java b/src/main/java/org/lwjgl/utils/vector/Vector3f.java
new file mode 100644
index 00000000..00d1d771
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector3f.java
@@ -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 org.lwjgl.utils.vector;
+
+import java.nio.FloatBuffer;
+
+import xueli.utils.buffer.LotsOfByteBuffer;
+
+/**
+ * Holds a 3-tuple vector.
+ *
+ * @author cix_foo
+ * @version $Revision$ $Id$
+ */
+
+public class Vector3f extends Vector implements 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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.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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (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;
+
+ }
+
+ @Override
+ public int getSize() {
+ return 3 * Float.BYTES;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.lwjgl.vector.Vector#store(FloatBuffer)
+ */
+ public void store(LotsOfByteBuffer buf) {
+ buf.putFloat(x);
+ buf.putFloat(y);
+ buf.putFloat(z);
+ }
+
+ /*
+ * (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;
+ }
+
+ /**
+ * Set X
+ *
+ * @param x
+ */
+ public final void setX(float x) {
+ this.x = x;
+ }
+
+ /**
+ * @return y
+ */
+ public final float getY() {
+ return y;
+ }
+
+ /**
+ * Set Y
+ *
+ * @param y
+ */
+ public final void setY(float y) {
+ this.y = y;
+ }
+
+ /*
+ * (Overrides)
+ *
+ * @see org.lwjgl.vector.ReadableVector3f#getZ()
+ */
+ public float getZ() {
+ return z;
+ }
+
+ /**
+ * Set Z
+ *
+ * @param z
+ */
+ public void setZ(float z) {
+ this.z = 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;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector3i.java b/src/main/java/org/lwjgl/utils/vector/Vector3i.java
new file mode 100644
index 00000000..b300653f
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector3i.java
@@ -0,0 +1,73 @@
+package org.lwjgl.utils.vector;
+
+import java.util.Objects;
+
+public class Vector3i {
+
+ public int x, y, z;
+
+ public Vector3i(int x, int y, int z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public Vector3i(Vector3d doubleVector) {
+ this.x = (int) Math.floor(doubleVector.x);
+ this.y = (int) Math.floor(doubleVector.y);
+ this.z = (int) Math.floor(doubleVector.z);
+
+ }
+
+ public Vector3i(Vector3f floatVector) {
+ this.x = (int) Math.floor(floatVector.x);
+ this.y = (int) Math.floor(floatVector.y);
+ this.z = (int) Math.floor(floatVector.z);
+
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ public int getZ() {
+ return z;
+ }
+
+ @Override
+ public String toString() {
+ return "Vector3i [x=" + x + ", y=" + y + ", z=" + z + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(x, y, z);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Vector3i other = (Vector3i) obj;
+ if (x != other.x)
+ return false;
+ if (y != other.y)
+ return false;
+ if (z != other.z)
+ return false;
+ return true;
+ }
+
+ public static Vector3i add(Vector3i v1, Vector3i v2) {
+ return new Vector3i(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector4b.java b/src/main/java/org/lwjgl/utils/vector/Vector4b.java
new file mode 100644
index 00000000..f63c9aa2
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector4b.java
@@ -0,0 +1,14 @@
+package org.lwjgl.utils.vector;
+
+public class Vector4b {
+
+ public byte x, y, z, w;
+
+ public Vector4b(byte x, byte y, byte z, byte w) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.w = w;
+ }
+
+}
diff --git a/src/main/java/org/lwjgl/utils/vector/Vector4f.java b/src/main/java/org/lwjgl/utils/vector/Vector4f.java
new file mode 100644
index 00000000..7c4c4eee
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/Vector4f.java
@@ -0,0 +1,384 @@
+/*
+ * 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 org.lwjgl.utils.vector;
+
+import java.nio.FloatBuffer;
+
+import xueli.utils.buffer.LotsOfByteBuffer;
+
+/**
+ * Holds a 4-tuple vector.
+ *
+ * @author cix_foo
+ * @version $Revision$ $Id$
+ */
+
+public class Vector4f extends Vector implements 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);
+ }
+
+ public Vector4f(float f) {
+ this(f, f, f, f);
+ }
+
+ /**
+ * 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;
+ }
+ }
+
+ /**
+ * 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.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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (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;
+ }
+
+ @Override
+ public int getSize() {
+ return 4 * Float.BYTES;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.lwjgl.vector.Vector#store(FloatBuffer)
+ */
+ public void store(LotsOfByteBuffer buf) {
+ buf.putFloat(x);
+ buf.putFloat(y);
+ buf.putFloat(z);
+ buf.putFloat(w);
+
+ }
+
+ public String toString() {
+ return "Vector4f: " + x + " " + y + " " + z + " " + w;
+ }
+
+ /**
+ * @return x
+ */
+ public final float getX() {
+ return x;
+ }
+
+ /**
+ * Set X
+ *
+ * @param x
+ */
+ public final void setX(float x) {
+ this.x = x;
+ }
+
+ /**
+ * @return y
+ */
+ public final float getY() {
+ return y;
+ }
+
+ /**
+ * Set Y
+ *
+ * @param y
+ */
+ public final void setY(float y) {
+ this.y = y;
+ }
+
+ /*
+ * (Overrides)
+ *
+ * @see org.lwjgl.vector.ReadableVector3f#getZ()
+ */
+ public float getZ() {
+ return z;
+ }
+
+ /**
+ * Set Z
+ *
+ * @param z
+ */
+ public void setZ(float z) {
+ this.z = z;
+ }
+
+ /*
+ * (Overrides)
+ *
+ * @see org.lwjgl.vector.ReadableVector3f#getZ()
+ */
+ public float getW() {
+ return w;
+ }
+
+ /**
+ * Set W
+ *
+ * @param w
+ */
+ public void setW(float w) {
+ this.w = 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;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/WritableVector2f.java b/src/main/java/org/lwjgl/utils/vector/WritableVector2f.java
new file mode 100644
index 00000000..15e66c6c
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/WritableVector2f.java
@@ -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 org.lwjgl.utils.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);
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/WritableVector3f.java b/src/main/java/org/lwjgl/utils/vector/WritableVector3f.java
new file mode 100644
index 00000000..13fc430d
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/WritableVector3f.java
@@ -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 org.lwjgl.utils.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);
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/lwjgl/utils/vector/WritableVector4f.java b/src/main/java/org/lwjgl/utils/vector/WritableVector4f.java
new file mode 100644
index 00000000..f20ba3ef
--- /dev/null
+++ b/src/main/java/org/lwjgl/utils/vector/WritableVector4f.java
@@ -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 org.lwjgl.utils.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);
+
+}
\ No newline at end of file
diff --git a/src/main/java/riven/PerlinNoise.java b/src/main/java/riven/PerlinNoise.java
new file mode 100644
index 00000000..4b26106c
--- /dev/null
+++ b/src/main/java/riven/PerlinNoise.java
@@ -0,0 +1,352 @@
+package riven;
+
+import java.util.Random;
+
+import xueli.mcremake.registry.PocketNativeType;
+
+/**
+ *
+ * Adapted from Riven's Implementation of Perlin noise. Modified it to be more
+ * OOP rather than C like.
+ *
+ *
+ * @author Matthew A. Johnston (WarmWaffles)
+ *
+ */
+@PocketNativeType(version = "0.1.3", value = "ImprovedNoise")
+public class PerlinNoise {
+
+ private static final double[] pow = new double[32];
+ static {
+ for (int i = 0; i < pow.length; i++)
+ pow[i] = Math.pow(2, i);
+
+ }
+
+ @PocketNativeType("*((_DWORD*)this + 2)")
+ private double xo;
+ @PocketNativeType("*((_DWORD*)this + 3)")
+ private double yo;
+ @PocketNativeType("*((_DWORD*)this + 4)")
+ private double zo;
+
+ @PocketNativeType("*((_DWORD*)v4_this + 5)")
+ private int[] perm;
+
+ /**
+ * Builds the Perlin Noise generator.
+ *
+ * @param seed The seed for the random number generator
+ */
+ public PerlinNoise(int seed) {
+ this(new Random(seed));
+ }
+
+ public PerlinNoise(Random r) {
+ this.xo = r.nextDouble(256.0); // Origin: (double)random.genrand_int32() * 2.32830644e-10
+ this.yo = r.nextDouble(256.0);
+ this.zo = r.nextDouble(256.0);
+
+ perm = new int[512];
+ for (int i = 0; i < 256; i++) {
+ perm[i] = i;
+ }
+
+ for (int i = 0; i < 256; i++) {
+ int v3 = r.nextInt(256 - i);
+
+ int v4 = perm[i];
+ perm[i] = perm[i + v3];
+ perm[i + v3] = v4;
+
+ perm[i + 256] = perm[i];
+
+ }
+
+// if (permutation.length != 256)
+// throw new IllegalStateException();
+
+// for (int i = 0; i < 256; i++)
+// perm[256 + i] = perm[i] = permutation[i];
+
+ }
+
+ /**
+ *
+ * @param x
+ * @param y
+ * @param z
+ */
+ public void offset(double x, double y, double z) {
+ this.xo = x;
+ this.yo = y;
+ this.zo = z;
+ }
+
+ /**
+ *
+ * @param x
+ * @param y
+ * @param z
+ * @param octaves
+ * @return
+ */
+ public double smoothNoise(double x, double y, double z, int octaves) {
+ double height = 0.0;
+ for (int octave = 1; octave <= octaves; octave++)
+ height += noise(x, y, z, octave);
+ return height;
+ }
+
+ /**
+ *
+ * @param x
+ * @param y
+ * @param z
+ * @param octaves
+ * @return
+ */
+ public double turbulentNoise(double x, double y, double z, int octaves) {
+ double height = 0.0;
+ for (int octave = 1; octave <= octaves; octave++) {
+ double h = noise(x, y, z, octave);
+ if (h < 0.0f)
+ h *= -1.0;
+ height += h;
+ }
+ return height;
+ }
+
+ /**
+ *
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ public double noise(double x, double y, double z) {
+ double fx = floor(x);
+ double fy = floor(y);
+ double fz = floor(z);
+
+ int gx = (int) fx & 0xFF;
+ int gy = (int) fy & 0xFF;
+ int gz = (int) fz & 0xFF;
+
+ double u = fade(x -= fx);
+ double v = fade(y -= fy);
+ double w = fade(z -= fz);
+
+ int a0 = perm[gx + 0] + gy;
+ int b0 = perm[gx + 1] + gy;
+ int aa = perm[a0 + 0] + gz;
+ int ab = perm[a0 + 1] + gz;
+ int ba = perm[b0 + 0] + gz;
+ int bb = perm[b0 + 1] + gz;
+
+ double a1 = grad(perm[bb + 1], x - 1, y - 1, z - 1);
+ double a2 = grad(perm[ab + 1], x - 0, y - 1, z - 1);
+ double a3 = grad(perm[ba + 1], x - 1, y - 0, z - 1);
+ double a4 = grad(perm[aa + 1], x - 0, y - 0, z - 1);
+ double a5 = grad(perm[bb + 0], x - 1, y - 1, z - 0);
+ double a6 = grad(perm[ab + 0], x - 0, y - 1, z - 0);
+ double a7 = grad(perm[ba + 0], x - 1, y - 0, z - 0);
+ double a8 = grad(perm[aa + 0], x - 0, y - 0, z - 0);
+
+ double a2_1 = lerp(u, a2, a1);
+ double a4_3 = lerp(u, a4, a3);
+ double a6_5 = lerp(u, a6, a5);
+ double a8_7 = lerp(u, a8, a7);
+ double a8_5 = lerp(v, a8_7, a6_5);
+ double a4_1 = lerp(v, a4_3, a2_1);
+ double a8_1 = lerp(w, a8_5, a4_1);
+
+ return a8_1;
+ }
+
+ public double[] add(double[] v39, double v38, double v37, double a5, int a6, int a7, double a8, double a9,
+ double a10, double a11, double a12) {
+ if (a7 == 1) {
+ if (a6 > 0) {
+ int v74 = 0;
+ for (int i = 0; i < a6; i++) {
+ double v49 = (i + v38) * a9 + this.xo;
+ int v49_floor = (int) Math.floor(v49); // Maybe casting it directly is faster
+ double v49_remain = v49 - v49_floor;
+ v49_floor = Math.floorMod(v49_floor, 256); // Cast to unsigned __int8
+
+ if (a8 > 0) {
+ double v49_fade = this.fade(v49_remain);
+ for (int j = 0; j < a8; j++) {
+ double v58 = (j + a5) * a11 + this.zo;
+ int v58_floor = (int) Math.floor(v58);
+ double v58_remain = v58 - v58_floor;
+ v58_floor = Math.floorMod(v58_floor, 256); // Cast to unsigned __int8
+
+ int v62 = v58_floor + perm[perm[v49_floor]];
+ int v64 = v58_floor + perm[perm[v49_floor + 1]];
+
+ double v65 = grad2(perm[v62], v49_remain, v58_remain); // Index 574 out of bounds for length
+ // 512
+ double v66 = grad(perm[v64], v49_remain - 1.0, 0.0, v58_remain);
+ double v67 = lerp(v49_fade, v65, v66);
+
+ double v68 = grad(perm[v62 + 1], v49_remain, 0.0, v58_remain - 1.0);
+ double v69 = grad(perm[v64 + 1], v49_remain - 1.0, 0.0, v58_remain - 1.0);
+ double v70 = lerp(v49_fade, v68, v69);
+
+ double result = lerp(fade(v58_remain), v67, v70);
+ v39[v74] += result / a12;
+ v74++;
+
+ }
+ }
+ }
+ }
+ } else if (a6 > 0) {
+ int v60 = 0;
+ int v59 = -1;
+ double v58 = 0.0, v57 = 0.0, v56 = 0.0, v55 = 0.0;
+ for (int k = 0; k < a6; k++) {
+ double v52 = (k + v38) * a9 + this.xo;
+ int v52_floor = (int) Math.floor(v52);
+ double v52_remain = v52 - v52_floor;
+ double v52_fade = fade(v52_remain);
+ v52_floor = Math.floorMod(v52_floor, 256); // Cast to unsigned __int8
+
+ for (int l = 0; l < a8; l++) {
+ double v47 = (l + a5) * a11 + this.zo;
+ int v47_floor = (int) Math.floor(v47);
+ double v47_remain = v47 - v47_floor;
+ double v47_fade = fade(v47_remain);
+ v47_floor = Math.floorMod(v47_floor, 256); // Cast to unsigned __int8
+
+ for (int m = 0; m < a7; m++) {
+ double v43 = (m + v37) * a10 + this.yo;
+ int v43_floor = (int) Math.floor(v43);
+ double v43_remain = v43 - v43_floor;
+ double v43_fade = fade(v43_remain);
+ v43_floor = Math.floorMod(v43_floor, 256); // Cast to unsigned __int8
+
+ if (m == 0 || v43_floor != v59) {
+ v59 = v43_floor;
+
+ int v21 = v43_floor + perm[v52_floor];
+ int v22 = v47_floor + perm[v21];
+ int v23 = v47_floor + perm[v21 + 1];
+
+ int v24 = v43_floor + perm[v52_floor + 1];
+ int v25 = v47_floor + perm[v24];
+ int v26 = v47_floor + perm[v24 + 1];
+
+ double v27 = grad(perm[v22], v52_remain, v43_remain, v47_remain);
+ double v28 = grad(perm[v25], v52_remain - 1.0, v43_remain, v47_remain);
+ v58 = lerp(v52_fade, v27, v28);
+ double v29 = grad(perm[v23], v52_remain, v43_remain - 1.0, v47_remain);
+ double v30 = grad(perm[v26], v52_remain - 1.0, v43_remain - 1.0, v47_remain);
+ v57 = lerp(v52_fade, v29, v30);
+ double v31 = grad(perm[v22 + 1], v52_remain, v43_remain, v47_remain - 1.0);
+ double v32 = grad(perm[v25 + 1], v52_remain - 1.0, v43_remain, v47_remain - 1.0);
+ v56 = lerp(v52_fade, v31, v32);
+ double v33 = grad(perm[v23 + 1], v52_remain, v43_remain - 1.0, v47_remain - 1.0);
+ double v34 = grad(perm[v26 + 1], v52_remain - 1.0, v43_remain - 1.0, v47_remain - 1.0);
+ v55 = lerp(v52_fade, v33, v34);
+
+ }
+
+ double v35 = lerp(v43_fade, v58, v57);
+ double v36 = lerp(v43_fade, v56, v55);
+ double result = lerp(v47_fade, v35, v36);
+ v39[v60] += result / a12;
+ v60++;
+ }
+ }
+ }
+
+ }
+ return v39;
+ }
+
+ // ========================================================================
+ // PRIVATE
+ // ========================================================================
+
+ /**
+ *
+ * @param x
+ * @param y
+ * @param z
+ * @param octave
+ * @return
+ */
+ private double noise(double x, double y, double z, int octave) {
+ double p = pow[octave];
+ return this.noise(x * p + this.xo, y * p + this.yo, z * p + this.zo) / p;
+ }
+
+ /**
+ *
+ * @param v
+ * @return
+ */
+ private final double floor(double v) {
+ return (int) v;
+ }
+
+ /**
+ *
+ * @param t
+ * @return
+ */
+ private final double fade(double t) {
+ return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
+ }
+
+ /**
+ *
+ * @param t
+ * @param a
+ * @param b
+ * @return
+ */
+ private final double lerp(double t, double a, double b) {
+ return a + t * (b - a);
+ }
+
+ /**
+ *
+ * @param hash
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ private static double grad(int hash, double x, double y, double z) {
+ int h = hash & 15;
+ double u = (h < 8) ? x : y;
+ double v = (h < 4) ? y : ((h == 12 || h == 14) ? x : z);
+ return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
+ }
+
+ private static double grad2(int hash, double a3, double a4) {
+ int h = hash & 0xF;
+ double v4, v5;
+ if (h <= 3) {
+ v4 = 0.0;
+ } else if (h != 12 && h != 14) {
+ v4 = a4;
+ } else {
+ v4 = a3;
+ }
+
+ v5 = ((1 - ((hash & 8) >> 3)) * a3);
+
+ if ((h & 1) != 0)
+ v5 = -v5;
+ if ((h & 2) != 0)
+ v4 = -v4;
+
+ return v4 + v5;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/xueLi/craftGame/Main.java b/src/main/java/xueLi/craftGame/Main.java
deleted file mode 100644
index a23bbc9b..00000000
--- a/src/main/java/xueLi/craftGame/Main.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package xueLi.craftGame;
-
-import java.io.IOException;
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.input.Mouse;
-import org.lwjgl.opengl.GL11;
-
-import xueLi.craftGame.block.Block;
-import xueLi.craftGame.utils.DisplayManager;
-import xueLi.craftGame.utils.FPSTimer;
-import xueLi.craftGame.world.WorldRenderer;
-
-public class Main {
-
- private static int width = 1200, height = 680;
-
- public static void main(String[] args) throws IOException {
- //ååģēä¸ä¸Ēæžį¤ēåēå
- DisplayManager.create(width, height);
-
- //čŋä¸ĒåŊæ°ééĸåŽį°å¯šæšåįæŗ¨å ä¸åŽčĻæžå¨åæĄŖįæäšå
- Block.init();
-
- //čŋä¸ĒåŊæ°åå§åä¸įæ¸˛æå¨
- //æč´¨æžå¨"res/textures.png"ééĸ,åĨŊå ä¸Ēæč´¨įģååå¨
- //å ŗäēæ°åĸæšåįæį¨ å¨Blockįinitæšæŗééĸ
- WorldRenderer.init();
-
- Mouse.setGrabbed(true);
- while (DisplayManager.isRunning()) {
- if (DisplayManager.isKeyDown(Keyboard.KEY_ESCAPE)) {
- DisplayManager.postDestroyMessage();
- }
-
- //čŋåFPSįåŧ åĻæå¤å¨debugæ¨Ąåŧåäŧ卿§åļå°ééĸčžåē
- FPSTimer.getFPS();
-
- //ä¸ä¸įæ¸˛ææå ŗ
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
- WorldRenderer.render();
-
- //TODO:čŋéå¯äģĨ忏¸ætickæ´æ°äšįąģį åæŖå°ąæ¯æ¸¸æåžĒį¯
-
-
- //čŋæ¯æžį¤ēįĒåŖį县°
- DisplayManager.update();
- }
-
- //čĩæēéæž
- WorldRenderer.release();
- DisplayManager.destroy();
-
- }
-}
diff --git a/src/main/java/xueLi/craftGame/block/Block.java b/src/main/java/xueLi/craftGame/block/Block.java
deleted file mode 100644
index 4caf8726..00000000
--- a/src/main/java/xueLi/craftGame/block/Block.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package xueLi.craftGame.block;
-
-import java.nio.FloatBuffer;
-
-import xueLi.craftGame.block.data.*;
-import xueLi.craftGame.entity.HitBox;
-
-import static xueLi.craftGame.block.BlockData.datas;
-
-public class Block {
-
- public static void init() {
- datas.put(1, new BlockStone());
- datas.put(2, new BlockGrass());
-
- }
-
- private BlockData data;
-
- public int dataValue = 0;
-
- public Block(int id) {
- this.data = BlockData.getData(id);
- }
-
- public Block(BlockData data) {
- this.data = data;
- }
-
- public Block(int id,int dataValue) {
- this.data = BlockData.getData(id);
- this.dataValue = dataValue;
- }
-
- public Block(BlockData data,int dataValue) {
- this.data = data;
- this.dataValue = dataValue;
- }
-
- public int getDrawData(FloatBuffer buffer,int x,int y,int z,int face) {
- return this.data.render(buffer, x, y, z, dataValue, face);
- }
-
- public String getName() {
- return data.getName();
- }
-
- public int getID() {
- return data.getId();
- }
-
- public HitBox getHitbox(int x, int y, int z) {
- return data.getHitBoxWithPos(x,y,z);
- }
-
-
-
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/block/BlockData.java b/src/main/java/xueLi/craftGame/block/BlockData.java
deleted file mode 100644
index debe91eb..00000000
--- a/src/main/java/xueLi/craftGame/block/BlockData.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package xueLi.craftGame.block;
-
-import java.nio.FloatBuffer;
-import java.util.HashMap;
-
-import xueLi.craftGame.entity.HitBox;
-import xueLi.craftGame.utils.BlockPos;
-
-public abstract class BlockData {
-
- public static HashMap datas = new HashMap();
-
- public static BlockData getData(int id) {
- return datas.get(id);
- }
-
- private int id;
- private String name;
-
- public BlockData(int id,String name) {
- this.id = id;
- this.name = name;
- }
-
- public int getId() {
- return id;
- }
-
- public String getName() {
- return name;
- }
-
- //čŋä¸Ēæ¯įĸ°æįŽąį¨į
- public static final HitBox defaultHitbox = new HitBox(0f, 0f, 0f, 1f, 1f, 1f);
-
- public abstract HitBox getHitbox();
-
- public HitBox getHitBoxWithPos(BlockPos pos) {
- HitBox box = getHitbox();
- box.x1 += pos.getX();
- box.x2 += pos.getX();
- box.y1 += pos.getY();
- box.y2 += pos.getY();
- box.z1 += pos.getZ();
- box.z2 += pos.getZ();
- return box;
- }
-
- public HitBox getHitBoxWithPos(int x,int y,int z) {
- HitBox box = getHitbox();
- box.x1 += x;
- box.x2 += x;
- box.y1 += y;
- box.y2 += y;
- box.z1 += z;
- box.z2 += z;
- return box;
- }
-
- //æ¸˛ææšåŧ čŋåéĄļįšæ°é
- public abstract int render(FloatBuffer buffer,int x,int y,int z,int dataValue,int face);
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/block/BlockRenderMethod.java b/src/main/java/xueLi/craftGame/block/BlockRenderMethod.java
deleted file mode 100644
index 656954af..00000000
--- a/src/main/java/xueLi/craftGame/block/BlockRenderMethod.java
+++ /dev/null
@@ -1,204 +0,0 @@
-package xueLi.craftGame.block;
-
-import java.nio.FloatBuffer;
-
-public class BlockRenderMethod {
-
- //ä¸ēæč´¨å åˇĨäŊ
- public static float TEXTURES_SIZE = 16;
-
- /**
- * äģ įģåļæšååŊĸįļ ä¸ä¸æč´¨
- */
- public static void drawDefaultBlockToBuffer(FloatBuffer buffer, int x, int y, int z, int face) {
- switch (face) {
- case 0:
- buffer.put(x).put(y).put(z);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x + 1).put(y + 1).put(z);
- break;
- case 1:
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
- break;
- case 2:
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
- break;
- case 3:
- buffer.put(x).put(y).put(z);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x).put(y + 1).put(z + 1);
- break;
- case 4:
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
- break;
- case 5:
- buffer.put(x).put(y).put(z);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x + 1).put(y).put(z + 1);
- break;
- }
-
- }
-
- //įģåļæšåčžšæĄ
- public static void drawDefaultBlockFrame(FloatBuffer buffer, int x, int y, int z) {
- buffer.put(x).put(y).put(z);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x + 1).put(y + 1).put(z);
-
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
-
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
-
- buffer.put(x).put(y).put(z);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x).put(y + 1).put(z + 1);
-
- buffer.put(x).put(y + 1).put(z);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
-
- buffer.put(x).put(y).put(z);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(x + 1).put(y).put(z + 1);
- }
-
- // æ¤å¤įxīŧyæ¯äģ0åŧå§æ°į ä¸äŧæšīŧįŦåīŧ
- public static int bindDefaultToBuffer(FloatBuffer buffer, int xInTexture, int yInTexture, int x, int y, int z, int face) {
- float u1 = (float) xInTexture / TEXTURES_SIZE;
- float v1 = (float) yInTexture / TEXTURES_SIZE;
- float u2 = (float) (xInTexture + 1) / TEXTURES_SIZE;
- float v2 = (float) (yInTexture + 1) / TEXTURES_SIZE;
-
- switch (face) {
- case 0:
- buffer.put(u1).put(v2);
- // buffer.put(-1).put(-1).put(-1);
- buffer.put(x).put(y).put(z);
- buffer.put(u1).put(v1);
- // buffer.put(-1).put(1).put(-1);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(u2).put(v2);
- // buffer.put(1).put(-1).put(-1);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(u1).put(v1);
- // buffer.put(-1).put(1).put(-1);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(u2).put(v1);
- // buffer.put(1).put(1).put(-1);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(u2).put(v2);
- // buffer.put(1).put(-1).put(-1);
- buffer.put(x + 1).put(y).put(z);
- break;
- case 1:
- buffer.put(u1).put(v2);
- // buffer.put(1).put(-1).put(-1);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(u1).put(v1);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(u2).put(v2);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(u1).put(v1);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(u2).put(v1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
- buffer.put(u2).put(v2);
- buffer.put(x + 1).put(y).put(z + 1);
- break;
- case 2:
- buffer.put(u1).put(v2);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(u2).put(v2);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(u1).put(v1);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(u1).put(v1);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(u2).put(v2);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(u2).put(v1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
- break;
- case 3:
- buffer.put(u1).put(v2);
- buffer.put(x).put(y).put(z);
- buffer.put(u2).put(v2);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(u1).put(v1);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(u1).put(v1);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(u2).put(v2);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(u2).put(v1);
- buffer.put(x).put(y + 1).put(z + 1);
- break;
- case 4:
- buffer.put(u1).put(v2);
- buffer.put(x).put(y + 1).put(z);
- buffer.put(u2).put(v2);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(u1).put(v1);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(u1).put(v1);
- buffer.put(x + 1).put(y + 1).put(z);
- buffer.put(u2).put(v2);
- buffer.put(x).put(y + 1).put(z + 1);
- buffer.put(u2).put(v1);
- buffer.put(x + 1).put(y + 1).put(z + 1);
- break;
- case 5:
- buffer.put(u1).put(v2);
- buffer.put(x).put(y).put(z);
- buffer.put(u1).put(v1);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(u2).put(v2);
- buffer.put(x).put(y).put(z + 1);
- buffer.put(u1).put(v1);
- buffer.put(x + 1).put(y).put(z);
- buffer.put(u2).put(v1);
- buffer.put(x + 1).put(y).put(z + 1);
- buffer.put(u2).put(v2);
- buffer.put(x).put(y).put(z + 1);
- break;
- }
-
- return 6;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/block/data/BlockGrass.java b/src/main/java/xueLi/craftGame/block/data/BlockGrass.java
deleted file mode 100644
index 22d12081..00000000
--- a/src/main/java/xueLi/craftGame/block/data/BlockGrass.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package xueLi.craftGame.block.data;
-
-import java.nio.FloatBuffer;
-
-import xueLi.craftGame.block.BlockData;
-import xueLi.craftGame.block.BlockRenderMethod;
-import xueLi.craftGame.entity.HitBox;
-
-public class BlockGrass extends BlockData {
-
- public BlockGrass() {
- super(2,"Grass Block");
-
- }
-
- @Override
- public HitBox getHitbox() {
- return defaultHitbox;
- }
-
- @Override
- public int render(FloatBuffer buffer, int x, int y, int z, int dataValue, int face) {
- if (face < 4)
- return BlockRenderMethod.bindDefaultToBuffer(buffer, 1, 0, x, y, z, face);
- else if (face == 4)
- return BlockRenderMethod.bindDefaultToBuffer(buffer, 0, 0, x, y, z, face);
- else if (face == 5)
- return BlockRenderMethod.bindDefaultToBuffer(buffer, 2, 0, x, y, z, face);
- return 0;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/block/data/BlockStone.java b/src/main/java/xueLi/craftGame/block/data/BlockStone.java
deleted file mode 100644
index 09f8349c..00000000
--- a/src/main/java/xueLi/craftGame/block/data/BlockStone.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package xueLi.craftGame.block.data;
-
-import java.nio.FloatBuffer;
-
-import xueLi.craftGame.block.BlockData;
-import xueLi.craftGame.block.BlockRenderMethod;
-import xueLi.craftGame.entity.HitBox;
-
-public class BlockStone extends BlockData {
-
- public BlockStone() {
- super(1,"Stone");
-
- }
-
- @Override
- public HitBox getHitbox() {
- return defaultHitbox;
- }
-
- @Override
- public int render(FloatBuffer buffer, int x, int y, int z, int dataValue, int face) {
- return BlockRenderMethod.bindDefaultToBuffer(buffer, 3, 0, x, y, z, face);
- }
-
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/database/Entities.java b/src/main/java/xueLi/craftGame/database/Entities.java
deleted file mode 100644
index 4259a115..00000000
--- a/src/main/java/xueLi/craftGame/database/Entities.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package xueLi.craftGame.database;
-
-import java.io.FileNotFoundException;
-
-import com.google.gson.JsonIOException;
-import com.google.gson.JsonSyntaxException;
-
-import xueLi.craftGame.template.entity.AttributeEntity;
-import xueLi.craftGame.utils.JsonReader;
-
-public class Entities {
-
- public static AttributeEntity mWarma;
-
- static {
- try {
- mWarma = JsonReader.readToEntityData("res/entities/Warma.json");
-
- } catch (JsonSyntaxException e) {
- e.printStackTrace();
- } catch (JsonIOException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
-
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/Bone.java b/src/main/java/xueLi/craftGame/entity/Bone.java
deleted file mode 100644
index b2b1e293..00000000
--- a/src/main/java/xueLi/craftGame/entity/Bone.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package xueLi.craftGame.entity;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.lwjgl.util.vector.Matrix4f;
-import org.lwjgl.util.vector.Vector3f;
-
-import xueLi.craftGame.entity.renderer.RenderArgs;
-import xueLi.craftGame.utils.Vector;
-
-public class Bone {
-
- public int id;
- public float[] vertices = new float[24];
- public float[] rotPoint;
- public float[] rawOffset;
-
- public Matrix4f localMatrix = new Matrix4f();
- public Matrix4f matrix = new Matrix4f();
-
- //public float[]
- public List children = new ArrayList();
-
- public float rotX = 0,rotY = 0,rotZ = 0;
-
- public List getDrawArgs(Vector pos){
- List args = new ArrayList();
-
- RenderArgs a = new RenderArgs();
- a.matrix = matrix;
-
- float[] rawVertices = vertices;
- a.vertices = new float[rawVertices.length];
- for(int m = 0;m < rawVertices.length;m++) {
- a.vertices[m] = rawVertices[m];
- }
- a.color = new Vector3f(1f / id,1f / id / 2,1f / id / 3);
- args.add(a);
-
- for(Bone c:children) {
- args.addAll(c.getDrawArgs(pos));
- }
- return args;
- }
-
- public void calculateMatrix(Matrix4f parentMatrix) {
- localMatrix.setIdentity();
-
- //Matrix4f transMatrix = new Matrix4f();
- //transMatrix.translate(new Vector3f(rawOffset[0],rawOffset[1],rawOffset[2]));
-
- Matrix4f rotMatrix = new Matrix4f();
- rotMatrix.setIdentity();
- rotX +=1;
- rotMatrix.rotate((float)Math.toRadians(rotX), new Vector3f(1,0,0));
- rotMatrix.rotate((float)Math.toRadians(rotY), new Vector3f(0,1,0));
- rotMatrix.rotate((float)Math.toRadians(rotZ), new Vector3f(0,0,1));
-
- Matrix4f transMatrix = new Matrix4f();
- transMatrix.setIdentity();
- transMatrix.translate(new Vector3f(rawOffset[0],rawOffset[1],rawOffset[2]));
-
- localMatrix = Matrix4f.mul(transMatrix, rotMatrix , null);
-
- matrix = Matrix4f.mul(parentMatrix, localMatrix, null);
-
- for(Bone c:children)
- c.calculateMatrix(matrix);
- }
-
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/Entity.java b/src/main/java/xueLi/craftGame/entity/Entity.java
deleted file mode 100644
index e4bc9d94..00000000
--- a/src/main/java/xueLi/craftGame/entity/Entity.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package xueLi.craftGame.entity;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.lwjgl.util.vector.Matrix4f;
-import org.lwjgl.util.vector.Vector3f;
-
-import xueLi.craftGame.entity.renderer.EntityRenderer;
-import xueLi.craftGame.entity.renderer.RenderArgs;
-import xueLi.craftGame.template.entity.AttributeEntity;
-import xueLi.craftGame.utils.DisplayManager;
-import xueLi.craftGame.utils.Vector;
-import xueLi.craftGame.world.World;
-
-public abstract class Entity {
-
- public Vector pos;
- public boolean isInLiquid = false;
-
- // For physical engine
- // public boolean[] collide = new boolean[6];
-
- // For entity bones
- public AttributeEntity attrib;
-
- public Entity(float x, float y, float z) {
- pos = new Vector(x, y, z);
-
- }
-
- public Entity(float x, float y, float z, float rotX, float rotY, float rotZ) {
- pos = new Vector(x, y, z, rotX, rotY, rotZ);
-
- }
-
- public Vector3f force = new Vector3f();
- public Vector3f speed = new Vector3f();
-
- // this is for real physical engine and I haven't done yet :)
- // I think maybe I can figure out how to correct the position of an entity by
- // the direction of the speed.
- // But now one of the most important things is adding entities,so :} I think it
- // will be done much later.
- public void updatePos(World w) {
- Vector3f deltaPos = new Vector3f(speed.x * DisplayManager.deltaTime, speed.y * DisplayManager.deltaTime,
- speed.z * DisplayManager.deltaTime);
-
- /**
- * The player will be stuck when collided with this code
- */
- // HitBox box = getHitBox();
- // if(w.getHitBoxes(box.move(deltaPos.x + deltaPos.x > 0 ? 0.005f : -0.005f,
- // deltaPos.y + deltaPos.y > 0 ? 0.005f : -0.005f, deltaPos.z + deltaPos.z > 0 ?
- // 0.005f : -0.005f), w.wlimit_long).size() == 0) {
- pos.x += deltaPos.x;
- pos.y += deltaPos.y;
- pos.z += deltaPos.z;
- // pos.y = new
- // BigDecimal(pos.y).setScale(2,BigDecimal.ROUND_HALF_UP).floatValue();
- // }
-
- /**
- * So I can only write a false engine code like this
- */
- //if (pos.y + this.getOriginHitBox().y1 < 5)
- // pos.y = 5 - this.getOriginHitBox().y1;
-
- // Physical? No no no it will be much later :}
- force.set(0, 0, 0);
- // At least moving had become smoother :)
-
- }
-
- protected List defaultRender() {
- List args = new ArrayList();
-
- Matrix4f posMatrix = EntityRenderer.identity;
- posMatrix.translate(new Vector3f(pos.x,pos.y,pos.z));
-
- for(Bone b:attrib.bones) {
- b.calculateMatrix(posMatrix);
- args.addAll(b.getDrawArgs(pos));
- }
-
- posMatrix.setIdentity();
-
- return args;
- }
-
- public abstract List render();
-
- public abstract void tick(World world);
-
- public abstract float getSpeed();
-
- public abstract HitBox getOriginHitBox();
-
- protected HitBox getHitBox() {
- return getOriginHitBox().move(pos.x, pos.y, pos.z);
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/EntityType.java b/src/main/java/xueLi/craftGame/entity/EntityType.java
deleted file mode 100644
index 30113ce0..00000000
--- a/src/main/java/xueLi/craftGame/entity/EntityType.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package xueLi.craftGame.entity;
-
-public enum EntityType {
-
- PASSIVE(0), ENEMY(1), EASTEREGG(2333);
-
- public int id;
-
- EntityType(int id) {
- this.id = id;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/EntityWarma.java b/src/main/java/xueLi/craftGame/entity/EntityWarma.java
deleted file mode 100644
index 0fdb9e3f..00000000
--- a/src/main/java/xueLi/craftGame/entity/EntityWarma.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package xueLi.craftGame.entity;
-
-import java.util.List;
-
-import xueLi.craftGame.database.Entities;
-import xueLi.craftGame.entity.renderer.RenderArgs;
-import xueLi.craftGame.world.World;
-
-public class EntityWarma extends Entity {
-
- public EntityWarma(float x, float y, float z) {
- super(x, y, z);
- this.attrib = Entities.mWarma;
- }
-
- @Override
- public void tick(World world) {
-
- super.updatePos(world);
- }
-
- @Override
- public float getSpeed() {
- return 0.001f;
- }
-
- @Override
- public HitBox getOriginHitBox() {
- return null;
- }
-
- @Override
- public List render() {
- return super.defaultRender();
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/HitBox.java b/src/main/java/xueLi/craftGame/entity/HitBox.java
deleted file mode 100644
index 362a34bd..00000000
--- a/src/main/java/xueLi/craftGame/entity/HitBox.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package xueLi.craftGame.entity;
-
-import org.lwjgl.util.vector.Vector3f;
-
-public class HitBox {
-
- public float x1, y1, z1, x2, y2, z2;
-
- public HitBox(float x1, float y1, float z1, float x2, float y2, float z2) {
- this.x1 = x1;
- this.y1 = y1;
- this.z1 = z1;
- this.x2 = x2;
- this.y2 = y2;
- this.z2 = z2;
- }
-
- public boolean isCollide(HitBox h2) {
- if (isPointIn(x1, y1, z1))
- return true;
- if (isPointIn(x1, y1, z2))
- return true;
- if (isPointIn(x1, y2, z1))
- return true;
- if (isPointIn(x1, y2, z2))
- return true;
- if (isPointIn(x2, y1, z1))
- return true;
- if (isPointIn(x2, y1, z2))
- return true;
- if (isPointIn(x2, y2, z1))
- return true;
- if (isPointIn(x2, y2, z2))
- return true;
- return false;
- }
-
- public boolean isPointIn(float x, float y, float z) {
- return isPointIn(new Vector3f(x, y, z), this);
- }
-
- public static boolean isPointIn(Vector3f point, HitBox box) {
- if (point.x <= box.x1 || point.x >= box.x2)
- return false;
- if (point.y >= box.y2 || point.y <= box.y1)
- return false;
- if (point.z <= box.z1 || point.z >= box.z2)
- return false;
- return true;
- }
-
- public HitBox move(float x, float y, float z) {
- return new HitBox(x1 + x, y1 + y, z1 + z, x2 + x, y2 + y, z2 + z);
- }
-
- public HitBox expand(float x, float y, float z) {
- if (x < 0)
- this.x1 += x;
- else if (x > 0)
- this.x2 += x;
- if (y < 0)
- this.y1 += y;
- else if (y > 0)
- this.y2 += y;
- if (z < 0)
- this.z1 += z;
- else if (z > 0)
- this.z2 += z;
- return this;
- }
-
- public float xCollide(HitBox a, float x) {
- if (a.y2 <= this.y1 || a.y1 >= this.y2)
- return x;
- if (a.z2 <= this.z1 || a.z1 >= this.z2)
- return x;
- float max;
- if (x > 0.0f && a.x2 <= this.x1) {
- max = this.x1 - a.x2;
- if (max < x)
- x = max;
- } else if (x < 0.0f && a.x1 >= this.x2) {
- max = this.x2 - a.x1;
- if (max > x)
- x = max;
- }
- return x;
- }
-
- public float yCollide(HitBox a, float y) {
- if (a.x2 <= this.x1 || a.x1 >= this.x2)
- return y;
- if (a.z2 <= this.z1 || a.z1 >= this.z2)
- return y;
- float max;
- if (y > 0.0f && a.y2 <= this.y1) {
- max = this.y1 - a.y2;
- if (max < y)
- y = max;
- } else if (y < 0.0f && a.y1 >= this.y2) {
- max = this.y2 - a.y1;
- if (max > y)
- y = max;
- }
- return y;
- }
-
- public float zCollide(HitBox a, float z) {
- if (a.x2 <= this.x1 || a.x1 >= this.x2)
- return z;
- if (a.y2 <= this.y1 || a.y1 >= this.y2)
- return z;
- float max;
- if (z > 0.0f && a.z2 <= this.z1) {
- max = this.z1 - a.z2;
- if (max < z)
- z = max;
- } else if (z < 0.0f && a.z1 >= this.z2) {
- max = this.z2 - a.z1;
- if (max > z)
- z = max;
- }
- return z;
- }
-
- @Override
- public String toString() {
- return x1 + "," + y1 + "," + z1 + " " + x2 + "," + y2 + "," + z2;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/Player.java b/src/main/java/xueLi/craftGame/entity/Player.java
deleted file mode 100644
index d9e06ecb..00000000
--- a/src/main/java/xueLi/craftGame/entity/Player.java
+++ /dev/null
@@ -1,145 +0,0 @@
-package xueLi.craftGame.entity;
-
-import java.util.List;
-
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.input.Mouse;
-
-import xueLi.craftGame.entity.renderer.RenderArgs;
-import xueLi.craftGame.utils.BlockPos;
-import xueLi.craftGame.utils.DisplayManager;
-import xueLi.craftGame.utils.MousePicker;
-import xueLi.craftGame.world.World;
-
-public class Player extends Entity {
-
- public int gamemode = 1;
- public int health = 20;
-
- public BlockPos blockPointed;
-
- public float resistant = 0.009f;
- public float sensivity = 0.1f;
-
- private final HitBox hitbox = new HitBox(-0.2f, -1.8f, -0.2f, 0.2f, 0.2f, 0.2f);
-
- public Player(float x, float y, float z) {
- super(x, y, z);
- this.attrib.box = hitbox;
- }
-
- public Player(float x, float y, float z, float rotX, float rotY, float rotZ) {
- super(x, y, z, rotX, rotY, rotZ);
- }
-
- private static BlockPos block_select, last_block_select;
- private static long placeTimeCount;
-
- @Override
- public void tick(World world) {
- if (speed.x > 0) {
- speed.x -= resistant * speed.x * DisplayManager.deltaTime;
- if (speed.x < 0)
- speed.x = 0;
- } else if (speed.x < 0) {
- speed.x -= resistant * speed.x * DisplayManager.deltaTime;
- if (speed.x > 0)
- speed.x = 0;
- }
-
- if (speed.y > 0) {
- speed.y -= resistant * speed.y * 1.2f * DisplayManager.deltaTime;
- if (speed.y < 0)
- speed.y = 0;
- } else if (speed.y < 0) {
- speed.y -= resistant * speed.y * 1.2f * DisplayManager.deltaTime;
- if (speed.y > 0)
- speed.y = 0;
- }
-
- if (speed.z > 0) {
- speed.z -= resistant * speed.z * DisplayManager.deltaTime;
- if (speed.z < 0)
- speed.z = 0;
- } else if (speed.z < 0) {
- speed.z -= resistant * speed.z * DisplayManager.deltaTime;
- if (speed.z > 0)
- speed.z = 0;
- }
-
- if (DisplayManager.isKeyDown(Keyboard.KEY_W)) {
- if (DisplayManager.isKeyDown(Keyboard.KEY_R)) {
- speed.x -= this.getSpeed() * 3f * (float) Math.sin(Math.toRadians(-pos.rotY));
- speed.z -= this.getSpeed() * 3f * (float) Math.cos(Math.toRadians(-pos.rotY));
- } else {
- speed.x -= this.getSpeed() * (float) Math.sin(Math.toRadians(-pos.rotY));
- speed.z -= this.getSpeed() * (float) Math.cos(Math.toRadians(-pos.rotY));
- }
- }
- if (DisplayManager.isKeyDown(Keyboard.KEY_S)) {
- speed.x += this.getSpeed() * (float) Math.sin(Math.toRadians(-pos.rotY));
- speed.z += this.getSpeed() * (float) Math.cos(Math.toRadians(-pos.rotY));
- }
- if (DisplayManager.isKeyDown(Keyboard.KEY_A)) {
- speed.x -= this.getSpeed() * (float) Math.sin(Math.toRadians(-pos.rotY + 90));
- speed.z -= this.getSpeed() * (float) Math.cos(Math.toRadians(-pos.rotY + 90));
- }
- if (DisplayManager.isKeyDown(Keyboard.KEY_D)) {
- speed.x -= this.getSpeed() * (float) Math.sin(Math.toRadians(-pos.rotY - 90));
- speed.z -= this.getSpeed() * (float) Math.cos(Math.toRadians(-pos.rotY - 90));
- }
-
- if (DisplayManager.isKeyDown(Keyboard.KEY_SPACE)) {
- speed.y += this.getSpeed() * 0.9f;
- }
-
- if (DisplayManager.isKeyDown(Keyboard.KEY_LSHIFT)) {
- speed.y -= this.getSpeed() * 0.9f;
- }
-
- pos.rotX -= Mouse.getDY() * sensivity;
- pos.rotY += Mouse.getDX() * sensivity;
-
- super.updatePos(world);
-
- if (DisplayManager.isMouseDown(0) & block_select != null & DisplayManager.currentTime - placeTimeCount > 100) {
- world.setBlock(block_select, null);
- placeTimeCount = DisplayManager.currentTime;
- }
-
- if (DisplayManager.isMouseDown(1) & block_select != null & DisplayManager.currentTime - placeTimeCount > 100) {
- world.setBlock(last_block_select, 1);
- placeTimeCount = DisplayManager.currentTime;
- }
-
- }
-
- public void pickTick(World world) {
- block_select = null;
- MousePicker.ray(pos);
- for (float distance = 0; distance < 8; distance += 0.05f) {
- BlockPos searching_block_pos = MousePicker.getPointOnRay(distance);
- if (world.hasBlock(searching_block_pos)) {
- block_select = searching_block_pos;
- break;
- }
- last_block_select = searching_block_pos;
- }
- }
-
- @Override
- public List render() {
- return null;
- }
-
- @Override
- public float getSpeed() {
- return 0.002f;
- }
-
- @Override
- public HitBox getOriginHitBox() {
- return hitbox;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/renderer/EntityRenderer.java b/src/main/java/xueLi/craftGame/entity/renderer/EntityRenderer.java
deleted file mode 100644
index 9635dfe2..00000000
--- a/src/main/java/xueLi/craftGame/entity/renderer/EntityRenderer.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package xueLi.craftGame.entity.renderer;
-
-import java.nio.FloatBuffer;
-import java.nio.ShortBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import org.lwjgl.BufferUtils;
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.opengl.GL15;
-import org.lwjgl.util.vector.Matrix4f;
-
-import xueLi.craftGame.entity.Entity;
-import xueLi.craftGame.world.Chunk;
-
-public class EntityRenderer {
-
- public static Matrix4f identity = new Matrix4f();
-
- private static final short[] ELEMENTS = {
- 0,1,2,
- 0,2,3,
-
- 3,2,6,
- 3,6,7,
-
- 0,5,1,
- 0,4,5,
-
- 4,6,5,
- 4,7,6,
-
- 0,7,4,
- 0,3,7,
-
- 1,5,6,
- 1,6,2
- };
- public static final int ELEMENTS_COUNT = ELEMENTS.length;
-
- private static FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(24);
- private static ShortBuffer element = BufferUtils.createShortBuffer(ELEMENTS_COUNT);
- private static List renderList = new ArrayList();
-
- private static int vbo;
- private static int ebo;
-
- public static void init() {
- identity.setIdentity();
-
- ebo = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo);
- element.put(ELEMENTS);
- element.flip();
- GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, element, GL15.GL_STATIC_DRAW);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
-
- vbo = GL15.glGenBuffers();
- }
-
- public static void buildMesh(Chunk chunk) {
- for(Entity e : chunk.entities) {
- renderList.addAll(e.render());
- }
- }
-
- private static FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
-
- public static void render() {
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
- for(RenderArgs arg:renderList) {
- vertBuffer.put(arg.vertices);
- vertBuffer.flip();
-
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertBuffer, GL15.GL_STATIC_DRAW);
- GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo);
- GL11.glColor3f(arg.color.x,arg.color.y,arg.color.z);
-
- GL11.glPushMatrix();
- arg.matrix.store(matrixBuffer);
- matrixBuffer.flip();
- GL11.glMultMatrix(matrixBuffer);
- matrixBuffer.clear();
-
- GL11.glDrawElements(GL11.GL_TRIANGLES,ELEMENTS_COUNT, GL11.GL_UNSIGNED_SHORT, 0);
- GL11.glPopMatrix();
-
- vertBuffer.clear();
- }
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
- renderList.clear();
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/entity/renderer/RenderArgs.java b/src/main/java/xueLi/craftGame/entity/renderer/RenderArgs.java
deleted file mode 100644
index e95a2d48..00000000
--- a/src/main/java/xueLi/craftGame/entity/renderer/RenderArgs.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package xueLi.craftGame.entity.renderer;
-
-import org.lwjgl.util.vector.Matrix4f;
-import org.lwjgl.util.vector.Vector3f;
-
-public class RenderArgs {
-
- public float[] vertices;
- public Matrix4f matrix;
- public Vector3f color;
-
-}
diff --git a/src/main/java/xueLi/craftGame/gui/EnumGUIAlign.java b/src/main/java/xueLi/craftGame/gui/EnumGUIAlign.java
deleted file mode 100644
index cb569890..00000000
--- a/src/main/java/xueLi/craftGame/gui/EnumGUIAlign.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package xueLi.craftGame.gui;
-
-public enum EnumGUIAlign {
-
- //åŽå ¨åą ä¸
- center,
- //äģ xåą ä¸
- xcenter,
- //äģ yåą ä¸
- ycenter
-
-}
diff --git a/src/main/java/xueLi/craftGame/gui/GUIRenderer.java b/src/main/java/xueLi/craftGame/gui/GUIRenderer.java
deleted file mode 100644
index 2df1e83a..00000000
--- a/src/main/java/xueLi/craftGame/gui/GUIRenderer.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package xueLi.craftGame.gui;
-
-public class GUIRenderer {
-
- public static void render(GUIScreen gui) {
-
- }
-
-
-
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/gui/GUIScreen.java b/src/main/java/xueLi/craftGame/gui/GUIScreen.java
deleted file mode 100644
index f10861d7..00000000
--- a/src/main/java/xueLi/craftGame/gui/GUIScreen.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package xueLi.craftGame.gui;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class GUIScreen {
-
- private static List widgets = new ArrayList();
-
- public GUIScreen(String path) {
-
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/gui/GUIWidget.java b/src/main/java/xueLi/craftGame/gui/GUIWidget.java
deleted file mode 100644
index b00db96b..00000000
--- a/src/main/java/xueLi/craftGame/gui/GUIWidget.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package xueLi.craftGame.gui;
-
-import org.lwjgl.util.vector.Vector2f;
-import org.lwjgl.util.vector.Vector4f;
-import org.newdawn.slick.opengl.Texture;
-
-public class GUIWidget {
-
- public Vector2f pos;
- public Vector2f size;
- public Vector4f backgroundColor;
- public Texture texture;
- public String panel;
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/nightmare/Subject.java b/src/main/java/xueLi/craftGame/nightmare/Subject.java
deleted file mode 100644
index cfaa0608..00000000
--- a/src/main/java/xueLi/craftGame/nightmare/Subject.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package xueLi.craftGame.nightmare;
-
-public enum Subject {
-
- CHINESE(100),MATH(1000),ENGLISH(50),PHYSICAL(500),CHEMISTRY(800),BIOLOGY(233);
-
- public int howHardItIs;
- Subject(int howHardItIs){
- this.howHardItIs = howHardItIs;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/physics/Force.java b/src/main/java/xueLi/craftGame/physics/Force.java
deleted file mode 100644
index 375fd0b9..00000000
--- a/src/main/java/xueLi/craftGame/physics/Force.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package xueLi.craftGame.physics;
-
-import xueLi.craftGame.utils.Vector;
-
-public class Force {
-
- public Vector pos;
- public ForceType type;
-
- public Force(Vector pos, ForceType type) {
- this.pos = pos;
- this.type = type;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/physics/ForceType.java b/src/main/java/xueLi/craftGame/physics/ForceType.java
deleted file mode 100644
index e4a2c397..00000000
--- a/src/main/java/xueLi/craftGame/physics/ForceType.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package xueLi.craftGame.physics;
-
-public enum ForceType {
-
- // ÖØÁĻŖŦÄϞÁÁĻŖŦŋÕÆø×čÁĻŖŦĩ¯ÁĻ
- Gravity, Friction, Resistance, Elasticity
-
-}
diff --git a/src/main/java/xueLi/craftGame/physics/Gravity.java b/src/main/java/xueLi/craftGame/physics/Gravity.java
deleted file mode 100644
index 60ab1842..00000000
--- a/src/main/java/xueLi/craftGame/physics/Gravity.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package xueLi.craftGame.physics;
-
-public class Gravity {
-
- public static final float g = 9.8f;
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/bilibili/TUpperRelation.java b/src/main/java/xueLi/craftGame/template/bilibili/TUpperRelation.java
deleted file mode 100644
index 7ee51187..00000000
--- a/src/main/java/xueLi/craftGame/template/bilibili/TUpperRelation.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package xueLi.craftGame.template.bilibili;
-
-public class TUpperRelation {
-
- @SuppressWarnings("unused")
- private int code;
-
- @SuppressWarnings("unused")
- private int message;
-
- @SuppressWarnings("unused")
- private int ttl;
-
- public TUpperRelationData data;
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/bilibili/TUpperRelationData.java b/src/main/java/xueLi/craftGame/template/bilibili/TUpperRelationData.java
deleted file mode 100644
index f3d0e498..00000000
--- a/src/main/java/xueLi/craftGame/template/bilibili/TUpperRelationData.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package xueLi.craftGame.template.bilibili;
-
-public class TUpperRelationData {
-
- @SuppressWarnings("unused")
- private long mid;
-
- @SuppressWarnings("unused")
- private long following;
-
- @SuppressWarnings("unused")
- private long whisper;
-
- @SuppressWarnings("unused")
- private long black;
-
- public long follower;
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/entity/AttributeEntity.java b/src/main/java/xueLi/craftGame/template/entity/AttributeEntity.java
deleted file mode 100644
index a8426ce4..00000000
--- a/src/main/java/xueLi/craftGame/template/entity/AttributeEntity.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package xueLi.craftGame.template.entity;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import xueLi.craftGame.entity.Bone;
-import xueLi.craftGame.entity.HitBox;
-
-public class AttributeEntity {
-
- public String name;
- public List bones = new ArrayList();
- public HitBox box;
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/entity/TBone.java b/src/main/java/xueLi/craftGame/template/entity/TBone.java
deleted file mode 100644
index c10aa762..00000000
--- a/src/main/java/xueLi/craftGame/template/entity/TBone.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package xueLi.craftGame.template.entity;
-
-public class TBone {
-
- public int id;
- public int parent;
- public float[] offset;
- public float[] size;
- public float[] uv;
- public float[] rotPoint;
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/entity/TEntity.java b/src/main/java/xueLi/craftGame/template/entity/TEntity.java
deleted file mode 100644
index 85be533c..00000000
--- a/src/main/java/xueLi/craftGame/template/entity/TEntity.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package xueLi.craftGame.template.entity;
-
-public class TEntity {
-
- public String name;
- public String type;
- public TModel model;
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/entity/TModel.java b/src/main/java/xueLi/craftGame/template/entity/TModel.java
deleted file mode 100644
index a8164883..00000000
--- a/src/main/java/xueLi/craftGame/template/entity/TModel.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package xueLi.craftGame.template.entity;
-
-public class TModel {
-
- public float[] box;
- public TBone[] bones;
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/gui/TGUI.java b/src/main/java/xueLi/craftGame/template/gui/TGUI.java
deleted file mode 100644
index 7346575c..00000000
--- a/src/main/java/xueLi/craftGame/template/gui/TGUI.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package xueLi.craftGame.template.gui;
-
-public class TGUI {
-
- public String type;
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/template/gui/TGUIData.java b/src/main/java/xueLi/craftGame/template/gui/TGUIData.java
deleted file mode 100644
index 2e71d2d4..00000000
--- a/src/main/java/xueLi/craftGame/template/gui/TGUIData.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package xueLi.craftGame.template.gui;
-
-public class TGUIData {
-
- public String type;
- public float[] size;
- public String align;
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/BilibiliAPI.java b/src/main/java/xueLi/craftGame/utils/BilibiliAPI.java
deleted file mode 100644
index 0a48c9de..00000000
--- a/src/main/java/xueLi/craftGame/utils/BilibiliAPI.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package xueLi.craftGame.utils;
-
-import java.io.IOException;
-
-public class BilibiliAPI {
-
- public static boolean realtimeGetFansRunning = true;
- public static long follower;
-
- private static final Thread realtimeGetFans = new Thread(()-> {
- while(realtimeGetFansRunning) {
- try {
- follower = JsonReader.getBilibiliUpperFollower(157262276);
- System.out.println("åŽįį˛ä¸æ°: " + follower);
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
-
- public static void startThreadOfRealtimeGetFans() {
- realtimeGetFans.start();
- }
-
- public static void stopThreadOfRealtimeGetFans() {
- realtimeGetFansRunning = false;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/BlockPos.java b/src/main/java/xueLi/craftGame/utils/BlockPos.java
deleted file mode 100644
index 2d9d8f48..00000000
--- a/src/main/java/xueLi/craftGame/utils/BlockPos.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package xueLi.craftGame.utils;
-
-public class BlockPos {
-
- private int x, y, z;
-
- public BlockPos(int x, int y, int z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
-
- public int getX() {
- return x;
- }
-
- public int getY() {
- return y;
- }
-
- public int getZ() {
- return z;
- }
-
- @Override
- public String toString() {
- return x + "," + y + "," + z;
- }
-
- public static Vector getBlockPosInChunk(Vector pos,ChunkPos cpos) {
- return new Vector(pos.x - cpos.getX() * 16,pos.y,pos.z - cpos.getZ() * 16,pos.rotX,pos.rotY,pos.rotZ);
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/ChunkPos.java b/src/main/java/xueLi/craftGame/utils/ChunkPos.java
deleted file mode 100644
index 8e83e3ce..00000000
--- a/src/main/java/xueLi/craftGame/utils/ChunkPos.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package xueLi.craftGame.utils;
-
-public class ChunkPos {
-
- private int x, z;
-
- public ChunkPos(int x, int z) {
- this.x = x;
- this.z = z;
- }
-
- public int getX() {
- return x;
- }
-
- public int getZ() {
- return z;
- }
-
- @Override
- public String toString() {
- return x + "," + z;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/DisplayManager.java b/src/main/java/xueLi/craftGame/utils/DisplayManager.java
deleted file mode 100644
index 9150d06e..00000000
--- a/src/main/java/xueLi/craftGame/utils/DisplayManager.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package xueLi.craftGame.utils;
-
-import java.nio.FloatBuffer;
-
-import org.lwjgl.BufferUtils;
-import org.lwjgl.LWJGLException;
-import org.lwjgl.Sys;
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.input.Mouse;
-import org.lwjgl.opengl.Display;
-import org.lwjgl.opengl.DisplayMode;
-import org.lwjgl.opengl.GL11;
-
-import xueLi.craftGame.world.Chunk;
-import xueLi.craftGame.world.World;
-
-public class DisplayManager {
-
- public static boolean isDebug = true;
-
- private static boolean isRunning = false;
- private static int fps_cap = 60;
-
- public static int d_width, d_height;
-
- public static long currentTime;
- public static long deltaTime;
-
- public static void create(int width, int height) {
- try {
- Display.setDisplayMode(new DisplayMode(width, height));
- Display.setResizable(true);
- Display.setSwapInterval(1);
- Display.setVSyncEnabled(true);
- Display.setTitle("CraftGame");
-
- Display.create();
- Display.makeCurrent();
-
- Keyboard.create();
- Mouse.create();
- } catch (LWJGLException e) {
- e.printStackTrace();
- }
- isRunning = true;
-
- GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
- GL11.glEnable(GL11.GL_TEXTURE_2D);
-
- GL11.glEnable(GL11.GL_DEPTH_TEST);
- GL11.glDepthFunc(GL11.GL_ONE);
-
- GL11.glEnable(GL11.GL_CULL_FACE);
- GL11.glCullFace(GL11.GL_BACK);
-
- FloatBuffer fogColor = BufferUtils.createFloatBuffer(4);
- float[] fogColour = { 0.8f, 0.8f, 1.0f, 1.0f };
- fogColor.put(fogColour);
- fogColor.flip();
-
- GL11.glEnable(GL11.GL_FOG);
- GL11.glFog(GL11.GL_FOG_COLOR, fogColor);
- GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);
- GL11.glFogf(GL11.GL_FOG_DENSITY, 0.003f);
- GL11.glFogf(GL11.GL_FOG_START, World.chunkRenderDistance * Chunk.size * 0.56f);
- GL11.glFogf(GL11.GL_FOG_END, World.chunkRenderDistance * Chunk.size * 1.90f);
- GL11.glHint(GL11.GL_FOG_HINT, GL11.GL_DONT_CARE);
-
- //The website says these are the way to anti-aliasing
- GL11.glEnable(GL11.GL_BLEND);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- GL11.glEnable(GL11.GL_POINT_SMOOTH);
- GL11.glEnable(GL11.GL_LINE_SMOOTH);
- GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
-
- d_width = width;
- d_height = height;
-
- }
-
- public static boolean tickResize() {
- if (Display.wasResized()) {
- d_width = Display.getWidth();
- d_height = Display.getHeight();
- GL11.glViewport(0, 0, d_width, d_height);
-
- return true;
- }
- return false;
- }
-
- private static long getCurrentTime() {
- return Sys.getTime() * 1000 / Sys.getTimerResolution();
- }
-
- public static void update() {
- if (Display.isCloseRequested())
- isRunning = false;
- Display.sync(fps_cap);
- Display.update();
-
- deltaTime = getCurrentTime() - currentTime;
- }
-
- public static boolean isKeyDown(int i) {
- return Keyboard.isKeyDown(i);
- }
-
- public static boolean isMouseDown(int i) {
- return Mouse.isButtonDown(i);
- }
-
- public static boolean isKeyDown() {
- return Keyboard.getEventKeyState();
- }
-
- public static boolean isRunning() {
- currentTime = getCurrentTime();
- return isRunning;
- }
-
- public static void postDestroyMessage() {
- isRunning = false;
- }
-
- public static void destroy() {
- isRunning = false;
- Display.destroy();
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/FPSTimer.java b/src/main/java/xueLi/craftGame/utils/FPSTimer.java
deleted file mode 100644
index 6c7448e6..00000000
--- a/src/main/java/xueLi/craftGame/utils/FPSTimer.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package xueLi.craftGame.utils;
-
-public class FPSTimer {
-
- private static int counter = 0;
- private static int fps = 0;
-
- private static long time1 = 0;
-
- public static int getFPS() {
- counter++;
- if (DisplayManager.currentTime - time1 >= 1000) {
- fps = counter;
- counter = 0;
- time1 = DisplayManager.currentTime;
- if (DisplayManager.isDebug)
- System.out.println("FPS : " + fps);
- }
- return fps;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/GLHelper.java b/src/main/java/xueLi/craftGame/utils/GLHelper.java
deleted file mode 100644
index 31d0c396..00000000
--- a/src/main/java/xueLi/craftGame/utils/GLHelper.java
+++ /dev/null
@@ -1,256 +0,0 @@
-package xueLi.craftGame.utils;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.nio.FloatBuffer;
-
-import org.lwjgl.BufferUtils;
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.opengl.GL12;
-import org.lwjgl.opengl.GL13;
-import org.lwjgl.util.vector.Matrix4f;
-import org.lwjgl.util.vector.Vector3f;
-import org.newdawn.slick.opengl.Texture;
-import org.newdawn.slick.opengl.TextureLoader;
-
-import xueLi.craftGame.entity.Player;
-
-public class GLHelper {
-
- public static Matrix4f lastTimeProjMatrix, lastTimeViewMatrix;
- private static FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
- public static float[][] frustumPlane = new float[6][4];
-
- public static int registerTexture(String path) {
- Texture t = null;
- try {
- t = TextureLoader.getTexture("png", new FileInputStream(new File(path)));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_BASE_LEVEL, 0);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 4);
- return t.getTextureID();
- }
-
- public static void deleteTexture(int id) {
- GL11.glDeleteTextures(id);
- }
-
- public static void perspecive(float width, float height, float fov, float near, float far) {
- Matrix4f projectionMatrix = new Matrix4f();
-
- float ratio = width / height;
- float y_scale = (float) ((1f / Math.tan(Math.toRadians(fov / 2F))) * ratio);
- float x_scale = y_scale / ratio;
- float frustum_length = far - near;
-
- projectionMatrix.setIdentity();
- projectionMatrix.m00 = x_scale;
- projectionMatrix.m11 = y_scale;
- projectionMatrix.m22 = -(far + near) / frustum_length;
- projectionMatrix.m23 = -1;
- projectionMatrix.m32 = -((2 * far * near) / frustum_length);
- projectionMatrix.m33 = 0;
-
- GL11.glMatrixMode(GL11.GL_PROJECTION);
- matrixBuffer.clear();
- projectionMatrix.store(matrixBuffer);
- matrixBuffer.flip();
- GL11.glLoadMatrix(matrixBuffer);
-
- lastTimeProjMatrix = projectionMatrix;
- }
-
- public static void player(Player player) {
- Vector camera = player.pos;
- Matrix4f viewMatrix = new Matrix4f();
- viewMatrix.setIdentity();
- Matrix4f.rotate((float) Math.toRadians(camera.rotX), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
- Matrix4f.rotate((float) Math.toRadians(camera.rotY), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
- Matrix4f.rotate((float) Math.toRadians(camera.rotZ), new Vector3f(0, 0, 1), viewMatrix, viewMatrix);
- Vector3f nagativeCamPos = new Vector3f(-camera.x, -camera.y, -camera.z);
- Matrix4f.translate(nagativeCamPos, viewMatrix, viewMatrix);
-
- lastTimeViewMatrix = viewMatrix;
- matrixBuffer.clear();
- viewMatrix.store(matrixBuffer);
- matrixBuffer.flip();
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- GL11.glLoadMatrix(matrixBuffer);
- }
-
- public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) {
- Matrix4f matrix = new Matrix4f();
- matrix.setIdentity();
- Matrix4f.translate(translation, matrix, matrix);
- Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1, 0, 0), matrix, matrix);
- Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0, 1, 0), matrix, matrix);
- Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0, 0, 1), matrix, matrix);
- Matrix4f.scale(new Vector3f(scale, scale, scale), matrix, matrix);
- return matrix;
- }
-
- public static void calculateFrustumPlane() {
- Matrix4f matrix = Matrix4f.mul(lastTimeProjMatrix, lastTimeViewMatrix, null);
-
- double temp;
- frustumPlane[0][0] = matrix.m03 - matrix.m00;
- frustumPlane[0][1] = matrix.m13 - matrix.m10;
- frustumPlane[0][2] = matrix.m23 - matrix.m20;
- frustumPlane[0][3] = matrix.m33 - matrix.m30;
- temp = Math.sqrt(frustumPlane[0][0] * frustumPlane[0][0] + frustumPlane[0][1] * frustumPlane[0][1]
- + frustumPlane[0][2] * frustumPlane[0][2]);
- frustumPlane[0][0] /= temp;
- frustumPlane[0][1] /= temp;
- frustumPlane[0][2] /= temp;
- frustumPlane[0][3] /= temp;
-
- frustumPlane[1][0] = matrix.m03 + matrix.m00;
- frustumPlane[1][1] = matrix.m13 + matrix.m10;
- frustumPlane[1][2] = matrix.m23 + matrix.m20;
- frustumPlane[1][3] = matrix.m33 + matrix.m30;
- temp = Math.sqrt(frustumPlane[1][0] * frustumPlane[1][0] + frustumPlane[1][1] * frustumPlane[1][1]
- + frustumPlane[1][2] * frustumPlane[1][2]);
- frustumPlane[1][0] /= temp;
- frustumPlane[1][1] /= temp;
- frustumPlane[1][2] /= temp;
- frustumPlane[1][3] /= temp;
-
- frustumPlane[2][0] = matrix.m03 + matrix.m01;
- frustumPlane[2][1] = matrix.m13 + matrix.m11;
- frustumPlane[2][2] = matrix.m23 + matrix.m21;
- frustumPlane[2][3] = matrix.m33 + matrix.m31;
- temp = Math.sqrt(frustumPlane[2][0] * frustumPlane[2][0] + frustumPlane[2][1] * frustumPlane[2][1]
- + frustumPlane[2][2] * frustumPlane[2][2]);
- frustumPlane[2][0] /= temp;
- frustumPlane[2][1] /= temp;
- frustumPlane[2][2] /= temp;
- frustumPlane[2][3] /= temp;
-
- frustumPlane[3][0] = matrix.m03 - matrix.m01;
- frustumPlane[3][1] = matrix.m13 - matrix.m11;
- frustumPlane[3][2] = matrix.m23 - matrix.m21;
- frustumPlane[3][3] = matrix.m33 - matrix.m31;
- temp = Math.sqrt(frustumPlane[3][0] * frustumPlane[3][0] + frustumPlane[3][1] * frustumPlane[3][1]
- + frustumPlane[3][2] * frustumPlane[3][2]);
- frustumPlane[3][0] /= temp;
- frustumPlane[3][1] /= temp;
- frustumPlane[3][2] /= temp;
- frustumPlane[3][3] /= temp;
-
- frustumPlane[4][0] = matrix.m03 - matrix.m02;
- frustumPlane[4][1] = matrix.m13 - matrix.m12;
- frustumPlane[4][2] = matrix.m23 - matrix.m22;
- frustumPlane[4][3] = matrix.m33 - matrix.m32;
- temp = Math.sqrt(frustumPlane[4][0] * frustumPlane[4][0] + frustumPlane[4][1] * frustumPlane[4][1]
- + frustumPlane[4][2] * frustumPlane[4][2]);
- frustumPlane[4][0] /= temp;
- frustumPlane[4][1] /= temp;
- frustumPlane[4][2] /= temp;
- frustumPlane[4][3] /= temp;
-
- frustumPlane[5][0] = matrix.m03 + matrix.m02;
- frustumPlane[5][1] = matrix.m13 + matrix.m12;
- frustumPlane[5][2] = matrix.m23 + matrix.m22;
- frustumPlane[5][3] = matrix.m33 + matrix.m32;
- temp = Math.sqrt(frustumPlane[5][0] * frustumPlane[5][0] + frustumPlane[5][1] * frustumPlane[5][1]
- + frustumPlane[5][2] * frustumPlane[5][2]);
- frustumPlane[5][0] /= temp;
- frustumPlane[5][1] /= temp;
- frustumPlane[5][2] /= temp;
- frustumPlane[5][3] /= temp;
- }
-
- public static boolean isPointInFrustum(float x, float y, float z) {
- for (int p = 0; p < 6; p++) {
- if (frustumPlane[p][0] * x + frustumPlane[p][1] * y + frustumPlane[p][2] * z + frustumPlane[p][3] <= 0)
- return false;
- }
- return true;
- }
-
- public static boolean isBlockInFrustum(int x, int y, int z) {
- for (int p = 0; p < 6; p++) {
- if (frustumPlane[p][0] * x + frustumPlane[p][1] * y + frustumPlane[p][2] * z + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) + frustumPlane[p][1] * y + frustumPlane[p][2] * z + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * x + frustumPlane[p][1] * (y + 1) + frustumPlane[p][2] * z + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) + frustumPlane[p][1] * (y + 1) + frustumPlane[p][2] * z
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * x + frustumPlane[p][1] * y + frustumPlane[p][2] * (z + 1) + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) + frustumPlane[p][1] * y + frustumPlane[p][2] * (z + 1)
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * x + frustumPlane[p][1] * (y + 1) + frustumPlane[p][2] * (z + 1)
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) + frustumPlane[p][1] * (y + 1) + frustumPlane[p][2] * (z + 1)
- + frustumPlane[p][3] > 0)
- continue;
- return false;
- }
- return true;
- }
-
- public static boolean isChunkInFrustum(int x, int heightMap, int z) {
- for (int p = 0; p < 6; p++) {
- if (frustumPlane[p][0] * x * 16 + frustumPlane[p][1] * 0 + frustumPlane[p][2] * z * 16
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) * 16 + frustumPlane[p][1] * 0 + frustumPlane[p][2] * z * 16
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * x * 16 + frustumPlane[p][1] * heightMap + frustumPlane[p][2] * z * 16
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) * 16 + frustumPlane[p][1] * heightMap + frustumPlane[p][2] * z * 16
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * x * 16 + frustumPlane[p][1] * 0 + frustumPlane[p][2] * (z + 1) * 16
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) * 16 + frustumPlane[p][1] * 0 + frustumPlane[p][2] * (z + 1) * 16
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * x * 16 + frustumPlane[p][1] * heightMap + frustumPlane[p][2] * (z + 1) * 16
- + frustumPlane[p][3] > 0)
- continue;
- if (frustumPlane[p][0] * (x + 1) * 16 + frustumPlane[p][1] * heightMap + frustumPlane[p][2] * (z + 1) * 16
- + frustumPlane[p][3] > 0)
- continue;
- return false;
- }
- return true;
- }
-
- public static float doubleToFloat(double value) {
- return new BigDecimal(String.valueOf(value)).floatValue();
- }
-
- public static double floatToDouble(float value) {
- return new BigDecimal(String.valueOf(value)).doubleValue();
- }
-
- public static int floatToInt(float value) {
- return new BigDecimal(String.valueOf(value)).setScale(2, BigDecimal.ROUND_DOWN).intValue();
- }
-
- public static long vert2ToLong(int x, int z) {
- return (long) x & 4294967295L | ((long) z & 4294967295L) << 32;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/JsonReader.java b/src/main/java/xueLi/craftGame/utils/JsonReader.java
deleted file mode 100644
index 016d9db3..00000000
--- a/src/main/java/xueLi/craftGame/utils/JsonReader.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package xueLi.craftGame.utils;
-
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import com.google.gson.Gson;
-import com.google.gson.JsonIOException;
-import com.google.gson.JsonSyntaxException;
-
-import xueLi.craftGame.entity.Bone;
-import xueLi.craftGame.entity.HitBox;
-import xueLi.craftGame.template.bilibili.TUpperRelation;
-import xueLi.craftGame.template.entity.*;
-
-public class JsonReader {
-
- private static Gson gson = new Gson();
-
- /**
- * @throws JsonSyntaxException jsonæ ŧåŧé蝝
- * @throws JsonIOException jsonæäģļč¯ģåé蝝
- * @throws FileNotFoundException æ˛Ąæžå°æäģļ
- * @throws IllegalArgumentException jsonåæ°é蝝
- */
- public static AttributeEntity readToEntityData(String path)
- throws JsonSyntaxException, JsonIOException, FileNotFoundException {
- TEntity raw = gson.fromJson(new FileReader(path), TEntity.class);
- if (raw == null) {
- System.err.println("Can't read entity: " + path);
- return null;
- }
-
- AttributeEntity attrib = new AttributeEntity();
- attrib.name = raw.name;
-
- TModel rawModel = raw.model;
- attrib.box = new HitBox(rawModel.box[0], rawModel.box[1], rawModel.box[2], rawModel.box[3], rawModel.box[4],
- rawModel.box[5]);
-
- TBone[] bones = rawModel.bones;
-
- for (int s = 0; s < bones.length; s++) {
- TBone rawData = bones[s];
- Bone bone = new Bone();
-
- bone.id = rawData.id;
-
- bone.vertices[0] = rawData.rotPoint[0]-rawData.size[0] / 2;
- bone.vertices[1] = rawData.rotPoint[1]-rawData.size[1] / 2;
- bone.vertices[2] = rawData.rotPoint[2]-rawData.size[2] / 2;
-
- bone.vertices[3] = rawData.rotPoint[0]-rawData.size[0] / 2;
- bone.vertices[4] = rawData.rotPoint[1]+rawData.size[1] / 2;
- bone.vertices[5] = rawData.rotPoint[2]-rawData.size[2] / 2;
-
- bone.vertices[6] = rawData.rotPoint[0]+rawData.size[0] / 2;
- bone.vertices[7] = rawData.rotPoint[1]+rawData.size[1] / 2;
- bone.vertices[8] = rawData.rotPoint[2]-rawData.size[2] / 2;
-
- bone.vertices[9] = rawData.rotPoint[0]+rawData.size[0] / 2;
- bone.vertices[10] = rawData.rotPoint[1]-rawData.size[1] / 2;
- bone.vertices[11] = rawData.rotPoint[2]-rawData.size[2] / 2;
-
- bone.vertices[12] = rawData.rotPoint[0]-rawData.size[0] / 2;
- bone.vertices[13] = rawData.rotPoint[1]-rawData.size[1] / 2;
- bone.vertices[14] = rawData.rotPoint[2]+rawData.size[2] / 2;
-
- bone.vertices[15] = rawData.rotPoint[0]-rawData.size[0] / 2;
- bone.vertices[16] = rawData.rotPoint[1]+rawData.size[1] / 2;
- bone.vertices[17] = rawData.rotPoint[2]+rawData.size[2] / 2;
-
- bone.vertices[18] = rawData.rotPoint[0]+rawData.size[0] / 2;
- bone.vertices[19] = rawData.rotPoint[1]+rawData.size[1] / 2;
- bone.vertices[20] = rawData.rotPoint[2]+rawData.size[2] / 2;
-
- bone.vertices[21] = rawData.rotPoint[0]+rawData.size[0] / 2;
- bone.vertices[22] = rawData.rotPoint[1]-rawData.size[1] / 2;
- bone.vertices[23] = rawData.rotPoint[2]+rawData.size[2] / 2;
-
- bone.rotPoint = rawData.rotPoint;
- bone.rawOffset = rawData.offset;
-
- if (rawData.parent != -1) {
- attrib.bones.get(rawData.parent).children.add(bone);
- } else {
- attrib.bones.add(bone);
- }
-
- }
-
- return attrib;
- }
-
- public static long getBilibiliUpperFollower(long uuid) throws IOException {
- URL url = new URL("http://api.bilibili.com/x/relation/stat?vmid=" + uuid);
- InputStream in = url.openStream();
- TUpperRelation r = gson.fromJson(new InputStreamReader(in), TUpperRelation.class);
- in.close();
- return r.data.follower;
- }
-
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/MousePicker.java b/src/main/java/xueLi/craftGame/utils/MousePicker.java
deleted file mode 100644
index 9213acde..00000000
--- a/src/main/java/xueLi/craftGame/utils/MousePicker.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package xueLi.craftGame.utils;
-
-import org.lwjgl.util.vector.Matrix4f;
-import org.lwjgl.util.vector.Vector3f;
-import org.lwjgl.util.vector.Vector4f;
-
-public class MousePicker {
-
- private static Vector3f ray, camPos;
-
- public static void ray(Vector pos) {
- camPos = new Vector3f(pos.x, pos.y, pos.z);
-
- // float MouseX = Mouse.getX();
- // float MouseY = Mouse.getY();
- // Vector2f normalizedMouseCoords = new Vector2f((2f * (MouseX)) /
- // Display.getWidth() - 1f,(2f * (MouseY)) / Display.getHeight() - 1f);
- Vector4f clipCoords = new Vector4f(0, 0, -1f, 1f);
-
- Matrix4f invertedProj = Matrix4f.invert(GLHelper.lastTimeProjMatrix, null);
- Vector4f eyeCoords_origin = Matrix4f.transform(invertedProj, clipCoords, null);
- Vector4f eyeCoords = new Vector4f(eyeCoords_origin.x, eyeCoords_origin.y, -1f, 0f);
- Matrix4f invertedView = Matrix4f.invert(GLHelper.lastTimeViewMatrix, null);
- Vector4f rayWorld = Matrix4f.transform(invertedView, eyeCoords, null);
- ray = new Vector3f(rayWorld.x, rayWorld.y, rayWorld.z);
- ray.normalise();
- }
-
- public static BlockPos getPointOnRay(float distance) {
- Vector3f scaledRay = new Vector3f(ray.x * distance, ray.y * distance, ray.z * distance);
- Vector3f rayEnd = Vector3f.add(camPos, scaledRay, null);
- return new BlockPos(GLHelper.floatToInt(rayEnd.x), GLHelper.floatToInt(rayEnd.y),
- GLHelper.floatToInt(rayEnd.z));
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/NoiseGenerator.java b/src/main/java/xueLi/craftGame/utils/NoiseGenerator.java
deleted file mode 100644
index d841298c..00000000
--- a/src/main/java/xueLi/craftGame/utils/NoiseGenerator.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package xueLi.craftGame.utils;
-
-import java.util.Random;
-
-import xueLi.craftGame.world.Chunk;
-
-public class NoiseGenerator {
-
- private Random r = new Random();
-
- public NoiseGenerator(long seed) {
- r.setSeed(seed);
- }
-
- private float[][] genWhiteNoise(){
- float[][] noise = new float[Chunk.size][Chunk.size];
- for(int i = 0;i < Chunk.size;i++)
- for(int j = 0;j < Chunk.size;j++)
- noise[i][j] = r.nextFloat() % 1;
- return noise;
- }
-
-
-
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/utils/Vector.java b/src/main/java/xueLi/craftGame/utils/Vector.java
deleted file mode 100644
index 704df4b9..00000000
--- a/src/main/java/xueLi/craftGame/utils/Vector.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package xueLi.craftGame.utils;
-
-public class Vector {
-
- public float x, y, z;
- public float rotX, rotY, rotZ;
-
- public Vector() {
- x = y = z = rotX = rotY = rotZ = 0;
- }
-
- public Vector(float x, float y, float z) {
- this.x = x;
- this.y = y;
- this.z = z;
- rotX = rotY = rotZ = 0;
- }
-
- public Vector(float x, float y, float z, float rotX, float rotY, float rotZ) {
- this.x = x;
- this.y = y;
- this.z = z;
- this.rotX = rotX;
- this.rotY = rotY;
- this.rotZ = rotZ;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/world/Chunk.java b/src/main/java/xueLi/craftGame/world/Chunk.java
deleted file mode 100644
index b276a705..00000000
--- a/src/main/java/xueLi/craftGame/world/Chunk.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package xueLi.craftGame.world;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import xueLi.craftGame.block.Block;
-import xueLi.craftGame.entity.Entity;
-import xueLi.craftGame.utils.BlockPos;
-
-public class Chunk {
-
- public static final int size = 16, height = 128;
- Block[][][] blockState = new Block[size][height][size];
- public int[][] heightMap = new int[size][size];
-
- public int chunkX, chunkZ;
-
- public Set entities = new HashSet();
-
- public Chunk(int chunkX, int chunkZ) {
- this.chunkX = chunkX;
- this.chunkZ = chunkZ;
- }
-
- public void update() {
-
- }
-
- public void setBlock(int x, int y, int z, Block block) {
- if (x < 0 || x >= size || y < 0 || y >= height || z < 0 || z >= size)
- return;
- blockState[x][y][z] = block;
-
- if (y > heightMap[x][z]) {
- if (block == null) {
- for (int yy = y;; y--) {
- if (this.getBlock(x, yy, z) != null) {
- heightMap[x][z] = yy;
- break;
- }
- }
- } else
- heightMap[x][z] = y;
- }
- }
-
- public Block getBlock(BlockPos pos) {
- if (pos.getX() < 0 || pos.getX() >= size || pos.getY() < 0 || pos.getY() >= height || pos.getZ() < 0
- || pos.getZ() >= size)
- return null;
- return blockState[pos.getX()][pos.getY()][pos.getZ()];
- }
-
- public Block getBlock(int x, int y, int z) {
- if (x < 0 || x >= size || y < 0 || y >= height || z < 0 || z >= size)
- return null;
- return blockState[x][y][z];
- }
-
- public boolean hasBlock(BlockPos pos) {
- if (pos.getX() < 0 || pos.getX() >= size || pos.getY() < 0 || pos.getY() >= height || pos.getZ() < 0
- || pos.getZ() >= size)
- return false;
- return blockState[pos.getX()][pos.getY()][pos.getZ()] != null;
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/world/ChunkGenerator.java b/src/main/java/xueLi/craftGame/world/ChunkGenerator.java
deleted file mode 100644
index 616c376c..00000000
--- a/src/main/java/xueLi/craftGame/world/ChunkGenerator.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package xueLi.craftGame.world;
-
-import xueLi.craftGame.block.Block;
-
-public class ChunkGenerator {
-
- //įæä¸ä¸Ēčļ åšŗåĻ å¯äģĨå¨Worldįąģįæé å¨ééĸæžå°
- public static Chunk superflat(int chunkX, int chunkZ) {
- Chunk chunk = new Chunk(chunkX,chunkZ);
- for (int x = 0; x < Chunk.size; x++) {
- for (int z = 0; z < Chunk.size; z++) {
- for (int y = 0; y < 4; y++) {
- chunk.blockState[x][y][z] = new Block(1);
-
- }
- chunk.blockState[x][4][z] = new Block(2);
-
- chunk.heightMap[x][z] = 4;
- }
- }
- return chunk;
- }
-
- //čŋ鿝ä¸įįææå ŗį äŊæ˛ĄæäŊŋį¨
- public static Chunk gen(int chunkX,int chunkZ) {
- Chunk chunk = new Chunk(chunkX,chunkZ);
- for (int x = 0; x < Chunk.size; x++) {
- for (int z = 0; z < Chunk.size; z++) {
-
- for(int y = 0;y < Chunk.height;y++)
- {
-
- }
-
- }
- }
- return chunk;
- }
-
-
-
-
-
-}
diff --git a/src/main/java/xueLi/craftGame/world/World.java b/src/main/java/xueLi/craftGame/world/World.java
deleted file mode 100644
index e40a4d6e..00000000
--- a/src/main/java/xueLi/craftGame/world/World.java
+++ /dev/null
@@ -1,216 +0,0 @@
-package xueLi.craftGame.world;
-
-import java.math.BigDecimal;
-import java.nio.FloatBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import xueLi.craftGame.block.Block;
-import xueLi.craftGame.entity.Entity;
-import xueLi.craftGame.entity.HitBox;
-import xueLi.craftGame.entity.Player;
-import xueLi.craftGame.entity.renderer.EntityRenderer;
-import xueLi.craftGame.utils.BlockPos;
-import xueLi.craftGame.utils.ChunkPos;
-import xueLi.craftGame.utils.GLHelper;
-
-public class World {
-
- private Map chunks = new HashMap();
-
- private boolean isWorldLimited = false;
- public int wlimit_long, wlimit_width;
- private int limit_long, limit_width;
-
- //ä¸įå¤§å° æåēåæĨįŽ
- public World(int limit_long, int limit_width) {
- isWorldLimited = true;
- this.wlimit_long = limit_long * Chunk.size;
- this.wlimit_width = limit_width * Chunk.size;
- this.limit_long = limit_long;
- this.limit_width = limit_width;
-
- }
-
- //ä¸įįæįæšæŗ
- public void generate() {
- for (int x = 0; x < limit_long; x++) {
- for (int z = 0; z < limit_width; z++) {
- chunks.put(GLHelper.vert2ToLong(x, z), ChunkGenerator.superflat(x, z));
- }
- }
- }
-
- private static Chunk tempChunk;
- public Block getBlock(int x, int y, int z) {
- ChunkPos cp = getChunkPosFromBlock(x, z);
- if (isWorldLimited) {
- if (cp.getX() > this.limit_long - 1 || cp.getZ() > this.limit_width - 1 || cp.getX() < 0 || cp.getZ() < 0)
- return null;
-
- int xInChunk = x - cp.getX() * Chunk.size;
- int zInChunk = z - cp.getZ() * Chunk.size;
-
- if (tempChunk == null || cp.getX() != tempChunk.chunkX || cp.getZ() != tempChunk.chunkZ)
- tempChunk = chunks.get(GLHelper.vert2ToLong(cp.getX(), cp.getZ()));
- if (tempChunk == null)
- return null;
- return tempChunk.getBlock(xInChunk, y, zInChunk);
- }
- return null;
- }
-
-
- public void setBlock(int x, int y, int z, Block block) {
- ChunkPos cp = getChunkPosFromBlock(x, z);
- if (isWorldLimited) {
- if (cp.getX() > this.limit_long - 1 || cp.getZ() > this.limit_width - 1 || cp.getX() < 0 || cp.getZ() < 0
- || y > Chunk.height - 1 || y < 0)
- return;
-
- int xInChunk = x - cp.getX() * Chunk.size;
- int zInChunk = z - cp.getZ() * Chunk.size;
- chunks.get(GLHelper.vert2ToLong(cp.getX(), cp.getZ())).setBlock(xInChunk, y, zInChunk, block);
- }
- }
-
- //I accidently found that sometimes the game will throw NullPointerException on World.java:77 and I dont know why
- public void setBlock(BlockPos p, Block b) {
- if(p == null)
- return;
- setBlock(p.getX(), p.getY(), p.getZ(), b);
- }
-
- public void setBlock(BlockPos p, int blockID) {
- if(p == null)
- return;
- setBlock(p.getX(), p.getY(), p.getZ(), new Block(blockID));
- }
-
- public boolean hasBlock(BlockPos p) {
- ChunkPos cp = getChunkPosFromBlock(p.getX(), p.getZ());
- if (isWorldLimited) {
- if (cp.getX() > this.limit_long - 1 || cp.getZ() > this.limit_width - 1 || cp.getX() < 0 || cp.getZ() < 0)
- return false;
-
- int xInChunk = p.getX() - cp.getX() * Chunk.size;
- int zInChunk = p.getZ() - cp.getZ() * Chunk.size;
- return chunks.get(GLHelper.vert2ToLong(cp.getX(), cp.getZ()))
- .hasBlock(new BlockPos(xInChunk, p.getY(), zInChunk));
- }
- return false;
- }
-
- public static int chunkRenderDistance = 5;
-
- public int draw(Player cam, FloatBuffer buffer) {
- int vertCount = 0;
- int camX = (int) cam.pos.x;
- int camZ = (int) cam.pos.z;
- ChunkPos chunkPos = this.getChunkPosFromBlock(camX, camZ);
- for (int chunkX = chunkPos.getX() - chunkRenderDistance; chunkX < chunkPos.getX()
- + chunkRenderDistance; chunkX++) {
- for (int chunkZ = chunkPos.getZ() - chunkRenderDistance; chunkZ < chunkPos.getZ()
- + chunkRenderDistance; chunkZ++) {
- Chunk c = this.chunks.get(GLHelper.vert2ToLong(chunkX, chunkZ));
- if (c == null)
- continue;
- c.update();
- if (!GLHelper.isChunkInFrustum(chunkX, Chunk.height, chunkZ))
- continue;
- EntityRenderer.buildMesh(c);
- for (int xInChunk = 0; xInChunk < Chunk.size; xInChunk++) {
- for (int zInChunk = 0; zInChunk < Chunk.size; zInChunk++) {
- int yMax = c.heightMap[xInChunk][zInChunk];
- for (int y = 0; y <= yMax; y++) {
- int x = chunkX * Chunk.size + xInChunk;
- int z = chunkZ * Chunk.size + zInChunk;
- Block block = c.getBlock(xInChunk, y, zInChunk);
- if (block == null)
- continue;
- if (c.getBlock(xInChunk, y - 1, zInChunk) == null) {
- vertCount += block.getDrawData(buffer, x, y, z, 5);
- }
- if (c.getBlock(xInChunk, y + 1, zInChunk) == null) {
- vertCount += block.getDrawData(buffer, x, y, z, 4);
- }
- if (xInChunk - 1 < 0 ? this.getBlock(x - 1, y, z) == null
- : c.getBlock(xInChunk - 1, y, zInChunk) == null) {
- vertCount += block.getDrawData(buffer, x, y, z, 3);
- }
- if (xInChunk + 1 >= Chunk.size ? this.getBlock(x + 1, y, z) == null
- : c.getBlock(xInChunk + 1, y, zInChunk) == null) {
- vertCount += block.getDrawData(buffer, x, y, z, 1);
- }
- if (zInChunk - 1 < 0 ? this.getBlock(x, y, z - 1) == null
- : c.getBlock(xInChunk, y, zInChunk - 1) == null) {
- vertCount += block.getDrawData(buffer, x, y, z, 0);
- }
- if (zInChunk + 1 >= Chunk.size ? this.getBlock(x, y, z + 1) == null
- : c.getBlock(xInChunk, y, zInChunk + 1) == null) {
- vertCount += block.getDrawData(buffer, x, y, z, 2);
- }
-
-
- }
- }
- }
- }
- }
-
- return vertCount;
- }
-
- public void addEntity(Entity entity) {
- ChunkPos chunkPos = getChunkPosFromBlock(entity.pos.x,entity.pos.z);
- chunks.get(GLHelper.vert2ToLong(chunkPos.getX(), chunkPos.getZ())).entities.add(entity);
- }
-
- public ArrayList getHitBoxes(HitBox box, int worldMaxSize) {
- int x1 = new BigDecimal(String.valueOf(box.x1)).setScale(0, BigDecimal.ROUND_DOWN).intValue();
- int x2 = new BigDecimal(String.valueOf(box.x2 + 1.0f)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
- int y1 = new BigDecimal(String.valueOf(box.y1)).setScale(0, BigDecimal.ROUND_DOWN).intValue();
- int y2 = new BigDecimal(String.valueOf(box.y2 + 1.0f)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
- int z1 = new BigDecimal(String.valueOf(box.z1)).setScale(0, BigDecimal.ROUND_DOWN).intValue();
- int z2 = new BigDecimal(String.valueOf(box.z2 + 1.0f)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
-
- if (x1 < 0)
- x1 = 0;
- if (y1 < 0)
- y1 = 0;
- if (z1 < 0)
- z1 = 0;
- if (x2 > worldMaxSize)
- x2 = worldMaxSize - 1;
- if (y2 > Chunk.height)
- y2 = Chunk.height - 1;
- if (z2 > worldMaxSize)
- z1 = worldMaxSize - 1;
-
- ArrayList boxes = new ArrayList();
- for (int x = x1; x < x2; x++) {
- for (int y = y1; y < y2; y++) {
- for (int z = z1; z < z2; z++) {
- Block block = this.getBlock(x, y, z);
- if (block == null)
- continue;
- boxes.add(block.getHitbox(x, y, z));
- }
- }
- }
- return boxes;
- }
-
- private ChunkPos getChunkPosFromBlock(int x, int z) {
- int chunkX = x / 16;
- int chunkZ = z / 16;
- return new ChunkPos(chunkX - (x < 0 ? 1 : 0), chunkZ - (z < 0 ? 1 : 0));
- }
-
- private ChunkPos getChunkPosFromBlock(float x, float z) {
- int chunkX = (int) (x / 16);
- int chunkZ = (int) (z / 16);
- return new ChunkPos(chunkX - (x < 0 ? 1 : 0), chunkZ - (z < 0 ? 1 : 0));
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/world/WorldRenderer.java b/src/main/java/xueLi/craftGame/world/WorldRenderer.java
deleted file mode 100644
index f5600a44..00000000
--- a/src/main/java/xueLi/craftGame/world/WorldRenderer.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package xueLi.craftGame.world;
-
-import java.nio.FloatBuffer;
-
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.opengl.GL13;
-import org.lwjgl.util.glu.GLU;
-
-import xueLi.craftGame.entity.Player;
-import xueLi.craftGame.utils.DisplayManager;
-import xueLi.craftGame.utils.GLHelper;
-
-public class WorldRenderer {
-
- private static int texture;
- private static FloatBuffer buffer;
-
- private static World w = new World(8,8);
-
- private static Player player = new Player(8, 8, 8, 0, 0, 0);
-
- public static void init() {
- texture = GLHelper.registerTexture("res/textures.png");
- WorldVertexBinder.init();
-
- //ä¸éĸéŖä¸¤ä¸ĒåŊæ°æ¯čˇOpenGLæå ŗį
- w.generate();
-
- }
-
- public static void render() {
- GL11.glClearColor(0.5f, 0.8f, 1.0f, 1.0f);
-
- player.tick(w);
- buffer = WorldVertexBinder.map();
- int v = w.draw(player, buffer);
-
- buffer.flip();
-
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- GL13.glActiveTexture(GL13.GL_TEXTURE0);
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
- //GL11.glColor3f(1, 1, 1);
- WorldVertexBinder.draw(GL11.GL_TRIANGLES, v);
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
-
- buffer.clear();
-
- //EntityRenderer.render();
-
- int error = GL11.glGetError();
- if (error != 0) {
- System.out.println(GLU.gluErrorString(error));
- }
-
- if (DisplayManager.tickResize()) {
- GLHelper.perspecive(DisplayManager.d_width, DisplayManager.d_height, 90.0f, 0.1f, 1000.0f);
- }
- GLHelper.player(player);
- GLHelper.calculateFrustumPlane();
-
- player.pickTick(w);
- }
-
- public static void release() {
- GLHelper.deleteTexture(texture);
-
- }
-
-}
diff --git a/src/main/java/xueLi/craftGame/world/WorldVertexBinder.java b/src/main/java/xueLi/craftGame/world/WorldVertexBinder.java
deleted file mode 100644
index 902a8452..00000000
--- a/src/main/java/xueLi/craftGame/world/WorldVertexBinder.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package xueLi.craftGame.world;
-
-import java.nio.FloatBuffer;
-
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.opengl.GL15;
-
-public class WorldVertexBinder {
-
- private static int vbo;
-
- public static void init() {
- vbo = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, 1073741824, GL15.GL_DYNAMIC_DRAW);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- }
-
- public static FloatBuffer map() {
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
- return GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY, null).asFloatBuffer();
- }
-
- public static void draw(int type, int vertex_count) {
- GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER);
- GL11.glInterleavedArrays(GL11.GL_T2F_V3F, 0, 0);
- GL11.glDrawArrays(type, 0, vertex_count);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- }
-
-}
diff --git a/src/main/java/xueli/animation/AnimationBinding.java b/src/main/java/xueli/animation/AnimationBinding.java
new file mode 100644
index 00000000..7c511f2c
--- /dev/null
+++ b/src/main/java/xueli/animation/AnimationBinding.java
@@ -0,0 +1,29 @@
+package xueli.animation;
+
+public interface AnimationBinding {
+
+ public void animStart();
+
+ default public void animStartFromEnd() {
+ this.animStart();
+ }
+
+ public void animProgress(double timeProgress);
+
+ public void animEnd();
+
+ public static AnimationBinding EMPTY = new AnimationBinding() {
+ @Override
+ public void animStart() {
+ }
+
+ @Override
+ public void animProgress(double timeProgress) {
+ }
+
+ @Override
+ public void animEnd() {
+ }
+ };
+
+}
diff --git a/src/main/java/xueli/animation/AnimationBindingBuilder.java b/src/main/java/xueli/animation/AnimationBindingBuilder.java
new file mode 100644
index 00000000..d211fbda
--- /dev/null
+++ b/src/main/java/xueli/animation/AnimationBindingBuilder.java
@@ -0,0 +1,106 @@
+package xueli.animation;
+
+import java.util.ArrayList;
+
+public class AnimationBindingBuilder {
+
+ private ArrayList bindings = new ArrayList<>();
+
+ private double lastPointTime = 0;
+ private ArrayList separatePoints = new ArrayList<>();
+
+ {
+ separatePoints.add(0.0);
+ }
+
+ private AnimationBindingBuilder() {
+ }
+
+ public AnimationBindingBuilder add(AnimationBinding binding, double part) {
+ binding = binding == null ? AnimationBinding.EMPTY : binding;
+ bindings.add(binding);
+ this.lastPointTime += part;
+ separatePoints.add(this.lastPointTime);
+ return this;
+ }
+
+ public AnimationBinding build() {
+ if (bindings.isEmpty())
+ return AnimationBinding.EMPTY;
+
+ double allCount = lastPointTime;
+
+ return new AnimationBinding() {
+ AnimationBinding current;
+ int currentAnimIndex;
+ double currentBindingStart, currentBindingEnd, currentBindingDuration;
+ double lastTimeProgress;
+
+ @Override
+ public void animStart() {
+ currentBindingStart = 0;
+ currentBindingEnd = 0;
+ currentBindingDuration = 0;
+
+ currentAnimIndex = 0;
+ refreshAnim();
+ lastTimeProgress = 0;
+
+ current.animStart();
+
+ }
+
+ @Override
+ public void animProgress(double timeProgress) {
+ double relativeTimeProgress = timeProgress * allCount;
+
+ if (relativeTimeProgress > lastTimeProgress) {
+ while (relativeTimeProgress > currentBindingEnd) {
+ current.animEnd();
+
+ currentAnimIndex++;
+ refreshAnim();
+
+ current.animStart();
+
+ }
+
+ } else if (relativeTimeProgress < lastTimeProgress) {
+ while (relativeTimeProgress < currentBindingStart) {
+ current.animStart();
+
+ currentAnimIndex--;
+ refreshAnim();
+
+ current.animStartFromEnd();
+
+ }
+
+ }
+
+ current.animProgress((relativeTimeProgress - currentBindingStart) / currentBindingDuration);
+ lastTimeProgress = relativeTimeProgress;
+
+ }
+
+ private void refreshAnim() {
+ current = bindings.get(currentAnimIndex = 0);
+ currentBindingStart = separatePoints.get(currentAnimIndex);
+ currentBindingEnd = separatePoints.get(currentAnimIndex + 1);
+ currentBindingDuration = currentBindingEnd - currentBindingStart;
+
+ }
+
+ @Override
+ public void animEnd() {
+ current.animEnd();
+
+ }
+ };
+ }
+
+ public static AnimationBindingBuilder newBuilder() {
+ return new AnimationBindingBuilder();
+ }
+
+}
diff --git a/src/main/java/xueli/animation/AnimationEndListener.java b/src/main/java/xueli/animation/AnimationEndListener.java
new file mode 100644
index 00000000..b1b426c1
--- /dev/null
+++ b/src/main/java/xueli/animation/AnimationEndListener.java
@@ -0,0 +1,7 @@
+package xueli.animation;
+
+public interface AnimationEndListener {
+
+ public void onAnimationEnd();
+
+}
diff --git a/src/main/java/xueli/animation/AnimationInstance.java b/src/main/java/xueli/animation/AnimationInstance.java
new file mode 100644
index 00000000..5823a600
--- /dev/null
+++ b/src/main/java/xueli/animation/AnimationInstance.java
@@ -0,0 +1,15 @@
+package xueli.animation;
+
+public interface AnimationInstance {
+
+ public void pause();
+
+ public void stop(double progress);
+
+ public double getProgress();
+
+ public long getDuration();
+
+ public void addAnimationEndListener(AnimationEndListener listener);
+
+}
diff --git a/src/main/java/xueli/animation/AnimationInstanceImpl.java b/src/main/java/xueli/animation/AnimationInstanceImpl.java
new file mode 100644
index 00000000..8f1762de
--- /dev/null
+++ b/src/main/java/xueli/animation/AnimationInstanceImpl.java
@@ -0,0 +1,93 @@
+package xueli.animation;
+
+import java.util.ArrayList;
+
+class AnimationInstanceImpl implements AnimationInstance {
+
+ private final AnimationBinding binding;
+ private final Curve curve;
+ private final long startTime, duration, endTime;
+ private final boolean reverse;
+
+ // Progress from the time, so its change is linear
+ private double progress = 0.0;
+ private AnimationStage stage = AnimationStage.PLAYING;
+
+ private final ArrayList endListeners = new ArrayList<>();
+
+ AnimationInstanceImpl(AnimationBinding binding, long startTime, long duration, Curve curve, boolean reverse) {
+ this.binding = binding;
+ this.startTime = startTime;
+ this.duration = duration;
+ this.curve = curve;
+ this.endTime = this.startTime + this.duration;
+
+ this.reverse = reverse;
+
+ this.binding.animStart();
+ this.progress = 0.0;
+
+ }
+
+ /**
+ * @return Whether the animation needs ticking
+ */
+ boolean tick(long currentTime) {
+ if (currentTime >= endTime) {
+ this.stage = AnimationStage.STOP;
+ this.progress = 1.0;
+ this.binding.animEnd();
+
+ endListeners.forEach(AnimationEndListener::onAnimationEnd);
+
+ return false;
+ }
+
+ switch (this.stage) {
+ case PLAYING -> {
+ this.progress = (double) (currentTime - startTime) / duration;
+ double curveValue = curve.getValue(progress);
+ if (reverse)
+ this.binding.animProgress(1 - curveValue);
+ else
+ this.binding.animProgress(curveValue);
+ }
+ case PAUSE -> {
+ }
+ case STOP -> {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void pause() {
+ this.stage = AnimationStage.PAUSE;
+
+ }
+
+ @Override
+ public void stop(double progress) {
+ this.stage = AnimationStage.STOP;
+ this.binding.animProgress(curve.getValue(progress));
+
+ }
+
+ @Override
+ public double getProgress() {
+ return this.progress;
+ }
+
+ @Override
+ public long getDuration() {
+ return this.duration;
+ }
+
+ @Override
+ public void addAnimationEndListener(AnimationEndListener listener) {
+ endListeners.add(listener);
+ }
+
+}
diff --git a/src/main/java/xueli/animation/AnimationManager.java b/src/main/java/xueli/animation/AnimationManager.java
new file mode 100644
index 00000000..21121a5a
--- /dev/null
+++ b/src/main/java/xueli/animation/AnimationManager.java
@@ -0,0 +1,55 @@
+package xueli.animation;
+
+import java.util.ArrayList;
+import java.util.function.Supplier;
+
+public class AnimationManager {
+
+ private final Supplier timeProvider;
+ private final ArrayList animationInstances = new ArrayList<>();
+
+ public AnimationManager(Supplier timeProvider) {
+ this.timeProvider = timeProvider;
+ }
+
+ public AnimationInstance start(AnimationBinding binding, Curve curve, long duration) {
+ AnimationInstanceImpl inst = new AnimationInstanceImpl(binding, timeProvider.get(), duration, curve, false);
+ animationInstances.add(inst);
+ return inst;
+ }
+
+ public AnimationInstance startReverse(AnimationBinding binding, Curve curve, long duration) {
+ AnimationInstanceImpl inst = new AnimationInstanceImpl(binding, timeProvider.get(), duration, curve, true);
+ animationInstances.add(inst);
+ return inst;
+ }
+
+ public AnimationInstance startReverse(AnimationBinding binding, Curve curve, AnimationInstance previous) {
+ return this.startReverse(binding, curve, previous.getDuration(), previous);
+ }
+
+ public AnimationInstance startReverse(AnimationBinding binding, Curve curve, long duration,
+ AnimationInstance previous) {
+ long simulateStartTime = timeProvider.get();
+ if (previous != null) {
+ double lastProgress = previous.getProgress();
+ int shouldHaveGoneTime = (int) ((1 - lastProgress) * duration);
+ simulateStartTime -= shouldHaveGoneTime;
+ }
+ AnimationInstanceImpl inst = new AnimationInstanceImpl(binding, simulateStartTime, duration, curve, true);
+ animationInstances.add(inst);
+ return inst;
+ }
+
+ public void tick() {
+ var iter = animationInstances.iterator();
+ while (iter.hasNext()) {
+ AnimationInstanceImpl inst = iter.next();
+ if (!inst.tick(timeProvider.get())) {
+ iter.remove();
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/java/xueli/animation/AnimationStage.java b/src/main/java/xueli/animation/AnimationStage.java
new file mode 100644
index 00000000..28a465be
--- /dev/null
+++ b/src/main/java/xueli/animation/AnimationStage.java
@@ -0,0 +1,7 @@
+package xueli.animation;
+
+public enum AnimationStage {
+
+ PLAYING, PAUSE, STOP;
+
+}
diff --git a/src/main/java/xueli/animation/Curve.java b/src/main/java/xueli/animation/Curve.java
new file mode 100644
index 00000000..887272c1
--- /dev/null
+++ b/src/main/java/xueli/animation/Curve.java
@@ -0,0 +1,7 @@
+package xueli.animation;
+
+public interface Curve {
+
+ public double getValue(double progress);
+
+}
diff --git a/src/main/java/xueli/animation/CurveAnimationBinding.java b/src/main/java/xueli/animation/CurveAnimationBinding.java
new file mode 100644
index 00000000..03f93695
--- /dev/null
+++ b/src/main/java/xueli/animation/CurveAnimationBinding.java
@@ -0,0 +1,18 @@
+package xueli.animation;
+
+public abstract class CurveAnimationBinding implements AnimationBinding {
+
+ private final Curve curve;
+
+ public CurveAnimationBinding(Curve curve) {
+ this.curve = curve;
+ }
+
+ @Override
+ public void animProgress(double timeProgress) {
+ this.animRealProgress(this.curve.getValue(timeProgress));
+ }
+
+ protected abstract void animRealProgress(double progress);
+
+}
diff --git a/src/main/java/xueli/animation/Curves.java b/src/main/java/xueli/animation/Curves.java
new file mode 100644
index 00000000..f6e0f5a9
--- /dev/null
+++ b/src/main/java/xueli/animation/Curves.java
@@ -0,0 +1,116 @@
+package xueli.animation;
+
+/**
+ * All the internal curves. Actually this is a clone of "https://easings.net/",
+ * so we have the same names
+ */
+public class Curves {
+
+ public final static Curve linear = x -> x;
+
+ public final static Curve easeInSine = x -> 1 - Math.cos((x * Math.PI) / 2);
+
+ public final static Curve easeOutSine = x -> Math.sin((x * Math.PI) / 2);
+
+ public final static Curve easeInOutSine = x -> -(Math.cos(Math.PI * x) - 1) / 2;
+
+ public final static Curve easeInQuad = x -> x * x;
+
+ public final static Curve easeOutQuad = x -> 1 - (1 - x) * (1 - x);
+
+ public final static Curve easeInOutQuad = x -> x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
+
+ public final static Curve easeInCubic = x -> x * x * x;
+
+ public final static Curve easeOutCubic = x -> 1 - Math.pow(1 - x, 3);
+
+ public final static Curve easeInOutCubic = x -> x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
+
+ public final static Curve easeInQuart = x -> x * x * x * x;
+
+ public final static Curve easeOutQuart = x -> 1 - Math.pow(1 - x, 4);
+
+ public final static Curve easeInOutQuart = x -> x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2;
+
+ public final static Curve easeInQuint = x -> x * x * x * x * x;
+
+ public final static Curve easeOutQuint = x -> 1 - Math.pow(1 - x, 5);
+
+ public final static Curve easeInOutQuint = x -> x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
+
+ public final static Curve easeInExpo = x -> x == 0 ? 0 : Math.pow(2, 10 * x - 10);
+
+ public final static Curve easeOutExpo = x -> x == 1 ? 1 : 1 - Math.pow(2, -10 * x);
+
+ public final static Curve easeInOutExpo = x -> x == 0 ? 0
+ : x == 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2;
+
+ public final static Curve easeInCirc = x -> 1 - Math.sqrt(1 - Math.pow(x, 2));
+
+ public final static Curve easeOutCirc = x -> Math.sqrt(1 - Math.pow(x - 1, 2));
+
+ public final static Curve easeInOutCirc = x -> x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2
+ : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
+
+ public final static Curve easeInBack = x -> {
+ double c1 = 1.70158;
+ double c3 = c1 + 1;
+ return c3 * x * x * x - c1 * x * x;
+ };
+
+ public final static Curve easeOutBack = x -> {
+ double c1 = 1.70158;
+ double c3 = c1 + 1;
+ return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
+ };
+
+ public final static Curve easeInOutBack = x -> {
+ double c1 = 1.70158;
+ double c2 = c1 * 1.525;
+ return x < 0.5 ? (Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
+ : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
+ };
+
+ public final static Curve easeInElastic = x -> {
+ double c4 = (2 * Math.PI) / 3;
+ return x == 0 ? 0 : x == 1 ? 1 : -Math.pow(2, 10 * x - 10) * Math.sin((x * 10 - 10.75) * c4);
+ };
+
+ public final static Curve easeOutElastic = x -> {
+ double c4 = (2 * Math.PI) / 3;
+ return x == 0 ? 0 : x == 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1;
+ };
+
+ public final static Curve easeInOutElastic = x -> {
+ double c5 = (2 * Math.PI) / 4.5;
+ return x == 0 ? 0
+ : x == 1 ? 1
+ : x < 0.5 ? -(Math.pow(2, 20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2
+ : (Math.pow(2, -20 * x + 10) * Math.sin((20 * x - 11.125) * c5)) / 2 + 1;
+ };
+
+ public final static Curve easeOutBounce = x -> {
+ double n1 = 7.5625;
+ double d1 = 2.75;
+ if (x < 1 / d1) {
+ return n1 * x * x;
+ } else if (x < 2 / d1) {
+ return n1 * (x -= 1.5 / d1) * x + 0.75;
+ } else if (x < 2.5 / d1) {
+ return n1 * (x -= 2.25 / d1) * x + 0.9375;
+ } else {
+ return n1 * (x -= 2.625 / d1) * x + 0.984375;
+ }
+ };
+
+ public final static Curve easeInBounce = x -> 1 - easeOutBounce.getValue(1 - x);
+
+ public final static Curve easeInOutBounce = x -> x < 0.5 ? (1 - easeOutBounce.getValue(1 - 2 * x)) / 2
+ : (1 + easeOutBounce.getValue(2 * x - 1)) / 2;
+
+ public final static Curve easeOutExtreme = x -> {
+ double exp = Math.exp(6 * x + 1);
+ return (exp - 1) / (exp + 1);
+ };
+
+}
diff --git a/src/main/java/xueli/animation/DoubleValueAnimationBinding.java b/src/main/java/xueli/animation/DoubleValueAnimationBinding.java
new file mode 100644
index 00000000..2246fd8c
--- /dev/null
+++ b/src/main/java/xueli/animation/DoubleValueAnimationBinding.java
@@ -0,0 +1,45 @@
+package xueli.animation;
+
+import java.util.function.Supplier;
+
+public abstract class DoubleValueAnimationBinding implements AnimationBinding {
+
+ private final Supplier startValueSupplier, endValueSupplier;
+ private final boolean stay;
+
+ public DoubleValueAnimationBinding(Supplier startValue, Supplier endValue, boolean stay) {
+ this.startValueSupplier = startValue;
+ this.endValueSupplier = endValue;
+ this.stay = stay;
+
+ }
+
+ private double realStartValue;
+ private double realEndValue, realDurationValue;
+
+ @Override
+ public void animStart() {
+ this.realStartValue = startValueSupplier.get();
+ this.realEndValue = endValueSupplier.get();
+ this.realDurationValue = this.realEndValue - this.realStartValue;
+
+ }
+
+ @Override
+ public void animProgress(double progress) {
+ this.progress(realStartValue + this.realDurationValue * progress);
+
+ }
+
+ @Override
+ public void animEnd() {
+ if (!stay) {
+ this.progress(realStartValue);
+ } else {
+ this.progress(realEndValue);
+ }
+ }
+
+ protected abstract void progress(double val);
+
+}
diff --git a/src/main/java/xueli/animation/FloatValueAnimationBinding.java b/src/main/java/xueli/animation/FloatValueAnimationBinding.java
new file mode 100644
index 00000000..eea1f22a
--- /dev/null
+++ b/src/main/java/xueli/animation/FloatValueAnimationBinding.java
@@ -0,0 +1,46 @@
+package xueli.animation;
+
+import java.util.function.Supplier;
+
+public abstract class FloatValueAnimationBinding implements AnimationBinding {
+
+ private final Supplier startValueSupplier, endValueSupplier;
+ private final boolean stay;
+
+ public FloatValueAnimationBinding(Supplier startValue, Supplier endValue, boolean stay) {
+ this.startValueSupplier = startValue;
+ this.endValueSupplier = endValue;
+ this.stay = stay;
+
+ }
+
+ private float realStartValue;
+ private double realEndValue, realDurationValue;
+
+ @Override
+ public void animStart() {
+ this.realStartValue = startValueSupplier.get();
+ this.realEndValue = endValueSupplier.get();
+ this.realDurationValue = this.realEndValue - this.realStartValue;
+
+ }
+
+ @Override
+ public void animProgress(double progress) {
+ this.progress((float) (realStartValue + this.realDurationValue * progress));
+// System.out.println(progress);
+
+ }
+
+ @Override
+ public void animEnd() {
+ if (!stay) {
+ this.progress(realStartValue);
+ } else {
+ this.progress((float) realEndValue);
+ }
+ }
+
+ protected abstract void progress(float val);
+
+}
diff --git a/src/main/java/xueli/animation/IntValueAnimationBinding.java b/src/main/java/xueli/animation/IntValueAnimationBinding.java
new file mode 100644
index 00000000..96d02d6c
--- /dev/null
+++ b/src/main/java/xueli/animation/IntValueAnimationBinding.java
@@ -0,0 +1,46 @@
+package xueli.animation;
+
+import java.util.function.Supplier;
+
+public abstract class IntValueAnimationBinding implements AnimationBinding {
+
+ private final Supplier startValueSupplier, endValueSupplier;
+ private final boolean stay;
+
+ public IntValueAnimationBinding(Supplier startValue, Supplier endValue, boolean stay) {
+ this.startValueSupplier = startValue;
+ this.endValueSupplier = endValue;
+ this.stay = stay;
+
+ }
+
+ private int realStartValue;
+ private double realEndValue, realDurationValue;
+
+ @Override
+ public void animStart() {
+ this.realStartValue = startValueSupplier.get();
+ this.realEndValue = endValueSupplier.get();
+ this.realDurationValue = this.realEndValue - this.realStartValue;
+// System.out.println(realStartValue + ", " + realEndValue + ", " + realDurationValue);
+
+ }
+
+ @Override
+ public void animProgress(double progress) {
+ this.progress((int) (realStartValue + this.realDurationValue * progress));
+// System.out.println(realStartValue + ", " + realDurationValue + ", " + progress);
+ }
+
+ @Override
+ public void animEnd() {
+ if (!stay) {
+ this.progress(realStartValue);
+ } else {
+ this.progress((int) realEndValue);
+ }
+ }
+
+ protected abstract void progress(int val);
+
+}
diff --git a/src/main/java/xueli/animation/StateChangingTransitionCaller.java b/src/main/java/xueli/animation/StateChangingTransitionCaller.java
new file mode 100644
index 00000000..f920b254
--- /dev/null
+++ b/src/main/java/xueli/animation/StateChangingTransitionCaller.java
@@ -0,0 +1,7 @@
+package xueli.animation;
+
+public interface StateChangingTransitionCaller {
+
+ public void announceTransition(boolean state);
+
+}
diff --git a/src/main/java/xueli/animation/TransitionBinding.java b/src/main/java/xueli/animation/TransitionBinding.java
new file mode 100644
index 00000000..ed1f9d72
--- /dev/null
+++ b/src/main/java/xueli/animation/TransitionBinding.java
@@ -0,0 +1,19 @@
+package xueli.animation;
+
+public abstract class TransitionBinding implements AnimationBinding {
+
+ public TransitionBinding() {
+ }
+
+ @Override
+ public void animStart() {
+ this.animProgress(0.0);
+
+ }
+
+ @Override
+ public void animEnd() {
+ this.animProgress(1.0);
+ }
+
+}
diff --git a/src/main/java/xueli/animation/TransitionCaller.java b/src/main/java/xueli/animation/TransitionCaller.java
new file mode 100644
index 00000000..38c41efd
--- /dev/null
+++ b/src/main/java/xueli/animation/TransitionCaller.java
@@ -0,0 +1,7 @@
+package xueli.animation;
+
+public interface TransitionCaller {
+
+ public void announceTransition();
+
+}
diff --git a/src/main/java/xueli/animation/TransitionManager.java b/src/main/java/xueli/animation/TransitionManager.java
new file mode 100644
index 00000000..2e42a3d9
--- /dev/null
+++ b/src/main/java/xueli/animation/TransitionManager.java
@@ -0,0 +1,61 @@
+package xueli.animation;
+
+public class TransitionManager {
+
+ private final AnimationManager animator;
+
+ public TransitionManager(AnimationManager animator) {
+ this.animator = animator;
+ }
+
+ public TransitionCaller registerNewTransition(TransitionBinding binding) {
+ return this.registerNewTransition(binding, Curves.linear, 0);
+ }
+
+ public TransitionCaller registerNewTransition(TransitionBinding binding, Curve curve, long duration) {
+ TransitionCaller caller = new TransitionCaller() {
+ private AnimationInstance previous;
+
+ @Override
+ public void announceTransition() {
+ if (previous != null) {
+ previous.stop(previous.getProgress());
+ }
+
+ AnimationInstance newInstance = animator.start(binding, curve, duration);
+ newInstance.addAnimationEndListener(() -> {
+ previous = null;
+ });
+ this.previous = newInstance;
+
+ }
+ };
+ caller.announceTransition();
+ return caller;
+ }
+
+ public StateChangingTransitionCaller registerNewStateChangingTransition(TransitionBinding binding, Curve curve,
+ long duration) {
+ StateChangingTransitionCaller caller = new StateChangingTransitionCaller() {
+ private AnimationInstance previous;
+
+ @Override
+ public void announceTransition(boolean state) {
+ if (previous != null) {
+ previous.stop(previous.getProgress());
+ }
+
+ AnimationInstance newInstance = state ? animator.start(binding, curve, duration)
+ : animator.startReverse(binding, curve, duration);
+ newInstance.addAnimationEndListener(() -> {
+ previous = null;
+ });
+ this.previous = newInstance;
+
+ }
+ };
+ caller.announceTransition(false);
+ return caller;
+ }
+
+}
diff --git a/src/main/java/xueli/daw/Channel.java b/src/main/java/xueli/daw/Channel.java
new file mode 100644
index 00000000..fc883389
--- /dev/null
+++ b/src/main/java/xueli/daw/Channel.java
@@ -0,0 +1,59 @@
+package xueli.daw;
+
+import java.util.ArrayList;
+
+public class Channel {
+
+ private final DawContext context;
+
+ private Generator generator;
+ private final ArrayList pluginChain = new ArrayList<>();
+
+ private final int[] buffer1 = new int[DawContext.BUFFER_SIZE];
+ private final int[] buffer2 = new int[DawContext.BUFFER_SIZE];
+
+ public Channel(DawContext context) {
+ this.context = context;
+ }
+
+ public void setGenerator(Generator generator) {
+ this.generator = generator;
+ }
+
+ public Generator getGenerator() {
+ return generator;
+ }
+
+ // Can plugins be singleton? No
+ public void addPlugin(Plugin plugin) {
+ this.pluginChain.add(plugin);
+ }
+
+ public void removePlugin(Plugin plugin) {
+ this.pluginChain.remove(plugin);
+ }
+
+ // Notice that the array yielded can be changed outside
+
+ public int[] tick(double time) {
+ if(generator == null) return null;
+
+ // Double buffer
+ int[] src = buffer1;
+ int[] dest = buffer2;
+
+ generator.progress(dest, time, context);
+
+ for(Plugin p : pluginChain) {
+ int[] temp = src;
+ src = dest;
+ dest = temp;
+
+ p.progress(src, dest, time, context);
+
+ }
+
+ return dest;
+ }
+
+}
diff --git a/src/main/java/xueli/daw/ChannelManager.java b/src/main/java/xueli/daw/ChannelManager.java
new file mode 100644
index 00000000..7f22f87e
--- /dev/null
+++ b/src/main/java/xueli/daw/ChannelManager.java
@@ -0,0 +1,92 @@
+package xueli.daw;
+
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+// The manager just store the channel, so the life-cycle should be managed by the user!
+public class ChannelManager {
+
+ private final DawContext context;
+ private final ArrayList channels = new ArrayList<>();
+
+ private double time = 0.0;
+
+ public ChannelManager(DawContext context) {
+ this.context = context;
+
+ }
+
+ private int[] buffer;
+ private byte[] destBuffer = new byte[DawContext.BUFFER_SIZE * DawContext.GLOBAL_FORMAT.getSampleSizeInBits()];
+
+ public void tick() {
+ time += DawContext.BUFFER_AHEAD_TIME;
+
+ AtomicBoolean firstApply = new AtomicBoolean(true);
+
+ channels.parallelStream()
+ .map(c -> c.tick(time))
+ // I want to make a collector myself but seems can't
+ // And I don't want to collect them either
+ .forEachOrdered(i -> {
+ if(i == null) return;
+ if(firstApply.get()) {
+ buffer = i;
+ firstApply.set(false);
+ } else {
+ for(int j = 0; j < DawContext.BUFFER_SIZE; j++) {
+ // Blend
+ buffer[j] = (buffer[j] + i[j]) / 2;
+ }
+ }
+ });
+
+ if(buffer == null) return;
+
+ // Convert to sample bit
+ for(int i = 0; i < DawContext.BUFFER_SIZE; i++) {
+ double percentage = (double) buffer[i] / Integer.MAX_VALUE;
+ percentage = Math.min(1.0, percentage);
+ percentage = Math.max(-1.0, percentage);
+
+ int sampleValue = (int) (percentage * DawContext.MAX_SAMPLE_VALUE);
+ System.out.println(sampleValue);
+ for(int j = 0; j < DawContext.SAMPLE_BYTES_COUNT; j++) {
+ // little-endian
+ destBuffer[i * DawContext.SAMPLE_BYTES_COUNT + j] = (byte) ((sampleValue >> (j * 8)) & (1 << 8 - 1));
+ }
+
+ // Set sign bit
+ if(sampleValue < 0) {
+ destBuffer[i * DawContext.SAMPLE_BYTES_COUNT] |= (1 << 8);
+ }
+
+ }
+
+ context.streamer.write(destBuffer);
+
+ }
+
+ public int addChannel(Channel channel) {
+ int index = this.channels.size();
+ this.channels.add(channel);
+ return index;
+ }
+
+ public boolean remove(Channel channel) {
+ return this.channels.remove(channel);
+ }
+
+ public Channel removeChannel(int index) {
+ return this.channels.remove(index);
+ }
+
+ public int getChannelsCount() {
+ return this.channels.size();
+ }
+
+ public Channel getChannelFromIndex(int i) {
+ return this.channels.get(i);
+ }
+
+}
diff --git a/src/main/java/xueli/daw/DawContext.java b/src/main/java/xueli/daw/DawContext.java
new file mode 100644
index 00000000..2ddfebed
--- /dev/null
+++ b/src/main/java/xueli/daw/DawContext.java
@@ -0,0 +1,50 @@
+package xueli.daw;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.LineUnavailableException;
+
+import xueli.daw.driver.JavaSoundDriver;
+import xueli.daw.driver.JavaSoundStream;
+
+public class DawContext {
+
+ public static final AudioFormat GLOBAL_FORMAT = new AudioFormat(44100, 16, 1, true, false);
+ public static final int BUFFER_SIZE = 2048;
+ public static final double BUFFER_AHEAD_TIME = (double) BUFFER_SIZE / GLOBAL_FORMAT.getSampleRate();
+
+ public static final int SAMPLE_BYTES_COUNT = GLOBAL_FORMAT.getSampleSizeInBits() >> 3;
+ public static final int MAX_SAMPLE_VALUE = (1 << (GLOBAL_FORMAT.getSampleSizeInBits() - 1)) - 1;
+
+ private final JavaSoundDriver driver;
+ final JavaSoundStream streamer;
+
+ private final ChannelManager channels;
+
+ public DawContext() {
+ try {
+ this.driver = new JavaSoundDriver(GLOBAL_FORMAT);
+ } catch (LineUnavailableException e) {
+ throw new RuntimeException(e);
+ }
+ this.streamer = driver.start();
+
+ this.channels = new ChannelManager(this);
+
+ }
+
+ public ChannelManager getChannelManager() {
+ return channels;
+ }
+
+ public void tick() {
+ this.channels.tick();
+
+ }
+
+ public void release() {
+ this.streamer.close();
+ this.driver.release();
+
+ }
+
+}
diff --git a/src/main/java/xueli/daw/Generator.java b/src/main/java/xueli/daw/Generator.java
new file mode 100644
index 00000000..85d1c442
--- /dev/null
+++ b/src/main/java/xueli/daw/Generator.java
@@ -0,0 +1,7 @@
+package xueli.daw;
+
+public interface Generator {
+
+ public void progress(int[] dest, double time, DawContext context);
+
+}
diff --git a/src/main/java/xueli/daw/Player.java b/src/main/java/xueli/daw/Player.java
new file mode 100644
index 00000000..acb814ca
--- /dev/null
+++ b/src/main/java/xueli/daw/Player.java
@@ -0,0 +1,9 @@
+package xueli.daw;
+
+interface Player {
+
+ public void progressForward(double time);
+
+ public void release();
+
+}
diff --git a/src/main/java/xueli/daw/Plugin.java b/src/main/java/xueli/daw/Plugin.java
new file mode 100644
index 00000000..c7072ef7
--- /dev/null
+++ b/src/main/java/xueli/daw/Plugin.java
@@ -0,0 +1,7 @@
+package xueli.daw;
+
+public interface Plugin {
+
+ public void progress(int[] src, int[] dest, double time, DawContext context);
+
+}
diff --git a/src/main/java/xueli/daw/driver/ALBuffer.java b/src/main/java/xueli/daw/driver/ALBuffer.java
new file mode 100644
index 00000000..c1f2f1b3
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/ALBuffer.java
@@ -0,0 +1,62 @@
+package xueli.daw.driver;
+
+import java.util.Objects;
+
+import org.lwjgl.openal.AL11;
+
+import xueli.utils.buffer.BufferSyncor;
+import xueli.utils.buffer.LotsOfByteBuffer;
+
+public class ALBuffer {
+
+ final int id;
+
+ BufferFormat format;
+ int frequency;
+
+ final BufferSyncor bufferManager = new BufferSyncor();
+
+ public ALBuffer(int id) {
+ this.id = id;
+ }
+
+ public void setBuffer(LotsOfByteBuffer buffer, BufferFormat format, int frequency) {
+ this.format = format;
+ this.frequency = frequency;
+ this.bufferManager.updateBuffer(buffer);
+
+ }
+
+ public BufferSyncor.BackBuffer createBackBuffer(BufferFormat format, int frequency) {
+ this.format = format;
+ this.frequency = frequency;
+ return this.bufferManager.createBackBuffer();
+ }
+
+ // Maybe here we have to do this ourselves
+ public void doingSyncIfNecessary() {
+ this.bufferManager.doingSyncIfNecessary(b -> AL11.alBufferData(this.id, BufferFormat.getALFormat(this.format), b.getBuffer(), this.frequency));
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ALBuffer other = (ALBuffer) obj;
+ return id == other.id;
+ }
+
+// public BufferState getState() {
+// return BufferState.getFromAL(AL11.algetbuffer);
+// }
+
+}
diff --git a/src/main/java/xueli/daw/driver/ALDriver.java b/src/main/java/xueli/daw/driver/ALDriver.java
new file mode 100644
index 00000000..b93eac85
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/ALDriver.java
@@ -0,0 +1,85 @@
+package xueli.daw.driver;
+
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.util.HashMap;
+
+import org.lwjgl.openal.AL;
+import org.lwjgl.openal.AL11;
+import org.lwjgl.openal.ALC;
+import org.lwjgl.openal.ALC11;
+import org.lwjgl.openal.ALCCapabilities;
+import xueli.utils.logger.Logger;
+
+// The driver is designed for DAW so it doesn't provide functions like "effects" or "positions".
+// But this group of classes can provide.
+// Not used!
+public class ALDriver {
+
+ private static final Logger LOGGER = new Logger();
+
+ private final long context;
+ private HashMap bufferPool = new HashMap<>();
+
+ public ALDriver(ByteBuffer deviceSpecifier) {
+ long device = ALC11.alcOpenDevice(deviceSpecifier);
+ if(device == 0) {
+ throw new RuntimeException("Can't open OpenAL device!");
+ }
+
+ ALCCapabilities deviceCaps = ALC.createCapabilities(device);
+ this.context = ALC11.alcCreateContext(device, (IntBuffer) null);
+ if (context == 0) {
+ throw new IllegalStateException("Failed to create OpenAL context.");
+ }
+ ALC11.alcMakeContextCurrent(context);
+ AL.createCapabilities(deviceCaps);
+
+ this.printDeviceInfo(device);
+
+ }
+
+ private void printDeviceInfo(long device) {
+ // Keep the same code structure as OpenGL :}
+ String nameString = AL11.alGetString(AL11.AL_VENDOR);
+ String platform = AL11.alGetString(AL11.AL_RENDERER);
+ String version = AL11.alGetString(AL11.AL_VERSION);
+ LOGGER.warning("[DeviceInfo] OpenAL: " + nameString + ", " + platform + ", " + version);
+
+
+ }
+
+ public ALSpeaker createSpeaker() {
+ int speaker = AL11.alGenSources();
+ return new ALSpeaker(speaker, this);
+ }
+
+ public void releaseSpeaker(ALSpeaker speaker) {
+ AL11.alDeleteSources(speaker.id);
+
+ }
+
+ public ALBuffer createBuffer() {
+ int name = AL11.alGenBuffers();
+ var bufferObj = new ALBuffer(name);
+ this.bufferPool.put(name, bufferObj);
+ return bufferObj;
+ }
+
+ public ALBuffer getBufferFromId(int id) {
+ return bufferPool.get(id);
+ }
+
+ public void releaseBuffer(ALBuffer buffer) {
+ AL11.alDeleteBuffers(buffer.id);
+ this.bufferPool.remove(buffer.id);
+
+ }
+
+ public void release() {
+ ALC11.alcMakeContextCurrent(0);
+ ALC11.alcDestroyContext(this.context);
+
+ }
+
+}
diff --git a/src/main/java/xueli/daw/driver/ALSpeaker.java b/src/main/java/xueli/daw/driver/ALSpeaker.java
new file mode 100644
index 00000000..491fd9ea
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/ALSpeaker.java
@@ -0,0 +1,105 @@
+package xueli.daw.driver;
+
+import java.nio.IntBuffer;
+import org.lwjgl.openal.AL11;
+import org.lwjgl.system.MemoryUtil;
+
+public class ALSpeaker {
+
+ final int id;
+ final ALDriver context;
+
+ public ALSpeaker(int id, ALDriver context) {
+ this.id = id;
+ this.context = context;
+ }
+
+ public void setBuffer(ALBuffer buffer) {
+ if(buffer == null)
+ AL11.alSourcei(this.id, AL11.AL_BUFFER, 0);
+ else {
+ AL11.alSourcei(this.id, AL11.AL_BUFFER, buffer.id);
+ }
+
+ }
+
+ public void setPitch(float pitch) {
+ AL11.alSourcef(this.id, AL11.AL_PITCH, pitch);
+ }
+
+ public void setGain(float gain) {
+ AL11.alSourcef(this.id, AL11.AL_GAIN, gain);
+ }
+
+ public void setLooping(boolean loop) {
+ AL11.alSourcei(this.id, AL11.AL_LOOPING, loop ? 1 : 0);
+ }
+
+ public void play() {
+ AL11.alSourcePlay(this.id);
+ }
+
+ public void pause() {
+ AL11.alSourcePause(this.id);
+ }
+
+ public void stop() {
+ AL11.alSourceStop(this.id);
+ }
+
+ public void rewind() {
+ AL11.alSourceRewind(this.id);
+ }
+
+ public SourceState getState() {
+ int state = AL11.alGetSourcei(this.id, AL11.AL_SOURCE_STATE);
+ return SourceState.getFromAL(state);
+ }
+
+ public SourceType getType() {
+ int type = AL11.alGetSourcei(this.id, AL11.AL_SOURCE_TYPE);
+ return SourceType.getFromAL(type);
+ }
+
+ public void queueBuffer(ALBuffer... queue) {
+ if(queue.length == 1) {
+ AL11.alSourceQueueBuffers(this.id, queue[0].id);
+ return;
+ }
+
+ // this time we can have full control of this memory
+ IntBuffer arrQueueNames = MemoryUtil.memAllocInt(queue.length);
+
+ for(ALBuffer buf : queue) { // Is this slower than directly access to array?
+ arrQueueNames.put(buf.id);
+ }
+ arrQueueNames.flip();
+ AL11.alSourceQueueBuffers(this.id, arrQueueNames);
+
+ MemoryUtil.memFree(arrQueueNames);
+
+ }
+
+ // Unqueue the buffer and put it in the queue
+ public void unqueueBuffer(ALBuffer[] dest) {
+ int[] temp = new int[dest.length];
+ AL11.alSourceUnqueueBuffers(this.id, temp);
+ for(int i = 0; i < dest.length; i++) {
+ dest[i] = context.getBufferFromId(temp[i]);
+ }
+ }
+
+ public int queryProcessedBufferCount() {
+ return AL11.alGetSourcei(this.id, AL11.AL_BUFFERS_PROCESSED);
+ }
+
+ public void queryProcessedBuffer(ALBuffer[] dest) {
+ int[] temp = new int[dest.length];
+ AL11.alGetSourceiv(this.id, AL11.AL_BUFFERS_PROCESSED, temp);
+ for(int i = 0; i < dest.length; i++) {
+ dest[i] = context.getBufferFromId(temp[i]);
+ }
+
+ }
+
+}
diff --git a/src/main/java/xueli/daw/driver/AudioDriver.java b/src/main/java/xueli/daw/driver/AudioDriver.java
new file mode 100644
index 00000000..4b8763a3
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/AudioDriver.java
@@ -0,0 +1,6 @@
+package xueli.daw.driver;
+
+// TODO: Wrap OpenAL like GraphicDriver
+public interface AudioDriver {
+
+}
diff --git a/src/main/java/xueli/daw/driver/BufferFormat.java b/src/main/java/xueli/daw/driver/BufferFormat.java
new file mode 100644
index 00000000..794acfa4
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/BufferFormat.java
@@ -0,0 +1,31 @@
+package xueli.daw.driver;
+
+import org.lwjgl.openal.AL11;
+
+public enum BufferFormat {
+
+ // For now it is the same as OpenAL because LovelyZeeiam doesn't know much about other format!
+ MONO8, MONO16, STEREO8, STEREO16;
+
+ // Will be moved when make ALDriver to interface!
+ public static int getALFormat(BufferFormat format) {
+ return switch (format){
+ case MONO8 -> AL11.AL_FORMAT_MONO8;
+ case MONO16 -> AL11.AL_FORMAT_MONO16;
+ case STEREO8 -> AL11.AL_FORMAT_STEREO8;
+ case STEREO16 -> AL11.AL_FORMAT_STEREO16;
+ default -> throw new IllegalArgumentException("Unexpected value: " + format);
+ };
+ }
+
+ public static BufferFormat getFromAL(int format) {
+ return switch (format) {
+ case AL11.AL_FORMAT_MONO8 -> MONO8;
+ case AL11.AL_FORMAT_MONO16 -> MONO16;
+ case AL11.AL_FORMAT_STEREO8 -> STEREO8;
+ case AL11.AL_FORMAT_STEREO16 -> STEREO16;
+ default -> throw new IllegalArgumentException("Unexpected value: " + format);
+ };
+ }
+
+}
diff --git a/src/main/java/xueli/daw/driver/BufferState.java b/src/main/java/xueli/daw/driver/BufferState.java
new file mode 100644
index 00000000..23a4751e
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/BufferState.java
@@ -0,0 +1,29 @@
+package xueli.daw.driver;
+
+import org.lwjgl.openal.AL11;
+
+public enum BufferState {
+
+ // For now it is the same as OpenAL because LovelyZeeiam doesn't know much about other format!
+ UNUSED, PENDING, PROCESSED;
+
+ // Will be moved when make ALDriver to interface!
+ public static int getALFormat(BufferState format) {
+ return switch (format){
+ case UNUSED -> AL11.AL_UNUSED;
+ case PENDING -> AL11.AL_PENDING;
+ case PROCESSED -> AL11.AL_PROCESSED;
+ default -> throw new IllegalArgumentException("Unexpected value: " + format);
+ };
+ }
+
+ public static BufferState getFromAL(int format) {
+ return switch (format) {
+ case AL11.AL_UNUSED -> UNUSED;
+ case AL11.AL_PENDING -> PENDING;
+ case AL11.AL_PROCESSED -> PROCESSED;
+ default -> throw new IllegalArgumentException("Unexpected value: " + format);
+ };
+ }
+
+}
diff --git a/src/main/java/xueli/daw/driver/JavaSoundDriver.java b/src/main/java/xueli/daw/driver/JavaSoundDriver.java
new file mode 100644
index 00000000..c9d2ccb9
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/JavaSoundDriver.java
@@ -0,0 +1,48 @@
+package xueli.daw.driver;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.SourceDataLine;
+
+public class JavaSoundDriver {
+
+// private static final Logger LOGGER = new Logger();
+
+ private final SourceDataLine sourceDataLine;
+ private JavaSoundStream stream;
+
+ public JavaSoundDriver(AudioFormat format) throws LineUnavailableException {
+ this.sourceDataLine = AudioSystem.getSourceDataLine(format);
+ this.sourceDataLine.open();
+
+ }
+
+ public JavaSoundStream start() {
+ if(this.stream != null) return stream;
+
+ this.sourceDataLine.start();
+ return new JavaSoundStream() {
+
+ @Override
+ public void write(byte[] b, int offset, int length) {
+ sourceDataLine.write(b, offset, length);
+ }
+
+ @Override
+ public void close() {
+ sourceDataLine.drain();
+ sourceDataLine.stop();
+
+ stream = null;
+
+ }
+ };
+ }
+
+ public void release() {
+ this.sourceDataLine.close();
+
+ }
+
+}
diff --git a/src/main/java/xueli/daw/driver/JavaSoundOutputStream.java b/src/main/java/xueli/daw/driver/JavaSoundOutputStream.java
new file mode 100644
index 00000000..5057d89c
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/JavaSoundOutputStream.java
@@ -0,0 +1,29 @@
+package xueli.daw.driver;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.sound.sampled.SourceDataLine;
+
+public class JavaSoundOutputStream extends OutputStream {
+
+ private final SourceDataLine dataLine;
+
+ public JavaSoundOutputStream(SourceDataLine dataLine) {
+ this.dataLine = dataLine;
+ }
+
+ private final byte[] buffer = new byte[1];
+
+ @Override
+ public void write(int b) throws IOException {
+ buffer[0] = (byte) b;
+ dataLine.write(buffer, 0, 1);
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ dataLine.write(b, off, len);
+ }
+
+}
diff --git a/src/main/java/xueli/daw/driver/JavaSoundStream.java b/src/main/java/xueli/daw/driver/JavaSoundStream.java
new file mode 100644
index 00000000..c563f000
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/JavaSoundStream.java
@@ -0,0 +1,13 @@
+package xueli.daw.driver;
+
+public interface JavaSoundStream {
+
+ default public void write(byte[] b) {
+ this.write(b, 0, b.length);
+ }
+
+ public void write(byte[] b, int offset, int length);
+
+ public void close();
+
+}
diff --git a/src/main/java/xueli/daw/driver/SourceState.java b/src/main/java/xueli/daw/driver/SourceState.java
new file mode 100644
index 00000000..651fbf26
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/SourceState.java
@@ -0,0 +1,32 @@
+package xueli.daw.driver;
+
+import org.lwjgl.openal.AL11;
+
+public enum SourceState {
+
+ // For now it is the same as OpenAL because LovelyZeeiam doesn't know much about other format!
+ INITIAL, PLAYING, PAUSED, STOPPED;
+
+ // Will be moved when make ALDriver to interface!
+ // Hard coded! wouldn't consider use a data structure to store this? ââ LovelyZeeiam
+ public static int getALState(SourceState state) {
+ return switch (state){
+ case INITIAL -> AL11.AL_INITIAL;
+ case PLAYING -> AL11.AL_PLAYING;
+ case PAUSED -> AL11.AL_PAUSED;
+ case STOPPED -> AL11.AL_STOPPED;
+ default -> throw new IllegalArgumentException("Unexpected value: " + state);
+ };
+ }
+
+ public static SourceState getFromAL(int state) {
+ return switch (state) {
+ case AL11.AL_INITIAL -> INITIAL;
+ case AL11.AL_PLAYING -> PLAYING;
+ case AL11.AL_PAUSED -> PAUSED;
+ case AL11.AL_STOPPED -> STOPPED;
+ default -> throw new IllegalArgumentException("Unexpected value: " + state);
+ };
+ }
+
+}
diff --git a/src/main/java/xueli/daw/driver/SourceType.java b/src/main/java/xueli/daw/driver/SourceType.java
new file mode 100644
index 00000000..88f78d9d
--- /dev/null
+++ b/src/main/java/xueli/daw/driver/SourceType.java
@@ -0,0 +1,21 @@
+package xueli.daw.driver;
+
+import org.lwjgl.openal.AL11;
+
+public enum SourceType {
+
+ // For now it is the same as OpenAL because LovelyZeeiam doesn't know much about other format!
+ UNDETERMINED, STATIC, STREAMING;
+
+ // Will be moved when make ALDriver to interface!
+ // Hard coded! wouldn't consider use a data structure to store this? ââ LovelyZeeiam
+ public static SourceType getFromAL(int state) {
+ return switch (state) {
+ case AL11.AL_UNDETERMINED -> UNDETERMINED;
+ case AL11.AL_STATIC -> STATIC;
+ case AL11.AL_STREAMING -> STREAMING;
+ default -> throw new IllegalArgumentException("Unexpected value: " + state);
+ };
+ }
+
+}
diff --git a/src/main/java/xueli/daw/package-info.java b/src/main/java/xueli/daw/package-info.java
new file mode 100644
index 00000000..a32d682c
--- /dev/null
+++ b/src/main/java/xueli/daw/package-info.java
@@ -0,0 +1,10 @@
+/**
+ *
This is a little DAW where several generator channels can be added.
+ *
+ *
Each channel has a chain. The beginning item in the chain received MIDI signal, acting as the beginning generator, and the last one should yield sound signal, which is actually byte buffer managed in the context.
+ *
+ * This is a failed test.
+ *
+ */
+@java.lang.Deprecated
+package xueli.daw;
\ No newline at end of file
diff --git a/src/main/java/xueli/daw/synthesizer/SineWaveSynthesizer.java b/src/main/java/xueli/daw/synthesizer/SineWaveSynthesizer.java
new file mode 100644
index 00000000..89fa5036
--- /dev/null
+++ b/src/main/java/xueli/daw/synthesizer/SineWaveSynthesizer.java
@@ -0,0 +1,19 @@
+package xueli.daw.synthesizer;
+
+import xueli.daw.DawContext;
+import xueli.daw.Generator;
+
+public class SineWaveSynthesizer implements Generator {
+
+ public SineWaveSynthesizer() {
+ }
+
+ @Override
+ public void progress(int[] dest, double time, DawContext context) {
+ for(int i = 0; i < dest.length; i++) {
+ dest[i] = (int) (Integer.MAX_VALUE * SynthesizerUtils.sine(440.0, time + i * DawContext.BUFFER_AHEAD_TIME / dest.length));
+ }
+
+ }
+
+}
diff --git a/src/main/java/xueli/daw/synthesizer/SynthesizerUtils.java b/src/main/java/xueli/daw/synthesizer/SynthesizerUtils.java
new file mode 100644
index 00000000..91d47127
--- /dev/null
+++ b/src/main/java/xueli/daw/synthesizer/SynthesizerUtils.java
@@ -0,0 +1,17 @@
+package xueli.daw.synthesizer;
+
+public class SynthesizerUtils {
+
+ public static double sine(double freq, double time) {
+ return Math.sin(2.0*Math.PI*freq*time);
+ }
+
+ public static double sawtooth(double freq, double time) {
+ return 2.0*(freq*time - Math.floor(freq*time + 0.5));
+ }
+
+ public static double triangle(double freq, double time) {
+ return 2.0*Math.abs(sawtooth(freq, time))-1.0;
+ }
+
+}
diff --git a/src/main/java/xueli/game/Game.java b/src/main/java/xueli/game/Game.java
new file mode 100644
index 00000000..8d19b5e8
--- /dev/null
+++ b/src/main/java/xueli/game/Game.java
@@ -0,0 +1,120 @@
+package xueli.game;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+import org.lwjgl.opengl.GL11;
+
+import xueli.game.renderer.RendererManager;
+import xueli.game2.display.Display;
+import xueli.utils.exception.CrashReport;
+
+@Deprecated
+public abstract class Game implements Runnable {
+
+ public static Game INSTANCE_GAME;
+ public static final String DEFAULT_RES_DIRECTORY_STRING = "./res/";
+ public static final String DEFAULT_WORKING_DIRECTORY_STRING = "./.cg/";
+
+ private final Display display;
+
+ private final Queue queueInMainThread = new LinkedList<>();
+
+ protected RendererManager rendererManager;
+
+ public Game(int width, int height, String windowTitle) {
+ INSTANCE_GAME = this;
+
+ this.display = new Display(width, height, windowTitle);
+
+ }
+
+ @Override
+ public void run() {
+ display.create();
+ rendererManager = new RendererManager();
+
+ onCreate();
+ display.show();
+
+ onSize((int) getWidth(), (int) getHeight());
+
+ while (display.isRunning()) {
+ onTick();
+ rendererManager.render();
+// GLHelper.checkGLError("[Renderer]");
+ display.update();
+
+// Logger.getInstance().pushState("MainThreadQueue");
+ if (!queueInMainThread.isEmpty()) {
+ queueInMainThread.poll().run();
+ }
+// Logger.getInstance().popState();
+
+ }
+
+ // display.hide();
+ display.release();
+
+ rendererManager.release();
+ onRelease();
+
+ }
+
+ public abstract void onCreate();
+
+ public abstract void onTick();
+
+ protected void defaultViewport() {
+ GL11.glViewport(0, 0, display.getWidth(), display.getHeight());
+
+ }
+
+ public void onSize(int width, int height) {
+ defaultViewport();
+ rendererManager.size(width, height);
+
+ }
+
+ public abstract void onRelease();
+
+ public void announceCrash(String state, Throwable throwable) {
+ queueInMainThread.add(() -> {
+ display.release();
+ new CrashReport(state, throwable).showCrashReport();
+ });
+ }
+
+ public Display getDisplay() {
+ return display;
+ }
+
+ public float getWidth() {
+ return display.getWidth();
+ }
+
+ public float getHeight() {
+ return display.getHeight();
+ }
+
+ public float getDisplayScale() {
+ return display.getDisplayScale();
+ }
+
+ public float getCursorX() {
+ return display.getCursorX();
+ }
+
+ public float getCursorY() {
+ return display.getCursorY();
+ }
+
+ public RendererManager getRendererManager() {
+ return rendererManager;
+ }
+
+ public void addTaskForMainThread(Runnable run) {
+ this.queueInMainThread.add(run);
+ }
+
+}
diff --git a/src/main/java/xueli/game/package-info.java b/src/main/java/xueli/game/package-info.java
new file mode 100644
index 00000000..7bb0e72e
--- /dev/null
+++ b/src/main/java/xueli/game/package-info.java
@@ -0,0 +1,2 @@
+@Deprecated
+package xueli.game;
\ No newline at end of file
diff --git a/src/main/java/xueli/game/renderer/Renderer.java b/src/main/java/xueli/game/renderer/Renderer.java
new file mode 100644
index 00000000..efc46549
--- /dev/null
+++ b/src/main/java/xueli/game/renderer/Renderer.java
@@ -0,0 +1,14 @@
+package xueli.game.renderer;
+
+@Deprecated
+public interface Renderer {
+
+ public void render();
+
+ public void update();
+
+ public void size();
+
+ public void release();
+
+}
diff --git a/src/main/java/xueli/game/renderer/RendererManager.java b/src/main/java/xueli/game/renderer/RendererManager.java
new file mode 100644
index 00000000..8cc1221d
--- /dev/null
+++ b/src/main/java/xueli/game/renderer/RendererManager.java
@@ -0,0 +1,51 @@
+package xueli.game.renderer;
+
+import xueli.game.Game;
+import xueli.utils.logger.Logger;
+
+@Deprecated
+public class RendererManager {
+
+ private Renderer current;
+
+ public RendererManager() {
+
+ }
+
+ public void setCurrentRenderer(Renderer renderer) {
+ Game.INSTANCE_GAME.addTaskForMainThread(() -> {
+// Logger.getInstance().pushState("Renderer");
+ if (this.current != null) {
+ this.current.release();
+ }
+ this.current = renderer;
+ this.current.size();
+ Logger.getInstance().info("Change renderer: " + renderer.getClass().getName());
+// Logger.getInstance().popState();
+ });
+
+ }
+
+ public void render() {
+ if (this.current != null) {
+ this.current.update();
+ this.current.render();
+ }
+
+ }
+
+ public void size(int w, int h) {
+ if (this.current != null) {
+ this.current.size();
+ }
+
+ }
+
+ public void release() {
+ if (this.current != null) {
+ this.current.release();
+ }
+
+ }
+
+}
diff --git a/src/main/java/xueli/game/renderer/ScreenQuadRenderer.java b/src/main/java/xueli/game/renderer/ScreenQuadRenderer.java
new file mode 100644
index 00000000..51a08a82
--- /dev/null
+++ b/src/main/java/xueli/game/renderer/ScreenQuadRenderer.java
@@ -0,0 +1,107 @@
+package xueli.game.renderer;
+
+// TODO: seems that a new one is needed!
+@Deprecated
+public class ScreenQuadRenderer {
+
+// private static final float[] VERTICES = new float[] { -1, -1, 0, 0, -1, 1, 0, 1, 1, 1, 1, 1, 1, -1, 1, 0 };
+//
+// private ScreenQuadPointer pointer;
+// private Shader shader;
+//
+// public ScreenQuadRenderer() {
+// pointer = new ScreenQuadPointer();
+//
+// pointer.bind();
+// pointer.mapBuffer().asFloatBuffer().put(VERTICES);
+// pointer.unmap();
+// pointer.unbind();
+//
+// try {
+// // TODO
+// shader = Shader.compile(
+// new String(Files.readResourcePackedInJar("/assets/craftgame/shaders/screen_quad/vert.txt"),
+// StandardCharsets.UTF_8),
+// new String(Files.readResourcePackedInJar("/assets/craftgame/shaders/screen_quad/frag.txt"),
+// StandardCharsets.UTF_8));
+// } catch (IOException e) {
+// e.printStackTrace();
+// System.exit(-1);
+// }
+// // shader = new Shader("res/shaders/screen_quad/vert.txt",
+// // "res/shaders/screen_quad/frag.txt");
+//
+// shader.bind();
+// shader.setInt(shader.getUnifromLocation("tex"), 0);
+// shader.setInt(shader.getUnifromLocation("depth"), 1);
+// shader.unbind();
+//
+// }
+//
+// public ScreenQuadRenderer(Shader shader) {
+// pointer = new ScreenQuadPointer();
+//
+// pointer.bind();
+// pointer.mapBuffer().asFloatBuffer().put(VERTICES);
+// pointer.unmap();
+// pointer.unbind();
+//
+// this.shader = shader;
+//
+// }
+//
+// public void render(int textureId) {
+// shader.bind();
+// pointer.bind();
+// GL30.glBindTexture(GL30.GL_TEXTURE_2D, textureId);
+// pointer.draw(GL30.GL_TRIANGLE_FAN, 0, 4);
+// pointer.unbind();
+// shader.unbind();
+//
+// }
+//
+// public void render(int textureId, int depthTexID) {
+// shader.bind();
+// pointer.bind();
+//
+// GL30.glActiveTexture(GL30.GL_TEXTURE0);
+// GL30.glBindTexture(GL30.GL_TEXTURE_2D, textureId);
+// GL30.glActiveTexture(GL30.GL_TEXTURE1);
+// GL30.glBindTexture(GL30.GL_TEXTURE_2D, depthTexID);
+//
+// pointer.draw(GL30.GL_TRIANGLE_FAN, 0, 4);
+// pointer.unbind();
+// shader.unbind();
+//
+// }
+//
+// public ScreenQuadPointer getPointer() {
+// return pointer;
+// }
+//
+// public Shader getShader() {
+// return shader;
+// }
+//
+// public static class ScreenQuadPointer extends DefaultRenderBuffer.DefaultVertexPointer {
+//
+// public ScreenQuadPointer() {
+// super(1024, GL30.GL_STATIC_DRAW);
+//
+// }
+//
+// @Override
+// protected void registerVertex() {
+// // UV
+// GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 4 * 4, 2 * 4);
+// GL20.glEnableVertexAttribArray(1);
+//
+// // position
+// GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 4 * 4, 0 * 4);
+// GL20.glEnableVertexAttribArray(0);
+//
+// }
+//
+// }
+
+}
diff --git a/src/main/java/xueli/game/renderer/package-info.java b/src/main/java/xueli/game/renderer/package-info.java
new file mode 100644
index 00000000..ee162973
--- /dev/null
+++ b/src/main/java/xueli/game/renderer/package-info.java
@@ -0,0 +1,2 @@
+@Deprecated
+package xueli.game.renderer;
\ No newline at end of file
diff --git a/src/main/java/xueli/game/resource/ImageResourceManager.java b/src/main/java/xueli/game/resource/ImageResourceManager.java
new file mode 100644
index 00000000..67f22dd2
--- /dev/null
+++ b/src/main/java/xueli/game/resource/ImageResourceManager.java
@@ -0,0 +1,54 @@
+package xueli.game.resource;
+
+import static org.lwjgl.nanovg.NanoVG.NVG_IMAGE_NEAREST;
+import static org.lwjgl.nanovg.NanoVG.nvgCreateImageMem;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import xueli.utils.io.Files;
+
+public class ImageResourceManager extends ResourceManager
+ implements ResourceLoader, MissingProvider {
+
+ private long currentNvg = 0;
+ private int imageLoadingFlag = NVG_IMAGE_NEAREST;
+
+ ImageResourceManager(ResourceMaster master) {
+ super(master);
+ setLoader(this);
+ setMissingProvider(this);
+
+ }
+
+ public ImageResourceManager setCurrentNvg(long currentNvg) {
+ this.currentNvg = currentNvg;
+ return this;
+ }
+
+ public ImageResourceManager setImageLoadingFlag(int imageLoadingFlag) {
+ this.imageLoadingFlag = imageLoadingFlag;
+ return this;
+ }
+
+ @Override
+ public NVGImage load(ResourceHolder holder) throws Exception {
+ ByteBuffer buffer = null;
+ int imageId = -1;
+ String virtualPath = holder.virtualPath;
+ try {
+ buffer = Files.readResourcePackedInJarAndPackedToBuffer(virtualPath);
+ imageId = nvgCreateImageMem(currentNvg, imageLoadingFlag, buffer);
+ } catch (IOException e) {
+ throw new Exception("Couldn't load image: " + virtualPath, e);
+ }
+ // System.out.println(imageId);
+ return new NVGImage(currentNvg, imageId);
+ }
+
+ @Override
+ public void onMissing(ResourceHolder holder) {
+ holder.result = TextureMissing.getMissingNvgImage(currentNvg);
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/MissingProvider.java b/src/main/java/xueli/game/resource/MissingProvider.java
new file mode 100644
index 00000000..bcdcc99d
--- /dev/null
+++ b/src/main/java/xueli/game/resource/MissingProvider.java
@@ -0,0 +1,7 @@
+package xueli.game.resource;
+
+public interface MissingProvider {
+
+ public void onMissing(ResourceHolder holder);
+
+}
diff --git a/src/main/java/xueli/game/resource/NVGImage.java b/src/main/java/xueli/game/resource/NVGImage.java
new file mode 100644
index 00000000..6e79fb26
--- /dev/null
+++ b/src/main/java/xueli/game/resource/NVGImage.java
@@ -0,0 +1,4 @@
+package xueli.game.resource;
+
+public record NVGImage(long nvg, int image) {
+}
diff --git a/src/main/java/xueli/game/resource/ResourceHolder.java b/src/main/java/xueli/game/resource/ResourceHolder.java
new file mode 100644
index 00000000..00d85ae3
--- /dev/null
+++ b/src/main/java/xueli/game/resource/ResourceHolder.java
@@ -0,0 +1,43 @@
+package xueli.game.resource;
+
+public class ResourceHolder {
+
+ private ResourceManager manager;
+ String namespace;
+ String virtualPath;
+
+ private boolean preloaded = false;
+ T result;
+
+ ResourceHolder(ResourceManager manager) {
+ this.manager = manager;
+ }
+
+ ResourceHolder(ResourceManager manager, String namespace, String virtualPath) {
+ this.virtualPath = virtualPath;
+ this.namespace = namespace;
+ this.manager = manager;
+
+ }
+
+ public void preload() throws Exception {
+ preloaded = true;
+ result = manager.getLoader().load(this);
+ }
+
+ public T getResult() {
+ if (!preloaded) {
+ try {
+ preload();
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ return null;
+ }
+ }
+ return result;
+ }
+
+ public void release() {
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/ResourceLoader.java b/src/main/java/xueli/game/resource/ResourceLoader.java
new file mode 100644
index 00000000..530d1438
--- /dev/null
+++ b/src/main/java/xueli/game/resource/ResourceLoader.java
@@ -0,0 +1,7 @@
+package xueli.game.resource;
+
+public interface ResourceLoader {
+
+ public T load(ResourceHolder holder) throws Exception;
+
+}
diff --git a/src/main/java/xueli/game/resource/ResourceManager.java b/src/main/java/xueli/game/resource/ResourceManager.java
new file mode 100644
index 00000000..5df676c8
--- /dev/null
+++ b/src/main/java/xueli/game/resource/ResourceManager.java
@@ -0,0 +1,66 @@
+package xueli.game.resource;
+
+import java.util.HashMap;
+
+public class ResourceManager {
+
+ protected ResourceMaster master;
+ protected HashMap> holderMap = new HashMap<>();
+ protected ResourceLoader loader;
+
+ private MissingProvider missingProvider = new MissingProvider() {
+ @Override
+ public void onMissing(ResourceHolder holder) {
+ holder.result = null;
+ }
+ };
+
+ public ResourceManager(ResourceLoader loader, ResourceMaster master) {
+ this.loader = loader;
+ this.master = master;
+
+ }
+
+ ResourceManager(ResourceMaster master) {
+ this.master = master;
+
+ }
+
+ public ResourceHolder addToken(String namespace, String virtualPath) {
+ ResourceHolder holder = holderMap.get(namespace);
+ if (holder == null) {
+ holder = new ResourceHolder(this, namespace, virtualPath);
+ holderMap.put(namespace, holder);
+ }
+ return holder;
+ }
+
+ public void removeToken(String namespace) {
+ holderMap.remove(namespace);
+ }
+
+ public void preload() throws Exception {
+ for (ResourceHolder value : holderMap.values()) {
+ value.preload();
+ }
+ }
+
+ public ResourceLoader getLoader() {
+ return loader;
+ }
+
+ public ResourceManager setLoader(ResourceLoader loader) {
+ this.loader = loader;
+ return this;
+ }
+
+ public MissingProvider getMissingProvider() {
+ return missingProvider;
+ }
+
+ public ResourceManager setMissingProvider(MissingProvider missingProvider) {
+ this.missingProvider = missingProvider;
+ return this;
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/ResourceMaster.java b/src/main/java/xueli/game/resource/ResourceMaster.java
new file mode 100644
index 00000000..38b9c08b
--- /dev/null
+++ b/src/main/java/xueli/game/resource/ResourceMaster.java
@@ -0,0 +1,51 @@
+package xueli.game.resource;
+
+import java.util.ArrayList;
+
+import xueli.game2.resource.provider.ClassLoaderResourceProvider;
+import xueli.game2.resource.provider.ResourceProvider;
+
+public class ResourceMaster {
+
+ private ResourceProvider provider = new ClassLoaderResourceProvider();
+
+ private ArrayList> allManager = new ArrayList<>();
+ private ImageResourceManager imageResourceManager;
+ private TextureResourceManager textureResourceManager;
+
+ public ResourceMaster() {
+ imageResourceManager = new ImageResourceManager(this);
+ textureResourceManager = new TextureResourceManager(this);
+
+ this.allManager.add(imageResourceManager);
+ this.allManager.add(textureResourceManager);
+
+ }
+
+ public ResourceMaster(ResourceProvider provider) {
+ this.provider = provider;
+ }
+
+ public void preload() throws Exception {
+ for (ResourceManager> manager : allManager) {
+ manager.preload();
+ }
+ }
+
+ public ResourceProvider getProvider() {
+ return provider;
+ }
+
+ public ImageResourceManager getImageResourceManager() {
+ return imageResourceManager;
+ }
+
+ public TextureResourceManager getTextureResourceManager() {
+ return textureResourceManager;
+ }
+
+ public void release() {
+
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/TextureAtlasManager.java b/src/main/java/xueli/game/resource/TextureAtlasManager.java
new file mode 100644
index 00000000..e4650d69
--- /dev/null
+++ b/src/main/java/xueli/game/resource/TextureAtlasManager.java
@@ -0,0 +1,59 @@
+package xueli.game.resource;
+
+import java.util.HashMap;
+
+import xueli.game.resource.texture.TextureAtlas;
+import xueli.game.resource.texture.TextureAtlasBuilder;
+import xueli.game.resource.texture.TextureAtlasHolder;
+
+class TextureAtlasManager extends ResourceManager {
+
+ private final HashMap builders = new HashMap<>();
+ private final HashMap atlases = new HashMap<>();
+
+ private HashMap namespaceToHolder = new HashMap<>();
+
+ TextureAtlasManager(ResourceMaster master) {
+ super(master);
+
+ }
+
+ @Override
+ public ResourceHolder addToken(String namespace, String virtualPath) {
+ throw new UnsupportedOperationException("");
+ }
+
+ public void addBuiltList(String namespace, TextureAtlasBuilder builder) {
+ builders.put(namespace, builder);
+ // System.out.println(namespace);
+
+ builder.getTextureMaps().keySet().forEach(n -> {
+ TextureAtlasHolder holder = new TextureAtlasHolder(n);
+ namespaceToHolder.put(n, holder);
+ });
+
+ }
+
+ @Override
+ public void preload() throws Exception {
+ // System.out.println(builders.size());
+ builders.forEach((n, builder) -> {
+ TextureAtlas atlas = TextureAtlas.generateAtlas(builder);
+ atlases.put(n, atlas);
+ // System.out.println(atlas + ", " + builder.getTextureMaps().keySet().size());
+ builder.getTextureMaps().keySet().forEach(namespace -> {
+ TextureAtlasHolder holder = namespaceToHolder.get(namespace);
+ holder.loadResult(atlas);
+ });
+ });
+ }
+
+ public TextureAtlasHolder getHolder(String namespace) {
+ return namespaceToHolder.get(namespace);
+ }
+
+ public TextureAtlas getAtlas(String namespace) {
+ return atlases.get(namespace);
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/TextureMissing.java b/src/main/java/xueli/game/resource/TextureMissing.java
new file mode 100644
index 00000000..4634d4e4
--- /dev/null
+++ b/src/main/java/xueli/game/resource/TextureMissing.java
@@ -0,0 +1,71 @@
+package xueli.game.resource;
+
+import static org.lwjgl.nanovg.NanoVG.NVG_IMAGE_NEAREST;
+import static org.lwjgl.nanovg.NanoVG.nvgCreateImageMem;
+
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+
+import javax.imageio.ImageIO;
+
+import org.lwjgl.BufferUtils;
+
+import xueli.game.resource.texture.TextureAtlas;
+import xueli.game.resource.texture.TextureAtlasHolder;
+
+public class TextureMissing {
+
+ private static BufferedImage IMAGE_MISSING = new BufferedImage(16, 16, BufferedImage.TYPE_4BYTE_ABGR);
+ private static ByteBuffer imageData;
+ static {
+ for (int k = 0; k < 16; ++k) {
+ for (int l = 0; l < 16; ++l) {
+ if (k < 8 ^ l < 8) {
+ IMAGE_MISSING.setRGB(l, k, -524040);
+ } else {
+ IMAGE_MISSING.setRGB(l, k, -16777216);
+ }
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ ImageIO.write(IMAGE_MISSING, "png", out);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ imageData = BufferUtils.createByteBuffer(out.size());
+ imageData.put(out.toByteArray());
+ imageData.flip();
+
+ }
+
+ private static HashMap missingImageMap = new HashMap<>();
+
+ public static NVGImage getMissingNvgImage(long nvg) {
+ NVGImage image = missingImageMap.get(nvg);
+ if (image == null) {
+ int imageId = nvgCreateImageMem(nvg, NVG_IMAGE_NEAREST, imageData);
+ image = new NVGImage(nvg, imageId);
+ missingImageMap.put(nvg, image);
+ }
+
+ return image;
+ }
+
+ private static TextureAtlas missingTextureAtlas;
+ private static TextureAtlasHolder missingTextureHolder;
+
+ public static TextureAtlasHolder getMissingTexture() {
+ if (missingTextureAtlas == null) {
+ missingTextureAtlas = TextureAtlas.single(IMAGE_MISSING);
+ missingTextureHolder = missingTextureAtlas.getHolder(TextureAtlas.SINGLE);
+ }
+
+ return missingTextureHolder;
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/TextureResourceManager.java b/src/main/java/xueli/game/resource/TextureResourceManager.java
new file mode 100644
index 00000000..e1e2a34b
--- /dev/null
+++ b/src/main/java/xueli/game/resource/TextureResourceManager.java
@@ -0,0 +1,68 @@
+package xueli.game.resource;
+
+import xueli.game.resource.texture.TextureAtlas;
+import xueli.game.resource.texture.TextureAtlasBuilder;
+import xueli.game.resource.texture.TextureAtlasHolder;
+
+public class TextureResourceManager extends ResourceManager
+ implements ResourceLoader, MissingProvider {
+
+ private TextureAtlasManager atlasManager;
+ private boolean textureAtlasPreloaded = false;
+
+ TextureResourceManager(ResourceMaster master) {
+ super(master);
+ setLoader(this);
+ setMissingProvider(this);
+
+ atlasManager = new TextureAtlasManager(master);
+
+ }
+
+ @Override
+ public ResourceHolder addToken(String namespace, String virtualPath) {
+ throw new UnsupportedOperationException("");
+ }
+
+ public TextureAtlasHolder addToken(String namespace) {
+ TextureAtlasHolder holder = atlasManager.getHolder(namespace);
+ holderMap.put(namespace, new ResourceHolder<>(null, namespace, null));
+ if (holder == null) {
+ System.err.println("Can't find holder: " + namespace);
+ }
+ return holder;
+ }
+
+ public void build(String namespace, TextureAtlasBuilder builder) {
+ atlasManager.addBuiltList(namespace, builder);
+ }
+
+ @Override
+ public TextureAtlasHolder load(ResourceHolder holder) throws Exception {
+ checkAtlasManagerPreloaded();
+ return atlasManager.getHolder(holder.namespace);
+ }
+
+ @Override
+ public void preload() throws Exception {
+ checkAtlasManagerPreloaded();
+ }
+
+ private void checkAtlasManagerPreloaded() throws Exception {
+ if (textureAtlasPreloaded)
+ return;
+ this.atlasManager.preload();
+ // System.out.println("checked");
+ textureAtlasPreloaded = true;
+ }
+
+ @Override
+ public void onMissing(ResourceHolder holder) {
+ holder.result = TextureMissing.getMissingTexture();
+ }
+
+ public TextureAtlas getAtlas(String namespace) {
+ return atlasManager.getAtlas(namespace);
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/package-info.java b/src/main/java/xueli/game/resource/package-info.java
new file mode 100644
index 00000000..0edcef49
--- /dev/null
+++ b/src/main/java/xueli/game/resource/package-info.java
@@ -0,0 +1,2 @@
+@Deprecated
+package xueli.game.resource;
\ No newline at end of file
diff --git a/src/main/java/xueli/game/resource/texture/Texture.java b/src/main/java/xueli/game/resource/texture/Texture.java
new file mode 100644
index 00000000..896c285e
--- /dev/null
+++ b/src/main/java/xueli/game/resource/texture/Texture.java
@@ -0,0 +1,96 @@
+package xueli.game.resource.texture;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.ImageIO;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL12;
+import org.lwjgl.opengl.GL13;
+
+import xueli.utils.logger.Logger;
+
+public class Texture {
+
+ public static final Texture NULL = new Texture(0, 0, 0);
+
+ private int id, width, height;
+
+ public Texture(int id, int imageWidth, int imageHeight) {
+ this.id = id;
+ this.width = imageWidth;
+ this.height = imageHeight;
+
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public void bind() {
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
+ }
+
+ public void unbind() {
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
+ }
+
+ public static Texture loadTexture(InputStream in) throws IOException {
+ BufferedImage image = ImageIO.read(in);
+ if (image == null) {
+ Logger.getInstance().warning("Can't read image file: " + in.toString());
+ return Texture.NULL;
+ }
+
+ return loadTexture(image);
+ }
+
+ public static Texture loadTexture(String path) throws IOException {
+ BufferedImage image = ImageIO.read(new File(path));
+ if (image == null) {
+ Logger.getInstance().warning("Can't read image file: " + path);
+ return Texture.NULL;
+ }
+
+ return loadTexture(image);
+ }
+
+ private static Texture loadTexture(BufferedImage image) {
+ int[] pixels = new int[image.getWidth() * image.getHeight()];
+ image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
+
+ int[] data = new int[image.getWidth() * image.getHeight()];
+ for (int i = 0; i < data.length; i++) {
+ int temp=pixels[i];
+ temp&=0xFF00FF00;
+ temp|=(data[i]&0xFF)<<16;
+ temp|=(data[i]>>16)&0xFF;
+ data[i]=temp;
+ }
+
+ int id = GL11.glGenTextures();
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_BASE_LEVEL, 0);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 4);
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA,
+ GL11.GL_UNSIGNED_BYTE, data);
+
+ return new Texture(id, image.getWidth(), image.getHeight());
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/texture/TextureAtlas.java b/src/main/java/xueli/game/resource/texture/TextureAtlas.java
new file mode 100644
index 00000000..5213a9d1
--- /dev/null
+++ b/src/main/java/xueli/game/resource/texture/TextureAtlas.java
@@ -0,0 +1,280 @@
+package xueli.game.resource.texture;
+
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map.Entry;
+
+import javax.imageio.ImageIO;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL12;
+import org.lwjgl.opengl.GL13;
+import org.lwjgl.utils.vector.Vector2i;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonIOException;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.stream.JsonReader;
+
+import xueli.utils.logger.Logger;
+
+public class TextureAtlas {
+
+ public static final String SINGLE = "S";
+
+ private int width = 0, height = 0;
+ private int id;
+ private HashMap atlas;
+
+ TextureAtlas(HashMap atlas, int width, int height, int id) {
+ this.id = id;
+ this.width = width;
+ this.height = height;
+ this.atlas = atlas;
+
+ }
+
+ public void bind() {
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
+ }
+
+ public void unbind() {
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
+ }
+
+ public void release() {
+ GL11.glDeleteTextures(id);
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public Vector2i getAtlas(String key) {
+ return atlas.get(key);
+ }
+
+ public TextureAtlasHolder getHolder(String namespace) {
+ TextureAtlasHolder holder = new TextureAtlasHolder(namespace);
+ holder.loadResult(this);
+ return holder;
+ }
+
+ public static TextureAtlas single(BufferedImage image) {
+ int width = image.getWidth();
+ int height = image.getHeight();
+
+ int[] pixels = new int[width * height];
+ image.getRGB(0, 0, width, height, pixels, 0, width);
+
+ int[] data = new int[width * height];
+ for (int i = 0; i < width * height; i++) {
+ int a = (pixels[i] & 0xff000000) >> 24;
+ int r = (pixels[i] & 0xff0000) >> 16;
+ int g = (pixels[i] & 0xff00) >> 8;
+ int b = (pixels[i] & 0xff);
+ data[i] = a << 24 | b << 16 | g << 8 | r;
+ }
+
+ int id = GL11.glGenTextures();
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_BASE_LEVEL, 0);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 4);
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
+ data);
+
+ HashMap atlas = new HashMap<>();
+ atlas.put(SINGLE, new Vector2i(0, 0));
+
+ return new TextureAtlas(atlas, width, height, id);
+ }
+
+ public static TextureAtlas generateAtlas(TextureAtlasBuilder builder) {
+ HashMap textureMaps = builder.textureMaps;
+
+ String[] names = new String[textureMaps.size()];
+ BufferedImage[] images = new BufferedImage[textureMaps.size()];
+
+ int per_width = 0, per_height = 0;
+
+ int count = 0;
+ try {
+ for (Entry e : textureMaps.entrySet()) {
+ String name = e.getKey();
+ URL imgUrl = e.getValue();
+ BufferedImage image = ImageIO.read(imgUrl);
+ if (image == null) {
+ Logger.getInstance().warning("Can't read image: " + imgUrl.toString());
+ continue;
+ }
+ per_width = Math.max(per_width, image.getWidth());
+ per_height = Math.max(per_height, image.getHeight());
+
+ names[count] = name;
+ images[count] = image;
+ count++;
+
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ int size = (int) Math.ceil(Math.sqrt(images.length));
+
+ HashMap atlas = new HashMap<>();
+
+ BufferedImage atlasImage = new BufferedImage(per_width * size, per_height * size,
+ BufferedImage.TYPE_4BYTE_ABGR);
+ Graphics2D g2d = atlasImage.createGraphics();
+
+ for (int i = 0; i < images.length; i++) {
+ BufferedImage image = images[i];
+
+ int x = i % size;
+ int y = i / size;
+ atlas.put(names[i], new Vector2i(x, y));
+
+ g2d.drawImage(image, x * per_width, y * per_height, null);
+
+ }
+
+ g2d.dispose();
+ /*
+ * try { ImageIO.write(atlasImage, "png", new File("temp/atlas.png")); } catch
+ * (IOException e) { e.printStackTrace(); }
+ */
+
+ int[] pixels = new int[atlasImage.getWidth() * atlasImage.getHeight()];
+ atlasImage.getRGB(0, 0, atlasImage.getWidth(), atlasImage.getHeight(), pixels, 0, atlasImage.getWidth());
+
+ int[] data = new int[atlasImage.getWidth() * atlasImage.getHeight()];
+ for (int i = 0; i < atlasImage.getWidth() * atlasImage.getHeight(); i++) {
+ int a = (pixels[i] & 0xff000000) >> 24;
+ int r = (pixels[i] & 0xff0000) >> 16;
+ int g = (pixels[i] & 0xff00) >> 8;
+ int b = (pixels[i] & 0xff);
+ data[i] = a << 24 | b << 16 | g << 8 | r;
+ }
+
+ int id = GL11.glGenTextures();
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_BASE_LEVEL, 0);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 4);
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, atlasImage.getWidth(), atlasImage.getHeight(), 0,
+ GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data);
+
+ return new TextureAtlas(atlas, size, size, id);
+ }
+
+ public static TextureAtlas generateAtlas(String defineJsonPath, String textureFolderString) {
+ JsonObject obj = null;
+ try {
+ obj = new Gson().fromJson(new JsonReader(new BufferedReader(new FileReader(defineJsonPath))),
+ JsonObject.class);
+ } catch (JsonIOException | JsonSyntaxException | FileNotFoundException e1) {
+ e1.printStackTrace();
+ }
+ JsonObject blocksObj = obj.get("blocks").getAsJsonObject();
+
+ String[] names = new String[blocksObj.entrySet().size()];
+ BufferedImage[] images = new BufferedImage[blocksObj.entrySet().size()];
+
+ int per_width = 0, per_height = 0;
+
+ int count = 0;
+ try {
+ for (Entry e : blocksObj.entrySet()) {
+ String name = e.getKey();
+ String imgPath = e.getValue().getAsString();
+
+ File imgFile = new File(textureFolderString + File.separator + imgPath);
+ BufferedImage image = ImageIO.read(imgFile);
+ if (image == null) {
+ Logger.getInstance().warning("Can't read image: " + imgPath);
+ continue;
+ }
+ per_width = Math.max(per_width, image.getWidth());
+ per_height = Math.max(per_height, image.getHeight());
+
+ names[count] = name;
+ images[count] = image;
+ count++;
+
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ int size = (int) Math.ceil(Math.sqrt(images.length));
+
+ HashMap atlas = new HashMap<>();
+
+ BufferedImage atlasImage = new BufferedImage(per_width * size, per_height * size,
+ BufferedImage.TYPE_4BYTE_ABGR);
+ Graphics2D g2d = atlasImage.createGraphics();
+
+ for (int i = 0; i < images.length; i++) {
+ BufferedImage image = images[i];
+
+ int x = i % size;
+ int y = i / size;
+ atlas.put(names[i], new Vector2i(x, y));
+
+ g2d.drawImage(image, x * per_width, y * per_height, null);
+
+ }
+
+ g2d.dispose();
+ /*
+ * try { ImageIO.write(atlasImage, "png", new File("temp/atlas.png")); } catch
+ * (IOException e) { e.printStackTrace(); }
+ */
+
+ int[] pixels = new int[atlasImage.getWidth() * atlasImage.getHeight()];
+ atlasImage.getRGB(0, 0, atlasImage.getWidth(), atlasImage.getHeight(), pixels, 0, atlasImage.getWidth());
+
+ int[] data = new int[atlasImage.getWidth() * atlasImage.getHeight()];
+ for (int i = 0; i < atlasImage.getWidth() * atlasImage.getHeight(); i++) {
+ int a = (pixels[i] & 0xff000000) >> 24;
+ int r = (pixels[i] & 0xff0000) >> 16;
+ int g = (pixels[i] & 0xff00) >> 8;
+ int b = (pixels[i] & 0xff);
+ data[i] = a << 24 | b << 16 | g << 8 | r;
+ }
+
+ int id = GL11.glGenTextures();
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_BASE_LEVEL, 0);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 4);
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, atlasImage.getWidth(), atlasImage.getHeight(), 0,
+ GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data);
+
+ return new TextureAtlas(atlas, size, size, id);
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/texture/TextureAtlasBuilder.java b/src/main/java/xueli/game/resource/texture/TextureAtlasBuilder.java
new file mode 100644
index 00000000..7a604402
--- /dev/null
+++ b/src/main/java/xueli/game/resource/texture/TextureAtlasBuilder.java
@@ -0,0 +1,83 @@
+package xueli.game.resource.texture;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+
+import xueli.game2.resource.provider.ResourceProvider;
+import xueli.utils.io.Files;
+
+public class TextureAtlasBuilder {
+
+// private static final MyLogger LOGGER = new MyLogger() {
+// {
+// pushState("TextureAtlasBuilder");
+// }
+// };
+
+ HashMap textureMaps = new HashMap<>();
+
+ public TextureAtlasBuilder() {
+
+ }
+
+ public TextureAtlasBuilder add(String namespace, String virtualPath, ResourceProvider provider) {
+// URL url = provider.virtualPathToUrl(virtualPath);
+// if(url == null) {
+// LOGGER.warning("Can't find virtual path: " + virtualPath);
+// } else {
+// textureMaps.put(namespace, url);
+// }
+
+ return this;
+ }
+
+ public TextureAtlasBuilder add(String namespace, String path) {
+ File file = new File(path);
+ URL url = null;
+ try {
+ url = file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ textureMaps.put(namespace, url);
+ return this;
+ }
+
+ public TextureAtlasBuilder iterate(String virtualPath, ResourceProvider provider, boolean onlyCurrentModule) {
+// String[] virtualPaths = provider.iterateFile(virtualPath, onlyCurrentModule);
+// // System.out.println(Arrays.toString(virtualPaths));
+// for (String path : virtualPaths) {
+// String name = Files.getNameExcludeSuffix(path);
+// this.add(name, path, provider);
+// // System.out.println(name);
+// }
+ return this;
+ }
+
+ public TextureAtlasBuilder iterate(File folder) {
+ File[] files = folder.listFiles(pathname -> pathname.getPath().endsWith(".png"));
+ assert files != null;
+ for (File file : files) {
+ String name = Files.getNameExcludeSuffix(file.getName());
+ this.add(name, file.getPath());
+ }
+
+ return this;
+ }
+
+ public static TextureAtlasBuilder iterateFiles(String virtualPath, ResourceProvider provider,
+ boolean onlyCurrentModule) {
+ return new TextureAtlasBuilder().iterate(virtualPath, provider, onlyCurrentModule);
+ }
+
+ public static TextureAtlasBuilder single(String namespace, String virtualPath, ResourceProvider provider) {
+ return new TextureAtlasBuilder().add(namespace, virtualPath, provider);
+ }
+
+ public HashMap getTextureMaps() {
+ return textureMaps;
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/texture/TextureAtlasHolder.java b/src/main/java/xueli/game/resource/texture/TextureAtlasHolder.java
new file mode 100644
index 00000000..2bb69f1d
--- /dev/null
+++ b/src/main/java/xueli/game/resource/texture/TextureAtlasHolder.java
@@ -0,0 +1,76 @@
+package xueli.game.resource.texture;
+
+import java.util.Objects;
+
+import org.lwjgl.utils.vector.Vector2f;
+import org.lwjgl.utils.vector.Vector2i;
+
+public class TextureAtlasHolder {
+
+ private String name;
+ private Vector2f offsetFrom, offsetTo;
+
+ private boolean hasResult = false;
+ private TextureAtlas atlas;
+ public Vector2f p_left_top, p_left_down, p_right_top, p_right_down;
+ private int atlasWidth, atlasHeight;
+
+ public TextureAtlasHolder(String name) {
+ this(name, new Vector2f(0, 0), new Vector2f(1, 1));
+ }
+
+ public TextureAtlasHolder(String name, Vector2f offsetFrom, Vector2f offsetTo) {
+ this.name = name;
+ this.offsetFrom = offsetFrom;
+ this.offsetTo = offsetTo;
+
+ }
+
+ public void loadResult(TextureAtlas atlas) {
+ this.atlas = atlas;
+
+ Vector2i index = atlas.getAtlas(name);
+ if (index == null) {
+ throw new RuntimeException("Found no atlas named: " + name);
+ }
+
+ this.atlasWidth = atlas.getWidth();
+ this.atlasHeight = atlas.getHeight();
+
+ p_left_top = new Vector2f((float) (index.x + offsetFrom.getX()) / atlasWidth,
+ (float) (index.y + offsetFrom.getY()) / atlasHeight);
+ p_left_down = new Vector2f((float) (index.x + offsetFrom.getX()) / atlasWidth,
+ (float) (index.y + offsetTo.getY()) / atlasHeight);
+ p_right_top = new Vector2f((float) (index.x + offsetTo.getX()) / atlasWidth,
+ (float) (index.y + offsetFrom.getY()) / atlasHeight);
+ p_right_down = new Vector2f((float) (index.x + offsetTo.getX()) / atlasWidth,
+ (float) (index.y + offsetTo.getY()) / atlasHeight);
+
+ this.hasResult = true;
+
+ }
+
+ public TextureAtlas getAtlas() {
+ return atlas;
+ }
+
+ public boolean hasResult() {
+ return hasResult;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ TextureAtlasHolder that = (TextureAtlasHolder) o;
+ return name.equals(that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name);
+ }
+
+}
diff --git a/src/main/java/xueli/game/resource/texture/package-info.java b/src/main/java/xueli/game/resource/texture/package-info.java
new file mode 100644
index 00000000..75861b81
--- /dev/null
+++ b/src/main/java/xueli/game/resource/texture/package-info.java
@@ -0,0 +1,2 @@
+@Deprecated
+package xueli.game.resource.texture;
\ No newline at end of file
diff --git a/src/main/java/xueli/game/ui/FontManager.java b/src/main/java/xueli/game/ui/FontManager.java
new file mode 100644
index 00000000..4ff9a998
--- /dev/null
+++ b/src/main/java/xueli/game/ui/FontManager.java
@@ -0,0 +1,9 @@
+package xueli.game.ui;
+
+public class FontManager {
+
+ public FontManager() {
+
+ }
+
+}
diff --git a/src/main/java/xueli/game/ui/ImageManager.java b/src/main/java/xueli/game/ui/ImageManager.java
new file mode 100644
index 00000000..2aa9e15e
--- /dev/null
+++ b/src/main/java/xueli/game/ui/ImageManager.java
@@ -0,0 +1,49 @@
+package xueli.game.ui;
+
+import static org.lwjgl.nanovg.NanoVG.NVG_IMAGE_NEAREST;
+import static org.lwjgl.nanovg.NanoVG.nvgCreateImageMem;
+import static org.lwjgl.nanovg.NanoVG.nvgDeleteImage;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+
+import xueli.utils.io.Files;
+
+public class ImageManager {
+
+ private UIRenderer renderer;
+ private HashMap imagesHashMap = new HashMap<>();
+
+ public ImageManager(UIRenderer renderer) {
+ this.renderer = renderer;
+
+ }
+
+ public int getImage(String pathInJar) {
+ Integer imageInteger = imagesHashMap.get(pathInJar);
+
+ if (imageInteger == null) {
+ ByteBuffer buffer = null;
+ try {
+ buffer = Files.readResourcePackedInJarAndPackedToBuffer(pathInJar);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return 0;
+ }
+
+ imageInteger = nvgCreateImageMem(renderer.nvg, NVG_IMAGE_NEAREST, buffer);
+ imagesHashMap.put(pathInJar, imageInteger);
+
+ }
+
+ return imageInteger;
+ }
+
+ public void release() {
+ imagesHashMap.values().forEach(i -> {
+ nvgDeleteImage(renderer.nvg, i);
+ });
+ }
+
+}
diff --git a/src/main/java/xueli/game/ui/UI.java b/src/main/java/xueli/game/ui/UI.java
new file mode 100644
index 00000000..94708177
--- /dev/null
+++ b/src/main/java/xueli/game/ui/UI.java
@@ -0,0 +1,35 @@
+package xueli.game.ui;
+
+import static org.lwjgl.nanovg.NanoVG.nvgBeginPath;
+import static org.lwjgl.nanovg.NanoVG.nvgFill;
+import static org.lwjgl.nanovg.NanoVG.nvgFillColor;
+import static org.lwjgl.nanovg.NanoVG.nvgFillPaint;
+import static org.lwjgl.nanovg.NanoVG.nvgImagePattern;
+import static org.lwjgl.nanovg.NanoVG.nvgRect;
+
+import org.lwjgl.nanovg.NVGColor;
+import org.lwjgl.nanovg.NVGPaint;
+
+public class UI {
+
+ private static NVGPaint paint = NVGPaint.create();
+
+ private UI() {
+ }
+
+ public static void drawTexture(long nvg, float x, float y, float width, float height, int image) {
+ nvgImagePattern(nvg, x, y, width, height, 0, image, 1.0f, paint);
+ nvgBeginPath(nvg);
+ nvgRect(nvg, x, y, width, height);
+ nvgFillPaint(nvg, paint);
+ nvgFill(nvg);
+ }
+
+ public static void drawRect(long nvg, float x, float y, float width, float height, NVGColor color) {
+ nvgBeginPath(nvg);
+ nvgRect(nvg, x, y, width, height);
+ nvgFillColor(nvg, color);
+ nvgFill(nvg);
+ }
+
+}
diff --git a/src/main/java/xueli/game/ui/UIRenderer.java b/src/main/java/xueli/game/ui/UIRenderer.java
new file mode 100644
index 00000000..83b6c6ad
--- /dev/null
+++ b/src/main/java/xueli/game/ui/UIRenderer.java
@@ -0,0 +1,94 @@
+package xueli.game.ui;
+
+import static org.lwjgl.nanovg.NanoVG.nvgBeginFrame;
+import static org.lwjgl.nanovg.NanoVG.nvgEndFrame;
+import static org.lwjgl.nanovg.NanoVGGL3.NVG_ANTIALIAS;
+import static org.lwjgl.nanovg.NanoVGGL3.NVG_DEBUG;
+import static org.lwjgl.nanovg.NanoVGGL3.NVG_STENCIL_STROKES;
+import static org.lwjgl.nanovg.NanoVGGL3.nvgCreate;
+
+import java.util.Stack;
+
+import xueli.game.Game;
+import xueli.game.renderer.Renderer;
+
+public class UIRenderer implements Renderer {
+
+ private Game game;
+ long nvg;
+
+ private ImageManager imageManager;
+
+ private Stack views = new Stack<>();
+
+ public UIRenderer(Game game) {
+ this.game = game;
+
+ this.nvg = nvgCreate(NVG_STENCIL_STROKES | NVG_ANTIALIAS | NVG_DEBUG);
+ if (this.nvg == 0) {
+ game.announceCrash("UI Init", new RuntimeException("Couldn't init NanoVG!"));
+ }
+
+ this.imageManager = new ImageManager(this);
+
+ }
+
+ public void pushUIView(UIView view) {
+ views.push(view);
+ }
+
+ public void popUIView() {
+ UIView view = views.pop();
+ if (view != null) {
+ view.release();
+ }
+ }
+
+ @Override
+ public void render() {
+ views.forEach(view -> {
+ view.update();
+ });
+
+ nvgBeginFrame(nvg, game.getWidth(), game.getHeight(), game.getWidth() / game.getHeight());
+ views.forEach(view -> {
+ view.render();
+ });
+ nvgEndFrame(nvg);
+
+ }
+
+ @Override
+ public void update() {
+ }
+
+ @Override
+ public void size() {
+ views.forEach(view -> {
+ view.requestRepaint();
+ });
+ }
+
+ @Override
+ public void release() {
+ views.forEach(view -> {
+ view.release();
+ });
+
+ imageManager.release();
+
+ }
+
+ public Game getGame() {
+ return game;
+ }
+
+ public long getNvg() {
+ return nvg;
+ }
+
+ public ImageManager getImageManager() {
+ return imageManager;
+ }
+
+}
diff --git a/src/main/java/xueli/game/ui/UIView.java b/src/main/java/xueli/game/ui/UIView.java
new file mode 100644
index 00000000..c6aeb174
--- /dev/null
+++ b/src/main/java/xueli/game/ui/UIView.java
@@ -0,0 +1,130 @@
+package xueli.game.ui;
+
+import static org.lwjgl.nanovg.NanoVG.NVG_IMAGE_NEAREST;
+import static org.lwjgl.nanovg.NanoVG.nvgBeginFrame;
+import static org.lwjgl.nanovg.NanoVG.nvgEndFrame;
+import static org.lwjgl.nanovg.NanoVGGL3.nvgluBindFramebuffer;
+import static org.lwjgl.nanovg.NanoVGGL3.nvgluCreateFramebuffer;
+import static org.lwjgl.nanovg.NanoVGGL3.nvgluDeleteFramebuffer;
+
+import java.util.ArrayList;
+
+import org.lwjgl.nanovg.NVGColor;
+import org.lwjgl.nanovg.NVGLUFramebuffer;
+import org.lwjgl.opengl.GL11;
+
+import xueli.game.renderer.Renderer;
+import xueli.game.utils.NVGColors;
+
+public abstract class UIView implements Renderer {
+
+ private UIRenderer ctxRenderer;
+
+ private NVGLUFramebuffer framebuffer;
+ public static final NVGColor ColorFrameBufferNull = NVGColors.DARK_GRAY;
+ private boolean needRepaint = true;
+
+ private float width = 0, height = 0;
+
+ UIView fatherComponent;
+ private ArrayList subCompnents = new ArrayList<>();
+
+ public UIView(UIRenderer ctx) {
+ this.ctxRenderer = ctx;
+
+ }
+
+ @Override
+ public void render() {
+ if (framebuffer != null) {
+ UI.drawTexture(ctxRenderer.nvg, 0, 0, width, height, framebuffer.image());
+ } else {
+ UI.drawRect(ctxRenderer.nvg, 0, 0, width, height, ColorFrameBufferNull);
+ }
+
+ }
+
+ @Override
+ public void update() {
+ subCompnents.forEach(UIView::update);
+
+ if (needRepaint) {
+ size();
+ stroke();
+ needRepaint = false;
+ }
+
+ }
+
+ public abstract void stroke();
+
+ @Override
+ public void size() {
+ this.width = ctxRenderer.getGame().getWidth();
+ this.height = ctxRenderer.getGame().getHeight();
+
+ if (framebuffer != null) {
+ nvgluDeleteFramebuffer(ctxRenderer.nvg, framebuffer);
+ }
+ framebuffer = nvgluCreateFramebuffer(ctxRenderer.nvg, (int) width, (int) height, NVG_IMAGE_NEAREST);
+
+ subCompnents.forEach(UIView::requestRepaint);
+
+ }
+
+ @Override
+ public void release() {
+ if (framebuffer != null) {
+ nvgluDeleteFramebuffer(ctxRenderer.nvg, framebuffer);
+ }
+
+ subCompnents.forEach(UIView::release);
+
+ }
+
+ protected void bindFrameBuffer() {
+ nvgluBindFramebuffer(ctxRenderer.nvg, framebuffer);
+ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
+ nvgBeginFrame(ctxRenderer.nvg, getWidth(), getHeight(), getWidth() / getHeight());
+ }
+
+ protected void unbindFrameBuffer() {
+ nvgEndFrame(ctxRenderer.nvg);
+ nvgluBindFramebuffer(ctxRenderer.nvg, null);
+ }
+
+ public T addView(T view) {
+ subCompnents.add(view);
+ view.fatherComponent = this;
+ return view;
+ }
+
+ public T removeView(T view) {
+ subCompnents.remove(view);
+ return view;
+ }
+
+ public float getWidth() {
+ return width;
+ }
+
+ public float getHeight() {
+ return height;
+ }
+
+ public UIRenderer getCtxRenderer() {
+ return ctxRenderer;
+ }
+
+ public int getImage(String pathInJar) {
+ return ctxRenderer.getImageManager().getImage(pathInJar);
+ }
+
+ public void requestRepaint() {
+ this.needRepaint = true;
+ if (this.fatherComponent != null) {
+ this.fatherComponent.requestRepaint();
+ }
+ }
+
+}
diff --git a/src/main/java/xueli/game/ui/package-info.java b/src/main/java/xueli/game/ui/package-info.java
new file mode 100644
index 00000000..bf14c585
--- /dev/null
+++ b/src/main/java/xueli/game/ui/package-info.java
@@ -0,0 +1,2 @@
+@Deprecated
+package xueli.game.ui;
\ No newline at end of file
diff --git a/src/main/java/xueli/game/utils/FloatList.java b/src/main/java/xueli/game/utils/FloatList.java
new file mode 100644
index 00000000..7ff106a9
--- /dev/null
+++ b/src/main/java/xueli/game/utils/FloatList.java
@@ -0,0 +1,131 @@
+package xueli.game.utils;
+
+import java.nio.FloatBuffer;
+import java.util.Arrays;
+
+import org.lwjgl.utils.vector.Vector2f;
+import org.lwjgl.utils.vector.Vector3f;
+import org.lwjgl.utils.vector.Vector4b;
+import org.lwjgl.utils.vector.Vector4f;
+
+/**
+ * įģčŋæĩč¯īŧæ§čŊæ˛Ąæį´æĨįfloatBufferéĢīŧ äŊæ¯čŋæ¯æēåĨŊį¨į å ä¸ēfloatBuffer大å°åˇ˛įģéåļæģäē
+ * Please use LotsOfByteBuffer instead!
+ */
+@Deprecated
+public class FloatList {
+
+ private float[] data;
+ private int capacity;
+
+ private int pointer;
+ private int size;
+
+ private boolean hasChanged = false;
+ private float[] realDataCache = null;
+
+ public FloatList() {
+ this(32);
+
+ }
+
+ public FloatList(int capacity) {
+ if (capacity <= 0)
+ throw new IllegalArgumentException("Capacity not bigger than zero: " + capacity);
+
+ this.data = new float[capacity];
+ this.pointer = 0;
+ this.size = 0;
+ this.capacity = capacity;
+
+ }
+
+ public void clear() {
+ this.pointer = 0;
+ this.size = 0;
+ this.hasChanged = true;
+
+ }
+
+ public FloatList put(float v) {
+ data[pointer] = v;
+ pointer++;
+ size = Math.max(pointer, size);
+
+ if (pointer == data.length) {
+ this.capacity += 4096;
+ float[] data2 = new float[this.capacity];
+ System.arraycopy(data, 0, data2, 0, data.length);
+ this.data = data2;
+
+ }
+
+ hasChanged = true;
+
+ return this;
+ }
+
+ public FloatList put(Vector4b v) {
+ int bits = (v.x << 24) | (v.y << 16) | (v.z << 8) | v.w;
+ return put(Float.intBitsToFloat(bits));
+ }
+
+ public FloatList put(Vector3f v) {
+ return put(v.x).put(v.y).put(v.z);
+ }
+
+ public FloatList put(Vector2f v) {
+ return put(v.x).put(v.y);
+ }
+
+ public FloatList put(Vector4f v) {
+ return put(v.x).put(v.y).put(v.z).put(v.w);
+ }
+
+ public int getPointer() {
+ return pointer;
+ }
+
+ public void setPointer(int pointer) {
+ if (this.pointer >= this.capacity)
+ throw new IllegalArgumentException("pointer bigger than capacity: " + pointer);
+ this.pointer = pointer;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public float[] getData() {
+ if (realDataCache == null || this.hasChanged) {
+ float[] realData = new float[size];
+ System.arraycopy(data, 0, realData, 0, size);
+ this.realDataCache = realData;
+ hasChanged = false;
+
+ }
+ return this.realDataCache;
+ }
+
+ public float[] getDataPointer() {
+ return data;
+ }
+
+ public void storeInBuffer(FloatBuffer buffer) {
+ if (data == null)
+ return;
+ buffer.put(data, 0, size);
+ }
+
+ public void postDispose() {
+ this.data = null;
+ realDataCache = null;
+
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(getData());
+ }
+
+}
diff --git a/src/main/java/xueli/game/utils/Light.java b/src/main/java/xueli/game/utils/Light.java
new file mode 100644
index 00000000..5bbadfe3
--- /dev/null
+++ b/src/main/java/xueli/game/utils/Light.java
@@ -0,0 +1,54 @@
+package xueli.game.utils;
+
+import org.lwjgl.utils.vector.Vector4b;
+
+public class Light {
+
+ public static final Light FULL_LIGHT = new Light((byte) 15, (byte) 15, (byte) 15, (byte) 15);
+
+ private byte sun, r, g, b;
+
+ public Light(byte sun, byte r, byte g, byte b) {
+ this.sun = sun;
+ this.r = r;
+ this.g = g;
+ this.b = b;
+ }
+
+ public byte getSunLight() {
+ return sun;
+ }
+
+ public void setSunLight(byte sun) {
+ this.sun = sun;
+ }
+
+ public byte getR() {
+ return r;
+ }
+
+ public void setR(byte r) {
+ this.r = r;
+ }
+
+ public byte getG() {
+ return g;
+ }
+
+ public void setG(byte g) {
+ this.g = g;
+ }
+
+ public byte getB() {
+ return b;
+ }
+
+ public void setB(byte b) {
+ this.b = b;
+ }
+
+ public Vector4b getLightBuffer() {
+ return new Vector4b(r, g, b, sun);
+ }
+
+}
diff --git a/src/main/java/xueli/game/utils/NVGColors.java b/src/main/java/xueli/game/utils/NVGColors.java
new file mode 100644
index 00000000..7a5eb353
--- /dev/null
+++ b/src/main/java/xueli/game/utils/NVGColors.java
@@ -0,0 +1,39 @@
+package xueli.game.utils;
+
+import static org.lwjgl.nanovg.NanoVG.nvgRGB;
+import static org.lwjgl.nanovg.NanoVG.nvgRGBA;
+
+import org.lwjgl.nanovg.NVGColor;
+
+@Deprecated
+public class NVGColors {
+
+ public static NVGColor GREEN = NVGColor.create();
+ public static NVGColor BLUE = NVGColor.create();
+ public static NVGColor WHITE = NVGColor.create();
+ public static NVGColor BLACK = NVGColor.create();
+ public static NVGColor YELLOW = NVGColor.create();
+ public static NVGColor PURPLE = NVGColor.create();
+ public static NVGColor DARK_GRAY = NVGColor.create();
+ public static NVGColor TRANSPARENT_BLACK = NVGColor.create();
+
+ static {
+ nvgRGB((byte) 0, (byte) 255, (byte) 0, GREEN);
+ nvgRGB((byte) 0, (byte) 0, (byte) 255, BLUE);
+ nvgRGB((byte) 255, (byte) 255, (byte) 255, WHITE);
+ nvgRGB((byte) 0, (byte) 0, (byte) 0, BLACK);
+ nvgRGB((byte) 255, (byte) 255, (byte) 0, YELLOW);
+ nvgRGB((byte) 128, (byte) 0, (byte) 128, PURPLE);
+ nvgRGB((byte) 60, (byte) 60, (byte) 60, DARK_GRAY);
+ nvgRGBA((byte) 0, (byte) 0, (byte) 0, (byte) 128, TRANSPARENT_BLACK);
+
+ }
+
+ public static NVGColor nvgColor(int c) {
+ NVGColor color = NVGColor.create();
+ nvgRGBA((byte) (c & 0xFF), (byte) ((c >> 8) & 0xFF), (byte) ((c >> 16) & 0xFF), (byte) ((c >> 24) & 0xFF),
+ color);
+ return color;
+ }
+
+}
diff --git a/src/main/java/xueli/game/utils/math/MathUtils.java b/src/main/java/xueli/game/utils/math/MathUtils.java
new file mode 100644
index 00000000..264311ae
--- /dev/null
+++ b/src/main/java/xueli/game/utils/math/MathUtils.java
@@ -0,0 +1,76 @@
+package xueli.game.utils.math;
+
+import java.math.BigDecimal;
+
+@Deprecated
+public class MathUtils {
+
+ public static float doubleToFloat(double value) {
+ if (Double.isNaN(value))
+ return -Float.MAX_VALUE;
+ return new BigDecimal(String.valueOf(value)).floatValue();
+ }
+
+ public static double floatToDouble(float value) {
+ if (Float.isNaN(value))
+ return -Double.MAX_VALUE;
+ return new BigDecimal(String.valueOf(value)).doubleValue();
+ }
+
+ public static int floatToInt(float value) {
+ if (Double.isNaN(value))
+ return -Integer.MAX_VALUE;
+ return (int) Math.floor(value);
+ }
+
+ public static int floatToInt2(float value) {
+ return (int) value;
+ }
+
+ public static long vert2ToLong(int x, int z) {
+ return (long) x & 4294967295L | ((long) z & 4294967295L) << 32;
+ }
+
+ public static float interpolate(float a, float b, float blend) {
+ double theta = blend * Math.PI;
+ float f = (float) (1f - Math.cos(theta)) * 0.5f;
+ return a * (1f - f) + b * f;
+ }
+
+ public static float mixLinear(float a, float b, float blend) {
+ return blend * (b - a) + a;
+ }
+
+ public static double min(double... nums) {
+ double min = nums[0];
+ for (int i = 0; i < nums.length; i++) {
+ min = Math.min(min, nums[i]);
+ }
+ return min;
+ }
+
+ public static int min(int... nums) {
+ int min = nums[0];
+ for (int i = 0; i < nums.length; i++) {
+ min = Math.min(min, nums[i]);
+ }
+ return min;
+ }
+
+ public static double max(double... nums) {
+ double max = nums[0];
+ for (int i = 0; i < nums.length; i++) {
+ max = Math.max(max, nums[i]);
+ }
+ return max;
+ }
+
+ public static int max(int... nums) {
+ int max = nums[0];
+ for (int i = 0; i < nums.length; i++) {
+ max = Math.max(max, nums[i]);
+ }
+ return max;
+ }
+
+}
diff --git a/src/main/java/xueli/game2/Timer.java b/src/main/java/xueli/game2/Timer.java
new file mode 100644
index 00000000..18e96593
--- /dev/null
+++ b/src/main/java/xueli/game2/Timer.java
@@ -0,0 +1,61 @@
+package xueli.game2;
+
+public class Timer {
+
+ private static final int DUE_TICK_PER_SECONDS = 20;
+ private static final double DUE_SECOND_PER_TICK = 1.0 * 1000 / DUE_TICK_PER_SECONDS;
+ private static final int MAX_TICK_PER_INVOKE = 100;
+
+ private long lastTime = 0;
+
+ private int numShouldTick = 0;
+ private int numHasTick = 0;
+
+ private long remain = 0;
+ private float remainProgress = 0;
+
+ public void tick() {
+ if (lastTime == 0) {
+ lastTime = System.currentTimeMillis();
+ return;
+ }
+
+ long thisTime = System.currentTimeMillis();
+ long delta = thisTime - lastTime;
+ remain += delta;
+
+ this.numShouldTick = (int) (this.remain / DUE_SECOND_PER_TICK);
+ this.remain -= this.numShouldTick * DUE_SECOND_PER_TICK;
+ this.remainProgress = (float) (this.remain / DUE_SECOND_PER_TICK);
+
+ int numExceed = this.numShouldTick - MAX_TICK_PER_INVOKE;
+ if (numExceed > 0) {
+ System.out.printf("Can't keep up! Drop %d ticks%n", numExceed);
+ this.numShouldTick = MAX_TICK_PER_INVOKE;
+ }
+
+ lastTime = thisTime;
+
+ }
+
+ @Deprecated
+ public void runTick(Runnable tick) {
+ for (int i = 0; i < numShouldTick; i++) {
+ this.numHasTick++;
+ tick.run();
+ }
+ }
+
+ public float getRemainProgress() {
+ return remainProgress;
+ }
+
+ public int getNumHasTick() {
+ return numHasTick;
+ }
+
+ public int getNumShouldTick() {
+ return numShouldTick;
+ }
+
+}
diff --git a/src/main/java/xueli/game2/Vector.java b/src/main/java/xueli/game2/Vector.java
new file mode 100644
index 00000000..f1a9abfd
--- /dev/null
+++ b/src/main/java/xueli/game2/Vector.java
@@ -0,0 +1,40 @@
+package xueli.game2;
+
+import java.io.Serializable;
+
+public class Vector implements Serializable {
+
+ private static final long serialVersionUID = 1957284979693368762L;
+
+ public double x;
+ public double y;
+ public double z;
+ public double rotX, rotY, rotZ;
+
+ public Vector() {
+ x = y = z = rotX = rotY = rotZ = 0;
+ }
+
+ public Vector(double x, double y, double z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ rotX = rotY = rotZ = 0;
+ }
+
+ public Vector(double x, double y, double z, double rotX, double rotY, double rotZ) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.rotX = rotX;
+ this.rotY = rotY;
+ this.rotZ = rotZ;
+ }
+
+ @Override
+ public String toString() {
+ return "Vector [x=" + x + ", y=" + y + ", z=" + z + ", rotX=" + rotX + ", rotY=" + rotY + ", rotZ=" + rotZ
+ + "]";
+ }
+
+}
diff --git a/src/main/java/xueli/game2/camera3d/BoundCamera.java b/src/main/java/xueli/game2/camera3d/BoundCamera.java
new file mode 100644
index 00000000..5eab52bb
--- /dev/null
+++ b/src/main/java/xueli/game2/camera3d/BoundCamera.java
@@ -0,0 +1,27 @@
+package xueli.game2.camera3d;
+
+import org.lwjgl.utils.vector.Matrix4f;
+
+public class BoundCamera implements ICamera {
+
+ private ICamera camera;
+
+ public BoundCamera(ICamera camera) {
+ this.camera = camera;
+ }
+
+ @Override
+ public Matrix4f getCameraMatrix() {
+ if (camera == null) {
+ Matrix4f matrix = new Matrix4f();
+ matrix.setIdentity();
+ return matrix;
+ }
+ return camera.getCameraMatrix();
+ }
+
+ public void setCamera(ICamera camera) {
+ this.camera = camera;
+ }
+
+}
diff --git a/src/main/java/xueli/game2/camera3d/ICamera.java b/src/main/java/xueli/game2/camera3d/ICamera.java
new file mode 100644
index 00000000..d86ab643
--- /dev/null
+++ b/src/main/java/xueli/game2/camera3d/ICamera.java
@@ -0,0 +1,9 @@
+package xueli.game2.camera3d;
+
+import org.lwjgl.utils.vector.Matrix4f;
+
+public interface ICamera {
+
+ public Matrix4f getCameraMatrix();
+
+}
diff --git a/src/main/java/xueli/game2/camera3d/MovableCamera.java b/src/main/java/xueli/game2/camera3d/MovableCamera.java
new file mode 100644
index 00000000..0fb468eb
--- /dev/null
+++ b/src/main/java/xueli/game2/camera3d/MovableCamera.java
@@ -0,0 +1,45 @@
+package xueli.game2.camera3d;
+
+import org.lwjgl.utils.vector.Matrix4f;
+import org.lwjgl.utils.vector.Vector3f;
+
+import xueli.game2.Vector;
+
+public class MovableCamera extends Vector implements ICamera {
+
+ private static final long serialVersionUID = 5715380559084534935L;
+
+ public MovableCamera() {
+ super();
+ }
+
+ public MovableCamera(float x, float y, float z) {
+ super(x, y, z);
+ }
+
+ public MovableCamera(float x, float y, float z, float rotX, float rotY, float rotZ) {
+ super(x, y, z, rotX, rotY, rotZ);
+ }
+
+ public MovableCamera(Vector other) {
+ this.x = other.x;
+ this.y = other.y;
+ this.z = other.z;
+ this.rotX = other.rotX;
+ this.rotY = other.rotY;
+ this.rotZ = other.rotZ;
+ }
+
+ @Override
+ public Matrix4f getCameraMatrix() {
+ Matrix4f viewMatrix = new Matrix4f();
+ viewMatrix.setIdentity();
+ Matrix4f.rotate((float) Math.toRadians(-this.rotX), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
+ Matrix4f.rotate((float) Math.toRadians(this.rotY), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
+ Matrix4f.rotate((float) Math.toRadians(this.rotZ), new Vector3f(0, 0, 1), viewMatrix, viewMatrix);
+ Vector3f negativeCamPos = new Vector3f((float) -this.x, (float) -this.y, (float) -this.z);
+ Matrix4f.translate(negativeCamPos, viewMatrix, viewMatrix);
+ return viewMatrix;
+ }
+
+}
diff --git a/src/main/java/xueli/game2/display/CursorPositionListener.java b/src/main/java/xueli/game2/display/CursorPositionListener.java
new file mode 100644
index 00000000..42df2b23
--- /dev/null
+++ b/src/main/java/xueli/game2/display/CursorPositionListener.java
@@ -0,0 +1,5 @@
+package xueli.game2.display;
+
+public interface CursorPositionListener {
+ public void onCursorPos(double x, double y);
+}
diff --git a/src/main/java/xueli/game2/display/Display.java b/src/main/java/xueli/game2/display/Display.java
new file mode 100644
index 00000000..dc2c1bd2
--- /dev/null
+++ b/src/main/java/xueli/game2/display/Display.java
@@ -0,0 +1,338 @@
+package xueli.game2.display;
+
+import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
+import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MINOR;
+import static org.lwjgl.glfw.GLFW.GLFW_CURSOR;
+import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED;
+import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_NORMAL;
+import static org.lwjgl.glfw.GLFW.GLFW_FALSE;
+import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_CORE_PROFILE;
+import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_FORWARD_COMPAT;
+import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_PROFILE;
+import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
+import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
+import static org.lwjgl.glfw.GLFW.GLFW_TRUE;
+import static org.lwjgl.glfw.GLFW.GLFW_VISIBLE;
+import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
+import static org.lwjgl.glfw.GLFW.glfwDestroyWindow;
+import static org.lwjgl.glfw.GLFW.glfwGetMouseButton;
+import static org.lwjgl.glfw.GLFW.glfwHideWindow;
+import static org.lwjgl.glfw.GLFW.glfwInit;
+import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
+import static org.lwjgl.glfw.GLFW.glfwPollEvents;
+import static org.lwjgl.glfw.GLFW.glfwSetCursorPosCallback;
+import static org.lwjgl.glfw.GLFW.glfwSetInputMode;
+import static org.lwjgl.glfw.GLFW.glfwSetKeyCallback;
+import static org.lwjgl.glfw.GLFW.glfwSetMouseButtonCallback;
+import static org.lwjgl.glfw.GLFW.glfwSetScrollCallback;
+import static org.lwjgl.glfw.GLFW.glfwSetWindowPos;
+import static org.lwjgl.glfw.GLFW.glfwSetWindowSizeCallback;
+import static org.lwjgl.glfw.GLFW.glfwShowWindow;
+import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
+import static org.lwjgl.glfw.GLFW.glfwSwapInterval;
+import static org.lwjgl.glfw.GLFW.glfwTerminate;
+import static org.lwjgl.glfw.GLFW.glfwWindowHint;
+import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose;
+
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.lwjgl.glfw.GLFWCursorPosCallback;
+import org.lwjgl.glfw.GLFWErrorCallback;
+import org.lwjgl.glfw.GLFWKeyCallback;
+import org.lwjgl.glfw.GLFWMouseButtonCallback;
+import org.lwjgl.glfw.GLFWScrollCallback;
+import org.lwjgl.glfw.GLFWWindowSizeCallback;
+import org.lwjgl.opengl.GL;
+import org.lwjgl.opengl.GL11;
+
+public class Display {
+
+ private long window;
+ private boolean running = false;
+ private final String mainTitle;
+
+ private int width, height;
+ private float displayScale;
+
+ private float cursorX, cursorY;
+ private float cursorDx = 0, cursorDy = 0;
+
+ private double wheelDelta;
+
+ private boolean mouseGrabbed = false;
+
+ private final ArrayList sizeCallbacks = new ArrayList<>();
+ private final GLFWWindowSizeCallback windowSizeCallback = new GLFWWindowSizeCallback() {
+ @Override
+ public void invoke(long window, int w, int h) {
+ if (w != 0 || h != 0) {
+ width = w;
+ height = h;
+ displayScale = getScale(w, h);
+
+ sizeCallbacks.forEach(c -> c.onSize(w, h));
+
+ }
+ }
+ };
+
+ private final ArrayList cursorPosCallbacks = new ArrayList<>();
+ private final GLFWCursorPosCallback cursorPosCallback = new GLFWCursorPosCallback() {
+ @Override
+ public void invoke(long window, double xpos, double ypos) {
+ cursorDx = (float) (xpos - cursorX);
+ cursorDy = (float) (ypos - cursorY);
+
+ cursorX = (float) xpos;
+ cursorY = (float) ypos;
+
+ cursorPosCallbacks.forEach(c -> c.onCursorPos(xpos, ypos));
+
+ }
+ };
+
+ private final boolean[] mouse_buttons = new boolean[8];
+ private final ArrayList mouseCallbacks = new ArrayList<>();
+
+ private final GLFWMouseButtonCallback mouseButtonCallback = new GLFWMouseButtonCallback() {
+ @Override
+ public void invoke(long window, int button, int action, int mods) {
+ if (button >= 0 && action == GLFW_RELEASE) {
+ mouse_buttons[button] = true;
+ }
+ mouseCallbacks.forEach(l -> l.onMouseButton(button, action, mods));
+
+ }
+ };
+
+ private final boolean[] keys = new boolean[65536];
+ private final boolean[] keyboard_keys = new boolean[65536];
+ private final ArrayList last_press_keys = new ArrayList<>();
+ private final ArrayList keyCallbacks = new ArrayList<>();
+ private final GLFWKeyCallback keyCallback = new GLFWKeyCallback() {
+ @Override
+ public void invoke(long window, int key, int scancode, int action, int mods) {
+ if (key >= 0 && action == GLFW_PRESS) {
+ keyboard_keys[key] = true;
+ last_press_keys.add(key);
+ }
+ if (key >= 0)
+ keys[key] = action != GLFW_RELEASE;
+
+ keyCallbacks.forEach(c -> c.onKey(key, scancode, action, mods));
+
+ }
+ };
+
+ private final GLFWScrollCallback scrollCallback = new GLFWScrollCallback() {
+ @Override
+ public void invoke(long window, double xoffset, double yoffset) {
+ wheelDelta = yoffset;
+ }
+ };
+
+ public Display(int width, int height, String title) {
+ this.width = width;
+ this.height = height;
+ displayScale = getScale(width, height);
+ this.mainTitle = title;
+
+ }
+
+ private float getScale(int width, int height) {
+ return Math.min(width, height) / 400.0f * 0.6f;
+ }
+
+ public void create() {
+ GLFWErrorCallback.createPrint(System.err).set();
+ if (!glfwInit()) {
+ throw new RuntimeException("Can't init GLFW!");
+ }
+
+ glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
+
+ window = glfwCreateWindow(width, height, mainTitle, 0, 0);
+
+ if (window == 0) {
+ throw new RuntimeException("Can't create window!");
+ }
+
+ // get width and height
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ // center the window
+ glfwSetWindowPos(window, (screenSize.width - width) / 2, (screenSize.height - height) / 2);
+
+ glfwMakeContextCurrent(window);
+ GL.createCapabilities();
+
+ glfwSwapInterval(1);
+
+ glfwSetWindowSizeCallback(window, windowSizeCallback);
+ glfwSetCursorPosCallback(window, cursorPosCallback);
+ glfwSetMouseButtonCallback(window, mouseButtonCallback);
+ glfwSetKeyCallback(window, keyCallback);
+ glfwSetScrollCallback(window, scrollCallback);
+
+ GL11.glEnable(GL11.GL_TEXTURE_2D);
+
+ this.running = true;
+
+ }
+
+ public void addKeyListener(KeyInputListener callback) {
+ keyCallbacks.add(callback);
+ }
+
+ public void removeKeyListener(KeyInputListener callback) {
+ keyCallbacks.remove(callback);
+ }
+
+ public void addWindowSizedListener(WindowSizeListener callback) {
+ sizeCallbacks.add(callback);
+ }
+
+ public void removeWindowSizedListener(WindowSizeListener callback) {
+ sizeCallbacks.remove(callback);
+ }
+
+ public void addMouseInputListener(MouseInputListener callback) {
+ mouseCallbacks.add(callback);
+ }
+
+ public void removeMouseInputListener(MouseInputListener callback) {
+ mouseCallbacks.remove(callback);
+ }
+
+ public void addMousePositionListener(CursorPositionListener callback) {
+ cursorPosCallbacks.add(callback);
+ }
+
+ public void removeMousePositionListener(CursorPositionListener callback) {
+ cursorPosCallbacks.remove(callback);
+ }
+
+ public void show() {
+ glfwShowWindow(window);
+
+ }
+
+ public void hide() {
+ glfwHideWindow(window);
+
+ }
+
+ private void callbackTick() {
+ for (int i = 0; i < 8; i++)
+ mouse_buttons[i] = false;
+
+ for (Integer r : last_press_keys)
+ keyboard_keys[r] = false;
+ last_press_keys.clear();
+
+ wheelDelta = 0;
+ cursorDx = 0;
+ cursorDy = 0;
+
+ }
+
+ public void update() {
+ callbackTick();
+
+ glfwSwapBuffers(window);
+ glfwPollEvents();
+
+ if (glfwWindowShouldClose(window))
+ running = false;
+
+ }
+
+ public void setMouseGrabbed(boolean mouseGrabbed) {
+ if (this.mouseGrabbed == mouseGrabbed)
+ return;
+
+ glfwSetInputMode(window, GLFW_CURSOR, mouseGrabbed ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
+ this.mouseGrabbed = mouseGrabbed;
+
+ }
+
+ public void release() {
+ this.running = false;
+ glfwDestroyWindow(window);
+ glfwTerminate();
+
+ }
+
+ public double getWheelDelta() {
+ return wheelDelta;
+ }
+
+ public boolean isRunning() {
+ return running;
+ }
+
+ public void setRunning(boolean running) {
+ this.running = running;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public float getCursorX() {
+ return cursorX;
+ }
+
+ public float getCursorY() {
+ return cursorY;
+ }
+
+ public float getCursorDX() {
+ return cursorDx;
+ }
+
+ public float getCursorDY() {
+ return cursorDy;
+ }
+
+ public float getDisplayScale() {
+ return displayScale;
+ }
+
+ public boolean isKeyDown(int key) {
+ return keys[key];
+ }
+
+ @Deprecated
+ public boolean isKeyDownOnce(int key) {
+ return keyboard_keys[key];
+ }
+
+ public boolean isMouseDown(int mouse) {
+ return glfwGetMouseButton(window, mouse) == GLFW_PRESS;
+ }
+
+ @Deprecated
+ public boolean isMouseDownOnce(int mouse) {
+ return mouse_buttons[mouse];
+ }
+
+ public boolean isMouseGrabbed() {
+ return mouseGrabbed;
+ }
+
+ public List getPressedKeyList() {
+ return last_press_keys;
+ }
+
+}
diff --git a/src/main/java/xueli/game2/display/FPSCalculator.java b/src/main/java/xueli/game2/display/FPSCalculator.java
new file mode 100644
index 00000000..ef7a86b4
--- /dev/null
+++ b/src/main/java/xueli/game2/display/FPSCalculator.java
@@ -0,0 +1,31 @@
+package xueli.game2.display;
+
+public class FPSCalculator {
+
+ private long thisTime;
+ private long lastTimeCountFPS = 0;
+
+ private int count = 0;
+
+ private int fps = 0;
+
+ public void tick() {
+ thisTime = System.currentTimeMillis();
+ if (thisTime - lastTimeCountFPS < 1000) {
+ count++;
+ } else {
+ fps = count;
+ count = 0;
+
+ lastTimeCountFPS = thisTime;
+ System.out.println("FPS: " + fps);
+
+ }
+
+ }
+
+ public int getFps() {
+ return fps;
+ }
+
+}
diff --git a/src/main/java/xueli/game2/display/GameDisplay.java b/src/main/java/xueli/game2/display/GameDisplay.java
new file mode 100644
index 00000000..fd756a71
--- /dev/null
+++ b/src/main/java/xueli/game2/display/GameDisplay.java
@@ -0,0 +1,203 @@
+package xueli.game2.display;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL30;
+
+import xueli.game2.Timer;
+import xueli.game2.display.event.CursorPositionEvent;
+import xueli.game2.display.event.WindowKeyEvent;
+import xueli.game2.display.event.WindowMouseButtonEvent;
+import xueli.game2.display.event.WindowSizedEvent;
+import xueli.game2.lifecycle.RunnableLifeCycle;
+import xueli.game2.resource.manager.BackwardResourceManager;
+import xueli.game2.resource.provider.ClassLoaderResourceProvider;
+import xueli.game2.resource.provider.ResourceProvider;
+import xueli.game2.resource.submanager.render.shader.ShaderRenderResource;
+import xueli.game2.resource.submanager.render.texture.TextureRenderResource;
+import xueli.gui.WindowSizeProvider;
+import xueli.utils.concurrent.ControllerExecutorService;
+import xueli.utils.events.EventBus;
+import xueli.utils.exception.CrashReport;
+import xueli.utils.logger.Logger;
+
+public abstract class GameDisplay implements RunnableLifeCycle, WindowSizeProvider {
+
+ private static final Logger LOGGER = new Logger();
+
+ protected Display display;
+
+ public final Timer timer = new Timer();
+ public final FPSCalculator fps = new FPSCalculator();
+
+ private boolean shouldCrash = false;
+
+ public final BackwardResourceManager resourceManager;
+ public final TextureRenderResource textureResource;
+ public final ShaderRenderResource shaderResource;
+
+// public final OverlayManager overlayManager;
+
+ public final EventBus eventbus = new EventBus();
+
+ private final ExecutorService asyncExecutor = Executors.newWorkStealingPool();
+ private final ControllerExecutorService mainThreadExecutor = new ControllerExecutorService();
+
+ public GameDisplay(int initialWidth, int initialHeight, String mainTitle) {
+ this.display = new Display(initialWidth, initialHeight, mainTitle);
+
+ List resourceProviders = List.of(new ClassLoaderResourceProvider(true));
+ this.resourceManager = new BackwardResourceManager(resourceProviders);
+
+ this.textureResource = new TextureRenderResource(resourceManager);
+ this.shaderResource = new ShaderRenderResource(resourceManager);
+// this.fontResource = new FontRenderResource(gui, resourceManager);
+
+// this.overlayManager = new OverlayManager(this);
+
+ }
+
+ @Override
+ public void init() {
+ this.display.create();
+ this.display.addKeyListener(
+ (key, scancode, action, mods) -> eventbus.post(new WindowKeyEvent(key, scancode, action, mods)));
+ this.display.addWindowSizedListener((w, h) -> eventbus.post(new WindowSizedEvent(w, h)));
+ this.display.addMouseInputListener(
+ (btn, action, mods) -> eventbus.post(new WindowMouseButtonEvent(btn, action, mods)));
+ this.display.addMousePositionListener((x, y) -> eventbus.post(new CursorPositionEvent(x, y)));
+
+// this.resourceManager.addResourceHolder(this.overlayManager);
+
+ try {
+// this.overlayManager.init();
+ renderInit();
+ } catch (Exception e) {
+ this.announceCrash("Init", e);
+ }
+
+ this.printDeviceInfo();
+
+ this.display.show();
+
+ }
+
+ @Override
+ public void tick() {
+ timer.tick();
+ fps.tick();
+ try {
+ mainThreadExecutor.tick();
+ } catch (Exception e) {
+ this.announceCrash("MainThreadExecutor", e);
+ }
+
+ GL30.glViewport(0, 0, display.getWidth(), display.getHeight());
+ GL30.glClear(GL30.GL_COLOR_BUFFER_BIT | GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);
+
+// if(this.overlayManager.hasOverlay()) {
+// getDisplay().setMouseGrabbed(false);
+// this.overlayManager.tick();
+// } else {
+// getDisplay().setMouseGrabbed(true);
+// }
+
+// try {
+ this.render();
+// } catch (Exception e) {
+// this.announceCrash("Render", e);
+// }
+
+ this.display.update();
+
+ this.checkGLError("Post-Render");
+
+ }
+
+ @Override
+ public boolean isRunning() {
+ return this.display.isRunning() && !shouldCrash;
+ }
+
+ @Override
+ public void release() {
+ this.display.hide();
+// this.overlayManager.release();
+ this.renderRelease();
+
+ asyncExecutor.shutdownNow();
+ mainThreadExecutor.shutdownNow();
+
+ try {
+ this.resourceManager.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ this.display.release();
+
+ }
+
+ protected abstract void renderInit();
+
+ protected abstract void render();
+
+ protected abstract void renderRelease();
+
+ public void announceClose() {
+ this.display.setRunning(false);
+ }
+
+ public void announceCrash(String state, Throwable t) {
+ this.shouldCrash = true;
+ new CrashReport(state, t).showCrashReport();
+ }
+
+ public void checkGLError(String state) {
+ int error = -1;
+ while (error != 0) {
+ error = GL11.glGetError();
+ if (error != 0)
+ System.out.println("[" + state + "] OpenGL Error: " + error);
+ }
+ }
+
+ private void printDeviceInfo() {
+ String nameString = GL11.glGetString(GL11.GL_VENDOR);
+ String platform = GL11.glGetString(GL11.GL_RENDERER);
+ String version = GL11.glGetString(GL11.GL_VERSION);
+ LOGGER.warning("[DeviceInfo] OpenGL: " + nameString + ", " + platform + ", " + version);
+
+ }
+
+ public ExecutorService getAsyncExecutor() {
+ return asyncExecutor;
+ }
+
+ public ExecutorService getMainThreadExecutor() {
+ return mainThreadExecutor;
+ }
+
+ public Display getDisplay() {
+ return display;
+ }
+
+ @Override
+ public int getWidth() {
+ return display.getWidth();
+ }
+
+ @Override
+ public int getHeight() {
+ return display.getHeight();
+ }
+
+ public float getDisplayScale() {
+ return display.getDisplayScale();
+ }
+
+}
diff --git a/src/main/java/xueli/game2/display/KeyInputListener.java b/src/main/java/xueli/game2/display/KeyInputListener.java
new file mode 100644
index 00000000..6c896b30
--- /dev/null
+++ b/src/main/java/xueli/game2/display/KeyInputListener.java
@@ -0,0 +1,7 @@
+package xueli.game2.display;
+
+public interface KeyInputListener {
+
+ public void onKey(int key, int scancode, int action, int mods);
+
+}
diff --git a/src/main/java/xueli/game2/display/MouseInputListener.java b/src/main/java/xueli/game2/display/MouseInputListener.java
new file mode 100644
index 00000000..9eda7830
--- /dev/null
+++ b/src/main/java/xueli/game2/display/MouseInputListener.java
@@ -0,0 +1,8 @@
+package xueli.game2.display;
+
+@FunctionalInterface
+public interface MouseInputListener {
+
+ public void onMouseButton(int button, int action, int mods);
+
+}
diff --git a/src/main/java/xueli/game2/display/RenderResourceProvider.java b/src/main/java/xueli/game2/display/RenderResourceProvider.java
new file mode 100644
index 00000000..d201291c
--- /dev/null
+++ b/src/main/java/xueli/game2/display/RenderResourceProvider.java
@@ -0,0 +1,10 @@
+package xueli.game2.display;
+
+import xueli.game2.resource.manager.ResourceManager;
+
+// TODO: make GameDisplay extend this
+public interface RenderResourceProvider {
+
+ public T getResourceManager(Class clazz);
+
+}
diff --git a/src/main/java/xueli/game2/display/WindowSizeListener.java b/src/main/java/xueli/game2/display/WindowSizeListener.java
new file mode 100644
index 00000000..2e5e1da4
--- /dev/null
+++ b/src/main/java/xueli/game2/display/WindowSizeListener.java
@@ -0,0 +1,7 @@
+package xueli.game2.display;
+
+public interface WindowSizeListener {
+
+ public void onSize(int width, int height);
+
+}
diff --git a/src/main/java/xueli/game2/display/event/CursorPositionEvent.java b/src/main/java/xueli/game2/display/event/CursorPositionEvent.java
new file mode 100644
index 00000000..9b0cda04
--- /dev/null
+++ b/src/main/java/xueli/game2/display/event/CursorPositionEvent.java
@@ -0,0 +1,4 @@
+package xueli.game2.display.event;
+
+public record CursorPositionEvent(double x, double y) {
+}
diff --git a/src/main/java/xueli/game2/display/event/WindowKeyEvent.java b/src/main/java/xueli/game2/display/event/WindowKeyEvent.java
new file mode 100644
index 00000000..33758174
--- /dev/null
+++ b/src/main/java/xueli/game2/display/event/WindowKeyEvent.java
@@ -0,0 +1,4 @@
+package xueli.game2.display.event;
+
+public record WindowKeyEvent(int key, int scancode, int action, int mods) {
+}
diff --git a/src/main/java/xueli/game2/display/event/WindowMouseButtonEvent.java b/src/main/java/xueli/game2/display/event/WindowMouseButtonEvent.java
new file mode 100644
index 00000000..bd49a560
--- /dev/null
+++ b/src/main/java/xueli/game2/display/event/WindowMouseButtonEvent.java
@@ -0,0 +1,4 @@
+package xueli.game2.display.event;
+
+public record WindowMouseButtonEvent(int button, int action, int mods) {
+}
diff --git a/src/main/java/xueli/game2/display/event/WindowSizedEvent.java b/src/main/java/xueli/game2/display/event/WindowSizedEvent.java
new file mode 100644
index 00000000..2dbcb31b
--- /dev/null
+++ b/src/main/java/xueli/game2/display/event/WindowSizedEvent.java
@@ -0,0 +1,4 @@
+package xueli.game2.display.event;
+
+public record WindowSizedEvent(int width, int height) {
+}
diff --git a/src/main/java/xueli/game2/ecs/ComponentInfo.java b/src/main/java/xueli/game2/ecs/ComponentInfo.java
new file mode 100644
index 00000000..b9165352
--- /dev/null
+++ b/src/main/java/xueli/game2/ecs/ComponentInfo.java
@@ -0,0 +1,26 @@
+package xueli.game2.ecs;
+
+import java.util.HashMap;
+import java.util.Set;
+
+class ComponentInfo {
+
+ private final HashMap components = new HashMap<>();
+
+ public void addComponent(long entityId, Object component) {
+ components.put(entityId, component);
+ }
+
+ public Object getComponent(long entityId) {
+ return components.get(entityId);
+ }
+
+ public void removeComponent(long entityId) {
+ components.remove(entityId);
+ }
+
+ public Set query() {
+ return components.keySet();
+ }
+
+}
diff --git a/src/main/java/xueli/game2/ecs/ECSContext.java b/src/main/java/xueli/game2/ecs/ECSContext.java
new file mode 100644
index 00000000..985c9f85
--- /dev/null
+++ b/src/main/java/xueli/game2/ecs/ECSContext.java
@@ -0,0 +1,109 @@
+package xueli.game2.ecs;
+
+import java.util.Set;
+
+/**
+ * This is an ECS context which holds an Entity Component System.
+ */
+public interface ECSContext {
+
+ /**
+ * Spawn an entity
+ *
+ * @return The ID of the entity
+ */
+ public long spawn();
+
+ /**
+ * Delete an entity
+ */
+ public void kill(long entityId);
+
+ /**
+ * Add an component to the entity
+ */
+ public void addComponent(long entityId, Object component);
+
+ /**
+ * Get an component from the entity
+ *
+ * @param The type of the component
+ */
+ public T getComponent(long entityId, Class componentClazz);
+
+ /**
+ * Remove an component from the entity
+ *
+ * @param The type of the component
+ */
+ public void removeComponent(long entityId, Class componentClazz);
+
+ /**
+ * Add a resource. A resource is a component that isn't bound to any entity and
+ * only one instance of each type exists.
+ *
+ * @param The type of the resource
+ */
+ public void addResource(Object resource);
+
+ /**
+ * Get a resource.
+ *
+ * @param The type of the resource
+ * @return The unique resource instance in the type R, or null if we don't have
+ * the corresponding resource.
+ */
+ public R getResource(Class resourceClazz);
+
+ /**
+ * Remove a resource
+ */
+ public void removeResource(Class resourceClazz);
+
+ /**
+ * Query all the entity that has component T
+ *
+ * @param The type of the entities that you want to find
+ * @return A list contains all the corresponding entities
+ */
+ public Set query(Class clazz);
+
+ /**
+ * Add a system
+ */
+ public void addSystem(ECSSystem system);
+
+ /**
+ * Broadcast an event to the context. When next update occurs, every system
+ * should have access to the events. And when it is the following update, these
+ * events will become inaccessible.
+ *
+ * @param The type of the event
+ */
+ public void broadcast(Object e);
+
+ /**
+ * Read an event
+ *
+ * @param The type of the event
+ * @return The instance of the event, or null if there is no event belonging to
+ * type E now
+ */
+ public E readEvent(Class clazz);
+
+ /**
+ * Startup all systems
+ */
+ public void startUp();
+
+ /**
+ * Update the systems
+ */
+ public void update();
+
+ /**
+ * Shut down all systems
+ */
+ public void shutdown();
+
+}
diff --git a/src/main/java/xueli/game2/ecs/ECSContextImpl.java b/src/main/java/xueli/game2/ecs/ECSContextImpl.java
new file mode 100644
index 00000000..9306c73d
--- /dev/null
+++ b/src/main/java/xueli/game2/ecs/ECSContextImpl.java
@@ -0,0 +1,114 @@
+package xueli.game2.ecs;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import xueli.utils.events.DeferredEventBus;
+
+public class ECSContextImpl implements ECSContext {
+
+ private long entityIndex = 0;
+
+ private final HashMap, ComponentInfo> componentInstances = new HashMap<>();
+
+ @Override
+ public long spawn() {
+ return entityIndex++;
+ }
+
+ @Override
+ public void kill(long entityId) {
+ componentInstances.forEach((c, i) -> {
+ i.removeComponent(entityId);
+ });
+ }
+
+ @Override
+ public void addComponent(long entityId, Object component) {
+ componentInstances.computeIfAbsent(component.getClass(), c -> new ComponentInfo()).addComponent(entityId,
+ component);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T getComponent(long entityId, Class componentClazz) {
+ ComponentInfo info = componentInstances.get(componentClazz);
+ if (info == null)
+ return null;
+ return (T) info.getComponent(entityId);
+ }
+
+ @Override
+ public void removeComponent(long entityId, Class componentClazz) {
+ ComponentInfo info = componentInstances.get(componentClazz);
+ if (info == null)
+ return;
+ info.removeComponent(entityId);
+ }
+
+ final ResourceList