some changes, nothing much

v5stable
Ondřej Hruška 11 years ago
parent 0d5b6eb995
commit 2f26602d15
  1. BIN
      fuck.ion
  2. 4
      src/mightypork/gamecore/render/fonts/impl/CachedFont.java
  3. 2
      src/mightypork/rogue/App.java
  4. 12
      src/mightypork/rogue/world/World.java
  5. 49
      src/mightypork/rogue/world/item/Item.java
  6. 14
      src/mightypork/rogue/world/item/ItemModel.java
  7. 1
      src/mightypork/rogue/world/map/Level.java
  8. 2
      src/mightypork/rogue/world/map/TileRenderContext.java
  9. 19
      src/mightypork/rogue/world/structs/ItemStack.java
  10. 19
      src/mightypork/rogue/world/structs/LevelList.java
  11. 45
      src/mightypork/rogue/world/tile/DroppedItemRenderer.java
  12. 92
      src/mightypork/rogue/world/tile/Tile.java
  13. 28
      src/mightypork/rogue/world/tile/TileModel.java
  14. 17
      src/mightypork/rogue/world/tile/models/AbstractNullTile.java
  15. 5
      src/mightypork/rogue/world/tile/models/Floor.java
  16. 31
      src/mightypork/rogue/world/tile/models/SimpleTile.java
  17. 5
      src/mightypork/rogue/world/tile/models/Wall.java
  18. 2
      src/mightypork/util/constraints/rect/builders/TiledRect.java
  19. 9
      src/mightypork/util/control/timing/Animator.java
  20. 4
      src/mightypork/util/files/ion/IonBundle.java
  21. 38
      src/mightypork/util/files/ion/Ionizable.java
  22. 36
      src/mightypork/util/files/ion/Streamable.java
  23. 4
      src/mightypork/util/files/ion/templates/StreamableArrayList.java
  24. 4
      src/mightypork/util/files/ion/templates/StreamableHashMap.java
  25. 4
      src/mightypork/util/files/ion/templates/StreamableHashSet.java
  26. 4
      src/mightypork/util/files/ion/templates/StreamableLinkedHashMap.java
  27. 4
      src/mightypork/util/files/ion/templates/StreamableLinkedList.java
  28. 4
      src/mightypork/util/files/ion/templates/StreamableStack.java
  29. 4
      src/mightypork/util/files/ion/templates/StreamableTreeSet.java

Binary file not shown.

@ -396,8 +396,8 @@ public class CachedFont implements GLFont {
// draw quad
float txmin = chtx.texPosX;
float tymin = chtx.texPosY;
final float txmin = chtx.texPosX;
final float tymin = chtx.texPosY;
final float draw_width = minx + chtx.width - minx;
final float draw_height = (float) (chtx.height) - (float) 0;

@ -27,7 +27,6 @@ import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldPos;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.map.Level;
import mightypork.rogue.world.structs.LevelList;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.control.eventbus.EventBus;
import mightypork.util.control.eventbus.events.Event;
@ -112,7 +111,6 @@ public final class App extends BaseApp {
{
Ion.registerIonizable(Item.ION_MARK, Item.class);
Ion.registerIonizable(Level.ION_MARK, Level.class);
Ion.registerIonizable(LevelList.ION_MARK, LevelList.class);
Ion.registerIonizable(PlayerInfo.ION_MARK, PlayerInfo.class);
Ion.registerIonizable(Tile.ION_MARK, Tile.class);
Ion.registerIonizable(World.ION_MARK, World.class);

@ -9,23 +9,22 @@ import java.util.Set;
import mightypork.rogue.world.map.Level;
import mightypork.rogue.world.map.TileRenderContext;
import mightypork.rogue.world.structs.LevelList;
import mightypork.util.constraints.rect.Rect;
import mightypork.util.constraints.rect.RectConst;
import mightypork.util.constraints.rect.proxy.RectBound;
import mightypork.util.constraints.vect.VectConst;
import mightypork.util.control.timing.Updateable;
import mightypork.util.error.CorruptedDataException;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.templates.StreamableArrayList;
public class World implements Ionizable, Updateable {
public static final short ION_MARK = 706;
private LevelList levels = new LevelList();
private StreamableArrayList<Level> levels = new StreamableArrayList<>();
private PlayerInfo player = new PlayerInfo();
@ -42,12 +41,8 @@ public class World implements Ionizable, Updateable {
final IonBundle ib = (IonBundle) Ion.readObject(in);
player = ib.get("player", player);
seed = ib.get("seed", seed);
levels = ib.get("levels", levels);
// levels
Ion.readSequence(in, levels);
if (player == null) throw new CorruptedDataException("Null player in world.");
}
@ -57,8 +52,9 @@ public class World implements Ionizable, Updateable {
final IonBundle ib = new IonBundle();
ib.put("player", player);
ib.put("seed", seed);
ib.put("levels", levels);
Ion.writeObject(out, ib);
Ion.writeSequence(out, levels);
}

@ -5,31 +5,20 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import mightypork.rogue.world.map.TileRenderContext;
import mightypork.util.constraints.rect.proxy.RectBound;
import mightypork.util.control.timing.Animator;
import mightypork.util.control.timing.AnimatorBounce;
import mightypork.util.control.timing.Updateable;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonConstructor;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.math.Easing;
public class Item implements Updateable, Ionizable {
public class Item implements Ionizable {
public static final short ION_MARK = 701;
private transient ItemModel model;
public transient Object modelData;
public transient Animator anim;
public int id;
public boolean[] flags;
public int[] numbers;
public Item(int id)
{
@ -47,7 +36,6 @@ public class Item implements Updateable, Ionizable {
{
this.model = model;
this.id = model.id;
this.anim = new AnimatorBounce(2, Easing.SINE_BOTH);
}
@ -60,28 +48,17 @@ public class Item implements Updateable, Ionizable {
@Override
public void save(OutputStream out) throws IOException
{
final IonBundle ib = new IonBundle();
ib.put("id", id);
ib.put("flags", flags);
ib.put("numbers", numbers);
Ion.writeObject(out, ib);
Ion.writeShort(out, (short) id);
}
@Override
public void load(InputStream in) throws IOException
{
final IonBundle ib = (IonBundle) Ion.readObject(in);
id = ib.get("id", 0);
flags = ib.get("flags", null);
numbers = ib.get("numbers", null);
id = Ion.readShort(in);
if (id != model.id) {
model = Items.get(id);
}
// if id changed, get new model
if (model == null || id != model.id) model = Items.get(id);
}
@ -91,20 +68,4 @@ public class Item implements Updateable, Ionizable {
return ION_MARK;
}
@Override
public void update(double delta)
{
if (anim != null) {
anim.update(delta);
}
}
public void renderOnTile(TileRenderContext context)
{
model.renderOnTile(this, context);
}
}

@ -13,11 +13,6 @@ public abstract class ItemModel {
public final int id;
private final RectBoundAdapter tileRect = new RectBoundAdapter();
private final NumBoundAdapter yOffset = new NumBoundAdapter();
private final Rect itemRect = tileRect.shrink(tileRect.height().perc(10)).moveY(yOffset.neg());
public ItemModel(int id)
{
@ -38,13 +33,4 @@ public abstract class ItemModel {
public abstract void render(Item item, RectBound context);
public void renderOnTile(Item item, TileRenderContext context)
{
tileRect.setRect(context.getRect());
yOffset.setNum(item.anim);
render(item, itemRect);
}
}

@ -193,6 +193,7 @@ public class Level implements MapAccess, Ionizable {
}
}
@Override
public NoiseGen getNoiseGen()
{

@ -28,7 +28,7 @@ public final class TileRenderContext implements RectBound {
this.map = map;
this.tiler = drawArea.tiles(map.getWidth(), map.getHeight());
this.tiler.setOverlap(0.001);
this.tiler.setOverlap(0.001); // avoid gaps (rounding error?)
this.noise = map.getNoiseGen();
}

@ -1,19 +0,0 @@
package mightypork.rogue.world.structs;
import mightypork.rogue.world.item.Item;
import mightypork.util.files.ion.templates.IonizableStack;
public class ItemStack extends IonizableStack<Item> {
private static final short ION_MARK = 710;
@Override
public short getIonMark()
{
return ION_MARK;
}
}

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

@ -0,0 +1,45 @@
package mightypork.rogue.world.tile;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.map.TileRenderContext;
import mightypork.util.constraints.rect.Rect;
import mightypork.util.constraints.rect.proxy.RectBoundAdapter;
import mightypork.util.control.timing.Animator;
import mightypork.util.control.timing.AnimatorBounce;
import mightypork.util.control.timing.Updateable;
import mightypork.util.math.Easing;
public class DroppedItemRenderer implements Updateable {
private Animator itemAnim = new AnimatorBounce(2, Easing.SINE_BOTH);
// prepared constraints, to avoid re-building each frame
private final RectBoundAdapter tileRectAdapter = new RectBoundAdapter();
private final Rect itemRect = tileRectAdapter.shrink(tileRectAdapter.height().perc(10)).moveY(itemAnim.neg());
public Animator getItemAnim()
{
if (itemAnim == null) {
itemAnim = new AnimatorBounce(2, Easing.SINE_BOTH);
}
return itemAnim;
}
public void render(Item item, TileRenderContext context)
{
tileRectAdapter.setRect(context);
item.render(itemRect);
}
@Override
public void update(double delta)
{
itemAnim.update(delta);
}
}

@ -4,14 +4,17 @@ package mightypork.rogue.world.tile;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Stack;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.map.TileRenderContext;
import mightypork.rogue.world.structs.ItemStack;
import mightypork.util.control.timing.Animator;
import mightypork.util.control.timing.Updateable;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonConstructor;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public final class Tile implements Ionizable, Updateable {
@ -19,15 +22,19 @@ public final class Tile implements Ionizable, Updateable {
public static final short ION_MARK = 700;
private transient TileModel model;
/**
* Temporary storage for the model (unlocked door state, lever switched etc)
*/
public transient Object modelData;
public transient Animator anim;
public int id;
/** Animator field for the model to use, if needed */
public transient Animator anim;
public ItemStack items = new ItemStack();
private transient DroppedItemRenderer itemRenderer; // lazy
public boolean[] flags;
public int[] numbers;
public int id;
private final Stack<Item> items = new Stack<>();
public Tile(int id)
@ -36,16 +43,16 @@ public final class Tile implements Ionizable, Updateable {
}
@IonConstructor
public Tile()
public Tile(TileModel model)
{
this.model = model;
this.id = model.id;
}
public Tile(TileModel model)
@IonConstructor
public Tile()
{
this.model = model;
this.id = model.id;
}
@ -54,7 +61,7 @@ public final class Tile implements Ionizable, Updateable {
model.render(context);
if (!items.isEmpty()) {
items.peek().renderOnTile(context);
getItemRenderer().render(items.peek(), context);
}
}
@ -64,17 +71,15 @@ public final class Tile implements Ionizable, Updateable {
{
if (model.isNullTile()) throw new RuntimeException("Cannot save null tile.");
Ion.writeShort(out, (short) id);
byte written = 0;
if (flags != null) written |= 1;
if (numbers != null) written |= 2;
if (items != null && !items.isEmpty()) written |= 4;
Ion.writeByte(out, written);
Ion.writeShort(out, (short) id); // tile ID
Ion.writeSequence(out, items); // if empty, writes single END mark
if ((written & 1) != 0) Ion.writeBooleanArray(out, flags);
if ((written & 2) != 0) Ion.writeIntArray(out, numbers);
if ((written & 4) != 0) Ion.writeObject(out, items);
// models with metadata can save their stuff
if (model.hasMetadata()) {
IonBundle ib = new IonBundle();
model.saveMetadata(this, ib);
Ion.writeObject(out, ib);
}
}
@ -83,23 +88,18 @@ public final class Tile implements Ionizable, Updateable {
{
id = Ion.readShort(in);
final byte written = Ion.readByte(in);
if ((written & 1) != 0) flags = Ion.readBooleanArray(in);
if ((written & 2) != 0) numbers = Ion.readIntArray(in);
if ((written & 4) != 0) items = (ItemStack) Ion.readObject(in);
// renew model
// check if model is changed (can happen)
if (model == null || id != model.id) {
model = Tiles.get(id);
}
}
Ion.readSequence(in, items); // if END is found, nothing is read.
@Override
public short getIonMark()
{
return ION_MARK;
// load model's stuff
if (model.hasMetadata()) {
IonBundle ib = (IonBundle) Ion.readObject(in);
model.loadMetadata(this, ib);
}
}
@ -108,8 +108,18 @@ public final class Tile implements Ionizable, Updateable {
{
model.update(this, delta);
if (!items.isEmpty()) {
items.peek().update(delta);
getItemRenderer().update(delta);
}
}
private DroppedItemRenderer getItemRenderer()
{
if (itemRenderer == null) {
itemRenderer = new DroppedItemRenderer();
}
return itemRenderer;
}
@ -118,4 +128,16 @@ public final class Tile implements Ionizable, Updateable {
return model;
}
public boolean hasItems()
{
return !items.isEmpty();
}
@Override
public short getIonMark()
{
return ION_MARK;
}
}

@ -3,6 +3,7 @@ package mightypork.rogue.world.tile;
import mightypork.rogue.world.map.TileRenderContext;
import mightypork.util.annotations.DefaultImpl;
import mightypork.util.files.ion.IonBundle;
/**
@ -76,4 +77,31 @@ public abstract class TileModel {
*/
public abstract void update(Tile tile, double delta);
/**
* Store tile metadata (door lock state etc)
*
* @param tile stored tile
* @param ib written data bundle
*/
public abstract void saveMetadata(Tile tile, IonBundle ib);
/**
* Load from an IonBundle. The bundle is guaranteed to not be null, but
* could be empty.
*
* @param tile loaded tile
* @param ib item data bundle
*/
public abstract void loadMetadata(Tile tile, IonBundle ib);
/**
* True if this tile's data should be saved/loaded.<br>
* Must be a constant value.
*
* @return has data
*/
public abstract boolean hasMetadata();
}

@ -4,6 +4,7 @@ package mightypork.rogue.world.tile.models;
import mightypork.rogue.world.map.TileRenderContext;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel;
import mightypork.util.files.ion.IonBundle;
/**
@ -58,4 +59,20 @@ public abstract class AbstractNullTile extends TileModel {
return inst;
}
@Override
public boolean hasMetadata()
{
return false;
}
@Override
public void loadMetadata(Tile tile, IonBundle ib)
{
}
@Override
public void saveMetadata(Tile tile, IonBundle ib)
{
}
}

@ -1,6 +1,11 @@
package mightypork.rogue.world.tile.models;
/**
* Template for floor tiles with no metadata
*
* @author MightyPork
*/
public class Floor extends SimpleTile {
public Floor(int id, String sheetKey)

@ -8,8 +8,14 @@ import mightypork.rogue.world.map.TileRenderContext;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel;
import mightypork.util.annotations.DefaultImpl;
import mightypork.util.files.ion.IonBundle;
/**
* Basic implementation of a tile with coord-random texture and no animation.
*
* @author MightyPork
*/
public abstract class SimpleTile extends TileModel {
protected final TxSheet sheet;
@ -36,8 +42,10 @@ public abstract class SimpleTile extends TileModel {
}
/*
* Items can override this if their walkability changes based on something
*/
@Override
@DefaultImpl
public boolean isWalkable(Tile tile)
{
return isPotentiallyWalkable();
@ -47,4 +55,25 @@ public abstract class SimpleTile extends TileModel {
@Override
public abstract boolean isPotentiallyWalkable();
@Override
@DefaultImpl
public boolean hasMetadata()
{
return false; // it's a SIMPLE tile
}
@Override
@DefaultImpl
public void loadMetadata(Tile tile, IonBundle ib)
{
}
@Override
@DefaultImpl
public void saveMetadata(Tile tile, IonBundle ib)
{
}
}

@ -1,6 +1,11 @@
package mightypork.rogue.world.tile.models;
/**
* Template for wall tiles with no metadata
*
* @author MightyPork
*/
public class Wall extends SimpleTile {
public Wall(int id, String sheetKey)

@ -97,7 +97,7 @@ public class TiledRect extends RectProxy {
Log.w("Y coordinate(s) out of range.", new IllegalAccessException());
}
Vect orig = origin().add(perCol.mul(x), perRow.mul(y));
final Vect orig = origin().add(perCol.mul(x), perRow.mul(y));
return Rect.make(orig, perCol.mul(size_x), perRow.mul(size_y));
}

@ -4,11 +4,10 @@ package mightypork.util.control.timing;
import mightypork.util.annotations.DefaultImpl;
import mightypork.util.constraints.num.Num;
import mightypork.util.constraints.num.mutable.NumAnimated;
import mightypork.util.constraints.num.proxy.NumBound;
import mightypork.util.math.Easing;
public abstract class Animator implements Updateable, Pauseable, NumBound {
public abstract class Animator extends Num implements Updateable, Pauseable {
private final NumAnimated animator;
private final Num num;
@ -81,12 +80,6 @@ public abstract class Animator implements Updateable, Pauseable, NumBound {
@Override
public final Num getNum()
{
return num;
}
public final double value()
{
return num.value();

@ -1,7 +1,7 @@
package mightypork.util.files.ion;
import mightypork.util.files.ion.templates.IonizableHashMap;
import mightypork.util.files.ion.templates.StreamableHashMap;
/**
@ -16,7 +16,7 @@ import mightypork.util.files.ion.templates.IonizableHashMap;
*
* @author MightyPork
*/
public class IonBundle extends IonizableHashMap<String, Object> {
public class IonBundle extends StreamableHashMap<String, Object> implements Ionizable {
/**
* Get an object. If not found, fallback is returned.

@ -1,39 +1,19 @@
package mightypork.util.files.ion;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Object that can be saved to and loaded from Ion file.<br>
* All classes implementing Ionizable must be registered to {@link Ion} using
* Ion.registerIonizable(obj.class).
* <p>
* Data object that can be reconstructed by Ion based on it's mark. Such object
* MUST provide an implicit constructor.
* </p>
* <p>
* All {@link Ionizable}s must be registered to {@link Ion}, otherwise they
* can't be written/loaded using the mark.
* </p>
*
* @author MightyPork
*/
public interface Ionizable {
/**
* Load data from the input stream. Mark has already been read, begin
* reading right after it.
*
* @param in input stream
* @throws IOException
*/
void load(InputStream in) throws IOException;
/**
* Store data to output stream. Mark has already been written, begin right
* after it.
*
* @param out Output stream
* @throws IOException
*/
void save(OutputStream out) throws IOException;
public interface Ionizable extends Streamable {
/**
* Get Ion mark byte.

@ -0,0 +1,36 @@
package mightypork.util.files.ion;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
*
* Saveable to a stream.
*
*
* @author MightyPork
*/
public interface Streamable {
/**
* Load data from the input stream. Must be compatible with the
* <code>save</code> method.
*
* @param in input stream
* @throws IOException
*/
void load(InputStream in) throws IOException;
/**
* Store data to output stream.
*
* @param out Output stream
* @throws IOException
*/
void save(OutputStream out) throws IOException;
}

@ -7,10 +7,10 @@ import java.io.OutputStream;
import java.util.ArrayList;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public abstract class IonizableArrayList<E> extends ArrayList<E> implements Ionizable {
public class StreamableArrayList<E> extends ArrayList<E> implements Streamable {
@Override
public void load(InputStream in) throws IOException

@ -7,10 +7,10 @@ import java.io.OutputStream;
import java.util.HashMap;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public abstract class IonizableHashMap<K, V> extends HashMap<K, V> implements Ionizable {
public class StreamableHashMap<K, V> extends HashMap<K, V> implements Streamable {
@Override
public void load(InputStream in) throws IOException

@ -7,10 +7,10 @@ import java.io.OutputStream;
import java.util.HashSet;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public abstract class IonizableHashSet<E> extends HashSet<E> implements Ionizable {
public abstract class StreamableHashSet<E> extends HashSet<E> implements Streamable {
@Override
public void load(InputStream in) throws IOException

@ -7,10 +7,10 @@ import java.io.OutputStream;
import java.util.LinkedHashMap;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public abstract class IonizableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implements Ionizable {
public class StreamableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implements Streamable {
@Override
public void load(InputStream in) throws IOException

@ -7,10 +7,10 @@ import java.io.OutputStream;
import java.util.LinkedList;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public abstract class IonizableLinkedList<E> extends LinkedList<E> implements Ionizable {
public class StreamableLinkedList<E> extends LinkedList<E> implements Streamable {
@Override
public void load(InputStream in) throws IOException

@ -7,10 +7,10 @@ import java.io.OutputStream;
import java.util.Stack;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public abstract class IonizableStack<E> extends Stack<E> implements Ionizable {
public class StreamableStack<E> extends Stack<E> implements Streamable {
@Override
public void load(InputStream in) throws IOException

@ -7,10 +7,10 @@ import java.io.OutputStream;
import java.util.TreeSet;
import mightypork.util.files.ion.Ion;
import mightypork.util.files.ion.Ionizable;
import mightypork.util.files.ion.Streamable;
public abstract class IonizableTreeSet<E> extends TreeSet<E> implements Ionizable {
public class StreamableTreeSet<E> extends TreeSet<E> implements Streamable {
@Override
public void load(InputStream in) throws IOException
Loading…
Cancel
Save