- Added final keyword wherever possible
- Improved some font code
This commit is contained in:
Ondřej Hruška
2014-04-06 20:53:52 +02:00
parent da67300522
commit e2b6752efb
93 changed files with 805 additions and 743 deletions
+12 -14
View File
@@ -16,7 +16,6 @@ import mightypork.rogue.gui.screens.test_cat_sound.ScreenTestCat;
import mightypork.rogue.gui.screens.test_font.ScreenTestFont;
import mightypork.rogue.input.InputSystem;
import mightypork.rogue.input.KeyStroke;
import mightypork.rogue.loading.DeferredLoader;
import mightypork.rogue.render.DisplaySystem;
import mightypork.rogue.sound.SoundSystem;
import mightypork.utils.control.bus.EventBus;
@@ -62,7 +61,7 @@ public class App implements AppAccess {
try {
inst.start();
} catch (Throwable t) {
} catch (final Throwable t) {
onCrash(t);
}
@@ -124,7 +123,7 @@ public class App implements AppAccess {
/*
* Setup logging
*/
LogInstance log = Log.create("runtime", Paths.LOGS, 10);
final LogInstance log = Log.create("runtime", Paths.LOGS, 10);
log.enable(Config.LOGGING_ENABLED);
log.enableSysout(Config.LOG_TO_STDOUT);
@@ -153,14 +152,6 @@ public class App implements AppAccess {
soundSystem = new SoundSystem(this);
soundSystem.setMasterVolume(1);
/*
* Load resources
*/
Log.f1("Registering resources...");
bus().subscribe(new DeferredLoader(this));
Res.load(this);
/*
* Input
*/
@@ -168,6 +159,13 @@ public class App implements AppAccess {
inputSystem = new InputSystem(this);
setupGlobalKeystrokes();
/*
* Load resources
*/
Log.f1("Loading resources...");
Res.load(this);
/*
* Screen registry
*/
@@ -179,7 +177,7 @@ public class App implements AppAccess {
* Prepare main loop
*/
Log.f1("Preparing main loop...");
ArrayList<Runnable> loopTasks = new ArrayList<Runnable>();
final ArrayList<Runnable> loopTasks = new ArrayList<Runnable>();
loopTasks.add(new Runnable() {
@@ -304,7 +302,7 @@ public class App implements AppAccess {
fileLock.release();
randomAccessFile.close();
lockFile.delete();
} catch (Exception e) {
} catch (final Exception e) {
System.err.println("Unable to remove lock file.");
e.printStackTrace();
}
@@ -313,7 +311,7 @@ public class App implements AppAccess {
return true;
}
} catch (Exception e) {
} catch (final Exception e) {
System.err.println("Unable to create and/or lock file.");
e.printStackTrace();
}
+1 -1
View File
@@ -14,7 +14,7 @@ import mightypork.utils.control.bus.EventBus;
*/
public class AppAdapter implements AppAccess {
private AppAccess app;
private final AppAccess app;
public AppAdapter(AppAccess app) {
+1 -2
View File
@@ -33,7 +33,7 @@ public class Config {
{
Log.f2("Initializing configuration manager.");
String comment = Const.APP_NAME + " config file";
final String comment = Const.APP_NAME + " config file";
mgr = new PropertyManager(Paths.CONFIG, comment);
@@ -76,7 +76,6 @@ public class Config {
public static boolean LOG_TO_STDOUT = true;
public static boolean SINGLE_INSTANCE = true;
public static boolean LOG_FONTS = false;
public static boolean LOG_BUS = false;
}
+4 -4
View File
@@ -18,8 +18,8 @@ import mightypork.utils.control.timing.TimerDelta;
public class MainLoop extends Subsystem implements ActionRequest.Listener, MainLoopTaskRequest.Listener {
private Queue<Runnable> taskQueue = new ConcurrentLinkedQueue<Runnable>();
private List<Runnable> regularTasks;
private final Queue<Runnable> taskQueue = new ConcurrentLinkedQueue<Runnable>();
private final List<Runnable> regularTasks;
public MainLoop(App app, ArrayList<Runnable> loopTasks) {
@@ -42,7 +42,7 @@ public class MainLoop extends Subsystem implements ActionRequest.Listener, MainL
bus().send(new UpdateEvent(timer.getDelta()));
for (Runnable r : regularTasks) {
for (final Runnable r : regularTasks) {
r.run();
}
@@ -113,7 +113,7 @@ public class MainLoop extends Subsystem implements ActionRequest.Listener, MainL
@Override
public void queueTask(Runnable request)
public synchronized void queueTask(Runnable request)
{
taskQueue.add(request);
}
+7 -4
View File
@@ -5,13 +5,14 @@ import mightypork.rogue.fonts.DeferredFont;
import mightypork.rogue.fonts.DeferredFont.FontStyle;
import mightypork.rogue.fonts.FontBank;
import mightypork.rogue.fonts.GLFont;
import mightypork.rogue.loading.AsyncResourceLoader;
import mightypork.rogue.sound.SoundBank;
import mightypork.rogue.sound.players.EffectPlayer;
import mightypork.rogue.sound.players.LoopPlayer;
import mightypork.rogue.texture.FilteredTexture.Filter;
import mightypork.rogue.texture.FilteredTexture.Wrap;
import mightypork.rogue.texture.TextureBank;
import mightypork.rogue.texture.TxQuad;
import mightypork.rogue.textures.TextureBank;
import mightypork.rogue.textures.TxQuad;
import mightypork.rogue.textures.FilteredTexture.Filter;
import mightypork.rogue.textures.FilteredTexture.Wrap;
import org.newdawn.slick.opengl.Texture;
@@ -40,6 +41,8 @@ public class Res {
if (initialized) return;
initialized = true;
AsyncResourceLoader.launch(app);
textures = new TextureBank(app);
sounds = new SoundBank(app);
fonts = new FontBank(app);
@@ -10,7 +10,8 @@ import mightypork.utils.control.bus.SingularEvent;
*
* @author MightyPork
*/
public class ActionRequest implements Event<ActionRequest.Listener>, SingularEvent {
@SingularEvent
public class ActionRequest implements Event<ActionRequest.Listener> {
private final RequestType type;
@@ -33,7 +34,7 @@ public class ActionRequest implements Event<ActionRequest.Listener>, SingularEve
*
* @param request
*/
public void requestAction(RequestType request);
void requestAction(RequestType request);
}
public static enum RequestType
@@ -74,7 +74,7 @@ public class KeyboardEvent implements Event<KeyboardEvent.Listener> {
*
* @param event event
*/
public void receive(KeyboardEvent event);
void receive(KeyboardEvent event);
}
@@ -10,7 +10,8 @@ import mightypork.utils.control.bus.SingularEvent;
*
* @author MightyPork
*/
public class MainLoopTaskRequest implements Event<MainLoopTaskRequest.Listener>, SingularEvent {
@SingularEvent
public class MainLoopTaskRequest implements Event<MainLoopTaskRequest.Listener> {
private final Runnable task;
@@ -33,6 +34,6 @@ public class MainLoopTaskRequest implements Event<MainLoopTaskRequest.Listener>,
*
* @param request
*/
public void queueTask(Runnable request);
void queueTask(Runnable request);
}
}
@@ -6,7 +6,7 @@ import mightypork.utils.math.coord.Coord;
/**
* Mouse button / wheel event
* Mouse button / wheel event triggered
*
* @author MightyPork
*/
@@ -114,6 +114,6 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
*
* @param event event
*/
public void receive(MouseButtonEvent event);
void receive(MouseButtonEvent event);
}
}
@@ -5,6 +5,11 @@ import mightypork.utils.control.bus.Event;
import mightypork.utils.math.coord.Coord;
/**
* Mouse moved
*
* @author MightyPork
*/
public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
private final Coord move;
@@ -48,7 +53,7 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
*
* @param event event
*/
public void receive(MouseMotionEvent event);
void receive(MouseMotionEvent event);
}
}
@@ -1,7 +1,7 @@
package mightypork.rogue.bus.events;
import mightypork.rogue.loading.Deferred;
import mightypork.rogue.loading.DeferredResource;
import mightypork.utils.control.bus.Event;
import mightypork.utils.control.bus.SingularEvent;
@@ -11,12 +11,13 @@ import mightypork.utils.control.bus.SingularEvent;
*
* @author MightyPork
*/
public class ResourceLoadRequest implements Event<ResourceLoadRequest.Listener>, SingularEvent {
@SingularEvent
public class ResourceLoadRequest implements Event<ResourceLoadRequest.Listener> {
private final Deferred resource;
private final DeferredResource resource;
public ResourceLoadRequest(Deferred resource) {
public ResourceLoadRequest(DeferredResource resource) {
this.resource = resource;
}
@@ -34,6 +35,6 @@ public class ResourceLoadRequest implements Event<ResourceLoadRequest.Listener>,
*
* @param resource
*/
public void loadResource(Deferred resource);
void loadResource(DeferredResource resource);
}
}
@@ -45,6 +45,6 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
public interface Listener {
public void receive(ScreenChangeEvent event);
void receive(ScreenChangeEvent event);
}
}
@@ -5,7 +5,13 @@ import mightypork.utils.control.bus.Event;
import mightypork.utils.control.bus.SingularEvent;
public class ScreenRequestEvent implements Event<ScreenRequestEvent.Listener>, SingularEvent {
/**
* Request to change screen
*
* @author MightyPork
*/
@SingularEvent
public class ScreenRequestEvent implements Event<ScreenRequestEvent.Listener> {
private final String scrName;
@@ -23,7 +29,7 @@ public class ScreenRequestEvent implements Event<ScreenRequestEvent.Listener>, S
public interface Listener {
public void showScreen(String key);
void showScreen(String key);
}
}
+6 -5
View File
@@ -6,7 +6,7 @@ import java.awt.FontFormatException;
import java.io.IOException;
import java.io.InputStream;
import mightypork.rogue.loading.DeferredResource;
import mightypork.rogue.loading.BaseDeferredResource;
import mightypork.rogue.loading.MustLoadInMainThread;
import mightypork.utils.files.FileUtils;
import mightypork.utils.math.color.RGB;
@@ -18,7 +18,8 @@ import mightypork.utils.math.coord.Coord;
*
* @author MightyPork
*/
public class DeferredFont extends DeferredResource implements MustLoadInMainThread, GLFont {
@MustLoadInMainThread
public class DeferredFont extends BaseDeferredResource implements GLFont {
public static enum FontStyle
{
@@ -44,7 +45,7 @@ public class DeferredFont extends DeferredResource implements MustLoadInMainThre
*
* @param resourcePath resource to load
* @param extraChars extra chars (0-255 loaded by default)
* @param size size (pt)
* @param size size (px)
*/
public DeferredFont(String resourcePath, String extraChars, double size) {
this(resourcePath, extraChars, size, FontStyle.PLAIN, true);
@@ -85,7 +86,7 @@ public class DeferredFont extends DeferredResource implements MustLoadInMainThre
@Override
protected final void loadResource(String path) throws FontFormatException, IOException
{
Font awtFont = getAwtFont(path, (float) size, style.numeric);
final Font awtFont = getAwtFont(path, (float) size, style.numeric);
font = new SlickFont(awtFont, antiAlias, extraChars);
}
@@ -119,7 +120,7 @@ public class DeferredFont extends DeferredResource implements MustLoadInMainThre
} finally {
try {
if (in != null) in.close();
} catch (IOException e) {
} catch (final IOException e) {
//pass
}
}
+1 -1
View File
@@ -62,7 +62,7 @@ public class FontBank extends AppAdapter {
*/
public GLFont getFont(String key)
{
GLFont f = fonts.get(key);
final GLFont f = fonts.get(key);
if (f == null) {
Log.w("There's no font called " + key + "!");
+6 -6
View File
@@ -13,7 +13,7 @@ public interface GLFont {
* @param text string to draw
* @param color draw color
*/
abstract void draw(String text, RGB color);
void draw(String text, RGB color);
/**
@@ -24,7 +24,7 @@ public interface GLFont {
* @param startIndex first drawn character index
* @param endIndex last drawn character index
*/
abstract void draw(String text, RGB color, int startIndex, int endIndex);
void draw(String text, RGB color, int startIndex, int endIndex);
/**
@@ -32,7 +32,7 @@ public interface GLFont {
*
* @param str string to draw
*/
abstract void draw(String str);
void draw(String str);
/**
@@ -41,19 +41,19 @@ public interface GLFont {
* @param text string to check
* @return coord (width, height)
*/
abstract Coord getNeededSpace(String text);
Coord getNeededSpace(String text);
/**
* @return font height
*/
abstract int getHeight();
int getHeight();
/**
* @param text texted text
* @return space needed
*/
abstract int getWidth(String text);
int getWidth(String text);
}
+2 -2
View File
@@ -39,8 +39,8 @@ public class SlickFont implements GLFont {
{
if (chars == null) return null;
StringBuilder sb = new StringBuilder();
for (char c : chars.toCharArray()) {
final StringBuilder sb = new StringBuilder();
for (final char c : chars.toCharArray()) {
if (c <= 255) continue; // already included in default set
sb.append(c);
}
+1 -1
View File
@@ -20,7 +20,7 @@ public abstract class LayeredScreen extends Screen {
@Override
protected final void renderScreen()
{
for (ScreenLayer layer : layers) {
for (final ScreenLayer layer : layers) {
layer.render();
}
}
+4 -2
View File
@@ -8,6 +8,7 @@ import mightypork.rogue.bus.events.ScreenChangeEvent;
import mightypork.rogue.input.KeyBinder;
import mightypork.rogue.input.KeyBindingPool;
import mightypork.rogue.input.KeyStroke;
import mightypork.rogue.render.Renderable;
import mightypork.utils.control.interf.Destroyable;
import mightypork.utils.math.constraints.ConstraintContext;
import mightypork.utils.math.coord.Coord;
@@ -19,7 +20,7 @@ import mightypork.utils.math.coord.Rect;
*
* @author MightyPork
*/
public abstract class Screen extends ChildClient implements Destroyable, KeyBinder, ConstraintContext, ScreenChangeEvent.Listener {
public abstract class Screen extends ChildClient implements Renderable, Destroyable, KeyBinder, ConstraintContext, ScreenChangeEvent.Listener {
private final KeyBindingPool keybindings = new KeyBindingPool();
@@ -148,6 +149,7 @@ public abstract class Screen extends ChildClient implements Destroyable, KeyBind
}
@Override
public final void render()
{
if (!isActive()) return;
@@ -165,7 +167,7 @@ public abstract class Screen extends ChildClient implements Destroyable, KeyBind
// fix projection for changed size
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Coord s = disp().getSize();
final Coord s = disp().getSize();
glViewport(0, 0, s.xi(), s.yi());
glOrtho(0, s.x, s.y, 0, -1000, 1000);
+1 -1
View File
@@ -2,10 +2,10 @@ package mightypork.rogue.gui;
import mightypork.rogue.bus.ChildClient;
import mightypork.rogue.gui.constraints.Renderable;
import mightypork.rogue.input.KeyBinder;
import mightypork.rogue.input.KeyBindingPool;
import mightypork.rogue.input.KeyStroke;
import mightypork.rogue.render.Renderable;
import mightypork.utils.math.constraints.ConstraintContext;
import mightypork.utils.math.coord.Rect;
+1 -1
View File
@@ -32,7 +32,7 @@ public class ScreenRegistry extends Subsystem implements ScreenRequestEvent.List
{
Log.f3("Request to show screen \"" + key + "\"");
Screen toshow = screens.get(key);
final Screen toshow = screens.get(key);
if (toshow == null) throw new RuntimeException("Screen " + key + " not defined.");
if (active != null) active.setActive(false);
@@ -5,6 +5,7 @@ import java.util.LinkedList;
import mightypork.rogue.AppAccess;
import mightypork.rogue.bus.ChildClient;
import mightypork.rogue.render.Renderable;
import mightypork.utils.control.bus.EventBus;
import mightypork.utils.math.constraints.ConstraintContext;
import mightypork.utils.math.constraints.RectConstraint;
@@ -44,7 +45,7 @@ public class ElementHolder extends ChildClient implements ConstraintContext, Ren
@Override
public void render()
{
for (Renderable element : elements) {
for (final Renderable element : elements) {
element.render();
}
}
@@ -57,19 +58,6 @@ public class ElementHolder extends ChildClient implements ConstraintContext, Ren
}
// /**
// * Add element to the holder.
// *
// * @param elem
// */
// public void add(RenderableWithContext elem)
// {
// if (elem == null) return;
// elem.setContext(this);
// elements.add(elem);
// addChildClient(elem);
// }
/**
* Add element to the holder.
*
@@ -1,6 +1,7 @@
package mightypork.rogue.gui.constraints;
import mightypork.rogue.render.Renderable;
import mightypork.utils.math.constraints.ConstraintContext;
import mightypork.utils.math.constraints.SettableContext;
@@ -13,9 +14,5 @@ import mightypork.utils.math.constraints.SettableContext;
public interface RenderableWithContext extends Renderable, SettableContext {
@Override
public void render();
@Override
public void setContext(ConstraintContext context);
void setContext(ConstraintContext context);
}
@@ -19,23 +19,23 @@ import mightypork.utils.math.coord.Rect;
public class BouncyBox implements RenderableWithContext, Updateable, ConstraintContext {
private Random rand = new Random();
private final Random rand = new Random();
private ConstraintContext context;
private RectConstraint box;
private final RectConstraint box;
private AnimDouble pos = new AnimDouble(0, Easing.BOUNCE_OUT);
private final AnimDouble pos = new AnimDouble(0, Easing.BOUNCE_OUT);
public BouncyBox() {
// create box
NumConstraint side = c_height(this);
final NumConstraint side = c_height(this);
RectConstraint abox = c_box_sized(this, side, side);
// move
NumConstraint move_length = c_sub(c_width(this), side);
NumConstraint offset = c_mul(move_length, c_n(pos));
final NumConstraint move_length = c_sub(c_width(this), side);
final NumConstraint offset = c_mul(move_length, c_n(pos));
abox = c_move(abox, offset, c_n(0));
// add padding
@@ -22,12 +22,12 @@ public class LayerBouncyBoxes extends ScreenLayer {
super(screen);
// shrink screen rect by 8% on all sides
RectConstraint holder_rect = c_shrink(this, c_percent(c_height(this), c_n(8)));
final RectConstraint holder_rect = c_shrink(this, c_percent(c_height(this), c_n(8)));
addChildClient(layout = new RowHolder(screen, holder_rect, 16));
for (int i = 0; i < 16; i++) {
BouncyBox bbr = new BouncyBox();
final BouncyBox bbr = new BouncyBox();
layout.addRow(bbr);
boxes.add(bbr);
}
@@ -44,7 +44,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
public void goLeft()
{
for (BouncyBox bbr : boxes) {
for (final BouncyBox bbr : boxes) {
bbr.goLeft();
}
}
@@ -52,7 +52,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
public void goRight()
{
for (BouncyBox bbr : boxes) {
for (final BouncyBox bbr : boxes) {
bbr.goRight();
}
}
@@ -11,7 +11,7 @@ import org.lwjgl.input.Keyboard;
public class ScreenTestBouncy extends LayeredScreen {
private LayerBouncyBoxes layer;
private final LayerBouncyBoxes layer;
public ScreenTestBouncy(AppAccess app) {
@@ -23,15 +23,15 @@ import org.newdawn.slick.opengl.Texture;
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener {
private RectConstraint kittenbox;
private final RectConstraint kittenbox;
private AnimDouble s = new AnimDouble(400, Easing.SINE_BOTH);
private AnimDouble x = new AnimDouble(200, Easing.ELASTIC_OUT);
private AnimDouble y = new AnimDouble(200, Easing.ELASTIC_OUT);
private final AnimDouble s = new AnimDouble(400, Easing.SINE_BOTH);
private final AnimDouble x = new AnimDouble(200, Easing.ELASTIC_OUT);
private final AnimDouble y = new AnimDouble(200, Easing.ELASTIC_OUT);
private Random rand = new Random();
private final Random rand = new Random();
private Texture cat_tx = Res.getTexture("test.kitten");
private final Texture cat_tx = Res.getTexture("test.kitten");
public LayerFlyingCat(Screen screen) {
@@ -65,11 +65,11 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
{
if (!event.isDown()) return;
Coord pos = event.getPos();
final Coord pos = event.getPos();
double newSize = 200 + rand.nextInt(600);
final double newSize = 200 + rand.nextInt(600);
double t = 2;
final double t = 2;
s.fadeTo(newSize, t / 2D);
x.fadeTo(pos.x - newSize / 2D, t);
@@ -40,10 +40,10 @@ public class ScreenTestFont extends Screen {
@Override
protected void renderScreen()
{
GLFont font = Res.getFont("PolygonPixel_16");
final GLFont font = Res.getFont("PolygonPixel_16");
String s = "It works!";
double scale = getRect().height() / 50D;
final String s = "It works!";
final double scale = getRect().height() / 50D;
Render.pushState();
Render.translate(getRect().getCenter().sub(font.getNeededSpace(s).mul(scale).half()));
Render.scale(new Coord(scale));
+11 -11
View File
@@ -53,7 +53,7 @@ public class InputSystem extends Subsystem implements Updateable, KeyBinder {
Mouse.create();
Keyboard.create();
Keyboard.enableRepeatEvents(false);
} catch (LWJGLException e) {
} catch (final LWJGLException e) {
throw new RuntimeException("Failed to initialize input devices.", e);
}
}
@@ -83,8 +83,8 @@ public class InputSystem extends Subsystem implements Updateable, KeyBinder {
Display.processMessages();
Coord moveSum = Coord.zero();
Coord lastPos = Coord.zero();
final Coord moveSum = Coord.zero();
final Coord lastPos = Coord.zero();
boolean wasMouse = false;
while (Mouse.next()) {
@@ -106,11 +106,11 @@ public class InputSystem extends Subsystem implements Updateable, KeyBinder {
private void onMouseEvent(Coord moveSum, Coord lastPos)
{
int button = Mouse.getEventButton();
boolean down = Mouse.getEventButtonState();
Coord pos = new Coord(Mouse.getEventX(), Mouse.getEventY());
Coord move = new Coord(Mouse.getEventDX(), Mouse.getEventDY());
int wheeld = Mouse.getEventDWheel();
final int button = Mouse.getEventButton();
final boolean down = Mouse.getEventButtonState();
final Coord pos = new Coord(Mouse.getEventX(), Mouse.getEventY());
final Coord move = new Coord(Mouse.getEventDX(), Mouse.getEventDY());
final int wheeld = Mouse.getEventDWheel();
if (yAxisDown) {
flipScrY(pos);
@@ -128,9 +128,9 @@ public class InputSystem extends Subsystem implements Updateable, KeyBinder {
private void onKeyEvent()
{
int key = Keyboard.getEventKey();
boolean down = Keyboard.getEventKeyState();
char c = Keyboard.getEventCharacter();
final int key = Keyboard.getEventKey();
final boolean down = Keyboard.getEventKeyState();
final char c = Keyboard.getEventCharacter();
bus().queue(new KeyboardEvent(key, c, down));
}
+2 -2
View File
@@ -9,7 +9,7 @@ public interface KeyBinder {
* @param stroke trigger keystroke
* @param task handler
*/
abstract void bindKeyStroke(KeyStroke stroke, Runnable task);
void bindKeyStroke(KeyStroke stroke, Runnable task);
/**
@@ -17,6 +17,6 @@ public interface KeyBinder {
*
* @param stroke stroke
*/
abstract void unbindKeyStroke(KeyStroke stroke);
void unbindKeyStroke(KeyStroke stroke);
}
@@ -4,6 +4,11 @@ package mightypork.rogue.input;
import mightypork.rogue.bus.events.KeyboardEvent;
/**
* Key binding, trigger activated by a keystroke event
*
* @author MightyPork
*/
public class KeyBinding implements KeyboardEvent.Listener {
private final KeyStroke keystroke;
@@ -11,6 +16,10 @@ public class KeyBinding implements KeyboardEvent.Listener {
private boolean wasActive = false;
/**
* @param stroke trigger keystroke
* @param handler action
*/
public KeyBinding(KeyStroke stroke, Runnable handler) {
this.keystroke = stroke;
this.handler = handler;
@@ -19,12 +28,21 @@ public class KeyBinding implements KeyboardEvent.Listener {
}
/**
* Check for equality of keystroke
*
* @param stroke other keystroke
* @return true if keystrokes are equal (cannot co-exist)
*/
public boolean matches(KeyStroke stroke)
{
return this.keystroke.equals(stroke);
}
/**
* @param handler event handler
*/
public void setHandler(Runnable handler)
{
this.handler = handler;
@@ -28,7 +28,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
@Override
public void bindKeyStroke(KeyStroke stroke, Runnable task)
{
for (KeyBinding kb : bindings) {
for (final KeyBinding kb : bindings) {
if (kb.matches(stroke)) {
Log.w("Duplicate KeyBinding (" + stroke + "), using newest handler.");
kb.setHandler(task);
@@ -48,10 +48,10 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
@Override
public void unbindKeyStroke(KeyStroke stroke)
{
Iterator<KeyBinding> iter = bindings.iterator();
final Iterator<KeyBinding> iter = bindings.iterator();
while (iter.hasNext()) {
KeyBinding kb = iter.next();
final KeyBinding kb = iter.next();
if (kb.matches(stroke)) {
iter.remove();
return;
@@ -63,7 +63,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
@Override
public void receive(KeyboardEvent event)
{
for (KeyBinding kb : bindings) {
for (final KeyBinding kb : bindings) {
kb.receive(event);
}
}
+16 -5
View File
@@ -8,6 +8,11 @@ import java.util.Set;
import org.lwjgl.input.Keyboard;
/**
* Key stroke trigger
*
* @author MightyPork
*/
public class KeyStroke {
private final Set<Integer> keys = new LinkedHashSet<Integer>();
@@ -22,7 +27,7 @@ public class KeyStroke {
*/
public KeyStroke(boolean fallingEdge, int... keys) {
this.fallingEdge = fallingEdge;
for (int k : keys) {
for (final int k : keys) {
this.keys.add(k);
}
}
@@ -35,16 +40,19 @@ public class KeyStroke {
*/
public KeyStroke(int... keys) {
fallingEdge = false;
for (int k : keys) {
for (final int k : keys) {
this.keys.add(k);
}
}
/**
* @return true if the keystroke is currently satisfied (keys pressed)
*/
public boolean isActive()
{
boolean st = true;
for (int k : keys) {
for (final int k : keys) {
st &= Keyboard.isKeyDown(k);
}
@@ -68,7 +76,7 @@ public class KeyStroke {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof KeyStroke)) return false;
KeyStroke other = (KeyStroke) obj;
final KeyStroke other = (KeyStroke) obj;
if (keys == null) {
if (other.keys != null) return false;
@@ -88,7 +96,7 @@ public class KeyStroke {
String s = "(";
int cnt = 0;
Iterator<Integer> i = keys.iterator();
final Iterator<Integer> i = keys.iterator();
for (; i.hasNext(); cnt++) {
if (cnt > 0) s += "+";
s += Keyboard.getKeyName(i.next());
@@ -102,6 +110,9 @@ public class KeyStroke {
}
/**
* @return the key set
*/
public Set<Integer> getKeys()
{
return keys;
@@ -17,28 +17,29 @@ import mightypork.utils.logging.Log;
*
* @author MightyPork
*/
public class DeferredLoader extends Thread implements ResourceLoadRequest.Listener, Destroyable {
public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.Listener, Destroyable {
public static void launch(AppAccess app)
{
(new DeferredLoader(app)).start();
(new AsyncResourceLoader(app)).start();
}
private ExecutorService exs = Executors.newCachedThreadPool();
private final ExecutorService exs = Executors.newCachedThreadPool();
private LinkedBlockingQueue<Deferred> toLoad = new LinkedBlockingQueue<Deferred>();
private final LinkedBlockingQueue<DeferredResource> toLoad = new LinkedBlockingQueue<DeferredResource>();
private boolean stopped;
private AppAccess app;
private final AppAccess app;
public DeferredLoader(AppAccess app) {
public AsyncResourceLoader(AppAccess app) {
super("Deferred loader");
this.app = app;
app.bus().subscribe(this);
}
@Override
public void loadResource(Deferred resource)
public void loadResource(DeferredResource resource)
{
toLoad.add(resource);
}
@@ -47,10 +48,12 @@ public class DeferredLoader extends Thread implements ResourceLoadRequest.Listen
@Override
public void run()
{
Log.f3("Asynchronous resource loader started.");
while (!stopped) {
try {
final Deferred def = toLoad.take();
final DeferredResource def = toLoad.take();
if (def == null) continue;
if (!def.isLoaded()) {
@@ -58,11 +61,8 @@ public class DeferredLoader extends Thread implements ResourceLoadRequest.Listen
// skip nulls
if (def instanceof NullResource) continue;
// texture needs to be loaded in main thread, unfortunately.
// -> delegate to MainLoop
if (def instanceof MustLoadInMainThread) {
Log.f3("<DEFERRED> Loading \"" + Log.str(def) + "\" in main thread (texture based).");
// textures & fonts needs to be loaded in main thread
if (def.getClass().isAnnotationPresent(MustLoadInMainThread.class)) {
app.bus().queue(new MainLoopTaskRequest(new Runnable() {
@Override
@@ -75,8 +75,6 @@ public class DeferredLoader extends Thread implements ResourceLoadRequest.Listen
continue;
}
Log.f3("<DEFERRED> Loading \"" + Log.str(def) + "\" asynchronously.");
exs.submit(new Runnable() {
@Override
@@ -87,7 +85,7 @@ public class DeferredLoader extends Thread implements ResourceLoadRequest.Listen
});
}
} catch (InterruptedException ignored) {
} catch (final InterruptedException ignored) {
//
}
@@ -0,0 +1,127 @@
package mightypork.rogue.loading;
import mightypork.utils.control.interf.Destroyable;
import mightypork.utils.logging.Log;
/**
* Deferred resource abstraction.<br>
* Resources implementing {@link NullResource} will be treated as fake and not
* attempted to load.
*
* @author MightyPork
*/
public abstract class BaseDeferredResource implements DeferredResource, Destroyable {
private final String resource;
private boolean loadFailed = false;
private boolean loadAttempted = false;
public BaseDeferredResource(String resource) {
this.resource = resource;
}
@Override
public synchronized final void load()
{
if (loadAttempted) return;
loadAttempted = true;
loadFailed = false;
if (isNull()) return;
try {
if (resource == null) throw new NullPointerException("Resource string cannot be null for non-null resource.");
Log.f3("<res> Loading: " + this);
loadResource(resource);
Log.f3("<res> Loaded: " + this + " loaded.");
} catch (final Exception e) {
loadFailed = true;
Log.e("Failed to load resource \"" + resource + "\"", e);
}
}
@Override
public synchronized final boolean isLoaded()
{
if (isNull()) return false;
return loadAttempted && !loadFailed;
}
/**
* Check if the resource is loaded; if not, try to do so.
*
* @return true if it's loaded now.
*/
public synchronized final boolean ensureLoaded()
{
if (isNull()) return false;
if (isLoaded()) {
return true;
} else {
load();
}
return isLoaded();
}
/**
* Load the resource. Called from load() - once only.
*
* @param resource the path / name of a resource
* @throws Exception when some problem prevented the resource from being
* loaded.
*/
protected abstract void loadResource(String resource) throws Exception;
@Override
public abstract void destroy();
@Override
public String toString()
{
return Log.str(getClass()) + "(\"" + resource + "\")";
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((resource == null) ? 0 : resource.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof BaseDeferredResource)) return false;
final BaseDeferredResource other = (BaseDeferredResource) obj;
if (resource == null) {
if (other.resource != null) return false;
} else if (!resource.equals(other.resource)) return false;
return true;
}
private boolean isNull()
{
return this instanceof NullResource;
}
}
@@ -1,23 +0,0 @@
package mightypork.rogue.loading;
/**
* Deferred resource
*
* @author MightyPork
*/
public interface Deferred {
/**
* Load the actual resource, if not loaded yet.
*/
public void load();
/**
* Check if resource was successfully loaded.
*
* @return true if already loaded
*/
public boolean isLoaded();
}
@@ -1,127 +1,23 @@
package mightypork.rogue.loading;
import mightypork.utils.control.interf.Destroyable;
import mightypork.utils.logging.Log;
/**
* Deferred resource abstraction.<br>
* Resources implementing {@link NullResource} will be treated as fake and not
* attempted to load.
* Deferred resource
*
* @author MightyPork
*/
public abstract class DeferredResource implements Deferred, Destroyable {
public interface DeferredResource {
private String resource;
private boolean loadFailed = false;
private boolean loadAttempted = false;
public DeferredResource(String resource) {
this.resource = resource;
}
@Override
public synchronized final void load()
{
if (loadAttempted) return;
loadAttempted = true;
loadFailed = false;
if (isNull()) return;
try {
if (resource == null) throw new NullPointerException("Resource string cannot be null for non-null resource.");
Log.f3("Loading resource " + this);
loadResource(resource);
Log.f3("Resource " + this + " loaded.");
} catch (Exception e) {
loadFailed = true;
Log.e("Failed to load resource \"" + resource + "\"", e);
}
}
@Override
public synchronized final boolean isLoaded()
{
if (isNull()) return false;
return loadAttempted && !loadFailed;
}
/**
* Load the actual resource, if not loaded yet.
*/
void load();
/**
* Check if the resource is loaded; if not, try to do so.
* Check if resource was successfully loaded.
*
* @return true if it's loaded now.
* @return true if already loaded
*/
public synchronized final boolean ensureLoaded()
{
if (isNull()) return false;
if (isLoaded()) {
return true;
} else {
load();
}
return isLoaded();
}
/**
* Load the resource. Called from load() - once only.
*
* @param resource the path / name of a resource
* @throws Exception when some problem prevented the resource from being
* loaded.
*/
protected abstract void loadResource(String resource) throws Exception;
@Override
public abstract void destroy();
@Override
public String toString()
{
return Log.str(getClass()) + "(\"" + resource + "\")";
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((resource == null) ? 0 : resource.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof DeferredResource)) return false;
DeferredResource other = (DeferredResource) obj;
if (resource == null) {
if (other.resource != null) return false;
} else if (!resource.equals(other.resource)) return false;
return true;
}
private boolean isNull()
{
return this instanceof NullResource;
}
boolean isLoaded();
}
@@ -1,12 +1,18 @@
package mightypork.rogue.loading;
import java.lang.annotation.*;
/**
* Resource that is texture-based and therefore needs to be loaded in the main
* thread (ie. main loop).
*
* @author MightyPork
*/
public interface MustLoadInMainThread {
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
public @interface MustLoadInMainThread {}
@@ -59,7 +59,7 @@ public class DisplaySystem extends Subsystem implements ConstraintContext {
Render.init();
} catch (LWJGLException e) {
} catch (final LWJGLException e) {
throw new RuntimeException("Could not initialize screen", e);
}
}
@@ -88,12 +88,12 @@ public class DisplaySystem extends Subsystem implements ConstraintContext {
bus().queue(new ScreenChangeEvent(true, Display.isFullscreen(), getSize()));
} catch (Throwable t) {
} catch (final Throwable t) {
Log.e("Failed to toggle fullscreen mode.", t);
try {
Display.setDisplayMode(windowDisplayMode);
Display.update();
} catch (Throwable t1) {
} catch (final Throwable t1) {
throw new RuntimeException("Failed to revert failed fullscreen toggle.", t1);
}
}
@@ -103,14 +103,14 @@ public class DisplaySystem extends Subsystem implements ConstraintContext {
public Screenshot takeScreenshot()
{
glReadBuffer(GL_FRONT);
int width = Display.getDisplayMode().getWidth();
int height = Display.getDisplayMode().getHeight();
int bpp = 4; // Assuming a 32-bit display with a byte each for red,
// green, blue, and alpha.
ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
final int width = Display.getDisplayMode().getWidth();
final int height = Display.getDisplayMode().getHeight();
final int bpp = 4; // Assuming a 32-bit display with a byte each for red,
// green, blue, and alpha.
final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
Screenshot sc = new Screenshot(width, height, bpp, buffer);
final Screenshot sc = new Screenshot(width, height, bpp, buffer);
return sc;
}
+25 -27
View File
@@ -5,7 +5,7 @@ import static org.lwjgl.opengl.GL11.*;
import java.io.IOException;
import mightypork.rogue.texture.TxQuad;
import mightypork.rogue.textures.TxQuad;
import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
@@ -170,7 +170,7 @@ public class Render {
*/
public static void rotate(double angle, Coord axis)
{
Coord vec = axis.norm(1);
final Coord vec = axis.norm(1);
glRotated(angle, vec.x, vec.y, vec.z);
}
@@ -204,11 +204,9 @@ public class Render {
try {
String ext = FileUtils.getExtension(resourcePath).toUpperCase();
final String ext = FileUtils.getExtension(resourcePath).toUpperCase();
Log.f3("Loading texture " + ext + " at " + resourcePath);
Texture texture = TextureLoader.getTexture(ext, ResourceLoader.getResourceAsStream(resourcePath));
final Texture texture = TextureLoader.getTexture(ext, ResourceLoader.getResourceAsStream(resourcePath));
if (texture == null) {
Log.w("Texture " + resourcePath + " could not be loaded.");
@@ -216,7 +214,7 @@ public class Render {
return texture;
} catch (IOException e) {
} catch (final IOException e) {
Log.e("Loading of texture " + resourcePath + " failed.", e);
throw new RuntimeException("Could not load texture " + resourcePath + ".", e);
}
@@ -280,10 +278,10 @@ public class Render {
*/
public static void quad(Rect quad)
{
double left = quad.xMin();
double bottom = quad.yMin();
double right = quad.xMax();
double top = quad.yMax();
final double left = quad.xMin();
final double bottom = quad.yMin();
final double right = quad.xMax();
final double top = quad.yMax();
// draw with color
unbindTexture();
@@ -320,15 +318,15 @@ public class Render {
*/
public static void quadUV_nobound(Rect quad, Rect uvs)
{
double left = quad.xMin();
double bottom = quad.yMin();
double right = quad.xMax();
double top = quad.yMax();
final double left = quad.xMin();
final double bottom = quad.yMin();
final double right = quad.xMax();
final double top = quad.yMax();
double tleft = uvs.xMin();
double tbottom = uvs.yMin();
double tright = uvs.xMax();
double ttop = uvs.yMax();
final double tleft = uvs.xMin();
final double tbottom = uvs.yMin();
final double tright = uvs.xMax();
final double ttop = uvs.yMax();
// quad with texture
glTexCoord2d(tleft, ttop);
@@ -344,10 +342,10 @@ public class Render {
public static void quadGradH(Rect quad, RGB colorLeft, RGB colorRight)
{
double left = quad.xMin();
double bottom = quad.yMin();
double right = quad.yMax();
double top = quad.yMax();
final double left = quad.xMin();
final double bottom = quad.yMin();
final double right = quad.yMax();
final double top = quad.yMax();
// draw with color
unbindTexture();
@@ -368,10 +366,10 @@ public class Render {
public static void quadGradV(Rect quad, RGB colorTop, RGB colorBottom)
{
double left = quad.xMin();
double bottom = quad.yMin();
double right = quad.yMax();
double top = quad.yMax();
final double left = quad.xMin();
final double bottom = quad.yMin();
final double right = quad.yMax();
final double top = quad.yMax();
// draw with color
unbindTexture();
@@ -1,4 +1,4 @@
package mightypork.rogue.gui.constraints;
package mightypork.rogue.render;
/**
@@ -11,6 +11,6 @@ public interface Renderable {
/**
* Render on screen
*/
public void render();
void render();
}
@@ -3,7 +3,7 @@ package mightypork.rogue.sound;
import java.io.IOException;
import mightypork.rogue.loading.DeferredResource;
import mightypork.rogue.loading.BaseDeferredResource;
import mightypork.utils.files.FileUtils;
import mightypork.utils.math.coord.Coord;
@@ -16,7 +16,7 @@ import org.newdawn.slick.openal.SoundStore;
*
* @author MightyPork
*/
public class DeferredAudio extends DeferredResource {
public class DeferredAudio extends BaseDeferredResource {
private enum PlayMode
{
@@ -86,7 +86,7 @@ public class DeferredAudio extends DeferredResource {
@Override
protected void loadResource(String resource) throws IOException
{
String ext = FileUtils.getExtension(resource);
final String ext = FileUtils.getExtension(resource);
if (ext.equalsIgnoreCase("ogg")) {
backingAudio = SoundStore.get().getOgg(resource);
+1 -1
View File
@@ -33,7 +33,7 @@ public class JointVolume extends Mutable<Double> {
public Double get()
{
double d = super.get();
for (Mutable<Double> v : volumes)
for (final Mutable<Double> v : volumes)
d *= v.get();
return Calc.clampd(d, 0, 1);
+2 -2
View File
@@ -65,7 +65,7 @@ public class SoundBank extends AppAdapter {
*/
public LoopPlayer getLoop(String key)
{
LoopPlayer p = loops.get(key);
final LoopPlayer p = loops.get(key);
if (p == null) {
Log.w("Requesting unknown sound loop \"" + key + "\".");
return NULL_LOOP;
@@ -82,7 +82,7 @@ public class SoundBank extends AppAdapter {
*/
public EffectPlayer getEffect(String key)
{
EffectPlayer p = effects.get(key);
final EffectPlayer p = effects.get(key);
if (p == null) {
Log.w("Requesting unknown sound effect \"" + key + "\".");
return NULL_EFFECT;
+6 -6
View File
@@ -88,7 +88,7 @@ public class SoundSystem extends Subsystem implements Updateable {
@Override
public final void deinit()
{
for (DeferredAudio r : resources) {
for (final DeferredAudio r : resources) {
r.destroy();
}
@@ -100,7 +100,7 @@ public class SoundSystem extends Subsystem implements Updateable {
@Override
public void update(double delta)
{
for (Updateable lp : loopPlayers) {
for (final Updateable lp : loopPlayers) {
lp.update(delta);
}
}
@@ -132,7 +132,7 @@ public class SoundSystem extends Subsystem implements Updateable {
*/
public LoopPlayer createLoop(String resource, double pitch, double gain, double fadeIn, double fadeOut)
{
LoopPlayer p = new LoopPlayer(getResource(resource), pitch, gain, loopsVolume);
final LoopPlayer p = new LoopPlayer(getResource(resource), pitch, gain, loopsVolume);
p.setFadeTimes(fadeIn, fadeOut);
loopPlayers.add(p);
return p;
@@ -148,7 +148,7 @@ public class SoundSystem extends Subsystem implements Updateable {
*/
private DeferredAudio getResource(String res)
{
DeferredAudio a = new DeferredAudio(res);
final DeferredAudio a = new DeferredAudio(res);
bus().queue(new ResourceLoadRequest(a));
if (resources.contains(a)) throw new IllegalArgumentException("Sound resource " + res + " is already registered.");
@@ -162,7 +162,7 @@ public class SoundSystem extends Subsystem implements Updateable {
*/
public void fadeOutAllLoops()
{
for (LoopPlayer p : loopPlayers) {
for (final LoopPlayer p : loopPlayers) {
p.fadeOut();
}
}
@@ -173,7 +173,7 @@ public class SoundSystem extends Subsystem implements Updateable {
*/
public void pauseAllLoops()
{
for (LoopPlayer p : loopPlayers) {
for (final LoopPlayer p : loopPlayers) {
p.pause();
}
}
@@ -92,7 +92,7 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
fadeAnim.update(delta);
double gain = getGain(fadeAnim.now());
final double gain = getGain(fadeAnim.now());
if (!paused && gain != lastUpdateGain) {
AL10.alSourcef(sourceID, AL10.AL_GAIN, (float) gain);
lastUpdateGain = gain;
@@ -18,7 +18,7 @@ import mightypork.utils.logging.Log;
public class TaskTakeScreenshot implements Runnable {
private Screenshot scr;
private final Screenshot scr;
public TaskTakeScreenshot(DisplaySystem disp) {
@@ -30,20 +30,20 @@ public class TaskTakeScreenshot implements Runnable {
public void run()
{
BufferedImage image = new BufferedImage(scr.width, scr.height, BufferedImage.TYPE_INT_RGB);
final BufferedImage image = new BufferedImage(scr.width, scr.height, BufferedImage.TYPE_INT_RGB);
// convert to a buffered image
for (int x = 0; x < scr.width; x++) {
for (int y = 0; y < scr.height; y++) {
int i = (x + (scr.width * y)) * scr.bpp;
int r = scr.bytes.get(i) & 0xFF;
int g = scr.bytes.get(i + 1) & 0xFF;
int b = scr.bytes.get(i + 2) & 0xFF;
final int i = (x + (scr.width * y)) * scr.bpp;
final int r = scr.bytes.get(i) & 0xFF;
final int g = scr.bytes.get(i + 1) & 0xFF;
final int b = scr.bytes.get(i + 2) & 0xFF;
image.setRGB(x, scr.height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
}
}
String fname = getUniqueScreenshotName();
final String fname = getUniqueScreenshotName();
// generate unique filename
File file;
@@ -56,12 +56,12 @@ public class TaskTakeScreenshot implements Runnable {
Log.f3("Saving screenshot to file: " + file);
String format = "PNG";
final String format = "PNG";
// save to disk
try {
ImageIO.write(image, format, file);
} catch (IOException e) {
} catch (final IOException e) {
Log.e("Failed to save screenshot.", e);
}
}
@@ -69,7 +69,7 @@ public class TaskTakeScreenshot implements Runnable {
private static String getUniqueScreenshotName()
{
DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
return df.format(new Date());
}
@@ -1,7 +1,7 @@
package mightypork.rogue.texture;
package mightypork.rogue.textures;
import mightypork.rogue.loading.DeferredResource;
import mightypork.rogue.loading.BaseDeferredResource;
import mightypork.rogue.loading.MustLoadInMainThread;
import mightypork.rogue.render.Render;
import mightypork.utils.math.coord.Rect;
@@ -15,7 +15,8 @@ import org.newdawn.slick.opengl.Texture;
*
* @author MightyPork
*/
public class DeferredTexture extends DeferredResource implements FilteredTexture, MustLoadInMainThread {
@MustLoadInMainThread
public class DeferredTexture extends BaseDeferredResource implements FilteredTexture {
private Texture backingTexture;
private Filter filter_min = Filter.LINEAR;
@@ -1,4 +1,4 @@
package mightypork.rogue.texture;
package mightypork.rogue.textures;
import org.lwjgl.opengl.GL11;
@@ -38,7 +38,7 @@ public interface FilteredTexture extends Texture {
* @param filterMin downscale filter
* @param filterMag upscale filter
*/
public void setFilter(Filter filterMin, Filter filterMag);
void setFilter(Filter filterMin, Filter filterMag);
/**
@@ -46,11 +46,11 @@ public interface FilteredTexture extends Texture {
*
* @param filter filter
*/
public void setFilter(Filter filter);
void setFilter(Filter filter);
/**
* @param wrapping wrap mode
*/
public void setWrap(Wrap wrapping);
void setWrap(Wrap wrapping);
}
@@ -1,4 +1,4 @@
package mightypork.rogue.texture;
package mightypork.rogue.textures;
import java.util.HashMap;
@@ -6,8 +6,8 @@ import java.util.HashMap;
import mightypork.rogue.AppAccess;
import mightypork.rogue.AppAdapter;
import mightypork.rogue.bus.events.ResourceLoadRequest;
import mightypork.rogue.texture.FilteredTexture.Filter;
import mightypork.rogue.texture.FilteredTexture.Wrap;
import mightypork.rogue.textures.FilteredTexture.Filter;
import mightypork.rogue.textures.FilteredTexture.Wrap;
import mightypork.utils.math.coord.Rect;
import org.newdawn.slick.opengl.Texture;
@@ -54,7 +54,7 @@ public class TextureBank extends AppAdapter {
*/
public void loadTexture(String key, String resourcePath, Filter filter_min, Filter filter_mag, Wrap wrap)
{
DeferredTexture tx = new DeferredTexture(resourcePath);
final DeferredTexture tx = new DeferredTexture(resourcePath);
tx.setFilter(filter_min, filter_mag);
tx.setWrap(wrap);
@@ -74,10 +74,10 @@ public class TextureBank extends AppAdapter {
*/
public void makeQuad(String quadKey, String textureKey, Rect quad)
{
DeferredTexture tx = textures.get(textureKey);
final DeferredTexture tx = textures.get(textureKey);
if (tx == null) throw new RuntimeException("Texture with key " + textureKey + " not defined!");
TxQuad txquad = tx.getQuad(quad);
final TxQuad txquad = tx.getQuad(quad);
quads.put(quadKey, txquad);
}
@@ -91,10 +91,10 @@ public class TextureBank extends AppAdapter {
*/
public void makeQuad(String quadKey, Rect quad)
{
DeferredTexture tx = lastTx;
final DeferredTexture tx = lastTx;
if (tx == null) throw new RuntimeException("There's no texture loaded yet, can't define quads!");
TxQuad txquad = tx.getQuad(quad);
final TxQuad txquad = tx.getQuad(quad);
quads.put(quadKey, txquad);
}
@@ -108,7 +108,7 @@ public class TextureBank extends AppAdapter {
*/
public TxQuad getTxQuad(String key)
{
TxQuad q = quads.get(key);
final TxQuad q = quads.get(key);
if (q == null) throw new RuntimeException("There's no quad called " + key + "!");
@@ -124,7 +124,7 @@ public class TextureBank extends AppAdapter {
*/
public Texture getTexture(String key)
{
Texture t = textures.get(key);
final Texture t = textures.get(key);
if (t == null) throw new RuntimeException("There's no texture called " + key + "!");
@@ -1,4 +1,4 @@
package mightypork.rogue.texture;
package mightypork.rogue.textures;
import mightypork.utils.math.coord.Rect;
@@ -31,8 +31,8 @@ public class TxQuad {
*/
public static TxQuad fromSizePx(Texture tx, double xPx, double yPx, double widthPx, double heightPx)
{
double w = tx.getImageWidth();
double h = tx.getImageHeight();
final double w = tx.getImageWidth();
final double h = tx.getImageHeight();
return fromSize(tx, xPx / w, yPx / h, widthPx / w, heightPx / h);
}
+1 -1
View File
@@ -10,7 +10,7 @@ public class Utils {
public static Thread runAsThread(Runnable r)
{
Thread t = new Thread(r);
final Thread t = new Thread(r);
t.start();
return t;
}