Refactoring, cleanup, removed junk.

master
Ondřej Hruška 11 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. 12
      src/mightypork/gamecore/backends/lwjgl/BufferHelper.java
  19. 16
      src/mightypork/gamecore/backends/lwjgl/InitTaskRedirectSlickLog.java
  20. 24
      src/mightypork/gamecore/backends/lwjgl/LwjglBackend.java
  21. 106
      src/mightypork/gamecore/backends/lwjgl/LwjglInputModule.java
  22. 41
      src/mightypork/gamecore/backends/lwjgl/SlickLogRedirector.java
  23. 28
      src/mightypork/gamecore/backends/lwjgl/audio/SlickAudioModule.java
  24. 14
      src/mightypork/gamecore/backends/lwjgl/audio/SlickSound.java
  25. 11
      src/mightypork/gamecore/backends/lwjgl/graphics/AwtScreenshot.java
  26. 25
      src/mightypork/gamecore/backends/lwjgl/graphics/LwjglGraphicsModule.java
  27. 91
      src/mightypork/gamecore/backends/lwjgl/graphics/SlickTexture.java
  28. 36
      src/mightypork/gamecore/backends/lwjgl/graphics/font/DeferredLwjglFontFromSystem.java
  29. 38
      src/mightypork/gamecore/backends/lwjgl/graphics/font/LwjglFont.java
  30. 24
      src/mightypork/gamecore/backends/lwjgl/graphics/font/LwjglTextureBackedFontImpl.java

@ -8,14 +8,14 @@ import org.lwjgl.BufferUtils;
/** /**
* Calc subclass with buffer utils. * Calc subclass with buffer utils.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public class BufferHelper { public class BufferHelper {
/** /**
* Create java.nio.FloatBuffer of given floats, and flip it. * Create java.nio.FloatBuffer of given floats, and flip it.
* *
* @param obj floats or float array * @param obj floats or float array
* @return float buffer * @return float buffer
*/ */
@ -27,9 +27,9 @@ public class BufferHelper {
/** /**
* Fill java.nio.FloatBuffer with floats or float array * Fill java.nio.FloatBuffer with floats or float array
* *
* @param buff * @param buff target buffer
* @param obj * @param obj floats to write
*/ */
public static void fill(FloatBuffer buff, float... obj) public static void fill(FloatBuffer buff, float... obj)
{ {
@ -40,7 +40,7 @@ public class BufferHelper {
/** /**
* Create new java.nio.FloatBuffer of given length * Create new java.nio.FloatBuffer of given length
* *
* @param count elements * @param count elements
* @return the new java.nio.FloatBuffer * @return the new java.nio.FloatBuffer
*/ */

@ -8,28 +8,28 @@ import mightypork.utils.logging.writers.LogWriter;
/** /**
* Initializer that redirects slick logging to main logger. * Initializer that redirects slick logging to main logger.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@OptionalInitTask @OptionalInitTask
public class InitTaskRedirectSlickLog extends InitTask { public class InitTaskRedirectSlickLog extends InitTask {
@Override @Override
public void run() public void run()
{ {
LogWriter ml = mightypork.utils.logging.Log.getMainLogger(); final LogWriter ml = mightypork.utils.logging.Log.getMainLogger();
SlickLogRedirector slr = new SlickLogRedirector(ml); final SlickLogRedirector slr = new SlickLogRedirector(ml);
org.newdawn.slick.util.Log.setLogSystem(slr); org.newdawn.slick.util.Log.setLogSystem(slr);
} }
@Override @Override
public String getName() public String getName()
{ {
return "slick_log"; return "slick_log";
} }
@Override @Override
public String[] getDependencies() public String[] getDependencies()
{ {

@ -11,45 +11,45 @@ import mightypork.gamecore.input.InputModule;
/** /**
* Game backend using LWJGL and SlickUtil * Game backend using LWJGL and SlickUtil
* *
* @author MightyPork * @author MightyPork
*/ */
public class LwjglBackend extends AppBackend { public class LwjglBackend extends AppBackend {
private LwjglGraphicsModule graphics; private LwjglGraphicsModule graphics;
private SlickAudioModule audio; private SlickAudioModule audio;
private LwjglInputModule input; private LwjglInputModule input;
@Override @Override
public void initialize() public void initialize()
{ {
addChildClient(graphics = new LwjglGraphicsModule()); addChildClient(graphics = new LwjglGraphicsModule());
addChildClient(audio = new SlickAudioModule()); addChildClient(audio = new SlickAudioModule());
addChildClient(input = new LwjglInputModule()); addChildClient(input = new LwjglInputModule());
graphics.init(); graphics.init();
audio.init(); audio.init();
input.init(); input.init();
app.addInitTask(new InitTaskRedirectSlickLog()); app.addInitTask(new InitTaskRedirectSlickLog());
} }
@Override @Override
public GraphicsModule getGraphics() public GraphicsModule getGraphics()
{ {
return graphics; return graphics;
} }
@Override @Override
public AudioModule getAudio() public AudioModule getAudio()
{ {
return audio; return audio;
} }
@Override @Override
public InputModule getInput() public InputModule getInput()
{ {

@ -20,23 +20,23 @@ import org.lwjgl.opengl.Display;
/** /**
* Lwjgl Input Module. * Lwjgl Input Module.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public class LwjglInputModule extends InputModule implements Updateable { public class LwjglInputModule extends InputModule implements Updateable {
/** Current mouse position */ /** Current mouse position */
private static final Vect mousePos = new Vect() { private static final Vect mousePos = new Vect() {
@Override @Override
public double x() public double x()
{ {
if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE; if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE;
return Mouse.getX(); return Mouse.getX();
} }
@Override @Override
public double y() public double y()
{ {
@ -45,8 +45,8 @@ public class LwjglInputModule extends InputModule implements Updateable {
return Display.getHeight() - Mouse.getY(); return Display.getHeight() - Mouse.getY();
} }
}; };
@Override @Override
protected void initDevices() protected void initDevices()
{ {
@ -58,13 +58,13 @@ public class LwjglInputModule extends InputModule implements Updateable {
throw new RuntimeException("Failed to initialize input devices.", e); throw new RuntimeException("Failed to initialize input devices.", e);
} }
} }
@Override @Override
protected void initKeyCodes() protected void initKeyCodes()
{ {
Keys.NONE.setCode(Keyboard.KEY_NONE); Keys.NONE.setCode(Keyboard.KEY_NONE);
Keys.NUM_1.setCode(Keyboard.KEY_1); Keys.NUM_1.setCode(Keyboard.KEY_1);
Keys.NUM_2.setCode(Keyboard.KEY_2); Keys.NUM_2.setCode(Keyboard.KEY_2);
Keys.NUM_3.setCode(Keyboard.KEY_3); Keys.NUM_3.setCode(Keyboard.KEY_3);
@ -75,7 +75,7 @@ public class LwjglInputModule extends InputModule implements Updateable {
Keys.NUM_8.setCode(Keyboard.KEY_8); Keys.NUM_8.setCode(Keyboard.KEY_8);
Keys.NUM_9.setCode(Keyboard.KEY_9); Keys.NUM_9.setCode(Keyboard.KEY_9);
Keys.NUM_0.setCode(Keyboard.KEY_0); Keys.NUM_0.setCode(Keyboard.KEY_0);
Keys.Q.setCode(Keyboard.KEY_Q); Keys.Q.setCode(Keyboard.KEY_Q);
Keys.W.setCode(Keyboard.KEY_W); Keys.W.setCode(Keyboard.KEY_W);
Keys.E.setCode(Keyboard.KEY_E); Keys.E.setCode(Keyboard.KEY_E);
@ -102,7 +102,7 @@ public class LwjglInputModule extends InputModule implements Updateable {
Keys.B.setCode(Keyboard.KEY_B); Keys.B.setCode(Keyboard.KEY_B);
Keys.N.setCode(Keyboard.KEY_N); Keys.N.setCode(Keyboard.KEY_N);
Keys.M.setCode(Keyboard.KEY_M); Keys.M.setCode(Keyboard.KEY_M);
Keys.MINUS.setCode(Keyboard.KEY_MINUS); Keys.MINUS.setCode(Keyboard.KEY_MINUS);
Keys.EQUALS.setCode(Keyboard.KEY_EQUALS); Keys.EQUALS.setCode(Keyboard.KEY_EQUALS);
Keys.SLASH.setCode(Keyboard.KEY_SLASH); Keys.SLASH.setCode(Keyboard.KEY_SLASH);
@ -114,17 +114,17 @@ public class LwjglInputModule extends InputModule implements Updateable {
Keys.GRAVE.setCode(Keyboard.KEY_GRAVE); Keys.GRAVE.setCode(Keyboard.KEY_GRAVE);
Keys.COMMA.setCode(Keyboard.KEY_COMMA); Keys.COMMA.setCode(Keyboard.KEY_COMMA);
Keys.PERIOD.setCode(Keyboard.KEY_PERIOD); Keys.PERIOD.setCode(Keyboard.KEY_PERIOD);
Keys.SPACE.setCode(Keyboard.KEY_SPACE); Keys.SPACE.setCode(Keyboard.KEY_SPACE);
Keys.BACKSPACE.setCode(Keyboard.KEY_BACK); Keys.BACKSPACE.setCode(Keyboard.KEY_BACK);
Keys.TAB.setCode(Keyboard.KEY_TAB); Keys.TAB.setCode(Keyboard.KEY_TAB);
Keys.ESCAPE.setCode(Keyboard.KEY_ESCAPE); Keys.ESCAPE.setCode(Keyboard.KEY_ESCAPE);
Keys.APPS.setCode(Keyboard.KEY_APPS); Keys.APPS.setCode(Keyboard.KEY_APPS);
Keys.POWER.setCode(Keyboard.KEY_POWER); Keys.POWER.setCode(Keyboard.KEY_POWER);
Keys.SLEEP.setCode(Keyboard.KEY_SLEEP); Keys.SLEEP.setCode(Keyboard.KEY_SLEEP);
//Keys.MENU.setCode(Keyboard.KEY_MENU); // not defined //Keys.MENU.setCode(Keyboard.KEY_MENU); // not defined
Keys.F1.setCode(Keyboard.KEY_F1); Keys.F1.setCode(Keyboard.KEY_F1);
Keys.F2.setCode(Keyboard.KEY_F2); Keys.F2.setCode(Keyboard.KEY_F2);
Keys.F3.setCode(Keyboard.KEY_F3); Keys.F3.setCode(Keyboard.KEY_F3);
@ -140,11 +140,11 @@ public class LwjglInputModule extends InputModule implements Updateable {
Keys.F13.setCode(Keyboard.KEY_F13); Keys.F13.setCode(Keyboard.KEY_F13);
Keys.F14.setCode(Keyboard.KEY_F14); Keys.F14.setCode(Keyboard.KEY_F14);
Keys.F15.setCode(Keyboard.KEY_F15); Keys.F15.setCode(Keyboard.KEY_F15);
Keys.CAPS_LOCK.setCode(Keyboard.KEY_CAPITAL); Keys.CAPS_LOCK.setCode(Keyboard.KEY_CAPITAL);
Keys.SCROLL_LOCK.setCode(Keyboard.KEY_SCROLL); Keys.SCROLL_LOCK.setCode(Keyboard.KEY_SCROLL);
Keys.NUM_LOCK.setCode(Keyboard.KEY_NUMLOCK); Keys.NUM_LOCK.setCode(Keyboard.KEY_NUMLOCK);
Keys.NUMPAD_MINUS.setCode(Keyboard.KEY_SUBTRACT); Keys.NUMPAD_MINUS.setCode(Keyboard.KEY_SUBTRACT);
Keys.NUMPAD_PLUSS.setCode(Keyboard.KEY_ADD); Keys.NUMPAD_PLUSS.setCode(Keyboard.KEY_ADD);
Keys.NUMPAD_0.setCode(Keyboard.KEY_NUMPAD0); Keys.NUMPAD_0.setCode(Keyboard.KEY_NUMPAD0);
@ -161,7 +161,7 @@ public class LwjglInputModule extends InputModule implements Updateable {
Keys.NUMPAD_ENTER.setCode(Keyboard.KEY_NUMPADENTER); Keys.NUMPAD_ENTER.setCode(Keyboard.KEY_NUMPADENTER);
Keys.NUMPAD_DIVIDE.setCode(Keyboard.KEY_DIVIDE); Keys.NUMPAD_DIVIDE.setCode(Keyboard.KEY_DIVIDE);
Keys.NUMPAD_MULTIPLY.setCode(Keyboard.KEY_MULTIPLY); Keys.NUMPAD_MULTIPLY.setCode(Keyboard.KEY_MULTIPLY);
Keys.CONTROL_LEFT.setCode(Keyboard.KEY_LCONTROL); Keys.CONTROL_LEFT.setCode(Keyboard.KEY_LCONTROL);
Keys.CONTROL_RIGHT.setCode(Keyboard.KEY_RCONTROL); Keys.CONTROL_RIGHT.setCode(Keyboard.KEY_RCONTROL);
Keys.ALT_LEFT.setCode(Keyboard.KEY_LMENU); Keys.ALT_LEFT.setCode(Keyboard.KEY_LMENU);
@ -170,37 +170,37 @@ public class LwjglInputModule extends InputModule implements Updateable {
Keys.SHIFT_RIGHT.setCode(Keyboard.KEY_RSHIFT); Keys.SHIFT_RIGHT.setCode(Keyboard.KEY_RSHIFT);
Keys.META_LEFT.setCode(Keyboard.KEY_LMETA); Keys.META_LEFT.setCode(Keyboard.KEY_LMETA);
Keys.META_RIGHT.setCode(Keyboard.KEY_RMETA); Keys.META_RIGHT.setCode(Keyboard.KEY_RMETA);
Keys.UP.setCode(Keyboard.KEY_UP); Keys.UP.setCode(Keyboard.KEY_UP);
Keys.DOWN.setCode(Keyboard.KEY_DOWN); Keys.DOWN.setCode(Keyboard.KEY_DOWN);
Keys.LEFT.setCode(Keyboard.KEY_LEFT); Keys.LEFT.setCode(Keyboard.KEY_LEFT);
Keys.RIGHT.setCode(Keyboard.KEY_RIGHT); Keys.RIGHT.setCode(Keyboard.KEY_RIGHT);
Keys.HOME.setCode(Keyboard.KEY_HOME); Keys.HOME.setCode(Keyboard.KEY_HOME);
Keys.END.setCode(Keyboard.KEY_END); Keys.END.setCode(Keyboard.KEY_END);
Keys.PAGE_UP.setCode(Keyboard.KEY_PRIOR); Keys.PAGE_UP.setCode(Keyboard.KEY_PRIOR);
Keys.PAGE_DOWN.setCode(Keyboard.KEY_NEXT); Keys.PAGE_DOWN.setCode(Keyboard.KEY_NEXT);
Keys.RETURN.setCode(Keyboard.KEY_RETURN); Keys.RETURN.setCode(Keyboard.KEY_RETURN);
Keys.PAUSE.setCode(Keyboard.KEY_PAUSE); Keys.PAUSE.setCode(Keyboard.KEY_PAUSE);
Keys.INSERT.setCode(Keyboard.KEY_INSERT); Keys.INSERT.setCode(Keyboard.KEY_INSERT);
Keys.DELETE.setCode(Keyboard.KEY_DELETE); Keys.DELETE.setCode(Keyboard.KEY_DELETE);
Keys.SYSRQ.setCode(Keyboard.KEY_SYSRQ); Keys.SYSRQ.setCode(Keyboard.KEY_SYSRQ);
} }
@Override @Override
public void destroy() public void destroy()
{ {
Mouse.destroy(); Mouse.destroy();
Keyboard.destroy(); Keyboard.destroy();
} }
private final VectVar mouseMove = Vect.makeVar(); private final VectVar mouseMove = Vect.makeVar();
private final VectVar mouseLastPos = Vect.makeVar(); private final VectVar mouseLastPos = Vect.makeVar();
@Override @Override
public synchronized void update(double delta) public synchronized void update(double delta)
{ {
@ -208,9 +208,9 @@ public class LwjglInputModule extends InputModule implements Updateable {
if (!Display.isCreated()) return; if (!Display.isCreated()) return;
if (!Mouse.isCreated()) return; if (!Mouse.isCreated()) return;
if (!Keyboard.isCreated()) return; if (!Keyboard.isCreated()) return;
Display.processMessages(); Display.processMessages();
// sum the moves // sum the moves
mouseMove.reset(); mouseMove.reset();
mouseLastPos.reset(); mouseLastPos.reset();
@ -219,81 +219,81 @@ public class LwjglInputModule extends InputModule implements Updateable {
onMouseEvent(mouseMove, mouseLastPos); onMouseEvent(mouseMove, mouseLastPos);
wasMouse = true; wasMouse = true;
} }
if (wasMouse && !mouseMove.isZero()) { if (wasMouse && !mouseMove.isZero()) {
App.bus().send(new MouseMotionEvent(mouseLastPos, mouseMove)); App.bus().send(new MouseMotionEvent(mouseLastPos, mouseMove));
} }
while (Keyboard.next()) { while (Keyboard.next()) {
onKeyEvent(); onKeyEvent();
} }
if (Display.isCloseRequested()) { if (Display.isCloseRequested()) {
App.shutdown(); App.shutdown();
} }
} }
private void onMouseEvent(VectVar moveSum, VectVar lastPos) private void onMouseEvent(VectVar moveSum, VectVar lastPos)
{ {
final int button = Mouse.getEventButton(); final int button = Mouse.getEventButton();
final boolean down = Mouse.getEventButtonState(); final boolean down = Mouse.getEventButtonState();
final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY()); final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY());
final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY()); final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY());
final int wheeld = Mouse.getEventDWheel(); final int wheeld = Mouse.getEventDWheel();
// flip Y axis // flip Y axis
pos.setY(Display.getHeight() - pos.y()); pos.setY(Display.getHeight() - pos.y());
if (button != -1 || wheeld != 0) { if (button != -1 || wheeld != 0) {
App.bus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld)); App.bus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld));
} }
moveSum.setTo(moveSum.add(move)); moveSum.setTo(moveSum.add(move));
lastPos.setTo(pos); lastPos.setTo(pos);
} }
private void onKeyEvent() private void onKeyEvent()
{ {
final int key = Keyboard.getEventKey(); final int key = Keyboard.getEventKey();
final boolean down = Keyboard.getEventKeyState(); final boolean down = Keyboard.getEventKeyState();
final char c = Keyboard.getEventCharacter(); final char c = Keyboard.getEventCharacter();
App.bus().send(new KeyEvent(key, c, down)); App.bus().send(new KeyEvent(key, c, down));
} }
@Override @Override
public Vect getMousePos() public Vect getMousePos()
{ {
return mousePos; return mousePos;
} }
@Override @Override
public boolean isMouseInside() public boolean isMouseInside()
{ {
return Mouse.isInsideWindow(); return Mouse.isInsideWindow();
} }
@Override @Override
public void grabMouse(boolean grab) public void grabMouse(boolean grab)
{ {
Mouse.setGrabbed(grab); Mouse.setGrabbed(grab);
} }
@Override @Override
public boolean isKeyDown(Key key) public boolean isKeyDown(Key key)
{ {
return key.isDefined() && Keyboard.isKeyDown(key.getCode()); return key.isDefined() && Keyboard.isKeyDown(key.getCode());
} }
@Override @Override
public boolean isMouseButtonDown(int button) public boolean isMouseButtonDown(int button)
{ {

@ -8,68 +8,69 @@ import mightypork.utils.logging.writers.LogWriter;
/** /**
* Used to redirect slick log into main logger. * Used to redirect slick log into main logger.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
class SlickLogRedirector implements org.newdawn.slick.util.LogSystem { class SlickLogRedirector implements org.newdawn.slick.util.LogSystem {
LogWriter writer; LogWriter writer;
/** /**
* @param log log to redirect into * @param log log to redirect into
*/ */
public SlickLogRedirector(LogWriter log) { public SlickLogRedirector(LogWriter log)
{
this.writer = log; this.writer = log;
} }
@Override @Override
public void error(String msg, Throwable e) public void error(String msg, Throwable e)
{ {
writer.log(Level.SEVERE, msg, e); writer.log(Level.SEVERE, msg, e);
} }
@Override @Override
public void error(Throwable e) public void error(Throwable e)
{ {
writer.log(Level.SEVERE, null, e); writer.log(Level.SEVERE, null, e);
} }
@Override @Override
public void error(String msg) public void error(String msg)
{ {
writer.log(Level.SEVERE, msg); writer.log(Level.SEVERE, msg);
} }
@Override @Override
public void warn(String msg) public void warn(String msg)
{ {
writer.log(Level.WARNING, msg); writer.log(Level.WARNING, msg);
} }
@Override @Override
public void warn(String msg, Throwable e) public void warn(String msg, Throwable e)
{ {
writer.log(Level.WARNING, msg, e); writer.log(Level.WARNING, msg, e);
} }
@Override @Override
public void info(String msg) public void info(String msg)
{ {
writer.log(Level.INFO, msg); writer.log(Level.INFO, msg);
} }
@Override @Override
public void debug(String msg) public void debug(String msg)
{ {
writer.log(Level.FINEST, msg); writer.log(Level.FINEST, msg);
} }
} }

@ -16,14 +16,14 @@ import org.newdawn.slick.openal.SoundStore;
/** /**
* SlickUtil-based audio module * SlickUtil-based audio module
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public class SlickAudioModule extends AudioModule { public class SlickAudioModule extends AudioModule {
private final VectVar listenerPos = Vect.makeVar(); private final VectVar listenerPos = Vect.makeVar();
@Override @Override
public void init() public void init()
{ {
@ -31,8 +31,8 @@ public class SlickAudioModule extends AudioModule {
SoundStore.get().init(); SoundStore.get().init();
setListenerPos(Vect.ZERO); setListenerPos(Vect.ZERO);
} }
@Override @Override
public void setListenerPos(Vect pos) public void setListenerPos(Vect pos)
{ {
@ -49,27 +49,27 @@ public class SlickAudioModule extends AudioModule {
BufferHelper.fill(buf6, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); BufferHelper.fill(buf6, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
AL10.alListener(AL10.AL_ORIENTATION, buf6); AL10.alListener(AL10.AL_ORIENTATION, buf6);
} }
@Override @Override
public Vect getListenerPos() public Vect getListenerPos()
{ {
return listenerPos; return listenerPos;
} }
@Override @Override
protected void deinitSoundSystem() protected void deinitSoundSystem()
{ {
SoundStore.get().clear(); SoundStore.get().clear();
AL.destroy(); AL.destroy();
} }
@Override @Override
protected DeferredAudio doCreateResource(String res) protected DeferredAudio doCreateResource(String res)
{ {
return new SlickAudio(res); return new SlickSound(res);
} }
} }

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

@ -15,7 +15,7 @@ import mightypork.gamecore.graphics.Screenshot;
* Screenshot object, can be used to extract image or write to file.<br> * Screenshot object, can be used to extract image or write to file.<br>
* Screenshot, once taken, can be safely processed in separate thread.<br> * Screenshot, once taken, can be safely processed in separate thread.<br>
* Based on {@link BufferedImage} and {@link ImageIO}. * Based on {@link BufferedImage} and {@link ImageIO}.
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public class AwtScreenshot implements Screenshot { public class AwtScreenshot implements Screenshot {
@ -31,9 +31,10 @@ public class AwtScreenshot implements Screenshot {
* @param width image width * @param width image width
* @param height image height * @param height image height
* @param bpp bits per pixel (typically 4) * @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.width = width;
this.height = height; this.height = height;
this.bpp = bpp; this.bpp = bpp;
@ -44,7 +45,7 @@ public class AwtScreenshot implements Screenshot {
/** /**
* Extract to an image.<br> * Extract to an image.<br>
* Subsequent calls will use a cached value. * Subsequent calls will use a cached value.
* *
* @return image * @return image
*/ */
public BufferedImage getImage() public BufferedImage getImage()
@ -71,7 +72,7 @@ public class AwtScreenshot implements Screenshot {
/** /**
* Save to a file.<br> * Save to a file.<br>
* Cached value is used if any. * Cached value is used if any.
* *
* @param file target file * @param file target file
* @throws IOException on error writing to file * @throws IOException on error writing to file
*/ */

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

@ -17,32 +17,33 @@ import org.newdawn.slick.opengl.TextureLoader;
/** /**
* Deferred texture * Deferred texture
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@Alias(name = "Texture") @Alias(name = "Texture")
@MustLoadInRenderingContext @MustLoadInRenderingContext
public class SlickTexture extends DeferredTexture { public class SlickTexture extends DeferredTexture {
private org.newdawn.slick.opengl.Texture backingTexture; private org.newdawn.slick.opengl.Texture backingTexture;
private boolean alpha; private boolean alpha;
private boolean alphal; private boolean alphal;
/** /**
* @param resourcePath resource path * @param resourcePath resource path
*/ */
public SlickTexture(String resourcePath) { public SlickTexture(String resourcePath)
{
super(resourcePath); super(resourcePath);
} }
@Override @Override
protected synchronized void loadResource(String path) protected synchronized void loadResource(String path)
{ {
try { try {
final String ext = FileUtil.getExtension(path).toUpperCase(); final String ext = FileUtil.getExtension(path).toUpperCase();
final int filtering; final int filtering;
switch (filter) { switch (filter) {
case NEAREST: case NEAREST:
@ -54,49 +55,49 @@ public class SlickTexture extends DeferredTexture {
default: default:
throw new IllegalValueException("Unsupported filtering mode."); throw new IllegalValueException("Unsupported filtering mode.");
} }
final Texture texture = TextureLoader.getTexture(ext, FileUtil.getResource(path), false, filtering); final Texture texture = TextureLoader.getTexture(ext, FileUtil.getResource(path), false, filtering);
if (texture == null) { if (texture == null) {
Log.w("Texture " + path + " could not be loaded."); Log.w("Texture " + path + " could not be loaded.");
} }
backingTexture = texture; backingTexture = texture;
} catch (final IOException e) { } catch (final IOException e) {
Log.e("Loading of texture " + path + " failed.", e); Log.e("Loading of texture " + path + " failed.", e);
throw new RuntimeException("Could not load texture " + path + ".", e); throw new RuntimeException("Could not load texture " + path + ".", e);
} }
} }
@Override @Override
public boolean hasAlpha() public boolean hasAlpha()
{ {
if (!ensureLoaded()) return false; if (!ensureLoaded()) return false;
if (!alphal) { if (!alphal) {
alphal = true; alphal = true;
alpha = backingTexture.hasAlpha(); alpha = backingTexture.hasAlpha();
} }
return alpha; return alpha;
} }
/** /**
* Bind to GL context, applying the filters prescribed. * Bind to GL context, applying the filters prescribed.
*/ */
public void bind() public void bind()
{ {
if (!ensureLoaded()) return; if (!ensureLoaded()) return;
//GL11.glEnable(GL11.GL_TEXTURE_2D); //GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureID()); GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureID());
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
final int wrapping; final int wrapping;
switch (wrap) { switch (wrap) {
case CLAMP: case CLAMP:
@ -108,10 +109,10 @@ public class SlickTexture extends DeferredTexture {
default: default:
throw new IllegalValueException("Unsupported wrapping mode."); throw new IllegalValueException("Unsupported wrapping mode.");
} }
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrapping); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrapping);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wrapping); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wrapping);
final int filtering; final int filtering;
switch (filter) { switch (filter) {
case NEAREST: case NEAREST:
@ -123,72 +124,72 @@ public class SlickTexture extends DeferredTexture {
default: default:
throw new IllegalValueException("Unsupported filtering mode."); throw new IllegalValueException("Unsupported filtering mode.");
} }
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filtering); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filtering);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filtering); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filtering);
} }
@Override @Override
public int getImageHeight() public int getImageHeight()
{ {
if (!ensureLoaded()) return 0; if (!ensureLoaded()) return 0;
return backingTexture.getImageHeight(); return backingTexture.getImageHeight();
} }
@Override @Override
public int getImageWidth() public int getImageWidth()
{ {
if (!ensureLoaded()) return 0; if (!ensureLoaded()) return 0;
return backingTexture.getImageWidth(); return backingTexture.getImageWidth();
} }
@Override @Override
public void destroy() public void destroy()
{ {
if (!isLoaded()) return; if (!isLoaded()) return;
backingTexture.release(); backingTexture.release();
} }
/** /**
* Get the height of the texture, 0..1.<br> * Get the height of the texture, 0..1.<br>
* *
* @return height 0..1 * @return height 0..1
*/ */
public float getHeight01() public float getHeight01()
{ {
if (!ensureLoaded()) return 0; if (!ensureLoaded()) return 0;
return backingTexture.getHeight(); return backingTexture.getHeight();
} }
/** /**
* Get the width of the texture, 0..1.<br> * Get the width of the texture, 0..1.<br>
* *
* @return width 0..1 * @return width 0..1
*/ */
public float getWidth01() public float getWidth01()
{ {
if (!ensureLoaded()) return 0; if (!ensureLoaded()) return 0;
return backingTexture.getWidth(); return backingTexture.getWidth();
} }
/** /**
* @return OpenGL texture ID * @return OpenGL texture ID
*/ */
public int getTextureID() public int getTextureID()
{ {
if (!ensureLoaded()) return -1; if (!ensureLoaded()) return -1;
return backingTexture.getTextureID(); return backingTexture.getTextureID();
} }
} }

@ -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);
}
}

@ -17,27 +17,24 @@ import mightypork.utils.math.constraints.vect.Vect;
/** /**
* Font obtained from a resource file (TTF). * Font obtained from a resource file (TTF).
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
@MustLoadInRenderingContext @MustLoadInRenderingContext
@Alias(name = "Font") @Alias(name = "Font")
public class DeferredLwjglFont extends DeferredFont { public class LwjglFont extends DeferredFont {
private IFont font = null; private IFont font = null;
/** /**
* A font from resource * A font from resource
* *
* @param resourcePath resource to load * @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); super(resourcePath);
this.size = size;
this.chars = chars;
} }
@ -46,28 +43,33 @@ public class DeferredLwjglFont extends DeferredFont {
{ {
final Font awtFont = getAwtFont(path, (float) size, style.numval); 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); font.setDiscardRatio(discardTop, discardBottom);
} }
/** /**
* Get a font for a resource path / name * Get a font for a resource path / name
* *
* @param resource resource to load * @param resource resource to load
* @param size font size (pt) * @param size font size (pt)
* @param style font style * @param style font style
* @return the {@link Font} * @return the {@link Font}
* @throws IOException * @throws IOException on load error
*/ */
protected Font getAwtFont(String resource, float size, int style) throws IOException 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); if (in != null) {
awtFont = awtFont.deriveFont(style); 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; return awtFont;
} catch (final FontFormatException e) { } catch (final FontFormatException e) {
@ -78,7 +80,7 @@ public class DeferredLwjglFont extends DeferredFont {
/** /**
* Draw string * Draw string
* *
* @param str string to draw * @param str string to draw
* @param color draw color * @param color draw color
*/ */
@ -93,7 +95,7 @@ public class DeferredLwjglFont extends DeferredFont {
/** /**
* Get size needed to render give string * Get size needed to render give string
* *
* @param text string to check * @param text string to check
* @return coord (width, height) * @return coord (width, height)
*/ */

@ -33,7 +33,7 @@ import org.newdawn.slick.opengl.GLUtils;
/** /**
* A TrueType font renderer with backing texture. * A TrueType font renderer with backing texture.
* *
* @author James Chambers (Jimmy) * @author James Chambers (Jimmy)
* @author Jeremy Adams (elias4444) * @author Jeremy Adams (elias4444)
* @author Kevin Glass (kevglass) * @author Kevin Glass (kevglass)
@ -41,7 +41,7 @@ import org.newdawn.slick.opengl.GLUtils;
* @author David Aaron Muhar (bobjob) * @author David Aaron Muhar (bobjob)
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public class LwjglTextureBackedFont implements IFont { class LwjglTextureBackedFontImpl implements IFont {
private class CharTile { private class CharTile {
@ -84,26 +84,28 @@ public class LwjglTextureBackedFont implements IFont {
/** /**
* Make a font * Make a font
* *
* @param font original awt font to load * @param font original awt font to load
* @param antialias use antialiasing when rendering to cache texture * @param antialias use antialiasing when rendering to cache texture
* @param filter used Gl filter * @param filter used Gl filter
* @param chars chars to load * @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()); this(font, antialias, filter, (" " + chars).toCharArray());
} }
/** /**
* Make a font * Make a font
* *
* @param font original awt font to load * @param font original awt font to load
* @param antialias use antialiasing when rendering to cache texture * @param antialias use antialiasing when rendering to cache texture
* @param filter used Gl filter * @param filter used Gl filter
* @param chars chars to load * @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(); GLUtils.checkGLContext();
this.font = font; this.font = font;
@ -117,7 +119,7 @@ public class LwjglTextureBackedFont implements IFont {
/** /**
* Create a BufferedImage of the given character * Create a BufferedImage of the given character
* *
* @param ch the character * @param ch the character
* @return BufferedImage containing the drawn character * @return BufferedImage containing the drawn character
*/ */
@ -163,7 +165,8 @@ public class LwjglTextureBackedFont implements IFont {
public int height; public int height;
public LoadedGlyph(char c, BufferedImage image) { public LoadedGlyph(char c, BufferedImage image)
{
this.image = image; this.image = image;
this.c = c; this.c = c;
this.width = image.getWidth(); 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); byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
} else { } 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(); byteBuffer.flip();
@ -349,7 +353,7 @@ public class LwjglTextureBackedFont implements IFont {
/** /**
* Get size needed to draw given string * Get size needed to draw given string
* *
* @param text drawn text * @param text drawn text
* @return needed width * @return needed width
*/ */
Loading…
Cancel
Save