Source import

master
Ondřej Hruška 10 years ago
parent a694f45af0
commit e56148559c
  1. 7
      .classpath
  2. 18
      .gitignore
  3. 17
      .project
  4. 11
      .settings/org.eclipse.jdt.core.prefs
  5. 2
      README.md
  6. 133
      src/junk/AppInitOptions.java
  7. 184
      src/junk/BaseApp.java
  8. 299
      src/junk/DisplaySystem.java
  9. 542
      src/junk/Render.java
  10. 261
      src/junk/SoundSystem.java
  11. 220
      src/mightypork/gamecore/audio/AudioModule.java
  12. 47
      src/mightypork/gamecore/audio/DeferredAudio.java
  13. 99
      src/mightypork/gamecore/audio/IAudio.java
  14. 51
      src/mightypork/gamecore/audio/JointVolume.java
  15. 83
      src/mightypork/gamecore/audio/SoundRegistry.java
  16. 29
      src/mightypork/gamecore/audio/Volume.java
  17. 105
      src/mightypork/gamecore/audio/players/BaseAudioPlayer.java
  18. 66
      src/mightypork/gamecore/audio/players/EffectPlayer.java
  19. 166
      src/mightypork/gamecore/audio/players/LoopPlayer.java
  20. 277
      src/mightypork/gamecore/core/App.java
  21. 65
      src/mightypork/gamecore/core/AppBackend.java
  22. 34
      src/mightypork/gamecore/core/AppPlugin.java
  23. 24
      src/mightypork/gamecore/core/BackendModule.java
  24. 150
      src/mightypork/gamecore/core/InitTask.java
  25. 130
      src/mightypork/gamecore/core/MainLoop.java
  26. 19
      src/mightypork/gamecore/core/OptionalInitTask.java
  27. 91
      src/mightypork/gamecore/core/WorkDir.java
  28. 269
      src/mightypork/gamecore/core/config/Config.java
  29. 75
      src/mightypork/gamecore/core/config/InitTaskConfig.java
  30. 55
      src/mightypork/gamecore/core/config/KeyStrokeProperty.java
  31. 44
      src/mightypork/gamecore/core/events/MainLoopRequest.java
  32. 47
      src/mightypork/gamecore/core/events/ShutdownEvent.java
  33. 18
      src/mightypork/gamecore/core/events/ShutdownListener.java
  34. 42
      src/mightypork/gamecore/core/init/InitTaskCrashHandler.java
  35. 97
      src/mightypork/gamecore/core/init/InitTaskDisplay.java
  36. 74
      src/mightypork/gamecore/core/init/InitTaskIonizables.java
  37. 108
      src/mightypork/gamecore/core/init/InitTaskLog.java
  38. 54
      src/mightypork/gamecore/core/init/InitTaskLogHeader.java
  39. 136
      src/mightypork/gamecore/core/init/InitTaskWorkdir.java
  40. 68
      src/mightypork/gamecore/core/plugins/screenshot/InitTaskPluginScreenshot.java
  41. 34
      src/mightypork/gamecore/core/plugins/screenshot/ScreenshotPlugin.java
  42. 22
      src/mightypork/gamecore/core/plugins/screenshot/ScreenshotRequest.java
  43. 100
      src/mightypork/gamecore/core/plugins/screenshot/TaskTakeScreenshot.java
  44. 16
      src/mightypork/gamecore/graphics/FullscreenToggleRequest.java
  45. 406
      src/mightypork/gamecore/graphics/GraphicsModule.java
  46. 16
      src/mightypork/gamecore/graphics/Renderable.java
  47. 34
      src/mightypork/gamecore/graphics/Screenshot.java
  48. 98
      src/mightypork/gamecore/graphics/fonts/DeferredFont.java
  49. 79
      src/mightypork/gamecore/graphics/fonts/FontRegistry.java
  50. 213
      src/mightypork/gamecore/graphics/fonts/FontRenderer.java
  51. 23
      src/mightypork/gamecore/graphics/fonts/Glyphs.java
  52. 76
      src/mightypork/gamecore/graphics/fonts/IFont.java
  53. 57
      src/mightypork/gamecore/graphics/textures/DeferredTexture.java
  54. 12
      src/mightypork/gamecore/graphics/textures/FilterMode.java
  55. 64
      src/mightypork/gamecore/graphics/textures/ITexture.java
  56. 92
      src/mightypork/gamecore/graphics/textures/QuadGrid.java
  57. 143
      src/mightypork/gamecore/graphics/textures/TextureRegistry.java
  58. 164
      src/mightypork/gamecore/graphics/textures/TxQuad.java
  59. 121
      src/mightypork/gamecore/graphics/textures/TxSheet.java
  60. 12
      src/mightypork/gamecore/graphics/textures/WrapMode.java
  61. 54
      src/mightypork/gamecore/gui/Action.java
  62. 38
      src/mightypork/gamecore/gui/ActionGroup.java
  63. 17
      src/mightypork/gamecore/gui/ActionTrigger.java
  64. 169
      src/mightypork/gamecore/gui/components/BaseComponent.java
  65. 95
      src/mightypork/gamecore/gui/components/Component.java
  66. 7
      src/mightypork/gamecore/gui/components/DynamicWidthComponent.java
  67. 15
      src/mightypork/gamecore/gui/components/InputComponent.java
  68. 122
      src/mightypork/gamecore/gui/components/LayoutComponent.java
  69. 77
      src/mightypork/gamecore/gui/components/LinearComponent.java
  70. 28
      src/mightypork/gamecore/gui/components/PluggableRenderable.java
  71. 49
      src/mightypork/gamecore/gui/components/input/ClickableComponent.java
  72. 63
      src/mightypork/gamecore/gui/components/input/ClickableWrapper.java
  73. 77
      src/mightypork/gamecore/gui/components/input/TextButton.java
  74. 42
      src/mightypork/gamecore/gui/components/layout/ColumnLayout.java
  75. 36
      src/mightypork/gamecore/gui/components/layout/ConstraintLayout.java
  76. 85
      src/mightypork/gamecore/gui/components/layout/FlowColumnLayout.java
  77. 84
      src/mightypork/gamecore/gui/components/layout/FlowRowLayout.java
  78. 78
      src/mightypork/gamecore/gui/components/layout/GridLayout.java
  79. 18
      src/mightypork/gamecore/gui/components/layout/NullComponent.java
  80. 42
      src/mightypork/gamecore/gui/components/layout/RowLayout.java
  81. 78
      src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java
  82. 24
      src/mightypork/gamecore/gui/components/layout/linear/LinearGap.java
  83. 93
      src/mightypork/gamecore/gui/components/layout/linear/LinearLayout.java
  84. 31
      src/mightypork/gamecore/gui/components/layout/linear/LinearRectangle.java
  85. 20
      src/mightypork/gamecore/gui/components/layout/linear/LinearSquare.java
  86. 20
      src/mightypork/gamecore/gui/components/layout/linear/LinearWrapper.java
  87. 46
      src/mightypork/gamecore/gui/components/painters/ImagePainter.java
  88. 62
      src/mightypork/gamecore/gui/components/painters/QuadPainter.java
  89. 163
      src/mightypork/gamecore/gui/components/painters/TextPainter.java
  90. 30
      src/mightypork/gamecore/gui/events/LayoutChangeEvent.java
  91. 7
      src/mightypork/gamecore/gui/events/LayoutChangeListener.java
  92. 33
      src/mightypork/gamecore/gui/events/ScreenRequest.java
  93. 15
      src/mightypork/gamecore/gui/events/ScreenRequestListener.java
  94. 44
      src/mightypork/gamecore/gui/events/ViewportChangeEvent.java
  95. 17
      src/mightypork/gamecore/gui/events/ViewportChangeListener.java
  96. 112
      src/mightypork/gamecore/gui/screens/LayeredScreen.java
  97. 222
      src/mightypork/gamecore/gui/screens/Overlay.java
  98. 153
      src/mightypork/gamecore/gui/screens/Screen.java
  99. 50
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  100. 106
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry combineaccessrules="false" kind="src" path="/MightyUtils"/>
<classpathentry kind="output" path="bin"/>
</classpath>

18
.gitignore vendored

@ -1,12 +1,6 @@
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
/target/
/~local/
*.log
.attach_pid*
*~

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GameCore</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

@ -2,3 +2,5 @@ gamecore
========
Versatile Java game engine with pluggable backends
TODO: better readme and tutorial games

@ -0,0 +1,133 @@
package junk;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import mightypork.gamecore.core.AppBackend;
import mightypork.gamecore.resources.ResourceSetup;
import mightypork.gamecore.resources.loading.AsyncResourceLoader;
import mightypork.gamecore.resources.loading.ResourceLoader;
/**
* Init options holder class
*/
public class AppInitOptions {
String logDir = "log";
String logFilePrefix = "runtime";
String screenshotDir = "screenshots";
boolean busLogging = false;
String configFile = "settings.cfg";
String configComment = "Main config file";
final List<ResourceSetup> resourceLists = new ArrayList<>();
final List<KeySetup> keyLists = new ArrayList<>();
final List<ConfigSetup> configLists = 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 addResources(ResourceSetup res)
{
resourceLists.add(res);
}
public void setBackend(AppBackend 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;
}
}

@ -0,0 +1,184 @@
package junk;
import java.lang.Thread.UncaughtExceptionHandler;
import mightypork.gamecore.backends.lwjgl.LwjglInputModule;
import mightypork.gamecore.core.App;
import mightypork.gamecore.core.AppBackend;
import mightypork.gamecore.core.MainLoop;
import mightypork.gamecore.core.WorkDir;
import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.ResourceSetup;
import mightypork.utils.logging.Log;
/**
* Basic screen-based game with subsystems.<br>
* This class takes care of the initialization sequence.
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class BaseApp extends App implements UncaughtExceptionHandler {
// modules
private MainLoop gameLoop;
private ScreenRegistry screenRegistry;
private boolean started = false;
private boolean lockObtained = false;
// init opt holder
private final AppInitOptions opt = new AppInitOptions();
/**
* Get init options
*
* @return opt holder
*/
public AppInitOptions getInitOptions()
{
if (started) {
throw new IllegalStateException("Cannot alter init options after starting the App.");
}
return opt;
}
public BaseApp(AppBackend backend) {
super(backend);
}
/**
* Start the application
*/
@Override
public final void start()
{
initialize();
Log.i("Starting main loop...");
// open first screen !!!
started = true;
gameLoop.start();
}
/**
* Init the app
*/
protected void initialize()
{
WorkDir.init(opt.workdir);
if (opt.sigleInstance) initLock();
lockObtained = true;
for (final RouteSetup rs : opt.routeLists) {
WorkDir.registerRoutes(rs);
}
WorkDir.addPath("_screenshot_dir", opt.screenshotDir);
// apply configurations
Config.init(WorkDir.getFile(opt.configFile), opt.configComment);
// add keys to config
for (final KeySetup l : opt.keyLists) {
Config.registerKeys(l);
}
// add options to config
for (final ConfigSetup c : opt.configLists) {
Config.registerOptions(c);
}
Config.load();
/*
* Display
*/
Log.f2("Initializing Display System...");
initDisplay(gfx());
/*
* Audio
*/
Log.f2("Initializing Sound System...");
soundSystem = new SoundSystem(this);
initSoundSystem(soundSystem);
/*
* Input
*/
Log.f2("Initializing Input System...");
inputSystem = new LwjglInputModule(this);
initInputSystem(inputSystem);
/*
* Prepare main loop
*/
Log.f1("Creating Screen Registry and Game Loop...");
screenRegistry = new ScreenRegistry(this);
gameLoop = createMainLoop();
gameLoop.setRootRenderable(screenRegistry);
/*
* Load resources
*
* Resources should be registered to registries, and AsyncResourceLoader will load them.
*/
Log.f1("Loading resources...");
if (opt.resourceLoader != null) {
opt.resourceLoader.init(this);
}
Res.init(this);
for (final ResourceSetup rl : opt.resourceLists) {
Res.load(rl);
}
/*
* Screen registry
*
* Must be after resources, because screens can request them during instantiation.
*/
Log.f2("Registering screens...");
initScreens(screenRegistry);
}
/**
* Register game screens to the registry.
*
* @param screens
*/
protected void initScreens(ScreenRegistry screens)
{
screens.addOverlay(new CrossfadeOverlay(this));
}
/**
* Create game loop instance
*
* @return the game loop.
*/
protected MainLoop createMainLoop()
{
return new MainLoop(this);
}
protected void beforeShutdown()
{
// ???
if (lockObtained) Config.save();
}
}

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

@ -0,0 +1,261 @@
package junk;
//package mightypork.gamecore.resources.audio;
//
//
//import java.nio.FloatBuffer;
//import java.util.ArrayList;
//import java.util.List;
//
//import mightypork.gamecore.backend.lwjgl.SlickAudio;
//import mightypork.gamecore.core.modules.App;
//import mightypork.gamecore.resources.ResourceLoadRequest;
//import mightypork.gamecore.resources.audio.players.EffectPlayer;
//import mightypork.gamecore.resources.audio.players.LoopPlayer;
//import mightypork.gamecore.util.BufferHelper;
//import mightypork.utils.eventbus.clients.BusNode;
//import mightypork.utils.interfaces.Destroyable;
//import mightypork.utils.interfaces.Updateable;
//import mightypork.utils.logging.Log;
//import mightypork.utils.math.constraints.vect.Vect;
//import mightypork.utils.math.constraints.vect.var.VectVar;
//
//import org.lwjgl.openal.AL;
//import org.lwjgl.openal.AL10;
//import org.newdawn.slick.openal.SoundStore;
//
//
///**
// * Sound system class (only one instance should be made per application)
// *
// * @author Ondřej Hruška (MightyPork)
// */
//@Deprecated
//public class SoundSystem extends BusNode implements Updateable, Destroyable {
//
// private static final Vect INITIAL_LISTENER_POS = Vect.ZERO;
// private static final int MAX_SOURCES = 256;
//
// private static VectVar listener = Vect.makeVar();
// private static boolean soundSystemInited = false;
//
//
// /**
// * Set listener pos
// *
// * @param pos
// */
// public static void setListener(Vect pos)
// {
// listener.setTo(pos);
// final FloatBuffer buf3 = BufferHelper.alloc(3);
// final FloatBuffer buf6 = BufferHelper.alloc(6);
// buf3.clear();
// BufferHelper.fill(buf3, (float) pos.x(), (float) pos.y(), (float) pos.z());
// AL10.alListener(AL10.AL_POSITION, buf3);
// buf3.clear();
// BufferHelper.fill(buf3, 0, 0, 0);
// AL10.alListener(AL10.AL_VELOCITY, buf3);
// buf6.clear();
// BufferHelper.fill(buf6, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
// AL10.alListener(AL10.AL_ORIENTATION, buf6);
// }
//
//
// /**
// * @return listener coordinate
// */
// public static Vect getListener()
// {
// return listener;
// }
//
// // -- instance --
//
// private final Volume masterVolume = new Volume(1D);
// private final Volume effectsVolume = new JointVolume(masterVolume);
// private final Volume loopsVolume = new JointVolume(masterVolume);
//
// private final List<LoopPlayer> loopPlayers = new ArrayList<>();
// private final List<DeferredAudio> resources = new ArrayList<>();
//
//
// /**
// * @param busAccess app access
// */
// public SoundSystem() {
//
// if (!soundSystemInited) {
// soundSystemInited = true;
//
// try {
// SoundStore.get().setMaxSources(MAX_SOURCES);
// SoundStore.get().init();
// setListener(INITIAL_LISTENER_POS);
//
// App.bus().send(new AudioReadyEvent());
// } catch (final Throwable t) {
// Log.e("Error initializing sound system.", t);
// }
// }
// }
//
//
// @Override
// public void destroy()
// {
// for (final DeferredAudio r : resources) {
// r.destroy();
// }
//
// SoundStore.get().clear();
// AL.destroy();
// }
//
//
// @Override
// public void update(double delta)
// {
// for (final Updateable lp : loopPlayers) {
// lp.update(delta);
// }
// }
//
//
// /**
// * Create effect resource
// *
// * @param resource resource path
// * @param pitch default pitch (1 = unchanged)
// * @param gain default gain (0-1)
// * @return player
// */
// public EffectPlayer createEffect(String resource, double pitch, double gain)
// {
// return new EffectPlayer(createResource(resource), pitch, gain, effectsVolume);
// }
//
//
// /**
// * Register loop resource (music / effect loop)
// *
// * @param resource resource path
// * @param pitch default pitch (1 = unchanged)
// * @param gain default gain (0-1)
// * @param fadeIn default time for fadeIn
// * @param fadeOut default time for fadeOut
// * @return player
// */
// public LoopPlayer createLoop(String resource, double pitch, double gain, double fadeIn, double fadeOut)
// {
// final LoopPlayer p = new LoopPlayer(createResource(resource), pitch, gain, loopsVolume);
// p.setFadeTimes(fadeIn, fadeOut);
// loopPlayers.add(p);
// return p;
// }
//
//
// /**
// * Create {@link DeferredAudio} for a resource
// *
// * @param res a resource name
// * @return the resource
// * @throws IllegalArgumentException if resource is already registered
// */
// private DeferredAudio createResource(String res)
// {
// final DeferredAudio a = new SlickAudio(res);
// App.bus().send(new ResourceLoadRequest(a));
// resources.add(a);
// return a;
// }
//
//
// /**
// * Fade out all loops (ie. for screen transitions)
// */
// public void fadeOutAllLoops()
// {
// for (final LoopPlayer p : loopPlayers) {
// p.fadeOut();
// }
// }
//
//
// /**
// * Pause all loops (leave volume unchanged)
// */
// public void pauseAllLoops()
// {
// for (final LoopPlayer p : loopPlayers) {
// p.pause();
// }
// }
//
//
// /**
// * Set level of master volume
// *
// * @param d level
// */
// public void setMasterVolume(double d)
// {
// masterVolume.set(d);
// }
//
//
// /**
// * Set level of effects volume
// *
// * @param d level
// */
// public void setEffectsVolume(double d)
// {
// effectsVolume.set(d);
// }
//
//
// /**
// * Set level of music volume
// *
// * @param d level
// */
// public void setMusicVolume(double d)
// {
// loopsVolume.set(d);
// }
//
//
// /**
// * Get level of master volume
// *
// * @return level
// */
// public double getMasterVolume()
// {
// return masterVolume.get();
// }
//
//
// /**
// * Get level of effects volume
// *
// * @return level
// */
// public double getEffectsVolume()
// {
// return effectsVolume.get();
// }
//
//
// /**
// * Get level of music volume
// *
// * @return level
// */
// public double getMusicVolume()
// {
// return loopsVolume.get();
// }
//}

@ -0,0 +1,220 @@
package mightypork.gamecore.audio;
import java.util.ArrayList;
import java.util.List;
import mightypork.gamecore.audio.players.EffectPlayer;
import mightypork.gamecore.audio.players.LoopPlayer;
import mightypork.gamecore.core.App;
import mightypork.gamecore.core.BackendModule;
import mightypork.gamecore.resources.loading.ResourceLoadRequest;
import mightypork.utils.interfaces.Updateable;
import mightypork.utils.math.constraints.vect.Vect;
/**
* Abstract audio module.
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class AudioModule extends BackendModule implements Updateable {
/**
* Set listener position
*
* @param pos listener position
*/
public abstract void setListenerPos(Vect pos);
/**
* Get current listener position
*
* @return listener position
*/
public abstract Vect getListenerPos();