WorldMap now successfully IONIZABLE!

v5stable
Ondřej Hruška 11 years ago
parent b70279acd5
commit db3da1554d
  1. BIN
      fuck.ion
  2. BIN
      hello.ion
  3. BIN
      maptest.ion
  4. BIN
      moo.ion
  5. 1
      src/mightypork/gamecore/render/textures/FilteredTexture.java
  6. 3
      src/mightypork/rogue/App.java
  7. 4
      src/mightypork/rogue/screens/CrossfadeOverlay.java
  8. 2
      src/mightypork/rogue/screens/CrossfadeRequest.java
  9. 24
      src/mightypork/rogue/screens/ingame/GameGui.java
  10. 16
      src/mightypork/rogue/screens/ingame/HeartBar.java
  11. 15
      src/mightypork/rogue/screens/ingame/NavItemSlot.java
  12. 2
      src/mightypork/rogue/screens/ingame/ScreenGame.java
  13. 22
      src/mightypork/rogue/screens/main_menu/MenuLayer.java
  14. 9
      src/mightypork/rogue/world/Entity.java
  15. 7
      src/mightypork/rogue/world/EntityModel.java
  16. 58
      src/mightypork/rogue/world/WorldMap.java
  17. 2
      src/mightypork/rogue/world/item/ItemData.java
  18. 2
      src/mightypork/rogue/world/item/Items.java
  19. 16
      src/mightypork/rogue/world/tile/Tile.java
  20. 6
      src/mightypork/rogue/world/tile/TileData.java
  21. 2
      src/mightypork/rogue/world/tile/Tiles.java
  22. 84
      src/mightypork/test/FakeTile.java
  23. 4
      src/mightypork/test/TestIonArray.java
  24. 26
      src/mightypork/test/TestIonArray2.java
  25. 8
      src/mightypork/test/TestPerlin.java
  26. 46
      src/mightypork/test/TestTileMap.java
  27. 1
      src/mightypork/util/constraints/num/mutable/NumAnimated.java
  28. 16
      src/mightypork/util/control/timing/TimedTask.java
  29. 84
      src/mightypork/util/files/ion/Ion.java
  30. 2
      src/mightypork/util/files/ion/IonDataBundle.java
  31. 2
      src/mightypork/util/math/noise/NoiseGen.java
  32. 154
      src/mightypork/util/math/noise/PerlinNoiseGenerator.java

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -11,7 +11,6 @@ import org.newdawn.slick.opengl.Texture;
*/ */
public interface FilteredTexture extends Texture { public interface FilteredTexture extends Texture {
/** /**
* Set filter for scaling * Set filter for scaling
* *

@ -22,6 +22,7 @@ import mightypork.rogue.screens.main_menu.ScreenMainMenu;
import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy; import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy;
import mightypork.rogue.screens.test_cat_sound.ScreenTestCat; import mightypork.rogue.screens.test_cat_sound.ScreenTestCat;
import mightypork.rogue.screens.test_render.ScreenTestRender; import mightypork.rogue.screens.test_render.ScreenTestRender;
import mightypork.rogue.world.WorldMap;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.util.control.eventbus.EventBus; import mightypork.util.control.eventbus.EventBus;
@ -107,8 +108,10 @@ public final class App extends BaseApp {
{ {
Ion.registerIonizable(Tile.ION_MARK, Tile.class); Ion.registerIonizable(Tile.ION_MARK, Tile.class);
Ion.registerIonizable(Item.ION_MARK, Item.class); Ion.registerIonizable(Item.ION_MARK, Item.class);
Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class);
} }
@Override @Override
protected File getLockFile() protected File getLockFile()
{ {

@ -26,7 +26,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen
@Override @Override
public void run() public void run()
{ {
if(requestedScreenName == null) shutdown(); if (requestedScreenName == null) shutdown();
getEventBus().send(new ScreenRequestEvent(requestedScreenName)); getEventBus().send(new ScreenRequestEvent(requestedScreenName));
} }
}; };
@ -45,7 +45,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen
public CrossfadeOverlay(AppAccess app) { public CrossfadeOverlay(AppAccess app) {
super(app); super(app);
QuadPainter qp = new QuadPainter(color); final QuadPainter qp = new QuadPainter(color);
qp.setRect(root); qp.setRect(root);
root.add(qp); root.add(qp);

@ -9,7 +9,7 @@ import mightypork.util.control.eventbus.events.Event;
*/ */
public class CrossfadeRequest implements Event<CrossfadeRequest.Listener> { public class CrossfadeRequest implements Event<CrossfadeRequest.Listener> {
private String screen; private final String screen;
/** /**

@ -19,35 +19,35 @@ public class GameGui extends ScreenLayer {
public GameGui(Screen screen) { public GameGui(Screen screen) {
super(screen); super(screen);
Num h = root.height(); final Num h = root.height();
Num w = root.width(); final Num w = root.width();
Num minWH = w.min(h).max(700); // avoid too small shrinking final Num minWH = w.min(h).max(700); // avoid too small shrinking
Component qp = new QuadPainter(PAL16.VOID); final Component qp = new QuadPainter(PAL16.VOID);
qp.setRect(root); qp.setRect(root);
root.add(qp); root.add(qp);
ImagePainter nav = new ImagePainter(Res.getTxQuad("panel")); final ImagePainter nav = new ImagePainter(Res.getTxQuad("panel"));
nav.setRect(root.bottomEdge().growUp(minWH.perc(7))); nav.setRect(root.bottomEdge().growUp(minWH.perc(7)));
root.add(nav); root.add(nav);
HorizontalFixedFlowLayout itemSlots = new HorizontalFixedFlowLayout(root, nav.height().mul(1.8), AlignX.LEFT); final HorizontalFixedFlowLayout itemSlots = new HorizontalFixedFlowLayout(root, nav.height().mul(1.8), AlignX.LEFT);
itemSlots.setRect(nav.growUp(nav.height()).move(nav.height().mul(0.2), nav.height().mul(-0.2))); itemSlots.setRect(nav.growUp(nav.height()).move(nav.height().mul(0.2), nav.height().mul(-0.2)));
root.add(itemSlots); root.add(itemSlots);
itemSlots.add(new NavItemSlot(Res.getTxQuad("meat"))); itemSlots.add(new NavItemSlot(Res.getTxQuad("meat")));
itemSlots.add(new NavItemSlot(Res.getTxQuad("sword"))); itemSlots.add(new NavItemSlot(Res.getTxQuad("sword")));
Rect shrunk = root.shrink(minWH.perc(3)); final Rect shrunk = root.shrink(minWH.perc(3));
Num displays_height = minWH.perc(6); final Num displays_height = minWH.perc(6);
HeartBar hearts = new HeartBar(6, 3, Res.getTxQuad("heart_on"), Res.getTxQuad("heart_off"), AlignX.LEFT); final HeartBar hearts = new HeartBar(6, 3, Res.getTxQuad("heart_on"), Res.getTxQuad("heart_off"), AlignX.LEFT);
Rect hearts_box = shrunk.topLeft().startRect().growDown(displays_height); final Rect hearts_box = shrunk.topLeft().startRect().growDown(displays_height);
hearts.setRect(hearts_box); hearts.setRect(hearts_box);
root.add(hearts); root.add(hearts);
HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT); final HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT);
Rect xp_box = shrunk.topRight().startRect().growDown(displays_height); final Rect xp_box = shrunk.topRight().startRect().growDown(displays_height);
experience.setRect(xp_box); experience.setRect(xp_box);
root.add(experience); root.add(experience);
} }

@ -12,10 +12,10 @@ import mightypork.util.constraints.rect.Rect;
public class HeartBar extends VisualComponent { public class HeartBar extends VisualComponent {
private TxQuad img_on; private final TxQuad img_on;
private TxQuad img_off; private final TxQuad img_off;
private int total; private final int total;
private int active; private final int active;
NumVar index = new NumVar(0); NumVar index = new NumVar(0);
Rect heart; Rect heart;
@ -35,18 +35,18 @@ public class HeartBar extends VisualComponent {
this.img_on = img_on; this.img_on = img_on;
this.img_off = img_off; this.img_off = img_off;
Num h = height(); final Num h = height();
Num w = width(); final Num w = width();
switch (align) { switch (align) {
case LEFT: case LEFT:
heart = leftEdge().growRight(h).moveX(index.mul(h)); heart = leftEdge().growRight(h).moveX(index.mul(h));
break; break;
case RIGHT: case RIGHT:
heart = rightEdge().growLeft(h).moveX(h.mul(-total+1).add(index.mul(h))); heart = rightEdge().growLeft(h).moveX(h.mul(-total + 1).add(index.mul(h)));
break; break;
case CENTER: case CENTER:
heart = leftEdge().moveX(w.half().add(h.mul(-total/2D))).growRight(h).moveX(index.mul(h)); heart = leftEdge().moveX(w.half().add(h.mul(-total / 2D))).growRight(h).moveX(index.mul(h));
break; break;
} }

@ -1,8 +1,8 @@
package mightypork.rogue.screens.ingame; package mightypork.rogue.screens.ingame;
import mightypork.gamecore.control.events.MouseMotionEvent;
import mightypork.gamecore.gui.components.ClickableComponent; import mightypork.gamecore.gui.components.ClickableComponent;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.textures.TxQuad; import mightypork.gamecore.render.textures.TxQuad;
import mightypork.rogue.Res; import mightypork.rogue.Res;
@ -13,15 +13,14 @@ import mightypork.util.constraints.rect.caching.RectCache;
import mightypork.util.constraints.vect.Vect; import mightypork.util.constraints.vect.Vect;
import mightypork.util.control.timing.Updateable; import mightypork.util.control.timing.Updateable;
import mightypork.util.math.Easing; import mightypork.util.math.Easing;
import mightypork.gamecore.control.events.MouseMotionEvent;
public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.Listener, Updateable { public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.Listener, Updateable {
private TxQuad image; private final TxQuad image;
private TxQuad frame; private final TxQuad frame;
private RectCache paintBox; private final RectCache paintBox;
private NumAnimated yOffset; private final NumAnimated yOffset;
private boolean wasInside = false; private boolean wasInside = false;
@ -29,11 +28,11 @@ public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.
this.image = image; this.image = image;
this.frame = Res.getTxQuad("item_frame"); this.frame = Res.getTxQuad("item_frame");
Rect ref = shrink(height().perc(8)); final Rect ref = shrink(height().perc(8));
yOffset = new NumAnimated(0, Easing.LINEAR); yOffset = new NumAnimated(0, Easing.LINEAR);
yOffset.setDefaultDuration(0.05); yOffset.setDefaultDuration(0.05);
Num h = ref.width().min(ref.height()); final Num h = ref.width().min(ref.height());
this.paintBox = ref.bottomLeft().startRect().grow(Num.ZERO, h, h, Num.ZERO).moveY(yOffset.mul(h.perc(-5))).cached(); this.paintBox = ref.bottomLeft().startRect().grow(Num.ZERO, h, h, Num.ZERO).moveY(yOffset.mul(h.perc(-5))).cached();
} }

@ -1,5 +1,6 @@
package mightypork.rogue.screens.ingame; package mightypork.rogue.screens.ingame;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.screens.LayeredScreen; import mightypork.gamecore.gui.screens.LayeredScreen;
@ -12,6 +13,7 @@ public class ScreenGame extends LayeredScreen {
addLayer(new GameGui(this)); addLayer(new GameGui(this));
} }
@Override @Override
public String getName() public String getName()
{ {

@ -1,7 +1,6 @@
package mightypork.rogue.screens.main_menu; package mightypork.rogue.screens.main_menu;
import mightypork.gamecore.control.events.ScreenRequestEvent;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.GridLayout; import mightypork.gamecore.gui.components.layout.GridLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
@ -9,8 +8,6 @@ import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.BaseScreen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.rogue.screens.CrossfadeRequest; import mightypork.rogue.screens.CrossfadeRequest;
import mightypork.util.constraints.num.Num; import mightypork.util.constraints.num.Num;
import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.Rect;
@ -49,13 +46,18 @@ class MenuLayer extends ScreenLayer {
b3 = new MenuButton("Flying Cat", PAL16.PIGMEAT); b3 = new MenuButton("Flying Cat", PAL16.PIGMEAT);
b4 = new MenuButton("Bye!", PAL16.BLOODRED); b4 = new MenuButton("Bye!", PAL16.BLOODRED);
int r=0; int r = 0;
layout.put(tp, r, 0, 4, 1); r += 5; layout.put(tp, r, 0, 4, 1);
layout.put(b0, r, 0, 2, 1); r += 3; r += 5;
layout.put(b1, r, 0, 2, 1); r += 2; layout.put(b0, r, 0, 2, 1);
layout.put(b2, r, 0, 2, 1); r += 2; r += 3;
layout.put(b3, r, 0, 2, 1); r += 3; layout.put(b1, r, 0, 2, 1);
r += 2;
layout.put(b2, r, 0, 2, 1);
r += 2;
layout.put(b3, r, 0, 2, 1);
r += 3;
layout.put(b4, r, 0, 2, 1); layout.put(b4, r, 0, 2, 1);
root.add(layout); root.add(layout);

@ -57,6 +57,15 @@ public abstract class Entity<D, M extends EntityModel<D, R>, R extends RectBound
} }
/**
* @return data
*/
public final D getData()
{
return data;
}
/** /**
* @return entity model * @return entity model
*/ */

@ -1,6 +1,7 @@
package mightypork.rogue.world; package mightypork.rogue.world;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -57,8 +58,9 @@ public abstract class EntityModel<D, R extends RectBound> {
* *
* @param data data to load * @param data data to load
* @param in input stream * @param in input stream
* @throws IOException
*/ */
public abstract void load(D data, InputStream in); public abstract void load(D data, InputStream in) throws IOException;
/** /**
@ -66,9 +68,10 @@ public abstract class EntityModel<D, R extends RectBound> {
* *
* @param data data to save * @param data data to save
* @param out output stream * @param out output stream
* @throws IOException
*/ */
@DefaultImpl @DefaultImpl
public abstract void save(D data, OutputStream out); public abstract void save(D data, OutputStream out) throws IOException;
/** /**

@ -13,12 +13,19 @@ import mightypork.util.files.ion.Ionizable;
public class WorldMap implements TileHolder, Ionizable { public class WorldMap implements TileHolder, Ionizable {
public static final int ION_MARK = 702;
private int width, height; private int width, height;
/** Array of tiles [y][x] */ /** Array of tiles [y][x] */
private Tile[][] tiles; private Tile[][] tiles;
public WorldMap() {
// constructor for ION
}
public WorldMap(int width, int height) { public WorldMap(int width, int height) {
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -33,27 +40,33 @@ public class WorldMap implements TileHolder, Ionizable {
@Override @Override
public Tile getTile(int x, int y) public final Tile getTile(int x, int y)
{ {
return tiles[y][x]; return tiles[y][x];
} }
public void setTile(Tile tile, int x, int y) public final void setTile(int tileId, int x, int y)
{
setTile(new Tile(tileId), x, y);
}
public final void setTile(Tile tile, int x, int y)
{ {
tiles[y][x] = tile; tiles[y][x] = tile;
} }
@Override @Override
public int getWidth() public final int getWidth()
{ {
return width; return width;
} }
@Override @Override
public int getHeight() public final int getHeight()
{ {
return height; return height;
} }
@ -67,23 +80,52 @@ public class WorldMap implements TileHolder, Ionizable {
buildArray(); buildArray();
short mark; while (true) {
final short mark = Ion.readMark(in);
if (mark == Ion.END) {
break;
} else if (mark == Ion.ENTRY) {
final int x = Ion.readInt(in);
final int y = Ion.readInt(in);
mark = Ion.readMark(in); final Tile tile = (Tile) Ion.readObject(in);
if(mark == Ion.START);
setTile(tile, x, y);
} else {
throw new IOException("Invalid mark encountered while reading tile map.");
}
}
} }
@Override @Override
public void saveTo(OutputStream out) throws IOException public void saveTo(OutputStream out) throws IOException
{ {
Ion.writeInt(out, width);
Ion.writeInt(out, height);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
final Tile t = getTile(x, y);
if (t != null) {
Ion.writeMark(out, Ion.ENTRY);
Ion.writeInt(out, x);
Ion.writeInt(out, y);
Ion.writeObject(out, t);
}
}
}
Ion.writeMark(out, Ion.END);
} }
@Override @Override
public short getIonMark() public short getIonMark()
{ {
return 0; return ION_MARK;
} }
} }

@ -2,7 +2,7 @@ package mightypork.rogue.world.item;
/** /**
* Item data object. Can be extended for particular models' needs. * Item data object.
* *
* @author MightyPork * @author MightyPork
*/ */

@ -10,7 +10,7 @@ public final class Items {
private static final Map<Integer, ItemModel> registered = new HashMap<>(); private static final Map<Integer, ItemModel> registered = new HashMap<>();
public static void register(int id, ItemModel model) static void register(int id, ItemModel model)
{ {
if (registered.containsKey(id)) throw new IllegalArgumentException("Item ID " + id + " already in use."); if (registered.containsKey(id)) throw new IllegalArgumentException("Item ID " + id + " already in use.");
registered.put(id, model); registered.put(id, model);

@ -1,8 +1,6 @@
package mightypork.rogue.world.tile; package mightypork.rogue.world.tile;
import java.util.Stack;
import mightypork.rogue.world.Entity; import mightypork.rogue.world.Entity;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
@ -16,12 +14,6 @@ public final class Tile extends Entity<TileData, TileModel, TileRenderContext> {
public static final short ION_MARK = 700; public static final short ION_MARK = 700;
/** Items dropped onto this tile */
public final Stack<Item> items = new Stack<>();
/** Whether the tile is occupied by an entity */
public boolean occupied;
public Tile() { public Tile() {
super(); super();
@ -58,8 +50,8 @@ public final class Tile extends Entity<TileData, TileModel, TileRenderContext> {
super.render(context); super.render(context);
// render laying-on-top item // render laying-on-top item
if (!items.isEmpty()) { if (!data.items.isEmpty()) {
Item item = items.peek(); final Item item = data.items.peek();
item.render(context.getRect()); item.render(context.getRect());
} }
@ -72,8 +64,8 @@ public final class Tile extends Entity<TileData, TileModel, TileRenderContext> {
super.update(delta); super.update(delta);
// update laying-on-top item // update laying-on-top item
if (!items.isEmpty()) { if (!data.items.isEmpty()) {
Item item = items.peek(); final Item item = data.items.peek();
item.update(delta); item.update(delta);
} }
} }

@ -5,8 +5,9 @@ import java.util.Stack;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
/** /**
* Tile data object. Can be extended for particular models' needs. * Tile data object.
* *
* @author MightyPork * @author MightyPork
*/ */
@ -15,4 +16,7 @@ public abstract class TileData {
/** Items dropped onto this tile */ /** Items dropped onto this tile */
public final Stack<Item> items = new Stack<>(); public final Stack<Item> items = new Stack<>();
/** Whether the tile is occupied by an entity */
public boolean occupied;
} }

@ -10,7 +10,7 @@ public final class Tiles {
private static final Map<Integer, TileModel> registered = new HashMap<>(); private static final Map<Integer, TileModel> registered = new HashMap<>();
public static void register(int id, TileModel model) static void register(int id, TileModel model)
{ {
if (registered.containsKey(id)) throw new IllegalArgumentException("Tile ID " + id + " already in use."); if (registered.containsKey(id)) throw new IllegalArgumentException("Tile ID " + id + " already in use.");
registered.put(id, model); registered.put(id, model);

@ -0,0 +1,84 @@
package mightypork.test;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import mightypork.rogue.world.tile.TileData;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderContext;
import mightypork.util.files.ion.Ion;
class FakeTileData extends TileData {
int number;
String name;
}
public class FakeTile extends TileModel {
public FakeTile(int id) {
super(id);
}
@Override
public boolean isPotentiallyWalkable()
{
return true;
}
@Override
public boolean isWalkable(TileData data)
{
return true;
}
@Override
public TileData createData()
{
return new FakeTileData() {
{
number = 255;
name = "ABC";
}
};
}
@Override
public void load(TileData data, InputStream in) throws IOException
{
((FakeTileData) data).name = Ion.readString(in);
((FakeTileData) data).number = Ion.readInt(in);
}
@Override
public void save(TileData data, OutputStream out) throws IOException
{
Ion.writeString(out, ((FakeTileData) data).name);
Ion.writeInt(out, ((FakeTileData) data).number);
}
@Override
public void render(TileData data, TileRenderContext context)
{
//
}
@Override
public void update(TileData item, double delta)
{
//
}
}

@ -12,9 +12,9 @@ public class TestIonArray {
public static void main(String[] args) throws IOException public static void main(String[] args) throws IOException
{ {
byte[] array = new byte[1024 * 8]; final byte[] array = new byte[1024 * 8];
Random rand = new Random(); final Random rand = new Random();
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
array[i] = (byte) rand.nextInt(); array[i] = (byte) rand.nextInt();

@ -1,7 +1,12 @@
package mightypork.test; package mightypork.test;
import java.io.*; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import mightypork.util.files.ion.Ion; import mightypork.util.files.ion.Ion;
@ -9,9 +14,9 @@ public class TestIonArray2 {
public static void main(String[] args) throws IOException public static void main(String[] args) throws IOException
{ {
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9,99999,8888888 }; final int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 99999, 8888888 };
OutputStream out = new FileOutputStream("fuck.ion"); final OutputStream out = new FileOutputStream("fuck.ion");
Ion.writeIntArray(out, array); Ion.writeIntArray(out, array);
Ion.writeString(out, "HELLO DUDE WHATSUP"); Ion.writeString(out, "HELLO DUDE WHATSUP");
@ -19,21 +24,20 @@ public class TestIonArray2 {
// --- // ---
InputStream in = new FileInputStream("fuck.ion"); final InputStream in = new FileInputStream("fuck.ion");
int[] a = Ion.readIntArray(in); final int[] a = Ion.readIntArray(in);
for (int i : a) for (final int i : a)
System.out.println(i); System.out.println(i);
String s = Ion.readString(in); final String s = Ion.readString(in);
System.out.println(s); System.out.println(s);
final char[] v = Ion.readCharArray(in);
char[] v = Ion.readCharArray(in); for (final int i : v)
System.out.print((char) i);
for (int i : v)
System.out.print((char)i);
} }
} }

@ -12,13 +12,13 @@ public class TestPerlin {
{ {
Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.ENGLISH);
int w = 50, h = 50; final int w = 50, h = 50;
NoiseGen ng = new NoiseGen(0.12, 0, 2.5, 5, (long) (Math.random()*100)); final NoiseGen ng = new NoiseGen(0.12, 0, 2.5, 5, (long) (Math.random() * 100));
double[][] map = ng.buildMap(w, h); final double[][] map = ng.buildMap(w, h);
char[] colors = {' ', '░','▒','▓','█'}; final char[] colors = { ' ', '░', '▒', '▓', '█' };
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {

@ -0,0 +1,46 @@
package mightypork.test;
import java.io.IOException;
import mightypork.rogue.world.WorldMap;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel;
import mightypork.util.files.ion.Ion;
public class TestTileMap {
public static void main(String[] args) throws IOException
{
Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class);
Ion.registerIonizable(Tile.ION_MARK, Tile.class);
Ion.registerIonizable(Item.ION_MARK, Item.class);
// register tile
final TileModel tm = new FakeTile(1);
//
// WorldMap map = new WorldMap(10, 10);
//
// Random r = new Random();
//
// for(int i=0; i<10; i++) {
// map.setTile(1, r.nextInt(10),r.nextInt(10));
// }
//
// Ion.toFile("maptest.ion", map);
final WorldMap map = (WorldMap) Ion.fromFile("maptest.ion");
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
final Tile t = map.getTile(x, y);
System.out.print(" " + (t == null ? " " : ((FakeTileData) t.getData()).number));
}
System.out.println();
}
}
}

@ -74,6 +74,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
setEasing(easingIn, easingOut); setEasing(easingIn, easingOut);
} }
/** /**
* Create as copy of another * Create as copy of another
* *

@ -1,32 +1,38 @@
package mightypork.util.control.timing; package mightypork.util.control.timing;
import mightypork.util.constraints.num.mutable.NumAnimated; import mightypork.util.constraints.num.mutable.NumAnimated;
public abstract class TimedTask implements Runnable, Updateable { public abstract class TimedTask implements Runnable, Updateable {
private NumAnimated timer = new NumAnimated(0); private final NumAnimated timer = new NumAnimated(0);
private boolean running = false; private boolean running = false;
@Override @Override
public void update(double delta) public void update(double delta)
{ {
if(running) { if (running) {
timer.update(delta); timer.update(delta);
if(timer.isFinished()) { if (timer.isFinished()) {
running = false; running = false;
run(); run();
} }
} }
} }
public void start(double seconds) {
public void start(double seconds)
{
timer.reset(); timer.reset();
timer.animate(1, seconds); timer.animate(1, seconds);
running = true; running = true;
} }
public void stop() {
public void stop()
{
running = false; running = false;
timer.reset(); timer.reset();
} }

@ -70,16 +70,10 @@ public class Ion {
*/ */
public static final short ENTRY = 60; public static final short ENTRY = 60;
/**
* Start mark - general purpose, marks start of a sequence of stored
* objects.
*/
public static final short START = 61;
/** /**
* End mark - general purpose, marks end of sequence of stored objects. * End mark - general purpose, marks end of sequence of stored objects.
*/ */
public static final short END = 62; public static final short END = 61;
// built in 80..99 // built in 80..99
/** Map mark (built-in data structure) */ /** Map mark (built-in data structure) */
@ -135,7 +129,7 @@ public class Ion {
if (mark > Short.MAX_VALUE) throw new IllegalArgumentException("Mark too high (max " + Short.MAX_VALUE + ")."); if (mark > Short.MAX_VALUE) throw new IllegalArgumentException("Mark too high (max " + Short.MAX_VALUE + ").");
if (mark < Short.MIN_VALUE) throw new IllegalArgumentException("Mark too low (min " + Short.MIN_VALUE + ")."); if (mark < Short.MIN_VALUE) throw new IllegalArgumentException("Mark too low (min " + Short.MIN_VALUE + ").");
short m = (short) mark; final short m = (short) mark;
if (markRangeChecking && m >= 0 && m < 100) { if (markRangeChecking && m >= 0 && m < 100) {
throw new IllegalArgumentException("Marks 0..99 are reserved."); throw new IllegalArgumentException("Marks 0..99 are reserved.");
@ -304,7 +298,7 @@ public class Ion {
case BOOLEAN_ARRAY: case BOOLEAN_ARRAY:
length = readInt(in); length = readInt(in);
boolean[] bools = new boolean[length]; final boolean[] bools = new boolean[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
bools[i] = readBoolean(in); bools[i] = readBoolean(in);
} }
@ -312,7 +306,7 @@ public class Ion {
case BYTE_ARRAY: case BYTE_ARRAY:
length = readInt(in); length = readInt(in);
byte[] bytes = new byte[length]; final byte[] bytes = new byte[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
bytes[i] = readByte(in); bytes[i] = readByte(in);
} }
@ -320,7 +314,7 @@ public class Ion {
case CHAR_ARRAY: case CHAR_ARRAY:
length = readInt(in); length = readInt(in);
char[] chars = new char[length]; final char[] chars = new char[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
chars[i] = readChar(in); chars[i] = readChar(in);
} }
@ -328,7 +322,7 @@ public class Ion {
case SHORT_ARRAY: case SHORT_ARRAY:
length = readInt(in); length = readInt(in);
short[] shorts = new short[length]; final short[] shorts = new short[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
shorts[i] = readShort(in); shorts[i] = readShort(in);
} }
@ -336,7 +330,7 @@ public class Ion {
case INT_ARRAY: case INT_ARRAY:
length = readInt(in); length = readInt(in);
int[] ints = new int[length]; final int[] ints = new int[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
ints[i] = readInt(in); ints[i] = readInt(in);
} }
@ -344,7 +338,7 @@ public class Ion {
case LONG_ARRAY: case LONG_ARRAY:
length = readInt(in); length = readInt(in);
long[] longs = new long[length]; final long[] longs = new long[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
longs[i] = readLong(in); longs[i] = readLong(in);
} }
@ -352,7 +346,7 @@ public class Ion {
case FLOAT_ARRAY: case FLOAT_ARRAY:
length = readInt(in); length = readInt(in);
float[] floats = new float[length]; final float[] floats = new float[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
floats[i] = readFloat(in); floats[i] = readFloat(in);
} }
@ -360,7 +354,7 @@ public class Ion {
case DOUBLE_ARRAY: case DOUBLE_ARRAY:
length = readInt(in); length = readInt(in);
double[] doubles = new double[length]; final double[] doubles = new double[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
doubles[i] = readDouble(in); doubles[i] = readDouble(in);
} }
@ -368,7 +362,7 @@ public class Ion {
case STRING_ARRAY: case STRING_ARRAY:
length = readInt(in); length = readInt(in);
String[] Strings = new String[length]; final String[] Strings = new String[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Strings[i] = readString(in); Strings[i] = readString(in);
} }
@ -732,7 +726,7 @@ public class Ion {
public static void writeBooleanArray(OutputStream out, boolean[] arr) throws IOException public static void writeBooleanArray(OutputStream out, boolean[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (boolean a : arr) { for (final boolean a : arr) {
writeBoolean(out, a); writeBoolean(out, a);
} }
} }
@ -748,7 +742,7 @@ public class Ion {
public static void writeByteArray(OutputStream out, byte[] arr) throws IOException public static void writeByteArray(OutputStream out, byte[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (byte a : arr) { for (final byte a : arr) {
writeByte(out, a); writeByte(out, a);
} }
} }
@ -764,7 +758,7 @@ public class Ion {
public static void writeCharArray(OutputStream out, char[] arr) throws IOException public static void writeCharArray(OutputStream out, char[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (char a : arr) { for (final char a : arr) {
writeChar(out, a); writeChar(out, a);
} }
} }
@ -780,7 +774,7 @@ public class Ion {
public static void writeShortArray(OutputStream out, short[] arr) throws IOException public static void writeShortArray(OutputStream out, short[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (short a : arr) { for (final short a : arr) {
writeShort(out, a); writeShort(out, a);
} }
} }
@ -796,7 +790,7 @@ public class Ion {
public static void writeIntArray(OutputStream out, int[] arr) throws IOException public static void writeIntArray(OutputStream out, int[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (int a : arr) { for (final int a : arr) {
writeInt(out, a); writeInt(out, a);
} }
} }
@ -812,7 +806,7 @@ public class Ion {
public static void writeLongArray(OutputStream out, long[] arr) throws IOException public static void writeLongArray(OutputStream out, long[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (long a : arr) { for (final long a : arr) {
writeLong(out, a); writeLong(out, a);
} }
} }
@ -828,7 +822,7 @@ public class Ion {
public static void writeFloatArray(OutputStream out, float[] arr) throws IOException public static void writeFloatArray(OutputStream out, float[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (float a : arr) { for (final float a : arr) {
writeFloat(out, a); writeFloat(out, a);
} }
} }
@ -844,7 +838,7 @@ public class Ion {
public static void writeDoubleArray(OutputStream out, double[] arr) throws IOException public static void writeDoubleArray(OutputStream out, double[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (double a : arr) { for (final double a : arr) {
writeDouble(out, a); writeDouble(out, a);
} }
} }
@ -860,7 +854,7 @@ public class Ion {
public static void writeStringArray(OutputStream out, String[] arr) throws IOException public static void writeStringArray(OutputStream out, String[] arr) throws IOException
{ {
writeInt(out, arr.length); writeInt(out, arr.length);
for (String a : arr) { for (final String a : arr) {
writeString(out, a); writeString(out, a);
} }
} }
@ -888,7 +882,7 @@ public class Ion {
*/ */
public static byte readByte(InputStream in) throws IOException public static byte readByte(InputStream in) throws IOException
{ {
int b = in.read(); final int b = in.read();
if (-1 == b) throw new IOException("End of stream."); if (-1 == b) throw new IOException("End of stream.");
return (byte) b; return (byte) b;
} }
@ -1018,8 +1012,8 @@ public class Ion {
*/ */
public static boolean[] readBooleanArray(InputStream in) throws IOException public static boolean[] readBooleanArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
boolean[] booleans = new boolean[length]; final boolean[] booleans = new boolean[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
booleans[i] = readBoolean(in); booleans[i] = readBoolean(in);
} }
@ -1036,8 +1030,8 @@ public class Ion {
*/ */
public static byte[] readByteArray(InputStream in) throws IOException public static byte[] readByteArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
byte[] bytes = new byte[length]; final byte[] bytes = new byte[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
bytes[i] = readByte(in); bytes[i] = readByte(in);
} }
@ -1054,8 +1048,8 @@ public class Ion {
*/ */
public static char[] readCharArray(InputStream in) throws IOException public static char[] readCharArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
char[] chars = new char[length]; final char[] chars = new char[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
chars[i] = readChar(in); chars[i] = readChar(in);
} }
@ -1072,8 +1066,8 @@ public class Ion {
*/ */
public static short[] readShortArray(InputStream in) throws IOException public static short[] readShortArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
short[] shorts = new short[length]; final short[] shorts = new short[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
shorts[i] = readShort(in); shorts[i] = readShort(in);
} }
@ -1090,8 +1084,8 @@ public class Ion {
*/ */
public static int[] readIntArray(InputStream in) throws IOException public static int[] readIntArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
int[] ints = new int[length]; final int[] ints = new int[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
ints[i] = readInt(in); ints[i] = readInt(in);
} }
@ -1108,8 +1102,8 @@ public class Ion {
*/ */
public static long[] readLongArray(InputStream in) throws IOException public static long[] readLongArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
long[] longs = new long[length]; final long[] longs = new long[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
longs[i] = readLong(in); longs[i] = readLong(in);
} }
@ -1126,8 +1120,8 @@ public class Ion {
*/ */
public static float[] readFloatArray(InputStream in) throws IOException public static float[] readFloatArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
float[] floats = new float[length]; final float[] floats = new float[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
floats[i] = readFloat(in); floats[i] = readFloat(in);
} }
@ -1144,8 +1138,8 @@ public class Ion {
*/ */
public static double[] readDoubleArray(InputStream in) throws IOException public static double[] readDoubleArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
double[] doubles = new double[length]; final double[] doubles = new double[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
doubles[i] = readDouble(in); doubles[i] = readDouble(in);
} }
@ -1162,8 +1156,8 @@ public class Ion {
*/ */
public static String[] readStringArray(InputStream in) throws IOException public static String[] readStringArray(InputStream in) throws IOException
{ {
int length = readInt(in); final int length = readInt(in);
String[] Strings = new String[length]; final String[] Strings = new String[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Strings[i] = readString(in); Strings[i] = readString(in);
} }

@ -1,7 +1,6 @@
package mightypork.util.files.ion; package mightypork.util.files.ion;
/** /**
* Ionizable HashMap<String, Object> with getters and setters for individual * Ionizable HashMap<String, Object> with getters and setters for individual
* supported types. * supported types.
@ -118,7 +117,6 @@ public class IonDataBundle extends IonMap<String, Object> {
} }
public Object getOfType(String key, Class<?> type) public Object getOfType(String key, Class<?> type)
{ {
final Object o = super.get(key); final Object o = super.get(key);

@ -81,7 +81,7 @@ public class NoiseGen {
*/ */
public double[][] buildMap(int width, int height) public double[][] buildMap(int width, int height)
{ {
double[][] map = new double[height][width]; final double[][] map = new double[height][width];
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {

@ -48,7 +48,7 @@ public class PerlinNoiseGenerator {
private final Random rand = new Random(DEFAULT_SEED); private final Random rand = new Random(DEFAULT_SEED);
/** Permutation array for the improved noise function */ /** Permutation array for the improved noise function */
private int[] p_imp; private final int[] p_imp;
/** P array for perline 1 noise */ /** P array for perline 1 noise */
private int[] p; private int[] p;
@ -103,39 +103,39 @@ public class PerlinNoiseGenerator {
public double improvedNoise(double x, double y, double z) public double improvedNoise(double x, double y, double z)
{ {
// Constraint the point to a unit cube // Constraint the point to a unit cube
int uc_x = (int) Math.floor(x) & 255; final int uc_x = (int) Math.floor(x) & 255;
int uc_y = (int) Math.floor(y) & 255; final int uc_y = (int) Math.floor(y) & 255;
int uc_z = (int) Math.floor(z) & 255; final int uc_z = (int) Math.floor(z) & 255;
// Relative location of the point in the unit cube // Relative location of the point in the unit cube
double xo = x - Math.floor(x); final double xo = x - Math.floor(x);
double yo = y - Math.floor(y); final double yo = y - Math.floor(y);
double zo = z - Math.floor(z); final double zo = z - Math.floor(z);
// Fade curves for x, y and z // Fade curves for x, y and z
double u = fade(xo); final double u = fade(xo);
double v = fade(yo); final double v = fade(yo);
double w = fade(zo); final double w = fade(zo);
// Generate a hash for each coordinate to find out where in the cube // Generate a hash for each coordinate to find out where in the cube
// it lies. // it lies.
int a = p_imp[uc_x] + uc_y; final int a = p_imp[uc_x] + uc_y;
int aa = p_imp[a] + uc_z; final int aa = p_imp[a] + uc_z;
int ab = p_imp[a + 1] + uc_z; final int ab = p_imp[a + 1] + uc_z;
int b = p_imp[uc_x + 1] + uc_y; final int b = p_imp[uc_x + 1] + uc_y;
int ba = p_imp[b] + uc_z; final int ba = p_imp[b] + uc_z;
int bb = p_imp[b + 1] + uc_z; final int bb = p_imp[b + 1] + uc_z;
// blend results from the 8 corners based on the noise function // blend results from the 8 corners based on the noise function
double c1 = grad(p_imp[aa], xo, yo, zo); final double c1 = grad(p_imp[aa], xo, yo, zo);
double c2 = grad(p_imp[ba], xo - 1, yo, zo); final double c2 = grad(p_imp[ba], xo - 1, yo, zo);
double c3 = grad(p_imp[ab], xo, yo - 1, zo); final double c3 = grad(p_imp[ab], xo, yo - 1, zo);
double c4 = grad(p_imp[bb], xo - 1, yo - 1, zo); final double c4 = grad(p_imp[bb], xo - 1, yo - 1, zo);
double c5 = grad(p_imp[aa + 1], xo, yo, zo - 1); final double c5 = grad(p_imp[aa + 1], xo, yo, zo - 1);
double c6 = grad(p_imp[ba + 1], xo - 1, yo, zo - 1); final double c6 = grad(p_imp[ba + 1], xo - 1, yo, zo - 1);
double c7 = grad(p_imp[ab + 1], xo, yo - 1, zo - 1); final double c7 = grad(p_imp[ab + 1], xo, yo - 1, zo - 1);
double c8 = grad(p_imp[bb + 1], xo - 1, yo - 1, zo - 1); final double c8 = grad(p_imp[bb + 1], xo - 1, yo - 1, zo - 1);
return lerp(w, lerp(v, lerp(u, c1, c2), lerp(u, c3, c4)), lerp(v, lerp(u, c5, c6), lerp(u, c7, c8))); return lerp(w, lerp(v, lerp(u, c1, c2), lerp(u, c3, c4)), lerp(v, lerp(u, c5, c6), lerp(u, c7, c8)));
} }
@ -149,16 +149,16 @@ public class PerlinNoiseGenerator {
*/ */
public double noise1(double x) public double noise1(double x)
{ {
double t = x + N; final double t = x + N;
int bx0 = ((int) t) & BM; final int bx0 = ((int) t) & BM;
int bx1 = (bx0 + 1) & BM; final int bx1 = (bx0 + 1) & BM;
double rx0 = t - (int) t; final double rx0 = t - (int) t;
double rx1 = rx0 - 1; final double rx1 = rx0 - 1;
double sx = sCurve(rx0); final double sx = sCurve(rx0);
double u = rx0 * g1[p[bx0]]; final double u = rx0 * g1[p[bx0]];
double v = rx1 * g1[p[bx1]]; final double v = rx1 * g1[p[bx1]];
return lerp(sx, u, v); return lerp(sx, u, v);
} }
@ -174,39 +174,39 @@ public class PerlinNoiseGenerator {
public double noise2(double x, double y) public double noise2(double x, double y)
{ {
double t = x + N; double t = x + N;
int bx0 = ((int) t) & BM; final int bx0 = ((int) t) & BM;
int bx1 = (bx0 + 1) & BM; final int bx1 = (bx0 + 1) & BM;
double rx0 = t - (int) t; final double rx0 = t - (int) t;
double rx1 = rx0 - 1; final double rx1 = rx0 - 1;
t = y + N; t = y + N;
int by0 = ((int) t) & BM; final int by0 = ((int) t) & BM;
int by1 = (by0 + 1) & BM; final int by1 = (by0 + 1) & BM;
double ry0 = t - (int) t; final double ry0 = t - (int) t;
double ry1 = ry0 - 1; final double ry1 = ry0 - 1;
int i = p[bx0]; final int i = p[bx0];
int j = p[bx1]; final int j = p[bx1];
int b00 = p[i + by0]; final int b00 = p[i + by0];
int b10 = p[j + by0]; final int b10 = p[j + by0];
int b01 = p[i + by1]; final int b01 = p[i + by1];
int b11 = p[j + by1]; final int b11 = p[j + by1];
double sx = sCurve(rx0); final double sx = sCurve(rx0);
double sy = sCurve(ry0); final double sy = sCurve(ry0);
double[] q = g2[b00]; double[] q = g2[b00];
double u = rx0 * q[0] + ry0 * q[1]; double u = rx0 * q[0] + ry0 * q[1];
q = g2[b10]; q = g2[b10];
double v = rx1 * q[0] + ry0 * q[1]; double v = rx1 * q[0] + ry0 * q[1];
double a = lerp(sx, u, v); final double a = lerp(sx, u, v);
q = g2[b01]; q = g2[b01];
u = rx0 * q[0] + ry1 * q[1]; u = rx0 * q[0] + ry1 * q[1];
q = g2[b11]; q = g2[b11];
v = rx1 * q[0] + ry1 * q[1]; v = rx1 * q[0] + ry1 * q[1];
double b = lerp(sx, u, v); final double b = lerp(sx, u, v);
return lerp(sy, a, b); return lerp(sy, a, b);
} }
@ -223,34 +223,34 @@ public class PerlinNoiseGenerator {
public double noise3(double x, double y, double z) public double noise3(double x, double y, double z)
{ {
double t = x + N; double t = x + N;
int bx0 = ((int) t) & BM; final int bx0 = ((int) t) & BM;
int bx1 = (bx0 + 1) & BM; final int bx1 = (bx0 + 1) & BM;
double rx0 = t - (int) t; final double rx0 = t - (int) t;
double rx1 = rx0 - 1; final double rx1 = rx0 - 1;
t = y + N; t = y + N;
int by0 = ((int) t) & BM; final int by0 = ((int) t) & BM;
int by1 = (by0 + 1) & BM; final int by1 = (by0 + 1) & BM;
double ry0 = t - (int) t; final double ry0 = t - (int) t;
double ry1 = ry0 - 1; final double ry1 = ry0 - 1;
t = z + N; t = z + N;
int bz0 = ((int) t) & BM; final int bz0 = ((int) t) & BM;
int bz1 = (bz0 + 1) & BM; final int bz1 = (bz0 + 1) & BM;
double rz0 = t - (int) t; final double rz0 = t - (int) t;
double rz1 = rz0 - 1; final double rz1 = rz0 - 1;
int i = p[bx0]; final int i = p[bx0];
int j = p[bx1]; final int j = p[bx1];
int b00 = p[i + by0]; final int b00 = p[i + by0];
int b10 = p[j + by0]; final int b10 = p[j + by0];
int b01 = p[i + by1]; final int b01 = p[i + by1];
int b11 = p[j + by1]; final int b11 = p[j + by1];
t = sCurve(rx0); t = sCurve(rx0);
double sy = sCurve(ry0); final double sy = sCurve(ry0);
double sz = sCurve(rz0); final double sz = sCurve(rz0);
double[] q = g3[b00 + bz0]; double[] q = g3[b00 + bz0];
double u = (rx0 * q[0] + ry0 * q[1] + rz0 * q[2]); double u = (rx0 * q[0] + ry0 * q[1] + rz0 * q[2]);
@ -264,7 +264,7 @@ public class PerlinNoiseGenerator {
v = (rx1 * q[0] + ry1 * q[1] + rz0 * q[2]); v = (rx1 * q[0] + ry1 * q[1] + rz0 * q[2]);
double b = lerp(t, u, v); double b = lerp(t, u, v);
double c = lerp(sy, a, b); final double c = lerp(sy, a, b);
q = g3[b00 + bz1]; q = g3[b00 + bz1];
u = (rx0 * q[0] + ry0 * q[1] + rz1 * q[2]); u = (rx0 * q[0] + ry0 * q[1] + rz1 * q[2]);
@ -278,7 +278,7 @@ public class PerlinNoiseGenerator {
v = (rx1 * q[0] + ry1 * q[1] + rz1 * q[2]); v = (rx1 * q[0] + ry1 * q[1] + rz1 * q[2]);
b = lerp(t, u, v); b = lerp(t, u, v);
double d = lerp(sy, a, b); final double d = lerp(sy, a, b);
return lerp(sz, c, d); return lerp(sz, c, d);
} }
@ -491,9 +491,9 @@ public class PerlinNoiseGenerator {
private double grad(int hash, double x, double y, double z) private double grad(int hash, double x, double y, double z)
{ {
// Convert low 4 bits of hash code into 12 gradient directions. // Convert low 4 bits of hash code into 12 gradient directions.
int h = hash & 15; final int h = hash & 15;
double u = (h < 8 || h == 12 || h == 13) ? x : y; final double u = (h < 8 || h == 12 || h == 13) ? x : y;
double v = (h < 4 || h == 12 || h == 13) ? y : z; final double v = (h < 4 || h == 12 || h == 13) ? y : z;
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
} }
@ -513,7 +513,7 @@ public class PerlinNoiseGenerator {
*/ */
private void normalize2(double[] v) private void normalize2(double[] v)
{ {
double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1]); final double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1]);
v[0] *= s; v[0] *= s;
v[1] *= s; v[1] *= s;
} }
@ -524,7 +524,7 @@ public class PerlinNoiseGenerator {
*/ */
private void normalize3(double[] v) private void normalize3(double[] v)
{ {
double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); final double s = 1 / Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
v[0] *= s; v[0] *= s;
v[1] *= s; v[1] *= s;
v[2] *= s; v[2] *= s;

Loading…
Cancel
Save