cleanup & reorg

v5stable
Ondřej Hruška 11 years ago
parent 0771a5e0d8
commit 83f21ca8c5
  1. 1
      src/mightypork/rogue/App.java
  2. 2
      src/mightypork/rogue/screens/gamescreen/HeartBar.java
  3. 4
      src/mightypork/rogue/screens/gamescreen/HudLayer.java
  4. 2
      src/mightypork/rogue/screens/gamescreen/NavItemSlot.java
  5. 1
      src/mightypork/rogue/screens/gamescreen/ScreenGame.java
  6. 6
      src/mightypork/rogue/screens/gamescreen/WorldLayer.java
  7. 10
      src/mightypork/rogue/world/PlayerControl.java
  8. 2
      src/mightypork/rogue/world/World.java
  9. 15
      src/mightypork/rogue/world/WorldProvider.java
  10. 9
      src/mightypork/rogue/world/WorldRenderer.java
  11. 20
      src/mightypork/rogue/world/entity/Entities.java
  12. 10
      src/mightypork/rogue/world/entity/Entity.java
  13. 9
      src/mightypork/rogue/world/entity/EntityModel.java
  14. 3
      src/mightypork/rogue/world/entity/EntityModule.java
  15. 3
      src/mightypork/rogue/world/entity/EntityPathfindingContext.java
  16. 12
      src/mightypork/rogue/world/entity/SimpleEntityPathFindingContext.java
  17. 9
      src/mightypork/rogue/world/entity/entities/PlayerEntity.java
  18. 4
      src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java
  19. 14
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  20. 3
      src/mightypork/rogue/world/entity/modules/EntityMoveListener.java
  21. 6
      src/mightypork/rogue/world/entity/modules/EntityPos.java
  22. 3
      src/mightypork/rogue/world/entity/renderers/EntityRenderer.java
  23. 3
      src/mightypork/rogue/world/entity/renderers/SimpleLeftRightMobRenderer.java
  24. 4
      src/mightypork/rogue/world/gen/LevelGenerator.java
  25. 6
      src/mightypork/rogue/world/gen/ScratchMap.java
  26. 21
      src/mightypork/rogue/world/gui/MapView.java
  27. 9
      src/mightypork/rogue/world/gui/Minimap.java
  28. 3
      src/mightypork/rogue/world/gui/interaction/MIPClickPathfWalk.java
  29. 3
      src/mightypork/rogue/world/gui/interaction/MIPKeyWalk.java
  30. 3
      src/mightypork/rogue/world/gui/interaction/MIPMouseWalk.java
  31. 3
      src/mightypork/rogue/world/gui/interaction/MapInteractionPlugin.java
  32. 20
      src/mightypork/rogue/world/level/Level.java
  33. 8
      src/mightypork/rogue/world/pathfinding/FillContext.java
  34. 21
      src/mightypork/rogue/world/pathfinding/FloodFill.java
  35. 4
      src/mightypork/rogue/world/pathfinding/PathFindingContext.java
  36. 3
      src/mightypork/rogue/world/tile/Tile.java
  37. 4
      src/mightypork/rogue/world/tile/TileModel.java
  38. 8
      src/mightypork/rogue/world/tile/TileRenderer.java
  39. 3
      src/mightypork/rogue/world/tile/TileType.java
  40. 16
      src/mightypork/rogue/world/tile/Tiles.java
  41. 2
      src/mightypork/rogue/world/tile/tiles/DoorTile.java
  42. 8
      src/mightypork/rogue/world/tile/tiles/GroundTile.java
  43. 1
      src/mightypork/rogue/world/tile/tiles/LockedDoorTile.java
  44. 11
      src/mightypork/rogue/world/tile/tiles/NullTile.java
  45. 12
      src/mightypork/rogue/world/tile/tiles/SolidTile.java
  46. 6
      src/mightypork/rogue/world/tile/tiles/WallTile.java
  47. 15
      src/mightypork/util/error/IllegalValueException.java
  48. 2
      src/mightypork/util/files/ion/IonBinary.java
  49. 8
      src/mightypork/util/files/ion/IonOutput.java

@ -113,6 +113,7 @@ public final class App extends BaseApp {
Ion.registerBinary(Level.ION_MARK, Level.class);
}
@Override
protected void postInit()
{

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.gui;
package mightypork.rogue.screens.gamescreen;
import mightypork.gamecore.gui.AlignX;

@ -9,9 +9,7 @@ import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.rogue.Res;
import mightypork.rogue.screens.gamescreen.gui.HeartBar;
import mightypork.rogue.screens.gamescreen.gui.NavItemSlot;
import mightypork.rogue.screens.gamescreen.world.Minimap;
import mightypork.rogue.world.gui.Minimap;
import mightypork.util.math.constraints.num.Num;
import mightypork.util.math.constraints.rect.Rect;

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.gui;
package mightypork.rogue.screens.gamescreen;
import mightypork.gamecore.control.events.input.MouseMotionEvent;

@ -32,6 +32,7 @@ public class ScreenGame extends LayeredScreen {
WorldProvider.get().setListening(true);
}
@Override
protected void onScreenLeave()
{

@ -3,9 +3,9 @@ package mightypork.rogue.screens.gamescreen;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.rogue.screens.gamescreen.world.MIPClickPathfWalk;
import mightypork.rogue.screens.gamescreen.world.MIPKeyWalk;
import mightypork.rogue.screens.gamescreen.world.MapView;
import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.world.gui.interaction.MIPClickPathfWalk;
import mightypork.rogue.world.gui.interaction.MIPKeyWalk;
import mightypork.util.math.constraints.num.Num;

@ -21,11 +21,11 @@ public abstract class PlayerControl {
private World getWorld2()
{
World newWorld = getWorld();
{
final World newWorld = getWorld();
if (newWorld != lastWorld) {
for (EntityMoveListener eml : playerMoveListeners) {
for (final EntityMoveListener eml : playerMoveListeners) {
newWorld.getPlayerEntity().pos.addMoveListener(eml);
}
}
@ -39,7 +39,7 @@ public abstract class PlayerControl {
private Entity getPlayerEntity()
{
if(getWorld2() == null) return null;
if (getWorld2() == null) return null;
return getWorld2().getPlayerEntity();
}
@ -82,7 +82,7 @@ public abstract class PlayerControl {
public void addMoveListener(EntityMoveListener eml)
{
playerMoveListeners.add(eml);
if(getPlayerEntity() != null) {
if (getPlayerEntity() != null) {
getPlayerEntity().pos.addMoveListener(eml);
}
}

@ -46,7 +46,7 @@ public class World implements IonBundled, Updateable {
in.loadBundled("player", playerInfo);
playerEntity = levels.get(playerInfo.getLevel()).getEntity(playerInfo.getEID());
if(playerEntity == null) throw new RuntimeException("Player entity not found in the world.");
if (playerEntity == null) throw new RuntimeException("Player entity not found in the world.");
}

@ -11,7 +11,7 @@ import mightypork.util.control.eventbus.clients.RootBusNode;
import mightypork.util.files.ion.Ion;
public class WorldProvider extends RootBusNode{
public class WorldProvider extends RootBusNode {
public static synchronized void init(BusAccess busAccess)
{
@ -21,7 +21,8 @@ public class WorldProvider extends RootBusNode{
}
public WorldProvider(BusAccess busAccess) {
public WorldProvider(BusAccess busAccess)
{
super(busAccess);
setListening(false);
}
@ -31,9 +32,7 @@ public class WorldProvider extends RootBusNode{
public static WorldProvider get()
{
if (inst == null) {
throw new IllegalStateException("World provider not initialized.");
}
if (inst == null) { throw new IllegalStateException("World provider not initialized."); }
return inst;
}
@ -60,8 +59,10 @@ public class WorldProvider extends RootBusNode{
return world;
}
private void setWorld(World newWorld) {
private void setWorld(World newWorld)
{
if (world != null) removeChildClient(world);
world = newWorld;
addChildClient(world);

@ -38,7 +38,8 @@ public class WorldRenderer extends RectProxy {
private TileRenderContext trc;
public WorldRenderer(Rect viewport, Num tileSize) {
public WorldRenderer(Rect viewport, Num tileSize)
{
super(viewport);
this.tileSize = tileSize;
@ -69,7 +70,7 @@ public class WorldRenderer extends RectProxy {
private VectConst getOffset()
{
Entity ent = WorldProvider.get().getPlayerEntity();
final Entity ent = WorldProvider.get().getPlayerEntity();
return Vect.make(ent.pos.getVisualPos().neg().sub(0.5, 0.5)).freeze();
}
@ -85,7 +86,7 @@ public class WorldRenderer extends RectProxy {
Render.translate(getOffset());
// tiles to render
Entity ent = WorldProvider.get().getPlayerEntity();
final Entity ent = WorldProvider.get().getPlayerEntity();
final Coord pos = ent.pos.getCoord();
final double w = width().value();
@ -131,7 +132,7 @@ public class WorldRenderer extends RectProxy {
for (final Entity e : activeLevel.getEntities()) {
// avoid entities out of view rect
Vect entPos = e.pos.getVisualPos();
final Vect entPos = e.pos.getVisualPos();
final int x = (int) Math.round(entPos.x());
final int y = (int) Math.round(entPos.y());

@ -23,13 +23,9 @@ public final class Entities {
public static void register(int id, EntityModel model)
{
if (id < 0 || id >= entities.length) {
throw new IllegalArgumentException("Entity model ID " + id + " is out of range.");
}
if (id < 0 || id >= entities.length) { throw new IllegalArgumentException("Entity model ID " + id + " is out of range."); }
if (entities[id] != null) {
throw new IllegalArgumentException("Entity model ID " + id + " already in use.");
}
if (entities[id] != null) { throw new IllegalArgumentException("Entity model ID " + id + " already in use."); }
entities[id] = model;
}
@ -39,9 +35,7 @@ public final class Entities {
{
final EntityModel e = entities[id];
if (e == null) {
throw new IllegalArgumentException("No entity model with ID " + id + ".");
}
if (e == null) { throw new IllegalArgumentException("No entity model with ID " + id + "."); }
return e;
}
@ -58,7 +52,7 @@ public final class Entities {
public static void saveEntities(IonOutput out, Collection<Entity> entities) throws IOException
{
for (Entity entity : entities) {
for (final Entity entity : entities) {
out.startEntry();
saveEntity(out, entity);
}
@ -69,16 +63,16 @@ public final class Entities {
public static Entity loadEntity(IonInput in) throws IOException
{
int id = in.readIntByte();
final int id = in.readIntByte();
EntityModel model = get(id);
final EntityModel model = get(id);
return model.loadEntity(in);
}
public static void saveEntity(IonOutput out, Entity entity) throws IOException
{
EntityModel model = entity.getModel();
final EntityModel model = entity.getModel();
out.writeIntByte(model.id);

@ -7,7 +7,6 @@ import java.util.Map;
import java.util.Map.Entry;
import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.modules.EntityModule;
import mightypork.rogue.world.entity.modules.EntityModuleHealth;
import mightypork.rogue.world.entity.modules.EntityModulePosition;
import mightypork.rogue.world.entity.modules.EntityMoveListener;
@ -41,7 +40,8 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
public final EntityModuleHealth health = new EntityModuleHealth(this);
public Entity(EntityModel model, int eid) {
public Entity(EntityModel model, int eid)
{
this.entityId = eid;
this.model = model;
@ -57,7 +57,7 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
public void save(IonBundle bundle) throws IOException
{
bundle.put("eid", entityId);
for (Entry<String, EntityModule> entry : modules.entrySet()) {
for (final Entry<String, EntityModule> entry : modules.entrySet()) {
bundle.putBundled(entry.getKey(), entry.getValue());
}
}
@ -69,7 +69,7 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
entityId = bundle.get("eid", -1);
if (entityId < 0) throw new IllegalValueException("Bad entity id: " + entityId);
for (Entry<String, EntityModule> entry : modules.entrySet()) {
for (final Entry<String, EntityModule> entry : modules.entrySet()) {
bundle.loadBundled(entry.getKey(), entry.getValue());
}
}
@ -117,7 +117,7 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
@Override
public void update(double delta)
{
for (Entry<String, EntityModule> entry : modules.entrySet()) {
for (final Entry<String, EntityModule> entry : modules.entrySet()) {
entry.getValue().update(delta);
}
}

@ -27,11 +27,12 @@ public final class EntityModel {
this.tileClass = entity;
}
public Entity createEntity(int eid)
{
try {
return tileClass.getConstructor(EntityModel.class, int.class).newInstance(this, eid);
} catch (Exception e) {
} catch (final Exception e) {
throw new RuntimeException("Could not instantiate a tile.", e);
}
}
@ -39,8 +40,8 @@ public final class EntityModel {
public Entity loadEntity(IonInput in) throws IOException
{
IonBundle bundle = in.readBundle();
Entity ent = createEntity(-1);
final IonBundle bundle = in.readBundle();
final Entity ent = createEntity(-1);
ent.load(bundle);
return ent;
}
@ -48,7 +49,7 @@ public final class EntityModel {
public void saveEntity(IonOutput out, Entity entity) throws IOException
{
IonBundle bundle = new IonBundle();
final IonBundle bundle = new IonBundle();
entity.save(bundle);
out.writeBundle(bundle);
}

@ -1,4 +1,5 @@
package mightypork.rogue.world.entity.modules;
package mightypork.rogue.world.entity;
import mightypork.util.files.ion.IonBundled;
import mightypork.util.timing.Updateable;

@ -13,7 +13,8 @@ public abstract class EntityPathfindingContext implements PathFindingContext {
protected final Entity entity;
public EntityPathfindingContext(Entity entity) {
public EntityPathfindingContext(Entity entity)
{
this.entity = entity;
}

@ -1,20 +1,24 @@
package mightypork.rogue.world.entity;
import mightypork.rogue.world.Coord;
public class SimpleEntityPathFindingContext extends EntityPathfindingContext {
public SimpleEntityPathFindingContext(Entity entity) {
public SimpleEntityPathFindingContext(Entity entity)
{
super(entity);
}
@Override
public int getCost(Coord from, Coord to)
{
return 10;
}
@Override
public int getMinCost()
{

@ -21,9 +21,7 @@ public class PlayerEntity extends Entity {
public int getCost(Coord from, Coord to)
{
if (!getLevel().getTile(pos.getCoord()).isExplored()) {
return 1000;
}
if (!getLevel().getTile(pos.getCoord()).isExplored()) { return 1000; }
return super.getCost(from, to);
@ -33,7 +31,8 @@ public class PlayerEntity extends Entity {
private final EntityRenderer renderer = new SimpleLeftRightMobRenderer(this, "sprite.player");
public PlayerEntity(EntityModel model, int eid) {
public PlayerEntity(EntityModel model, int eid)
{
super(model, eid);
// init default values
@ -47,6 +46,7 @@ public class PlayerEntity extends Entity {
return pathfc;
}
@Override
public void setLevel(Level level)
{
@ -61,6 +61,7 @@ public class PlayerEntity extends Entity {
renderer.render(context);
}
@Override
public void onStepFinished(Entity entity)
{

@ -4,6 +4,7 @@ package mightypork.rogue.world.entity.modules;
import java.io.IOException;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModule;
import mightypork.util.error.IllegalValueException;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.math.Calc;
@ -11,7 +12,8 @@ import mightypork.util.math.Calc;
public class EntityModuleHealth implements EntityModule {
public EntityModuleHealth(Entity entity) {
public EntityModuleHealth(Entity entity)
{
this.entity = entity;
}

@ -10,6 +10,7 @@ import java.util.Set;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModule;
import mightypork.rogue.world.entity.PathStep;
import mightypork.rogue.world.pathfinding.PathFinder;
import mightypork.rogue.world.pathfinding.PathFindingContext;
@ -36,7 +37,8 @@ public class EntityModulePosition implements EntityModule {
private final Set<EntityMoveListener> moveListeners = new LinkedHashSet<>();
public EntityModulePosition(Entity entity) {
public EntityModulePosition(Entity entity)
{
this.entity = entity;
}
@ -144,7 +146,7 @@ public class EntityModulePosition implements EntityModule {
public boolean navigateTo(Coord target)
{
if (target.equals(getCoord())) return true;
PathFindingContext pfc = entity.getPathfindingContext();
final PathFindingContext pfc = entity.getPathfindingContext();
final List<PathStep> newPath = PathFinder.findPathRelative(pfc, entityPos.getCoord(), target);
if (newPath == null) return false;
@ -185,14 +187,14 @@ public class EntityModulePosition implements EntityModule {
{
this.stepTime = stepTime;
}
public double getProgress()
{
return entityPos.getProgress();
}
public VectConst getVisualPos()
{
return entityPos.getVisualPos();

@ -1,8 +1,7 @@
package mightypork.rogue.world.entity.modules;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.Entity;
public interface EntityMoveListener {

@ -177,10 +177,10 @@ public class EntityPos implements IonBundled, Updateable {
} else if (!coord.equals(other.coord)) return false;
return true;
}
public VectConst getVisualPos()
{
return Vect.make(walkOffset.x()+coord.x, walkOffset.y()+coord.y);
return Vect.make(walkOffset.x() + coord.x, walkOffset.y() + coord.y);
}
}

@ -10,7 +10,8 @@ public abstract class EntityRenderer {
protected final Entity entity;
public EntityRenderer(Entity entity) {
public EntityRenderer(Entity entity)
{
this.entity = entity;
}

@ -17,7 +17,8 @@ public class SimpleLeftRightMobRenderer extends EntityRenderer {
private final TxSheet sheet;
public SimpleLeftRightMobRenderer(Entity entity, String sheetKey) {
public SimpleLeftRightMobRenderer(Entity entity, String sheetKey)
{
super(entity);
this.sheet = Res.getTxSheet(sheetKey);
}

@ -29,9 +29,9 @@ public class LevelGenerator {
// start
map.addRoom(ROOM_SQUARE);
for (int i = 0; i < 2+complexity/2+rand.nextInt((int) (1+complexity*0.3)); i++) {
for (int i = 0; i < 2 + complexity / 2 + rand.nextInt((int) (1 + complexity * 0.3)); i++) {
map.addRoom(ROOM_SQUARE);
if(rand.nextInt(4)>0) map.addRoom(DEAD_END);
if (rand.nextInt(4) > 0) map.addRoom(DEAD_END);
}
map.buildCorridors();

@ -77,8 +77,10 @@ public class ScratchMap {
return PathFinder.CORNER_HEURISTIC;
}
@Override
public Coord[] getWalkSides() {
public Coord[] getWalkSides()
{
return Sides.cardinalSides;
}
@ -261,7 +263,7 @@ public class ScratchMap {
Log.f3("Building corridors.");
Coord start = nodes.get(0);
Set<Coord> starts = new HashSet<>();
final Set<Coord> starts = new HashSet<>();
for (int i = 0; i < 2 + rooms.size() / 5; i++) {
if (!starts.contains(start)) {

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.world;
package mightypork.rogue.world.gui;
import java.util.HashSet;
@ -16,6 +16,7 @@ import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.WorldRenderer;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.modules.EntityMoveListener;
import mightypork.rogue.world.gui.interaction.MapInteractionPlugin;
import mightypork.util.math.Easing;
import mightypork.util.math.constraints.num.Num;
import mightypork.util.math.constraints.num.mutable.NumAnimated;
@ -23,6 +24,11 @@ import mightypork.util.math.constraints.vect.Vect;
import mightypork.util.timing.Updateable;
/**
* Level display component
*
* @author MightyPork
*/
public class MapView extends InputComponent implements KeyListener, MouseButtonListener, EntityMoveListener, Updateable {
protected final WorldRenderer worldRenderer;
@ -109,8 +115,8 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
p.onKey(this, pc, event.getKey(), event.isDown());
}
if(event.getKey() == Keys.Z) {
if(event.isDown()) {
if (event.getKey() == Keys.Z) {
if (event.isDown()) {
zoom.fadeIn(1);
} else {
zoom.fadeOut(1);
@ -123,12 +129,17 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
}
/**
* Add interaction plugin
*
* @param plugin
*/
public void addPlugin(MapInteractionPlugin plugin)
{
plugins.add(plugin);
}
@Override
public void update(double delta)
{

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.world;
package mightypork.rogue.world.gui;
import mightypork.gamecore.control.events.input.MouseButtonEvent;
@ -6,7 +6,6 @@ import mightypork.gamecore.control.events.input.MouseButtonListener;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.render.Render;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.level.Level;
@ -29,17 +28,15 @@ public class Minimap extends InputComponent implements MouseButtonListener {
private final Color playerColor = RGB.RED;
@Override
protected void renderComponent()
{
Color.pushAlpha(translucency);
final Level lvl = WorldProvider.get().getCurrentLevel();
unit = (int) Math.min(Math.max(2, Math.ceil((height().value()/2) / (lvl.getHeight() + 2))), 6);
unit = (int) Math.min(Math.max(2, Math.ceil((height().value() / 2) / (lvl.getHeight() + 2))), 6);
final World w = lvl.getWorld();
final Entity e = w.getPlayerEntity();
final Entity e = WorldProvider.get().getPlayerEntity();
final Vect plCoord = e.pos.getVisualPos();
final int lw = lvl.getWidth();

@ -1,9 +1,10 @@
package mightypork.rogue.screens.gamescreen.world;
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.constraints.vect.Vect;

@ -1,9 +1,10 @@
package mightypork.rogue.screens.gamescreen.world;
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.Keys;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.constraints.vect.Vect;

@ -1,9 +1,10 @@
package mightypork.rogue.screens.gamescreen.world;
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.Calc.Deg;
import mightypork.util.math.Polar;
import mightypork.util.math.constraints.vect.Vect;

@ -1,7 +1,8 @@
package mightypork.rogue.screens.gamescreen.world;
package mightypork.rogue.world.gui.interaction;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.constraints.vect.Vect;

@ -53,11 +53,13 @@ public class Level implements MapAccess, IonBinary {
private transient NoiseGen noiseGen;
public Level() {
public Level()
{
}
public Level(int width, int height) {
public Level(int width, int height)
{
size.setTo(width, height);
buildArray();
}
@ -89,7 +91,7 @@ public class Level implements MapAccess, IonBinary {
public final Tile getTile(Coord pos)
{
if (!pos.isInRange(0, 0, size.x - 1, size.y - 1)) return Tiles.NULL.createTile(); // out of range
return tiles[pos.y][pos.x];
}
@ -164,7 +166,7 @@ public class Level implements MapAccess, IonBinary {
setTile(c, Tiles.loadTile(in));
}
}
// load entities
Entities.loadEntities(in, entitySet);
@ -327,16 +329,16 @@ public class Level implements MapAccess, IonBinary {
public void explore(Coord center)
{
Collection<Coord> filled = new HashSet<>();
final Collection<Coord> filled = new HashSet<>();
FloodFill.fill(center, exploreFc, filled);
for (Coord c : filled) {
for (final Coord c : filled) {
getTile(c).setExplored();
}
}
private FillContext exploreFc = new FillContext() {
private final FillContext exploreFc = new FillContext() {
@Override
public Coord[] getSpreadSides()
@ -355,7 +357,7 @@ public class Level implements MapAccess, IonBinary {
@Override
public boolean canSpreadFrom(Coord pos)
{
Tile t = getTile(pos);
final Tile t = getTile(pos);
return t.isWalkable() && t.getType() != TileType.DOOR;
}
@ -363,7 +365,7 @@ public class Level implements MapAccess, IonBinary {
@Override
public boolean canEnter(Coord pos)
{
Tile t = getTile(pos);
final Tile t = getTile(pos);
return !t.isNull();
}

@ -11,7 +11,9 @@ public interface FillContext {
boolean canSpreadFrom(Coord pos);
Coord[] getSpreadSides();
Coord[] getSpreadSides();
/**
* Get the max distance filled form start point. Use -1 for unlimited range.
@ -19,8 +21,8 @@ public interface FillContext {
* @return max distance
*/
double getMaxDistance();
/**
* @return true if start should be spread no matter what
*/

@ -8,10 +8,11 @@ import java.util.Queue;
import mightypork.rogue.world.Coord;
public class FloodFill {
public class FloodFill {
/**
* Fill an area
*
* @param start start point
* @param context filling context
* @param foundNodes collection to put filled coords in
@ -19,29 +20,29 @@ public class FloodFill {
*/
public static final boolean fill(Coord start, FillContext context, Collection<Coord> foundNodes)
{
Queue<Coord> activeNodes = new LinkedList<>();
final Queue<Coord> activeNodes = new LinkedList<>();
double maxDist = context.getMaxDistance();
final double maxDist = context.getMaxDistance();
activeNodes.add(start);
Coord[] sides = context.getSpreadSides();
final Coord[] sides = context.getSpreadSides();
boolean forceSpreadNext = context.forceSpreadStart();
boolean limitReached = false;
while (!activeNodes.isEmpty()) {
Coord current = activeNodes.poll();
while (!activeNodes.isEmpty()) {
final Coord current = activeNodes.poll();
foundNodes.add(current);
if(!context.canSpreadFrom(current) && !forceSpreadNext) continue;
if (!context.canSpreadFrom(current) && !forceSpreadNext) continue;
forceSpreadNext = false;
for (Coord spr : sides) {
Coord next = current.add(spr);
if(activeNodes.contains(next) || foundNodes.contains(next)) continue;
for (final Coord spr : sides) {
final Coord next = current.add(spr);
if (activeNodes.contains(next) || foundNodes.contains(next)) continue;
if (next.dist(start) > maxDist) {
limitReached = true;

@ -33,7 +33,7 @@ public interface PathFindingContext {
* @return used heuristic
*/
Heuristic getHeuristic();
Coord[] getWalkSides();
}

@ -33,7 +33,8 @@ public abstract class Tile implements IonBinaryHeadless {
protected boolean explored;
public Tile(TileModel model, TileRenderer renderer) {
public Tile(TileModel model, TileRenderer renderer)
{
this.model = model;
this.renderer = renderer;
}

@ -36,7 +36,7 @@ public final class TileModel {
{
try {
return tileClass.getConstructor(TileModel.class, TileRenderer.class).newInstance(this, renderer);
} catch (Exception e) {
} catch (final Exception e) {
throw new RuntimeException("Could not instantiate a tile.", e);
}
}
@ -44,7 +44,7 @@ public final class TileModel {
public Tile loadTile(IonInput in) throws IOException
{
Tile t = createTile();
final Tile t = createTile();
t.load(in);
return t;
}

@ -1,5 +1,6 @@
package mightypork.rogue.world.tile;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.textures.TxQuad;
import mightypork.rogue.Res;
@ -22,7 +23,8 @@ public abstract class TileRenderer {
private static boolean inited;
public TileRenderer() {
public TileRenderer()
{
if (!inited) {
SH_N = Res.getTxQuad("tile.shadow.n");
SH_S = Res.getTxQuad("tile.shadow.s");
@ -100,7 +102,7 @@ public abstract class TileRenderer {
if (ufog == 0) return;
final Rect rect = context.getRect();
final Rect rect = context.getRect();
if ((ufog & Sides.NW_CORNER) == Sides.NW) Render.quadTextured(rect, UFOG_NW);
if ((ufog & Sides.N) != 0) Render.quadTextured(rect, UFOG_N);
if ((ufog & Sides.NE_CORNER) == Sides.NE) Render.quadTextured(rect, UFOG_NE);
@ -108,7 +110,7 @@ public abstract class TileRenderer {
if ((ufog & Sides.W) != 0) Render.quadTextured(rect, UFOG_W);
if ((ufog & Sides.E) != 0) Render.quadTextured(rect, UFOG_E);
if ((ufog & Sides.SW_CORNER) == Sides.SW) Render.quadTextured(rect, UFOG_SW);
if ((ufog & Sides.SW_CORNER) == Sides.SW) Render.quadTextured(rect, UFOG_SW);
if ((ufog & Sides.S) != 0) Render.quadTextured(rect, UFOG_S);
if ((ufog & Sides.SE_CORNER) == Sides.SE) Render.quadTextured(rect, UFOG_SE);
}

@ -26,7 +26,8 @@ public enum TileType
private final boolean potentiallyWalkable;
private TileType(Color mapColor, boolean potentiallyWalkable) {
private TileType(Color mapColor, boolean potentiallyWalkable)
{
this.mapColor = mapColor;
this.potentiallyWalkable = potentiallyWalkable;
}

@ -26,9 +26,9 @@ public final class Tiles {
public static final TileModel NULL = new TileModel(0, NullTile.class, new NullTileRenderer());
public static final TileModel FLOOR_DARK = new TileModel(10, FloorTile.class, new BasicTileRenderer("tile.floor.dark"));
public static final TileModel WALL_BRICK = new TileModel(11, WallTile.class, new BasicTileRenderer("tile.wall.brick"));
public static final TileModel WALL_BRICK = new TileModel(11, WallTile.class, new BasicTileRenderer("tile.wall.brick"));
public static final TileModel DOOR = new TileModel(12, DoorTile.class, new DoorTileRenderer("tile.door.closed", "tile.door.open"));
public static void register(int id, TileModel model)
{
@ -52,22 +52,22 @@ public final class Tiles {
public static Tile loadTile(IonInput in) throws IOException
{
int id = in.readIntByte();
final int id = in.readIntByte();
TileModel model = get(id);
final TileModel model = get(id);
return model.loadTile(in);
}
public static void saveTile(IonOutput out, Tile tile) throws IOException
{
TileModel model = tile.getModel();
final TileModel model = tile.getModel();
out.writeIntByte(model.id);
out.writeIntByte(model.id);
model.saveTile(out, tile);
}
public static Tile create(int tileId)
{
return get(tileId).createTile();

@ -13,12 +13,14 @@ public class DoorTile extends SolidTile {
super(model, renderer);
}
@Override
public boolean isWalkable()
{
return true;
}
@Override
public TileType getType()
{

@ -17,10 +17,11 @@ import mightypork.util.files.ion.IonOutput;
public abstract class GroundTile extends Tile {
private DroppedItemRenderer itemRenderer = new DroppedItemRenderer();
private final DroppedItemRenderer itemRenderer = new DroppedItemRenderer();
protected final Stack<Item> items = new Stack<>();
public GroundTile(TileModel model, TileRenderer renderer)
{
super(model, renderer);
@ -60,18 +61,21 @@ public abstract class GroundTile extends Tile {
in.readSequence(items);
}
@Override
public boolean doesCastShadow()
{
return false;
}
@Override
public boolean isWalkable()
{
return true;
}
@Override
public boolean dropItem(Item item)
{
@ -79,12 +83,14 @@ public abstract class GroundTile extends Tile {
return true;
}
@Override
public Item pickItem()
{
return hasItem() ? items.pop() : null;
}
@Override
public boolean hasItem()
{

@ -19,6 +19,7 @@ public class LockedDoorTile extends DoorTile {
super(model, renderer);
}
@Override
public boolean isWalkable()
{

@ -62,21 +62,22 @@ public class NullTile extends Tile {
{
return false;
}
@Override
public boolean dropItem(Item item)
{
return false;
}
@Override
public Item pickItem()
{
return null;
}
@Override
public boolean hasItem()
{

@ -1,5 +1,6 @@
package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel;
@ -7,36 +8,41 @@ import mightypork.rogue.world.tile.TileRenderer;
public abstract class SolidTile extends Tile {
public SolidTile(TileModel model, TileRenderer renderer)
{
super(model, renderer);
}
@Override
public boolean isWalkable()
{
return false;
}
@Override
public boolean doesCastShadow()
{
return true;
}
@Override
public boolean hasItem()
{
return false;
}
@Override
public boolean dropItem(Item item)
{
return false;
}
@Override
public Item pickItem()
{

@ -1,17 +1,19 @@
package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType;
public class WallTile extends SolidTile {
public WallTile(TileModel model, TileRenderer renderer)
{
super(model, renderer);
}
@Override
public TileType getType()
{

@ -3,26 +3,31 @@ package mightypork.util.error;
public class IllegalValueException extends RuntimeException {
public IllegalValueException() {
public IllegalValueException()
{
}
public IllegalValueException(String message) {
public IllegalValueException(String message)
{
super(message);
}
public IllegalValueException(Throwable cause) {
public IllegalValueException(Throwable cause)
{
super(cause);
}
public IllegalValueException(String message, Throwable cause) {
public IllegalValueException(String message, Throwable cause)
{
super(message, cause);
}
public IllegalValueException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
public IllegalValueException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
{
super(message, cause, enableSuppression, writableStackTrace);
}

@ -1,8 +1,6 @@
package mightypork.util.files.ion;
/**
* Binary ion object, with a mark = saveable / loadable on it's own
*

@ -229,14 +229,14 @@ public class IonOutput {
}
endSequence();
}
public void endSequence() throws IOException
{
writeMark(Ion.END);
}
public void startEntry() throws IOException
{
writeMark(Ion.ENTRY);

Loading…
Cancel
Save