optimized map ionization to avoid extra marks

v5stable
Ondřej Hruška 11 years ago
parent 8872fd3f5f
commit f8f49b81ff
  1. 1
      src/mightypork/gamecore/gui/components/LayoutComponent.java
  2. 10
      src/mightypork/rogue/App.java
  3. 8
      src/mightypork/rogue/screens/ingame/GameGui.java
  4. 14
      src/mightypork/rogue/screens/ingame/WorldLayer.java
  5. 5
      src/mightypork/rogue/screens/ingame/WorldRenderer.java
  6. 15
      src/mightypork/rogue/world/MapGenerator.java
  7. 12
      src/mightypork/rogue/world/PlayerInfo.java
  8. 55
      src/mightypork/rogue/world/World.java
  9. 44
      src/mightypork/rogue/world/map/Level.java
  10. 5
      src/mightypork/rogue/world/structs/LevelList.java
  11. 38
      src/mightypork/rogue/world/tile/Tile.java
  12. 4
      src/mightypork/rogue/world/tile/models/SimpleTile.java
  13. 3
      src/mightypork/util/constraints/rect/Rect.java
  14. 1
      src/mightypork/util/error/CorruptedDataException.java
  15. 20
      src/mightypork/util/files/ion/Ion.java
  16. 1
      src/mightypork/util/files/ion/IonBundle.java
  17. 2
      src/mightypork/util/logging/Log.java

@ -13,7 +13,6 @@ import mightypork.util.constraints.rect.proxy.RectBound;
import mightypork.util.control.Enableable; import mightypork.util.control.Enableable;
import mightypork.util.control.eventbus.EventBus; import mightypork.util.control.eventbus.EventBus;
import mightypork.util.control.eventbus.clients.ClientHub; import mightypork.util.control.eventbus.clients.ClientHub;
import mightypork.util.logging.Log;
public abstract class LayoutComponent extends VisualComponent implements Enableable, ClientHub, AppAccess { public abstract class LayoutComponent extends VisualComponent implements Enableable, ClientHub, AppAccess {

@ -22,11 +22,12 @@ 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.LocalPlayer; import mightypork.rogue.world.PlayerInfo;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldPos; import mightypork.rogue.world.WorldPos;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.map.LevelMap; import mightypork.rogue.world.map.Level;
import mightypork.rogue.world.structs.LevelList;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.util.control.eventbus.EventBus; import mightypork.util.control.eventbus.EventBus;
import mightypork.util.control.eventbus.events.Event; import mightypork.util.control.eventbus.events.Event;
@ -110,8 +111,9 @@ public final class App extends BaseApp {
protected void preInit() protected void preInit()
{ {
Ion.registerIonizable(Item.ION_MARK, Item.class); Ion.registerIonizable(Item.ION_MARK, Item.class);
Ion.registerIonizable(LevelMap.ION_MARK, LevelMap.class); Ion.registerIonizable(Level.ION_MARK, Level.class);
Ion.registerIonizable(LocalPlayer.ION_MARK, LocalPlayer.class); Ion.registerIonizable(LevelList.ION_MARK, LevelList.class);
Ion.registerIonizable(PlayerInfo.ION_MARK, PlayerInfo.class);
Ion.registerIonizable(Tile.ION_MARK, Tile.class); Ion.registerIonizable(Tile.ION_MARK, Tile.class);
Ion.registerIonizable(World.ION_MARK, World.class); Ion.registerIonizable(World.ION_MARK, World.class);
Ion.registerIonizable(WorldPos.ION_MARK, WorldPos.class); Ion.registerIonizable(WorldPos.ION_MARK, WorldPos.class);

@ -2,23 +2,17 @@ package mightypork.rogue.screens.ingame;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.Component;
import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout; import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.render.Render;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.util.constraints.num.Num; import mightypork.util.constraints.num.Num;
import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.Rect;
import mightypork.util.math.color.PAL16;
import mightypork.util.math.color.RGB;
public class GameGui extends ScreenLayer { public class GameGui extends ScreenLayer {
public GameGui(Screen screen) public GameGui(Screen screen)
{ {
super(screen); super(screen);
@ -59,11 +53,11 @@ public class GameGui extends ScreenLayer {
return 100; return 100;
} }
@Override @Override
public void render() public void render()
{ {
super.render(); super.render();
} }

@ -1,12 +1,14 @@
package mightypork.rogue.screens.ingame; package mightypork.rogue.screens.ingame;
import java.io.IOException;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.rogue.world.MapGenerator; import mightypork.rogue.world.MapGenerator;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.util.files.ion.Ion;
public class WorldLayer extends ScreenLayer { public class WorldLayer extends ScreenLayer {
@ -15,14 +17,20 @@ public class WorldLayer extends ScreenLayer {
{ {
super(screen); super(screen);
Random rand = new Random(); final Random rand = new Random();
World w = MapGenerator.createWorld(rand.nextLong()); final World w = MapGenerator.createWorld(rand.nextLong());
try {
Ion.toFile("amap.ion", w);
} catch (final IOException e) {
e.printStackTrace();
}
WorldRenderer wr = new WorldRenderer(w); final WorldRenderer wr = new WorldRenderer(w);
wr.setRect(root); wr.setRect(root);
root.add(wr); root.add(wr);
} }
@Override @Override
public int getPriority() public int getPriority()
{ {

@ -8,7 +8,6 @@ import mightypork.rogue.world.World;
import mightypork.util.constraints.num.Num; import mightypork.util.constraints.num.Num;
import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.Rect;
import mightypork.util.control.timing.Updateable; import mightypork.util.control.timing.Updateable;
import mightypork.util.math.color.PAL16;
import mightypork.util.math.color.RGB; import mightypork.util.math.color.RGB;
@ -29,8 +28,8 @@ public class WorldRenderer extends InputComponent implements Updateable {
final Num w = width(); final Num w = width();
final Num minWH = w.min(h).max(700); final Num minWH = w.min(h).max(700);
Num grX = w.perc(30); final Num grX = w.perc(30);
Num grY = h.perc(20); final Num grY = h.perc(20);
leftShadow = leftEdge().growRight(grX); leftShadow = leftEdge().growRight(grX);
rightShadow = rightEdge().growLeft(grX); rightShadow = rightEdge().growLeft(grX);

@ -3,7 +3,7 @@ package mightypork.rogue.world;
import java.util.Random; import java.util.Random;
import mightypork.rogue.world.map.LevelMap; import mightypork.rogue.world.map.Level;
import mightypork.rogue.world.tile.Tiles; import mightypork.rogue.world.tile.Tiles;
@ -17,31 +17,32 @@ public class MapGenerator {
synchronized (rand) { synchronized (rand) {
rand.setSeed(seed); rand.setSeed(seed);
World w = new World(); final World w = new World();
w.setSeed(seed); w.setSeed(seed);
int levels = 4 + rand.nextInt(6); final int levels = 4 + rand.nextInt(6);
for (int i = 0; i < levels; i++) { for (int i = 0; i < levels; i++) {
w.addLevel(createLevel(rand.nextLong())); w.addLevel(createLevel(rand.nextLong()));
} }
// TODO place on start position // TODO place on start position
w.setPlayer(new LocalPlayer(10, 10, 0)); w.setPlayer(new PlayerInfo(10, 10, 0));
return w; return w;
} }
} }
private static LevelMap createLevel(long seed) private static Level createLevel(long seed)
{ {
// TODO // TODO
LevelMap lm = new LevelMap(20, 20); final Level lm = new Level(20, 20);
lm.setSeed(seed);
lm.fill(Tiles.CRYSTAL_FLOOR); lm.fill(Tiles.CRYSTAL_FLOOR);
Random rand = new Random(); final Random rand = new Random();
rand.setSeed(seed); rand.setSeed(seed);
for (int i = 0; i < 150; i++) { for (int i = 0; i < 150; i++) {

@ -16,7 +16,7 @@ import mightypork.util.files.ion.Ionizable;
* *
* @author MightyPork * @author MightyPork
*/ */
public class LocalPlayer implements Ionizable, MapObserver { public class PlayerInfo implements Ionizable, MapObserver {
public static final short ION_MARK = 708; public static final short ION_MARK = 708;
@ -24,18 +24,18 @@ public class LocalPlayer implements Ionizable, MapObserver {
@IonConstructor @IonConstructor
public LocalPlayer() public PlayerInfo()
{ {
} }
public LocalPlayer(int x, int y, int floor) public PlayerInfo(int x, int y, int floor)
{ {
this.position.setTo(x, y, floor); this.position.setTo(x, y, floor);
} }
public LocalPlayer(WorldPos pos) public PlayerInfo(WorldPos pos)
{ {
this.position = pos; this.position = pos;
} }
@ -44,7 +44,7 @@ public class LocalPlayer implements Ionizable, MapObserver {
@Override @Override
public void load(InputStream in) throws IOException public void load(InputStream in) throws IOException
{ {
IonBundle ib = (IonBundle) Ion.readObject(in); final IonBundle ib = (IonBundle) Ion.readObject(in);
position = ib.get("pos", position); position = ib.get("pos", position);
} }
@ -53,7 +53,7 @@ public class LocalPlayer implements Ionizable, MapObserver {
@Override @Override
public void save(OutputStream out) throws IOException public void save(OutputStream out) throws IOException
{ {
IonBundle ib = new IonBundle(); final IonBundle ib = new IonBundle();
ib.put("pos", position); ib.put("pos", position);

@ -7,21 +7,18 @@ import java.io.OutputStream;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import mightypork.gamecore.render.Render; import mightypork.rogue.world.map.Level;
import mightypork.rogue.world.map.LevelMap;
import mightypork.rogue.world.map.TileRenderContext; import mightypork.rogue.world.map.TileRenderContext;
import mightypork.rogue.world.structs.LevelList; import mightypork.rogue.world.structs.LevelList;
import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.Rect;
import mightypork.util.constraints.rect.RectConst; import mightypork.util.constraints.rect.RectConst;
import mightypork.util.constraints.rect.proxy.RectBound; import mightypork.util.constraints.rect.proxy.RectBound;
import mightypork.util.constraints.vect.Vect;
import mightypork.util.constraints.vect.VectConst; import mightypork.util.constraints.vect.VectConst;
import mightypork.util.control.timing.Updateable; import mightypork.util.control.timing.Updateable;
import mightypork.util.error.CorruptedDataException; import mightypork.util.error.CorruptedDataException;
import mightypork.util.files.ion.Ion; import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.IonBundle; import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.Ionizable; import mightypork.util.files.ion.Ionizable;
import mightypork.util.math.color.RGB;
public class World implements Ionizable, Updateable { public class World implements Ionizable, Updateable {
@ -30,10 +27,11 @@ public class World implements Ionizable, Updateable {
private LevelList levels = new LevelList(); private LevelList levels = new LevelList();
private LocalPlayer player = new LocalPlayer(); private PlayerInfo player = new PlayerInfo();
private transient final Set<MapObserver> observers = new HashSet<>(); private transient final Set<MapObserver> observers = new HashSet<>();
/** This seed can be used to re-create identical world. */
private long seed; private long seed;
@ -41,10 +39,10 @@ public class World implements Ionizable, Updateable {
public void load(InputStream in) throws IOException public void load(InputStream in) throws IOException
{ {
// world data // world data
IonBundle ib = (IonBundle) Ion.readObject(in); final IonBundle ib = (IonBundle) Ion.readObject(in);
player = ib.get("player", player); player = ib.get("player", player);
levels = ib.get("levels", levels);
seed = ib.get("seed", seed); seed = ib.get("seed", seed);
levels = ib.get("levels", levels);
// levels // levels
Ion.readSequence(in, levels); Ion.readSequence(in, levels);
@ -56,14 +54,15 @@ public class World implements Ionizable, Updateable {
@Override @Override
public void save(OutputStream out) throws IOException public void save(OutputStream out) throws IOException
{ {
IonBundle ib = new IonBundle(); final IonBundle ib = new IonBundle();
ib.put("player", player); ib.put("player", player);
ib.put("levels", levels);
ib.put("seed", seed); ib.put("seed", seed);
ib.put("levels", levels);
Ion.writeObject(out, ib);
} }
public void setPlayer(LocalPlayer player) public void setPlayer(PlayerInfo player)
{ {
removeObserver(this.player); removeObserver(this.player);
@ -85,7 +84,7 @@ public class World implements Ionizable, Updateable {
} }
public void addLevel(LevelMap level) public void addLevel(Level level)
{ {
levels.add(level); levels.add(level);
} }
@ -102,7 +101,7 @@ public class World implements Ionizable, Updateable {
public void update(double delta) public void update(double delta)
{ {
for (int level = 0; level < levels.size(); level++) { for (int level = 0; level < levels.size(); level++) {
for (MapObserver observer : observers) { for (final MapObserver observer : observers) {
if (observer.getPosition().floor == level) { if (observer.getPosition().floor == level) {
levels.get(level).update(observer, delta); levels.get(level).update(observer, delta);
} }
@ -111,7 +110,7 @@ public class World implements Ionizable, Updateable {
} }
public LevelMap getLevelForObserver(MapObserver observer) public Level getLevelForObserver(MapObserver observer)
{ {
return levels.get(observer.getPosition().floor); return levels.get(observer.getPosition().floor);
} }
@ -127,28 +126,28 @@ public class World implements Ionizable, Updateable {
*/ */
public void render(final RectBound viewport, final int yTiles, final int xTiles, final int minSize) public void render(final RectBound viewport, final int yTiles, final int xTiles, final int minSize)
{ {
LevelMap floor = getLevelForObserver(player); // TODO fractional movement final Level floor = getLevelForObserver(player); // TODO fractional movement
Rect r = viewport.getRect(); final Rect r = viewport.getRect();
double vpH = r.height().value(); final double vpH = r.height().value();
double vpW = r.width().value(); final double vpW = r.width().value();
// adjust tile size to fit desired amount of tiles // adjust tile size to fit desired amount of tiles
double allowedSizeW = vpW / xTiles; final double allowedSizeW = vpW / xTiles;
double allowedSizeH = vpH / yTiles; final double allowedSizeH = vpH / yTiles;
int tileSize = (int) Math.round(Math.max(Math.min(allowedSizeH, allowedSizeW), minSize)); int tileSize = (int) Math.round(Math.max(Math.min(allowedSizeH, allowedSizeW), minSize));
tileSize -= tileSize % 16; tileSize -= tileSize % 16;
VectConst vpCenter = r.center().sub(tileSize * 0.5, tileSize).freeze(); // 0.5 to center, 1 to move up (down is teh navbar) final VectConst vpCenter = r.center().sub(tileSize * 0.5, tileSize).freeze(); // 0.5 to center, 1 to move up (down is teh navbar)
int playerX = player.getPosition().x; final int playerX = player.getPosition().x;
int playerY = player.getPosition().y; final int playerY = player.getPosition().y;
// total map area // total map area
//@formatter:off //@formatter:off
RectConst mapRect = vpCenter.startRect().grow( final RectConst mapRect = vpCenter.startRect().grow(
playerX*tileSize, playerX*tileSize,
playerY*tileSize,// playerY*tileSize,//
(floor.getWidth() - playerX) * tileSize, (floor.getWidth() - playerX) * tileSize,
@ -157,12 +156,12 @@ public class World implements Ionizable, Updateable {
//@formatter:on //@formatter:on
// tiles to render // tiles to render
int x1 = (int) Math.floor(playerX - (vpW / tileSize)); final int x1 = (int) Math.floor(playerX - (vpW / tileSize));
int y1 = (int) Math.floor(playerY - (vpH / tileSize)); final int y1 = (int) Math.floor(playerY - (vpH / tileSize));
int x2 = (int) Math.ceil(playerX + (vpW / tileSize)); final int x2 = (int) Math.ceil(playerX + (vpW / tileSize));
int y2 = (int) Math.ceil(playerY + (vpH / tileSize)); final int y2 = (int) Math.ceil(playerY + (vpH / tileSize));
TileRenderContext trc = new TileRenderContext(floor, mapRect); //-tileSize*0.5 final TileRenderContext trc = new TileRenderContext(floor, mapRect); //-tileSize*0.5
for (trc.y = y1; trc.y <= y2; trc.y++) { for (trc.y = y1; trc.y <= y2; trc.y++) {
for (trc.x = x1; trc.x <= x2; trc.x++) { for (trc.x = x1; trc.x <= x2; trc.x++) {
trc.render(); trc.render();

@ -13,7 +13,6 @@ import mightypork.rogue.world.tile.Tiles;
import mightypork.util.files.ion.Ion; import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.IonConstructor; import mightypork.util.files.ion.IonConstructor;
import mightypork.util.files.ion.Ionizable; import mightypork.util.files.ion.Ionizable;
import mightypork.util.logging.Log;
/** /**
@ -21,7 +20,7 @@ import mightypork.util.logging.Log;
* *
* @author MightyPork * @author MightyPork
*/ */
public class LevelMap implements MapAccess, Ionizable { public class Level implements MapAccess, Ionizable {
public static final int ION_MARK = 702; public static final int ION_MARK = 702;
@ -35,12 +34,12 @@ public class LevelMap implements MapAccess, Ionizable {
@IonConstructor @IonConstructor
public LevelMap() public Level()
{ {
} }
public LevelMap(int width, int height) public Level(int width, int height)
{ {
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -56,7 +55,7 @@ public class LevelMap implements MapAccess, Ionizable {
} }
public void fill(int id) public void fill(short id)
{ {
fill(Tiles.get(id)); fill(Tiles.get(id));
} }
@ -131,19 +130,17 @@ public class LevelMap implements MapAccess, Ionizable {
@Override @Override
public void load(InputStream in) throws IOException public void load(InputStream in) throws IOException
{ {
seed = Ion.readLong(in);
width = Ion.readInt(in); width = Ion.readInt(in);
height = Ion.readInt(in); height = Ion.readInt(in);
buildArray(); buildArray();
while (Ion.hasNextEntry(in)) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
final int x = Ion.readInt(in); tiles[y][x] = new Tile();
final int y = Ion.readInt(in); tiles[y][x].load(in);
}
final Tile tile = (Tile) Ion.readObject(in);
setTile(tile, x, y);
} }
} }
@ -151,24 +148,15 @@ public class LevelMap implements MapAccess, Ionizable {
@Override @Override
public void save(OutputStream out) throws IOException public void save(OutputStream out) throws IOException
{ {
Ion.writeLong(out, seed);
Ion.writeInt(out, width); Ion.writeInt(out, width);
Ion.writeInt(out, height); Ion.writeInt(out, height);
for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) {
for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) {
final Tile t = getTile(x, y); tiles[y][x].save(out);
// skip null tiles
if (!t.getModel().isNullTile()) {
Ion.writeMark(out, Ion.ENTRY);
Ion.writeInt(out, x);
Ion.writeInt(out, y);
Ion.writeObject(out, t);
}
} }
} }
// end of sequence
Ion.writeMark(out, Ion.END);
} }
@ -181,8 +169,8 @@ public class LevelMap implements MapAccess, Ionizable {
public void update(MapObserver observer, double delta) public void update(MapObserver observer, double delta)
{ {
int viewRange = observer.getViewRange(); final int viewRange = observer.getViewRange();
WorldPos position = observer.getPosition(); final WorldPos position = observer.getPosition();
int x1 = position.x - viewRange; int x1 = position.x - viewRange;
int y1 = position.y - viewRange; int y1 = position.y - viewRange;

@ -1,14 +1,15 @@
package mightypork.rogue.world.structs; package mightypork.rogue.world.structs;
import mightypork.rogue.world.map.LevelMap; import mightypork.rogue.world.map.Level;
import mightypork.util.files.ion.templates.IonizableArrayList; import mightypork.util.files.ion.templates.IonizableArrayList;
public class LevelList extends IonizableArrayList<LevelMap> { public class LevelList extends IonizableArrayList<Level> {
public static final short ION_MARK = 709; public static final short ION_MARK = 709;
@Override @Override
public short getIonMark() public short getIonMark()
{ {

@ -4,14 +4,12 @@ package mightypork.rogue.world.tile;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Stack;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.map.TileRenderContext; import mightypork.rogue.world.map.TileRenderContext;
import mightypork.rogue.world.structs.ItemStack;
import mightypork.util.control.timing.Animator; import mightypork.util.control.timing.Animator;
import mightypork.util.control.timing.Updateable; import mightypork.util.control.timing.Updateable;
import mightypork.util.files.ion.Ion; import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonConstructor; import mightypork.util.files.ion.IonConstructor;
import mightypork.util.files.ion.Ionizable; import mightypork.util.files.ion.Ionizable;
@ -26,7 +24,7 @@ public final class Tile implements Ionizable, Updateable {
public int id; public int id;
public Stack<Item> items = new Stack<>(); public ItemStack items = new ItemStack();
public boolean[] flags; public boolean[] flags;
public int[] numbers; public int[] numbers;
@ -66,30 +64,30 @@ public final class Tile implements Ionizable, Updateable {
{ {
if (model.isNullTile()) throw new RuntimeException("Cannot save null tile."); if (model.isNullTile()) throw new RuntimeException("Cannot save null tile.");
final IonBundle ib = new IonBundle(); Ion.writeShort(out, (short) id);
ib.put("id", id); byte written = 0;
ib.put("flags", flags); if (flags != null) written |= 1;
ib.put("numbers", numbers); if (numbers != null) written |= 2;
if (items != null && !items.isEmpty()) written |= 4;
Ion.writeByte(out, written);
Ion.writeSequence(out, items); if ((written & 1) != 0) Ion.writeBooleanArray(out, flags);
if ((written & 2) != 0) Ion.writeIntArray(out, numbers);
Ion.writeObject(out, ib); if ((written & 4) != 0) Ion.writeObject(out, items);
} }
@Override @Override
public void load(InputStream in) throws IOException public void load(InputStream in) throws IOException
{ {
// bundle of data id = Ion.readShort(in);
final IonBundle ib = (IonBundle) Ion.readObject(in);
id = ib.get("id", id); final byte written = Ion.readByte(in);
flags = ib.get("flags", flags);
numbers = ib.get("numbers", numbers); if ((written & 1) != 0) flags = Ion.readBooleanArray(in);
if ((written & 2) != 0) numbers = Ion.readIntArray(in);
// stored items if ((written & 4) != 0) items = (ItemStack) Ion.readObject(in);
items.clear();
Ion.readSequence(in, items);
// renew model // renew model
if (model == null || id != model.id) { if (model == null || id != model.id) {

@ -1,7 +1,6 @@
package mightypork.rogue.world.tile.models; package mightypork.rogue.world.tile.models;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.textures.TxSheet; import mightypork.gamecore.render.textures.TxSheet;
import mightypork.rogue.Res; import mightypork.rogue.Res;
@ -9,8 +8,6 @@ import mightypork.rogue.world.map.TileRenderContext;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.util.annotations.DefaultImpl; import mightypork.util.annotations.DefaultImpl;
import mightypork.util.constraints.vect.Vect;
import mightypork.util.math.color.RGB;
public abstract class SimpleTile extends TileModel { public abstract class SimpleTile extends TileModel {
@ -31,6 +28,7 @@ public abstract class SimpleTile extends TileModel {
Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getTileNoise())); Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getTileNoise()));
} }
@Override @Override
@DefaultImpl @DefaultImpl
public void update(Tile tile, double delta) public void update(Tile tile, double delta)

@ -727,7 +727,6 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
} }
/** /**
* Round coords down * Round coords down
* *
@ -758,7 +757,6 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
} }
/** /**
* Round coords up * Round coords up
* *
@ -789,7 +787,6 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
} }
public Num x() public Num x()
{ {
return p_x != null ? p_x : (p_x = origin().xn()); return p_x != null ? p_x : (p_x = origin().xn());

@ -1,5 +1,6 @@
package mightypork.util.error; package mightypork.util.error;
import java.io.IOException; import java.io.IOException;

@ -3,9 +3,13 @@ package mightypork.util.files.ion;
import java.io.*; import java.io.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.error.CorruptedDataException; import mightypork.util.error.CorruptedDataException;
import mightypork.util.logging.Log; import mightypork.util.logging.Log;
@ -403,11 +407,17 @@ public class Ion {
*/ */
public static void writeObject(OutputStream out, Object obj) throws IOException public static void writeObject(OutputStream out, Object obj) throws IOException
{ {
if (obj instanceof Tile) throw new IllegalAccessError();
if (obj == null) {
writeMark(out, NULL);
return;
}
if (obj instanceof Ionizable) { if (obj instanceof Ionizable) {
short mark = ((Ionizable) obj).getIonMark(); final short mark = ((Ionizable) obj).getIonMark();
Class<? extends Ionizable> clzRegistered = customIonizables.get(mark); final Class<? extends Ionizable> clzRegistered = customIonizables.get(mark);
if (clzRegistered == null) { if (clzRegistered == null) {
throw new IOException("Ionizable object not registered: " + Log.str(obj.getClass())); throw new IOException("Ionizable object not registered: " + Log.str(obj.getClass()));
@ -1292,6 +1302,10 @@ public class Ion {
public static <K, V> void writeMap(OutputStream out, Map<K, V> map) throws IOException public static <K, V> void writeMap(OutputStream out, Map<K, V> map) throws IOException
{ {
for (final Entry<K, V> e : map.entrySet()) { for (final Entry<K, V> e : map.entrySet()) {
if (e.getValue() == null) {
continue;
}
writeMark(out, ENTRY); writeMark(out, ENTRY);
writeObject(out, e.getKey()); writeObject(out, e.getKey());
writeObject(out, e.getValue()); writeObject(out, e.getValue());

@ -1,5 +1,6 @@
package mightypork.util.files.ion; package mightypork.util.files.ion;
import mightypork.util.files.ion.templates.IonizableHashMap; import mightypork.util.files.ion.templates.IonizableHashMap;

@ -337,6 +337,8 @@ public class Log {
public static String str(Object o) public static String str(Object o)
{ {
if (o == null) return "<null>";
boolean hasToString = false; boolean hasToString = false;
try { try {

Loading…
Cancel
Save