diff --git a/fuck.ion b/fuck.ion new file mode 100644 index 0000000..44b42b2 Binary files /dev/null and b/fuck.ion differ diff --git a/hello.ion b/hello.ion new file mode 100644 index 0000000..40c6801 Binary files /dev/null and b/hello.ion differ diff --git a/maptest.ion b/maptest.ion new file mode 100644 index 0000000..f5fd464 Binary files /dev/null and b/maptest.ion differ diff --git a/moo.ion b/moo.ion new file mode 100644 index 0000000..bb41aa6 Binary files /dev/null and b/moo.ion differ diff --git a/src/mightypork/gamecore/render/textures/FilteredTexture.java b/src/mightypork/gamecore/render/textures/FilteredTexture.java index f9cad9d..a686255 100644 --- a/src/mightypork/gamecore/render/textures/FilteredTexture.java +++ b/src/mightypork/gamecore/render/textures/FilteredTexture.java @@ -11,7 +11,6 @@ import org.newdawn.slick.opengl.Texture; */ public interface FilteredTexture extends Texture { - /** * Set filter for scaling * diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index c1f4df8..0428f9c 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -22,6 +22,7 @@ import mightypork.rogue.screens.main_menu.ScreenMainMenu; import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy; import mightypork.rogue.screens.test_cat_sound.ScreenTestCat; import mightypork.rogue.screens.test_render.ScreenTestRender; +import mightypork.rogue.world.WorldMap; import mightypork.rogue.world.item.Item; import mightypork.rogue.world.tile.Tile; 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(Item.ION_MARK, Item.class); + Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class); } + @Override protected File getLockFile() { diff --git a/src/mightypork/rogue/screens/CrossfadeOverlay.java b/src/mightypork/rogue/screens/CrossfadeOverlay.java index 09137d8..caf3457 100644 --- a/src/mightypork/rogue/screens/CrossfadeOverlay.java +++ b/src/mightypork/rogue/screens/CrossfadeOverlay.java @@ -26,7 +26,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen @Override public void run() { - if(requestedScreenName == null) shutdown(); + if (requestedScreenName == null) shutdown(); getEventBus().send(new ScreenRequestEvent(requestedScreenName)); } }; @@ -45,7 +45,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen public CrossfadeOverlay(AppAccess app) { super(app); - QuadPainter qp = new QuadPainter(color); + final QuadPainter qp = new QuadPainter(color); qp.setRect(root); root.add(qp); diff --git a/src/mightypork/rogue/screens/CrossfadeRequest.java b/src/mightypork/rogue/screens/CrossfadeRequest.java index 9e13f36..c4742d1 100644 --- a/src/mightypork/rogue/screens/CrossfadeRequest.java +++ b/src/mightypork/rogue/screens/CrossfadeRequest.java @@ -9,7 +9,7 @@ import mightypork.util.control.eventbus.events.Event; */ public class CrossfadeRequest implements Event { - 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;