Explorar el Código

Add IRNG::nextShort(short bound) + delete SquidPanelBuilder which I don't use anymore

smelc hace 6 años
padre
commit
88863bde0b

+ 10 - 0
squidlib-util/src/main/java/squidpony/squidmath/IRNG.java

@@ -156,6 +156,16 @@ public interface IRNG {
 	 */
 	public long nextLong();
 
+	/**
+	 * Returns a random non-negative short below the given bound, or 0 if the bound
+	 * is 0 or negative.
+	 * 
+	 * @param bound
+	 *            the upper bound (exclusive)
+	 * @return a 64-bit random long.
+	 */
+	public short nextShort(short bound);
+
 	/**
 	 * Shuffle an array using the Fisher-Yates algorithm and returns a shuffled
 	 * copy. Not GWT-compatible; use the overload that takes two arrays if you use

+ 0 - 185
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/SquidPanelBuilder.java

@@ -1,185 +0,0 @@
-package squidpony.squidgrid.gui.gdx;
-
-import com.badlogic.gdx.assets.AssetDescriptor;
-import com.badlogic.gdx.assets.AssetManager;
-import com.badlogic.gdx.graphics.Texture.TextureFilter;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
-
-/**
- * An almost-concrete implementation of {@link IPanelBuilder}. This class makes
- * the assumption that font files are only available for square and even sizes.
- * The only method to implement is {@link #fontfile(int)} that must return the
- * name of the file where a font of a given size lives.
- * 
- * <p>
- * I think this class should be generalized so that it supports cell width and
- * cell height that are proportional (for example: a height that is the double
- * of the width), but not to arbitrary combinations. In that case
- * {@link #adjustCellSize(int)} would become impossible to implement.
- * </p>
- * 
- * @author smelC
- */
-// FIXME MOVE ME to com.hgames.core
-public abstract class SquidPanelBuilder extends IPanelBuilder.Skeleton {
-
-	public final /* @Nullable */ AssetManager assetManager;
-
-	protected final int smallestCellSize;
-	protected final int largestCellSize;
-
-	protected final int fontOffset;
-
-	/**
-	 * There MUST be font for [smallestCellSize, smallestCellSize + 2, ...,
-	 * largestCellSize]
-	 * 
-	 * @param smallestCellSize
-	 *            The smallest cell size available.
-	 * @param largestCellSize
-	 *            The largest cell size available.
-	 * @param fontOffset
-	 *            This offset is added to the cell size when computing the font size
-	 *            for a given cell size. not to call this method.
-	 * @param assetManager
-	 */
-	public SquidPanelBuilder(int smallestCellSize, int largestCellSize, int fontOffset,
-			/* @Nullable */ AssetManager assetManager) {
-		assert smallestCellSize <= largestCellSize;
-		assert 0 <= fontOffset;
-		this.assetManager = assetManager;
-
-		this.smallestCellSize = smallestCellSize;
-		this.largestCellSize = largestCellSize;
-		this.fontOffset = fontOffset;
-	}
-
-	@Override
-	public SquidPanel buildScreenWide(int screenWidth, int screenHeight, int desiredCellSize,
-			/* @Nullable */ TextCellFactory tcf) {
-		final int sz = adjustCellSize(desiredCellSize);
-		final int hcells = screenWidth / sz;
-		final int vcells = screenHeight / sz;
-		final SquidPanel result = buildByCells(hcells, vcells, sz, sz, tcf);
-		final int vmargin = screenHeight - (vcells * sz);
-		final int hmargin = screenWidth - (hcells * sz);
-		result.setPosition(hmargin / 2, vmargin / 2);
-		/* TODO smelC Draw margins ? */
-		return result;
-	}
-
-	@Override
-	public SquidPanel buildByCells(int hCells, int vCells, int cellWidth, int cellHeight,
-			/* @Nullable */ TextCellFactory tcf_) {
-		if (cellWidth != cellHeight)
-			throw new IllegalStateException("Non square cells aren't supported");
-
-		final TextCellFactory tcf;
-		if (tcf_ != null && tcf_.width() == cellWidth && tcf_.height() == cellHeight) {
-			/* Can reuse */
-			tcf = tcf_;
-		} else {
-			final int fontSize = fontSizeForCellSize(cellWidth);
-			if (!hasFontOfSize(fontSize))
-				throw new IllegalStateException("No font of size " + fontSize);
-
-			final String fontpath = fontfile(fontSize);
-
-			assetManager.load(new AssetDescriptor<BitmapFont>(fontpath, BitmapFont.class));
-			/*
-			 * We're using the AssetManager not be asynchronous, but to avoid loading a file
-			 * twice (because that takes some time (tens of milliseconds)). Hence this KISS
-			 * code to avoid having to handle a not-yet-loaded font:
-			 */
-			assetManager.finishLoading();
-			final BitmapFont bmpFont = assetManager.get(fontpath, BitmapFont.class);
-			tcf = new TextCellFactory(bmpFont);
-			for (TextureRegion region : tcf.font().getRegions())
-				region.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
-			tcf.initByFont();
-			tcf.width(cellWidth).height(cellHeight);
-		}
-
-		assert tcf != null;
-
-		return new SquidPanel(hCells, vCells, tcf, 0f, 0f);
-	}
-
-	/**
-	 * @param sz
-	 * @return A valid cell size, as close as possible to {@code sz}.
-	 */
-	@Override
-	public int adjustCellSize(int sz) {
-		int result = sz % 2 == 0 ? sz : sz - 1;
-		if (acceptsCellOfSize(result))
-			return result;
-		if (cellSizeTooBig(sz)) {
-			/*
-			 * Note that we don't want the cell increment (2 on ascii, 12 on pixels) here,
-			 * because 'result' may not be valid at all (hence we need to correct it).
-			 */
-			final int offset = -2;
-			while (0 < result) {
-				result += offset;
-				if (acceptsCellOfSize(result))
-					return result;
-			}
-			throw new IllegalStateException("There's a bug in the computation of the cell size");
-		} else if (cellSizeTooSmall(result)) {
-			/*
-			 * Note that we don't want the cell increment (2 on ascii, 12 on pixels) here,
-			 * because 'result' may not be valid at all (hence we need to correct it).
-			 */
-			final int offset = 2;
-			while (/* It's better to stop one day */ result < 512) {
-				result += offset;
-				if (acceptsCellOfSize(result))
-					return result;
-			}
-			throw new IllegalStateException("There's a bug in the computation of the cell size");
-		} else
-			throw new IllegalStateException("There's a bug in the computation of the cell size");
-
-	}
-
-	@Override
-	public boolean cellSizeTooBig(int cellSize) {
-		return largestCellSize < fontSizeForCellSize(cellSize);
-	}
-
-	@Override
-	public boolean cellSizeTooSmall(int cellSize) {
-		return fontSizeForCellSize(cellSize) < smallestCellSize;
-	}
-
-	public int getSmallestCellSize() {
-		return smallestCellSize;
-	}
-
-	public int getLargestCellSize() {
-		return largestCellSize;
-	}
-
-	@Override
-	public boolean acceptsCellOfSize(int cellSize) {
-		return hasFontOfSize(fontSizeForCellSize(cellSize));
-	}
-
-	@Override
-	public int fontSizeForCellSize(int cellSize) {
-		return cellSize + fontOffset;
-	}
-
-	@Override
-	public boolean hasFontOfSize(int sz) {
-		return sz % 2 == 0 && smallestCellSize <= sz && sz <= largestCellSize;
-	}
-
-	/**
-	 * @param sz
-	 * @return The name of the file where the font of size {@code sz} lives.
-	 */
-	protected abstract String fontfile(int sz);
-}