Refactoring, cleanup, removed junk.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -8,14 +8,14 @@ import org.lwjgl.BufferUtils;
|
||||
|
||||
/**
|
||||
* Calc subclass with buffer utils.
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public class BufferHelper {
|
||||
|
||||
/**
|
||||
* Create java.nio.FloatBuffer of given floats, and flip it.
|
||||
*
|
||||
*
|
||||
* @param obj floats or float array
|
||||
* @return float buffer
|
||||
*/
|
||||
@@ -27,9 +27,9 @@ 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)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ public class BufferHelper {
|
||||
|
||||
/**
|
||||
* Create new java.nio.FloatBuffer of given length
|
||||
*
|
||||
*
|
||||
* @param count elements
|
||||
* @return the new java.nio.FloatBuffer
|
||||
*/
|
||||
|
||||
@@ -8,28 +8,28 @@ import mightypork.utils.logging.writers.LogWriter;
|
||||
|
||||
/**
|
||||
* Initializer that redirects slick logging to main logger.
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
@OptionalInitTask
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "slick_log";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getDependencies()
|
||||
{
|
||||
|
||||
@@ -11,45 +11,45 @@ import mightypork.gamecore.input.InputModule;
|
||||
|
||||
/**
|
||||
* Game backend using LWJGL and SlickUtil
|
||||
*
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class LwjglBackend extends AppBackend {
|
||||
|
||||
|
||||
private LwjglGraphicsModule graphics;
|
||||
private SlickAudioModule audio;
|
||||
private LwjglInputModule input;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
addChildClient(graphics = new LwjglGraphicsModule());
|
||||
addChildClient(audio = new SlickAudioModule());
|
||||
addChildClient(input = new LwjglInputModule());
|
||||
|
||||
|
||||
graphics.init();
|
||||
audio.init();
|
||||
input.init();
|
||||
|
||||
|
||||
app.addInitTask(new InitTaskRedirectSlickLog());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public GraphicsModule getGraphics()
|
||||
{
|
||||
return graphics;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public AudioModule getAudio()
|
||||
{
|
||||
return audio;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public InputModule getInput()
|
||||
{
|
||||
|
||||
@@ -20,23 +20,23 @@ import org.lwjgl.opengl.Display;
|
||||
|
||||
/**
|
||||
* Lwjgl Input Module.
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public class LwjglInputModule extends InputModule implements Updateable {
|
||||
|
||||
|
||||
/** Current mouse position */
|
||||
private static final Vect mousePos = new Vect() {
|
||||
|
||||
|
||||
@Override
|
||||
public double x()
|
||||
{
|
||||
if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE;
|
||||
|
||||
|
||||
return Mouse.getX();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public double y()
|
||||
{
|
||||
@@ -45,8 +45,8 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
return Display.getHeight() - Mouse.getY();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void initDevices()
|
||||
{
|
||||
@@ -58,13 +58,13 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
throw new RuntimeException("Failed to initialize input devices.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void initKeyCodes()
|
||||
{
|
||||
Keys.NONE.setCode(Keyboard.KEY_NONE);
|
||||
|
||||
|
||||
Keys.NUM_1.setCode(Keyboard.KEY_1);
|
||||
Keys.NUM_2.setCode(Keyboard.KEY_2);
|
||||
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_9.setCode(Keyboard.KEY_9);
|
||||
Keys.NUM_0.setCode(Keyboard.KEY_0);
|
||||
|
||||
|
||||
Keys.Q.setCode(Keyboard.KEY_Q);
|
||||
Keys.W.setCode(Keyboard.KEY_W);
|
||||
Keys.E.setCode(Keyboard.KEY_E);
|
||||
@@ -102,7 +102,7 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.B.setCode(Keyboard.KEY_B);
|
||||
Keys.N.setCode(Keyboard.KEY_N);
|
||||
Keys.M.setCode(Keyboard.KEY_M);
|
||||
|
||||
|
||||
Keys.MINUS.setCode(Keyboard.KEY_MINUS);
|
||||
Keys.EQUALS.setCode(Keyboard.KEY_EQUALS);
|
||||
Keys.SLASH.setCode(Keyboard.KEY_SLASH);
|
||||
@@ -114,17 +114,17 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.GRAVE.setCode(Keyboard.KEY_GRAVE);
|
||||
Keys.COMMA.setCode(Keyboard.KEY_COMMA);
|
||||
Keys.PERIOD.setCode(Keyboard.KEY_PERIOD);
|
||||
|
||||
|
||||
Keys.SPACE.setCode(Keyboard.KEY_SPACE);
|
||||
Keys.BACKSPACE.setCode(Keyboard.KEY_BACK);
|
||||
Keys.TAB.setCode(Keyboard.KEY_TAB);
|
||||
Keys.ESCAPE.setCode(Keyboard.KEY_ESCAPE);
|
||||
|
||||
|
||||
Keys.APPS.setCode(Keyboard.KEY_APPS);
|
||||
Keys.POWER.setCode(Keyboard.KEY_POWER);
|
||||
Keys.SLEEP.setCode(Keyboard.KEY_SLEEP);
|
||||
//Keys.MENU.setCode(Keyboard.KEY_MENU); // not defined
|
||||
|
||||
|
||||
Keys.F1.setCode(Keyboard.KEY_F1);
|
||||
Keys.F2.setCode(Keyboard.KEY_F2);
|
||||
Keys.F3.setCode(Keyboard.KEY_F3);
|
||||
@@ -140,11 +140,11 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
Keys.F13.setCode(Keyboard.KEY_F13);
|
||||
Keys.F14.setCode(Keyboard.KEY_F14);
|
||||
Keys.F15.setCode(Keyboard.KEY_F15);
|
||||
|
||||
|
||||
Keys.CAPS_LOCK.setCode(Keyboard.KEY_CAPITAL);
|
||||
Keys.SCROLL_LOCK.setCode(Keyboard.KEY_SCROLL);
|
||||
Keys.NUM_LOCK.setCode(Keyboard.KEY_NUMLOCK);
|
||||
|
||||
|
||||
Keys.NUMPAD_MINUS.setCode(Keyboard.KEY_SUBTRACT);
|
||||
Keys.NUMPAD_PLUSS.setCode(Keyboard.KEY_ADD);
|
||||
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_DIVIDE.setCode(Keyboard.KEY_DIVIDE);
|
||||
Keys.NUMPAD_MULTIPLY.setCode(Keyboard.KEY_MULTIPLY);
|
||||
|
||||
|
||||
Keys.CONTROL_LEFT.setCode(Keyboard.KEY_LCONTROL);
|
||||
Keys.CONTROL_RIGHT.setCode(Keyboard.KEY_RCONTROL);
|
||||
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.META_LEFT.setCode(Keyboard.KEY_LMETA);
|
||||
Keys.META_RIGHT.setCode(Keyboard.KEY_RMETA);
|
||||
|
||||
|
||||
Keys.UP.setCode(Keyboard.KEY_UP);
|
||||
Keys.DOWN.setCode(Keyboard.KEY_DOWN);
|
||||
Keys.LEFT.setCode(Keyboard.KEY_LEFT);
|
||||
Keys.RIGHT.setCode(Keyboard.KEY_RIGHT);
|
||||
|
||||
|
||||
Keys.HOME.setCode(Keyboard.KEY_HOME);
|
||||
Keys.END.setCode(Keyboard.KEY_END);
|
||||
|
||||
|
||||
Keys.PAGE_UP.setCode(Keyboard.KEY_PRIOR);
|
||||
Keys.PAGE_DOWN.setCode(Keyboard.KEY_NEXT);
|
||||
|
||||
|
||||
Keys.RETURN.setCode(Keyboard.KEY_RETURN);
|
||||
Keys.PAUSE.setCode(Keyboard.KEY_PAUSE);
|
||||
Keys.INSERT.setCode(Keyboard.KEY_INSERT);
|
||||
Keys.DELETE.setCode(Keyboard.KEY_DELETE);
|
||||
Keys.SYSRQ.setCode(Keyboard.KEY_SYSRQ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
Mouse.destroy();
|
||||
Keyboard.destroy();
|
||||
}
|
||||
|
||||
|
||||
private final VectVar mouseMove = Vect.makeVar();
|
||||
private final VectVar mouseLastPos = Vect.makeVar();
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void update(double delta)
|
||||
{
|
||||
@@ -208,9 +208,9 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
if (!Display.isCreated()) return;
|
||||
if (!Mouse.isCreated()) return;
|
||||
if (!Keyboard.isCreated()) return;
|
||||
|
||||
|
||||
Display.processMessages();
|
||||
|
||||
|
||||
// sum the moves
|
||||
mouseMove.reset();
|
||||
mouseLastPos.reset();
|
||||
@@ -219,81 +219,81 @@ public class LwjglInputModule extends InputModule implements Updateable {
|
||||
onMouseEvent(mouseMove, mouseLastPos);
|
||||
wasMouse = true;
|
||||
}
|
||||
|
||||
|
||||
if (wasMouse && !mouseMove.isZero()) {
|
||||
App.bus().send(new MouseMotionEvent(mouseLastPos, mouseMove));
|
||||
}
|
||||
|
||||
|
||||
while (Keyboard.next()) {
|
||||
onKeyEvent();
|
||||
}
|
||||
|
||||
|
||||
if (Display.isCloseRequested()) {
|
||||
App.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void onMouseEvent(VectVar moveSum, VectVar lastPos)
|
||||
{
|
||||
final int button = Mouse.getEventButton();
|
||||
final boolean down = Mouse.getEventButtonState();
|
||||
|
||||
|
||||
final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY());
|
||||
final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY());
|
||||
|
||||
|
||||
final int wheeld = Mouse.getEventDWheel();
|
||||
|
||||
|
||||
// flip Y axis
|
||||
pos.setY(Display.getHeight() - pos.y());
|
||||
|
||||
|
||||
if (button != -1 || wheeld != 0) {
|
||||
App.bus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld));
|
||||
}
|
||||
|
||||
|
||||
moveSum.setTo(moveSum.add(move));
|
||||
lastPos.setTo(pos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void onKeyEvent()
|
||||
{
|
||||
final int key = Keyboard.getEventKey();
|
||||
final boolean down = Keyboard.getEventKeyState();
|
||||
final char c = Keyboard.getEventCharacter();
|
||||
|
||||
|
||||
App.bus().send(new KeyEvent(key, c, down));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vect getMousePos()
|
||||
{
|
||||
return mousePos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isMouseInside()
|
||||
{
|
||||
return Mouse.isInsideWindow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void grabMouse(boolean grab)
|
||||
{
|
||||
Mouse.setGrabbed(grab);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isKeyDown(Key key)
|
||||
{
|
||||
return key.isDefined() && Keyboard.isKeyDown(key.getCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isMouseButtonDown(int button)
|
||||
{
|
||||
|
||||
@@ -8,68 +8,69 @@ import mightypork.utils.logging.writers.LogWriter;
|
||||
|
||||
/**
|
||||
* Used to redirect slick log into main logger.
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
class SlickLogRedirector implements org.newdawn.slick.util.LogSystem {
|
||||
|
||||
|
||||
LogWriter writer;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param log log to redirect into
|
||||
*/
|
||||
public SlickLogRedirector(LogWriter log) {
|
||||
public SlickLogRedirector(LogWriter log)
|
||||
{
|
||||
this.writer = log;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable e)
|
||||
{
|
||||
writer.log(Level.SEVERE, msg, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void error(Throwable e)
|
||||
{
|
||||
writer.log(Level.SEVERE, null, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void error(String msg)
|
||||
{
|
||||
writer.log(Level.SEVERE, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void warn(String msg)
|
||||
{
|
||||
writer.log(Level.WARNING, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable e)
|
||||
{
|
||||
writer.log(Level.WARNING, msg, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void info(String msg)
|
||||
{
|
||||
writer.log(Level.INFO, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void debug(String msg)
|
||||
{
|
||||
writer.log(Level.FINEST, msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@ import org.newdawn.slick.openal.SoundStore;
|
||||
|
||||
/**
|
||||
* SlickUtil-based audio module
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public class SlickAudioModule extends AudioModule {
|
||||
|
||||
|
||||
private final VectVar listenerPos = Vect.makeVar();
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
@@ -31,8 +31,8 @@ public class SlickAudioModule extends AudioModule {
|
||||
SoundStore.get().init();
|
||||
setListenerPos(Vect.ZERO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
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);
|
||||
AL10.alListener(AL10.AL_ORIENTATION, buf6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vect getListenerPos()
|
||||
{
|
||||
return listenerPos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void deinitSoundSystem()
|
||||
{
|
||||
SoundStore.get().clear();
|
||||
AL.destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected DeferredAudio doCreateResource(String res)
|
||||
{
|
||||
return new SlickAudio(res);
|
||||
return new SlickSound(res);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+10
-4
@@ -14,10 +14,10 @@ import org.newdawn.slick.openal.SoundStore;
|
||||
|
||||
/**
|
||||
* SlickUtil-based deferred audio resource.
|
||||
*
|
||||
*
|
||||
* @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);
|
||||
@@ -15,7 +15,7 @@ import mightypork.gamecore.graphics.Screenshot;
|
||||
* Screenshot object, can be used to extract image or write to file.<br>
|
||||
* Screenshot, once taken, can be safely processed in separate thread.<br>
|
||||
* Based on {@link BufferedImage} and {@link ImageIO}.
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public class AwtScreenshot implements Screenshot {
|
||||
@@ -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;
|
||||
@@ -44,7 +45,7 @@ public class AwtScreenshot implements Screenshot {
|
||||
/**
|
||||
* Extract to an image.<br>
|
||||
* Subsequent calls will use a cached value.
|
||||
*
|
||||
*
|
||||
* @return image
|
||||
*/
|
||||
public BufferedImage getImage()
|
||||
@@ -71,7 +72,7 @@ public class AwtScreenshot implements Screenshot {
|
||||
/**
|
||||
* Save to a file.<br>
|
||||
* Cached value is used if any.
|
||||
*
|
||||
*
|
||||
* @param file target file
|
||||
* @throws IOException on error writing to file
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
@@ -30,7 +32,7 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* LWJGL rendering module
|
||||
*
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class LwjglGraphicsModule extends GraphicsModule {
|
||||
@@ -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,10 +416,17 @@ 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
|
||||
@@ -467,7 +476,7 @@ public class LwjglGraphicsModule extends GraphicsModule {
|
||||
try {
|
||||
|
||||
if (Display.isFullscreen() == fs) return; // no work
|
||||
|
||||
|
||||
if (fs) {
|
||||
Log.f3("Entering fullscreen.");
|
||||
// save window resize
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,32 +17,33 @@ import org.newdawn.slick.opengl.TextureLoader;
|
||||
|
||||
/**
|
||||
* Deferred texture
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
@Alias(name = "Texture")
|
||||
@MustLoadInRenderingContext
|
||||
public class SlickTexture extends DeferredTexture {
|
||||
|
||||
|
||||
private org.newdawn.slick.opengl.Texture backingTexture;
|
||||
private boolean alpha;
|
||||
private boolean alphal;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param resourcePath resource path
|
||||
*/
|
||||
public SlickTexture(String resourcePath) {
|
||||
public SlickTexture(String resourcePath)
|
||||
{
|
||||
super(resourcePath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected synchronized void loadResource(String path)
|
||||
{
|
||||
try {
|
||||
final String ext = FileUtil.getExtension(path).toUpperCase();
|
||||
|
||||
|
||||
final int filtering;
|
||||
switch (filter) {
|
||||
case NEAREST:
|
||||
@@ -54,49 +55,49 @@ public class SlickTexture extends DeferredTexture {
|
||||
default:
|
||||
throw new IllegalValueException("Unsupported filtering mode.");
|
||||
}
|
||||
|
||||
|
||||
final Texture texture = TextureLoader.getTexture(ext, FileUtil.getResource(path), false, filtering);
|
||||
|
||||
|
||||
if (texture == null) {
|
||||
Log.w("Texture " + path + " could not be loaded.");
|
||||
}
|
||||
|
||||
|
||||
backingTexture = texture;
|
||||
|
||||
|
||||
} catch (final IOException e) {
|
||||
Log.e("Loading of texture " + path + " failed.", e);
|
||||
throw new RuntimeException("Could not load texture " + path + ".", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasAlpha()
|
||||
{
|
||||
if (!ensureLoaded()) return false;
|
||||
|
||||
|
||||
if (!alphal) {
|
||||
alphal = true;
|
||||
alpha = backingTexture.hasAlpha();
|
||||
}
|
||||
|
||||
|
||||
return alpha;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Bind to GL context, applying the filters prescribed.
|
||||
*/
|
||||
public void bind()
|
||||
{
|
||||
if (!ensureLoaded()) return;
|
||||
|
||||
|
||||
//GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureID());
|
||||
|
||||
|
||||
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
|
||||
|
||||
|
||||
final int wrapping;
|
||||
switch (wrap) {
|
||||
case CLAMP:
|
||||
@@ -108,10 +109,10 @@ public class SlickTexture extends DeferredTexture {
|
||||
default:
|
||||
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_T, wrapping);
|
||||
|
||||
|
||||
final int filtering;
|
||||
switch (filter) {
|
||||
case NEAREST:
|
||||
@@ -123,72 +124,72 @@ public class SlickTexture extends DeferredTexture {
|
||||
default:
|
||||
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_MAG_FILTER, filtering);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getImageHeight()
|
||||
{
|
||||
if (!ensureLoaded()) return 0;
|
||||
|
||||
|
||||
return backingTexture.getImageHeight();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getImageWidth()
|
||||
{
|
||||
if (!ensureLoaded()) return 0;
|
||||
|
||||
|
||||
return backingTexture.getImageWidth();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
if (!isLoaded()) return;
|
||||
|
||||
|
||||
backingTexture.release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the height of the texture, 0..1.<br>
|
||||
*
|
||||
*
|
||||
* @return height 0..1
|
||||
*/
|
||||
public float getHeight01()
|
||||
{
|
||||
if (!ensureLoaded()) return 0;
|
||||
|
||||
|
||||
return backingTexture.getHeight();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the width of the texture, 0..1.<br>
|
||||
*
|
||||
*
|
||||
* @return width 0..1
|
||||
*/
|
||||
public float getWidth01()
|
||||
{
|
||||
if (!ensureLoaded()) return 0;
|
||||
|
||||
|
||||
return backingTexture.getWidth();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return OpenGL texture ID
|
||||
*/
|
||||
public int getTextureID()
|
||||
{
|
||||
if (!ensureLoaded()) return -1;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
+20
-18
@@ -17,27 +17,24 @@ import mightypork.utils.math.constraints.vect.Vect;
|
||||
|
||||
/**
|
||||
* Font obtained from a resource file (TTF).
|
||||
*
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
@MustLoadInRenderingContext
|
||||
@Alias(name = "Font")
|
||||
public class DeferredLwjglFont extends DeferredFont {
|
||||
public class LwjglFont extends DeferredFont {
|
||||
|
||||
private IFont font = null;
|
||||
|
||||
|
||||
/**
|
||||
* 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,28 +43,33 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a font for a resource path / name
|
||||
*
|
||||
*
|
||||
* @param resource resource to load
|
||||
* @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 = null;
|
||||
|
||||
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in);
|
||||
|
||||
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) {
|
||||
@@ -78,7 +80,7 @@ public class DeferredLwjglFont extends DeferredFont {
|
||||
|
||||
/**
|
||||
* Draw string
|
||||
*
|
||||
*
|
||||
* @param str string to draw
|
||||
* @param color draw color
|
||||
*/
|
||||
@@ -93,7 +95,7 @@ public class DeferredLwjglFont extends DeferredFont {
|
||||
|
||||
/**
|
||||
* Get size needed to render give string
|
||||
*
|
||||
*
|
||||
* @param text string to check
|
||||
* @return coord (width, height)
|
||||
*/
|
||||
+14
-10
@@ -33,7 +33,7 @@ import org.newdawn.slick.opengl.GLUtils;
|
||||
|
||||
/**
|
||||
* A TrueType font renderer with backing texture.
|
||||
*
|
||||
*
|
||||
* @author James Chambers (Jimmy)
|
||||
* @author Jeremy Adams (elias4444)
|
||||
* @author Kevin Glass (kevglass)
|
||||
@@ -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 {
|
||||
|
||||
@@ -84,26 +84,28 @@ public class LwjglTextureBackedFont implements IFont {
|
||||
|
||||
/**
|
||||
* Make a font
|
||||
*
|
||||
*
|
||||
* @param font original awt font to load
|
||||
* @param antialias use antialiasing when rendering to cache texture
|
||||
* @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());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a font
|
||||
*
|
||||
*
|
||||
* @param font original awt font to load
|
||||
* @param antialias use antialiasing when rendering to cache texture
|
||||
* @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;
|
||||
@@ -117,7 +119,7 @@ public class LwjglTextureBackedFont implements IFont {
|
||||
|
||||
/**
|
||||
* Create a BufferedImage of the given character
|
||||
*
|
||||
*
|
||||
* @param ch the character
|
||||
* @return BufferedImage containing the drawn character
|
||||
*/
|
||||
@@ -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();
|
||||
@@ -349,7 +353,7 @@ public class LwjglTextureBackedFont implements IFont {
|
||||
|
||||
/**
|
||||
* Get size needed to draw given string
|
||||
*
|
||||
*
|
||||
* @param text drawn text
|
||||
* @return needed width
|
||||
*/
|
||||
Reference in New Issue
Block a user