weirdly broken world renderer while triny to optimize
This commit is contained in:
@@ -26,8 +26,8 @@ import mightypork.rogue.world.entity.Entity;
|
||||
import mightypork.rogue.world.item.Item;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.util.control.eventbus.BusEvent;
|
||||
import mightypork.util.control.eventbus.EventBus;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.ion.Ion;
|
||||
import mightypork.util.logging.Log;
|
||||
import mightypork.util.logging.writers.LogWriter;
|
||||
@@ -139,7 +139,7 @@ public final class App extends BaseApp {
|
||||
}
|
||||
|
||||
|
||||
private void bindToKey(final Event<?> event, int... keys)
|
||||
private void bindToKey(final BusEvent<?> event, int... keys)
|
||||
{
|
||||
getInput().bindKey(new KeyStroke(keys), new Runnable() {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.rogue.events;
|
||||
|
||||
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.BusEvent;
|
||||
import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent;
|
||||
* @author MightyPork
|
||||
*/
|
||||
@SingleReceiverEvent
|
||||
public class ActionRequest implements Event<ActionRequest.Listener> {
|
||||
public class ActionRequest extends BusEvent<ActionRequest.Listener> {
|
||||
|
||||
private final RequestType type;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package mightypork.rogue.screens;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.events.ScreenRequestEvent;
|
||||
import mightypork.gamecore.control.events.requests.ScreenRequestEvent;
|
||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||
import mightypork.gamecore.gui.screens.Overlay;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
@@ -62,7 +62,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return Integer.MAX_VALUE - 1; // let FPS go on top
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package mightypork.rogue.screens;
|
||||
|
||||
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.BusEvent;
|
||||
|
||||
|
||||
/**
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class CrossfadeRequest implements Event<CrossfadeRequest.Listener> {
|
||||
public class CrossfadeRequest extends BusEvent<CrossfadeRequest.Listener> {
|
||||
|
||||
private final String screen;
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class FpsOverlay extends Overlay {
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
+5
-3
@@ -7,13 +7,15 @@ import mightypork.gamecore.gui.components.painters.ImagePainter;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.screens.gamescreen.gui.HeartBar;
|
||||
import mightypork.rogue.screens.gamescreen.gui.NavItemSlot;
|
||||
import mightypork.util.constraints.num.Num;
|
||||
import mightypork.util.constraints.rect.Rect;
|
||||
|
||||
|
||||
public class GameGui extends ScreenLayer {
|
||||
public class HudLayer extends ScreenLayer {
|
||||
|
||||
public GameGui(Screen screen)
|
||||
public HudLayer(Screen screen)
|
||||
{
|
||||
super(screen);
|
||||
|
||||
@@ -48,7 +50,7 @@ public class GameGui extends ScreenLayer {
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
@@ -1,18 +1,60 @@
|
||||
package mightypork.rogue.screens.gamescreen;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.screens.LayeredScreen;
|
||||
import mightypork.rogue.Paths;
|
||||
import mightypork.rogue.world.MapGenerator;
|
||||
import mightypork.rogue.world.World;
|
||||
import mightypork.util.ion.Ion;
|
||||
|
||||
|
||||
public class ScreenGame extends LayeredScreen {
|
||||
|
||||
public ScreenGame(AppAccess app)
|
||||
{
|
||||
public ScreenGame(AppAccess app) {
|
||||
super(app);
|
||||
|
||||
addLayer(new WorldLayer(this)); //TODO with provided world
|
||||
addLayer(new GameGui(this));
|
||||
addLayer(new WorldLayer(this, obtainWorld())); //TODO with provided world
|
||||
addLayer(new HudLayer(this));
|
||||
}
|
||||
|
||||
|
||||
private World obtainWorld()
|
||||
{
|
||||
|
||||
// FIXME just temporary test here
|
||||
|
||||
final Random rand = new Random();
|
||||
final File f = new File(Paths.WORKDIR, "test-world.ion");
|
||||
|
||||
// SAVE
|
||||
|
||||
World world = MapGenerator.createWorld(rand.nextLong());
|
||||
addChildClient(world);
|
||||
|
||||
try {
|
||||
Ion.toFile(f, world);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// LOAD
|
||||
|
||||
// final World w;
|
||||
//
|
||||
// try {
|
||||
// world = Ion.fromFile(f, World.class);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// System.exit(1);
|
||||
// return;
|
||||
// }
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
package mightypork.rogue.screens.gamescreen;
|
||||
|
||||
|
||||
import mightypork.rogue.world.PlayerControl;
|
||||
import mightypork.rogue.world.World;
|
||||
import mightypork.rogue.world.WorldPos;
|
||||
import mightypork.rogue.world.entity.Entity;
|
||||
import mightypork.rogue.world.entity.models.EntityMoveListener;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
import mightypork.util.math.Polar;
|
||||
import mightypork.util.math.Calc.Deg;
|
||||
import mightypork.gamecore.control.events.KeyEvent;
|
||||
import mightypork.gamecore.control.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
|
||||
|
||||
public class WRBasicControls extends WorldRenderComponent implements KeyEvent.Listener, MouseButtonEvent.Listener, EntityMoveListener {
|
||||
|
||||
private final PlayerControl pc;
|
||||
|
||||
|
||||
public WRBasicControls(World world) {
|
||||
super(world);
|
||||
pc = world.getPlayerControl();
|
||||
pc.addMoveListener(this);
|
||||
}
|
||||
|
||||
|
||||
private void handleHeldKey()
|
||||
{
|
||||
if (InputSystem.isKeyDown(Keys.LEFT)) {
|
||||
pc.walkWest();
|
||||
} else if (InputSystem.isKeyDown(Keys.RIGHT)) {
|
||||
pc.walkEast();
|
||||
} else if (InputSystem.isKeyDown(Keys.UP)) {
|
||||
pc.walkNorth();
|
||||
} else if (InputSystem.isKeyDown(Keys.DOWN)) {
|
||||
pc.walkSouth();
|
||||
}
|
||||
|
||||
if(InputSystem.isMouseButtonDown(0)) {
|
||||
walkByMouse(InputSystem.getMousePos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStepFinished(Entity entity, World world, Level level)
|
||||
{
|
||||
handleHeldKey();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPathFinished(Entity entity, World world, Level level)
|
||||
{
|
||||
handleHeldKey();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPathInterrupted(Entity entity, World world, Level level)
|
||||
{
|
||||
handleHeldKey();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(MouseButtonEvent event)
|
||||
{
|
||||
if (!event.isDown()) return;
|
||||
|
||||
walkByMouse(event.getPos());
|
||||
}
|
||||
|
||||
|
||||
private void walkByMouse(Vect mouse)
|
||||
{
|
||||
|
||||
WorldPos clicked = toWorldPos(mouse);
|
||||
WorldPos plpos = pc.getPos();
|
||||
|
||||
Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y);
|
||||
|
||||
int dir = Deg.round90(p.getAngleDeg()) / 90;
|
||||
|
||||
switch (dir) {
|
||||
case 0:
|
||||
pc.walkEast();
|
||||
return;
|
||||
|
||||
case 1:
|
||||
pc.walkSouth();
|
||||
return;
|
||||
|
||||
case 2:
|
||||
pc.walkWest();
|
||||
return;
|
||||
|
||||
case 3:
|
||||
pc.walkNorth();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(KeyEvent event)
|
||||
{
|
||||
handleHeldKey();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +1,31 @@
|
||||
package mightypork.rogue.screens.gamescreen;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.gui.components.InputComponent;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.rogue.Paths;
|
||||
import mightypork.rogue.world.MapGenerator;
|
||||
import mightypork.rogue.screens.gamescreen.world.MIPKeyWalk;
|
||||
import mightypork.rogue.screens.gamescreen.world.MIPMouseWalk;
|
||||
import mightypork.rogue.screens.gamescreen.world.MapView;
|
||||
import mightypork.rogue.world.World;
|
||||
import mightypork.util.constraints.num.Num;
|
||||
import mightypork.util.ion.Ion;
|
||||
|
||||
|
||||
public class WorldLayer extends ScreenLayer {
|
||||
|
||||
private World world;
|
||||
private InputComponent worldView;
|
||||
private MapView worldView;
|
||||
|
||||
|
||||
public WorldLayer(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
// FIXME just temporary test here
|
||||
|
||||
final Random rand = new Random();
|
||||
final File f = new File(Paths.WORKDIR, "test-world.ion");
|
||||
|
||||
// SAVE
|
||||
|
||||
world = MapGenerator.createWorld(rand.nextLong());
|
||||
updated.add(world);
|
||||
|
||||
try {
|
||||
Ion.toFile(f, world);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1); // fail
|
||||
return;
|
||||
}
|
||||
|
||||
// LOAD
|
||||
|
||||
// final World w;
|
||||
//
|
||||
// try {
|
||||
// world = Ion.fromFile(f, World.class);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// System.exit(1);
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
public WorldLayer(Screen screen, World world) {
|
||||
super(screen);
|
||||
|
||||
// render component
|
||||
|
||||
worldView = new WRBasicControls(world);
|
||||
worldView = new MapView(world);
|
||||
|
||||
// map input plugins
|
||||
worldView.addPlugin(new MIPKeyWalk());
|
||||
worldView.addPlugin(new MIPMouseWalk());
|
||||
|
||||
|
||||
// size of lower navbar
|
||||
final Num lownav = root.width().min(root.height()).max(700).perc(7);
|
||||
@@ -69,7 +36,7 @@ public class WorldLayer extends ScreenLayer {
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return -1; // stay down
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package mightypork.rogue.screens.gamescreen;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.components.InputComponent;
|
||||
import mightypork.rogue.world.World;
|
||||
import mightypork.rogue.world.WorldPos;
|
||||
import mightypork.rogue.world.WorldRenderer;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
|
||||
|
||||
public class WorldRenderComponent extends InputComponent {
|
||||
|
||||
protected final WorldRenderer worldRenderer;
|
||||
protected final World world;
|
||||
|
||||
|
||||
public WorldRenderComponent(World world) {
|
||||
this.world = world;
|
||||
this.worldRenderer = new WorldRenderer(world, this, 8, 6, 72);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void renderComponent()
|
||||
{
|
||||
worldRenderer.render();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateLayout()
|
||||
{
|
||||
worldRenderer.poll(); // update sizing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get tile coord at a screen position
|
||||
*/
|
||||
public WorldPos toWorldPos(Vect pos)
|
||||
{
|
||||
return worldRenderer.getClickedTile(pos);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.rogue.screens.gamescreen;
|
||||
package mightypork.rogue.screens.gamescreen.gui;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.AlignX;
|
||||
+4
-3
@@ -1,7 +1,8 @@
|
||||
package mightypork.rogue.screens.gamescreen;
|
||||
package mightypork.rogue.screens.gamescreen.gui;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.events.MouseMotionEvent;
|
||||
import mightypork.gamecore.control.events.input.MouseMotionEvent;
|
||||
import mightypork.gamecore.control.events.input.MouseMotionListener;
|
||||
import mightypork.gamecore.gui.components.ClickableComponent;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.gamecore.render.textures.TxQuad;
|
||||
@@ -15,7 +16,7 @@ import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.math.Easing;
|
||||
|
||||
|
||||
public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.Listener, Updateable {
|
||||
public class NavItemSlot extends ClickableComponent implements MouseMotionListener, Updateable {
|
||||
|
||||
private final TxQuad image;
|
||||
private final TxQuad frame;
|
||||
@@ -0,0 +1,45 @@
|
||||
package mightypork.rogue.screens.gamescreen.world;
|
||||
|
||||
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.rogue.world.PlayerControl;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
|
||||
|
||||
public class MIPKeyWalk implements MapInteractionPlugin {
|
||||
|
||||
@Override
|
||||
public void onStepEnd(MapView wv, PlayerControl player)
|
||||
{
|
||||
walkByKey(player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(MapView wv, PlayerControl player, Vect mouse)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onKey(MapView wv, PlayerControl player, int key)
|
||||
{
|
||||
walkByKey(player);
|
||||
}
|
||||
|
||||
|
||||
private void walkByKey(PlayerControl player)
|
||||
{
|
||||
if (InputSystem.isKeyDown(Keys.LEFT)) {
|
||||
player.goWest();
|
||||
} else if (InputSystem.isKeyDown(Keys.RIGHT)) {
|
||||
player.goEast();
|
||||
} else if (InputSystem.isKeyDown(Keys.UP)) {
|
||||
player.goNorth();
|
||||
} else if (InputSystem.isKeyDown(Keys.DOWN)) {
|
||||
player.goSouth();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package mightypork.rogue.screens.gamescreen.world;
|
||||
|
||||
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.rogue.world.PlayerControl;
|
||||
import mightypork.rogue.world.WorldPos;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
import mightypork.util.math.Polar;
|
||||
import mightypork.util.math.Calc.Deg;
|
||||
|
||||
|
||||
public class MIPMouseWalk implements MapInteractionPlugin {
|
||||
|
||||
@Override
|
||||
public void onStepEnd(MapView wv, PlayerControl player)
|
||||
{
|
||||
if (InputSystem.isMouseButtonDown(0)) {
|
||||
// walk by holding btn
|
||||
onClick(wv, player, InputSystem.getMousePos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(MapView wv, PlayerControl player, Vect mouse)
|
||||
{
|
||||
WorldPos plpos = player.getPos();
|
||||
WorldPos clicked = wv.toWorldPos(mouse);
|
||||
|
||||
Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y);
|
||||
|
||||
int dir = Deg.round90(p.getAngleDeg()) / 90;
|
||||
|
||||
switch (dir) {
|
||||
case 0:
|
||||
player.goEast();
|
||||
return;
|
||||
|
||||
case 1:
|
||||
player.goSouth();
|
||||
return;
|
||||
|
||||
case 2:
|
||||
player.goWest();
|
||||
return;
|
||||
|
||||
case 3:
|
||||
player.goNorth();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onKey(MapView wv, PlayerControl player, int key)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package mightypork.rogue.screens.gamescreen.world;
|
||||
|
||||
|
||||
import mightypork.rogue.world.PlayerControl;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
|
||||
|
||||
public interface MapInteractionPlugin {
|
||||
|
||||
void onStepEnd(MapView wv, PlayerControl player);
|
||||
|
||||
|
||||
void onClick(MapView wv, PlayerControl player, Vect mouse);
|
||||
|
||||
|
||||
void onKey(MapView wv, PlayerControl player, int key);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package mightypork.rogue.screens.gamescreen.world;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.control.events.input.KeyEvent;
|
||||
import mightypork.gamecore.control.events.input.KeyListener;
|
||||
import mightypork.gamecore.control.events.input.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.events.input.MouseButtonListener;
|
||||
import mightypork.gamecore.gui.components.InputComponent;
|
||||
import mightypork.rogue.world.PlayerControl;
|
||||
import mightypork.rogue.world.World;
|
||||
import mightypork.rogue.world.WorldPos;
|
||||
import mightypork.rogue.world.WorldRenderer;
|
||||
import mightypork.rogue.world.entity.Entity;
|
||||
import mightypork.rogue.world.entity.models.EntityMoveListener;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
|
||||
|
||||
public class MapView extends InputComponent implements KeyListener, MouseButtonListener, EntityMoveListener {
|
||||
|
||||
protected final WorldRenderer worldRenderer;
|
||||
protected final World world;
|
||||
private final PlayerControl pc;
|
||||
|
||||
private final Set<MapInteractionPlugin> plugins = new HashSet<>();
|
||||
|
||||
|
||||
public MapView(World world) {
|
||||
this.world = world;
|
||||
this.worldRenderer = new WorldRenderer(world, this, 8, 6, 72);
|
||||
pc = world.getPlayerControl();
|
||||
pc.addMoveListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void renderComponent()
|
||||
{
|
||||
worldRenderer.render();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateLayout()
|
||||
{
|
||||
worldRenderer.poll(); // update sizing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get tile coord at a screen position
|
||||
*
|
||||
* @param pos position on screen (px)
|
||||
* @return position on map (tiles)
|
||||
*/
|
||||
public WorldPos toWorldPos(Vect pos)
|
||||
{
|
||||
return worldRenderer.getClickedTile(pos);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStepFinished(Entity entity, World world, Level level)
|
||||
{
|
||||
for (MapInteractionPlugin p : plugins) {
|
||||
p.onStepEnd(this, pc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPathFinished(Entity entity, World world, Level level)
|
||||
{
|
||||
for (MapInteractionPlugin p : plugins) {
|
||||
p.onStepEnd(this, pc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPathInterrupted(Entity entity, World world, Level level)
|
||||
{
|
||||
for (MapInteractionPlugin p : plugins) {
|
||||
p.onStepEnd(this, pc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(MouseButtonEvent event)
|
||||
{
|
||||
if (!event.isOver(this)) return;
|
||||
|
||||
if (!event.isUp()) return; // only btn-release evt
|
||||
|
||||
for (MapInteractionPlugin p : plugins) {
|
||||
p.onClick(this, pc, event.getPos());
|
||||
}
|
||||
|
||||
event.consume(); // only our clicks.
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(KeyEvent event)
|
||||
{
|
||||
if (!event.isDown()) return;
|
||||
|
||||
for (MapInteractionPlugin p : plugins) {
|
||||
p.onKey(this, pc, event.getKey());
|
||||
}
|
||||
|
||||
// don't consume key events, can be useful for others.
|
||||
}
|
||||
|
||||
|
||||
public void addPlugin(MapInteractionPlugin plugin)
|
||||
{
|
||||
plugins.add(plugin);
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class MenuLayer extends ScreenLayer {
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class LayerColor extends ScreenLayer {
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ package mightypork.rogue.screens.test_cat_sound;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.control.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.events.input.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.events.input.MouseButtonListener;
|
||||
import mightypork.gamecore.gui.AlignX;
|
||||
import mightypork.gamecore.gui.components.painters.ImagePainter;
|
||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||
@@ -21,7 +22,7 @@ import mightypork.util.math.Easing;
|
||||
import mightypork.util.math.color.Color;
|
||||
|
||||
|
||||
public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.Listener {
|
||||
public class LayerFlyingCat extends ScreenLayer implements MouseButtonListener {
|
||||
|
||||
private final NumAnimated size = new NumAnimated(300, Easing.SINE_BOTH);
|
||||
private final VectAnimated cat_position = VectAnimated.makeVar(Easing.ELASTIC_OUT);
|
||||
@@ -99,7 +100,7 @@ public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.List
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class LayerTestGradient extends ScreenLayer {
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
public int getZIndex()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mightypork.rogue.world;
|
||||
|
||||
|
||||
import mightypork.rogue.world.entity.models.EntityMoveListener;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
|
||||
|
||||
public class PlayerControl {
|
||||
@@ -9,50 +10,55 @@ public class PlayerControl {
|
||||
private final World world;
|
||||
|
||||
|
||||
public PlayerControl(World w)
|
||||
{
|
||||
public PlayerControl(World w) {
|
||||
this.world = w;
|
||||
}
|
||||
|
||||
|
||||
public void walkNorth()
|
||||
public void goNorth()
|
||||
{
|
||||
world.playerEntity.addStep(PathStep.NORTH);
|
||||
world.getPlayerEntity().addStep(PathStep.NORTH);
|
||||
}
|
||||
|
||||
|
||||
public void walkSouth()
|
||||
public void goSouth()
|
||||
{
|
||||
world.playerEntity.addStep(PathStep.SOUTH);
|
||||
world.getPlayerEntity().addStep(PathStep.SOUTH);
|
||||
}
|
||||
|
||||
|
||||
public void walkEast()
|
||||
public void goEast()
|
||||
{
|
||||
world.playerEntity.addStep(PathStep.EAST);
|
||||
world.getPlayerEntity().addStep(PathStep.EAST);
|
||||
}
|
||||
|
||||
|
||||
public void walkWest()
|
||||
public void goWest()
|
||||
{
|
||||
world.playerEntity.addStep(PathStep.WEST);
|
||||
world.getPlayerEntity().addStep(PathStep.WEST);
|
||||
}
|
||||
|
||||
|
||||
public void addMoveListener(EntityMoveListener eml)
|
||||
{
|
||||
world.playerEntity.addMoveListener(eml);
|
||||
world.getPlayerEntity().addMoveListener(eml);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public WorldPos getPos()
|
||||
{
|
||||
return world.playerEntity.getPosition();
|
||||
return world.getPlayerEntity().getPosition();
|
||||
}
|
||||
|
||||
|
||||
public void walk(PathStep step)
|
||||
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
world.playerEntity.addStep(step);
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
public Level getLevel()
|
||||
{
|
||||
return world.getCurrentLevel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public class World implements IonBundled, Updateable {
|
||||
|
||||
private final ArrayList<Level> levels = new ArrayList<>();
|
||||
|
||||
final PlayerInfo player = new PlayerInfo();
|
||||
Entity playerEntity;
|
||||
private final PlayerInfo playerInfo = new PlayerInfo();
|
||||
private Entity playerEntity;
|
||||
|
||||
private final PlayerControl control = new PlayerControl(this);
|
||||
|
||||
@@ -36,9 +36,9 @@ public class World implements IonBundled, Updateable {
|
||||
seed = in.get("seed", 0L);
|
||||
eid = in.get("next_eid", 0);
|
||||
in.loadSequence("levels", levels);
|
||||
in.loadBundled("player", player);
|
||||
in.loadBundled("player", playerInfo);
|
||||
|
||||
playerEntity = levels.get(player.getLevel()).getEntity(player.getEID());
|
||||
playerEntity = levels.get(playerInfo.getLevel()).getEntity(playerInfo.getEID());
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class World implements IonBundled, Updateable {
|
||||
out.put("seed", seed);
|
||||
out.put("next_eid", eid);
|
||||
out.putSequence("levels", levels);
|
||||
out.putBundled("player", player);
|
||||
out.putBundled("player", playerInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public class World implements IonBundled, Updateable {
|
||||
|
||||
public void createPlayer(int x, int y, int level)
|
||||
{
|
||||
if (player.isInitialized()) {
|
||||
if (playerInfo.isInitialized()) {
|
||||
throw new RuntimeException("Player already created.");
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ public class World implements IonBundled, Updateable {
|
||||
|
||||
playerEntity = Entities.PLAYER.createEntity(playerEid, new WorldPos(x, y));
|
||||
|
||||
player.setLevel(level);
|
||||
player.setEID(playerEid);
|
||||
playerInfo.setLevel(level);
|
||||
playerInfo.setEID(playerEid);
|
||||
|
||||
levels.get(level).addEntity(playerEntity);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class World implements IonBundled, Updateable {
|
||||
|
||||
public Level getCurrentLevel()
|
||||
{
|
||||
return levels.get(player.getLevel());
|
||||
return levels.get(playerInfo.getLevel());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import mightypork.util.constraints.rect.RectConst;
|
||||
import mightypork.util.constraints.rect.caching.RectCache;
|
||||
import mightypork.util.constraints.rect.proxy.RectProxy;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
import mightypork.util.constraints.vect.VectConst;
|
||||
import mightypork.util.constraints.vect.caching.VectCache;
|
||||
import mightypork.util.math.color.RGB;
|
||||
|
||||
@@ -42,12 +43,14 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
private final Rect topShadow;
|
||||
private final Rect bottomShadow;
|
||||
|
||||
private TileRenderContext trc;
|
||||
|
||||
|
||||
public WorldRenderer(World world, Rect viewport, int xTiles, int yTiles, int minTileSize) {
|
||||
super(viewport);
|
||||
|
||||
this.world = world;
|
||||
this.player = world.playerEntity;
|
||||
this.player = world.getPlayerEntity();
|
||||
|
||||
tileSize = width().div(xTiles).min(height().div(yTiles)).max(minTileSize).cached();
|
||||
|
||||
@@ -62,11 +65,11 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
topShadow = topEdge().growDown(grY);
|
||||
bottomShadow = bottomEdge().growUp(grY);
|
||||
|
||||
setupMapRect();
|
||||
rebuildTiles();
|
||||
}
|
||||
|
||||
|
||||
private void setupMapRect()
|
||||
private void rebuildTiles()
|
||||
{
|
||||
Level level = world.getCurrentLevel();
|
||||
|
||||
@@ -74,29 +77,30 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
activeLevel = level;
|
||||
|
||||
mapRect = Rect.make(vpCenter, tileSize.mul(level.getWidth()), tileSize.mul(level.getHeight())).cached();
|
||||
|
||||
trc = new TileRenderContext(activeLevel, mapRect);
|
||||
}
|
||||
|
||||
|
||||
private RectConst getCurrentDrawRect()
|
||||
private int[] getOffset()
|
||||
{
|
||||
|
||||
WorldPos pos = player.getPosition();
|
||||
final double playerX = pos.getVisualX();
|
||||
final double playerY = pos.getVisualY();
|
||||
|
||||
double ts = tileSize.value();
|
||||
|
||||
final RectConst drawRect = mapRect.move(-ts * playerX, -ts * playerY).freeze();
|
||||
|
||||
return drawRect;
|
||||
return new int[]{(int) (-ts * playerX), (int) (-ts * playerY)};
|
||||
}
|
||||
|
||||
|
||||
public void render()
|
||||
{
|
||||
setupMapRect();
|
||||
int[] off = getOffset();
|
||||
System.out.println(trc.getRectForTile(10, 10));
|
||||
|
||||
final TileRenderContext rc = new TileRenderContext(activeLevel, getCurrentDrawRect());
|
||||
Render.pushMatrix();
|
||||
Render.translate(off[0], off[1]);
|
||||
|
||||
// tiles to render
|
||||
final WorldPos pos = player.getPosition();
|
||||
@@ -117,9 +121,9 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
Render.enterBatchTexturedQuadMode(Res.getTexture("tiles16"));
|
||||
}
|
||||
|
||||
for (rc.y = y1; rc.y <= y2; rc.y++) {
|
||||
for (rc.x = x1; rc.x <= x2; rc.x++) {
|
||||
rc.renderTile();
|
||||
for (trc.y = y1; trc.y <= y2; trc.y++) {
|
||||
for (trc.x = x1; trc.x <= x2; trc.x++) {
|
||||
trc.renderTile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,9 +133,9 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
|
||||
// === ITEMS ON TILES ===
|
||||
|
||||
for (rc.y = y1; rc.y <= y2; rc.y++) {
|
||||
for (rc.x = x1; rc.x <= x2; rc.x++) {
|
||||
rc.renderItems();
|
||||
for (trc.y = y1; trc.y <= y2; trc.y++) {
|
||||
for (trc.x = x1; trc.x <= x2; trc.x++) {
|
||||
trc.renderItems();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,9 +150,11 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
if (x < x1 - ts || x > x2 + ts) continue;
|
||||
if (y < y1 - ts || y > y2 + ts) continue;
|
||||
|
||||
e.render(rc);
|
||||
e.render(trc);
|
||||
}
|
||||
|
||||
Render.popMatrix();
|
||||
|
||||
// === OVERLAY SHADOW ===
|
||||
|
||||
Render.quadGradH(leftShadow, RGB.BLACK, RGB.NONE);
|
||||
@@ -161,9 +167,9 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
|
||||
public WorldPos getClickedTile(Vect clickPos)
|
||||
{
|
||||
RectConst drawRect = getCurrentDrawRect();
|
||||
Vect v = clickPos.sub(drawRect.origin());
|
||||
int ts = (int)tileSize.value();
|
||||
int[] off = getOffset();
|
||||
Vect v = clickPos.sub(mapRect.origin().add(off[0], off[1]));
|
||||
int ts = (int) tileSize.value();
|
||||
return new WorldPos(v.xi() / ts, v.yi() / ts);
|
||||
}
|
||||
|
||||
@@ -176,6 +182,8 @@ public class WorldRenderer extends RectProxy implements Pollable {
|
||||
tileSize.poll();
|
||||
|
||||
mapRect.poll();
|
||||
|
||||
rebuildTiles();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mightypork.rogue.world.level.render;
|
||||
|
||||
import mightypork.rogue.world.level.MapAccess;
|
||||
import mightypork.util.constraints.rect.Rect;
|
||||
import mightypork.util.constraints.rect.RectConst;
|
||||
import mightypork.util.constraints.rect.builders.TiledRect;
|
||||
|
||||
|
||||
@@ -12,18 +13,33 @@ public abstract class MapRenderContext {
|
||||
protected final TiledRect tiler;
|
||||
private final Rect mapRect;
|
||||
|
||||
private RectConst tileRects[][];
|
||||
|
||||
public MapRenderContext(MapAccess map, Rect drawArea)
|
||||
{
|
||||
|
||||
public MapRenderContext(MapAccess map, Rect drawArea) {
|
||||
this.map = map;
|
||||
this.tiler = drawArea.tiles(map.getWidth(), map.getHeight());
|
||||
this.mapRect = drawArea;
|
||||
|
||||
tileRects = new RectConst[map.getHeight()][map.getWidth()];
|
||||
|
||||
rebuildTileRects();
|
||||
}
|
||||
|
||||
|
||||
public void rebuildTileRects()
|
||||
{
|
||||
for(int y=0;y<map.getHeight();y++) {
|
||||
for(int x=0;x<map.getWidth();x++) {
|
||||
tileRects[y][x] = tiler.tile(x, y).freeze();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Rect getRectForTile(int x, int y)
|
||||
{
|
||||
return tiler.tile(x, y);
|
||||
return tileRects[y][x];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user