From db3da1554d102f931861ef5ecc0a9213eba97737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 19 Apr 2014 03:43:18 +0200 Subject: [PATCH] WorldMap now successfully IONIZABLE! --- fuck.ion | Bin 0 -> 140 bytes hello.ion | Bin 0 -> 8204 bytes maptest.ion | Bin 0 -> 282 bytes moo.ion | Bin 0 -> 50 bytes .../render/textures/FilteredTexture.java | 1 - src/mightypork/rogue/App.java | 3 + .../rogue/screens/CrossfadeOverlay.java | 4 +- .../rogue/screens/CrossfadeRequest.java | 2 +- .../rogue/screens/ingame/GameGui.java | 24 +-- .../rogue/screens/ingame/HeartBar.java | 18 +- .../rogue/screens/ingame/NavItemSlot.java | 17 +- .../rogue/screens/ingame/ScreenGame.java | 6 +- .../rogue/screens/main_menu/MenuLayer.java | 20 ++- src/mightypork/rogue/world/Entity.java | 9 + src/mightypork/rogue/world/EntityModel.java | 7 +- src/mightypork/rogue/world/WorldMap.java | 60 ++++++- src/mightypork/rogue/world/item/ItemData.java | 2 +- src/mightypork/rogue/world/item/Items.java | 2 +- src/mightypork/rogue/world/tile/Tile.java | 16 +- src/mightypork/rogue/world/tile/TileData.java | 6 +- src/mightypork/rogue/world/tile/Tiles.java | 2 +- src/mightypork/test/FakeTile.java | 84 ++++++++++ src/mightypork/test/TestIonArray.java | 4 +- src/mightypork/test/TestIonArray2.java | 30 ++-- src/mightypork/test/TestPerlin.java | 12 +- src/mightypork/test/TestTileMap.java | 46 ++++++ .../constraints/num/mutable/NumAnimated.java | 3 +- .../util/control/timing/TimedTask.java | 18 +- src/mightypork/util/files/ion/Ion.java | 84 +++++----- .../util/files/ion/IonDataBundle.java | 2 - src/mightypork/util/math/noise/NoiseGen.java | 2 +- .../util/math/noise/PerlinNoiseGenerator.java | 154 +++++++++--------- 32 files changed, 413 insertions(+), 225 deletions(-) create mode 100644 fuck.ion create mode 100644 hello.ion create mode 100644 maptest.ion create mode 100644 moo.ion create mode 100644 src/mightypork/test/FakeTile.java create mode 100644 src/mightypork/test/TestTileMap.java diff --git a/fuck.ion b/fuck.ion new file mode 100644 index 0000000000000000000000000000000000000000..44b42b221823e172fc3a7f2bf8e2baef8d7ef705 GIT binary patch literal 140 zcmW-YK?;Ik7zM|)G~Bgn`MdH8Zp8!_qM=53p*lv;Ngd@e@Oa;RKn_H5l2{Ts%SBSj yl!8yzjZ83{aiNo#w%*DTB~Prdu$P2NhkpgkO3V;lVr+LNhSDfVm!i4EHT literal 0 HcmV?d00001 diff --git a/hello.ion b/hello.ion new file mode 100644 index 0000000000000000000000000000000000000000..40c6801324a99c4044733491dd94b65000f579b8 GIT binary patch literal 8204 zcmV+nAoJe<3jjX=03ZMWJ<+-Wv!-S%V%v6zeMf#7Np%PnS#;mnd+LfC)o&JMN*5Wy zAyD$M=wC>AQMsQL=AG3bMWw#dABkJP1U zShIl77{{YWrNVncM}O4zn-5l%x)D;rnnk`ovtxegx%hMt*a`$$JnzDu zL1_^U6+aProKYi}lgkY{XP$ns8A*A3OoDN6Q3 z`aojcKb{Di#)IC?oDJc{t}t58vdCdvNARYET9j|D%tYLXQA=_?n*i44wp-XhwaT-f zjzy9pLZ4PBKp&O@3s2|i8WUVH{`^qD%HCqRuAjhrNRq z`r(uUUVcYcp%%&tKGkfG`vY*-N}3W0@)yi;?v>TJl@{q%`Xo<7m6#axBDti6$%tw) zep&Yms--sQ3Lf&A*94hjC$~eUlZ^4<7~>h+LU>{thWV?P@Yzwd{baFj$r9_&Z6E2S zqFSGLsXddpZ#|$k>tpuS%N%5ZPE6TebEqdoQ$z}D%WG+3U9Q_kS3hhoHGiM&L)5qP zhQKnD+%J`DVh?X06(yHQyB@cz1LO{^>oaf$VQZ4LEvJMt4Gn(kA!pv`iSu#KOm^`Q zdzQ{vm1!_ZEl53W%ITM94Xh|@88spAE;>J=mz__Y#=Z2|y$Gn@uG9d;`r<#gPX z(O~{u4rEDaC48HC?Z3#>==h%P?RFz#2OuCSoy_76($GI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ce35a4e8a8cf3 GIT binary patch literal 282 zcmZSD$H2hA1;#c&5(HS8_5evnAZBK8WN>0|2D1J$fMh{p40vTZamq3QwX)-sWdWIv VSC$R0EN*+*@Y)NK<-lsPEdbs58a)62 literal 0 HcmV?d00001 diff --git a/moo.ion b/moo.ion new file mode 100644 index 0000000000000000000000000000000000000000..bb41aa681c7cb728b70bac3002524d88e7046975 GIT binary patch literal 50 rcmZSJV_;z524Y4aW&&bnAZ7t#Rv=~rVs;?r0AfxC# { - private String screen; + private final String screen; /** diff --git a/src/mightypork/rogue/screens/ingame/GameGui.java b/src/mightypork/rogue/screens/ingame/GameGui.java index 0ee95d3..77681b3 100644 --- a/src/mightypork/rogue/screens/ingame/GameGui.java +++ b/src/mightypork/rogue/screens/ingame/GameGui.java @@ -19,35 +19,35 @@ public class GameGui extends ScreenLayer { public GameGui(Screen screen) { super(screen); - Num h = root.height(); - Num w = root.width(); - Num minWH = w.min(h).max(700); // avoid too small shrinking + final Num h = root.height(); + final Num w = root.width(); + 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); 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))); 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))); root.add(itemSlots); itemSlots.add(new NavItemSlot(Res.getTxQuad("meat"))); itemSlots.add(new NavItemSlot(Res.getTxQuad("sword"))); - Rect shrunk = root.shrink(minWH.perc(3)); - Num displays_height = minWH.perc(6); + final Rect shrunk = root.shrink(minWH.perc(3)); + final Num displays_height = minWH.perc(6); - 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 HeartBar hearts = new HeartBar(6, 3, Res.getTxQuad("heart_on"), Res.getTxQuad("heart_off"), AlignX.LEFT); + final Rect hearts_box = shrunk.topLeft().startRect().growDown(displays_height); hearts.setRect(hearts_box); root.add(hearts); - 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 HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT); + final Rect xp_box = shrunk.topRight().startRect().growDown(displays_height); experience.setRect(xp_box); root.add(experience); } diff --git a/src/mightypork/rogue/screens/ingame/HeartBar.java b/src/mightypork/rogue/screens/ingame/HeartBar.java index bd94b96..f37da5d 100644 --- a/src/mightypork/rogue/screens/ingame/HeartBar.java +++ b/src/mightypork/rogue/screens/ingame/HeartBar.java @@ -12,10 +12,10 @@ import mightypork.util.constraints.rect.Rect; public class HeartBar extends VisualComponent { - private TxQuad img_on; - private TxQuad img_off; - private int total; - private int active; + private final TxQuad img_on; + private final TxQuad img_off; + private final int total; + private final int active; NumVar index = new NumVar(0); Rect heart; @@ -26,7 +26,7 @@ public class HeartBar extends VisualComponent { * @param active * @param img_on * @param img_off - * @param align + * @param align */ public HeartBar(int total, int active, TxQuad img_on, TxQuad img_off, AlignX align) { super(); @@ -35,18 +35,18 @@ public class HeartBar extends VisualComponent { this.img_on = img_on; this.img_off = img_off; - Num h = height(); - Num w = width(); + final Num h = height(); + final Num w = width(); switch (align) { case LEFT: heart = leftEdge().growRight(h).moveX(index.mul(h)); break; 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; 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; } diff --git a/src/mightypork/rogue/screens/ingame/NavItemSlot.java b/src/mightypork/rogue/screens/ingame/NavItemSlot.java index bbddf25..bf34d48 100644 --- a/src/mightypork/rogue/screens/ingame/NavItemSlot.java +++ b/src/mightypork/rogue/screens/ingame/NavItemSlot.java @@ -1,8 +1,8 @@ package mightypork.rogue.screens.ingame; +import mightypork.gamecore.control.events.MouseMotionEvent; import mightypork.gamecore.gui.components.ClickableComponent; -import mightypork.gamecore.gui.components.InputComponent; import mightypork.gamecore.render.Render; import mightypork.gamecore.render.textures.TxQuad; import mightypork.rogue.Res; @@ -13,15 +13,14 @@ import mightypork.util.constraints.rect.caching.RectCache; import mightypork.util.constraints.vect.Vect; import mightypork.util.control.timing.Updateable; import mightypork.util.math.Easing; -import mightypork.gamecore.control.events.MouseMotionEvent; public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.Listener, Updateable { - private TxQuad image; - private TxQuad frame; - private RectCache paintBox; - private NumAnimated yOffset; + private final TxQuad image; + private final TxQuad frame; + private final RectCache paintBox; + private final NumAnimated yOffset; private boolean wasInside = false; @@ -29,11 +28,11 @@ public class NavItemSlot extends ClickableComponent implements MouseMotionEvent. this.image = image; 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.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(); } @@ -61,7 +60,7 @@ public class NavItemSlot extends ClickableComponent implements MouseMotionEvent. @Override public void receive(MouseMotionEvent event) - { + { if (event.getPos().isInside(this) != wasInside) { if (wasInside) { // left diff --git a/src/mightypork/rogue/screens/ingame/ScreenGame.java b/src/mightypork/rogue/screens/ingame/ScreenGame.java index 3acb8f1..d995bc4 100644 --- a/src/mightypork/rogue/screens/ingame/ScreenGame.java +++ b/src/mightypork/rogue/screens/ingame/ScreenGame.java @@ -1,17 +1,19 @@ package mightypork.rogue.screens.ingame; + import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.screens.LayeredScreen; public class ScreenGame extends LayeredScreen { - + public ScreenGame(AppAccess app) { super(app); addLayer(new GameGui(this)); } - + + @Override public String getName() { diff --git a/src/mightypork/rogue/screens/main_menu/MenuLayer.java b/src/mightypork/rogue/screens/main_menu/MenuLayer.java index f813825..c69d4c0 100644 --- a/src/mightypork/rogue/screens/main_menu/MenuLayer.java +++ b/src/mightypork/rogue/screens/main_menu/MenuLayer.java @@ -1,7 +1,6 @@ package mightypork.rogue.screens.main_menu; -import mightypork.gamecore.control.events.ScreenRequestEvent; import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.layout.GridLayout; 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.ScreenLayer; import mightypork.rogue.Res; -import mightypork.rogue.events.ActionRequest; -import mightypork.rogue.events.ActionRequest.RequestType; import mightypork.rogue.screens.CrossfadeRequest; import mightypork.util.constraints.num.Num; import mightypork.util.constraints.rect.Rect; @@ -49,13 +46,18 @@ class MenuLayer extends ScreenLayer { b3 = new MenuButton("Flying Cat", PAL16.PIGMEAT); b4 = new MenuButton("Bye!", PAL16.BLOODRED); - int r=0; + int r = 0; - layout.put(tp, r, 0, 4, 1); r += 5; - layout.put(b0, 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(tp, r, 0, 4, 1); + r += 5; + layout.put(b0, 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); root.add(layout); diff --git a/src/mightypork/rogue/world/Entity.java b/src/mightypork/rogue/world/Entity.java index 6e6ac55..3d8bdf5 100644 --- a/src/mightypork/rogue/world/Entity.java +++ b/src/mightypork/rogue/world/Entity.java @@ -57,6 +57,15 @@ public abstract class Entity, R extends RectBound } + /** + * @return data + */ + public final D getData() + { + return data; + } + + /** * @return entity model */ diff --git a/src/mightypork/rogue/world/EntityModel.java b/src/mightypork/rogue/world/EntityModel.java index b7ac5f9..a4597c8 100644 --- a/src/mightypork/rogue/world/EntityModel.java +++ b/src/mightypork/rogue/world/EntityModel.java @@ -1,6 +1,7 @@ package mightypork.rogue.world; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -57,8 +58,9 @@ public abstract class EntityModel { * * @param data data to load * @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 { * * @param data data to save * @param out output stream + * @throws IOException */ @DefaultImpl - public abstract void save(D data, OutputStream out); + public abstract void save(D data, OutputStream out) throws IOException; /** diff --git a/src/mightypork/rogue/world/WorldMap.java b/src/mightypork/rogue/world/WorldMap.java index 93b4fc3..48289c8 100644 --- a/src/mightypork/rogue/world/WorldMap.java +++ b/src/mightypork/rogue/world/WorldMap.java @@ -13,12 +13,19 @@ import mightypork.util.files.ion.Ionizable; public class WorldMap implements TileHolder, Ionizable { + public static final int ION_MARK = 702; + private int width, height; /** Array of tiles [y][x] */ private Tile[][] tiles; + public WorldMap() { + // constructor for ION + } + + public WorldMap(int width, int height) { this.width = width; this.height = height; @@ -33,27 +40,33 @@ public class WorldMap implements TileHolder, Ionizable { @Override - public Tile getTile(int x, int y) + public final Tile getTile(int x, int y) { 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; } @Override - public int getWidth() + public final int getWidth() { return width; } @Override - public int getHeight() + public final int getHeight() { return height; } @@ -67,23 +80,52 @@ public class WorldMap implements TileHolder, Ionizable { buildArray(); - short mark; - - mark = Ion.readMark(in); - if(mark == Ion.START); + 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); + + final Tile tile = (Tile) Ion.readObject(in); + + setTile(tile, x, y); + + } else { + throw new IOException("Invalid mark encountered while reading tile map."); + } + } } @Override 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 public short getIonMark() { - return 0; + return ION_MARK; } } diff --git a/src/mightypork/rogue/world/item/ItemData.java b/src/mightypork/rogue/world/item/ItemData.java index 1e6e835..dc65a38 100644 --- a/src/mightypork/rogue/world/item/ItemData.java +++ b/src/mightypork/rogue/world/item/ItemData.java @@ -2,7 +2,7 @@ package mightypork.rogue.world.item; /** - * Item data object. Can be extended for particular models' needs. + * Item data object. * * @author MightyPork */ diff --git a/src/mightypork/rogue/world/item/Items.java b/src/mightypork/rogue/world/item/Items.java index 8e7fb89..23960ba 100644 --- a/src/mightypork/rogue/world/item/Items.java +++ b/src/mightypork/rogue/world/item/Items.java @@ -10,7 +10,7 @@ public final class Items { private static final Map 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."); registered.put(id, model); diff --git a/src/mightypork/rogue/world/tile/Tile.java b/src/mightypork/rogue/world/tile/Tile.java index 50526cb..477e45f 100644 --- a/src/mightypork/rogue/world/tile/Tile.java +++ b/src/mightypork/rogue/world/tile/Tile.java @@ -1,8 +1,6 @@ package mightypork.rogue.world.tile; -import java.util.Stack; - import mightypork.rogue.world.Entity; import mightypork.rogue.world.item.Item; @@ -16,12 +14,6 @@ public final class Tile extends Entity { public static final short ION_MARK = 700; - /** Items dropped onto this tile */ - public final Stack items = new Stack<>(); - - /** Whether the tile is occupied by an entity */ - public boolean occupied; - public Tile() { super(); @@ -58,8 +50,8 @@ public final class Tile extends Entity { super.render(context); // render laying-on-top item - if (!items.isEmpty()) { - Item item = items.peek(); + if (!data.items.isEmpty()) { + final Item item = data.items.peek(); item.render(context.getRect()); } @@ -72,8 +64,8 @@ public final class Tile extends Entity { super.update(delta); // update laying-on-top item - if (!items.isEmpty()) { - Item item = items.peek(); + if (!data.items.isEmpty()) { + final Item item = data.items.peek(); item.update(delta); } } diff --git a/src/mightypork/rogue/world/tile/TileData.java b/src/mightypork/rogue/world/tile/TileData.java index e883a97..0f57d03 100644 --- a/src/mightypork/rogue/world/tile/TileData.java +++ b/src/mightypork/rogue/world/tile/TileData.java @@ -5,8 +5,9 @@ import java.util.Stack; import mightypork.rogue.world.item.Item; + /** - * Tile data object. Can be extended for particular models' needs. + * Tile data object. * * @author MightyPork */ @@ -15,4 +16,7 @@ public abstract class TileData { /** Items dropped onto this tile */ public final Stack items = new Stack<>(); + /** Whether the tile is occupied by an entity */ + public boolean occupied; + } diff --git a/src/mightypork/rogue/world/tile/Tiles.java b/src/mightypork/rogue/world/tile/Tiles.java index 4a3b30a..2888e4a 100644 --- a/src/mightypork/rogue/world/tile/Tiles.java +++ b/src/mightypork/rogue/world/tile/Tiles.java @@ -10,7 +10,7 @@ public final class Tiles { private static final Map 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."); registered.put(id, model); diff --git a/src/mightypork/test/FakeTile.java b/src/mightypork/test/FakeTile.java new file mode 100644 index 0000000..8f94d8d --- /dev/null +++ b/src/mightypork/test/FakeTile.java @@ -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) + { + // + } + +} diff --git a/src/mightypork/test/TestIonArray.java b/src/mightypork/test/TestIonArray.java index 21988c4..629dd92 100644 --- a/src/mightypork/test/TestIonArray.java +++ b/src/mightypork/test/TestIonArray.java @@ -12,9 +12,9 @@ public class TestIonArray { 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++) { array[i] = (byte) rand.nextInt(); diff --git a/src/mightypork/test/TestIonArray2.java b/src/mightypork/test/TestIonArray2.java index 0e5bbd4..65ff2e2 100644 --- a/src/mightypork/test/TestIonArray2.java +++ b/src/mightypork/test/TestIonArray2.java @@ -1,7 +1,12 @@ 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; @@ -9,31 +14,30 @@ public class TestIonArray2 { 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.writeString(out, "HELLO DUDE WHATSUP"); Ion.writeCharArray(out, "HERE'S ONE COOL ARRAY!!!".toCharArray()); - + // --- - 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); - - String s = Ion.readString(in); + + final String s = Ion.readString(in); System.out.println(s); - - char[] v = Ion.readCharArray(in); + final char[] v = Ion.readCharArray(in); - for (int i : v) - System.out.print((char)i); + for (final int i : v) + System.out.print((char) i); } } diff --git a/src/mightypork/test/TestPerlin.java b/src/mightypork/test/TestPerlin.java index 38274e6..732932d 100644 --- a/src/mightypork/test/TestPerlin.java +++ b/src/mightypork/test/TestPerlin.java @@ -6,22 +6,22 @@ import java.util.Locale; import mightypork.util.math.noise.NoiseGen; -public class TestPerlin { +public class TestPerlin { public static void main(String[] args) { 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 x = 0; x < w; x++) { + for (int x = 0; x < w; x++) { // "pixels" two-thick System.out.print(colors[(int) Math.floor(map[y][x])]); System.out.print(colors[(int) Math.floor(map[y][x])]); diff --git a/src/mightypork/test/TestTileMap.java b/src/mightypork/test/TestTileMap.java new file mode 100644 index 0000000..3caf54a --- /dev/null +++ b/src/mightypork/test/TestTileMap.java @@ -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(); + } + } +} diff --git a/src/mightypork/util/constraints/num/mutable/NumAnimated.java b/src/mightypork/util/constraints/num/mutable/NumAnimated.java index 2ac3a56..47e3e03 100644 --- a/src/mightypork/util/constraints/num/mutable/NumAnimated.java +++ b/src/mightypork/util/constraints/num/mutable/NumAnimated.java @@ -60,7 +60,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable { this(value); setEasing(easing); } - + /** * Create animator with easing @@ -74,6 +74,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable { setEasing(easingIn, easingOut); } + /** * Create as copy of another * diff --git a/src/mightypork/util/control/timing/TimedTask.java b/src/mightypork/util/control/timing/TimedTask.java index 5229699..c05b044 100644 --- a/src/mightypork/util/control/timing/TimedTask.java +++ b/src/mightypork/util/control/timing/TimedTask.java @@ -1,32 +1,38 @@ package mightypork.util.control.timing; + import mightypork.util.constraints.num.mutable.NumAnimated; public abstract class TimedTask implements Runnable, Updateable { - - private NumAnimated timer = new NumAnimated(0); + + private final NumAnimated timer = new NumAnimated(0); private boolean running = false; + @Override public void update(double delta) { - if(running) { + if (running) { timer.update(delta); - if(timer.isFinished()) { + if (timer.isFinished()) { running = false; run(); } } } - public void start(double seconds) { + + public void start(double seconds) + { timer.reset(); timer.animate(1, seconds); running = true; } - public void stop() { + + public void stop() + { running = false; timer.reset(); } diff --git a/src/mightypork/util/files/ion/Ion.java b/src/mightypork/util/files/ion/Ion.java index 7939b12..4cd9a58 100644 --- a/src/mightypork/util/files/ion/Ion.java +++ b/src/mightypork/util/files/ion/Ion.java @@ -70,16 +70,10 @@ public class Ion { */ 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. */ - public static final short END = 62; + public static final short END = 61; // built in 80..99 /** 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.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) { throw new IllegalArgumentException("Marks 0..99 are reserved."); @@ -304,7 +298,7 @@ public class Ion { case BOOLEAN_ARRAY: length = readInt(in); - boolean[] bools = new boolean[length]; + final boolean[] bools = new boolean[length]; for (int i = 0; i < length; i++) { bools[i] = readBoolean(in); } @@ -312,7 +306,7 @@ public class Ion { case BYTE_ARRAY: length = readInt(in); - byte[] bytes = new byte[length]; + final byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { bytes[i] = readByte(in); } @@ -320,7 +314,7 @@ public class Ion { case CHAR_ARRAY: length = readInt(in); - char[] chars = new char[length]; + final char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = readChar(in); } @@ -328,7 +322,7 @@ public class Ion { case SHORT_ARRAY: length = readInt(in); - short[] shorts = new short[length]; + final short[] shorts = new short[length]; for (int i = 0; i < length; i++) { shorts[i] = readShort(in); } @@ -336,7 +330,7 @@ public class Ion { case INT_ARRAY: length = readInt(in); - int[] ints = new int[length]; + final int[] ints = new int[length]; for (int i = 0; i < length; i++) { ints[i] = readInt(in); } @@ -344,7 +338,7 @@ public class Ion { case LONG_ARRAY: length = readInt(in); - long[] longs = new long[length]; + final long[] longs = new long[length]; for (int i = 0; i < length; i++) { longs[i] = readLong(in); } @@ -352,7 +346,7 @@ public class Ion { case FLOAT_ARRAY: length = readInt(in); - float[] floats = new float[length]; + final float[] floats = new float[length]; for (int i = 0; i < length; i++) { floats[i] = readFloat(in); } @@ -360,7 +354,7 @@ public class Ion { case DOUBLE_ARRAY: length = readInt(in); - double[] doubles = new double[length]; + final double[] doubles = new double[length]; for (int i = 0; i < length; i++) { doubles[i] = readDouble(in); } @@ -368,7 +362,7 @@ public class Ion { case STRING_ARRAY: length = readInt(in); - String[] Strings = new String[length]; + final String[] Strings = new String[length]; for (int i = 0; i < length; i++) { Strings[i] = readString(in); } @@ -732,7 +726,7 @@ public class Ion { public static void writeBooleanArray(OutputStream out, boolean[] arr) throws IOException { writeInt(out, arr.length); - for (boolean a : arr) { + for (final boolean a : arr) { writeBoolean(out, a); } } @@ -748,7 +742,7 @@ public class Ion { public static void writeByteArray(OutputStream out, byte[] arr) throws IOException { writeInt(out, arr.length); - for (byte a : arr) { + for (final byte a : arr) { writeByte(out, a); } } @@ -764,7 +758,7 @@ public class Ion { public static void writeCharArray(OutputStream out, char[] arr) throws IOException { writeInt(out, arr.length); - for (char a : arr) { + for (final char a : arr) { writeChar(out, a); } } @@ -780,7 +774,7 @@ public class Ion { public static void writeShortArray(OutputStream out, short[] arr) throws IOException { writeInt(out, arr.length); - for (short a : arr) { + for (final short a : arr) { writeShort(out, a); } } @@ -796,7 +790,7 @@ public class Ion { public static void writeIntArray(OutputStream out, int[] arr) throws IOException { writeInt(out, arr.length); - for (int a : arr) { + for (final int a : arr) { writeInt(out, a); } } @@ -812,7 +806,7 @@ public class Ion { public static void writeLongArray(OutputStream out, long[] arr) throws IOException { writeInt(out, arr.length); - for (long a : arr) { + for (final long a : arr) { writeLong(out, a); } } @@ -828,7 +822,7 @@ public class Ion { public static void writeFloatArray(OutputStream out, float[] arr) throws IOException { writeInt(out, arr.length); - for (float a : arr) { + for (final float a : arr) { writeFloat(out, a); } } @@ -844,7 +838,7 @@ public class Ion { public static void writeDoubleArray(OutputStream out, double[] arr) throws IOException { writeInt(out, arr.length); - for (double a : arr) { + for (final double a : arr) { writeDouble(out, a); } } @@ -860,7 +854,7 @@ public class Ion { public static void writeStringArray(OutputStream out, String[] arr) throws IOException { writeInt(out, arr.length); - for (String a : arr) { + for (final String a : arr) { writeString(out, a); } } @@ -888,7 +882,7 @@ public class Ion { */ 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."); return (byte) b; } @@ -1018,8 +1012,8 @@ public class Ion { */ public static boolean[] readBooleanArray(InputStream in) throws IOException { - int length = readInt(in); - boolean[] booleans = new boolean[length]; + final int length = readInt(in); + final boolean[] booleans = new boolean[length]; for (int i = 0; i < length; i++) { booleans[i] = readBoolean(in); } @@ -1036,8 +1030,8 @@ public class Ion { */ public static byte[] readByteArray(InputStream in) throws IOException { - int length = readInt(in); - byte[] bytes = new byte[length]; + final int length = readInt(in); + final byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { bytes[i] = readByte(in); } @@ -1054,8 +1048,8 @@ public class Ion { */ public static char[] readCharArray(InputStream in) throws IOException { - int length = readInt(in); - char[] chars = new char[length]; + final int length = readInt(in); + final char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = readChar(in); } @@ -1072,8 +1066,8 @@ public class Ion { */ public static short[] readShortArray(InputStream in) throws IOException { - int length = readInt(in); - short[] shorts = new short[length]; + final int length = readInt(in); + final short[] shorts = new short[length]; for (int i = 0; i < length; i++) { shorts[i] = readShort(in); } @@ -1090,8 +1084,8 @@ public class Ion { */ public static int[] readIntArray(InputStream in) throws IOException { - int length = readInt(in); - int[] ints = new int[length]; + final int length = readInt(in); + final int[] ints = new int[length]; for (int i = 0; i < length; i++) { ints[i] = readInt(in); } @@ -1108,8 +1102,8 @@ public class Ion { */ public static long[] readLongArray(InputStream in) throws IOException { - int length = readInt(in); - long[] longs = new long[length]; + final int length = readInt(in); + final long[] longs = new long[length]; for (int i = 0; i < length; i++) { longs[i] = readLong(in); } @@ -1126,8 +1120,8 @@ public class Ion { */ public static float[] readFloatArray(InputStream in) throws IOException { - int length = readInt(in); - float[] floats = new float[length]; + final int length = readInt(in); + final float[] floats = new float[length]; for (int i = 0; i < length; i++) { floats[i] = readFloat(in); } @@ -1144,8 +1138,8 @@ public class Ion { */ public static double[] readDoubleArray(InputStream in) throws IOException { - int length = readInt(in); - double[] doubles = new double[length]; + final int length = readInt(in); + final double[] doubles = new double[length]; for (int i = 0; i < length; i++) { doubles[i] = readDouble(in); } @@ -1162,8 +1156,8 @@ public class Ion { */ public static String[] readStringArray(InputStream in) throws IOException { - int length = readInt(in); - String[] Strings = new String[length]; + final int length = readInt(in); + final String[] Strings = new String[length]; for (int i = 0; i < length; i++) { Strings[i] = readString(in); } diff --git a/src/mightypork/util/files/ion/IonDataBundle.java b/src/mightypork/util/files/ion/IonDataBundle.java index 3864cc2..53f43c9 100644 --- a/src/mightypork/util/files/ion/IonDataBundle.java +++ b/src/mightypork/util/files/ion/IonDataBundle.java @@ -1,7 +1,6 @@ package mightypork.util.files.ion; - /** * Ionizable HashMap with getters and setters for individual * supported types. @@ -116,7 +115,6 @@ public class IonDataBundle extends IonMap { { super.put(key, num); } - public Object getOfType(String key, Class type) diff --git a/src/mightypork/util/math/noise/NoiseGen.java b/src/mightypork/util/math/noise/NoiseGen.java index 66f946d..f01688c 100644 --- a/src/mightypork/util/math/noise/NoiseGen.java +++ b/src/mightypork/util/math/noise/NoiseGen.java @@ -81,7 +81,7 @@ public class NoiseGen { */ 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 x = 0; x < width; x++) { diff --git a/src/mightypork/util/math/noise/PerlinNoiseGenerator.java b/src/mightypork/util/math/noise/PerlinNoiseGenerator.java index ebfd535..da95165 100644 --- a/src/mightypork/util/math/noise/PerlinNoiseGenerator.java +++ b/src/mightypork/util/math/noise/PerlinNoiseGenerator.java @@ -48,7 +48,7 @@ public class PerlinNoiseGenerator { private final Random rand = new Random(DEFAULT_SEED); /** Permutation array for the improved noise function */ - private int[] p_imp; + private final int[] p_imp; /** P array for perline 1 noise */ private int[] p; @@ -103,39 +103,39 @@ public class PerlinNoiseGenerator { public double improvedNoise(double x, double y, double z) { // Constraint the point to a unit cube - int uc_x = (int) Math.floor(x) & 255; - int uc_y = (int) Math.floor(y) & 255; - int uc_z = (int) Math.floor(z) & 255; + final int uc_x = (int) Math.floor(x) & 255; + final int uc_y = (int) Math.floor(y) & 255; + final int uc_z = (int) Math.floor(z) & 255; // Relative location of the point in the unit cube - double xo = x - Math.floor(x); - double yo = y - Math.floor(y); - double zo = z - Math.floor(z); + final double xo = x - Math.floor(x); + final double yo = y - Math.floor(y); + final double zo = z - Math.floor(z); // Fade curves for x, y and z - double u = fade(xo); - double v = fade(yo); - double w = fade(zo); + final double u = fade(xo); + final double v = fade(yo); + final double w = fade(zo); // Generate a hash for each coordinate to find out where in the cube // it lies. - int a = p_imp[uc_x] + uc_y; - int aa = p_imp[a] + uc_z; - int ab = p_imp[a + 1] + uc_z; + final int a = p_imp[uc_x] + uc_y; + final int aa = p_imp[a] + uc_z; + final int ab = p_imp[a + 1] + uc_z; - int b = p_imp[uc_x + 1] + uc_y; - int ba = p_imp[b] + uc_z; - int bb = p_imp[b + 1] + uc_z; + final int b = p_imp[uc_x + 1] + uc_y; + final int ba = p_imp[b] + uc_z; + final int bb = p_imp[b + 1] + uc_z; // blend results from the 8 corners based on the noise function - double c1 = grad(p_imp[aa], xo, yo, zo); - double c2 = grad(p_imp[ba], xo - 1, yo, zo); - double c3 = grad(p_imp[ab], xo, yo - 1, zo); - double c4 = grad(p_imp[bb], xo - 1, yo - 1, zo); - double c5 = grad(p_imp[aa + 1], xo, yo, zo - 1); - double c6 = grad(p_imp[ba + 1], xo - 1, yo, zo - 1); - 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 c1 = grad(p_imp[aa], xo, yo, zo); + final double c2 = grad(p_imp[ba], xo - 1, yo, zo); + final double c3 = grad(p_imp[ab], xo, yo - 1, zo); + final double c4 = grad(p_imp[bb], xo - 1, yo - 1, zo); + final double c5 = grad(p_imp[aa + 1], xo, yo, zo - 1); + final double c6 = grad(p_imp[ba + 1], xo - 1, yo, zo - 1); + final double c7 = grad(p_imp[ab + 1], xo, 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))); } @@ -149,16 +149,16 @@ public class PerlinNoiseGenerator { */ public double noise1(double x) { - double t = x + N; - int bx0 = ((int) t) & BM; - int bx1 = (bx0 + 1) & BM; - double rx0 = t - (int) t; - double rx1 = rx0 - 1; + final double t = x + N; + final int bx0 = ((int) t) & BM; + final int bx1 = (bx0 + 1) & BM; + final double rx0 = t - (int) t; + final double rx1 = rx0 - 1; - double sx = sCurve(rx0); + final double sx = sCurve(rx0); - double u = rx0 * g1[p[bx0]]; - double v = rx1 * g1[p[bx1]]; + final double u = rx0 * g1[p[bx0]]; + final double v = rx1 * g1[p[bx1]]; return lerp(sx, u, v); } @@ -174,39 +174,39 @@ public class PerlinNoiseGenerator { public double noise2(double x, double y) { double t = x + N; - int bx0 = ((int) t) & BM; - int bx1 = (bx0 + 1) & BM; - double rx0 = t - (int) t; - double rx1 = rx0 - 1; + final int bx0 = ((int) t) & BM; + final int bx1 = (bx0 + 1) & BM; + final double rx0 = t - (int) t; + final double rx1 = rx0 - 1; t = y + N; - int by0 = ((int) t) & BM; - int by1 = (by0 + 1) & BM; - double ry0 = t - (int) t; - double ry1 = ry0 - 1; + final int by0 = ((int) t) & BM; + final int by1 = (by0 + 1) & BM; + final double ry0 = t - (int) t; + final double ry1 = ry0 - 1; - int i = p[bx0]; - int j = p[bx1]; + final int i = p[bx0]; + final int j = p[bx1]; - int b00 = p[i + by0]; - int b10 = p[j + by0]; - int b01 = p[i + by1]; - int b11 = p[j + by1]; + final int b00 = p[i + by0]; + final int b10 = p[j + by0]; + final int b01 = p[i + by1]; + final int b11 = p[j + by1]; - double sx = sCurve(rx0); - double sy = sCurve(ry0); + final double sx = sCurve(rx0); + final double sy = sCurve(ry0); double[] q = g2[b00]; double u = rx0 * q[0] + ry0 * q[1]; q = g2[b10]; double v = rx1 * q[0] + ry0 * q[1]; - double a = lerp(sx, u, v); + final double a = lerp(sx, u, v); q = g2[b01]; u = rx0 * q[0] + ry1 * q[1]; q = g2[b11]; 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); } @@ -223,34 +223,34 @@ public class PerlinNoiseGenerator { public double noise3(double x, double y, double z) { double t = x + N; - int bx0 = ((int) t) & BM; - int bx1 = (bx0 + 1) & BM; - double rx0 = t - (int) t; - double rx1 = rx0 - 1; + final int bx0 = ((int) t) & BM; + final int bx1 = (bx0 + 1) & BM; + final double rx0 = t - (int) t; + final double rx1 = rx0 - 1; t = y + N; - int by0 = ((int) t) & BM; - int by1 = (by0 + 1) & BM; - double ry0 = t - (int) t; - double ry1 = ry0 - 1; + final int by0 = ((int) t) & BM; + final int by1 = (by0 + 1) & BM; + final double ry0 = t - (int) t; + final double ry1 = ry0 - 1; t = z + N; - int bz0 = ((int) t) & BM; - int bz1 = (bz0 + 1) & BM; - double rz0 = t - (int) t; - double rz1 = rz0 - 1; + final int bz0 = ((int) t) & BM; + final int bz1 = (bz0 + 1) & BM; + final double rz0 = t - (int) t; + final double rz1 = rz0 - 1; - int i = p[bx0]; - int j = p[bx1]; + final int i = p[bx0]; + final int j = p[bx1]; - int b00 = p[i + by0]; - int b10 = p[j + by0]; - int b01 = p[i + by1]; - int b11 = p[j + by1]; + final int b00 = p[i + by0]; + final int b10 = p[j + by0]; + final int b01 = p[i + by1]; + final int b11 = p[j + by1]; t = sCurve(rx0); - double sy = sCurve(ry0); - double sz = sCurve(rz0); + final double sy = sCurve(ry0); + final double sz = sCurve(rz0); double[] q = g3[b00 + bz0]; 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]); double b = lerp(t, u, v); - double c = lerp(sy, a, b); + final double c = lerp(sy, a, b); q = g3[b00 + bz1]; 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]); b = lerp(t, u, v); - double d = lerp(sy, a, b); + final double d = lerp(sy, a, b); return lerp(sz, c, d); } @@ -491,9 +491,9 @@ public class PerlinNoiseGenerator { private double grad(int hash, double x, double y, double z) { // Convert low 4 bits of hash code into 12 gradient directions. - int h = hash & 15; - double u = (h < 8 || h == 12 || h == 13) ? x : y; - double v = (h < 4 || h == 12 || h == 13) ? y : z; + final int h = hash & 15; + final double u = (h < 8 || h == 12 || h == 13) ? x : y; + final double v = (h < 4 || h == 12 || h == 13) ? y : z; return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); } @@ -513,7 +513,7 @@ public class PerlinNoiseGenerator { */ 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[1] *= s; } @@ -524,7 +524,7 @@ public class PerlinNoiseGenerator { */ 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[1] *= s; v[2] *= s;