preparing for rewrite of tile and item system
This commit is contained in:
@@ -32,7 +32,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
private FpsMeter fpsMeter;
|
private FpsMeter fpsMeter;
|
||||||
|
|
||||||
/** Current screen size */
|
/** Current screen size */
|
||||||
private final Vect screenSize = new Vect() {
|
private static final Vect screenSize = new Vect() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double y()
|
public double y()
|
||||||
@@ -48,7 +48,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Rect rect = Rect.make(screenSize);
|
private static final Rect rect = Rect.make(screenSize);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,7 +168,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
/**
|
/**
|
||||||
* @return true if close was requested (i.e. click on cross)
|
* @return true if close was requested (i.e. click on cross)
|
||||||
*/
|
*/
|
||||||
public boolean isCloseRequested()
|
public static boolean isCloseRequested()
|
||||||
{
|
{
|
||||||
return Display.isCloseRequested();
|
return Display.isCloseRequested();
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
*
|
*
|
||||||
* @return is fullscreen
|
* @return is fullscreen
|
||||||
*/
|
*/
|
||||||
public boolean isFullscreen()
|
public static boolean isFullscreen()
|
||||||
{
|
{
|
||||||
return Display.isFullscreen();
|
return Display.isFullscreen();
|
||||||
}
|
}
|
||||||
@@ -190,16 +190,27 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
*
|
*
|
||||||
* @return size
|
* @return size
|
||||||
*/
|
*/
|
||||||
public Vect getSize()
|
public static Vect getSize()
|
||||||
{
|
{
|
||||||
return screenSize;
|
return screenSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get screen rect. Static version of getRect().
|
||||||
|
*
|
||||||
|
* @return size
|
||||||
|
*/
|
||||||
|
public static Rect getBounds()
|
||||||
|
{
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return screen width
|
* @return screen width
|
||||||
*/
|
*/
|
||||||
public int getWidth()
|
public static int getWidth()
|
||||||
{
|
{
|
||||||
return screenSize.xi();
|
return screenSize.xi();
|
||||||
}
|
}
|
||||||
@@ -208,7 +219,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
/**
|
/**
|
||||||
* @return screen height
|
* @return screen height
|
||||||
*/
|
*/
|
||||||
public int getHeight()
|
public static int getHeight()
|
||||||
{
|
{
|
||||||
return screenSize.yi();
|
return screenSize.yi();
|
||||||
}
|
}
|
||||||
@@ -246,7 +257,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public Rect getRect()
|
||||||
{
|
{
|
||||||
return rect;
|
return getBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -264,7 +275,7 @@ public class DisplaySystem extends AppModule implements RectBound {
|
|||||||
*
|
*
|
||||||
* @return screen center.
|
* @return screen center.
|
||||||
*/
|
*/
|
||||||
public Vect getCenter()
|
public static Vect getCenter()
|
||||||
{
|
{
|
||||||
return rect.center();
|
return rect.center();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ import mightypork.rogue.screens.test_cat_sound.ScreenTestCat;
|
|||||||
import mightypork.rogue.screens.test_render.ScreenTestRender;
|
import mightypork.rogue.screens.test_render.ScreenTestRender;
|
||||||
import mightypork.rogue.world.WorldMap;
|
import mightypork.rogue.world.WorldMap;
|
||||||
import mightypork.rogue.world.item.Item;
|
import mightypork.rogue.world.item.Item;
|
||||||
|
import mightypork.rogue.world.item.ItemData;
|
||||||
import mightypork.rogue.world.tile.Tile;
|
import mightypork.rogue.world.tile.Tile;
|
||||||
|
import mightypork.rogue.world.tile.TileData;
|
||||||
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;
|
||||||
import mightypork.util.files.ion.Ion;
|
import mightypork.util.files.ion.Ion;
|
||||||
@@ -106,9 +108,11 @@ public final class App extends BaseApp {
|
|||||||
@Override
|
@Override
|
||||||
protected void preInit()
|
protected void preInit()
|
||||||
{
|
{
|
||||||
Ion.registerIonizable(Tile.ION_MARK, Tile.class);
|
Ion.registerIonizable(Tile.ION_MARK, Tile.class); // 700
|
||||||
Ion.registerIonizable(Item.ION_MARK, Item.class);
|
Ion.registerIonizable(Item.ION_MARK, Item.class); // 701
|
||||||
Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class);
|
Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class); // 702
|
||||||
|
Ion.registerIonizable(TileData.ION_MARK, TileData.class); // 703
|
||||||
|
Ion.registerIonizable(ItemData.ION_MARK, ItemData.class); // 704
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ public final class Res {
|
|||||||
texture = textures.loadTexture("tiles", "/res/img/map_tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
texture = textures.loadTexture("tiles", "/res/img/map_tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
||||||
QuadGrid tiles = texture.grid(32, 32);
|
QuadGrid tiles = texture.grid(32, 32);
|
||||||
|
|
||||||
|
textures.addSheet("tile.mossy_bricks.wall", tiles.makeSheet(4, 0, 7, 1));
|
||||||
|
textures.addSheet("tile.mossy_bricks.floor", tiles.makeSheet(16, 5, 7, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,6 +105,12 @@ public final class Res {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static TxSheet getTxSheet(String key)
|
||||||
|
{
|
||||||
|
return textures.getSheet(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static LoopPlayer getLoop(String key)
|
public static LoopPlayer getLoop(String key)
|
||||||
{
|
{
|
||||||
return sounds.getLoop(key);
|
return sounds.getLoop(key);
|
||||||
|
|||||||
@@ -54,27 +54,6 @@ public abstract class EntityModel<D, R extends RectBound> {
|
|||||||
public abstract D createData();
|
public abstract D createData();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load an entity from ION input stream.
|
|
||||||
*
|
|
||||||
* @param data data to load
|
|
||||||
* @param in input stream
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public abstract void load(D data, InputStream in) throws IOException;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save an entity to ION output stream.
|
|
||||||
*
|
|
||||||
* @param data data to save
|
|
||||||
* @param out output stream
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@DefaultImpl
|
|
||||||
public abstract void save(D data, OutputStream out) throws IOException;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the item according to given context.
|
* Render the item according to given context.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import mightypork.rogue.world.tile.Tile;
|
import mightypork.rogue.world.tile.Tile;
|
||||||
import mightypork.rogue.world.tile.TileHolder;
|
import mightypork.rogue.world.tile.TileGrid;
|
||||||
import mightypork.util.files.ion.Ion;
|
import mightypork.util.files.ion.Ion;
|
||||||
import mightypork.util.files.ion.Ionizable;
|
import mightypork.util.files.ion.Ionizable;
|
||||||
|
|
||||||
|
|
||||||
public class WorldMap implements TileHolder, Ionizable {
|
public class WorldMap implements TileGrid, Ionizable {
|
||||||
|
|
||||||
public static final int ION_MARK = 702;
|
public static final int ION_MARK = 702;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package mightypork.rogue.world.item;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public abstract class ItemData {
|
public final class ItemData {
|
||||||
|
|
||||||
|
public static final int ION_MARK = 704;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package mightypork.rogue.world.tile;
|
package mightypork.rogue.world.tile;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import mightypork.rogue.world.item.Item;
|
import mightypork.rogue.world.item.Item;
|
||||||
|
import mightypork.util.files.ion.IonList;
|
||||||
|
import mightypork.util.files.ion.Ionizable;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,9 +16,39 @@ import mightypork.rogue.world.item.Item;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public abstract class TileData {
|
public final class TileData implements Ionizable {
|
||||||
|
|
||||||
|
public static final short ION_MARK = 703;
|
||||||
|
|
||||||
/** Items dropped onto this tile */
|
/** Items dropped onto this tile */
|
||||||
public final Stack<Item> items = new Stack<>();
|
public final Stack<Item> items = new Stack<>();
|
||||||
|
|
||||||
|
public int id;
|
||||||
|
|
||||||
|
public boolean[] flags;
|
||||||
|
public int[] numbers;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFrom(InputStream in) throws IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(OutputStream out) throws IOException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getIonMark()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile toTile() {
|
||||||
|
Tile t = new Tile(Tiles.get(id));
|
||||||
|
t.s
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.rogue.world.tile;
|
package mightypork.rogue.world.tile;
|
||||||
|
|
||||||
|
|
||||||
public interface TileHolder {
|
public interface TileGrid {
|
||||||
|
|
||||||
Tile getTile(int x, int y);
|
Tile getTile(int x, int y);
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ public abstract class TileModel extends EntityModel<TileData, TileRenderContext>
|
|||||||
*
|
*
|
||||||
* @return can be walked through (if discovered / open)
|
* @return can be walked through (if discovered / open)
|
||||||
*/
|
*/
|
||||||
public abstract boolean isPotentiallyWalkable();
|
public abstract boolean isWalkable();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,18 +4,22 @@ package mightypork.rogue.world.tile;
|
|||||||
import mightypork.util.constraints.rect.Rect;
|
import mightypork.util.constraints.rect.Rect;
|
||||||
import mightypork.util.constraints.rect.builders.TiledRect;
|
import mightypork.util.constraints.rect.builders.TiledRect;
|
||||||
import mightypork.util.constraints.rect.proxy.RectBound;
|
import mightypork.util.constraints.rect.proxy.RectBound;
|
||||||
|
import mightypork.util.math.noise.NoiseGen;
|
||||||
|
|
||||||
|
|
||||||
public final class TileRenderContext implements RectBound {
|
public final class TileRenderContext implements RectBound {
|
||||||
|
|
||||||
private final TileHolder map;
|
private final TileGrid map;
|
||||||
private final TiledRect tiler;
|
private final TiledRect tiler;
|
||||||
private int x, y;
|
private final NoiseGen noise;
|
||||||
|
|
||||||
|
public int x, y;
|
||||||
|
|
||||||
|
|
||||||
public TileRenderContext(TileHolder map, Rect mapArea) {
|
public TileRenderContext(TileGrid map, Rect drawArea, long renderNoiseSeed) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.tiler = mapArea.tiles(map.getWidth(), map.getHeight());
|
this.tiler = drawArea.tiles(map.getWidth(), map.getHeight());
|
||||||
|
this.noise = new NoiseGen(0.2, 0, 0.5, 1, renderNoiseSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -36,4 +40,20 @@ public final class TileRenderContext implements RectBound {
|
|||||||
{
|
{
|
||||||
return tiler.tile(x, y);
|
return tiler.tile(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return per-coord noise value 0..1
|
||||||
|
*/
|
||||||
|
public double getNoise()
|
||||||
|
{
|
||||||
|
return noise.valueAt(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setCoord(int x, int y)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package mightypork.rogue.world.tile.impl;
|
||||||
|
|
||||||
|
public class SimpleFloor extends SimpleTile {
|
||||||
|
|
||||||
|
public SimpleFloor(int id, String sheetKey) {
|
||||||
|
super(id, sheetKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWalkable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package mightypork.rogue.world.tile.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import mightypork.gamecore.render.DisplaySystem;
|
||||||
|
import mightypork.gamecore.render.Render;
|
||||||
|
import mightypork.gamecore.render.textures.TxSheet;
|
||||||
|
import mightypork.rogue.Res;
|
||||||
|
import mightypork.rogue.world.tile.TileData;
|
||||||
|
import mightypork.rogue.world.tile.TileModel;
|
||||||
|
import mightypork.rogue.world.tile.TileRenderContext;
|
||||||
|
import mightypork.util.annotations.DefaultImpl;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class SimpleTile extends TileModel {
|
||||||
|
|
||||||
|
private TxSheet sheet;
|
||||||
|
|
||||||
|
|
||||||
|
public SimpleTile(int id, String sheetKey) {
|
||||||
|
super(id);
|
||||||
|
this.sheet = Res.getTxSheet(sheetKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DefaultImpl
|
||||||
|
public void load(TileData data, InputStream in) throws IOException
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DefaultImpl
|
||||||
|
public void save(TileData data, OutputStream out) throws IOException
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(TileData data, TileRenderContext context)
|
||||||
|
{
|
||||||
|
// TODO worldmap should take care of this and break the row drawing when it encounters end of screen etc
|
||||||
|
|
||||||
|
// not in screen -> no draw
|
||||||
|
if (!context.getRect().intersectsWith(DisplaySystem.getBounds())) return;
|
||||||
|
|
||||||
|
Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getNoise()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DefaultImpl
|
||||||
|
public void update(TileData item, double delta)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DefaultImpl
|
||||||
|
public boolean isWalkable(TileData data)
|
||||||
|
{
|
||||||
|
return isWalkable();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package mightypork.rogue.world.tile.impl;
|
||||||
|
|
||||||
|
|
||||||
|
public class SimpleWall extends SimpleTile {
|
||||||
|
|
||||||
|
public SimpleWall(int id, String sheetKey) {
|
||||||
|
super(id, sheetKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWalkable()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ public class FakeTile extends TileModel {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPotentiallyWalkable()
|
public boolean isWalkable()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package mightypork.util.constraints.rect;
|
package mightypork.util.constraints.rect;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.util.annotations.FactoryMethod;
|
import mightypork.util.annotations.FactoryMethod;
|
||||||
import mightypork.util.constraints.DigestCache;
|
import mightypork.util.constraints.DigestCache;
|
||||||
import mightypork.util.constraints.Digestable;
|
import mightypork.util.constraints.Digestable;
|
||||||
@@ -952,4 +951,37 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
|
|||||||
{
|
{
|
||||||
return new TiledRect(this, 1, rows);
|
return new TiledRect(this, 1, rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for intersection
|
||||||
|
*
|
||||||
|
* @param other other rect
|
||||||
|
* @return true if they intersect
|
||||||
|
* @see org.lwjgl.util.Rectangle
|
||||||
|
*/
|
||||||
|
public boolean intersectsWith(Rect other)
|
||||||
|
{
|
||||||
|
double tw = this.size().x();
|
||||||
|
double th = this.size().y();
|
||||||
|
double rw = other.size().x();
|
||||||
|
double rh = other.size().y();
|
||||||
|
|
||||||
|
if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
double tx = this.origin().x();
|
||||||
|
double ty = this.origin().y();
|
||||||
|
double rx = other.origin().x();
|
||||||
|
double ry = other.origin().y();
|
||||||
|
|
||||||
|
rw += rx;
|
||||||
|
rh += ry;
|
||||||
|
tw += tx;
|
||||||
|
th += ty;
|
||||||
|
|
||||||
|
// overflow || intersect
|
||||||
|
return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,19 @@ public class NoiseGen {
|
|||||||
private final double density;
|
private final double density;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* make a new noise generator with a random seed
|
||||||
|
*
|
||||||
|
* @param density noise density (0..1). Lower density means larger "spots".
|
||||||
|
* @param low low bound ("valley")
|
||||||
|
* @param middle middle bound ("surface")
|
||||||
|
* @param high high bound ("hill")
|
||||||
|
*/
|
||||||
|
public NoiseGen(double density, double low, double middle, double high) {
|
||||||
|
this(density, low, middle, high, Double.doubleToLongBits(Math.random()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make a new noise generator
|
* make a new noise generator
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user