Refactoring, cleanup, removed junk.

master
Ondřej Hruška 10 years ago
parent 22e5a8a12e
commit 2d212970f0
  1. BIN
      bin/mightypork/gamecore/backends/lwjgl/BufferHelper.class
  2. BIN
      bin/mightypork/gamecore/backends/lwjgl/InitTaskRedirectSlickLog.class
  3. BIN
      bin/mightypork/gamecore/backends/lwjgl/LwjglBackend.class
  4. BIN
      bin/mightypork/gamecore/backends/lwjgl/LwjglInputModule$1.class
  5. BIN
      bin/mightypork/gamecore/backends/lwjgl/LwjglInputModule.class
  6. BIN
      bin/mightypork/gamecore/backends/lwjgl/SlickLogRedirector.class
  7. BIN
      bin/mightypork/gamecore/backends/lwjgl/audio/SlickAudio.class
  8. BIN
      bin/mightypork/gamecore/backends/lwjgl/audio/SlickAudioModule.class
  9. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/AwtScreenshot.class
  10. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/LwjglGraphicsModule$1.class
  11. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/LwjglGraphicsModule.class
  12. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/SlickTexture.class
  13. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/font/DeferredLwjglFont.class
  14. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/font/DeferredLwjglFontFromSystem.class
  15. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/font/LwjglTextureBackedFont$1LoadedGlyph.class
  16. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/font/LwjglTextureBackedFont$CharTile.class
  17. BIN
      bin/mightypork/gamecore/backends/lwjgl/graphics/font/LwjglTextureBackedFont.class
  18. 4
      src/mightypork/gamecore/backends/lwjgl/BufferHelper.java
  19. 4
      src/mightypork/gamecore/backends/lwjgl/InitTaskRedirectSlickLog.java
  20. 3
      src/mightypork/gamecore/backends/lwjgl/SlickLogRedirector.java
  21. 2
      src/mightypork/gamecore/backends/lwjgl/audio/SlickAudioModule.java
  22. 12
      src/mightypork/gamecore/backends/lwjgl/audio/SlickSound.java
  23. 5
      src/mightypork/gamecore/backends/lwjgl/graphics/AwtScreenshot.java
  24. 21
      src/mightypork/gamecore/backends/lwjgl/graphics/LwjglGraphicsModule.java
  25. 3
      src/mightypork/gamecore/backends/lwjgl/graphics/SlickTexture.java
  26. 36
      src/mightypork/gamecore/backends/lwjgl/graphics/font/DeferredLwjglFontFromSystem.java
  27. 26
      src/mightypork/gamecore/backends/lwjgl/graphics/font/LwjglFont.java
  28. 14
      src/mightypork/gamecore/backends/lwjgl/graphics/font/LwjglTextureBackedFontImpl.java

@ -28,8 +28,8 @@ public class BufferHelper {
/**
* Fill java.nio.FloatBuffer with floats or float array
*
* @param buff
* @param obj
* @param buff target buffer
* @param obj floats to write
*/
public static void fill(FloatBuffer buff, float... obj)
{

@ -17,8 +17,8 @@ public class InitTaskRedirectSlickLog extends InitTask {
@Override
public void run()
{
LogWriter ml = mightypork.utils.logging.Log.getMainLogger();
SlickLogRedirector slr = new SlickLogRedirector(ml);
final LogWriter ml = mightypork.utils.logging.Log.getMainLogger();
final SlickLogRedirector slr = new SlickLogRedirector(ml);
org.newdawn.slick.util.Log.setLogSystem(slr);
}

@ -19,7 +19,8 @@ class SlickLogRedirector implements org.newdawn.slick.util.LogSystem {
/**
* @param log log to redirect into
*/
public SlickLogRedirector(LogWriter log) {
public SlickLogRedirector(LogWriter log)
{
this.writer = log;
}

@ -69,7 +69,7 @@ public class SlickAudioModule extends AudioModule {
@Override
protected DeferredAudio doCreateResource(String res)
{
return new SlickAudio(res);
return new SlickSound(res);
}
}

@ -17,7 +17,7 @@ import org.newdawn.slick.openal.SoundStore;
*
* @author Ondřej Hruška (MightyPork)
*/
public class SlickAudio extends DeferredAudio {
public class SlickSound extends DeferredAudio {
private double pauseLoopPosition = 0;
private boolean looping = false;
@ -30,7 +30,13 @@ public class SlickAudio extends DeferredAudio {
private int sourceID;
public SlickAudio(String resourceName) {
/**
* Slick-util based sound resource
*
* @param resourceName resource path
*/
public SlickSound(String resourceName)
{
super(resourceName);
}
@ -40,7 +46,7 @@ public class SlickAudio extends DeferredAudio {
{
final String ext = FileUtil.getExtension(resource);
try (final InputStream stream = FileUtil.getResource(resource)) {
try(final InputStream stream = FileUtil.getResource(resource)) {
if (ext.equalsIgnoreCase("ogg")) {
backingAudio = SoundStore.get().getOgg(resource, stream);

@ -31,9 +31,10 @@ public class AwtScreenshot implements Screenshot {
* @param width image width
* @param height image height
* @param bpp bits per pixel (typically 4)
* @param buffer
* @param buffer buffer with the screenshot bytes
*/
public AwtScreenshot(int width, int height, int bpp, ByteBuffer buffer) {
public AwtScreenshot(int width, int height, int bpp, ByteBuffer buffer)
{
this.width = width;
this.height = height;
this.bpp = bpp;

@ -6,9 +6,11 @@ import static org.lwjgl.opengl.GL11.*;
import java.nio.ByteBuffer;
import java.util.Stack;
import mightypork.gamecore.backends.lwjgl.graphics.font.LwjglFont;
import mightypork.gamecore.core.App;
import mightypork.gamecore.graphics.GraphicsModule;
import mightypork.gamecore.graphics.Screenshot;
import mightypork.gamecore.graphics.fonts.DeferredFont;
import mightypork.gamecore.graphics.textures.DeferredTexture;
import mightypork.gamecore.graphics.textures.TxQuad;
import mightypork.gamecore.gui.events.ViewportChangeEvent;
@ -40,7 +42,7 @@ public class LwjglGraphicsModule extends GraphicsModule {
/** Currently binded color's alpha multiplier */
private double activeColorAlpha = 1;
/** Stack of pushed colors */
private Stack<Color> colorPushStack = new Stack<>();
private final Stack<Color> colorPushStack = new Stack<>();
/** Currently binded texture */
private SlickTexture activeTexture;
@ -49,7 +51,7 @@ public class LwjglGraphicsModule extends GraphicsModule {
/** FPS the user wants */
private int targetFps;
/** FPS meter used for measuring actual FPS */
private FpsMeter fpsMeter = new FpsMeter();
private final FpsMeter fpsMeter = new FpsMeter();
/** Flag that at the end of frame, fullscreen should be toggled. */
private boolean fullscreenToggleRequested;
@ -387,8 +389,8 @@ public class LwjglGraphicsModule extends GraphicsModule {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
int w = Display.getWidth();
int h = Display.getHeight();
final int w = Display.getWidth();
final int h = Display.getHeight();
glViewport(0, 0, w, h);
glOrtho(0, w, h, 0, -1000, 1000);
@ -414,12 +416,19 @@ public class LwjglGraphicsModule extends GraphicsModule {
@Override
public DeferredTexture getLazyTexture(String path)
public DeferredTexture createDeferredTexture(String path)
{
return new SlickTexture(path);
}
@Override
public DeferredFont createDeferredFont(String path)
{
return new LwjglFont(path);
}
@Override
public void destroy()
{
@ -549,7 +558,7 @@ public class LwjglGraphicsModule extends GraphicsModule {
{
try {
Display.setDisplayMode(windowDisplayMode = new DisplayMode(width, height));
} catch (LWJGLException e) {
} catch (final LWJGLException e) {
throw new RuntimeException(e);
}
}

@ -32,7 +32,8 @@ public class SlickTexture extends DeferredTexture {
/**
* @param resourcePath resource path
*/
public SlickTexture(String resourcePath) {
public SlickTexture(String resourcePath)
{
super(resourcePath);
}

@ -1,36 +0,0 @@
package mightypork.gamecore.backends.lwjgl.graphics.font;
import java.awt.Font;
import java.io.IOException;
import mightypork.utils.annotations.Alias;
/**
* Font obtained from the OS
*
* @author Ondřej Hruška (MightyPork)
*/
@Alias(name = "FontNative")
public class DeferredLwjglFontFromSystem extends DeferredLwjglFont {
/**
* A font from OS, found by name
*
* @param fontName font family name
* @param chars chars to load; null to load basic chars only
* @param size size (pt)
*/
public DeferredLwjglFontFromSystem(String fontName, String chars, double size) {
super(fontName, chars, size);
}
@Override
protected Font getAwtFont(String resource, float size, int style) throws IOException
{
return new Font(resource, style, (int) size);
}
}

@ -22,7 +22,7 @@ import mightypork.utils.math.constraints.vect.Vect;
*/
@MustLoadInRenderingContext
@Alias(name = "Font")
public class DeferredLwjglFont extends DeferredFont {
public class LwjglFont extends DeferredFont {
private IFont font = null;
@ -31,13 +31,10 @@ public class DeferredLwjglFont extends DeferredFont {
* A font from resource
*
* @param resourcePath resource to load
* @param chars chars to load; null to load basic chars only
* @param size size (px)
*/
public DeferredLwjglFont(String resourcePath, String chars, double size) {
public LwjglFont(String resourcePath)
{
super(resourcePath);
this.size = size;
this.chars = chars;
}
@ -46,7 +43,7 @@ public class DeferredLwjglFont extends DeferredFont {
{
final Font awtFont = getAwtFont(path, (float) size, style.numval);
font = new LwjglTextureBackedFont(awtFont, antialias, filter, chars);
font = new LwjglTextureBackedFontImpl(awtFont, antialias, filter, chars);
font.setDiscardRatio(discardTop, discardBottom);
}
@ -58,16 +55,21 @@ public class DeferredLwjglFont extends DeferredFont {
* @param size font size (pt)
* @param style font style
* @return the {@link Font}
* @throws IOException
* @throws IOException on load error
*/
protected Font getAwtFont(String resource, float size, int style) throws IOException
{
try (InputStream in = FileUtil.getResource(resource)) {
try(InputStream in = FileUtil.getResource(resource)) {
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in);
Font awtFont = null;
awtFont = awtFont.deriveFont(size);
awtFont = awtFont.deriveFont(style);
if (in != null) {
awtFont = Font.createFont(Font.TRUETYPE_FONT, in);
awtFont = awtFont.deriveFont(size);
awtFont = awtFont.deriveFont(style);
} else {
awtFont = new Font(/* font name */resource, style, (int) size);
}
return awtFont;
} catch (final FontFormatException e) {

@ -41,7 +41,7 @@ import org.newdawn.slick.opengl.GLUtils;
* @author David Aaron Muhar (bobjob)
* @author Ondřej Hruška (MightyPork)
*/
public class LwjglTextureBackedFont implements IFont {
class LwjglTextureBackedFontImpl implements IFont {
private class CharTile {
@ -90,7 +90,8 @@ public class LwjglTextureBackedFont implements IFont {
* @param filter used Gl filter
* @param chars chars to load
*/
public LwjglTextureBackedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars) {
public LwjglTextureBackedFontImpl(java.awt.Font font, boolean antialias, FilterMode filter, String chars)
{
this(font, antialias, filter, (" " + chars).toCharArray());
}
@ -103,7 +104,8 @@ public class LwjglTextureBackedFont implements IFont {
* @param filter used Gl filter
* @param chars chars to load
*/
public LwjglTextureBackedFont(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars) {
public LwjglTextureBackedFontImpl(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars)
{
GLUtils.checkGLContext();
this.font = font;
@ -163,7 +165,8 @@ public class LwjglTextureBackedFont implements IFont {
public int height;
public LoadedGlyph(char c, BufferedImage image) {
public LoadedGlyph(char c, BufferedImage image)
{
this.image = image;
this.c = c;
this.width = image.getWidth();
@ -299,7 +302,8 @@ public class LwjglTextureBackedFont implements IFont {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
} else {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder())
.put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
}
byteBuffer.flip();
Loading…
Cancel
Save