Some refactoring

master
Ondřej Hruška 10 years ago
parent ec64ad21fc
commit eee9ed14dc
  1. 299
      src/junk/DisplaySystem.java
  2. 542
      src/junk/Render.java
  3. 8
      src/mightypork/gamecore/backend/Backend.java
  4. 7
      src/mightypork/gamecore/backend/BackendModule.java
  5. 3
      src/mightypork/gamecore/backend/lwjgl/AwtScreenshot.java
  6. 5
      src/mightypork/gamecore/backend/lwjgl/LwjglBackend.java
  7. 22
      src/mightypork/gamecore/backend/lwjgl/LwjglRenderModule.java
  8. 5
      src/mightypork/gamecore/backend/lwjgl/SlickLazyTexture.java
  9. 1
      src/mightypork/gamecore/core/config/Config.java
  10. 4
      src/mightypork/gamecore/core/config/ConfigSetup.java
  11. 8
      src/mightypork/gamecore/core/config/KeyOpts.java
  12. 7
      src/mightypork/gamecore/core/config/KeyProperty.java
  13. 2
      src/mightypork/gamecore/core/config/KeySetup.java
  14. 3
      src/mightypork/gamecore/core/events/MainLoopRequest.java
  15. 7
      src/mightypork/gamecore/core/modules/AppAccess.java
  16. 11
      src/mightypork/gamecore/core/modules/AppAccessAdapter.java
  17. 151
      src/mightypork/gamecore/core/modules/AppInitOptions.java
  18. 11
      src/mightypork/gamecore/core/modules/AppModule.java
  19. 11
      src/mightypork/gamecore/core/modules/AppSubModule.java
  20. 154
      src/mightypork/gamecore/core/modules/BaseApp.java
  21. 13
      src/mightypork/gamecore/core/modules/MainLoop.java
  22. 7
      src/mightypork/gamecore/gui/components/BaseComponent.java
  23. 14
      src/mightypork/gamecore/gui/components/LayoutComponent.java
  24. 3
      src/mightypork/gamecore/gui/components/LinearComponent.java
  25. 3
      src/mightypork/gamecore/gui/components/input/ClickableWrapper.java
  26. 3
      src/mightypork/gamecore/gui/components/input/TextButton.java
  27. 6
      src/mightypork/gamecore/gui/components/layout/ColumnLayout.java
  28. 6
      src/mightypork/gamecore/gui/components/layout/ConstraintLayout.java
  29. 6
      src/mightypork/gamecore/gui/components/layout/FlowColumnLayout.java
  30. 6
      src/mightypork/gamecore/gui/components/layout/FlowRowLayout.java
  31. 6
      src/mightypork/gamecore/gui/components/layout/GridLayout.java
  32. 6
      src/mightypork/gamecore/gui/components/layout/RowLayout.java
  33. 3
      src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java
  34. 6
      src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java
  35. 6
      src/mightypork/gamecore/gui/components/layout/linear/LinearLayout.java
  36. 3
      src/mightypork/gamecore/gui/components/layout/linear/LinearRectangle.java
  37. 3
      src/mightypork/gamecore/gui/components/layout/linear/LinearSquare.java
  38. 3
      src/mightypork/gamecore/gui/components/layout/linear/LinearWrapper.java
  39. 3
      src/mightypork/gamecore/gui/components/painters/ImagePainter.java
  40. 3
      src/mightypork/gamecore/gui/events/LayoutChangeEvent.java
  41. 3
      src/mightypork/gamecore/gui/events/ScreenRequest.java
  42. 3
      src/mightypork/gamecore/gui/screens/LayeredScreen.java
  43. 19
      src/mightypork/gamecore/gui/screens/Overlay.java
  44. 11
      src/mightypork/gamecore/gui/screens/Screen.java
  45. 9
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  46. 7
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  47. 3
      src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java
  48. 6
      src/mightypork/gamecore/gui/screens/impl/CrossfadeRequest.java
  49. 12
      src/mightypork/gamecore/gui/screens/impl/FadingLayer.java
  50. 3
      src/mightypork/gamecore/gui/screens/impl/LayerColor.java
  51. 3
      src/mightypork/gamecore/input/InputSystem.java
  52. 3
      src/mightypork/gamecore/input/KeyBinding.java
  53. 6
      src/mightypork/gamecore/input/KeyStroke.java
  54. 3
      src/mightypork/gamecore/input/events/KeyEvent.java
  55. 3
      src/mightypork/gamecore/input/events/MouseButtonEvent.java
  56. 3
      src/mightypork/gamecore/input/events/MouseMotionEvent.java
  57. 300
      src/mightypork/gamecore/render/DisplaySystem.java
  58. 542
      src/mightypork/gamecore/render/Render.java
  59. 8
      src/mightypork/gamecore/render/RenderModule.java
  60. 1
      src/mightypork/gamecore/render/TaskTakeScreenshot.java
  61. 6
      src/mightypork/gamecore/render/events/FullscreenToggleRequest.java
  62. 3
      src/mightypork/gamecore/render/events/ViewportChangeEvent.java
  63. 3
      src/mightypork/gamecore/resources/AsyncResourceLoader.java
  64. 3
      src/mightypork/gamecore/resources/BaseLazyResource.java
  65. 3
      src/mightypork/gamecore/resources/ResourceLoadRequest.java
  66. 7
      src/mightypork/gamecore/resources/TextureBasedResource.java
  67. 3
      src/mightypork/gamecore/resources/audio/JointVolume.java
  68. 5
      src/mightypork/gamecore/resources/audio/LazyAudio.java
  69. 3
      src/mightypork/gamecore/resources/audio/SoundRegistry.java
  70. 4
      src/mightypork/gamecore/resources/audio/SoundSystem.java
  71. 3
      src/mightypork/gamecore/resources/audio/Volume.java
  72. 3
      src/mightypork/gamecore/resources/audio/players/BaseAudioPlayer.java
  73. 3
      src/mightypork/gamecore/resources/audio/players/EffectPlayer.java
  74. 3
      src/mightypork/gamecore/resources/audio/players/LoopPlayer.java
  75. 3
      src/mightypork/gamecore/resources/fonts/FontRegistry.java
  76. 6
      src/mightypork/gamecore/resources/fonts/FontRenderer.java
  77. 11
      src/mightypork/gamecore/resources/fonts/impl/LazyFont.java
  78. 3
      src/mightypork/gamecore/resources/fonts/impl/LazyFontNative.java
  79. 13
      src/mightypork/gamecore/resources/fonts/impl/TextureBackedFont.java
  80. 3
      src/mightypork/gamecore/resources/textures/FilterMode.java
  81. 3
      src/mightypork/gamecore/resources/textures/QuadGrid.java
  82. 3
      src/mightypork/gamecore/resources/textures/TextureRegistry.java
  83. 9
      src/mightypork/gamecore/resources/textures/TxQuad.java
  84. 3
      src/mightypork/gamecore/resources/textures/TxSheet.java
  85. 3
      src/mightypork/gamecore/resources/textures/WrapMode.java
  86. 3
      src/mightypork/gamecore/util/SlickLogRedirector.java
  87. 5
      src/mightypork/rogue/Launcher.java
  88. 29
      src/mightypork/rogue/RogueApp.java
  89. 5
      src/mightypork/rogue/RogueResources.java
  90. 4
      src/mightypork/rogue/RogueStateManager.java
  91. 3
      src/mightypork/rogue/events/LoadingOverlayRequest.java
  92. 6
      src/mightypork/rogue/events/RogueStateRequest.java
  93. 6
      src/mightypork/rogue/screens/FpsOverlay.java
  94. 3
      src/mightypork/rogue/screens/LoadingOverlay.java
  95. 7
      src/mightypork/rogue/screens/RogueScreen.java
  96. 7
      src/mightypork/rogue/screens/game/HeartBar.java
  97. 12
      src/mightypork/rogue/screens/game/IngameNav.java
  98. 12
      src/mightypork/rogue/screens/game/InvSlot.java
  99. 3
      src/mightypork/rogue/screens/game/LayerAskSave.java
  100. 4
      src/mightypork/rogue/screens/game/LayerDeath.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,299 @@
//package junk;
//
//
//import static org.lwjgl.opengl.GL11.*;
//
//import java.nio.ByteBuffer;
//
//import mightypork.gamecore.backend.lwjgl.AwtScreenshot;
//import mightypork.gamecore.core.modules.AppAccess;
//import mightypork.gamecore.core.modules.AppModule;
//import mightypork.gamecore.render.events.DisplayReadyEvent;
//import mightypork.gamecore.render.events.ViewportChangeEvent;
//import mightypork.utils.logging.Log;
//import mightypork.utils.math.constraints.rect.Rect;
//import mightypork.utils.math.constraints.rect.RectBound;
//import mightypork.utils.math.constraints.vect.Vect;
//import mightypork.utils.math.timing.FpsMeter;
//
//import org.lwjgl.BufferUtils;
//import org.lwjgl.LWJGLException;
//import org.lwjgl.opengl.Display;
//import org.lwjgl.opengl.DisplayMode;
//
//
///**
// * Display system
// *
// * @author Ondřej Hruška (MightyPork)
// */
//@Deprecated
//public class DisplaySystem extends AppModule implements RectBound {
//
// private DisplayMode windowDisplayMode;
// private int targetFps;
// private FpsMeter fpsMeter;
// private boolean fullscreenSwitchRequested;
//
// /** Current screen size */
// private static final Vect screenSize = new Vect() {
//
// @Override
// public double y()
// {
// return Display.getHeight();
// }
//
//
// @Override
// public double x()
// {
// return Display.getWidth();
// }
// };
//
// private static final Rect rect = Rect.make(screenSize);
//
//
// /**
// * @param app app access
// */
// public DisplaySystem(AppAccess app) {
// super(app);
// }
//
//
// @Override
// protected void deinit()
// {
// Display.destroy();
// }
//
//
// /**
// * Set target fps (for syncing in endFrame() call).<br>
// * With vsync enabled, the target fps may not be met.
// *
// * @param fps requested fps
// */
// public void setTargetFps(int fps)
// {
// this.targetFps = fps;
// }
//
//
// /**
// * Create a main window
// *
// * @param width requested width
// * @param height requested height
// * @param resizable is resizable by the user
// * @param fullscreen is in fullscreen
// * @param title window title
// */
// public void createMainWindow(int width, int height, boolean resizable, boolean fullscreen, String title)
// {
// try {
// Display.setDisplayMode(windowDisplayMode = new DisplayMode(width, height));
// Display.setResizable(resizable);
// Display.setVSyncEnabled(true);
// Display.setTitle(title);
// Display.create();
//
// fpsMeter = new FpsMeter();
//
// if (fullscreen) {
// switchFullscreen();
// Display.update();
// }
//
// getEventBus().send(new DisplayReadyEvent());
//
// } catch (final LWJGLException e) {
// throw new RuntimeException("Could not initialize screen", e);
// }
// }
//
//
// /**
// * Toggle FS if possible
// */
// public void switchFullscreen()
// {
// fullscreenSwitchRequested = true;
// }
//
//
// private void doSwitchFullscreen()
// {
// try {
//
// if (!Display.isFullscreen()) {
// Log.f3("Entering fullscreen.");
// // save window resize
// windowDisplayMode = new DisplayMode(Display.getWidth(), Display.getHeight());
//
// Display.setDisplayMode(Display.getDesktopDisplayMode());
// Display.setFullscreen(true);
// Display.update();
// } else {
// Log.f3("Leaving fullscreen.");
// Display.setDisplayMode(windowDisplayMode);
// Display.update();
// }
//
// getEventBus().send(new ViewportChangeEvent(getSize()));
//
// } catch (final Throwable t) {
// Log.e("Failed to toggle fullscreen mode.", t);
// try {
// Display.setDisplayMode(windowDisplayMode);
// Display.update();
// } catch (final Throwable t1) {
// throw new RuntimeException("Failed to revert failed fullscreen toggle.", t1);
// }
// }
// }
//
//
// /**
// * Take screenshot (expensive processing is done on-demand when screenshot
// * is processed).
// *
// * @return screenshot object
// */
// public static AwtScreenshot prepareScreenshot()
// {
// glReadBuffer(GL_FRONT);
// final int width = Display.getWidth();
// final int height = Display.getHeight();
// final int bpp = 4;
// final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
// glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
//
// final AwtScreenshot sc = new AwtScreenshot(width, height, bpp, buffer);
//
// return sc;
// }
//
//
// /**
// * @return true if close was requested (i.e. click on cross)
// */
// public static boolean isCloseRequested()
// {
// return Display.isCloseRequested();
// }
//
//
// /**
// * Get fullscreen state
// *
// * @return is fullscreen
// */
// public static boolean isFullscreen()
// {
// return Display.isFullscreen();
// }
//
//
// /**
// * Get screen size. This Vect is final and views at it can safely be made.
// *
// * @return size
// */
// public static Vect getSize()
// {
// return screenSize;
// }
//
//
// /**
// * Get screen rect. Static version of getRect().
// *
// * @return size
// */
// public static Rect getBounds()
// {
// return rect;
// }
//
//
// /**
// * @return screen width
// */
// public static int getWidth()
// {
// return screenSize.xi();
// }
//
//
// /**
// * @return screen height
// */
// public static int getHeight()
// {
// return screenSize.yi();
// }
//
//
// /**
// * Start a OpenGL frame
// */
// public void beginFrame()
// {
// // handle resize
// if (Display.wasResized()) {
// getEventBus().send(new ViewportChangeEvent(getSize()));
// }
//
// if (fullscreenSwitchRequested) {
// fullscreenSwitchRequested = false;
// doSwitchFullscreen();
// }
//
// glLoadIdentity();
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// fpsMeter.frame();
// }
//
//
// /**
// * End an OpenGL frame, flip buffers, sync to fps.
// */
// public void endFrame()
// {
// Display.update(false); // don't poll input devices
// Display.sync(targetFps);
// }
//
//
// /**
// * Get screen rect. This Rect is final and views at it can safely be made.
// */
// @Override
// public Rect getRect()
// {
// return getBounds();
// }
//
//
// /**
// * @return current FPS
// */
// public long getFps()
// {
// return fpsMeter.getFPS();
// }
//
//
// /**
// * Get screen center. This vect is final and views at it can safely be made.
// *
// * @return screen center.
// */
// public static Vect getCenter()
// {
// return rect.center();
// }
//}

@ -0,0 +1,542 @@
//package junk;
//
//
//import static org.lwjgl.opengl.GL11.*;
//
//import java.io.IOException;
//
//import mightypork.gamecore.resources.textures.FilterMode;
//import mightypork.gamecore.resources.textures.ITexture;
//import mightypork.gamecore.resources.textures.TxQuad;
//import mightypork.utils.files.FileUtils;
//import mightypork.utils.logging.Log;
//import mightypork.utils.math.color.Color;
//import mightypork.utils.math.color.pal.RGB;
//import mightypork.utils.math.constraints.rect.Rect;
//import mightypork.utils.math.constraints.rect.caching.RectDigest;
//import mightypork.utils.math.constraints.vect.Vect;
//import mightypork.utils.math.constraints.vect.VectConst;
//
//import org.lwjgl.opengl.GL11;
//import org.newdawn.slick.opengl.Texture;
//import org.newdawn.slick.opengl.TextureLoader;
//
//
///**
// * Render utilities
// *
// * @author Ondřej Hruška (MightyPork)
// */
//@Deprecated
//public class Render {
//
// public static final VectConst AXIS_X = Vect.make(1, 0, 0);
// public static final VectConst AXIS_Y = Vect.make(0, 1, 0);
// public static final VectConst AXIS_Z = Vect.make(0, 0, 1);
//
//
// /**
// * Bind GL color
// *
// * @param color Color color
// */
// public static void setColor(Color color)
// {
// if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a());
// }
//
//
// /**
// * Bind GL color
// *
// * @param color Color color
// * @param alpha alpha multiplier
// */
// public static void setColor(Color color, double alpha)
// {
// if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a() * alpha);
// }
//
//
// /**
// * Translate
// *
// * @param x
// * @param y
// */
// public static void translate(double x, double y)
// {
// glTranslated(x, y, 0);
// }
//
//
// /**
// * Translate
// *
// * @param x
// * @param y
// * @param z
// */
// public static void translate(double x, double y, double z)
// {
// glTranslated(x, y, z);
// }
//
//
// /**
// * Translate with coord
// *
// * @param coord coord
// */
// public static void translate(Vect coord)
// {
// glTranslated(coord.x(), coord.y(), coord.z());
// }
//
//
// /**
// * Translate with coord, discard Z
// *
// * @param coord coord
// */
// public static void translateXY(Vect coord)
// {
// glTranslated(coord.x(), coord.y(), 0);
// }
//
//
// /**
// * Scale
// *
// * @param x
// * @param y
// */
// public static void scale(double x, double y)
// {
// glScaled(x, y, 0);
// }
//
//
// /**
// * Scale
// *
// * @param x
// * @param y
// * @param z
// */
// public static void scale(double x, double y, double z)
// {
// glScaled(x, y, z);
// }
//
//
// /**
// * Scale
// *
// * @param factor vector of scaling factors
// */
// public static void scale(Vect factor)
// {
// glScaled(factor.x(), factor.y(), factor.z());
// }
//
//
// /**
// * Scale by X factor
// *
// * @param factor scaling factor
// */
// public static void scaleXY(double factor)
// {
// glScaled(factor, factor, 1);
// }
//
//
// /**
// * Scale by X factor
// *
// * @param factor scaling factor
// */
// public static void scaleX(double factor)
// {
// glScaled(factor, 1, 1);
// }
//
//
// /**
// * Scale by Y factor
// *
// * @param factor scaling factor
// */
// public static void scaleY(double factor)
// {
// glScaled(1, factor, 1);
// }
//
//
// /**
// * Scale by Z factor
// *
// * @param factor scaling factor
// */
// public static void scaleZ(double factor)
// {
// glScaled(1, 1, factor);
// }
//
//
// /**
// * Rotate around X axis
// *
// * @param angle deg
// */
// public static void rotateX(double angle)
// {
// rotate(angle, AXIS_X);
// }
//
//
// /**
// * Rotate around Y axis
// *
// * @param angle deg
// */
// public static void rotateY(double angle)
// {
// rotate(angle, AXIS_Y);
// }
//
//
// /**
// * Rotate around Z axis
// *
// * @param angle deg
// */
// public static void rotateZ(double angle)
// {
// rotate(angle, AXIS_Z);
// }
//
//
// /**
// * Rotate
// *
// * @param angle rotate angle
// * @param axis rotation axis
// */
// public static void rotate(double angle, Vect axis)
// {
// final Vect vec = axis.norm(1);
// glRotated(angle, vec.x(), vec.y(), vec.z());
// }
//
// private static int pushed = 0;
// /** Can be used to avoid texture binding and glBegin/glEnd in textured quads */
// public static boolean batchTexturedQuadMode;
//
//
// /**
// * Store GL state
// */
// public static void pushState()
// {
// pushed++;
//
// if (pushed >= 100) {
// Log.w("Suspicious number of state pushes: " + pushed);
// }
//
// GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
// GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
// GL11.glMatrixMode(GL11.GL_MODELVIEW);
// GL11.glPushMatrix();
// GL11.glMatrixMode(GL11.GL_PROJECTION);
// GL11.glPushMatrix();
// GL11.glMatrixMode(GL11.GL_MODELVIEW);
// }
//
//
// /**
// * Restore Gl state
// */
// public static void popState()
// {
// if (pushed == 0) {
// Log.w("Pop without push.");
// }
//
// pushed--;
//
// GL11.glMatrixMode(GL11.GL_PROJECTION);
// GL11.glPopMatrix();
// GL11.glMatrixMode(GL11.GL_MODELVIEW);
// GL11.glPopMatrix();
// GL11.glPopClientAttrib();
// GL11.glPopAttrib();
// }
//
//
// /**
// * Store matrix
// */
// public static void pushMatrix()
// {
// GL11.glPushMatrix();
// }
//
//
// /**
// * Restore Gl state
// */
// public static void popMatrix()
// {
// GL11.glPopMatrix();
// }
//
//
// /**
// * Load texture
// *
// * @param resourcePath
// * @param filtering filtering mode to use while loading.
// * @return the loaded texture
// */
// public synchronized static Texture loadSlickTexture(String resourcePath, FilterMode filtering)
// {
//
// try {
//
// final String ext = FileUtils.getExtension(resourcePath).toUpperCase();
//
// final Texture texture = TextureLoader.getTexture(ext, FileUtils.getResource(resourcePath), false, filtering.num);
//
// if (texture == null) {
// Log.w("Texture " + resourcePath + " could not be loaded.");
// }
//
// return texture;
//
// } catch (final IOException e) {
// Log.e("Loading of texture " + resourcePath + " failed.", e);
// throw new RuntimeException("Could not load texture " + resourcePath + ".", e);
// }
//
// }
//
//
// /**
// * Render quad 2D
// *
// * @param rect rectangle
// * @param color draw color
// */
// public static void quad(Rect rect, Color color)
// {
// setColor(color);
// quad(rect);
// }
//
//
// /**
// * Render quad
// *
// * @param quad the quad to draw (px)
// */
// public static void quad(Rect quad)
// {
// final RectDigest q = quad.digest();
//
// // draw with color
//
// glDisable(GL_TEXTURE_2D);
//
// // quad
// glBegin(GL_QUADS);
// glVertex2d(q.left, q.bottom);
// glVertex2d(q.right, q.bottom);
// glVertex2d(q.right, q.top);
// glVertex2d(q.left, q.top);
// glEnd();
// }
//
//
// /**
// * Draw quad with horizontal gradient
// *
// * @param quad drawn quad bounds
// * @param color1 left color
// * @param color2 right color
// */
// public static void quadGradH(Rect quad, Color color1, Color color2)
// {
// quadColor(quad, color1, color2, color2, color1);
// }
//
//
// public static void quadColor(Rect quad, Color color)
// {
// quadColor(quad, color, color, color, color);
// }
//
//
// /**
// * Draw quad with coloured vertices.
// *
// * @param quad drawn quad bounds
// * @param colorHMinVMin
// * @param colorHMaxVMin
// * @param colorHMaxVMax
// * @param colorHMinVMax
// */
// public static void quadColor(Rect quad, Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax)
// {
// final RectDigest r = quad.digest();
//
// // draw with color
//
// glDisable(GL_TEXTURE_2D);
//
// glBegin(GL_QUADS);
// setColor(colorHMinVMax);
// glVertex2d(r.left, r.bottom);
//
// setColor(colorHMaxVMax);
// glVertex2d(r.right, r.bottom);
//
// setColor(colorHMaxVMin);
// glVertex2d(r.right, r.top);
//
// setColor(colorHMinVMin);
// glVertex2d(r.left, r.top);
// glEnd();
// }
//
//
// /**
// * Draw quad with vertical gradient
// *
// * @param quad drawn quad bounds
// * @param color1 top color
// * @param color2 bottom color
// */
// public static void quadGradV(Rect quad, Color color1, Color color2)
// {
// quadColor(quad, color1, color1, color2, color2);
// }
//
//
// /**
// * Render textured rect
// *
// * @param quad rectangle (px)
// * @param txquad texture quad
// */
// public static void quadTextured(Rect quad, TxQuad txquad)
// {
// quadTextured(quad, txquad, RGB.WHITE);
// }
//
//
// /**
// * Render textured rect
// *
// * @param quad rectangle (px)
// * @param txquad texture instance
// * @param tint color tint
// */
// public static void quadTextured(Rect quad, TxQuad txquad, Color tint)
// {
// if (!batchTexturedQuadMode) {
// glEnable(GL_TEXTURE_2D);
// txquad.tx.bind();
// glBegin(GL_QUADS);
// setColor(tint);
// }
//
// final RectDigest q = quad.digest();
// final RectDigest u = txquad.uvs.digest();
//
// final double offs = 0.0001;// hack to avoid white stitching
//
// double tL = u.left + offs, tR = u.right - offs, tT = u.top + offs, tB = u.bottom - offs;
//
// // handle flip
// if (txquad.isFlippedY()) {
// final double swap = tT;
// tT = tB;
// tB = swap;
// }
//
// if (txquad.isFlippedX()) {
// final double swap = tL;
// tL = tR;
// tR = swap;
// }
//
// final double w = txquad.tx.getWidth01();
// final double h = txquad.tx.getHeight01();
//
// // quad with texture
// glTexCoord2d(tL * w, tB * h);
// glVertex2d(q.left, q.bottom);
//
// glTexCoord2d(tR * w, tB * h);
// glVertex2d(q.right, q.bottom);
//
// glTexCoord2d(tR * w, tT * h);
// glVertex2d(q.right, q.top);
//
// glTexCoord2d(tL * w, tT * h);
// glVertex2d(q.left, q.top);
//
// if (!batchTexturedQuadMode) glEnd();
// }
//
//
// /**
// * Setup Ortho projection for 2D graphics
// *
// * @param size viewport size (screen size)
// */
// public static void setupOrtho(Vect size)
// {
// // fix projection for changed size
// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// glViewport(0, 0, size.xi(), size.yi());
// glOrtho(0, size.xi(), size.yi(), 0, -1000, 1000);
//
// // back to modelview
// glMatrixMode(GL_MODELVIEW);
//
// glLoadIdentity();
//
// glDisable(GL_LIGHTING);
//
// glClearDepth(1f);
// glEnable(GL_DEPTH_TEST);
// glDepthFunc(GL_LEQUAL);
//
// glEnable(GL_NORMALIZE);
//
// glShadeModel(GL_SMOOTH);
//
// glEnable(GL_BLEND);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// }
//
//
// public static void enterBatchTexturedQuadMode(ITexture texture)
// {
// texture.bind();
// glBegin(GL11.GL_QUADS);
// batchTexturedQuadMode = true;
// }
//
//
// public static void leaveBatchTexturedQuadMode()
// {
// glEnd();
// batchTexturedQuadMode = false;
// }
//}

@ -7,16 +7,14 @@ import mightypork.utils.eventbus.clients.RootBusNode;
/**
* Application backend interface (set of core modules)
* Application backend interface (set of core modules).<br>
* Backend is created without a bus access, which will be assigned during app
* initialization.
*
* @author MightyPork
*/
public abstract class Backend extends RootBusNode {
public Backend(BusAccess busAccess) {
super(busAccess);
}
/**
* Initialize backend modules, add them to event bus.<br>

@ -1,7 +1,7 @@
package mightypork.gamecore.backend;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.eventbus.BusAccess;
import mightypork.utils.eventbus.clients.BusNode;
import mightypork.utils.interfaces.Destroyable;
@ -23,10 +23,11 @@ public abstract class BackendModule extends BusNode implements Destroyable {
super(busAccess);
}
@Override
@DefaultImpl
@Stub
public void destroy()
{
{
}
}

@ -33,8 +33,7 @@ public class AwtScreenshot implements Screenshot {
* @param bpp bits per pixel (typically 4)
* @param buffer
*/
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;

@ -13,11 +13,6 @@ import mightypork.utils.eventbus.BusAccess;
*/
public class LwjglBackend extends Backend {
public LwjglBackend(BusAccess busAccess) {
super(busAccess);
}
private LwjglRenderModule renderer;

@ -6,12 +6,6 @@ import static org.lwjgl.opengl.GL11.*;
import java.nio.ByteBuffer;
import java.util.Stack;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import mightypork.gamecore.render.Grad;
import mightypork.gamecore.render.RenderModule;
import mightypork.gamecore.render.Screenshot;
@ -29,6 +23,12 @@ import mightypork.utils.math.constraints.rect.caching.RectDigest;
import mightypork.utils.math.constraints.vect.Vect;
import mightypork.utils.math.timing.FpsMeter;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
/**
* LWJGL rendering module
@ -376,13 +376,17 @@ public class LwjglRenderModule extends RenderModule {
@Override
public void setupProjection(Vect screenSize)
public void setupProjection()
{
// fix projection for changed size
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, screenSize.xi(), screenSize.yi());
glOrtho(0, screenSize.xi(), screenSize.yi(), 0, -1000, 1000);
int w = Display.getWidth();
int h = Display.getHeight();
glViewport(0, 0, w, h);
glOrtho(0, w, h, 0, -1000, 1000);
// back to modelview
glMatrixMode(GL_MODELVIEW);

@ -4,10 +4,11 @@ package mightypork.gamecore.backend.lwjgl;
import java.io.IOException;
import mightypork.gamecore.resources.TextureBasedResource;
import mightypork.gamecore.resources.textures.*;
import mightypork.gamecore.resources.textures.LazyTexture;
import mightypork.utils.annotations.Alias;
import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.Log;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
@ -26,6 +27,7 @@ public class SlickLazyTexture extends LazyTexture {
private boolean alpha;
private boolean alphal;
/**
* @param resourcePath resource path
*/
@ -33,6 +35,7 @@ public class SlickLazyTexture extends LazyTexture {
super(resourcePath);
}
@Override
protected synchronized void loadResource(String path)
{

@ -116,6 +116,7 @@ public class Config {
/**
* Add "key." before the given config file key
*
* @param cfgKey config key
* @return key. + cfgKey
*/

@ -1,11 +1,13 @@
package mightypork.gamecore.core.config;
import mightypork.utils.files.config.PropertyManager;
/**
* Config setup, class used to populate the config file.
*/
public interface ConfigSetup {
void addOptions(PropertyManager prop);
}
}

@ -1,13 +1,14 @@
package mightypork.gamecore.core.config;
import mightypork.gamecore.input.KeyStroke;
/**
* Key options - restricted access to {@link Config} for keys
*/
public class KeyOpts {
public void add(String cfgKey, String dataString)
{
add(cfgKey, dataString, null);
@ -16,7 +17,8 @@ public class KeyOpts {
/**
* @param cfgKey key in config file
* @param dataString string representing the keystroke (format for {@link KeyStroke})
* @param dataString string representing the keystroke (format for
* {@link KeyStroke})
* @param comment optional comment
*/
public void add(String cfgKey, String dataString, String comment)
@ -25,4 +27,4 @@ public class KeyOpts {
Config.strokes.put(Config.prefixKey(cfgKey), kprop);
Config.cfg.putProperty(kprop);
}
}
}

@ -1,9 +1,11 @@
package mightypork.gamecore.core.config;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.utils.files.config.Property;
/**
* Key property.<br>
* The stored value must be invariant ({@link KeyStroke} is mutable).
@ -12,8 +14,7 @@ import mightypork.utils.files.config.Property;
*/
public class KeyProperty extends Property<KeyStroke> {
public KeyProperty(String key, KeyStroke defaultValue, String comment)
{
public KeyProperty(String key, KeyStroke defaultValue, String comment) {
super(key, defaultValue, comment);
}
@ -50,4 +51,4 @@ public class KeyProperty extends Property<KeyStroke> {
// keep it invariant
getValue().setTo(((KeyStroke) value).getKey(), ((KeyStroke) value).getMod());
}
}
}

@ -7,4 +7,4 @@ package mightypork.gamecore.core.config;
public interface KeySetup {
public void addKeys(KeyOpts keys);
}
}

@ -22,8 +22,7 @@ public class MainLoopRequest extends BusEvent<MainLoop> {
* @param task task to run on main thread in rendering context
* @param priority if true, skip other tasks in queue
*/
public MainLoopRequest(Runnable task, boolean priority)
{
public MainLoopRequest(Runnable task, boolean priority) {
this.task = task;
this.priority = priority;
}

@ -2,7 +2,6 @@ package mightypork.gamecore.core.modules;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.audio.SoundSystem;
import mightypork.utils.eventbus.BusAccess;
@ -26,12 +25,6 @@ public interface AppAccess extends BusAccess {
abstract InputSystem getInput();
/**
* @return display system
*/
abstract DisplaySystem getDisplay();
/**
* Quit to OS<br>
* Destroy app & exit VM

@ -2,7 +2,6 @@ package mightypork.gamecore.core.modules;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.audio.SoundSystem;
import mightypork.utils.eventbus.EventBus;
@ -20,8 +19,7 @@ public class AppAccessAdapter implements AppAccess {
/**
* @param app app access
*/
public AppAccessAdapter(AppAccess app)
{
public AppAccessAdapter(AppAccess app) {
if (app == null) throw new NullPointerException("AppAccess instance cannot be null.");
this.app = app;
@ -42,13 +40,6 @@ public class AppAccessAdapter implements AppAccess {
}
@Override
public final DisplaySystem getDisplay()
{
return app.getDisplay();
}
@Override
public final EventBus getEventBus()
{

@ -0,0 +1,151 @@
package mightypork.gamecore.core.modules;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import mightypork.gamecore.backend.Backend;
import mightypork.gamecore.core.WorkDir.RouteSetup;
import mightypork.gamecore.core.config.ConfigSetup;
import mightypork.gamecore.core.config.KeySetup;
import mightypork.gamecore.resources.AsyncResourceLoader;
import mightypork.gamecore.resources.ResourceLoader;
import mightypork.gamecore.resources.ResourceSetup;
/**
* Init options holder class
*/
public class AppInitOptions {
boolean singleInstance = false;
Backend backend = null;
File workdir = null;
String logDir = "log";
String logFilePrefix = "runtime";
String screenshotDir = "screenshots";
int logArchiveCount = 0;
boolean busLogging = false;
String configFile = "settings.cfg";
String configComment = "Main config file";
public String lockFile = ".lock";
final List<ResourceSetup> resourceLists = new ArrayList<>();
final List<KeySetup> keyLists = new ArrayList<>();
final List<ConfigSetup> configLists = new ArrayList<>();
final List<RouteSetup> routeLists = new ArrayList<>();
ResourceLoader resourceLoader = new AsyncResourceLoader();
Level logLevel = Level.ALL;
public boolean sigleInstance = true;
Level logSoutLevel = Level.ALL;
public void setConfigFile(String filename, String comment)
{
configFile = filename;
configComment = comment;
}
public void addConfig(ConfigSetup cfg)
{
configLists.add(cfg);
}
public void addKeys(KeySetup keys)
{
keyLists.add(keys);
}
public void addRoutes(RouteSetup keys)
{
routeLists.add(keys);
}
public void addResources(ResourceSetup res)
{
resourceLists.add(res);
}
public void setBackend(Backend backend)
{
this.backend = backend;
}
/**
* Set whether to run in single instance mode, or allow multiple instances.<br>
* Multiple instances running can cause various collisions (eg. when writing
* config file or logging).
*
* @param sigleInstance true to allow only one instance
*/
public void setSigleInstance(boolean sigleInstance)
{
this.sigleInstance = sigleInstance;
}
/**
* Set working directory path. If not exists, it will be created.
*
* @param workdir work dir path
*/
public void setWorkdir(File workdir)
{
this.workdir = workdir;
}
public void setBusLogging(boolean yes)
{
busLogging = yes;
}
public void setLogOptions(String logDir, String filePrefix, int archivedCount, Level logLevel)
{
this.logDir = logDir;
this.logFilePrefix = filePrefix;
this.logArchiveCount = archivedCount;
this.logLevel = logLevel;
}
public void setResourceLoader(ResourceLoader resLoader)
{
resourceLoader = resLoader;
}
public void setScreenshotDir(String path)
{
this.screenshotDir = path;
}
public void setLockFile(String lockFile)
{
this.lockFile = lockFile;
}
public void setLogLevel(Level logLevel, Level soutLevel)
{
this.logLevel = logLevel;
this.logSoutLevel = soutLevel;
}
}

@ -2,7 +2,6 @@ package mightypork.gamecore.core.modules;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.audio.SoundSystem;
import mightypork.utils.eventbus.clients.RootBusNode;
@ -23,8 +22,7 @@ public abstract class AppModule extends RootBusNode implements AppAccess {
*
* @param app access to app systems
*/
public AppModule(AppAccess app)
{
public AppModule(AppAccess app) {
super(app);
this.app = app;
@ -45,13 +43,6 @@ public abstract class AppModule extends RootBusNode implements AppAccess {
}
@Override
public final DisplaySystem getDisplay()
{
return app.getDisplay();
}
@Override
public final void shutdown()
{

@ -2,7 +2,6 @@ package mightypork.gamecore.core.modules;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.audio.SoundSystem;
import mightypork.utils.eventbus.clients.BusNode;
import mightypork.utils.eventbus.clients.DelegatingClient;
@ -25,8 +24,7 @@ public class AppSubModule extends BusNode implements AppAccess {
*
* @param app access to app systems
*/
public AppSubModule(AppAccess app)
{
public AppSubModule(AppAccess app) {
super(app);
this.app = app;
@ -47,13 +45,6 @@ public class AppSubModule extends BusNode implements AppAccess {
}
@Override
public final DisplaySystem getDisplay()
{
return app.getDisplay();
}
@Override
public final void shutdown()
{

@ -4,9 +4,6 @@ package mightypork.gamecore.core.modules;
import java.io.File;
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
@ -19,14 +16,12 @@ import mightypork.gamecore.core.config.KeySetup;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.AsyncResourceLoader;
import mightypork.gamecore.render.RenderModule;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.ResourceLoader;
import mightypork.gamecore.resources.ResourceSetup;
import mightypork.gamecore.resources.audio.SoundSystem;
import mightypork.gamecore.util.SlickLogRedirector;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.eventbus.EventBus;
import mightypork.utils.eventbus.events.DestroyEvent;
import mightypork.utils.files.InstanceLock;
@ -48,109 +43,8 @@ import mightypork.utils.math.algo.Move;
*/
public abstract class BaseApp extends App implements AppAccess, UncaughtExceptionHandler {
/**
* Init options holder class
*/
public class AppInitOptions {
private String logDir = "log";
private String logFilePrefix = "runtime";
private String screenshotDir = "screenshots";
private int logArchiveCount = 0;
private boolean busLogging = false;
private String configFile = "settings.cfg";
private String configComment = "Main config file";
public String lockFile = ".lock";
private final List<ResourceSetup> resourceLists = new ArrayList<>();
private final List<KeySetup> keyLists = new ArrayList<>();
private final List<ConfigSetup> configLists = new ArrayList<>();
private final List<RouteSetup> routeLists = new ArrayList<>();
private ResourceLoader resourceLoader = new AsyncResourceLoader();
private Level logLevel = Level.ALL;
public boolean sigleInstance;
private Level logSoutLevel;
public void setConfigFile(String filename, String comment)
{
configFile = filename;
configComment = comment;
}
public void addConfig(ConfigSetup cfg)
{
configLists.add(cfg);
}
public void addKeys(KeySetup keys)
{
keyLists.add(keys);
}
public void addRoutes(RouteSetup keys)
{
routeLists.add(keys);
}
public void addResources(ResourceSetup res)
{
resourceLists.add(res);
}
public void setBusLogging(boolean yes)
{
busLogging = yes;
}
public void setLogOptions(String logDir, String filePrefix, int archivedCount, Level logLevel)
{
this.logDir = logDir;
this.logFilePrefix = filePrefix;
this.logArchiveCount = archivedCount;
this.logLevel = logLevel;
}
public void setResourceLoader(ResourceLoader resLoader)
{
resourceLoader = resLoader;
}
public void setScreenshotDir(String path)
{
this.screenshotDir = path;
}
public void setLockFile(String lockFile)
{
this.lockFile = lockFile;
}
public void setLogLevel(Level logLevel, Level soutLevel)
{
this.logLevel = logLevel;
this.logSoutLevel = soutLevel;
}
}
// modules
private InputSystem inputSystem;
private DisplaySystem displaySystem;
private SoundSystem soundSystem;
private EventBus eventBus;
private MainLoop gameLoop;
@ -177,11 +71,11 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
}
public BaseApp(File workdir, boolean singleInstance) {
public BaseApp(Backend backend) {
WorkDir.init(workdir);
opt.sigleInstance = singleInstance;
eventBus = new EventBus();
setBackend(backend);
backend.setBusAccess(this);
}
@ -207,6 +101,8 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
*/
protected void initialize()
{
WorkDir.init(opt.workdir);
if (opt.sigleInstance) initLock();
lockObtained = true;
@ -265,8 +161,7 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
* Display
*/
Log.f2("Initializing Display System...");
displaySystem = new DisplaySystem(this);
initDisplay(displaySystem);
initDisplay(gfx());
/*
* Audio
@ -393,7 +288,7 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
* Called at the beginning of the initialization sequence, right after lock
* was obtained.
*/
@DefaultImpl
@Stub
protected void preInit()
{
}
@ -402,22 +297,26 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
/**
* Called at the end of init sequence, before main loop starts.
*/
@DefaultImpl
@Stub
protected void postInit()
{
}
/**
* Create window and configure display system
* Create window and configure rendering system
*
* @param display
* @param gfx Graphics module
*/
@DefaultImpl
protected void initDisplay(DisplaySystem display)
@Stub
protected void initDisplay(RenderModule gfx)
{
display.createMainWindow(800, 600, true, false, "LWJGL game");
display.setTargetFps(60);
gfx.setSize(800, 600);
gfx.setResizable(true);
gfx.setTitle("New Game");
gfx.setTargetFps(60);
gfx.createDisplay();
}
@ -426,7 +325,7 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
*
* @param audio
*/
@DefaultImpl
@Stub
protected void initSoundSystem(SoundSystem audio)
{
}
@ -467,7 +366,7 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
}
@DefaultImpl
@Stub
protected void initInputSystem(InputSystem input)
{
}
@ -508,13 +407,6 @@ public abstract class BaseApp extends App implements AppAccess, UncaughtExceptio
}
@Override
public final DisplaySystem getDisplay()
{
return displaySystem;
}
@Override
public final EventBus getEventBus()
{

@ -9,7 +9,7 @@ import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.render.TaskTakeScreenshot;
import mightypork.gamecore.render.events.ScreenshotRequestListener;
import mightypork.utils.Support;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.eventbus.events.UpdateEvent;
import mightypork.utils.logging.Log;
import mightypork.utils.math.timing.Profiler;
@ -35,8 +35,7 @@ public class MainLoop extends AppModule implements ScreenshotRequestListener {
/**
* @param app {@link AppAccess} instance
*/
public MainLoop(AppAccess app)
{
public MainLoop(AppAccess app) {
super(app);
}
@ -61,7 +60,7 @@ public class MainLoop extends AppModule implements ScreenshotRequestListener {
timer = new TimerDelta();
while (running) {
getDisplay().beginFrame();
App.gfx().beginFrame();
double delta = timer.getDelta();
if (delta > MAX_DELTA) {
@ -90,7 +89,7 @@ public class MainLoop extends AppModule implements ScreenshotRequestListener {
afterRender();
getDisplay().endFrame();
App.gfx().endFrame();
}
}
@ -98,7 +97,7 @@ public class MainLoop extends AppModule implements ScreenshotRequestListener {
/**
* Called before render
*/
@DefaultImpl
@Stub
protected void beforeRender()
{
//
@ -108,7 +107,7 @@ public class MainLoop extends AppModule implements ScreenshotRequestListener {
/**
* Called after render
*/
@DefaultImpl
@Stub
protected void afterRender()
{
//

@ -6,7 +6,7 @@ import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.Renderable;
import mightypork.utils.Support;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.interfaces.Enableable;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.Color;
@ -33,8 +33,7 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
private Num alphaMul = Num.ONE;
public BaseComponent()
{
public BaseComponent() {
enableCaching(false);
}
@ -110,7 +109,7 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
@Override
@DefaultImpl
@Stub
public void updateLayout()
{
}

@ -7,7 +7,6 @@ import java.util.LinkedList;
import mightypork.gamecore.core.modules.AppAccess;
import mightypork.gamecore.core.modules.AppSubModule;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.audio.SoundSystem;
import mightypork.utils.eventbus.EventBus;
import mightypork.utils.eventbus.clients.ClientHub;
@ -20,16 +19,14 @@ public abstract class LayoutComponent extends BaseComponent implements ClientHub
final LinkedList<Component> components = new LinkedList<>();
public LayoutComponent(AppAccess app, RectBound context)
{
public LayoutComponent(AppAccess app, RectBound context) {
this.subModule = new AppSubModule(app);
setRect(context);
enableCaching(true); // layout is typically updated only when screen resizes.
}
public LayoutComponent(AppAccess app)
{
public LayoutComponent(AppAccess app) {
this(app, null);
}
@ -76,13 +73,6 @@ public abstract class LayoutComponent extends BaseComponent implements ClientHub
}
@Override
public DisplaySystem getDisplay()
{
return subModule.getDisplay();
}
@Override
public void shutdown()
{

@ -52,8 +52,7 @@ public abstract class LinearComponent extends BaseComponent implements DynamicWi
private Num height;
public LinearComponent()
{
public LinearComponent() {
super.setRect(rect);
}

@ -14,8 +14,7 @@ public class ClickableWrapper extends ClickableComponent implements DelegatingCl
private final ClientList list;
public ClickableWrapper(Component wrapped)
{
public ClickableWrapper(Component wrapped) {
this.wrapped = wrapped;
wrapped.setRect(this);

@ -32,8 +32,7 @@ public class TextButton extends ClickableComponent implements DynamicWidthCompon
private boolean hoverMove = true;
public TextButton(GLFont font, String text, Color color)
{
public TextButton(GLFont font, String text, Color color) {
this.color = color;
this.textPainter = new TextPainter(font, AlignX.CENTER, this.color, text);

@ -11,14 +11,12 @@ public class ColumnLayout extends GridLayout {
private int col = 0;
public ColumnLayout(AppAccess app, int rows)
{
public ColumnLayout(AppAccess app, int rows) {
this(app, null, rows);
}
public ColumnLayout(AppAccess app, RectBound context, int cols)
{
public ColumnLayout(AppAccess app, RectBound context, int cols) {
super(app, context, 1, cols);
}

@ -14,14 +14,12 @@ import mightypork.utils.math.constraints.rect.RectBound;
*/
public class ConstraintLayout extends LayoutComponent {
public ConstraintLayout(AppAccess app)
{
public ConstraintLayout(AppAccess app) {
super(app);
}
public ConstraintLayout(AppAccess app, RectBound context)
{
public ConstraintLayout(AppAccess app, RectBound context) {
super(app, context);
}

@ -28,8 +28,7 @@ public class FlowColumnLayout extends LayoutComponent {
* @param elementWidth width of all elements
* @param align component align. Legal values are LEFT and RIGHT.
*/
public FlowColumnLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align)
{
public FlowColumnLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align) {
super(app, context);
this.elementWidth = elementWidth;
this.align = align;
@ -48,8 +47,7 @@ public class FlowColumnLayout extends LayoutComponent {
* @param elementWidth width of all elements
* @param align component align. Legal values are LEFT and RIGHT.
*/
public FlowColumnLayout(AppAccess app, Num elementWidth, AlignX align)
{
public FlowColumnLayout(AppAccess app, Num elementWidth, AlignX align) {
this(app, null, elementWidth, align);
}

@ -28,8 +28,7 @@ public class FlowRowLayout extends LayoutComponent {
* @param elementHeight height of all elements
* @param align component align. Legal values are TOP and BOTTOM.
*/
public FlowRowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align)
{
public FlowRowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align) {
super(app, context);
this.elementHeight = elementHeight;
this.align = align;
@ -48,8 +47,7 @@ public class FlowRowLayout extends LayoutComponent {
* @param elementHeight height of all elements
* @param align component align. Legal values are TOP and BOTTOM.
*/
public FlowRowLayout(AppAccess app, Num elementHeight, AlignY align)
{
public FlowRowLayout(AppAccess app, Num elementHeight, AlignY align) {
this(app, null, elementHeight, align);
}

@ -24,8 +24,7 @@ public class GridLayout extends LayoutComponent {
* @param rows number of rows
* @param cols number of columns
*/
public GridLayout(AppAccess app, RectBound context, int rows, int cols)
{
public GridLayout(AppAccess app, RectBound context, int rows, int cols) {
super(app, context);
this.tiler = tiles(cols, rows);
}
@ -39,8 +38,7 @@ public class GridLayout extends LayoutComponent {
* @param rows number of rows
* @param cols number of columns
*/
public GridLayout(AppAccess app, int rows, int cols)
{
public GridLayout(AppAccess app, int rows, int cols) {
this(app, null, rows, cols);
}

@ -11,14 +11,12 @@ public class RowLayout extends GridLayout {
private int row = 0;
public RowLayout(AppAccess app, int rows)
{
public RowLayout(AppAccess app, int rows) {
this(app, null, rows);
}
public RowLayout(AppAccess app, RectBound context, int rows)
{
public RowLayout(AppAccess app, RectBound context, int rows) {
super(app, context, rows, 1);
}

@ -23,8 +23,7 @@ public abstract class AbstractLinearWrapper extends LinearComponent implements D
/**
* @param wrapped wrapped component. Can be null.
*/
public AbstractLinearWrapper(Component wrapped)
{
public AbstractLinearWrapper(Component wrapped) {
this.wrapped = wrapped;
if (wrapped != null) {
if (wrapped instanceof LinearComponent) {

@ -12,14 +12,12 @@ import mightypork.utils.math.constraints.num.Num;
*/
public class LinearGap extends LinearRectangle {
public LinearGap(Num width)
{
public LinearGap(Num width) {
super(new NullComponent(), width);
}
public LinearGap(double heightPercent)
{
public LinearGap(double heightPercent) {
this(Num.ZERO);
setWidth(height().perc(heightPercent));
}

@ -15,15 +15,13 @@ import mightypork.utils.math.constraints.vect.proxy.VectAdapter;
public class LinearLayout extends LayoutComponent {
public LinearLayout(AppAccess app, AlignX align)
{
public LinearLayout(AppAccess app, AlignX align) {
super(app);
this.align = align;
}
public LinearLayout(AppAccess app, RectBound context, AlignX align)
{
public LinearLayout(AppAccess app, RectBound context, AlignX align) {
super(app, context);
this.align = align;
}

@ -10,8 +10,7 @@ public class LinearRectangle extends AbstractLinearWrapper {
private Num width;
public LinearRectangle(Component wrapped, Num width)
{
public LinearRectangle(Component wrapped, Num width) {
super(wrapped);
this.width = width;
}

@ -6,8 +6,7 @@ import mightypork.gamecore.gui.components.Component;
public class LinearSquare extends AbstractLinearWrapper {
public LinearSquare(Component wrapped)
{
public LinearSquare(Component wrapped) {
super(wrapped);
}

@ -6,8 +6,7 @@ import mightypork.gamecore.gui.components.DynamicWidthComponent;
public class LinearWrapper extends AbstractLinearWrapper {
public LinearWrapper(DynamicWidthComponent wrapped)
{
public LinearWrapper(DynamicWidthComponent wrapped) {
super(wrapped);
}

@ -20,8 +20,7 @@ public class ImagePainter extends BaseComponent implements DynamicWidthComponent
/**
* @param txQuad drawn image
*/
public ImagePainter(TxQuad txQuad)
{
public ImagePainter(TxQuad txQuad) {
this.txQuad = txQuad;
}

@ -18,8 +18,7 @@ import mightypork.utils.eventbus.events.flags.NonRejectableEvent;
@NonRejectableEvent
public class LayoutChangeEvent extends BusEvent<LayoutChangeListener> {
public LayoutChangeEvent()
{
public LayoutChangeEvent() {
}

@ -19,8 +19,7 @@ public class ScreenRequest extends BusEvent<ScreenRequestListener> {
/**
* @param screenKey screen name
*/
public ScreenRequest(String screenKey)
{
public ScreenRequest(String screenKey) {
scrName = screenKey;
}

@ -50,8 +50,7 @@ public abstract class LayeredScreen extends Screen {
/**
* @param app app access
*/
public LayeredScreen(AppAccess app)
{
public LayeredScreen(AppAccess app) {
super(app);
addChildClient(layersClient);
}

@ -4,17 +4,19 @@ package mightypork.gamecore.gui.screens;
import java.util.ArrayList;
import java.util.Collection;
import mightypork.gamecore.core.modules.App;
import mightypork.gamecore.core.modules.AppAccess;
import mightypork.gamecore.core.modules.AppSubModule;
import mightypork.gamecore.gui.Hideable;
import mightypork.gamecore.gui.components.layout.ConstraintLayout;
import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.Renderable;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.interfaces.Enableable;
import mightypork.utils.interfaces.Updateable;
import mightypork.utils.math.color.Color;
@ -28,8 +30,7 @@ import mightypork.utils.math.constraints.vect.Vect;
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class Overlay extends AppSubModule implements Comparable<Overlay>, Updateable, Renderable, KeyBinder, Hideable, Enableable,
LayoutChangeListener {
public abstract class Overlay extends AppSubModule implements Comparable<Overlay>, Updateable, Renderable, KeyBinder, Hideable, Enableable, LayoutChangeListener {
private boolean visible = true;
private boolean enabled = true;
@ -50,13 +51,13 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
private Num alphaMul = Num.ONE;
public Overlay(AppAccess app)
{
public Overlay(AppAccess app) {
super(app);
this.mouse = getInput().getMousePos();
getInput();
this.mouse = InputSystem.getMousePos();
this.root = new ConstraintLayout(app, getDisplay());
this.root = new ConstraintLayout(app, App.gfx().getRect());
addChildClient(root);
addChildClient(keybindings);
@ -117,7 +118,7 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
*
* @return higher = on top.
*/
@DefaultImpl
@Stub
public abstract int getZIndex();
@ -178,7 +179,7 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
* </p>
*/
@Override
@DefaultImpl
@Stub
public void onLayoutChanged()
{
}

@ -10,9 +10,8 @@ import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.Renderable;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.rect.RectBound;
@ -112,7 +111,7 @@ public abstract class Screen extends AppSubModule implements Renderable, RectBou
@Override
public final Rect getRect()
{
return getDisplay().getRect();
return App.gfx().getRect();
}
@ -122,7 +121,7 @@ public abstract class Screen extends AppSubModule implements Renderable, RectBou
if (!isActive()) return;
if (needSetupViewport) {
App.gfx().setupProjection(DisplaySystem.getSize());
App.gfx().setupProjection();
}
App.gfx().pushState();
@ -136,7 +135,7 @@ public abstract class Screen extends AppSubModule implements Renderable, RectBou
/**
* Called when the screen becomes active
*/
@DefaultImpl
@Stub
protected void onScreenEnter()
{
}
@ -145,7 +144,7 @@ public abstract class Screen extends AppSubModule implements Renderable, RectBou
/**
* Called when the screen is no longer active
*/
@DefaultImpl
@Stub
protected void onScreenLeave()
{
}

@ -1,7 +1,7 @@
package mightypork.gamecore.gui.screens;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
/**
@ -17,8 +17,7 @@ public abstract class ScreenLayer extends Overlay {
/**
* @param screen parent screen
*/
public ScreenLayer(Screen screen)
{
public ScreenLayer(Screen screen) {
super(screen); // screen as AppAccess
this.screen = screen;
@ -37,7 +36,7 @@ public abstract class ScreenLayer extends Overlay {
/**
* Called when the screen becomes active
*/
@DefaultImpl
@Stub
protected void onScreenEnter()
{
}
@ -46,7 +45,7 @@ public abstract class ScreenLayer extends Overlay {
/**
* Called when the screen is no longer active
*/
@DefaultImpl
@Stub
protected void onScreenLeave()
{
}

@ -13,7 +13,7 @@ import mightypork.gamecore.gui.events.ScreenRequestListener;
import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.render.events.ViewportChangeEvent;
import mightypork.gamecore.render.events.ViewportChangeListener;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.logging.Log;
@ -32,8 +32,7 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
/**
* @param app app access
*/
public ScreenRegistry(AppAccess app)
{
public ScreenRegistry(AppAccess app) {
super(app);
}
@ -102,7 +101,7 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
@Override
@DefaultImpl
@Stub
protected void deinit()
{
//

@ -41,8 +41,7 @@ public class CrossfadeOverlay extends Overlay {
};
public CrossfadeOverlay(AppAccess app)
{
public CrossfadeOverlay(AppAccess app) {
super(app);
final QuadPainter qp = new QuadPainter(RGB.BLACK); // TODO allow custom colors

@ -19,8 +19,7 @@ public class CrossfadeRequest extends BusEvent<CrossfadeOverlay> {
* @param screen screen key to show. Null = exit the app.
* @param fromDark true to fade from full black (ie. start of the game)
*/
public CrossfadeRequest(String screen, boolean fromDark)
{
public CrossfadeRequest(String screen, boolean fromDark) {
super();
this.screen = screen;
this.fromDark = fromDark;
@ -30,8 +29,7 @@ public class CrossfadeRequest extends BusEvent<CrossfadeOverlay> {
/**
* @param screen screen key to show. Null = exit the app.
*/
public CrossfadeRequest(String screen)
{
public CrossfadeRequest(String screen) {
super();
this.screen = screen;
this.fromDark = false;

@ -3,7 +3,7 @@ package mightypork.gamecore.gui.screens.impl;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
import mightypork.utils.math.animation.Easing;
import mightypork.utils.math.animation.NumAnimated;
import mightypork.utils.math.timing.TimedTask;
@ -47,8 +47,7 @@ public abstract class FadingLayer extends ScreenLayer {
*
* @param screen
*/
public FadingLayer(Screen screen)
{
public FadingLayer(Screen screen) {
this(screen, new NumAnimated(1, Easing.QUADRATIC_OUT, 0.3));
}
@ -57,8 +56,7 @@ public abstract class FadingLayer extends ScreenLayer {
* @param screen
* @param easingAnim the animation num
*/
public FadingLayer(Screen screen, NumAnimated easingAnim)
{
public FadingLayer(Screen screen, NumAnimated easingAnim) {
super(screen);
numa = easingAnim;
@ -74,7 +72,7 @@ public abstract class FadingLayer extends ScreenLayer {
/**
* Called after the fade-out was completed
*/
@DefaultImpl
@Stub
protected void onHideFinished()
{
}
@ -83,7 +81,7 @@ public abstract class FadingLayer extends ScreenLayer {
/**
* Called after the fade-in was completed
*/
@DefaultImpl
@Stub
protected void onShowFinished()
{
}

@ -12,8 +12,7 @@ public class LayerColor extends ScreenLayer {
private final int zIndex;
public LayerColor(Screen screen, Color color, int zIndex)
{
public LayerColor(Screen screen, Color color, int zIndex) {
super(screen);
final QuadPainter qp = new QuadPainter(color);

@ -58,8 +58,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
/**
* @param app app access
*/
public InputSystem(AppAccess app)
{
public InputSystem(AppAccess app) {
super(app);
initDevices();

@ -25,8 +25,7 @@ public class KeyBinding implements KeyEventHandler, InputReadyListener {
* @param stroke trigger keystroke
* @param handler action
*/
public KeyBinding(KeyStroke stroke, Edge edge, Runnable handler)
{
public KeyBinding(KeyStroke stroke, Edge edge, Runnable handler) {
this.keystroke = stroke;
this.handler = handler;
this.edge = edge;

@ -28,8 +28,7 @@ public class KeyStroke { //implements Pollable
* @param key key code
* @param mod_mask mods mask
*/
public KeyStroke(int key, int mod_mask)
{
public KeyStroke(int key, int mod_mask) {
setTo(key, mod_mask);
}
@ -39,8 +38,7 @@ public class KeyStroke { //implements Pollable
*
* @param key key code
*/
public KeyStroke(int key)
{
public KeyStroke(int key) {
this(key, Keys.MOD_NONE);
}

@ -25,8 +25,7 @@ public class KeyEvent extends BusEvent<KeyEventHandler> {
* @param c typed char (can be zero char)
* @param down true = pressed, false = released.
*/
public KeyEvent(int key, char c, boolean down)
{
public KeyEvent(int key, char c, boolean down) {
this.key = key;
this.c = c;
this.down = down;

@ -34,8 +34,7 @@ public class MouseButtonEvent extends BusEvent<MouseButtonHandler> {
* @param down button pressed
* @param wheeld wheel change
*/
public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld)
{
public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) {
this.button = button;
this.down = down;
this.pos = pos.freeze();

@ -23,8 +23,7 @@ public class MouseMotionEvent extends BusEvent<MouseMotionHandler> {
* @param pos end pos
* @param move move vector
*/
public MouseMotionEvent(Vect pos, Vect move)
{
public MouseMotionEvent(Vect pos, Vect move) {
this.move = move.freeze();
this.pos = pos.freeze();
}

@ -1,300 +0,0 @@
package mightypork.gamecore.render;
import static org.lwjgl.opengl.GL11.*;
import java.nio.ByteBuffer;
import mightypork.gamecore.backend.lwjgl.AwtScreenshot;
import mightypork.gamecore.core.modules.AppAccess;
import mightypork.gamecore.core.modules.AppModule;
import mightypork.gamecore.render.events.DisplayReadyEvent;
import mightypork.gamecore.render.events.ViewportChangeEvent;
import mightypork.utils.logging.Log;
import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.rect.RectBound;
import mightypork.utils.math.constraints.vect.Vect;
import mightypork.utils.math.timing.FpsMeter;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
/**
* Display system
*
* @author Ondřej Hruška (MightyPork)
*/
@Deprecated
public class DisplaySystem extends AppModule implements RectBound {
private DisplayMode windowDisplayMode;
private int targetFps;
private FpsMeter fpsMeter;
private boolean fullscreenSwitchRequested;
/** Current screen size */
private static final Vect screenSize = new Vect() {
@Override
public double y()
{
return Display.getHeight();
}
@Override
public double x()
{
return Display.getWidth();
}
};
private static final Rect rect = Rect.make(screenSize);
/**
* @param app app access
*/
public DisplaySystem(AppAccess app)
{
super(app);
}
@Override
protected void deinit()
{
Display.destroy();
}
/**
* Set target fps (for syncing in endFrame() call).<br>
* With vsync enabled, the target fps may not be met.
*
* @param fps requested fps
*/
public void setTargetFps(int fps)
{
this.targetFps = fps;
}
/**
* Create a main window
*
* @param width requested width
* @param height requested height
* @param resizable is resizable by the user
* @param fullscreen is in fullscreen
* @param title window title
*/
public void createMainWindow(int width, int height, boolean resizable, boolean fullscreen, String title)
{
try {
Display.setDisplayMode(windowDisplayMode = new DisplayMode(width, height));
Display.setResizable(resizable);
Display.setVSyncEnabled(true);
Display.setTitle(title);
Display.create();
fpsMeter = new FpsMeter();
if (fullscreen) {
switchFullscreen();
Display.update();
}
getEventBus().send(new DisplayReadyEvent());
} catch (final LWJGLException e) {
throw new RuntimeException("Could not initialize screen", e);
}
}
/**
* Toggle FS if possible
*/
public void switchFullscreen()
{
fullscreenSwitchRequested = true;
}
private void doSwitchFullscreen()
{
try {
if (!Display.isFullscreen()) {
Log.f3("Entering fullscreen.");
// save window resize
windowDisplayMode = new DisplayMode(Display.getWidth(), Display.getHeight());
Display.setDisplayMode(Display.getDesktopDisplayMode());
Display.setFullscreen(true);
Display.update();
} else {
Log.f3("Leaving fullscreen.");
Display.setDisplayMode(windowDisplayMode);
Display.update();
}
getEventBus().send(new ViewportChangeEvent(getSize()));
} catch (final Throwable t) {
Log.e("Failed to toggle fullscreen mode.", t);
try {
Display.setDisplayMode(windowDisplayMode);
Display.update();
} catch (final Throwable t1) {
throw new RuntimeException("Failed to revert failed fullscreen toggle.", t1);
}
}
}
/**
* Take screenshot (expensive processing is done on-demand when screenshot
* is processed).
*
* @return screenshot object
*/
public static AwtScreenshot prepareScreenshot()
{
glReadBuffer(GL_FRONT);
final int width = Display.getWidth();
final int height = Display.getHeight();
final int bpp = 4;
final ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
final AwtScreenshot sc = new AwtScreenshot(width, height, bpp, buffer);
return sc;
}
/**
* @return true if close was requested (i.e. click on cross)
*/
public static boolean isCloseRequested()
{
return Display.isCloseRequested();
}
/**
* Get fullscreen state
*
* @return is fullscreen
*/
public static boolean isFullscreen()
{
return Display.isFullscreen();
}
/**
* Get screen size. This Vect is final and views at it can safely be made.
*
* @return size
*/
public static Vect getSize()
{
return screenSize;
}
/**
* Get screen rect. Static version of getRect().
*
* @return size
*/
public static Rect getBounds()
{
return rect;
}
/**
* @return screen width
*/
public static int getWidth()
{
return screenSize.xi();
}
/**
* @return screen height
*/
public static int getHeight()
{
return screenSize.yi();
}
/**
* Start a OpenGL frame
*/
public void beginFrame()
{
// handle resize
if (Display.wasResized()) {
getEventBus().send(new ViewportChangeEvent(getSize()));
}
if (fullscreenSwitchRequested) {
fullscreenSwitchRequested = false;
doSwitchFullscreen();
}
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
fpsMeter.frame();
}
/**
* End an OpenGL frame, flip buffers, sync to fps.
*/
public void endFrame()
{
Display.update(false); // don't poll input devices
Display.sync(targetFps);
}
/**
* Get screen rect. This Rect is final and views at it can safely be made.
*/
@Override
public Rect getRect()
{
return getBounds();
}
/**
* @return current FPS
*/
public long getFps()
{
return fpsMeter.getFPS();
}
/**
* Get screen center. This vect is final and views at it can safely be made.
*
* @return screen center.
*/
public static Vect getCenter()
{
return rect.center();
}
}

@ -1,542 +0,0 @@
package mightypork.gamecore.render;
import static org.lwjgl.opengl.GL11.*;
import java.io.IOException;
import mightypork.gamecore.resources.textures.FilterMode;
import mightypork.gamecore.resources.textures.ITexture;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.Color;
import mightypork.utils.math.color.pal.RGB;
import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.rect.caching.RectDigest;
import mightypork.utils.math.constraints.vect.Vect;
import mightypork.utils.math.constraints.vect.VectConst;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
/**
* Render utilities
*
* @author Ondřej Hruška (MightyPork)
*/
@Deprecated
public class Render {
public static final VectConst AXIS_X = Vect.make(1, 0, 0);
public static final VectConst AXIS_Y = Vect.make(0, 1, 0);
public static final VectConst AXIS_Z = Vect.make(0, 0, 1);
/**
* Bind GL color
*
* @param color Color color
*/
public static void setColor(Color color)
{
if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a());
}
/**
* Bind GL color
*
* @param color Color color
* @param alpha alpha multiplier
*/
public static void setColor(Color color, double alpha)
{
if (color != null) glColor4d(color.r(), color.g(), color.b(), color.a() * alpha);
}
/**
* Translate
*
* @param x
* @param y
*/
public static void translate(double x, double y)
{
glTranslated(x, y, 0);
}
/**
* Translate
*
* @param x
* @param y
* @param z
*/
public static void translate(double x, double y, double z)
{
glTranslated(x, y, z);
}
/**
* Translate with coord
*
* @param coord coord
*/
public static void translate(Vect coord)
{
glTranslated(coord.x(), coord.y(), coord.z());
}
/**
* Translate with coord, discard Z
*
* @param coord coord
*/
public static void translateXY(Vect coord)
{
glTranslated(coord.x(), coord.y(), 0);
}
/**
* Scale
*
* @param x
* @param y
*/
public static void scale(double x, double y)
{
glScaled(x, y, 0);
}
/**
* Scale
*
* @param x
* @param y
* @param z
*/
public static void scale(double x, double y, double z)
{
glScaled(x, y, z);
}
/**
* Scale
*
* @param factor vector of scaling factors
*/
public static void scale(Vect factor)
{
glScaled(factor.x(), factor.y(), factor.z());
}
/**
* Scale by X factor
*
* @param factor scaling factor
*/
public static void scaleXY(double factor)
{
glScaled(factor, factor, 1);
}
/**
* Scale by X factor
*
* @param factor scaling factor
*/
public static void scaleX(double factor)
{
glScaled(factor, 1, 1);
}
/**
* Scale by Y factor
*
* @param factor scaling factor
*/
public static void scaleY(double factor)
{
glScaled(1, factor, 1);
}
/**
* Scale by Z factor
*
* @param factor scaling factor
*/
public static void scaleZ(double factor)
{
glScaled(1, 1, factor);
}
/**
* Rotate around X axis
*
* @param angle deg
*/
public static void rotateX(double angle)
{
rotate(angle, AXIS_X);
}
/**
* Rotate around Y axis
*
* @param angle deg
*/
public static void rotateY(double angle)
{
rotate(angle, AXIS_Y);
}
/**
* Rotate around Z axis
*
* @param angle deg
*/
public static void rotateZ(double angle)
{
rotate(angle, AXIS_Z);
}
/**
* Rotate
*
* @param angle rotate angle
* @param axis rotation axis
*/
public static void rotate(double angle, Vect axis)
{
final Vect vec = axis.norm(1);
glRotated(angle, vec.x(), vec.y(), vec.z());
}
private static int pushed = 0;
/** Can be used to avoid texture binding and glBegin/glEnd in textured quads */
public static boolean batchTexturedQuadMode;
/**
* Store GL state
*/
public static void pushState()
{
pushed++;
if (pushed >= 100) {
Log.w("Suspicious number of state pushes: " + pushed);
}
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
/**
* Restore Gl state
*/
public static void popState()
{
if (pushed == 0) {
Log.w("Pop without push.");
}
pushed--;
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPopMatrix();
GL11.glPopClientAttrib();
GL11.glPopAttrib();
}
/**
* Store matrix
*/
public static void pushMatrix()
{
GL11.glPushMatrix();
}
/**
* Restore Gl state
*/
public static void popMatrix()
{
GL11.glPopMatrix();
}
/**
* Load texture
*
* @param resourcePath
* @param filtering filtering mode to use while loading.
* @return the loaded texture
*/
public synchronized static Texture loadSlickTexture(String resourcePath, FilterMode filtering)
{
try {
final String ext = FileUtils.getExtension(resourcePath).toUpperCase();
final Texture texture = TextureLoader.getTexture(ext, FileUtils.getResource(resourcePath), false, filtering.num);
if (texture == null) {
Log.w("Texture " + resourcePath + " could not be loaded.");
}
return texture;
} catch (final IOException e) {
Log.e("Loading of texture " + resourcePath + " failed.", e);
throw new RuntimeException("Could not load texture " + resourcePath + ".", e);
}
}
/**
* Render quad 2D
*
* @param rect rectangle
* @param color draw color
*/
public static void quad(Rect rect, Color color)
{
setColor(color);
quad(rect);
}
/**
* Render quad
*
* @param quad the quad to draw (px)
*/
public static void quad(Rect quad)
{
final RectDigest q = quad.digest();
// draw with color
glDisable(GL_TEXTURE_2D);
// quad
glBegin(GL_QUADS);
glVertex2d(q.left, q.bottom);
glVertex2d(q.right, q.bottom);
glVertex2d(q.right, q.top);
glVertex2d(q.left, q.top);
glEnd();
}
/**
* Draw quad with horizontal gradient
*
* @param quad drawn quad bounds
* @param color1 left color
* @param color2 right color
*/
public static void quadGradH(Rect quad, Color color1, Color color2)
{
quadColor(quad, color1, color2, color2, color1);
}
public static void quadColor(Rect quad, Color color)
{
quadColor(quad, color, color, color, color);
}
/**
* Draw quad with coloured vertices.
*
* @param quad drawn quad bounds
* @param colorHMinVMin
* @param colorHMaxVMin
* @param colorHMaxVMax
* @param colorHMinVMax
*/
public static void quadColor(Rect quad, Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax)
{
final RectDigest r = quad.digest();
// draw with color
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
setColor(colorHMinVMax);
glVertex2d(r.left, r.bottom);
setColor(colorHMaxVMax);
glVertex2d(r.right, r.bottom);
setColor(colorHMaxVMin);
glVertex2d(r.right, r.top);
setColor(colorHMinVMin);
glVertex2d(r.left, r.top);
glEnd();
}
/**
* Draw quad with vertical gradient
*
* @param quad drawn quad bounds
* @param color1 top color
* @param color2 bottom color
*/
public static void quadGradV(Rect quad, Color color1, Color color2)
{
quadColor(quad, color1, color1, color2, color2);
}
/**
* Render textured rect
*
* @param quad rectangle (px)
* @param txquad texture quad
*/
public static void quadTextured(Rect quad, TxQuad txquad)
{
quadTextured(quad, txquad, RGB.WHITE);
}
/**
* Render textured rect
*
* @param quad rectangle (px)
* @param txquad texture instance
* @param tint color tint
*/
public static void quadTextured(Rect quad, TxQuad txquad, Color tint)
{
if (!batchTexturedQuadMode) {
glEnable(GL_TEXTURE_2D);
txquad.tx.bind();
glBegin(GL_QUADS);
setColor(tint);
}
final RectDigest q = quad.digest();
final RectDigest u = txquad.uvs.digest();
final double offs = 0.0001;// hack to avoid white stitching
double tL = u.left + offs, tR = u.right - offs, tT = u.top + offs, tB = u.bottom - offs;
// handle flip
if (txquad.isFlippedY()) {
final double swap = tT;
tT = tB;
tB = swap;
}
if (txquad.isFlippedX()) {
final double swap = tL;
tL = tR;
tR = swap;
}
final double w = txquad.tx.getWidth01();
final double h = txquad.tx.getHeight01();
// quad with texture
glTexCoord2d(tL * w, tB * h);
glVertex2d(q.left, q.bottom);
glTexCoord2d(tR * w, tB * h);
glVertex2d(q.right, q.bottom);
glTexCoord2d(tR * w, tT * h);
glVertex2d(q.right, q.top);
glTexCoord2d(tL * w, tT * h);
glVertex2d(q.left, q.top);
if (!batchTexturedQuadMode) glEnd();
}
/**
* Setup Ortho projection for 2D graphics
*
* @param size viewport size (screen size)
*/
public static void setupOrtho(Vect size)
{
// fix projection for changed size
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, size.xi(), size.yi());
glOrtho(0, size.xi(), size.yi(), 0, -1000, 1000);
// back to modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_LIGHTING);
glClearDepth(1f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
public static void enterBatchTexturedQuadMode(ITexture texture)
{
texture.bind();
glBegin(GL11.GL_QUADS);
batchTexturedQuadMode = true;
}
public static void leaveBatchTexturedQuadMode()
{
glEnd();
batchTexturedQuadMode = false;
}
}

@ -260,11 +260,9 @@ public abstract class RenderModule extends BackendModule {
/**
* Setup projection for 2D graphics
*
* @param screenSize current viewport size
* Setup projection for 2D graphics, using current scren size
*/
public abstract void setupProjection(Vect screenSize);
public abstract void setupProjection();
/**
@ -286,7 +284,7 @@ public abstract class RenderModule extends BackendModule {
/**
* Create a main window
* Create a main window, if needed
*/
public abstract void createDisplay();

@ -4,7 +4,6 @@ package mightypork.gamecore.render;
import java.io.File;
import java.io.IOException;
import mightypork.gamecore.backend.lwjgl.AwtScreenshot;
import mightypork.gamecore.core.WorkDir;
import mightypork.gamecore.core.modules.App;
import mightypork.utils.Support;

@ -1,16 +1,16 @@
package mightypork.gamecore.render.events;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.RenderModule;
import mightypork.utils.eventbus.BusEvent;
import mightypork.utils.eventbus.events.flags.SingleReceiverEvent;
@SingleReceiverEvent
public class FullscreenToggleRequest extends BusEvent<DisplaySystem> {
public class FullscreenToggleRequest extends BusEvent<RenderModule> {
@Override
protected void handleBy(DisplaySystem handler)
protected void handleBy(RenderModule handler)
{
handler.switchFullscreen();
}

@ -22,8 +22,7 @@ public class ViewportChangeEvent extends BusEvent<ViewportChangeListener> {
/**
* @param size new screen size
*/
public ViewportChangeEvent(Vect size)
{
public ViewportChangeEvent(Vect size) {
this.screenSize = size;
}

@ -43,8 +43,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr
}
public AsyncResourceLoader()
{
public AsyncResourceLoader() {
super("Deferred loader");
}

@ -27,8 +27,7 @@ public abstract class BaseLazyResource implements LazyResource, Destroyable {
* @param resource resource path / name; this string is later used in
* loadResource()
*/
public BaseLazyResource(String resource)
{
public BaseLazyResource(String resource) {
this.resource = resource;
}

@ -19,8 +19,7 @@ public class ResourceLoadRequest extends BusEvent<ResourceLoader> {
/**
* @param resource resource to load
*/
public ResourceLoadRequest(LazyResource resource)
{
public ResourceLoadRequest(LazyResource resource) {
this.resource = resource;
}

@ -1,12 +1,7 @@
package mightypork.gamecore.resources;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**

@ -20,8 +20,7 @@ public class JointVolume extends Volume {
* @param volumes individual volumes to join
*/
@SafeVarargs
public JointVolume(Volume... volumes)
{
public JointVolume(Volume... volumes) {
super(1D);
this.volumes = volumes;
}

@ -43,8 +43,7 @@ public class LazyAudio extends BaseLazyResource {
*
* @param resourceName resource to load when needed
*/
public LazyAudio(String resourceName)
{
public LazyAudio(String resourceName) {
super(resourceName);
}
@ -92,7 +91,7 @@ public class LazyAudio extends BaseLazyResource {
{
final String ext = FileUtils.getExtension(resource);
try(final InputStream stream = FileUtils.getResource(resource)) {
try (final InputStream stream = FileUtils.getResource(resource)) {
if (ext.equalsIgnoreCase("ogg")) {
backingAudio = SoundStore.get().getOgg(resource, stream);

@ -24,8 +24,7 @@ public class SoundRegistry extends AppAccessAdapter {
/**
* @param app app access
*/
public SoundRegistry(AppAccess app)
{
public SoundRegistry(AppAccess app) {
super(app);
if (getSoundSystem() == null) throw new NullPointerException("SoundSystem cannot be null.");
}

@ -78,8 +78,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
/**
* @param app app access
*/
public SoundSystem(AppAccess app)
{
public SoundSystem(AppAccess app) {
super(app);
if (!soundSystemInited) {
@ -90,7 +89,6 @@ public class SoundSystem extends RootBusNode implements Updateable {
SoundStore.get().init();
setListener(INITIAL_LISTENER_POS);
getEventBus().send(new AudioReadyEvent());
} catch (final Throwable t) {
Log.e("Error initializing sound system.", t);

@ -15,8 +15,7 @@ public class Volume extends Mutable<Double> {
/**
* @param d initial value
*/
public Volume(Double d)
{
public Volume(Double d) {
super(d);
}

@ -32,8 +32,7 @@ public abstract class BaseAudioPlayer implements Destroyable {
* @param baseGain base gain (volume multiplier)
* @param volume colume control
*/
public BaseAudioPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume)
{
public BaseAudioPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume) {
this.audio = track;
this.baseGain = baseGain;

@ -19,8 +19,7 @@ public class EffectPlayer extends BaseAudioPlayer {
* @param baseGain base gain (volume multiplier)
* @param volume volume control
*/
public EffectPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume)
{
public EffectPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume) {
super(track, (float) basePitch, (float) baseGain, volume);
}

@ -40,8 +40,7 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
* @param baseGain base gain (volume multiplier)
* @param volume volume control
*/
public LoopPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume)
{
public LoopPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume) {
super(track, (float) basePitch, (float) baseGain, volume);
paused = true;

@ -21,8 +21,7 @@ public class FontRegistry extends AppAccessAdapter {
/**
* @param app app access
*/
public FontRegistry(AppAccess app)
{
public FontRegistry(AppAccess app) {
super(app);
}

@ -24,8 +24,7 @@ public class FontRenderer {
/**
* @param font used font
*/
public FontRenderer(GLFont font)
{
public FontRenderer(GLFont font) {
this(font, RGB.WHITE);
}
@ -34,8 +33,7 @@ public class FontRenderer {
* @param font used font
* @param color drawing color
*/
public FontRenderer(GLFont font, Color color)
{
public FontRenderer(GLFont font, Color color) {
this.font = font;
this.color = color;
}

@ -32,8 +32,7 @@ public class LazyFont extends BaseLazyResource implements GLFont {
int numval;
private FontStyle(int style)
{
private FontStyle(int style) {
this.numval = style;
}
}
@ -56,8 +55,7 @@ public class LazyFont extends BaseLazyResource implements GLFont {
* @param chars chars to load; null to load basic chars only
* @param size size (px)
*/
public LazyFont(String resourcePath, String chars, double size)
{
public LazyFont(String resourcePath, String chars, double size) {
this(resourcePath, chars, size, FontStyle.PLAIN, false, FilterMode.NEAREST);
}
@ -72,8 +70,7 @@ public class LazyFont extends BaseLazyResource implements GLFont {
* @param antialias use antialiasing for caching texture
* @param filter gl filtering mode
*/
public LazyFont(String resourcePath, String chars, double size, FontStyle style, boolean antialias, FilterMode filter)
{
public LazyFont(String resourcePath, String chars, double size, FontStyle style, boolean antialias, FilterMode filter) {
super(resourcePath);
this.size = size;
this.style = style;
@ -134,7 +131,7 @@ public class LazyFont extends BaseLazyResource implements GLFont {
*/
protected Font getAwtFont(String resource, float size, int style) throws IOException
{
try(InputStream in = FileUtils.getResource(resource)) {
try (InputStream in = FileUtils.getResource(resource)) {
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in);

@ -26,8 +26,7 @@ public class LazyFontNative extends LazyFont {
* @param antialias use antialiasing when drawn on the cache texture
* @param filter GL filtering mode
*/
public LazyFontNative(String fontName, String extraChars, double size, FontStyle style, boolean antialias, FilterMode filter)
{
public LazyFontNative(String fontName, String extraChars, double size, FontStyle style, boolean antialias, FilterMode filter) {
super(fontName, extraChars, size, style, antialias, filter);
}

@ -20,7 +20,6 @@ import java.util.Map;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.resources.textures.FilterMode;
import mightypork.gamecore.resources.textures.LazyTexture;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.Color;
import mightypork.utils.math.constraints.vect.Vect;
@ -90,8 +89,7 @@ public class TextureBackedFont implements GLFont {
* @param filter used Gl filter
* @param chars chars to load
*/
public TextureBackedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars)
{
public TextureBackedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars) {
this(font, antialias, filter, (" " + chars).toCharArray());
}
@ -104,8 +102,7 @@ public class TextureBackedFont implements GLFont {
* @param filter used Gl filter
* @param chars chars to load
*/
public TextureBackedFont(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars)
{
public TextureBackedFont(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars) {
GLUtils.checkGLContext();
this.font = font;
@ -165,8 +162,7 @@ public class TextureBackedFont implements GLFont {
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();
@ -302,8 +298,7 @@ public class TextureBackedFont implements GLFont {
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();

@ -16,8 +16,7 @@ public enum FilterMode
public final int num;
private FilterMode(int gl)
{
private FilterMode(int gl) {
this.num = gl;
}
}

@ -18,8 +18,7 @@ public class QuadGrid {
private final double tileH;
public QuadGrid(ITexture tx, int tilesX, int tilesY)
{
public QuadGrid(ITexture tx, int tilesX, int tilesY) {
this.tx = tx;
this.txWidth = tilesX;
this.txHeight = tilesY;

@ -27,8 +27,7 @@ public class TextureRegistry extends AppAccessAdapter {
/**
* @param app app access
*/
public TextureRegistry(AppAccess app)
{
public TextureRegistry(AppAccess app) {
super(app);
}

@ -65,8 +65,7 @@ public class TxQuad {
* @param x2 right bottom X (0-1)
* @param y2 right bottom Y (0-1)
*/
public TxQuad(ITexture tx, double x1, double y1, double x2, double y2)
{
public TxQuad(ITexture tx, double x1, double y1, double x2, double y2) {
this(tx, Rect.make(x1, y1, x2, y2));
}
@ -75,8 +74,7 @@ public class TxQuad {
* @param tx Texture
* @param uvs Rect of texture UVs (0-1); will be frozen.
*/
public TxQuad(ITexture tx, Rect uvs)
{
public TxQuad(ITexture tx, Rect uvs) {
this.tx = tx;
this.uvs = uvs.freeze();
}
@ -87,8 +85,7 @@ public class TxQuad {
*
* @param txQuad a copied quad
*/
public TxQuad(TxQuad txQuad)
{
public TxQuad(TxQuad txQuad) {
this.tx = txQuad.tx;
this.uvs = txQuad.uvs;
this.flipX = txQuad.flipX;

@ -22,8 +22,7 @@ public class TxSheet {
private final int count;
public TxSheet(TxQuad tx, int width, int height)
{
public TxSheet(TxQuad tx, int width, int height) {
this.original = tx;
this.width = width;
this.count = width * height;

@ -16,8 +16,7 @@ public enum WrapMode
public final int num;
private WrapMode(int gl)
{
private WrapMode(int gl) {
this.num = gl;
}
}

@ -19,8 +19,7 @@ public 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;
}

@ -77,7 +77,10 @@ public class Launcher {
System.exit(1);
}
final BaseApp app = new RogueApp(workdir, true);
final BaseApp app = new RogueApp();
app.getInitOptions().setWorkdir(workdir);
app.getInitOptions().setSigleInstance(true);
app.getInitOptions().setLogLevel(llFile, llSyso);
app.getInitOptions().setBusLogging(logBus);

@ -8,11 +8,12 @@ import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.core.events.MainLoopRequest;
import mightypork.gamecore.core.events.ShudownRequest;
import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.core.modules.AppInitOptions;
import mightypork.gamecore.core.modules.BaseApp;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.RenderModule;
import mightypork.gamecore.render.events.FullscreenToggleRequest;
import mightypork.gamecore.render.events.ScreenshotRequest;
import mightypork.gamecore.render.events.ScreenshotRequestListener;
@ -42,11 +43,8 @@ import mightypork.utils.logging.Log;
*/
public final class RogueApp extends BaseApp implements ViewportChangeListener, ScreenshotRequestListener {
public RogueApp(File workdir, boolean singleInstance)
{
super(workdir, singleInstance);
setBackend(new LwjglBackend(this));
public RogueApp() {
super(new LwjglBackend());
AppInitOptions opt = getInitOptions();
@ -72,15 +70,20 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener, S
@Override
protected void initDisplay(DisplaySystem display)
protected void initDisplay(RenderModule gfx)
{
// init based on config
final int w = Config.getValue("display.width");
final int h = Config.getValue("display.height");
final boolean fs = Config.getValue("display.fullscreen");
display.createMainWindow(w, h, true, fs, Const.TITLEBAR);
display.setTargetFps(Const.FPS_RENDER);
gfx.setSize(w, h);
gfx.setResizable(true);
gfx.setFullscreen(fs);
gfx.setTitle(Const.TITLEBAR);
gfx.setTargetFps(Const.FPS_RENDER);
gfx.createDisplay();
}
@ -93,7 +96,6 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener, S
WorldProvider.init(this);
getEventBus().subscribe(new RogueStateManager(this));
screens.addScreen("main_menu", new ScreenMainMenu(this));
screens.addScreen("select_world", new ScreenSelectWorld(this));
screens.addScreen("game", new ScreenGame(this));
@ -133,7 +135,6 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener, S
protected void postInit()
{
getEventBus().send(new MainLoopRequest(new Runnable() {
@Override
@ -154,13 +155,13 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener, S
public void onViewportChanged(ViewportChangeEvent event)
{
// save viewport size to config file
final boolean fs = DisplaySystem.isFullscreen();
final boolean fs = gfx().isFullscreen();
Config.setValue("display.fullscreen", fs);
if (!fs) {
Config.setValue("display.width", DisplaySystem.getWidth());
Config.setValue("display.height", DisplaySystem.getHeight());
Config.setValue("display.width", gfx().getWidth());
Config.setValue("display.height", gfx().getHeight());
}
}

@ -16,7 +16,6 @@ import mightypork.utils.math.constraints.rect.Rect;
public class RogueResources implements ResourceSetup {
@Override
public void addFonts(FontRegistry fonts)
{
@ -111,7 +110,6 @@ public class RogueResources implements ResourceSetup {
textures.add("inv.slot.base", grid.makeQuad(0, 5));
textures.add("inv.slot.selected", grid.makeQuad(1, 5));
// sprites
texture = textures.addTexture("/res/img/sprites.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
@ -121,7 +119,6 @@ public class RogueResources implements ResourceSetup {
textures.add("sprite.rat.boss", grid.makeSheet(0, 3, 4, 1));
textures.add("sprite.zzz", grid.makeQuad(0, 7)); // sleep thingy
// logo
texture = textures.addTexture("/res/img/logo.png", FilterMode.NEAREST, WrapMode.CLAMP);
textures.add("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203)));
@ -135,7 +132,6 @@ public class RogueResources implements ResourceSetup {
textures.add("story_2", grid.makeQuad(3, 2, 3, 1));
textures.add("story_3", grid.makeQuad(0, 3, 3, 1));
// tiles
texture = textures.addTexture("tiles", "/res/img/tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
@ -176,7 +172,6 @@ public class RogueResources implements ResourceSetup {
textures.add("tile.ufog.se", grid.makeQuad(5, 7).flipY().flipX());
textures.add("tile.ufog.full", grid.makeQuad(6, 7));
texture = textures.addTexture("items", "/res/img/items.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.add("item.meat", grid.makeQuad(0, 0));

@ -9,8 +9,7 @@ import mightypork.utils.logging.Log;
public class RogueStateManager extends AppModule {
public RogueStateManager(AppAccess app)
{
public RogueStateManager(AppAccess app) {
super(app);
}
@ -49,5 +48,4 @@ public class RogueStateManager extends AppModule {
}
}
}

@ -22,8 +22,7 @@ public class LoadingOverlayRequest extends BusEvent<LoadingOverlay> {
* @param msg task description
* @param task task runnable
*/
public LoadingOverlayRequest(String msg, Runnable task)
{
public LoadingOverlayRequest(String msg, Runnable task) {
this.task = task;
this.msg = msg;
}

@ -17,15 +17,13 @@ public class RogueStateRequest extends BusEvent<RogueStateManager> {
private final boolean fromDark;
public RogueStateRequest(RogueState requested)
{
public RogueStateRequest(RogueState requested) {
this.requested = requested;
this.fromDark = false;
}
public RogueStateRequest(RogueState requested, boolean fromDark)
{
public RogueStateRequest(RogueState requested, boolean fromDark) {
this.requested = requested;
this.fromDark = fromDark;
}

@ -2,6 +2,7 @@ package mightypork.rogue.screens;
import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.core.modules.App;
import mightypork.gamecore.core.modules.AppAccess;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX;
@ -27,8 +28,7 @@ public class FpsOverlay extends Overlay {
TextPainter tp;
public FpsOverlay(AppAccess screen)
{
public FpsOverlay(AppAccess screen) {
super(screen);
/*
@ -53,7 +53,7 @@ public class FpsOverlay extends Overlay {
@Override
public String getString()
{
return getDisplay().getFps() + " fps";
return App.gfx().getFps() + " fps";
}
});

@ -64,8 +64,7 @@ public class LoadingOverlay extends Overlay {
};
public LoadingOverlay(AppAccess app)
{
public LoadingOverlay(AppAccess app) {
super(app);
final QuadPainter qp = new QuadPainter(PAL16.SEABLUE);

@ -7,19 +7,18 @@ import mightypork.gamecore.core.modules.AppAccess;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.Stub;
public class RogueScreen extends LayeredScreen implements UserQuitRequestListener {
public RogueScreen(AppAccess app)
{
public RogueScreen(AppAccess app) {
super(app);
}
@Override
@DefaultImpl
@Stub
public void onQuitRequest(UserQuitRequest event)
{
getEventBus().send(new RogueStateRequest(RogueState.EXIT));

@ -1,9 +1,9 @@
package mightypork.rogue.screens.game;
import mightypork.gamecore.core.modules.App;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.BaseComponent;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.utils.math.constraints.num.Num;
import mightypork.utils.math.constraints.num.var.NumVar;
@ -22,8 +22,7 @@ public class HeartBar extends BaseComponent {
private final Rect heart;
public HeartBar(Num total, Num active, TxQuad img_on, TxQuad img_half, TxQuad img_off, AlignX align)
{
public HeartBar(Num total, Num active, TxQuad img_on, TxQuad img_half, TxQuad img_off, AlignX align) {
super();
this.total = total;
this.active = active;
@ -58,7 +57,7 @@ public class HeartBar extends BaseComponent {
index.setTo(i);
final double rem = active.value() - i;
Render.quadTextured(heart, (rem > 0.6 ? img_on : rem > 0.25 ? img_half : img_off));
App.gfx().quad(heart, (rem > 0.6 ? img_on : rem > 0.25 ? img_half : img_off));
}
}

@ -1,11 +1,11 @@
package mightypork.rogue.screens.game;
import mightypork.gamecore.core.modules.App;
import mightypork.gamecore.core.modules.AppAccess;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.gamecore.gui.components.layout.FlowColumnLayout;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.utils.math.constraints.rect.Rect;
@ -21,21 +21,18 @@ public class IngameNav extends LayoutComponent {
private final TxQuad bg;
public IngameNav(AppAccess app)
{
public IngameNav(AppAccess app) {
this(app, null);
}
public IngameNav(AppAccess app, RectBound context)
{
public IngameNav(AppAccess app, RectBound context) {
super(app, context);
final Rect shr = this.shrink(height().perc(5));
leftFlow = new FlowColumnLayout(app, context, shr.height(), AlignX.LEFT);
rightFlow = new FlowColumnLayout(app, context, shr.height(), AlignX.RIGHT);
leftFlow.setRect(shr);
rightFlow.setRect(shr);
attach(leftFlow);
@ -64,11 +61,10 @@ public class IngameNav extends LayoutComponent {
{
// draw BG (manually repeat)
for (int i = 0; i < Math.ceil(width().value() / paintHelper.width().value()); i++) {
Render.quadTextured(paintHelper.moveX(paintHelper.width().value() * i), bg);
App.gfx().quad(paintHelper.moveX(paintHelper.width().value() * i), bg);
}
super.renderComponent();
}
}

@ -1,11 +1,11 @@
package mightypork.rogue.screens.game;
import mightypork.gamecore.core.modules.App;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.input.ClickableComponent;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.rogue.world.PlayerFacade;
@ -47,8 +47,7 @@ public class InvSlot extends ClickableComponent {
private final Num hAlpha = Num.make(0.7);
public InvSlot(int index, InvSlot[] allSlots)
{
public InvSlot(int index, InvSlot[] allSlots) {
super();
this.txBase = Res.getTxQuad("inv.slot.base");
this.txSelected = Res.getTxQuad("inv.slot.selected");
@ -117,7 +116,7 @@ public class InvSlot extends ClickableComponent {
bg = txBase;
}
Render.quadTextured(this, bg);
App.gfx().quad(this, bg);
final PlayerFacade pl = WorldProvider.get().getPlayer();
@ -148,17 +147,16 @@ public class InvSlot extends ClickableComponent {
rtTxP.render();
}
if (itm.isDamageable()) {
Color.pushAlpha(hAlpha);
Render.quadColor(usesRect, RGB.BLACK);
App.gfx().quad(usesRect, RGB.BLACK);
final double useRatio = (itm.getRemainingUses() / (double) itm.getMaxUses());
final Color barColor = (useRatio > 0.6 ? RGB.GREEN : useRatio > 0.2 ? RGB.ORANGE : RGB.RED);
Render.quadColor(usesRect.shrinkRight(usesRect.width().value() * (1 - useRatio)), barColor);
App.gfx().quad(usesRect.shrinkRight(usesRect.width().value() * (1 - useRatio)), barColor);
Color.popAlpha();
}

@ -44,8 +44,7 @@ public class LayerAskSave extends FadingLayer {
}
public LayerAskSave(final ScreenGame screen)
{
public LayerAskSave(final ScreenGame screen) {
super(screen);
this.gscreen = screen;

@ -28,8 +28,7 @@ import mightypork.utils.math.constraints.num.Num;
public class LayerDeath extends FadingLayer {
public LayerDeath(final ScreenGame screen)
{
public LayerDeath(final ScreenGame screen) {
super(screen);
// darker down to cover console.
@ -54,7 +53,6 @@ public class LayerDeath extends FadingLayer {
linl = new LinearLayout(root, AlignX.CENTER);
rl.add(linl);
final TextButton btn1 = new TextButton(thick_font, "Retry", ScreenGame.COLOR_BTN_GOOD);
btn1.textPainter.setVPaddingPercent(25);
linl.add(btn1);

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save