diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..cb2fdb3a9 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 000000000..c630c0b87 --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml index b5c503a41..26cb1d226 100644 --- a/.idea/libraries/lib.xml +++ b/.idea/libraries/lib.xml @@ -6,17 +6,20 @@ - + + + - - - + + + + - + \ No newline at end of file diff --git a/Terrarum_renewed.iml b/Terrarum_renewed.iml index e1985f524..03b9daec3 100644 --- a/Terrarum_renewed.iml +++ b/Terrarum_renewed.iml @@ -15,6 +15,17 @@ - + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/graphics/fonts/LatinExtA_variable.tga b/assets/graphics/fonts/LatinExtA_variable.tga deleted file mode 100644 index 50a7176e7..000000000 --- a/assets/graphics/fonts/LatinExtA_variable.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:09b5ee5cffab7bf8868b6f8d6e08e50bbac0c2a8767598f97dfe8463e5a0d0f4 -size 163884 diff --git a/assets/graphics/fonts/LatinExtB_variable.tga b/assets/graphics/fonts/LatinExtB_variable.tga deleted file mode 100644 index df1bf4c3c..000000000 --- a/assets/graphics/fonts/LatinExtB_variable.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7ad5f0f8a42c8ec8b53e0190b39a53c83542a4cd1bf3230c9032a9ceda80311c -size 266284 diff --git a/assets/graphics/fonts/cyrilic_bulgarian_variable.tga b/assets/graphics/fonts/cyrilic_bulgarian_variable.tga deleted file mode 100644 index 42f09b760..000000000 --- a/assets/graphics/fonts/cyrilic_bulgarian_variable.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0dce090d6e32db61b047898f962060d4534e2dd142e5efe0c3f47bd8290e5559 -size 122924 diff --git a/assets/graphics/fonts/cyrilic_serbian_variable.tga b/assets/graphics/fonts/cyrilic_serbian_variable.tga deleted file mode 100644 index 69783b512..000000000 --- a/assets/graphics/fonts/cyrilic_serbian_variable.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:23b85f724f00f845f68cc3d9fc9b37db9c76524cf34d52fe75cc3a2519161df7 -size 122924 diff --git a/assets/graphics/fonts/cyrilic_variable.tga b/assets/graphics/fonts/cyrilic_variable.tga deleted file mode 100644 index eb495dd36..000000000 --- a/assets/graphics/fonts/cyrilic_variable.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:99b4f848a386b7219a4def17b4e4e08aedfa66d432c3d8e04c42fc020835ae25 -size 122924 diff --git a/assets/graphics/fonts/hangul_johab.tga b/assets/graphics/fonts/hangul_johab.tga deleted file mode 100644 index 739bd8e7b..000000000 --- a/assets/graphics/fonts/hangul_johab.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:738e67a7f9f23b2bcadc94128c7b4bfbb9c81ee1051512b4e3c8738baf1bf93f -size 268818 diff --git a/assets/graphics/fonts/numeric_small.tga b/assets/graphics/fonts/numeric_small.tga index 2e5bed73d..c792a9ee0 100644 --- a/assets/graphics/fonts/numeric_small.tga +++ b/assets/graphics/fonts/numeric_small.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ac3bd5c75ead34552e5aa3e932a315346514f80895cdbad8c94fd9ff921ddb50 -size 1618 +oid sha256:667a8c5fa366c42b873c196b866571ee0c35c0992a3114d88593d37e0979d4a6 +size 1644 diff --git a/assets/graphics/fonts/puae000-e0ff.tga b/assets/graphics/fonts/puae000-e0ff.tga deleted file mode 100644 index 0f5beca17..000000000 --- a/assets/graphics/fonts/puae000-e0ff.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c135a82f5c921f3a92e354703470a557d372d6345af8a093f656c567efd2a93b -size 331820 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtA_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtA_variable.tga new file mode 100644 index 000000000..153315c68 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtA_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c066e27cec3894dd008bd0786b7a968371bf80d9d6c49b78ba541e3b9fd6b6f5 +size 163884 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtB_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtB_variable.tga new file mode 100644 index 000000000..1ff7dfba9 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtB_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad0a7c9ad92ddfdf268f77ec47f5e056174730518689c2540bd80795096717bc +size 266284 diff --git a/assets/graphics/fonts/ascii_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/ascii_variable.tga similarity index 100% rename from assets/graphics/fonts/ascii_variable.tga rename to assets/graphics/fonts/terrarum-sans-bitmap/ascii_variable.tga diff --git a/assets/graphics/fonts/cjkpunct.tga b/assets/graphics/fonts/terrarum-sans-bitmap/cjkpunct.tga similarity index 100% rename from assets/graphics/fonts/cjkpunct.tga rename to assets/graphics/fonts/terrarum-sans-bitmap/cjkpunct.tga diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_bulgarian_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_bulgarian_variable.tga new file mode 100644 index 000000000..3547356bc --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_bulgarian_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1640dd83ed0769dd8f58105fb360990f3252e8c83997f8357864d74151738b9 +size 389164 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_serbian_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_serbian_variable.tga new file mode 100644 index 000000000..d8b9594d7 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_serbian_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccb7284e79124b69cdbb18fefad8546103313694b9769ec206d92e0c3f12f919 +size 389164 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_variable.tga new file mode 100644 index 000000000..9ed5e7d97 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8c05c12eef217e32a4d2a55ed060736e0e8d6b7b603c4be04ef5b5a41c726aa +size 389164 diff --git a/assets/graphics/fonts/fullwidth_forms.tga b/assets/graphics/fonts/terrarum-sans-bitmap/fullwidth_forms.tga similarity index 100% rename from assets/graphics/fonts/fullwidth_forms.tga rename to assets/graphics/fonts/terrarum-sans-bitmap/fullwidth_forms.tga diff --git a/assets/graphics/fonts/greek_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/greek_variable.tga similarity index 100% rename from assets/graphics/fonts/greek_variable.tga rename to assets/graphics/fonts/terrarum-sans-bitmap/greek_variable.tga diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/hangul_johab.tga b/assets/graphics/fonts/terrarum-sans-bitmap/hangul_johab.tga new file mode 100644 index 000000000..99df6a513 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/hangul_johab.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56548976bad3847a0de61a12e31f12a06b3575f2a750c312074fd840ca72583a +size 268844 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/hayeren_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/hayeren_variable.tga new file mode 100644 index 000000000..aa1669fe8 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/hayeren_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f9fc5b918a0fd6803a0609256ff3620e54c5cc9c6f5094851f221e807da5d176 +size 122924 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/insular_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/insular_variable.tga new file mode 100644 index 000000000..e97acfb87 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/insular_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5ee21a0973a60feb3fb8132c9a838b56e197bdab1418deab55b4a9beb2ced14 +size 40978 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/ipa_ext_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/ipa_ext_variable.tga new file mode 100644 index 000000000..8225c4c7e --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/ipa_ext_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2be447fc79f9897de0c58eec7feebcd5fd9d9d3bd3b7b0c1d29a667fdc4802c6 +size 122924 diff --git a/assets/graphics/fonts/kana.tga b/assets/graphics/fonts/terrarum-sans-bitmap/kana.tga similarity index 100% rename from assets/graphics/fonts/kana.tga rename to assets/graphics/fonts/terrarum-sans-bitmap/kana.tga diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/kartuli_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/kartuli_variable.tga new file mode 100644 index 000000000..29f955312 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/kartuli_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e32f80fd89ae06e0a66731653a1ed2fa9b7a8cbb2df6096195ec34383c9a17a +size 61484 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/puae000-e0ff.tga b/assets/graphics/fonts/terrarum-sans-bitmap/puae000-e0ff.tga new file mode 100644 index 000000000..9fb33d142 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/puae000-e0ff.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56091eeb4f186e7b641cb31b41b61ad62d435bf5b0cceb5755398fe06ea260ca +size 331820 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/thai_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/thai_variable.tga new file mode 100644 index 000000000..aa1fcb984 --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/thai_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42aa0e6c5c5fa0371ec64a9ebb7d78969b886235d63dbe307bba4e03ed1a23c2 +size 122924 diff --git a/assets/graphics/fonts/unipunct_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/unipunct_variable.tga similarity index 100% rename from assets/graphics/fonts/unipunct_variable.tga rename to assets/graphics/fonts/terrarum-sans-bitmap/unipunct_variable.tga diff --git a/assets/graphics/fonts/wenquanyi.tga.gz b/assets/graphics/fonts/terrarum-sans-bitmap/wenquanyi.tga.gz similarity index 100% rename from assets/graphics/fonts/wenquanyi.tga.gz rename to assets/graphics/fonts/terrarum-sans-bitmap/wenquanyi.tga.gz diff --git a/assets/graphics/fonts/thai_variable.tga b/assets/graphics/fonts/thai_variable.tga deleted file mode 100644 index 1da7219b1..000000000 --- a/assets/graphics/fonts/thai_variable.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:695841163f0bdb8a797b29e21ed046e011d06e950dff4a30cd1e5867f9d9bbf6 -size 122898 diff --git a/assets/graphics/gui/StoneGUITex.tga b/assets/graphics/gui/StoneGUITex.tga deleted file mode 100644 index 8be184e33..000000000 --- a/assets/graphics/gui/StoneGUITex.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:23377c4da632d7c9b2033561f5880cefd01e09e36c249bb9b5a53d716d22b49f -size 1469178 diff --git a/assets/graphics/gui/control_helper_body.tga b/assets/graphics/gui/control_helper_body.tga deleted file mode 100644 index dc2c83066..000000000 --- a/assets/graphics/gui/control_helper_body.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0ab7837af32ac394fbff99fd6700c43bb4ea42abcc73103392a594448d84efd9 -size 98 diff --git a/assets/graphics/gui/control_helper_left b/assets/graphics/gui/control_helper_left deleted file mode 100644 index 48b36b393..000000000 Binary files a/assets/graphics/gui/control_helper_left and /dev/null differ diff --git a/assets/graphics/gui/control_helper_right.tga b/assets/graphics/gui/control_helper_right.tga deleted file mode 100644 index fdeed5457..000000000 --- a/assets/graphics/gui/control_helper_right.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f20865c8a9aaf3f204dcd4d7e07409c8b9a19456da9115a882ab3ba86cfdc5aa -size 418 diff --git a/assets/graphics/gui/message_black.tga b/assets/graphics/gui/message_black.tga new file mode 100644 index 000000000..63b3b1f43 --- /dev/null +++ b/assets/graphics/gui/message_black.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85907cefb4e0f674cb4d83cf51a9dcf145a24825e9909eede4699fb36cb93454 +size 5394 diff --git a/assets/graphics/gui/message_black_body.tga b/assets/graphics/gui/message_black_body.tga deleted file mode 100644 index 0457e9c48..000000000 --- a/assets/graphics/gui/message_black_body.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8dcc084c75046bc5f4266751fdf11615019b574bbfd0f8e322decede2d43a19b -size 524 diff --git a/assets/graphics/gui/message_black_left.tga b/assets/graphics/gui/message_black_left.tga deleted file mode 100644 index 59fec1d30..000000000 --- a/assets/graphics/gui/message_black_left.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1fd7807b7ee5e3766ffe7ce77b6c5a2402e853ce3d20a21744d7abd4e52749ff -size 1964 diff --git a/assets/graphics/gui/message_black_right.tga b/assets/graphics/gui/message_black_right.tga deleted file mode 100644 index 6385ca2e6..000000000 --- a/assets/graphics/gui/message_black_right.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5c92f6317ed2424a34187bd07ea42067d44851ebf3f9d57d2aeddeba9d5ee9e7 -size 1964 diff --git a/assets/graphics/gui/message_twoline_black_body.tga b/assets/graphics/gui/message_twoline_black_body.tga deleted file mode 100644 index 7f5efc7a9..000000000 --- a/assets/graphics/gui/message_twoline_black_body.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:68391840e8d6edb9432e2fa95597b67e305db8144d7fd75624c5b04143492606 -size 11538 diff --git a/assets/graphics/gui/message_twoline_black_left.tga b/assets/graphics/gui/message_twoline_black_left.tga deleted file mode 100644 index 439f63a4d..000000000 --- a/assets/graphics/gui/message_twoline_black_left.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e15e7e4251ddbdf215835b9c3c3aef874a419f9bdb492bed60a0d5dd393f7536 -size 1938 diff --git a/assets/graphics/gui/message_twoline_black_right.tga b/assets/graphics/gui/message_twoline_black_right.tga deleted file mode 100644 index 1222d2347..000000000 --- a/assets/graphics/gui/message_twoline_black_right.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:50ab1e3f6dbe6e0d0dcbdc76fc4a259115705b2799675a4450e836a6df4e0f25 -size 1938 diff --git a/assets/graphics/gui/message_white.tga b/assets/graphics/gui/message_white.tga new file mode 100644 index 000000000..07ef7906a --- /dev/null +++ b/assets/graphics/gui/message_white.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c142d12e5b939adef30be08f00cc4240b04b35a5c8f942319052fef81a3535c0 +size 5394 diff --git a/assets/graphics/gui/tooltip_black.tga b/assets/graphics/gui/tooltip_black.tga new file mode 100644 index 000000000..ad848773b --- /dev/null +++ b/assets/graphics/gui/tooltip_black.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4e615bd3ddc02c8965daf123326c4d600dd5e3e6e71fc274aa26e197f2ffea4 +size 3474 diff --git a/assets/graphics/gui/tooltip_black_body.tga b/assets/graphics/gui/tooltip_black_body.tga deleted file mode 100644 index 82d1e1149..000000000 --- a/assets/graphics/gui/tooltip_black_body.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:eefd6ed8198c789855f59c6d625828fc0e678473c54344dc49e118b30b7a7666 -size 7698 diff --git a/assets/graphics/gui/tooltip_black_left.tga b/assets/graphics/gui/tooltip_black_left.tga deleted file mode 100644 index 075b36bc9..000000000 --- a/assets/graphics/gui/tooltip_black_left.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:07b66222f3de2849bc9513975a8d13c1873fc8fd896cf74a03f75ec57216e27e -size 1298 diff --git a/assets/graphics/gui/tooltip_black_right.tga b/assets/graphics/gui/tooltip_black_right.tga deleted file mode 100644 index 72b1c2b66..000000000 --- a/assets/graphics/gui/tooltip_black_right.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:05c6fc9b4a04571d3996beda28133fc1e89bf3fd1942f9895b7c6aa8eeaec6f7 -size 1298 diff --git a/assets/graphics/gui/tooltip_white.tga b/assets/graphics/gui/tooltip_white.tga new file mode 100644 index 000000000..ec2a59d1a --- /dev/null +++ b/assets/graphics/gui/tooltip_white.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca16b84289d652c01a858099dd49450593c15584e9aa8b884703a6b72c00d472 +size 3474 diff --git a/assets/graphics/ortho_line_tex_2px.tga b/assets/graphics/ortho_line_tex_2px.tga new file mode 100644 index 000000000..3028afc03 --- /dev/null +++ b/assets/graphics/ortho_line_tex_2px.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a5e5942b47dcb6fbb3e2c48959a8fd0aadd46cc7071b94e54e23ba1357fd063 +size 60 diff --git a/assets/graphics/ortho_line_tex_3px.tga b/assets/graphics/ortho_line_tex_3px.tga new file mode 100644 index 000000000..308d678cb --- /dev/null +++ b/assets/graphics/ortho_line_tex_3px.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7082ee7cad27a63b21ee775437e6e525092a3981c77ebe4441a921e7f91e58f0 +size 80 diff --git a/assets/modules/basegame/items/testpick.groovy b/assets/modules/basegame/items/testpick.groovy index f7c5a8d7a..81f47ed1f 100644 --- a/assets/modules/basegame/items/testpick.groovy +++ b/assets/modules/basegame/items/testpick.groovy @@ -5,7 +5,7 @@ import net.torvald.point.Point2d -import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.TerrarumGDX import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.ActorWithPhysics import net.torvald.terrarum.itemproperties.Calculate @@ -14,7 +14,6 @@ import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.blockproperties.Block // following two are NOT UNUSED! import org.jetbrains.annotations.NotNull -import org.newdawn.slick.GameContainer @@ -56,42 +55,42 @@ class TestPick extends GameItem { } @Override - boolean primaryUse(@NotNull GameContainer gc, int delta) { - int mouseTileX = Terrarum.getMouseTileX() - int mouseTileY = Terrarum.getMouseTileY() + boolean primaryUse(float delta) { + int mouseTileX = TerrarumGdx.getMouseTileX() + int mouseTileY = TerrarumGdx.getMouseTileY() def mousePoint = new Point2d(mouseTileX, mouseTileY) - def actorvalue = Terrarum.ingame.player.actorValue + def actorvalue = TerrarumGDX.ingame.player.actorValue using = true // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // return false if hitting actors - Terrarum.ingame.actorContainer.forEach({ + TerrarumGDX.ingame.actorContainer.forEach({ if (it instanceof ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint)) return false }) // return false if here's no tile - if (Block.AIR == Terrarum.ingame.world.getTileFromTerrain(mouseTileX, mouseTileY)) + if (Block.AIR == TerrarumGDX.ingame.world.getTileFromTerrain(mouseTileX, mouseTileY)) return false // filter passed, do the job double swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL) - Terrarum.ingame.world.inflictTerrainDamage( + TerrarumGDX.ingame.world.inflictTerrainDamage( mouseTileX, mouseTileY, - Calculate.pickaxePower(Terrarum.ingame.player, material) * swingDmgToFrameDmg + Calculate.pickaxePower(TerrarumGDX.ingame.player, material) * swingDmgToFrameDmg ) return true } @Override - boolean endPrimaryUse(@NotNull GameContainer gc, int delta) { + boolean endPrimaryUse(float delta) { using = false // reset action timer to zero - Terrarum.ingame.player.actorValue.set(AVKey.__ACTION_TIMER, 0.0) + TerrarumGDX.ingame.player.actorValue.set(AVKey.__ACTION_TIMER, 0.0) return true } } diff --git a/assets/sounds/ambient/ambient_forest_01.ogg b/assets/modules/basegame/sounds/ambient/ambient_forest_01.ogg similarity index 100% rename from assets/sounds/ambient/ambient_forest_01.ogg rename to assets/modules/basegame/sounds/ambient/ambient_forest_01.ogg diff --git a/assets/sounds/ambient/ambient_meadow_01.ogg b/assets/modules/basegame/sounds/ambient/ambient_meadow_01.ogg similarity index 100% rename from assets/sounds/ambient/ambient_meadow_01.ogg rename to assets/modules/basegame/sounds/ambient/ambient_meadow_01.ogg diff --git a/assets/sounds/ambient/ambient_windy_01.ogg b/assets/modules/basegame/sounds/ambient/ambient_windy_01.ogg similarity index 100% rename from assets/sounds/ambient/ambient_windy_01.ogg rename to assets/modules/basegame/sounds/ambient/ambient_windy_01.ogg diff --git a/assets/sounds/ambient/ambient_woods_01.ogg b/assets/modules/basegame/sounds/ambient/ambient_woods_01.ogg similarity index 100% rename from assets/sounds/ambient/ambient_woods_01.ogg rename to assets/modules/basegame/sounds/ambient/ambient_woods_01.ogg diff --git a/assets/sounds/ambient/crickets_01.ogg b/assets/modules/basegame/sounds/ambient/crickets_01.ogg similarity index 100% rename from assets/sounds/ambient/crickets_01.ogg rename to assets/modules/basegame/sounds/ambient/crickets_01.ogg diff --git a/assets/sounds/ambient/crickets_02.ogg b/assets/modules/basegame/sounds/ambient/crickets_02.ogg similarity index 100% rename from assets/sounds/ambient/crickets_02.ogg rename to assets/modules/basegame/sounds/ambient/crickets_02.ogg diff --git a/assets/sounds/effects/power_button_push.wav b/assets/modules/basegame/sounds/effects/power_button_push.wav similarity index 100% rename from assets/sounds/effects/power_button_push.wav rename to assets/modules/basegame/sounds/effects/power_button_push.wav diff --git a/assets/modules/basegame/weathers/generic_light.tga b/assets/modules/basegame/weathers/generic_light.tga index a957b1c2d..49b27272d 100644 --- a/assets/modules/basegame/weathers/generic_light.tga +++ b/assets/modules/basegame/weathers/generic_light.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:322765ec695f78761d7f7c65b23f8e3fdeec331fa6828666de908ffb9c6e1016 +oid sha256:5c9a93c54d74a447930dab6647bc8a1ede7ff6737441cd1c1d93bc0be57bff51 size 836 diff --git a/assets/modules/basegame/weathers/generic_skybox.tga b/assets/modules/basegame/weathers/generic_skybox.tga index b86f2a912..a6f8f0a29 100644 --- a/assets/modules/basegame/weathers/generic_skybox.tga +++ b/assets/modules/basegame/weathers/generic_skybox.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:98857e276bc40139b074380a8f406398198852d4dd430d25fb69805803d28150 +oid sha256:8cf091ec7a8d0693add04cc0dafb0eb3e9f8ad9f21e6036ccc822a2635bdd0ba size 2420 diff --git a/assets/modules/modules_doc.md b/assets/modules/modules_doc.md index b622f55ee..4e21dc985 100644 --- a/assets/modules/modules_doc.md +++ b/assets/modules/modules_doc.md @@ -1,3 +1,12 @@ +## Note to modders + +- You DON'T just edit built-in modules; you must make your own module even if you want to replace defaults. + +### To devs + +- make that happen :\ + + ## Register modules Only the modules that enlisted in LoadOrder.csv will be loaded. diff --git a/lib/OpenAL32.dll b/lib/OpenAL32.dll deleted file mode 100755 index 1f69e9454..000000000 Binary files a/lib/OpenAL32.dll and /dev/null differ diff --git a/lib/OpenAL64.dll b/lib/OpenAL64.dll deleted file mode 100755 index 6f2a2fe13..000000000 Binary files a/lib/OpenAL64.dll and /dev/null differ diff --git a/lib/TerrarumSansBitmap.jar b/lib/TerrarumSansBitmap.jar new file mode 100644 index 000000000..b85aa2b8a Binary files /dev/null and b/lib/TerrarumSansBitmap.jar differ diff --git a/lib/Terrarum_Joise.jar b/lib/Terrarum_Joise.jar new file mode 100644 index 000000000..be920faae Binary files /dev/null and b/lib/Terrarum_Joise.jar differ diff --git a/lib/jinput-dx8.dll b/lib/jinput-dx8.dll deleted file mode 100755 index 6d27ad5eb..000000000 Binary files a/lib/jinput-dx8.dll and /dev/null differ diff --git a/lib/jinput-dx8_64.dll b/lib/jinput-dx8_64.dll deleted file mode 100755 index 67305896d..000000000 Binary files a/lib/jinput-dx8_64.dll and /dev/null differ diff --git a/lib/jinput-raw.dll b/lib/jinput-raw.dll deleted file mode 100755 index ce1d16201..000000000 Binary files a/lib/jinput-raw.dll and /dev/null differ diff --git a/lib/jinput-raw_64.dll b/lib/jinput-raw_64.dll deleted file mode 100755 index 3d2b3ada9..000000000 Binary files a/lib/jinput-raw_64.dll and /dev/null differ diff --git a/lib/jinput.jar b/lib/jinput.jar deleted file mode 100644 index 7c2b6b06f..000000000 Binary files a/lib/jinput.jar and /dev/null differ diff --git a/lib/kotlin-reflect.jar b/lib/kotlin-reflect.jar index 5d6aea243..02eed31b6 100755 Binary files a/lib/kotlin-reflect.jar and b/lib/kotlin-reflect.jar differ diff --git a/lib/source/kotlin-runtime-sources.jar b/lib/kotlin-runtime-sources.jar similarity index 100% rename from lib/source/kotlin-runtime-sources.jar rename to lib/kotlin-runtime-sources.jar diff --git a/lib/kotlin-runtime.jar b/lib/kotlin-runtime.jar index 9c7cc8b80..c784c5931 100755 Binary files a/lib/kotlin-runtime.jar and b/lib/kotlin-runtime.jar differ diff --git a/lib/libjinput-linux.so b/lib/libjinput-linux.so deleted file mode 100755 index 3cdc43973..000000000 Binary files a/lib/libjinput-linux.so and /dev/null differ diff --git a/lib/libjinput-linux64.so b/lib/libjinput-linux64.so deleted file mode 100755 index de1ee5f3c..000000000 Binary files a/lib/libjinput-linux64.so and /dev/null differ diff --git a/lib/libjinput-osx.dylib b/lib/libjinput-osx.dylib deleted file mode 100755 index 59a3eab5e..000000000 Binary files a/lib/libjinput-osx.dylib and /dev/null differ diff --git a/lib/libjinput.zip b/lib/libjinput.zip new file mode 100644 index 000000000..bdcbb98f5 Binary files /dev/null and b/lib/libjinput.zip differ diff --git a/lib/libjnlua5.2.jnilib b/lib/libjnlua5.2.jnilib deleted file mode 100755 index 01c4b5113..000000000 Binary files a/lib/libjnlua5.2.jnilib and /dev/null differ diff --git a/lib/liblwjgl.dylib b/lib/liblwjgl.dylib deleted file mode 100755 index a6083b95e..000000000 Binary files a/lib/liblwjgl.dylib and /dev/null differ diff --git a/lib/liblwjgl.so b/lib/liblwjgl.so deleted file mode 100755 index 3fe6b16c1..000000000 Binary files a/lib/liblwjgl.so and /dev/null differ diff --git a/lib/liblwjgl64.so b/lib/liblwjgl64.so deleted file mode 100755 index 690f6354b..000000000 Binary files a/lib/liblwjgl64.so and /dev/null differ diff --git a/lib/libopenal.so b/lib/libopenal.so deleted file mode 100755 index 0a3a619b4..000000000 Binary files a/lib/libopenal.so and /dev/null differ diff --git a/lib/libopenal64.so b/lib/libopenal64.so deleted file mode 100755 index e0693c01a..000000000 Binary files a/lib/libopenal64.so and /dev/null differ diff --git a/lib/lwjgl.dll b/lib/lwjgl.dll deleted file mode 100755 index 7cca39f88..000000000 Binary files a/lib/lwjgl.dll and /dev/null differ diff --git a/lib/lwjgl.jar b/lib/lwjgl.jar deleted file mode 100644 index e2fa09652..000000000 Binary files a/lib/lwjgl.jar and /dev/null differ diff --git a/lib/lwjgl64.dll b/lib/lwjgl64.dll deleted file mode 100755 index 99cbd9884..000000000 Binary files a/lib/lwjgl64.dll and /dev/null differ diff --git a/lib/lwjgl_util.jar b/lib/lwjgl_util.jar deleted file mode 100644 index 237a1d77c..000000000 Binary files a/lib/lwjgl_util.jar and /dev/null differ diff --git a/lib/openal.dylib b/lib/openal.dylib deleted file mode 100755 index 3c6d0f7f4..000000000 Binary files a/lib/openal.dylib and /dev/null differ diff --git a/lib/slick.jar b/lib/slick.jar deleted file mode 100644 index 1d3d07578..000000000 Binary files a/lib/slick.jar and /dev/null differ diff --git a/src/com/sudoplay/joise/Joise.java b/src/com/sudoplay/joise/Joise.java deleted file mode 100755 index 029bd4908..000000000 --- a/src/com/sudoplay/joise/Joise.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - -import com.sudoplay.joise.module.Module; -import com.sudoplay.joise.module.SeedableModule; -import com.sudoplay.util.Assert; - -public class Joise { - - private Module module; - private ModuleMap moduleMap; - private HashMap> seedMap = new HashMap>(); - - /** - * Creates a new instance of Joise with the supplied module chain. - *

- * This method duplicates the module chain by first converting the chain to a - * {@link ModuleMap}, then converting it back to a {@link Module} while - * mapping any seed names to the seedmap. - *

- * Changes made to the original module passed in will not be reflected in this - * instance of Joise. - * - * @param module - */ - public Joise(Module module) { - Assert.notNull(module); - moduleMap = module.getModuleMap(); - this.module = fromModuleMap(moduleMap); - } - - /** - * Creates a new instance of Joise from the supplied {@link ModuleMap}. - *

- * This method duplicates the module map by first converting the map to a - * {@link Module}, then converting it back to a module map. Seed names are - * mapped during the conversion from map to module. - *

- * Changes made to the original module map passed in will not be reflected in - * this instance of Joise. - * - * @param moduleMap - */ - public Joise(ModuleMap moduleMap) { - Assert.notNull(moduleMap); - this.module = fromModuleMap(moduleMap); - this.moduleMap = module.getModuleMap(); - } - - private Module fromModuleMap(ModuleMap map) { - try { - ModuleInstanceMap im = new ModuleInstanceMap(); - Iterator> it = map.mapIterator(); - Module module = null; - while (it.hasNext()) { - Entry e = it.next(); - ModulePropertyMap props = e.getValue(); - String moduleName = "com.sudoplay.joise.module." + props.get("module"); - module = (Module) Class.forName(moduleName).newInstance(); - module.buildFromPropertyMap(props, im); - if (module instanceof SeedableModule - && ((SeedableModule) module).hasSeedName()) { - SeedableModule sm = (SeedableModule) module; - String seedName = sm.getSeedName(); - - ArrayList list = seedMap.get(seedName); - if (list == null) { - list = new ArrayList(); - seedMap.put(seedName, list); - } - list.add(sm); - } - im.put(e.getKey(), module); - } - return module; - } catch (Exception e) { - throw new JoiseException(e); - } - } - - /** - * Sets the seed of the module linked by seedName. - * - * @param seedName - * @param seed - * @throws IllegalStateException - * if the seed name is not found in the seed map - */ - public void setSeed(String seedName, long seed) { - ArrayList list = seedMap.get(seedName); - if (list == null || list.isEmpty()) { - throw new IllegalStateException("Seed name not found: " + seedName); - } - for (SeedableModule sm : list) { - sm.setSeed(seed); - } - } - - public boolean hasSeed(String seedName) { - return seedMap.get(seedName) != null; - } - - /** - * @return the stored module map for this Joise - */ - public ModuleMap getModuleMap() { - return moduleMap; - } - - public double get(double x, double y) { - return module.get(x, y); - } - - public double get(double x, double y, double z) { - return module.get(x, y, z); - } - - public double get(double x, double y, double z, double w) { - return module.get(x, y, z, w); - } - - public double get(double x, double y, double z, double w, double u, double v) { - return module.get(x, y, z, w, u, v); - } - -} diff --git a/src/com/sudoplay/joise/JoiseException.java b/src/com/sudoplay/joise/JoiseException.java deleted file mode 100755 index 3a888f168..000000000 --- a/src/com/sudoplay/joise/JoiseException.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise; - -@SuppressWarnings("serial") -public class JoiseException extends RuntimeException { - - public JoiseException(String msg) { - super(msg); - } - - public JoiseException(Exception e) { - super(e); - } - - public JoiseException(String msg, Exception e) { - super(msg, e); - } - -} diff --git a/src/com/sudoplay/joise/ModuleInstanceMap.java b/src/com/sudoplay/joise/ModuleInstanceMap.java deleted file mode 100755 index f8502ca73..000000000 --- a/src/com/sudoplay/joise/ModuleInstanceMap.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - -import com.sudoplay.joise.module.Module; - -@SuppressWarnings("serial") -public class ModuleInstanceMap extends HashMap { - - @Override - public Module put(String id, Module module) { - if (id == null) { - throw new NullPointerException("null id"); - } - if (module == null) { - throw new NullPointerException("null module, id=" + id); - } - return super.put(id, module); - } - - @Override - public Module get(Object key) { - Module module = super.get(key); - if (module == null) { - throw new NullPointerException("null module, id=" + key); - } - return module; - } - - public boolean contains(String id) { - return super.get(id) != null; - } - - public Iterator> iterator() { - return super.entrySet().iterator(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("["); - - Iterator> it = iterator(); - while (it.hasNext()) { - Entry e = it.next(); - sb.append("["); - sb.append(e.getKey()); - sb.append("|"); - sb.append(e.getValue()); - sb.append("]"); - } - - sb.append("]"); - return sb.toString(); - } - -} diff --git a/src/com/sudoplay/joise/ModuleMap.java b/src/com/sudoplay/joise/ModuleMap.java deleted file mode 100755 index fe5680701..000000000 --- a/src/com/sudoplay/joise/ModuleMap.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise; - -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map.Entry; - -@SuppressWarnings("serial") -public class ModuleMap extends LinkedHashMap { - - @Override - public ModulePropertyMap put(String module, ModulePropertyMap propertyMap) { - if (propertyMap == null) { - throw new NullPointerException("property map for module [" + module - + "] null"); - } - return super.put(module, propertyMap); - } - - @Override - public ModulePropertyMap get(Object key) { - ModulePropertyMap props = super.get(key); - if (props == null) { - throw new NullPointerException("property map [" + key + "] null"); - } - return super.get(key); - } - - public boolean contains(String id) { - return super.get(id) != null; - } - - public Iterator> mapIterator() { - return super.entrySet().iterator(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("["); - - Iterator> it = mapIterator(); - while (it.hasNext()) { - Entry e = it.next(); - sb.append("["); - sb.append(e.getKey()); - sb.append("|"); - sb.append(e.getValue()); - sb.append("]"); - } - - sb.append("]"); - return sb.toString(); - } - -} diff --git a/src/com/sudoplay/joise/ModulePropertyMap.java b/src/com/sudoplay/joise/ModulePropertyMap.java deleted file mode 100755 index 3f292c320..000000000 --- a/src/com/sudoplay/joise/ModulePropertyMap.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise; - -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map.Entry; - -import com.sudoplay.joise.module.Module; - -@SuppressWarnings("serial") -public class ModulePropertyMap extends LinkedHashMap { - - public ModulePropertyMap() { - // serialization - } - - public ModulePropertyMap(Module module) { - setModule(module); - } - - public void setModule(Module module) { - super.put("module", module.getClass().getSimpleName()); - } - - @Override - public Object put(String key, Object value) { - if (key == null) { - throw new NullPointerException(); - } - if (value == null) { - return super.put(key, null); - } else { - return super.put(key, value.toString()); - } - } - - @Override - public Object get(Object key) { - if (key == null) { - throw new NullPointerException(); - } - Object value = super.get(key); - return value; - } - - public String getAsString(String key) { - return get(key).toString(); - } - - public long getAsLong(String key) { - try { - return Long.parseLong(getAsString(key)); - } catch (NumberFormatException e) { - throw new JoiseException("Expecting property [" + key + ", " - + getAsString(key) + "] to be a long"); - } - } - - public double getAsDouble(String key) { - try { - return Double.parseDouble(getAsString(key)); - } catch (NumberFormatException e) { - throw new JoiseException("Expecting property [" + key + ", " - + getAsString(key) + "] to be a double"); - } - } - - public boolean getAsBoolean(String key) { - String candidate = getAsString(key).toLowerCase(); - if ("true".equals(candidate) || "false".equals(candidate)) { - return Boolean.parseBoolean(getAsString(key)); - } else { - throw new JoiseException("Expecting property [" + key + ", " - + getAsString(key) + "] to be a boolean"); - } - } - - public boolean isModuleID(String key) { - return getAsString(key).startsWith("func_"); - } - - public boolean contains(String key) { - return super.get(key) != null; - } - - public Iterator> iterator() { - return super.entrySet().iterator(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - - Iterator> it = iterator(); - while (it.hasNext()) { - Entry e = it.next(); - sb.append("["); - sb.append(e.getKey()); - sb.append("|"); - sb.append(e.getValue()); - sb.append("]"); - } - - return sb.toString(); - } - -} diff --git a/src/com/sudoplay/joise/generator.tar b/src/com/sudoplay/joise/generator.tar deleted file mode 100644 index 267bf2de0..000000000 Binary files a/src/com/sudoplay/joise/generator.tar and /dev/null differ diff --git a/src/com/sudoplay/joise/generator/BasePRNG.java b/src/com/sudoplay/joise/generator/BasePRNG.java deleted file mode 100755 index 183f73bde..000000000 --- a/src/com/sudoplay/joise/generator/BasePRNG.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.generator; - -public abstract class BasePRNG { - - public abstract int get(); - - public abstract void setSeed(long seed); - - public void setSeedTime() { - setSeed(System.currentTimeMillis()); - } - - public int getTarget(int t) { - double v = get01(); - return (int) (v * (double) t); - } - - public double get01() { - return ((double) get() / (double) 4294967295L) + 0.5; - } - - public int getRange(int low, int high) { - if (high < low) { - int temp = low; - low = high; - high = temp; - } - double range = (double) ((high - low) + 1); - double val = (double) low + get01() * range; - return (int) val; - } - -} diff --git a/src/com/sudoplay/joise/generator/Xorshift128plus.kt b/src/com/sudoplay/joise/generator/Xorshift128plus.kt deleted file mode 100644 index 0ee83fd9b..000000000 --- a/src/com/sudoplay/joise/generator/Xorshift128plus.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.sudoplay.joise.generator - -/** - * Created by SKYHi14 on 2017-02-20. - */ -class Xorshift128plus : BasePRNG() { - - private var s0: Long = 0 - private var s1: Long = 0 - - init { - setSeed(10000L) - } - - override fun get(): Int { - var x = s0 - val y = s1 - s0 = y - x = x xor (x shl 23) - s1 = x xor y xor (x ushr 17) xor (y ushr 26) - return (s1 + y).toInt() - } - - override fun setSeed(seed: Long) { - if (seed == 0L) - throw IllegalArgumentException("Invalid seed: cannot be zero") - - s0 = (6364136223846793005L * seed + 1442695040888963407L) - s1 = (6364136223846793005L * s0 + 1442695040888963407L) - } -} \ No newline at end of file diff --git a/src/com/sudoplay/joise/mapping/Array2Double.java b/src/com/sudoplay/joise/mapping/Array2Double.java deleted file mode 100755 index afa79a4f3..000000000 --- a/src/com/sudoplay/joise/mapping/Array2Double.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public class Array2Double { - - public static final byte X = 0; - public static final byte Y = 1; - - private int[] size = new int[2]; - private double[] data; - - @SuppressWarnings("unused") - private Array2Double() {} - - public Array2Double(int x, int y) { - this(x, y, new double[x * y]); - } - - public Array2Double(int x, int y, double[] data) { - size[X] = x; - size[Y] = y; - this.data = data; - } - - public void set(int x, int y, double v) { - data[x + size[X] * y] = v; - } - - public double get(int x, int y) { - return data[x + size[X] * y]; - } - - public double[] getData() { - return data; - } - - public int[] getSize() { - return size; - } - - public int getWidth() { - return size[X]; - } - - public int getHeight() { - return size[Y]; - } - -} diff --git a/src/com/sudoplay/joise/mapping/Array2DoubleWriter.java b/src/com/sudoplay/joise/mapping/Array2DoubleWriter.java deleted file mode 100755 index e419470db..000000000 --- a/src/com/sudoplay/joise/mapping/Array2DoubleWriter.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public class Array2DoubleWriter implements Mapping2DWriter { - - private Array2Double data; - - public Array2DoubleWriter(int x, int y) { - this(new Array2Double(x, y)); - } - - public Array2DoubleWriter(Array2Double data) { - this.data = data; - } - - public Array2Double getData() { - return data; - } - - @Override - public void write(int x, int y, double value) { - data.set(x, y, value); - } - -} diff --git a/src/com/sudoplay/joise/mapping/Array3Double.java b/src/com/sudoplay/joise/mapping/Array3Double.java deleted file mode 100755 index cabeb1623..000000000 --- a/src/com/sudoplay/joise/mapping/Array3Double.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public class Array3Double { - - public static final byte X = 0; - public static final byte Y = 1; - public static final byte Z = 2; - public static final byte XY = 3; - - private int[] size = new int[4]; - private double[] data; - - @SuppressWarnings("unused") - private Array3Double() {} - - public Array3Double(int x, int y, int z) { - size[X] = x; - size[Y] = y; - size[Z] = z; - size[XY] = x * y; - data = new double[x * y * z]; - } - - public void set(int x, int y, int z, double v) { - data[x + (size[X] * y) + (size[XY] * z)] = v; - } - - public double get(int x, int y, int z) { - return data[x + (size[X] * y) + (size[XY] * z)]; - } - - public double[] getData() { - return data; - } - - public int[] getSize() { - return size; - } - - public int getWidth() { - return size[X]; - } - - public int getHeight() { - return size[Y]; - } - - public int getDepth() { - return size[Z]; - } - -} diff --git a/src/com/sudoplay/joise/mapping/Array3DoubleWriter.java b/src/com/sudoplay/joise/mapping/Array3DoubleWriter.java deleted file mode 100755 index 429b502ec..000000000 --- a/src/com/sudoplay/joise/mapping/Array3DoubleWriter.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public class Array3DoubleWriter implements Mapping3DWriter { - - private Array3Double data; - - public Array3DoubleWriter(int x, int y, int z) { - this(new Array3Double(x, y, z)); - } - - public Array3DoubleWriter(Array3Double data) { - this.data = data; - } - - public Array3Double getData() { - return data; - } - - @Override - public void write(int x, int y, int z, double value) { - data.set(x, y, z, value); - } - -} diff --git a/src/com/sudoplay/joise/mapping/Mapping.java b/src/com/sudoplay/joise/mapping/Mapping.java deleted file mode 100755 index 540512347..000000000 --- a/src/com/sudoplay/joise/mapping/Mapping.java +++ /dev/null @@ -1,753 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -import com.sudoplay.joise.module.Module; - -public final class Mapping { - - private static final double TWO_PI = Math.PI * 2.0; - - private Mapping() { - // do not instantiate - } - - public static void map2D(MappingMode mode, int width, int height, Module m, - MappingRange range, Mapping2DWriter writer, - MappingUpdateListener listener, double z) { - - if (writer == null) { - writer = Mapping2DWriter.NULL_WRITER; - } - - if (listener == null) { - listener = MappingUpdateListener.NULL_LISTENER; - } - - double p, q; - double nx, ny, nz, nw, nu, nv; - double r; - double zval; - - double dx, dy, dz; - double dx_div_2pi; - double dy_div_2pi; - double dz_div_2pi; - - double iw = 1.0 / (double) width; - double ih = 1.0 / (double) height; - - double total = width * height; - double current = 0; - - switch (mode) { - - case NORMAL: - - dx = range.map1.x - range.map0.x; - dy = range.map1.y - range.map0.y; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - nx = range.map0.x + p * dx; - ny = range.map0.y + q * dy; - nz = z; - - writer.write(x, y, m.get(nx, ny, nz)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_X: - - dx = range.loop1.x - range.loop0.x; - dy = range.map1.y - range.map0.y; - - dx_div_2pi = dx / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - p = p * (range.map1.x - range.map0.x) / dx; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.map0.y + q * dy; - nw = z; - - writer.write(x, y, m.get(nx, ny, nz, nw)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_Y: - - dx = range.map1.x - range.map0.x; - dy = range.loop1.y - range.loop0.y; - - dy_div_2pi = dy / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.map0.x + p * dx; - ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nw = z; - - writer.write(x, y, m.get(nx, ny, nz, nw)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_Z: - - dx = range.map1.x - range.map0.x; - dy = range.map1.y - range.map0.y; - dz = range.loop1.z - range.loop0.z; - - r = (z - range.map0.z) / (range.map1.z - range.map0.z); - zval = r * (range.map1.z - range.map0.z) / dz; - - dz_div_2pi = dz / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - nx = range.map0.x + p * dx; - ny = range.map0.y + p * dx; - - nz = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi; - nw = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi; - - writer.write(x, y, m.get(nx, ny, nz, nw)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_XY: - - dx = range.loop1.x - range.loop0.x; - dy = range.loop1.y - range.loop0.y; - - dx_div_2pi = dx / TWO_PI; - dy_div_2pi = dy / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - p = p * (range.map1.x - range.map0.x) / dx; - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nu = z; - nv = 0; - - writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_XZ: - - dx = range.loop1.x - range.loop0.x; - dy = range.map1.y - range.map0.y; - dz = range.loop1.z - range.loop0.z; - - dx_div_2pi = dx / TWO_PI; - dz_div_2pi = dz / TWO_PI; - - r = (z - range.map0.z) / (range.map1.z - range.map0.z); - zval = r * (range.map1.z - range.map0.z) / dz; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - p = p * (range.map1.x - range.map0.x) / dz; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.map0.y + q * dy; - nw = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi; - nu = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi; - nv = 0; - - writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_YZ: - - dx = range.map1.x - range.map0.x; - dy = range.loop1.y - range.loop0.y; - dz = range.loop1.z - range.loop0.z; - - dy_div_2pi = dy / TWO_PI; - dz_div_2pi = dz / TWO_PI; - - r = (z - range.map0.z) / (range.map1.z - range.map0.z); - zval = r * (range.map1.z - range.map0.z) / dz; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.map0.x + p * dx; - ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nw = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi; - nu = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi; - nv = 0; - - writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_XYZ: - - dx = range.loop1.x - range.loop0.x; - dy = range.loop1.y - range.loop0.y; - dz = range.loop1.z - range.loop0.z; - - dx_div_2pi = dx / TWO_PI; - dy_div_2pi = dy / TWO_PI; - dz_div_2pi = dz / TWO_PI; - - r = (z - range.map0.z) / (range.map1.z - range.map0.z); - zval = r * (range.map1.z - range.map0.z) / dz; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - p = p * (range.map1.x - range.map0.x) / dx; - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nu = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi; - nv = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi; - - writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - return; - - default: - throw new AssertionError(); - } - - } - - public static void map2DNoZ(MappingMode mode, int width, int height, - Module m, MappingRange range, Mapping2DWriter writer, - MappingUpdateListener listener) { - - if (writer == null) { - writer = Mapping2DWriter.NULL_WRITER; - } - - if (listener == null) { - listener = MappingUpdateListener.NULL_LISTENER; - } - - double p, q; - double nx, ny, nz, nw; - - double dx, dy; - double dx_div_2pi; - double dy_div_2pi; - - double iw = 1.0 / (double) width; - double ih = 1.0 / (double) height; - - double total = width * height; - double current = 0; - - switch (mode) { - - case NORMAL: - - dx = range.map1.x - range.map0.x; - dy = range.map1.y - range.map0.y; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - nx = range.map0.x + p * dx; - ny = range.map0.y + q * dy; - - writer.write(x, y, m.get(nx, ny)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_X: - - dx = range.loop1.x - range.loop0.x; - dy = range.map1.y - range.map0.y; - - dx_div_2pi = dx / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - p = p * (range.map1.x - range.map0.x) / dx; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.map0.y + q * dy; - - writer.write(x, y, m.get(nx, ny, nz)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_Y: - - dx = range.map1.x - range.map0.x; - dy = range.loop1.y - range.loop0.y; - - dy_div_2pi = dy / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.map0.x + p * dx; - ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - - writer.write(x, y, m.get(nx, ny, nz)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_XY: - - dx = range.loop1.x - range.loop0.x; - dy = range.loop1.y - range.loop0.y; - - dx_div_2pi = dx / TWO_PI; - dy_div_2pi = dy / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - - p = (double) x * iw; - q = (double) y * ih; - - p = p * (range.map1.x - range.map0.x) / dx; - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - - writer.write(x, y, m.get(nx, ny, nz, nw)); - listener.update(++current, total); - } - } - return; - - case SEAMLESS_Z: - case SEAMLESS_XZ: - case SEAMLESS_YZ: - case SEAMLESS_XYZ: - throw new UnsupportedOperationException(mode.toString()); - default: - throw new AssertionError(); - } - - } - - public static void map3D(MappingMode mode, int width, int height, int depth, - Module m, MappingRange range, Mapping3DWriter writer, - MappingUpdateListener listener) { - - if (writer == null) { - writer = Mapping3DWriter.NULL_WRITER; - } - - if (listener == null) { - listener = MappingUpdateListener.NULL_LISTENER; - } - - double p, q, r; - double nx, ny, nz, nw, nu, nv; - - double dx, dy, dz; - double dx_div_2pi; - double dy_div_2pi; - double dz_div_2pi; - - double iw = 1.0 / (double) width; - double ih = 1.0 / (double) height; - double id = 1.0 / (double) depth; - - double total = width * height * depth; - double current = 0; - - switch (mode) { - - case NORMAL: - - dx = range.map1.x - range.map0.x; - dy = range.map1.y - range.map0.y; - dz = range.map1.z - range.map0.z; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - nx = range.map0.x + p * dx; - ny = range.map0.y + q * dy; - nz = range.map0.z + r * dz; - - writer.write(x, y, z, m.get(nx, ny, nz)); - listener.update(++current, total); - } - } - } - return; - - case SEAMLESS_X: - - dx = range.loop1.x - range.loop0.x; - dy = range.map1.y - range.map0.y; - dz = range.map1.z - range.map0.z; - - dx_div_2pi = dx / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - p = p * (range.map1.x - range.map0.x) / dx; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.map0.y + q * dy; - nw = range.map0.z + r * dz; - - writer.write(x, y, z, m.get(nx, ny, nz, nw)); - listener.update(++current, total); - } - } - } - return; - - case SEAMLESS_Y: - - dx = range.map1.x - range.map0.x; - dy = range.loop1.y - range.loop0.y; - dz = range.map1.z - range.map0.z; - - dy_div_2pi = dy / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.map0.x + p * dx; - ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nw = range.map0.z + r * dz; - - writer.write(x, y, z, m.get(nx, ny, nz, nw)); - listener.update(++current, total); - } - } - } - return; - - case SEAMLESS_Z: - - dx = range.map1.x - range.map0.x; - dy = range.map1.y - range.map0.y; - dz = range.loop1.z - range.loop0.z; - - dz_div_2pi = dz / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - r = r * (range.map1.z - range.map0.z) / dz; - - nx = range.map0.x + p * dx; - ny = range.map0.y + q * dy; - nz = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi; - nw = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi; - - writer.write(x, y, z, m.get(nx, ny, nz, nw)); - listener.update(++current, total); - } - } - } - return; - - case SEAMLESS_XY: - - dx = range.loop1.x - range.loop0.x; - dy = range.loop1.y - range.loop0.y; - dz = range.map1.z - range.map0.z; - - dx_div_2pi = dx / TWO_PI; - dy_div_2pi = dy / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - p = p * (range.map1.x - range.map0.x) / dx; - q = q * (range.map1.y - range.map0.y) / dy; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nu = range.map0.z + r * dz; - nv = 0; - - writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - } - return; - - case SEAMLESS_XZ: - - dx = range.loop1.x - range.loop0.x; - dy = range.map1.y - range.map0.y; - dz = range.loop1.z - range.loop0.z; - - dx_div_2pi = dx / TWO_PI; - dz_div_2pi = dz / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - p = p * (range.map1.x - range.map0.x) / dx; - r = r * (range.map1.z - range.map0.z) / dz; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.map0.y + q * dy; - nw = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi; - nu = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi; - nv = 0; - - writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - } - return; - - case SEAMLESS_YZ: - - dx = range.map1.x - range.map0.x; - dy = range.loop1.y - range.loop0.y; - dz = range.loop1.z - range.loop0.z; - - dy_div_2pi = dy / TWO_PI; - dz_div_2pi = dz / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - q = q * (range.map1.y - range.map0.y) / dy; - r = r * (range.map1.z - range.map0.z) / dz; - - nx = range.map0.x + p * dx; - ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nw = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi; - nu = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi; - nv = 0; - - writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - } - return; - - case SEAMLESS_XYZ: - - dx = range.loop1.x - range.loop0.x; - dy = range.loop1.y - range.loop0.y; - dz = range.loop1.z - range.loop0.z; - - dx_div_2pi = dx / TWO_PI; - dy_div_2pi = dy / TWO_PI; - dz_div_2pi = dz / TWO_PI; - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { - - p = (double) x * iw; - q = (double) y * ih; - r = (double) z * id; - - p = p * (range.map1.x - range.map0.x) / dx; - q = q * (range.map1.y - range.map0.y) / dy; - r = r * (range.map1.z - range.map0.z) / dz; - - nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi; - ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi; - nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi; - nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi; - nu = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi; - nv = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi; - - writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv)); - listener.update(++current, total); - } - } - } - return; - - default: - throw new AssertionError(); - } - } - -} diff --git a/src/com/sudoplay/joise/mapping/Mapping2DWriter.java b/src/com/sudoplay/joise/mapping/Mapping2DWriter.java deleted file mode 100755 index a117f8907..000000000 --- a/src/com/sudoplay/joise/mapping/Mapping2DWriter.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public interface Mapping2DWriter { - - public void write(int x, int y, double value); - - public static final Mapping2DWriter NULL_WRITER = new Mapping2DWriter() { - @Override - public void write(int x, int y, double value) { - // do nothing - } - }; - -} diff --git a/src/com/sudoplay/joise/mapping/Mapping3DWriter.java b/src/com/sudoplay/joise/mapping/Mapping3DWriter.java deleted file mode 100755 index 79f8fff32..000000000 --- a/src/com/sudoplay/joise/mapping/Mapping3DWriter.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public interface Mapping3DWriter { - - public void write(int x, int y, int z, double value); - - public static final Mapping3DWriter NULL_WRITER = new Mapping3DWriter() { - @Override - public void write(int x, int y, int z, double value) { - // do nothing - } - }; - -} diff --git a/src/com/sudoplay/joise/mapping/MappingMode.java b/src/com/sudoplay/joise/mapping/MappingMode.java deleted file mode 100755 index b6626d950..000000000 --- a/src/com/sudoplay/joise/mapping/MappingMode.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public enum MappingMode { - NORMAL, SEAMLESS_X, SEAMLESS_Y, SEAMLESS_Z, SEAMLESS_XY, SEAMLESS_XZ, SEAMLESS_YZ, SEAMLESS_XYZ -} diff --git a/src/com/sudoplay/joise/mapping/MappingRange.java b/src/com/sudoplay/joise/mapping/MappingRange.java deleted file mode 100755 index 6ade070e5..000000000 --- a/src/com/sudoplay/joise/mapping/MappingRange.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -import com.sudoplay.joise.noise.Util.Vector3d; - -public class MappingRange { - public Vector3d map0 = new Vector3d(-1, -1, -1); - public Vector3d map1 = new Vector3d(1, 1, 1); - public Vector3d loop0 = new Vector3d(-1, -1, -1); - public Vector3d loop1 = new Vector3d(1, 1, 1); - - public static final MappingRange DEFAULT = new MappingRange(); -} diff --git a/src/com/sudoplay/joise/mapping/MappingUpdateListener.java b/src/com/sudoplay/joise/mapping/MappingUpdateListener.java deleted file mode 100755 index 32b04fea0..000000000 --- a/src/com/sudoplay/joise/mapping/MappingUpdateListener.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.mapping; - -public interface MappingUpdateListener { - - public void update(double current, double total); - - public static final MappingUpdateListener NULL_LISTENER = new MappingUpdateListener() { - @Override - public void update(double current, double total) { - // do nothing - } - }; - -} diff --git a/src/com/sudoplay/joise/module/Module.java b/src/com/sudoplay/joise/module/Module.java deleted file mode 100755 index c0ff6f8d8..000000000 --- a/src/com/sudoplay/joise/module/Module.java +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import java.lang.reflect.Method; -import java.util.concurrent.atomic.AtomicInteger; - -import com.sudoplay.joise.JoiseException; -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public abstract class Module { - - public static final long DEFAULT_SEED = 10000; - public static final int MAX_SOURCES = 10; - - protected double spacing = 0.0001; - - public abstract double get(double x, double y); - - public abstract double get(double x, double y, double z); - - public abstract double get(double x, double y, double z, double w); - - public abstract double get(double x, double y, double z, double w, double u, - double v); - - protected static AtomicInteger nextId = new AtomicInteger(); - - private String id = setId(); - - protected String setId() { - return "func_" + nextId.incrementAndGet(); - } - - public String getId() { - return id; - } - - public ModuleMap getModuleMap() { - ModuleMap map = new ModuleMap(); - _writeToMap(map); - return map; - } - - public void writeToMap(ModuleMap map) { - if (map.contains(id)) { - return; - } - _writeToMap(map); - } - - protected abstract void _writeToMap(ModuleMap map); - - public abstract Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map); - - public void setDerivativeSpacing(double spacing) { - this.spacing = spacing; - } - - public double getDX(double x, double y) { - return (get(x - spacing, y) - get(x + spacing, y)) / spacing; - } - - public double getDY(double x, double y) { - return (get(x, y - spacing) - get(x, y + spacing)) / spacing; - } - - public double getDX(double x, double y, double z) { - return (get(x - spacing, y, z) - get(x + spacing, y, z)) / spacing; - } - - public double getDY(double x, double y, double z) { - return (get(x, y - spacing, z) - get(x, y + spacing, z)) / spacing; - } - - public double getDZ(double x, double y, double z) { - return (get(x, y, z - spacing) - get(x, y, z + spacing)) / spacing; - } - - public double getDX(double x, double y, double z, double w) { - return (get(x - spacing, y, z, w) - get(x + spacing, y, z, w)) / spacing; - } - - public double getDY(double x, double y, double z, double w) { - return (get(x, y - spacing, z, w) - get(x, y + spacing, z, w)) / spacing; - } - - public double getDZ(double x, double y, double z, double w) { - return (get(x, y, z - spacing, w) - get(x, y, z + spacing, w)) / spacing; - } - - public double getDW(double x, double y, double z, double w) { - return (get(x, y, z, w - spacing) - get(x, y, z, w + spacing)) / spacing; - } - - public double getDX(double x, double y, double z, double w, double u, double v) { - return (get(x - spacing, y, z, w, u, v) - get(x + spacing, y, z, w, u, v)) - / spacing; - } - - public double getDY(double x, double y, double z, double w, double u, double v) { - return (get(x, y - spacing, z, w, u, v) - get(x, y + spacing, z, w, u, v)) - / spacing; - } - - public double getDZ(double x, double y, double z, double w, double u, double v) { - return (get(x, y, z - spacing, w, u, v) - get(x, y, z + spacing, w, u, v)) - / spacing; - } - - public double getDW(double x, double y, double z, double w, double u, double v) { - return (get(x, y, z, w - spacing, u, v) - get(x, y, z, w + spacing, u, v)) - / spacing; - } - - public double getDU(double x, double y, double z, double w, double u, double v) { - return (get(x, y, z, w, u - spacing, v) - get(x, y, z, w, u + spacing, v)) - / spacing; - } - - public double getDV(double x, double y, double z, double w, double u, double v) { - return (get(x, y, z, w, u, v - spacing) - get(x, y, z, w, u, v + spacing)) - / spacing; - } - - protected void assertMaxSources(int index) { - if (index < 0 || index >= MAX_SOURCES) { - throw new IllegalArgumentException("expecting index < " + MAX_SOURCES - + " but was " + index); - } - } - - /** - * Read a scalar property from the provided property map and set the property - * in this module using reflection to call the supplied method name with the - * retrieved property passed as an argument. If the scalar is a module name, - * the module is retrieved from the provided {@link ModuleInstanceMap} and set - * using the reflected method provided. - * - * @param name - * @param methodName - * @param props - * @param map - * - * @throws JoiseException - * if there is an error with the retrieval or setting of the - * property - */ - protected void readScalar(String name, String methodName, - ModulePropertyMap props, ModuleInstanceMap map) { - - try { - if (props.isModuleID(name)) { - Method method = getClass().getMethod(methodName, Module.class); - method.invoke(this, new Object[] { map.get(props.get(name)) }); - } else { - Method method = getClass().getMethod(methodName, double.class); - method.invoke(this, new Object[] { props.getAsDouble(name) }); - } - } catch (Exception e) { - throw new JoiseException(e); - } - - } - - /** - * Write a scalar property to the provided property map. If the scalar is a - * module, {@link #_writeToMap(ModuleMap)} is called on the scalar's module. - * - * @param key - * @param scalar - * @param props - * @param map - */ - protected void writeScalar(String key, ScalarParameter scalar, - ModulePropertyMap props, ModuleMap map) { - - props.put(key, scalar); - if (scalar != null && scalar.isModule()) { - scalar.getModule()._writeToMap(map); - } - - } - - /** - * Read an enum property from the provided property map and set the property - * in this module using reflection to call the supplied method name with the - * retrieved property passed as an argument. - * - * @param name - * @param methodName - * @param c - * @param props - */ - protected > void readEnum(String name, String methodName, - Class c, ModulePropertyMap props) { - - try { - Method method = getClass().getMethod(methodName, c); - T _enum = Enum.valueOf(c, props.get(name).toString().toUpperCase()); - method.invoke(this, new Object[] { _enum }); - } catch (Exception e) { - throw new JoiseException(e); - } - - } - - /** - * Write an enum property to the provided property map. The enum is converted - * to lower-case. - * - * @param key - * @param _enum - * @param props - */ - protected void writeEnum(String key, Enum _enum, ModulePropertyMap props) { - - props.put(key, _enum.toString().toLowerCase()); - - } - - /** - * Read a long property from the provided property map and set the property in - * this module using reflection to call the supplied method name with the - * retrieved property passed as an argument. - * - * @param key - * @param methodName - * @param props - */ - protected void readLong(String key, String methodName, ModulePropertyMap props) { - - try { - Method method = getClass().getMethod(methodName, long.class); - method.invoke(this, new Object[] { props.getAsLong(key) }); - } catch (Exception e) { - throw new JoiseException(e); - } - - } - - /** - * Write a long property to the provided property map. - * - * @param key - * @param value - * @param props - */ - protected void writeLong(String key, long value, ModulePropertyMap props) { - - props.put(key, value); - - } - - /** - * Read a double property from the provided property map and set the property - * in this module using reflection to call the supplied method name with the - * retrieved property passed as an argument. - * - * @param key - * @param methodName - * @param props - */ - protected void readDouble(String key, String methodName, - ModulePropertyMap props) { - - try { - Method method = getClass().getMethod(methodName, double.class); - method.invoke(this, new Object[] { props.getAsDouble(key) }); - } catch (Exception e) { - throw new JoiseException(e); - } - - } - - /** - * Write a double property to the provided property map. - * - * @param key - * @param value - * @param props - */ - protected void writeDouble(String key, double value, ModulePropertyMap props) { - - props.put(key, value); - - } - - /** - * Read a boolean property from the provided property map and set the property - * in this module using reflection to call the supplied method name with the - * retrieved property passed as an argument. - * - * @param key - * @param methodName - * @param props - */ - protected void readBoolean(String key, String methodName, - ModulePropertyMap props) { - - try { - Method method = getClass().getMethod(methodName, boolean.class); - method.invoke(this, new Object[] { props.getAsBoolean(key) }); - } catch (Exception e) { - throw new JoiseException(e); - } - - } - - /** - * Write a boolean property to the provided property map. - * - * @param key - * @param value - * @param props - */ - protected void writeBoolean(String key, boolean value, ModulePropertyMap props) { - - props.put(key, String.valueOf(value)); - - } -} diff --git a/src/com/sudoplay/joise/module/ModuleAbs.java b/src/com/sudoplay/joise/module/ModuleAbs.java deleted file mode 100755 index a89abd5d6..000000000 --- a/src/com/sudoplay/joise/module/ModuleAbs.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleAbs extends SourcedModule { - - @Override - public double get(double x, double y) { - return Math.abs(source.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return Math.abs(source.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return Math.abs(source.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return Math.abs(source.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleAutoCorrect.java b/src/com/sudoplay/joise/module/ModuleAutoCorrect.java deleted file mode 100755 index 72cf68d3b..000000000 --- a/src/com/sudoplay/joise/module/ModuleAutoCorrect.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import static com.sudoplay.joise.noise.Util.clamp; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.generator.Xorshift128plus; -import com.sudoplay.util.Checked; - -public class ModuleAutoCorrect extends SourcedModule { - - public static final double DEFAULT_LOW = 0.0; - public static final double DEFAULT_HIGH = 1.0; - public static final int DEFAULT_SAMPLES = 100; - public static final double DEFAULT_SAMPLE_SCALE = 1.0; - - protected double low; - protected double high; - - protected double sampleScale = DEFAULT_SAMPLE_SCALE; - - protected double scale2, offset2; - protected double scale3, offset3; - protected double scale4, offset4; - protected double scale6, offset6; - - protected boolean locked; - - protected int samples = DEFAULT_SAMPLES; - - public ModuleAutoCorrect() { - this(DEFAULT_LOW, DEFAULT_HIGH); - } - - public ModuleAutoCorrect(double low, double high) { - this.low = low; - this.high = high; - } - - public void setRange(double low, double high) { - this.low = low; - this.high = high; - } - - public void setLow(double low) { - this.low = low; - } - - public void setHigh(double high) { - this.high = high; - } - - public void setSamples(long s) { - samples = Checked.safeLongToInt(s); - } - - public void setSampleScale(double s) { - sampleScale = s; - } - - public void setLocked(boolean lock) { - locked = lock; - } - - @Override - public void setSource(double source) { - super.setSource(source); - } - - @Override - public void setSource(Module source) { - super.setSource(source); - } - - public void calculate() { - if (!source.isModule() || locked) return; - - double mn, mx; - Xorshift128plus lcg = new Xorshift128plus(); - - // Calculate 2D - mn = 10000.0; - mx = -10000.0; - for (int c = 0; c < samples; c++) { - double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale; - - double v = source.get(nx, ny); - if (v < mn) mn = v; - if (v > mx) mx = v; - } - scale2 = (high - low) / (mx - mn); - offset2 = low - mn * scale2; - - // Calculate 3D - mn = 10000.0; - mx = -10000.0; - for (int c = 0; c < samples; c++) { - double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale; - - double v = source.get(nx, ny, nz); - if (v < mn) mn = v; - if (v > mx) mx = v; - } - scale3 = (high - low) / (mx - mn); - offset3 = low - mn * scale3; - - // Calculate 4D - mn = 10000.0; - mx = -10000.0; - for (int c = 0; c < samples; c++) { - double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double nw = (lcg.get01() * 4.0 - 2.0) * sampleScale; - - double v = source.get(nx, ny, nz, nw); - if (v < mn) mn = v; - if (v > mx) mx = v; - } - scale4 = (high - low) / (mx - mn); - offset4 = low - mn * scale4; - - // Calculate 6D - mn = 10000.0; - mx = -10000.0; - for (int c = 0; c < samples; c++) { - double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double nw = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double nu = (lcg.get01() * 4.0 - 2.0) * sampleScale; - double nv = (lcg.get01() * 4.0 - 2.0) * sampleScale; - - double v = source.get(nx, ny, nz, nw, nu, nv); - if (v < mn) mn = v; - if (v > mx) mx = v; - } - scale6 = (high - low) / (mx - mn); - offset6 = low - mn * scale6; - - } - - @Override - public double get(double x, double y) { - double v = source.get(x, y); - return clamp(v * scale2 + offset2, low, high); - } - - @Override - public double get(double x, double y, double z) { - double v = source.get(x, y, z); - return clamp(v * scale3 + offset3, low, high); - } - - @Override - public double get(double x, double y, double z, double w) { - double v = source.get(x, y, z, w); - return clamp(v * scale4 + offset4, low, high); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double val = source.get(x, y, z, w, u, v); - return clamp(val * scale6 + offset6, low, high); - } - - public double getOffset2D() { - return offset2; - } - - public double getOffset3D() { - return offset3; - } - - public double getOffset4D() { - return offset4; - } - - public double getOffset6D() { - return offset6; - } - - public double getScale2D() { - return scale2; - } - - public double getScale3D() { - return scale3; - } - - public double getScale4D() { - return scale4; - } - - public double getScale6D() { - return scale6; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeDouble("low", low, props); - writeDouble("high", high, props); - writeLong("samples", samples, props); - writeDouble("sampleScale", sampleScale, props); - writeBoolean("locked", locked, props); - - if (locked) { - writeDouble("scale2", scale2, props); - writeDouble("offset2", offset2, props); - writeDouble("scale3", scale3, props); - writeDouble("offset3", offset3, props); - writeDouble("scale4", scale4, props); - writeDouble("offset4", offset4, props); - writeDouble("scale6", scale6, props); - writeDouble("offset6", offset6, props); - } - - writeSource(props, map); - - map.put(getId(), props); - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readDouble("low", "setLow", props); - readDouble("high", "setHigh", props); - readLong("samples", "setSamples", props); - readDouble("sampleScale", "setSampleScale", props); - readBoolean("locked", "setLocked", props); - - if (locked) { - scale2 = props.getAsDouble("scale2"); - offset2 = props.getAsDouble("offset2"); - scale3 = props.getAsDouble("scale3"); - offset3 = props.getAsDouble("offset3"); - scale4 = props.getAsDouble("scale4"); - offset4 = props.getAsDouble("offset4"); - scale6 = props.getAsDouble("scale6"); - offset6 = props.getAsDouble("offset6"); - } - - readSource(props, map); - calculate(); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleBasisFunction.java b/src/com/sudoplay/joise/module/ModuleBasisFunction.java deleted file mode 100755 index bdd93f434..000000000 --- a/src/com/sudoplay/joise/module/ModuleBasisFunction.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.generator.Xorshift128plus; -import com.sudoplay.joise.noise.Interpolator; -import com.sudoplay.joise.noise.Noise; - -public class ModuleBasisFunction extends SeedableModule { - - public enum BasisType { - VALUE, GRADIENT, GRADVAL, SIMPLEX, WHITE - } - - public enum InterpolationType { - NONE, LINEAR, CUBIC, QUINTIC - } - - protected double[] scale = new double[4]; - protected double[] offset = new double[4]; - protected double[][] rotMatrix = new double[3][3]; - protected double cos2d, sin2d; - - protected Noise.Function2D func2D; - protected Noise.Function3D func3D; - protected Noise.Function4D func4D; - protected Noise.Function6D func6D; - - protected Interpolator interpolator; - - protected BasisType basisType; - protected InterpolationType interpolationType; - - public ModuleBasisFunction() { - this(BasisType.GRADIENT, InterpolationType.QUINTIC, 10000); - } - - public ModuleBasisFunction(BasisType type) { - this(type, InterpolationType.QUINTIC, 10000); - } - - public ModuleBasisFunction(BasisType type, InterpolationType interpolationType) { - this(type, interpolationType, 10000); - } - - public ModuleBasisFunction(BasisType type, - InterpolationType interpolationType, long seed) { - setType(type); - setInterpolation(interpolationType); - setSeed(seed); - } - - public void setType(BasisType type) { - basisType = type; - switch (type) { - case GRADVAL: - func2D = Noise.Function2D.GRADVAL; - func3D = Noise.Function3D.GRADVAL; - func4D = Noise.Function4D.GRADVAL; - func6D = Noise.Function6D.GRADVAL; - break; - case SIMPLEX: - func2D = Noise.Function2D.SIMPLEX; - func3D = Noise.Function3D.SIMPLEX; - func4D = Noise.Function4D.SIMPLEX; - func6D = Noise.Function6D.SIMPLEX; - break; - case VALUE: - func2D = Noise.Function2D.VALUE; - func3D = Noise.Function3D.VALUE; - func4D = Noise.Function4D.VALUE; - func6D = Noise.Function6D.VALUE; - break; - case WHITE: - func2D = Noise.Function2D.WHITE; - func3D = Noise.Function3D.WHITE; - func4D = Noise.Function4D.WHITE; - func6D = Noise.Function6D.WHITE; - break; - case GRADIENT: - // fallthrough intentional - default: - func2D = Noise.Function2D.GRADIENT; - func3D = Noise.Function3D.GRADIENT; - func4D = Noise.Function4D.GRADIENT; - func6D = Noise.Function6D.GRADIENT; - break; - } - setMagicNumbers(type); - } - - public BasisType getBasisType() { - return basisType; - } - - public void setInterpolation(InterpolationType type) { - interpolationType = type; - switch (type) { - case CUBIC: - this.interpolator = Interpolator.HERMITE; - break; - case LINEAR: - this.interpolator = Interpolator.LINEAR; - break; - case NONE: - this.interpolator = Interpolator.NONE; - break; - default: - this.interpolator = Interpolator.QUINTIC; - break; - } - } - - public InterpolationType getInterpolationType() { - return interpolationType; - } - - /** - * Set the rotation axis and angle to use for 3D, 4D and 6D noise. - * - * @param x - * @param y - * @param z - * @param angle - */ - public void setRotationAngle(double x, double y, double z, double angle) { - double sin = Math.sin(angle); - double cos = Math.cos(angle); - - rotMatrix[0][0] = 1 + (1 - cos) * (x * x - 1); - rotMatrix[1][0] = -z * sin + (1 - cos) * x * y; - rotMatrix[2][0] = y * sin + (1 - cos) * x * z; - - rotMatrix[0][1] = z * sin + (1 - cos) * x * y; - rotMatrix[1][1] = 1 + (1 - cos) * (y * y - 1); - rotMatrix[2][1] = -x * sin + (1 - cos) * y * z; - - rotMatrix[0][2] = -y * sin + (1 - cos) * x * z; - rotMatrix[1][2] = x * sin + (1 - cos) * y * z; - rotMatrix[2][2] = 1 + (1 - cos) * (z * z - 1); - } - - @Override - public void setSeed(long seed) { - super.setSeed(seed); - - Xorshift128plus lcg = new Xorshift128plus(); - lcg.setSeed(seed); - - double ax, ay, az; - double len; - - ax = lcg.get01(); - ay = lcg.get01(); - az = lcg.get01(); - len = Math.sqrt(ax * ax + ay * ay + az * az); - ax /= len; - ay /= len; - az /= len; - setRotationAngle(ax, ay, az, lcg.get01() * 3.141592 * 2.0); - double angle = lcg.get01() * 3.141592 * 2.0; - cos2d = Math.cos(angle); - sin2d = Math.sin(angle); - } - - @Override - public double get(double x, double y) { - double nx, ny; - nx = x * cos2d - y * sin2d; - ny = y * cos2d + x * sin2d; - return func2D.get(nx, ny, seed, interpolator); - } - - @Override - public double get(double x, double y, double z) { - double nx, ny, nz; - nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z); - ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z); - nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z); - return func3D.get(nx, ny, nz, seed, interpolator); - } - - @Override - public double get(double x, double y, double z, double w) { - double nx, ny, nz; - nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z); - ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z); - nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z); - return func4D.get(nx, ny, nz, w, seed, interpolator); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double nx, ny, nz; - nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z); - ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z); - nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z); - return func6D.get(nx, ny, nz, w, u, v, seed, interpolator); - } - - protected void setMagicNumbers(BasisType type) { - switch (type) { - case VALUE: - scale[0] = 1.0; - offset[0] = 0.0; - scale[1] = 1.0; - offset[1] = 0.0; - scale[2] = 1.0; - offset[2] = 0.0; - scale[3] = 1.0; - offset[3] = 0.0; - break; - - case GRADIENT: - scale[0] = 1.86848; - offset[0] = -0.000118; - scale[1] = 1.85148; - offset[1] = -0.008272; - scale[2] = 1.64127; - offset[2] = -0.01527; - scale[3] = 1.92517; - offset[3] = 0.03393; - break; - - case GRADVAL: - scale[0] = 0.6769; - offset[0] = -0.00151; - scale[1] = 0.6957; - offset[1] = -0.133; - scale[2] = 0.74622; - offset[2] = 0.01916; - scale[3] = 0.7961; - offset[3] = -0.0352; - break; - - case WHITE: - scale[0] = 1.0; - offset[0] = 0.0; - scale[1] = 1.0; - offset[1] = 0.0; - scale[2] = 1.0; - offset[2] = 0.0; - scale[3] = 1.0; - offset[3] = 0.0; - break; - - default: - scale[0] = 1.0; - offset[0] = 0.0; - scale[1] = 1.0; - offset[1] = 0.0; - scale[2] = 1.0; - offset[2] = 0.0; - scale[3] = 1.0; - offset[3] = 0.0; - break; - } - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeEnum("basis", getBasisType(), props); - writeEnum("interpolation", getInterpolationType(), props); - writeSeed(props); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readEnum("basis", "setType", BasisType.class, props); - readEnum("interpolation", "setInterpolation", InterpolationType.class, - props); - readSeed(props); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleBias.java b/src/com/sudoplay/joise/module/ModuleBias.java deleted file mode 100755 index 128ee36d0..000000000 --- a/src/com/sudoplay/joise/module/ModuleBias.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import static com.sudoplay.joise.noise.Util.bias; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleBias extends SourcedModule { - - protected ScalarParameter bias = new ScalarParameter(0.5); - - public ModuleBias() {} - - public ModuleBias(double bias) { - this.bias.set(bias); - } - - public ModuleBias(Module bias) { - this.bias.set(bias); - } - - public void setBias(double bias) { - this.bias.set(bias); - } - - public void setBias(Module bias) { - this.bias.set(bias); - } - - @Override - public double get(double x, double y) { - double val = source.get(x, y); - return bias(bias.get(x, y), val); - } - - @Override - public double get(double x, double y, double z) { - double val = source.get(x, y, z); - return bias(bias.get(x, y, z), val); - } - - @Override - public double get(double x, double y, double z, double w) { - double val = source.get(x, y, z, w); - return bias(bias.get(x, y, z, w), val); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double val = source.get(x, y, z, w, u, v); - return bias(bias.get(x, y, z, w, u, v), val); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("bias", bias, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("bias", "setBias", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleBlend.java b/src/com/sudoplay/joise/module/ModuleBlend.java deleted file mode 100755 index 849144755..000000000 --- a/src/com/sudoplay/joise/module/ModuleBlend.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import static com.sudoplay.joise.noise.Util.lerp; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleBlend extends Module { - - protected ScalarParameter low = new ScalarParameter(0.0); - protected ScalarParameter high = new ScalarParameter(1.0); - protected ScalarParameter control = new ScalarParameter(0.5); - - public void setLowSource(Module source) { - low.set(source); - } - - public void setLowSource(double source) { - low.set(source); - } - - public void setHighSource(Module source) { - high.set(source); - } - - public void setHighSource(double source) { - high.set(source); - } - - public void setControlSource(Module source) { - control.set(source); - } - - public void setControlSource(double source) { - control.set(source); - } - - @Override - public double get(double x, double y) { - double v1 = low.get(x, y); - double v2 = high.get(x, y); - double bl = control.get(x, y); - bl = (bl + 1.0) * 0.5; - return lerp(bl, v1, v2); - } - - @Override - public double get(double x, double y, double z) { - double v1 = low.get(x, y, z); - double v2 = high.get(x, y, z); - double bl = control.get(x, y, z); - return lerp(bl, v1, v2); - } - - @Override - public double get(double x, double y, double z, double w) { - double v1 = low.get(x, y, z, w); - double v2 = high.get(x, y, z, w); - double bl = control.get(x, y, z, w); - return lerp(bl, v1, v2); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double v1 = low.get(x, y, z, w, u, v); - double v2 = high.get(x, y, z, w, u, v); - double bl = control.get(x, y, z, w, u, v); - return lerp(bl, v1, v2); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("high", high, props, map); - writeScalar("low", low, props, map); - writeScalar("control", control, props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("high", "setHighSource", props, map); - readScalar("low", "setLowSource", props, map); - readScalar("control", "setControlSource", props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleBrightContrast.java b/src/com/sudoplay/joise/module/ModuleBrightContrast.java deleted file mode 100755 index f80d975eb..000000000 --- a/src/com/sudoplay/joise/module/ModuleBrightContrast.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleBrightContrast extends SourcedModule { - - protected ScalarParameter bright = new ScalarParameter(0.0); - protected ScalarParameter threshold = new ScalarParameter(0.0); - protected ScalarParameter factor = new ScalarParameter(1.0); - - public void setBrightness(double b) { - bright.set(b); - } - - public void setBrightness(Module source) { - bright.set(source); - } - - public void setContrastThreshold(double t) { - threshold.set(t); - } - - public void setContrastThreshold(Module source) { - threshold.set(source); - } - - public void setContrastFactor(double f) { - factor.set(f); - } - - public void setContrastFactor(Module source) { - factor.set(source); - } - - @Override - public double get(double x, double y) { - double val = source.get(x, y); - // apply brightness - val += bright.get(x, y); - // subtract threshold, scale by factor, add threshold - double t = threshold.get(x, y); - val -= t; - val *= factor.get(x, y); - val += t; - return val; - } - - @Override - public double get(double x, double y, double z) { - double val = source.get(x, y, z); - // apply brightness - val += bright.get(x, y, z); - // subtract threshold, scale by factor, add threshold - double t = threshold.get(x, y, z); - val -= t; - val *= factor.get(x, y, z); - val += t; - return val; - } - - @Override - public double get(double x, double y, double z, double w) { - double val = source.get(x, y, z, w); - // apply brightness - val += bright.get(x, y, z, w); - // subtract threshold, scale by factor, add threshold - double t = threshold.get(x, y, z, w); - val -= t; - val *= factor.get(x, y, z, w); - val += t; - return val; - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double val = source.get(x, y, z, w, u, v); - // apply brightness - val += bright.get(x, y, z, w, u, v); - // subtract threshold, scale by factor, add threshold - double t = threshold.get(x, y, z, w, u, v); - val -= t; - val *= factor.get(x, y, z, w, u, v); - val += t; - return val; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("brightness", bright, props, map); - writeScalar("contrastFactor", factor, props, map); - writeScalar("contrastThreshold", threshold, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("brightness", "setBrightness", props, map); - readScalar("contrastFactor", "setContrastFactor", props, map); - readScalar("contrastThreshold", "setContrastThreshold", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleCache.java b/src/com/sudoplay/joise/module/ModuleCache.java deleted file mode 100755 index 09b187447..000000000 --- a/src/com/sudoplay/joise/module/ModuleCache.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleCache extends SourcedModule { - - class Cache { - double x, y, z, w, u, v; - double val; - boolean valid = false; - } - - protected Cache c2 = new Cache(); - protected Cache c3 = new Cache(); - protected Cache c4 = new Cache(); - protected Cache c6 = new Cache(); - - @Override - public double get(double x, double y) { - if (!c2.valid || c2.x != x || c2.y != y) { - c2.x = x; - c2.y = y; - c2.valid = true; - c2.val = source.get(x, y); - } - return c2.val; - } - - @Override - public double get(double x, double y, double z) { - if (!c3.valid || c3.x != x || c3.y != y || c3.z != z) { - c3.x = x; - c3.y = y; - c3.z = z; - c3.valid = true; - c3.val = source.get(x, y, z); - } - return c3.val; - } - - @Override - public double get(double x, double y, double z, double w) { - if (!c4.valid || c4.x != x || c4.y != y || c4.z != z || c4.w != w) { - c4.x = x; - c4.y = y; - c4.z = z; - c4.w = w; - c4.valid = true; - c4.val = source.get(x, y, z, w); - } - return c4.val; - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - if (!c6.valid || c6.x != x || c6.y != y || c6.z != z || c6.w != w - || c6.u != u || c6.v != v) { - c6.x = x; - c6.y = y; - c6.z = z; - c6.w = w; - c6.u = u; - c6.v = v; - c6.valid = true; - c6.val = source.get(x, y, z, w, u, v); - } - return c6.val; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleCellGen.java b/src/com/sudoplay/joise/module/ModuleCellGen.java deleted file mode 100755 index 8a766a8b7..000000000 --- a/src/com/sudoplay/joise/module/ModuleCellGen.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.noise.Noise; - -public class ModuleCellGen extends SeedableModule { - - private int id = Module.nextId.incrementAndGet(); - - public class CellularCache { - double[] f = new double[4]; - double[] d = new double[4]; - double x, y, z, w, u, v; - boolean valid = false; - } - - protected CellularCache c2 = new CellularCache(); - protected CellularCache c3 = new CellularCache(); - protected CellularCache c4 = new CellularCache(); - protected CellularCache c6 = new CellularCache(); - - @Override - public String getId() { - return "func_" + id; - } - - @Override - public void setSeed(long seed) { - super.setSeed(seed); - - c2.valid = false; - c3.valid = false; - c4.valid = false; - c6.valid = false; - } - - public CellularCache getCache(double x, double y) { - if (!c2.valid || c2.x != x || c2.y != y) { - Noise.cellularFunction2D(x, y, seed, c2.f, c2.d); - c2.x = x; - c2.y = y; - c2.valid = true; - } - return c2; - } - - public CellularCache getCache(double x, double y, double z) { - if (!c3.valid || c3.x != x || c3.y != y || c3.z != z) { - Noise.cellularFunction3D(x, y, z, seed, c3.f, c3.d); - c3.x = x; - c3.y = y; - c3.z = z; - c3.valid = true; - } - return c3; - } - - public CellularCache getCache(double x, double y, double z, double w) { - if (!c4.valid || c4.x != x || c4.y != y || c4.z != z || c4.w != w) { - Noise.cellularFunction4D(x, y, z, w, seed, c4.f, c4.d); - c4.x = x; - c4.y = y; - c4.z = z; - c4.w = w; - c4.valid = true; - } - return c4; - } - - public CellularCache getCache(double x, double y, double z, double w, - double u, double v) { - if (!c6.valid || c6.x != x || c6.y != y || c6.z != z || c6.w != w - || c6.u != u || c6.v != v) { - Noise.cellularFunction6D(x, y, z, w, u, v, seed, c6.f, c6.d); - c6.x = x; - c6.y = y; - c6.z = z; - c6.w = w; - c6.u = u; - c6.v = v; - c6.valid = true; - } - return c6; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeSeed(props); - - map.put(getId(), props); - - } - - @Override - public ModuleCellGen buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readSeed(props); - - return this; - } - - @Override - public double get(double x, double y) { - throw new UnsupportedOperationException(); - } - - @Override - public double get(double x, double y, double z) { - throw new UnsupportedOperationException(); - } - - @Override - public double get(double x, double y, double z, double w) { - throw new UnsupportedOperationException(); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleCellular.java b/src/com/sudoplay/joise/module/ModuleCellular.java deleted file mode 100755 index b5870a0ce..000000000 --- a/src/com/sudoplay/joise/module/ModuleCellular.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.module.ModuleCellGen.CellularCache; - -public class ModuleCellular extends Module { - - protected double[] coefficients = new double[4]; - protected ModuleCellGen generator; - - public ModuleCellular() { - setCoefficients(1, 0, 0, 0); - } - - public void setCellularSource(ModuleCellGen generator) { - this.generator = generator; - } - - public void setCoefficients(double a, double b, double c, double d) { - coefficients[0] = a; - coefficients[1] = b; - coefficients[2] = c; - coefficients[3] = d; - } - - public void setCoefficient(int index, double val) { - if (index > 3 || index < 0) { - throw new IllegalArgumentException(); - } - coefficients[index] = val; - } - - @Override - public double get(double x, double y) { - if (generator == null) { - return 0.0; - } - CellularCache c = generator.getCache(x, y); - return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2] - * coefficients[2] + c.f[3] * coefficients[3]; - } - - @Override - public double get(double x, double y, double z) { - if (generator == null) { - return 0.0; - } - CellularCache c = generator.getCache(x, y, z); - return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2] - * coefficients[2] + c.f[3] * coefficients[3]; - } - - @Override - public double get(double x, double y, double z, double w) { - if (generator == null) { - return 0.0; - } - CellularCache c = generator.getCache(x, y, z, w); - return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2] - * coefficients[2] + c.f[3] * coefficients[3]; - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - if (generator == null) { - return 0.0; - } - CellularCache c = generator.getCache(x, y, z, w, u, v); - return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2] - * coefficients[2] + c.f[3] * coefficients[3]; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - if (generator != null) { - props.put("generator", generator.getId()); - generator._writeToMap(map); - } else { - props.put("generator", 0); - } - - StringBuilder sb = new StringBuilder(); - for (double d : coefficients) { - sb.append(String.valueOf(d)).append(" "); - } - props.put("coefficients", sb.toString().trim()); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - String coeff = props.getAsString("coefficients"); - String[] arr = coeff.split(" "); - for (int i = 0; i < 4; i++) { - coefficients[i] = Double.parseDouble(arr[i]); - } - - String gen = props.getAsString("generator"); - setCellularSource((ModuleCellGen) map.get(gen)); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleClamp.java b/src/com/sudoplay/joise/module/ModuleClamp.java deleted file mode 100755 index e7beae514..000000000 --- a/src/com/sudoplay/joise/module/ModuleClamp.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import static com.sudoplay.joise.noise.Util.clamp; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleClamp extends SourcedModule { - - protected double low; - protected double high; - - public ModuleClamp() { - setRange(-1.0, 1.0); - } - - public ModuleClamp(double low, double high) { - setRange(low, high); - } - - public void setRange(double low, double high) { - this.low = low; - this.high = high; - } - - public void setLow(double low) { - this.low = low; - } - - public void setHigh(double high) { - this.high = high; - } - - @Override - public double get(double x, double y) { - return clamp(source.get(x, y), low, high); - } - - @Override - public double get(double x, double y, double z) { - return clamp(source.get(x, y, z), low, high); - } - - @Override - public double get(double x, double y, double z, double w) { - return clamp(source.get(x, y, z, w), low, high); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return clamp(source.get(x, y, z, w, u, v), low, high); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeDouble("low", low, props); - writeDouble("high", high, props); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readDouble("low", "setLow", props); - readDouble("high", "setHigh", props); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleCombiner.java b/src/com/sudoplay/joise/module/ModuleCombiner.java deleted file mode 100755 index ec0e1e1ac..000000000 --- a/src/com/sudoplay/joise/module/ModuleCombiner.java +++ /dev/null @@ -1,489 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleCombiner extends Module { - - public static enum CombinerType { - ADD, MULT, MAX, MIN, AVG - } - - protected ScalarParameter[] sources = new ScalarParameter[MAX_SOURCES]; - protected CombinerType type; - - public ModuleCombiner(CombinerType type) { - setType(type); - } - - public ModuleCombiner() { - // serialization - } - - public void setType(CombinerType type) { - this.type = type; - } - - public void setSource(int index, Module source) { - sources[index] = new ScalarParameter(source); - } - - public void setSource(int index, double source) { - sources[index] = new ScalarParameter(source); - } - - public void clearAllSources() { - for (int i = 0; i < MAX_SOURCES; i++) { - sources[i] = null; - } - } - - @Override - public double get(double x, double y) { - switch (type) { - case ADD: - return addGet(x, y); - case AVG: - return avgGet(x, y); - case MAX: - return maxGet(x, y); - case MIN: - return minGet(x, y); - case MULT: - return multGet(x, y); - default: - return 0.0; - } - } - - @Override - public double get(double x, double y, double z) { - switch (type) { - case ADD: - return addGet(x, y, z); - case AVG: - return avgGet(x, y, z); - case MAX: - return maxGet(x, y, z); - case MIN: - return minGet(x, y, z); - case MULT: - return multGet(x, y, z); - default: - return 0.0; - } - } - - @Override - public double get(double x, double y, double z, double w) { - switch (type) { - case ADD: - return addGet(x, y, z, w); - case AVG: - return avgGet(x, y, z, w); - case MAX: - return maxGet(x, y, z, w); - case MIN: - return minGet(x, y, z, w); - case MULT: - return multGet(x, y, z, w); - default: - return 0.0; - } - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - switch (type) { - case ADD: - return addGet(x, y, z, w, u, v); - case AVG: - return avgGet(x, y, z, w, u, v); - case MAX: - return maxGet(x, y, z, w, u, v); - case MIN: - return minGet(x, y, z, w, u, v); - case MULT: - return multGet(x, y, z, w, u, v); - default: - return 0.0; - } - } - - // ========================================================================== - // = ADD - // ========================================================================== - - protected double addGet(double x, double y) { - double value = 0.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value += sources[i].get(x, y); - } - return value; - } - - protected double addGet(double x, double y, double z) { - double value = 0.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value += sources[i].get(x, y, z); - } - return value; - } - - protected double addGet(double x, double y, double z, double w) { - double value = 0.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value += sources[i].get(x, y, z, w); - } - return value; - } - - protected double addGet(double x, double y, double z, double w, double u, - double v) { - double value = 0.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value += sources[i].get(x, y, z, w, u, v); - } - return value; - } - - // ========================================================================== - // = AVG - // ========================================================================== - - protected double avgGet(double x, double y) { - int count = 0; - double value = 0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) { - value += sources[i].get(x, y); - count++; - } - } - if (count == 0) return 0.0; - return value / (double) count; - } - - protected double avgGet(double x, double y, double z) { - int count = 0; - double value = 0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) { - value += sources[i].get(x, y, z); - count++; - } - } - if (count == 0) return 0.0; - return value / (double) count; - } - - protected double avgGet(double x, double y, double z, double w) { - int count = 0; - double value = 0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) { - value += sources[i].get(x, y, z, w); - count++; - } - } - if (count == 0) return 0.0; - return value / (double) count; - } - - protected double avgGet(double x, double y, double z, double w, double u, - double v) { - int count = 0; - double value = 0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) { - value += sources[i].get(x, y, z, w, u, v); - count++; - } - } - if (count == 0) return 0.0; - return value / (double) count; - } - - // ========================================================================== - // = MAX - // ========================================================================== - - protected double maxGet(double x, double y) { - double mx; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mx = sources[c].get(x, y); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y); - if (val > mx) mx = val; - } - } - - return mx; - } - - protected double maxGet(double x, double y, double z) { - double mx; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mx = sources[c].get(x, y, z); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y, z); - if (val > mx) mx = val; - } - } - - return mx; - } - - protected double maxGet(double x, double y, double z, double w) { - double mx; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mx = sources[c].get(x, y, z, w); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y, z, w); - if (val > mx) mx = val; - } - } - - return mx; - } - - protected double maxGet(double x, double y, double z, double w, double u, - double v) { - double mx; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mx = sources[c].get(x, y, z, w, u, v); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y, z, w, u, v); - if (val > mx) mx = val; - } - } - - return mx; - } - - // ========================================================================== - // = MIN - // ========================================================================== - - protected double minGet(double x, double y) { - double mn; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mn = sources[c].get(x, y); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y); - if (val < mn) mn = val; - } - } - - return mn; - } - - protected double minGet(double x, double y, double z) { - double mn; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mn = sources[c].get(x, y, z); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y, z); - if (val < mn) mn = val; - } - } - - return mn; - } - - protected double minGet(double x, double y, double z, double w) { - double mn; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mn = sources[c].get(x, y, z, w); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y, z, w); - if (val < mn) mn = val; - } - } - - return mn; - } - - protected double minGet(double x, double y, double z, double w, double u, - double v) { - double mn; - int c = 0; - while (c < MAX_SOURCES && sources[c] == null) { - c++; - } - if (c == MAX_SOURCES) return 0.0; - mn = sources[c].get(x, y, z, w, u, v); - - for (int d = c; d < MAX_SOURCES; d++) { - if (sources[d] != null) { - double val = sources[d].get(x, y, z, w, u, v); - if (val < mn) mn = val; - } - } - - return mn; - } - - // ========================================================================== - // = MULT - // ========================================================================== - - protected double multGet(double x, double y) { - double value = 1.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value *= sources[i].get(x, y); - } - return value; - } - - protected double multGet(double x, double y, double z) { - double value = 1.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value *= sources[i].get(x, y, z); - } - return value; - } - - protected double multGet(double x, double y, double z, double w) { - double value = 1.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value *= sources[i].get(x, y, z, w); - } - return value; - } - - protected double multGet(double x, double y, double z, double w, double u, - double v) { - double value = 1.0; - for (int i = 0; i < MAX_SOURCES; i++) { - if (sources[i] != null) value *= sources[i].get(x, y, z, w, u, v); - } - return value; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeEnum("type", type, props); - - for (int i = 0; i < MAX_SOURCES; i++) { - writeScalar("source" + i, sources[i], props, map); - } - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readEnum("type", "setType", CombinerType.class, props); - - String name; - Object o; - for (int i = 0; i < MAX_SOURCES; i++) { - o = props.get("source" + i); - if (o != null) { - name = o.toString(); - setSource(i, map.get(name)); - } - } - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleCos.java b/src/com/sudoplay/joise/module/ModuleCos.java deleted file mode 100755 index d0fbe8ee5..000000000 --- a/src/com/sudoplay/joise/module/ModuleCos.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleCos extends SourcedModule { - - @Override - public double get(double x, double y) { - return Math.cos(source.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return Math.cos(source.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return Math.cos(source.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return Math.cos(source.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleFloor.java b/src/com/sudoplay/joise/module/ModuleFloor.java deleted file mode 100755 index e463749d7..000000000 --- a/src/com/sudoplay/joise/module/ModuleFloor.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleFloor extends SourcedModule { - - @Override - public double get(double x, double y) { - return Math.floor(source.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return Math.floor(source.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return Math.floor(source.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return Math.floor(source.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleFractal.java b/src/com/sudoplay/joise/module/ModuleFractal.java deleted file mode 100755 index 41c841999..000000000 --- a/src/com/sudoplay/joise/module/ModuleFractal.java +++ /dev/null @@ -1,1035 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.module.ModuleBasisFunction.BasisType; -import com.sudoplay.joise.module.ModuleBasisFunction.InterpolationType; -import com.sudoplay.joise.noise.Util; - -public class ModuleFractal extends SeedableModule { - - public static final FractalType DEFAULT_FRACTAL_TYPE = FractalType.FBM; - public static final BasisType DEFAULT_BASIS_TYPE = BasisType.GRADVAL; - public static final InterpolationType DEFAULT_INTERPOLATION_TYPE = InterpolationType.QUINTIC; - public static final int DEFAULT_OCTAVES = 2; - public static final double DEFAULT_FREQUENCY = 1.0; - public static final double DEFAULT_LACUNARITY = 2.0; - - public static enum FractalType { - FBM, RIDGEMULTI, BILLOW, MULTI, HYBRIDMULTI, DECARPENTIERSWISS - } - - protected ModuleBasisFunction[] basis = new ModuleBasisFunction[MAX_SOURCES]; - protected Module[] source = new Module[MAX_SOURCES]; - - protected double[] exparray = new double[MAX_SOURCES]; - protected double[][] correct = new double[MAX_SOURCES][2]; - - protected double offset, gain, H; - protected double frequency, lacunarity; - protected int numOctaves; - protected FractalType type; - - public ModuleFractal() { - this(DEFAULT_FRACTAL_TYPE, DEFAULT_BASIS_TYPE, DEFAULT_INTERPOLATION_TYPE); - } - - public ModuleFractal(FractalType type, BasisType basisType, - InterpolationType interpolationType) { - for (int i = 0; i < MAX_SOURCES; i++) { - basis[i] = new ModuleBasisFunction(); - } - setNumOctaves(2); - setFrequency(1.0); - setLacunarity(2.0); - setType(type); - setAllSourceTypes(basisType, interpolationType); - resetAllSources(); - } - - public void setNumOctaves(long n) { - if (n > MAX_SOURCES) { - throw new IllegalArgumentException("number of octaves must be <= " - + MAX_SOURCES); - } - numOctaves = (int) n; - } - - public void setFrequency(double f) { - frequency = f; - } - - public void setLacunarity(double l) { - lacunarity = l; - } - - public void setGain(double g) { - gain = g; - } - - public void setOffset(double o) { - offset = o; - } - - public void setH(double h) { - H = h; - } - - public void setType(FractalType type) { - this.type = type; - switch (type) { - case BILLOW: - H = 1.0; - gain = 0.5; - offset = 0.0; - break; - case DECARPENTIERSWISS: - H = 0.9; - gain = 1.0; - offset = 0.7; - break; - case FBM: - H = 1.0; - gain = 0.5; - offset = 0.0; - break; - case HYBRIDMULTI: - H = 0.25; - gain = 1.0; - offset = 0.7; - break; - case MULTI: - H = 1.0; - gain = 0.0; - offset = 0.0; - break; - case RIDGEMULTI: - H = 0.9; - gain = 0.5; - offset = 1.0; - break; - default: - throw new AssertionError(); - } - calcWeights(type); - } - - public void setAllSourceTypes(BasisType basisType, - InterpolationType interpolationType) { - for (int i = 0; i < MAX_SOURCES; i++) { - basis[i].setType(basisType); - basis[i].setInterpolation(interpolationType); - } - } - - public void setAllSourceBasisTypes(BasisType basisType) { - for (int i = 0; i < MAX_SOURCES; i++) { - basis[i].setType(basisType); - } - } - - public void setAllSourceInterpolationTypes(InterpolationType interpolationType) { - for (int i = 0; i < MAX_SOURCES; i++) { - basis[i].setInterpolation(interpolationType); - } - } - - public void setSourceType(int index, BasisType basisType, - InterpolationType interpolationType) { - assertMaxSources(index); - basis[index].setType(basisType); - basis[index].setInterpolation(interpolationType); - } - - public void overrideSource(int index, Module source) { - if (index < 0 || index >= MAX_SOURCES) { - throw new IllegalArgumentException("expecting index < " + MAX_SOURCES - + " but was " + index); - } - this.source[index] = source; - } - - public void resetSource(int index) { - assertMaxSources(index); - source[index] = basis[index]; - } - - public void resetAllSources() { - for (int i = 0; i < MAX_SOURCES; i++) { - source[i] = basis[i]; - } - } - - @Override - public void setSeed(long seed) { - super.setSeed(seed); - for (int i = 0; i < MAX_SOURCES; i++) { - if (source[i] instanceof SeedableModule) { - ((SeedableModule) source[i]).setSeed(seed); - } - } - } - - public ModuleBasisFunction getBasis(int index) { - assertMaxSources(index); - return basis[index]; - } - - @Override - public double get(double x, double y) { - switch (type) { - case BILLOW: - return getBillow(x, y); - case DECARPENTIERSWISS: - return getDeCarpentierSwiss(x, y); - case FBM: - return getFBM(x, y); - case HYBRIDMULTI: - return getHybridMulti(x, y); - case MULTI: - return getMulti(x, y); - case RIDGEMULTI: - return getRidgedMulti(x, y); - default: - throw new AssertionError(); - } - } - - @Override - public double get(double x, double y, double z) { - switch (type) { - case BILLOW: - return getBillow(x, y, z); - case DECARPENTIERSWISS: - return getDeCarpentierSwiss(x, y, z); - case FBM: - return getFBM(x, y, z); - case HYBRIDMULTI: - return getHybridMulti(x, y, z); - case MULTI: - return getMulti(x, y, z); - case RIDGEMULTI: - return getRidgedMulti(x, y, z); - default: - throw new AssertionError(); - } - } - - @Override - public double get(double x, double y, double z, double w) { - switch (type) { - case BILLOW: - return getBillow(x, y, z, w); - case DECARPENTIERSWISS: - return getDeCarpentierSwiss(x, y, z, w); - case FBM: - return getFBM(x, y, z, w); - case HYBRIDMULTI: - return getHybridMulti(x, y, z, w); - case MULTI: - return getMulti(x, y, z, w); - case RIDGEMULTI: - return getRidgedMulti(x, y, z, w); - default: - throw new AssertionError(); - } - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - switch (type) { - case BILLOW: - return getBillow(x, y, z, w, u, v); - case DECARPENTIERSWISS: - return getDeCarpentierSwiss(x, y, z, w, u, v); - case FBM: - return getFBM(x, y, z, w, u, v); - case HYBRIDMULTI: - return getHybridMulti(x, y, z, w, u, v); - case MULTI: - return getMulti(x, y, z, w, u, v); - case RIDGEMULTI: - return getRidgedMulti(x, y, z, w, u, v); - default: - throw new AssertionError(); - } - } - - protected double getFBM(double x, double y) { - double sum = 0; - double amp = 1.0; - - x *= frequency; - y *= frequency; - - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y); - sum += n * amp; - amp *= gain; - - x *= lacunarity; - y *= lacunarity; - } - return sum; - } - - protected double getFBM(double x, double y, double z) { - double sum = 0; - double amp = 1.0; - - x *= frequency; - y *= frequency; - z *= frequency; - - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y, z); - sum += n * amp; - amp *= gain; - - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - } - return sum; - } - - protected double getFBM(double x, double y, double z, double w) { - double sum = 0; - double amp = 1.0; - - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y, z, w); - sum += n * amp; - amp *= gain; - - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - } - return sum; - } - - protected double getFBM(double x, double y, double z, double w, double u, - double v) { - double sum = 0; - double amp = 1.0; - - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - u *= frequency; - v *= frequency; - - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y, z, w); - sum += n * amp; - amp *= gain; - - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - u *= lacunarity; - v *= lacunarity; - } - return sum; - } - - protected double getMulti(double x, double y) { - double value = 1.0; - x *= frequency; - y *= frequency; - for (int i = 0; i < numOctaves; ++i) { - value *= source[i].get(x, y) * exparray[i] + 1.0; - x *= lacunarity; - y *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getMulti(double x, double y, double z) { - double value = 1.0; - x *= frequency; - y *= frequency; - z *= frequency; - for (int i = 0; i < numOctaves; ++i) { - value *= source[i].get(x, y, z) * exparray[i] + 1.0; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getMulti(double x, double y, double z, double w) { - double value = 1.0; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - for (int i = 0; i < numOctaves; ++i) { - value *= source[i].get(x, y, z, w) * exparray[i] + 1.0; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getMulti(double x, double y, double z, double w, double u, - double v) { - double value = 1.0; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - u *= frequency; - v *= frequency; - for (int i = 0; i < numOctaves; ++i) { - value *= source[i].get(x, y, z, w, u, v) * exparray[i] + 1.0; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - u *= lacunarity; - v *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getBillow(double x, double y) { - double sum = 0.0; - double amp = 1.0; - - x *= frequency; - y *= frequency; - - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y); - sum += (2.0 * Math.abs(n) - 1.0) * amp; - amp *= gain; - - x *= lacunarity; - y *= lacunarity; - } - return sum; - } - - protected double getBillow(double x, double y, double z) { - double sum = 0.0; - double amp = 1.0; - x *= frequency; - y *= frequency; - z *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y, z); - sum += (2.0 * Math.abs(n) - 1.0) * amp; - amp *= gain; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - } - return sum; - } - - protected double getBillow(double x, double y, double z, double w) { - double sum = 0.0; - double amp = 1.0; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y, z, w); - sum += (2.0 * Math.abs(n) - 1.0) * amp; - amp *= gain; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - } - return sum; - } - - protected double getBillow(double x, double y, double z, double w, double u, - double v) { - double sum = 0.0; - double amp = 1.0; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - u *= frequency; - v *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y, z, w, u, v); - sum += (2.0 * Math.abs(n) - 1.0) * amp; - amp *= gain; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - u *= lacunarity; - v *= lacunarity; - } - return sum; - } - - protected double getRidgedMulti(double x, double y) { - double sum = 0; - double amp = 1.0; - x *= frequency; - y *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y); - n = 1.0 - Math.abs(n); - sum += amp * n; - amp *= gain; - x *= lacunarity; - y *= lacunarity; - } - return sum; - } - - protected double getRidgedMulti(double x, double y, double z) { - double sum = 0; - double amp = 1.0; - x *= frequency; - y *= frequency; - z *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x, y, z); - n = 1.0 - Math.abs(n); - sum += amp * n; - amp *= gain; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - } - return sum; - } - - protected double getRidgedMulti(double x, double y, double z, double w) { - double result = 0.0, signal; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - for (int i = 0; i < numOctaves; ++i) { - signal = source[i].get(x, y, z, w); - signal = offset - Math.abs(signal); - signal *= signal; - result += signal * exparray[i]; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - } - return result * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getRidgedMulti(double x, double y, double z, double w, - double u, double v) { - double result = 0.0, signal; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - u *= frequency; - v *= frequency; - for (int i = 0; i < numOctaves; ++i) { - signal = source[i].get(x, y, z, w, u, v); - signal = offset - Math.abs(signal); - signal *= signal; - result += signal * exparray[i]; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - u *= lacunarity; - v *= lacunarity; - } - return result * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getHybridMulti(double x, double y) { - double value, signal, weight; - x *= frequency; - y *= frequency; - value = source[0].get(x, y) + offset; - weight = gain * value; - x *= lacunarity; - y *= lacunarity; - for (int i = 1; i < numOctaves; ++i) { - if (weight > 1.0) weight = 1.0; - signal = (source[i].get(x, y) + offset) * exparray[i]; - value += weight * signal; - weight *= gain * signal; - x *= lacunarity; - y *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getHybridMulti(double x, double y, double z) { - double value, signal, weight; - x *= frequency; - y *= frequency; - z *= frequency; - value = source[0].get(x, y, z) + offset; - weight = gain * value; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - for (int i = 1; i < numOctaves; ++i) { - if (weight > 1.0) weight = 1.0; - signal = (source[i].get(x, y, z) + offset) * exparray[i]; - value += weight * signal; - weight *= gain * signal; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getHybridMulti(double x, double y, double z, double w) { - double value, signal, weight; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - value = source[0].get(x, y, z, w) + offset; - weight = gain * value; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - for (int i = 1; i < numOctaves; ++i) { - if (weight > 1.0) weight = 1.0; - signal = (source[i].get(x, y, z, w) + offset) * exparray[i]; - value += weight * signal; - weight *= gain * signal; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getHybridMulti(double x, double y, double z, double w, - double u, double v) { - double value, signal, weight; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - u *= frequency; - v *= frequency; - value = source[0].get(x, y, z, w, u, v) + offset; - weight = gain * value; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - u *= lacunarity; - v *= lacunarity; - for (int i = 1; i < numOctaves; ++i) { - if (weight > 1.0) weight = 1.0; - signal = (source[i].get(x, y, z, w, u, v) + offset) * exparray[i]; - value += weight * signal; - weight *= gain * signal; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - u *= lacunarity; - v *= lacunarity; - } - return value * correct[numOctaves - 1][0] + correct[numOctaves - 1][1]; - } - - protected double getDeCarpentierSwiss(double x, double y) { - double sum = 0; - double amp = 1.0; - double dx_sum = 0; - double dy_sum = 0; - x *= frequency; - y *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum); - double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum); - double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum); - sum += amp * (1.0 - Math.abs(n)); - dx_sum += amp * dx * -n; - dy_sum += amp * dy * -n; - amp *= gain * Util.clamp(sum, 0.0, 1.0); - x *= lacunarity; - y *= lacunarity; - } - return sum; - } - - protected double getDeCarpentierSwiss(double x, double y, double z) { - double sum = 0; - double amp = 1.0; - double dx_sum = 0; - double dy_sum = 0; - double dz_sum = 0; - x *= frequency; - y *= frequency; - z *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum); - double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum); - double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum); - double dz = source[i].getDZ(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum); - sum += amp * (1.0 - Math.abs(n)); - dx_sum += amp * dx * -n; - dy_sum += amp * dy * -n; - dz_sum += amp * dz * -n; - amp *= gain * Util.clamp(sum, 0.0, 1.0); - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - } - return sum; - } - - protected double getDeCarpentierSwiss(double x, double y, double z, double w) { - double sum = 0; - double amp = 1.0; - double dx_sum = 0; - double dy_sum = 0; - double dz_sum = 0; - double dw_sum = 0; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum); - double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum); - double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum); - double dz = source[i].getDZ(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum); - double dw = source[i].getDW(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum); - sum += amp * (1.0 - Math.abs(n)); - dx_sum += amp * dx * -n; - dy_sum += amp * dy * -n; - dz_sum += amp * dz * -n; - dw_sum += amp * dw * -n; - amp *= gain * Util.clamp(sum, 0.0, 1.0); - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - } - return sum; - } - - protected double getDeCarpentierSwiss(double x, double y, double z, double w, - double u, double v) { - double sum = 0; - double amp = 1.0; - double dx_sum = 0; - double dy_sum = 0; - double dz_sum = 0; - double dw_sum = 0; - double du_sum = 0; - double dv_sum = 0; - x *= frequency; - y *= frequency; - z *= frequency; - w *= frequency; - u *= frequency; - v *= frequency; - for (int i = 0; i < numOctaves; ++i) { - double n = source[i].get(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum); - double dx = source[i].getDX(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dx_sum, w + offset * dw_sum, u + offset * du_sum, v - + offset * dv_sum); - double dy = source[i].getDY(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v - + offset * dv_sum); - double dz = source[i].getDZ(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v - + offset * dv_sum); - double dw = source[i].getDW(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v - + offset * dv_sum); - double du = source[i].getDU(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v - + offset * dv_sum); - double dv = source[i].getDV(x + offset * dx_sum, y + offset * dy_sum, z - + offset * dz_sum, w + offset * dw_sum, u + offset * du_sum, v - + offset * dv_sum); - sum += amp * (1.0 - Math.abs(n)); - dx_sum += amp * dx * -n; - dy_sum += amp * dy * -n; - dz_sum += amp * dz * -n; - dw_sum += amp * dw * -n; - du_sum += amp * du * -n; - dv_sum += amp * dv * -n; - amp *= gain * Util.clamp(sum, 0.0, 1.0); - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - u *= lacunarity; - v *= lacunarity; - } - return sum; - } - - protected void calcWeights(FractalType type) { - double minvalue, maxvalue; - switch (type) { - case FBM: - for (int i = 0; i < MAX_SOURCES; i++) { - exparray[i] = Math.pow(lacunarity, -i * H); - } - minvalue = 0.0; - maxvalue = 0.0; - for (int i = 0; i < MAX_SOURCES; i++) { - minvalue += -1.0 * exparray[i]; - maxvalue += 1.0 * exparray[i]; - - double A = -1.0, B = 1.0; - double scale = (B - A) / (maxvalue - minvalue); - double bias = A - minvalue * scale; - correct[i][0] = scale; - correct[i][1] = bias; - } - break; - - case RIDGEMULTI: - for (int i = 0; i < MAX_SOURCES; ++i) { - exparray[i] = Math.pow(lacunarity, -i * H); - } - minvalue = 0.0; - maxvalue = 0.0; - for (int i = 0; i < MAX_SOURCES; ++i) { - minvalue += (offset - 1.0) * (offset - 1.0) * exparray[i]; - maxvalue += (offset) * (offset) * exparray[i]; - - double A = -1.0, B = 1.0; - double scale = (B - A) / (maxvalue - minvalue); - double bias = A - minvalue * scale; - correct[i][0] = scale; - correct[i][1] = bias; - } - break; - - case DECARPENTIERSWISS: - for (int i = 0; i < MAX_SOURCES; ++i) { - exparray[i] = Math.pow(lacunarity, -i * H); - } - minvalue = 0.0; - maxvalue = 0.0; - for (int i = 0; i < MAX_SOURCES; ++i) { - minvalue += (offset - 1.0) * (offset - 1.0) * exparray[i]; - maxvalue += (offset) * (offset) * exparray[i]; - - double A = -1.0, B = 1.0; - double scale = (B - A) / (maxvalue - minvalue); - double bias = A - minvalue * scale; - correct[i][0] = scale; - correct[i][1] = bias; - } - break; - - case BILLOW: - for (int i = 0; i < MAX_SOURCES; ++i) { - exparray[i] = Math.pow(lacunarity, -i * H); - } - minvalue = 0.0; - maxvalue = 0.0; - for (int i = 0; i < MAX_SOURCES; ++i) { - minvalue += -1.0 * exparray[i]; - maxvalue += 1.0 * exparray[i]; - - double A = -1.0, B = 1.0; - double scale = (B - A) / (maxvalue - minvalue); - double bias = A - minvalue * scale; - correct[i][0] = scale; - correct[i][1] = bias; - } - break; - - case MULTI: - for (int i = 0; i < MAX_SOURCES; ++i) { - exparray[i] = Math.pow(lacunarity, -i * H); - } - minvalue = 1.0; - maxvalue = 1.0; - for (int i = 0; i < MAX_SOURCES; ++i) { - minvalue *= -1.0 * exparray[i] + 1.0; - maxvalue *= 1.0 * exparray[i] + 1.0; - - double A = -1.0, B = 1.0; - double scale = (B - A) / (maxvalue - minvalue); - double bias = A - minvalue * scale; - correct[i][0] = scale; - correct[i][1] = bias; - } - break; - - case HYBRIDMULTI: - for (int i = 0; i < MAX_SOURCES; ++i) { - exparray[i] = Math.pow(lacunarity, -i * H); - } - minvalue = 1.0; - maxvalue = 1.0; - double weightmin, - weightmax; - double A = -1.0, - B = 1.0, - scale, - bias; - - minvalue = offset - 1.0; - maxvalue = offset + 1.0; - weightmin = gain * minvalue; - weightmax = gain * maxvalue; - - scale = (B - A) / (maxvalue - minvalue); - bias = A - minvalue * scale; - correct[0][0] = scale; - correct[0][1] = bias; - - for (int i = 1; i < MAX_SOURCES; ++i) { - if (weightmin > 1.0) weightmin = 1.0; - if (weightmax > 1.0) weightmax = 1.0; - - double signal = (offset - 1.0) * exparray[i]; - minvalue += signal * weightmin; - weightmin *= gain * signal; - - signal = (offset + 1.0) * exparray[i]; - maxvalue += signal * weightmax; - weightmax *= gain * signal; - - scale = (B - A) / (maxvalue - minvalue); - bias = A - minvalue * scale; - correct[i][0] = scale; - correct[i][1] = bias; - } - break; - } - - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeEnum("type", type, props); - writeLong("octaves", numOctaves, props); - writeDouble("frequency", frequency, props); - writeDouble("lacunarity", lacunarity, props); - writeDouble("gain", gain, props); - writeDouble("H", H, props); - writeDouble("offset", offset, props); - for (int i = 0; i < numOctaves; i++) { - props.put("source_" + i, source[i].getId()); - source[i]._writeToMap(map); - } - - writeSeed(props); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readEnum("type", "setType", FractalType.class, props); - readLong("octaves", "setNumOctaves", props); - readDouble("frequency", "setFrequency", props); - readDouble("lacunarity", "setLacunarity", props); - readDouble("gain", "setGain", props); - readDouble("H", "setH", props); - readDouble("offset", "setOffset", props); - - readSeed(props); - - // must override sources after seed has been set - for (int i = 0; i < numOctaves; i++) { - overrideSource(i, map.get(props.get("source_" + i))); - } - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleFunctionGradient.java b/src/com/sudoplay/joise/module/ModuleFunctionGradient.java deleted file mode 100755 index 237c23d9f..000000000 --- a/src/com/sudoplay/joise/module/ModuleFunctionGradient.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleFunctionGradient extends SourcedModule { - - public static final double DEFAULT_SPACING = 0.01; - - public static enum FunctionGradientAxis { - X_AXIS, Y_AXIS, Z_AXIS, W_AXIS, U_AXIS, V_AXIS - } - - protected FunctionGradientAxis axis; - protected double spacing; - protected double invSpacing; - - public ModuleFunctionGradient() { - setAxis(FunctionGradientAxis.X_AXIS); - setSpacing(DEFAULT_SPACING); - } - - public void setAxis(FunctionGradientAxis axis) { - this.axis = axis; - } - - public void setSpacing(double s) { - spacing = s; - invSpacing = 1.0 / spacing; - } - - @Override - public double get(double x, double y) { - switch (axis) { - case X_AXIS: - return (source.get(x - spacing, y) - source.get(x + spacing, y)) - * invSpacing; - case Y_AXIS: - return (source.get(x, y - spacing) - source.get(x, y + spacing)) - * invSpacing; - case Z_AXIS: - return 0.0; - case W_AXIS: - return 0.0; - case U_AXIS: - return 0.0; - case V_AXIS: - return 0.0; - } - return 0.0; - } - - @Override - public double get(double x, double y, double z) { - switch (axis) { - case X_AXIS: - return (source.get(x - spacing, y, z) - source.get(x + spacing, y, z)) - * invSpacing; - case Y_AXIS: - return (source.get(x, y - spacing, z) - source.get(x, y + spacing, z)) - * invSpacing; - case Z_AXIS: - return (source.get(x, y, z - spacing) - source.get(x, y, z + spacing)) - * invSpacing; - case W_AXIS: - return 0.0; - case U_AXIS: - return 0.0; - case V_AXIS: - return 0.0; - } - return 0.0; - } - - @Override - public double get(double x, double y, double z, double w) { - switch (axis) { - case X_AXIS: - return (source.get(x - spacing, y, z, w) - source.get(x + spacing, y, z, - w)) * invSpacing; - - case Y_AXIS: - return (source.get(x, y - spacing, z, w) - source.get(x, y + spacing, z, - w)) * invSpacing; - - case Z_AXIS: - return (source.get(x, y, z - spacing, w) - source.get(x, y, z + spacing, - w)) * invSpacing; - - case W_AXIS: - return (source.get(x, y, z, w - spacing) - source.get(x, y, z, w - + spacing)) - * invSpacing; - case U_AXIS: - return 0.0; - case V_AXIS: - return 0.0; - } - return 0.0; - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - switch (axis) { - case X_AXIS: - return (source.get(x - spacing, y, z, w, u, v) - source.get(x + spacing, - y, z, w, u, v)) * invSpacing; - - case Y_AXIS: - return (source.get(x, y - spacing, z, w, u, v) - source.get(x, y - + spacing, z, w, u, v)) - * invSpacing; - case Z_AXIS: - return (source.get(x, y, z - spacing, w, u, v) - source.get(x, y, z - + spacing, w, u, v)) - * invSpacing; - case W_AXIS: - return (source.get(x, y, z, w - spacing, u, v) - source.get(x, y, z, w - + spacing, u, v)) - * invSpacing; - case U_AXIS: - return (source.get(x, y, z, w, u - spacing, v) - source.get(x, y, z, w, u - + spacing, v)) - * invSpacing; - case V_AXIS: - return (source.get(x, y, z, w, u, v - spacing) - source.get(x, y, z, w, - u, v + spacing)) * invSpacing; - - } - return 0.0; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeEnum("axis", axis, props); - writeDouble("spacing", spacing, props); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readEnum("axis", "setAxis", FunctionGradientAxis.class, props); - readDouble("spacing", "setSpacing", props); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleGain.java b/src/com/sudoplay/joise/module/ModuleGain.java deleted file mode 100755 index 74ad975c4..000000000 --- a/src/com/sudoplay/joise/module/ModuleGain.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.noise.Util; - -public class ModuleGain extends SourcedModule { - - public static final double DEFAULT_GAIN = 0.5; - - protected ScalarParameter gain = new ScalarParameter(DEFAULT_GAIN); - - public ModuleGain() { - setGain(DEFAULT_GAIN); - } - - public ModuleGain(double gain) { - setGain(gain); - } - - public void setGain(double gain) { - this.gain.set(gain); - } - - public void setGain(Module gain) { - this.gain.set(gain); - } - - @Override - public double get(double x, double y) { - return Util.gain(gain.get(x, y), source.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return Util.gain(gain.get(x, y, z), source.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return Util.gain(gain.get(x, y, z, w), source.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return Util.gain(gain.get(x, y, z, w, u, v), source.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("gain", gain, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("gain", "setGain", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleGradient.java b/src/com/sudoplay/joise/module/ModuleGradient.java deleted file mode 100755 index fea7268cb..000000000 --- a/src/com/sudoplay/joise/module/ModuleGradient.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleGradient extends Module { - - public static final double DEFAULT_X1 = 0.0; - public static final double DEFAULT_X2 = 1.0; - public static final double DEFAULT_Y1 = 0.0; - public static final double DEFAULT_Y2 = 1.0; - public static final double DEFAULT_Z1 = 0.0; - public static final double DEFAULT_Z2 = 0.0; - public static final double DEFAULT_W1 = 0.0; - public static final double DEFAULT_W2 = 0.0; - public static final double DEFAULT_U1 = 0.0; - public static final double DEFAULT_U2 = 0.0; - public static final double DEFAULT_V1 = 0.0; - public static final double DEFAULT_V2 = 0.0; - - protected double gx1, gx2, gy1, gy2, gz1, gz2, gw1, gw2, gu1, gu2, gv1, gv2; - protected double x, y, z, w, u, v; - protected double vlen; - - public ModuleGradient() { - setGradient(DEFAULT_X1, DEFAULT_X2, DEFAULT_Y1, DEFAULT_Y2, DEFAULT_Z1, - DEFAULT_Z2, DEFAULT_W1, DEFAULT_W2, DEFAULT_U1, DEFAULT_U2, DEFAULT_V1, - DEFAULT_V2); - } - - public void setGradient(double x1, double x2, double y1, double y2) { - setGradient(x1, x2, y1, y2, 0, 0, 0, 0, 0, 0, 0, 0); - } - - public void setGradient(double x1, double x2, double y1, double y2, - double z1, double z2) { - setGradient(x1, x2, y1, y2, z1, z2, 0, 0, 0, 0, 0, 0); - } - - public void setGradient(double x1, double x2, double y1, double y2, - double z1, double z2, double w1, double w2) { - setGradient(x1, x2, y1, y2, z1, z2, w1, w2, 0, 0, 0, 0); - } - - public void setGradient(double x1, double x2, double y1, double y2, - double z1, double z2, double w1, double w2, double u1, double u2, - double v1, double v2) { - gx1 = x1; - gx2 = x2; - gy1 = y1; - gy2 = y2; - gz1 = z1; - gz2 = z2; - gw1 = w1; - gw2 = w2; - gu1 = u1; - gu2 = u2; - gv1 = v1; - gv2 = v2; - - x = x2 - x1; - y = y2 - y1; - z = z2 - z1; - w = w2 - w1; - u = u2 - u1; - v = v2 - v1; - - vlen = (x * x + y * y + z * z + w * w + u * u + v * v); - } - - @Override - public double get(double x, double y) { - double dx = x - gx1; - double dy = y - gy1; - double dp = dx * this.x + dy * this.y; - dp /= vlen; - return dp; - } - - @Override - public double get(double x, double y, double z) { - double dx = x - gx1; - double dy = y - gy1; - double dz = z - gz1; - double dp = dx * this.x + dy * this.y + dz * this.z; - dp /= vlen; - return dp; - } - - @Override - public double get(double x, double y, double z, double w) { - double dx = x - gx1; - double dy = y - gy1; - double dz = z - gz1; - double dw = w - gw1; - double dp = dx * this.x + dy * this.y + dz * this.z + dw * this.w; - dp /= vlen; - return dp; - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double dx = x - gx1; - double dy = y - gy1; - double dz = z - gz1; - double dw = w - gw1; - double du = u - gu1; - double dv = v - gv1; - double dp = dx * this.x + dy * this.y + dz * this.z + dw * this.w + du - * this.u + dv * this.v; - dp /= vlen; - return dp; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - StringBuffer sb = new StringBuffer(); - sb.append(gx1).append(" "); - sb.append(gx2).append(" "); - sb.append(gy1).append(" "); - sb.append(gy2).append(" "); - sb.append(gz1).append(" "); - sb.append(gz2).append(" "); - sb.append(gw1).append(" "); - sb.append(gw2).append(" "); - sb.append(gu1).append(" "); - sb.append(gu2).append(" "); - sb.append(gv1).append(" "); - sb.append(gv2); - props.put("gradient", sb.toString()); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - String buf = props.getAsString("gradient"); - String[] arr = buf.split(" "); - double[] d = new double[12]; - for (int i = 0; i < 12; i++) { - d[i] = Double.parseDouble(arr[i]); - } - setGradient(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], - d[10], d[11]); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleInvert.java b/src/com/sudoplay/joise/module/ModuleInvert.java deleted file mode 100755 index 2d97d8287..000000000 --- a/src/com/sudoplay/joise/module/ModuleInvert.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleInvert extends SourcedModule { - - @Override - public double get(double x, double y) { - return -source.get(x, y); - } - - @Override - public double get(double x, double y, double z) { - return -source.get(x, y, z); - } - - @Override - public double get(double x, double y, double z, double w) { - return -source.get(x, y, z, w); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return -source.get(x, y, z, w, u, v); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleMagnitude.java b/src/com/sudoplay/joise/module/ModuleMagnitude.java deleted file mode 100755 index 54d14952d..000000000 --- a/src/com/sudoplay/joise/module/ModuleMagnitude.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleMagnitude extends Module { - - protected ScalarParameter sX = new ScalarParameter(0); - protected ScalarParameter sY = new ScalarParameter(0); - protected ScalarParameter sZ = new ScalarParameter(0); - protected ScalarParameter sW = new ScalarParameter(0); - protected ScalarParameter sU = new ScalarParameter(0); - protected ScalarParameter sV = new ScalarParameter(0); - - public void setX(double source) { - sX.set(source); - } - - public void setY(double source) { - sY.set(source); - } - - public void setZ(double source) { - sZ.set(source); - } - - public void setW(double source) { - sW.set(source); - } - - public void setU(double source) { - sU.set(source); - } - - public void setV(double source) { - sV.set(source); - } - - public void setX(Module source) { - sX.set(source); - } - - public void setY(Module source) { - sY.set(source); - } - - public void setZ(Module source) { - sZ.set(source); - } - - public void setW(Module source) { - sW.set(source); - } - - public void setU(Module source) { - sU.set(source); - } - - public void setV(Module source) { - sV.set(source); - } - - @Override - public double get(double x, double y) { - double xx = sX.get(x, y); - double yy = sY.get(x, y); - return Math.sqrt(xx * xx + yy * yy); - } - - @Override - public double get(double x, double y, double z) { - double xx = sX.get(x, y, z); - double yy = sY.get(x, y, z); - double zz = sZ.get(x, y, z); - return Math.sqrt(xx * xx + yy * yy + zz * zz); - } - - @Override - public double get(double x, double y, double z, double w) { - double xx = sX.get(x, y, z, w); - double yy = sY.get(x, y, z, w); - double zz = sZ.get(x, y, z, w); - double ww = sW.get(x, y, z, w); - return Math.sqrt(xx * xx + yy * yy + zz * zz + ww * ww); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double xx = sX.get(x, y, z, w, u, v); - double yy = sY.get(x, y, z, w, u, v); - double zz = sZ.get(x, y, z, w, u, v); - double ww = sW.get(x, y, z, w, u, v); - double uu = sU.get(x, y, z, w, u, v); - double vv = sV.get(x, y, z, w, u, v); - return Math.sqrt(xx * xx + yy * yy + zz * zz + ww * ww + uu * uu + vv * vv); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("X", sX, props, map); - writeScalar("Y", sY, props, map); - writeScalar("Z", sZ, props, map); - writeScalar("W", sW, props, map); - writeScalar("U", sU, props, map); - writeScalar("V", sV, props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("X", "setX", props, map); - readScalar("Y", "setY", props, map); - readScalar("Z", "setZ", props, map); - readScalar("W", "setW", props, map); - readScalar("U", "setU", props, map); - readScalar("V", "setV", props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleNormalizedCoords.java b/src/com/sudoplay/joise/module/ModuleNormalizedCoords.java deleted file mode 100755 index 48f847bc2..000000000 --- a/src/com/sudoplay/joise/module/ModuleNormalizedCoords.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleNormalizedCoords extends SourcedModule { - - public static final double DEFAULT_LENGTH = 1.0; - - protected ScalarParameter length = new ScalarParameter(DEFAULT_LENGTH); - - public ModuleNormalizedCoords() { - this(DEFAULT_LENGTH); - } - - public ModuleNormalizedCoords(double length) { - setLength(length); - } - - public void setLength(double source) { - length.set(source); - } - - public void setLength(Module source) { - length.set(source); - } - - @Override - public double get(double x, double y) { - if (x == 0 && y == 0) return source.get(x, y); - - double len = Math.sqrt(x * x + y * y); - double r = length.get(x, y); - return source.get(x / len * r, y / len * r); - } - - @Override - public double get(double x, double y, double z) { - if (x == 0 && y == 0 && z == 0) return source.get(x, y, z); - - double len = Math.sqrt(x * x + y * y + z * z); - double r = length.get(x, y, z); - return source.get(x / len * r, y / len * r, z / len * r); - } - - @Override - public double get(double x, double y, double z, double w) { - if (x == 0 && y == 0 && z == 0 && w == 0) return source.get(x, y, z, w); - - double len = Math.sqrt(x * x + y * y + z * z + w * w); - double r = length.get(x, y, z, w); - return source.get(x / len * r, y / len * r, z / len * r, w / len * r); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - if (x == 0 && y == 0 && z == 0 && w == 0 && u == 0 && v == 0) - return source.get(x, y, z, w, u, v); - - double len = Math.sqrt(x * x + y * y + z * z + w * w + u * u + v * v); - double r = length.get(x, y, z, w, u, v); - return source.get(x / len * r, y / len * r, z / len * r, w / len * r, u - / len * r, v / len * r); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("length", length, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("length", "setLength", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModulePow.java b/src/com/sudoplay/joise/module/ModulePow.java deleted file mode 100755 index c5b41f1d5..000000000 --- a/src/com/sudoplay/joise/module/ModulePow.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModulePow extends SourcedModule { - - public static final double DEFAULT_POWER = 1.0; - - protected ScalarParameter power = new ScalarParameter(DEFAULT_POWER); - - public void setPower(double v) { - power.set(v); - } - - public void setPower(Module source) { - power.set(source); - } - - @Override - public double get(double x, double y) { - return Math.pow(source.get(x, y), power.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return Math.pow(source.get(x, y, z), power.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return Math.pow(source.get(x, y, z, w), power.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return Math.pow(source.get(x, y, z, w, u, v), power.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("power", power, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("power", "setPower", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleRotateDomain.java b/src/com/sudoplay/joise/module/ModuleRotateDomain.java deleted file mode 100755 index 6a4053c29..000000000 --- a/src/com/sudoplay/joise/module/ModuleRotateDomain.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.noise.Util; - -public class ModuleRotateDomain extends SourcedModule { - - protected double[][] rotmatrix = new double[3][3]; - protected ScalarParameter ax = new ScalarParameter(0); - protected ScalarParameter ay = new ScalarParameter(0); - protected ScalarParameter az = new ScalarParameter(0); - protected ScalarParameter axisangle = new ScalarParameter(0); - - public void setAxis(double ax, double ay, double az) { - this.ax.set(ax); - this.ay.set(ay); - this.az.set(az); - } - - public void setAxis(Module ax, Module ay, Module az) { - this.ax.set(ax); - this.ay.set(ay); - this.az.set(az); - } - - public void setAxisX(double ax) { - this.ax.set(ax); - } - - public void setAxisX(Module ax) { - this.ax.set(ax); - } - - public void setAxisY(double ay) { - this.ay.set(ay); - } - - public void setAxisY(Module ay) { - this.ay.set(ay); - } - - public void setAxisZ(double az) { - this.az.set(az); - } - - public void setAxisZ(Module az) { - this.az.set(az); - } - - public void setAngle(double a) { - this.axisangle.set(a); - } - - public void setAngle(Module a) { - this.axisangle.set(a); - } - - @Override - public double get(double x, double y) { - double nx, ny; - double angle = axisangle.get(x, y) * Util.TWO_PI; - double cos2d = Math.cos(angle); - double sin2d = Math.sin(angle); - nx = x * cos2d - y * sin2d; - ny = y * cos2d + x * sin2d; - return source.get(nx, ny); - } - - @Override - public double get(double x, double y, double z) { - calculateRotMatrix(x, y, z); - double nx, ny, nz; - nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z); - ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z); - nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z); - return source.get(nx, ny, nz); - } - - @Override - public double get(double x, double y, double z, double w) { - calculateRotMatrix(x, y, z, w); - double nx, ny, nz; - nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z); - ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z); - nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z); - return source.get(nx, ny, nz, w); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - calculateRotMatrix(x, y, z, w, u, v); - double nx, ny, nz; - nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z); - ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z); - nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z); - return source.get(nx, ny, nz, w, u, v); - } - - protected void calculateRotMatrix(double x, double y) { - double angle = axisangle.get(x, y) * Util.TWO_PI; - double ax = this.ax.get(x, y); - double ay = this.ay.get(x, y); - double az = this.az.get(x, y); - calc(angle, ax, ay, az); - } - - protected void calculateRotMatrix(double x, double y, double z) { - double angle = axisangle.get(x, y, z) * Util.TWO_PI; - double ax = this.ax.get(x, y, z); - double ay = this.ay.get(x, y, z); - double az = this.az.get(x, y, z); - calc(angle, ax, ay, az); - } - - protected void calculateRotMatrix(double x, double y, double z, double w) { - double angle = axisangle.get(x, y, z, w) * Util.TWO_PI; - double ax = this.ax.get(x, y, z, w); - double ay = this.ay.get(x, y, z, w); - double az = this.az.get(x, y, z, w); - calc(angle, ax, ay, az); - } - - protected void calculateRotMatrix(double x, double y, double z, double w, - double u, double v) { - double angle = axisangle.get(x, y, z, w, u, v) * Util.TWO_PI; - double ax = this.ax.get(x, y, z, w, u, v); - double ay = this.ay.get(x, y, z, w, u, v); - double az = this.az.get(x, y, z, w, u, v); - calc(angle, ax, ay, az); - } - - protected void calc(double angle, double ax, double ay, double az) { - double cosangle = Math.cos(angle); - double sinangle = Math.sin(angle); - - rotmatrix[0][0] = 1.0 + (1.0 - cosangle) * (ax * ax - 1.0); - rotmatrix[1][0] = -az * sinangle + (1.0 - cosangle) * ax * ay; - rotmatrix[2][0] = ay * sinangle + (1.0 - cosangle) * ax * az; - - rotmatrix[0][1] = az * sinangle + (1.0 - cosangle) * ax * ay; - rotmatrix[1][1] = 1.0 + (1.0 - cosangle) * (ay * ay - 1.0); - rotmatrix[2][1] = -ax * sinangle + (1.0 - cosangle) * ay * az; - - rotmatrix[0][2] = -ay * sinangle + (1.0 - cosangle) * ax * az; - rotmatrix[1][2] = ax * sinangle + (1.0 - cosangle) * ay * az; - rotmatrix[2][2] = 1.0 + (1.0 - cosangle) * (az * az - 1.0); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("axisX", ax, props, map); - writeScalar("axisY", ay, props, map); - writeScalar("axisZ", az, props, map); - writeScalar("angle", axisangle, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("axisX", "setAxisX", props, map); - readScalar("axisY", "setAxisY", props, map); - readScalar("axisZ", "setAxisZ", props, map); - readScalar("angle", "setAngle", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleSawtooth.java b/src/com/sudoplay/joise/module/ModuleSawtooth.java deleted file mode 100755 index d973022be..000000000 --- a/src/com/sudoplay/joise/module/ModuleSawtooth.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleSawtooth extends SourcedModule { - - protected ScalarParameter period = new ScalarParameter(0); - - public void setPeriod(double p) { - period.set(p); - } - - public void setPeriod(Module p) { - period.set(p); - } - - @Override - public double get(double x, double y) { - double val = source.get(x, y) / period.get(x, y); - return 2.0 * (val - Math.floor(0.5 + val)); - } - - @Override - public double get(double x, double y, double z) { - double val = source.get(x, y, z) / period.get(x, y, z); - return 2.0 * (val - Math.floor(0.5 + val)); - } - - @Override - public double get(double x, double y, double z, double w) { - double val = source.get(x, y, z, w) / period.get(x, y, z, w); - return 2.0 * (val - Math.floor(0.5 + val)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double val = source.get(x, y, z, w, u, v) / period.get(x, y, z, w, u, v); - return 2.0 * (val - Math.floor(0.5 + val)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("period", period, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("period", "setPeriod", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleScaleDomain.java b/src/com/sudoplay/joise/module/ModuleScaleDomain.java deleted file mode 100755 index 3515c1211..000000000 --- a/src/com/sudoplay/joise/module/ModuleScaleDomain.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleScaleDomain extends SourcedModule { - - public static final double DEFAULT_SCALE = 1.0; - - protected ScalarParameter sx = new ScalarParameter(1.0); - protected ScalarParameter sy = new ScalarParameter(1.0); - protected ScalarParameter sz = new ScalarParameter(1.0); - protected ScalarParameter sw = new ScalarParameter(1.0); - protected ScalarParameter su = new ScalarParameter(1.0); - protected ScalarParameter sv = new ScalarParameter(1.0); - - public void setScaleX(double x) { - sx.set(x); - } - - public void setScaleY(double y) { - sy.set(y); - } - - public void setScaleZ(double z) { - sz.set(z); - } - - public void setScaleW(double w) { - sw.set(w); - } - - public void setScaleU(double u) { - su.set(u); - } - - public void setScaleV(double v) { - sv.set(v); - } - - public void setScaleX(Module x) { - sx.set(x); - } - - public void setScaleY(Module y) { - sy.set(y); - } - - public void setScaleZ(Module z) { - sz.set(z); - } - - public void setScaleW(Module w) { - sw.set(w); - } - - public void setScaleU(Module u) { - su.set(u); - } - - public void setScaleV(Module v) { - sv.set(v); - } - - @Override - public double get(double x, double y) { - return source.get(x * sx.get(x, y), y * sy.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return source.get(x * sx.get(x, y, z), y * sy.get(x, y, z), - z * sz.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return source.get(x * sx.get(x, y, z, w), y * sy.get(x, y, z, w), - z * sz.get(x, y, z, w), w * sw.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return source.get(x * sx.get(x, y, z, w, u, v), - y * sy.get(x, y, z, w, u, v), z * sz.get(x, y, z, w, u, v), - w * sw.get(x, y, z, w, u, v), u * su.get(x, y, z, w, u, v), - v * sv.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("x", sx, props, map); - writeScalar("y", sy, props, map); - writeScalar("z", sz, props, map); - writeScalar("w", sw, props, map); - writeScalar("u", su, props, map); - writeScalar("v", sv, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("x", "setScaleX", props, map); - readScalar("y", "setScaleY", props, map); - readScalar("z", "setScaleZ", props, map); - readScalar("w", "setScaleW", props, map); - readScalar("u", "setScaleU", props, map); - readScalar("v", "setScaleV", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleScaleOffset.java b/src/com/sudoplay/joise/module/ModuleScaleOffset.java deleted file mode 100755 index 3c8f72064..000000000 --- a/src/com/sudoplay/joise/module/ModuleScaleOffset.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleScaleOffset extends SourcedModule { - - protected ScalarParameter scale = new ScalarParameter(1.0); - protected ScalarParameter offset = new ScalarParameter(0.0); - - public void setScale(double s) { - scale.set(s); - } - - public void setScale(Module s) { - scale.set(s); - } - - public void setOffset(double o) { - offset.set(o); - } - - public void setOffset(Module o) { - offset.set(o); - } - - @Override - public double get(double x, double y) { - return source.get(x, y) * scale.get(x, y) + offset.get(x, y); - } - - @Override - public double get(double x, double y, double z) { - return source.get(x, y, z) * scale.get(x, y, z) + offset.get(x, y, z); - } - - @Override - public double get(double x, double y, double z, double w) { - return source.get(x, y, z, w) * scale.get(x, y, z, w) - + offset.get(x, y, z, w); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return source.get(x, y, z, w, u, v) * scale.get(x, y, z, w, u, v) - + offset.get(x, y, z, w, u, v); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("offset", offset, props, map); - writeScalar("scale", scale, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("offset", "setOffset", props, map); - readScalar("scale", "setScale", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleSelect.java b/src/com/sudoplay/joise/module/ModuleSelect.java deleted file mode 100755 index c5beac715..000000000 --- a/src/com/sudoplay/joise/module/ModuleSelect.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.noise.Util; - -public class ModuleSelect extends Module { - - protected ScalarParameter low = new ScalarParameter(0); - protected ScalarParameter high = new ScalarParameter(0); - protected ScalarParameter control = new ScalarParameter(0); - protected ScalarParameter threshold = new ScalarParameter(0); - protected ScalarParameter falloff = new ScalarParameter(0); - - public void setLowSource(double source) { - low.set(source); - } - - public void setHighSource(double source) { - high.set(source); - } - - public void setControlSource(double source) { - control.set(source); - } - - public void setThreshold(double source) { - threshold.set(source); - } - - public void setFalloff(double source) { - falloff.set(source); - } - - public void setLowSource(Module source) { - low.set(source); - } - - public void setHighSource(Module source) { - high.set(source); - } - - public void setControlSource(Module source) { - control.set(source); - } - - public void setThreshold(Module source) { - threshold.set(source); - } - - public void setFalloff(Module source) { - falloff.set(source); - } - - @Override - public double get(double x, double y) { - double c = control.get(x, y); - double f = falloff.get(x, y); - double t = threshold.get(x, y); - - if (f > 0.0) { - - if (c < (t - f)) { - return low.get(x, y); - } else if (c > (t + f)) { - return high.get(x, y); - } else { - double lower = t - f; - double upper = t + f; - double blend = Util.quinticBlend((c - lower) / (upper - lower)); - return Util.lerp(blend, low.get(x, y), high.get(x, y)); - } - - } else { - if (c < t) { - return low.get(x, y); - } else { - return high.get(x, y); - } - } - } - - @Override - public double get(double x, double y, double z) { - double c = control.get(x, y, z); - double f = falloff.get(x, y, z); - double t = threshold.get(x, y, z); - - if (f > 0.0) { - - if (c < (t - f)) { - return low.get(x, y, z); - } else if (c > (t + f)) { - return high.get(x, y, z); - } else { - double lower = t - f; - double upper = t + f; - double blend = Util.quinticBlend((c - lower) / (upper - lower)); - return Util.lerp(blend, low.get(x, y, z), high.get(x, y, z)); - } - - } else { - if (c < t) { - return low.get(x, y, z); - } else { - return high.get(x, y, z); - } - } - } - - @Override - public double get(double x, double y, double z, double w) { - double c = control.get(x, y, z, w); - double f = falloff.get(x, y, z, w); - double t = threshold.get(x, y, z, w); - - if (f > 0.0) { - - if (c < (t - f)) { - return low.get(x, y, z, w); - } else if (c > (t + f)) { - return high.get(x, y, z, w); - } else { - double lower = t - f; - double upper = t + f; - double blend = Util.quinticBlend((c - lower) / (upper - lower)); - return Util.lerp(blend, low.get(x, y, z, w), high.get(x, y, z, w)); - } - - } else { - if (c < t) { - return low.get(x, y, z, w); - } else { - return high.get(x, y, z, w); - } - } - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double c = control.get(x, y, z, w, u, v); - double f = falloff.get(x, y, z, w, u, v); - double t = threshold.get(x, y, z, w, u, v); - - if (f > 0.0) { - - if (c < (t - f)) { - return low.get(x, y, z, w, u, v); - } else if (c > (t + f)) { - return high.get(x, y, z, w, u, v); - } else { - double lower = t - f; - double upper = t + f; - double blend = Util.quinticBlend((c - lower) / (upper - lower)); - return Util.lerp(blend, low.get(x, y, z, w, u, v), - high.get(x, y, z, w, u, v)); - } - - } else { - if (c < t) { - return low.get(x, y, z, w, u, v); - } else { - return high.get(x, y, z, w, u, v); - } - } - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("low", low, props, map); - writeScalar("high", high, props, map); - writeScalar("control", control, props, map); - writeScalar("threshold", threshold, props, map); - writeScalar("falloff", falloff, props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("low", "setLowSource", props, map); - readScalar("high", "setHighSource", props, map); - readScalar("control", "setControlSource", props, map); - readScalar("threshold", "setThreshold", props, map); - readScalar("falloff", "setFalloff", props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleSin.java b/src/com/sudoplay/joise/module/ModuleSin.java deleted file mode 100755 index c9d2b2e15..000000000 --- a/src/com/sudoplay/joise/module/ModuleSin.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleSin extends SourcedModule { - - @Override - public double get(double x, double y) { - return Math.sin(source.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return Math.sin(source.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return Math.sin(source.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return Math.sin(source.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleSphere.java b/src/com/sudoplay/joise/module/ModuleSphere.java deleted file mode 100755 index ca271e052..000000000 --- a/src/com/sudoplay/joise/module/ModuleSphere.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleSphere extends Module { - - protected ScalarParameter cx = new ScalarParameter(0); - protected ScalarParameter cy = new ScalarParameter(0); - protected ScalarParameter cz = new ScalarParameter(0); - protected ScalarParameter cw = new ScalarParameter(0); - protected ScalarParameter cu = new ScalarParameter(0); - protected ScalarParameter cv = new ScalarParameter(0); - protected ScalarParameter radius = new ScalarParameter(1); - - public void setCenterX(double source) { - cx.set(source); - } - - public void setCenterY(double source) { - cy.set(source); - } - - public void setCenterZ(double source) { - cz.set(source); - } - - public void setCenterW(double source) { - cw.set(source); - } - - public void setCenterU(double source) { - cu.set(source); - } - - public void setCenterV(double source) { - cv.set(source); - } - - public void setRadius(double source) { - radius.set(source); - } - - public void setCenterX(Module source) { - cx.set(source); - } - - public void setCenterY(Module source) { - cy.set(source); - } - - public void setCenterZ(Module source) { - cz.set(source); - } - - public void setCenterW(Module source) { - cw.set(source); - } - - public void setCenterU(Module source) { - cu.set(source); - } - - public void setCenterV(Module source) { - cv.set(source); - } - - public void setRadius(Module source) { - radius.set(source); - } - - @Override - public double get(double x, double y) { - double dx = x - cx.get(x, y), dy = y - cy.get(x, y); - double len = Math.sqrt(dx * dx + dy * dy); - double r = radius.get(x, y); - double i = (r - len) / r; - if (i < 0) i = 0; - if (i > 1) i = 1; - - return i; - } - - @Override - public double get(double x, double y, double z) { - double dx = x - cx.get(x, y, z), dy = y - cy.get(x, y, z), dz = z - - cz.get(x, y, z); - double len = Math.sqrt(dx * dx + dy * dy + dz * dz); - double r = radius.get(x, y, z); - double i = (r - len) / r; - if (i < 0) i = 0; - if (i > 1) i = 1; - - return i; - } - - @Override - public double get(double x, double y, double z, double w) { - double dx = x - cx.get(x, y, z, w), dy = y - cy.get(x, y, z, w), dz = z - - cz.get(x, y, z, w), dw = w - cw.get(x, y, z, w); - double len = Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw); - double r = radius.get(x, y, z, w); - double i = (r - len) / r; - if (i < 0) i = 0; - if (i > 1) i = 1; - - return i; - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double dx = x - cx.get(x, y, z, w, u, v), dy = y - cy.get(x, y, z, w, u, v), dz = z - - cz.get(x, y, z, w, u, v), dw = w - cw.get(x, y, z, w, u, v), du = u - - cu.get(x, y, z, w, u, v), dv = v - cv.get(x, y, z, w, u, v); - double len = Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw + du * du + dv - * dv); - double r = radius.get(x, y, z, w, u, v); - double i = (r - len) / r; - if (i < 0) i = 0; - if (i > 1) i = 1; - - return i; - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("cx", cx, props, map); - writeScalar("cy", cy, props, map); - writeScalar("cz", cz, props, map); - writeScalar("cw", cw, props, map); - writeScalar("cu", cu, props, map); - writeScalar("cv", cv, props, map); - writeScalar("radius", radius, props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("cx", "setCenterX", props, map); - readScalar("cy", "setCenterY", props, map); - readScalar("cz", "setCenterZ", props, map); - readScalar("cw", "setCenterW", props, map); - readScalar("cu", "setCenterU", props, map); - readScalar("cv", "setCenterV", props, map); - readScalar("radius", "setRadius", props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleTiers.java b/src/com/sudoplay/joise/module/ModuleTiers.java deleted file mode 100755 index 6e9e64fda..000000000 --- a/src/com/sudoplay/joise/module/ModuleTiers.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.noise.Util; -import com.sudoplay.util.Checked; - -public class ModuleTiers extends SourcedModule { - - public static final int DEFAULT_NUM_TIERS = 0; - public static final boolean DEFAULT_SMOOTH = true; - - protected int numTiers = DEFAULT_NUM_TIERS; - protected boolean smooth = DEFAULT_SMOOTH; - - public void setNumTiers(long n) { - numTiers = Checked.safeLongToInt(n); - } - - public void setNumTiers(int n) { - numTiers = n; - } - - public void setSmooth(boolean b) { - smooth = b; - } - - @Override - public double get(double x, double y) { - int numsteps = numTiers; - if (smooth) --numsteps; - double val = source.get(x, y); - double Tb = Math.floor(val * (double) (numsteps)); - double Tt = Tb + 1.0; - double t = val * (double) (numsteps) - Tb; - Tb /= (double) (numsteps); - Tt /= (double) (numsteps); - double u; - if (smooth) - u = Util.quinticBlend(t); - else - u = 0.0; - return Tb + u * (Tt - Tb); - } - - @Override - public double get(double x, double y, double z) { - int numsteps = numTiers; - if (smooth) --numsteps; - double val = source.get(x, y, z); - double Tb = Math.floor(val * (double) (numsteps)); - double Tt = Tb + 1.0; - double t = val * (double) (numsteps) - Tb; - Tb /= (double) (numsteps); - Tt /= (double) (numsteps); - double u; - if (smooth) - u = Util.quinticBlend(t); - else - u = 0.0; - return Tb + u * (Tt - Tb); - } - - @Override - public double get(double x, double y, double z, double w) { - int numsteps = numTiers; - if (smooth) --numsteps; - double val = source.get(x, y, z, w); - double Tb = Math.floor(val * (double) (numsteps)); - double Tt = Tb + 1.0; - double t = val * (double) (numsteps) - Tb; - Tb /= (double) (numsteps); - Tt /= (double) (numsteps); - double u; - if (smooth) - u = Util.quinticBlend(t); - else - u = 0.0; - return Tb + u * (Tt - Tb); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - int numsteps = numTiers; - if (smooth) --numsteps; - double val = source.get(x, y, z, w, u, v); - double Tb = Math.floor(val * (double) (numsteps)); - double Tt = Tb + 1.0; - double t = val * (double) (numsteps) - Tb; - Tb /= (double) (numsteps); - Tt /= (double) (numsteps); - double s; - if (smooth) - s = Util.quinticBlend(t); - else - s = 0.0; - return Tb + s * (Tt - Tb); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeLong("tiers", numTiers, props); - writeBoolean("smooth", smooth, props); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readLong("tiers", "setNumTiers", props); - readBoolean("smooth", "setSmooth", props); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleTranslateDomain.java b/src/com/sudoplay/joise/module/ModuleTranslateDomain.java deleted file mode 100755 index d69dca6c4..000000000 --- a/src/com/sudoplay/joise/module/ModuleTranslateDomain.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public class ModuleTranslateDomain extends SourcedModule { - - protected ScalarParameter ax = new ScalarParameter(0); - protected ScalarParameter ay = new ScalarParameter(0); - protected ScalarParameter az = new ScalarParameter(0); - protected ScalarParameter aw = new ScalarParameter(0); - protected ScalarParameter au = new ScalarParameter(0); - protected ScalarParameter av = new ScalarParameter(0); - - public void setAxisXSource(double source) { - ax.set(source); - } - - public void setAxisYSource(double source) { - ay.set(source); - } - - public void setAxisZSource(double source) { - az.set(source); - } - - public void setAxisWSource(double source) { - aw.set(source); - } - - public void setAxisUSource(double source) { - au.set(source); - } - - public void setAxisVSource(double source) { - av.set(source); - } - - public void setAxisXSource(Module source) { - ax.set(source); - } - - public void setAxisYSource(Module source) { - ay.set(source); - } - - public void setAxisZSource(Module source) { - az.set(source); - } - - public void setAxisWSource(Module source) { - aw.set(source); - } - - public void setAxisUSource(Module source) { - au.set(source); - } - - public void setAxisVSource(Module source) { - av.set(source); - } - - @Override - public double get(double x, double y) { - return source.get(x + ax.get(x, y), y + ay.get(x, y)); - } - - @Override - public double get(double x, double y, double z) { - return source.get(x + ax.get(x, y, z), y + ay.get(x, y, z), - z + az.get(x, y, z)); - } - - @Override - public double get(double x, double y, double z, double w) { - return source.get(x + ax.get(x, y, z, w), y + ay.get(x, y, z, w), - z + az.get(x, y, z, w), w + aw.get(x, y, z, w)); - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - return source.get(x + ax.get(x, y, z, w, u, v), - y + ay.get(x, y, z, w, u, v), z + az.get(x, y, z, w, u, v), - w + aw.get(x, y, z, w, u, v), u + au.get(x, y, z, w, u, v), - v + av.get(x, y, z, w, u, v)); - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("axisX", ax, props, map); - writeScalar("axisY", ay, props, map); - writeScalar("axisZ", az, props, map); - writeScalar("axisW", aw, props, map); - writeScalar("axisU", au, props, map); - writeScalar("axisV", av, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("axisX", "setAxisXSource", props, map); - readScalar("axisY", "setAxisYSource", props, map); - readScalar("axisZ", "setAxisZSource", props, map); - readScalar("axisW", "setAxisWSource", props, map); - readScalar("axisU", "setAxisUSource", props, map); - readScalar("axisV", "setAxisVSource", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ModuleTriangle.java b/src/com/sudoplay/joise/module/ModuleTriangle.java deleted file mode 100755 index 7bb1ee2d1..000000000 --- a/src/com/sudoplay/joise/module/ModuleTriangle.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; -import com.sudoplay.joise.noise.Util; - -public class ModuleTriangle extends SourcedModule { - - public static final double DEFAULT_PERIOD = 0; - public static final double DEFAULT_OFFSET = 0; - - protected ScalarParameter period = new ScalarParameter(DEFAULT_PERIOD); - protected ScalarParameter offset = new ScalarParameter(DEFAULT_OFFSET); - - public void setPeriod(double source) { - period.set(source); - } - - public void setOffset(double source) { - offset.set(source); - } - - public void setPeriod(Module source) { - period.set(source); - } - - public void setOffset(Module source) { - offset.set(source); - } - - @Override - public double get(double x, double y) { - double val = source.get(x, y); - double p = period.get(x, y); - double o = offset.get(x, y); - - if (o >= 1) - return Util.sawtooth(val, p); - else if (o <= 0) - return 1.0 - Util.sawtooth(val, p); - else { - double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0; - double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0; - return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2 - / (1.0 - o); - } - } - - @Override - public double get(double x, double y, double z) { - double val = source.get(x, y, z); - double p = period.get(x, y, z); - double o = offset.get(x, y, z); - - if (o >= 1) - return Util.sawtooth(val, p); - else if (o <= 0) - return 1.0 - Util.sawtooth(val, p); - else { - double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0; - double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0; - return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2 - / (1.0 - o); - } - } - - @Override - public double get(double x, double y, double z, double w) { - double val = source.get(x, y, z, w); - double p = period.get(x, y, z, w); - double o = offset.get(x, y, z, w); - - if (o >= 1) - return Util.sawtooth(val, p); - else if (o <= 0) - return 1.0 - Util.sawtooth(val, p); - else { - double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0; - double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0; - return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2 - / (1.0 - o); - } - } - - @Override - public double get(double x, double y, double z, double w, double u, double v) { - double val = source.get(x, y, z, w, u, v); - double p = period.get(x, y, z, w, u, v); - double o = offset.get(x, y, z, w, u, v); - - if (o >= 1) - return Util.sawtooth(val, p); - else if (o <= 0) - return 1.0 - Util.sawtooth(val, p); - else { - double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0; - double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0; - return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2 - / (1.0 - o); - } - } - - @Override - protected void _writeToMap(ModuleMap map) { - - ModulePropertyMap props = new ModulePropertyMap(this); - - writeScalar("offset", offset, props, map); - writeScalar("period", period, props, map); - writeSource(props, map); - - map.put(getId(), props); - - } - - @Override - public Module buildFromPropertyMap(ModulePropertyMap props, - ModuleInstanceMap map) { - - readScalar("offset", "setOffset", props, map); - readScalar("period", "setPeriod", props, map); - readSource(props, map); - - return this; - } - -} diff --git a/src/com/sudoplay/joise/module/ScalarParameter.java b/src/com/sudoplay/joise/module/ScalarParameter.java deleted file mode 100755 index bc533e44d..000000000 --- a/src/com/sudoplay/joise/module/ScalarParameter.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -public class ScalarParameter { - - private Module module; - private double value; - - public ScalarParameter(Module source) { - set(source); - } - - public ScalarParameter(double source) { - set(source); - } - - public void set(Module source) { - module = source; - } - - public void set(double source) { - module = null; - value = source; - } - - public boolean isModule() { - return module != null; - } - - public Module getModule() { - return module; - } - - public double getValue() { - return value; - } - - public double get(double x, double y) { - if (module != null) return module.get(x, y); - return value; - } - - public double get(double x, double y, double z) { - if (module != null) return module.get(x, y, z); - return value; - } - - public double get(double x, double y, double z, double w) { - if (module != null) return module.get(x, y, z, w); - return value; - } - - public double get(double x, double y, double z, double w, double u, double v) { - if (module != null) return module.get(x, y, z, w, u, v); - return value; - } - - @Override - public String toString() { - if (module != null) { - return module.getId(); - } else { - return String.valueOf(value); - } - } - -} diff --git a/src/com/sudoplay/joise/module/SeedableModule.java b/src/com/sudoplay/joise/module/SeedableModule.java deleted file mode 100755 index f57598773..000000000 --- a/src/com/sudoplay/joise/module/SeedableModule.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModulePropertyMap; - -public abstract class SeedableModule extends Module { - - protected long seed = DEFAULT_SEED; - - protected String seedName; - - public void setSeed(long seed) { - this.seed = seed; - } - - public long getSeed() { - return seed; - } - - public void setSeedName(String name) { - seedName = name; - } - - public String getSeedName() { - return seedName; - } - - public boolean hasSeedName() { - return seedName != null; - } - - protected void readSeed(ModulePropertyMap props) { - String sn = (String) props.get("seedName"); - if (sn != null) { - seedName = sn; - } - setSeed(props.getAsLong("seed")); - } - - protected void writeSeed(ModulePropertyMap props) { - if (seedName != null) { - props.put("seedName", seedName); - } - props.put("seed", seed); - } - -} diff --git a/src/com/sudoplay/joise/module/SourcedModule.java b/src/com/sudoplay/joise/module/SourcedModule.java deleted file mode 100755 index 52d694898..000000000 --- a/src/com/sudoplay/joise/module/SourcedModule.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.module; - -import com.sudoplay.joise.ModuleInstanceMap; -import com.sudoplay.joise.ModuleMap; -import com.sudoplay.joise.ModulePropertyMap; - -public abstract class SourcedModule extends Module { - - protected ScalarParameter source = new ScalarParameter(0.0); - - public void setSource(double source) { - this.source.set(source); - } - - public void setSource(Module source) { - this.source.set(source); - } - - public ScalarParameter getSource() { - return source; - } - - protected void writeSource(ModulePropertyMap props, ModuleMap map) { - writeScalar("source", source, props, map); - } - - protected void readSource(ModulePropertyMap props, ModuleInstanceMap map) { - readScalar("source", "setSource", props, map); - } - -} diff --git a/src/com/sudoplay/joise/noise/Interpolator.java b/src/com/sudoplay/joise/noise/Interpolator.java deleted file mode 100755 index 5c57d5906..000000000 --- a/src/com/sudoplay/joise/noise/Interpolator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.noise; - -public interface Interpolator { - - public static final Interpolator NONE = new Interpolator() { - @Override - public double interpolate(double t) { - return 0; - } - }; - - public static final Interpolator LINEAR = new Interpolator() { - @Override - public double interpolate(double t) { - return t; - } - }; - - public static final Interpolator HERMITE = new Interpolator() { - @Override - public double interpolate(double t) { - return (t * t * (3 - 2 * t)); - } - }; - - public static final Interpolator QUINTIC = new Interpolator() { - @Override - public double interpolate(double t) { - return t * t * t * (t * (t * 6 - 15) + 10); - } - }; - - public double interpolate(double t); - -} diff --git a/src/com/sudoplay/joise/noise/Noise.java b/src/com/sudoplay/joise/noise/Noise.java deleted file mode 100755 index e05808c83..000000000 --- a/src/com/sudoplay/joise/noise/Noise.java +++ /dev/null @@ -1,1387 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.noise; - -import java.nio.ByteBuffer; -import java.util.Arrays; - -public class Noise { - - private static final long INIT32 = 0x811c9dc5L; - private static final int PRIME32 = 0x01000193; - private static final int FNV_MASK_8 = (1 << 8) - 1; - - private static final double INV_BYTEVAL = 1.0 / 255.0; - - private static final double F2 = 0.36602540378443864676372317075294; - private static final double G2 = 0.21132486540518711774542560974902; - private static final double F3 = 1.0 / 3.0; - private static final double G3 = 1.0 / 6.0; - - private static final ThreadLocal buf16 = new ThreadLocal() { - @Override - protected ByteBuffer initialValue() { - return ByteBuffer.allocate(16); - } - }; - - private static final ThreadLocal buf20 = new ThreadLocal() { - @Override - protected ByteBuffer initialValue() { - return ByteBuffer.allocate(20); - } - }; - - private static final ThreadLocal buf24 = new ThreadLocal() { - @Override - protected ByteBuffer initialValue() { - return ByteBuffer.allocate(24); - } - }; - - private static final ThreadLocal buf32 = new ThreadLocal() { - @Override - protected ByteBuffer initialValue() { - return ByteBuffer.allocate(32); - } - }; - - private static final ThreadLocal buf40 = new ThreadLocal() { - @Override - protected ByteBuffer initialValue() { - return ByteBuffer.allocate(40); - } - }; - - private static final ThreadLocal buf56 = new ThreadLocal() { - @Override - protected ByteBuffer initialValue() { - return ByteBuffer.allocate(56); - } - }; - - // ========================================================================== - // = Worker noise functions - // ========================================================================== - - private static interface WorkerNoise2 { - - public static final WorkerNoise2 VALUE = new WorkerNoise2() { - @Override - public double calculate(double x, double y, int ix, int iy, long seed) { - int n = (hashCoords2(ix, iy, seed)); - double noise = (double) n * INV_BYTEVAL; - return noise * 2.0 - 1.0; - } - }; - - public static final WorkerNoise2 GRADIENT = new WorkerNoise2() { - @Override - public double calculate(double x, double y, int ix, int iy, long seed) { - int hash = hashCoords2(ix, iy, seed); - double[] vec = NoiseLUT.gradient2DLUT[hash]; - double dx = x - (double) ix; - double dy = y - (double) iy; - return dx * vec[0] + dy * vec[1]; - } - }; - - public double calculate(double x, double y, int ix, int iy, long seed); - } - - private static interface WorkerNoise3 { - - public static final WorkerNoise3 VALUE = new WorkerNoise3() { - @Override - public double calculate(double x, double y, double z, int ix, int iy, - int iz, long seed) { - int n = (hashCoords3(ix, iy, iz, seed)); - double noise = (double) n * INV_BYTEVAL; - return noise * 2.0 - 1.0; - } - }; - - public static final WorkerNoise3 GRADIENT = new WorkerNoise3() { - @Override - public double calculate(double x, double y, double z, int ix, int iy, - int iz, long seed) { - int hash = hashCoords3(ix, iy, iz, seed); - double[] vec = NoiseLUT.gradient3DLUT[hash]; - double dx = x - (double) ix; - double dy = y - (double) iy; - double dz = z - (double) iz; - return (dx * vec[0] + dy * vec[1] + dz * vec[2]); - } - }; - - public double calculate(double x, double y, double z, int ix, int iy, - int iz, long seed); - } - - private static interface WorkerNoise4 { - - public static final WorkerNoise4 VALUE = new WorkerNoise4() { - @Override - public double calculate(double x, double y, double z, double w, int ix, - int iy, int iz, int iw, long seed) { - int n = (hashCoords4(ix, iy, iz, iw, seed)); - double noise = (double) n * INV_BYTEVAL; - return noise * 2.0 - 1.0; - } - }; - - public static final WorkerNoise4 GRADIENT = new WorkerNoise4() { - @Override - public double calculate(double x, double y, double z, double w, int ix, - int iy, int iz, int iw, long seed) { - int hash = hashCoords4(ix, iy, iz, iw, seed); - double[] vec = NoiseLUT.gradient4DLUT[hash]; - double dx = x - (double) ix; - double dy = y - (double) iy; - double dz = z - (double) iz; - double dw = w - (double) iw; - return (dx * vec[0] + dy * vec[1] + dz * vec[2] + dw * vec[3]); - } - }; - - public double calculate(double x, double y, double z, double w, int ix, - int iy, int iz, int iw, long seed); - } - - private static interface WorkerNoise6 { - - public static final WorkerNoise6 VALUE = new WorkerNoise6() { - @Override - public double calculate(double x, double y, double z, double w, double u, - double v, int ix, int iy, int iz, int iw, int iu, int iv, long seed) { - int n = (hashCoords6(ix, iy, iz, iw, iu, iv, seed)); - double noise = (double) n * INV_BYTEVAL; - return noise * 2.0 - 1.0; - } - }; - - public static final WorkerNoise6 GRADIENT = new WorkerNoise6() { - @Override - public double calculate(double x, double y, double z, double w, double u, - double v, int ix, int iy, int iz, int iw, int iu, int iv, long seed) { - int hash = hashCoords6(ix, iy, iz, iw, iu, iv, seed); - double[] vec = NoiseLUT.gradient6DLUT[hash]; - - double dx = x - (double) ix; - double dy = y - (double) iy; - double dz = z - (double) iz; - double dw = w - (double) iw; - double du = u - (double) iu; - double dv = v - (double) iv; - - return (dx * vec[0] + dy * vec[1] + dz * vec[2] + dw * vec[3] + du - * vec[4] + dv * vec[5]); - } - }; - - public double calculate(double x, double y, double z, double w, double u, - double v, int ix, int iy, int iz, int iw, int iu, int iv, long seed); - } - - // ========================================================================== - // = Common - // ========================================================================== - - private static double lerp(double s, double v1, double v2) { - return v1 + s * (v2 - v1); - } - - private static int fastFloor(double t) { - return t > 0 ? (int) t : (int) t - 1; - } - - private static double arrayDot2(double[] arr, double a, double b) { - return a * arr[0] + b * arr[1]; - } - - private static double arrayDot3(double[] arr, double a, double b, double c) { - return a * arr[0] + b * arr[1] + c * arr[2]; - } - - private static double arrayDot4(double[] arr, double x, double y, double z, - double w) { - return x * arr[0] + y * arr[1] + z * arr[2] + w * arr[3]; - } - - private static void addDist(double[] f, double[] disp, double testDist, - double testDisp) { - int index; - if (testDist < f[3]) { - index = 3; - while (index > 0 && testDist < f[index - 1]) - index--; - for (int i = 3; i-- > index;) { - f[i + 1] = f[i]; - disp[i + 1] = disp[i]; - } - f[index] = testDist; - disp[index] = testDisp; - } - } - - private static class SVectorOrdering implements Comparable { - public double val; - public int axis; - - public SVectorOrdering(double v, int a) { - val = v; - axis = a; - } - - @Override - public int compareTo(SVectorOrdering o) { - if (val > o.val) { - return 1; - } - return -1; - } - } - - private static void sortBy6(double[] l1, int[] l2) { - SVectorOrdering[] a = new SVectorOrdering[6]; - for (int i = 0; i < 6; i++) { - a[i] = new SVectorOrdering(l1[i], l2[i]); - } - Arrays.sort(a); - for (int i = 0; i < 6; i++) { - l2[i] = a[i].axis; - } - } - - // ========================================================================== - // = Hashing functions - // ========================================================================== - - private static int fnv32ABuf(byte[] buf) { - long hval = INIT32; - for (int i = 0; i < buf.length; i++) { - hval ^= buf[i]; - hval *= PRIME32; - } - return (int) (hval & 0x00000000ffffffffL); - } - - private static int xorFoldHash(int hash) { - return ((byte) ((hash >> 8) ^ (hash & FNV_MASK_8))) & 0xFF; - } - - private static int hashCoords2(int x, int y, long seed) { - ByteBuffer buf = buf16.get(); - buf.clear(); - buf.putInt(x).putInt(y).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - private static int hashCoords3(int x, int y, int z, long seed) { - ByteBuffer buf = buf20.get(); - buf.clear(); - buf.putInt(x).putInt(y).putInt(z).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - private static int hashCoords4(int x, int y, int z, int w, long seed) { - ByteBuffer buf = buf24.get(); - buf.clear(); - buf.putInt(x).putInt(y).putInt(z).putInt(w).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - private static int hashCoords6(int x, int y, int z, int w, int u, int v, - long seed) { - ByteBuffer buf = buf32.get(); - buf.clear(); - buf.putInt(x).putInt(y).putInt(z); - buf.putInt(w).putInt(u).putInt(v).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - private static int computeHashDouble2(double x, double y, long seed) { - ByteBuffer buf = buf24.get(); - buf.clear(); - buf.putDouble(x).putDouble(y).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - private static int computeHashDouble3(double x, double y, double z, long seed) { - ByteBuffer buf = buf32.get(); - buf.clear(); - buf.putDouble(x).putDouble(y).putDouble(z).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - private static int computeHashDouble4(double x, double y, double z, double w, - long seed) { - ByteBuffer buf = buf40.get(); - buf.clear(); - buf.putDouble(x).putDouble(y).putDouble(z).putDouble(w).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - private static int computeHashDouble6(double x, double y, double z, double w, - double u, double v, long seed) { - ByteBuffer buf = buf56.get(); - buf.clear(); - buf.putDouble(x).putDouble(y).putDouble(z); - buf.putDouble(w).putDouble(u).putDouble(v).putLong(seed); - return xorFoldHash(fnv32ABuf(buf.array())); - } - - // ========================================================================== - // = Interpolation functions - // ========================================================================== - - private static double interpolateX2(double x, double y, double xs, int x0, - int x1, int iy, long seed, WorkerNoise2 noisefunc) { - double v1 = noisefunc.calculate(x, y, x0, iy, seed); - double v2 = noisefunc.calculate(x, y, x1, iy, seed); - return lerp(xs, v1, v2); - } - - private static double interpolateXY2(double x, double y, double xs, - double ys, int x0, int x1, int y0, int y1, long seed, - WorkerNoise2 noisefunc) { - double v1 = interpolateX2(x, y, xs, x0, x1, y0, seed, noisefunc); - double v2 = interpolateX2(x, y, xs, x0, x1, y1, seed, noisefunc); - return lerp(ys, v1, v2); - } - - private static double interpolateX3(double x, double y, double z, double xs, - int x0, int x1, int iy, int iz, long seed, WorkerNoise3 noisefunc) { - double v1 = noisefunc.calculate(x, y, z, x0, iy, iz, seed); - double v2 = noisefunc.calculate(x, y, z, x1, iy, iz, seed); - return lerp(xs, v1, v2); - } - - private static double interpolateXY3(double x, double y, double z, double xs, - double ys, int x0, int x1, int y0, int y1, int iz, long seed, - WorkerNoise3 noisefunc) { - double v1 = interpolateX3(x, y, z, xs, x0, x1, y0, iz, seed, noisefunc); - double v2 = interpolateX3(x, y, z, xs, x0, x1, y1, iz, seed, noisefunc); - return lerp(ys, v1, v2); - } - - private static double interpolateXYZ3(double x, double y, double z, - double xs, double ys, double zs, int x0, int x1, int y0, int y1, int z0, - int z1, long seed, WorkerNoise3 noisefunc) { - double v1 = interpolateXY3(x, y, z, xs, ys, x0, x1, y0, y1, z0, seed, - noisefunc); - double v2 = interpolateXY3(x, y, z, xs, ys, x0, x1, y0, y1, z1, seed, - noisefunc); - return lerp(zs, v1, v2); - } - - private static double interpolateX4(double x, double y, double z, double w, - double xs, int x0, int x1, int iy, int iz, int iw, long seed, - WorkerNoise4 noisefunc) { - double v1 = noisefunc.calculate(x, y, z, w, x0, iy, iz, iw, seed); - double v2 = noisefunc.calculate(x, y, z, w, x1, iy, iz, iw, seed); - return lerp(xs, v1, v2); - } - - private static double interpolateXY4(double x, double y, double z, double w, - double xs, double ys, int x0, int x1, int y0, int y1, int iz, int iw, - long seed, WorkerNoise4 noisefunc) { - double v1 = interpolateX4(x, y, z, w, xs, x0, x1, y0, iz, iw, seed, - noisefunc); - double v2 = interpolateX4(x, y, z, w, xs, x0, x1, y1, iz, iw, seed, - noisefunc); - return lerp(ys, v1, v2); - } - - private static double interpolateXYZ4(double x, double y, double z, double w, - double xs, double ys, double zs, int x0, int x1, int y0, int y1, int z0, - int z1, int iw, long seed, WorkerNoise4 noisefunc) { - double v1 = interpolateXY4(x, y, z, w, xs, ys, x0, x1, y0, y1, z0, iw, - seed, noisefunc); - double v2 = interpolateXY4(x, y, z, w, xs, ys, x0, x1, y0, y1, z1, iw, - seed, noisefunc); - return lerp(zs, v1, v2); - } - - private static double interpolateXYZW4(double x, double y, double z, - double w, double xs, double ys, double zs, double ws, int x0, int x1, - int y0, int y1, int z0, int z1, int w0, int w1, long seed, - WorkerNoise4 noisefunc) { - double v1 = interpolateXYZ4(x, y, z, w, xs, ys, zs, x0, x1, y0, y1, z0, z1, - w0, seed, noisefunc); - double v2 = interpolateXYZ4(x, y, z, w, xs, ys, zs, x0, x1, y0, y1, z0, z1, - w1, seed, noisefunc); - return lerp(ws, v1, v2); - } - - private static double interpolateX6(double x, double y, double z, double w, - double u, double v, double xs, int x0, int x1, int iy, int iz, int iw, - int iu, int iv, long seed, WorkerNoise6 noisefunc) { - double v1 = noisefunc.calculate(x, y, z, w, u, v, x0, iy, iz, iw, iu, iv, - seed); - double v2 = noisefunc.calculate(x, y, z, w, u, v, x1, iy, iz, iw, iu, iv, - seed); - return lerp(xs, v1, v2); - } - - private static double interpolateXY6(double x, double y, double z, double w, - double u, double v, double xs, double ys, int x0, int x1, int y0, int y1, - int iz, int iw, int iu, int iv, long seed, WorkerNoise6 noisefunc) { - double v1 = interpolateX6(x, y, z, w, u, v, xs, x0, x1, y0, iz, iw, iu, iv, - seed, noisefunc); - double v2 = interpolateX6(x, y, z, w, u, v, xs, x0, x1, y1, iz, iw, iu, iv, - seed, noisefunc); - return lerp(ys, v1, v2); - } - - private static double interpolateXYZ6(double x, double y, double z, double w, - double u, double v, double xs, double ys, double zs, int x0, int x1, - int y0, int y1, int z0, int z1, int iw, int iu, int iv, long seed, - WorkerNoise6 noisefunc) { - double v1 = interpolateXY6(x, y, z, w, u, v, xs, ys, x0, x1, y0, y1, z0, - iw, iu, iv, seed, noisefunc); - double v2 = interpolateXY6(x, y, z, w, u, v, xs, ys, x0, x1, y0, y1, z1, - iw, iu, iv, seed, noisefunc); - return lerp(zs, v1, v2); - } - - private static double interpolateXYZW6(double x, double y, double z, - double w, double u, double v, double xs, double ys, double zs, double ws, - int x0, int x1, int y0, int y1, int z0, int z1, int w0, int w1, int iu, - int iv, long seed, WorkerNoise6 noisefunc) { - double v1 = interpolateXYZ6(x, y, z, w, u, v, xs, ys, zs, x0, x1, y0, y1, - z0, z1, w0, iu, iv, seed, noisefunc); - double v2 = interpolateXYZ6(x, y, z, w, u, v, xs, ys, zs, x0, x1, y0, y1, - z0, z1, w1, iu, iv, seed, noisefunc); - return lerp(ws, v1, v2); - } - - private static double interpolateXYZWU6(double x, double y, double z, - double w, double u, double v, double xs, double ys, double zs, double ws, - double us, int x0, int x1, int y0, int y1, int z0, int z1, int w0, - int w1, int u0, int u1, int iv, long seed, WorkerNoise6 noisefunc) { - double v1 = interpolateXYZW6(x, y, z, w, u, v, xs, ys, zs, ws, x0, x1, y0, - y1, z0, z1, w0, w1, u0, iv, seed, noisefunc); - double v2 = interpolateXYZW6(x, y, z, w, u, v, xs, ys, zs, ws, x0, x1, y0, - y1, z0, z1, w0, w1, u1, iv, seed, noisefunc); - return lerp(us, v1, v2); - } - - private static double interpolateXYZWUV6(double x, double y, double z, - double w, double u, double v, double xs, double ys, double zs, double ws, - double us, double vs, int x0, int x1, int y0, int y1, int z0, int z1, - int w0, int w1, int u0, int u1, int v0, int v1, long seed, - WorkerNoise6 noisefunc) { - double val1 = interpolateXYZWU6(x, y, z, w, u, v, xs, ys, zs, ws, us, x0, - x1, y0, y1, z0, z1, w0, w1, u0, u1, v0, seed, noisefunc); - double val2 = interpolateXYZWU6(x, y, z, w, u, v, xs, ys, zs, ws, us, x0, - x1, y0, y1, z0, z1, w0, w1, u0, u1, v1, seed, noisefunc); - return lerp(vs, val1, val2); - } - - // ========================================================================== - // = 2D noise functions - // ========================================================================== - - public static interface Function2D { - - public static Function2D VALUE = new Function2D() { - @Override - public double get(double x, double y, long seed, Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int x1 = x0 + 1; - int y1 = y0 + 1; - double xs = interpolator.interpolate(x - (double) x0); - double ys = interpolator.interpolate(y - (double) y0); - return interpolateXY2(x, y, xs, ys, x0, x1, y0, y1, seed, - WorkerNoise2.VALUE); - } - }; - - public static Function2D GRADIENT = new Function2D() { - @Override - public double get(double x, double y, long seed, Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int x1 = x0 + 1; - int y1 = y0 + 1; - double xs = interpolator.interpolate(x - (double) x0); - double ys = interpolator.interpolate(y - (double) y0); - return interpolateXY2(x, y, xs, ys, x0, x1, y0, y1, seed, - WorkerNoise2.GRADIENT); - } - }; - - public static Function2D GRADVAL = new Function2D() { - @Override - public double get(double x, double y, long seed, Interpolator interpolator) { - return Function2D.VALUE.get(x, y, seed, interpolator) - + Function2D.GRADIENT.get(x, y, seed, interpolator); - } - }; - - public static Function2D WHITE = new Function2D() { - @Override - public double get(double x, double y, long seed, Interpolator interpolator) { - int hash = computeHashDouble2(x, y, seed); - return NoiseLUT.whitenoiseLUT[hash]; - } - }; - - public static Function2D SIMPLEX = new Function2D() { - @Override - public double get(double x, double y, long seed, Interpolator interpolator) { - double s = (x + y) * F2; - int i = fastFloor(x + s); - int j = fastFloor(y + s); - double t = (i + j) * G2; - double X0 = i - t; - double Y0 = j - t; - double x0 = x - X0; - double y0 = y - Y0; - int i1, j1; - if (x0 > y0) { - i1 = 1; - j1 = 0; - } else { - i1 = 0; - j1 = 1; - } - double x1 = x0 - (double) i1 + G2; - double y1 = y0 - (double) j1 + G2; - double x2 = x0 - 1.0 + 2.0 * G2; - double y2 = y0 - 1.0 + 2.0 * G2; - int h0 = hashCoords2(i, j, seed); - int h1 = hashCoords2(i + i1, j + j1, seed); - int h2 = hashCoords2(i + 1, j + 1, seed); - double[] g0 = NoiseLUT.gradient2DLUT[h0]; - double[] g1 = NoiseLUT.gradient2DLUT[h1]; - double[] g2 = NoiseLUT.gradient2DLUT[h2]; - double n0, n1, n2; - double t0 = 0.5 - x0 * x0 - y0 * y0; - if (t0 < 0) - n0 = 0; - else { - t0 *= t0; - n0 = t0 * t0 * arrayDot2(g0, x0, y0); - } - double t1 = 0.5 - x1 * x1 - y1 * y1; - if (t1 < 0) - n1 = 0; - else { - t1 *= t1; - n1 = t1 * t1 * arrayDot2(g1, x1, y1); - } - double t2 = 0.5 - x2 * x2 - y2 * y2; - if (t2 < 0) - n2 = 0; - else { - t2 *= t2; - n2 = t2 * t2 * arrayDot2(g2, x2, y2); - } - return (70.0 * (n0 + n1 + n2)) * 1.42188695 + 0.001054489; - } - }; - - public double get(double x, double y, long seed, Interpolator interpolator); - } - - // ========================================================================== - // = 3D noise functions - // ========================================================================== - - public static interface Function3D { - - public static final Function3D VALUE = new Function3D() { - @Override - public double get(double x, double y, double z, long seed, - Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int z0 = fastFloor(z); - int x1 = x0 + 1; - int y1 = y0 + 1; - int z1 = z0 + 1; - double xs = interpolator.interpolate(x - (double) x0); - double ys = interpolator.interpolate(y - (double) y0); - double zs = interpolator.interpolate(z - (double) z0); - return interpolateXYZ3(x, y, z, xs, ys, zs, x0, x1, y0, y1, z0, z1, - seed, WorkerNoise3.VALUE); - } - }; - - public static final Function3D GRADIENT = new Function3D() { - @Override - public double get(double x, double y, double z, long seed, - Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int z0 = fastFloor(z); - int x1 = x0 + 1; - int y1 = y0 + 1; - int z1 = z0 + 1; - double xs = interpolator.interpolate(x - (double) x0); - double ys = interpolator.interpolate(y - (double) y0); - double zs = interpolator.interpolate(z - (double) z0); - return interpolateXYZ3(x, y, z, xs, ys, zs, x0, x1, y0, y1, z0, z1, - seed, WorkerNoise3.GRADIENT); - } - }; - - public static final Function3D GRADVAL = new Function3D() { - @Override - public double get(double x, double y, double z, long seed, - Interpolator interpolator) { - return Function3D.VALUE.get(x, y, z, seed, interpolator) - + Function3D.GRADIENT.get(x, y, z, seed, interpolator); - } - }; - - public static final Function3D WHITE = new Function3D() { - @Override - public double get(double x, double y, double z, long seed, - Interpolator interpolator) { - int hash = computeHashDouble3(x, y, z, seed); - return NoiseLUT.whitenoiseLUT[hash]; - } - }; - - public static final Function3D SIMPLEX = new Function3D() { - @Override - public double get(double x, double y, double z, long seed, - Interpolator interpolator) { - double n0, n1, n2, n3; - - double s = (x + y + z) * F3; - int i = fastFloor(x + s); - int j = fastFloor(y + s); - int k = fastFloor(z + s); - - double t = (i + j + k) * G3; - double X0 = i - t; - double Y0 = j - t; - double Z0 = k - t; - - double x0 = x - X0; - double y0 = y - Y0; - double z0 = z - Z0; - - int i1, j1, k1; - int i2, j2, k2; - - if (x0 >= y0) { - if (y0 >= z0) { - i1 = 1; - j1 = 0; - k1 = 0; - i2 = 1; - j2 = 1; - k2 = 0; - } else if (x0 >= z0) { - i1 = 1; - j1 = 0; - k1 = 0; - i2 = 1; - j2 = 0; - k2 = 1; - } else { - i1 = 0; - j1 = 0; - k1 = 1; - i2 = 1; - j2 = 0; - k2 = 1; - } - } else { - if (y0 < z0) { - i1 = 0; - j1 = 0; - k1 = 1; - i2 = 0; - j2 = 1; - k2 = 1; - } else if (x0 < z0) { - i1 = 0; - j1 = 1; - k1 = 0; - i2 = 0; - j2 = 1; - k2 = 1; - } else { - i1 = 0; - j1 = 1; - k1 = 0; - i2 = 1; - j2 = 1; - k2 = 0; - } - } - - double x1 = x0 - i1 + G3; - double y1 = y0 - j1 + G3; - double z1 = z0 - k1 + G3; - double x2 = x0 - i2 + 2.0 * G3; - double y2 = y0 - j2 + 2.0 * G3; - double z2 = z0 - k2 + 2.0 * G3; - double x3 = x0 - 1.0 + 3.0 * G3; - double y3 = y0 - 1.0 + 3.0 * G3; - double z3 = z0 - 1.0 + 3.0 * G3; - - int h0, h1, h2, h3; - - h0 = hashCoords3(i, j, k, seed); - h1 = hashCoords3(i + i1, j + j1, k + k1, seed); - h2 = hashCoords3(i + i2, j + j2, k + k2, seed); - h3 = hashCoords3(i + 1, j + 1, k + 1, seed); - - double[] g0 = NoiseLUT.gradient3DLUT[h0]; - double[] g1 = NoiseLUT.gradient3DLUT[h1]; - double[] g2 = NoiseLUT.gradient3DLUT[h2]; - double[] g3 = NoiseLUT.gradient3DLUT[h3]; - - double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0; - if (t0 < 0.0) - n0 = 0.0; - else { - t0 *= t0; - n0 = t0 * t0 * arrayDot3(g0, x0, y0, z0); - } - - double t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1; - if (t1 < 0.0) - n1 = 0.0; - else { - t1 *= t1; - n1 = t1 * t1 * arrayDot3(g1, x1, y1, z1); - } - - double t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2; - if (t2 < 0) - n2 = 0.0; - else { - t2 *= t2; - n2 = t2 * t2 * arrayDot3(g2, x2, y2, z2); - } - - double t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3; - if (t3 < 0) - n3 = 0.0; - else { - t3 *= t3; - n3 = t3 * t3 * arrayDot3(g3, x3, y3, z3); - } - - return (32.0 * (n0 + n1 + n2 + n3)) * 1.25086885 + 0.0003194984; - } - }; - - public double get(double x, double y, double z, long seed, - Interpolator interpolator); - } - - // ========================================================================== - // = 4D noise functions - // ========================================================================== - - public static interface Function4D { - - public static final Function4D VALUE = new Function4D() { - @Override - public double get(double x, double y, double z, double w, long seed, - Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int z0 = fastFloor(z); - int w0 = fastFloor(w); - int x1 = x0 + 1; - int y1 = y0 + 1; - int z1 = z0 + 1; - int w1 = w0 + 1; - double xs = interpolator.interpolate(x - (double) x0); - double ys = interpolator.interpolate(y - (double) y0); - double zs = interpolator.interpolate(z - (double) z0); - double ws = interpolator.interpolate(w - (double) w0); - return interpolateXYZW4(x, y, z, w, xs, ys, zs, ws, x0, x1, y0, y1, z0, - z1, w0, w1, seed, WorkerNoise4.VALUE); - } - }; - - public static final Function4D GRADIENT = new Function4D() { - @Override - public double get(double x, double y, double z, double w, long seed, - Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int z0 = fastFloor(z); - int w0 = fastFloor(w); - int x1 = x0 + 1; - int y1 = y0 + 1; - int z1 = z0 + 1; - int w1 = w0 + 1; - double xs = interpolator.interpolate(x - (double) x0); - double ys = interpolator.interpolate(y - (double) y0); - double zs = interpolator.interpolate(z - (double) z0); - double ws = interpolator.interpolate(w - (double) w0); - return interpolateXYZW4(x, y, z, w, xs, ys, zs, ws, x0, x1, y0, y1, z0, - z1, w0, w1, seed, WorkerNoise4.GRADIENT); - } - }; - - public static final Function4D GRADVAL = new Function4D() { - @Override - public double get(double x, double y, double z, double w, long seed, - Interpolator interpolator) { - return Function4D.VALUE.get(x, y, z, w, seed, interpolator) - + Function4D.GRADIENT.get(x, y, z, w, seed, interpolator); - } - }; - - public static final Function4D WHITE = new Function4D() { - @Override - public double get(double x, double y, double z, double w, long seed, - Interpolator interpolator) { - int hash = computeHashDouble4(x, y, z, w, seed); - return NoiseLUT.whitenoiseLUT[hash]; - } - }; - - public static final Function4D SIMPLEX = new Function4D() { - @Override - public double get(double x, double y, double z, double w, long seed, - Interpolator interpolator) { - final 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 } }; - - double F4 = (Math.sqrt(5.0) - 1.0) / 4.0; - double G4 = (5.0 - Math.sqrt(5.0)) / 20.0; - double n0, n1, n2, n3, n4; - double s = (x + y + z + w) * F4; - int i = fastFloor(x + s); - int j = fastFloor(y + s); - int k = fastFloor(z + s); - int l = fastFloor(w + s); - double t = (i + j + k + l) * G4; - double X0 = i - t; - double Y0 = j - t; - double Z0 = k - t; - double W0 = l - t; - double x0 = x - X0; - double y0 = y - Y0; - double z0 = z - Z0; - double w0 = w - W0; - int c1 = (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; - int i2, j2, k2, l2; - int i3, j3, k3, l3; - i1 = simplex[c][0] >= 3 ? 1 : 0; - j1 = simplex[c][1] >= 3 ? 1 : 0; - k1 = simplex[c][2] >= 3 ? 1 : 0; - l1 = simplex[c][3] >= 3 ? 1 : 0; - 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; - 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; - double x1 = x0 - i1 + G4; - double y1 = y0 - j1 + G4; - double z1 = z0 - k1 + G4; - double w1 = w0 - l1 + G4; - double x2 = x0 - i2 + 2.0 * G4; - 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; - 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; - double y4 = y0 - 1.0 + 4.0 * G4; - double z4 = z0 - 1.0 + 4.0 * G4; - double w4 = w0 - 1.0 + 4.0 * G4; - int h0, h1, h2, h3, h4; - h0 = hashCoords4(i, j, k, l, seed); - h1 = hashCoords4(i + i1, j + j1, k + k1, l + l1, seed); - h2 = hashCoords4(i + i2, j + j2, k + k2, l + l2, seed); - h3 = hashCoords4(i + i3, j + j3, k + k3, l + l3, seed); - h4 = hashCoords4(i + 1, j + 1, k + 1, l + 1, seed); - double[] g0 = NoiseLUT.gradient4DLUT[h0]; - double[] g1 = NoiseLUT.gradient4DLUT[h1]; - double[] g2 = NoiseLUT.gradient4DLUT[h2]; - double[] g3 = NoiseLUT.gradient4DLUT[h3]; - double[] g4 = NoiseLUT.gradient4DLUT[h4]; - double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0; - if (t0 < 0) - n0 = 0.0; - else { - t0 *= t0; - n0 = t0 * t0 * arrayDot4(g0, 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 * arrayDot4(g1, 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 * arrayDot4(g2, 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 * arrayDot4(g3, 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 * arrayDot4(g4, x4, y4, z4, w4); - } - return 27.0 * (n0 + n1 + n2 + n3 + n4); - } - }; - - public double get(double x, double y, double z, double w, long seed, - Interpolator interpolator); - } - - // ========================================================================== - // = 6D noise functions - // ========================================================================== - - public static interface Function6D { - - public static final Function6D VALUE = new Function6D() { - @Override - public double get(double x, double y, double z, double w, double u, - double v, long seed, Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int z0 = fastFloor(z); - int w0 = fastFloor(w); - int u0 = fastFloor(u); - int v0 = fastFloor(v); - - int x1 = x0 + 1; - int y1 = y0 + 1; - int z1 = z0 + 1; - int w1 = w0 + 1; - int u1 = u0 + 1; - int v1 = v0 + 1; - - double xs = interpolator.interpolate((x - (double) x0)); - double ys = interpolator.interpolate((y - (double) y0)); - double zs = interpolator.interpolate((z - (double) z0)); - double ws = interpolator.interpolate((w - (double) w0)); - double us = interpolator.interpolate((u - (double) u0)); - double vs = interpolator.interpolate((v - (double) v0)); - - return interpolateXYZWUV6(x, y, z, w, u, v, xs, ys, zs, ws, us, vs, x0, - x1, y0, y1, z0, z1, w0, w1, u0, u1, v0, v1, seed, - WorkerNoise6.VALUE); - } - }; - - public static final Function6D GRADIENT = new Function6D() { - @Override - public double get(double x, double y, double z, double w, double u, - double v, long seed, Interpolator interpolator) { - int x0 = fastFloor(x); - int y0 = fastFloor(y); - int z0 = fastFloor(z); - int w0 = fastFloor(w); - int u0 = fastFloor(u); - int v0 = fastFloor(v); - - int x1 = x0 + 1; - int y1 = y0 + 1; - int z1 = z0 + 1; - int w1 = w0 + 1; - int u1 = u0 + 1; - int v1 = v0 + 1; - - double xs = interpolator.interpolate((x - (double) x0)); - double ys = interpolator.interpolate((y - (double) y0)); - double zs = interpolator.interpolate((z - (double) z0)); - double ws = interpolator.interpolate((w - (double) w0)); - double us = interpolator.interpolate((u - (double) u0)); - double vs = interpolator.interpolate((v - (double) v0)); - - return interpolateXYZWUV6(x, y, z, w, u, v, xs, ys, zs, ws, us, vs, x0, - x1, y0, y1, z0, z1, w0, w1, u0, u1, v0, v1, seed, - WorkerNoise6.GRADIENT); - } - }; - - public static final Function6D GRADVAL = new Function6D() { - @Override - public double get(double x, double y, double z, double w, double u, - double v, long seed, Interpolator interpolator) { - return Function6D.VALUE.get(x, y, z, w, u, v, seed, interpolator) - + Function6D.GRADIENT.get(x, y, z, w, u, v, seed, interpolator); - } - }; - - public static final Function6D WHITE = new Function6D() { - @Override - public double get(double x, double y, double z, double w, double u, - double v, long seed, Interpolator interpolator) { - int hash = computeHashDouble6(x, y, z, w, u, v, seed); - return NoiseLUT.whitenoiseLUT[hash]; - } - }; - - public static final Function6D SIMPLEX = new Function6D() { - @Override - public double get(double x, double y, double z, double w, double u, - double v, long seed, Interpolator interpolator) { - - double F4 = (Math.sqrt(7.0) - 1.0) / 6.0; - double G4 = F4 / (1.0 + 6.0 * F4); - - double sideLength = Math.sqrt(6.0) / (6.0 * F4 + 1.0); - double a = Math.sqrt((sideLength * sideLength) - - ((sideLength / 2.0) * (sideLength / 2.0))); - double cornerFace = Math.sqrt(a * a + (a / 2.0) * (a / 2.0)); - - double cornerFaceSqrd = cornerFace * cornerFace; - - double valueScaler = Math.pow(5.0, -0.5); - valueScaler *= Math.pow(5.0, -3.5) * 100 + 13; - - double[] loc = { x, y, z, w, u, v }; - double s = 0; - for (int c = 0; c < 6; ++c) - s += loc[c]; - s *= F4; - - int[] skewLoc = { fastFloor(x + s), fastFloor(y + s), fastFloor(z + s), - fastFloor(w + s), fastFloor(u + s), fastFloor(v + s) }; - int[] intLoc = { fastFloor(x + s), fastFloor(y + s), fastFloor(z + s), - fastFloor(w + s), fastFloor(u + s), fastFloor(v + s) }; - double unskew = 0.0; - for (int c = 0; c < 6; ++c) - unskew += skewLoc[c]; - unskew *= G4; - double[] cellDist = { loc[0] - (double) skewLoc[0] + unskew, - loc[1] - (double) skewLoc[1] + unskew, - loc[2] - (double) skewLoc[2] + unskew, - loc[3] - (double) skewLoc[3] + unskew, - loc[4] - (double) skewLoc[4] + unskew, - loc[5] - (double) skewLoc[5] + unskew }; - int[] distOrder = { 0, 1, 2, 3, 4, 5 }; - sortBy6(cellDist, distOrder); - - int[] newDistOrder = { -1, distOrder[0], distOrder[1], distOrder[2], - distOrder[3], distOrder[4], distOrder[5] }; - - double n = 0.0; - double skewOffset = 0.0; - - for (int c = 0; c < 7; ++c) { - int i = newDistOrder[c]; - if (i != -1) intLoc[i] += 1; - - double[] m = new double[6]; - for (int d = 0; d < 6; ++d) { - m[d] = cellDist[d] - (intLoc[d] - skewLoc[d]) + skewOffset; - } - - double t = cornerFaceSqrd; - - for (int d = 0; d < 6; ++d) { - t -= m[d] * m[d]; - } - - if (t > 0.0) { - int h = hashCoords6(intLoc[0], intLoc[1], intLoc[2], intLoc[3], - intLoc[4], intLoc[5], seed); - double[] vec = NoiseLUT.gradient6DLUT[h]; - double gr = 0.0; - for (int d = 0; d < 6; ++d) { - gr += vec[d] * m[d]; - } - - n += gr * t * t * t * t; - } - skewOffset += G4; - } - n *= valueScaler; - return n; - } - }; - - public double get(double x, double y, double z, double w, double u, - double v, long seed, Interpolator interpolator); - } - - // ========================================================================== - // = Cellular functions - // ========================================================================== - - public static void cellularFunction2D(double x, double y, long seed, - double[] f, double[] disp) { - int xint = fastFloor(x); - int yint = fastFloor(y); - - for (int c = 0; c < 4; ++c) { - f[c] = 99999.0; - disp[c] = 0.0; - } - - for (int ycur = yint - 3; ycur <= yint + 3; ++ycur) { - for (int xcur = xint - 3; xcur <= xint + 3; ++xcur) { - - double xpos = (double) xcur - + WorkerNoise2.VALUE.calculate(x, y, xcur, ycur, seed); - double ypos = (double) ycur - + WorkerNoise2.VALUE.calculate(x, y, xcur, ycur, seed + 1); - double xdist = xpos - x; - double ydist = ypos - y; - double dist = (xdist * xdist + ydist * ydist); - int xval = fastFloor(xpos); - int yval = fastFloor(ypos); - double dsp = WorkerNoise2.VALUE.calculate(x, y, xval, yval, seed + 3); - addDist(f, disp, dist, dsp); - } - } - - } - - public static void cellularFunction3D(double x, double y, double z, - long seed, double[] f, double[] disp) { - int xint = fastFloor(x); - int yint = fastFloor(y); - int zint = fastFloor(z); - - for (int c = 0; c < 4; ++c) { - f[c] = 99999.0; - disp[c] = 0.0; - } - - for (int zcur = zint - 2; zcur <= zint + 2; ++zcur) { - for (int ycur = yint - 2; ycur <= yint + 2; ++ycur) { - for (int xcur = xint - 2; xcur <= xint + 2; ++xcur) { - double xpos = (double) xcur - + WorkerNoise3.VALUE.calculate(x, y, z, xcur, ycur, zcur, seed); - double ypos = (double) ycur - + WorkerNoise3.VALUE.calculate(x, y, z, xcur, ycur, zcur, - seed + 1); - double zpos = (double) zcur - + WorkerNoise3.VALUE.calculate(x, y, z, xcur, ycur, zcur, - seed + 2); - double xdist = xpos - x; - double ydist = ypos - y; - double zdist = zpos - z; - double dist = (xdist * xdist + ydist * ydist + zdist * zdist); - int xval = fastFloor(xpos); - int yval = fastFloor(ypos); - int zval = fastFloor(zpos); - double dsp = WorkerNoise3.VALUE.calculate(x, y, z, xval, yval, zval, - seed + 3); - addDist(f, disp, dist, dsp); - } - } - } - } - - public static void cellularFunction4D(double x, double y, double z, double w, - long seed, double[] f, double[] disp) { - int xint = fastFloor(x); - int yint = fastFloor(y); - int zint = fastFloor(z); - int wint = fastFloor(w); - - for (int c = 0; c < 4; ++c) { - f[c] = 99999.0; - disp[c] = 0.0; - } - - for (int wcur = wint - 2; wcur <= wint + 2; ++wcur) { - for (int zcur = zint - 2; zcur <= zint + 2; ++zcur) { - for (int ycur = yint - 2; ycur <= yint + 2; ++ycur) { - for (int xcur = xint - 2; xcur <= xint + 2; ++xcur) { - double xpos = (double) xcur - + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur, - wcur, seed); - double ypos = (double) ycur - + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur, - wcur, seed + 1); - double zpos = (double) zcur - + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur, - wcur, seed + 2); - double wpos = (double) wcur - + WorkerNoise4.VALUE.calculate(x, y, z, w, xcur, ycur, zcur, - wcur, seed + 3); - double xdist = xpos - x; - double ydist = ypos - y; - double zdist = zpos - z; - double wdist = wpos - w; - double dist = (xdist * xdist + ydist * ydist + zdist * zdist + wdist - * wdist); - int xval = fastFloor(xpos); - int yval = fastFloor(ypos); - int zval = fastFloor(zpos); - int wval = fastFloor(wpos); - double dsp = WorkerNoise4.VALUE.calculate(x, y, z, w, xval, yval, - zval, wval, seed + 3); - addDist(f, disp, dist, dsp); - } - } - } - } - } - - public static void cellularFunction6D(double x, double y, double z, double w, - double u, double v, long seed, double[] f, double[] disp) { - int xint = fastFloor(x); - int yint = fastFloor(y); - int zint = fastFloor(z); - int wint = fastFloor(w); - int uint = fastFloor(u); - int vint = fastFloor(v); - - for (int c = 0; c < 4; ++c) { - f[c] = 99999.0; - disp[c] = 0.0; - } - - for (int vcur = vint - 1; vcur <= vint + 1; ++vcur) { - for (int ucur = uint - 1; ucur <= uint + 1; ++ucur) { - - for (int wcur = wint - 2; wcur <= wint + 2; ++wcur) { - for (int zcur = zint - 2; zcur <= zint + 2; ++zcur) { - for (int ycur = yint - 2; ycur <= yint + 2; ++ycur) { - for (int xcur = xint - 2; xcur <= xint + 2; ++xcur) { - double xpos = (double) xcur - + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur, - ycur, zcur, wcur, ucur, vcur, seed); - double ypos = (double) ycur - + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur, - ycur, zcur, wcur, ucur, vcur, seed + 1); - double zpos = (double) zcur - + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur, - ycur, zcur, wcur, ucur, vcur, seed + 2); - double wpos = (double) wcur - + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur, - ycur, zcur, wcur, ucur, vcur, seed + 3); - double upos = (double) ucur - + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur, - ycur, zcur, wcur, ucur, vcur, seed + 4); - double vpos = (double) vcur - + WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, xcur, - ycur, zcur, wcur, ucur, vcur, seed + 5); - double xdist = xpos - x; - double ydist = ypos - y; - double zdist = zpos - z; - double wdist = wpos - w; - double udist = upos - u; - double vdist = vpos - v; - double dist = (xdist * xdist + ydist * ydist + zdist * zdist - + wdist * wdist + udist * udist + vdist * vdist); - int xval = fastFloor(xpos); - int yval = fastFloor(ypos); - int zval = fastFloor(zpos); - int wval = fastFloor(wpos); - int uval = fastFloor(upos); - int vval = fastFloor(vpos); - double dsp = WorkerNoise6.VALUE.calculate(x, y, z, w, u, v, - xval, yval, zval, wval, uval, vval, seed + 6); - addDist(f, disp, dist, dsp); - } - } - } - } - } - } - } - - public static double intValueNoise3D(int x, int y, int z, int seed) { - int n = (1619 * x + 31337 * y + 6971 * z + 1013 * seed) & 0x7fffffff; - n = (n >> 13) ^ n; - return (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; - } - - public static double valueNoise3D(int x, int y, int z, int seed) { - return 1.0 - ((double) intValueNoise3D(x, y, z, seed) / 1073741824.0); - } - -} diff --git a/src/com/sudoplay/joise/noise/NoiseLUT.java b/src/com/sudoplay/joise/noise/NoiseLUT.java deleted file mode 100755 index ab5e63ba5..000000000 --- a/src/com/sudoplay/joise/noise/NoiseLUT.java +++ /dev/null @@ -1,1121 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.noise; - -public class NoiseLUT { - - private NoiseLUT() {} - - public static final double[][] gradient2DLUT = { { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, - { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, - { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, - { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, - { 1, 0 }, { -1, 0 } }; - - public static final double[][] gradient3DLUT = { { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, - { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, - { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, - { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, { 0, 0, -1 }, - { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 }, { 1, 0, 0 }, { -1, 0, 0 }, - { 0, 0, 1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, -1, 0 } }; - - public static final double[][] gradient4DLUT = { - { 0.22552454980774, 0.66749286953929, 0.53967936463105, -0.46080161668515 }, - { 0.52981737633302, 0.80705123608169, 0.25001068952995, 0.073868160904199 }, - { 0.2551718844115, 0.40169779308827, -0.87581570003174, 0.080455279577005 }, - { 0.2446720608745, -0.57667976542766, -0.10969185644738, 0.77171479667222 }, - { 0.56152621692767, -0.4292067323737, 0.16103874251227, -0.68886603341873 }, - { -0.47332175931021, 0.093442231646057, -0.75172946705559, - 0.44959745313871 }, - { 0.36614231721753, 0.4625818257178, -0.50122840201262, 0.63303076313402 }, - { 0.50134394883212, -0.32248055428503, 0.80140206134118, - -0.049145428633102 }, - { 0.23609302357006, 0.78968939092939, 0.46805407624526, -0.31871010618635 }, - { 0.3566224687564, 0.82280076001748, -0.42198348844058, -0.13322634715498 }, - { 0.53249173494918, 0.35833499357915, 0.62048711191207, -0.45060440359416 }, - { -0.10495021075845, -0.57318889402664, -0.51484484295083, - -0.62878830516575 }, - { 0.48320530716683, -0.57172831979762, -0.61957401150899, - -0.2361512306338 }, - { 0.56139247202719, -0.59285009197507, -0.5563962302756, 0.15424167961823 }, - { -0.12102422542118, -0.49213994645356, 0.4794977231538, -0.7164030593571 }, - { -0.39415630019406, -0.16750296810702, -0.77313995219119, - -0.46780143332237 }, - { -0.077996875735257, -0.72521264783548, 0.21322391118796, - -0.65001435868195 }, - { 0.36675239692246, -0.32607458507754, -0.86882175267727, - -0.065702407816875 }, - { 0.54875576857984, 0.35330602237706, -0.70129121026282, - -0.28676226985181 }, - { -0.5812728198809, 0.52878141440118, -0.48813116423404, - -0.37978953534178 }, - { -0.22120336443784, -0.50216367205327, 0.23141872050005, - -0.80333435992336 }, - { -0.62382494805532, -0.47276765886765, -0.5623445209171, - -0.26664923533941 }, - { -0.34810294100203, 0.77605534406345, -0.015707133464448, - -0.52565742777462 }, - { 0.69115837887353, -0.3936531009971, 0.089410248049089, 0.59945236585744 }, - { 0.3133597935846, -0.79750731117234, -0.24841572824554, 0.45174921621572 }, - { 0.15712455106329, -0.49358619043723, -0.56123861872675, - -0.64551976028044 }, - { 0.12957880127654, -0.537223110548, -0.5612004467528, 0.61616127946936 }, - { 0.14715736388495, -0.54550513683857, 0.70400607913576, -0.4302839719035 }, - { -0.27603940501488, 0.66664669430619, -0.20940134756402, - -0.65995114022784 }, - { -0.28542058243422, -0.26629956698313, -0.48526805245045, - 0.78239027922032 }, - { 0.90830597179735, -0.30802834137341, 0.13130250877935, - -0.25071588241727 }, - { -0.68975034153593, 0.29656664042552, 0.66049372644302, - -0.0063821209016788 }, - { 0.23754231359754, 0.86360891835925, -0.37634599141988, - -0.23689022800294 }, - { -0.3008221008451, 0.71840381218331, -0.19107614574202, 0.59740432942188 }, - { -0.2544530858471, 0.33459224995788, 0.893299034533, 0.15911784398182 }, - { -0.30908481589984, -0.76069512866564, -0.024337358188341, - 0.57027816966892 }, - { 0.097288831244174, 0.96921511737704, -0.095017157071808, - -0.205252720871 }, - { 0.63294540707629, -0.14805006160837, -0.42005382286916, - -0.6332583018104 }, - { -0.67195172729974, -0.10550185088633, 0.18728512185188, - -0.70871328389651 }, - { -0.69993983031639, -0.27629564601678, 0.47717744770779, - 0.45392359855806 }, - { 0.45229382710377, 0.10953589230206, -0.86039839883114, 0.20771802413423 }, - { 0.57507084430014, 0.49537901571099, 0.63765893106374, 0.13146954956864 }, - { 0.49273255198119, 0.7371708819457, -0.29362806469134, 0.35717822253761 }, - { 0.65308805992157, -0.50561647234808, 0.37455865201808, 0.42134758226026 }, - { 0.015875966700541, 0.70304296752082, 0.628464130577, 0.3324325135707 }, - { -0.61291521126741, 0.30295474138901, 0.43959142245302, -0.5825055791773 }, - { 0.28870150781935, -0.055081790563628, 0.65913922715236, - -0.69220872210637 }, - { -0.079733017226467, -0.22918659811981, 0.95837698208327, - -0.15043174338946 }, - { -0.35025365580024, -0.58440279590723, 0.61398669509432, - -0.39851736095375 }, - { -0.49583300276112, 0.8320520239064, 0.12466582301665, -0.2151685280373 }, - { -0.57838068316419, -0.20866225618262, -0.25891317127095, - 0.74491598044996 }, - { 0.24517181230967, 0.87106847894657, 0.38643251825943, 0.178326656073 }, - { -0.032939982735198, 0.72735694715047, 0.59789863494626, - 0.33523730594724 }, - { 0.46839767570091, 0.28725504887534, -0.82223460003592, - -0.14838603976579 }, - { -0.68530688721453, 0.30062191695867, -0.65188139443225, - 0.12260334813328 }, - { -0.09481691601797, -0.72846602189708, -0.47810363374399, - -0.48141865645099 }, - { -0.71095576728456, -0.44889238701561, -0.38663259872485, - 0.37888356449908 }, - { 0.65266817536949, -0.048437131039962, 0.073940142453456, - 0.75246990141163 }, - { -0.58567515556267, 0.80836413944392, -0.052196260915081, - 0.028417961999587 }, - { 0.4307524920894, 0.78828122681196, 0.28407778104785, -0.33520861016616 }, - { -0.047152592626151, 0.080906814134336, 0.95331289758053, - -0.28709796192567 }, - { -0.092934311395387, -0.93376149171941, -0.1711922375466, - -0.30024308177073 }, - { 0.35964306202515, 0.79090749262634, -0.44772535519024, 0.21133909331798 }, - { 0.78826512774619, -0.22601198404862, 0.57215985576402, - -0.013775735834394 }, - { 0.090244004443892, -0.73057802155678, -0.077209310249513, - -0.6724213682587 }, - { -0.0054007086447244, 0.64607993441819, -0.46651331454209, - 0.60408350254189 }, - { -0.70185725868085, 0.5369402202072, 0.36637576194925, -0.29130806617212 }, - { -0.32396804158331, 0.70188757706857, -0.30408596246687, - -0.55671380854088 }, - { 0.56090670073868, -0.48169400187882, -0.66248222629843, - 0.12029905011714 }, - { -0.21148730570035, -0.66324178429788, 0.42537806814415, - -0.57830524312938 }, - { 0.49184121803223, -0.53433759959622, 0.41996352447612, - -0.54424827423881 }, - { -0.62991318148171, 0.6560831504895, -0.018944460160231, - -0.41521728151487 }, - { -0.74278663987202, -0.57070585901822, -0.26473071464775, - -0.2290861821062 }, - { 0.5025495101175, -0.37409188240791, 0.47531478480926, 0.61771766102232 }, - { -0.22227660391851, 0.082683771800495, -0.17294940947311, - 0.95595240833119 }, - { 0.47549422210941, 0.27384409989549, -0.73038192404162, - -0.40676393488884 }, - { 0.59221657484784, 0.050200153729467, 0.70240850515692, 0.3916398408286 }, - { 0.89287935537108, -0.18228187488468, 0.20326879532789, 0.35808039835574 }, - { -0.63303616764545, -0.56090787852805, 0.5182368140323, 0.12679971151219 }, - { 0.78287411316931, 0.49854614640923, 0.30404279624908, -0.2147506481455 }, - { -0.41503470490899, -0.6268605824938, -0.35991041023467, - 0.55250022664371 }, - { -0.53157442679059, 0.048919235389262, -0.84511446630526, - -0.028584541849774 }, - { 0.63177262851732, -0.27840711796915, 0.58586252075951, - -0.42440302695638 }, - { -0.44119538483073, 0.5829738945766, -0.51924450975423, 0.44257565425174 }, - { 0.61392386167432, -0.58465170951844, 0.20613607919186, 0.48865917312527 }, - { 0.24475051899163, 0.30754543456076, -0.15222721025769, 0.90682956810601 }, - { 0.41724992835443, -0.13224180301206, 0.89274161403018, 0.10689720951984 }, - { -0.76873245399282, 0.075325506550414, -0.61855849417628, - 0.14408980367632 }, - { 0.53191194272188, 0.53084656080533, 0.3798738941559, -0.5394139770249 }, - { 0.75910942848531, 0.39530213014524, -0.29984000888542, 0.4214084367439 }, - { -0.03541957430639, -0.62483127808284, 0.75776450849439, - 0.18472757604531 }, - { 0.4625891622941, -0.2531420033374, 0.56439885635973, -0.63512543958985 }, - { 0.660548158654, 0.076935839301002, 0.62489061261352, 0.40898499849916 }, - { -0.13772992864036, -0.35663701661207, -0.70063282711493, - -0.60245675920161 }, - { 0.3331436864299, 0.15331116273714, -0.48119522685978, 0.79621738565511 }, - { 0.71571654511597, -0.26028084726799, 0.52940810879996, - -0.37380578102748 }, - { -0.45879392024731, 0.070422886390706, -0.88044825819407, - -0.096745131451335 }, - { -0.3710610095712, 0.49491399293823, -0.19875303607171, 0.76017833264453 }, - { 0.67521169438188, -0.21089530160678, 0.30499481128614, - -0.63764449705041 }, - { 0.37955387270282, 0.37946220745499, 0.64929517854168, -0.53885346983406 }, - { -0.76118100241106, -0.2502648698634, -0.48213952651367, - 0.35427736796742 }, - { -0.81826013990967, 0.29678177941379, 0.27395924681324, -0.4090443129155 }, - { -0.48735224983659, 0.75897371421789, 0.029778664412101, - 0.43076666172228 }, - { -0.42267571253102, -0.28154084743402, -0.55892959867618, - 0.65549805261817 }, - { -0.34623389175769, -0.19627361980202, 0.62165029251141, - 0.67464781344685 }, - { 0.4829697897084, -0.57358816947082, 0.66156267623348, - 0.0084628297236668 }, - { 0.74866979663621, -0.0035805505812814, -0.64318857973023, - -0.16059005625143 }, - { -0.090152317154269, 0.6862809022405, 0.64123846108899, 0.33121642313131 }, - { -0.78321651600427, -0.19115065168422, -0.56201602070159, - 0.18485483465027 }, - { -0.73377708689206, 0.0284256453642, 0.67360273611538, 0.08380049722821 }, - { 0.49834502400233, -0.35880739756757, -0.78920001543545, - 0.0085337060880708 }, - { -0.8413442675025, -0.49848949817935, -0.033350567138177, - 0.20624205055503 }, - { 0.62993466610518, -0.0034911977529077, -0.075714594190885, - -0.77294076629695 }, - { -0.17272033203772, -0.29580796453879, -0.37548041615855, - -0.86120833257558 }, - { -0.47432431050844, -0.60995101955389, -0.62418813212925, - 0.11560872767599 }, - { 0.23618736517714, -0.40605404979081, 0.6180271784331, 0.63037928574564 }, - { 0.55500851198302, 0.41920843999997, -0.40467056584228, - -0.59369316031101 }, - { -0.17861281311101, 0.6681171368602, 0.72039649788735, 0.052400765814444 }, - { 0.051032005226464, 0.77077381574869, -0.21368401455548, - 0.59803227448209 }, - { -0.27130398085814, -0.2356472352851, 0.54860265705132, 0.75491698560123 }, - { 0.34863907202149, -0.1008710712593, 0.31299887927802, -0.87767165045574 }, - { 0.65671708149768, 0.18729913477315, 0.690161625609, 0.23941311476012 }, - { 0.21543450079531, 0.62368781511756, 0.6740194876821, -0.33211325683525 }, - { -0.29368781227182, -0.70194271867824, 0.64731835728572, - -0.044753021557358 }, - { 0.47957288380265, -0.48010386819579, -0.41528424196963, - -0.60584579163047 }, - { 0.77465998420784, 0.2064625496211, -0.59762679675591, - -0.010832186775088 }, - { 0.59374912564074, 0.44398057182928, -0.628531238492, -0.23514189307461 }, - { 0.29933292179378, -0.13849303742408, -0.75484941644759, - -0.56694077204253 }, - { 0.67864785518517, -0.66598612231715, -0.20117390931759, - -0.23543286037301 }, - { 0.41139382663025, -0.50162129081774, 0.76099758294395, - -0.0037254210934192 }, - { -0.63872455601276, 0.22070744447973, -0.66020520498325, - -0.32779300299205 }, - { 0.29418192945737, 0.76084869464354, 0.56579367268056, -0.12018226239594 }, - { 0.57883638224948, 0.54835864232767, -0.58981423708497, - -0.12794689406458 }, - { -0.49577506786442, -0.40376295003701, 0.74730897396085, - -0.18086420237026 }, - { -0.23542938066082, -0.82998760453564, 0.044423043427579, - 0.50370643856465 }, - { 0.51460246995974, -0.20375144052087, -0.58171443714984, - 0.59605197928405 }, - { -0.57420458168785, 0.50828481072877, -0.64181398835659, - -0.0032332492798049 }, - { -0.59114159943176, -0.70202688911205, 0.3951425902627, - -0.039650847978142 }, - { 0.32348943025434, 0.15426522631209, 0.48865478831089, -0.79547050625742 }, - { 0.78091367446976, 0.24332864387958, -0.57453483550803, - 0.029575782012119 }, - { 0.29640854502528, 0.81484848881134, 0.33564412795113, 0.36811266494077 }, - { 0.067881648517454, 0.59549997670039, 0.50990703475037, -0.6170629428644 }, - { 0.28894916793968, -0.69198564828725, 0.023585472505226, - 0.66114141180095 }, - { -0.48325755685412, 0.44101587160833, 0.32395739272709, - -0.68338769555092 }, - { -0.5710256256505, -0.12907895901829, -0.17172158524436, - 0.79232572490761 }, - { 0.6847915554189, 0.46529665784725, 0.53390899832342, 0.17175775770671 }, - { 0.42165492939873, 0.79428961452838, 0.38934026723474, 0.19931202943048 }, - { -0.63847181078, 0.53274793784908, 0.28633773611669, -0.47596647196249 }, - { 0.19156995438377, -0.77779812107245, -0.14338187979369, - -0.58118213322537 }, - { 0.44339330307, 0.062294908508799, 0.49992742799503, 0.74134626855797 }, - { 0.11414857945734, -0.80669520663252, -0.039462641492769, - 0.57849429152793 }, - { 0.51140504554998, 0.77475373616074, 0.37094692794394, 0.024897878221959 }, - { -0.42141421118923, 0.41042157807017, -0.78825942772297, - -0.18058589498632 }, - { -0.61241893151874, -0.31986126390856, 0.71454099453741, - 0.10983164978162 }, - { 0.42647810613114, -0.16890980399214, -0.58321474597059, 0.670407684315 }, - { -0.62005519270376, 0.24692971568815, 0.55376487937289, - -0.49789731058161 }, - { -0.2357164754471, 0.80976845323815, -0.53339765737773, - -0.064805358166192 }, - { -0.45289067914353, -0.60809715423324, -0.18106295928925, - -0.62635779593756 }, - { -0.60064300362149, -0.55194968809516, 0.27130873161666, - 0.51085330199654 }, - { 0.1788394866438, -0.29721754352243, -0.50108833389719, - -0.79283582882688 }, - { -0.65652402015051, 0.42070413168568, -0.54025124528414, - 0.31640612591564 }, - { 0.43620946470649, -0.1249196094834, -0.27642429463064, - -0.84717530854301 }, - { 0.2543621682741, 0.27962706507339, -0.8372594728531, 0.39510146411661 }, - { -0.81374681782569, -0.49558273399432, -0.30261128321578, - 0.02530378461355 }, - { -0.67641647228818, 0.48707240260253, 0.33721313271051, 0.43761688012207 }, - { 0.28572653298411, 0.63329777351537, -0.019774894218509, - 0.71895982639366 }, - { 0.65708200570959, -0.34223476177811, -0.041917555540789, - -0.67034433251936 }, - { 0.071864648185965, -0.59386186862736, 0.59510615312859, - 0.53666769964292 }, - { -0.52113381082923, 0.32294388060376, -0.34686930359901, - -0.70979467975741 }, - { 0.25004346113893, -0.42478362076275, -0.0072114313495278, - -0.87004892869956 }, - { -0.73610460974203, 0.39085477297004, 0.080434514738008, - 0.54672921890268 }, - { -0.096982051782443, 0.12922152423063, 0.59661992662453, - -0.78609219717672 }, - { -0.64487244725608, -0.38386246316229, -0.66001973035734, - 0.034104130013256 }, - { 0.40625275106386, 0.61435583542081, -0.52718551420461, - -0.42379363297515 }, - { 0.35878268156959, -0.54570539388485, 0.533316880214, 0.53763715995969 }, - { 0.74780942148728, 0.59755384906022, -0.26296181239253, 0.12067125519944 }, - { 0.011316905138058, 0.067102377315201, -0.065593365654346, - 0.99552333423124 }, - { 0.49827563594909, -0.084377896327059, -0.53850763396471, - 0.67424868512491 }, - { -0.60044976118633, -0.76761748085432, -0.13587914428152, - 0.17821432469774 }, - { -0.089523490602341, 0.050789198860078, 0.84713826909812, - 0.52130869447859 }, - { 0.46769441316167, 0.50567662542845, 0.70334020343911, 0.175686210668 }, - { -0.072408203487527, -0.31419198049473, 0.093326787268646, - -0.94198225155181 }, - { -0.47533232374788, 0.74785636631068, 0.46059616621554, - 0.051197744448182 }, - { -0.76253271533295, -0.055650486369972, 0.42686845243099, - 0.48293913253423 }, - { 0.55865209759069, 0.49155664008023, -0.11550774589067, - -0.65798013958615 }, - { -0.75641809583475, 0.13770124300455, 0.17748717881056, 0.61430312820838 }, - { -0.61344640313317, -0.71640963441606, 0.33111243107609, - 0.028377881980612 }, - { -0.031294256698522, -0.56229739591621, -0.75650470039123, - -0.3324799938786 }, - { -0.31717913354911, -0.35531289896521, -0.26284619748583, - -0.83908403484825 }, - { -0.55737524479375, -0.37655617201624, -0.17745250976186, - 0.71836543109117 }, - { 0.48847471582806, 0.27948593392061, 0.6728110320026, -0.4802138897958 }, - { -0.2401291096457, 0.022664846959043, -0.38631652993552, - -0.89027178665375 }, - { 0.28762309079035, -0.16511988268503, 0.68256059934388, - -0.65124450877502 }, - { -0.70891164838165, 0.31807128215605, -0.3269335982313, 0.53794921377761 }, - { -0.69925979018203, -0.69254454516254, 0.1409638893828, - -0.10745687828272 }, - { -0.64120757688022, -0.40145811379293, -0.28410809936898, - -0.58903889013729 }, - { 0.55206757527974, 0.3654706551822, -0.61301107780799, -0.43112644434103 }, - { 0.83974327448309, -0.41693097107897, 0.037330301823741, - 0.34584136085972 }, - { -0.29447692882523, -0.65463017535059, -0.54293549296166, - -0.43584827909789 }, - { -0.05333405362299, 0.9970375499538, 0.047225492146849, - -0.029006130347889 }, - { 0.36963990470761, 0.71417634995674, -0.13865235293535, 0.57800865654045 }, - { 0.012132225757714, -0.042395617365683, 0.98893274157796, - 0.14165963914058 }, - { -0.58926155813878, -0.12803001087421, 0.79159291473138, - -0.098791648242605 }, - { -0.19438700623313, 0.67901470490797, -0.70701504134766, - -0.035811361809222 }, - { 0.34532714734742, 0.46443499574166, 0.60148495729299, 0.55069514450882 }, - { 0.081003548026406, 0.72421956716693, -0.17809963017465, - 0.66122988851937 }, - { -0.51806271332971, -0.47124904656651, -0.64746889488023, - 0.30053184744748 }, - { -0.21613493655961, -0.91660583460148, -0.10703233312329, - -0.31884716219386 }, - { 0.51867393084966, -0.4936987587863, 0.46464576962979, -0.52090613146226 }, - { 0.70188550832442, -0.1818312879146, -0.68784926160938, - -0.034022187509377 }, - { -0.18536271511511, -0.6668126355463, 0.023834990060033, - 0.72141074719593 }, - { -0.15031909443203, -0.33262730296075, -0.48817739687091, - -0.79274590907714 }, - { 0.20243051601476, -0.5429805329116, 0.6054719468901, 0.54552520436194 }, - { 0.52537152557096, -0.58327808848175, 0.46508915228105, 0.40922305903604 }, - { 0.31485477581576, 0.73539414558825, -0.57616972550483, 0.16760181440614 }, - { -0.1026518864305, -0.84929281956374, 0.44243387033807, 0.26910326498838 }, - { 0.027920771196629, -0.51581324522376, 0.27916735407976, - -0.80945828490641 }, - { 0.52095648805607, -0.31217499797683, 0.78890796559237, - -0.093676731451121 }, - { -0.32665063346977, -0.42237533445303, -0.29678775049627, - -0.79171678752876 }, - { -0.64857997918119, 0.22770551134203, -0.62280006685563, - -0.37364995307697 }, - { -0.60407573890498, -0.71425303787341, -0.057839679785266, - 0.34869710494546 }, - { 0.15576683671559, 0.46059388821688, 0.68108199108405, -0.54746441358124 }, - { -0.42965263988294, -0.4128555315267, -0.80007348682047, - -0.069507803996135 }, - { 0.62468470253348, -0.55608652633181, 0.44736045231719, - -0.31686814821852 }, - { -0.5887363856243, 0.15029359337305, 0.75607823697339, 0.24320156991324 }, - { 0.78882247105678, -0.55978440598547, -0.19260987829514, - -0.16523305587714 }, - { -0.2397762652948, 0.50109182594502, 0.26413811744859, 0.7884449121423 }, - { -0.7830303555834, -0.22084579025076, -0.28393537655337, - -0.50741629960512 }, - { -0.73073108036106, -0.028836092490741, 0.67193346093654, - 0.11707259302706 }, - { 0.024769701828925, -0.022793005056951, -0.61772537208025, - -0.78567315435879 }, - { -0.58543792858876, -0.21000596085194, -0.34309660713653, - -0.70387828944198 }, - { -0.73256166113309, -0.39947841108428, -0.55115200779339, - -0.0013696790967066 }, - { -0.65553402559555, 0.71965699083607, 0.18362339375227, 0.13657015081697 }, - { 0.21014780367008, 0.93277837816337, 0.091205127277356, - -0.27828766160555 }, - { -0.11787197549632, -0.78483975651814, 0.20342129122119, - 0.57336945528955 }, - { -0.6881964578452, -0.22721428035754, -0.50932656202979, - -0.46405361696881 }, - { -0.30800922001431, 0.76151734782072, 0.45056635743119, - -0.34958776709928 }, - { 0.56307840922658, 0.61616965967068, -0.39982036117689, 0.37871009275244 }, - { 0.32091099001565, 0.42988923391959, 0.65069385181346, 0.53740942888953 }, - { -0.65360317449729, 0.21381907132369, -0.37900175759245, 0.6192269073346 }, - { 0.34144172603729, -0.68022974823899, 0.36172522685587, - -0.53838638317427 }, - { -0.082427387138187, -0.81983951792536, -0.062698716423876, - 0.56314985719281 }, - { 0.53660230478027, -0.10888689641277, 0.49610311211367, 0.67385704154904 }, - { 0.37828905310898, 0.24829585477921, 0.45837561130552, 0.7649433702946 }, - { 0.31077471220013, -0.64394458615427, -0.42742602417387, - -0.55322820072594 }, - { -0.74914861903498, -0.44168063108052, -0.42549539767358, - 0.2502962909931 }, - { 0.63772244990386, -0.68871779209415, -0.16359297580573, - 0.30366958690097 }, - { -0.10823423405648, -0.47886043588247, 0.5951258423328, 0.63624151492365 }, - { -0.58450908643191, -0.23751295715095, 0.68158351804545, - -0.37064893226977 }, - { -0.51170891961924, 0.51317237144319, -0.3868723565637, - -0.57020862716758 }, - { -0.65861950006955, 0.33272485253463, -0.34970834814331, - -0.57725089681422 }, - { 0.67192193031742, 0.52947366261195, 0.23487166423469, -0.46153424737329 }, - { -0.44355315014768, 0.64728264624511, 0.5825071861006, -0.21206403986806 }, - { 0.68832586073433, -0.19106885563402, -0.36416840615895, - -0.59756302914981 }, - { 0.062746887857648, 0.79955877089706, 0.59681863174015, - -0.02400251556763 }, - { 0.28392054221674, -0.049695747604861, -0.95198891214713, - 0.10313374581711 } }; - - public static final double[][] gradient6DLUT = { - { 0.31733186658157, 0.043599150809166, -0.63578104939541, - 0.60224147484783, -0.061995657882187, 0.35587048501823 }, - { -0.54645425808647, -0.75981513883963, -0.035144342454363, - 0.13137365402959, 0.29650029456531, 0.13289887942467 }, - { 0.72720729277573, -0.0170513084554, 0.10403853926717, 0.57016794579524, - 0.10006650294475, -0.35348266879289 }, - { 0.0524867271859, 0.16599786784909, -0.49406271077513, 0.51847470894887, - 0.63927166664011, -0.21933445140234 }, - { -0.57224122530978, -0.089985946187774, 0.44829955643248, - 0.53836681748476, -0.051299333576026, -0.41352093713992 }, - { -0.35034584363296, -0.37367516013323, -0.52676009109159, - 0.12379417201967, 0.42566489477591, 0.51345191723381 }, - { 0.40936909283115, 0.33036021753157, 0.46771483894695, 0.15073372728805, - 0.51541333179083, -0.46491971651678 }, - { -0.64339751231027, -0.29341468636474, -0.50841617762291, - -0.080659811936781, -0.46873502824317, -0.12345817650503 }, - { 0.46950904113222, 0.41685007896275, -0.33378791988356, - -0.39617029121348, 0.54659770033168, 0.19662896748851 }, - { -0.49213884108338, 0.50450587466563, -0.0073247243900323, - 0.57958418990163, 0.39591449230465, 0.10272980841415 }, - { 0.34572956497624, 0.62770109739866, 0.12165109216674, 0.35267248385686, - 0.34842369637704, -0.47527514024373 }, - { 0.076282233884284, 0.56461194794873, -0.392426730607, - -0.20639693057567, 0.33197602170266, 0.60711436994661 }, - { 0.46792592791359, -0.38434666353171, -0.46719345820863, - -0.40169520060432, -0.061343490026986, 0.49993117813162 }, - { -0.25398819915038, -0.82255018555745, 0.40372967512401, - 0.21051604195389, 0.020384827146984, 0.22621006002887 }, - { 0.23269489013955, -0.42234243708413, -0.18886779174866, - 0.44290933725703, -0.40895242871151, 0.60695810498111 }, - { -0.13615585122038, 0.26142849716038, 0.68738606675966, - 0.42914965171764, 0.26332301994884, 0.43256061294487 }, - { 0.06145597366231, -0.25432792035414, 0.65050463165568, - 0.35622065678761, -0.52670947710524, -0.32259598080167 }, - { -0.28027055313228, 0.30275296247348, 0.39083872911587, - 0.17564171472763, 0.25278203996272, 0.76307625890429 }, - { -0.62937098181034, -0.24958587788613, 0.11855057687171, - 0.52714220921895, 0.47759151204224, -0.14687496867489 }, - { 0.68607574135496, 0.28465344118508, 0.57132493696771, 0.11365238375433, - -0.32111327299854, -0.076352560636185 }, - { 0.42669573845021, -0.1643996530281, -0.54881376863042, - -0.56551221465284, 0.4027156095588, -0.087880721039792 }, - { -0.30211042220321, -0.47278547361731, 0.050137867251391, - 0.46804387457884, -0.39450159355792, 0.55497099667426 }, - { 0.31255895138908, 0.034478918459459, -0.079232996020732, - 0.39803160685016, 0.82281399721198, 0.24369695191021 }, - { -0.5524321671417, 0.49350231710234, 0.52530668244467, 0.253625789825, - 0.26218499242504, -0.20557247282514 }, - { 0.060763010271891, -0.023938406391206, 0.36557410300471, - 0.55368747615095, 0.25557899769702, -0.70014279913759 }, - { 0.36398574324757, 0.049110464042478, -0.2428951164628, - -0.18733973495522, 0.020130805835303, 0.87784000694654 }, - { -0.62385490124849, 0.020947599003133, -0.44548631925386, - -0.21069894502123, -0.60559127508405, 0.027809382425643 }, - { 0.51562840479369, -0.27416131751628, -0.14365580420426, - -0.46525735490594, 0.16338488557607, 0.62862302132303 }, - { 0.52085189275139, 0.51359303425374, 0.021844789421786, - 0.53521775458267, -0.23767218281397, -0.34858599348565 }, - { 0.12263603513069, 0.53912951801629, 0.57550729534804, - -0.10335514143554, 0.57524709075397, 0.14662748040551 }, - { 0.40942178494947, 0.17197663954561, -0.025238012475873, - -0.20104824969996, -0.60303014654018, 0.63094779803243 }, - { 0.051685704973311, 0.23577798459204, -0.19154992327678, - -0.67743578708385, -0.51070301615526, 0.43047548181493 }, - { 0.21373839204543, -0.44348268823586, 0.34347986958921, - -0.49945694096162, 0.45888698118478, -0.42382317871053 }, - { -0.60376535923059, -0.065300874745824, 0.49448067868339, - 0.12358559784007, 0.58623743735263, -0.16656623971303 }, - { 0.44140930948322, -0.41692548571374, -0.23774988226818, - -0.27542786466885, 0.39264397083621, 0.58717642823542 }, - { -0.67860697457746, 0.2070991391515, -0.12832398784247, - -0.58381216132288, 0.24050209342748, 0.2854077401022 }, - { -0.021324501342617, 0.0098658783730532, 0.2694901128571, - 0.42580554353158, -0.82903198308789, -0.24128534823695 }, - { -0.20344882384938, 0.51719618805529, 0.24379623299129, - 0.11303683173372, -0.46058654895958, -0.63777957124993 }, - { 0.15686479897897, -0.67777169905813, -0.04974608057712, - 0.51313211803344, 0.49928667286231, -0.030863149692696 }, - { 0.53527130791104, -0.50102597915466, -0.60754472649714, - -0.25235098830686, 0.13490559284448, 0.10708155847142 }, - { -0.20613512232544, 0.39533044356843, -0.34422306275706, - 0.4792145528465, -0.19178040223502, -0.64521804411898 }, - { 0.3304779611047, 0.49148538926455, -0.30004348427342, 0.33473309391851, - 0.31079743137844, 0.59208027276116 }, - { -0.52688857216953, 0.40250311061529, 0.38833191043333, - 0.50432308135853, -0.33327489215794, -0.21015252001231 }, - { -0.30306420816123, -0.34460825415019, -0.26894228639121, - -0.58579646837355, -0.51178483212848, 0.33464319317466 }, - { -0.20258582390514, -0.29195675136034, 0.11887973573086, - 0.91211540292822, 0.034118810787236, -0.16269371903027 }, - { 0.61207678339522, -0.21883722070929, -0.23415725333464, - 0.0041447691596985, -0.34019274152454, 0.6378827339521 }, - { 0.11272999861808, -0.54780877011146, -0.62497664375172, - -0.41373740141301, 0.33306010353229, 0.12039112788093 }, - { 0.24918468395037, -0.068734287809286, -0.42234580029763, - 0.12235329631887, -0.26545138767734, 0.81815148205875 }, - { 0.32048708659406, -0.40233908147851, 0.24633289057781, - -0.37087758270512, -0.55466799718133, -0.47908728788262 }, - { -0.33748729653627, -0.45507986822699, -0.50597645316527, - -0.2863701644881, -0.5404199724601, -0.22120318557996 }, - { -0.23520314824941, 0.82195093398991, -0.22661283339659, - 0.16382454786402, -0.41400232366734, -0.13959354720703 }, - { -0.30495751902889, -0.47964557116121, -0.68490238495876, - -0.4324077675155, -0.13521732523742, -0.050887702629247 }, - { -0.56629250538137, 0.19768903044, -0.080075220953828, - -0.29952637623112, 0.095974426142512, -0.73136356489112 }, - { -0.21316607993139, 0.47585902758173, -0.49429850443227, - -0.24146904800157, 0.45631329089651, 0.46610972545109 }, - { 0.12647584748018, -0.10203700758813, 0.20801341293098, - 0.66418891258418, -0.65219775460192, -0.2526141453282 }, - { -0.69345279552921, 0.30149980453822, -0.46870940095961, - 0.20092958919922, -0.21817920622376, 0.34721422759447 }, - { -0.69001417476102, 0.09722776919634, -0.37852252163632, - -0.24995374433763, 0.24829304775112, 0.4970126640943 }, - { -0.82278510972964, 0.050748830242865, -0.3934733016285, - 0.00029980431140623, -0.34677214869339, -0.21301870187776 }, - { -0.51821811089111, -0.22147302694699, 0.53524316281446, - 0.12892242816244, -0.5543955478928, -0.26821451961648 }, - { -0.21006612796354, 0.26079212570498, -0.021870637510645, - 0.72402587064608, -0.27651658712238, 0.53544979218311 }, - { -0.099744280251479, -0.4534212871731, 0.71954978543864, - -0.31082396323078, -0.26933824624449, 0.31233586755618 }, - { -0.48121951222937, -0.43051247772929, -0.5038415181805, - 0.12342710418307, 0.037467829082858, -0.55909965468017 }, - { -0.51180831908824, -0.079955485578946, -0.53046702060975, - 0.48748209854708, 0.16148937559829, -0.43191028009105 }, - { -0.38131649706702, 0.46242477534251, 0.46416075424014, - -0.20634110277567, -0.53778490132009, 0.30582118902172 }, - { 0.6245043069106, 0.14316692963071, -0.1436103838143, 0.27519251589203, - -0.60467865310212, -0.35708047307373 }, - { 0.52425890739441, -0.20390682829262, -0.33609142609195, - 0.51803372559413, 0.28921536255925, 0.46756035964091 }, - { -0.4455164148456, 0.31831805515328, 0.24217750314789, 0.49821219078654, - -0.47209418708575, 0.41285649844363 }, - { -0.015857310429397, -0.45214512052441, -0.14591363373753, - 0.74070676188619, 0.0098874230592725, -0.47463489014478 }, - { 0.24260837156464, 0.44639366601915, 0.31528570191456, 0.45334773303464, - -0.47964168123625, -0.45484996397296 }, - { 0.47123463487178, 0.64525048646519, -0.064257637508608, - -0.18737730572971, -0.11735335340515, -0.55549853319118 }, - { -0.025197229767488, -0.257963271803, 0.26277107860996, - -0.58236203161499, -0.41893538667715, 0.59086294196016 }, - { -0.48940330017687, 0.33728563842186, -0.057634928591543, - 0.44862021996899, -0.40048256377746, 0.53080564921806 }, - { 0.73350664260388, -0.021482988114587, 0.016568147533453, - 0.0021905972927896, 0.49384961731337, 0.46619710394628 }, - { -0.25151229880228, -0.62009962583403, -0.26948657433033, - 0.31711936293198, -0.35081923073755, 0.50592112116981 }, - { 0.0094298597779172, -0.35925999444899, 0.47529205807388, - -0.26709475088579, -0.53352146543694, 0.53754630836074 }, - { -0.5948549517534, -0.53195924881292, -0.094383768924555, - -0.41704491211939, -0.41397531920841, -0.09463944474724 }, - { -0.74917126125127, -0.24166385705367, 0.22864554725283, - 0.31721357549513, 0.06066292638611, -0.47303041351952 }, - { -0.3300396030254, -0.08758658200966, -0.096726092930468, - -0.39607089556472, 0.55566932028997, 0.63906648027271 }, - { -0.58933068378397, -0.38176870540341, 0.46748019640554, - -0.061358837959321, 0.36268480315292, -0.39127879224432 }, - { -0.066556695042975, -0.73863083674701, -0.32153946998935, - 0.57454599361106, -0.090856896694743, -0.09082394033963 }, - { -0.36335404704287, -0.41643677881158, -0.57839830999334, - -0.030959887755637, 0.5989792522053, -0.016582566905843 }, - { 0.23126668855143, 0.2107790785413, -0.14272193312959, - -0.29232225134991, -0.48451339172564, -0.74934159314943 }, - { 0.48188197979627, -0.040214759215399, -0.15667971883369, - 0.16054853668069, -0.6083975436752, -0.58796308779952 }, - { 0.31319356064062, -0.19280657835646, 0.76136690598738, - -0.084506239097717, 0.4768786755523, -0.22472488900872 }, - { 0.67504537519138, 0.36920158913876, 0.40321048682396, - 0.034436041975613, -0.29332731631919, 0.39774172001359 }, - { -0.1459159803857, -0.59726183207777, -0.036384224081948, - -0.65093487874945, 0.39515711468056, -0.20198429937477 }, - { 0.60092128630869, 0.18110182176699, 0.2579491954112, -0.39594768022975, - 0.15112959843347, 0.59995268930018 }, - { -0.42310244265976, -0.26937197256148, 0.074700012546319, - 0.53119510349465, 0.41614374632783, 0.53618944036115 }, - { 0.0071605427687482, -0.69599782505338, -0.053138604739257, - -0.00054500262230378, 0.69533871546989, 0.1709263483943 }, - { 0.12447149375466, 0.33265313001972, 0.35070015349473, 0.53879932284829, - 0.37648083373421, 0.56463759722353 }, - { 0.29540077719054, 0.04954124873475, -0.48345087234985, - 0.72758494948264, 0.070069102610626, 0.377186640377 }, - { 0.4882414260383, 0.45135801463006, 0.48450857902353, -0.26042407965644, - -0.4251358047458, 0.2731053563007 }, - { -0.49806371818291, -0.4719759672029, 0.029647087810764, - -0.13788472163255, -0.45346141932978, -0.5510470160674 }, - { -0.5359511936033, -0.53585470245895, 0.1771036246335, -0.4537763243703, - 0.41838964069644, 0.11527149720722 }, - { -0.36846431808379, -0.46533180802325, 0.65800816763703, - -0.28691297783558, 0.31521457275327, 0.18178647457201 }, - { -0.29243126901345, -0.4352956525447, -0.58895978125929, - -0.49649471729812, 0.29271342931272, 0.21433587621517 }, - { 0.056256690265475, -0.50387710054371, 0.48145041862725, - 0.44723671964597, -0.55771174894027, -0.0092449146014199 }, - { -0.40973125164006, -0.73147173623276, -0.094076302480945, - 0.43033451471976, 0.014334271843521, -0.32066459724334 }, - { 0.26752725373294, 0.50477344684769, 0.065069516529324, - 0.36001097578267, 0.59393393889869, -0.43247366096278 }, - { 0.48945720845334, 0.6043315650632, 0.12458128550608, -0.48327805813458, - -0.25681943056744, 0.28316179557217 }, - { -0.45182760404001, 0.21574002665039, -0.31462623994251, - 0.25279349500371, 0.44865729380505, -0.62058075048081 }, - { 0.44017304540101, 0.43789555905674, 0.58423563606269, 0.41842994331139, - -0.26836655962348, 0.16143005677844 }, - { -0.67897032028819, -0.32730885869255, -0.0243997359109, - 0.40649244381227, 0.47711065295824, -0.19596475712206 }, - { 0.57441588138131, 0.09386994843744, 0.28400793066375, 0.59394229842661, - 0.45349906020748, 0.14881354725974 }, - { -0.3393739967757, -0.54929055652002, 0.26209493900588, 0.0733800373509, - 0.56557076402003, 0.43492125584075 }, - { 0.050007991188197, 0.74652764513134, -0.36432144611385, - -0.20993543754239, -0.1352041047841, 0.49508839805322 }, - { -0.041332158875019, -0.20655741061568, 0.52511282214888, - 0.047248635933477, -0.6276121766011, -0.5326844609727 }, - { -0.1889491176448, 0.05188976739355, -0.45677123586268, - 0.42884456750344, 0.61612085530435, -0.43526216197988 }, - { -0.65873541163911, -0.094770059351695, 0.40844030815782, - 0.35536013391048, -0.16940065827957, 0.48506226422661 }, - { -0.45779281442862, -0.46052673126242, 0.34138050378631, - -0.54943270263121, 0.37140594702643, -0.14826175595089 }, - { -0.069378715405383, -0.14845488608058, -0.73991837897813, - 0.41519184526768, -0.11098464009855, -0.49088356499611 }, - { 0.46422563805447, 0.46130716873201, -0.44207791495441, - 0.12050605352899, 0.34969556083561, -0.4893349322843 }, - { -0.35482925073362, 0.28146983672487, -0.35356606227648, - -0.38774754218768, 0.35979702647173, -0.62454776976122 }, - { -0.48343191508515, 0.41492185792886, -0.50175316406656, - 0.21953122931153, -0.54083165333237, 0.041040952107647 }, - { -0.51280508048852, -0.54131124436697, -0.0099287129207481, - 0.23788701199175, 0.4350333223576, 0.44505087885649 }, - { 0.2253837335044, -0.30117119745248, 0.46587685049056, - -0.46672901001472, -0.59182069765377, 0.27086737661249 }, - { 0.43015756480475, -0.067851118947538, -0.26917802105288, - -0.57731860676632, -0.53950120703807, -0.33696522367557 }, - { 0.20858352742161, 0.63695057987625, 0.49453142202915, - -0.046235371593379, -0.54436247241885, -0.088075720520231 }, - { -0.35626464703623, 0.067539543974725, -0.18142793486226, - -0.49044207117167, 0.5542388249925, 0.53654796190017 }, - { 0.52238539932434, 0.55175875223621, 0.29070268774296, - -0.14119026819648, -0.55841587206055, -0.080029639759127 }, - { -0.025988002903175, 0.46612949273683, -0.56880970348453, - -0.44824563336003, -0.030000490931808, 0.50663523727173 }, - { 0.047284583258099, -0.26595723160738, 0.21032033434131, - 0.52986834914146, -0.52245334572957, -0.5736534757312 }, - { -0.31924244568277, -0.13888420092891, 0.30725800370737, - 0.49792332552544, 0.61035592292817, -0.40487771982263 }, - { 0.038758575627018, -0.53813545398707, -0.56167256912901, - 0.46815373895572, -0.14142713486975, 0.39276248966752 }, - { -0.19936871608885, 0.12488860648831, -0.62990029833727, - -0.29296146144627, 0.49734531468753, 0.46335923993672 }, - { -0.078826705546604, -0.15548800857414, 0.57456768467721, - 0.5558854465212, -0.56893054194692, -0.082408823513622 }, - { 0.11678856295109, 0.53358760166951, 0.49302489382249, - -0.53981846952046, -0.237913367643, -0.33251226509871 }, - { 0.39126928439834, -0.39416116630681, -0.35778844984527, - -0.39395609960567, 0.50270356681194, -0.39448759513757 }, - { -0.17961290695406, 0.34239532682819, -0.21870225043453, - -0.23322835296688, 0.75997835134209, 0.41317237364121 }, - { 0.29699501400111, 0.17195435585404, -0.34903627841034, - -0.31751884057854, -0.59661546358767, 0.55102732418683 }, - { -0.2237291316445, -0.51254305965518, -0.31277318571798, - 0.54270199705442, -0.34885011313806, 0.41616819064585 }, - { 0.53534023676892, 0.45905986582643, -0.20308675275303, - 0.019523641323632, 0.3378580580099, 0.58898336258938 }, - { -0.045038463119119, -0.52553334288797, -0.6098545897634, - 0.46226027841702, -0.36069029000651, 0.077984430434637 }, - { -0.40129033029845, 0.39526722066586, -0.20379584931963, - 0.45466492237669, 0.46504795737483, -0.46712669863522 }, - { -0.43845831945339, -0.59284534057943, 0.050241908216277, - -0.36494839821973, 0.32363879325018, 0.46458051299488 }, - { -0.46057360356064, -0.34584626825548, -0.12264748451482, - 0.48835437094478, 0.21102526990984, 0.60843919401837 }, - { -0.086047549693024, -0.16981605114589, -0.37222833669973, - 0.45158609930017, -0.55710254634126, 0.55759406480139 }, - { 0.54697451263099, -0.45070837355303, 0.032962522247893, - -0.48584332140086, -0.28055687213837, 0.42642516953676 }, - { 0.34061925303691, 0.38443007758012, 0.61614808332652, - -0.55774172327958, -0.075660378162998, 0.19938218730551 }, - { 0.30626924920956, -0.057939049897675, -0.10461119704504, - -0.4395638756485, -0.57307193269415, 0.60849886616281 }, - { -0.52519951444608, -0.42567534157254, -0.19896500097138, - 0.48819483593271, 0.12539008064447, 0.49932157157064 }, - { -0.10173361116951, -0.07873850987854, 0.3713554090283, - 0.65889542748449, 0.63411890875068, 0.096414235519521 }, - { 0.60342393773609, 0.057617370697663, 0.35558841250938, - 0.20766418929404, 0.030670189501999, -0.67974377143949 }, - { -0.071971052874019, -0.44567383014704, 0.65917594080871, - 0.44113802003588, -0.29627117199757, 0.28160739274962 }, - { 0.38284479693596, 0.43552320173998, -0.4282368470258, - -0.54809258921772, -0.27202273485667, 0.32551612927831 }, - { -0.74755699288716, -0.20979308948438, 0.19268299390085, - 0.27864013929953, -0.39085278833717, 0.36001727246301 }, - { -0.64575536737195, 0.59253747557756, 0.040885512266333, - -0.20167391777406, -0.43481684011627, -0.02212841779644 }, - { 0.45874103754271, -0.0066587566394561, -0.30494054091993, - 0.52731059172348, -0.64443887148677, 0.056264275617853 }, - { 0.61573773369959, -0.00074622703454316, 0.25455659350429, - 0.30670278147618, -0.18573195942296, 0.65383825999316 }, - { -0.089919562456316, -0.28968403215216, -0.60618287937171, - 0.53370861364121, 0.37921556323246, -0.33450055738044 }, - { -0.47481167613763, 0.3899274103573, -0.1047963185367, 0.45545456567005, - 0.12142073778317, 0.62397625076847 }, - { 0.59154225785278, -0.10812441303593, -0.4685834521013, - -0.36007270807588, -0.1012374701199, 0.52812407295968 }, - { -0.01292122984647, -0.23607532114711, -0.57680411110671, - -0.44955815301222, -0.31913443306122, -0.55448100298376 }, - { 0.54231398466289, -0.31845386154668, -0.38636423612049, - 0.22187979539931, -0.6346425853783, -0.056599490898788 }, - { -0.41950690366157, -0.4578028963184, 0.31139813874057, - 0.39787962066193, -0.20885901240181, 0.56172180435883 }, - { -0.031404881097728, 0.56267475273157, -0.5556815383811, - 0.33075363850824, 0.39071115867626, 0.3340294973255 }, - { -0.51485161085589, -0.34037011091125, -0.46826090820473, - -0.60086679836276, -0.075069409610657, 0.18202033570633 }, - { -0.49669644859095, 0.13236483793072, 0.53440735955877, 0.4720120049858, - -0.05992551666341, -0.47306929861073 }, - { -0.32796852486185, 0.65593302097807, 0.20800030327303, - -0.38965914824176, -0.51564565153044, -0.034636725857177 }, - { -0.30473794783797, 0.12584230588041, 0.63911213518179, - 0.11269477188219, 0.62944339013855, 0.27191006392352 }, - { -0.53642197294029, 0.50742224701512, -0.22907820767928, - 0.47022559371179, -0.1914125650624, 0.38019261684316 }, - { -0.28865425091309, 0.76169672032907, -0.36166127667225, - -0.30555403321368, -0.12541657537884, -0.31081403770203 }, - { 0.0025978417989835, 0.3737146483793, -0.3151511957077, - 0.62032810853005, 0.60524642517936, -0.09939888944988 }, - { -0.40019833530022, 0.15931480693456, -0.61653030345628, - -0.49479441153976, -0.021517911098538, -0.43481713333933 }, - { -0.26445143166732, -0.48401155081335, 0.27737058096082, - -0.12537486208624, -0.46956235249512, 0.61859207953377 }, - { -0.49776294425122, 0.6509513246149, -0.20147785800704, - 0.26022926925791, 0.39526195830317, -0.25288299425858 }, - { 0.20792543895216, 0.6725599557329, 0.013296712014115, - 0.069082404776847, -0.37233547685047, 0.60070560947898 }, - { -0.60329265885108, 0.40708027238668, -0.17229997007444, - -0.52997954496878, 0.22211745651394, -0.33229784433365 }, - { 0.61826884506104, -0.62582169643111, 0.33820439950773, - 0.23870919720066, -0.20670655096227, -0.10953969425599 }, - { -0.63678168786213, -0.51101649337563, -0.19131817442969, - -0.49493417544846, -0.22614515287593, 0.025828539221376 }, - { 0.7068462559507, 0.072932806612059, -0.30827034359477, - -0.52659704221432, -0.33954839093364, 0.086145323573817 }, - { -0.52429050496975, 0.39091424683727, 0.52819210715237, - -0.16569162349745, 0.447191673089, 0.25667977984796 }, - { 0.85033978527922, -0.37311666188152, -0.031585518143925, - -0.063546921071094, -0.35026506762952, 0.099923633151172 }, - { -0.43149574251927, 0.16017753208259, -0.36624037246965, - 0.49372029676385, -0.60067103922455, 0.2223896202103 }, - { -0.43599537393092, -0.360658355506, -0.42475053011196, - -0.52301759011739, 0.039454536357949, 0.47362064109658 }, - { -0.35793170214797, -0.43917817788312, -0.49072242572643, - -0.32880277826743, -0.38509560837703, -0.42636724894184 }, - { -0.043679644403255, 0.74697226557232, -0.40732954428872, - -0.48088968590275, 0.18029290312902, -0.10220931735307 }, - { -0.058902573502295, 0.0082595236590186, 0.7136596141971, - -0.53043791172483, 0.22906331492979, 0.39155822265168 }, - { 0.43459649233879, 0.18964470832196, 0.15217427204218, 0.59694624534505, - 0.053786588105393, 0.62671041756872 }, - { -0.48833575031057, 0.068909881680922, 0.60168404074737, - -0.055455043023162, -0.62426261497771, -0.044461939113733 }, - { -0.71822145541427, 0.054494951105527, 0.25733756171599, - -0.42706881935297, -0.44024663347316, 0.19687748949208 }, - { 0.4723221071836, 0.63009683957253, 0.2166256995021, 0.31063720960745, - 0.079455887335627, 0.47974409023622 }, - { -0.39506538843406, 0.42517729990346, 0.29375773990216, - 0.044503633424429, -0.46173213926286, 0.60139575234582 }, - { -0.40354126620316, 0.41304136826673, -0.29533980868045, - -0.45300699221804, 0.23702354154238, -0.56385297528377 }, - { -0.62315380378984, -0.42397903326965, 0.53044082394843, - 0.37874432092957, 0.054922713129263, 0.063952196248596 }, - { 0.41959045692314, -0.83420441875842, -0.25505372502578, - 0.25012310515014, 0.010974237503127, 0.017675743681809 }, - { -0.25231575134089, -0.17034034508503, -0.0022254428444259, - -0.4967771056787, 0.43184899693064, -0.68850194407078 }, - { -0.1852812882862, -0.48330898597592, 0.13528868642679, - 0.15202104844417, 0.57661281495368, -0.59848767913131 }, - { 0.64287473226568, -0.30923674494923, 0.22234318117192, - 0.099248962994541, 0.64370450011427, 0.13206961744112 }, - { -0.49018899717866, 0.68654120859156, -0.27238863334662, - -0.085832423495263, 0.44161945604453, 0.10856057983467 }, - { 0.48795432482822, 0.42184193883513, -0.43797315744756, - 0.35186997012044, -0.46483432791096, 0.22857392808385 }, - { 0.52970834834669, -0.50684486922008, -0.39782161731912, - -0.3932709335414, -0.34863027587322, 0.16748196501934 }, - { -0.46048505533, -0.3887126918161, -0.68287320410729, -0.18448530888361, - -0.25358256326157, 0.26870280714361 }, - { 0.6889557358588, -0.3101022706485, -0.35882194962822, 0.30088738418801, - -0.039139540883101, -0.45646277242166 }, - { -0.21954767479275, 0.40838837410593, 0.23284186868997, - 0.30349649888064, 0.57233263099925, 0.55778817953937 }, - { 0.57731035290905, 0.091218309942656, 0.70670016667131, - 0.016358033634041, 0.3939245235472, -0.059352634867484 }, - { 0.50055570130024, -0.021749790970703, 0.56767851040093, - 0.50580176326624, 0.34691320957643, 0.22478399991032 }, - { -0.37901911159632, 0.53804099887537, -0.46780195460858, - 0.51497346779204, -0.27981005467588, 0.067278440906787 }, - { 0.67241900483514, 0.074099582737, 0.43138117954806, 0.054567519697911, - -0.37927768894619, 0.45764946429346 }, - { 0.14529189179172, -0.23854982910384, 0.45401647091062, - 0.25466539906731, 0.46182069803887, -0.66160446396375 }, - { -0.15570980059397, -0.38476787034627, 0.37322840954917, - -0.43977613626294, -0.61243005550684, -0.34631643815896 }, - { -0.19590302894013, 0.42065974653653, 0.43447548638809, - -0.10575548452794, 0.70439951675651, -0.29754920754254 }, - { -0.13558865796725, 0.1427073453776, 0.49647494823192, - -0.65533234019218, -0.11714854214663, 0.5211321311867 }, - { -0.6228374766114, 0.20812698103217, -0.16205154548883, - 0.20384566967497, -0.59321895467652, 0.38604941246779 }, - { 0.44487837128099, -0.37224943035393, -0.22188447638327, - 0.48921538939858, 0.41432418029434, -0.45087099253189 }, - { 0.66422841315008, 0.21517761068003, 0.094012579794123, - -0.4358159040875, 0.22245680154647, -0.51404116085847 }, - { -0.11369362736032, 0.32284689991698, -0.38818285117689, - 0.49680024166881, 0.047684866166158, -0.69503480904222 }, - { -0.5137200731924, -0.50673230867252, 0.32715252974108, - -0.26799714004956, -0.47616510509846, 0.27153195326233 }, - { -0.47315177716491, -0.45711495983609, -0.31178280842352, - -0.51697763052226, -0.14302372043059, -0.42689944315384 }, - { -0.050442035795027, 0.23609184251469, 0.38634880236106, - 0.56012774305243, 0.38963669840218, -0.57174382424149 }, - { -0.15472134925391, -0.15333579424307, -0.14189768300467, - 0.032279269476252, -0.66054298438621, -0.70360180527557 }, - { -0.10345191679557, -0.30503725808375, 0.31038263802383, - 0.36878846502877, -0.76824774853417, 0.2714830658427 }, - { -0.060212868606223, -0.4172755444983, 0.39199300681258, - -0.44040104260082, 0.24955102139032, -0.64215903203727 }, - { 0.25443195353315, -0.013789583113498, 0.44365000614699, - 0.53296203342425, -0.55057750350733, -0.38867053403178 }, - { -0.36068564301268, -0.65616661625162, -0.48495997865466, - 0.24088316031012, -0.18080297655217, -0.33682435258394 }, - { -0.53824550487673, -0.096728907851005, -0.5208619866167, - 0.33195321221408, -0.032263947064791, 0.56427315050798 }, - { 0.40151657866643, -0.44825725748635, -0.54910020122855, - -0.095936272447708, 0.5719563905078, 0.00097783623607218 }, - { 0.21961099467771, 0.62823723408945, -0.010045934028323, - -0.6610564872634, -0.17161595423903, -0.30089924032373 }, - { 0.27961471530636, 0.054523395513076, 0.61485903249347, - 0.11958885677663, -0.61032561244673, -0.39241856813031 }, - { -0.30223065341134, -0.23605925177166, -0.09697276975263, - -0.46458104180761, -0.37853464945647, 0.69599203908657 }, - { 0.0023635513043496, 0.62702100484886, 0.49658954056984, - -0.20369645124455, -0.56457560315907, 0.00021299797811461 }, - { -0.64198493892962, 0.59676262320476, 0.46274573284143, - 0.088421912306785, 0.098029994490406, -0.012953072012707 }, - { -0.053965435026011, 0.13439533803278, -0.33103493780685, - 0.55991756423782, -0.58127599631056, -0.46696041830103 }, - { -0.43965993689353, 0.07544961763381, 0.1509639518808, - -0.38868406689028, -0.0033436054452783, -0.79191533434483 }, - { -0.21743914630025, -0.32019630124298, -0.56067107727615, - 0.027284914419519, -0.49444926389798, -0.53908992599417 }, - { -0.36492599248168, 0.52529904803377, 0.18002253442693, - 0.14829474115897, 0.17212619314998, -0.71194315827942 }, - { 0.0051876209353066, 0.50490293404098, 0.24361032552454, - 0.13688117617809, -0.61381291176911, -0.5386997104485 }, - { 0.66421180843392, 0.21833854629637, -0.087909936660014, - 0.15624552502148, -0.68780724971724, 0.077015056461268 }, - { 0.52710630558705, -0.42143671471468, -0.069964559463205, - -0.24196341534187, -0.68814841622245, 0.08695091377684 }, - { 0.62392249806692, -0.23663281560035, -0.59058622185178, - 0.22685863859977, -0.36683948058558, -0.14105848121323 }, - { 0.18069852004855, -0.083828559172887, 0.66240167877879, - 0.16722813432165, -0.25503640214793, -0.65462662498637 }, - { -0.37112528006203, 0.43100319401562, -0.11342774633614, - 0.14418808646988, 0.5753326931164, 0.55842502411684 }, - { 0.55378724068611, 0.21098160548047, -0.3224976646632, 0.31268307369255, - -0.37624695517597, -0.55269271266764 }, - { 0.2601465870231, 0.56373458886982, -0.21638357910201, 0.41216916619413, - -0.25078072187299, -0.57873208070982 }, - { 0.11217864148346, 0.54196554704815, -0.31989128683717, - 0.54691221598945, 0.24062434044524, 0.48409277788476 }, - { 0.087564423746579, -0.12083081671284, 0.69931172084498, - 0.35220575672909, 0.28770484569954, -0.53091668762919 }, - { 0.3395702120398, 0.042520943289575, -0.30935928261896, - 0.61022210846475, 0.54650816974112, 0.34079124619266 }, - { 0.32746112891934, 0.32095220193351, -0.61142534799442, - 0.32197324480666, -0.38236071343678, 0.40749411210419 }, - { 0.58741915356593, -0.30916030490652, -0.57642977381104, - -0.038846190358607, 0.047926713761208, -0.4725265742377 }, - { 0.026224389898652, 0.031768907187292, -0.12510902263321, - 0.36102734397001, -0.72217212865059, 0.57513252722531 }, - { -0.27510374152496, -0.5153402145828, 0.025774022629799, - 0.59201067073603, 0.40728366085253, -0.37645913420642 }, - { -0.29983338495183, -0.61017291361195, -0.18551919513643, - 0.50515945610161, 0.18206593801497, -0.46372136367049 }, - { -0.64290893575119, -0.34887011406157, -0.55318606770362, - -0.21230198963112, -0.19828983785672, 0.2730419816548 }, - { -0.32778879906348, -0.094317293167129, 0.57811170538439, - 0.54346692190204, 0.17699503497579, -0.47197676839855 }, - { -0.075738705663962, 0.53381750682665, -0.13406342524856, - 0.71765386263773, 0.34271060834977, 0.24259408122628 }, - { -0.30574273227855, 0.17419449782542, -0.78861555508124, - 0.43305678368813, 0.064853328282818, 0.25003806266734 }, - { 0.4397035983709, -0.51651518914239, -0.3972346186176, - -0.34513492086703, 0.32129829777342, -0.39965829527563 }, - { -0.25184899643619, -0.35937572373004, 0.15273239148905, - -0.51640931868766, 0.4218715745627, -0.58261460582976 }, - { -0.57396000790758, 0.1912786199605, 0.45995634753032, - -0.43664716984512, 0.4601630113166, 0.14146310231856 }, - { 0.11500068018889, 0.05112652754666, -0.25672855859366, - -0.54715738035577, 0.67669928552409, 0.40118355777989 }, - { -0.45252668004418, -0.40809988524453, -0.064931545867856, - 0.19116562077283, 0.76523014995576, 0.048337406798767 }, - { -0.080075651760374, 0.75305314115418, 0.34797424409913, - 0.29104493928016, 0.0040185919664457, -0.46977598520425 }, - { -0.3890257668276, 0.49100041230416, -0.17812126809985, - -0.43787557151231, -0.46923187878333, 0.40489108352503 }, - { 0.37433236324043, -0.29441766760791, -0.066285137006724, - 0.33217472508825, 0.73917165688328, 0.33479099915638 }, - { -0.02973230696179, -0.51371026289118, 0.34133522703692, - -0.41361792362786, -0.51561746819514, -0.4263412462482 }, - { 0.51057171220039, -0.23740201245544, 0.26673587003088, 0.5521767379032, - 0.16849318602455, 0.52774964064755 } }; - - public static final double[] whitenoiseLUT = { -0.714286, 0.301587, 0.333333, - -1, 0.396825, -0.0793651, -0.968254, -0.047619, 0.301587, -0.111111, - 0.015873, 0.968254, -0.428571, 0.428571, 0.047619, 0.84127, -0.015873, - -0.746032, -0.809524, -0.619048, -0.301587, -0.68254, 0.777778, 0.365079, - -0.460317, 0.714286, 0.142857, 0.047619, -0.0793651, -0.492063, - -0.873016, -0.269841, -0.84127, -0.809524, -0.396825, -0.777778, - -0.396825, -0.746032, 0.301587, -0.52381, 0.650794, 0.301587, -0.015873, - 0.269841, 0.492063, -0.936508, -0.777778, 0.555556, 0.68254, -0.650794, - -0.968254, 0.619048, 0.777778, 0.68254, 0.206349, -0.555556, 0.904762, - 0.587302, -0.174603, -0.047619, -0.206349, -0.68254, 0.111111, -0.52381, - 0.174603, -0.968254, -0.111111, -0.238095, 0.396825, -0.777778, - -0.206349, 0.142857, 0.904762, -0.111111, -0.269841, 0.777778, -0.015873, - -0.047619, -0.333333, 0.68254, -0.238095, 0.904762, 0.0793651, 0.68254, - -0.301587, -0.333333, 0.206349, 0.52381, 0.904762, -0.015873, -0.555556, - 0.396825, 0.460317, -0.142857, 0.587302, 1, -0.650794, -0.333333, - -0.365079, 0.015873, -0.873016, -1, -0.777778, 0.174603, -0.84127, - -0.428571, 0.365079, -0.587302, -0.587302, 0.650794, 0.714286, 0.84127, - 0.936508, 0.746032, 0.047619, -0.52381, -0.714286, -0.746032, -0.206349, - -0.301587, -0.174603, 0.460317, 0.238095, 0.968254, 0.555556, -0.269841, - 0.206349, -0.0793651, 0.777778, 0.174603, 0.111111, -0.714286, -0.84127, - -0.68254, 0.587302, 0.746032, -0.68254, 0.587302, 0.365079, 0.492063, - -0.809524, 0.809524, -0.873016, -0.142857, -0.142857, -0.619048, - -0.873016, -0.587302, 0.0793651, -0.269841, -0.460317, -0.904762, - -0.174603, 0.619048, 0.936508, 0.650794, 0.238095, 0.111111, 0.873016, - 0.0793651, 0.460317, -0.746032, -0.460317, 0.428571, -0.714286, - -0.365079, -0.428571, 0.206349, 0.746032, -0.492063, 0.269841, 0.269841, - -0.365079, 0.492063, 0.873016, 0.142857, 0.714286, -0.936508, 1, - -0.142857, -0.904762, -0.301587, -0.968254, 0.619048, 0.269841, - -0.809524, 0.936508, 0.714286, 0.333333, 0.428571, 0.0793651, -0.650794, - 0.968254, 0.809524, 0.492063, 0.555556, -0.396825, -1, -0.492063, - -0.936508, -0.492063, -0.111111, 0.809524, 0.333333, 0.238095, 0.174603, - 0.333333, 0.873016, 0.809524, -0.047619, -0.619048, -0.174603, 0.84127, - 0.111111, 0.619048, -0.0793651, 0.52381, 1, 0.015873, 0.52381, -0.619048, - -0.52381, 1, 0.650794, -0.428571, 0.84127, -0.555556, 0.015873, 0.428571, - 0.746032, -0.238095, -0.238095, 0.936508, -0.206349, -0.936508, 0.873016, - -0.555556, -0.650794, -0.904762, 0.52381, 0.968254, -0.333333, -0.904762, - 0.396825, 0.047619, -0.84127, -0.365079, -0.587302, -1, -0.396825, - 0.365079, 0.555556, 0.460317, 0.142857, -0.460317, 0.238095, }; -} diff --git a/src/com/sudoplay/joise/noise/Util.java b/src/com/sudoplay/joise/noise/Util.java deleted file mode 100755 index d81b701bb..000000000 --- a/src/com/sudoplay/joise/noise/Util.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.joise.noise; - -public class Util { - - public static final double TWO_PI = Math.PI * 2.0; - - private static final double INV_LOG_HALF = 1.0 / Math.log(0.5); - - private Util() {} - - public static double clamp(double input, double min, double max) { - return (input < min) ? min : (input > max) ? max : input; - } - - public static double bias(double b, double t) { - return Math.pow(t, Math.log(b) * INV_LOG_HALF); - } - - public static double lerp(double t, double a, double b) { - return a + t * (b - a); - } - - public static double gain(double g, double t) { - g = clamp(g, 0.0, 1.0); - if (t < 0.5) { - return bias(1.0 - g, 2.0 * t) * 0.5; - } else { - return 1.0 - bias(1.0 - g, 2.0 - 2.0 * t) * 0.5; - } - } - - public static double quinticBlend(double t) { - return t * t * t * (t * (t * 6 - 15) + 10); - } - - public static double sawtooth(double x, double p) { - return (2.0 * (x / p - Math.floor(0.5 + x / p))) * 0.5 + 0.5; - } - - public static class Vector3d { - public double x, y, z; - - public Vector3d() { - this(0, 0, 0); - } - - public Vector3d(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - } -} diff --git a/src/com/sudoplay/util/Assert.java b/src/com/sudoplay/util/Assert.java deleted file mode 100755 index 8251d1f64..000000000 --- a/src/com/sudoplay/util/Assert.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.util; - -public class Assert { - - public static void notNull(Object... objects) { - for (Object o : objects) { - if (o == null) { - throw new NullPointerException(); - } - } - } - - public static void hasLength(Object[] objects, int length) { - if (objects == null && length > 0) { - throw new IllegalArgumentException("Expecting " + length - + " objects but was null"); - } else if (objects.length != length) { - throw new IllegalArgumentException("Expecting " + length - + " objects but was " + objects.length); - } - } - - public static void isClassNotNull(Class c, Object... objects) { - for (Object o : objects) { - if (o == null) { - throw new NullPointerException("Expecting " + c.getName() - + " but was null"); - } else if (!c.equals(o.getClass())) { - throw new IllegalArgumentException("Expecting " + c.getName() - + " but was " + o.getClass().getName()); - } - } - } - - public static void isInstanceNotNull(Class c, Object... objects) { - for (Object o : objects) { - if (o == null) { - throw new NullPointerException("Expecting " + c.getName() - + " but was null"); - } else if (!c.isInstance(o)) { - throw new IllegalArgumentException("Expecting " + c.getName() - + " but was " + o.getClass().getName()); - } - } - } - - public static void isClass(Class c, Object... objects) { - for (Object o : objects) { - if (!c.equals(o.getClass())) { - throw new IllegalArgumentException("Expecting " + c.getName() - + " but was " + o.getClass().getName()); - } - } - } - - public static void isInstance(Class c, Object... objects) { - for (Object o : objects) { - if (!c.isInstance(o)) { - throw new IllegalArgumentException("Expecting " + c.getName() - + " but was " + o.getClass().getName()); - } - } - } - - public static T isInstance(Class c, Object o) { - if (!c.isInstance(o)) { - throw new IllegalArgumentException("Expecting " + c.getName() - + " but was " + o.getClass().getName()); - } - return c.cast(o); - } - -} diff --git a/src/com/sudoplay/util/Checked.java b/src/com/sudoplay/util/Checked.java deleted file mode 100755 index 2395a75db..000000000 --- a/src/com/sudoplay/util/Checked.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2013 Jason Taylor. - * Released as open-source under the Apache License, Version 2.0. - * - * ============================================================================ - * | Joise - * ============================================================================ - * - * Copyright (C) 2013 Jason Taylor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================ - * | Accidental Noise Library - * | -------------------------------------------------------------------------- - * | Joise is a derivative work based on Josua Tippetts' C++ library: - * | http://accidentalnoise.sourceforge.net/index.html - * ============================================================================ - * - * Copyright (C) 2011 Joshua Tippetts - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -package com.sudoplay.util; - -public class Checked { - - private Checked() {} - - public static int safeLongToInt(long l) { - if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { - throw new IllegalArgumentException(l - + " cannot be cast to int without changing its value."); - } - return (int) l; - } - -} diff --git a/src/net/torvald/aa/AAFrame.kt b/src/net/torvald/aa/AAFrame.kt index 30a5610e2..051753cf6 100644 --- a/src/net/torvald/aa/AAFrame.kt +++ b/src/net/torvald/aa/AAFrame.kt @@ -1,16 +1,13 @@ package net.torvald.aa import net.torvald.terrarum.gameworld.toUint -import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal -import org.newdawn.slick.* /** * @param terminal: for sending redraw only * * Created by minjaesong on 16-08-10. */ -class AAFrame @Throws(SlickException::class) -constructor(var width: Int, var height: Int, var terminal: SimpleTextTerminal) { +/*class AAFrame(var width: Int, var height: Int, var terminal: SimpleTextTerminal) { /** * 0000_0000_00000000 @@ -94,4 +91,4 @@ constructor(var width: Int, var height: Int, var terminal: SimpleTextTerminal) { private fun checkOOB(x: Int, y: Int) = (x < 0 || y < 0 || x >= width || y >= height) fun getColourKey(x: Int, y: Int): Int = frameBuffer[y * width + x].toInt().ushr(8).and(0xFF) -} +}*/ diff --git a/src/net/torvald/colourutil/CIELChabUtil.kt b/src/net/torvald/colourutil/CIELChabUtil.kt index faa8116ac..6990013c3 100644 --- a/src/net/torvald/colourutil/CIELChabUtil.kt +++ b/src/net/torvald/colourutil/CIELChabUtil.kt @@ -7,8 +7,7 @@ import net.torvald.colourutil.CIELabUtil.toLab import net.torvald.colourutil.CIEXYZUtil.toXYZ import net.torvald.colourutil.CIEXYZUtil.toColor import net.torvald.colourutil.CIELabUtil.toXYZ -import org.newdawn.slick.Color - +import com.badlogic.gdx.graphics.Color /** * Cylindrical modification of CIELab colour space * diff --git a/src/net/torvald/colourutil/CIELabUtil.kt b/src/net/torvald/colourutil/CIELabUtil.kt index 695603cd9..aaa7371bd 100644 --- a/src/net/torvald/colourutil/CIELabUtil.kt +++ b/src/net/torvald/colourutil/CIELabUtil.kt @@ -6,7 +6,7 @@ import net.torvald.colourutil.CIEXYZUtil.toColor import net.torvald.colourutil.CIEXYZUtil.toRGB import net.torvald.colourutil.CIEXYZUtil.toXYZ import net.torvald.colourutil.CIELabUtil.toXYZ -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color /** * A modification of CIEXYZ that is useful for surface colours diff --git a/src/net/torvald/colourutil/CIELuvUtil.kt b/src/net/torvald/colourutil/CIELuvUtil.kt index a4d3aaa83..10666d1b6 100644 --- a/src/net/torvald/colourutil/CIELuvUtil.kt +++ b/src/net/torvald/colourutil/CIELuvUtil.kt @@ -1,7 +1,7 @@ package net.torvald.colourutil import com.jme3.math.FastMath -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color import net.torvald.colourutil.CIELabUtil.toXYZ import net.torvald.colourutil.CIEXYZUtil.toColor import net.torvald.colourutil.CIEXYZUtil.toRGB diff --git a/src/net/torvald/colourutil/CIEXYZUtil.kt b/src/net/torvald/colourutil/CIEXYZUtil.kt index bb4f5d156..c90e76313 100644 --- a/src/net/torvald/colourutil/CIEXYZUtil.kt +++ b/src/net/torvald/colourutil/CIEXYZUtil.kt @@ -1,7 +1,7 @@ package net.torvald.colourutil import com.jme3.math.FastMath -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color /** * Created by minjaesong on 2017-01-12. diff --git a/src/net/torvald/colourutil/Col216.kt b/src/net/torvald/colourutil/Col216.kt index 419cca0e0..fe745f747 100644 --- a/src/net/torvald/colourutil/Col216.kt +++ b/src/net/torvald/colourutil/Col216.kt @@ -1,6 +1,6 @@ package net.torvald.colourutil -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color /** * 6-Step RGB with builtin utils. @@ -31,18 +31,18 @@ class Col216 : LimitedColours { create(r, g, b) } - override fun createSlickColor(raw: Int): Color { + override fun createGdxColor(raw: Int): Color { assertRaw(raw) val r = raw / MUL_2 val g = raw % MUL_2 / MUL val b = raw % MUL - return createSlickColor(r, g, b) + return createGdxColor(r, g, b) } - override fun createSlickColor(r: Int, g: Int, b: Int): Color { + override fun createGdxColor(r: Int, g: Int, b: Int): Color { assertRGB(r, g, b) - return Color(LOOKUP[r], LOOKUP[g], LOOKUP[b]) + return Color((LOOKUP[r] shl 24) + (LOOKUP[g] shl 16) + (LOOKUP[b] shl 8) + 255) } override fun create(raw: Int) { @@ -55,7 +55,7 @@ class Col216 : LimitedColours { raw = (MUL_2 * r + MUL * g + b).toByte() } - override fun toSlickColour(): Color = createSlickColor(raw.toUint()) + override fun toGdxColour(): Color = createGdxColor(raw.toUint()) private fun assertRaw(i: Int) { if (i >= COLOUR_RANGE_SIZE || i < 0) { diff --git a/src/net/torvald/colourutil/Col40 b/src/net/torvald/colourutil/Col40 deleted file mode 100644 index 46a7d6b8b..000000000 --- a/src/net/torvald/colourutil/Col40 +++ /dev/null @@ -1,72 +0,0 @@ -package com.torvald.colourutil - -import org.newdawn.slick.Color - -/** - * 40-Step RGB with builtin utils. - * Created by minjaesong on 16-02-20. - */ -class Col40 : LimitedColours { - - var raw: Char = ' ' - private set - - override fun createSlickColor(raw: Int): Color { - assertRaw(raw) - val r = raw / MUL_2 - val g = raw % MUL_2 / MUL - val b = raw % MUL - - return createSlickColor(r, g, b) - } - - override fun createSlickColor(r: Int, g: Int, b: Int): Color { - assertRGB(r, g, b) - return Color(LOOKUP[r] shl 16 or (LOOKUP[g] shl 8) or LOOKUP[b]) - } - - override fun create(raw: Int) { - assertRaw(raw) - this.raw = raw.toChar() - } - - override fun create(r: Int, g: Int, b: Int) { - assertRGB(r, g, b) - raw = (MUL_2 * r + MUL * g + b).toChar() - } - - constructor() { - } - - constructor(c: Color) { - create( - Math.round(c.r * (MUL - 1)), - Math.round(c.g * (MUL - 1)), - Math.round(c.b * (MUL - 1))) - } - - private fun assertRaw(i: Int) { - if (i >= COLOUR_DOMAIN_SIZE || i < 0) { - println("i: " + i.toString()) - throw IllegalArgumentException() - } - } - - private fun assertRGB(r: Int, g: Int, b: Int) { - if (r !in 0..MAX_STEP || g !in 0..MAX_STEP || b !in 0..MAX_STEP) { - println("r: " + r.toString()) - println("g: " + g.toString()) - println("b: " + b.toString()) - throw IllegalArgumentException() - } - } - - companion object { - @Transient private val LOOKUP = intArrayOf(0, 7, 13, 20, 26, 33, 39, 46, 52, 59, 65, 72, 78, 85, 92, 98, 105, 111, 118, 124, 131, 137, 144, 150, 157, 163, 170, 177, 183, 190, 196, 203, 209, 216, 222, 229, 235, 242, 248, 255) - - const val MUL = 40 - const val MUL_2 = MUL * MUL - const val MAX_STEP = MUL - 1 - const val COLOUR_DOMAIN_SIZE = MUL_2 * MUL - } -} diff --git a/src/net/torvald/colourutil/Col4096.kt b/src/net/torvald/colourutil/Col4096.kt index a6a74bc44..f3bcdd772 100644 --- a/src/net/torvald/colourutil/Col4096.kt +++ b/src/net/torvald/colourutil/Col4096.kt @@ -1,6 +1,6 @@ package net.torvald.colourutil -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color /** * 12-bit (16-step) RGB with builtin utils. @@ -41,7 +41,7 @@ class Col4096 : LimitedColours { * * * @return */ - override fun createSlickColor(raw: Int): Color { + override fun createGdxColor(raw: Int): Color { assertRaw(raw) val a: Int @@ -57,22 +57,22 @@ class Col4096 : LimitedColours { a = raw and 0xF000 shr 12 return Color( - r.shl(4) or r, g.shl(4) or g, b.shl(4) or b, a.shl(4) or a) + (r.shl(4) or r).shl(24) + (g.shl(4) or g).shl(16) + (b.shl(4) or b).shl(8) + (a.shl(4) or a)) } else { return Color( - r.shl(4) or r, g.shl(4) or g, b.shl(4) or b) + (r.shl(4) or r).shl(24) + (g.shl(4) or g).shl(16) + (b.shl(4) or b).shl(8) + 255) } } - override fun createSlickColor(r: Int, g: Int, b: Int): Color { + override fun createGdxColor(r: Int, g: Int, b: Int): Color { assertARGB(0, r, g, b) - return createSlickColor(r.shl(8) or g.shl(4) or b) + return createGdxColor(r.shl(8) or g.shl(4) or b) } fun createSlickColor(a: Int, r: Int, g: Int, b: Int): Color { assertARGB(a, r, g, b) - return createSlickColor(a.shl(12) or r.shl(8) or g.shl(4) or b) + return createGdxColor(a.shl(12) or r.shl(8) or g.shl(4) or b) } override fun create(raw: Int) { @@ -107,7 +107,7 @@ class Col4096 : LimitedColours { return ret } - override fun toSlickColour(): Color = createSlickColor(raw.toUint()) + override fun toGdxColour(): Color = createGdxColor(raw.toUint()) private fun assertRaw(i: Int) { if (i > 0xFFFF || i < 0) { diff --git a/src/net/torvald/colourutil/ColourTemp.kt b/src/net/torvald/colourutil/ColourTemp.kt index 465207490..2539a70e3 100644 --- a/src/net/torvald/colourutil/ColourTemp.kt +++ b/src/net/torvald/colourutil/ColourTemp.kt @@ -1,10 +1,8 @@ package net.torvald.colourutil -import net.torvald.terrarum.getPixel -import net.torvald.terrarum.weather.toColor -import org.newdawn.slick.Color -import org.newdawn.slick.Image +import com.badlogic.gdx.graphics.Color import net.torvald.colourutil.CIEXYZUtil.toColor +import net.torvald.terrarum.GdxColorMap import net.torvald.terrarum.ModMgr /** @@ -12,7 +10,7 @@ import net.torvald.terrarum.ModMgr * Created by minjaesong on 16-07-26. */ object ColourTemp { - private var clut = Image(ModMgr.getPath("basegame", "colourmap/black_body_col_1000_40000_K.tga")) + private var clut = GdxColorMap(ModMgr.getGdxFile("basegame", "colourmap/black_body_col_1000_40000_K.tga")) private fun colTempToImagePos(K: Int): Int { if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)") @@ -21,7 +19,7 @@ object ColourTemp { /** returns sRGB-normalised colour */ operator fun invoke(temp: Int): Color = - clut.getPixel(colTempToImagePos(temp), 0).toColor() + clut.get(colTempToImagePos(temp)) /** returns CIExyY-based colour converted to slick.color * @param CIE_Y 0.0 - 1.0+ */ diff --git a/src/net/torvald/colourutil/ColourUtil.kt b/src/net/torvald/colourutil/ColourUtil.kt index 3be83ead8..485589ded 100644 --- a/src/net/torvald/colourutil/ColourUtil.kt +++ b/src/net/torvald/colourutil/ColourUtil.kt @@ -1,13 +1,13 @@ package net.torvald.colourutil import com.jme3.math.FastMath -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color /** * Created by minjaesong on 16-07-26. */ object ColourUtil { - fun toSlickColor(r: Int, g: Int, b: Int) = Color(r.shl(16) or g.shl(8) or b) + fun toColor(r: Int, g: Int, b: Int) = Color(r.shl(24) or g.shl(16) or b.shl(8) or 0xff) /** * Use CIELabUtil.getGradient for natural-looking colour diff --git a/src/net/torvald/colourutil/HSVUtil.kt b/src/net/torvald/colourutil/HSVUtil.kt index 63153a3be..496290e5f 100644 --- a/src/net/torvald/colourutil/HSVUtil.kt +++ b/src/net/torvald/colourutil/HSVUtil.kt @@ -1,7 +1,7 @@ package net.torvald.colourutil import com.jme3.math.FastMath -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color /** * OBSOLETE; use CIELchUtil for natural-looking colour @@ -17,9 +17,6 @@ object HSVUtil { * @param S 0-1 Saturation * * * @param V 0-1 Value - * * - * @return org.newdawn.slick.Color - * * * @link http://www.rapidtables.com/convert/color/hsv-to-rgb.htm */ fun toRGB(H: Float, S: Float, V: Float, alpha: Float = 1f): Color { diff --git a/src/net/torvald/colourutil/LimitedColours.kt b/src/net/torvald/colourutil/LimitedColours.kt index 40744be5c..eedd033cd 100644 --- a/src/net/torvald/colourutil/LimitedColours.kt +++ b/src/net/torvald/colourutil/LimitedColours.kt @@ -1,17 +1,17 @@ package net.torvald.colourutil -import org.newdawn.slick.Color +import com.badlogic.gdx.graphics.Color /** * Created by minjaesong on 16-02-11. */ interface LimitedColours { - fun createSlickColor(raw: Int): Color - fun createSlickColor(r: Int, g: Int, b: Int): Color + fun createGdxColor(raw: Int): Color + fun createGdxColor(r: Int, g: Int, b: Int): Color fun create(raw: Int) fun create(r: Int, g: Int, b: Int) - fun toSlickColour(): Color + fun toGdxColour(): Color } diff --git a/src/net/torvald/imagefont/TinyAlphNum.kt b/src/net/torvald/imagefont/TinyAlphNum.kt deleted file mode 100644 index 049f83270..000000000 --- a/src/net/torvald/imagefont/TinyAlphNum.kt +++ /dev/null @@ -1,79 +0,0 @@ -package net.torvald.imagefont - -import org.newdawn.slick.Color -import org.newdawn.slick.Font -import org.newdawn.slick.SpriteSheet -import java.util.* - -/** - * Created by minjaesong on 16-04-15. - */ -class TinyAlphNum : Font { - - internal val fontSheet: SpriteSheet - - internal val W = 8 - internal val H = 8 - - /*private val chars = arrayOf( - '0','1','2','3','4','5','6','7', - '8','9','[','#','@',':','>','?', - ' ','A','B','C','D','E','F','G', - 'H','I','&','.',']','(','<','\\', - '^','J','K','L','M','N','O','P', - 'Q','R','-','¤','*',')',';','\'', - '+','/','S','T','U','V','W','X', - 'Y','Z','_',',','%','=','"','!' - ) - private val mappingTable = HashMap()*/ - - init { - fontSheet = SpriteSheet("./assets/graphics/fonts/milky.tga", W, H) - //chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i } - } - - override fun getHeight(str: String): Int = H - - override fun getWidth(str: String): Int { - var ret = 0 - for (i in 0..str.length - 1) { - val c = str.codePointAt(i).toChar() - if (!c.isColourCode()) - ret += W - } - return ret - } - - override fun getLineHeight(): Int = H - - override fun drawString(x: Float, y: Float, text: String) = drawString(x, y, text, Color.white) - - override fun drawString(x: Float, y: Float, text: String, col: Color) { - var thisCol = col - var textPosOffset = 0 - for (i in 0..text.length - 1) { - //val index = charToSpriteNum(text.toUpperCase().codePointAt(i)) - val ch = text[i] - val index = ch.toInt() and 0xFF - - if (ch.isColourCode()) { - thisCol = GameFontBase.colourKey[ch]!! - continue - } - - fontSheet.getSubImage(index % 16, index / 16).drawWithShadow( - x + textPosOffset, y, thisCol, false - ) - - textPosOffset += W - } - } - - override fun drawString(x: Float, y: Float, text: String, col: Color, startIndex: Int, endIndex: Int) { - throw UnsupportedOperationException() - } - - //private fun charToSpriteNum(ch: Int): Int? = mappingTable[ch] - - fun Char.isColourCode() = GameFontBase.colourKey.containsKey(this) -} \ No newline at end of file diff --git a/src/net/torvald/slick/opengl/TGAGzImageData.java b/src/net/torvald/slick/opengl/TGAGzImageData.java deleted file mode 100644 index 0065cacf8..000000000 --- a/src/net/torvald/slick/opengl/TGAGzImageData.java +++ /dev/null @@ -1,328 +0,0 @@ -package net.torvald.slick.opengl; - -/* - * A utility to load .tga.gz - * - * Created by SKYHi14 on 2017-04-19. - */ - - -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.zip.GZIPInputStream; - -import org.lwjgl.BufferUtils; -import org.newdawn.slick.opengl.LoadableImageData; - -/** - * A utility to load TGAs. Note: NOT THREAD SAFE - * - * Fresh cut of code but largely influeneced by the TGA loading class - * provided as part of the Java Monkey Engine (JME). Why not check out - * what they're doing over at http://www.jmonkeyengine.com. kudos to - * Mark Powell. - * - * @author Kevin Glass - */ -public class TGAGzImageData implements LoadableImageData { - /** The width of the texture that needs to be generated */ - private int texWidth; - /** The height of the texture that needs to be generated */ - private int texHeight; - /** The width of the TGA image */ - private int width; - /** The height of the TGA image */ - private int height; - /** The bit depth of the image */ - private short pixelDepth; - - /** - * Create a new TGA Loader - */ - public TGAGzImageData() { - } - - /** - * Flip the endian-ness of the short - * - * @param signedShort The short to flip - * @return The flipped short - */ - private short flipEndian(short signedShort) { - int input = signedShort & 0xFFFF; - return (short) (input << 8 | (input & 0xFF00) >>> 8); - } - - /** - * @see org.newdawn.slick.opengl.ImageData#getDepth() - */ - public int getDepth() { - return pixelDepth; - } - - /** - * @see org.newdawn.slick.opengl.ImageData#getWidth() - */ - public int getWidth() { - return width; - } - - /** - * @see org.newdawn.slick.opengl.ImageData#getHeight() - */ - public int getHeight() { - return height; - } - - /** - * @see org.newdawn.slick.opengl.ImageData#getTexWidth() - */ - public int getTexWidth() { - return texWidth; - } - - /** - * @see org.newdawn.slick.opengl.ImageData#getTexHeight() - */ - public int getTexHeight() { - return texHeight; - } - - /** - * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream) - */ - public ByteBuffer loadImage(InputStream fis) throws IOException { - return loadImage(fis,true, null); - } - - /** - * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, int[]) - */ - public ByteBuffer loadImage(InputStream fis, boolean flipped, int[] transparent) throws IOException { - return loadImage(fis, flipped, false, transparent); - } - - /** - * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[]) - */ - public ByteBuffer loadImage(InputStream fis, boolean flipped, boolean forceAlpha, int[] transparent) throws IOException { - if (transparent != null) { - forceAlpha = true; - } - byte red = 0; - byte green = 0; - byte blue = 0; - byte alpha = 0; - - BufferedInputStream bis = new BufferedInputStream(new GZIPInputStream(fis, 8192), 16384); - DataInputStream dis = new DataInputStream(bis); - - // Read in the Header - short idLength = (short) dis.read(); - short colorMapType = (short) dis.read(); - short imageType = (short) dis.read(); - short cMapStart = flipEndian(dis.readShort()); - short cMapLength = flipEndian(dis.readShort()); - short cMapDepth = (short) dis.read(); - short xOffset = flipEndian(dis.readShort()); - short yOffset = flipEndian(dis.readShort()); - - if (imageType != 2) { - throw new IOException("Slick only supports uncompressed RGB(A) TGA images"); - } - - width = flipEndian(dis.readShort()); - height = flipEndian(dis.readShort()); - pixelDepth = (short) dis.read(); - if (pixelDepth == 32) { - forceAlpha = false; - } - - texWidth = get2Fold(width); - texHeight = get2Fold(height); - - short imageDescriptor = (short) dis.read(); - if ((imageDescriptor & 0x0020) == 0) { - flipped = !flipped; - } - - // Skip image ID - if (idLength > 0) { - bis.skip(idLength); - } - - byte[] rawData = null; - if ((pixelDepth == 32) || (forceAlpha)) { - pixelDepth = 32; - rawData = new byte[texWidth * texHeight * 4]; - } else if (pixelDepth == 24) { - rawData = new byte[texWidth * texHeight * 3]; - } else { - throw new RuntimeException("Only 24 and 32 bit TGAs are supported"); - } - - if (pixelDepth == 24) { - if (flipped) { - for (int i = height-1; i >= 0; i--) { - for (int j = 0; j < width; j++) { - blue = dis.readByte(); - green = dis.readByte(); - red = dis.readByte(); - - int ofs = ((j + (i * texWidth)) * 3); - rawData[ofs] = red; - rawData[ofs + 1] = green; - rawData[ofs + 2] = blue; - } - } - } else { - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - blue = dis.readByte(); - green = dis.readByte(); - red = dis.readByte(); - - int ofs = ((j + (i * texWidth)) * 3); - rawData[ofs] = red; - rawData[ofs + 1] = green; - rawData[ofs + 2] = blue; - } - } - } - } else if (pixelDepth == 32) { - if (flipped) { - for (int i = height-1; i >= 0; i--) { - for (int j = 0; j < width; j++) { - blue = dis.readByte(); - green = dis.readByte(); - red = dis.readByte(); - if (forceAlpha) { - alpha = (byte) 255; - } else { - alpha = dis.readByte(); - } - - int ofs = ((j + (i * texWidth)) * 4); - - rawData[ofs] = red; - rawData[ofs + 1] = green; - rawData[ofs + 2] = blue; - rawData[ofs + 3] = alpha; - - if (alpha == 0) { - rawData[ofs + 2] = (byte) 0; - rawData[ofs + 1] = (byte) 0; - rawData[ofs] = (byte) 0; - } - } - } - } else { - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - blue = dis.readByte(); - green = dis.readByte(); - red = dis.readByte(); - if (forceAlpha) { - alpha = (byte) 255; - } else { - alpha = dis.readByte(); - } - - int ofs = ((j + (i * texWidth)) * 4); - - if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) { - rawData[ofs] = red; - rawData[ofs + 1] = green; - rawData[ofs + 2] = blue; - rawData[ofs + 3] = alpha; - } else { - rawData[ofs] = red; - rawData[ofs + 1] = green; - rawData[ofs + 2] = blue; - rawData[ofs + 3] = alpha; - } - - if (alpha == 0) { - rawData[ofs + 2] = 0; - rawData[ofs + 1] = 0; - rawData[ofs] = 0; - } - } - } - } - } - fis.close(); - - if (transparent != null) { - for (int i=0;i 0) { delay = newDelay } @@ -169,17 +155,4 @@ class SpriteAnimation(val parentActor: ActorWithPhysics, val cellWidth: Int, val flipVertical = vertical } - fun flippedHorizontal(): Boolean { - return flipHorizontal - } - - fun flippedVertical(): Boolean { - return flipVertical - } - - private fun getScaledSprite(scale: Float): Image { - val selectedImage = spriteImage!!.getSprite(currentFrame, currentRow) - selectedImage.filter = Image.FILTER_NEAREST - return selectedImage.getScaledCopy(scale) - } } diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index 006c8fcd1..fbfe1d9c4 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum +import com.badlogic.gdx.Input import com.google.gson.JsonArray -import com.google.gson.JsonElement import com.google.gson.JsonObject import net.torvald.terrarum.gamecontroller.Key @@ -20,7 +20,7 @@ object DefaultConfig { jsonObject.addProperty("smoothlighting", true) jsonObject.addProperty("imtooyoungtodie", false) // perma-death - jsonObject.addProperty("language", Terrarum.sysLang) + jsonObject.addProperty("language", TerrarumGDX.sysLang) jsonObject.addProperty("notificationshowuptime", 6500) jsonObject.addProperty("multithread", true) // experimental! @@ -47,31 +47,31 @@ object DefaultConfig { // control-keyboard (Java key codes. This is what Minecraft also uses) - jsonObject.addProperty("keyup", Key.E) - jsonObject.addProperty("keyleft", Key.S) - jsonObject.addProperty("keydown", Key.D) - jsonObject.addProperty("keyright", Key.F) + jsonObject.addProperty("keyup", Input.Keys.E) + jsonObject.addProperty("keyleft", Input.Keys.S) + jsonObject.addProperty("keydown", Input.Keys.D) + jsonObject.addProperty("keyright", Input.Keys.F) - jsonObject.addProperty("keymovementaux", Key.A) // movement-auxiliary, or hookshot - jsonObject.addProperty("keyinventory", Key.W) - jsonObject.addProperty("keyinteract", Key.R) - jsonObject.addProperty("keyclose", Key.C) + jsonObject.addProperty("keymovementaux", Input.Keys.A) // movement-auxiliary, or hookshot + jsonObject.addProperty("keyinventory", Input.Keys.W) + jsonObject.addProperty("keyinteract", Input.Keys.R) + jsonObject.addProperty("keyclose", Input.Keys.C) - jsonObject.addProperty("keygamemenu", Key.TAB) + jsonObject.addProperty("keygamemenu", Input.Keys.TAB) jsonObject.addProperty("keyquicksel", Key.CAPS_LOCK) // pie menu - val keyquickselalt = JsonArray(); keyquickselalt.add(Key.BACKSPACE); keyquickselalt.add(Key.L_COMMAND); keyquickselalt.add(Key.L_CONTROL) + val keyquickselalt = JsonArray(); keyquickselalt.add(Input.Keys.BACKSPACE); keyquickselalt.add(Key.L_COMMAND); keyquickselalt.add(Input.Keys.CONTROL_LEFT) // Colemak, Workman and some typers use CapsLock as Backspace, Apple-JIS and HHKB has Control in place of CapsLock and often re-assigned to Command // so these keys are treated as the same. // FOR ~~FUCKS~~ERGONOMICS' SAKE DON'T USE CTRL AND ALT AS A KEY! jsonObject.add("keyquickselalt", keyquickselalt) - jsonObject.addProperty("keyjump", Key.SPACE) + jsonObject.addProperty("keyjump", Input.Keys.SPACE) val keyquickbars = JsonArray(); for (i in 2..11) keyquickbars.add(i) // NUM_1 to NUM_0 jsonObject.add("keyquickbars", keyquickbars) - jsonObject.addProperty("mouseprimary", 0) // left mouse - jsonObject.addProperty("mousesecondary", 1) // right mouse + jsonObject.addProperty("mouseprimary", Input.Buttons.LEFT) // left mouse + jsonObject.addProperty("mousesecondary", Input.Buttons.RIGHT) // right mouse jsonObject.addProperty("pcgamepadenv", "console") diff --git a/src/net/torvald/terrarum/GdxColorMap.kt b/src/net/torvald/terrarum/GdxColorMap.kt new file mode 100644 index 000000000..a00880991 --- /dev/null +++ b/src/net/torvald/terrarum/GdxColorMap.kt @@ -0,0 +1,57 @@ +package net.torvald.terrarum + +import com.badlogic.gdx.files.FileHandle +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.Pixmap +import javax.naming.OperationNotSupportedException + +/** + * Created by minjaesong on 2017-06-17. + */ + +typealias XRGB888 = Int + +class GdxColorMap { + + constructor(imageFile: FileHandle) { + val pixmap = Pixmap(imageFile) + width = pixmap.width + height = pixmap.height + is2D = pixmap.height == 1 + + data = kotlin.IntArray(pixmap.width * pixmap.height, { + pixmap.getPixel(it % pixmap.width, it / pixmap.width) + }) + + pixmap.dispose() + } + + constructor(xrgb888: XRGB888) { + data = intArrayOf(xrgb888.shl(24) + xrgb888.shl(16) + xrgb888.shl(8) + 255) + width = 1 + height = 1 + is2D = false + } + + constructor(gradStart: XRGB888, gradEnd: XRGB888) { + data = intArrayOf(gradStart.shl(24) + gradStart.shl(16) + gradStart.shl(8) + 255, + gradEnd.shl(24) + gradEnd.shl(16) + gradEnd.shl(8) + 255) + width = 1 + height = 2 + is2D = true + } + + private val data: IntArray + val width: Int + val height: Int + val is2D: Boolean + + + + fun get(x: Int, y: Int): Color = Color(data[y * width + x]) + operator fun get(x: Int): Color = if (!is2D) throw OperationNotSupportedException("This is 2D color map") else Color(data[x]) + + fun getRaw(x: Int, y: Int): RGBA8888 = data[y * width + x] + fun getRaw(x: Int): RGBA8888 = if (!is2D) throw OperationNotSupportedException("This is 2D color map") else data[x] + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index 793dceb76..50ec89895 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -1,5 +1,7 @@ package net.torvald.terrarum +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.files.FileHandle import net.torvald.terrarum.utils.CSVFetcher import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex @@ -115,6 +117,9 @@ object ModMgr { checkExistence(module) return "$modDir/$module/${path.sanitisePath()}" } + fun getGdxFile(module: String, path: String): FileHandle { + return Gdx.files.internal(getPath(module, path)) + } fun getFile(module: String, path: String): File { checkExistence(module) return FileSystems.getDefault().getPath(getPath(module, path)).toFile() diff --git a/src/net/torvald/terrarum/StateBlurTest.kt b/src/net/torvald/terrarum/StateBlurTest.kt deleted file mode 100644 index ed1f57523..000000000 --- a/src/net/torvald/terrarum/StateBlurTest.kt +++ /dev/null @@ -1,347 +0,0 @@ -package net.torvald.terrarum - -import com.jme3.math.FastMath -import net.torvald.terrarum.gameactors.floor -import net.torvald.terrarum.gameactors.floorInt -import net.torvald.terrarum.gameworld.toUint -import org.newdawn.slick.* -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.nio.ByteOrder - - -/** - * Software rendering test for blur - * - * Created by minjaesong on 2017-01-12. - */ -class StateBlurTest : BasicGameState() { - - /** Warning: the image must have a bit depth of 32! (use 32-bit PNG or TGA) */ - private val testImage = Image("./assets/test_texture.tga") - private val bluredImage = ImageBuffer(testImage.width, testImage.height) - - override fun init(gc: GameContainer, sbg: StateBasedGame) { - /*testImage.flushPixelData() - - System.arraycopy( - testImage.texture.textureData, 0, - bluredImage.rgba, 0, testImage.texture.textureData.size - )*/ - //kotlin.repeat(3) { fastBoxBlur(bluredImage, 3) } - } - - - - override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { - Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}") - - theta += delta / 500f - if (theta > FastMath.TWO_PI) - theta -= FastMath.TWO_PI - } - - override fun getID() = Terrarum.STATE_ID_TEST_BLUR - - var theta = 0f - - override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) { - System.arraycopy( - testImage.texture.textureData, 0, - bluredImage.rgba, 0, testImage.texture.textureData.size - ) - kotlin.repeat(3) { fastBoxBlur(bluredImage, 3) } - - g.background = Color(0x404040) - val image = bluredImage.image // ImageBuffer.getImage() always HARDCOPIES texture data by - // allocating new ByteBuffer. We need variable so that we can destroy() it manually - g.drawImage(image, - Terrarum.WIDTH.minus(testImage.width).div(2f).floor() + FastMath.cos(theta) * 120, - Terrarum.HEIGHT.minus(testImage.height).div(2f).floor() + FastMath.sin(theta) * 40 - ) - g.flush() - - image.destroy() // You are done and you will be terminated, for the perkeleen memory's sake - } - - private val isLE: Boolean - get() = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN - - /** three iterations of box blur \simeq gaussian blur */ - fun fastBoxBlur(from: Image, to: ImageBuffer, radius: Int) { - - /** 0xRRGGBBAA */ - fun getPixelData(index: Int): Int { - val r = from.texture.textureData[4 * index + if (isLE) 0 else 2].toUint() - val g = from.texture.textureData[4 * index + 1].toUint() - val b = from.texture.textureData[4 * index + if (isLE) 2 else 0].toUint() - - if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { - return r.shl(16) or g.shl(8) or b - } - else { - return b.shl(16) or g.shl(8) or r - } - } - - /** alpha will be passed through */ - fun setPixelData(index: Int, value: Int) { - val r = value.ushr(24).and(0xff) - val g = value.ushr(16).and(0xff) - val b = value.ushr(8).and(0xff) - - to.rgba[4 * index + if (isLE) 0 else 2] = r.toByte() - to.rgba[4 * index + 1] = g.toByte() - to.rgba[4 * index + if (isLE) 2 else 0] = b.toByte() - } - - if (radius < 1) { - return - } - val w = to.texWidth - val h = to.texHeight - val wm = w - 1 - val hm = h - 1 - val wh = w * h - val div = radius + radius + 1 - val r = IntArray(wh) - val g = IntArray(wh) - val b = IntArray(wh) - var rsum: Int - var gsum: Int - var bsum: Int - var x: Int - var y: Int - var i: Int - var p: Int - var p1: Int - var p2: Int - var yp: Int - var yi: Int - var yw: Int - val vmin = IntArray(Math.max(w, h)) - val vmax = IntArray(Math.max(w, h)) - - //img.getPixels(pix, 0, w, 0, 0, w, h) - - val dv = IntArray(256 * div) - i = 0 - while (i < 256 * div) { - dv[i] = i / div - i++ - } - - yi = 0 - yw = yi - - y = 0 - while (y < h) { - bsum = 0 - gsum = bsum - rsum = gsum - i = -radius - while (i <= radius) { - p = getPixelData(yi + Math.min(wm, Math.max(i, 0))) - rsum += p and 0xff0000 shr 16 - gsum += p and 0x00ff00 shr 8 - bsum += p and 0x0000ff - i++ - } - x = 0 - while (x < w) { - - r[yi] = dv[rsum] - g[yi] = dv[gsum] - b[yi] = dv[bsum] - - if (y == 0) { - vmin[x] = Math.min(x + radius + 1, wm) - vmax[x] = Math.max(x - radius, 0) - } - p1 = getPixelData(yw + vmin[x]) - p2 = getPixelData(yw + vmax[x]) - - rsum += (p1 and 0xff0000) - (p2 and 0xff0000) shr 16 - gsum += (p1 and 0x00ff00) - (p2 and 0x00ff00) shr 8 - bsum += (p1 and 0x0000ff) - (p2 and 0x0000ff) - yi++ - x++ - } - yw += w - y++ - } - - x = 0 - while (x < w) { - bsum = 0 - gsum = bsum - rsum = gsum - yp = -radius * w - i = -radius - while (i <= radius) { - yi = Math.max(0, yp) + x - rsum += r[yi] - gsum += g[yi] - bsum += b[yi] - yp += w - i++ - } - yi = x - y = 0 - while (y < h) { - setPixelData(yi, dv[rsum].shl(24) or dv[gsum].shl(16) or dv[bsum].shl(8)) - - if (x == 0) { - vmin[y] = Math.min(y + radius + 1, hm) * w - vmax[y] = Math.max(y - radius, 0) * w - } - p1 = x + vmin[y] - p2 = x + vmax[y] - - rsum += r[p1] - r[p2] - gsum += g[p1] - g[p2] - bsum += b[p1] - b[p2] - - yi += w - y++ - } - x++ - } - } - - fun fastBoxBlur(img: ImageBuffer, radius: Int) { - - /** 0xRRGGBBAA */ - fun getPixelData(index: Int): Int { - val r = img.rgba[4 * index].toUint() - val g = img.rgba[4 * index + 1].toUint() - val b = img.rgba[4 * index + 2].toUint() - - return r.shl(16) or g.shl(8) or b - } - - /** alpha will be passed through */ - fun setPixelData(index: Int, value: Int) { - val r = value.ushr(24).and(0xff) - val g = value.ushr(16).and(0xff) - val b = value.ushr(8).and(0xff) - - img.rgba[4 * index] = r.toByte() - img.rgba[4 * index + 1] = g.toByte() - img.rgba[4 * index + 2] = b.toByte() - } - - if (radius < 1) { - return - } - val w = img.texWidth - val h = img.texHeight - val wm = w - 1 - val hm = h - 1 - val wh = w * h - val div = radius + radius + 1 - val r = IntArray(wh) - val g = IntArray(wh) - val b = IntArray(wh) - var rsum: Int - var gsum: Int - var bsum: Int - var x: Int - var y: Int - var i: Int - var p: Int - var p1: Int - var p2: Int - var yp: Int - var yi: Int - var yw: Int - val vmin = IntArray(Math.max(w, h)) - val vmax = IntArray(Math.max(w, h)) - - //img.getPixels(pix, 0, w, 0, 0, w, h) - - val dv = IntArray(256 * div) - i = 0 - while (i < 256 * div) { - dv[i] = i / div - i++ - } - - yi = 0 - yw = yi - - y = 0 - while (y < h) { - bsum = 0 - gsum = bsum - rsum = gsum - i = -radius - while (i <= radius) { - p = getPixelData(yi + Math.min(wm, Math.max(i, 0))) - rsum += p and 0xff0000 shr 16 - gsum += p and 0x00ff00 shr 8 - bsum += p and 0x0000ff - i++ - } - x = 0 - while (x < w) { - - r[yi] = dv[rsum] - g[yi] = dv[gsum] - b[yi] = dv[bsum] - - if (y == 0) { - vmin[x] = Math.min(x + radius + 1, wm) - vmax[x] = Math.max(x - radius, 0) - } - p1 = getPixelData(yw + vmin[x]) - p2 = getPixelData(yw + vmax[x]) - - rsum += (p1 and 0xff0000) - (p2 and 0xff0000) shr 16 - gsum += (p1 and 0x00ff00) - (p2 and 0x00ff00) shr 8 - bsum += (p1 and 0x0000ff) - (p2 and 0x0000ff) - yi++ - x++ - } - yw += w - y++ - } - - x = 0 - while (x < w) { - bsum = 0 - gsum = bsum - rsum = gsum - yp = -radius * w - i = -radius - while (i <= radius) { - yi = Math.max(0, yp) + x - rsum += r[yi] - gsum += g[yi] - bsum += b[yi] - yp += w - i++ - } - yi = x - y = 0 - while (y < h) { - setPixelData(yi, dv[rsum].shl(24) or dv[gsum].shl(16) or dv[bsum].shl(8)) - - if (x == 0) { - vmin[y] = Math.min(y + radius + 1, hm) * w - vmax[y] = Math.max(y - radius, 0) * w - } - p1 = x + vmin[y] - p2 = x + vmax[y] - - rsum += r[p1] - r[p2] - gsum += g[p1] - g[p2] - bsum += b[p1] - b[p2] - - yi += w - y++ - } - x++ - } - } -} diff --git a/src/net/torvald/terrarum/StateControllerRumbleTest.kt b/src/net/torvald/terrarum/StateControllerRumbleTest.kt deleted file mode 100644 index e05decb58..000000000 --- a/src/net/torvald/terrarum/StateControllerRumbleTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.terrarum.gamecontroller.Key -import net.torvald.terrarum.gamecontroller.KeyToggler -import net.torvald.terrarum.gameworld.fmod -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame - -/** - * Created by SKYHi14 on 2017-03-15. - */ -class StateControllerRumbleTest : BasicGameState() { - override fun init(container: GameContainer?, game: StateBasedGame?) { - } - - override fun update(container: GameContainer, game: StateBasedGame, delta: Int) { - Terrarum.appgc.setTitle("${GAME_NAME} — Do not pull out the controller!") - - KeyToggler.update(container.input) - - if (Terrarum.controller != null) { - for (i in 0..minOf(rumblerCount - 1, 9)) { - Terrarum.controller!!.setRumblerStrength(i, if (KeyToggler.isOn(2 + i)) 1f else 0f) - } - } - } - - private var rumblerCount = Terrarum.controller?.rumblerCount ?: 0 - - override fun getID() = Terrarum.STATE_ID_TOOL_RUMBLE_DIAGNOSIS - - override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) { - g.font = Terrarum.fontGame - g.color = Color.white - - if (Terrarum.controller != null) { - g.drawString("Controller: ${Terrarum.controller!!.name}", 10f, 10f) - g.drawString("Rumbler count: ${rumblerCount}", 10f, 30f) - g.drawString("Rumblers", 10f, 70f) - for (i in 0..minOf(rumblerCount - 1, 9)) { - g.color = if (KeyToggler.isOn(2 + i)) Color(0x55ff55) else Color(0x808080) - //g.drawString("$i", 10f + i * 16f, 90f) - - g.drawString("$i — ${Terrarum.controller!!.getRumblerName(i)}", 10f, 90f + 20 * i) - } - } - else { - g.drawString("Controller not found.", 10f, 10f) - } - } - -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateFontTester.kt b/src/net/torvald/terrarum/StateFontTester.kt deleted file mode 100644 index fa8c442c4..000000000 --- a/src/net/torvald/terrarum/StateFontTester.kt +++ /dev/null @@ -1,160 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.imagefont.GameFontImpl -import net.torvald.terrarum.langpack.Lang -import org.newdawn.slick.* -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame - -/** - * Created by minjaesong on 16-06-28. - */ -class StateFontTester : BasicGameState() { - val textToPrint = """ -ABCDEFGHIJKLM -NOPQRSTUVWXYZ - -abcdefghijklm -nopqrstuvwxyz - -1234567890 -""" - - lateinit var canvas: Graphics - - //lateinit var segfont: Font - - lateinit var mtfont: Font - - override fun init(gc: GameContainer, game: StateBasedGame) { - canvas = Graphics(1024, 1024) - - } - - override fun update(gc: GameContainer, game: StateBasedGame, delta: Int) { - - } - - override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) { - - g.background = Color(0x282828) - g.font = Terrarum.fontGame - - - g.drawString("ABCDEFGHIJKLMN", 10f, 10f) - g.drawString("OPQRSTÜVWXYZÆŒ", 10f, 30f) - - g.drawString("abcdefghijklmno", 160f, 10f) - g.drawString("pqrstuvwxyzßæœ", 160f, 30f) - - g.drawString("1234567890?!", 320f, 10f) - //g.drawString("minimum kerning keming Narnu Namu", 320f, 30f) - - //g.drawString("Syö salmiakkia perkele", 480f, 10f) - - /*val text = arrayOf( - "The bitmap font for game developers who seek good font that has real multilingual support,", - "for free (as in freedom AND without cost).", - "", - "There are many bitmap fonts on the internet. You care for the multilingual support, but alas!", - "most of them do not support your language, vector fonts take too much time to load, and even", - "then their legibility suffers because fuck built-in antialias.", - "You somehow found a fine one, and it makes your game look like a linux terminal, and you say:", - "“Well, better than nothing *sigh*; No, it’s ugly.”", - "You speak Japanese, and you wish to support it, but then このクソなfontは only good for Japanese,", - "it is not even multilingual, and their English look ugly and inconsistent anyway.", - "Eventually you just use different fonts together, and the result was always mildly infuriating.", - "", - "No more suffering. This font has everything you need.", - "", - "while (isVisible(BadFonts)) { ripAndTear(BadFonts).scope(Guts); }", - "How multilingual? Real multilingual!", - "", - "Příliš žluťoučký kůň úpěl ďábelské ódy", - "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich", - "διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα", - "ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ", - "Pack my box with five dozen liquor jugs", - "Voix ambiguë d'un cœur qui au zéphyr préfère les jattes de kiwi", - "정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날 하얬다 도럄직한 퀡봹퉪헰", - "Kæmi ný öxi hér, ykist þjófum nú bæði víl og ádrepa", - "Árvíztűrő tükörfúrógép Kŕdeľ ďatľov učí koňa žrať kôru", - "とりなくこゑす ゆめさませ みよあけわたる ひんかしを そらいろはえて おきつへに ほふねむれゐぬ もやのうち", - "鳥啼ク声ス 夢覚マセ 見ヨ明ク渡ル 東ヲ 空色栄エテ 沖ツ辺ニ 帆船群レヰヌ 靄ノ中", - "Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila", - "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства", - "Pijamalı hasta yağız şoföre çabucak güvendi", - "Also supports: ‛Unicode’ „quotation marks“—dashes…「括弧」‼", - "ASCII Latin-1 Latin_Ext-A Latin_Ext-B Greek Cyrillic CJK-Ideo Kana Hangul_Syllables", - "", - "…not seeing your language/writing system? Let me know on the Issue Tracker!" - )*/ - val text = arrayOf( - "x64またはx86-64とは、x86アーキテクチャを64ビットに拡張した命令セットアーキテクチャ。", - "実際には、AMDが発表したAMD64命令セット、続けてインテルが採用したIntel 64命令セット (かつてIA-32eまたはEM64Tと呼ばれていた)", - "などを含む、各社のAMD64互換命令セットの総称である。x86命令セットと互換性を持っていることから、広義にはx86にx64を含む場合がある。", - "", - "x86-64는 x86 명령어 집합 아키텍처의 64비트 모임이다. x86-64 명령어 집합은 에뮬레이션 없이 인텔의 x86를 지원하며 AMD64로 이름 붙인", - "AMD에 의해 고안되었다. 이 아키텍처는 인텔 64라는 이름으로 인텔에 의해 복제되기도 했다. (옘힐, 클래카마스 기술, CT, IA-32e, EM64T 등으로", - "불렸음) 이로써 x86-64 또는 x64의 이름을 일상적으로 사용하기에 이르렀다.", - "", - "x86-64 (также AMD64/Intel64/EM64T) — 64-битное расширение, набор команд для архитектуры x86, разработанное", - "компанией AMD, позволяющее выполнять программы в 64-разрядном режиме. Это расширение архитектуры x86 с", - "почти полной обратной совместимостью.", - "", - "Επίσης η x86-64 έχει καταχωρητές γενικής χρήσης 64-bit και πολλές άλλες βελτιώσεις. Η αρχική προδιαγραφή", - "δημιουργήθηκε από την AMD και έχει υλοποιηθεί από την AMD, την Intel, τη VIA και άλλες εταιρείες. Διατηρεί πλήρη", - "συμβατότητα προς τα πίσω με κώδικα 32-bit.", - "", - "x86-64 (簡稱x64) 是64位版本的x86指令集,向后相容於16位及32位的x86架構。x64於1999年由AMD設計,AMD首次公開", - "64位元集以擴充給x86,稱為「AMD64」。其後也為英特爾所採用,現時英特爾稱之為「Intel 64」,在之前曾使用過「Clackamas", - "Technology」 (CT)、「IA-32e」及「EM64T」", - "", - "x86-64, ou x64, est une extension du jeu d'instructions x86 d'Intel, introduite par la société AMD avec la gamme", - "AMD64. Intel utilisera cette extension en l'appelant initialement EM64T renommé aujourd'hui en Intel 64.", - "", - "Amd64 (також x86-64/intel64/em64t/x64) — 64-бітова архітектура мікропроцесора і відповідний набір інструкцій,", - "розроблені компанією AMD. Це розширення архітектури x86 з повною зворотною сумісністю.", - "", - "x86-64 е наименованието на наборът от 64-битови разширения към x86 процесорната архитектура. Като синоним", - "на това наименование, се използват и съкращенията AMD64 (използвано от AMD), EM64T и IA-32e (използвани от", - "Intel) и x64 (използвано от Microsoft)." - ) - val SP = "${0x3000.toChar()}${0x3000.toChar()}" - - /*val text = arrayOf( - "${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"p]}$SP${0xe011.toChar()}..${0xe019.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}" - )*/ - - Terrarum.gameLocale = "bgBG" - - text.forEachIndexed { i, s -> - g.drawString(s, 10f, 70f + 20 * i) - } - - - - - /*val text = arrayOf( - "ru: Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства", - "bg: Под южно дърво, цъфтящо в синьо, бягаше малко пухкаво зайче", - "sr: Ајшо, лепото и чежњо, за љубав срца мога дођи у Хаџиће на кафу" - )*/ - /*val text = arrayOf( - "……退魔の剣に選ばれし ハイラルの勇者よ", - "その たゆまぬ努力と 結実せに剣技を認め……", - "女神ハイリアの名において祝福を授けん……", - "空を舞い 時を回り 黄昏に染まろうとも……", - "結ばれし剣は 勇者の魂と共に……", - "さらなる力が そなたと そして退魔の剣に宿らんことを……" - )*/ - - - /*(0..text.size - 1).forEach { - g.drawString(text[it], 10f, 70f + 20 * it) - }*/ - - } - - override fun getID(): Int = Terrarum.STATE_ID_TEST_FONT -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateGraphicComputerTest.kt b/src/net/torvald/terrarum/StateGraphicComputerTest.kt deleted file mode 100644 index 81af58603..000000000 --- a/src/net/torvald/terrarum/StateGraphicComputerTest.kt +++ /dev/null @@ -1,131 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.random.HQRNG -import net.torvald.terrarum.Terrarum.delta -import net.torvald.terrarum.gameactors.roundInt -import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer -import net.torvald.terrarum.virtualcomputer.peripheral.PeripheralVideoCard -import net.torvald.terrarum.virtualcomputer.terminal.GraphicsTerminal -import org.lwjgl.opengl.GL11 -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.Image -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.util.* - -/** - * Created by SKYHi14 on 2017-02-23. - */ -class StateGraphicComputerTest : BasicGameState() { - val computer = TerrarumComputer(8) - val monitor = GraphicsTerminal(computer) - - val monitorUI: Image - val monitorUIG: Graphics - - init { - val videocard = PeripheralVideoCard(computer) - monitor.attachVideoCard(videocard) - - computer.attachTerminal(monitor) - computer.attachPeripheral(videocard) - - monitorUI = Image(videocard.width, videocard.height * 2) - monitorUIG = monitorUI.graphics - } - - override fun init(container: GameContainer?, game: StateBasedGame?) { - /*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram - - // it's a-me, Mario! - (0..3).forEach { - vcard.sprites[it].setPaletteSet(64,33,12,62) - vcard.sprites[it].isVisible = true - vcard.sprites[it].drawWide = true - } - - vcard.sprites[0].setAll(intArrayOf( - 0,0,0,0,0,1,1,1, - 0,0,0,0,1,1,1,1, - 0,0,0,0,2,2,2,3, - 0,0,0,2,3,2,3,3, - 0,0,0,2,3,2,2,3, - 0,0,0,2,2,3,3,3, - 0,0,0,0,0,3,3,3, - 0,0,0,0,2,2,1,2 - )) - vcard.sprites[1].setAll(intArrayOf( - 1,1,0,0,0,0,0,0, - 1,1,1,1,1,0,0,0, - 3,2,3,0,0,0,0,0, - 3,2,3,3,3,0,0,0, - 3,3,2,3,3,3,0,0, - 3,2,2,2,2,0,0,0, - 3,3,3,3,0,0,0,0, - 2,2,0,0,0,0,0,0 - )) - vcard.sprites[2].setAll(intArrayOf( - 0,0,0,2,2,2,1,2, - 0,0,2,2,2,2,1,1, - 0,0,3,3,2,1,3,1, - 0,0,3,3,3,1,1,1, - 0,0,3,3,1,1,1,1, - 0,0,0,0,1,1,1,0, - 0,0,0,2,2,2,0,0, - 0,0,2,2,2,2,0,0 - )) - vcard.sprites[3].setAll(intArrayOf( - 2,1,2,2,2,0,0,0, - 1,1,2,2,2,2,0,0, - 1,3,1,2,3,3,0,0, - 1,1,1,3,3,3,0,0, - 1,1,1,1,3,3,0,0, - 0,1,1,1,0,0,0,0, - 0,0,2,2,2,0,0,0, - 0,0,2,2,2,2,0,0 - ))*/ - } - - var angle = 0.0 - - override fun update(container: GameContainer, game: StateBasedGame?, delta: Int) { - Terrarum.delta = delta - - Terrarum.appgc.setTitle("VT — F: ${container.fps}" + - " — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M" + - " ${Random().nextInt(100)}") - monitor.update(container, delta) - computer.update(container, delta) - - - /*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram - val sprites = vcard.sprites - angle += delta / 1000.0 - - - sprites[0].posX = (Math.cos(angle) * 80 + 100).roundInt() - 16 - sprites[0].posY = (Math.sin(angle) * 0 + 100).roundInt() - 8 - - sprites[1].posX = (Math.cos(angle) * 80 + 100).roundInt() - sprites[1].posY = (Math.sin(angle) * 0 + 100).roundInt() - 8 - - sprites[2].posX = (Math.cos(angle) * 80 + 100).roundInt() - 16 - sprites[2].posY = (Math.sin(angle) * 0 + 100).roundInt() - - sprites[3].posX = (Math.cos(angle) * 80 + 100).roundInt() - sprites[3].posY = (Math.sin(angle) * 0 + 100).roundInt()*/ - } - - override fun getID() = Terrarum.STATE_ID_TEST_TTY - - - override fun render(container: GameContainer, game: StateBasedGame?, g: Graphics) { - monitor.render(container, monitorUIG) - g.drawImage(monitorUI, 30f, 30f) - } - - override fun keyPressed(key: Int, c: Char) { - monitor.keyPressed(key, c) - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGameGDX.kt similarity index 65% rename from src/net/torvald/terrarum/StateInGame.kt rename to src/net/torvald/terrarum/StateInGameGDX.kt index 78ddf0d70..2ca68fac7 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGameGDX.kt @@ -1,14 +1,16 @@ package net.torvald.terrarum +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Screen +import com.badlogic.gdx.graphics.* +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.glutils.FrameBuffer + import net.torvald.dataclass.CircularArray -import net.torvald.imagefont.GameFontBase -import net.torvald.random.HQRNG -import net.torvald.terrarum.Terrarum.HALFH -import net.torvald.terrarum.Terrarum.HALFW -import net.torvald.terrarum.Terrarum.delta +import net.torvald.terrarum.blockproperties.BlockPropUtil +import net.torvald.terrarum.blockstats.BlockStats import net.torvald.terrarum.concurrent.ThreadParallel import net.torvald.terrarum.console.* -import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver import net.torvald.terrarum.gamecontroller.GameController @@ -16,30 +18,33 @@ import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.WorldSimulator -import net.torvald.terrarum.worlddrawer.LightmapRenderer -import net.torvald.terrarum.worlddrawer.LightmapRenderer.constructRGBFromInt +import net.torvald.terrarum.weather.WeatherMixer import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.FeaturesDrawer -import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE +import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.WorldCamera -import net.torvald.terrarum.worldgenerator.WorldGenerator -import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser -import net.torvald.terrarum.blockproperties.BlockPropUtil -import net.torvald.terrarum.blockstats.BlockStats -import net.torvald.terrarum.ui.* -import net.torvald.terrarum.weather.WeatherMixer -import org.newdawn.slick.* -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.util.* + +import java.util.ArrayList import java.util.concurrent.locks.Lock import java.util.concurrent.locks.ReentrantLock + import javax.swing.JOptionPane +import com.badlogic.gdx.graphics.OrthographicCamera +import com.badlogic.gdx.graphics.glutils.ShapeRenderer +import net.torvald.random.HQRNG +import net.torvald.terrarum.ui.* +import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser +import net.torvald.terrarum.worldgenerator.WorldGenerator + + /** - * Created by minjaesong on 15-12-30. + * Created by minjaesong on 2017-06-16. */ -class StateInGame : BasicGameState() { + +class StateInGameGDX(val batch: SpriteBatch) : Screen { + + private val ACTOR_UPDATE_RANGE = 4096 lateinit var world: GameWorld @@ -48,7 +53,7 @@ class StateInGame : BasicGameState() { * list of Actors that is sorted by Actors' referenceID */ val ACTORCONTAINER_INITIAL_SIZE = 64 - val PARTICLES_MAX = Terrarum.getConfigInt("maxparticles") + val PARTICLES_MAX = TerrarumGDX.getConfigInt("maxparticles") val actorContainer = ArrayList(ACTORCONTAINER_INITIAL_SIZE) val actorContainerInactive = ArrayList(ACTORCONTAINER_INITIAL_SIZE) val particlesContainer = CircularArray(PARTICLES_MAX) @@ -68,10 +73,8 @@ class StateInGame : BasicGameState() { val ZOOM_MAX = 4.0f val ZOOM_MIN = 0.5f - val worldDrawFrameBuffer = Image(Terrarum.WIDTH.div(ZOOM_MIN).ceilInt(), Terrarum.HEIGHT.div(ZOOM_MIN).ceilInt()) - val worldG = worldDrawFrameBuffer.graphics - val backDrawFrameBuffer = Image(Terrarum.WIDTH, Terrarum.HEIGHT) - val backG = backDrawFrameBuffer.graphics + var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false) + var backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false) //private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader //private lateinit var shaderBlur: Shader @@ -114,13 +117,70 @@ class StateInGame : BasicGameState() { inline val canPlayerControl: Boolean get() = !paused // FIXME temporary behab (block movement if the game is paused or paused by UIs) - @Throws(SlickException::class) - override fun init(gameContainer: GameContainer, stateBasedGame: StateBasedGame) { - // state init code. Executed before the game goes into any "state" in states in StateBasedGame.java + var particlesActive = 0 + private set + + ////////////// + // GDX code // + ////////////// + + var camera = OrthographicCamera(Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) + + // invert Y + fun initViewPort(width: Int, height: Int, aspect: Float) { + val width = width.toFloat() + val height = height.toFloat() + + // Get the window size in pixels + val w = Gdx.graphics.width.toFloat() + val h = Gdx.graphics.height.toFloat() + + val vw: Float + val vh: Float // Viewport size in screen coordinates + val ox: Float + val oy: Float // Viewport offset in screen coordinates + + // Check aspect ratio + if (w > h * aspect) { + // Black bars on the sides + vh = h + vw = Math.round(vh * aspect).toFloat() + oy = 0f + ox = (w - vw) / 2 + } + else { + // Black bars on top and bottom + vw = w + vh = Math.round(vw * (1 / aspect)).toFloat() + ox = 0f + oy = (h - vh) / 2 + } + + // Create camera with the desired resolution + camera = OrthographicCamera(width, height) + + // Move camera center to push 0,0 into the corner + camera.translate(width / 2, height / 2) + + // Set Y to point downwards + camera.setToOrtho(true, width, height) + + // Update camera matrix + camera.update() + + // Set viewport to restrict drawing + Gdx.gl20.glViewport(ox.toInt(), oy.toInt(), vw.toInt(), vh.toInt()) } - override fun enter(gc: GameContainer, sbg: StateBasedGame) { + + override fun show() { + // Set up viewport on first load + initViewPort(Gdx.graphics.width, Gdx.graphics.height, Gdx.graphics.width.toFloat() / Gdx.graphics.height.toFloat()) + } + + + fun enter() { // load things when the game entered this "state" // load necessary shaders //shader12BitCol = Shader.makeShader("./assets/4096.vert", "./assets/4096.frag") @@ -163,10 +223,10 @@ class StateInGame : BasicGameState() { notifier = UIHandler(Notification()) notifier.UI.handler = notifier notifier.setPosition( - (Terrarum.WIDTH - notifier.UI.width) / 2, Terrarum.HEIGHT - notifier.UI.height) + (Gdx.graphics.width - notifier.UI.width) / 2, Gdx.graphics.height - notifier.UI.height) // set smooth lighting as in config - KeyToggler.forceSet(KEY_LIGHTMAP_SMOOTH, Terrarum.getConfigBoolean("smoothlighting")) + KeyToggler.forceSet(KEY_LIGHTMAP_SMOOTH, TerrarumGDX.getConfigBoolean("smoothlighting")) @@ -175,10 +235,10 @@ class StateInGame : BasicGameState() { uiInventoryPlayer = UIHandler( UIInventory(player, width = 840, - height = Terrarum.HEIGHT - 160, + height = Gdx.graphics.height - 160, categoryWidth = 210 ), - toggleKey = Terrarum.getConfigInt("keyinventory") + toggleKey = TerrarumGDX.getConfigInt("keyinventory") ) uiInventoryPlayer.setPosition( -uiInventoryPlayer.UI.width, @@ -193,34 +253,34 @@ class StateInGame : BasicGameState() { // pie menu uiPieMenu = UIHandler(UIPieMenu()) - uiPieMenu.setPosition(HALFW, HALFH) + uiPieMenu.setPosition(TerrarumGDX.HALFW, TerrarumGDX.HALFH) // vital metre // fill in getter functions by // (uiAliases[UI_QUICK_BAR]!!.UI as UIVitalMetre).vitalGetterMax = { some_function } - uiVitalPrimary = UIHandler(UIVitalMetre(player, { 80f }, { 100f }, Color.red, 2), customPositioning = true) - uiVitalPrimary.setAsAlwaysVisible() - uiVitalSecondary = UIHandler(UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1), customPositioning = true) - uiVitalSecondary.setAsAlwaysVisible() - uiVitalItem = UIHandler(UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0), customPositioning = true) - uiVitalItem.setAsAlwaysVisible() + //uiVitalPrimary = UIHandler(UIVitalMetre(player, { 80f }, { 100f }, Color.red, 2), customPositioning = true) + //uiVitalPrimary.setAsAlwaysVisible() + //uiVitalSecondary = UIHandler(UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1), customPositioning = true) + //uiVitalSecondary.setAsAlwaysVisible() + //uiVitalItem = UIHandler(UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0), customPositioning = true) + //uiVitalItem.setAsAlwaysVisible() // basic watch-style notification bar (temperature, new mail) uiWatchBasic = UIHandler(UIBasicNotifier(player)) uiWatchBasic.setAsAlwaysVisible() - uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.UI.width, 0) + uiWatchBasic.setPosition(Gdx.graphics.width - uiWatchBasic.UI.width, 0) uiWatchTierOne = UIHandler(UITierOneWatch(player)) uiWatchTierOne.setAsAlwaysVisible() - uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2) + uiWatchTierOne.setPosition(Gdx.graphics.width - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2) // batch-process uiAliases uiAliases = arrayListOf( // drawn first - uiVitalPrimary, - uiVitalSecondary, - uiVitalItem, + //uiVitalPrimary, + //uiVitalSecondary, + //uiVitalItem, uiPieMenu, uiQuickBar, uiWatchBasic, @@ -234,27 +294,26 @@ class StateInGame : BasicGameState() { ) uiAlasesPausing.forEach { addUI(it) } // put them all to the UIContainer uiAliases.forEach { addUI(it) } // put them all to the UIContainer - - - - - - - // audio test - //AudioResourceLibrary.ambientsWoods[0].play() } - var particlesActive = 0 - private set - override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { + /////////////// + // prod code // + /////////////// + override fun render(delta: Float) { + Gdx.graphics.setTitle(GAME_NAME + + " — F: ${Gdx.graphics.framesPerSecond} (${TerrarumGDX.TARGET_INTERNAL_FPS})" + + " — M: ${TerrarumGDX.memInUse}M / ${TerrarumGDX.memTotal}M / ${TerrarumGDX.memXmx}M" + ) + + + /** UPDATE CODE GOES HERE */ + particlesActive = 0 - Terrarum.delta = delta - setAppTitle() - KeyToggler.update(gc.input) - GameController.processInput(gc, delta, gc.input) + KeyToggler.update() + GameController.processInput(delta) if (!paused) { @@ -265,26 +324,22 @@ class StateInGame : BasicGameState() { BlockPropUtil.dynamicLumFuncTickClock() world.updateWorldTime(delta) //WorldSimulator(player, delta) - WeatherMixer.update(gc, delta) + WeatherMixer.update(delta) BlockStats.update() if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride) - world.globalLight = constructRGBFromInt( - WeatherMixer.globalLightNow.redByte, - WeatherMixer.globalLightNow.greenByte, - WeatherMixer.globalLightNow.blueByte - ) + world.globalLight = WeatherMixer.globalLightNow.toRGB10() /////////////////////////// // input-related updates // /////////////////////////// - uiContainer.forEach { it.processInput(gc, delta, gc.input) } + uiContainer.forEach { it.processInput(delta) } //////////////////////////// // camera-related updates // //////////////////////////// - FeaturesDrawer.update(gc, delta) + FeaturesDrawer.update(delta) WorldCamera.update() @@ -298,8 +353,8 @@ class StateInGame : BasicGameState() { wakeDormantActors() // determine whether the actor should keep being activated or be dormant KillOrKnockdownActors() - updateActors(gc, delta) - particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(gc, delta) } + updateActors(delta) + particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) } // TODO thread pool(?) CollisionSolver.process() } @@ -308,9 +363,9 @@ class StateInGame : BasicGameState() { //////////////////////// // ui-related updates // //////////////////////// - uiContainer.forEach { it.update(gc, delta) } - debugWindow.update(gc, delta) - notifier.update(gc, delta) + uiContainer.forEach { it.update(delta) } + debugWindow.update(delta) + notifier.update(delta) // update debuggers using javax.swing // if (Authenticator.b()) { @@ -325,9 +380,183 @@ class StateInGame : BasicGameState() { ///////////////////////// // determine if lightmap blending should be done - Terrarum.setConfig("smoothlighting", KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH)) + TerrarumGDX.setConfig("smoothlighting", KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH)) + + + + /** RENDER CODE GOES HERE */ + renderGame(batch, delta) } + + private fun renderGame(batch: SpriteBatch, delta: Float) { + Gdx.gl.glClearColor(.157f, .157f, .157f, 0f) + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) + + camera.position.set(-WorldCamera.x.toFloat(), -WorldCamera.y.toFloat(), 0f) // make camara work + + batch.projectionMatrix = camera.combined + + TerrarumGDX.GLOBAL_RENDER_TIMER += 1 + + + // clean the shit beforehand + worldDrawFrameBuffer.inAction { + Gdx.gl.glClearColor(0f,0f,0f,1f) + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) + } + backDrawFrameBuffer.inAction { + Gdx.gl.glClearColor(0f,0f,0f,1f) + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) + } + + + + + blendNormal() + backDrawFrameBuffer.inAction { + batch.inUse { + WeatherMixer.render(batch) // drawing to gwin so that any lights from lamp wont "leak" to the skybox + // e.g. Bright blue light on sunset + } + } + blendNormal() + + ///////////////////////////// + // draw map related stuffs // + ///////////////////////////// + worldDrawFrameBuffer.inAction { + batch.inUse { + BlocksDrawer.renderWall(batch) + actorsRenderBehind.forEach { it.drawBody(batch) } + actorsRenderBehind.forEach { it.drawGlow(batch) } + particlesContainer.forEach { it.drawBody(batch) } + particlesContainer.forEach { it.drawGlow(batch) } + BlocksDrawer.renderTerrain(batch) + + ///////////////// + // draw actors // + ///////////////// + actorsRenderMiddle.forEach { it.drawBody(batch) } + actorsRenderMidTop.forEach { it.drawBody(batch) } + player?.drawBody(batch) + actorsRenderFront.forEach { it.drawBody(batch) } + // --> Change of blend mode <-- introduced by childs of ActorWithBody // + + + ///////////////////////////// + // draw map related stuffs // + ///////////////////////////// + LightmapRenderer.renderLightMap() + + BlocksDrawer.renderFront(batch, false) + // --> blendNormal() <-- by BlocksDrawer.renderFront + FeaturesDrawer.render(batch) + + + FeaturesDrawer.drawEnvOverlay(batch) + + if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() + else blendNormal() + LightmapRenderer.draw(batch) + + + ////////////////////// + // draw actor glows // + ////////////////////// + actorsRenderMiddle.forEach { it.drawGlow(batch) } + actorsRenderMidTop.forEach { it.drawGlow(batch) } + player?.drawGlow(batch) + actorsRenderFront.forEach { it.drawGlow(batch) } + // --> blendLightenOnly() <-- introduced by childs of ActorWithBody // + + + //////////////////////// + // debug informations // + //////////////////////// + blendNormal() + // draw reference ID if debugWindow is open + if (debugWindow.isVisible) { + actorContainer.forEachIndexed { i, actor -> + if (actor is ActorWithBody) { + batch.color = Color.WHITE + TerrarumGDX.fontSmallNumbers.draw(batch, + actor.referenceID.toString(), + actor.hitbox.startX.toFloat(), + actor.hitbox.canonicalY.toFloat() + 4 + ) + } + } + } + // debug physics + if (KeyToggler.isOn(Key.F11)) { + actorContainer.forEachIndexed { i, actor -> + if (actor is ActorWithPhysics) { + /*shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) { + shapeRenderer.color = Color(1f, 0f, 1f, 1f) + //shapeRenderer.lineWidth = 1f + shapeRenderer.rect( + actor.hitbox.startX.toFloat(), + actor.hitbox.startY.toFloat(), + actor.hitbox.width.toFloat(), + actor.hitbox.height.toFloat() + ) + }*/ + + // velocity + batch.color = Color.CHARTREUSE//GameFontBase.codeToCol["g"] + TerrarumGDX.fontSmallNumbers.draw(batch, + "${0x7F.toChar()}X ${actor.externalForce.x}", + actor.hitbox.startX.toFloat(), + actor.hitbox.canonicalY.toFloat() + 4 + 8 + ) + TerrarumGDX.fontSmallNumbers.draw(batch, + "${0x7F.toChar()}Y ${actor.externalForce.y}", + actor.hitbox.startX.toFloat(), + actor.hitbox.canonicalY.toFloat() + 4 + 8 * 2 + ) + } + } + } + // fluidmap debug + if (KeyToggler.isOn(Key.F4)) + WorldSimulator.drawFluidMapDebug(batch) + + + } + } + ///////////////// + // GUI Predraw // + ///////////////// + //worldG.flush() + //backG.drawImage(worldDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f) + //backG.flush() + + + ///////////////////// + // draw UIs ONLY! // + ///////////////////// + uiContainer.forEach { if (it != consoleHandler) it.render(batch) } + debugWindow.render(batch) + // make sure console draws on top of other UIs + consoleHandler.render(batch) + notifier.render(batch) + + + ////////////////// + // GUI Postdraw // + ////////////////// + //backG.flush() + //gwin.drawImage(backDrawFrameBuffer, 0f, 0f) + + // centre marker + /*gwin.color = Color(0x00FFFF) + gwin.lineWidth = 1f + gwin.drawLine(Gdx.graphics.width / 2f, 0f, Gdx.graphics.width / 2f, Gdx.graphics.height.toFloat()) + gwin.drawLine(0f, Gdx.graphics.height / 2f, Gdx.graphics.width.toFloat(), Gdx.graphics.height / 2f)*/ + } + + private fun repossessActor() { // check if currently pocessed actor is removed from game if (!theGameHasActor(player)) { @@ -345,7 +574,7 @@ class StateInGame : BasicGameState() { } playableActorDelegate = newActor - WorldSimulator(player, delta) + WorldSimulator(player, Gdx.graphics.deltaTime) } private fun changePossession(refid: Int) { @@ -360,192 +589,9 @@ class StateInGame : BasicGameState() { // accept new delegate playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid) playableActorDelegate!!.actor.collisionType = ActorWithPhysics.COLLISION_KINEMATIC - WorldSimulator(player, delta) + WorldSimulator(player, Gdx.graphics.deltaTime) } - private fun setAppTitle() { - Terrarum.appgc.setTitle( - Terrarum.NAME + - " — F: ${Terrarum.appgc.fps} (${Terrarum.TARGET_INTERNAL_FPS})" + - " — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M" - ) - } - - override fun render(gc: GameContainer, sbg: StateBasedGame, gwin: Graphics) { - Terrarum.GLOBAL_RENDER_TIMER += 1 - - // clean the shit beforehand - worldG.clear() - backG.clear() - - blendNormal() - - - drawSkybox(backG) // drawing to gwin so that any lights from lamp wont "leak" to the skybox - // e.g. Bright blue light on sunset - - - // make camara work - worldG.translate(-WorldCamera.x.toFloat(), -WorldCamera.y.toFloat()) - - - blendNormal() - - ///////////////////////////// - // draw map related stuffs // - ///////////////////////////// - BlocksDrawer.renderWall(worldG) - actorsRenderBehind.forEach { it.drawBody(worldG) } - actorsRenderBehind.forEach { it.drawGlow(worldG) } - particlesContainer.forEach { it.drawBody(worldG) } - particlesContainer.forEach { it.drawGlow(worldG) } - BlocksDrawer.renderTerrain(worldG) - - ///////////////// - // draw actors // - ///////////////// - actorsRenderMiddle.forEach { it.drawBody(worldG) } - actorsRenderMidTop.forEach { it.drawBody(worldG) } - player?.drawBody(worldG) - actorsRenderFront.forEach { it.drawBody(worldG) } - // --> Change of blend mode <-- introduced by childs of ActorWithBody // - - - ///////////////////////////// - // draw map related stuffs // - ///////////////////////////// - LightmapRenderer.renderLightMap() - - BlocksDrawer.renderFront(worldG, false) - // --> blendNormal() <-- by BlocksDrawer.renderFront - FeaturesDrawer.render(gc, worldG) - - - FeaturesDrawer.drawEnvOverlay(worldG) - - if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() - else blendNormal() - LightmapRenderer.draw(worldG) - - - ////////////////////// - // draw actor glows // - ////////////////////// - actorsRenderMiddle.forEach { it.drawGlow(worldG) } - actorsRenderMidTop.forEach { it.drawGlow(worldG) } - player?.drawGlow(worldG) - actorsRenderFront.forEach { it.drawGlow(worldG) } - // --> blendLightenOnly() <-- introduced by childs of ActorWithBody // - - - //////////////////////// - // debug informations // - //////////////////////// - blendNormal() - // draw reference ID if debugWindow is open - if (debugWindow.isVisible) { - actorContainer.forEachIndexed { i, actor -> - if (actor is ActorWithBody) { - worldG.color = Color.white - worldG.font = Terrarum.fontSmallNumbers - worldG.drawString( - actor.referenceID.toString(), - actor.hitbox.startX.toFloat(), - actor.hitbox.canonicalY.toFloat() + 4 - ) - } - } - } - // debug physics - if (KeyToggler.isOn(Key.F11)) { - actorContainer.forEachIndexed { i, actor -> - if (actor is ActorWithPhysics) { - worldG.color = Color(1f, 0f, 1f, 1f) - worldG.font = Terrarum.fontSmallNumbers - worldG.lineWidth = 1f - worldG.drawRect( - actor.hitbox.startX.toFloat(), - actor.hitbox.startY.toFloat(), - actor.hitbox.width.toFloat(), - actor.hitbox.height.toFloat() - ) - - // velocity - worldG.color = GameFontBase.codeToCol["g"] - worldG.drawString( - "${0x7F.toChar()}X ${actor.externalForce.x}", - actor.hitbox.startX.toFloat(), - actor.hitbox.canonicalY.toFloat() + 4 + 8 - ) - worldG.drawString( - "${0x7F.toChar()}Y ${actor.externalForce.y}", - actor.hitbox.startX.toFloat(), - actor.hitbox.canonicalY.toFloat() + 4 + 8 * 2 - ) - } - } - } - // fluidmap debug - if (KeyToggler.isOn(Key.F4)) - WorldSimulator.drawFluidMapDebug(worldG) - - - - - ///////////////// - // GUI Predraw // - ///////////////// - worldG.flush() - backG.drawImage(worldDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f) - backG.flush() - - - ///////////////////// - // draw UIs ONLY! // - ///////////////////// - uiContainer.forEach { if (it != consoleHandler) it.render(gc, sbg, backG) } - debugWindow.render(gc, sbg, backG) - // make sure console draws on top of other UIs - consoleHandler.render(gc, sbg, backG) - notifier.render(gc, sbg, backG) - - - ////////////////// - // GUI Postdraw // - ////////////////// - backG.flush() - gwin.drawImage(backDrawFrameBuffer, 0f, 0f) - - // centre marker - /*gwin.color = Color(0x00FFFF) - gwin.lineWidth = 1f - gwin.drawLine(Terrarum.WIDTH / 2f, 0f, Terrarum.WIDTH / 2f, Terrarum.HEIGHT.toFloat()) - gwin.drawLine(0f, Terrarum.HEIGHT / 2f, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT / 2f)*/ - } - - override fun keyPressed(key: Int, c: Char) { - if (key == Key.GRAVE || key == Key.ESCAPE) { - consoleHandler.toggleOpening() - } - else if (key == Key.F3) { - debugWindow.toggleOpening() - } - - GameController.keyPressed(key, c) - } - override fun keyReleased(key: Int, c: Char) { GameController.keyReleased(key, c) } - override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { GameController.mouseMoved(oldx, oldy, newx, newy) } - override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { GameController.mouseDragged(oldx, oldy, newx, newy) } - override fun mousePressed(button: Int, x: Int, y: Int) { GameController.mousePressed(button, x, y) } - override fun mouseReleased(button: Int, x: Int, y: Int) { GameController.mouseReleased(button, x, y) } - override fun mouseWheelMoved(change: Int) { GameController.mouseWheelMoved(change) } - override fun controllerButtonPressed(controller: Int, button: Int) { GameController.controllerButtonPressed(controller, button) } - override fun controllerButtonReleased(controller: Int, button: Int) { GameController.controllerButtonReleased(controller, button) } - - override fun getID(): Int = Terrarum.STATE_ID_GAME - - private fun drawSkybox(g: Graphics) = WeatherMixer.render(g) - /** Send message to notifier UI and toggle the UI as opened. */ fun sendNotification(msg: Array) { (notifier.UI as Notification).sendNotification(msg) @@ -600,17 +646,16 @@ class StateInGame : BasicGameState() { * * NOTE: concurrency for actor updating is currently disabled because of it's poor performance */ - fun updateActors(gc: GameContainer, delta: Int) { - if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainer.size > Terrarum.THREADS) { + fun updateActors(delta: Float) { + if (false) { // don't multithread this for now, it's SLOWER //if (TerrarumGDX.MULTITHREAD && actorContainer.size > TerrarumGDX.THREADS) { val actors = actorContainer.size.toFloat() // set up indices - for (i in 0..Terrarum.THREADS - 1) { + for (i in 0..TerrarumGDX.THREADS - 1) { ThreadParallel.map( i, ThreadActorUpdate( - actors.div(Terrarum.THREADS).times(i).roundInt(), - actors.div(Terrarum.THREADS).times(i.plus(1)).roundInt() - 1, - gc, delta + actors.div(TerrarumGDX.THREADS).times(i).roundInt(), + actors.div(TerrarumGDX.THREADS).times(i.plus(1)).roundInt() - 1 ), "ActorUpdate" ) @@ -620,18 +665,18 @@ class StateInGame : BasicGameState() { } else { actorContainer.forEach { - it.update(gc, delta) + it.update(delta) if (it is Pocketed) { it.inventory.forEach { inventoryEntry -> - inventoryEntry.item.effectWhileInPocket(gc, delta) + inventoryEntry.item.effectWhileInPocket(delta) if (it.equipped(inventoryEntry.item)) { - inventoryEntry.item.effectWhenEquipped(gc, delta) + inventoryEntry.item.effectWhenEquipped(delta) } } } } - AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre) + //AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre) } } @@ -646,26 +691,26 @@ class StateInGame : BasicGameState() { min(// take min of normal position and wrapped (x < 0) position (a.hitbox.centeredX - p.hitbox.centeredX).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr(), - (a.hitbox.centeredX - p.hitbox.centeredX + world.width * TILE_SIZE).sqr() + + (a.hitbox.centeredX - p.hitbox.centeredX + world.width * FeaturesDrawer.TILE_SIZE).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr(), - (a.hitbox.centeredX - p.hitbox.centeredX - world.width * TILE_SIZE).sqr() + + (a.hitbox.centeredX - p.hitbox.centeredX - world.width * FeaturesDrawer.TILE_SIZE).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr() ) private fun distToCameraSqr(a: ActorWithBody) = min( (a.hitbox.startX - WorldCamera.x).sqr() + (a.hitbox.startY - WorldCamera.y).sqr(), - (a.hitbox.startX - WorldCamera.x + world.width * TILE_SIZE).sqr() + + (a.hitbox.startX - WorldCamera.x + world.width * FeaturesDrawer.TILE_SIZE).sqr() + (a.hitbox.startY - WorldCamera.y).sqr(), - (a.hitbox.startX - WorldCamera.x - world.width * TILE_SIZE).sqr() + + (a.hitbox.startX - WorldCamera.x - world.width * FeaturesDrawer.TILE_SIZE).sqr() + (a.hitbox.startY - WorldCamera.y).sqr() ) /** whether the actor is within screen */ private fun ActorWithBody.inScreen() = distToCameraSqr(this) <= - (Terrarum.WIDTH.plus(this.hitbox.width.div(2)).times(1 / Terrarum.ingame!!.screenZoom).sqr() + - Terrarum.HEIGHT.plus(this.hitbox.height.div(2)).times(1 / Terrarum.ingame!!.screenZoom).sqr()) + (Gdx.graphics.width.plus(this.hitbox.width.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr() + + Gdx.graphics.height.plus(this.hitbox.height.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr()) /** whether the actor is within update range */ @@ -879,4 +924,29 @@ class StateInGame : BasicGameState() { lock.unlock() } } + + override fun pause() { + // TODO no pause when off-focus on desktop + } + + override fun resume() { + } + + override fun hide() { + } + + override fun resize(width: Int, height: Int) { + worldDrawFrameBuffer.dispose() + worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false) + backDrawFrameBuffer.dispose() + backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false) + + // Set up viewport when window is resized + initViewPort(width, height, width.toFloat() / height.toFloat()) + } + + override fun dispose() { + worldDrawFrameBuffer.dispose() + backDrawFrameBuffer.dispose() + } } diff --git a/src/net/torvald/terrarum/StateMidiInputTest.kt b/src/net/torvald/terrarum/StateMidiInputTest.kt deleted file mode 100644 index 7bc45ecbc..000000000 --- a/src/net/torvald/terrarum/StateMidiInputTest.kt +++ /dev/null @@ -1,323 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.terrarum.Terrarum.STATE_ID_TEST_INPUT -import net.torvald.terrarum.gameactors.roundInt -import net.torvald.terrarum.gameworld.toUint -import net.torvald.terrarum.virtualcomputer.terminal.ALException -import org.lwjgl.BufferUtils -import org.lwjgl.openal.AL -import org.lwjgl.openal.AL10 -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.nio.ByteBuffer -import java.util.ArrayList -import javax.sound.midi.* -import kotlin.experimental.and - -/** - * Midi input test for Spieluhr (this game's version of Note Block) - * - * Spieluhrs can make sound ranged from C1 to C6 - * (61 keys, which is the most common Midi Keyboard configuration) - * - * There is some latency if you are on Windows. Mac and Linux should be okay - * because real musicians use Mac anyway, for a reason. - * - * Created by SKYHi14 on 2017-03-17. - */ -class StateMidiInputTest : BasicGameState() { - - var midiKeyboard: MidiDevice? = null - val beeperSlave = BeeperSlave() - - val preferredDeviceList = arrayOf( - "USB MIDI" - ) - val avoidedDeviceList = arrayOf( - "Real Time Sequencer" - ) - - init { - val midiDevInfo = MidiSystem.getMidiDeviceInfo() - - midiDevInfo.forEach { - //println(it) - - val device = MidiSystem.getMidiDevice(it) - try { - if (!avoidedDeviceList.contains(device.deviceInfo.name)) { - device.transmitter // test if tranmitter available - //println("Transmitter: $it") - - midiKeyboard = device - } - } - catch (e: MidiUnavailableException) { - //println("(no transmitter found)") - } - - //println() - } - - //midiKeyboard = MidiSystem.getMidiDevice() - } - - override fun init(container: GameContainer?, game: StateBasedGame?) { - if (midiKeyboard != null) { - midiKeyboard!!.open() - midiKeyboard!!.transmitter.receiver = MidiInputReceiver(beeperSlave) - println("Opened Midi device ${midiKeyboard!!.deviceInfo.name}") - } - else { - println("Midi keyboard not found, using computer keyboard as a controller.") - } - } - - override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { - beeperSlave.runBeepQueueManager(delta) - } - - override fun getID() = STATE_ID_TEST_INPUT - - override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { - g.font = Terrarum.fontGame - g.drawString("Listening from ${midiKeyboard!!.deviceInfo.name}", 10f, 10f) - } - - - class MidiInputReceiver(val slave: BeeperSlave) : Receiver { - override fun send(message: MidiMessage, timeStamp: Long) { - //println("MIDI Event ${message}") - val parsedEvent = ParseMidiMessage(message) - println(parsedEvent ?: "Don't care") - if (parsedEvent != null) { - if (!parsedEvent.isNoteOff) { - slave.enqueueBeep(100, parsedEvent.frequency()) - } - } - } - - override fun close() { - } - } - -} - - -class BeeperSlave { - - /////////////////// - // BEEPER DRIVER // - /////////////////// - - private val beepMaxLen = 10000 - // let's regard it as a tracker... - private val beepQueue = ArrayList>() - private var beepCursor = -1 - private var beepQueueLineExecTimer: Millisec = 0 - private var beepQueueFired = false - - fun update(delta: Int) { - runBeepQueueManager(delta) - } - - fun runBeepQueueManager(delta: Int) { - // start emitTone queue - if (beepQueue.size > 0 && beepCursor == -1) { - beepCursor = 0 - } - - // advance emitTone queue - if (beepCursor >= 0 && beepQueueLineExecTimer >= beepQueueGetLenOfPtn(beepCursor)) { - beepQueueLineExecTimer -= beepQueueGetLenOfPtn(beepCursor) - beepCursor += 1 - beepQueueFired = false - } - - // complete emitTone queue - if (beepCursor >= beepQueue.size) { - clearBeepQueue() - } - - // actually play queue - if (beepCursor >= 0 && beepQueue.size > 0 && !beepQueueFired) { - playTone(beepQueue[beepCursor].first, beepQueue[beepCursor].second) - beepQueueFired = true - - // delete sources that is finished. AL is limited to 256 sources. If you exceed it, - // we won't get any more sounds played. - AL10.alSourcei(oldBeepSource, AL10.AL_BUFFER, 0) - AL10.alDeleteSources(oldBeepSource) - AL10.alDeleteBuffers(oldBeepBuffer) - } - - if (beepQueueFired) beepQueueLineExecTimer += delta - } - - fun clearBeepQueue() { - beepQueue.clear() - beepCursor = -1 - beepQueueLineExecTimer = 0 - - //AL.destroy() - - } - - fun enqueueBeep(duration: Int, freq: Double) { - beepQueue.add(Pair(Math.min(duration, beepMaxLen), freq)) - } - - fun beepQueueGetLenOfPtn(ptnIndex: Int) = beepQueue[ptnIndex].first - - - //////////////////// - // TONE GENERATOR // - //////////////////// - - private val sampleRate = 44100 - private var beepSource: Int = -1 - private var beepBuffer: Int = -1 - private var oldBeepSource: Int = -1 - private var oldBeepBuffer: Int = -1 - var audioData: ByteBuffer? = null - - /** - * @param duration : milliseconds - * @param rampUp - * @param rampDown - * - * ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false) - */ - private fun makeAudioData(duration: Millisec, freq: Double, - rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer { - val audioData = BufferUtils.createByteBuffer(duration.times(sampleRate).div(1000)) - - val realDuration = duration * sampleRate / 1000 - val chopSize = freq / sampleRate - - val amp = Math.max(4600.0 / freq, 1.0) - val nHarmonics = if (freq >= 22050.0) 1 - else if (freq >= 11025.0) 2 - else if (freq >= 5512.5) 3 - else if (freq >= 2756.25) 4 - else if (freq >= 1378.125) 5 - else if (freq >= 689.0625) 6 - else 7 - - val transitionThre = 974.47218 - - // TODO volume ramping? - if (freq == 0.0) { - for (x in 0..realDuration - 1) { - audioData.put(0x00.toByte()) - } - } - else if (freq < transitionThre) { // chopper generator (for low freq) - for (x in 0..realDuration - 1) { - var sine: Double = amp * Math.cos(Math.PI * 2 * x * chopSize) - if (sine > 0.79) sine = 0.79 - else if (sine < -0.79) sine = -0.79 - audioData.put( - (0.5 + 0.5 * sine).times(0xFF).roundInt().toByte() - ) - } - } - else { // harmonics generator (for high freq) - for (x in 0..realDuration - 1) { - var sine: Double = 0.0 - for (k in 1..nHarmonics) { // mix only odd harmonics in order to make a squarewave - sine += Math.sin(Math.PI * 2 * (2*k - 1) * chopSize * x) / (2*k - 1) - } - audioData.put( - (0.5 + 0.5 * sine).times(0xFF).roundInt().toByte() - ) - } - } - - audioData.rewind() - - return audioData - } - - fun playTone(leninmilli: Int, freq: Double) { - /*audioData = makeAudioData(leninmilli, freq) - - - if (!AL.isCreated()) AL.create() - - - // Clear error stack. - AL10.alGetError() - - oldBeepBuffer = beepBuffer - beepBuffer = AL10.alGenBuffers() - checkALError() - - try { - AL10.alBufferData(beepBuffer, AL10.AL_FORMAT_MONO8, audioData, sampleRate) - checkALError() - - oldBeepSource = beepSource - beepSource = AL10.alGenSources() - checkALError() - - try { - AL10.alSourceQueueBuffers(beepSource, beepBuffer) - checkALError() - - AL10.alSource3f(beepSource, AL10.AL_POSITION, 0f, 0f, 1f) - AL10.alSourcef(beepSource, AL10.AL_REFERENCE_DISTANCE, 1f) - AL10.alSourcef(beepSource, AL10.AL_MAX_DISTANCE, 1f) - AL10.alSourcef(beepSource, AL10.AL_GAIN, 0.3f) - checkALError() - - AL10.alSourcePlay(beepSource) - checkALError() - } - catch (e: ALException) { - AL10.alDeleteSources(beepSource) - } - } - catch (e: ALException) { - AL10.alDeleteSources(beepSource) - }*/ - } - - // Custom implementation of Util.checkALError() that uses our custom exception. - private fun checkALError() { - val errorCode = AL10.alGetError() - if (errorCode != AL10.AL_NO_ERROR) { - throw ALException(errorCode) - } - } -} - -object ParseMidiMessage { - operator fun invoke(message: MidiMessage): MidiKeyEvent? { - val bytes = message.message - val header = bytes[0].toUint().ushr(4) // 0b0000 - 0b1111 - if (header == 0b1000) { // note off - return MidiKeyEvent(true, bytes[1].toInt(), bytes[2].toInt()) // no need for uint() - } - else if (header == 0b1001) { // note on - return MidiKeyEvent(false, bytes[1].toInt(), bytes[2].toInt()) // no need for uint() - } - else { // don't care - return null - } - } - - data class MidiKeyEvent(val isNoteOff: Boolean, val key: Int, val velocity: Int) { - override fun toString() = "${if (isNoteOff) "Off" else "On "} $key v$velocity" - /** - * @param tuning frequency of middle A (default: 440.0) - */ - fun frequency(tuning: Double = 440.0): Double { - val a3 = 69 // midi note number for middle A - - return tuning * Math.pow(2.0, (key - a3) / 12.0) - } - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateMonitorCheck.kt b/src/net/torvald/terrarum/StateMonitorCheck.kt deleted file mode 100644 index b94f36400..000000000 --- a/src/net/torvald/terrarum/StateMonitorCheck.kt +++ /dev/null @@ -1,171 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.ui.* -import org.newdawn.slick.* -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.util.* - -/** - * Created by minjaesong on 16-07-06. - */ -class StateMonitorCheck : BasicGameState() { - private lateinit var uiMonitorCheck: UIHandler - - override fun init(gc: GameContainer, g: StateBasedGame) { - uiMonitorCheck = UIHandler(MonitorCheckUI()) - uiMonitorCheck.isVisible = true - } - - override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { - uiMonitorCheck.update(gc, delta) - } - - override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) { - uiMonitorCheck.render(gc, sbg, g) - } - - override fun keyPressed(key: Int, c: Char) { - //uiMonitorCheck.setAsClose() - } - - override fun getID(): Int = Terrarum.STATE_ID_CONFIG_CALIBRATE - - class MonitorCheckUI : UICanvas { - override var width = Terrarum.WIDTH - override var height = Terrarum.HEIGHT - override var openCloseTime = 150 - - override var handler: UIHandler? = null - - private val backgroundCol = Color(0x404040) - - private val colourLUT = IntArray(32, { 255.times(it + 1).div(32) }) - - val pictograms = ArrayList() - val imageGallery: UIItemImageGallery - - val instructionY = Terrarum.HEIGHT / 2//Terrarum.HEIGHT * 9 / 16 - val anykeyY = Terrarum.HEIGHT * 15 / 16 - - val maru_alt = Regex("CN|JP|K[RP]|TW") - - init { - if (Terrarum.gameLocale.length >= 4 && Terrarum.gameLocale.contains(maru_alt)) - pictograms.add(Image("./assets/graphics/gui/monitor_good_alt_maru.tga")) - else - pictograms.add(Image("./assets/graphics/gui/monitor_good.tga")) - pictograms.add(Image("./assets/graphics/gui/monitor_bad.tga")) - - imageGallery = UIItemImageGallery( - this, 0, instructionY, Terrarum.WIDTH, anykeyY - instructionY, pictograms - ) - } - - override fun update(gc: GameContainer, delta: Int) { - } - - override fun render(gc: GameContainer, g: Graphics) { - val titleY = Terrarum.HEIGHT * 7 / 16 - - val barWidthAll = Terrarum.WIDTH.div(100).times(100) * 9 / 10 - val barWidth: Int = barWidthAll / 32 + 1 - val barHeight = 90 - - val yCentre = Terrarum.HEIGHT.shr(1) - - val barNumberGap = 5 - - g.background = Color.black - // draw bars - for (i in 0..31) { - val labelW = g.font.getWidth(i.plus(1).toString()) - val labelH = g.font.lineHeight - val barXstart = center(Terrarum.WIDTH, barWidthAll) + i.times(barWidth) - val barYstart = center(yCentre, barHeight) - - // bar start point indicator - if (i == 0) { - g.color = backgroundCol - g.drawLine( - barXstart.toFloat(), barYstart - barNumberGap - labelH.toFloat(), - barXstart.toFloat(), barYstart - barNumberGap.toFloat() - ) - } - - // bar numbers - if (i.plus(1) and 0x1 == 0 || i.plus(1) == 1) { - g.color = Color.white - g.drawString( - i.plus(1).toString(), - barXstart + center(barWidth, labelW).toFloat(), - barYstart - barNumberGap - labelH.toFloat() - ) - } - - // actual bar - g.color = Color(colourLUT[i], colourLUT[i], colourLUT[i]) - g.fillRect( - barXstart.toFloat(), - barYstart.toFloat(), - barWidth.toFloat(), - barHeight.toFloat() - ) - } - - // messages background - g.color = backgroundCol - g.fillRect( - 0f, Terrarum.HEIGHT.shr(1).toFloat(), - Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.shr(1).plus(1).toFloat() - ) - - // labels - g.color = Color.white - Typography.printCentered( - g, Lang["MENU_MONITOR_CALI_TITLE"], - titleY, - this - ) - - // message text - /*(1..12).forEach { - Typography.printCentered( - g, Lang["MENU_MONITOR_CALI_LABEL_$it"], - instructionY + it.minus(2).times(g.font.lineHeight), - this - ) - }*/ - - // message pictogram - imageGallery.render(gc, g) - - - // anykey - Typography.printCentered( - g, Lang["MENU_LABEL_PRESS_ANYKEY"], - anykeyY, - this - ) - - } - - override fun processInput(gc: GameContainer, delta: Int, input: Input) { - } - - override fun doOpening(gc: GameContainer, delta: Int) { - } - - override fun doClosing(gc: GameContainer, delta: Int) { - } - - override fun endOpening(gc: GameContainer, delta: Int) { - } - - override fun endClosing(gc: GameContainer, delta: Int) { - } - - private fun center(x1: Int, x2: Int) = x1.minus(x2).div(2) - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateNewRunesTest.kt b/src/net/torvald/terrarum/StateNewRunesTest.kt deleted file mode 100644 index 8a2b0ece8..000000000 --- a/src/net/torvald/terrarum/StateNewRunesTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.imagefont.NewRunes -import org.newdawn.slick.* -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame - -/** - * Created by SKYHi14 on 2017-03-24. - */ - -class StateNewRunesTest : BasicGameState() { - - lateinit var runes: NewRunes - - override fun init(gc: GameContainer, game: StateBasedGame) { - runes = NewRunes() - runes.scale = 2 - } - - override fun update(gc: GameContainer, game: StateBasedGame, delta: Int) { - - } - - override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) { - - g.background = Color(0x282828) - g.font = runes - g.color = Color(0x00c0f3) - - val text = arrayOf( - "ㅎㅏㅣㄹㅏㄹㅍㅏㄴㅌㅏㅈㅣ", - "ㅈㅔㄹㄷㅏㅢㅈㅓㄴㅅㅓㄹ.", // <> - ".22884646ㄴㄱ." - ) - - text.forEachIndexed { index, s -> - g.drawString(s, 30f, 30f + (runes.lineHeight * index)) - } - } - - override fun getID(): Int = Terrarum.STATE_ID_TEST_FONT -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateNoiseTester.kt b/src/net/torvald/terrarum/StateNoiseTester.kt deleted file mode 100644 index e4d8a08d1..000000000 --- a/src/net/torvald/terrarum/StateNoiseTester.kt +++ /dev/null @@ -1,284 +0,0 @@ -package net.torvald.terrarum - -import com.sudoplay.joise.Joise -import com.sudoplay.joise.module.* -import net.torvald.random.HQRNG -import net.torvald.terrarum.concurrent.ThreadParallel -import net.torvald.terrarum.gameactors.roundInt -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.ImageBuffer -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.util.* - -/** - * WARNING! HAS SERIOUS MEMORY LEAK - * - * Created by SKYHi14 on 2017-01-30. - */ -class StateNoiseTester : BasicGameState() { - - companion object { - val imagesize = 512 - val sampleDensity = 1.0 - val noiseImageBuffer = ImageBuffer(imagesize, imagesize) - var generating = false - } - override fun init(p0: GameContainer?, p1: StateBasedGame?) { - generateNoiseImage() - } - - private fun noise(seed: Long): Joise { - /* Init */ - - val joiseSeed = seed - val lowlandMagic: Long = 0x44A21A114DBE56 // maria lindberg - val highlandMagic: Long = 0x0114E091 // olive oyl - val mountainMagic: Long = 0x115AA4DE2504 // lisa anderson - val selectionMagic: Long = 0x44E10D9B100 // melody blue - - val ground_gradient = ModuleGradient() - ground_gradient.setGradient(0.0, 0.0, 0.0, 1.0) - - /* Lowlands */ - - val lowland_shape_fractal = ModuleFractal() - lowland_shape_fractal.setType(ModuleFractal.FractalType.FBM) - lowland_shape_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) - lowland_shape_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - lowland_shape_fractal.setNumOctaves(2) - lowland_shape_fractal.setFrequency(1.0) - lowland_shape_fractal.seed = joiseSeed xor lowlandMagic - - val lowland_autocorrect = ModuleAutoCorrect() - lowland_autocorrect.setSource(lowland_shape_fractal) - lowland_autocorrect.setLow(0.0) - lowland_autocorrect.setHigh(1.0) - - val lowland_scale = ModuleScaleOffset() - lowland_scale.setSource(lowland_autocorrect) - lowland_scale.setScale(0.2) - lowland_scale.setOffset(-0.25) - - val lowland_y_scale = ModuleScaleDomain() - lowland_y_scale.setSource(lowland_scale) - lowland_y_scale.setScaleY(0.0) - - val lowland_terrain = ModuleTranslateDomain() - lowland_terrain.setSource(ground_gradient) - lowland_terrain.setAxisYSource(lowland_y_scale) - - - /* highlands */ - - val highland_shape_fractal = ModuleFractal() - highland_shape_fractal.setType(ModuleFractal.FractalType.RIDGEMULTI) - highland_shape_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) - highland_shape_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - highland_shape_fractal.setNumOctaves(2) - highland_shape_fractal.setFrequency(2.0) - highland_shape_fractal.seed = joiseSeed xor highlandMagic - - val highland_autocorrect = ModuleAutoCorrect() - highland_autocorrect.setSource(highland_shape_fractal) - highland_autocorrect.setLow(0.0) - highland_autocorrect.setHigh(1.0) - - val highland_scale = ModuleScaleOffset() - highland_scale.setSource(highland_autocorrect) - highland_scale.setScale(0.45) - highland_scale.setOffset(0.0) - - val highland_y_scale = ModuleScaleDomain() - highland_y_scale.setSource(highland_scale) - highland_y_scale.setScaleY(0.0) - - val highland_terrain = ModuleTranslateDomain() - highland_terrain.setSource(ground_gradient) - highland_terrain.setAxisYSource(highland_y_scale) - - - /* mountains */ - - val mountain_shape_fractal = ModuleFractal() - mountain_shape_fractal.setType(ModuleFractal.FractalType.BILLOW) - mountain_shape_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) - mountain_shape_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - mountain_shape_fractal.setNumOctaves(4) - mountain_shape_fractal.setFrequency(1.0) - mountain_shape_fractal.seed = joiseSeed xor mountainMagic - - val mountain_autocorrect = ModuleAutoCorrect() - mountain_autocorrect.setSource(mountain_shape_fractal) - mountain_autocorrect.setLow(0.0) - mountain_autocorrect.setHigh(1.0) - - val mountain_scale = ModuleScaleOffset() - mountain_scale.setSource(mountain_autocorrect) - mountain_scale.setScale(0.75) - mountain_scale.setOffset(0.25) - - val mountain_y_scale = ModuleScaleDomain() - mountain_y_scale.setSource(mountain_scale) - mountain_y_scale.setScaleY(0.1) // controls "quirkiness" of the mountain - - val mountain_terrain = ModuleTranslateDomain() - mountain_terrain.setSource(ground_gradient) - mountain_terrain.setAxisYSource(mountain_y_scale) - - - /* selection */ - - val terrain_type_fractal = ModuleFractal() - terrain_type_fractal.setType(ModuleFractal.FractalType.FBM) - terrain_type_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) - terrain_type_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - terrain_type_fractal.setNumOctaves(3) - terrain_type_fractal.setFrequency(0.5) - terrain_type_fractal.seed = joiseSeed xor selectionMagic - - val terrain_autocorrect = ModuleAutoCorrect() - terrain_autocorrect.setSource(terrain_type_fractal) - terrain_autocorrect.setLow(0.0) - terrain_autocorrect.setHigh(1.0) - - val terrain_type_cache = ModuleCache() - terrain_type_cache.setSource(terrain_autocorrect) - - val highland_mountain_select = ModuleSelect() - highland_mountain_select.setLowSource(highland_terrain) - highland_mountain_select.setHighSource(mountain_terrain) - highland_mountain_select.setControlSource(terrain_type_cache) - highland_mountain_select.setThreshold(0.55) - highland_mountain_select.setFalloff(0.15) - - val highland_lowland_select = ModuleSelect() - highland_lowland_select.setLowSource(lowland_terrain) - highland_lowland_select.setHighSource(highland_mountain_select) - highland_lowland_select.setControlSource(terrain_type_cache) - highland_lowland_select.setThreshold(0.25) - highland_lowland_select.setFalloff(0.15) - - val ground_select = ModuleSelect() - ground_select.setLowSource(0.0) - ground_select.setHighSource(1.0) - ground_select.setThreshold(0.5) - ground_select.setControlSource(highland_lowland_select) - - - val joise = Joise(ground_select) - return joise - } - - fun generateNoiseImage() { - val noiseModule = noise(HQRNG().nextLong()) // change noise function here - - for (y in 0..imagesize - 1) { - for (x in 0..imagesize - 1) { - noiseImageBuffer.setRGBA(x, y, 0, 0, 0, 255) - } - } - - for (i in 0..Terrarum.THREADS - 1) { - ThreadParallel.map( - i, - ThreadRunNoiseSampling( - imagesize.toFloat().div(Terrarum.THREADS).times(i).roundInt(), - imagesize.toFloat().div(Terrarum.THREADS).times(i.plus(1)).roundInt() - 1, - noiseModule - ), - "SampleJoiseMap" - ) - } - - ThreadParallel.startAll() - } - - override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { - Terrarum.appgc.setTitle( - Terrarum.NAME + - " — F: ${Terrarum.appgc.fps} (${Terrarum.TARGET_INTERNAL_FPS})" + - " — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M" - ) - - - if (ThreadParallel.allFinished()) generating = false - } - - override fun getID() = Terrarum.STATE_ID_TOOL_NOISEGEN - - override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) { - g.color = Color.red - g.drawString("Press SPACE to generate new noise", 8f, 8f) - g.drawString("CPUs: ${Terrarum.THREADS}", Terrarum.WIDTH - 90f, 8f) - - g.background = Color.cyan - g.drawImage(noiseImageBuffer.image,//noiseImage, - Terrarum.WIDTH.minus(imagesize).div(2).toFloat(), - Terrarum.HEIGHT.minus(imagesize).div(2).toFloat() - ) - } - - override fun keyPressed(key: Int, c: Char) { - if (c == ' ' && !generating) { - println("Generating noise, may take a while") - generating = true - generateNoiseImage() - } - } - - - class ThreadRunNoiseSampling(val startIndex: Int, val endIndex: Int, val joise: Joise) : Runnable { - /*override fun run() { - for (sy in startIndex..endIndex) { - for (sx in 0..imagesize - 1) { - val y = sy.toDouble() / imagesize - val x = sx.toDouble() / imagesize - - val sampleOffset = sampleDensity - // 4-D toroidal sampling (looped H and V) - val sampleTheta1 = x * Math.PI * 2.0 - val sampleTheta2 = y * Math.PI * 2.0 - val sampleX = Math.sin(sampleTheta1) * sampleDensity + sampleDensity - val sampleY = Math.cos(sampleTheta1) * sampleDensity + sampleDensity - val sampleZ = Math.sin(sampleTheta2) * sampleDensity + sampleDensity - val sampleW = Math.cos(sampleTheta2) * sampleDensity + sampleDensity - - val noise = joise.get( - sampleX, sampleY, sampleZ, sampleW - ) // autocorrection REQUIRED! - - val noiseCol = noise.times(255f).toInt() - noiseImageBuffer.setRGBA(sx, sy, noiseCol, noiseCol, noiseCol, 255) - - } - } - }*/ - - override fun run() { - for (sy in startIndex..endIndex) { - for (sx in 0..imagesize - 1) { - val y = sy.toDouble() / imagesize * 1.5 -.6 - val x = sx.toDouble() / imagesize - - val sampleOffset = sampleDensity - // 4-D toroidal sampling (looped H and V) - val sampleTheta1 = x * Math.PI * 2.0 - val sampleX = Math.sin(sampleTheta1) * sampleDensity + sampleDensity - val sampleZ = Math.cos(sampleTheta1) * sampleDensity + sampleDensity - val sampleY = y - - val noise = joise.get( - sampleX, sampleY, sampleZ - ) // autocorrection REQUIRED! - - val noiseCol = noise.times(255f).toInt() - noiseImageBuffer.setRGBA(sx, sy, noiseCol, noiseCol, noiseCol, 255) - - } - } - } - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateNoiseTexGen.kt b/src/net/torvald/terrarum/StateNoiseTexGen.kt deleted file mode 100644 index e74d13028..000000000 --- a/src/net/torvald/terrarum/StateNoiseTexGen.kt +++ /dev/null @@ -1,203 +0,0 @@ -package net.torvald.terrarum - -import com.sudoplay.joise.Joise -import com.sudoplay.joise.module.* -import net.torvald.terrarum.Terrarum.STATE_ID_TOOL_NOISEGEN -import net.torvald.terrarum.concurrent.ThreadParallel -import net.torvald.terrarum.gameactors.roundInt -import org.newdawn.slick.* -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.util.* - -/** - * Created by minjaesong on 2016-12-21. - */ -class StateNoiseTexGen : BasicGameState() { - - companion object { - val imagesize = 512 - val sampleDensity = 1.0 - val noiseImageBuffer = ImageBuffer(imagesize, imagesize) - var generating = false - } - override fun init(p0: GameContainer?, p1: StateBasedGame?) { - generateNoiseImage() - } - - private fun noiseRidged(): Joise { - val ridged = ModuleFractal() - ridged.setType(ModuleFractal.FractalType.RIDGEMULTI) - ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - ridged.setNumOctaves(4) - ridged.setFrequency(1.0) - ridged.seed = Random().nextLong() - - val ridged_autocorrect = ModuleAutoCorrect() - ridged_autocorrect.setRange(0.0, 1.0) - ridged_autocorrect.setSource(ridged) - - return Joise(ridged_autocorrect) - } - - private fun noiseBrownian(): Joise { - val ridged = ModuleFractal() - ridged.setType(ModuleFractal.FractalType.FBM) - ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - ridged.setNumOctaves(8) - ridged.setFrequency(1.0) - ridged.seed = Random().nextLong() - - val ridged_autocorrect = ModuleAutoCorrect() - ridged_autocorrect.setRange(0.0, 1.0) - ridged_autocorrect.setSource(ridged) - - return Joise(ridged_autocorrect) - } - - private fun noiseBrownianGranite(): Joise { - val ridged = ModuleFractal() - ridged.setType(ModuleFractal.FractalType.FBM) - ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - ridged.setNumOctaves(2) - ridged.setFrequency(16.0) - ridged.seed = Random().nextLong() - - val brownian_select = ModuleSelect() - brownian_select.setControlSource(ridged) - brownian_select.setThreshold(0.8) - brownian_select.setLowSource(0.0) - brownian_select.setHighSource(1.0) - - return Joise(brownian_select) - } - - private fun noiseBillowFractal(): Joise { - val ridged = ModuleFractal() - ridged.setType(ModuleFractal.FractalType.BILLOW) - ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC) - ridged.setNumOctaves(8) - ridged.setFrequency(1.0) - ridged.seed = Random().nextLong() - - val ridged_autocorrect = ModuleAutoCorrect() - ridged_autocorrect.setRange(0.0, 1.0) - ridged_autocorrect.setSource(ridged) - - return Joise(ridged_autocorrect) - } - - private fun noiseSimplex(): Joise { - val simplex = ModuleFractal() - simplex.seed = Random().nextLong() - simplex.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.SIMPLEX) - simplex.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.LINEAR) - simplex.setNumOctaves(2) - simplex.setFrequency(1.0) - - val simplex_autocorrect = ModuleAutoCorrect() - simplex_autocorrect.setRange(0.0, 1.0) - simplex_autocorrect.setSource(simplex) - - return Joise(simplex_autocorrect) - } - - private fun noiseCellular(): Joise { - val cellgen = ModuleCellGen() - cellgen.seed = Random().nextLong() - - val cellular = ModuleCellular() - cellular.setCellularSource(cellgen) - cellular.setCoefficients(-1.0, 1.0, 0.0, 0.0) - - val cellular_autocorrect = ModuleAutoCorrect() - cellular_autocorrect.setRange(0.0, 1.0) - cellular_autocorrect.setSource(cellular) - - return Joise(cellular_autocorrect) - } - - fun generateNoiseImage() { - val noiseModule = noiseBrownianGranite() // change noise function here - - for (y in 0..imagesize - 1) { - for (x in 0..imagesize - 1) { - noiseImageBuffer.setRGBA(x, y, 0, 0, 0, 255) - } - } - - for (i in 0..Terrarum.THREADS - 1) { - ThreadParallel.map( - i, - ThreadRunNoiseSampling( - imagesize.toFloat().div(Terrarum.THREADS).times(i).roundInt(), - imagesize.toFloat().div(Terrarum.THREADS).times(i.plus(1)).roundInt() - 1, - noiseModule - ), - "SampleJoiseMap" - ) - } - - ThreadParallel.startAll() - } - - override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { - Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}") - - if (ThreadParallel.allFinished()) generating = false - } - - override fun getID() = STATE_ID_TOOL_NOISEGEN - - override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) { - g.color = Color.red - g.drawString("Press SPACE to generate new noise", 8f, 8f) - g.drawString("CPUs: ${Terrarum.THREADS}", Terrarum.WIDTH - 90f, 8f) - - g.background = Color.cyan - val img = noiseImageBuffer.image - g.drawImage(img,//noiseImage, - Terrarum.WIDTH.minus(imagesize).div(2).toFloat(), - Terrarum.HEIGHT.minus(imagesize).div(2).toFloat() - ) - - img.destroy() - } - - override fun keyPressed(key: Int, c: Char) { - if (c == ' ' && !generating) { - println("Generating noise, may take a while") - generating = true - generateNoiseImage() - } - } - - - class ThreadRunNoiseSampling(val startIndex: Int, val endIndex: Int, val joise: Joise) : Runnable { - override fun run() { - for (sy in startIndex..endIndex) { - for (sx in 0..imagesize - 1) { - val y = sy.toDouble() / imagesize - val x = sx.toDouble() / imagesize - - val sampleOffset = sampleDensity - // 4-D toroidal sampling (looped H and V) - val sampleTheta1 = x * Math.PI * 2.0 - val sampleTheta2 = y * Math.PI * 2.0 - val sampleX = Math.sin(sampleTheta1) * sampleDensity + sampleDensity - val sampleY = Math.cos(sampleTheta1) * sampleDensity + sampleDensity - val sampleZ = Math.sin(sampleTheta2) * sampleDensity + sampleDensity - val sampleW = Math.cos(sampleTheta2) * sampleDensity + sampleDensity - - val noise = joise.get( - sampleX, sampleY, sampleZ, sampleW - ) // autocorrection REQUIRED! - - val noiseCol = noise.times(255f).toInt() - noiseImageBuffer.setRGBA(sx, sy, noiseCol, noiseCol, noiseCol, 255) - - } - } - } - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateShaderTest.kt b/src/net/torvald/terrarum/StateShaderTest.kt deleted file mode 100644 index 9c2dd9922..000000000 --- a/src/net/torvald/terrarum/StateShaderTest.kt +++ /dev/null @@ -1,100 +0,0 @@ -package net.torvald.terrarum - -import org.lwjgl.opengl.* -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.Image -import org.newdawn.slick.opengl.renderer.SGL -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import shader.Shader -import org.lwjgl.opengl.GL11 -import org.lwjgl.opengl.ARBShaderObjects -import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.close -import jdk.nashorn.internal.runtime.ScriptingFunctions.readLine -import net.torvald.terrarum.Terrarum.STATE_ID_TEST_SHADER -import net.torvald.terrarum.gameworld.fmod -import org.newdawn.slick.Color -import org.newdawn.slick.opengl.TextureImpl -import java.io.InputStreamReader -import java.io.BufferedReader -import java.io.File -import java.io.FileInputStream - - - - - - - -/** - * Created by SKYHi14 on 2017-01-23. - */ -class StateShaderTest : BasicGameState() { - override fun getID() = STATE_ID_TEST_SHADER - - - - override fun init(container: GameContainer?, game: StateBasedGame?) { - } - - private lateinit var shaderTest: Shader - private lateinit var testImage: Image - - override fun enter(container: GameContainer?, game: StateBasedGame?) { - shaderTest = Shader.makeShader("./assets/test.vert", "./assets/test.frag") - - testImage = Image("./assets/test_texture.tga") - //testImage = Image("./logo_repository.png") - } - - override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { - Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}") - } - - override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { - val x = 10f - val y = 10f - val width = testImage.width - val height = testImage.height - val textureWidth = testImage.textureWidth - val textureHeight = testImage.textureHeight - val textureOffsetX = testImage.textureOffsetX - val textureOffsetY = testImage.textureOffsetY - - - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT) - // bind texture - // glBegin(SGL.GL_QUADS) - // do shader - // glEnd() - - - - //testImage.bind() - - GL11.glBegin(GL11.GL_QUADS) - - //GL20.glUseProgram(0) - shaderTest.startShader() - //GL13.glActiveTexture(testImage.texture.textureID) - //GL11.glBindTexture(GL13.GL_TEXTURE0, testImage.texture.textureID) - //testImage.bind() - shaderTest.setUniformIntVariable("u_texture", 0) - - /*GL11.glTexCoord2f(textureOffsetX, textureOffsetY) - GL11.glVertex3f(x, y, 0f) - GL11.glTexCoord2f(textureOffsetX, textureOffsetY + textureHeight) - GL11.glVertex3f(x, y + height, 0f) - GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY + textureHeight) - GL11.glVertex3f(x + width, y + height, 0f) - GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY) - GL11.glVertex3f(x + width, y, 0f)*/ - - g!!.color = Color.orange - g!!.fillRect(10f, 10f, 512f, 512f) - - GL20.glUseProgram(0) - GL11.glEnd() - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateSplash.kt b/src/net/torvald/terrarum/StateSplash.kt deleted file mode 100644 index 429b1f8b6..000000000 --- a/src/net/torvald/terrarum/StateSplash.kt +++ /dev/null @@ -1,138 +0,0 @@ -package net.torvald.terrarum - -import com.jme3.math.FastMath -import net.torvald.terrarum.gameactors.roundInt -import net.torvald.terrarum.gamecontroller.Key -import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.ui.DrawUtil -import net.torvald.terrarum.ui.NullUI -import net.torvald.terrarum.ui.UIItemImageGallery -import net.torvald.terrarum.ui.Typography -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.Image -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.util.* - -/** - * Created by minjaesong on 16-08-04. - */ -class StateSplash : BasicGameState() { - - val pictogramCollection = ArrayList() - - val virtualImageHeight = 100 - var imageBoardHeight = 0 - var imageBoardOffset = 0 - - lateinit var fadeSheet: Image - lateinit var thisG: Graphics - - var opacity = 0f - - val fadeTime = 500 - var fadeTimer = -1 - - var anykey_hit = false - - val backgroundColour = Color(0x303030) - - val deltathre = 500 - - val auto_dismiss = 6500 - - var opened = false - - var init = false - - lateinit var imageGallery: UIItemImageGallery - - override fun init(container: GameContainer?, game: StateBasedGame?) { - // pre-load lang - Lang["MENU_LANGUAGE_THIS"] - - pictogramCollection.add(Image("./assets/graphics/gui/health_take_a_break.tga")) - pictogramCollection.add(Image("./assets/graphics/gui/health_distance.tga")) - - fadeSheet = Image(Terrarum.WIDTH, Terrarum.HEIGHT) - thisG = fadeSheet.graphics - thisG.font = Terrarum.fontGame - - imageBoardHeight = Terrarum.HEIGHT - thisG.font.lineHeight.times(6) - imageBoardOffset = thisG.font.lineHeight.times(3) - - imageGallery = UIItemImageGallery( - NullUI(), 0, imageBoardOffset, Terrarum.WIDTH, imageBoardHeight, pictogramCollection - ) - } - - override fun update(container: GameContainer, game: StateBasedGame, delta: Int) { - // next splash or load next scene - if (anykey_hit && opacity < 0.0001f) { - game.enterState(Terrarum.STATE_ID_GAME) - } - - // fade-in - if (delta < deltathre) { - init = true - fadeTimer += delta - - if (opacity < 1f && !anykey_hit) { - opacity = FastMath.interpolateLinear( - fadeTimer.toFloat() / fadeTime, 0f, 1f - ) - } - else if (opacity > 0f && anykey_hit) { - opacity = FastMath.interpolateLinear( - fadeTimer.toFloat() / fadeTime, 1f, 0f - ) - } - - if (!opened && fadeTimer >= fadeTime && !anykey_hit) { - fadeTimer = 0 - opened = true - } - } - - // auto dismiss - if (opened && fadeTimer >= auto_dismiss) { - doAnykeyThingy() - } - } - - override fun getID(): Int = Terrarum.STATE_ID_SPLASH - - override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { - thisG.color = backgroundColour - thisG.fillRect(0f, 0f, fadeSheet.width.toFloat(), fadeSheet.height.toFloat()) - - thisG.color = Color.white - - Typography.printCentered(thisG, Lang["APP_WARNING_HEALTH_AND_SAFETY"], - thisG.font.lineHeight * 2) - - Typography.printCentered(thisG, Lang["MENU_LABEL_PRESS_ANYKEY"], - Terrarum.HEIGHT - thisG.font.lineHeight.times(3)) - - imageGallery.render(container, thisG) - - g.drawImage(fadeSheet, 0f, 0f, Color(1f, 1f, 1f, opacity)) - } - - override fun keyPressed(key: Int, c: Char) { - doAnykeyThingy() - } - - override fun controllerButtonPressed(controller: Int, button: Int) { - doAnykeyThingy() - } - - private fun doAnykeyThingy() { - if (!anykey_hit) { - anykey_hit = true - fadeTimer = 0 - } - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateStutterTest.kt b/src/net/torvald/terrarum/StateStutterTest.kt deleted file mode 100644 index 2f962367c..000000000 --- a/src/net/torvald/terrarum/StateStutterTest.kt +++ /dev/null @@ -1,65 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.terrarum.gamecontroller.Key -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.Image -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame - -/** - * Created by SKYHi14 on 2017-04-22. - */ -class StateStutterTest : BasicGameState() { - - private val testImage = Image(4096, 1728) - private val testImageG = testImage.graphics - - override fun init(container: GameContainer?, game: StateBasedGame?) { - } - - override fun update(container: GameContainer, game: StateBasedGame, delta: Int) { - Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}") - - - if (container.input.isKeyDown(Key.UP)) - dy -= moveDelta - if (container.input.isKeyDown(Key.DOWN)) - dy += moveDelta - if (container.input.isKeyDown(Key.LEFT)) - dx -= moveDelta - if (container.input.isKeyDown(Key.RIGHT)) - dx += moveDelta - } - - override fun getID() = Terrarum.STATE_ID_TEST_REFRESHRATE - - private var imageMade = false - - private var moveDelta = 3 - private var dx = 0 - private var dy = 0 - - override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { - if (!imageMade) { - testImageG.font = Terrarum.fontGame - testImageG.color = Color.white - - (0x3400..0x9FFF).forEach { - testImageG.drawString( - "${it.toChar()}", - (it - 0x3400) % 256 * 16f, - (it - 0x3400) / 256 * 16f - ) - } - - testImageG.flush() - - imageMade = true - } - - g.translate(-dx.toFloat(), -dy.toFloat()) - g.drawImage(testImage, 0f, 0f) - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateTestingLightning.kt b/src/net/torvald/terrarum/StateTestingLightning.kt deleted file mode 100644 index f4356a667..000000000 --- a/src/net/torvald/terrarum/StateTestingLightning.kt +++ /dev/null @@ -1,137 +0,0 @@ -package net.torvald.terrarum - - -import com.jme3.math.FastMath -import net.torvald.colourutil.ColourTemp -import net.torvald.point.Point2d -import net.torvald.random.HQRNG -import net.torvald.random.TileableValueNoise -import net.torvald.terrarum.gameactors.floorInt -import net.torvald.terrarum.gameactors.roundInt -import net.torvald.terrarum.virtualcomputer.terminal.ALException -import org.apache.commons.csv.CSVRecord -import org.lwjgl.BufferUtils -import org.lwjgl.openal.AL -import org.lwjgl.openal.AL10 -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame -import java.io.ByteArrayInputStream -import java.nio.ByteBuffer -import java.util.* -import javax.sound.sampled.AudioFormat -import javax.sound.sampled.AudioInputStream -import javax.sound.sampled.AudioSystem - -/** - * Created by minjaesong on 16-09-05. - */ -class StateTestingLightning : BasicGameState() { - - val lightning_start = Point2d(50.0, 100.0) - val lightning_end = Point2d(750.0, 300.0) - - val bolt = LightingBolt(lightning_start, lightning_end, 50) - - - override fun init(container: GameContainer?, game: StateBasedGame?) { - reseed(genOnly = true) - } - - override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { - /*timer += delta - if (timer > regenTime) { - timer -= regenTime - reseed() - }*/ - } - - override fun getID() = Terrarum.STATE_ID_TEST_GFX - - - private var timer = 0 - private var regenTime = 17 - - private var seed = System.nanoTime() - - val samples = 128 - - val lightningXgen = TileableValueNoise(8, 0.67f, samples, 8) - val lightningYgen = TileableValueNoise(8, 0.58f, samples, 4) - - override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { - g.color = ColourTemp(7500) - g.lineWidth = 3f - - //g.drawLine(lightning_start, lightning_end) - //bolt.draw(g) - - // TODO rotational transformmation for the points - // (newX, newY) = (x cos(theta) - y sin(theta), x sin(theta) + y cos(theta)) - - - val ampY = 40f - val ampX = 6 - val xoff = 10f - val yoff = 300f - - for (x in 0..lightningYgen.width - 1) { - val pXstart = (x + lightningXgen[x ]) * ampX + xoff - val pXend = (x + 1 + lightningXgen[x + 1]) * ampX + xoff - val pYstart = lightningYgen[x ] * ampY + yoff - val pYend = lightningYgen[x + 1] * ampY + yoff - - g.drawLine(pXstart, pYstart, pXend, pYend) - } - - g.color = Color.red - g.lineWidth = 1f - - g.drawLine(xoff, yoff, xoff + lightningYgen.width * ampX, yoff) - - } - - override fun keyPressed(key: Int, c: Char) { - if (c == ' ') reseed() - } - - private fun reseed(genOnly: Boolean = false) { - if (!genOnly) seed = System.nanoTime() - lightningXgen.generate(0x51621DL xor seed) - lightningYgen.generate(seed) - } -} - -class LightingBolt(val start: Point2d, val end: Point2d, val segments: Int) { - val mainBolt = LinkedList() //Pair - - val boltYDev = 20.0 - - init { - val length = start.length(end) - - for (i in 0..segments - 1) { - mainBolt.add( - Point2d( - start.x + length / segments * i, - start.y + HQRNG().nextFloat().times(2.0).minus(1.0).times(boltYDev) - ) - ) - } - } - - fun draw(g: Graphics) { - for (i in 0..segments - 1) { - val startpoint = mainBolt[i] - val endpoint = if (i == segments - 1) end else mainBolt[i + 1] - - g.drawLine(startpoint, endpoint) - } - } - - fun Graphics.drawLine(p1: Point2d, p2: Point2d) { - drawLine(p1.x.toFloat(), p1.y.toFloat(), p2.x.toFloat(), p2.y.toFloat()) - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateUITest.kt b/src/net/torvald/terrarum/StateUITest.kt deleted file mode 100644 index 6be124572..000000000 --- a/src/net/torvald/terrarum/StateUITest.kt +++ /dev/null @@ -1,109 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.terrarum.gameactors.* -import net.torvald.terrarum.itemproperties.IVKey -import net.torvald.terrarum.itemproperties.GameItem -import net.torvald.terrarum.itemproperties.ItemCodex -import net.torvald.terrarum.itemproperties.Material -import net.torvald.terrarum.blockproperties.Block -import net.torvald.terrarum.ui.* -import org.newdawn.slick.* -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame - -/** - * Created by SKYHi14 on 2017-03-13. - */ -class StateUITest : BasicGameState() { - - val ui: UIHandler - - private val actor = object : Actor(RenderOrder.FRONT), Pocketed { - override fun update(gc: GameContainer, delta: Int) { - TODO("not implemented") - } - - override fun run() { - TODO("not implemented") - } - - override fun onActorValueChange(key: String, value: Any?) { - } - - override var inventory: ActorInventory = ActorInventory(this, 100, ActorInventory.CAPACITY_MODE_WEIGHT) - } - - init { - ui = UIHandler(UIInventory(actor, 900, Terrarum.HEIGHT - 160, 220)) - - ui.posX = 0 - ui.posY = 60 - ui.isVisible = true - - - - // these are the test codes. - // Item properties must be pre-composed using CSV/JSON, and read and made into the item instance - // using factory/builder pattern. @see ItemCodex - - actor.inventory.add(object : GameItem() { - init { - itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER - } - override var dynamicID: Int = 5656 - override val originalID = dynamicID - override val isUnique: Boolean = true - override var originalName: String = "Test tool" - override var baseMass: Double = 12.0 - override var baseToolSize: Double? = 8.0 - override var inventoryCategory: String = GameItem.Category.TOOL - override var maxDurability: Int = 143 - override var durability: Float = 64f - override var stackable = false - override val isDynamic = true - override val material = Material(0,0,0,0,0,0,0,0,0,0.0) - }) - actor.inventory.getByDynamicID(5656)!!.item.name = "Test tool" - - actor.inventory.add(object : GameItem() { - init { - itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT - } - override var dynamicID: Int = 4633 - override val originalID = dynamicID - override val isUnique: Boolean = true - override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN" - override var baseMass: Double = 1.4 - override var baseToolSize: Double? = null - override var inventoryCategory: String = GameItem.Category.MISC - override var stackable = false - override val isDynamic = false - override val material = Material(0,0,0,0,0,0,0,0,0,0.0) - }) - - actor.inventory.add(ItemCodex[16], 543) - - actor.inventory.getByDynamicID(Block.STONE)!!.item equipTo actor - } - - override fun init(container: GameContainer?, game: StateBasedGame?) { - } - - override fun update(container: GameContainer, game: StateBasedGame, delta: Int) { - Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}") - - ui.update(container, delta) - } - - override fun getID() = Terrarum.STATE_ID_TEST_UI1 - - override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { - blendNormal() - g.color = Color.green - g.fillRect(0f, 0f, 2048f, 2048f) - - - - ui.render(container, game, g) - } -} diff --git a/src/net/torvald/terrarum/StateVTTest.kt b/src/net/torvald/terrarum/StateVTTest.kt deleted file mode 100644 index 409416027..000000000 --- a/src/net/torvald/terrarum/StateVTTest.kt +++ /dev/null @@ -1,64 +0,0 @@ -package net.torvald.terrarum - -import net.torvald.terrarum.gamecontroller.Key -import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer -import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal -import net.torvald.terrarum.virtualcomputer.terminal.Teletype -import net.torvald.terrarum.virtualcomputer.terminal.TeletypeTerminal -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.Image -import org.newdawn.slick.state.BasicGameState -import org.newdawn.slick.state.StateBasedGame - -/** - * ComputerCraft/OpenComputers like-alike, just for fun! - * - * Created by minjaesong on 16-09-07. - */ -class StateVTTest : BasicGameState() { - - // HiRes: 100x64, LoRes: 80x25 - val computerInside = TerrarumComputer(peripheralSlots = 8) - val vt = SimpleTextTerminal(SimpleTextTerminal.BLUE_NOVELTY, 80, 25, - computerInside, colour = false, hires = false) - - - val vtUI = Image(vt.displayW, vt.displayH) - - - init { - computerInside.attachTerminal(vt) - } - - override fun init(container: GameContainer, game: StateBasedGame) { - //vt.openInput() - } - - override fun update(container: GameContainer, game: StateBasedGame, delta: Int) { - Terrarum.appgc.setTitle("VT — F: ${container.fps}" + - " — M: ${Terrarum.memInUse}M / ${Terrarum.memXmx}M") - vt.update(container, delta) - computerInside.update(container, delta) - } - - override fun getID() = Terrarum.STATE_ID_TEST_TTY - - private val paperColour = Color(0xfffce6) - - val vtUIrenderX = Terrarum.WIDTH.minus(vtUI.width).div(2f) - val vtUIrenderY = Terrarum.HEIGHT.minus(vtUI.height).div(2f) - - override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { - vt.render(container, vtUI.graphics) - - - blendNormal() - g.drawImage(vtUI, vtUIrenderX, vtUIrenderY) - } - - override fun keyPressed(key: Int, c: Char) { - vt.keyPressed(key, c) - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt deleted file mode 100644 index 9fc3257b3..000000000 --- a/src/net/torvald/terrarum/Terrarum.kt +++ /dev/null @@ -1,689 +0,0 @@ -package net.torvald.terrarum - -import com.google.gson.JsonArray -import com.google.gson.JsonPrimitive -import net.torvald.imagefont.GameFontImpl -import net.torvald.terrarum.utils.JsonFetcher -import net.torvald.terrarum.utils.JsonWriter -import net.torvald.imagefont.TinyAlphNum -import net.torvald.terrarum.gamecontroller.mouseTileX -import net.torvald.terrarum.gamecontroller.mouseTileY -import net.torvald.terrarum.gameworld.toUint -import net.torvald.terrarum.langpack.Lang -import org.lwjgl.input.Controllers -import org.lwjgl.opengl.* -import org.newdawn.slick.* -import org.newdawn.slick.opengl.Texture -import org.newdawn.slick.state.StateBasedGame -import java.io.File -import java.io.IOException -import java.nio.ByteOrder -import java.text.SimpleDateFormat -import java.util.* -import java.util.logging.FileHandler -import java.util.logging.Level -import java.util.logging.Logger -import java.util.logging.SimpleFormatter - -const val GAME_NAME = "Terrarum" - -typealias Millisec = Int - -/** - * Created by minjaesong on 15-12-30. - */ -object Terrarum : StateBasedGame(GAME_NAME) { - - - - ////////////////////////////// - // GLOBAL IMMUTABLE CONFIGS // - ////////////////////////////// - var WIDTH = 1072 - var HEIGHT = 742 // IMAX ratio - - val RENDER_FPS = getConfigInt("displayfps") - val USE_VSYNC = getConfigBoolean("usevsync") - var VSYNC = USE_VSYNC - val VSYNC_TRIGGER_THRESHOLD = 56 - - val HALFW: Int - get() = WIDTH.ushr(1) - val HALFH: Int - get() = HEIGHT.ushr(1) - - /** - * To be used with physics simulator - */ - val TARGET_FPS = 50 - - /** - * To be used with render, to achieve smooth frame drawing - - * TARGET_INTERNAL_FPS > TARGET_FPS for smooth frame drawing - - * Must choose a value so that (1000 / VAL) is still integer - */ - val TARGET_INTERNAL_FPS = 100 - - /** - * For the events depends on rendering frame (e.g. flicker on post-hit invincibility) - */ - var GLOBAL_RENDER_TIMER = Random().nextInt(1020) + 1 - - - - - - - val sysLang: String - get() { - val lan = System.getProperty("user.language") - val country = System.getProperty("user.country") - return lan + country - } - - - lateinit var appgc: AppGameContainer - - var ingame: StateInGame? = null - private val gameConfig = GameConfig() - - val OSName = System.getProperty("os.name") - val OSVersion = System.getProperty("os.version") - lateinit var OperationSystem: String // all caps "WINDOWS, "OSX", "LINUX", "SOLARIS", "UNKNOWN" - private set - val isWin81: Boolean - get() = OperationSystem == "WINDOWS" && OSVersion.toDouble() >= 8.1 - lateinit var defaultDir: String - private set - lateinit var defaultSaveDir: String - private set - - val memInUse: Long - get() = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) shr 20 - val memTotal: Long - get() = Runtime.getRuntime().totalMemory() shr 20 - val memXmx: Long - get() = Runtime.getRuntime().maxMemory() shr 20 - - val environment: RunningEnvironment - - private val localeSimple = arrayOf("de", "en", "es", "it") - var gameLocale = "lateinit" - set(value) { - if (localeSimple.contains(value.substring(0..1))) - field = value.substring(0..1) - else - field = value - - (fontGame as GameFontImpl).reload() - } - - private val nullFont = object : Font { - override fun getHeight(str: String?) = 0 - override fun drawString(x: Float, y: Float, text: String?) {} - override fun drawString(x: Float, y: Float, text: String?, col: Color?) {} - override fun drawString(x: Float, y: Float, text: String?, col: Color?, startIndex: Int, endIndex: Int) {} - override fun getWidth(str: String?) = 0 - override fun getLineHeight() = 0 - } - - var fontGame: Font = nullFont - private set - var fontSmallNumbers: Font = nullFont - private set - - var joypadLabelStart: Char = 0xE000.toChar() // lateinit - var joypadLableSelect: Char = 0xE000.toChar() // lateinit - var joypadLabelNinA: Char = 0xE000.toChar() // lateinit TODO - var joypadLabelNinB: Char = 0xE000.toChar() // lateinit TODO - var joypadLabelNinX: Char = 0xE000.toChar() // lateinit TODO - var joypadLabelNinY: Char = 0xE000.toChar() // lateinit TODO - var joypadLabelNinL: Char = 0xE000.toChar() // lateinit TODO - var joypadLabelNinR: Char = 0xE000.toChar() // lateinit TODO - var joypadLabelNinZL: Char = 0xE000.toChar() // lateinit TODO - var joypadLabelNinZR: Char = 0xE000.toChar() // lateinit TODO - val joypadLabelLEFT = 0xE068.toChar() - val joypadLabelDOWN = 0xE069.toChar() - val joypadLabelUP = 0xE06A.toChar() - val joypadLabelRIGHT = 0xE06B.toChar() - - // 0x0 - 0xF: Game-related - // 0x10 - 0x1F: Config - // 0x100 and onward: unit tests for dev - val STATE_ID_SPLASH = 0x0 - val STATE_ID_HOME = 0x1 - val STATE_ID_GAME = 0x3 - val STATE_ID_CONFIG_CALIBRATE = 0x11 - - val STATE_ID_TEST_FONT = 0x100 - val STATE_ID_TEST_GFX = 0x101 - val STATE_ID_TEST_TTY = 0x102 - val STATE_ID_TEST_BLUR = 0x103 - val STATE_ID_TEST_SHADER = 0x104 - val STATE_ID_TEST_REFRESHRATE = 0x105 - val STATE_ID_TEST_INPUT = 0x106 - - val STATE_ID_TEST_UI1 = 0x110 - - val STATE_ID_TOOL_NOISEGEN = 0x200 - val STATE_ID_TOOL_RUMBLE_DIAGNOSIS = 0x201 - - var controller: org.lwjgl.input.Controller? = null - private set - val CONTROLLER_DEADZONE = 0.1f - - /** Available CPU threads */ - val THREADS = Runtime.getRuntime().availableProcessors() - - /** - * If the game is multithreading. - * True if: - * - * THREADS >= 2 and config "multithread" is true - */ - val MULTITHREAD: Boolean - get() = THREADS >= 2 && getConfigBoolean("multithread") - - private lateinit var configDir: String - - /** - * 0xAA_BB_XXXX - * AA: Major version - * BB: Minor version - * XXXX: Revision (Repository commits) - * - * e.g. 0x02010034 can be translated as 2.1.52 - */ - const val VERSION_RAW = 0x0002018E - const val VERSION_STRING: String = - "${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}" - const val NAME = "Terrarum" - - var delta: Int = 0 - - // these properties goes into the GameContainer - - var previousState: Int? = null // to be used with temporary states like StateMonitorCheck - - val systemArch = System.getProperty("os.arch") - - private val thirtyTwoBitArchs = arrayOf("i386", "i686", "ppc", "x86", "x86_32") // I know I should Write Once, Run Everywhere; but just in case :) - val is32Bit = thirtyTwoBitArchs.contains(systemArch) - - lateinit var textureWhite: Image - lateinit var textureBlack: Image - - init { - - // just in case - println("[Terrarum] os.arch = $systemArch") - - if (is32Bit) { - println("Java is running in 32 Bit") - } - - joypadLabelStart = when (getConfigString("joypadlabelstyle")) { - "nwii" -> 0xE04B.toChar() // + mark - "logitech" -> 0xE05A.toChar() // number 10 - else -> 0xE042.toChar() // |> mark (sonyps, msxb360, generic) - } - joypadLableSelect = when (getConfigString("joypadlabelstyle")) { - "nwii" -> 0xE04D.toChar() // - mark - "logitech" -> 0xE059.toChar() // number 9 - "sonyps" -> 0xE043.toChar() // solid rectangle - "msxb360" -> 0xE041.toChar() // <| mark - else -> 0xE043.toChar() // solid rectangle - } - - - - getDefaultDirectory() - createDirs() - - val readFromDisk = readConfigJson() - if (!readFromDisk) readConfigJson() - - environment = try { - Controllers.getController(0) - if (getConfigString("pcgamepadenv") == "console") - RunningEnvironment.CONSOLE - else - RunningEnvironment.PC - } - catch (e: IndexOutOfBoundsException) { - RunningEnvironment.PC - } - } - - @Throws(SlickException::class) - override fun initStatesList(gc: GameContainer) { - textureWhite = Image("./assets/graphics/background_white.png") - textureBlack = Image("./assets/graphics/background_black.png") - - - fontGame = GameFontImpl() - fontSmallNumbers = TinyAlphNum() - - - gc.input.enableKeyRepeat() - - - // get locale from config - val gameLocaleFromConfig = gameConfig.getAsString("language") ?: sysLang - - // if bad game locale were set, use system locale - if (gameLocaleFromConfig.length < 2) - gameLocale = sysLang - else - gameLocale = gameLocaleFromConfig - - println("[Terrarum] Locale: " + gameLocale) - - - - // search for real controller - // exclude controllers with name "Mouse", "keyboard" - val notControllerRegex = Regex("mouse|keyboard") - try { - // gc.input.controllerCount is unreliable - for (i in 0..255) { - val controllerInQuo = Controllers.getController(i) - - println("Controller $i: ${controllerInQuo.name}") - - // check the name - if (!controllerInQuo.name.toLowerCase().contains(notControllerRegex)) { - controller = controllerInQuo - println("Controller $i selected: ${controller!!.name}") - break - } - } - - - // test acquired controller - controller!!.getAxisValue(0) - } - catch (controllerDoesNotHaveAnyAxesException: java.lang.ArrayIndexOutOfBoundsException) { - controller = null - } - - if (controller != null) { - for (c in 0..controller!!.axisCount - 1) { - controller!!.setDeadZone(c, CONTROLLER_DEADZONE) - } - } - - // load languages - Lang - // load modules - ModMgr - - - gc.graphics.clear() // clean up any 'dust' in the buffer - - //addState(StateVTTest()) - //addState(StateGraphicComputerTest()) - //addState(StateTestingLightning()) - //addState(StateSplash()) - //addState(StateMonitorCheck()) - //addState(StateFontTester()) - //addState(StateNoiseTexGen()) - //addState(StateBlurTest()) - //addState(StateShaderTest()) - //addState(StateNoiseTester()) - //addState(StateUITest()) - //addState(StateControllerRumbleTest()) - //addState(StateMidiInputTest()) - //addState(StateNewRunesTest()) - //addState(StateStutterTest()) - - - ingame = StateInGame(); addState(ingame) - - - // foolproof - if (stateCount < 1) { - throw Error("Please add or un-comment addState statements") - } - } - - private fun getDefaultDirectory() { - val OS = System.getProperty("os.name").toUpperCase() - if (OS.contains("WIN")) { - OperationSystem = "WINDOWS" - defaultDir = System.getenv("APPDATA") + "/Terrarum" - } - else if (OS.contains("OS X")) { - OperationSystem = "OSX" - defaultDir = System.getProperty("user.home") + "/Library/Application Support/Terrarum" - } - else if (OS.contains("NUX") || OS.contains("NIX")) { - OperationSystem = "LINUX" - defaultDir = System.getProperty("user.home") + "/.Terrarum" - } - else if (OS.contains("SUNOS")) { - OperationSystem = "SOLARIS" - defaultDir = System.getProperty("user.home") + "/.Terrarum" - } - else { - OperationSystem = "UNKNOWN" - defaultDir = System.getProperty("user.home") + "/.Terrarum" - } - - defaultSaveDir = defaultDir + "/Saves" - configDir = defaultDir + "/config.json" - - println("[Terrarum] os.name = $OSName") - println("[Terrarum] os.version = $OSVersion") - } - - private fun createDirs() { - val dirs = arrayOf(File(defaultSaveDir)) - dirs.forEach { if (!it.exists()) it.mkdirs() } - } - - @Throws(IOException::class) - private fun createConfigJson() { - val configFile = File(configDir) - - if (!configFile.exists() || configFile.length() == 0L) { - JsonWriter.writeToFile(DefaultConfig.fetch(), configDir) - } - } - - private fun readConfigJson(): Boolean { - try { - // read from disk and build config from it - val jsonObject = JsonFetcher(configDir) - - // make config - jsonObject.entrySet().forEach { entry -> gameConfig[entry.key] = entry.value } - - return true - } - catch (e: IOException) { - // write default config to game dir. Call this method again to read config from it. - try { - createConfigJson() - } - catch (e1: IOException) { - e.printStackTrace() - } - - return false - } - - } - - /** - * Return config from config set. If the config does not exist, default value will be returned. - * @param key - * * - * @return Config from config set or default config if it does not exist. - * * - * @throws NullPointerException if the specified config simply does not exist. - */ - fun getConfigInt(key: String): Int { - val cfg = getConfigMaster(key) - if (cfg is JsonPrimitive) - return cfg.asInt - else - return cfg as Int - } - - /** - * Return config from config set. If the config does not exist, default value will be returned. - * @param key - * * - * @return Config from config set or default config if it does not exist. - * * - * @throws NullPointerException if the specified config simply does not exist. - */ - fun getConfigString(key: String): String { - val cfg = getConfigMaster(key) - if (cfg is JsonPrimitive) - return cfg.asString - else - return cfg as String - } - - /** - * Return config from config set. If the config does not exist, default value will be returned. - * @param key - * * - * @return Config from config set or default config if it does not exist. - * * - * @throws NullPointerException if the specified config simply does not exist. - */ - fun getConfigBoolean(key: String): Boolean { - val cfg = getConfigMaster(key) - if (cfg is JsonPrimitive) - return cfg.asBoolean - else - return cfg as Boolean - } - - fun getConfigIntArray(key: String): IntArray { - val cfg = getConfigMaster(key) - if (cfg is JsonArray) { - val jsonArray = cfg.asJsonArray - return IntArray(jsonArray.size(), { i -> jsonArray[i].asInt }) - } - else - return cfg as IntArray - } - - private fun getConfigMaster(key: String): Any { - var cfg: Any? = null - try { - cfg = gameConfig[key.toLowerCase()]!! - } - catch (e: NullPointerException) { - try { - cfg = DefaultConfig.fetch()[key.toLowerCase()] - } - catch (e1: NullPointerException) { - e.printStackTrace() - } - } - return cfg!! - } - - fun setConfig(key: String, value: Any) { - gameConfig[key] = value - } - - val currentSaveDir: File - get() { - val file = File(defaultSaveDir + "/test") - - // failsafe? - if (!file.exists()) file.mkdir() - - return file // TODO TEST CODE - } - - - - // for external scripts (e.g. Groovy) - @JvmStatic fun getMouseTileX(): Int = appgc.mouseTileX - @JvmStatic fun getMouseTileY(): Int = appgc.mouseTileY -} - -fun main(args: Array) { - System.setProperty("java.library.path", "lib") - System.setProperty("org.lwjgl.librarypath", File("lib").absolutePath) - - try { - Terrarum.appgc = AppGameContainer(Terrarum) - Terrarum.appgc.setDisplayMode(Terrarum.WIDTH, Terrarum.HEIGHT, false) - - if (Terrarum.RENDER_FPS > 0) { - Terrarum.appgc.setTargetFrameRate(Terrarum.RENDER_FPS) - } - //Terrarum.appgc.setVSync(Terrarum.VSYNC) - Terrarum.appgc.setMaximumLogicUpdateInterval(1000 / Terrarum.TARGET_INTERNAL_FPS) // 10 ms - Terrarum.appgc.setMinimumLogicUpdateInterval(1000 / Terrarum.TARGET_INTERNAL_FPS - 1) // 9 ms - - Terrarum.appgc.setMultiSample(0) - - Terrarum.appgc.setShowFPS(false) - - // game will run normally even if it is not focused - Terrarum.appgc.setUpdateOnlyWhenVisible(false) - Terrarum.appgc.alwaysRender = true - - Terrarum.appgc.start() - } - catch (ex: Exception) { - val logger = Logger.getLogger(Terrarum::class.java.name) - val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss") - val calendar = Calendar.getInstance() - val filepath = "${Terrarum.defaultDir}/crashlog-${dateFormat.format(calendar.time)}.txt" - val fileHandler = FileHandler(filepath) - logger.addHandler(fileHandler) - - val formatter = SimpleFormatter() - fileHandler.formatter = formatter - - //logger.info() - println("The game has crashed!") - println("Crash log were saved to $filepath.") - println("================================================================================") - logger.log(Level.SEVERE, null, ex) - } -} - -/////////////////////////////////// -// customised blending functions // -/////////////////////////////////// - -fun blendMul() { - // I must say: What the fuck is wrong with you, Slick2D? Your built-it blending is just fucking wrong. - GL11.glEnable(GL11.GL_BLEND) - GL11.glColorMask(true, true, true, true) - GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA) -} - -fun blendNormal() { - GL11.glEnable(GL11.GL_BLEND) - GL11.glColorMask(true, true, true, true) - //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) - - // semitransparent textures working as intended with this, - // but needs further investigation in the case of: - // TODO test blend in the situation of semitransparent over semitransparent - GL14.glBlendFuncSeparate( - GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, // blend func for RGB channels - GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels - ) -} - -fun blendLightenOnly() { - GL11.glEnable(GL11.GL_BLEND) - GL11.glColorMask(true, true, true, false) - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE) - GL14.glBlendEquation(GL14.GL_MAX) -} - -fun blendAlphaMap() { - GL11.glDisable(GL11.GL_BLEND) - GL11.glColorMask(false, false, false, true) -} - -fun blendScreen() { - GL11.glEnable(GL11.GL_BLEND) - GL11.glColorMask(true, true, true, true) - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR) -} - -fun blendDisable() { - GL11.glDisable(GL11.GL_BLEND) -} - -object BlendMode { - const val SCREEN = "GL_BLEND screen" - const val MULTIPLY = "GL_BLEND multiply" - const val NORMAL = "GL_BLEND normal" - const val MAX = "GL_MAX" - - fun resolve(mode: String) { - when (mode) { - SCREEN -> blendScreen() - MULTIPLY -> blendMul() - NORMAL -> blendNormal() - MAX -> blendLightenOnly() - else -> throw Error("Unknown blend mode: $mode") - } - } -} - -enum class RunningEnvironment { - PC, CONSOLE, MOBILE -} - -/** @return Intarray(R, G, B, A) */ -fun Texture.getPixel(x: Int, y: Int): IntArray { - val textureWidth = this.textureWidth - val hasAlpha = this.hasAlpha() - - val offset = (if (hasAlpha) 4 else 3) * (textureWidth * y + x) // 4: # of channels (RGBA) - - if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { - return intArrayOf( - this.textureData[offset].toUint(), - this.textureData[offset + 1].toUint(), - this.textureData[offset + 2].toUint(), - if (hasAlpha) - this.textureData[offset + 3].toUint() - else 255 - ) - } - else { - return intArrayOf( - this.textureData[offset + 2].toUint(), - this.textureData[offset + 1].toUint(), - this.textureData[offset].toUint(), - if (hasAlpha) - this.textureData[offset + 3].toUint() - else 255 - ) - } -} - -/** @return Intarray(R, G, B, A) */ -fun Image.getPixel(x: Int, y: Int) = this.texture.getPixel(x, y) - -fun Color.toInt() = redByte.shl(16) or greenByte.shl(8) or blueByte -fun Color.to10bit() = redByte.shl(20) or greenByte.shl(10) or blueByte - -infix fun Color.screen(other: Color) = Color( - 1f - (1f - this.r) * (1f - other.r), - 1f - (1f - this.g) * (1f - other.g), - 1f - (1f - this.b) * (1f - other.b), - 1f - (1f - this.a) * (1f - other.a) -) -infix fun Color.mul(other: Color) = Color( // don't turn into an operator! - this.r * other.r, - this.g * other.g, - this.b * other.b, - this.a * other.a -) -infix fun Color.minus(other: Color) = Color( // don't turn into an operator! - this.r - other.r, - this.g - other.g, - this.b - other.b, - this.a - other.a -) - -fun Int.toHex() = this.toLong().and(0xFFFFFFFF).toString(16).padStart(8, '0').toUpperCase() -fun Long.toHex() = { - val sb = StringBuilder() - (0..16).forEach { - - } -} - - diff --git a/src/net/torvald/terrarum/TerrarumGDX.kt b/src/net/torvald/terrarum/TerrarumGDX.kt index 58afc7b0a..d675a761f 100644 --- a/src/net/torvald/terrarum/TerrarumGDX.kt +++ b/src/net/torvald/terrarum/TerrarumGDX.kt @@ -1,7 +1,610 @@ package net.torvald.terrarum +import com.badlogic.gdx.ApplicationAdapter +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Screen +import com.badlogic.gdx.backends.lwjgl.LwjglApplication +import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.GL20 +import com.badlogic.gdx.graphics.GL30 +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.Batch +import com.badlogic.gdx.graphics.g2d.BitmapFont +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.glutils.FrameBuffer +import com.badlogic.gdx.graphics.glutils.ShapeRenderer +import com.google.gson.JsonArray +import com.google.gson.JsonPrimitive +import net.torvald.terrarum.gameactors.ActorWithPhysics.Companion.TILE_SIZE +import net.torvald.terrarum.gamecontroller.GameController +import net.torvald.terrarum.imagefont.TinyAlphNum +import net.torvald.terrarum.utils.JsonFetcher +import net.torvald.terrarum.utils.JsonWriter +import net.torvald.terrarum.worlddrawer.RGB10 +import net.torvald.terrarumsansbitmap.gdx.GameFontBase +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import org.lwjgl.input.Controllers +import org.lwjgl.opengl.GL11 +import java.io.File +import java.io.IOException +import java.util.* + /** * Created by minjaesong on 2017-06-15. */ -object TerrarumGDX { -} \ No newline at end of file + +const val GAME_NAME = "Terrarum" + +fun main(args: Array) { + val config = LwjglApplicationConfiguration() + config.foregroundFPS = TerrarumGDX.RENDER_FPS + config.backgroundFPS = TerrarumGDX.RENDER_FPS + config.vSyncEnabled = true + config.resizable = false + config.width = 1072 + config.height = 742 + config.title = GAME_NAME + + LwjglApplication(TerrarumGDX, config) +} + + + +typealias RGBA8888 = Int + +object TerrarumGDX : ApplicationAdapter() { + + lateinit var batch: SpriteBatch + lateinit var shapeRender: ShapeRenderer // DO NOT USE!! for very limited applications e.g. WeatherMixer + inline fun inShapeRenderer(shapeRendererType: ShapeRenderer.ShapeType = ShapeRenderer.ShapeType.Filled, action: (ShapeRenderer) -> Unit) { + shapeRender.begin(shapeRendererType) + action(shapeRender) + shapeRender.end() + } + + + lateinit var orthoLineTex2px: Texture + lateinit var orthoLineTex3px: Texture + + + ////////////////////////////// + // GLOBAL IMMUTABLE CONFIGS // + ////////////////////////////// + + val RENDER_FPS = getConfigInt("displayfps") + val USE_VSYNC = getConfigBoolean("usevsync") + var VSYNC = USE_VSYNC + val VSYNC_TRIGGER_THRESHOLD = 56 + + inline val HALFW: Int + get() = Gdx.graphics.width.ushr(1) + inline val HALFH: Int + get() = Gdx.graphics.height.ushr(1) + + /** + * To be used with physics simulator + */ + val TARGET_FPS = 50 + + /** + * To be used with render, to achieve smooth frame drawing + + * TARGET_INTERNAL_FPS > TARGET_FPS for smooth frame drawing + + * Must choose a value so that (1000 / VAL) is still integer + */ + val TARGET_INTERNAL_FPS = 100 + + + /** + * For the events depends on rendering frame (e.g. flicker on post-hit invincibility) + */ + var GLOBAL_RENDER_TIMER = Random().nextInt(1020) + 1 + + + + + + + val sysLang: String + get() { + val lan = System.getProperty("user.language") + val country = System.getProperty("user.country") + return lan + country + } + + lateinit var currentScreen: Screen + var previousScreen: Screen? = null // to be used with temporary states like StateMonitorCheck + + + var ingame: StateInGameGDX? = null + private val gameConfig = GameConfig() + + val OSName = System.getProperty("os.name") + val OSVersion = System.getProperty("os.version") + lateinit var OperationSystem: String // all caps "WINDOWS, "OSX", "LINUX", "SOLARIS", "UNKNOWN" + private set + lateinit var defaultDir: String + private set + lateinit var defaultSaveDir: String + private set + + val memInUse: Long + get() = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) shr 20 + val memTotal: Long + get() = Runtime.getRuntime().totalMemory() shr 20 + val memXmx: Long + get() = Runtime.getRuntime().maxMemory() shr 20 + + val environment: RunningEnvironment + + private val localeSimple = arrayOf("de", "en", "es", "it") + var gameLocale = "lateinit" + set(value) { + if (localeSimple.contains(value.substring(0..1))) + field = value.substring(0..1) + else + field = value + + fontGame.reload(value) + } + + + + lateinit var fontGame: GameFontBase + lateinit var fontSmallNumbers: BitmapFont + + var joypadLabelStart: Char = 0xE000.toChar() // lateinit + var joypadLableSelect: Char = 0xE000.toChar() // lateinit + var joypadLabelNinA: Char = 0xE000.toChar() // lateinit TODO + var joypadLabelNinB: Char = 0xE000.toChar() // lateinit TODO + var joypadLabelNinX: Char = 0xE000.toChar() // lateinit TODO + var joypadLabelNinY: Char = 0xE000.toChar() // lateinit TODO + var joypadLabelNinL: Char = 0xE000.toChar() // lateinit TODO + var joypadLabelNinR: Char = 0xE000.toChar() // lateinit TODO + var joypadLabelNinZL: Char = 0xE000.toChar() // lateinit TODO + var joypadLabelNinZR: Char = 0xE000.toChar() // lateinit TODO + val joypadLabelLEFT = 0xE068.toChar() + val joypadLabelDOWN = 0xE069.toChar() + val joypadLabelUP = 0xE06A.toChar() + val joypadLabelRIGHT = 0xE06B.toChar() + + // 0x0 - 0xF: Game-related + // 0x10 - 0x1F: Config + // 0x100 and onward: unit tests for dev + val STATE_ID_SPLASH = 0x0 + val STATE_ID_HOME = 0x1 + val STATE_ID_GAME = 0x3 + val STATE_ID_CONFIG_CALIBRATE = 0x11 + + val STATE_ID_TEST_FONT = 0x100 + val STATE_ID_TEST_GFX = 0x101 + val STATE_ID_TEST_TTY = 0x102 + val STATE_ID_TEST_BLUR = 0x103 + val STATE_ID_TEST_SHADER = 0x104 + val STATE_ID_TEST_REFRESHRATE = 0x105 + val STATE_ID_TEST_INPUT = 0x106 + + val STATE_ID_TEST_UI1 = 0x110 + + val STATE_ID_TOOL_NOISEGEN = 0x200 + val STATE_ID_TOOL_RUMBLE_DIAGNOSIS = 0x201 + + var controller: org.lwjgl.input.Controller? = null + private set + val CONTROLLER_DEADZONE = 0.1f + + /** Available CPU threads */ + val THREADS = Runtime.getRuntime().availableProcessors() + + /** + * If the game is multithreading. + * True if: + * + * THREADS >= 2 and config "multithread" is true + */ + val MULTITHREAD: Boolean + get() = THREADS >= 2 && getConfigBoolean("multithread") + + private lateinit var configDir: String + + /** + * 0xAA_BB_XXXX + * AA: Major version + * BB: Minor version + * XXXX: Revision (Repository commits) + * + * e.g. 0x02010034 can be translated as 2.1.52 + */ + const val VERSION_RAW = 0x00_02_018E + const val VERSION_STRING: String = + "${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}" + const val NAME = "Terrarum" + + + val systemArch = System.getProperty("os.arch") + + val is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64") + + + init { + println("[Terrarum] os.arch = $systemArch") // debug info + + if (is32BitJVM) { + println("32 Bit JVM detected") + } + + joypadLabelStart = when (getConfigString("joypadlabelstyle")) { + "nwii" -> 0xE04B.toChar() // + mark + "logitech" -> 0xE05A.toChar() // number 10 + else -> 0xE042.toChar() // |> mark (sonyps, msxb360, generic) + } + joypadLableSelect = when (getConfigString("joypadlabelstyle")) { + "nwii" -> 0xE04D.toChar() // - mark + "logitech" -> 0xE059.toChar() // number 9 + "sonyps" -> 0xE043.toChar() // solid rectangle + "msxb360" -> 0xE041.toChar() // <| mark + else -> 0xE043.toChar() // solid rectangle + } + + + + getDefaultDirectory() + createDirs() + + val readFromDisk = readConfigJson() + if (!readFromDisk) readConfigJson() + + environment = try { + Controllers.getController(0) // test if controller exists + if (getConfigString("pcgamepadenv") == "console") + RunningEnvironment.CONSOLE + else + RunningEnvironment.PC + } + catch (e: IndexOutOfBoundsException) { + RunningEnvironment.PC + } + } + + override fun create() { + TextureRegionPack.globalFlipY = true // !! TO MAKE LEGACY CODE RENDER ON ITS POSITION !! + Gdx.graphics.isContinuousRendering = true + + batch = SpriteBatch() + shapeRender = ShapeRenderer() + + orthoLineTex2px = Texture("assets/graphics/ortho_line_tex_2px.tga") + orthoLineTex3px = Texture("assets/graphics/ortho_line_tex_3px.tga") + + + fontGame = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", flipY = true) + fontSmallNumbers = TinyAlphNum + + + + + ingame = StateInGameGDX(batch) + ingame!!.enter() + currentScreen = ingame as Screen + } + + override fun render() { + currentScreen.render(Gdx.graphics.deltaTime) + } + + override fun pause() { + currentScreen.pause() + } + + override fun resume() { + currentScreen.resume() + } + + override fun dispose() { + currentScreen.dispose() + fontGame.dispose() + fontSmallNumbers.dispose() + //dispose any other resources used in this level + } + + override fun resize(width: Int, height: Int) { + currentScreen.resize(width, height) + } + + + + + private fun getDefaultDirectory() { + val OS = System.getProperty("os.name").toUpperCase() + if (OS.contains("WIN")) { + OperationSystem = "WINDOWS" + defaultDir = System.getenv("APPDATA") + "/Terrarum" + } + else if (OS.contains("OS X")) { + OperationSystem = "OSX" + defaultDir = System.getProperty("user.home") + "/Library/Application Support/Terrarum" + } + else if (OS.contains("NUX") || OS.contains("NIX")) { + OperationSystem = "LINUX" + defaultDir = System.getProperty("user.home") + "/.Terrarum" + } + else if (OS.contains("SUNOS")) { + OperationSystem = "SOLARIS" + defaultDir = System.getProperty("user.home") + "/.Terrarum" + } + else { + OperationSystem = "UNKNOWN" + defaultDir = System.getProperty("user.home") + "/.Terrarum" + } + + defaultSaveDir = defaultDir + "/Saves" + configDir = defaultDir + "/config.json" + + println("[Terrarum] os.name = $OSName") + println("[Terrarum] os.version = $OSVersion") + } + + private fun createDirs() { + val dirs = arrayOf(File(defaultSaveDir)) + dirs.forEach { if (!it.exists()) it.mkdirs() } + } + + private fun createConfigJson() { + val configFile = File(configDir) + + if (!configFile.exists() || configFile.length() == 0L) { + JsonWriter.writeToFile(DefaultConfig.fetch(), configDir) + } + } + + private fun readConfigJson(): Boolean { + try { + // read from disk and build config from it + val jsonObject = JsonFetcher(configDir) + + // make config + jsonObject.entrySet().forEach { entry -> gameConfig[entry.key] = entry.value } + + return true + } + catch (e: IOException) { + // write default config to game dir. Call this method again to read config from it. + try { + createConfigJson() + } + catch (e1: IOException) { + e.printStackTrace() + } + + return false + } + + } + + /** + * Return config from config set. If the config does not exist, default value will be returned. + * @param key + * * + * @return Config from config set or default config if it does not exist. + * * + * @throws NullPointerException if the specified config simply does not exist. + */ + fun getConfigInt(key: String): Int { + val cfg = getConfigMaster(key) + if (cfg is JsonPrimitive) + return cfg.asInt + else + return cfg as Int + } + + /** + * Return config from config set. If the config does not exist, default value will be returned. + * @param key + * * + * @return Config from config set or default config if it does not exist. + * * + * @throws NullPointerException if the specified config simply does not exist. + */ + fun getConfigString(key: String): String { + val cfg = getConfigMaster(key) + if (cfg is JsonPrimitive) + return cfg.asString + else + return cfg as String + } + + /** + * Return config from config set. If the config does not exist, default value will be returned. + * @param key + * * + * @return Config from config set or default config if it does not exist. + * * + * @throws NullPointerException if the specified config simply does not exist. + */ + fun getConfigBoolean(key: String): Boolean { + val cfg = getConfigMaster(key) + if (cfg is JsonPrimitive) + return cfg.asBoolean + else + return cfg as Boolean + } + + fun getConfigIntArray(key: String): IntArray { + val cfg = getConfigMaster(key) + if (cfg is JsonArray) { + val jsonArray = cfg.asJsonArray + return IntArray(jsonArray.size(), { i -> jsonArray[i].asInt }) + } + else + return cfg as IntArray + } + + private fun getConfigMaster(key: String): Any { + var cfg: Any? = null + try { + cfg = gameConfig[key.toLowerCase()]!! + } + catch (e: NullPointerException) { + try { + cfg = DefaultConfig.fetch()[key.toLowerCase()] + } + catch (e1: NullPointerException) { + e.printStackTrace() + } + } + return cfg!! + } + + fun setConfig(key: String, value: Any) { + gameConfig[key] = value + } + + val currentSaveDir: File + get() { + val file = File(defaultSaveDir + "/test") + + // failsafe? + if (!file.exists()) file.mkdir() + + return file // TODO TEST CODE + } + + inline val mouseX: Double + get() = GameController.mouseX.toDouble() + inline val mouseY: Double + get() = GameController.mouseY.toDouble() + @JvmStatic inline val mouseTileX: Int + get() = mouseX.toInt() / TILE_SIZE + @JvmStatic inline val mouseTileY: Int + get() = mouseY.toInt() / TILE_SIZE + inline val mouseScreenX: Int + get() = Gdx.input.x + inline val mouseScreenY: Int + get() = Gdx.input.y + + + + +} + +inline fun Batch.inUse(action: (Batch) -> Unit) { + this.begin() + action(this) + this.end() +} + +inline fun ShapeRenderer.inUse(shapeRendererType: ShapeRenderer.ShapeType = ShapeRenderer.ShapeType.Filled, action: (ShapeRenderer) -> Unit) { + this.begin(shapeRendererType) + action(this) + this.end() +} + +/** Use Batch inside of it! */ +inline fun FrameBuffer.inAction(action: (FrameBuffer) -> Unit) { + this.begin() + action(this) + this.end() +} + + + +// ShapeRenderer alternative for rects +inline fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) { + this.draw(net.torvald.terrarum.TerrarumGDX.orthoLineTex2px, x, y, w, h) +} +inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, p2: Float, thickness: Float, isVertical: Boolean) { + if (!isVertical) + this.fillRect(x, y, p2 - x, thickness) + else + this.fillRect(x, y, thickness, p2 - y) +} + + + +infix fun Color.mul(other: Color): Color = this.mul(other) + + + +inline fun Color.toRGB10(): RGB10 { + val bits = this.toIntBits() // ABGR + // 0bxxRRRRRRRRRRGGGGGGGGGGBBBBBBBBBB + // 0bAAAAAAAABBBBBBBBGGGGGGGGRRRRRRRR + return bits.and(0x0000FF).shl(20) or bits.and(0x00FF00).shl(2) or bits.and(0xFF0000).ushr(16) +} + + + +fun blendMul() { + // I must say: What the fuck is wrong with you, Slick2D? Your built-it blending is just fucking wrong. + TerrarumGDX.batch.enableBlending() + TerrarumGDX.batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA) + Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation +} + +fun blendNormal() { + TerrarumGDX.batch.enableBlending() + TerrarumGDX.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) + Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation +} + +fun blendLightenOnly() { + TerrarumGDX.batch.enableBlending() + TerrarumGDX.batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE) + Gdx.gl.glBlendEquation(GL30.GL_MAX) // batch.flush does not touch blend equation +} + +fun blendScreen() { + TerrarumGDX.batch.enableBlending() + TerrarumGDX.batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR) + Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation +} + +object BlendMode { + const val SCREEN = "GL_BLEND screen" + const val MULTIPLY = "GL_BLEND multiply" + const val NORMAL = "GL_BLEND normal" + const val MAX = "GL_MAX" + + fun resolve(mode: String) { + when (mode) { + SCREEN -> blendScreen() + MULTIPLY -> blendMul() + NORMAL -> blendNormal() + MAX -> blendLightenOnly() + else -> throw Error("Unknown blend mode: $mode") + } + } +} + +enum class RunningEnvironment { + PC, CONSOLE, MOBILE +} + +infix fun Color.screen(other: Color) = Color( + 1f - (1f - this.r) * (1f - other.r), + 1f - (1f - this.g) * (1f - other.g), + 1f - (1f - this.b) * (1f - other.b), + 1f - (1f - this.a) * (1f - other.a) +) + +infix fun Color.minus(other: Color) = Color( // don't turn into an operator! + this.r - other.r, + this.g - other.g, + this.b - other.b, + this.a - other.a +) + +fun Int.toHex() = this.toLong().and(0xFFFFFFFF).toString(16).padStart(8, '0').toUpperCase() +fun Long.toHex() = { + val sb = StringBuilder() + (0..16).forEach { + + } +} + + + + + diff --git a/src/net/torvald/terrarum/TestTestTest.kt b/src/net/torvald/terrarum/TestTestTest.kt index ef7c0307e..cbc0415e9 100644 --- a/src/net/torvald/terrarum/TestTestTest.kt +++ b/src/net/torvald/terrarum/TestTestTest.kt @@ -26,7 +26,7 @@ class TestTestTest : ApplicationAdapter() { batch = SpriteBatch() img = Texture("assets/test_texture.tga") - gameFont = GameFontBase("assets/graphics/fonts") + gameFont = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap") //gameFont = BitmapFont() } diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index b4a89ac3e..5c97cccd9 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -1,15 +1,15 @@ package net.torvald.terrarum +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.colourutil.CIELabUtil.darkerLab import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItemTextButton -import org.newdawn.slick.Color -import org.newdawn.slick.GameContainer -import org.newdawn.slick.Graphics -import org.newdawn.slick.Image /*** * Note that the UI will not render if either item or itemImage is null. @@ -23,12 +23,12 @@ class UIItemInventoryElem( override val width: Int, var item: GameItem?, var amount: Int, - var itemImage: Image?, - val mouseOverTextCol: Color = Color(0xfff066), - val mouseoverBackCol: Color = Color(0,0,0,0), + var itemImage: TextureRegion?, + val mouseOverTextCol: Color = Color(0xfff066_ff.toInt()), + val mouseoverBackCol: Color = Color(0), val mouseoverBackBlendMode: String = BlendMode.NORMAL, val inactiveTextCol: Color = UIItemTextButton.defaultInactiveCol, - val backCol: Color = Color(0,0,0,0), + val backCol: Color = Color(0), val backBlendMode: String = BlendMode.NORMAL, var quickslot: Int? = null, var equippedSlot: Int? = null, @@ -45,7 +45,7 @@ class UIItemInventoryElem( override val height = UIItemInventoryElem.height private val imgOffset: Float - get() = (this.height - itemImage!!.height).div(2).toFloat() // to snap to the pixel grid + get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid private val textOffsetX = 50f private val textOffsetY = 8f @@ -56,7 +56,7 @@ class UIItemInventoryElem( - override fun update(gc: GameContainer, delta: Int) { + override fun update(delta: Float) { if (item != null) { } @@ -64,22 +64,21 @@ class UIItemInventoryElem( private val fwsp = 0x3000.toChar() - override fun render(gc: GameContainer, g: Graphics) { - g.font = Terrarum.fontGame + override fun render(batch: SpriteBatch) { // mouseover background if (item != null || drawBackOnNull) { // do not highlight even if drawBackOnNull is true if (mouseUp && item != null) { BlendMode.resolve(mouseoverBackBlendMode) - g.color = mouseoverBackCol + batch.color = mouseoverBackCol } // if drawBackOnNull, just draw background else { BlendMode.resolve(backBlendMode) - g.color = backCol + batch.color = backCol } - g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat()) + batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat()) } @@ -87,12 +86,12 @@ class UIItemInventoryElem( blendNormal() // item image - g.drawImage(itemImage!!, posX + imgOffset, posY + imgOffset) + batch.draw(itemImage, posX + imgOffset, posY + imgOffset) // if mouse is over, text lights up // this one-liner sets color - g.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol - g.drawString( + batch.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol + TerrarumGDX.fontGame.draw(batch, //"$item" + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") + item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") + (if (equippedSlot != null) " ${0xE081.toChar()}\$$equippedSlot" else ""), @@ -105,28 +104,27 @@ class UIItemInventoryElem( val barFullLen = (width - 8f) - textOffsetX val barOffset = posX + textOffsetX if (item!!.maxDurability > 0.0) { - g.color = durabilityBack - g.lineWidth = 3f - g.drawLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen, posY + durabilityBarOffY) - g.color = durabilityCol - g.drawLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen * (item!!.durability / item!!.maxDurability), posY + durabilityBarOffY) + batch.color = durabilityBack + batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen, 3f, false) + batch.color = durabilityCol + batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen * (item!!.durability / item!!.maxDurability), 3f, false) } // quickslot marker (TEMPORARY UNTIL WE GET BETTER DESIGN) if (quickslot != null) { val label = quickslot!!.plus(0xE010).toChar() - val labelW = g.font.getWidth("$label") - g.color = Color.white - g.drawString("$label", barOffset + barFullLen - labelW, posY + textOffsetY) + val labelW = TerrarumGDX.fontGame.getWidth("$label") + batch.color = Color.WHITE + TerrarumGDX.fontGame.draw(batch, "$label", barOffset + barFullLen - labelW, posY + textOffsetY) } } } override fun keyPressed(key: Int, c: Char) { - if (item != null && Terrarum.ingame != null && key in Key.NUM_1..Key.NUM_0) { - val inventory = Terrarum.ingame!!.player?.inventory + if (item != null && TerrarumGDX.ingame != null && key in Key.NUM_1..Key.NUM_0) { + val inventory = TerrarumGDX.ingame!!.player?.inventory val slot = key - Key.NUM_1 val currentSlotItem = inventory?.getQuickBar(slot) @@ -159,11 +157,11 @@ class UIItemInventoryElem( } override fun mousePressed(button: Int, x: Int, y: Int) { - if (item != null && Terrarum.ingame != null) { + if (item != null && TerrarumGDX.ingame != null) { // equip da shit val itemEquipSlot = item!!.equipPosition - val player = Terrarum.ingame!!.player + val player = TerrarumGDX.ingame!!.player if (item != player?.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it player?.equipItem(item!!) @@ -187,4 +185,4 @@ class UIItemInventoryElem( override fun controllerButtonReleased(controller: Int, button: Int) { } -} \ No newline at end of file +} diff --git a/src/net/torvald/terrarum/audio/AudioMixer.kt b/src/net/torvald/terrarum/audio/AudioMixer.kt deleted file mode 100644 index 0287d1555..000000000 --- a/src/net/torvald/terrarum/audio/AudioMixer.kt +++ /dev/null @@ -1,56 +0,0 @@ -package net.torvald.terrarum.audio - -import org.lwjgl.BufferUtils -import org.lwjgl.openal.AL10 -import org.newdawn.slick.Music -import org.newdawn.slick.openal.Audio -import org.newdawn.slick.openal.AudioImpl -import org.newdawn.slick.openal.MODSound -import org.newdawn.slick.openal.StreamSound -import java.util.* - -/** - * Created by minjaesong on 16-07-08. - */ -object AudioMixer { - const val TRACK_COUNT = 32 - - const val TRACK_AMBIENT_ONE = 0 // music track one - const val TRACK_AMBIENT_ONE_NEXT = 1 // music track two - const val TRACK_AMBIENT_TWO = 2 // music track three - const val TRACK_AMBIENT_TWO_NEXT = 3 // music track four - - const val TRACK_UI_ONE = 8 - const val TRACK_UI_TWO = 9 - - const val TRACK_SFX_START = 16 - const val TRACK_SFX_END = 31 - - val tracks = ArrayList(TRACK_COUNT) // stores index of ALSource - - init { - tracks[TRACK_AMBIENT_ONE] - } - - fun getAudio(track: Int) = tracks[track] - - fun play(channel: Int) { - - } - - /** - * Queue an SFX to any empty SFX track and play it. - */ - fun queueSfx(audio: Audio) { - - } - - fun update(delta: Int) { - - } - - - class MixerTrack(val audio: Audio, var volume: Float, var pan: Float) { - - } -} diff --git a/src/net/torvald/terrarum/audio/AudioResourceLibrary.kt b/src/net/torvald/terrarum/audio/AudioResourceLibrary.kt index 68e5d89e0..76d6bb53c 100644 --- a/src/net/torvald/terrarum/audio/AudioResourceLibrary.kt +++ b/src/net/torvald/terrarum/audio/AudioResourceLibrary.kt @@ -1,9 +1,9 @@ package net.torvald.terrarum.audio -import org.newdawn.slick.openal.Audio -import org.newdawn.slick.openal.AudioLoader -import java.io.File -import java.io.FileInputStream +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.audio.Music +import com.badlogic.gdx.audio.Sound +import net.torvald.terrarum.ModMgr import java.util.* /** @@ -12,24 +12,21 @@ import java.util.* object AudioResourceLibrary { // will play as music - val ambientsForest = ArrayList