diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 96cc43efa..43b000d95 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -14,7 +14,7 @@ - + diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 000000000..b0b18f4e3 --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml index db5f1ccdf..147d598bf 100644 --- a/.idea/libraries/lib.xml +++ b/.idea/libraries/lib.xml @@ -19,6 +19,7 @@ + diff --git a/lib/kotlin-reflect.jar b/lib/kotlin-reflect.jar new file mode 100755 index 000000000..2e4228f33 Binary files /dev/null and b/lib/kotlin-reflect.jar differ diff --git a/lib/kotlin-runtime-sources.jar b/lib/kotlin-runtime-sources.jar new file mode 100755 index 000000000..f00a854e7 Binary files /dev/null and b/lib/kotlin-runtime-sources.jar differ diff --git a/lib/kotlin-runtime.jar b/lib/kotlin-runtime.jar new file mode 100755 index 000000000..5c27d0b90 Binary files /dev/null and b/lib/kotlin-runtime.jar differ diff --git a/out/production/Terrarum_renewed/META-INF/Terrarum_renewed.kotlin_module b/out/production/Terrarum_renewed/META-INF/Terrarum_renewed.kotlin_module new file mode 100644 index 000000000..ea5bb5077 Binary files /dev/null and b/out/production/Terrarum_renewed/META-INF/Terrarum_renewed.kotlin_module differ diff --git a/out/production/Terrarum_renewed/com/Torvald/CSVFetcher.class b/out/production/Terrarum_renewed/com/Torvald/CSVFetcher.class index 952b99d4e..bf4b8795f 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/CSVFetcher.class and b/out/production/Terrarum_renewed/com/Torvald/CSVFetcher.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/ImageFont/GameFontBase.class b/out/production/Terrarum_renewed/com/Torvald/ImageFont/GameFontBase.class index 4928989b2..477342d27 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/ImageFont/GameFontBase.class and b/out/production/Terrarum_renewed/com/Torvald/ImageFont/GameFontBase.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/ImageFont/GameFontBlack.class b/out/production/Terrarum_renewed/com/Torvald/ImageFont/GameFontBlack.class deleted file mode 100644 index 8957085e4..000000000 Binary files a/out/production/Terrarum_renewed/com/Torvald/ImageFont/GameFontBlack.class and /dev/null differ diff --git a/out/production/Terrarum_renewed/com/Torvald/JsonWriter.class b/out/production/Terrarum_renewed/com/Torvald/JsonWriter.class index 1c0b83093..d2fbb6816 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/JsonWriter.class and b/out/production/Terrarum_renewed/com/Torvald/JsonWriter.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AI/ActorAI.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AI/ActorAI.class index 181602438..ca14c10e3 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AI/ActorAI.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AI/ActorAI.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AIControlled.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AIControlled.class index b8a774720..a41c1a6d6 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AIControlled.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/AIControlled.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Actor.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Actor similarity index 100% rename from src/com/Torvald/Terrarum/Actors/Actor.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Actor diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Actor.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Actor.class index e78b82e0a..73d40d410 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Actor.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Actor.class differ diff --git a/src/com/Torvald/Terrarum/Actors/ActorWithBody.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody similarity index 98% rename from src/com/Torvald/Terrarum/Actors/ActorWithBody.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody index a2c8e3ce9..c9e1cb980 100644 --- a/src/com/Torvald/Terrarum/Actors/ActorWithBody.java +++ b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody @@ -4,14 +4,14 @@ import com.Torvald.Rand.HQRNG; import com.Torvald.Terrarum.*; import com.Torvald.Terrarum.GameMap.GameMap; import com.Torvald.Terrarum.MapDrawer.MapDrawer; +import com.Torvald.Terrarum.NotNull; +import com.Torvald.Terrarum.Nullable; import com.Torvald.Terrarum.TileProperties.TilePropCodex; import com.Torvald.spriteAnimation.SpriteAnimation; import com.jme3.math.FastMath; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; -import java.io.Serializable; - /** * Created by minjaesong on 16-01-13. */ @@ -245,7 +245,7 @@ public class ActorWithBody implements Actor, Visible, Glowing { */ // FIXME abnormal jump behaviour if mass < 2, same thing happens if mass == 0 (but zero mass is invalid anyway). private void applyGravitation() { - if (!isGrounded()) { + if (!getGrounded()) { /** * weight; gravitational force in action * W = mass * G (9.8 [m/s^2]) @@ -766,11 +766,6 @@ public class ActorWithBody implements Actor, Visible, Glowing { if (sprite != null) sprite.update(delta_t); } - @Override - public long getRefID() { - return referenceID; - } - private float clampW(float x) { if (x < TSIZE + nextHitbox.getWidth() / 2) { return TSIZE + nextHitbox.getWidth() / 2; @@ -980,6 +975,17 @@ public class ActorWithBody implements Actor, Visible, Glowing { this.density = density; } + + @org.jetbrains.annotations.Nullable + @Override + public Long getReferenceID() { + return this.referenceID; + } + + @Override + public void setReferenceID(@org.jetbrains.annotations.Nullable Long aLong) { + referenceID = aLong; + } } /** diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody$Companion.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody$Companion.class new file mode 100644 index 000000000..25cdc0ba9 Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody$Companion.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class index 9de151aff..51370b80c 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class differ diff --git a/src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CanBeStoredAsItem similarity index 100% rename from src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CanBeStoredAsItem diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.class index 3501172c8..33c50554e 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Controllable.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Controllable similarity index 100% rename from src/com/Torvald/Terrarum/Actors/Controllable.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Controllable diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Controllable.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Controllable.class index 7e6fe67b7..72cfb963b 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Controllable.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Controllable.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureBuildFactory.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureBuildFactory.class deleted file mode 100644 index ee8ea06e2..000000000 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureBuildFactory.class and /dev/null differ diff --git a/src/com/Torvald/Terrarum/Actors/CreatureBuildFactory.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactory similarity index 99% rename from src/com/Torvald/Terrarum/Actors/CreatureBuildFactory.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactory index 1595d82a3..571a8f745 100644 --- a/src/com/Torvald/Terrarum/Actors/CreatureBuildFactory.java +++ b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactory @@ -12,7 +12,7 @@ import java.io.IOException; /** * Created by minjaesong on 16-02-05. */ -public class CreatureBuildFactory { +public class CreatureFactory { private static final String JSONPATH = "./res/raw/"; @@ -62,7 +62,6 @@ public class CreatureBuildFactory { actor.inventory = new ActorInventory((int) actor.actorValue.get("encumberance"), true); - return actor; } diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactory.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactory.class new file mode 100644 index 000000000..052e4edff Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactory.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactoryKt.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactoryKt.class new file mode 100644 index 000000000..666802a3c Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/CreatureFactoryKt.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Faction/FactionRelatorFactory.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Faction/FactionRelatorFactory.class index 6af94e618..f56c34412 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Faction/FactionRelatorFactory.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Faction/FactionRelatorFactory.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Factionable.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Factionable similarity index 100% rename from src/com/Torvald/Terrarum/Actors/Factionable.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Factionable diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Factionable.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Factionable.class index c14e9f842..9c4ab5722 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Factionable.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Factionable.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Glowing.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Glowing similarity index 100% rename from src/com/Torvald/Terrarum/Actors/Glowing.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Glowing diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Glowing.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Glowing.class index a262d8065..eb1d8bd87 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Glowing.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Glowing.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Landholder.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Landholder similarity index 100% rename from src/com/Torvald/Terrarum/Actors/Landholder.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Landholder diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Landholder.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Landholder.class index e2e3f77fc..2d49e126f 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Landholder.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Landholder.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Luminous.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Luminous similarity index 100% rename from src/com/Torvald/Terrarum/Actors/Luminous.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Luminous diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Luminous.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Luminous.class index 46ad2272b..58dc8ac0b 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Luminous.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Luminous.class differ diff --git a/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase similarity index 100% rename from src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$1.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$1.class deleted file mode 100644 index 5b43492b9..000000000 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$1.class and /dev/null differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$attachItemData$1.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$attachItemData$1.class new file mode 100644 index 000000000..bdc9c0d44 Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$attachItemData$1.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class index f4e1e88b6..930a251d9 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PBFSigrid.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PBFSigrid.class deleted file mode 100644 index dd6a3d1df..000000000 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PBFSigrid.class and /dev/null differ diff --git a/src/com/Torvald/Terrarum/Actors/PBFSigrid.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid similarity index 97% rename from src/com/Torvald/Terrarum/Actors/PBFSigrid.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid index 2a6f5c4e3..197a1b9f8 100644 --- a/src/com/Torvald/Terrarum/Actors/PBFSigrid.java +++ b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid @@ -13,7 +13,7 @@ import java.io.IOException; /** * Created by minjaesong on 16-02-03. */ -public class PBFSigrid { +public class PFSigrid { private static String FACTION_PATH = "./res/raw/"; @@ -36,7 +36,6 @@ public class PBFSigrid { p.spriteGlow.setAsVisible(); p.spriteGlow.composeSprite(); - p.actorValue = new ActorValue(); p.actorValue.set("scale", 1.0f); p.actorValue.set("speed", 4.0f); @@ -66,7 +65,7 @@ public class PBFSigrid { p.setHitboxDimension(18, 46, 8, 0); - p.inventory = new ActorInventory(0x7FFFFFFF, true); + p.setInventory(new ActorInventory(0x7FFFFFFF, true)); p.setPosition(4096 * 16, 300 * 16); diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid$Companion.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid$Companion.class new file mode 100644 index 000000000..34119565f Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid$Companion.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid.class new file mode 100644 index 000000000..f781c509f Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PFSigrid.class differ diff --git a/src/com/Torvald/Terrarum/Actors/PhysTestBall.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PhysTestBall similarity index 100% rename from src/com/Torvald/Terrarum/Actors/PhysTestBall.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PhysTestBall diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PhysTestBall.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PhysTestBall.class index 527e33c48..deec5d57e 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PhysTestBall.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PhysTestBall.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Player.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player similarity index 98% rename from src/com/Torvald/Terrarum/Actors/Player.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player index 2785ac6ed..81db85bd4 100644 --- a/src/com/Torvald/Terrarum/Actors/Player.java +++ b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player @@ -522,16 +522,6 @@ public class Player extends ActorWithBody implements Controllable, Pocketed, Fac } } - @Override - public ActorInventory getInventory() { - return inventory; - } - - @Override - public void overwriteInventory(ActorInventory inventory) { - this.inventory = inventory; - } - public boolean isNoClip() { return noClip; } diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player$Companion.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player$Companion.class new file mode 100644 index 000000000..b7a735d7b Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player$Companion.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class index 8a30d4439..89aa3a295 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class differ diff --git a/src/com/Torvald/Terrarum/Actors/PlayerDebugger.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerDebugger similarity index 95% rename from src/com/Torvald/Terrarum/Actors/PlayerDebugger.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerDebugger index 123e08241..3999b080c 100644 --- a/src/com/Torvald/Terrarum/Actors/PlayerDebugger.java +++ b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerDebugger @@ -38,7 +38,7 @@ public class PlayerDebugger { public float scale() { return getPlayer().getScale(); } public Hitbox hitbox() { return getPlayer().getHitbox(); } public Hitbox nextHitbox() { return getPlayer().getNextHitbox(); } - public boolean grounded() { return getPlayer().isGrounded(); } + public boolean grounded() { return getPlayer().getGrounded(); } public ActorValue actorValue() { return getPlayer().getActorValue(); } public float mass() { return getPlayer().getMass(); } public boolean noClip() { return getPlayer().isNoClip(); } diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerDebugger.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerDebugger.class deleted file mode 100644 index 5fcbfb11c..000000000 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerDebugger.class and /dev/null differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerBuildFactory.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerFactory.class similarity index 57% rename from out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerBuildFactory.class rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerFactory.class index db2372411..441b72509 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerBuildFactory.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerFactory.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerKt.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerKt.class new file mode 100644 index 000000000..c8bb2e657 Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PlayerKt.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Pocketed.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Pocketed.class index 4be5bb35c..308d4fbe2 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Pocketed.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Pocketed.class differ diff --git a/src/com/Torvald/Terrarum/Actors/Visible.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Visible similarity index 100% rename from src/com/Torvald/Terrarum/Actors/Visible.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Visible diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Visible.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Visible.class index e797b856f..679e2f7a4 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Visible.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Visible.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class index f8cbcefe0..60b956d4e 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/ExportAV.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/ExportAV.class index ec3cf88a5..1d94091fa 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/ExportAV.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/ExportAV.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class index c27084b51..dd208e903 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class index 8030070ae..906e0e5b2 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.class index 4c8bc535f..670c5d6fa 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetLocale.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetLocale.class index 8c51aa24f..926768494 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetLocale.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/SetLocale.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/DefaultConfig.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/DefaultConfig.class new file mode 100644 index 000000000..d13b44dad Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/DefaultConfig.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class index 8739c8a87..a6d549486 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameControl/GameController.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameControl/GameController.class index c0e67f8c7..a1eeccd3d 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameControl/GameController.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameControl/GameController.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashMap.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashMap.class index 2812a4842..4cfae2146 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashMap.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashMap.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.class index ad27b36bb..257748749 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/MapCamera.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/MapCamera.class index 6fa4b2f78..e6c52b5c1 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/MapCamera.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapDrawer/MapCamera.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Terrarum.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Terrarum.class index 399016b58..1b42c9553 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Terrarum.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Terrarum.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TileNameCode.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TileNameCode.class index 1133f9e9a..5a50aba8a 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TileNameCode.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TileNameCode.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TilePropCodex.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TilePropCodex.class index 4556c3bb3..5f66a968d 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TilePropCodex.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/TilePropCodex.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/tileprop.csv b/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/tileprop.csv index b520a8bb3..cf3374aed 100644 --- a/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/tileprop.csv +++ b/out/production/Terrarum_renewed/com/Torvald/Terrarum/TileProperties/tileprop.csv @@ -60,13 +60,29 @@ "13"; "12";"TILE_ILLUMINATOR_GREY_LIGHT"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "47589"; "13"; "12"; "0";"16" "13"; "13";"TILE_ILLUMINATOR_GREY_MED"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "29538"; "13"; "13"; "0";"16" "13"; "14";"TILE_ILLUMINATOR_GREY_DARK"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "16410"; "13"; "14"; "0";"16" - "13"; "15";"TILE_ILLUMINATOR_BLACK" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "4923"; "13"; "15"; "0";"16" - "14"; "0";"TILE_SANDSTONE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "0"; "0";"16" - "14"; "1";"TILE_SANDSTONE_WHITE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "1"; "0";"16" - "14"; "2";"TILE_SANDSTONE_RED" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "2"; "0";"16" - "14"; "3";"TILE_SANDSTONE_DESERT" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "3"; "0";"16" - "14"; "4";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "4"; "0";"16" - "14"; "5";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "5"; "0";"16" + "13"; "15";"TILE_ILLUMINATOR_BLACK" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "27239"; "13"; "15"; "0";"16" + "14"; "0";"TILE_ILLUMINATOR_WHITE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "0"; "0";"16" + "14"; "1";"TILE_ILLUMINATOR_YELLOW" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "1"; "0";"16" + "14"; "2";"TILE_ILLUMINATOR_ORANGE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "2"; "0";"16" + "14"; "3";"TILE_ILLUMINATOR_RED" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "3"; "0";"16" + "14"; "4";"TILE_ILLUMINATOR_FUCHSIA" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "4"; "0";"16" + "14"; "5";"TILE_ILLUMINATOR_PURPLE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "5"; "0";"16" + "14"; "6";"TILE_ILLUMINATOR_BLUE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "6"; "0";"16" + "14"; "7";"TILE_ILLUMINATOR_CYAN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "7"; "0";"16" + "14"; "8";"TILE_ILLUMINATOR_GREEN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "8"; "0";"16" + "14"; "9";"TILE_ILLUMINATOR_GREEN_DARK"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "9"; "0";"16" + "14"; "10";"TILE_ILLUMINATOR_BROWN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "10"; "0";"16" + "14"; "11";"TILE_ILLUMINATOR_TAN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "11"; "0";"16" + "14"; "12";"TILE_ILLUMINATOR_GREY_LIGHT"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "12"; "0";"16" + "14"; "13";"TILE_ILLUMINATOR_GREY_MED"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "13"; "0";"16" + "14"; "14";"TILE_ILLUMINATOR_GREY_DARK"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "14"; "0";"16" + "14"; "15";"TILE_ILLUMINATOR_BLACK" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "15"; "0";"16" + "15"; "0";"TILE_SANDSTONE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "0"; "0";"16" + "15"; "1";"TILE_SANDSTONE_WHITE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "1"; "0";"16" + "15"; "2";"TILE_SANDSTONE_RED" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "2"; "0";"16" + "15"; "3";"TILE_SANDSTONE_DESERT" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "3"; "0";"16" + "15"; "4";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "4"; "0";"16" + "15"; "5";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "5"; "0";"16" "254"; "0";"TILE_WATER" ; "6522"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16" "254"; "1";"TILE_WATER" ; "6522"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16" "254"; "2";"TILE_WATER" ; "6522"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16" @@ -111,6 +127,8 @@ # Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess. +# Off illuminator: NO OPACITY! this is intended! + # References: # * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html # * Density of various phases of ice : http://www1.lsbu.ac.uk/water/ice_phases.html \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow similarity index 100% rename from src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.class index dba1b230d..2aa28ed5d 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Bulletin.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Bulletin.class deleted file mode 100644 index c210221c5..000000000 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Bulletin.class and /dev/null differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/ConsoleWindow.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/ConsoleWindow.class index 4e7f6c4ab..82bd85c96 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/ConsoleWindow.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/ConsoleWindow.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Message.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Message.class index 03a6e6ea1..e0af42bd1 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Message.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Message.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Notification.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Notification.class new file mode 100644 index 000000000..3468710e0 Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/Notification.class differ diff --git a/src/com/Torvald/Terrarum/UserInterface/UICanvas.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UICanvas similarity index 100% rename from src/com/Torvald/Terrarum/UserInterface/UICanvas.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UICanvas diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UICanvas.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UICanvas.class index 8d6805d77..8fc3f3388 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UICanvas.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UICanvas.class differ diff --git a/src/com/Torvald/Terrarum/UserInterface/UIClickable.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIClickable similarity index 100% rename from src/com/Torvald/Terrarum/UserInterface/UIClickable.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIClickable diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIClickable.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIClickable.class index edf6a15ed..ae8c04c28 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIClickable.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIClickable.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIHandler.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIHandler.class index f8d7f7367..255355215 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIHandler.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UIHandler.class differ diff --git a/src/com/Torvald/Terrarum/UserInterface/UITypable.java b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UITypable similarity index 100% rename from src/com/Torvald/Terrarum/UserInterface/UITypable.java rename to out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UITypable diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UITypable.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UITypable.class index 80a36f76b..d58fa4ada 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UITypable.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/UserInterface/UITypable.class differ diff --git a/out/production/Terrarum_renewed/com/jme3/math/FastMath.class b/out/production/Terrarum_renewed/com/jme3/math/FastMath.class index 3f5728389..587ff433b 100644 Binary files a/out/production/Terrarum_renewed/com/jme3/math/FastMath.class and b/out/production/Terrarum_renewed/com/jme3/math/FastMath.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/Joise.class b/out/production/Terrarum_renewed/com/sudoplay/joise/Joise.class new file mode 100644 index 000000000..4a76eeee8 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/Joise.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/JoiseException.class b/out/production/Terrarum_renewed/com/sudoplay/joise/JoiseException.class new file mode 100644 index 000000000..ed7d64d00 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/JoiseException.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/ModuleInstanceMap.class b/out/production/Terrarum_renewed/com/sudoplay/joise/ModuleInstanceMap.class new file mode 100644 index 000000000..d2868defc Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/ModuleInstanceMap.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/ModuleMap.class b/out/production/Terrarum_renewed/com/sudoplay/joise/ModuleMap.class new file mode 100644 index 000000000..90edd36a8 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/ModuleMap.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/ModulePropertyMap.class b/out/production/Terrarum_renewed/com/sudoplay/joise/ModulePropertyMap.class new file mode 100644 index 000000000..2190f4c5e Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/ModulePropertyMap.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/generator/BasePRNG.class b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/BasePRNG.class new file mode 100644 index 000000000..dedf4c473 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/BasePRNG.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/generator/CMWC4096.class b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/CMWC4096.class new file mode 100644 index 000000000..a4306c2f6 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/CMWC4096.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/generator/KISS.class b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/KISS.class new file mode 100644 index 000000000..1bb6323a2 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/KISS.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/generator/LCG.class b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/LCG.class new file mode 100644 index 000000000..f1c00e371 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/LCG.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/generator/MWC.class b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/MWC.class new file mode 100644 index 000000000..9f3c9c0cb Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/MWC.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/generator/MWC256.class b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/MWC256.class new file mode 100644 index 000000000..48cd869b4 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/MWC256.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/generator/XORShift.class b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/XORShift.class new file mode 100644 index 000000000..389729ea1 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/generator/XORShift.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array2Double.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array2Double.class new file mode 100644 index 000000000..c10654dd8 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array2Double.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array2DoubleWriter.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array2DoubleWriter.class new file mode 100644 index 000000000..78273f636 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array2DoubleWriter.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array3Double.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array3Double.class new file mode 100644 index 000000000..b91efc3c5 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array3Double.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array3DoubleWriter.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array3DoubleWriter.class new file mode 100644 index 000000000..9b514deb4 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Array3DoubleWriter.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping$1.class new file mode 100644 index 000000000..40e8022de Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping.class new file mode 100644 index 000000000..586cac35c Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping2DWriter$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping2DWriter$1.class new file mode 100644 index 000000000..bd38e37b0 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping2DWriter$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping2DWriter.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping2DWriter.class new file mode 100644 index 000000000..f96461779 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping2DWriter.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping3DWriter$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping3DWriter$1.class new file mode 100644 index 000000000..6aa2be9eb Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping3DWriter$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping3DWriter.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping3DWriter.class new file mode 100644 index 000000000..5943baf3b Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/Mapping3DWriter.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingMode.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingMode.class new file mode 100644 index 000000000..3c9543940 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingMode.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingRange.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingRange.class new file mode 100644 index 000000000..0b6f189b6 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingRange.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingUpdateListener$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingUpdateListener$1.class new file mode 100644 index 000000000..b67d557b7 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingUpdateListener$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingUpdateListener.class b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingUpdateListener.class new file mode 100644 index 000000000..0a9bbb7f1 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/mapping/MappingUpdateListener.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/Module.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/Module.class new file mode 100644 index 000000000..d5fa3d7a5 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/Module.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleAbs.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleAbs.class new file mode 100644 index 000000000..1286273c0 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleAbs.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleAutoCorrect.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleAutoCorrect.class new file mode 100644 index 000000000..631cf0858 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleAutoCorrect.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$1.class new file mode 100644 index 000000000..a58672d48 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$BasisType.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$BasisType.class new file mode 100644 index 000000000..786515c15 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$BasisType.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$InterpolationType.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$InterpolationType.class new file mode 100644 index 000000000..a2d61b2e0 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction$InterpolationType.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction.class new file mode 100644 index 000000000..0bcc803a5 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBasisFunction.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBias.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBias.class new file mode 100644 index 000000000..f90e4598a Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBias.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBlend.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBlend.class new file mode 100644 index 000000000..83fcce078 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBlend.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBrightContrast.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBrightContrast.class new file mode 100644 index 000000000..a1c8d9687 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleBrightContrast.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCache$Cache.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCache$Cache.class new file mode 100644 index 000000000..e8ed2d1f1 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCache$Cache.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCache.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCache.class new file mode 100644 index 000000000..158561200 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCache.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellGen$CellularCache.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellGen$CellularCache.class new file mode 100644 index 000000000..56da129b6 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellGen$CellularCache.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellGen.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellGen.class new file mode 100644 index 000000000..969eff838 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellGen.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellular.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellular.class new file mode 100644 index 000000000..ebaddf104 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCellular.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleClamp.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleClamp.class new file mode 100644 index 000000000..836abea45 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleClamp.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner$1.class new file mode 100644 index 000000000..fcfbb9c27 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner$CombinerType.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner$CombinerType.class new file mode 100644 index 000000000..fa1245321 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner$CombinerType.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner.class new file mode 100644 index 000000000..6fb1f7b7b Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCombiner.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCos.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCos.class new file mode 100644 index 000000000..bf88f76f8 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleCos.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFloor.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFloor.class new file mode 100644 index 000000000..b3e5231ce Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFloor.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal$1.class new file mode 100644 index 000000000..c43da4393 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal$FractalType.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal$FractalType.class new file mode 100644 index 000000000..24a7f8f63 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal$FractalType.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal.class new file mode 100644 index 000000000..20908a383 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFractal.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient$1.class new file mode 100644 index 000000000..490d8dd6d Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient$FunctionGradientAxis.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient$FunctionGradientAxis.class new file mode 100644 index 000000000..b6350a3ff Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient$FunctionGradientAxis.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient.class new file mode 100644 index 000000000..498e979ca Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleFunctionGradient.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleGain.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleGain.class new file mode 100644 index 000000000..35d9f052a Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleGain.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleGradient.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleGradient.class new file mode 100644 index 000000000..3dde884f1 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleGradient.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleInvert.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleInvert.class new file mode 100644 index 000000000..d64d4fda2 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleInvert.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleMagnitude.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleMagnitude.class new file mode 100644 index 000000000..7d43420ad Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleMagnitude.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleNormalizedCoords.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleNormalizedCoords.class new file mode 100644 index 000000000..a89247825 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleNormalizedCoords.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModulePow.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModulePow.class new file mode 100644 index 000000000..6f94aa6a5 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModulePow.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleRotateDomain.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleRotateDomain.class new file mode 100644 index 000000000..13b3d79fe Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleRotateDomain.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSawtooth.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSawtooth.class new file mode 100644 index 000000000..597b201ea Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSawtooth.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleScaleDomain.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleScaleDomain.class new file mode 100644 index 000000000..d8b292347 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleScaleDomain.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleScaleOffset.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleScaleOffset.class new file mode 100644 index 000000000..1649a939b Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleScaleOffset.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSelect.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSelect.class new file mode 100644 index 000000000..d04374089 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSelect.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSin.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSin.class new file mode 100644 index 000000000..25dea0243 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSin.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSphere.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSphere.class new file mode 100644 index 000000000..6c70d7958 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleSphere.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTiers.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTiers.class new file mode 100644 index 000000000..c382a8e97 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTiers.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTranslateDomain.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTranslateDomain.class new file mode 100644 index 000000000..c9bda690b Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTranslateDomain.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTriangle.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTriangle.class new file mode 100644 index 000000000..e7f3d8cfe Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ModuleTriangle.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/ScalarParameter.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ScalarParameter.class new file mode 100644 index 000000000..d9a5d28dd Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/ScalarParameter.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/SeedableModule.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/SeedableModule.class new file mode 100644 index 000000000..7e5532173 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/SeedableModule.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/module/SourcedModule.class b/out/production/Terrarum_renewed/com/sudoplay/joise/module/SourcedModule.class new file mode 100644 index 000000000..c1618d0b4 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/module/SourcedModule.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$1.class new file mode 100644 index 000000000..0843a7469 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$2.class new file mode 100644 index 000000000..384c65a6b Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$3.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$3.class new file mode 100644 index 000000000..996538263 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$3.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$4.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$4.class new file mode 100644 index 000000000..ac6ce830c Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator$4.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator.class new file mode 100644 index 000000000..30e1db0c3 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Interpolator.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$1.class new file mode 100644 index 000000000..942588380 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$2.class new file mode 100644 index 000000000..77cb9da39 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$3.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$3.class new file mode 100644 index 000000000..df2940396 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$3.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$4.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$4.class new file mode 100644 index 000000000..aa547c890 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$4.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$5.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$5.class new file mode 100644 index 000000000..ed2646c04 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$5.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$6.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$6.class new file mode 100644 index 000000000..e19686377 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$6.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$1.class new file mode 100644 index 000000000..a24ec7e4c Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$2.class new file mode 100644 index 000000000..4cb2dcdf9 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$3.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$3.class new file mode 100644 index 000000000..bb7b2d222 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$3.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$4.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$4.class new file mode 100644 index 000000000..cb33bdef0 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$4.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$5.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$5.class new file mode 100644 index 000000000..1a06de70b Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D$5.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D.class new file mode 100644 index 000000000..5f1f8ce7c Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function2D.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$1.class new file mode 100644 index 000000000..a41a118bb Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$2.class new file mode 100644 index 000000000..4360efa8c Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$3.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$3.class new file mode 100644 index 000000000..c2900a294 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$3.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$4.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$4.class new file mode 100644 index 000000000..80108c617 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$4.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$5.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$5.class new file mode 100644 index 000000000..408f1ede9 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D$5.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D.class new file mode 100644 index 000000000..e6d1072ed Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function3D.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$1.class new file mode 100644 index 000000000..c0165ddaf Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$2.class new file mode 100644 index 000000000..535b4bffe Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$3.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$3.class new file mode 100644 index 000000000..c0f73e4f1 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$3.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$4.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$4.class new file mode 100644 index 000000000..a8a534714 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$4.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$5.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$5.class new file mode 100644 index 000000000..0df3cf8d2 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D$5.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D.class new file mode 100644 index 000000000..c03ba4fb4 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function4D.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$1.class new file mode 100644 index 000000000..420c6a935 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$2.class new file mode 100644 index 000000000..417771b79 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$3.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$3.class new file mode 100644 index 000000000..0333c6072 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$3.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$4.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$4.class new file mode 100644 index 000000000..3610211f4 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$4.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$5.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$5.class new file mode 100644 index 000000000..6f28f2211 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D$5.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D.class new file mode 100644 index 000000000..e12a4397f Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$Function6D.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$SVectorOrdering.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$SVectorOrdering.class new file mode 100644 index 000000000..5b43af2b1 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$SVectorOrdering.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2$1.class new file mode 100644 index 000000000..514543aa5 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2$2.class new file mode 100644 index 000000000..1f704827c Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2.class new file mode 100644 index 000000000..e9e5e59de Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3$1.class new file mode 100644 index 000000000..d674de942 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3$2.class new file mode 100644 index 000000000..2013afbbf Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3.class new file mode 100644 index 000000000..a49cc7f6f Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise3.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4$1.class new file mode 100644 index 000000000..371de2578 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4$2.class new file mode 100644 index 000000000..00b4417de Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4.class new file mode 100644 index 000000000..e6bf1008d Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise4.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6$1.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6$1.class new file mode 100644 index 000000000..81938b8a7 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6$1.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6$2.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6$2.class new file mode 100644 index 000000000..00778dea4 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6$2.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6.class new file mode 100644 index 000000000..2b241626e Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise$WorkerNoise6.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise.class new file mode 100644 index 000000000..6d9b07081 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Noise.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/NoiseLUT.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/NoiseLUT.class new file mode 100644 index 000000000..451efd5ca Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/NoiseLUT.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Util$Vector3d.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Util$Vector3d.class new file mode 100644 index 000000000..be0c4aaa7 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Util$Vector3d.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Util.class b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Util.class new file mode 100644 index 000000000..0b94f7e64 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/joise/noise/Util.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/util/Assert.class b/out/production/Terrarum_renewed/com/sudoplay/util/Assert.class new file mode 100644 index 000000000..a0bce8220 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/util/Assert.class differ diff --git a/out/production/Terrarum_renewed/com/sudoplay/util/Checked.class b/out/production/Terrarum_renewed/com/sudoplay/util/Checked.class new file mode 100644 index 000000000..45efe87c5 Binary files /dev/null and b/out/production/Terrarum_renewed/com/sudoplay/util/Checked.class differ diff --git a/res/config_default.json b/res/config_default.json deleted file mode 100644 index 6ff8410b6..000000000 --- a/res/config_default.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "smoothlighting" : true, - "imtooyoungtodie" : false, - "language" : "enUS" -} \ No newline at end of file diff --git a/res/graphics/terrain/terrain.png b/res/graphics/terrain/terrain.png index 26185dcaf..7a09cbfa5 100644 Binary files a/res/graphics/terrain/terrain.png and b/res/graphics/terrain/terrain.png differ diff --git a/src/com/Torvald/ImageFont/GameFontBase.java b/src/com/Torvald/ImageFont/GameFontBase.java index 8e306f2b0..3c2e57ceb 100644 --- a/src/com/Torvald/ImageFont/GameFontBase.java +++ b/src/com/Torvald/ImageFont/GameFontBase.java @@ -288,7 +288,7 @@ public class GameFontBase implements Font { } private int wenQuanYi1IndexY(char c) { - return (c - (c <= 0x4DB5 ? 0x33F3 : 0x33F3 + 0x4A)) / 32; + return (c - (0x33F3 + 0x4A)) / 32; } private int wenQuanYi2IndexY(char c) { @@ -358,24 +358,6 @@ public class GameFontBase implements Font { public void drawString(float x, float y, String s, Color color) { // hangul fonts first hangulSheet.startUse(); - // WANSEONG - /*for (int i = 0; i < s.length(); i++) { - char ch = s.charAt(i); - - if (isHangul(ch)) { - int[] hanPos = getHan(ch - 0xAC00); - int glyphW = getWidth("" + ch); - hangulSheet.renderInUse( - Math.round(x - + getWidthSubstr(s, i + 1) - glyphW - ) - , Math.round((H - H_HANGUL) / 2 + y + 1) - , hanPos[0] - , hanPos[1] - ); - } - }*/ - // JOHAB for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); @@ -456,7 +438,7 @@ public class GameFontBase implements Font { Math.round(x + getWidthSubstr(s, i + 1) - glyphW ) - , Math.round((H - H_UNIHAN) / 2 + y) + , Math.round((H - H_UNIHAN) / 2 + y - 1) , wenQuanYiIndexX(ch) , wenQuanYi1IndexY(ch) ); @@ -475,7 +457,7 @@ public class GameFontBase implements Font { Math.round(x + getWidthSubstr(s, i + 1) - glyphW ) - , Math.round((H - H_UNIHAN) / 2 + y) + , Math.round((H - H_UNIHAN) / 2 + y - 1) , wenQuanYiIndexX(ch) , wenQuanYi2IndexY(ch) ); diff --git a/src/com/Torvald/ImageFont/GameFontBlack.java b/src/com/Torvald/ImageFont/GameFontBlack.java deleted file mode 100644 index 14a964a32..000000000 --- a/src/com/Torvald/ImageFont/GameFontBlack.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.Torvald.ImageFont; - -import org.newdawn.slick.SlickException; -import org.newdawn.slick.SpriteSheet; - -/** - * Created by minjaesong on 16-01-27. - */ -public class GameFontBlack extends GameFontBase { - - public GameFontBlack() throws SlickException { - super(); - - hangulSheet = new SpriteSheet( - "./res/graphics/fonts/han_johab_black.png" - , W_CJK, H_HANGUL - ); - asciiSheet = new SpriteSheet( - "./res/graphics/fonts/ascii_majuscule_black.png" - , W_LATIN_WIDE, H - ); - asciiSheetEF = new SpriteSheet( - "./res/graphics/fonts/ascii_special_ef_black.png" - , W_LATIN_NARROW, H - ); - runicSheet = new SpriteSheet( - "./res/graphics/fonts/futhark_black.png" - , W_LATIN_WIDE, H - ); - extASheet = new SpriteSheet( - "./res/graphics/fonts/LatinExtA_majuscule_black.png" - , W_LATIN_WIDE, H - ); - extASheetEF = new SpriteSheet( - "./res/graphics/fonts/LatinExtA_ef_black.png" - , W_LATIN_NARROW, H - ); - - SpriteSheet[] shk = { - asciiSheet - , asciiSheetEF - , hangulSheet - , runicSheet - , extASheet - , extASheetEF - }; - sheetKey = shk; - } -} diff --git a/src/com/Torvald/JsonWriter.java b/src/com/Torvald/JsonWriter.java index 3b615a4a6..a580938ff 100644 --- a/src/com/Torvald/JsonWriter.java +++ b/src/com/Torvald/JsonWriter.java @@ -2,6 +2,7 @@ package com.Torvald; import com.google.gson.Gson; import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import java.io.FileWriter; import java.io.IOException; @@ -11,7 +12,7 @@ import java.io.IOException; */ public class JsonWriter { - public static void writeFile(Object c, String path) throws IOException { + public static void writeToFile(Object c, String path) throws IOException { JsonElement classElem = new Gson().toJsonTree(c); String jsonString = classElem.toString(); FileWriter writer = new FileWriter(path); @@ -19,4 +20,10 @@ public class JsonWriter { writer.close(); } + public static void writeToFile(JsonObject jsonObject, String path) throws IOException { + FileWriter writer = new FileWriter(path); + writer.write(jsonObject.toString()); + writer.close(); + } + } diff --git a/src/com/Torvald/Terrarum/Actors/AI/ActorAI.java b/src/com/Torvald/Terrarum/Actors/AI/ActorAI.java deleted file mode 100644 index a9fed8b0d..000000000 --- a/src/com/Torvald/Terrarum/Actors/AI/ActorAI.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.Torvald.Terrarum.Actors.AI; - -/** - * Created by minjaesong on 16-03-02. - */ -public interface ActorAI { -} diff --git a/src/com/Torvald/Terrarum/Actors/AI/ActorAI.kt b/src/com/Torvald/Terrarum/Actors/AI/ActorAI.kt new file mode 100644 index 000000000..952a1b735 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/AI/ActorAI.kt @@ -0,0 +1,7 @@ +package com.Torvald.Terrarum.Actors.AI + +/** + * Created by minjaesong on 16-03-14. + */ +interface ActorAI { +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/AIControlled.java b/src/com/Torvald/Terrarum/Actors/AIControlled.java deleted file mode 100644 index aeda95cc8..000000000 --- a/src/com/Torvald/Terrarum/Actors/AIControlled.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.Torvald.Terrarum.Actors; - -import com.Torvald.Terrarum.Actors.AI.ActorAI; - -/** - * Created by minjaesong on 16-01-31. - */ -public interface AIControlled { - - void attachAI(ActorAI ai); - -} diff --git a/src/com/Torvald/Terrarum/Actors/AIControlled.kt b/src/com/Torvald/Terrarum/Actors/AIControlled.kt new file mode 100644 index 000000000..82729002a --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/AIControlled.kt @@ -0,0 +1,10 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.Terrarum.Actors.AI.ActorAI + +/** + * Created by minjaesong on 16-03-14. + */ +interface AIControlled { + fun attachAI(ai: ActorAI) +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/Actor b/src/com/Torvald/Terrarum/Actors/Actor new file mode 100644 index 000000000..54a60be02 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Actor @@ -0,0 +1,18 @@ +package com.Torvald.Terrarum.Actors; + +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; + +/** + * Created by minjaesong on 15-12-31. + */ +public interface Actor { + + void update(GameContainer gc, int delta_t); + + /** + * Valid RefID is equal to or greater than 32768. + * @return Reference ID. (32768-0x7FFF_FFFF_FFFF_FFFF) + */ + long getRefID(); +} diff --git a/src/com/Torvald/Terrarum/Actors/Actor.kt b/src/com/Torvald/Terrarum/Actors/Actor.kt new file mode 100644 index 000000000..5e2b2325c --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Actor.kt @@ -0,0 +1,17 @@ +package com.Torvald.Terrarum.Actors + +import org.newdawn.slick.GameContainer + +/** + * Created by minjaesong on 16-03-14. + */ +interface Actor { + + fun update(gc: GameContainer, delta_t: Int) + + /** + * Valid RefID is equal to or greater than 32768. + * @return Reference ID. (32768-0x7FFF_FFFF_FFFF_FFFF) + */ + var referenceID: Long? +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/ActorWithBody b/src/com/Torvald/Terrarum/Actors/ActorWithBody new file mode 100644 index 000000000..c9e1cb980 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/ActorWithBody @@ -0,0 +1,1002 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.Rand.HQRNG; +import com.Torvald.Terrarum.*; +import com.Torvald.Terrarum.GameMap.GameMap; +import com.Torvald.Terrarum.MapDrawer.MapDrawer; +import com.Torvald.Terrarum.NotNull; +import com.Torvald.Terrarum.Nullable; +import com.Torvald.Terrarum.TileProperties.TilePropCodex; +import com.Torvald.spriteAnimation.SpriteAnimation; +import com.jme3.math.FastMath; +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; + +/** + * Created by minjaesong on 16-01-13. + */ +public class ActorWithBody implements Actor, Visible, Glowing { + + ActorValue actorValue; + + ActorInventory inventory; + + private @NotNull float hitboxTranslateX; // relative to spritePosX + private @NotNull float hitboxTranslateY; // relative to spritePosY + private @NotNull int baseHitboxW; + private @NotNull int baseHitboxH; + + /** + * Velocity for newtonian sim. + * Fluctuation in, otherwise still, velocity is equal to acceleration. + * + * Acceleration: used in code like: + * veloY += 3.0 + * +3.0 is acceleration. You __accumulate__ acceleration to the velocity. + */ + private volatile @NotNull float veloX, veloY; + private transient final float VELO_HARD_LIMIT = 10000; + + boolean grounded = false; + + transient @Nullable SpriteAnimation sprite; + transient @Nullable SpriteAnimation spriteGlow; + /** Default to 'false' */ + private boolean visible = false; + /** Default to 'true' */ + private boolean update = true; + + private boolean noSubjectToGrav = false; + private boolean noCollideWorld = false; + private boolean noSubjectToFluidResistance = false; + + int baseSpriteWidth, baseSpriteHeight; + + /** + * Positions: top-left point + */ + private volatile @NotNull Hitbox hitbox; + private volatile transient @NotNull Hitbox nextHitbox; + + /** + * Physical properties + */ + private volatile transient @NonZero float scale = 1; + private volatile transient @NonZero float mass = 2f; + private transient final float MASS_LOWEST = 2f; + /** Valid range: [0, 1] */ + private float elasticity = 0; + private transient final float ELASTICITY_MAX = 0.993f; + private @NoNegative float density = 1000; + + private static transient final int TSIZE = MapDrawer.TILE_SIZE; + private static int AUTO_CLIMB_RATE = TSIZE / 8; + + /** + * Gravitational Constant G. Load from GameMap. + * [m / s^2] + * s^2 = 1/FPS = 1/60 if FPS is targeted to 60 + * meter to pixel : 24/FPS + */ + private transient final float METER = 24f; + /** + * [m / s^2] * SI_TO_GAME_ACC -> [px / IFrame^2] + */ + private transient final float SI_TO_GAME_ACC = METER / FastMath.sqr(Terrarum.TARGET_FPS); + /** + * [m / s] * SI_TO_GAME_VEL -> [px / IFrame] + */ + private transient final float SI_TO_GAME_VEL = METER / Terrarum.TARGET_FPS; + + private transient float gravitation; + private transient final float DRAG_COEFF = 1f; + + private transient final int CONTACT_AREA_TOP = 0; + private transient final int CONTACT_AREA_RIGHT = 1; + private transient final int CONTACT_AREA_BOTTOM = 2; + private transient final int CONTACT_AREA_LEFT = 3; + + private transient final int UD_COMPENSATOR_MAX = TSIZE; + private transient final int LR_COMPENSATOR_MAX = TSIZE; + private transient final int TILE_AUTOCLIMB_RATE = 4; + + /** + * A constant to make falling faster so that the game is more playable + */ + private transient final float G_MUL_PLAYABLE_CONST = 1.4142f; + + long referenceID; + + private transient final int EVENT_MOVE_TOP = 0; + private transient final int EVENT_MOVE_RIGHT = 1; + private transient final int EVENT_MOVE_BOTTOM = 2; + private transient final int EVENT_MOVE_LEFT = 3; + private transient final int EVENT_MOVE_NONE = -1; + + transient int eventMoving = EVENT_MOVE_NONE; // cannot collide both X-axis and Y-axis, or else jump control breaks up. + + /** + * in milliseconds + */ + public transient final int INVINCIBILITY_TIME = 500; + + /** + * Will ignore fluid resistance if (submerged height / actor height) <= this var + */ + private transient final float FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO = 0.2f; + private transient final float FLUID_RESISTANCE_APPLY_FULL_RATIO = 0.5f; + + private transient GameMap map; + + /** + * Give new random ReferenceID and initialise ActorValue + */ + public ActorWithBody() { + referenceID = new HQRNG().nextLong(); + actorValue = new ActorValue(); + map = Terrarum.game.map; + } + + /** + * + * @param w + * @param h + * @param tx +: translate drawn sprite to LEFT. + * @param ty +: translate drawn sprite to DOWN. + * @see ActorWithBody#drawBody(GameContainer, Graphics) + * @see ActorWithBody#drawGlow(GameContainer, Graphics) + */ + public void setHitboxDimension(int w, int h, int tx, int ty) { + baseHitboxH = h; + baseHitboxW = w; + hitboxTranslateX = tx; + hitboxTranslateY = ty; + } + + /** + * Set hitbox position from bottom-center point + * @param x + * @param y + */ + public void setPosition(float x, float y) { + hitbox = new Hitbox( + x - ((baseHitboxW / 2) - hitboxTranslateX) * scale + , y - (baseHitboxH - hitboxTranslateY) * scale + , baseHitboxW * scale + , baseHitboxH * scale + ); + + nextHitbox = new Hitbox( + x - ((baseHitboxW / 2) - hitboxTranslateX) * scale + , y - (baseHitboxH - hitboxTranslateY) * scale + , baseHitboxW * scale + , baseHitboxH * scale + ); + } + + public void setSprite(SpriteAnimation sprite) {this.sprite = sprite; } + + public void setSpriteGlow(SpriteAnimation sprite) { this.spriteGlow = sprite; } + + public void update(GameContainer gc, int delta_t) { + if (update) { + /** + * Update variables + */ + if (this instanceof Player) { + noSubjectToGrav = isPlayerNoClip(); + noCollideWorld = isPlayerNoClip(); + noSubjectToFluidResistance = isPlayerNoClip(); + } + + if (mass < MASS_LOWEST) mass = MASS_LOWEST; // clamp to minimum possible mass + if (sprite != null) { + baseSpriteHeight = sprite.getHeight(); + baseSpriteWidth = sprite.getWidth(); + } + gravitation = map.getGravitation(); + AUTO_CLIMB_RATE = (int) Math.min(TSIZE / 8 * FastMath.sqrt(scale), TSIZE); + + if (!isNoSubjectToGrav()) { + applyGravitation(); + applyBuoyancy(); + } + + // hard limit velocity + if (veloX > VELO_HARD_LIMIT) veloX = VELO_HARD_LIMIT; + if (veloY > VELO_HARD_LIMIT) veloY = VELO_HARD_LIMIT; + // limit velocity by fluid resistance + //int tilePropResistance = getTileMvmtRstc(); + //if (!noSubjectToFluidResistance) { + // veloX *= mvmtRstcToMultiplier(tilePropResistance); + // veloY *= mvmtRstcToMultiplier(tilePropResistance); + //} + + + // Set 'next' positions to fiddle with + updateNextHitboxFromVelo(); + + + // if not horizontally moving then ... + //if (Math.abs(veloX) < 0.5) { // fix for special situations (see fig. 1 at the bottom of the source) + // updateVerticalPos(); + // updateHorizontalPos(); + //} + //else { + updateHorizontalPos(); + updateVerticalPos(); + //} + + + updateHitboxX(); + updateHitboxY(); + + + clampNextHitbox(); + clampHitbox(); + } + } + + /** + * Apply gravitation to the every falling body (unless not levitating) + * + * Apply only if not grounded; normal force is not implemented (and redundant) + * so we manually reset G to zero (not applying G. force) if grounded. + */ + // FIXME abnormal jump behaviour if mass < 2, same thing happens if mass == 0 (but zero mass is invalid anyway). + private void applyGravitation() { + if (!getGrounded()) { + /** + * weight; gravitational force in action + * W = mass * G (9.8 [m/s^2]) + */ + float W = gravitation * mass; + /** + * Drag of atmosphere + * D = Cd (drag coefficient) * 0.5 * rho (density) * V^2 (velocity) * A (area) + */ + float A = scale * scale; + float D = DRAG_COEFF * 0.5f * 1.292f * veloY * veloY * A; + + int fluidResistance = getTileMvmtRstc(); + + veloY += clampCeil( + ((W - D) / mass) * SI_TO_GAME_ACC * G_MUL_PLAYABLE_CONST + // * mvmtRstcToMultiplier(fluidResistance) // eliminate shoot-up from fluids + , VELO_HARD_LIMIT + ); + } + } + + private void updateVerticalPos() { + if (!isNoCollideWorld()) { + // check downward + if (veloY >= 0) { + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_BOTTOM)) { + adjustHitBottom(); + elasticReflectY(); + grounded = true; + } + else if (isColliding(CONTACT_AREA_BOTTOM, 0, 1)) { + elasticReflectY(); + grounded = true; + } + else { + grounded = false; + } + } + else if (veloY < 0) { + grounded = false; + + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_TOP)) { + adjustHitTop(); + elasticReflectY(); + } + else if (isColliding(CONTACT_AREA_TOP, 0, -1)) { + elasticReflectY(); // for reversed gravity + } + else { + } + } + } + } + + private void adjustHitBottom() { + float newX = nextHitbox.getPointedX(); // look carefully, getPos or getPointed + // int-ify posY of nextHitbox + nextHitbox.setPositionYFromPoint( FastMath.floor(nextHitbox.getPointedY()) ); + + int newYOff = 0; // always positive + + boolean colliding; + do { + newYOff += 1; + colliding = isColliding(CONTACT_AREA_BOTTOM, 0, -newYOff); + } while (colliding); + + float newY = nextHitbox.getPointedY() - newYOff; + nextHitbox.setPositionFromPoint(newX, newY); + } + + private void adjustHitTop() { + float newX = nextHitbox.getPosX(); + // int-ify posY of nextHitbox + nextHitbox.setPositionY( FastMath.ceil(nextHitbox.getPosY()) ); + + int newYOff = 0; // always positive + + boolean colliding; + do { + newYOff += 1; + colliding = isColliding(CONTACT_AREA_TOP, 0, newYOff); + } while (colliding); + + float newY = nextHitbox.getPosY() + newYOff; + nextHitbox.setPosition(newX, newY); + } + + private void updateHorizontalPos() { + if (!isNoCollideWorld()) { + // check right + if (veloX >= 0.5) { + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_RIGHT) && !isColliding(CONTACT_AREA_LEFT)) { + adjustHitRight(); + elasticReflectX(); + } + else if (isColliding(CONTACT_AREA_RIGHT, 1, 0) + && !isColliding(CONTACT_AREA_LEFT, -1, 0)) { + elasticReflectX(); + } + else { + } + } + else if (veloX <= -0.5) { + // System.out.println("collidingleft"); + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_LEFT) && !isColliding(CONTACT_AREA_RIGHT)) { + adjustHitLeft(); + elasticReflectX(); + } + else if (isColliding(CONTACT_AREA_LEFT, -1, 0) + && !isColliding(CONTACT_AREA_RIGHT, 1, 0)) { + elasticReflectX(); + } + else { + } + } + else { + // System.out.println("updatehorizontal - |velo| < 0.5"); + if (isColliding(CONTACT_AREA_LEFT) || isColliding(CONTACT_AREA_RIGHT)) { + elasticReflectX(); + } + } + } + } + + private void adjustHitRight() { + float newY = nextHitbox.getPosY(); // look carefully, getPos or getPointed + // int-ify posY of nextHitbox + nextHitbox.setPositionX( FastMath.floor(nextHitbox.getPosX() + nextHitbox.getWidth()) + - nextHitbox.getWidth() + ); + + int newXOff = 0; // always positive + + boolean colliding; + do { + newXOff += 1; + colliding = isColliding(CONTACT_AREA_BOTTOM, -newXOff, 0); + } while (newXOff < TSIZE && colliding); + + float newX = nextHitbox.getPosX() - newXOff; + nextHitbox.setPosition(newX, newY); + } + + private void adjustHitLeft() { + float newY = nextHitbox.getPosY(); + // int-ify posY of nextHitbox + nextHitbox.setPositionX( FastMath.ceil(nextHitbox.getPosX()) ); + + int newXOff = 0; // always positive + + boolean colliding; + do { + newXOff += 1; + colliding = isColliding(CONTACT_AREA_TOP, newXOff, 0); + } while (newXOff < TSIZE && colliding); + + float newX = nextHitbox.getPosX() + newXOff; + nextHitbox.setPosition(newX, newY); // + 1; float-point rounding compensation (i think...) + } + + private void elasticReflectX() { + if (veloX != 0) veloX = -veloX * elasticity; + } + + private void elasticReflectY() { + if (veloY != 0) veloY = -veloY * elasticity; + } + + private boolean isColliding(int side) { + return isColliding(side, 0, 0); + } + + private boolean isColliding(int side, int tx, int ty) { + return getContactingArea(side, tx, ty) > 1; + } + + private int getContactingArea(int side) { + return getContactingArea(side, 0, 0); + } + + private int getContactingArea(int side, int translateX, int translateY) { + int contactAreaCounter = 0; + for (int i = 0 + ; i < Math.round((side % 2 == 0) ? nextHitbox.getWidth() : nextHitbox.getHeight()) + ; i++) { + // set tile positions + int tileX, tileY; + /*if (side == CONTACT_AREA_BOTTOM) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX()) + + i + translateX); + tileY = div16TruncateToMapHeight(FastMath.floor(nextHitbox.getHitboxEnd().getY()) + + translateY); + } + else if (side == CONTACT_AREA_TOP) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX()) + + i + translateX); + tileY = div16TruncateToMapHeight(FastMath.ceil(nextHitbox.getHitboxStart().getY()) + + translateY); + } + else if (side == CONTACT_AREA_RIGHT) { + tileX = div16TruncateToMapWidth(FastMath.floor(nextHitbox.getHitboxEnd().getX()) + + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY()) + + i + translateY); + } + else if (side == CONTACT_AREA_LEFT) { + tileX = div16TruncateToMapWidth(FastMath.ceil(nextHitbox.getHitboxStart().getX()) + + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY()) + + i + translateY); + }*/ + if (side == CONTACT_AREA_BOTTOM) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX()) + + i + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxEnd().getY()) + + translateY); + } + else if (side == CONTACT_AREA_TOP) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX()) + + i + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY()) + + translateY); + } + else if (side == CONTACT_AREA_RIGHT) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxEnd().getX()) + + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY()) + + i + translateY); + } + else if (side == CONTACT_AREA_LEFT) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX()) + + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY()) + + i + translateY); + } + else { + throw new IllegalArgumentException(String.valueOf(side) + ": Wrong side input"); + } + + // evaluate + if (TilePropCodex.getProp(map.getTileFromTerrain(tileX, tileY)).isSolid()) { + contactAreaCounter += 1; + } + } + + return contactAreaCounter; + } + + /** + * [N] = [kg * m / s^2] + * F(bo) = density * submerged_volume * gravitational_acceleration [N] + */ + private void applyBuoyancy() { + int fluidDensity = getTileDensity(); + float submergedVolume = getSubmergedVolume(); + + if (!isPlayerNoClip() && !grounded) { + // System.out.println("density: "+density); + veloY -= ((fluidDensity - this.density) + * map.getGravitation() * submergedVolume + * Math.pow(mass, -1) + * SI_TO_GAME_ACC); + } + } + + private float getSubmergedVolume() { + float GAME_TO_SI_VOL = FastMath.pow((1f/METER), 3); + + if( density > 0 ){ + return getSubmergedHeight() + * nextHitbox.getWidth() * nextHitbox.getWidth() + * GAME_TO_SI_VOL + ; + //System.out.println("fluidHeight: "+fluidHeight+", submerged: "+submergedVolume); + //submergedHeight / TILE_SIZE * 1^2 (pixel to meter) + } + else{ + return 0; + } + } + + private float getSubmergedHeight() { + return FastMath.clamp( + nextHitbox.getPointedY() - getFluidLevel() + , 0 + , nextHitbox.getHeight() + ); + } + + private int getFluidLevel() { + int tilePosXStart = Math.round(nextHitbox.getPosX() / TSIZE); + int tilePosXEnd = Math.round(nextHitbox.getHitboxEnd().getX() / TSIZE); + int tilePosY = Math.round(nextHitbox.getPosY() / TSIZE); + + int fluidHeight = 2147483647; + + for (int x = tilePosXStart; x <= tilePosXEnd; x++) { + int tile = map.getTileFromTerrain(x, tilePosY); + if ( TilePropCodex.getProp(tile).isFluid() + && tilePosY * TSIZE < fluidHeight ){ + fluidHeight = tilePosY * TSIZE; + } + } + + return fluidHeight; + } + + /** + * Get highest friction value from feet tiles. + * @return + */ + private int getTileFriction(){ + int friction = 0; + + int tilePosXStart = Math.round(nextHitbox.getPosX() / TSIZE); + int tilePosXEnd = Math.round(nextHitbox.getHitboxEnd().getX() / TSIZE); + int tilePosY = Math.round(nextHitbox.getPointedY() / TSIZE); + + //get density + for (int x = tilePosXStart; x <= tilePosXEnd; x++) { + int tile = map.getTileFromTerrain(x, tilePosY); + if (TilePropCodex.getProp(tile).isFluid()) { + int thisFluidDensity = TilePropCodex.getProp(tile).getFriction(); + + if (thisFluidDensity > friction) friction = thisFluidDensity; + } + } + + return friction; + } + + /** + * Get highest movement resistance value from tiles that the body occupies. + * @return + */ + private int getTileMvmtRstc(){ + int resistance = 0; + + int tilePosXStart = Math.round(nextHitbox.getPosX() / TSIZE); + int tilePosYStart = Math.round(nextHitbox.getPosY() / TSIZE); + int tilePosXEnd = Math.round(nextHitbox.getHitboxEnd().getX() / TSIZE); + int tilePosYEnd = Math.round(nextHitbox.getHitboxEnd().getY() / TSIZE); + + //get density + for (int y = tilePosYStart; y <= tilePosYEnd; y++) { + for (int x = tilePosXStart; x <= tilePosXEnd; x++) { + int tile = map.getTileFromTerrain(x, y); + if (TilePropCodex.getProp(tile).isFluid()) { + int thisFluidDensity = TilePropCodex.getProp(tile).getMovementResistance(); + + if (thisFluidDensity > resistance) resistance = thisFluidDensity; + } + } + } + + return resistance; + } + + /** + * Get highest density (specific gravity) value from tiles that the body occupies. + * @return + */ + private int getTileDensity() { + int density = 0; + + int tilePosXStart = Math.round(nextHitbox.getPosX() / TSIZE); + int tilePosYStart = Math.round(nextHitbox.getPosY() / TSIZE); + int tilePosXEnd = Math.round(nextHitbox.getHitboxEnd().getX() / TSIZE); + int tilePosYEnd = Math.round(nextHitbox.getHitboxEnd().getY() / TSIZE); + + //get density + for (int y = tilePosYStart; y <= tilePosYEnd; y++) { + for (int x = tilePosXStart; x <= tilePosXEnd; x++) { + int tile = map.getTileFromTerrain(x, y); + if (TilePropCodex.getProp(tile).isFluid()) { + int thisFluidDensity = TilePropCodex.getProp(tile).getDensity(); + + if (thisFluidDensity > density) density = thisFluidDensity; + } + } + } + + return density; + } + + private float mvmtRstcToMultiplier(int movementResistanceValue) { + return 1f / (1 + (movementResistanceValue / 16f)); + } + + private void clampHitbox() { + hitbox.setPositionFromPoint( + clampW(hitbox.getPointedX()) + , clampH(hitbox.getPointedY()) + ); + } + + private void clampNextHitbox() { + nextHitbox.setPositionFromPoint( + clampW(nextHitbox.getPointedX()) + , clampH(nextHitbox.getPointedY()) + ); + } + + private void updateNextHitboxFromVelo() { + float fluidResistance = mvmtRstcToMultiplier(getTileMvmtRstc()); + float submergedRatio = FastMath.clamp( + getSubmergedHeight() / nextHitbox.getHeight() + , 0f, 1f + ); + + boolean applyResistance = (!isNoSubjectToFluidResistance() + && submergedRatio > FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO + ); + float resistanceMulInterValueSize = FLUID_RESISTANCE_APPLY_FULL_RATIO - FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO; + float resistanceMultiplier = FastMath.interpolateLinear( + (submergedRatio - FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO) + * FastMath.pow(resistanceMulInterValueSize, -1) + , 0, 1 + ); + float adjustedResistance = FastMath.interpolateLinear( + resistanceMultiplier + , 1f, fluidResistance + ); + + nextHitbox.set( + Math.round(hitbox.getPosX() + + (veloX + * (!applyResistance ? 1 : adjustedResistance) + )) + , Math.round(hitbox.getPosY() + + (veloY + * (!applyResistance ? 1 : adjustedResistance) + )) + , Math.round(baseHitboxW * scale) + , Math.round(baseHitboxH * scale) + /** Full quantisation; wonder what havoc these statements would wreak... + */ + ); + } + + private void updateHitboxX() { + hitbox.setDimension( + nextHitbox.getWidth() + , nextHitbox.getHeight() + ); + hitbox.setPositionX(nextHitbox.getPosX()); + } + + private void updateHitboxY() { + hitbox.setDimension( + nextHitbox.getWidth() + , nextHitbox.getHeight() + ); + hitbox.setPositionY(nextHitbox.getPosY()); + } + + @Override + public void drawGlow(GameContainer gc, Graphics g) { + if (visible && spriteGlow != null) { + if (!sprite.flippedHorizontal()) { + spriteGlow.render(g + , (hitbox.getPosX() - (hitboxTranslateX * scale)) + , (hitbox.getPosY() + (hitboxTranslateY * scale)) + - (baseSpriteHeight - baseHitboxH) * scale + + 2 + , scale + ); + } + else { + spriteGlow.render(g + , (hitbox.getPosX() - scale) + , (hitbox.getPosY() + (hitboxTranslateY * scale)) + - (baseSpriteHeight - baseHitboxH) * scale + + 2 + , scale + ); + } + } + } + + @Override + public void drawBody(GameContainer gc, Graphics g) { + if (visible && sprite != null) { + if (!sprite.flippedHorizontal()) { + sprite.render(g + , (hitbox.getPosX() - (hitboxTranslateX * scale)) + , (hitbox.getPosY() + (hitboxTranslateY * scale)) + - (baseSpriteHeight - baseHitboxH) * scale + + 2 + , scale + ); + } + else { + sprite.render(g + , (hitbox.getPosX() - scale) + , (hitbox.getPosY() + (hitboxTranslateY * scale)) + - (baseSpriteHeight - baseHitboxH) * scale + + 2 + , scale + ); + } + } + } + + @Override + public void updateGlowSprite(GameContainer gc, int delta_t) { + if (spriteGlow != null) spriteGlow.update(delta_t); + } + + @Override + public void updateBodySprite(GameContainer gc, int delta_t) { + if (sprite != null) sprite.update(delta_t); + } + + private float clampW(float x) { + if (x < TSIZE + nextHitbox.getWidth() / 2) { + return TSIZE + nextHitbox.getWidth() / 2; + } + else if (x >= map.width * TSIZE - TSIZE - nextHitbox.getWidth() / 2) { + return map.width * TSIZE - 1 - TSIZE - nextHitbox.getWidth() / 2; + } + else { + return x; + } + } + + private float clampH(float y) { + if (y < TSIZE + nextHitbox.getHeight()) { + return TSIZE + nextHitbox.getHeight(); + } + else if (y >= map.height * TSIZE - TSIZE - nextHitbox.getHeight()) { + return map.height * TSIZE - 1 - TSIZE - nextHitbox.getHeight(); + } + else { + return y; + } + } + + private int clampWtile(int x) { + if (x < 0) { + return 0; + } + else if (x >= map.width) { + return map.width - 1; + } + else { + return x; + } + } + + private int clampHtile(int x) { + if (x < 0) { + return 0; + } + else if (x >= map.height) { + return map.height - 1; + } + else { + return x; + } + } + + private boolean isPlayerNoClip() { + return (this instanceof Player && ((Player) this).isNoClip()); + } + + private static int div16(int x) { + if (x < 0) { throw new IllegalArgumentException("div16: Positive integer only: " + + String.valueOf(x)); } + return (x & 0x7FFF_FFFF) >> 4; + } + + private static int div16TruncateToMapWidth(int x) { + if (x < 0) return 0; + else if (x >= Terrarum.game.map.width << 4) return Terrarum.game.map.width - 1; + else return (x & 0x7FFF_FFFF) >> 4; + } + + private static int div16TruncateToMapHeight(int y) { + if (y < 0) return 0; + else if (y >= Terrarum.game.map.height << 4) return Terrarum.game.map.height - 1; + else return (y & 0x7FFF_FFFF) >> 4; + } + + private static int mod16(int x) { + if (x < 0) { throw new IllegalArgumentException("mod16: Positive integer only: " + + String.valueOf(x)); } + return x & 0b1111; + } + + private static float clampCeil(float x, float ceil) { + return (Math.abs(x) > ceil ? ceil : x); + } + + public void setVisible(boolean visible) { + this.visible = visible; + } + + public void setScale(float scale) { + this.scale = scale; + } + + public void setMass(float mass) { + this.mass = mass; + } + + public void setVeloX(float veloX) { + this.veloX = veloX; + } + + public void setVeloY(float veloY) { + this.veloY = veloY; + } + + public void setGrounded(boolean grounded) { + this.grounded = grounded; + } + + public boolean isVisible() { + return visible; + } + + public float getScale() { + return scale; + } + + public float getMass() { + return mass; + } + + public float getVeloX() { + return veloX; + } + + public float getVeloY() { + return veloY; + } + + public boolean isGrounded() { + return grounded; + } + + public int getBaseHitboxW() { + return baseHitboxW; + } + + public int getBaseHitboxH() { + return baseHitboxH; + } + + public float getHitboxTranslateX() { + return hitboxTranslateX; + } + + public float getHitboxTranslateY() { + return hitboxTranslateY; + } + + public Hitbox getHitbox() { + return hitbox; + } + + public Hitbox getNextHitbox() { + return nextHitbox; + } + + public boolean isUpdate() { + return update; + } + + public void setUpdate(boolean update) { + this.update = update; + } + + private int quantiseTSize(float v) { + return FastMath.floor(v / TSIZE) * TSIZE; + } + + public boolean isNoSubjectToGrav() { + return noSubjectToGrav; + } + + public void setNoSubjectToGrav(boolean noSubjectToGrav) { + this.noSubjectToGrav = noSubjectToGrav; + } + + public boolean isNoCollideWorld() { + return noCollideWorld; + } + + public boolean isNoSubjectToFluidResistance() { + return noSubjectToFluidResistance; + } + + public void setNoCollideWorld(boolean noCollideWorld) { + this.noCollideWorld = noCollideWorld; + } + + public void setNoSubjectToFluidResistance(boolean noSubjectToFluidResistance) { + this.noSubjectToFluidResistance = noSubjectToFluidResistance; + } + + public float getElasticity() { + return elasticity; + } + + public void setElasticity(float elasticity) { + if (elasticity < 0) + throw new IllegalArgumentException("[ActorWithBody] " + elasticity + ": valid elasticity value is [0, 1]."); + + if (elasticity > 1) { + System.out.println("[ActorWithBody] Elasticity were capped to 1."); + this.elasticity = ELASTICITY_MAX; + } + else this.elasticity = elasticity * ELASTICITY_MAX; + } + + public void setDensity(int density) { + if (density < 0) + throw new IllegalArgumentException("[ActorWithBody] " + density + ": density cannot be negative."); + + this.density = density; + } + + @org.jetbrains.annotations.Nullable + @Override + public Long getReferenceID() { + return this.referenceID; + } + + @Override + public void setReferenceID(@org.jetbrains.annotations.Nullable Long aLong) { + referenceID = aLong; + } +} + +/** + + = = ↑ + === ===@! + =↑ =↑ + =↑ = + =↑ = + =@ (pressing R) = +================== ================== + + Fig. 1: the fix was not applied + */ \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/ActorWithBody.kt b/src/com/Torvald/Terrarum/Actors/ActorWithBody.kt new file mode 100644 index 000000000..96afa5a95 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/ActorWithBody.kt @@ -0,0 +1,781 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.Rand.HQRNG +import com.Torvald.Terrarum.* +import com.Torvald.Terrarum.GameMap.GameMap +import com.Torvald.Terrarum.MapDrawer.MapDrawer +import com.Torvald.Terrarum.TileProperties.TilePropCodex +import com.Torvald.spriteAnimation.SpriteAnimation +import com.jme3.math.FastMath +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics + +/** + * Created by minjaesong on 16-03-14. + */ +open class ActorWithBody : Actor, Visible, Glowing, Pocketed { + + internal var actorValue: ActorValue + override var inventory: ActorInventory? = null + + var hitboxTranslateX: Float = 0.toFloat()// relative to spritePosX + var hitboxTranslateY: Float = 0.toFloat()// relative to spritePosY + var baseHitboxW: Int = 0 + var baseHitboxH: Int = 0 + + /** + * Velocity for newtonian sim. + * Fluctuation in, otherwise still, velocity is equal to acceleration. + + * Acceleration: used in code like: + * veloY += 3.0 + * +3.0 is acceleration. You __accumulate__ acceleration to the velocity. + */ + @Volatile var veloX: Float = 0.toFloat() + @Volatile var veloY: Float = 0.toFloat() + @Transient private val VELO_HARD_LIMIT = 10000f + + var grounded = false + + @Transient var sprite: SpriteAnimation? = null + @Transient var spriteGlow: SpriteAnimation? = null + /** Default to 'false' */ + var isVisible = false + /** Default to 'true' */ + var isUpdate = true + + var isNoSubjectToGrav = false + var isNoCollideWorld = false + var isNoSubjectToFluidResistance = false + + internal var baseSpriteWidth: Int = 0 + internal var baseSpriteHeight: Int = 0 + + override var referenceID: Long? = null + /** + * Positions: top-left point + */ + @Volatile var hitbox: Hitbox? = null + @Volatile @Transient var nextHitbox: Hitbox? = null + + /** + * Physical properties + */ + @Volatile @Transient var scale = 1f + @Volatile @Transient var mass = 2f + @Transient private val MASS_LOWEST = 2f + /** Valid range: [0, 1] */ + var elasticity = 0f + set(elasticity) { + if (elasticity < 0) + throw IllegalArgumentException("[ActorWithBody] $elasticity: valid elasticity value is [0, 1].") + + if (elasticity > 1) { + println("[ActorWithBody] Elasticity were capped to 1.") + this.elasticity = ELASTICITY_MAX + } else + this.elasticity = elasticity * ELASTICITY_MAX + } + @Transient private val ELASTICITY_MAX = 0.993f + private var density = 1000f + + /** + * Gravitational Constant G. Load from GameMap. + * [m / s^2] + * s^2 = 1/FPS = 1/60 if FPS is targeted to 60 + * meter to pixel : 24/FPS + */ + @Transient private val METER = 24f + /** + * [m / s^2] * SI_TO_GAME_ACC -> [px / IFrame^2] + */ + @Transient private val SI_TO_GAME_ACC = METER / FastMath.sqr(Terrarum.TARGET_FPS.toFloat()) + /** + * [m / s] * SI_TO_GAME_VEL -> [px / IFrame] + */ + @Transient private val SI_TO_GAME_VEL = METER / Terrarum.TARGET_FPS + + @Transient private var gravitation: Float = 0.toFloat() + @Transient private val DRAG_COEFF = 1f + + @Transient private val CONTACT_AREA_TOP = 0 + @Transient private val CONTACT_AREA_RIGHT = 1 + @Transient private val CONTACT_AREA_BOTTOM = 2 + @Transient private val CONTACT_AREA_LEFT = 3 + + @Transient private val UD_COMPENSATOR_MAX = TSIZE + @Transient private val LR_COMPENSATOR_MAX = TSIZE + @Transient private val TILE_AUTOCLIMB_RATE = 4 + + /** + * A constant to make falling faster so that the game is more playable + */ + @Transient private val G_MUL_PLAYABLE_CONST = 1.4142f + + @Transient private val EVENT_MOVE_TOP = 0 + @Transient private val EVENT_MOVE_RIGHT = 1 + @Transient private val EVENT_MOVE_BOTTOM = 2 + @Transient private val EVENT_MOVE_LEFT = 3 + @Transient private val EVENT_MOVE_NONE = -1 + + @Transient internal var eventMoving = EVENT_MOVE_NONE // cannot collide both X-axis and Y-axis, or else jump control breaks up. + + /** + * in milliseconds + */ + @Transient val INVINCIBILITY_TIME = 500 + + /** + * Will ignore fluid resistance if (submerged height / actor height) <= this var + */ + @Transient private val FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO = 0.2f + @Transient private val FLUID_RESISTANCE_APPLY_FULL_RATIO = 0.5f + + @Transient private val map: GameMap + + init { + referenceID = HQRNG().nextLong() + actorValue = ActorValue() + map = Terrarum.game.map + } + + /** + + * @param w + * * + * @param h + * * + * @param tx +: translate drawn sprite to LEFT. + * * + * @param ty +: translate drawn sprite to DOWN. + * * + * @see ActorWithBody.drawBody + * @see ActorWithBody.drawGlow + */ + fun setHitboxDimension(w: Int, h: Int, tx: Int, ty: Int) { + baseHitboxH = h + baseHitboxW = w + hitboxTranslateX = tx.toFloat() + hitboxTranslateY = ty.toFloat() + } + + /** + * Set hitbox position from bottom-center point + * @param x + * * + * @param y + */ + fun setPosition(x: Float, y: Float) { + hitbox = Hitbox( + x - (baseHitboxW / 2 - hitboxTranslateX) * scale, y - (baseHitboxH - hitboxTranslateY) * scale, baseHitboxW * scale, baseHitboxH * scale) + + nextHitbox = Hitbox( + x - (baseHitboxW / 2 - hitboxTranslateX) * scale, y - (baseHitboxH - hitboxTranslateY) * scale, baseHitboxW * scale, baseHitboxH * scale) + } + + override fun update(gc: GameContainer, delta_t: Int) { + if (isUpdate) { + /** + * Update variables + */ + if (this is Player) { + isNoSubjectToGrav = isPlayerNoClip + isNoCollideWorld = isPlayerNoClip + isNoSubjectToFluidResistance = isPlayerNoClip + } + + if (mass < MASS_LOWEST) mass = MASS_LOWEST // clamp to minimum possible mass + if (sprite != null) { + baseSpriteHeight = sprite!!.height + baseSpriteWidth = sprite!!.width + } + gravitation = map.gravitation + AUTO_CLIMB_RATE = Math.min(TSIZE / 8 * FastMath.sqrt(scale), TSIZE.toFloat()).toInt() + + if (!isNoSubjectToGrav) { + applyGravitation() + applyBuoyancy() + } + + // hard limit velocity + if (veloX > VELO_HARD_LIMIT) veloX = VELO_HARD_LIMIT + if (veloY > VELO_HARD_LIMIT) veloY = VELO_HARD_LIMIT + // limit velocity by fluid resistance + //int tilePropResistance = getTileMvmtRstc(); + //if (!noSubjectToFluidResistance) { + // veloX *= mvmtRstcToMultiplier(tilePropResistance); + // veloY *= mvmtRstcToMultiplier(tilePropResistance); + //} + + + // Set 'next' positions to fiddle with + updateNextHitboxFromVelo() + + + // if not horizontally moving then ... + //if (Math.abs(veloX) < 0.5) { // fix for special situations (see fig. 1 at the bottom of the source) + // updateVerticalPos(); + // updateHorizontalPos(); + //} + //else { + updateHorizontalPos() + updateVerticalPos() + //} + + + updateHitboxX() + updateHitboxY() + + + clampNextHitbox() + clampHitbox() + } + } + + /** + * Apply gravitation to the every falling body (unless not levitating) + + * Apply only if not grounded; normal force is not implemented (and redundant) + * so we manually reset G to zero (not applying G. force) if grounded. + */ + // FIXME abnormal jump behaviour if mass < 2, same thing happens if mass == 0 (but zero mass is invalid anyway). + private fun applyGravitation() { + if (!grounded) { + /** + * weight; gravitational force in action + * W = mass * G (9.8 [m/s^2]) + */ + val W = gravitation * mass + /** + * Drag of atmosphere + * D = Cd (drag coefficient) * 0.5 * rho (density) * V^2 (velocity) * A (area) + */ + val A = scale * scale + val D = DRAG_COEFF * 0.5f * 1.292f * veloY * veloY * A + + val fluidResistance = tileMvmtRstc + + veloY += clampCeil( + (W - D) / mass * SI_TO_GAME_ACC * G_MUL_PLAYABLE_CONST, VELO_HARD_LIMIT)// * mvmtRstcToMultiplier(fluidResistance) // eliminate shoot-up from fluids + } + } + + private fun updateVerticalPos() { + if (!isNoCollideWorld) { + // check downward + if (veloY >= 0) { + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_BOTTOM)) { + adjustHitBottom() + elasticReflectY() + grounded = true + } else if (isColliding(CONTACT_AREA_BOTTOM, 0, 1)) { + elasticReflectY() + grounded = true + } else { + grounded = false + } + } else if (veloY < 0) { + grounded = false + + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_TOP)) { + adjustHitTop() + elasticReflectY() + } else if (isColliding(CONTACT_AREA_TOP, 0, -1)) { + elasticReflectY() // for reversed gravity + } else { + } + } + } + } + + private fun adjustHitBottom() { + val newX = nextHitbox!!.pointedX // look carefully, getPos or getPointed + // int-ify posY of nextHitbox + nextHitbox!!.setPositionYFromPoint(FastMath.floor(nextHitbox!!.pointedY).toFloat()) + + var newYOff = 0 // always positive + + var colliding: Boolean + do { + newYOff += 1 + colliding = isColliding(CONTACT_AREA_BOTTOM, 0, -newYOff) + } while (colliding) + + val newY = nextHitbox!!.pointedY - newYOff + nextHitbox!!.setPositionFromPoint(newX, newY) + } + + private fun adjustHitTop() { + val newX = nextHitbox!!.posX + // int-ify posY of nextHitbox + nextHitbox!!.setPositionY(FastMath.ceil(nextHitbox!!.posY).toFloat()) + + var newYOff = 0 // always positive + + var colliding: Boolean + do { + newYOff += 1 + colliding = isColliding(CONTACT_AREA_TOP, 0, newYOff) + } while (colliding) + + val newY = nextHitbox!!.posY + newYOff + nextHitbox!!.setPosition(newX, newY) + } + + private fun updateHorizontalPos() { + if (!isNoCollideWorld) { + // check right + if (veloX >= 0.5) { + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_RIGHT) && !isColliding(CONTACT_AREA_LEFT)) { + adjustHitRight() + elasticReflectX() + } else if (isColliding(CONTACT_AREA_RIGHT, 1, 0) && !isColliding(CONTACT_AREA_LEFT, -1, 0)) { + elasticReflectX() + } else { + } + } else if (veloX <= -0.5) { + // System.out.println("collidingleft"); + // order of the if-elseif chain is IMPORTANT + if (isColliding(CONTACT_AREA_LEFT) && !isColliding(CONTACT_AREA_RIGHT)) { + adjustHitLeft() + elasticReflectX() + } else if (isColliding(CONTACT_AREA_LEFT, -1, 0) && !isColliding(CONTACT_AREA_RIGHT, 1, 0)) { + elasticReflectX() + } else { + } + } else { + // System.out.println("updatehorizontal - |velo| < 0.5"); + if (isColliding(CONTACT_AREA_LEFT) || isColliding(CONTACT_AREA_RIGHT)) { + elasticReflectX() + } + } + } + } + + private fun adjustHitRight() { + val newY = nextHitbox!!.posY // look carefully, getPos or getPointed + // int-ify posY of nextHitbox + nextHitbox!!.setPositionX(FastMath.floor(nextHitbox!!.posX + nextHitbox!!.width) - nextHitbox!!.width) + + var newXOff = 0 // always positive + + var colliding: Boolean + do { + newXOff += 1 + colliding = isColliding(CONTACT_AREA_BOTTOM, -newXOff, 0) + } while (newXOff < TSIZE && colliding) + + val newX = nextHitbox!!.posX - newXOff + nextHitbox!!.setPosition(newX, newY) + } + + private fun adjustHitLeft() { + val newY = nextHitbox!!.posY + // int-ify posY of nextHitbox + nextHitbox!!.setPositionX(FastMath.ceil(nextHitbox!!.posX).toFloat()) + + var newXOff = 0 // always positive + + var colliding: Boolean + do { + newXOff += 1 + colliding = isColliding(CONTACT_AREA_TOP, newXOff, 0) + } while (newXOff < TSIZE && colliding) + + val newX = nextHitbox!!.posX + newXOff + nextHitbox!!.setPosition(newX, newY) // + 1; float-point rounding compensation (i think...) + } + + private fun elasticReflectX() { + if (veloX != 0f) veloX = -veloX * elasticity + } + + private fun elasticReflectY() { + if (veloY != 0f) veloY = -veloY * elasticity + } + + private fun isColliding(side: Int, tx: Int = 0, ty: Int = 0): Boolean { + return getContactingArea(side, tx, ty) > 1 + } + + private fun getContactingArea(side: Int, translateX: Int = 0, translateY: Int = 0): Int { + var contactAreaCounter = 0 + for (i in 0..Math.round(if (side % 2 == 0) nextHitbox!!.width else nextHitbox!!.height) - 1) { + // set tile positions + val tileX: Int + val tileY: Int + /*if (side == CONTACT_AREA_BOTTOM) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX()) + + i + translateX); + tileY = div16TruncateToMapHeight(FastMath.floor(nextHitbox.getHitboxEnd().getY()) + + translateY); + } + else if (side == CONTACT_AREA_TOP) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX()) + + i + translateX); + tileY = div16TruncateToMapHeight(FastMath.ceil(nextHitbox.getHitboxStart().getY()) + + translateY); + } + else if (side == CONTACT_AREA_RIGHT) { + tileX = div16TruncateToMapWidth(FastMath.floor(nextHitbox.getHitboxEnd().getX()) + + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY()) + + i + translateY); + } + else if (side == CONTACT_AREA_LEFT) { + tileX = div16TruncateToMapWidth(FastMath.ceil(nextHitbox.getHitboxStart().getX()) + + translateX); + tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY()) + + i + translateY); + }*/ + if (side == CONTACT_AREA_BOTTOM) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x) + + i + translateX) + tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxEnd.y) + translateY) + } else if (side == CONTACT_AREA_TOP) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x) + + i + translateX) + tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxStart.y) + translateY) + } else if (side == CONTACT_AREA_RIGHT) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxEnd.x) + translateX) + tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxStart.y) + + i + translateY) + } else if (side == CONTACT_AREA_LEFT) { + tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x) + translateX) + tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxStart.y) + + i + translateY) + } else { + throw IllegalArgumentException(side.toString() + ": Wrong side input") + } + + // evaluate + if (TilePropCodex.getProp(map.getTileFromTerrain(tileX, tileY)).isSolid) { + contactAreaCounter += 1 + } + } + + return contactAreaCounter + } + + /** + * [N] = [kg * m / s^2] + * F(bo) = density * submerged_volume * gravitational_acceleration [N] + */ + private fun applyBuoyancy() { + val fluidDensity = tileDensity + val submergedVolume = submergedVolume + + if (!isPlayerNoClip && !grounded) { + // System.out.println("density: "+density); + veloY -= ((fluidDensity - this.density).toDouble() + * map.gravitation.toDouble() * submergedVolume.toDouble() + * Math.pow(mass.toDouble(), -1.0) + * SI_TO_GAME_ACC.toDouble()).toFloat() + } + } + + private //System.out.println("fluidHeight: "+fluidHeight+", submerged: "+submergedVolume); + //submergedHeight / TILE_SIZE * 1^2 (pixel to meter) + val submergedVolume: Float + get() { + val GAME_TO_SI_VOL = FastMath.pow(1f / METER, 3f) + + if (density > 0) { + return submergedHeight * + nextHitbox!!.width * nextHitbox!!.width * + GAME_TO_SI_VOL + } else { + return 0f + } + } + + private val submergedHeight: Float + get() = FastMath.clamp( + nextHitbox!!.pointedY - fluidLevel, 0f, nextHitbox!!.height) + + private val fluidLevel: Int + get() { + val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE) + val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE) + val tilePosY = Math.round(nextHitbox!!.posY / TSIZE) + + var fluidHeight = 2147483647 + + for (x in tilePosXStart..tilePosXEnd) { + val tile = map.getTileFromTerrain(x, tilePosY) + if (TilePropCodex.getProp(tile).isFluid && tilePosY * TSIZE < fluidHeight) { + fluidHeight = tilePosY * TSIZE + } + } + + return fluidHeight + } + + /** + * Get highest friction value from feet tiles. + * @return + */ + private //get density + val tileFriction: Int + get() { + var friction = 0 + + val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE) + val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE) + val tilePosY = Math.round(nextHitbox!!.pointedY / TSIZE) + for (x in tilePosXStart..tilePosXEnd) { + val tile = map.getTileFromTerrain(x, tilePosY) + if (TilePropCodex.getProp(tile).isFluid) { + val thisFluidDensity = TilePropCodex.getProp(tile).friction + + if (thisFluidDensity > friction) friction = thisFluidDensity + } + } + + return friction + } + + /** + * Get highest movement resistance value from tiles that the body occupies. + * @return + */ + private //get density + val tileMvmtRstc: Int + get() { + var resistance = 0 + + val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE) + val tilePosYStart = Math.round(nextHitbox!!.posY / TSIZE) + val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE) + val tilePosYEnd = Math.round(nextHitbox!!.hitboxEnd.y / TSIZE) + for (y in tilePosYStart..tilePosYEnd) { + for (x in tilePosXStart..tilePosXEnd) { + val tile = map.getTileFromTerrain(x, y) + if (TilePropCodex.getProp(tile).isFluid) { + val thisFluidDensity = TilePropCodex.getProp(tile).movementResistance + + if (thisFluidDensity > resistance) resistance = thisFluidDensity + } + } + } + + return resistance + } + + /** + * Get highest density (specific gravity) value from tiles that the body occupies. + * @return + */ + private //get density + val tileDensity: Int + get() { + var density = 0 + + val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE) + val tilePosYStart = Math.round(nextHitbox!!.posY / TSIZE) + val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE) + val tilePosYEnd = Math.round(nextHitbox!!.hitboxEnd.y / TSIZE) + for (y in tilePosYStart..tilePosYEnd) { + for (x in tilePosXStart..tilePosXEnd) { + val tile = map.getTileFromTerrain(x, y) + if (TilePropCodex.getProp(tile).isFluid) { + val thisFluidDensity = TilePropCodex.getProp(tile).density + + if (thisFluidDensity > density) density = thisFluidDensity + } + } + } + + return density + } + + private fun mvmtRstcToMultiplier(movementResistanceValue: Int): Float { + return 1f / (1 + movementResistanceValue / 16f) + } + + private fun clampHitbox() { + hitbox!!.setPositionFromPoint( + clampW(hitbox!!.pointedX), clampH(hitbox!!.pointedY)) + } + + private fun clampNextHitbox() { + nextHitbox!!.setPositionFromPoint( + clampW(nextHitbox!!.pointedX), clampH(nextHitbox!!.pointedY)) + } + + private fun updateNextHitboxFromVelo() { + val fluidResistance = mvmtRstcToMultiplier(tileMvmtRstc) + val submergedRatio = FastMath.clamp( + submergedHeight / nextHitbox!!.height, 0f, 1f) + + val applyResistance = !isNoSubjectToFluidResistance && submergedRatio > FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO + val resistanceMulInterValueSize = FLUID_RESISTANCE_APPLY_FULL_RATIO - FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO + val resistanceMultiplier = FastMath.interpolateLinear( + (submergedRatio - FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO) * FastMath.pow(resistanceMulInterValueSize, -1f), 0f, 1f) + val adjustedResistance = FastMath.interpolateLinear( + resistanceMultiplier, 1f, fluidResistance) + + nextHitbox!!.set( + Math.round(hitbox!!.posX + veloX * (if (!applyResistance) 1f else adjustedResistance)).toFloat() + , Math.round(hitbox!!.posY + veloY * (if (!applyResistance) 1f else adjustedResistance)).toFloat() + , Math.round(baseHitboxW * scale).toFloat() + , Math.round(baseHitboxH * scale).toFloat()) + /** Full quantisation; wonder what havoc these statements would wreak... + */ + } + + private fun updateHitboxX() { + hitbox!!.setDimension( + nextHitbox!!.width, nextHitbox!!.height) + hitbox!!.setPositionX(nextHitbox!!.posX) + } + + private fun updateHitboxY() { + hitbox!!.setDimension( + nextHitbox!!.width, nextHitbox!!.height) + hitbox!!.setPositionY(nextHitbox!!.posY) + } + + override fun drawGlow(gc: GameContainer, g: Graphics) { + if (isVisible && spriteGlow != null) { + if (!sprite!!.flippedHorizontal()) { + spriteGlow!!.render(g, hitbox!!.posX - hitboxTranslateX * scale, hitbox!!.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale) + } else { + spriteGlow!!.render(g, hitbox!!.posX - scale, hitbox!!.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale) + } + } + } + + override fun drawBody(gc: GameContainer, g: Graphics) { + if (isVisible && sprite != null) { + if (!sprite!!.flippedHorizontal()) { + sprite!!.render(g, hitbox!!.posX - hitboxTranslateX * scale, hitbox!!.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale) + } else { + sprite!!.render(g, hitbox!!.posX - scale, hitbox!!.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale) + } + } + } + + override fun updateGlowSprite(gc: GameContainer, delta_t: Int) { + if (spriteGlow != null) spriteGlow!!.update(delta_t) + } + + override fun updateBodySprite(gc: GameContainer, delta_t: Int) { + if (sprite != null) sprite!!.update(delta_t) + } + + private fun clampW(x: Float): Float { + if (x < TSIZE + nextHitbox!!.width / 2) { + return TSIZE + nextHitbox!!.width / 2 + } else if (x >= (map.width * TSIZE).toFloat() - TSIZE.toFloat() - nextHitbox!!.width / 2) { + return (map.width * TSIZE).toFloat() - 1f - TSIZE.toFloat() - nextHitbox!!.width / 2 + } else { + return x + } + } + + private fun clampH(y: Float): Float { + if (y < TSIZE + nextHitbox!!.height) { + return TSIZE + nextHitbox!!.height + } else if (y >= (map.height * TSIZE).toFloat() - TSIZE.toFloat() - nextHitbox!!.height) { + return (map.height * TSIZE).toFloat() - 1f - TSIZE.toFloat() - nextHitbox!!.height + } else { + return y + } + } + + private fun clampWtile(x: Int): Int { + if (x < 0) { + return 0 + } else if (x >= map.width) { + return map.width - 1 + } else { + return x + } + } + + private fun clampHtile(x: Int): Int { + if (x < 0) { + return 0 + } else if (x >= map.height) { + return map.height - 1 + } else { + return x + } + } + + private val isPlayerNoClip: Boolean + get() = this is Player && this.isNoClip() + + private fun quantiseTSize(v: Float): Int { + return FastMath.floor(v / TSIZE) * TSIZE + } + + fun setDensity(density: Int) { + if (density < 0) + throw IllegalArgumentException("[ActorWithBody] $density: density cannot be negative.") + + this.density = density.toFloat() + } + + companion object { + + @Transient private val TSIZE = MapDrawer.TILE_SIZE + private var AUTO_CLIMB_RATE = TSIZE / 8 + + private fun div16(x: Int): Int { + if (x < 0) { + throw IllegalArgumentException("div16: Positive integer only: " + x.toString()) + } + return x and 0x7FFFFFFF shr 4 + } + + private fun div16TruncateToMapWidth(x: Int): Int { + if (x < 0) + return 0 + else if (x >= Terrarum.game.map.width shl 4) + return Terrarum.game.map.width - 1 + else + return x and 0x7FFFFFFF shr 4 + } + + private fun div16TruncateToMapHeight(y: Int): Int { + if (y < 0) + return 0 + else if (y >= Terrarum.game.map.height shl 4) + return Terrarum.game.map.height - 1 + else + return y and 0x7FFFFFFF shr 4 + } + + private fun mod16(x: Int): Int { + if (x < 0) { + throw IllegalArgumentException("mod16: Positive integer only: " + x.toString()) + } + return x and 15 + } + + private fun clampCeil(x: Float, ceil: Float): Float { + return if (Math.abs(x) > ceil) ceil else x + } + } +} +/** + * Give new random ReferenceID and initialise ActorValue + */ + +/** + += = ↑ +=== ===@! +=↑ =↑ +=↑ = +=↑ = +=@ (pressing R) = +================== ================== + +Fig. 1: the fix was not applied + */ \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem b/src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem new file mode 100644 index 000000000..93d9aa723 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem @@ -0,0 +1,20 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.Terrarum.GameItem.InventoryItem; + +/** + * Created by minjaesong on 16-01-31. + */ +public interface CanBeStoredAsItem { + + void attachItemData(); + + float getItemWeight(); + + void stopUpdateAndDraw(); + + void resumeUpdateAndDraw(); + + InventoryItem getItemData(); + +} diff --git a/src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.kt b/src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.kt new file mode 100644 index 000000000..e6897cfbe --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/CanBeStoredAsItem.kt @@ -0,0 +1,20 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.Terrarum.GameItem.InventoryItem + +/** + * Created by minjaesong on 16-03-14. + */ +interface CanBeStoredAsItem { + + fun attachItemData() + + fun getItemWeight(): Float + + fun stopUpdateAndDraw() + + fun resumeUpdateAndDraw() + + var itemData: InventoryItem? + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/Controllable b/src/com/Torvald/Terrarum/Actors/Controllable new file mode 100644 index 000000000..0e3ee33f6 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Controllable @@ -0,0 +1,17 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.spriteAnimation.SpriteAnimation; +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; +import org.newdawn.slick.Input; + +/** + * Created by minjaesong on 15-12-31. + */ +public interface Controllable { + + void processInput(Input input); + + void keyPressed(int key, char c); + +} diff --git a/src/com/Torvald/Terrarum/Actors/Controllable.kt b/src/com/Torvald/Terrarum/Actors/Controllable.kt new file mode 100644 index 000000000..43d1a3160 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Controllable.kt @@ -0,0 +1,14 @@ +package com.Torvald.Terrarum.Actors + +import org.newdawn.slick.Input + +/** + * Created by minjaesong on 16-03-14. + */ +interface Controllable { + + fun processInput(input: Input) + + fun keyPressed(key: Int, c: Char) + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/CreatureFactory b/src/com/Torvald/Terrarum/Actors/CreatureFactory new file mode 100644 index 000000000..571a8f745 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/CreatureFactory @@ -0,0 +1,137 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.JsonFetcher; +import com.Torvald.Rand.Fudge3; +import com.Torvald.Rand.HQRNG; +import com.Torvald.Terrarum.LangPack.Lang; +import com.google.gson.JsonObject; +import org.newdawn.slick.SlickException; + +import java.io.IOException; + +/** + * Created by minjaesong on 16-02-05. + */ +public class CreatureFactory { + + private static final String JSONPATH = "./res/raw/"; + + public ActorWithBody build(String jsonFileName) throws IOException, SlickException { + JsonObject jsonObj = JsonFetcher.readJson(JSONPATH + jsonFileName); + ActorWithBody actor = new ActorWithBody(); + + + String[] elementsString = { + "racename" + , "racenameplural" + }; + + String[] elementsFloat = { + "baseheight" + , "basemass" + , "accel" + , "toolsize" + , "encumbrance" + }; + + String[] elementsFloatVariable = { + "strength" + , "speed" + , "jumppower" + , "scale" + , "speed" + }; + + String[] elementsBoolean = { + "intelligent" + }; + + String[] elementsMultiplyFromOne = { + "physiquemult" + }; + + + setAVStrings(actor, elementsString, jsonObj); + setAVFloats(actor, elementsFloat, jsonObj); + setAVFloatsVariable(actor, elementsFloatVariable, jsonObj); + setAVMultiplyFromOne(actor, elementsMultiplyFromOne, jsonObj); + setAVBooleans(actor, elementsBoolean, jsonObj); + + actor.actorValue.set("accel", Player.WALK_ACCEL_BASE); + actor.actorValue.set("accelmult", 1f); + + actor.inventory = new ActorInventory((int) actor.actorValue.get("encumberance"), true); + + return actor; + } + + /** + * Fetch and set actor values that have 'variable' appended. E.g. strength + * @param p + * @param elemSet + * @param jsonObject + */ + private void setAVFloatsVariable(ActorWithBody p, String[] elemSet, JsonObject jsonObject) { + for (String s : elemSet) { + float baseValue = jsonObject.get(s).getAsFloat(); + // roll fudge dice and get value [-3, 3] as [0, 6] + int varSelected = new Fudge3(new HQRNG()).rollForArray(); + // get multiplier from json. Assuming percentile + int multiplier = jsonObject.get(s + "variable").getAsJsonArray().get(varSelected).getAsInt(); + float realValue = baseValue * multiplier / 100f; + + p.actorValue.set(s, realValue); + } + } + + /** + * Fetch and set string actor values + * @param p + * @param elemSet + * @param jsonObject + */ + private void setAVStrings(ActorWithBody p, String[] elemSet, JsonObject jsonObject) { + for (String s : elemSet) { + String key = jsonObject.get(s).getAsString(); + p.actorValue.set(s, Lang.get(key)); + } + } + + /** + * Fetch and set float actor values + * @param p + * @param elemSet + * @param jsonObject + */ + private void setAVFloats(ActorWithBody p, String[] elemSet, JsonObject jsonObject) { + for (String s : elemSet) { + p.actorValue.set(s, jsonObject.get(s).getAsFloat()); + } + } + + /** + * Fetch and set actor values that should multiplier be applied to the base value of 1. + * E.g. physiquemult + * @param p + * @param elemSet + * @param jsonObject + */ + private void setAVMultiplyFromOne(ActorWithBody p, String[] elemSet, JsonObject jsonObject) { + for (String s : elemSet) { + float baseValue = 1f; + // roll fudge dice and get value [-3, 3] as [0, 6] + int varSelected = new Fudge3(new HQRNG()).rollForArray(); + // get multiplier from json. Assuming percentile + int multiplier = jsonObject.get(s).getAsJsonArray().get(varSelected).getAsInt(); + float realValue = baseValue * multiplier / 100f; + + p.actorValue.set(s, realValue); + } + } + + private void setAVBooleans(ActorWithBody p, String[] elemSet, JsonObject jsonObject) { + for (String s : elemSet) { + p.actorValue.set(s, jsonObject.get(s).getAsBoolean()); + } + } +} diff --git a/src/com/Torvald/Terrarum/Actors/CreatureFactory.kt b/src/com/Torvald/Terrarum/Actors/CreatureFactory.kt new file mode 100644 index 000000000..cfa361a56 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/CreatureFactory.kt @@ -0,0 +1,127 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.JsonFetcher +import com.Torvald.Rand.Fudge3 +import com.Torvald.Rand.HQRNG +import com.Torvald.Terrarum.LangPack.Lang +import com.google.gson.JsonObject +import org.newdawn.slick.SlickException +import java.io.IOException + +/** + * Created by minjaesong on 16-03-14. + */ + +private const val JSONPATH = "./res/raw/" + +class CreatureFactory { + + @Throws(IOException::class, SlickException::class) + fun build(jsonFileName: String): ActorWithBody { + val jsonObj = JsonFetcher.readJson(JSONPATH + jsonFileName) + val actor = ActorWithBody() + + + val elementsString = arrayOf("racename", "racenameplural") + + val elementsFloat = arrayOf("baseheight", "basemass", "accel", "toolsize", "encumbrance") + + val elementsFloatVariable = arrayOf("strength", "speed", "jumppower", "scale", "speed") + + val elementsBoolean = arrayOf("intelligent") + + val elementsMultiplyFromOne = arrayOf("physiquemult") + + + setAVStrings(actor, elementsString, jsonObj) + setAVFloats(actor, elementsFloat, jsonObj) + setAVFloatsVariable(actor, elementsFloatVariable, jsonObj) + setAVMultiplyFromOne(actor, elementsMultiplyFromOne, jsonObj) + setAVBooleans(actor, elementsBoolean, jsonObj) + + actor.actorValue.set("accel", Player.WALK_ACCEL_BASE) + actor.actorValue.set("accelmult", 1f) + + actor.inventory = (ActorInventory(actor.actorValue.get("encumbrance") as Int, true)) + + return actor + } + + /** + * Fetch and set actor values that have 'variable' appended. E.g. strength + * @param p + * * + * @param elemSet + * * + * @param jsonObject + */ + private fun setAVFloatsVariable(p: ActorWithBody, elemSet: Array, jsonObject: JsonObject) { + for (s in elemSet) { + val baseValue = jsonObject.get(s).asFloat + // roll fudge dice and get value [-3, 3] as [0, 6] + val varSelected = Fudge3(HQRNG()).rollForArray() + // get multiplier from json. Assuming percentile + val multiplier = jsonObject.get(s + "variable").asJsonArray.get(varSelected).asInt + val realValue = baseValue * multiplier / 100f + + p.actorValue.set(s, realValue) + } + } + + /** + * Fetch and set string actor values + * @param p + * * + * @param elemSet + * * + * @param jsonObject + */ + private fun setAVStrings(p: ActorWithBody, elemSet: Array, jsonObject: JsonObject) { + for (s in elemSet) { + val key = jsonObject.get(s).asString + p.actorValue.set(s, Lang.get(key)) + } + } + + /** + * Fetch and set float actor values + * @param p + * * + * @param elemSet + * * + * @param jsonObject + */ + private fun setAVFloats(p: ActorWithBody, elemSet: Array, jsonObject: JsonObject) { + for (s in elemSet) { + p.actorValue.set(s, jsonObject.get(s).asFloat) + } + } + + /** + * Fetch and set actor values that should multiplier be applied to the base value of 1. + * E.g. physiquemult + * @param p + * * + * @param elemSet + * * + * @param jsonObject + */ + private fun setAVMultiplyFromOne(p: ActorWithBody, elemSet: Array, jsonObject: JsonObject) { + for (s in elemSet) { + val baseValue = 1f + // roll fudge dice and get value [-3, 3] as [0, 6] + val varSelected = Fudge3(HQRNG()).rollForArray() + // get multiplier from json. Assuming percentile + val multiplier = jsonObject.get(s).asJsonArray.get(varSelected).asInt + val realValue = baseValue * multiplier / 100f + + p.actorValue.set(s, realValue) + } + } + + private fun setAVBooleans(p: ActorWithBody, elemSet: Array, jsonObject: JsonObject) { + for (s in elemSet) { + p.actorValue.set(s, jsonObject.get(s).asBoolean) + } + } +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/Factionable b/src/com/Torvald/Terrarum/Actors/Factionable new file mode 100644 index 000000000..1ad44cfb0 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Factionable @@ -0,0 +1,17 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.Terrarum.Actors.Faction.Faction; + +import java.util.HashSet; + +/** + * Created by minjaesong on 16-02-15. + */ +public interface Factionable { + + void assignFaction(Faction f); + void unassignFaction(Faction f); + HashSet getAssignedFactions(); + void clearFactionAssigning(); + +} diff --git a/src/com/Torvald/Terrarum/Actors/Factionable.kt b/src/com/Torvald/Terrarum/Actors/Factionable.kt new file mode 100644 index 000000000..cad117824 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Factionable.kt @@ -0,0 +1,15 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.Terrarum.Actors.Faction.Faction +import java.util.* + +/** + * Created by minjaesong on 16-03-14. + */ +interface Factionable { + + fun assignFaction(f: Faction) + fun unassignFaction(f: Faction) + var faction: HashSet? + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/Glowing b/src/com/Torvald/Terrarum/Actors/Glowing new file mode 100644 index 000000000..01be025aa --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Glowing @@ -0,0 +1,15 @@ +package com.Torvald.Terrarum.Actors; + +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; + +/** + * Created by minjaesong on 16-01-25. + */ +public interface Glowing { + + void drawGlow(GameContainer gc, Graphics g); + + void updateGlowSprite(GameContainer gc, int delta_t); + +} diff --git a/src/com/Torvald/Terrarum/Actors/Glowing.kt b/src/com/Torvald/Terrarum/Actors/Glowing.kt new file mode 100644 index 000000000..1890e2820 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Glowing.kt @@ -0,0 +1,13 @@ +package com.Torvald.Terrarum.Actors + +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics + +/** + * Created by minjaesong on 16-03-14. + */ +interface Glowing { + fun drawGlow(gc: GameContainer, g: Graphics) + + fun updateGlowSprite(gc: GameContainer, delta: Int) +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/LandHolder.kt b/src/com/Torvald/Terrarum/Actors/LandHolder.kt new file mode 100644 index 000000000..a246d0960 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/LandHolder.kt @@ -0,0 +1,19 @@ +package com.Torvald.Terrarum.Actors + +import java.util.* + +/** + * Created by minjaesong on 16-03-14. + */ +interface LandHolder { + + /** + * Absolute tile index. index(x, y) = y * map.width + x + * The arraylist will be saved in JSON format with GSON. + */ + var houseDesignation: ArrayList? + fun addHouseTile(x: Int, y: Int); + fun removeHouseTile(x: Int, y: Int); + fun clearHouseDesignation(); + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/Landholder b/src/com/Torvald/Terrarum/Actors/Landholder new file mode 100644 index 000000000..a76f694f1 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Landholder @@ -0,0 +1,16 @@ +package com.Torvald.Terrarum.Actors; + +import java.util.ArrayList; + +/** + * Created by minjaesong on 16-02-20. + */ +public interface Landholder { + + ArrayList getHouseDesignation(); + void setHouseDesignation(ArrayList list); + void addHouseTile(int x, int y); + void removeHouseTile(int x, int y); + void clearHouseDesignation(); + +} diff --git a/src/com/Torvald/Terrarum/Actors/Luminous b/src/com/Torvald/Terrarum/Actors/Luminous new file mode 100644 index 000000000..f0b1e7730 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Luminous @@ -0,0 +1,11 @@ +package com.Torvald.Terrarum.Actors; + +/** + * Created by minjaesong on 16-02-19. + */ +public interface Luminous { + + void setLuminance(char RGB); + char getLuminance(); + +} diff --git a/src/com/Torvald/Terrarum/Actors/Luminous.kt b/src/com/Torvald/Terrarum/Actors/Luminous.kt new file mode 100644 index 000000000..6fc62470e --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Luminous.kt @@ -0,0 +1,24 @@ +package com.Torvald.Terrarum.Actors + +/** + * Created by minjaesong on 16-03-14. + */ +interface Luminous { + + /** + * Recommended implementation: + * + override var luminosity: Char + get() = if (actorValue.get("luminosity") != null) { + actorValue.get("luminosity") as Char + } + else { + 0 as Char + } + set(value) { + actorValue.set("luminosity", value) + } + */ + var luminosity: Char + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase b/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase new file mode 100644 index 000000000..eae22f103 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase @@ -0,0 +1,152 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.Terrarum.Actors.AI.ActorAI; +import com.Torvald.Terrarum.Actors.Faction.Faction; +import com.Torvald.Terrarum.GameItem.InventoryItem; +import com.Torvald.Terrarum.Terrarum; +import org.newdawn.slick.GameContainer; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashSet; + +/** + * Created by minjaesong on 16-01-31. + */ +public class NPCIntelligentBase extends ActorWithBody implements AIControlled, Pocketed, CanBeStoredAsItem, + Factionable, Landholder { + + private InventoryItem itemData; // keep it for extendibility, like Carriers in SC1 + private transient ActorAI ai; + private ActorInventory inventory; + + private HashSet factionSet = new HashSet<>(); + + /** + * Absolute tile index. index(x, y) = y * map.width + x
+ * The arraylist will be saved in JSON format with GSON. + */ + private ArrayList houseTiles = new ArrayList<>(); + + @Override + public void assignFaction(Faction f) { + factionSet.add(f); + } + + @Override + public void unassignFaction(Faction f) { + factionSet.remove(f); + } + + @Override + public HashSet getAssignedFactions() { + return factionSet; + } + + @Override + public void clearFactionAssigning() { + factionSet.clear(); + } + + @Override + public void attachItemData() { + itemData = new InventoryItem() { + @Override + public long getItemID() { + return 0; + } + + @Override + public float getWeight() { + return 0; + } + + @Override + public void effectWhileInPocket(GameContainer gc, int delta_t) { + + } + + @Override + public void effectWhenPickedUp(GameContainer gc, int delta_t) { + + } + + @Override + public void primaryUse(GameContainer gc, int delta_t) { + + } + + @Override + public void secondaryUse(GameContainer gc, int delta_t) { + + } + + @Override + public void effectWhenThrownAway(GameContainer gc, int delta_t) { + + } + }; + } + + @Override + public float getItemWeight() { + return super.getMass(); + } + + @Override + public ArrayList getHouseDesignation() { + return houseTiles; + } + + @Override + public void setHouseDesignation(ArrayList list) { + houseTiles = list; + } + + @Override + public void addHouseTile(int x, int y) { + houseTiles.add(Terrarum.game.map.width * y + x); + } + + @Override + public void removeHouseTile(int x, int y) { + houseTiles.remove(new Integer(Terrarum.game.map.width * y + x)); + } + + @Override + public void clearHouseDesignation() { + houseTiles.clear(); + } + + @Override + public void stopUpdateAndDraw() { + super.setUpdate(false); + super.setVisible(false); + } + + @Override + public void resumeUpdateAndDraw() { + super.setUpdate(true); + super.setVisible(true); + } + + @Override + public InventoryItem getItemData() { + return itemData; + } + + @Override + public ActorInventory getInventory() { + return null; + } + + @Override + public void overwriteInventory(ActorInventory inventory) { + this.inventory = inventory; + } + + @Override + public void attachAI(ActorAI ai) { + this.ai = ai; + } +} diff --git a/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.kt b/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.kt new file mode 100644 index 000000000..88e9aa0f6 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.kt @@ -0,0 +1,103 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.Terrarum.Actors.AI.ActorAI +import com.Torvald.Terrarum.Actors.Faction.Faction +import com.Torvald.Terrarum.GameItem.InventoryItem +import com.Torvald.Terrarum.Terrarum +import org.newdawn.slick.GameContainer +import java.util.* + +/** + * Created by minjaesong on 16-03-14. + */ +open class NPCIntelligentBase : ActorWithBody() + , AIControlled, Pocketed, CanBeStoredAsItem, Factionable, LandHolder { + + override var itemData: InventoryItem? = null + + @Transient private var ai: ActorAI? = null + override var inventory: ActorInventory? = null + + private val factionSet = HashSet() + + override var referenceID: Long? = null + + override var faction: HashSet? = null + + override var houseDesignation: ArrayList? = null + /** + * Absolute tile index. index(x, y) = y * map.width + x + * The arraylist will be saved in JSON format with GSON. + */ + private var houseTiles = ArrayList() + + override fun assignFaction(f: Faction) { + factionSet.add(f) + } + + override fun unassignFaction(f: Faction) { + factionSet.remove(f) + } + + override fun attachItemData() { + itemData = object : InventoryItem { + override fun getItemID(): Long { + return 0 + } + + override fun getWeight(): Float { + return 0f + } + + override fun effectWhileInPocket(gc: GameContainer, delta_t: Int) { + + } + + override fun effectWhenPickedUp(gc: GameContainer, delta_t: Int) { + + } + + override fun primaryUse(gc: GameContainer, delta_t: Int) { + + } + + override fun secondaryUse(gc: GameContainer, delta_t: Int) { + + } + + override fun effectWhenThrownAway(gc: GameContainer, delta_t: Int) { + + } + } + } + + override fun getItemWeight(): Float { + return mass + } + + override fun addHouseTile(x: Int, y: Int) { + houseTiles.add(Terrarum.game.map.width * y + x) + } + + override fun removeHouseTile(x: Int, y: Int) { + houseTiles.remove(Terrarum.game.map.width * y + x) + } + + override fun clearHouseDesignation() { + houseTiles.clear() + } + + override fun stopUpdateAndDraw() { + isUpdate = false + isVisible = false + } + + override fun resumeUpdateAndDraw() { + isUpdate = true + isVisible = true + } + + override fun attachAI(ai: ActorAI) { + this.ai = ai + } +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/PFSigrid b/src/com/Torvald/Terrarum/Actors/PFSigrid new file mode 100644 index 000000000..197a1b9f8 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/PFSigrid @@ -0,0 +1,104 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.JsonFetcher; +import com.Torvald.Terrarum.Actors.Faction.Faction; +import com.Torvald.Terrarum.Game; +import com.Torvald.spriteAnimation.SpriteAnimation; +import com.google.gson.JsonObject; +import org.lwjgl.Sys; +import org.newdawn.slick.SlickException; + +import java.io.IOException; + +/** + * Created by minjaesong on 16-02-03. + */ +public class PFSigrid { + + private static String FACTION_PATH = "./res/raw/"; + + public Player build() throws SlickException { + Player p = new Player(); + + p.sprite = new SpriteAnimation(); + p.sprite.setDimension(28, 51); + p.sprite.setSpriteImage("res/graphics/sprites/test_player.png"); + p.sprite.setDelay(200); + p.sprite.setRowsAndFrames(1, 1); + p.sprite.setAsVisible(); + p.sprite.composeSprite(); + + p.spriteGlow = new SpriteAnimation(); + p.spriteGlow.setDimension(28, 51); + p.spriteGlow.setSpriteImage("res/graphics/sprites/test_player_glow.png"); + p.spriteGlow.setDelay(200); + p.spriteGlow.setRowsAndFrames(1, 1); + p.spriteGlow.setAsVisible(); + p.spriteGlow.composeSprite(); + + p.actorValue = new ActorValue(); + p.actorValue.set("scale", 1.0f); + p.actorValue.set("speed", 4.0f); + p.actorValue.set("speedmult", 1.0f); + p.actorValue.set("accel", Player.WALK_ACCEL_BASE); + p.actorValue.set("accelmult", 1.0f); + + p.actorValue.set("jumppower", 5f); + + p.actorValue.set("basemass", 80f); + + p.actorValue.set("physiquemult", 1); // Constant 1.0 for player, meant to be used by random mobs + /** + * fixed value, or 'base value', from creature strength of Dwarf Fortress. + * Human race uses 1000. (see CreatureHuman.json) + */ + p.actorValue.set("strength", 1414); + p.actorValue.set("encumbrance", 1000); + + p.actorValue.set("name", "Sigrid"); + + p.actorValue.set("intelligent", true); + + p.actorValue.set("luminosity", 22819); + + p.actorValue.set("selectedtile", 16); + + p.setHitboxDimension(18, 46, 8, 0); + + p.setInventory(new ActorInventory(0x7FFFFFFF, true)); + + p.setPosition(4096 * 16, 300 * 16); + + p.assignFaction(loadFactioningData("FactionSigrid.json")); + + return p; + } + + private Faction loadFactioningData(String filename) { + JsonObject jsonObject = null; + try { + jsonObject = JsonFetcher.readJson(FACTION_PATH + filename); + } + catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + + Faction faction = new Faction(jsonObject.get("factionname").getAsString()); + + jsonObject.get("factionamicable").getAsJsonArray().forEach( + jobj -> faction.addFactionAmicable(jobj.getAsString()) + ); + jsonObject.get("factionneutral").getAsJsonArray().forEach( + jobj -> faction.addFactionNeutral(jobj.getAsString()) + ); + jsonObject.get("factionhostile").getAsJsonArray().forEach( + jobj -> faction.addFactionHostile(jobj.getAsString()) + ); + jsonObject.get("factionfearful").getAsJsonArray().forEach( + jobj -> faction.addFactionFearful(jobj.getAsString()) + ); + + return faction; + } +} diff --git a/src/com/Torvald/Terrarum/Actors/PFSigrid.kt b/src/com/Torvald/Terrarum/Actors/PFSigrid.kt new file mode 100644 index 000000000..58f6b62b7 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/PFSigrid.kt @@ -0,0 +1,96 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.JsonFetcher +import com.Torvald.Terrarum.Actors.Faction.Faction +import com.Torvald.spriteAnimation.SpriteAnimation +import com.google.gson.JsonObject +import org.newdawn.slick.SlickException +import java.io.IOException + +/** + * Created by minjaesong on 16-03-14. + */ +class PFSigrid { + + @Throws(SlickException::class) + fun build(): Player { + val p = Player() + + p.sprite = SpriteAnimation() + p.sprite!!.setDimension(28, 51) + p.sprite!!.setSpriteImage("res/graphics/sprites/test_player.png") + p.sprite!!.setDelay(200) + p.sprite!!.setRowsAndFrames(1, 1) + p.sprite!!.setAsVisible() + p.sprite!!.composeSprite() + + p.spriteGlow = SpriteAnimation() + p.spriteGlow!!.setDimension(28, 51) + p.spriteGlow!!.setSpriteImage("res/graphics/sprites/test_player_glow.png") + p.spriteGlow!!.setDelay(200) + p.spriteGlow!!.setRowsAndFrames(1, 1) + p.spriteGlow!!.setAsVisible() + p.spriteGlow!!.composeSprite() + + p.actorValue = ActorValue() + p.actorValue.set("scale", 1.0f) + p.actorValue.set("speed", 4.0f) + p.actorValue.set("speedmult", 1.0f) + p.actorValue.set("accel", Player.WALK_ACCEL_BASE) + p.actorValue.set("accelmult", 1.0f) + + p.actorValue.set("jumppower", 5f) + + p.actorValue.set("basemass", 80f) + + p.actorValue.set("physiquemult", 1) // Constant 1.0 for player, meant to be used by random mobs + /** + * fixed value, or 'base value', from creature strength of Dwarf Fortress. + * Human race uses 1000. (see CreatureHuman.json) + */ + p.actorValue.set("strength", 1414) + p.actorValue.set("encumbrance", 1000) + + p.actorValue.set("name", "Sigrid") + + p.actorValue.set("intelligent", true) + + p.actorValue.set("luminosity", 22819) + + p.actorValue.set("selectedtile", 16) + + p.setHitboxDimension(18, 46, 8, 0) + + p.inventory = ActorInventory(0x7FFFFFFF, true) + + p.setPosition((4096 * 16).toFloat(), (300 * 16).toFloat()) + + p.assignFaction(loadFactioningData("FactionSigrid.json")) + + return p + } + + private fun loadFactioningData(filename: String): Faction { + var jsonObject: JsonObject? = null + try { + jsonObject = JsonFetcher.readJson(FACTION_PATH + filename) + } catch (e: IOException) { + e.printStackTrace() + System.exit(-1) + } + + val faction = Faction(jsonObject!!.get("factionname").asString) + + jsonObject.get("factionamicable").asJsonArray.forEach { jobj -> faction.addFactionAmicable(jobj.asString) } + jsonObject.get("factionneutral").asJsonArray.forEach { jobj -> faction.addFactionNeutral(jobj.asString) } + jsonObject.get("factionhostile").asJsonArray.forEach { jobj -> faction.addFactionHostile(jobj.asString) } + jsonObject.get("factionfearful").asJsonArray.forEach { jobj -> faction.addFactionFearful(jobj.asString) } + + return faction + } + + companion object { + + private val FACTION_PATH = "./res/raw/" + } +} diff --git a/src/com/Torvald/Terrarum/Actors/PhysTestBall b/src/com/Torvald/Terrarum/Actors/PhysTestBall new file mode 100644 index 000000000..930bb6b66 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/PhysTestBall @@ -0,0 +1,29 @@ +package com.Torvald.Terrarum.Actors; + +import org.newdawn.slick.Color; +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; + +/** + * Created by minjaesong on 16-03-05. + */ +public class PhysTestBall extends ActorWithBody { + + public PhysTestBall() { + super(); + setHitboxDimension(16, 16, 0, 0); + setVisible(true); + setMass(10f); + } + + @Override + public void drawBody(GameContainer gc, Graphics g) { + g.setColor(Color.orange); + g.fillOval( + getHitbox().getPosX() + , getHitbox().getPosY() + , getHitbox().getWidth() + , getHitbox().getHeight() + ); + } +} diff --git a/src/com/Torvald/Terrarum/Actors/PhysTestBall.kt b/src/com/Torvald/Terrarum/Actors/PhysTestBall.kt new file mode 100644 index 000000000..d4c009258 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/PhysTestBall.kt @@ -0,0 +1,25 @@ +package com.Torvald.Terrarum.Actors + +import org.newdawn.slick.Color +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics + +/** + * Created by minjaesong on 16-03-14. + */ +class PhysTestBall : ActorWithBody { + constructor(): super() { + setHitboxDimension(16, 16, 0, 0) + isVisible = true + mass = 10f + } + + override fun drawBody(gc: GameContainer, g: Graphics) { + g.color = Color.orange + g.fillOval( + hitbox!!.getPosX(), + hitbox!!.getPosY(), + hitbox!!.getWidth(), + hitbox!!.getHeight()) + } +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/Player b/src/com/Torvald/Terrarum/Actors/Player new file mode 100644 index 000000000..81db85bd4 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Player @@ -0,0 +1,571 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.Terrarum.Actors.Faction.Faction; +import com.Torvald.Terrarum.GameControl.EnumKeyFunc; +import com.Torvald.Terrarum.GameControl.KeyMap; +import com.Torvald.Terrarum.MapDrawer.MapDrawer; +import com.Torvald.Terrarum.Terrarum; +import com.Torvald.spriteAnimation.SpriteAnimation; +import com.jme3.math.FastMath; +import com.sun.istack.internal.NotNull; +import com.sun.istack.internal.Nullable; +import org.lwjgl.input.Controller; +import org.lwjgl.input.Controllers; +import org.newdawn.slick.*; + +import java.io.Serializable; +import java.util.HashSet; + +/** + * Created by minjaesong on 15-12-31. + */ +public class Player extends ActorWithBody implements Controllable, Pocketed, Factionable, Luminous { + + public transient @Nullable Controllable vehicleRiding; + + int jumpCounter = 0; + int walkPowerCounter = 0; + private transient final int MAX_JUMP_LENGTH = 17; // use 17; in internal frames + /** + * experimental value. + */ + // private transient final float JUMP_ACCELERATION_MOD = ???f / 10000f; //quadratic mode + private transient final float JUMP_ACCELERATION_MOD = 170f / 10000f; //linear mode + private transient final int WALK_FRAMES_TO_MAX_ACCEL = 6; + + public float readonly_totalX = 0, readonly_totalY = 0; + + boolean jumping = false; + + @NotNull int walkHeading; + + private transient final int LEFT = 1; + private transient final int RIGHT = 2; + + private transient final int KEY_NULL = -1; + private transient int prevHMoveKey = KEY_NULL; + private transient int prevVMoveKey = KEY_NULL; + + static transient final float ACCEL_MULT_IN_FLIGHT = 0.48f; + static transient final float WALK_STOP_ACCEL = 0.32f; + static transient final float WALK_ACCEL_BASE = 0.32f; + + private boolean noClip = false; + + public static transient final long PLAYER_REF_ID = 0x51621D; + + private transient final float AXIS_POSMAX = 1.0f; + private transient final int GAMEPAD_JUMP = 5; + + private transient final int TSIZE = MapDrawer.TILE_SIZE; + + private HashSet factionSet = new HashSet<>(); + + private transient final int BASE_DENSITY = 1020; + + + /** + * Creates new Player instance with empty elements (sprites, actorvalue, etc.).
+ * + * Use PlayerBuildFactory to build player! + * + * @throws SlickException + */ + public Player() throws SlickException { + super(); + referenceID = PLAYER_REF_ID; + setVisible(true); + super.setDensity(BASE_DENSITY); + } + + @Override + public void update(GameContainer gc, int delta_t) { + if (vehicleRiding instanceof Player) throw new RuntimeException("Attempted to 'ride' " + + "player object."); + + updatePhysicalInfos(); + super.update(gc, delta_t); + + updateSprite(delta_t); + + updateMovementControl(); + + if (noClip) { super.setGrounded(true); } + + } + + private void updatePhysicalInfos() { + super.setScale(actorValue.getAsFloat("scale")); + super.setMass(actorValue.getAsFloat("basemass") + * FastMath.pow(super.getScale(), 3)); + if (super.getElasticity() != 0) super.setElasticity(0); + } + + /** + * + * @param left (even if the game is joypad controlled, you must give valid value) + * @param absAxisVal (set AXIS_POSMAX if keyboard controlled) + */ + private void walkHorizontal(boolean left, float absAxisVal) { + //if ((!super.isWalledLeft() && left) || (!super.isWalledRight() && !left)) { + readonly_totalX = super.getVeloX() + + + actorValue.getAsFloat("accel") + * actorValue.getAsFloat("accelmult") + * FastMath.sqrt(super.getScale()) + * applyAccelRealism(walkPowerCounter) + * (left ? -1 : 1) + * absAxisVal; + + super.setVeloX(readonly_totalX); + + if (walkPowerCounter < WALK_FRAMES_TO_MAX_ACCEL) { + walkPowerCounter += 1; + } + + // Clamp veloX + super.setVeloX( + absClamp(super.getVeloX() + , actorValue.getAsFloat("speed") + * actorValue.getAsFloat("speedmult") + * FastMath.sqrt(super.getScale()) + ) + ); + + // Heading flag + if (left) walkHeading = LEFT; + else walkHeading = RIGHT; + //} + } + + /** + * + * @param up (even if the game is joypad controlled, you must give valid value) + * @param absAxisVal (set AXIS_POSMAX if keyboard controlled) + */ + private void walkVertical(boolean up, float absAxisVal) { + readonly_totalY = super.getVeloY() + + + actorValue.getAsFloat("accel") + * actorValue.getAsFloat("accelmult") + * FastMath.sqrt(super.getScale()) + * applyAccelRealism(walkPowerCounter) + * (up ? -1 : 1) + * absAxisVal; + + super.setVeloY(readonly_totalY); + + if (walkPowerCounter < WALK_FRAMES_TO_MAX_ACCEL) { + walkPowerCounter += 1; + } + + // Clamp veloX + super.setVeloY( + absClamp(super.getVeloY() + , actorValue.getAsFloat("speed") + * actorValue.getAsFloat("speedmult") + * FastMath.sqrt(super.getScale()) + ) + ); + } + + /** + * For realistic accelerating while walking. + * + * Naïve 'veloX += 3' is actually like: + * + * a + * | ------------ + * | + * | + * 0+------············ t + * + * which is unrealistic, so this method tries to introduce some realism by doing: + * + * a + * | ------------ + * | --- + * | - + * | --- + * 0+----··················· t + * + * + * @param x + */ + private float applyAccelRealism(int x) { + return 0.5f + 0.5f * -FastMath.cos(10 * x / (WALK_FRAMES_TO_MAX_ACCEL * FastMath.PI)); + } + + private void walkHStop() { + if (super.getVeloX() > 0) { + super.setVeloX(super.getVeloX() + - + actorValue.getAsFloat("accel") + * actorValue.getAsFloat("accelmult") + * FastMath.sqrt(super.getScale()) + ); + + // compensate overshoot + if (super.getVeloX() < 0) + super.setVeloX(0); + } + else if (super.getVeloX() < 0) { + super.setVeloX(super.getVeloX() + + + actorValue.getAsFloat("accel") + * actorValue.getAsFloat("accelmult") + * FastMath.sqrt(super.getScale()) + ); + + // compensate overshoot + if (super.getVeloX() > 0) + super.setVeloX(0); + } + else { + super.setVeloX(0); + } + + walkPowerCounter = 0; + } + + private void walkVStop() { + if (super.getVeloY() > 0) { + super.setVeloY(super.getVeloY() + - + WALK_STOP_ACCEL + * actorValue.getAsFloat("accelmult") + * FastMath.sqrt(super.getScale()) + ); + + // compensate overshoot + if (super.getVeloY() < 0) + super.setVeloY(0); + } + else if (super.getVeloY() < 0) { + super.setVeloY(super.getVeloY() + + + WALK_STOP_ACCEL + * actorValue.getAsFloat("accelmult") + * FastMath.sqrt(super.getScale()) + ); + + // compensate overshoot + if (super.getVeloY() > 0) + super.setVeloY(0); + } + else { + super.setVeloY(0); + } + + walkPowerCounter = 0; + } + + private void updateMovementControl() { + if (!noClip) { + if (super.isGrounded()) { + actorValue.set("accelmult", 1f); + } else { + actorValue.set("accelmult", ACCEL_MULT_IN_FLIGHT); + } + } + else { + actorValue.set("accelmult", 1f); + } + } + + public void processInput(Input input) { + Controller gamepad = null; + float axisX = 0, axisY = 0, axisRX = 0, axisRY = 0; + if (Terrarum.hasController) { + gamepad = Controllers.getController(0); + axisX = gamepad.getAxisValue(0); + axisY = gamepad.getAxisValue(1); + axisRX = gamepad.getAxisValue(2); + axisRY = gamepad.getAxisValue(3); + + if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0; + if (Math.abs(axisY) < Terrarum.CONTROLLER_DEADZONE) axisY = 0; + if (Math.abs(axisRX) < Terrarum.CONTROLLER_DEADZONE) axisRX = 0; + if (Math.abs(axisRY) < Terrarum.CONTROLLER_DEADZONE) axisRY = 0; + } + + /** + * L-R stop + */ + if (Terrarum.hasController) { + if (axisX == 0) { + walkHStop(); + } + } + else { + // ↑F, ↑S + if (!isFuncDown(input, EnumKeyFunc.MOVE_LEFT) + && !isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) { + walkHStop(); + prevHMoveKey = KEY_NULL; + } + } + /** + * U-D stop + */ + if (Terrarum.hasController) { + if (axisY == 0) { + walkVStop(); + } + } + else { + // ↑E + // ↑D + if (isNoClip() + && !isFuncDown(input, EnumKeyFunc.MOVE_UP) + && !isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) { + walkVStop(); + prevVMoveKey = KEY_NULL; + } + } + + /** + * Left/Right movement + */ + + if (Terrarum.hasController) { + if (axisX != 0) { + walkHorizontal(axisX < 0, AXIS_POSMAX); + } + } + else { + // ↑F, ↓S + if (isFuncDown(input, EnumKeyFunc.MOVE_RIGHT) + && !isFuncDown(input, EnumKeyFunc.MOVE_LEFT)) { + walkHorizontal(false, AXIS_POSMAX); + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT); + } + // ↓F, ↑S + else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) + && !isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) { + walkHorizontal(true, AXIS_POSMAX); + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT); + } + // ↓F, ↓S + else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) + && isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) { + if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) { + walkHorizontal(false, AXIS_POSMAX); + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT); + } + else if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT)) { + walkHorizontal(true, AXIS_POSMAX); + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT); + } + } + } + + /** + * Up/Down movement + */ + if (noClip) { + if (Terrarum.hasController) { + if (axisY != 0) { + walkVertical(axisY > 0, AXIS_POSMAX); + } + } + else { + // ↑E + // ↓D + if (isFuncDown(input, EnumKeyFunc.MOVE_DOWN) + && !isFuncDown(input, EnumKeyFunc.MOVE_UP)) { + walkVertical(false, AXIS_POSMAX); + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN); + } + // ↓E + // ↑D + else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) + && !isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) { + walkVertical(true, AXIS_POSMAX); + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP); + } + // ↓E + // ↓D + else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) + && isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) { + if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) { + walkVertical(false, AXIS_POSMAX); + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN); + } + else if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN)) { + walkVertical(true, AXIS_POSMAX); + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP); + } + } + } + } + + /** + * Jump control + */ + if (isFuncDown(input, EnumKeyFunc.JUMP) + || (Terrarum.hasController && gamepad.isButtonPressed(GAMEPAD_JUMP))) { + if (!noClip) { + if (super.isGrounded()) { + jumping = true; + } + jump(); + } + else { + walkVertical(true, AXIS_POSMAX); + } + } + else { + jumping = false; + jumpCounter = 0; + } + + } + + public void keyPressed(int key, char c) { + + } + + /** + * See ./work_files/Jump\ power\ by\ pressing\ time.gcx + */ + private void jump() { + if (jumping) { + float len = MAX_JUMP_LENGTH; + float pwr = actorValue.getAsFloat("jumppower"); + + // increment jump counter + if (jumpCounter < len) jumpCounter += 1; + // quadratic time (convex) mode + /* + float sumT = (jumpCounter * (jumpCounter + 1)) / 2f; + float timedJumpCharge = ((len + 1) / 2f) - (sumT / len); + if (timedJumpCharge < 0) timedJumpCharge = 0; + + float jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD; + + super.setVeloY(super.getVeloY() + - jumpAcc + ); + */ + + // linear time mode + float init = (len + 1) / 2f; + float timedJumpCharge = init - (init / len) * jumpCounter; + if (timedJumpCharge < 0) timedJumpCharge = 0; + + float jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD + * FastMath.sqrt(getScale()); + + super.setVeloY(super.getVeloY() + - jumpAcc + ); + + // concave mode? + } + + // for mob AI: + //super.setVeloY(super.getVeloY() + // - + // pwr * FastMath.sqrt(super.getScale()) + //); + } + + private float jumpFuncLin(float pwr, float len) { + return -(pwr / len) * jumpCounter; + } + + private float jumpFuncSqu(float pwr, float len) { + return (pwr / (len * len)) + * (jumpCounter - len) + * (jumpCounter - len) // square + - pwr; + } + + private float jumpFuncExp(float pwr, float len) { + float a = FastMath.pow(pwr + 1, 1 / len); + return -FastMath.pow(a, len) + 1; + } + + private boolean isFuncDown(Input input, EnumKeyFunc fn) { + return input.isKeyDown(KeyMap.getKeyCode(fn)); + } + + private float absClamp(float i, float ceil) { + if (i > 0) + return (i > ceil) ? ceil : i; + else if (i < 0) + return (-i > ceil) ? -ceil : i; + else + return 0; + } + + private void updateSprite(int delta_t) { + sprite.update(delta_t); + if (spriteGlow != null) { + spriteGlow.update(delta_t); + } + + if (super.isGrounded()) { + if (walkHeading == LEFT) { + sprite.flip(true, false); + if (spriteGlow != null) { + spriteGlow.flip(true, false); + } + } + else { + sprite.flip(false, false); + if (spriteGlow != null) { + spriteGlow.flip(false, false); + } + } + } + } + + public boolean isNoClip() { + return noClip; + } + + public void setNoClip(boolean b) { + noClip = b; + } + + public ActorValue getActorValue() { + return actorValue; + } + + public SpriteAnimation getSpriteGlow() { + return spriteGlow; + } + + @Override + public void assignFaction(Faction f) { + factionSet.add(f); + } + + @Override + public void unassignFaction(Faction f) { + factionSet.remove(f); + } + + @Override + public HashSet getAssignedFactions() { + return factionSet; + } + + @Override + public void clearFactionAssigning() { + factionSet.clear(); + } + + @Override + public void setLuminance(char RGB) { + actorValue.set("luminosity", (int) RGB); + } + + @Override + public char getLuminance() { + return actorValue.hasKey("luminosity") ? + (char) actorValue.getAsInt("luminosity") : 0; + } +} diff --git a/src/com/Torvald/Terrarum/Actors/Player.kt b/src/com/Torvald/Terrarum/Actors/Player.kt new file mode 100644 index 000000000..cea4e9bde --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Player.kt @@ -0,0 +1,524 @@ +package com.Torvald.Terrarum.Actors + +import com.Torvald.Terrarum.Actors.Faction.Faction +import com.Torvald.Terrarum.GameControl.EnumKeyFunc +import com.Torvald.Terrarum.GameControl.KeyMap +import com.Torvald.Terrarum.MapDrawer.MapDrawer +import com.Torvald.Terrarum.Terrarum +import com.Torvald.spriteAnimation.SpriteAnimation +import com.jme3.math.FastMath +import org.lwjgl.input.Controller +import org.lwjgl.input.Controllers +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Input +import org.newdawn.slick.SlickException +import java.util.* + +/** + * Created by minjaesong on 16-03-14. + */ + +/** + * empirical value. + */ +// private transient final float JUMP_ACCELERATION_MOD = ???f / 10000f; //quadratic mode +@Transient private const val JUMP_ACCELERATION_MOD = 170f / 10000f //linear mode +@Transient private const val WALK_FRAMES_TO_MAX_ACCEL = 6 + +@Transient private const val LEFT = 1 +@Transient private const val RIGHT = 2 + +@Transient private const val KEY_NULL = -1 + +class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, LandHolder { + + var vehicleRiding: Controllable? = null + + internal var jumpCounter = 0 + internal var walkPowerCounter = 0 + @Transient private val MAX_JUMP_LENGTH = 17 // use 17; in internal frames + + private var readonly_totalX = 0f + private var readonly_totalY = 0f + + internal var jumping = false + + internal var walkHeading: Int = 0 + + @Transient private var prevHMoveKey = KEY_NULL + @Transient private var prevVMoveKey = KEY_NULL + + internal var noClip = false + + @Transient private val AXIS_POSMAX = 1.0f + @Transient private val GAMEPAD_JUMP = 5 + + @Transient private val TSIZE = MapDrawer.TILE_SIZE + + private val factionSet = HashSet() + + @Transient private val BASE_DENSITY = 1020 + + override var referenceID: Long? = PLAYER_REF_ID + + /** Must be set by PlayerFactory */ + override var inventory: ActorInventory? = null + + /** Must be set by PlayerFactory */ + override var faction: HashSet? = null + + override var houseDesignation: ArrayList? = null + + override var luminosity: Char + get() = if (actorValue.get("luminosity") != null) actorValue.getAsInt("luminosity").toChar() + else 0 as Char + set(value) { + actorValue.set("luminosity", value) + } + + companion object { + @Transient internal const val ACCEL_MULT_IN_FLIGHT = 0.48f + @Transient internal const val WALK_STOP_ACCEL = 0.32f + @Transient internal const val WALK_ACCEL_BASE = 0.32f + + @Transient val PLAYER_REF_ID: Long = 0x51621D + } + + /** + * Creates new Player instance with empty elements (sprites, actorvalue, etc.). + + * **Use PlayerFactory to build player!** + + * @throws SlickException + */ + @Throws(SlickException::class) + constructor() : super() { + isVisible = true + super.setDensity(BASE_DENSITY) + } + + override fun update(gc: GameContainer, delta_t: Int) { + if (vehicleRiding is Player) + throw RuntimeException("Attempted to 'ride' " + "player object.") + + updatePhysicalInfos() + super.update(gc, delta_t) + + updateSprite(delta_t) + + updateMovementControl() + + if (noClip) { + grounded = true + } + + } + + private fun updatePhysicalInfos() { + scale = actorValue.getAsFloat("scale") + mass = actorValue.getAsFloat("basemass") * FastMath.pow(scale, 3f) + if (elasticity != 0f) elasticity = 0f + } + + /** + + * @param left (even if the game is joypad controlled, you must give valid value) + * * + * @param absAxisVal (set AXIS_POSMAX if keyboard controlled) + */ + private fun walkHorizontal(left: Boolean, absAxisVal: Float) { + //if ((!super.isWalledLeft() && left) || (!super.isWalledRight() && !left)) { + readonly_totalX = veloX + + actorValue.getAsFloat("accel") * + actorValue.getAsFloat("accelmult") * + FastMath.sqrt(scale) * + applyAccelRealism(walkPowerCounter) * + (if (left) -1 else 1).toFloat() * + absAxisVal + + veloX = readonly_totalX + + if (walkPowerCounter < WALK_FRAMES_TO_MAX_ACCEL) { + walkPowerCounter += 1 + } + + // Clamp veloX + veloX = absClamp(veloX, actorValue.getAsFloat("speed") + * actorValue.getAsFloat("speedmult") + * FastMath.sqrt(scale)) + + // Heading flag + if (left) + walkHeading = LEFT + else + walkHeading = RIGHT + //} + } + + /** + + * @param up (even if the game is joypad controlled, you must give valid value) + * * + * @param absAxisVal (set AXIS_POSMAX if keyboard controlled) + */ + private fun walkVertical(up: Boolean, absAxisVal: Float) { + readonly_totalY = veloY + + actorValue.getAsFloat("accel") * + actorValue.getAsFloat("accelmult") * + FastMath.sqrt(scale) * + applyAccelRealism(walkPowerCounter) * + (if (up) -1 else 1).toFloat() * + absAxisVal + + veloY = readonly_totalY + + if (walkPowerCounter < WALK_FRAMES_TO_MAX_ACCEL) { + walkPowerCounter += 1 + } + + // Clamp veloX + veloY = absClamp(veloY, actorValue.getAsFloat("speed") + * actorValue.getAsFloat("speedmult") + * FastMath.sqrt(scale)) + } + + /** + * For realistic accelerating while walking. + + * Naïve 'veloX += 3' is actually like: + + * a + * | ------------ + * | + * | + * 0+------············ t + + * which is unrealistic, so this method tries to introduce some realism by doing: + + * a + * | ------------ + * | --- + * | - + * | --- + * 0+----··················· t + + + * @param x + */ + private fun applyAccelRealism(x: Int): Float { + return 0.5f + 0.5f * -FastMath.cos(10 * x / (WALK_FRAMES_TO_MAX_ACCEL * FastMath.PI)) + } + + private fun walkHStop() { + if (veloX > 0) { + veloX -= actorValue.getAsFloat("accel") * + actorValue.getAsFloat("accelmult") * + FastMath.sqrt(scale) + + // compensate overshoot + if (veloX < 0) veloX = 0f + } else if (veloX < 0) { + veloX += actorValue.getAsFloat("accel") * + actorValue.getAsFloat("accelmult") * + FastMath.sqrt(scale) + + // compensate overshoot + if (veloX > 0) veloX = 0f + } else { + veloX = 0f + } + + walkPowerCounter = 0 + } + + private fun walkVStop() { + if (veloY > 0) { + veloY -= WALK_STOP_ACCEL * + actorValue.getAsFloat("accelmult") * + FastMath.sqrt(scale) + + // compensate overshoot + if (veloY < 0) + veloY = 0f + } else if (veloY < 0) { + veloY += WALK_STOP_ACCEL * + actorValue.getAsFloat("accelmult") * + FastMath.sqrt(scale) + + // compensate overshoot + if (veloY > 0) veloY = 0f + } else { + veloY = 0f + } + + walkPowerCounter = 0 + } + + private fun updateMovementControl() { + if (!noClip) { + if (grounded) { + actorValue.set("accelmult", 1f) + } else { + actorValue.set("accelmult", ACCEL_MULT_IN_FLIGHT) + } + } else { + actorValue.set("accelmult", 1f) + } + } + + override fun processInput(input: Input) { + var gamepad: Controller? = null + var axisX = 0f + var axisY = 0f + var axisRX = 0f + var axisRY = 0f + if (Terrarum.hasController) { + gamepad = Controllers.getController(0) + axisX = gamepad!!.getAxisValue(0) + axisY = gamepad.getAxisValue(1) + axisRX = gamepad.getAxisValue(2) + axisRY = gamepad.getAxisValue(3) + + if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0f + if (Math.abs(axisY) < Terrarum.CONTROLLER_DEADZONE) axisY = 0f + if (Math.abs(axisRX) < Terrarum.CONTROLLER_DEADZONE) axisRX = 0f + if (Math.abs(axisRY) < Terrarum.CONTROLLER_DEADZONE) axisRY = 0f + } + + /** + * L-R stop + */ + if (Terrarum.hasController) { + if (axisX == 0f) { + walkHStop() + } + } else { + // ↑F, ↑S + if (!isFuncDown(input, EnumKeyFunc.MOVE_LEFT) && !isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) { + walkHStop() + prevHMoveKey = KEY_NULL + } + } + /** + * U-D stop + */ + if (Terrarum.hasController) { + if (axisY == 0f) { + walkVStop() + } + } else { + // ↑E + // ↑D + if (isNoClip() + && !isFuncDown(input, EnumKeyFunc.MOVE_UP) + && !isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) { + walkVStop() + prevVMoveKey = KEY_NULL + } + } + + /** + * Left/Right movement + */ + + if (Terrarum.hasController) { + if (axisX != 0f) { + walkHorizontal(axisX < 0, AXIS_POSMAX) + } + } else { + // ↑F, ↓S + if (isFuncDown(input, EnumKeyFunc.MOVE_RIGHT) && !isFuncDown(input, EnumKeyFunc.MOVE_LEFT)) { + walkHorizontal(false, AXIS_POSMAX) + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT) + } else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) && !isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) { + walkHorizontal(true, AXIS_POSMAX) + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT) + } else if (isFuncDown(input, EnumKeyFunc.MOVE_LEFT) && isFuncDown(input, EnumKeyFunc.MOVE_RIGHT)) { + if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) { + walkHorizontal(false, AXIS_POSMAX) + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT) + } else if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_RIGHT)) { + walkHorizontal(true, AXIS_POSMAX) + prevHMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT) + } + }// ↓F, ↓S + // ↓F, ↑S + } + + /** + * Up/Down movement + */ + if (noClip) { + if (Terrarum.hasController) { + if (axisY != 0f) { + walkVertical(axisY > 0, AXIS_POSMAX) + } + } else { + // ↑E + // ↓D + if (isFuncDown(input, EnumKeyFunc.MOVE_DOWN) && !isFuncDown(input, EnumKeyFunc.MOVE_UP)) { + walkVertical(false, AXIS_POSMAX) + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN) + } else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) && !isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) { + walkVertical(true, AXIS_POSMAX) + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP) + } else if (isFuncDown(input, EnumKeyFunc.MOVE_UP) && isFuncDown(input, EnumKeyFunc.MOVE_DOWN)) { + if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) { + walkVertical(false, AXIS_POSMAX) + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN) + } else if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_DOWN)) { + walkVertical(true, AXIS_POSMAX) + prevVMoveKey = KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP) + } + }// ↓E + // ↓D + // ↓E + // ↑D + } + } + + /** + * Jump control + */ + if (isFuncDown(input, EnumKeyFunc.JUMP) || Terrarum.hasController && gamepad!!.isButtonPressed(GAMEPAD_JUMP)) { + if (!noClip) { + if (grounded) { + jumping = true + } + jump() + } else { + walkVertical(true, AXIS_POSMAX) + } + } else { + jumping = false + jumpCounter = 0 + } + + } + + override fun keyPressed(key: Int, c: Char) { + + } + + /** + * See ./work_files/Jump\ power\ by\ pressing\ time.gcx + */ + private fun jump() { + if (jumping) { + val len = MAX_JUMP_LENGTH.toFloat() + val pwr = actorValue.getAsFloat("jumppower") + + // increment jump counter + if (jumpCounter < len) jumpCounter += 1 + // quadratic time (convex) mode + /* + float sumT = (jumpCounter * (jumpCounter + 1)) / 2f; + float timedJumpCharge = ((len + 1) / 2f) - (sumT / len); + if (timedJumpCharge < 0) timedJumpCharge = 0; + + float jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD; + + super.setVeloY(veloY + - jumpAcc + ); + */ + + // linear time mode + val init = (len + 1) / 2f + var timedJumpCharge = init - init / len * jumpCounter + if (timedJumpCharge < 0) timedJumpCharge = 0f + + val jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * FastMath.sqrt(scale) + + veloY -= jumpAcc + + // concave mode? + } + + // for mob AI: + //super.setVeloY(veloY + // - + // pwr * FastMath.sqrt(scale) + //); + } + + private fun jumpFuncLin(pwr: Float, len: Float): Float { + return -(pwr / len) * jumpCounter + } + + private fun jumpFuncSqu(pwr: Float, len: Float): Float { + return pwr / (len * len) * (jumpCounter - len * jumpCounter - len) - pwr + } + + private fun jumpFuncExp(pwr: Float, len: Float): Float { + val a = FastMath.pow(pwr + 1, 1 / len) + return -FastMath.pow(a, len) + 1 + } + + private fun isFuncDown(input: Input, fn: EnumKeyFunc): Boolean { + return input.isKeyDown(KeyMap.getKeyCode(fn)) + } + + private fun absClamp(i: Float, ceil: Float): Float { + if (i > 0) + return if (i > ceil) ceil else i + else if (i < 0) + return if (-i > ceil) -ceil else i + else + return 0f + } + + private fun updateSprite(delta_t: Int) { + sprite!!.update(delta_t) + if (spriteGlow != null) { + spriteGlow!!.update(delta_t) + } + + if (grounded) { + if (walkHeading == LEFT) { + sprite!!.flip(true, false) + if (spriteGlow != null) { + spriteGlow!!.flip(true, false) + } + } else { + sprite!!.flip(false, false) + if (spriteGlow != null) { + spriteGlow!!.flip(false, false) + } + } + } + } + + fun isNoClip(): Boolean { + return noClip + } + + fun setNoClip(b: Boolean) { + noClip = b + } + + fun getActorValue(): ActorValue { + return actorValue + } + + override fun assignFaction(f: Faction) { + factionSet.add(f) + } + + override fun unassignFaction(f: Faction) { + factionSet.remove(f) + } + + override fun addHouseTile(x: Int, y: Int) { + throw UnsupportedOperationException() + } + + override fun removeHouseTile(x: Int, y: Int) { + throw UnsupportedOperationException() + } + + override fun clearHouseDesignation() { + throw UnsupportedOperationException() + } + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/PlayerDebugger b/src/com/Torvald/Terrarum/Actors/PlayerDebugger new file mode 100644 index 000000000..3999b080c --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/PlayerDebugger @@ -0,0 +1,46 @@ +package com.Torvald.Terrarum.Actors; + +import com.Torvald.spriteAnimation.SpriteAnimation; + +/** + * Created by minjaesong on 16-01-14. + */ +public class PlayerDebugger { + + private Actor actor; + + public PlayerDebugger(Actor actor) { + this.actor = actor; + } + + public Player getPlayer() { + if (actor instanceof Player) { + return (Player) actor; + } + else { + throw new UnsupportedOperationException(); + } + } + + /** + * Delegates for Player instances + */ + + public float baseHitboxW() { return getPlayer().getBaseHitboxW(); } + public float baseHitboxH() { return getPlayer().getBaseHitboxH(); } + public float hitboxTranslateX() { return getPlayer().getHitboxTranslateX(); } + public float hitboxTranslateY() { return getPlayer().getHitboxTranslateY(); } + public float veloX() { return getPlayer().getVeloX(); } + public float veloY() { return getPlayer().getVeloY(); } + public int baseSpriteWidth() { return getPlayer().baseSpriteWidth; } + public int baseSpriteHeight() { return getPlayer().baseSpriteHeight; } + public SpriteAnimation sprite() { return getPlayer().sprite; } + public float scale() { return getPlayer().getScale(); } + public Hitbox hitbox() { return getPlayer().getHitbox(); } + public Hitbox nextHitbox() { return getPlayer().getNextHitbox(); } + public boolean grounded() { return getPlayer().getGrounded(); } + public ActorValue actorValue() { return getPlayer().getActorValue(); } + public float mass() { return getPlayer().getMass(); } + public boolean noClip() { return getPlayer().isNoClip(); } + public int eventMoving() { return getPlayer().eventMoving; } +} diff --git a/src/com/Torvald/Terrarum/Actors/PlayerBuildFactory.java b/src/com/Torvald/Terrarum/Actors/PlayerFactory.java similarity index 78% rename from src/com/Torvald/Terrarum/Actors/PlayerBuildFactory.java rename to src/com/Torvald/Terrarum/Actors/PlayerFactory.java index 29cf6545b..a571222d1 100644 --- a/src/com/Torvald/Terrarum/Actors/PlayerBuildFactory.java +++ b/src/com/Torvald/Terrarum/Actors/PlayerFactory.java @@ -8,13 +8,13 @@ import java.io.IOException; /** * Created by minjaesong on 16-02-03. */ -public class PlayerBuildFactory { +public class PlayerFactory { private static final String JSONPATH = "./res/raw/"; private static String jsonString = new String(); public Player build(String jsonFileName) throws IOException, SlickException { - Player p = (Player) (new CreatureBuildFactory().build("CreatureHuman")); + Player p = (Player) (new CreatureFactory().build("CreatureHuman")); // attach sprite diff --git a/src/com/Torvald/Terrarum/Actors/Pocketed.java b/src/com/Torvald/Terrarum/Actors/Pocketed.java deleted file mode 100644 index bfc9aec7b..000000000 --- a/src/com/Torvald/Terrarum/Actors/Pocketed.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.Torvald.Terrarum.Actors; - -/** - * Created by minjaesong on 16-01-15. - */ -public interface Pocketed { - - public ActorInventory getInventory(); - - public void overwriteInventory(ActorInventory inventory); - -} diff --git a/src/com/Torvald/Terrarum/Actors/Pocketed.kt b/src/com/Torvald/Terrarum/Actors/Pocketed.kt new file mode 100644 index 000000000..c2ff9625f --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Pocketed.kt @@ -0,0 +1,10 @@ +package com.Torvald.Terrarum.Actors + +/** + * Created by minjaesong on 16-03-14. + */ +interface Pocketed { + + var inventory: ActorInventory? + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/Actors/Visible b/src/com/Torvald/Terrarum/Actors/Visible new file mode 100644 index 000000000..f78a6cdf4 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Visible @@ -0,0 +1,15 @@ +package com.Torvald.Terrarum.Actors; + +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; + +/** + * Created by minjaesong on 16-01-25. + */ +public interface Visible { + + void drawBody(GameContainer gc, Graphics g); + + void updateBodySprite(GameContainer gc, int delta_t); + +} diff --git a/src/com/Torvald/Terrarum/Actors/Visible.kt b/src/com/Torvald/Terrarum/Actors/Visible.kt new file mode 100644 index 000000000..693e12896 --- /dev/null +++ b/src/com/Torvald/Terrarum/Actors/Visible.kt @@ -0,0 +1,13 @@ +package com.Torvald.Terrarum.Actors + +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics + +/** + * Created by minjaesong on 16-03-14. + */ +interface Visible { + fun drawBody(gc: GameContainer, g: Graphics) + + fun updateBodySprite(gc: GameContainer, delta: Int) +} diff --git a/src/com/Torvald/Terrarum/ConsoleCommand/ExportAV.java b/src/com/Torvald/Terrarum/ConsoleCommand/ExportAV.java index 6b6f9438a..d664124eb 100644 --- a/src/com/Torvald/Terrarum/ConsoleCommand/ExportAV.java +++ b/src/com/Torvald/Terrarum/ConsoleCommand/ExportAV.java @@ -2,12 +2,7 @@ package com.Torvald.Terrarum.ConsoleCommand; import com.Torvald.JsonWriter; import com.Torvald.Terrarum.Terrarum; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.io.File; -import java.io.FileWriter; import java.io.IOException; /** @@ -18,7 +13,7 @@ public class ExportAV implements ConsoleCommand { public void execute(String[] args) { if (args.length == 2) { try { - JsonWriter.writeFile(Terrarum.game.getPlayer().getActorValue() + JsonWriter.writeToFile(Terrarum.game.getPlayer().getActorValue() , Terrarum.defaultDir + "/Exports/" + args[1] + ".json" ); diff --git a/src/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.java b/src/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.java index 0db7f6b13..fc6adc70a 100644 --- a/src/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.java +++ b/src/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.java @@ -18,7 +18,7 @@ public class GetFactioning implements ConsoleCommand { Echo echo = new Echo(); if (args.length == 1) { // get all factioning data of player - HashSet factionSet = Terrarum.game.getPlayer().getAssignedFactions(); + HashSet factionSet = Terrarum.game.getPlayer().getFaction(); int count = factionSet.size(); echo.execute(String.valueOf(count) + Lang.pluralise(" faction", count) + " assigned."); diff --git a/src/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.java b/src/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.java index a55fa0e03..6c0d71144 100644 --- a/src/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.java +++ b/src/com/Torvald/Terrarum/ConsoleCommand/SetBulletin.java @@ -1,9 +1,8 @@ package com.Torvald.Terrarum.ConsoleCommand; -import com.Torvald.Terrarum.Game; import com.Torvald.Terrarum.LangPack.Lang; import com.Torvald.Terrarum.Terrarum; -import com.Torvald.Terrarum.UserInterface.Bulletin; +import com.Torvald.Terrarum.UserInterface.Notification; /** * Created by minjaesong on 16-01-23. @@ -11,13 +10,10 @@ import com.Torvald.Terrarum.UserInterface.Bulletin; public class SetBulletin implements ConsoleCommand { @Override public void execute(String[] args) { - new Echo().execute(Lang.get("ERROR_SAVE_CORRUPTED") - + " " - + Lang.get("MENU_LABEL_CONTINUE_QUESTION")); - String[] testMsg = { - "SetBulletin: this is a test!" - , "게임 내 방송입니다." + //Lang.get("ERROR_SAVE_CORRUPTED") + //, Lang.get("MENU_LABEL_CONTINUE_QUESTION") + "갎갎갎갎갎갎갎갎갎갎갎갎갎갎" }; send(testMsg); } @@ -28,11 +24,11 @@ public class SetBulletin implements ConsoleCommand { } /** - * Actually send bulletin + * Actually send notifinator * @param message real message */ public void send(String[] message) { - ((Bulletin) (Terrarum.game.bulletin.getUI())).sendBulletin(message); - System.out.println("sent bulletin"); + Terrarum.game.sendNotification(message); + System.out.println("sent notifinator"); } } diff --git a/src/com/Torvald/Terrarum/DefaultConfig.java b/src/com/Torvald/Terrarum/DefaultConfig.java new file mode 100644 index 000000000..8c6f69734 --- /dev/null +++ b/src/com/Torvald/Terrarum/DefaultConfig.java @@ -0,0 +1,21 @@ +package com.Torvald.Terrarum; + +import com.google.gson.JsonObject; + +/** + * Created by minjaesong on 16-03-12. + */ +public class DefaultConfig { + + public static JsonObject fetch() { + JsonObject jsonObject = new JsonObject(); + + jsonObject.addProperty("smoothlighting", true); + jsonObject.addProperty("imtooyoungtodie", false); + jsonObject.addProperty("language", Terrarum.getSysLang()); + jsonObject.addProperty("notificationshowuptime", 6500); + + return jsonObject; + } + +} diff --git a/src/com/Torvald/Terrarum/Game.java b/src/com/Torvald/Terrarum/Game.java index cc8a52f49..e0a87e78a 100644 --- a/src/com/Torvald/Terrarum/Game.java +++ b/src/com/Torvald/Terrarum/Game.java @@ -5,7 +5,6 @@ import com.Torvald.Terrarum.ConsoleCommand.Authenticator; import com.Torvald.Terrarum.ConsoleCommand.CommandDict; import com.Torvald.Terrarum.GameControl.GameController; import com.Torvald.Terrarum.GameControl.KeyMap; -import com.Torvald.Terrarum.GameControl.KeyToggler; import com.Torvald.Terrarum.GameMap.GameMap; import com.Torvald.Terrarum.GameMap.WorldTime; import com.Torvald.Terrarum.MapDrawer.LightmapRenderer; @@ -15,6 +14,7 @@ import com.Torvald.Terrarum.MapGenerator.MapGenerator; import com.Torvald.Terrarum.TileProperties.TilePropCodex; import com.Torvald.Terrarum.TileStat.TileStat; import com.Torvald.Terrarum.UserInterface.*; +import org.lwjgl.opengl.ARBShaderObjects; import org.lwjgl.opengl.GL11; import org.newdawn.slick.*; import org.newdawn.slick.Graphics; @@ -24,6 +24,9 @@ import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; import shader.Shader; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.util.HashSet; @@ -36,8 +39,6 @@ public class Game extends BasicGameState { public static long totalVMMem; int game_mode = 0; - public GameConfig gameConfig; - public GameMap map; public HashSet actorContainer = new HashSet<>(); @@ -45,7 +46,7 @@ public class Game extends BasicGameState { public UIHandler consoleHandler; public UIHandler debugWindow; - public UIHandler bulletin; + public UIHandler notifinator; @NotNull Player player; @@ -64,6 +65,11 @@ public class Game extends BasicGameState { public Game() throws SlickException { } + + private boolean useShader; + private int shaderProgram = 0; + + @Override public void init(GameContainer gameContainer, StateBasedGame stateBasedGame) throws SlickException { @@ -72,14 +78,11 @@ public class Game extends BasicGameState { GameController.setKeyMap(new KeyMap()); - - gameConfig = new GameConfig(); - gameConfig.set("smoothlighting", true); - shader12BitCol = Shader.makeShader("./res/4096.vrt", "./res/4096.frg"); shaderBlurH = Shader.makeShader("./res/blurH.vrt", "./res/blur.frg"); shaderBlurV = Shader.makeShader("./res/blurV.vrt", "./res/blur.frg"); + GRADIENT_IMAGE = new Image("res/graphics/backgroundGradientColour.png"); skyBox = new Rectangle(0, 0, Terrarum.WIDTH, Terrarum.HEIGHT); @@ -98,7 +101,7 @@ public class Game extends BasicGameState { // add new player and put it to actorContainer //player = new Player(); - player = new PBFSigrid().build(); + player = new PFSigrid().build(); //player.setNoClip(true); actorContainer.add(player); @@ -112,22 +115,13 @@ public class Game extends BasicGameState { debugWindow = new UIHandler(new BasicDebugInfoWindow()); debugWindow.setPosition(0, 0); - bulletin = new UIHandler(new Bulletin()); - bulletin.setPosition( - (Terrarum.WIDTH - bulletin.getUI().getWidth()) + notifinator = new UIHandler(new Notification()); + notifinator.setPosition( + (Terrarum.WIDTH - notifinator.getUI().getWidth()) / 2 - , 0 + , Terrarum.HEIGHT - notifinator.getUI().getHeight() ); - bulletin.setVisibility(true); - - - UIHandler msgtest = new UIHandler(new Message(400, true)); - String[] msg = {"Hello, world!", "안녕, 세상아!"}; - ((Message) msgtest.getUI()).setMessage(msg); - msgtest.setPosition(32, 32); - // msgtest.setVisibility(true); - - uiContainer.add(msgtest); + notifinator.setVisibility(true); } public Player getPlayer() { @@ -159,7 +153,7 @@ public class Game extends BasicGameState { uiContainer.forEach(ui -> ui.update(gc, delta_t)); - //bulletin.update(gc, delta_t); + notifinator.update(gc, delta_t); Terrarum.appgc.setVSync(Terrarum.appgc.getFPS() >= Terrarum.VSYNC_TRIGGER_THRESHOLD); } @@ -212,9 +206,7 @@ public class Game extends BasicGameState { uiContainer.forEach(ui -> ui.render(gc, g)); debugWindow.render(gc, g); consoleHandler.render(gc, g); - //bulletin.render(gc, g); - - GL11.glEnd(); + notifinator.render(gc, g); } public boolean addActor(Actor e) { @@ -294,4 +286,98 @@ public class Game extends BasicGameState { GL11.glDisable(GL11.GL_BLEND); Terrarum.appgc.getGraphics().setDrawMode(Graphics.MODE_NORMAL); } + + public void sendNotification(String[] msg) { + ((Notification) notifinator.getUI()).sendNotification(msg); + } + + private int createShader(String filename, int shaderType) throws Exception { + int shader = 0; + try { + shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType); + + if(shader == 0) + return 0; + + ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename)); + ARBShaderObjects.glCompileShaderARB(shader); + + if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE) + throw new RuntimeException("Error creating shader: " + getLogInfo(shader)); + + return shader; + } + catch(Exception exc) { + ARBShaderObjects.glDeleteObjectARB(shader); + throw exc; + } + } + + private static String getLogInfo(int obj) { + return ARBShaderObjects.glGetInfoLogARB(obj, ARBShaderObjects.glGetObjectParameteriARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB)); + } + + private String readFileAsString(String filename) throws Exception { + StringBuilder source = new StringBuilder(); + + FileInputStream in = new FileInputStream(filename); + + Exception exception = null; + + BufferedReader reader; + try{ + reader = new BufferedReader(new InputStreamReader(in,"UTF-8")); + + Exception innerExc= null; + try { + String line; + while((line = reader.readLine()) != null) + source.append(line).append('\n'); + } + catch(Exception exc) { + exception = exc; + } + finally { + try { + reader.close(); + } + catch(Exception exc) { + if(innerExc == null) + innerExc = exc; + else + exc.printStackTrace(); + } + } + + if(innerExc != null) + throw innerExc; + } + catch(Exception exc) { + exception = exc; + } + finally { + try { + in.close(); + } + catch(Exception exc) { + if(exception == null) + exception = exc; + else + exc.printStackTrace(); + } + + if(exception != null) + throw exception; + } + + return source.toString(); + } + + public long getMemInUse() { + return memInUse; + } + + public long getTotalVMMem() { + return totalVMMem; + } } diff --git a/src/com/Torvald/Terrarum/GameControl/GameController.java b/src/com/Torvald/Terrarum/GameControl/GameController.java index fe280ec12..cdbdb62ba 100644 --- a/src/com/Torvald/Terrarum/GameControl/GameController.java +++ b/src/com/Torvald/Terrarum/GameControl/GameController.java @@ -36,8 +36,8 @@ public class GameController { if (!Terrarum.game.consoleHandler.isTakingControl()) { - if (Terrarum.game.getPlayer().vehicleRiding != null) { - Terrarum.game.getPlayer().vehicleRiding.processInput(input); + if (Terrarum.game.getPlayer().getVehicleRiding() != null) { + Terrarum.game.getPlayer().getVehicleRiding().processInput(input); } Terrarum.game.getPlayer().processInput(input); @@ -82,8 +82,8 @@ public class GameController { if (!Terrarum.game.consoleHandler.isTakingControl()) { - if (Terrarum.game.getPlayer().vehicleRiding != null) { - Terrarum.game.getPlayer().vehicleRiding.keyPressed(key, c); + if (Terrarum.game.getPlayer().getVehicleRiding() != null) { + Terrarum.game.getPlayer().getVehicleRiding().keyPressed(key, c); } Terrarum.game.getPlayer().keyPressed(key, c); diff --git a/src/com/Torvald/Terrarum/KVHashMap.java b/src/com/Torvald/Terrarum/KVHashMap.java index 32490546a..f909cef33 100644 --- a/src/com/Torvald/Terrarum/KVHashMap.java +++ b/src/com/Torvald/Terrarum/KVHashMap.java @@ -1,5 +1,7 @@ package com.Torvald.Terrarum; +import com.google.gson.JsonPrimitive; + import java.util.HashMap; import java.util.Hashtable; import java.util.Set; @@ -44,15 +46,20 @@ public class KVHashMap { public float getAsFloat(String key) { Object value = get(key); if (value instanceof Integer) return ((Integer) value).floatValue(); - else return (float) value; + else if (value instanceof JsonPrimitive) return ((JsonPrimitive) value).getAsFloat(); + return (float) value; } public String getAsString(String key) { - return (String) get(key); + Object value = get(key); + if (value instanceof JsonPrimitive) return ((JsonPrimitive) value).getAsString(); + return (String) value; } public boolean getAsBoolean(String key) { - return (boolean) get(key); + Object value = get(key); + if (value instanceof JsonPrimitive) return ((JsonPrimitive) value).getAsBoolean(); + return (boolean) value; } public boolean hasKey(String key) { diff --git a/src/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.java b/src/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.java index fb13a4e86..e846b8f6f 100644 --- a/src/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.java +++ b/src/com/Torvald/Terrarum/MapDrawer/LightmapRenderer.java @@ -155,8 +155,8 @@ public class LightmapRenderer { for (int y = for_y_start; y < for_y_end; y++) { for (int x = for_x_start; x < for_x_end; x++) { // smooth - if (Terrarum.game.screenZoom >= 1 && ((boolean) Terrarum.game.gameConfig.get( - "smoothlighting"))) { + if (Terrarum.game.screenZoom >= 1 + && Terrarum.gameConfig.getAsBoolean("smoothlighting")) { char thisLightLevel = staticLightMap[y][x]; if (y > 0 && x < for_x_end && thisLightLevel == 0 && staticLightMap[y - 1][x] == 0) { try { @@ -317,7 +317,7 @@ public class LightmapRenderer { int tileX = Math.round(actorBody.getHitbox().getPointedX() / TSIZE); int tileY = Math.round(actorBody.getHitbox().getPointedY() / TSIZE) - 1; - char actorLuminosity = actorLum.getLuminance(); + char actorLuminosity = actorLum.getLuminosity(); if (x == tileX && y == tileY) { lightLevelThis = screenBlend(lightLevelThis, actorLuminosity); } diff --git a/src/com/Torvald/Terrarum/MapDrawer/MapCamera.java b/src/com/Torvald/Terrarum/MapDrawer/MapCamera.java index a1d4bfab1..3dc0618c0 100644 --- a/src/com/Torvald/Terrarum/MapDrawer/MapCamera.java +++ b/src/com/Torvald/Terrarum/MapDrawer/MapCamera.java @@ -71,6 +71,22 @@ public class MapCamera { , TileNameCode.ILLUMINATOR_TAN , TileNameCode.ILLUMINATOR_WHITE , TileNameCode.ILLUMINATOR_YELLOW + , TileNameCode.ILLUMINATOR_BLACK_OFF + , TileNameCode.ILLUMINATOR_BLUE_OFF + , TileNameCode.ILLUMINATOR_BROWN_OFF + , TileNameCode.ILLUMINATOR_CYAN_OFF + , TileNameCode.ILLUMINATOR_FUCHSIA_OFF + , TileNameCode.ILLUMINATOR_GREEN_OFF + , TileNameCode.ILLUMINATOR_GREEN_DARK_OFF + , TileNameCode.ILLUMINATOR_GREY_DARK_OFF + , TileNameCode.ILLUMINATOR_GREY_LIGHT_OFF + , TileNameCode.ILLUMINATOR_GREY_MED_OFF + , TileNameCode.ILLUMINATOR_ORANGE_OFF + , TileNameCode.ILLUMINATOR_PURPLE_OFF + , TileNameCode.ILLUMINATOR_RED_OFF + , TileNameCode.ILLUMINATOR_TAN_OFF + , TileNameCode.ILLUMINATOR_WHITE_OFF + , TileNameCode.ILLUMINATOR_YELLOW , TileNameCode.SANDSTONE , TileNameCode.SANDSTONE_BLACK , TileNameCode.SANDSTONE_DESERT @@ -376,9 +392,12 @@ public class MapCamera { // try for int ret = 0; for (int i = 0; i < 4; i++) { - if (!TilePropCodex.getProp(nearbyTiles[i]).isSolid()) { - ret += (1 << i); // add 1, 2, 4, 8 for i = 0, 1, 2, 3 + try { + if (!TilePropCodex.getProp(nearbyTiles[i]).isSolid()) { + ret += (1 << i); // add 1, 2, 4, 8 for i = 0, 1, 2, 3 + } } + catch (ArrayIndexOutOfBoundsException e) {} } return ret; diff --git a/src/com/Torvald/Terrarum/SAVE_FORMAT b/src/com/Torvald/Terrarum/SAVE_FORMAT index 38c6f9583..ba15602a5 100644 --- a/src/com/Torvald/Terrarum/SAVE_FORMAT +++ b/src/com/Torvald/Terrarum/SAVE_FORMAT @@ -8,11 +8,10 @@ Byte[n] name Savegame name, UTF-8 Byte null String terminator Byte[8] terraseed Terrain seed - Byte[8] possible other seeds + Byte[8] rogueseed Randomiser seed Byte[32] hash1 SHA-256 hash of worldinfo1 being stored Byte[32] hash2 SHA-256 hash of worldinfo2 being stored - Byte[32] hash3 SHA-256 hash of worldinfo3 being stored - Byte[32] hash4 SHA-256 hash of worldinfo4 beihg stored (TEMD data) [32, 214, 42, 3, 76, ...] + Byte[32] hash4 SHA-256 hash of worldinfo3 beihg stored (TEMD data) [32, 214, 42, 3, 76, ...] * Actor data @@ -51,5 +50,4 @@ --- world save meta --- worldinfo1 tileprop --- worldinfo2 itemprop - --- worldinfo3 Roguelike randomiser - --- worldinfo4 TEMD binary + --- worldinfo3 TEMD binary diff --git a/src/com/Torvald/Terrarum/Terrarum.java b/src/com/Torvald/Terrarum/Terrarum.java index e61f57448..45be528a9 100644 --- a/src/com/Torvald/Terrarum/Terrarum.java +++ b/src/com/Torvald/Terrarum/Terrarum.java @@ -1,17 +1,15 @@ package com.Torvald.Terrarum; import java.io.File; -import java.io.FileWriter; import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; -import com.Torvald.ImageFont.GameFontBase; import com.Torvald.ImageFont.GameFontWhite; import com.Torvald.JsonFetcher; +import com.Torvald.JsonWriter; import com.Torvald.Terrarum.LangPack.Lang; +import com.google.gson.JsonObject; import org.lwjgl.input.Controllers; import org.newdawn.slick.*; import org.newdawn.slick.state.StateBasedGame; @@ -43,6 +41,7 @@ public class Terrarum extends StateBasedGame { public static final int VSYNC_TRIGGER_THRESHOLD = 56; public static Game game; + public static GameConfig gameConfig; public static String OSName; public static String OSVersion; @@ -60,31 +59,25 @@ public class Terrarum extends StateBasedGame { public static boolean hasController = false; public static final float CONTROLLER_DEADZONE = 0.1f; + private static String configDir; + public Terrarum(String gamename) throws SlickException { super(gamename); + gameConfig = new GameConfig(); + getDefaultDirectory(); createDirs(); - try { - createFiles(); - } - catch (IOException e) { - e.printStackTrace(); - } - // TODO if config language is not defined - if (gameLocale.length() < 2) { // get system language if not overridden - String lan = System.getProperty("user.language"); - String country = System.getProperty("user.country"); + boolean readFromDisk = readConfigJson(); + if (!readFromDisk) readConfigJson(); - // exception handling - if (lan.equals("en")) country = "US"; - else if (lan.equals("fr")) country = "FR"; - else if (lan.equals("de")) country = "DE"; - else if (lan.equals("ko")) country = "KR"; + // get locale from config + gameLocale = gameConfig.getAsString("language"); - gameLocale = lan + country; - } + // if game locale were not set, use system locale + if (gameLocale.length() < 4) + gameLocale = getSysLang(); System.out.println("[Terrarum] Locale: " + gameLocale); } @@ -160,6 +153,7 @@ public class Terrarum extends StateBasedGame { } defaultSaveDir = defaultDir + "/Saves"; + configDir = defaultDir + "/config.json"; } private static void createDirs(){ @@ -174,15 +168,138 @@ public class Terrarum extends StateBasedGame { } } - private static void createFiles() throws IOException { - File configFile = new File(defaultDir + "/config.json"); + private static void createConfigJson() throws IOException { + File configFile = new File(configDir); if (!configFile.exists() || configFile.length() == 0) { - configFile.createNewFile(); - ArrayList jsonLines = JsonFetcher.readJsonAsString("./res/config_default.json"); - PrintWriter printWriter = new PrintWriter(configFile); - jsonLines.forEach(printWriter::println); - printWriter.close(); + JsonWriter.writeToFile(DefaultConfig.fetch(), configDir); } } + + private static boolean readConfigJson() { + try { + // read from disk and build config from it + JsonObject jsonObject = JsonFetcher.readJson(configDir); + + // make config + jsonObject.entrySet().forEach( + entry -> gameConfig.set(entry.getKey(), entry.getValue()) + ); + + return true; + } + catch (IOException e) { + // write default config to game dir. Call this method again to read config from it. + try { + createConfigJson(); + } + catch (IOException e1) { + e.printStackTrace(); + } + + return false; + } + } + + public static String getSysLang() { + String lan = System.getProperty("user.language"); + String country = System.getProperty("user.country"); + + // exception handling + if (lan.equals("en")) country = "US"; + else if (lan.equals("fr")) country = "FR"; + else if (lan.equals("de")) country = "DE"; + else if (lan.equals("ko")) country = "KR"; + + return lan + country; + } + + + /** + * 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. + */ + public static int getConfigInt(String key) { + int cfg = 0; + try { + cfg = gameConfig.getAsInt(key); + } + catch (NullPointerException e) { + try { + cfg = DefaultConfig.fetch().get(key).getAsInt(); + } + catch (NullPointerException e1) { + e.printStackTrace(); + } + } + return cfg; + } + + /** + * 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. + */ + public static float getConfigFloat(String key) { + float cfg = 0; + try { + cfg = gameConfig.getAsFloat(key); + } + catch (NullPointerException e) { + try { + cfg = DefaultConfig.fetch().get(key).getAsFloat(); + } + catch (NullPointerException e1) { + e.printStackTrace(); + } + } + return cfg; + } + + /** + * 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. + */ + public static String getConfigString(String key) { + String cfg = ""; + try { + cfg = gameConfig.getAsString(key); + } + catch (NullPointerException e) { + try { + cfg = DefaultConfig.fetch().get(key).getAsString(); + } + catch (NullPointerException e1) { + e.printStackTrace(); + } + } + return cfg; + } + + /** + * 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. + */ + public static boolean getConfigBoolean(String key) { + boolean cfg = false; + try { + cfg = gameConfig.getAsBoolean(key); + } + catch (NullPointerException e) { + try { + cfg = DefaultConfig.fetch().get(key).getAsBoolean(); + } + catch (NullPointerException e1) { + e.printStackTrace(); + } + } + return cfg; + } } diff --git a/src/com/Torvald/Terrarum/TileProperties/TileNameCode.java b/src/com/Torvald/Terrarum/TileProperties/TileNameCode.java index d4b4163b3..93c0a4fe4 100644 --- a/src/com/Torvald/Terrarum/TileProperties/TileNameCode.java +++ b/src/com/Torvald/Terrarum/TileProperties/TileNameCode.java @@ -83,12 +83,29 @@ public class TileNameCode { public static final int ILLUMINATOR_GREY_DARK = TilePropCodex.indexDamageToArrayAddr(13, 14); public static final int ILLUMINATOR_BLACK = TilePropCodex.indexDamageToArrayAddr(13, 15); - public static final int SANDSTONE = TilePropCodex.indexDamageToArrayAddr(14, 0); - public static final int SANDSTONE_WHITE = TilePropCodex.indexDamageToArrayAddr(14, 1); - public static final int SANDSTONE_RED = TilePropCodex.indexDamageToArrayAddr(14, 2); - public static final int SANDSTONE_DESERT = TilePropCodex.indexDamageToArrayAddr(14, 3); - public static final int SANDSTONE_BLACK = TilePropCodex.indexDamageToArrayAddr(14, 4); - public static final int SANDSTONE_GREEN = TilePropCodex.indexDamageToArrayAddr(14, 5); + public static final int ILLUMINATOR_WHITE_OFF = TilePropCodex.indexDamageToArrayAddr(14, 0); + public static final int ILLUMINATOR_YELLOW_OFF = TilePropCodex.indexDamageToArrayAddr(14, 1); + public static final int ILLUMINATOR_ORANGE_OFF = TilePropCodex.indexDamageToArrayAddr(14, 2); + public static final int ILLUMINATOR_RED_OFF = TilePropCodex.indexDamageToArrayAddr(14, 3); + public static final int ILLUMINATOR_FUCHSIA_OFF = TilePropCodex.indexDamageToArrayAddr(14, 4); + public static final int ILLUMINATOR_PURPLE_OFF = TilePropCodex.indexDamageToArrayAddr(14, 5); + public static final int ILLUMINATOR_BLUE_OFF = TilePropCodex.indexDamageToArrayAddr(14, 6); + public static final int ILLUMINATOR_CYAN_OFF = TilePropCodex.indexDamageToArrayAddr(14, 7); + public static final int ILLUMINATOR_GREEN_OFF = TilePropCodex.indexDamageToArrayAddr(14, 8); + public static final int ILLUMINATOR_GREEN_DARK_OFF = TilePropCodex.indexDamageToArrayAddr(14, 9); + public static final int ILLUMINATOR_BROWN_OFF = TilePropCodex.indexDamageToArrayAddr(14, 10); + public static final int ILLUMINATOR_TAN_OFF = TilePropCodex.indexDamageToArrayAddr(14, 11); + public static final int ILLUMINATOR_GREY_LIGHT_OFF = TilePropCodex.indexDamageToArrayAddr(14, 12); + public static final int ILLUMINATOR_GREY_MED_OFF = TilePropCodex.indexDamageToArrayAddr(14, 13); + public static final int ILLUMINATOR_GREY_DARK_OFF = TilePropCodex.indexDamageToArrayAddr(14, 14); + public static final int ILLUMINATOR_BLACK_OFF = TilePropCodex.indexDamageToArrayAddr(14, 15); + + public static final int SANDSTONE = TilePropCodex.indexDamageToArrayAddr(15, 0); + public static final int SANDSTONE_WHITE = TilePropCodex.indexDamageToArrayAddr(15, 1); + public static final int SANDSTONE_RED = TilePropCodex.indexDamageToArrayAddr(15, 2); + public static final int SANDSTONE_DESERT = TilePropCodex.indexDamageToArrayAddr(15, 3); + public static final int SANDSTONE_BLACK = TilePropCodex.indexDamageToArrayAddr(15, 4); + public static final int SANDSTONE_GREEN = TilePropCodex.indexDamageToArrayAddr(15, 5); public static final int WATER_1 = TilePropCodex.indexDamageToArrayAddr(254, 0); public static final int WATER_2 = TilePropCodex.indexDamageToArrayAddr(254, 1); diff --git a/src/com/Torvald/Terrarum/TileProperties/tileprop.csv b/src/com/Torvald/Terrarum/TileProperties/tileprop.csv index b520a8bb3..cf3374aed 100644 --- a/src/com/Torvald/Terrarum/TileProperties/tileprop.csv +++ b/src/com/Torvald/Terrarum/TileProperties/tileprop.csv @@ -60,13 +60,29 @@ "13"; "12";"TILE_ILLUMINATOR_GREY_LIGHT"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "47589"; "13"; "12"; "0";"16" "13"; "13";"TILE_ILLUMINATOR_GREY_MED"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "29538"; "13"; "13"; "0";"16" "13"; "14";"TILE_ILLUMINATOR_GREY_DARK"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "16410"; "13"; "14"; "0";"16" - "13"; "15";"TILE_ILLUMINATOR_BLACK" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "4923"; "13"; "15"; "0";"16" - "14"; "0";"TILE_SANDSTONE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "0"; "0";"16" - "14"; "1";"TILE_SANDSTONE_WHITE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "1"; "0";"16" - "14"; "2";"TILE_SANDSTONE_RED" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "2"; "0";"16" - "14"; "3";"TILE_SANDSTONE_DESERT" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "3"; "0";"16" - "14"; "4";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "4"; "0";"16" - "14"; "5";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "14"; "5"; "0";"16" + "13"; "15";"TILE_ILLUMINATOR_BLACK" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "27239"; "13"; "15"; "0";"16" + "14"; "0";"TILE_ILLUMINATOR_WHITE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "0"; "0";"16" + "14"; "1";"TILE_ILLUMINATOR_YELLOW" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "1"; "0";"16" + "14"; "2";"TILE_ILLUMINATOR_ORANGE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "2"; "0";"16" + "14"; "3";"TILE_ILLUMINATOR_RED" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "3"; "0";"16" + "14"; "4";"TILE_ILLUMINATOR_FUCHSIA" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "4"; "0";"16" + "14"; "5";"TILE_ILLUMINATOR_PURPLE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "5"; "0";"16" + "14"; "6";"TILE_ILLUMINATOR_BLUE" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "6"; "0";"16" + "14"; "7";"TILE_ILLUMINATOR_CYAN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "7"; "0";"16" + "14"; "8";"TILE_ILLUMINATOR_GREEN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "8"; "0";"16" + "14"; "9";"TILE_ILLUMINATOR_GREEN_DARK"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "9"; "0";"16" + "14"; "10";"TILE_ILLUMINATOR_BROWN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "10"; "0";"16" + "14"; "11";"TILE_ILLUMINATOR_TAN" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "11"; "0";"16" + "14"; "12";"TILE_ILLUMINATOR_GREY_LIGHT"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "12"; "0";"16" + "14"; "13";"TILE_ILLUMINATOR_GREY_MED"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "13"; "0";"16" + "14"; "14";"TILE_ILLUMINATOR_GREY_DARK"; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "14"; "0";"16" + "14"; "15";"TILE_ILLUMINATOR_BLACK" ; "0"; "0"; "N/A"; "0"; "0"; "1"; "1"; "0"; "13"; "15"; "0";"16" + "15"; "0";"TILE_SANDSTONE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "0"; "0";"16" + "15"; "1";"TILE_SANDSTONE_WHITE" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "1"; "0";"16" + "15"; "2";"TILE_SANDSTONE_RED" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "2"; "0";"16" + "15"; "3";"TILE_SANDSTONE_DESERT" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "3"; "0";"16" + "15"; "4";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "4"; "0";"16" + "15"; "5";"TILE_SANDSTONE_BLACK" ; "8205"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "5"; "0";"16" "254"; "0";"TILE_WATER" ; "6522"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16" "254"; "1";"TILE_WATER" ; "6522"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16" "254"; "2";"TILE_WATER" ; "6522"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16" @@ -111,6 +127,8 @@ # Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess. +# Off illuminator: NO OPACITY! this is intended! + # References: # * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html # * Density of various phases of ice : http://www1.lsbu.ac.uk/water/ice_phases.html \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow b/src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow new file mode 100644 index 000000000..318abdc41 --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow @@ -0,0 +1,220 @@ +package com.Torvald.Terrarum.UserInterface; + +import com.Torvald.Terrarum.Actors.PlayerDebugger; +import com.Torvald.Terrarum.Actors.Hitbox; +import com.Torvald.Terrarum.GameMap.PairedMapLayer; +import com.Torvald.Terrarum.LangPack.Lang; +import com.Torvald.Terrarum.MapDrawer.LightmapRenderer; +import com.Torvald.Terrarum.MapDrawer.MapDrawer; +import com.Torvald.Terrarum.Terrarum; +import com.Torvald.Terrarum.MapDrawer.MapCamera; +import org.newdawn.slick.Color; +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; +import org.newdawn.slick.Input; + +import java.util.Formatter; + +/** + * Created by minjaesong on 16-01-19. + */ +public class BasicDebugInfoWindow implements UICanvas { + + private static PlayerDebugger playerDbg; + + int width; + int height; + + /** + * Call AFTER player constuction! + */ + public BasicDebugInfoWindow() { + width = Terrarum.WIDTH; + height = Terrarum.HEIGHT; + } + + @Override + public void render(GameContainer gc, Graphics g) { + if (playerDbg == null) { + playerDbg = new PlayerDebugger(Terrarum.game.getPlayer()); + } + + + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb); + + int mouseTileX = (int) ((MapCamera.getCameraX() + gc.getInput().getMouseX() / Terrarum.game.screenZoom) + / MapDrawer.TILE_SIZE); + int mouseTileY = (int) ((MapCamera.getCameraY() + gc.getInput().getMouseY() / Terrarum.game.screenZoom) + / MapDrawer.TILE_SIZE); + + g.setColor(Color.white); + + Hitbox hitbox = playerDbg.hitbox(); + Hitbox nextHitbox = playerDbg.nextHitbox(); + + printLine(g, 1, "posX : " + + String.valueOf(hitbox.getPointedX()) + + " (" + + String.valueOf((int) (hitbox.getPointedX() / MapDrawer.TILE_SIZE)) + + ")" + ); + printLine(g, 2, "posY : " + + String.valueOf(hitbox.getPointedY()) + + " (" + + String.valueOf((int) (hitbox.getPointedY() / MapDrawer.TILE_SIZE)) + + ")" + ); + printLine(g, 3, "veloX : " + String.valueOf(playerDbg.veloX())); + printLine(g, 4, "veloY : " + String.valueOf(playerDbg.veloY())); + printLine(g, 5, "grounded : " + String.valueOf(playerDbg.grounded())); + printLine(g, 6, "noClip : " + String.valueOf(playerDbg.noClip())); + printLine(g, 7, "mass : " + String.valueOf(playerDbg.mass()) + " [kg]"); + + String lightVal; + String mtX = String.valueOf(mouseTileX), mtY = String.valueOf(mouseTileY); + try { + char valRaw = LightmapRenderer.getValueFromMap(mouseTileX, mouseTileY); + int rawR = LightmapRenderer.getRawR(valRaw); + int rawG = LightmapRenderer.getRawG(valRaw); + int rawB = LightmapRenderer.getRawB(valRaw); + lightVal = String.valueOf((int)valRaw) + " (" + + String.valueOf(rawR) + " " + + String.valueOf(rawG) + " " + + String.valueOf(rawB) + ")"; + } + catch (ArrayIndexOutOfBoundsException e) { + lightVal = "out of bounds"; + mtX = "---"; + mtY = "---"; + } + printLine(g, 8, "light at cursor : " + lightVal + ); + + String tileNo; + try { + int tileNumRaw = Terrarum.game.map.getTileFromTerrain(mouseTileX, mouseTileY); + int tilenum = tileNumRaw / PairedMapLayer.RANGE; + int tiledmg = tileNumRaw % PairedMapLayer.RANGE; + tileNo = tilenum + ":" + tiledmg; + } + catch (ArrayIndexOutOfBoundsException e) { + tileNo = "-"; + } + printLine(g, 9, "tile : " + tileNo + " (" + mtX + ", " + mtY + ")"); + + /** + * Second column + */ + + int collisonFlag = playerDbg.eventMoving(); + printLineColumn(g, 2, 1, "Vsync : " + Terrarum.appgc.isVSyncRequested()); + printLineColumn(g, 2, 2, "Env colour temp : " + MapDrawer.getColTemp()); + + /** + * On screen + */ + + // Memory allocation + long memInUse = Terrarum.game.memInUse; + long totalVMMem = Terrarum.game.totalVMMem; + + g.setColor(new Color(0xFF7F00)); + g.drawString( + Lang.get("DEV_MEMORY_SHORT_CAP") + + " : " + + formatter.format( + Lang.get("DEV_MEMORY_A_OF_B") + , memInUse + , totalVMMem + ) + , Terrarum.WIDTH - 200, line(1) + ); + + // Hitbox + float zoom = Terrarum.game.screenZoom; + g.setColor(new Color(0x007f00)); + g.drawRect(hitbox.getHitboxStart().getX() * zoom + - MapCamera.getCameraX() * zoom + , hitbox.getHitboxStart().getY() * zoom + - MapCamera.getCameraY() * zoom + , hitbox.getWidth() * zoom + , hitbox.getHeight() * zoom + ); + // ...and its point + g.fillRect( + (hitbox.getPointedX() - 1) * zoom + - MapCamera.getCameraX() * zoom + , (hitbox.getPointedY() - 1) * zoom + - MapCamera.getCameraY() * zoom + , 3 + , 3 + ); + g.drawString( + Lang.get("DEV_COLOUR_LEGEND_GREEN") + + " : hitbox", Terrarum.WIDTH - 200 + , line(2) + ); + + // Next hitbox + g.setColor(Color.blue); + g.drawRect(nextHitbox.getHitboxStart().getX() * zoom + - MapCamera.getCameraX() * zoom + , nextHitbox.getHitboxStart().getY() * zoom + - MapCamera.getCameraY() * zoom + , nextHitbox.getWidth() * zoom + , nextHitbox.getHeight() * zoom + ); + // ...and its point + g.fillRect( + (nextHitbox.getPointedX() - 1) * zoom + - MapCamera.getCameraX() * zoom + , (nextHitbox.getPointedY() - 1) * zoom + - MapCamera.getCameraY() * zoom + , 3 + , 3 + ); + g.drawString( + Lang.get("DEV_COLOUR_LEGEND_BLUE") + + " : nextHitbox", Terrarum.WIDTH - 200 + , line(3) + ); + } + + private static void printLine(Graphics g, int l, String s) { + g.drawString(s, 20, line(l)); + } + + private static void printLineColumn(Graphics g, int col, int row, String s) { + g.drawString(s, 20 + column(col), line(row)); + } + + private static int line(int i) { + return i * 20; + } + + private static int column(int i) { + return (250 * (i - 1)); + } + + @Override + public void update(GameContainer gc, int delta_t) { + + } + + @Override + public void processInput(Input input) { + + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + +} diff --git a/src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.kt b/src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.kt new file mode 100644 index 000000000..0503ce6c2 --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/BasicDebugInfoWindow.kt @@ -0,0 +1,150 @@ +package com.Torvald.Terrarum.UserInterface + +import com.Torvald.Terrarum.GameMap.PairedMapLayer +import com.Torvald.Terrarum.LangPack.Lang +import com.Torvald.Terrarum.MapDrawer.LightmapRenderer +import com.Torvald.Terrarum.MapDrawer.MapCamera +import com.Torvald.Terrarum.MapDrawer.MapDrawer +import com.Torvald.Terrarum.Terrarum +import org.newdawn.slick.Color +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Input +import java.util.* + +/** + * Created by minjaesong on 16-03-14. + */ +class BasicDebugInfoWindow : UICanvas { + + override var width: Int? = Terrarum.WIDTH + override var height: Int? = Terrarum.HEIGHT + + override fun processInput(input: Input) { + + } + + override fun update(gc: GameContainer, delta_t: Int) { + + } + + override fun render(gc: GameContainer, g: Graphics) { + val player = Terrarum.game.player + + val sb = StringBuilder() + val formatter = Formatter(sb) + + val mouseTileX = ((MapCamera.getCameraX() + gc.getInput().mouseX / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt() + val mouseTileY = ((MapCamera.getCameraY() + gc.getInput().mouseY / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt() + + g.setColor(Color.white) + + val hitbox = player.hitbox + val nextHitbox = player.nextHitbox + + printLine(g, 1, "posX : " + + "${hitbox!!.pointedX.toString()}" + + " (" + + "${(hitbox!!.pointedX / MapDrawer.TILE_SIZE).toInt().toString()}" + + ")") + printLine(g, 2, "posY : " + + hitbox.pointedY.toString() + + " (" + + (hitbox.pointedY / MapDrawer.TILE_SIZE).toInt().toString() + + ")") + printLine(g, 3, "veloX : ${player.veloX}") + printLine(g, 4, "veloY : ${player.veloY}") + printLine(g, 5, "grounded : ${player.grounded}") + printLine(g, 6, "noClip : ${player.noClip}") + printLine(g, 7, "mass : ${player.mass} [kg]") + + val lightVal: String + var mtX = mouseTileX.toString() + var mtY = mouseTileY.toString() + try { + val valRaw = LightmapRenderer.getValueFromMap(mouseTileX, mouseTileY) + val rawR = LightmapRenderer.getRawR(valRaw) + val rawG = LightmapRenderer.getRawG(valRaw) + val rawB = LightmapRenderer.getRawB(valRaw) + lightVal = valRaw.toInt().toString() + " (" + + rawR.toString() + " " + + rawG.toString() + " " + + rawB.toString() + ")" + } catch (e: ArrayIndexOutOfBoundsException) { + lightVal = "out of bounds" + mtX = "---" + mtY = "---" + } + + printLine(g, 8, "light at cursor : " + lightVal) + + val tileNo: String + try { + val tileNumRaw = Terrarum.game.map.getTileFromTerrain(mouseTileX, mouseTileY) + val tilenum = tileNumRaw / PairedMapLayer.RANGE + val tiledmg = tileNumRaw % PairedMapLayer.RANGE + tileNo = "$tilenum:$tiledmg" + } catch (e: ArrayIndexOutOfBoundsException) { + tileNo = "-" + } + + printLine(g, 9, "tile : $tileNo ($mtX, $mtY)") + + /** + * Second column + */ + + printLineColumn(g, 2, 1, "Vsync : " + Terrarum.appgc.isVSyncRequested) + printLineColumn(g, 2, 2, "Env colour temp : " + MapDrawer.getColTemp()) + + /** + * On screen + */ + + // Memory allocation + val memInUse = Terrarum.game.memInUse + val totalVMMem = Terrarum.game.totalVMMem + + g.setColor(Color(0xFF7F00)) + g.drawString( + Lang.get("DEV_MEMORY_SHORT_CAP") + + " : " + + formatter.format( + Lang.get("DEV_MEMORY_A_OF_B"), memInUse, totalVMMem), (Terrarum.WIDTH - 200).toFloat(), line(1).toFloat()) + + // Hitbox + val zoom = Terrarum.game.screenZoom + g.setColor(Color(0x007f00)) + g.drawRect(hitbox.getHitboxStart().getX() * zoom - MapCamera.getCameraX() * zoom, hitbox.getHitboxStart().getY() * zoom - MapCamera.getCameraY() * zoom, hitbox.getWidth() * zoom, hitbox.getHeight() * zoom) + // ...and its point + g.fillRect( + (hitbox.getPointedX() - 1) * zoom - MapCamera.getCameraX() * zoom, (hitbox.getPointedY() - 1) * zoom - MapCamera.getCameraY() * zoom, 3f, 3f) + g.drawString( + Lang.get("DEV_COLOUR_LEGEND_GREEN") + " : hitbox", (Terrarum.WIDTH - 200).toFloat(), line(2).toFloat()) + + // Next hitbox + g.setColor(Color.blue) + g.drawRect(nextHitbox!!.getHitboxStart().getX() * zoom - MapCamera.getCameraX() * zoom, nextHitbox.getHitboxStart().getY() * zoom - MapCamera.getCameraY() * zoom, nextHitbox.getWidth() * zoom, nextHitbox.getHeight() * zoom) + // ...and its point + g.fillRect( + (nextHitbox!!.getPointedX() - 1) * zoom - MapCamera.getCameraX() * zoom, (nextHitbox.getPointedY() - 1) * zoom - MapCamera.getCameraY() * zoom, 3f, 3f) + g.drawString( + Lang.get("DEV_COLOUR_LEGEND_BLUE") + " : nextHitbox", (Terrarum.WIDTH - 200).toFloat(), line(3).toFloat()) + } + + private fun printLine(g: Graphics, l: Int, s: String) { + g.drawString(s, 20f, line(l).toFloat()) + } + + private fun printLineColumn(g: Graphics, col: Int, row: Int, s: String) { + g.drawString(s, (20 + column(col)).toFloat(), line(row).toFloat()) + } + + private fun line(i: Int): Int { + return i * 20 + } + + private fun column(i: Int): Int { + return 250 * (i - 1) + } +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/UserInterface/Bulletin.java b/src/com/Torvald/Terrarum/UserInterface/Bulletin.java deleted file mode 100644 index 5e3cf0977..000000000 --- a/src/com/Torvald/Terrarum/UserInterface/Bulletin.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.Torvald.Terrarum.UserInterface; - -import com.Torvald.Terrarum.Terrarum; -import org.newdawn.slick.Color; -import org.newdawn.slick.GameContainer; -import org.newdawn.slick.Graphics; -import org.newdawn.slick.Input; -import org.newdawn.slick.geom.RoundedRectangle; - -/** - * Created by minjaesong on 16-01-23. - */ -public class Bulletin implements UICanvas { - - int width = 400; - int height; - - int visibleTime = 5000; - int showupTimeConuter = 0; - - boolean isShowing = false; - String[] message; - - Color uiColour = new Color(0x90000000); - - final int FRAME_SIZE = 5; - - private RoundedRectangle uiBox = new RoundedRectangle( - width - , Terrarum.HEIGHT - , FRAME_SIZE - , 2 - , RoundedRectangle.TOP_LEFT + RoundedRectangle.TOP_RIGHT - ); - - @Override - public void update(GameContainer gc, int delta_t) { - if (showupTimeConuter >= visibleTime) { - isShowing = false; - } - - if (isShowing) { - showupTimeConuter += delta_t; - } - } - - @Override - public void render(GameContainer gc, Graphics g) { - //if (isShowing) { - int lineHeight = Terrarum.gameFontWhite.getLineHeight(); - - g.setColor(uiColour); - g.fillRect(0 - , getHeight() - message.length * lineHeight - - 10 - , width - , getHeight() - ); - - for (int i = 0; i < message.length; i++) { - g.drawString(message[i] - , 5 - , getHeight() - message.length * lineHeight - + 5 - + (i * lineHeight) - ); - } - //} - - System.out.println("arst"); - } - - @Override - public void processInput(Input input) { - - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return Terrarum.HEIGHT; - } - - public void sendBulletin(String[] message) { - isShowing = true; - this.message = message; - } -} diff --git a/src/com/Torvald/Terrarum/UserInterface/ConsoleWindow.java b/src/com/Torvald/Terrarum/UserInterface/ConsoleWindow.java index 79557ab5d..22e4bf3b6 100644 --- a/src/com/Torvald/Terrarum/UserInterface/ConsoleWindow.java +++ b/src/com/Torvald/Terrarum/UserInterface/ConsoleWindow.java @@ -4,6 +4,7 @@ import com.Torvald.Terrarum.LangPack.Lang; import com.Torvald.Terrarum.Terrarum; import com.Torvald.Terrarum.ConsoleCommand.CommandInterpreter; import com.Torvald.Terrarum.GameControl.Key; +import org.jetbrains.annotations.Nullable; import org.newdawn.slick.Color; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; @@ -144,8 +145,8 @@ public class ConsoleWindow implements UICanvas, UITypable { } public void reset() { - width = Terrarum.WIDTH; - height = 200; + setWidth(Terrarum.WIDTH); + setHeight(200); messages = new String[MESSAGES_MAX]; messageDisplayPos = 0; @@ -157,13 +158,25 @@ public class ConsoleWindow implements UICanvas, UITypable { if (Terrarum.game.auth.b()) sendMessage(Lang.get("DEV_MESSAGE_CONSOLE_CODEX")); } + @Nullable @Override - public int getWidth() { + public Integer getWidth() { return width; } @Override - public int getHeight() { + public void setWidth(@Nullable Integer integer) { + width = integer; + } + + @Nullable + @Override + public Integer getHeight() { return height; } + + @Override + public void setHeight(@Nullable Integer integer) { + height = integer; + } } diff --git a/src/com/Torvald/Terrarum/UserInterface/Message.java b/src/com/Torvald/Terrarum/UserInterface/Message.java index c3419446e..f9a1196e6 100644 --- a/src/com/Torvald/Terrarum/UserInterface/Message.java +++ b/src/com/Torvald/Terrarum/UserInterface/Message.java @@ -1,7 +1,7 @@ package com.Torvald.Terrarum.UserInterface; -import com.Torvald.ImageFont.GameFontBlack; import com.Torvald.ImageFont.GameFontWhite; +import org.jetbrains.annotations.Nullable; import org.newdawn.slick.*; /** @@ -12,7 +12,8 @@ public class Message implements UICanvas { private Image segmentLeft, segmentRight, segmentBody; private String[] messagesList; - private int messagesShowingIndex = 0; + // private int messagesShowingIndex = 0; + private static final int MESSAGES_DISPLAY = 2; private int width; private int height; @@ -23,10 +24,11 @@ public class Message implements UICanvas { public Message(int width, boolean isBlackVariant) throws SlickException { if (!isBlackVariant) { - segmentLeft = new Image("./res/graphics/gui/message_twoline_white_left.png"); - segmentRight = new Image("./res/graphics/gui/message_twoline_white_right.png"); - segmentBody = new Image("./res/graphics/gui/message_twoline_white_body.png"); - uiFont = new GameFontBlack(); + //segmentLeft = new Image("./res/graphics/gui/message_twoline_white_left.png"); + //segmentRight = new Image("./res/graphics/gui/message_twoline_white_right.png"); + //segmentBody = new Image("./res/graphics/gui/message_twoline_white_body.png"); + //uiFont = new GameFontBlack(); + throw new SlickException("Black font not supported for now"); } else { segmentLeft = new Image("./res/graphics/gui/message_twoline_black_left.png"); @@ -60,14 +62,14 @@ public class Message implements UICanvas { g.drawImage(segmentRight, width - segmentRight.getWidth(), 0); g.setFont(uiFont); - g.setDrawMode(Graphics.MODE_NORMAL); - for (int i = messagesShowingIndex; i < messagesShowingIndex + 2; i++) { + //g.setDrawMode(Graphics.MODE_NORMAL); + for (int i = 0; i < Math.min(messagesList.length, MESSAGES_DISPLAY); i++) { g.drawString(messagesList[i] , messageWindowRadius + 4 - , messageWindowRadius + (GLYPH_HEIGHT * (i - messagesShowingIndex)) + , messageWindowRadius + (GLYPH_HEIGHT * i) ); } - g.setDrawMode(Graphics.MODE_NORMAL); + //g.setDrawMode(Graphics.MODE_NORMAL); } @Override @@ -75,13 +77,25 @@ public class Message implements UICanvas { } + @Nullable @Override - public int getWidth() { + public Integer getWidth() { return width; } @Override - public int getHeight() { + public void setWidth(@Nullable Integer integer) { + width = integer; + } + + @Nullable + @Override + public Integer getHeight() { return height; } + + @Override + public void setHeight(@Nullable Integer integer) { + height = integer; + } } diff --git a/src/com/Torvald/Terrarum/UserInterface/Notification.java b/src/com/Torvald/Terrarum/UserInterface/Notification.java new file mode 100644 index 000000000..c1e155588 --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/Notification.java @@ -0,0 +1,82 @@ +package com.Torvald.Terrarum.UserInterface; + +import com.Torvald.Terrarum.Terrarum; +import org.jetbrains.annotations.Nullable; +import org.newdawn.slick.*; +import org.newdawn.slick.geom.RoundedRectangle; + +/** + * Created by minjaesong on 16-01-23. + */ +public class Notification implements UICanvas { + + int width; + int height; + + int visibleTime; + int showupTimeConuter = 0; + + boolean isShowing = false; + String[] message; + + Message msgUI; + + public Notification() throws SlickException { + width = 400; + msgUI = new Message(width, true); + height = msgUI.getHeight(); + visibleTime = Terrarum.getConfigInt("notificationshowuptime"); + } + + @Override + public void update(GameContainer gc, int delta_t) { + if (showupTimeConuter >= visibleTime) { + isShowing = false; + } + + if (isShowing) { + showupTimeConuter += delta_t; + } + } + + @Override + public void render(GameContainer gc, Graphics g) { + if (isShowing) { + msgUI.render(gc, g); + } + } + + @Override + public void processInput(Input input) { + + } + + @Nullable + @Override + public Integer getWidth() { + return width; + } + + @Override + public void setWidth(@Nullable Integer integer) { + width = integer; + } + + @Nullable + @Override + public Integer getHeight() { + return height; + } + + @Override + public void setHeight(@Nullable Integer integer) { + height = integer; + } + + public void sendNotification(String[] message) { + isShowing = true; + this.message = message; + showupTimeConuter = 0; + msgUI.setMessage(this.message); + } +} diff --git a/src/com/Torvald/Terrarum/UserInterface/UICanvas b/src/com/Torvald/Terrarum/UserInterface/UICanvas new file mode 100644 index 000000000..8e296a46e --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/UICanvas @@ -0,0 +1,24 @@ +package com.Torvald.Terrarum.UserInterface; + +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; +import org.newdawn.slick.Input; + +import java.util.LinkedList; + +/** + * Created by minjaesong on 15-12-31.
+ */ +public interface UICanvas { + + int getWidth(); + + int getHeight(); + + void update(GameContainer gc, int delta_t); + + void render(GameContainer gc, Graphics g); + + void processInput(Input input); + +} diff --git a/src/com/Torvald/Terrarum/UserInterface/UICanvas.kt b/src/com/Torvald/Terrarum/UserInterface/UICanvas.kt new file mode 100644 index 000000000..07e105666 --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/UICanvas.kt @@ -0,0 +1,21 @@ +package com.Torvald.Terrarum.UserInterface + +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Input + +/** + * Created by minjaesong on 16-03-14. + */ +interface UICanvas { + + var width: Int? + var height: Int? + + fun update(gc: GameContainer, delta_t: Int) + + fun render(gc: GameContainer, g: Graphics) + + fun processInput(input: Input) + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/UserInterface/UIClickable b/src/com/Torvald/Terrarum/UserInterface/UIClickable new file mode 100644 index 000000000..b4ef9a84e --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/UIClickable @@ -0,0 +1,22 @@ +package com.Torvald.Terrarum.UserInterface; + +/** + * Created by minjaesong on 16-03-06. + */ +public interface UIClickable { + + void mouseMoved(int oldx, int oldy, int newx, int newy); + + void mouseDragged(int oldx, int oldy, int newx, int newy); + + void mousePressed(int button, int x, int y); + + void mouseReleased(int button, int x, int y); + + void mouseWheelMoved(int change); + + void controllerButtonPressed(int controller, int button); + + void controllerButtonReleased(int controller, int button); + +} diff --git a/src/com/Torvald/Terrarum/UserInterface/UIClickable.kt b/src/com/Torvald/Terrarum/UserInterface/UIClickable.kt new file mode 100644 index 000000000..2d24eb925 --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/UIClickable.kt @@ -0,0 +1,21 @@ +package com.Torvald.Terrarum.UserInterface + +/** + * Created by minjaesong on 16-03-14. + */ +interface UIClickable { + fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) + + fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) + + fun mousePressed(button: Int, x: Int, y: Int) + + fun mouseReleased(button: Int, x: Int, y: Int) + + fun mouseWheelMoved(change: Int) + + fun controllerButtonPressed(controller: Int, button: Int) + + fun controllerButtonReleased(controller: Int, button: Int) + +} \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/UserInterface/UITypable b/src/com/Torvald/Terrarum/UserInterface/UITypable new file mode 100644 index 000000000..9766ea95a --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/UITypable @@ -0,0 +1,12 @@ +package com.Torvald.Terrarum.UserInterface; + +/** + * Created by minjaesong on 16-03-06. + */ +public interface UITypable { + + void keyPressed(int key, char c); + + void keyReleased(int key, char c); + +} diff --git a/src/com/Torvald/Terrarum/UserInterface/UITypable.kt b/src/com/Torvald/Terrarum/UserInterface/UITypable.kt new file mode 100644 index 000000000..1a62bc206 --- /dev/null +++ b/src/com/Torvald/Terrarum/UserInterface/UITypable.kt @@ -0,0 +1,10 @@ +package com.Torvald.Terrarum.UserInterface + +/** + * Created by minjaesong on 16-03-14. + */ +interface UITypable { + fun keyPressed(key: Int, c: Char) + + fun keyReleased(key: Int, c: Char) +} \ No newline at end of file diff --git a/src/com/jme3/math/FastMath.java b/src/com/jme3/math/FastMath.java index c9d5a643e..8018970d3 100644 --- a/src/com/jme3/math/FastMath.java +++ b/src/com/jme3/math/FastMath.java @@ -840,14 +840,14 @@ final public class FastMath { } public static float min(float... f) { - float[] sorted = f.clone(); - Arrays.sort(f.clone()); - return sorted[0]; + float min = f[0]; + for (int i = 1; i < f.length; i++) min = (f[i] < min) ? f[i] : min; + return min; } public static float max(float... f) { - float[] sorted = f.clone(); - Arrays.sort(f.clone()); - return sorted[sorted.length - 1]; + float max = f[0]; + for (int i = 1; i < f.length; i++) max = (f[i] > max) ? f[i] : max; + return max; } } diff --git a/src/com/sudoplay/joise/Joise.java b/src/com/sudoplay/joise/Joise.java new file mode 100755 index 000000000..029bd4908 --- /dev/null +++ b/src/com/sudoplay/joise/Joise.java @@ -0,0 +1,178 @@ +/* + * 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 new file mode 100755 index 000000000..3a888f168 --- /dev/null +++ b/src/com/sudoplay/joise/JoiseException.java @@ -0,0 +1,66 @@ +/* + * 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 new file mode 100755 index 000000000..f8502ca73 --- /dev/null +++ b/src/com/sudoplay/joise/ModuleInstanceMap.java @@ -0,0 +1,107 @@ +/* + * 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 new file mode 100755 index 000000000..fe5680701 --- /dev/null +++ b/src/com/sudoplay/joise/ModuleMap.java @@ -0,0 +1,103 @@ +/* + * 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 new file mode 100755 index 000000000..3f292c320 --- /dev/null +++ b/src/com/sudoplay/joise/ModulePropertyMap.java @@ -0,0 +1,154 @@ +/* + * 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/BasePRNG.java b/src/com/sudoplay/joise/generator/BasePRNG.java new file mode 100755 index 000000000..183f73bde --- /dev/null +++ b/src/com/sudoplay/joise/generator/BasePRNG.java @@ -0,0 +1,81 @@ +/* + * 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/CMWC4096.java b/src/com/sudoplay/joise/generator/CMWC4096.java new file mode 100755 index 000000000..42c6b3f04 --- /dev/null +++ b/src/com/sudoplay/joise/generator/CMWC4096.java @@ -0,0 +1,91 @@ +/* + * 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; + +/** + * Complimentary multiply with carry. + */ +public class CMWC4096 extends BasePRNG { + + protected int c; + protected int[] Q = new int[4096]; + protected LCG lcg = new LCG(); + protected int i; + + public CMWC4096() { + setSeed(10000); + } + + @Override + public int get() { + long t; + long a = 18782L; + long b = 4294967295L; + int r = (int) (b - 1); + i = (i + 1) & 4095; + t = a * Q[i] + c; + c = (int) (t >> 32); + t = (t & b) + c; + if (t > r) { + c++; + t = t - b; + } + return Q[i] = (int) (r - t); + } + + @Override + public void setSeed(long seed) { + lcg.setSeed(seed); + for (int i = 0; i < 4096; i++) { + Q[i] = lcg.get(); + } + c = lcg.getTarget(18781); + } + +} diff --git a/src/com/sudoplay/joise/generator/KISS.java b/src/com/sudoplay/joise/generator/KISS.java new file mode 100755 index 000000000..71236dc2b --- /dev/null +++ b/src/com/sudoplay/joise/generator/KISS.java @@ -0,0 +1,81 @@ +/* + * 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 class KISS extends BasePRNG { + + protected LCG lcg = new LCG(); + protected int z, w, jsr, jcong; + + public KISS() { + setSeed(10000); + } + + @Override + public int get() { + z = 36969 * (z & 65535) + (z >> 16); + w = 18000 * (w & 65535) + (w >> 16); + int mwc = (z << 16) + w; + jcong = 69069 * jcong + 1234567; + jsr ^= (jsr << 17); + jsr ^= (jsr >> 13); + jsr ^= (jsr << 5); + return ((mwc ^ jcong) + jsr); + } + + @Override + public void setSeed(long seed) { + lcg.setSeed(seed); + z = lcg.get(); + w = lcg.get(); + jsr = lcg.get(); + jcong = lcg.get(); + } + +} diff --git a/src/com/sudoplay/joise/generator/LCG.java b/src/com/sudoplay/joise/generator/LCG.java new file mode 100755 index 000000000..5d4f887bc --- /dev/null +++ b/src/com/sudoplay/joise/generator/LCG.java @@ -0,0 +1,72 @@ +/* + * 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; + +/** + * Linear congruential generator. + */ +public class LCG extends BasePRNG { + + protected long state; + + public LCG() { + setSeed(10000); + } + + @Override + public int get() { + return (int) (state = (25214903917L * state + 11) % 281474976710656L); + } + + @Override + public void setSeed(long seed) { + state = (int) seed; + } + +} diff --git a/src/com/sudoplay/joise/generator/MWC.java b/src/com/sudoplay/joise/generator/MWC.java new file mode 100755 index 000000000..1e8c0a24b --- /dev/null +++ b/src/com/sudoplay/joise/generator/MWC.java @@ -0,0 +1,75 @@ +/* + * 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; + +/** + * Multiply with carry. + */ +public class MWC extends BasePRNG { + + protected LCG lcg = new LCG(); + protected long x; + protected long a = 0xffffda61L; + + public MWC() { + setSeed(10000); + } + + @Override + public int get() { + return (int) (x = (a * (x & 0xffffffffL)) + (x >>> 32)); + } + + @Override + public void setSeed(long seed) { + lcg.setSeed(seed); + x = lcg.get() & 0xffffffffL; + } + +} diff --git a/src/com/sudoplay/joise/generator/MWC256.java b/src/com/sudoplay/joise/generator/MWC256.java new file mode 100755 index 000000000..cd22c4113 --- /dev/null +++ b/src/com/sudoplay/joise/generator/MWC256.java @@ -0,0 +1,83 @@ +/* + * 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; + +/** + * Multiply with carry. + */ +public class MWC256 extends BasePRNG { + + protected int[] Q = new int[256]; + protected int c; + protected LCG lcg = new LCG(); + protected byte b = (byte) 255; + + public MWC256() { + setSeed(10000); + } + + @Override + public int get() { + long t; + long a = 809430660L; + t = a * Q[++b & 0xFF] + c; + c = (int) (t >> 32); + return Q[b & 0xFF] = (int) t; + } + + @Override + public void setSeed(long seed) { + lcg.setSeed(seed); + for (int i = 0; i < 256; i++) { + Q[i] = lcg.get(); + } + c = lcg.getTarget(809430660); + } + +} diff --git a/src/com/sudoplay/joise/generator/XORShift.java b/src/com/sudoplay/joise/generator/XORShift.java new file mode 100755 index 000000000..1f4c3723b --- /dev/null +++ b/src/com/sudoplay/joise/generator/XORShift.java @@ -0,0 +1,82 @@ +/* + * 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 class XORShift extends BasePRNG { + + protected int x, y, z, w, v; + protected LCG lcg = new LCG(); + + public XORShift() { + setSeed(10000); + } + + @Override + public int get() { + int t; + t = (x ^ (x >> 7)); + x = y; + y = z; + z = w; + w = v; + v = (v ^ (v << 6)) ^ (t ^ (t << 13)); + return (y + y + 1) * v; + } + + @Override + public void setSeed(long seed) { + lcg.setSeed(seed); + x = lcg.get(); + y = lcg.get(); + z = lcg.get(); + w = lcg.get(); + v = lcg.get(); + } + +} diff --git a/src/com/sudoplay/joise/mapping/Array2Double.java b/src/com/sudoplay/joise/mapping/Array2Double.java new file mode 100755 index 000000000..afa79a4f3 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/Array2Double.java @@ -0,0 +1,96 @@ +/* + * 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 new file mode 100755 index 000000000..e419470db --- /dev/null +++ b/src/com/sudoplay/joise/mapping/Array2DoubleWriter.java @@ -0,0 +1,72 @@ +/* + * 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 new file mode 100755 index 000000000..cabeb1623 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/Array3Double.java @@ -0,0 +1,100 @@ +/* + * 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 new file mode 100755 index 000000000..429b502ec --- /dev/null +++ b/src/com/sudoplay/joise/mapping/Array3DoubleWriter.java @@ -0,0 +1,72 @@ +/* + * 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 new file mode 100755 index 000000000..540512347 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/Mapping.java @@ -0,0 +1,753 @@ +/* + * 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 new file mode 100755 index 000000000..a117f8907 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/Mapping2DWriter.java @@ -0,0 +1,62 @@ +/* + * 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 new file mode 100755 index 000000000..79f8fff32 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/Mapping3DWriter.java @@ -0,0 +1,62 @@ +/* + * 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 new file mode 100755 index 000000000..b6626d950 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/MappingMode.java @@ -0,0 +1,53 @@ +/* + * 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 new file mode 100755 index 000000000..6ade070e5 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/MappingRange.java @@ -0,0 +1,60 @@ +/* + * 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 new file mode 100755 index 000000000..32b04fea0 --- /dev/null +++ b/src/com/sudoplay/joise/mapping/MappingUpdateListener.java @@ -0,0 +1,62 @@ +/* + * 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 new file mode 100755 index 000000000..c0ff6f8d8 --- /dev/null +++ b/src/com/sudoplay/joise/module/Module.java @@ -0,0 +1,371 @@ +/* + * 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 new file mode 100755 index 000000000..a89abd5d6 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleAbs.java @@ -0,0 +1,97 @@ +/* + * 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 new file mode 100755 index 000000000..29dc9f516 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleAutoCorrect.java @@ -0,0 +1,305 @@ +/* + * 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.LCG; +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; + LCG lcg = new LCG(); + + // 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 new file mode 100755 index 000000000..0f27bb3a9 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleBasisFunction.java @@ -0,0 +1,334 @@ +/* + * 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.LCG; +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); + + LCG lcg = new LCG(); + 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 new file mode 100755 index 000000000..128ee36d0 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleBias.java @@ -0,0 +1,125 @@ +/* + * 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 new file mode 100755 index 000000000..849144755 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleBlend.java @@ -0,0 +1,144 @@ +/* + * 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 new file mode 100755 index 000000000..f80d975eb --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleBrightContrast.java @@ -0,0 +1,163 @@ +/* + * 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 new file mode 100755 index 000000000..09b187447 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleCache.java @@ -0,0 +1,140 @@ +/* + * 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 new file mode 100755 index 000000000..8a766a8b7 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleCellGen.java @@ -0,0 +1,176 @@ +/* + * 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 new file mode 100755 index 000000000..b5870a0ce --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleCellular.java @@ -0,0 +1,161 @@ +/* + * 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 new file mode 100755 index 000000000..e7beae514 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleClamp.java @@ -0,0 +1,127 @@ +/* + * 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 new file mode 100755 index 000000000..ec0e1e1ac --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleCombiner.java @@ -0,0 +1,489 @@ +/* + * 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 new file mode 100755 index 000000000..d0fbe8ee5 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleCos.java @@ -0,0 +1,97 @@ +/* + * 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 new file mode 100755 index 000000000..e463749d7 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleFloor.java @@ -0,0 +1,97 @@ +/* + * 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 new file mode 100755 index 000000000..41c841999 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleFractal.java @@ -0,0 +1,1035 @@ +/* + * 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 new file mode 100755 index 000000000..237c23d9f --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleFunctionGradient.java @@ -0,0 +1,206 @@ +/* + * 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 new file mode 100755 index 000000000..74ad975c4 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleGain.java @@ -0,0 +1,120 @@ +/* + * 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 new file mode 100755 index 000000000..fea7268cb --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleGradient.java @@ -0,0 +1,204 @@ +/* + * 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 new file mode 100755 index 000000000..2d97d8287 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleInvert.java @@ -0,0 +1,97 @@ +/* + * 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 new file mode 100755 index 000000000..54d14952d --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleMagnitude.java @@ -0,0 +1,177 @@ +/* + * 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 new file mode 100755 index 000000000..48f847bc2 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleNormalizedCoords.java @@ -0,0 +1,137 @@ +/* + * 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 new file mode 100755 index 000000000..c5b41f1d5 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModulePow.java @@ -0,0 +1,111 @@ +/* + * 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 new file mode 100755 index 000000000..6a4053c29 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleRotateDomain.java @@ -0,0 +1,227 @@ +/* + * 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 new file mode 100755 index 000000000..d973022be --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleSawtooth.java @@ -0,0 +1,113 @@ +/* + * 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 new file mode 100755 index 000000000..3515c1211 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleScaleDomain.java @@ -0,0 +1,171 @@ +/* + * 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 new file mode 100755 index 000000000..3c8f72064 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleScaleOffset.java @@ -0,0 +1,122 @@ +/* + * 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 new file mode 100755 index 000000000..c5beac715 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleSelect.java @@ -0,0 +1,245 @@ +/* + * 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 new file mode 100755 index 000000000..c9d2b2e15 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleSin.java @@ -0,0 +1,97 @@ +/* + * 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 new file mode 100755 index 000000000..ca271e052 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleSphere.java @@ -0,0 +1,206 @@ +/* + * 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 new file mode 100755 index 000000000..6e9e64fda --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleTiers.java @@ -0,0 +1,173 @@ +/* + * 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 new file mode 100755 index 000000000..d69dca6c4 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleTranslateDomain.java @@ -0,0 +1,169 @@ +/* + * 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 new file mode 100755 index 000000000..7bb1ee2d1 --- /dev/null +++ b/src/com/sudoplay/joise/module/ModuleTriangle.java @@ -0,0 +1,176 @@ +/* + * 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 new file mode 100755 index 000000000..bc533e44d --- /dev/null +++ b/src/com/sudoplay/joise/module/ScalarParameter.java @@ -0,0 +1,114 @@ +/* + * 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 new file mode 100755 index 000000000..f57598773 --- /dev/null +++ b/src/com/sudoplay/joise/module/SeedableModule.java @@ -0,0 +1,94 @@ +/* + * 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 new file mode 100755 index 000000000..52d694898 --- /dev/null +++ b/src/com/sudoplay/joise/module/SourcedModule.java @@ -0,0 +1,79 @@ +/* + * 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 new file mode 100755 index 000000000..5c57d5906 --- /dev/null +++ b/src/com/sudoplay/joise/noise/Interpolator.java @@ -0,0 +1,83 @@ +/* + * 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 new file mode 100755 index 000000000..e05808c83 --- /dev/null +++ b/src/com/sudoplay/joise/noise/Noise.java @@ -0,0 +1,1387 @@ +/* + * 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 new file mode 100755 index 000000000..ab5e63ba5 --- /dev/null +++ b/src/com/sudoplay/joise/noise/NoiseLUT.java @@ -0,0 +1,1121 @@ +/* + * 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 new file mode 100755 index 000000000..d81b701bb --- /dev/null +++ b/src/com/sudoplay/joise/noise/Util.java @@ -0,0 +1,101 @@ +/* + * 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 new file mode 100755 index 000000000..8251d1f64 --- /dev/null +++ b/src/com/sudoplay/util/Assert.java @@ -0,0 +1,121 @@ +/* + * 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 new file mode 100755 index 000000000..2395a75db --- /dev/null +++ b/src/com/sudoplay/util/Checked.java @@ -0,0 +1,63 @@ +/* + * 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/work_files/Tools/b24_col_to_40step_col.py b/work_files/Tools/b24_col_to_40step_col.py index fd2a78139..a59e31815 100644 --- a/work_files/Tools/b24_col_to_40step_col.py +++ b/work_files/Tools/b24_col_to_40step_col.py @@ -32,5 +32,5 @@ def intFromRGB24(r24, g24, b24): def colFromNum(raw): return getR40(raw), getG40(raw), getB40(raw) -print(intFromCol(12, 19, 39)) -print(colFromNum(5009)) +print(intFromRGB24(111, 0, 255)) +print(colFromNum(27239))