tweaks to texture sys
This commit is contained in:
@@ -17,7 +17,6 @@ public class QuadGrid {
|
||||
private double tileW;
|
||||
private double tileH;
|
||||
|
||||
|
||||
public QuadGrid(GLTexture tx, int tilesX, int tilesY) {
|
||||
this.tx = tx;
|
||||
this.txWidth = tilesX;
|
||||
|
||||
@@ -18,6 +18,10 @@ import mightypork.util.error.KeyAlreadyExistsException;
|
||||
*/
|
||||
public class TextureBank extends AppAdapter {
|
||||
|
||||
private final Map<String, GLTexture> textures = new HashMap<>();
|
||||
private final Map<String, TxQuad> quads = new HashMap<>();
|
||||
private final Map<String, TxSheet> sheets = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param app app access
|
||||
*/
|
||||
@@ -25,12 +29,6 @@ public class TextureBank extends AppAdapter {
|
||||
super(app);
|
||||
}
|
||||
|
||||
private final Map<String, GLTexture> textures = new HashMap<>();
|
||||
|
||||
private final Map<String, TxQuad> quads = new HashMap<>();
|
||||
|
||||
private final Map<String, TxSheet> sheets = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Load a texture from resource. A full-sized quad with the same key will be
|
||||
@@ -72,22 +70,6 @@ public class TextureBank extends AppAdapter {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a quad from texture, and add it to quads registry.
|
||||
*
|
||||
* @param quadKey key
|
||||
* @param texture source texture
|
||||
* @param uvs rect
|
||||
* @return the created quad
|
||||
*/
|
||||
public TxQuad makeQuad(String quadKey, GLTexture texture, Rect uvs)
|
||||
{
|
||||
TxQuad quad = texture.makeQuad(uvs);
|
||||
addQuad(quadKey, quad);
|
||||
return quad;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add already created quad to the quad registry
|
||||
*
|
||||
@@ -102,25 +84,6 @@ public class TextureBank extends AppAdapter {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* make a sprite sheet originating at given quad, spanning right and down.
|
||||
*
|
||||
* @param sheetKey key
|
||||
* @param origin starting quad
|
||||
* @param width sheet width (multiplies of origin width)
|
||||
* @param height sheet height (multiplies of origin height)
|
||||
* @return the created sheet
|
||||
*/
|
||||
public TxSheet makeSheet(String sheetKey, TxQuad origin, int width, int height)
|
||||
{
|
||||
TxSheet sheet = origin.makeSheet(width, height);
|
||||
|
||||
addSheet(sheetKey, sheet);
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an already created sheet
|
||||
*
|
||||
@@ -143,11 +106,11 @@ public class TextureBank extends AppAdapter {
|
||||
*/
|
||||
public TxQuad getQuad(String key)
|
||||
{
|
||||
final TxQuad q = quads.get(key);
|
||||
final TxQuad qu = quads.get(key);
|
||||
|
||||
if (q == null) throw new RuntimeException("There's no quad called " + key + "!");
|
||||
if (qu == null) throw new RuntimeException("There's no quad called " + key + "!");
|
||||
|
||||
return q;
|
||||
return qu;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,11 +122,27 @@ public class TextureBank extends AppAdapter {
|
||||
*/
|
||||
public GLTexture getTexture(String key)
|
||||
{
|
||||
final GLTexture t = textures.get(key);
|
||||
final GLTexture tx = textures.get(key);
|
||||
|
||||
if (t == null) throw new RuntimeException("There's no texture called " + key + "!");
|
||||
if (tx == null) throw new RuntimeException("There's no texture called " + key + "!");
|
||||
|
||||
return t;
|
||||
return tx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a {@link TxSheet} for key
|
||||
*
|
||||
* @param key sheet key
|
||||
* @return the sheet
|
||||
*/
|
||||
public TxSheet getSheet(String key)
|
||||
{
|
||||
final TxSheet sh = sheets.get(key);
|
||||
|
||||
if (sh == null) throw new RuntimeException("There's no sheet called " + key + "!");
|
||||
|
||||
return sh;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,4 +87,17 @@ public class TxSheet {
|
||||
randForSeed.setSeed(seed);
|
||||
return getQuad(randForSeed.nextInt(count));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get random TxQuad from this sheet
|
||||
*
|
||||
* @param seed random number generator seed (double will be converted to
|
||||
* long)
|
||||
* @return the picked quad
|
||||
*/
|
||||
public TxQuad getRandomQuad(double seed)
|
||||
{
|
||||
return getRandomQuad(Double.doubleToLongBits(seed));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ package mightypork.rogue;
|
||||
import mightypork.gamecore.audio.SoundBank;
|
||||
import mightypork.gamecore.audio.players.EffectPlayer;
|
||||
import mightypork.gamecore.audio.players.LoopPlayer;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.BaseApp;
|
||||
import mightypork.gamecore.render.fonts.FontBank;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.gamecore.render.fonts.Glyphs;
|
||||
import mightypork.gamecore.render.fonts.impl.DeferredFont;
|
||||
import mightypork.gamecore.render.textures.*;
|
||||
import mightypork.util.constraints.rect.Rect;
|
||||
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
|
||||
@@ -31,7 +29,7 @@ public final class Res {
|
||||
|
||||
|
||||
/**
|
||||
* Load on behalf of given {@link AppAccess}
|
||||
* Load on behalf of given base app
|
||||
*
|
||||
* @param app app access
|
||||
*/
|
||||
@@ -52,14 +50,10 @@ public final class Res {
|
||||
|
||||
private static void loadFonts()
|
||||
{
|
||||
DeferredFont font;
|
||||
|
||||
font = new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16);
|
||||
fonts.loadFont("polygon_pixel", font);
|
||||
|
||||
font = new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16);
|
||||
fonts.loadFont("press_start", font);
|
||||
fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16));
|
||||
fonts.loadFont("press_start", new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
|
||||
|
||||
// aliases based on concrete usage
|
||||
fonts.addAlias("default", "polygon_pixel");
|
||||
fonts.addAlias("main_menu_button", "press_start");
|
||||
fonts.addAlias("main_menu_title", "press_start");
|
||||
@@ -68,32 +62,20 @@ public final class Res {
|
||||
|
||||
private static void loadTextures()
|
||||
{
|
||||
DeferredTexture texture;
|
||||
GLTexture texture;
|
||||
|
||||
texture = new DeferredTexture("/res/img/kitten.png");
|
||||
texture.setFilter(FilterMode.LINEAR);
|
||||
texture.setWrap(WrapMode.CLAMP);
|
||||
textures.loadTexture("test.kitten", texture);
|
||||
texture = textures.loadTexture("test.kitten", "/res/img/kitten.png", FilterMode.LINEAR, WrapMode.CLAMP);
|
||||
|
||||
texture = new DeferredTexture("/res/img/gui1.png");
|
||||
texture.setFilter(FilterMode.NEAREST);
|
||||
texture.setWrap(WrapMode.CLAMP);
|
||||
textures.loadTexture("gui1", texture);
|
||||
QuadGrid guiGrid = texture.grid(4, 4);
|
||||
|
||||
//@formatter:off
|
||||
textures.addQuad("item_frame", guiGrid.makeQuad(0, 0));
|
||||
textures.addQuad("sword", guiGrid.makeQuad(1, 0));
|
||||
textures.addQuad("meat", guiGrid.makeQuad(2, 0));
|
||||
|
||||
textures.addQuad("heart_on", guiGrid.makeQuad(.0, 1, .5, .5));
|
||||
textures.addQuad("heart_off", guiGrid.makeQuad(.5, 1, .5, .5));
|
||||
|
||||
textures.addQuad("xp_on", guiGrid.makeQuad(0, 1.5, .5, .5));
|
||||
textures.addQuad("xp_off", guiGrid.makeQuad(.5, 1.5, .5, .5));
|
||||
|
||||
textures.addQuad("panel", guiGrid.makeQuad(0, 3.75, 4, .25));
|
||||
//@formatter:off
|
||||
texture = textures.loadTexture("gui1", "/res/img/gui1.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
||||
QuadGrid gui = texture.grid(4, 4);
|
||||
textures.addQuad("item_frame", gui.makeQuad(0, 0));
|
||||
textures.addQuad("sword", gui.makeQuad(1, 0));
|
||||
textures.addQuad("meat", gui.makeQuad(2, 0));
|
||||
textures.addQuad("heart_on", gui.makeQuad(.0, 1, .5, .5));
|
||||
textures.addQuad("heart_off", gui.makeQuad(.5, 1, .5, .5));
|
||||
textures.addQuad("xp_on", gui.makeQuad(0, 1.5, .5, .5));
|
||||
textures.addQuad("xp_off", gui.makeQuad(.5, 1.5, .5, .5));
|
||||
textures.addQuad("panel", gui.makeQuad(0, 3.75, 4, .25));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@ package mightypork.util.control.timing;
|
||||
import mightypork.util.constraints.num.mutable.NumAnimated;
|
||||
|
||||
|
||||
/**
|
||||
* Delayed runnable controlled by delta timing.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class TimedTask implements Runnable, Updateable {
|
||||
|
||||
private final NumAnimated timer = new NumAnimated(0);
|
||||
|
||||
Reference in New Issue
Block a user